UNPKG

@ckeditor/ckeditor5-ai

Version:

AI features for CKEditor 5.

23 lines • 7.95 kB
/* * Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved. * * * * * +---------------------------------------------------------------------------------+ * | | * | Hello stranger! | * | | * | | * | What you're currently looking at is the source code of a legally protected, | * | proprietary software. Any attempts to deobfuscate / disassemble this code | * | are forbidden and will result in legal consequences. | * | | * | | * +---------------------------------------------------------------------------------+ * * * * */ import{Collection as _0x5bca20,KeystrokeHandler as _0x46a759,FocusTracker as _0x218119}from'ckeditor5/src/utils.js';import{View as _0x14e58e,ViewCollection as _0xd5a926,ButtonView as _0x238f63,FormRowView as _0x14c315,createDropdown as _0x440797,addListToDropdown as _0x8ea5b9,UIModel as _0x15a683,ButtonLabelView as _0xc6c098,LabeledFieldView as _0xcd84f,FocusCycler as ts}from'ckeditor5/src/ui.js';import{AIReviewModePromptInputView as _0x1051d7}from'./aireviemodepromptinputview.js';import{getTranslation as _0x595826}from'../../aicore/utils/common-translations.js';import{AIModels as _0x1f1125}from'../../aicore/model/aimodels.js';export class AIReviewModeCustomCheckView extends _0x14e58e{['focusTracker']=new _0x218119();['keystrokes']=new _0x46a759();['focusCycler'];['_focusables']=new _0xd5a926();['submitButtonView'];['cancelButtonView'];['promptInputView'];['actionsFooterView'];['_modelSelectionDropdown'];['_modelSelectionDropdownItems'];['_check'];['_defaultValue'];['_defaultLabel'];constructor(_0x2a96ae,_0x191f73){super(_0x2a96ae),this['_check']=_0x191f73,this['set']('prompt',''),this['set']('modelId',''),this['_defaultValue']=_0x191f73['models']&&_0x191f73['models']['length']>0x0?_0x191f73['models'][0x0]['id']:'',this['_defaultLabel']=_0x191f73['models']&&_0x191f73['models']['length']>0x0?_0x191f73['models'][0x0]['name']:'',this['submitButtonView']=this['_createSubmitButtonView'](),this['cancelButtonView']=this['_createCancelButtonView'](),(this['promptInputView']=new _0xcd84f(this['locale'],()=>new _0x1051d7(_0x2a96ae)),this['promptInputView']['fieldView']['bind']('value')['to'](this,'prompt'),this['promptInputView']['fieldView']['on']('input',()=>{this['prompt']=this['promptInputView']['fieldView']['element']['value'];}),this['_modelSelectionDropdown']=this['_createModelSelectionDropdown'](),this['_modelSelectionDropdownItems']=new _0x5bca20(),this['_setModelList'](),_0x8ea5b9(this['_modelSelectionDropdown'],this['_modelSelectionDropdownItems']),this['actionsFooterView']=this['_createActionsFooterView'](),this['setTemplate']({'tag':'div','attributes':{'class':['ck-ai-review-mode__check-list-item-custom-actions']},'children':[new _0x14c315(this['locale'],{'children':[this['promptInputView']]}),new _0x14c315(this['locale'],{'children':[this['actionsFooterView']]})]}),this['promptInputView']['fieldView']['keystrokes']['set']('Enter',(_0x54e079,_0x454ba8)=>{this['_isValid']()?(this['fire']('runReviewCheck',{'id':'custom','args':{'prompt':this['prompt'],'model':this['modelId']},'isCustom':!0x0}),_0x454ba8()):_0x454ba8();}),this['focusCycler']=new ts({'focusables':this['_focusables'],'focusTracker':this['focusTracker'],'keystrokeHandler':this['keystrokes'],'actions':{'focusPrevious':'shift\x20+\x20tab','focusNext':'tab'}}));}['render'](){super['render'](),([this['promptInputView'],this['_modelSelectionDropdown'],this['cancelButtonView'],this['submitButtonView']]['forEach'](_0x2e95ac=>{this['_focusables']['add'](_0x2e95ac),this['focusTracker']['add'](_0x2e95ac['element']);}),this['keystrokes']['listenTo'](this['element']));}get['modelDefaultValue'](){return this['_defaultValue'];}get['modelDefaultLabel'](){return this['_defaultLabel'];}['resetToDefault'](){this['prompt']='',this['modelId']=this['modelDefaultValue'],this['_modelSelectionDropdown']['buttonView']['label']=this['modelDefaultLabel'],this['resetFormValidationStatus']();}['resetFormValidationStatus'](){this['promptInputView']['errorText']='';}['_isValid'](){this['resetFormValidationStatus']();for(const _0x24a02f of this['_getFormValidators']()){const _0x1813a4=_0x24a02f();if(_0x1813a4)return this['promptInputView']['errorText']=_0x1813a4,!0x1;}return!0x0;}['_getFormValidators'](){return[()=>{if(0x0===this['promptInputView']['fieldView']['value']?.['trim']()['length'])return _0x595826(this['locale'],'AI_REVIEW_MODE_PROMPT_EMPTY_ERROR');}];}['_createSubmitButtonView'](){const _0xcbed89=new _0x238f63(this['locale']),t=this['locale']['t'];return _0xcbed89['set']({'label':t('Submit'),'withText':!0x0,'class':'ck-ai-button-primary'}),_0xcbed89['on']('execute',()=>{this['_isValid']()&&this['fire']('runReviewCheck',{'id':'custom','args':{'prompt':this['prompt'],'model':this['modelId']},'isCustom':!0x0});}),_0xcbed89;}['_createCancelButtonView'](){const _0x416afd=new _0x238f63(this['locale']),t=this['locale']['t'];return _0x416afd['set']({'label':t('Cancel'),'withText':!0x0,'class':'ck-ai-button-tertiary-filled'}),_0x416afd['extendTemplate']({'on':{'click':this['bindTemplate']['to'](_0x3566d9=>{_0x3566d9['stopPropagation']();})}}),_0x416afd['on']('execute',()=>{this['resetToDefault'](),this['fire']('closeCustomCheck');}),_0x416afd;}['_setModelList'](){this['_modelSelectionDropdownItems']['clear']();const _0x5bdcd6=this['_check']['models'];if(this['resetToDefault'](),_0x5bdcd6?.['length']){const _0x27be66=_0x1f1125['getLocalized'](this['locale'],_0x5bdcd6);for(const _0x119ae1 of _0x27be66){const _0x5fe39=new _0x15a683({'label':_0x119ae1['name'],'withText':!0x0,'role':'menuitemradio','id':_0x119ae1['id'],'model':_0x119ae1});_0x5fe39['bind']('isOn')['to'](this,'modelId',_0x29bef5=>_0x29bef5===_0x119ae1['id']),this['_modelSelectionDropdownItems']['add']({'type':'button','model':_0x5fe39,'labelView':new Xs(this['locale'],_0x119ae1)});}}}['_createModelSelectionDropdown'](){const _0xc9531=_0x440797(this['locale']);return _0xc9531['set']({'panelPosition':'se','class':'ck-ai-review-mode__check-list-item-model-dropdown'}),_0xc9531['buttonView']['set']({'label':this['_defaultLabel'],'withText':!0x0,'tooltip':!0x0}),this['listenTo'](_0xc9531,'execute',_0x4932d1=>{this['modelId']=_0x4932d1['source']['model']['id'],_0xc9531['buttonView']['label']=_0x4932d1['source']['label'];}),_0xc9531;}['_createActionsFooterView'](){const _0x404db3=new _0x14e58e(this['locale']);return _0x404db3['setTemplate']({'tag':'div','attributes':{'class':['ck-ai-review-mode__check-list-item-custom-actions-footer']},'children':[this['_modelSelectionDropdown'],{'tag':'div','attributes':{'class':['ck-ai-review-mode__check-list-item-parameterized-custom-actions-buttons']},'children':[this['cancelButtonView'],this['submitButtonView']]}]}),_0x404db3;}}class Xs extends _0xc6c098{constructor(_0x292278,_0x12ff4b){super();const _0x147c18=this['bindTemplate'];this['setTemplate']({'tag':'div','attributes':{'class':['ck','ck-button__label'],'style':_0x147c18['to']('style'),'id':_0x147c18['to']('id')},'children':[{'tag':'div','attributes':{'class':['ck-ai-review-mode__check-list-item-model-dropdown-name']},'children':[{'tag':'span','children':[{'text':_0x147c18['to']('text')}]}]},{'tag':'div','attributes':{'class':['ck-ai-review-mode__check-list-item-model-dropdown-description']},'children':[{'tag':'span','children':[_0x12ff4b['description']||'']}]}]});}}