@univerjs/sheets-data-validation-ui 0.20.1 → 0.21.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.
Files changed (41) hide show
  1. package/lib/cjs/index.js +3763 -1
  2. package/lib/cjs/locale/ca-ES.js +174 -1
  3. package/lib/cjs/locale/en-US.js +189 -1
  4. package/lib/cjs/locale/es-ES.js +174 -1
  5. package/lib/cjs/locale/fa-IR.js +174 -1
  6. package/lib/cjs/locale/fr-FR.js +174 -1
  7. package/lib/cjs/locale/ja-JP.js +174 -1
  8. package/lib/cjs/locale/ko-KR.js +174 -1
  9. package/lib/cjs/locale/ru-RU.js +174 -1
  10. package/lib/cjs/locale/sk-SK.js +174 -1
  11. package/lib/cjs/locale/vi-VN.js +174 -1
  12. package/lib/cjs/locale/zh-CN.js +174 -1
  13. package/lib/cjs/locale/zh-TW.js +174 -1
  14. package/lib/es/index.js +3717 -1
  15. package/lib/es/locale/ca-ES.js +173 -1
  16. package/lib/es/locale/en-US.js +188 -1
  17. package/lib/es/locale/es-ES.js +173 -1
  18. package/lib/es/locale/fa-IR.js +173 -1
  19. package/lib/es/locale/fr-FR.js +173 -1
  20. package/lib/es/locale/ja-JP.js +173 -1
  21. package/lib/es/locale/ko-KR.js +173 -1
  22. package/lib/es/locale/ru-RU.js +173 -1
  23. package/lib/es/locale/sk-SK.js +173 -1
  24. package/lib/es/locale/vi-VN.js +173 -1
  25. package/lib/es/locale/zh-CN.js +173 -1
  26. package/lib/es/locale/zh-TW.js +173 -1
  27. package/lib/index.js +3717 -1
  28. package/lib/locale/ca-ES.js +173 -1
  29. package/lib/locale/en-US.js +188 -1
  30. package/lib/locale/es-ES.js +173 -1
  31. package/lib/locale/fa-IR.js +173 -1
  32. package/lib/locale/fr-FR.js +173 -1
  33. package/lib/locale/ja-JP.js +173 -1
  34. package/lib/locale/ko-KR.js +173 -1
  35. package/lib/locale/ru-RU.js +173 -1
  36. package/lib/locale/sk-SK.js +173 -1
  37. package/lib/locale/vi-VN.js +173 -1
  38. package/lib/locale/zh-CN.js +173 -1
  39. package/lib/locale/zh-TW.js +173 -1
  40. package/lib/umd/index.js +1 -1
  41. package/package.json +15 -15
package/lib/cjs/index.js CHANGED
@@ -1 +1,3763 @@
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.20.1`;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.dateKit)();if(typeof e==`number`||!Number.isNaN(+e))return(0,c.dateKit)(c.numfmt.format(`yyyy-MM-dd HH:mm:ss`,Number(e)));let t=(0,c.dateKit)(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}});
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
+ key = keys[i];
13
+ if (!__hasOwnProp.call(to, key) && key !== except) {
14
+ __defProp(to, key, {
15
+ get: ((k) => from[k]).bind(null, key),
16
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
+ });
18
+ }
19
+ }
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
26
+ }) : target, mod));
27
+
28
+ //#endregion
29
+ let _univerjs_core = require("@univerjs/core");
30
+ let _univerjs_engine_render = require("@univerjs/engine-render");
31
+ let _univerjs_sheets = require("@univerjs/sheets");
32
+ let _univerjs_sheets_data_validation = require("@univerjs/sheets-data-validation");
33
+ let _univerjs_data_validation = require("@univerjs/data-validation");
34
+ let _univerjs_ui = require("@univerjs/ui");
35
+ let rxjs = require("rxjs");
36
+ let _univerjs_sheets_numfmt = require("@univerjs/sheets-numfmt");
37
+ let _univerjs_sheets_ui = require("@univerjs/sheets-ui");
38
+ let _univerjs_design = require("@univerjs/design");
39
+ let react = require("react");
40
+ react = __toESM(react);
41
+ let _univerjs_icons = require("@univerjs/icons");
42
+ let _univerjs_engine_formula = require("@univerjs/engine-formula");
43
+ let _univerjs_sheets_formula_ui = require("@univerjs/sheets-formula-ui");
44
+ let react_jsx_runtime = require("react/jsx-runtime");
45
+
46
+ //#region package.json
47
+ var name = "@univerjs/sheets-data-validation-ui";
48
+ var version = "0.21.0";
49
+
50
+ //#endregion
51
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
52
+ function _typeof(o) {
53
+ "@babel/helpers - typeof";
54
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
55
+ return typeof o;
56
+ } : function(o) {
57
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
58
+ }, _typeof(o);
59
+ }
60
+
61
+ //#endregion
62
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
63
+ function toPrimitive(t, r) {
64
+ if ("object" != _typeof(t) || !t) return t;
65
+ var e = t[Symbol.toPrimitive];
66
+ if (void 0 !== e) {
67
+ var i = e.call(t, r || "default");
68
+ if ("object" != _typeof(i)) return i;
69
+ throw new TypeError("@@toPrimitive must return a primitive value.");
70
+ }
71
+ return ("string" === r ? String : Number)(t);
72
+ }
73
+
74
+ //#endregion
75
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
76
+ function toPropertyKey(t) {
77
+ var i = toPrimitive(t, "string");
78
+ return "symbol" == _typeof(i) ? i : i + "";
79
+ }
80
+
81
+ //#endregion
82
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
83
+ function _defineProperty(e, r, t) {
84
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
85
+ value: t,
86
+ enumerable: !0,
87
+ configurable: !0,
88
+ writable: !0
89
+ }) : e[r] = t, e;
90
+ }
91
+
92
+ //#endregion
93
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
94
+ function __decorateParam(paramIndex, decorator) {
95
+ return function(target, key) {
96
+ decorator(target, key, paramIndex);
97
+ };
98
+ }
99
+
100
+ //#endregion
101
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
102
+ function __decorate(decorators, target, key, desc) {
103
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
104
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
105
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
106
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
107
+ }
108
+
109
+ //#endregion
110
+ //#region src/services/data-validation-panel.service.ts
111
+ let DataValidationPanelService = class DataValidationPanelService extends _univerjs_core.Disposable {
112
+ get activeRule() {
113
+ return this._activeRule;
114
+ }
115
+ get isOpen() {
116
+ return this._open$.getValue();
117
+ }
118
+ constructor(_univerInstanceService, _sidebarService) {
119
+ super();
120
+ this._univerInstanceService = _univerInstanceService;
121
+ this._sidebarService = _sidebarService;
122
+ _defineProperty(this, "_open$", new rxjs.BehaviorSubject(false));
123
+ _defineProperty(this, "open$", this._open$.pipe((0, rxjs.distinctUntilChanged)()));
124
+ _defineProperty(this, "_activeRule", void 0);
125
+ _defineProperty(this, "_activeRule$", new rxjs.BehaviorSubject(void 0));
126
+ _defineProperty(this, "activeRule$", this._activeRule$.asObservable());
127
+ _defineProperty(this, "_closeDisposable", null);
128
+ _defineProperty(this, "_focusFormulaEditorActiveRuleSubUnitId", null);
129
+ this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs.filter)((sheet) => !sheet)).subscribe(() => {
130
+ this.close();
131
+ }));
132
+ this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe((info) => {
133
+ if (info.id === "DataValidationPanel") {
134
+ if (!info.visible) setTimeout(() => {
135
+ this._sidebarService.sidebarOptions$.next({ visible: false });
136
+ });
137
+ }
138
+ }));
139
+ }
140
+ dispose() {
141
+ var _this$_closeDisposabl;
142
+ super.dispose();
143
+ this._open$.next(false);
144
+ this._open$.complete();
145
+ this._activeRule$.complete();
146
+ (_this$_closeDisposabl = this._closeDisposable) === null || _this$_closeDisposabl === void 0 || _this$_closeDisposabl.dispose();
147
+ }
148
+ open() {
149
+ this._open$.next(true);
150
+ }
151
+ close() {
152
+ var _this$_closeDisposabl2;
153
+ this._open$.next(false);
154
+ (_this$_closeDisposabl2 = this._closeDisposable) === null || _this$_closeDisposabl2 === void 0 || _this$_closeDisposabl2.dispose();
155
+ }
156
+ setCloseDisposable(disposable) {
157
+ this._closeDisposable = (0, _univerjs_core.toDisposable)(() => {
158
+ disposable.dispose();
159
+ this._closeDisposable = null;
160
+ });
161
+ }
162
+ setActiveRule(rule) {
163
+ this._activeRule = rule;
164
+ this._activeRule$.next(rule);
165
+ }
166
+ setFocusFormulaEditorActiveRuleSubUnitId(subUnitId) {
167
+ this._focusFormulaEditorActiveRuleSubUnitId = subUnitId;
168
+ }
169
+ getFocusFormulaEditorActiveRuleSubUnitId() {
170
+ return this._focusFormulaEditorActiveRuleSubUnitId;
171
+ }
172
+ };
173
+ DataValidationPanelService = __decorate([__decorateParam(0, _univerjs_core.IUniverInstanceService), __decorateParam(1, _univerjs_ui.ISidebarService)], DataValidationPanelService);
174
+
175
+ //#endregion
176
+ //#region src/config/config.ts
177
+ const SHEETS_DATA_VALIDATION_UI_PLUGIN_CONFIG_KEY = "sheets-data-validation-ui.config";
178
+ const configSymbol = Symbol(SHEETS_DATA_VALIDATION_UI_PLUGIN_CONFIG_KEY);
179
+ const defaultPluginConfig = {};
180
+
181
+ //#endregion
182
+ //#region src/const.ts
183
+ /**
184
+ * Copyright 2023-present DreamNum Co., Ltd.
185
+ *
186
+ * Licensed under the Apache License, Version 2.0 (the "License");
187
+ * you may not use this file except in compliance with the License.
188
+ * You may obtain a copy of the License at
189
+ *
190
+ * http://www.apache.org/licenses/LICENSE-2.0
191
+ *
192
+ * Unless required by applicable law or agreed to in writing, software
193
+ * distributed under the License is distributed on an "AS IS" BASIS,
194
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
195
+ * See the License for the specific language governing permissions and
196
+ * limitations under the License.
197
+ */
198
+ const DROP_DOWN_DEFAULT_COLOR = "#ECECEC";
199
+
200
+ //#endregion
201
+ //#region src/controllers/dv-reject-input.controller.ts
202
+ /**
203
+ * Copyright 2023-present DreamNum Co., Ltd.
204
+ *
205
+ * Licensed under the Apache License, Version 2.0 (the "License");
206
+ * you may not use this file except in compliance with the License.
207
+ * You may obtain a copy of the License at
208
+ *
209
+ * http://www.apache.org/licenses/LICENSE-2.0
210
+ *
211
+ * Unless required by applicable law or agreed to in writing, software
212
+ * distributed under the License is distributed on an "AS IS" BASIS,
213
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
214
+ * See the License for the specific language governing permissions and
215
+ * limitations under the License.
216
+ */
217
+ let DataValidationRejectInputController = class DataValidationRejectInputController extends _univerjs_core.Disposable {
218
+ constructor(_sheetInterceptorService, _dataValidationModel, _dataValidatorRegistryService, _dialogService, _localeService, _sheetsDataValidationValidatorService) {
219
+ super();
220
+ this._sheetInterceptorService = _sheetInterceptorService;
221
+ this._dataValidationModel = _dataValidationModel;
222
+ this._dataValidatorRegistryService = _dataValidatorRegistryService;
223
+ this._dialogService = _dialogService;
224
+ this._localeService = _localeService;
225
+ this._sheetsDataValidationValidatorService = _sheetsDataValidationValidatorService;
226
+ this._initEditorBridgeInterceptor();
227
+ }
228
+ _initEditorBridgeInterceptor() {
229
+ this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(_univerjs_sheets.VALIDATE_CELL, { handler: async (lastResult, context, next) => {
230
+ const cell = await lastResult;
231
+ const { row, col, unitId, subUnitId } = context;
232
+ const ruleId = this._dataValidationModel.getRuleIdByLocation(unitId, subUnitId, row, col);
233
+ const rule = ruleId ? this._dataValidationModel.getRuleById(unitId, subUnitId, ruleId) : void 0;
234
+ if (cell === false) return next(Promise.resolve(false));
235
+ if (!rule || rule.errorStyle !== _univerjs_core.DataValidationErrorStyle.STOP) return next(Promise.resolve(true));
236
+ const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type);
237
+ if (!validator) return next(Promise.resolve(true));
238
+ if (await this._sheetsDataValidationValidatorService.validatorCell(unitId, subUnitId, row, col) === _univerjs_core.DataValidationStatus.VALID) return next(Promise.resolve(true));
239
+ this._dialogService.open({
240
+ width: 368,
241
+ title: { title: this._localeService.t("dataValidation.alert.title") },
242
+ id: "reject-input-dialog",
243
+ children: { title: validator.getRuleFinalError(rule, {
244
+ row,
245
+ col,
246
+ unitId,
247
+ subUnitId
248
+ }) },
249
+ footer: { title: (0, react.createElement)(_univerjs_design.Button, {
250
+ variant: "primary",
251
+ onClick: () => this._dialogService.close("reject-input-dialog")
252
+ }, this._localeService.t("dataValidation.alert.ok")) },
253
+ onClose: () => {
254
+ this._dialogService.close("reject-input-dialog");
255
+ }
256
+ });
257
+ return next(Promise.resolve(false));
258
+ } }));
259
+ }
260
+ showReject(title) {
261
+ this._dialogService.open({
262
+ width: 368,
263
+ title: { title: this._localeService.t("dataValidation.alert.title") },
264
+ id: "reject-input-dialog",
265
+ children: { title },
266
+ footer: { title: (0, react.createElement)(_univerjs_design.Button, {
267
+ variant: "primary",
268
+ onClick: () => this._dialogService.close("reject-input-dialog")
269
+ }, this._localeService.t("dataValidation.alert.ok")) },
270
+ onClose: () => {
271
+ this._dialogService.close("reject-input-dialog");
272
+ }
273
+ });
274
+ }
275
+ };
276
+ DataValidationRejectInputController = __decorate([
277
+ __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
278
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel)),
279
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidatorRegistryService)),
280
+ __decorateParam(3, _univerjs_ui.IDialogService),
281
+ __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
282
+ __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetsDataValidationValidatorService))
283
+ ], DataValidationRejectInputController);
284
+
285
+ //#endregion
286
+ //#region src/services/dropdown-manager.service.ts
287
+ const transformDate = (value) => {
288
+ if (value === void 0 || value === null || typeof value === "boolean") return;
289
+ if (value === "") return (0, _univerjs_core.dateKit)();
290
+ if (typeof value === "number" || !Number.isNaN(+value)) return (0, _univerjs_core.dateKit)(_univerjs_core.numfmt.format("yyyy-MM-dd HH:mm:ss", Number(value)));
291
+ const date = (0, _univerjs_core.dateKit)(value);
292
+ if (date.isValid()) return date;
293
+ };
294
+ function getDefaultFormat(patternType, format) {
295
+ if (patternType === (0, _univerjs_sheets_numfmt.getPatternType)(format)) return format;
296
+ switch (patternType) {
297
+ case "datetime": return "yyyy-MM-dd hh:mm:ss";
298
+ case "date": return "yyyy-MM-dd";
299
+ case "time": return "HH:mm:ss";
300
+ }
301
+ }
302
+ let DataValidationDropdownManagerService = class DataValidationDropdownManagerService extends _univerjs_core.Disposable {
303
+ get activeDropdown() {
304
+ return this._activeDropdown;
305
+ }
306
+ constructor(_univerInstanceService, _dataValidatorRegistryService, _zenZoneService, _dataValidationModel, _sheetsSelectionsService, _cellDropdownManagerService, _sheetDataValidationModel, _commandService, _editorBridgeService, _injector, _configService) {
307
+ super();
308
+ this._univerInstanceService = _univerInstanceService;
309
+ this._dataValidatorRegistryService = _dataValidatorRegistryService;
310
+ this._zenZoneService = _zenZoneService;
311
+ this._dataValidationModel = _dataValidationModel;
312
+ this._sheetsSelectionsService = _sheetsSelectionsService;
313
+ this._cellDropdownManagerService = _cellDropdownManagerService;
314
+ this._sheetDataValidationModel = _sheetDataValidationModel;
315
+ this._commandService = _commandService;
316
+ this._editorBridgeService = _editorBridgeService;
317
+ this._injector = _injector;
318
+ this._configService = _configService;
319
+ _defineProperty(this, "_activeDropdown", void 0);
320
+ _defineProperty(this, "_activeDropdown$", new rxjs.Subject());
321
+ _defineProperty(this, "_currentPopup", null);
322
+ _defineProperty(this, "activeDropdown$", this._activeDropdown$.asObservable());
323
+ _defineProperty(this, "_zenVisible", false);
324
+ this._init();
325
+ this._initSelectionChange();
326
+ this.disposeWithMe(() => {
327
+ this._activeDropdown$.complete();
328
+ });
329
+ }
330
+ _init() {
331
+ this.disposeWithMe(this._zenZoneService.visible$.subscribe((visible) => {
332
+ this._zenVisible = visible;
333
+ if (visible) this.hideDropdown();
334
+ }));
335
+ }
336
+ _getDropdownByCell(unitId, subUnitId, row, col) {
337
+ const workbook = unitId ? this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET) : this._univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
338
+ if (!workbook) return;
339
+ const worksheet = subUnitId ? workbook.getSheetBySheetId(subUnitId) : workbook.getActiveSheet();
340
+ if (!worksheet) return;
341
+ const rule = this._dataValidationModel.getRuleByLocation(workbook.getUnitId(), worksheet.getSheetId(), row, col);
342
+ if (!rule) return;
343
+ const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type);
344
+ return validator === null || validator === void 0 ? void 0 : validator.dropdownType;
345
+ }
346
+ _initSelectionChange() {
347
+ this.disposeWithMe(this._sheetsSelectionsService.selectionMoveEnd$.subscribe((selections) => {
348
+ if (selections && selections.every((selection) => !(selection.primary && this._getDropdownByCell(selection.primary.unitId, selection.primary.sheetId, selection.primary.actualRow, selection.primary.actualColumn)))) this.hideDropdown();
349
+ }));
350
+ }
351
+ showDropdown(param) {
352
+ const { location } = param;
353
+ const { row, col, unitId, subUnitId, workbook, worksheet } = location;
354
+ if (this._currentPopup) this._currentPopup.dispose();
355
+ if (this._zenVisible) return;
356
+ this._activeDropdown = param;
357
+ this._activeDropdown$.next(this._activeDropdown);
358
+ const rule = this._sheetDataValidationModel.getRuleByLocation(unitId, subUnitId, row, col);
359
+ if (!rule) return;
360
+ const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type);
361
+ if (!(validator === null || validator === void 0 ? void 0 : validator.dropdownType)) return;
362
+ let popupDisposable;
363
+ const handleSave = async (date, targetPatternType) => {
364
+ var _numfmt$parseDate, _cellStyle$n$pattern, _cellStyle$n;
365
+ if (!date) return true;
366
+ const newValue = date;
367
+ const cellData = worksheet.getCell(row, col);
368
+ const dateStr = newValue.format(targetPatternType === "date" ? "YYYY-MM-DD 00:00:00" : "YYYY-MM-DD HH:mm:ss");
369
+ const serialNum = (_numfmt$parseDate = _univerjs_core.numfmt.parseDate(dateStr)) === null || _numfmt$parseDate === void 0 ? void 0 : _numfmt$parseDate.v;
370
+ const serialTime = targetPatternType === "time" ? serialNum % 1 : serialNum;
371
+ const cellStyle = workbook.getStyles().getStyleByCell(cellData);
372
+ const format = (_cellStyle$n$pattern = cellStyle === null || cellStyle === void 0 || (_cellStyle$n = cellStyle.n) === null || _cellStyle$n === void 0 ? void 0 : _cellStyle$n.pattern) !== null && _cellStyle$n$pattern !== void 0 ? _cellStyle$n$pattern : "";
373
+ if (rule.errorStyle !== _univerjs_core.DataValidationErrorStyle.STOP || await validator.validator({
374
+ value: serialTime,
375
+ unitId,
376
+ subUnitId,
377
+ row,
378
+ column: col,
379
+ worksheet,
380
+ workbook,
381
+ interceptValue: dateStr.replace("Z", "").replace("T", " "),
382
+ t: _univerjs_core.CellValueType.NUMBER
383
+ }, rule)) {
384
+ await this._commandService.executeCommand(_univerjs_sheets.SetRangeValuesCommand.id, {
385
+ unitId,
386
+ subUnitId,
387
+ range: {
388
+ startColumn: col,
389
+ endColumn: col,
390
+ startRow: row,
391
+ endRow: row
392
+ },
393
+ value: {
394
+ v: serialTime,
395
+ t: 2,
396
+ p: null,
397
+ f: null,
398
+ si: null,
399
+ s: { n: { pattern: getDefaultFormat(targetPatternType, format) } }
400
+ }
401
+ });
402
+ await this._commandService.executeCommand(_univerjs_sheets_ui.SetCellEditVisibleOperation.id, {
403
+ visible: false,
404
+ eventType: _univerjs_engine_render.DeviceInputEventType.Keyboard,
405
+ unitId,
406
+ keycode: _univerjs_ui.KeyCode.ESC
407
+ });
408
+ return true;
409
+ } else {
410
+ if (this._injector.has(DataValidationRejectInputController)) this._injector.get(DataValidationRejectInputController).showReject(validator.getRuleFinalError(rule, {
411
+ row,
412
+ col,
413
+ unitId,
414
+ subUnitId
415
+ }));
416
+ return false;
417
+ }
418
+ };
419
+ let dropdownParam;
420
+ switch (validator.dropdownType) {
421
+ case _univerjs_data_validation.DataValidatorDropdownType.DATE: {
422
+ var _rule$bizInfo;
423
+ const originDate = transformDate((0, _univerjs_sheets_data_validation.getCellValueOrigin)(worksheet.getCellRaw(row, col)));
424
+ const showTime = Boolean((_rule$bizInfo = rule.bizInfo) === null || _rule$bizInfo === void 0 ? void 0 : _rule$bizInfo.showTime);
425
+ dropdownParam = {
426
+ location,
427
+ type: "datepicker",
428
+ props: {
429
+ showTime,
430
+ onChange: (newValue) => handleSave(newValue, showTime ? "datetime" : "date"),
431
+ defaultValue: originDate,
432
+ patternType: "date"
433
+ }
434
+ };
435
+ break;
436
+ }
437
+ case _univerjs_data_validation.DataValidatorDropdownType.TIME:
438
+ dropdownParam = {
439
+ location,
440
+ type: "datepicker",
441
+ props: {
442
+ onChange: (newValue) => handleSave(newValue, "time"),
443
+ defaultValue: transformDate((0, _univerjs_sheets_data_validation.getCellValueOrigin)(worksheet.getCellRaw(row, col))),
444
+ patternType: "time"
445
+ }
446
+ };
447
+ break;
448
+ case _univerjs_data_validation.DataValidatorDropdownType.DATETIME:
449
+ dropdownParam = {
450
+ location,
451
+ type: "datepicker",
452
+ props: {
453
+ onChange: (newValue) => handleSave(newValue, "datetime"),
454
+ defaultValue: transformDate((0, _univerjs_sheets_data_validation.getCellValueOrigin)(worksheet.getCellRaw(row, col))),
455
+ patternType: "datetime"
456
+ }
457
+ };
458
+ break;
459
+ case _univerjs_data_validation.DataValidatorDropdownType.LIST:
460
+ case _univerjs_data_validation.DataValidatorDropdownType.MULTIPLE_LIST: {
461
+ var _this$_configService$, _this$_configService$2, _this$_configService$3, _this$_configService$4;
462
+ const multiple = validator.dropdownType === _univerjs_data_validation.DataValidatorDropdownType.MULTIPLE_LIST;
463
+ const handleSave = async (newValue) => {
464
+ const str = (0, _univerjs_sheets_data_validation.serializeListOptions)(newValue);
465
+ const params = {
466
+ unitId,
467
+ subUnitId,
468
+ range: {
469
+ startColumn: col,
470
+ endColumn: col,
471
+ startRow: row,
472
+ endRow: row
473
+ },
474
+ value: {
475
+ v: str,
476
+ p: null,
477
+ f: null,
478
+ si: null
479
+ }
480
+ };
481
+ this._commandService.executeCommand(_univerjs_sheets.SetRangeValuesCommand.id, params);
482
+ if (this._editorBridgeService.isVisible().visible) await this._commandService.executeCommand(_univerjs_sheets_ui.SetCellEditVisibleOperation.id, {
483
+ visible: false,
484
+ eventType: _univerjs_engine_render.DeviceInputEventType.Keyboard,
485
+ unitId,
486
+ keycode: _univerjs_ui.KeyCode.ESC
487
+ });
488
+ if (multiple) return false;
489
+ return true;
490
+ };
491
+ const showColor = (rule === null || rule === void 0 ? void 0 : rule.renderMode) === _univerjs_core.DataValidationRenderMode.CUSTOM || (rule === null || rule === void 0 ? void 0 : rule.renderMode) === void 0;
492
+ const list = validator.getListWithColor(rule, unitId, subUnitId);
493
+ const cellStr = (0, _univerjs_sheets_data_validation.getDataValidationCellValue)(worksheet.getCellRaw(row, col));
494
+ const handleEdit = () => {
495
+ this._commandService.executeCommand(OpenValidationPanelOperation.id, { ruleId: rule.uid });
496
+ popupDisposable === null || popupDisposable === void 0 || popupDisposable.dispose();
497
+ };
498
+ dropdownParam = {
499
+ location,
500
+ type: "list",
501
+ props: {
502
+ onChange: (newValue) => handleSave(newValue),
503
+ options: list.map((item) => ({
504
+ label: item.label,
505
+ value: item.label,
506
+ color: showColor || item.color ? item.color || "#ECECEC" : "transparent"
507
+ })),
508
+ onEdit: handleEdit,
509
+ defaultValue: cellStr,
510
+ multiple,
511
+ showEdit: (_this$_configService$ = (_this$_configService$2 = this._configService.getConfig("sheets-data-validation-ui.config")) === null || _this$_configService$2 === void 0 ? void 0 : _this$_configService$2.showEditOnDropdown) !== null && _this$_configService$ !== void 0 ? _this$_configService$ : true,
512
+ showSearch: (_this$_configService$3 = (_this$_configService$4 = this._configService.getConfig("sheets-data-validation-ui.config")) === null || _this$_configService$4 === void 0 ? void 0 : _this$_configService$4.showSearchOnDropdown) !== null && _this$_configService$3 !== void 0 ? _this$_configService$3 : true
513
+ }
514
+ };
515
+ break;
516
+ }
517
+ case _univerjs_data_validation.DataValidatorDropdownType.CASCADE: {
518
+ var _rule$formula;
519
+ const handleSave = (newValue) => {
520
+ const params = {
521
+ unitId,
522
+ subUnitId,
523
+ range: {
524
+ startColumn: col,
525
+ endColumn: col,
526
+ startRow: row,
527
+ endRow: row
528
+ },
529
+ value: {
530
+ v: newValue.join("/"),
531
+ p: null,
532
+ f: null,
533
+ si: null
534
+ }
535
+ };
536
+ this._commandService.syncExecuteCommand(_univerjs_sheets.SetRangeValuesCommand.id, params);
537
+ if (this._editorBridgeService.isVisible().visible) this._commandService.syncExecuteCommand(_univerjs_sheets_ui.SetCellEditVisibleOperation.id, {
538
+ visible: false,
539
+ eventType: _univerjs_engine_render.DeviceInputEventType.Keyboard,
540
+ unitId,
541
+ keycode: _univerjs_ui.KeyCode.ESC
542
+ });
543
+ return true;
544
+ };
545
+ dropdownParam = {
546
+ type: "cascader",
547
+ props: {
548
+ onChange: handleSave,
549
+ defaultValue: (0, _univerjs_sheets_data_validation.getDataValidationCellValue)(worksheet.getCellRaw(row, col)).split("/"),
550
+ options: JSON.parse((_rule$formula = rule.formula1) !== null && _rule$formula !== void 0 ? _rule$formula : "[]")
551
+ },
552
+ location
553
+ };
554
+ break;
555
+ }
556
+ case _univerjs_data_validation.DataValidatorDropdownType.COLOR: {
557
+ const handleSave = (newValue) => {
558
+ const params = {
559
+ unitId,
560
+ subUnitId,
561
+ range: {
562
+ startColumn: col,
563
+ endColumn: col,
564
+ startRow: row,
565
+ endRow: row
566
+ },
567
+ value: {
568
+ v: newValue,
569
+ p: null,
570
+ f: null,
571
+ si: null
572
+ }
573
+ };
574
+ this._commandService.syncExecuteCommand(_univerjs_sheets.SetRangeValuesCommand.id, params);
575
+ if (this._editorBridgeService.isVisible().visible) this._commandService.syncExecuteCommand(_univerjs_sheets_ui.SetCellEditVisibleOperation.id, {
576
+ visible: false,
577
+ eventType: _univerjs_engine_render.DeviceInputEventType.Keyboard,
578
+ unitId,
579
+ keycode: _univerjs_ui.KeyCode.ESC
580
+ });
581
+ return true;
582
+ };
583
+ dropdownParam = {
584
+ type: "color",
585
+ props: {
586
+ onChange: handleSave,
587
+ defaultValue: (0, _univerjs_sheets_data_validation.getDataValidationCellValue)(worksheet.getCellRaw(row, col))
588
+ },
589
+ location
590
+ };
591
+ break;
592
+ }
593
+ default: throw new Error("[DataValidationDropdownManagerService]: unknown type!");
594
+ }
595
+ popupDisposable = this._cellDropdownManagerService.showDropdown({
596
+ ...dropdownParam,
597
+ onHide: () => {
598
+ this._activeDropdown = null;
599
+ this._activeDropdown$.next(null);
600
+ }
601
+ });
602
+ if (!popupDisposable) throw new Error("[DataValidationDropdownManagerService]: cannot show dropdown!");
603
+ const disposableCollection = new _univerjs_core.DisposableCollection();
604
+ disposableCollection.add(popupDisposable);
605
+ disposableCollection.add({ dispose: () => {
606
+ var _this$_activeDropdown, _this$_activeDropdown2;
607
+ (_this$_activeDropdown = this._activeDropdown) === null || _this$_activeDropdown === void 0 || (_this$_activeDropdown2 = _this$_activeDropdown.onHide) === null || _this$_activeDropdown2 === void 0 || _this$_activeDropdown2.call(_this$_activeDropdown);
608
+ } });
609
+ this._currentPopup = disposableCollection;
610
+ }
611
+ hideDropdown() {
612
+ if (!this._activeDropdown) return;
613
+ this._currentPopup && this._currentPopup.dispose();
614
+ this._currentPopup = null;
615
+ this._activeDropdown = null;
616
+ this._activeDropdown$.next(null);
617
+ }
618
+ showDataValidationDropdown(unitId, subUnitId, row, col, onHide) {
619
+ const workbook = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
620
+ if (!workbook) return;
621
+ const worksheet = workbook.getSheetBySheetId(subUnitId);
622
+ if (!worksheet) return;
623
+ const rule = this._dataValidationModel.getRuleByLocation(workbook.getUnitId(), worksheet.getSheetId(), row, col);
624
+ if (!rule) return;
625
+ const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type);
626
+ if (!validator || !validator.dropdownType) {
627
+ this.hideDropdown();
628
+ return;
629
+ }
630
+ this.showDropdown({
631
+ location: {
632
+ workbook,
633
+ worksheet,
634
+ row,
635
+ col,
636
+ unitId,
637
+ subUnitId
638
+ },
639
+ onHide
640
+ });
641
+ }
642
+ };
643
+ DataValidationDropdownManagerService = __decorate([
644
+ __decorateParam(0, _univerjs_core.IUniverInstanceService),
645
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidatorRegistryService)),
646
+ __decorateParam(2, _univerjs_ui.IZenZoneService),
647
+ __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel)),
648
+ __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetsSelectionsService)),
649
+ __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.ISheetCellDropdownManagerService)),
650
+ __decorateParam(6, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel)),
651
+ __decorateParam(7, _univerjs_core.ICommandService),
652
+ __decorateParam(8, _univerjs_sheets_ui.IEditorBridgeService),
653
+ __decorateParam(9, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
654
+ __decorateParam(10, _univerjs_core.IConfigService)
655
+ ], DataValidationDropdownManagerService);
656
+
657
+ //#endregion
658
+ //#region src/commands/operations/data-validation.operation.ts
659
+ const DATA_VALIDATION_PANEL = "DataValidationPanel";
660
+ const OpenValidationPanelOperation = {
661
+ id: "data-validation.operation.open-validation-panel",
662
+ type: _univerjs_core.CommandType.OPERATION,
663
+ handler(accessor, params) {
664
+ if (!params) return false;
665
+ const { ruleId, isAdd } = params;
666
+ const dataValidationPanelService = accessor.get(DataValidationPanelService);
667
+ const dataValidationModel = accessor.get(_univerjs_data_validation.DataValidationModel);
668
+ const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
669
+ const sidebarService = accessor.get(_univerjs_ui.ISidebarService);
670
+ const target = (0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService);
671
+ if (!target) return false;
672
+ const { unitId, subUnitId } = target;
673
+ const rule = ruleId ? dataValidationModel.getRuleById(unitId, subUnitId, ruleId) : void 0;
674
+ dataValidationPanelService.open();
675
+ dataValidationPanelService.setActiveRule(rule && {
676
+ unitId,
677
+ subUnitId,
678
+ rule
679
+ });
680
+ const disposable = sidebarService.open({
681
+ id: DATA_VALIDATION_PANEL,
682
+ header: { title: isAdd ? "dataValidation.panel.addTitle" : "dataValidation.panel.title" },
683
+ children: { label: DATA_VALIDATION_PANEL },
684
+ width: 312,
685
+ onClose: () => dataValidationPanelService.close()
686
+ });
687
+ dataValidationPanelService.setCloseDisposable(disposable);
688
+ return true;
689
+ }
690
+ };
691
+ const CloseValidationPanelOperation = {
692
+ id: "data-validation.operation.close-validation-panel",
693
+ type: _univerjs_core.CommandType.OPERATION,
694
+ handler(accessor) {
695
+ accessor.get(DataValidationPanelService).close();
696
+ return true;
697
+ }
698
+ };
699
+ const ToggleValidationPanelOperation = {
700
+ id: "data-validation.operation.toggle-validation-panel",
701
+ type: _univerjs_core.CommandType.OPERATION,
702
+ handler(accessor) {
703
+ const commandService = accessor.get(_univerjs_core.ICommandService);
704
+ const dataValidationPanelService = accessor.get(DataValidationPanelService);
705
+ dataValidationPanelService.open();
706
+ if (dataValidationPanelService.isOpen) commandService.executeCommand(CloseValidationPanelOperation.id);
707
+ else commandService.executeCommand(OpenValidationPanelOperation.id);
708
+ return true;
709
+ }
710
+ };
711
+ const ShowDataValidationDropdown = {
712
+ type: _univerjs_core.CommandType.OPERATION,
713
+ id: "sheet.operation.show-data-validation-dropdown",
714
+ handler(accessor, params) {
715
+ if (!params) return false;
716
+ const dataValidationDropdownManagerService = accessor.get(DataValidationDropdownManagerService);
717
+ const { unitId, subUnitId, row, column } = params;
718
+ const activeDropdown = dataValidationDropdownManagerService.activeDropdown;
719
+ const currLoc = activeDropdown === null || activeDropdown === void 0 ? void 0 : activeDropdown.location;
720
+ if (currLoc && currLoc.unitId === unitId && currLoc.subUnitId === subUnitId && currLoc.row === row && currLoc.col === column) return true;
721
+ dataValidationDropdownManagerService.showDataValidationDropdown(unitId, subUnitId, row, column);
722
+ return true;
723
+ }
724
+ };
725
+ const HideDataValidationDropdown = {
726
+ type: _univerjs_core.CommandType.OPERATION,
727
+ id: "sheet.operation.hide-data-validation-dropdown",
728
+ handler(accessor, params) {
729
+ if (!params) return false;
730
+ accessor.get(DataValidationDropdownManagerService).hideDropdown();
731
+ return true;
732
+ }
733
+ };
734
+
735
+ //#endregion
736
+ //#region src/commands/commands/data-validation-ui.command.ts
737
+ const AddSheetDataValidationAndOpenCommand = {
738
+ type: _univerjs_core.CommandType.COMMAND,
739
+ id: "data-validation.command.addRuleAndOpen",
740
+ handler(accessor) {
741
+ const target = (0, _univerjs_sheets.getSheetCommandTarget)(accessor.get(_univerjs_core.IUniverInstanceService));
742
+ if (!target) return false;
743
+ const { workbook, worksheet } = target;
744
+ const rule = (0, _univerjs_sheets_data_validation.createDefaultNewRule)(accessor);
745
+ const commandService = accessor.get(_univerjs_core.ICommandService);
746
+ const addParams = {
747
+ rule,
748
+ unitId: workbook.getUnitId(),
749
+ subUnitId: worksheet.getSheetId()
750
+ };
751
+ if (commandService.syncExecuteCommand(_univerjs_sheets_data_validation.AddSheetDataValidationCommand.id, addParams)) {
752
+ commandService.syncExecuteCommand(OpenValidationPanelOperation.id, {
753
+ ruleId: rule.uid,
754
+ isAdd: true
755
+ });
756
+ return true;
757
+ }
758
+ return false;
759
+ }
760
+ };
761
+
762
+ //#endregion
763
+ //#region src/controllers/dv-alert.controller.ts
764
+ const ALERT_KEY = "SHEET_DATA_VALIDATION_ALERT";
765
+ let DataValidationAlertController = class DataValidationAlertController extends _univerjs_core.Disposable {
766
+ constructor(_hoverManagerService, _cellAlertManagerService, _univerInstanceService, _localeService, _zenZoneService, _dataValidationModel) {
767
+ super();
768
+ this._hoverManagerService = _hoverManagerService;
769
+ this._cellAlertManagerService = _cellAlertManagerService;
770
+ this._univerInstanceService = _univerInstanceService;
771
+ this._localeService = _localeService;
772
+ this._zenZoneService = _zenZoneService;
773
+ this._dataValidationModel = _dataValidationModel;
774
+ this._init();
775
+ }
776
+ _init() {
777
+ this._initCellAlertPopup();
778
+ this._initZenService();
779
+ }
780
+ _initCellAlertPopup() {
781
+ this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0, rxjs.debounceTime)(100)).subscribe((cellPos) => {
782
+ if (cellPos) {
783
+ const workbook = this._univerInstanceService.getUnit(cellPos.location.unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
784
+ const worksheet = workbook.getSheetBySheetId(cellPos.location.subUnitId);
785
+ if (!worksheet) return;
786
+ const rule = this._dataValidationModel.getRuleByLocation(cellPos.location.unitId, cellPos.location.subUnitId, cellPos.location.row, cellPos.location.col);
787
+ if (!rule) {
788
+ this._cellAlertManagerService.removeAlert(ALERT_KEY);
789
+ return;
790
+ }
791
+ if (this._dataValidationModel.validator(rule, {
792
+ ...cellPos.location,
793
+ workbook,
794
+ worksheet
795
+ }) === _univerjs_core.DataValidationStatus.INVALID) {
796
+ var _currentAlert$alert;
797
+ const currentAlert = this._cellAlertManagerService.currentAlert.get(ALERT_KEY);
798
+ const currentLoc = currentAlert === null || currentAlert === void 0 || (_currentAlert$alert = currentAlert.alert) === null || _currentAlert$alert === void 0 ? void 0 : _currentAlert$alert.location;
799
+ if (currentLoc && currentLoc.row === cellPos.location.row && currentLoc.col === cellPos.location.col && currentLoc.subUnitId === cellPos.location.subUnitId && currentLoc.unitId === cellPos.location.unitId) {
800
+ this._cellAlertManagerService.removeAlert(ALERT_KEY);
801
+ return;
802
+ }
803
+ const validator = this._dataValidationModel.getValidator(rule.type);
804
+ if (!validator) {
805
+ this._cellAlertManagerService.removeAlert(ALERT_KEY);
806
+ return;
807
+ }
808
+ this._cellAlertManagerService.showAlert({
809
+ type: _univerjs_sheets_ui.CellAlertType.ERROR,
810
+ title: this._localeService.t("dataValidation.error.title"),
811
+ message: validator === null || validator === void 0 ? void 0 : validator.getRuleFinalError(rule, cellPos.location),
812
+ location: cellPos.location,
813
+ width: 200,
814
+ height: 74,
815
+ key: ALERT_KEY
816
+ });
817
+ return;
818
+ }
819
+ }
820
+ this._cellAlertManagerService.removeAlert(ALERT_KEY);
821
+ }));
822
+ }
823
+ _initZenService() {
824
+ this.disposeWithMe(this._zenZoneService.visible$.subscribe((visible) => {
825
+ if (visible) this._cellAlertManagerService.removeAlert(ALERT_KEY);
826
+ }));
827
+ }
828
+ };
829
+ DataValidationAlertController = __decorate([
830
+ __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.HoverManagerService)),
831
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.CellAlertManagerService)),
832
+ __decorateParam(2, _univerjs_core.IUniverInstanceService),
833
+ __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
834
+ __decorateParam(4, _univerjs_ui.IZenZoneService),
835
+ __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel))
836
+ ], DataValidationAlertController);
837
+
838
+ //#endregion
839
+ //#region src/controllers/dv-auto-fill.controller.ts
840
+ let DataValidationAutoFillController = class DataValidationAutoFillController extends _univerjs_core.Disposable {
841
+ constructor(_autoFillService, _sheetDataValidationModel, _injector) {
842
+ super();
843
+ this._autoFillService = _autoFillService;
844
+ this._sheetDataValidationModel = _sheetDataValidationModel;
845
+ this._injector = _injector;
846
+ this._initAutoFill();
847
+ }
848
+ _initAutoFill() {
849
+ const noopReturnFunc = () => ({
850
+ redos: [],
851
+ undos: []
852
+ });
853
+ const generalApplyFunc = (location, applyType) => {
854
+ const { source: sourceRange, target: targetRange, unitId, subUnitId } = location;
855
+ const ruleMatrixCopy = this._sheetDataValidationModel.getRuleObjectMatrix(unitId, subUnitId).clone();
856
+ const virtualRange = (0, _univerjs_sheets_ui.virtualizeDiscreteRanges)([sourceRange, targetRange]);
857
+ const [vSourceRange, vTargetRange] = virtualRange.ranges;
858
+ const { mapFunc } = virtualRange;
859
+ const sourceStartCell = {
860
+ row: vSourceRange.startRow,
861
+ col: vSourceRange.startColumn
862
+ };
863
+ const repeats = _univerjs_sheets.AutoFillTools.getAutoFillRepeatRange(vSourceRange, vTargetRange);
864
+ const additionMatrix = new _univerjs_core.ObjectMatrix();
865
+ const additionRules = /* @__PURE__ */ new Set();
866
+ repeats.forEach((repeat) => {
867
+ const targetStartCell = repeat.repeatStartCell;
868
+ const relativeRange = repeat.relativeRange;
869
+ const sourceRange = {
870
+ startRow: sourceStartCell.row,
871
+ startColumn: sourceStartCell.col,
872
+ endColumn: sourceStartCell.col,
873
+ endRow: sourceStartCell.row
874
+ };
875
+ const targetRange = {
876
+ startRow: targetStartCell.row,
877
+ startColumn: targetStartCell.col,
878
+ endColumn: targetStartCell.col,
879
+ endRow: targetStartCell.row
880
+ };
881
+ _univerjs_core.Range.foreach(relativeRange, (row, col) => {
882
+ const sourcePositionRange = _univerjs_core.Rectangle.getPositionRange({
883
+ startRow: row,
884
+ startColumn: col,
885
+ endColumn: col,
886
+ endRow: row
887
+ }, sourceRange);
888
+ const { row: sourceRow, col: sourceCol } = mapFunc(sourcePositionRange.startRow, sourcePositionRange.startColumn);
889
+ const ruleId = this._sheetDataValidationModel.getRuleIdByLocation(unitId, subUnitId, sourceRow, sourceCol) || "";
890
+ const targetPositionRange = _univerjs_core.Rectangle.getPositionRange({
891
+ startRow: row,
892
+ startColumn: col,
893
+ endColumn: col,
894
+ endRow: row
895
+ }, targetRange);
896
+ const { row: targetRow, col: targetCol } = mapFunc(targetPositionRange.startRow, targetPositionRange.startColumn);
897
+ additionMatrix.setValue(targetRow, targetCol, ruleId);
898
+ additionRules.add(ruleId);
899
+ });
900
+ });
901
+ const additions = Array.from(additionRules).map((id) => ({
902
+ id,
903
+ ranges: (0, _univerjs_core.queryObjectMatrix)(additionMatrix, (value) => value === id)
904
+ }));
905
+ ruleMatrixCopy.addRangeRules(additions);
906
+ const { redoMutations, undoMutations } = (0, _univerjs_sheets_data_validation.getDataValidationDiffMutations)(unitId, subUnitId, ruleMatrixCopy.diff(this._sheetDataValidationModel.getRules(unitId, subUnitId)), this._injector, "patched", applyType === _univerjs_sheets.AUTO_FILL_APPLY_TYPE.ONLY_FORMAT);
907
+ return {
908
+ undos: undoMutations,
909
+ redos: redoMutations
910
+ };
911
+ };
912
+ const hook = {
913
+ id: _univerjs_sheets_data_validation.DATA_VALIDATION_PLUGIN_NAME,
914
+ onBeforeFillData: (location) => {
915
+ const { source: sourceRange, unitId, subUnitId } = location;
916
+ for (const row of sourceRange.rows) for (const col of sourceRange.cols) {
917
+ const dv = this._sheetDataValidationModel.getRuleByLocation(unitId, subUnitId, row, col);
918
+ if (dv && dv.type === _univerjs_core.DataValidationType.CHECKBOX) {
919
+ this._autoFillService.setDisableApplyType(_univerjs_sheets.AUTO_FILL_APPLY_TYPE.SERIES, true);
920
+ return;
921
+ }
922
+ }
923
+ },
924
+ onFillData: (location, direction, applyType) => {
925
+ if (applyType === _univerjs_sheets.AUTO_FILL_APPLY_TYPE.COPY || applyType === _univerjs_sheets.AUTO_FILL_APPLY_TYPE.ONLY_FORMAT || applyType === _univerjs_sheets.AUTO_FILL_APPLY_TYPE.SERIES) return generalApplyFunc(location, applyType);
926
+ return noopReturnFunc();
927
+ },
928
+ onAfterFillData: () => {}
929
+ };
930
+ this.disposeWithMe(this._autoFillService.addHook(hook));
931
+ }
932
+ };
933
+ DataValidationAutoFillController = __decorate([
934
+ __decorateParam(0, _univerjs_sheets.IAutoFillService),
935
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel)),
936
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_core.Injector))
937
+ ], DataValidationAutoFillController);
938
+
939
+ //#endregion
940
+ //#region src/controllers/dv-copy-paste.controller.ts
941
+ const specialPastes = [
942
+ _univerjs_sheets_ui.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,
943
+ _univerjs_sheets_ui.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,
944
+ _univerjs_sheets_ui.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,
945
+ _univerjs_sheets_ui.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA
946
+ ];
947
+ let DataValidationCopyPasteController = class DataValidationCopyPasteController extends _univerjs_core.Disposable {
948
+ constructor(_sheetClipboardService, _sheetDataValidationModel, _injector, _univerInstanceService) {
949
+ super();
950
+ this._sheetClipboardService = _sheetClipboardService;
951
+ this._sheetDataValidationModel = _sheetDataValidationModel;
952
+ this._injector = _injector;
953
+ this._univerInstanceService = _univerInstanceService;
954
+ _defineProperty(this, "_copyInfo", void 0);
955
+ this._initCopyPaste();
956
+ }
957
+ _initCopyPaste() {
958
+ this._sheetClipboardService.addClipboardHook({
959
+ id: _univerjs_sheets_data_validation.DATA_VALIDATION_PLUGIN_NAME,
960
+ onBeforeCopy: (unitId, subUnitId, range) => this._collect(unitId, subUnitId, range),
961
+ onPasteCells: (pasteFrom, pasteTo, data, payload) => {
962
+ if (!pasteFrom || !this._copyInfo || specialPastes.includes(payload.pasteType)) return {
963
+ redos: [],
964
+ undos: []
965
+ };
966
+ return this._generateMutations(pasteFrom, pasteTo, payload);
967
+ }
968
+ });
969
+ }
970
+ _collect(unitId, subUnitId, range) {
971
+ const matrix = new _univerjs_core.ObjectMatrix();
972
+ this._copyInfo = {
973
+ unitId,
974
+ subUnitId,
975
+ matrix
976
+ };
977
+ const discreteRange = this._injector.invoke((accessor) => {
978
+ return (0, _univerjs_sheets.rangeToDiscreteRange)(range, accessor, unitId, subUnitId);
979
+ });
980
+ if (!discreteRange) return;
981
+ const { rows, cols } = discreteRange;
982
+ rows.forEach((row, rowIndex) => {
983
+ cols.forEach((col, colIndex) => {
984
+ const ruleId = this._sheetDataValidationModel.getRuleIdByLocation(unitId, subUnitId, row, col);
985
+ matrix.setValue(rowIndex, colIndex, ruleId !== null && ruleId !== void 0 ? ruleId : "");
986
+ });
987
+ });
988
+ }
989
+ _generateMutations(pasteFrom, pasteTo, payload) {
990
+ const { unitId: copyUnitId, subUnitId: copySubUnitId, range: copyRange } = pasteFrom;
991
+ const { unitId: pastedUnitId, subUnitId: pastedSubUnitId, range: pastedRange } = pasteTo;
992
+ const { copyType = _univerjs_sheets_ui.COPY_TYPE.COPY } = payload;
993
+ if (!(0, _univerjs_sheets.getSheetCommandTarget)(this._univerInstanceService, {
994
+ unitId: pastedUnitId,
995
+ subUnitId: pastedSubUnitId
996
+ })) return {
997
+ redos: [],
998
+ undos: []
999
+ };
1000
+ if (copyType === _univerjs_sheets_ui.COPY_TYPE.CUT && pastedUnitId === copyUnitId && pastedSubUnitId === copySubUnitId) {
1001
+ this._copyInfo = null;
1002
+ return {
1003
+ redos: [],
1004
+ undos: []
1005
+ };
1006
+ }
1007
+ if (pastedUnitId !== copyUnitId || pastedSubUnitId !== copySubUnitId) {
1008
+ const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(pastedUnitId, pastedSubUnitId).clone();
1009
+ const additionMatrix = new _univerjs_core.ObjectMatrix();
1010
+ const addRules = /* @__PURE__ */ new Set();
1011
+ const { ranges: [vCopyRange, vPastedRange], mapFunc } = (0, _univerjs_sheets_ui.virtualizeDiscreteRanges)([copyRange, pastedRange]);
1012
+ const repeatRange = (0, _univerjs_sheets_ui.getRepeatRange)(vCopyRange, vPastedRange, true);
1013
+ const additionRules = /* @__PURE__ */ new Map();
1014
+ repeatRange.forEach(({ startRange }) => {
1015
+ var _this$_copyInfo;
1016
+ (_this$_copyInfo = this._copyInfo) === null || _this$_copyInfo === void 0 || _this$_copyInfo.matrix.forValue((row, col, ruleId) => {
1017
+ const range = _univerjs_core.Rectangle.getPositionRange({
1018
+ startRow: row,
1019
+ endRow: row,
1020
+ startColumn: col,
1021
+ endColumn: col
1022
+ }, startRange);
1023
+ const transformedRuleId = `${copySubUnitId}-${ruleId}`;
1024
+ const oldRule = this._sheetDataValidationModel.getRuleById(copyUnitId, copySubUnitId, ruleId);
1025
+ if (!this._sheetDataValidationModel.getRuleById(pastedUnitId, pastedSubUnitId, transformedRuleId) && oldRule) additionRules.set(transformedRuleId, {
1026
+ ...oldRule,
1027
+ uid: transformedRuleId
1028
+ });
1029
+ const { row: startRow, col: startColumn } = mapFunc(range.startRow, range.startColumn);
1030
+ addRules.add(transformedRuleId);
1031
+ additionMatrix.setValue(startRow, startColumn, transformedRuleId);
1032
+ });
1033
+ });
1034
+ const additions = Array.from(addRules).map((id) => ({
1035
+ id,
1036
+ ranges: (0, _univerjs_core.queryObjectMatrix)(additionMatrix, (value) => value === id)
1037
+ }));
1038
+ ruleMatrix.addRangeRules(additions);
1039
+ const { redoMutations, undoMutations } = (0, _univerjs_sheets_data_validation.getDataValidationDiffMutations)(pastedUnitId, pastedSubUnitId, ruleMatrix.diffWithAddition(this._sheetDataValidationModel.getRules(pastedUnitId, pastedSubUnitId), additionRules.values()), this._injector, "patched", false);
1040
+ if (copyType === _univerjs_sheets_ui.COPY_TYPE.CUT) {
1041
+ const copySheetRuleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(copyUnitId, copySubUnitId).clone();
1042
+ const deleteRangeStartCell = mapFunc(vCopyRange.startRow, vCopyRange.startColumn);
1043
+ const deleteRangeEndCell = mapFunc(vCopyRange.endRow, vCopyRange.endColumn);
1044
+ copySheetRuleMatrix.addRangeRules([{
1045
+ id: "",
1046
+ ranges: [{
1047
+ startRow: deleteRangeStartCell.row,
1048
+ endRow: deleteRangeEndCell.row,
1049
+ startColumn: deleteRangeStartCell.col,
1050
+ endColumn: deleteRangeEndCell.col
1051
+ }]
1052
+ }]);
1053
+ const { redoMutations: cutRedos, undoMutations: cutUndos } = (0, _univerjs_sheets_data_validation.getDataValidationDiffMutations)(copyUnitId, copySubUnitId, copySheetRuleMatrix.diff(this._sheetDataValidationModel.getRules(copyUnitId, copySubUnitId)), this._injector, "patched", false);
1054
+ redoMutations.push(...cutRedos);
1055
+ undoMutations.push(...cutUndos);
1056
+ }
1057
+ return {
1058
+ redos: redoMutations,
1059
+ undos: undoMutations
1060
+ };
1061
+ } else {
1062
+ const ruleMatrix = this._sheetDataValidationModel.getRuleObjectMatrix(copyUnitId, copySubUnitId).clone();
1063
+ const additionMatrix = new _univerjs_core.ObjectMatrix();
1064
+ const additionRules = /* @__PURE__ */ new Set();
1065
+ const { ranges: [vCopyRange, vPastedRange], mapFunc } = (0, _univerjs_sheets_ui.virtualizeDiscreteRanges)([copyRange, pastedRange]);
1066
+ (0, _univerjs_sheets_ui.getRepeatRange)(vCopyRange, vPastedRange, true).forEach(({ startRange }) => {
1067
+ var _this$_copyInfo2;
1068
+ (_this$_copyInfo2 = this._copyInfo) === null || _this$_copyInfo2 === void 0 || _this$_copyInfo2.matrix.forValue((row, col, ruleId) => {
1069
+ const range = _univerjs_core.Rectangle.getPositionRange({
1070
+ startRow: row,
1071
+ endRow: row,
1072
+ startColumn: col,
1073
+ endColumn: col
1074
+ }, startRange);
1075
+ const { row: startRow, col: startColumn } = mapFunc(range.startRow, range.startColumn);
1076
+ additionMatrix.setValue(startRow, startColumn, ruleId);
1077
+ additionRules.add(ruleId);
1078
+ });
1079
+ });
1080
+ const additions = Array.from(additionRules).map((id) => ({
1081
+ id,
1082
+ ranges: (0, _univerjs_core.queryObjectMatrix)(additionMatrix, (value) => value === id)
1083
+ }));
1084
+ ruleMatrix.addRangeRules(additions);
1085
+ const { redoMutations, undoMutations } = (0, _univerjs_sheets_data_validation.getDataValidationDiffMutations)(pastedUnitId, pastedSubUnitId, ruleMatrix.diff(this._sheetDataValidationModel.getRules(copyUnitId, copySubUnitId)), this._injector, "patched", false);
1086
+ return {
1087
+ redos: redoMutations,
1088
+ undos: undoMutations
1089
+ };
1090
+ }
1091
+ }
1092
+ };
1093
+ DataValidationCopyPasteController = __decorate([
1094
+ __decorateParam(0, _univerjs_sheets_ui.ISheetClipboardService),
1095
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel)),
1096
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
1097
+ __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_core.IUniverInstanceService))
1098
+ ], DataValidationCopyPasteController);
1099
+
1100
+ //#endregion
1101
+ //#region src/controllers/dv-permission.controller.ts
1102
+ let DataValidationPermissionController = class DataValidationPermissionController extends _univerjs_core.Disposable {
1103
+ constructor(_localeService, _commandService, _sheetPermissionCheckController) {
1104
+ super();
1105
+ this._localeService = _localeService;
1106
+ this._commandService = _commandService;
1107
+ this._sheetPermissionCheckController = _sheetPermissionCheckController;
1108
+ this._commandExecutedListener();
1109
+ }
1110
+ _commandExecutedListener() {
1111
+ this.disposeWithMe(this._commandService.beforeCommandExecuted((command) => {
1112
+ if (command.id === _univerjs_sheets_data_validation.AddSheetDataValidationCommand.id) {
1113
+ const { unitId, subUnitId, rule: { ranges } } = command.params;
1114
+ if (!this._sheetPermissionCheckController.permissionCheckWithRanges({
1115
+ workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
1116
+ rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint],
1117
+ worksheetTypes: [_univerjs_sheets.WorksheetEditPermission, _univerjs_sheets.WorksheetSetCellStylePermission]
1118
+ }, ranges, unitId, subUnitId)) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.setStyleErr"));
1119
+ }
1120
+ if (command.id === _univerjs_sheets_data_validation.UpdateSheetDataValidationRangeCommand.id) {
1121
+ const { unitId, subUnitId, ranges } = command.params;
1122
+ if (!this._sheetPermissionCheckController.permissionCheckWithRanges({
1123
+ workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
1124
+ rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint],
1125
+ worksheetTypes: [_univerjs_sheets.WorksheetEditPermission, _univerjs_sheets.WorksheetSetCellStylePermission]
1126
+ }, ranges, unitId, subUnitId)) this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.setStyleErr"));
1127
+ }
1128
+ }));
1129
+ }
1130
+ };
1131
+ DataValidationPermissionController = __decorate([
1132
+ __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
1133
+ __decorateParam(1, _univerjs_core.ICommandService),
1134
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetPermissionCheckController))
1135
+ ], DataValidationPermissionController);
1136
+
1137
+ //#endregion
1138
+ //#region src/menu/dv.menu.ts
1139
+ const DATA_VALIDATION_MENU_ID = "sheet.menu.data-validation";
1140
+ function dataValidationMenuFactory(accessor) {
1141
+ return {
1142
+ id: DATA_VALIDATION_MENU_ID,
1143
+ type: _univerjs_ui.MenuItemType.SUBITEMS,
1144
+ icon: "DataValidationIcon",
1145
+ tooltip: "dataValidation.title",
1146
+ hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET),
1147
+ disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
1148
+ workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
1149
+ worksheetTypes: [_univerjs_sheets.WorksheetSetCellStylePermission, _univerjs_sheets.WorksheetEditPermission],
1150
+ rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint]
1151
+ })
1152
+ };
1153
+ }
1154
+ function openDataValidationMenuFactory(_accessor) {
1155
+ return {
1156
+ id: OpenValidationPanelOperation.id,
1157
+ title: "dataValidation.panel.title",
1158
+ type: _univerjs_ui.MenuItemType.BUTTON
1159
+ };
1160
+ }
1161
+ function addDataValidationMenuFactory(_accessor) {
1162
+ return {
1163
+ id: AddSheetDataValidationAndOpenCommand.id,
1164
+ title: "dataValidation.panel.add",
1165
+ type: _univerjs_ui.MenuItemType.BUTTON
1166
+ };
1167
+ }
1168
+
1169
+ //#endregion
1170
+ //#region src/menu/schema.ts
1171
+ const menuSchema = { [_univerjs_ui.RibbonDataGroup.RULES]: { [DATA_VALIDATION_MENU_ID]: {
1172
+ order: 0,
1173
+ menuItemFactory: dataValidationMenuFactory,
1174
+ [OpenValidationPanelOperation.id]: {
1175
+ order: 0,
1176
+ menuItemFactory: openDataValidationMenuFactory
1177
+ },
1178
+ [AddSheetDataValidationAndOpenCommand.id]: {
1179
+ order: 1,
1180
+ menuItemFactory: addDataValidationMenuFactory
1181
+ }
1182
+ } } };
1183
+
1184
+ //#endregion
1185
+ //#region src/controllers/dv-render.controller.ts
1186
+ const INVALID_MARK = { tr: {
1187
+ size: 6,
1188
+ color: "#fe4b4b"
1189
+ } };
1190
+ let SheetsDataValidationRenderController = class SheetsDataValidationRenderController extends _univerjs_core.RxDisposable {
1191
+ constructor(_commandService, _menuManagerService, _renderManagerService, _univerInstanceService, _autoHeightController, _dropdownManagerService, _sheetDataValidationModel, _dataValidatorRegistryService, _sheetInterceptorService, _dataValidationCacheService, _editorBridgeService) {
1192
+ super();
1193
+ this._commandService = _commandService;
1194
+ this._menuManagerService = _menuManagerService;
1195
+ this._renderManagerService = _renderManagerService;
1196
+ this._univerInstanceService = _univerInstanceService;
1197
+ this._autoHeightController = _autoHeightController;
1198
+ this._dropdownManagerService = _dropdownManagerService;
1199
+ this._sheetDataValidationModel = _sheetDataValidationModel;
1200
+ this._dataValidatorRegistryService = _dataValidatorRegistryService;
1201
+ this._sheetInterceptorService = _sheetInterceptorService;
1202
+ this._dataValidationCacheService = _dataValidationCacheService;
1203
+ this._editorBridgeService = _editorBridgeService;
1204
+ this._initMenu();
1205
+ this._initDropdown();
1206
+ this._initViewModelIntercept();
1207
+ this._initAutoHeight();
1208
+ }
1209
+ _initMenu() {
1210
+ this._menuManagerService.mergeMenu(menuSchema);
1211
+ }
1212
+ _initDropdown() {
1213
+ if (!this._editorBridgeService) return;
1214
+ this.disposeWithMe(this._editorBridgeService.visible$.subscribe((visible) => {
1215
+ if (!visible.visible) {
1216
+ var _this$_dropdownManage;
1217
+ if (((_this$_dropdownManage = this._dropdownManagerService.activeDropdown) === null || _this$_dropdownManage === void 0 ? void 0 : _this$_dropdownManage.trigger) === "editor-bridge") this._dropdownManagerService.hideDropdown();
1218
+ return;
1219
+ }
1220
+ const state = this._editorBridgeService.getEditCellState();
1221
+ if (state) {
1222
+ const { unitId, sheetId, row, column } = state;
1223
+ const workbook = this._univerInstanceService.getUniverSheetInstance(unitId);
1224
+ if (!workbook) return;
1225
+ const rule = this._sheetDataValidationModel.getRuleByLocation(unitId, sheetId, row, column);
1226
+ if (!rule) return;
1227
+ const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type);
1228
+ if (!(validator === null || validator === void 0 ? void 0 : validator.dropdownType)) return;
1229
+ const worksheet = workbook.getActiveSheet();
1230
+ if (!worksheet) return;
1231
+ const activeDropdown = this._dropdownManagerService.activeDropdown;
1232
+ const currLoc = activeDropdown === null || activeDropdown === void 0 ? void 0 : activeDropdown.location;
1233
+ if (currLoc && currLoc.unitId === unitId && currLoc.subUnitId === sheetId && currLoc.row === row && currLoc.col === column) return;
1234
+ this._dropdownManagerService.showDropdown({
1235
+ location: {
1236
+ unitId,
1237
+ subUnitId: sheetId,
1238
+ row,
1239
+ col: column,
1240
+ workbook,
1241
+ worksheet
1242
+ },
1243
+ trigger: "editor-bridge",
1244
+ closeOnOutSide: false
1245
+ });
1246
+ }
1247
+ }));
1248
+ }
1249
+ _initViewModelIntercept() {
1250
+ this.disposeWithMe(this._sheetInterceptorService.intercept(_univerjs_sheets.INTERCEPTOR_POINT.CELL_CONTENT, {
1251
+ effect: _univerjs_core.InterceptorEffectEnum.Style,
1252
+ priority: _univerjs_sheets.InterceptCellContentPriority.DATA_VALIDATION,
1253
+ handler: (cell, pos, next) => {
1254
+ var _this$_dataValidation, _cell$customRender, _cell$fontRenderExten, _validator$skipDefaul, _cell$coverable;
1255
+ const { row, col, unitId, subUnitId, workbook, worksheet } = pos;
1256
+ const ruleId = this._sheetDataValidationModel.getRuleIdByLocation(unitId, subUnitId, row, col);
1257
+ if (!ruleId) return next(cell);
1258
+ const rule = this._sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId);
1259
+ if (!rule) return next(cell);
1260
+ const validStatus = (_this$_dataValidation = this._dataValidationCacheService.getValue(unitId, subUnitId, row, col)) !== null && _this$_dataValidation !== void 0 ? _this$_dataValidation : _univerjs_core.DataValidationStatus.VALID;
1261
+ const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type);
1262
+ const cellOrigin = pos.rawData;
1263
+ let cache;
1264
+ const cellValue = { get value() {
1265
+ var _getCellValueOrigin;
1266
+ if (cache !== void 0) return cache;
1267
+ cache = (_getCellValueOrigin = (0, _univerjs_sheets_data_validation.getCellValueOrigin)(cellOrigin)) !== null && _getCellValueOrigin !== void 0 ? _getCellValueOrigin : null;
1268
+ return cache;
1269
+ } };
1270
+ const valueStr = { get value() {
1271
+ var _cellValue$value;
1272
+ return `${(_cellValue$value = cellValue.value) !== null && _cellValue$value !== void 0 ? _cellValue$value : ""}`;
1273
+ } };
1274
+ if (!cell || cell === pos.rawData) cell = { ...pos.rawData };
1275
+ cell.markers = {
1276
+ ...cell === null || cell === void 0 ? void 0 : cell.markers,
1277
+ ...validStatus === _univerjs_core.DataValidationStatus.INVALID ? INVALID_MARK : null
1278
+ };
1279
+ cell.customRender = [...(_cell$customRender = cell === null || cell === void 0 ? void 0 : cell.customRender) !== null && _cell$customRender !== void 0 ? _cell$customRender : [], ...(validator === null || validator === void 0 ? void 0 : validator.canvasRender) ? [validator.canvasRender] : []];
1280
+ cell.fontRenderExtension = {
1281
+ ...cell === null || cell === void 0 ? void 0 : cell.fontRenderExtension,
1282
+ isSkip: (cell === null || cell === void 0 || (_cell$fontRenderExten = cell.fontRenderExtension) === null || _cell$fontRenderExten === void 0 ? void 0 : _cell$fontRenderExten.isSkip) || (validator === null || validator === void 0 || (_validator$skipDefaul = validator.skipDefaultFontRender) === null || _validator$skipDefaul === void 0 ? void 0 : _validator$skipDefaul.call(validator, rule, cellValue.value, pos))
1283
+ };
1284
+ cell.interceptorStyle = {
1285
+ ...cell === null || cell === void 0 ? void 0 : cell.interceptorStyle,
1286
+ ...validator === null || validator === void 0 ? void 0 : validator.getExtraStyle(rule, valueStr.value, { get style() {
1287
+ const styleMap = workbook.getStyles();
1288
+ return (typeof (cell === null || cell === void 0 ? void 0 : cell.s) === "string" ? styleMap.get(cell === null || cell === void 0 ? void 0 : cell.s) : cell === null || cell === void 0 ? void 0 : cell.s) || {};
1289
+ } }, row, col)
1290
+ };
1291
+ cell.interceptorAutoHeight = () => {
1292
+ var _this$_renderManagerS, _mergeCell$startRow, _mergeCell$startColum, _validator$canvasRend, _validator$canvasRend2;
1293
+ const skeleton = (_this$_renderManagerS = this._renderManagerService.getRenderById(unitId)) === null || _this$_renderManagerS === void 0 || (_this$_renderManagerS = _this$_renderManagerS.with(_univerjs_sheets_ui.SheetSkeletonManagerService).getSkeletonParam(subUnitId)) === null || _this$_renderManagerS === void 0 ? void 0 : _this$_renderManagerS.skeleton;
1294
+ if (!skeleton) return;
1295
+ const mergeCell = skeleton.worksheet.getMergedCell(row, col);
1296
+ const info = {
1297
+ data: cell,
1298
+ style: skeleton.getStyles().getStyleByCell(cell),
1299
+ primaryWithCoord: skeleton.getCellWithCoordByIndex((_mergeCell$startRow = mergeCell === null || mergeCell === void 0 ? void 0 : mergeCell.startRow) !== null && _mergeCell$startRow !== void 0 ? _mergeCell$startRow : row, (_mergeCell$startColum = mergeCell === null || mergeCell === void 0 ? void 0 : mergeCell.startColumn) !== null && _mergeCell$startColum !== void 0 ? _mergeCell$startColum : col),
1300
+ unitId,
1301
+ subUnitId,
1302
+ row,
1303
+ col,
1304
+ workbook,
1305
+ worksheet
1306
+ };
1307
+ return validator === null || validator === void 0 || (_validator$canvasRend = validator.canvasRender) === null || _validator$canvasRend === void 0 || (_validator$canvasRend2 = _validator$canvasRend.calcCellAutoHeight) === null || _validator$canvasRend2 === void 0 ? void 0 : _validator$canvasRend2.call(_validator$canvasRend, info);
1308
+ };
1309
+ cell.interceptorAutoWidth = () => {
1310
+ var _this$_renderManagerS2, _mergeCell$startRow2, _mergeCell$startColum2, _validator$canvasRend3, _validator$canvasRend4;
1311
+ const skeleton = (_this$_renderManagerS2 = this._renderManagerService.getRenderById(unitId)) === null || _this$_renderManagerS2 === void 0 || (_this$_renderManagerS2 = _this$_renderManagerS2.with(_univerjs_sheets_ui.SheetSkeletonManagerService).getSkeletonParam(subUnitId)) === null || _this$_renderManagerS2 === void 0 ? void 0 : _this$_renderManagerS2.skeleton;
1312
+ if (!skeleton) return;
1313
+ const mergeCell = skeleton.worksheet.getMergedCell(row, col);
1314
+ const info = {
1315
+ data: cell,
1316
+ style: skeleton.getStyles().getStyleByCell(cell),
1317
+ primaryWithCoord: skeleton.getCellWithCoordByIndex((_mergeCell$startRow2 = mergeCell === null || mergeCell === void 0 ? void 0 : mergeCell.startRow) !== null && _mergeCell$startRow2 !== void 0 ? _mergeCell$startRow2 : row, (_mergeCell$startColum2 = mergeCell === null || mergeCell === void 0 ? void 0 : mergeCell.startColumn) !== null && _mergeCell$startColum2 !== void 0 ? _mergeCell$startColum2 : col),
1318
+ unitId,
1319
+ subUnitId,
1320
+ row,
1321
+ col,
1322
+ workbook,
1323
+ worksheet
1324
+ };
1325
+ return validator === null || validator === void 0 || (_validator$canvasRend3 = validator.canvasRender) === null || _validator$canvasRend3 === void 0 || (_validator$canvasRend4 = _validator$canvasRend3.calcCellAutoWidth) === null || _validator$canvasRend4 === void 0 ? void 0 : _validator$canvasRend4.call(_validator$canvasRend3, info);
1326
+ };
1327
+ cell.coverable = ((_cell$coverable = cell === null || cell === void 0 ? void 0 : cell.coverable) !== null && _cell$coverable !== void 0 ? _cell$coverable : true) && !(rule.type === _univerjs_core.DataValidationType.LIST || rule.type === _univerjs_core.DataValidationType.LIST_MULTIPLE);
1328
+ return next(cell);
1329
+ }
1330
+ }));
1331
+ }
1332
+ _initAutoHeight() {
1333
+ this._sheetDataValidationModel.ruleChange$.pipe((0, rxjs.filter)((change) => change.source === "command"), (0, rxjs.bufferTime)(100)).subscribe((infos) => {
1334
+ if (infos.length === 0) return;
1335
+ const ranges = [];
1336
+ infos.forEach((info) => {
1337
+ if (info.rule.type === _univerjs_core.DataValidationType.LIST_MULTIPLE || info.rule.type === _univerjs_core.DataValidationType.LIST) {
1338
+ var _info$rule;
1339
+ if ((_info$rule = info.rule) === null || _info$rule === void 0 ? void 0 : _info$rule.ranges) ranges.push(...info.rule.ranges);
1340
+ }
1341
+ });
1342
+ if (ranges.length) (0, _univerjs_core.sequenceExecute)(this._autoHeightController.getUndoRedoParamsOfAutoHeight(ranges).redos, this._commandService);
1343
+ });
1344
+ }
1345
+ };
1346
+ SheetsDataValidationRenderController = __decorate([
1347
+ __decorateParam(0, _univerjs_core.ICommandService),
1348
+ __decorateParam(1, _univerjs_ui.IMenuManagerService),
1349
+ __decorateParam(2, _univerjs_engine_render.IRenderManagerService),
1350
+ __decorateParam(3, _univerjs_core.IUniverInstanceService),
1351
+ __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.AutoHeightController)),
1352
+ __decorateParam(5, (0, _univerjs_core.Inject)(DataValidationDropdownManagerService)),
1353
+ __decorateParam(6, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel)),
1354
+ __decorateParam(7, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidatorRegistryService)),
1355
+ __decorateParam(8, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
1356
+ __decorateParam(9, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.DataValidationCacheService)),
1357
+ __decorateParam(10, (0, _univerjs_core.Optional)(_univerjs_sheets_ui.IEditorBridgeService))
1358
+ ], SheetsDataValidationRenderController);
1359
+ let SheetsDataValidationMobileRenderController = class SheetsDataValidationMobileRenderController extends _univerjs_core.RxDisposable {
1360
+ constructor(_commandService, _renderManagerService, _autoHeightController, _dataValidatorRegistryService, _sheetInterceptorService, _sheetDataValidationModel, _dataValidationCacheService) {
1361
+ super();
1362
+ this._commandService = _commandService;
1363
+ this._renderManagerService = _renderManagerService;
1364
+ this._autoHeightController = _autoHeightController;
1365
+ this._dataValidatorRegistryService = _dataValidatorRegistryService;
1366
+ this._sheetInterceptorService = _sheetInterceptorService;
1367
+ this._sheetDataValidationModel = _sheetDataValidationModel;
1368
+ this._dataValidationCacheService = _dataValidationCacheService;
1369
+ this._initViewModelIntercept();
1370
+ this._initAutoHeight();
1371
+ }
1372
+ _initViewModelIntercept() {
1373
+ this.disposeWithMe(this._sheetInterceptorService.intercept(_univerjs_sheets.INTERCEPTOR_POINT.CELL_CONTENT, {
1374
+ effect: _univerjs_core.InterceptorEffectEnum.Style,
1375
+ priority: _univerjs_sheets.InterceptCellContentPriority.DATA_VALIDATION,
1376
+ handler: (cell, pos, next) => {
1377
+ var _this$_dataValidation2, _cell$customRender2, _cell$fontRenderExten2, _validator$skipDefaul2, _cell$coverable2;
1378
+ const { row, col, unitId, subUnitId, workbook, worksheet } = pos;
1379
+ const ruleId = this._sheetDataValidationModel.getRuleIdByLocation(unitId, subUnitId, row, col);
1380
+ if (!ruleId) return next(cell);
1381
+ const rule = this._sheetDataValidationModel.getRuleById(unitId, subUnitId, ruleId);
1382
+ if (!rule) return next(cell);
1383
+ const validStatus = (_this$_dataValidation2 = this._dataValidationCacheService.getValue(unitId, subUnitId, row, col)) !== null && _this$_dataValidation2 !== void 0 ? _this$_dataValidation2 : _univerjs_core.DataValidationStatus.VALID;
1384
+ const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type);
1385
+ const cellValue = (0, _univerjs_sheets_data_validation.getCellValueOrigin)(worksheet.getCellRaw(row, col));
1386
+ const valueStr = `${cellValue !== null && cellValue !== void 0 ? cellValue : ""}`;
1387
+ if (!cell || cell === pos.rawData) cell = { ...pos.rawData };
1388
+ cell.markers = {
1389
+ ...cell === null || cell === void 0 ? void 0 : cell.markers,
1390
+ ...validStatus === _univerjs_core.DataValidationStatus.INVALID ? INVALID_MARK : null
1391
+ };
1392
+ cell.customRender = [...(_cell$customRender2 = cell === null || cell === void 0 ? void 0 : cell.customRender) !== null && _cell$customRender2 !== void 0 ? _cell$customRender2 : [], ...(validator === null || validator === void 0 ? void 0 : validator.canvasRender) ? [validator.canvasRender] : []];
1393
+ cell.fontRenderExtension = {
1394
+ ...cell === null || cell === void 0 ? void 0 : cell.fontRenderExtension,
1395
+ isSkip: (cell === null || cell === void 0 || (_cell$fontRenderExten2 = cell.fontRenderExtension) === null || _cell$fontRenderExten2 === void 0 ? void 0 : _cell$fontRenderExten2.isSkip) || (validator === null || validator === void 0 || (_validator$skipDefaul2 = validator.skipDefaultFontRender) === null || _validator$skipDefaul2 === void 0 ? void 0 : _validator$skipDefaul2.call(validator, rule, cellValue, pos))
1396
+ };
1397
+ cell.interceptorStyle = {
1398
+ ...cell === null || cell === void 0 ? void 0 : cell.interceptorStyle,
1399
+ ...validator === null || validator === void 0 ? void 0 : validator.getExtraStyle(rule, valueStr, { get style() {
1400
+ const styleMap = workbook.getStyles();
1401
+ return (typeof (cell === null || cell === void 0 ? void 0 : cell.s) === "string" ? styleMap.get(cell === null || cell === void 0 ? void 0 : cell.s) : cell === null || cell === void 0 ? void 0 : cell.s) || {};
1402
+ } }, row, col)
1403
+ };
1404
+ cell.interceptorAutoHeight = () => {
1405
+ var _this$_renderManagerS3, _mergeCell$startRow3, _mergeCell$startColum3, _validator$canvasRend5, _validator$canvasRend6;
1406
+ const skeleton = (_this$_renderManagerS3 = this._renderManagerService.getRenderById(unitId)) === null || _this$_renderManagerS3 === void 0 || (_this$_renderManagerS3 = _this$_renderManagerS3.with(_univerjs_sheets_ui.SheetSkeletonManagerService).getSkeletonParam(subUnitId)) === null || _this$_renderManagerS3 === void 0 ? void 0 : _this$_renderManagerS3.skeleton;
1407
+ if (!skeleton) return;
1408
+ const mergeCell = skeleton.worksheet.getMergedCell(row, col);
1409
+ const info = {
1410
+ data: cell,
1411
+ style: skeleton.getStyles().getStyleByCell(cell),
1412
+ primaryWithCoord: skeleton.getCellWithCoordByIndex((_mergeCell$startRow3 = mergeCell === null || mergeCell === void 0 ? void 0 : mergeCell.startRow) !== null && _mergeCell$startRow3 !== void 0 ? _mergeCell$startRow3 : row, (_mergeCell$startColum3 = mergeCell === null || mergeCell === void 0 ? void 0 : mergeCell.startColumn) !== null && _mergeCell$startColum3 !== void 0 ? _mergeCell$startColum3 : col),
1413
+ unitId,
1414
+ subUnitId,
1415
+ row,
1416
+ col,
1417
+ workbook,
1418
+ worksheet
1419
+ };
1420
+ return validator === null || validator === void 0 || (_validator$canvasRend5 = validator.canvasRender) === null || _validator$canvasRend5 === void 0 || (_validator$canvasRend6 = _validator$canvasRend5.calcCellAutoHeight) === null || _validator$canvasRend6 === void 0 ? void 0 : _validator$canvasRend6.call(_validator$canvasRend5, info);
1421
+ };
1422
+ cell.interceptorAutoWidth = () => {
1423
+ var _this$_renderManagerS4, _mergeCell$startRow4, _mergeCell$startColum4, _validator$canvasRend7, _validator$canvasRend8;
1424
+ const skeleton = (_this$_renderManagerS4 = this._renderManagerService.getRenderById(unitId)) === null || _this$_renderManagerS4 === void 0 || (_this$_renderManagerS4 = _this$_renderManagerS4.with(_univerjs_sheets_ui.SheetSkeletonManagerService).getSkeletonParam(subUnitId)) === null || _this$_renderManagerS4 === void 0 ? void 0 : _this$_renderManagerS4.skeleton;
1425
+ if (!skeleton) return;
1426
+ const mergeCell = skeleton.worksheet.getMergedCell(row, col);
1427
+ const info = {
1428
+ data: cell,
1429
+ style: skeleton.getStyles().getStyleByCell(cell),
1430
+ primaryWithCoord: skeleton.getCellWithCoordByIndex((_mergeCell$startRow4 = mergeCell === null || mergeCell === void 0 ? void 0 : mergeCell.startRow) !== null && _mergeCell$startRow4 !== void 0 ? _mergeCell$startRow4 : row, (_mergeCell$startColum4 = mergeCell === null || mergeCell === void 0 ? void 0 : mergeCell.startColumn) !== null && _mergeCell$startColum4 !== void 0 ? _mergeCell$startColum4 : col),
1431
+ unitId,
1432
+ subUnitId,
1433
+ row,
1434
+ col,
1435
+ workbook,
1436
+ worksheet
1437
+ };
1438
+ return validator === null || validator === void 0 || (_validator$canvasRend7 = validator.canvasRender) === null || _validator$canvasRend7 === void 0 || (_validator$canvasRend8 = _validator$canvasRend7.calcCellAutoWidth) === null || _validator$canvasRend8 === void 0 ? void 0 : _validator$canvasRend8.call(_validator$canvasRend7, info);
1439
+ };
1440
+ cell.coverable = ((_cell$coverable2 = cell === null || cell === void 0 ? void 0 : cell.coverable) !== null && _cell$coverable2 !== void 0 ? _cell$coverable2 : true) && !(rule.type === _univerjs_core.DataValidationType.LIST || rule.type === _univerjs_core.DataValidationType.LIST_MULTIPLE);
1441
+ return next(cell);
1442
+ }
1443
+ }));
1444
+ }
1445
+ _initAutoHeight() {
1446
+ this._sheetDataValidationModel.ruleChange$.pipe((0, rxjs.filter)((change) => change.source === "command"), (0, rxjs.bufferTime)(16)).subscribe((infos) => {
1447
+ const ranges = [];
1448
+ infos.forEach((info) => {
1449
+ if (info.rule.type === _univerjs_core.DataValidationType.LIST_MULTIPLE || info.rule.type === _univerjs_core.DataValidationType.LIST) {
1450
+ var _info$rule2;
1451
+ if ((_info$rule2 = info.rule) === null || _info$rule2 === void 0 ? void 0 : _info$rule2.ranges) ranges.push(...info.rule.ranges);
1452
+ }
1453
+ });
1454
+ if (ranges.length) (0, _univerjs_core.sequenceExecute)(this._autoHeightController.getUndoRedoParamsOfAutoHeight(ranges).redos, this._commandService);
1455
+ });
1456
+ }
1457
+ };
1458
+ SheetsDataValidationMobileRenderController = __decorate([
1459
+ __decorateParam(0, _univerjs_core.ICommandService),
1460
+ __decorateParam(1, _univerjs_engine_render.IRenderManagerService),
1461
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.AutoHeightController)),
1462
+ __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidatorRegistryService)),
1463
+ __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
1464
+ __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel)),
1465
+ __decorateParam(6, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.DataValidationCacheService))
1466
+ ], SheetsDataValidationMobileRenderController);
1467
+
1468
+ //#endregion
1469
+ //#region src/controllers/dv-rerender.controller.ts
1470
+ let SheetsDataValidationReRenderController = class SheetsDataValidationReRenderController extends _univerjs_core.Disposable {
1471
+ constructor(_context, _sheetDataValidationModel, _sheetSkeletonManagerService) {
1472
+ super();
1473
+ this._context = _context;
1474
+ this._sheetDataValidationModel = _sheetDataValidationModel;
1475
+ this._sheetSkeletonManagerService = _sheetSkeletonManagerService;
1476
+ this._initSkeletonChange();
1477
+ }
1478
+ _initSkeletonChange() {
1479
+ const reRender = (values) => {
1480
+ var _this$_context$mainCo;
1481
+ if (!values.length) return;
1482
+ const sheetIds = /* @__PURE__ */ new Set();
1483
+ values.forEach((value) => {
1484
+ sheetIds.add(value.subUnitId);
1485
+ });
1486
+ sheetIds.forEach((sheetId) => {
1487
+ var _this$_sheetSkeletonM;
1488
+ (_this$_sheetSkeletonM = this._sheetSkeletonManagerService.getSkeletonParam(sheetId)) === null || _this$_sheetSkeletonM === void 0 || _this$_sheetSkeletonM.skeleton.makeDirty(true);
1489
+ });
1490
+ (_this$_context$mainCo = this._context.mainComponent) === null || _this$_context$mainCo === void 0 || _this$_context$mainCo.makeForceDirty();
1491
+ };
1492
+ this.disposeWithMe(this._sheetDataValidationModel.validStatusChange$.pipe((0, _univerjs_core.bufferDebounceTime)(16)).subscribe(reRender));
1493
+ }
1494
+ };
1495
+ SheetsDataValidationReRenderController = __decorate([__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel)), __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.SheetSkeletonManagerService))], SheetsDataValidationReRenderController);
1496
+
1497
+ //#endregion
1498
+ //#region src/views/components/options/index.tsx
1499
+ function DataValidationOptions(props) {
1500
+ var _value$errorStyle;
1501
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
1502
+ const componentManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.ComponentManager);
1503
+ const { value, onChange, extraComponent } = props;
1504
+ const [show, setShow] = (0, react.useState)(false);
1505
+ const ExtraOptions = extraComponent ? componentManager.get(extraComponent) : null;
1506
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1507
+ className: "univer-mb-3 univer-flex univer-cursor-pointer univer-items-center univer-text-sm univer-text-gray-900 dark:!univer-text-white",
1508
+ onClick: () => setShow(!show),
1509
+ children: [localeService.t("dataValidation.panel.options"), show ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreUpIcon, { className: "univer-ml-1" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, { className: "univer-ml-1" })]
1510
+ }), show && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
1511
+ ExtraOptions ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ExtraOptions, {
1512
+ value,
1513
+ onChange
1514
+ }) : null,
1515
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
1516
+ label: localeService.t("dataValidation.panel.invalid"),
1517
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.RadioGroup, {
1518
+ value: `${(_value$errorStyle = value.errorStyle) !== null && _value$errorStyle !== void 0 ? _value$errorStyle : _univerjs_core.DataValidationErrorStyle.WARNING}`,
1519
+ onChange: (errorStyle) => onChange({
1520
+ ...value,
1521
+ errorStyle: +errorStyle
1522
+ }),
1523
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
1524
+ value: `${_univerjs_core.DataValidationErrorStyle.WARNING}`,
1525
+ children: localeService.t("dataValidation.panel.showWarning")
1526
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
1527
+ value: `${_univerjs_core.DataValidationErrorStyle.STOP}`,
1528
+ children: localeService.t("dataValidation.panel.rejectInput")
1529
+ })]
1530
+ })
1531
+ }),
1532
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
1533
+ label: localeService.t("dataValidation.panel.messageInfo"),
1534
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Checkbox, {
1535
+ checked: value.showErrorMessage,
1536
+ onChange: () => onChange({
1537
+ ...value,
1538
+ showErrorMessage: !value.showErrorMessage
1539
+ }),
1540
+ children: localeService.t("dataValidation.panel.showInfo")
1541
+ })
1542
+ }),
1543
+ value.showErrorMessage ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
1544
+ value: value.error,
1545
+ onChange: (error) => onChange({
1546
+ ...value,
1547
+ error
1548
+ })
1549
+ }) }) : null
1550
+ ] })] });
1551
+ }
1552
+
1553
+ //#endregion
1554
+ //#region src/views/components/detail/index.tsx
1555
+ const debounceExecuteFactory = (commandService) => (0, _univerjs_core.debounce)(async (id, params, options, callback) => {
1556
+ const res = await commandService.executeCommand(id, params, options);
1557
+ callback === null || callback === void 0 || callback(res);
1558
+ }, 1e3);
1559
+ function getSheetIdByName(univerInstanceService, unitId, name) {
1560
+ var _univerInstanceServic2;
1561
+ if (unitId) {
1562
+ var _univerInstanceServic;
1563
+ return ((_univerInstanceServic = univerInstanceService.getUnit(unitId)) === null || _univerInstanceServic === void 0 || (_univerInstanceServic = _univerInstanceServic.getSheetBySheetName(name)) === null || _univerInstanceServic === void 0 ? void 0 : _univerInstanceServic.getSheetId()) || "";
1564
+ }
1565
+ return ((_univerInstanceServic2 = univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET)) === null || _univerInstanceServic2 === void 0 || (_univerInstanceServic2 = _univerInstanceServic2.getSheetBySheetName(name)) === null || _univerInstanceServic2 === void 0 ? void 0 : _univerInstanceServic2.getSheetId()) || "";
1566
+ }
1567
+ function DataValidationDetail() {
1568
+ var _validators$sort, _localRule$allowBlank;
1569
+ const [key, setKey] = (0, react.useState)(0);
1570
+ const dataValidationPanelService = (0, _univerjs_ui.useDependency)(DataValidationPanelService);
1571
+ const { unitId, subUnitId, rule } = (0, _univerjs_ui.useObservable)(dataValidationPanelService.activeRule$, dataValidationPanelService.activeRule) || {};
1572
+ const ruleId = rule.uid;
1573
+ const validatorService = (0, _univerjs_ui.useDependency)(_univerjs_data_validation.DataValidatorRegistryService);
1574
+ const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
1575
+ const componentManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.ComponentManager);
1576
+ const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
1577
+ const dataValidationModel = (0, _univerjs_ui.useDependency)(_univerjs_data_validation.DataValidationModel);
1578
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
1579
+ const workbook = (0, _univerjs_ui.useObservable)(() => univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET), void 0, void 0, []);
1580
+ const worksheet = (0, _univerjs_ui.useObservable)(() => {
1581
+ var _workbook$activeSheet;
1582
+ return (_workbook$activeSheet = workbook === null || workbook === void 0 ? void 0 : workbook.activeSheet$) !== null && _workbook$activeSheet !== void 0 ? _workbook$activeSheet : (0, rxjs.of)(null);
1583
+ }, void 0, void 0, []);
1584
+ const [localRule, setLocalRule] = (0, react.useState)(rule);
1585
+ const validator = validatorService.getValidatorItem(localRule.type);
1586
+ const [showError, setShowError] = (0, react.useState)(false);
1587
+ const validators = validatorService.getValidatorsByScope(_univerjs_data_validation.DataValidatorRegistryScope.SHEET);
1588
+ const [localRanges, setLocalRanges] = (0, react.useState)(() => localRule.ranges.map((i) => ({
1589
+ unitId: "",
1590
+ sheetId: "",
1591
+ range: i
1592
+ })));
1593
+ const debounceExecute = (0, react.useMemo)(() => debounceExecuteFactory(commandService), [commandService]);
1594
+ const [isRangeError, setIsRangeError] = (0, react.useState)(false);
1595
+ const [isFocusRangeSelector, setIsFocusRangeSelector] = (0, react.useState)(false);
1596
+ const rangeSelectorInstance = (0, react.useRef)(null);
1597
+ const sheetSelectionService = (0, _univerjs_ui.useDependency)(_univerjs_sheets.SheetsSelectionsService);
1598
+ (0, react.useEffect)(() => {
1599
+ return () => {
1600
+ const currentSelection = sheetSelectionService.getCurrentLastSelection();
1601
+ if (currentSelection) sheetSelectionService.setSelections([currentSelection]);
1602
+ };
1603
+ }, [sheetSelectionService]);
1604
+ (0, react.useEffect)(() => {
1605
+ commandService.onCommandExecuted((commandInfo) => {
1606
+ if (commandInfo.id === _univerjs_core.UndoCommand.id || commandInfo.id === _univerjs_core.RedoCommand.id) setTimeout(() => {
1607
+ const activeRule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
1608
+ setKey((k) => k + 1);
1609
+ if (activeRule) {
1610
+ setLocalRule(activeRule);
1611
+ setLocalRanges(activeRule.ranges.map((i) => ({
1612
+ unitId: "",
1613
+ sheetId: "",
1614
+ range: i
1615
+ })));
1616
+ }
1617
+ }, 20);
1618
+ });
1619
+ }, [
1620
+ commandService,
1621
+ dataValidationModel,
1622
+ ruleId,
1623
+ subUnitId,
1624
+ unitId
1625
+ ]);
1626
+ if (!validator) return null;
1627
+ const operators = validator.operators;
1628
+ const operatorNames = validator.operatorNames;
1629
+ const isTwoFormula = localRule.operator ? _univerjs_data_validation.TWO_FORMULA_OPERATOR_COUNT.includes(localRule.operator) : false;
1630
+ const goBackActiveRuleSheet = () => {
1631
+ if ((worksheet === null || worksheet === void 0 ? void 0 : worksheet.getSheetId()) !== subUnitId) commandService.syncExecuteCommand(_univerjs_sheets.SetWorksheetActiveOperation.id, {
1632
+ unitId,
1633
+ subUnitId
1634
+ });
1635
+ };
1636
+ const handleOk = () => {
1637
+ var _rangeSelectorInstanc;
1638
+ if ((_rangeSelectorInstanc = rangeSelectorInstance.current) === null || _rangeSelectorInstanc === void 0 || (_rangeSelectorInstanc = _rangeSelectorInstanc.editor) === null || _rangeSelectorInstanc === void 0 ? void 0 : _rangeSelectorInstanc.isFocus()) {
1639
+ var _rangeSelectorInstanc2;
1640
+ handleUpdateRuleRanges((_rangeSelectorInstanc2 = rangeSelectorInstance.current) === null || _rangeSelectorInstanc2 === void 0 ? void 0 : _rangeSelectorInstanc2.getValue());
1641
+ }
1642
+ if (!localRule.ranges.length || isRangeError) return;
1643
+ if (validator.validatorFormula(localRule, unitId, subUnitId).success) dataValidationPanelService.setActiveRule(null);
1644
+ else setShowError(true);
1645
+ goBackActiveRuleSheet();
1646
+ };
1647
+ const handleUpdateRuleRanges = (0, _univerjs_ui.useEvent)((rangeText) => {
1648
+ const unitRanges = rangeText.split(",").filter(Boolean).map(_univerjs_engine_formula.deserializeRangeWithSheet).map((unitRange) => {
1649
+ const sheetName = unitRange.sheetName;
1650
+ if (sheetName) {
1651
+ const sheetId = getSheetIdByName(univerInstanceService, unitRange.unitId, sheetName);
1652
+ return {
1653
+ ...unitRange,
1654
+ sheetId
1655
+ };
1656
+ }
1657
+ return {
1658
+ ...unitRange,
1659
+ sheetId: ""
1660
+ };
1661
+ });
1662
+ if ((0, _univerjs_core.isUnitRangesEqual)(unitRanges, localRanges)) return;
1663
+ setLocalRanges(unitRanges);
1664
+ const ranges = unitRanges.filter((i) => (!i.unitId || i.unitId === unitId) && (!i.sheetId || i.sheetId === subUnitId)).map((i) => i.range);
1665
+ setLocalRule({
1666
+ ...localRule,
1667
+ ranges
1668
+ });
1669
+ if (ranges.length === 0) return;
1670
+ const params = {
1671
+ unitId,
1672
+ subUnitId,
1673
+ ruleId,
1674
+ ranges
1675
+ };
1676
+ debounceExecute(_univerjs_sheets_data_validation.UpdateSheetDataValidationRangeCommand.id, params);
1677
+ });
1678
+ const handleUpdateRuleSetting = (setting) => {
1679
+ if ((0, _univerjs_core.shallowEqual)(setting, (0, _univerjs_data_validation.getRuleSetting)(localRule))) return;
1680
+ setLocalRule({
1681
+ ...localRule,
1682
+ ...setting
1683
+ });
1684
+ const params = {
1685
+ unitId,
1686
+ subUnitId,
1687
+ ruleId,
1688
+ setting
1689
+ };
1690
+ debounceExecute(_univerjs_sheets_data_validation.UpdateSheetDataValidationSettingCommand.id, params, void 0);
1691
+ };
1692
+ const handleDelete = async () => {
1693
+ await commandService.executeCommand(_univerjs_sheets_data_validation.RemoveSheetDataValidationCommand.id, {
1694
+ ruleId,
1695
+ unitId,
1696
+ subUnitId
1697
+ });
1698
+ dataValidationPanelService.setActiveRule(null);
1699
+ goBackActiveRuleSheet();
1700
+ };
1701
+ const baseRule = {
1702
+ type: localRule.type,
1703
+ operator: localRule.operator,
1704
+ formula1: localRule.formula1,
1705
+ formula2: localRule.formula2,
1706
+ allowBlank: localRule.allowBlank
1707
+ };
1708
+ const handleChangeType = (newType) => {
1709
+ const validator = validatorService.getValidatorItem(newType);
1710
+ if (!validator) return;
1711
+ const operators = validator.operators;
1712
+ const rule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
1713
+ const newRule = newType === (rule === null || rule === void 0 ? void 0 : rule.type) || newType.includes("list") && (rule === null || rule === void 0 ? void 0 : rule.type.includes("list")) ? {
1714
+ ...rule,
1715
+ type: newType
1716
+ } : {
1717
+ ...localRule,
1718
+ type: newType,
1719
+ operator: operators[0],
1720
+ formula1: void 0,
1721
+ formula2: void 0
1722
+ };
1723
+ setLocalRule(newRule);
1724
+ commandService.executeCommand(_univerjs_sheets_data_validation.UpdateSheetDataValidationSettingCommand.id, {
1725
+ unitId,
1726
+ subUnitId,
1727
+ ruleId: localRule.uid,
1728
+ setting: (0, _univerjs_data_validation.getRuleSetting)(newRule)
1729
+ });
1730
+ };
1731
+ const FormulaInput = componentManager.get(validator.formulaInput);
1732
+ const rangeStr = (0, react.useMemo)(() => localRanges.map((i) => (0, _univerjs_engine_formula.serializeRange)(i.range)).join(","), []);
1733
+ const options = (0, _univerjs_data_validation.getRuleOptions)(localRule);
1734
+ const handleUpdateRuleOptions = (newOptions) => {
1735
+ if ((0, _univerjs_core.shallowEqual)(newOptions, (0, _univerjs_data_validation.getRuleOptions)(localRule))) return;
1736
+ setLocalRule({
1737
+ ...localRule,
1738
+ ...newOptions
1739
+ });
1740
+ debounceExecute(_univerjs_sheets_data_validation.UpdateSheetDataValidationOptionsCommand.id, {
1741
+ unitId,
1742
+ subUnitId,
1743
+ ruleId,
1744
+ options: newOptions
1745
+ });
1746
+ };
1747
+ const shouldHideFormula = operators.length && !localRule.operator;
1748
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1749
+ "data-u-comp": "data-validation-detail",
1750
+ className: "univer-py-2",
1751
+ children: [
1752
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
1753
+ label: localeService.t("dataValidation.panel.range"),
1754
+ error: !localRule.ranges.length || isRangeError ? localeService.t("dataValidation.panel.rangeError") : "",
1755
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_sheets_formula_ui.RangeSelector, {
1756
+ selectorRef: rangeSelectorInstance,
1757
+ unitId,
1758
+ subUnitId,
1759
+ initialValue: rangeStr,
1760
+ onChange: (doc, str) => {
1761
+ var _rangeSelectorInstanc3;
1762
+ if (!isFocusRangeSelector && ((_rangeSelectorInstanc3 = rangeSelectorInstance.current) === null || _rangeSelectorInstanc3 === void 0 ? void 0 : _rangeSelectorInstanc3.verify())) handleUpdateRuleRanges(str);
1763
+ },
1764
+ onFocusChange: (focusing, str) => {
1765
+ var _rangeSelectorInstanc4;
1766
+ setIsFocusRangeSelector(focusing);
1767
+ if (!focusing && str && ((_rangeSelectorInstanc4 = rangeSelectorInstance.current) === null || _rangeSelectorInstanc4 === void 0 ? void 0 : _rangeSelectorInstanc4.verify())) handleUpdateRuleRanges(str);
1768
+ },
1769
+ onVerify: (isValid) => setIsRangeError(!isValid)
1770
+ })
1771
+ }),
1772
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
1773
+ label: localeService.t("dataValidation.panel.type"),
1774
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Select, {
1775
+ className: "univer-w-full",
1776
+ value: localRule.type,
1777
+ options: validators === null || validators === void 0 || (_validators$sort = validators.sort((a, b) => a.order - b.order)) === null || _validators$sort === void 0 ? void 0 : _validators$sort.map((validator) => ({
1778
+ label: localeService.t(validator.title),
1779
+ value: validator.id
1780
+ })),
1781
+ onChange: handleChangeType
1782
+ })
1783
+ }),
1784
+ (operators === null || operators === void 0 ? void 0 : operators.length) ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
1785
+ label: localeService.t("dataValidation.panel.operator"),
1786
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Select, {
1787
+ className: "univer-w-full",
1788
+ value: `${localRule.operator}`,
1789
+ options: [{
1790
+ value: "",
1791
+ label: localeService.t("dataValidation.operators.legal")
1792
+ }, ...operators.map((op, i) => ({
1793
+ value: `${op}`,
1794
+ label: operatorNames[i]
1795
+ }))],
1796
+ onChange: (operator) => {
1797
+ handleUpdateRuleSetting({
1798
+ ...baseRule,
1799
+ operator
1800
+ });
1801
+ }
1802
+ })
1803
+ }) : null,
1804
+ FormulaInput && !shouldHideFormula ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FormulaInput, {
1805
+ isTwoFormula,
1806
+ value: {
1807
+ formula1: localRule.formula1,
1808
+ formula2: localRule.formula2
1809
+ },
1810
+ onChange: (value) => {
1811
+ handleUpdateRuleSetting({
1812
+ ...baseRule,
1813
+ ...value
1814
+ });
1815
+ },
1816
+ showError,
1817
+ validResult: validator.validatorFormula(localRule, unitId, subUnitId),
1818
+ unitId,
1819
+ subUnitId,
1820
+ ruleId
1821
+ }, key + localRule.type) : null,
1822
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Checkbox, {
1823
+ checked: (_localRule$allowBlank = localRule.allowBlank) !== null && _localRule$allowBlank !== void 0 ? _localRule$allowBlank : true,
1824
+ onChange: () => {
1825
+ var _localRule$allowBlank2;
1826
+ return handleUpdateRuleSetting({
1827
+ ...baseRule,
1828
+ allowBlank: !((_localRule$allowBlank2 = localRule.allowBlank) !== null && _localRule$allowBlank2 !== void 0 ? _localRule$allowBlank2 : true)
1829
+ });
1830
+ },
1831
+ children: localeService.t("dataValidation.panel.allowBlank")
1832
+ }) }),
1833
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataValidationOptions, {
1834
+ value: options,
1835
+ onChange: handleUpdateRuleOptions,
1836
+ extraComponent: validator.optionsInput
1837
+ }),
1838
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1839
+ className: "univer-mt-5 univer-flex univer-flex-row univer-justify-end",
1840
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
1841
+ className: "univer-ml-3",
1842
+ onClick: handleDelete,
1843
+ children: localeService.t("dataValidation.panel.removeRule")
1844
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
1845
+ className: "univer-ml-3",
1846
+ variant: "primary",
1847
+ onClick: handleOk,
1848
+ children: localeService.t("dataValidation.panel.done")
1849
+ })]
1850
+ })
1851
+ ]
1852
+ });
1853
+ }
1854
+
1855
+ //#endregion
1856
+ //#region src/views/components/item/index.tsx
1857
+ const DataValidationItem = (props) => {
1858
+ const { rule, onClick, unitId, subUnitId, disable } = props;
1859
+ const validatorRegistry = (0, _univerjs_ui.useDependency)(_univerjs_data_validation.DataValidatorRegistryService);
1860
+ const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
1861
+ const markSelectionService = (0, _univerjs_ui.useDependency)(_univerjs_sheets_ui.IMarkSelectionService);
1862
+ const validator = validatorRegistry.getValidatorItem(rule.type);
1863
+ const ids = (0, react.useRef)(void 0);
1864
+ const [isHover, setIsHover] = (0, react.useState)(false);
1865
+ const themeService = (0, _univerjs_ui.useDependency)(_univerjs_core.ThemeService);
1866
+ const style = (0, react.useMemo)(() => {
1867
+ var _themeService$getColo;
1868
+ const defaultColor = themeService.getColorFromTheme("primary.600");
1869
+ const key = themeService.getColorFromTheme("loop-color.2");
1870
+ const color = (_themeService$getColo = themeService.getColorFromTheme(key)) !== null && _themeService$getColo !== void 0 ? _themeService$getColo : defaultColor;
1871
+ const rgb = new _univerjs_core.ColorKit(color).toRgb();
1872
+ return {
1873
+ fill: `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, 0.1)`,
1874
+ stroke: color
1875
+ };
1876
+ }, [(0, _univerjs_ui.useObservable)(themeService.currentTheme$)]);
1877
+ const handleDelete = (e) => {
1878
+ commandService.executeCommand(_univerjs_sheets_data_validation.RemoveSheetDataValidationCommand.id, {
1879
+ ruleId: rule.uid,
1880
+ unitId,
1881
+ subUnitId
1882
+ });
1883
+ e.stopPropagation();
1884
+ };
1885
+ (0, react.useEffect)(() => {
1886
+ return () => {
1887
+ if (ids.current) {
1888
+ var _ids$current;
1889
+ (_ids$current = ids.current) === null || _ids$current === void 0 || _ids$current.forEach((id) => {
1890
+ id && markSelectionService.removeShape(id);
1891
+ });
1892
+ }
1893
+ };
1894
+ }, [markSelectionService]);
1895
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1896
+ className: (0, _univerjs_design.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", {
1897
+ "hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-700": !disable,
1898
+ "univer-opacity-50": disable
1899
+ }),
1900
+ onClick,
1901
+ onMouseEnter: () => {
1902
+ if (disable) return;
1903
+ setIsHover(true);
1904
+ ids.current = rule.ranges.map((range) => markSelectionService.addShape({
1905
+ range,
1906
+ style,
1907
+ primary: null
1908
+ }));
1909
+ },
1910
+ onMouseLeave: () => {
1911
+ var _ids$current2;
1912
+ setIsHover(false);
1913
+ (_ids$current2 = ids.current) === null || _ids$current2 === void 0 || _ids$current2.forEach((id) => {
1914
+ id && markSelectionService.removeShape(id);
1915
+ });
1916
+ ids.current = void 0;
1917
+ },
1918
+ children: [
1919
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1920
+ className: "univer-truncate univer-text-sm univer-font-medium univer-leading-[22px] univer-text-gray-900 dark:!univer-text-white",
1921
+ children: validator === null || validator === void 0 ? void 0 : validator.generateRuleName(rule)
1922
+ }),
1923
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1924
+ className: "univer-text-secondary univer-truncate univer-text-xs univer-leading-[18px] dark:!univer-text-gray-300",
1925
+ children: rule.ranges.map((range) => (0, _univerjs_engine_formula.serializeRange)(range)).join(",")
1926
+ }),
1927
+ isHover ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1928
+ 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",
1929
+ onClick: handleDelete,
1930
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DeleteIcon, {})
1931
+ }) : null
1932
+ ]
1933
+ });
1934
+ };
1935
+
1936
+ //#endregion
1937
+ //#region src/views/components/list/index.tsx
1938
+ function DataValidationList(props) {
1939
+ const sheetDataValidationModel = (0, _univerjs_ui.useDependency)(_univerjs_sheets_data_validation.SheetDataValidationModel);
1940
+ const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
1941
+ const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
1942
+ const injector = (0, _univerjs_ui.useDependency)(_univerjs_core.Injector);
1943
+ const dataValidationPanelService = (0, _univerjs_ui.useDependency)(DataValidationPanelService);
1944
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
1945
+ const [rules, setRules] = (0, react.useState)([]);
1946
+ const { workbook } = props;
1947
+ const worksheet = (0, _univerjs_ui.useObservable)(workbook.activeSheet$, void 0, true);
1948
+ const unitId = workbook.getUnitId();
1949
+ const subUnitId = worksheet === null || worksheet === void 0 ? void 0 : worksheet.getSheetId();
1950
+ (0, react.useEffect)(() => {
1951
+ setRules(sheetDataValidationModel.getRules(unitId, subUnitId));
1952
+ const subscription = sheetDataValidationModel.ruleChange$.subscribe((change) => {
1953
+ if (change.unitId === unitId && change.subUnitId === subUnitId) setRules(sheetDataValidationModel.getRules(unitId, subUnitId));
1954
+ });
1955
+ return () => {
1956
+ subscription.unsubscribe();
1957
+ };
1958
+ }, [
1959
+ unitId,
1960
+ subUnitId,
1961
+ sheetDataValidationModel
1962
+ ]);
1963
+ const handleAddRule = async () => {
1964
+ const rule = (0, _univerjs_sheets_data_validation.createDefaultNewRule)(injector);
1965
+ const params = {
1966
+ unitId,
1967
+ subUnitId,
1968
+ rule
1969
+ };
1970
+ await commandService.executeCommand(_univerjs_sheets_data_validation.AddSheetDataValidationCommand.id, params);
1971
+ dataValidationPanelService.setActiveRule({
1972
+ unitId,
1973
+ subUnitId,
1974
+ rule
1975
+ });
1976
+ };
1977
+ const handleRemoveAll = () => {
1978
+ commandService.executeCommand(_univerjs_sheets_data_validation.RemoveSheetAllDataValidationCommand.id, {
1979
+ unitId,
1980
+ subUnitId
1981
+ });
1982
+ };
1983
+ const getDvRulesByPermissionCorrect = (rules) => {
1984
+ const workbook = univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
1985
+ const worksheet = workbook.getActiveSheet();
1986
+ const unitId = workbook.getUnitId();
1987
+ const subUnitId = worksheet.getSheetId();
1988
+ return rules.map((rule) => {
1989
+ if ((0, _univerjs_sheets.checkRangesEditablePermission)(injector, unitId, subUnitId, rule.ranges)) return { ...rule };
1990
+ else return {
1991
+ ...rule,
1992
+ disable: true
1993
+ };
1994
+ });
1995
+ };
1996
+ const rulesByPermissionCheck = getDvRulesByPermissionCorrect(rules);
1997
+ const hasDisableRule = rulesByPermissionCheck === null || rulesByPermissionCheck === void 0 ? void 0 : rulesByPermissionCheck.some((rule) => rule.disable);
1998
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1999
+ className: "univer-pb-4",
2000
+ children: [rulesByPermissionCheck === null || rulesByPermissionCheck === void 0 ? void 0 : rulesByPermissionCheck.map((rule) => {
2001
+ var _rule$disable;
2002
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataValidationItem, {
2003
+ unitId,
2004
+ subUnitId,
2005
+ onClick: () => {
2006
+ if (rule.disable) return;
2007
+ dataValidationPanelService.setActiveRule({
2008
+ unitId,
2009
+ subUnitId,
2010
+ rule
2011
+ });
2012
+ },
2013
+ rule,
2014
+ disable: (_rule$disable = rule.disable) !== null && _rule$disable !== void 0 ? _rule$disable : false
2015
+ }, rule.uid);
2016
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2017
+ className: "univer-mt-4 univer-flex univer-flex-row univer-justify-end univer-gap-2",
2018
+ children: [rules.length && !hasDisableRule ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
2019
+ onClick: handleRemoveAll,
2020
+ children: localeService.t("dataValidation.panel.removeAll")
2021
+ }) : null, /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
2022
+ variant: "primary",
2023
+ onClick: handleAddRule,
2024
+ children: localeService.t("dataValidation.panel.add")
2025
+ })]
2026
+ })]
2027
+ });
2028
+ }
2029
+
2030
+ //#endregion
2031
+ //#region src/views/components/panel/index.tsx
2032
+ const DataValidationPanel = () => {
2033
+ const dataValidationPanelService = (0, _univerjs_ui.useDependency)(DataValidationPanelService);
2034
+ const activeRule = (0, _univerjs_ui.useObservable)(dataValidationPanelService.activeRule$, dataValidationPanelService.activeRule);
2035
+ const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
2036
+ const workbook = (0, _univerjs_ui.useObservable)(() => univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET), void 0, void 0, []);
2037
+ const worksheet = (0, _univerjs_ui.useObservable)(() => {
2038
+ var _workbook$activeSheet;
2039
+ return (_workbook$activeSheet = workbook === null || workbook === void 0 ? void 0 : workbook.activeSheet$) !== null && _workbook$activeSheet !== void 0 ? _workbook$activeSheet : (0, rxjs.of)(null);
2040
+ }, void 0, void 0, []);
2041
+ if (!workbook || !worksheet) return null;
2042
+ return activeRule && (activeRule.subUnitId === worksheet.getSheetId() || activeRule.subUnitId === dataValidationPanelService.getFocusFormulaEditorActiveRuleSubUnitId()) ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataValidationDetail, {}, activeRule.rule.uid) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DataValidationList, { workbook });
2043
+ };
2044
+
2045
+ //#endregion
2046
+ //#region src/views/components/formula-input/BaseFormulaInput.tsx
2047
+ const BaseFormulaInput = (props) => {
2048
+ const { isTwoFormula = false, value, onChange, showError, validResult } = props;
2049
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
2050
+ const formula1Res = showError ? validResult === null || validResult === void 0 ? void 0 : validResult.formula1 : "";
2051
+ const formula2Res = showError ? validResult === null || validResult === void 0 ? void 0 : validResult.formula2 : "";
2052
+ if (isTwoFormula) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
2053
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2054
+ error: formula1Res,
2055
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
2056
+ className: "univer-w-full",
2057
+ placeholder: localeService.t("dataValidation.panel.formulaPlaceholder"),
2058
+ value: value === null || value === void 0 ? void 0 : value.formula1,
2059
+ onChange: (newValue) => {
2060
+ onChange === null || onChange === void 0 || onChange({
2061
+ ...value,
2062
+ formula1: newValue
2063
+ });
2064
+ }
2065
+ })
2066
+ }),
2067
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2068
+ className: "-univer-mt-2 univer-mb-1 univer-text-sm univer-text-gray-400",
2069
+ children: localeService.t("dataValidation.panel.formulaAnd")
2070
+ }),
2071
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2072
+ error: formula2Res,
2073
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
2074
+ className: "univer-w-full",
2075
+ placeholder: localeService.t("dataValidation.panel.formulaPlaceholder"),
2076
+ value: value === null || value === void 0 ? void 0 : value.formula2,
2077
+ onChange: (newValue) => {
2078
+ onChange === null || onChange === void 0 || onChange({
2079
+ ...value,
2080
+ formula2: newValue
2081
+ });
2082
+ }
2083
+ })
2084
+ })
2085
+ ] });
2086
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2087
+ error: formula1Res,
2088
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
2089
+ className: "univer-w-full",
2090
+ placeholder: localeService.t("dataValidation.panel.formulaPlaceholder"),
2091
+ value: value === null || value === void 0 ? void 0 : value.formula1,
2092
+ onChange: (newValue) => {
2093
+ onChange === null || onChange === void 0 || onChange({ formula1: newValue });
2094
+ }
2095
+ })
2096
+ });
2097
+ };
2098
+
2099
+ //#endregion
2100
+ //#region src/views/components/formula-input/CheckboxFormulaInput.tsx
2101
+ function CheckboxFormulaInput(props) {
2102
+ const { value, onChange, showError, validResult } = props;
2103
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
2104
+ const formula1Res = showError ? validResult === null || validResult === void 0 ? void 0 : validResult.formula1 : "";
2105
+ const formula2Res = showError ? validResult === null || validResult === void 0 ? void 0 : validResult.formula2 : "";
2106
+ const [checked, setChecked] = (0, react.useState)(!((value === null || value === void 0 ? void 0 : value.formula1) === void 0 && (value === null || value === void 0 ? void 0 : value.formula2) === void 0));
2107
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
2108
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Checkbox, {
2109
+ checked,
2110
+ onChange: (newValue) => {
2111
+ if (newValue) setChecked(true);
2112
+ else {
2113
+ setChecked(false);
2114
+ onChange === null || onChange === void 0 || onChange({
2115
+ ...value,
2116
+ formula1: void 0,
2117
+ formula2: void 0
2118
+ });
2119
+ }
2120
+ },
2121
+ children: localeService.t("dataValidation.checkbox.tips")
2122
+ }) }),
2123
+ checked ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2124
+ label: localeService.t("dataValidation.checkbox.checked"),
2125
+ error: formula1Res,
2126
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
2127
+ className: "univer-w-full",
2128
+ placeholder: localeService.t("dataValidation.panel.valuePlaceholder"),
2129
+ value: value === null || value === void 0 ? void 0 : value.formula1,
2130
+ onChange: (newValue) => {
2131
+ onChange === null || onChange === void 0 || onChange({
2132
+ ...value,
2133
+ formula1: newValue || void 0
2134
+ });
2135
+ }
2136
+ })
2137
+ }) : null,
2138
+ checked ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2139
+ label: localeService.t("dataValidation.checkbox.unchecked"),
2140
+ error: formula2Res,
2141
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
2142
+ className: "univer-w-full",
2143
+ placeholder: localeService.t("dataValidation.panel.valuePlaceholder"),
2144
+ value: value === null || value === void 0 ? void 0 : value.formula2,
2145
+ onChange: (newValue) => {
2146
+ onChange === null || onChange === void 0 || onChange({
2147
+ ...value,
2148
+ formula2: newValue || void 0
2149
+ });
2150
+ }
2151
+ })
2152
+ }) : null
2153
+ ] });
2154
+ }
2155
+
2156
+ //#endregion
2157
+ //#region src/views/components/formula-input/CustomFormulaInput.tsx
2158
+ function CustomFormulaInput(props) {
2159
+ var _value$formula;
2160
+ const { unitId, subUnitId, value, onChange, showError, validResult } = props;
2161
+ const formula1Res = showError ? validResult === null || validResult === void 0 ? void 0 : validResult.formula1 : void 0;
2162
+ const formulaEditorRef = (0, react.useRef)(null);
2163
+ const [isFocusFormulaEditor, setIsFocusFormulaEditor] = (0, react.useState)(false);
2164
+ (0, _univerjs_ui.useSidebarClick)((e) => {
2165
+ var _formulaEditorRef$cur;
2166
+ !((_formulaEditorRef$cur = formulaEditorRef.current) === null || _formulaEditorRef$cur === void 0) && _formulaEditorRef$cur.isClickOutSide(e) && setIsFocusFormulaEditor(false);
2167
+ });
2168
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2169
+ error: formula1Res,
2170
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_sheets_formula_ui.FormulaEditor, {
2171
+ ref: formulaEditorRef,
2172
+ className: (0, _univerjs_design.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", _univerjs_design.borderClassName),
2173
+ initValue: (_value$formula = value === null || value === void 0 ? void 0 : value.formula1) !== null && _value$formula !== void 0 ? _value$formula : "=",
2174
+ unitId,
2175
+ subUnitId,
2176
+ isFocus: isFocusFormulaEditor,
2177
+ isSupportAcrossSheet: true,
2178
+ onChange: (newValue) => {
2179
+ const newFormula = (newValue !== null && newValue !== void 0 ? newValue : "").trim();
2180
+ if (newFormula === (value === null || value === void 0 ? void 0 : value.formula1)) return;
2181
+ onChange === null || onChange === void 0 || onChange({
2182
+ ...value,
2183
+ formula1: newFormula
2184
+ });
2185
+ },
2186
+ onFocus: () => setIsFocusFormulaEditor(true)
2187
+ })
2188
+ });
2189
+ }
2190
+
2191
+ //#endregion
2192
+ //#region src/views/components/formula-input/ListFormulaInput.tsx
2193
+ const DEFAULT_COLOR_PRESET = [
2194
+ "#FFFFFF",
2195
+ "#FEE7E7",
2196
+ "#FEF0E6",
2197
+ "#EFFBD0",
2198
+ "#E4F4FE",
2199
+ "#E8ECFD",
2200
+ "#F1EAFA",
2201
+ "#FDE8F3",
2202
+ "#E5E5E5",
2203
+ "#FDCECE",
2204
+ "#FDC49B",
2205
+ "#DEF6A2",
2206
+ "#9FDAFF",
2207
+ "#D0D9FB",
2208
+ "#E3D5F6",
2209
+ "#FBD0E8",
2210
+ "#656565",
2211
+ "#FE4B4B",
2212
+ "#FF8C51",
2213
+ "#8BBB11",
2214
+ "#0B9EFB",
2215
+ "#3A60F7",
2216
+ "#9E6DE3",
2217
+ "#F248A6"
2218
+ ];
2219
+ const ColorSelect = (props) => {
2220
+ const { value, onChange, disabled } = props;
2221
+ const [open, setOpen] = (0, react.useState)(false);
2222
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Dropdown, {
2223
+ align: "start",
2224
+ disabled,
2225
+ open,
2226
+ onOpenChange: setOpen,
2227
+ overlay: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2228
+ className: "univer-box-border univer-grid univer-w-fit univer-grid-cols-6 univer-flex-wrap univer-gap-2 univer-p-1.5",
2229
+ children: DEFAULT_COLOR_PRESET.map((color) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2230
+ className: (0, _univerjs_design.clsx)("univer-box-border univer-size-4 univer-cursor-pointer univer-rounded", _univerjs_design.borderClassName),
2231
+ style: { background: color },
2232
+ onClick: () => {
2233
+ onChange(color);
2234
+ setOpen(false);
2235
+ }
2236
+ }, color))
2237
+ }),
2238
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2239
+ className: (0, _univerjs_design.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", _univerjs_design.borderClassName),
2240
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2241
+ className: "univer-box-border univer-size-4 univer-rounded univer-text-base",
2242
+ style: { background: value }
2243
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, {})]
2244
+ })
2245
+ });
2246
+ };
2247
+ const Template = (props) => {
2248
+ const { item, commonProps, className } = props;
2249
+ const { onItemChange, onItemDelete } = commonProps;
2250
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2251
+ className: (0, _univerjs_design.clsx)("univer-flex univer-items-center univer-gap-2", className),
2252
+ children: [
2253
+ !item.isRef && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2254
+ className: (0, _univerjs_design.clsx)("univer-cursor-move", "draggableHandle"),
2255
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.SequenceIcon, {})
2256
+ }),
2257
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ColorSelect, {
2258
+ value: item.color,
2259
+ onChange: (color) => {
2260
+ onItemChange(item.id, item.label, color);
2261
+ }
2262
+ }),
2263
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
2264
+ disabled: item.isRef,
2265
+ value: item.label,
2266
+ onChange: (label) => {
2267
+ onItemChange(item.id, label, item.color);
2268
+ }
2269
+ }),
2270
+ item.isRef ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2271
+ className: "univer-ml-1 univer-cursor-pointer univer-rounded univer-text-base hover:univer-bg-gray-200",
2272
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DeleteIcon, { onClick: () => onItemDelete(item.id) })
2273
+ })
2274
+ ]
2275
+ });
2276
+ };
2277
+ function ListFormulaInput(props) {
2278
+ const { value, onChange: _onChange = () => {}, unitId, subUnitId, validResult, showError, ruleId } = props;
2279
+ const { formula1 = "", formula2 = "" } = value || {};
2280
+ const [isFormulaStr, setIsFormulaStr] = (0, react.useState)(() => (0, _univerjs_core.isFormulaString)(formula1) ? "1" : "0");
2281
+ const [formulaStr, setFormulaStr] = (0, react.useState)(isFormulaStr === "1" ? formula1 : "=");
2282
+ const [formulaStrCopy, setFormulaStrCopy] = (0, react.useState)(isFormulaStr === "1" ? formula1 : "=");
2283
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
2284
+ const dataValidatorRegistryService = (0, _univerjs_ui.useDependency)(_univerjs_data_validation.DataValidatorRegistryService);
2285
+ const dataValidationModel = (0, _univerjs_ui.useDependency)(_univerjs_data_validation.DataValidationModel);
2286
+ const dataValidationFormulaController = (0, _univerjs_ui.useDependency)(_univerjs_sheets_data_validation.DataValidationFormulaController);
2287
+ const dataValidationPanelService = (0, _univerjs_ui.useDependency)(DataValidationPanelService);
2288
+ const [refColors, setRefColors] = (0, react.useState)(() => formula2.split(","));
2289
+ const listValidator = dataValidatorRegistryService.getValidatorItem(_univerjs_core.DataValidationType.LIST);
2290
+ const [refOptions, setRefOptions] = (0, react.useState)([]);
2291
+ const [localError, setLocalError] = (0, react.useState)("");
2292
+ const formula1Res = showError ? validResult === null || validResult === void 0 ? void 0 : validResult.formula1 : "";
2293
+ const ruleChange = (0, _univerjs_ui.useObservable)((0, react.useMemo)(() => dataValidationModel.ruleChange$.pipe((0, rxjs.debounceTime)(16)), []));
2294
+ const onChange = (0, _univerjs_ui.useEvent)(_onChange);
2295
+ (0, react.useEffect)(() => {
2296
+ (async () => {
2297
+ await new Promise((resolve) => {
2298
+ setTimeout(() => resolve(true), 100);
2299
+ });
2300
+ const rule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
2301
+ if ((0, _univerjs_core.isFormulaString)(rule === null || rule === void 0 ? void 0 : rule.formula1) && listValidator && rule) setRefOptions(await listValidator.getListAsync(rule, unitId, subUnitId));
2302
+ })();
2303
+ }, [
2304
+ dataValidationModel,
2305
+ ruleChange,
2306
+ listValidator,
2307
+ ruleId,
2308
+ subUnitId,
2309
+ unitId
2310
+ ]);
2311
+ (0, react.useEffect)(() => {
2312
+ if ((0, _univerjs_core.isFormulaString)(formula1) && formula1 !== formulaStrCopy) {
2313
+ setFormulaStr(formula1);
2314
+ setFormulaStrCopy(formulaStrCopy);
2315
+ }
2316
+ }, [formulaStrCopy, formula1]);
2317
+ const [strList, setStrList] = (0, react.useState)(() => {
2318
+ const strOptions = isFormulaStr !== "1" ? (0, _univerjs_sheets_data_validation.deserializeListOptions)(formula1) : [];
2319
+ const strColors = formula2.split(",");
2320
+ return strOptions.map((label, i) => ({
2321
+ label,
2322
+ color: strColors[i] || "#ECECEC",
2323
+ isRef: false,
2324
+ id: (0, _univerjs_core.generateRandomId)(4)
2325
+ }));
2326
+ });
2327
+ const handleStrItemChange = (id, value, color) => {
2328
+ const item = strList.find((i) => i.id === id);
2329
+ if (!item) return;
2330
+ item.label = value;
2331
+ item.color = color;
2332
+ setStrList([...strList]);
2333
+ };
2334
+ const handleStrItemDelete = (id) => {
2335
+ const index = strList.findIndex((i) => i.id === id);
2336
+ if (index !== -1) {
2337
+ strList.splice(index, 1);
2338
+ setStrList([...strList]);
2339
+ }
2340
+ };
2341
+ const colorList = formula2.split(",");
2342
+ const refFinalList = (0, react.useMemo)(() => refOptions.map((label, i) => ({
2343
+ label,
2344
+ color: colorList[i] || "#ECECEC",
2345
+ id: `${i}`,
2346
+ isRef: true
2347
+ })), [colorList, refOptions]);
2348
+ const handleRefItemChange = (id, value, color) => {
2349
+ const newColors = [...refColors];
2350
+ newColors[+id] = color;
2351
+ setRefColors(newColors);
2352
+ onChange({
2353
+ formula1,
2354
+ formula2: newColors.join(",")
2355
+ });
2356
+ };
2357
+ const handleAdd = () => {
2358
+ setStrList([...strList, {
2359
+ label: "",
2360
+ color: DROP_DOWN_DEFAULT_COLOR,
2361
+ isRef: false,
2362
+ id: (0, _univerjs_core.generateRandomId)(4)
2363
+ }]);
2364
+ };
2365
+ (0, react.useEffect)(() => {
2366
+ if (isFormulaStr === "1") return;
2367
+ const labelSet = /* @__PURE__ */ new Set();
2368
+ const finalList = [];
2369
+ strList.map((item) => {
2370
+ return {
2371
+ labelList: item.label.split(","),
2372
+ item
2373
+ };
2374
+ }).forEach(({ item, labelList }) => {
2375
+ labelList.forEach((labelItem) => {
2376
+ if (!labelSet.has(labelItem)) {
2377
+ labelSet.add(labelItem);
2378
+ finalList.push({
2379
+ label: labelItem,
2380
+ color: item.color
2381
+ });
2382
+ }
2383
+ });
2384
+ });
2385
+ onChange({
2386
+ formula1: (0, _univerjs_sheets_data_validation.serializeListOptions)(finalList.map((item) => item.label)),
2387
+ formula2: finalList.map((item) => item.color === "#ECECEC" ? "" : item.color).join(",")
2388
+ });
2389
+ }, [
2390
+ strList,
2391
+ onChange,
2392
+ isFormulaStr,
2393
+ formulaStrCopy,
2394
+ refColors
2395
+ ]);
2396
+ const updateFormula = (0, _univerjs_ui.useEvent)(async (str) => {
2397
+ if (!(0, _univerjs_core.isFormulaString)(str)) {
2398
+ onChange === null || onChange === void 0 || onChange({
2399
+ formula1: "",
2400
+ formula2
2401
+ });
2402
+ return;
2403
+ }
2404
+ if (dataValidationFormulaController.getFormulaRefCheck(str)) {
2405
+ onChange === null || onChange === void 0 || onChange({
2406
+ formula1: (0, _univerjs_core.isFormulaString)(str) ? str : "",
2407
+ formula2
2408
+ });
2409
+ setLocalError("");
2410
+ } else {
2411
+ onChange === null || onChange === void 0 || onChange({
2412
+ formula1: "",
2413
+ formula2
2414
+ });
2415
+ setFormulaStr("=");
2416
+ setLocalError(localeService.t("dataValidation.validFail.formulaError"));
2417
+ }
2418
+ });
2419
+ const formulaEditorRef = (0, react.useRef)(null);
2420
+ const [isFocusFormulaEditor, setIsFocusFormulaEditor] = (0, react.useState)(false);
2421
+ (0, _univerjs_ui.useSidebarClick)((e) => {
2422
+ var _formulaEditorRef$cur;
2423
+ !((_formulaEditorRef$cur = formulaEditorRef.current) === null || _formulaEditorRef$cur === void 0) && _formulaEditorRef$cur.isClickOutSide(e) && setIsFocusFormulaEditor(false);
2424
+ });
2425
+ (0, react.useEffect)(() => {
2426
+ if (isFocusFormulaEditor) dataValidationPanelService.setFocusFormulaEditorActiveRuleSubUnitId(subUnitId);
2427
+ else dataValidationPanelService.setFocusFormulaEditorActiveRuleSubUnitId(null);
2428
+ }, [
2429
+ isFocusFormulaEditor,
2430
+ subUnitId,
2431
+ dataValidationPanelService
2432
+ ]);
2433
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2434
+ label: localeService.t("dataValidation.list.options"),
2435
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.RadioGroup, {
2436
+ value: isFormulaStr,
2437
+ onChange: (v) => {
2438
+ setIsFormulaStr(v);
2439
+ setFormulaStr(formulaStrCopy);
2440
+ if (v === "1") onChange({
2441
+ formula1: formulaStrCopy === "=" ? "" : formulaStrCopy,
2442
+ formula2: refColors.join(",")
2443
+ });
2444
+ },
2445
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2446
+ value: "0",
2447
+ children: localeService.t("dataValidation.list.customOptions")
2448
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2449
+ value: "1",
2450
+ children: localeService.t("dataValidation.list.refOptions")
2451
+ })]
2452
+ })
2453
+ }), isFormulaStr === "1" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.FormLayout, {
2454
+ error: formula1Res || localError || void 0,
2455
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_sheets_formula_ui.FormulaEditor, {
2456
+ ref: formulaEditorRef,
2457
+ className: (0, _univerjs_design.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", _univerjs_design.borderClassName),
2458
+ initValue: formulaStr,
2459
+ unitId,
2460
+ subUnitId,
2461
+ isFocus: isFocusFormulaEditor,
2462
+ isSupportAcrossSheet: true,
2463
+ onFocus: () => setIsFocusFormulaEditor(true),
2464
+ onChange: (v = "") => {
2465
+ const str = (v !== null && v !== void 0 ? v : "").trim();
2466
+ setFormulaStrCopy(str);
2467
+ updateFormula(str);
2468
+ }
2469
+ }), refFinalList.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
2470
+ className: "univer-mt-3",
2471
+ children: refFinalList.map((item) => {
2472
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Template, {
2473
+ className: "univer-mb-3",
2474
+ item,
2475
+ commonProps: { onItemChange: handleRefItemChange }
2476
+ }, item.id);
2477
+ })
2478
+ })]
2479
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2480
+ error: formula1Res,
2481
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2482
+ className: "-univer-mt-3",
2483
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.DraggableList, {
2484
+ list: strList,
2485
+ onListChange: setStrList,
2486
+ rowHeight: 28,
2487
+ margin: [0, 12],
2488
+ draggableHandle: ".draggableHandle",
2489
+ itemRender: (item) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Template, {
2490
+ item,
2491
+ commonProps: {
2492
+ onItemChange: handleStrItemChange,
2493
+ onItemDelete: handleStrItemDelete
2494
+ }
2495
+ }, item.id),
2496
+ idKey: "id"
2497
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("a", {
2498
+ 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",
2499
+ onClick: handleAdd,
2500
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.IncreaseIcon, { className: "univer-mr-1" }), localeService.t("dataValidation.list.add")]
2501
+ })]
2502
+ })
2503
+ })] });
2504
+ }
2505
+
2506
+ //#endregion
2507
+ //#region src/views/components/formula-input/index.ts
2508
+ const FORMULA_INPUTS = [
2509
+ [_univerjs_sheets_data_validation.CUSTOM_FORMULA_INPUT_NAME, CustomFormulaInput],
2510
+ [_univerjs_sheets_data_validation.BASE_FORMULA_INPUT_NAME, BaseFormulaInput],
2511
+ [_univerjs_sheets_data_validation.LIST_FORMULA_INPUT_NAME, ListFormulaInput],
2512
+ [_univerjs_sheets_data_validation.CHECKBOX_FORMULA_INPUT_NAME, CheckboxFormulaInput]
2513
+ ];
2514
+
2515
+ //#endregion
2516
+ //#region src/views/components/render-mode/index.tsx
2517
+ const LIST_RENDER_MODE_OPTION_INPUT = "LIST_RENDER_MODE_OPTION_INPUT";
2518
+ function ListRenderModeInput(props) {
2519
+ var _value$renderMode;
2520
+ const { value, onChange } = props;
2521
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
2522
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, {
2523
+ label: localeService.t("dataValidation.renderMode.label"),
2524
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.RadioGroup, {
2525
+ value: `${(_value$renderMode = value.renderMode) !== null && _value$renderMode !== void 0 ? _value$renderMode : _univerjs_core.DataValidationRenderMode.CUSTOM}`,
2526
+ onChange: (renderMode) => onChange({
2527
+ ...value,
2528
+ renderMode: +renderMode
2529
+ }),
2530
+ children: [
2531
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2532
+ value: `${_univerjs_core.DataValidationRenderMode.CUSTOM}`,
2533
+ children: localeService.t("dataValidation.renderMode.chip")
2534
+ }),
2535
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2536
+ value: `${_univerjs_core.DataValidationRenderMode.ARROW}`,
2537
+ children: localeService.t("dataValidation.renderMode.arrow")
2538
+ }),
2539
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Radio, {
2540
+ value: `${_univerjs_core.DataValidationRenderMode.TEXT}`,
2541
+ children: localeService.t("dataValidation.renderMode.text")
2542
+ })
2543
+ ]
2544
+ })
2545
+ });
2546
+ }
2547
+ ListRenderModeInput.componentKey = LIST_RENDER_MODE_OPTION_INPUT;
2548
+
2549
+ //#endregion
2550
+ //#region src/views/components/show-time/index.tsx
2551
+ const DATE_SHOW_TIME_OPTION = "DATE_SHOW_TIME_OPTION";
2552
+ function DateShowTimeOption(props) {
2553
+ var _value$bizInfo;
2554
+ const { value, onChange } = props;
2555
+ const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
2556
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.FormLayout, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Checkbox, {
2557
+ checked: (_value$bizInfo = value.bizInfo) === null || _value$bizInfo === void 0 ? void 0 : _value$bizInfo.showTime,
2558
+ onChange: (showTime) => {
2559
+ onChange({
2560
+ ...value,
2561
+ bizInfo: {
2562
+ ...value.bizInfo,
2563
+ showTime
2564
+ }
2565
+ });
2566
+ },
2567
+ children: localeService.t("dataValidation.showTime.label")
2568
+ }) });
2569
+ }
2570
+ DateShowTimeOption.componentKey = DATE_SHOW_TIME_OPTION;
2571
+
2572
+ //#endregion
2573
+ //#region src/views/widgets/checkbox-widget.ts
2574
+ const MARGIN_H$2 = 6;
2575
+ let CheckboxRender = class CheckboxRender {
2576
+ _calc(cellInfo, style) {
2577
+ var _style$fs, _style$fs2, _style$fs3;
2578
+ const { vt, ht } = style || {};
2579
+ const width = cellInfo.endX - cellInfo.startX - MARGIN_H$2 * 2;
2580
+ const height = cellInfo.endY - cellInfo.startY;
2581
+ const size = ((_style$fs = style === null || style === void 0 ? void 0 : style.fs) !== null && _style$fs !== void 0 ? _style$fs : 10) * 1.6;
2582
+ let widgetLeft = 0;
2583
+ let widgetTop = 0;
2584
+ switch (vt) {
2585
+ case _univerjs_core.VerticalAlign.TOP:
2586
+ widgetTop = 0;
2587
+ break;
2588
+ case _univerjs_core.VerticalAlign.BOTTOM:
2589
+ widgetTop = 0 + (height - size);
2590
+ break;
2591
+ default:
2592
+ widgetTop = 0 + (height - size) / 2;
2593
+ break;
2594
+ }
2595
+ switch (ht) {
2596
+ case _univerjs_core.HorizontalAlign.LEFT:
2597
+ widgetLeft = MARGIN_H$2;
2598
+ break;
2599
+ case _univerjs_core.HorizontalAlign.RIGHT:
2600
+ widgetLeft = MARGIN_H$2 + (width - size);
2601
+ break;
2602
+ default:
2603
+ widgetLeft = MARGIN_H$2 + (width - size) / 2;
2604
+ break;
2605
+ }
2606
+ return {
2607
+ left: cellInfo.startX + widgetLeft,
2608
+ top: cellInfo.startY + widgetTop,
2609
+ width: ((_style$fs2 = style === null || style === void 0 ? void 0 : style.fs) !== null && _style$fs2 !== void 0 ? _style$fs2 : 10) * 1.6,
2610
+ height: ((_style$fs3 = style === null || style === void 0 ? void 0 : style.fs) !== null && _style$fs3 !== void 0 ? _style$fs3 : 10) * 1.6
2611
+ };
2612
+ }
2613
+ constructor(_commandService, _univerInstanceService, _formulaService, _themeService, _renderManagerService, _dataValidationModel) {
2614
+ this._commandService = _commandService;
2615
+ this._univerInstanceService = _univerInstanceService;
2616
+ this._formulaService = _formulaService;
2617
+ this._themeService = _themeService;
2618
+ this._renderManagerService = _renderManagerService;
2619
+ this._dataValidationModel = _dataValidationModel;
2620
+ }
2621
+ calcCellAutoHeight(info) {
2622
+ var _style$fs4;
2623
+ const { style } = info;
2624
+ return ((_style$fs4 = style === null || style === void 0 ? void 0 : style.fs) !== null && _style$fs4 !== void 0 ? _style$fs4 : 10) * 1.6;
2625
+ }
2626
+ calcCellAutoWidth(info) {
2627
+ var _style$fs5;
2628
+ const { style } = info;
2629
+ return ((_style$fs5 = style === null || style === void 0 ? void 0 : style.fs) !== null && _style$fs5 !== void 0 ? _style$fs5 : 10) * 1.6;
2630
+ }
2631
+ async _parseFormula(rule, unitId, subUnitId) {
2632
+ var _results$, _results$2, _results$3;
2633
+ const { formula1 = _univerjs_sheets_data_validation.CHECKBOX_FORMULA_1, formula2 = _univerjs_sheets_data_validation.CHECKBOX_FORMULA_2 } = rule;
2634
+ const results = await this._formulaService.getRuleFormulaResult(unitId, subUnitId, rule.uid);
2635
+ const formulaResult1 = (0, _univerjs_sheets_data_validation.getFormulaResult)(results === null || results === void 0 || (_results$ = results[0]) === null || _results$ === void 0 || (_results$ = _results$.result) === null || _results$ === void 0 || (_results$ = _results$[0]) === null || _results$ === void 0 ? void 0 : _results$[0]);
2636
+ const formulaResult2 = (0, _univerjs_sheets_data_validation.getFormulaResult)(results === null || results === void 0 || (_results$2 = results[1]) === null || _results$2 === void 0 || (_results$2 = _results$2.result) === null || _results$2 === void 0 || (_results$2 = _results$2[0]) === null || _results$2 === void 0 ? void 0 : _results$2[0]);
2637
+ const isFormulaValid = (0, _univerjs_sheets_data_validation.isLegalFormulaResult)(String(formulaResult1)) && (0, _univerjs_sheets_data_validation.isLegalFormulaResult)(String(formulaResult2));
2638
+ return {
2639
+ formula1: (0, _univerjs_core.isFormulaString)(formula1) ? (0, _univerjs_sheets_data_validation.getFormulaResult)(results === null || results === void 0 || (_results$3 = results[0]) === null || _results$3 === void 0 || (_results$3 = _results$3.result) === null || _results$3 === void 0 || (_results$3 = _results$3[0]) === null || _results$3 === void 0 ? void 0 : _results$3[0]) : formula1,
2640
+ formula2: (0, _univerjs_core.isFormulaString)(formula2) ? formulaResult2 : formula2,
2641
+ isFormulaValid
2642
+ };
2643
+ }
2644
+ drawWith(ctx, info) {
2645
+ var _validator$skipDefaul, _style$fs6, _style$cl$rgb, _style$cl;
2646
+ const { style, primaryWithCoord, unitId, subUnitId, worksheet, row, col } = info;
2647
+ const cellBounding = primaryWithCoord.isMergedMainCell ? primaryWithCoord.mergeInfo : primaryWithCoord;
2648
+ const value = (0, _univerjs_sheets_data_validation.getCellValueOrigin)(worksheet.getCellRaw(row, col));
2649
+ const rule = this._dataValidationModel.getRuleByLocation(unitId, subUnitId, row, col);
2650
+ if (!rule) return;
2651
+ const validator = this._dataValidationModel.getValidator(rule.type);
2652
+ if (!validator) return;
2653
+ if (!((_validator$skipDefaul = validator.skipDefaultFontRender) === null || _validator$skipDefaul === void 0 ? void 0 : _validator$skipDefaul.call(validator, rule, value, {
2654
+ unitId,
2655
+ subUnitId,
2656
+ row,
2657
+ column: col
2658
+ }))) return;
2659
+ const { formula1 } = validator.parseFormulaSync(rule, unitId, subUnitId);
2660
+ const layout = this._calc(cellBounding, style);
2661
+ const { a: scaleX, d: scaleY } = ctx.getTransform();
2662
+ const left = (0, _univerjs_engine_render.fixLineWidthByScale)(layout.left, scaleX);
2663
+ const top = (0, _univerjs_engine_render.fixLineWidthByScale)(layout.top, scaleY);
2664
+ const transform = _univerjs_engine_render.Transform.create().composeMatrix({
2665
+ left,
2666
+ top,
2667
+ scaleX: 1,
2668
+ scaleY: 1,
2669
+ angle: 0,
2670
+ skewX: 0,
2671
+ skewY: 0,
2672
+ flipX: false,
2673
+ flipY: false
2674
+ });
2675
+ const cellWidth = cellBounding.endX - cellBounding.startX;
2676
+ const cellHeight = cellBounding.endY - cellBounding.startY;
2677
+ ctx.save();
2678
+ ctx.beginPath();
2679
+ ctx.rect(cellBounding.startX, cellBounding.startY, cellWidth, cellHeight);
2680
+ ctx.clip();
2681
+ const m = transform.getMatrix();
2682
+ ctx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
2683
+ const size = ((_style$fs6 = style === null || style === void 0 ? void 0 : style.fs) !== null && _style$fs6 !== void 0 ? _style$fs6 : 10) * 1.6;
2684
+ const checked = String(value) === String(formula1);
2685
+ const defaultColor = this._themeService.getColorFromTheme("primary.600");
2686
+ _univerjs_engine_render.CheckboxShape.drawWith(ctx, {
2687
+ checked,
2688
+ width: size,
2689
+ height: size,
2690
+ fill: (_style$cl$rgb = style === null || style === void 0 || (_style$cl = style.cl) === null || _style$cl === void 0 ? void 0 : _style$cl.rgb) !== null && _style$cl$rgb !== void 0 ? _style$cl$rgb : defaultColor
2691
+ });
2692
+ ctx.restore();
2693
+ }
2694
+ isHit(evt, info) {
2695
+ const cellBounding = info.primaryWithCoord.isMergedMainCell ? info.primaryWithCoord.mergeInfo : info.primaryWithCoord;
2696
+ const layout = this._calc(cellBounding, info.style);
2697
+ const startY = layout.top;
2698
+ const endY = layout.top + layout.height;
2699
+ const startX = layout.left;
2700
+ const endX = layout.left + layout.width;
2701
+ const { x: offsetX, y: offsetY } = evt;
2702
+ if (offsetX <= endX && offsetX >= startX && offsetY <= endY && offsetY >= startY) return true;
2703
+ return false;
2704
+ }
2705
+ async onPointerDown(info, evt) {
2706
+ var _validator$skipDefaul2;
2707
+ if (evt.button === 2) return;
2708
+ const { primaryWithCoord, unitId, subUnitId, worksheet, row, col } = info;
2709
+ const value = (0, _univerjs_sheets_data_validation.getCellValueOrigin)(worksheet.getCellRaw(row, col));
2710
+ const rule = this._dataValidationModel.getRuleByLocation(unitId, subUnitId, row, col);
2711
+ if (!rule) return;
2712
+ const validator = this._dataValidationModel.getValidator(rule.type);
2713
+ if (!validator) return;
2714
+ if (!((_validator$skipDefaul2 = validator.skipDefaultFontRender) === null || _validator$skipDefaul2 === void 0 ? void 0 : _validator$skipDefaul2.call(validator, rule, value, {
2715
+ unitId,
2716
+ subUnitId,
2717
+ row,
2718
+ column: col
2719
+ }))) return;
2720
+ const { formula1, formula2 } = await this._parseFormula(rule, unitId, subUnitId);
2721
+ const params = {
2722
+ range: {
2723
+ startColumn: primaryWithCoord.actualColumn,
2724
+ endColumn: primaryWithCoord.actualColumn,
2725
+ startRow: primaryWithCoord.actualRow,
2726
+ endRow: primaryWithCoord.actualRow
2727
+ },
2728
+ value: {
2729
+ v: String(value) === (0, _univerjs_sheets_data_validation.transformCheckboxValue)(String(formula1)) ? formula2 : formula1,
2730
+ p: null
2731
+ }
2732
+ };
2733
+ this._commandService.executeCommand(_univerjs_sheets.SetRangeValuesCommand.id, params);
2734
+ }
2735
+ onPointerEnter(info, evt) {
2736
+ var _getCurrentTypeOfRend;
2737
+ (_getCurrentTypeOfRend = (0, _univerjs_engine_render.getCurrentTypeOfRenderer)(_univerjs_core.UniverInstanceType.UNIVER_SHEET, this._univerInstanceService, this._renderManagerService)) === null || _getCurrentTypeOfRend === void 0 || (_getCurrentTypeOfRend = _getCurrentTypeOfRend.mainComponent) === null || _getCurrentTypeOfRend === void 0 || _getCurrentTypeOfRend.setCursor(_univerjs_engine_render.CURSOR_TYPE.POINTER);
2738
+ }
2739
+ onPointerLeave(info, evt) {
2740
+ var _getCurrentTypeOfRend2;
2741
+ (_getCurrentTypeOfRend2 = (0, _univerjs_engine_render.getCurrentTypeOfRenderer)(_univerjs_core.UniverInstanceType.UNIVER_SHEET, this._univerInstanceService, this._renderManagerService)) === null || _getCurrentTypeOfRend2 === void 0 || (_getCurrentTypeOfRend2 = _getCurrentTypeOfRend2.mainComponent) === null || _getCurrentTypeOfRend2 === void 0 || _getCurrentTypeOfRend2.setCursor(_univerjs_engine_render.CURSOR_TYPE.DEFAULT);
2742
+ }
2743
+ };
2744
+ CheckboxRender = __decorate([
2745
+ __decorateParam(0, _univerjs_core.ICommandService),
2746
+ __decorateParam(1, _univerjs_core.IUniverInstanceService),
2747
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.DataValidationFormulaService)),
2748
+ __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_core.ThemeService)),
2749
+ __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_engine_render.IRenderManagerService)),
2750
+ __decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel))
2751
+ ], CheckboxRender);
2752
+
2753
+ //#endregion
2754
+ //#region src/views/validator-views/sheet-validator-view.ts
2755
+ let BaseSheetDataValidatorView = class BaseSheetDataValidatorView {
2756
+ constructor(injector) {
2757
+ this.injector = injector;
2758
+ _defineProperty(this, "canvasRender", null);
2759
+ _defineProperty(this, "dropdownType", void 0);
2760
+ _defineProperty(this, "optionsInput", void 0);
2761
+ _defineProperty(this, "formulaInput", _univerjs_sheets_data_validation.LIST_FORMULA_INPUT_NAME);
2762
+ }
2763
+ };
2764
+ BaseSheetDataValidatorView = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.Injector))], BaseSheetDataValidatorView);
2765
+
2766
+ //#endregion
2767
+ //#region src/views/validator-views/checkbox-validator-view.ts
2768
+ /**
2769
+ * Copyright 2023-present DreamNum Co., Ltd.
2770
+ *
2771
+ * Licensed under the Apache License, Version 2.0 (the "License");
2772
+ * you may not use this file except in compliance with the License.
2773
+ * You may obtain a copy of the License at
2774
+ *
2775
+ * http://www.apache.org/licenses/LICENSE-2.0
2776
+ *
2777
+ * Unless required by applicable law or agreed to in writing, software
2778
+ * distributed under the License is distributed on an "AS IS" BASIS,
2779
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2780
+ * See the License for the specific language governing permissions and
2781
+ * limitations under the License.
2782
+ */
2783
+ var CheckboxValidatorView = class extends BaseSheetDataValidatorView {
2784
+ constructor(..._args) {
2785
+ super(..._args);
2786
+ _defineProperty(this, "id", _univerjs_core.DataValidationType.CHECKBOX);
2787
+ _defineProperty(this, "canvasRender", this.injector.createInstance(CheckboxRender));
2788
+ _defineProperty(this, "formulaInput", _univerjs_sheets_data_validation.CHECKBOX_FORMULA_INPUT_NAME);
2789
+ }
2790
+ };
2791
+
2792
+ //#endregion
2793
+ //#region src/views/validator-views/custom-validator-view.ts
2794
+ /**
2795
+ * Copyright 2023-present DreamNum Co., Ltd.
2796
+ *
2797
+ * Licensed under the Apache License, Version 2.0 (the "License");
2798
+ * you may not use this file except in compliance with the License.
2799
+ * You may obtain a copy of the License at
2800
+ *
2801
+ * http://www.apache.org/licenses/LICENSE-2.0
2802
+ *
2803
+ * Unless required by applicable law or agreed to in writing, software
2804
+ * distributed under the License is distributed on an "AS IS" BASIS,
2805
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2806
+ * See the License for the specific language governing permissions and
2807
+ * limitations under the License.
2808
+ */
2809
+ var CustomFormulaValidatorView = class extends BaseSheetDataValidatorView {
2810
+ constructor(..._args) {
2811
+ super(..._args);
2812
+ _defineProperty(this, "id", _univerjs_core.DataValidationType.CUSTOM);
2813
+ _defineProperty(this, "formulaInput", _univerjs_sheets_data_validation.CUSTOM_FORMULA_INPUT_NAME);
2814
+ }
2815
+ };
2816
+
2817
+ //#endregion
2818
+ //#region src/views/components/formula-input/formula-input.ts
2819
+ const BASE_FORMULA_INPUT_NAME = "data-validation.formula-input";
2820
+
2821
+ //#endregion
2822
+ //#region src/views/validator-views/date-validator-view.ts
2823
+ /**
2824
+ * Copyright 2023-present DreamNum Co., Ltd.
2825
+ *
2826
+ * Licensed under the Apache License, Version 2.0 (the "License");
2827
+ * you may not use this file except in compliance with the License.
2828
+ * You may obtain a copy of the License at
2829
+ *
2830
+ * http://www.apache.org/licenses/LICENSE-2.0
2831
+ *
2832
+ * Unless required by applicable law or agreed to in writing, software
2833
+ * distributed under the License is distributed on an "AS IS" BASIS,
2834
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2835
+ * See the License for the specific language governing permissions and
2836
+ * limitations under the License.
2837
+ */
2838
+ var DateValidatorView = class extends BaseSheetDataValidatorView {
2839
+ constructor(..._args) {
2840
+ super(..._args);
2841
+ _defineProperty(this, "id", _univerjs_core.DataValidationType.DATE);
2842
+ _defineProperty(this, "formulaInput", BASE_FORMULA_INPUT_NAME);
2843
+ _defineProperty(this, "optionsInput", DateShowTimeOption.componentKey);
2844
+ _defineProperty(this, "dropdownType", _univerjs_data_validation.DataValidatorDropdownType.DATE);
2845
+ }
2846
+ };
2847
+
2848
+ //#endregion
2849
+ //#region src/views/validator-views/decimal-validator-view.ts
2850
+ /**
2851
+ * Copyright 2023-present DreamNum Co., Ltd.
2852
+ *
2853
+ * Licensed under the Apache License, Version 2.0 (the "License");
2854
+ * you may not use this file except in compliance with the License.
2855
+ * You may obtain a copy of the License at
2856
+ *
2857
+ * http://www.apache.org/licenses/LICENSE-2.0
2858
+ *
2859
+ * Unless required by applicable law or agreed to in writing, software
2860
+ * distributed under the License is distributed on an "AS IS" BASIS,
2861
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2862
+ * See the License for the specific language governing permissions and
2863
+ * limitations under the License.
2864
+ */
2865
+ var DecimalValidatorView = class extends BaseSheetDataValidatorView {
2866
+ constructor(..._args) {
2867
+ super(..._args);
2868
+ _defineProperty(this, "id", _univerjs_core.DataValidationType.DECIMAL);
2869
+ _defineProperty(this, "formulaInput", _univerjs_sheets_data_validation.BASE_FORMULA_INPUT_NAME);
2870
+ }
2871
+ };
2872
+
2873
+ //#endregion
2874
+ //#region src/views/widgets/shape/layout.ts
2875
+ const PADDING_H$1 = 4;
2876
+ const PADDING_V$1 = 0;
2877
+ const MARGIN_H$1 = 4;
2878
+ const MARGIN_V$1 = 4;
2879
+ const CELL_PADDING_H = 6;
2880
+ const CELL_PADDING_V = 6;
2881
+ const ICON_PLACE$1 = 14;
2882
+ function getDropdownItemSize(text, fontStyle) {
2883
+ const bBox = _univerjs_engine_render.FontCache.getTextSize(text, fontStyle);
2884
+ const rectWidth = bBox.width + 4 * 2;
2885
+ const { ba, bd } = bBox;
2886
+ return {
2887
+ width: rectWidth,
2888
+ height: ba + bd + 0 * 2,
2889
+ ba
2890
+ };
2891
+ }
2892
+ function layoutDropdowns(items, fontStyle, cellWidth, cellHeight) {
2893
+ const cellPaddingH = 14 + 6 * 2;
2894
+ const widthAvailableForContent = cellWidth - cellPaddingH;
2895
+ const heightAvailableForContent = cellHeight - 6 * 2;
2896
+ const textLayout = items.map((item) => ({
2897
+ layout: getDropdownItemSize(item, fontStyle),
2898
+ text: item
2899
+ }));
2900
+ let currentLine;
2901
+ const lines = [];
2902
+ textLayout.forEach((item) => {
2903
+ const { layout } = item;
2904
+ const { width, height } = layout;
2905
+ if (!currentLine || currentLine.width + width + 4 > widthAvailableForContent) {
2906
+ currentLine = {
2907
+ width,
2908
+ height,
2909
+ items: [{
2910
+ ...item,
2911
+ left: 0
2912
+ }]
2913
+ };
2914
+ lines.push(currentLine);
2915
+ } else {
2916
+ currentLine.items.push({
2917
+ ...item,
2918
+ left: currentLine.width + 4
2919
+ });
2920
+ currentLine.width = currentLine.width + width + 4;
2921
+ }
2922
+ });
2923
+ let totalHeight = 0;
2924
+ let maxLineWidth = 0;
2925
+ lines.forEach((line, index) => {
2926
+ maxLineWidth = Math.max(maxLineWidth, line.width);
2927
+ if (index === lines.length - 1) totalHeight += line.height;
2928
+ else totalHeight += line.height + 4;
2929
+ });
2930
+ return {
2931
+ lines,
2932
+ totalHeight,
2933
+ contentWidth: widthAvailableForContent,
2934
+ contentHeight: heightAvailableForContent,
2935
+ cellAutoHeight: totalHeight + 6 * 2,
2936
+ calcAutoWidth: maxLineWidth + cellPaddingH
2937
+ };
2938
+ }
2939
+
2940
+ //#endregion
2941
+ //#region src/views/widgets/shape/dropdown.ts
2942
+ const RADIUS = 8;
2943
+ var Dropdown = class extends _univerjs_engine_render.Shape {
2944
+ static drawWith(ctx, props) {
2945
+ const { fontString, info, fill, color } = props;
2946
+ const { layout, text } = info;
2947
+ ctx.save();
2948
+ _univerjs_engine_render.Rect.drawWith(ctx, {
2949
+ width: layout.width,
2950
+ height: layout.height,
2951
+ radius: RADIUS,
2952
+ fill: fill || "#ECECEC"
2953
+ });
2954
+ ctx.translateWithPrecision(4, layout.ba);
2955
+ ctx.font = fontString;
2956
+ ctx.fillStyle = color;
2957
+ ctx.fillText(text, 0, 0);
2958
+ ctx.restore();
2959
+ }
2960
+ };
2961
+
2962
+ //#endregion
2963
+ //#region src/views/widgets/dropdown-multiple-widget.ts
2964
+ const downPath$1 = 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");
2965
+ let DropdownMultipleWidget = class DropdownMultipleWidget {
2966
+ constructor(_commandService, _univerInstanceService, _renderManagerService, _dataValidationModel) {
2967
+ this._commandService = _commandService;
2968
+ this._univerInstanceService = _univerInstanceService;
2969
+ this._renderManagerService = _renderManagerService;
2970
+ this._dataValidationModel = _dataValidationModel;
2971
+ _defineProperty(this, "zIndex", void 0);
2972
+ _defineProperty(this, "_dropdownInfoMap", /* @__PURE__ */ new Map());
2973
+ }
2974
+ _ensureMap(subUnitId) {
2975
+ let map = this._dropdownInfoMap.get(subUnitId);
2976
+ if (!map) {
2977
+ map = /* @__PURE__ */ new Map();
2978
+ this._dropdownInfoMap.set(subUnitId, map);
2979
+ }
2980
+ return map;
2981
+ }
2982
+ _generateKey(row, col) {
2983
+ return `${row}.${col}`;
2984
+ }
2985
+ _drawDownIcon(ctx, cellBounding, cellWidth, cellHeight, vt) {
2986
+ const left = cellWidth - 14 + 4;
2987
+ let top = 4;
2988
+ switch (vt) {
2989
+ case _univerjs_core.VerticalAlign.MIDDLE:
2990
+ top = (cellHeight - 14) / 2 + 4;
2991
+ break;
2992
+ case _univerjs_core.VerticalAlign.BOTTOM:
2993
+ top = cellHeight - 14 + 4;
2994
+ break;
2995
+ default: break;
2996
+ }
2997
+ ctx.save();
2998
+ ctx.translateWithPrecision(cellBounding.startX + left, cellBounding.startY + top);
2999
+ ctx.fillStyle = "#565656";
3000
+ ctx.fill(downPath$1);
3001
+ ctx.restore();
3002
+ }
3003
+ drawWith(ctx, info, skeleton, spreadsheets) {
3004
+ var _ref, _getCellValueOrigin;
3005
+ const { primaryWithCoord, row, col, style, data, subUnitId } = info;
3006
+ const _cellBounding = primaryWithCoord.isMergedMainCell ? primaryWithCoord.mergeInfo : primaryWithCoord;
3007
+ const { leftOffset = 0, rightOffset = 0, topOffset = 0, downOffset = 0 } = (data === null || data === void 0 ? void 0 : data.fontRenderExtension) || {};
3008
+ const map = this._ensureMap(subUnitId);
3009
+ const key = this._generateKey(row, col);
3010
+ const _row = primaryWithCoord.isMergedMainCell ? primaryWithCoord.mergeInfo.startRow : row;
3011
+ const _col = primaryWithCoord.isMergedMainCell ? primaryWithCoord.mergeInfo.startColumn : col;
3012
+ const rule = this._dataValidationModel.getRuleByLocation(info.unitId, info.subUnitId, _row, _col);
3013
+ if (!rule) return;
3014
+ const validator = this._dataValidationModel.getValidator(rule.type);
3015
+ if (!validator) return;
3016
+ const cellBounding = {
3017
+ startX: _cellBounding.startX + leftOffset,
3018
+ endX: _cellBounding.endX - rightOffset,
3019
+ startY: _cellBounding.startY + topOffset,
3020
+ endY: _cellBounding.endY - downOffset
3021
+ };
3022
+ const cellWidth = cellBounding.endX - cellBounding.startX;
3023
+ const cellHeight = cellBounding.endY - cellBounding.startY;
3024
+ const { cl } = style || {};
3025
+ const color = (_ref = typeof cl === "object" ? cl === null || cl === void 0 ? void 0 : cl.rgb : cl) !== null && _ref !== void 0 ? _ref : "#000";
3026
+ const fontStyle = (0, _univerjs_engine_render.getFontStyleString)(style !== null && style !== void 0 ? style : void 0);
3027
+ const { vt: _vt, ht } = style || {};
3028
+ const vt = _vt !== null && _vt !== void 0 ? _vt : _univerjs_core.VerticalAlign.MIDDLE;
3029
+ const cellValue = (_getCellValueOrigin = (0, _univerjs_sheets_data_validation.getCellValueOrigin)(data)) !== null && _getCellValueOrigin !== void 0 ? _getCellValueOrigin : "";
3030
+ const items = validator.parseCellValue(cellValue);
3031
+ const labelColorMap = validator.getListWithColorMap(rule);
3032
+ const layout = layoutDropdowns(items, fontStyle, cellWidth, cellHeight);
3033
+ this._drawDownIcon(ctx, cellBounding, cellWidth, cellHeight, vt);
3034
+ ctx.save();
3035
+ ctx.translateWithPrecision(cellBounding.startX, cellBounding.startY);
3036
+ ctx.beginPath();
3037
+ ctx.rect(0, 0, cellWidth - 14, cellHeight);
3038
+ ctx.clip();
3039
+ ctx.translateWithPrecision(6, 6);
3040
+ let top = 0;
3041
+ switch (vt) {
3042
+ case _univerjs_core.VerticalAlign.MIDDLE:
3043
+ top = (layout.contentHeight - layout.totalHeight) / 2;
3044
+ break;
3045
+ case _univerjs_core.VerticalAlign.BOTTOM:
3046
+ top = layout.contentHeight - layout.totalHeight;
3047
+ break;
3048
+ default: break;
3049
+ }
3050
+ ctx.translateWithPrecision(0, top);
3051
+ layout.lines.forEach((line, index) => {
3052
+ ctx.save();
3053
+ const { width, height, items } = line;
3054
+ let left = 0;
3055
+ switch (ht) {
3056
+ case _univerjs_core.HorizontalAlign.RIGHT:
3057
+ left = layout.contentWidth - width;
3058
+ break;
3059
+ case _univerjs_core.HorizontalAlign.CENTER:
3060
+ left = (layout.contentWidth - width) / 2;
3061
+ break;
3062
+ default: break;
3063
+ }
3064
+ ctx.translate(left, index * (height + 4));
3065
+ items.forEach((item) => {
3066
+ ctx.save();
3067
+ ctx.translateWithPrecision(item.left, 0);
3068
+ Dropdown.drawWith(ctx, {
3069
+ ...fontStyle,
3070
+ info: item,
3071
+ color,
3072
+ fill: labelColorMap[item.text]
3073
+ });
3074
+ ctx.restore();
3075
+ });
3076
+ ctx.restore();
3077
+ });
3078
+ ctx.restore();
3079
+ map.set(key, {
3080
+ left: cellBounding.startX,
3081
+ top: cellBounding.startY,
3082
+ width: layout.contentWidth + 6 + 14,
3083
+ height: layout.contentHeight + 6 * 2
3084
+ });
3085
+ }
3086
+ calcCellAutoHeight(info) {
3087
+ var _getCellValueOrigin2;
3088
+ const { primaryWithCoord, style, data, row, col } = info;
3089
+ const { leftOffset = 0, rightOffset = 0, topOffset = 0, downOffset = 0 } = (data === null || data === void 0 ? void 0 : data.fontRenderExtension) || {};
3090
+ const _cellBounding = primaryWithCoord.isMergedMainCell ? primaryWithCoord.mergeInfo : primaryWithCoord;
3091
+ const cellBounding = {
3092
+ startX: _cellBounding.startX + leftOffset,
3093
+ endX: _cellBounding.endX - rightOffset,
3094
+ startY: _cellBounding.startY + topOffset,
3095
+ endY: _cellBounding.endY - downOffset
3096
+ };
3097
+ const rule = this._dataValidationModel.getRuleByLocation(info.unitId, info.subUnitId, row, col);
3098
+ if (!rule) return;
3099
+ const validator = this._dataValidationModel.getValidator(rule.type);
3100
+ if (!validator) return;
3101
+ const cellWidth = cellBounding.endX - cellBounding.startX;
3102
+ const cellHeight = cellBounding.endY - cellBounding.startY;
3103
+ const cellValue = (_getCellValueOrigin2 = (0, _univerjs_sheets_data_validation.getCellValueOrigin)(data)) !== null && _getCellValueOrigin2 !== void 0 ? _getCellValueOrigin2 : "";
3104
+ return layoutDropdowns(validator.parseCellValue(cellValue), (0, _univerjs_engine_render.getFontStyleString)(style !== null && style !== void 0 ? style : void 0), cellWidth, cellHeight).cellAutoHeight;
3105
+ }
3106
+ calcCellAutoWidth(info) {
3107
+ var _getCellValueOrigin3;
3108
+ const { primaryWithCoord, style, data, row, col } = info;
3109
+ const { leftOffset = 0, rightOffset = 0, topOffset = 0, downOffset = 0 } = (data === null || data === void 0 ? void 0 : data.fontRenderExtension) || {};
3110
+ const _cellBounding = primaryWithCoord.isMergedMainCell ? primaryWithCoord.mergeInfo : primaryWithCoord;
3111
+ const cellBounding = {
3112
+ startX: _cellBounding.startX + leftOffset,
3113
+ endX: _cellBounding.endX - rightOffset,
3114
+ startY: _cellBounding.startY + topOffset,
3115
+ endY: _cellBounding.endY - downOffset
3116
+ };
3117
+ const rule = this._dataValidationModel.getRuleByLocation(info.unitId, info.subUnitId, row, col);
3118
+ if (!rule) return;
3119
+ const validator = this._dataValidationModel.getValidator(rule.type);
3120
+ if (!validator) return;
3121
+ const cellWidth = cellBounding.endX - cellBounding.startX;
3122
+ const cellHeight = cellBounding.endY - cellBounding.startY;
3123
+ const cellValue = (_getCellValueOrigin3 = (0, _univerjs_sheets_data_validation.getCellValueOrigin)(data)) !== null && _getCellValueOrigin3 !== void 0 ? _getCellValueOrigin3 : "";
3124
+ return layoutDropdowns(validator.parseCellValue(cellValue), (0, _univerjs_engine_render.getFontStyleString)(style !== null && style !== void 0 ? style : void 0), cellWidth, cellHeight).calcAutoWidth;
3125
+ }
3126
+ isHit(position, info) {
3127
+ const { primaryWithCoord } = info;
3128
+ const { endX } = primaryWithCoord.isMergedMainCell ? primaryWithCoord.mergeInfo : primaryWithCoord;
3129
+ const { x } = position;
3130
+ if (x >= endX - 14 && x <= endX) return true;
3131
+ return false;
3132
+ }
3133
+ onPointerDown(info, evt) {
3134
+ if (evt.button === 2) return;
3135
+ const { unitId, subUnitId, row, col } = info;
3136
+ const params = {
3137
+ unitId,
3138
+ subUnitId,
3139
+ row,
3140
+ column: col
3141
+ };
3142
+ this._commandService.executeCommand(ShowDataValidationDropdown.id, params);
3143
+ }
3144
+ onPointerEnter(info, evt) {
3145
+ var _getCurrentTypeOfRend;
3146
+ return (_getCurrentTypeOfRend = (0, _univerjs_engine_render.getCurrentTypeOfRenderer)(_univerjs_core.UniverInstanceType.UNIVER_SHEET, this._univerInstanceService, this._renderManagerService)) === null || _getCurrentTypeOfRend === void 0 || (_getCurrentTypeOfRend = _getCurrentTypeOfRend.mainComponent) === null || _getCurrentTypeOfRend === void 0 ? void 0 : _getCurrentTypeOfRend.setCursor(_univerjs_engine_render.CURSOR_TYPE.POINTER);
3147
+ }
3148
+ onPointerLeave(info, evt) {
3149
+ var _getCurrentTypeOfRend2;
3150
+ return (_getCurrentTypeOfRend2 = (0, _univerjs_engine_render.getCurrentTypeOfRenderer)(_univerjs_core.UniverInstanceType.UNIVER_SHEET, this._univerInstanceService, this._renderManagerService)) === null || _getCurrentTypeOfRend2 === void 0 || (_getCurrentTypeOfRend2 = _getCurrentTypeOfRend2.mainComponent) === null || _getCurrentTypeOfRend2 === void 0 ? void 0 : _getCurrentTypeOfRend2.setCursor(_univerjs_engine_render.CURSOR_TYPE.DEFAULT);
3151
+ }
3152
+ };
3153
+ DropdownMultipleWidget = __decorate([
3154
+ __decorateParam(0, _univerjs_core.ICommandService),
3155
+ __decorateParam(1, _univerjs_core.IUniverInstanceService),
3156
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_engine_render.IRenderManagerService)),
3157
+ __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel))
3158
+ ], DropdownMultipleWidget);
3159
+
3160
+ //#endregion
3161
+ //#region src/views/validator-views/list-multiple-view.ts
3162
+ /**
3163
+ * Copyright 2023-present DreamNum Co., Ltd.
3164
+ *
3165
+ * Licensed under the Apache License, Version 2.0 (the "License");
3166
+ * you may not use this file except in compliance with the License.
3167
+ * You may obtain a copy of the License at
3168
+ *
3169
+ * http://www.apache.org/licenses/LICENSE-2.0
3170
+ *
3171
+ * Unless required by applicable law or agreed to in writing, software
3172
+ * distributed under the License is distributed on an "AS IS" BASIS,
3173
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3174
+ * See the License for the specific language governing permissions and
3175
+ * limitations under the License.
3176
+ */
3177
+ var ListMultipleValidatorView = class extends BaseSheetDataValidatorView {
3178
+ constructor(..._args) {
3179
+ super(..._args);
3180
+ _defineProperty(this, "id", _univerjs_core.DataValidationType.LIST_MULTIPLE);
3181
+ _defineProperty(this, "canvasRender", this.injector.createInstance(DropdownMultipleWidget));
3182
+ _defineProperty(this, "dropdownType", _univerjs_data_validation.DataValidatorDropdownType.MULTIPLE_LIST);
3183
+ }
3184
+ };
3185
+
3186
+ //#endregion
3187
+ //#region src/views/widgets/dropdown-widget.ts
3188
+ /**
3189
+ * padding in Capsule
3190
+ */
3191
+ const PADDING_H = 4;
3192
+ const ICON_SIZE = 4;
3193
+ const ICON_PLACE = 14;
3194
+ const PADDING_V = 1;
3195
+ /**
3196
+ * margin for Capsule, that means distance between capsule and cell border
3197
+ */
3198
+ const MARGIN_H = 6;
3199
+ const MARGIN_V = 3;
3200
+ const RADIUS_BG = 8;
3201
+ const DROP_DOWN_ICON_COLOR = "#565656";
3202
+ const downPath = 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");
3203
+ function calcPadding(cellWidth, cellHeight, fontWidth, fontHeight, vt, ht, margin = true) {
3204
+ let paddingTop = 0;
3205
+ const realMargin = margin ? MARGIN_V : 0;
3206
+ switch (vt) {
3207
+ case _univerjs_core.VerticalAlign.BOTTOM:
3208
+ paddingTop = cellHeight - fontHeight - realMargin;
3209
+ break;
3210
+ case _univerjs_core.VerticalAlign.MIDDLE:
3211
+ paddingTop = (cellHeight - fontHeight) / 2;
3212
+ break;
3213
+ default:
3214
+ paddingTop = realMargin;
3215
+ break;
3216
+ }
3217
+ paddingTop = Math.max(MARGIN_V, paddingTop);
3218
+ let paddingLeft = 0;
3219
+ switch (ht) {
3220
+ case _univerjs_core.HorizontalAlign.CENTER:
3221
+ paddingLeft = (cellWidth - fontWidth) / 2;
3222
+ break;
3223
+ case _univerjs_core.HorizontalAlign.RIGHT:
3224
+ paddingLeft = cellWidth - fontWidth;
3225
+ break;
3226
+ default: break;
3227
+ }
3228
+ paddingLeft = Math.max(MARGIN_H, paddingLeft);
3229
+ return {
3230
+ paddingLeft,
3231
+ paddingTop
3232
+ };
3233
+ }
3234
+ let DropdownWidget = class DropdownWidget {
3235
+ constructor(_univerInstanceService, _localeService, _commandService, _renderManagerService, _dataValidationModel) {
3236
+ this._univerInstanceService = _univerInstanceService;
3237
+ this._localeService = _localeService;
3238
+ this._commandService = _commandService;
3239
+ this._renderManagerService = _renderManagerService;
3240
+ this._dataValidationModel = _dataValidationModel;
3241
+ _defineProperty(this, "_dropdownInfoMap", /* @__PURE__ */ new Map());
3242
+ _defineProperty(this, "zIndex", void 0);
3243
+ }
3244
+ _ensureMap(subUnitId) {
3245
+ let map = this._dropdownInfoMap.get(subUnitId);
3246
+ if (!map) {
3247
+ map = /* @__PURE__ */ new Map();
3248
+ this._dropdownInfoMap.set(subUnitId, map);
3249
+ }
3250
+ return map;
3251
+ }
3252
+ _generateKey(row, col) {
3253
+ return `${row}.${col}`;
3254
+ }
3255
+ _drawDownIcon(ctx, cellBounding, cellWidth, cellHeight, fontHeight, vt, pd) {
3256
+ const { t = _univerjs_core.DEFAULT_STYLES.pd.t, b = _univerjs_core.DEFAULT_STYLES.pd.b } = pd;
3257
+ const left = cellWidth - ICON_PLACE;
3258
+ let top;
3259
+ switch (vt) {
3260
+ case _univerjs_core.VerticalAlign.MIDDLE:
3261
+ top = (cellHeight - ICON_SIZE) / 2;
3262
+ break;
3263
+ case _univerjs_core.VerticalAlign.BOTTOM:
3264
+ top = cellHeight - b - fontHeight - MARGIN_V + (fontHeight / 2 - ICON_SIZE / 2);
3265
+ break;
3266
+ default:
3267
+ top = t + MARGIN_V + (fontHeight / 2 - ICON_SIZE / 2);
3268
+ break;
3269
+ }
3270
+ ctx.save();
3271
+ ctx.translateWithPrecision(cellBounding.startX + left, cellBounding.startY + top);
3272
+ ctx.fillStyle = "#565656";
3273
+ ctx.fill(downPath);
3274
+ ctx.restore();
3275
+ }
3276
+ drawWith(ctx, info, skeleton) {
3277
+ var _tb, _vt, _ht, _pd;
3278
+ const { primaryWithCoord, row, col, style, data, subUnitId } = info;
3279
+ const _cellBounding = primaryWithCoord.isMergedMainCell ? primaryWithCoord.mergeInfo : primaryWithCoord;
3280
+ const _row = primaryWithCoord.isMergedMainCell ? primaryWithCoord.mergeInfo.startRow : row;
3281
+ const _col = primaryWithCoord.isMergedMainCell ? primaryWithCoord.mergeInfo.startColumn : col;
3282
+ const rule = this._dataValidationModel.getRuleByLocation(info.unitId, info.subUnitId, _row, _col);
3283
+ if (!rule) return;
3284
+ const validator = this._dataValidationModel.getValidator(rule.type);
3285
+ if (!validator) return;
3286
+ const { leftOffset = 0, rightOffset = 0, topOffset = 0, downOffset = 0 } = (data === null || data === void 0 ? void 0 : data.fontRenderExtension) || {};
3287
+ if (!rule || !validator || !validator || validator.id.indexOf(_univerjs_core.DataValidationType.LIST) !== 0) return;
3288
+ if (!validator.skipDefaultFontRender(rule)) return;
3289
+ const cellBounding = {
3290
+ startX: _cellBounding.startX + leftOffset,
3291
+ endX: _cellBounding.endX - rightOffset,
3292
+ startY: _cellBounding.startY + topOffset,
3293
+ endY: _cellBounding.endY - downOffset
3294
+ };
3295
+ const cellWidth = cellBounding.endX - cellBounding.startX;
3296
+ const cellHeight = cellBounding.endY - cellBounding.startY;
3297
+ const map = this._ensureMap(subUnitId);
3298
+ const key = this._generateKey(row, col);
3299
+ const colorMap = validator.getListWithColorMap(rule);
3300
+ const value = (0, _univerjs_sheets_data_validation.getCellValueOrigin)(data);
3301
+ const valueStr = `${value !== null && value !== void 0 ? value : ""}`;
3302
+ const activeColor = colorMap[valueStr];
3303
+ let { tb, vt, ht, pd } = style || {};
3304
+ tb = (_tb = tb) !== null && _tb !== void 0 ? _tb : _univerjs_core.WrapStrategy.WRAP;
3305
+ vt = (_vt = vt) !== null && _vt !== void 0 ? _vt : _univerjs_core.VerticalAlign.BOTTOM;
3306
+ ht = (_ht = ht) !== null && _ht !== void 0 ? _ht : _univerjs_core.DEFAULT_STYLES.ht;
3307
+ pd = (_pd = pd) !== null && _pd !== void 0 ? _pd : _univerjs_core.DEFAULT_STYLES.pd;
3308
+ const fontStyle = (0, _univerjs_engine_render.getFontStyleString)(style).fontCache;
3309
+ if (rule.renderMode === _univerjs_core.DataValidationRenderMode.ARROW) {
3310
+ var _style$cl, _style$st, _style$ul;
3311
+ const { l = _univerjs_core.DEFAULT_STYLES.pd.l, t = _univerjs_core.DEFAULT_STYLES.pd.t, r = _univerjs_core.DEFAULT_STYLES.pd.r, b = _univerjs_core.DEFAULT_STYLES.pd.b } = pd;
3312
+ const realWidth = cellWidth - l - r - ICON_PLACE - 4;
3313
+ const textSkeleton = new _univerjs_engine_render.DocSimpleSkeleton(valueStr, fontStyle, Boolean(tb === _univerjs_core.WrapStrategy.WRAP), realWidth, Infinity);
3314
+ textSkeleton.calculate();
3315
+ const fontWidth = textSkeleton.getTotalWidth();
3316
+ const fontHeight = textSkeleton.getTotalHeight();
3317
+ const { paddingTop, paddingLeft } = calcPadding(realWidth, cellHeight - t - b, fontWidth, fontHeight, vt, ht, true);
3318
+ this._drawDownIcon(ctx, cellBounding, cellWidth, cellHeight, fontHeight, vt, pd);
3319
+ ctx.save();
3320
+ ctx.translateWithPrecision(cellBounding.startX + l, cellBounding.startY + t);
3321
+ ctx.beginPath();
3322
+ ctx.rect(0, 0, cellWidth - l - r, cellHeight - t - b);
3323
+ ctx.clip();
3324
+ ctx.translateWithPrecision(0, paddingTop);
3325
+ ctx.save();
3326
+ ctx.translateWithPrecision(paddingLeft, 0);
3327
+ ctx.beginPath();
3328
+ ctx.rect(0, 0, realWidth, fontHeight);
3329
+ ctx.clip();
3330
+ _univerjs_engine_render.Text.drawWith(ctx, {
3331
+ text: valueStr,
3332
+ fontStyle,
3333
+ width: realWidth,
3334
+ height: fontHeight,
3335
+ color: style === null || style === void 0 || (_style$cl = style.cl) === null || _style$cl === void 0 ? void 0 : _style$cl.rgb,
3336
+ strokeLine: Boolean(style === null || style === void 0 || (_style$st = style.st) === null || _style$st === void 0 ? void 0 : _style$st.s),
3337
+ underline: Boolean(style === null || style === void 0 || (_style$ul = style.ul) === null || _style$ul === void 0 ? void 0 : _style$ul.s),
3338
+ warp: tb === _univerjs_core.WrapStrategy.WRAP,
3339
+ hAlign: _univerjs_core.HorizontalAlign.LEFT
3340
+ }, textSkeleton);
3341
+ ctx.restore();
3342
+ ctx.restore();
3343
+ map.set(key, {
3344
+ left: cellBounding.endX - ICON_PLACE + skeleton.rowHeaderWidth,
3345
+ top: cellBounding.startY + t + skeleton.columnHeaderHeight,
3346
+ width: ICON_PLACE,
3347
+ height: cellHeight - t - b
3348
+ });
3349
+ } else {
3350
+ var _style$cl2, _style$st2, _style$ul2;
3351
+ ctx.save();
3352
+ ctx.translateWithPrecision(cellBounding.startX, cellBounding.startY);
3353
+ ctx.beginPath();
3354
+ ctx.rect(0, 0, cellWidth, cellHeight);
3355
+ ctx.clip();
3356
+ const realWidth = cellWidth - MARGIN_H * 2 - PADDING_H - ICON_PLACE - 4;
3357
+ const textSkeleton = new _univerjs_engine_render.DocSimpleSkeleton(valueStr, fontStyle, Boolean(tb === _univerjs_core.WrapStrategy.WRAP), realWidth, Infinity);
3358
+ textSkeleton.calculate();
3359
+ const fontWidth = textSkeleton.getTotalWidth();
3360
+ const fontHeight = textSkeleton.getTotalHeight();
3361
+ const rectHeight = fontHeight + PADDING_V * 2;
3362
+ const rectWidth = Math.max(cellWidth - MARGIN_H * 2, 1);
3363
+ const { paddingTop } = calcPadding(rectWidth, cellHeight, fontWidth, rectHeight, vt, ht);
3364
+ ctx.translateWithPrecision(MARGIN_H, paddingTop);
3365
+ _univerjs_engine_render.Rect.drawWith(ctx, {
3366
+ width: rectWidth,
3367
+ height: rectHeight,
3368
+ fill: activeColor || "#ECECEC",
3369
+ radius: RADIUS_BG
3370
+ });
3371
+ ctx.save();
3372
+ ctx.translateWithPrecision(PADDING_H, PADDING_V);
3373
+ ctx.beginPath();
3374
+ ctx.rect(0, 0, realWidth, fontHeight);
3375
+ ctx.clip();
3376
+ _univerjs_engine_render.Text.drawWith(ctx, {
3377
+ text: valueStr,
3378
+ fontStyle,
3379
+ width: realWidth,
3380
+ height: fontHeight,
3381
+ color: style === null || style === void 0 || (_style$cl2 = style.cl) === null || _style$cl2 === void 0 ? void 0 : _style$cl2.rgb,
3382
+ strokeLine: Boolean(style === null || style === void 0 || (_style$st2 = style.st) === null || _style$st2 === void 0 ? void 0 : _style$st2.s),
3383
+ underline: Boolean(style === null || style === void 0 || (_style$ul2 = style.ul) === null || _style$ul2 === void 0 ? void 0 : _style$ul2.s),
3384
+ warp: tb === _univerjs_core.WrapStrategy.WRAP,
3385
+ hAlign: _univerjs_core.HorizontalAlign.LEFT
3386
+ }, textSkeleton);
3387
+ ctx.restore();
3388
+ ctx.translateWithPrecision(realWidth + PADDING_H + 4, (fontHeight - ICON_SIZE) / 2);
3389
+ ctx.fillStyle = DROP_DOWN_ICON_COLOR;
3390
+ ctx.fill(downPath);
3391
+ ctx.restore();
3392
+ map.set(key, {
3393
+ left: cellBounding.startX + MARGIN_H + skeleton.rowHeaderWidth,
3394
+ top: cellBounding.startY + paddingTop + skeleton.columnHeaderHeight,
3395
+ width: rectWidth,
3396
+ height: rectHeight
3397
+ });
3398
+ }
3399
+ }
3400
+ calcCellAutoHeight(info) {
3401
+ var _tb2;
3402
+ const { primaryWithCoord, style, data, row, col } = info;
3403
+ const _cellBounding = primaryWithCoord.isMergedMainCell ? primaryWithCoord.mergeInfo : primaryWithCoord;
3404
+ const { leftOffset = 0, rightOffset = 0, topOffset = 0, downOffset = 0 } = (data === null || data === void 0 ? void 0 : data.fontRenderExtension) || {};
3405
+ const rule = this._dataValidationModel.getRuleByLocation(info.unitId, info.subUnitId, row, col);
3406
+ if (!rule) return;
3407
+ if (rule.renderMode === _univerjs_core.DataValidationRenderMode.TEXT) return;
3408
+ const cellBounding = {
3409
+ startX: _cellBounding.startX + leftOffset,
3410
+ endX: _cellBounding.endX - rightOffset,
3411
+ startY: _cellBounding.startY + topOffset,
3412
+ endY: _cellBounding.endY - downOffset
3413
+ };
3414
+ const cellWidth = cellBounding.endX - cellBounding.startX;
3415
+ const value = (0, _univerjs_sheets_data_validation.getCellValueOrigin)(data);
3416
+ const valueStr = `${value !== null && value !== void 0 ? value : ""}`;
3417
+ let { tb, pd } = style || {};
3418
+ const { t = _univerjs_core.DEFAULT_STYLES.pd.t, b = _univerjs_core.DEFAULT_STYLES.pd.b } = pd !== null && pd !== void 0 ? pd : {};
3419
+ tb = (_tb2 = tb) !== null && _tb2 !== void 0 ? _tb2 : _univerjs_core.WrapStrategy.WRAP;
3420
+ if (rule.renderMode === _univerjs_core.DataValidationRenderMode.ARROW) {
3421
+ const { l = _univerjs_core.DEFAULT_STYLES.pd.l, r = _univerjs_core.DEFAULT_STYLES.pd.r } = pd !== null && pd !== void 0 ? pd : {};
3422
+ const realWidth = cellWidth - l - r - ICON_PLACE - 4;
3423
+ const skeleton = new _univerjs_engine_render.DocSimpleSkeleton(valueStr, (0, _univerjs_engine_render.getFontStyleString)(style).fontCache, Boolean(tb === _univerjs_core.WrapStrategy.WRAP), realWidth, Infinity);
3424
+ skeleton.calculate();
3425
+ return skeleton.getTotalHeight() + t + b + MARGIN_V * 2;
3426
+ } else {
3427
+ const realWidth = Math.max(cellWidth - MARGIN_H * 2 - PADDING_H - ICON_PLACE - 4, 10);
3428
+ const skeleton = new _univerjs_engine_render.DocSimpleSkeleton(valueStr, (0, _univerjs_engine_render.getFontStyleString)(style).fontCache, Boolean(tb === _univerjs_core.WrapStrategy.WRAP), realWidth, Infinity);
3429
+ skeleton.calculate();
3430
+ return skeleton.getTotalHeight() + MARGIN_V * 2 + PADDING_V * 2;
3431
+ }
3432
+ }
3433
+ calcCellAutoWidth(info) {
3434
+ var _tb3;
3435
+ const { primaryWithCoord, style, data, row, col } = info;
3436
+ const cellRange = primaryWithCoord.isMergedMainCell ? primaryWithCoord.mergeInfo : primaryWithCoord;
3437
+ const { leftOffset = 0, rightOffset = 0, topOffset = 0, downOffset = 0 } = (data === null || data === void 0 ? void 0 : data.fontRenderExtension) || {};
3438
+ const rule = this._dataValidationModel.getRuleByLocation(info.unitId, info.subUnitId, row, col);
3439
+ if (!rule) return;
3440
+ if (rule.renderMode === _univerjs_core.DataValidationRenderMode.TEXT) return;
3441
+ const cellBounding = {
3442
+ startX: cellRange.startX + leftOffset,
3443
+ endX: cellRange.endX - rightOffset,
3444
+ startY: cellRange.startY + topOffset,
3445
+ endY: cellRange.endY - downOffset
3446
+ };
3447
+ const cellWidth = cellBounding.endX - cellBounding.startX;
3448
+ const value = (0, _univerjs_sheets_data_validation.getCellValueOrigin)(data);
3449
+ const valueStr = `${value !== null && value !== void 0 ? value : ""}`;
3450
+ let { tb, pd } = style || {};
3451
+ const { l = _univerjs_core.DEFAULT_STYLES.pd.l, r = _univerjs_core.DEFAULT_STYLES.pd.r } = pd !== null && pd !== void 0 ? pd : {};
3452
+ tb = (_tb3 = tb) !== null && _tb3 !== void 0 ? _tb3 : _univerjs_core.WrapStrategy.WRAP;
3453
+ let paddingAll = MARGIN_H * 2 + ICON_PLACE;
3454
+ switch (rule.renderMode) {
3455
+ case _univerjs_core.DataValidationRenderMode.ARROW:
3456
+ paddingAll = ICON_PLACE + 4 + r + l;
3457
+ break;
3458
+ case _univerjs_core.DataValidationRenderMode.CUSTOM:
3459
+ paddingAll = ICON_PLACE + MARGIN_H * 2 + PADDING_H * 2 + r + l + RADIUS_BG / 2 + 1;
3460
+ break;
3461
+ default: paddingAll = ICON_PLACE + MARGIN_H * 2 + PADDING_H * 2 + r + l + RADIUS_BG / 2 + 1;
3462
+ }
3463
+ const widthForTextLayout = cellWidth - paddingAll;
3464
+ const skeleton = new _univerjs_engine_render.DocSimpleSkeleton(valueStr, (0, _univerjs_engine_render.getFontStyleString)(style).fontCache, Boolean(tb === _univerjs_core.WrapStrategy.WRAP), widthForTextLayout, Infinity);
3465
+ skeleton.calculate();
3466
+ return skeleton.getTotalWidth() + paddingAll;
3467
+ }
3468
+ isHit(position, info) {
3469
+ const { subUnitId, row, col } = info;
3470
+ const dropdownInfo = this._ensureMap(subUnitId).get(this._generateKey(row, col));
3471
+ const rule = this._dataValidationModel.getRuleByLocation(info.unitId, info.subUnitId, row, col);
3472
+ if (!rule) return false;
3473
+ if (!dropdownInfo) return false;
3474
+ if (rule.renderMode === _univerjs_core.DataValidationRenderMode.TEXT) return false;
3475
+ const { top, left, width, height } = dropdownInfo;
3476
+ const { x, y } = position;
3477
+ if (x >= left && x <= left + width && y >= top && y <= top + height) return true;
3478
+ return false;
3479
+ }
3480
+ onPointerDown(info, evt) {
3481
+ if (evt.button === 2) return;
3482
+ const { unitId, subUnitId, row, col } = info;
3483
+ const params = {
3484
+ unitId,
3485
+ subUnitId,
3486
+ row,
3487
+ column: col
3488
+ };
3489
+ this._commandService.executeCommand(ShowDataValidationDropdown.id, params);
3490
+ }
3491
+ onPointerEnter(_info, _evt) {
3492
+ var _getCurrentTypeOfRend;
3493
+ (_getCurrentTypeOfRend = (0, _univerjs_engine_render.getCurrentTypeOfRenderer)(_univerjs_core.UniverInstanceType.UNIVER_SHEET, this._univerInstanceService, this._renderManagerService)) === null || _getCurrentTypeOfRend === void 0 || (_getCurrentTypeOfRend = _getCurrentTypeOfRend.mainComponent) === null || _getCurrentTypeOfRend === void 0 || _getCurrentTypeOfRend.setCursor(_univerjs_engine_render.CURSOR_TYPE.POINTER);
3494
+ }
3495
+ onPointerLeave(_info, _evt) {
3496
+ var _getCurrentTypeOfRend2;
3497
+ (_getCurrentTypeOfRend2 = (0, _univerjs_engine_render.getCurrentTypeOfRenderer)(_univerjs_core.UniverInstanceType.UNIVER_SHEET, this._univerInstanceService, this._renderManagerService)) === null || _getCurrentTypeOfRend2 === void 0 || (_getCurrentTypeOfRend2 = _getCurrentTypeOfRend2.mainComponent) === null || _getCurrentTypeOfRend2 === void 0 || _getCurrentTypeOfRend2.setCursor(_univerjs_engine_render.CURSOR_TYPE.DEFAULT);
3498
+ }
3499
+ };
3500
+ DropdownWidget = __decorate([
3501
+ __decorateParam(0, _univerjs_core.IUniverInstanceService),
3502
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
3503
+ __decorateParam(2, _univerjs_core.ICommandService),
3504
+ __decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_engine_render.IRenderManagerService)),
3505
+ __decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets_data_validation.SheetDataValidationModel))
3506
+ ], DropdownWidget);
3507
+
3508
+ //#endregion
3509
+ //#region src/views/validator-views/list-validator-view.ts
3510
+ var ListValidatorView = class extends BaseSheetDataValidatorView {
3511
+ constructor(..._args) {
3512
+ super(..._args);
3513
+ _defineProperty(this, "id", _univerjs_core.DataValidationType.LIST);
3514
+ _defineProperty(this, "canvasRender", this.injector.createInstance(DropdownWidget));
3515
+ _defineProperty(this, "dropdownType", _univerjs_data_validation.DataValidatorDropdownType.LIST);
3516
+ _defineProperty(this, "optionsInput", ListRenderModeInput.componentKey);
3517
+ _defineProperty(this, "formulaInput", _univerjs_sheets_data_validation.LIST_FORMULA_INPUT_NAME);
3518
+ }
3519
+ };
3520
+
3521
+ //#endregion
3522
+ //#region src/views/validator-views/text-length-validator.view.ts
3523
+ /**
3524
+ * Copyright 2023-present DreamNum Co., Ltd.
3525
+ *
3526
+ * Licensed under the Apache License, Version 2.0 (the "License");
3527
+ * you may not use this file except in compliance with the License.
3528
+ * You may obtain a copy of the License at
3529
+ *
3530
+ * http://www.apache.org/licenses/LICENSE-2.0
3531
+ *
3532
+ * Unless required by applicable law or agreed to in writing, software
3533
+ * distributed under the License is distributed on an "AS IS" BASIS,
3534
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3535
+ * See the License for the specific language governing permissions and
3536
+ * limitations under the License.
3537
+ */
3538
+ var TextLengthValidatorView = class extends BaseSheetDataValidatorView {
3539
+ constructor(..._args) {
3540
+ super(..._args);
3541
+ _defineProperty(this, "id", _univerjs_core.DataValidationType.TEXT_LENGTH);
3542
+ _defineProperty(this, "formulaInput", _univerjs_sheets_data_validation.BASE_FORMULA_INPUT_NAME);
3543
+ }
3544
+ };
3545
+
3546
+ //#endregion
3547
+ //#region src/views/validator-views/whole-validator-view.ts
3548
+ /**
3549
+ * Copyright 2023-present DreamNum Co., Ltd.
3550
+ *
3551
+ * Licensed under the Apache License, Version 2.0 (the "License");
3552
+ * you may not use this file except in compliance with the License.
3553
+ * You may obtain a copy of the License at
3554
+ *
3555
+ * http://www.apache.org/licenses/LICENSE-2.0
3556
+ *
3557
+ * Unless required by applicable law or agreed to in writing, software
3558
+ * distributed under the License is distributed on an "AS IS" BASIS,
3559
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3560
+ * See the License for the specific language governing permissions and
3561
+ * limitations under the License.
3562
+ */
3563
+ var WholeValidatorView = class extends BaseSheetDataValidatorView {
3564
+ constructor(..._args) {
3565
+ super(..._args);
3566
+ _defineProperty(this, "id", _univerjs_core.DataValidationType.WHOLE);
3567
+ _defineProperty(this, "formulaInput", _univerjs_sheets_data_validation.BASE_FORMULA_INPUT_NAME);
3568
+ }
3569
+ };
3570
+
3571
+ //#endregion
3572
+ //#region src/controllers/dv-ui.controller.ts
3573
+ let SheetsDataValidationUIController = class SheetsDataValidationUIController extends _univerjs_core.RxDisposable {
3574
+ constructor(_injector, _componentManger, _dataValidatorRegistryService) {
3575
+ super();
3576
+ this._injector = _injector;
3577
+ this._componentManger = _componentManger;
3578
+ this._dataValidatorRegistryService = _dataValidatorRegistryService;
3579
+ this._initComponents();
3580
+ this._registerValidatorViews();
3581
+ }
3582
+ _initComponents() {
3583
+ [
3584
+ ["DataValidationIcon", _univerjs_icons.DataValidationIcon],
3585
+ [DATA_VALIDATION_PANEL, DataValidationPanel],
3586
+ [ListRenderModeInput.componentKey, ListRenderModeInput],
3587
+ [DateShowTimeOption.componentKey, DateShowTimeOption],
3588
+ ...FORMULA_INPUTS
3589
+ ].forEach(([key, comp]) => {
3590
+ this.disposeWithMe(this._componentManger.register(key, comp));
3591
+ });
3592
+ }
3593
+ _registerValidatorViews() {
3594
+ [
3595
+ DecimalValidatorView,
3596
+ WholeValidatorView,
3597
+ TextLengthValidatorView,
3598
+ DateValidatorView,
3599
+ CheckboxValidatorView,
3600
+ ListValidatorView,
3601
+ ListMultipleValidatorView,
3602
+ CustomFormulaValidatorView
3603
+ ].forEach((v) => {
3604
+ const view = this._injector.createInstance(v);
3605
+ const validator = this._dataValidatorRegistryService.getValidatorItem(view.id);
3606
+ if (validator) {
3607
+ validator.formulaInput = view.formulaInput;
3608
+ validator.canvasRender = view.canvasRender;
3609
+ validator.dropdownType = view.dropdownType;
3610
+ validator.optionsInput = view.optionsInput;
3611
+ }
3612
+ });
3613
+ }
3614
+ };
3615
+ SheetsDataValidationUIController = __decorate([
3616
+ __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
3617
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)),
3618
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_data_validation.DataValidatorRegistryService))
3619
+ ], SheetsDataValidationUIController);
3620
+
3621
+ //#endregion
3622
+ //#region src/mobile-plugin.ts
3623
+ let UniverSheetsDataValidationMobileUIPlugin = class UniverSheetsDataValidationMobileUIPlugin extends _univerjs_core.Plugin {
3624
+ constructor(_config = defaultPluginConfig, _injector, _commandService, _configService) {
3625
+ super();
3626
+ this._config = _config;
3627
+ this._injector = _injector;
3628
+ this._commandService = _commandService;
3629
+ this._configService = _configService;
3630
+ const { menu, ...rest } = (0, _univerjs_core.merge)({}, defaultPluginConfig, this._config);
3631
+ if (menu) this._configService.setConfig("menu", menu, { merge: true });
3632
+ this._configService.setConfig(SHEETS_DATA_VALIDATION_UI_PLUGIN_CONFIG_KEY, rest);
3633
+ }
3634
+ onStarting() {
3635
+ [
3636
+ [DataValidationPanelService],
3637
+ [DataValidationDropdownManagerService],
3638
+ [DataValidationAlertController],
3639
+ [DataValidationAutoFillController],
3640
+ [SheetsDataValidationRenderController],
3641
+ [DataValidationPermissionController],
3642
+ [DataValidationCopyPasteController],
3643
+ [SheetsDataValidationUIController]
3644
+ ].forEach((dep) => {
3645
+ this._injector.add(dep);
3646
+ });
3647
+ [
3648
+ AddSheetDataValidationAndOpenCommand,
3649
+ ShowDataValidationDropdown,
3650
+ HideDataValidationDropdown,
3651
+ CloseValidationPanelOperation,
3652
+ OpenValidationPanelOperation,
3653
+ ToggleValidationPanelOperation
3654
+ ].forEach((command) => {
3655
+ this._commandService.registerCommand(command);
3656
+ });
3657
+ }
3658
+ onReady() {
3659
+ this._injector.get(DataValidationCopyPasteController);
3660
+ this._injector.get(DataValidationPermissionController);
3661
+ this._injector.get(_univerjs_engine_render.IRenderManagerService).registerRenderModule(_univerjs_core.UniverInstanceType.UNIVER_SHEET, [SheetsDataValidationReRenderController]);
3662
+ }
3663
+ onRendered() {
3664
+ this._injector.get(SheetsDataValidationUIController);
3665
+ this._injector.get(SheetsDataValidationRenderController);
3666
+ }
3667
+ onSteady() {
3668
+ this._injector.get(DataValidationAutoFillController);
3669
+ }
3670
+ };
3671
+ _defineProperty(UniverSheetsDataValidationMobileUIPlugin, "pluginName", "SHEET_DATA_VALIDATION_UI_PLUGIN");
3672
+ _defineProperty(UniverSheetsDataValidationMobileUIPlugin, "packageName", name);
3673
+ _defineProperty(UniverSheetsDataValidationMobileUIPlugin, "version", version);
3674
+ _defineProperty(UniverSheetsDataValidationMobileUIPlugin, "type", _univerjs_core.UniverInstanceType.UNIVER_SHEET);
3675
+ UniverSheetsDataValidationMobileUIPlugin = __decorate([
3676
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
3677
+ __decorateParam(2, _univerjs_core.ICommandService),
3678
+ __decorateParam(3, _univerjs_core.IConfigService)
3679
+ ], UniverSheetsDataValidationMobileUIPlugin);
3680
+
3681
+ //#endregion
3682
+ //#region src/plugin.ts
3683
+ let UniverSheetsDataValidationUIPlugin = class UniverSheetsDataValidationUIPlugin extends _univerjs_core.Plugin {
3684
+ constructor(_config = defaultPluginConfig, _injector, _commandService, _configService) {
3685
+ super();
3686
+ this._config = _config;
3687
+ this._injector = _injector;
3688
+ this._commandService = _commandService;
3689
+ this._configService = _configService;
3690
+ const { menu, ...rest } = (0, _univerjs_core.merge)({}, defaultPluginConfig, this._config);
3691
+ if (menu) this._configService.setConfig("menu", menu, { merge: true });
3692
+ this._configService.setConfig(SHEETS_DATA_VALIDATION_UI_PLUGIN_CONFIG_KEY, rest);
3693
+ }
3694
+ onStarting() {
3695
+ [
3696
+ [DataValidationPanelService],
3697
+ [DataValidationDropdownManagerService],
3698
+ [DataValidationAlertController],
3699
+ [DataValidationAutoFillController],
3700
+ [SheetsDataValidationRenderController],
3701
+ [DataValidationPermissionController],
3702
+ [DataValidationCopyPasteController],
3703
+ [DataValidationRejectInputController],
3704
+ [SheetsDataValidationUIController]
3705
+ ].forEach((dep) => {
3706
+ this._injector.add(dep);
3707
+ });
3708
+ [
3709
+ AddSheetDataValidationAndOpenCommand,
3710
+ ShowDataValidationDropdown,
3711
+ HideDataValidationDropdown,
3712
+ CloseValidationPanelOperation,
3713
+ OpenValidationPanelOperation,
3714
+ ToggleValidationPanelOperation
3715
+ ].forEach((command) => {
3716
+ this._commandService.registerCommand(command);
3717
+ });
3718
+ }
3719
+ onReady() {
3720
+ this._injector.get(DataValidationCopyPasteController);
3721
+ this._injector.get(DataValidationPermissionController);
3722
+ this._injector.get(DataValidationRejectInputController);
3723
+ this._injector.get(DataValidationAlertController);
3724
+ this._injector.get(_univerjs_engine_render.IRenderManagerService).registerRenderModule(_univerjs_core.UniverInstanceType.UNIVER_SHEET, [SheetsDataValidationReRenderController]);
3725
+ }
3726
+ onRendered() {
3727
+ this._injector.get(SheetsDataValidationUIController);
3728
+ this._injector.get(SheetsDataValidationRenderController);
3729
+ }
3730
+ onSteady() {
3731
+ this._injector.get(DataValidationAutoFillController);
3732
+ }
3733
+ };
3734
+ _defineProperty(UniverSheetsDataValidationUIPlugin, "pluginName", "SHEET_DATA_VALIDATION_UI_PLUGIN");
3735
+ _defineProperty(UniverSheetsDataValidationUIPlugin, "packageName", name);
3736
+ _defineProperty(UniverSheetsDataValidationUIPlugin, "version", version);
3737
+ _defineProperty(UniverSheetsDataValidationUIPlugin, "type", _univerjs_core.UniverInstanceType.UNIVER_SHEET);
3738
+ UniverSheetsDataValidationUIPlugin = __decorate([
3739
+ (0, _univerjs_core.DependentOn)(_univerjs_sheets_data_validation.UniverSheetsDataValidationPlugin),
3740
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
3741
+ __decorateParam(2, _univerjs_core.ICommandService),
3742
+ __decorateParam(3, _univerjs_core.IConfigService)
3743
+ ], UniverSheetsDataValidationUIPlugin);
3744
+
3745
+ //#endregion
3746
+ Object.defineProperty(exports, 'BaseSheetDataValidatorView', {
3747
+ enumerable: true,
3748
+ get: function () {
3749
+ return BaseSheetDataValidatorView;
3750
+ }
3751
+ });
3752
+ Object.defineProperty(exports, 'UniverSheetsDataValidationMobileUIPlugin', {
3753
+ enumerable: true,
3754
+ get: function () {
3755
+ return UniverSheetsDataValidationMobileUIPlugin;
3756
+ }
3757
+ });
3758
+ Object.defineProperty(exports, 'UniverSheetsDataValidationUIPlugin', {
3759
+ enumerable: true,
3760
+ get: function () {
3761
+ return UniverSheetsDataValidationUIPlugin;
3762
+ }
3763
+ });