UNPKG

jodit-pro

Version:

PRO Version of Jodit Editor

2 lines (1 loc) 6.13 kB
var m=Object.defineProperty;var r=(l,t)=>m(l,"name",{value:t,configurable:!0});var c,d=function(l,t,e,s){var n=arguments.length,i=n<3?t:s===null?s=Object.getOwnPropertyDescriptor(t,e):s,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")i=Reflect.decorate(l,t,e,s);else for(var a=l.length-1;a>=0;a--)(o=l[a])&&(i=(n<3?o(i):n>3?o(t,e,i):o(t,e))||i);return n>3&&i&&Object.defineProperty(t,e,i),i};import{UIArtifact as g}from"../artifact.js";import{component as f,hook as C}from"jodit/esm/core/decorators/index.js";import{UIElement as j}from"jodit/esm/core/ui/index.js";import{UIButton as E}from"jodit/esm/core/ui/button/index.js";import{UIGroup as x}from"jodit/esm/core/ui/group/group.js";import{ContextMenu as b}from"jodit/esm/modules/context-menu/context-menu.js";let h=(c=class extends j{className(){return"UIMessageListItem"}constructor(t,e,s){super(t),this.message=e,this.opts=s,this.artifactGroup=null,this.actionsButton=null,this.contextMenu=null}render(){return`<div class="${this.getFullElName("message")}"></div>`}onReady(){this.updateContent(),this.contextMenu=new b(this.j)}updateContent(){const t=this.container;t.innerHTML="",t.setAttribute("data-message-id",this.message.id),t.setAttribute("data-role",this.message.role);const e=this.j.c.div(this.getFullElName("message-bubble"));e.classList.add(this.getFullElName("message-bubble",this.message.role,!0));const s=this.j.c.div(this.getFullElName("message-content"));if(s.innerHTML=this.formatMessageContent(this.message.content),e.appendChild(s),this.opts.showTimestamps){const i=this.j.c.div(this.getFullElName("message-timestamp"));i.textContent=this.formatTimestamp(this.message.timestamp),e.appendChild(i)}const n=this.j.c.div(this.getFullElName("message-actions"));if(this.renderActionsButton(n),e.appendChild(n),t.appendChild(e),this.message.toolCalls&&this.message.toolCalls.length>0){const i=this.j.c.div(this.getFullElName("tool-calls"));t.appendChild(i),this.message.toolCalls.forEach(o=>{const a=this.createToolCallElement(o);i.appendChild(a)})}this.message.artifacts&&this.message.artifacts.length>0&&this.renderArtifacts()}renderActionsButton(t){const e=this.opts;(e.showCopyMessageAction||e.showRestartMessageAction||e.showEditMessageAction||e.showDeleteMessageAction)&&(this.actionsButton=new E(this.j,{icon:{name:"dots"},tooltip:"Message actions",name:"messageActions",size:"tiny"}),this.actionsButton.onAction(n=>{this.showActionsMenu(n)}),t.appendChild(this.actionsButton.container))}showActionsMenu(t){if(!this.contextMenu||!this.actionsButton)return;const e=this.j,s=e.o.aiAssistantPro,n=[];s.showCopyMessageAction&&n.push({title:"Copy message",icon:"copy",exec:r(()=>{this.j.e.fire("copyMessage.ai-assistant-pro",this.message.id)},"exec")}),this.message.role==="user"&&(s.showRestartMessageAction&&n.push({title:"Restart from here",icon:"update",exec:r(()=>{this.j.e.fire("restartFromMessage.ai-assistant-pro",this.message.id)},"exec")}),s.showEditMessageAction&&n.push({title:"Edit message",icon:"pencil",exec:r(()=>{this.j.e.fire("editMessage.ai-assistant-pro",this.message.id)},"exec")})),s.showDeleteMessageAction&&n.push({title:"Delete message",icon:"bin",exec:r(()=>{e.confirm("Are you sure you want to delete this message?","Delete message",o=>{o&&this.j.e.fire("deleteMessage.ai-assistant-pro",this.message.id)})},"exec")});const i=this.actionsButton.container.getBoundingClientRect();this.contextMenu.show(i.left,i.bottom,n),t.stopPropagation()}renderArtifacts(){if(!this.message.artifacts||this.message.artifacts.length===0)return;const t=this.j.c.div(this.getFullElName("artifacts"));this.container.appendChild(t),this.artifactGroup||(this.artifactGroup=new x(this.j),this.artifactGroup.container.className="jodit-ui-artifact-group"),this.artifactGroup.clear(),this.message.artifacts.forEach(e=>{const s=new g(this.j,e);this.artifactGroup.append(s)}),t.appendChild(this.artifactGroup.container)}createToolCallElement(t){const e=this.j.c.div(this.getFullElName("tool-call"));e.setAttribute("data-tool-id",t.id),e.setAttribute("data-status",t.status);const s=this.j.c.div(this.getFullElName("tool-header")),n=this.j.c.div(this.getFullElName("tool-icon"));n.classList.add(this.getFullElName("tool-icon",t.status,!0)),n.textContent="\u26A1";const i=this.j.c.div(this.getFullElName("tool-name"));i.textContent=this.j.i18n(t.name);const o=this.j.c.div(this.getFullElName("tool-status"));o.textContent=this.getToolStatusText(t.status||"unknown"),s.appendChild(n),s.appendChild(i),s.appendChild(o),e.appendChild(s);const a=this.createExpandableSection("Arguments",JSON.stringify(t.arguments||{},null,2));if(e.appendChild(a),t.result){const u=t.result.error?`Error: ${t.result.error}`:t.result.result||"",p=this.createExpandableSection("Result",typeof u=="string"?u:JSON.stringify(u,null,2));e.appendChild(p)}return e}createExpandableSection(t,e){const s=this.j.c.div(this.getFullElName("tool-expandable")),n=this.j.c.element("button",{type:"button",class:this.getFullElName("tool-expandable-toggle")});n.textContent=`\u25B6 ${this.j.i18n(t)}`;const i=this.j.c.element("pre",{class:this.getFullElName("tool-expandable-content")});return i.textContent=e,i.style.display="none",this.j.e.on(n,"click",()=>{i.style.display!=="none"?(i.style.display="none",n.textContent=`\u25B6 ${this.j.i18n(t)}`):(i.style.display="block",n.textContent=`\u25BC ${this.j.i18n(t)}`)}),s.appendChild(n),s.appendChild(i),s}getToolStatusText(t){return{pending:"\u23F3",approved:"\u2713",denied:"\u2715",executing:"\u26A1",executed:"\u2713",error:"\u26A0"}[t]||"\u25CF"}formatMessageContent(t){const e=this.opts.formatMessageContent,s=this.message.role;return e(t,s,this.j.i18n.bind(this.j))}formatTimestamp(t){const e=this.opts.formatTimestamp;return e(t,this.j.i18n.bind(this.j))}updateMessage(t){this.message=t,this.updateContent()}destruct(){var t,e,s;(t=this.actionsButton)===null||t===void 0||t.destruct(),(e=this.contextMenu)===null||e===void 0||e.destruct(),(s=this.artifactGroup)===null||s===void 0||s.destruct(),super.destruct()}},r(c,"UIMessageListItem"),c);d([C("ready")],h.prototype,"onReady",null),h=d([f],h);export{h as UIMessageListItem};