@univerjs/sheets-data-validation-ui 0.7.0-nightly.202505091607 → 0.7.0-nightly.202505111606
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +4 -5
- package/lib/es/index.js +361 -362
- package/lib/index.css +1 -1
- package/lib/index.js +361 -362
- package/lib/umd/index.js +4 -5
- package/package.json +12 -12
package/lib/cjs/index.js
CHANGED
@@ -30,16 +30,15 @@
|
|
30
30
|
hover:univer-bg-primary-600/5
|
31
31
|
`,onClick:re,children:[p.jsx(yt,{className:"univer-mr-1"}),M.t("dataValidation.list.add")]})]})})]})}const en=[[_.CUSTOM_FORMULA_INPUT_NAME,kt],[_.BASE_FORMULA_INPUT_NAME,Ft],[_.LIST_FORMULA_INPUT_NAME,Qt],[_.CHECKBOX_FORMULA_INPUT_NAME,Nt]];var tn=Object.getOwnPropertyDescriptor,nn=(e,t,a,n)=>{for(var r=n>1?void 0:n?tn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},an=(e,t)=>(a,n)=>t(a,n,e);exports.BaseSheetDataValidatorView=class{constructor(t){O(this,"canvasRender",null);O(this,"dropdownType");O(this,"optionsInput");O(this,"formulaInput",_.LIST_FORMULA_INPUT_NAME);this.injector=t}};exports.BaseSheetDataValidatorView=nn([an(0,o.Inject(o.Injector))],exports.BaseSheetDataValidatorView);var rn=Object.getOwnPropertyDescriptor,on=(e,t,a,n)=>{for(var r=n>1?void 0:n?rn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},vt=(e,t)=>(a,n)=>t(a,n,e);let ue=class extends o.Disposable{constructor(t,a){super();O(this,"_open$",new ae.BehaviorSubject(!1));O(this,"open$",this._open$.pipe(ae.distinctUntilChanged()));O(this,"_activeRule");O(this,"_activeRule$",new ae.BehaviorSubject(void 0));O(this,"activeRule$",this._activeRule$.asObservable());O(this,"_closeDisposable",null);this._univerInstanceService=t,this._sidebarService=a,this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_SHEET).pipe(ae.filter(n=>!n)).subscribe(()=>{this.close()})),this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe(n=>{n.id===ke&&(n.visible||setTimeout(()=>{this._sidebarService.sidebarOptions$.next({visible:!1})}))}))}get activeRule(){return this._activeRule}get isOpen(){return this._open$.getValue()}dispose(){var t;super.dispose(),this._open$.next(!1),this._open$.complete(),this._activeRule$.complete(),(t=this._closeDisposable)==null||t.dispose()}open(){this._open$.next(!0)}close(){var t;this._open$.next(!1),(t=this._closeDisposable)==null||t.dispose()}setCloseDisposable(t){this._closeDisposable=o.toDisposable(()=>{t.dispose(),this._closeDisposable=null})}setActiveRule(t){this._activeRule=t,this._activeRule$.next(t)}};ue=on([vt(0,o.IUniverInstanceService),vt(1,w.ISidebarService)],ue);const ut="sheets-data-validation-ui.config",Ne={};var sn=Object.getOwnPropertyDescriptor,ln=(e,t,a,n)=>{for(var r=n>1?void 0:n?sn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},Ie=(e,t)=>(a,n)=>t(a,n,e);let Ve=class extends o.Disposable{constructor(e,t,a,n,r,i){super(),this._sheetInterceptorService=e,this._dataValidationModel=t,this._dataValidatorRegistryService=a,this._dialogService=n,this._localeService=r,this._sheetsDataValidationValidatorService=i,this._initEditorBridgeInterceptor()}_initEditorBridgeInterceptor(){this._sheetInterceptorService.writeCellInterceptor.intercept(W.VALIDATE_CELL,{handler:async(e,t,a)=>{const n=await e,{row:r,col:i,unitId:s,subUnitId:c}=t,l=this._dataValidationModel.getRuleIdByLocation(s,c,r,i),d=l?this._dataValidationModel.getRuleById(s,c,l):void 0;if(n===!1)return a(Promise.resolve(!1));if(!d||d.errorStyle!==o.DataValidationErrorStyle.STOP)return a(Promise.resolve(!0));const h=this._dataValidatorRegistryService.getValidatorItem(d.type);return!h||await this._sheetsDataValidationValidatorService.validatorCell(s,c,r,i)===o.DataValidationStatus.VALID?a(Promise.resolve(!0)):(this._dialogService.open({width:368,title:{title:this._localeService.t("dataValidation.alert.title")},id:"reject-input-dialog",children:{title:h.getRuleFinalError(d,{row:r,col:i,unitId:s,subUnitId:c})},footer:{title:b.createElement(E.Button,{variant:"primary",onClick:()=>this._dialogService.close("reject-input-dialog")},this._localeService.t("dataValidation.alert.ok"))},onClose:()=>{this._dialogService.close("reject-input-dialog")}}),a(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:b.createElement(E.Button,{variant:"primary",onClick:()=>this._dialogService.close("reject-input-dialog")},this._localeService.t("dataValidation.alert.ok"))},onClose:()=>{this._dialogService.close("reject-input-dialog")}})}};Ve=ln([Ie(0,o.Inject(W.SheetInterceptorService)),Ie(1,o.Inject(_.SheetDataValidationModel)),Ie(2,o.Inject($.DataValidatorRegistryService)),Ie(3,w.IDialogService),Ie(4,o.Inject(o.LocaleService)),Ie(5,o.Inject(_.SheetsDataValidationValidatorService))],Ve);var cn=Object.getOwnPropertyDescriptor,dn=(e,t,a,n)=>{for(var r=n>1?void 0:n?cn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},oe=(e,t)=>(a,n)=>t(a,n,e);const ze=e=>{if(e==null||typeof e=="boolean")return;if(typeof e=="number"||!Number.isNaN(+e))return o.dayjs(o.numfmt.format("yyyy-MM-dd HH:mm:ss",Number(e)));const t=o.dayjs(e);if(t.isValid())return t};function un(e,t){const a=Ut.getPatternType(t);if(e===a)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 fe=class extends o.Disposable{constructor(t,a,n,r,i,s,c,l,d,h,g){super();O(this,"_activeDropdown");O(this,"_activeDropdown$",new ae.Subject);O(this,"_currentPopup",null);O(this,"activeDropdown$",this._activeDropdown$.asObservable());O(this,"_zenVisible",!1);this._univerInstanceService=t,this._dataValidatorRegistryService=a,this._zenZoneService=n,this._dataValidationModel=r,this._sheetsSelectionsService=i,this._cellDropdownManagerService=s,this._sheetDataValidationModel=c,this._commandService=l,this._editorBridgeService=d,this._injector=h,this._configService=g,this._init(),this._initSelectionChange(),this.disposeWithMe(()=>{this._activeDropdown$.complete()})}get activeDropdown(){return this._activeDropdown}_init(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(t=>{this._zenVisible=t,t&&this.hideDropdown()}))}_getDropdownByCell(t,a,n,r){const i=t?this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!i)return;const s=a?i.getSheetBySheetId(a):i.getActiveSheet();if(!s)return;const c=this._dataValidationModel.getRuleByLocation(i.getUnitId(),s.getSheetId(),n,r);if(!c)return;const l=this._dataValidatorRegistryService.getValidatorItem(c.type);return l==null?void 0:l.dropdownType}_initSelectionChange(){this.disposeWithMe(this._sheetsSelectionsService.selectionMoveEnd$.subscribe(t=>{t&&t.every(a=>!(a.primary&&this._getDropdownByCell(a.primary.unitId,a.primary.sheetId,a.primary.actualRow,a.primary.actualColumn)))&&this.hideDropdown()}))}showDropdown(t){var T,M,m,C;const{location:a}=t,{row:n,col:r,unitId:i,subUnitId:s,workbook:c,worksheet:l}=a;if(this._currentPopup&&this._currentPopup.dispose(),this._zenVisible)return;this._activeDropdown=t,this._activeDropdown$.next(this._activeDropdown);const d=this._sheetDataValidationModel.getRuleByLocation(i,s,n,r);if(!d)return;const h=this._dataValidatorRegistryService.getValidatorItem(d.type);if(!(h!=null&&h.dropdownType))return;let g;const u=async(f,y)=>{var F,N,A;if(!f)return!0;const R=f,D=l.getCell(n,r),V=R.format(y==="date"?"YYYY-MM-DD 00:00:00":"YYYY-MM-DD HH:mm:ss"),x=(F=o.numfmt.parseDate(V))==null?void 0:F.v,H=y==="time"?x%1:x,P=c.getStyles().getStyleByCell(D),U=(A=(N=P==null?void 0:P.n)==null?void 0:N.pattern)!=null?A:"";return d.errorStyle!==o.DataValidationErrorStyle.STOP||await h.validator({value:H,unitId:i,subUnitId:s,row:n,column:r,worksheet:l,workbook:c,interceptValue:V.replace("Z","").replace("T"," "),t:o.CellValueType.NUMBER},d)?(await this._commandService.executeCommand(B.SetCellEditVisibleOperation.id,{visible:!1,eventType:L.DeviceInputEventType.Keyboard,unitId:i,keycode:w.KeyCode.ESC}),await this._commandService.executeCommand(W.SetRangeValuesCommand.id,{unitId:i,subUnitId:s,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:H,t:2,p:null,f:null,si:null,s:{n:{pattern:un(y,U)}}}}),!0):(this._injector.has(Ve)&&this._injector.get(Ve).showReject(h.getRuleFinalError(d,{row:n,col:r,unitId:i,subUnitId:s})),!1)};let S;switch(h.dropdownType){case $.DataValidatorDropdownType.DATE:{const f=_.getCellValueOrigin(l.getCellRaw(n,r)),y=ze(f),R=!!((T=d.bizInfo)!=null&&T.showTime);S={location:a,type:"datepicker",props:{showTime:R,onChange:D=>u(D,R?"datetime":"date"),defaultValue:y,patternType:"date"}};break}case $.DataValidatorDropdownType.TIME:{const f=_.getCellValueOrigin(l.getCellRaw(n,r)),y=ze(f);S={location:a,type:"datepicker",props:{onChange:R=>u(R,"time"),defaultValue:y,patternType:"time"}};break}case $.DataValidatorDropdownType.DATETIME:{const f=_.getCellValueOrigin(l.getCellRaw(n,r)),y=ze(f);S={location:a,type:"datepicker",props:{onChange:R=>u(R,"datetime"),defaultValue:y,patternType:"datetime"}};break}case $.DataValidatorDropdownType.LIST:case $.DataValidatorDropdownType.MULTIPLE_LIST:{const f=h.dropdownType===$.DataValidatorDropdownType.MULTIPLE_LIST,y=async P=>{const U=_.serializeListOptions(P),F={unitId:i,subUnitId:s,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:U,p:null,f:null,si:null}};return this._editorBridgeService.isVisible().visible&&await this._commandService.executeCommand(B.SetCellEditVisibleOperation.id,{visible:!1,eventType:L.DeviceInputEventType.Keyboard,unitId:i,keycode:w.KeyCode.ESC}),this._commandService.executeCommand(W.SetRangeValuesCommand.id,F),!f},R=(d==null?void 0:d.renderMode)===o.DataValidationRenderMode.CUSTOM||(d==null?void 0:d.renderMode)===void 0,D=h.getListWithColor(d,i,s),V=_.getDataValidationCellValue(l.getCellRaw(n,r)),x=()=>{this._commandService.executeCommand(_e.id,{ruleId:d.uid}),g==null||g.dispose()},H=D.map(P=>({label:P.label,value:P.label,color:R||P.color?P.color:"transparent"}));S={location:a,type:"list",props:{onChange:P=>y(P),options:H,onEdit:x,defaultValue:V,multiple:f,showEdit:(m=(M=this._configService.getConfig(ut))==null?void 0:M.showEditOnDropdown)!=null?m:!0}};break}case $.DataValidatorDropdownType.CASCADE:{S={type:"cascader",props:{onChange:y=>{const R={unitId:i,subUnitId:s,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:y.join("/"),p:null,f:null,si:null}};return this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(B.SetCellEditVisibleOperation.id,{visible:!1,eventType:L.DeviceInputEventType.Keyboard,unitId:i,keycode:w.KeyCode.ESC}),this._commandService.syncExecuteCommand(W.SetRangeValuesCommand.id,R),!0},defaultValue:_.getDataValidationCellValue(l.getCellRaw(n,r)).split("/"),options:JSON.parse((C=d.formula1)!=null?C:"[]")},location:a};break}case $.DataValidatorDropdownType.COLOR:{S={type:"color",props:{onChange:y=>{const R={unitId:i,subUnitId:s,range:{startColumn:r,endColumn:r,startRow:n,endRow:n},value:{v:y,p:null,f:null,si:null}};return this._editorBridgeService.isVisible().visible&&this._commandService.syncExecuteCommand(B.SetCellEditVisibleOperation.id,{visible:!1,eventType:L.DeviceInputEventType.Keyboard,unitId:i,keycode:w.KeyCode.ESC}),this._commandService.syncExecuteCommand(W.SetRangeValuesCommand.id,R),!0},defaultValue:_.getDataValidationCellValue(l.getCellRaw(n,r))},location:a};break}default:throw new Error("[DataValidationDropdownManagerService]: unknown type!")}if(g=this._cellDropdownManagerService.showDropdown(S),!g)throw new Error("[DataValidationDropdownManagerService]: cannot show dropdown!");const v=new o.DisposableCollection;v.add(g),v.add({dispose:()=>{var f,y;(y=(f=this._activeDropdown)==null?void 0:f.onHide)==null||y.call(f)}}),this._currentPopup=v}hideDropdown(){this._activeDropdown&&(this._currentPopup&&this._currentPopup.dispose(),this._currentPopup=null,this._activeDropdown=null,this._activeDropdown$.next(null))}showDataValidationDropdown(t,a,n,r,i){const s=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!s)return;const c=s.getSheetBySheetId(a);if(!c)return;const l=this._dataValidationModel.getRuleByLocation(s.getUnitId(),c.getSheetId(),n,r);if(!l)return;const d=this._dataValidatorRegistryService.getValidatorItem(l.type);if(!d||!d.dropdownType){this.hideDropdown();return}this.showDropdown({location:{workbook:s,worksheet:c,row:n,col:r,unitId:t,subUnitId:a},onHide:i})}};fe=dn([oe(0,o.IUniverInstanceService),oe(1,o.Inject($.DataValidatorRegistryService)),oe(2,w.IZenZoneService),oe(3,o.Inject(_.SheetDataValidationModel)),oe(4,o.Inject(W.SheetsSelectionsService)),oe(5,o.Inject(B.ISheetCellDropdownManagerService)),oe(6,o.Inject(_.SheetDataValidationModel)),oe(7,o.ICommandService),oe(8,B.IEditorBridgeService),oe(9,o.Inject(o.Injector)),oe(10,o.IConfigService)],fe);const ke="DataValidationPanel",_e={id:"data-validation.operation.open-validation-panel",type:o.CommandType.OPERATION,handler(e,t){if(!t)return!1;const{ruleId:a,isAdd:n}=t,r=e.get(ue),i=e.get($.DataValidationModel),s=e.get(o.IUniverInstanceService),c=e.get(w.ISidebarService),l=W.getSheetCommandTarget(s);if(!l)return!1;const{unitId:d,subUnitId:h}=l,g=a?i.getRuleById(d,h,a):void 0;r.open(),r.setActiveRule(g&&{unitId:d,subUnitId:h,rule:g});const u=c.open({id:ke,header:{title:n?"dataValidation.panel.addTitle":"dataValidation.panel.title"},children:{label:ke},width:312,onClose:()=>r.close()});return r.setCloseDisposable(u),!0}},ht={id:"data-validation.operation.close-validation-panel",type:o.CommandType.OPERATION,handler(e){return e.get(ue).close(),!0}},Vt={id:"data-validation.operation.toggle-validation-panel",type:o.CommandType.OPERATION,handler(e){const t=e.get(o.ICommandService),a=e.get(ue);return a.open(),a.isOpen?t.executeCommand(ht.id):t.executeCommand(_e.id),!0}},Ye={type:o.CommandType.OPERATION,id:"sheet.operation.show-data-validation-dropdown",handler(e,t){if(!t)return!1;const a=e.get(fe),{unitId:n,subUnitId:r,row:i,column:s}=t,c=a.activeDropdown,l=c==null?void 0:c.location;return l&&l.unitId===n&&l.subUnitId===r&&l.row===i&&l.col===s||a.showDataValidationDropdown(n,r,i,s),!0}},wt={type:o.CommandType.OPERATION,id:"sheet.operation.hide-data-validation-dropdown",handler(e,t){return t?(e.get(fe).hideDropdown(),!0):!1}},Xe={type:o.CommandType.COMMAND,id:"data-validation.command.addRuleAndOpen",handler(e){const t=e.get(o.IUniverInstanceService),a=W.getSheetCommandTarget(t);if(!a)return!1;const{workbook:n,worksheet:r}=a,i=_.createDefaultNewRule(e),s=e.get(o.ICommandService),c=n.getUnitId(),l=r.getSheetId(),d={rule:i,unitId:c,subUnitId:l};return s.syncExecuteCommand(_.AddSheetDataValidationCommand.id,d)?(s.syncExecuteCommand(_e.id,{ruleId:i.uid,isAdd:!0}),!0):!1}};var hn=Object.getOwnPropertyDescriptor,gn=(e,t,a,n)=>{for(var r=n>1?void 0:n?hn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},Ce=(e,t)=>(a,n)=>t(a,n,e);const pe="SHEET_DATA_VALIDATION_ALERT";let Pe=class extends o.Disposable{constructor(e,t,a,n,r,i){super(),this._hoverManagerService=e,this._cellAlertManagerService=t,this._univerInstanceService=a,this._localeService=n,this._zenZoneService=r,this._dataValidationModel=i,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(ae.debounceTime(100)).subscribe(e=>{var t;if(e){const a=this._univerInstanceService.getUnit(e.location.unitId,o.UniverInstanceType.UNIVER_SHEET),n=a.getSheetBySheetId(e.location.subUnitId);if(!n)return;const r=this._dataValidationModel.getRuleByLocation(e.location.unitId,e.location.subUnitId,e.location.row,e.location.col);if(!r){this._cellAlertManagerService.removeAlert(pe);return}if(this._dataValidationModel.validator(r,{...e.location,workbook:a,worksheet:n})===o.DataValidationStatus.INVALID){const s=this._cellAlertManagerService.currentAlert.get(pe),c=(t=s==null?void 0:s.alert)==null?void 0:t.location;if(c&&c.row===e.location.row&&c.col===e.location.col&&c.subUnitId===e.location.subUnitId&&c.unitId===e.location.unitId){this._cellAlertManagerService.removeAlert(pe);return}const l=this._dataValidationModel.getValidator(r.type);if(!l){this._cellAlertManagerService.removeAlert(pe);return}this._cellAlertManagerService.showAlert({type:B.CellAlertType.ERROR,title:this._localeService.t("dataValidation.error.title"),message:l==null?void 0:l.getRuleFinalError(r,e.location),location:e.location,width:200,height:74,key:pe});return}}this._cellAlertManagerService.removeAlert(pe)}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._cellAlertManagerService.removeAlert(pe)}))}};Pe=gn([Ce(0,o.Inject(B.HoverManagerService)),Ce(1,o.Inject(B.CellAlertManagerService)),Ce(2,o.IUniverInstanceService),Ce(3,o.Inject(o.LocaleService)),Ce(4,w.IZenZoneService),Ce(5,o.Inject(_.SheetDataValidationModel))],Pe);var pn=Object.getOwnPropertyDescriptor,vn=(e,t,a,n)=>{for(var r=n>1?void 0:n?pn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},Ke=(e,t)=>(a,n)=>t(a,n,e);let we=class extends o.Disposable{constructor(e,t,a){super(),this._autoFillService=e,this._sheetDataValidationModel=t,this._injector=a,this._initAutoFill()}_initAutoFill(){const e=()=>({redos:[],undos:[]}),t=(n,r)=>{const{source:i,target:s,unitId:c,subUnitId:l}=n,d=this._sheetDataValidationModel.getRuleObjectMatrix(c,l).clone(),h=B.virtualizeDiscreteRanges([i,s]),[g,u]=h.ranges,{mapFunc:S}=h,v={row:g.startRow,col:g.startColumn},T=B.getAutoFillRepeatRange(g,u),M=new o.ObjectMatrix,m=new Set;T.forEach(D=>{const V=D.repeatStartCell,x=D.relativeRange,H={startRow:v.row,startColumn:v.col,endColumn:v.col,endRow:v.row},P={startRow:V.row,startColumn:V.col,endColumn:V.col,endRow:V.row};o.Range.foreach(x,(U,F)=>{const N=o.Rectangle.getPositionRange({startRow:U,startColumn:F,endColumn:F,endRow:U},H),{row:A,col:Y}=S(N.startRow,N.startColumn),X=this._sheetDataValidationModel.getRuleIdByLocation(c,l,A,Y)||"",G=o.Rectangle.getPositionRange({startRow:U,startColumn:F,endColumn:F,endRow:U},P),{row:J,col:q}=S(G.startRow,G.startColumn);M.setValue(J,q,X),m.add(X)})});const C=Array.from(m).map(D=>({id:D,ranges:o.queryObjectMatrix(M,V=>V===D)}));d.addRangeRules(C);const f=d.diff(this._sheetDataValidationModel.getRules(c,l)),{redoMutations:y,undoMutations:R}=_.getDataValidationDiffMutations(c,l,f,this._injector,"patched",r===B.APPLY_TYPE.ONLY_FORMAT);return{undos:R,redos:y}},a={id:_.DATA_VALIDATION_PLUGIN_NAME,onBeforeFillData:n=>{const{source:r,unitId:i,subUnitId:s}=n;for(const c of r.rows)for(const l of r.cols){const d=this._sheetDataValidationModel.getRuleByLocation(i,s,c,l);if(d&&d.type===o.DataValidationType.CHECKBOX){this._autoFillService.setDisableApplyType(B.APPLY_TYPE.SERIES,!0);return}}},onFillData:(n,r,i)=>i===B.APPLY_TYPE.COPY||i===B.APPLY_TYPE.ONLY_FORMAT||i===B.APPLY_TYPE.SERIES?t(n,i):e(),onAfterFillData:()=>{}};this.disposeWithMe(this._autoFillService.addHook(a))}};we=vn([Ke(0,B.IAutoFillService),Ke(1,o.Inject(_.SheetDataValidationModel)),Ke(2,o.Inject(o.Injector))],we);var mn=Object.getOwnPropertyDescriptor,fn=(e,t,a,n)=>{for(var r=n>1?void 0:n?mn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},Ge=(e,t)=>(a,n)=>t(a,n,e);let Ee=class extends o.Disposable{constructor(t,a,n){super();O(this,"_copyInfo");this._sheetClipboardService=t,this._sheetDataValidationModel=a,this._injector=n,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:_.DATA_VALIDATION_PLUGIN_NAME,onBeforeCopy:(t,a,n)=>this._collect(t,a,n),onPasteCells:(t,a,n,r)=>{const{copyType:i=B.COPY_TYPE.COPY,pasteType:s}=r,{range:c}=t||{},{range:l,unitId:d,subUnitId:h}=a;return this._generateMutations(l,{copyType:i,pasteType:s,copyRange:c,unitId:d,subUnitId:h})}})}_collect(t,a,n){const r=new o.ObjectMatrix;this._copyInfo={unitId:t,subUnitId:a,matrix:r};const i=this._injector.invoke(l=>W.rangeToDiscreteRange(n,l,t,a));if(!i)return;const{rows:s,cols:c}=i;s.forEach((l,d)=>{c.forEach((h,g)=>{const u=this._sheetDataValidationModel.getRuleIdByLocation(t,a,l,h);r.setValue(d,g,u!=null?u:"")})})}_generateMutations(t,a){if(!this._copyInfo)return{redos:[],undos:[]};if(a.copyType===B.COPY_TYPE.CUT)return this._copyInfo=null,{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!a.copyRange)return{redos:[],undos:[]};if([B.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,B.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,B.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,B.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(a.pasteType))return{redos:[],undos:[]};const{unitId:r,subUnitId:i}=this._copyInfo;if(a.unitId!==r||i!==a.subUnitId){const s=this._sheetDataValidationModel.getRuleObjectMatrix(a.unitId,a.subUnitId).clone(),c=new o.ObjectMatrix,l=new Set,{ranges:[d,h],mapFunc:g}=B.virtualizeDiscreteRanges([a.copyRange,t]),u=B.getRepeatRange(d,h,!0),S=new Map;u.forEach(({startRange:m})=>{var C;(C=this._copyInfo)==null||C.matrix.forValue((f,y,R)=>{const D=o.Rectangle.getPositionRange({startRow:f,endRow:f,startColumn:y,endColumn:y},m),V=`${i}-${R}`,x=this._sheetDataValidationModel.getRuleById(r,i,R);!this._sheetDataValidationModel.getRuleById(a.unitId,a.subUnitId,V)&&x&&S.set(V,{...x,uid:V});const{row:H,col:P}=g(D.startRow,D.startColumn);l.add(V),c.setValue(H,P,V)})});const v=Array.from(l).map(m=>({id:m,ranges:o.queryObjectMatrix(c,C=>C===m)}));s.addRangeRules(v);const{redoMutations:T,undoMutations:M}=_.getDataValidationDiffMutations(a.unitId,a.subUnitId,s.diffWithAddition(this._sheetDataValidationModel.getRules(a.unitId,a.subUnitId),S.values()),this._injector,"patched",!1);return{redos:T,undos:M}}else{const s=this._sheetDataValidationModel.getRuleObjectMatrix(r,i).clone(),c=new o.ObjectMatrix,l=new Set,{ranges:[d,h],mapFunc:g}=B.virtualizeDiscreteRanges([a.copyRange,t]);B.getRepeatRange(d,h,!0).forEach(({startRange:M})=>{var m;(m=this._copyInfo)==null||m.matrix.forValue((C,f,y)=>{const R=o.Rectangle.getPositionRange({startRow:C,endRow:C,startColumn:f,endColumn:f},M),{row:D,col:V}=g(R.startRow,R.startColumn);c.setValue(D,V,y),l.add(y)})});const S=Array.from(l).map(M=>({id:M,ranges:o.queryObjectMatrix(c,m=>m===M)}));s.addRangeRules(S);const{redoMutations:v,undoMutations:T}=_.getDataValidationDiffMutations(r,i,s.diff(this._sheetDataValidationModel.getRules(r,i)),this._injector,"patched",!1);return{redos:v,undos:T}}}};Ee=fn([Ge(0,B.ISheetClipboardService),Ge(1,o.Inject(_.SheetDataValidationModel)),Ge(2,o.Inject(o.Injector))],Ee);var Sn=Object.getOwnPropertyDescriptor,_n=(e,t,a,n)=>{for(var r=n>1?void 0:n?Sn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},qe=(e,t)=>(a,n)=>t(a,n,e);let Me=class extends o.Disposable{constructor(e,t,a){super(),this._localeService=e,this._commandService=t,this._sheetPermissionCheckController=a,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{e.id===_.AddSheetDataValidationCommand.id&&(this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[W.WorkbookEditablePermission],rangeTypes:[W.RangeProtectionPermissionEditPoint],worksheetTypes:[W.WorksheetEditPermission,W.WorksheetSetCellStylePermission]})||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.setStyleErr"))),e.id===_.UpdateSheetDataValidationRangeCommand.id&&(this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[W.WorkbookEditablePermission],rangeTypes:[W.RangeProtectionPermissionEditPoint],worksheetTypes:[W.WorksheetEditPermission,W.WorksheetSetCellStylePermission]},e.params.ranges)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.setStyleErr")))}))}};Me=_n([qe(0,o.Inject(o.LocaleService)),qe(1,o.ICommandService),qe(2,o.Inject(W.SheetPermissionCheckController))],Me);const Et="data-validation-single",Mt="sheet.menu.data-validation";function In(e){return{id:Mt,type:w.MenuItemType.SUBITEMS,icon:Et,tooltip:"dataValidation.title",hidden$:w.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:B.getCurrentRangeDisable$(e,{workbookTypes:[W.WorkbookEditablePermission],worksheetTypes:[W.WorksheetSetCellStylePermission,W.WorksheetEditPermission],rangeTypes:[W.RangeProtectionPermissionEditPoint]})}}function Cn(e){return{id:_e.id,title:"dataValidation.panel.title",type:w.MenuItemType.BUTTON}}function yn(e){return{id:Xe.id,title:"dataValidation.panel.add",type:w.MenuItemType.BUTTON}}const Dn={[w.RibbonStartGroup.FORMULAS_INSERT]:{[Mt]:{order:9,menuItemFactory:In,[_e.id]:{order:0,menuItemFactory:Cn},[Xe.id]:{order:1,menuItemFactory:yn}}}};var Rn=Object.getOwnPropertyDescriptor,bt=(e,t,a,n)=>{for(var r=n>1?void 0:n?Rn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},Z=(e,t)=>(a,n)=>t(a,n,e);const Tt={tr:{size:6,color:"#fe4b4b"}};let be=class extends o.RxDisposable{constructor(e,t,a,n,r,i,s,c,l,d,h){super(),this._commandService=e,this._menuManagerService=t,this._renderManagerService=a,this._univerInstanceService=n,this._autoHeightController=r,this._dropdownManagerService=i,this._sheetDataValidationModel=s,this._dataValidatorRegistryService=c,this._sheetInterceptorService=l,this._dataValidationCacheService=d,this._editorBridgeService=h,this._initMenu(),this._initDropdown(),this._initViewModelIntercept(),this._initAutoHeight()}_initMenu(){this._menuManagerService.mergeMenu(Dn)}_initDropdown(){this._editorBridgeService&&this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{var a;if(!e.visible){((a=this._dropdownManagerService.activeDropdown)==null?void 0:a.trigger)==="editor-bridge"&&this._dropdownManagerService.hideDropdown();return}const t=this._editorBridgeService.getEditCellState();if(t){const{unitId:n,sheetId:r,row:i,column:s}=t,c=this._univerInstanceService.getUniverSheetInstance(n);if(!c)return;const l=this._sheetDataValidationModel.getRuleByLocation(n,r,i,s);if(!l)return;const d=this._dataValidatorRegistryService.getValidatorItem(l.type);if(!(d!=null&&d.dropdownType))return;const h=c.getActiveSheet();if(!h)return;const g=this._dropdownManagerService.activeDropdown,u=g==null?void 0:g.location;if(u&&u.unitId===n&&u.subUnitId===r&&u.row===i&&u.col===s)return;this._dropdownManagerService.showDropdown({location:{unitId:n,subUnitId:r,row:i,col:s,workbook:c,worksheet:h},trigger:"editor-bridge",closeOnOutSide:!1})}}))}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(W.INTERCEPTOR_POINT.CELL_CONTENT,{effect:o.InterceptorEffectEnum.Style,priority:W.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,t,a)=>{var m,C,f,y,R;const{row:n,col:r,unitId:i,subUnitId:s,workbook:c,worksheet:l}=t,d=this._sheetDataValidationModel.getRuleIdByLocation(i,s,n,r);if(!d)return a(e);const h=this._sheetDataValidationModel.getRuleById(i,s,d);if(!h)return a(e);const g=(m=this._dataValidationCacheService.getValue(i,s,n,r))!=null?m:o.DataValidationStatus.VALID,u=this._dataValidatorRegistryService.getValidatorItem(h.type),S=t.rawData;let v;const T={get value(){var D;return v!==void 0||(v=(D=_.getCellValueOrigin(S))!=null?D:null),v}},M={get value(){var D;return`${(D=T.value)!=null?D:""}`}};return a({...e,markers:{...e==null?void 0:e.markers,...g===o.DataValidationStatus.INVALID?Tt:null},customRender:[...(C=e==null?void 0:e.customRender)!=null?C:[],...u!=null&&u.canvasRender?[u.canvasRender]:[]],fontRenderExtension:{...e==null?void 0:e.fontRenderExtension,isSkip:((f=e==null?void 0:e.fontRenderExtension)==null?void 0:f.isSkip)||((y=u==null?void 0:u.skipDefaultFontRender)==null?void 0:y.call(u,h,T.value,t))},interceptorStyle:{...e==null?void 0:e.interceptorStyle,...u==null?void 0:u.getExtraStyle(h,M.value,{get style(){const D=c.getStyles();return(typeof(e==null?void 0:e.s)=="string"?D.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},n,r)},interceptorAutoHeight:()=>{var H,P,U,F,N,A;const D=(P=(H=this._renderManagerService.getRenderById(i))==null?void 0:H.with(B.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:P.skeleton;if(!D)return;const V=D.worksheet.getMergedCell(n,r),x={data:e,style:D.getStyles().getStyleByCell(e),primaryWithCoord:D.getCellWithCoordByIndex((U=V==null?void 0:V.startRow)!=null?U:n,(F=V==null?void 0:V.startColumn)!=null?F:r),unitId:i,subUnitId:s,row:n,col:r,workbook:c,worksheet:l};return(A=(N=u==null?void 0:u.canvasRender)==null?void 0:N.calcCellAutoHeight)==null?void 0:A.call(N,x)},interceptorAutoWidth:()=>{var H,P,U,F,N,A;const D=(P=(H=this._renderManagerService.getRenderById(i))==null?void 0:H.with(B.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:P.skeleton;if(!D)return;const V=D.worksheet.getMergedCell(n,r),x={data:e,style:D.getStyles().getStyleByCell(e),primaryWithCoord:D.getCellWithCoordByIndex((U=V==null?void 0:V.startRow)!=null?U:n,(F=V==null?void 0:V.startColumn)!=null?F:r),unitId:i,subUnitId:s,row:n,col:r,workbook:c,worksheet:l};return(A=(N=u==null?void 0:u.canvasRender)==null?void 0:N.calcCellAutoWidth)==null?void 0:A.call(N,x)},coverable:((R=e==null?void 0:e.coverable)!=null?R:!0)&&!(h.type===o.DataValidationType.LIST||h.type===o.DataValidationType.LIST_MULTIPLE)})}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe(ae.filter(e=>e.source==="command"),ae.bufferTime(100)).subscribe(e=>{if(e.length===0)return;const t=[];if(e.forEach(a=>{var n;(a.rule.type===o.DataValidationType.LIST_MULTIPLE||a.rule.type===o.DataValidationType.LIST)&&(n=a.rule)!=null&&n.ranges&&t.push(...a.rule.ranges)}),t.length){const a=this._autoHeightController.getUndoRedoParamsOfAutoHeight(t);o.sequenceExecute(a.redos,this._commandService)}})}};be=bt([Z(0,o.ICommandService),Z(1,w.IMenuManagerService),Z(2,L.IRenderManagerService),Z(3,o.IUniverInstanceService),Z(4,o.Inject(B.AutoHeightController)),Z(5,o.Inject(fe)),Z(6,o.Inject(_.SheetDataValidationModel)),Z(7,o.Inject($.DataValidatorRegistryService)),Z(8,o.Inject(W.SheetInterceptorService)),Z(9,o.Inject(_.DataValidationCacheService)),Z(10,o.Optional(B.IEditorBridgeService))],be);let mt=class extends o.RxDisposable{constructor(e,t,a,n,r,i,s){super(),this._commandService=e,this._renderManagerService=t,this._autoHeightController=a,this._dataValidatorRegistryService=n,this._sheetInterceptorService=r,this._sheetDataValidationModel=i,this._dataValidationCacheService=s,this._initViewModelIntercept(),this._initAutoHeight()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(W.INTERCEPTOR_POINT.CELL_CONTENT,{effect:o.InterceptorEffectEnum.Style,priority:W.InterceptCellContentPriority.DATA_VALIDATION,handler:(e,t,a)=>{var M,m,C,f,y;const{row:n,col:r,unitId:i,subUnitId:s,workbook:c,worksheet:l}=t,d=this._sheetDataValidationModel.getRuleIdByLocation(i,s,n,r);if(!d)return a(e);const h=this._sheetDataValidationModel.getRuleById(i,s,d);if(!h)return a(e);const g=(M=this._dataValidationCacheService.getValue(i,s,n,r))!=null?M:o.DataValidationStatus.VALID,u=this._dataValidatorRegistryService.getValidatorItem(h.type),S=l.getCellRaw(n,r),v=_.getCellValueOrigin(S),T=`${v!=null?v:""}`;return a({...e,markers:{...e==null?void 0:e.markers,...g===o.DataValidationStatus.INVALID?Tt:null},customRender:[...(m=e==null?void 0:e.customRender)!=null?m:[],...u!=null&&u.canvasRender?[u.canvasRender]:[]],fontRenderExtension:{...e==null?void 0:e.fontRenderExtension,isSkip:((C=e==null?void 0:e.fontRenderExtension)==null?void 0:C.isSkip)||((f=u==null?void 0:u.skipDefaultFontRender)==null?void 0:f.call(u,h,v,t))},interceptorStyle:{...e==null?void 0:e.interceptorStyle,...u==null?void 0:u.getExtraStyle(h,T,{get style(){const R=c.getStyles();return(typeof(e==null?void 0:e.s)=="string"?R.get(e==null?void 0:e.s):e==null?void 0:e.s)||{}}},n,r)},interceptorAutoHeight:()=>{var x,H,P,U,F,N;const R=(H=(x=this._renderManagerService.getRenderById(i))==null?void 0:x.with(B.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:H.skeleton;if(!R)return;const D=R.worksheet.getMergedCell(n,r),V={data:e,style:R.getStyles().getStyleByCell(e),primaryWithCoord:R.getCellWithCoordByIndex((P=D==null?void 0:D.startRow)!=null?P:n,(U=D==null?void 0:D.startColumn)!=null?U:r),unitId:i,subUnitId:s,row:n,col:r,workbook:c,worksheet:l};return(N=(F=u==null?void 0:u.canvasRender)==null?void 0:F.calcCellAutoHeight)==null?void 0:N.call(F,V)},coverable:((y=e==null?void 0:e.coverable)!=null?y:!0)&&!(h.type===o.DataValidationType.LIST||h.type===o.DataValidationType.LIST_MULTIPLE)})}}))}_initAutoHeight(){this._sheetDataValidationModel.ruleChange$.pipe(ae.filter(e=>e.source==="command"),ae.bufferTime(16)).subscribe(e=>{const t=[];if(e.forEach(a=>{var n;(n=a.rule)!=null&&n.ranges&&t.push(...a.rule.ranges)}),t.length){const a=this._autoHeightController.getUndoRedoParamsOfAutoHeight(t);o.sequenceExecute(a.redos,this._commandService)}})}};mt=bt([Z(0,o.ICommandService),Z(1,L.IRenderManagerService),Z(2,o.Inject(B.AutoHeightController)),Z(3,o.Inject($.DataValidatorRegistryService)),Z(4,o.Inject(W.SheetInterceptorService)),Z(5,o.Inject(_.SheetDataValidationModel)),Z(6,o.Inject(_.DataValidationCacheService))],mt);var Vn=Object.getOwnPropertyDescriptor,wn=(e,t,a,n)=>{for(var r=n>1?void 0:n?Vn(t,a):t,i=e.length-1,s;i>=0;i--)(s=e[i])&&(r=s(r)||r);return r},ft=(e,t)=>(a,n)=>t(a,n,e);let Be=class extends o.Disposable{constructor(e,t,a){super(),this._context=e,this._sheetDataValidationModel=t,this._sheetSkeletonManagerService=a,this._initSkeletonChange()}_initSkeletonChange(){const e=t=>{var n;if(!t.length)return;const a=new Set;t.forEach(r=>{a.add(r.subUnitId)}),a.forEach(r=>{var i;(i=this._sheetSkeletonManagerService.getSkeletonParam(r))==null||i.skeleton.makeDirty(!0)}),(n=this._context.mainComponent)==null||n.makeForceDirty()};this.disposeWithMe(this._sheetDataValidationModel.validStatusChange$.pipe(o.bufferDebounceTime(16)).subscribe(e))}};Be=wn([ft(1,o.Inject(_.SheetDataValidationModel)),ft(2,o.Inject(B.SheetSkeletonManagerService))],Be);function En(e){var d;const t=w.useDependency(o.LocaleService),a=w.useDependency(w.ComponentManager),{value:n,onChange:r,extraComponent:i}=e,[s,c]=b.useState(!1),l=i?a.get(i):null;return p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:`
|
32
32
|
univer-mb-3 univer-flex univer-cursor-pointer univer-items-center univer-text-sm univer-text-gray-900
|
33
|
+
dark:univer-text-white
|
33
34
|
`,onClick:()=>c(!s),children:[t.t("dataValidation.panel.options"),s?p.jsx(Dt,{className:"univer-ml-1"}):p.jsx(dt,{className:"univer-ml-1"})]}),s&&p.jsxs(p.Fragment,{children:[l?p.jsx(l,{value:n,onChange:r}):null,p.jsx(E.FormLayout,{label:t.t("dataValidation.panel.invalid"),children:p.jsxs(E.RadioGroup,{value:`${(d=n.errorStyle)!=null?d:o.DataValidationErrorStyle.WARNING}`,onChange:h=>r({...n,errorStyle:+h}),children:[p.jsx(E.Radio,{value:`${o.DataValidationErrorStyle.WARNING}`,children:t.t("dataValidation.panel.showWarning")}),p.jsx(E.Radio,{value:`${o.DataValidationErrorStyle.STOP}`,children:t.t("dataValidation.panel.rejectInput")})]})}),p.jsx(E.FormLayout,{label:t.t("dataValidation.panel.messageInfo"),children:p.jsx(E.Checkbox,{checked:n.showErrorMessage,onChange:()=>r({...n,showErrorMessage:!n.showErrorMessage}),children:t.t("dataValidation.panel.showInfo")})}),n.showErrorMessage?p.jsx(E.FormLayout,{children:p.jsx(E.Input,{value:n.error,onChange:h=>r({...n,error:h})})}):null]})]})}const Mn=e=>o.debounce(async(t,a,n,r)=>{const i=await e.executeCommand(t,a,n);r==null||r(i)},1e3);function bn(e,t,a){var n,r,i,s;return t?((r=(n=e.getUnit(t))==null?void 0:n.getSheetBySheetName(a))==null?void 0:r.getSheetId())||"":((s=(i=e.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET))==null?void 0:i.getSheetBySheetName(a))==null?void 0:s.getSheetId())||""}function Tn(){var j,K;const[e,t]=b.useState(0),a=w.useDependency(ue),n=w.useObservable(a.activeRule$,a.activeRule),{unitId:r,subUnitId:i,rule:s}=n||{},c=s.uid,l=w.useDependency($.DataValidatorRegistryService),d=w.useDependency(o.IUniverInstanceService),h=w.useDependency(w.ComponentManager),g=w.useDependency(o.ICommandService),u=w.useDependency($.DataValidationModel),S=w.useDependency(o.LocaleService),[v,T]=b.useState(s),M=l.getValidatorItem(v.type),[m,C]=b.useState(!1),f=l.getValidatorsByScope($.DataValidatorRegistryScope.SHEET),[y,R]=b.useState(()=>v.ranges.map(I=>({unitId:"",sheetId:"",range:I}))),D=b.useMemo(()=>Mn(g),[g]),[V,x]=b.useState(!1),[H,P]=b.useState(!1),U=b.useRef(null),F=w.useDependency(W.SheetsSelectionsService);if(b.useEffect(()=>()=>{const I=F.getCurrentLastSelection();I&&F.setSelections([I])},[F]),b.useEffect(()=>{g.onCommandExecuted(I=>{(I.id===o.UndoCommand.id||I.id===o.RedoCommand.id)&&setTimeout(()=>{const k=u.getRuleById(r,i,c);t(z=>z+1),k&&(T(k),R(k.ranges.map(z=>({unitId:"",sheetId:"",range:z}))))},20)})},[g,u,c,i,r]),!M)return null;const N=M.operators,A=M.operatorNames,Y=v.operator?$.TWO_FORMULA_OPERATOR_COUNT.includes(v.operator):!1,X=()=>{var I,k,z;(k=(I=U.current)==null?void 0:I.editor)!=null&&k.isFocus()&&G((z=U.current)==null?void 0:z.getValue()),!(!v.ranges.length||V)&&(M.validatorFormula(v,r,i).success?a.setActiveRule(null):C(!0))},G=w.useEvent(I=>{const k=I.split(",").filter(Boolean).map(at.deserializeRangeWithSheet).map(Q=>{const gt=Q.sheetName;if(gt){const Lt=bn(d,Q.unitId,gt);return{...Q,sheetId:Lt}}return{...Q,sheetId:""}});if(o.isUnitRangesEqual(k,y))return;R(k);const z=k.filter(Q=>(!Q.unitId||Q.unitId===r)&&(!Q.sheetId||Q.sheetId===i)).map(Q=>Q.range);if(T({...v,ranges:z}),z.length===0)return;const ge={unitId:r,subUnitId:i,ruleId:c,ranges:z};D(_.UpdateSheetDataValidationRangeCommand.id,ge)}),J=I=>{if(o.shallowEqual(I,$.getRuleSetting(v)))return;T({...v,...I});const k={unitId:r,subUnitId:i,ruleId:c,setting:I};D(_.UpdateSheetDataValidationSettingCommand.id,k,void 0)},q=async()=>{await g.executeCommand(_.RemoveSheetDataValidationCommand.id,{ruleId:c,unitId:r,subUnitId:i}),a.setActiveRule(null)},ee={type:v.type,operator:v.operator,formula1:v.formula1,formula2:v.formula2,allowBlank:v.allowBlank},le=I=>{const k=l.getValidatorItem(I);if(!k)return;const z=k.operators,ge=u.getRuleById(r,i,c),Q=I===(ge==null?void 0:ge.type)||I.includes("list")&&(ge!=null&&ge.type.includes("list"))?{...ge,type:I}:{...v,type:I,operator:z[0],formula1:void 0,formula2:void 0};T(Q),g.executeCommand(_.UpdateSheetDataValidationSettingCommand.id,{unitId:r,subUnitId:i,ruleId:v.uid,setting:$.getRuleSetting(Q)})},re=h.get(M.formulaInput),te=b.useMemo(()=>y.map(I=>at.serializeRange(I.range)).join(","),[]),ie=$.getRuleOptions(v),he=I=>{o.shallowEqual(I,$.getRuleOptions(v))||(T({...v,...I}),D(_.UpdateSheetDataValidationOptionsCommand.id,{unitId:r,subUnitId:i,ruleId:c,options:I}))},ce=N.length&&!v.operator;return p.jsxs("div",{className:"univer-py-4",children:[p.jsx(E.FormLayout,{label:S.t("dataValidation.panel.range"),error:!v.ranges.length||V?S.t("dataValidation.panel.rangeError"):"",children:p.jsx(lt.RangeSelector,{selectorRef:U,unitId:r,subUnitId:i,initialValue:te,onChange:(I,k)=>{var z;!H&&((z=U.current)!=null&&z.verify())&&G(k)},onFocusChange:(I,k)=>{var z;P(I),!I&&k&&((z=U.current)!=null&&z.verify())&&G(k)},onVerify:I=>x(!I)})}),p.jsx(E.FormLayout,{label:S.t("dataValidation.panel.type"),children:p.jsx(E.Select,{className:"univer-w-full",value:v.type,options:(j=f==null?void 0:f.sort((I,k)=>I.order-k.order))==null?void 0:j.map(I=>({label:S.t(I.title),value:I.id})),onChange:le})}),N!=null&&N.length?p.jsx(E.FormLayout,{label:S.t("dataValidation.panel.operator"),children:p.jsx(E.Select,{className:"univer-w-full",value:`${v.operator}`,options:[{value:"",label:S.t("dataValidation.operators.legal")},...N.map((I,k)=>({value:`${I}`,label:A[k]}))],onChange:I=>{J({...ee,operator:I})}})}):null,re&&!ce?p.jsx(re,{isTwoFormula:Y,value:{formula1:v.formula1,formula2:v.formula2},onChange:I=>{J({...ee,...I})},showError:m,validResult:M.validatorFormula(v,r,i),unitId:r,subUnitId:i,ruleId:c},e+v.type):null,p.jsx(E.FormLayout,{children:p.jsx(E.Checkbox,{checked:(K=v.allowBlank)!=null?K:!0,onChange:()=>{var I;return J({...ee,allowBlank:!((I=v.allowBlank)==null||I)})},children:S.t("dataValidation.panel.allowBlank")})}),p.jsx(En,{value:ie,onChange:he,extraComponent:M.optionsInput}),p.jsxs("div",{className:"univer-mt-5 univer-flex univer-flex-row univer-justify-end",children:[p.jsx(E.Button,{className:"univer-ml-3",onClick:q,children:S.t("dataValidation.panel.removeRule")}),p.jsx(E.Button,{className:"univer-ml-3",variant:"primary",onClick:X,children:S.t("dataValidation.panel.done")})]})]})}const On=e=>{const{rule:t,onClick:a,unitId:n,subUnitId:r,disable:i}=e,s=w.useDependency($.DataValidatorRegistryService),c=w.useDependency(o.ICommandService),l=w.useDependency(B.IMarkSelectionService),d=s.getValidatorItem(t.type),h=b.useRef(void 0),[g,u]=b.useState(!1),S=w.useDependency(o.ThemeService),v=w.useObservable(S.currentTheme$),T=b.useMemo(()=>{var R;const m=S.getColorFromTheme("primary.600"),C=S.getColorFromTheme("loop-color.2"),f=(R=S.getColorFromTheme(C))!=null?R:m,y=new o.ColorKit(f).toRgb();return{fill:`rgba(${y.r}, ${y.g}, ${y.b}, 0.1)`,stroke:f}},[v]),M=m=>{c.executeCommand(_.RemoveSheetDataValidationCommand.id,{ruleId:t.uid,unitId:n,subUnitId:r}),m.stopPropagation()};return b.useEffect(()=>()=>{var m;h.current&&((m=h.current)==null||m.forEach(C=>{C&&l.removeShape(C)}))},[l]),p.jsxs("div",{className:E.clsx(`
|
34
35
|
univer-rounded-md univer-bg-secondary univer-relative univer--ml-2 univer--mr-2 univer-box-border
|
35
36
|
univer-flex univer-w-[287px] univer-cursor-pointer univer-flex-col univer-justify-between
|
36
37
|
univer-overflow-hidden univer-p-2 univer-pr-9
|
37
38
|
`,{"hover:univer-bg-gray-50":!i,"univer-opacity-50":i}),onClick:a,onMouseEnter:()=>{i||(u(!0),h.current=t.ranges.map(m=>l.addShape({range:m,style:T,primary:null})))},onMouseLeave:()=>{var m;u(!1),(m=h.current)==null||m.forEach(C=>{C&&l.removeShape(C)}),h.current=void 0},children:[p.jsx("div",{className:`
|
38
|
-
univer-
|
39
|
-
univer-text-
|
40
|
-
`,children:d==null?void 0:d.generateRuleName(t)}),p.jsx("div",{className:`
|
41
|
-
univer-text-secondary univer-overflow-hidden univer-text-ellipsis univer-text-xs univer-leading-[18px]
|
42
|
-
`,children:t.ranges.map(m=>at.serializeRange(m)).join(",")}),g?p.jsx("div",{className:`
|
39
|
+
univer-truncate univer-text-sm univer-font-medium univer-leading-[22px] univer-text-gray-900
|
40
|
+
dark:univer-text-white
|
41
|
+
`,children:d==null?void 0:d.generateRuleName(t)}),p.jsx("div",{className:"univer-text-secondary univer-truncate univer-text-xs univer-leading-[18px]",children:t.ranges.map(m=>at.serializeRange(m)).join(",")}),g?p.jsx("div",{className:`
|
43
42
|
univer-absolute univer-right-2 univer-top-[19px] univer-flex univer-h-5 univer-w-5
|
44
43
|
univer-items-center univer-justify-center univer-rounded
|
45
44
|
hover:univer-bg-gray-200
|