UNPKG

@progress/kendo-ui

Version:

This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.

3 lines (2 loc) 5.07 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("kendo.core.js"),require("kendo.icons.js"),require("kendo.textarea.js"),require("kendo.button.js"),require("kendo.toolbar.js"),require("kendo.aiprompt.views.js")):"function"==typeof define&&define.amd?define(["exports","kendo.core.min","kendo.icons","kendo.textarea","kendo.button","kendo.toolbar","kendo.aiprompt.views"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).kendo=e.kendo||{},e.kendo._globals=e.kendo._globals||{},e.kendo._globals.Aiprompt={}))}(this,(function(e){!function(e){let t=window.kendo,o=t.ui.Widget,i=t.ui,n=e.extend,s="focus",r="k-prompt",p={prompt:{type:"kendo.ui.AIPromptPromptView",name:"prompt",buttonIcon:"sparkles"},output:{type:"kendo.ui.AIPromptOutputView",name:"output",buttonIcon:"comment"},commands:{type:"kendo.ui.AIPromptCommandsView",name:"commands",buttonIcon:"more-horizontal"},custom:{type:"kendo.ui.AIPromptCustomView",name:"custom"}},a=o.extend({init:function(e,i){let n=this;i=i||{},o.fn.init.call(n,e,i),0==n.options.views.length&&(n.options.views=["prompt","output"],this.options.promptCommands&&this.options.promptCommands.length&&this.options.views.push("commands")),n.promptOutputs=n.options.promptOutputs||[],n._initLayout(),n._initViews(),n._initToolbar(),n.activeView(n.options.activeView),t.notify(n)},options:{name:"AIPrompt",enabled:!0,toolbarItems:[],promptOutputs:[],activeView:0,views:[],popup:null,messages:{promptView:"Ask AI",outputView:"Output",commandsView:"",customView:"Custom View",promptPlaceholder:"Ask or generate content with AI",promptSuggestions:"Prompt Suggestions",generateOutput:"Generate",outputTitle:"Generated with AI",outputRetryTitle:"Generated with AI",copyOutput:"Copy",retryGeneration:"Retry",ratePositive:"",rateNegative:""},showOutputRating:!0,service:null},events:["commandExecute","promptRequest","promptResponse","outputRatingChange","outputCopy"],_initializeView:function(e){let o,i=this.views[e];if(i){let e=i.type;if("string"==typeof e&&(e=t.getter(i.type)(window)),!e)throw new Error("There is no such view");o=new e(this.element,n(!0,{promptSuggestions:this.options.promptSuggestions,promptCommands:this.options.promptCommands,promptOutputs:this.promptOutputs,showOutputRating:this.options.showOutputRating,messages:this.options.messages,promptSuggestionItemTemplate:this.options.promptSuggestionItemTemplate,service:this.options.service},i))}return o},_unbindView:function(e){e&&e.destroy()},_initViews:function(){let e=this,t=e.options.views;e.views={},e.viewsArray=[];for(let o=0,i=t.length;o<i;o++){let i=t[o],n="object"==typeof i,s=i;n&&(s="string"!=typeof i.type?i.name:i.type);let r=p[s];r&&(n&&(i.type=r.type),r.buttonText=e.options.messages[`${s}View`]),i=Object.assign({title:i.title,name:s,index:o},r,n?i:{}),e.viewsArray.push(i),s&&(e.views[s]=i)}},getViews:function(){return this.viewsArray},activeView:function(t){let o=this;if(void 0===t)return o._activeViewIndex;if(Number.isInteger(t)&&(t=o.viewsArray[t].name),t&&o.views[t]){o._selectedView&&o._unbindView(o._selectedView),o._selectedView=o._initializeView(t),o._activeViewIndex=o.viewsArray.findIndex((e=>e.name===t)),o._selectedView.render(),o._updateToolbarState(o._activeViewIndex);let i=e(o.toolbar._getAllItems()[o._activeViewIndex]);o.toolbar._resetTabIndex(i),i.trigger(s)}},addPromptOutput:function(e){if(e.id=e.id||t.guid(),this.promptOutputs.unshift(e),"function"==typeof this._selectedView.renderPromptOutput)return this._selectedView.renderPromptOutput(e)},_updateToolbarState:function(t){let o=this.toolbar;o.element.find(".k-toolbar-toggle-button").each((function(i,n){o.toggle(e(n),i==t)}))},_initLayout:function(){let t=this,o=e("<div></div>").addClass("k-prompt-header");t.header=o,t.element.addClass(r),t.element.append(o);const i=t.element.closest(".k-popup");i.length&&e(i).addClass("k-prompt-popup")},_getViewTools:function(){let e=this;return e.viewsArray.map((t=>("commands"===t.name&&(t.buttonText?t.title=t.buttonText:t.title="More Actions"),{type:"button",text:t.buttonText,icon:t.buttonIcon,fillMode:"flat",themeColor:"primary",rounded:"full",togglable:!0,attributes:{title:t.title},toggle:function(){e.activeView(t.name)}})))},_initToolbar:function(){let t=this,o=t.options.toolbarItems;o=Array.isArray(o)?o:[o];const i=o.find((e=>"x"===e.icon));i&&(i.themeColor="base");let n=e("<div></div>").kendoToolBar({resizable:!1,fillMode:"flat",items:t._getViewTools().concat(o)}).appendTo(t.header);t.toolbar=n.data("kendoToolBar")},focus:function(){this.element.trigger(s)},destroy:function(){let e=this;e.toolbar?.destroy(),e._selectedView?.destroy(),e.element.off(".kendoAIPrompt"),o.fn.destroy.call(e)}});i.plugin(a)}(window.kendo.jQuery);var t=kendo;e.__meta__={id:"aiprompt",name:"AIPrompt",category:"web",description:"The AIPrompt component simplifies the incorporation of external AI services into apps.",depends:["core","icons","textarea","button","toolbar","panelbar"]},e.default=t,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=kendo.aiprompt.min.js.map