UNPKG

@iimm/formily-mui

Version:

form field components based on @mui/material and @formily/react

38 lines 2.27 kB
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } var isSameFile = function isSameFile(f1, f2) { return !(f1.name !== f2.name || f1.size !== f2.size || f1.type !== f2.type || f1.lastModified !== f2.lastModified); }; export var updateFileList = function updateFileList(newfile, fileList) { var newFileList = Array.isArray(newfile) ? newfile : newfile ? [newfile] : []; if (!newFileList.length) return null; var nextFileList = _toConsumableArray(fileList || []); var _loop = function _loop() { var file = newFileList[i]; var fileIndex = nextFileList.findIndex(function (item) { return isSameFile(item, file); }); if (fileIndex === -1) { nextFileList.push(file); } else { nextFileList[fileIndex] = file; } }; for (var i = 0; i < newFileList.length; i++) { _loop(); } return nextFileList; }; export var removeFileItem = function removeFileItem(file, fileList) { var newFileList = (fileList || []).filter(function (item) { return !isSameFile(item, file); }); if (newFileList.length === (fileList || []).length) { return null; } return newFileList; };