@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,97 +0,0 @@
1
- .modal-alert {
2
- --animation-transform: null;
3
- --animation-transition: null;
4
- --animation-keyframes: animation-open-default;
5
- --animation-keyframes-duration: .3s;
6
- --animation-timeout-progress: 1s;
7
- --modal-alert-vertical-gutter: 1.5rem;
8
- --modal-alert-icon-size: 92px;
9
-
10
- transition: var(--animation-transition);
11
- transform: var(--animation-transform);
12
-
13
- &.fade {
14
- animation: animation-open-fade;
15
- }
16
-
17
- &.scale,
18
- &.bounce,
19
- &.default {
20
- animation: var(--animation-keyframes) var(--animation-keyframes-duration) ease-in-out;
21
- }
22
-
23
-
24
- &.show {
25
- --animation-transform: none;
26
- }
27
-
28
- &.close {
29
- animation-direction: reverse;
30
- animation-duration: calc(var(--animation-keyframes-duration) / 2);
31
- }
32
-
33
- .btn-close {
34
- position: absolute;
35
- top: 1rem;
36
- right: 1rem;
37
- }
38
-
39
- .modal-alert-icon {
40
- width: var(--modal-alert-icon-size);
41
- height: var(--modal-alert-icon-size);
42
- margin-bottom: var(--modal-alert-vertical-gutter);
43
- }
44
-
45
- .modal-alert-title,
46
- .modal-alert-text {
47
- margin-bottom: var(--modal-alert-vertical-gutter);
48
- }
49
-
50
- .modal-alert-progress {
51
- background: var(--bs-primary);
52
- animation: animation-progress var(--animation-timeout-progress) linear;
53
- height: .25rem;
54
- position: absolute;
55
- bottom: 0;
56
- }
57
- }
58
-
59
- @keyframes animation-progress {
60
- 0% {
61
- width: 100%;
62
- }
63
-
64
- 100% {
65
- width: 0%;
66
- }
67
- }
68
-
69
-
70
- @keyframes animation-open-default {
71
- 0% {
72
- transform: scale(0.7);
73
- opacity: 0;
74
- }
75
-
76
- 45% {
77
- transform: scale(1.05);
78
- }
79
-
80
- 80% {
81
- transform: scale(.95);
82
- }
83
-
84
- 100% {
85
- transform: scale(1);
86
- opacity: 1;
87
- }
88
- }
89
-
90
- @keyframes animation-open-fade {
91
- 0% {
92
- opacity: 0;
93
- }
94
- 100% {
95
- opacity: 1;
96
- }
97
- }
@@ -1,50 +0,0 @@
1
- import {useEffect, useRef} from "react";
2
- import {default as LottiePlayer, AnimationConfigWithData, AnimationConfigWithPath, AnimationConfig} from "lottie-web";
3
-
4
- const Animation = ({
5
- animationData,
6
- path,
7
- options,
8
- width,
9
- height,
10
- className,
11
- ...props
12
- }: Omit<AnimationConfigWithPath, "container"> & Omit<AnimationConfigWithData, "container"> & {
13
- width?: number | `${number}%`;
14
- height?: number | `${number}%`;
15
- className?: string;
16
- options?: AnimationConfig;
17
-
18
- }) => {
19
- const elementRef = useRef<HTMLDivElement | null>(null);
20
-
21
- useEffect(() => {
22
- if (!elementRef.current) {
23
- return;
24
- }
25
-
26
- const animation = LottiePlayer.loadAnimation({
27
- renderer: 'svg',
28
- loop: false,
29
- autoplay: true,
30
- rendererSettings: {
31
- preserveAspectRatio: 'xMidYMid meet'
32
- },
33
- animationData: animationData,
34
- path: path,
35
- container: elementRef.current,
36
- ...(options || {})
37
- });
38
-
39
- return () => {
40
- animation.destroy();
41
- }
42
- }, []);
43
-
44
- return (
45
- <div className={className} ref={elementRef} style={{width: width, height: height}}>
46
- </div>
47
- )
48
- }
49
-
50
- export default Animation;
@@ -1,26 +0,0 @@
1
- import React from "react";
2
-
3
- export type Link = {
4
- icon?: any;
5
- rightIcon?: any,
6
- textClassName?: string,
7
- permission?: string | string[],
8
- rightIconProps?: any,
9
- children?: any,
10
- preload?: boolean;
11
- }
12
-
13
- const BaseButton = ({icon, rightIcon, rightIconProps, children, preload = false}: Link) => {
14
- return (
15
- <>
16
- {/*{preload ?*/}
17
- {/* <Icon {...iconProps} icon={['far', 'spinner']} spin={true} className={"icon " + (children && "me-2")}/> :*/}
18
- {/* (icon && <Icon {...iconProps} icon={icon} className={"icon " + (children && "me-2")}/>)*/}
19
- {/*}*/}
20
- {children && children}
21
- {/*{rightIcon && <Icon className={"icon-right ms-2"} icon={rightIcon} {...rightIconProps} />}*/}
22
- </>
23
- );
24
- }
25
-
26
- export default BaseButton;
@@ -1,15 +0,0 @@
1
- import React, {ForwardedRef, forwardRef} from "react";
2
- import BaseButton, {Link} from "./BaseButton";
3
-
4
- export default forwardRef(({
5
- children,
6
- preload,
7
- ...props
8
- }: Link & React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, ref:ForwardedRef<HTMLButtonElement>) => {
9
-
10
- return (
11
- <button {...{disabled: preload}} {...props} ref={ref}>
12
- <BaseButton preload={preload} {...props}>{children}</BaseButton>
13
- </button>
14
- );
15
- })
@@ -1,55 +0,0 @@
1
- import React, {PropsWithChildren, useEffect, useRef} from "react";
2
- import {Link as LinkType} from "./BaseButton";
3
- import Button from "./Button";
4
- import Link from "./Link";
5
- import {default as BootstrapDropdown} from "bootstrap/js/src/dropdown"
6
- import {LinkProps} from "react-router-dom";
7
- import {IconName, IconPrefix} from "@fortawesome/fontawesome-common-types";
8
-
9
- const DropdownButton = ({children, disabled, className}: PropsWithChildren<{className?: string, disabled?: boolean}>) => {
10
- return <>
11
- {children}
12
- </>
13
- };
14
-
15
- const DropdownContent = ({children, ...props}: { children: any }) => {
16
- return <div className={"dropdown-menu"}>
17
- {children}
18
- </div>
19
- }
20
-
21
- const Dropdown = ({items, className, children, icon}: PropsWithChildren<{
22
- className?: string,
23
- items?: (LinkProps & LinkType)[],
24
- icon?: [IconPrefix, IconName] | false
25
- }>) => {
26
- const ref = useRef<HTMLButtonElement>(null);
27
- useEffect(() => {
28
- const dropdown = new BootstrapDropdown(ref.current);
29
- return () => {
30
- dropdown.dispose();
31
- };
32
- }, []);
33
-
34
- const contentElement = React.Children.toArray(children).find(x => React.isValidElement(x) && x.type === DropdownContent);
35
- const linkElements = React.Children.toArray(children).filter(x => React.isValidElement(x) && x.type === Link);
36
- const buttonElement = React.Children.toArray(children).find(x => React.isValidElement(x) && x.type === DropdownButton);
37
- const buttonElements = React.Children.toArray(children).filter(x => !React.isValidElement(x) || (x.type !== Link && x.type !== DropdownContent && x.type !== DropdownButton));
38
- const buttonProps: any = React.isValidElement(buttonElement) ? buttonElement.props : {};
39
-
40
- return (
41
- <div className={[...(className || '').split(' '), 'dropdown'].filter((v, i, self) => self.indexOf(v) === i).join(' ')}>
42
- <Button ref={ref} data-bs-toggle={"dropdown"} {...buttonProps} className={[...(buttonProps.className || '').split(' '), 'btn', 'dropdown-toggle'].filter((v, i, self) => self.indexOf(v) === i).join(' ')}>
43
- {buttonProps.children ? buttonProps.children : buttonElements}
44
- </Button>
45
- {contentElement || (
46
- <DropdownContent>
47
- {linkElements}
48
- </DropdownContent>
49
- )}
50
- </div>
51
- );
52
- }
53
-
54
- export {DropdownContent, DropdownButton};
55
- export default Dropdown;
@@ -1,5 +0,0 @@
1
- export default () => {
2
- return <div>
3
- No View Found
4
- </div>
5
- }
@@ -1,11 +0,0 @@
1
- import React from "react";
2
- import {Link, LinkProps} from "react-router-dom";
3
- import BaseButton, {Link as LinkType} from "./BaseButton";
4
-
5
- export default ({to, children, ...props}: LinkProps & React.RefAttributes<HTMLAnchorElement> & LinkType) => {
6
- return (
7
- <Link to={to} {...props}>
8
- <BaseButton {...props}>{children && children}</BaseButton>
9
- </Link>
10
- );
11
- }
@@ -1,174 +0,0 @@
1
- import TemplateBlock from "@src/component/TemplateBlock.tsx";
2
- import React, {forwardRef, KeyboardEvent, ReactNode, useEffect, useImperativeHandle, useRef, useState} from "react";
3
- import {createPortal} from "react-dom";
4
-
5
- export type ModalType = {
6
- children?: ReactNode,
7
- open?: boolean,
8
- onClose?: () => void,
9
- backdrop?: boolean,
10
- animation?: Animation | string,
11
- keyboard?: boolean,
12
- size?: 'sm' | 'lg' | 'xl' | 'auto',
13
- className?: string,
14
- };
15
-
16
- export type ModalRefType = {
17
- toggle: () => void;
18
- open: () => void;
19
- close: () => Promise<void>;
20
- isOpen: () => boolean;
21
- };
22
-
23
- export enum Animation {
24
- fade = 'fade'
25
- }
26
-
27
- const Modal = forwardRef(({
28
- children,
29
- open = false,
30
- animation = Animation.fade,
31
- backdrop = true,
32
- keyboard = true,
33
- size,
34
- onClose,
35
- className,
36
- }: ModalType, ref) => {
37
- const [isOpen, setIsOpen] = useState<boolean>(open);
38
-
39
- useImperativeHandle(ref, () => ({
40
- toggle: () => setIsOpen(!isOpen),
41
- open: () => setIsOpen(true),
42
- close: () => startClosing(),
43
- isOpen: () => isOpen,
44
- }));
45
-
46
- useEffect(() => {
47
- setIsOpen(open);
48
- }, [open]);
49
-
50
- const closeOnKeyboard = (ev: any & KeyboardEvent<Window>): any => {
51
- if (!keyboard) {
52
- return;
53
- }
54
-
55
- switch (ev.key) {
56
- case 'Escape': {
57
- startClosing();
58
- break;
59
- }
60
- }
61
- };
62
-
63
- useEffect(() => {
64
- if (!isOpen) {
65
- return;
66
- }
67
-
68
- const onAnimationStart = () => {
69
- modalRef.current?.addEventListener('animationend', onAnimationEnd);
70
- };
71
-
72
- const onAnimationEnd = () => {
73
- modalRef.current?.classList.remove(animation);
74
- modalRef.current?.removeEventListener('animationstart', onAnimationStart)
75
- modalRef.current?.removeEventListener('animationend', onAnimationEnd);
76
- };
77
-
78
- setTimeout(() => {
79
- modalRef.current?.classList.add(...['d-block', 'show']);
80
- modalBackdropRef?.current?.classList.add('show');
81
- }, animation ? 100 : 0);
82
-
83
- document.addEventListener('keydown', closeOnKeyboard);
84
- modalRef.current?.addEventListener('animationstart', onAnimationStart);
85
-
86
- return () => {
87
- document.removeEventListener('keydown', closeOnKeyboard)
88
- modalRef.current?.removeEventListener('animationstart', onAnimationStart)
89
- modalRef.current?.removeEventListener('animationend', onAnimationEnd)
90
- }
91
- }, [isOpen]);
92
-
93
- const modalRef = useRef<HTMLDivElement | null>(null);
94
- const modalBackdropRef = useRef<HTMLDivElement | null>(null);
95
-
96
- const endClosing = () => {
97
- setIsOpen(false);
98
- onClose && onClose();
99
- }
100
- const startClosing = (): Promise<void> => {
101
- return new Promise((resolve: Function, reject: Function) => {
102
- if (!isOpen) {
103
- return resolve();
104
- }
105
-
106
- const closeAndResolve = () => {
107
- modalRef?.current?.classList.remove(...['show', 'd-block']);
108
- resolve();
109
- endClosing();
110
- };
111
-
112
-
113
- if (animation) {
114
- const closeTimeout = setTimeout(() => {
115
- closeAndResolve();
116
- }, animation ? 50 : 0);
117
-
118
- modalRef.current?.addEventListener('animationstart', () => {
119
- console.log('timeout');
120
- clearTimeout(closeTimeout);
121
- modalRef.current?.removeEventListener('animationend', closeAndResolve);
122
- modalRef.current?.addEventListener('animationend', closeAndResolve);
123
- });
124
-
125
- modalRef.current?.classList.add(...[animation, 'close']);
126
- } else {
127
- closeAndResolve();
128
- }
129
- })
130
-
131
- }
132
-
133
- return isOpen && createPortal((
134
- <>
135
- <div ref={modalRef}
136
- className={["modal", (size && "modal-" + size), animation && animation, className].filter(v => v).join(' ')}>
137
- <div className="modal-dialog modal-dialog-centered" role="document">
138
- <div className="modal-content">
139
- <TemplateBlock name={"header"} content={children} data={null}>
140
- <div className="modal-header">
141
- <h5 className="modal-title" id="exampleModalLabel">
142
- <TemplateBlock name={"title"} content={children} data={null}>
143
- Title
144
- </TemplateBlock>
145
- </h5>
146
- <button onClick={startClosing} type="button" className="btn-close" aria-label="Close"/>
147
- </div>
148
- </TemplateBlock>
149
- <div className="modal-body">
150
- <TemplateBlock name={"content"} content={children} data={null}>
151
- {children}
152
- </TemplateBlock>
153
- </div>
154
- <TemplateBlock name={"footer"} content={children} data={null}>
155
- <div className="modal-footer">
156
- <TemplateBlock name={"actions"} content={children} data={null}>
157
- <button onClick={startClosing} type="button" className="btn btn-secondary">
158
- Close
159
- </button>
160
- </TemplateBlock>
161
- </div>
162
- </TemplateBlock>
163
- </div>
164
- </div>
165
- </div>
166
- {backdrop && (
167
- <div ref={modalBackdropRef}
168
- className={["modal-backdrop", "fade", ...(animation && ['show'])].filter(v => v).join(' ')}></div>
169
- )}
170
- </>
171
- ), document.body);
172
- });
173
-
174
- export default Modal;
@@ -1,139 +0,0 @@
1
- import {Form, FormRef} from "@src/component/form/Form.tsx";
2
- import FormView from "@src/component/crud/FormView.tsx";
3
- import React, {forwardRef, ReactNode, useEffect, useImperativeHandle, useRef, useState} from "react";
4
- import {ModifyType} from "@src/type/ModifyType.tsx";
5
- import {generateRoute} from "@src/helper/RouterUtils.tsx";
6
- import {FormViewType} from "@src/type/FormViewType.tsx";
7
- import {useNavigate} from "react-router-dom";
8
- import Requester, {RequestBodyType} from "@dakataa/requester";
9
- import {ActionType} from "@src/type/ActionType.tsx";
10
- import TemplateBlock from "@src/component/TemplateBlock.tsx";
11
- import Button from "@src/component/Button.tsx";
12
- import {UseDataProvider} from "@src/component/hooks/GetData.tsx";
13
- import {FormFieldError} from "@src/component/form/FormFieldError.tsx";
14
- import {default as T} from "@src/component/Translation.tsx";
15
- import {ExceptionType} from "@src/type/ExceptionType.tsx";
16
-
17
- export type ModifyFormRefType = {
18
- getData: () => ModifyType | null;
19
- getFormRef: () => FormRef | null
20
- };
21
-
22
- const ModifyForm = forwardRef(({name, data: initData, action, parameters, onSuccess, onError, onLoad, children, embedded = false}: {
23
- name?: string,
24
- data?: ModifyType;
25
- action: ActionType;
26
- parameters?: { [key: string]: any };
27
- onSuccess?: (data: any) => void;
28
- onError?: (data: ExceptionType) => void;
29
- onLoad?: () => void;
30
- children?: ReactNode;
31
- embedded?: boolean;
32
- }, ref) => {
33
- const [preload, setPreloader] = useState(false);
34
- const navigate = useNavigate();
35
- const actionURL = generateRoute(action.route, (parameters || {}));
36
- const formRef = useRef<FormRef | null>(null);
37
- const dataProvider = UseDataProvider();
38
- const [data, setData] = useState<ModifyType | undefined>();
39
-
40
- useImperativeHandle(ref, () => ({
41
- getData: (): ModifyType | undefined => data,
42
- getFormRef: (): FormRef | null => formRef.current
43
- }));
44
-
45
- const getFormErrors = (view: FormViewType): { [key: string]: any } => {
46
- let result: { [key: string]: any } = {
47
- ...(view.errors?.length ? {[view.full_name]: view.errors} : {})
48
- }
49
-
50
- for (let [, child] of Object.entries(view?.children || [])) {
51
- if (child.children && Object.values(child.children).length) {
52
- result = {...result, ...getFormErrors(child)};
53
- } else if (child.errors?.length) {
54
- result[child.full_name] = child.errors;
55
- }
56
- }
57
-
58
- return result;
59
- };
60
-
61
- const onSubmit = (formData: FormData) => {
62
- setPreloader(true);
63
-
64
- (new Requester()).post(actionURL, formData, RequestBodyType.FormData).then(response => {
65
- return response.getData().then((data) => {
66
- if (![200, 201, 400].includes(response.status)) {
67
- return Promise.reject(data);
68
- }
69
-
70
- return data;
71
- })
72
-
73
- }).then(data => {
74
- setData(data);
75
-
76
- const errors = getFormErrors(data.form.modify.view);
77
- if (Object.entries(errors).length) {
78
- formRef.current?.setErrors(errors);
79
- return;
80
- }
81
-
82
- if (onSuccess) {
83
- onSuccess(data);
84
- }
85
-
86
- if (data.redirect && !embedded) {
87
- navigate(generateRoute(data.redirect.route, {...(parameters || {}), ...data.redirect.parameters}));
88
- }
89
- }).catch((error: ExceptionType) => {
90
- if (onError) {
91
- onError(error);
92
- }
93
- }).finally(() => {
94
- setPreloader(false);
95
- });
96
- }
97
-
98
- useEffect(() => {
99
- if (onLoad) {
100
- onLoad();
101
- }
102
- }, []);
103
-
104
- initData = (dataProvider?.results as ModifyType) ?? initData;
105
- useEffect(() => {
106
- setData(initData);
107
- }, [JSON.stringify(initData)])
108
-
109
- return data && (
110
- <>
111
- {Object.keys(data?.messages || {}).map((messageType, index) => (
112
- <div key={"alert-" + messageType} className={['alert', 'alert-' + messageType].join(' ')}>
113
- {(data?.messages[messageType] || ['Item was saved successful.']).join(' ')}
114
- </div>
115
- ))}
116
-
117
- <Form id={data?.form?.modify?.view?.id} ref={formRef} action={actionURL} method={"POST"} onSubmit={onSubmit}>
118
- {
119
- data?.form?.modify?.view !== undefined && (
120
- <>
121
- <FormView
122
- name={name}
123
- namespace={action.namespace}
124
- key={data.form.modify.view.id}
125
- view={data.form.modify.view}
126
- />
127
- <FormFieldError name={data.form.modify.view.full_name} className={"alert alert-danger"}/>
128
- </>
129
- )
130
- }
131
- <TemplateBlock name={"actions"} content={children} data={{formRef}}>
132
- <Button type={"submit"} className={"btn btn-primary"}><T>Save</T></Button>
133
- </TemplateBlock>
134
- </Form>
135
- </>
136
- )
137
- });
138
-
139
- export default ModifyForm;
@@ -1,21 +0,0 @@
1
- import React, {memo} from "react";
2
- import TemplateExtend from "@src/component/TemplateExtend.tsx";
3
-
4
- const TemplateBlock = memo(({name, content, children, data}: {
5
- name: string,
6
- content: any,
7
- children?: any,
8
- data: any
9
- }) => {
10
- const templateElement = React.Children.toArray(content).find(x => React.isValidElement(x) && x.type === TemplateExtend && x.props.name === name);
11
- let contentElement = null;
12
- if (templateElement && React.isValidElement(templateElement)) {
13
- contentElement = React.cloneElement(templateElement as any, {parent: children, data: data});
14
- }
15
-
16
- const restChildren = React.Children.toArray(children).filter(e => React.isValidElement(e) && e.type !== TemplateExtend);
17
-
18
- return <>{contentElement || (restChildren.length ? restChildren : children)}</>
19
- })
20
-
21
- export default TemplateBlock;
@@ -1,17 +0,0 @@
1
- import React, {memo} from "react";
2
- import TemplateParentBlock from "@src/component/TemplateParentBlock.tsx";
3
- import TemplateBlock from "@src/component/TemplateBlock.tsx";
4
-
5
- const TemplateExtend = memo(({name, children, data, parent, render}: { name: string, children?: any, parent?: any, data?: any, render?: (...args: any) => void }) => {
6
- children = React.Children.toArray((render ? render(data, parent) : children) || []).map(x => {
7
- if(React.isValidElement(x) && x.type === TemplateParentBlock) {
8
- x = React.cloneElement(x as any, { children: parent }) ;
9
- }
10
-
11
- return x;
12
- });
13
-
14
- return <>{children}</>
15
- })
16
-
17
- export default TemplateExtend;
@@ -1,7 +0,0 @@
1
- import React, {ReactNode} from "react";
2
-
3
- const TemplateParentBlock = ({children}: { children?: ReactNode | undefined }) => {
4
- return <>{children}</>
5
- };
6
-
7
- export default TemplateParentBlock;
@@ -1,7 +0,0 @@
1
- import {memo} from "react";
2
-
3
- const Translation = memo(({children}: {children?: string}) => {
4
- return <>{children}</>
5
- })
6
-
7
- export default Translation;
@@ -1,33 +0,0 @@
1
- import Modify from "@src/page/Modify";
2
- import EmptyView from "@src/component/EmptyView";
3
- import List from "@src/page/List";
4
- import React from "react";
5
- import DynamicView from "@src/component/crud/DynamicView.tsx";
6
- import HttpException from "@src/component/error/HttpException.tsx";
7
-
8
- const DefaultViewComponent = ({view, props}: {
9
- view: string,
10
- props?: { [key: string]: any }
11
- }) => {
12
- const defaultComponents: { [key: string]: any } = {
13
- add: Modify,
14
- edit: Modify,
15
- list: List
16
- }
17
-
18
- if(defaultComponents[view] === undefined)
19
- throw new HttpException(500, 'View not found');
20
-
21
- return React.createElement(defaultComponents[view] || EmptyView, props);
22
- }
23
-
24
- const ViewLoader = ({view, namespace, props}: { view: string; namespace: string; props?: { [key: string]: any } }): any => {
25
-
26
- return (
27
- <DynamicView namespace={namespace} view={view} key={namespace + view} props={props}>
28
- <DefaultViewComponent view={view} props={props}/>
29
- </DynamicView>
30
- );
31
- }
32
-
33
- export {ViewLoader as default, DefaultViewComponent};