dynamic-modal 1.1.8 → 1.1.10
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 +0 -1
- package/dist/components/input-upload/input-upload.js +3 -3
- package/dist/components/make-button/make-button.js +19 -10
- package/dist/components/make-description/make-description.js +2 -2
- package/dist/components/make-input/make-input.js +57 -29
- package/dist/components/make-select/make-select.js +66 -29
- package/dist/components/make-textarea/make-textarea.js +57 -29
- package/dist/components/make-toggle/make-toggle.js +57 -29
- package/dist/components/make-upload/make-upload.js +72 -18
- package/dist/components/portal/portal.js +20 -10
- package/dist/context/component/component-state.d.ts +3 -3
- package/dist/context/component/component-state.js +20 -11
- package/dist/hooks/use-enable-if.d.ts +9 -0
- package/dist/hooks/use-enable-if.js +45 -0
- package/dist/hooks/use-live-data.d.ts +14 -0
- package/dist/hooks/use-live-data.js +42 -0
- package/dist/hooks/use-render-if.d.ts +12 -0
- package/dist/hooks/use-render-if.js +51 -0
- package/dist/interfaces/component-state.d.ts +8 -8
- package/dist/interfaces/modal.d.ts +4 -2
- package/dist/modal.js +70 -58
- package/dist/util/general/general.util.d.ts +3 -0
- package/dist/util/general/general.util.js +28 -0
- package/eslint.config.mjs +72 -14
- package/examples/live-data.ts +0 -1
- package/package.json +11 -9
- package/src/components/input-upload/input-upload.tsx +40 -28
- package/src/components/make-button/make-button.tsx +11 -13
- package/src/components/make-description/make-description.tsx +14 -8
- package/src/components/make-input/make-input.tsx +94 -47
- package/src/components/make-select/make-select.tsx +118 -48
- package/src/components/make-textarea/make-textarea.tsx +94 -47
- package/src/components/make-toggle/make-toggle.tsx +94 -47
- package/src/components/make-upload/make-upload.tsx +88 -36
- package/src/components/portal/portal.tsx +27 -25
- package/src/context/component/component-state.tsx +16 -9
- package/src/hooks/modal-handler.ts +17 -14
- package/src/hooks/use-enable-if.ts +64 -0
- package/src/hooks/use-live-data.ts +45 -0
- package/src/hooks/use-render-if.ts +59 -0
- package/src/interfaces/component-state.ts +38 -23
- package/src/interfaces/field.ts +33 -27
- package/src/interfaces/input-upload.ts +17 -15
- package/src/interfaces/make-button.ts +14 -13
- package/src/interfaces/make-description.ts +9 -8
- package/src/interfaces/make-field-group.ts +9 -8
- package/src/interfaces/make-input.ts +9 -8
- package/src/interfaces/make-select.ts +9 -9
- package/src/interfaces/make-textarea.ts +5 -5
- package/src/interfaces/make-toggle.ts +3 -3
- package/src/interfaces/make-upload.ts +8 -8
- package/src/interfaces/modal.ts +57 -39
- package/src/interfaces/option.ts +3 -3
- package/src/interfaces/portal.ts +5 -5
- package/src/modal.tsx +243 -147
- package/src/util/general/general.util.ts +27 -0
- package/tsconfig.json +1 -1
- package/dist/hooks/field-render.d.ts +0 -20
- package/dist/hooks/field-render.js +0 -94
- package/dist/tools/general.d.ts +0 -1
- package/dist/tools/general.js +0 -11
- package/src/hooks/field-render.ts +0 -120
- package/src/tools/general.ts +0 -8
|
@@ -16,13 +16,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
16
16
|
}) : function(o, v) {
|
|
17
17
|
o["default"] = v;
|
|
18
18
|
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
26
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
37
|
exports.Portal = void 0;
|
|
28
38
|
const react_1 = __importStar(require("react"));
|
|
@@ -48,8 +58,8 @@ const Portal = (props) => {
|
|
|
48
58
|
setMounted(true);
|
|
49
59
|
}
|
|
50
60
|
}, [mounted, props.closeTime, props.portalOpen, props.portalTag]);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
61
|
+
if (!mounted && !ref.current)
|
|
62
|
+
return null;
|
|
63
|
+
return (0, react_dom_1.createPortal)(react_1.default.createElement("div", { className: "transition-all delay-100 fixed top-0 left-0 w-full h-full grid place-items-center bg-black bg-opacity-40 z-20" }, props.children), ref.current);
|
|
54
64
|
};
|
|
55
65
|
exports.Portal = Portal;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { IComponentState, IComponentStateProps } from
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IComponentState, IComponentStateProps } from '../../interfaces/component-state';
|
|
3
3
|
export declare const ComponentStateContext: React.Context<IComponentState>;
|
|
4
|
-
export declare const ComponentState: ({ children, components }: IComponentStateProps) => React.JSX.Element;
|
|
4
|
+
export declare const ComponentState: ({ children, components, }: IComponentStateProps) => React.JSX.Element;
|
|
@@ -16,20 +16,29 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
16
16
|
}) : function(o, v) {
|
|
17
17
|
o["default"] = v;
|
|
18
18
|
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
26
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
37
|
exports.ComponentState = exports.ComponentStateContext = void 0;
|
|
28
38
|
const react_1 = __importStar(require("react"));
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
const value = (0, react_1.useMemo)(() => components, []);
|
|
39
|
+
exports.ComponentStateContext = (0, react_1.createContext)({});
|
|
40
|
+
const ComponentState = ({ children, components, }) => {
|
|
41
|
+
const value = (0, react_1.useMemo)(() => components, [components]);
|
|
33
42
|
return (react_1.default.createElement(exports.ComponentStateContext.Provider, { value: value }, children));
|
|
34
43
|
};
|
|
35
44
|
exports.ComponentState = ComponentState;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IModalRenderCondition } from '../interfaces/modal';
|
|
2
|
+
export interface IRenderIfProps {
|
|
3
|
+
elementEnableIf?: IModalRenderCondition;
|
|
4
|
+
}
|
|
5
|
+
declare const useEnableIf: ({ elementEnableIf }: IRenderIfProps) => {
|
|
6
|
+
enable: boolean;
|
|
7
|
+
checkEnable: (formData: Record<string, unknown>, { name }: Record<"name", string> & Record<"type", string | undefined>) => Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
export default useEnableIf;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const react_1 = require("react");
|
|
13
|
+
const general_util_1 = require("../util/general/general.util");
|
|
14
|
+
const useEnableIf = ({ elementEnableIf }) => {
|
|
15
|
+
const [enable, setEnable] = (0, react_1.useState)(() => {
|
|
16
|
+
return elementEnableIf === undefined;
|
|
17
|
+
});
|
|
18
|
+
const checkEnable = (formData_1, _a) => __awaiter(void 0, [formData_1, _a], void 0, function* (formData, { name }) {
|
|
19
|
+
const targetFieldData = formData[name];
|
|
20
|
+
if (targetFieldData === undefined ||
|
|
21
|
+
targetFieldData === '' ||
|
|
22
|
+
targetFieldData === null)
|
|
23
|
+
return;
|
|
24
|
+
const enableIfConfig = elementEnableIf;
|
|
25
|
+
const isLiveEnable = !!(enableIfConfig === null || enableIfConfig === void 0 ? void 0 : enableIfConfig.action) && !!enableIfConfig.condition;
|
|
26
|
+
if (isLiveEnable && enableIfConfig.condition.includes(name)) {
|
|
27
|
+
const enableStatus = yield (0, general_util_1.liveDataHandler)(targetFieldData, formData, enableIfConfig.action);
|
|
28
|
+
if (enable !== enableStatus)
|
|
29
|
+
setEnable(enableStatus);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
const enableConditionList = Object.keys(elementEnableIf);
|
|
33
|
+
if (enableConditionList.includes(name)) {
|
|
34
|
+
const enableStatus = enableIfConfig[name].includes(targetFieldData) || enableIfConfig[name].includes('*');
|
|
35
|
+
if (enable !== enableStatus)
|
|
36
|
+
setEnable(enableStatus);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return {
|
|
41
|
+
enable,
|
|
42
|
+
checkEnable,
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
exports.default = useEnableIf;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FieldValues, UseFormSetValue } from 'react-hook-form';
|
|
2
|
+
import { IModalLiveDataCondition } from '../interfaces/modal';
|
|
3
|
+
import { IOption } from '../interfaces/option';
|
|
4
|
+
export interface ILiveDataProps {
|
|
5
|
+
elementName: string;
|
|
6
|
+
elementLiveData?: IModalLiveDataCondition;
|
|
7
|
+
setValue: UseFormSetValue<FieldValues>;
|
|
8
|
+
}
|
|
9
|
+
declare const useLiveData: ({ elementName, elementLiveData, setValue, }: ILiveDataProps) => {
|
|
10
|
+
liveSearching: boolean;
|
|
11
|
+
liveData: IOption[] | undefined;
|
|
12
|
+
checkLiveData: (formData: Record<string, unknown>, { name }: Record<"name", string> & Record<"type", string | undefined>) => Promise<void>;
|
|
13
|
+
};
|
|
14
|
+
export default useLiveData;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const react_1 = require("react");
|
|
13
|
+
const general_util_1 = require("../util/general/general.util");
|
|
14
|
+
const useLiveData = ({ elementName, elementLiveData, setValue, }) => {
|
|
15
|
+
const [liveSearching, setLiveSearching] = (0, react_1.useState)(false);
|
|
16
|
+
const [liveData, setLiveData] = (0, react_1.useState)(undefined);
|
|
17
|
+
const checkLiveData = (formData_1, _a) => __awaiter(void 0, [formData_1, _a], void 0, function* (formData, { name }) {
|
|
18
|
+
var _b;
|
|
19
|
+
const targetFieldData = formData[name];
|
|
20
|
+
if (targetFieldData === undefined ||
|
|
21
|
+
targetFieldData === '' ||
|
|
22
|
+
targetFieldData === null)
|
|
23
|
+
return;
|
|
24
|
+
const liveDataConfig = elementLiveData;
|
|
25
|
+
const isLiveData = !!(liveDataConfig === null || liveDataConfig === void 0 ? void 0 : liveDataConfig.action) && !!liveDataConfig.condition;
|
|
26
|
+
if (!isLiveData)
|
|
27
|
+
return;
|
|
28
|
+
if (liveDataConfig.condition.includes(name)) {
|
|
29
|
+
setLiveSearching(true);
|
|
30
|
+
const options = (_b = (yield (0, general_util_1.liveDataAction)(targetFieldData, formData, liveDataConfig.action))) !== null && _b !== void 0 ? _b : [];
|
|
31
|
+
setValue(elementName, options);
|
|
32
|
+
setLiveData(options);
|
|
33
|
+
setLiveSearching(false);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return {
|
|
37
|
+
liveSearching,
|
|
38
|
+
liveData,
|
|
39
|
+
checkLiveData,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
exports.default = useLiveData;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IModalRenderCondition } from '../interfaces/modal';
|
|
2
|
+
import { FieldValues, UseFormUnregister } from 'react-hook-form';
|
|
3
|
+
export interface IRenderIfProps {
|
|
4
|
+
elementName: string;
|
|
5
|
+
elementRenderIf?: IModalRenderCondition;
|
|
6
|
+
unregister: UseFormUnregister<FieldValues>;
|
|
7
|
+
}
|
|
8
|
+
declare const useRenderIf: ({ elementName, elementRenderIf, unregister, }: IRenderIfProps) => {
|
|
9
|
+
render: boolean;
|
|
10
|
+
checkRender: (formData: Record<string, unknown>, { name }: Record<"name", string> & Record<"type", string | undefined>) => Promise<void>;
|
|
11
|
+
};
|
|
12
|
+
export default useRenderIf;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const react_1 = require("react");
|
|
13
|
+
const general_util_1 = require("../util/general/general.util");
|
|
14
|
+
const useRenderIf = ({ elementName, elementRenderIf, unregister, }) => {
|
|
15
|
+
const [render, setRender] = (0, react_1.useState)(() => {
|
|
16
|
+
return elementRenderIf === undefined;
|
|
17
|
+
});
|
|
18
|
+
const checkRender = (formData_1, _a) => __awaiter(void 0, [formData_1, _a], void 0, function* (formData, { name }) {
|
|
19
|
+
const targetFieldData = formData[name];
|
|
20
|
+
if (targetFieldData === undefined ||
|
|
21
|
+
targetFieldData === '' ||
|
|
22
|
+
targetFieldData === null)
|
|
23
|
+
return;
|
|
24
|
+
const renderIfConfig = elementRenderIf;
|
|
25
|
+
const isLiveRender = !!(renderIfConfig === null || renderIfConfig === void 0 ? void 0 : renderIfConfig.action) && !!(renderIfConfig === null || renderIfConfig === void 0 ? void 0 : renderIfConfig.condition);
|
|
26
|
+
if (isLiveRender && renderIfConfig.condition.includes(name)) {
|
|
27
|
+
const renderStatus = yield (0, general_util_1.liveDataHandler)(targetFieldData, formData, renderIfConfig.action);
|
|
28
|
+
if (render !== renderStatus) {
|
|
29
|
+
if (render && !renderStatus)
|
|
30
|
+
unregister(elementName);
|
|
31
|
+
setRender(renderStatus);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const renderConditionList = Object.keys(elementRenderIf);
|
|
36
|
+
if (renderConditionList.includes(name)) {
|
|
37
|
+
const renderStatus = renderIfConfig[name].includes(targetFieldData) || renderIfConfig[name].includes('*');
|
|
38
|
+
if (render !== renderStatus) {
|
|
39
|
+
if (render && !renderStatus)
|
|
40
|
+
unregister(elementName);
|
|
41
|
+
setRender(renderStatus);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
return {
|
|
47
|
+
render,
|
|
48
|
+
checkRender,
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
exports.default = useRenderIf;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { FC, PropsWithChildren } from
|
|
2
|
-
import { FieldError } from
|
|
3
|
-
import { IOption } from
|
|
4
|
-
import { IMakeInput } from
|
|
5
|
-
import { IMakeButton } from
|
|
6
|
-
import { IMakeSelect } from
|
|
7
|
-
import { IMakeTextarea } from
|
|
8
|
-
import { IMakeToggle } from
|
|
1
|
+
import { FC, PropsWithChildren } from 'react';
|
|
2
|
+
import { FieldError } from 'react-hook-form';
|
|
3
|
+
import { IOption } from './option';
|
|
4
|
+
import { IMakeInput } from './make-input';
|
|
5
|
+
import { IMakeButton } from './make-button';
|
|
6
|
+
import { IMakeSelect } from './make-select';
|
|
7
|
+
import { IMakeTextarea } from './make-textarea';
|
|
8
|
+
import { IMakeToggle } from './make-toggle';
|
|
9
9
|
export interface IComponentAditionalProps {
|
|
10
10
|
onChange: (...event: any[]) => void;
|
|
11
11
|
value: any;
|
|
@@ -10,10 +10,12 @@ import { IOption } from './option';
|
|
|
10
10
|
import { IMakeButton } from './make-button';
|
|
11
11
|
export type IModalField = IMakeSelect | IMakeInput | IMakeFieldGroup | IMakeTextarea | IMakeToggle | IMakeDescription | IMakeUpload | IMakeButton;
|
|
12
12
|
export type IFormField = IMakeSelect | IMakeInput | IMakeTextarea | IMakeToggle;
|
|
13
|
-
export
|
|
13
|
+
export interface IModalRenderAction {
|
|
14
14
|
action: (data: string, ...args: any[]) => Promise<boolean>;
|
|
15
15
|
condition: Array<string>;
|
|
16
|
-
}
|
|
16
|
+
}
|
|
17
|
+
export type IModalRenderCriteria = Record<string, Array<string | number | boolean> | undefined>;
|
|
18
|
+
export type IModalRenderCondition = IModalRenderAction | IModalRenderCriteria;
|
|
17
19
|
export type IModalLiveDataCondition = {
|
|
18
20
|
action: (data: string, ...args: any[]) => Promise<Array<IOption>>;
|
|
19
21
|
condition: Array<string>;
|
package/dist/modal.js
CHANGED
|
@@ -16,13 +16,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
16
16
|
}) : function(o, v) {
|
|
17
17
|
o["default"] = v;
|
|
18
18
|
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
26
36
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
27
37
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
28
38
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -63,7 +73,7 @@ const Modal = ({ open, close, config }) => {
|
|
|
63
73
|
const { ModalButtonAction, ModalButtonCancel } = (0, react_1.useContext)(component_state_1.ComponentStateContext);
|
|
64
74
|
const [modalReady, setModalReady] = (0, react_1.useState)(undefined);
|
|
65
75
|
const [defaultLoaded, setDefaultLoaded] = (0, react_1.useState)(false);
|
|
66
|
-
const { control, handleSubmit, getValues, unregister, setValue, watch, trigger, getFieldState } = (0, react_hook_form_1.useForm)();
|
|
76
|
+
const { control, handleSubmit, getValues, unregister, setValue, watch, trigger, getFieldState, } = (0, react_hook_form_1.useForm)();
|
|
67
77
|
const formValueHandler = (element) => {
|
|
68
78
|
var _a;
|
|
69
79
|
if (['group', 'upload', 'text'].includes(element.elementType))
|
|
@@ -73,18 +83,22 @@ const Modal = ({ open, close, config }) => {
|
|
|
73
83
|
return;
|
|
74
84
|
}
|
|
75
85
|
const defaultValue = (_a = element.defaultValue) !== null && _a !== void 0 ? _a : '';
|
|
76
|
-
const parsedValue = defaultValue === 'true'
|
|
86
|
+
const parsedValue = defaultValue === 'true'
|
|
87
|
+
? true
|
|
88
|
+
: defaultValue === 'false'
|
|
89
|
+
? false
|
|
90
|
+
: defaultValue;
|
|
77
91
|
setValue(element.name, parsedValue !== null && parsedValue !== void 0 ? parsedValue : '');
|
|
78
92
|
};
|
|
79
93
|
const autoLoadGroup = (groupFields) => {
|
|
80
|
-
groupFields.forEach(element => {
|
|
94
|
+
groupFields.forEach((element) => {
|
|
81
95
|
formValueHandler(element);
|
|
82
96
|
});
|
|
83
97
|
};
|
|
84
98
|
const autoLoadField = (modalFields) => {
|
|
85
99
|
if (defaultLoaded)
|
|
86
100
|
return;
|
|
87
|
-
modalFields.forEach(element => {
|
|
101
|
+
modalFields.forEach((element) => {
|
|
88
102
|
if (element.elementType === 'group') {
|
|
89
103
|
autoLoadGroup(element.groups);
|
|
90
104
|
return;
|
|
@@ -94,7 +108,11 @@ const Modal = ({ open, close, config }) => {
|
|
|
94
108
|
setDefaultLoaded(true);
|
|
95
109
|
};
|
|
96
110
|
const getUseSubmit = (modalConfig) => {
|
|
97
|
-
const useSubmit = modalConfig.useSubmit === undefined
|
|
111
|
+
const useSubmit = modalConfig.useSubmit === undefined
|
|
112
|
+
? true
|
|
113
|
+
: modalConfig.useSubmit === false
|
|
114
|
+
? false
|
|
115
|
+
: true;
|
|
98
116
|
return useSubmit;
|
|
99
117
|
};
|
|
100
118
|
const getRender = (_a, index, isEndOfRender) => {
|
|
@@ -106,23 +124,9 @@ const Modal = ({ open, close, config }) => {
|
|
|
106
124
|
control,
|
|
107
125
|
watch,
|
|
108
126
|
setValue,
|
|
109
|
-
unregister
|
|
127
|
+
unregister,
|
|
110
128
|
};
|
|
111
|
-
return elementType === 'input'
|
|
112
|
-
? react_1.default.createElement(make_input_1.default, Object.assign({}, props, { key: `modal-input-${index}`, element: element }))
|
|
113
|
-
: elementType === 'select'
|
|
114
|
-
? react_1.default.createElement(make_select_1.default, Object.assign({}, props, { key: `modal-select-${index}`, element: element }))
|
|
115
|
-
: elementType === 'textarea'
|
|
116
|
-
? react_1.default.createElement(make_textarea_1.default, Object.assign({}, props, { key: `modal-textarea-${index}`, element: element }))
|
|
117
|
-
: elementType === 'toggle'
|
|
118
|
-
? react_1.default.createElement(make_toggle_1.default, Object.assign({}, props, { key: `modal-toggle-${index}`, element: element }))
|
|
119
|
-
: elementType === 'text'
|
|
120
|
-
? react_1.default.createElement(make_description_1.default, Object.assign({}, props, { key: `modal-text-${index}`, element: element }))
|
|
121
|
-
: elementType === 'upload'
|
|
122
|
-
? react_1.default.createElement(make_upload_1.default, Object.assign({}, props, { key: `modal-upload-${index}`, element: element }))
|
|
123
|
-
: elementType === 'button'
|
|
124
|
-
? react_1.default.createElement(make_button_1.default, Object.assign({}, props, { key: `modal-button-${index}`, element: element }))
|
|
125
|
-
: null;
|
|
129
|
+
return elementType === 'input' ? (react_1.default.createElement(make_input_1.default, Object.assign({}, props, { key: `modal-input-${index}`, element: element }))) : elementType === 'select' ? (react_1.default.createElement(make_select_1.default, Object.assign({}, props, { key: `modal-select-${index}`, element: element }))) : elementType === 'textarea' ? (react_1.default.createElement(make_textarea_1.default, Object.assign({}, props, { key: `modal-textarea-${index}`, element: element }))) : elementType === 'toggle' ? (react_1.default.createElement(make_toggle_1.default, Object.assign({}, props, { key: `modal-toggle-${index}`, element: element }))) : elementType === 'text' ? (react_1.default.createElement(make_description_1.default, Object.assign({}, props, { key: `modal-text-${index}`, element: element }))) : elementType === 'upload' ? (react_1.default.createElement(make_upload_1.default, Object.assign({}, props, { key: `modal-upload-${index}`, element: element }))) : elementType === 'button' ? (react_1.default.createElement(make_button_1.default, Object.assign({}, props, { key: `modal-button-${index}`, element: element }))) : null;
|
|
126
130
|
};
|
|
127
131
|
const closeHandler = () => {
|
|
128
132
|
if (modalReady === null || modalReady === void 0 ? void 0 : modalReady.onClose)
|
|
@@ -140,11 +144,13 @@ const Modal = ({ open, close, config }) => {
|
|
|
140
144
|
const form = getValues();
|
|
141
145
|
const fields = Object.keys(form);
|
|
142
146
|
yield trigger(fields);
|
|
143
|
-
const validations = fields.map(field => {
|
|
147
|
+
const validations = fields.map((field) => {
|
|
144
148
|
const { invalid } = getFieldState(field);
|
|
145
149
|
return invalid;
|
|
146
150
|
});
|
|
147
|
-
const result = validations.some(isInvalid => isInvalid)
|
|
151
|
+
const result = validations.some((isInvalid) => isInvalid)
|
|
152
|
+
? undefined
|
|
153
|
+
: form;
|
|
148
154
|
if (!result)
|
|
149
155
|
return;
|
|
150
156
|
actionHandler(Object.assign(Object.assign({}, ((_a = modalReady === null || modalReady === void 0 ? void 0 : modalReady.reservedData) !== null && _a !== void 0 ? _a : {})), form));
|
|
@@ -158,34 +164,40 @@ const Modal = ({ open, close, config }) => {
|
|
|
158
164
|
if (open && !modalReady)
|
|
159
165
|
setModalReady(config);
|
|
160
166
|
}, [config, modalReady, open]);
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
167
|
+
if (!modalReady)
|
|
168
|
+
return null;
|
|
169
|
+
return (react_1.default.createElement(portal_1.Portal, { closeTime: 200, portalOpen: open, portalTag: '#modal-portal' },
|
|
170
|
+
react_1.default.createElement("div", { className: "rounded bg-white relative w-auto h-auto min-h-[200px] min-w-[500px]", style: modalReady.style },
|
|
171
|
+
react_1.default.createElement("form", { className: "flex flex-col p-4 gap-4", autoComplete: "off", onSubmit: handleSubmit(actionHandler) },
|
|
172
|
+
react_1.default.createElement("h2", { className: "text-bold text-center border-b pb-4 font-semibold" }, modalReady.title),
|
|
173
|
+
react_1.default.createElement("div", { className: "flex flex-col gap-4 py-4", style: {
|
|
174
|
+
overflowY: modalReady.overFlowBody ? 'auto' : undefined,
|
|
175
|
+
height: modalReady.overFlowBody,
|
|
176
|
+
minHeight: modalReady.minHeightBody,
|
|
177
|
+
} }, modalReady.fields.map((element, index) => {
|
|
178
|
+
const isEndOfRender = index + 1 === modalReady.fields.length;
|
|
179
|
+
if (element.elementType === 'group') {
|
|
180
|
+
return (react_1.default.createElement("div", { key: `modal-group-${index}`, className: "flex flex-col w-full gap-2" },
|
|
181
|
+
element.title && (react_1.default.createElement("h3", { className: "font-bold border-b-2 pb-2 mb-2" }, element.title)),
|
|
182
|
+
react_1.default.createElement("div", { key: `modal-group-${index}`, className: "flex gap-4 w-full", style: element.style }, element.groups
|
|
183
|
+
.filter((sub) => [
|
|
184
|
+
'input',
|
|
185
|
+
'select',
|
|
186
|
+
'toggle',
|
|
187
|
+
'multiselect',
|
|
188
|
+
'upload',
|
|
189
|
+
'button',
|
|
190
|
+
'autocomplete',
|
|
191
|
+
].includes(sub.elementType))
|
|
192
|
+
.map((sub, subIndex) => getRender(sub, index + subIndex, isEndOfRender)))));
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
return getRender(element, index, isEndOfRender);
|
|
196
|
+
}
|
|
197
|
+
})),
|
|
198
|
+
react_1.default.createElement("div", { className: "flex gap-4 items-center justify-center border-t p-2", style: modalReady === null || modalReady === void 0 ? void 0 : modalReady.actions.containerStyle },
|
|
199
|
+
modalReady.actions.cancel && (react_1.default.createElement(ModalButtonCancel, Object.assign({}, modalReady.actions.cancel, { onClick: closeHandler }))),
|
|
200
|
+
getUseSubmit(modalReady) ? (react_1.default.createElement(ModalButtonAction, Object.assign({}, modalReady.actions.action, { type: "submit" }))) : (react_1.default.createElement(ModalButtonAction, Object.assign({}, modalReady.actions.action, { onClick: manualSubmit, type: "button" }))))))));
|
|
189
201
|
};
|
|
190
202
|
exports.Modal = Modal;
|
|
191
203
|
exports.default = exports.Modal;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { IOption } from '../../interfaces/option';
|
|
2
|
+
export declare const liveDataAction: (fieldData: string | number | Array<unknown>, formData: Record<string, unknown>, action: (data: string, ...args: any[]) => Promise<IOption[]>) => Promise<IOption[]>;
|
|
3
|
+
export declare const liveDataHandler: (fieldData: string | number | Array<unknown>, formData: Record<string, unknown>, action: (data: string, ...args: any[]) => Promise<boolean>) => Promise<boolean>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.liveDataHandler = exports.liveDataAction = void 0;
|
|
13
|
+
const liveDataAction = (fieldData, formData, action) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
+
if (typeof fieldData === 'string') {
|
|
15
|
+
const options = yield action(fieldData, formData);
|
|
16
|
+
return options !== null && options !== void 0 ? options : [];
|
|
17
|
+
}
|
|
18
|
+
return [];
|
|
19
|
+
});
|
|
20
|
+
exports.liveDataAction = liveDataAction;
|
|
21
|
+
const liveDataHandler = (fieldData, formData, action) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
if (typeof fieldData === 'string') {
|
|
23
|
+
const result = yield action(fieldData, formData);
|
|
24
|
+
return result !== null && result !== void 0 ? result : false;
|
|
25
|
+
}
|
|
26
|
+
return false;
|
|
27
|
+
});
|
|
28
|
+
exports.liveDataHandler = liveDataHandler;
|
package/eslint.config.mjs
CHANGED
|
@@ -1,14 +1,72 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
|
|
2
|
+
import typescriptEslintEslintPlugin from '@typescript-eslint/eslint-plugin';
|
|
3
|
+
import tsParser from '@typescript-eslint/parser';
|
|
4
|
+
import { dirname } from "path";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
import js from '@eslint/js';
|
|
7
|
+
import { FlatCompat } from "@eslint/eslintrc";
|
|
8
|
+
|
|
9
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
+
const __dirname = dirname(__filename);
|
|
11
|
+
|
|
12
|
+
const compat = new FlatCompat({
|
|
13
|
+
baseDirectory: __dirname,
|
|
14
|
+
recommendedConfig: js.configs.recommended,
|
|
15
|
+
allConfig: js.configs.all,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const eslintConfig = [
|
|
19
|
+
...compat.extends(
|
|
20
|
+
'plugin:@typescript-eslint/recommended',
|
|
21
|
+
'plugin:prettier/recommended'
|
|
22
|
+
),
|
|
23
|
+
{ ignores : ['index.ts', 'examples/**', 'dist/**', 'node_modules/**', 'eslint.config.mjs', 'tsconfig.json'] },
|
|
24
|
+
{
|
|
25
|
+
plugins: {
|
|
26
|
+
'@typescript-eslint': typescriptEslintEslintPlugin,
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
languageOptions: {
|
|
30
|
+
|
|
31
|
+
parser: tsParser,
|
|
32
|
+
ecmaVersion: 5,
|
|
33
|
+
sourceType: 'module',
|
|
34
|
+
|
|
35
|
+
parserOptions: {
|
|
36
|
+
project: 'tsconfig.json',
|
|
37
|
+
tsconfigRootDir: __dirname,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
rules: {
|
|
42
|
+
'@typescript-eslint/interface-name-prefix': 'off',
|
|
43
|
+
'@typescript-eslint/explicit-function-return-type': 'off',
|
|
44
|
+
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
|
45
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
46
|
+
'global-require': 'off',
|
|
47
|
+
'newline-per-chained-call': 'off',
|
|
48
|
+
'import/no-dynamic-require': 'off',
|
|
49
|
+
|
|
50
|
+
quotes: [
|
|
51
|
+
'error',
|
|
52
|
+
'single',
|
|
53
|
+
{
|
|
54
|
+
allowTemplateLiterals: true,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
|
|
58
|
+
'class-methods-use-this': 'off',
|
|
59
|
+
|
|
60
|
+
'prettier/prettier': [
|
|
61
|
+
'error',
|
|
62
|
+
{
|
|
63
|
+
endOfLine: 'auto',
|
|
64
|
+
singleQuote: true,
|
|
65
|
+
trailingComma: 'all',
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
];
|
|
71
|
+
|
|
72
|
+
export default eslintConfig;
|
package/examples/live-data.ts
CHANGED