UNPKG

jodit-pro

Version:

PRO Version of Jodit Editor

12 lines (11 loc) 3.17 kB
var v=Object.defineProperty;var u=(r,t)=>v(r,"name",{value:t,configurable:!0});var l,c=function(r,t,e,o){var i=arguments.length,n=i<3?t:o===null?o=Object.getOwnPropertyDescriptor(t,e):o,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(r,t,e,o);else for(var p=r.length-1;p>=0;p--)(a=r[p])&&(n=(i<3?a(n):i>3?a(t,e,n):a(t,e))||n);return i>3&&n&&Object.defineProperty(t,e,n),n};import{autobind as d,component as m,hook as f}from"jodit/esm/core/decorators/index.js";import{UIElement as _}from"jodit/esm/core/ui/index.js";import{UIButton as h}from"jodit/esm/core/ui/button/index.js";import{UISelect as C}from"jodit/esm/core/ui/form/inputs/select/select.js";let s=(l=class extends _{className(){return"UIPermissionRequest"}constructor(t,e){super(t),this.state=e,this.scopeSelect=null,this.approveButton=null,this.denyButton=null}setToolCall(t){this.toolCall=t,this.updateContent()}setParentView(t){var e,o,i;return(e=this.scopeSelect)===null||e===void 0||e.setParentView(t),(o=this.approveButton)===null||o===void 0||o.setParentView(t),(i=this.denyButton)===null||i===void 0||i.setParentView(t),super.setParentView(t)}render(){return`<div class="&__container"> <div class="&__header"> <div class="&__icon"></div> <div class="&__title">~Permission Required~</div> </div> <div class="&__tool-info"></div> <div class="&__actions"></div> </div>`}afterRender(){this.createControls(),this.updateContent()}createControls(){const t=this.getElm("actions");this.denyButton=new h(this.j,{icon:{name:"cancel"},variant:"danger",size:"small"}),this.j.e.on(this.denyButton,"click",this.onDeny),this.approveButton=new h(this.j,{icon:{name:"check"},variant:"success",size:"small"}),this.j.e.on(this.approveButton,"click",this.onApprove),this.scopeSelect=new C(this.j,{name:"permission-scope",options:[{value:"once",text:this.j.i18n("Once")},{value:"conversation",text:this.j.i18n("This conversation")},{value:"forever",text:this.j.i18n("Always")}]}),this.scopeSelect.value=this.state.defaultPermissionScope,t.appendChild(this.denyButton.container),t.appendChild(this.approveButton.container),t.appendChild(this.scopeSelect.container)}updateContent(){if(!this.toolCall)return;const t=this.getElm("tool-info");t.innerHTML=` <div class="${this.getFullElName("tool-name")}">${this.j.i18n(this.toolCall.name)}</div> <div class="${this.getFullElName("tool-args")}">${this.formatArguments(this.toolCall.arguments)}</div> `}formatArguments(t){return Object.entries(t).map(([e,o])=>`${e}: ${JSON.stringify(o)}`).join(", ")}onApprove(){var t;const e=(t=this.scopeSelect)===null||t===void 0?void 0:t.value;this.j.e.fire("approveToolCall.ai-assistant-pro",this.toolCall.id,e)}onDeny(){this.j.e.fire("denyToolCall.ai-assistant-pro",this.toolCall.id)}destruct(){var t,e,o;(t=this.scopeSelect)===null||t===void 0||t.destruct(),(e=this.approveButton)===null||e===void 0||e.destruct(),(o=this.denyButton)===null||o===void 0||o.destruct(),super.destruct()}},u(l,"UIPermissionRequest"),l);c([f("ready")],s.prototype,"afterRender",null),c([d],s.prototype,"onApprove",null),c([d],s.prototype,"onDeny",null),s=c([m],s);export{s as UIPermissionRequest};