react-hook-toolkit 1.0.13 → 1.0.14
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/README.md +255 -4
- package/dist/contexts/chunk158261.d.ts +16 -0
- package/dist/contexts/chunk158261.js +35 -0
- package/dist/hookExecuter/chunk143.d.ts +20 -0
- package/dist/hookExecuter/chunk143.js +58 -0
- package/dist/hooks/chunk613852.d.ts +55 -0
- package/dist/hooks/chunk613852.js +168 -0
- package/dist/hooks/chunk726433.d.ts +40 -0
- package/dist/hooks/chunk726433.js +267 -0
- package/dist/hooks/chunk940514.d.ts +265 -0
- package/dist/hooks/chunk940514.js +1413 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.js +6 -5
- package/dist/skeletons/chunk613555.d.ts +19 -0
- package/dist/skeletons/chunk613555.js +94 -0
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +24 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,6 +21,10 @@ pnpm add react-hook-toolkit
|
|
|
21
21
|
| ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
|
|
22
22
|
| Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ |
|
|
23
23
|
|
|
24
|
+
### **Authors**
|
|
25
|
+
|
|
26
|
+
_&_Shyamal_(JS_Expert)-red)    
|
|
27
|
+
|
|
24
28
|
## Features
|
|
25
29
|
Here's the properly structured documentation with clear purpose explanations:
|
|
26
30
|
|
|
@@ -595,6 +599,257 @@ useUpdateEffect(() => {
|
|
|
595
599
|
}, [value]);
|
|
596
600
|
```
|
|
597
601
|
|
|
602
|
+
---
|
|
603
|
+
|
|
604
|
+
📌 **usePersistedForm**
|
|
605
|
+
Automatically persists form state to localStorage/sessionStorage and restores it on page reload.
|
|
606
|
+
|
|
607
|
+
```ts
|
|
608
|
+
const { values, setField, reset } = usePersistedForm('form-key', initialValues);
|
|
609
|
+
|
|
610
|
+
// Example
|
|
611
|
+
setField('username', 'john_doe'); // Auto-saves to storage
|
|
612
|
+
reset(); // Clears storage
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
---
|
|
616
|
+
|
|
617
|
+
📌 **useCrossFieldValidation**
|
|
618
|
+
Handles complex validation rules that depend on multiple fields.
|
|
619
|
+
|
|
620
|
+
```ts
|
|
621
|
+
const { errors, validate } = useCrossFieldValidation({
|
|
622
|
+
rules: {
|
|
623
|
+
password: (val, { confirmPassword }) => val === confirmPassword,
|
|
624
|
+
},
|
|
625
|
+
initialValues
|
|
626
|
+
});
|
|
627
|
+
|
|
628
|
+
// Example
|
|
629
|
+
validate('password', 'secret123', { confirmPassword: 'secret123' });
|
|
630
|
+
```
|
|
631
|
+
|
|
632
|
+
---
|
|
633
|
+
|
|
634
|
+
📌 **useFieldArray**
|
|
635
|
+
Manages dynamic arrays of form fields with add/remove/reorder operations.
|
|
636
|
+
|
|
637
|
+
```ts
|
|
638
|
+
const { fields, append, remove, move } = useFieldArray(initialItems);
|
|
639
|
+
|
|
640
|
+
// Example
|
|
641
|
+
append({ name: '', email: '' });
|
|
642
|
+
remove(0); // Remove first item
|
|
643
|
+
move(1, 0); // Move second item to first position
|
|
644
|
+
```
|
|
645
|
+
|
|
646
|
+
---
|
|
647
|
+
|
|
648
|
+
📌 **useFormSubmit**
|
|
649
|
+
Handles form submission with loading/error states and success callbacks.
|
|
650
|
+
|
|
651
|
+
```ts
|
|
652
|
+
const { submit, isLoading, error } = useFormSubmit(apiCall, {
|
|
653
|
+
onSuccess: (data) => console.log('Saved!', data)
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
// Example
|
|
657
|
+
submit(formData);
|
|
658
|
+
```
|
|
659
|
+
|
|
660
|
+
---
|
|
661
|
+
|
|
662
|
+
📌 **useSmartForm**
|
|
663
|
+
Complete form management with validation, submission, and state handling.
|
|
664
|
+
|
|
665
|
+
```ts
|
|
666
|
+
const { register, handleSubmit, errors } = useSmartForm({
|
|
667
|
+
initialValues,
|
|
668
|
+
validationSchema,
|
|
669
|
+
onSubmit: (data) => console.log(data)
|
|
670
|
+
});
|
|
671
|
+
|
|
672
|
+
// Example
|
|
673
|
+
<input {...register('email') />
|
|
674
|
+
<button onClick={handleSubmit}>Save</button>
|
|
675
|
+
```
|
|
676
|
+
|
|
677
|
+
---
|
|
678
|
+
|
|
679
|
+
📌 **useUndo**
|
|
680
|
+
Provides undo/redo functionality for state changes.
|
|
681
|
+
|
|
682
|
+
```ts
|
|
683
|
+
const { state, setState, undo, redo } = useUndo(initialState);
|
|
684
|
+
|
|
685
|
+
// Example
|
|
686
|
+
setState({ items: [...] });
|
|
687
|
+
undo(); // Reverts to previous state
|
|
688
|
+
```
|
|
689
|
+
|
|
690
|
+
---
|
|
691
|
+
|
|
692
|
+
📌 **useFormWizard**
|
|
693
|
+
Manages multi-step forms with navigation between steps.
|
|
694
|
+
|
|
695
|
+
```ts
|
|
696
|
+
const { currentStep, next, prev, goto } = useFormWizard(steps.length);
|
|
697
|
+
|
|
698
|
+
// Example
|
|
699
|
+
next(); // Move to next step
|
|
700
|
+
goto(3); // Jump to step 4
|
|
701
|
+
```
|
|
702
|
+
|
|
703
|
+
---
|
|
704
|
+
|
|
705
|
+
📌 **useWebSocket**
|
|
706
|
+
Manages WebSocket connections with auto-reconnect.
|
|
707
|
+
|
|
708
|
+
```ts
|
|
709
|
+
const { send, message, status } = useWebSocket('ws://api.example.com');
|
|
710
|
+
|
|
711
|
+
// Example
|
|
712
|
+
send(JSON.stringify({ action: 'ping' }));
|
|
713
|
+
```
|
|
714
|
+
|
|
715
|
+
---
|
|
716
|
+
|
|
717
|
+
📌 **useDragReorder**
|
|
718
|
+
Enables drag-and-drop reordering of lists.
|
|
719
|
+
|
|
720
|
+
```ts
|
|
721
|
+
const { items, dragStart, dragOver, drop } = useDragReorder(initialItems);
|
|
722
|
+
|
|
723
|
+
// Example
|
|
724
|
+
<div
|
|
725
|
+
draggable
|
|
726
|
+
onDragStart={() => dragStart(index)}
|
|
727
|
+
onDragOver={() => dragOver(index)}
|
|
728
|
+
onDrop={drop}
|
|
729
|
+
/>
|
|
730
|
+
```
|
|
731
|
+
|
|
732
|
+
---
|
|
733
|
+
|
|
734
|
+
📌 **useInfiniteScroll**
|
|
735
|
+
Implements infinite scroll pagination.
|
|
736
|
+
|
|
737
|
+
```ts
|
|
738
|
+
const { items, loadMore, isLoading } = useInfiniteScroll(fetchCallback);
|
|
739
|
+
|
|
740
|
+
// Example
|
|
741
|
+
<div onScroll={loadMore}>...</div>
|
|
742
|
+
```
|
|
743
|
+
|
|
744
|
+
---
|
|
745
|
+
|
|
746
|
+
📌 **useEventListeners**
|
|
747
|
+
Simplifies adding/removing event listeners.
|
|
748
|
+
|
|
749
|
+
```ts
|
|
750
|
+
useEventListeners({
|
|
751
|
+
click: handleClick,
|
|
752
|
+
resize: handleResize
|
|
753
|
+
});
|
|
754
|
+
|
|
755
|
+
// Example
|
|
756
|
+
useEventListeners({
|
|
757
|
+
keydown: (e) => console.log(e.key)
|
|
758
|
+
});
|
|
759
|
+
```
|
|
760
|
+
|
|
761
|
+
---
|
|
762
|
+
|
|
763
|
+
📌 **useHistoryState**
|
|
764
|
+
Manages state history with undo/redo capabilities.
|
|
765
|
+
|
|
766
|
+
```ts
|
|
767
|
+
const { state, setState, undo, redo } = useHistoryState(initialState);
|
|
768
|
+
|
|
769
|
+
// Example
|
|
770
|
+
setState({...});
|
|
771
|
+
undo(); // Reverts change
|
|
772
|
+
```
|
|
773
|
+
|
|
774
|
+
---
|
|
775
|
+
|
|
776
|
+
📌 **useIdle**
|
|
777
|
+
Detects when user becomes inactive.
|
|
778
|
+
|
|
779
|
+
```ts
|
|
780
|
+
const isIdle = useIdle(30000); // 30s timeout
|
|
781
|
+
|
|
782
|
+
// Example
|
|
783
|
+
{isIdle && <ScreenSaver />}
|
|
784
|
+
```
|
|
785
|
+
|
|
786
|
+
---
|
|
787
|
+
|
|
788
|
+
📌 **useIsFirstRender**
|
|
789
|
+
Returns true only on component's first render.
|
|
790
|
+
|
|
791
|
+
```ts
|
|
792
|
+
const isFirst = useIsFirstRender();
|
|
793
|
+
|
|
794
|
+
// Example
|
|
795
|
+
useEffect(() => {
|
|
796
|
+
if (!isFirst) console.log('Updated!');
|
|
797
|
+
}, [deps]);
|
|
798
|
+
```
|
|
799
|
+
|
|
800
|
+
---
|
|
801
|
+
|
|
802
|
+
📌 **useList**
|
|
803
|
+
Manages array state with utility methods.
|
|
804
|
+
|
|
805
|
+
```ts
|
|
806
|
+
const { list, push, remove, update } = useList(initialItems);
|
|
807
|
+
|
|
808
|
+
// Example
|
|
809
|
+
push(newItem);
|
|
810
|
+
remove(0); // Remove first item
|
|
811
|
+
```
|
|
812
|
+
|
|
813
|
+
---
|
|
814
|
+
|
|
815
|
+
📌 **useLockBodyScroll**
|
|
816
|
+
Locks scrolling on the document body.
|
|
817
|
+
|
|
818
|
+
```ts
|
|
819
|
+
useLockBodyScroll(true); // Enable lock
|
|
820
|
+
|
|
821
|
+
// Example
|
|
822
|
+
useLockBodyScroll(modalIsOpen);
|
|
823
|
+
```
|
|
824
|
+
|
|
825
|
+
---
|
|
826
|
+
|
|
827
|
+
📌 **useLongPress**
|
|
828
|
+
Detects long press gestures.
|
|
829
|
+
|
|
830
|
+
```ts
|
|
831
|
+
const handlers = useLongPress(() => console.log('Long pressed!'), {
|
|
832
|
+
threshold: 1000
|
|
833
|
+
});
|
|
834
|
+
|
|
835
|
+
// Example
|
|
836
|
+
<button {...handlers}>Hold me</button>
|
|
837
|
+
```
|
|
838
|
+
|
|
839
|
+
---
|
|
840
|
+
|
|
841
|
+
📌 **createOptimizedContext**
|
|
842
|
+
Creates optimized React context with selector support.
|
|
843
|
+
|
|
844
|
+
```ts
|
|
845
|
+
const { Provider, useStore } = createOptimizedContext(initialState);
|
|
846
|
+
|
|
847
|
+
// Example
|
|
848
|
+
const user = useStore(state => state.user);
|
|
849
|
+
```
|
|
850
|
+
|
|
851
|
+
---
|
|
852
|
+
|
|
598
853
|
------------------------------------------------ **Custom Components** --------------------------------------------
|
|
599
854
|
|
|
600
855
|
✅ **DynamicLoader**
|
|
@@ -749,10 +1004,6 @@ Displays a skeleton placeholder for a pie chart inside a card layout. Includes a
|
|
|
749
1004
|
|
|
750
1005
|
---
|
|
751
1006
|
|
|
752
|
-
✏️ **Authors**
|
|
753
|
-
|
|
754
|
-
    
|
|
755
|
-
|
|
756
1007
|
**License**
|
|
757
1008
|
|
|
758
1009
|
[MIT](https://opensource.org/licenses)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FC, ReactNode } from 'react';
|
|
2
|
+
export interface DrawerContextValue {
|
|
3
|
+
drawerOpen: boolean;
|
|
4
|
+
openDrawer: () => void;
|
|
5
|
+
closeDrawer: () => void;
|
|
6
|
+
openDrawerInButton: () => void;
|
|
7
|
+
closeDrawerInButton: () => void;
|
|
8
|
+
currentMainMenu?: string;
|
|
9
|
+
setCurrentMainMenu?: (value: string) => void;
|
|
10
|
+
}
|
|
11
|
+
interface DrawerProviderProps {
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
}
|
|
14
|
+
declare const DrawerContext: import("react").Context<DrawerContextValue>;
|
|
15
|
+
export declare const DrawerProvider: FC<DrawerProviderProps>;
|
|
16
|
+
export default DrawerContext;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useState } from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
var DrawerContext = createContext({
|
|
5
|
+
drawerOpen: false,
|
|
6
|
+
openDrawer: function () { },
|
|
7
|
+
closeDrawer: function () { },
|
|
8
|
+
openDrawerInButton: function () { },
|
|
9
|
+
closeDrawerInButton: function () { },
|
|
10
|
+
currentMainMenu: '',
|
|
11
|
+
setCurrentMainMenu: function () { }
|
|
12
|
+
});
|
|
13
|
+
export var DrawerProvider = function (_a) {
|
|
14
|
+
var children = _a.children;
|
|
15
|
+
var _b = useState(true), drawerOpen = _b[0], setDrawer = _b[1];
|
|
16
|
+
var _c = useState(''), currentMainMenu = _c[0], setCurrOpenMenu = _c[1];
|
|
17
|
+
var openDrawer = function () { return setDrawer(true); };
|
|
18
|
+
var closeDrawer = function () { return setDrawer(false); };
|
|
19
|
+
var openDrawerInButton = function () { return setDrawer(false); };
|
|
20
|
+
var closeDrawerInButton = function () { return setDrawer(true); };
|
|
21
|
+
var setCurrentMainMenu = function (value) { return setCurrOpenMenu(value); };
|
|
22
|
+
return (_jsx(DrawerContext.Provider, { value: {
|
|
23
|
+
drawerOpen: drawerOpen,
|
|
24
|
+
openDrawer: openDrawer,
|
|
25
|
+
closeDrawer: closeDrawer,
|
|
26
|
+
openDrawerInButton: openDrawerInButton,
|
|
27
|
+
closeDrawerInButton: closeDrawerInButton,
|
|
28
|
+
currentMainMenu: currentMainMenu,
|
|
29
|
+
setCurrentMainMenu: setCurrentMainMenu
|
|
30
|
+
}, children: children }));
|
|
31
|
+
};
|
|
32
|
+
DrawerProvider.propTypes = {
|
|
33
|
+
children: PropTypes.node.isRequired
|
|
34
|
+
};
|
|
35
|
+
export default DrawerContext;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license HEXE
|
|
3
|
+
* Copyright (c) 2020-2024 Shivaji & Collaborators
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react';
|
|
8
|
+
type HookFunction = () => any;
|
|
9
|
+
declare class HEXE {
|
|
10
|
+
private hs;
|
|
11
|
+
private ss;
|
|
12
|
+
constructor();
|
|
13
|
+
setHook(name: string, hookFunction: HookFunction): this;
|
|
14
|
+
private putHooks;
|
|
15
|
+
component(): React.FC;
|
|
16
|
+
getHook(name: string): any;
|
|
17
|
+
}
|
|
18
|
+
declare const ReactHooksWrapper: React.FC<{}>;
|
|
19
|
+
declare const getHook: (name: string) => any, setHook: (name: string, hookFunction: HookFunction) => HEXE;
|
|
20
|
+
export { ReactHooksWrapper, getHook, setHook };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license HEXE
|
|
3
|
+
* Copyright (c) 2020-2024 Shivaji & Collaborators
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import React from 'react';
|
|
8
|
+
var HEXE = /** @class */ (function () {
|
|
9
|
+
function HEXE() {
|
|
10
|
+
this.hs = {};
|
|
11
|
+
this.ss = {};
|
|
12
|
+
this.setHook = this.setHook.bind(this);
|
|
13
|
+
this.getHook = this.getHook.bind(this);
|
|
14
|
+
this.putHooks = this.putHooks.bind(this);
|
|
15
|
+
}
|
|
16
|
+
HEXE.prototype.setHook = function (name, hookFunction) {
|
|
17
|
+
[
|
|
18
|
+
{ value: name, id: 'name', type: 'string' },
|
|
19
|
+
{ value: hookFunction, id: 'hook', type: 'function' },
|
|
20
|
+
].forEach(function (_a) {
|
|
21
|
+
var value = _a.value, id = _a.id, type = _a.type;
|
|
22
|
+
if (type === 'string' && typeof value !== 'string') {
|
|
23
|
+
throw new TypeError("\"".concat(id, "\" expected to be of type ").concat(type));
|
|
24
|
+
}
|
|
25
|
+
if (type === 'function' && typeof value !== 'function') {
|
|
26
|
+
throw new TypeError("\"".concat(id, "\" expected to be of type ").concat(type));
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
this.hs[name] = {
|
|
30
|
+
name: name,
|
|
31
|
+
hook: hookFunction,
|
|
32
|
+
};
|
|
33
|
+
return this;
|
|
34
|
+
};
|
|
35
|
+
HEXE.prototype.putHooks = function (name, value) {
|
|
36
|
+
this.ss[name] = value;
|
|
37
|
+
};
|
|
38
|
+
HEXE.prototype.component = function () {
|
|
39
|
+
var _this = this;
|
|
40
|
+
/* Author: Shivaji & Shyamal */
|
|
41
|
+
var Component = function () {
|
|
42
|
+
Object.values(_this.hs).forEach(function (_a) {
|
|
43
|
+
var name = _a.name, hook = _a.hook;
|
|
44
|
+
_this.putHooks(name, hook());
|
|
45
|
+
});
|
|
46
|
+
return /*#__PURE__*/ React.createElement(React.Fragment, null);
|
|
47
|
+
};
|
|
48
|
+
return Component;
|
|
49
|
+
};
|
|
50
|
+
HEXE.prototype.getHook = function (name) {
|
|
51
|
+
return this.ss[name];
|
|
52
|
+
};
|
|
53
|
+
return HEXE;
|
|
54
|
+
}());
|
|
55
|
+
var o = new HEXE();
|
|
56
|
+
var ReactHooksWrapper = o.component();
|
|
57
|
+
var getHook = o.getHook, setHook = o.setHook;
|
|
58
|
+
export { ReactHooksWrapper, getHook, setHook };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
export declare const DynamicLoader: (Component: any) => (props: any) => import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
interface PropsType {
|
|
4
|
+
type: string;
|
|
5
|
+
msg: string;
|
|
6
|
+
duration?: number;
|
|
7
|
+
}
|
|
8
|
+
export declare const AlertMessage: FC<PropsType>;
|
|
9
|
+
interface DetailsCardProps {
|
|
10
|
+
isLoading?: boolean;
|
|
11
|
+
title: string;
|
|
12
|
+
details: any[];
|
|
13
|
+
spacing?: number;
|
|
14
|
+
boxShadow?: string;
|
|
15
|
+
background?: string;
|
|
16
|
+
loaderType?: 'skeleton' | 'circular';
|
|
17
|
+
displayType?: 'flex' | 'block';
|
|
18
|
+
}
|
|
19
|
+
export declare const DetailsCard: ({ isLoading, title, details, spacing, boxShadow, background, loaderType, displayType, }: DetailsCardProps) => import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
export declare const LabeledValue: ({ label, value, style }: any) => import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
interface FileComponentProps {
|
|
22
|
+
primaryKey: string | number;
|
|
23
|
+
filename: string;
|
|
24
|
+
size: string | number;
|
|
25
|
+
onDownload?: any;
|
|
26
|
+
width?: number;
|
|
27
|
+
borderColor?: string;
|
|
28
|
+
fileColor?: 'inherit' | 'primary' | 'secondary' | 'error' | 'disabled' | 'action';
|
|
29
|
+
isDownloading: boolean;
|
|
30
|
+
}
|
|
31
|
+
export declare const FilePreview: ({ primaryKey, filename, size, onDownload, width, borderColor, fileColor, isDownloading, }: FileComponentProps) => import("react/jsx-runtime").JSX.Element;
|
|
32
|
+
interface UploadButtonProps {
|
|
33
|
+
isUpload?: boolean;
|
|
34
|
+
color?: 'inherit' | 'primary' | 'secondary' | 'success' | 'error' | 'info' | 'warning';
|
|
35
|
+
state?: {
|
|
36
|
+
isUploaded?: boolean;
|
|
37
|
+
isUploadError?: boolean;
|
|
38
|
+
isLoadingUpload?: boolean;
|
|
39
|
+
};
|
|
40
|
+
onFileSelect: (file: File) => void;
|
|
41
|
+
}
|
|
42
|
+
export declare const UploadFile: React.FC<UploadButtonProps>;
|
|
43
|
+
interface DownloadButtonState {
|
|
44
|
+
isDownloaded?: boolean;
|
|
45
|
+
isDownloadError?: boolean;
|
|
46
|
+
isLoadingDownload?: boolean;
|
|
47
|
+
}
|
|
48
|
+
interface DownloadFileProps {
|
|
49
|
+
isDownload?: boolean;
|
|
50
|
+
color?: 'inherit' | 'primary' | 'secondary' | 'success' | 'error' | 'info' | 'warning';
|
|
51
|
+
state?: DownloadButtonState;
|
|
52
|
+
onDownload: () => void;
|
|
53
|
+
}
|
|
54
|
+
export declare const DownloadFile: React.FC<DownloadFileProps>;
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
|
+
import { forwardRef } from 'react';
|
|
14
|
+
import { useEffect, useCallback, useRef, Suspense } from 'react';
|
|
15
|
+
import { Box, Alert, AlertTitle, IconButton, CardContent, Tooltip, Typography, Card, Grid, Skeleton, CircularProgress, } from '@mui/material';
|
|
16
|
+
import { Close, InsertDriveFile, Image, Description, Download, CheckCircleOutlined, ErrorOutlineOutlined, Upload, } from '@mui/icons-material';
|
|
17
|
+
import NProgress from 'nprogress';
|
|
18
|
+
import { ErrorBoundary } from 'react-error-boundary';
|
|
19
|
+
import { promise } from '../utils';
|
|
20
|
+
import { getHook } from '../hookExecuter/chunk143';
|
|
21
|
+
import { useWindowSize } from './chunk940514';
|
|
22
|
+
function Fallback(_a) {
|
|
23
|
+
var error = _a.error;
|
|
24
|
+
return (_jsxs(Box, { sx: { padding: 2 }, children: [process.env.NODE_ENV === 'production' && (_jsxs(Alert, { sx: { py: 0, borderLeft: '2px solid #00abff !important', border: '1px solid #d0cfcf' }, severity: "info", children: [_jsx(AlertTitle, { children: "Page Loading Error" }), "Please check your network connection..."] })), process.env.NODE_ENV !== 'production' && (_jsxs(Alert, { severity: "error", sx: { py: 0, borderTop: '2px solid #791212ad !important', border: '1px solid #d0cfcf' }, children: [_jsx(AlertTitle, { children: "Error" }), error.message] }))] }));
|
|
25
|
+
}
|
|
26
|
+
var Error = function (_a) {
|
|
27
|
+
var children = _a.children;
|
|
28
|
+
var firstRender = useRef(false);
|
|
29
|
+
var handleReload = useCallback(function () {
|
|
30
|
+
if (!firstRender.current) {
|
|
31
|
+
firstRender.current = true; // Ensure this runs only once
|
|
32
|
+
promise(1500).then(function () {
|
|
33
|
+
window.location.reload();
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}, []);
|
|
37
|
+
return (_jsx(ErrorBoundary, { FallbackComponent: Fallback, onError: function () {
|
|
38
|
+
if (process.env.NODE_ENV === 'production') {
|
|
39
|
+
handleReload();
|
|
40
|
+
}
|
|
41
|
+
}, children: children }));
|
|
42
|
+
};
|
|
43
|
+
var LoadingScreen = function () {
|
|
44
|
+
useEffect(function () {
|
|
45
|
+
NProgress.start();
|
|
46
|
+
return function () {
|
|
47
|
+
NProgress.done();
|
|
48
|
+
};
|
|
49
|
+
}, []);
|
|
50
|
+
return (_jsx(Box, { sx: {
|
|
51
|
+
backgroundColor: 'background.paper',
|
|
52
|
+
minHeight: '100%',
|
|
53
|
+
} }));
|
|
54
|
+
};
|
|
55
|
+
// prettier-ignore
|
|
56
|
+
export var DynamicLoader = function (Component) { return function (props) { return (_jsx(Error, { children: _jsx(Suspense, { fallback: _jsx(LoadingScreen, {}), children: _jsx(Component, __assign({}, props)) }) })); }; };
|
|
57
|
+
export var AlertMessage = function (_a) {
|
|
58
|
+
var type = _a.type, msg = _a.msg, duration = _a.duration;
|
|
59
|
+
var _b = getHook('snackBar'), enqueueSnackbar = _b.enqueueSnackbar, closeSnackbar = _b.closeSnackbar;
|
|
60
|
+
if (msg !== undefined && msg !== '') {
|
|
61
|
+
enqueueSnackbar(msg !== null && msg !== void 0 ? msg : '', {
|
|
62
|
+
anchorOrigin: {
|
|
63
|
+
// @shivaji perpose dyanamic global alert.
|
|
64
|
+
horizontal: 'right',
|
|
65
|
+
vertical: 'top',
|
|
66
|
+
},
|
|
67
|
+
variant: type,
|
|
68
|
+
preventDuplicate: true,
|
|
69
|
+
// persist: true, whenever you want to close.
|
|
70
|
+
action: function (key) { return (_jsx(IconButton, { "aria-label": "close", size: "small", onClick: function () { return closeSnackbar(key); }, children: _jsx(Close, { fontSize: "small", sx: { color: '#fff' } }) })); },
|
|
71
|
+
autoHideDuration: duration !== null && duration !== void 0 ? duration : 6000,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
};
|
|
76
|
+
export var DetailsCard = function (_a) {
|
|
77
|
+
var _b = _a.isLoading, isLoading = _b === void 0 ? false : _b, title = _a.title, details = _a.details, _c = _a.spacing, spacing = _c === void 0 ? 2 : _c, _d = _a.boxShadow, boxShadow = _d === void 0 ? '0px 0px 2px 2px #d8d8d8' : _d, _e = _a.background, background = _e === void 0 ? '#eee' : _e, _f = _a.loaderType, loaderType = _f === void 0 ? 'skeleton' : _f, _g = _a.displayType, displayType = _g === void 0 ? 'flex' : _g;
|
|
78
|
+
var width = useWindowSize().width;
|
|
79
|
+
return (_jsx(Card, { sx: { boxShadow: boxShadow }, children: _jsxs(CardContent, { children: [_jsx(Typography, { variant: "h6", sx: { background: background, padding: '4px' }, children: title }), _jsx(Grid, { container: true, spacing: spacing, sx: { mt: 1 }, children: details.filter(Boolean).map(function (item, index) { return (_jsx(Grid, { item: true, xs: 12, sm: 6, md: 6, lg: width < 1367 ? 6 : 4, children: _jsxs(Box, { display: displayType, alignItems: "center", sx: { fontSize: '14px' }, children: [_jsxs(Typography, { fontWeight: "bold", component: "span", sx: { fontSize: '14px' }, children: [item === null || item === void 0 ? void 0 : item.label, ":\u00A0"] }), isLoading ? (loaderType === 'skeleton' ? (_jsx(Skeleton, { sx: { ml: 2 }, variant: "text", width: 100, height: 20 })) : (_jsx(CircularProgress, { sx: { ml: 2 }, color: "success", size: 18 }))) : (_jsx(Typography, { component: "span", sx: { fontSize: '14px' }, children: (item === null || item === void 0 ? void 0 : item.value) !== undefined && (item === null || item === void 0 ? void 0 : item.value) !== null && (item === null || item === void 0 ? void 0 : item.value) !== '' ? item.value : 'N/A' }))] }) }, index.toString())); }) })] }) }));
|
|
80
|
+
};
|
|
81
|
+
export var LabeledValue = function (_a) {
|
|
82
|
+
var label = _a.label, value = _a.value, _b = _a.style, style = _b === void 0 ? undefined : _b;
|
|
83
|
+
return (_jsx(_Fragment, { children: _jsx(Typography, { sx: style !== null && style !== void 0 ? style : { padding: '5px' }, children: _jsxs("span", { style: { fontSize: '13px' }, children: [_jsxs("b", { children: [label, " "] }), ": ", value !== null && value !== void 0 ? value : 'N/A'] }) }) }));
|
|
84
|
+
};
|
|
85
|
+
export var FilePreview = function (_a) {
|
|
86
|
+
var primaryKey = _a.primaryKey, filename = _a.filename, size = _a.size, _b = _a.onDownload, onDownload = _b === void 0 ? undefined : _b, _c = _a.width, width = _c === void 0 ? 350 : _c, _d = _a.borderColor, borderColor = _d === void 0 ? '#dfdfdf' : _d, _e = _a.fileColor, fileColor = _e === void 0 ? 'primary' : _e, _f = _a.isDownloading, isDownloading = _f === void 0 ? false : _f;
|
|
87
|
+
// Icon mapping configuration
|
|
88
|
+
var iconMap = {
|
|
89
|
+
pdf: _jsx(InsertDriveFile, { fontSize: "large", color: fileColor }),
|
|
90
|
+
image: _jsx(Image, { fontSize: "large", color: fileColor }),
|
|
91
|
+
doc: _jsx(Description, { fontSize: "large", color: fileColor }),
|
|
92
|
+
default: _jsx(Description, { fontSize: "large", color: fileColor }),
|
|
93
|
+
};
|
|
94
|
+
// Determine file type from filename extension
|
|
95
|
+
var getFileType = function (filenames) {
|
|
96
|
+
var extension = filenames.split('.').pop().toLowerCase();
|
|
97
|
+
if (['pdf'].includes(extension))
|
|
98
|
+
return 'pdf';
|
|
99
|
+
if (['jpg', 'jpeg', 'png', 'gif'].includes(extension))
|
|
100
|
+
return 'image';
|
|
101
|
+
if (['doc', 'docx', 'txt'].includes(extension))
|
|
102
|
+
return 'doc';
|
|
103
|
+
return 'default';
|
|
104
|
+
};
|
|
105
|
+
return (_jsx(Card, { variant: "outlined", sx: {
|
|
106
|
+
maxWidth: width,
|
|
107
|
+
minWidth: width,
|
|
108
|
+
border: "1px solid ".concat(borderColor),
|
|
109
|
+
borderRadius: 1,
|
|
110
|
+
'&:hover': { boxShadow: 2 },
|
|
111
|
+
marginLeft: 1,
|
|
112
|
+
}, children: _jsxs(CardContent, { sx: {
|
|
113
|
+
display: 'flex',
|
|
114
|
+
alignItems: 'center',
|
|
115
|
+
gap: 2,
|
|
116
|
+
padding: '8px !important',
|
|
117
|
+
}, children: [iconMap[getFileType(filename)], _jsxs(Box, { sx: { flexGrow: 1 }, children: [filename.length > 33 ? (_jsx(Tooltip, { title: filename, placement: "top", arrow: true, children: _jsx(Typography, { sx: {
|
|
118
|
+
fontSize: '14px',
|
|
119
|
+
whiteSpace: 'nowrap',
|
|
120
|
+
overflow: 'hidden',
|
|
121
|
+
textOverflow: 'ellipsis',
|
|
122
|
+
maxWidth: width - 120,
|
|
123
|
+
}, children: filename }) })) : (_jsx(Typography, { sx: {
|
|
124
|
+
fontSize: '14px',
|
|
125
|
+
whiteSpace: 'nowrap',
|
|
126
|
+
overflow: 'hidden',
|
|
127
|
+
textOverflow: 'ellipsis',
|
|
128
|
+
maxWidth: width - 120,
|
|
129
|
+
}, children: filename })), _jsx(Typography, { variant: "caption", color: "text.secondary", children: size })] }), _jsx(IconButton, { disabled: onDownload === undefined, "aria-label": "download", onClick: function () { return onDownload(primaryKey); }, sx: { color: '#dfdfdf', '&:hover': { color: 'primary.main' } }, children: isDownloading ? (_jsx(CircularProgress, { color: "success", size: 20 })) : (_jsx(Download, { fontSize: "small", color: "primary" })) })] }) }));
|
|
130
|
+
};
|
|
131
|
+
var VisuallyHiddenInput = forwardRef(function (props, ref) { return (_jsx("input", __assign({ ref: ref, type: "file", style: {
|
|
132
|
+
position: 'absolute',
|
|
133
|
+
width: 1,
|
|
134
|
+
height: 1,
|
|
135
|
+
padding: 0,
|
|
136
|
+
overflow: 'hidden',
|
|
137
|
+
clip: 'rect(0,0,0,0)',
|
|
138
|
+
whiteSpace: 'nowrap',
|
|
139
|
+
border: 0,
|
|
140
|
+
} }, props))); });
|
|
141
|
+
export var UploadFile = function (_a) {
|
|
142
|
+
var _b = _a.isUpload, isUpload = _b === void 0 ? true : _b, color = _a.color, _c = _a.state, state = _c === void 0 ? {} : _c, onFileSelect = _a.onFileSelect;
|
|
143
|
+
var onFileInputChange = function (e) {
|
|
144
|
+
var _a;
|
|
145
|
+
var file = (_a = e.target.files) === null || _a === void 0 ? void 0 : _a[0];
|
|
146
|
+
if (file) {
|
|
147
|
+
onFileSelect(file);
|
|
148
|
+
e.target.value = '';
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
return (_jsx(Tooltip, { title: "Upload", children: _jsxs(Box, { sx: { position: 'relative', display: 'inline-block' }, children: [_jsxs(IconButton, { disabled: !isUpload, component: "label", children: [(state === null || state === void 0 ? void 0 : state.isUploaded) ? (_jsx(CheckCircleOutlined, { color: "success" })) : (state === null || state === void 0 ? void 0 : state.isUploadError) ? (_jsx(ErrorOutlineOutlined, { color: "error" })) : (_jsx(Upload, { color: color !== null && color !== void 0 ? color : 'primary' })), _jsx(VisuallyHiddenInput, { onChange: onFileInputChange })] }), (state === null || state === void 0 ? void 0 : state.isLoadingUpload) && (_jsx(CircularProgress, { size: "40px", sx: {
|
|
152
|
+
position: 'absolute',
|
|
153
|
+
top: 0,
|
|
154
|
+
left: 0,
|
|
155
|
+
zIndex: 1,
|
|
156
|
+
} }))] }) }));
|
|
157
|
+
};
|
|
158
|
+
export var DownloadFile = function (_a) {
|
|
159
|
+
var _b = _a.isDownload, isDownload = _b === void 0 ? true : _b, color = _a.color, _c = _a.state, state = _c === void 0 ? {} : _c, onDownload = _a.onDownload;
|
|
160
|
+
return (_jsx(Tooltip, { title: "Download", children: _jsxs(Box, { sx: { position: 'relative', display: 'inline-block' }, children: [_jsx(IconButton, { disabled: !isDownload || (state === null || state === void 0 ? void 0 : state.isLoadingDownload), onClick: onDownload, sx: {
|
|
161
|
+
bgcolor: function (theme) { return (color ? (theme.palette.mode === 'dark' ? '#303041' : color) : 'default'); },
|
|
162
|
+
}, children: (state === null || state === void 0 ? void 0 : state.isDownloaded) ? (_jsx(CheckCircleOutlined, { color: "success" })) : (state === null || state === void 0 ? void 0 : state.isDownloadError) ? (_jsx(ErrorOutlineOutlined, { color: "error" })) : (_jsx(Download, { color: color !== null && color !== void 0 ? color : 'primary' })) }), (state === null || state === void 0 ? void 0 : state.isLoadingDownload) && (_jsx(CircularProgress, { size: "40px", sx: {
|
|
163
|
+
position: 'absolute',
|
|
164
|
+
top: 0,
|
|
165
|
+
left: 0,
|
|
166
|
+
zIndex: 1,
|
|
167
|
+
} }))] }) }));
|
|
168
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export declare function useHistoryState<T>(initialPresent: T): {
|
|
2
|
+
state: T;
|
|
3
|
+
set: (newPresent: T) => void;
|
|
4
|
+
undo: () => void;
|
|
5
|
+
redo: () => void;
|
|
6
|
+
reset: (newPresent: T) => void;
|
|
7
|
+
clear: () => void;
|
|
8
|
+
canUndo: boolean;
|
|
9
|
+
canRedo: boolean;
|
|
10
|
+
past: T[];
|
|
11
|
+
future: T[];
|
|
12
|
+
};
|
|
13
|
+
export declare function useIdle(ms?: number): boolean;
|
|
14
|
+
export declare function useIsFirstRender(): boolean;
|
|
15
|
+
export declare function useList<T>(initialList?: T[]): {
|
|
16
|
+
list: T[];
|
|
17
|
+
actions: {
|
|
18
|
+
set: (newList: T[]) => void;
|
|
19
|
+
push: (element: T) => void;
|
|
20
|
+
removeAt: (index: number) => void;
|
|
21
|
+
insertAt: (index: number, element: T) => void;
|
|
22
|
+
updateAt: (index: number, element: T) => void;
|
|
23
|
+
clear: () => void;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export declare function useLockBodyScroll(lock?: boolean): void;
|
|
27
|
+
type LongPressOptions = {
|
|
28
|
+
threshold?: number;
|
|
29
|
+
onStart?: (event: Event) => void;
|
|
30
|
+
onFinish?: (event: Event) => void;
|
|
31
|
+
onCancel?: (event: Event) => void;
|
|
32
|
+
};
|
|
33
|
+
export declare function useLongPress(callback: (event: Event) => void, options?: LongPressOptions): {
|
|
34
|
+
onMouseDown: any;
|
|
35
|
+
onMouseUp: any;
|
|
36
|
+
onMouseLeave: any;
|
|
37
|
+
onTouchStart: any;
|
|
38
|
+
onTouchEnd: any;
|
|
39
|
+
};
|
|
40
|
+
export {};
|