jb-core 0.2.0 → 0.3.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/dist/index.cjs.js CHANGED
@@ -1,2 +1,2 @@
1
1
  "use strict";exports.createFocusEvent=function(e,t,n){const o={bubbles:t.bubbles,cancelable:t.cancelable,composed:t.composed,detail:t.detail,view:t.view,which:t.which,relatedTarget:t.relatedTarget,...n};return new FocusEvent(e,o)},exports.createInputEvent=function(e,t,n){const o={bubbles:t.bubbles,cancelable:t.cancelable,composed:t.composed,detail:t.detail,isComposing:t.isComposing,view:t.view,which:t.which,data:t.data,dataTransfer:t.dataTransfer,inputType:t.inputType,targetRanges:"function"==typeof t.getTargetRanges()?t.getTargetRanges():[],...n};return new InputEvent(e,o)},exports.createKeyboardEvent=function(e,t,n){const o={altKey:t.altKey,bubbles:t.bubbles,cancelable:t.cancelable,code:t.code,composed:t.composed,ctrlKey:t.ctrlKey,detail:t.detail,isComposing:t.isComposing,key:t.key,location:t.location,metaKey:t.metaKey,repeat:t.repeat,shiftKey:t.shiftKey,view:t.view,charCode:t.charCode,keyCode:t.keyCode,which:t.which,...n};return new KeyboardEvent(e,o)},exports.enToFaDigits=function(e){return"string"!=typeof e&&isNaN(e)?"":e.toString().replace(/[0-9]/g,(function(e){return String.fromCharCode(e.charCodeAt(0)+1728)}))},exports.faToEnDigits=function(e){return"string"!=typeof e?"":e.replace(/[۰-۹]/g,(function(e){return String.fromCharCode(e.charCodeAt(0)-1728)}))},exports.isMobile=()=>/Mobi/i.test(window.navigator.userAgent),exports.listenAndSilentEvent=function(e,t,n,o={}){document.addEventListener(t,(t=>{t.composedPath().includes(e)&&(t.stopPropagation(),t.stopImmediatePropagation(),n(t))}),{capture:!0,...o})};
2
- //# sourceMappingURL=index.cjs.js.map
2
+ //# sourceMappingURL=index.cjs.js.map
Binary file
Binary file
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../lib/events.ts","../lib/persian-tools.ts","../lib/device-detection.ts"],"sourcesContent":["/**\r\n * add type to event target for easier access to target\r\n */\r\nexport type EventTypeWithTarget<TEvent, TTarget> = TEvent & {\r\n target: TTarget;\r\n};\r\n/**\r\n * this function will stop event from propagate even in capturing phase and will call handler only if event target is the element\r\n */\r\nexport function listenAndSilentEvent<TEvent extends Event, TTarget>(element: TTarget, eventName: string, handler: (e:TEvent) => void, options: AddEventListenerOptions = {}) {\r\n document.addEventListener(eventName, (e: TEvent) => {\r\n if (e.composedPath().includes(element as unknown as EventTarget)) {\r\n e.stopPropagation();\r\n e.stopImmediatePropagation();\r\n handler(e);\r\n }\r\n },{capture:true,...options});\r\n}\r\n/**\r\n * create a keyboardEvent based on `e` value and replace them with initObj\r\n */\r\nexport function createKeyboardEvent(eventName: string, e: KeyboardEvent, initObj: KeyboardEventInit) {\r\n const initialObject: KeyboardEventInit = {\r\n altKey: e.altKey,\r\n bubbles: e.bubbles,\r\n cancelable: e.cancelable,\r\n code: e.code,\r\n composed: e.composed,\r\n ctrlKey: e.ctrlKey,\r\n detail: e.detail,\r\n isComposing: e.isComposing,\r\n key: e.key,\r\n location: e.location,\r\n metaKey: e.metaKey,\r\n repeat: e.repeat,\r\n shiftKey: e.shiftKey,\r\n view: e.view,\r\n charCode: e.charCode,\r\n keyCode: e.keyCode,\r\n which: e.which,\r\n ...initObj\r\n };\r\n const event = new KeyboardEvent(eventName, initialObject);\r\n return event;\r\n}\r\n/**\r\n * create a InputEvent based on `e` value and replace them with initObj\r\n */\r\nexport function createInputEvent(eventName: string, e: InputEvent, initObj: InputEventInit) {\r\n const initialObject: InputEventInit = {\r\n bubbles: e.bubbles,\r\n cancelable: e.cancelable,\r\n composed: e.composed,\r\n detail: e.detail,\r\n isComposing: e.isComposing,\r\n view: e.view,\r\n which: e.which,\r\n data: e.data,\r\n dataTransfer: e.dataTransfer,\r\n inputType: e.inputType,\r\n targetRanges: typeof e.getTargetRanges() == \"function\" ? e.getTargetRanges() : [],\r\n ...initObj\r\n };\r\n const event = new InputEvent(eventName, initialObject);\r\n return event;\r\n}\r\n\r\n/**\r\n * create a InputEvent based on `e` value and replace them with initObj\r\n */\r\nexport function createFocusEvent(eventName: string, e: FocusEvent, initObj: FocusEventInit) {\r\n const initialObject: FocusEventInit = {\r\n bubbles: e.bubbles,\r\n cancelable: e.cancelable,\r\n composed: e.composed,\r\n detail: e.detail,\r\n view: e.view,\r\n which: e.which,\r\n relatedTarget: e.relatedTarget,\r\n ...initObj\r\n };\r\n const event = new FocusEvent(eventName, initialObject);\r\n return event;\r\n}","function faToEnDigits(input:string | number):string{\r\n if (typeof input !== \"string\"){\r\n return '';\r\n }\r\n const regex = /[۰-۹]/g;\r\n const result = input.replace(regex, function (w) {\r\n return String.fromCharCode(w.charCodeAt(0) - 1728);\r\n }\r\n );\r\n return result;\r\n}\r\n\r\nfunction enToFaDigits(input:string | number):string{\r\n if (typeof input !== \"string\" && isNaN(input)){\r\n return '';\r\n }\r\n const regex = /[0-9]/g;\r\n const result = input.toString().replace(regex, function (w) {\r\n return String.fromCharCode(w.charCodeAt(0) + 1728);\r\n }\r\n );\r\n return result;\r\n}\r\nexport {enToFaDigits, faToEnDigits};","export const isMobile = ()=>{\r\n return /Mobi/i.test(window.navigator.userAgent);\r\n};"],"names":["eventName","e","initObj","initialObject","bubbles","cancelable","composed","detail","view","which","relatedTarget","FocusEvent","isComposing","data","dataTransfer","inputType","targetRanges","getTargetRanges","InputEvent","altKey","code","ctrlKey","key","location","metaKey","repeat","shiftKey","charCode","keyCode","KeyboardEvent","input","isNaN","toString","replace","w","String","fromCharCode","charCodeAt","test","window","navigator","userAgent","element","handler","options","document","addEventListener","composedPath","includes","stopPropagation","stopImmediatePropagation","capture"],"mappings":"+CAsEiCA,EAAmBC,EAAeC,GACjE,MAAMC,EAAgC,CACpCC,QAASH,EAAEG,QACXC,WAAYJ,EAAEI,WACdC,SAAUL,EAAEK,SACZC,OAAQN,EAAEM,OACVC,KAAMP,EAAEO,KACRC,MAAOR,E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AAKC,OAAOC,UAAUC,wCFQjC,SAA8DC,EAAkB1C,EAAmB2C,EAA6BC,EAAmC,CAAA,GACvKC,SAASC,iBAAiB9C,GAAYC,IAChCA,EAAE8C,eAAeC,SAASN,KAC5BzC,EAAEgD,kBACFhD,EAAEiD,2BACFP,EAAQ1C,GACT,GACD,CAACkD,SAAQ,KAAQP,GACrB"}
1
+ {"version":3,"file":"index.cjs.js","names":[],"sources":["../lib/events.ts","../lib/device-detection.ts","../lib/persian-tools.ts"],"sourcesContent":["/**\r\n * add type to event target for easier access to target\r\n */\r\nexport type EventTypeWithTarget<TEvent, TTarget> = TEvent & {\r\n target: TTarget;\r\n};\r\n/**\r\n * this function will stop event from propagate even in capturing phase and will call handler only if event target is the element\r\n */\r\nexport function listenAndSilentEvent<TEvent extends Event, TTarget>(element: TTarget, eventName: string, handler: (e:TEvent) => void, options: AddEventListenerOptions = {}) {\r\n document.addEventListener(eventName, (e: TEvent) => {\r\n if (e.composedPath().includes(element as unknown as EventTarget)) {\r\n e.stopPropagation();\r\n e.stopImmediatePropagation();\r\n handler(e);\r\n }\r\n },{capture:true,...options});\r\n}\r\n/**\r\n * create a keyboardEvent based on `e` value and replace them with initObj\r\n */\r\nexport function createKeyboardEvent(eventName: string, e: KeyboardEvent, initObj: KeyboardEventInit) {\r\n const initialObject: KeyboardEventInit = {\r\n altKey: e.altKey,\r\n bubbles: e.bubbles,\r\n cancelable: e.cancelable,\r\n code: e.code,\r\n composed: e.composed,\r\n ctrlKey: e.ctrlKey,\r\n detail: e.detail,\r\n isComposing: e.isComposing,\r\n key: e.key,\r\n location: e.location,\r\n metaKey: e.metaKey,\r\n repeat: e.repeat,\r\n shiftKey: e.shiftKey,\r\n view: e.view,\r\n charCode: e.charCode,\r\n keyCode: e.keyCode,\r\n which: e.which,\r\n ...initObj\r\n };\r\n const event = new KeyboardEvent(eventName, initialObject);\r\n return event;\r\n}\r\n/**\r\n * create a InputEvent based on `e` value and replace them with initObj\r\n */\r\nexport function createInputEvent(eventName: string, e: InputEvent, initObj: InputEventInit) {\r\n const initialObject: InputEventInit = {\r\n bubbles: e.bubbles,\r\n cancelable: e.cancelable,\r\n composed: e.composed,\r\n detail: e.detail,\r\n isComposing: e.isComposing,\r\n view: e.view,\r\n which: e.which,\r\n data: e.data,\r\n dataTransfer: e.dataTransfer,\r\n inputType: e.inputType,\r\n targetRanges: typeof e.getTargetRanges() == \"function\" ? e.getTargetRanges() : [],\r\n ...initObj\r\n };\r\n const event = new InputEvent(eventName, initialObject);\r\n return event;\r\n}\r\n\r\n/**\r\n * create a InputEvent based on `e` value and replace them with initObj\r\n */\r\nexport function createFocusEvent(eventName: string, e: FocusEvent, initObj: FocusEventInit) {\r\n const initialObject: FocusEventInit = {\r\n bubbles: e.bubbles,\r\n cancelable: e.cancelable,\r\n composed: e.composed,\r\n detail: e.detail,\r\n view: e.view,\r\n which: e.which,\r\n relatedTarget: e.relatedTarget,\r\n ...initObj\r\n };\r\n const event = new FocusEvent(eventName, initialObject);\r\n return event;\r\n}","export const isMobile = ()=>{\r\n return /Mobi/i.test(window.navigator.userAgent);\r\n};","function faToEnDigits(input:string | number):string{\r\n if (typeof input !== \"string\"){\r\n return '';\r\n }\r\n const regex = /[۰-۹]/g;\r\n const result = input.replace(regex, function (w) {\r\n return String.fromCharCode(w.charCodeAt(0) - 1728);\r\n }\r\n );\r\n return result;\r\n}\r\n\r\nfunction enToFaDigits(input:string | number):string{\r\n if (typeof input !== \"string\" && isNaN(input)){\r\n return '';\r\n }\r\n const regex = /[0-9]/g;\r\n const result = input.toString().replace(regex, function (w) {\r\n return String.fromCharCode(w.charCodeAt(0) + 1728);\r\n }\r\n );\r\n return result;\r\n}\r\nexport {enToFaDigits, faToEnDigits};"],"mappings":"sCAsEM,SAA2B,EAAmB,EAAe,GACjE,MAAM,EAAgC,CACpC,QAAS,EAAE,QACX,WAAY,EAAE,WACd,SAAU,EAAE,SACZ,OAAQ,EAAE,OACV,KAAM,EAAE,KACR,MAAO,EAAE,M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,KAAQ,GACpB"}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  function e(e,t,n,o={}){document.addEventListener(t,(t=>{t.composedPath().includes(e)&&(t.stopPropagation(),t.stopImmediatePropagation(),n(t))}),{capture:!0,...o})}function t(e,t,n){const o={altKey:t.altKey,bubbles:t.bubbles,cancelable:t.cancelable,code:t.code,composed:t.composed,ctrlKey:t.ctrlKey,detail:t.detail,isComposing:t.isComposing,key:t.key,location:t.location,metaKey:t.metaKey,repeat:t.repeat,shiftKey:t.shiftKey,view:t.view,charCode:t.charCode,keyCode:t.keyCode,which:t.which,...n};return new KeyboardEvent(e,o)}function n(e,t,n){const o={bubbles:t.bubbles,cancelable:t.cancelable,composed:t.composed,detail:t.detail,isComposing:t.isComposing,view:t.view,which:t.which,data:t.data,dataTransfer:t.dataTransfer,inputType:t.inputType,targetRanges:"function"==typeof t.getTargetRanges()?t.getTargetRanges():[],...n};return new InputEvent(e,o)}function o(e,t,n){const o={bubbles:t.bubbles,cancelable:t.cancelable,composed:t.composed,detail:t.detail,view:t.view,which:t.which,relatedTarget:t.relatedTarget,...n};return new FocusEvent(e,o)}const a=()=>/Mobi/i.test(window.navigator.userAgent);function i(e){if("string"!=typeof e)return"";return e.replace(/[۰-۹]/g,(function(e){return String.fromCharCode(e.charCodeAt(0)-1728)}))}function r(e){if("string"!=typeof e&&isNaN(e))return"";return e.toString().replace(/[0-9]/g,(function(e){return String.fromCharCode(e.charCodeAt(0)+1728)}))}export{o as createFocusEvent,n as createInputEvent,t as createKeyboardEvent,r as enToFaDigits,i as faToEnDigits,a as isMobile,e as listenAndSilentEvent};
2
- //# sourceMappingURL=index.js.map
2
+ //# sourceMappingURL=index.js.map
package/dist/index.js.br CHANGED
Binary file
package/dist/index.js.gz CHANGED
Binary file
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../lib/events.ts","../lib/device-detection.ts","../lib/persian-tools.ts"],"sourcesContent":["/**\r\n * add type to event target for easier access to target\r\n */\r\nexport type EventTypeWithTarget<TEvent, TTarget> = TEvent & {\r\n target: TTarget;\r\n};\r\n/**\r\n * this function will stop event from propagate even in capturing phase and will call handler only if event target is the element\r\n */\r\nexport function listenAndSilentEvent<TEvent extends Event, TTarget>(element: TTarget, eventName: string, handler: (e:TEvent) => void, options: AddEventListenerOptions = {}) {\r\n document.addEventListener(eventName, (e: TEvent) => {\r\n if (e.composedPath().includes(element as unknown as EventTarget)) {\r\n e.stopPropagation();\r\n e.stopImmediatePropagation();\r\n handler(e);\r\n }\r\n },{capture:true,...options});\r\n}\r\n/**\r\n * create a keyboardEvent based on `e` value and replace them with initObj\r\n */\r\nexport function createKeyboardEvent(eventName: string, e: KeyboardEvent, initObj: KeyboardEventInit) {\r\n const initialObject: KeyboardEventInit = {\r\n altKey: e.altKey,\r\n bubbles: e.bubbles,\r\n cancelable: e.cancelable,\r\n code: e.code,\r\n composed: e.composed,\r\n ctrlKey: e.ctrlKey,\r\n detail: e.detail,\r\n isComposing: e.isComposing,\r\n key: e.key,\r\n location: e.location,\r\n metaKey: e.metaKey,\r\n repeat: e.repeat,\r\n shiftKey: e.shiftKey,\r\n view: e.view,\r\n charCode: e.charCode,\r\n keyCode: e.keyCode,\r\n which: e.which,\r\n ...initObj\r\n };\r\n const event = new KeyboardEvent(eventName, initialObject);\r\n return event;\r\n}\r\n/**\r\n * create a InputEvent based on `e` value and replace them with initObj\r\n */\r\nexport function createInputEvent(eventName: string, e: InputEvent, initObj: InputEventInit) {\r\n const initialObject: InputEventInit = {\r\n bubbles: e.bubbles,\r\n cancelable: e.cancelable,\r\n composed: e.composed,\r\n detail: e.detail,\r\n isComposing: e.isComposing,\r\n view: e.view,\r\n which: e.which,\r\n data: e.data,\r\n dataTransfer: e.dataTransfer,\r\n inputType: e.inputType,\r\n targetRanges: typeof e.getTargetRanges() == \"function\" ? e.getTargetRanges() : [],\r\n ...initObj\r\n };\r\n const event = new InputEvent(eventName, initialObject);\r\n return event;\r\n}\r\n\r\n/**\r\n * create a InputEvent based on `e` value and replace them with initObj\r\n */\r\nexport function createFocusEvent(eventName: string, e: FocusEvent, initObj: FocusEventInit) {\r\n const initialObject: FocusEventInit = {\r\n bubbles: e.bubbles,\r\n cancelable: e.cancelable,\r\n composed: e.composed,\r\n detail: e.detail,\r\n view: e.view,\r\n which: e.which,\r\n relatedTarget: e.relatedTarget,\r\n ...initObj\r\n };\r\n const event = new FocusEvent(eventName, initialObject);\r\n return event;\r\n}","export const isMobile = ()=>{\r\n return /Mobi/i.test(window.navigator.userAgent);\r\n};","function faToEnDigits(input:string | number):string{\r\n if (typeof input !== \"string\"){\r\n return '';\r\n }\r\n const regex = /[۰-۹]/g;\r\n const result = input.replace(regex, function (w) {\r\n return String.fromCharCode(w.charCodeAt(0) - 1728);\r\n }\r\n );\r\n return result;\r\n}\r\n\r\nfunction enToFaDigits(input:string | number):string{\r\n if (typeof input !== \"string\" && isNaN(input)){\r\n return '';\r\n }\r\n const regex = /[0-9]/g;\r\n const result = input.toString().replace(regex, function (w) {\r\n return String.fromCharCode(w.charCodeAt(0) + 1728);\r\n }\r\n );\r\n return result;\r\n}\r\nexport {enToFaDigits, faToEnDigits};"],"names":["listenAndSilentEvent","element","eventName","handler","options","document","addEventListener","e","composedPath","includes","stopPropagation","stopImmediatePropagation","capture","createKeyboardEvent","initObj","initialObject","altKey","bubbles","cancelable","code","composed","ctrlKey","detail","isComposing","key","location","metaKey","repeat","shiftKey","view","charCode","keyCode","which","KeyboardEvent","createInputEvent","data","dataTransfer","inputType","targetRanges","getTargetRanges","InputEvent","createFocusEvent","relatedTarget","FocusEvent","isMobile","test","window","navigator","userAgent","faToEnDigits","input","replace","w","String","fromCharCode","charCodeAt","enToFaDigits","isNaN","toString"],"mappings":"AASM,SAAUA,EAAoDC,EAAkBC,EAAmBC,EAA6BC,EAAmC,CAAA,GACvKC,SAASC,iBAAiBJ,GAAYK,IAChCA,EAAEC,eAAeC,SAASR,KAC5BM,EAAEG,kBACFH,EA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,EAAaC,GACpB,GAAqB,iBAAVA,EACT,MAAO,GAOT,OAJeA,EAAMC,QADP,UACsB,SAAUC,GAC5C,OAAOC,OAAOC,aAAaF,EAAEG,WAAW,GAAK,KAC/C,GAGF,CAEA,SAASC,EAAaN,GACpB,GAAqB,iBAAVA,GAAsBO,MAAMP,GACrC,MAAO,GAOT,OAJeA,EAAMQ,WAAWP,QADlB,UACiC,SAAUC,GACvD,OAAOC,OAAOC,aAAaF,EAAEG,WAAW,GAAK,KAC/C,GAGF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../lib/events.ts","../lib/device-detection.ts","../lib/persian-tools.ts"],"sourcesContent":["/**\r\n * add type to event target for easier access to target\r\n */\r\nexport type EventTypeWithTarget<TEvent, TTarget> = TEvent & {\r\n target: TTarget;\r\n};\r\n/**\r\n * this function will stop event from propagate even in capturing phase and will call handler only if event target is the element\r\n */\r\nexport function listenAndSilentEvent<TEvent extends Event, TTarget>(element: TTarget, eventName: string, handler: (e:TEvent) => void, options: AddEventListenerOptions = {}) {\r\n document.addEventListener(eventName, (e: TEvent) => {\r\n if (e.composedPath().includes(element as unknown as EventTarget)) {\r\n e.stopPropagation();\r\n e.stopImmediatePropagation();\r\n handler(e);\r\n }\r\n },{capture:true,...options});\r\n}\r\n/**\r\n * create a keyboardEvent based on `e` value and replace them with initObj\r\n */\r\nexport function createKeyboardEvent(eventName: string, e: KeyboardEvent, initObj: KeyboardEventInit) {\r\n const initialObject: KeyboardEventInit = {\r\n altKey: e.altKey,\r\n bubbles: e.bubbles,\r\n cancelable: e.cancelable,\r\n code: e.code,\r\n composed: e.composed,\r\n ctrlKey: e.ctrlKey,\r\n detail: e.detail,\r\n isComposing: e.isComposing,\r\n key: e.key,\r\n location: e.location,\r\n metaKey: e.metaKey,\r\n repeat: e.repeat,\r\n shiftKey: e.shiftKey,\r\n view: e.view,\r\n charCode: e.charCode,\r\n keyCode: e.keyCode,\r\n which: e.which,\r\n ...initObj\r\n };\r\n const event = new KeyboardEvent(eventName, initialObject);\r\n return event;\r\n}\r\n/**\r\n * create a InputEvent based on `e` value and replace them with initObj\r\n */\r\nexport function createInputEvent(eventName: string, e: InputEvent, initObj: InputEventInit) {\r\n const initialObject: InputEventInit = {\r\n bubbles: e.bubbles,\r\n cancelable: e.cancelable,\r\n composed: e.composed,\r\n detail: e.detail,\r\n isComposing: e.isComposing,\r\n view: e.view,\r\n which: e.which,\r\n data: e.data,\r\n dataTransfer: e.dataTransfer,\r\n inputType: e.inputType,\r\n targetRanges: typeof e.getTargetRanges() == \"function\" ? e.getTargetRanges() : [],\r\n ...initObj\r\n };\r\n const event = new InputEvent(eventName, initialObject);\r\n return event;\r\n}\r\n\r\n/**\r\n * create a InputEvent based on `e` value and replace them with initObj\r\n */\r\nexport function createFocusEvent(eventName: string, e: FocusEvent, initObj: FocusEventInit) {\r\n const initialObject: FocusEventInit = {\r\n bubbles: e.bubbles,\r\n cancelable: e.cancelable,\r\n composed: e.composed,\r\n detail: e.detail,\r\n view: e.view,\r\n which: e.which,\r\n relatedTarget: e.relatedTarget,\r\n ...initObj\r\n };\r\n const event = new FocusEvent(eventName, initialObject);\r\n return event;\r\n}","export const isMobile = ()=>{\r\n return /Mobi/i.test(window.navigator.userAgent);\r\n};","function faToEnDigits(input:string | number):string{\r\n if (typeof input !== \"string\"){\r\n return '';\r\n }\r\n const regex = /[۰-۹]/g;\r\n const result = input.replace(regex, function (w) {\r\n return String.fromCharCode(w.charCodeAt(0) - 1728);\r\n }\r\n );\r\n return result;\r\n}\r\n\r\nfunction enToFaDigits(input:string | number):string{\r\n if (typeof input !== \"string\" && isNaN(input)){\r\n return '';\r\n }\r\n const regex = /[0-9]/g;\r\n const result = input.toString().replace(regex, function (w) {\r\n return String.fromCharCode(w.charCodeAt(0) + 1728);\r\n }\r\n );\r\n return result;\r\n}\r\nexport {enToFaDigits, faToEnDigits};"],"mappings":"AASM,SAAU,EAAoD,EAAkB,EAAmB,EAA6B,EAAmC,CAAE,GACzK,SAAS,iBA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a,GACpB,GAAqB,iBAAV,GAAsB,MAAM,GACrC,MAAO,GAOT,OAJe,EAAM,WAAW,QADlB,UACiC,SAAU,GACvD,OAAO,OAAO,aAAa,EAAE,WAAW,GAAK,KAC9C,GAGF"}
package/dist/index.umd.js CHANGED
@@ -1,2 +1,2 @@
1
1
  !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).JBCore={})}(this,(function(e){"use strict";e.createFocusEvent=function(e,t,n){const o={bubbles:t.bubbles,cancelable:t.cancelable,composed:t.composed,detail:t.detail,view:t.view,which:t.which,relatedTarget:t.relatedTarget,...n};return new FocusEvent(e,o)},e.createInputEvent=function(e,t,n){const o={bubbles:t.bubbles,cancelable:t.cancelable,composed:t.composed,detail:t.detail,isComposing:t.isComposing,view:t.view,which:t.which,data:t.data,dataTransfer:t.dataTransfer,inputType:t.inputType,targetRanges:"function"==typeof t.getTargetRanges()?t.getTargetRanges():[],...n};return new InputEvent(e,o)},e.createKeyboardEvent=function(e,t,n){const o={altKey:t.altKey,bubbles:t.bubbles,cancelable:t.cancelable,code:t.code,composed:t.composed,ctrlKey:t.ctrlKey,detail:t.detail,isComposing:t.isComposing,key:t.key,location:t.location,metaKey:t.metaKey,repeat:t.repeat,shiftKey:t.shiftKey,view:t.view,charCode:t.charCode,keyCode:t.keyCode,which:t.which,...n};return new KeyboardEvent(e,o)},e.enToFaDigits=function(e){return"string"!=typeof e&&isNaN(e)?"":e.toString().replace(/[0-9]/g,(function(e){return String.fromCharCode(e.charCodeAt(0)+1728)}))},e.faToEnDigits=function(e){return"string"!=typeof e?"":e.replace(/[۰-۹]/g,(function(e){return String.fromCharCode(e.charCodeAt(0)-1728)}))},e.isMobile=()=>/Mobi/i.test(window.navigator.userAgent),e.listenAndSilentEvent=function(e,t,n,o={}){document.addEventListener(t,(t=>{t.composedPath().includes(e)&&(t.stopPropagation(),t.stopImmediatePropagation(),n(t))}),{capture:!0,...o})}}));
2
- //# sourceMappingURL=index.umd.js.map
2
+ //# sourceMappingURL=index.umd.js.map
Binary file
Binary file
@@ -1 +1 @@
1
- {"version":3,"file":"index.umd.js","sources":["../lib/events.ts","../lib/persian-tools.ts","../lib/device-detection.ts"],"sourcesContent":["/**\r\n * add type to event target for easier access to target\r\n */\r\nexport type EventTypeWithTarget<TEvent, TTarget> = TEvent & {\r\n target: TTarget;\r\n};\r\n/**\r\n * this function will stop event from propagate even in capturing phase and will call handler only if event target is the element\r\n */\r\nexport function listenAndSilentEvent<TEvent extends Event, TTarget>(element: TTarget, eventName: string, handler: (e:TEvent) => void, options: AddEventListenerOptions = {}) {\r\n document.addEventListener(eventName, (e: TEvent) => {\r\n if (e.composedPath().includes(element as unknown as EventTarget)) {\r\n e.stopPropagation();\r\n e.stopImmediatePropagation();\r\n handler(e);\r\n }\r\n },{capture:true,...options});\r\n}\r\n/**\r\n * create a keyboardEvent based on `e` value and replace them with initObj\r\n */\r\nexport function createKeyboardEvent(eventName: string, e: KeyboardEvent, initObj: KeyboardEventInit) {\r\n const initialObject: KeyboardEventInit = {\r\n altKey: e.altKey,\r\n bubbles: e.bubbles,\r\n cancelable: e.cancelable,\r\n code: e.code,\r\n composed: e.composed,\r\n ctrlKey: e.ctrlKey,\r\n detail: e.detail,\r\n isComposing: e.isComposing,\r\n key: e.key,\r\n location: e.location,\r\n metaKey: e.metaKey,\r\n repeat: e.repeat,\r\n shiftKey: e.shiftKey,\r\n view: e.view,\r\n charCode: e.charCode,\r\n keyCode: e.keyCode,\r\n which: e.which,\r\n ...initObj\r\n };\r\n const event = new KeyboardEvent(eventName, initialObject);\r\n return event;\r\n}\r\n/**\r\n * create a InputEvent based on `e` value and replace them with initObj\r\n */\r\nexport function createInputEvent(eventName: string, e: InputEvent, initObj: InputEventInit) {\r\n const initialObject: InputEventInit = {\r\n bubbles: e.bubbles,\r\n cancelable: e.cancelable,\r\n composed: e.composed,\r\n detail: e.detail,\r\n isComposing: e.isComposing,\r\n view: e.view,\r\n which: e.which,\r\n data: e.data,\r\n dataTransfer: e.dataTransfer,\r\n inputType: e.inputType,\r\n targetRanges: typeof e.getTargetRanges() == \"function\" ? e.getTargetRanges() : [],\r\n ...initObj\r\n };\r\n const event = new InputEvent(eventName, initialObject);\r\n return event;\r\n}\r\n\r\n/**\r\n * create a InputEvent based on `e` value and replace them with initObj\r\n */\r\nexport function createFocusEvent(eventName: string, e: FocusEvent, initObj: FocusEventInit) {\r\n const initialObject: FocusEventInit = {\r\n bubbles: e.bubbles,\r\n cancelable: e.cancelable,\r\n composed: e.composed,\r\n detail: e.detail,\r\n view: e.view,\r\n which: e.which,\r\n relatedTarget: e.relatedTarget,\r\n ...initObj\r\n };\r\n const event = new FocusEvent(eventName, initialObject);\r\n return event;\r\n}","function faToEnDigits(input:string | number):string{\r\n if (typeof input !== \"string\"){\r\n return '';\r\n }\r\n const regex = /[۰-۹]/g;\r\n const result = input.replace(regex, function (w) {\r\n return String.fromCharCode(w.charCodeAt(0) - 1728);\r\n }\r\n );\r\n return result;\r\n}\r\n\r\nfunction enToFaDigits(input:string | number):string{\r\n if (typeof input !== \"string\" && isNaN(input)){\r\n return '';\r\n }\r\n const regex = /[0-9]/g;\r\n const result = input.toString().replace(regex, function (w) {\r\n return String.fromCharCode(w.charCodeAt(0) + 1728);\r\n }\r\n );\r\n return result;\r\n}\r\nexport {enToFaDigits, faToEnDigits};","export const isMobile = ()=>{\r\n return /Mobi/i.test(window.navigator.userAgent);\r\n};"],"names":["eventName","e","initObj","initialObject","bubbles","cancelable","composed","detail","view","which","relatedTarget","FocusEvent","isComposing","data","dataTransfer","inputType","targetRanges","getTargetRanges","InputEvent","altKey","code","ctrlKey","key","location","metaKey","repeat","shiftKey","charCode","keyCode","KeyboardEvent","input","isNaN","toString","replace","w","String","fromCharCode","charCodeAt","test","window","navigator","userAgent","element","handler","options","document","addEventListener","composedPath","includes","stopPropagation","stopImmediatePropagation","capture"],"mappings":"0QAsEiCA,E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A,SAAsBP,GACpB,MAAqB,iBAAVA,EACF,GAGMA,EAAMG,QADP,UACsB,SAAUC,GAC5C,OAAOC,OAAOC,aAAaF,EAAEG,WAAW,GAAK,KAC/C,GAGF,aCVwB,IACf,QAAQC,KAAKC,OAAOC,UAAUC,kCFQjC,SAA8DC,EAAkB1C,EAAmB2C,EAA6BC,EAAmC,CAAA,GACvKC,SAASC,iBAAiB9C,GAAYC,IAChCA,EAAE8C,eAAeC,SAASN,KAC5BzC,EAAEgD,kBACFhD,EAAEiD,2BACFP,EAAQ1C,GACT,GACD,CAACkD,SAAQ,KAAQP,GACrB"}
1
+ {"version":3,"file":"index.umd.js","names":[],"sources":["../lib/events.ts","../lib/device-detection.ts","../lib/persian-tools.ts"],"sourcesContent":["/**\r\n * add type to event target for easier access to target\r\n */\r\nexport type EventTypeWithTarget<TEvent, TTarget> = TEvent & {\r\n target: TTarget;\r\n};\r\n/**\r\n * this function will stop event from propagate even in capturing phase and will call handler only if event target is the element\r\n */\r\nexport function listenAndSilentEvent<TEvent extends Event, TTarget>(element: TTarget, eventName: string, handler: (e:TEvent) => void, options: AddEventListenerOptions = {}) {\r\n document.addEventListener(eventName, (e: TEvent) => {\r\n if (e.composedPath().includes(element as unknown as EventTarget)) {\r\n e.stopPropagation();\r\n e.stopImmediatePropagation();\r\n handler(e);\r\n }\r\n },{capture:true,...options});\r\n}\r\n/**\r\n * create a keyboardEvent based on `e` value and replace them with initObj\r\n */\r\nexport function createKeyboardEvent(eventName: string, e: KeyboardEvent, initObj: KeyboardEventInit) {\r\n const initialObject: KeyboardEventInit = {\r\n altKey: e.altKey,\r\n bubbles: e.bubbles,\r\n cancelable: e.cancelable,\r\n code: e.code,\r\n composed: e.composed,\r\n ctrlKey: e.ctrlKey,\r\n detail: e.detail,\r\n isComposing: e.isComposing,\r\n key: e.key,\r\n location: e.location,\r\n metaKey: e.metaKey,\r\n repeat: e.repeat,\r\n shiftKey: e.shiftKey,\r\n view: e.view,\r\n charCode: e.charCode,\r\n keyCode: e.keyCode,\r\n which: e.which,\r\n ...initObj\r\n };\r\n const event = new KeyboardEvent(eventName, initialObject);\r\n return event;\r\n}\r\n/**\r\n * create a InputEvent based on `e` value and replace them with initObj\r\n */\r\nexport function createInputEvent(eventName: string, e: InputEvent, initObj: InputEventInit) {\r\n const initialObject: InputEventInit = {\r\n bubbles: e.bubbles,\r\n cancelable: e.cancelable,\r\n composed: e.composed,\r\n detail: e.detail,\r\n isComposing: e.isComposing,\r\n view: e.view,\r\n which: e.which,\r\n data: e.data,\r\n dataTransfer: e.dataTransfer,\r\n inputType: e.inputType,\r\n targetRanges: typeof e.getTargetRanges() == \"function\" ? e.getTargetRanges() : [],\r\n ...initObj\r\n };\r\n const event = new InputEvent(eventName, initialObject);\r\n return event;\r\n}\r\n\r\n/**\r\n * create a InputEvent based on `e` value and replace them with initObj\r\n */\r\nexport function createFocusEvent(eventName: string, e: FocusEvent, initObj: FocusEventInit) {\r\n const initialObject: FocusEventInit = {\r\n bubbles: e.bubbles,\r\n cancelable: e.cancelable,\r\n composed: e.composed,\r\n detail: e.detail,\r\n view: e.view,\r\n which: e.which,\r\n relatedTarget: e.relatedTarget,\r\n ...initObj\r\n };\r\n const event = new FocusEvent(eventName, initialObject);\r\n return event;\r\n}","export const isMobile = ()=>{\r\n return /Mobi/i.test(window.navigator.userAgent);\r\n};","function faToEnDigits(input:string | number):string{\r\n if (typeof input !== \"string\"){\r\n return '';\r\n }\r\n const regex = /[۰-۹]/g;\r\n const result = input.replace(regex, function (w) {\r\n return String.fromCharCode(w.charCodeAt(0) - 1728);\r\n }\r\n );\r\n return result;\r\n}\r\n\r\nfunction enToFaDigits(input:string | number):string{\r\n if (typeof input !== \"string\" && isNaN(input)){\r\n return '';\r\n }\r\n const regex = /[0-9]/g;\r\n const result = input.toString().replace(regex, function (w) {\r\n return String.fromCharCode(w.charCodeAt(0) + 1728);\r\n }\r\n );\r\n return result;\r\n}\r\nexport {enToFaDigits, faToEnDigits};"],"mappings":"iQA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8D,EAAkB,EAAmB,EAA6B,EAAmC,CAAE,GACzK,SAAS,iBAAiB,GAAY,IAChC,EAAE,eAAe,SAAS,KAC5B,EAAE,kBACF,EAAE,2BACF,EAAQ,GACT,GACD,CAAC,SAAQ,KAAQ,GACpB"}
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "react component",
15
15
  "event"
16
16
  ],
17
- "version": "0.2.0",
17
+ "version": "0.3.0",
18
18
  "bugs": "https://github.com/javadbat/jb-core/issues",
19
19
  "license": "MIT",
20
20
  "files": [
@@ -22,6 +22,7 @@
22
22
  "README.md",
23
23
  "lib/",
24
24
  "dist/",
25
+ "styles/",
25
26
  "react/",
26
27
  "react/dist/"
27
28
  ],
@@ -1,27 +1,71 @@
1
- 'use strict';
1
+ "use strict";
2
+ //#region rolldown:runtime
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
2
23
 
3
- var react = require('react');
24
+ //#endregion
25
+ const react = __toESM(require("react"));
4
26
 
5
- function useEvent(ref, event, handler, passive = false) {
6
- const internalHandler = react.useCallback((e) => {
7
- if (ref.current && typeof handler == "function") {
8
- handler(e);
9
- }
10
- }, [ref, handler]);
11
- react.useEffect(() => {
12
- const dom = ref.current;
13
- if (dom) {
14
- // initiate the event handler
15
- dom.addEventListener(event, internalHandler, { passive, capture: false });
16
- }
17
- // this will clean up the event every time the component is re-rendered
18
- return function cleanup() {
19
- if (dom) {
20
- dom.removeEventListener(event, internalHandler, { passive, capture: false });
21
- }
22
- };
23
- }, [ref, event, handler, passive]);
27
+ //#region web-component/jb-core/react/lib/hooks/use-event.ts
28
+ function useEvent(ref, event, handler, passive = false) {
29
+ const internalHandler = (0, react.useCallback)((e) => {
30
+ if (ref.current && typeof handler == "function") handler(e);
31
+ }, [ref, handler]);
32
+ (0, react.useEffect)(() => {
33
+ const dom = ref.current;
34
+ if (dom) dom.addEventListener(event, internalHandler, {
35
+ passive,
36
+ capture: false
37
+ });
38
+ return function cleanup() {
39
+ if (dom) dom.removeEventListener(event, internalHandler, {
40
+ passive,
41
+ capture: false
42
+ });
43
+ };
44
+ }, [
45
+ ref,
46
+ event,
47
+ handler,
48
+ passive
49
+ ]);
24
50
  }
25
51
 
26
- exports.useEvent = useEvent;
27
- //# sourceMappingURL=index.cjs.js.map
52
+ //#endregion
53
+ //#region web-component/jb-core/react/lib/hooks/useLazyRef.ts
54
+ const useLazyRef = (initValFunc) => {
55
+ const ref = (0, react.useRef)(null);
56
+ if (ref.current === null) ref.current = initValFunc();
57
+ return ref;
58
+ };
59
+
60
+ //#endregion
61
+ //#region web-component/jb-core/react/lib/hooks/useInstance.ts
62
+ const useInstance = (Store, initializers) => {
63
+ const vm = useLazyRef(() => new Store(...initializers));
64
+ return vm.current;
65
+ };
66
+
67
+ //#endregion
68
+ exports.useEvent = useEvent
69
+ exports.useInstance = useInstance
70
+ exports.useLazyRef = useLazyRef
71
+ //# sourceMappingURL=index.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../lib/use-event.ts"],"sourcesContent":["import { useCallback, useEffect } from \"react\";\r\n\r\nexport function useEvent<TRef extends React.MutableRefObject<any|null>,TEvent>(ref:TRef, event:string, handler?:(e:TEvent)=>void, passive = false) {\r\n const internalHandler = useCallback((e:TEvent)=>{\r\n if(ref.current && typeof handler == \"function\"){\r\n handler(e);\r\n }\r\n },[ref,handler]);\r\n useEffect(() => {\r\n const dom = ref.current;\r\n if (dom) {\r\n // initiate the event handler\r\n dom.addEventListener(event, internalHandler, { passive, capture:false }); \r\n }\r\n // this will clean up the event every time the component is re-rendered\r\n return function cleanup() {\r\n if(dom){\r\n dom.removeEventListener(event, internalHandler, {passive, capture:false});\r\n }\r\n };\r\n },[ref,event,handler,passive]);\r\n}"],"names":["useCallback","useEffect"],"mappings":";;;;AAEM,SAAU,QAAQ,CAAuD,GAAQ,EAAE,KAAY,EAAE,OAAyB,EAAE,OAAO,GAAG,KAAK,EAAA;AAC/I,IAAA,MAAM,eAAe,GAAGA,iBAAW,CAAC,CAAC,CAAQ,KAAG;QAC9C,IAAG,GAAG,CAAC,OAAO,IAAI,OAAO,OAAO,IAAI,UAAU,EAAC;YAC7C,OAAO,CAAC,CAAC,CAAC,CAAC;AACZ,SAAA;AACH,KAAC,EAAC,CAAC,GAAG,EAAC,OAAO,CAAC,CAAC,CAAC;IACjBC,eAAS,CAAC,MAAK;AACb,QAAA,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC;AACxB,QAAA,IAAI,GAAG,EAAE;;AAEP,YAAA,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,eAAe,EAAE,EAAE,OAAO,EAAE,OAAO,EAAC,KAAK,EAAE,CAAC,CAAC;AAC1E,SAAA;;AAED,QAAA,OAAO,SAAS,OAAO,GAAA;AACrB,YAAA,IAAG,GAAG,EAAC;AACL,gBAAA,GAAG,CAAC,mBAAmB,CAAC,KAAK,EAAE,eAAe,EAAE,EAAC,OAAO,EAAE,OAAO,EAAC,KAAK,EAAC,CAAC,CAAC;AAC3E,aAAA;AACH,SAAC,CAAC;KACH,EAAC,CAAC,GAAG,EAAC,KAAK,EAAC,OAAO,EAAC,OAAO,CAAC,CAAC,CAAC;AACjC;;;;"}
1
+ {"version":3,"file":"index.cjs.js","names":[],"sources":["../lib/hooks/use-event.ts","../lib/hooks/useLazyRef.ts","../lib/hooks/useInstance.ts"],"sourcesContent":["import { useCallback, useEffect } from \"react\";\r\n\r\nexport function useEvent<TRef extends React.MutableRefObject<any|null>,TEvent>(ref:TRef, event:string, handler?:(e:TEvent)=>void, passive = false) {\r\n const internalHandler = useCallback((e:TEvent)=>{\r\n if(ref.current && typeof handler == \"function\"){\r\n handler(e);\r\n }\r\n },[ref,handler]);\r\n useEffect(() => {\r\n const dom = ref.current;\r\n if (dom) {\r\n // initiate the event handler\r\n dom.addEventListener(event, internalHandler, { passive, capture:false }); \r\n }\r\n // this will clean up the event every time the component is re-rendered\r\n return function cleanup() {\r\n if(dom){\r\n dom.removeEventListener(event, internalHandler, {passive, capture:false});\r\n }\r\n };\r\n },[ref,event,handler,passive]);\r\n}","import { MutableRefObject, useRef } from \"react\";\r\n\r\ntype InitFunc<T> = ()=>T\r\nexport const useLazyRef = <T>(initValFunc:InitFunc<T>) => {\r\n const ref:MutableRefObject<any> = useRef(null);\r\n if (ref.current === null) {\r\n ref.current = initValFunc();\r\n }\r\n return ref;\r\n};\r\n\r\n// used by: useMobx","import { useLazyRef } from \"./useLazyRef.js\";\r\n\r\n\r\ntype BaseConstructableClass<T = any> = new (...args: any[]) => T;\r\n\r\n// Type to get the constructor parameters of a class\r\ntype Initializers<T extends BaseConstructableClass> = ConstructorParameters<T>;\r\n\r\n// useInstance function that accepts a Store class and its initializers\r\n/**\r\n * create a instance of an class with lazy initialization\r\n * @param Store class to create instance of\r\n * @param initializers initializers to pass to the class constructor\r\n * @returns instance of the class\r\n */\r\nexport const useInstance = <T extends BaseConstructableClass>(Store: T, initializers: Initializers<T>): InstanceType<T> => {\r\n const vm = useLazyRef(() => new Store(...initializers));\r\n return vm.current;\r\n};\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAEM,SAAU,SAA+D,KAAU,OAAc,SAA2B,UAAU,OAAK;CAC/I,MAAM,kBAAkB,uBAAY,CAAC,MAAW;AAC9C,MAAG,IAAI,kBAAkB,WAAW,WAClC,SAAQ,EAAE;CAEb,GAAC,CAAC,KAAI,OAAQ,EAAC;AAChB,sBAAU,MAAK;EACb,MAAM,MAAM,IAAI;AAChB,MAAI,IAEF,KAAI,iBAAiB,OAAO,iBAAiB;GAAE;GAAS,SAAQ;EAAO,EAAC;AAG1E,SAAO,SAAS,UAAO;AACrB,OAAG,IACD,KAAI,oBAAoB,OAAO,iBAAiB;IAAC;IAAS,SAAQ;GAAM,EAAC;EAE5E;CACF,GAAC;EAAC;EAAI;EAAM;EAAQ;CAAQ,EAAC;AAC/B;;;;MClBY,aAAa,CAAI,gBAA2B;CACvD,MAAM,MAA4B,kBAAO,KAAK;AAC9C,KAAI,IAAI,YAAY,KAClB,KAAI,UAAU,aAAa;AAE7B,QAAO;AACR;;;;MCMY,cAAc,CAAmC,OAAU,iBAAkD;CACxH,MAAM,KAAK,WAAW,MAAM,IAAI,MAAM,GAAG,cAAc;AACvD,QAAO,GAAG;AACX"}
@@ -1,25 +1,45 @@
1
- import { useCallback, useEffect } from 'react';
1
+ import { useCallback, useEffect, useRef } from "react";
2
2
 
3
- function useEvent(ref, event, handler, passive = false) {
4
- const internalHandler = useCallback((e) => {
5
- if (ref.current && typeof handler == "function") {
6
- handler(e);
7
- }
8
- }, [ref, handler]);
9
- useEffect(() => {
10
- const dom = ref.current;
11
- if (dom) {
12
- // initiate the event handler
13
- dom.addEventListener(event, internalHandler, { passive, capture: false });
14
- }
15
- // this will clean up the event every time the component is re-rendered
16
- return function cleanup() {
17
- if (dom) {
18
- dom.removeEventListener(event, internalHandler, { passive, capture: false });
19
- }
20
- };
21
- }, [ref, event, handler, passive]);
3
+ //#region web-component/jb-core/react/lib/hooks/use-event.ts
4
+ function useEvent(ref, event, handler, passive = false) {
5
+ const internalHandler = useCallback((e) => {
6
+ if (ref.current && typeof handler == "function") handler(e);
7
+ }, [ref, handler]);
8
+ useEffect(() => {
9
+ const dom = ref.current;
10
+ if (dom) dom.addEventListener(event, internalHandler, {
11
+ passive,
12
+ capture: false
13
+ });
14
+ return function cleanup() {
15
+ if (dom) dom.removeEventListener(event, internalHandler, {
16
+ passive,
17
+ capture: false
18
+ });
19
+ };
20
+ }, [
21
+ ref,
22
+ event,
23
+ handler,
24
+ passive
25
+ ]);
22
26
  }
23
27
 
24
- export { useEvent };
25
- //# sourceMappingURL=index.js.map
28
+ //#endregion
29
+ //#region web-component/jb-core/react/lib/hooks/useLazyRef.ts
30
+ const useLazyRef = (initValFunc) => {
31
+ const ref = useRef(null);
32
+ if (ref.current === null) ref.current = initValFunc();
33
+ return ref;
34
+ };
35
+
36
+ //#endregion
37
+ //#region web-component/jb-core/react/lib/hooks/useInstance.ts
38
+ const useInstance = (Store, initializers) => {
39
+ const vm = useLazyRef(() => new Store(...initializers));
40
+ return vm.current;
41
+ };
42
+
43
+ //#endregion
44
+ export { useEvent, useInstance, useLazyRef };
45
+ //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../lib/use-event.ts"],"sourcesContent":["import { useCallback, useEffect } from \"react\";\r\n\r\nexport function useEvent<TRef extends React.MutableRefObject<any|null>,TEvent>(ref:TRef, event:string, handler?:(e:TEvent)=>void, passive = false) {\r\n const internalHandler = useCallback((e:TEvent)=>{\r\n if(ref.current && typeof handler == \"function\"){\r\n handler(e);\r\n }\r\n },[ref,handler]);\r\n useEffect(() => {\r\n const dom = ref.current;\r\n if (dom) {\r\n // initiate the event handler\r\n dom.addEventListener(event, internalHandler, { passive, capture:false }); \r\n }\r\n // this will clean up the event every time the component is re-rendered\r\n return function cleanup() {\r\n if(dom){\r\n dom.removeEventListener(event, internalHandler, {passive, capture:false});\r\n }\r\n };\r\n },[ref,event,handler,passive]);\r\n}"],"names":[],"mappings":";;AAEM,SAAU,QAAQ,CAAuD,GAAQ,EAAE,KAAY,EAAE,OAAyB,EAAE,OAAO,GAAG,KAAK,EAAA;AAC/I,IAAA,MAAM,eAAe,GAAG,WAAW,CAAC,CAAC,CAAQ,KAAG;QAC9C,IAAG,GAAG,CAAC,OAAO,IAAI,OAAO,OAAO,IAAI,UAAU,EAAC;YAC7C,OAAO,CAAC,CAAC,CAAC,CAAC;AACZ,SAAA;AACH,KAAC,EAAC,CAAC,GAAG,EAAC,OAAO,CAAC,CAAC,CAAC;IACjB,SAAS,CAAC,MAAK;AACb,QAAA,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC;AACxB,QAAA,IAAI,GAAG,EAAE;;AAEP,YAAA,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,eAAe,EAAE,EAAE,OAAO,EAAE,OAAO,EAAC,KAAK,EAAE,CAAC,CAAC;AAC1E,SAAA;;AAED,QAAA,OAAO,SAAS,OAAO,GAAA;AACrB,YAAA,IAAG,GAAG,EAAC;AACL,gBAAA,GAAG,CAAC,mBAAmB,CAAC,KAAK,EAAE,eAAe,EAAE,EAAC,OAAO,EAAE,OAAO,EAAC,KAAK,EAAC,CAAC,CAAC;AAC3E,aAAA;AACH,SAAC,CAAC;KACH,EAAC,CAAC,GAAG,EAAC,KAAK,EAAC,OAAO,EAAC,OAAO,CAAC,CAAC,CAAC;AACjC;;;;"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../lib/hooks/use-event.ts","../lib/hooks/useLazyRef.ts","../lib/hooks/useInstance.ts"],"sourcesContent":["import { useCallback, useEffect } from \"react\";\r\n\r\nexport function useEvent<TRef extends React.MutableRefObject<any|null>,TEvent>(ref:TRef, event:string, handler?:(e:TEvent)=>void, passive = false) {\r\n const internalHandler = useCallback((e:TEvent)=>{\r\n if(ref.current && typeof handler == \"function\"){\r\n handler(e);\r\n }\r\n },[ref,handler]);\r\n useEffect(() => {\r\n const dom = ref.current;\r\n if (dom) {\r\n // initiate the event handler\r\n dom.addEventListener(event, internalHandler, { passive, capture:false }); \r\n }\r\n // this will clean up the event every time the component is re-rendered\r\n return function cleanup() {\r\n if(dom){\r\n dom.removeEventListener(event, internalHandler, {passive, capture:false});\r\n }\r\n };\r\n },[ref,event,handler,passive]);\r\n}","import { MutableRefObject, useRef } from \"react\";\r\n\r\ntype InitFunc<T> = ()=>T\r\nexport const useLazyRef = <T>(initValFunc:InitFunc<T>) => {\r\n const ref:MutableRefObject<any> = useRef(null);\r\n if (ref.current === null) {\r\n ref.current = initValFunc();\r\n }\r\n return ref;\r\n};\r\n\r\n// used by: useMobx","import { useLazyRef } from \"./useLazyRef.js\";\r\n\r\n\r\ntype BaseConstructableClass<T = any> = new (...args: any[]) => T;\r\n\r\n// Type to get the constructor parameters of a class\r\ntype Initializers<T extends BaseConstructableClass> = ConstructorParameters<T>;\r\n\r\n// useInstance function that accepts a Store class and its initializers\r\n/**\r\n * create a instance of an class with lazy initialization\r\n * @param Store class to create instance of\r\n * @param initializers initializers to pass to the class constructor\r\n * @returns instance of the class\r\n */\r\nexport const useInstance = <T extends BaseConstructableClass>(Store: T, initializers: Initializers<T>): InstanceType<T> => {\r\n const vm = useLazyRef(() => new Store(...initializers));\r\n return vm.current;\r\n};\r\n"],"mappings":";;;AAEM,SAAU,SAA+D,KAAU,OAAc,SAA2B,UAAU,OAAK;CAC/I,MAAM,kBAAkB,YAAY,CAAC,MAAW;AAC9C,MAAG,IAAI,kBAAkB,WAAW,WAClC,SAAQ,EAAE;CAEb,GAAC,CAAC,KAAI,OAAQ,EAAC;AAChB,WAAU,MAAK;EACb,MAAM,MAAM,IAAI;AAChB,MAAI,IAEF,KAAI,iBAAiB,OAAO,iBAAiB;GAAE;GAAS,SAAQ;EAAO,EAAC;AAG1E,SAAO,SAAS,UAAO;AACrB,OAAG,IACD,KAAI,oBAAoB,OAAO,iBAAiB;IAAC;IAAS,SAAQ;GAAM,EAAC;EAE5E;CACF,GAAC;EAAC;EAAI;EAAM;EAAQ;CAAQ,EAAC;AAC/B;;;;MClBY,aAAa,CAAI,gBAA2B;CACvD,MAAM,MAA4B,OAAO,KAAK;AAC9C,KAAI,IAAI,YAAY,KAClB,KAAI,UAAU,aAAa;AAE7B,QAAO;AACR;;;;MCMY,cAAc,CAAmC,OAAU,iBAAkD;CACxH,MAAM,KAAK,WAAW,MAAM,IAAI,MAAM,GAAG,cAAc;AACvD,QAAO,GAAG;AACX"}
@@ -1,31 +1,77 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
1
+ (function(global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.JBCoreReact = {}, global.React));
5
- })(this, (function (exports, react) { 'use strict';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.JBCoreReact = {}), global.React));
5
+ })(this, function(exports, react) {
6
+ "use strict";
7
+ //#region rolldown:runtime
8
+ var __create = Object.create;
9
+ var __defProp = Object.defineProperty;
10
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
+ var __getOwnPropNames = Object.getOwnPropertyNames;
12
+ var __getProtoOf = Object.getPrototypeOf;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
16
+ key = keys[i];
17
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
18
+ get: ((k) => from[k]).bind(null, key),
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
+ });
21
+ }
22
+ return to;
23
+ };
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
25
+ value: mod,
26
+ enumerable: true
27
+ }) : target, mod));
6
28
 
7
- function useEvent(ref, event, handler, passive = false) {
8
- const internalHandler = react.useCallback((e) => {
9
- if (ref.current && typeof handler == "function") {
10
- handler(e);
11
- }
12
- }, [ref, handler]);
13
- react.useEffect(() => {
14
- const dom = ref.current;
15
- if (dom) {
16
- // initiate the event handler
17
- dom.addEventListener(event, internalHandler, { passive, capture: false });
18
- }
19
- // this will clean up the event every time the component is re-rendered
20
- return function cleanup() {
21
- if (dom) {
22
- dom.removeEventListener(event, internalHandler, { passive, capture: false });
23
- }
24
- };
25
- }, [ref, event, handler, passive]);
26
- }
29
+ //#endregion
30
+ react = __toESM(react);
27
31
 
28
- exports.useEvent = useEvent;
32
+ //#region web-component/jb-core/react/lib/hooks/use-event.ts
33
+ function useEvent(ref, event, handler, passive = false) {
34
+ const internalHandler = (0, react.useCallback)((e) => {
35
+ if (ref.current && typeof handler == "function") handler(e);
36
+ }, [ref, handler]);
37
+ (0, react.useEffect)(() => {
38
+ const dom = ref.current;
39
+ if (dom) dom.addEventListener(event, internalHandler, {
40
+ passive,
41
+ capture: false
42
+ });
43
+ return function cleanup() {
44
+ if (dom) dom.removeEventListener(event, internalHandler, {
45
+ passive,
46
+ capture: false
47
+ });
48
+ };
49
+ }, [
50
+ ref,
51
+ event,
52
+ handler,
53
+ passive
54
+ ]);
55
+ }
29
56
 
30
- }));
31
- //# sourceMappingURL=index.umd.js.map
57
+ //#endregion
58
+ //#region web-component/jb-core/react/lib/hooks/useLazyRef.ts
59
+ const useLazyRef = (initValFunc) => {
60
+ const ref = (0, react.useRef)(null);
61
+ if (ref.current === null) ref.current = initValFunc();
62
+ return ref;
63
+ };
64
+
65
+ //#endregion
66
+ //#region web-component/jb-core/react/lib/hooks/useInstance.ts
67
+ const useInstance = (Store, initializers) => {
68
+ const vm = useLazyRef(() => new Store(...initializers));
69
+ return vm.current;
70
+ };
71
+
72
+ //#endregion
73
+ exports.useEvent = useEvent
74
+ exports.useInstance = useInstance
75
+ exports.useLazyRef = useLazyRef
76
+ });
77
+ //# sourceMappingURL=index.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.umd.js","sources":["../lib/use-event.ts"],"sourcesContent":["import { useCallback, useEffect } from \"react\";\r\n\r\nexport function useEvent<TRef extends React.MutableRefObject<any|null>,TEvent>(ref:TRef, event:string, handler?:(e:TEvent)=>void, passive = false) {\r\n const internalHandler = useCallback((e:TEvent)=>{\r\n if(ref.current && typeof handler == \"function\"){\r\n handler(e);\r\n }\r\n },[ref,handler]);\r\n useEffect(() => {\r\n const dom = ref.current;\r\n if (dom) {\r\n // initiate the event handler\r\n dom.addEventListener(event, internalHandler, { passive, capture:false }); \r\n }\r\n // this will clean up the event every time the component is re-rendered\r\n return function cleanup() {\r\n if(dom){\r\n dom.removeEventListener(event, internalHandler, {passive, capture:false});\r\n }\r\n };\r\n },[ref,event,handler,passive]);\r\n}"],"names":["useCallback","useEffect"],"mappings":";;;;;;EAEM,SAAU,QAAQ,CAAuD,GAAQ,EAAE,KAAY,EAAE,OAAyB,EAAE,OAAO,GAAG,KAAK,EAAA;EAC/I,IAAA,MAAM,eAAe,GAAGA,iBAAW,CAAC,CAAC,CAAQ,KAAG;UAC9C,IAAG,GAAG,CAAC,OAAO,IAAI,OAAO,OAAO,IAAI,UAAU,EAAC;cAC7C,OAAO,CAAC,CAAC,CAAC,CAAC;EACZ,SAAA;EACH,KAAC,EAAC,CAAC,GAAG,EAAC,OAAO,CAAC,CAAC,CAAC;MACjBC,eAAS,CAAC,MAAK;EACb,QAAA,MAAM,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC;EACxB,QAAA,IAAI,GAAG,EAAE;;EAEP,YAAA,GAAG,CAAC,gBAAgB,CAAC,KAAK,EAAE,eAAe,EAAE,EAAE,OAAO,EAAE,OAAO,EAAC,KAAK,EAAE,CAAC,CAAC;EAC1E,SAAA;;EAED,QAAA,OAAO,SAAS,OAAO,GAAA;EACrB,YAAA,IAAG,GAAG,EAAC;EACL,gBAAA,GAAG,CAAC,mBAAmB,CAAC,KAAK,EAAE,eAAe,EAAE,EAAC,OAAO,EAAE,OAAO,EAAC,KAAK,EAAC,CAAC,CAAC;EAC3E,aAAA;EACH,SAAC,CAAC;OACH,EAAC,CAAC,GAAG,EAAC,KAAK,EAAC,OAAO,EAAC,OAAO,CAAC,CAAC,CAAC;EACjC;;;;;;;;"}
1
+ {"version":3,"file":"index.umd.js","names":[],"sources":["../lib/hooks/use-event.ts","../lib/hooks/useLazyRef.ts","../lib/hooks/useInstance.ts"],"sourcesContent":["import { useCallback, useEffect } from \"react\";\r\n\r\nexport function useEvent<TRef extends React.MutableRefObject<any|null>,TEvent>(ref:TRef, event:string, handler?:(e:TEvent)=>void, passive = false) {\r\n const internalHandler = useCallback((e:TEvent)=>{\r\n if(ref.current && typeof handler == \"function\"){\r\n handler(e);\r\n }\r\n },[ref,handler]);\r\n useEffect(() => {\r\n const dom = ref.current;\r\n if (dom) {\r\n // initiate the event handler\r\n dom.addEventListener(event, internalHandler, { passive, capture:false }); \r\n }\r\n // this will clean up the event every time the component is re-rendered\r\n return function cleanup() {\r\n if(dom){\r\n dom.removeEventListener(event, internalHandler, {passive, capture:false});\r\n }\r\n };\r\n },[ref,event,handler,passive]);\r\n}","import { MutableRefObject, useRef } from \"react\";\r\n\r\ntype InitFunc<T> = ()=>T\r\nexport const useLazyRef = <T>(initValFunc:InitFunc<T>) => {\r\n const ref:MutableRefObject<any> = useRef(null);\r\n if (ref.current === null) {\r\n ref.current = initValFunc();\r\n }\r\n return ref;\r\n};\r\n\r\n// used by: useMobx","import { useLazyRef } from \"./useLazyRef.js\";\r\n\r\n\r\ntype BaseConstructableClass<T = any> = new (...args: any[]) => T;\r\n\r\n// Type to get the constructor parameters of a class\r\ntype Initializers<T extends BaseConstructableClass> = ConstructorParameters<T>;\r\n\r\n// useInstance function that accepts a Store class and its initializers\r\n/**\r\n * create a instance of an class with lazy initialization\r\n * @param Store class to create instance of\r\n * @param initializers initializers to pass to the class constructor\r\n * @returns instance of the class\r\n */\r\nexport const useInstance = <T extends BaseConstructableClass>(Store: T, initializers: Initializers<T>): InstanceType<T> => {\r\n const vm = useLazyRef(() => new Store(...initializers));\r\n return vm.current;\r\n};\r\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEM,SAAU,SAA+D,KAAU,OAAc,SAA2B,UAAU,OAAK;CAC/I,MAAM,kBAAkB,uBAAY,CAAC,MAAW;AAC9C,MAAG,IAAI,kBAAkB,WAAW,WAClC,SAAQ,EAAE;CAEb,GAAC,CAAC,KAAI,OAAQ,EAAC;AAChB,sBAAU,MAAK;EACb,MAAM,MAAM,IAAI;AAChB,MAAI,IAEF,KAAI,iBAAiB,OAAO,iBAAiB;GAAE;GAAS,SAAQ;EAAO,EAAC;AAG1E,SAAO,SAAS,UAAO;AACrB,OAAG,IACD,KAAI,oBAAoB,OAAO,iBAAiB;IAAC;IAAS,SAAQ;GAAM,EAAC;EAE5E;CACF,GAAC;EAAC;EAAI;EAAM;EAAQ;CAAQ,EAAC;AAC/B;;;;MClBY,aAAa,CAAI,gBAA2B;CACvD,MAAM,MAA4B,kBAAO,KAAK;AAC9C,KAAI,IAAI,YAAY,KAClB,KAAI,UAAU,aAAa;AAE7B,QAAO;AACR;;;;MCMY,cAAc,CAAmC,OAAU,iBAAkD;CACxH,MAAM,KAAK,WAAW,MAAM,IAAI,MAAM,GAAG,cAAc;AACvD,QAAO,GAAG;AACX"}
@@ -0,0 +1,3 @@
1
+ export * from './use-event.js';
2
+ export * from './useInstance.js';
3
+ export * from './useLazyRef.js';
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare function useEvent<TRef extends React.MutableRefObject<any | null>, TEvent>(ref: TRef, event: string, handler?: (e: TEvent) => void, passive?: boolean): void;
@@ -0,0 +1,10 @@
1
+ type BaseConstructableClass<T = any> = new (...args: any[]) => T;
2
+ type Initializers<T extends BaseConstructableClass> = ConstructorParameters<T>;
3
+ /**
4
+ * create a instance of an class with lazy initialization
5
+ * @param Store class to create instance of
6
+ * @param initializers initializers to pass to the class constructor
7
+ * @returns instance of the class
8
+ */
9
+ export declare const useInstance: <T extends BaseConstructableClass<any>>(Store: T, initializers: ConstructorParameters<T>) => InstanceType<T>;
10
+ export {};
@@ -0,0 +1,4 @@
1
+ import { MutableRefObject } from "react";
2
+ type InitFunc<T> = () => T;
3
+ export declare const useLazyRef: <T>(initValFunc: InitFunc<T>) => MutableRefObject<any>;
4
+ export {};
@@ -1 +1 @@
1
- export * from './use-event.js';
1
+ export * from './hooks/index.js';
@@ -0,0 +1,38 @@
1
+ //TODO: try to remove this after migration to lightning css
2
+ $desktop-large-width: 1200px;
3
+ $desktop-width: 1024px;
4
+ $tablet-width: 768px;
5
+ $mobile-width: 480px;
6
+ $mobile-small-width:320px;
7
+ @mixin large-desktop {
8
+ //for defualt our pages style is in this scale but for some cases we define it
9
+ @media (min-width: #{$desktop-large-width}){
10
+ @content;
11
+ }
12
+ }
13
+ @mixin desktop {
14
+ @media (min-width: #{$desktop-width}) and (max-width: #{$desktop-large-width - 1px}){
15
+ @content;
16
+ }
17
+ }
18
+ @mixin small-desktop {
19
+ @media (min-width: #{$tablet-width}) and (max-width: #{$desktop-width - 1px}) {
20
+ @content;
21
+ }
22
+ }
23
+ @mixin tablet {
24
+ @media (min-width: #{$mobile-width}) and (max-width: #{$tablet-width - 1px}) {
25
+ @content;
26
+ }
27
+ }
28
+ @mixin mobile {
29
+ @media (min-width: #{$mobile-small-width}) and (max-width: #{$mobile-width - 1px}) {
30
+ @content;
31
+ }
32
+ }
33
+ @mixin mobile-tablet {
34
+ @media (min-width: #{$mobile-small-width}) and (max-width: #{$tablet-width - 1px}) {
35
+ @content;
36
+ }
37
+ }
38
+ //if it smaller than 320 i think he must change device :D