@flatbiz/antd 4.2.101 → 4.2.103
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/drag-editable-table/index.css +0 -0
- package/esm/drag-editable-table/index.js +28 -0
- package/esm/drag-editable-table/index.js.map +1 -0
- package/esm/drag-table/index.js +1 -1
- package/esm/drag-table/index.js.map +1 -1
- package/esm/file-import/index.js.map +1 -1
- package/esm/index.js +13 -10
- package/esm/json-editor/index.css +0 -0
- package/esm/json-editor/index.js +5 -0
- package/esm/json-editor/index.js.map +1 -0
- package/esm/rich-text-editor/index.js +1 -1
- package/esm/rich-text-editor/index.js.map +1 -1
- package/esm/rich-text-viewer/index.js +1 -1
- package/esm/rich-text-viewer/index.js.map +1 -1
- package/esm/search-form/index.css +0 -0
- package/esm/search-form/index.js +5 -0
- package/esm/search-form/index.js.map +1 -0
- package/esm/search-menu/index.js +4 -1
- package/esm/search-menu/index.js.map +1 -1
- package/esm/table-cell-render/index.css +1 -1
- package/esm/table-cell-render/index.js +1 -1
- package/esm/table-cell-render/index.js.map +1 -1
- package/esm/table-scrollbar/index.js +1 -1
- package/esm/table-scrollbar/index.js.map +1 -1
- package/esm/text-css-ellipsis/index.js.map +1 -1
- package/esm/text-overflow/index.css +1 -0
- package/esm/text-overflow/index.js +6 -0
- package/esm/text-overflow/index.js.map +1 -0
- package/esm/text-overflow-render/index.js.map +1 -1
- package/esm/upload-wrapper/index.js +1 -1
- package/esm/upload-wrapper/index.js.map +1 -1
- package/index.d.ts +1046 -794
- package/package.json +4 -3
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
import './../fba-hooks/index.css';
|
|
3
3
|
import './index.css';
|
|
4
4
|
/*! @flatjs/forge MIT @flatbiz/antd */
|
|
5
|
-
import r from"@ant-design/icons/es/icons/PlusOutlined";import{a as e,_ as i}from"../_rollupPluginBabelHelpers-a0769acd.js";import{classNames as n}from"@dimjs/utils/cjs/class-names";import{hooks as t}from"@wove/react/cjs/hooks";import{isPlainObject as a}from"@dimjs/lang/cjs/is-plain-object";import{extend as
|
|
5
|
+
import r from"@ant-design/icons/es/icons/PlusOutlined";import{a as e,_ as i}from"../_rollupPluginBabelHelpers-a0769acd.js";import{classNames as n}from"@dimjs/utils/cjs/class-names";import{hooks as t}from"@wove/react/cjs/hooks";import{isPlainObject as a}from"@dimjs/lang/cjs/is-plain-object";import{extend as o}from"@dimjs/utils/cjs/extend";import{isUndefinedOrNull as s,toArray as u}from"@flatbiz/utils";import{message as l,Upload as d,Button as f}from"antd";import{useState as m,useMemo as c,Fragment as p}from"react";import{flushSync as v}from"react-dom";import{fbaHooks as g}from"../fba-hooks/index.js";import{jsx as h,jsxs as x}from"react/jsx-runtime";import"@dimjs/lang/cjs/is-array";import"../use-responsive-point-21b8c601.js";var j=["onChange","onUploadError","value","triggerText","limitHidden","autoSubmit"];var C=function r(f){var p=f.onChange,x=f.onUploadError,C=f.value,y=f.triggerText,b=f.limitHidden,O=f.autoSubmit,R=e(f,j);var U=s(C)?undefined:u(C);var E=m(),k=E[0],D=E[1];var H=o({uid:"uid",name:"name",url:"url"},f.fieldNames);g.useEffectCustom((function(){var r=(k==null?void 0:k.filter((function(r){return r["status"]==="error"})))||[];var e=(U==null?void 0:U.map((function(r){return{uid:r[H.uid],name:r[H.name],url:r[H.url],status:"done",isOriginal:true,responseData:r["responseData"]}})))||[];if(r.length>0){var i=r.map((function(r){return{uid:r.uid,name:r.name,status:"error",isOriginal:true,response:r["response"]}}));e=e.concat(i)}D(e)}),[H.name,H.uid,H.url,U]);var L=function r(e){var i=[];var n=false;e.forEach((function(r){if(r["isOriginal"]){if(r["status"]!=="error"){var e;i.push((e={},e[H.uid]=r.uid,e[H.name]=r.name,e[H.url]=r.url,e))}}else if(a(r.response)){if(r.response.code==="0000"){var t;var o=r.response.data;var s=(f.onRequestResultAdapter==null?void 0:f.onRequestResultAdapter(o))||o;i.push((t={},t[H.uid]=s[H.uid]||r.uid,t[H.name]=s[H.name]||r.name,t[H.url]=s[H.url],t.responseData=o,t))}else{var u=r.response.message||"上传失败";n=true;r.status="error";r.response=r.response.message||"上传失败";if(x){x==null?void 0:x(u)}else{void l.error("上传操作失败...")}}}}));if(n){D([].concat(e))}p==null?void 0:p(i)};var N=t.useCallbackRef((function(r){var e=r.fileList;if(r.file.status==="done"){var i=[].concat(r.fileList);var n=i.filter((function(r){return r.status==="done"||r["isOriginal"]}));var t=n.length===i.length;if(t){L(i)}v((function(){return D(i)}));return}else if(r.file.status==="removed"){var a=r.file.uid;var o=U!==undefined?[].concat(U):[];var s=o.findIndex((function(r){var e=r[H.uid];return e===a}));if(s>=0){o.splice(s,1)}p==null?void 0:p(o)}else if(r.file.status==="error"){if(x){x()}else{void l.error("上传操作失败...")}}D([].concat(e));f.onUploadChange==null?void 0:f.onUploadChange(r)}));var q=c((function(){if(R.maxCount===undefined||!b)return false;if(R.maxCount===0)return true;if(k&&k.length>=R.maxCount)return true;return false}),[b,R.maxCount,k]);var w=function r(e,i){if(O===false){var n=[].concat(k||[],i);D(n);f.onChange==null?void 0:f.onChange(n);return false}return true};return h(d,i({beforeUpload:w},R,{onChange:N,fileList:k,className:n("v-upload-wrapper",R.className),children:R.disabled||q?null:h(T,{triggerText:y,listType:R.listType,children:f.children})}))};var T=function e(i){if(i.children)return h(p,{children:i.children});if(i.listType==="picture-card"){return x("div",{children:[h(r,{}),h("div",{style:{marginTop:8},children:i.triggerText||"上传图片"})]})}if(i.listType==="picture"){return h(f,{type:"primary",ghost:true,children:i.triggerText||"选择图片上传"})}return h(f,{type:"primary",ghost:true,children:i.triggerText||"选择文件上传"})};export{C as UploadWrapper};
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["@flatbiz/antd/src/upload-wrapper/upload-wrapper.tsx"],"sourcesContent":["import { PlusOutlined } from '@ant-design/icons';\nimport { isPlainObject } from '@dimjs/lang';\nimport { classNames, extend } from '@dimjs/utils';\nimport { isUndefinedOrNull, TAny, toArray, TPlainObject } from '@flatbiz/utils';\nimport { hooks } from '@wove/react';\nimport { Button, message, Upload, UploadProps } from 'antd';\nimport { UploadChangeParam } from 'antd/lib/upload';\nimport { UploadFile, UploadListType } from 'antd/lib/upload/interface';\nimport { Fragment, ReactNode, useMemo, useState } from 'react';\nimport { flushSync } from 'react-dom';\nimport { fbaHooks } from '../fba-hooks';\nimport './style.less';\n\nexport type UploadWrapperFileItem = {\n uid: string;\n name: string;\n url?: string;\n};\n\nexport type UploadWrapperProps<T extends TPlainObject = TPlainObject> = {\n value?: T[] | T;\n onChange?: (value?: T[]) => void;\n onUploadError?: (message?: string) => void;\n onUploadChange?: (info: UploadChangeParam<UploadFile>) => void;\n /**\n * 属性映射\n */\n fieldNames?: {\n uid: string;\n name?: string;\n url?: string;\n };\n /**\n * 接口响应数据适配器,如果配置了fieldNames,适配器返回值会再进过fieldNames转换\n */\n onRequestResultAdapter?: (respData: TAny) => TPlainObject;\n /** 操作触发显示文本 */\n triggerText?: string;\n /** 超过maxCount 隐藏上传入口 */\n limitHidden?: boolean;\n} & Omit<UploadProps, 'onChange' | 'fileList'>;\n\n/**\n * 文件上传\n * ```\n * 1. 可通过配置children替换默认上传触发布局\n * 2. 接口返回结构:\n * formData上传接口返回值\n * {\n * code: '0000',\n * data: {\n * uid: '唯一值,可使用fileKey值'\n * name: '文件名称'\n * url: '预览地址'\n * }\n * }\n * 3. 如果接口返回的不是上面的字段名称,可通过fieldNames配置接口返回字段名称映射\n *\n * 4. 最佳使用方式,与Form结合使用\n * <Form.Item name=\"attachmentList\" label=\"附件\">\n * <UploadWrapper action={uploadUrl} />\n * </Form.Item>\n * ```\n *\n */\nexport const UploadWrapper = (props: UploadWrapperProps) => {\n const { onChange, onUploadError, value, triggerText, limitHidden, ...otherProps } = props;\n const valueList = isUndefinedOrNull(value) ? undefined : toArray<TPlainObject>(value);\n const [uploadList, setUploadList] = useState<UploadWrapperFileItem[]>();\n const fieldNames = extend(\n {\n uid: 'uid',\n name: 'name',\n url: 'url',\n },\n props.fieldNames,\n ) as Required<UploadWrapperFileItem>;\n\n fbaHooks.useEffectCustom(() => {\n const errorList = uploadList?.filter((item) => item['status'] === 'error') || [];\n let newList =\n valueList?.map((item) => {\n return {\n uid: item[fieldNames.uid],\n name: item[fieldNames.name],\n url: item[fieldNames.url],\n status: 'done',\n isOriginal: true,\n responseData: item['responseData'],\n };\n }) || [];\n if (errorList.length > 0) {\n const newErrorList = errorList.map((item) => {\n return {\n uid: item.uid,\n name: item.name,\n status: 'error',\n isOriginal: true,\n response: item['response'],\n };\n }) as TAny[];\n newList = newList.concat(newErrorList);\n }\n setUploadList(newList);\n }, [fieldNames.name, fieldNames.uid, fieldNames.url, valueList]);\n\n const handleResponse = (fileList: UploadFile<TAny>[]) => {\n const newFileList: TAny[] = [];\n let hasError = false;\n fileList.forEach((item) => {\n if (item['isOriginal']) {\n if (item['status'] !== 'error') {\n newFileList.push({\n [fieldNames.uid]: item.uid,\n [fieldNames.name]: item.name,\n [fieldNames.url]: item.url,\n });\n }\n } else if (isPlainObject(item.response)) {\n if (item.response.code === '0000') {\n const respData = item.response.data;\n const result = (props.onRequestResultAdapter?.(respData) || respData) as TPlainObject;\n newFileList.push({\n [fieldNames.uid]: result[fieldNames.uid] || item.uid,\n [fieldNames.name]: result[fieldNames.name] || item.name,\n [fieldNames.url]: result[fieldNames.url],\n responseData: respData,\n });\n } else {\n const errorMsg = item.response.message || '上传失败';\n hasError = true;\n item.status = 'error';\n item.response = item.response.message || '上传失败';\n if (onUploadError) {\n onUploadError?.(errorMsg);\n } else {\n void message.error('上传操作失败...');\n }\n }\n }\n });\n if (hasError) {\n setUploadList([...fileList] as UploadWrapperFileItem[]);\n }\n onChange?.(newFileList);\n };\n\n const onUploadChange = hooks.useCallbackRef((info) => {\n const fileList = info.fileList as TPlainObject[];\n if (info.file.status === 'done') {\n const newFileList = [...info.fileList];\n const donwList = newFileList.filter((item) => item.status === 'done' || item['isOriginal']);\n\n const allDone = donwList.length === newFileList.length;\n if (allDone) {\n handleResponse(newFileList);\n }\n flushSync(() => setUploadList(newFileList));\n return;\n } else if (info.file.status === 'removed') {\n const uid = info.file.uid;\n const targetList = valueList !== undefined ? [...valueList] : [];\n const targetIndex = targetList.findIndex((item) => {\n const tempUid = item[fieldNames.uid];\n return tempUid === uid;\n });\n if (targetIndex >= 0) {\n targetList.splice(targetIndex, 1);\n }\n onChange?.(targetList);\n } else if (info.file.status === 'error') {\n if (onUploadError) {\n onUploadError();\n } else {\n void message.error('上传操作失败...');\n }\n }\n // https://github.com/ant-design/ant-design/issues/2423\n setUploadList([...fileList] as UploadWrapperFileItem[]);\n props.onUploadChange?.(info);\n });\n\n const hiddenEmtry = useMemo(() => {\n if (otherProps.maxCount === undefined || !limitHidden) return false;\n if (otherProps.maxCount === 0) return true;\n if (uploadList && uploadList.length >= otherProps.maxCount) return true;\n return false;\n }, [limitHidden, otherProps.maxCount, uploadList]);\n\n return (\n <Upload\n {...otherProps}\n onChange={onUploadChange}\n fileList={uploadList}\n className={classNames('v-upload-wrapper', otherProps.className)}\n >\n {otherProps.disabled || hiddenEmtry ? null : (\n <UploadTrigger triggerText={triggerText} listType={otherProps.listType}>\n {props.children}\n </UploadTrigger>\n )}\n </Upload>\n );\n};\n\nconst UploadTrigger = (props: {\n listType?: UploadListType;\n children?: ReactNode | ReactNode[];\n triggerText?: string;\n}) => {\n if (props.children) return <Fragment>{props.children}</Fragment>;\n if (props.listType === 'picture-card') {\n return (\n <div>\n <PlusOutlined />\n <div style={{ marginTop: 8 }}>{props.triggerText || '上传图片'}</div>\n </div>\n );\n }\n if (props.listType === 'picture') {\n return (\n <Button type=\"primary\" ghost>\n {props.triggerText || '选择图片上传'}\n </Button>\n );\n }\n return (\n <Button type=\"primary\" ghost>\n {props.triggerText || '选择文件上传'}\n </Button>\n );\n};\n"],"names":["UploadWrapper","props","onChange","onUploadError","value","triggerText","limitHidden","otherProps","_objectWithoutPropertiesLoose","_excluded","valueList","isUndefinedOrNull","undefined","toArray","_useState","useState","uploadList","setUploadList","fieldNames","_extend","uid","name","url","fbaHooks","useEffectCustom","errorList","filter","item","newList","map","status","isOriginal","responseData","length","newErrorList","response","concat","handleResponse","fileList","newFileList","hasError","forEach","_newFileList$push","push","_isPlainObject","code","_newFileList$push2","respData","data","result","onRequestResultAdapter","errorMsg","message","error","onUploadChange","_hooks","useCallbackRef","info","file","donwList","allDone","flushSync","targetList","targetIndex","findIndex","tempUid","splice","hiddenEmtry","useMemo","maxCount","_jsx","Upload","_extends","className","_classNames","children","disabled","UploadTrigger","listType","Fragment","_jsxs","_PlusOutlined","style","marginTop","Button","type","ghost"],"mappings":";wyBAiEaA,EAAgB,SAAhBA,EAAiBC,GAC5B,IAAQC,EAA4ED,EAA5EC,SAAUC,EAAkEF,EAAlEE,cAAeC,EAAmDH,EAAnDG,MAAOC,EAA4CJ,EAA5CI,YAAaC,EAA+BL,EAA/BK,YAAgBC,EAAUC,EAAKP,EAAKQ,GACzF,IAAMC,EAAYC,EAAkBP,GAASQ,UAAYC,EAAsBT,GAC/E,IAAAU,EAAoCC,IAA7BC,EAAUF,EAAA,GAAEG,EAAaH,EAAA,GAChC,IAAMI,EAAaC,EACjB,CACEC,IAAK,MACLC,KAAM,OACNC,IAAK,OAEPrB,EAAMiB,YAGRK,EAASC,iBAAgB,WACvB,IAAMC,GAAYT,GAAU,UAAA,EAAVA,EAAYU,QAAO,SAACC,GAAI,OAAKA,EAAK,YAAc,OAAO,MAAK,GAC9E,IAAIC,GACFlB,GAAS,UAAA,EAATA,EAAWmB,KAAI,SAACF,GACd,MAAO,CACLP,IAAKO,EAAKT,EAAWE,KACrBC,KAAMM,EAAKT,EAAWG,MACtBC,IAAKK,EAAKT,EAAWI,KACrBQ,OAAQ,OACRC,WAAY,KACZC,aAAcL,EAAK,gBAEtB,MAAK,GACR,GAAIF,EAAUQ,OAAS,EAAG,CACxB,IAAMC,EAAeT,EAAUI,KAAI,SAACF,GACl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AaC,EAAW8D,SAAUrD,IAEtC,OACEsD,EAACC,EAAMC,KACDjE,EAAU,CACdL,SAAUoD,EACVhB,SAAUtB,EACVyD,UAAWC,EAAW,mBAAoBnE,EAAWkE,WAAWE,SAE/DpE,EAAWqE,UAAYT,EAAc,KACpCG,EAACO,EAAa,CAACxE,YAAaA,EAAayE,SAAUvE,EAAWuE,SAASH,SACpE1E,EAAM0E,aAKjB,EAEA,IAAME,EAAgB,SAAhBA,EAAiB5E,GAKrB,GAAIA,EAAM0E,SAAU,OAAOL,EAACS,EAAQ,CAAAJ,SAAE1E,EAAM0E,WAC5C,GAAI1E,EAAM6E,WAAa,eAAgB,CACrC,OACEE,EAAA,MAAA,CAAAL,UACEL,EAAAW,EAAe,CAAA,GACfX,EAAA,MAAA,CAAKY,MAAO,CAAEC,UAAW,GAAIR,SAAE1E,EAAMI,aAAe,WAG1D,CACA,GAAIJ,EAAM6E,WAAa,UAAW,CAChC,OACER,EAACc,EAAM,CAACC,KAAK,UAAUC,MAAK,KAAAX,SACzB1E,EAAMI,aAAe,UAG5B,CACA,OACEiE,EAACc,EAAM,CAACC,KAAK,UAAUC,MAAK,KAAAX,SACzB1E,EAAMI,aAAe,UAG5B"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["@flatbiz/antd/src/upload-wrapper/upload-wrapper.tsx"],"sourcesContent":["import { PlusOutlined } from '@ant-design/icons';\nimport { isPlainObject } from '@dimjs/lang';\nimport { classNames, extend } from '@dimjs/utils';\nimport { isUndefinedOrNull, TAny, toArray, TPlainObject } from '@flatbiz/utils';\nimport { hooks } from '@wove/react';\nimport { Button, message, Upload, UploadProps } from 'antd';\nimport { UploadChangeParam } from 'antd/lib/upload';\nimport { UploadFile, UploadListType } from 'antd/lib/upload/interface';\nimport { Fragment, ReactNode, useMemo, useState } from 'react';\nimport { flushSync } from 'react-dom';\nimport { fbaHooks } from '../fba-hooks';\nimport './style.less';\n\nexport type UploadWrapperFileItem = {\n uid: string;\n name: string;\n url?: string;\n};\n\nexport type UploadWrapperProps<T extends TPlainObject = TPlainObject> = {\n value?: T[] | T;\n onChange?: (value?: T[]) => void;\n onUploadError?: (message?: string) => void;\n onUploadChange?: (info: UploadChangeParam<UploadFile>) => void;\n /**\n * 属性取值映射\n */\n fieldNames?: {\n uid: string;\n name?: string;\n url?: string;\n };\n /**\n * 接口响应数据适配器,如果配置了fieldNames,适配器返回值会再进过fieldNames转换\n */\n onRequestResultAdapter?: (respData: TAny) => TPlainObject;\n /** 操作触发显示文本 */\n triggerText?: string;\n /** 超过maxCount 隐藏上传入口 */\n limitHidden?: boolean;\n /**\n * 自动提交,默认:true\n * ```\n * 1. 自定义beforeUpload配置后 autoSubmit 失效\n * ```\n */\n autoSubmit?: boolean;\n} & Omit<UploadProps, 'onChange' | 'fileList'>;\n\n/**\n * 文件上传\n * ```\n * 1. 可通过配置children替换默认上传触发布局\n * 2. 接口返回结构:\n * formData上传接口返回值\n * {\n * code: '0000',\n * data: {\n * uid: '唯一值,可使用fileKey值'\n * name: '文件名称'\n * url: '预览地址'\n * }\n * }\n * 3. 如果接口返回的不是上面的字段名称,可通过fieldNames配置接口返回字段名称映射\n *\n * 4. 最佳使用方式,与Form结合使用\n * <Form.Item name=\"attachmentList\" label=\"附件\">\n * <UploadWrapper action={uploadUrl} />\n * </Form.Item>\n * ```\n *\n */\nexport const UploadWrapper = (props: UploadWrapperProps) => {\n const { onChange, onUploadError, value, triggerText, limitHidden, autoSubmit, ...otherProps } = props;\n const valueList = isUndefinedOrNull(value) ? undefined : toArray<TPlainObject>(value);\n const [uploadList, setUploadList] = useState<UploadWrapperFileItem[]>();\n const fieldNames = extend(\n {\n uid: 'uid',\n name: 'name',\n url: 'url',\n },\n props.fieldNames,\n ) as Required<UploadWrapperFileItem>;\n\n fbaHooks.useEffectCustom(() => {\n const errorList = uploadList?.filter((item) => item['status'] === 'error') || [];\n let newList =\n valueList?.map((item) => {\n return {\n uid: item[fieldNames.uid],\n name: item[fieldNames.name],\n url: item[fieldNames.url],\n status: 'done',\n isOriginal: true,\n responseData: item['responseData'],\n };\n }) || [];\n if (errorList.length > 0) {\n const newErrorList = errorList.map((item) => {\n return {\n uid: item.uid,\n name: item.name,\n status: 'error',\n isOriginal: true,\n response: item['response'],\n };\n }) as TAny[];\n newList = newList.concat(newErrorList);\n }\n setUploadList(newList);\n }, [fieldNames.name, fieldNames.uid, fieldNames.url, valueList]);\n\n const handleResponse = (fileList: UploadFile<TAny>[]) => {\n const newFileList: TAny[] = [];\n let hasError = false;\n fileList.forEach((item) => {\n if (item['isOriginal']) {\n if (item['status'] !== 'error') {\n newFileList.push({\n [fieldNames.uid]: item.uid,\n [fieldNames.name]: item.name,\n [fieldNames.url]: item.url,\n });\n }\n } else if (isPlainObject(item.response)) {\n if (item.response.code === '0000') {\n const respData = item.response.data;\n const result = (props.onRequestResultAdapter?.(respData) || respData) as TPlainObject;\n newFileList.push({\n [fieldNames.uid]: result[fieldNames.uid] || item.uid,\n [fieldNames.name]: result[fieldNames.name] || item.name,\n [fieldNames.url]: result[fieldNames.url],\n responseData: respData,\n });\n } else {\n const errorMsg = item.response.message || '上传失败';\n hasError = true;\n item.status = 'error';\n item.response = item.response.message || '上传失败';\n if (onUploadError) {\n onUploadError?.(errorMsg);\n } else {\n void message.error('上传操作失败...');\n }\n }\n }\n });\n if (hasError) {\n setUploadList([...fileList] as UploadWrapperFileItem[]);\n }\n onChange?.(newFileList);\n };\n\n const onUploadChange = hooks.useCallbackRef((info) => {\n const fileList = info.fileList as TPlainObject[];\n if (info.file.status === 'done') {\n const newFileList = [...info.fileList];\n const donwList = newFileList.filter((item) => item.status === 'done' || item['isOriginal']);\n\n const allDone = donwList.length === newFileList.length;\n if (allDone) {\n handleResponse(newFileList);\n }\n flushSync(() => setUploadList(newFileList));\n return;\n } else if (info.file.status === 'removed') {\n const uid = info.file.uid;\n const targetList = valueList !== undefined ? [...valueList] : [];\n const targetIndex = targetList.findIndex((item) => {\n const tempUid = item[fieldNames.uid];\n return tempUid === uid;\n });\n if (targetIndex >= 0) {\n targetList.splice(targetIndex, 1);\n }\n onChange?.(targetList);\n } else if (info.file.status === 'error') {\n if (onUploadError) {\n onUploadError();\n } else {\n void message.error('上传操作失败...');\n }\n }\n // https://github.com/ant-design/ant-design/issues/2423\n setUploadList([...fileList] as UploadWrapperFileItem[]);\n props.onUploadChange?.(info);\n });\n\n const hiddenEmtry = useMemo(() => {\n if (otherProps.maxCount === undefined || !limitHidden) return false;\n if (otherProps.maxCount === 0) return true;\n if (uploadList && uploadList.length >= otherProps.maxCount) return true;\n return false;\n }, [limitHidden, otherProps.maxCount, uploadList]);\n\n const beforeUpload = (_file, fileList) => {\n if (autoSubmit === false) {\n const mergeList = [...(uploadList || []), ...fileList];\n setUploadList(mergeList);\n props.onChange?.(mergeList);\n return false;\n }\n return true;\n };\n\n return (\n <Upload\n beforeUpload={beforeUpload}\n {...otherProps}\n onChange={onUploadChange}\n fileList={uploadList}\n className={classNames('v-upload-wrapper', otherProps.className)}\n >\n {otherProps.disabled || hiddenEmtry ? null : (\n <UploadTrigger triggerText={triggerText} listType={otherProps.listType}>\n {props.children}\n </UploadTrigger>\n )}\n </Upload>\n );\n};\n\nconst UploadTrigger = (props: {\n listType?: UploadListType;\n children?: ReactNode | ReactNode[];\n triggerText?: string;\n}) => {\n if (props.children) return <Fragment>{props.children}</Fragment>;\n if (props.listType === 'picture-card') {\n return (\n <div>\n <PlusOutlined />\n <div style={{ marginTop: 8 }}>{props.triggerText || '上传图片'}</div>\n </div>\n );\n }\n if (props.listType === 'picture') {\n return (\n <Button type=\"primary\" ghost>\n {props.triggerText || '选择图片上传'}\n </Button>\n );\n }\n return (\n <Button type=\"primary\" ghost>\n {props.triggerText || '选择文件上传'}\n </Button>\n );\n};\n"],"names":["UploadWrapper","props","onChange","onUploadError","value","triggerText","limitHidden","autoSubmit","otherProps","_objectWithoutPropertiesLoose","_excluded","valueList","isUndefinedOrNull","undefined","toArray","_useState","useState","uploadList","setUploadList","fieldNames","_extend","uid","name","url","fbaHooks","useEffectCustom","errorList","filter","item","newList","map","status","isOriginal","responseData","length","newErrorList","response","concat","handleResponse","fileList","newFileList","hasError","forEach","_newFileList$push","push","_isPlainObject","code","_newFileList$push2","respData","data","result","onRequestResultAdapter","errorMsg","message","error","onUploadChange","_hooks","useCallbackRef","info","file","donwList","allDone","flushSync","targetList","targetIndex","findIndex","tempUid","splice","hiddenEmtry","useMemo","maxCount","beforeUpload","_file","mergeList","_jsx","Upload","_extends","className","_classNames","children","disabled","UploadTrigger","listType","Fragment","_jsxs","_PlusOutlined","style","marginTop","Button","type","ghost"],"mappings":";qzBAwEaA,EAAgB,SAAhBA,EAAiBC,GAC5B,IAAQC,EAAwFD,EAAxFC,SAAUC,EAA8EF,EAA9EE,cAAeC,EAA+DH,EAA/DG,MAAOC,EAAwDJ,EAAxDI,YAAaC,EAA2CL,EAA3CK,YAAaC,EAA8BN,EAA9BM,WAAeC,EAAUC,EAAKR,EAAKS,GACrG,IAAMC,EAAYC,EAAkBR,GAASS,UAAYC,EAAsBV,GAC/E,IAAAW,EAAoCC,IAA7BC,EAAUF,EAAA,GAAEG,EAAaH,EAAA,GAChC,IAAMI,EAAaC,EACjB,CACEC,IAAK,MACLC,KAAM,OACNC,IAAK,OAEPtB,EAAMkB,YAGRK,EAASC,iBAAgB,WACvB,IAAMC,GAAYT,GAAU,UAAA,EAAVA,EAAYU,QAAO,SAACC,GAAI,OAAKA,EAAK,YAAc,OAAO,MAAK,GAC9E,IAAIC,GACFlB,GAAS,UAAA,EAATA,EAAWmB,KAAI,SAACF,GACd,MAAO,CACLP,IAAKO,EAAKT,EAAWE,KACrBC,KAAMM,EAAKT,EAAWG,MACtBC,IAAKK,EAAKT,EAAWI,KACrBQ,OAAQ,OACRC,WAAY,KACZC,aAAcL,EAAK,gBAEtB,MAAK,GACR,GAAIF,EAAUQ,OAAS,EAAG,CACxB,IAAMC,EAAeT,EAAUI,KAAI,SAACF,GAClC,MAAO,CACLP,IAAKO,EAAKP,IAC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