@univerjs/sheets-numfmt-ui 0.6.3 → 0.6.4

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