index.js 33 KB

123456789
  1. (function(b,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/sheets-numfmt"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("@univerjs/engine-formula"),require("@univerjs/engine-numfmt"),require("@univerjs/sheets"),require("rxjs"),require("rxjs/operators"),require("react"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","@univerjs/sheets-numfmt","@univerjs/sheets-ui","@univerjs/ui","@univerjs/engine-formula","@univerjs/engine-numfmt","@univerjs/sheets","rxjs","rxjs/operators","react","@univerjs/design"],s):(b=typeof globalThis<"u"?globalThis:b||self,s(b.UniverSheetsNumfmtUi={},b.UniverCore,b.UniverEngineRender,b.UniverSheetsNumfmt,b.UniverSheetsUi,b.UniverUi,b.UniverEngineFormula,b.UniverEngineNumfmt,b.UniverSheets,b.rxjs,b.rxjs.operators,b.React,b.UniverDesign))})(this,function(b,s,U,m,E,I,_e,J,g,x,V,_,M){"use strict";var yt=Object.defineProperty;var bt=(b,s,U)=>s in b?yt(b,s,{enumerable:!0,configurable:!0,writable:!0,value:U}):b[s]=U;var z=(b,s,U)=>bt(b,typeof s!="symbol"?s+"":s,U);const ae={};var ye=Object.defineProperty,be=Object.getOwnPropertyDescriptor,Ce=(t,e,r,n)=>{for(var i=n>1?void 0:n?be(e,r):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(n?o(e,r,i):o(i))||i);return n&&i&&ye(e,r,i),i},w=(t,e)=>(r,n)=>e(r,n,t);const X="SHEET_NUMFMT_ALERT";let Q=class extends s.Disposable{constructor(t,e,r,n,i,a,o){super(),this._context=t,this._hoverManagerService=e,this._cellAlertManagerService=r,this._localeService=n,this._formulaDataModel=i,this._zenZoneService=a,this._numfmtService=o,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(x.debounceTime(100)).subscribe(t=>{var e;if(t){const r=t.location,n=this._context.unit,i=n.getActiveSheet();if(!i)return;const a=r.unitId,o=r.subUnitId;let l;const c=i.getCell(r.row,r.col);if(c!=null&&c.s){const d=n.getStyles().get(c.s);d!=null&&d.n&&(l=d.n)}if(l||(l=this._numfmtService.getValue(a,o,r.row,r.col)),!l){this._hideAlert();return}if(l.pattern===J.DEFAULT_TEXT_FORMAT&&(c!=null&&c.v)&&s.isRealNum(c.v)){const d=this._cellAlertManagerService.currentAlert.get(X),f=(e=d==null?void 0:d.alert)==null?void 0:e.location;if(f&&f.row===r.row&&f.col===r.col&&f.subUnitId===r.subUnitId&&f.unitId===r.unitId)return;this._cellAlertManagerService.showAlert({type:E.CellAlertType.ERROR,title:this._localeService.t("info.error"),message:this._localeService.t("info.forceStringInfo"),location:r,width:200,height:74,key:X});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(t=>{t&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(X)}};Q=Ce([w(1,s.Inject(E.HoverManagerService)),w(2,s.Inject(E.CellAlertManagerService)),w(3,s.Inject(s.LocaleService)),w(4,s.Inject(_e.FormulaDataModel)),w(5,I.IZenZoneService),w(6,s.Inject(g.INumfmtService))],Q);const $={id:"sheet.operation.close.numfmt.panel",type:s.CommandType.OPERATION,handler:()=>!0},L={id:"sheet.operation.open.numfmt.panel",type:s.CommandType.OPERATION,handler:t=>(t.get(A).openPanel(),!0)};var q={exports:{}},k={};/**
  2. * @license React
  3. * react-jsx-runtime.production.min.js
  4. *
  5. * Copyright (c) Facebook, Inc. and its affiliates.
  6. *
  7. * This source code is licensed under the MIT license found in the
  8. * LICENSE file in the root directory of this source tree.
  9. */var oe;function Ie(){if(oe)return k;oe=1;var t=_,e=Symbol.for("react.element"),r=Symbol.for("react.fragment"),n=Object.prototype.hasOwnProperty,i=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a={key:!0,ref:!0,__self:!0,__source:!0};function o(l,c,d){var f,p={},v=null,S=null;d!==void 0&&(v=""+d),c.key!==void 0&&(v=""+c.key),c.ref!==void 0&&(S=c.ref);for(f in c)n.call(c,f)&&!a.hasOwnProperty(f)&&(p[f]=c[f]);if(l&&l.defaultProps)for(f in c=l.defaultProps,c)p[f]===void 0&&(p[f]=c[f]);return{$$typeof:e,type:l,key:v,ref:S,props:p,_owner:i.current}}return k.Fragment=r,k.jsx=o,k.jsxs=o,k}var ce;function Te(){return ce||(ce=1,q.exports=Ie()),q.exports}var u=Te(),Pe=Object.defineProperty,Ee=Object.getOwnPropertyDescriptor,Me=(t,e,r,n)=>{for(var i=n>1?void 0:n?Ee(e,r):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(n?o(e,r,i):o(i))||i);return n&&i&&Pe(e,r,i),i},je=(t,e)=>(r,n)=>e(r,n,t);const ee=_.createContext([]);let H=class{constructor(t){this._localStorageService=t}_getKey(t){return`userHabitController_${t}`}async addHabit(t,e){const r=this._getKey(t);return this._localStorageService.getItem(r).then(n=>{n||this._localStorageService.setItem(r,e)})}markHabit(t,e){const r=this._getKey(t);this._localStorageService.getItem(r).then(n=>{if(n){const i=n.findIndex(a=>a===e);i>-1&&n.splice(i,1),n.unshift(e),this._localStorageService.setItem(r,n)}})}async getHabit(t,e){const r=this._getKey(t),n=await this._localStorageService.getItem(r);if(e&&n){const i=n.map((a,o,l)=>{const c=l.length;return{value:a,priority:c-o}});return e.sort((a,o)=>{var d,f;const l=((d=i.find(p=>p.value===a))==null?void 0:d.priority)||-1;return(((f=i.find(p=>p.value===o))==null?void 0:f.priority)||-1)-l})}return n||[]}deleteHabit(t){this._localStorageService.removeItem(t)}};H=Me([je(0,s.Inject(s.ILocalStorageService))],H);const le="numfmtCurrency",Re=t=>{const e=s.useDependency(H),[r,n]=_.useState(m.currencySymbols);return _.useEffect(()=>{e.addHabit("numfmtCurrency",[]).then(()=>{e.getHabit(le,[...m.currencySymbols]).then(a=>{n(a),t(a)})})},[]),{userHabitCurrency:r,mark:a=>{e.markHabit(le,a)}}},De=()=>{const t=_.useRef([]),[e,r]=_.useState({});return _.useEffect(()=>{t.current.forEach(i=>{i()}),t.current=[]},[e]),i=>{t.current.push(i),r({})}},xe=t=>!!m.getCurrencyType(t)&&t.startsWith("_("),Oe=t=>{const{defaultPattern:e,action:r,onChange:n}=t,[i,a]=_.useState(()=>m.getDecimalFromPattern(e||"",2)),o=_.useContext(ee),[l,c]=_.useState(()=>m.getCurrencyType(e)||o[0]),d=_.useMemo(()=>o.map(y=>({label:y,value:y})),[]),p=s.useDependency(s.LocaleService).t;r.current=()=>m.setPatternDecimal(`_("${l}"* #,##0${i>0?".0":""}_)`,i);const v=y=>{c(y),n(m.setPatternDecimal(`_("${y}"* #,##0${i>0?".0":""}_)`,i))},S=y=>{const h=y||0;a(h),n(m.setPatternDecimal(`_("${l}"* #,##0${h>0?".0":""}_)`,h))};return u.jsxs("div",{children:[u.jsxs("div",{className:"m-t-16 options",children:[u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:p("sheet.numfmt.decimalLength")}),u.jsx("div",{className:"m-t-8 w-120",children:u.jsx(M.InputNumber,{value:i,max:20,min:0,onChange:S})})]}),u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:p("sheet.numfmt.currencyType")}),u.jsx("div",{className:"m-t-8 w-140",children:u.jsx(M.Select,{onChange:v,options:d,value:l})})]})]}),u.jsx("div",{className:"describe m-t-14",children:p("sheet.numfmt.accountingDes")})]})},Ue=t=>!!m.getCurrencyType(t)&&!t.startsWith("_("),Ne=t=>{const r=s.useDependency(s.LocaleService).t,n=_.useContext(ee),[i,a]=_.useState(()=>m.getCurrencyType(t.defaultPattern)||n[0]),[o,l]=_.useState(()=>m.getDecimalFromPattern(t.defaultPattern||"",2)),[c,d]=_.useState(()=>{var C;const h=m.getCurrencyFormatOptions(i);return((C=h.find(R=>m.isPatternEqualWithoutDecimal(R.value,t.defaultPattern)))==null?void 0:C.value)||h[0].value}),f=_.useMemo(()=>m.getCurrencyFormatOptions(i),[i]),p=_.useMemo(()=>n.map(h=>({label:h,value:h})),[n]);t.action.current=()=>m.setPatternDecimal(c,o);const v=h=>{if(h===void 0)return;a(h);const P=m.getCurrencyFormatOptions(h)[0].value;d(P),t.onChange(m.setPatternDecimal(P,o))},S=h=>{h!==void 0&&(d(h),t.onChange(m.setPatternDecimal(h,o)))},y=h=>{l(h||0),t.onChange(m.setPatternDecimal(c,h||0))};return u.jsxs("div",{children:[u.jsxs("div",{className:"m-t-16 options",children:[u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:r("sheet.numfmt.decimalLength")}),u.jsx("div",{className:"m-t-8 w-120",children:u.jsx(M.InputNumber,{value:o,max:20,min:0,onChange:y})})]}),u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:r("sheet.numfmt.currencyType")}),u.jsx("div",{className:"m-t-8 w-140",children:u.jsx(M.Select,{onChange:v,options:p,value:i})})]})]}),u.jsx("div",{className:"m-t-16 label",children:r("sheet.numfmt.negType")}),u.jsx("div",{className:"m-t-8",children:u.jsx(M.SelectList,{onChange:S,options:f,value:c})}),u.jsx("div",{className:"describe m-t-14",children:r("sheet.numfmt.currencyDes")})]})};var j=function(){return j=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++){e=arguments[r];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},j.apply(this,arguments)},we=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},ue=_.forwardRef(function(t,e){var r=t.icon,n=t.id,i=t.className,a=t.extend,o=we(t,["icon","id","className","extend"]),l="univerjs-icon univerjs-icon-".concat(n," ").concat(i||"").trim(),c=_.useRef("_".concat(ke()));return me(r,"".concat(n),{defIds:r.defIds,idSuffix:c.current},j({ref:e,className:l},o),a)});function me(t,e,r,n,i){return _.createElement(t.tag,j(j({key:e},Fe(t,r,i)),n),(Le(t,r).children||[]).map(function(a,o){return me(a,"".concat(e,"-").concat(t.tag,"-").concat(o),r,void 0,i)}))}function Fe(t,e,r){var n=j({},t.attrs);r!=null&&r.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=r.colorChannel1);var i=e.defIds;return!i||i.length===0||(t.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+e.idSuffix),Object.entries(n).forEach(function(a){var o=a[0],l=a[1];typeof l=="string"&&(n[o]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),n}function Le(t,e){var r,n=e.defIds;return!n||n.length===0?t:t.tag==="defs"&&(!((r=t.children)===null||r===void 0)&&r.length)?j(j({},t),{children:t.children.map(function(i){return typeof i.attrs.id=="string"&&n&&n.indexOf(i.attrs.id)>-1?j(j({},i),{attrs:j(j({},i.attrs),{id:i.attrs.id+e.idSuffix})}):i})}):t}function ke(){return Math.random().toString(36).substring(2,8)}ue.displayName="UniverIcon";var He={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},de=_.forwardRef(function(t,e){return _.createElement(ue,Object.assign({},t,{id:"check-mark-single",ref:e,icon:He}))});de.displayName="CheckMarkSingle";const N={customFormatTitle:"univer-custom-format-title",customFormatInput:"univer-custom-format-input",customFormatHistoryList:"univer-custom-format-history-list",customFormatHistoryListItem:"univer-custom-format-history-list-item",customFormatHistoryListItemIconWrap:"univer-custom-format-history-list-item-icon-wrap",customFormatDes:"univer-custom-format-des"},te="customFormat",ne="numfmt_custom_pattern";function Ae(t){const{defaultPattern:e,action:r,onChange:n}=t,i=s.useDependency(H),a=s.useDependency(s.ILocalStorageService),o=s.useDependency(s.LocaleService),[l,c]=_.useState(e);r.current=()=>(i.markHabit(te,l),a.getItem(ne).then((S=[])=>{const y=[...new Set([l,...S||[]])].splice(0,10).filter(h=>!!h);a.setItem(ne,y)}),l);const[d,f]=_.useState([]);_.useEffect(()=>{a.getItem(ne).then(S=>{const y=[...m.CURRENCYFORMAT.map(h=>h.suffix("$")),...m.DATEFMTLISG.map(h=>h.suffix),...m.NUMBERFORMAT.map(h=>h.suffix)];y.push(...S||[]),i.addHabit(te,[]).finally(()=>{i.getHabit(te,y).then(h=>{f([...new Set(h)])})})})},[]);const p=S=>{c(S),n(S)},v=()=>{n(l)};return u.jsxs("div",{className:N.customFormat,children:[u.jsx("div",{className:N.customFormatTitle,children:o.t("sheet.numfmt.customFormat")}),u.jsx(M.Input,{placeholder:o.t("sheet.numfmt.customFormat"),onBlur:v,value:l,onChange:c,className:N.customFormatInput}),u.jsx("div",{className:N.customFormatHistoryList,children:d.map(S=>u.jsxs("div",{onClick:()=>p(S),className:N.customFormatHistoryListItem,children:[u.jsx("div",{className:N.customFormatHistoryListItemIconWrap,children:l===S&&u.jsx(de,{})}),u.jsx("div",{children:S})]},S))}),u.jsx("div",{className:N.customFormatDes,children:o.t("sheet.numfmt.customFormatDes")})]})}const We=t=>{const e=s.numfmt.getInfo(t);return m.getDateFormatOptions().map(r=>r.value).includes(t)||["date","datetime","time"].includes(e.type)},Be=t=>{const e=_.useMemo(m.getDateFormatOptions,[]),n=s.useDependency(s.LocaleService).t,[i,a]=_.useState(()=>{if(t.defaultPattern){const l=e.find(c=>c.value===t.defaultPattern);if(l)return l.value}return e[0].value});t.action.current=()=>i;const o=l=>{l!==void 0&&(a(l),t.onChange(l))};return u.jsxs("div",{children:[u.jsx("div",{className:"m-t-16 label",children:n("sheet.numfmt.dateType")}),u.jsx("div",{className:"m-t-8",children:u.jsx(M.SelectList,{value:i,options:e,onChange:o})}),u.jsx("div",{className:"describe m-t-14",children:n("sheet.numfmt.dateDes")})]})},Ve=t=>!t,Ge=t=>{const r=s.useDependency(s.LocaleService).t;return t.action.current=()=>"",u.jsx("div",{children:u.jsx("div",{className:"describe m-t-14",children:r("sheet.numfmt.generalDes")})})},Ke=t=>m.getNumberFormatOptions().some(e=>m.isPatternEqualWithoutDecimal(e.value,t)),Ye=t=>{const e=s.useDependency(s.LocaleService),r=_.useMemo(m.getNumberFormatOptions,[]),[n,i]=_.useState(()=>m.getDecimalFromPattern(t.defaultPattern||"",0)),[a,o]=_.useState(()=>{const p=r.find(v=>m.isPatternEqualWithoutDecimal(v.value,t.defaultPattern||""));return(p==null?void 0:p.value)||r[0].value}),l=_.useMemo(()=>m.setPatternDecimal(a,Number(n||0)),[a,n]),c=_.useMemo(()=>!m.isPatternHasDecimal(a),[a]),d=p=>{i(p||0),t.onChange(m.setPatternDecimal(a,Number(p||0)))},f=p=>{p!==void 0&&(i(m.getDecimalFromPattern(p,0)),o(p),t.onChange(p))};return t.action.current=()=>l,u.jsxs("div",{children:[u.jsx("div",{className:"m-t-16 label",children:e.t("sheet.numfmt.decimalLength")}),u.jsx("div",{className:"m-t-8",children:u.jsx(M.InputNumber,{disabled:c,value:n,max:20,min:0,onChange:d})}),u.jsxs("div",{className:"m-t-16 label",children:[" ",e.t("sheet.numfmt.negType")]}),u.jsx("div",{className:"m-t-8",children:u.jsx(M.SelectList,{onChange:f,options:r,value:a})}),u.jsx("div",{className:"describe m-t-14",children:e.t("sheet.numfmt.thousandthPercentileDes")})]})},Ze=t=>{const{defaultValue:e,defaultPattern:r,row:n,col:i}=t.value,a=s.useDependency(s.LocaleService),o=_.useRef(()=>""),l=a.t,c=De(),d=_.useMemo(()=>[{label:"sheet.numfmt.general",component:Ge},{label:"sheet.numfmt.accounting",component:Oe},{label:"sheet.numfmt.currency",component:Ne},{label:"sheet.numfmt.date",component:Be},{label:"sheet.numfmt.thousandthPercentile",component:Ye},{label:"sheet.numfmt.customFormat",component:Ae}].map(T=>({...T,label:l(T.label)})),[]),[f,p]=_.useState(C),[v,S]=_.useState(()=>`${n}_${i}`),{mark:y,userHabitCurrency:h}=Re(()=>S(`${n}_${i}_userCurrency'`)),P=_.useMemo(()=>{var T;return(T=d.find(F=>F.label===f))==null?void 0:T.component},[f]);function C(){return[Ve,xe,Ue,We,Ke].reduce((F,gt,_t)=>F||(gt(r)?d[_t].label:""),"")||d[0].label}const R=d.map(T=>({label:T.label,value:T.label})),O=T=>{p(T),c(()=>t.onChange({type:"change",value:o.current()||""}))},Z=T=>{t.onChange({type:"change",value:T})},ie=()=>{const T=o.current()||"",F=m.getCurrencyType(T);F&&y(F),t.onChange({type:"confirm",value:T})},B=()=>{t.onChange({type:"cancel",value:""})},se={onChange:Z,defaultValue:e,defaultPattern:r,action:o};return _.useEffect(()=>{p(C()),S(`${n}_${i}`)},[n,i]),u.jsxs("div",{className:"numfmt-panel p-b-20",children:[u.jsxs("div",{children:[u.jsx("div",{className:"label m-t-14",children:l("sheet.numfmt.numfmtType")}),u.jsx("div",{className:"m-t-8",children:u.jsx(M.Select,{onChange:O,options:R,value:f,style:{width:"100%"}})}),u.jsx("div",{children:P&&u.jsx(ee.Provider,{value:h,children:_.createElement(P,{...se,key:v})})})]}),u.jsxs("div",{className:"btn-list m-t-14 m-b-20",children:[u.jsx(M.Button,{size:"small",onClick:B,className:"m-r-12",children:l("sheet.numfmt.cancel")}),u.jsx(M.Button,{type:"primary",size:"small",onClick:ie,children:l("sheet.numfmt.confirm")})]})]})};var ze=Object.defineProperty,Je=Object.getOwnPropertyDescriptor,Xe=(t,e,r,n)=>{for(var i=n>1?void 0:n?Je(e,r):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(n?o(e,r,i):o(i))||i);return n&&i&&ze(e,r,i),i},D=(t,e)=>(r,n)=>e(r,n,t);const pe="SHEET_NUMFMT_PANEL";let A=class extends s.Disposable{constructor(e,r,n,i,a,o,l,c,d,f,p){super();z(this,"_previewPattern","");z(this,"_sidebarDisposable",null);this._sheetInterceptorService=e,this._themeService=r,this._univerInstanceService=n,this._commandService=i,this._selectionManagerService=a,this._renderManagerService=o,this._numfmtService=l,this._componentManager=c,this._sidebarService=d,this._localeService=f,this._sheetsNumfmtCellContentController=p,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener(),this._initNumfmtLocalChange()}_initNumfmtLocalChange(){this.disposeWithMe(x.merge(this._sheetsNumfmtCellContentController.local$,this._localeService.currentLocale$).subscribe(()=>{this._forceUpdate()}))}openPanel(){var P;const e=this._sidebarService,r=this._selectionManagerService,n=this._commandService,i=this._univerInstanceService,a=this._numfmtService,o=this._localeService,c=(((P=r.getCurrentSelections())==null?void 0:P.map(C=>C.range))||[])[0];if(!c)return!1;const d=i.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),f=d.getActiveSheet();if(!f)return!1;const p=f.getCellRaw(c.startRow,c.startColumn),v=a.getValue(d.getUnitId(),f.getSheetId(),c.startRow,c.startColumn);let S="";v&&(S=v.pattern);const y=(p==null?void 0:p.t)===s.CellValueType.NUMBER?p.v:12345678,h={onChange:C=>{var R;if(C.type==="change")this._previewPattern=C.value,this._forceUpdate();else if(C.type==="confirm"){const O=((R=r.getCurrentSelections())==null?void 0:R.map(B=>B.range))||[],Z={values:[]},ie=m.getPatternType(C.value);O.forEach(B=>{s.Range.foreach(B,(se,T)=>{Z.values.push({row:se,col:T,pattern:C.value,type:ie})})}),n.executeCommand(m.SetNumfmtCommand.id,Z),e.close()}else C.type==="cancel"&&e.close()},value:{defaultPattern:S,defaultValue:y,row:c.startRow,col:c.startColumn}};return this._sidebarDisposable=e.open({header:{title:o.t("sheet.numfmt.title")},children:{label:pe,...h},onClose:()=>{this._forceUpdate(),n.executeCommand($.id)}}),!0}_forceUpdate(e){var n;const r=this._renderManagerService.getRenderById(e!=null?e:this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET).getUnitId());r==null||r.with(E.SheetSkeletonManagerService).reCalculate(),(n=r==null?void 0:r.mainComponent)==null||n.makeDirty()}_initCommands(){[L,$].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initPanel(){this._componentManager.register(pe,Ze)}_initRealTimeRenderingInterceptor(){const e=new x.Observable(n=>{this._commandService.onCommandExecuted(i=>{i.id===L.id&&n.next(!0),i.id===$.id&&n.next(!1)})}),r=x.combineLatest([e,this._selectionManagerService.selectionMoveEnd$.pipe(V.map(n=>n?n.map(i=>i.range):[]))]);this.disposeWithMe(s.toDisposable(r.pipe(V.switchMap(([n,i])=>new x.Observable(a=>{const o=new s.DisposableCollection;return n&&i.length&&a.next({selectionRanges:i,disposableCollection:o}),()=>{o.dispose()}})),V.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:n,selectionRanges:i})=>{var o,l;const a=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);this.openPanel(),n.add(this._sheetInterceptorService.intercept(g.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,effect:s.InterceptorEffectEnum.Value|s.InterceptorEffectEnum.Style,handler:(c,d,f)=>{const{row:p,col:v}=d,S=f(c)||{};if(i.find(y=>y.startColumn<=v&&y.endColumn>=v&&y.startRow<=p&&y.endRow>=p)){const y=d.worksheet.getCellRaw(p,v),h=y==null?void 0:y.v,P=y==null?void 0:y.t;if(h==null||P!==s.CellValueType.NUMBER||this._previewPattern===null)return S;const C=m.getPatternPreviewIgnoreGeneral(this._previewPattern,h,this._sheetsNumfmtCellContentController.local);if(C.color){const O=this._themeService.getCurrentTheme()[`${C.color}500`];return{...S,v:C.result,t:s.CellValueType.STRING,s:{cl:{rgb:O}}}}return{...S,v:C.result,t:s.CellValueType.STRING}}return S}})),(l=(o=this._renderManagerService.getRenderById(a.getUnitId()))==null?void 0:o.mainComponent)==null||l.makeDirty()})))}_commandExecutedListener(){const e=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id];this.disposeWithMe(new x.Observable(r=>{const n=this._commandService.onCommandExecuted(i=>{if(e.includes(i.id)){const a=i.params;r.next(a.unitId)}});return()=>n.dispose()}).pipe(V.debounceTime(16)).subscribe(r=>this._forceUpdate(r)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_SHEET).subscribe(e=>{var r;e||((r=this._sidebarDisposable)==null||r.dispose(),this._sidebarDisposable=null)})}};A=Xe([D(0,s.Inject(g.SheetInterceptorService)),D(1,s.Inject(s.ThemeService)),D(2,s.IUniverInstanceService),D(3,s.ICommandService),D(4,s.Inject(g.SheetsSelectionsService)),D(5,U.IRenderManagerService),D(6,g.INumfmtService),D(7,s.Inject(I.ComponentManager)),D(8,I.ISidebarService),D(9,s.Inject(s.LocaleService)),D(10,s.Inject(m.SheetsNumfmtCellContentController))],A);var Qe=Object.defineProperty,$e=Object.getOwnPropertyDescriptor,qe=(t,e,r,n)=>{for(var i=n>1?void 0:n?$e(e,r):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(n?o(e,r,i):o(i))||i);return n&&i&&Qe(e,r,i),i},W=(t,e)=>(r,n)=>e(r,n,t);const et=()=>{let t=[];return{add:(i,a,o,l,c)=>t.push({unitId:i,subUnitId:a,row:o,col:l,value:c}),getEffects:()=>t,clean:()=>{t=[]}}};let G=class extends s.Disposable{constructor(e,r,n,i,a){super();z(this,"_collectEffectMutation",et());this._sheetInterceptorService=e,this._numfmtService=r,this._univerInstanceService=n,this._injector=i,this._editorBridgeService=a,this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(s.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.BEFORE_CELL_EDIT,{handler:(e,r,n)=>{const i=r.row,a=r.col,o=this._numfmtService.getValue(r.unitId,r.subUnitId,i,a);if(o)switch(m.getPatternType(o.pattern)){case"scientific":case"currency":case"grouped":case"number":{const c=r.worksheet.getCellRaw(i,a);return n&&n(c)}case"percent":case"date":case"time":case"datetime":default:return n&&n(e)}return n(e)}})))}_initInterceptorEditorEnd(){this.disposeWithMe(s.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.AFTER_CELL_EDIT,{handler:(e,r,n)=>{var f,p,v,S;this._collectEffectMutation.clean();const i=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col),a=(f=i&&m.getPatternType(i.pattern))!=null?f:"",o=()=>{i&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,null)};if(!(e!=null&&e.v)&&!(e!=null&&e.p)||(i==null?void 0:i.pattern)===J.DEFAULT_TEXT_FORMAT||e.t===s.CellValueType.FORCE_STRING)return n(e);const l=(p=e.p)==null?void 0:p.body,c=(S=(v=e==null?void 0:e.p)==null?void 0:v.body)!=null&&S.dataStream?e.p.body.dataStream.replace(/\r\n$/,""):String(e.v),d=s.numfmt.parseDate(c)||s.numfmt.parseTime(c)||s.numfmt.parseNumber(c);if(l)if(nt(l)){const{dataStream:y}=l,h=y.replace(/\r\n$/,""),P=Number(h);if(Number.isNaN(P)&&!d)return n(e)}else return n(e);if(d){d.z&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:d.z});const y=Number(d.v);return n({...e,p:void 0,v:y,t:s.CellValueType.NUMBER})}else(["date","time","datetime","percent"].includes(a)||!tt(c))&&o();return n(e)}})))}_initInterceptorCommands(){const e=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(r){var n;switch(r.id){case g.SetRangeValuesCommand.id:{const i=e._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),a=i.getUnitId(),o=(n=i.getActiveSheet())==null?void 0:n.getSheetId();if(!o)return{redos:[],undos:[]};const l=e._collectEffectMutation.getEffects();if(e._collectEffectMutation.clean(),!l.length)return{redos:[],undos:[]};const c=l.filter(v=>{var S;return!!((S=v.value)!=null&&S.pattern)}).map(v=>({row:v.row,col:v.col,pattern:v.value.pattern})),d=l.filter(v=>{var S;return!((S=v.value)!=null&&S.pattern)}).map(v=>({startRow:v.row,endColumn:v.col,startColumn:v.col,endRow:v.row})),f=[],p=[];if(c.length){const v={id:g.SetNumfmtMutation.id,params:g.transformCellsToRange(a,o,c)};f.push(v),p.push(...g.factorySetNumfmtUndoMutation(e._injector,v.params))}if(d.length){const v={id:g.RemoveNumfmtMutation.id,params:{unitId:a,subUnitId:o,ranges:d}};f.push(v),p.push(...g.factoryRemoveNumfmtUndoMutation(e._injector,v.params))}return{redos:f,undos:p.reverse()}}}return{redos:[],undos:[]}}}))}};G=qe([W(0,s.Inject(g.SheetInterceptorService)),W(1,s.Inject(g.INumfmtService)),W(2,s.Inject(s.IUniverInstanceService)),W(3,s.Inject(s.Injector)),W(4,s.Optional(E.IEditorBridgeService))],G);function tt(t){return/^-?\d+(\.\d+)?$/.test(t)}function nt(t){const{textRuns:e=[],paragraphs:r=[],customRanges:n,customBlocks:i=[]}=t,a=["va"];return!(e.some(o=>!!(o.ts&&Object.keys(o.ts).some(c=>a.includes(c))))||r.some(o=>o.bullet)||r.length>=2||n!=null&&n.length||i.length>0)}const K=[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:J.DEFAULT_TEXT_FORMAT},"|",{label:"sheet.numfmt.number",pattern:"0"},"|",{label:"sheet.numfmt.accounting",pattern:'"¥" #,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.financialValue",pattern:"#,##0.00;[Red]#,##0.00"},{label:"sheet.numfmt.currency",pattern:'"¥"#,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.roundingCurrency",pattern:'"¥"#,##0;[Red]"¥"#,##0'},"|",{label:"sheet.numfmt.date",pattern:"yyyy-mm-dd;@"},{label:"sheet.numfmt.time",pattern:'am/pm h":"mm":"ss'},{label:"sheet.numfmt.dateTime",pattern:"yyyy-m-d am/pm h:mm"},{label:"sheet.numfmt.timeDuration",pattern:"h:mm:ss"},"|",{label:"sheet.numfmt.moreFmt",pattern:""}],rt=t=>({icon:new x.Observable(e=>{const r=t.get(m.MenuCurrencyService);function n(a){return{[m.countryCurrencyMap.US]:"DollarSingle",[m.countryCurrencyMap.RU]:"RoubleSingle",[m.countryCurrencyMap.CN]:"RmbSingle",[m.countryCurrencyMap.AT]:"EuroSingle"}[a]||"DollarSingle"}const i=m.countryCurrencyMap[r.getCurrencySymbol()]||"$";return e.next(n(i)),r.currencySymbol$.subscribe(a=>{const o=m.countryCurrencyMap[a]||"$";e.next(n(o))})}),id:m.SetCurrencyCommand.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:I.MenuItemType.BUTTON,hidden$:I.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(t,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),it=t=>({icon:"AddDigitsSingle",id:m.AddDecimalCommand.id,title:"sheet.numfmt.addDecimal",tooltip:"sheet.numfmt.addDecimal",type:I.MenuItemType.BUTTON,hidden$:I.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(t,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),st=t=>({icon:"ReduceDigitsSingle",id:m.SubtractDecimalCommand.id,title:"sheet.numfmt.subtractDecimal",tooltip:"sheet.numfmt.subtractDecimal",type:I.MenuItemType.BUTTON,hidden$:I.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(t,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),at=t=>({icon:"PercentSingle",id:m.SetPercentCommand.id,title:"sheet.numfmt.percent",tooltip:"sheet.numfmt.percent",type:I.MenuItemType.BUTTON,hidden$:I.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(t,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),ot=t=>{const e=t.get(s.IUniverInstanceService),r=t.get(s.ICommandService),n=t.get(s.LocaleService),i=t.get(g.SheetsSelectionsService),a=E.deriveStateFromActiveSheet$(e,"",({workbook:o,worksheet:l})=>new x.Observable(c=>x.merge(i.selectionMoveEnd$,new x.Observable(d=>{const f=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id],p=r.onCommandExecuted(v=>{f.includes(v.id)&&d.next(null)});return()=>p.dispose()})).subscribe(()=>{var f,p;const d=i.getCurrentSelections();if(d&&d[0]){const v=d[0].range,S=v.startRow,y=v.startColumn,h=(p=o.getStyles().get((f=l.getCell(S,y))==null?void 0:f.s))==null?void 0:p.n,P=h==null?void 0:h.pattern;let C=n.t("sheet.numfmt.general");if(P){const R=K.filter(O=>typeof O=="object"&&O.pattern).find(O=>m.isPatternEqualWithoutDecimal(P,O.pattern));R&&typeof R=="object"&&R.pattern?C=n.t(R.label):C=n.t("sheet.numfmt.moreFmt")}c.next(C)}})));return{label:fe,id:L.id,tooltip:"sheet.numfmt.title",type:I.MenuItemType.SELECTOR,selections:[{label:{name:ve,hoverable:!1}}],value$:a,hidden$:I.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(t,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetSetCellStylePermission,g.WorksheetEditPermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}},fe="sheet.numfmt.moreNumfmtType",ve="sheet.numfmt.moreNumfmtType.options",ct=t=>{var n;const e=s.useDependency(s.LocaleService),r=(n=t.value)!=null?n:e.t("sheet.numfmt.general");return u.jsx("span",{className:"more-numfmt-type",children:r})},lt=()=>{const t=s.useDependency(s.ICommandService),e=s.useDependency(s.LocaleService),r=s.useDependency(I.ILayoutService),n=s.useDependency(m.SheetsNumfmtCellContentController),i=s.useDependency(g.SheetsSelectionsService),a=c=>{const d=i.getCurrentLastSelection();if(!d)return;const f=d.range,p=[];s.Range.foreach(f,(v,S)=>{c?p.push({row:v,col:S,pattern:c,type:m.getPatternType(c)}):p.push({row:v,col:S})}),t.executeCommand(m.SetNumfmtCommand.id,{values:p}),r.focus()},o=c=>{if(c===0)a(null);else if(c===K.length-1)t.executeCommand(L.id);else{const d=K[c];d.pattern&&a(d.pattern)}},l=1220;return u.jsx("div",{className:"more-numfmt-type-options",children:K.map((c,d)=>c==="|"?u.jsx("div",{className:"line m-t-4",onClick:f=>f.stopPropagation()},d):u.jsxs("div",{className:"option-item m-t-4",onClick:()=>{o(d)},children:[u.jsx("div",{children:e.t(c.label)}),u.jsx("div",{className:"m-l-26",children:c.pattern?m.getPatternPreview(c.pattern||"",l,n.local).result:""})]},d))})},ut={[I.RibbonStartGroup.FORMULAS_INSERT]:{[m.SetCurrencyCommand.id]:{order:4,menuItemFactory:rt},[m.AddDecimalCommand.id]:{order:5,menuItemFactory:it},[m.SubtractDecimalCommand.id]:{order:6,menuItemFactory:st},[m.SetPercentCommand.id]:{order:7,menuItemFactory:at},[L.id]:{order:8,menuItemFactory:ot}}};var mt=Object.defineProperty,dt=Object.getOwnPropertyDescriptor,pt=(t,e,r,n)=>{for(var i=n>1?void 0:n?dt(e,r):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(n?o(e,r,i):o(i))||i);return n&&i&&mt(e,r,i),i},he=(t,e)=>(r,n)=>e(r,n,t);let Y=class extends s.Disposable{constructor(t,e){super(),this._componentManager=t,this._menuManagerService=e,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(ut),this.disposeWithMe(this._componentManager.register(fe,ct)),this.disposeWithMe(this._componentManager.register(ve,lt))}};Y=pt([he(0,s.Inject(I.ComponentManager)),he(1,I.IMenuManagerService)],Y);var Se=Object.defineProperty,ft=Object.getOwnPropertyDescriptor,vt=(t,e,r)=>e in t?Se(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ht=(t,e,r,n)=>{for(var i=n>1?void 0:n?ft(e,r):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(n?o(e,r,i):o(i))||i);return n&&i&&Se(e,r,i),i},re=(t,e)=>(r,n)=>e(r,n,t),ge=(t,e,r)=>vt(t,typeof e!="symbol"?e+"":e,r);const St="SHEET_NUMFMT_UI_PLUGIN";b.UniverSheetsNumfmtUIPlugin=class extends s.Plugin{constructor(e=ae,r,n,i){super(),this._config=e,this._injector=r,this._configService=n,this._renderManagerService=i;const{menu:a,...o}=s.merge({},ae,this._config);a&&this._configService.setConfig("menu",a,{merge:!0}),this._configService.setConfig(I.UI_PLUGIN_CONFIG_KEY,o)}onStarting(){s.registerDependencies(this._injector,[[A],[G],[H],[Y]])}onRendered(){this._registerRenderModules(),s.touchDependencies(this._injector,[[A],[G],[Y]])}_registerRenderModules(){[[Q]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(s.UniverInstanceType.UNIVER_SHEET,r))})}},ge(b.UniverSheetsNumfmtUIPlugin,"pluginName",St),ge(b.UniverSheetsNumfmtUIPlugin,"type",s.UniverInstanceType.UNIVER_SHEET),b.UniverSheetsNumfmtUIPlugin=ht([s.DependentOn(E.UniverSheetsUIPlugin,m.UniverSheetsNumfmtPlugin),re(1,s.Inject(s.Injector)),re(2,s.IConfigService),re(3,U.IRenderManagerService)],b.UniverSheetsNumfmtUIPlugin),Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});