b9135e17f9915fc2be5e8c31623be0d8.json
15.1 KB
{"ast":null,"code":"import _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport * as React from 'react';\nimport warning from \"rc-util/es/warning\";\nimport FieldContext from './FieldContext';\nimport Field from './Field';\nimport { move as _move, getNamePath } from './utils/valueUtil';\n\nvar List = function List(_ref) {\n var name = _ref.name,\n initialValue = _ref.initialValue,\n children = _ref.children,\n rules = _ref.rules,\n validateTrigger = _ref.validateTrigger;\n var context = React.useContext(FieldContext);\n var keyRef = React.useRef({\n keys: [],\n id: 0\n });\n var keyManager = keyRef.current; // User should not pass `children` as other type.\n\n if (typeof children !== 'function') {\n warning(false, 'Form.List only accepts function as children.');\n return null;\n }\n\n var parentPrefixName = getNamePath(context.prefixName) || [];\n var prefixName = [].concat(_toConsumableArray(parentPrefixName), _toConsumableArray(getNamePath(name)));\n\n var shouldUpdate = function shouldUpdate(prevValue, nextValue, _ref2) {\n var source = _ref2.source;\n\n if (source === 'internal') {\n return false;\n }\n\n return prevValue !== nextValue;\n };\n\n return /*#__PURE__*/React.createElement(FieldContext.Provider, {\n value: _objectSpread(_objectSpread({}, context), {}, {\n prefixName: prefixName\n })\n }, /*#__PURE__*/React.createElement(Field, {\n name: [],\n shouldUpdate: shouldUpdate,\n rules: rules,\n validateTrigger: validateTrigger,\n initialValue: initialValue,\n isList: true\n }, function (_ref3, meta) {\n var _ref3$value = _ref3.value,\n value = _ref3$value === void 0 ? [] : _ref3$value,\n onChange = _ref3.onChange;\n var getFieldValue = context.getFieldValue;\n\n var getNewValue = function getNewValue() {\n var values = getFieldValue(prefixName || []);\n return values || [];\n };\n /**\n * Always get latest value in case user update fields by `form` api.\n */\n\n\n var operations = {\n add: function add(defaultValue, index) {\n // Mapping keys\n var newValue = getNewValue();\n\n if (index >= 0 && index <= newValue.length) {\n keyManager.keys = [].concat(_toConsumableArray(keyManager.keys.slice(0, index)), [keyManager.id], _toConsumableArray(keyManager.keys.slice(index)));\n onChange([].concat(_toConsumableArray(newValue.slice(0, index)), [defaultValue], _toConsumableArray(newValue.slice(index))));\n } else {\n if (process.env.NODE_ENV !== 'production' && (index < 0 || index > newValue.length)) {\n warning(false, 'The second parameter of the add function should be a valid positive number.');\n }\n\n keyManager.keys = [].concat(_toConsumableArray(keyManager.keys), [keyManager.id]);\n onChange([].concat(_toConsumableArray(newValue), [defaultValue]));\n }\n\n keyManager.id += 1;\n },\n remove: function remove(index) {\n var newValue = getNewValue();\n var indexSet = new Set(Array.isArray(index) ? index : [index]);\n\n if (indexSet.size <= 0) {\n return;\n }\n\n keyManager.keys = keyManager.keys.filter(function (_, keysIndex) {\n return !indexSet.has(keysIndex);\n }); // Trigger store change\n\n onChange(newValue.filter(function (_, valueIndex) {\n return !indexSet.has(valueIndex);\n }));\n },\n move: function move(from, to) {\n if (from === to) {\n return;\n }\n\n var newValue = getNewValue(); // Do not handle out of range\n\n if (from < 0 || from >= newValue.length || to < 0 || to >= newValue.length) {\n return;\n }\n\n keyManager.keys = _move(keyManager.keys, from, to); // Trigger store change\n\n onChange(_move(newValue, from, to));\n }\n };\n var listValue = value || [];\n\n if (!Array.isArray(listValue)) {\n listValue = [];\n\n if (process.env.NODE_ENV !== 'production') {\n warning(false, \"Current value of '\".concat(prefixName.join(' > '), \"' is not an array type.\"));\n }\n }\n\n return children(listValue.map(function (__, index) {\n var key = keyManager.keys[index];\n\n if (key === undefined) {\n keyManager.keys[index] = keyManager.id;\n key = keyManager.keys[index];\n keyManager.id += 1;\n }\n\n return {\n name: index,\n key: key,\n isListField: true\n };\n }), operations, meta);\n }));\n};\n\nexport default List;","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/node_modules/rc-field-form/es/List.js"],"names":["_objectSpread","_toConsumableArray","React","warning","FieldContext","Field","move","_move","getNamePath","List","_ref","name","initialValue","children","rules","validateTrigger","context","useContext","keyRef","useRef","keys","id","keyManager","current","parentPrefixName","prefixName","concat","shouldUpdate","prevValue","nextValue","_ref2","source","createElement","Provider","value","isList","_ref3","meta","_ref3$value","onChange","getFieldValue","getNewValue","values","operations","add","defaultValue","index","newValue","length","slice","process","env","NODE_ENV","remove","indexSet","Set","Array","isArray","size","filter","_","keysIndex","has","valueIndex","from","to","listValue","join","map","__","key","undefined","isListField"],"mappings":"AAAA,OAAOA,aAAP,MAA0B,0CAA1B;AACA,OAAOC,kBAAP,MAA+B,8CAA/B;AACA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA,OAAOC,OAAP,MAAoB,oBAApB;AACA,OAAOC,YAAP,MAAyB,gBAAzB;AACA,OAAOC,KAAP,MAAkB,SAAlB;AACA,SAASC,IAAI,IAAIC,KAAjB,EAAwBC,WAAxB,QAA2C,mBAA3C;;AAEA,IAAIC,IAAI,GAAG,SAASA,IAAT,CAAcC,IAAd,EAAoB;AAC7B,MAAIC,IAAI,GAAGD,IAAI,CAACC,IAAhB;AAAA,MACIC,YAAY,GAAGF,IAAI,CAACE,YADxB;AAAA,MAEIC,QAAQ,GAAGH,IAAI,CAACG,QAFpB;AAAA,MAGIC,KAAK,GAAGJ,IAAI,CAACI,KAHjB;AAAA,MAIIC,eAAe,GAAGL,IAAI,CAACK,eAJ3B;AAKA,MAAIC,OAAO,GAAGd,KAAK,CAACe,UAAN,CAAiBb,YAAjB,CAAd;AACA,MAAIc,MAAM,GAAGhB,KAAK,CAACiB,MAAN,CAAa;AACxBC,IAAAA,IAAI,EAAE,EADkB;AAExBC,IAAAA,EAAE,EAAE;AAFoB,GAAb,CAAb;AAIA,MAAIC,UAAU,GAAGJ,MAAM,CAACK,OAAxB,CAX6B,CAWI;;AAEjC,MAAI,OAAOV,QAAP,KAAoB,UAAxB,EAAoC;AAClCV,IAAAA,OAAO,CAAC,KAAD,EAAQ,8CAAR,CAAP;AACA,WAAO,IAAP;AACD;;AAED,MAAIqB,gBAAgB,GAAGhB,WAAW,CAACQ,OAAO,CAACS,UAAT,C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5B,IAAf","sourcesContent":["import _objectSpread from \"@babel/runtime/helpers/esm/objectSpread2\";\nimport _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport * as React from 'react';\nimport warning from \"rc-util/es/warning\";\nimport FieldContext from './FieldContext';\nimport Field from './Field';\nimport { move as _move, getNamePath } from './utils/valueUtil';\n\nvar List = function List(_ref) {\n var name = _ref.name,\n initialValue = _ref.initialValue,\n children = _ref.children,\n rules = _ref.rules,\n validateTrigger = _ref.validateTrigger;\n var context = React.useContext(FieldContext);\n var keyRef = React.useRef({\n keys: [],\n id: 0\n });\n var keyManager = keyRef.current; // User should not pass `children` as other type.\n\n if (typeof children !== 'function') {\n warning(false, 'Form.List only accepts function as children.');\n return null;\n }\n\n var parentPrefixName = getNamePath(context.prefixName) || [];\n var prefixName = [].concat(_toConsumableArray(parentPrefixName), _toConsumableArray(getNamePath(name)));\n\n var shouldUpdate = function shouldUpdate(prevValue, nextValue, _ref2) {\n var source = _ref2.source;\n\n if (source === 'internal') {\n return false;\n }\n\n return prevValue !== nextValue;\n };\n\n return /*#__PURE__*/React.createElement(FieldContext.Provider, {\n value: _objectSpread(_objectSpread({}, context), {}, {\n prefixName: prefixName\n })\n }, /*#__PURE__*/React.createElement(Field, {\n name: [],\n shouldUpdate: shouldUpdate,\n rules: rules,\n validateTrigger: validateTrigger,\n initialValue: initialValue,\n isList: true\n }, function (_ref3, meta) {\n var _ref3$value = _ref3.value,\n value = _ref3$value === void 0 ? [] : _ref3$value,\n onChange = _ref3.onChange;\n var getFieldValue = context.getFieldValue;\n\n var getNewValue = function getNewValue() {\n var values = getFieldValue(prefixName || []);\n return values || [];\n };\n /**\n * Always get latest value in case user update fields by `form` api.\n */\n\n\n var operations = {\n add: function add(defaultValue, index) {\n // Mapping keys\n var newValue = getNewValue();\n\n if (index >= 0 && index <= newValue.length) {\n keyManager.keys = [].concat(_toConsumableArray(keyManager.keys.slice(0, index)), [keyManager.id], _toConsumableArray(keyManager.keys.slice(index)));\n onChange([].concat(_toConsumableArray(newValue.slice(0, index)), [defaultValue], _toConsumableArray(newValue.slice(index))));\n } else {\n if (process.env.NODE_ENV !== 'production' && (index < 0 || index > newValue.length)) {\n warning(false, 'The second parameter of the add function should be a valid positive number.');\n }\n\n keyManager.keys = [].concat(_toConsumableArray(keyManager.keys), [keyManager.id]);\n onChange([].concat(_toConsumableArray(newValue), [defaultValue]));\n }\n\n keyManager.id += 1;\n },\n remove: function remove(index) {\n var newValue = getNewValue();\n var indexSet = new Set(Array.isArray(index) ? index : [index]);\n\n if (indexSet.size <= 0) {\n return;\n }\n\n keyManager.keys = keyManager.keys.filter(function (_, keysIndex) {\n return !indexSet.has(keysIndex);\n }); // Trigger store change\n\n onChange(newValue.filter(function (_, valueIndex) {\n return !indexSet.has(valueIndex);\n }));\n },\n move: function move(from, to) {\n if (from === to) {\n return;\n }\n\n var newValue = getNewValue(); // Do not handle out of range\n\n if (from < 0 || from >= newValue.length || to < 0 || to >= newValue.length) {\n return;\n }\n\n keyManager.keys = _move(keyManager.keys, from, to); // Trigger store change\n\n onChange(_move(newValue, from, to));\n }\n };\n var listValue = value || [];\n\n if (!Array.isArray(listValue)) {\n listValue = [];\n\n if (process.env.NODE_ENV !== 'production') {\n warning(false, \"Current value of '\".concat(prefixName.join(' > '), \"' is not an array type.\"));\n }\n }\n\n return children(listValue.map(function (__, index) {\n var key = keyManager.keys[index];\n\n if (key === undefined) {\n keyManager.keys[index] = keyManager.id;\n key = keyManager.keys[index];\n keyManager.id += 1;\n }\n\n return {\n name: index,\n key: key,\n isListField: true\n };\n }), operations, meta);\n }));\n};\n\nexport default List;"]},"metadata":{},"sourceType":"module"}