@topthink/chat 1.0.34 → 1.0.35
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/es/index.js +1 -1
- package/package.json +2 -2
package/es/index.js
CHANGED
|
@@ -511,7 +511,7 @@ import*as e from"react";import{useCallback as t,useState as r,useRef as n,useImp
|
|
|
511
511
|
`};
|
|
512
512
|
`,Ee=[".txt",".md",".pdf",".docx",".xlsx",".pptx",".png",".jpg"];function Fe(e){let{variables:t,values:r,onSubmit:n,onChange:o,children:i}=e;const a={},s=[],l={};return t.forEach((e=>{a[e.key]={type:"string",title:e.label},"textarea"===e.type?l[e.key]={"ui:widget":"textarea"}:"select"===e.type&&e.options&&(a[e.key].enum=e.options,a[e.key].enumNames=e.options,e.options.length>0&&(a[e.key].default=e.options[0])),e.required&&s.push(e.key)})),z(j,{schema:{type:"object",properties:a,required:s},formData:r,omitExtraData:!0,uiSchema:l,submitText:"开始对话",onSubmit:n,onChange:o,children:i})}function Se(e){let{chat:o,fileTypes:i,scrollRef:a,onMessages:s,onSuggestions:l,variables:c,minRows:d,toolbar:g,disabled:f,onLoading:b,autoFocus:v}=e;const x=n(null),k=n(null),[w,j]=r(""),[$,q]=h([]),[C,E]=r(!1),F=i&&i.length>0?i:Ee,{loading:S,messages:D,suggestions:R,send:T}=H({...o,onSuccess(){requestAnimationFrame((()=>{x.current?.focus()})),o.onSuccess?.()}}),[_,B]=r((()=>{const e=D.filter((e=>!!e.query));if(e.length>0){return e[e.length-1].variables}}));m((()=>{s(D)}),[D]),m((()=>{l(R)}),[R]),m((()=>{b?.(S)}),[S]),m((()=>{!i&&$.length>0&&q([])}),[i]),m((()=>{const e=a.current;if(e&&T){const t=e=>{e.target instanceof HTMLAnchorElement&&"#!question"===e.target.hash&&(e.preventDefault(),T(e.target.text))};return e.addEventListener("click",t),()=>{e.removeEventListener("click",t)}}}),[a,T]);const O=t((e=>{let{target:t}=e;if(t.files){const e=Array.from(t.files).filter((e=>!!F.includes(L.extname(e.name))&&(!(e.size>20971520)&&e))).slice(0,6-$.length);q((t=>{t.push(...e.map((e=>({file:e}))))})),e.forEach((async e=>{try{const t=new FormData;t.set("file",e);let r={method:"POST",url:`${o.url}/upload`,data:t};o.transformRequest&&(r=o.transformRequest("upload",r));const n=await u(r);q((t=>{const r=t.find((t=>t.file===e));r&&(r.path=n.path)}))}catch(t){const r=p(t)?t.message:"unknown error";q((t=>{const n=t.find((t=>t.file===e));n&&(n.error=r)}))}}))}t.value=""}),[$,F]),P=$.flatMap((e=>{let{file:t,path:r}=e;return r?[{name:t.name,size:t.size,path:r}]:[]})),I=()=>{(w||P.length>0)&&(c?T(w,P,{..._,...c.values}):T(w,P),j(""),q([]))};if(c){const e=c.config.filter((e=>!(e.key in(c.values||{})))),t=function(t){let r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return!!t&&e.every((e=>{const n=!e.required||t?.[e.key];return!n&&r&&N.error("请完善必填信息"),n}))};if(e.length>0&&!t(_))return z(Re,{children:z(De,{children:z(Fe,{values:_,variables:e,onSubmit:e=>{let{formData:r}=e;if(t(r,!0))return B(r),!0}})})})}return M(Ae,{children:[g,M(Oe,{$focused:C&&!S,children:[$.length>0&&z(_e,{children:$.map(((e,t)=>{let{file:r,error:n,path:o}=e;const i=void 0===n&&void 0===o;return z(Te,{name:r.name,size:r.size,error:n,loading:i,onRemove:()=>{q((e=>{const t=e.findIndex((e=>e.file===r));-1!==t&&e.splice(t,1)}))}},t)}))}),M(Le,{children:[z(A,{disabled:S||f,ref:x,placeholder:"请输入你的问题, Enter+Shift换行, Enter发送",minRows:d,maxRows:5,value:w,onChange:e=>j(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),I())},autoFocus:v,onFocus:()=>E(!0),onBlur:()=>E(!1)}),i&&z(y,{tooltip:"可上传不超过6个小于20MB的文件",placement:"top",children:M(Be,{disabled:$.length>=6,onClick:()=>k.current?.click(),children:[z("input",{onChange:O,multiple:!0,accept:F.join(","),ref:k,type:"file",hidden:!0}),z("i",{className:"bi bi-file-earmark-arrow-up"})]})}),z(Be,{className:"text-primary",disabled:!w&&0===P.length,onClick:e=>{e.preventDefault(),I()},children:z("i",{className:"bi bi-send-fill"})})]})]})]})}const De=f.div`
|
|
513
513
|
border-radius: var(--bs-border-radius-lg);
|
|
514
|
-
box-shadow:
|
|
514
|
+
box-shadow: var(--bs-box-shadow-sm);
|
|
515
515
|
margin: 1rem;
|
|
516
516
|
padding: 1rem;
|
|
517
517
|
width: 100%;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@topthink/chat",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.35",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prebuild": "rimraf es types",
|
|
6
6
|
"build": "rollup -c --environment NODE_ENV:production",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
},
|
|
66
66
|
"author": "yunwuxin <tzzhangyajun@qq.com> (https://github.com/yunwuxin)",
|
|
67
67
|
"license": "MIT",
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "72fc8ffdf592b98c9230a1a2f5bb352dc084c578"
|
|
69
69
|
}
|