@aheart-ui/ai 0.0.0-stage → 1.1.0
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/LICENSE +21 -0
- package/README.md +30 -2
- package/es/actions/index.d.ts +2 -0
- package/es/actions/index.js +5 -0
- package/es/actions/style.css +36 -0
- package/es/actions.vue.d.ts +34 -0
- package/es/actions.vue.js +27 -0
- package/es/actions.vue2.js +4 -0
- package/es/agent/index.d.ts +5 -0
- package/es/agent/index.js +12 -0
- package/es/agent/style.css +308 -0
- package/es/agent-execution.vue.d.ts +106 -0
- package/es/agent-execution.vue.js +441 -0
- package/es/agent-execution.vue2.js +4 -0
- package/es/agent-workbench/index.d.ts +2 -0
- package/es/agent-workbench/index.js +5 -0
- package/es/agent-workbench/style.css +1332 -0
- package/es/agent-workbench.vue.d.ts +186 -0
- package/es/agent-workbench.vue.js +537 -0
- package/es/agent-workbench.vue2.js +4 -0
- package/es/attachments/index.d.ts +2 -0
- package/es/attachments/index.js +5 -0
- package/es/attachments/style.css +62 -0
- package/es/attachments.vue.d.ts +39 -0
- package/es/attachments.vue.js +39 -0
- package/es/attachments.vue2.js +4 -0
- package/es/bubble/index.d.ts +2 -0
- package/es/bubble/index.js +5 -0
- package/es/bubble/style.css +241 -0
- package/es/bubble.vue.d.ts +27 -0
- package/es/bubble.vue.js +82 -0
- package/es/bubble.vue2.js +4 -0
- package/es/chat/index.d.ts +11 -0
- package/es/chat/index.js +23 -0
- package/es/chat/style.css +595 -0
- package/es/chat-panel/index.d.ts +3 -0
- package/es/chat-panel/index.js +8 -0
- package/es/chat-panel/style.css +595 -0
- package/es/chat-panel.vue.d.ts +108 -0
- package/es/chat-panel.vue.js +330 -0
- package/es/chat-panel.vue2.js +4 -0
- package/es/conversations/index.d.ts +2 -0
- package/es/conversations/index.js +5 -0
- package/es/conversations/style.css +48 -0
- package/es/conversations.vue.d.ts +39 -0
- package/es/conversations.vue.js +29 -0
- package/es/conversations.vue2.js +4 -0
- package/es/form/index.d.ts +3 -0
- package/es/form/index.js +9 -0
- package/es/form/style.css +242 -0
- package/es/form-field.vue.d.ts +28 -0
- package/es/form-field.vue.js +176 -0
- package/es/form-field.vue2.js +4 -0
- package/es/form-schema.d.ts +73 -0
- package/es/form-schema.js +105 -0
- package/es/form.vue.d.ts +81 -0
- package/es/form.vue.js +376 -0
- package/es/form.vue2.js +4 -0
- package/es/index.d.ts +20 -0
- package/es/index.js +42 -0
- package/es/package.json +3 -0
- package/es/process/index.d.ts +2 -0
- package/es/process/index.js +5 -0
- package/es/process/style.css +77 -0
- package/es/process.vue.d.ts +30 -0
- package/es/process.vue.js +29 -0
- package/es/process.vue2.js +4 -0
- package/es/prompts/index.d.ts +2 -0
- package/es/prompts/index.js +5 -0
- package/es/prompts/style.css +76 -0
- package/es/prompts.vue.d.ts +39 -0
- package/es/prompts.vue.js +33 -0
- package/es/prompts.vue2.js +4 -0
- package/es/safe-markdown.d.ts +3 -0
- package/es/safe-markdown.js +23 -0
- package/es/sender/index.d.ts +2 -0
- package/es/sender/index.js +5 -0
- package/es/sender/style.css +88 -0
- package/es/sender.vue.d.ts +52 -0
- package/es/sender.vue.js +46 -0
- package/es/sender.vue2.js +4 -0
- package/es/sources/index.d.ts +2 -0
- package/es/sources/index.js +5 -0
- package/es/sources/style.css +54 -0
- package/es/sources.vue.d.ts +30 -0
- package/es/sources.vue.js +34 -0
- package/es/sources.vue2.js +4 -0
- package/es/stream-reducer.d.ts +35 -0
- package/es/stream-reducer.js +85 -0
- package/es/style.css +1586 -0
- package/es/thought-chain/index.d.ts +2 -0
- package/es/thought-chain/index.js +5 -0
- package/es/thought-chain/style.css +77 -0
- package/es/thought-chain.vue.d.ts +30 -0
- package/es/thought-chain.vue.js +15 -0
- package/es/thought-chain.vue2.js +4 -0
- package/es/types.d.ts +203 -0
- package/es/welcome/index.d.ts +2 -0
- package/es/welcome/index.js +5 -0
- package/es/welcome/style.css +33 -0
- package/es/welcome.vue.d.ts +41 -0
- package/es/welcome.vue.js +27 -0
- package/es/welcome.vue2.js +4 -0
- package/lib/actions/index.d.ts +2 -0
- package/lib/actions/index.js +1 -0
- package/lib/actions/style.css +36 -0
- package/lib/actions.vue.d.ts +34 -0
- package/lib/actions.vue.js +1 -0
- package/lib/actions.vue2.js +1 -0
- package/lib/agent/index.d.ts +5 -0
- package/lib/agent/index.js +1 -0
- package/lib/agent/style.css +308 -0
- package/lib/agent-execution.vue.d.ts +106 -0
- package/lib/agent-execution.vue.js +1 -0
- package/lib/agent-execution.vue2.js +1 -0
- package/lib/agent-workbench/index.d.ts +2 -0
- package/lib/agent-workbench/index.js +1 -0
- package/lib/agent-workbench/style.css +1332 -0
- package/lib/agent-workbench.vue.d.ts +186 -0
- package/lib/agent-workbench.vue.js +1 -0
- package/lib/agent-workbench.vue2.js +1 -0
- package/lib/attachments/index.d.ts +2 -0
- package/lib/attachments/index.js +1 -0
- package/lib/attachments/style.css +62 -0
- package/lib/attachments.vue.d.ts +39 -0
- package/lib/attachments.vue.js +1 -0
- package/lib/attachments.vue2.js +1 -0
- package/lib/bubble/index.d.ts +2 -0
- package/lib/bubble/index.js +1 -0
- package/lib/bubble/style.css +241 -0
- package/lib/bubble.vue.d.ts +27 -0
- package/lib/bubble.vue.js +1 -0
- package/lib/bubble.vue2.js +1 -0
- package/lib/chat/index.d.ts +11 -0
- package/lib/chat/index.js +1 -0
- package/lib/chat/style.css +595 -0
- package/lib/chat-panel/index.d.ts +3 -0
- package/lib/chat-panel/index.js +1 -0
- package/lib/chat-panel/style.css +595 -0
- package/lib/chat-panel.vue.d.ts +108 -0
- package/lib/chat-panel.vue.js +1 -0
- package/lib/chat-panel.vue2.js +1 -0
- package/lib/conversations/index.d.ts +2 -0
- package/lib/conversations/index.js +1 -0
- package/lib/conversations/style.css +48 -0
- package/lib/conversations.vue.d.ts +39 -0
- package/lib/conversations.vue.js +1 -0
- package/lib/conversations.vue2.js +1 -0
- package/lib/form/index.d.ts +3 -0
- package/lib/form/index.js +1 -0
- package/lib/form/style.css +242 -0
- package/lib/form-field.vue.d.ts +28 -0
- package/lib/form-field.vue.js +1 -0
- package/lib/form-field.vue2.js +1 -0
- package/lib/form-schema.d.ts +73 -0
- package/lib/form-schema.js +1 -0
- package/lib/form.vue.d.ts +81 -0
- package/lib/form.vue.js +1 -0
- package/lib/form.vue2.js +1 -0
- package/lib/index.d.ts +20 -0
- package/lib/index.js +1 -0
- package/lib/package.json +3 -0
- package/lib/process/index.d.ts +2 -0
- package/lib/process/index.js +1 -0
- package/lib/process/style.css +77 -0
- package/lib/process.vue.d.ts +30 -0
- package/lib/process.vue.js +1 -0
- package/lib/process.vue2.js +1 -0
- package/lib/prompts/index.d.ts +2 -0
- package/lib/prompts/index.js +1 -0
- package/lib/prompts/style.css +76 -0
- package/lib/prompts.vue.d.ts +39 -0
- package/lib/prompts.vue.js +1 -0
- package/lib/prompts.vue2.js +1 -0
- package/lib/safe-markdown.d.ts +3 -0
- package/lib/safe-markdown.js +2 -0
- package/lib/sender/index.d.ts +2 -0
- package/lib/sender/index.js +1 -0
- package/lib/sender/style.css +88 -0
- package/lib/sender.vue.d.ts +52 -0
- package/lib/sender.vue.js +1 -0
- package/lib/sender.vue2.js +1 -0
- package/lib/sources/index.d.ts +2 -0
- package/lib/sources/index.js +1 -0
- package/lib/sources/style.css +54 -0
- package/lib/sources.vue.d.ts +30 -0
- package/lib/sources.vue.js +1 -0
- package/lib/sources.vue2.js +1 -0
- package/lib/stream-reducer.d.ts +35 -0
- package/lib/stream-reducer.js +1 -0
- package/lib/style.css +1586 -0
- package/lib/thought-chain/index.d.ts +2 -0
- package/lib/thought-chain/index.js +1 -0
- package/lib/thought-chain/style.css +77 -0
- package/lib/thought-chain.vue.d.ts +30 -0
- package/lib/thought-chain.vue.js +1 -0
- package/lib/thought-chain.vue2.js +1 -0
- package/lib/types.d.ts +203 -0
- package/lib/welcome/index.d.ts +2 -0
- package/lib/welcome/index.js +1 -0
- package/lib/welcome/style.css +33 -0
- package/lib/welcome.vue.d.ts +41 -0
- package/lib/welcome.vue.js +1 -0
- package/lib/welcome.vue2.js +1 -0
- package/package.json +172 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("vue"),de=require("./attachments.vue.js"),ve=require("./bubble.vue.js"),me=require("./conversations.vue.js"),pe=require("./prompts.vue.js"),fe=require("./sender.vue.js"),ge=require("./welcome.vue.js"),be=require("./stream-reducer.js"),ye={class:"aheart-ai-chat-panel","aria-label":"AI 对话"},_e={class:"aheart-ai-chat-panel__surface"},he={key:0,class:"aheart-ai-chat-panel__messages",role:"log","aria-live":"polite","aria-relevant":"additions text"},ke={class:"aheart-ai-chat-panel__message-actions","aria-label":"消息操作"},Ce=["aria-label","onClick"],Be=["disabled","onClick"],Ve=["disabled","onClick"],we=["disabled","onClick"],Ee={key:1,class:"aheart-ai-chat-panel__empty"},xe={class:"aheart-ai-chat-panel__composer"},Ie={key:0,class:"aheart-ai-chat-panel__stream-reconnecting",role:"status","aria-live":"polite"},Ae={key:1,class:"aheart-ai-chat-panel__editing",role:"status"},Ne={class:"aheart-ai-visually-hidden",role:"status","aria-live":"polite"},Se=a.defineComponent({name:"AAIChatPanel",__name:"chat-panel",props:{messages:{default:()=>[]},defaultMessages:{default:()=>[]},transport:{},conversationId:{default:void 0},conversations:{default:()=>[]},activeConversation:{default:void 0},prompts:{default:()=>[]},attachments:{default:()=>[]},welcomeTitle:{default:"你好,我能为你做些什么?"},welcomeDescription:{default:"描述目标、补充上下文,或从建议任务开始。"},disabled:{type:Boolean,default:!1},maxReconnectAttempts:{default:1}},emits:["update:messages","update:activeConversation","update:attachments","send","stop","retry","regenerate","edit","copy","error","stream-status","stream-reject"],setup(p,{emit:Y}){const i=p,l=Y,h=a.getCurrentInstance(),L=e=>Object.prototype.hasOwnProperty.call((h==null?void 0:h.vnode.props)??{},e),z=a.ref(L("messages"));a.onBeforeUpdate(()=>{z.value=L("messages")});const f=()=>z.value,j=a.ref([...i.defaultMessages]),c=a.ref(f()?[...i.messages]:[...j.value]),E=a.ref(""),d=a.ref(!1),y=a.ref(),x=a.ref(),A=a.ref(),R=a.ref(""),k=a.ref("idle");let g=0,Z=0;const B=a.computed(()=>f()?i.messages:j.value),O=a.computed(()=>i.conversationId??i.activeConversation),W=a.computed(()=>{if(k.value==="reconnecting")return"";if(!f()&&d.value&&R.value)return`AI 回复:${R.value}`;const e=[...B.value].reverse().find(s=>s.role==="assistant");return e?e.status==="streaming"?"正在生成":e.status==="stopped"?"已停止生成":e.status==="error"?"生成失败":e.status==="complete"?"已完成生成":"":""}),C=e=>{e==="idle"&&d.value&&(k.value==="streaming"||k.value==="reconnecting")||k.value!==e&&(k.value=e,l("stream-status",e))};a.watch(()=>i.messages,e=>{f()&&!d.value&&(c.value=[...e])},{deep:!0});const M=e=>`${e}-${Date.now()}-${Z++}`,N=e=>{c.value=e,f()||(j.value=e),l("update:messages",e)},q=(e,s)=>{N(c.value.map(t=>t.id===e?{...t,...s}:t))},ee=(e,s,t)=>e==null?void 0:e.map(o=>o.status==="pending"||o.status==="running"?{...o,status:s,...t&&!o.detail?{detail:t}:{}}:o),S=(e,s,t)=>{const o=c.value.find(v=>v.id===e);if(!o)return;const r=s==="complete"?"complete":s==="stopped"?"stopped":"error";q(e,{status:s,...t?{error:t}:{},process:ee(o.process,r,t)}),s==="complete"?C("completed"):s==="stopped"?C("cancelled"):s==="error"&&C("error")},te=(e,s)=>{const t=c.value.find(o=>o.id===e);if(!t)return!1;if(s.type==="text-delta")f()||(R.value=s.delta),q(e,{content:`${t.content}${s.delta}`});else if(s.type==="process"){const o=[...(t.process??[]).filter(r=>r.id!==s.item.id),s.item];q(e,{process:o})}else if(s.type==="sources")q(e,{sources:s.sources});else{if(s.type==="done")return S(e,"complete"),!0;if(s.type==="cancelled")return S(e,"stopped"),!0;if(s.type==="error")return S(e,"error",s.error),l("error",s.error),!0}return!1},F=async(e,s={})=>{var J,Q,X;const t={id:M("assistant"),role:"assistant",content:"",status:"streaming"},o=((Q=(J=h==null?void 0:h.proxy)==null?void 0:J.$el)==null?void 0:Q.ownerDocument)??(typeof document<"u"?document:void 0),r=new(((X=o==null?void 0:o.defaultView)==null?void 0:X.AbortController)??AbortController),v=++g,n=i.transport,$=n&&"version"in n&&n.version==="2",D=M("request");d.value=!0,C("streaming"),y.value=r,x.value=t.id,R.value="",$&&f()?c.value=[...e,t]:N([...e,t]),$&&f()&&l("update:messages",[...e,t]);try{if($){const b={version:"2",requestId:D,messageId:t.id,idempotencyKey:M("idempotency"),conversationId:O.value,messages:e,...s.action&&{action:s.action},...s.messageId&&{targetMessageId:s.messageId}},u=be.createAIStreamReducer({requestId:D,messageId:t.id,maxReconnectAttempts:i.maxReconnectAttempts});let I=n.send(b,r.signal),P=0,U=!1,T=!1;for(;!U;)try{for await(const _ of I){if(v!==g||r.signal.aborted)break;const m=u.dispatch(_);if(m.diagnostic.kind==="protocol-error"){const K=u.failRecovery(`协议错误:${m.diagnostic.reason??"invalid envelope"}`,!1);l("stream-reject",m.diagnostic.reason??"协议错误"),C(K.status),l("error",K.message.error??"协议错误");const ue={...t,...K.message};c.value=[...e,ue],f()?l("update:messages",c.value):N(c.value),T=!0,U=!0;break}C(m.status),(m.status==="completed"||m.status==="cancelled"||m.status==="error")&&(U=!0);const ie={...t,...m.message};if(c.value=[...e,ie],f()?l("update:messages",c.value):N(c.value),!f()&&_.type==="text-delta"&&m.diagnostic.kind==="accepted"&&(R.value=_.delta),m.status==="completed"||m.status==="cancelled"||m.status==="error"){U=!0;break}if(m.recoveryRequired)break}if(v!==g||r.signal.aborted)break;const V=u.getState();if(V.status==="completed"||V.status==="cancelled"||V.status==="error")break;if(T||!("resume"in n)||!n.resume||P>=Math.max(0,Number.isSafeInteger(i.maxReconnectAttempts)?i.maxReconnectAttempts:1)){let _=n.resume?u.recover({reason:T?"protocol":"eof"}):u.failRecovery("连接中断,请重试");_.status==="reconnecting"&&T&&(_=u.failRecovery("协议错误",!1)),C(_.status);const m={...t,..._.message};c.value=[...e,m],f()?l("update:messages",c.value):N(c.value);break}P+=1;const w=u.recover({reason:"eof"});C(w.status),I=n.resume({...b,resume:u.getState().cursor},r.signal)}catch{if(v!==g||r.signal.aborted)break;let w=n.resume?u.recover({reason:"transport"}):u.failRecovery("连接中断,请重试",!0);if(C(w.status),w.status==="error"){const _={...t,...w.message};c.value=[...e,_],f()?l("update:messages",c.value):N(c.value)}if(!("resume"in n)||!n.resume||w.status==="error"||P>=(i.maxReconnectAttempts??1))break;P+=1,I=n.resume({...b,resume:u.getState().cursor},r.signal)}if(v===g&&!r.signal.aborted){const V=u.getState(),w={...t,...V.message};c.value=[...e,w],V.status==="error"&&l("error",V.message.error??"生成失败")}}else{const b=n;for await(const I of b.send({conversationId:O.value,messages:e,...s.action&&{action:s.action},...s.messageId&&{messageId:s.messageId}},r.signal))if(v!==g||r.signal.aborted||te(t.id,I))break;const u=c.value.find(I=>I.id===t.id);(u==null?void 0:u.status)==="streaming"&&v===g&&S(t.id,"complete")}}catch(b){const u=String(b instanceof Error?b.message:b);if(r.signal.aborted||v!==g)return;S(t.id,"error",u),l("error",u)}finally{y.value===r&&(d.value=!1,k.value=B.value.some(b=>b.status==="streaming")?"streaming":"idle",y.value=void 0,x.value=void 0,c.value=[...B.value])}},G=async e=>{const s=(e??E.value).trim();if(!s||d.value||i.disabled)return;if(A.value){const r=A.value,v=[...B.value],n=v.findIndex(D=>D.id===r.id);if(n<0)return;const $={...r,content:s,status:"complete"};E.value="",A.value=void 0,l("edit",r,s),await F([...v.slice(0,n),$],{action:"edit",messageId:r.id});return}const t={id:M("user"),role:"user",content:s,status:"complete",...i.attachments.length&&{attachments:[...i.attachments]}},o=[...B.value,t];E.value="",l("send",s),i.attachments.length&&l("update:attachments",[]),await F(o)},H=async(e,s)=>{if(d.value||i.disabled)return;const t=[...B.value],o=t.findIndex(n=>n.id===e.id);if(o<1)return;const r=t.slice(0,o);[...r].reverse().find(n=>n.role==="user")&&(l(s==="retry"?"retry":"regenerate",e),await F(r,{action:s,messageId:e.id}))},ae=e=>H(e,"retry"),se=e=>H(e,"regenerate"),oe=e=>{d.value||i.disabled||(A.value=e,E.value=e.content)},re=()=>{A.value=void 0,E.value=""},ne=e=>{var t,o,r,v,n;const s=(r=(o=(t=h==null?void 0:h.proxy)==null?void 0:t.$el)==null?void 0:o.ownerDocument)==null?void 0:r.defaultView;(n=(v=s==null?void 0:s.navigator)==null?void 0:v.clipboard)==null||n.writeText(e.content),l("copy",e)},le=e=>{l("update:attachments",i.attachments.filter(s=>s.id!==e.id))},ce=()=>{g+=1;const e=y.value;x.value&&S(x.value,"stopped"),e==null||e.abort(),y.value=void 0,x.value=void 0,d.value=!1,l("stop")};return a.watch(O,(e,s)=>{var t;e!==s&&(g+=1,(t=y.value)==null||t.abort(),y.value=void 0,x.value=void 0,d.value=!1,k.value="idle")}),a.watch(()=>i.transport,(e,s)=>{var t;e!==s&&(g+=1,(t=y.value)==null||t.abort(),y.value=void 0,x.value=void 0,d.value=!1,k.value="idle")}),a.onBeforeUnmount(()=>{var e;g+=1,(e=y.value)==null||e.abort()}),(e,s)=>(a.openBlock(),a.createElementBlock("section",ye,[p.conversations.length?(a.openBlock(),a.createBlock(me.default,{key:0,"model-value":p.activeConversation,conversations:p.conversations,"onUpdate:modelValue":s[0]||(s[0]=t=>l("update:activeConversation",t))},null,8,["model-value","conversations"])):a.createCommentVNode("",!0),a.createElementVNode("div",_e,[B.value.length?(a.openBlock(),a.createElementBlock("div",he,[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(B.value,t=>(a.openBlock(),a.createBlock(ve.default,{key:t.id,"data-message-id":t.id,message:t},{actions:a.withCtx(()=>[a.createElementVNode("div",ke,[t.content?(a.openBlock(),a.createElementBlock("button",{key:0,type:"button","data-action":"copy","aria-label":`复制${t.role==="user"?"问题":"回答"}`,onClick:o=>ne(t)}," 复制 ",8,Ce)):a.createCommentVNode("",!0),t.role==="user"?(a.openBlock(),a.createElementBlock("button",{key:1,type:"button","data-action":"edit",disabled:p.disabled||d.value,onClick:o=>oe(t)}," 编辑 ",8,Be)):a.createCommentVNode("",!0),t.role==="assistant"&&(t.status==="error"||t.status==="stopped")&&t.retryable!==!1?(a.openBlock(),a.createElementBlock("button",{key:2,type:"button","data-action":"retry",disabled:p.disabled||d.value,onClick:o=>ae(t)}," 重试 ",8,Ve)):a.createCommentVNode("",!0),t.role==="assistant"&&t.status==="complete"?(a.openBlock(),a.createElementBlock("button",{key:3,type:"button","data-action":"regenerate",disabled:p.disabled||d.value,onClick:o=>se(t)}," 重新生成 ",8,we)):a.createCommentVNode("",!0)])]),_:2},1032,["data-message-id","message"]))),128))])):(a.openBlock(),a.createElementBlock("div",Ee,[a.createVNode(ge.default,{title:p.welcomeTitle,description:p.welcomeDescription},null,8,["title","description"]),a.createVNode(pe.default,{prompts:p.prompts,disabled:p.disabled||d.value,onSelect:s[1]||(s[1]=t=>G(t.label))},null,8,["prompts","disabled"])])),a.createElementVNode("div",xe,[k.value==="reconnecting"?(a.openBlock(),a.createElementBlock("p",Ie,"正在恢复连接")):a.createCommentVNode("",!0),A.value?(a.openBlock(),a.createElementBlock("div",Ae,[s[3]||(s[3]=a.createElementVNode("span",null,"正在编辑已发送的问题",-1)),a.createElementVNode("button",{type:"button",onClick:re},"取消编辑")])):a.createCommentVNode("",!0),a.createVNode(de.default,{items:p.attachments,removable:"",onRemove:le},null,8,["items"]),a.createVNode(fe.default,{modelValue:E.value,"onUpdate:modelValue":s[2]||(s[2]=t=>E.value=t),disabled:p.disabled,loading:d.value,onSubmit:G,onStop:ce},null,8,["modelValue","disabled","loading"])])]),a.createElementVNode("p",Ne,a.toDisplayString(W.value),1)]))}});exports.default=Se;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./chat-panel.vue.js");exports.default=e.default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("../conversations.vue.js");exports.AIConversations=e.default;exports.default=e.default;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--aheart-ai-cyan: #0e7490;
|
|
3
|
+
--aheart-ai-cyan-strong: #0e7490;
|
|
4
|
+
--aheart-ai-brand-strong: #0958d9;
|
|
5
|
+
--aheart-ai-cyan-soft: #ecfeff;
|
|
6
|
+
--aheart-ai-line: #e4e7ec;
|
|
7
|
+
--aheart-ai-surface: #ffffff;
|
|
8
|
+
--aheart-ai-surface-subtle: #f8fafc;
|
|
9
|
+
--aheart-ai-text: #182230;
|
|
10
|
+
--aheart-ai-text-secondary: #667085;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.aheart-ai-conversations {
|
|
14
|
+
display: grid;
|
|
15
|
+
gap: 8px;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.aheart-ai-conversations button {
|
|
19
|
+
min-block-size: 36px;
|
|
20
|
+
padding: 7px 9px;
|
|
21
|
+
border: 1px solid transparent;
|
|
22
|
+
border-radius: 5px;
|
|
23
|
+
background: transparent;
|
|
24
|
+
color: var(--aheart-ai-text-secondary);
|
|
25
|
+
font: inherit;
|
|
26
|
+
text-align: left;
|
|
27
|
+
cursor: pointer;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.aheart-ai-conversations button:hover,
|
|
31
|
+
.aheart-ai-conversations button:focus-visible {
|
|
32
|
+
background: #f2f4f7;
|
|
33
|
+
color: var(--aheart-ai-text);
|
|
34
|
+
outline: none;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.aheart-ai-conversations button.is-active {
|
|
38
|
+
border-color: #b2ddff;
|
|
39
|
+
background: #eff8ff;
|
|
40
|
+
color: #175cd3;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@media (pointer: coarse) {
|
|
44
|
+
.aheart-ai-conversations button {
|
|
45
|
+
min-block-size: 44px;
|
|
46
|
+
min-inline-size: 44px;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { AIConversation } from './types';
|
|
2
|
+
declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
|
|
3
|
+
modelValue?: string | undefined;
|
|
4
|
+
conversations?: AIConversation[] | undefined;
|
|
5
|
+
}>, {
|
|
6
|
+
modelValue: undefined;
|
|
7
|
+
conversations: () => never[];
|
|
8
|
+
}>>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
9
|
+
"update:modelValue": (key: string) => void;
|
|
10
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
|
|
11
|
+
modelValue?: string | undefined;
|
|
12
|
+
conversations?: AIConversation[] | undefined;
|
|
13
|
+
}>, {
|
|
14
|
+
modelValue: undefined;
|
|
15
|
+
conversations: () => never[];
|
|
16
|
+
}>>> & Readonly<{
|
|
17
|
+
"onUpdate:modelValue"?: ((key: string) => any) | undefined;
|
|
18
|
+
}>, {
|
|
19
|
+
modelValue: string;
|
|
20
|
+
conversations: AIConversation[];
|
|
21
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
22
|
+
export default _default;
|
|
23
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
24
|
+
type __VLS_TypePropsToRuntimeProps<T> = {
|
|
25
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
26
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
27
|
+
} : {
|
|
28
|
+
type: import('vue').PropType<T[K]>;
|
|
29
|
+
required: true;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
type __VLS_WithDefaults<P, D> = {
|
|
33
|
+
[K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
|
|
34
|
+
default: D[K];
|
|
35
|
+
}> : P[K];
|
|
36
|
+
};
|
|
37
|
+
type __VLS_Prettify<T> = {
|
|
38
|
+
[K in keyof T]: T[K];
|
|
39
|
+
} & {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("vue"),o={class:"aheart-ai-conversations","aria-label":"会话列表"},s=["disabled","aria-current","onClick"],i=e.defineComponent({name:"AAIConversations",__name:"conversations",props:{modelValue:{default:void 0},conversations:{default:()=>[]}},emits:["update:modelValue"],setup(a,{emit:l}){const n=l;return(r,u)=>(e.openBlock(),e.createElementBlock("nav",o,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(a.conversations,t=>(e.openBlock(),e.createElementBlock("button",{key:t.key,type:"button",class:e.normalizeClass({"is-active":t.key===a.modelValue}),disabled:t.disabled,"aria-current":t.key===a.modelValue?"page":void 0,onClick:c=>n("update:modelValue",t.key)},e.toDisplayString(t.label),11,s))),128))]))}});exports.default=i;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./conversations.vue.js");exports.default=e.default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const _=require("../form.vue.js"),e=require("../form-schema.js");exports.AIForm=_.default;exports.default=_.default;exports.AI_FORM_CONDITION_OPERATORS=e.AI_FORM_CONDITION_OPERATORS;exports.AI_FORM_FIELD_TYPES=e.AI_FORM_FIELD_TYPES;exports.validateAIFormSchema=e.validateAIFormSchema;
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--aheart-ai-cyan: #0e7490;
|
|
3
|
+
--aheart-ai-cyan-strong: #0e7490;
|
|
4
|
+
--aheart-ai-brand-strong: #0958d9;
|
|
5
|
+
--aheart-ai-cyan-soft: #ecfeff;
|
|
6
|
+
--aheart-ai-line: #e4e7ec;
|
|
7
|
+
--aheart-ai-surface: #ffffff;
|
|
8
|
+
--aheart-ai-surface-subtle: #f8fafc;
|
|
9
|
+
--aheart-ai-text: #182230;
|
|
10
|
+
--aheart-ai-text-secondary: #667085;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.aheart-ai-visually-hidden {
|
|
14
|
+
position: absolute;
|
|
15
|
+
width: 1px;
|
|
16
|
+
height: 1px;
|
|
17
|
+
padding: 0;
|
|
18
|
+
margin: -1px;
|
|
19
|
+
overflow: hidden;
|
|
20
|
+
clip: rect(0, 0, 0, 0);
|
|
21
|
+
white-space: nowrap;
|
|
22
|
+
border: 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.aheart-ai-form {
|
|
26
|
+
box-sizing: border-box;
|
|
27
|
+
color: var(--aheart-color-text, var(--aheart-ai-text));
|
|
28
|
+
letter-spacing: 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.aheart-ai-form * {
|
|
32
|
+
box-sizing: border-box;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.aheart-ai-form {
|
|
36
|
+
display: grid;
|
|
37
|
+
gap: 20px;
|
|
38
|
+
inline-size: min(100%, 760px);
|
|
39
|
+
padding: clamp(18px, 4vw, 32px);
|
|
40
|
+
border: 1px solid var(--aheart-ai-line);
|
|
41
|
+
border-radius: 8px;
|
|
42
|
+
background: var(--aheart-ai-surface);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.aheart-ai-form__header {
|
|
46
|
+
display: grid;
|
|
47
|
+
gap: 5px;
|
|
48
|
+
padding-block-end: 18px;
|
|
49
|
+
border-block-end: 1px solid var(--aheart-ai-line);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.aheart-ai-form__header h2,
|
|
53
|
+
.aheart-ai-form__header p {
|
|
54
|
+
margin: 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.aheart-ai-form__header h2 {
|
|
58
|
+
color: var(--aheart-ai-text);
|
|
59
|
+
font-size: 20px;
|
|
60
|
+
line-height: 1.4;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.aheart-ai-form__header p {
|
|
64
|
+
color: var(--aheart-ai-text-secondary);
|
|
65
|
+
line-height: 1.6;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.aheart-ai-form__group {
|
|
69
|
+
display: grid;
|
|
70
|
+
gap: 16px;
|
|
71
|
+
min-inline-size: 0;
|
|
72
|
+
margin: 0;
|
|
73
|
+
padding: 0;
|
|
74
|
+
border: 0;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
fieldset.aheart-ai-form__group {
|
|
78
|
+
padding-block-start: 16px;
|
|
79
|
+
border-block-start: 1px solid var(--aheart-ai-line);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.aheart-ai-form__group legend {
|
|
83
|
+
display: grid;
|
|
84
|
+
gap: 3px;
|
|
85
|
+
inline-size: 100%;
|
|
86
|
+
padding: 0;
|
|
87
|
+
color: var(--aheart-ai-text);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.aheart-ai-form__group legend span {
|
|
91
|
+
font-weight: 650;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.aheart-ai-form__group legend small,
|
|
95
|
+
.aheart-ai-form__field-description {
|
|
96
|
+
color: var(--aheart-ai-text-secondary);
|
|
97
|
+
font-size: 12px;
|
|
98
|
+
line-height: 1.5;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.aheart-ai-form__field {
|
|
102
|
+
display: grid;
|
|
103
|
+
grid-template-columns: minmax(140px, 190px) minmax(0, 1fr);
|
|
104
|
+
column-gap: 18px;
|
|
105
|
+
row-gap: 6px;
|
|
106
|
+
align-items: start;
|
|
107
|
+
padding: 3px 0;
|
|
108
|
+
border-radius: 5px;
|
|
109
|
+
outline: none;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.aheart-ai-form__field:focus-visible {
|
|
113
|
+
box-shadow: 0 0 0 2px rgba(22, 119, 255, 0.15);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.aheart-ai-form__field > label {
|
|
117
|
+
grid-column: 1;
|
|
118
|
+
grid-row: 1;
|
|
119
|
+
padding-block-start: 7px;
|
|
120
|
+
color: #344054;
|
|
121
|
+
font-weight: 550;
|
|
122
|
+
line-height: 1.5;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
.aheart-ai-form__field-description {
|
|
126
|
+
grid-column: 1;
|
|
127
|
+
grid-row: 2;
|
|
128
|
+
margin: 0;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.aheart-ai-form__field > :not(label):not(.aheart-ai-form__field-description):not(.aheart-ai-form__field-error):not(.aheart-switch) {
|
|
132
|
+
grid-column: 2;
|
|
133
|
+
grid-row: 1 / span 2;
|
|
134
|
+
inline-size: 100%;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
.aheart-ai-form__field > .aheart-switch {
|
|
138
|
+
grid-column: 2;
|
|
139
|
+
grid-row: 1 / span 2;
|
|
140
|
+
justify-self: start;
|
|
141
|
+
inline-size: fit-content;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.aheart-ai-form__required {
|
|
145
|
+
margin-inline-start: 3px;
|
|
146
|
+
color: var(--aheart-color-danger, #d92d20);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.aheart-ai-form__field-error {
|
|
150
|
+
grid-column: 2;
|
|
151
|
+
margin: 0;
|
|
152
|
+
color: var(--aheart-color-danger, #d92d20);
|
|
153
|
+
font-size: 12px;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
.aheart-ai-form__field.is-error {
|
|
157
|
+
padding: 8px;
|
|
158
|
+
background: #fff7f6;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
.aheart-ai-form__error-summary,
|
|
162
|
+
.aheart-ai-form__submit-error,
|
|
163
|
+
.aheart-ai-form__error {
|
|
164
|
+
border-inline-start: 3px solid var(--aheart-color-danger, #d92d20);
|
|
165
|
+
background: #fff7f6;
|
|
166
|
+
color: #912018;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.aheart-ai-form__error-summary {
|
|
170
|
+
display: grid;
|
|
171
|
+
gap: 8px;
|
|
172
|
+
padding: 12px 14px;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.aheart-ai-form__error-summary ul,
|
|
176
|
+
.aheart-ai-form__error ul {
|
|
177
|
+
display: grid;
|
|
178
|
+
gap: 4px;
|
|
179
|
+
margin: 0;
|
|
180
|
+
padding-inline-start: 20px;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.aheart-ai-form__error-summary button {
|
|
184
|
+
padding: 0;
|
|
185
|
+
border: 0;
|
|
186
|
+
background: transparent;
|
|
187
|
+
color: inherit;
|
|
188
|
+
font: inherit;
|
|
189
|
+
text-decoration: underline;
|
|
190
|
+
cursor: pointer;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.aheart-ai-form__submit-error {
|
|
194
|
+
margin: 0;
|
|
195
|
+
padding: 9px 12px;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.aheart-ai-form__footer {
|
|
199
|
+
display: flex;
|
|
200
|
+
justify-content: flex-end;
|
|
201
|
+
padding-block-start: 16px;
|
|
202
|
+
border-block-start: 1px solid var(--aheart-ai-line);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.aheart-ai-form__error {
|
|
206
|
+
display: grid;
|
|
207
|
+
gap: 8px;
|
|
208
|
+
max-inline-size: 760px;
|
|
209
|
+
padding: 16px;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
@media (max-width: 760px) {
|
|
213
|
+
|
|
214
|
+
.aheart-ai-form {
|
|
215
|
+
padding: 18px 14px;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
.aheart-ai-form__field {
|
|
219
|
+
grid-template-columns: minmax(0, 1fr);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.aheart-ai-form__field > label,
|
|
223
|
+
.aheart-ai-form__field-description,
|
|
224
|
+
.aheart-ai-form__field > :not(label):not(.aheart-ai-form__field-description):not(.aheart-ai-form__field-error):not(.aheart-switch),
|
|
225
|
+
.aheart-ai-form__field > .aheart-switch,
|
|
226
|
+
.aheart-ai-form__field-error {
|
|
227
|
+
grid-column: 1;
|
|
228
|
+
grid-row: auto;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
.aheart-ai-form__field > label {
|
|
232
|
+
padding-block-start: 0;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
@media (prefers-reduced-motion: reduce) {
|
|
237
|
+
.aheart-ai-form * {
|
|
238
|
+
scroll-behavior: auto !important;
|
|
239
|
+
transition-duration: 0.01ms !important;
|
|
240
|
+
animation-duration: 0.01ms !important;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AIFormFieldV1 } from './form-schema';
|
|
2
|
+
declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
|
|
3
|
+
field: AIFormFieldV1;
|
|
4
|
+
value: unknown;
|
|
5
|
+
disabled?: boolean | undefined;
|
|
6
|
+
error?: string | undefined;
|
|
7
|
+
}>>, {
|
|
8
|
+
focus: () => void;
|
|
9
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
10
|
+
update: (value: unknown) => void;
|
|
11
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_TypePropsToRuntimeProps<{
|
|
12
|
+
field: AIFormFieldV1;
|
|
13
|
+
value: unknown;
|
|
14
|
+
disabled?: boolean | undefined;
|
|
15
|
+
error?: string | undefined;
|
|
16
|
+
}>>> & Readonly<{
|
|
17
|
+
onUpdate?: ((value: unknown) => any) | undefined;
|
|
18
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
19
|
+
export default _default;
|
|
20
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
21
|
+
type __VLS_TypePropsToRuntimeProps<T> = {
|
|
22
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
23
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
24
|
+
} : {
|
|
25
|
+
type: import('vue').PropType<T[K]>;
|
|
26
|
+
required: true;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("vue"),t=require("aheart-ui"),m=["data-field-key","aria-invalid","aria-describedby"],s=["id","for"],v={key:0,class:"aheart-ai-form__required","aria-hidden":"true"},B=["id"],V=["id"],U=l.defineComponent({__name:"form-field",props:{field:{},value:{},disabled:{type:Boolean},error:{}},emits:["update"],setup(e,{expose:f,emit:y}){const o=e,i=y,b=l.ref(),n=l.ref(),c=l.computed(()=>(o.field.options??[]).map(r=>({key:r.value,title:r.label,disabled:r.disabled}))),u=l.computed(()=>[o.field.description&&`${o.field.key}-description`,o.error&&`${o.field.key}-error`].filter(Boolean).join(" ")||void 0),k=l.computed(()=>o.field.type==="date-range"||o.field.type==="time-range"?`${o.field.key}-start`:o.field.key);return f({focus:()=>{var r,d;if(n.value){n.value.focus("start");return}(d=(r=b.value)==null?void 0:r.querySelector('input, button, [role="combobox"], [tabindex="0"]'))==null||d.focus({preventScroll:!0})}}),(r,d)=>(l.openBlock(),l.createElementBlock("div",{ref_key:"fieldElement",ref:b,class:l.normalizeClass(["aheart-ai-form__field",{"is-error":!!e.error,"is-disabled":e.disabled}]),"data-field-key":e.field.key,"aria-invalid":e.error?"true":void 0,"aria-describedby":u.value,tabindex:"-1"},[l.createElementVNode("label",{id:`${e.field.key}-label`,for:k.value},[l.createTextVNode(l.toDisplayString(e.field.label)+" ",1),e.field.required?(l.openBlock(),l.createElementBlock("span",v,"*")):l.createCommentVNode("",!0)],8,s),e.field.description?(l.openBlock(),l.createElementBlock("p",{key:0,id:`${e.field.key}-description`,class:"aheart-ai-form__field-description"},l.toDisplayString(e.field.description),9,B)):l.createCommentVNode("",!0),e.field.type==="textarea"?(l.openBlock(),l.createBlock(l.unref(t.Textarea),{key:1,id:e.field.key,"aria-labelledby":`${e.field.key}-label`,"aria-describedby":u.value,"model-value":e.value,placeholder:e.field.placeholder,disabled:e.disabled,"onUpdate:modelValue":d[0]||(d[0]=a=>i("update",a))},null,8,["id","aria-labelledby","aria-describedby","model-value","placeholder","disabled"])):e.field.type==="tree-select"?(l.openBlock(),l.createBlock(l.unref(t.TreeSelect),{key:2,id:e.field.key,"labelled-by":`${e.field.key}-label`,"model-value":e.value,"tree-data":c.value,multiple:Array.isArray(e.value),disabled:e.disabled,"onUpdate:modelValue":d[1]||(d[1]=a=>i("update",a))},null,8,["id","labelled-by","model-value","tree-data","multiple","disabled"])):e.field.type==="upload"?(l.openBlock(),l.createBlock(l.unref(t.Upload),{key:3,"file-list":e.value,disabled:e.disabled,"onUpdate:fileList":d[2]||(d[2]=a=>i("update",a))},null,8,["file-list","disabled"])):e.field.type==="radio"?(l.openBlock(),l.createBlock(l.unref(t.RadioGroup),{key:4,"model-value":e.value,options:e.field.options,disabled:e.disabled,"onUpdate:modelValue":d[3]||(d[3]=a=>i("update",a))},null,8,["model-value","options","disabled"])):e.field.type==="checkbox"?(l.openBlock(),l.createBlock(l.unref(t.CheckboxGroup),{key:5,"model-value":e.value,options:e.field.options,disabled:e.disabled,"onUpdate:modelValue":d[4]||(d[4]=a=>i("update",a))},null,8,["model-value","options","disabled"])):e.field.type==="select"?(l.openBlock(),l.createBlock(l.unref(t.Select),{key:6,id:e.field.key,"labelled-by":`${e.field.key}-label`,"model-value":e.value,disabled:e.disabled,options:e.field.options,"onUpdate:modelValue":d[5]||(d[5]=a=>i("update",a))},null,8,["id","labelled-by","model-value","disabled","options"])):e.field.type==="switch"?(l.openBlock(),l.createBlock(l.unref(t.Switch),{key:7,id:e.field.key,"model-value":!!e.value,disabled:e.disabled,"onUpdate:modelValue":d[6]||(d[6]=a=>i("update",a))},null,8,["id","model-value","disabled"])):e.field.type==="number"?(l.openBlock(),l.createBlock(l.unref(t.InputNumber),{key:8,id:e.field.key,"model-value":e.value,placeholder:e.field.placeholder,disabled:e.disabled,"onUpdate:modelValue":d[7]||(d[7]=a=>i("update",a))},null,8,["id","model-value","placeholder","disabled"])):e.field.type==="date"?(l.openBlock(),l.createBlock(l.unref(t.DatePicker),{key:9,id:e.field.key,"labelled-by":`${e.field.key}-label`,"described-by":u.value,status:e.error?"error":void 0,"model-value":e.value,placeholder:e.field.placeholder,disabled:e.disabled,"onUpdate:modelValue":d[8]||(d[8]=a=>i("update",a))},null,8,["id","labelled-by","described-by","status","model-value","placeholder","disabled"])):e.field.type==="date-range"?(l.openBlock(),l.createBlock(l.unref(t.DateRangePicker),{key:10,ref_key:"rangeControl",ref:n,id:e.field.key,"labelled-by":`${e.field.key}-label`,"described-by":u.value,status:e.error?"error":void 0,"model-value":e.value,disabled:e.disabled,"onUpdate:modelValue":d[9]||(d[9]=a=>i("update",a))},null,8,["id","labelled-by","described-by","status","model-value","disabled"])):e.field.type==="time"?(l.openBlock(),l.createBlock(l.unref(t.TimePicker),{key:11,id:e.field.key,"labelled-by":`${e.field.key}-label`,"described-by":u.value,status:e.error?"error":void 0,"model-value":e.value,placeholder:e.field.placeholder,disabled:e.disabled,"onUpdate:modelValue":d[10]||(d[10]=a=>i("update",a))},null,8,["id","labelled-by","described-by","status","model-value","placeholder","disabled"])):e.field.type==="time-range"?(l.openBlock(),l.createBlock(l.unref(t.TimeRangePicker),{key:12,ref_key:"rangeControl",ref:n,id:e.field.key,"labelled-by":`${e.field.key}-label`,"described-by":u.value,status:e.error?"error":void 0,"model-value":e.value,disabled:e.disabled,"onUpdate:modelValue":d[11]||(d[11]=a=>i("update",a))},null,8,["id","labelled-by","described-by","status","model-value","disabled"])):(l.openBlock(),l.createBlock(l.unref(t.Input),{key:13,id:e.field.key,"model-value":e.value,placeholder:e.field.placeholder,disabled:e.disabled,"aria-describedby":u.value,"onUpdate:modelValue":d[12]||(d[12]=a=>i("update",a))},null,8,["id","model-value","placeholder","disabled","aria-describedby"])),e.error?(l.openBlock(),l.createElementBlock("p",{key:14,id:`${e.field.key}-error`,class:"aheart-ai-form__field-error",role:"alert"},l.toDisplayString(e.error),9,V)):l.createCommentVNode("",!0)],10,m))}});exports.default=U;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./form-field.vue.js");exports.default=e.default;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export declare const AI_FORM_FIELD_TYPES: readonly ["input", "textarea", "number", "select", "checkbox", "radio", "switch", "date", "date-range", "time", "time-range", "upload", "tree-select"];
|
|
2
|
+
export declare const AI_FORM_CONDITION_OPERATORS: readonly ["equals", "not-equals", "includes", "not-includes", "is-empty", "is-not-empty"];
|
|
3
|
+
export type AIFormFieldType = (typeof AI_FORM_FIELD_TYPES)[number];
|
|
4
|
+
export type AIFormConditionOperator = (typeof AI_FORM_CONDITION_OPERATORS)[number];
|
|
5
|
+
export interface AIFormCondition {
|
|
6
|
+
field: string;
|
|
7
|
+
operator: AIFormConditionOperator;
|
|
8
|
+
value?: string | number | boolean | string[];
|
|
9
|
+
}
|
|
10
|
+
export interface AIFormOption {
|
|
11
|
+
label: string;
|
|
12
|
+
value: string | number;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface AIFormGroupV1 {
|
|
16
|
+
key: string;
|
|
17
|
+
title: string;
|
|
18
|
+
description?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface AIFormFieldV1 {
|
|
21
|
+
key: string;
|
|
22
|
+
label: string;
|
|
23
|
+
type: AIFormFieldType;
|
|
24
|
+
defaultValue?: unknown;
|
|
25
|
+
placeholder?: string;
|
|
26
|
+
description?: string;
|
|
27
|
+
group?: string;
|
|
28
|
+
required?: boolean;
|
|
29
|
+
options?: AIFormOption[];
|
|
30
|
+
visibleWhen?: AIFormCondition;
|
|
31
|
+
disabledWhen?: AIFormCondition;
|
|
32
|
+
rules?: AIFormRuleV1[];
|
|
33
|
+
dependencies?: string[];
|
|
34
|
+
preserve?: boolean;
|
|
35
|
+
}
|
|
36
|
+
export type AIFormRuleV1 = {
|
|
37
|
+
kind: 'range';
|
|
38
|
+
valueType: 'number' | 'length';
|
|
39
|
+
min?: number;
|
|
40
|
+
max?: number;
|
|
41
|
+
message?: string;
|
|
42
|
+
} | {
|
|
43
|
+
kind: 'format';
|
|
44
|
+
format: 'email' | 'url' | 'date' | 'time';
|
|
45
|
+
message?: string;
|
|
46
|
+
} | {
|
|
47
|
+
kind: 'compare';
|
|
48
|
+
field: string;
|
|
49
|
+
operator: 'equals' | 'not-equals' | 'greater-than' | 'greater-than-or-equal' | 'less-than' | 'less-than-or-equal';
|
|
50
|
+
message?: string;
|
|
51
|
+
} | {
|
|
52
|
+
kind: 'async';
|
|
53
|
+
validator: string;
|
|
54
|
+
message?: string;
|
|
55
|
+
};
|
|
56
|
+
export type AIFormAsyncValidator = (value: unknown, context: {
|
|
57
|
+
values: Readonly<Record<string, unknown>>;
|
|
58
|
+
field: AIFormFieldV1;
|
|
59
|
+
signal: AbortSignal;
|
|
60
|
+
}) => void | boolean | string | Promise<void | boolean | string>;
|
|
61
|
+
export interface AIFormSchemaV1 {
|
|
62
|
+
version: '1';
|
|
63
|
+
title?: string;
|
|
64
|
+
description?: string;
|
|
65
|
+
groups?: AIFormGroupV1[];
|
|
66
|
+
fields: AIFormFieldV1[];
|
|
67
|
+
}
|
|
68
|
+
export interface AIFormSchemaValidation {
|
|
69
|
+
valid: boolean;
|
|
70
|
+
errors: string[];
|
|
71
|
+
schema?: AIFormSchemaV1;
|
|
72
|
+
}
|
|
73
|
+
export declare const validateAIFormSchema: (schema: unknown) => AIFormSchemaValidation;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const $=["input","textarea","number","select","checkbox","radio","switch","date","date-range","time","time-range","upload","tree-select"],b=["equals","not-equals","includes","not-includes","is-empty","is-not-empty"],a=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),u=e=>typeof e=="string"||typeof e=="number",c=e=>Array.isArray(e)&&e.every(u),A=e=>a(e)&&typeof e.uid=="string"&&typeof e.name=="string",l=e=>{if(typeof e!="string"||!/^\d{4}-\d{2}-\d{2}$/.test(e))return!1;const[t,i,o]=e.split("-").map(Number),r=new Date(Date.UTC(t,i-1,o));return r.getUTCFullYear()===t&&r.getUTCMonth()===i-1&&r.getUTCDate()===o},h=e=>{if(typeof e!="string"||!/^\d{2}:\d{2}:\d{2}$/.test(e))return!1;const[t,i,o]=e.split(":").map(Number);return t<=23&&i<=59&&o<=59},m=(e,t)=>Array.isArray(e)&&e.length===2&&e.every(t),k=new Set(["version","title","description","groups","fields"]),S=new Set(["key","title","description"]),O=new Set(["key","label","type","defaultValue","placeholder","description","group","required","options","visibleWhen","disabledWhen","rules","dependencies","preserve"]),T=new Set(["label","value","disabled"]),E=new Set(["field","operator","value"]),_=new Set(["select","checkbox","radio","tree-select"]),d=(e,t,i,o)=>{const r=Object.keys(e).filter(p=>!t.has(p));r.length&&o.push(`${i} 包含不支持的属性:${r.join("、")}`)},w=(e,t)=>t===void 0?!0:e==="switch"?typeof t=="boolean":e==="number"?typeof t=="number":e==="checkbox"?c(t):e==="upload"?Array.isArray(t)&&t.every(A):e==="date"?l(t):e==="time"?h(t):e==="date-range"?m(t,l):e==="time-range"?m(t,h):e==="tree-select"?u(t)||c(t):e==="select"||e==="radio"?u(t):typeof t=="string",g=(e,t,i)=>!a(e)||typeof e.field!="string"||!e.field.trim()?(i.push(`${t} 必须包含字段名`),!1):(d(e,E,t,i),typeof e.operator!="string"||!b.includes(e.operator)?(i.push(`${t} 包含不支持的条件操作符`),!1):e.value!==void 0&&!u(e.value)&&typeof e.value!="boolean"&&!Array.isArray(e.value)?(i.push(`${t}.value 类型不安全`),!1):Array.isArray(e.value)&&!e.value.every(o=>typeof o=="string")?(i.push(`${t}.value 数组只能包含字符串`),!1):!0),I=e=>{const t=[];if(!a(e)||e.version!=="1"||!Array.isArray(e.fields))return{valid:!1,errors:["AIForm schema 必须是 version 为 1 的 fields 数组"]};d(e,k,"schema",t),e.title!==void 0&&typeof e.title!="string"&&t.push("schema.title 必须是字符串"),e.description!==void 0&&typeof e.description!="string"&&t.push("schema.description 必须是字符串");const i=new Set;e.groups!==void 0&&(Array.isArray(e.groups)?e.groups.forEach((r,p)=>{const s=`groups[${p}]`;if(!a(r)){t.push(`${s} 必须是对象`);return}d(r,S,s,t),typeof r.key!="string"||!r.key.trim()?t.push(`${s}.key 必须是非空字符串`):i.has(r.key)?t.push(`${s}.key 不能重复`):i.add(r.key),(typeof r.title!="string"||!r.title.trim())&&t.push(`${s}.title 必须是非空字符串`),r.description!==void 0&&typeof r.description!="string"&&t.push(`${s}.description 必须是字符串`)}):t.push("schema.groups 必须是数组"));const o=new Set;return e.fields.forEach((r,p)=>{const s=`fields[${p}]`;if(!a(r)||typeof r.key!="string"||!r.key.trim()){t.push(`${s}.key 必须是非空字符串`);return}d(r,O,s,t),o.has(r.key)&&t.push(`${s}.key 不能重复`),o.add(r.key),typeof r.label!="string"&&t.push(`${s}.label 必须是字符串`),(typeof r.type!="string"||!$.includes(r.type))&&t.push(`${s}.type 不受支持`),r.required!==void 0&&typeof r.required!="boolean"&&t.push(`${s}.required 必须是布尔值`),r.placeholder!==void 0&&typeof r.placeholder!="string"&&t.push(`${s}.placeholder 必须是字符串`),r.description!==void 0&&typeof r.description!="string"&&t.push(`${s}.description 必须是字符串`),r.group!==void 0&&(typeof r.group!="string"||!i.has(r.group))&&t.push(`${s}.group 必须引用已声明的分组`),w(r.type,r.defaultValue)||t.push(`${s}.defaultValue 与字段类型不兼容`),r.visibleWhen!==void 0&&g(r.visibleWhen,`${s}.visibleWhen`,t),r.disabledWhen!==void 0&&g(r.disabledWhen,`${s}.disabledWhen`,t),r.dependencies!==void 0&&(!Array.isArray(r.dependencies)||!r.dependencies.every(n=>typeof n=="string"&&n.trim()))&&t.push(`${s}.dependencies 必须是非空字段名数组`),r.preserve!==void 0&&typeof r.preserve!="boolean"&&t.push(`${s}.preserve 必须是布尔值`),r.rules!==void 0&&(Array.isArray(r.rules)?r.rules.forEach((n,f)=>D(n,`${s}.rules[${f}]`,t)):t.push(`${s}.rules 必须是数组`)),r.options!==void 0&&(Array.isArray(r.options)?r.options.forEach((n,f)=>{!a(n)||typeof n.label!="string"||!u(n.value)||n.disabled!==void 0&&typeof n.disabled!="boolean"?t.push(`${s}.options[${f}] 不合法`):d(n,T,`${s}.options[${f}]`,t)}):t.push(`${s}.options 必须是数组`)),r.required===!0&&_.has(r.type)&&(!Array.isArray(r.options)||!r.options.some(n=>a(n)&&n.disabled!==!0))&&t.push(`${s}.options 必须为必填字段提供至少一个可用选项`)}),e.fields.forEach((r,p)=>{if(a(r)){for(const s of["visibleWhen","disabledWhen"]){const n=r[s];a(n)&&typeof n.field=="string"&&!o.has(n.field)&&t.push(`fields[${p}].${s}.field 必须引用已声明的字段`)}if(Array.isArray(r.dependencies))for(const s of r.dependencies)typeof s=="string"&&!o.has(s)&&t.push(`fields[${p}].dependencies 必须引用已声明的字段`);if(Array.isArray(r.rules))for(const s of r.rules)a(s)&&s.kind==="compare"&&typeof s.field=="string"&&!o.has(s.field)&&t.push(`fields[${p}].rules.compare.field 必须引用已声明的字段`);if(Array.isArray(r.rules)){for(const s of r.rules)if(a(s)&&(s.kind==="range"&&(s.valueType==="number"&&r.type!=="number"||s.valueType==="length"&&!["input","textarea","checkbox"].includes(String(r.type)))&&t.push(`fields[${p}].rules.range 与字段类型组合不合法`),s.kind==="format"&&((s.format==="email"||s.format==="url"?["input","textarea"]:s.format==="date"?["date"]:["time"]).includes(String(r.type))||t.push(`fields[${p}].rules.format 与字段类型组合不合法`)),s.kind==="compare"&&typeof s.field=="string")){const n=e.fields.find(f=>a(f)&&f.key===s.field);n&&["greater-than","greater-than-or-equal","less-than","less-than-or-equal"].includes(String(s.operator))&&(r.type==="number"&&n.type==="number"||["date","time"].includes(String(r.type))&&r.type===n.type||t.push(`fields[${p}].rules.compare 有序比较类型不兼容`))}}}}),t.length?{valid:!1,errors:t}:{valid:!0,errors:[],schema:e}},y=Object.create(null);Object.assign(y,{range:new Set(["kind","valueType","min","max","message"]),format:new Set(["kind","format","message"]),compare:new Set(["kind","field","operator","message"]),async:new Set(["kind","validator","message"])});const D=(e,t,i)=>{if(!a(e)||typeof e.kind!="string"||!Object.prototype.hasOwnProperty.call(y,e.kind)){i.push(`${t} kind 不受支持`);return}if(d(e,y[e.kind],t,i),e.message!==void 0&&typeof e.message!="string"&&i.push(`${t}.message 必须是字符串`),e.kind==="range"){e.valueType!=="number"&&e.valueType!=="length"&&i.push(`${t}.valueType 不受支持`),e.min===void 0&&e.max===void 0&&i.push(`${t} 至少需要一个范围边界`);for(const o of["min","max"])e[o]!==void 0&&(typeof e[o]!="number"||!Number.isFinite(e[o]))&&i.push(`${t}.${o} 必须是有限数字`);typeof e.min=="number"&&typeof e.max=="number"&&e.min>e.max&&i.push(`${t} min 不能大于 max`)}else e.kind==="format"?["email","url","date","time"].includes(String(e.format))||i.push(`${t}.format 不受支持`):e.kind==="compare"?((typeof e.field!="string"||!e.field.trim())&&i.push(`${t}.field 必须是字段名`),["equals","not-equals","greater-than","greater-than-or-equal","less-than","less-than-or-equal"].includes(String(e.operator))||i.push(`${t}.operator 不受支持`)):(typeof e.validator!="string"||!/^[A-Za-z][A-Za-z0-9_-]*$/.test(e.validator))&&i.push(`${t}.validator 必须是安全名称`)};exports.AI_FORM_CONDITION_OPERATORS=b;exports.AI_FORM_FIELD_TYPES=$;exports.validateAIFormSchema=I;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type AIFormAsyncValidator } from './form-schema';
|
|
2
|
+
declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
|
|
3
|
+
modelValue?: Record<string, unknown> | undefined;
|
|
4
|
+
schema: unknown;
|
|
5
|
+
disabled?: boolean | undefined;
|
|
6
|
+
submitting?: boolean | undefined;
|
|
7
|
+
submitText?: string | undefined;
|
|
8
|
+
submitError?: string | undefined;
|
|
9
|
+
validators?: Record<string, AIFormAsyncValidator> | undefined;
|
|
10
|
+
}>, {
|
|
11
|
+
modelValue: () => {};
|
|
12
|
+
disabled: boolean;
|
|
13
|
+
submitting: boolean;
|
|
14
|
+
submitText: string;
|
|
15
|
+
submitError: undefined;
|
|
16
|
+
validators: () => {};
|
|
17
|
+
}>>, {
|
|
18
|
+
validate: () => Promise<any>;
|
|
19
|
+
resetFields: () => void;
|
|
20
|
+
clearValidate: (names?: string[] | undefined) => void;
|
|
21
|
+
setFieldsErrors: (fields: {
|
|
22
|
+
name: string;
|
|
23
|
+
errors: string[];
|
|
24
|
+
}[]) => void;
|
|
25
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
26
|
+
submit: (value: Record<string, unknown>) => void;
|
|
27
|
+
"update:modelValue": (value: Record<string, unknown>) => void;
|
|
28
|
+
"schema-error": (errors: string[]) => void;
|
|
29
|
+
"validation-error": (errors: {
|
|
30
|
+
key: string;
|
|
31
|
+
message: string;
|
|
32
|
+
}[]) => void;
|
|
33
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
|
|
34
|
+
modelValue?: Record<string, unknown> | undefined;
|
|
35
|
+
schema: unknown;
|
|
36
|
+
disabled?: boolean | undefined;
|
|
37
|
+
submitting?: boolean | undefined;
|
|
38
|
+
submitText?: string | undefined;
|
|
39
|
+
submitError?: string | undefined;
|
|
40
|
+
validators?: Record<string, AIFormAsyncValidator> | undefined;
|
|
41
|
+
}>, {
|
|
42
|
+
modelValue: () => {};
|
|
43
|
+
disabled: boolean;
|
|
44
|
+
submitting: boolean;
|
|
45
|
+
submitText: string;
|
|
46
|
+
submitError: undefined;
|
|
47
|
+
validators: () => {};
|
|
48
|
+
}>>> & Readonly<{
|
|
49
|
+
onSubmit?: ((value: Record<string, unknown>) => any) | undefined;
|
|
50
|
+
"onUpdate:modelValue"?: ((value: Record<string, unknown>) => any) | undefined;
|
|
51
|
+
"onSchema-error"?: ((errors: string[]) => any) | undefined;
|
|
52
|
+
"onValidation-error"?: ((errors: {
|
|
53
|
+
key: string;
|
|
54
|
+
message: string;
|
|
55
|
+
}[]) => any) | undefined;
|
|
56
|
+
}>, {
|
|
57
|
+
disabled: boolean;
|
|
58
|
+
modelValue: Record<string, unknown>;
|
|
59
|
+
submitting: boolean;
|
|
60
|
+
submitText: string;
|
|
61
|
+
submitError: string;
|
|
62
|
+
validators: Record<string, AIFormAsyncValidator>;
|
|
63
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
64
|
+
export default _default;
|
|
65
|
+
type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
|
|
66
|
+
type __VLS_TypePropsToRuntimeProps<T> = {
|
|
67
|
+
[K in keyof T]-?: {} extends Pick<T, K> ? {
|
|
68
|
+
type: import('vue').PropType<__VLS_NonUndefinedable<T[K]>>;
|
|
69
|
+
} : {
|
|
70
|
+
type: import('vue').PropType<T[K]>;
|
|
71
|
+
required: true;
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
type __VLS_WithDefaults<P, D> = {
|
|
75
|
+
[K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
|
|
76
|
+
default: D[K];
|
|
77
|
+
}> : P[K];
|
|
78
|
+
};
|
|
79
|
+
type __VLS_Prettify<T> = {
|
|
80
|
+
[K in keyof T]: T[K];
|
|
81
|
+
} & {};
|
package/lib/form.vue.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("vue"),T=require("aheart-ui"),ie=require("./form-field.vue.js"),ce=require("./form-schema.js"),ue={key:0,class:"aheart-ai-form__header"},de={key:0},me={key:1},fe={key:1,class:"aheart-ai-form__error-summary",role:"alert",tabindex:"-1"},pe=["onClick"],ye={key:0},he={key:0},ge={key:2,class:"aheart-ai-form__submit-error",role:"alert"},ve={class:"aheart-ai-form__footer"},be={key:1,class:"aheart-ai-form__error",role:"alert"},ke=a.defineComponent({name:"AAIForm",__name:"form",props:{modelValue:{default:()=>({})},schema:{},disabled:{type:Boolean,default:!1},submitting:{type:Boolean,default:!1},submitText:{default:"提交"},submitError:{default:void 0},validators:{default:()=>({})}},emits:["update:modelValue","submit","schema-error","validation-error"],setup(p,{expose:G,emit:H}){const u=p,V=H,c=a.computed(()=>{const e=ce.validateAIFormSchema(u.schema);if(!e.valid||!e.schema)return e;const t=e.schema.fields.flatMap(r=>(r.rules??[]).filter(o=>o.kind==="async"&&!(Object.prototype.hasOwnProperty.call(u.validators,o.validator)&&typeof u.validators[o.validator]=="function")).map(o=>`fields.${r.key}.rules.${o.validator} validator 不存在`));return t.length?{valid:!1,errors:[...e.errors,...t]}:e}),y=a.computed(()=>u.modelValue),h=a.computed(()=>{var e;return(((e=c.value.schema)==null?void 0:e.fields)??[]).reduce((t,r)=>{const o=Object.prototype.hasOwnProperty.call(y.value,r.key);return!o&&N.has(r.key)||(t[r.key]=o?y.value[r.key]:r.defaultValue),t},{...y.value})}),i=a.reactive({}),A=a.reactive({}),j=new Map,q=a.reactive({}),R=new Map,v=a.ref(),d=new Map,P=()=>{for(const e of d.values())e.abort();d.clear()},x=a.ref({}),N=a.reactive(new Set),g=new Set,B=new Map,b=new Map,k=new Map,Y=a.ref(!1);a.onMounted(()=>{Y.value=!0});const U=a.ref(!1),J=a.ref(0),_=a.ref(!1);a.watch(c,e=>{e.valid||V("schema-error",e.errors)},{immediate:!0}),a.watch(h,e=>{Object.keys(x.value).length||(x.value=O(e))},{immediate:!0,deep:!0}),a.watch(h,(e,t)=>{Object.keys(A).forEach(r=>{Object.prototype.hasOwnProperty.call(e,r)||delete A[r]}),Object.entries(e).forEach(([r,o])=>{const s=j.get(r);j.has(r)?E(o,s)&&(j.delete(r),delete i[r]):t&&!E(o,t[r])&&delete i[r],A[r]=O(o)})},{immediate:!0,deep:!0}),a.watch(y,e=>{for(const t of[...g]){const r=b.get(t),o=k.get(t),s=a.toRaw(e);if(s!==r){if(s!==r&&!E(s,o)){g.delete(t),B.delete(t),b.delete(t),k.delete(t);continue}Object.prototype.hasOwnProperty.call(e,t)?(g.delete(t),B.delete(t),b.delete(t),k.delete(t)):(N.add(t),g.delete(t),B.delete(t),b.delete(t),k.delete(t))}}},{deep:!0});const D=e=>{if(!e)return!0;const t=h.value[e.field];return e.operator==="equals"?t===e.value:e.operator==="not-equals"?t!==e.value:e.operator==="includes"?Array.isArray(t)?t.includes(e.value):String(t??"").includes(String(e.value??"")):e.operator==="not-includes"?Array.isArray(t)?!t.includes(e.value):!String(t??"").includes(String(e.value??"")):e.operator==="is-empty"?w(t):!w(t)},F=a.computed(()=>{var e;return((e=c.value.schema)==null?void 0:e.fields.filter(t=>D(t.visibleWhen)))??[]});a.watch(h,(e,t)=>{var l;const r=t??{},o={...y.value};let s=!1;for(const n of((l=c.value.schema)==null?void 0:l.fields)??[]){const m=W(n.visibleWhen,r),f=W(n.visibleWhen,e);f&&g.has(n.key)&&!N.has(n.key)&&(g.delete(n.key),B.delete(n.key),b.delete(n.key),k.delete(n.key)),m&&!f&&n.preserve===!1&&(delete o[n.key],g.add(n.key),B.set(n.key,Object.prototype.hasOwnProperty.call(y.value,n.key)),b.set(n.key,a.toRaw(y.value)),k.set(n.key,a.toRaw(o)),s=!0)}s&&V("update:modelValue",o)},{deep:!0}),a.watch(h,(e,t)=>{var o,s;const r=t??{};for(const l of((o=c.value.schema)==null?void 0:o.fields)??[]){const n=z(l);(!E(e[l.key],r[l.key])||n.some(f=>!E(e[f],r[f])))&&((s=d.get(l.key))==null||s.abort(),d.delete(l.key))}},{deep:!0}),a.watch(()=>u.schema,()=>{for(const e of d.values())e.abort();d.clear()});const W=(e,t)=>{if(!e)return!0;const r=t[e.field];return e.operator==="equals"?r===e.value:e.operator==="not-equals"?r!==e.value:e.operator==="is-empty"?w(r):e.operator==="is-not-empty"?!w(r):e.operator==="includes"?Array.isArray(r)?r.includes(e.value):String(r??"").includes(String(e.value??"")):Array.isArray(r)?!r.includes(e.value):!String(r??"").includes(String(e.value??""))},S=e=>u.disabled||u.submitting||!!(e.disabledWhen&&D(e.disabledWhen)),Q=a.computed(()=>{const e=c.value.schema;if(!e)return[];const t=(e.groups??[]).map(o=>({key:o.key,group:o,fields:F.value.filter(s=>s.group===o.key)})).filter(o=>o.fields.length>0),r=F.value.filter(o=>!o.group);return r.length&&t.push({key:"__ungrouped",fields:r}),t}),M=a.computed(()=>F.value.filter(e=>i[e.key]).map(e=>({key:e.key,message:i[e.key]})));a.watch([h,F],()=>{var t;const e=((t=c.value.schema)==null?void 0:t.fields)??[];Object.keys(i).forEach(r=>{const o=e.find(s=>s.key===r);(!o||!D(o.visibleWhen)||S(o))&&delete i[r]})});function w(e){return e==null||e===""||e===!1||Array.isArray(e)&&(e.length===0||e.every(t=>t==null||t===""))}function E(e,t){if(Object.is(e,t))return!0;if(Array.isArray(e)||Array.isArray(t))return Array.isArray(e)&&Array.isArray(t)&&e.length===t.length&&e.every((r,o)=>E(r,t[o]));if(e&&t&&typeof e=="object"&&typeof t=="object"){const r=e,o=t,s=Object.keys(r),l=Object.keys(o);return s.length===l.length&&s.every(n=>Object.prototype.hasOwnProperty.call(o,n)&&E(r[n],o[n]))}return!1}function O(e){return Array.isArray(e)?e.map(t=>O(t)):e&&typeof e=="object"&&Object.getPrototypeOf(e)===Object.prototype?Object.fromEntries(Object.entries(e).map(([t,r])=>[t,O(r)])):e}const X=(e,t)=>e.type==="date-range"||e.type==="time-range"?!Array.isArray(t)||t.length!==2||t.some(r=>r==null||r===""):w(t),Z=e=>{const t=h.value[e.key];if(t!==void 0)return t;if(e.type==="checkbox"||e.type==="upload")return[];if(!(e.type==="date-range"||e.type==="time-range"))return""},ee=e=>`${e.key}-${q[e.key]??0}`,te=(e,t)=>{t&&typeof t.focus=="function"?R.set(e,t):R.delete(e)},L=e=>{var t;return(t=R.get(e))==null?void 0:t.focus()},re=async(e,t)=>{j.set(e,t),V("update:modelValue",{...y.value,[e]:t}),await a.nextTick(),y.value[e]!==t&&(q[e]=(q[e]??0)+1)},ae=e=>{if(S(e))return[];const t=[];if(e.required&&!S(e)){const r=`${e.label}为必填项`;t.push({required:!0,message:r},{message:r,validator:(o,s)=>X(e,s)?r:void 0})}for(const r of e.rules??[])t.push(oe(e,r));return t},K=e=>{if(typeof e!="string"||!/^\d{4}-\d{2}-\d{2}$/.test(e))return!1;const[t,r,o]=e.split("-").map(Number),s=new Date(Date.UTC(t,r-1,o));return s.getUTCFullYear()===t&&s.getUTCMonth()===r-1&&s.getUTCDate()===o},I=e=>typeof e=="string"&&/^\d{2}:\d{2}:\d{2}$/.test(e)&&e.split(":").map(Number).every((t,r)=>r===0?t<24:t<60),oe=(e,t)=>({...t.kind==="format"&&t.format==="email"?{type:"email"}:{},...t.kind==="range"&&t.min!==void 0?{min:t.min}:{},...t.kind==="range"&&t.max!==void 0?{max:t.max}:{},message:t.message??`${e.label}校验失败`,validator:(r,o)=>{if(!e.required&&w(o))return;if(t.kind==="range"){const n=t.valueType==="number"?typeof o=="number"&&Number.isFinite(o)?o:void 0:typeof o=="string"||Array.isArray(o)?o.length:void 0;return n===void 0||t.min!==void 0&&n<t.min||t.max!==void 0&&n>t.max?t.message??`${e.label}范围不合法`:void 0}if(t.kind==="format")return typeof o!="string"?t.message??`${e.label}格式不合法`:(t.format==="email"?/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(o):t.format==="url"?(()=>{try{const m=new URL(o);return m.protocol==="http:"||m.protocol==="https:"}catch{return!1}})():t.format==="date"?/^\d{4}-\d{2}-\d{2}$/.test(o)&&K(o):I(o))?void 0:t.message??`${e.label}格式不合法`;if(t.kind==="compare"){const n=h.value[t.field];if(!(typeof o==typeof n&&(typeof o=="number"?Number.isFinite(o)&&Number.isFinite(n):!0)))return t.message??`${e.label}与${t.field}类型不匹配`;if(["greater-than","greater-than-or-equal","less-than","less-than-or-equal"].includes(t.operator)){const C=$=>typeof $=="number"&&Number.isFinite($)?"number":K($)?"date":I($)?"time":void 0;if(!C(o)||!C(n)||C(o)!==C(n))return t.message??`${e.label}有序比较不合法`}return(t.operator==="equals"?o===n:t.operator==="not-equals"?o!==n:t.operator==="greater-than"?o>n:t.operator==="greater-than-or-equal"?o>=n:t.operator==="less-than"?o<n:o<=n)?void 0:t.message??`${e.label}比较不成立`}const s=d.get(e.key)??new AbortController;d.set(e.key,s);const l=Object.prototype.hasOwnProperty.call(u.validators,t.validator)&&typeof u.validators[t.validator]=="function"?u.validators[t.validator]:void 0;if(!l)return`${e.label}校验器不存在`;try{const n=l(o,{values:h.value,field:e,signal:s.signal}),m=f=>{if(!s.signal.aborted){if(f===!1)return t.message??`${e.label}校验失败`;if(typeof f=="string")return f}};return n&&typeof n.then=="function"?n.then(m):m(n)}catch(n){return s.signal.aborted?void 0:n instanceof Error?n.message:t.message??`${e.label}校验失败`}}}),se=()=>{var e,t;u.disabled||u.submitting||(_.value=!1,P(),(t=(e=v.value)==null?void 0:e.clearValidate)==null||t.call(e),Object.keys(i).forEach(r=>delete i[r]),U.value=!1)},z=e=>Array.from(new Set([...e.dependencies??[],...(e.rules??[]).filter(t=>t.kind==="compare").map(t=>t.field)])),ne=e=>{if(_.value){_.value=!1;return}u.disabled||u.submitting||U.value||V("submit",{...e})},le=e=>{if(_.value){_.value=!1;return}if(u.disabled||u.submitting)return;const t=e.errorFields.map(r=>{var n;const o=typeof r.name=="string"?r.name:String(r.name[0]),s=(n=c.value.schema)==null?void 0:n.fields.find(m=>m.key===o),l=r.errors[0]||`${(s==null?void 0:s.label)??o}为必填项`;return{key:o,message:l}}).filter(r=>F.value.some(o=>o.key===r.key)&&!S(c.value.schema.fields.find(o=>o.key===r.key)));t.forEach(r=>{i[r.key]=r.message}),t.length&&(V("validation-error",t),a.nextTick(()=>L(t[0].key)))};return G({validate:()=>{var e,t;return P(),Promise.resolve(((t=(e=v.value)==null?void 0:e.validate)==null?void 0:t.call(e))??{errorFields:[]}).then(r=>{var o;Object.keys(i).forEach(s=>delete i[s]);for(const s of r.errorFields??[]){const l=typeof s.name=="string"?s.name:String(s.name[0]);(o=s.errors)!=null&&o[0]&&(i[l]=s.errors[0])}return r})},resetFields:()=>{var t,r,o,s,l;for(const n of d.values())n.abort();d.clear(),N.clear(),g.clear(),B.clear(),b.clear(),k.clear(),J.value+=1,_.value=!0,Object.keys(i).forEach(n=>delete i[n]);const e=(((t=c.value.schema)==null?void 0:t.fields)??[]).map(n=>({name:n.key,errors:[]}));(o=(r=v.value)==null?void 0:r.clearValidate)==null||o.call(r),(l=(s=v.value)==null?void 0:s.setFieldsErrors)==null||l.call(s,e),Object.keys(i).forEach(n=>delete i[n]),V("update:modelValue",O(x.value))},clearValidate:e=>{var t,r;e?e.forEach(o=>delete i[o]):Object.keys(i).forEach(o=>delete i[o]),(r=(t=v.value)==null?void 0:t.clearValidate)==null||r.call(t,e)},setFieldsErrors:e=>{var t,r;e.forEach(o=>{o.errors[0]?i[o.name]=o.errors[0]:delete i[o.name]}),(r=(t=v.value)==null?void 0:t.setFieldsErrors)==null||r.call(t,e)}}),a.onBeforeUnmount(()=>{for(const e of d.values())e.abort()}),(e,t)=>c.value.valid&&c.value.schema?(a.openBlock(),a.createBlock(a.unref(T.Form),{key:0,ref_key:"formElement",ref:v,class:"aheart-ai-form",model:A,disabled:p.disabled||p.submitting,"required-mark":!1,layout:"vertical","aria-busy":p.submitting?"true":"false",onSubmit:se,onFinish:ne,onFinishFailed:le},{default:a.withCtx(()=>[c.value.schema.title||c.value.schema.description?(a.openBlock(),a.createElementBlock("header",ue,[c.value.schema.title?(a.openBlock(),a.createElementBlock("h2",de,a.toDisplayString(c.value.schema.title),1)):a.createCommentVNode("",!0),c.value.schema.description?(a.openBlock(),a.createElementBlock("p",me,a.toDisplayString(c.value.schema.description),1)):a.createCommentVNode("",!0)])):a.createCommentVNode("",!0),M.value.length?(a.openBlock(),a.createElementBlock("div",fe,[a.createElementVNode("strong",null,"请解决 "+a.toDisplayString(M.value.length)+" 个校验问题",1),a.createElementVNode("ul",null,[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(M.value,r=>(a.openBlock(),a.createElementBlock("li",{key:r.key},[a.createElementVNode("button",{type:"button",onClick:o=>L(r.key)},a.toDisplayString(r.message),9,pe)]))),128))])])):a.createCommentVNode("",!0),(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(Q.value,r=>{var o;return a.openBlock(),a.createBlock(a.resolveDynamicComponent(r.group?"fieldset":"section"),{key:r.key,class:"aheart-ai-form__group","data-group-key":(o=r.group)==null?void 0:o.key},{default:a.withCtx(()=>[r.group?(a.openBlock(),a.createElementBlock("legend",ye,[a.createElementVNode("span",null,a.toDisplayString(r.group.title),1),r.group.description?(a.openBlock(),a.createElementBlock("small",he,a.toDisplayString(r.group.description),1)):a.createCommentVNode("",!0)])):a.createCommentVNode("",!0),(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(r.fields,s=>(a.openBlock(),a.createBlock(a.unref(T.FormItem),{key:ee(s),name:s.key,rules:ae(s),dependencies:z(s),"no-style":""},{default:a.withCtx(()=>[a.createVNode(ie.default,{ref_for:!0,ref:l=>te(s.key,l),field:s,value:Z(s),disabled:S(s),error:i[s.key],onUpdate:l=>re(s.key,l)},null,8,["field","value","disabled","error","onUpdate"])]),_:2},1032,["name","rules","dependencies"]))),128))]),_:2},1032,["data-group-key"])}),128)),p.submitError?(a.openBlock(),a.createElementBlock("p",ge,a.toDisplayString(p.submitError),1)):a.createCommentVNode("",!0),a.createElementVNode("footer",ve,[a.createVNode(a.unref(T.Button),{"html-type":"submit",type:"primary",loading:p.submitting,disabled:p.disabled},{default:a.withCtx(()=>[a.createTextVNode(a.toDisplayString(p.submitText),1)]),_:1},8,["loading","disabled"])])]),_:1},8,["model","disabled","aria-busy"])):(a.openBlock(),a.createElementBlock("div",be,[t[0]||(t[0]=a.createElementVNode("strong",null,"表单配置无效",-1)),a.createElementVNode("ul",null,[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(c.value.errors,r=>(a.openBlock(),a.createElementBlock("li",{key:r},a.toDisplayString(r),1))),128))])]))}});exports.default=ke;
|
package/lib/form.vue2.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("./form.vue.js");exports.default=e.default;
|