eee18f5e1b1053587dc6ef5eb770a7ef.json 15.5 KB
{"ast":null,"code":"import _extends from \"@babel/runtime/helpers/esm/extends\";\nimport _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport _objectWithoutProperties from \"@babel/runtime/helpers/esm/objectWithoutProperties\";\nimport * as React from 'react';\nimport useForm from './useForm';\nimport FieldContext, { HOOK_MARK } from './FieldContext';\nimport FormContext from './FormContext';\nimport { isSimilar } from './utils/valueUtil';\n\nvar Form = function Form(_ref, ref) {\n  var name = _ref.name,\n      initialValues = _ref.initialValues,\n      fields = _ref.fields,\n      form = _ref.form,\n      preserve = _ref.preserve,\n      children = _ref.children,\n      _ref$component = _ref.component,\n      Component = _ref$component === void 0 ? 'form' : _ref$component,\n      validateMessages = _ref.validateMessages,\n      _ref$validateTrigger = _ref.validateTrigger,\n      validateTrigger = _ref$validateTrigger === void 0 ? 'onChange' : _ref$validateTrigger,\n      onValuesChange = _ref.onValuesChange,\n      _onFieldsChange = _ref.onFieldsChange,\n      _onFinish = _ref.onFinish,\n      onFinishFailed = _ref.onFinishFailed,\n      restProps = _objectWithoutProperties(_ref, [\"name\", \"initialValues\", \"fields\", \"form\", \"preserve\", \"children\", \"component\", \"validateMessages\", \"validateTrigger\", \"onValuesChange\", \"onFieldsChange\", \"onFinish\", \"onFinishFailed\"]);\n\n  var formContext = React.useContext(FormContext); // We customize handle event since Context will makes all the consumer re-render:\n  // https://reactjs.org/docs/context.html#contextprovider\n\n  var _useForm = useForm(form),\n      _useForm2 = _slicedToArray(_useForm, 1),\n      formInstance = _useForm2[0];\n\n  var _formInstance$getInte = formInstance.getInternalHooks(HOOK_MARK),\n      useSubscribe = _formInstance$getInte.useSubscribe,\n      setInitialValues = _formInstance$getInte.setInitialValues,\n      setCallbacks = _formInstance$getInte.setCallbacks,\n      setValidateMessages = _formInstance$getInte.setValidateMessages,\n      setPreserve = _formInstance$getInte.setPreserve; // Pass ref with form instance\n\n\n  React.useImperativeHandle(ref, function () {\n    return formInstance;\n  }); // Register form into Context\n\n  React.useEffect(function () {\n    formContext.registerForm(name, formInstance);\n    return function () {\n      formContext.unregisterForm(name);\n    };\n  }, [formContext, formInstance, name]); // Pass props to store\n\n  setValidateMessages(_objectSpread(_objectSpread({}, formContext.validateMessages), validateMessages));\n  setCallbacks({\n    onValuesChange: onValuesChange,\n    onFieldsChange: function onFieldsChange(changedFields) {\n      formContext.triggerFormChange(name, changedFields);\n\n      if (_onFieldsChange) {\n        for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {\n          rest[_key - 1] = arguments[_key];\n        }\n\n        _onFieldsChange.apply(void 0, [changedFields].concat(rest));\n      }\n    },\n    onFinish: function onFinish(values) {\n      formContext.triggerFormFinish(name, values);\n\n      if (_onFinish) {\n        _onFinish(values);\n      }\n    },\n    onFinishFailed: onFinishFailed\n  });\n  setPreserve(preserve); // Set initial value, init store value when first mount\n\n  var mountRef = React.useRef(null);\n  setInitialValues(initialValues, !mountRef.current);\n\n  if (!mountRef.current) {\n    mountRef.current = true;\n  } // Prepare children by `children` type\n\n\n  var childrenNode = children;\n  var childrenRenderProps = typeof children === 'function';\n\n  if (childrenRenderProps) {\n    var values = formInstance.getFieldsValue(true);\n    childrenNode = children(values, formInstance);\n  } // Not use subscribe when using render props\n\n\n  useSubscribe(!childrenRenderProps); // Listen if fields provided. We use ref to save prev data here to avoid additional render\n\n  var prevFieldsRef = React.useRef();\n  React.useEffect(function () {\n    if (!isSimilar(prevFieldsRef.current || [], fields || [])) {\n      formInstance.setFields(fields || []);\n    }\n\n    prevFieldsRef.current = fields;\n  }, [fields, formInstance]);\n  var formContextValue = React.useMemo(function () {\n    return _objectSpread(_objectSpread({}, formInstance), {}, {\n      validateTrigger: validateTrigger\n    });\n  }, [formInstance, validateTrigger]);\n  var wrapperNode = /*#__PURE__*/React.createElement(FieldContext.Provider, {\n    value: formContextValue\n  }, childrenNode);\n\n  if (Component === false) {\n    return wrapperNode;\n  }\n\n  return /*#__PURE__*/React.createElement(Component, _extends({}, restProps, {\n    onSubmit: function onSubmit(event) {\n      event.preventDefault();\n      event.stopPropagation();\n      formInstance.submit();\n    }\n  }), wrapperNode);\n};\n\nexport default Form;","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/node_modules/rc-field-form/es/Form.js"],"names":["_extends","_objectSpread","_slicedToArray","_objectWithoutProperties","React","useForm","FieldContext","HOOK_MARK","FormContext","isSimilar","Form","_ref","ref","name","initialValues","fields","form","preserve","children","_ref$component","component","Component","validateMessages","_ref$validateTrigger","validateTrigger","onValuesChange","_onFieldsChange","onFieldsChange","_onFinish","onFinish","onFinishFailed","restProps","formContext","useContext","_useForm","_useForm2","formInstance","_formInstance$getInte","getInternalHooks","useSubscribe","setInitialValues","setCallbacks","setValidateMessages","setPreserve","useImperativeHandle","useEffect","registerForm","unregisterForm","changedFields","triggerFormChange","_len","arguments","length","rest","Array","_key","apply","concat","values","triggerFormFinish","mountRef","useRef","current","childrenNode","childrenRenderProps","getFieldsValue","prevFieldsRef","setFields","formContextValue","useMemo","wrapperNode","createElement","Provider","value","onSubmit","event","preventDefault","stopPropagation","submit"],"mappings":"AAAA,OAAOA,QAAP,MAAqB,oCAArB;AACA,OAAOC,aAAP,MAA0B,0CAA1B;AACA,OAAOC,cAAP,MAA2B,0CAA3B;AACA,OAAOC,wBAAP,MAAqC,oDAArC;AACA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,OAAOC,YAAP,IAAuBC,SAAvB,QAAwC,gBAAxC;AACA,OAAOC,WAAP,MAAwB,eAAxB;AACA,SAASC,SAAT,QAA0B,mBAA1B;;AAEA,IAAIC,IAAI,GAAG,SAASA,IAAT,CAAcC,IAAd,EAAoBC,GAApB,EAAyB;AAClC,MAAIC,IAAI,GAAGF,IAAI,CAACE,IAAhB;AAAA,MACIC,a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eAAe5D,IAAf","sourcesContent":["import _extends from \"@babel/runtime/helpers/esm/extends\";\nimport _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport _objectWithoutProperties from \"@babel/runtime/helpers/esm/objectWithoutProperties\";\nimport * as React from 'react';\nimport useForm from './useForm';\nimport FieldContext, { HOOK_MARK } from './FieldContext';\nimport FormContext from './FormContext';\nimport { isSimilar } from './utils/valueUtil';\n\nvar Form = function Form(_ref, ref) {\n  var name = _ref.name,\n      initialValues = _ref.initialValues,\n      fields = _ref.fields,\n      form = _ref.form,\n      preserve = _ref.preserve,\n      children = _ref.children,\n      _ref$component = _ref.component,\n      Component = _ref$component === void 0 ? 'form' : _ref$component,\n      validateMessages = _ref.validateMessages,\n      _ref$validateTrigger = _ref.validateTrigger,\n      validateTrigger = _ref$validateTrigger === void 0 ? 'onChange' : _ref$validateTrigger,\n      onValuesChange = _ref.onValuesChange,\n      _onFieldsChange = _ref.onFieldsChange,\n      _onFinish = _ref.onFinish,\n      onFinishFailed = _ref.onFinishFailed,\n      restProps = _objectWithoutProperties(_ref, [\"name\", \"initialValues\", \"fields\", \"form\", \"preserve\", \"children\", \"component\", \"validateMessages\", \"validateTrigger\", \"onValuesChange\", \"onFieldsChange\", \"onFinish\", \"onFinishFailed\"]);\n\n  var formContext = React.useContext(FormContext); // We customize handle event since Context will makes all the consumer re-render:\n  // https://reactjs.org/docs/context.html#contextprovider\n\n  var _useForm = useForm(form),\n      _useForm2 = _slicedToArray(_useForm, 1),\n      formInstance = _useForm2[0];\n\n  var _formInstance$getInte = formInstance.getInternalHooks(HOOK_MARK),\n      useSubscribe = _formInstance$getInte.useSubscribe,\n      setInitialValues = _formInstance$getInte.setInitialValues,\n      setCallbacks = _formInstance$getInte.setCallbacks,\n      setValidateMessages = _formInstance$getInte.setValidateMessages,\n      setPreserve = _formInstance$getInte.setPreserve; // Pass ref with form instance\n\n\n  React.useImperativeHandle(ref, function () {\n    return formInstance;\n  }); // Register form into Context\n\n  React.useEffect(function () {\n    formContext.registerForm(name, formInstance);\n    return function () {\n      formContext.unregisterForm(name);\n    };\n  }, [formContext, formInstance, name]); // Pass props to store\n\n  setValidateMessages(_objectSpread(_objectSpread({}, formContext.validateMessages), validateMessages));\n  setCallbacks({\n    onValuesChange: onValuesChange,\n    onFieldsChange: function onFieldsChange(changedFields) {\n      formContext.triggerFormChange(name, changedFields);\n\n      if (_onFieldsChange) {\n        for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {\n          rest[_key - 1] = arguments[_key];\n        }\n\n        _onFieldsChange.apply(void 0, [changedFields].concat(rest));\n      }\n    },\n    onFinish: function onFinish(values) {\n      formContext.triggerFormFinish(name, values);\n\n      if (_onFinish) {\n        _onFinish(values);\n      }\n    },\n    onFinishFailed: onFinishFailed\n  });\n  setPreserve(preserve); // Set initial value, init store value when first mount\n\n  var mountRef = React.useRef(null);\n  setInitialValues(initialValues, !mountRef.current);\n\n  if (!mountRef.current) {\n    mountRef.current = true;\n  } // Prepare children by `children` type\n\n\n  var childrenNode = children;\n  var childrenRenderProps = typeof children === 'function';\n\n  if (childrenRenderProps) {\n    var values = formInstance.getFieldsValue(true);\n    childrenNode = children(values, formInstance);\n  } // Not use subscribe when using render props\n\n\n  useSubscribe(!childrenRenderProps); // Listen if fields provided. We use ref to save prev data here to avoid additional render\n\n  var prevFieldsRef = React.useRef();\n  React.useEffect(function () {\n    if (!isSimilar(prevFieldsRef.current || [], fields || [])) {\n      formInstance.setFields(fields || []);\n    }\n\n    prevFieldsRef.current = fields;\n  }, [fields, formInstance]);\n  var formContextValue = React.useMemo(function () {\n    return _objectSpread(_objectSpread({}, formInstance), {}, {\n      validateTrigger: validateTrigger\n    });\n  }, [formInstance, validateTrigger]);\n  var wrapperNode = /*#__PURE__*/React.createElement(FieldContext.Provider, {\n    value: formContextValue\n  }, childrenNode);\n\n  if (Component === false) {\n    return wrapperNode;\n  }\n\n  return /*#__PURE__*/React.createElement(Component, _extends({}, restProps, {\n    onSubmit: function onSubmit(event) {\n      event.preventDefault();\n      event.stopPropagation();\n      formInstance.submit();\n    }\n  }), wrapperNode);\n};\n\nexport default Form;"]},"metadata":{},"sourceType":"module"}