{"version":3,"file":"kendo.aiprompt.min.js","names":["global","factory","exports","module","require","define","amd","globalThis","self","kendoaiprompt","js","this","$","kendo","window","Widget","ui","extend","FOCUS","cssClasses","defaultViews","prompt","type","name","buttonIcon","output","commands","custom","AIPrompt","init","element","options","that","fn","call","views","length","promptCommands","push","promptOutputs","_initLayout","_initViews","_initToolbar","activeView","notify","enabled","toolbarItems","popup","messages","promptView","outputView","commandsView","customView","promptPlaceholder","promptSuggestions","generateOutput","outputTitle","outputRetryTitle","copyOutput","retryGeneration","ratePositive","rateNegative","showOutputRating","events","_initializeView","view","viewConfig","getter","Error","promptSuggestionItemTemplate","_unbindView","destroy","viewsArray","i","l","isSettings","defaultView","buttonText","Object","assign","title","index","getViews","undefined","_activeViewIndex","Number","isInteger","_selectedView","findIndex","v","render","_updateToolbarState","toolItem","toolbar","_getAllItems","_resetTabIndex","trigger","addPromptOutput","id","guid","unshift","renderPromptOutput","activeToolIndex","find","each","elm","toggle","header","addClass","append","_getViewTools","map","text","icon","fillMode","themeColor","rounded","togglable","items","Array","isArray","toolbarEl","kendoToolBar","resizable","concat","appendTo","data","focus","off","plugin","jQuery"],"sources":["kendo.aiprompt.js"],"mappings":"CAAA,SAAWA,EAAQC,GACI,iBAAZC,SAA0C,oBAAXC,OAAyBA,OAAOD,QAAUD,EAAQG,QAAQ,iBAAkBA,QAAQ,kBAAmBA,QAAQ,qBAAsBA,QAAQ,mBAAoBA,QAAQ,oBAAqBA,QAAQ,4BAC1N,mBAAXC,QAAyBA,OAAOC,IAAMD,OAAO,CAAC,iBAAkB,kBAAmB,qBAAsB,mBAAoB,oBAAqB,4BAA6BJ,KACrLD,EAA+B,oBAAfO,WAA6BA,WAAaP,GAAUQ,MAAcC,cAAgBT,EAAOS,eAAiB,CAAC,EAAGT,EAAOS,cAAcC,GAAKT,IAC5J,CAJD,CAIGU,MAAM,WA+RL,OAtRA,SAAUC,GACN,IAAIC,EAAQC,OAAOD,MACfE,EAASF,EAAMG,GAAGD,OAElBC,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AAW8C,EAAElE,KACtB,KAER,EAEAmB,aAAc,WACV,IAAIV,EAAOrB,KACP2G,EAAQtF,EAAKD,QAAQe,aACzBwE,EAAQC,MAAMC,QAAQF,GAASA,EAAQ,CAACA,GAExC,IAAIG,EAAY7G,EAAE,eAAe8G,aAAa,CAC1CC,WAAW,EACXT,SAAU,OACVI,MAAOtF,EAAK8E,gBAAgBc,OAAON,KACpCO,SAAS7F,EAAK2E,QAEjB3E,EAAK6D,QAAU4B,EAAUK,KAAK,eAClC,EAEAC,MAAO,WACQpH,KACNmB,QAAQkE,QAAQ9E,EACzB,EAEAqD,QAAS,WACL,IAAIvC,EAAOrB,KAEXqB,EAAK6D,SAAStB,UACdvC,EAAKuD,eAAehB,UAEpBvC,EAAKF,QAAQkG,IAxQZ,kBA0QDjH,EAAOkB,GAAGsC,QAAQrC,KAAKF,EAC3B,IAGJhB,EAAGiH,OAAOrG,EAEb,CAnRD,CAmRGd,OAAOD,MAAMqH,QACFrH,KAIjB","sourcesContent":["(function (global, factory) {\n typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(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')) :\n typeof define === 'function' && define.amd ? define(['kendo.core', 'kendo.icons', 'kendo.textarea', 'kendo.button', 'kendo.toolbar', 'kendo.aiprompt.views'], factory) :\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self, (global.kendoaiprompt = global.kendoaiprompt || {}, global.kendoaiprompt.js = factory()));\n})(this, (function () {\n let __meta__ = {\n id: \"aiprompt\",\n name: \"AIPrompt\",\n category: \"web\",\n description: \"The AIPrompt component simplifies the incorporation of external AI services into apps.\",\n depends: [\"core\", \"icons\", \"textarea\", \"button\", \"toolbar\", \"panelbar\"],\n };\n\n (function($) {\n let kendo = window.kendo,\n Widget = kendo.ui.Widget,\n NS = \".kendoAIPrompt\",\n ui = kendo.ui,\n extend = $.extend,\n\n COMMAND_EXECUTE = \"commandExecute\",\n PROMPT_REQUEST = \"promptRequest\",\n OUTPUT_RATING_CHANGE = \"outputRatingChange\",\n OUTPUT_COPY = \"outputCopy\",\n\n FOCUS = \"focus\";\n\n let cssClasses = {\n menuButton: \"k-menu-button\",\n aIPrompt: \"k-prompt\"\n };\n\n let defaultViews = {\n prompt: {\n type: \"kendo.ui.AIPromptPromptView\",\n name: \"prompt\",\n buttonIcon: \"sparkles\",\n },\n output: {\n type: \"kendo.ui.AIPromptOutputView\",\n name: \"output\",\n buttonIcon: \"comment\",\n },\n commands: {\n type: \"kendo.ui.AIPromptCommandsView\",\n name: \"commands\",\n buttonIcon: \"more-horizontal\",\n },\n custom: {\n type: \"kendo.ui.AIPromptCustomView\",\n name: \"custom\",\n }\n };\n\n let AIPrompt = Widget.extend({\n init: function(element, options) {\n let that = this;\n options = options || {};\n Widget.fn.init.call(that, element, options);\n\n if (that.options.views.length == 0) {\n that.options.views = [\"prompt\", \"output\"];\n\n if (this.options.promptCommands && this.options.promptCommands.length) {\n this.options.views.push(\"commands\");\n }\n }\n\n that.promptOutputs = that.options.promptOutputs || [];\n that._initLayout();\n that._initViews();\n that._initToolbar();\n that.activeView(that.options.activeView);\n\n kendo.notify(that);\n },\n\n options: {\n name: \"AIPrompt\",\n enabled: true,\n toolbarItems: [],\n promptOutputs: [],\n activeView: 0,\n views: [],\n popup: null,\n messages: {\n promptView: \"Ask AI\",\n outputView: \"Output\",\n commandsView: \"\",\n customView: \"Custom View\",\n promptPlaceholder: \"Ask or generate content with AI\",\n promptSuggestions: \"Prompt Suggestions\",\n generateOutput: \"Generate\",\n outputTitle: \"Generated with AI\",\n outputRetryTitle: \"Generated with AI\",\n copyOutput: \"Copy\",\n retryGeneration: \"Retry\",\n ratePositive: \"\",\n rateNegative: \"\"\n },\n showOutputRating: true,\n },\n\n events: [\n COMMAND_EXECUTE,\n PROMPT_REQUEST,\n OUTPUT_RATING_CHANGE,\n OUTPUT_COPY,\n ],\n\n _initializeView: function(name) {\n let viewConfig = this.views[name];\n let view;\n if (viewConfig) {\n let type = viewConfig.type;\n\n if (typeof type === \"string\") {\n type = kendo.getter(viewConfig.type)(window);\n }\n\n if (type) {\n view = new type(this.element, extend(true, {\n promptSuggestions: this.options.promptSuggestions,\n promptCommands: this.options.promptCommands,\n promptOutputs: this.promptOutputs,\n showOutputRating: this.options.showOutputRating,\n messages: this.options.messages,\n promptSuggestionItemTemplate: this.options.promptSuggestionItemTemplate,\n\n },\n viewConfig\n ));\n } else {\n throw new Error(\"There is no such view\");\n }\n }\n\n return view;\n },\n\n _unbindView: function(view) {\n if (view) {\n view.destroy();\n }\n },\n\n _initViews: function() {\n let that = this,\n options = that.options,\n views = options.views;\n\n that.views = {};\n that.viewsArray = [];\n\n for (let i = 0, l = views.length; i < l; i++) {\n let view = views[i];\n let isSettings = typeof view === \"object\";\n let name = view;\n\n if (isSettings) {\n name = typeof view.type !== \"string\" ? view.name : view.type;\n }\n\n let defaultView = defaultViews[name];\n\n if (defaultView) {\n if (isSettings) {\n view.type = defaultView.type;\n }\n\n defaultView.buttonText = that.options.messages[`${name}View`];\n }\n\n view = Object.assign({ title: view.title, name, index: i }, defaultView, isSettings ? view : {});\n that.viewsArray.push(view);\n\n if (name) {\n that.views[name] = view;\n }\n }\n },\n\n getViews: function() {\n return this.viewsArray;\n },\n\n activeView: function(name) {\n let that = this;\n if (name === undefined) {\n return that._activeViewIndex;\n }\n\n if (Number.isInteger(name)) {\n name = that.viewsArray[name].name;\n }\n\n if (name && that.views[name]) {\n if (that._selectedView) {\n that._unbindView(that._selectedView);\n }\n\n that._selectedView = that._initializeView(name);\n that._activeViewIndex = that.viewsArray.findIndex(v => v.name === name);\n that._selectedView.render();\n\n that._updateToolbarState(that._activeViewIndex);\n\n let toolItem = $(that.toolbar._getAllItems()[that._activeViewIndex]);\n that.toolbar._resetTabIndex(toolItem);\n toolItem.trigger(FOCUS);\n }\n },\n\n addPromptOutput: function(output) {\n output.id = output.id || kendo.guid();\n this.promptOutputs.unshift(output);\n\n if (typeof this._selectedView.renderPromptOutput === \"function\") {\n return this._selectedView.renderPromptOutput(output);\n }\n },\n\n _updateToolbarState: function(activeToolIndex) {\n let toolbar = this.toolbar;\n toolbar.element.find(\".k-toolbar-toggle-button\").each(function(index, elm) {\n toolbar.toggle($(elm), index == activeToolIndex);\n });\n },\n\n _initLayout: function() {\n let that = this,\n header = $(\"
\").addClass(\"k-prompt-header\");\n\n that.header = header;\n that.element.addClass(cssClasses.aIPrompt);\n that.element.append(header);\n },\n\n _getViewTools: function() {\n let that = this;\n\n return that.viewsArray.map(v => ({\n type: \"button\",\n text: v.buttonText,\n icon: v.buttonIcon,\n fillMode: \"flat\",\n themeColor: \"primary\",\n rounded: \"full\",\n togglable: true,\n toggle: function() {\n that.activeView(v.name);\n }\n }));\n },\n\n _initToolbar: function() {\n let that = this;\n let items = that.options.toolbarItems;\n items = Array.isArray(items) ? items : [items];\n\n let toolbarEl = $(\"
\").kendoToolBar({\n resizable: false,\n fillMode: \"flat\",\n items: that._getViewTools().concat(items)\n }).appendTo(that.header);\n\n that.toolbar = toolbarEl.data(\"kendoToolBar\");\n },\n\n focus: function() {\n let that = this;\n that.element.trigger(FOCUS);\n },\n\n destroy: function() {\n let that = this;\n\n that.toolbar?.destroy();\n that._selectedView?.destroy();\n\n that.element.off(NS);\n\n Widget.fn.destroy.call(that);\n }\n });\n\n ui.plugin(AIPrompt);\n\n })(window.kendo.jQuery);\n var kendo$1 = kendo;\n\n return kendo$1;\n\n}));\n"]}