@dakataa/crud-react 1.0.0 → 1.0.1

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.
Files changed (84) hide show
  1. package/dist/crud-react.css +5 -0
  2. package/dist/crud-react.js +14467 -0
  3. package/dist/denied-CgoMpaA7.js +27 -0
  4. package/dist/info-D-NzIEYs.js +144 -0
  5. package/dist/main.d.ts +19 -0
  6. package/dist/success-Bu_BJcf1.js +27 -0
  7. package/dist/warning-B1nr7TsB.js +27 -0
  8. package/package.json +11 -3
  9. package/.env +0 -3
  10. package/babel-plugin-macros.config.js +0 -5
  11. package/index.html +0 -12
  12. package/public/favicon.ico +0 -0
  13. package/public/logo192.png +0 -0
  14. package/public/logo512.png +0 -0
  15. package/public/manifest.json +0 -25
  16. package/public/robots.txt +0 -3
  17. package/src/Crud.tsx +0 -29
  18. package/src/CrudContext.tsx +0 -21
  19. package/src/CrudLoader.tsx +0 -27
  20. package/src/assets/images/alert/denied.json +0 -1
  21. package/src/assets/images/alert/info.json +0 -1
  22. package/src/assets/images/alert/success.json +0 -1
  23. package/src/assets/images/alert/warning.json +0 -1
  24. package/src/assets/style/alert.scss +0 -97
  25. package/src/component/Animation.tsx +0 -50
  26. package/src/component/BaseButton.tsx +0 -26
  27. package/src/component/Button.tsx +0 -15
  28. package/src/component/Dropdown.tsx +0 -55
  29. package/src/component/EmptyView.tsx +0 -5
  30. package/src/component/Link.tsx +0 -11
  31. package/src/component/Modal.tsx +0 -174
  32. package/src/component/ModifyForm.tsx +0 -139
  33. package/src/component/TemplateBlock.tsx +0 -21
  34. package/src/component/TemplateExtend.tsx +0 -17
  35. package/src/component/TemplateParentBlock.tsx +0 -7
  36. package/src/component/Translation.tsx +0 -7
  37. package/src/component/ViewLoader.tsx +0 -33
  38. package/src/component/crud/DynamicView.tsx +0 -42
  39. package/src/component/crud/FormView.tsx +0 -29
  40. package/src/component/crud/GridTableView.tsx +0 -205
  41. package/src/component/crud/PaginatorView.tsx +0 -80
  42. package/src/component/error/ErrorBoundary.tsx +0 -78
  43. package/src/component/error/Exception.tsx +0 -17
  44. package/src/component/error/HttpException.tsx +0 -24
  45. package/src/component/form/Choice.tsx +0 -119
  46. package/src/component/form/Form.tsx +0 -233
  47. package/src/component/form/FormAlert.tsx +0 -19
  48. package/src/component/form/FormFieldError.tsx +0 -16
  49. package/src/component/form/FormGroup.tsx +0 -53
  50. package/src/component/form/FormWidget.tsx +0 -34
  51. package/src/component/form/Input.tsx +0 -63
  52. package/src/component/form/constraint/Contraint.tsx +0 -8
  53. package/src/component/form/constraint/NotBlank.tsx +0 -20
  54. package/src/component/hooks/GetData.tsx +0 -137
  55. package/src/context/ActionContext.tsx +0 -99
  56. package/src/context/AlertContext.tsx +0 -181
  57. package/src/context/ModalContext.tsx +0 -56
  58. package/src/context/SessionContext.tsx +0 -97
  59. package/src/helper/ObjectUtils.tsx +0 -36
  60. package/src/helper/RouterUtils.tsx +0 -24
  61. package/src/helper/StingUtils.tsx +0 -25
  62. package/src/index.tsx +0 -23
  63. package/src/layout/default/Base.tsx +0 -15
  64. package/src/layout/default/Error.tsx +0 -27
  65. package/src/layout/default/Main.tsx +0 -64
  66. package/src/layout/default/component/Navigation.tsx +0 -197
  67. package/src/page/List.tsx +0 -268
  68. package/src/page/Modify.tsx +0 -156
  69. package/src/react-app-env.d.ts +0 -2
  70. package/src/setupTests.ts +0 -5
  71. package/src/type/ActionType.tsx +0 -10
  72. package/src/type/ColumnType.tsx +0 -18
  73. package/src/type/ExceptionType.tsx +0 -7
  74. package/src/type/FormType.tsx +0 -6
  75. package/src/type/FormViewType.tsx +0 -37
  76. package/src/type/ListMetaType.tsx +0 -7
  77. package/src/type/ListType.tsx +0 -20
  78. package/src/type/ModifyType.tsx +0 -10
  79. package/src/type/RedirectType.tsx +0 -6
  80. package/src/type/RouteType.tsx +0 -5
  81. package/tsconfig.app.json +0 -46
  82. package/tsconfig.json +0 -11
  83. package/tsconfig.node.json +0 -15
  84. package/vite.config.ts +0 -33
@@ -1,181 +0,0 @@
1
- import '@src/assets/style/alert.scss';
2
- import React, {PropsWithChildren, useContext, useEffect, useRef, useState} from "react";
3
- import Modal, {ModalRefType} from "@src/component/Modal.tsx";
4
- import TemplateExtend from "@src/component/TemplateExtend.tsx";
5
- import Button from "@src/component/Button.tsx";
6
- import {default as LottieAnimation} from "@src/component/Animation.tsx";
7
-
8
- type AlertConfigOptionalType = {
9
- [K in keyof AlertConfigType]?: AlertConfigType[K]
10
- }
11
-
12
- type AlertContextType = {
13
- open: (config: AlertConfigOptionalType) => void;
14
- };
15
-
16
- const AlertContext = React.createContext<AlertContextType | undefined>(undefined);
17
-
18
- export enum Icon {
19
- success,
20
- denied,
21
- warning,
22
- info,
23
- confirm
24
- }
25
-
26
- export enum Animation {
27
- scale = 'scale',
28
- fade = 'fade'
29
- }
30
-
31
- export enum Size {
32
- small = 'sm',
33
- default = 'auto',
34
- large = 'lg',
35
- extraLarge = 'xl'
36
- }
37
-
38
- export type Action = {
39
- label: string;
40
- classList?: string[];
41
- };
42
-
43
- export type AlertConfigType = {
44
- title: string;
45
- text?: string | null;
46
- icon: Icon | string;
47
- animation: Animation | string;
48
- size: Size | string;
49
- actions?: { [key: string]: Action } | null;
50
- allowClose?: boolean;
51
- timeout?: number;
52
- timeoutProgress?: boolean;
53
- onResult?: (result: Result) => void
54
- };
55
-
56
- export type Result = {
57
- [action: string]: boolean;
58
- isConfirmed: boolean;
59
- isCancelled: boolean;
60
- isDenied: boolean;
61
- }
62
-
63
- export function UseAlert() {
64
- const context = React.useContext<AlertContextType | undefined>(AlertContext);
65
- if (context === undefined) {
66
- throw new Error("UseAlert must be within AlertProvider")
67
- }
68
-
69
- return context;
70
- }
71
-
72
- export function AlertProvider(props: PropsWithChildren) {
73
- const [alert, setAlert] = useState<AlertConfigType>();
74
-
75
- const updates = useRef(0);
76
- const modalRef = useRef<ModalRefType>(undefined);
77
- const [animationData, setAnimationData] = useState(null);
78
-
79
- useEffect(() => {
80
- updates.current += 1;
81
- }, [alert]);
82
-
83
- const animationFiles = import.meta.glob('@src/assets/images/alert/*');
84
-
85
- const open = (config?: AlertConfigOptionalType): void => {
86
- let alertConfig = {
87
- title: 'Are you confirm?',
88
- icon: Icon.success,
89
- animation: Animation.scale,
90
- size: Size.default,
91
- allowClose: false,
92
- timeoutProgress: false,
93
- ...(config || {})
94
- };
95
-
96
- const iconMap = {
97
- [Icon.success]: 'success.json',
98
- [Icon.denied]: 'denied.json',
99
- [Icon.warning]: 'warning.json',
100
- [Icon.info]: 'info.json',
101
- [Icon.confirm]: 'info.json',
102
- };
103
-
104
- if (Object.hasOwn(iconMap, alertConfig.icon)) {
105
- const iconPath = iconMap[alertConfig.icon as Icon];
106
- const iconFilePath = Object.keys(animationFiles).filter(k => k.endsWith(iconPath)).pop()
107
- if(iconFilePath) {
108
- animationFiles[iconFilePath]().then((module: any) => {
109
- setAnimationData(module.default)
110
- });
111
- }
112
- }
113
-
114
- if (!alertConfig.actions && !alertConfig.timeoutProgress) {
115
- alertConfig.actions = {
116
- cancel: {
117
- label: 'Cancel',
118
- classList: ['btn-outline-primary']
119
- },
120
- confirm: {
121
- label: 'Confirm',
122
- }
123
- }
124
- }
125
-
126
- if (modalRef.current?.isOpen()) {
127
- modalRef.current?.close().finally(() => {
128
- setAlert(alertConfig);
129
- });
130
- } else {
131
- setAlert(alertConfig);
132
- }
133
- }
134
-
135
- const actionHandler = (action: string) => {
136
- const result: Result = {
137
- [action]: true,
138
- isConfirmed: action === 'confirm',
139
- isCancelled: action === 'cancel',
140
- isDenied: action === 'deny',
141
- };
142
-
143
- alert?.onResult && alert.onResult(result);
144
- modalRef.current?.close().then(() => {
145
- setAnimationData(null);
146
- setAlert(undefined);
147
- });
148
- };
149
-
150
- return (
151
- <AlertContext.Provider value={{open}}>
152
- {props.children}
153
- {alert && (
154
- <Modal size={alert.size as any} className={"modal-alert"} animation={alert.animation} open={true} ref={modalRef}>
155
- <TemplateExtend name={"header"}/>
156
- <TemplateExtend name={"footer"}/>
157
- <TemplateExtend name={"content"}>
158
- <div className={"d-flex flex-column align-items-center"}>
159
- {animationData !== null && (
160
- <LottieAnimation className={"modal-alert-icon"} animationData={animationData} />
161
- )}
162
- <h3 className={"modal-alert-title"}>{alert.title}</h3>
163
- {!!alert.text?.length && (
164
- <p className={"modal-alert-text"}>{alert.text}</p>
165
- )}
166
- {alert.actions && (
167
- <div className={"d-flex justify-content-center align-items-center"}>
168
- {Object.keys(alert.actions).map((action: string) => (
169
- <Button key={action}
170
- className={"btn btn-lg mx-2 " + (alert.actions?.[action].classList ?? ["btn-primary"]).join(' ')}
171
- onClick={() => actionHandler(action)}>{(alert.actions?.[action] ?? null)?.label || action}</Button>
172
- ))}
173
- </div>
174
- )}
175
- </div>
176
- </TemplateExtend>
177
- </Modal>
178
- )}
179
- </AlertContext.Provider>
180
- );
181
- }
@@ -1,56 +0,0 @@
1
- import React, {PropsWithChildren, useEffect, useRef, useState} from "react";
2
- import ViewLoader from "@src/component/ViewLoader.tsx";
3
- import {OnClickAction} from "@src/component/crud/GridTableView.tsx";
4
- import {ModalType} from "@src/component/Modal.tsx";
5
- import CrudContext from "@src/CrudContext.tsx";
6
-
7
- type ModalActionType = {
8
- action: OnClickAction;
9
- props?: ModalType
10
- }
11
-
12
- type ModalContextType = {
13
- setModal?: (modal: ModalActionType) => void;
14
- }
15
-
16
- const ModalContext = React.createContext<ModalContextType>({});
17
-
18
- export function UseModal() {
19
- const {setModal} = React.useContext<ModalContextType>(ModalContext);
20
-
21
- return {
22
- openModal: (modal: ModalActionType) => {
23
- setModal && setModal(modal)
24
- }
25
- };
26
- }
27
-
28
- export function ModalProvider(props: PropsWithChildren) {
29
- const [modal, setModal] = useState<ModalActionType | null>(null);
30
-
31
- const updates = useRef(0);
32
- useEffect(() => {
33
- updates.current += 1;
34
- }, [modal]);
35
-
36
- return (
37
- <ModalContext.Provider value={{setModal}}>
38
- {props.children}
39
- {modal && (
40
- <CrudContext>
41
- <ViewLoader
42
- key={updates.current}
43
- view={modal.action.action.name || 'list'}
44
- namespace={modal.action.action.namespace || ''}
45
- props={{
46
- action: modal.action.action,
47
- routeParams: modal.action.parameters,
48
- modal: true,
49
- props: modal.props
50
- }}
51
- />
52
- </CrudContext>
53
- )}
54
- </ModalContext.Provider>
55
- );
56
- }
@@ -1,97 +0,0 @@
1
- import React from "react";
2
-
3
- const SESSION_KEY = 'settings';
4
-
5
- export type Session = {
6
- locale?: string,
7
- }
8
-
9
- const initialState: Session = {
10
- locale: import.meta.env.VIEW_LOCALE || 'en',
11
- // accessToken: null,
12
- // user: null,
13
- // branch: null,
14
- // authChain: []
15
- };
16
-
17
- const SessionContext = React.createContext<any>(initialState);
18
-
19
- function reducer(currentState: Session, newState: Session) {
20
- const state = {
21
- ...currentState,
22
- ...newState
23
- };
24
-
25
- sessionStorage.setItem(SESSION_KEY, btoa(JSON.stringify(state)));
26
-
27
- return state;
28
- }
29
-
30
- export function UseSession() {
31
- const context = React.useContext<any>(SessionContext);
32
- if (!context) {
33
- throw new Error("useSession must be used in SessionProvider");
34
- }
35
-
36
- const [state, dispatch] = context;
37
-
38
- // const getUserByAccessToken = (accessToken: AccessToken) => Fetch({
39
- // url: buildEndpointURL('/internal-api/profile/me'),
40
- // accessToken: accessToken,
41
- // showErrors: false
42
- // });
43
-
44
- return {
45
- state,
46
- setParameter: (key: string, value: any) => {
47
- dispatch({[key]: value})
48
- },
49
- setParameters: (parameters: Object) => {
50
- dispatch(parameters)
51
- },
52
- isLoggedIn: (): boolean => {
53
- return state?.accessToken !== null;
54
- },
55
- isLoggedAs: (): boolean => {
56
- return !!state?.authChain.length;
57
- },
58
- // login: (token: AccessToken) => {
59
- // dispatch({accessToken: token});
60
- // },
61
- logout: () => {
62
- dispatch({accessToken: null, user: null, authChain: []});
63
- },
64
- // setUser: (user: User) => {
65
- // dispatch({user: user});
66
- // },
67
- // getMe: () => {
68
- // getUserByAccessToken(state.accessToken).then((result: Response) => {
69
- // switch (result.status) {
70
- // case 200: {
71
- // dispatch({user: result.data});
72
- // break;
73
- // }
74
- // }
75
- // }).catch((result: Response) => {
76
- // dispatch({accessToken: null, user: null});
77
- // });
78
- // },
79
-
80
- };
81
- }
82
-
83
- export function SessionProvider(props: any) {
84
- let state: any = initialState;
85
- try {
86
- const data = sessionStorage.getItem(SESSION_KEY);
87
- state = JSON.parse(atob(data || ''));
88
- } catch (e) {
89
- reducer(initialState, state);
90
- }
91
-
92
- return (
93
- <SessionContext.Provider value={React.useReducer(reducer, state)}>
94
- {props.children}
95
- </SessionContext.Provider>
96
- );
97
- }
@@ -1,36 +0,0 @@
1
- export const objectKeyIntersect = (entry:object, ...objects: object[]): object => {
2
- objects.forEach((object) => {
3
- Object.keys(entry).filter((key) => object.hasOwnProperty(key)).forEach((key) => {
4
- delete entry[key as keyof object];
5
- })
6
- })
7
-
8
- return entry;
9
- }
10
-
11
- export const objectKeyDiff = (entry:object, ...objects: object[]): object => {
12
- objects.forEach((object) => {
13
- Object.keys(entry).filter((key) => !object.hasOwnProperty(key)).forEach((key) => {
14
- delete entry[key as keyof object];
15
- })
16
- })
17
-
18
- return entry;
19
- }
20
-
21
- export const objectRemoveEmpty = (obj: object, nested: boolean = true): object => {
22
- Object.entries(obj)
23
- .map(([key, value]) => {
24
- if (nested && value instanceof Object) {
25
- value = objectRemoveEmpty(value);
26
- }
27
-
28
- return [key, value];
29
- })
30
- .filter(([, value]) => !(value instanceof Object ? Object.keys(value).length : value))
31
- .forEach(([key]) => {
32
- delete obj[key as keyof object];
33
- });
34
-
35
- return obj;
36
- }
@@ -1,24 +0,0 @@
1
- import {generatePath, UNSAFE_RouteContext} from "react-router-dom";
2
- import {RouteType} from "@src/type/RouteType.tsx";
3
- import {useContext} from "react";
4
-
5
- const crudToReactPathPattern = (path: string) => {
6
- return path.replaceAll(new RegExp('{(.*?)}', 'gi'), ':$1');
7
- }
8
-
9
-
10
- const generateRoute = (route?: RouteType, parameters?: {[key: string]: string} | null): string => {
11
- return route ? generatePath(crudToReactPathPattern(route.path), {...route.defaults || {}, ...parameters}) : '#';
12
- }
13
-
14
- const generateRoutePath = (path: string, parameters: {} | undefined = undefined): string => {
15
- return generatePath(crudToReactPathPattern(path), parameters);
16
- }
17
-
18
-
19
- const UseCurrentReactRoute = () => {
20
- const routeContext = useContext(UNSAFE_RouteContext);
21
- return routeContext.matches.pop();
22
- }
23
-
24
- export {generateRoutePath, generateRoute, crudToReactPathPattern, UseCurrentReactRoute};
@@ -1,25 +0,0 @@
1
- export const maskEmail = (email: string) => {
2
- const regexp = /(?<=.)[^@\n](?=[^@\n]*?@)|(?:(?<=@.)|(?!^)\G(?=[^@\n]*$)).(?=.*[^@\n]\.)/i;
3
- return email.replace(regexp, '*');
4
- }
5
-
6
- export const capitalize = (value: string): string => {
7
- return value.toLowerCase().replace(new RegExp('^.{1,1}'), (v) => v.toUpperCase());
8
- }
9
-
10
- export const titlize = (value: string): string => {
11
- let parts = value.replace(new RegExp('[-_]', 'gi'), ' ').split(new RegExp('(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])'));
12
- const firstWord = parts.shift();
13
- const lastWord = parts.pop();
14
- parts = parts.map((v) => v.toLowerCase());
15
-
16
- if(firstWord) {
17
- parts.unshift(capitalize(firstWord));
18
- }
19
-
20
- if(lastWord) {
21
- parts.push(capitalize(lastWord));
22
- }
23
-
24
- return parts.join(' ');
25
- }
package/src/index.tsx DELETED
@@ -1,23 +0,0 @@
1
- import React from 'react';
2
- import ReactDOM from 'react-dom/client';
3
- import Crud from './Crud.tsx';
4
- import {BrowserRouter} from "react-router-dom";
5
- import {Route, Routes} from "react-router";
6
- import Main from "@src/layout/default/Main.tsx";
7
-
8
- const root = ReactDOM.createRoot(
9
- document.getElementById('root') as HTMLElement
10
- );
11
- root.render(
12
- // <React.StrictMode>
13
- <BrowserRouter>
14
- <Routes>
15
- <Route element={<Main/>}>
16
- <Route path={"*"} element={<Crud/>}/>
17
- </Route>
18
- </Routes>
19
- </BrowserRouter>
20
- // </React.StrictMode>
21
- );
22
-
23
- // TODO: Add Google WebVitals to measure performance
@@ -1,15 +0,0 @@
1
- import React, {memo} from "react";
2
- import '@dakataa/crud-theme/scss/theme.scss';
3
-
4
- const Base = memo(({children}: {
5
- children?: any
6
- }) => {
7
-
8
- return (
9
- <>
10
- {children}
11
- </>
12
- );
13
- });
14
-
15
- export default Base;
@@ -1,27 +0,0 @@
1
- import React, {memo} from "react";
2
- import Base from "@src/layout/default/Base.tsx";
3
- import HttpException from "@src/component/error/HttpException.tsx";
4
-
5
- const Error = memo(({error}: {
6
- error?: any
7
- }) => {
8
-
9
- error ??= new HttpException(404, 'Page not found.');
10
-
11
- return (
12
- <Base>
13
- <main>
14
- <div className={"content d-flex flex-column"}>
15
- <h1 className={"display-1"}>{error.status || 'Error'}</h1>
16
- <p className={"text-secondary"}>{error.detail}</p>
17
- <br/>
18
- <div>
19
- <a className={"btn btn-primary"} href={"#"}>Back to home</a>
20
- </div>
21
- </div>
22
- </main>
23
- </Base>
24
- );
25
- });
26
-
27
- export default Error;
@@ -1,64 +0,0 @@
1
- import React, {memo, startTransition, useEffect, useRef, useState} from "react";
2
- import Navigation, {MenuItem, NavigationItemContextType} from "@src/layout/default/component/Navigation.tsx";
3
- import Dropdown from "@src/component/Dropdown";
4
- import Link from "@src/component/Link";
5
- import Requester from '@dakataa/requester';
6
- import {Outlet} from "react-router-dom";
7
- import Base from "@src/layout/default/Base.tsx";
8
-
9
- const Main = memo(({children}: {
10
- children?: any
11
- }) => {
12
- const mainMenuRef = useRef<NavigationItemContextType | null>(null);
13
- const [navigationItems, setNavigationItems] = useState<MenuItem[]>([]);
14
-
15
- useEffect(() => {
16
- (new Requester()).get('/_crud/navigation', {}).then((response) => {
17
- if (response.status !== 200) {
18
- return;
19
- }
20
-
21
- response.getData().then((data) => {
22
- setNavigationItems(data);
23
- });
24
- })
25
- }, []);
26
-
27
- return (
28
- <Base>
29
- <header>
30
- <div className={"wrap"}>
31
- <button onClick={(e) => mainMenuRef.current?.toggle()} className={"btn btn-mobile"}>
32
- <i></i>
33
- </button>
34
- <nav className="first-nav">
35
- <Link className="logo" to="/">Admin</Link>
36
- </nav>
37
- <nav className="second-nav">
38
- <Dropdown className={"user"}>
39
- <span className="initials">YL</span>
40
- <Link to={"#"}>
41
- Yordan Lazarov
42
- </Link>
43
- <Link to={"#"}>
44
- Logout
45
- </Link>
46
- </Dropdown>
47
- </nav>
48
- </div>
49
- </header>
50
- <main>
51
- {!!navigationItems.length && (
52
- <div className={"navigation d-print-none"}>
53
- <Navigation ref={mainMenuRef} items={navigationItems}/>
54
- </div>
55
- )}
56
- <div className={"content"}>
57
- <Outlet/>
58
- </div>
59
- </main>
60
- </Base>
61
- );
62
- });
63
-
64
- export default Main;