@univerjs/sheets-numfmt-ui 0.14.0 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var de=Object.defineProperty;var he=(e,t,r)=>t in e?de(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var A=(e,t,r)=>he(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),ne=require("@univerjs/engine-render"),d=require("@univerjs/sheets-numfmt"),E=require("@univerjs/sheets-ui"),g=require("@univerjs/sheets"),_=require("@univerjs/ui"),j=require("rxjs"),H=require("rxjs/operators"),l=require("react/jsx-runtime"),y=require("react"),T=require("@univerjs/design"),ve=require("@univerjs/engine-formula"),J={};var fe=Object.getOwnPropertyDescriptor,pe=(e,t,r,n)=>{for(var i=n>1?void 0:n?fe(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=c(i)||i);return i},U=(e,t)=>(r,n)=>t(r,n,e);const q="SHEET_NUMFMT_ALERT";let z=class extends o.Disposable{constructor(e,t,r,n,i,s,c){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=r,this._localeService=n,this._zenZoneService=i,this._numfmtService=s,this._configService=c,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(j.debounceTime(100)).subscribe(e=>{var t,r;if(e){const n=e.location,i=this._context.unit,s=i.getActiveSheet();if(!s)return this._hideAlert();const c=n.unitId,v=n.subUnitId;let a;const u=s.getCell(n.row,n.col);if(u!=null&&u.s){const h=i.getStyles().get(u.s);h!=null&&h.n&&(a=h.n)}if(a||(a=this._numfmtService.getValue(c,v,n.row,n.col)),!a){this._hideAlert();return}if(o.isTextFormat(a.pattern)&&o.Tools.isDefine(u==null?void 0:u.v)&&o.isRealNum(u.v)){if((t=this._configService.getConfig(d.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY))!=null&&t.disableTextFormatAlert)return;const h=this._cellAlertManagerService.currentAlert.get(q),m=(r=h==null?void 0:h.alert)==null?void 0:r.location;if(m&&m.row===n.row&&m.col===n.col&&m.subUnitId===n.subUnitId&&m.unitId===n.unitId){this._hideAlert();return}this._cellAlertManagerService.showAlert({type:E.CellAlertType.ERROR,title:this._localeService.t("info.error"),message:this._localeService.t("info.forceStringInfo"),location:n,width:200,height:74,key:q});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(q)}};z=pe([U(1,o.Inject(E.HoverManagerService)),U(2,o.Inject(E.CellAlertManagerService)),U(3,o.Inject(o.LocaleService)),U(4,_.IZenZoneService),U(5,o.Inject(g.INumfmtService)),U(6,o.IConfigService)],z);const G={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(F).openPanel(),!0)};var ge=Object.getOwnPropertyDescriptor,Se=(e,t,r,n)=>{for(var i=n>1?void 0:n?ge(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=c(i)||i);return i},ye=(e,t)=>(r,n)=>t(r,n,e);const X=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 i=n.findIndex(s=>s===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((s,c,v)=>{const a=v.length;return{value:s,priority:a-c}});return t.sort((s,c)=>{var u,h;const v=((u=i.find(m=>m.value===s))==null?void 0:u.priority)||-1;return(((h=i.find(m=>m.value===c))==null?void 0:h.priority)||-1)-v})}return n||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};L=Se([ye(0,o.Inject(o.ILocalStorageService))],L);const Q="numfmtCurrency",_e=e=>{const t=_.useDependency(L),[r,n]=y.useState(d.currencySymbols);return y.useEffect(()=>{t.addHabit("numfmtCurrency",[]).then(()=>{t.getHabit(Q,[...d.currencySymbols]).then(s=>{n(s),e&&e(s)})})},[]),{userHabitCurrency:r,mark:s=>{t.markHabit(Q,s)}}},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=>!!d.getCurrencyType(e)&&e.startsWith("_("),Ie=e=>{const{defaultPattern:t,action:r,onChange:n}=e,[i,s]=y.useState(()=>d.getDecimalFromPattern(t||"",2)),c=y.useContext(X),[v,a]=y.useState(()=>d.getCurrencyType(t)||c[0]),u=y.useMemo(()=>c.map(C=>({label:C,value:C})),[]),m=_.useDependency(o.LocaleService).t;r.current=()=>d.setPatternDecimal(`_("${v}"* #,##0${i>0?".0":""}_)`,i);const p=C=>{a(C),n(d.setPatternDecimal(`_("${C}"* #,##0${i>0?".0":""}_)`,i))},S=C=>{const f=C||0;s(f),n(d.setPatternDecimal(`_("${v}"* #,##0${f>0?".0":""}_)`,f))};return l.jsxs("div",{children:[l.jsxs("div",{className:"univer-mt-4 univer-flex univer-justify-between",children:[l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2 univer-w-32",children:l.jsx(T.InputNumber,{value:i,step:1,precision:0,max:20,min:0,onChange:S})})]}),l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.currencyType")}),l.jsx("div",{className:"univer-mt-2 univer-w-36",children:l.jsx(T.Select,{options:u,value:v,onChange:p})})]})]}),l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.accountingDes")})]})},xe=e=>!!d.getCurrencyType(e)&&!e.startsWith("_("),Te=e=>{const r=_.useDependency(o.LocaleService).t,n=y.useContext(X),[i,s]=y.useState(()=>d.getCurrencyType(e.defaultPattern)||n[0]),[c,v]=y.useState(()=>d.getDecimalFromPattern(e.defaultPattern||"",2)),[a,u]=y.useState(()=>{var b;const f=d.getCurrencyFormatOptions(i);return((b=f.find(N=>o.isPatternEqualWithoutDecimal(N.value,e.defaultPattern)))==null?void 0:b.value)||f[0].value}),h=y.useMemo(()=>d.getCurrencyFormatOptions(i),[i]),m=y.useMemo(()=>n.map(f=>({label:f,value:f})),[n]);e.action.current=()=>d.setPatternDecimal(a,c);const p=f=>{if(f===void 0)return;s(f);const x=d.getCurrencyFormatOptions(f)[0].value;u(x),e.onChange(d.setPatternDecimal(x,c))},S=f=>{f!==void 0&&(u(f),e.onChange(d.setPatternDecimal(f,c)))},C=f=>{v(f||0),e.onChange(d.setPatternDecimal(a,f||0))};return l.jsxs("div",{children:[l.jsxs("div",{className:"univer-mt-4 univer-flex univer-justify-between",children:[l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:r("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2 univer-w-32",children:l.jsx(T.InputNumber,{value:c,max:20,min:0,onChange:C})})]}),l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:r("sheet.numfmt.currencyType")}),l.jsx("div",{className:"univer-mt-2 univer-w-36",children:l.jsx(T.Select,{value:i,options:m,onChange:p})})]})]}),l.jsx("div",{className:"label univer-mt-4",children:r("sheet.numfmt.negType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(T.SelectList,{value:a,options:h,onChange:S})}),l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:r("sheet.numfmt.currencyDes")})]})};function re({ref:e,...t}){const{icon:r,id:n,className:i,extend:s,...c}=t,v=`univerjs-icon univerjs-icon-${n} ${i||""}`.trim(),a=y.useRef(`_${Pe()}`);return ie(r,`${n}`,{defIds:r.defIds,idSuffix:a.current},{ref:e,className:v,...c},s)}function ie(e,t,r,n,i){return y.createElement(e.tag,{key:t,...Ne(e,r,i),...n},(Ee(e,r).children||[]).map((s,c)=>ie(s,`${t}-${e.tag}-${c}`,r,void 0,i)))}function Ne(e,t,r){const n={...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(([s,c])=>{s==="mask"&&typeof c=="string"&&(n[s]=c.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});const{defIds:i}=t;return!i||i.length===0||(e.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(([s,c])=>{typeof c=="string"&&(n[s]=c.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),n}function Ee(e,t){var n;const{defIds:r}=t;return!r||r.length===0?e:e.tag==="defs"&&((n=e.children)!=null&&n.length)?{...e,children:e.children.map(i=>typeof i.attrs.id=="string"&&r&&r.includes(i.attrs.id)?{...i,attrs:{...i.attrs,id:i.attrs.id+t.idSuffix}}:i)}:e}function Pe(){return Math.random().toString(36).substring(2,8)}re.displayName="UniverIcon";const Me={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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"}}]},se=y.forwardRef(function(t,r){return y.createElement(re,Object.assign({},t,{id:"check-mark-icon",ref:r,icon:Me}))});se.displayName="CheckMarkIcon";const K="customFormat",Y="numfmt_custom_pattern";function je(e){const{defaultPattern:t,action:r,onChange:n}=e,i=_.useDependency(L),s=_.useDependency(o.ILocalStorageService),c=_.useDependency(o.LocaleService),[v,a]=y.useState(t);r.current=()=>(i.markHabit(K,v),s.getItem(Y).then((S=[])=>{const C=[...new Set([v,...S||[]])].splice(0,10).filter(f=>!!f);s.setItem(Y,C)}),v);const[u,h]=y.useState([]);y.useEffect(()=>{s.getItem(Y).then(S=>{const C=[...d.CURRENCYFORMAT.map(f=>f.suffix("$")),...d.DATEFMTLISG.map(f=>f.suffix),...d.NUMBERFORMAT.map(f=>f.suffix)];C.push(...S||[]),i.addHabit(K,[]).finally(()=>{i.getHabit(K,C).then(f=>{h([...new Set(f)])})})})},[]);const m=S=>{a(S),n(S)},p=()=>{n(v)};return l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:c.t("sheet.numfmt.customFormat")}),l.jsx(T.Input,{placeholder:c.t("sheet.numfmt.customFormat"),onBlur:p,value:v,onChange:a,className:"univer-mt-2 univer-w-full"}),l.jsx("div",{className:T.clsx("univer-mt-2 univer-max-h-[400px] univer-overflow-auto univer-rounded-lg univer-p-2",T.borderClassName),children:u.map(S=>l.jsxs("div",{onClick:()=>m(S),className:"univer-flex univer-cursor-pointer univer-items-center univer-gap-1.5 univer-py-1.5 univer-text-sm",children:[l.jsx("div",{className:"univer-flex univer-w-4 univer-items-center univer-text-primary-600",children:v===S&&l.jsx(se,{})}),l.jsx("div",{children:S})]},S))}),l.jsx("div",{className:"univer-mt-3 univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200",children:c.t("sheet.numfmt.customFormatDes")})]})}const Re=e=>{const t=o.numfmt.getFormatInfo(e);return d.getDateFormatOptions().map(r=>r.value).includes(e)||["date","datetime","time"].includes(t.type)};function De(e){const{onChange:t,defaultPattern:r}=e,n=y.useMemo(d.getDateFormatOptions,[]),i=_.useDependency(o.LocaleService),[s,c]=y.useState(()=>{if(r){const a=n.find(u=>u.value===r);if(a)return a.value}return n[0].value});e.action.current=()=>s;const v=a=>{a!==void 0&&(c(a),t(a))};return l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:i.t("sheet.numfmt.dateType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(T.SelectList,{value:s,options:n,onChange:v})}),l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:i.t("sheet.numfmt.dateDes")})]})}const we=e=>!e,Ue=e=>{const r=_.useDependency(o.LocaleService).t;return e.action.current=()=>"",l.jsx("div",{children:l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:r("sheet.numfmt.generalDes")})})},Oe=e=>d.getNumberFormatOptions().some(t=>o.isPatternEqualWithoutDecimal(t.value,e));function ke(e){const t=_.useDependency(o.LocaleService),r=y.useMemo(d.getNumberFormatOptions,[]),[n,i]=y.useState(()=>d.getDecimalFromPattern(e.defaultPattern||"",0)),[s,c]=y.useState(()=>{const m=r.find(p=>o.isPatternEqualWithoutDecimal(p.value,e.defaultPattern||""));return(m==null?void 0:m.value)||r[0].value}),v=y.useMemo(()=>d.setPatternDecimal(s,Number(n||0)),[s,n]),a=y.useMemo(()=>!d.isPatternHasDecimal(s),[s]),u=m=>{i(m||0),e.onChange(d.setPatternDecimal(s,Number(m||0)))},h=m=>{m!==void 0&&(i(d.getDecimalFromPattern(m,0)),c(m),e.onChange(m))};return e.action.current=()=>v,l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:t.t("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(T.InputNumber,{disabled:a,value:n,max:20,min:0,onChange:u})}),l.jsxs("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:[" ",t.t("sheet.numfmt.negType")]}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(T.SelectList,{onChange:h,options:r,value:s})}),l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:t.t("sheet.numfmt.thousandthPercentileDes")})]})}const $e=e=>{const{defaultValue:t,defaultPattern:r,row:n,col:i}=e.value,s=_.useDependency(o.LocaleService),c=y.useRef(()=>""),v=s.t,a=Ce(),u=y.useMemo(()=>[{label:"sheet.numfmt.general",component:Ue},{label:"sheet.numfmt.accounting",component:Ie},{label:"sheet.numfmt.currency",component:Te},{label:"sheet.numfmt.date",component:De},{label:"sheet.numfmt.thousandthPercentile",component:ke},{label:"sheet.numfmt.customFormat",component:je}].map(I=>({...I,label:v(I.label)})),[]),[h,m]=y.useState(b),[p,S]=y.useState(()=>`${n}_${i}`),{mark:C,userHabitCurrency:f}=_e(()=>S(`${n}_${i}_userCurrency'`)),x=y.useMemo(()=>{var I;return(I=u.find(w=>w.label===h))==null?void 0:I.component},[h]);function b(){return[we,be,xe,Re,Oe].reduce((w,ue,me)=>w||(ue(r)?u[me].label:""),"")||u[0].label}const N=u.map(I=>({label:I.label,value:I.label})),M=I=>{m(I),a(()=>e.onChange({type:"change",value:c.current()||""}))},R=y.useCallback(I=>{e.onChange({type:"change",value:I})},[]),D=()=>{const I=c.current()||"",w=d.getCurrencyType(I);w&&C(w),e.onChange({type:"confirm",value:I})},O=()=>{e.onChange({type:"cancel",value:""})},V={onChange:R,defaultValue:t,defaultPattern:r,action:c};return y.useEffect(()=>{m(b()),S(`${n}_${i}`)},[n,i]),l.jsxs("div",{className:T.clsx("univer-flex univer-h-full univer-flex-col univer-justify-between univer-overflow-y-auto univer-pb-5",T.scrollbarClassName),children:[l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-3.5 univer-text-sm univer-text-gray-400",children:v("sheet.numfmt.numfmtType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(T.Select,{className:"univer-w-full",value:h,options:N,onChange:M})}),l.jsx("div",{children:x&&l.jsx(X.Provider,{value:f,children:y.createElement(x,{...V,key:p})})})]}),l.jsxs("div",{className:"univer-mb-5 univer-mt-3.5 univer-flex univer-justify-end",children:[l.jsx(T.Button,{onClick:O,className:"univer-mr-3",children:v("sheet.numfmt.cancel")}),l.jsx(T.Button,{variant:"primary",onClick:D,children:v("sheet.numfmt.confirm")})]})]})};var Le=Object.getOwnPropertyDescriptor,Fe=(e,t,r,n)=>{for(var i=n>1?void 0:n?Le(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=c(i)||i);return i},P=(e,t)=>(r,n)=>t(r,n,e);const ee="SHEET_NUMFMT_PANEL";let F=class extends o.Disposable{constructor(t,r,n,i,s,c,v,a,u,h,m){super();A(this,"_previewPattern","");A(this,"_sidebarDisposable",null);this._sheetInterceptorService=t,this._themeService=r,this._univerInstanceService=n,this._commandService=i,this._selectionManagerService=s,this._renderManagerService=c,this._numfmtService=v,this._componentManager=a,this._sidebarService=u,this._localeService=h,this._sheetsNumfmtCellContentController=m,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener(),this._initNumfmtLocalChange()}_initNumfmtLocalChange(){this.disposeWithMe(j.merge(this._sheetsNumfmtCellContentController.locale$,this._localeService.currentLocale$).subscribe(()=>{this._forceUpdate()}))}openPanel(){var x;const t=this._sidebarService,r=this._selectionManagerService,n=this._commandService,i=this._univerInstanceService,s=this._numfmtService,c=this._localeService,a=(((x=r.getCurrentSelections())==null?void 0:x.map(b=>b.range))||[])[0];if(!a)return!1;const u=i.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),h=u.getActiveSheet();if(!h)return!1;const m=h.getCellRaw(a.startRow,a.startColumn),p=s.getValue(u.getUnitId(),h.getSheetId(),a.startRow,a.startColumn);let S="";p&&(S=p.pattern);const C=(m==null?void 0:m.t)===o.CellValueType.NUMBER?m.v:12345678,f={onChange:b=>{var N;if(b.type==="change")this._previewPattern=b.value,this._forceUpdate();else if(b.type==="confirm"){const M=((N=r.getCurrentSelections())==null?void 0:N.map(O=>O.range))||[],R={values:[]},D=d.getPatternType(b.value);M.forEach(O=>{o.Range.foreach(O,(V,I)=>{R.values.push({row:V,col:I,pattern:b.value,type:D})})}),n.executeCommand(d.SetNumfmtCommand.id,R),t.close()}else b.type==="cancel"&&t.close()},value:{defaultPattern:S,defaultValue:C,row:a.startRow,col:a.startColumn}};return this._sidebarDisposable=t.open({header:{title:c.t("sheet.numfmt.title")},children:{label:ee,...f},onClose:()=>{this._forceUpdate(),n.executeCommand(G.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(E.SheetSkeletonManagerService).reCalculate(),(n=r==null?void 0:r.mainComponent)==null||n.makeDirty()}_initCommands(){[$,G].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initPanel(){this.disposeWithMe(this._componentManager.register(ee,$e))}_initRealTimeRenderingInterceptor(){const t=new j.Observable(n=>{this._commandService.onCommandExecuted(i=>{i.id===$.id&&n.next(!0),i.id===G.id&&n.next(!1)})}),r=j.combineLatest([t,this._selectionManagerService.selectionMoveEnd$.pipe(H.map(n=>n?n.map(i=>i.range):[]))]);this.disposeWithMe(o.toDisposable(r.pipe(H.switchMap(([n,i])=>new j.Observable(s=>{const c=new o.DisposableCollection;return n&&i.length&&s.next({selectionRanges:i,disposableCollection:c}),()=>{c.dispose()}})),H.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:n,selectionRanges:i})=>{var c,v;const s=this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);this.openPanel(),n.add(this._sheetInterceptorService.intercept(g.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,effect:o.InterceptorEffectEnum.Value|o.InterceptorEffectEnum.Style,handler:(a,u,h)=>{var C;const{row:m,col:p}=u,S=h(a)||{};if(i.find(f=>f.startColumn<=p&&f.endColumn>=p&&f.startRow<=m&&f.endRow>=m)){const f=u.worksheet.getCellRaw(m,p),x=f==null?void 0:f.v,b=f==null?void 0:f.t;if(x==null||b!==o.CellValueType.NUMBER||this._previewPattern===null)return S;const N=d.getPatternPreviewIgnoreGeneral(this._previewPattern,x,this._sheetsNumfmtCellContentController.locale);if(N.color){const M=(C=this._themeService.getColorFromTheme(`${N.color}.500`))!=null?C:N.color;return{...S,v:N.result,t:o.CellValueType.STRING,s:{cl:{rgb:M}}}}return{...S,v:N.result,t:o.CellValueType.STRING}}return S}})),(v=(c=this._renderManagerService.getRenderById(s.getUnitId()))==null?void 0:c.mainComponent)==null||v.makeDirty()})))}_commandExecutedListener(){const t=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id];this.disposeWithMe(new j.Observable(r=>{const n=this._commandService.onCommandExecuted(i=>{if(t.includes(i.id)){const s=i.params;r.next(s.unitId)}});return()=>n.dispose()}).pipe(H.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)})}};F=Fe([P(0,o.Inject(g.SheetInterceptorService)),P(1,o.Inject(o.ThemeService)),P(2,o.IUniverInstanceService),P(3,o.ICommandService),P(4,o.Inject(g.SheetsSelectionsService)),P(5,ne.IRenderManagerService),P(6,g.INumfmtService),P(7,o.Inject(_.ComponentManager)),P(8,_.ISidebarService),P(9,o.Inject(o.LocaleService)),P(10,o.Inject(d.SheetsNumfmtCellContentController))],F);var Ae=Object.getOwnPropertyDescriptor,He=(e,t,r,n)=>{for(var i=n>1?void 0:n?Ae(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=c(i)||i);return i},k=(e,t)=>(r,n)=>t(r,n,e);const We=()=>{let e=[];return{add:(i,s,c,v,a)=>e.push({unitId:i,subUnitId:s,row:c,col:v,value:a}),getEffects:()=>e,clean:()=>{e=[]}}};let W=class extends o.Disposable{constructor(t,r,n,i,s){super();A(this,"_collectEffectMutation",We());this._sheetInterceptorService=t,this._numfmtService=r,this._univerInstanceService=n,this._injector=i,this._editorBridgeService=s,this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(o.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.BEFORE_CELL_EDIT,{handler:(t,r,n)=>{const i=r.row,s=r.col,c=this._numfmtService.getValue(r.unitId,r.subUnitId,i,s);if(c)switch(d.getPatternType(c.pattern)){case"scientific":case"currency":case"grouped":case"number":{const a=r.worksheet.getCellRaw(i,s);return(a==null?void 0:a.t)===o.CellValueType.NUMBER&&(a==null?void 0:a.v)!==void 0&&a.v!==null&&o.isRealNum(a.v)&&(a.v=ve.stripErrorMargin(Number(a.v))),n&&n(a)}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(g.AFTER_CELL_EDIT,{handler:(t,r,n)=>{var u,h,m;if(!(t!=null&&t.v)&&!(t!=null&&t.p))return n(t);this._collectEffectMutation.clean();const i=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col),s=r.worksheet.getCellRaw(r.row,r.col);if(o.isTextFormat(i==null?void 0:i.pattern)||t.t===o.CellValueType.FORCE_STRING)return n(t);const c=(u=t.p)==null?void 0:u.body,v=(m=(h=t==null?void 0:t.p)==null?void 0:h.body)!=null&&m.dataStream?t.p.body.dataStream.replace(/\r\n$/,""):String(t.v),a=o.getNumfmtParseValueFilter(v);if(c)if(Be(c)){const{dataStream:p}=c,S=p.replace(/\r\n$/,""),C=Number(S);if(Number.isNaN(C)&&!a)return n(t)}else return n(t);if(a){if(!a.z&&!(i!=null&&i.pattern)&&(s==null?void 0:s.t)!==o.CellValueType.STRING&&(s==null?void 0:s.t)!==o.CellValueType.FORCE_STRING&&o.willLoseNumericPrecision(v))return n({...t,p:void 0,v,t:o.CellValueType.FORCE_STRING});a.z&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:a.z});const p=Number(a.v);return n({...t,p:void 0,v:p,t:o.CellValueType.NUMBER})}return n(t)}})))}_initInterceptorCommands(){const t=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(r){var n;switch(r.id){case g.SetRangeValuesCommand.id:{const i=t._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),s=i.getUnitId(),c=(n=i.getActiveSheet())==null?void 0:n.getSheetId();if(!c)return{redos:[],undos:[]};const v=t._collectEffectMutation.getEffects();if(t._collectEffectMutation.clean(),!v.length)return{redos:[],undos:[]};const a=v.filter(p=>{var S;return!!((S=p.value)!=null&&S.pattern)}).map(p=>({row:p.row,col:p.col,pattern:p.value.pattern})),u=v.filter(p=>{var S;return!((S=p.value)!=null&&S.pattern)}).map(p=>({startRow:p.row,endColumn:p.col,startColumn:p.col,endRow:p.row})),h=[],m=[];if(a.length){const p={id:g.SetNumfmtMutation.id,params:g.transformCellsToRange(s,c,a)};h.push(p),m.push(...g.factorySetNumfmtUndoMutation(t._injector,p.params))}if(u.length){const p={id:g.RemoveNumfmtMutation.id,params:{unitId:s,subUnitId:c,ranges:u}};h.push(p),m.push(...g.factoryRemoveNumfmtUndoMutation(t._injector,p.params))}return{redos:h,undos:m.reverse()}}}return{redos:[],undos:[]}}}))}dispose(){super.dispose(),this._collectEffectMutation.clean()}};W=He([k(0,o.Inject(g.SheetInterceptorService)),k(1,o.Inject(g.INumfmtService)),k(2,o.Inject(o.IUniverInstanceService)),k(3,o.Inject(o.Injector)),k(4,o.Optional(E.IEditorBridgeService))],W);function Be(e){const{textRuns:t=[],paragraphs:r=[],customRanges:n,customBlocks:i=[]}=e,s=["va"];return!(t.some(c=>!!(c.ts&&Object.keys(c.ts).some(a=>s.includes(a))))||r.some(c=>c.bullet)||r.length>=2||n!=null&&n.length||i.length>0)}const oe=e=>[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:o.DEFAULT_TEXT_FORMAT_EXCEL},"|",{label:"sheet.numfmt.number",pattern:"0"},{label:"sheet.numfmt.percent",pattern:"0.00%"},{label:"sheet.numfmt.scientific",pattern:"0.00E+00"},"|",{label:"sheet.numfmt.accounting",pattern:`"${e}" #,##0.00_);[Red]("${e}"#,##0.00)`},{label:"sheet.numfmt.financialValue",pattern:"#,##0.00;[Red]#,##0.00"},{label:"sheet.numfmt.currency",pattern:`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`},{label:"sheet.numfmt.roundingCurrency",pattern:`"${e}"#,##0;[Red]"${e}"#,##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:""}],Ve=e=>({icon:new j.Observable(t=>{const r=e.get(o.LocaleService);return t.next(d.getCurrencySymbolIconByLocale(r.getCurrentLocale()).icon),r.localeChanged$.subscribe(()=>{t.next(d.getCurrencySymbolIconByLocale(r.getCurrentLocale()).icon)})}),id:d.SetCurrencyCommand.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),qe=e=>({icon:"AddDigitsIcon",id:d.AddDecimalCommand.id,title:"sheet.numfmt.addDecimal",tooltip:"sheet.numfmt.addDecimal",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Ge=e=>({icon:"ReduceDigitsIcon",id:d.SubtractDecimalCommand.id,title:"sheet.numfmt.subtractDecimal",tooltip:"sheet.numfmt.subtractDecimal",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Ke=e=>({icon:"PercentIcon",id:d.SetPercentCommand.id,title:"sheet.numfmt.percent",tooltip:"sheet.numfmt.percent",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Ye=e=>{const t=e.get(o.IUniverInstanceService),r=e.get(o.ICommandService),n=e.get(o.LocaleService),i=e.get(g.SheetsSelectionsService),s=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id],c=E.deriveStateFromActiveSheet$(t,"",({workbook:v,worksheet:a})=>new j.Observable(u=>j.merge(i.selectionMoveEnd$,o.fromCallback(r.onCommandExecuted.bind(r)).pipe(j.filter(([h])=>s.includes(h.id)))).subscribe(()=>{var m,p;const h=i.getCurrentSelections();if(h&&h[0]){const S=h[0].range,C=S.startRow,f=S.startColumn,x=(p=v.getStyles().get((m=a.getCell(C,f))==null?void 0:m.s))==null?void 0:p.n,b=x==null?void 0:x.pattern,N=d.getCurrencySymbolByLocale(n.getCurrentLocale());let M=n.t("sheet.numfmt.general");if(o.isDefaultFormat(b)){u.next(M);return}if(b){const R=oe(N).filter(D=>typeof D=="object"&&D.pattern).find(D=>o.isPatternEqualWithoutDecimal(b,D.pattern));R&&typeof R=="object"&&R.pattern?M=n.t(R.label):M=n.t("sheet.numfmt.moreFmt")}u.next(M)}})));return{label:ce,id:$.id,tooltip:"sheet.numfmt.title",type:_.MenuItemType.SELECTOR,slot:!0,selections:[{label:{name:ae,hoverable:!1,selectable:!1}}],value$:c,hidden$:_.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetSetCellStylePermission,g.WorksheetEditPermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}},ce="sheet.numfmt.moreNumfmtType",ae="sheet.numfmt.moreNumfmtType.options";function Ze(e){const{value:t}=e,r=_.useDependency(o.LocaleService),n=t!=null?t:r.t("sheet.numfmt.general");return l.jsx("span",{className:"univer-text-sm",children:n})}function ze(){const e=_.useDependency(o.ICommandService),t=_.useDependency(o.LocaleService),r=_.useDependency(_.ILayoutService),n=_.useDependency(d.SheetsNumfmtCellContentController),i=_.useDependency(g.SheetsSelectionsService),s=u=>{const h=i.getCurrentLastSelection();if(!h)return;const m=h.range,p=[];o.Range.foreach(m,(S,C)=>{u?p.push({row:S,col:C,pattern:u,type:d.getPatternType(u)}):p.push({row:S,col:C})}),e.executeCommand(d.SetNumfmtCommand.id,{values:p}),r.focus()},c=y.useMemo(()=>{const u=d.localeCurrencySymbolMap.get(t.getCurrentLocale());return oe(u)},[t]),v=u=>{if(u===0)s(null);else if(u===c.length-1)e.executeCommand($.id),r.focus();else{const h=c[u];h.pattern&&s(h.pattern)}},a=1220;return l.jsx("div",{className:"univer-grid univer-gap-1 univer-p-1.5",children:c.map((u,h)=>u==="|"?l.jsx(T.Separator,{},h):l.jsxs("div",{className:"univer-flex univer-h-7 univer-items-center univer-justify-between univer-gap-6 univer-rounded univer-px-2 univer-text-sm hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",onClick:()=>v(h),children:[l.jsx("span",{children:t.t(u.label)}),l.jsx("span",{className:"univer-text-xs univer-text-gray-500",children:u.pattern?d.getPatternPreview(u.pattern||"",a,n.locale).result.trim():""})]},h))})}const Xe={[_.RibbonStartGroup.LAYOUT]:{[$.id]:{order:9,menuItemFactory:Ye},[d.SetPercentCommand.id]:{order:9.1,menuItemFactory:Ke},[d.SetCurrencyCommand.id]:{order:9.2,menuItemFactory:Ve},[d.AddDecimalCommand.id]:{order:9.3,menuItemFactory:qe},[d.SubtractDecimalCommand.id]:{order:9.4,menuItemFactory:Ge}}};var Je=Object.getOwnPropertyDescriptor,Qe=(e,t,r,n)=>{for(var i=n>1?void 0:n?Je(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=c(i)||i);return i},te=(e,t)=>(r,n)=>t(r,n,e);let B=class extends o.Disposable{constructor(e,t){super(),this._componentManager=e,this._menuManagerService=t,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(Xe),[[ce,Ze],[ae,ze]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};B=Qe([te(0,o.Inject(_.ComponentManager)),te(1,_.IMenuManagerService)],B);var et=Object.defineProperty,tt=Object.getOwnPropertyDescriptor,nt=(e,t,r)=>t in e?et(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,rt=(e,t,r,n)=>{for(var i=n>1?void 0:n?tt(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=c(i)||i);return i},Z=(e,t)=>(r,n)=>t(r,n,e),le=(e,t,r)=>nt(e,typeof t!="symbol"?t+"":t,r);const it="SHEET_NUMFMT_UI_PLUGIN";exports.UniverSheetsNumfmtUIPlugin=class extends o.Plugin{constructor(t=J,r,n,i){super(),this._config=t,this._injector=r,this._configService=n,this._renderManagerService=i;const{menu:s,...c}=o.merge({},J,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig("sheets-numfmt-ui.config",c)}onStarting(){o.registerDependencies(this._injector,[[F],[W],[L],[B]])}onRendered(){this._registerRenderModules(),o.touchDependencies(this._injector,[[F],[W],[B]])}_registerRenderModules(){[[z]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,r))})}};le(exports.UniverSheetsNumfmtUIPlugin,"pluginName",it);le(exports.UniverSheetsNumfmtUIPlugin,"type",o.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtUIPlugin=rt([o.DependentOn(E.UniverSheetsUIPlugin,d.UniverSheetsNumfmtPlugin),Z(1,o.Inject(o.Injector)),Z(2,o.IConfigService),Z(3,ne.IRenderManagerService)],exports.UniverSheetsNumfmtUIPlugin);
1
+ "use strict";var de=Object.defineProperty;var he=(e,t,r)=>t in e?de(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var A=(e,t,r)=>he(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),ne=require("@univerjs/engine-render"),d=require("@univerjs/sheets-numfmt"),E=require("@univerjs/sheets-ui"),g=require("@univerjs/sheets"),_=require("@univerjs/ui"),j=require("rxjs"),H=require("rxjs/operators"),l=require("react/jsx-runtime"),y=require("react"),T=require("@univerjs/design"),ve=require("@univerjs/engine-formula"),J={};var fe=Object.getOwnPropertyDescriptor,pe=(e,t,r,n)=>{for(var i=n>1?void 0:n?fe(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=c(i)||i);return i},U=(e,t)=>(r,n)=>t(r,n,e);const q="SHEET_NUMFMT_ALERT";let z=class extends o.Disposable{constructor(e,t,r,n,i,s,c){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=r,this._localeService=n,this._zenZoneService=i,this._numfmtService=s,this._configService=c,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(j.debounceTime(100)).subscribe(e=>{var t,r;if(e){const n=e.location,i=this._context.unit,s=i.getActiveSheet();if(!s)return this._hideAlert();const c=n.unitId,v=n.subUnitId;let a;const u=s.getCell(n.row,n.col);if(u!=null&&u.s){const h=i.getStyles().get(u.s);h!=null&&h.n&&(a=h.n)}if(a||(a=this._numfmtService.getValue(c,v,n.row,n.col)),!a){this._hideAlert();return}if(o.isTextFormat(a.pattern)&&o.Tools.isDefine(u==null?void 0:u.v)&&o.isRealNum(u.v)){if((t=this._configService.getConfig(d.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY))!=null&&t.disableTextFormatAlert)return;const h=this._cellAlertManagerService.currentAlert.get(q),m=(r=h==null?void 0:h.alert)==null?void 0:r.location;if(m&&m.row===n.row&&m.col===n.col&&m.subUnitId===n.subUnitId&&m.unitId===n.unitId){this._hideAlert();return}this._cellAlertManagerService.showAlert({type:E.CellAlertType.ERROR,title:this._localeService.t("info.error"),message:this._localeService.t("info.forceStringInfo"),location:n,width:200,height:74,key:q});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(q)}};z=pe([U(1,o.Inject(E.HoverManagerService)),U(2,o.Inject(E.CellAlertManagerService)),U(3,o.Inject(o.LocaleService)),U(4,_.IZenZoneService),U(5,o.Inject(g.INumfmtService)),U(6,o.IConfigService)],z);const G={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(F).openPanel(),!0)};var ge=Object.getOwnPropertyDescriptor,Se=(e,t,r,n)=>{for(var i=n>1?void 0:n?ge(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=c(i)||i);return i},ye=(e,t)=>(r,n)=>t(r,n,e);const X=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 i=n.findIndex(s=>s===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((s,c,v)=>{const a=v.length;return{value:s,priority:a-c}});return t.sort((s,c)=>{var u,h;const v=((u=i.find(m=>m.value===s))==null?void 0:u.priority)||-1;return(((h=i.find(m=>m.value===c))==null?void 0:h.priority)||-1)-v})}return n||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};L=Se([ye(0,o.Inject(o.ILocalStorageService))],L);const Q="numfmtCurrency",_e=e=>{const t=_.useDependency(L),[r,n]=y.useState(d.currencySymbols);return y.useEffect(()=>{t.addHabit("numfmtCurrency",[]).then(()=>{t.getHabit(Q,[...d.currencySymbols]).then(s=>{n(s),e&&e(s)})})},[]),{userHabitCurrency:r,mark:s=>{t.markHabit(Q,s)}}},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=>!!d.getCurrencyType(e)&&e.startsWith("_("),Ie=e=>{const{defaultPattern:t,action:r,onChange:n}=e,[i,s]=y.useState(()=>d.getDecimalFromPattern(t||"",2)),c=y.useContext(X),[v,a]=y.useState(()=>d.getCurrencyType(t)||c[0]),u=y.useMemo(()=>c.map(C=>({label:C,value:C})),[]),m=_.useDependency(o.LocaleService).t;r.current=()=>d.setPatternDecimal(`_("${v}"* #,##0${i>0?".0":""}_)`,i);const p=C=>{a(C),n(d.setPatternDecimal(`_("${C}"* #,##0${i>0?".0":""}_)`,i))},S=C=>{const f=C||0;s(f),n(d.setPatternDecimal(`_("${v}"* #,##0${f>0?".0":""}_)`,f))};return l.jsxs("div",{children:[l.jsxs("div",{className:"univer-mt-4 univer-flex univer-justify-between",children:[l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2 univer-w-32",children:l.jsx(T.InputNumber,{value:i,step:1,precision:0,max:20,min:0,onChange:S})})]}),l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.currencyType")}),l.jsx("div",{className:"univer-mt-2 univer-w-36",children:l.jsx(T.Select,{options:u,value:v,onChange:p})})]})]}),l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.accountingDes")})]})},xe=e=>!!d.getCurrencyType(e)&&!e.startsWith("_("),Te=e=>{const r=_.useDependency(o.LocaleService).t,n=y.useContext(X),[i,s]=y.useState(()=>d.getCurrencyType(e.defaultPattern)||n[0]),[c,v]=y.useState(()=>d.getDecimalFromPattern(e.defaultPattern||"",2)),[a,u]=y.useState(()=>{var b;const f=d.getCurrencyFormatOptions(i);return((b=f.find(N=>o.isPatternEqualWithoutDecimal(N.value,e.defaultPattern)))==null?void 0:b.value)||f[0].value}),h=y.useMemo(()=>d.getCurrencyFormatOptions(i),[i]),m=y.useMemo(()=>n.map(f=>({label:f,value:f})),[n]);e.action.current=()=>d.setPatternDecimal(a,c);const p=f=>{if(f===void 0)return;s(f);const x=d.getCurrencyFormatOptions(f)[0].value;u(x),e.onChange(d.setPatternDecimal(x,c))},S=f=>{f!==void 0&&(u(f),e.onChange(d.setPatternDecimal(f,c)))},C=f=>{v(f||0),e.onChange(d.setPatternDecimal(a,f||0))};return l.jsxs("div",{children:[l.jsxs("div",{className:"univer-mt-4 univer-flex univer-justify-between",children:[l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:r("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2 univer-w-32",children:l.jsx(T.InputNumber,{value:c,max:20,min:0,onChange:C})})]}),l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:r("sheet.numfmt.currencyType")}),l.jsx("div",{className:"univer-mt-2 univer-w-36",children:l.jsx(T.Select,{value:i,options:m,onChange:p})})]})]}),l.jsx("div",{className:"label univer-mt-4",children:r("sheet.numfmt.negType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(T.SelectList,{value:a,options:h,onChange:S})}),l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:r("sheet.numfmt.currencyDes")})]})};function re({ref:e,...t}){const{icon:r,id:n,className:i,extend:s,...c}=t,v=`univerjs-icon univerjs-icon-${n} ${i||""}`.trim(),a=y.useRef(`_${Pe()}`);return ie(r,`${n}`,{defIds:r.defIds,idSuffix:a.current},{ref:e,className:v,...c},s)}function ie(e,t,r,n,i){return y.createElement(e.tag,{key:t,...Ne(e,r,i),...n},(Ee(e,r).children||[]).map((s,c)=>ie(s,`${t}-${e.tag}-${c}`,r,void 0,i)))}function Ne(e,t,r){const n={...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(([s,c])=>{s==="mask"&&typeof c=="string"&&(n[s]=c.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});const{defIds:i}=t;return!i||i.length===0||(e.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(([s,c])=>{typeof c=="string"&&(n[s]=c.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),n}function Ee(e,t){var n;const{defIds:r}=t;return!r||r.length===0?e:e.tag==="defs"&&((n=e.children)!=null&&n.length)?{...e,children:e.children.map(i=>typeof i.attrs.id=="string"&&r&&r.includes(i.attrs.id)?{...i,attrs:{...i.attrs,id:i.attrs.id+t.idSuffix}}:i)}:e}function Pe(){return Math.random().toString(36).substring(2,8)}re.displayName="UniverIcon";const Me={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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"}}]},se=y.forwardRef(function(t,r){return y.createElement(re,Object.assign({},t,{id:"check-mark-icon",ref:r,icon:Me}))});se.displayName="CheckMarkIcon";const K="customFormat",Y="numfmt_custom_pattern";function je(e){const{defaultPattern:t,action:r,onChange:n}=e,i=_.useDependency(L),s=_.useDependency(o.ILocalStorageService),c=_.useDependency(o.LocaleService),[v,a]=y.useState(t);r.current=()=>(i.markHabit(K,v),s.getItem(Y).then((S=[])=>{const C=[...new Set([v,...S||[]])].splice(0,10).filter(f=>!!f);s.setItem(Y,C)}),v);const[u,h]=y.useState([]);y.useEffect(()=>{s.getItem(Y).then(S=>{const C=[...d.CURRENCYFORMAT.map(f=>f.suffix("$")),...d.DATEFMTLISG.map(f=>f.suffix),...d.NUMBERFORMAT.map(f=>f.suffix)];C.push(...S||[]),i.addHabit(K,[]).finally(()=>{i.getHabit(K,C).then(f=>{h([...new Set(f)])})})})},[]);const m=S=>{a(S),n(S)},p=()=>{n(v)};return l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:c.t("sheet.numfmt.customFormat")}),l.jsx(T.Input,{placeholder:c.t("sheet.numfmt.customFormat"),onBlur:p,value:v,onChange:a,className:"univer-mt-2 univer-w-full"}),l.jsx("div",{className:T.clsx("univer-mt-2 univer-max-h-[400px] univer-overflow-auto univer-rounded-lg univer-p-2",T.borderClassName),children:u.map(S=>l.jsxs("div",{onClick:()=>m(S),className:"univer-flex univer-cursor-pointer univer-items-center univer-gap-1.5 univer-py-1.5 univer-text-sm",children:[l.jsx("div",{className:"univer-flex univer-w-4 univer-items-center univer-text-primary-600",children:v===S&&l.jsx(se,{})}),l.jsx("div",{children:S})]},S))}),l.jsx("div",{className:"univer-mt-3 univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200",children:c.t("sheet.numfmt.customFormatDes")})]})}const Re=e=>{const t=o.numfmt.getFormatInfo(e);return d.getDateFormatOptions().map(r=>r.value).includes(e)||["date","datetime","time"].includes(t.type)};function De(e){const{onChange:t,defaultPattern:r}=e,n=y.useMemo(d.getDateFormatOptions,[]),i=_.useDependency(o.LocaleService),[s,c]=y.useState(()=>{if(r){const a=n.find(u=>u.value===r);if(a)return a.value}return n[0].value});e.action.current=()=>s;const v=a=>{a!==void 0&&(c(a),t(a))};return l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:i.t("sheet.numfmt.dateType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(T.SelectList,{value:s,options:n,onChange:v})}),l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:i.t("sheet.numfmt.dateDes")})]})}const we=e=>!e,Ue=e=>{const r=_.useDependency(o.LocaleService).t;return e.action.current=()=>"",l.jsx("div",{children:l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:r("sheet.numfmt.generalDes")})})},Oe=e=>d.getNumberFormatOptions().some(t=>o.isPatternEqualWithoutDecimal(t.value,e));function ke(e){const t=_.useDependency(o.LocaleService),r=y.useMemo(d.getNumberFormatOptions,[]),[n,i]=y.useState(()=>d.getDecimalFromPattern(e.defaultPattern||"",0)),[s,c]=y.useState(()=>{const m=r.find(p=>o.isPatternEqualWithoutDecimal(p.value,e.defaultPattern||""));return(m==null?void 0:m.value)||r[0].value}),v=y.useMemo(()=>d.setPatternDecimal(s,Number(n||0)),[s,n]),a=y.useMemo(()=>!d.isPatternHasDecimal(s),[s]),u=m=>{i(m||0),e.onChange(d.setPatternDecimal(s,Number(m||0)))},h=m=>{m!==void 0&&(i(d.getDecimalFromPattern(m,0)),c(m),e.onChange(m))};return e.action.current=()=>v,l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:t.t("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(T.InputNumber,{disabled:a,value:n,max:20,min:0,onChange:u})}),l.jsxs("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:[" ",t.t("sheet.numfmt.negType")]}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(T.SelectList,{onChange:h,options:r,value:s})}),l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:t.t("sheet.numfmt.thousandthPercentileDes")})]})}const $e=e=>{const{defaultValue:t,defaultPattern:r,row:n,col:i}=e.value,s=_.useDependency(o.LocaleService),c=y.useRef(()=>""),v=s.t,a=Ce(),u=y.useMemo(()=>[{label:"sheet.numfmt.general",component:Ue},{label:"sheet.numfmt.accounting",component:Ie},{label:"sheet.numfmt.currency",component:Te},{label:"sheet.numfmt.date",component:De},{label:"sheet.numfmt.thousandthPercentile",component:ke},{label:"sheet.numfmt.customFormat",component:je}].map(I=>({...I,label:v(I.label)})),[]),[h,m]=y.useState(b),[p,S]=y.useState(()=>`${n}_${i}`),{mark:C,userHabitCurrency:f}=_e(()=>S(`${n}_${i}_userCurrency'`)),x=y.useMemo(()=>{var I;return(I=u.find(w=>w.label===h))==null?void 0:I.component},[h]);function b(){return[we,be,xe,Re,Oe].reduce((w,ue,me)=>w||(ue(r)?u[me].label:""),"")||u[0].label}const N=u.map(I=>({label:I.label,value:I.label})),M=I=>{m(I),a(()=>e.onChange({type:"change",value:c.current()||""}))},R=y.useCallback(I=>{e.onChange({type:"change",value:I})},[]),D=()=>{const I=c.current()||"",w=d.getCurrencyType(I);w&&C(w),e.onChange({type:"confirm",value:I})},O=()=>{e.onChange({type:"cancel",value:""})},V={onChange:R,defaultValue:t,defaultPattern:r,action:c};return y.useEffect(()=>{m(b()),S(`${n}_${i}`)},[n,i]),l.jsxs("div",{className:T.clsx("univer-flex univer-h-full univer-flex-col univer-justify-between univer-overflow-y-auto univer-pb-5",T.scrollbarClassName),children:[l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-3.5 univer-text-sm univer-text-gray-400",children:v("sheet.numfmt.numfmtType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(T.Select,{className:"univer-w-full",value:h,options:N,onChange:M})}),l.jsx("div",{children:x&&l.jsx(X.Provider,{value:f,children:y.createElement(x,{...V,key:p})})})]}),l.jsxs("div",{className:"univer-mb-5 univer-mt-3.5 univer-flex univer-justify-end",children:[l.jsx(T.Button,{onClick:O,className:"univer-mr-3",children:v("sheet.numfmt.cancel")}),l.jsx(T.Button,{variant:"primary",onClick:D,children:v("sheet.numfmt.confirm")})]})]})};var Le=Object.getOwnPropertyDescriptor,Fe=(e,t,r,n)=>{for(var i=n>1?void 0:n?Le(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=c(i)||i);return i},P=(e,t)=>(r,n)=>t(r,n,e);const ee="SHEET_NUMFMT_PANEL";let F=class extends o.Disposable{constructor(t,r,n,i,s,c,v,a,u,h,m){super();A(this,"_previewPattern","");A(this,"_sidebarDisposable",null);this._sheetInterceptorService=t,this._themeService=r,this._univerInstanceService=n,this._commandService=i,this._selectionManagerService=s,this._renderManagerService=c,this._numfmtService=v,this._componentManager=a,this._sidebarService=u,this._localeService=h,this._sheetsNumfmtCellContentController=m,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener(),this._initNumfmtLocalChange()}_initNumfmtLocalChange(){this.disposeWithMe(j.merge(this._sheetsNumfmtCellContentController.locale$,this._localeService.currentLocale$).subscribe(()=>{this._forceUpdate()}))}openPanel(){var x;const t=this._sidebarService,r=this._selectionManagerService,n=this._commandService,i=this._univerInstanceService,s=this._numfmtService,c=this._localeService,a=(((x=r.getCurrentSelections())==null?void 0:x.map(b=>b.range))||[])[0];if(!a)return!1;const u=i.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),h=u.getActiveSheet();if(!h)return!1;const m=h.getCellRaw(a.startRow,a.startColumn),p=s.getValue(u.getUnitId(),h.getSheetId(),a.startRow,a.startColumn);let S="";p&&(S=p.pattern);const C=(m==null?void 0:m.t)===o.CellValueType.NUMBER?m.v:12345678,f={onChange:b=>{var N;if(b.type==="change")this._previewPattern=b.value,this._forceUpdate();else if(b.type==="confirm"){const M=((N=r.getCurrentSelections())==null?void 0:N.map(O=>O.range))||[],R={values:[]},D=d.getPatternType(b.value);M.forEach(O=>{o.Range.foreach(O,(V,I)=>{R.values.push({row:V,col:I,pattern:b.value,type:D})})}),n.executeCommand(d.SetNumfmtCommand.id,R),t.close()}else b.type==="cancel"&&t.close()},value:{defaultPattern:S,defaultValue:C,row:a.startRow,col:a.startColumn}};return this._sidebarDisposable=t.open({header:{title:c.t("sheet.numfmt.title")},children:{label:ee,...f},onClose:()=>{this._forceUpdate(),n.executeCommand(G.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(E.SheetSkeletonManagerService).reCalculate(),(n=r==null?void 0:r.mainComponent)==null||n.makeDirty()}_initCommands(){[$,G].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initPanel(){this.disposeWithMe(this._componentManager.register(ee,$e))}_initRealTimeRenderingInterceptor(){const t=new j.Observable(n=>{this._commandService.onCommandExecuted(i=>{i.id===$.id&&n.next(!0),i.id===G.id&&n.next(!1)})}),r=j.combineLatest([t,this._selectionManagerService.selectionMoveEnd$.pipe(H.map(n=>n?n.map(i=>i.range):[]))]);this.disposeWithMe(o.toDisposable(r.pipe(H.switchMap(([n,i])=>new j.Observable(s=>{const c=new o.DisposableCollection;return n&&i.length&&s.next({selectionRanges:i,disposableCollection:c}),()=>{c.dispose()}})),H.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:n,selectionRanges:i})=>{var c,v;const s=this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);this.openPanel(),n.add(this._sheetInterceptorService.intercept(g.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,effect:o.InterceptorEffectEnum.Value|o.InterceptorEffectEnum.Style,handler:(a,u,h)=>{var C;const{row:m,col:p}=u,S=h(a)||{};if(i.find(f=>f.startColumn<=p&&f.endColumn>=p&&f.startRow<=m&&f.endRow>=m)){const f=u.worksheet.getCellRaw(m,p),x=f==null?void 0:f.v,b=f==null?void 0:f.t;if(x==null||b!==o.CellValueType.NUMBER||this._previewPattern===null)return S;const N=d.getPatternPreviewIgnoreGeneral(this._previewPattern,x,this._sheetsNumfmtCellContentController.locale);if(N.color){const M=(C=this._themeService.getColorFromTheme(`${N.color}.500`))!=null?C:N.color;return{...S,v:N.result,t:o.CellValueType.STRING,s:{cl:{rgb:M}}}}return{...S,v:N.result,t:o.CellValueType.STRING}}return S}})),(v=(c=this._renderManagerService.getRenderById(s.getUnitId()))==null?void 0:c.mainComponent)==null||v.makeDirty()})))}_commandExecutedListener(){const t=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id];this.disposeWithMe(new j.Observable(r=>{const n=this._commandService.onCommandExecuted(i=>{if(t.includes(i.id)){const s=i.params;r.next(s.unitId)}});return()=>n.dispose()}).pipe(H.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)})}};F=Fe([P(0,o.Inject(g.SheetInterceptorService)),P(1,o.Inject(o.ThemeService)),P(2,o.IUniverInstanceService),P(3,o.ICommandService),P(4,o.Inject(g.SheetsSelectionsService)),P(5,ne.IRenderManagerService),P(6,g.INumfmtService),P(7,o.Inject(_.ComponentManager)),P(8,_.ISidebarService),P(9,o.Inject(o.LocaleService)),P(10,o.Inject(d.SheetsNumfmtCellContentController))],F);var Ae=Object.getOwnPropertyDescriptor,He=(e,t,r,n)=>{for(var i=n>1?void 0:n?Ae(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=c(i)||i);return i},k=(e,t)=>(r,n)=>t(r,n,e);const We=()=>{let e=[];return{add:(i,s,c,v,a)=>e.push({unitId:i,subUnitId:s,row:c,col:v,value:a}),getEffects:()=>e,clean:()=>{e=[]}}};let W=class extends o.Disposable{constructor(t,r,n,i,s){super();A(this,"_collectEffectMutation",We());this._sheetInterceptorService=t,this._numfmtService=r,this._univerInstanceService=n,this._injector=i,this._editorBridgeService=s,this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(o.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.BEFORE_CELL_EDIT,{handler:(t,r,n)=>{const i=r.row,s=r.col,c=this._numfmtService.getValue(r.unitId,r.subUnitId,i,s);if(c)switch(d.getPatternType(c.pattern)){case"scientific":case"currency":case"grouped":case"number":{const a=r.worksheet.getCellRaw(i,s);return(a==null?void 0:a.t)===o.CellValueType.NUMBER&&(a==null?void 0:a.v)!==void 0&&a.v!==null&&o.isRealNum(a.v)&&(a.v=ve.stripErrorMargin(Number(a.v))),n&&n(a)}default:return n&&n(t)}return n(t)}})))}_initInterceptorEditorEnd(){this.disposeWithMe(o.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.AFTER_CELL_EDIT,{handler:(t,r,n)=>{var u,h,m;if(!(t!=null&&t.v)&&!(t!=null&&t.p))return n(t);this._collectEffectMutation.clean();const i=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col),s=r.worksheet.getCellRaw(r.row,r.col);if(o.isTextFormat(i==null?void 0:i.pattern)||t.t===o.CellValueType.FORCE_STRING)return n(t);const c=(u=t.p)==null?void 0:u.body,v=(m=(h=t==null?void 0:t.p)==null?void 0:h.body)!=null&&m.dataStream?t.p.body.dataStream.replace(/\r\n$/,""):String(t.v),a=o.getNumfmtParseValueFilter(v);if(c)if(Be(c)){const{dataStream:p}=c,S=p.replace(/\r\n$/,""),C=Number(S);if(Number.isNaN(C)&&!a)return n(t)}else return n(t);if(a){if(!a.z&&!(i!=null&&i.pattern)&&(s==null?void 0:s.t)!==o.CellValueType.STRING&&(s==null?void 0:s.t)!==o.CellValueType.FORCE_STRING&&o.willLoseNumericPrecision(v))return n({...t,p:void 0,v,t:o.CellValueType.FORCE_STRING});a.z&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:a.z});const p=Number(a.v);return n({...t,p:void 0,v:p,t:o.CellValueType.NUMBER})}return n(t)}})))}_initInterceptorCommands(){const t=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(r){var n;switch(r.id){case g.SetRangeValuesCommand.id:{const i=t._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),s=i.getUnitId(),c=(n=i.getActiveSheet())==null?void 0:n.getSheetId();if(!c)return{redos:[],undos:[]};const v=t._collectEffectMutation.getEffects();if(t._collectEffectMutation.clean(),!v.length)return{redos:[],undos:[]};const a=v.filter(p=>{var S;return!!((S=p.value)!=null&&S.pattern)}).map(p=>({row:p.row,col:p.col,pattern:p.value.pattern})),u=v.filter(p=>{var S;return!((S=p.value)!=null&&S.pattern)}).map(p=>({startRow:p.row,endColumn:p.col,startColumn:p.col,endRow:p.row})),h=[],m=[];if(a.length){const p={id:g.SetNumfmtMutation.id,params:g.transformCellsToRange(s,c,a)};h.push(p),m.push(...g.factorySetNumfmtUndoMutation(t._injector,p.params))}if(u.length){const p={id:g.RemoveNumfmtMutation.id,params:{unitId:s,subUnitId:c,ranges:u}};h.push(p),m.push(...g.factoryRemoveNumfmtUndoMutation(t._injector,p.params))}return{redos:h,undos:m.reverse()}}}return{redos:[],undos:[]}}}))}dispose(){super.dispose(),this._collectEffectMutation.clean()}};W=He([k(0,o.Inject(g.SheetInterceptorService)),k(1,o.Inject(g.INumfmtService)),k(2,o.Inject(o.IUniverInstanceService)),k(3,o.Inject(o.Injector)),k(4,o.Optional(E.IEditorBridgeService))],W);function Be(e){const{textRuns:t=[],paragraphs:r=[],customRanges:n,customBlocks:i=[]}=e,s=["va"];return!(t.some(c=>!!(c.ts&&Object.keys(c.ts).some(a=>s.includes(a))))||r.some(c=>c.bullet)||r.length>=2||n!=null&&n.length||i.length>0)}const oe=e=>[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:o.DEFAULT_TEXT_FORMAT_EXCEL},"|",{label:"sheet.numfmt.number",pattern:"0"},{label:"sheet.numfmt.percent",pattern:"0.00%"},{label:"sheet.numfmt.scientific",pattern:"0.00E+00"},"|",{label:"sheet.numfmt.accounting",pattern:`"${e}" #,##0.00_);[Red]("${e}"#,##0.00)`},{label:"sheet.numfmt.financialValue",pattern:"#,##0.00;[Red]#,##0.00"},{label:"sheet.numfmt.currency",pattern:`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`},{label:"sheet.numfmt.roundingCurrency",pattern:`"${e}"#,##0;[Red]"${e}"#,##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:""}],Ve=e=>({icon:new j.Observable(t=>{const r=e.get(o.LocaleService);return t.next(d.getCurrencySymbolIconByLocale(r.getCurrentLocale()).icon),r.localeChanged$.subscribe(()=>{t.next(d.getCurrencySymbolIconByLocale(r.getCurrentLocale()).icon)})}),id:d.SetCurrencyCommand.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),qe=e=>({icon:"AddDigitsIcon",id:d.AddDecimalCommand.id,title:"sheet.numfmt.addDecimal",tooltip:"sheet.numfmt.addDecimal",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Ge=e=>({icon:"ReduceDigitsIcon",id:d.SubtractDecimalCommand.id,title:"sheet.numfmt.subtractDecimal",tooltip:"sheet.numfmt.subtractDecimal",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Ke=e=>({icon:"PercentIcon",id:d.SetPercentCommand.id,title:"sheet.numfmt.percent",tooltip:"sheet.numfmt.percent",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Ye=e=>{const t=e.get(o.IUniverInstanceService),r=e.get(o.ICommandService),n=e.get(o.LocaleService),i=e.get(g.SheetsSelectionsService),s=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id],c=E.deriveStateFromActiveSheet$(t,"",({workbook:v,worksheet:a})=>new j.Observable(u=>j.merge(i.selectionMoveEnd$,o.fromCallback(r.onCommandExecuted.bind(r)).pipe(j.filter(([h])=>s.includes(h.id)))).subscribe(()=>{var m,p;const h=i.getCurrentSelections();if(h&&h[0]){const S=h[0].range,C=S.startRow,f=S.startColumn,x=(p=v.getStyles().get((m=a.getCell(C,f))==null?void 0:m.s))==null?void 0:p.n,b=x==null?void 0:x.pattern,N=d.getCurrencySymbolByLocale(n.getCurrentLocale());let M=n.t("sheet.numfmt.general");if(o.isDefaultFormat(b)){u.next(M);return}if(b){const R=oe(N).filter(D=>typeof D=="object"&&D.pattern).find(D=>o.isPatternEqualWithoutDecimal(b,D.pattern));R&&typeof R=="object"&&R.pattern?M=n.t(R.label):M=n.t("sheet.numfmt.moreFmt")}u.next(M)}})));return{label:ce,id:$.id,tooltip:"sheet.numfmt.title",type:_.MenuItemType.SELECTOR,slot:!0,selections:[{label:{name:ae,hoverable:!1,selectable:!1}}],value$:c,hidden$:_.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetSetCellStylePermission,g.WorksheetEditPermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}},ce="sheet.numfmt.moreNumfmtType",ae="sheet.numfmt.moreNumfmtType.options";function Ze(e){const{value:t}=e,r=_.useDependency(o.LocaleService),n=t!=null?t:r.t("sheet.numfmt.general");return l.jsx("span",{className:"univer-text-sm",children:n})}function ze(){const e=_.useDependency(o.ICommandService),t=_.useDependency(o.LocaleService),r=_.useDependency(_.ILayoutService),n=_.useDependency(d.SheetsNumfmtCellContentController),i=_.useDependency(g.SheetsSelectionsService),s=u=>{const h=i.getCurrentLastSelection();if(!h)return;const m=h.range,p=[];o.Range.foreach(m,(S,C)=>{u?p.push({row:S,col:C,pattern:u,type:d.getPatternType(u)}):p.push({row:S,col:C})}),e.executeCommand(d.SetNumfmtCommand.id,{values:p}),r.focus()},c=y.useMemo(()=>{const u=d.localeCurrencySymbolMap.get(t.getCurrentLocale());return oe(u)},[t]),v=u=>{if(u===0)s(null);else if(u===c.length-1)e.executeCommand($.id),r.focus();else{const h=c[u];h.pattern&&s(h.pattern)}},a=1220;return l.jsx("div",{className:"univer-grid univer-gap-1 univer-p-1.5",children:c.map((u,h)=>u==="|"?l.jsx(T.Separator,{},h):l.jsxs("div",{className:"univer-flex univer-h-7 univer-items-center univer-justify-between univer-gap-6 univer-rounded univer-px-2 univer-text-sm hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",onClick:()=>v(h),children:[l.jsx("span",{children:t.t(u.label)}),l.jsx("span",{className:"univer-text-xs univer-text-gray-500 dark:!univer-text-gray-400",children:u.pattern?d.getPatternPreview(u.pattern||"",a,n.locale).result.trim():""})]},h))})}const Xe={[_.RibbonStartGroup.LAYOUT]:{[$.id]:{order:9,menuItemFactory:Ye},[d.SetPercentCommand.id]:{order:9.1,menuItemFactory:Ke},[d.SetCurrencyCommand.id]:{order:9.2,menuItemFactory:Ve},[d.AddDecimalCommand.id]:{order:9.3,menuItemFactory:qe},[d.SubtractDecimalCommand.id]:{order:9.4,menuItemFactory:Ge}}};var Je=Object.getOwnPropertyDescriptor,Qe=(e,t,r,n)=>{for(var i=n>1?void 0:n?Je(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=c(i)||i);return i},te=(e,t)=>(r,n)=>t(r,n,e);let B=class extends o.Disposable{constructor(e,t){super(),this._componentManager=e,this._menuManagerService=t,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(Xe),[[ce,Ze],[ae,ze]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};B=Qe([te(0,o.Inject(_.ComponentManager)),te(1,_.IMenuManagerService)],B);var et=Object.defineProperty,tt=Object.getOwnPropertyDescriptor,nt=(e,t,r)=>t in e?et(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,rt=(e,t,r,n)=>{for(var i=n>1?void 0:n?tt(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=c(i)||i);return i},Z=(e,t)=>(r,n)=>t(r,n,e),le=(e,t,r)=>nt(e,typeof t!="symbol"?t+"":t,r);const it="SHEET_NUMFMT_UI_PLUGIN";exports.UniverSheetsNumfmtUIPlugin=class extends o.Plugin{constructor(t=J,r,n,i){super(),this._config=t,this._injector=r,this._configService=n,this._renderManagerService=i;const{menu:s,...c}=o.merge({},J,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig("sheets-numfmt-ui.config",c)}onStarting(){o.registerDependencies(this._injector,[[F],[W],[L],[B]])}onRendered(){this._registerRenderModules(),o.touchDependencies(this._injector,[[F],[W],[B]])}_registerRenderModules(){[[z]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,r))})}};le(exports.UniverSheetsNumfmtUIPlugin,"pluginName",it);le(exports.UniverSheetsNumfmtUIPlugin,"type",o.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtUIPlugin=rt([o.DependentOn(E.UniverSheetsUIPlugin,d.UniverSheetsNumfmtPlugin),Z(1,o.Inject(o.Injector)),Z(2,o.IConfigService),Z(3,ne.IRenderManagerService)],exports.UniverSheetsNumfmtUIPlugin);
package/lib/es/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  var ut = Object.defineProperty;
2
2
  var mt = (e, t, r) => t in e ? ut(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
3
  var X = (e, t, r) => mt(e, typeof t != "symbol" ? t + "" : t, r);
4
- import { Inject as C, LocaleService as E, IConfigService as Ue, Disposable as te, isTextFormat as ke, Tools as dt, isRealNum as De, CommandType as Fe, ILocalStorageService as Le, isPatternEqualWithoutDecimal as ne, numfmt as ht, ThemeService as vt, IUniverInstanceService as he, ICommandService as ve, UniverInstanceType as T, CellValueType as P, toDisposable as me, DisposableCollection as ft, InterceptorEffectEnum as Te, Range as Ae, Injector as He, Optional as pt, getNumfmtParseValueFilter as gt, willLoseNumericPrecision as _t, fromCallback as St, isDefaultFormat as Ct, DEFAULT_TEXT_FORMAT_EXCEL as yt, DependentOn as bt, Plugin as It, merge as Nt, registerDependencies as Et, touchDependencies as Tt } from "@univerjs/core";
4
+ import { Inject as C, LocaleService as E, IConfigService as ke, Disposable as te, isTextFormat as Ue, Tools as dt, isRealNum as De, CommandType as Fe, ILocalStorageService as Le, isPatternEqualWithoutDecimal as ne, numfmt as ht, ThemeService as vt, IUniverInstanceService as he, ICommandService as ve, UniverInstanceType as T, CellValueType as P, toDisposable as me, DisposableCollection as ft, InterceptorEffectEnum as Te, Range as Ae, Injector as He, Optional as pt, getNumfmtParseValueFilter as gt, willLoseNumericPrecision as _t, fromCallback as St, isDefaultFormat as Ct, DEFAULT_TEXT_FORMAT_EXCEL as yt, DependentOn as bt, Plugin as It, merge as Nt, registerDependencies as Et, touchDependencies as Tt } from "@univerjs/core";
5
5
  import { IRenderManagerService as je } from "@univerjs/engine-render";
6
- import { SHEETS_NUMFMT_PLUGIN_CONFIG_KEY as Mt, currencySymbols as Me, getDecimalFromPattern as q, getCurrencyType as B, setPatternDecimal as $, getCurrencyFormatOptions as se, CURRENCYFORMAT as wt, DATEFMTLISG as Pt, NUMBERFORMAT as xt, getDateFormatOptions as Be, getNumberFormatOptions as Ve, isPatternHasDecimal as Rt, SheetsNumfmtCellContentController as We, getPatternPreviewIgnoreGeneral as $t, getPatternType as fe, SetNumfmtCommand as Ge, SubtractDecimalCommand as Ke, AddDecimalCommand as Ye, SetCurrencyCommand as Ze, getCurrencySymbolIconByLocale as we, SetPercentCommand as ze, getCurrencySymbolByLocale as Ot, localeCurrencySymbolMap as Ut, getPatternPreview as kt, UniverSheetsNumfmtPlugin as Dt } from "@univerjs/sheets-numfmt";
6
+ import { SHEETS_NUMFMT_PLUGIN_CONFIG_KEY as Mt, currencySymbols as Me, getDecimalFromPattern as q, getCurrencyType as B, setPatternDecimal as $, getCurrencyFormatOptions as se, CURRENCYFORMAT as wt, DATEFMTLISG as Pt, NUMBERFORMAT as xt, getDateFormatOptions as Be, getNumberFormatOptions as Ve, isPatternHasDecimal as Rt, SheetsNumfmtCellContentController as We, getPatternPreviewIgnoreGeneral as $t, getPatternType as fe, SetNumfmtCommand as Ge, SubtractDecimalCommand as Ke, AddDecimalCommand as Ye, SetCurrencyCommand as Ze, getCurrencySymbolIconByLocale as we, SetPercentCommand as ze, getCurrencySymbolByLocale as Ot, localeCurrencySymbolMap as kt, getPatternPreview as Ut, UniverSheetsNumfmtPlugin as Dt } from "@univerjs/sheets-numfmt";
7
7
  import { HoverManagerService as Ft, CellAlertManagerService as Lt, CellAlertType as At, SheetSkeletonManagerService as Ht, IEditorBridgeService as jt, getCurrentRangeDisable$ as V, deriveStateFromActiveSheet$ as Bt, UniverSheetsUIPlugin as Vt } from "@univerjs/sheets-ui";
8
8
  import { INumfmtService as pe, SheetInterceptorService as Xe, SheetsSelectionsService as ge, INTERCEPTOR_POINT as Wt, RemoveNumfmtMutation as _e, SetNumfmtMutation as Se, BEFORE_CELL_EDIT as Gt, AFTER_CELL_EDIT as Kt, SetRangeValuesCommand as Yt, transformCellsToRange as Zt, factorySetNumfmtUndoMutation as zt, factoryRemoveNumfmtUndoMutation as Xt, RangeProtectionPermissionEditPoint as W, WorksheetEditPermission as G, WorksheetSetCellStylePermission as K, WorkbookEditablePermission as Y } from "@univerjs/sheets";
9
9
  import { IZenZoneService as qt, useDependency as b, ComponentManager as qe, ISidebarService as Jt, getMenuHiddenObservable as Z, MenuItemType as z, ILayoutService as Qt, RibbonStartGroup as en, IMenuManagerService as tn } from "@univerjs/ui";
@@ -18,7 +18,7 @@ var _n = Object.getOwnPropertyDescriptor, Sn = (e, t, r, n) => {
18
18
  for (var i = n > 1 ? void 0 : n ? _n(t, r) : t, s = e.length - 1, o; s >= 0; s--)
19
19
  (o = e[s]) && (i = o(i) || i);
20
20
  return i;
21
- }, k = (e, t) => (r, n) => t(r, n, e);
21
+ }, U = (e, t) => (r, n) => t(r, n, e);
22
22
  const oe = "SHEET_NUMFMT_ALERT";
23
23
  let de = class extends te {
24
24
  constructor(e, t, r, n, i, s, o) {
@@ -44,7 +44,7 @@ let de = class extends te {
44
44
  this._hideAlert();
45
45
  return;
46
46
  }
47
- if (ke(c.pattern) && dt.isDefine(a == null ? void 0 : a.v) && De(a.v)) {
47
+ if (Ue(c.pattern) && dt.isDefine(a == null ? void 0 : a.v) && De(a.v)) {
48
48
  if ((t = this._configService.getConfig(Mt)) != null && t.disableTextFormatAlert)
49
49
  return;
50
50
  const u = this._cellAlertManagerService.currentAlert.get(oe), l = (r = u == null ? void 0 : u.alert) == null ? void 0 : r.location;
@@ -77,12 +77,12 @@ let de = class extends te {
77
77
  }
78
78
  };
79
79
  de = Sn([
80
- k(1, C(Ft)),
81
- k(2, C(Lt)),
82
- k(3, C(E)),
83
- k(4, qt),
84
- k(5, C(pe)),
85
- k(6, Ue)
80
+ U(1, C(Ft)),
81
+ U(2, C(Lt)),
82
+ U(3, C(E)),
83
+ U(4, qt),
84
+ U(5, C(pe)),
85
+ U(6, ke)
86
86
  ], de);
87
87
  const ce = {
88
88
  id: "sheet.operation.close.numfmt.panel",
@@ -395,11 +395,11 @@ function On(e) {
395
395
  )
396
396
  ] });
397
397
  }
398
- const Un = (e) => {
398
+ const kn = (e) => {
399
399
  const t = ht.getFormatInfo(e);
400
400
  return Be().map((r) => r.value).includes(e) || ["date", "datetime", "time"].includes(t.type);
401
401
  };
402
- function kn(e) {
402
+ function Un(e) {
403
403
  const { onChange: t, defaultPattern: r } = e, n = x(Be, []), i = b(E), [s, o] = N(() => {
404
404
  if (r) {
405
405
  const c = n.find((a) => a.value === r);
@@ -475,17 +475,17 @@ const Hn = (e) => {
475
475
  { label: "sheet.numfmt.general", component: Fn },
476
476
  { label: "sheet.numfmt.accounting", component: Tn },
477
477
  { label: "sheet.numfmt.currency", component: wn },
478
- { label: "sheet.numfmt.date", component: kn },
478
+ { label: "sheet.numfmt.date", component: Un },
479
479
  { label: "sheet.numfmt.thousandthPercentile", component: An },
480
480
  { label: "sheet.numfmt.customFormat", component: On }
481
481
  ].map((_) => ({ ..._, label: m(_.label) })),
482
482
  []
483
483
  ), [u, l] = N(g), [v, f] = N(() => `${n}_${i}`), { mark: p, userHabitCurrency: d } = In(() => f(`${n}_${i}_userCurrency'`)), S = x(() => {
484
484
  var _;
485
- return (_ = a.find((U) => U.label === u)) == null ? void 0 : _.component;
485
+ return (_ = a.find((k) => k.label === u)) == null ? void 0 : _.component;
486
486
  }, [u]);
487
487
  function g() {
488
- return [Dn, En, Mn, Un, Ln].reduce((U, at, lt) => U || (at(r) ? a[lt].label : ""), "") || a[0].label;
488
+ return [Dn, En, Mn, kn, Ln].reduce((k, at, lt) => k || (at(r) ? a[lt].label : ""), "") || a[0].label;
489
489
  }
490
490
  const I = a.map((_) => ({
491
491
  label: _.label,
@@ -495,8 +495,8 @@ const Hn = (e) => {
495
495
  }, R = dn((_) => {
496
496
  e.onChange({ type: "change", value: _ });
497
497
  }, []), O = () => {
498
- const _ = o.current() || "", U = B(_);
499
- U && p(U), e.onChange({ type: "confirm", value: _ });
498
+ const _ = o.current() || "", k = B(_);
499
+ k && p(k), e.onChange({ type: "confirm", value: _ });
500
500
  }, D = () => {
501
501
  e.onChange({ type: "cancel", value: "" });
502
502
  }, ie = {
@@ -760,10 +760,6 @@ let J = class extends te {
760
760
  const c = r.worksheet.getCellRaw(i, s);
761
761
  return (c == null ? void 0 : c.t) === P.NUMBER && (c == null ? void 0 : c.v) !== void 0 && c.v !== null && De(c.v) && (c.v = gn(Number(c.v))), n && n(c);
762
762
  }
763
- case "percent":
764
- case "date":
765
- case "time":
766
- case "datetime":
767
763
  default:
768
764
  return n && n(t);
769
765
  }
@@ -795,7 +791,7 @@ let J = class extends te {
795
791
  r.row,
796
792
  r.col
797
793
  ), s = r.worksheet.getCellRaw(r.row, r.col);
798
- if (ke(i == null ? void 0 : i.pattern) || t.t === P.FORCE_STRING)
794
+ if (Ue(i == null ? void 0 : i.pattern) || t.t === P.FORCE_STRING)
799
795
  return n(t);
800
796
  const o = (a = t.p) == null ? void 0 : a.body, m = (l = (u = t == null ? void 0 : t.p) == null ? void 0 : u.body) != null && l.dataStream ? t.p.body.dataStream.replace(/\r\n$/, "") : String(t.v), c = gt(m);
801
797
  if (o)
@@ -1075,7 +1071,7 @@ function Qn() {
1075
1071
  a ? v.push({ row: f, col: p, pattern: a, type: fe(a) }) : v.push({ row: f, col: p });
1076
1072
  }), e.executeCommand(Ge.id, { values: v }), r.focus();
1077
1073
  }, o = x(() => {
1078
- const a = Ut.get(t.getCurrentLocale());
1074
+ const a = kt.get(t.getCurrentLocale());
1079
1075
  return it(a);
1080
1076
  }, [t]), m = (a) => {
1081
1077
  if (a === 0)
@@ -1094,7 +1090,13 @@ function Qn() {
1094
1090
  onClick: () => m(u),
1095
1091
  children: [
1096
1092
  /* @__PURE__ */ h("span", { children: t.t(a.label) }),
1097
- /* @__PURE__ */ h("span", { className: "univer-text-xs univer-text-gray-500", children: a.pattern ? kt(a.pattern || "", c, n.locale).result.trim() : "" })
1093
+ /* @__PURE__ */ h(
1094
+ "span",
1095
+ {
1096
+ className: "univer-text-xs univer-text-gray-500 dark:!univer-text-gray-400",
1097
+ children: a.pattern ? Ut(a.pattern || "", c, n.locale).result.trim() : ""
1098
+ }
1099
+ )
1098
1100
  ]
1099
1101
  },
1100
1102
  u
@@ -1192,7 +1194,7 @@ ct(ee, "type", T.UNIVER_SHEET);
1192
1194
  ee = or([
1193
1195
  bt(Vt, Dt),
1194
1196
  ue(1, C(He)),
1195
- ue(2, Ue),
1197
+ ue(2, ke),
1196
1198
  ue(3, je)
1197
1199
  ], ee);
1198
1200
  export {
package/lib/index.css CHANGED
@@ -1 +1 @@
1
- .univer-mb-5{margin-bottom:1.25rem}.univer-mr-3{margin-right:.75rem}.univer-mt-2{margin-top:.5rem}.univer-mt-3{margin-top:.75rem}.univer-mt-3\.5{margin-top:.875rem}.univer-mt-4{margin-top:1rem}.univer-flex{display:flex}.univer-grid{display:grid}.univer-h-7{height:1.75rem}.univer-h-full{height:100%}.univer-max-h-\[400px\]{max-height:400px}.univer-w-32{width:8rem}.univer-w-36{width:9rem}.univer-w-4{width:1rem}.univer-w-\[340px\]{width:340px}.univer-w-full{width:100%}.univer-cursor-pointer{cursor:pointer}.univer-flex-col{flex-direction:column}.univer-items-center{align-items:center}.univer-justify-end{justify-content:flex-end}.univer-justify-between{justify-content:space-between}.univer-gap-1{gap:.25rem}.univer-gap-1\.5{gap:.375rem}.univer-gap-6{gap:1.5rem}.univer-overflow-auto{overflow:auto}.univer-overflow-y-auto{overflow-y:auto}.univer-rounded{border-radius:.25rem}.univer-rounded-lg{border-radius:.5rem}.univer-p-1\.5{padding:.375rem}.univer-p-2{padding:.5rem}.univer-px-2{padding-left:.5rem;padding-right:.5rem}.univer-py-1\.5{padding-top:.375rem;padding-bottom:.375rem}.univer-pb-5{padding-bottom:1.25rem}.univer-text-sm,.univer-text-sm\/5{font-size:.875rem;line-height:1.25rem}.univer-text-xs{font-size:.75rem;line-height:1rem}.univer-text-gray-400{color:var(--univer-gray-400)}.univer-text-gray-500{color:var(--univer-gray-500)}.univer-text-gray-600{color:var(--univer-gray-600)}.univer-text-primary-600{color:var(--univer-primary-600)}.hover\:univer-bg-gray-100:hover{background-color:var(--univer-gray-100)}.dark\:\!univer-text-gray-200:where(.univer-dark,.univer-dark *){color:var(--univer-gray-200)!important}.dark\:hover\:\!univer-bg-gray-700:hover:where(.univer-dark,.univer-dark *){background-color:var(--univer-gray-700)!important}
1
+ .univer-mb-5{margin-bottom:1.25rem}.univer-mr-3{margin-right:.75rem}.univer-mt-2{margin-top:.5rem}.univer-mt-3{margin-top:.75rem}.univer-mt-3\.5{margin-top:.875rem}.univer-mt-4{margin-top:1rem}.univer-flex{display:flex}.univer-grid{display:grid}.univer-h-7{height:1.75rem}.univer-h-full{height:100%}.univer-max-h-\[400px\]{max-height:400px}.univer-w-32{width:8rem}.univer-w-36{width:9rem}.univer-w-4{width:1rem}.univer-w-\[340px\]{width:340px}.univer-w-full{width:100%}.univer-cursor-pointer{cursor:pointer}.univer-flex-col{flex-direction:column}.univer-items-center{align-items:center}.univer-justify-end{justify-content:flex-end}.univer-justify-between{justify-content:space-between}.univer-gap-1{gap:.25rem}.univer-gap-1\.5{gap:.375rem}.univer-gap-6{gap:1.5rem}.univer-overflow-auto{overflow:auto}.univer-overflow-y-auto{overflow-y:auto}.univer-rounded{border-radius:.25rem}.univer-rounded-lg{border-radius:.5rem}.univer-p-1\.5{padding:.375rem}.univer-p-2{padding:.5rem}.univer-px-2{padding-left:.5rem;padding-right:.5rem}.univer-py-1\.5{padding-top:.375rem;padding-bottom:.375rem}.univer-pb-5{padding-bottom:1.25rem}.univer-text-sm,.univer-text-sm\/5{font-size:.875rem;line-height:1.25rem}.univer-text-xs{font-size:.75rem;line-height:1rem}.univer-text-gray-400{color:var(--univer-gray-400)}.univer-text-gray-500{color:var(--univer-gray-500)}.univer-text-gray-600{color:var(--univer-gray-600)}.univer-text-primary-600{color:var(--univer-primary-600)}.hover\:univer-bg-gray-100:hover{background-color:var(--univer-gray-100)}.dark\:\!univer-text-gray-200:where(.univer-dark,.univer-dark *){color:var(--univer-gray-200)!important}.dark\:\!univer-text-gray-400:where(.univer-dark,.univer-dark *){color:var(--univer-gray-400)!important}.dark\:hover\:\!univer-bg-gray-700:hover:where(.univer-dark,.univer-dark *){background-color:var(--univer-gray-700)!important}
package/lib/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  var ut = Object.defineProperty;
2
2
  var mt = (e, t, r) => t in e ? ut(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
3
3
  var X = (e, t, r) => mt(e, typeof t != "symbol" ? t + "" : t, r);
4
- import { Inject as C, LocaleService as E, IConfigService as Ue, Disposable as te, isTextFormat as ke, Tools as dt, isRealNum as De, CommandType as Fe, ILocalStorageService as Le, isPatternEqualWithoutDecimal as ne, numfmt as ht, ThemeService as vt, IUniverInstanceService as he, ICommandService as ve, UniverInstanceType as T, CellValueType as P, toDisposable as me, DisposableCollection as ft, InterceptorEffectEnum as Te, Range as Ae, Injector as He, Optional as pt, getNumfmtParseValueFilter as gt, willLoseNumericPrecision as _t, fromCallback as St, isDefaultFormat as Ct, DEFAULT_TEXT_FORMAT_EXCEL as yt, DependentOn as bt, Plugin as It, merge as Nt, registerDependencies as Et, touchDependencies as Tt } from "@univerjs/core";
4
+ import { Inject as C, LocaleService as E, IConfigService as ke, Disposable as te, isTextFormat as Ue, Tools as dt, isRealNum as De, CommandType as Fe, ILocalStorageService as Le, isPatternEqualWithoutDecimal as ne, numfmt as ht, ThemeService as vt, IUniverInstanceService as he, ICommandService as ve, UniverInstanceType as T, CellValueType as P, toDisposable as me, DisposableCollection as ft, InterceptorEffectEnum as Te, Range as Ae, Injector as He, Optional as pt, getNumfmtParseValueFilter as gt, willLoseNumericPrecision as _t, fromCallback as St, isDefaultFormat as Ct, DEFAULT_TEXT_FORMAT_EXCEL as yt, DependentOn as bt, Plugin as It, merge as Nt, registerDependencies as Et, touchDependencies as Tt } from "@univerjs/core";
5
5
  import { IRenderManagerService as je } from "@univerjs/engine-render";
6
- import { SHEETS_NUMFMT_PLUGIN_CONFIG_KEY as Mt, currencySymbols as Me, getDecimalFromPattern as q, getCurrencyType as B, setPatternDecimal as $, getCurrencyFormatOptions as se, CURRENCYFORMAT as wt, DATEFMTLISG as Pt, NUMBERFORMAT as xt, getDateFormatOptions as Be, getNumberFormatOptions as Ve, isPatternHasDecimal as Rt, SheetsNumfmtCellContentController as We, getPatternPreviewIgnoreGeneral as $t, getPatternType as fe, SetNumfmtCommand as Ge, SubtractDecimalCommand as Ke, AddDecimalCommand as Ye, SetCurrencyCommand as Ze, getCurrencySymbolIconByLocale as we, SetPercentCommand as ze, getCurrencySymbolByLocale as Ot, localeCurrencySymbolMap as Ut, getPatternPreview as kt, UniverSheetsNumfmtPlugin as Dt } from "@univerjs/sheets-numfmt";
6
+ import { SHEETS_NUMFMT_PLUGIN_CONFIG_KEY as Mt, currencySymbols as Me, getDecimalFromPattern as q, getCurrencyType as B, setPatternDecimal as $, getCurrencyFormatOptions as se, CURRENCYFORMAT as wt, DATEFMTLISG as Pt, NUMBERFORMAT as xt, getDateFormatOptions as Be, getNumberFormatOptions as Ve, isPatternHasDecimal as Rt, SheetsNumfmtCellContentController as We, getPatternPreviewIgnoreGeneral as $t, getPatternType as fe, SetNumfmtCommand as Ge, SubtractDecimalCommand as Ke, AddDecimalCommand as Ye, SetCurrencyCommand as Ze, getCurrencySymbolIconByLocale as we, SetPercentCommand as ze, getCurrencySymbolByLocale as Ot, localeCurrencySymbolMap as kt, getPatternPreview as Ut, UniverSheetsNumfmtPlugin as Dt } from "@univerjs/sheets-numfmt";
7
7
  import { HoverManagerService as Ft, CellAlertManagerService as Lt, CellAlertType as At, SheetSkeletonManagerService as Ht, IEditorBridgeService as jt, getCurrentRangeDisable$ as V, deriveStateFromActiveSheet$ as Bt, UniverSheetsUIPlugin as Vt } from "@univerjs/sheets-ui";
8
8
  import { INumfmtService as pe, SheetInterceptorService as Xe, SheetsSelectionsService as ge, INTERCEPTOR_POINT as Wt, RemoveNumfmtMutation as _e, SetNumfmtMutation as Se, BEFORE_CELL_EDIT as Gt, AFTER_CELL_EDIT as Kt, SetRangeValuesCommand as Yt, transformCellsToRange as Zt, factorySetNumfmtUndoMutation as zt, factoryRemoveNumfmtUndoMutation as Xt, RangeProtectionPermissionEditPoint as W, WorksheetEditPermission as G, WorksheetSetCellStylePermission as K, WorkbookEditablePermission as Y } from "@univerjs/sheets";
9
9
  import { IZenZoneService as qt, useDependency as b, ComponentManager as qe, ISidebarService as Jt, getMenuHiddenObservable as Z, MenuItemType as z, ILayoutService as Qt, RibbonStartGroup as en, IMenuManagerService as tn } from "@univerjs/ui";
@@ -18,7 +18,7 @@ var _n = Object.getOwnPropertyDescriptor, Sn = (e, t, r, n) => {
18
18
  for (var i = n > 1 ? void 0 : n ? _n(t, r) : t, s = e.length - 1, o; s >= 0; s--)
19
19
  (o = e[s]) && (i = o(i) || i);
20
20
  return i;
21
- }, k = (e, t) => (r, n) => t(r, n, e);
21
+ }, U = (e, t) => (r, n) => t(r, n, e);
22
22
  const oe = "SHEET_NUMFMT_ALERT";
23
23
  let de = class extends te {
24
24
  constructor(e, t, r, n, i, s, o) {
@@ -44,7 +44,7 @@ let de = class extends te {
44
44
  this._hideAlert();
45
45
  return;
46
46
  }
47
- if (ke(c.pattern) && dt.isDefine(a == null ? void 0 : a.v) && De(a.v)) {
47
+ if (Ue(c.pattern) && dt.isDefine(a == null ? void 0 : a.v) && De(a.v)) {
48
48
  if ((t = this._configService.getConfig(Mt)) != null && t.disableTextFormatAlert)
49
49
  return;
50
50
  const u = this._cellAlertManagerService.currentAlert.get(oe), l = (r = u == null ? void 0 : u.alert) == null ? void 0 : r.location;
@@ -77,12 +77,12 @@ let de = class extends te {
77
77
  }
78
78
  };
79
79
  de = Sn([
80
- k(1, C(Ft)),
81
- k(2, C(Lt)),
82
- k(3, C(E)),
83
- k(4, qt),
84
- k(5, C(pe)),
85
- k(6, Ue)
80
+ U(1, C(Ft)),
81
+ U(2, C(Lt)),
82
+ U(3, C(E)),
83
+ U(4, qt),
84
+ U(5, C(pe)),
85
+ U(6, ke)
86
86
  ], de);
87
87
  const ce = {
88
88
  id: "sheet.operation.close.numfmt.panel",
@@ -395,11 +395,11 @@ function On(e) {
395
395
  )
396
396
  ] });
397
397
  }
398
- const Un = (e) => {
398
+ const kn = (e) => {
399
399
  const t = ht.getFormatInfo(e);
400
400
  return Be().map((r) => r.value).includes(e) || ["date", "datetime", "time"].includes(t.type);
401
401
  };
402
- function kn(e) {
402
+ function Un(e) {
403
403
  const { onChange: t, defaultPattern: r } = e, n = x(Be, []), i = b(E), [s, o] = N(() => {
404
404
  if (r) {
405
405
  const c = n.find((a) => a.value === r);
@@ -475,17 +475,17 @@ const Hn = (e) => {
475
475
  { label: "sheet.numfmt.general", component: Fn },
476
476
  { label: "sheet.numfmt.accounting", component: Tn },
477
477
  { label: "sheet.numfmt.currency", component: wn },
478
- { label: "sheet.numfmt.date", component: kn },
478
+ { label: "sheet.numfmt.date", component: Un },
479
479
  { label: "sheet.numfmt.thousandthPercentile", component: An },
480
480
  { label: "sheet.numfmt.customFormat", component: On }
481
481
  ].map((_) => ({ ..._, label: m(_.label) })),
482
482
  []
483
483
  ), [u, l] = N(g), [v, f] = N(() => `${n}_${i}`), { mark: p, userHabitCurrency: d } = In(() => f(`${n}_${i}_userCurrency'`)), S = x(() => {
484
484
  var _;
485
- return (_ = a.find((U) => U.label === u)) == null ? void 0 : _.component;
485
+ return (_ = a.find((k) => k.label === u)) == null ? void 0 : _.component;
486
486
  }, [u]);
487
487
  function g() {
488
- return [Dn, En, Mn, Un, Ln].reduce((U, at, lt) => U || (at(r) ? a[lt].label : ""), "") || a[0].label;
488
+ return [Dn, En, Mn, kn, Ln].reduce((k, at, lt) => k || (at(r) ? a[lt].label : ""), "") || a[0].label;
489
489
  }
490
490
  const I = a.map((_) => ({
491
491
  label: _.label,
@@ -495,8 +495,8 @@ const Hn = (e) => {
495
495
  }, R = dn((_) => {
496
496
  e.onChange({ type: "change", value: _ });
497
497
  }, []), O = () => {
498
- const _ = o.current() || "", U = B(_);
499
- U && p(U), e.onChange({ type: "confirm", value: _ });
498
+ const _ = o.current() || "", k = B(_);
499
+ k && p(k), e.onChange({ type: "confirm", value: _ });
500
500
  }, D = () => {
501
501
  e.onChange({ type: "cancel", value: "" });
502
502
  }, ie = {
@@ -760,10 +760,6 @@ let J = class extends te {
760
760
  const c = r.worksheet.getCellRaw(i, s);
761
761
  return (c == null ? void 0 : c.t) === P.NUMBER && (c == null ? void 0 : c.v) !== void 0 && c.v !== null && De(c.v) && (c.v = gn(Number(c.v))), n && n(c);
762
762
  }
763
- case "percent":
764
- case "date":
765
- case "time":
766
- case "datetime":
767
763
  default:
768
764
  return n && n(t);
769
765
  }
@@ -795,7 +791,7 @@ let J = class extends te {
795
791
  r.row,
796
792
  r.col
797
793
  ), s = r.worksheet.getCellRaw(r.row, r.col);
798
- if (ke(i == null ? void 0 : i.pattern) || t.t === P.FORCE_STRING)
794
+ if (Ue(i == null ? void 0 : i.pattern) || t.t === P.FORCE_STRING)
799
795
  return n(t);
800
796
  const o = (a = t.p) == null ? void 0 : a.body, m = (l = (u = t == null ? void 0 : t.p) == null ? void 0 : u.body) != null && l.dataStream ? t.p.body.dataStream.replace(/\r\n$/, "") : String(t.v), c = gt(m);
801
797
  if (o)
@@ -1075,7 +1071,7 @@ function Qn() {
1075
1071
  a ? v.push({ row: f, col: p, pattern: a, type: fe(a) }) : v.push({ row: f, col: p });
1076
1072
  }), e.executeCommand(Ge.id, { values: v }), r.focus();
1077
1073
  }, o = x(() => {
1078
- const a = Ut.get(t.getCurrentLocale());
1074
+ const a = kt.get(t.getCurrentLocale());
1079
1075
  return it(a);
1080
1076
  }, [t]), m = (a) => {
1081
1077
  if (a === 0)
@@ -1094,7 +1090,13 @@ function Qn() {
1094
1090
  onClick: () => m(u),
1095
1091
  children: [
1096
1092
  /* @__PURE__ */ h("span", { children: t.t(a.label) }),
1097
- /* @__PURE__ */ h("span", { className: "univer-text-xs univer-text-gray-500", children: a.pattern ? kt(a.pattern || "", c, n.locale).result.trim() : "" })
1093
+ /* @__PURE__ */ h(
1094
+ "span",
1095
+ {
1096
+ className: "univer-text-xs univer-text-gray-500 dark:!univer-text-gray-400",
1097
+ children: a.pattern ? Ut(a.pattern || "", c, n.locale).result.trim() : ""
1098
+ }
1099
+ )
1098
1100
  ]
1099
1101
  },
1100
1102
  u
@@ -1192,7 +1194,7 @@ ct(ee, "type", T.UNIVER_SHEET);
1192
1194
  ee = or([
1193
1195
  bt(Vt, Dt),
1194
1196
  ue(1, C(He)),
1195
- ue(2, Ue),
1197
+ ue(2, ke),
1196
1198
  ue(3, je)
1197
1199
  ], ee);
1198
1200
  export {
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(C,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/sheets-numfmt"),require("@univerjs/sheets-ui"),require("@univerjs/sheets"),require("@univerjs/ui"),require("rxjs"),require("rxjs/operators"),require("react/jsx-runtime"),require("react"),require("@univerjs/design"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","@univerjs/sheets-numfmt","@univerjs/sheets-ui","@univerjs/sheets","@univerjs/ui","rxjs","rxjs/operators","react/jsx-runtime","react","@univerjs/design","@univerjs/engine-formula"],s):(C=typeof globalThis<"u"?globalThis:C||self,s(C.UniverSheetsNumfmtUi={},C.UniverCore,C.UniverEngineRender,C.UniverSheetsNumfmt,C.UniverSheetsUi,C.UniverSheets,C.UniverUi,C.rxjs,C.rxjs.operators,C.React,C.React,C.UniverDesign,C.UniverEngineFormula))})(this,(function(C,s,k,d,N,g,_,w,W,l,y,E,me){"use strict";var it=Object.defineProperty;var st=(C,s,k)=>s in C?it(C,s,{enumerable:!0,configurable:!0,writable:!0,value:k}):C[s]=k;var q=(C,s,k)=>st(C,typeof s!="symbol"?s+"":s,k);const ee={};var de=Object.getOwnPropertyDescriptor,ve=(e,t,r,n)=>{for(var i=n>1?void 0:n?de(t,r):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=o(i)||i);return i},$=(e,t)=>(r,n)=>t(r,n,e);const G="SHEET_NUMFMT_ALERT";let K=class extends s.Disposable{constructor(e,t,r,n,i,a,o){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=r,this._localeService=n,this._zenZoneService=i,this._numfmtService=a,this._configService=o,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(w.debounceTime(100)).subscribe(e=>{var t,r;if(e){const n=e.location,i=this._context.unit,a=i.getActiveSheet();if(!a)return this._hideAlert();const o=n.unitId,p=n.subUnitId;let c;const u=a.getCell(n.row,n.col);if(u!=null&&u.s){const v=i.getStyles().get(u.s);v!=null&&v.n&&(c=v.n)}if(c||(c=this._numfmtService.getValue(o,p,n.row,n.col)),!c){this._hideAlert();return}if(s.isTextFormat(c.pattern)&&s.Tools.isDefine(u==null?void 0:u.v)&&s.isRealNum(u.v)){if((t=this._configService.getConfig(d.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY))!=null&&t.disableTextFormatAlert)return;const v=this._cellAlertManagerService.currentAlert.get(G),m=(r=v==null?void 0:v.alert)==null?void 0:r.location;if(m&&m.row===n.row&&m.col===n.col&&m.subUnitId===n.subUnitId&&m.unitId===n.unitId){this._hideAlert();return}this._cellAlertManagerService.showAlert({type:N.CellAlertType.ERROR,title:this._localeService.t("info.error"),message:this._localeService.t("info.forceStringInfo"),location:n,width:200,height:74,key:G});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(G)}};K=ve([$(1,s.Inject(N.HoverManagerService)),$(2,s.Inject(N.CellAlertManagerService)),$(3,s.Inject(s.LocaleService)),$(4,_.IZenZoneService),$(5,s.Inject(g.INumfmtService)),$(6,s.IConfigService)],K);const Y={id:"sheet.operation.close.numfmt.panel",type:s.CommandType.OPERATION,handler:()=>!0},j={id:"sheet.operation.open.numfmt.panel",type:s.CommandType.OPERATION,handler:e=>(e.get(A).openPanel(),!0)};var pe=Object.getOwnPropertyDescriptor,he=(e,t,r,n)=>{for(var i=n>1?void 0:n?pe(t,r):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=o(i)||i);return i},fe=(e,t)=>(r,n)=>t(r,n,e);const Z=y.createContext([]);let F=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,o,p)=>{const c=p.length;return{value:a,priority:c-o}});return t.sort((a,o)=>{var u,v;const p=((u=i.find(m=>m.value===a))==null?void 0:u.priority)||-1;return(((v=i.find(m=>m.value===o))==null?void 0:v.priority)||-1)-p})}return n||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};F=he([fe(0,s.Inject(s.ILocalStorageService))],F);const te="numfmtCurrency",ge=e=>{const t=_.useDependency(F),[r,n]=y.useState(d.currencySymbols);return y.useEffect(()=>{t.addHabit("numfmtCurrency",[]).then(()=>{t.getHabit(te,[...d.currencySymbols]).then(a=>{n(a),e&&e(a)})})},[]),{userHabitCurrency:r,mark:a=>{t.markHabit(te,a)}}},Se=()=>{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({})}},ye=e=>!!d.getCurrencyType(e)&&e.startsWith("_("),_e=e=>{const{defaultPattern:t,action:r,onChange:n}=e,[i,a]=y.useState(()=>d.getDecimalFromPattern(t||"",2)),o=y.useContext(Z),[p,c]=y.useState(()=>d.getCurrencyType(t)||o[0]),u=y.useMemo(()=>o.map(b=>({label:b,value:b})),[]),m=_.useDependency(s.LocaleService).t;r.current=()=>d.setPatternDecimal(`_("${p}"* #,##0${i>0?".0":""}_)`,i);const f=b=>{c(b),n(d.setPatternDecimal(`_("${b}"* #,##0${i>0?".0":""}_)`,i))},S=b=>{const h=b||0;a(h),n(d.setPatternDecimal(`_("${p}"* #,##0${h>0?".0":""}_)`,h))};return l.jsxs("div",{children:[l.jsxs("div",{className:"univer-mt-4 univer-flex univer-justify-between",children:[l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2 univer-w-32",children:l.jsx(E.InputNumber,{value:i,step:1,precision:0,max:20,min:0,onChange:S})})]}),l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.currencyType")}),l.jsx("div",{className:"univer-mt-2 univer-w-36",children:l.jsx(E.Select,{options:u,value:p,onChange:f})})]})]}),l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.accountingDes")})]})},Ce=e=>!!d.getCurrencyType(e)&&!e.startsWith("_("),be=e=>{const r=_.useDependency(s.LocaleService).t,n=y.useContext(Z),[i,a]=y.useState(()=>d.getCurrencyType(e.defaultPattern)||n[0]),[o,p]=y.useState(()=>d.getDecimalFromPattern(e.defaultPattern||"",2)),[c,u]=y.useState(()=>{var I;const h=d.getCurrencyFormatOptions(i);return((I=h.find(M=>s.isPatternEqualWithoutDecimal(M.value,e.defaultPattern)))==null?void 0:I.value)||h[0].value}),v=y.useMemo(()=>d.getCurrencyFormatOptions(i),[i]),m=y.useMemo(()=>n.map(h=>({label:h,value:h})),[n]);e.action.current=()=>d.setPatternDecimal(c,o);const f=h=>{if(h===void 0)return;a(h);const P=d.getCurrencyFormatOptions(h)[0].value;u(P),e.onChange(d.setPatternDecimal(P,o))},S=h=>{h!==void 0&&(u(h),e.onChange(d.setPatternDecimal(h,o)))},b=h=>{p(h||0),e.onChange(d.setPatternDecimal(c,h||0))};return l.jsxs("div",{children:[l.jsxs("div",{className:"univer-mt-4 univer-flex univer-justify-between",children:[l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:r("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2 univer-w-32",children:l.jsx(E.InputNumber,{value:o,max:20,min:0,onChange:b})})]}),l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:r("sheet.numfmt.currencyType")}),l.jsx("div",{className:"univer-mt-2 univer-w-36",children:l.jsx(E.Select,{value:i,options:m,onChange:f})})]})]}),l.jsx("div",{className:"label univer-mt-4",children:r("sheet.numfmt.negType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(E.SelectList,{value:c,options:v,onChange:S})}),l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:r("sheet.numfmt.currencyDes")})]})};function ne({ref:e,...t}){const{icon:r,id:n,className:i,extend:a,...o}=t,p=`univerjs-icon univerjs-icon-${n} ${i||""}`.trim(),c=y.useRef(`_${Ee()}`);return re(r,`${n}`,{defIds:r.defIds,idSuffix:c.current},{ref:e,className:p,...o},a)}function re(e,t,r,n,i){return y.createElement(e.tag,{key:t,...Ie(e,r,i),...n},(Te(e,r).children||[]).map((a,o)=>re(a,`${t}-${e.tag}-${o}`,r,void 0,i)))}function Ie(e,t,r){const n={...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(([a,o])=>{a==="mask"&&typeof o=="string"&&(n[a]=o.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});const{defIds:i}=t;return!i||i.length===0||(e.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(([a,o])=>{typeof o=="string"&&(n[a]=o.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),n}function Te(e,t){var n;const{defIds:r}=t;return!r||r.length===0?e:e.tag==="defs"&&((n=e.children)!=null&&n.length)?{...e,children:e.children.map(i=>typeof i.attrs.id=="string"&&r&&r.includes(i.attrs.id)?{...i,attrs:{...i.attrs,id:i.attrs.id+t.idSuffix}}:i)}:e}function Ee(){return Math.random().toString(36).substring(2,8)}ne.displayName="UniverIcon";const Pe={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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"}}]},ie=y.forwardRef(function(t,r){return y.createElement(ne,Object.assign({},t,{id:"check-mark-icon",ref:r,icon:Pe}))});ie.displayName="CheckMarkIcon";const z="customFormat",X="numfmt_custom_pattern";function Me(e){const{defaultPattern:t,action:r,onChange:n}=e,i=_.useDependency(F),a=_.useDependency(s.ILocalStorageService),o=_.useDependency(s.LocaleService),[p,c]=y.useState(t);r.current=()=>(i.markHabit(z,p),a.getItem(X).then((S=[])=>{const b=[...new Set([p,...S||[]])].splice(0,10).filter(h=>!!h);a.setItem(X,b)}),p);const[u,v]=y.useState([]);y.useEffect(()=>{a.getItem(X).then(S=>{const b=[...d.CURRENCYFORMAT.map(h=>h.suffix("$")),...d.DATEFMTLISG.map(h=>h.suffix),...d.NUMBERFORMAT.map(h=>h.suffix)];b.push(...S||[]),i.addHabit(z,[]).finally(()=>{i.getHabit(z,b).then(h=>{v([...new Set(h)])})})})},[]);const m=S=>{c(S),n(S)},f=()=>{n(p)};return l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:o.t("sheet.numfmt.customFormat")}),l.jsx(E.Input,{placeholder:o.t("sheet.numfmt.customFormat"),onBlur:f,value:p,onChange:c,className:"univer-mt-2 univer-w-full"}),l.jsx("div",{className:E.clsx("univer-mt-2 univer-max-h-[400px] univer-overflow-auto univer-rounded-lg univer-p-2",E.borderClassName),children:u.map(S=>l.jsxs("div",{onClick:()=>m(S),className:"univer-flex univer-cursor-pointer univer-items-center univer-gap-1.5 univer-py-1.5 univer-text-sm",children:[l.jsx("div",{className:"univer-flex univer-w-4 univer-items-center univer-text-primary-600",children:p===S&&l.jsx(ie,{})}),l.jsx("div",{children:S})]},S))}),l.jsx("div",{className:"univer-mt-3 univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200",children:o.t("sheet.numfmt.customFormatDes")})]})}const Ne=e=>{const t=s.numfmt.getFormatInfo(e);return d.getDateFormatOptions().map(r=>r.value).includes(e)||["date","datetime","time"].includes(t.type)};function De(e){const{onChange:t,defaultPattern:r}=e,n=y.useMemo(d.getDateFormatOptions,[]),i=_.useDependency(s.LocaleService),[a,o]=y.useState(()=>{if(r){const c=n.find(u=>u.value===r);if(c)return c.value}return n[0].value});e.action.current=()=>a;const p=c=>{c!==void 0&&(o(c),t(c))};return l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:i.t("sheet.numfmt.dateType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(E.SelectList,{value:a,options:n,onChange:p})}),l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:i.t("sheet.numfmt.dateDes")})]})}const we=e=>!e,Ue=e=>{const r=_.useDependency(s.LocaleService).t;return e.action.current=()=>"",l.jsx("div",{children:l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:r("sheet.numfmt.generalDes")})})},xe=e=>d.getNumberFormatOptions().some(t=>s.isPatternEqualWithoutDecimal(t.value,e));function Oe(e){const t=_.useDependency(s.LocaleService),r=y.useMemo(d.getNumberFormatOptions,[]),[n,i]=y.useState(()=>d.getDecimalFromPattern(e.defaultPattern||"",0)),[a,o]=y.useState(()=>{const m=r.find(f=>s.isPatternEqualWithoutDecimal(f.value,e.defaultPattern||""));return(m==null?void 0:m.value)||r[0].value}),p=y.useMemo(()=>d.setPatternDecimal(a,Number(n||0)),[a,n]),c=y.useMemo(()=>!d.isPatternHasDecimal(a),[a]),u=m=>{i(m||0),e.onChange(d.setPatternDecimal(a,Number(m||0)))},v=m=>{m!==void 0&&(i(d.getDecimalFromPattern(m,0)),o(m),e.onChange(m))};return e.action.current=()=>p,l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:t.t("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(E.InputNumber,{disabled:c,value:n,max:20,min:0,onChange:u})}),l.jsxs("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:[" ",t.t("sheet.numfmt.negType")]}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(E.SelectList,{onChange:v,options:r,value:a})}),l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:t.t("sheet.numfmt.thousandthPercentileDes")})]})}const ke=e=>{const{defaultValue:t,defaultPattern:r,row:n,col:i}=e.value,a=_.useDependency(s.LocaleService),o=y.useRef(()=>""),p=a.t,c=Se(),u=y.useMemo(()=>[{label:"sheet.numfmt.general",component:Ue},{label:"sheet.numfmt.accounting",component:_e},{label:"sheet.numfmt.currency",component:be},{label:"sheet.numfmt.date",component:De},{label:"sheet.numfmt.thousandthPercentile",component:Oe},{label:"sheet.numfmt.customFormat",component:Me}].map(T=>({...T,label:p(T.label)})),[]),[v,m]=y.useState(I),[f,S]=y.useState(()=>`${n}_${i}`),{mark:b,userHabitCurrency:h}=ge(()=>S(`${n}_${i}_userCurrency'`)),P=y.useMemo(()=>{var T;return(T=u.find(L=>L.label===v))==null?void 0:T.component},[v]);function I(){return[we,ye,Ce,Ne,xe].reduce((L,nt,rt)=>L||(nt(r)?u[rt].label:""),"")||u[0].label}const M=u.map(T=>({label:T.label,value:T.label})),U=T=>{m(T),c(()=>e.onChange({type:"change",value:o.current()||""}))},x=y.useCallback(T=>{e.onChange({type:"change",value:T})},[]),O=()=>{const T=o.current()||"",L=d.getCurrencyType(T);L&&b(L),e.onChange({type:"confirm",value:T})},R=()=>{e.onChange({type:"cancel",value:""})},Q={onChange:x,defaultValue:t,defaultPattern:r,action:o};return y.useEffect(()=>{m(I()),S(`${n}_${i}`)},[n,i]),l.jsxs("div",{className:E.clsx("univer-flex univer-h-full univer-flex-col univer-justify-between univer-overflow-y-auto univer-pb-5",E.scrollbarClassName),children:[l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-3.5 univer-text-sm univer-text-gray-400",children:p("sheet.numfmt.numfmtType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(E.Select,{className:"univer-w-full",value:v,options:M,onChange:U})}),l.jsx("div",{children:P&&l.jsx(Z.Provider,{value:h,children:y.createElement(P,{...Q,key:f})})})]}),l.jsxs("div",{className:"univer-mb-5 univer-mt-3.5 univer-flex univer-justify-end",children:[l.jsx(E.Button,{onClick:R,className:"univer-mr-3",children:p("sheet.numfmt.cancel")}),l.jsx(E.Button,{variant:"primary",onClick:O,children:p("sheet.numfmt.confirm")})]})]})};var $e=Object.getOwnPropertyDescriptor,Le=(e,t,r,n)=>{for(var i=n>1?void 0:n?$e(t,r):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=o(i)||i);return i},D=(e,t)=>(r,n)=>t(r,n,e);const se="SHEET_NUMFMT_PANEL";let A=class extends s.Disposable{constructor(t,r,n,i,a,o,p,c,u,v,m){super();q(this,"_previewPattern","");q(this,"_sidebarDisposable",null);this._sheetInterceptorService=t,this._themeService=r,this._univerInstanceService=n,this._commandService=i,this._selectionManagerService=a,this._renderManagerService=o,this._numfmtService=p,this._componentManager=c,this._sidebarService=u,this._localeService=v,this._sheetsNumfmtCellContentController=m,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener(),this._initNumfmtLocalChange()}_initNumfmtLocalChange(){this.disposeWithMe(w.merge(this._sheetsNumfmtCellContentController.locale$,this._localeService.currentLocale$).subscribe(()=>{this._forceUpdate()}))}openPanel(){var P;const t=this._sidebarService,r=this._selectionManagerService,n=this._commandService,i=this._univerInstanceService,a=this._numfmtService,o=this._localeService,c=(((P=r.getCurrentSelections())==null?void 0:P.map(I=>I.range))||[])[0];if(!c)return!1;const u=i.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),v=u.getActiveSheet();if(!v)return!1;const m=v.getCellRaw(c.startRow,c.startColumn),f=a.getValue(u.getUnitId(),v.getSheetId(),c.startRow,c.startColumn);let S="";f&&(S=f.pattern);const b=(m==null?void 0:m.t)===s.CellValueType.NUMBER?m.v:12345678,h={onChange:I=>{var M;if(I.type==="change")this._previewPattern=I.value,this._forceUpdate();else if(I.type==="confirm"){const U=((M=r.getCurrentSelections())==null?void 0:M.map(R=>R.range))||[],x={values:[]},O=d.getPatternType(I.value);U.forEach(R=>{s.Range.foreach(R,(Q,T)=>{x.values.push({row:Q,col:T,pattern:I.value,type:O})})}),n.executeCommand(d.SetNumfmtCommand.id,x),t.close()}else I.type==="cancel"&&t.close()},value:{defaultPattern:S,defaultValue:b,row:c.startRow,col:c.startColumn}};return this._sidebarDisposable=t.open({header:{title:o.t("sheet.numfmt.title")},children:{label:se,...h},onClose:()=>{this._forceUpdate(),n.executeCommand(Y.id)}}),!0}_forceUpdate(t){var n;const r=this._renderManagerService.getRenderById(t!=null?t:this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET).getUnitId());r==null||r.with(N.SheetSkeletonManagerService).reCalculate(),(n=r==null?void 0:r.mainComponent)==null||n.makeDirty()}_initCommands(){[j,Y].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initPanel(){this.disposeWithMe(this._componentManager.register(se,ke))}_initRealTimeRenderingInterceptor(){const t=new w.Observable(n=>{this._commandService.onCommandExecuted(i=>{i.id===j.id&&n.next(!0),i.id===Y.id&&n.next(!1)})}),r=w.combineLatest([t,this._selectionManagerService.selectionMoveEnd$.pipe(W.map(n=>n?n.map(i=>i.range):[]))]);this.disposeWithMe(s.toDisposable(r.pipe(W.switchMap(([n,i])=>new w.Observable(a=>{const o=new s.DisposableCollection;return n&&i.length&&a.next({selectionRanges:i,disposableCollection:o}),()=>{o.dispose()}})),W.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:n,selectionRanges:i})=>{var o,p;const a=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);this.openPanel(),n.add(this._sheetInterceptorService.intercept(g.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,effect:s.InterceptorEffectEnum.Value|s.InterceptorEffectEnum.Style,handler:(c,u,v)=>{var b;const{row:m,col:f}=u,S=v(c)||{};if(i.find(h=>h.startColumn<=f&&h.endColumn>=f&&h.startRow<=m&&h.endRow>=m)){const h=u.worksheet.getCellRaw(m,f),P=h==null?void 0:h.v,I=h==null?void 0:h.t;if(P==null||I!==s.CellValueType.NUMBER||this._previewPattern===null)return S;const M=d.getPatternPreviewIgnoreGeneral(this._previewPattern,P,this._sheetsNumfmtCellContentController.locale);if(M.color){const U=(b=this._themeService.getColorFromTheme(`${M.color}.500`))!=null?b:M.color;return{...S,v:M.result,t:s.CellValueType.STRING,s:{cl:{rgb:U}}}}return{...S,v:M.result,t:s.CellValueType.STRING}}return S}})),(p=(o=this._renderManagerService.getRenderById(a.getUnitId()))==null?void 0:o.mainComponent)==null||p.makeDirty()})))}_commandExecutedListener(){const t=[g.RemoveNumfmtMutation.id,g.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(W.debounceTime(16)).subscribe(r=>this._forceUpdate(r)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_SHEET).subscribe(t=>{var r;t||((r=this._sidebarDisposable)==null||r.dispose(),this._sidebarDisposable=null)})}};A=Le([D(0,s.Inject(g.SheetInterceptorService)),D(1,s.Inject(s.ThemeService)),D(2,s.IUniverInstanceService),D(3,s.ICommandService),D(4,s.Inject(g.SheetsSelectionsService)),D(5,k.IRenderManagerService),D(6,g.INumfmtService),D(7,s.Inject(_.ComponentManager)),D(8,_.ISidebarService),D(9,s.Inject(s.LocaleService)),D(10,s.Inject(d.SheetsNumfmtCellContentController))],A);var je=Object.getOwnPropertyDescriptor,Fe=(e,t,r,n)=>{for(var i=n>1?void 0:n?je(t,r):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=o(i)||i);return i},H=(e,t)=>(r,n)=>t(r,n,e);const Ae=()=>{let e=[];return{add:(i,a,o,p,c)=>e.push({unitId:i,subUnitId:a,row:o,col:p,value:c}),getEffects:()=>e,clean:()=>{e=[]}}};let B=class extends s.Disposable{constructor(t,r,n,i,a){super();q(this,"_collectEffectMutation",Ae());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(s.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.BEFORE_CELL_EDIT,{handler:(t,r,n)=>{const i=r.row,a=r.col,o=this._numfmtService.getValue(r.unitId,r.subUnitId,i,a);if(o)switch(d.getPatternType(o.pattern)){case"scientific":case"currency":case"grouped":case"number":{const c=r.worksheet.getCellRaw(i,a);return(c==null?void 0:c.t)===s.CellValueType.NUMBER&&(c==null?void 0:c.v)!==void 0&&c.v!==null&&s.isRealNum(c.v)&&(c.v=me.stripErrorMargin(Number(c.v))),n&&n(c)}case"percent":case"date":case"time":case"datetime":default:return n&&n(t)}return n(t)}})))}_initInterceptorEditorEnd(){this.disposeWithMe(s.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.AFTER_CELL_EDIT,{handler:(t,r,n)=>{var u,v,m;if(!(t!=null&&t.v)&&!(t!=null&&t.p))return n(t);this._collectEffectMutation.clean();const i=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col),a=r.worksheet.getCellRaw(r.row,r.col);if(s.isTextFormat(i==null?void 0:i.pattern)||t.t===s.CellValueType.FORCE_STRING)return n(t);const o=(u=t.p)==null?void 0:u.body,p=(m=(v=t==null?void 0:t.p)==null?void 0:v.body)!=null&&m.dataStream?t.p.body.dataStream.replace(/\r\n$/,""):String(t.v),c=s.getNumfmtParseValueFilter(p);if(o)if(He(o)){const{dataStream:f}=o,S=f.replace(/\r\n$/,""),b=Number(S);if(Number.isNaN(b)&&!c)return n(t)}else return n(t);if(c){if(!c.z&&!(i!=null&&i.pattern)&&(a==null?void 0:a.t)!==s.CellValueType.STRING&&(a==null?void 0:a.t)!==s.CellValueType.FORCE_STRING&&s.willLoseNumericPrecision(p))return n({...t,p:void 0,v:p,t:s.CellValueType.FORCE_STRING});c.z&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:c.z});const f=Number(c.v);return n({...t,p:void 0,v:f,t:s.CellValueType.NUMBER})}return n(t)}})))}_initInterceptorCommands(){const t=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(r){var n;switch(r.id){case g.SetRangeValuesCommand.id:{const i=t._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),a=i.getUnitId(),o=(n=i.getActiveSheet())==null?void 0:n.getSheetId();if(!o)return{redos:[],undos:[]};const p=t._collectEffectMutation.getEffects();if(t._collectEffectMutation.clean(),!p.length)return{redos:[],undos:[]};const c=p.filter(f=>{var S;return!!((S=f.value)!=null&&S.pattern)}).map(f=>({row:f.row,col:f.col,pattern:f.value.pattern})),u=p.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=[],m=[];if(c.length){const f={id:g.SetNumfmtMutation.id,params:g.transformCellsToRange(a,o,c)};v.push(f),m.push(...g.factorySetNumfmtUndoMutation(t._injector,f.params))}if(u.length){const f={id:g.RemoveNumfmtMutation.id,params:{unitId:a,subUnitId:o,ranges:u}};v.push(f),m.push(...g.factoryRemoveNumfmtUndoMutation(t._injector,f.params))}return{redos:v,undos:m.reverse()}}}return{redos:[],undos:[]}}}))}dispose(){super.dispose(),this._collectEffectMutation.clean()}};B=Fe([H(0,s.Inject(g.SheetInterceptorService)),H(1,s.Inject(g.INumfmtService)),H(2,s.Inject(s.IUniverInstanceService)),H(3,s.Inject(s.Injector)),H(4,s.Optional(N.IEditorBridgeService))],B);function He(e){const{textRuns:t=[],paragraphs:r=[],customRanges:n,customBlocks:i=[]}=e,a=["va"];return!(t.some(o=>!!(o.ts&&Object.keys(o.ts).some(c=>a.includes(c))))||r.some(o=>o.bullet)||r.length>=2||n!=null&&n.length||i.length>0)}const ae=e=>[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:s.DEFAULT_TEXT_FORMAT_EXCEL},"|",{label:"sheet.numfmt.number",pattern:"0"},{label:"sheet.numfmt.percent",pattern:"0.00%"},{label:"sheet.numfmt.scientific",pattern:"0.00E+00"},"|",{label:"sheet.numfmt.accounting",pattern:`"${e}" #,##0.00_);[Red]("${e}"#,##0.00)`},{label:"sheet.numfmt.financialValue",pattern:"#,##0.00;[Red]#,##0.00"},{label:"sheet.numfmt.currency",pattern:`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`},{label:"sheet.numfmt.roundingCurrency",pattern:`"${e}"#,##0;[Red]"${e}"#,##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:""}],Re=e=>({icon:new w.Observable(t=>{const r=e.get(s.LocaleService);return t.next(d.getCurrencySymbolIconByLocale(r.getCurrentLocale()).icon),r.localeChanged$.subscribe(()=>{t.next(d.getCurrencySymbolIconByLocale(r.getCurrentLocale()).icon)})}),id:d.SetCurrencyCommand.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:N.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),We=e=>({icon:"AddDigitsIcon",id:d.AddDecimalCommand.id,title:"sheet.numfmt.addDecimal",tooltip:"sheet.numfmt.addDecimal",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:N.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Be=e=>({icon:"ReduceDigitsIcon",id:d.SubtractDecimalCommand.id,title:"sheet.numfmt.subtractDecimal",tooltip:"sheet.numfmt.subtractDecimal",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:N.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Ve=e=>({icon:"PercentIcon",id:d.SetPercentCommand.id,title:"sheet.numfmt.percent",tooltip:"sheet.numfmt.percent",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:N.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),qe=e=>{const t=e.get(s.IUniverInstanceService),r=e.get(s.ICommandService),n=e.get(s.LocaleService),i=e.get(g.SheetsSelectionsService),a=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id],o=N.deriveStateFromActiveSheet$(t,"",({workbook:p,worksheet:c})=>new w.Observable(u=>w.merge(i.selectionMoveEnd$,s.fromCallback(r.onCommandExecuted.bind(r)).pipe(w.filter(([v])=>a.includes(v.id)))).subscribe(()=>{var m,f;const v=i.getCurrentSelections();if(v&&v[0]){const S=v[0].range,b=S.startRow,h=S.startColumn,P=(f=p.getStyles().get((m=c.getCell(b,h))==null?void 0:m.s))==null?void 0:f.n,I=P==null?void 0:P.pattern,M=d.getCurrencySymbolByLocale(n.getCurrentLocale());let U=n.t("sheet.numfmt.general");if(s.isDefaultFormat(I)){u.next(U);return}if(I){const x=ae(M).filter(O=>typeof O=="object"&&O.pattern).find(O=>s.isPatternEqualWithoutDecimal(I,O.pattern));x&&typeof x=="object"&&x.pattern?U=n.t(x.label):U=n.t("sheet.numfmt.moreFmt")}u.next(U)}})));return{label:oe,id:j.id,tooltip:"sheet.numfmt.title",type:_.MenuItemType.SELECTOR,slot:!0,selections:[{label:{name:ce,hoverable:!1,selectable:!1}}],value$:o,hidden$:_.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:N.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetSetCellStylePermission,g.WorksheetEditPermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}},oe="sheet.numfmt.moreNumfmtType",ce="sheet.numfmt.moreNumfmtType.options";function Ge(e){const{value:t}=e,r=_.useDependency(s.LocaleService),n=t!=null?t:r.t("sheet.numfmt.general");return l.jsx("span",{className:"univer-text-sm",children:n})}function Ke(){const e=_.useDependency(s.ICommandService),t=_.useDependency(s.LocaleService),r=_.useDependency(_.ILayoutService),n=_.useDependency(d.SheetsNumfmtCellContentController),i=_.useDependency(g.SheetsSelectionsService),a=u=>{const v=i.getCurrentLastSelection();if(!v)return;const m=v.range,f=[];s.Range.foreach(m,(S,b)=>{u?f.push({row:S,col:b,pattern:u,type:d.getPatternType(u)}):f.push({row:S,col:b})}),e.executeCommand(d.SetNumfmtCommand.id,{values:f}),r.focus()},o=y.useMemo(()=>{const u=d.localeCurrencySymbolMap.get(t.getCurrentLocale());return ae(u)},[t]),p=u=>{if(u===0)a(null);else if(u===o.length-1)e.executeCommand(j.id),r.focus();else{const v=o[u];v.pattern&&a(v.pattern)}},c=1220;return l.jsx("div",{className:"univer-grid univer-gap-1 univer-p-1.5",children:o.map((u,v)=>u==="|"?l.jsx(E.Separator,{},v):l.jsxs("div",{className:"univer-flex univer-h-7 univer-items-center univer-justify-between univer-gap-6 univer-rounded univer-px-2 univer-text-sm hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",onClick:()=>p(v),children:[l.jsx("span",{children:t.t(u.label)}),l.jsx("span",{className:"univer-text-xs univer-text-gray-500",children:u.pattern?d.getPatternPreview(u.pattern||"",c,n.locale).result.trim():""})]},v))})}const Ye={[_.RibbonStartGroup.LAYOUT]:{[j.id]:{order:9,menuItemFactory:qe},[d.SetPercentCommand.id]:{order:9.1,menuItemFactory:Ve},[d.SetCurrencyCommand.id]:{order:9.2,menuItemFactory:Re},[d.AddDecimalCommand.id]:{order:9.3,menuItemFactory:We},[d.SubtractDecimalCommand.id]:{order:9.4,menuItemFactory:Be}}};var Ze=Object.getOwnPropertyDescriptor,ze=(e,t,r,n)=>{for(var i=n>1?void 0:n?Ze(t,r):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=o(i)||i);return i},le=(e,t)=>(r,n)=>t(r,n,e);let V=class extends s.Disposable{constructor(e,t){super(),this._componentManager=e,this._menuManagerService=t,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(Ye),[[oe,Ge],[ce,Ke]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};V=ze([le(0,s.Inject(_.ComponentManager)),le(1,_.IMenuManagerService)],V);var Xe=Object.defineProperty,Je=Object.getOwnPropertyDescriptor,Qe=(e,t,r)=>t in e?Xe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,et=(e,t,r,n)=>{for(var i=n>1?void 0:n?Je(t,r):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=o(i)||i);return i},J=(e,t)=>(r,n)=>t(r,n,e),ue=(e,t,r)=>Qe(e,typeof t!="symbol"?t+"":t,r);const tt="SHEET_NUMFMT_UI_PLUGIN";C.UniverSheetsNumfmtUIPlugin=class extends s.Plugin{constructor(t=ee,r,n,i){super(),this._config=t,this._injector=r,this._configService=n,this._renderManagerService=i;const{menu:a,...o}=s.merge({},ee,this._config);a&&this._configService.setConfig("menu",a,{merge:!0}),this._configService.setConfig("sheets-numfmt-ui.config",o)}onStarting(){s.registerDependencies(this._injector,[[A],[B],[F],[V]])}onRendered(){this._registerRenderModules(),s.touchDependencies(this._injector,[[A],[B],[V]])}_registerRenderModules(){[[K]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(s.UniverInstanceType.UNIVER_SHEET,r))})}},ue(C.UniverSheetsNumfmtUIPlugin,"pluginName",tt),ue(C.UniverSheetsNumfmtUIPlugin,"type",s.UniverInstanceType.UNIVER_SHEET),C.UniverSheetsNumfmtUIPlugin=et([s.DependentOn(N.UniverSheetsUIPlugin,d.UniverSheetsNumfmtPlugin),J(1,s.Inject(s.Injector)),J(2,s.IConfigService),J(3,k.IRenderManagerService)],C.UniverSheetsNumfmtUIPlugin),Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(C,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/sheets-numfmt"),require("@univerjs/sheets-ui"),require("@univerjs/sheets"),require("@univerjs/ui"),require("rxjs"),require("rxjs/operators"),require("react/jsx-runtime"),require("react"),require("@univerjs/design"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","@univerjs/sheets-numfmt","@univerjs/sheets-ui","@univerjs/sheets","@univerjs/ui","rxjs","rxjs/operators","react/jsx-runtime","react","@univerjs/design","@univerjs/engine-formula"],s):(C=typeof globalThis<"u"?globalThis:C||self,s(C.UniverSheetsNumfmtUi={},C.UniverCore,C.UniverEngineRender,C.UniverSheetsNumfmt,C.UniverSheetsUi,C.UniverSheets,C.UniverUi,C.rxjs,C.rxjs.operators,C.React,C.React,C.UniverDesign,C.UniverEngineFormula))})(this,(function(C,s,k,d,N,g,_,w,W,l,y,E,me){"use strict";var it=Object.defineProperty;var st=(C,s,k)=>s in C?it(C,s,{enumerable:!0,configurable:!0,writable:!0,value:k}):C[s]=k;var q=(C,s,k)=>st(C,typeof s!="symbol"?s+"":s,k);const ee={};var de=Object.getOwnPropertyDescriptor,ve=(e,t,r,n)=>{for(var i=n>1?void 0:n?de(t,r):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=o(i)||i);return i},$=(e,t)=>(r,n)=>t(r,n,e);const G="SHEET_NUMFMT_ALERT";let K=class extends s.Disposable{constructor(e,t,r,n,i,a,o){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=r,this._localeService=n,this._zenZoneService=i,this._numfmtService=a,this._configService=o,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(w.debounceTime(100)).subscribe(e=>{var t,r;if(e){const n=e.location,i=this._context.unit,a=i.getActiveSheet();if(!a)return this._hideAlert();const o=n.unitId,p=n.subUnitId;let c;const u=a.getCell(n.row,n.col);if(u!=null&&u.s){const v=i.getStyles().get(u.s);v!=null&&v.n&&(c=v.n)}if(c||(c=this._numfmtService.getValue(o,p,n.row,n.col)),!c){this._hideAlert();return}if(s.isTextFormat(c.pattern)&&s.Tools.isDefine(u==null?void 0:u.v)&&s.isRealNum(u.v)){if((t=this._configService.getConfig(d.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY))!=null&&t.disableTextFormatAlert)return;const v=this._cellAlertManagerService.currentAlert.get(G),m=(r=v==null?void 0:v.alert)==null?void 0:r.location;if(m&&m.row===n.row&&m.col===n.col&&m.subUnitId===n.subUnitId&&m.unitId===n.unitId){this._hideAlert();return}this._cellAlertManagerService.showAlert({type:N.CellAlertType.ERROR,title:this._localeService.t("info.error"),message:this._localeService.t("info.forceStringInfo"),location:n,width:200,height:74,key:G});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(G)}};K=ve([$(1,s.Inject(N.HoverManagerService)),$(2,s.Inject(N.CellAlertManagerService)),$(3,s.Inject(s.LocaleService)),$(4,_.IZenZoneService),$(5,s.Inject(g.INumfmtService)),$(6,s.IConfigService)],K);const Y={id:"sheet.operation.close.numfmt.panel",type:s.CommandType.OPERATION,handler:()=>!0},j={id:"sheet.operation.open.numfmt.panel",type:s.CommandType.OPERATION,handler:e=>(e.get(A).openPanel(),!0)};var pe=Object.getOwnPropertyDescriptor,he=(e,t,r,n)=>{for(var i=n>1?void 0:n?pe(t,r):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=o(i)||i);return i},fe=(e,t)=>(r,n)=>t(r,n,e);const Z=y.createContext([]);let F=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,o,p)=>{const c=p.length;return{value:a,priority:c-o}});return t.sort((a,o)=>{var u,v;const p=((u=i.find(m=>m.value===a))==null?void 0:u.priority)||-1;return(((v=i.find(m=>m.value===o))==null?void 0:v.priority)||-1)-p})}return n||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};F=he([fe(0,s.Inject(s.ILocalStorageService))],F);const te="numfmtCurrency",ge=e=>{const t=_.useDependency(F),[r,n]=y.useState(d.currencySymbols);return y.useEffect(()=>{t.addHabit("numfmtCurrency",[]).then(()=>{t.getHabit(te,[...d.currencySymbols]).then(a=>{n(a),e&&e(a)})})},[]),{userHabitCurrency:r,mark:a=>{t.markHabit(te,a)}}},Se=()=>{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({})}},ye=e=>!!d.getCurrencyType(e)&&e.startsWith("_("),_e=e=>{const{defaultPattern:t,action:r,onChange:n}=e,[i,a]=y.useState(()=>d.getDecimalFromPattern(t||"",2)),o=y.useContext(Z),[p,c]=y.useState(()=>d.getCurrencyType(t)||o[0]),u=y.useMemo(()=>o.map(b=>({label:b,value:b})),[]),m=_.useDependency(s.LocaleService).t;r.current=()=>d.setPatternDecimal(`_("${p}"* #,##0${i>0?".0":""}_)`,i);const f=b=>{c(b),n(d.setPatternDecimal(`_("${b}"* #,##0${i>0?".0":""}_)`,i))},S=b=>{const h=b||0;a(h),n(d.setPatternDecimal(`_("${p}"* #,##0${h>0?".0":""}_)`,h))};return l.jsxs("div",{children:[l.jsxs("div",{className:"univer-mt-4 univer-flex univer-justify-between",children:[l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2 univer-w-32",children:l.jsx(E.InputNumber,{value:i,step:1,precision:0,max:20,min:0,onChange:S})})]}),l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.currencyType")}),l.jsx("div",{className:"univer-mt-2 univer-w-36",children:l.jsx(E.Select,{options:u,value:p,onChange:f})})]})]}),l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.accountingDes")})]})},Ce=e=>!!d.getCurrencyType(e)&&!e.startsWith("_("),be=e=>{const r=_.useDependency(s.LocaleService).t,n=y.useContext(Z),[i,a]=y.useState(()=>d.getCurrencyType(e.defaultPattern)||n[0]),[o,p]=y.useState(()=>d.getDecimalFromPattern(e.defaultPattern||"",2)),[c,u]=y.useState(()=>{var I;const h=d.getCurrencyFormatOptions(i);return((I=h.find(M=>s.isPatternEqualWithoutDecimal(M.value,e.defaultPattern)))==null?void 0:I.value)||h[0].value}),v=y.useMemo(()=>d.getCurrencyFormatOptions(i),[i]),m=y.useMemo(()=>n.map(h=>({label:h,value:h})),[n]);e.action.current=()=>d.setPatternDecimal(c,o);const f=h=>{if(h===void 0)return;a(h);const P=d.getCurrencyFormatOptions(h)[0].value;u(P),e.onChange(d.setPatternDecimal(P,o))},S=h=>{h!==void 0&&(u(h),e.onChange(d.setPatternDecimal(h,o)))},b=h=>{p(h||0),e.onChange(d.setPatternDecimal(c,h||0))};return l.jsxs("div",{children:[l.jsxs("div",{className:"univer-mt-4 univer-flex univer-justify-between",children:[l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:r("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2 univer-w-32",children:l.jsx(E.InputNumber,{value:o,max:20,min:0,onChange:b})})]}),l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:r("sheet.numfmt.currencyType")}),l.jsx("div",{className:"univer-mt-2 univer-w-36",children:l.jsx(E.Select,{value:i,options:m,onChange:f})})]})]}),l.jsx("div",{className:"label univer-mt-4",children:r("sheet.numfmt.negType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(E.SelectList,{value:c,options:v,onChange:S})}),l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:r("sheet.numfmt.currencyDes")})]})};function ne({ref:e,...t}){const{icon:r,id:n,className:i,extend:a,...o}=t,p=`univerjs-icon univerjs-icon-${n} ${i||""}`.trim(),c=y.useRef(`_${Ee()}`);return re(r,`${n}`,{defIds:r.defIds,idSuffix:c.current},{ref:e,className:p,...o},a)}function re(e,t,r,n,i){return y.createElement(e.tag,{key:t,...Ie(e,r,i),...n},(Te(e,r).children||[]).map((a,o)=>re(a,`${t}-${e.tag}-${o}`,r,void 0,i)))}function Ie(e,t,r){const n={...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(([a,o])=>{a==="mask"&&typeof o=="string"&&(n[a]=o.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});const{defIds:i}=t;return!i||i.length===0||(e.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(([a,o])=>{typeof o=="string"&&(n[a]=o.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))})),n}function Te(e,t){var n;const{defIds:r}=t;return!r||r.length===0?e:e.tag==="defs"&&((n=e.children)!=null&&n.length)?{...e,children:e.children.map(i=>typeof i.attrs.id=="string"&&r&&r.includes(i.attrs.id)?{...i,attrs:{...i.attrs,id:i.attrs.id+t.idSuffix}}:i)}:e}function Ee(){return Math.random().toString(36).substring(2,8)}ne.displayName="UniverIcon";const Pe={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",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"}}]},ie=y.forwardRef(function(t,r){return y.createElement(ne,Object.assign({},t,{id:"check-mark-icon",ref:r,icon:Pe}))});ie.displayName="CheckMarkIcon";const z="customFormat",X="numfmt_custom_pattern";function Me(e){const{defaultPattern:t,action:r,onChange:n}=e,i=_.useDependency(F),a=_.useDependency(s.ILocalStorageService),o=_.useDependency(s.LocaleService),[p,c]=y.useState(t);r.current=()=>(i.markHabit(z,p),a.getItem(X).then((S=[])=>{const b=[...new Set([p,...S||[]])].splice(0,10).filter(h=>!!h);a.setItem(X,b)}),p);const[u,v]=y.useState([]);y.useEffect(()=>{a.getItem(X).then(S=>{const b=[...d.CURRENCYFORMAT.map(h=>h.suffix("$")),...d.DATEFMTLISG.map(h=>h.suffix),...d.NUMBERFORMAT.map(h=>h.suffix)];b.push(...S||[]),i.addHabit(z,[]).finally(()=>{i.getHabit(z,b).then(h=>{v([...new Set(h)])})})})},[]);const m=S=>{c(S),n(S)},f=()=>{n(p)};return l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:o.t("sheet.numfmt.customFormat")}),l.jsx(E.Input,{placeholder:o.t("sheet.numfmt.customFormat"),onBlur:f,value:p,onChange:c,className:"univer-mt-2 univer-w-full"}),l.jsx("div",{className:E.clsx("univer-mt-2 univer-max-h-[400px] univer-overflow-auto univer-rounded-lg univer-p-2",E.borderClassName),children:u.map(S=>l.jsxs("div",{onClick:()=>m(S),className:"univer-flex univer-cursor-pointer univer-items-center univer-gap-1.5 univer-py-1.5 univer-text-sm",children:[l.jsx("div",{className:"univer-flex univer-w-4 univer-items-center univer-text-primary-600",children:p===S&&l.jsx(ie,{})}),l.jsx("div",{children:S})]},S))}),l.jsx("div",{className:"univer-mt-3 univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200",children:o.t("sheet.numfmt.customFormatDes")})]})}const Ne=e=>{const t=s.numfmt.getFormatInfo(e);return d.getDateFormatOptions().map(r=>r.value).includes(e)||["date","datetime","time"].includes(t.type)};function De(e){const{onChange:t,defaultPattern:r}=e,n=y.useMemo(d.getDateFormatOptions,[]),i=_.useDependency(s.LocaleService),[a,o]=y.useState(()=>{if(r){const c=n.find(u=>u.value===r);if(c)return c.value}return n[0].value});e.action.current=()=>a;const p=c=>{c!==void 0&&(o(c),t(c))};return l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:i.t("sheet.numfmt.dateType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(E.SelectList,{value:a,options:n,onChange:p})}),l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:i.t("sheet.numfmt.dateDes")})]})}const we=e=>!e,Ue=e=>{const r=_.useDependency(s.LocaleService).t;return e.action.current=()=>"",l.jsx("div",{children:l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:r("sheet.numfmt.generalDes")})})},xe=e=>d.getNumberFormatOptions().some(t=>s.isPatternEqualWithoutDecimal(t.value,e));function Oe(e){const t=_.useDependency(s.LocaleService),r=y.useMemo(d.getNumberFormatOptions,[]),[n,i]=y.useState(()=>d.getDecimalFromPattern(e.defaultPattern||"",0)),[a,o]=y.useState(()=>{const m=r.find(f=>s.isPatternEqualWithoutDecimal(f.value,e.defaultPattern||""));return(m==null?void 0:m.value)||r[0].value}),p=y.useMemo(()=>d.setPatternDecimal(a,Number(n||0)),[a,n]),c=y.useMemo(()=>!d.isPatternHasDecimal(a),[a]),u=m=>{i(m||0),e.onChange(d.setPatternDecimal(a,Number(m||0)))},v=m=>{m!==void 0&&(i(d.getDecimalFromPattern(m,0)),o(m),e.onChange(m))};return e.action.current=()=>p,l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:t.t("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(E.InputNumber,{disabled:c,value:n,max:20,min:0,onChange:u})}),l.jsxs("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:[" ",t.t("sheet.numfmt.negType")]}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(E.SelectList,{onChange:v,options:r,value:a})}),l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:t.t("sheet.numfmt.thousandthPercentileDes")})]})}const ke=e=>{const{defaultValue:t,defaultPattern:r,row:n,col:i}=e.value,a=_.useDependency(s.LocaleService),o=y.useRef(()=>""),p=a.t,c=Se(),u=y.useMemo(()=>[{label:"sheet.numfmt.general",component:Ue},{label:"sheet.numfmt.accounting",component:_e},{label:"sheet.numfmt.currency",component:be},{label:"sheet.numfmt.date",component:De},{label:"sheet.numfmt.thousandthPercentile",component:Oe},{label:"sheet.numfmt.customFormat",component:Me}].map(T=>({...T,label:p(T.label)})),[]),[v,m]=y.useState(I),[f,S]=y.useState(()=>`${n}_${i}`),{mark:b,userHabitCurrency:h}=ge(()=>S(`${n}_${i}_userCurrency'`)),P=y.useMemo(()=>{var T;return(T=u.find(L=>L.label===v))==null?void 0:T.component},[v]);function I(){return[we,ye,Ce,Ne,xe].reduce((L,nt,rt)=>L||(nt(r)?u[rt].label:""),"")||u[0].label}const M=u.map(T=>({label:T.label,value:T.label})),U=T=>{m(T),c(()=>e.onChange({type:"change",value:o.current()||""}))},x=y.useCallback(T=>{e.onChange({type:"change",value:T})},[]),O=()=>{const T=o.current()||"",L=d.getCurrencyType(T);L&&b(L),e.onChange({type:"confirm",value:T})},R=()=>{e.onChange({type:"cancel",value:""})},Q={onChange:x,defaultValue:t,defaultPattern:r,action:o};return y.useEffect(()=>{m(I()),S(`${n}_${i}`)},[n,i]),l.jsxs("div",{className:E.clsx("univer-flex univer-h-full univer-flex-col univer-justify-between univer-overflow-y-auto univer-pb-5",E.scrollbarClassName),children:[l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-3.5 univer-text-sm univer-text-gray-400",children:p("sheet.numfmt.numfmtType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(E.Select,{className:"univer-w-full",value:v,options:M,onChange:U})}),l.jsx("div",{children:P&&l.jsx(Z.Provider,{value:h,children:y.createElement(P,{...Q,key:f})})})]}),l.jsxs("div",{className:"univer-mb-5 univer-mt-3.5 univer-flex univer-justify-end",children:[l.jsx(E.Button,{onClick:R,className:"univer-mr-3",children:p("sheet.numfmt.cancel")}),l.jsx(E.Button,{variant:"primary",onClick:O,children:p("sheet.numfmt.confirm")})]})]})};var $e=Object.getOwnPropertyDescriptor,Le=(e,t,r,n)=>{for(var i=n>1?void 0:n?$e(t,r):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=o(i)||i);return i},D=(e,t)=>(r,n)=>t(r,n,e);const se="SHEET_NUMFMT_PANEL";let A=class extends s.Disposable{constructor(t,r,n,i,a,o,p,c,u,v,m){super();q(this,"_previewPattern","");q(this,"_sidebarDisposable",null);this._sheetInterceptorService=t,this._themeService=r,this._univerInstanceService=n,this._commandService=i,this._selectionManagerService=a,this._renderManagerService=o,this._numfmtService=p,this._componentManager=c,this._sidebarService=u,this._localeService=v,this._sheetsNumfmtCellContentController=m,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener(),this._initNumfmtLocalChange()}_initNumfmtLocalChange(){this.disposeWithMe(w.merge(this._sheetsNumfmtCellContentController.locale$,this._localeService.currentLocale$).subscribe(()=>{this._forceUpdate()}))}openPanel(){var P;const t=this._sidebarService,r=this._selectionManagerService,n=this._commandService,i=this._univerInstanceService,a=this._numfmtService,o=this._localeService,c=(((P=r.getCurrentSelections())==null?void 0:P.map(I=>I.range))||[])[0];if(!c)return!1;const u=i.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),v=u.getActiveSheet();if(!v)return!1;const m=v.getCellRaw(c.startRow,c.startColumn),f=a.getValue(u.getUnitId(),v.getSheetId(),c.startRow,c.startColumn);let S="";f&&(S=f.pattern);const b=(m==null?void 0:m.t)===s.CellValueType.NUMBER?m.v:12345678,h={onChange:I=>{var M;if(I.type==="change")this._previewPattern=I.value,this._forceUpdate();else if(I.type==="confirm"){const U=((M=r.getCurrentSelections())==null?void 0:M.map(R=>R.range))||[],x={values:[]},O=d.getPatternType(I.value);U.forEach(R=>{s.Range.foreach(R,(Q,T)=>{x.values.push({row:Q,col:T,pattern:I.value,type:O})})}),n.executeCommand(d.SetNumfmtCommand.id,x),t.close()}else I.type==="cancel"&&t.close()},value:{defaultPattern:S,defaultValue:b,row:c.startRow,col:c.startColumn}};return this._sidebarDisposable=t.open({header:{title:o.t("sheet.numfmt.title")},children:{label:se,...h},onClose:()=>{this._forceUpdate(),n.executeCommand(Y.id)}}),!0}_forceUpdate(t){var n;const r=this._renderManagerService.getRenderById(t!=null?t:this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET).getUnitId());r==null||r.with(N.SheetSkeletonManagerService).reCalculate(),(n=r==null?void 0:r.mainComponent)==null||n.makeDirty()}_initCommands(){[j,Y].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initPanel(){this.disposeWithMe(this._componentManager.register(se,ke))}_initRealTimeRenderingInterceptor(){const t=new w.Observable(n=>{this._commandService.onCommandExecuted(i=>{i.id===j.id&&n.next(!0),i.id===Y.id&&n.next(!1)})}),r=w.combineLatest([t,this._selectionManagerService.selectionMoveEnd$.pipe(W.map(n=>n?n.map(i=>i.range):[]))]);this.disposeWithMe(s.toDisposable(r.pipe(W.switchMap(([n,i])=>new w.Observable(a=>{const o=new s.DisposableCollection;return n&&i.length&&a.next({selectionRanges:i,disposableCollection:o}),()=>{o.dispose()}})),W.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:n,selectionRanges:i})=>{var o,p;const a=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);this.openPanel(),n.add(this._sheetInterceptorService.intercept(g.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,effect:s.InterceptorEffectEnum.Value|s.InterceptorEffectEnum.Style,handler:(c,u,v)=>{var b;const{row:m,col:f}=u,S=v(c)||{};if(i.find(h=>h.startColumn<=f&&h.endColumn>=f&&h.startRow<=m&&h.endRow>=m)){const h=u.worksheet.getCellRaw(m,f),P=h==null?void 0:h.v,I=h==null?void 0:h.t;if(P==null||I!==s.CellValueType.NUMBER||this._previewPattern===null)return S;const M=d.getPatternPreviewIgnoreGeneral(this._previewPattern,P,this._sheetsNumfmtCellContentController.locale);if(M.color){const U=(b=this._themeService.getColorFromTheme(`${M.color}.500`))!=null?b:M.color;return{...S,v:M.result,t:s.CellValueType.STRING,s:{cl:{rgb:U}}}}return{...S,v:M.result,t:s.CellValueType.STRING}}return S}})),(p=(o=this._renderManagerService.getRenderById(a.getUnitId()))==null?void 0:o.mainComponent)==null||p.makeDirty()})))}_commandExecutedListener(){const t=[g.RemoveNumfmtMutation.id,g.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(W.debounceTime(16)).subscribe(r=>this._forceUpdate(r)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_SHEET).subscribe(t=>{var r;t||((r=this._sidebarDisposable)==null||r.dispose(),this._sidebarDisposable=null)})}};A=Le([D(0,s.Inject(g.SheetInterceptorService)),D(1,s.Inject(s.ThemeService)),D(2,s.IUniverInstanceService),D(3,s.ICommandService),D(4,s.Inject(g.SheetsSelectionsService)),D(5,k.IRenderManagerService),D(6,g.INumfmtService),D(7,s.Inject(_.ComponentManager)),D(8,_.ISidebarService),D(9,s.Inject(s.LocaleService)),D(10,s.Inject(d.SheetsNumfmtCellContentController))],A);var je=Object.getOwnPropertyDescriptor,Fe=(e,t,r,n)=>{for(var i=n>1?void 0:n?je(t,r):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=o(i)||i);return i},H=(e,t)=>(r,n)=>t(r,n,e);const Ae=()=>{let e=[];return{add:(i,a,o,p,c)=>e.push({unitId:i,subUnitId:a,row:o,col:p,value:c}),getEffects:()=>e,clean:()=>{e=[]}}};let B=class extends s.Disposable{constructor(t,r,n,i,a){super();q(this,"_collectEffectMutation",Ae());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(s.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.BEFORE_CELL_EDIT,{handler:(t,r,n)=>{const i=r.row,a=r.col,o=this._numfmtService.getValue(r.unitId,r.subUnitId,i,a);if(o)switch(d.getPatternType(o.pattern)){case"scientific":case"currency":case"grouped":case"number":{const c=r.worksheet.getCellRaw(i,a);return(c==null?void 0:c.t)===s.CellValueType.NUMBER&&(c==null?void 0:c.v)!==void 0&&c.v!==null&&s.isRealNum(c.v)&&(c.v=me.stripErrorMargin(Number(c.v))),n&&n(c)}default:return n&&n(t)}return n(t)}})))}_initInterceptorEditorEnd(){this.disposeWithMe(s.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.AFTER_CELL_EDIT,{handler:(t,r,n)=>{var u,v,m;if(!(t!=null&&t.v)&&!(t!=null&&t.p))return n(t);this._collectEffectMutation.clean();const i=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col),a=r.worksheet.getCellRaw(r.row,r.col);if(s.isTextFormat(i==null?void 0:i.pattern)||t.t===s.CellValueType.FORCE_STRING)return n(t);const o=(u=t.p)==null?void 0:u.body,p=(m=(v=t==null?void 0:t.p)==null?void 0:v.body)!=null&&m.dataStream?t.p.body.dataStream.replace(/\r\n$/,""):String(t.v),c=s.getNumfmtParseValueFilter(p);if(o)if(He(o)){const{dataStream:f}=o,S=f.replace(/\r\n$/,""),b=Number(S);if(Number.isNaN(b)&&!c)return n(t)}else return n(t);if(c){if(!c.z&&!(i!=null&&i.pattern)&&(a==null?void 0:a.t)!==s.CellValueType.STRING&&(a==null?void 0:a.t)!==s.CellValueType.FORCE_STRING&&s.willLoseNumericPrecision(p))return n({...t,p:void 0,v:p,t:s.CellValueType.FORCE_STRING});c.z&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:c.z});const f=Number(c.v);return n({...t,p:void 0,v:f,t:s.CellValueType.NUMBER})}return n(t)}})))}_initInterceptorCommands(){const t=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(r){var n;switch(r.id){case g.SetRangeValuesCommand.id:{const i=t._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),a=i.getUnitId(),o=(n=i.getActiveSheet())==null?void 0:n.getSheetId();if(!o)return{redos:[],undos:[]};const p=t._collectEffectMutation.getEffects();if(t._collectEffectMutation.clean(),!p.length)return{redos:[],undos:[]};const c=p.filter(f=>{var S;return!!((S=f.value)!=null&&S.pattern)}).map(f=>({row:f.row,col:f.col,pattern:f.value.pattern})),u=p.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=[],m=[];if(c.length){const f={id:g.SetNumfmtMutation.id,params:g.transformCellsToRange(a,o,c)};v.push(f),m.push(...g.factorySetNumfmtUndoMutation(t._injector,f.params))}if(u.length){const f={id:g.RemoveNumfmtMutation.id,params:{unitId:a,subUnitId:o,ranges:u}};v.push(f),m.push(...g.factoryRemoveNumfmtUndoMutation(t._injector,f.params))}return{redos:v,undos:m.reverse()}}}return{redos:[],undos:[]}}}))}dispose(){super.dispose(),this._collectEffectMutation.clean()}};B=Fe([H(0,s.Inject(g.SheetInterceptorService)),H(1,s.Inject(g.INumfmtService)),H(2,s.Inject(s.IUniverInstanceService)),H(3,s.Inject(s.Injector)),H(4,s.Optional(N.IEditorBridgeService))],B);function He(e){const{textRuns:t=[],paragraphs:r=[],customRanges:n,customBlocks:i=[]}=e,a=["va"];return!(t.some(o=>!!(o.ts&&Object.keys(o.ts).some(c=>a.includes(c))))||r.some(o=>o.bullet)||r.length>=2||n!=null&&n.length||i.length>0)}const ae=e=>[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:s.DEFAULT_TEXT_FORMAT_EXCEL},"|",{label:"sheet.numfmt.number",pattern:"0"},{label:"sheet.numfmt.percent",pattern:"0.00%"},{label:"sheet.numfmt.scientific",pattern:"0.00E+00"},"|",{label:"sheet.numfmt.accounting",pattern:`"${e}" #,##0.00_);[Red]("${e}"#,##0.00)`},{label:"sheet.numfmt.financialValue",pattern:"#,##0.00;[Red]#,##0.00"},{label:"sheet.numfmt.currency",pattern:`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`},{label:"sheet.numfmt.roundingCurrency",pattern:`"${e}"#,##0;[Red]"${e}"#,##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:""}],Re=e=>({icon:new w.Observable(t=>{const r=e.get(s.LocaleService);return t.next(d.getCurrencySymbolIconByLocale(r.getCurrentLocale()).icon),r.localeChanged$.subscribe(()=>{t.next(d.getCurrencySymbolIconByLocale(r.getCurrentLocale()).icon)})}),id:d.SetCurrencyCommand.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:N.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),We=e=>({icon:"AddDigitsIcon",id:d.AddDecimalCommand.id,title:"sheet.numfmt.addDecimal",tooltip:"sheet.numfmt.addDecimal",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:N.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Be=e=>({icon:"ReduceDigitsIcon",id:d.SubtractDecimalCommand.id,title:"sheet.numfmt.subtractDecimal",tooltip:"sheet.numfmt.subtractDecimal",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:N.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Ve=e=>({icon:"PercentIcon",id:d.SetPercentCommand.id,title:"sheet.numfmt.percent",tooltip:"sheet.numfmt.percent",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:N.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),qe=e=>{const t=e.get(s.IUniverInstanceService),r=e.get(s.ICommandService),n=e.get(s.LocaleService),i=e.get(g.SheetsSelectionsService),a=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id],o=N.deriveStateFromActiveSheet$(t,"",({workbook:p,worksheet:c})=>new w.Observable(u=>w.merge(i.selectionMoveEnd$,s.fromCallback(r.onCommandExecuted.bind(r)).pipe(w.filter(([v])=>a.includes(v.id)))).subscribe(()=>{var m,f;const v=i.getCurrentSelections();if(v&&v[0]){const S=v[0].range,b=S.startRow,h=S.startColumn,P=(f=p.getStyles().get((m=c.getCell(b,h))==null?void 0:m.s))==null?void 0:f.n,I=P==null?void 0:P.pattern,M=d.getCurrencySymbolByLocale(n.getCurrentLocale());let U=n.t("sheet.numfmt.general");if(s.isDefaultFormat(I)){u.next(U);return}if(I){const x=ae(M).filter(O=>typeof O=="object"&&O.pattern).find(O=>s.isPatternEqualWithoutDecimal(I,O.pattern));x&&typeof x=="object"&&x.pattern?U=n.t(x.label):U=n.t("sheet.numfmt.moreFmt")}u.next(U)}})));return{label:oe,id:j.id,tooltip:"sheet.numfmt.title",type:_.MenuItemType.SELECTOR,slot:!0,selections:[{label:{name:ce,hoverable:!1,selectable:!1}}],value$:o,hidden$:_.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:N.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetSetCellStylePermission,g.WorksheetEditPermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}},oe="sheet.numfmt.moreNumfmtType",ce="sheet.numfmt.moreNumfmtType.options";function Ge(e){const{value:t}=e,r=_.useDependency(s.LocaleService),n=t!=null?t:r.t("sheet.numfmt.general");return l.jsx("span",{className:"univer-text-sm",children:n})}function Ke(){const e=_.useDependency(s.ICommandService),t=_.useDependency(s.LocaleService),r=_.useDependency(_.ILayoutService),n=_.useDependency(d.SheetsNumfmtCellContentController),i=_.useDependency(g.SheetsSelectionsService),a=u=>{const v=i.getCurrentLastSelection();if(!v)return;const m=v.range,f=[];s.Range.foreach(m,(S,b)=>{u?f.push({row:S,col:b,pattern:u,type:d.getPatternType(u)}):f.push({row:S,col:b})}),e.executeCommand(d.SetNumfmtCommand.id,{values:f}),r.focus()},o=y.useMemo(()=>{const u=d.localeCurrencySymbolMap.get(t.getCurrentLocale());return ae(u)},[t]),p=u=>{if(u===0)a(null);else if(u===o.length-1)e.executeCommand(j.id),r.focus();else{const v=o[u];v.pattern&&a(v.pattern)}},c=1220;return l.jsx("div",{className:"univer-grid univer-gap-1 univer-p-1.5",children:o.map((u,v)=>u==="|"?l.jsx(E.Separator,{},v):l.jsxs("div",{className:"univer-flex univer-h-7 univer-items-center univer-justify-between univer-gap-6 univer-rounded univer-px-2 univer-text-sm hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",onClick:()=>p(v),children:[l.jsx("span",{children:t.t(u.label)}),l.jsx("span",{className:"univer-text-xs univer-text-gray-500 dark:!univer-text-gray-400",children:u.pattern?d.getPatternPreview(u.pattern||"",c,n.locale).result.trim():""})]},v))})}const Ye={[_.RibbonStartGroup.LAYOUT]:{[j.id]:{order:9,menuItemFactory:qe},[d.SetPercentCommand.id]:{order:9.1,menuItemFactory:Ve},[d.SetCurrencyCommand.id]:{order:9.2,menuItemFactory:Re},[d.AddDecimalCommand.id]:{order:9.3,menuItemFactory:We},[d.SubtractDecimalCommand.id]:{order:9.4,menuItemFactory:Be}}};var Ze=Object.getOwnPropertyDescriptor,ze=(e,t,r,n)=>{for(var i=n>1?void 0:n?Ze(t,r):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=o(i)||i);return i},le=(e,t)=>(r,n)=>t(r,n,e);let V=class extends s.Disposable{constructor(e,t){super(),this._componentManager=e,this._menuManagerService=t,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(Ye),[[oe,Ge],[ce,Ke]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};V=ze([le(0,s.Inject(_.ComponentManager)),le(1,_.IMenuManagerService)],V);var Xe=Object.defineProperty,Je=Object.getOwnPropertyDescriptor,Qe=(e,t,r)=>t in e?Xe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,et=(e,t,r,n)=>{for(var i=n>1?void 0:n?Je(t,r):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=o(i)||i);return i},J=(e,t)=>(r,n)=>t(r,n,e),ue=(e,t,r)=>Qe(e,typeof t!="symbol"?t+"":t,r);const tt="SHEET_NUMFMT_UI_PLUGIN";C.UniverSheetsNumfmtUIPlugin=class extends s.Plugin{constructor(t=ee,r,n,i){super(),this._config=t,this._injector=r,this._configService=n,this._renderManagerService=i;const{menu:a,...o}=s.merge({},ee,this._config);a&&this._configService.setConfig("menu",a,{merge:!0}),this._configService.setConfig("sheets-numfmt-ui.config",o)}onStarting(){s.registerDependencies(this._injector,[[A],[B],[F],[V]])}onRendered(){this._registerRenderModules(),s.touchDependencies(this._injector,[[A],[B],[V]])}_registerRenderModules(){[[K]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(s.UniverInstanceType.UNIVER_SHEET,r))})}},ue(C.UniverSheetsNumfmtUIPlugin,"pluginName",tt),ue(C.UniverSheetsNumfmtUIPlugin,"type",s.UniverInstanceType.UNIVER_SHEET),C.UniverSheetsNumfmtUIPlugin=et([s.DependentOn(N.UniverSheetsUIPlugin,d.UniverSheetsNumfmtPlugin),J(1,s.Inject(s.Injector)),J(2,s.IConfigService),J(3,k.IRenderManagerService)],C.UniverSheetsNumfmtUIPlugin),Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-numfmt-ui",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "private": false,
5
5
  "description": "UniverSheet numfmt plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -54,15 +54,15 @@
54
54
  "rxjs": ">=7.0.0"
55
55
  },
56
56
  "dependencies": {
57
- "@univerjs/icons": "^1.0.2",
58
- "@univerjs/core": "0.14.0",
59
- "@univerjs/design": "0.14.0",
60
- "@univerjs/engine-formula": "0.14.0",
61
- "@univerjs/engine-render": "0.14.0",
62
- "@univerjs/sheets": "0.14.0",
63
- "@univerjs/sheets-numfmt": "0.14.0",
64
- "@univerjs/sheets-ui": "0.14.0",
65
- "@univerjs/ui": "0.14.0"
57
+ "@univerjs/icons": "^1.1.0",
58
+ "@univerjs/core": "0.15.0",
59
+ "@univerjs/design": "0.15.0",
60
+ "@univerjs/engine-formula": "0.15.0",
61
+ "@univerjs/sheets": "0.15.0",
62
+ "@univerjs/engine-render": "0.15.0",
63
+ "@univerjs/sheets-numfmt": "0.15.0",
64
+ "@univerjs/sheets-ui": "0.15.0",
65
+ "@univerjs/ui": "0.15.0"
66
66
  },
67
67
  "devDependencies": {
68
68
  "postcss": "^8.5.6",
@@ -70,9 +70,9 @@
70
70
  "rxjs": "^7.8.2",
71
71
  "tailwindcss": "3.4.18",
72
72
  "typescript": "^5.9.3",
73
- "vite": "^7.2.7",
74
- "vitest": "^4.0.15",
75
- "@univerjs-infra/shared": "0.14.0"
73
+ "vite": "^7.3.0",
74
+ "vitest": "^4.0.16",
75
+ "@univerjs-infra/shared": "0.15.0"
76
76
  },
77
77
  "scripts": {
78
78
  "test": "vitest run",