@univerjs/sheets-data-validation-ui 0.18.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1,51 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`@univerjs/core`),l=require(`@univerjs/engine-render`),u=require(`@univerjs/sheets`),d=require(`@univerjs/sheets-data-validation`),f=require(`@univerjs/data-validation`),p=require(`@univerjs/ui`),m=require(`rxjs`),h=require(`@univerjs/sheets-numfmt`),g=require(`@univerjs/sheets-ui`),_=require(`@univerjs/design`),v=require(`react`);v=s(v);let y=require(`@univerjs/icons`),b=require(`@univerjs/engine-formula`),x=require(`@univerjs/sheets-formula-ui`),S=require(`react/jsx-runtime`);var C=`@univerjs/sheets-data-validation-ui`,w=`0.18.0`;function T(e){"@babel/helpers - typeof";return T=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},T(e)}function E(e,t){if(T(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(T(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function D(e){var t=E(e,`string`);return T(t)==`symbol`?t:t+``}function O(e,t,n){return(t=D(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function k(e,t){return function(n,r){t(n,r,e)}}function A(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let j=class extends c.Disposable{get activeRule(){return this._activeRule}get isOpen(){return this._open$.getValue()}constructor(e,t){super(),this._univerInstanceService=e,this._sidebarService=t,O(this,`_open$`,new m.BehaviorSubject(!1)),O(this,`open$`,this._open$.pipe((0,m.distinctUntilChanged)())),O(this,`_activeRule`,void 0),O(this,`_activeRule$`,new m.BehaviorSubject(void 0)),O(this,`activeRule$`,this._activeRule$.asObservable()),O(this,`_closeDisposable`,null),O(this,`_focusFormulaEditorActiveRuleSubUnitId`,null),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET).pipe((0,m.filter)(e=>!e)).subscribe(()=>{this.close()})),this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(e=>{e.id===`DataValidationPanel`&&(e.visible||setTimeout(()=>{this._sidebarService.sidebarOptions$.next({visible:!1})}))}))}dispose(){var e;super.dispose(),this._open$.next(!1),this._open$.complete(),this._activeRule$.complete(),(e=this._closeDisposable)==null||e.dispose()}open(){this._open$.next(!0)}close(){var e;this._open$.next(!1),(e=this._closeDisposable)==null||e.dispose()}setCloseDisposable(e){this._closeDisposable=(0,c.toDisposable)(()=>{e.dispose(),this._closeDisposable=null})}setActiveRule(e){this._activeRule=e,this._activeRule$.next(e)}setFocusFormulaEditorActiveRuleSubUnitId(e){this._focusFormulaEditorActiveRuleSubUnitId=e}getFocusFormulaEditorActiveRuleSubUnitId(){return this._focusFormulaEditorActiveRuleSubUnitId}};j=A([k(0,c.IUniverInstanceService),k(1,p.ISidebarService)],j);const M=`sheets-data-validation-ui.config`;Symbol(M);const N={};let P=class extends c.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetInterceptorService=e,this._dataValidationModel=t,this._dataValidatorRegistryService=n,this._dialogService=r,this._localeService=i,this._sheetsDataValidationValidatorService=a,this._initEditorBridgeInterceptor()}_initEditorBridgeInterceptor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(u.VALIDATE_CELL,{handler:async(e,t,n)=>{let r=await e,{row:i,col:a,unitId:o,subUnitId:s}=t,l=this._dataValidationModel.getRuleIdByLocation(o,s,i,a),u=l?this._dataValidationModel.getRuleById(o,s,l):void 0;if(r===!1)return n(Promise.resolve(!1));if(!u||u.errorStyle!==c.DataValidationErrorStyle.STOP)return n(Promise.resolve(!0));let d=this._dataValidatorRegistryService.getValidatorItem(u.type);return!d||await this._sheetsDataValidationValidatorService.validatorCell(o,s,i,a)===c.DataValidationStatus.VALID?n(Promise.resolve(!0)):(this._dialogService.open({width:368,title:{title:this._localeService.t(`dataValidation.alert.title`)},id:`reject-input-dialog`,children:{title:d.getRuleFinalError(u,{row:i,col:a,unitId:o,subUnitId:s})},footer:{title:(0,v.createElement)(_.Button,{variant:`primary`,onClick:()=>this._dialogService.close(`reject-input-dialog`)},this._localeService.t(`dataValidation.alert.ok`))},onClose:()=>{this._dialogService.close(`reject-input-dialog`)}}),n(Promise.resolve(!1)))}}))}showReject(e){this._dialogService.open({width:368,title:{title:this._localeService.t(`dataValidation.alert.title`)},id:`reject-input-dialog`,children:{title:e},footer:{title:(0,v.createElement)(_.Button,{variant:`primary`,onClick:()=>this._dialogService.close(`reject-input-dialog`)},this._localeService.t(`dataValidation.alert.ok`))},onClose:()=>{this._dialogService.close(`reject-input-dialog`)}})}};P=A([k(0,(0,c.Inject)(u.SheetInterceptorService)),k(1,(0,c.Inject)(d.SheetDataValidationModel)),k(2,(0,c.Inject)(f.DataValidatorRegistryService)),k(3,p.IDialogService),k(4,(0,c.Inject)(c.LocaleService)),k(5,(0,c.Inject)(d.SheetsDataValidationValidatorService))],P);const F=e=>{if(e==null||typeof e==`boolean`)return;if(e===``)return(0,c.dayjs)();if(typeof e==`number`||!Number.isNaN(+e))return(0,c.dayjs)(c.numfmt.format(`yyyy-MM-dd HH:mm:ss`,Number(e)));let t=(0,c.dayjs)(e);if(t.isValid())return t};function I(e,t){if(e===(0,h.getPatternType)(t))return t;switch(e){case`datetime`:return`yyyy-MM-dd hh:mm:ss`;case`date`:return`yyyy-MM-dd`;case`time`:return`HH:mm:ss`}}let L=class extends c.Disposable{get activeDropdown(){return this._activeDropdown}constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._univerInstanceService=e,this._dataValidatorRegistryService=t,this._zenZoneService=n,this._dataValidationModel=r,this._sheetsSelectionsService=i,this._cellDropdownManagerService=a,this._sheetDataValidationModel=o,this._commandService=s,this._editorBridgeService=c,this._injector=l,this._configService=u,O(this,`_activeDropdown`,void 0),O(this,`_activeDropdown$`,new m.Subject),O(this,`_currentPopup`,null),O(this,`activeDropdown$`,this._activeDropdown$.asObservable()),O(this,`_zenVisible`,!1),this._init(),this._initSelectionChange(),this.disposeWithMe(()=>{this._activeDropdown$.complete()})}_init(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{this._zenVisible=e,e&&this.hideDropdown()}))}_getDropdownByCell(e,t,n,r){let i=e?this._univerInstanceService.getUnit(e,c.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET);if(!i)return;let a=t?i.getSheetBySheetId(t):i.getActiveSheet();if(!a)return;let o=this._dataValidationModel.getRuleByLocation(i.getUnitId(),a.getSheetId(),n,r);if(!o)return;let s=this._dataValidatorRegistryService.getValidatorItem(o.type);return s==null?void 0:s.dropdownType}_initSelectionChange(){this.disposeWithMe(this._sheetsSelectionsService.selectionMoveEnd$.subscribe(e=>{e&&e.every(e=>!(e.primary&&this._getDropdownByCell(e.primary.unitId,e.primary.sheetId,e.primary.actualRow,e.primary.actualColumn)))&&this.hideDropdown()}))}showDropdown(e){let{location:t}=e,{row:n,col:r,unitId:i,subUnitId:a,workbook:o,worksheet:s}=t;if(this._currentPopup&&this._currentPopup.dispose(),this._zenVisible)return;this._activeDropdown=e,this._activeDropdown$.next(this._activeDropdown);let m=this._sheetDataValidationModel.getRuleByLocation(i,a,n,r);if(!m)return;let h=this._dataValidatorRegistryService.getValidatorItem(m.type);if(!(h!=null&&h.dropdownType))return;let _,v=async(e,t)=>{var d,f,_;if(!e)return!0;let v=e,y=s.getCell(n,r),b=v.format(t===`date`?`YYYY-MM-DD 00:00:00`:`YYYY-MM-DD HH:mm:ss`),x=(d=c.numfmt.parseDate(b))==null?void 0:d.v,S=t===`time`?x%1:x,C=o.getStyles().getStyleByCell(y),w=(f=C==null||(_=C.n)==null?void 0:_.pattern)==null?``:f;return m.errorStyle!==c.DataValidationErrorStyle.STOP||await h.validator({value:S,unitId:i,subUnitId:a,row:n,column:r,worksheet:s,workbook:o,interceptValue:b.replace(`Z`,``).replace(`T`,` `),t:c.CellValueType.NUMBER},m)?(await this._commandService.executeCommand(u.SetRangeValuesCommand.id,{unitId:i,subUnitId:a,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:S,t:2,p:null,f:null,si:null,s:{n:{pattern:I(t,w)}}}}),await this._commandService.executeCommand(g.SetCellEditVisibleOperation.id,{visible:!1,eventType:l.DeviceInputEventType.Keyboard,unitId:i,keycode:p.KeyCode.ESC}),!0):(this._injector.has(P)&&this._injector.get(P).showReject(h.getRuleFinalError(m,{row:n,col:r,unitId:i,subUnitId:a})),!1)},y;switch(h.dropdownType){case f.DataValidatorDropdownType.DATE:{var b;let e=F((0,d.getCellValueOrigin)(s.getCellRaw(n,r))),i=!!((b=m.bizInfo)!=null&&b.showTime);y={location:t,type:`datepicker`,props:{showTime:i,onChange:e=>v(e,i?`datetime`:`date`),defaultValue:e,patternType:`date`}};break}case f.DataValidatorDropdownType.TIME:y={location:t,type:`datepicker`,props:{onChange:e=>v(e,`time`),defaultValue:F((0,d.getCellValueOrigin)(s.getCellRaw(n,r))),patternType:`time`}};break;case f.DataValidatorDropdownType.DATETIME:y={location:t,type:`datepicker`,props:{onChange:e=>v(e,`datetime`),defaultValue:F((0,d.getCellValueOrigin)(s.getCellRaw(n,r))),patternType:`datetime`}};break;case f.DataValidatorDropdownType.LIST:case f.DataValidatorDropdownType.MULTIPLE_LIST:{var x,S,C,w;let e=h.dropdownType===f.DataValidatorDropdownType.MULTIPLE_LIST,o=async t=>{let o=(0,d.serializeListOptions)(t),s={unitId:i,subUnitId:a,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:o,p:null,f:null,si:null}};return this._commandService.executeCommand(u.SetRangeValuesCommand.id,s),this._editorBridgeService.isVisible().visible&&await this._commandService.executeCommand(g.SetCellEditVisibleOperation.id,{visible:!1,eventType:l.DeviceInputEventType.Keyboard,unitId:i,keycode:p.KeyCode.ESC}),!e},v=(m==null?void 0:m.renderMode)===c.DataValidationRenderMode.CUSTOM||(m==null?void 0:m.renderMode)===void 0,b=h.getListWithColor(m,i,a),T=(0,d.getDataValidationCellValue)(s.getCellRaw(n,r));y={location:t,type:`list`,props:{onChange:e=>o(e),options:b.map(e=>({label:e.label,value:e.label,color:v||e.color?e.color||`#ECECEC`:`transparent`})),onEdit:()=>{this._commandService.executeCommand(z.id,{ruleId:m.uid}),_==null||_.dispose()},defaultValue:T,multiple:e,showEdit:(x=(S=this._configService.getConfig(`sheets-data-validation-ui.config`))==null?void 0:S.showEditOnDropdown)==null?!0:x,showSearch:(C=(w=this._configService.getConfig(`sheets-data-validation-ui.config`))==null?void 0:w.showSearchOnDropdown)==null?!0:C}};break}case f.DataValidatorDropdownType.CASCADE:var T;y={type:`cascader`,props:{onChange:e=>{let t={unitId:i,subUnitId:a,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:e.join(`/`),p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(u.SetRangeValuesCommand.id,t),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(g.SetCellEditVisibleOperation.id,{visible:!1,eventType:l.DeviceInputEventType.Keyboard,unitId:i,keycode:p.KeyCode.ESC}),!0},defaultValue:(0,d.getDataValidationCellValue)(s.getCellRaw(n,r)).split(`/`),options:JSON.parse((T=m.formula1)==null?`[]`:T)},location:t};break;case f.DataValidatorDropdownType.COLOR:y={type:`color`,props:{onChange:e=>{let t={unitId:i,subUnitId:a,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:e,p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(u.SetRangeValuesCommand.id,t),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(g.SetCellEditVisibleOperation.id,{visible:!1,eventType:l.DeviceInputEventType.Keyboard,unitId:i,keycode:p.KeyCode.ESC}),!0},defaultValue:(0,d.getDataValidationCellValue)(s.getCellRaw(n,r))},location:t};break;default:throw Error(`[DataValidationDropdownManagerService]: unknown type!`)}if(_=this._cellDropdownManagerService.showDropdown({...y,onHide:()=>{this._activeDropdown=null,this._activeDropdown$.next(null)}}),!_)throw Error(`[DataValidationDropdownManagerService]: cannot show dropdown!`);let E=new c.DisposableCollection;E.add(_),E.add({dispose:()=>{var e,t;(e=this._activeDropdown)==null||(t=e.onHide)==null||t.call(e)}}),this._currentPopup=E}hideDropdown(){this._activeDropdown&&(this._currentPopup&&this._currentPopup.dispose(),this._currentPopup=null,this._activeDropdown=null,this._activeDropdown$.next(null))}showDataValidationDropdown(e,t,n,r,i){let a=this._univerInstanceService.getUnit(e,c.UniverInstanceType.UNIVER_SHEET);if(!a)return;let o=a.getSheetBySheetId(t);if(!o)return;let s=this._dataValidationModel.getRuleByLocation(a.getUnitId(),o.getSheetId(),n,r);if(!s)return;let l=this._dataValidatorRegistryService.getValidatorItem(s.type);if(!l||!l.dropdownType){this.hideDropdown();return}this.showDropdown({location:{workbook:a,worksheet:o,row:n,col:r,unitId:e,subUnitId:t},onHide:i})}};L=A([k(0,c.IUniverInstanceService),k(1,(0,c.Inject)(f.DataValidatorRegistryService)),k(2,p.IZenZoneService),k(3,(0,c.Inject)(d.SheetDataValidationModel)),k(4,(0,c.Inject)(u.SheetsSelectionsService)),k(5,(0,c.Inject)(g.ISheetCellDropdownManagerService)),k(6,(0,c.Inject)(d.SheetDataValidationModel)),k(7,c.ICommandService),k(8,g.IEditorBridgeService),k(9,(0,c.Inject)(c.Injector)),k(10,c.IConfigService)],L);const R=`DataValidationPanel`,z={id:`data-validation.operation.open-validation-panel`,type:c.CommandType.OPERATION,handler(e,t){if(!t)return!1;let{ruleId:n,isAdd:r}=t,i=e.get(j),a=e.get(f.DataValidationModel),o=e.get(c.IUniverInstanceService),s=e.get(p.ISidebarService),l=(0,u.getSheetCommandTarget)(o);if(!l)return!1;let{unitId:d,subUnitId:m}=l,h=n?a.getRuleById(d,m,n):void 0;i.open(),i.setActiveRule(h&&{unitId:d,subUnitId:m,rule:h});let g=s.open({id:R,header:{title:r?`dataValidation.panel.addTitle`:`dataValidation.panel.title`},children:{label:R},width:312,onClose:()=>i.close()});return i.setCloseDisposable(g),!0}},B={id:`data-validation.operation.close-validation-panel`,type:c.CommandType.OPERATION,handler(e){return e.get(j).close(),!0}},V={id:`data-validation.operation.toggle-validation-panel`,type:c.CommandType.OPERATION,handler(e){let t=e.get(c.ICommandService),n=e.get(j);return n.open(),n.isOpen?t.executeCommand(B.id):t.executeCommand(z.id),!0}},H={type:c.CommandType.OPERATION,id:`sheet.operation.show-data-validation-dropdown`,handler(e,t){if(!t)return!1;let n=e.get(L),{unitId:r,subUnitId:i,row:a,column:o}=t,s=n.activeDropdown,c=s==null?void 0:s.location;return c&&c.unitId===r&&c.subUnitId===i&&c.row===a&&c.col===o||n.showDataValidationDropdown(r,i,a,o),!0}},U={type:c.CommandType.OPERATION,id:`sheet.operation.hide-data-validation-dropdown`,handler(e,t){return t?(e.get(L).hideDropdown(),!0):!1}},W={type:c.CommandType.COMMAND,id:`data-validation.command.addRuleAndOpen`,handler(e){let t=(0,u.getSheetCommandTarget)(e.get(c.IUniverInstanceService));if(!t)return!1;let{workbook:n,worksheet:r}=t,i=(0,d.createDefaultNewRule)(e),a=e.get(c.ICommandService),o={rule:i,unitId:n.getUnitId(),subUnitId:r.getSheetId()};return a.syncExecuteCommand(d.AddSheetDataValidationCommand.id,o)?(a.syncExecuteCommand(z.id,{ruleId:i.uid,isAdd:!0}),!0):!1}},G=`SHEET_DATA_VALIDATION_ALERT`;let K=class extends c.Disposable{constructor(e,t,n,r,i,a){super(),this._hoverManagerService=e,this._cellAlertManagerService=t,this._univerInstanceService=n,this._localeService=r,this._zenZoneService=i,this._dataValidationModel=a,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0,m.debounceTime)(100)).subscribe(e=>{if(e){let n=this._univerInstanceService.getUnit(e.location.unitId,c.UniverInstanceType.UNIVER_SHEET),r=n.getSheetBySheetId(e.location.subUnitId);if(!r)return;let i=this._dataValidationModel.getRuleByLocation(e.location.unitId,e.location.subUnitId,e.location.row,e.location.col);if(!i){this._cellAlertManagerService.removeAlert(G);return}if(this._dataValidationModel.validator(i,{...e.location,workbook:n,worksheet:r})===c.DataValidationStatus.INVALID){var t;let n=this._cellAlertManagerService.currentAlert.get(G),r=n==null||(t=n.alert)==null?void 0:t.location;if(r&&r.row===e.location.row&&r.col===e.location.col&&r.subUnitId===e.location.subUnitId&&r.unitId===e.location.unitId){this._cellAlertManagerService.removeAlert(G);return}let a=this._dataValidationModel.getValidator(i.type);if(!a){this._cellAlertManagerService.removeAlert(G);return}this._cellAlertManagerService.showAlert({type:g.CellAlertType.ERROR,title:this._localeService.t(`dataValidation.error.title`),message:a==null?void 0:a.getRuleFinalError(i,e.location),location:e.location,width:200,height:74,key:G});return}}this._cellAlertManagerService.removeAlert(G)}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._cellAlertManagerService.removeAlert(G)}))}};K=A([k(0,(0,c.Inject)(g.HoverManagerService)),k(1,(0,c.Inject)(g.CellAlertManagerService)),k(2,c.IUniverInstanceService),k(3,(0,c.Inject)(c.LocaleService)),k(4,p.IZenZoneService),k(5,(0,c.Inject)(d.SheetDataValidationModel))],K);let q=class extends c.Disposable{constructor(e,t,n){super(),this._autoFillService=e,this._sheetDataValidationModel=t,this._injector=n,this._initAutoFill()}_initAutoFill(){let e=()=>({redos:[],undos:[]}),t=(e,t)=>{let{source:n,target:r,unitId:i,subUnitId:a}=e,o=this._sheetDataValidationModel.getRuleObjectMatrix(i,a).clone(),s=(0,g.virtualizeDiscreteRanges)([n,r]),[l,f]=s.ranges,{mapFunc:p}=s,m={row:l.startRow,col:l.startColumn},h=u.AutoFillTools.getAutoFillRepeatRange(l,f),_=new c.ObjectMatrix,v=new Set;h.forEach(e=>{let t=e.repeatStartCell,n=e.relativeRange,r={startRow:m.row,startColumn:m.col,endColumn:m.col,endRow:m.row},o={startRow:t.row,startColumn:t.col,endColumn:t.col,endRow:t.row};c.Range.foreach(n,(e,t)=>{let n=c.Rectangle.getPositionRange({startRow:e,startColumn:t,endColumn:t,endRow:e},r),{row:s,col:l}=p(n.startRow,n.startColumn),u=this._sheetDataValidationModel.getRuleIdByLocation(i,a,s,l)||``,d=c.Rectangle.getPositionRange({startRow:e,startColumn:t,endColumn:t,endRow:e},o),{row:f,col:m}=p(d.startRow,d.startColumn);_.setValue(f,m,u),v.add(u)})});let y=Array.from(v).map(e=>({id:e,ranges:(0,c.queryObjectMatrix)(_,t=>t===e)}));o.addRangeRules(y);let{redoMutations:b,undoMutations:x}=(0,d.getDataValidationDiffMutations)(i,a,o.diff(this._sheetDataValidationModel.getRules(i,a)),this._injector,`patched`,t===u.AUTO_FILL_APPLY_TYPE.ONLY_FORMAT);return{undos:x,redos:b}},n={id:d.DATA_VALIDATION_PLUGIN_NAME,onBeforeFillData:e=>{let{source:t,unitId:n,subUnitId:r}=e;for(let e of t.rows)for(let i of t.cols){let t=this._sheetDataValidationModel.getRuleByLocation(n,r,e,i);if(t&&t.type===c.DataValidationType.CHECKBOX){this._autoFillService.setDisableApplyType(u.AUTO_FILL_APPLY_TYPE.SERIES,!0);return}}},onFillData:(n,r,i)=>i===u.AUTO_FILL_APPLY_TYPE.COPY||i===u.AUTO_FILL_APPLY_TYPE.ONLY_FORMAT||i===u.AUTO_FILL_APPLY_TYPE.SERIES?t(n,i):e(),onAfterFillData:()=>{}};this.disposeWithMe(this._autoFillService.addHook(n))}};q=A([k(0,u.IAutoFillService),k(1,(0,c.Inject)(d.SheetDataValidationModel)),k(2,(0,c.Inject)(c.Injector))],q);let J=class extends c.Disposable{constructor(e,t,n){super(),this._sheetClipboardService=e,this._sheetDataValidationModel=t,this._injector=n,O(this,`_copyInfo`,void 0),this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:d.DATA_VALIDATION_PLUGIN_NAME,onBeforeCopy:(e,t,n)=>this._collect(e,t,n),onPasteCells:(e,t,n,r)=>{let{copyType:i=g.COPY_TYPE.COPY,pasteType:a}=r,{range:o}=e||{},{range:s,unitId:c,subUnitId:l}=t;return this._generateMutations(s,{copyType:i,pasteType:a,copyRange:o,unitId:c,subUnitId:l})}})}_collect(e,t,n){let r=new c.ObjectMatrix;this._copyInfo={unitId:e,subUnitId:t,matrix:r};let i=this._injector.invoke(r=>(0,u.rangeToDiscreteRange)(n,r,e,t));if(!i)return;let{rows:a,cols:o}=i;a.forEach((n,i)=>{o.forEach((a,o)=>{let s=this._sheetDataValidationModel.getRuleIdByLocation(e,t,n,a);r.setValue(i,o,s==null?``:s)})})}_generateMutations(e,t){if(!this._copyInfo)return{redos:[],undos:[]};if(t.copyType===g.COPY_TYPE.CUT)return this._copyInfo=null,{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!t.copyRange||[g.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,g.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,g.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,g.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA].includes(t.pasteType))return{redos:[],undos:[]};let{unitId:n,subUnitId:r}=this._copyInfo;if(t.unitId!==n||r!==t.subUnitId){let i=this._sheetDataValidationModel.getRuleObjectMatrix(t.unitId,t.subUnitId).clone(),a=new c.ObjectMatrix,o=new Set,{ranges:[s,l],mapFunc:u}=(0,g.virtualizeDiscreteRanges)([t.copyRange,e]),f=(0,g.getRepeatRange)(s,l,!0),p=new Map;f.forEach(({startRange:e})=>{var i;(i=this._copyInfo)==null||i.matrix.forValue((i,s,l)=>{let d=c.Rectangle.getPositionRange({startRow:i,endRow:i,startColumn:s,endColumn:s},e),f=`${r}-${l}`,m=this._sheetDataValidationModel.getRuleById(n,r,l);!this._sheetDataValidationModel.getRuleById(t.unitId,t.subUnitId,f)&&m&&p.set(f,{...m,uid:f});let{row:h,col:g}=u(d.startRow,d.startColumn);o.add(f),a.setValue(h,g,f)})});let m=Array.from(o).map(e=>({id:e,ranges:(0,c.queryObjectMatrix)(a,t=>t===e)}));i.addRangeRules(m);let{redoMutations:h,undoMutations:_}=(0,d.getDataValidationDiffMutations)(t.unitId,t.subUnitId,i.diffWithAddition(this._sheetDataValidationModel.getRules(t.unitId,t.subUnitId),p.values()),this._injector,`patched`,!1);return{redos:h,undos:_}}else{let i=this._sheetDataValidationModel.getRuleObjectMatrix(n,r).clone(),a=new c.ObjectMatrix,o=new Set,{ranges:[s,l],mapFunc:u}=(0,g.virtualizeDiscreteRanges)([t.copyRange,e]);(0,g.getRepeatRange)(s,l,!0).forEach(({startRange:e})=>{var t;(t=this._copyInfo)==null||t.matrix.forValue((t,n,r)=>{let i=c.Rectangle.getPositionRange({startRow:t,endRow:t,startColumn:n,endColumn:n},e),{row:s,col:l}=u(i.startRow,i.startColumn);a.setValue(s,l,r),o.add(r)})});let f=Array.from(o).map(e=>({id:e,ranges:(0,c.queryObjectMatrix)(a,t=>t===e)}));i.addRangeRules(f);let{redoMutations:p,undoMutations:m}=(0,d.getDataValidationDiffMutations)(n,r,i.diff(this._sheetDataValidationModel.getRules(n,r)),this._injector,`patched`,!1);return{redos:p,undos:m}}}};J=A([k(0,g.ISheetClipboardService),k(1,(0,c.Inject)(d.SheetDataValidationModel)),k(2,(0,c.Inject)(c.Injector))],J);let Y=class extends c.Disposable{constructor(e,t,n){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=n,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===d.AddSheetDataValidationCommand.id){let{unitId:t,subUnitId:n,rule:{ranges:r}}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[u.WorkbookEditablePermission],rangeTypes:[u.RangeProtectionPermissionEditPoint],worksheetTypes:[u.WorksheetEditPermission,u.WorksheetSetCellStylePermission]},r,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.setStyleErr`))}if(e.id===d.UpdateSheetDataValidationRangeCommand.id){let{unitId:t,subUnitId:n,ranges:r}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[u.WorkbookEditablePermission],rangeTypes:[u.RangeProtectionPermissionEditPoint],worksheetTypes:[u.WorksheetEditPermission,u.WorksheetSetCellStylePermission]},r,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.setStyleErr`))}}))}};Y=A([k(0,(0,c.Inject)(c.LocaleService)),k(1,c.ICommandService),k(2,(0,c.Inject)(u.SheetPermissionCheckController))],Y);const ee=`sheet.menu.data-validation`;function te(e){return{id:ee,type:p.MenuItemType.SUBITEMS,icon:`DataValidationIcon`,tooltip:`dataValidation.title`,hidden$:(0,p.getMenuHiddenObservable)(e,c.UniverInstanceType.UNIVER_SHEET),disabled$:(0,g.getCurrentRangeDisable$)(e,{workbookTypes:[u.WorkbookEditablePermission],worksheetTypes:[u.WorksheetSetCellStylePermission,u.WorksheetEditPermission],rangeTypes:[u.RangeProtectionPermissionEditPoint]})}}function X(e){return{id:z.id,title:`dataValidation.panel.title`,type:p.MenuItemType.BUTTON}}function ne(e){return{id:W.id,title:`dataValidation.panel.add`,type:p.MenuItemType.BUTTON}}const re={[p.RibbonDataGroup.RULES]:{[ee]:{order:0,menuItemFactory:te,[z.id]:{order:0,menuItemFactory:X},[W.id]:{order:1,menuItemFactory:ne}}}},ie={tr:{size:6,color:`#fe4b4b`}};let Z=class extends c.RxDisposable{constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._commandService=e,this._menuManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._autoHeightController=i,this._dropdownManagerService=a,this._sheetDataValidationModel=o,this._dataValidatorRegistryService=s,this._sheetInterceptorService=c,this._dataValidationCacheService=l,this._editorBridgeService=u,this._initMenu(),this._initDropdown(),this._initViewModelIntercept(),this._initAutoHeight()}_initMenu(){this._menuManagerService.mergeMenu(re)}_initDropdown(){this._editorBridgeService&&this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{if(!e.visible){var t;((t=this._dropdownManagerService.activeDropdown)==null?void 0:t.trigger)===`editor-bridge`&&this._dropdownManagerService.hideDropdown();return}let n=this._editorBridgeService.getEditCellState();if(n){let{unitId:e,sheetId:t,row:r,column:i}=n,a=this._univerInstanceService.getUniverSheetInstance(e);if(!a)return;let o=this._sheetDataValidationModel.getRuleByLocation(e,t,r,i);if(!o)return;let s=this._dataValidatorRegistryService.getValidatorItem(o.type);if(!(s!=null&&s.dropdownType))return;let c=a.getActiveSheet();if(!c)return;let l=this._dropdownManagerService.activeDropdown,u=l==null?void 0:l.location;if(u&&u.unitId===e&&u.subUnitId===t&&u.row===r&&u.col===i)return;this._dropdownManagerService.showDropdown({location:{unitId:e,subUnitId:t,row:r,col:i,workbook:a,worksheet:c},trigger:`editor-bridge`,closeOnOutSide:!1})}}))}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(u.INTERCEPTOR_POINT.CELL_CONTENT,{effect:c.InterceptorEffectEnum.Style,priority:u.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,t,n)=>{var r,i,a,o,s;let{row:l,col:u,unitId:f,subUnitId:p,workbook:m,worksheet:h}=t,_=this._sheetDataValidationModel.getRuleIdByLocation(f,p,l,u);if(!_)return n(e);let v=this._sheetDataValidationModel.getRuleById(f,p,_);if(!v)return n(e);let y=(r=this._dataValidationCacheService.getValue(f,p,l,u))==null?c.DataValidationStatus.VALID:r,b=this._dataValidatorRegistryService.getValidatorItem(v.type),x=t.rawData,S,C={get value(){var e;return S===void 0&&(S=(e=(0,d.getCellValueOrigin)(x))==null?null:e),S}},w={get value(){var e;return`${(e=C.value)==null?``:e}`}};return(!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,...y===c.DataValidationStatus.INVALID?ie:null},e.customRender=[...(i=e==null?void 0:e.customRender)==null?[]:i,...b!=null&&b.canvasRender?[b.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:(e==null||(a=e.fontRenderExtension)==null?void 0:a.isSkip)||(b==null||(o=b.skipDefaultFontRender)==null?void 0:o.call(b,v,C.value,t))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...b==null?void 0:b.getExtraStyle(v,w.value,{get style(){let t=m.getStyles();return(typeof(e==null?void 0:e.s)==`string`?t.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},l,u)},e.interceptorAutoHeight=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(g.SheetSkeletonManagerService).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(l,u),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?l:n,(r=s==null?void 0:s.startColumn)==null?u:r),unitId:f,subUnitId:p,row:l,col:u,workbook:m,worksheet:h};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoHeight)==null?void 0:a.call(i,c)},e.interceptorAutoWidth=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(g.SheetSkeletonManagerService).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(l,u),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?l:n,(r=s==null?void 0:s.startColumn)==null?u:r),unitId:f,subUnitId:p,row:l,col:u,workbook:m,worksheet:h};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoWidth)==null?void 0:a.call(i,c)},e.coverable=((s=e==null?void 0:e.coverable)==null?!0:s)&&!(v.type===c.DataValidationType.LIST||v.type===c.DataValidationType.LIST_MULTIPLE),n(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe((0,m.filter)(e=>e.source===`command`),(0,m.bufferTime)(100)).subscribe(e=>{if(e.length===0)return;let t=[];e.forEach(e=>{if(e.rule.type===c.DataValidationType.LIST_MULTIPLE||e.rule.type===c.DataValidationType.LIST){var n;(n=e.rule)!=null&&n.ranges&&t.push(...e.rule.ranges)}}),t.length&&(0,c.sequenceExecute)(this._autoHeightController.getUndoRedoParamsOfAutoHeight(t).redos,this._commandService)})}};Z=A([k(0,c.ICommandService),k(1,p.IMenuManagerService),k(2,l.IRenderManagerService),k(3,c.IUniverInstanceService),k(4,(0,c.Inject)(g.AutoHeightController)),k(5,(0,c.Inject)(L)),k(6,(0,c.Inject)(d.SheetDataValidationModel)),k(7,(0,c.Inject)(f.DataValidatorRegistryService)),k(8,(0,c.Inject)(u.SheetInterceptorService)),k(9,(0,c.Inject)(d.DataValidationCacheService)),k(10,(0,c.Optional)(g.IEditorBridgeService))],Z);let ae=class extends c.RxDisposable{constructor(e,t,n,r,i,a,o){super(),this._commandService=e,this._renderManagerService=t,this._autoHeightController=n,this._dataValidatorRegistryService=r,this._sheetInterceptorService=i,this._sheetDataValidationModel=a,this._dataValidationCacheService=o,this._initViewModelIntercept(),this._initAutoHeight()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(u.INTERCEPTOR_POINT.CELL_CONTENT,{effect:c.InterceptorEffectEnum.Style,priority:u.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,t,n)=>{var r,i,a,o,s;let{row:l,col:u,unitId:f,subUnitId:p,workbook:m,worksheet:h}=t,_=this._sheetDataValidationModel.getRuleIdByLocation(f,p,l,u);if(!_)return n(e);let v=this._sheetDataValidationModel.getRuleById(f,p,_);if(!v)return n(e);let y=(r=this._dataValidationCacheService.getValue(f,p,l,u))==null?c.DataValidationStatus.VALID:r,b=this._dataValidatorRegistryService.getValidatorItem(v.type),x=(0,d.getCellValueOrigin)(h.getCellRaw(l,u)),S=`${x==null?``:x}`;return(!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,...y===c.DataValidationStatus.INVALID?ie:null},e.customRender=[...(i=e==null?void 0:e.customRender)==null?[]:i,...b!=null&&b.canvasRender?[b.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:(e==null||(a=e.fontRenderExtension)==null?void 0:a.isSkip)||(b==null||(o=b.skipDefaultFontRender)==null?void 0:o.call(b,v,x,t))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...b==null?void 0:b.getExtraStyle(v,S,{get style(){let t=m.getStyles();return(typeof(e==null?void 0:e.s)==`string`?t.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},l,u)},e.interceptorAutoHeight=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(g.SheetSkeletonManagerService).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(l,u),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?l:n,(r=s==null?void 0:s.startColumn)==null?u:r),unitId:f,subUnitId:p,row:l,col:u,workbook:m,worksheet:h};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoHeight)==null?void 0:a.call(i,c)},e.interceptorAutoWidth=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(g.SheetSkeletonManagerService).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(l,u),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?l:n,(r=s==null?void 0:s.startColumn)==null?u:r),unitId:f,subUnitId:p,row:l,col:u,workbook:m,worksheet:h};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoWidth)==null?void 0:a.call(i,c)},e.coverable=((s=e==null?void 0:e.coverable)==null?!0:s)&&!(v.type===c.DataValidationType.LIST||v.type===c.DataValidationType.LIST_MULTIPLE),n(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe((0,m.filter)(e=>e.source===`command`),(0,m.bufferTime)(16)).subscribe(e=>{let t=[];e.forEach(e=>{if(e.rule.type===c.DataValidationType.LIST_MULTIPLE||e.rule.type===c.DataValidationType.LIST){var n;(n=e.rule)!=null&&n.ranges&&t.push(...e.rule.ranges)}}),t.length&&(0,c.sequenceExecute)(this._autoHeightController.getUndoRedoParamsOfAutoHeight(t).redos,this._commandService)})}};ae=A([k(0,c.ICommandService),k(1,l.IRenderManagerService),k(2,(0,c.Inject)(g.AutoHeightController)),k(3,(0,c.Inject)(f.DataValidatorRegistryService)),k(4,(0,c.Inject)(u.SheetInterceptorService)),k(5,(0,c.Inject)(d.SheetDataValidationModel)),k(6,(0,c.Inject)(d.DataValidationCacheService))],ae);let oe=class extends c.Disposable{constructor(e,t,n){super(),this._context=e,this._sheetDataValidationModel=t,this._sheetSkeletonManagerService=n,this._initSkeletonChange()}_initSkeletonChange(){this.disposeWithMe(this._sheetDataValidationModel.validStatusChange$.pipe((0,c.bufferDebounceTime)(16)).subscribe(e=>{var t;if(!e.length)return;let n=new Set;e.forEach(e=>{n.add(e.subUnitId)}),n.forEach(e=>{var t;(t=this._sheetSkeletonManagerService.getSkeletonParam(e))==null||t.skeleton.makeDirty(!0)}),(t=this._context.mainComponent)==null||t.makeForceDirty()}))}};oe=A([k(1,(0,c.Inject)(d.SheetDataValidationModel)),k(2,(0,c.Inject)(g.SheetSkeletonManagerService))],oe);function se(e){var t;let n=(0,p.useDependency)(c.LocaleService),r=(0,p.useDependency)(p.ComponentManager),{value:i,onChange:a,extraComponent:o}=e,[s,l]=(0,v.useState)(!1),u=o?r.get(o):null;return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`
2
- univer-mb-3 univer-flex univer-cursor-pointer univer-items-center univer-text-sm univer-text-gray-900
3
- dark:!univer-text-white
4
- `,onClick:()=>l(!s),children:[n.t(`dataValidation.panel.options`),s?(0,S.jsx)(y.MoreUpIcon,{className:`univer-ml-1`}):(0,S.jsx)(y.MoreDownIcon,{className:`univer-ml-1`})]}),s&&(0,S.jsxs)(S.Fragment,{children:[u?(0,S.jsx)(u,{value:i,onChange:a}):null,(0,S.jsx)(_.FormLayout,{label:n.t(`dataValidation.panel.invalid`),children:(0,S.jsxs)(_.RadioGroup,{value:`${(t=i.errorStyle)==null?c.DataValidationErrorStyle.WARNING:t}`,onChange:e=>a({...i,errorStyle:+e}),children:[(0,S.jsx)(_.Radio,{value:`${c.DataValidationErrorStyle.WARNING}`,children:n.t(`dataValidation.panel.showWarning`)}),(0,S.jsx)(_.Radio,{value:`${c.DataValidationErrorStyle.STOP}`,children:n.t(`dataValidation.panel.rejectInput`)})]})}),(0,S.jsx)(_.FormLayout,{label:n.t(`dataValidation.panel.messageInfo`),children:(0,S.jsx)(_.Checkbox,{checked:i.showErrorMessage,onChange:()=>a({...i,showErrorMessage:!i.showErrorMessage}),children:n.t(`dataValidation.panel.showInfo`)})}),i.showErrorMessage?(0,S.jsx)(_.FormLayout,{children:(0,S.jsx)(_.Input,{value:i.error,onChange:e=>a({...i,error:e})})}):null]})]})}const ce=e=>(0,c.debounce)(async(t,n,r,i)=>{let a=await e.executeCommand(t,n,r);i==null||i(a)},1e3);function le(e,t,n){var r;if(t){var i;return((i=e.getUnit(t))==null||(i=i.getSheetBySheetName(n))==null?void 0:i.getSheetId())||``}return((r=e.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET))==null||(r=r.getSheetBySheetName(n))==null?void 0:r.getSheetId())||``}function ue(){var e,t;let[n,r]=(0,v.useState)(0),i=(0,p.useDependency)(j),{unitId:a,subUnitId:o,rule:s}=(0,p.useObservable)(i.activeRule$,i.activeRule)||{},l=s.uid,h=(0,p.useDependency)(f.DataValidatorRegistryService),g=(0,p.useDependency)(c.IUniverInstanceService),y=(0,p.useDependency)(p.ComponentManager),C=(0,p.useDependency)(c.ICommandService),w=(0,p.useDependency)(f.DataValidationModel),T=(0,p.useDependency)(c.LocaleService),E=(0,p.useObservable)(()=>g.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]),D=(0,p.useObservable)(()=>{var e;return(e=E==null?void 0:E.activeSheet$)==null?(0,m.of)(null):e},void 0,void 0,[]),[O,k]=(0,v.useState)(s),A=h.getValidatorItem(O.type),[M,N]=(0,v.useState)(!1),P=h.getValidatorsByScope(f.DataValidatorRegistryScope.SHEET),[F,I]=(0,v.useState)(()=>O.ranges.map(e=>({unitId:``,sheetId:``,range:e}))),L=(0,v.useMemo)(()=>ce(C),[C]),[R,z]=(0,v.useState)(!1),[B,V]=(0,v.useState)(!1),H=(0,v.useRef)(null),U=(0,p.useDependency)(u.SheetsSelectionsService);if((0,v.useEffect)(()=>()=>{let e=U.getCurrentLastSelection();e&&U.setSelections([e])},[U]),(0,v.useEffect)(()=>{C.onCommandExecuted(e=>{(e.id===c.UndoCommand.id||e.id===c.RedoCommand.id)&&setTimeout(()=>{let e=w.getRuleById(a,o,l);r(e=>e+1),e&&(k(e),I(e.ranges.map(e=>({unitId:``,sheetId:``,range:e}))))},20)})},[C,w,l,o,a]),!A)return null;let W=A.operators,G=A.operatorNames,K=O.operator?f.TWO_FORMULA_OPERATOR_COUNT.includes(O.operator):!1,q=()=>{(D==null?void 0:D.getSheetId())!==o&&C.syncExecuteCommand(u.SetWorksheetActiveOperation.id,{unitId:a,subUnitId:o})},J=()=>{var e;if(!((e=H.current)==null||(e=e.editor)==null)&&e.isFocus()){var t;Y((t=H.current)==null?void 0:t.getValue())}!O.ranges.length||R||(A.validatorFormula(O,a,o).success?i.setActiveRule(null):N(!0),q())},Y=(0,p.useEvent)(e=>{let t=e.split(`,`).filter(Boolean).map(b.deserializeRangeWithSheet).map(e=>{let t=e.sheetName;if(t){let n=le(g,e.unitId,t);return{...e,sheetId:n}}return{...e,sheetId:``}});if((0,c.isUnitRangesEqual)(t,F))return;I(t);let n=t.filter(e=>(!e.unitId||e.unitId===a)&&(!e.sheetId||e.sheetId===o)).map(e=>e.range);if(k({...O,ranges:n}),n.length===0)return;let r={unitId:a,subUnitId:o,ruleId:l,ranges:n};L(d.UpdateSheetDataValidationRangeCommand.id,r)}),ee=e=>{if((0,c.shallowEqual)(e,(0,f.getRuleSetting)(O)))return;k({...O,...e});let t={unitId:a,subUnitId:o,ruleId:l,setting:e};L(d.UpdateSheetDataValidationSettingCommand.id,t,void 0)},te=async()=>{await C.executeCommand(d.RemoveSheetDataValidationCommand.id,{ruleId:l,unitId:a,subUnitId:o}),i.setActiveRule(null),q()},X={type:O.type,operator:O.operator,formula1:O.formula1,formula2:O.formula2,allowBlank:O.allowBlank},ne=e=>{let t=h.getValidatorItem(e);if(!t)return;let n=t.operators,r=w.getRuleById(a,o,l),i=e===(r==null?void 0:r.type)||e.includes(`list`)&&r!=null&&r.type.includes(`list`)?{...r,type:e}:{...O,type:e,operator:n[0],formula1:void 0,formula2:void 0};k(i),C.executeCommand(d.UpdateSheetDataValidationSettingCommand.id,{unitId:a,subUnitId:o,ruleId:O.uid,setting:(0,f.getRuleSetting)(i)})},re=y.get(A.formulaInput),ie=(0,v.useMemo)(()=>F.map(e=>(0,b.serializeRange)(e.range)).join(`,`),[]),Z=(0,f.getRuleOptions)(O),ae=e=>{(0,c.shallowEqual)(e,(0,f.getRuleOptions)(O))||(k({...O,...e}),L(d.UpdateSheetDataValidationOptionsCommand.id,{unitId:a,subUnitId:o,ruleId:l,options:e}))},oe=W.length&&!O.operator;return(0,S.jsxs)(`div`,{"data-u-comp":`data-validation-detail`,className:`univer-py-2`,children:[(0,S.jsx)(_.FormLayout,{label:T.t(`dataValidation.panel.range`),error:!O.ranges.length||R?T.t(`dataValidation.panel.rangeError`):``,children:(0,S.jsx)(x.RangeSelector,{selectorRef:H,unitId:a,subUnitId:o,initialValue:ie,onChange:(e,t)=>{var n;!B&&(n=H.current)!=null&&n.verify()&&Y(t)},onFocusChange:(e,t)=>{var n;V(e),!e&&t&&(n=H.current)!=null&&n.verify()&&Y(t)},onVerify:e=>z(!e)})}),(0,S.jsx)(_.FormLayout,{label:T.t(`dataValidation.panel.type`),children:(0,S.jsx)(_.Select,{className:`univer-w-full`,value:O.type,options:P==null||(e=P.sort((e,t)=>e.order-t.order))==null?void 0:e.map(e=>({label:T.t(e.title),value:e.id})),onChange:ne})}),W!=null&&W.length?(0,S.jsx)(_.FormLayout,{label:T.t(`dataValidation.panel.operator`),children:(0,S.jsx)(_.Select,{className:`univer-w-full`,value:`${O.operator}`,options:[{value:``,label:T.t(`dataValidation.operators.legal`)},...W.map((e,t)=>({value:`${e}`,label:G[t]}))],onChange:e=>{ee({...X,operator:e})}})}):null,re&&!oe?(0,S.jsx)(re,{isTwoFormula:K,value:{formula1:O.formula1,formula2:O.formula2},onChange:e=>{ee({...X,...e})},showError:M,validResult:A.validatorFormula(O,a,o),unitId:a,subUnitId:o,ruleId:l},n+O.type):null,(0,S.jsx)(_.FormLayout,{children:(0,S.jsx)(_.Checkbox,{checked:(t=O.allowBlank)==null?!0:t,onChange:()=>{var e;return ee({...X,allowBlank:!((e=O.allowBlank)==null||e)})},children:T.t(`dataValidation.panel.allowBlank`)})}),(0,S.jsx)(se,{value:Z,onChange:ae,extraComponent:A.optionsInput}),(0,S.jsxs)(`div`,{className:`univer-mt-5 univer-flex univer-flex-row univer-justify-end`,children:[(0,S.jsx)(_.Button,{className:`univer-ml-3`,onClick:te,children:T.t(`dataValidation.panel.removeRule`)}),(0,S.jsx)(_.Button,{className:`univer-ml-3`,variant:`primary`,onClick:J,children:T.t(`dataValidation.panel.done`)})]})]})}const de=e=>{let{rule:t,onClick:n,unitId:r,subUnitId:i,disable:a}=e,o=(0,p.useDependency)(f.DataValidatorRegistryService),s=(0,p.useDependency)(c.ICommandService),l=(0,p.useDependency)(g.IMarkSelectionService),u=o.getValidatorItem(t.type),m=(0,v.useRef)(void 0),[h,x]=(0,v.useState)(!1),C=(0,p.useDependency)(c.ThemeService),w=(0,v.useMemo)(()=>{var e;let t=C.getColorFromTheme(`primary.600`),n=C.getColorFromTheme(`loop-color.2`),r=(e=C.getColorFromTheme(n))==null?t:e,i=new c.ColorKit(r).toRgb();return{fill:`rgba(${i.r}, ${i.g}, ${i.b}, 0.1)`,stroke:r}},[(0,p.useObservable)(C.currentTheme$)]),T=e=>{s.executeCommand(d.RemoveSheetDataValidationCommand.id,{ruleId:t.uid,unitId:r,subUnitId:i}),e.stopPropagation()};return(0,v.useEffect)(()=>()=>{if(m.current){var e;(e=m.current)==null||e.forEach(e=>{e&&l.removeShape(e)})}},[l]),(0,S.jsxs)(`div`,{className:(0,_.clsx)(`
5
- univer-bg-secondary univer-relative univer--mx-2 univer-box-border univer-flex univer-w-[287px]
6
- univer-cursor-pointer univer-flex-col univer-justify-between univer-overflow-hidden univer-rounded-md
7
- univer-p-2 univer-pr-9
8
- `,{"hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-700":!a,"univer-opacity-50":a}),onClick:n,onMouseEnter:()=>{a||(x(!0),m.current=t.ranges.map(e=>l.addShape({range:e,style:w,primary:null})))},onMouseLeave:()=>{var e;x(!1),(e=m.current)==null||e.forEach(e=>{e&&l.removeShape(e)}),m.current=void 0},children:[(0,S.jsx)(`div`,{className:`
9
- univer-truncate univer-text-sm univer-font-medium univer-leading-[22px] univer-text-gray-900
10
- dark:!univer-text-white
11
- `,children:u==null?void 0:u.generateRuleName(t)}),(0,S.jsx)(`div`,{className:`
12
- univer-text-secondary univer-truncate univer-text-xs univer-leading-[18px]
13
- dark:!univer-text-gray-300
14
- `,children:t.ranges.map(e=>(0,b.serializeRange)(e)).join(`,`)}),h?(0,S.jsx)(`div`,{className:`
15
- univer-absolute univer-right-2 univer-top-[19px] univer-flex univer-size-5 univer-items-center
16
- univer-justify-center univer-rounded
17
- hover:univer-bg-gray-200
18
- dark:!univer-text-gray-300
19
- dark:hover:!univer-bg-gray-700
20
- `,onClick:T,children:(0,S.jsx)(y.DeleteIcon,{})}):null]})};function fe(e){let t=(0,p.useDependency)(d.SheetDataValidationModel),n=(0,p.useDependency)(c.IUniverInstanceService),r=(0,p.useDependency)(c.ICommandService),i=(0,p.useDependency)(c.Injector),a=(0,p.useDependency)(j),o=(0,p.useDependency)(c.LocaleService),[s,l]=(0,v.useState)([]),{workbook:f}=e,m=(0,p.useObservable)(f.activeSheet$,void 0,!0),h=f.getUnitId(),g=m==null?void 0:m.getSheetId();(0,v.useEffect)(()=>{l(t.getRules(h,g));let e=t.ruleChange$.subscribe(e=>{e.unitId===h&&e.subUnitId===g&&l(t.getRules(h,g))});return()=>{e.unsubscribe()}},[h,g,t]);let y=async()=>{let e=(0,d.createDefaultNewRule)(i),t={unitId:h,subUnitId:g,rule:e};await r.executeCommand(d.AddSheetDataValidationCommand.id,t),a.setActiveRule({unitId:h,subUnitId:g,rule:e})},b=()=>{r.executeCommand(d.RemoveSheetAllDataValidationCommand.id,{unitId:h,subUnitId:g})},x=(e=>{let t=n.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET),r=t.getActiveSheet(),a=t.getUnitId(),o=r.getSheetId();return e.map(e=>(0,u.checkRangesEditablePermission)(i,a,o,e.ranges)?{...e}:{...e,disable:!0})})(s),C=x==null?void 0:x.some(e=>e.disable);return(0,S.jsxs)(`div`,{className:`univer-pb-4`,children:[x==null?void 0:x.map(e=>{var t;return(0,S.jsx)(de,{unitId:h,subUnitId:g,onClick:()=>{e.disable||a.setActiveRule({unitId:h,subUnitId:g,rule:e})},rule:e,disable:(t=e.disable)==null?!1:t},e.uid)}),(0,S.jsxs)(`div`,{className:`univer-mt-4 univer-flex univer-flex-row univer-justify-end univer-gap-2`,children:[s.length&&!C?(0,S.jsx)(_.Button,{onClick:b,children:o.t(`dataValidation.panel.removeAll`)}):null,(0,S.jsx)(_.Button,{variant:`primary`,onClick:y,children:o.t(`dataValidation.panel.add`)})]})]})}const pe=()=>{let e=(0,p.useDependency)(j),t=(0,p.useObservable)(e.activeRule$,e.activeRule),n=(0,p.useDependency)(c.IUniverInstanceService),r=(0,p.useObservable)(()=>n.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]),i=(0,p.useObservable)(()=>{var e;return(e=r==null?void 0:r.activeSheet$)==null?(0,m.of)(null):e},void 0,void 0,[]);return!r||!i?null:t&&(t.subUnitId===i.getSheetId()||t.subUnitId===e.getFocusFormulaEditorActiveRuleSubUnitId())?(0,S.jsx)(ue,{},t.rule.uid):(0,S.jsx)(fe,{workbook:r})},me=e=>{let{isTwoFormula:t=!1,value:n,onChange:r,showError:i,validResult:a}=e,o=(0,p.useDependency)(c.LocaleService),s=i?a==null?void 0:a.formula1:``,l=i?a==null?void 0:a.formula2:``;return t?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(_.FormLayout,{error:s,children:(0,S.jsx)(_.Input,{className:`univer-w-full`,placeholder:o.t(`dataValidation.panel.formulaPlaceholder`),value:n==null?void 0:n.formula1,onChange:e=>{r==null||r({...n,formula1:e})}})}),(0,S.jsx)(`div`,{className:`-univer-mt-2 univer-mb-1 univer-text-sm univer-text-gray-400`,children:o.t(`dataValidation.panel.formulaAnd`)}),(0,S.jsx)(_.FormLayout,{error:l,children:(0,S.jsx)(_.Input,{className:`univer-w-full`,placeholder:o.t(`dataValidation.panel.formulaPlaceholder`),value:n==null?void 0:n.formula2,onChange:e=>{r==null||r({...n,formula2:e})}})})]}):(0,S.jsx)(_.FormLayout,{error:s,children:(0,S.jsx)(_.Input,{className:`univer-w-full`,placeholder:o.t(`dataValidation.panel.formulaPlaceholder`),value:n==null?void 0:n.formula1,onChange:e=>{r==null||r({formula1:e})}})})};function he(e){let{value:t,onChange:n,showError:r,validResult:i}=e,a=(0,p.useDependency)(c.LocaleService),o=r?i==null?void 0:i.formula1:``,s=r?i==null?void 0:i.formula2:``,[l,u]=(0,v.useState)(!((t==null?void 0:t.formula1)===void 0&&(t==null?void 0:t.formula2)===void 0));return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(_.FormLayout,{children:(0,S.jsx)(_.Checkbox,{checked:l,onChange:e=>{e?u(!0):(u(!1),n==null||n({...t,formula1:void 0,formula2:void 0}))},children:a.t(`dataValidation.checkbox.tips`)})}),l?(0,S.jsx)(_.FormLayout,{label:a.t(`dataValidation.checkbox.checked`),error:o,children:(0,S.jsx)(_.Input,{className:`univer-w-full`,placeholder:a.t(`dataValidation.panel.valuePlaceholder`),value:t==null?void 0:t.formula1,onChange:e=>{n==null||n({...t,formula1:e||void 0})}})}):null,l?(0,S.jsx)(_.FormLayout,{label:a.t(`dataValidation.checkbox.unchecked`),error:s,children:(0,S.jsx)(_.Input,{className:`univer-w-full`,placeholder:a.t(`dataValidation.panel.valuePlaceholder`),value:t==null?void 0:t.formula2,onChange:e=>{n==null||n({...t,formula2:e||void 0})}})}):null]})}function ge(e){var t;let{unitId:n,subUnitId:r,value:i,onChange:a,showError:o,validResult:s}=e,c=o?s==null?void 0:s.formula1:void 0,l=(0,v.useRef)(null),[u,d]=(0,v.useState)(!1);return(0,p.useSidebarClick)(e=>{var t;(t=l.current)!=null&&t.isClickOutSide(e)&&d(!1)}),(0,S.jsx)(_.FormLayout,{error:c,children:(0,S.jsx)(x.FormulaEditor,{ref:l,className:(0,_.clsx)(`
21
- univer-box-border univer-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-rounded-lg
22
- univer-bg-white univer-pt-2 univer-transition-colors
23
- hover:univer-border-primary-600
24
- dark:!univer-bg-gray-700 dark:!univer-text-white
25
- [&>div:first-child]:univer-px-2.5
26
- [&>div]:univer-h-5 [&>div]:univer-ring-transparent
27
- `,_.borderClassName),initValue:(t=i==null?void 0:i.formula1)==null?`=`:t,unitId:n,subUnitId:r,isFocus:u,isSupportAcrossSheet:!0,onChange:e=>{let t=(e==null?``:e).trim();t!==(i==null?void 0:i.formula1)&&(a==null||a({...i,formula1:t}))},onFocus:()=>d(!0)})})}const _e=[`#FFFFFF`,`#FEE7E7`,`#FEF0E6`,`#EFFBD0`,`#E4F4FE`,`#E8ECFD`,`#F1EAFA`,`#FDE8F3`,`#E5E5E5`,`#FDCECE`,`#FDC49B`,`#DEF6A2`,`#9FDAFF`,`#D0D9FB`,`#E3D5F6`,`#FBD0E8`,`#656565`,`#FE4B4B`,`#FF8C51`,`#8BBB11`,`#0B9EFB`,`#3A60F7`,`#9E6DE3`,`#F248A6`],ve=e=>{let{value:t,onChange:n,disabled:r}=e,[i,a]=(0,v.useState)(!1);return(0,S.jsx)(_.Dropdown,{align:`start`,disabled:r,open:i,onOpenChange:a,overlay:(0,S.jsx)(`div`,{className:`
28
- univer-box-border univer-grid univer-w-fit univer-grid-cols-6 univer-flex-wrap univer-gap-2
29
- univer-p-1.5
30
- `,children:_e.map(e=>(0,S.jsx)(`div`,{className:(0,_.clsx)(`univer-box-border univer-size-4 univer-cursor-pointer univer-rounded`,_.borderClassName),style:{background:e},onClick:()=>{n(e),a(!1)}},e))}),children:(0,S.jsxs)(`div`,{className:(0,_.clsx)(`
31
- univer-box-border univer-inline-flex univer-h-8 univer-w-16 univer-cursor-pointer univer-items-center
32
- univer-justify-between univer-gap-2 univer-rounded-lg univer-bg-white univer-px-2.5
33
- univer-transition-colors univer-duration-200
34
- hover:univer-border-primary-600
35
- dark:!univer-bg-gray-700 dark:!univer-text-white
36
- `,_.borderClassName),children:[(0,S.jsx)(`div`,{className:`univer-box-border univer-size-4 univer-rounded univer-text-base`,style:{background:t}}),(0,S.jsx)(y.MoreDownIcon,{})]})})},ye=e=>{let{item:t,commonProps:n,className:r}=e,{onItemChange:i,onItemDelete:a}=n;return(0,S.jsxs)(`div`,{className:(0,_.clsx)(`univer-flex univer-items-center univer-gap-2`,r),children:[!t.isRef&&(0,S.jsx)(`div`,{className:(0,_.clsx)(`univer-cursor-move`,`draggableHandle`),children:(0,S.jsx)(y.SequenceIcon,{})}),(0,S.jsx)(ve,{value:t.color,onChange:e=>{i(t.id,t.label,e)}}),(0,S.jsx)(_.Input,{disabled:t.isRef,value:t.label,onChange:e=>{i(t.id,e,t.color)}}),t.isRef?null:(0,S.jsx)(`div`,{className:`
37
- univer-ml-1 univer-cursor-pointer univer-rounded univer-text-base
38
- hover:univer-bg-gray-200
39
- `,children:(0,S.jsx)(y.DeleteIcon,{onClick:()=>a(t.id)})})]})};function be(e){let{value:t,onChange:n=()=>{},unitId:r,subUnitId:i,validResult:a,showError:o,ruleId:s}=e,{formula1:l=``,formula2:u=``}=t||{},[h,g]=(0,v.useState)(()=>(0,c.isFormulaString)(l)?`1`:`0`),[b,C]=(0,v.useState)(h===`1`?l:`=`),[w,T]=(0,v.useState)(h===`1`?l:`=`),E=(0,p.useDependency)(c.LocaleService),D=(0,p.useDependency)(f.DataValidatorRegistryService),O=(0,p.useDependency)(f.DataValidationModel),k=(0,p.useDependency)(d.DataValidationFormulaController),A=(0,p.useDependency)(j),[M,N]=(0,v.useState)(()=>u.split(`,`)),P=D.getValidatorItem(c.DataValidationType.LIST),[F,I]=(0,v.useState)([]),[L,R]=(0,v.useState)(``),z=o?a==null?void 0:a.formula1:``,B=(0,p.useObservable)((0,v.useMemo)(()=>O.ruleChange$.pipe((0,m.debounceTime)(16)),[])),V=(0,p.useEvent)(n);(0,v.useEffect)(()=>{(async()=>{await new Promise(e=>{setTimeout(()=>e(!0),100)});let e=O.getRuleById(r,i,s);(0,c.isFormulaString)(e==null?void 0:e.formula1)&&P&&e&&I(await P.getListAsync(e,r,i))})()},[O,B,P,s,i,r]),(0,v.useEffect)(()=>{(0,c.isFormulaString)(l)&&l!==w&&(C(l),T(w))},[w,l]);let[H,U]=(0,v.useState)(()=>{let e=h===`1`?[]:(0,d.deserializeListOptions)(l),t=u.split(`,`);return e.map((e,n)=>({label:e,color:t[n]||`#ECECEC`,isRef:!1,id:(0,c.generateRandomId)(4)}))}),W=(e,t,n)=>{let r=H.find(t=>t.id===e);r&&(r.label=t,r.color=n,U([...H]))},G=e=>{let t=H.findIndex(t=>t.id===e);t!==-1&&(H.splice(t,1),U([...H]))},K=u.split(`,`),q=(0,v.useMemo)(()=>F.map((e,t)=>({label:e,color:K[t]||`#ECECEC`,id:`${t}`,isRef:!0})),[K,F]),J=(e,t,n)=>{let r=[...M];r[+e]=n,N(r),V({formula1:l,formula2:r.join(`,`)})},Y=()=>{U([...H,{label:``,color:`#ECECEC`,isRef:!1,id:(0,c.generateRandomId)(4)}])};(0,v.useEffect)(()=>{if(h===`1`)return;let e=new Set,t=[];H.map(e=>({labelList:e.label.split(`,`),item:e})).forEach(({item:n,labelList:r})=>{r.forEach(r=>{e.has(r)||(e.add(r),t.push({label:r,color:n.color}))})}),V({formula1:(0,d.serializeListOptions)(t.map(e=>e.label)),formula2:t.map(e=>e.color===`#ECECEC`?``:e.color).join(`,`)})},[H,V,h,w,M]);let ee=(0,p.useEvent)(async e=>{if(!(0,c.isFormulaString)(e)){V==null||V({formula1:``,formula2:u});return}k.getFormulaRefCheck(e)?(V==null||V({formula1:(0,c.isFormulaString)(e)?e:``,formula2:u}),R(``)):(V==null||V({formula1:``,formula2:u}),C(`=`),R(E.t(`dataValidation.validFail.formulaError`)))}),te=(0,v.useRef)(null),[X,ne]=(0,v.useState)(!1);return(0,p.useSidebarClick)(e=>{var t;(t=te.current)!=null&&t.isClickOutSide(e)&&ne(!1)}),(0,v.useEffect)(()=>{X?A.setFocusFormulaEditorActiveRuleSubUnitId(i):A.setFocusFormulaEditorActiveRuleSubUnitId(null)},[X,i,A]),(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(_.FormLayout,{label:E.t(`dataValidation.list.options`),children:(0,S.jsxs)(_.RadioGroup,{value:h,onChange:e=>{g(e),C(w),e===`1`&&V({formula1:w===`=`?``:w,formula2:M.join(`,`)})},children:[(0,S.jsx)(_.Radio,{value:`0`,children:E.t(`dataValidation.list.customOptions`)}),(0,S.jsx)(_.Radio,{value:`1`,children:E.t(`dataValidation.list.refOptions`)})]})}),h===`1`?(0,S.jsxs)(_.FormLayout,{error:z||L||void 0,children:[(0,S.jsx)(x.FormulaEditor,{ref:te,className:(0,_.clsx)(`
40
- univer-box-border univer-h-8 univer-w-full univer-cursor-pointer univer-items-center
41
- univer-rounded-lg univer-bg-white univer-pt-2 univer-transition-colors
42
- hover:univer-border-primary-600
43
- dark:!univer-bg-gray-700 dark:!univer-text-white
44
- [&>div:first-child]:univer-px-2.5
45
- [&>div]:univer-h-5 [&>div]:univer-ring-transparent
46
- `,_.borderClassName),initValue:b,unitId:r,subUnitId:i,isFocus:X,isSupportAcrossSheet:!0,onFocus:()=>ne(!0),onChange:(e=``)=>{let t=(e==null?``:e).trim();T(t),ee(t)}}),q.length>0&&(0,S.jsx)(`div`,{className:`univer-mt-3`,children:q.map(e=>(0,S.jsx)(ye,{className:`univer-mb-3`,item:e,commonProps:{onItemChange:J}},e.id))})]}):(0,S.jsx)(_.FormLayout,{error:z,children:(0,S.jsxs)(`div`,{className:`-univer-mt-3`,children:[(0,S.jsx)(_.DraggableList,{list:H,onListChange:U,rowHeight:28,margin:[0,12],draggableHandle:`.draggableHandle`,itemRender:e=>(0,S.jsx)(ye,{item:e,commonProps:{onItemChange:W,onItemDelete:G}},e.id),idKey:`id`}),(0,S.jsxs)(`a`,{className:`
47
- univer-text-primary univer-flex univer-w-fit univer-cursor-pointer univer-flex-row
48
- univer-items-center univer-rounded univer-p-1 univer-px-2 univer-text-sm
49
- hover:univer-bg-primary-50
50
- dark:hover:!univer-bg-gray-800
51
- `,onClick:Y,children:[(0,S.jsx)(y.IncreaseIcon,{className:`univer-mr-1`}),E.t(`dataValidation.list.add`)]})]})})]})}const xe=[[d.CUSTOM_FORMULA_INPUT_NAME,ge],[d.BASE_FORMULA_INPUT_NAME,me],[d.LIST_FORMULA_INPUT_NAME,be],[d.CHECKBOX_FORMULA_INPUT_NAME,he]];function Se(e){var t;let{value:n,onChange:r}=e,i=(0,p.useDependency)(c.LocaleService);return(0,S.jsx)(_.FormLayout,{label:i.t(`dataValidation.renderMode.label`),children:(0,S.jsxs)(_.RadioGroup,{value:`${(t=n.renderMode)==null?c.DataValidationRenderMode.CUSTOM:t}`,onChange:e=>r({...n,renderMode:+e}),children:[(0,S.jsx)(_.Radio,{value:`${c.DataValidationRenderMode.CUSTOM}`,children:i.t(`dataValidation.renderMode.chip`)}),(0,S.jsx)(_.Radio,{value:`${c.DataValidationRenderMode.ARROW}`,children:i.t(`dataValidation.renderMode.arrow`)}),(0,S.jsx)(_.Radio,{value:`${c.DataValidationRenderMode.TEXT}`,children:i.t(`dataValidation.renderMode.text`)})]})})}Se.componentKey=`LIST_RENDER_MODE_OPTION_INPUT`;function Ce(e){var t;let{value:n,onChange:r}=e,i=(0,p.useDependency)(c.LocaleService);return(0,S.jsx)(_.FormLayout,{children:(0,S.jsx)(_.Checkbox,{checked:(t=n.bizInfo)==null?void 0:t.showTime,onChange:e=>{r({...n,bizInfo:{...n.bizInfo,showTime:e}})},children:i.t(`dataValidation.showTime.label`)})})}Ce.componentKey=`DATE_SHOW_TIME_OPTION`;let we=class{_calc(e,t){var n,r,i;let{vt:a,ht:o}=t||{},s=e.endX-e.startX-12,l=e.endY-e.startY,u=((n=t==null?void 0:t.fs)==null?10:n)*1.6,d=0,f=0;switch(a){case c.VerticalAlign.TOP:f=0;break;case c.VerticalAlign.BOTTOM:f=0+(l-u);break;default:f=0+(l-u)/2;break}switch(o){case c.HorizontalAlign.LEFT:d=6;break;case c.HorizontalAlign.RIGHT:d=6+(s-u);break;default:d=6+(s-u)/2;break}return{left:e.startX+d,top:e.startY+f,width:((r=t==null?void 0:t.fs)==null?10:r)*1.6,height:((i=t==null?void 0:t.fs)==null?10:i)*1.6}}constructor(e,t,n,r,i,a){this._commandService=e,this._univerInstanceService=t,this._formulaService=n,this._themeService=r,this._renderManagerService=i,this._dataValidationModel=a}calcCellAutoHeight(e){var t;let{style:n}=e;return((t=n==null?void 0:n.fs)==null?10:t)*1.6}calcCellAutoWidth(e){var t;let{style:n}=e;return((t=n==null?void 0:n.fs)==null?10:t)*1.6}async _parseFormula(e,t,n){var r,i,a;let{formula1:o=d.CHECKBOX_FORMULA_1,formula2:s=d.CHECKBOX_FORMULA_2}=e,l=await this._formulaService.getRuleFormulaResult(t,n,e.uid),u=(0,d.getFormulaResult)(l==null||(r=l[0])==null||(r=r.result)==null||(r=r[0])==null?void 0:r[0]),f=(0,d.getFormulaResult)(l==null||(i=l[1])==null||(i=i.result)==null||(i=i[0])==null?void 0:i[0]),p=(0,d.isLegalFormulaResult)(String(u))&&(0,d.isLegalFormulaResult)(String(f));return{formula1:(0,c.isFormulaString)(o)?(0,d.getFormulaResult)(l==null||(a=l[0])==null||(a=a.result)==null||(a=a[0])==null?void 0:a[0]):o,formula2:(0,c.isFormulaString)(s)?f:s,isFormulaValid:p}}drawWith(e,t){var n,r,i,a;let{style:o,primaryWithCoord:s,unitId:c,subUnitId:u,worksheet:f,row:p,col:m}=t,h=s.isMergedMainCell?s.mergeInfo:s,g=(0,d.getCellValueOrigin)(f.getCellRaw(p,m)),_=this._dataValidationModel.getRuleByLocation(c,u,p,m);if(!_)return;let v=this._dataValidationModel.getValidator(_.type);if(!v||!((n=v.skipDefaultFontRender)!=null&&n.call(v,_,g,{unitId:c,subUnitId:u,row:p,column:m})))return;let{formula1:y}=v.parseFormulaSync(_,c,u),b=this._calc(h,o),{a:x,d:S}=e.getTransform(),C=(0,l.fixLineWidthByScale)(b.left,x),w=(0,l.fixLineWidthByScale)(b.top,S),T=l.Transform.create().composeMatrix({left:C,top:w,scaleX:1,scaleY:1,angle:0,skewX:0,skewY:0,flipX:!1,flipY:!1}),E=h.endX-h.startX,D=h.endY-h.startY;e.save(),e.beginPath(),e.rect(h.startX,h.startY,E,D),e.clip();let O=T.getMatrix();e.transform(O[0],O[1],O[2],O[3],O[4],O[5]);let k=((r=o==null?void 0:o.fs)==null?10:r)*1.6,A=String(g)===String(y),j=this._themeService.getColorFromTheme(`primary.600`);l.CheckboxShape.drawWith(e,{checked:A,width:k,height:k,fill:(i=o==null||(a=o.cl)==null?void 0:a.rgb)==null?j:i}),e.restore()}isHit(e,t){let n=t.primaryWithCoord.isMergedMainCell?t.primaryWithCoord.mergeInfo:t.primaryWithCoord,r=this._calc(n,t.style),i=r.top,a=r.top+r.height,o=r.left,s=r.left+r.width,{x:c,y:l}=e;return c<=s&&c>=o&&l<=a&&l>=i}async onPointerDown(e,t){var n;if(t.button===2)return;let{primaryWithCoord:r,unitId:i,subUnitId:a,worksheet:o,row:s,col:c}=e,l=(0,d.getCellValueOrigin)(o.getCellRaw(s,c)),f=this._dataValidationModel.getRuleByLocation(i,a,s,c);if(!f)return;let p=this._dataValidationModel.getValidator(f.type);if(!p||!((n=p.skipDefaultFontRender)!=null&&n.call(p,f,l,{unitId:i,subUnitId:a,row:s,column:c})))return;let{formula1:m,formula2:h}=await this._parseFormula(f,i,a),g={range:{startColumn:r.actualColumn,endColumn:r.actualColumn,startRow:r.actualRow,endRow:r.actualRow},value:{v:String(l)===(0,d.transformCheckboxValue)(String(m))?h:m,p:null}};this._commandService.executeCommand(u.SetRangeValuesCommand.id,g)}onPointerEnter(e,t){var n;(n=(0,l.getCurrentTypeOfRenderer)(c.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null||(n=n.mainComponent)==null||n.setCursor(l.CURSOR_TYPE.POINTER)}onPointerLeave(e,t){var n;(n=(0,l.getCurrentTypeOfRenderer)(c.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null||(n=n.mainComponent)==null||n.setCursor(l.CURSOR_TYPE.DEFAULT)}};we=A([k(0,c.ICommandService),k(1,c.IUniverInstanceService),k(2,(0,c.Inject)(d.DataValidationFormulaService)),k(3,(0,c.Inject)(c.ThemeService)),k(4,(0,c.Inject)(l.IRenderManagerService)),k(5,(0,c.Inject)(d.SheetDataValidationModel))],we);let Q=class{constructor(e){this.injector=e,O(this,`canvasRender`,null),O(this,`dropdownType`,void 0),O(this,`optionsInput`,void 0),O(this,`formulaInput`,d.LIST_FORMULA_INPUT_NAME)}};Q=A([k(0,(0,c.Inject)(c.Injector))],Q);var Te=class extends Q{constructor(...e){super(...e),O(this,`id`,c.DataValidationType.CHECKBOX),O(this,`canvasRender`,this.injector.createInstance(we)),O(this,`formulaInput`,d.CHECKBOX_FORMULA_INPUT_NAME)}},Ee=class extends Q{constructor(...e){super(...e),O(this,`id`,c.DataValidationType.CUSTOM),O(this,`formulaInput`,d.CUSTOM_FORMULA_INPUT_NAME)}},De=class extends Q{constructor(...e){super(...e),O(this,`id`,c.DataValidationType.DATE),O(this,`formulaInput`,`data-validation.formula-input`),O(this,`optionsInput`,Ce.componentKey),O(this,`dropdownType`,f.DataValidatorDropdownType.DATE)}},Oe=class extends Q{constructor(...e){super(...e),O(this,`id`,c.DataValidationType.DECIMAL),O(this,`formulaInput`,d.BASE_FORMULA_INPUT_NAME)}};function ke(e,t){let n=l.FontCache.getTextSize(e,t),r=n.width+8,{ba:i,bd:a}=n;return{width:r,height:i+a+0,ba:i}}function Ae(e,t,n,r){let i=n-26,a=r-12,o=e.map(e=>({layout:ke(e,t),text:e})),s,c=[];o.forEach(e=>{let{layout:t}=e,{width:n,height:r}=t;!s||s.width+n+4>i?(s={width:n,height:r,items:[{...e,left:0}]},c.push(s)):(s.items.push({...e,left:s.width+4}),s.width=s.width+n+4)});let l=0,u=0;return c.forEach((e,t)=>{u=Math.max(u,e.width),t===c.length-1?l+=e.height:l+=e.height+4}),{lines:c,totalHeight:l,contentWidth:i,contentHeight:a,cellAutoHeight:l+12,calcAutoWidth:u+26}}var je=class extends l.Shape{static drawWith(e,t){let{fontString:n,info:r,fill:i,color:a}=t,{layout:o,text:s}=r;e.save(),l.Rect.drawWith(e,{width:o.width,height:o.height,radius:8,fill:i||`#ECECEC`}),e.translateWithPrecision(4,o.ba),e.font=n,e.fillStyle=a,e.fillText(s,0,0),e.restore()}};const Me=new Path2D(`M3.32201 4.84556C3.14417 5.05148 2.85583 5.05148 2.67799 4.84556L0.134292 1.90016C-0.152586 1.56798 0.0505937 1 0.456301 1L5.5437 1C5.94941 1 6.15259 1.56798 5.86571 1.90016L3.32201 4.84556Z`);let Ne=class{constructor(e,t,n,r){this._commandService=e,this._univerInstanceService=t,this._renderManagerService=n,this._dataValidationModel=r,O(this,`zIndex`,void 0),O(this,`_dropdownInfoMap`,new Map)}_ensureMap(e){let t=this._dropdownInfoMap.get(e);return t||(t=new Map,this._dropdownInfoMap.set(e,t)),t}_generateKey(e,t){return`${e}.${t}`}_drawDownIcon(e,t,n,r,i){let a=n-14+4,o=4;switch(i){case c.VerticalAlign.MIDDLE:o=(r-14)/2+4;break;case c.VerticalAlign.BOTTOM:o=r-14+4;break;default:break}e.save(),e.translateWithPrecision(t.startX+a,t.startY+o),e.fillStyle=`#565656`,e.fill(Me),e.restore()}drawWith(e,t,n,r){var i,a;let{primaryWithCoord:o,row:s,col:u,style:f,data:p,subUnitId:m}=t,h=o.isMergedMainCell?o.mergeInfo:o,{leftOffset:g=0,rightOffset:_=0,topOffset:v=0,downOffset:y=0}=(p==null?void 0:p.fontRenderExtension)||{},b=this._ensureMap(m),x=this._generateKey(s,u),S=o.isMergedMainCell?o.mergeInfo.startRow:s,C=o.isMergedMainCell?o.mergeInfo.startColumn:u,w=this._dataValidationModel.getRuleByLocation(t.unitId,t.subUnitId,S,C);if(!w)return;let T=this._dataValidationModel.getValidator(w.type);if(!T)return;let E={startX:h.startX+g,endX:h.endX-_,startY:h.startY+v,endY:h.endY-y},D=E.endX-E.startX,O=E.endY-E.startY,{cl:k}=f||{},A=(i=typeof k==`object`?k==null?void 0:k.rgb:k)==null?`#000`:i,j=(0,l.getFontStyleString)(f==null?void 0:f),{vt:M,ht:N}=f||{},P=M==null?c.VerticalAlign.MIDDLE:M,F=(a=(0,d.getCellValueOrigin)(p))==null?``:a,I=T.parseCellValue(F),L=T.getListWithColorMap(w),R=Ae(I,j,D,O);this._drawDownIcon(e,E,D,O,P),e.save(),e.translateWithPrecision(E.startX,E.startY),e.beginPath(),e.rect(0,0,D-14,O),e.clip(),e.translateWithPrecision(6,6);let z=0;switch(P){case c.VerticalAlign.MIDDLE:z=(R.contentHeight-R.totalHeight)/2;break;case c.VerticalAlign.BOTTOM:z=R.contentHeight-R.totalHeight;break;default:break}e.translateWithPrecision(0,z),R.lines.forEach((t,n)=>{e.save();let{width:r,height:i,items:a}=t,o=0;switch(N){case c.HorizontalAlign.RIGHT:o=R.contentWidth-r;break;case c.HorizontalAlign.CENTER:o=(R.contentWidth-r)/2;break;default:break}e.translate(o,n*(i+4)),a.forEach(t=>{e.save(),e.translateWithPrecision(t.left,0),je.drawWith(e,{...j,info:t,color:A,fill:L[t.text]}),e.restore()}),e.restore()}),e.restore(),b.set(x,{left:E.startX,top:E.startY,width:R.contentWidth+6+14,height:R.contentHeight+12})}calcCellAutoHeight(e){var t;let{primaryWithCoord:n,style:r,data:i,row:a,col:o}=e,{leftOffset:s=0,rightOffset:c=0,topOffset:u=0,downOffset:f=0}=(i==null?void 0:i.fontRenderExtension)||{},p=n.isMergedMainCell?n.mergeInfo:n,m={startX:p.startX+s,endX:p.endX-c,startY:p.startY+u,endY:p.endY-f},h=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,o);if(!h)return;let g=this._dataValidationModel.getValidator(h.type);if(!g)return;let _=m.endX-m.startX,v=m.endY-m.startY,y=(t=(0,d.getCellValueOrigin)(i))==null?``:t;return Ae(g.parseCellValue(y),(0,l.getFontStyleString)(r==null?void 0:r),_,v).cellAutoHeight}calcCellAutoWidth(e){var t;let{primaryWithCoord:n,style:r,data:i,row:a,col:o}=e,{leftOffset:s=0,rightOffset:c=0,topOffset:u=0,downOffset:f=0}=(i==null?void 0:i.fontRenderExtension)||{},p=n.isMergedMainCell?n.mergeInfo:n,m={startX:p.startX+s,endX:p.endX-c,startY:p.startY+u,endY:p.endY-f},h=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,o);if(!h)return;let g=this._dataValidationModel.getValidator(h.type);if(!g)return;let _=m.endX-m.startX,v=m.endY-m.startY,y=(t=(0,d.getCellValueOrigin)(i))==null?``:t;return Ae(g.parseCellValue(y),(0,l.getFontStyleString)(r==null?void 0:r),_,v).calcAutoWidth}isHit(e,t){let{primaryWithCoord:n}=t,{endX:r}=n.isMergedMainCell?n.mergeInfo:n,{x:i}=e;return i>=r-14&&i<=r}onPointerDown(e,t){if(t.button===2)return;let{unitId:n,subUnitId:r,row:i,col:a}=e,o={unitId:n,subUnitId:r,row:i,column:a};this._commandService.executeCommand(H.id,o)}onPointerEnter(e,t){var n;return(n=(0,l.getCurrentTypeOfRenderer)(c.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null||(n=n.mainComponent)==null?void 0:n.setCursor(l.CURSOR_TYPE.POINTER)}onPointerLeave(e,t){var n;return(n=(0,l.getCurrentTypeOfRenderer)(c.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null||(n=n.mainComponent)==null?void 0:n.setCursor(l.CURSOR_TYPE.DEFAULT)}};Ne=A([k(0,c.ICommandService),k(1,c.IUniverInstanceService),k(2,(0,c.Inject)(l.IRenderManagerService)),k(3,(0,c.Inject)(d.SheetDataValidationModel))],Ne);var Pe=class extends Q{constructor(...e){super(...e),O(this,`id`,c.DataValidationType.LIST_MULTIPLE),O(this,`canvasRender`,this.injector.createInstance(Ne)),O(this,`dropdownType`,f.DataValidatorDropdownType.MULTIPLE_LIST)}};const Fe=new Path2D(`M3.32201 4.84556C3.14417 5.05148 2.85583 5.05148 2.67799 4.84556L0.134292 1.90016C-0.152586 1.56798 0.0505937 1 0.456301 1L5.5437 1C5.94941 1 6.15259 1.56798 5.86571 1.90016L3.32201 4.84556Z`);function Ie(e,t,n,r,i,a,o=!0){let s=0,l=o?3:0;switch(i){case c.VerticalAlign.BOTTOM:s=t-r-l;break;case c.VerticalAlign.MIDDLE:s=(t-r)/2;break;default:s=l;break}s=Math.max(3,s);let u=0;switch(a){case c.HorizontalAlign.CENTER:u=(e-n)/2;break;case c.HorizontalAlign.RIGHT:u=e-n;break;default:break}return u=Math.max(6,u),{paddingLeft:u,paddingTop:s}}let Le=class{constructor(e,t,n,r,i){this._univerInstanceService=e,this._localeService=t,this._commandService=n,this._renderManagerService=r,this._dataValidationModel=i,O(this,`_dropdownInfoMap`,new Map),O(this,`zIndex`,void 0)}_ensureMap(e){let t=this._dropdownInfoMap.get(e);return t||(t=new Map,this._dropdownInfoMap.set(e,t)),t}_generateKey(e,t){return`${e}.${t}`}_drawDownIcon(e,t,n,r,i,a,o){let{t:s=c.DEFAULT_STYLES.pd.t,b:l=c.DEFAULT_STYLES.pd.b}=o,u=n-14,d;switch(a){case c.VerticalAlign.MIDDLE:d=(r-4)/2;break;case c.VerticalAlign.BOTTOM:d=r-l-i-3+(i/2-4/2);break;default:d=s+3+(i/2-4/2);break}e.save(),e.translateWithPrecision(t.startX+u,t.startY+d),e.fillStyle=`#565656`,e.fill(Fe),e.restore()}drawWith(e,t,n){var r,i,a,o;let{primaryWithCoord:s,row:u,col:f,style:p,data:m,subUnitId:h}=t,g=s.isMergedMainCell?s.mergeInfo:s,_=s.isMergedMainCell?s.mergeInfo.startRow:u,v=s.isMergedMainCell?s.mergeInfo.startColumn:f,y=this._dataValidationModel.getRuleByLocation(t.unitId,t.subUnitId,_,v);if(!y)return;let b=this._dataValidationModel.getValidator(y.type);if(!b)return;let{leftOffset:x=0,rightOffset:S=0,topOffset:C=0,downOffset:w=0}=(m==null?void 0:m.fontRenderExtension)||{};if(!y||!b||!b||b.id.indexOf(c.DataValidationType.LIST)!==0||!b.skipDefaultFontRender(y))return;let T={startX:g.startX+x,endX:g.endX-S,startY:g.startY+C,endY:g.endY-w},E=T.endX-T.startX,D=T.endY-T.startY,O=this._ensureMap(h),k=this._generateKey(u,f),A=b.getListWithColorMap(y),j=(0,d.getCellValueOrigin)(m),M=`${j==null?``:j}`,N=A[M],{tb:P,vt:F,ht:I,pd:L}=p||{};P=(r=P)==null?c.WrapStrategy.WRAP:r,F=(i=F)==null?c.VerticalAlign.BOTTOM:i,I=(a=I)==null?c.DEFAULT_STYLES.ht:a,L=(o=L)==null?c.DEFAULT_STYLES.pd:o;let R=(0,l.getFontStyleString)(p).fontCache;if(y.renderMode===c.DataValidationRenderMode.ARROW){var z,B,V;let{l:t=c.DEFAULT_STYLES.pd.l,t:r=c.DEFAULT_STYLES.pd.t,r:i=c.DEFAULT_STYLES.pd.r,b:a=c.DEFAULT_STYLES.pd.b}=L,o=E-t-i-14-4,s=new l.DocSimpleSkeleton(M,R,P===c.WrapStrategy.WRAP,o,1/0);s.calculate();let u=s.getTotalWidth(),d=s.getTotalHeight(),{paddingTop:f,paddingLeft:m}=Ie(o,D-r-a,u,d,F,I,!0);this._drawDownIcon(e,T,E,D,d,F,L),e.save(),e.translateWithPrecision(T.startX+t,T.startY+r),e.beginPath(),e.rect(0,0,E-t-i,D-r-a),e.clip(),e.translateWithPrecision(0,f),e.save(),e.translateWithPrecision(m,0),e.beginPath(),e.rect(0,0,o,d),e.clip(),l.Text.drawWith(e,{text:M,fontStyle:R,width:o,height:d,color:p==null||(z=p.cl)==null?void 0:z.rgb,strokeLine:!!(!(p==null||(B=p.st)==null)&&B.s),underline:!!(!(p==null||(V=p.ul)==null)&&V.s),warp:P===c.WrapStrategy.WRAP,hAlign:c.HorizontalAlign.LEFT},s),e.restore(),e.restore(),O.set(k,{left:T.endX-14+n.rowHeaderWidth,top:T.startY+r+n.columnHeaderHeight,width:14,height:D-r-a})}else{var H,U,W;e.save(),e.translateWithPrecision(T.startX,T.startY),e.beginPath(),e.rect(0,0,E,D),e.clip();let t=E-12-4-14-4,r=new l.DocSimpleSkeleton(M,R,P===c.WrapStrategy.WRAP,t,1/0);r.calculate();let i=r.getTotalWidth(),a=r.getTotalHeight(),o=a+2,s=Math.max(E-12,1),{paddingTop:u}=Ie(s,D,i,o,F,I);e.translateWithPrecision(6,u),l.Rect.drawWith(e,{width:s,height:o,fill:N||`#ECECEC`,radius:8}),e.save(),e.translateWithPrecision(4,1),e.beginPath(),e.rect(0,0,t,a),e.clip(),l.Text.drawWith(e,{text:M,fontStyle:R,width:t,height:a,color:p==null||(H=p.cl)==null?void 0:H.rgb,strokeLine:!!(!(p==null||(U=p.st)==null)&&U.s),underline:!!(!(p==null||(W=p.ul)==null)&&W.s),warp:P===c.WrapStrategy.WRAP,hAlign:c.HorizontalAlign.LEFT},r),e.restore(),e.translateWithPrecision(t+4+4,(a-4)/2),e.fillStyle=`#565656`,e.fill(Fe),e.restore(),O.set(k,{left:T.startX+6+n.rowHeaderWidth,top:T.startY+u+n.columnHeaderHeight,width:s,height:o})}}calcCellAutoHeight(e){var t;let{primaryWithCoord:n,style:r,data:i,row:a,col:o}=e,s=n.isMergedMainCell?n.mergeInfo:n,{leftOffset:u=0,rightOffset:f=0,topOffset:p=0,downOffset:m=0}=(i==null?void 0:i.fontRenderExtension)||{},h=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,o);if(!h||h.renderMode===c.DataValidationRenderMode.TEXT)return;let g={startX:s.startX+u,endX:s.endX-f,startY:s.startY+p,endY:s.endY-m},_=g.endX-g.startX,v=(0,d.getCellValueOrigin)(i),y=`${v==null?``:v}`,{tb:b,pd:x}=r||{},{t:S=c.DEFAULT_STYLES.pd.t,b:C=c.DEFAULT_STYLES.pd.b}=x==null?{}:x;if(b=(t=b)==null?c.WrapStrategy.WRAP:t,h.renderMode===c.DataValidationRenderMode.ARROW){let{l:e=c.DEFAULT_STYLES.pd.l,r:t=c.DEFAULT_STYLES.pd.r}=x==null?{}:x,n=_-e-t-14-4,i=new l.DocSimpleSkeleton(y,(0,l.getFontStyleString)(r).fontCache,b===c.WrapStrategy.WRAP,n,1/0);return i.calculate(),i.getTotalHeight()+S+C+6}else{let e=Math.max(_-12-4-14-4,10),t=new l.DocSimpleSkeleton(y,(0,l.getFontStyleString)(r).fontCache,b===c.WrapStrategy.WRAP,e,1/0);return t.calculate(),t.getTotalHeight()+6+2}}calcCellAutoWidth(e){var t;let{primaryWithCoord:n,style:r,data:i,row:a,col:o}=e,s=n.isMergedMainCell?n.mergeInfo:n,{leftOffset:u=0,rightOffset:f=0,topOffset:p=0,downOffset:m=0}=(i==null?void 0:i.fontRenderExtension)||{},h=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,o);if(!h||h.renderMode===c.DataValidationRenderMode.TEXT)return;let g={startX:s.startX+u,endX:s.endX-f,startY:s.startY+p,endY:s.endY-m},_=g.endX-g.startX,v=(0,d.getCellValueOrigin)(i),y=`${v==null?``:v}`,{tb:b,pd:x}=r||{},{l:S=c.DEFAULT_STYLES.pd.l,r:C=c.DEFAULT_STYLES.pd.r}=x==null?{}:x;b=(t=b)==null?c.WrapStrategy.WRAP:t;let w=26;switch(h.renderMode){case c.DataValidationRenderMode.ARROW:w=18+C+S;break;case c.DataValidationRenderMode.CUSTOM:w=34+C+S+8/2+1;break;default:w=34+C+S+8/2+1}let T=_-w,E=new l.DocSimpleSkeleton(y,(0,l.getFontStyleString)(r).fontCache,b===c.WrapStrategy.WRAP,T,1/0);return E.calculate(),E.getTotalWidth()+w}isHit(e,t){let{subUnitId:n,row:r,col:i}=t,a=this._ensureMap(n).get(this._generateKey(r,i)),o=this._dataValidationModel.getRuleByLocation(t.unitId,t.subUnitId,r,i);if(!o||!a||o.renderMode===c.DataValidationRenderMode.TEXT)return!1;let{top:s,left:l,width:u,height:d}=a,{x:f,y:p}=e;return f>=l&&f<=l+u&&p>=s&&p<=s+d}onPointerDown(e,t){if(t.button===2)return;let{unitId:n,subUnitId:r,row:i,col:a}=e,o={unitId:n,subUnitId:r,row:i,column:a};this._commandService.executeCommand(H.id,o)}onPointerEnter(e,t){var n;(n=(0,l.getCurrentTypeOfRenderer)(c.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null||(n=n.mainComponent)==null||n.setCursor(l.CURSOR_TYPE.POINTER)}onPointerLeave(e,t){var n;(n=(0,l.getCurrentTypeOfRenderer)(c.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null||(n=n.mainComponent)==null||n.setCursor(l.CURSOR_TYPE.DEFAULT)}};Le=A([k(0,c.IUniverInstanceService),k(1,(0,c.Inject)(c.LocaleService)),k(2,c.ICommandService),k(3,(0,c.Inject)(l.IRenderManagerService)),k(4,(0,c.Inject)(d.SheetDataValidationModel))],Le);var Re=class extends Q{constructor(...e){super(...e),O(this,`id`,c.DataValidationType.LIST),O(this,`canvasRender`,this.injector.createInstance(Le)),O(this,`dropdownType`,f.DataValidatorDropdownType.LIST),O(this,`optionsInput`,Se.componentKey),O(this,`formulaInput`,d.LIST_FORMULA_INPUT_NAME)}},ze=class extends Q{constructor(...e){super(...e),O(this,`id`,c.DataValidationType.TEXT_LENGTH),O(this,`formulaInput`,d.BASE_FORMULA_INPUT_NAME)}},Be=class extends Q{constructor(...e){super(...e),O(this,`id`,c.DataValidationType.WHOLE),O(this,`formulaInput`,d.BASE_FORMULA_INPUT_NAME)}};let Ve=class extends c.RxDisposable{constructor(e,t,n){super(),this._injector=e,this._componentManger=t,this._dataValidatorRegistryService=n,this._initComponents(),this._registerValidatorViews()}_initComponents(){[[`DataValidationIcon`,y.DataValidationIcon],[R,pe],[Se.componentKey,Se],[Ce.componentKey,Ce],...xe].forEach(([e,t])=>{this.disposeWithMe(this._componentManger.register(e,t))})}_registerValidatorViews(){[Oe,Be,ze,De,Te,Re,Pe,Ee].forEach(e=>{let t=this._injector.createInstance(e),n=this._dataValidatorRegistryService.getValidatorItem(t.id);n&&(n.formulaInput=t.formulaInput,n.canvasRender=t.canvasRender,n.dropdownType=t.dropdownType,n.optionsInput=t.optionsInput)})}};Ve=A([k(0,(0,c.Inject)(c.Injector)),k(1,(0,c.Inject)(p.ComponentManager)),k(2,(0,c.Inject)(f.DataValidatorRegistryService))],Ve);let $=class extends c.Plugin{constructor(e=N,t,n,r){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r;let{menu:i,...a}=(0,c.merge)({},N,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(M,a)}onStarting(){[[j],[L],[K],[q],[Z],[Y],[J],[Ve]].forEach(e=>{this._injector.add(e)}),[W,H,U,B,z,V].forEach(e=>{this._commandService.registerCommand(e)})}onReady(){this._injector.get(J),this._injector.get(Y),this._injector.get(l.IRenderManagerService).registerRenderModule(c.UniverInstanceType.UNIVER_SHEET,[oe])}onRendered(){this._injector.get(Ve),this._injector.get(Z)}onSteady(){this._injector.get(q)}};O($,`pluginName`,`SHEET_DATA_VALIDATION_UI_PLUGIN`),O($,`packageName`,C),O($,`version`,w),O($,`type`,c.UniverInstanceType.UNIVER_SHEET),$=A([k(1,(0,c.Inject)(c.Injector)),k(2,c.ICommandService),k(3,c.IConfigService)],$);let He=class extends c.Plugin{constructor(e=N,t,n,r){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r;let{menu:i,...a}=(0,c.merge)({},N,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(M,a)}onStarting(){[[j],[L],[K],[q],[Z],[Y],[J],[P],[Ve]].forEach(e=>{this._injector.add(e)}),[W,H,U,B,z,V].forEach(e=>{this._commandService.registerCommand(e)})}onReady(){this._injector.get(J),this._injector.get(Y),this._injector.get(P),this._injector.get(K),this._injector.get(l.IRenderManagerService).registerRenderModule(c.UniverInstanceType.UNIVER_SHEET,[oe])}onRendered(){this._injector.get(Ve),this._injector.get(Z)}onSteady(){this._injector.get(q)}};O(He,`pluginName`,`SHEET_DATA_VALIDATION_UI_PLUGIN`),O(He,`packageName`,C),O(He,`version`,w),O(He,`type`,c.UniverInstanceType.UNIVER_SHEET),He=A([(0,c.DependentOn)(d.UniverSheetsDataValidationPlugin),k(1,(0,c.Inject)(c.Injector)),k(2,c.ICommandService),k(3,c.IConfigService)],He),Object.defineProperty(exports,`BaseSheetDataValidatorView`,{enumerable:!0,get:function(){return Q}}),Object.defineProperty(exports,`UniverSheetsDataValidationMobileUIPlugin`,{enumerable:!0,get:function(){return $}}),Object.defineProperty(exports,`UniverSheetsDataValidationUIPlugin`,{enumerable:!0,get:function(){return He}});
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`@univerjs/core`),l=require(`@univerjs/engine-render`),u=require(`@univerjs/sheets`),d=require(`@univerjs/sheets-data-validation`),f=require(`@univerjs/data-validation`),p=require(`@univerjs/ui`),m=require(`rxjs`),h=require(`@univerjs/sheets-numfmt`),g=require(`@univerjs/sheets-ui`),_=require(`@univerjs/design`),v=require(`react`);v=s(v);let y=require(`@univerjs/icons`),b=require(`@univerjs/engine-formula`),x=require(`@univerjs/sheets-formula-ui`),S=require(`react/jsx-runtime`);var C=`@univerjs/sheets-data-validation-ui`,w=`0.19.0`;function T(e){"@babel/helpers - typeof";return T=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},T(e)}function E(e,t){if(T(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(T(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function D(e){var t=E(e,`string`);return T(t)==`symbol`?t:t+``}function O(e,t,n){return(t=D(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function k(e,t){return function(n,r){t(n,r,e)}}function A(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let j=class extends c.Disposable{get activeRule(){return this._activeRule}get isOpen(){return this._open$.getValue()}constructor(e,t){super(),this._univerInstanceService=e,this._sidebarService=t,O(this,`_open$`,new m.BehaviorSubject(!1)),O(this,`open$`,this._open$.pipe((0,m.distinctUntilChanged)())),O(this,`_activeRule`,void 0),O(this,`_activeRule$`,new m.BehaviorSubject(void 0)),O(this,`activeRule$`,this._activeRule$.asObservable()),O(this,`_closeDisposable`,null),O(this,`_focusFormulaEditorActiveRuleSubUnitId`,null),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET).pipe((0,m.filter)(e=>!e)).subscribe(()=>{this.close()})),this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(e=>{e.id===`DataValidationPanel`&&(e.visible||setTimeout(()=>{this._sidebarService.sidebarOptions$.next({visible:!1})}))}))}dispose(){var e;super.dispose(),this._open$.next(!1),this._open$.complete(),this._activeRule$.complete(),(e=this._closeDisposable)==null||e.dispose()}open(){this._open$.next(!0)}close(){var e;this._open$.next(!1),(e=this._closeDisposable)==null||e.dispose()}setCloseDisposable(e){this._closeDisposable=(0,c.toDisposable)(()=>{e.dispose(),this._closeDisposable=null})}setActiveRule(e){this._activeRule=e,this._activeRule$.next(e)}setFocusFormulaEditorActiveRuleSubUnitId(e){this._focusFormulaEditorActiveRuleSubUnitId=e}getFocusFormulaEditorActiveRuleSubUnitId(){return this._focusFormulaEditorActiveRuleSubUnitId}};j=A([k(0,c.IUniverInstanceService),k(1,p.ISidebarService)],j);const M=`sheets-data-validation-ui.config`;Symbol(M);const N={};let P=class extends c.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetInterceptorService=e,this._dataValidationModel=t,this._dataValidatorRegistryService=n,this._dialogService=r,this._localeService=i,this._sheetsDataValidationValidatorService=a,this._initEditorBridgeInterceptor()}_initEditorBridgeInterceptor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(u.VALIDATE_CELL,{handler:async(e,t,n)=>{let r=await e,{row:i,col:a,unitId:o,subUnitId:s}=t,l=this._dataValidationModel.getRuleIdByLocation(o,s,i,a),u=l?this._dataValidationModel.getRuleById(o,s,l):void 0;if(r===!1)return n(Promise.resolve(!1));if(!u||u.errorStyle!==c.DataValidationErrorStyle.STOP)return n(Promise.resolve(!0));let d=this._dataValidatorRegistryService.getValidatorItem(u.type);return!d||await this._sheetsDataValidationValidatorService.validatorCell(o,s,i,a)===c.DataValidationStatus.VALID?n(Promise.resolve(!0)):(this._dialogService.open({width:368,title:{title:this._localeService.t(`dataValidation.alert.title`)},id:`reject-input-dialog`,children:{title:d.getRuleFinalError(u,{row:i,col:a,unitId:o,subUnitId:s})},footer:{title:(0,v.createElement)(_.Button,{variant:`primary`,onClick:()=>this._dialogService.close(`reject-input-dialog`)},this._localeService.t(`dataValidation.alert.ok`))},onClose:()=>{this._dialogService.close(`reject-input-dialog`)}}),n(Promise.resolve(!1)))}}))}showReject(e){this._dialogService.open({width:368,title:{title:this._localeService.t(`dataValidation.alert.title`)},id:`reject-input-dialog`,children:{title:e},footer:{title:(0,v.createElement)(_.Button,{variant:`primary`,onClick:()=>this._dialogService.close(`reject-input-dialog`)},this._localeService.t(`dataValidation.alert.ok`))},onClose:()=>{this._dialogService.close(`reject-input-dialog`)}})}};P=A([k(0,(0,c.Inject)(u.SheetInterceptorService)),k(1,(0,c.Inject)(d.SheetDataValidationModel)),k(2,(0,c.Inject)(f.DataValidatorRegistryService)),k(3,p.IDialogService),k(4,(0,c.Inject)(c.LocaleService)),k(5,(0,c.Inject)(d.SheetsDataValidationValidatorService))],P);const F=e=>{if(e==null||typeof e==`boolean`)return;if(e===``)return(0,c.dayjs)();if(typeof e==`number`||!Number.isNaN(+e))return(0,c.dayjs)(c.numfmt.format(`yyyy-MM-dd HH:mm:ss`,Number(e)));let t=(0,c.dayjs)(e);if(t.isValid())return t};function I(e,t){if(e===(0,h.getPatternType)(t))return t;switch(e){case`datetime`:return`yyyy-MM-dd hh:mm:ss`;case`date`:return`yyyy-MM-dd`;case`time`:return`HH:mm:ss`}}let L=class extends c.Disposable{get activeDropdown(){return this._activeDropdown}constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._univerInstanceService=e,this._dataValidatorRegistryService=t,this._zenZoneService=n,this._dataValidationModel=r,this._sheetsSelectionsService=i,this._cellDropdownManagerService=a,this._sheetDataValidationModel=o,this._commandService=s,this._editorBridgeService=c,this._injector=l,this._configService=u,O(this,`_activeDropdown`,void 0),O(this,`_activeDropdown$`,new m.Subject),O(this,`_currentPopup`,null),O(this,`activeDropdown$`,this._activeDropdown$.asObservable()),O(this,`_zenVisible`,!1),this._init(),this._initSelectionChange(),this.disposeWithMe(()=>{this._activeDropdown$.complete()})}_init(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{this._zenVisible=e,e&&this.hideDropdown()}))}_getDropdownByCell(e,t,n,r){let i=e?this._univerInstanceService.getUnit(e,c.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET);if(!i)return;let a=t?i.getSheetBySheetId(t):i.getActiveSheet();if(!a)return;let o=this._dataValidationModel.getRuleByLocation(i.getUnitId(),a.getSheetId(),n,r);if(!o)return;let s=this._dataValidatorRegistryService.getValidatorItem(o.type);return s==null?void 0:s.dropdownType}_initSelectionChange(){this.disposeWithMe(this._sheetsSelectionsService.selectionMoveEnd$.subscribe(e=>{e&&e.every(e=>!(e.primary&&this._getDropdownByCell(e.primary.unitId,e.primary.sheetId,e.primary.actualRow,e.primary.actualColumn)))&&this.hideDropdown()}))}showDropdown(e){let{location:t}=e,{row:n,col:r,unitId:i,subUnitId:a,workbook:o,worksheet:s}=t;if(this._currentPopup&&this._currentPopup.dispose(),this._zenVisible)return;this._activeDropdown=e,this._activeDropdown$.next(this._activeDropdown);let m=this._sheetDataValidationModel.getRuleByLocation(i,a,n,r);if(!m)return;let h=this._dataValidatorRegistryService.getValidatorItem(m.type);if(!(h!=null&&h.dropdownType))return;let _,v=async(e,t)=>{var d,f,_;if(!e)return!0;let v=e,y=s.getCell(n,r),b=v.format(t===`date`?`YYYY-MM-DD 00:00:00`:`YYYY-MM-DD HH:mm:ss`),x=(d=c.numfmt.parseDate(b))==null?void 0:d.v,S=t===`time`?x%1:x,C=o.getStyles().getStyleByCell(y),w=(f=C==null||(_=C.n)==null?void 0:_.pattern)==null?``:f;return m.errorStyle!==c.DataValidationErrorStyle.STOP||await h.validator({value:S,unitId:i,subUnitId:a,row:n,column:r,worksheet:s,workbook:o,interceptValue:b.replace(`Z`,``).replace(`T`,` `),t:c.CellValueType.NUMBER},m)?(await this._commandService.executeCommand(u.SetRangeValuesCommand.id,{unitId:i,subUnitId:a,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:S,t:2,p:null,f:null,si:null,s:{n:{pattern:I(t,w)}}}}),await this._commandService.executeCommand(g.SetCellEditVisibleOperation.id,{visible:!1,eventType:l.DeviceInputEventType.Keyboard,unitId:i,keycode:p.KeyCode.ESC}),!0):(this._injector.has(P)&&this._injector.get(P).showReject(h.getRuleFinalError(m,{row:n,col:r,unitId:i,subUnitId:a})),!1)},y;switch(h.dropdownType){case f.DataValidatorDropdownType.DATE:{var b;let e=F((0,d.getCellValueOrigin)(s.getCellRaw(n,r))),i=!!((b=m.bizInfo)!=null&&b.showTime);y={location:t,type:`datepicker`,props:{showTime:i,onChange:e=>v(e,i?`datetime`:`date`),defaultValue:e,patternType:`date`}};break}case f.DataValidatorDropdownType.TIME:y={location:t,type:`datepicker`,props:{onChange:e=>v(e,`time`),defaultValue:F((0,d.getCellValueOrigin)(s.getCellRaw(n,r))),patternType:`time`}};break;case f.DataValidatorDropdownType.DATETIME:y={location:t,type:`datepicker`,props:{onChange:e=>v(e,`datetime`),defaultValue:F((0,d.getCellValueOrigin)(s.getCellRaw(n,r))),patternType:`datetime`}};break;case f.DataValidatorDropdownType.LIST:case f.DataValidatorDropdownType.MULTIPLE_LIST:{var x,S,C,w;let e=h.dropdownType===f.DataValidatorDropdownType.MULTIPLE_LIST,o=async t=>{let o=(0,d.serializeListOptions)(t),s={unitId:i,subUnitId:a,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:o,p:null,f:null,si:null}};return this._commandService.executeCommand(u.SetRangeValuesCommand.id,s),this._editorBridgeService.isVisible().visible&&await this._commandService.executeCommand(g.SetCellEditVisibleOperation.id,{visible:!1,eventType:l.DeviceInputEventType.Keyboard,unitId:i,keycode:p.KeyCode.ESC}),!e},v=(m==null?void 0:m.renderMode)===c.DataValidationRenderMode.CUSTOM||(m==null?void 0:m.renderMode)===void 0,b=h.getListWithColor(m,i,a),T=(0,d.getDataValidationCellValue)(s.getCellRaw(n,r));y={location:t,type:`list`,props:{onChange:e=>o(e),options:b.map(e=>({label:e.label,value:e.label,color:v||e.color?e.color||`#ECECEC`:`transparent`})),onEdit:()=>{this._commandService.executeCommand(z.id,{ruleId:m.uid}),_==null||_.dispose()},defaultValue:T,multiple:e,showEdit:(x=(S=this._configService.getConfig(`sheets-data-validation-ui.config`))==null?void 0:S.showEditOnDropdown)==null?!0:x,showSearch:(C=(w=this._configService.getConfig(`sheets-data-validation-ui.config`))==null?void 0:w.showSearchOnDropdown)==null?!0:C}};break}case f.DataValidatorDropdownType.CASCADE:var T;y={type:`cascader`,props:{onChange:e=>{let t={unitId:i,subUnitId:a,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:e.join(`/`),p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(u.SetRangeValuesCommand.id,t),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(g.SetCellEditVisibleOperation.id,{visible:!1,eventType:l.DeviceInputEventType.Keyboard,unitId:i,keycode:p.KeyCode.ESC}),!0},defaultValue:(0,d.getDataValidationCellValue)(s.getCellRaw(n,r)).split(`/`),options:JSON.parse((T=m.formula1)==null?`[]`:T)},location:t};break;case f.DataValidatorDropdownType.COLOR:y={type:`color`,props:{onChange:e=>{let t={unitId:i,subUnitId:a,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:e,p:null,f:null,si:null}};return this._commandService.syncExecuteCommand(u.SetRangeValuesCommand.id,t),this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(g.SetCellEditVisibleOperation.id,{visible:!1,eventType:l.DeviceInputEventType.Keyboard,unitId:i,keycode:p.KeyCode.ESC}),!0},defaultValue:(0,d.getDataValidationCellValue)(s.getCellRaw(n,r))},location:t};break;default:throw Error(`[DataValidationDropdownManagerService]: unknown type!`)}if(_=this._cellDropdownManagerService.showDropdown({...y,onHide:()=>{this._activeDropdown=null,this._activeDropdown$.next(null)}}),!_)throw Error(`[DataValidationDropdownManagerService]: cannot show dropdown!`);let E=new c.DisposableCollection;E.add(_),E.add({dispose:()=>{var e,t;(e=this._activeDropdown)==null||(t=e.onHide)==null||t.call(e)}}),this._currentPopup=E}hideDropdown(){this._activeDropdown&&(this._currentPopup&&this._currentPopup.dispose(),this._currentPopup=null,this._activeDropdown=null,this._activeDropdown$.next(null))}showDataValidationDropdown(e,t,n,r,i){let a=this._univerInstanceService.getUnit(e,c.UniverInstanceType.UNIVER_SHEET);if(!a)return;let o=a.getSheetBySheetId(t);if(!o)return;let s=this._dataValidationModel.getRuleByLocation(a.getUnitId(),o.getSheetId(),n,r);if(!s)return;let l=this._dataValidatorRegistryService.getValidatorItem(s.type);if(!l||!l.dropdownType){this.hideDropdown();return}this.showDropdown({location:{workbook:a,worksheet:o,row:n,col:r,unitId:e,subUnitId:t},onHide:i})}};L=A([k(0,c.IUniverInstanceService),k(1,(0,c.Inject)(f.DataValidatorRegistryService)),k(2,p.IZenZoneService),k(3,(0,c.Inject)(d.SheetDataValidationModel)),k(4,(0,c.Inject)(u.SheetsSelectionsService)),k(5,(0,c.Inject)(g.ISheetCellDropdownManagerService)),k(6,(0,c.Inject)(d.SheetDataValidationModel)),k(7,c.ICommandService),k(8,g.IEditorBridgeService),k(9,(0,c.Inject)(c.Injector)),k(10,c.IConfigService)],L);const R=`DataValidationPanel`,z={id:`data-validation.operation.open-validation-panel`,type:c.CommandType.OPERATION,handler(e,t){if(!t)return!1;let{ruleId:n,isAdd:r}=t,i=e.get(j),a=e.get(f.DataValidationModel),o=e.get(c.IUniverInstanceService),s=e.get(p.ISidebarService),l=(0,u.getSheetCommandTarget)(o);if(!l)return!1;let{unitId:d,subUnitId:m}=l,h=n?a.getRuleById(d,m,n):void 0;i.open(),i.setActiveRule(h&&{unitId:d,subUnitId:m,rule:h});let g=s.open({id:R,header:{title:r?`dataValidation.panel.addTitle`:`dataValidation.panel.title`},children:{label:R},width:312,onClose:()=>i.close()});return i.setCloseDisposable(g),!0}},B={id:`data-validation.operation.close-validation-panel`,type:c.CommandType.OPERATION,handler(e){return e.get(j).close(),!0}},V={id:`data-validation.operation.toggle-validation-panel`,type:c.CommandType.OPERATION,handler(e){let t=e.get(c.ICommandService),n=e.get(j);return n.open(),n.isOpen?t.executeCommand(B.id):t.executeCommand(z.id),!0}},H={type:c.CommandType.OPERATION,id:`sheet.operation.show-data-validation-dropdown`,handler(e,t){if(!t)return!1;let n=e.get(L),{unitId:r,subUnitId:i,row:a,column:o}=t,s=n.activeDropdown,c=s==null?void 0:s.location;return c&&c.unitId===r&&c.subUnitId===i&&c.row===a&&c.col===o||n.showDataValidationDropdown(r,i,a,o),!0}},U={type:c.CommandType.OPERATION,id:`sheet.operation.hide-data-validation-dropdown`,handler(e,t){return t?(e.get(L).hideDropdown(),!0):!1}},W={type:c.CommandType.COMMAND,id:`data-validation.command.addRuleAndOpen`,handler(e){let t=(0,u.getSheetCommandTarget)(e.get(c.IUniverInstanceService));if(!t)return!1;let{workbook:n,worksheet:r}=t,i=(0,d.createDefaultNewRule)(e),a=e.get(c.ICommandService),o={rule:i,unitId:n.getUnitId(),subUnitId:r.getSheetId()};return a.syncExecuteCommand(d.AddSheetDataValidationCommand.id,o)?(a.syncExecuteCommand(z.id,{ruleId:i.uid,isAdd:!0}),!0):!1}},G=`SHEET_DATA_VALIDATION_ALERT`;let K=class extends c.Disposable{constructor(e,t,n,r,i,a){super(),this._hoverManagerService=e,this._cellAlertManagerService=t,this._univerInstanceService=n,this._localeService=r,this._zenZoneService=i,this._dataValidationModel=a,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0,m.debounceTime)(100)).subscribe(e=>{if(e){let n=this._univerInstanceService.getUnit(e.location.unitId,c.UniverInstanceType.UNIVER_SHEET),r=n.getSheetBySheetId(e.location.subUnitId);if(!r)return;let i=this._dataValidationModel.getRuleByLocation(e.location.unitId,e.location.subUnitId,e.location.row,e.location.col);if(!i){this._cellAlertManagerService.removeAlert(G);return}if(this._dataValidationModel.validator(i,{...e.location,workbook:n,worksheet:r})===c.DataValidationStatus.INVALID){var t;let n=this._cellAlertManagerService.currentAlert.get(G),r=n==null||(t=n.alert)==null?void 0:t.location;if(r&&r.row===e.location.row&&r.col===e.location.col&&r.subUnitId===e.location.subUnitId&&r.unitId===e.location.unitId){this._cellAlertManagerService.removeAlert(G);return}let a=this._dataValidationModel.getValidator(i.type);if(!a){this._cellAlertManagerService.removeAlert(G);return}this._cellAlertManagerService.showAlert({type:g.CellAlertType.ERROR,title:this._localeService.t(`dataValidation.error.title`),message:a==null?void 0:a.getRuleFinalError(i,e.location),location:e.location,width:200,height:74,key:G});return}}this._cellAlertManagerService.removeAlert(G)}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._cellAlertManagerService.removeAlert(G)}))}};K=A([k(0,(0,c.Inject)(g.HoverManagerService)),k(1,(0,c.Inject)(g.CellAlertManagerService)),k(2,c.IUniverInstanceService),k(3,(0,c.Inject)(c.LocaleService)),k(4,p.IZenZoneService),k(5,(0,c.Inject)(d.SheetDataValidationModel))],K);let q=class extends c.Disposable{constructor(e,t,n){super(),this._autoFillService=e,this._sheetDataValidationModel=t,this._injector=n,this._initAutoFill()}_initAutoFill(){let e=()=>({redos:[],undos:[]}),t=(e,t)=>{let{source:n,target:r,unitId:i,subUnitId:a}=e,o=this._sheetDataValidationModel.getRuleObjectMatrix(i,a).clone(),s=(0,g.virtualizeDiscreteRanges)([n,r]),[l,f]=s.ranges,{mapFunc:p}=s,m={row:l.startRow,col:l.startColumn},h=u.AutoFillTools.getAutoFillRepeatRange(l,f),_=new c.ObjectMatrix,v=new Set;h.forEach(e=>{let t=e.repeatStartCell,n=e.relativeRange,r={startRow:m.row,startColumn:m.col,endColumn:m.col,endRow:m.row},o={startRow:t.row,startColumn:t.col,endColumn:t.col,endRow:t.row};c.Range.foreach(n,(e,t)=>{let n=c.Rectangle.getPositionRange({startRow:e,startColumn:t,endColumn:t,endRow:e},r),{row:s,col:l}=p(n.startRow,n.startColumn),u=this._sheetDataValidationModel.getRuleIdByLocation(i,a,s,l)||``,d=c.Rectangle.getPositionRange({startRow:e,startColumn:t,endColumn:t,endRow:e},o),{row:f,col:m}=p(d.startRow,d.startColumn);_.setValue(f,m,u),v.add(u)})});let y=Array.from(v).map(e=>({id:e,ranges:(0,c.queryObjectMatrix)(_,t=>t===e)}));o.addRangeRules(y);let{redoMutations:b,undoMutations:x}=(0,d.getDataValidationDiffMutations)(i,a,o.diff(this._sheetDataValidationModel.getRules(i,a)),this._injector,`patched`,t===u.AUTO_FILL_APPLY_TYPE.ONLY_FORMAT);return{undos:x,redos:b}},n={id:d.DATA_VALIDATION_PLUGIN_NAME,onBeforeFillData:e=>{let{source:t,unitId:n,subUnitId:r}=e;for(let e of t.rows)for(let i of t.cols){let t=this._sheetDataValidationModel.getRuleByLocation(n,r,e,i);if(t&&t.type===c.DataValidationType.CHECKBOX){this._autoFillService.setDisableApplyType(u.AUTO_FILL_APPLY_TYPE.SERIES,!0);return}}},onFillData:(n,r,i)=>i===u.AUTO_FILL_APPLY_TYPE.COPY||i===u.AUTO_FILL_APPLY_TYPE.ONLY_FORMAT||i===u.AUTO_FILL_APPLY_TYPE.SERIES?t(n,i):e(),onAfterFillData:()=>{}};this.disposeWithMe(this._autoFillService.addHook(n))}};q=A([k(0,u.IAutoFillService),k(1,(0,c.Inject)(d.SheetDataValidationModel)),k(2,(0,c.Inject)(c.Injector))],q);const ee=[g.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,g.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,g.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,g.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA];let J=class extends c.Disposable{constructor(e,t,n,r){super(),this._sheetClipboardService=e,this._sheetDataValidationModel=t,this._injector=n,this._univerInstanceService=r,O(this,`_copyInfo`,void 0),this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:d.DATA_VALIDATION_PLUGIN_NAME,onBeforeCopy:(e,t,n)=>this._collect(e,t,n),onPasteCells:(e,t,n,r)=>!e||!this._copyInfo||ee.includes(r.pasteType)?{redos:[],undos:[]}:this._generateMutations(e,t,r)})}_collect(e,t,n){let r=new c.ObjectMatrix;this._copyInfo={unitId:e,subUnitId:t,matrix:r};let i=this._injector.invoke(r=>(0,u.rangeToDiscreteRange)(n,r,e,t));if(!i)return;let{rows:a,cols:o}=i;a.forEach((n,i)=>{o.forEach((a,o)=>{let s=this._sheetDataValidationModel.getRuleIdByLocation(e,t,n,a);r.setValue(i,o,s==null?``:s)})})}_generateMutations(e,t,n){let{unitId:r,subUnitId:i,range:a}=e,{unitId:o,subUnitId:s,range:l}=t,{copyType:f=g.COPY_TYPE.COPY}=n;if(!(0,u.getSheetCommandTarget)(this._univerInstanceService,{unitId:o,subUnitId:s}))return{redos:[],undos:[]};if(f===g.COPY_TYPE.CUT&&o===r&&s===i)return this._copyInfo=null,{redos:[],undos:[]};if(o!==r||s!==i){let e=this._sheetDataValidationModel.getRuleObjectMatrix(o,s).clone(),t=new c.ObjectMatrix,n=new Set,{ranges:[u,p],mapFunc:m}=(0,g.virtualizeDiscreteRanges)([a,l]),h=(0,g.getRepeatRange)(u,p,!0),_=new Map;h.forEach(({startRange:e})=>{var a;(a=this._copyInfo)==null||a.matrix.forValue((a,l,u)=>{let d=c.Rectangle.getPositionRange({startRow:a,endRow:a,startColumn:l,endColumn:l},e),f=`${i}-${u}`,p=this._sheetDataValidationModel.getRuleById(r,i,u);!this._sheetDataValidationModel.getRuleById(o,s,f)&&p&&_.set(f,{...p,uid:f});let{row:h,col:g}=m(d.startRow,d.startColumn);n.add(f),t.setValue(h,g,f)})});let v=Array.from(n).map(e=>({id:e,ranges:(0,c.queryObjectMatrix)(t,t=>t===e)}));e.addRangeRules(v);let{redoMutations:y,undoMutations:b}=(0,d.getDataValidationDiffMutations)(o,s,e.diffWithAddition(this._sheetDataValidationModel.getRules(o,s),_.values()),this._injector,`patched`,!1);if(f===g.COPY_TYPE.CUT){let e=this._sheetDataValidationModel.getRuleObjectMatrix(r,i).clone(),t=m(u.startRow,u.startColumn),n=m(u.endRow,u.endColumn);e.addRangeRules([{id:``,ranges:[{startRow:t.row,endRow:n.row,startColumn:t.col,endColumn:n.col}]}]);let{redoMutations:a,undoMutations:o}=(0,d.getDataValidationDiffMutations)(r,i,e.diff(this._sheetDataValidationModel.getRules(r,i)),this._injector,`patched`,!1);y.push(...a),b.push(...o)}return{redos:y,undos:b}}else{let e=this._sheetDataValidationModel.getRuleObjectMatrix(r,i).clone(),t=new c.ObjectMatrix,n=new Set,{ranges:[u,f],mapFunc:p}=(0,g.virtualizeDiscreteRanges)([a,l]);(0,g.getRepeatRange)(u,f,!0).forEach(({startRange:e})=>{var r;(r=this._copyInfo)==null||r.matrix.forValue((r,i,a)=>{let o=c.Rectangle.getPositionRange({startRow:r,endRow:r,startColumn:i,endColumn:i},e),{row:s,col:l}=p(o.startRow,o.startColumn);t.setValue(s,l,a),n.add(a)})});let m=Array.from(n).map(e=>({id:e,ranges:(0,c.queryObjectMatrix)(t,t=>t===e)}));e.addRangeRules(m);let{redoMutations:h,undoMutations:_}=(0,d.getDataValidationDiffMutations)(o,s,e.diff(this._sheetDataValidationModel.getRules(r,i)),this._injector,`patched`,!1);return{redos:h,undos:_}}}};J=A([k(0,g.ISheetClipboardService),k(1,(0,c.Inject)(d.SheetDataValidationModel)),k(2,(0,c.Inject)(c.Injector)),k(3,(0,c.Inject)(c.IUniverInstanceService))],J);let Y=class extends c.Disposable{constructor(e,t,n){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=n,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===d.AddSheetDataValidationCommand.id){let{unitId:t,subUnitId:n,rule:{ranges:r}}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[u.WorkbookEditablePermission],rangeTypes:[u.RangeProtectionPermissionEditPoint],worksheetTypes:[u.WorksheetEditPermission,u.WorksheetSetCellStylePermission]},r,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.setStyleErr`))}if(e.id===d.UpdateSheetDataValidationRangeCommand.id){let{unitId:t,subUnitId:n,ranges:r}=e.params;this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[u.WorkbookEditablePermission],rangeTypes:[u.RangeProtectionPermissionEditPoint],worksheetTypes:[u.WorksheetEditPermission,u.WorksheetSetCellStylePermission]},r,t,n)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`permission.dialog.setStyleErr`))}}))}};Y=A([k(0,(0,c.Inject)(c.LocaleService)),k(1,c.ICommandService),k(2,(0,c.Inject)(u.SheetPermissionCheckController))],Y);const te=`sheet.menu.data-validation`;function X(e){return{id:te,type:p.MenuItemType.SUBITEMS,icon:`DataValidationIcon`,tooltip:`dataValidation.title`,hidden$:(0,p.getMenuHiddenObservable)(e,c.UniverInstanceType.UNIVER_SHEET),disabled$:(0,g.getCurrentRangeDisable$)(e,{workbookTypes:[u.WorkbookEditablePermission],worksheetTypes:[u.WorksheetSetCellStylePermission,u.WorksheetEditPermission],rangeTypes:[u.RangeProtectionPermissionEditPoint]})}}function ne(e){return{id:z.id,title:`dataValidation.panel.title`,type:p.MenuItemType.BUTTON}}function re(e){return{id:W.id,title:`dataValidation.panel.add`,type:p.MenuItemType.BUTTON}}const ie={[p.RibbonDataGroup.RULES]:{[te]:{order:0,menuItemFactory:X,[z.id]:{order:0,menuItemFactory:ne},[W.id]:{order:1,menuItemFactory:re}}}},ae={tr:{size:6,color:`#fe4b4b`}};let Z=class extends c.RxDisposable{constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._commandService=e,this._menuManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._autoHeightController=i,this._dropdownManagerService=a,this._sheetDataValidationModel=o,this._dataValidatorRegistryService=s,this._sheetInterceptorService=c,this._dataValidationCacheService=l,this._editorBridgeService=u,this._initMenu(),this._initDropdown(),this._initViewModelIntercept(),this._initAutoHeight()}_initMenu(){this._menuManagerService.mergeMenu(ie)}_initDropdown(){this._editorBridgeService&&this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{if(!e.visible){var t;((t=this._dropdownManagerService.activeDropdown)==null?void 0:t.trigger)===`editor-bridge`&&this._dropdownManagerService.hideDropdown();return}let n=this._editorBridgeService.getEditCellState();if(n){let{unitId:e,sheetId:t,row:r,column:i}=n,a=this._univerInstanceService.getUniverSheetInstance(e);if(!a)return;let o=this._sheetDataValidationModel.getRuleByLocation(e,t,r,i);if(!o)return;let s=this._dataValidatorRegistryService.getValidatorItem(o.type);if(!(s!=null&&s.dropdownType))return;let c=a.getActiveSheet();if(!c)return;let l=this._dropdownManagerService.activeDropdown,u=l==null?void 0:l.location;if(u&&u.unitId===e&&u.subUnitId===t&&u.row===r&&u.col===i)return;this._dropdownManagerService.showDropdown({location:{unitId:e,subUnitId:t,row:r,col:i,workbook:a,worksheet:c},trigger:`editor-bridge`,closeOnOutSide:!1})}}))}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(u.INTERCEPTOR_POINT.CELL_CONTENT,{effect:c.InterceptorEffectEnum.Style,priority:u.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,t,n)=>{var r,i,a,o,s;let{row:l,col:u,unitId:f,subUnitId:p,workbook:m,worksheet:h}=t,_=this._sheetDataValidationModel.getRuleIdByLocation(f,p,l,u);if(!_)return n(e);let v=this._sheetDataValidationModel.getRuleById(f,p,_);if(!v)return n(e);let y=(r=this._dataValidationCacheService.getValue(f,p,l,u))==null?c.DataValidationStatus.VALID:r,b=this._dataValidatorRegistryService.getValidatorItem(v.type),x=t.rawData,S,C={get value(){var e;return S===void 0&&(S=(e=(0,d.getCellValueOrigin)(x))==null?null:e),S}},w={get value(){var e;return`${(e=C.value)==null?``:e}`}};return(!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,...y===c.DataValidationStatus.INVALID?ae:null},e.customRender=[...(i=e==null?void 0:e.customRender)==null?[]:i,...b!=null&&b.canvasRender?[b.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:(e==null||(a=e.fontRenderExtension)==null?void 0:a.isSkip)||(b==null||(o=b.skipDefaultFontRender)==null?void 0:o.call(b,v,C.value,t))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...b==null?void 0:b.getExtraStyle(v,w.value,{get style(){let t=m.getStyles();return(typeof(e==null?void 0:e.s)==`string`?t.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},l,u)},e.interceptorAutoHeight=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(g.SheetSkeletonManagerService).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(l,u),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?l:n,(r=s==null?void 0:s.startColumn)==null?u:r),unitId:f,subUnitId:p,row:l,col:u,workbook:m,worksheet:h};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoHeight)==null?void 0:a.call(i,c)},e.interceptorAutoWidth=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(g.SheetSkeletonManagerService).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(l,u),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?l:n,(r=s==null?void 0:s.startColumn)==null?u:r),unitId:f,subUnitId:p,row:l,col:u,workbook:m,worksheet:h};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoWidth)==null?void 0:a.call(i,c)},e.coverable=((s=e==null?void 0:e.coverable)==null?!0:s)&&!(v.type===c.DataValidationType.LIST||v.type===c.DataValidationType.LIST_MULTIPLE),n(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe((0,m.filter)(e=>e.source===`command`),(0,m.bufferTime)(100)).subscribe(e=>{if(e.length===0)return;let t=[];e.forEach(e=>{if(e.rule.type===c.DataValidationType.LIST_MULTIPLE||e.rule.type===c.DataValidationType.LIST){var n;(n=e.rule)!=null&&n.ranges&&t.push(...e.rule.ranges)}}),t.length&&(0,c.sequenceExecute)(this._autoHeightController.getUndoRedoParamsOfAutoHeight(t).redos,this._commandService)})}};Z=A([k(0,c.ICommandService),k(1,p.IMenuManagerService),k(2,l.IRenderManagerService),k(3,c.IUniverInstanceService),k(4,(0,c.Inject)(g.AutoHeightController)),k(5,(0,c.Inject)(L)),k(6,(0,c.Inject)(d.SheetDataValidationModel)),k(7,(0,c.Inject)(f.DataValidatorRegistryService)),k(8,(0,c.Inject)(u.SheetInterceptorService)),k(9,(0,c.Inject)(d.DataValidationCacheService)),k(10,(0,c.Optional)(g.IEditorBridgeService))],Z);let oe=class extends c.RxDisposable{constructor(e,t,n,r,i,a,o){super(),this._commandService=e,this._renderManagerService=t,this._autoHeightController=n,this._dataValidatorRegistryService=r,this._sheetInterceptorService=i,this._sheetDataValidationModel=a,this._dataValidationCacheService=o,this._initViewModelIntercept(),this._initAutoHeight()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(u.INTERCEPTOR_POINT.CELL_CONTENT,{effect:c.InterceptorEffectEnum.Style,priority:u.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,t,n)=>{var r,i,a,o,s;let{row:l,col:u,unitId:f,subUnitId:p,workbook:m,worksheet:h}=t,_=this._sheetDataValidationModel.getRuleIdByLocation(f,p,l,u);if(!_)return n(e);let v=this._sheetDataValidationModel.getRuleById(f,p,_);if(!v)return n(e);let y=(r=this._dataValidationCacheService.getValue(f,p,l,u))==null?c.DataValidationStatus.VALID:r,b=this._dataValidatorRegistryService.getValidatorItem(v.type),x=(0,d.getCellValueOrigin)(h.getCellRaw(l,u)),S=`${x==null?``:x}`;return(!e||e===t.rawData)&&(e={...t.rawData}),e.markers={...e==null?void 0:e.markers,...y===c.DataValidationStatus.INVALID?ae:null},e.customRender=[...(i=e==null?void 0:e.customRender)==null?[]:i,...b!=null&&b.canvasRender?[b.canvasRender]:[]],e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,isSkip:(e==null||(a=e.fontRenderExtension)==null?void 0:a.isSkip)||(b==null||(o=b.skipDefaultFontRender)==null?void 0:o.call(b,v,x,t))},e.interceptorStyle={...e==null?void 0:e.interceptorStyle,...b==null?void 0:b.getExtraStyle(v,S,{get style(){let t=m.getStyles();return(typeof(e==null?void 0:e.s)==`string`?t.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},l,u)},e.interceptorAutoHeight=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(g.SheetSkeletonManagerService).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(l,u),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?l:n,(r=s==null?void 0:s.startColumn)==null?u:r),unitId:f,subUnitId:p,row:l,col:u,workbook:m,worksheet:h};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoHeight)==null?void 0:a.call(i,c)},e.interceptorAutoWidth=()=>{var t,n,r,i,a;let o=(t=this._renderManagerService.getRenderById(f))==null||(t=t.with(g.SheetSkeletonManagerService).getSkeletonParam(p))==null?void 0:t.skeleton;if(!o)return;let s=o.worksheet.getMergedCell(l,u),c={data:e,style:o.getStyles().getStyleByCell(e),primaryWithCoord:o.getCellWithCoordByIndex((n=s==null?void 0:s.startRow)==null?l:n,(r=s==null?void 0:s.startColumn)==null?u:r),unitId:f,subUnitId:p,row:l,col:u,workbook:m,worksheet:h};return b==null||(i=b.canvasRender)==null||(a=i.calcCellAutoWidth)==null?void 0:a.call(i,c)},e.coverable=((s=e==null?void 0:e.coverable)==null?!0:s)&&!(v.type===c.DataValidationType.LIST||v.type===c.DataValidationType.LIST_MULTIPLE),n(e)}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe((0,m.filter)(e=>e.source===`command`),(0,m.bufferTime)(16)).subscribe(e=>{let t=[];e.forEach(e=>{if(e.rule.type===c.DataValidationType.LIST_MULTIPLE||e.rule.type===c.DataValidationType.LIST){var n;(n=e.rule)!=null&&n.ranges&&t.push(...e.rule.ranges)}}),t.length&&(0,c.sequenceExecute)(this._autoHeightController.getUndoRedoParamsOfAutoHeight(t).redos,this._commandService)})}};oe=A([k(0,c.ICommandService),k(1,l.IRenderManagerService),k(2,(0,c.Inject)(g.AutoHeightController)),k(3,(0,c.Inject)(f.DataValidatorRegistryService)),k(4,(0,c.Inject)(u.SheetInterceptorService)),k(5,(0,c.Inject)(d.SheetDataValidationModel)),k(6,(0,c.Inject)(d.DataValidationCacheService))],oe);let se=class extends c.Disposable{constructor(e,t,n){super(),this._context=e,this._sheetDataValidationModel=t,this._sheetSkeletonManagerService=n,this._initSkeletonChange()}_initSkeletonChange(){this.disposeWithMe(this._sheetDataValidationModel.validStatusChange$.pipe((0,c.bufferDebounceTime)(16)).subscribe(e=>{var t;if(!e.length)return;let n=new Set;e.forEach(e=>{n.add(e.subUnitId)}),n.forEach(e=>{var t;(t=this._sheetSkeletonManagerService.getSkeletonParam(e))==null||t.skeleton.makeDirty(!0)}),(t=this._context.mainComponent)==null||t.makeForceDirty()}))}};se=A([k(1,(0,c.Inject)(d.SheetDataValidationModel)),k(2,(0,c.Inject)(g.SheetSkeletonManagerService))],se);function ce(e){var t;let n=(0,p.useDependency)(c.LocaleService),r=(0,p.useDependency)(p.ComponentManager),{value:i,onChange:a,extraComponent:o}=e,[s,l]=(0,v.useState)(!1),u=o?r.get(o):null;return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsxs)(`div`,{className:`univer-mb-3 univer-flex univer-cursor-pointer univer-items-center univer-text-sm univer-text-gray-900 dark:!univer-text-white`,onClick:()=>l(!s),children:[n.t(`dataValidation.panel.options`),s?(0,S.jsx)(y.MoreUpIcon,{className:`univer-ml-1`}):(0,S.jsx)(y.MoreDownIcon,{className:`univer-ml-1`})]}),s&&(0,S.jsxs)(S.Fragment,{children:[u?(0,S.jsx)(u,{value:i,onChange:a}):null,(0,S.jsx)(_.FormLayout,{label:n.t(`dataValidation.panel.invalid`),children:(0,S.jsxs)(_.RadioGroup,{value:`${(t=i.errorStyle)==null?c.DataValidationErrorStyle.WARNING:t}`,onChange:e=>a({...i,errorStyle:+e}),children:[(0,S.jsx)(_.Radio,{value:`${c.DataValidationErrorStyle.WARNING}`,children:n.t(`dataValidation.panel.showWarning`)}),(0,S.jsx)(_.Radio,{value:`${c.DataValidationErrorStyle.STOP}`,children:n.t(`dataValidation.panel.rejectInput`)})]})}),(0,S.jsx)(_.FormLayout,{label:n.t(`dataValidation.panel.messageInfo`),children:(0,S.jsx)(_.Checkbox,{checked:i.showErrorMessage,onChange:()=>a({...i,showErrorMessage:!i.showErrorMessage}),children:n.t(`dataValidation.panel.showInfo`)})}),i.showErrorMessage?(0,S.jsx)(_.FormLayout,{children:(0,S.jsx)(_.Input,{value:i.error,onChange:e=>a({...i,error:e})})}):null]})]})}const le=e=>(0,c.debounce)(async(t,n,r,i)=>{let a=await e.executeCommand(t,n,r);i==null||i(a)},1e3);function ue(e,t,n){var r;if(t){var i;return((i=e.getUnit(t))==null||(i=i.getSheetBySheetName(n))==null?void 0:i.getSheetId())||``}return((r=e.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET))==null||(r=r.getSheetBySheetName(n))==null?void 0:r.getSheetId())||``}function de(){var e,t;let[n,r]=(0,v.useState)(0),i=(0,p.useDependency)(j),{unitId:a,subUnitId:o,rule:s}=(0,p.useObservable)(i.activeRule$,i.activeRule)||{},l=s.uid,h=(0,p.useDependency)(f.DataValidatorRegistryService),g=(0,p.useDependency)(c.IUniverInstanceService),y=(0,p.useDependency)(p.ComponentManager),C=(0,p.useDependency)(c.ICommandService),w=(0,p.useDependency)(f.DataValidationModel),T=(0,p.useDependency)(c.LocaleService),E=(0,p.useObservable)(()=>g.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]),D=(0,p.useObservable)(()=>{var e;return(e=E==null?void 0:E.activeSheet$)==null?(0,m.of)(null):e},void 0,void 0,[]),[O,k]=(0,v.useState)(s),A=h.getValidatorItem(O.type),[M,N]=(0,v.useState)(!1),P=h.getValidatorsByScope(f.DataValidatorRegistryScope.SHEET),[F,I]=(0,v.useState)(()=>O.ranges.map(e=>({unitId:``,sheetId:``,range:e}))),L=(0,v.useMemo)(()=>le(C),[C]),[R,z]=(0,v.useState)(!1),[B,V]=(0,v.useState)(!1),H=(0,v.useRef)(null),U=(0,p.useDependency)(u.SheetsSelectionsService);if((0,v.useEffect)(()=>()=>{let e=U.getCurrentLastSelection();e&&U.setSelections([e])},[U]),(0,v.useEffect)(()=>{C.onCommandExecuted(e=>{(e.id===c.UndoCommand.id||e.id===c.RedoCommand.id)&&setTimeout(()=>{let e=w.getRuleById(a,o,l);r(e=>e+1),e&&(k(e),I(e.ranges.map(e=>({unitId:``,sheetId:``,range:e}))))},20)})},[C,w,l,o,a]),!A)return null;let W=A.operators,G=A.operatorNames,K=O.operator?f.TWO_FORMULA_OPERATOR_COUNT.includes(O.operator):!1,q=()=>{(D==null?void 0:D.getSheetId())!==o&&C.syncExecuteCommand(u.SetWorksheetActiveOperation.id,{unitId:a,subUnitId:o})},ee=()=>{var e;if(!((e=H.current)==null||(e=e.editor)==null)&&e.isFocus()){var t;J((t=H.current)==null?void 0:t.getValue())}!O.ranges.length||R||(A.validatorFormula(O,a,o).success?i.setActiveRule(null):N(!0),q())},J=(0,p.useEvent)(e=>{let t=e.split(`,`).filter(Boolean).map(b.deserializeRangeWithSheet).map(e=>{let t=e.sheetName;if(t){let n=ue(g,e.unitId,t);return{...e,sheetId:n}}return{...e,sheetId:``}});if((0,c.isUnitRangesEqual)(t,F))return;I(t);let n=t.filter(e=>(!e.unitId||e.unitId===a)&&(!e.sheetId||e.sheetId===o)).map(e=>e.range);if(k({...O,ranges:n}),n.length===0)return;let r={unitId:a,subUnitId:o,ruleId:l,ranges:n};L(d.UpdateSheetDataValidationRangeCommand.id,r)}),Y=e=>{if((0,c.shallowEqual)(e,(0,f.getRuleSetting)(O)))return;k({...O,...e});let t={unitId:a,subUnitId:o,ruleId:l,setting:e};L(d.UpdateSheetDataValidationSettingCommand.id,t,void 0)},te=async()=>{await C.executeCommand(d.RemoveSheetDataValidationCommand.id,{ruleId:l,unitId:a,subUnitId:o}),i.setActiveRule(null),q()},X={type:O.type,operator:O.operator,formula1:O.formula1,formula2:O.formula2,allowBlank:O.allowBlank},ne=e=>{let t=h.getValidatorItem(e);if(!t)return;let n=t.operators,r=w.getRuleById(a,o,l),i=e===(r==null?void 0:r.type)||e.includes(`list`)&&r!=null&&r.type.includes(`list`)?{...r,type:e}:{...O,type:e,operator:n[0],formula1:void 0,formula2:void 0};k(i),C.executeCommand(d.UpdateSheetDataValidationSettingCommand.id,{unitId:a,subUnitId:o,ruleId:O.uid,setting:(0,f.getRuleSetting)(i)})},re=y.get(A.formulaInput),ie=(0,v.useMemo)(()=>F.map(e=>(0,b.serializeRange)(e.range)).join(`,`),[]),ae=(0,f.getRuleOptions)(O),Z=e=>{(0,c.shallowEqual)(e,(0,f.getRuleOptions)(O))||(k({...O,...e}),L(d.UpdateSheetDataValidationOptionsCommand.id,{unitId:a,subUnitId:o,ruleId:l,options:e}))},oe=W.length&&!O.operator;return(0,S.jsxs)(`div`,{"data-u-comp":`data-validation-detail`,className:`univer-py-2`,children:[(0,S.jsx)(_.FormLayout,{label:T.t(`dataValidation.panel.range`),error:!O.ranges.length||R?T.t(`dataValidation.panel.rangeError`):``,children:(0,S.jsx)(x.RangeSelector,{selectorRef:H,unitId:a,subUnitId:o,initialValue:ie,onChange:(e,t)=>{var n;!B&&(n=H.current)!=null&&n.verify()&&J(t)},onFocusChange:(e,t)=>{var n;V(e),!e&&t&&(n=H.current)!=null&&n.verify()&&J(t)},onVerify:e=>z(!e)})}),(0,S.jsx)(_.FormLayout,{label:T.t(`dataValidation.panel.type`),children:(0,S.jsx)(_.Select,{className:`univer-w-full`,value:O.type,options:P==null||(e=P.sort((e,t)=>e.order-t.order))==null?void 0:e.map(e=>({label:T.t(e.title),value:e.id})),onChange:ne})}),W!=null&&W.length?(0,S.jsx)(_.FormLayout,{label:T.t(`dataValidation.panel.operator`),children:(0,S.jsx)(_.Select,{className:`univer-w-full`,value:`${O.operator}`,options:[{value:``,label:T.t(`dataValidation.operators.legal`)},...W.map((e,t)=>({value:`${e}`,label:G[t]}))],onChange:e=>{Y({...X,operator:e})}})}):null,re&&!oe?(0,S.jsx)(re,{isTwoFormula:K,value:{formula1:O.formula1,formula2:O.formula2},onChange:e=>{Y({...X,...e})},showError:M,validResult:A.validatorFormula(O,a,o),unitId:a,subUnitId:o,ruleId:l},n+O.type):null,(0,S.jsx)(_.FormLayout,{children:(0,S.jsx)(_.Checkbox,{checked:(t=O.allowBlank)==null?!0:t,onChange:()=>{var e;return Y({...X,allowBlank:!((e=O.allowBlank)==null||e)})},children:T.t(`dataValidation.panel.allowBlank`)})}),(0,S.jsx)(ce,{value:ae,onChange:Z,extraComponent:A.optionsInput}),(0,S.jsxs)(`div`,{className:`univer-mt-5 univer-flex univer-flex-row univer-justify-end`,children:[(0,S.jsx)(_.Button,{className:`univer-ml-3`,onClick:te,children:T.t(`dataValidation.panel.removeRule`)}),(0,S.jsx)(_.Button,{className:`univer-ml-3`,variant:`primary`,onClick:ee,children:T.t(`dataValidation.panel.done`)})]})]})}const fe=e=>{let{rule:t,onClick:n,unitId:r,subUnitId:i,disable:a}=e,o=(0,p.useDependency)(f.DataValidatorRegistryService),s=(0,p.useDependency)(c.ICommandService),l=(0,p.useDependency)(g.IMarkSelectionService),u=o.getValidatorItem(t.type),m=(0,v.useRef)(void 0),[h,x]=(0,v.useState)(!1),C=(0,p.useDependency)(c.ThemeService),w=(0,v.useMemo)(()=>{var e;let t=C.getColorFromTheme(`primary.600`),n=C.getColorFromTheme(`loop-color.2`),r=(e=C.getColorFromTheme(n))==null?t:e,i=new c.ColorKit(r).toRgb();return{fill:`rgba(${i.r}, ${i.g}, ${i.b}, 0.1)`,stroke:r}},[(0,p.useObservable)(C.currentTheme$)]),T=e=>{s.executeCommand(d.RemoveSheetDataValidationCommand.id,{ruleId:t.uid,unitId:r,subUnitId:i}),e.stopPropagation()};return(0,v.useEffect)(()=>()=>{if(m.current){var e;(e=m.current)==null||e.forEach(e=>{e&&l.removeShape(e)})}},[l]),(0,S.jsxs)(`div`,{className:(0,_.clsx)(`univer-bg-secondary univer-relative univer--mx-2 univer-box-border univer-flex univer-w-[287px] univer-cursor-pointer univer-flex-col univer-justify-between univer-overflow-hidden univer-rounded-md univer-p-2 univer-pr-9`,{"hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-700":!a,"univer-opacity-50":a}),onClick:n,onMouseEnter:()=>{a||(x(!0),m.current=t.ranges.map(e=>l.addShape({range:e,style:w,primary:null})))},onMouseLeave:()=>{var e;x(!1),(e=m.current)==null||e.forEach(e=>{e&&l.removeShape(e)}),m.current=void 0},children:[(0,S.jsx)(`div`,{className:`univer-truncate univer-text-sm univer-font-medium univer-leading-[22px] univer-text-gray-900 dark:!univer-text-white`,children:u==null?void 0:u.generateRuleName(t)}),(0,S.jsx)(`div`,{className:`univer-text-secondary univer-truncate univer-text-xs univer-leading-[18px] dark:!univer-text-gray-300`,children:t.ranges.map(e=>(0,b.serializeRange)(e)).join(`,`)}),h?(0,S.jsx)(`div`,{className:`univer-absolute univer-right-2 univer-top-[19px] univer-flex univer-size-5 univer-items-center univer-justify-center univer-rounded hover:univer-bg-gray-200 dark:!univer-text-gray-300 dark:hover:!univer-bg-gray-700`,onClick:T,children:(0,S.jsx)(y.DeleteIcon,{})}):null]})};function pe(e){let t=(0,p.useDependency)(d.SheetDataValidationModel),n=(0,p.useDependency)(c.IUniverInstanceService),r=(0,p.useDependency)(c.ICommandService),i=(0,p.useDependency)(c.Injector),a=(0,p.useDependency)(j),o=(0,p.useDependency)(c.LocaleService),[s,l]=(0,v.useState)([]),{workbook:f}=e,m=(0,p.useObservable)(f.activeSheet$,void 0,!0),h=f.getUnitId(),g=m==null?void 0:m.getSheetId();(0,v.useEffect)(()=>{l(t.getRules(h,g));let e=t.ruleChange$.subscribe(e=>{e.unitId===h&&e.subUnitId===g&&l(t.getRules(h,g))});return()=>{e.unsubscribe()}},[h,g,t]);let y=async()=>{let e=(0,d.createDefaultNewRule)(i),t={unitId:h,subUnitId:g,rule:e};await r.executeCommand(d.AddSheetDataValidationCommand.id,t),a.setActiveRule({unitId:h,subUnitId:g,rule:e})},b=()=>{r.executeCommand(d.RemoveSheetAllDataValidationCommand.id,{unitId:h,subUnitId:g})},x=(e=>{let t=n.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET),r=t.getActiveSheet(),a=t.getUnitId(),o=r.getSheetId();return e.map(e=>(0,u.checkRangesEditablePermission)(i,a,o,e.ranges)?{...e}:{...e,disable:!0})})(s),C=x==null?void 0:x.some(e=>e.disable);return(0,S.jsxs)(`div`,{className:`univer-pb-4`,children:[x==null?void 0:x.map(e=>{var t;return(0,S.jsx)(fe,{unitId:h,subUnitId:g,onClick:()=>{e.disable||a.setActiveRule({unitId:h,subUnitId:g,rule:e})},rule:e,disable:(t=e.disable)==null?!1:t},e.uid)}),(0,S.jsxs)(`div`,{className:`univer-mt-4 univer-flex univer-flex-row univer-justify-end univer-gap-2`,children:[s.length&&!C?(0,S.jsx)(_.Button,{onClick:b,children:o.t(`dataValidation.panel.removeAll`)}):null,(0,S.jsx)(_.Button,{variant:`primary`,onClick:y,children:o.t(`dataValidation.panel.add`)})]})]})}const me=()=>{let e=(0,p.useDependency)(j),t=(0,p.useObservable)(e.activeRule$,e.activeRule),n=(0,p.useDependency)(c.IUniverInstanceService),r=(0,p.useObservable)(()=>n.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]),i=(0,p.useObservable)(()=>{var e;return(e=r==null?void 0:r.activeSheet$)==null?(0,m.of)(null):e},void 0,void 0,[]);return!r||!i?null:t&&(t.subUnitId===i.getSheetId()||t.subUnitId===e.getFocusFormulaEditorActiveRuleSubUnitId())?(0,S.jsx)(de,{},t.rule.uid):(0,S.jsx)(pe,{workbook:r})},he=e=>{let{isTwoFormula:t=!1,value:n,onChange:r,showError:i,validResult:a}=e,o=(0,p.useDependency)(c.LocaleService),s=i?a==null?void 0:a.formula1:``,l=i?a==null?void 0:a.formula2:``;return t?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(_.FormLayout,{error:s,children:(0,S.jsx)(_.Input,{className:`univer-w-full`,placeholder:o.t(`dataValidation.panel.formulaPlaceholder`),value:n==null?void 0:n.formula1,onChange:e=>{r==null||r({...n,formula1:e})}})}),(0,S.jsx)(`div`,{className:`-univer-mt-2 univer-mb-1 univer-text-sm univer-text-gray-400`,children:o.t(`dataValidation.panel.formulaAnd`)}),(0,S.jsx)(_.FormLayout,{error:l,children:(0,S.jsx)(_.Input,{className:`univer-w-full`,placeholder:o.t(`dataValidation.panel.formulaPlaceholder`),value:n==null?void 0:n.formula2,onChange:e=>{r==null||r({...n,formula2:e})}})})]}):(0,S.jsx)(_.FormLayout,{error:s,children:(0,S.jsx)(_.Input,{className:`univer-w-full`,placeholder:o.t(`dataValidation.panel.formulaPlaceholder`),value:n==null?void 0:n.formula1,onChange:e=>{r==null||r({formula1:e})}})})};function ge(e){let{value:t,onChange:n,showError:r,validResult:i}=e,a=(0,p.useDependency)(c.LocaleService),o=r?i==null?void 0:i.formula1:``,s=r?i==null?void 0:i.formula2:``,[l,u]=(0,v.useState)(!((t==null?void 0:t.formula1)===void 0&&(t==null?void 0:t.formula2)===void 0));return(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(_.FormLayout,{children:(0,S.jsx)(_.Checkbox,{checked:l,onChange:e=>{e?u(!0):(u(!1),n==null||n({...t,formula1:void 0,formula2:void 0}))},children:a.t(`dataValidation.checkbox.tips`)})}),l?(0,S.jsx)(_.FormLayout,{label:a.t(`dataValidation.checkbox.checked`),error:o,children:(0,S.jsx)(_.Input,{className:`univer-w-full`,placeholder:a.t(`dataValidation.panel.valuePlaceholder`),value:t==null?void 0:t.formula1,onChange:e=>{n==null||n({...t,formula1:e||void 0})}})}):null,l?(0,S.jsx)(_.FormLayout,{label:a.t(`dataValidation.checkbox.unchecked`),error:s,children:(0,S.jsx)(_.Input,{className:`univer-w-full`,placeholder:a.t(`dataValidation.panel.valuePlaceholder`),value:t==null?void 0:t.formula2,onChange:e=>{n==null||n({...t,formula2:e||void 0})}})}):null]})}function _e(e){var t;let{unitId:n,subUnitId:r,value:i,onChange:a,showError:o,validResult:s}=e,c=o?s==null?void 0:s.formula1:void 0,l=(0,v.useRef)(null),[u,d]=(0,v.useState)(!1);return(0,p.useSidebarClick)(e=>{var t;(t=l.current)!=null&&t.isClickOutSide(e)&&d(!1)}),(0,S.jsx)(_.FormLayout,{error:c,children:(0,S.jsx)(x.FormulaEditor,{ref:l,className:(0,_.clsx)(`univer-box-border univer-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-rounded-lg univer-bg-white univer-pt-2 univer-transition-colors hover:univer-border-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-white [&>div:first-child]:univer-px-2.5 [&>div]:univer-h-5 [&>div]:univer-ring-transparent`,_.borderClassName),initValue:(t=i==null?void 0:i.formula1)==null?`=`:t,unitId:n,subUnitId:r,isFocus:u,isSupportAcrossSheet:!0,onChange:e=>{let t=(e==null?``:e).trim();t!==(i==null?void 0:i.formula1)&&(a==null||a({...i,formula1:t}))},onFocus:()=>d(!0)})})}const ve=[`#FFFFFF`,`#FEE7E7`,`#FEF0E6`,`#EFFBD0`,`#E4F4FE`,`#E8ECFD`,`#F1EAFA`,`#FDE8F3`,`#E5E5E5`,`#FDCECE`,`#FDC49B`,`#DEF6A2`,`#9FDAFF`,`#D0D9FB`,`#E3D5F6`,`#FBD0E8`,`#656565`,`#FE4B4B`,`#FF8C51`,`#8BBB11`,`#0B9EFB`,`#3A60F7`,`#9E6DE3`,`#F248A6`],ye=e=>{let{value:t,onChange:n,disabled:r}=e,[i,a]=(0,v.useState)(!1);return(0,S.jsx)(_.Dropdown,{align:`start`,disabled:r,open:i,onOpenChange:a,overlay:(0,S.jsx)(`div`,{className:`univer-box-border univer-grid univer-w-fit univer-grid-cols-6 univer-flex-wrap univer-gap-2 univer-p-1.5`,children:ve.map(e=>(0,S.jsx)(`div`,{className:(0,_.clsx)(`univer-box-border univer-size-4 univer-cursor-pointer univer-rounded`,_.borderClassName),style:{background:e},onClick:()=>{n(e),a(!1)}},e))}),children:(0,S.jsxs)(`div`,{className:(0,_.clsx)(`univer-box-border univer-inline-flex univer-h-8 univer-w-16 univer-cursor-pointer univer-items-center univer-justify-between univer-gap-2 univer-rounded-lg univer-bg-white univer-px-2.5 univer-transition-colors univer-duration-200 hover:univer-border-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-white`,_.borderClassName),children:[(0,S.jsx)(`div`,{className:`univer-box-border univer-size-4 univer-rounded univer-text-base`,style:{background:t}}),(0,S.jsx)(y.MoreDownIcon,{})]})})},be=e=>{let{item:t,commonProps:n,className:r}=e,{onItemChange:i,onItemDelete:a}=n;return(0,S.jsxs)(`div`,{className:(0,_.clsx)(`univer-flex univer-items-center univer-gap-2`,r),children:[!t.isRef&&(0,S.jsx)(`div`,{className:(0,_.clsx)(`univer-cursor-move`,`draggableHandle`),children:(0,S.jsx)(y.SequenceIcon,{})}),(0,S.jsx)(ye,{value:t.color,onChange:e=>{i(t.id,t.label,e)}}),(0,S.jsx)(_.Input,{disabled:t.isRef,value:t.label,onChange:e=>{i(t.id,e,t.color)}}),t.isRef?null:(0,S.jsx)(`div`,{className:`univer-ml-1 univer-cursor-pointer univer-rounded univer-text-base hover:univer-bg-gray-200`,children:(0,S.jsx)(y.DeleteIcon,{onClick:()=>a(t.id)})})]})};function xe(e){let{value:t,onChange:n=()=>{},unitId:r,subUnitId:i,validResult:a,showError:o,ruleId:s}=e,{formula1:l=``,formula2:u=``}=t||{},[h,g]=(0,v.useState)(()=>(0,c.isFormulaString)(l)?`1`:`0`),[b,C]=(0,v.useState)(h===`1`?l:`=`),[w,T]=(0,v.useState)(h===`1`?l:`=`),E=(0,p.useDependency)(c.LocaleService),D=(0,p.useDependency)(f.DataValidatorRegistryService),O=(0,p.useDependency)(f.DataValidationModel),k=(0,p.useDependency)(d.DataValidationFormulaController),A=(0,p.useDependency)(j),[M,N]=(0,v.useState)(()=>u.split(`,`)),P=D.getValidatorItem(c.DataValidationType.LIST),[F,I]=(0,v.useState)([]),[L,R]=(0,v.useState)(``),z=o?a==null?void 0:a.formula1:``,B=(0,p.useObservable)((0,v.useMemo)(()=>O.ruleChange$.pipe((0,m.debounceTime)(16)),[])),V=(0,p.useEvent)(n);(0,v.useEffect)(()=>{(async()=>{await new Promise(e=>{setTimeout(()=>e(!0),100)});let e=O.getRuleById(r,i,s);(0,c.isFormulaString)(e==null?void 0:e.formula1)&&P&&e&&I(await P.getListAsync(e,r,i))})()},[O,B,P,s,i,r]),(0,v.useEffect)(()=>{(0,c.isFormulaString)(l)&&l!==w&&(C(l),T(w))},[w,l]);let[H,U]=(0,v.useState)(()=>{let e=h===`1`?[]:(0,d.deserializeListOptions)(l),t=u.split(`,`);return e.map((e,n)=>({label:e,color:t[n]||`#ECECEC`,isRef:!1,id:(0,c.generateRandomId)(4)}))}),W=(e,t,n)=>{let r=H.find(t=>t.id===e);r&&(r.label=t,r.color=n,U([...H]))},G=e=>{let t=H.findIndex(t=>t.id===e);t!==-1&&(H.splice(t,1),U([...H]))},K=u.split(`,`),q=(0,v.useMemo)(()=>F.map((e,t)=>({label:e,color:K[t]||`#ECECEC`,id:`${t}`,isRef:!0})),[K,F]),ee=(e,t,n)=>{let r=[...M];r[+e]=n,N(r),V({formula1:l,formula2:r.join(`,`)})},J=()=>{U([...H,{label:``,color:`#ECECEC`,isRef:!1,id:(0,c.generateRandomId)(4)}])};(0,v.useEffect)(()=>{if(h===`1`)return;let e=new Set,t=[];H.map(e=>({labelList:e.label.split(`,`),item:e})).forEach(({item:n,labelList:r})=>{r.forEach(r=>{e.has(r)||(e.add(r),t.push({label:r,color:n.color}))})}),V({formula1:(0,d.serializeListOptions)(t.map(e=>e.label)),formula2:t.map(e=>e.color===`#ECECEC`?``:e.color).join(`,`)})},[H,V,h,w,M]);let Y=(0,p.useEvent)(async e=>{if(!(0,c.isFormulaString)(e)){V==null||V({formula1:``,formula2:u});return}k.getFormulaRefCheck(e)?(V==null||V({formula1:(0,c.isFormulaString)(e)?e:``,formula2:u}),R(``)):(V==null||V({formula1:``,formula2:u}),C(`=`),R(E.t(`dataValidation.validFail.formulaError`)))}),te=(0,v.useRef)(null),[X,ne]=(0,v.useState)(!1);return(0,p.useSidebarClick)(e=>{var t;(t=te.current)!=null&&t.isClickOutSide(e)&&ne(!1)}),(0,v.useEffect)(()=>{X?A.setFocusFormulaEditorActiveRuleSubUnitId(i):A.setFocusFormulaEditorActiveRuleSubUnitId(null)},[X,i,A]),(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(_.FormLayout,{label:E.t(`dataValidation.list.options`),children:(0,S.jsxs)(_.RadioGroup,{value:h,onChange:e=>{g(e),C(w),e===`1`&&V({formula1:w===`=`?``:w,formula2:M.join(`,`)})},children:[(0,S.jsx)(_.Radio,{value:`0`,children:E.t(`dataValidation.list.customOptions`)}),(0,S.jsx)(_.Radio,{value:`1`,children:E.t(`dataValidation.list.refOptions`)})]})}),h===`1`?(0,S.jsxs)(_.FormLayout,{error:z||L||void 0,children:[(0,S.jsx)(x.FormulaEditor,{ref:te,className:(0,_.clsx)(`univer-box-border univer-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-rounded-lg univer-bg-white univer-pt-2 univer-transition-colors hover:univer-border-primary-600 dark:!univer-bg-gray-700 dark:!univer-text-white [&>div:first-child]:univer-px-2.5 [&>div]:univer-h-5 [&>div]:univer-ring-transparent`,_.borderClassName),initValue:b,unitId:r,subUnitId:i,isFocus:X,isSupportAcrossSheet:!0,onFocus:()=>ne(!0),onChange:(e=``)=>{let t=(e==null?``:e).trim();T(t),Y(t)}}),q.length>0&&(0,S.jsx)(`div`,{className:`univer-mt-3`,children:q.map(e=>(0,S.jsx)(be,{className:`univer-mb-3`,item:e,commonProps:{onItemChange:ee}},e.id))})]}):(0,S.jsx)(_.FormLayout,{error:z,children:(0,S.jsxs)(`div`,{className:`-univer-mt-3`,children:[(0,S.jsx)(_.DraggableList,{list:H,onListChange:U,rowHeight:28,margin:[0,12],draggableHandle:`.draggableHandle`,itemRender:e=>(0,S.jsx)(be,{item:e,commonProps:{onItemChange:W,onItemDelete:G}},e.id),idKey:`id`}),(0,S.jsxs)(`a`,{className:`univer-text-primary univer-flex univer-w-fit univer-cursor-pointer univer-flex-row univer-items-center univer-rounded univer-p-1 univer-px-2 univer-text-sm hover:univer-bg-primary-50 dark:hover:!univer-bg-gray-800`,onClick:J,children:[(0,S.jsx)(y.IncreaseIcon,{className:`univer-mr-1`}),E.t(`dataValidation.list.add`)]})]})})]})}const Se=[[d.CUSTOM_FORMULA_INPUT_NAME,_e],[d.BASE_FORMULA_INPUT_NAME,he],[d.LIST_FORMULA_INPUT_NAME,xe],[d.CHECKBOX_FORMULA_INPUT_NAME,ge]];function Ce(e){var t;let{value:n,onChange:r}=e,i=(0,p.useDependency)(c.LocaleService);return(0,S.jsx)(_.FormLayout,{label:i.t(`dataValidation.renderMode.label`),children:(0,S.jsxs)(_.RadioGroup,{value:`${(t=n.renderMode)==null?c.DataValidationRenderMode.CUSTOM:t}`,onChange:e=>r({...n,renderMode:+e}),children:[(0,S.jsx)(_.Radio,{value:`${c.DataValidationRenderMode.CUSTOM}`,children:i.t(`dataValidation.renderMode.chip`)}),(0,S.jsx)(_.Radio,{value:`${c.DataValidationRenderMode.ARROW}`,children:i.t(`dataValidation.renderMode.arrow`)}),(0,S.jsx)(_.Radio,{value:`${c.DataValidationRenderMode.TEXT}`,children:i.t(`dataValidation.renderMode.text`)})]})})}Ce.componentKey=`LIST_RENDER_MODE_OPTION_INPUT`;function we(e){var t;let{value:n,onChange:r}=e,i=(0,p.useDependency)(c.LocaleService);return(0,S.jsx)(_.FormLayout,{children:(0,S.jsx)(_.Checkbox,{checked:(t=n.bizInfo)==null?void 0:t.showTime,onChange:e=>{r({...n,bizInfo:{...n.bizInfo,showTime:e}})},children:i.t(`dataValidation.showTime.label`)})})}we.componentKey=`DATE_SHOW_TIME_OPTION`;let Te=class{_calc(e,t){var n,r,i;let{vt:a,ht:o}=t||{},s=e.endX-e.startX-12,l=e.endY-e.startY,u=((n=t==null?void 0:t.fs)==null?10:n)*1.6,d=0,f=0;switch(a){case c.VerticalAlign.TOP:f=0;break;case c.VerticalAlign.BOTTOM:f=0+(l-u);break;default:f=0+(l-u)/2;break}switch(o){case c.HorizontalAlign.LEFT:d=6;break;case c.HorizontalAlign.RIGHT:d=6+(s-u);break;default:d=6+(s-u)/2;break}return{left:e.startX+d,top:e.startY+f,width:((r=t==null?void 0:t.fs)==null?10:r)*1.6,height:((i=t==null?void 0:t.fs)==null?10:i)*1.6}}constructor(e,t,n,r,i,a){this._commandService=e,this._univerInstanceService=t,this._formulaService=n,this._themeService=r,this._renderManagerService=i,this._dataValidationModel=a}calcCellAutoHeight(e){var t;let{style:n}=e;return((t=n==null?void 0:n.fs)==null?10:t)*1.6}calcCellAutoWidth(e){var t;let{style:n}=e;return((t=n==null?void 0:n.fs)==null?10:t)*1.6}async _parseFormula(e,t,n){var r,i,a;let{formula1:o=d.CHECKBOX_FORMULA_1,formula2:s=d.CHECKBOX_FORMULA_2}=e,l=await this._formulaService.getRuleFormulaResult(t,n,e.uid),u=(0,d.getFormulaResult)(l==null||(r=l[0])==null||(r=r.result)==null||(r=r[0])==null?void 0:r[0]),f=(0,d.getFormulaResult)(l==null||(i=l[1])==null||(i=i.result)==null||(i=i[0])==null?void 0:i[0]),p=(0,d.isLegalFormulaResult)(String(u))&&(0,d.isLegalFormulaResult)(String(f));return{formula1:(0,c.isFormulaString)(o)?(0,d.getFormulaResult)(l==null||(a=l[0])==null||(a=a.result)==null||(a=a[0])==null?void 0:a[0]):o,formula2:(0,c.isFormulaString)(s)?f:s,isFormulaValid:p}}drawWith(e,t){var n,r,i,a;let{style:o,primaryWithCoord:s,unitId:c,subUnitId:u,worksheet:f,row:p,col:m}=t,h=s.isMergedMainCell?s.mergeInfo:s,g=(0,d.getCellValueOrigin)(f.getCellRaw(p,m)),_=this._dataValidationModel.getRuleByLocation(c,u,p,m);if(!_)return;let v=this._dataValidationModel.getValidator(_.type);if(!v||!((n=v.skipDefaultFontRender)!=null&&n.call(v,_,g,{unitId:c,subUnitId:u,row:p,column:m})))return;let{formula1:y}=v.parseFormulaSync(_,c,u),b=this._calc(h,o),{a:x,d:S}=e.getTransform(),C=(0,l.fixLineWidthByScale)(b.left,x),w=(0,l.fixLineWidthByScale)(b.top,S),T=l.Transform.create().composeMatrix({left:C,top:w,scaleX:1,scaleY:1,angle:0,skewX:0,skewY:0,flipX:!1,flipY:!1}),E=h.endX-h.startX,D=h.endY-h.startY;e.save(),e.beginPath(),e.rect(h.startX,h.startY,E,D),e.clip();let O=T.getMatrix();e.transform(O[0],O[1],O[2],O[3],O[4],O[5]);let k=((r=o==null?void 0:o.fs)==null?10:r)*1.6,A=String(g)===String(y),j=this._themeService.getColorFromTheme(`primary.600`);l.CheckboxShape.drawWith(e,{checked:A,width:k,height:k,fill:(i=o==null||(a=o.cl)==null?void 0:a.rgb)==null?j:i}),e.restore()}isHit(e,t){let n=t.primaryWithCoord.isMergedMainCell?t.primaryWithCoord.mergeInfo:t.primaryWithCoord,r=this._calc(n,t.style),i=r.top,a=r.top+r.height,o=r.left,s=r.left+r.width,{x:c,y:l}=e;return c<=s&&c>=o&&l<=a&&l>=i}async onPointerDown(e,t){var n;if(t.button===2)return;let{primaryWithCoord:r,unitId:i,subUnitId:a,worksheet:o,row:s,col:c}=e,l=(0,d.getCellValueOrigin)(o.getCellRaw(s,c)),f=this._dataValidationModel.getRuleByLocation(i,a,s,c);if(!f)return;let p=this._dataValidationModel.getValidator(f.type);if(!p||!((n=p.skipDefaultFontRender)!=null&&n.call(p,f,l,{unitId:i,subUnitId:a,row:s,column:c})))return;let{formula1:m,formula2:h}=await this._parseFormula(f,i,a),g={range:{startColumn:r.actualColumn,endColumn:r.actualColumn,startRow:r.actualRow,endRow:r.actualRow},value:{v:String(l)===(0,d.transformCheckboxValue)(String(m))?h:m,p:null}};this._commandService.executeCommand(u.SetRangeValuesCommand.id,g)}onPointerEnter(e,t){var n;(n=(0,l.getCurrentTypeOfRenderer)(c.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null||(n=n.mainComponent)==null||n.setCursor(l.CURSOR_TYPE.POINTER)}onPointerLeave(e,t){var n;(n=(0,l.getCurrentTypeOfRenderer)(c.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null||(n=n.mainComponent)==null||n.setCursor(l.CURSOR_TYPE.DEFAULT)}};Te=A([k(0,c.ICommandService),k(1,c.IUniverInstanceService),k(2,(0,c.Inject)(d.DataValidationFormulaService)),k(3,(0,c.Inject)(c.ThemeService)),k(4,(0,c.Inject)(l.IRenderManagerService)),k(5,(0,c.Inject)(d.SheetDataValidationModel))],Te);let Q=class{constructor(e){this.injector=e,O(this,`canvasRender`,null),O(this,`dropdownType`,void 0),O(this,`optionsInput`,void 0),O(this,`formulaInput`,d.LIST_FORMULA_INPUT_NAME)}};Q=A([k(0,(0,c.Inject)(c.Injector))],Q);var Ee=class extends Q{constructor(...e){super(...e),O(this,`id`,c.DataValidationType.CHECKBOX),O(this,`canvasRender`,this.injector.createInstance(Te)),O(this,`formulaInput`,d.CHECKBOX_FORMULA_INPUT_NAME)}},De=class extends Q{constructor(...e){super(...e),O(this,`id`,c.DataValidationType.CUSTOM),O(this,`formulaInput`,d.CUSTOM_FORMULA_INPUT_NAME)}},Oe=class extends Q{constructor(...e){super(...e),O(this,`id`,c.DataValidationType.DATE),O(this,`formulaInput`,`data-validation.formula-input`),O(this,`optionsInput`,we.componentKey),O(this,`dropdownType`,f.DataValidatorDropdownType.DATE)}},ke=class extends Q{constructor(...e){super(...e),O(this,`id`,c.DataValidationType.DECIMAL),O(this,`formulaInput`,d.BASE_FORMULA_INPUT_NAME)}};function Ae(e,t){let n=l.FontCache.getTextSize(e,t),r=n.width+8,{ba:i,bd:a}=n;return{width:r,height:i+a+0,ba:i}}function je(e,t,n,r){let i=n-26,a=r-12,o=e.map(e=>({layout:Ae(e,t),text:e})),s,c=[];o.forEach(e=>{let{layout:t}=e,{width:n,height:r}=t;!s||s.width+n+4>i?(s={width:n,height:r,items:[{...e,left:0}]},c.push(s)):(s.items.push({...e,left:s.width+4}),s.width=s.width+n+4)});let l=0,u=0;return c.forEach((e,t)=>{u=Math.max(u,e.width),t===c.length-1?l+=e.height:l+=e.height+4}),{lines:c,totalHeight:l,contentWidth:i,contentHeight:a,cellAutoHeight:l+12,calcAutoWidth:u+26}}var Me=class extends l.Shape{static drawWith(e,t){let{fontString:n,info:r,fill:i,color:a}=t,{layout:o,text:s}=r;e.save(),l.Rect.drawWith(e,{width:o.width,height:o.height,radius:8,fill:i||`#ECECEC`}),e.translateWithPrecision(4,o.ba),e.font=n,e.fillStyle=a,e.fillText(s,0,0),e.restore()}};const Ne=new Path2D(`M3.32201 4.84556C3.14417 5.05148 2.85583 5.05148 2.67799 4.84556L0.134292 1.90016C-0.152586 1.56798 0.0505937 1 0.456301 1L5.5437 1C5.94941 1 6.15259 1.56798 5.86571 1.90016L3.32201 4.84556Z`);let Pe=class{constructor(e,t,n,r){this._commandService=e,this._univerInstanceService=t,this._renderManagerService=n,this._dataValidationModel=r,O(this,`zIndex`,void 0),O(this,`_dropdownInfoMap`,new Map)}_ensureMap(e){let t=this._dropdownInfoMap.get(e);return t||(t=new Map,this._dropdownInfoMap.set(e,t)),t}_generateKey(e,t){return`${e}.${t}`}_drawDownIcon(e,t,n,r,i){let a=n-14+4,o=4;switch(i){case c.VerticalAlign.MIDDLE:o=(r-14)/2+4;break;case c.VerticalAlign.BOTTOM:o=r-14+4;break;default:break}e.save(),e.translateWithPrecision(t.startX+a,t.startY+o),e.fillStyle=`#565656`,e.fill(Ne),e.restore()}drawWith(e,t,n,r){var i,a;let{primaryWithCoord:o,row:s,col:u,style:f,data:p,subUnitId:m}=t,h=o.isMergedMainCell?o.mergeInfo:o,{leftOffset:g=0,rightOffset:_=0,topOffset:v=0,downOffset:y=0}=(p==null?void 0:p.fontRenderExtension)||{},b=this._ensureMap(m),x=this._generateKey(s,u),S=o.isMergedMainCell?o.mergeInfo.startRow:s,C=o.isMergedMainCell?o.mergeInfo.startColumn:u,w=this._dataValidationModel.getRuleByLocation(t.unitId,t.subUnitId,S,C);if(!w)return;let T=this._dataValidationModel.getValidator(w.type);if(!T)return;let E={startX:h.startX+g,endX:h.endX-_,startY:h.startY+v,endY:h.endY-y},D=E.endX-E.startX,O=E.endY-E.startY,{cl:k}=f||{},A=(i=typeof k==`object`?k==null?void 0:k.rgb:k)==null?`#000`:i,j=(0,l.getFontStyleString)(f==null?void 0:f),{vt:M,ht:N}=f||{},P=M==null?c.VerticalAlign.MIDDLE:M,F=(a=(0,d.getCellValueOrigin)(p))==null?``:a,I=T.parseCellValue(F),L=T.getListWithColorMap(w),R=je(I,j,D,O);this._drawDownIcon(e,E,D,O,P),e.save(),e.translateWithPrecision(E.startX,E.startY),e.beginPath(),e.rect(0,0,D-14,O),e.clip(),e.translateWithPrecision(6,6);let z=0;switch(P){case c.VerticalAlign.MIDDLE:z=(R.contentHeight-R.totalHeight)/2;break;case c.VerticalAlign.BOTTOM:z=R.contentHeight-R.totalHeight;break;default:break}e.translateWithPrecision(0,z),R.lines.forEach((t,n)=>{e.save();let{width:r,height:i,items:a}=t,o=0;switch(N){case c.HorizontalAlign.RIGHT:o=R.contentWidth-r;break;case c.HorizontalAlign.CENTER:o=(R.contentWidth-r)/2;break;default:break}e.translate(o,n*(i+4)),a.forEach(t=>{e.save(),e.translateWithPrecision(t.left,0),Me.drawWith(e,{...j,info:t,color:A,fill:L[t.text]}),e.restore()}),e.restore()}),e.restore(),b.set(x,{left:E.startX,top:E.startY,width:R.contentWidth+6+14,height:R.contentHeight+12})}calcCellAutoHeight(e){var t;let{primaryWithCoord:n,style:r,data:i,row:a,col:o}=e,{leftOffset:s=0,rightOffset:c=0,topOffset:u=0,downOffset:f=0}=(i==null?void 0:i.fontRenderExtension)||{},p=n.isMergedMainCell?n.mergeInfo:n,m={startX:p.startX+s,endX:p.endX-c,startY:p.startY+u,endY:p.endY-f},h=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,o);if(!h)return;let g=this._dataValidationModel.getValidator(h.type);if(!g)return;let _=m.endX-m.startX,v=m.endY-m.startY,y=(t=(0,d.getCellValueOrigin)(i))==null?``:t;return je(g.parseCellValue(y),(0,l.getFontStyleString)(r==null?void 0:r),_,v).cellAutoHeight}calcCellAutoWidth(e){var t;let{primaryWithCoord:n,style:r,data:i,row:a,col:o}=e,{leftOffset:s=0,rightOffset:c=0,topOffset:u=0,downOffset:f=0}=(i==null?void 0:i.fontRenderExtension)||{},p=n.isMergedMainCell?n.mergeInfo:n,m={startX:p.startX+s,endX:p.endX-c,startY:p.startY+u,endY:p.endY-f},h=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,o);if(!h)return;let g=this._dataValidationModel.getValidator(h.type);if(!g)return;let _=m.endX-m.startX,v=m.endY-m.startY,y=(t=(0,d.getCellValueOrigin)(i))==null?``:t;return je(g.parseCellValue(y),(0,l.getFontStyleString)(r==null?void 0:r),_,v).calcAutoWidth}isHit(e,t){let{primaryWithCoord:n}=t,{endX:r}=n.isMergedMainCell?n.mergeInfo:n,{x:i}=e;return i>=r-14&&i<=r}onPointerDown(e,t){if(t.button===2)return;let{unitId:n,subUnitId:r,row:i,col:a}=e,o={unitId:n,subUnitId:r,row:i,column:a};this._commandService.executeCommand(H.id,o)}onPointerEnter(e,t){var n;return(n=(0,l.getCurrentTypeOfRenderer)(c.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null||(n=n.mainComponent)==null?void 0:n.setCursor(l.CURSOR_TYPE.POINTER)}onPointerLeave(e,t){var n;return(n=(0,l.getCurrentTypeOfRenderer)(c.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null||(n=n.mainComponent)==null?void 0:n.setCursor(l.CURSOR_TYPE.DEFAULT)}};Pe=A([k(0,c.ICommandService),k(1,c.IUniverInstanceService),k(2,(0,c.Inject)(l.IRenderManagerService)),k(3,(0,c.Inject)(d.SheetDataValidationModel))],Pe);var Fe=class extends Q{constructor(...e){super(...e),O(this,`id`,c.DataValidationType.LIST_MULTIPLE),O(this,`canvasRender`,this.injector.createInstance(Pe)),O(this,`dropdownType`,f.DataValidatorDropdownType.MULTIPLE_LIST)}};const Ie=new Path2D(`M3.32201 4.84556C3.14417 5.05148 2.85583 5.05148 2.67799 4.84556L0.134292 1.90016C-0.152586 1.56798 0.0505937 1 0.456301 1L5.5437 1C5.94941 1 6.15259 1.56798 5.86571 1.90016L3.32201 4.84556Z`);function Le(e,t,n,r,i,a,o=!0){let s=0,l=o?3:0;switch(i){case c.VerticalAlign.BOTTOM:s=t-r-l;break;case c.VerticalAlign.MIDDLE:s=(t-r)/2;break;default:s=l;break}s=Math.max(3,s);let u=0;switch(a){case c.HorizontalAlign.CENTER:u=(e-n)/2;break;case c.HorizontalAlign.RIGHT:u=e-n;break;default:break}return u=Math.max(6,u),{paddingLeft:u,paddingTop:s}}let Re=class{constructor(e,t,n,r,i){this._univerInstanceService=e,this._localeService=t,this._commandService=n,this._renderManagerService=r,this._dataValidationModel=i,O(this,`_dropdownInfoMap`,new Map),O(this,`zIndex`,void 0)}_ensureMap(e){let t=this._dropdownInfoMap.get(e);return t||(t=new Map,this._dropdownInfoMap.set(e,t)),t}_generateKey(e,t){return`${e}.${t}`}_drawDownIcon(e,t,n,r,i,a,o){let{t:s=c.DEFAULT_STYLES.pd.t,b:l=c.DEFAULT_STYLES.pd.b}=o,u=n-14,d;switch(a){case c.VerticalAlign.MIDDLE:d=(r-4)/2;break;case c.VerticalAlign.BOTTOM:d=r-l-i-3+(i/2-4/2);break;default:d=s+3+(i/2-4/2);break}e.save(),e.translateWithPrecision(t.startX+u,t.startY+d),e.fillStyle=`#565656`,e.fill(Ie),e.restore()}drawWith(e,t,n){var r,i,a,o;let{primaryWithCoord:s,row:u,col:f,style:p,data:m,subUnitId:h}=t,g=s.isMergedMainCell?s.mergeInfo:s,_=s.isMergedMainCell?s.mergeInfo.startRow:u,v=s.isMergedMainCell?s.mergeInfo.startColumn:f,y=this._dataValidationModel.getRuleByLocation(t.unitId,t.subUnitId,_,v);if(!y)return;let b=this._dataValidationModel.getValidator(y.type);if(!b)return;let{leftOffset:x=0,rightOffset:S=0,topOffset:C=0,downOffset:w=0}=(m==null?void 0:m.fontRenderExtension)||{};if(!y||!b||!b||b.id.indexOf(c.DataValidationType.LIST)!==0||!b.skipDefaultFontRender(y))return;let T={startX:g.startX+x,endX:g.endX-S,startY:g.startY+C,endY:g.endY-w},E=T.endX-T.startX,D=T.endY-T.startY,O=this._ensureMap(h),k=this._generateKey(u,f),A=b.getListWithColorMap(y),j=(0,d.getCellValueOrigin)(m),M=`${j==null?``:j}`,N=A[M],{tb:P,vt:F,ht:I,pd:L}=p||{};P=(r=P)==null?c.WrapStrategy.WRAP:r,F=(i=F)==null?c.VerticalAlign.BOTTOM:i,I=(a=I)==null?c.DEFAULT_STYLES.ht:a,L=(o=L)==null?c.DEFAULT_STYLES.pd:o;let R=(0,l.getFontStyleString)(p).fontCache;if(y.renderMode===c.DataValidationRenderMode.ARROW){var z,B,V;let{l:t=c.DEFAULT_STYLES.pd.l,t:r=c.DEFAULT_STYLES.pd.t,r:i=c.DEFAULT_STYLES.pd.r,b:a=c.DEFAULT_STYLES.pd.b}=L,o=E-t-i-14-4,s=new l.DocSimpleSkeleton(M,R,P===c.WrapStrategy.WRAP,o,1/0);s.calculate();let u=s.getTotalWidth(),d=s.getTotalHeight(),{paddingTop:f,paddingLeft:m}=Le(o,D-r-a,u,d,F,I,!0);this._drawDownIcon(e,T,E,D,d,F,L),e.save(),e.translateWithPrecision(T.startX+t,T.startY+r),e.beginPath(),e.rect(0,0,E-t-i,D-r-a),e.clip(),e.translateWithPrecision(0,f),e.save(),e.translateWithPrecision(m,0),e.beginPath(),e.rect(0,0,o,d),e.clip(),l.Text.drawWith(e,{text:M,fontStyle:R,width:o,height:d,color:p==null||(z=p.cl)==null?void 0:z.rgb,strokeLine:!!(!(p==null||(B=p.st)==null)&&B.s),underline:!!(!(p==null||(V=p.ul)==null)&&V.s),warp:P===c.WrapStrategy.WRAP,hAlign:c.HorizontalAlign.LEFT},s),e.restore(),e.restore(),O.set(k,{left:T.endX-14+n.rowHeaderWidth,top:T.startY+r+n.columnHeaderHeight,width:14,height:D-r-a})}else{var H,U,W;e.save(),e.translateWithPrecision(T.startX,T.startY),e.beginPath(),e.rect(0,0,E,D),e.clip();let t=E-12-4-14-4,r=new l.DocSimpleSkeleton(M,R,P===c.WrapStrategy.WRAP,t,1/0);r.calculate();let i=r.getTotalWidth(),a=r.getTotalHeight(),o=a+2,s=Math.max(E-12,1),{paddingTop:u}=Le(s,D,i,o,F,I);e.translateWithPrecision(6,u),l.Rect.drawWith(e,{width:s,height:o,fill:N||`#ECECEC`,radius:8}),e.save(),e.translateWithPrecision(4,1),e.beginPath(),e.rect(0,0,t,a),e.clip(),l.Text.drawWith(e,{text:M,fontStyle:R,width:t,height:a,color:p==null||(H=p.cl)==null?void 0:H.rgb,strokeLine:!!(!(p==null||(U=p.st)==null)&&U.s),underline:!!(!(p==null||(W=p.ul)==null)&&W.s),warp:P===c.WrapStrategy.WRAP,hAlign:c.HorizontalAlign.LEFT},r),e.restore(),e.translateWithPrecision(t+4+4,(a-4)/2),e.fillStyle=`#565656`,e.fill(Ie),e.restore(),O.set(k,{left:T.startX+6+n.rowHeaderWidth,top:T.startY+u+n.columnHeaderHeight,width:s,height:o})}}calcCellAutoHeight(e){var t;let{primaryWithCoord:n,style:r,data:i,row:a,col:o}=e,s=n.isMergedMainCell?n.mergeInfo:n,{leftOffset:u=0,rightOffset:f=0,topOffset:p=0,downOffset:m=0}=(i==null?void 0:i.fontRenderExtension)||{},h=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,o);if(!h||h.renderMode===c.DataValidationRenderMode.TEXT)return;let g={startX:s.startX+u,endX:s.endX-f,startY:s.startY+p,endY:s.endY-m},_=g.endX-g.startX,v=(0,d.getCellValueOrigin)(i),y=`${v==null?``:v}`,{tb:b,pd:x}=r||{},{t:S=c.DEFAULT_STYLES.pd.t,b:C=c.DEFAULT_STYLES.pd.b}=x==null?{}:x;if(b=(t=b)==null?c.WrapStrategy.WRAP:t,h.renderMode===c.DataValidationRenderMode.ARROW){let{l:e=c.DEFAULT_STYLES.pd.l,r:t=c.DEFAULT_STYLES.pd.r}=x==null?{}:x,n=_-e-t-14-4,i=new l.DocSimpleSkeleton(y,(0,l.getFontStyleString)(r).fontCache,b===c.WrapStrategy.WRAP,n,1/0);return i.calculate(),i.getTotalHeight()+S+C+6}else{let e=Math.max(_-12-4-14-4,10),t=new l.DocSimpleSkeleton(y,(0,l.getFontStyleString)(r).fontCache,b===c.WrapStrategy.WRAP,e,1/0);return t.calculate(),t.getTotalHeight()+6+2}}calcCellAutoWidth(e){var t;let{primaryWithCoord:n,style:r,data:i,row:a,col:o}=e,s=n.isMergedMainCell?n.mergeInfo:n,{leftOffset:u=0,rightOffset:f=0,topOffset:p=0,downOffset:m=0}=(i==null?void 0:i.fontRenderExtension)||{},h=this._dataValidationModel.getRuleByLocation(e.unitId,e.subUnitId,a,o);if(!h||h.renderMode===c.DataValidationRenderMode.TEXT)return;let g={startX:s.startX+u,endX:s.endX-f,startY:s.startY+p,endY:s.endY-m},_=g.endX-g.startX,v=(0,d.getCellValueOrigin)(i),y=`${v==null?``:v}`,{tb:b,pd:x}=r||{},{l:S=c.DEFAULT_STYLES.pd.l,r:C=c.DEFAULT_STYLES.pd.r}=x==null?{}:x;b=(t=b)==null?c.WrapStrategy.WRAP:t;let w=26;switch(h.renderMode){case c.DataValidationRenderMode.ARROW:w=18+C+S;break;case c.DataValidationRenderMode.CUSTOM:w=34+C+S+8/2+1;break;default:w=34+C+S+8/2+1}let T=_-w,E=new l.DocSimpleSkeleton(y,(0,l.getFontStyleString)(r).fontCache,b===c.WrapStrategy.WRAP,T,1/0);return E.calculate(),E.getTotalWidth()+w}isHit(e,t){let{subUnitId:n,row:r,col:i}=t,a=this._ensureMap(n).get(this._generateKey(r,i)),o=this._dataValidationModel.getRuleByLocation(t.unitId,t.subUnitId,r,i);if(!o||!a||o.renderMode===c.DataValidationRenderMode.TEXT)return!1;let{top:s,left:l,width:u,height:d}=a,{x:f,y:p}=e;return f>=l&&f<=l+u&&p>=s&&p<=s+d}onPointerDown(e,t){if(t.button===2)return;let{unitId:n,subUnitId:r,row:i,col:a}=e,o={unitId:n,subUnitId:r,row:i,column:a};this._commandService.executeCommand(H.id,o)}onPointerEnter(e,t){var n;(n=(0,l.getCurrentTypeOfRenderer)(c.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null||(n=n.mainComponent)==null||n.setCursor(l.CURSOR_TYPE.POINTER)}onPointerLeave(e,t){var n;(n=(0,l.getCurrentTypeOfRenderer)(c.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null||(n=n.mainComponent)==null||n.setCursor(l.CURSOR_TYPE.DEFAULT)}};Re=A([k(0,c.IUniverInstanceService),k(1,(0,c.Inject)(c.LocaleService)),k(2,c.ICommandService),k(3,(0,c.Inject)(l.IRenderManagerService)),k(4,(0,c.Inject)(d.SheetDataValidationModel))],Re);var ze=class extends Q{constructor(...e){super(...e),O(this,`id`,c.DataValidationType.LIST),O(this,`canvasRender`,this.injector.createInstance(Re)),O(this,`dropdownType`,f.DataValidatorDropdownType.LIST),O(this,`optionsInput`,Ce.componentKey),O(this,`formulaInput`,d.LIST_FORMULA_INPUT_NAME)}},Be=class extends Q{constructor(...e){super(...e),O(this,`id`,c.DataValidationType.TEXT_LENGTH),O(this,`formulaInput`,d.BASE_FORMULA_INPUT_NAME)}},Ve=class extends Q{constructor(...e){super(...e),O(this,`id`,c.DataValidationType.WHOLE),O(this,`formulaInput`,d.BASE_FORMULA_INPUT_NAME)}};let He=class extends c.RxDisposable{constructor(e,t,n){super(),this._injector=e,this._componentManger=t,this._dataValidatorRegistryService=n,this._initComponents(),this._registerValidatorViews()}_initComponents(){[[`DataValidationIcon`,y.DataValidationIcon],[R,me],[Ce.componentKey,Ce],[we.componentKey,we],...Se].forEach(([e,t])=>{this.disposeWithMe(this._componentManger.register(e,t))})}_registerValidatorViews(){[ke,Ve,Be,Oe,Ee,ze,Fe,De].forEach(e=>{let t=this._injector.createInstance(e),n=this._dataValidatorRegistryService.getValidatorItem(t.id);n&&(n.formulaInput=t.formulaInput,n.canvasRender=t.canvasRender,n.dropdownType=t.dropdownType,n.optionsInput=t.optionsInput)})}};He=A([k(0,(0,c.Inject)(c.Injector)),k(1,(0,c.Inject)(p.ComponentManager)),k(2,(0,c.Inject)(f.DataValidatorRegistryService))],He);let $=class extends c.Plugin{constructor(e=N,t,n,r){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r;let{menu:i,...a}=(0,c.merge)({},N,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(M,a)}onStarting(){[[j],[L],[K],[q],[Z],[Y],[J],[He]].forEach(e=>{this._injector.add(e)}),[W,H,U,B,z,V].forEach(e=>{this._commandService.registerCommand(e)})}onReady(){this._injector.get(J),this._injector.get(Y),this._injector.get(l.IRenderManagerService).registerRenderModule(c.UniverInstanceType.UNIVER_SHEET,[se])}onRendered(){this._injector.get(He),this._injector.get(Z)}onSteady(){this._injector.get(q)}};O($,`pluginName`,`SHEET_DATA_VALIDATION_UI_PLUGIN`),O($,`packageName`,C),O($,`version`,w),O($,`type`,c.UniverInstanceType.UNIVER_SHEET),$=A([k(1,(0,c.Inject)(c.Injector)),k(2,c.ICommandService),k(3,c.IConfigService)],$);let Ue=class extends c.Plugin{constructor(e=N,t,n,r){super(),this._config=e,this._injector=t,this._commandService=n,this._configService=r;let{menu:i,...a}=(0,c.merge)({},N,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(M,a)}onStarting(){[[j],[L],[K],[q],[Z],[Y],[J],[P],[He]].forEach(e=>{this._injector.add(e)}),[W,H,U,B,z,V].forEach(e=>{this._commandService.registerCommand(e)})}onReady(){this._injector.get(J),this._injector.get(Y),this._injector.get(P),this._injector.get(K),this._injector.get(l.IRenderManagerService).registerRenderModule(c.UniverInstanceType.UNIVER_SHEET,[se])}onRendered(){this._injector.get(He),this._injector.get(Z)}onSteady(){this._injector.get(q)}};O(Ue,`pluginName`,`SHEET_DATA_VALIDATION_UI_PLUGIN`),O(Ue,`packageName`,C),O(Ue,`version`,w),O(Ue,`type`,c.UniverInstanceType.UNIVER_SHEET),Ue=A([(0,c.DependentOn)(d.UniverSheetsDataValidationPlugin),k(1,(0,c.Inject)(c.Injector)),k(2,c.ICommandService),k(3,c.IConfigService)],Ue),Object.defineProperty(exports,`BaseSheetDataValidatorView`,{enumerable:!0,get:function(){return Q}}),Object.defineProperty(exports,`UniverSheetsDataValidationMobileUIPlugin`,{enumerable:!0,get:function(){return $}}),Object.defineProperty(exports,`UniverSheetsDataValidationUIPlugin`,{enumerable:!0,get:function(){return Ue}});