@univerjs/sheets-data-validation-ui 0.18.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -51
- package/lib/es/index.js +1 -51
- package/lib/index.js +1 -51
- package/lib/types/controllers/dv-copy-paste.controller.d.ts +3 -2
- package/lib/umd/index.js +1 -51
- package/package.json +15 -15
package/lib/es/index.js
CHANGED
|
@@ -1,51 +1 @@
|
|
|
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,dayjs 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.18.0`;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);let zn=class extends l{constructor(e,t,n){super(),this._sheetClipboardService=e,this._sheetDataValidationModel=t,this._injector=n,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)=>{let{copyType:i=Mt.COPY,pasteType:a}=r,{range:o}=e||{},{range:s,unitId:c,subUnitId:l}=t;return this._generateMutations(s,{copyType:i,pasteType:a,copyRange:o,unitId:c,subUnitId:l})}})}_collect(e,t,n){let r=new 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){if(!this._copyInfo)return{redos:[],undos:[]};if(t.copyType===Mt.CUT)return this._copyInfo=null,{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!t.copyRange||[Bt.SPECIAL_PASTE_COL_WIDTH,Bt.SPECIAL_PASTE_VALUE,Bt.SPECIAL_PASTE_FORMAT,Bt.SPECIAL_PASTE_FORMULA].includes(t.pasteType))return{redos:[],undos:[]};let{unitId:n,subUnitId:r}=this._copyInfo;if(t.unitId!==n||r!==t.subUnitId){let i=this._sheetDataValidationModel.getRuleObjectMatrix(t.unitId,t.subUnitId).clone(),a=new y,o=new Set,{ranges:[s,c],mapFunc:l}=Gt([t.copyRange,e]),u=Wt(s,c,!0),d=new Map;u.forEach(({startRange:e})=>{var i;(i=this._copyInfo)==null||i.matrix.forValue((i,s,c)=>{let u=C.getPositionRange({startRow:i,endRow:i,startColumn:s,endColumn:s},e),f=`${r}-${c}`,p=this._sheetDataValidationModel.getRuleById(n,r,c);!this._sheetDataValidationModel.getRuleById(t.unitId,t.subUnitId,f)&&p&&d.set(f,{...p,uid:f});let{row:m,col:h}=l(u.startRow,u.startColumn);o.add(f),a.setValue(m,h,f)})});let f=Array.from(o).map(e=>({id:e,ranges:I(a,t=>t===e)}));i.addRangeRules(f);let{redoMutations:p,undoMutations:m}=et(t.unitId,t.subUnitId,i.diffWithAddition(this._sheetDataValidationModel.getRules(t.unitId,t.subUnitId),d.values()),this._injector,`patched`,!1);return{redos:p,undos:m}}else{let i=this._sheetDataValidationModel.getRuleObjectMatrix(n,r).clone(),a=new y,o=new Set,{ranges:[s,c],mapFunc:l}=Gt([t.copyRange,e]);Wt(s,c,!0).forEach(({startRange:e})=>{var t;(t=this._copyInfo)==null||t.matrix.forValue((t,n,r)=>{let i=C.getPositionRange({startRow:t,endRow:t,startColumn:n,endColumn:n},e),{row:s,col:c}=l(i.startRow,i.startColumn);a.setValue(s,c,r),o.add(r)})});let u=Array.from(o).map(e=>({id:e,ranges:I(a,t=>t===e)}));i.addRangeRules(u);let{redoMutations:d,undoMutations:f}=et(n,r,i.diff(this._sheetDataValidationModel.getRules(n,r)),this._injector,`patched`,!1);return{redos:d,undos:f}}}};zn=Z([X(0,zt),X(1,h(V)),X(2,h(g))],zn);let Bn=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`))}}))}};Bn=Z([X(0,h(v)),X(1,f),X(2,h(we))],Bn);const Vn=`sheet.menu.data-validation`;function Hn(e){return{id:Vn,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 Un(e){return{id:An.id,title:`dataValidation.panel.title`,type:_t.BUTTON}}function Wn(e){return{id:Fn.id,title:`dataValidation.panel.add`,type:_t.BUTTON}}const Gn={[vt.RULES]:{[Vn]:{order:0,menuItemFactory:Hn,[An.id]:{order:0,menuItemFactory:Un},[Fn.id]:{order:1,menuItemFactory:Wn}}}},Kn={tr:{size:6,color:`#fe4b4b`}};let qn=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(Gn)}_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?Kn: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)})}};qn=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))],qn);let Jn=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?Kn: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)})}};Jn=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))],Jn);let Yn=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()}))}};Yn=Z([X(1,h(V)),X(2,h(Ht))],Yn);function Xn(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:`
|
|
2
|
-
univer-mb-3 univer-flex univer-cursor-pointer univer-items-center univer-text-sm univer-text-gray-900
|
|
3
|
-
dark:!univer-text-white
|
|
4
|
-
`,onClick:()=>l(!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 Zn=e=>M(async(t,n,r,i)=>{let a=await e.executeCommand(t,n,r);i==null||i(a)},1e3);function Qn(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 $n(){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(()=>Zn(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=Qn(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(Xn,{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 er=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(`
|
|
5
|
-
univer-bg-secondary univer-relative univer--mx-2 univer-box-border univer-flex univer-w-[287px]
|
|
6
|
-
univer-cursor-pointer univer-flex-col univer-justify-between univer-overflow-hidden univer-rounded-md
|
|
7
|
-
univer-p-2 univer-pr-9
|
|
8
|
-
`,{"hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-700":!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:`
|
|
9
|
-
univer-truncate univer-text-sm univer-font-medium univer-leading-[22px] univer-text-gray-900
|
|
10
|
-
dark:!univer-text-white
|
|
11
|
-
`,children:u==null?void 0:u.generateRuleName(n)}),q(`div`,{className:`
|
|
12
|
-
univer-text-secondary univer-truncate univer-text-xs univer-leading-[18px]
|
|
13
|
-
dark:!univer-text-gray-300
|
|
14
|
-
`,children:n.ranges.map(e=>mn(e)).join(`,`)}),p?q(`div`,{className:`
|
|
15
|
-
univer-absolute univer-right-2 univer-top-[19px] univer-flex univer-size-5 univer-items-center
|
|
16
|
-
univer-justify-center univer-rounded
|
|
17
|
-
hover:univer-bg-gray-200
|
|
18
|
-
dark:!univer-text-gray-300
|
|
19
|
-
dark:hover:!univer-bg-gray-700
|
|
20
|
-
`,onClick:_,children:q(cn,{})}):null]})};function tr(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(er,{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 nr=()=>{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($n,{},t.rule.uid):q(tr,{workbook:r})},rr=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 ir(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 ar(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(`
|
|
21
|
-
univer-box-border univer-h-8 univer-w-full univer-cursor-pointer univer-items-center univer-rounded-lg
|
|
22
|
-
univer-bg-white univer-pt-2 univer-transition-colors
|
|
23
|
-
hover:univer-border-primary-600
|
|
24
|
-
dark:!univer-bg-gray-700 dark:!univer-text-white
|
|
25
|
-
[&>div:first-child]:univer-px-2.5
|
|
26
|
-
[&>div]:univer-h-5 [&>div]:univer-ring-transparent
|
|
27
|
-
`,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 or=[`#FFFFFF`,`#FEE7E7`,`#FEF0E6`,`#EFFBD0`,`#E4F4FE`,`#E8ECFD`,`#F1EAFA`,`#FDE8F3`,`#E5E5E5`,`#FDCECE`,`#FDC49B`,`#DEF6A2`,`#9FDAFF`,`#D0D9FB`,`#E3D5F6`,`#FBD0E8`,`#656565`,`#FE4B4B`,`#FF8C51`,`#8BBB11`,`#0B9EFB`,`#3A60F7`,`#9E6DE3`,`#F248A6`],sr=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:`
|
|
28
|
-
univer-box-border univer-grid univer-w-fit univer-grid-cols-6 univer-flex-wrap univer-gap-2
|
|
29
|
-
univer-p-1.5
|
|
30
|
-
`,children:or.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(`
|
|
31
|
-
univer-box-border univer-inline-flex univer-h-8 univer-w-16 univer-cursor-pointer univer-items-center
|
|
32
|
-
univer-justify-between univer-gap-2 univer-rounded-lg univer-bg-white univer-px-2.5
|
|
33
|
-
univer-transition-colors univer-duration-200
|
|
34
|
-
hover:univer-border-primary-600
|
|
35
|
-
dark:!univer-bg-gray-700 dark:!univer-text-white
|
|
36
|
-
`,en),children:[q(`div`,{className:`univer-box-border univer-size-4 univer-rounded univer-text-base`,style:{background:t}}),q(un,{})]})})},cr=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(sr,{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:`
|
|
37
|
-
univer-ml-1 univer-cursor-pointer univer-rounded univer-text-base
|
|
38
|
-
hover:univer-bg-gray-200
|
|
39
|
-
`,children:q(cn,{onClick:()=>a(t.id)})})]})};function lr(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(`
|
|
40
|
-
univer-box-border univer-h-8 univer-w-full univer-cursor-pointer univer-items-center
|
|
41
|
-
univer-rounded-lg univer-bg-white univer-pt-2 univer-transition-colors
|
|
42
|
-
hover:univer-border-primary-600
|
|
43
|
-
dark:!univer-bg-gray-700 dark:!univer-text-white
|
|
44
|
-
[&>div:first-child]:univer-px-2.5
|
|
45
|
-
[&>div]:univer-h-5 [&>div]:univer-ring-transparent
|
|
46
|
-
`,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(cr,{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(cr,{item:e,commonProps:{onItemChange:P,onItemDelete:F}},e.id),idKey:`id`}),J(`a`,{className:`
|
|
47
|
-
univer-text-primary univer-flex univer-w-fit univer-cursor-pointer univer-flex-row
|
|
48
|
-
univer-items-center univer-rounded univer-p-1 univer-px-2 univer-text-sm
|
|
49
|
-
hover:univer-bg-primary-50
|
|
50
|
-
dark:hover:!univer-bg-gray-800
|
|
51
|
-
`,onClick:ae,children:[q(ln,{className:`univer-mr-1`}),_.t(`dataValidation.list.add`)]})]})})]})}const ur=[[Re,ar],[Pe,rr],[Ue,lr],[Le,ir]];function dr(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`)})]})})}dr.componentKey=`LIST_RENDER_MODE_OPTION_INPUT`;function fr(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`)})})}fr.componentKey=`DATE_SHOW_TIME_OPTION`;let pr=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)}};pr=Z([X(0,f),X(1,m),X(2,h(He)),X(3,h(E)),X(4,h(B)),X(5,h(V))],pr);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 mr=class extends ${constructor(...e){super(...e),Y(this,`id`,s.CHECKBOX),Y(this,`canvasRender`,this.injector.createInstance(pr)),Y(this,`formulaInput`,Le)}},hr=class extends ${constructor(...e){super(...e),Y(this,`id`,s.CUSTOM),Y(this,`formulaInput`,Re)}},gr=class extends ${constructor(...e){super(...e),Y(this,`id`,s.DATE),Y(this,`formulaInput`,`data-validation.formula-input`),Y(this,`optionsInput`,fr.componentKey),Y(this,`dropdownType`,U.DATE)}},_r=class extends ${constructor(...e){super(...e),Y(this,`id`,s.DECIMAL),Y(this,`formulaInput`,Pe)}};function vr(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 yr(e,t,n,r){let i=n-26,a=r-12,o=e.map(e=>({layout:vr(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 br=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 xr=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 Sr=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(xr),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=yr(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),br.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 yr(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 yr(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)}};Sr=Z([X(0,f),X(1,m),X(2,h(B)),X(3,h(V))],Sr);var Cr=class extends ${constructor(...e){super(...e),Y(this,`id`,s.LIST_MULTIPLE),Y(this,`canvasRender`,this.injector.createInstance(Sr)),Y(this,`dropdownType`,U.MULTIPLE_LIST)}};const wr=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 Tr(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 Er=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(wr),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}=Tr(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}=Tr(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(wr),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)}};Er=Z([X(0,m),X(1,h(v)),X(2,f),X(3,h(B)),X(4,h(V))],Er);var Dr=class extends ${constructor(...e){super(...e),Y(this,`id`,s.LIST),Y(this,`canvasRender`,this.injector.createInstance(Er)),Y(this,`dropdownType`,U.LIST),Y(this,`optionsInput`,dr.componentKey),Y(this,`formulaInput`,Ue)}},Or=class extends ${constructor(...e){super(...e),Y(this,`id`,s.TEXT_LENGTH),Y(this,`formulaInput`,Pe)}},kr=class extends ${constructor(...e){super(...e),Y(this,`id`,s.WHOLE),Y(this,`formulaInput`,Pe)}};let Ar=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,nr],[dr.componentKey,dr],[fr.componentKey,fr],...ur].forEach(([e,t])=>{this.disposeWithMe(this._componentManger.register(e,t))})}_registerValidatorViews(){[_r,kr,Or,gr,mr,Dr,Cr,hr].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)})}};Ar=Z([X(0,h(g)),X(1,h(dt)),X(2,h(st))],Ar);let jr=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],[qn],[Bn],[zn],[Ar]].forEach(e=>{this._injector.add(e)}),[Fn,Nn,Pn,jn,An,Mn].forEach(e=>{this._commandService.registerCommand(e)})}onReady(){this._injector.get(zn),this._injector.get(Bn),this._injector.get(B).registerRenderModule(O.UNIVER_SHEET,[Yn])}onRendered(){this._injector.get(Ar),this._injector.get(qn)}onSteady(){this._injector.get(Rn)}};Y(jr,`pluginName`,`SHEET_DATA_VALIDATION_UI_PLUGIN`),Y(jr,`packageName`,vn),Y(jr,`version`,yn),Y(jr,`type`,O.UNIVER_SHEET),jr=Z([X(1,h(g)),X(2,f),X(3,p)],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],[qn],[Bn],[zn],[Tn],[Ar]].forEach(e=>{this._injector.add(e)}),[Fn,Nn,Pn,jn,An,Mn].forEach(e=>{this._commandService.registerCommand(e)})}onReady(){this._injector.get(zn),this._injector.get(Bn),this._injector.get(Tn),this._injector.get(Ln),this._injector.get(B).registerRenderModule(O.UNIVER_SHEET,[Yn])}onRendered(){this._injector.get(Ar),this._injector.get(qn)}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([c(qe),X(1,h(g)),X(2,f),X(3,p)],Mr);export{$ as BaseSheetDataValidatorView,jr as UniverSheetsDataValidationMobileUIPlugin,Mr as UniverSheetsDataValidationUIPlugin};
|
|
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,dayjs 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.19.0`;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};
|