@fairys/valtio-form-basic 1.0.1 → 1.0.2

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.
@@ -81,6 +81,8 @@ export interface FairysValtioFormItemAttrsProps<T extends MObject<T> = Record<st
81
81
  * @default true
82
82
  */
83
83
  isRemoveValueOnUnmount?: boolean;
84
+ /**隐藏表单项移除数据*/
85
+ isHideRemoveValue?: boolean;
84
86
  }
85
87
  /**
86
88
  * 处理表单表单项属性
@@ -244,3 +246,7 @@ export interface FairysValtioFormItemNoStyleAttrsReturn<T extends MObject<T> = R
244
246
  /**子元素*/
245
247
  children?: React.ReactNode;
246
248
  }
249
+ /**
250
+ * 处理表单表单项属性,隐藏表单项时移除数据值
251
+ */
252
+ export declare function useFairysValtioFormItemHideAttrs<T extends MObject<T> = Record<string, any>>(props: FairysValtioFormItemAttrsProps<T>): void;
@@ -21,7 +21,7 @@ function useFairysValtioFormItemAttrs(props) {
21
21
  const parent_isInvalidTextRed = layoutAttrs.isInvalidTextRed;
22
22
  const parent_showColon = layoutAttrs.showColon;
23
23
  const parent_platform = layoutAttrs.platform;
24
- const { name, valuePropName = 'value', getValuePath = valuePropName, getValueFromEvent, formatValue, onAfterUpdate, trigger = 'onChange', className, style, labelClassName, labelStyle, bodyClassName, bodyStyle, children, labelMode = parent_labelMode, errorLayout = parent_errorLayout, colSpan = 1, rowSpan = 1, isRequired: _isRequired, itemBorderType = parent_borderedType, attrs = {}, showColon = parent_showColon, itemBorderColor = parent_itemBorderColor, isInvalidBorderRed = parent_isInvalidBorderRed, isInvalidTextRed = parent_isInvalidTextRed, isJoinParentField = true, rules, platform = parent_platform, isRemoveValueOnUnmount = true } = props;
24
+ const { name, valuePropName = 'value', getValuePath = valuePropName, getValueFromEvent, formatValue, onAfterUpdate, trigger = 'onChange', className, style, labelClassName, labelStyle, bodyClassName, bodyStyle, children, labelMode = parent_labelMode, errorLayout = parent_errorLayout, colSpan = 1, rowSpan = 1, isRequired: _isRequired, itemBorderType = parent_borderedType, attrs = {}, showColon = parent_showColon, itemBorderColor = parent_itemBorderColor, isInvalidBorderRed = parent_isInvalidBorderRed, isInvalidTextRed = parent_isInvalidTextRed, isJoinParentField = true, rules, platform = parent_platform, isRemoveValueOnUnmount = false } = props;
25
25
  const { name: _name, paths, parentName, formAttrsNameInstance } = useFairysValtioFormAttrsName({
26
26
  name,
27
27
  isJoinParentField
@@ -216,7 +216,7 @@ function useFairysValtioFormItemAttrs(props) {
216
216
  };
217
217
  }
218
218
  function useFairysValtioFormItemNoStyleAttrs(props) {
219
- const { name, valuePropName = 'value', getValuePath = valuePropName, getValueFromEvent, formatValue, onAfterUpdate, trigger = 'onChange', children, attrs = {}, isJoinParentField = true, rules, isRemoveValueOnUnmount = true, isRequired: _isRequired } = props;
219
+ const { name, valuePropName = 'value', getValuePath = valuePropName, getValueFromEvent, formatValue, onAfterUpdate, trigger = 'onChange', children, attrs = {}, isJoinParentField = true, rules, isRemoveValueOnUnmount = false, isRequired: _isRequired } = props;
220
220
  const [state, errorState, formInstance] = useFairysValtioFormInstanceContextState();
221
221
  const { name: _name, paths, parentName, formAttrsNameInstance } = useFairysValtioFormAttrsName({
222
222
  name,
@@ -295,4 +295,15 @@ function useFairysValtioFormItemNoStyleAttrs(props) {
295
295
  }) : children
296
296
  };
297
297
  }
298
- export { useFairysValtioFormItemAttrs, useFairysValtioFormItemNoStyleAttrs };
298
+ function useFairysValtioFormItemHideAttrs(props) {
299
+ const { name, isJoinParentField = true, isHideRemoveValue = true } = props;
300
+ const [, , formInstance] = useFairysValtioFormInstanceContextState();
301
+ const { name: _name } = useFairysValtioFormAttrsName({
302
+ name,
303
+ isJoinParentField
304
+ });
305
+ useEffect(()=>()=>{
306
+ if (isHideRemoveValue) formInstance.removeValueByPaths(_name);
307
+ }, []);
308
+ }
309
+ export { useFairysValtioFormItemAttrs, useFairysValtioFormItemHideAttrs, useFairysValtioFormItemNoStyleAttrs };
@@ -81,6 +81,8 @@ export interface FairysValtioFormItemAttrsProps<T extends MObject<T> = Record<st
81
81
  * @default true
82
82
  */
83
83
  isRemoveValueOnUnmount?: boolean;
84
+ /**隐藏表单项移除数据*/
85
+ isHideRemoveValue?: boolean;
84
86
  }
85
87
  /**
86
88
  * 处理表单表单项属性
@@ -244,3 +246,7 @@ export interface FairysValtioFormItemNoStyleAttrsReturn<T extends MObject<T> = R
244
246
  /**子元素*/
245
247
  children?: React.ReactNode;
246
248
  }
249
+ /**
250
+ * 处理表单表单项属性,隐藏表单项时移除数据值
251
+ */
252
+ export declare function useFairysValtioFormItemHideAttrs<T extends MObject<T> = Record<string, any>>(props: FairysValtioFormItemAttrsProps<T>): void;
@@ -34,7 +34,8 @@ var __webpack_exports__ = {};
34
34
  __webpack_require__.r(__webpack_exports__);
35
35
  __webpack_require__.d(__webpack_exports__, {
36
36
  useFairysValtioFormItemNoStyleAttrs: ()=>useFairysValtioFormItemNoStyleAttrs,
37
- useFairysValtioFormItemAttrs: ()=>useFairysValtioFormItemAttrs
37
+ useFairysValtioFormItemAttrs: ()=>useFairysValtioFormItemAttrs,
38
+ useFairysValtioFormItemHideAttrs: ()=>useFairysValtioFormItemHideAttrs
38
39
  });
39
40
  const external_react_namespaceObject = require("react");
40
41
  var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
@@ -61,7 +62,7 @@ function useFairysValtioFormItemAttrs(props) {
61
62
  const parent_isInvalidTextRed = layoutAttrs.isInvalidTextRed;
62
63
  const parent_showColon = layoutAttrs.showColon;
63
64
  const parent_platform = layoutAttrs.platform;
64
- const { name, valuePropName = 'value', getValuePath = valuePropName, getValueFromEvent, formatValue, onAfterUpdate, trigger = 'onChange', className, style, labelClassName, labelStyle, bodyClassName, bodyStyle, children, labelMode = parent_labelMode, errorLayout = parent_errorLayout, colSpan = 1, rowSpan = 1, isRequired: _isRequired, itemBorderType = parent_borderedType, attrs = {}, showColon = parent_showColon, itemBorderColor = parent_itemBorderColor, isInvalidBorderRed = parent_isInvalidBorderRed, isInvalidTextRed = parent_isInvalidTextRed, isJoinParentField = true, rules, platform = parent_platform, isRemoveValueOnUnmount = true } = props;
65
+ const { name, valuePropName = 'value', getValuePath = valuePropName, getValueFromEvent, formatValue, onAfterUpdate, trigger = 'onChange', className, style, labelClassName, labelStyle, bodyClassName, bodyStyle, children, labelMode = parent_labelMode, errorLayout = parent_errorLayout, colSpan = 1, rowSpan = 1, isRequired: _isRequired, itemBorderType = parent_borderedType, attrs = {}, showColon = parent_showColon, itemBorderColor = parent_itemBorderColor, isInvalidBorderRed = parent_isInvalidBorderRed, isInvalidTextRed = parent_isInvalidTextRed, isJoinParentField = true, rules, platform = parent_platform, isRemoveValueOnUnmount = false } = props;
65
66
  const { name: _name, paths, parentName, formAttrsNameInstance } = (0, hooks_index_js_namespaceObject.useFairysValtioFormAttrsName)({
66
67
  name,
67
68
  isJoinParentField
@@ -256,7 +257,7 @@ function useFairysValtioFormItemAttrs(props) {
256
257
  };
257
258
  }
258
259
  function useFairysValtioFormItemNoStyleAttrs(props) {
259
- const { name, valuePropName = 'value', getValuePath = valuePropName, getValueFromEvent, formatValue, onAfterUpdate, trigger = 'onChange', children, attrs = {}, isJoinParentField = true, rules, isRemoveValueOnUnmount = true, isRequired: _isRequired } = props;
260
+ const { name, valuePropName = 'value', getValuePath = valuePropName, getValueFromEvent, formatValue, onAfterUpdate, trigger = 'onChange', children, attrs = {}, isJoinParentField = true, rules, isRemoveValueOnUnmount = false, isRequired: _isRequired } = props;
260
261
  const [state, errorState, formInstance] = (0, index_js_namespaceObject.useFairysValtioFormInstanceContextState)();
261
262
  const { name: _name, paths, parentName, formAttrsNameInstance } = (0, hooks_index_js_namespaceObject.useFairysValtioFormAttrsName)({
262
263
  name,
@@ -335,10 +336,23 @@ function useFairysValtioFormItemNoStyleAttrs(props) {
335
336
  }) : children
336
337
  };
337
338
  }
339
+ function useFairysValtioFormItemHideAttrs(props) {
340
+ const { name, isJoinParentField = true, isHideRemoveValue = true } = props;
341
+ const [, , formInstance] = (0, index_js_namespaceObject.useFairysValtioFormInstanceContextState)();
342
+ const { name: _name } = (0, hooks_index_js_namespaceObject.useFairysValtioFormAttrsName)({
343
+ name,
344
+ isJoinParentField
345
+ });
346
+ (0, external_react_namespaceObject.useEffect)(()=>()=>{
347
+ if (isHideRemoveValue) formInstance.removeValueByPaths(_name);
348
+ }, []);
349
+ }
338
350
  exports.useFairysValtioFormItemAttrs = __webpack_exports__.useFairysValtioFormItemAttrs;
351
+ exports.useFairysValtioFormItemHideAttrs = __webpack_exports__.useFairysValtioFormItemHideAttrs;
339
352
  exports.useFairysValtioFormItemNoStyleAttrs = __webpack_exports__.useFairysValtioFormItemNoStyleAttrs;
340
353
  for(var __webpack_i__ in __webpack_exports__)if (-1 === [
341
354
  "useFairysValtioFormItemAttrs",
355
+ "useFairysValtioFormItemHideAttrs",
342
356
  "useFairysValtioFormItemNoStyleAttrs"
343
357
  ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
344
358
  Object.defineProperty(exports, '__esModule', {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "SunLxy <1011771396@qq.com>",
4
4
  "description": "使用 valtio 实现的表单基础库, 使其更加便捷,同时支持`PC`、`H5`、`Taro`,同时也更加灵活。",
5
5
  "homepage": "https://github.com/autumn-fairy-tales/valtio-form-basic",
6
- "version": "1.0.1",
6
+ "version": "1.0.2",
7
7
  "main": "lib/index.js",
8
8
  "types": "esm/index.d.ts",
9
9
  "module": "esm/index.js",
@@ -85,6 +85,8 @@ export interface FairysValtioFormItemAttrsProps<T extends MObject<T> = Record<st
85
85
  * @default true
86
86
  */
87
87
  isRemoveValueOnUnmount?: boolean;
88
+ /**隐藏表单项移除数据*/
89
+ isHideRemoveValue?: boolean;
88
90
  }
89
91
 
90
92
  /**
@@ -179,7 +181,7 @@ export function useFairysValtioFormItemAttrs<T extends MObject<T> = Record<strin
179
181
  isJoinParentField = true,
180
182
  rules,
181
183
  platform = parent_platform,
182
- isRemoveValueOnUnmount = true,
184
+ isRemoveValueOnUnmount = false,
183
185
  } = props;
184
186
 
185
187
  const {
@@ -537,7 +539,7 @@ export function useFairysValtioFormItemNoStyleAttrs<T extends MObject<T> = Recor
537
539
  attrs = {},
538
540
  isJoinParentField = true,
539
541
  rules,
540
- isRemoveValueOnUnmount = true,
542
+ isRemoveValueOnUnmount = false,
541
543
  isRequired: _isRequired,
542
544
  } = props;
543
545
  const [state, errorState, formInstance] = useFairysValtioFormInstanceContextState<T>();
@@ -670,3 +672,21 @@ export interface FairysValtioFormItemNoStyleAttrsReturn<T extends MObject<T> = R
670
672
  /**子元素*/
671
673
  children?: React.ReactNode;
672
674
  }
675
+
676
+ /**
677
+ * 处理表单表单项属性,隐藏表单项时移除数据值
678
+ */
679
+ export function useFairysValtioFormItemHideAttrs<T extends MObject<T> = Record<string, any>>(
680
+ props: FairysValtioFormItemAttrsProps<T>,
681
+ ) {
682
+ const { name, isJoinParentField = true, isHideRemoveValue = true } = props;
683
+ const [, , formInstance] = useFairysValtioFormInstanceContextState<T>();
684
+ const { name: _name } = useFairysValtioFormAttrsName({ name, isJoinParentField });
685
+ useEffect(() => {
686
+ return () => {
687
+ if (isHideRemoveValue) {
688
+ formInstance.removeValueByPaths(_name);
689
+ }
690
+ };
691
+ }, []);
692
+ }