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