UNPKG

@kitn.ai/ui

Version:

Framework-agnostic, Shadow-DOM web components for building AI chat interfaces — works in React, Vue, Angular, Svelte, or plain HTML. Authored in SolidJS.

2 lines (1 loc) 1.11 kB
import{g as l,p as v}from"./define-CNSKFZCd.js";import{t as u}from"./toast-store-BEMda0fv.js";const b=2e3;function T(r){const[m,f]=l({}),[g,d]=l(new Set),p=r.copiedDuration??b,a=new Map;v(()=>{a.forEach(e=>clearTimeout(e)),a.clear()});const c=e=>e.feedback??m()[e.id],h=e=>g().has(e),k=e=>{d(o=>{const i=new Set(o);return i.add(e),i});const t=a.get(e);t&&clearTimeout(t),a.set(e,setTimeout(()=>{a.delete(e),d(o=>{if(!o.has(e))return o;const i=new Set(o);return i.delete(e),i})},p))},s=(e,t)=>{f(o=>{const i={...o};return t===void 0?delete i[e]:i[e]=t,i})};return{resolveFeedback:c,isCopied:h,handleAction:(e,t)=>{var o,i,n;if(t==="copy"){try{(o=navigator.clipboard)==null||o.writeText(e.content)}catch{}k(e.id),u("Copied to clipboard",{target:(i=r.target)==null?void 0:i.call(r)}),r.emit({messageId:e.id,action:t});return}if(t==="like"||t==="dislike"){c(e)===t?(s(e.id,void 0),r.emit({messageId:e.id,action:t,state:"off"})):(s(e.id,t),u("Thanks for your feedback",{target:(n=r.target)==null?void 0:n.call(r)}),r.emit({messageId:e.id,action:t,state:"on"}));return}r.emit({messageId:e.id,action:t})}}}export{T as c};