@univerjs/sheets-numfmt-ui 0.6.1 → 0.6.2

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 +1,5 @@
1
- "use strict";var pe=Object.defineProperty;var ve=(e,t,r)=>t in e?pe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var A=(e,t,r)=>ve(e,typeof t!="symbol"?t+"":t,r);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"),P=require("@univerjs/design"),ne={};var Se=Object.getOwnPropertyDescriptor,ye=(e,t,r,n)=>{for(var s=n>1?void 0:n?Se(t,r):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=o(s)||s);return s},U=(e,t)=>(r,n)=>t(r,n,e);const z="SHEET_NUMFMT_ALERT";let ee=class extends c.Disposable{constructor(e,t,r,n,s,i,o){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=r,this._localeService=n,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 r=e.location,n=this._context.unit,s=n.getActiveSheet();if(!s)return;const i=r.unitId,o=r.subUnitId;let l;const a=s.getCell(r.row,r.col);if(a!=null&&a.s){const d=n.getStyles().get(a.s);d!=null&&d.n&&(l=d.n)}if(l||(l=this._numfmtService.getValue(i,o,r.row,r.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===r.row&&v.col===r.col&&v.subUnitId===r.subUnitId&&v.unitId===r.unitId)return;this._cellAlertManagerService.showAlert({type:M.CellAlertType.ERROR,title:this._localeService.t("info.error"),message:this._localeService.t("info.forceStringInfo"),location:r,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,r,n)=>{for(var s=n>1?void 0:n?_e(t,r):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=o(s)||s);return s},Ce=(e,t)=>(r,n)=>t(r,n,e);const te=y.createContext([]);let L=class{constructor(e){this._localStorageService=e}_getKey(e){return`userHabitController_${e}`}async addHabit(e,t){const r=this._getKey(e);return this._localStorageService.getItem(r).then(n=>{n||this._localStorageService.setItem(r,t)})}markHabit(e,t){const r=this._getKey(e);this._localStorageService.getItem(r).then(n=>{if(n){const s=n.findIndex(i=>i===t);s>-1&&n.splice(s,1),n.unshift(t),this._localStorageService.setItem(r,n)}})}async getHabit(e,t){const r=this._getKey(e),n=await this._localStorageService.getItem(r);if(t&&n){const s=n.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 n||[]}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),[r,n]=y.useState(m.currencySymbols);return y.useEffect(()=>{t.addHabit("numfmtCurrency",[]).then(()=>{t.getHabit(re,[...m.currencySymbols]).then(i=>{n(i),e&&e(i)})})},[]),{userHabitCurrency:r,mark:i=>{t.markHabit(re,i)}}},Ne=()=>{const e=y.useRef([]),[t,r]=y.useState({});return y.useEffect(()=>{e.current.forEach(s=>{s()}),e.current=[]},[t]),s=>{e.current.push(s),r({})}},Te=e=>!!m.getCurrencyType(e)&&e.startsWith("_("),Ee=e=>{const{defaultPattern:t,action:r,onChange:n}=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;r.current=()=>m.setPatternDecimal(`_("${l}"* #,##0${s>0?".0":""}_)`,s);const f=_=>{a(_),n(m.setPatternDecimal(`_("${_}"* #,##0${s>0?".0":""}_)`,s))},S=_=>{const p=_||0;i(p),n(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(P.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(P.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 r=b.useDependency(c.LocaleService).t,n=y.useContext(te),[s,i]=y.useState(()=>m.getCurrencyType(e.defaultPattern)||n[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(T=>m.isPatternEqualWithoutDecimal(T.value,e.defaultPattern)))==null?void 0:C.value)||p[0].value}),v=y.useMemo(()=>m.getCurrencyFormatOptions(s),[s]),h=y.useMemo(()=>n.map(p=>({label:p,value:p})),[n]);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:r("sheet.numfmt.decimalLength")}),u.jsx("div",{className:"m-t-8 w-120",children:u.jsx(P.InputNumber,{value:o,max:20,min:0,onChange:_})})]}),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(P.Select,{onChange:f,options:h,value:s})})]})]}),u.jsx("div",{className:"m-t-16 label",children:r("sheet.numfmt.negType")}),u.jsx("div",{className:"m-t-8",children:u.jsx(P.SelectList,{onChange:S,options:v,value:a})}),u.jsx("div",{className:"describe m-t-14",children:r("sheet.numfmt.currencyDes")})]})};var E=function(){return E=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(e[s]=t[s])}return e},E.apply(this,arguments)},je=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,n=Object.getOwnPropertySymbols(e);s<n.length;s++)t.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(e,n[s])&&(r[n[s]]=e[n[s]]);return r},ce=y.forwardRef(function(e,t){var r=e.icon,n=e.id,s=e.className,i=e.extend,o=je(e,["icon","id","className","extend"]),l="univerjs-icon univerjs-icon-".concat(n," ").concat(s||"").trim(),a=y.useRef("_".concat(Re()));return ae(r,"".concat(n),{defIds:r.defIds,idSuffix:a.current},E({ref:t,className:l},o),i)});function ae(e,t,r,n,s){return y.createElement(e.tag,E(E({key:t},xe(e,r,s)),n),(De(e,r).children||[]).map(function(i,o){return ae(i,"".concat(t,"-").concat(e.tag,"-").concat(o),r,void 0,s)}))}function xe(e,t,r){var n=E({},e.attrs);r!=null&&r.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=r.colorChannel1),e.tag==="mask"&&n.id&&(n.id=n.id+t.idSuffix),Object.entries(n).forEach(function(i){var o=i[0],l=i[1];o==="mask"&&typeof l=="string"&&(n[o]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var s=t.defIds;return!s||s.length===0||(e.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(function(i){var o=i[0],l=i[1];typeof l=="string"&&(n[o]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function De(e,t){var r,n=t.defIds;return!n||n.length===0?e:e.tag==="defs"&&(!((r=e.children)===null||r===void 0)&&r.length)?E(E({},e),{children:e.children.map(function(s){return typeof s.attrs.id=="string"&&n&&n.indexOf(s.attrs.id)>-1?E(E({},s),{attrs:E(E({},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:r,onChange:n}=e,s=b.useDependency(L),i=b.useDependency(c.ILocalStorageService),o=b.useDependency(c.LocaleService),[l,a]=y.useState(t);r.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),n(S)},f=()=>{n(l)};return u.jsxs("div",{className:R.customFormat,children:[u.jsx("div",{className:R.customFormatTitle,children:o.t("sheet.numfmt.customFormat")}),u.jsx(P.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(r=>r.value).includes(e)||["date","datetime","time"].includes(t.type)},We=e=>{const t=y.useMemo(m.getDateFormatOptions,[]),n=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:n("sheet.numfmt.dateType")}),u.jsx("div",{className:"m-t-8",children:u.jsx(P.SelectList,{value:s,options:t,onChange:o})}),u.jsx("div",{className:"describe m-t-14",children:n("sheet.numfmt.dateDes")})]})},Ve=e=>!e,Be=e=>{const r=b.useDependency(c.LocaleService).t;return e.action.current=()=>"",u.jsx("div",{children:u.jsx("div",{className:"describe m-t-14",children:r("sheet.numfmt.generalDes")})})},qe=e=>m.getNumberFormatOptions().some(t=>m.isPatternEqualWithoutDecimal(t.value,e)),Ge=e=>{const t=b.useDependency(c.LocaleService),r=y.useMemo(m.getNumberFormatOptions,[]),[n,s]=y.useState(()=>m.getDecimalFromPattern(e.defaultPattern||"",0)),[i,o]=y.useState(()=>{const h=r.find(f=>m.isPatternEqualWithoutDecimal(f.value,e.defaultPattern||""));return(h==null?void 0:h.value)||r[0].value}),l=y.useMemo(()=>m.setPatternDecimal(i,Number(n||0)),[i,n]),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(P.InputNumber,{disabled:a,value:n,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(P.SelectList,{onChange:v,options:r,value:i})}),u.jsx("div",{className:"describe m-t-14",children:t.t("sheet.numfmt.thousandthPercentileDes")})]})},Ke=e=>{const{defaultValue:t,defaultPattern:r,row:n,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(()=>`${n}_${s}`),{mark:_,userHabitCurrency:p}=Ie(()=>S(`${n}_${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(r)?d[fe].label:""),"")||d[0].label}const T=d.map(I=>({label:I.label,value:I.label})),x=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:r,action:o};return y.useEffect(()=>{h(C()),S(`${n}_${s}`)},[n,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(P.Select,{onChange:x,options:T,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(P.Button,{size:"small",onClick:w,className:"m-r-12",children:l("sheet.numfmt.cancel")}),u.jsx(P.Button,{type:"primary",size:"small",onClick:K,children:l("sheet.numfmt.confirm")})]})]})};var Ze=Object.getOwnPropertyDescriptor,ze=(e,t,r,n)=>{for(var s=n>1?void 0:n?Ze(t,r):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=o(s)||s);return s},j=(e,t)=>(r,n)=>t(r,n,e);const se="SHEET_NUMFMT_PANEL";let $=class extends c.Disposable{constructor(t,r,n,s,i,o,l,a,d,v,h){super();A(this,"_previewPattern","");A(this,"_sidebarDisposable",null);this._sheetInterceptorService=t,this._themeService=r,this._univerInstanceService=n,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,r=this._selectionManagerService,n=this._commandService,s=this._univerInstanceService,i=this._numfmtService,o=this._localeService,a=(((N=r.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 T;if(C.type==="change")this._previewPattern=C.value,this._forceUpdate();else if(C.type==="confirm"){const x=((T=r.getCurrentSelections())==null?void 0:T.map(w=>w.range))||[],H={values:[]},K=m.getPatternType(C.value);x.forEach(w=>{c.Range.foreach(w,(Z,I)=>{H.values.push({row:Z,col:I,pattern:C.value,type:K})})}),n.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(),n.executeCommand(Y.id)}}),!0}_forceUpdate(t){var n;const r=this._renderManagerService.getRenderById(t!=null?t:this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET).getUnitId());r==null||r.with(M.SheetSkeletonManagerService).reCalculate(),(n=r==null?void 0:r.mainComponent)==null||n.makeDirty()}_initCommands(){[F,Y].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initPanel(){this._componentManager.register(se,Ke)}_initRealTimeRenderingInterceptor(){const t=new D.Observable(n=>{this._commandService.onCommandExecuted(s=>{s.id===F.id&&n.next(!0),s.id===Y.id&&n.next(!1)})}),r=D.combineLatest([t,this._selectionManagerService.selectionMoveEnd$.pipe(W.map(n=>n?n.map(s=>s.range):[]))]);this.disposeWithMe(c.toDisposable(r.pipe(W.switchMap(([n,s])=>new D.Observable(i=>{const o=new c.DisposableCollection;return n&&s.length&&i.next({selectionRanges:s,disposableCollection:o}),()=>{o.dispose()}})),W.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:n,selectionRanges:s})=>{var o,l;const i=this._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET);this.openPanel(),n.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 x=this._themeService.getCurrentTheme()[`${C.color}500`];return{...S,v:C.result,t:c.CellValueType.STRING,s:{cl:{rgb:x}}}}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(r=>{const n=this._commandService.onCommandExecuted(s=>{if(t.includes(s.id)){const i=s.params;r.next(i.unitId)}});return()=>n.dispose()}).pipe(W.debounceTime(16)).subscribe(r=>this._forceUpdate(r)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(c.UniverInstanceType.UNIVER_SHEET).subscribe(t=>{var r;t||((r=this._sidebarDisposable)==null||r.dispose(),this._sidebarDisposable=null)})}};$=ze([j(0,c.Inject(g.SheetInterceptorService)),j(1,c.Inject(c.ThemeService)),j(2,c.IUniverInstanceService),j(3,c.ICommandService),j(4,c.Inject(g.SheetsSelectionsService)),j(5,oe.IRenderManagerService),j(6,g.INumfmtService),j(7,c.Inject(b.ComponentManager)),j(8,b.ISidebarService),j(9,c.Inject(c.LocaleService)),j(10,c.Inject(m.SheetsNumfmtCellContentController))],$);var Ye=Object.getOwnPropertyDescriptor,Xe=(e,t,r,n)=>{for(var s=n>1?void 0:n?Ye(t,r):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=o(s)||s);return s},k=(e,t)=>(r,n)=>t(r,n,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,r,n,s,i){super();A(this,"_collectEffectMutation",Je());this._sheetInterceptorService=t,this._numfmtService=r,this._univerInstanceService=n,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,r,n)=>{const s=r.row,i=r.col,o=this._numfmtService.getValue(r.unitId,r.subUnitId,s,i);if(o)switch(m.getPatternType(o.pattern)){case"scientific":case"currency":case"grouped":case"number":{const a=r.worksheet.getCellRaw(s,i);return n&&n(a)}case"percent":case"date":case"time":case"datetime":default:return n&&n(t)}return n(t)}})))}_initInterceptorEditorEnd(){this.disposeWithMe(c.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.AFTER_CELL_EDIT,{handler:(t,r,n)=>{var v,h,f,S;this._collectEffectMutation.clean();const s=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col),i=(v=s&&m.getPatternType(s.pattern))!=null?v:"",o=()=>{s&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.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 n(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 n(t)}else return n(t);if(d){d.z&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:d.z});const _=Number(d.v);return n({...t,p:void 0,v:_,t:c.CellValueType.NUMBER})}else(["date","time","datetime","percent"].includes(i)||!Qe(a))&&o();return n(t)}})))}_initInterceptorCommands(){const t=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(r){var n;switch(r.id){case g.SetRangeValuesCommand.id:{const s=t._univerInstanceService.getCurrentUnitForType(c.UniverInstanceType.UNIVER_SHEET),i=s.getUnitId(),o=(n=s.getActiveSheet())==null?void 0:n.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:r=[],customRanges:n,customBlocks:s=[]}=e,i=["va"];return!(t.some(o=>!!(o.ts&&Object.keys(o.ts).some(a=>i.includes(a))))||r.some(o=>o.bullet)||r.length>=2||n!=null&&n.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 r=e.get(m.MenuCurrencyService);function n(i){return{[m.countryCurrencyMap.US]:"DollarSingle",[m.countryCurrencyMap.RU]:"RoubleSingle",[m.countryCurrencyMap.CN]:"RmbSingle",[m.countryCurrencyMap.AT]:"EuroSingle"}[i]||"DollarSingle"}const s=m.countryCurrencyMap[r.getCurrencySymbol()]||"$";return t.next(n(s)),r.currencySymbol$.subscribe(i=>{const o=m.countryCurrencyMap[i]||"$";t.next(n(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),r=e.get(c.ICommandService),n=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=r.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=n.t("sheet.numfmt.general");if(G.isDefaultFormat(N)){a.next(C);return}if(N){const T=V.filter(x=>typeof x=="object"&&x.pattern).find(x=>m.isPatternEqualWithoutDecimal(N,x.pattern));T&&typeof T=="object"&&T.pattern?C=n.t(T.label):C=n.t("sheet.numfmt.moreFmt")}a.next(C)}})));return{label:ue,id:F.id,tooltip:"sheet.numfmt.title",type:b.MenuItemType.SELECTOR,selections:[{label:{name:me,hoverable:!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=>{var n;const t=b.useDependency(c.LocaleService),r=(n=e.value)!=null?n:t.t("sheet.numfmt.general");return u.jsx("span",{className:"more-numfmt-type",children:r})},ct=()=>{const e=b.useDependency(c.ICommandService),t=b.useDependency(c.LocaleService),r=b.useDependency(b.ILayoutService),n=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}),r.focus()},o=a=>{if(a===0)i(null);else if(a===V.length-1)e.executeCommand(F.id);else{const d=V[a];d.pattern&&i(d.pattern)}},l=1220;return u.jsx("div",{className:"more-numfmt-type-options",children:V.map((a,d)=>a==="|"?u.jsx("div",{className:"line m-t-4",onClick:v=>v.stopPropagation()},d):u.jsxs("div",{className:"option-item m-t-4",onClick:()=>{o(d)},children:[u.jsx("div",{children:t.t(a.label)}),u.jsx("div",{className:"m-l-26",children:a.pattern?m.getPatternPreview(a.pattern||"",l,n.local).result:""})]},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,r,n)=>{for(var s=n>1?void 0:n?lt(t,r):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=o(s)||s);return s},ie=(e,t)=>(r,n)=>t(r,n,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,r)=>t in e?mt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ft=(e,t,r,n)=>{for(var s=n>1?void 0:n?dt(t,r):t,i=e.length-1,o;i>=0;i--)(o=e[i])&&(s=o(s)||s);return s},Q=(e,t)=>(r,n)=>t(r,n,e),de=(e,t,r)=>ht(e,typeof t!="symbol"?t+"":t,r);const pt="SHEET_NUMFMT_UI_PLUGIN";exports.UniverSheetsNumfmtUIPlugin=class extends c.Plugin{constructor(t=ne,r,n,s){super(),this._config=t,this._injector=r,this._configService=n,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(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(c.UniverInstanceType.UNIVER_SHEET,r))})}};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);
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:`
2
+ univer-flex univer-h-7 univer-items-center univer-justify-between univer-gap-6 univer-rounded
3
+ univer-px-2 univer-text-[13px]
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);
package/lib/es/index.js CHANGED
@@ -1,22 +1,22 @@
1
1
  var ut = Object.defineProperty;
2
2
  var dt = (e, t, r) => t in e ? ut(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
3
  var J = (e, t, r) => dt(e, typeof t != "symbol" ? t + "" : t, r);
4
- import { Inject as S, LocaleService as M, Disposable as oe, isRealNum as ht, CommandType as He, ILocalStorageService as xe, numfmt as Q, ThemeService as ft, IUniverInstanceService as Se, ICommandService as ye, UniverInstanceType as T, CellValueType as $, toDisposable as ge, DisposableCollection as pt, InterceptorEffectEnum as Oe, Range as Ae, Injector as je, Optional as vt, DependentOn as gt, IConfigService as _t, Plugin as St, merge as yt, registerDependencies as bt, touchDependencies as Ct } from "@univerjs/core";
4
+ import { Inject as S, LocaleService as M, Disposable as oe, isRealNum as ht, CommandType as Le, ILocalStorageService as He, numfmt as Q, ThemeService as ft, IUniverInstanceService as Se, ICommandService as ye, UniverInstanceType as T, CellValueType as $, toDisposable as ge, DisposableCollection as pt, InterceptorEffectEnum as Oe, Range as Ae, Injector as je, Optional as vt, DependentOn as gt, IConfigService as _t, Plugin as St, merge as yt, registerDependencies as bt, touchDependencies as Ct } from "@univerjs/core";
5
5
  import { IRenderManagerService as Be } from "@univerjs/engine-render";
6
6
  import { currencySymbols as Ue, getDecimalFromPattern as te, getCurrencyType as W, setPatternDecimal as R, getCurrencyFormatOptions as ue, isPatternEqualWithoutDecimal as ce, CURRENCYFORMAT as It, DATEFMTLISG as Nt, NUMBERFORMAT as Et, getDateFormatOptions as We, getNumberFormatOptions as Ve, isPatternHasDecimal as Tt, SheetsNumfmtCellContentController as Ge, getPatternPreviewIgnoreGeneral as Mt, getPatternType as ne, SetNumfmtCommand as Ke, SetPercentCommand as Ze, SubtractDecimalCommand as ze, AddDecimalCommand as Ye, SetCurrencyCommand as Xe, MenuCurrencyService as Pt, countryCurrencyMap as k, getPatternPreview as wt, UniverSheetsNumfmtPlugin as Rt } from "@univerjs/sheets-numfmt";
7
- import { HoverManagerService as Ot, CellAlertManagerService as Ut, CellAlertType as Dt, SheetSkeletonManagerService as kt, IEditorBridgeService as Ft, deriveStateFromActiveSheet$ as $t, getCurrentRangeDisable$ as V, UniverSheetsUIPlugin as Lt } from "@univerjs/sheets-ui";
8
- import { IZenZoneService as Ht, useDependency as C, ComponentManager as qe, ISidebarService as xt, getMenuHiddenObservable as G, MenuItemType as K, ILayoutService as At, RibbonStartGroup as jt, IMenuManagerService as Bt, UI_PLUGIN_CONFIG_KEY as Wt } from "@univerjs/ui";
7
+ import { HoverManagerService as Ot, CellAlertManagerService as Ut, CellAlertType as Dt, SheetSkeletonManagerService as kt, IEditorBridgeService as Ft, deriveStateFromActiveSheet$ as $t, getCurrentRangeDisable$ as V, UniverSheetsUIPlugin as xt } from "@univerjs/sheets-ui";
8
+ import { IZenZoneService as Lt, useDependency as C, ComponentManager as qe, ISidebarService as Ht, getMenuHiddenObservable as G, MenuItemType as K, ILayoutService as At, RibbonStartGroup as jt, IMenuManagerService as Bt, UI_PLUGIN_CONFIG_KEY as Wt } from "@univerjs/ui";
9
9
  import { FormulaDataModel as Vt } from "@univerjs/engine-formula";
10
10
  import { isTextFormat as Je, isDefaultFormat as Gt, DEFAULT_TEXT_FORMAT_EXCEL as Kt } from "@univerjs/engine-numfmt";
11
11
  import { INumfmtService as be, SheetInterceptorService as Qe, SheetsSelectionsService as Ce, INTERCEPTOR_POINT as Zt, RemoveNumfmtMutation as Ie, SetNumfmtMutation as Ne, BEFORE_CELL_EDIT as zt, AFTER_CELL_EDIT as Yt, SetRangeValuesCommand as Xt, transformCellsToRange as qt, factorySetNumfmtUndoMutation as Jt, factoryRemoveNumfmtUndoMutation as Qt, RangeProtectionPermissionEditPoint as Z, WorksheetSetCellStylePermission as z, WorksheetEditPermission as Y, WorkbookEditablePermission as X } from "@univerjs/sheets";
12
- import { debounceTime as en, merge as et, Observable as L, combineLatest as tn } from "rxjs";
12
+ import { debounceTime as en, merge as et, Observable as x, combineLatest as tn } from "rxjs";
13
13
  import { map as nn, switchMap as rn, tap as sn, debounceTime as on } from "rxjs/operators";
14
14
  import { jsxs as b, jsx as u } from "react/jsx-runtime";
15
15
  import { createContext as cn, useState as I, useEffect as ae, useRef as Ee, useContext as tt, useMemo as O, forwardRef as nt, createElement as Te } from "react";
16
- import { InputNumber as Me, Select as Pe, SelectList as we, Input as an, Button as De } from "@univerjs/design";
16
+ import { InputNumber as Me, Select as Pe, SelectList as we, Input as an, Button as De, Separator as ln } from "@univerjs/design";
17
17
  const ke = {};
18
- var ln = Object.getOwnPropertyDescriptor, mn = (e, t, r, n) => {
19
- for (var i = n > 1 ? void 0 : n ? ln(t, r) : t, s = e.length - 1, o; s >= 0; s--)
18
+ var mn = Object.getOwnPropertyDescriptor, un = (e, t, r, n) => {
19
+ for (var i = n > 1 ? void 0 : n ? mn(t, r) : t, s = e.length - 1, o; s >= 0; s--)
20
20
  (o = e[s]) && (i = o(i) || i);
21
21
  return i;
22
22
  }, F = (e, t) => (r, n) => t(r, n, e);
@@ -73,31 +73,31 @@ let _e = class extends oe {
73
73
  this._cellAlertManagerService.removeAlert(de);
74
74
  }
75
75
  };
76
- _e = mn([
76
+ _e = un([
77
77
  F(1, S(Ot)),
78
78
  F(2, S(Ut)),
79
79
  F(3, S(M)),
80
80
  F(4, S(Vt)),
81
- F(5, Ht),
81
+ F(5, Lt),
82
82
  F(6, S(be))
83
83
  ], _e);
84
84
  const he = {
85
85
  id: "sheet.operation.close.numfmt.panel",
86
- type: He.OPERATION,
86
+ type: Le.OPERATION,
87
87
  handler: () => (
88
88
  // do nothing, just notify panel is closed
89
89
  !0
90
90
  )
91
91
  }, A = {
92
92
  id: "sheet.operation.open.numfmt.panel",
93
- type: He.OPERATION,
93
+ type: Le.OPERATION,
94
94
  handler: (e) => (e.get(B).openPanel(), !0)
95
95
  };
96
- var un = Object.getOwnPropertyDescriptor, dn = (e, t, r, n) => {
97
- for (var i = n > 1 ? void 0 : n ? un(t, r) : t, s = e.length - 1, o; s >= 0; s--)
96
+ var dn = Object.getOwnPropertyDescriptor, hn = (e, t, r, n) => {
97
+ for (var i = n > 1 ? void 0 : n ? dn(t, r) : t, s = e.length - 1, o; s >= 0; s--)
98
98
  (o = e[s]) && (i = o(i) || i);
99
99
  return i;
100
- }, hn = (e, t) => (r, n) => t(r, n, e);
100
+ }, fn = (e, t) => (r, n) => t(r, n, e);
101
101
  const Re = cn([]);
102
102
  let j = class {
103
103
  constructor(e) {
@@ -143,10 +143,10 @@ let j = class {
143
143
  this._localStorageService.removeItem(e);
144
144
  }
145
145
  };
146
- j = dn([
147
- hn(0, S(xe))
146
+ j = hn([
147
+ fn(0, S(He))
148
148
  ], j);
149
- const Fe = "numfmtCurrency", fn = (e) => {
149
+ const Fe = "numfmtCurrency", pn = (e) => {
150
150
  const t = C(j), [r, n] = I(Ue);
151
151
  return ae(() => {
152
152
  t.addHabit("numfmtCurrency", []).then(() => {
@@ -157,7 +157,7 @@ const Fe = "numfmtCurrency", fn = (e) => {
157
157
  }, []), { userHabitCurrency: r, mark: (s) => {
158
158
  t.markHabit(Fe, s);
159
159
  } };
160
- }, pn = () => {
160
+ }, vn = () => {
161
161
  const e = Ee([]), [t, r] = I({});
162
162
  return ae(() => {
163
163
  e.current.forEach((i) => {
@@ -166,7 +166,7 @@ const Fe = "numfmtCurrency", fn = (e) => {
166
166
  }, [t]), (i) => {
167
167
  e.current.push(i), r({});
168
168
  };
169
- }, vn = (e) => !!W(e) && e.startsWith("_("), gn = (e) => {
169
+ }, gn = (e) => !!W(e) && e.startsWith("_("), _n = (e) => {
170
170
  const { defaultPattern: t, action: r, onChange: n } = e, [i, s] = I(() => te(t || "", 2)), o = tt(Re), [a, c] = I(() => W(t) || o[0]), l = O(() => o.map((v) => ({ label: v, value: v })), []), m = C(M).t;
171
171
  r.current = () => R(`_("${a}"* #,##0${i > 0 ? ".0" : ""}_)`, i);
172
172
  const d = (v) => {
@@ -188,7 +188,7 @@ const Fe = "numfmtCurrency", fn = (e) => {
188
188
  ] }),
189
189
  /* @__PURE__ */ u("div", { className: "describe m-t-14", children: m("sheet.numfmt.accountingDes") })
190
190
  ] });
191
- }, _n = (e) => !!W(e) && !e.startsWith("_("), Sn = (e) => {
191
+ }, Sn = (e) => !!W(e) && !e.startsWith("_("), yn = (e) => {
192
192
  const r = C(M).t, n = tt(Re), [i, s] = I(() => W(e.defaultPattern) || n[0]), [o, a] = I(() => te(e.defaultPattern || "", 2)), [c, l] = I(() => {
193
193
  var g;
194
194
  const h = ue(i);
@@ -230,7 +230,7 @@ var E = function() {
230
230
  }
231
231
  return e;
232
232
  }, E.apply(this, arguments);
233
- }, yn = function(e, t) {
233
+ }, bn = function(e, t) {
234
234
  var r = {};
235
235
  for (var n in e) Object.prototype.hasOwnProperty.call(e, n) && t.indexOf(n) < 0 && (r[n] = e[n]);
236
236
  if (e != null && typeof Object.getOwnPropertySymbols == "function")
@@ -238,15 +238,15 @@ var E = function() {
238
238
  t.indexOf(n[i]) < 0 && Object.prototype.propertyIsEnumerable.call(e, n[i]) && (r[n[i]] = e[n[i]]);
239
239
  return r;
240
240
  }, rt = nt(function(e, t) {
241
- var r = e.icon, n = e.id, i = e.className, s = e.extend, o = yn(e, ["icon", "id", "className", "extend"]), a = "univerjs-icon univerjs-icon-".concat(n, " ").concat(i || "").trim(), c = Ee("_".concat(In()));
241
+ var r = e.icon, n = e.id, i = e.className, s = e.extend, o = bn(e, ["icon", "id", "className", "extend"]), a = "univerjs-icon univerjs-icon-".concat(n, " ").concat(i || "").trim(), c = Ee("_".concat(Nn()));
242
242
  return it(r, "".concat(n), { defIds: r.defIds, idSuffix: c.current }, E({ ref: t, className: a }, o), s);
243
243
  });
244
244
  function it(e, t, r, n, i) {
245
- return Te(e.tag, E(E({ key: t }, bn(e, r, i)), n), (Cn(e, r).children || []).map(function(s, o) {
245
+ return Te(e.tag, E(E({ key: t }, Cn(e, r, i)), n), (In(e, r).children || []).map(function(s, o) {
246
246
  return it(s, "".concat(t, "-").concat(e.tag, "-").concat(o), r, void 0, i);
247
247
  }));
248
248
  }
249
- function bn(e, t, r) {
249
+ function Cn(e, t, r) {
250
250
  var n = E({}, e.attrs);
251
251
  r != null && r.colorChannel1 && n.fill === "colorChannel1" && (n.fill = r.colorChannel1), e.tag === "mask" && n.id && (n.id = n.id + t.idSuffix), Object.entries(n).forEach(function(s) {
252
252
  var o = s[0], a = s[1];
@@ -258,34 +258,34 @@ function bn(e, t, r) {
258
258
  typeof a == "string" && (n[o] = a.replace(/url\(#(.*)\)/, "url(#$1".concat(t.idSuffix, ")")));
259
259
  })), n;
260
260
  }
261
- function Cn(e, t) {
261
+ function In(e, t) {
262
262
  var r, n = t.defIds;
263
263
  return !n || n.length === 0 ? e : e.tag === "defs" && (!((r = e.children) === null || r === void 0) && r.length) ? E(E({}, e), { children: e.children.map(function(i) {
264
264
  return typeof i.attrs.id == "string" && n && n.indexOf(i.attrs.id) > -1 ? E(E({}, i), { attrs: E(E({}, i.attrs), { id: i.attrs.id + t.idSuffix }) }) : i;
265
265
  }) }) : e;
266
266
  }
267
- function In() {
267
+ function Nn() {
268
268
  return Math.random().toString(36).substring(2, 8);
269
269
  }
270
270
  rt.displayName = "UniverIcon";
271
- var Nn = { 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" } }] }, st = nt(function(e, t) {
271
+ var En = { 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" } }] }, st = nt(function(e, t) {
272
272
  return Te(rt, Object.assign({}, e, {
273
273
  id: "check-mark-single",
274
274
  ref: t,
275
- icon: Nn
275
+ icon: En
276
276
  }));
277
277
  });
278
278
  st.displayName = "CheckMarkSingle";
279
- const En = "univer-custom-format-title", Tn = "univer-custom-format-input", Mn = "univer-custom-format-history-list", Pn = "univer-custom-format-history-list-item", wn = "univer-custom-format-history-list-item-icon-wrap", Rn = "univer-custom-format-des", U = {
280
- customFormatTitle: En,
281
- customFormatInput: Tn,
282
- customFormatHistoryList: Mn,
283
- customFormatHistoryListItem: Pn,
284
- customFormatHistoryListItemIconWrap: wn,
285
- customFormatDes: Rn
279
+ const Tn = "univer-custom-format-title", Mn = "univer-custom-format-input", Pn = "univer-custom-format-history-list", wn = "univer-custom-format-history-list-item", Rn = "univer-custom-format-history-list-item-icon-wrap", On = "univer-custom-format-des", U = {
280
+ customFormatTitle: Tn,
281
+ customFormatInput: Mn,
282
+ customFormatHistoryList: Pn,
283
+ customFormatHistoryListItem: wn,
284
+ customFormatHistoryListItemIconWrap: Rn,
285
+ customFormatDes: On
286
286
  }, fe = "customFormat", pe = "numfmt_custom_pattern";
287
- function On(e) {
288
- const { defaultPattern: t, action: r, onChange: n } = e, i = C(j), s = C(xe), o = C(M), [a, c] = I(t);
287
+ function Un(e) {
288
+ const { defaultPattern: t, action: r, onChange: n } = e, i = C(j), s = C(He), o = C(M), [a, c] = I(t);
289
289
  r.current = () => (i.markHabit(fe, a), s.getItem(pe).then((p = []) => {
290
290
  const v = [.../* @__PURE__ */ new Set([a, ...p || []])].splice(0, 10).filter((h) => !!h);
291
291
  s.setItem(pe, v);
@@ -320,10 +320,10 @@ function On(e) {
320
320
  /* @__PURE__ */ u("div", { className: U.customFormatDes, children: o.t("sheet.numfmt.customFormatDes") })
321
321
  ] });
322
322
  }
323
- const Un = (e) => {
323
+ const Dn = (e) => {
324
324
  const t = Q.getInfo(e);
325
325
  return We().map((r) => r.value).includes(e) || ["date", "datetime", "time"].includes(t.type);
326
- }, Dn = (e) => {
326
+ }, kn = (e) => {
327
327
  const t = O(We, []), n = C(M).t, [i, s] = I(() => {
328
328
  if (e.defaultPattern) {
329
329
  const a = t.find((c) => c.value === e.defaultPattern);
@@ -341,10 +341,10 @@ const Un = (e) => {
341
341
  /* @__PURE__ */ u("div", { className: "m-t-8", children: /* @__PURE__ */ u(we, { value: i, options: t, onChange: o }) }),
342
342
  /* @__PURE__ */ u("div", { className: "describe m-t-14", children: n("sheet.numfmt.dateDes") })
343
343
  ] });
344
- }, kn = (e) => !e, Fn = (e) => {
344
+ }, Fn = (e) => !e, $n = (e) => {
345
345
  const r = C(M).t;
346
346
  return e.action.current = () => "", /* @__PURE__ */ u("div", { children: /* @__PURE__ */ u("div", { className: "describe m-t-14", children: r("sheet.numfmt.generalDes") }) });
347
- }, $n = (e) => Ve().some((t) => ce(t.value, e)), Ln = (e) => {
347
+ }, xn = (e) => Ve().some((t) => ce(t.value, e)), Ln = (e) => {
348
348
  const t = C(M), r = O(Ve, []), [n, i] = I(() => te(e.defaultPattern || "", 0)), [s, o] = I(() => {
349
349
  const m = r.find((d) => ce(d.value, e.defaultPattern || ""));
350
350
  return (m == null ? void 0 : m.value) || r[0].value;
@@ -373,22 +373,22 @@ const Un = (e) => {
373
373
  /* @__PURE__ */ u("div", { className: "describe m-t-14", children: t.t("sheet.numfmt.thousandthPercentileDes") })
374
374
  ] });
375
375
  }, Hn = (e) => {
376
- const { defaultValue: t, defaultPattern: r, row: n, col: i } = e.value, s = C(M), o = Ee(() => ""), a = s.t, c = pn(), l = O(
376
+ const { defaultValue: t, defaultPattern: r, row: n, col: i } = e.value, s = C(M), o = Ee(() => ""), a = s.t, c = vn(), l = O(
377
377
  () => [
378
- { label: "sheet.numfmt.general", component: Fn },
379
- { label: "sheet.numfmt.accounting", component: gn },
380
- { label: "sheet.numfmt.currency", component: Sn },
381
- { label: "sheet.numfmt.date", component: Dn },
378
+ { label: "sheet.numfmt.general", component: $n },
379
+ { label: "sheet.numfmt.accounting", component: _n },
380
+ { label: "sheet.numfmt.currency", component: yn },
381
+ { label: "sheet.numfmt.date", component: kn },
382
382
  { label: "sheet.numfmt.thousandthPercentile", component: Ln },
383
- { label: "sheet.numfmt.customFormat", component: On }
383
+ { label: "sheet.numfmt.customFormat", component: Un }
384
384
  ].map((_) => ({ ..._, label: a(_.label) })),
385
385
  []
386
- ), [f, m] = I(g), [d, p] = I(() => `${n}_${i}`), { mark: v, userHabitCurrency: h } = fn(() => p(`${n}_${i}_userCurrency'`)), y = O(() => {
386
+ ), [f, m] = I(g), [d, p] = I(() => `${n}_${i}`), { mark: v, userHabitCurrency: h } = pn(() => p(`${n}_${i}_userCurrency'`)), y = O(() => {
387
387
  var _;
388
388
  return (_ = l.find((D) => D.label === f)) == null ? void 0 : _.component;
389
389
  }, [f]);
390
390
  function g() {
391
- return [kn, vn, _n, Un, $n].reduce((D, lt, mt) => D || (lt(r) ? l[mt].label : ""), "") || l[0].label;
391
+ return [Fn, gn, Sn, Dn, xn].reduce((D, lt, mt) => D || (lt(r) ? l[mt].label : ""), "") || l[0].label;
392
392
  }
393
393
  const N = l.map((_) => ({
394
394
  label: _.label,
@@ -400,7 +400,7 @@ const Un = (e) => {
400
400
  }, le = () => {
401
401
  const _ = o.current() || "", D = W(_);
402
402
  D && v(D), e.onChange({ type: "confirm", value: _ });
403
- }, H = () => {
403
+ }, L = () => {
404
404
  e.onChange({ type: "cancel", value: "" });
405
405
  }, me = {
406
406
  onChange: q,
@@ -417,13 +417,13 @@ const Un = (e) => {
417
417
  /* @__PURE__ */ u("div", { children: y && /* @__PURE__ */ u(Re.Provider, { value: h, children: /* @__PURE__ */ Te(y, { ...me, key: d }) }) })
418
418
  ] }),
419
419
  /* @__PURE__ */ b("div", { className: "btn-list m-t-14 m-b-20", children: [
420
- /* @__PURE__ */ u(De, { size: "small", onClick: H, className: "m-r-12", children: a("sheet.numfmt.cancel") }),
420
+ /* @__PURE__ */ u(De, { size: "small", onClick: L, className: "m-r-12", children: a("sheet.numfmt.cancel") }),
421
421
  /* @__PURE__ */ u(De, { type: "primary", size: "small", onClick: le, children: a("sheet.numfmt.confirm") })
422
422
  ] })
423
423
  ] });
424
424
  };
425
- var xn = Object.getOwnPropertyDescriptor, An = (e, t, r, n) => {
426
- for (var i = n > 1 ? void 0 : n ? xn(t, r) : t, s = e.length - 1, o; s >= 0; s--)
425
+ var An = Object.getOwnPropertyDescriptor, jn = (e, t, r, n) => {
426
+ for (var i = n > 1 ? void 0 : n ? An(t, r) : t, s = e.length - 1, o; s >= 0; s--)
427
427
  (o = e[s]) && (i = o(i) || i);
428
428
  return i;
429
429
  }, P = (e, t) => (r, n) => t(r, n, e);
@@ -468,9 +468,9 @@ let B = class extends oe {
468
468
  if (g.type === "change")
469
469
  this._previewPattern = g.value, this._forceUpdate();
470
470
  else if (g.type === "confirm") {
471
- const w = ((N = r.getCurrentSelections()) == null ? void 0 : N.map((H) => H.range)) || [], q = { values: [] }, le = ne(g.value);
472
- w.forEach((H) => {
473
- Ae.foreach(H, (me, _) => {
471
+ const w = ((N = r.getCurrentSelections()) == null ? void 0 : N.map((L) => L.range)) || [], q = { values: [] }, le = ne(g.value);
472
+ w.forEach((L) => {
473
+ Ae.foreach(L, (me, _) => {
474
474
  q.values.push({
475
475
  row: me,
476
476
  col: _,
@@ -515,7 +515,7 @@ let B = class extends oe {
515
515
  }
516
516
  // eslint-disable-next-line max-lines-per-function
517
517
  _initRealTimeRenderingInterceptor() {
518
- const t = new L((n) => {
518
+ const t = new x((n) => {
519
519
  this._commandService.onCommandExecuted((i) => {
520
520
  i.id === A.id && n.next(!0), i.id === he.id && n.next(!1);
521
521
  });
@@ -529,7 +529,7 @@ let B = class extends oe {
529
529
  ge(
530
530
  r.pipe(
531
531
  rn(
532
- ([n, i]) => new L((s) => {
532
+ ([n, i]) => new x((s) => {
533
533
  const o = new pt();
534
534
  return n && i.length && s.next({ selectionRanges: i, disposableCollection: o }), () => {
535
535
  o.dispose();
@@ -581,7 +581,7 @@ let B = class extends oe {
581
581
  _commandExecutedListener() {
582
582
  const t = [Ie.id, Ne.id];
583
583
  this.disposeWithMe(
584
- new L((r) => {
584
+ new x((r) => {
585
585
  const n = this._commandService.onCommandExecuted((i) => {
586
586
  if (t.includes(i.id)) {
587
587
  const s = i.params;
@@ -599,7 +599,7 @@ let B = class extends oe {
599
599
  });
600
600
  }
601
601
  };
602
- B = An([
602
+ B = jn([
603
603
  P(0, S(Qe)),
604
604
  P(1, S(ft)),
605
605
  P(2, Se),
@@ -608,16 +608,16 @@ B = An([
608
608
  P(5, Be),
609
609
  P(6, be),
610
610
  P(7, S(qe)),
611
- P(8, xt),
611
+ P(8, Ht),
612
612
  P(9, S(M)),
613
613
  P(10, S(Ge))
614
614
  ], B);
615
- var jn = Object.getOwnPropertyDescriptor, Bn = (e, t, r, n) => {
616
- for (var i = n > 1 ? void 0 : n ? jn(t, r) : t, s = e.length - 1, o; s >= 0; s--)
615
+ var Bn = Object.getOwnPropertyDescriptor, Wn = (e, t, r, n) => {
616
+ for (var i = n > 1 ? void 0 : n ? Bn(t, r) : t, s = e.length - 1, o; s >= 0; s--)
617
617
  (o = e[s]) && (i = o(i) || i);
618
618
  return i;
619
- }, x = (e, t) => (r, n) => t(r, n, e);
620
- const Wn = () => {
619
+ }, H = (e, t) => (r, n) => t(r, n, e);
620
+ const Vn = () => {
621
621
  let e = [];
622
622
  return {
623
623
  add: (i, s, o, a, c) => e.push({ unitId: i, subUnitId: s, row: o, col: a, value: c }),
@@ -631,7 +631,7 @@ let re = class extends oe {
631
631
  constructor(t, r, n, i, s) {
632
632
  super();
633
633
  // collect effect mutations when edit end and push this to commands stack in next commands progress
634
- J(this, "_collectEffectMutation", Wn());
634
+ J(this, "_collectEffectMutation", Vn());
635
635
  this._sheetInterceptorService = t, this._numfmtService = r, this._univerInstanceService = n, this._injector = i, this._editorBridgeService = s, this._initInterceptorEditorStart(), this._initInterceptorEditorEnd(), this._initInterceptorCommands();
636
636
  }
637
637
  _initInterceptorEditorStart() {
@@ -703,7 +703,7 @@ let re = class extends oe {
703
703
  return n(t);
704
704
  const a = (m = t.p) == null ? void 0 : m.body, c = (p = (d = t == null ? void 0 : t.p) == null ? void 0 : d.body) != null && p.dataStream ? t.p.body.dataStream.replace(/\r\n$/, "") : String(t.v), l = Q.parseDate(c) || Q.parseTime(c) || Q.parseNumber(c);
705
705
  if (a)
706
- if (Gn(a)) {
706
+ if (Kn(a)) {
707
707
  const { dataStream: v } = a, h = v.replace(/\r\n$/, ""), y = Number(h);
708
708
  if (Number.isNaN(y) && !l)
709
709
  return n(t);
@@ -721,7 +721,7 @@ let re = class extends oe {
721
721
  );
722
722
  const v = Number(l.v);
723
723
  return n({ ...t, p: void 0, v, t: $.NUMBER });
724
- } else (["date", "time", "datetime", "percent"].includes(s) || !Vn(c)) && o();
724
+ } else (["date", "time", "datetime", "percent"].includes(s) || !Gn(c)) && o();
725
725
  return n(t);
726
726
  }
727
727
  }
@@ -798,17 +798,17 @@ let re = class extends oe {
798
798
  );
799
799
  }
800
800
  };
801
- re = Bn([
802
- x(0, S(Qe)),
803
- x(1, S(be)),
804
- x(2, S(Se)),
805
- x(3, S(je)),
806
- x(4, vt(Ft))
801
+ re = Wn([
802
+ H(0, S(Qe)),
803
+ H(1, S(be)),
804
+ H(2, S(Se)),
805
+ H(3, S(je)),
806
+ H(4, vt(Ft))
807
807
  ], re);
808
- function Vn(e) {
808
+ function Gn(e) {
809
809
  return /^-?\d+(\.\d+)?$/.test(e);
810
810
  }
811
- function Gn(e) {
811
+ function Kn(e) {
812
812
  const { textRuns: t = [], paragraphs: r = [], customRanges: n, customBlocks: i = [] } = e, s = ["va"];
813
813
  return !(t.some((o) => !!(o.ts && Object.keys(o.ts).some((c) => s.includes(c)))) || r.some((o) => o.bullet) || r.length >= 2 || n != null && n.length || i.length > 0);
814
814
  }
@@ -865,8 +865,8 @@ const ee = [
865
865
  label: "sheet.numfmt.moreFmt",
866
866
  pattern: ""
867
867
  }
868
- ], Kn = (e) => ({
869
- icon: new L((t) => {
868
+ ], Zn = (e) => ({
869
+ icon: new x((t) => {
870
870
  const r = e.get(Pt);
871
871
  function n(s) {
872
872
  return {
@@ -888,7 +888,7 @@ const ee = [
888
888
  type: K.BUTTON,
889
889
  hidden$: G(e, T.UNIVER_SHEET),
890
890
  disabled$: V(e, { workbookTypes: [X], worksheetTypes: [Y, z], rangeTypes: [Z] })
891
- }), Zn = (e) => ({
891
+ }), zn = (e) => ({
892
892
  icon: "AddDigitsSingle",
893
893
  id: Ye.id,
894
894
  title: "sheet.numfmt.addDecimal",
@@ -896,7 +896,7 @@ const ee = [
896
896
  type: K.BUTTON,
897
897
  hidden$: G(e, T.UNIVER_SHEET),
898
898
  disabled$: V(e, { workbookTypes: [X], worksheetTypes: [Y, z], rangeTypes: [Z] })
899
- }), zn = (e) => ({
899
+ }), Yn = (e) => ({
900
900
  icon: "ReduceDigitsSingle",
901
901
  id: ze.id,
902
902
  title: "sheet.numfmt.subtractDecimal",
@@ -904,7 +904,7 @@ const ee = [
904
904
  type: K.BUTTON,
905
905
  hidden$: G(e, T.UNIVER_SHEET),
906
906
  disabled$: V(e, { workbookTypes: [X], worksheetTypes: [Y, z], rangeTypes: [Z] })
907
- }), Yn = (e) => ({
907
+ }), Xn = (e) => ({
908
908
  icon: "PercentSingle",
909
909
  id: Ze.id,
910
910
  title: "sheet.numfmt.percent",
@@ -912,11 +912,11 @@ const ee = [
912
912
  type: K.BUTTON,
913
913
  hidden$: G(e, T.UNIVER_SHEET),
914
914
  disabled$: V(e, { workbookTypes: [X], worksheetTypes: [Y, z], rangeTypes: [Z] })
915
- }), Xn = (e) => {
916
- const t = e.get(Se), r = e.get(ye), n = e.get(M), i = e.get(Ce), s = $t(t, "", ({ workbook: o, worksheet: a }) => new L(
915
+ }), qn = (e) => {
916
+ const t = e.get(Se), r = e.get(ye), n = e.get(M), i = e.get(Ce), s = $t(t, "", ({ workbook: o, worksheet: a }) => new x(
917
917
  (c) => et(
918
918
  i.selectionMoveEnd$,
919
- new L((l) => {
919
+ new x((l) => {
920
920
  const f = [Ie.id, Ne.id], m = r.onCommandExecuted((d) => {
921
921
  f.includes(d.id) && l.next(null);
922
922
  });
@@ -947,11 +947,13 @@ const ee = [
947
947
  id: A.id,
948
948
  tooltip: "sheet.numfmt.title",
949
949
  type: K.SELECTOR,
950
+ slot: !0,
950
951
  selections: [
951
952
  {
952
953
  label: {
953
954
  name: ct,
954
- hoverable: !1
955
+ hoverable: !1,
956
+ selectable: !1
955
957
  }
956
958
  }
957
959
  ],
@@ -959,11 +961,10 @@ const ee = [
959
961
  hidden$: G(e, T.UNIVER_SHEET),
960
962
  disabled$: V(e, { workbookTypes: [X], worksheetTypes: [z, Y], rangeTypes: [Z] })
961
963
  };
962
- }, ot = "sheet.numfmt.moreNumfmtType", ct = "sheet.numfmt.moreNumfmtType.options", qn = (e) => {
963
- var n;
964
- const t = C(M), r = (n = e.value) != null ? n : t.t("sheet.numfmt.general");
965
- return /* @__PURE__ */ u("span", { className: "more-numfmt-type", children: r });
966
- }, Jn = () => {
964
+ }, ot = "sheet.numfmt.moreNumfmtType", ct = "sheet.numfmt.moreNumfmtType.options", Jn = (e) => {
965
+ const { value: t } = e, r = C(M), n = t != null ? t : r.t("sheet.numfmt.general");
966
+ return /* @__PURE__ */ u("span", { className: "univer-text-sm", children: n });
967
+ }, Qn = () => {
967
968
  const e = C(ye), t = C(M), r = C(At), n = C(Ge), i = C(Ce), s = (c) => {
968
969
  const l = i.getCurrentLastSelection();
969
970
  if (!l)
@@ -976,73 +977,77 @@ const ee = [
976
977
  if (c === 0)
977
978
  s(null);
978
979
  else if (c === ee.length - 1)
979
- e.executeCommand(A.id);
980
+ e.executeCommand(A.id), r.focus();
980
981
  else {
981
982
  const l = ee[c];
982
983
  l.pattern && s(l.pattern);
983
984
  }
984
985
  }, a = 1220;
985
- return /* @__PURE__ */ u("div", { className: "more-numfmt-type-options", children: ee.map((c, l) => c === "|" ? /* @__PURE__ */ u("div", { className: "line m-t-4", onClick: (f) => f.stopPropagation() }, l) : /* @__PURE__ */ b(
986
+ return /* @__PURE__ */ u("div", { className: "univer-grid univer-gap-1 univer-p-1.5", children: ee.map((c, l) => c === "|" ? /* @__PURE__ */ u(ln, {}, l) : /* @__PURE__ */ b(
986
987
  "div",
987
988
  {
988
- className: "option-item m-t-4",
989
+ className: `
990
+ univer-flex univer-h-7 univer-items-center univer-justify-between univer-gap-6 univer-rounded
991
+ univer-px-2 univer-text-[13px]
992
+ hover:univer-bg-gray-100
993
+ `,
989
994
  onClick: () => {
990
995
  o(l);
991
996
  },
992
997
  children: [
993
- /* @__PURE__ */ u("div", { children: t.t(c.label) }),
994
- /* @__PURE__ */ u("div", { className: "m-l-26", children: c.pattern ? wt(c.pattern || "", a, n.local).result : "" })
998
+ /* @__PURE__ */ u("span", { children: t.t(c.label) }),
999
+ /* @__PURE__ */ u("span", { className: "univer-text-xs univer-text-gray-500", children: c.pattern ? wt(c.pattern || "", a, n.local).result.trim() : "" })
995
1000
  ]
996
1001
  },
997
1002
  l
998
1003
  )) });
999
- }, Qn = {
1004
+ }, er = {
1000
1005
  [jt.FORMULAS_INSERT]: {
1001
1006
  [Xe.id]: {
1002
1007
  order: 4,
1003
- menuItemFactory: Kn
1008
+ menuItemFactory: Zn
1004
1009
  },
1005
1010
  [Ye.id]: {
1006
1011
  order: 5,
1007
- menuItemFactory: Zn
1012
+ menuItemFactory: zn
1008
1013
  },
1009
1014
  [ze.id]: {
1010
1015
  order: 6,
1011
- menuItemFactory: zn
1016
+ menuItemFactory: Yn
1012
1017
  },
1013
1018
  [Ze.id]: {
1014
1019
  order: 7,
1015
- menuItemFactory: Yn
1020
+ menuItemFactory: Xn
1016
1021
  },
1017
1022
  [A.id]: {
1018
1023
  order: 8,
1019
- menuItemFactory: Xn
1024
+ menuItemFactory: qn
1020
1025
  }
1021
1026
  }
1022
1027
  };
1023
- var er = Object.getOwnPropertyDescriptor, tr = (e, t, r, n) => {
1024
- for (var i = n > 1 ? void 0 : n ? er(t, r) : t, s = e.length - 1, o; s >= 0; s--)
1028
+ var tr = Object.getOwnPropertyDescriptor, nr = (e, t, r, n) => {
1029
+ for (var i = n > 1 ? void 0 : n ? tr(t, r) : t, s = e.length - 1, o; s >= 0; s--)
1025
1030
  (o = e[s]) && (i = o(i) || i);
1026
1031
  return i;
1027
- }, Le = (e, t) => (r, n) => t(r, n, e);
1032
+ }, xe = (e, t) => (r, n) => t(r, n, e);
1028
1033
  let ie = class extends oe {
1029
1034
  constructor(e, t) {
1030
1035
  super(), this._componentManager = e, this._menuManagerService = t, this._initMenu();
1031
1036
  }
1032
1037
  _initMenu() {
1033
- this._menuManagerService.mergeMenu(Qn), this.disposeWithMe(this._componentManager.register(ot, qn)), this.disposeWithMe(this._componentManager.register(ct, Jn));
1038
+ this._menuManagerService.mergeMenu(er), this.disposeWithMe(this._componentManager.register(ot, Jn)), this.disposeWithMe(this._componentManager.register(ct, Qn));
1034
1039
  }
1035
1040
  };
1036
- ie = tr([
1037
- Le(0, S(qe)),
1038
- Le(1, Bt)
1041
+ ie = nr([
1042
+ xe(0, S(qe)),
1043
+ xe(1, Bt)
1039
1044
  ], ie);
1040
- var nr = Object.defineProperty, rr = Object.getOwnPropertyDescriptor, ir = (e, t, r) => t in e ? nr(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, sr = (e, t, r, n) => {
1041
- for (var i = n > 1 ? void 0 : n ? rr(t, r) : t, s = e.length - 1, o; s >= 0; s--)
1045
+ var rr = Object.defineProperty, ir = Object.getOwnPropertyDescriptor, sr = (e, t, r) => t in e ? rr(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r, or = (e, t, r, n) => {
1046
+ for (var i = n > 1 ? void 0 : n ? ir(t, r) : t, s = e.length - 1, o; s >= 0; s--)
1042
1047
  (o = e[s]) && (i = o(i) || i);
1043
1048
  return i;
1044
- }, ve = (e, t) => (r, n) => t(r, n, e), at = (e, t, r) => ir(e, typeof t != "symbol" ? t + "" : t, r);
1045
- const or = "SHEET_NUMFMT_UI_PLUGIN";
1049
+ }, ve = (e, t) => (r, n) => t(r, n, e), at = (e, t, r) => sr(e, typeof t != "symbol" ? t + "" : t, r);
1050
+ const cr = "SHEET_NUMFMT_UI_PLUGIN";
1046
1051
  let se = class extends St {
1047
1052
  constructor(e = ke, t, r, n) {
1048
1053
  super(), this._config = e, this._injector = t, this._configService = r, this._renderManagerService = n;
@@ -1076,10 +1081,10 @@ let se = class extends St {
1076
1081
  });
1077
1082
  }
1078
1083
  };
1079
- at(se, "pluginName", or);
1084
+ at(se, "pluginName", cr);
1080
1085
  at(se, "type", T.UNIVER_SHEET);
1081
- se = sr([
1082
- gt(Lt, Rt),
1086
+ se = or([
1087
+ gt(xt, Rt),
1083
1088
  ve(1, S(je)),
1084
1089
  ve(2, _t),
1085
1090
  ve(3, Be)
package/lib/index.css CHANGED
@@ -1 +1 @@
1
- .options{display:flex;justify-content:space-between}.options .w-140{width:140px}.options .w-120{width:120px}.univer-custom-format-title{margin-top:16px}.univer-custom-format-input{margin-top:8px;width:100%}.univer-custom-format-history-list{margin-top:8px;padding:8px;border-radius:8px;border:1px solid #e5e5e5;border:1px solid var(---Grey-200, #e5e5e5);max-height:400px;overflow:scroll}.univer-custom-format-history-list-item{padding:6px 0;display:flex;gap:6px;align-items:center;cursor:pointer}.univer-custom-format-history-list-item-icon-wrap{width:16px;display:flex;align-items:center;color:#274fee}.univer-custom-format-des{margin-top:8px;color:#7a7a7a;color:var(---Grey-600, #7a7a7a);font-size:12px;font-style:normal;font-weight:400;line-height:16px}.numfmt-panel{overflow-y:auto;display:flex;flex-direction:column;justify-content:space-between;height:100%}.numfmt-panel .group-title{font-size:16px;color:rgba(var(--color-black))}.numfmt-panel .label{font-size:15px;color:rgba(var(--grey-400))}.numfmt-panel .describe{font-size:13px;line-height:20px;color:rgba(var(--grey-600))}.numfmt-panel .preview{height:36px;padding:0 16px;font-size:14px;line-height:36px;color:var(--color-black);border:1px solid rgb(var(--grey-200));border-radius:4px}.numfmt-panel .btn-list{display:flex;justify-content:flex-end}.numfmt-panel .m-r-12{margin-right:12px}.numfmt-panel .m-t-16{margin-top:16px}.numfmt-panel .m-t-14{margin-top:14px}.numfmt-panel .m-t-8{margin-top:8px}.numfmt-panel .m-b-20{margin-bottom:20px}.more-numfmt-type{display:flex;flex-shrink:0;padding:0 4px;font-size:13px;color:var(--black)}.more-numfmt-type .icon{display:flex;align-items:center;height:auto;padding-left:8px;color:rgb(var(--grey-400))}.more-numfmt-type-options .line{width:100%;height:1px;background-color:rgb(var(--grey-200))}.more-numfmt-type-options .m-t-4{margin-top:4px}.more-numfmt-type-options .option-item{display:flex;align-items:center;justify-content:space-between;height:28px;padding:0 8px;font-size:13px}.more-numfmt-type-options .option-item:hover{background-color:rgb(var(--grey-100));border-radius:var(--border-radius-base)}.more-numfmt-type-options .m-l-26{margin-left:26px}
1
+ .univer-flex{display:flex}.univer-grid{display:grid}.univer-h-7{height:1.75rem}.univer-items-center{align-items:center}.univer-justify-between{justify-content:space-between}.univer-gap-1{gap:.25rem}.univer-gap-6{gap:1.5rem}.univer-rounded{border-radius:.25rem}.univer-p-1\.5{padding:.375rem}.univer-px-2{padding-left:.5rem;padding-right:.5rem}.univer-text-\[13px\]{font-size:13px}.univer-text-sm{font-size:.875rem;line-height:1.25rem}.univer-text-xs{font-size:.75rem;line-height:1rem}.univer-text-gray-500{--tw-text-opacity: 1;color:#5f6574;color:rgba(95,101,116,var(--tw-text-opacity, 1))}.hover\:univer-bg-gray-100:hover{--tw-bg-opacity: 1;background-color:#eeeff1;background-color:rgba(238,239,241,var(--tw-bg-opacity, 1))}.options{display:flex;justify-content:space-between}.options .w-140{width:140px}.options .w-120{width:120px}.univer-custom-format-title{margin-top:16px}.univer-custom-format-input{margin-top:8px;width:100%}.univer-custom-format-history-list{margin-top:8px;padding:8px;border-radius:8px;border:1px solid #e5e5e5;border:1px solid var(---Grey-200, #e5e5e5);max-height:400px;overflow:scroll}.univer-custom-format-history-list-item{padding:6px 0;display:flex;gap:6px;align-items:center;cursor:pointer}.univer-custom-format-history-list-item-icon-wrap{width:16px;display:flex;align-items:center;color:#274fee}.univer-custom-format-des{margin-top:8px;color:#7a7a7a;color:var(---Grey-600, #7a7a7a);font-size:12px;font-style:normal;font-weight:400;line-height:16px}.numfmt-panel{overflow-y:auto;display:flex;flex-direction:column;justify-content:space-between;height:100%}.numfmt-panel .group-title{font-size:16px;color:rgba(var(--color-black))}.numfmt-panel .label{font-size:15px;color:rgba(var(--grey-400))}.numfmt-panel .describe{font-size:13px;line-height:20px;color:rgba(var(--grey-600))}.numfmt-panel .preview{height:36px;padding:0 16px;font-size:14px;line-height:36px;color:var(--color-black);border:1px solid rgb(var(--grey-200));border-radius:4px}.numfmt-panel .btn-list{display:flex;justify-content:flex-end}.numfmt-panel .m-r-12{margin-right:12px}.numfmt-panel .m-t-16{margin-top:16px}.numfmt-panel .m-t-14{margin-top:14px}.numfmt-panel .m-t-8{margin-top:8px}.numfmt-panel .m-b-20{margin-bottom:20px}
@@ -13,7 +13,6 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import './index.less';
17
16
  export declare const MORE_NUMFMT_TYPE_KEY = "sheet.numfmt.moreNumfmtType";
18
17
  export declare const OPTIONS_KEY = "sheet.numfmt.moreNumfmtType.options";
19
18
  export declare const MoreNumfmtType: (props: {
package/lib/umd/index.js CHANGED
@@ -1 +1,5 @@
1
- (function(b,a){typeof exports=="object"&&typeof module<"u"?a(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/jsx-runtime"),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/jsx-runtime","react","@univerjs/design"],a):(b=typeof globalThis<"u"?globalThis:b||self,a(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.React,b.UniverDesign))})(this,function(b,a,k,m,P,C,ve,W,S,N,V,u,y,M){"use strict";var lt=Object.defineProperty;var ut=(b,a,k)=>a in b?lt(b,a,{enumerable:!0,configurable:!0,writable:!0,value:k}):b[a]=k;var Z=(b,a,k)=>ut(b,typeof a!="symbol"?a+"":a,k);const ie={};var fe=Object.getOwnPropertyDescriptor,he=(e,t,r,n)=>{for(var i=n>1?void 0:n?fe(t,r):t,o=e.length-1,s;o>=0;o--)(s=e[o])&&(i=s(i)||i);return i},L=(e,t)=>(r,n)=>t(r,n,e);const z="SHEET_NUMFMT_ALERT";let Y=class extends a.Disposable{constructor(e,t,r,n,i,o,s){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=r,this._localeService=n,this._formulaDataModel=i,this._zenZoneService=o,this._numfmtService=s,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(N.debounceTime(100)).subscribe(e=>{var t;if(e){const r=e.location,n=this._context.unit,i=n.getActiveSheet();if(!i)return;const o=r.unitId,s=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(o,s,r.row,r.col)),!l){this._hideAlert();return}if(W.isTextFormat(l.pattern)&&(c!=null&&c.v)&&a.isRealNum(c.v)){const d=this._cellAlertManagerService.currentAlert.get(z),h=(t=d==null?void 0:d.alert)==null?void 0:t.location;if(h&&h.row===r.row&&h.col===r.col&&h.subUnitId===r.subUnitId&&h.unitId===r.unitId)return;this._cellAlertManagerService.showAlert({type:P.CellAlertType.ERROR,title:this._localeService.t("info.error"),message:this._localeService.t("info.forceStringInfo"),location:r,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)}};Y=he([L(1,a.Inject(P.HoverManagerService)),L(2,a.Inject(P.CellAlertManagerService)),L(3,a.Inject(a.LocaleService)),L(4,a.Inject(ve.FormulaDataModel)),L(5,C.IZenZoneService),L(6,a.Inject(S.INumfmtService))],Y);const X={id:"sheet.operation.close.numfmt.panel",type:a.CommandType.OPERATION,handler:()=>!0},$={id:"sheet.operation.open.numfmt.panel",type:a.CommandType.OPERATION,handler:e=>(e.get(A).openPanel(),!0)};var Se=Object.getOwnPropertyDescriptor,ge=(e,t,r,n)=>{for(var i=n>1?void 0:n?Se(t,r):t,o=e.length-1,s;o>=0;o--)(s=e[o])&&(i=s(i)||i);return i},ye=(e,t)=>(r,n)=>t(r,n,e);const J=y.createContext([]);let H=class{constructor(e){this._localStorageService=e}_getKey(e){return`userHabitController_${e}`}async addHabit(e,t){const r=this._getKey(e);return this._localStorageService.getItem(r).then(n=>{n||this._localStorageService.setItem(r,t)})}markHabit(e,t){const r=this._getKey(e);this._localStorageService.getItem(r).then(n=>{if(n){const i=n.findIndex(o=>o===t);i>-1&&n.splice(i,1),n.unshift(t),this._localStorageService.setItem(r,n)}})}async getHabit(e,t){const r=this._getKey(e),n=await this._localStorageService.getItem(r);if(t&&n){const i=n.map((o,s,l)=>{const c=l.length;return{value:o,priority:c-s}});return t.sort((o,s)=>{var d,h;const l=((d=i.find(p=>p.value===o))==null?void 0:d.priority)||-1;return(((h=i.find(p=>p.value===s))==null?void 0:h.priority)||-1)-l})}return n||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};H=ge([ye(0,a.Inject(a.ILocalStorageService))],H);const oe="numfmtCurrency",_e=e=>{const t=C.useDependency(H),[r,n]=y.useState(m.currencySymbols);return y.useEffect(()=>{t.addHabit("numfmtCurrency",[]).then(()=>{t.getHabit(oe,[...m.currencySymbols]).then(o=>{n(o),e&&e(o)})})},[]),{userHabitCurrency:r,mark:o=>{t.markHabit(oe,o)}}},Ce=()=>{const e=y.useRef([]),[t,r]=y.useState({});return y.useEffect(()=>{e.current.forEach(i=>{i()}),e.current=[]},[t]),i=>{e.current.push(i),r({})}},be=e=>!!m.getCurrencyType(e)&&e.startsWith("_("),Ie=e=>{const{defaultPattern:t,action:r,onChange:n}=e,[i,o]=y.useState(()=>m.getDecimalFromPattern(t||"",2)),s=y.useContext(J),[l,c]=y.useState(()=>m.getCurrencyType(t)||s[0]),d=y.useMemo(()=>s.map(_=>({label:_,value:_})),[]),p=C.useDependency(a.LocaleService).t;r.current=()=>m.setPatternDecimal(`_("${l}"* #,##0${i>0?".0":""}_)`,i);const v=_=>{c(_),n(m.setPatternDecimal(`_("${_}"* #,##0${i>0?".0":""}_)`,i))},g=_=>{const f=_||0;o(f),n(m.setPatternDecimal(`_("${l}"* #,##0${f>0?".0":""}_)`,f))};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:g})})]}),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")})]})},Te=e=>!!m.getCurrencyType(e)&&!e.startsWith("_("),Ee=e=>{const r=C.useDependency(a.LocaleService).t,n=y.useContext(J),[i,o]=y.useState(()=>m.getCurrencyType(e.defaultPattern)||n[0]),[s,l]=y.useState(()=>m.getDecimalFromPattern(e.defaultPattern||"",2)),[c,d]=y.useState(()=>{var I;const f=m.getCurrencyFormatOptions(i);return((I=f.find(O=>m.isPatternEqualWithoutDecimal(O.value,e.defaultPattern)))==null?void 0:I.value)||f[0].value}),h=y.useMemo(()=>m.getCurrencyFormatOptions(i),[i]),p=y.useMemo(()=>n.map(f=>({label:f,value:f})),[n]);e.action.current=()=>m.setPatternDecimal(c,s);const v=f=>{if(f===void 0)return;o(f);const E=m.getCurrencyFormatOptions(f)[0].value;d(E),e.onChange(m.setPatternDecimal(E,s))},g=f=>{f!==void 0&&(d(f),e.onChange(m.setPatternDecimal(f,s)))},_=f=>{l(f||0),e.onChange(m.setPatternDecimal(c,f||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:s,max:20,min:0,onChange:_})})]}),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:g,options:h,value:c})}),u.jsx("div",{className:"describe m-t-14",children:r("sheet.numfmt.currencyDes")})]})};var D=function(){return D=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},D.apply(this,arguments)},Pe=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r},ae=y.forwardRef(function(e,t){var r=e.icon,n=e.id,i=e.className,o=e.extend,s=Pe(e,["icon","id","className","extend"]),l="univerjs-icon univerjs-icon-".concat(n," ").concat(i||"").trim(),c=y.useRef("_".concat(Oe()));return se(r,"".concat(n),{defIds:r.defIds,idSuffix:c.current},D({ref:t,className:l},s),o)});function se(e,t,r,n,i){return y.createElement(e.tag,D(D({key:t},Me(e,r,i)),n),(De(e,r).children||[]).map(function(o,s){return se(o,"".concat(t,"-").concat(e.tag,"-").concat(s),r,void 0,i)}))}function Me(e,t,r){var n=D({},e.attrs);r!=null&&r.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=r.colorChannel1),e.tag==="mask"&&n.id&&(n.id=n.id+t.idSuffix),Object.entries(n).forEach(function(o){var s=o[0],l=o[1];s==="mask"&&typeof l=="string"&&(n[s]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var i=t.defIds;return!i||i.length===0||(e.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(function(o){var s=o[0],l=o[1];typeof l=="string"&&(n[s]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function De(e,t){var r,n=t.defIds;return!n||n.length===0?e:e.tag==="defs"&&(!((r=e.children)===null||r===void 0)&&r.length)?D(D({},e),{children:e.children.map(function(i){return typeof i.attrs.id=="string"&&n&&n.indexOf(i.attrs.id)>-1?D(D({},i),{attrs:D(D({},i.attrs),{id:i.attrs.id+t.idSuffix})}):i})}):e}function Oe(){return Math.random().toString(36).substring(2,8)}ae.displayName="UniverIcon";var Ue={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"}}]},ce=y.forwardRef(function(e,t){return y.createElement(ae,Object.assign({},e,{id:"check-mark-single",ref:t,icon:Ue}))});ce.displayName="CheckMarkSingle";const F={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"},Q="customFormat",ee="numfmt_custom_pattern";function Ne(e){const{defaultPattern:t,action:r,onChange:n}=e,i=C.useDependency(H),o=C.useDependency(a.ILocalStorageService),s=C.useDependency(a.LocaleService),[l,c]=y.useState(t);r.current=()=>(i.markHabit(Q,l),o.getItem(ee).then((g=[])=>{const _=[...new Set([l,...g||[]])].splice(0,10).filter(f=>!!f);o.setItem(ee,_)}),l);const[d,h]=y.useState([]);y.useEffect(()=>{o.getItem(ee).then(g=>{const _=[...m.CURRENCYFORMAT.map(f=>f.suffix("$")),...m.DATEFMTLISG.map(f=>f.suffix),...m.NUMBERFORMAT.map(f=>f.suffix)];_.push(...g||[]),i.addHabit(Q,[]).finally(()=>{i.getHabit(Q,_).then(f=>{h([...new Set(f)])})})})},[]);const p=g=>{c(g),n(g)},v=()=>{n(l)};return u.jsxs("div",{className:F.customFormat,children:[u.jsx("div",{className:F.customFormatTitle,children:s.t("sheet.numfmt.customFormat")}),u.jsx(M.Input,{placeholder:s.t("sheet.numfmt.customFormat"),onBlur:v,value:l,onChange:c,className:F.customFormatInput}),u.jsx("div",{className:F.customFormatHistoryList,children:d.map(g=>u.jsxs("div",{onClick:()=>p(g),className:F.customFormatHistoryListItem,children:[u.jsx("div",{className:F.customFormatHistoryListItemIconWrap,children:l===g&&u.jsx(ce,{})}),u.jsx("div",{children:g})]},g))}),u.jsx("div",{className:F.customFormatDes,children:s.t("sheet.numfmt.customFormatDes")})]})}const we=e=>{const t=a.numfmt.getInfo(e);return m.getDateFormatOptions().map(r=>r.value).includes(e)||["date","datetime","time"].includes(t.type)},ke=e=>{const t=y.useMemo(m.getDateFormatOptions,[]),n=C.useDependency(a.LocaleService).t,[i,o]=y.useState(()=>{if(e.defaultPattern){const l=t.find(c=>c.value===e.defaultPattern);if(l)return l.value}return t[0].value});e.action.current=()=>i;const s=l=>{l!==void 0&&(o(l),e.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:t,onChange:s})}),u.jsx("div",{className:"describe m-t-14",children:n("sheet.numfmt.dateDes")})]})},Fe=e=>!e,Le=e=>{const r=C.useDependency(a.LocaleService).t;return e.action.current=()=>"",u.jsx("div",{children:u.jsx("div",{className:"describe m-t-14",children:r("sheet.numfmt.generalDes")})})},je=e=>m.getNumberFormatOptions().some(t=>m.isPatternEqualWithoutDecimal(t.value,e)),$e=e=>{const t=C.useDependency(a.LocaleService),r=y.useMemo(m.getNumberFormatOptions,[]),[n,i]=y.useState(()=>m.getDecimalFromPattern(e.defaultPattern||"",0)),[o,s]=y.useState(()=>{const p=r.find(v=>m.isPatternEqualWithoutDecimal(v.value,e.defaultPattern||""));return(p==null?void 0:p.value)||r[0].value}),l=y.useMemo(()=>m.setPatternDecimal(o,Number(n||0)),[o,n]),c=y.useMemo(()=>!m.isPatternHasDecimal(o),[o]),d=p=>{i(p||0),e.onChange(m.setPatternDecimal(o,Number(p||0)))},h=p=>{p!==void 0&&(i(m.getDecimalFromPattern(p,0)),s(p),e.onChange(p))};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(M.InputNumber,{disabled:c,value:n,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(M.SelectList,{onChange:h,options:r,value:o})}),u.jsx("div",{className:"describe m-t-14",children:t.t("sheet.numfmt.thousandthPercentileDes")})]})},He=e=>{const{defaultValue:t,defaultPattern:r,row:n,col:i}=e.value,o=C.useDependency(a.LocaleService),s=y.useRef(()=>""),l=o.t,c=Ce(),d=y.useMemo(()=>[{label:"sheet.numfmt.general",component:Le},{label:"sheet.numfmt.accounting",component:Ie},{label:"sheet.numfmt.currency",component:Ee},{label:"sheet.numfmt.date",component:ke},{label:"sheet.numfmt.thousandthPercentile",component:$e},{label:"sheet.numfmt.customFormat",component:Ne}].map(T=>({...T,label:l(T.label)})),[]),[h,p]=y.useState(I),[v,g]=y.useState(()=>`${n}_${i}`),{mark:_,userHabitCurrency:f}=_e(()=>g(`${n}_${i}_userCurrency'`)),E=y.useMemo(()=>{var T;return(T=d.find(j=>j.label===h))==null?void 0:T.component},[h]);function I(){return[Fe,be,Te,we,je].reduce((j,st,ct)=>j||(st(r)?d[ct].label:""),"")||d[0].label}const O=d.map(T=>({label:T.label,value:T.label})),w=T=>{p(T),c(()=>e.onChange({type:"change",value:s.current()||""}))},K=T=>{e.onChange({type:"change",value:T})},ne=()=>{const T=s.current()||"",j=m.getCurrencyType(T);j&&_(j),e.onChange({type:"confirm",value:T})},R=()=>{e.onChange({type:"cancel",value:""})},re={onChange:K,defaultValue:t,defaultPattern:r,action:s};return y.useEffect(()=>{p(I()),g(`${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:w,options:O,value:h,style:{width:"100%"}})}),u.jsx("div",{children:E&&u.jsx(J.Provider,{value:f,children:y.createElement(E,{...re,key:v})})})]}),u.jsxs("div",{className:"btn-list m-t-14 m-b-20",children:[u.jsx(M.Button,{size:"small",onClick:R,className:"m-r-12",children:l("sheet.numfmt.cancel")}),u.jsx(M.Button,{type:"primary",size:"small",onClick:ne,children:l("sheet.numfmt.confirm")})]})]})};var Ae=Object.getOwnPropertyDescriptor,xe=(e,t,r,n)=>{for(var i=n>1?void 0:n?Ae(t,r):t,o=e.length-1,s;o>=0;o--)(s=e[o])&&(i=s(i)||i);return i},U=(e,t)=>(r,n)=>t(r,n,e);const le="SHEET_NUMFMT_PANEL";let A=class extends a.Disposable{constructor(t,r,n,i,o,s,l,c,d,h,p){super();Z(this,"_previewPattern","");Z(this,"_sidebarDisposable",null);this._sheetInterceptorService=t,this._themeService=r,this._univerInstanceService=n,this._commandService=i,this._selectionManagerService=o,this._renderManagerService=s,this._numfmtService=l,this._componentManager=c,this._sidebarService=d,this._localeService=h,this._sheetsNumfmtCellContentController=p,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener(),this._initNumfmtLocalChange()}_initNumfmtLocalChange(){this.disposeWithMe(N.merge(this._sheetsNumfmtCellContentController.local$,this._localeService.currentLocale$).subscribe(()=>{this._forceUpdate()}))}openPanel(){var E;const t=this._sidebarService,r=this._selectionManagerService,n=this._commandService,i=this._univerInstanceService,o=this._numfmtService,s=this._localeService,c=(((E=r.getCurrentSelections())==null?void 0:E.map(I=>I.range))||[])[0];if(!c)return!1;const d=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),h=d.getActiveSheet();if(!h)return!1;const p=h.getCellRaw(c.startRow,c.startColumn),v=o.getValue(d.getUnitId(),h.getSheetId(),c.startRow,c.startColumn);let g="";v&&(g=v.pattern);const _=(p==null?void 0:p.t)===a.CellValueType.NUMBER?p.v:12345678,f={onChange:I=>{var O;if(I.type==="change")this._previewPattern=I.value,this._forceUpdate();else if(I.type==="confirm"){const w=((O=r.getCurrentSelections())==null?void 0:O.map(R=>R.range))||[],K={values:[]},ne=m.getPatternType(I.value);w.forEach(R=>{a.Range.foreach(R,(re,T)=>{K.values.push({row:re,col:T,pattern:I.value,type:ne})})}),n.executeCommand(m.SetNumfmtCommand.id,K),t.close()}else I.type==="cancel"&&t.close()},value:{defaultPattern:g,defaultValue:_,row:c.startRow,col:c.startColumn}};return this._sidebarDisposable=t.open({header:{title:s.t("sheet.numfmt.title")},children:{label:le,...f},onClose:()=>{this._forceUpdate(),n.executeCommand(X.id)}}),!0}_forceUpdate(t){var n;const r=this._renderManagerService.getRenderById(t!=null?t:this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId());r==null||r.with(P.SheetSkeletonManagerService).reCalculate(),(n=r==null?void 0:r.mainComponent)==null||n.makeDirty()}_initCommands(){[$,X].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initPanel(){this._componentManager.register(le,He)}_initRealTimeRenderingInterceptor(){const t=new N.Observable(n=>{this._commandService.onCommandExecuted(i=>{i.id===$.id&&n.next(!0),i.id===X.id&&n.next(!1)})}),r=N.combineLatest([t,this._selectionManagerService.selectionMoveEnd$.pipe(V.map(n=>n?n.map(i=>i.range):[]))]);this.disposeWithMe(a.toDisposable(r.pipe(V.switchMap(([n,i])=>new N.Observable(o=>{const s=new a.DisposableCollection;return n&&i.length&&o.next({selectionRanges:i,disposableCollection:s}),()=>{s.dispose()}})),V.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:n,selectionRanges:i})=>{var s,l;const o=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);this.openPanel(),n.add(this._sheetInterceptorService.intercept(S.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,effect:a.InterceptorEffectEnum.Value|a.InterceptorEffectEnum.Style,handler:(c,d,h)=>{const{row:p,col:v}=d,g=h(c)||{};if(i.find(_=>_.startColumn<=v&&_.endColumn>=v&&_.startRow<=p&&_.endRow>=p)){const _=d.worksheet.getCellRaw(p,v),f=_==null?void 0:_.v,E=_==null?void 0:_.t;if(f==null||E!==a.CellValueType.NUMBER||this._previewPattern===null)return g;const I=m.getPatternPreviewIgnoreGeneral(this._previewPattern,f,this._sheetsNumfmtCellContentController.local);if(I.color){const w=this._themeService.getCurrentTheme()[`${I.color}500`];return{...g,v:I.result,t:a.CellValueType.STRING,s:{cl:{rgb:w}}}}return{...g,v:I.result,t:a.CellValueType.STRING}}return g}})),(l=(s=this._renderManagerService.getRenderById(o.getUnitId()))==null?void 0:s.mainComponent)==null||l.makeDirty()})))}_commandExecutedListener(){const t=[S.RemoveNumfmtMutation.id,S.SetNumfmtMutation.id];this.disposeWithMe(new N.Observable(r=>{const n=this._commandService.onCommandExecuted(i=>{if(t.includes(i.id)){const o=i.params;r.next(o.unitId)}});return()=>n.dispose()}).pipe(V.debounceTime(16)).subscribe(r=>this._forceUpdate(r)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(t=>{var r;t||((r=this._sidebarDisposable)==null||r.dispose(),this._sidebarDisposable=null)})}};A=xe([U(0,a.Inject(S.SheetInterceptorService)),U(1,a.Inject(a.ThemeService)),U(2,a.IUniverInstanceService),U(3,a.ICommandService),U(4,a.Inject(S.SheetsSelectionsService)),U(5,k.IRenderManagerService),U(6,S.INumfmtService),U(7,a.Inject(C.ComponentManager)),U(8,C.ISidebarService),U(9,a.Inject(a.LocaleService)),U(10,a.Inject(m.SheetsNumfmtCellContentController))],A);var Re=Object.getOwnPropertyDescriptor,We=(e,t,r,n)=>{for(var i=n>1?void 0:n?Re(t,r):t,o=e.length-1,s;o>=0;o--)(s=e[o])&&(i=s(i)||i);return i},x=(e,t)=>(r,n)=>t(r,n,e);const Ve=()=>{let e=[];return{add:(i,o,s,l,c)=>e.push({unitId:i,subUnitId:o,row:s,col:l,value:c}),getEffects:()=>e,clean:()=>{e=[]}}};let B=class extends a.Disposable{constructor(t,r,n,i,o){super();Z(this,"_collectEffectMutation",Ve());this._sheetInterceptorService=t,this._numfmtService=r,this._univerInstanceService=n,this._injector=i,this._editorBridgeService=o,this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(a.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(S.BEFORE_CELL_EDIT,{handler:(t,r,n)=>{const i=r.row,o=r.col,s=this._numfmtService.getValue(r.unitId,r.subUnitId,i,o);if(s)switch(m.getPatternType(s.pattern)){case"scientific":case"currency":case"grouped":case"number":{const c=r.worksheet.getCellRaw(i,o);return n&&n(c)}case"percent":case"date":case"time":case"datetime":default:return n&&n(t)}return n(t)}})))}_initInterceptorEditorEnd(){this.disposeWithMe(a.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(S.AFTER_CELL_EDIT,{handler:(t,r,n)=>{var h,p,v,g;this._collectEffectMutation.clean();const i=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col),o=(h=i&&m.getPatternType(i.pattern))!=null?h:"",s=()=>{i&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,null)};if(!(t!=null&&t.v)&&!(t!=null&&t.p)||W.isTextFormat(i==null?void 0:i.pattern)||t.t===a.CellValueType.FORCE_STRING)return n(t);const l=(p=t.p)==null?void 0:p.body,c=(g=(v=t==null?void 0:t.p)==null?void 0:v.body)!=null&&g.dataStream?t.p.body.dataStream.replace(/\r\n$/,""):String(t.v),d=a.numfmt.parseDate(c)||a.numfmt.parseTime(c)||a.numfmt.parseNumber(c);if(l)if(qe(l)){const{dataStream:_}=l,f=_.replace(/\r\n$/,""),E=Number(f);if(Number.isNaN(E)&&!d)return n(t)}else return n(t);if(d){d.z&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:d.z});const _=Number(d.v);return n({...t,p:void 0,v:_,t:a.CellValueType.NUMBER})}else(["date","time","datetime","percent"].includes(o)||!Be(c))&&s();return n(t)}})))}_initInterceptorCommands(){const t=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(r){var n;switch(r.id){case S.SetRangeValuesCommand.id:{const i=t._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),o=i.getUnitId(),s=(n=i.getActiveSheet())==null?void 0:n.getSheetId();if(!s)return{redos:[],undos:[]};const l=t._collectEffectMutation.getEffects();if(t._collectEffectMutation.clean(),!l.length)return{redos:[],undos:[]};const c=l.filter(v=>{var g;return!!((g=v.value)!=null&&g.pattern)}).map(v=>({row:v.row,col:v.col,pattern:v.value.pattern})),d=l.filter(v=>{var g;return!((g=v.value)!=null&&g.pattern)}).map(v=>({startRow:v.row,endColumn:v.col,startColumn:v.col,endRow:v.row})),h=[],p=[];if(c.length){const v={id:S.SetNumfmtMutation.id,params:S.transformCellsToRange(o,s,c)};h.push(v),p.push(...S.factorySetNumfmtUndoMutation(t._injector,v.params))}if(d.length){const v={id:S.RemoveNumfmtMutation.id,params:{unitId:o,subUnitId:s,ranges:d}};h.push(v),p.push(...S.factoryRemoveNumfmtUndoMutation(t._injector,v.params))}return{redos:h,undos:p.reverse()}}}return{redos:[],undos:[]}}}))}};B=We([x(0,a.Inject(S.SheetInterceptorService)),x(1,a.Inject(S.INumfmtService)),x(2,a.Inject(a.IUniverInstanceService)),x(3,a.Inject(a.Injector)),x(4,a.Optional(P.IEditorBridgeService))],B);function Be(e){return/^-?\d+(\.\d+)?$/.test(e)}function qe(e){const{textRuns:t=[],paragraphs:r=[],customRanges:n,customBlocks:i=[]}=e,o=["va"];return!(t.some(s=>!!(s.ts&&Object.keys(s.ts).some(c=>o.includes(c))))||r.some(s=>s.bullet)||r.length>=2||n!=null&&n.length||i.length>0)}const q=[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:W.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:""}],Ge=e=>({icon:new N.Observable(t=>{const r=e.get(m.MenuCurrencyService);function n(o){return{[m.countryCurrencyMap.US]:"DollarSingle",[m.countryCurrencyMap.RU]:"RoubleSingle",[m.countryCurrencyMap.CN]:"RmbSingle",[m.countryCurrencyMap.AT]:"EuroSingle"}[o]||"DollarSingle"}const i=m.countryCurrencyMap[r.getCurrencySymbol()]||"$";return t.next(n(i)),r.currencySymbol$.subscribe(o=>{const s=m.countryCurrencyMap[o]||"$";t.next(n(s))})}),id:m.SetCurrencyCommand.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:C.MenuItemType.BUTTON,hidden$:C.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:P.getCurrentRangeDisable$(e,{workbookTypes:[S.WorkbookEditablePermission],worksheetTypes:[S.WorksheetEditPermission,S.WorksheetSetCellStylePermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}),Ke=e=>({icon:"AddDigitsSingle",id:m.AddDecimalCommand.id,title:"sheet.numfmt.addDecimal",tooltip:"sheet.numfmt.addDecimal",type:C.MenuItemType.BUTTON,hidden$:C.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:P.getCurrentRangeDisable$(e,{workbookTypes:[S.WorkbookEditablePermission],worksheetTypes:[S.WorksheetEditPermission,S.WorksheetSetCellStylePermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}),Ze=e=>({icon:"ReduceDigitsSingle",id:m.SubtractDecimalCommand.id,title:"sheet.numfmt.subtractDecimal",tooltip:"sheet.numfmt.subtractDecimal",type:C.MenuItemType.BUTTON,hidden$:C.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:P.getCurrentRangeDisable$(e,{workbookTypes:[S.WorkbookEditablePermission],worksheetTypes:[S.WorksheetEditPermission,S.WorksheetSetCellStylePermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}),ze=e=>({icon:"PercentSingle",id:m.SetPercentCommand.id,title:"sheet.numfmt.percent",tooltip:"sheet.numfmt.percent",type:C.MenuItemType.BUTTON,hidden$:C.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:P.getCurrentRangeDisable$(e,{workbookTypes:[S.WorkbookEditablePermission],worksheetTypes:[S.WorksheetEditPermission,S.WorksheetSetCellStylePermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}),Ye=e=>{const t=e.get(a.IUniverInstanceService),r=e.get(a.ICommandService),n=e.get(a.LocaleService),i=e.get(S.SheetsSelectionsService),o=P.deriveStateFromActiveSheet$(t,"",({workbook:s,worksheet:l})=>new N.Observable(c=>N.merge(i.selectionMoveEnd$,new N.Observable(d=>{const h=[S.RemoveNumfmtMutation.id,S.SetNumfmtMutation.id],p=r.onCommandExecuted(v=>{h.includes(v.id)&&d.next(null)});return()=>p.dispose()})).subscribe(()=>{var h,p;const d=i.getCurrentSelections();if(d&&d[0]){const v=d[0].range,g=v.startRow,_=v.startColumn,f=(p=s.getStyles().get((h=l.getCell(g,_))==null?void 0:h.s))==null?void 0:p.n,E=f==null?void 0:f.pattern;let I=n.t("sheet.numfmt.general");if(W.isDefaultFormat(E)){c.next(I);return}if(E){const O=q.filter(w=>typeof w=="object"&&w.pattern).find(w=>m.isPatternEqualWithoutDecimal(E,w.pattern));O&&typeof O=="object"&&O.pattern?I=n.t(O.label):I=n.t("sheet.numfmt.moreFmt")}c.next(I)}})));return{label:ue,id:$.id,tooltip:"sheet.numfmt.title",type:C.MenuItemType.SELECTOR,selections:[{label:{name:me,hoverable:!1}}],value$:o,hidden$:C.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:P.getCurrentRangeDisable$(e,{workbookTypes:[S.WorkbookEditablePermission],worksheetTypes:[S.WorksheetSetCellStylePermission,S.WorksheetEditPermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}},ue="sheet.numfmt.moreNumfmtType",me="sheet.numfmt.moreNumfmtType.options",Xe=e=>{var n;const t=C.useDependency(a.LocaleService),r=(n=e.value)!=null?n:t.t("sheet.numfmt.general");return u.jsx("span",{className:"more-numfmt-type",children:r})},Je=()=>{const e=C.useDependency(a.ICommandService),t=C.useDependency(a.LocaleService),r=C.useDependency(C.ILayoutService),n=C.useDependency(m.SheetsNumfmtCellContentController),i=C.useDependency(S.SheetsSelectionsService),o=c=>{const d=i.getCurrentLastSelection();if(!d)return;const h=d.range,p=[];a.Range.foreach(h,(v,g)=>{c?p.push({row:v,col:g,pattern:c,type:m.getPatternType(c)}):p.push({row:v,col:g})}),e.executeCommand(m.SetNumfmtCommand.id,{values:p}),r.focus()},s=c=>{if(c===0)o(null);else if(c===q.length-1)e.executeCommand($.id);else{const d=q[c];d.pattern&&o(d.pattern)}},l=1220;return u.jsx("div",{className:"more-numfmt-type-options",children:q.map((c,d)=>c==="|"?u.jsx("div",{className:"line m-t-4",onClick:h=>h.stopPropagation()},d):u.jsxs("div",{className:"option-item m-t-4",onClick:()=>{s(d)},children:[u.jsx("div",{children:t.t(c.label)}),u.jsx("div",{className:"m-l-26",children:c.pattern?m.getPatternPreview(c.pattern||"",l,n.local).result:""})]},d))})},Qe={[C.RibbonStartGroup.FORMULAS_INSERT]:{[m.SetCurrencyCommand.id]:{order:4,menuItemFactory:Ge},[m.AddDecimalCommand.id]:{order:5,menuItemFactory:Ke},[m.SubtractDecimalCommand.id]:{order:6,menuItemFactory:Ze},[m.SetPercentCommand.id]:{order:7,menuItemFactory:ze},[$.id]:{order:8,menuItemFactory:Ye}}};var et=Object.getOwnPropertyDescriptor,tt=(e,t,r,n)=>{for(var i=n>1?void 0:n?et(t,r):t,o=e.length-1,s;o>=0;o--)(s=e[o])&&(i=s(i)||i);return i},de=(e,t)=>(r,n)=>t(r,n,e);let G=class extends a.Disposable{constructor(e,t){super(),this._componentManager=e,this._menuManagerService=t,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(Qe),this.disposeWithMe(this._componentManager.register(ue,Xe)),this.disposeWithMe(this._componentManager.register(me,Je))}};G=tt([de(0,a.Inject(C.ComponentManager)),de(1,C.IMenuManagerService)],G);var nt=Object.defineProperty,rt=Object.getOwnPropertyDescriptor,it=(e,t,r)=>t in e?nt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,ot=(e,t,r,n)=>{for(var i=n>1?void 0:n?rt(t,r):t,o=e.length-1,s;o>=0;o--)(s=e[o])&&(i=s(i)||i);return i},te=(e,t)=>(r,n)=>t(r,n,e),pe=(e,t,r)=>it(e,typeof t!="symbol"?t+"":t,r);const at="SHEET_NUMFMT_UI_PLUGIN";b.UniverSheetsNumfmtUIPlugin=class extends a.Plugin{constructor(t=ie,r,n,i){super(),this._config=t,this._injector=r,this._configService=n,this._renderManagerService=i;const{menu:o,...s}=a.merge({},ie,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(C.UI_PLUGIN_CONFIG_KEY,s)}onStarting(){a.registerDependencies(this._injector,[[A],[B],[H],[G]])}onRendered(){this._registerRenderModules(),a.touchDependencies(this._injector,[[A],[B],[G]])}_registerRenderModules(){[[Y]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,r))})}},pe(b.UniverSheetsNumfmtUIPlugin,"pluginName",at),pe(b.UniverSheetsNumfmtUIPlugin,"type",a.UniverInstanceType.UNIVER_SHEET),b.UniverSheetsNumfmtUIPlugin=ot([a.DependentOn(P.UniverSheetsUIPlugin,m.UniverSheetsNumfmtPlugin),te(1,a.Inject(a.Injector)),te(2,a.IConfigService),te(3,k.IRenderManagerService)],b.UniverSheetsNumfmtUIPlugin),Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
1
+ (function(b,o){typeof exports=="object"&&typeof module<"u"?o(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/jsx-runtime"),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/jsx-runtime","react","@univerjs/design"],o):(b=typeof globalThis<"u"?globalThis:b||self,o(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.React,b.UniverDesign))})(this,function(b,o,k,m,M,C,ve,W,h,w,V,u,y,P){"use strict";var lt=Object.defineProperty;var ut=(b,o,k)=>o in b?lt(b,o,{enumerable:!0,configurable:!0,writable:!0,value:k}):b[o]=k;var Z=(b,o,k)=>ut(b,typeof o!="symbol"?o+"":o,k);const ie={};var fe=Object.getOwnPropertyDescriptor,he=(e,t,r,n)=>{for(var i=n>1?void 0:n?fe(t,r):t,a=e.length-1,s;a>=0;a--)(s=e[a])&&(i=s(i)||i);return i},L=(e,t)=>(r,n)=>t(r,n,e);const z="SHEET_NUMFMT_ALERT";let Y=class extends o.Disposable{constructor(e,t,r,n,i,a,s){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=r,this._localeService=n,this._formulaDataModel=i,this._zenZoneService=a,this._numfmtService=s,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(w.debounceTime(100)).subscribe(e=>{var t;if(e){const r=e.location,n=this._context.unit,i=n.getActiveSheet();if(!i)return;const a=r.unitId,s=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,s,r.row,r.col)),!l){this._hideAlert();return}if(W.isTextFormat(l.pattern)&&(c!=null&&c.v)&&o.isRealNum(c.v)){const d=this._cellAlertManagerService.currentAlert.get(z),S=(t=d==null?void 0:d.alert)==null?void 0:t.location;if(S&&S.row===r.row&&S.col===r.col&&S.subUnitId===r.subUnitId&&S.unitId===r.unitId)return;this._cellAlertManagerService.showAlert({type:M.CellAlertType.ERROR,title:this._localeService.t("info.error"),message:this._localeService.t("info.forceStringInfo"),location:r,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)}};Y=he([L(1,o.Inject(M.HoverManagerService)),L(2,o.Inject(M.CellAlertManagerService)),L(3,o.Inject(o.LocaleService)),L(4,o.Inject(ve.FormulaDataModel)),L(5,C.IZenZoneService),L(6,o.Inject(h.INumfmtService))],Y);const X={id:"sheet.operation.close.numfmt.panel",type:o.CommandType.OPERATION,handler:()=>!0},$={id:"sheet.operation.open.numfmt.panel",type:o.CommandType.OPERATION,handler:e=>(e.get(x).openPanel(),!0)};var Se=Object.getOwnPropertyDescriptor,ge=(e,t,r,n)=>{for(var i=n>1?void 0:n?Se(t,r):t,a=e.length-1,s;a>=0;a--)(s=e[a])&&(i=s(i)||i);return i},ye=(e,t)=>(r,n)=>t(r,n,e);const J=y.createContext([]);let H=class{constructor(e){this._localStorageService=e}_getKey(e){return`userHabitController_${e}`}async addHabit(e,t){const r=this._getKey(e);return this._localStorageService.getItem(r).then(n=>{n||this._localStorageService.setItem(r,t)})}markHabit(e,t){const r=this._getKey(e);this._localStorageService.getItem(r).then(n=>{if(n){const i=n.findIndex(a=>a===t);i>-1&&n.splice(i,1),n.unshift(t),this._localStorageService.setItem(r,n)}})}async getHabit(e,t){const r=this._getKey(e),n=await this._localStorageService.getItem(r);if(t&&n){const i=n.map((a,s,l)=>{const c=l.length;return{value:a,priority:c-s}});return t.sort((a,s)=>{var d,S;const l=((d=i.find(p=>p.value===a))==null?void 0:d.priority)||-1;return(((S=i.find(p=>p.value===s))==null?void 0:S.priority)||-1)-l})}return n||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};H=ge([ye(0,o.Inject(o.ILocalStorageService))],H);const ae="numfmtCurrency",_e=e=>{const t=C.useDependency(H),[r,n]=y.useState(m.currencySymbols);return y.useEffect(()=>{t.addHabit("numfmtCurrency",[]).then(()=>{t.getHabit(ae,[...m.currencySymbols]).then(a=>{n(a),e&&e(a)})})},[]),{userHabitCurrency:r,mark:a=>{t.markHabit(ae,a)}}},Ce=()=>{const e=y.useRef([]),[t,r]=y.useState({});return y.useEffect(()=>{e.current.forEach(i=>{i()}),e.current=[]},[t]),i=>{e.current.push(i),r({})}},be=e=>!!m.getCurrencyType(e)&&e.startsWith("_("),Ie=e=>{const{defaultPattern:t,action:r,onChange:n}=e,[i,a]=y.useState(()=>m.getDecimalFromPattern(t||"",2)),s=y.useContext(J),[l,c]=y.useState(()=>m.getCurrencyType(t)||s[0]),d=y.useMemo(()=>s.map(_=>({label:_,value:_})),[]),p=C.useDependency(o.LocaleService).t;r.current=()=>m.setPatternDecimal(`_("${l}"* #,##0${i>0?".0":""}_)`,i);const v=_=>{c(_),n(m.setPatternDecimal(`_("${_}"* #,##0${i>0?".0":""}_)`,i))},g=_=>{const f=_||0;a(f),n(m.setPatternDecimal(`_("${l}"* #,##0${f>0?".0":""}_)`,f))};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(P.InputNumber,{value:i,max:20,min:0,onChange:g})})]}),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(P.Select,{onChange:v,options:d,value:l})})]})]}),u.jsx("div",{className:"describe m-t-14",children:p("sheet.numfmt.accountingDes")})]})},Te=e=>!!m.getCurrencyType(e)&&!e.startsWith("_("),Ee=e=>{const r=C.useDependency(o.LocaleService).t,n=y.useContext(J),[i,a]=y.useState(()=>m.getCurrencyType(e.defaultPattern)||n[0]),[s,l]=y.useState(()=>m.getDecimalFromPattern(e.defaultPattern||"",2)),[c,d]=y.useState(()=>{var I;const f=m.getCurrencyFormatOptions(i);return((I=f.find(O=>m.isPatternEqualWithoutDecimal(O.value,e.defaultPattern)))==null?void 0:I.value)||f[0].value}),S=y.useMemo(()=>m.getCurrencyFormatOptions(i),[i]),p=y.useMemo(()=>n.map(f=>({label:f,value:f})),[n]);e.action.current=()=>m.setPatternDecimal(c,s);const v=f=>{if(f===void 0)return;a(f);const E=m.getCurrencyFormatOptions(f)[0].value;d(E),e.onChange(m.setPatternDecimal(E,s))},g=f=>{f!==void 0&&(d(f),e.onChange(m.setPatternDecimal(f,s)))},_=f=>{l(f||0),e.onChange(m.setPatternDecimal(c,f||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(P.InputNumber,{value:s,max:20,min:0,onChange:_})})]}),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(P.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(P.SelectList,{onChange:g,options:S,value:c})}),u.jsx("div",{className:"describe m-t-14",children:r("sheet.numfmt.currencyDes")})]})};var D=function(){return D=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},D.apply(this,arguments)},Pe=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r},oe=y.forwardRef(function(e,t){var r=e.icon,n=e.id,i=e.className,a=e.extend,s=Pe(e,["icon","id","className","extend"]),l="univerjs-icon univerjs-icon-".concat(n," ").concat(i||"").trim(),c=y.useRef("_".concat(Oe()));return se(r,"".concat(n),{defIds:r.defIds,idSuffix:c.current},D({ref:t,className:l},s),a)});function se(e,t,r,n,i){return y.createElement(e.tag,D(D({key:t},Me(e,r,i)),n),(De(e,r).children||[]).map(function(a,s){return se(a,"".concat(t,"-").concat(e.tag,"-").concat(s),r,void 0,i)}))}function Me(e,t,r){var n=D({},e.attrs);r!=null&&r.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=r.colorChannel1),e.tag==="mask"&&n.id&&(n.id=n.id+t.idSuffix),Object.entries(n).forEach(function(a){var s=a[0],l=a[1];s==="mask"&&typeof l=="string"&&(n[s]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var i=t.defIds;return!i||i.length===0||(e.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(function(a){var s=a[0],l=a[1];typeof l=="string"&&(n[s]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function De(e,t){var r,n=t.defIds;return!n||n.length===0?e:e.tag==="defs"&&(!((r=e.children)===null||r===void 0)&&r.length)?D(D({},e),{children:e.children.map(function(i){return typeof i.attrs.id=="string"&&n&&n.indexOf(i.attrs.id)>-1?D(D({},i),{attrs:D(D({},i.attrs),{id:i.attrs.id+t.idSuffix})}):i})}):e}function Oe(){return Math.random().toString(36).substring(2,8)}oe.displayName="UniverIcon";var Ue={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"}}]},ce=y.forwardRef(function(e,t){return y.createElement(oe,Object.assign({},e,{id:"check-mark-single",ref:t,icon:Ue}))});ce.displayName="CheckMarkSingle";const F={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"},Q="customFormat",ee="numfmt_custom_pattern";function we(e){const{defaultPattern:t,action:r,onChange:n}=e,i=C.useDependency(H),a=C.useDependency(o.ILocalStorageService),s=C.useDependency(o.LocaleService),[l,c]=y.useState(t);r.current=()=>(i.markHabit(Q,l),a.getItem(ee).then((g=[])=>{const _=[...new Set([l,...g||[]])].splice(0,10).filter(f=>!!f);a.setItem(ee,_)}),l);const[d,S]=y.useState([]);y.useEffect(()=>{a.getItem(ee).then(g=>{const _=[...m.CURRENCYFORMAT.map(f=>f.suffix("$")),...m.DATEFMTLISG.map(f=>f.suffix),...m.NUMBERFORMAT.map(f=>f.suffix)];_.push(...g||[]),i.addHabit(Q,[]).finally(()=>{i.getHabit(Q,_).then(f=>{S([...new Set(f)])})})})},[]);const p=g=>{c(g),n(g)},v=()=>{n(l)};return u.jsxs("div",{className:F.customFormat,children:[u.jsx("div",{className:F.customFormatTitle,children:s.t("sheet.numfmt.customFormat")}),u.jsx(P.Input,{placeholder:s.t("sheet.numfmt.customFormat"),onBlur:v,value:l,onChange:c,className:F.customFormatInput}),u.jsx("div",{className:F.customFormatHistoryList,children:d.map(g=>u.jsxs("div",{onClick:()=>p(g),className:F.customFormatHistoryListItem,children:[u.jsx("div",{className:F.customFormatHistoryListItemIconWrap,children:l===g&&u.jsx(ce,{})}),u.jsx("div",{children:g})]},g))}),u.jsx("div",{className:F.customFormatDes,children:s.t("sheet.numfmt.customFormatDes")})]})}const Ne=e=>{const t=o.numfmt.getInfo(e);return m.getDateFormatOptions().map(r=>r.value).includes(e)||["date","datetime","time"].includes(t.type)},ke=e=>{const t=y.useMemo(m.getDateFormatOptions,[]),n=C.useDependency(o.LocaleService).t,[i,a]=y.useState(()=>{if(e.defaultPattern){const l=t.find(c=>c.value===e.defaultPattern);if(l)return l.value}return t[0].value});e.action.current=()=>i;const s=l=>{l!==void 0&&(a(l),e.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(P.SelectList,{value:i,options:t,onChange:s})}),u.jsx("div",{className:"describe m-t-14",children:n("sheet.numfmt.dateDes")})]})},Fe=e=>!e,Le=e=>{const r=C.useDependency(o.LocaleService).t;return e.action.current=()=>"",u.jsx("div",{children:u.jsx("div",{className:"describe m-t-14",children:r("sheet.numfmt.generalDes")})})},je=e=>m.getNumberFormatOptions().some(t=>m.isPatternEqualWithoutDecimal(t.value,e)),$e=e=>{const t=C.useDependency(o.LocaleService),r=y.useMemo(m.getNumberFormatOptions,[]),[n,i]=y.useState(()=>m.getDecimalFromPattern(e.defaultPattern||"",0)),[a,s]=y.useState(()=>{const p=r.find(v=>m.isPatternEqualWithoutDecimal(v.value,e.defaultPattern||""));return(p==null?void 0:p.value)||r[0].value}),l=y.useMemo(()=>m.setPatternDecimal(a,Number(n||0)),[a,n]),c=y.useMemo(()=>!m.isPatternHasDecimal(a),[a]),d=p=>{i(p||0),e.onChange(m.setPatternDecimal(a,Number(p||0)))},S=p=>{p!==void 0&&(i(m.getDecimalFromPattern(p,0)),s(p),e.onChange(p))};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(P.InputNumber,{disabled:c,value:n,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(P.SelectList,{onChange:S,options:r,value:a})}),u.jsx("div",{className:"describe m-t-14",children:t.t("sheet.numfmt.thousandthPercentileDes")})]})},He=e=>{const{defaultValue:t,defaultPattern:r,row:n,col:i}=e.value,a=C.useDependency(o.LocaleService),s=y.useRef(()=>""),l=a.t,c=Ce(),d=y.useMemo(()=>[{label:"sheet.numfmt.general",component:Le},{label:"sheet.numfmt.accounting",component:Ie},{label:"sheet.numfmt.currency",component:Ee},{label:"sheet.numfmt.date",component:ke},{label:"sheet.numfmt.thousandthPercentile",component:$e},{label:"sheet.numfmt.customFormat",component:we}].map(T=>({...T,label:l(T.label)})),[]),[S,p]=y.useState(I),[v,g]=y.useState(()=>`${n}_${i}`),{mark:_,userHabitCurrency:f}=_e(()=>g(`${n}_${i}_userCurrency'`)),E=y.useMemo(()=>{var T;return(T=d.find(j=>j.label===S))==null?void 0:T.component},[S]);function I(){return[Fe,be,Te,Ne,je].reduce((j,st,ct)=>j||(st(r)?d[ct].label:""),"")||d[0].label}const O=d.map(T=>({label:T.label,value:T.label})),N=T=>{p(T),c(()=>e.onChange({type:"change",value:s.current()||""}))},K=T=>{e.onChange({type:"change",value:T})},ne=()=>{const T=s.current()||"",j=m.getCurrencyType(T);j&&_(j),e.onChange({type:"confirm",value:T})},R=()=>{e.onChange({type:"cancel",value:""})},re={onChange:K,defaultValue:t,defaultPattern:r,action:s};return y.useEffect(()=>{p(I()),g(`${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(P.Select,{onChange:N,options:O,value:S,style:{width:"100%"}})}),u.jsx("div",{children:E&&u.jsx(J.Provider,{value:f,children:y.createElement(E,{...re,key:v})})})]}),u.jsxs("div",{className:"btn-list m-t-14 m-b-20",children:[u.jsx(P.Button,{size:"small",onClick:R,className:"m-r-12",children:l("sheet.numfmt.cancel")}),u.jsx(P.Button,{type:"primary",size:"small",onClick:ne,children:l("sheet.numfmt.confirm")})]})]})};var xe=Object.getOwnPropertyDescriptor,Ae=(e,t,r,n)=>{for(var i=n>1?void 0:n?xe(t,r):t,a=e.length-1,s;a>=0;a--)(s=e[a])&&(i=s(i)||i);return i},U=(e,t)=>(r,n)=>t(r,n,e);const le="SHEET_NUMFMT_PANEL";let x=class extends o.Disposable{constructor(t,r,n,i,a,s,l,c,d,S,p){super();Z(this,"_previewPattern","");Z(this,"_sidebarDisposable",null);this._sheetInterceptorService=t,this._themeService=r,this._univerInstanceService=n,this._commandService=i,this._selectionManagerService=a,this._renderManagerService=s,this._numfmtService=l,this._componentManager=c,this._sidebarService=d,this._localeService=S,this._sheetsNumfmtCellContentController=p,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener(),this._initNumfmtLocalChange()}_initNumfmtLocalChange(){this.disposeWithMe(w.merge(this._sheetsNumfmtCellContentController.local$,this._localeService.currentLocale$).subscribe(()=>{this._forceUpdate()}))}openPanel(){var E;const t=this._sidebarService,r=this._selectionManagerService,n=this._commandService,i=this._univerInstanceService,a=this._numfmtService,s=this._localeService,c=(((E=r.getCurrentSelections())==null?void 0:E.map(I=>I.range))||[])[0];if(!c)return!1;const d=i.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),S=d.getActiveSheet();if(!S)return!1;const p=S.getCellRaw(c.startRow,c.startColumn),v=a.getValue(d.getUnitId(),S.getSheetId(),c.startRow,c.startColumn);let g="";v&&(g=v.pattern);const _=(p==null?void 0:p.t)===o.CellValueType.NUMBER?p.v:12345678,f={onChange:I=>{var O;if(I.type==="change")this._previewPattern=I.value,this._forceUpdate();else if(I.type==="confirm"){const N=((O=r.getCurrentSelections())==null?void 0:O.map(R=>R.range))||[],K={values:[]},ne=m.getPatternType(I.value);N.forEach(R=>{o.Range.foreach(R,(re,T)=>{K.values.push({row:re,col:T,pattern:I.value,type:ne})})}),n.executeCommand(m.SetNumfmtCommand.id,K),t.close()}else I.type==="cancel"&&t.close()},value:{defaultPattern:g,defaultValue:_,row:c.startRow,col:c.startColumn}};return this._sidebarDisposable=t.open({header:{title:s.t("sheet.numfmt.title")},children:{label:le,...f},onClose:()=>{this._forceUpdate(),n.executeCommand(X.id)}}),!0}_forceUpdate(t){var n;const r=this._renderManagerService.getRenderById(t!=null?t:this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET).getUnitId());r==null||r.with(M.SheetSkeletonManagerService).reCalculate(),(n=r==null?void 0:r.mainComponent)==null||n.makeDirty()}_initCommands(){[$,X].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initPanel(){this._componentManager.register(le,He)}_initRealTimeRenderingInterceptor(){const t=new w.Observable(n=>{this._commandService.onCommandExecuted(i=>{i.id===$.id&&n.next(!0),i.id===X.id&&n.next(!1)})}),r=w.combineLatest([t,this._selectionManagerService.selectionMoveEnd$.pipe(V.map(n=>n?n.map(i=>i.range):[]))]);this.disposeWithMe(o.toDisposable(r.pipe(V.switchMap(([n,i])=>new w.Observable(a=>{const s=new o.DisposableCollection;return n&&i.length&&a.next({selectionRanges:i,disposableCollection:s}),()=>{s.dispose()}})),V.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:n,selectionRanges:i})=>{var s,l;const a=this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);this.openPanel(),n.add(this._sheetInterceptorService.intercept(h.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,effect:o.InterceptorEffectEnum.Value|o.InterceptorEffectEnum.Style,handler:(c,d,S)=>{const{row:p,col:v}=d,g=S(c)||{};if(i.find(_=>_.startColumn<=v&&_.endColumn>=v&&_.startRow<=p&&_.endRow>=p)){const _=d.worksheet.getCellRaw(p,v),f=_==null?void 0:_.v,E=_==null?void 0:_.t;if(f==null||E!==o.CellValueType.NUMBER||this._previewPattern===null)return g;const I=m.getPatternPreviewIgnoreGeneral(this._previewPattern,f,this._sheetsNumfmtCellContentController.local);if(I.color){const N=this._themeService.getCurrentTheme()[`${I.color}500`];return{...g,v:I.result,t:o.CellValueType.STRING,s:{cl:{rgb:N}}}}return{...g,v:I.result,t:o.CellValueType.STRING}}return g}})),(l=(s=this._renderManagerService.getRenderById(a.getUnitId()))==null?void 0:s.mainComponent)==null||l.makeDirty()})))}_commandExecutedListener(){const t=[h.RemoveNumfmtMutation.id,h.SetNumfmtMutation.id];this.disposeWithMe(new w.Observable(r=>{const n=this._commandService.onCommandExecuted(i=>{if(t.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$(o.UniverInstanceType.UNIVER_SHEET).subscribe(t=>{var r;t||((r=this._sidebarDisposable)==null||r.dispose(),this._sidebarDisposable=null)})}};x=Ae([U(0,o.Inject(h.SheetInterceptorService)),U(1,o.Inject(o.ThemeService)),U(2,o.IUniverInstanceService),U(3,o.ICommandService),U(4,o.Inject(h.SheetsSelectionsService)),U(5,k.IRenderManagerService),U(6,h.INumfmtService),U(7,o.Inject(C.ComponentManager)),U(8,C.ISidebarService),U(9,o.Inject(o.LocaleService)),U(10,o.Inject(m.SheetsNumfmtCellContentController))],x);var Re=Object.getOwnPropertyDescriptor,We=(e,t,r,n)=>{for(var i=n>1?void 0:n?Re(t,r):t,a=e.length-1,s;a>=0;a--)(s=e[a])&&(i=s(i)||i);return i},A=(e,t)=>(r,n)=>t(r,n,e);const Ve=()=>{let e=[];return{add:(i,a,s,l,c)=>e.push({unitId:i,subUnitId:a,row:s,col:l,value:c}),getEffects:()=>e,clean:()=>{e=[]}}};let B=class extends o.Disposable{constructor(t,r,n,i,a){super();Z(this,"_collectEffectMutation",Ve());this._sheetInterceptorService=t,this._numfmtService=r,this._univerInstanceService=n,this._injector=i,this._editorBridgeService=a,this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(o.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(h.BEFORE_CELL_EDIT,{handler:(t,r,n)=>{const i=r.row,a=r.col,s=this._numfmtService.getValue(r.unitId,r.subUnitId,i,a);if(s)switch(m.getPatternType(s.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(t)}return n(t)}})))}_initInterceptorEditorEnd(){this.disposeWithMe(o.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(h.AFTER_CELL_EDIT,{handler:(t,r,n)=>{var S,p,v,g;this._collectEffectMutation.clean();const i=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col),a=(S=i&&m.getPatternType(i.pattern))!=null?S:"",s=()=>{i&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,null)};if(!(t!=null&&t.v)&&!(t!=null&&t.p)||W.isTextFormat(i==null?void 0:i.pattern)||t.t===o.CellValueType.FORCE_STRING)return n(t);const l=(p=t.p)==null?void 0:p.body,c=(g=(v=t==null?void 0:t.p)==null?void 0:v.body)!=null&&g.dataStream?t.p.body.dataStream.replace(/\r\n$/,""):String(t.v),d=o.numfmt.parseDate(c)||o.numfmt.parseTime(c)||o.numfmt.parseNumber(c);if(l)if(qe(l)){const{dataStream:_}=l,f=_.replace(/\r\n$/,""),E=Number(f);if(Number.isNaN(E)&&!d)return n(t)}else return n(t);if(d){d.z&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:d.z});const _=Number(d.v);return n({...t,p:void 0,v:_,t:o.CellValueType.NUMBER})}else(["date","time","datetime","percent"].includes(a)||!Be(c))&&s();return n(t)}})))}_initInterceptorCommands(){const t=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(r){var n;switch(r.id){case h.SetRangeValuesCommand.id:{const i=t._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),a=i.getUnitId(),s=(n=i.getActiveSheet())==null?void 0:n.getSheetId();if(!s)return{redos:[],undos:[]};const l=t._collectEffectMutation.getEffects();if(t._collectEffectMutation.clean(),!l.length)return{redos:[],undos:[]};const c=l.filter(v=>{var g;return!!((g=v.value)!=null&&g.pattern)}).map(v=>({row:v.row,col:v.col,pattern:v.value.pattern})),d=l.filter(v=>{var g;return!((g=v.value)!=null&&g.pattern)}).map(v=>({startRow:v.row,endColumn:v.col,startColumn:v.col,endRow:v.row})),S=[],p=[];if(c.length){const v={id:h.SetNumfmtMutation.id,params:h.transformCellsToRange(a,s,c)};S.push(v),p.push(...h.factorySetNumfmtUndoMutation(t._injector,v.params))}if(d.length){const v={id:h.RemoveNumfmtMutation.id,params:{unitId:a,subUnitId:s,ranges:d}};S.push(v),p.push(...h.factoryRemoveNumfmtUndoMutation(t._injector,v.params))}return{redos:S,undos:p.reverse()}}}return{redos:[],undos:[]}}}))}};B=We([A(0,o.Inject(h.SheetInterceptorService)),A(1,o.Inject(h.INumfmtService)),A(2,o.Inject(o.IUniverInstanceService)),A(3,o.Inject(o.Injector)),A(4,o.Optional(M.IEditorBridgeService))],B);function Be(e){return/^-?\d+(\.\d+)?$/.test(e)}function qe(e){const{textRuns:t=[],paragraphs:r=[],customRanges:n,customBlocks:i=[]}=e,a=["va"];return!(t.some(s=>!!(s.ts&&Object.keys(s.ts).some(c=>a.includes(c))))||r.some(s=>s.bullet)||r.length>=2||n!=null&&n.length||i.length>0)}const q=[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:W.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:""}],Ge=e=>({icon:new w.Observable(t=>{const r=e.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 t.next(n(i)),r.currencySymbol$.subscribe(a=>{const s=m.countryCurrencyMap[a]||"$";t.next(n(s))})}),id:m.SetCurrencyCommand.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:C.MenuItemType.BUTTON,hidden$:C.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:M.getCurrentRangeDisable$(e,{workbookTypes:[h.WorkbookEditablePermission],worksheetTypes:[h.WorksheetEditPermission,h.WorksheetSetCellStylePermission],rangeTypes:[h.RangeProtectionPermissionEditPoint]})}),Ke=e=>({icon:"AddDigitsSingle",id:m.AddDecimalCommand.id,title:"sheet.numfmt.addDecimal",tooltip:"sheet.numfmt.addDecimal",type:C.MenuItemType.BUTTON,hidden$:C.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:M.getCurrentRangeDisable$(e,{workbookTypes:[h.WorkbookEditablePermission],worksheetTypes:[h.WorksheetEditPermission,h.WorksheetSetCellStylePermission],rangeTypes:[h.RangeProtectionPermissionEditPoint]})}),Ze=e=>({icon:"ReduceDigitsSingle",id:m.SubtractDecimalCommand.id,title:"sheet.numfmt.subtractDecimal",tooltip:"sheet.numfmt.subtractDecimal",type:C.MenuItemType.BUTTON,hidden$:C.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:M.getCurrentRangeDisable$(e,{workbookTypes:[h.WorkbookEditablePermission],worksheetTypes:[h.WorksheetEditPermission,h.WorksheetSetCellStylePermission],rangeTypes:[h.RangeProtectionPermissionEditPoint]})}),ze=e=>({icon:"PercentSingle",id:m.SetPercentCommand.id,title:"sheet.numfmt.percent",tooltip:"sheet.numfmt.percent",type:C.MenuItemType.BUTTON,hidden$:C.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:M.getCurrentRangeDisable$(e,{workbookTypes:[h.WorkbookEditablePermission],worksheetTypes:[h.WorksheetEditPermission,h.WorksheetSetCellStylePermission],rangeTypes:[h.RangeProtectionPermissionEditPoint]})}),Ye=e=>{const t=e.get(o.IUniverInstanceService),r=e.get(o.ICommandService),n=e.get(o.LocaleService),i=e.get(h.SheetsSelectionsService),a=M.deriveStateFromActiveSheet$(t,"",({workbook:s,worksheet:l})=>new w.Observable(c=>w.merge(i.selectionMoveEnd$,new w.Observable(d=>{const S=[h.RemoveNumfmtMutation.id,h.SetNumfmtMutation.id],p=r.onCommandExecuted(v=>{S.includes(v.id)&&d.next(null)});return()=>p.dispose()})).subscribe(()=>{var S,p;const d=i.getCurrentSelections();if(d&&d[0]){const v=d[0].range,g=v.startRow,_=v.startColumn,f=(p=s.getStyles().get((S=l.getCell(g,_))==null?void 0:S.s))==null?void 0:p.n,E=f==null?void 0:f.pattern;let I=n.t("sheet.numfmt.general");if(W.isDefaultFormat(E)){c.next(I);return}if(E){const O=q.filter(N=>typeof N=="object"&&N.pattern).find(N=>m.isPatternEqualWithoutDecimal(E,N.pattern));O&&typeof O=="object"&&O.pattern?I=n.t(O.label):I=n.t("sheet.numfmt.moreFmt")}c.next(I)}})));return{label:ue,id:$.id,tooltip:"sheet.numfmt.title",type:C.MenuItemType.SELECTOR,slot:!0,selections:[{label:{name:me,hoverable:!1,selectable:!1}}],value$:a,hidden$:C.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:M.getCurrentRangeDisable$(e,{workbookTypes:[h.WorkbookEditablePermission],worksheetTypes:[h.WorksheetSetCellStylePermission,h.WorksheetEditPermission],rangeTypes:[h.RangeProtectionPermissionEditPoint]})}},ue="sheet.numfmt.moreNumfmtType",me="sheet.numfmt.moreNumfmtType.options",Xe=e=>{const{value:t}=e,r=C.useDependency(o.LocaleService),n=t!=null?t:r.t("sheet.numfmt.general");return u.jsx("span",{className:"univer-text-sm",children:n})},Je=()=>{const e=C.useDependency(o.ICommandService),t=C.useDependency(o.LocaleService),r=C.useDependency(C.ILayoutService),n=C.useDependency(m.SheetsNumfmtCellContentController),i=C.useDependency(h.SheetsSelectionsService),a=c=>{const d=i.getCurrentLastSelection();if(!d)return;const S=d.range,p=[];o.Range.foreach(S,(v,g)=>{c?p.push({row:v,col:g,pattern:c,type:m.getPatternType(c)}):p.push({row:v,col:g})}),e.executeCommand(m.SetNumfmtCommand.id,{values:p}),r.focus()},s=c=>{if(c===0)a(null);else if(c===q.length-1)e.executeCommand($.id),r.focus();else{const d=q[c];d.pattern&&a(d.pattern)}},l=1220;return u.jsx("div",{className:"univer-grid univer-gap-1 univer-p-1.5",children:q.map((c,d)=>c==="|"?u.jsx(P.Separator,{},d):u.jsxs("div",{className:`
2
+ univer-flex univer-h-7 univer-items-center univer-justify-between univer-gap-6 univer-rounded
3
+ univer-px-2 univer-text-[13px]
4
+ hover:univer-bg-gray-100
5
+ `,onClick:()=>{s(d)},children:[u.jsx("span",{children:t.t(c.label)}),u.jsx("span",{className:"univer-text-xs univer-text-gray-500",children:c.pattern?m.getPatternPreview(c.pattern||"",l,n.local).result.trim():""})]},d))})},Qe={[C.RibbonStartGroup.FORMULAS_INSERT]:{[m.SetCurrencyCommand.id]:{order:4,menuItemFactory:Ge},[m.AddDecimalCommand.id]:{order:5,menuItemFactory:Ke},[m.SubtractDecimalCommand.id]:{order:6,menuItemFactory:Ze},[m.SetPercentCommand.id]:{order:7,menuItemFactory:ze},[$.id]:{order:8,menuItemFactory:Ye}}};var et=Object.getOwnPropertyDescriptor,tt=(e,t,r,n)=>{for(var i=n>1?void 0:n?et(t,r):t,a=e.length-1,s;a>=0;a--)(s=e[a])&&(i=s(i)||i);return i},de=(e,t)=>(r,n)=>t(r,n,e);let G=class extends o.Disposable{constructor(e,t){super(),this._componentManager=e,this._menuManagerService=t,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(Qe),this.disposeWithMe(this._componentManager.register(ue,Xe)),this.disposeWithMe(this._componentManager.register(me,Je))}};G=tt([de(0,o.Inject(C.ComponentManager)),de(1,C.IMenuManagerService)],G);var nt=Object.defineProperty,rt=Object.getOwnPropertyDescriptor,it=(e,t,r)=>t in e?nt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,at=(e,t,r,n)=>{for(var i=n>1?void 0:n?rt(t,r):t,a=e.length-1,s;a>=0;a--)(s=e[a])&&(i=s(i)||i);return i},te=(e,t)=>(r,n)=>t(r,n,e),pe=(e,t,r)=>it(e,typeof t!="symbol"?t+"":t,r);const ot="SHEET_NUMFMT_UI_PLUGIN";b.UniverSheetsNumfmtUIPlugin=class extends o.Plugin{constructor(t=ie,r,n,i){super(),this._config=t,this._injector=r,this._configService=n,this._renderManagerService=i;const{menu:a,...s}=o.merge({},ie,this._config);a&&this._configService.setConfig("menu",a,{merge:!0}),this._configService.setConfig(C.UI_PLUGIN_CONFIG_KEY,s)}onStarting(){o.registerDependencies(this._injector,[[x],[B],[H],[G]])}onRendered(){this._registerRenderModules(),o.touchDependencies(this._injector,[[x],[B],[G]])}_registerRenderModules(){[[Y]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,r))})}},pe(b.UniverSheetsNumfmtUIPlugin,"pluginName",ot),pe(b.UniverSheetsNumfmtUIPlugin,"type",o.UniverInstanceType.UNIVER_SHEET),b.UniverSheetsNumfmtUIPlugin=at([o.DependentOn(M.UniverSheetsUIPlugin,m.UniverSheetsNumfmtPlugin),te(1,o.Inject(o.Injector)),te(2,o.IConfigService),te(3,k.IRenderManagerService)],b.UniverSheetsNumfmtUIPlugin),Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-numfmt-ui",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "private": false,
5
5
  "description": "UniverSheet numfmt plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -55,15 +55,15 @@
55
55
  },
56
56
  "dependencies": {
57
57
  "@univerjs/icons": "^0.2.20",
58
- "@univerjs/core": "0.6.1",
59
- "@univerjs/design": "0.6.1",
60
- "@univerjs/engine-formula": "0.6.1",
61
- "@univerjs/engine-numfmt": "0.6.1",
62
- "@univerjs/engine-render": "0.6.1",
63
- "@univerjs/sheets": "0.6.1",
64
- "@univerjs/sheets-numfmt": "0.6.1",
65
- "@univerjs/sheets-ui": "0.6.1",
66
- "@univerjs/ui": "0.6.1"
58
+ "@univerjs/core": "0.6.2",
59
+ "@univerjs/design": "0.6.2",
60
+ "@univerjs/engine-formula": "0.6.2",
61
+ "@univerjs/engine-numfmt": "0.6.2",
62
+ "@univerjs/engine-render": "0.6.2",
63
+ "@univerjs/sheets": "0.6.2",
64
+ "@univerjs/sheets-numfmt": "0.6.2",
65
+ "@univerjs/sheets-ui": "0.6.2",
66
+ "@univerjs/ui": "0.6.2"
67
67
  },
68
68
  "devDependencies": {
69
69
  "less": "^4.2.2",
@@ -72,9 +72,9 @@
72
72
  "rxjs": "^7.8.1",
73
73
  "tailwindcss": "^3.4.17",
74
74
  "typescript": "^5.7.3",
75
- "vite": "^6.1.1",
76
- "vitest": "^3.0.6",
77
- "@univerjs-infra/shared": "0.6.1"
75
+ "vite": "^6.2.0",
76
+ "vitest": "^3.0.7",
77
+ "@univerjs-infra/shared": "0.6.2"
78
78
  },
79
79
  "scripts": {
80
80
  "test": "vitest run",