jb-core 0.2.0 → 0.4.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/configs/global.d.ts +15 -0
- package/configs/tsconfig-base.json +15 -0
- package/configs/tsconfig-react.json +31 -0
- package/configs/tsconfig-web-component.json +27 -0
- package/dist/device-detection.d.ts +1 -0
- package/dist/events.d.ts +22 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.br +0 -0
- package/dist/index.cjs.js.gz +0 -0
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -1
- package/dist/index.js.br +0 -0
- package/dist/index.js.gz +0 -0
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.br +0 -0
- package/dist/index.umd.js.gz +0 -0
- package/dist/index.umd.js.map +1 -1
- package/dist/lib/device-detection.d.ts +1 -0
- package/dist/lib/events.d.ts +22 -0
- package/dist/lib/index.d.ts +3 -0
- package/dist/lib/persian-tools.d.ts +3 -0
- package/dist/persian-tools.d.ts +3 -0
- package/package.json +4 -2
- package/react/dist/hooks/index.d.ts +3 -0
- package/react/dist/hooks/use-event.d.ts +1 -0
- package/react/dist/hooks/useInstance.d.ts +10 -0
- package/react/dist/hooks/useLazyRef.d.ts +4 -0
- package/react/dist/index.cjs.js +2 -27
- package/react/dist/index.cjs.js.map +1 -1
- package/react/dist/index.d.ts +1 -0
- package/react/dist/index.js +2 -25
- package/react/dist/index.js.map +1 -1
- package/react/dist/index.umd.js +2 -31
- package/react/dist/index.umd.js.map +1 -1
- package/react/dist/lib/hooks/index.d.ts +3 -0
- package/react/dist/lib/hooks/use-event.d.ts +1 -0
- package/react/dist/lib/hooks/useInstance.d.ts +10 -0
- package/react/dist/lib/hooks/useLazyRef.d.ts +4 -0
- package/react/dist/lib/index.d.ts +1 -0
- package/react/dist/web-component/jb-core/react/lib/hooks/index.d.ts +3 -0
- package/react/dist/web-component/jb-core/react/lib/hooks/use-event.d.ts +2 -0
- package/react/dist/web-component/jb-core/react/lib/hooks/useInstance.d.ts +10 -0
- package/react/dist/web-component/jb-core/react/lib/hooks/useLazyRef.d.ts +4 -0
- package/react/dist/web-component/jb-core/react/lib/index.d.ts +1 -1
- package/react/package.json +1 -1
- package/react/tsconfig.json +2 -1
- package/styles/colors.scss +14 -0
- package/styles/medias.scss +38 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
type FileStringModules = {
|
|
2
|
+
readonly default: string;
|
|
3
|
+
}
|
|
4
|
+
declare module '*.scss' {
|
|
5
|
+
const value: FileStringModules;
|
|
6
|
+
export default value;
|
|
7
|
+
}
|
|
8
|
+
declare module '*.html' {
|
|
9
|
+
const value: FileStringModules;
|
|
10
|
+
export default value.default;
|
|
11
|
+
}
|
|
12
|
+
declare module '*.svg' {
|
|
13
|
+
const value: string;
|
|
14
|
+
export default value;
|
|
15
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"baseUrl": ".",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"removeComments": false,
|
|
7
|
+
"preserveConstEnums": true,
|
|
8
|
+
"sourceMap": true,
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
"target": "ES2020",
|
|
11
|
+
"allowSyntheticDefaultImports": true,
|
|
12
|
+
"emitDecoratorMetadata": true,
|
|
13
|
+
"experimentalDecorators": true,
|
|
14
|
+
"noImplicitAny": false,
|
|
15
|
+
"noLib": false,
|
|
16
|
+
"esModuleInterop": false,
|
|
17
|
+
"declaration": true,
|
|
18
|
+
"declarationDir": "./",
|
|
19
|
+
"declarationMap": false,
|
|
20
|
+
"jsx": "react",
|
|
21
|
+
"typeRoots" : ["../node_modules/@types", "./global.d.ts"],
|
|
22
|
+
},
|
|
23
|
+
"include": [
|
|
24
|
+
"global.d.ts",
|
|
25
|
+
],
|
|
26
|
+
"exclude": [
|
|
27
|
+
"node_modules",
|
|
28
|
+
"**/*.spec.ts",
|
|
29
|
+
],
|
|
30
|
+
"extends":"./tsconfig-base.json"
|
|
31
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"useTsconfigDeclarationDir": true,
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"baseUrl": ".",
|
|
5
|
+
"module": "ES2020",
|
|
6
|
+
"noImplicitAny": true,
|
|
7
|
+
"removeComments": false,
|
|
8
|
+
"preserveConstEnums": true,
|
|
9
|
+
"moduleResolution": "node",
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"allowJs": true,
|
|
12
|
+
"target": "ES2020",
|
|
13
|
+
"typeRoots" : ["../node_modules/@types", "./global.d.ts"],
|
|
14
|
+
"composite": true,
|
|
15
|
+
"declaration": true,
|
|
16
|
+
"declarationDir": "./",
|
|
17
|
+
"declarationMap": false,
|
|
18
|
+
},
|
|
19
|
+
"include": [
|
|
20
|
+
"global.d.ts",
|
|
21
|
+
],
|
|
22
|
+
"exclude": [
|
|
23
|
+
"node_modules",
|
|
24
|
+
"**/*.spec.ts",
|
|
25
|
+
],
|
|
26
|
+
"extends":"./tsconfig-base.json"
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isMobile: () => boolean;
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* add type to event target for easier access to target
|
|
3
|
+
*/
|
|
4
|
+
export type EventTypeWithTarget<TEvent, TTarget> = TEvent & {
|
|
5
|
+
target: TTarget;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* this function will stop event from propagate even in capturing phase and will call handler only if event target is the element
|
|
9
|
+
*/
|
|
10
|
+
export declare function listenAndSilentEvent<TEvent extends Event, TTarget>(element: TTarget, eventName: string, handler: (e: TEvent) => void, options?: AddEventListenerOptions): void;
|
|
11
|
+
/**
|
|
12
|
+
* create a keyboardEvent based on `e` value and replace them with initObj
|
|
13
|
+
*/
|
|
14
|
+
export declare function createKeyboardEvent(eventName: string, e: KeyboardEvent, initObj: KeyboardEventInit): KeyboardEvent;
|
|
15
|
+
/**
|
|
16
|
+
* create a InputEvent based on `e` value and replace them with initObj
|
|
17
|
+
*/
|
|
18
|
+
export declare function createInputEvent(eventName: string, e: InputEvent, initObj: InputEventInit): InputEvent;
|
|
19
|
+
/**
|
|
20
|
+
* create a InputEvent based on `e` value and replace them with initObj
|
|
21
|
+
*/
|
|
22
|
+
export declare function createFocusEvent(eventName: string, e: FocusEvent, initObj: FocusEventInit): FocusEvent;
|
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
|
package/dist/index.cjs.js.br
CHANGED
|
Binary file
|
package/dist/index.cjs.js.gz
CHANGED
|
Binary file
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../lib/events.ts","../lib/
|
|
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,MACT,cAAe,EAAE,iBACd,GAGL,OADc,IAAI,WAAW,EAAW,EAEzC,2BAnCK,SAA2B,EAAmB,EAAe,GACjE,MAAM,EAAgC,CACpC,QAAS,EAAE,QACX,WAAY,EAAE,WACd,SAAU,EAAE,SACZ,OAAQ,EAAE,OACV,YAAa,EAAE,YACf,KAAM,EAAE,KACR,MAAO,EAAE,MACT,KAAM,EAAE,KACR,aAAc,EAAE,aAChB,UAAW,EAAE,UACb,aAA4C,mBAAvB,EAAE,kBAAkC,EAAE,kBAAoB,MAC5E,GAGL,OADc,IAAI,WAAW,EAAW,EAEzC,8BA5CK,SAA8B,EAAmB,EAAkB,GACvE,MAAM,EAAmC,CACvC,OAAQ,EAAE,OACV,QAAS,EAAE,QACX,WAAY,EAAE,WACd,KAAM,EAAE,KACR,SAAU,EAAE,SACZ,QAAS,EAAE,QACX,OAAQ,EAAE,OACV,YAAa,EAAE,YACf,IAAK,EAAE,IACP,SAAU,EAAE,SACZ,QAAS,EAAE,QACX,OAAQ,EAAE,OACV,SAAU,EAAE,SACZ,KAAM,EAAE,KACR,SAAU,EAAE,SACZ,QAAS,EAAE,QACX,MAAO,EAAE,SACN,GAGL,OADc,IAAI,cAAc,EAAW,EAE5C,uBEhCD,SAAsB,GACpB,MAAqB,iBAAV,GAAsB,MAAM,GAC9B,GAGM,EAAM,WAAW,QADlB,UACiC,SAAU,GACvD,OAAO,OAAO,aAAa,EAAE,WAAW,GAAK,KAC9C,GAGF,uBAtBD,SAAsB,GACpB,MAAqB,iBAAV,EACF,GAGM,EAAM,QADP,UACsB,SAAU,GAC5C,OAAO,OAAO,aAAa,EAAE,WAAW,GAAK,KAC9C,GAGF,mBDVuB,IACf,QAAQ,KAAK,OAAO,UAAU,wCDQjC,SAA8D,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/dist/index.d.ts
ADDED
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};"],"
|
|
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,iBAAiB,GAAY,IAChC,EAAE,eAAe,SAAS,KAC5B,EAAE,kBACF,EAAE,2BACF,EAAQ,GACT,GACD,CAAC,SAAQ,KAAQ,GACpB,CAIK,SAAU,EAAoB,EAAmB,EAAkB,GACvE,MAAM,EAAmC,CACvC,OAAQ,EAAE,OACV,QAAS,EAAE,QACX,WAAY,EAAE,WACd,KAAM,EAAE,KACR,SAAU,EAAE,SACZ,QAAS,EAAE,QACX,OAAQ,EAAE,OACV,YAAa,EAAE,YACf,IAAK,EAAE,IACP,SAAU,EAAE,SACZ,QAAS,EAAE,QACX,OAAQ,EAAE,OACV,SAAU,EAAE,SACZ,KAAM,EAAE,KACR,SAAU,EAAE,SACZ,QAAS,EAAE,QACX,MAAO,EAAE,SACN,GAGL,OADc,IAAI,cAAc,EAAW,EAE5C,CAIK,SAAU,EAAiB,EAAmB,EAAe,GACjE,MAAM,EAAgC,CACpC,QAAS,EAAE,QACX,WAAY,EAAE,WACd,SAAU,EAAE,SACZ,OAAQ,EAAE,OACV,YAAa,EAAE,YACf,KAAM,EAAE,KACR,MAAO,EAAE,MACT,KAAM,EAAE,KACR,aAAc,EAAE,aAChB,UAAW,EAAE,UACb,aAA4C,mBAAvB,EAAE,kBAAkC,EAAE,kBAAoB,MAC5E,GAGL,OADc,IAAI,WAAW,EAAW,EAEzC,CAKK,SAAU,EAAiB,EAAmB,EAAe,GACjE,MAAM,EAAgC,CACpC,QAAS,EAAE,QACX,WAAY,EAAE,WACd,SAAU,EAAE,SACZ,OAAQ,EAAE,OACV,KAAM,EAAE,KACR,MAAO,EAAE,MACT,cAAe,EAAE,iBACd,GAGL,OADc,IAAI,WAAW,EAAW,EAEzC,OCnFY,EAAW,IACf,QAAQ,KAAK,OAAO,UAAU,WCDvC,SAAS,EAAa,GACpB,GAAqB,iBAAV,EACT,MAAO,GAOT,OAJe,EAAM,QADP,UACsB,SAAU,GAC5C,OAAO,OAAO,aAAa,EAAE,WAAW,GAAK,KAC9C,GAGF,CAED,SAAS,EAAa,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
|
package/dist/index.umd.js.br
CHANGED
|
Binary file
|
package/dist/index.umd.js.gz
CHANGED
|
Binary file
|
package/dist/index.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../lib/events.ts","../lib/
|
|
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":"iQAsEM,SAA2B,EAAmB,EAAe,GACjE,MAAM,EAAgC,CACpC,QAAS,EAAE,QACX,WAAY,EAAE,WACd,SAAU,EAAE,SACZ,OAAQ,EAAE,OACV,KAAM,EAAE,KACR,MAAO,EAAE,MACT,cAAe,EAAE,iBACd,GAGL,OADc,IAAI,WAAW,EAAW,EAEzC,qBAnCK,SAA2B,EAAmB,EAAe,GACjE,MAAM,EAAgC,CACpC,QAAS,EAAE,QACX,WAAY,EAAE,WACd,SAAU,EAAE,SACZ,OAAQ,EAAE,OACV,YAAa,EAAE,YACf,KAAM,EAAE,KACR,MAAO,EAAE,MACT,KAAM,EAAE,KACR,aAAc,EAAE,aAChB,UAAW,EAAE,UACb,aAA4C,mBAAvB,EAAE,kBAAkC,EAAE,kBAAoB,MAC5E,GAGL,OADc,IAAI,WAAW,EAAW,EAEzC,wBA5CK,SAA8B,EAAmB,EAAkB,GACvE,MAAM,EAAmC,CACvC,OAAQ,EAAE,OACV,QAAS,EAAE,QACX,WAAY,EAAE,WACd,KAAM,EAAE,KACR,SAAU,EAAE,SACZ,QAAS,EAAE,QACX,OAAQ,EAAE,OACV,YAAa,EAAE,YACf,IAAK,EAAE,IACP,SAAU,EAAE,SACZ,QAAS,EAAE,QACX,OAAQ,EAAE,OACV,SAAU,EAAE,SACZ,KAAM,EAAE,KACR,SAAU,EAAE,SACZ,QAAS,EAAE,QACX,MAAO,EAAE,SACN,GAGL,OADc,IAAI,cAAc,EAAW,EAE5C,iBEhCD,SAAsB,GACpB,MAAqB,iBAAV,GAAsB,MAAM,GAC9B,GAGM,EAAM,WAAW,QADlB,UACiC,SAAU,GACvD,OAAO,OAAO,aAAa,EAAE,WAAW,GAAK,KAC9C,GAGF,iBAtBD,SAAsB,GACpB,MAAqB,iBAAV,EACF,GAGM,EAAM,QADP,UACsB,SAAU,GAC5C,OAAO,OAAO,aAAa,EAAE,WAAW,GAAK,KAC9C,GAGF,aDVuB,IACf,QAAQ,KAAK,OAAO,UAAU,kCDQjC,SAA8D,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isMobile: () => boolean;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* add type to event target for easier access to target
|
|
3
|
+
*/
|
|
4
|
+
export type EventTypeWithTarget<TEvent, TTarget> = TEvent & {
|
|
5
|
+
target: TTarget;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* this function will stop event from propagate even in capturing phase and will call handler only if event target is the element
|
|
9
|
+
*/
|
|
10
|
+
export declare function listenAndSilentEvent<TEvent extends Event, TTarget>(element: TTarget, eventName: string, handler: (e: TEvent) => void, options?: AddEventListenerOptions): void;
|
|
11
|
+
/**
|
|
12
|
+
* create a keyboardEvent based on `e` value and replace them with initObj
|
|
13
|
+
*/
|
|
14
|
+
export declare function createKeyboardEvent(eventName: string, e: KeyboardEvent, initObj: KeyboardEventInit): KeyboardEvent;
|
|
15
|
+
/**
|
|
16
|
+
* create a InputEvent based on `e` value and replace them with initObj
|
|
17
|
+
*/
|
|
18
|
+
export declare function createInputEvent(eventName: string, e: InputEvent, initObj: InputEventInit): InputEvent;
|
|
19
|
+
/**
|
|
20
|
+
* create a InputEvent based on `e` value and replace them with initObj
|
|
21
|
+
*/
|
|
22
|
+
export declare function createFocusEvent(eventName: string, e: FocusEvent, initObj: FocusEventInit): FocusEvent;
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"react component",
|
|
15
15
|
"event"
|
|
16
16
|
],
|
|
17
|
-
"version": "0.
|
|
17
|
+
"version": "0.4.0",
|
|
18
18
|
"bugs": "https://github.com/javadbat/jb-core/issues",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"files": [
|
|
@@ -22,11 +22,13 @@
|
|
|
22
22
|
"README.md",
|
|
23
23
|
"lib/",
|
|
24
24
|
"dist/",
|
|
25
|
+
"styles/",
|
|
26
|
+
"configs/",
|
|
25
27
|
"react/",
|
|
26
28
|
"react/dist/"
|
|
27
29
|
],
|
|
28
30
|
"main": "index.js",
|
|
29
|
-
"types": "./dist/
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
30
32
|
"repository": {
|
|
31
33
|
"type": "git",
|
|
32
34
|
"url": "git@github.com:javadbat/jb-core.git"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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 {};
|
package/react/dist/index.cjs.js
CHANGED
|
@@ -1,27 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var react = require('react');
|
|
4
|
-
|
|
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]);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
exports.useEvent = useEvent;
|
|
27
|
-
//# sourceMappingURL=index.cjs.js.map
|
|
1
|
+
"use strict";let e,t;var r=Object.create,n=Object.defineProperty,u=Object.getOwnPropertyDescriptor,c=Object.getOwnPropertyNames,o=Object.getPrototypeOf,l=Object.prototype.hasOwnProperty;const a=(t=null!=(e=require("react"))?r(o(e)):{},((e,t,r,o)=>{if(t&&"object"==typeof t||"function"==typeof t)for(var a,s=c(t),f=0,p=s.length;f<p;f++)a=s[f],l.call(e,a)||void 0===a||n(e,a,{get:(e=>t[e]).bind(null,a),enumerable:!(o=u(t,a))||o.enumerable});return e})(e&&e.__esModule?t:n(t,"default",{value:e,enumerable:!0}),e)),s=e=>{let t=(0,a.useRef)(null);return null===t.current&&(t.current=e()),t};exports.useEvent=function(e,t,r,n=!1){let u=(0,a.useCallback)(t=>{e.current&&"function"==typeof r&&r(t)},[e,r]);(0,a.useEffect)(()=>{let r=e.current;return r&&r.addEventListener(t,u,{passive:n,capture:!1}),function(){r&&r.removeEventListener(t,u,{passive:n,capture:!1})}},[e,t,r,n])},exports.useInstance=(e,t)=>s(()=>new e(...t)).current,exports.useLazyRef=s;
|
|
2
|
+
//# 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}"
|
|
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,MAAS;AAC5C,MAAG,IAAI,kBAAkB,WAAW,WAClC,SAAQ,EAAE;CAEb,GAAC,CACF,KACE;sBAEE,MAAA;QACA,MAAI,IAAA;MACL,IAED,KAAO,iBAAgB,OAAA,iBAAA;GAClB;GACD,SAAI;EACL,EAAA;AAGN,SAAA,SAAA,UAAA;;;;;;;;;;;;;;;;MClBY,aAAa,CAAI,gBAAyB;CACrD,MAAM,MAA4B,kBAAO,KAAK;AAC9C,KAAI,IAAI,YAAY,KAClB,KAAI,UAAU,aAAa;AAE7B,QAAO;AACR;;;;MCKE,cAAA,CAAA,OAAA,iBAAA;CACH,MAAO,KAAM,WAAW,MAAsC,IAAQ,MAAE,GAAA,cAAkD;AACxH,QAAM,GAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './hooks/index.js';
|
package/react/dist/index.js
CHANGED
|
@@ -1,25 +1,2 @@
|
|
|
1
|
-
import {
|
|
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]);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export { useEvent };
|
|
25
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import{useCallback as e,useEffect as t,useRef as n}from"react";function r(n,u,c,l=!1){let o=e(e=>{n.current&&"function"==typeof c&&c(e)},[n,c]);t(()=>{let e=n.current;return e&&e.addEventListener(u,o,{passive:l,capture:!1}),function(){e&&e.removeEventListener(u,o,{passive:l,capture:!1})}},[n,u,c,l])}let u=e=>{let t=n(null);return null===t.current&&(t.current=e()),t},c=(e,t)=>u(()=>new e(...t)).current;export{r as useEvent,c as useInstance,u as useLazyRef};
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
package/react/dist/index.js.map
CHANGED
|
@@ -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}"
|
|
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,MAAS;AAC5C,MAAG,IAAI,kBAAkB,WAAW,WAClC,SAAQ,EAAE;CAEb,GAAC,CACF,KACE;WAEE,MAAA;QACA,MAAI,IAAA;MACL,IAED,KAAO,iBAAgB,OAAA,iBAAA;GAClB;GACD,SAAI;EACL,EAAA;AAGN,SAAA,SAAA,UAAA;;;;;;;;;;;;;;;;MClBY,aAAa,CAAI,gBAAyB;CACrD,MAAM,MAA4B,OAAO,KAAK;AAC9C,KAAI,IAAI,YAAY,KAClB,KAAI,UAAU,aAAa;AAE7B,QAAO;AACR;;;;MCKE,cAAA,CAAA,OAAA,iBAAA;CACH,MAAO,KAAM,WAAW,MAAsC,IAAQ,MAAE,GAAA,cAAkD;AACxH,QAAM,GAAE"}
|
package/react/dist/index.umd.js
CHANGED
|
@@ -1,31 +1,2 @@
|
|
|
1
|
-
(function (
|
|
2
|
-
|
|
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';
|
|
6
|
-
|
|
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
|
-
}
|
|
27
|
-
|
|
28
|
-
exports.useEvent = useEvent;
|
|
29
|
-
|
|
30
|
-
}));
|
|
31
|
-
//# sourceMappingURL=index.umd.js.map
|
|
1
|
+
var e,t;e=this,t=function(e,t){"use strict";let r,n;var u=Object.create,o=Object.defineProperty,c=Object.getOwnPropertyDescriptor,l=Object.getOwnPropertyNames,f=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty;n=null!=(r=t)?u(f(r)):{},t=((e,t,r,n)=>{if(t&&"object"==typeof t||"function"==typeof t)for(var u,f=l(t),i=0,s=f.length;i<s;i++)u=f[i],a.call(e,u)||void 0===u||o(e,u,{get:(e=>t[e]).bind(null,u),enumerable:!(n=c(t,u))||n.enumerable});return e})(r&&r.__esModule?n:o(n,"default",{value:r,enumerable:!0}),r);let i=e=>{let r=(0,t.useRef)(null);return null===r.current&&(r.current=e()),r};e.useEvent=function(e,r,n,u=!1){let o=(0,t.useCallback)(t=>{e.current&&"function"==typeof n&&n(t)},[e,n]);(0,t.useEffect)(()=>{let t=e.current;return t&&t.addEventListener(r,o,{passive:u,capture:!1}),function(){t&&t.removeEventListener(r,o,{passive:u,capture:!1})}},[e,r,n,u])},e.useInstance=(e,t)=>i(()=>new e(...t)).current,e.useLazyRef=i},"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).JBCoreReact={},e.React);
|
|
2
|
+
//# 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}"
|
|
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,MAAS;AAC5C,MAAG,IAAI,kBAAkB,WAAW,WAClC,SAAQ,EAAE;CAEb,GAAC,CACF,KACE;sBAEE,MAAA;QACA,MAAI,IAAA;MACL,IAED,KAAO,iBAAgB,OAAA,iBAAA;GAClB;GACD,SAAI;EACL,EAAA;AAGN,SAAA,SAAA,UAAA;;;;;;;;;;;;;;;;MClBY,aAAa,CAAI,gBAAyB;CACrD,MAAM,MAA4B,kBAAO,KAAK;AAC9C,KAAI,IAAI,YAAY,KAClB,KAAI,UAAU,aAAa;AAE7B,QAAO;AACR;;;;MCKE,cAAA,CAAA,OAAA,iBAAA;CACH,MAAO,KAAM,WAAW,MAAsC,IAAQ,MAAE,GAAA,cAAkD;AACxH,QAAM,GAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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 @@
|
|
|
1
|
+
export * from './hooks/index.js';
|
|
@@ -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 {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './hooks/index.js';
|
package/react/package.json
CHANGED
package/react/tsconfig.json
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
root{
|
|
2
|
+
//recommended by teammate
|
|
3
|
+
--primary-c:blue,
|
|
4
|
+
--secondary-c:red,
|
|
5
|
+
--grey-c:#888,
|
|
6
|
+
// status
|
|
7
|
+
--error-c,
|
|
8
|
+
--success-c,
|
|
9
|
+
--warning-c,
|
|
10
|
+
--info-c
|
|
11
|
+
//and about shade
|
|
12
|
+
--primary-c-100:#44000000;
|
|
13
|
+
// we must have this color but use semantic color name in our code base
|
|
14
|
+
}
|
|
@@ -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
|