@tiny-codes/react-easy 1.0.3 → 1.0.4

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 (96) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/es/components/BreakLines/index.js +43 -26
  3. package/es/components/BreakLines/index.js.map +1 -1
  4. package/es/components/ConfigProvider/context.js +3 -3
  5. package/es/components/ConfigProvider/context.js.map +1 -1
  6. package/es/components/ConfigProvider/index.js +37 -35
  7. package/es/components/ConfigProvider/index.js.map +1 -1
  8. package/es/components/ConfirmAction/index.d.ts +74 -6
  9. package/es/components/ConfirmAction/index.js +210 -104
  10. package/es/components/ConfirmAction/index.js.map +1 -1
  11. package/es/components/DeleteConfirmAction/index.js +22 -20
  12. package/es/components/DeleteConfirmAction/index.js.map +1 -1
  13. package/es/components/ModalAction/index.d.ts +45 -5
  14. package/es/components/ModalAction/index.js +393 -209
  15. package/es/components/ModalAction/index.js.map +1 -1
  16. package/es/components/index.js +10 -8
  17. package/es/components/index.js.map +1 -1
  18. package/es/hooks/index.js +4 -4
  19. package/es/hooks/index.js.map +1 -1
  20. package/es/hooks/useContextValidator.js +7 -12
  21. package/es/hooks/useContextValidator.js.map +1 -1
  22. package/es/hooks/useLocalizedText.js +6 -4
  23. package/es/hooks/useLocalizedText.js.map +1 -1
  24. package/es/hooks/useRefFunction.js +13 -6
  25. package/es/hooks/useRefFunction.js.map +1 -1
  26. package/es/hooks/useT.js +11 -8
  27. package/es/hooks/useT.js.map +1 -1
  28. package/es/hooks/useValidator.js +7 -4
  29. package/es/hooks/useValidator.js.map +1 -1
  30. package/es/hooks/useValidatorBuilder.js +146 -117
  31. package/es/hooks/useValidatorBuilder.js.map +1 -1
  32. package/es/hooks/useValidators.js +94 -58
  33. package/es/hooks/useValidators.js.map +1 -1
  34. package/es/index.js +2 -2
  35. package/es/index.js.map +1 -1
  36. package/es/locales/index.js +19 -13
  37. package/es/locales/index.js.map +1 -1
  38. package/es/locales/langs/en-US.js +20 -20
  39. package/es/locales/langs/en-US.js.map +1 -1
  40. package/es/locales/langs/en.js +1 -1
  41. package/es/locales/langs/en.js.map +1 -1
  42. package/es/locales/langs/zh-CN.js +20 -20
  43. package/es/locales/langs/zh-CN.js.map +1 -1
  44. package/es/utils/index.js +1 -1
  45. package/es/utils/index.js.map +1 -1
  46. package/lib/components/BreakLines/index.js +50 -37
  47. package/lib/components/BreakLines/index.js.map +7 -1
  48. package/lib/components/ConfigProvider/context.js +35 -6
  49. package/lib/components/ConfigProvider/context.js.map +7 -1
  50. package/lib/components/ConfigProvider/index.js +56 -42
  51. package/lib/components/ConfigProvider/index.js.map +7 -1
  52. package/lib/components/ConfirmAction/index.d.ts +74 -6
  53. package/lib/components/ConfirmAction/index.js +194 -138
  54. package/lib/components/ConfirmAction/index.js.map +7 -1
  55. package/lib/components/DeleteConfirmAction/index.js +50 -51
  56. package/lib/components/DeleteConfirmAction/index.js.map +7 -1
  57. package/lib/components/ModalAction/index.d.ts +45 -5
  58. package/lib/components/ModalAction/index.js +303 -243
  59. package/lib/components/ModalAction/index.js.map +7 -1
  60. package/lib/components/index.js +63 -11
  61. package/lib/components/index.js.map +7 -1
  62. package/lib/hooks/index.js +49 -5
  63. package/lib/hooks/index.js.map +7 -1
  64. package/lib/hooks/useContextValidator.js +47 -11
  65. package/lib/hooks/useContextValidator.js.map +7 -1
  66. package/lib/hooks/useLocalizedText.js +41 -15
  67. package/lib/hooks/useLocalizedText.js.map +7 -1
  68. package/lib/hooks/useRefFunction.js +34 -21
  69. package/lib/hooks/useRefFunction.js.map +7 -1
  70. package/lib/hooks/useT.js +43 -11
  71. package/lib/hooks/useT.js.map +7 -1
  72. package/lib/hooks/useValidator.js +41 -12
  73. package/lib/hooks/useValidator.js.map +7 -1
  74. package/lib/hooks/useValidatorBuilder.js +149 -132
  75. package/lib/hooks/useValidatorBuilder.js.map +7 -1
  76. package/lib/hooks/useValidators.js +104 -67
  77. package/lib/hooks/useValidators.js.map +7 -1
  78. package/lib/index.js +26 -3
  79. package/lib/index.js.map +7 -1
  80. package/lib/locales/index.js +58 -15
  81. package/lib/locales/index.js.map +7 -1
  82. package/lib/locales/langs/en-US.js +46 -22
  83. package/lib/locales/langs/en-US.js.map +7 -1
  84. package/lib/locales/langs/en.js +37 -3
  85. package/lib/locales/langs/en.js.map +7 -1
  86. package/lib/locales/langs/zh-CN.js +46 -22
  87. package/lib/locales/langs/zh-CN.js.map +7 -1
  88. package/lib/utils/index.js +1 -2
  89. package/lib/utils/index.js.map +7 -1
  90. package/package.json +14 -15
  91. package/es/hooks/useValidateContext.d.ts +0 -2
  92. package/es/hooks/useValidateContext.js +0 -16
  93. package/es/hooks/useValidateContext.js.map +0 -1
  94. package/lib/hooks/useValidateContext.d.ts +0 -2
  95. package/lib/hooks/useValidateContext.js +0 -16
  96. package/lib/hooks/useValidateContext.js.map +0 -1
@@ -1,259 +1,319 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
9
10
  };
10
- var __rest = (this && this.__rest) || function (s, e) {
11
- var t = {};
12
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
- t[p] = s[p];
14
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
- t[p[i]] = s[p[i]];
18
- }
19
- return t;
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
20
18
  };
21
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
22
- import { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react';
23
- import { Button, Form, Modal, Switch, Typography } from 'antd';
24
- import { isForwardRef } from 'react-is';
25
- import useContextValidator from '../../hooks/useContextValidator';
26
- /**
27
- * **EN:** Symbol for not closing the dialog when submitting the form, which takes effect when
28
- * returning in the `onSave` event of the editing form component
29
- *
30
- * **CN:** 提交表单时不关闭弹框的Symbol,在编辑表单组件的`onSave`事件中返回时生效
31
- */
32
- export const SubmitWithoutClosingSymbol = Symbol('[SubmitWithoutClose]');
33
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
- export const genModalActionRenderer = (defaultProps) => {
35
- const ModalActionRenderer = (props, ref) => {
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/components/ModalAction/index.tsx
30
+ var ModalAction_exports = {};
31
+ __export(ModalAction_exports, {
32
+ SubmitWithoutClosingSymbol: () => SubmitWithoutClosingSymbol,
33
+ default: () => ModalAction_default,
34
+ genModalActionRenderer: () => genModalActionRenderer,
35
+ withDefaultModalActionProps: () => withDefaultModalActionProps,
36
+ withModalAction: () => withModalAction
37
+ });
38
+ module.exports = __toCommonJS(ModalAction_exports);
39
+ var import_react = require("react");
40
+ var import_antd = require("antd");
41
+ var import_react_is = require("react-is");
42
+ var import_useContextValidator = __toESM(require("../../hooks/useContextValidator"));
43
+ var SubmitWithoutClosingSymbol = Symbol("[SubmitWithoutClose]");
44
+ var genModalActionRenderer = (defaultProps) => {
45
+ const ModalActionRenderer = (props, ref) => {
46
+ const [userModalProps, setUserModalProps] = (0, import_react.useState)({});
47
+ let mergedProps = mergeProps(defaultProps, props);
48
+ mergedProps = mergeProps(mergedProps, userModalProps);
49
+ const {
50
+ formComp,
51
+ formProps,
52
+ triggerComponent: Trigger = import_antd.Button,
53
+ triggerEvent = "onClick",
54
+ triggerProps,
55
+ open: openInProps,
56
+ destroyOnClose = true,
57
+ maskClosable = false,
58
+ onOk,
59
+ afterOk,
60
+ onCancel,
61
+ onClose,
62
+ children,
63
+ ...restProps
64
+ } = mergedProps;
65
+ (0, import_useContextValidator.default)();
66
+ const FormComp = formComp;
67
+ const triggerEventArgsRef = (0, import_react.useRef)(void 0);
68
+ const [open, setOpen] = (0, import_react.useState)(false);
69
+ const saveFuncRef = (0, import_react.useRef)(void 0);
70
+ const [isSaving, setIsSaving] = (0, import_react.useState)(false);
71
+ const [formCompRef, setFormCompRef] = (0, import_react.useState)(null);
72
+ const [form, setForm] = (0, import_react.useState)();
73
+ const formRef = (0, import_react.useRef)(form);
74
+ formRef.current = form;
75
+ const destroyOnCloseRef = (0, import_react.useRef)(destroyOnClose);
76
+ destroyOnCloseRef.current = destroyOnClose;
77
+ const openListenerRef = (0, import_react.useRef)(void 0);
78
+ (0, import_react.useEffect)(() => {
79
+ if (openInProps) {
80
+ setOpen(openInProps);
81
+ }
82
+ }, [openInProps]);
83
+ (0, import_react.useEffect)(() => {
84
+ if (!destroyOnCloseRef.current && open && formRef.current) {
85
+ formRef.current.resetFields();
86
+ }
87
+ }, [open]);
88
+ const showInProps = triggerProps == null ? void 0 : triggerProps.show;
89
+ const showTrigger = (0, import_react.useMemo)(() => {
90
+ if (typeof showInProps === "boolean") {
91
+ return showInProps;
92
+ } else if (typeof showInProps === "function") {
93
+ return showInProps(formProps);
94
+ }
95
+ return true;
96
+ }, [showInProps, formProps]);
97
+ const showModal = (0, import_react.useCallback)(() => {
98
+ var _a;
99
+ setOpen(true);
100
+ (_a = openListenerRef.current) == null ? void 0 : _a.call(openListenerRef, true);
101
+ }, []);
102
+ const hideModal = (0, import_react.useCallback)(() => {
103
+ var _a;
104
+ setOpen(false);
105
+ (_a = openListenerRef.current) == null ? void 0 : _a.call(openListenerRef, false);
106
+ }, []);
107
+ const setOpenListener = (0, import_react.useCallback)(
108
+ (listener) => {
36
109
  var _a;
37
- const [userModalProps, setUserModalProps] = useState({});
38
- let mergedProps = mergeProps(defaultProps, props);
39
- mergedProps = mergeProps(mergedProps, userModalProps);
40
- const { formComp, formProps, triggerComponent: Trigger = Button, triggerEvent = 'onClick', triggerProps, open: openInProps, destroyOnClose = true, maskClosable = false, onOk, afterOk, onCancel, onClose, children } = mergedProps, restProps = __rest(mergedProps, ["formComp", "formProps", "triggerComponent", "triggerEvent", "triggerProps", "open", "destroyOnClose", "maskClosable", "onOk", "afterOk", "onCancel", "onClose", "children"]);
41
- useContextValidator();
42
- const FormComp = formComp;
43
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
- const triggerEventArgsRef = useRef(undefined);
45
- const [open, setOpen] = useState(false);
46
- const saveFuncRef = useRef(undefined);
47
- const [isSaving, setIsSaving] = useState(false);
48
- const [formCompRef, setFormCompRef] = useState(null);
49
- const [form, setForm] = useState();
50
- const formRef = useRef(form);
51
- formRef.current = form;
52
- const destroyOnCloseRef = useRef(destroyOnClose);
53
- destroyOnCloseRef.current = destroyOnClose;
54
- const openListenerRef = useRef(undefined);
55
- // Listen to the open props changes
56
- useEffect(() => {
57
- if (openInProps) {
58
- setOpen(openInProps);
110
+ openListenerRef.current = listener;
111
+ (_a = openListenerRef.current) == null ? void 0 : _a.call(openListenerRef, open);
112
+ },
113
+ [open]
114
+ );
115
+ const setOnSaveHandler = (0, import_react.useCallback)((handler) => {
116
+ saveFuncRef.current = handler;
117
+ }, []);
118
+ const handleSetOpen = (0, import_react.useCallback)((open2) => {
119
+ var _a;
120
+ setOpen(open2);
121
+ (_a = openListenerRef.current) == null ? void 0 : _a.call(openListenerRef, open2);
122
+ }, []);
123
+ (0, import_react.useImperativeHandle)(ref, () => ({ ...formCompRef, show: showModal }), [
124
+ formCompRef,
125
+ showModal
126
+ ]);
127
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, showTrigger && /* @__PURE__ */ React.createElement(
128
+ Trigger,
129
+ {
130
+ ...triggerProps,
131
+ ...triggerEvent ? {
132
+ [triggerEvent]: (...args) => {
133
+ triggerEventArgsRef.current = args;
134
+ showModal();
135
+ if (triggerProps && typeof triggerProps[triggerEvent] === "function") {
136
+ triggerProps[triggerEvent](...args);
59
137
  }
60
- }, [openInProps]);
61
- // Reset the form after closed
62
- useEffect(() => {
63
- if (!destroyOnCloseRef.current && open && formRef.current) {
64
- formRef.current.resetFields();
138
+ }
139
+ } : {}
140
+ },
141
+ triggerProps.children ?? children
142
+ ), /* @__PURE__ */ React.createElement(
143
+ import_antd.Modal,
144
+ {
145
+ open,
146
+ confirmLoading: isSaving,
147
+ destroyOnClose,
148
+ maskClosable,
149
+ onOk: async (e) => {
150
+ var _a;
151
+ let formData;
152
+ try {
153
+ formData = await (form == null ? void 0 : form.validateFields());
154
+ } catch (e2) {
155
+ return;
156
+ }
157
+ if (Object.keys(formData).length === 0) {
158
+ console.warn(
159
+ "form.getFieldsValue() is empty. Please use the form instance passed to formComp instead of creating the form instance yourself."
160
+ );
161
+ }
162
+ try {
163
+ setIsSaving(true);
164
+ let result = await ((_a = saveFuncRef.current) == null ? void 0 : _a.call(saveFuncRef, formData, ...triggerEventArgsRef.current ?? []));
165
+ if (result === SubmitWithoutClosingSymbol) {
166
+ throw new Error("SubmitWithoutClosing");
65
167
  }
66
- }, [open]);
67
- // Show the dialog
68
- const showModal = useCallback(() => {
69
- var _a;
70
- setOpen(true);
71
- (_a = openListenerRef.current) === null || _a === void 0 ? void 0 : _a.call(openListenerRef, true);
72
- }, []);
73
- // Hide the dialog
74
- const hideModal = useCallback(() => {
75
- var _a;
76
- setOpen(false);
77
- (_a = openListenerRef.current) === null || _a === void 0 ? void 0 : _a.call(openListenerRef, false);
78
- }, []);
79
- // Set the dialog status listener
80
- const setOpenListener = useCallback((listener) => {
81
- var _a;
82
- openListenerRef.current = listener;
83
- // Call once when initialized
84
- (_a = openListenerRef.current) === null || _a === void 0 ? void 0 : _a.call(openListenerRef, open);
85
- }, [open]);
86
- // Receive the onSave callback method passed by the form component
87
- const setOnSaveHandler = useCallback((handler) => {
88
- saveFuncRef.current = handler;
89
- }, []);
90
- // Set the dialog status and trigger the onOpenChange event of the form component
91
- const handleSetOpen = useCallback((open) => {
92
- var _a;
93
- setOpen(open);
94
- (_a = openListenerRef.current) === null || _a === void 0 ? void 0 : _a.call(openListenerRef, open);
95
- }, []);
96
- // Output ref
97
- useImperativeHandle(ref, () => (Object.assign(Object.assign({}, formCompRef), { show: showModal })), [
98
- formCompRef,
99
- showModal,
100
- ]);
101
- // Render the trigger component
102
- return (_jsxs(_Fragment, { children: [_jsx(Trigger, Object.assign({}, triggerProps, (triggerEvent
103
- ? {
104
- [triggerEvent]: (...args) => {
105
- triggerEventArgsRef.current = args;
106
- showModal();
107
- if (triggerProps && typeof triggerProps[triggerEvent] === 'function') {
108
- triggerProps[triggerEvent](...args);
109
- }
110
- },
111
- }
112
- : {}), { children: (_a = triggerProps.children) !== null && _a !== void 0 ? _a : children })), _jsxs(Modal, Object.assign({ open: open, confirmLoading: isSaving, destroyOnClose: destroyOnClose, maskClosable: maskClosable, onOk: (e) => __awaiter(void 0, void 0, void 0, function* () {
113
- var _a, _b, _c, _d;
114
- let formData;
115
- try {
116
- formData = (yield (form === null || form === void 0 ? void 0 : form.validateFields()));
117
- }
118
- catch (e) {
119
- // Validation error, should not throw error
120
- return;
121
- }
122
- if (Object.keys(formData).length === 0) {
123
- console.warn('form.getFieldsValue() is empty. Please use the form instance passed to formComp instead of creating the form instance yourself.');
124
- }
125
- try {
126
- setIsSaving(true);
127
- // First call onSave of the form component
128
- let result = yield ((_a = saveFuncRef.current) === null || _a === void 0 ? void 0 : _a.call(saveFuncRef, formData, ...((_b = triggerEventArgsRef.current) !== null && _b !== void 0 ? _b : [])));
129
- // The onSave of the form component has the ability to prevent the dialog from closing
130
- if (result === SubmitWithoutClosingSymbol) {
131
- throw new Error('SubmitWithoutClosing');
132
- }
133
- // Then call onOk of the dialog, support asynchronous, and will pass the return value of onSave, if any
134
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
135
- result = yield (onOk === null || onOk === void 0 ? void 0 : onOk((_c = result) !== null && _c !== void 0 ? _c : formData, ...((_d = triggerEventArgsRef.current) !== null && _d !== void 0 ? _d : [])));
136
- // onOk also has the ability to prevent the dialog from closing
137
- if (result === SubmitWithoutClosingSymbol) {
138
- throw new Error('SubmitWithoutClosing');
139
- }
140
- // If onOK is successful, close the dialog and trigger the afterOk event
141
- hideModal();
142
- afterOk === null || afterOk === void 0 ? void 0 : afterOk(result);
143
- }
144
- catch (error) {
145
- console.error(error);
146
- }
147
- finally {
148
- setIsSaving(false);
149
- }
150
- }), onCancel: (e) => __awaiter(void 0, void 0, void 0, function* () {
151
- hideModal();
152
- onCancel === null || onCancel === void 0 ? void 0 : onCancel(e);
153
- }), onClose: (e) => {
154
- hideModal();
155
- onClose === null || onClose === void 0 ? void 0 : onClose(e);
156
- } }, restProps, { children: [_jsx(FormCreator, { onCreate: setForm }), form && (_jsx(FormComp, Object.assign({ ref: isForwardRef(FormComp) ? setFormCompRef : undefined }, formProps, { form: form, onOpenChange: setOpenListener, onSave: setOnSaveHandler, triggerEventData: triggerEventArgsRef.current, setOpen: handleSetOpen, updateModalProps: setUserModalProps })))] }))] }));
157
- };
158
- return ModalActionRenderer;
168
+ result = await (onOk == null ? void 0 : onOk(result ?? formData, ...triggerEventArgsRef.current ?? []));
169
+ if (result === SubmitWithoutClosingSymbol) {
170
+ throw new Error("SubmitWithoutClosing");
171
+ }
172
+ hideModal();
173
+ afterOk == null ? void 0 : afterOk(result);
174
+ } catch (error) {
175
+ console.error(error);
176
+ } finally {
177
+ setIsSaving(false);
178
+ }
179
+ },
180
+ onCancel: async (e) => {
181
+ hideModal();
182
+ onCancel == null ? void 0 : onCancel(e);
183
+ },
184
+ onClose: (e) => {
185
+ hideModal();
186
+ onClose == null ? void 0 : onClose(e);
187
+ },
188
+ ...restProps
189
+ },
190
+ /* @__PURE__ */ React.createElement(FormCreator, { onCreate: setForm }),
191
+ form && /* @__PURE__ */ React.createElement(
192
+ FormComp,
193
+ {
194
+ ref: (0, import_react_is.isForwardRef)(FormComp) ? setFormCompRef : void 0,
195
+ ...formProps,
196
+ form,
197
+ onOpenChange: setOpenListener,
198
+ onSave: setOnSaveHandler,
199
+ triggerEventData: triggerEventArgsRef.current,
200
+ setOpen: handleSetOpen,
201
+ updateModalProps: setUserModalProps
202
+ }
203
+ )
204
+ ));
205
+ };
206
+ return ModalActionRenderer;
159
207
  };
160
208
  function mergeProps(first, second) {
161
- return Object.assign(Object.assign(Object.assign({}, first), second), { okButtonProps: Object.assign(Object.assign({}, first === null || first === void 0 ? void 0 : first.okButtonProps), second === null || second === void 0 ? void 0 : second.okButtonProps), cancelButtonProps: Object.assign(Object.assign({}, first === null || first === void 0 ? void 0 : first.cancelButtonProps), second === null || second === void 0 ? void 0 : second.cancelButtonProps), bodyProps: Object.assign(Object.assign({}, first === null || first === void 0 ? void 0 : first.bodyProps), second === null || second === void 0 ? void 0 : second.bodyProps), maskProps: Object.assign(Object.assign({}, first === null || first === void 0 ? void 0 : first.maskProps), second === null || second === void 0 ? void 0 : second.maskProps), wrapProps: Object.assign(Object.assign({}, first === null || first === void 0 ? void 0 : first.wrapProps), second === null || second === void 0 ? void 0 : second.wrapProps), triggerProps: Object.assign(Object.assign(Object.assign({}, first === null || first === void 0 ? void 0 : first.triggerProps), second === null || second === void 0 ? void 0 : second.triggerProps), { style: Object.assign(Object.assign({}, ((first === null || first === void 0 ? void 0 : first.triggerProps) && 'style' in first.triggerProps && typeof first.triggerProps.style === 'object'
162
- ? first.triggerProps.style
163
- : {})), ((second === null || second === void 0 ? void 0 : second.triggerProps) && 'style' in second.triggerProps && typeof second.triggerProps.style === 'object'
164
- ? second.triggerProps.style
165
- : {})) }) });
209
+ return {
210
+ ...first,
211
+ ...second,
212
+ okButtonProps: {
213
+ ...first == null ? void 0 : first.okButtonProps,
214
+ ...second == null ? void 0 : second.okButtonProps
215
+ },
216
+ cancelButtonProps: {
217
+ ...first == null ? void 0 : first.cancelButtonProps,
218
+ ...second == null ? void 0 : second.cancelButtonProps
219
+ },
220
+ bodyProps: {
221
+ ...first == null ? void 0 : first.bodyProps,
222
+ ...second == null ? void 0 : second.bodyProps
223
+ },
224
+ maskProps: {
225
+ ...first == null ? void 0 : first.maskProps,
226
+ ...second == null ? void 0 : second.maskProps
227
+ },
228
+ wrapProps: {
229
+ ...first == null ? void 0 : first.wrapProps,
230
+ ...second == null ? void 0 : second.wrapProps
231
+ },
232
+ triggerProps: {
233
+ ...first == null ? void 0 : first.triggerProps,
234
+ ...second == null ? void 0 : second.triggerProps,
235
+ style: {
236
+ ...(first == null ? void 0 : first.triggerProps) && "style" in first.triggerProps && typeof first.triggerProps.style === "object" ? first.triggerProps.style : {},
237
+ ...(second == null ? void 0 : second.triggerProps) && "style" in second.triggerProps && typeof second.triggerProps.style === "object" ? second.triggerProps.style : {}
238
+ }
239
+ }
240
+ };
166
241
  }
167
242
  function FormCreator(props) {
168
- const { onCreate } = props;
169
- const onCreateRef = useRef(onCreate);
170
- onCreateRef.current = onCreate;
171
- const [form] = Form.useForm();
172
- // output ref
173
- useEffect(() => {
174
- onCreateRef.current(form);
175
- return () => {
176
- onCreateRef.current(undefined);
177
- };
178
- }, [form]);
179
- return null;
243
+ const { onCreate } = props;
244
+ const onCreateRef = (0, import_react.useRef)(onCreate);
245
+ onCreateRef.current = onCreate;
246
+ const [form] = import_antd.Form.useForm();
247
+ (0, import_react.useEffect)(() => {
248
+ onCreateRef.current(form);
249
+ return () => {
250
+ onCreateRef.current(void 0);
251
+ };
252
+ }, [form]);
253
+ return null;
180
254
  }
181
- /**
182
- * **EN:** Add default properties to the ModalAction component
183
- *
184
- * **CN:** 给ModalAction组件添加默认属性
185
- *
186
- * @param WrappedComponent ModalAction component | ModalAction组件
187
- * @param defaultProps Default properties | 默认属性
188
- */
189
- export const withDefaultModalActionProps = (WrappedComponent, defaultProps) => {
190
- const WithDefaultProps = forwardRef((props, ref) => {
191
- const useDefaultProps = typeof defaultProps === 'function' ? defaultProps : () => defaultProps;
192
- const defaults = useDefaultProps();
193
- const mergedProps = mergeProps(defaults, props);
194
- WithDefaultProps.displayName = 'ForwardedRef(WithDefaultProps)';
195
- return _jsx(WrappedComponent, Object.assign({ ref: ref }, mergedProps));
196
- });
197
- return WithDefaultProps;
255
+ var withDefaultModalActionProps = (WrappedComponent, defaultProps) => {
256
+ const WithDefaultProps = (0, import_react.forwardRef)((props, ref) => {
257
+ const useDefaultProps = typeof defaultProps === "function" ? defaultProps : () => defaultProps;
258
+ const defaults = useDefaultProps();
259
+ const mergedProps = mergeProps(defaults, props);
260
+ WithDefaultProps.displayName = "ForwardedRef(WithDefaultProps)";
261
+ return /* @__PURE__ */ React.createElement(WrappedComponent, { ref, ...mergedProps });
262
+ });
263
+ return WithDefaultProps;
198
264
  };
199
- const renderModalAction = genModalActionRenderer({});
200
- const forwardedModalAction = forwardRef(renderModalAction);
201
- forwardedModalAction.displayName = 'ForwardedRef(ModalAction)';
202
- /**
203
- * **EN:** Add trigger types to the ModalAction component
204
- *
205
- * **CN:** 给ModalAction组件添加子触发器类型
206
- */
207
- const addTriggers = (comp) => {
208
- const patchedComp = comp;
209
- // Type of button trigger
210
- patchedComp.Button = withDefaultModalActionProps(comp, {
211
- triggerComponent: Button,
212
- triggerEvent: 'onClick',
213
- triggerProps: {},
214
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
215
- });
216
- // Type of switch trigger
217
- patchedComp.Switch = withDefaultModalActionProps(comp, {
218
- triggerComponent: Switch,
219
- triggerEvent: 'onChange',
220
- triggerProps: {},
265
+ var renderModalAction = genModalActionRenderer({});
266
+ var forwardedModalAction = (0, import_react.forwardRef)(renderModalAction);
267
+ forwardedModalAction.displayName = "ForwardedRef(ModalAction)";
268
+ var addTriggers = (comp) => {
269
+ const patchedComp = comp;
270
+ patchedComp.Button = withDefaultModalActionProps(comp, {
271
+ triggerComponent: import_antd.Button,
272
+ triggerEvent: "onClick",
273
+ triggerProps: {}
274
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
275
+ });
276
+ patchedComp.Switch = withDefaultModalActionProps(
277
+ comp,
278
+ {
279
+ triggerComponent: import_antd.Switch,
280
+ triggerEvent: "onChange",
281
+ triggerProps: {}
221
282
  }
222
283
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
223
- );
224
- // Type of link trigger
225
- patchedComp.Link = withDefaultModalActionProps(comp, {
226
- triggerComponent: Typography.Link,
227
- triggerEvent: 'onClick',
228
- triggerProps: {
229
- style: { whiteSpace: 'nowrap' },
230
- },
231
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
232
- });
233
- return patchedComp;
284
+ );
285
+ patchedComp.Link = withDefaultModalActionProps(comp, {
286
+ triggerComponent: import_antd.Typography.Link,
287
+ triggerEvent: "onClick",
288
+ triggerProps: {
289
+ style: { whiteSpace: "nowrap" }
290
+ }
291
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
292
+ });
293
+ return patchedComp;
234
294
  };
235
- /**
236
- * **EN:** Dialog component with trigger
237
- *
238
- * **CN:** 带触发器的弹窗组件
239
- */
240
- const ModalAction = addTriggers(forwardedModalAction);
295
+ var ModalAction = addTriggers(forwardedModalAction);
241
296
  ModalAction.SubmitWithoutClosing = SubmitWithoutClosingSymbol;
242
- /**
243
- * **EN:** Generate a dialog component based on the editing form component
244
- *
245
- * **CN:** 基于编辑表单组件生成一个弹框组件
246
- *
247
- * @param formComp Component of dialog content | 弹窗内容组件
248
- * @param defaultProps Default properties of the dialog | 弹窗的默认属性
249
- */
250
- export function withModalAction(formComp, defaultProps) {
251
- const withForm = withDefaultModalActionProps(forwardedModalAction, () => {
252
- const useDefaultProps = typeof defaultProps === 'function' ? defaultProps : () => defaultProps;
253
- const defaults = useDefaultProps();
254
- return Object.assign({ formComp }, defaults);
255
- });
256
- return addTriggers(withForm);
297
+ function withModalAction(formComp, defaultProps) {
298
+ const withForm = withDefaultModalActionProps(
299
+ forwardedModalAction,
300
+ () => {
301
+ const useDefaultProps = typeof defaultProps === "function" ? defaultProps : () => defaultProps;
302
+ const defaults = useDefaultProps();
303
+ return {
304
+ formComp,
305
+ ...defaults
306
+ };
307
+ }
308
+ );
309
+ return addTriggers(withForm);
257
310
  }
258
- export default ModalAction;
259
- //# sourceMappingURL=index.js.map
311
+ var ModalAction_default = ModalAction;
312
+ // Annotate the CommonJS export names for ESM import in node:
313
+ 0 && (module.exports = {
314
+ SubmitWithoutClosingSymbol,
315
+ genModalActionRenderer,
316
+ withDefaultModalActionProps,
317
+ withModalAction
318
+ });
319
+ //# sourceMappingURL=index.js.map