@carefrees/form-utils-react-hooks 0.0.5 → 0.0.6
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/esm/hooks/register/register.FormHideItem.js +3 -3
- package/esm/hooks/register/register.FormItem.js +3 -4
- package/esm/index.d.ts +0 -1
- package/esm/index.js +0 -1
- package/lib/hooks/register/register.FormHideItem.js +3 -3
- package/lib/hooks/register/register.FormItem.js +3 -4
- package/lib/index.d.ts +0 -1
- package/lib/index.js +3 -12
- package/package.json +2 -2
- package/src/hooks/register/register.FormHideItem.ts +4 -5
- package/src/hooks/register/register.FormItem.ts +5 -5
- package/src/index.ts +0 -1
- package/esm/hooks/useUpdate.d.ts +0 -2
- package/esm/hooks/useUpdate.js +0 -10
- package/lib/hooks/useUpdate.d.ts +0 -2
- package/lib/hooks/useUpdate.js +0 -44
- package/src/hooks/useUpdate.ts +0 -12
|
@@ -2,11 +2,10 @@ import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
|
2
2
|
import * as __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__ from "@carefrees/form-utils";
|
|
3
3
|
import * as __WEBPACK_EXTERNAL_MODULE__useFormItemParentName_js_a729dfb1__ from "../useFormItemParentName.js";
|
|
4
4
|
import * as __WEBPACK_EXTERNAL_MODULE__useForm_js_2c14e707__ from "../useForm.js";
|
|
5
|
-
import * as __WEBPACK_EXTERNAL_MODULE__useUpdate_js_b5f1687a__ from "../useUpdate.js";
|
|
6
5
|
const useRegisterFormHideItem = (options)=>{
|
|
7
6
|
const { name, sort, isJoinParentField = true } = options;
|
|
8
7
|
const form = (0, __WEBPACK_EXTERNAL_MODULE__useForm_js_2c14e707__.useFormInstance)();
|
|
9
|
-
const
|
|
8
|
+
const [, setValue] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)({});
|
|
10
9
|
const { newName, newSort } = (0, __WEBPACK_EXTERNAL_MODULE__useFormItemParentName_js_a729dfb1__.useFormItemParentName)({
|
|
11
10
|
name,
|
|
12
11
|
sort,
|
|
@@ -14,8 +13,9 @@ const useRegisterFormHideItem = (options)=>{
|
|
|
14
13
|
});
|
|
15
14
|
const hideItemInstance = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(new __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__.FormHideItemInstanceBase().ctor(newName)).current;
|
|
16
15
|
const isHide = form.getFieldHideValue(newName);
|
|
16
|
+
hideItemInstance.preHideValue = isHide;
|
|
17
17
|
hideItemInstance.instance = form;
|
|
18
|
-
hideItemInstance.
|
|
18
|
+
hideItemInstance.updatedItem = setValue;
|
|
19
19
|
hideItemInstance.sort = newSort;
|
|
20
20
|
(0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
|
|
21
21
|
const unMount = form.registerFormHideItem(hideItemInstance);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
2
2
|
import * as __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__ from "@carefrees/form-utils";
|
|
3
|
-
import * as __WEBPACK_EXTERNAL_MODULE__useUpdate_js_b5f1687a__ from "../useUpdate.js";
|
|
4
3
|
import * as __WEBPACK_EXTERNAL_MODULE__useForm_js_2c14e707__ from "../useForm.js";
|
|
5
4
|
import * as __WEBPACK_EXTERNAL_MODULE__useFormItem_js_cd5761e5__ from "../useFormItem.js";
|
|
6
5
|
import * as __WEBPACK_EXTERNAL_MODULE__useFormItemParentName_js_a729dfb1__ from "../useFormItemParentName.js";
|
|
@@ -12,6 +11,7 @@ const useRegisterFormItem = (options)=>{
|
|
|
12
11
|
sort,
|
|
13
12
|
isJoinParentField
|
|
14
13
|
});
|
|
14
|
+
const [, setValue] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)({});
|
|
15
15
|
const ruleInstance = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(new __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__.RuleInstanceBase()).current;
|
|
16
16
|
(0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>ruleInstance.ctor(newName, rules), [
|
|
17
17
|
rules,
|
|
@@ -24,9 +24,8 @@ const useRegisterFormItem = (options)=>{
|
|
|
24
24
|
formItemInstance.instance = form;
|
|
25
25
|
formItemInstance.sort = newSort;
|
|
26
26
|
formItemInstance.parentDataField = parentName;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
ruleInstance.updated = _updated.current;
|
|
27
|
+
formItemInstance.updated = setValue;
|
|
28
|
+
ruleInstance.updated = setValue;
|
|
30
29
|
(0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
|
|
31
30
|
const unMount = form.registerFormItem(formItemInstance);
|
|
32
31
|
return ()=>unMount();
|
package/esm/index.d.ts
CHANGED
package/esm/index.js
CHANGED
|
@@ -30,11 +30,10 @@ const external_react_namespaceObject = require("react");
|
|
|
30
30
|
const form_utils_namespaceObject = require("@carefrees/form-utils");
|
|
31
31
|
const external_useFormItemParentName_js_namespaceObject = require("../useFormItemParentName.js");
|
|
32
32
|
const external_useForm_js_namespaceObject = require("../useForm.js");
|
|
33
|
-
const external_useUpdate_js_namespaceObject = require("../useUpdate.js");
|
|
34
33
|
const useRegisterFormHideItem = (options)=>{
|
|
35
34
|
const { name, sort, isJoinParentField = true } = options;
|
|
36
35
|
const form = (0, external_useForm_js_namespaceObject.useFormInstance)();
|
|
37
|
-
const
|
|
36
|
+
const [, setValue] = (0, external_react_namespaceObject.useState)({});
|
|
38
37
|
const { newName, newSort } = (0, external_useFormItemParentName_js_namespaceObject.useFormItemParentName)({
|
|
39
38
|
name,
|
|
40
39
|
sort,
|
|
@@ -42,8 +41,9 @@ const useRegisterFormHideItem = (options)=>{
|
|
|
42
41
|
});
|
|
43
42
|
const hideItemInstance = (0, external_react_namespaceObject.useRef)(new form_utils_namespaceObject.FormHideItemInstanceBase().ctor(newName)).current;
|
|
44
43
|
const isHide = form.getFieldHideValue(newName);
|
|
44
|
+
hideItemInstance.preHideValue = isHide;
|
|
45
45
|
hideItemInstance.instance = form;
|
|
46
|
-
hideItemInstance.
|
|
46
|
+
hideItemInstance.updatedItem = setValue;
|
|
47
47
|
hideItemInstance.sort = newSort;
|
|
48
48
|
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
49
49
|
const unMount = form.registerFormHideItem(hideItemInstance);
|
|
@@ -28,7 +28,6 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
28
28
|
});
|
|
29
29
|
const external_react_namespaceObject = require("react");
|
|
30
30
|
const form_utils_namespaceObject = require("@carefrees/form-utils");
|
|
31
|
-
const external_useUpdate_js_namespaceObject = require("../useUpdate.js");
|
|
32
31
|
const external_useForm_js_namespaceObject = require("../useForm.js");
|
|
33
32
|
const external_useFormItem_js_namespaceObject = require("../useFormItem.js");
|
|
34
33
|
const external_useFormItemParentName_js_namespaceObject = require("../useFormItemParentName.js");
|
|
@@ -40,6 +39,7 @@ const useRegisterFormItem = (options)=>{
|
|
|
40
39
|
sort,
|
|
41
40
|
isJoinParentField
|
|
42
41
|
});
|
|
42
|
+
const [, setValue] = (0, external_react_namespaceObject.useState)({});
|
|
43
43
|
const ruleInstance = (0, external_react_namespaceObject.useRef)(new form_utils_namespaceObject.RuleInstanceBase()).current;
|
|
44
44
|
(0, external_react_namespaceObject.useMemo)(()=>ruleInstance.ctor(newName, rules), [
|
|
45
45
|
rules,
|
|
@@ -52,9 +52,8 @@ const useRegisterFormItem = (options)=>{
|
|
|
52
52
|
formItemInstance.instance = form;
|
|
53
53
|
formItemInstance.sort = newSort;
|
|
54
54
|
formItemInstance.parentDataField = parentName;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
ruleInstance.updated = _updated.current;
|
|
55
|
+
formItemInstance.updated = setValue;
|
|
56
|
+
ruleInstance.updated = setValue;
|
|
58
57
|
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
59
58
|
const unMount = form.registerFormItem(formItemInstance);
|
|
60
59
|
return ()=>unMount();
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -33,9 +33,6 @@ var __webpack_modules__ = {
|
|
|
33
33
|
"./hooks/useMultipleForm": function(module) {
|
|
34
34
|
module.exports = require("./hooks/useMultipleForm.js");
|
|
35
35
|
},
|
|
36
|
-
"./hooks/useUpdate": function(module) {
|
|
37
|
-
module.exports = require("./hooks/useUpdate.js");
|
|
38
|
-
},
|
|
39
36
|
"./hooks/useWatch": function(module) {
|
|
40
37
|
module.exports = require("./hooks/useWatch.js");
|
|
41
38
|
}
|
|
@@ -149,16 +146,10 @@ var __webpack_exports__ = {};
|
|
|
149
146
|
return _hooks_useMultipleForm__WEBPACK_IMPORTED_MODULE_10__[key];
|
|
150
147
|
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
151
148
|
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
152
|
-
var
|
|
153
|
-
var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
154
|
-
for(var __WEBPACK_IMPORT_KEY__ in _hooks_useUpdate__WEBPACK_IMPORTED_MODULE_11__)if ("default" !== __WEBPACK_IMPORT_KEY__) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
|
|
155
|
-
return _hooks_useUpdate__WEBPACK_IMPORTED_MODULE_11__[key];
|
|
156
|
-
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
157
|
-
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
158
|
-
var _hooks_useWatch__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__("./hooks/useWatch");
|
|
149
|
+
var _hooks_useWatch__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__("./hooks/useWatch");
|
|
159
150
|
var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
160
|
-
for(var __WEBPACK_IMPORT_KEY__ in
|
|
161
|
-
return
|
|
151
|
+
for(var __WEBPACK_IMPORT_KEY__ in _hooks_useWatch__WEBPACK_IMPORTED_MODULE_11__)if ("default" !== __WEBPACK_IMPORT_KEY__) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
|
|
152
|
+
return _hooks_useWatch__WEBPACK_IMPORTED_MODULE_11__[key];
|
|
162
153
|
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
163
154
|
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
164
155
|
})();
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"author": "SunLxy <1011771396@qq.com>",
|
|
4
4
|
"description": "表单组件公共hooks",
|
|
5
5
|
"homepage": "https://github.com/SunLxy/carefrees-form-utils",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.6",
|
|
7
7
|
"main": "lib/index.js",
|
|
8
8
|
"types": "lib/index.d.ts",
|
|
9
9
|
"module": "esm/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"esm"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@carefrees/form-utils": "^0.0.
|
|
24
|
+
"@carefrees/form-utils": "^0.0.6"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/react": "18.2.21",
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { useEffect, useRef } from 'react';
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { RegisterFormItemOptions } from './register.FormItem';
|
|
3
3
|
import { FormHideItemInstanceBase } from '@carefrees/form-utils';
|
|
4
4
|
import { useFormItemParentName } from '../useFormItemParentName';
|
|
5
5
|
import { useFormInstance } from '../useForm';
|
|
6
|
-
import { useUpdate } from '../useUpdate';
|
|
7
6
|
|
|
8
7
|
interface RegisterFormHideItemOptions extends Omit<RegisterFormItemOptions, 'rules'> {}
|
|
9
8
|
|
|
@@ -11,13 +10,13 @@ interface RegisterFormHideItemOptions extends Omit<RegisterFormItemOptions, 'rul
|
|
|
11
10
|
export const useRegisterFormHideItem = (options: RegisterFormHideItemOptions) => {
|
|
12
11
|
const { name, sort, isJoinParentField = true } = options;
|
|
13
12
|
const form = useFormInstance();
|
|
14
|
-
const
|
|
13
|
+
const [, setValue] = useState({});
|
|
15
14
|
const { newName, newSort } = useFormItemParentName({ name, sort, isJoinParentField });
|
|
16
15
|
const hideItemInstance = useRef(new FormHideItemInstanceBase().ctor(newName)).current;
|
|
17
16
|
const isHide = form.getFieldHideValue(newName);
|
|
18
|
-
|
|
17
|
+
hideItemInstance.preHideValue = isHide;
|
|
19
18
|
hideItemInstance.instance = form;
|
|
20
|
-
hideItemInstance.
|
|
19
|
+
hideItemInstance.updatedItem = setValue;
|
|
21
20
|
hideItemInstance.sort = newSort;
|
|
22
21
|
|
|
23
22
|
useEffect(() => {
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
* @description 注册组件
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { useEffect, useMemo, useRef } from 'react';
|
|
5
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
6
6
|
import { RuleInstanceBase } from '@carefrees/form-utils';
|
|
7
7
|
import type { RuleItem } from 'async-validator';
|
|
8
|
-
import { useUpdate } from '../useUpdate';
|
|
9
8
|
import { useFormInstance } from '../useForm';
|
|
10
9
|
import { useFormItem } from '../useFormItem';
|
|
11
10
|
import { useFormItemParentName } from '../useFormItemParentName';
|
|
@@ -26,6 +25,8 @@ export const useRegisterFormItem = (options: RegisterFormItemOptions) => {
|
|
|
26
25
|
const { name, rules, sort, isJoinParentField = true } = options;
|
|
27
26
|
const form = useFormInstance();
|
|
28
27
|
const { newName, newSort, parentName } = useFormItemParentName({ name, sort, isJoinParentField });
|
|
28
|
+
const [, setValue] = useState({});
|
|
29
|
+
|
|
29
30
|
// 注册规则
|
|
30
31
|
// 注册单个实例
|
|
31
32
|
const ruleInstance = useRef(new RuleInstanceBase()).current;
|
|
@@ -39,9 +40,8 @@ export const useRegisterFormItem = (options: RegisterFormItemOptions) => {
|
|
|
39
40
|
formItemInstance.sort = newSort;
|
|
40
41
|
formItemInstance.parentDataField = parentName;
|
|
41
42
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
ruleInstance.updated = _updated.current;
|
|
43
|
+
formItemInstance.updated = setValue;
|
|
44
|
+
ruleInstance.updated = setValue;
|
|
45
45
|
|
|
46
46
|
useEffect(() => {
|
|
47
47
|
const unMount = form.registerFormItem(formItemInstance);
|
package/src/index.ts
CHANGED
package/esm/hooks/useUpdate.d.ts
DELETED
package/esm/hooks/useUpdate.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
|
|
2
|
-
const useUpdate = ()=>{
|
|
3
|
-
const [, _update] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)({});
|
|
4
|
-
const refUpdate = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(()=>void 0);
|
|
5
|
-
refUpdate.current = ()=>{
|
|
6
|
-
_update({});
|
|
7
|
-
};
|
|
8
|
-
return refUpdate;
|
|
9
|
-
};
|
|
10
|
-
export { useUpdate };
|
package/lib/hooks/useUpdate.d.ts
DELETED
package/lib/hooks/useUpdate.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: definition[key]
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
})();
|
|
11
|
-
(()=>{
|
|
12
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
-
})();
|
|
14
|
-
(()=>{
|
|
15
|
-
__webpack_require__.r = (exports1)=>{
|
|
16
|
-
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
-
value: 'Module'
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
-
value: true
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
})();
|
|
24
|
-
var __webpack_exports__ = {};
|
|
25
|
-
__webpack_require__.r(__webpack_exports__);
|
|
26
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
useUpdate: ()=>useUpdate
|
|
28
|
-
});
|
|
29
|
-
const external_react_namespaceObject = require("react");
|
|
30
|
-
const useUpdate = ()=>{
|
|
31
|
-
const [, _update] = (0, external_react_namespaceObject.useState)({});
|
|
32
|
-
const refUpdate = (0, external_react_namespaceObject.useRef)(()=>void 0);
|
|
33
|
-
refUpdate.current = ()=>{
|
|
34
|
-
_update({});
|
|
35
|
-
};
|
|
36
|
-
return refUpdate;
|
|
37
|
-
};
|
|
38
|
-
exports.useUpdate = __webpack_exports__.useUpdate;
|
|
39
|
-
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
40
|
-
"useUpdate"
|
|
41
|
-
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
42
|
-
Object.defineProperty(exports, '__esModule', {
|
|
43
|
-
value: true
|
|
44
|
-
});
|
package/src/hooks/useUpdate.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { useState, useRef } from 'react';
|
|
2
|
-
|
|
3
|
-
/**更新页面状态*/
|
|
4
|
-
export const useUpdate = () => {
|
|
5
|
-
const [, _update] = useState({});
|
|
6
|
-
/**为了防止 hooks 闭包问题*/
|
|
7
|
-
const refUpdate = useRef<Function>(() => void 0);
|
|
8
|
-
refUpdate.current = () => {
|
|
9
|
-
_update({});
|
|
10
|
-
};
|
|
11
|
-
return refUpdate;
|
|
12
|
-
};
|