@univerjs/sheets-numfmt-ui 0.5.2 → 0.5.3

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
@@ -6,4 +6,4 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var ee;function ye(){if(ee)return w;ee=1;var t=y,e=Symbol.for("react.element"),r=Symbol.for("react.fragment"),n=Object.prototype.hasOwnProperty,s=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function c(a,l,p){var f,d={},h=null,S=null;p!==void 0&&(h=""+p),l.key!==void 0&&(h=""+l.key),l.ref!==void 0&&(S=l.ref);for(f in l)n.call(l,f)&&!i.hasOwnProperty(f)&&(d[f]=l[f]);if(a&&a.defaultProps)for(f in l=a.defaultProps,l)d[f]===void 0&&(d[f]=l[f]);return{$$typeof:e,type:a,key:h,ref:S,props:d,_owner:s.current}}return w.Fragment=r,w.jsx=c,w.jsxs=c,w}var te;function _e(){return te||(te=1,J.exports=ye()),J.exports}var u=_e(),be=Object.defineProperty,Ce=Object.getOwnPropertyDescriptor,Ie=(t,e,r,n)=>{for(var s=n>1?void 0:n?Ce(e,r):e,i=t.length-1,c;i>=0;i--)(c=t[i])&&(s=(n?c(e,r,s):c(s))||s);return n&&s&&be(e,r,s),s},Pe=(t,e)=>(r,n)=>e(r,n,t);const Z=y.createContext([]);let L=class{constructor(t){this._localStorageService=t}_getKey(t){return`userHabitController_${t}`}async addHabit(t,e){const r=this._getKey(t);return this._localStorageService.getItem(r).then(n=>{n||this._localStorageService.setItem(r,e)})}markHabit(t,e){const r=this._getKey(t);this._localStorageService.getItem(r).then(n=>{if(n){const s=n.findIndex(i=>i===e);s>-1&&n.splice(s,1),n.unshift(e),this._localStorageService.setItem(r,n)}})}async getHabit(t,e){const r=this._getKey(t),n=await this._localStorageService.getItem(r);if(e&&n){const s=n.map((i,c,a)=>{const l=a.length;return{value:i,priority:l-c}});return e.sort((i,c)=>{var p,f;const a=((p=s.find(d=>d.value===i))==null?void 0:p.priority)||-1;return(((f=s.find(d=>d.value===c))==null?void 0:f.priority)||-1)-a})}return n||[]}deleteHabit(t){this._localStorageService.removeItem(t)}};L=Ie([Pe(0,o.Inject(o.ILocalStorageService))],L);const ne="numfmtCurrency",Te=t=>{const e=o.useDependency(L),[r,n]=y.useState(m.currencySymbols);return y.useEffect(()=>{e.addHabit("numfmtCurrency",[]).then(()=>{e.getHabit(ne,[...m.currencySymbols]).then(i=>{n(i),t&&t(i)})})},[]),{userHabitCurrency:r,mark:i=>{e.markHabit(ne,i)}}},Ne=()=>{const t=y.useRef([]),[e,r]=y.useState({});return y.useEffect(()=>{t.current.forEach(s=>{s()}),t.current=[]},[e]),s=>{t.current.push(s),r({})}},Ee=t=>!!m.getCurrencyType(t)&&t.startsWith("_("),xe=t=>{const{defaultPattern:e,action:r,onChange:n}=t,[s,i]=y.useState(()=>m.getDecimalFromPattern(e||"",2)),c=y.useContext(Z),[a,l]=y.useState(()=>m.getCurrencyType(e)||c[0]),p=y.useMemo(()=>c.map(_=>({label:_,value:_})),[]),d=o.useDependency(o.LocaleService).t;r.current=()=>m.setPatternDecimal(`_("${a}"* #,##0${s>0?".0":""}_)`,s);const h=_=>{l(_),n(m.setPatternDecimal(`_("${_}"* #,##0${s>0?".0":""}_)`,s))},S=_=>{const v=_||0;i(v),n(m.setPatternDecimal(`_("${a}"* #,##0${v>0?".0":""}_)`,v))};return u.jsxs("div",{children:[u.jsxs("div",{className:"m-t-16 options",children:[u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:d("sheet.numfmt.decimalLength")}),u.jsx("div",{className:"m-t-8 w-120",children:u.jsx(E.InputNumber,{value:s,max:20,min:0,onChange:S})})]}),u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:d("sheet.numfmt.currencyType")}),u.jsx("div",{className:"m-t-8 w-140",children:u.jsx(E.Select,{onChange:h,options:p,value:a})})]})]}),u.jsx("div",{className:"describe m-t-14",children:d("sheet.numfmt.accountingDes")})]})},Me=t=>!!m.getCurrencyType(t)&&!t.startsWith("_("),je=t=>{const r=o.useDependency(o.LocaleService).t,n=y.useContext(Z),[s,i]=y.useState(()=>m.getCurrencyType(t.defaultPattern)||n[0]),[c,a]=y.useState(()=>m.getDecimalFromPattern(t.defaultPattern||"",2)),[l,p]=y.useState(()=>{var b;const v=m.getCurrencyFormatOptions(s);return((b=v.find(T=>m.isPatternEqualWithoutDecimal(T.value,t.defaultPattern)))==null?void 0:b.value)||v[0].value}),f=y.useMemo(()=>m.getCurrencyFormatOptions(s),[s]),d=y.useMemo(()=>n.map(v=>({label:v,value:v})),[n]);t.action.current=()=>m.setPatternDecimal(l,c);const h=v=>{if(v===void 0)return;i(v);const P=m.getCurrencyFormatOptions(v)[0].value;p(P),t.onChange(m.setPatternDecimal(P,c))},S=v=>{v!==void 0&&(p(v),t.onChange(m.setPatternDecimal(v,c)))},_=v=>{a(v||0),t.onChange(m.setPatternDecimal(l,v||0))};return u.jsxs("div",{children:[u.jsxs("div",{className:"m-t-16 options",children:[u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:r("sheet.numfmt.decimalLength")}),u.jsx("div",{className:"m-t-8 w-120",children:u.jsx(E.InputNumber,{value:c,max:20,min:0,onChange:_})})]}),u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:r("sheet.numfmt.currencyType")}),u.jsx("div",{className:"m-t-8 w-140",children:u.jsx(E.Select,{onChange:h,options:d,value:s})})]})]}),u.jsx("div",{className:"m-t-16 label",children:r("sheet.numfmt.negType")}),u.jsx("div",{className:"m-t-8",children:u.jsx(E.SelectList,{onChange:S,options:f,value:l})}),u.jsx("div",{className:"describe m-t-14",children:r("sheet.numfmt.currencyDes")})]})};var N=function(){return N=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++){e=arguments[r];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s])}return t},N.apply(this,arguments)},De=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,n=Object.getOwnPropertySymbols(t);s<n.length;s++)e.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(t,n[s])&&(r[n[s]]=t[n[s]]);return r},ce=y.forwardRef(function(t,e){var r=t.icon,n=t.id,s=t.className,i=t.extend,c=De(t,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(n," ").concat(s||"").trim(),l=y.useRef("_".concat(Ue()));return ae(r,"".concat(n),{defIds:r.defIds,idSuffix:l.current},N({ref:e,className:a},c),i)});function ae(t,e,r,n,s){return y.createElement(t.tag,N(N({key:e},Re(t,r,s)),n),(Oe(t,r).children||[]).map(function(i,c){return ae(i,"".concat(e,"-").concat(t.tag,"-").concat(c),r,void 0,s)}))}function Re(t,e,r){var n=N({},t.attrs);r!=null&&r.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=r.colorChannel1);var s=e.defIds;return!s||s.length===0||(t.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+e.idSuffix),Object.entries(n).forEach(function(i){var c=i[0],a=i[1];typeof a=="string"&&(n[c]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),n}function Oe(t,e){var r,n=e.defIds;return!n||n.length===0?t:t.tag==="defs"&&(!((r=t.children)===null||r===void 0)&&r.length)?N(N({},t),{children:t.children.map(function(s){return typeof s.attrs.id=="string"&&n&&n.indexOf(s.attrs.id)>-1?N(N({},s),{attrs:N(N({},s.attrs),{id:s.attrs.id+e.idSuffix})}):s})}):t}function Ue(){return Math.random().toString(36).substring(2,8)}ce.displayName="UniverIcon";var we={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},le=y.forwardRef(function(t,e){return y.createElement(ce,Object.assign({},t,{id:"check-mark-single",ref:e,icon:we}))});le.displayName="CheckMarkSingle";const Fe="univer-custom-format-title",$e="univer-custom-format-input",Le="univer-custom-format-history-list",ke="univer-custom-format-history-list-item",He="univer-custom-format-history-list-item-icon-wrap",We="univer-custom-format-des",R={customFormatTitle:Fe,customFormatInput:$e,customFormatHistoryList:Le,customFormatHistoryListItem:ke,customFormatHistoryListItemIconWrap:He,customFormatDes:We},z="customFormat",X="numfmt_custom_pattern";function Ae(t){const{defaultPattern:e,action:r,onChange:n}=t,s=o.useDependency(L),i=o.useDependency(o.ILocalStorageService),c=o.useDependency(o.LocaleService),[a,l]=y.useState(e);r.current=()=>(s.markHabit(z,a),i.getItem(X).then((S=[])=>{const _=[...new Set([a,...S||[]])].splice(0,10).filter(v=>!!v);i.setItem(X,_)}),a);const[p,f]=y.useState([]);y.useEffect(()=>{i.getItem(X).then(S=>{const _=[...m.CURRENCYFORMAT.map(v=>v.suffix("$")),...m.DATEFMTLISG.map(v=>v.suffix),...m.NUMBERFORMAT.map(v=>v.suffix)];_.push(...S||[]),s.addHabit(z,[]).finally(()=>{s.getHabit(z,_).then(v=>{f([...new Set(v)])})})})},[]);const d=S=>{l(S),n(S)},h=()=>{n(a)};return u.jsxs("div",{className:R.customFormat,children:[u.jsx("div",{className:R.customFormatTitle,children:c.t("sheet.numfmt.customFormat")}),u.jsx(E.Input,{placeholder:c.t("sheet.numfmt.customFormat"),onBlur:h,value:a,onChange:l,className:R.customFormatInput}),u.jsx("div",{className:R.customFormatHistoryList,children:p.map(S=>u.jsxs("div",{onClick:()=>d(S),className:R.customFormatHistoryListItem,children:[u.jsx("div",{className:R.customFormatHistoryListItemIconWrap,children:a===S&&u.jsx(le,{})}),u.jsx("div",{children:S})]},S))}),u.jsx("div",{className:R.customFormatDes,children:c.t("sheet.numfmt.customFormatDes")})]})}const Be=t=>{const e=o.numfmt.getInfo(t);return m.getDateFormatOptions().map(r=>r.value).includes(t)||["date","datetime","time"].includes(e.type)},qe=t=>{const e=y.useMemo(m.getDateFormatOptions,[]),n=o.useDependency(o.LocaleService).t,[s,i]=y.useState(()=>{if(t.defaultPattern){const a=e.find(l=>l.value===t.defaultPattern);if(a)return a.value}return e[0].value});t.action.current=()=>s;const c=a=>{a!==void 0&&(i(a),t.onChange(a))};return u.jsxs("div",{children:[u.jsx("div",{className:"m-t-16 label",children:n("sheet.numfmt.dateType")}),u.jsx("div",{className:"m-t-8",children:u.jsx(E.SelectList,{value:s,options:e,onChange:c})}),u.jsx("div",{className:"describe m-t-14",children:n("sheet.numfmt.dateDes")})]})},Ve=t=>!t,Ge=t=>{const r=o.useDependency(o.LocaleService).t;return t.action.current=()=>"",u.jsx("div",{children:u.jsx("div",{className:"describe m-t-14",children:r("sheet.numfmt.generalDes")})})},Ke=t=>m.getNumberFormatOptions().some(e=>m.isPatternEqualWithoutDecimal(e.value,t)),Ye=t=>{const e=o.useDependency(o.LocaleService),r=y.useMemo(m.getNumberFormatOptions,[]),[n,s]=y.useState(()=>m.getDecimalFromPattern(t.defaultPattern||"",0)),[i,c]=y.useState(()=>{const d=r.find(h=>m.isPatternEqualWithoutDecimal(h.value,t.defaultPattern||""));return(d==null?void 0:d.value)||r[0].value}),a=y.useMemo(()=>m.setPatternDecimal(i,Number(n||0)),[i,n]),l=y.useMemo(()=>!m.isPatternHasDecimal(i),[i]),p=d=>{s(d||0),t.onChange(m.setPatternDecimal(i,Number(d||0)))},f=d=>{d!==void 0&&(s(m.getDecimalFromPattern(d,0)),c(d),t.onChange(d))};return t.action.current=()=>a,u.jsxs("div",{children:[u.jsx("div",{className:"m-t-16 label",children:e.t("sheet.numfmt.decimalLength")}),u.jsx("div",{className:"m-t-8",children:u.jsx(E.InputNumber,{disabled:l,value:n,max:20,min:0,onChange:p})}),u.jsxs("div",{className:"m-t-16 label",children:[" ",e.t("sheet.numfmt.negType")]}),u.jsx("div",{className:"m-t-8",children:u.jsx(E.SelectList,{onChange:f,options:r,value:i})}),u.jsx("div",{className:"describe m-t-14",children:e.t("sheet.numfmt.thousandthPercentileDes")})]})},Je=t=>{const{defaultValue:e,defaultPattern:r,row:n,col:s}=t.value,i=o.useDependency(o.LocaleService),c=y.useRef(()=>""),a=i.t,l=Ne(),p=y.useMemo(()=>[{label:"sheet.numfmt.general",component:Ge},{label:"sheet.numfmt.accounting",component:xe},{label:"sheet.numfmt.currency",component:je},{label:"sheet.numfmt.date",component:qe},{label:"sheet.numfmt.thousandthPercentile",component:Ye},{label:"sheet.numfmt.customFormat",component:Ae}].map(C=>({...C,label:a(C.label)})),[]),[f,d]=y.useState(b),[h,S]=y.useState(()=>`${n}_${s}`),{mark:_,userHabitCurrency:v}=Te(()=>S(`${n}_${s}_userCurrency'`)),P=y.useMemo(()=>{var C;return(C=p.find(O=>O.label===f))==null?void 0:C.component},[f]);function b(){return[Ve,Ee,Me,Be,Ke].reduce((O,fe,pe)=>O||(fe(r)?p[pe].label:""),"")||p[0].label}const T=p.map(C=>({label:C.label,value:C.label})),x=C=>{d(C),l(()=>t.onChange({type:"change",value:c.current()||""}))},H=C=>{t.onChange({type:"change",value:C})},G=()=>{const C=c.current()||"",O=m.getCurrencyType(C);O&&_(O),t.onChange({type:"confirm",value:C})},U=()=>{t.onChange({type:"cancel",value:""})},K={onChange:H,defaultValue:e,defaultPattern:r,action:c};return y.useEffect(()=>{d(b()),S(`${n}_${s}`)},[n,s]),u.jsxs("div",{className:"numfmt-panel p-b-20",children:[u.jsxs("div",{children:[u.jsx("div",{className:"label m-t-14",children:a("sheet.numfmt.numfmtType")}),u.jsx("div",{className:"m-t-8",children:u.jsx(E.Select,{onChange:x,options:T,value:f,style:{width:"100%"}})}),u.jsx("div",{children:P&&u.jsx(Z.Provider,{value:v,children:y.createElement(P,{...K,key:h})})})]}),u.jsxs("div",{className:"btn-list m-t-14 m-b-20",children:[u.jsx(E.Button,{size:"small",onClick:U,className:"m-r-12",children:a("sheet.numfmt.cancel")}),u.jsx(E.Button,{type:"primary",size:"small",onClick:G,children:a("sheet.numfmt.confirm")})]})]})};var ze=Object.defineProperty,Xe=Object.getOwnPropertyDescriptor,Ze=(t,e,r,n)=>{for(var s=n>1?void 0:n?Xe(e,r):e,i=t.length-1,c;i>=0;i--)(c=t[i])&&(s=(n?c(e,r,s):c(s))||s);return n&&s&&ze(e,r,s),s},M=(t,e)=>(r,n)=>e(r,n,t);const re="SHEET_NUMFMT_PANEL";let k=class extends o.Disposable{constructor(e,r,n,s,i,c,a,l,p,f){super();W(this,"_previewPattern","");W(this,"_sidebarDisposable",null);this._sheetInterceptorService=e,this._themeService=r,this._univerInstanceService=n,this._commandService=s,this._selectionManagerService=i,this._renderManagerService=c,this._numfmtService=a,this._componentManager=l,this._sidebarService=p,this._localeService=f,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener()}openPanel(){var P;const e=this._sidebarService,r=this._selectionManagerService,n=this._commandService,s=this._univerInstanceService,i=this._numfmtService,c=this._localeService,l=(((P=r.getCurrentSelections())==null?void 0:P.map(b=>b.range))||[])[0];if(!l)return!1;const p=s.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),f=p.getActiveSheet();if(!f)return!1;const d=f.getCellRaw(l.startRow,l.startColumn),h=i.getValue(p.getUnitId(),f.getSheetId(),l.startRow,l.startColumn);let S="";h&&(S=h.pattern);const _=(d==null?void 0:d.t)===o.CellValueType.NUMBER?d.v:12345678,v={onChange:b=>{var T;if(b.type==="change")this._previewPattern=b.value,this._forceUpdate();else if(b.type==="confirm"){const x=((T=r.getCurrentSelections())==null?void 0:T.map(U=>U.range))||[],H={values:[]},G=m.getPatternType(b.value);x.forEach(U=>{o.Range.foreach(U,(K,C)=>{H.values.push({row:K,col:C,pattern:b.value,type:G})})}),n.executeCommand(m.SetNumfmtCommand.id,H),e.close()}else b.type==="cancel"&&e.close()},value:{defaultPattern:S,defaultValue:_,row:l.startRow,col:l.startColumn}};return this._sidebarDisposable=e.open({header:{title:c.t("sheet.numfmt.title")},children:{label:re,...v},onClose:()=>{this._forceUpdate(),n.executeCommand(Y.id)}}),!0}_forceUpdate(e){var n;const r=this._renderManagerService.getRenderById(e!=null?e:this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET).getUnitId());r==null||r.with(j.SheetSkeletonManagerService).reCalculate(),(n=r==null?void 0:r.mainComponent)==null||n.makeDirty()}_initCommands(){[$,Y].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initPanel(){this._componentManager.register(re,Je)}_initRealTimeRenderingInterceptor(){const e=new D.Observable(n=>{this._commandService.onCommandExecuted(s=>{s.id===$.id&&n.next(!0),s.id===Y.id&&n.next(!1)})}),r=D.combineLatest([e,this._selectionManagerService.selectionMoveEnd$.pipe(A.map(n=>n?n.map(s=>s.range):[]))]);this.disposeWithMe(o.toDisposable(r.pipe(A.switchMap(([n,s])=>new D.Observable(i=>{const c=new o.DisposableCollection;return n&&s.length&&i.next({selectionRanges:s,disposableCollection:c}),()=>{c.dispose()}})),A.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:n,selectionRanges:s})=>{var c,a;const i=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:(l,p,f)=>{const{row:d,col:h}=p,S=f(l)||{};if(s.find(_=>_.startColumn<=h&&_.endColumn>=h&&_.startRow<=d&&_.endRow>=d)){const _=p.worksheet.getCellRaw(d,h),v=_==null?void 0:_.v,P=_==null?void 0:_.t;if(v==null||P!==o.CellValueType.NUMBER||this._previewPattern===null)return S;const b=m.getPatternPreviewIgnoreGeneral(this._previewPattern,v,this._localeService.getCurrentLocale());if(b.color){const x=this._themeService.getCurrentTheme()[`${b.color}500`];return{...S,v:b.result,t:o.CellValueType.STRING,s:{cl:{rgb:x}}}}return{...S,v:b.result,t:o.CellValueType.STRING}}return S}})),(a=(c=this._renderManagerService.getRenderById(i.getUnitId()))==null?void 0:c.mainComponent)==null||a.makeDirty()})))}_commandExecutedListener(){const e=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id];this.disposeWithMe(new D.Observable(r=>{const n=this._commandService.onCommandExecuted(s=>{if(e.includes(s.id)){const i=s.params;r.next(i.unitId)}});return()=>n.dispose()}).pipe(A.debounceTime(16)).subscribe(r=>this._forceUpdate(r)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_SHEET).subscribe(e=>{var r;e||((r=this._sidebarDisposable)==null||r.dispose(),this._sidebarDisposable=null)})}};k=Ze([M(0,o.Inject(g.SheetInterceptorService)),M(1,o.Inject(o.ThemeService)),M(2,o.IUniverInstanceService),M(3,o.ICommandService),M(4,o.Inject(g.SheetsSelectionsService)),M(5,ge.IRenderManagerService),M(6,g.INumfmtService),M(7,o.Inject(I.ComponentManager)),M(8,I.ISidebarService),M(9,o.Inject(o.LocaleService))],k);var Qe=Object.defineProperty,et=Object.getOwnPropertyDescriptor,tt=(t,e,r,n)=>{for(var s=n>1?void 0:n?et(e,r):e,i=t.length-1,c;i>=0;i--)(c=t[i])&&(s=(n?c(e,r,s):c(s))||s);return n&&s&&Qe(e,r,s),s},F=(t,e)=>(r,n)=>e(r,n,t);const nt=()=>{let t=[];return{add:(s,i,c,a,l)=>t.push({unitId:s,subUnitId:i,row:c,col:a,value:l}),getEffects:()=>t,clean:()=>{t=[]}}};let q=class extends o.Disposable{constructor(e,r,n,s,i){super();W(this,"_collectEffectMutation",nt());this._sheetInterceptorService=e,this._numfmtService=r,this._univerInstanceService=n,this._injector=s,this._editorBridgeService=i,this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(o.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.BEFORE_CELL_EDIT,{handler:(e,r,n)=>{const s=r.row,i=r.col,c=this._numfmtService.getValue(r.unitId,r.subUnitId,s,i);if(c)switch(m.getPatternType(c.pattern)){case"scientific":case"currency":case"grouped":case"number":return r.worksheet.getCellRaw(s,i);case"percent":case"date":case"time":case"datetime":default:return n&&n(e)}return n(e)}})))}_initInterceptorEditorEnd(){this.disposeWithMe(o.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.AFTER_CELL_EDIT,{handler:(e,r,n)=>{var f,d,h,S;this._collectEffectMutation.clean();const s=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col),i=(f=s&&m.getPatternType(s.pattern))!=null?f:"",c=()=>{s&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,null)};if(!(e!=null&&e.v)&&!(e!=null&&e.p)||(s==null?void 0:s.pattern)===oe.DEFAULT_TEXT_FORMAT)return n(e);const a=(d=e.p)==null?void 0:d.body,l=(S=(h=e==null?void 0:e.p)==null?void 0:h.body)!=null&&S.dataStream?e.p.body.dataStream.replace(/\r\n$/,""):String(e.v),p=o.numfmt.parseDate(l)||o.numfmt.parseTime(l)||o.numfmt.parseNumber(l);if(a)if(st(a)){const{dataStream:_}=a,v=_.replace(/\r\n$/,""),P=Number(v);if(Number.isNaN(P)&&!p)return n(e)}else return n(e);if(p){p.z&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:p.z});const _=Number(p.v);return n({...e,p:void 0,v:_,t:o.CellValueType.NUMBER})}else(["date","time","datetime","percent"].includes(i)||!rt(l))&&c();return n(e)}})))}_initInterceptorCommands(){const e=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(r){var n;switch(r.id){case g.SetRangeValuesCommand.id:{const s=e._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),i=s.getUnitId(),c=(n=s.getActiveSheet())==null?void 0:n.getSheetId();if(!c)return{redos:[],undos:[]};const a=e._collectEffectMutation.getEffects();if(e._collectEffectMutation.clean(),!a.length)return{redos:[],undos:[]};const l=a.filter(h=>{var S;return!!((S=h.value)!=null&&S.pattern)}).map(h=>({row:h.row,col:h.col,pattern:h.value.pattern})),p=a.filter(h=>{var S;return!((S=h.value)!=null&&S.pattern)}).map(h=>({startRow:h.row,endColumn:h.col,startColumn:h.col,endRow:h.row})),f=[],d=[];if(l.length){const h={id:g.SetNumfmtMutation.id,params:g.transformCellsToRange(i,c,l)};f.push(h),d.push(...g.factorySetNumfmtUndoMutation(e._injector,h.params))}if(p.length){const h={id:g.RemoveNumfmtMutation.id,params:{unitId:i,subUnitId:c,ranges:p}};f.push(h),d.push(...g.factoryRemoveNumfmtUndoMutation(e._injector,h.params))}return{redos:f,undos:d.reverse()}}}return{redos:[],undos:[]}}}))}};q=tt([F(0,o.Inject(g.SheetInterceptorService)),F(1,o.Inject(g.INumfmtService)),F(2,o.Inject(o.IUniverInstanceService)),F(3,o.Inject(o.Injector)),F(4,o.Optional(j.IEditorBridgeService))],q);function rt(t){return/^-?\d+(\.\d+)?$/.test(t)}function st(t){const{textRuns:e=[],paragraphs:r=[],customRanges:n,customBlocks:s=[]}=t,i=["va"];return!(e.some(c=>!!(c.ts&&Object.keys(c.ts).some(l=>i.includes(l))))||r.some(c=>c.bullet)||r.length>=2||n!=null&&n.length||s.length>0)}const B=[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:oe.DEFAULT_TEXT_FORMAT},"|",{label:"sheet.numfmt.number",pattern:"0"},"|",{label:"sheet.numfmt.accounting",pattern:'"¥" #,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.financialValue",pattern:"#,##0.00;[Red]#,##0.00"},{label:"sheet.numfmt.currency",pattern:'"¥"#,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.roundingCurrency",pattern:'"¥"#,##0;[Red]"¥"#,##0'},"|",{label:"sheet.numfmt.date",pattern:"yyyy-mm-dd;@"},{label:"sheet.numfmt.time",pattern:'am/pm h":"mm":"ss'},{label:"sheet.numfmt.dateTime",pattern:"yyyy-m-d am/pm h:mm"},{label:"sheet.numfmt.timeDuration",pattern:"h:mm:ss"},"|",{label:"sheet.numfmt.moreFmt",pattern:""}],it=t=>({icon:new D.Observable(e=>{const r=t.get(m.MenuCurrencyService);function n(i){return{[m.countryCurrencyMap.US]:"DollarSingle",[m.countryCurrencyMap.RU]:"RoubleSingle",[m.countryCurrencyMap.CN]:"RmbSingle",[m.countryCurrencyMap.AT]:"EuroSingle"}[i]||"DollarSingle"}const s=m.countryCurrencyMap[r.getCurrencySymbol()]||"$";return e.next(n(s)),r.currencySymbol$.subscribe(i=>{const c=m.countryCurrencyMap[i]||"$";e.next(n(c))})}),id:m.SetCurrencyCommand.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:I.MenuItemType.BUTTON,hidden$:I.getMenuHiddenObservable(t,o.UniverInstanceType.UNIVER_SHEET),disabled$:j.getCurrentRangeDisable$(t,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),ot=t=>({icon:"AddDigitsSingle",id:m.AddDecimalCommand.id,title:"sheet.numfmt.addDecimal",tooltip:"sheet.numfmt.addDecimal",type:I.MenuItemType.BUTTON,hidden$:I.getMenuHiddenObservable(t,o.UniverInstanceType.UNIVER_SHEET),disabled$:j.getCurrentRangeDisable$(t,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),ct=t=>({icon:"ReduceDigitsSingle",id:m.SubtractDecimalCommand.id,title:"sheet.numfmt.subtractDecimal",tooltip:"sheet.numfmt.subtractDecimal",type:I.MenuItemType.BUTTON,hidden$:I.getMenuHiddenObservable(t,o.UniverInstanceType.UNIVER_SHEET),disabled$:j.getCurrentRangeDisable$(t,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),at=t=>({icon:"PercentSingle",id:m.SetPercentCommand.id,title:"sheet.numfmt.percent",tooltip:"sheet.numfmt.percent",type:I.MenuItemType.BUTTON,hidden$:I.getMenuHiddenObservable(t,o.UniverInstanceType.UNIVER_SHEET),disabled$:j.getCurrentRangeDisable$(t,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),lt=t=>{const e=t.get(o.IUniverInstanceService),r=t.get(o.ICommandService),n=t.get(o.LocaleService),s=t.get(g.SheetsSelectionsService),i=j.deriveStateFromActiveSheet$(e,"",({workbook:c,worksheet:a})=>new D.Observable(l=>D.merge(s.selectionMoveEnd$,new D.Observable(p=>{const f=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id],d=r.onCommandExecuted(h=>{f.includes(h.id)&&p.next(null)});return()=>d.dispose()})).subscribe(()=>{var f,d;const p=s.getCurrentSelections();if(p&&p[0]){const h=p[0].range,S=h.startRow,_=h.startColumn,v=(d=c.getStyles().get((f=a.getCell(S,_))==null?void 0:f.s))==null?void 0:d.n,P=v==null?void 0:v.pattern;let b=n.t("sheet.numfmt.general");if(P){const T=B.filter(x=>typeof x=="object"&&x.pattern).find(x=>m.isPatternEqualWithoutDecimal(P,x.pattern));T&&typeof T=="object"&&T.pattern?b=n.t(T.label):b=n.t("sheet.numfmt.moreFmt")}l.next(b)}})));return{label:ue,id:$.id,tooltip:"sheet.numfmt.title",type:I.MenuItemType.SELECTOR,selections:[{label:{name:me,hoverable:!1}}],value$:i,hidden$:I.getMenuHiddenObservable(t,o.UniverInstanceType.UNIVER_SHEET),disabled$:j.getCurrentRangeDisable$(t,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetSetCellStylePermission,g.WorksheetEditPermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}},ue="sheet.numfmt.moreNumfmtType",me="sheet.numfmt.moreNumfmtType.options",ut=t=>{var n;const e=o.useDependency(o.LocaleService),r=(n=t.value)!=null?n:e.t("sheet.numfmt.general");return u.jsx("span",{className:"more-numfmt-type",children:r})},mt=()=>{const t=o.useDependency(o.ICommandService),e=o.useDependency(o.LocaleService),r=o.useDependency(I.ILayoutService);o.useInjector();const n=o.useDependency(g.SheetsSelectionsService),s=a=>{const l=n.getCurrentLastSelection();if(!l)return;const p=l.range,f=[];o.Range.foreach(p,(d,h)=>{a?f.push({row:d,col:h,pattern:a,type:m.getPatternType(a)}):f.push({row:d,col:h})}),t.executeCommand(m.SetNumfmtCommand.id,{values:f}),r.focus()},i=a=>{if(a===0)s(null);else if(a===B.length-1)t.executeCommand($.id);else{const l=B[a];l.pattern&&s(l.pattern)}},c=1220;return u.jsx("div",{className:"more-numfmt-type-options",children:B.map((a,l)=>a==="|"?u.jsx("div",{className:"line m-t-4",onClick:p=>p.stopPropagation()},l):u.jsxs("div",{className:"option-item m-t-4",onClick:()=>{i(l)},children:[u.jsx("div",{children:e.t(a.label)}),u.jsx("div",{className:"m-l-26",children:a.pattern?m.getPatternPreview(a.pattern||"",c,e.getCurrentLocale()).result:""})]},l))})},dt={[I.RibbonStartGroup.FORMULAS_INSERT]:{[m.SetCurrencyCommand.id]:{order:4,menuItemFactory:it},[m.AddDecimalCommand.id]:{order:5,menuItemFactory:ot},[m.SubtractDecimalCommand.id]:{order:6,menuItemFactory:ct},[m.SetPercentCommand.id]:{order:7,menuItemFactory:at},[$.id]:{order:8,menuItemFactory:lt}}};var ht=Object.defineProperty,ft=Object.getOwnPropertyDescriptor,pt=(t,e,r,n)=>{for(var s=n>1?void 0:n?ft(e,r):e,i=t.length-1,c;i>=0;i--)(c=t[i])&&(s=(n?c(e,r,s):c(s))||s);return n&&s&&ht(e,r,s),s},se=(t,e)=>(r,n)=>e(r,n,t);let V=class extends o.Disposable{constructor(t,e){super(),this._componentManager=t,this._menuManagerService=e,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(dt),this.disposeWithMe(this._componentManager.register(ue,ut)),this.disposeWithMe(this._componentManager.register(me,mt))}};V=pt([se(0,o.Inject(I.ComponentManager)),se(1,I.IMenuManagerService)],V);var de=Object.defineProperty,vt=Object.getOwnPropertyDescriptor,St=(t,e,r)=>e in t?de(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,gt=(t,e,r,n)=>{for(var s=n>1?void 0:n?vt(e,r):e,i=t.length-1,c;i>=0;i--)(c=t[i])&&(s=(n?c(e,r,s):c(s))||s);return n&&s&&de(e,r,s),s},ie=(t,e)=>(r,n)=>e(r,n,t),he=(t,e,r)=>St(t,typeof e!="symbol"?e+"":e,r);const yt="SHEET_NUMFMT_UI_PLUGIN";exports.UniverSheetsNumfmtUIPlugin=class extends o.Plugin{constructor(e=Q,r,n){super(),this._config=e,this._injector=r,this._configService=n;const{menu:s,...i}=o.merge({},Q,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig(I.UI_PLUGIN_CONFIG_KEY,i)}onStarting(){o.registerDependencies(this._injector,[[k],[q],[L],[V]])}onRendered(){o.touchDependencies(this._injector,[[k],[q],[V]])}};he(exports.UniverSheetsNumfmtUIPlugin,"pluginName",yt);he(exports.UniverSheetsNumfmtUIPlugin,"type",o.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtUIPlugin=gt([o.DependentOn(j.UniverSheetsUIPlugin,m.UniverSheetsNumfmtPlugin),ie(1,o.Inject(o.Injector)),ie(2,o.IConfigService)],exports.UniverSheetsNumfmtUIPlugin);
9
+ */var ee;function ye(){if(ee)return w;ee=1;var t=y,e=Symbol.for("react.element"),r=Symbol.for("react.fragment"),n=Object.prototype.hasOwnProperty,s=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function c(a,l,p){var f,d={},h=null,S=null;p!==void 0&&(h=""+p),l.key!==void 0&&(h=""+l.key),l.ref!==void 0&&(S=l.ref);for(f in l)n.call(l,f)&&!i.hasOwnProperty(f)&&(d[f]=l[f]);if(a&&a.defaultProps)for(f in l=a.defaultProps,l)d[f]===void 0&&(d[f]=l[f]);return{$$typeof:e,type:a,key:h,ref:S,props:d,_owner:s.current}}return w.Fragment=r,w.jsx=c,w.jsxs=c,w}var te;function _e(){return te||(te=1,J.exports=ye()),J.exports}var u=_e(),be=Object.defineProperty,Ce=Object.getOwnPropertyDescriptor,Ie=(t,e,r,n)=>{for(var s=n>1?void 0:n?Ce(e,r):e,i=t.length-1,c;i>=0;i--)(c=t[i])&&(s=(n?c(e,r,s):c(s))||s);return n&&s&&be(e,r,s),s},Pe=(t,e)=>(r,n)=>e(r,n,t);const Z=y.createContext([]);let L=class{constructor(t){this._localStorageService=t}_getKey(t){return`userHabitController_${t}`}async addHabit(t,e){const r=this._getKey(t);return this._localStorageService.getItem(r).then(n=>{n||this._localStorageService.setItem(r,e)})}markHabit(t,e){const r=this._getKey(t);this._localStorageService.getItem(r).then(n=>{if(n){const s=n.findIndex(i=>i===e);s>-1&&n.splice(s,1),n.unshift(e),this._localStorageService.setItem(r,n)}})}async getHabit(t,e){const r=this._getKey(t),n=await this._localStorageService.getItem(r);if(e&&n){const s=n.map((i,c,a)=>{const l=a.length;return{value:i,priority:l-c}});return e.sort((i,c)=>{var p,f;const a=((p=s.find(d=>d.value===i))==null?void 0:p.priority)||-1;return(((f=s.find(d=>d.value===c))==null?void 0:f.priority)||-1)-a})}return n||[]}deleteHabit(t){this._localStorageService.removeItem(t)}};L=Ie([Pe(0,o.Inject(o.ILocalStorageService))],L);const ne="numfmtCurrency",Te=t=>{const e=o.useDependency(L),[r,n]=y.useState(m.currencySymbols);return y.useEffect(()=>{e.addHabit("numfmtCurrency",[]).then(()=>{e.getHabit(ne,[...m.currencySymbols]).then(i=>{n(i),t(i)})})},[]),{userHabitCurrency:r,mark:i=>{e.markHabit(ne,i)}}},Ne=()=>{const t=y.useRef([]),[e,r]=y.useState({});return y.useEffect(()=>{t.current.forEach(s=>{s()}),t.current=[]},[e]),s=>{t.current.push(s),r({})}},Ee=t=>!!m.getCurrencyType(t)&&t.startsWith("_("),xe=t=>{const{defaultPattern:e,action:r,onChange:n}=t,[s,i]=y.useState(()=>m.getDecimalFromPattern(e||"",2)),c=y.useContext(Z),[a,l]=y.useState(()=>m.getCurrencyType(e)||c[0]),p=y.useMemo(()=>c.map(_=>({label:_,value:_})),[]),d=o.useDependency(o.LocaleService).t;r.current=()=>m.setPatternDecimal(`_("${a}"* #,##0${s>0?".0":""}_)`,s);const h=_=>{l(_),n(m.setPatternDecimal(`_("${_}"* #,##0${s>0?".0":""}_)`,s))},S=_=>{const v=_||0;i(v),n(m.setPatternDecimal(`_("${a}"* #,##0${v>0?".0":""}_)`,v))};return u.jsxs("div",{children:[u.jsxs("div",{className:"m-t-16 options",children:[u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:d("sheet.numfmt.decimalLength")}),u.jsx("div",{className:"m-t-8 w-120",children:u.jsx(E.InputNumber,{value:s,max:20,min:0,onChange:S})})]}),u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:d("sheet.numfmt.currencyType")}),u.jsx("div",{className:"m-t-8 w-140",children:u.jsx(E.Select,{onChange:h,options:p,value:a})})]})]}),u.jsx("div",{className:"describe m-t-14",children:d("sheet.numfmt.accountingDes")})]})},Me=t=>!!m.getCurrencyType(t)&&!t.startsWith("_("),je=t=>{const r=o.useDependency(o.LocaleService).t,n=y.useContext(Z),[s,i]=y.useState(()=>m.getCurrencyType(t.defaultPattern)||n[0]),[c,a]=y.useState(()=>m.getDecimalFromPattern(t.defaultPattern||"",2)),[l,p]=y.useState(()=>{var b;const v=m.getCurrencyFormatOptions(s);return((b=v.find(T=>m.isPatternEqualWithoutDecimal(T.value,t.defaultPattern)))==null?void 0:b.value)||v[0].value}),f=y.useMemo(()=>m.getCurrencyFormatOptions(s),[s]),d=y.useMemo(()=>n.map(v=>({label:v,value:v})),[n]);t.action.current=()=>m.setPatternDecimal(l,c);const h=v=>{if(v===void 0)return;i(v);const P=m.getCurrencyFormatOptions(v)[0].value;p(P),t.onChange(m.setPatternDecimal(P,c))},S=v=>{v!==void 0&&(p(v),t.onChange(m.setPatternDecimal(v,c)))},_=v=>{a(v||0),t.onChange(m.setPatternDecimal(l,v||0))};return u.jsxs("div",{children:[u.jsxs("div",{className:"m-t-16 options",children:[u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:r("sheet.numfmt.decimalLength")}),u.jsx("div",{className:"m-t-8 w-120",children:u.jsx(E.InputNumber,{value:c,max:20,min:0,onChange:_})})]}),u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:r("sheet.numfmt.currencyType")}),u.jsx("div",{className:"m-t-8 w-140",children:u.jsx(E.Select,{onChange:h,options:d,value:s})})]})]}),u.jsx("div",{className:"m-t-16 label",children:r("sheet.numfmt.negType")}),u.jsx("div",{className:"m-t-8",children:u.jsx(E.SelectList,{onChange:S,options:f,value:l})}),u.jsx("div",{className:"describe m-t-14",children:r("sheet.numfmt.currencyDes")})]})};var N=function(){return N=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++){e=arguments[r];for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s])}return t},N.apply(this,arguments)},De=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,n=Object.getOwnPropertySymbols(t);s<n.length;s++)e.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(t,n[s])&&(r[n[s]]=t[n[s]]);return r},ce=y.forwardRef(function(t,e){var r=t.icon,n=t.id,s=t.className,i=t.extend,c=De(t,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(n," ").concat(s||"").trim(),l=y.useRef("_".concat(Ue()));return ae(r,"".concat(n),{defIds:r.defIds,idSuffix:l.current},N({ref:e,className:a},c),i)});function ae(t,e,r,n,s){return y.createElement(t.tag,N(N({key:e},Re(t,r,s)),n),(Oe(t,r).children||[]).map(function(i,c){return ae(i,"".concat(e,"-").concat(t.tag,"-").concat(c),r,void 0,s)}))}function Re(t,e,r){var n=N({},t.attrs);r!=null&&r.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=r.colorChannel1);var s=e.defIds;return!s||s.length===0||(t.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+e.idSuffix),Object.entries(n).forEach(function(i){var c=i[0],a=i[1];typeof a=="string"&&(n[c]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),n}function Oe(t,e){var r,n=e.defIds;return!n||n.length===0?t:t.tag==="defs"&&(!((r=t.children)===null||r===void 0)&&r.length)?N(N({},t),{children:t.children.map(function(s){return typeof s.attrs.id=="string"&&n&&n.indexOf(s.attrs.id)>-1?N(N({},s),{attrs:N(N({},s.attrs),{id:s.attrs.id+e.idSuffix})}):s})}):t}function Ue(){return Math.random().toString(36).substring(2,8)}ce.displayName="UniverIcon";var we={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},le=y.forwardRef(function(t,e){return y.createElement(ce,Object.assign({},t,{id:"check-mark-single",ref:e,icon:we}))});le.displayName="CheckMarkSingle";const Fe="univer-custom-format-title",$e="univer-custom-format-input",Le="univer-custom-format-history-list",ke="univer-custom-format-history-list-item",He="univer-custom-format-history-list-item-icon-wrap",We="univer-custom-format-des",R={customFormatTitle:Fe,customFormatInput:$e,customFormatHistoryList:Le,customFormatHistoryListItem:ke,customFormatHistoryListItemIconWrap:He,customFormatDes:We},z="customFormat",X="numfmt_custom_pattern";function Ae(t){const{defaultPattern:e,action:r,onChange:n}=t,s=o.useDependency(L),i=o.useDependency(o.ILocalStorageService),c=o.useDependency(o.LocaleService),[a,l]=y.useState(e);r.current=()=>(s.markHabit(z,a),i.getItem(X).then((S=[])=>{const _=[...new Set([a,...S||[]])].splice(0,10).filter(v=>!!v);i.setItem(X,_)}),a);const[p,f]=y.useState([]);y.useEffect(()=>{i.getItem(X).then(S=>{const _=[...m.CURRENCYFORMAT.map(v=>v.suffix("$")),...m.DATEFMTLISG.map(v=>v.suffix),...m.NUMBERFORMAT.map(v=>v.suffix)];_.push(...S||[]),s.addHabit(z,[]).finally(()=>{s.getHabit(z,_).then(v=>{f([...new Set(v)])})})})},[]);const d=S=>{l(S),n(S)},h=()=>{n(a)};return u.jsxs("div",{className:R.customFormat,children:[u.jsx("div",{className:R.customFormatTitle,children:c.t("sheet.numfmt.customFormat")}),u.jsx(E.Input,{placeholder:c.t("sheet.numfmt.customFormat"),onBlur:h,value:a,onChange:l,className:R.customFormatInput}),u.jsx("div",{className:R.customFormatHistoryList,children:p.map(S=>u.jsxs("div",{onClick:()=>d(S),className:R.customFormatHistoryListItem,children:[u.jsx("div",{className:R.customFormatHistoryListItemIconWrap,children:a===S&&u.jsx(le,{})}),u.jsx("div",{children:S})]},S))}),u.jsx("div",{className:R.customFormatDes,children:c.t("sheet.numfmt.customFormatDes")})]})}const Be=t=>{const e=o.numfmt.getInfo(t);return m.getDateFormatOptions().map(r=>r.value).includes(t)||["date","datetime","time"].includes(e.type)},qe=t=>{const e=y.useMemo(m.getDateFormatOptions,[]),n=o.useDependency(o.LocaleService).t,[s,i]=y.useState(()=>{if(t.defaultPattern){const a=e.find(l=>l.value===t.defaultPattern);if(a)return a.value}return e[0].value});t.action.current=()=>s;const c=a=>{a!==void 0&&(i(a),t.onChange(a))};return u.jsxs("div",{children:[u.jsx("div",{className:"m-t-16 label",children:n("sheet.numfmt.dateType")}),u.jsx("div",{className:"m-t-8",children:u.jsx(E.SelectList,{value:s,options:e,onChange:c})}),u.jsx("div",{className:"describe m-t-14",children:n("sheet.numfmt.dateDes")})]})},Ve=t=>!t,Ge=t=>{const r=o.useDependency(o.LocaleService).t;return t.action.current=()=>"",u.jsx("div",{children:u.jsx("div",{className:"describe m-t-14",children:r("sheet.numfmt.generalDes")})})},Ke=t=>m.getNumberFormatOptions().some(e=>m.isPatternEqualWithoutDecimal(e.value,t)),Ye=t=>{const e=o.useDependency(o.LocaleService),r=y.useMemo(m.getNumberFormatOptions,[]),[n,s]=y.useState(()=>m.getDecimalFromPattern(t.defaultPattern||"",0)),[i,c]=y.useState(()=>{const d=r.find(h=>m.isPatternEqualWithoutDecimal(h.value,t.defaultPattern||""));return(d==null?void 0:d.value)||r[0].value}),a=y.useMemo(()=>m.setPatternDecimal(i,Number(n||0)),[i,n]),l=y.useMemo(()=>!m.isPatternHasDecimal(i),[i]),p=d=>{s(d||0),t.onChange(m.setPatternDecimal(i,Number(d||0)))},f=d=>{d!==void 0&&(s(m.getDecimalFromPattern(d,0)),c(d),t.onChange(d))};return t.action.current=()=>a,u.jsxs("div",{children:[u.jsx("div",{className:"m-t-16 label",children:e.t("sheet.numfmt.decimalLength")}),u.jsx("div",{className:"m-t-8",children:u.jsx(E.InputNumber,{disabled:l,value:n,max:20,min:0,onChange:p})}),u.jsxs("div",{className:"m-t-16 label",children:[" ",e.t("sheet.numfmt.negType")]}),u.jsx("div",{className:"m-t-8",children:u.jsx(E.SelectList,{onChange:f,options:r,value:i})}),u.jsx("div",{className:"describe m-t-14",children:e.t("sheet.numfmt.thousandthPercentileDes")})]})},Je=t=>{const{defaultValue:e,defaultPattern:r,row:n,col:s}=t.value,i=o.useDependency(o.LocaleService),c=y.useRef(()=>""),a=i.t,l=Ne(),p=y.useMemo(()=>[{label:"sheet.numfmt.general",component:Ge},{label:"sheet.numfmt.accounting",component:xe},{label:"sheet.numfmt.currency",component:je},{label:"sheet.numfmt.date",component:qe},{label:"sheet.numfmt.thousandthPercentile",component:Ye},{label:"sheet.numfmt.customFormat",component:Ae}].map(C=>({...C,label:a(C.label)})),[]),[f,d]=y.useState(b),[h,S]=y.useState(()=>`${n}_${s}`),{mark:_,userHabitCurrency:v}=Te(()=>S(`${n}_${s}_userCurrency'`)),P=y.useMemo(()=>{var C;return(C=p.find(O=>O.label===f))==null?void 0:C.component},[f]);function b(){return[Ve,Ee,Me,Be,Ke].reduce((O,fe,pe)=>O||(fe(r)?p[pe].label:""),"")||p[0].label}const T=p.map(C=>({label:C.label,value:C.label})),x=C=>{d(C),l(()=>t.onChange({type:"change",value:c.current()||""}))},H=C=>{t.onChange({type:"change",value:C})},G=()=>{const C=c.current()||"",O=m.getCurrencyType(C);O&&_(O),t.onChange({type:"confirm",value:C})},U=()=>{t.onChange({type:"cancel",value:""})},K={onChange:H,defaultValue:e,defaultPattern:r,action:c};return y.useEffect(()=>{d(b()),S(`${n}_${s}`)},[n,s]),u.jsxs("div",{className:"numfmt-panel p-b-20",children:[u.jsxs("div",{children:[u.jsx("div",{className:"label m-t-14",children:a("sheet.numfmt.numfmtType")}),u.jsx("div",{className:"m-t-8",children:u.jsx(E.Select,{onChange:x,options:T,value:f,style:{width:"100%"}})}),u.jsx("div",{children:P&&u.jsx(Z.Provider,{value:v,children:y.createElement(P,{...K,key:h})})})]}),u.jsxs("div",{className:"btn-list m-t-14 m-b-20",children:[u.jsx(E.Button,{size:"small",onClick:U,className:"m-r-12",children:a("sheet.numfmt.cancel")}),u.jsx(E.Button,{type:"primary",size:"small",onClick:G,children:a("sheet.numfmt.confirm")})]})]})};var ze=Object.defineProperty,Xe=Object.getOwnPropertyDescriptor,Ze=(t,e,r,n)=>{for(var s=n>1?void 0:n?Xe(e,r):e,i=t.length-1,c;i>=0;i--)(c=t[i])&&(s=(n?c(e,r,s):c(s))||s);return n&&s&&ze(e,r,s),s},M=(t,e)=>(r,n)=>e(r,n,t);const re="SHEET_NUMFMT_PANEL";let k=class extends o.Disposable{constructor(e,r,n,s,i,c,a,l,p,f){super();W(this,"_previewPattern","");W(this,"_sidebarDisposable",null);this._sheetInterceptorService=e,this._themeService=r,this._univerInstanceService=n,this._commandService=s,this._selectionManagerService=i,this._renderManagerService=c,this._numfmtService=a,this._componentManager=l,this._sidebarService=p,this._localeService=f,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener()}openPanel(){var P;const e=this._sidebarService,r=this._selectionManagerService,n=this._commandService,s=this._univerInstanceService,i=this._numfmtService,c=this._localeService,l=(((P=r.getCurrentSelections())==null?void 0:P.map(b=>b.range))||[])[0];if(!l)return!1;const p=s.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),f=p.getActiveSheet();if(!f)return!1;const d=f.getCellRaw(l.startRow,l.startColumn),h=i.getValue(p.getUnitId(),f.getSheetId(),l.startRow,l.startColumn);let S="";h&&(S=h.pattern);const _=(d==null?void 0:d.t)===o.CellValueType.NUMBER?d.v:12345678,v={onChange:b=>{var T;if(b.type==="change")this._previewPattern=b.value,this._forceUpdate();else if(b.type==="confirm"){const x=((T=r.getCurrentSelections())==null?void 0:T.map(U=>U.range))||[],H={values:[]},G=m.getPatternType(b.value);x.forEach(U=>{o.Range.foreach(U,(K,C)=>{H.values.push({row:K,col:C,pattern:b.value,type:G})})}),n.executeCommand(m.SetNumfmtCommand.id,H),e.close()}else b.type==="cancel"&&e.close()},value:{defaultPattern:S,defaultValue:_,row:l.startRow,col:l.startColumn}};return this._sidebarDisposable=e.open({header:{title:c.t("sheet.numfmt.title")},children:{label:re,...v},onClose:()=>{this._forceUpdate(),n.executeCommand(Y.id)}}),!0}_forceUpdate(e){var n;const r=this._renderManagerService.getRenderById(e!=null?e:this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET).getUnitId());r==null||r.with(j.SheetSkeletonManagerService).reCalculate(),(n=r==null?void 0:r.mainComponent)==null||n.makeDirty()}_initCommands(){[$,Y].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initPanel(){this._componentManager.register(re,Je)}_initRealTimeRenderingInterceptor(){const e=new D.Observable(n=>{this._commandService.onCommandExecuted(s=>{s.id===$.id&&n.next(!0),s.id===Y.id&&n.next(!1)})}),r=D.combineLatest([e,this._selectionManagerService.selectionMoveEnd$.pipe(A.map(n=>n?n.map(s=>s.range):[]))]);this.disposeWithMe(o.toDisposable(r.pipe(A.switchMap(([n,s])=>new D.Observable(i=>{const c=new o.DisposableCollection;return n&&s.length&&i.next({selectionRanges:s,disposableCollection:c}),()=>{c.dispose()}})),A.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:n,selectionRanges:s})=>{var c,a;const i=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:(l,p,f)=>{const{row:d,col:h}=p,S=f(l)||{};if(s.find(_=>_.startColumn<=h&&_.endColumn>=h&&_.startRow<=d&&_.endRow>=d)){const _=p.worksheet.getCellRaw(d,h),v=_==null?void 0:_.v,P=_==null?void 0:_.t;if(v==null||P!==o.CellValueType.NUMBER||this._previewPattern===null)return S;const b=m.getPatternPreviewIgnoreGeneral(this._previewPattern,v,this._localeService.getCurrentLocale());if(b.color){const x=this._themeService.getCurrentTheme()[`${b.color}500`];return{...S,v:b.result,t:o.CellValueType.STRING,s:{cl:{rgb:x}}}}return{...S,v:b.result,t:o.CellValueType.STRING}}return S}})),(a=(c=this._renderManagerService.getRenderById(i.getUnitId()))==null?void 0:c.mainComponent)==null||a.makeDirty()})))}_commandExecutedListener(){const e=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id];this.disposeWithMe(new D.Observable(r=>{const n=this._commandService.onCommandExecuted(s=>{if(e.includes(s.id)){const i=s.params;r.next(i.unitId)}});return()=>n.dispose()}).pipe(A.debounceTime(16)).subscribe(r=>this._forceUpdate(r)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(o.UniverInstanceType.UNIVER_SHEET).subscribe(e=>{var r;e||((r=this._sidebarDisposable)==null||r.dispose(),this._sidebarDisposable=null)})}};k=Ze([M(0,o.Inject(g.SheetInterceptorService)),M(1,o.Inject(o.ThemeService)),M(2,o.IUniverInstanceService),M(3,o.ICommandService),M(4,o.Inject(g.SheetsSelectionsService)),M(5,ge.IRenderManagerService),M(6,g.INumfmtService),M(7,o.Inject(I.ComponentManager)),M(8,I.ISidebarService),M(9,o.Inject(o.LocaleService))],k);var Qe=Object.defineProperty,et=Object.getOwnPropertyDescriptor,tt=(t,e,r,n)=>{for(var s=n>1?void 0:n?et(e,r):e,i=t.length-1,c;i>=0;i--)(c=t[i])&&(s=(n?c(e,r,s):c(s))||s);return n&&s&&Qe(e,r,s),s},F=(t,e)=>(r,n)=>e(r,n,t);const nt=()=>{let t=[];return{add:(s,i,c,a,l)=>t.push({unitId:s,subUnitId:i,row:c,col:a,value:l}),getEffects:()=>t,clean:()=>{t=[]}}};let q=class extends o.Disposable{constructor(e,r,n,s,i){super();W(this,"_collectEffectMutation",nt());this._sheetInterceptorService=e,this._numfmtService=r,this._univerInstanceService=n,this._injector=s,this._editorBridgeService=i,this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(o.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.BEFORE_CELL_EDIT,{handler:(e,r,n)=>{const s=r.row,i=r.col,c=this._numfmtService.getValue(r.unitId,r.subUnitId,s,i);if(c)switch(m.getPatternType(c.pattern)){case"scientific":case"currency":case"grouped":case"number":return r.worksheet.getCellRaw(s,i);case"percent":case"date":case"time":case"datetime":default:return n&&n(e)}return n(e)}})))}_initInterceptorEditorEnd(){this.disposeWithMe(o.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.AFTER_CELL_EDIT,{handler:(e,r,n)=>{var f,d,h,S;this._collectEffectMutation.clean();const s=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col),i=(f=s&&m.getPatternType(s.pattern))!=null?f:"",c=()=>{s&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,null)};if(!(e!=null&&e.v)&&!(e!=null&&e.p)||(s==null?void 0:s.pattern)===oe.DEFAULT_TEXT_FORMAT)return n(e);const a=(d=e.p)==null?void 0:d.body,l=(S=(h=e==null?void 0:e.p)==null?void 0:h.body)!=null&&S.dataStream?e.p.body.dataStream.replace(/\r\n$/,""):String(e.v),p=o.numfmt.parseDate(l)||o.numfmt.parseTime(l)||o.numfmt.parseNumber(l);if(a)if(st(a)){const{dataStream:_}=a,v=_.replace(/\r\n$/,""),P=Number(v);if(Number.isNaN(P)&&!p)return n(e)}else return n(e);if(p){p.z&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:p.z});const _=Number(p.v);return n({...e,p:void 0,v:_,t:o.CellValueType.NUMBER})}else(["date","time","datetime","percent"].includes(i)||!rt(l))&&c();return n(e)}})))}_initInterceptorCommands(){const e=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(r){var n;switch(r.id){case g.SetRangeValuesCommand.id:{const s=e._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),i=s.getUnitId(),c=(n=s.getActiveSheet())==null?void 0:n.getSheetId();if(!c)return{redos:[],undos:[]};const a=e._collectEffectMutation.getEffects();if(e._collectEffectMutation.clean(),!a.length)return{redos:[],undos:[]};const l=a.filter(h=>{var S;return!!((S=h.value)!=null&&S.pattern)}).map(h=>({row:h.row,col:h.col,pattern:h.value.pattern})),p=a.filter(h=>{var S;return!((S=h.value)!=null&&S.pattern)}).map(h=>({startRow:h.row,endColumn:h.col,startColumn:h.col,endRow:h.row})),f=[],d=[];if(l.length){const h={id:g.SetNumfmtMutation.id,params:g.transformCellsToRange(i,c,l)};f.push(h),d.push(...g.factorySetNumfmtUndoMutation(e._injector,h.params))}if(p.length){const h={id:g.RemoveNumfmtMutation.id,params:{unitId:i,subUnitId:c,ranges:p}};f.push(h),d.push(...g.factoryRemoveNumfmtUndoMutation(e._injector,h.params))}return{redos:f,undos:d.reverse()}}}return{redos:[],undos:[]}}}))}};q=tt([F(0,o.Inject(g.SheetInterceptorService)),F(1,o.Inject(g.INumfmtService)),F(2,o.Inject(o.IUniverInstanceService)),F(3,o.Inject(o.Injector)),F(4,o.Optional(j.IEditorBridgeService))],q);function rt(t){return/^-?\d+(\.\d+)?$/.test(t)}function st(t){const{textRuns:e=[],paragraphs:r=[],customRanges:n,customBlocks:s=[]}=t,i=["va"];return!(e.some(c=>!!(c.ts&&Object.keys(c.ts).some(l=>i.includes(l))))||r.some(c=>c.bullet)||r.length>=2||n!=null&&n.length||s.length>0)}const B=[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:oe.DEFAULT_TEXT_FORMAT},"|",{label:"sheet.numfmt.number",pattern:"0"},"|",{label:"sheet.numfmt.accounting",pattern:'"¥" #,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.financialValue",pattern:"#,##0.00;[Red]#,##0.00"},{label:"sheet.numfmt.currency",pattern:'"¥"#,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.roundingCurrency",pattern:'"¥"#,##0;[Red]"¥"#,##0'},"|",{label:"sheet.numfmt.date",pattern:"yyyy-mm-dd;@"},{label:"sheet.numfmt.time",pattern:'am/pm h":"mm":"ss'},{label:"sheet.numfmt.dateTime",pattern:"yyyy-m-d am/pm h:mm"},{label:"sheet.numfmt.timeDuration",pattern:"h:mm:ss"},"|",{label:"sheet.numfmt.moreFmt",pattern:""}],it=t=>({icon:new D.Observable(e=>{const r=t.get(m.MenuCurrencyService);function n(i){return{[m.countryCurrencyMap.US]:"DollarSingle",[m.countryCurrencyMap.RU]:"RoubleSingle",[m.countryCurrencyMap.CN]:"RmbSingle",[m.countryCurrencyMap.AT]:"EuroSingle"}[i]||"DollarSingle"}const s=m.countryCurrencyMap[r.getCurrencySymbol()]||"$";return e.next(n(s)),r.currencySymbol$.subscribe(i=>{const c=m.countryCurrencyMap[i]||"$";e.next(n(c))})}),id:m.SetCurrencyCommand.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:I.MenuItemType.BUTTON,hidden$:I.getMenuHiddenObservable(t,o.UniverInstanceType.UNIVER_SHEET),disabled$:j.getCurrentRangeDisable$(t,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),ot=t=>({icon:"AddDigitsSingle",id:m.AddDecimalCommand.id,title:"sheet.numfmt.addDecimal",tooltip:"sheet.numfmt.addDecimal",type:I.MenuItemType.BUTTON,hidden$:I.getMenuHiddenObservable(t,o.UniverInstanceType.UNIVER_SHEET),disabled$:j.getCurrentRangeDisable$(t,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),ct=t=>({icon:"ReduceDigitsSingle",id:m.SubtractDecimalCommand.id,title:"sheet.numfmt.subtractDecimal",tooltip:"sheet.numfmt.subtractDecimal",type:I.MenuItemType.BUTTON,hidden$:I.getMenuHiddenObservable(t,o.UniverInstanceType.UNIVER_SHEET),disabled$:j.getCurrentRangeDisable$(t,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),at=t=>({icon:"PercentSingle",id:m.SetPercentCommand.id,title:"sheet.numfmt.percent",tooltip:"sheet.numfmt.percent",type:I.MenuItemType.BUTTON,hidden$:I.getMenuHiddenObservable(t,o.UniverInstanceType.UNIVER_SHEET),disabled$:j.getCurrentRangeDisable$(t,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),lt=t=>{const e=t.get(o.IUniverInstanceService),r=t.get(o.ICommandService),n=t.get(o.LocaleService),s=t.get(g.SheetsSelectionsService),i=j.deriveStateFromActiveSheet$(e,"",({workbook:c,worksheet:a})=>new D.Observable(l=>D.merge(s.selectionMoveEnd$,new D.Observable(p=>{const f=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id],d=r.onCommandExecuted(h=>{f.includes(h.id)&&p.next(null)});return()=>d.dispose()})).subscribe(()=>{var f,d;const p=s.getCurrentSelections();if(p&&p[0]){const h=p[0].range,S=h.startRow,_=h.startColumn,v=(d=c.getStyles().get((f=a.getCell(S,_))==null?void 0:f.s))==null?void 0:d.n,P=v==null?void 0:v.pattern;let b=n.t("sheet.numfmt.general");if(P){const T=B.filter(x=>typeof x=="object"&&x.pattern).find(x=>m.isPatternEqualWithoutDecimal(P,x.pattern));T&&typeof T=="object"&&T.pattern?b=n.t(T.label):b=n.t("sheet.numfmt.moreFmt")}l.next(b)}})));return{label:ue,id:$.id,tooltip:"sheet.numfmt.title",type:I.MenuItemType.SELECTOR,selections:[{label:{name:me,hoverable:!1}}],value$:i,hidden$:I.getMenuHiddenObservable(t,o.UniverInstanceType.UNIVER_SHEET),disabled$:j.getCurrentRangeDisable$(t,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetSetCellStylePermission,g.WorksheetEditPermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}},ue="sheet.numfmt.moreNumfmtType",me="sheet.numfmt.moreNumfmtType.options",ut=t=>{var n;const e=o.useDependency(o.LocaleService),r=(n=t.value)!=null?n:e.t("sheet.numfmt.general");return u.jsx("span",{className:"more-numfmt-type",children:r})},mt=()=>{const t=o.useDependency(o.ICommandService),e=o.useDependency(o.LocaleService),r=o.useDependency(I.ILayoutService);o.useInjector();const n=o.useDependency(g.SheetsSelectionsService),s=a=>{const l=n.getCurrentLastSelection();if(!l)return;const p=l.range,f=[];o.Range.foreach(p,(d,h)=>{a?f.push({row:d,col:h,pattern:a,type:m.getPatternType(a)}):f.push({row:d,col:h})}),t.executeCommand(m.SetNumfmtCommand.id,{values:f}),r.focus()},i=a=>{if(a===0)s(null);else if(a===B.length-1)t.executeCommand($.id);else{const l=B[a];l.pattern&&s(l.pattern)}},c=1220;return u.jsx("div",{className:"more-numfmt-type-options",children:B.map((a,l)=>a==="|"?u.jsx("div",{className:"line m-t-4",onClick:p=>p.stopPropagation()},l):u.jsxs("div",{className:"option-item m-t-4",onClick:()=>{i(l)},children:[u.jsx("div",{children:e.t(a.label)}),u.jsx("div",{className:"m-l-26",children:a.pattern?m.getPatternPreview(a.pattern||"",c,e.getCurrentLocale()).result:""})]},l))})},dt={[I.RibbonStartGroup.FORMULAS_INSERT]:{[m.SetCurrencyCommand.id]:{order:4,menuItemFactory:it},[m.AddDecimalCommand.id]:{order:5,menuItemFactory:ot},[m.SubtractDecimalCommand.id]:{order:6,menuItemFactory:ct},[m.SetPercentCommand.id]:{order:7,menuItemFactory:at},[$.id]:{order:8,menuItemFactory:lt}}};var ht=Object.defineProperty,ft=Object.getOwnPropertyDescriptor,pt=(t,e,r,n)=>{for(var s=n>1?void 0:n?ft(e,r):e,i=t.length-1,c;i>=0;i--)(c=t[i])&&(s=(n?c(e,r,s):c(s))||s);return n&&s&&ht(e,r,s),s},se=(t,e)=>(r,n)=>e(r,n,t);let V=class extends o.Disposable{constructor(t,e){super(),this._componentManager=t,this._menuManagerService=e,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(dt),this.disposeWithMe(this._componentManager.register(ue,ut)),this.disposeWithMe(this._componentManager.register(me,mt))}};V=pt([se(0,o.Inject(I.ComponentManager)),se(1,I.IMenuManagerService)],V);var de=Object.defineProperty,vt=Object.getOwnPropertyDescriptor,St=(t,e,r)=>e in t?de(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,gt=(t,e,r,n)=>{for(var s=n>1?void 0:n?vt(e,r):e,i=t.length-1,c;i>=0;i--)(c=t[i])&&(s=(n?c(e,r,s):c(s))||s);return n&&s&&de(e,r,s),s},ie=(t,e)=>(r,n)=>e(r,n,t),he=(t,e,r)=>St(t,typeof e!="symbol"?e+"":e,r);const yt="SHEET_NUMFMT_UI_PLUGIN";exports.UniverSheetsNumfmtUIPlugin=class extends o.Plugin{constructor(e=Q,r,n){super(),this._config=e,this._injector=r,this._configService=n;const{menu:s,...i}=o.merge({},Q,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig(I.UI_PLUGIN_CONFIG_KEY,i)}onStarting(){o.registerDependencies(this._injector,[[k],[q],[L],[V]])}onRendered(){o.touchDependencies(this._injector,[[k],[q],[V]])}};he(exports.UniverSheetsNumfmtUIPlugin,"pluginName",yt);he(exports.UniverSheetsNumfmtUIPlugin,"type",o.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtUIPlugin=gt([o.DependentOn(j.UniverSheetsUIPlugin,m.UniverSheetsNumfmtPlugin),ie(1,o.Inject(o.Injector)),ie(2,o.IConfigService)],exports.UniverSheetsNumfmtUIPlugin);
package/lib/es/index.js CHANGED
@@ -3,7 +3,7 @@ var mt = (t, e, r) => e in t ? lt(t, e, { enumerable: !0, configurable: !0, writ
3
3
  var X = (t, e, r) => mt(t, typeof e != "symbol" ? e + "" : e, r);
4
4
  import { CommandType as Fe, Inject as N, ILocalStorageService as Le, useDependency as y, LocaleService as T, numfmt as Z, Disposable as pe, UniverInstanceType as E, CellValueType as L, Range as He, toDisposable as fe, DisposableCollection as ut, InterceptorEffectEnum as xe, ThemeService as dt, IUniverInstanceService as ve, ICommandService as ge, Injector as ke, Optional as ht, useInjector as ft, DependentOn as pt, Plugin as vt, merge as gt, registerDependencies as _t, touchDependencies as St, IConfigService as yt } from "@univerjs/core";
5
5
  import { currencySymbols as Pe, getDecimalFromPattern as ee, getCurrencyType as B, setPatternDecimal as j, getCurrencyFormatOptions as le, isPatternEqualWithoutDecimal as ie, CURRENCYFORMAT as bt, DATEFMTLISG as Ct, NUMBERFORMAT as It, getDateFormatOptions as Ae, getNumberFormatOptions as Be, isPatternHasDecimal as Nt, getPatternType as te, SetNumfmtCommand as We, getPatternPreviewIgnoreGeneral as Et, MenuCurrencyService as Tt, countryCurrencyMap as w, SetCurrencyCommand as Ve, AddDecimalCommand as Ge, SubtractDecimalCommand as Ke, SetPercentCommand as qe, getPatternPreview as xt, UniverSheetsNumfmtPlugin as Pt } from "@univerjs/sheets-numfmt";
6
- import { SheetSkeletonManagerService as jt, IEditorBridgeService as Rt, getCurrentRangeDisable$ as W, deriveStateFromActiveSheet$ as Mt, UniverSheetsUIPlugin as Ot } from "@univerjs/sheets-ui";
6
+ import { SheetSkeletonManagerService as jt, IEditorBridgeService as Rt, getCurrentRangeDisable$ as W, deriveStateFromActiveSheet$ as Ot, UniverSheetsUIPlugin as Mt } from "@univerjs/sheets-ui";
7
7
  import { ComponentManager as Ye, ISidebarService as wt, MenuItemType as V, getMenuHiddenObservable as G, ILayoutService as Ut, RibbonStartGroup as Dt, IMenuManagerService as $t, UI_PLUGIN_CONFIG_KEY as Ft } from "@univerjs/ui";
8
8
  import { IRenderManagerService as Lt } from "@univerjs/engine-render";
9
9
  import { INTERCEPTOR_POINT as Ht, RemoveNumfmtMutation as _e, SetNumfmtMutation as Se, SheetInterceptorService as Je, SheetsSelectionsService as ye, INumfmtService as ze, BEFORE_CELL_EDIT as kt, AFTER_CELL_EDIT as At, SetRangeValuesCommand as Bt, transformCellsToRange as Wt, factorySetNumfmtUndoMutation as Vt, factoryRemoveNumfmtUndoMutation as Gt, WorkbookEditablePermission as K, WorksheetEditPermission as q, WorksheetSetCellStylePermission as Y, RangeProtectionPermissionEditPoint as J } from "@univerjs/sheets";
@@ -34,10 +34,10 @@ var ue = { exports: {} }, $ = {};
34
34
  * This source code is licensed under the MIT license found in the
35
35
  * LICENSE file in the root directory of this source tree.
36
36
  */
37
- var Me;
37
+ var Oe;
38
38
  function tn() {
39
- if (Me) return $;
40
- Me = 1;
39
+ if (Oe) return $;
40
+ Oe = 1;
41
41
  var t = Zt, e = Symbol.for("react.element"), r = Symbol.for("react.fragment"), n = Object.prototype.hasOwnProperty, s = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, i = { key: !0, ref: !0, __self: !0, __source: !0 };
42
42
  function o(c, a, h) {
43
43
  var d, m = {}, u = null, p = null;
@@ -48,9 +48,9 @@ function tn() {
48
48
  }
49
49
  return $.Fragment = r, $.jsx = o, $.jsxs = o, $;
50
50
  }
51
- var Oe;
51
+ var Me;
52
52
  function nn() {
53
- return Oe || (Oe = 1, ue.exports = tn()), ue.exports;
53
+ return Me || (Me = 1, ue.exports = tn()), ue.exports;
54
54
  }
55
55
  var l = nn(), rn = Object.defineProperty, sn = Object.getOwnPropertyDescriptor, on = (t, e, r, n) => {
56
56
  for (var s = n > 1 ? void 0 : n ? sn(e, r) : e, i = t.length - 1, o; i >= 0; i--)
@@ -110,7 +110,7 @@ const we = "numfmtCurrency", an = (t) => {
110
110
  return oe(() => {
111
111
  e.addHabit("numfmtCurrency", []).then(() => {
112
112
  e.getHabit(we, [...Pe]).then((i) => {
113
- n(i), t && t(i);
113
+ n(i), t(i);
114
114
  });
115
115
  });
116
116
  }, []), { userHabitCurrency: r, mark: (i) => {
@@ -232,7 +232,7 @@ var _n = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em"
232
232
  }));
233
233
  });
234
234
  nt.displayName = "CheckMarkSingle";
235
- const Sn = "univer-custom-format-title", yn = "univer-custom-format-input", bn = "univer-custom-format-history-list", Cn = "univer-custom-format-history-list-item", In = "univer-custom-format-history-list-item-icon-wrap", Nn = "univer-custom-format-des", M = {
235
+ const Sn = "univer-custom-format-title", yn = "univer-custom-format-input", bn = "univer-custom-format-history-list", Cn = "univer-custom-format-history-list-item", In = "univer-custom-format-history-list-item-icon-wrap", Nn = "univer-custom-format-des", O = {
236
236
  customFormatTitle: Sn,
237
237
  customFormatInput: yn,
238
238
  customFormatHistoryList: bn,
@@ -266,14 +266,14 @@ function En(t) {
266
266
  }, u = () => {
267
267
  n(c);
268
268
  };
269
- return /* @__PURE__ */ l.jsxs("div", { className: M.customFormat, children: [
270
- /* @__PURE__ */ l.jsx("div", { className: M.customFormatTitle, children: o.t("sheet.numfmt.customFormat") }),
271
- /* @__PURE__ */ l.jsx(en, { placeholder: o.t("sheet.numfmt.customFormat"), onBlur: u, value: c, onChange: a, className: M.customFormatInput }),
272
- /* @__PURE__ */ l.jsx("div", { className: M.customFormatHistoryList, children: h.map((p) => /* @__PURE__ */ l.jsxs("div", { onClick: () => m(p), className: M.customFormatHistoryListItem, children: [
273
- /* @__PURE__ */ l.jsx("div", { className: M.customFormatHistoryListItemIconWrap, children: c === p && /* @__PURE__ */ l.jsx(nt, {}) }),
269
+ return /* @__PURE__ */ l.jsxs("div", { className: O.customFormat, children: [
270
+ /* @__PURE__ */ l.jsx("div", { className: O.customFormatTitle, children: o.t("sheet.numfmt.customFormat") }),
271
+ /* @__PURE__ */ l.jsx(en, { placeholder: o.t("sheet.numfmt.customFormat"), onBlur: u, value: c, onChange: a, className: O.customFormatInput }),
272
+ /* @__PURE__ */ l.jsx("div", { className: O.customFormatHistoryList, children: h.map((p) => /* @__PURE__ */ l.jsxs("div", { onClick: () => m(p), className: O.customFormatHistoryListItem, children: [
273
+ /* @__PURE__ */ l.jsx("div", { className: O.customFormatHistoryListItemIconWrap, children: c === p && /* @__PURE__ */ l.jsx(nt, {}) }),
274
274
  /* @__PURE__ */ l.jsx("div", { children: p })
275
275
  ] }, p)) }),
276
- /* @__PURE__ */ l.jsx("div", { className: M.customFormatDes, children: o.t("sheet.numfmt.customFormatDes") })
276
+ /* @__PURE__ */ l.jsx("div", { className: O.customFormatDes, children: o.t("sheet.numfmt.customFormatDes") })
277
277
  ] });
278
278
  }
279
279
  const Tn = (t) => {
@@ -300,7 +300,7 @@ const Tn = (t) => {
300
300
  }, Pn = (t) => !t, jn = (t) => {
301
301
  const r = y(T).t;
302
302
  return t.action.current = () => "", /* @__PURE__ */ l.jsx("div", { children: /* @__PURE__ */ l.jsx("div", { className: "describe m-t-14", children: r("sheet.numfmt.generalDes") }) });
303
- }, Rn = (t) => Be().some((e) => ie(e.value, t)), Mn = (t) => {
303
+ }, Rn = (t) => Be().some((e) => ie(e.value, t)), On = (t) => {
304
304
  const e = y(T), r = R(Be, []), [n, s] = b(() => ee(t.defaultPattern || "", 0)), [i, o] = b(() => {
305
305
  const m = r.find((u) => ie(u.value, t.defaultPattern || ""));
306
306
  return (m == null ? void 0 : m.value) || r[0].value;
@@ -328,23 +328,23 @@ const Tn = (t) => {
328
328
  /* @__PURE__ */ l.jsx("div", { className: "m-t-8", children: /* @__PURE__ */ l.jsx(Ee, { onChange: d, options: r, value: i }) }),
329
329
  /* @__PURE__ */ l.jsx("div", { className: "describe m-t-14", children: e.t("sheet.numfmt.thousandthPercentileDes") })
330
330
  ] });
331
- }, On = (t) => {
331
+ }, Mn = (t) => {
332
332
  const { defaultValue: e, defaultPattern: r, row: n, col: s } = t.value, i = y(T), o = be(() => ""), c = i.t, a = ln(), h = R(
333
333
  () => [
334
334
  { label: "sheet.numfmt.general", component: jn },
335
335
  { label: "sheet.numfmt.accounting", component: un },
336
336
  { label: "sheet.numfmt.currency", component: hn },
337
337
  { label: "sheet.numfmt.date", component: xn },
338
- { label: "sheet.numfmt.thousandthPercentile", component: Mn },
338
+ { label: "sheet.numfmt.thousandthPercentile", component: On },
339
339
  { label: "sheet.numfmt.customFormat", component: En }
340
340
  ].map((_) => ({ ..._, label: c(_.label) })),
341
341
  []
342
342
  ), [d, m] = b(g), [u, p] = b(() => `${n}_${s}`), { mark: v, userHabitCurrency: f } = an(() => p(`${n}_${s}_userCurrency'`)), S = R(() => {
343
343
  var _;
344
- return (_ = h.find((O) => O.label === d)) == null ? void 0 : _.component;
344
+ return (_ = h.find((M) => M.label === d)) == null ? void 0 : _.component;
345
345
  }, [d]);
346
346
  function g() {
347
- return [Pn, mn, dn, Tn, Rn].reduce((O, ct, at) => O || (ct(r) ? h[at].label : ""), "") || h[0].label;
347
+ return [Pn, mn, dn, Tn, Rn].reduce((M, ct, at) => M || (ct(r) ? h[at].label : ""), "") || h[0].label;
348
348
  }
349
349
  const C = h.map((_) => ({
350
350
  label: _.label,
@@ -354,8 +354,8 @@ const Tn = (t) => {
354
354
  }, z = (_) => {
355
355
  t.onChange({ type: "change", value: _ });
356
356
  }, ce = () => {
357
- const _ = o.current() || "", O = B(_);
358
- O && v(O), t.onChange({ type: "confirm", value: _ });
357
+ const _ = o.current() || "", M = B(_);
358
+ M && v(M), t.onChange({ type: "confirm", value: _ });
359
359
  }, D = () => {
360
360
  t.onChange({ type: "cancel", value: "" });
361
361
  }, ae = {
@@ -462,7 +462,7 @@ let A = class extends pe {
462
462
  });
463
463
  }
464
464
  _initPanel() {
465
- this._componentManager.register(Ue, On);
465
+ this._componentManager.register(Ue, Mn);
466
466
  }
467
467
  _initRealTimeRenderingInterceptor() {
468
468
  const e = new U((n) => {
@@ -860,7 +860,7 @@ const Q = [
860
860
  hidden$: G(t, E.UNIVER_SHEET),
861
861
  disabled$: W(t, { workbookTypes: [K], worksheetTypes: [q, Y], rangeTypes: [J] })
862
862
  }), Kn = (t) => {
863
- const e = t.get(ve), r = t.get(ge), n = t.get(T), s = t.get(ye), i = Mt(e, "", ({ workbook: o, worksheet: c }) => new U(
863
+ const e = t.get(ve), r = t.get(ge), n = t.get(T), s = t.get(ye), i = Ot(e, "", ({ workbook: o, worksheet: c }) => new U(
864
864
  (a) => qt(
865
865
  s.selectionMoveEnd$,
866
866
  new U((h) => {
@@ -1017,7 +1017,7 @@ let se = class extends vt {
1017
1017
  ot(se, "pluginName", nr);
1018
1018
  ot(se, "type", E.UNIVER_SHEET);
1019
1019
  se = tr([
1020
- pt(Ot, Pt),
1020
+ pt(Mt, Pt),
1021
1021
  $e(1, N(ke)),
1022
1022
  $e(2, yt)
1023
1023
  ], se);
package/lib/index.css CHANGED
@@ -1 +1 @@
1
- *,:before,:after{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(63 131 248 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }::backdrop{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-gradient-from-position: ;--tw-gradient-via-position: ;--tw-gradient-to-position: ;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(63 131 248 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: ;--tw-contain-size: ;--tw-contain-layout: ;--tw-contain-paint: ;--tw-contain-style: }*{scrollbar-color:initial;scrollbar-width:initial}@keyframes enter{0%{opacity:var(--tw-enter-opacity, 1);transform:translate3d(var(--tw-enter-translate-x, 0),var(--tw-enter-translate-y, 0),0) scale3d(var(--tw-enter-scale, 1),var(--tw-enter-scale, 1),var(--tw-enter-scale, 1)) rotate(var(--tw-enter-rotate, 0))}}@keyframes exit{to{opacity:var(--tw-exit-opacity, 1);transform:translate3d(var(--tw-exit-translate-x, 0),var(--tw-exit-translate-y, 0),0) scale3d(var(--tw-exit-scale, 1),var(--tw-exit-scale, 1),var(--tw-exit-scale, 1)) rotate(var(--tw-exit-rotate, 0))}}.options{display:flex;justify-content:space-between}.options .w-140{width:140px}.options .w-120{width:120px}.univer-custom-format-title{margin-top:16px}.univer-custom-format-input{margin-top:8px;width:100%}.univer-custom-format-history-list{margin-top:8px;padding:8px;border-radius:8px;border:1px solid var(---Grey-200, #e5e5e5);max-height:400px;overflow:scroll}.univer-custom-format-history-list-item{padding:6px 0;display:flex;gap:6px;align-items:center;cursor:pointer}.univer-custom-format-history-list-item-icon-wrap{width:16px;display:flex;align-items:center;color:#274fee}.univer-custom-format-des{margin-top:8px;color:var(---Grey-600, #7a7a7a);font-size:12px;font-style:normal;font-weight:400;line-height:16px}.numfmt-panel{overflow-y:auto;display:flex;flex-direction:column;justify-content:space-between;height:100%}.numfmt-panel .group-title{font-size:16px;color:rgba(var(--color-black))}.numfmt-panel .label{font-size:15px;color:rgba(var(--grey-400))}.numfmt-panel .describe{font-size:13px;line-height:20px;color:rgba(var(--grey-600))}.numfmt-panel .preview{height:36px;padding:0 16px;font-size:14px;line-height:36px;color:var(--color-black);border:1px solid rgb(var(--grey-200));border-radius:4px}.numfmt-panel .btn-list{display:flex;justify-content:flex-end}.numfmt-panel .m-r-12{margin-right:12px}.numfmt-panel .m-t-16{margin-top:16px}.numfmt-panel .m-t-14{margin-top:14px}.numfmt-panel .m-t-8{margin-top:8px}.numfmt-panel .m-b-20{margin-bottom:20px}.more-numfmt-type{display:flex;flex-shrink:0;padding:0 4px;font-size:13px;color:var(--black)}.more-numfmt-type .icon{display:flex;align-items:center;height:auto;padding-left:8px;color:rgb(var(--grey-400))}.more-numfmt-type-options .line{width:100%;height:1px;background-color:rgb(var(--grey-200))}.more-numfmt-type-options .m-t-4{margin-top:4px}.more-numfmt-type-options .option-item{display:flex;align-items:center;justify-content:space-between;height:28px;padding:0 8px;font-size:13px}.more-numfmt-type-options .option-item:hover{background-color:rgb(var(--grey-100));border-radius:var(--border-radius-base)}.more-numfmt-type-options .m-l-26{margin-left:26px}
1
+ .options{display:flex;justify-content:space-between}.options .w-140{width:140px}.options .w-120{width:120px}.univer-custom-format-title{margin-top:16px}.univer-custom-format-input{margin-top:8px;width:100%}.univer-custom-format-history-list{margin-top:8px;padding:8px;border-radius:8px;border:1px solid var(---Grey-200, #e5e5e5);max-height:400px;overflow:scroll}.univer-custom-format-history-list-item{padding:6px 0;display:flex;gap:6px;align-items:center;cursor:pointer}.univer-custom-format-history-list-item-icon-wrap{width:16px;display:flex;align-items:center;color:#274fee}.univer-custom-format-des{margin-top:8px;color:var(---Grey-600, #7a7a7a);font-size:12px;font-style:normal;font-weight:400;line-height:16px}.numfmt-panel{overflow-y:auto;display:flex;flex-direction:column;justify-content:space-between;height:100%}.numfmt-panel .group-title{font-size:16px;color:rgba(var(--color-black))}.numfmt-panel .label{font-size:15px;color:rgba(var(--grey-400))}.numfmt-panel .describe{font-size:13px;line-height:20px;color:rgba(var(--grey-600))}.numfmt-panel .preview{height:36px;padding:0 16px;font-size:14px;line-height:36px;color:var(--color-black);border:1px solid rgb(var(--grey-200));border-radius:4px}.numfmt-panel .btn-list{display:flex;justify-content:flex-end}.numfmt-panel .m-r-12{margin-right:12px}.numfmt-panel .m-t-16{margin-top:16px}.numfmt-panel .m-t-14{margin-top:14px}.numfmt-panel .m-t-8{margin-top:8px}.numfmt-panel .m-b-20{margin-bottom:20px}.more-numfmt-type{display:flex;flex-shrink:0;padding:0 4px;font-size:13px;color:var(--black)}.more-numfmt-type .icon{display:flex;align-items:center;height:auto;padding-left:8px;color:rgb(var(--grey-400))}.more-numfmt-type-options .line{width:100%;height:1px;background-color:rgb(var(--grey-200))}.more-numfmt-type-options .m-t-4{margin-top:4px}.more-numfmt-type-options .option-item{display:flex;align-items:center;justify-content:space-between;height:28px;padding:0 8px;font-size:13px}.more-numfmt-type-options .option-item:hover{background-color:rgb(var(--grey-100));border-radius:var(--border-radius-base)}.more-numfmt-type-options .m-l-26{margin-left:26px}
package/lib/umd/index.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(b,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/sheets-numfmt"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("@univerjs/engine-render"),require("@univerjs/sheets"),require("rxjs"),require("rxjs/operators"),require("react"),require("@univerjs/design"),require("@univerjs/engine-numfmt")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-numfmt","@univerjs/sheets-ui","@univerjs/ui","@univerjs/engine-render","@univerjs/sheets","rxjs","rxjs/operators","react","@univerjs/design","@univerjs/engine-numfmt"],s):(b=typeof globalThis<"u"?globalThis:b||self,s(b.UniverSheetsNumfmtUi={},b.UniverCore,b.UniverSheetsNumfmt,b.UniverSheetsUi,b.UniverUi,b.UniverEngineRender,b.UniverSheets,b.rxjs,b.rxjs.operators,b.React,b.UniverDesign,b.UniverEngineNumfmt))})(this,function(b,s,m,R,P,ve,S,O,A,g,E,ee){"use strict";var pt=Object.defineProperty;var ft=(b,s,m)=>s in b?pt(b,s,{enumerable:!0,configurable:!0,writable:!0,value:m}):b[s]=m;var Y=(b,s,m)=>ft(b,typeof s!="symbol"?s+"":s,m);const te={},J={id:"sheet.operation.close.numfmt.panel",type:s.CommandType.OPERATION,handler:()=>!0},w={id:"sheet.operation.open.numfmt.panel",type:s.CommandType.OPERATION,handler:e=>(e.get(k).openPanel(),!0)};var z={exports:{}},F={};/**
1
+ (function(b,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/sheets-numfmt"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("@univerjs/engine-render"),require("@univerjs/sheets"),require("rxjs"),require("rxjs/operators"),require("react"),require("@univerjs/design"),require("@univerjs/engine-numfmt")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-numfmt","@univerjs/sheets-ui","@univerjs/ui","@univerjs/engine-render","@univerjs/sheets","rxjs","rxjs/operators","react","@univerjs/design","@univerjs/engine-numfmt"],s):(b=typeof globalThis<"u"?globalThis:b||self,s(b.UniverSheetsNumfmtUi={},b.UniverCore,b.UniverSheetsNumfmt,b.UniverSheetsUi,b.UniverUi,b.UniverEngineRender,b.UniverSheets,b.rxjs,b.rxjs.operators,b.React,b.UniverDesign,b.UniverEngineNumfmt))})(this,function(b,s,m,R,P,ve,S,O,A,g,E,ee){"use strict";var pt=Object.defineProperty;var ft=(b,s,m)=>s in b?pt(b,s,{enumerable:!0,configurable:!0,writable:!0,value:m}):b[s]=m;var Y=(b,s,m)=>ft(b,typeof s!="symbol"?s+"":s,m);const te={},J={id:"sheet.operation.close.numfmt.panel",type:s.CommandType.OPERATION,handler:()=>!0},w={id:"sheet.operation.open.numfmt.panel",type:s.CommandType.OPERATION,handler:t=>(t.get(k).openPanel(),!0)};var z={exports:{}},F={};/**
2
2
  * @license React
3
3
  * react-jsx-runtime.production.min.js
4
4
  *
@@ -6,4 +6,4 @@
6
6
  *
7
7
  * This source code is licensed under the MIT license found in the
8
8
  * LICENSE file in the root directory of this source tree.
9
- */var ne;function he(){if(ne)return F;ne=1;var e=g,t=Symbol.for("react.element"),r=Symbol.for("react.fragment"),n=Object.prototype.hasOwnProperty,i=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a={key:!0,ref:!0,__self:!0,__source:!0};function o(c,l,v){var f,d={},p=null,y=null;v!==void 0&&(p=""+v),l.key!==void 0&&(p=""+l.key),l.ref!==void 0&&(y=l.ref);for(f in l)n.call(l,f)&&!a.hasOwnProperty(f)&&(d[f]=l[f]);if(c&&c.defaultProps)for(f in l=c.defaultProps,l)d[f]===void 0&&(d[f]=l[f]);return{$$typeof:t,type:c,key:p,ref:y,props:d,_owner:i.current}}return F.Fragment=r,F.jsx=o,F.jsxs=o,F}var re;function Se(){return re||(re=1,z.exports=he()),z.exports}var u=Se(),ye=Object.defineProperty,ge=Object.getOwnPropertyDescriptor,_e=(e,t,r,n)=>{for(var i=n>1?void 0:n?ge(t,r):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=(n?o(t,r,i):o(i))||i);return n&&i&&ye(t,r,i),i},be=(e,t)=>(r,n)=>t(r,n,e);const X=g.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(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,c)=>{const l=c.length;return{value:a,priority:l-o}});return t.sort((a,o)=>{var v,f;const c=((v=i.find(d=>d.value===a))==null?void 0:v.priority)||-1;return(((f=i.find(d=>d.value===o))==null?void 0:f.priority)||-1)-c})}return n||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};L=_e([be(0,s.Inject(s.ILocalStorageService))],L);const ie="numfmtCurrency",Ce=e=>{const t=s.useDependency(L),[r,n]=g.useState(m.currencySymbols);return g.useEffect(()=>{t.addHabit("numfmtCurrency",[]).then(()=>{t.getHabit(ie,[...m.currencySymbols]).then(a=>{n(a),e&&e(a)})})},[]),{userHabitCurrency:r,mark:a=>{t.markHabit(ie,a)}}},Ie=()=>{const e=g.useRef([]),[t,r]=g.useState({});return g.useEffect(()=>{e.current.forEach(i=>{i()}),e.current=[]},[t]),i=>{e.current.push(i),r({})}},Pe=e=>!!m.getCurrencyType(e)&&e.startsWith("_("),Te=e=>{const{defaultPattern:t,action:r,onChange:n}=e,[i,a]=g.useState(()=>m.getDecimalFromPattern(t||"",2)),o=g.useContext(X),[c,l]=g.useState(()=>m.getCurrencyType(t)||o[0]),v=g.useMemo(()=>o.map(_=>({label:_,value:_})),[]),d=s.useDependency(s.LocaleService).t;r.current=()=>m.setPatternDecimal(`_("${c}"* #,##0${i>0?".0":""}_)`,i);const p=_=>{l(_),n(m.setPatternDecimal(`_("${_}"* #,##0${i>0?".0":""}_)`,i))},y=_=>{const h=_||0;a(h),n(m.setPatternDecimal(`_("${c}"* #,##0${h>0?".0":""}_)`,h))};return u.jsxs("div",{children:[u.jsxs("div",{className:"m-t-16 options",children:[u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:d("sheet.numfmt.decimalLength")}),u.jsx("div",{className:"m-t-8 w-120",children:u.jsx(E.InputNumber,{value:i,max:20,min:0,onChange:y})})]}),u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:d("sheet.numfmt.currencyType")}),u.jsx("div",{className:"m-t-8 w-140",children:u.jsx(E.Select,{onChange:p,options:v,value:c})})]})]}),u.jsx("div",{className:"describe m-t-14",children:d("sheet.numfmt.accountingDes")})]})},Ee=e=>!!m.getCurrencyType(e)&&!e.startsWith("_("),je=e=>{const r=s.useDependency(s.LocaleService).t,n=g.useContext(X),[i,a]=g.useState(()=>m.getCurrencyType(e.defaultPattern)||n[0]),[o,c]=g.useState(()=>m.getDecimalFromPattern(e.defaultPattern||"",2)),[l,v]=g.useState(()=>{var C;const h=m.getCurrencyFormatOptions(i);return((C=h.find(M=>m.isPatternEqualWithoutDecimal(M.value,e.defaultPattern)))==null?void 0:C.value)||h[0].value}),f=g.useMemo(()=>m.getCurrencyFormatOptions(i),[i]),d=g.useMemo(()=>n.map(h=>({label:h,value:h})),[n]);e.action.current=()=>m.setPatternDecimal(l,o);const p=h=>{if(h===void 0)return;a(h);const T=m.getCurrencyFormatOptions(h)[0].value;v(T),e.onChange(m.setPatternDecimal(T,o))},y=h=>{h!==void 0&&(v(h),e.onChange(m.setPatternDecimal(h,o)))},_=h=>{c(h||0),e.onChange(m.setPatternDecimal(l,h||0))};return u.jsxs("div",{children:[u.jsxs("div",{className:"m-t-16 options",children:[u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:r("sheet.numfmt.decimalLength")}),u.jsx("div",{className:"m-t-8 w-120",children:u.jsx(E.InputNumber,{value:o,max:20,min:0,onChange:_})})]}),u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:r("sheet.numfmt.currencyType")}),u.jsx("div",{className:"m-t-8 w-140",children:u.jsx(E.Select,{onChange:p,options:d,value:i})})]})]}),u.jsx("div",{className:"m-t-16 label",children:r("sheet.numfmt.negType")}),u.jsx("div",{className:"m-t-8",children:u.jsx(E.SelectList,{onChange:y,options:f,value:l})}),u.jsx("div",{className:"describe m-t-14",children:r("sheet.numfmt.currencyDes")})]})};var j=function(){return j=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},j.apply(this,arguments)},Me=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r},se=g.forwardRef(function(e,t){var r=e.icon,n=e.id,i=e.className,a=e.extend,o=Me(e,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(n," ").concat(i||"").trim(),l=g.useRef("_".concat(Re()));return ae(r,"".concat(n),{defIds:r.defIds,idSuffix:l.current},j({ref:t,className:c},o),a)});function ae(e,t,r,n,i){return g.createElement(e.tag,j(j({key:t},xe(e,r,i)),n),(De(e,r).children||[]).map(function(a,o){return ae(a,"".concat(t,"-").concat(e.tag,"-").concat(o),r,void 0,i)}))}function xe(e,t,r){var n=j({},e.attrs);r!=null&&r.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=r.colorChannel1);var i=t.defIds;return!i||i.length===0||(e.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(function(a){var o=a[0],c=a[1];typeof c=="string"&&(n[o]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function De(e,t){var r,n=t.defIds;return!n||n.length===0?e:e.tag==="defs"&&(!((r=e.children)===null||r===void 0)&&r.length)?j(j({},e),{children:e.children.map(function(i){return typeof i.attrs.id=="string"&&n&&n.indexOf(i.attrs.id)>-1?j(j({},i),{attrs:j(j({},i.attrs),{id:i.attrs.id+t.idSuffix})}):i})}):e}function Re(){return Math.random().toString(36).substring(2,8)}se.displayName="UniverIcon";var Oe={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},oe=g.forwardRef(function(e,t){return g.createElement(se,Object.assign({},e,{id:"check-mark-single",ref:t,icon:Oe}))});oe.displayName="CheckMarkSingle";const U={customFormatTitle:"univer-custom-format-title",customFormatInput:"univer-custom-format-input",customFormatHistoryList:"univer-custom-format-history-list",customFormatHistoryListItem:"univer-custom-format-history-list-item",customFormatHistoryListItemIconWrap:"univer-custom-format-history-list-item-icon-wrap",customFormatDes:"univer-custom-format-des"},Z="customFormat",Q="numfmt_custom_pattern";function Ue(e){const{defaultPattern:t,action:r,onChange:n}=e,i=s.useDependency(L),a=s.useDependency(s.ILocalStorageService),o=s.useDependency(s.LocaleService),[c,l]=g.useState(t);r.current=()=>(i.markHabit(Z,c),a.getItem(Q).then((y=[])=>{const _=[...new Set([c,...y||[]])].splice(0,10).filter(h=>!!h);a.setItem(Q,_)}),c);const[v,f]=g.useState([]);g.useEffect(()=>{a.getItem(Q).then(y=>{const _=[...m.CURRENCYFORMAT.map(h=>h.suffix("$")),...m.DATEFMTLISG.map(h=>h.suffix),...m.NUMBERFORMAT.map(h=>h.suffix)];_.push(...y||[]),i.addHabit(Z,[]).finally(()=>{i.getHabit(Z,_).then(h=>{f([...new Set(h)])})})})},[]);const d=y=>{l(y),n(y)},p=()=>{n(c)};return u.jsxs("div",{className:U.customFormat,children:[u.jsx("div",{className:U.customFormatTitle,children:o.t("sheet.numfmt.customFormat")}),u.jsx(E.Input,{placeholder:o.t("sheet.numfmt.customFormat"),onBlur:p,value:c,onChange:l,className:U.customFormatInput}),u.jsx("div",{className:U.customFormatHistoryList,children:v.map(y=>u.jsxs("div",{onClick:()=>d(y),className:U.customFormatHistoryListItem,children:[u.jsx("div",{className:U.customFormatHistoryListItemIconWrap,children:c===y&&u.jsx(oe,{})}),u.jsx("div",{children:y})]},y))}),u.jsx("div",{className:U.customFormatDes,children:o.t("sheet.numfmt.customFormatDes")})]})}const Ne=e=>{const t=s.numfmt.getInfo(e);return m.getDateFormatOptions().map(r=>r.value).includes(e)||["date","datetime","time"].includes(t.type)},we=e=>{const t=g.useMemo(m.getDateFormatOptions,[]),n=s.useDependency(s.LocaleService).t,[i,a]=g.useState(()=>{if(e.defaultPattern){const c=t.find(l=>l.value===e.defaultPattern);if(c)return c.value}return t[0].value});e.action.current=()=>i;const o=c=>{c!==void 0&&(a(c),e.onChange(c))};return u.jsxs("div",{children:[u.jsx("div",{className:"m-t-16 label",children:n("sheet.numfmt.dateType")}),u.jsx("div",{className:"m-t-8",children:u.jsx(E.SelectList,{value:i,options:t,onChange:o})}),u.jsx("div",{className:"describe m-t-14",children:n("sheet.numfmt.dateDes")})]})},Fe=e=>!e,Le=e=>{const r=s.useDependency(s.LocaleService).t;return e.action.current=()=>"",u.jsx("div",{children:u.jsx("div",{className:"describe m-t-14",children:r("sheet.numfmt.generalDes")})})},ke=e=>m.getNumberFormatOptions().some(t=>m.isPatternEqualWithoutDecimal(t.value,e)),He=e=>{const t=s.useDependency(s.LocaleService),r=g.useMemo(m.getNumberFormatOptions,[]),[n,i]=g.useState(()=>m.getDecimalFromPattern(e.defaultPattern||"",0)),[a,o]=g.useState(()=>{const d=r.find(p=>m.isPatternEqualWithoutDecimal(p.value,e.defaultPattern||""));return(d==null?void 0:d.value)||r[0].value}),c=g.useMemo(()=>m.setPatternDecimal(a,Number(n||0)),[a,n]),l=g.useMemo(()=>!m.isPatternHasDecimal(a),[a]),v=d=>{i(d||0),e.onChange(m.setPatternDecimal(a,Number(d||0)))},f=d=>{d!==void 0&&(i(m.getDecimalFromPattern(d,0)),o(d),e.onChange(d))};return e.action.current=()=>c,u.jsxs("div",{children:[u.jsx("div",{className:"m-t-16 label",children:t.t("sheet.numfmt.decimalLength")}),u.jsx("div",{className:"m-t-8",children:u.jsx(E.InputNumber,{disabled:l,value:n,max:20,min:0,onChange:v})}),u.jsxs("div",{className:"m-t-16 label",children:[" ",t.t("sheet.numfmt.negType")]}),u.jsx("div",{className:"m-t-8",children:u.jsx(E.SelectList,{onChange:f,options:r,value:a})}),u.jsx("div",{className:"describe m-t-14",children:t.t("sheet.numfmt.thousandthPercentileDes")})]})},We=e=>{const{defaultValue:t,defaultPattern:r,row:n,col:i}=e.value,a=s.useDependency(s.LocaleService),o=g.useRef(()=>""),c=a.t,l=Ie(),v=g.useMemo(()=>[{label:"sheet.numfmt.general",component:Le},{label:"sheet.numfmt.accounting",component:Te},{label:"sheet.numfmt.currency",component:je},{label:"sheet.numfmt.date",component:we},{label:"sheet.numfmt.thousandthPercentile",component:He},{label:"sheet.numfmt.customFormat",component:Ue}].map(I=>({...I,label:c(I.label)})),[]),[f,d]=g.useState(C),[p,y]=g.useState(()=>`${n}_${i}`),{mark:_,userHabitCurrency:h}=Ce(()=>y(`${n}_${i}_userCurrency'`)),T=g.useMemo(()=>{var I;return(I=v.find(N=>N.label===f))==null?void 0:I.component},[f]);function C(){return[Fe,Pe,Ee,Ne,ke].reduce((N,mt,dt)=>N||(mt(r)?v[dt].label:""),"")||v[0].label}const M=v.map(I=>({label:I.label,value:I.label})),D=I=>{d(I),l(()=>e.onChange({type:"change",value:o.current()||""}))},K=I=>{e.onChange({type:"change",value:I})},$=()=>{const I=o.current()||"",N=m.getCurrencyType(I);N&&_(N),e.onChange({type:"confirm",value:I})},W=()=>{e.onChange({type:"cancel",value:""})},q={onChange:K,defaultValue:t,defaultPattern:r,action:o};return g.useEffect(()=>{d(C()),y(`${n}_${i}`)},[n,i]),u.jsxs("div",{className:"numfmt-panel p-b-20",children:[u.jsxs("div",{children:[u.jsx("div",{className:"label m-t-14",children:c("sheet.numfmt.numfmtType")}),u.jsx("div",{className:"m-t-8",children:u.jsx(E.Select,{onChange:D,options:M,value:f,style:{width:"100%"}})}),u.jsx("div",{children:T&&u.jsx(X.Provider,{value:h,children:g.createElement(T,{...q,key:p})})})]}),u.jsxs("div",{className:"btn-list m-t-14 m-b-20",children:[u.jsx(E.Button,{size:"small",onClick:W,className:"m-r-12",children:c("sheet.numfmt.cancel")}),u.jsx(E.Button,{type:"primary",size:"small",onClick:$,children:c("sheet.numfmt.confirm")})]})]})};var Ae=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,Ve=(e,t,r,n)=>{for(var i=n>1?void 0:n?Be(t,r):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=(n?o(t,r,i):o(i))||i);return n&&i&&Ae(t,r,i),i},x=(e,t)=>(r,n)=>t(r,n,e);const ce="SHEET_NUMFMT_PANEL";let k=class extends s.Disposable{constructor(t,r,n,i,a,o,c,l,v,f){super();Y(this,"_previewPattern","");Y(this,"_sidebarDisposable",null);this._sheetInterceptorService=t,this._themeService=r,this._univerInstanceService=n,this._commandService=i,this._selectionManagerService=a,this._renderManagerService=o,this._numfmtService=c,this._componentManager=l,this._sidebarService=v,this._localeService=f,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener()}openPanel(){var T;const t=this._sidebarService,r=this._selectionManagerService,n=this._commandService,i=this._univerInstanceService,a=this._numfmtService,o=this._localeService,l=(((T=r.getCurrentSelections())==null?void 0:T.map(C=>C.range))||[])[0];if(!l)return!1;const v=i.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),f=v.getActiveSheet();if(!f)return!1;const d=f.getCellRaw(l.startRow,l.startColumn),p=a.getValue(v.getUnitId(),f.getSheetId(),l.startRow,l.startColumn);let y="";p&&(y=p.pattern);const _=(d==null?void 0:d.t)===s.CellValueType.NUMBER?d.v:12345678,h={onChange:C=>{var M;if(C.type==="change")this._previewPattern=C.value,this._forceUpdate();else if(C.type==="confirm"){const D=((M=r.getCurrentSelections())==null?void 0:M.map(W=>W.range))||[],K={values:[]},$=m.getPatternType(C.value);D.forEach(W=>{s.Range.foreach(W,(q,I)=>{K.values.push({row:q,col:I,pattern:C.value,type:$})})}),n.executeCommand(m.SetNumfmtCommand.id,K),t.close()}else C.type==="cancel"&&t.close()},value:{defaultPattern:y,defaultValue:_,row:l.startRow,col:l.startColumn}};return this._sidebarDisposable=t.open({header:{title:o.t("sheet.numfmt.title")},children:{label:ce,...h},onClose:()=>{this._forceUpdate(),n.executeCommand(J.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(R.SheetSkeletonManagerService).reCalculate(),(n=r==null?void 0:r.mainComponent)==null||n.makeDirty()}_initCommands(){[w,J].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initPanel(){this._componentManager.register(ce,We)}_initRealTimeRenderingInterceptor(){const t=new O.Observable(n=>{this._commandService.onCommandExecuted(i=>{i.id===w.id&&n.next(!0),i.id===J.id&&n.next(!1)})}),r=O.combineLatest([t,this._selectionManagerService.selectionMoveEnd$.pipe(A.map(n=>n?n.map(i=>i.range):[]))]);this.disposeWithMe(s.toDisposable(r.pipe(A.switchMap(([n,i])=>new O.Observable(a=>{const o=new s.DisposableCollection;return n&&i.length&&a.next({selectionRanges:i,disposableCollection:o}),()=>{o.dispose()}})),A.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:n,selectionRanges:i})=>{var o,c;const a=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);this.openPanel(),n.add(this._sheetInterceptorService.intercept(S.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,effect:s.InterceptorEffectEnum.Value|s.InterceptorEffectEnum.Style,handler:(l,v,f)=>{const{row:d,col:p}=v,y=f(l)||{};if(i.find(_=>_.startColumn<=p&&_.endColumn>=p&&_.startRow<=d&&_.endRow>=d)){const _=v.worksheet.getCellRaw(d,p),h=_==null?void 0:_.v,T=_==null?void 0:_.t;if(h==null||T!==s.CellValueType.NUMBER||this._previewPattern===null)return y;const C=m.getPatternPreviewIgnoreGeneral(this._previewPattern,h,this._localeService.getCurrentLocale());if(C.color){const D=this._themeService.getCurrentTheme()[`${C.color}500`];return{...y,v:C.result,t:s.CellValueType.STRING,s:{cl:{rgb:D}}}}return{...y,v:C.result,t:s.CellValueType.STRING}}return y}})),(c=(o=this._renderManagerService.getRenderById(a.getUnitId()))==null?void 0:o.mainComponent)==null||c.makeDirty()})))}_commandExecutedListener(){const t=[S.RemoveNumfmtMutation.id,S.SetNumfmtMutation.id];this.disposeWithMe(new O.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(A.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)})}};k=Ve([x(0,s.Inject(S.SheetInterceptorService)),x(1,s.Inject(s.ThemeService)),x(2,s.IUniverInstanceService),x(3,s.ICommandService),x(4,s.Inject(S.SheetsSelectionsService)),x(5,ve.IRenderManagerService),x(6,S.INumfmtService),x(7,s.Inject(P.ComponentManager)),x(8,P.ISidebarService),x(9,s.Inject(s.LocaleService))],k);var Ge=Object.defineProperty,Ke=Object.getOwnPropertyDescriptor,Ye=(e,t,r,n)=>{for(var i=n>1?void 0:n?Ke(t,r):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=(n?o(t,r,i):o(i))||i);return n&&i&&Ge(t,r,i),i},H=(e,t)=>(r,n)=>t(r,n,e);const Je=()=>{let e=[];return{add:(i,a,o,c,l)=>e.push({unitId:i,subUnitId:a,row:o,col:c,value:l}),getEffects:()=>e,clean:()=>{e=[]}}};let B=class extends s.Disposable{constructor(t,r,n,i,a){super();Y(this,"_collectEffectMutation",Je());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(S.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(m.getPatternType(o.pattern)){case"scientific":case"currency":case"grouped":case"number":return r.worksheet.getCellRaw(i,a);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(S.AFTER_CELL_EDIT,{handler:(t,r,n)=>{var f,d,p,y;this._collectEffectMutation.clean();const i=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col),a=(f=i&&m.getPatternType(i.pattern))!=null?f:"",o=()=>{i&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,null)};if(!(t!=null&&t.v)&&!(t!=null&&t.p)||(i==null?void 0:i.pattern)===ee.DEFAULT_TEXT_FORMAT)return n(t);const c=(d=t.p)==null?void 0:d.body,l=(y=(p=t==null?void 0:t.p)==null?void 0:p.body)!=null&&y.dataStream?t.p.body.dataStream.replace(/\r\n$/,""):String(t.v),v=s.numfmt.parseDate(l)||s.numfmt.parseTime(l)||s.numfmt.parseNumber(l);if(c)if(Xe(c)){const{dataStream:_}=c,h=_.replace(/\r\n$/,""),T=Number(h);if(Number.isNaN(T)&&!v)return n(t)}else return n(t);if(v){v.z&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:v.z});const _=Number(v.v);return n({...t,p:void 0,v:_,t:s.CellValueType.NUMBER})}else(["date","time","datetime","percent"].includes(a)||!ze(l))&&o();return n(t)}})))}_initInterceptorCommands(){const t=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(r){var n;switch(r.id){case S.SetRangeValuesCommand.id:{const i=t._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),a=i.getUnitId(),o=(n=i.getActiveSheet())==null?void 0:n.getSheetId();if(!o)return{redos:[],undos:[]};const c=t._collectEffectMutation.getEffects();if(t._collectEffectMutation.clean(),!c.length)return{redos:[],undos:[]};const l=c.filter(p=>{var y;return!!((y=p.value)!=null&&y.pattern)}).map(p=>({row:p.row,col:p.col,pattern:p.value.pattern})),v=c.filter(p=>{var y;return!((y=p.value)!=null&&y.pattern)}).map(p=>({startRow:p.row,endColumn:p.col,startColumn:p.col,endRow:p.row})),f=[],d=[];if(l.length){const p={id:S.SetNumfmtMutation.id,params:S.transformCellsToRange(a,o,l)};f.push(p),d.push(...S.factorySetNumfmtUndoMutation(t._injector,p.params))}if(v.length){const p={id:S.RemoveNumfmtMutation.id,params:{unitId:a,subUnitId:o,ranges:v}};f.push(p),d.push(...S.factoryRemoveNumfmtUndoMutation(t._injector,p.params))}return{redos:f,undos:d.reverse()}}}return{redos:[],undos:[]}}}))}};B=Ye([H(0,s.Inject(S.SheetInterceptorService)),H(1,s.Inject(S.INumfmtService)),H(2,s.Inject(s.IUniverInstanceService)),H(3,s.Inject(s.Injector)),H(4,s.Optional(R.IEditorBridgeService))],B);function ze(e){return/^-?\d+(\.\d+)?$/.test(e)}function Xe(e){const{textRuns:t=[],paragraphs:r=[],customRanges:n,customBlocks:i=[]}=e,a=["va"];return!(t.some(o=>!!(o.ts&&Object.keys(o.ts).some(l=>a.includes(l))))||r.some(o=>o.bullet)||r.length>=2||n!=null&&n.length||i.length>0)}const V=[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:ee.DEFAULT_TEXT_FORMAT},"|",{label:"sheet.numfmt.number",pattern:"0"},"|",{label:"sheet.numfmt.accounting",pattern:'"¥" #,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.financialValue",pattern:"#,##0.00;[Red]#,##0.00"},{label:"sheet.numfmt.currency",pattern:'"¥"#,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.roundingCurrency",pattern:'"¥"#,##0;[Red]"¥"#,##0'},"|",{label:"sheet.numfmt.date",pattern:"yyyy-mm-dd;@"},{label:"sheet.numfmt.time",pattern:'am/pm h":"mm":"ss'},{label:"sheet.numfmt.dateTime",pattern:"yyyy-m-d am/pm h:mm"},{label:"sheet.numfmt.timeDuration",pattern:"h:mm:ss"},"|",{label:"sheet.numfmt.moreFmt",pattern:""}],Ze=e=>({icon:new O.Observable(t=>{const r=e.get(m.MenuCurrencyService);function n(a){return{[m.countryCurrencyMap.US]:"DollarSingle",[m.countryCurrencyMap.RU]:"RoubleSingle",[m.countryCurrencyMap.CN]:"RmbSingle",[m.countryCurrencyMap.AT]:"EuroSingle"}[a]||"DollarSingle"}const i=m.countryCurrencyMap[r.getCurrencySymbol()]||"$";return t.next(n(i)),r.currencySymbol$.subscribe(a=>{const o=m.countryCurrencyMap[a]||"$";t.next(n(o))})}),id:m.SetCurrencyCommand.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:P.MenuItemType.BUTTON,hidden$:P.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:R.getCurrentRangeDisable$(e,{workbookTypes:[S.WorkbookEditablePermission],worksheetTypes:[S.WorksheetEditPermission,S.WorksheetSetCellStylePermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}),Qe=e=>({icon:"AddDigitsSingle",id:m.AddDecimalCommand.id,title:"sheet.numfmt.addDecimal",tooltip:"sheet.numfmt.addDecimal",type:P.MenuItemType.BUTTON,hidden$:P.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:R.getCurrentRangeDisable$(e,{workbookTypes:[S.WorkbookEditablePermission],worksheetTypes:[S.WorksheetEditPermission,S.WorksheetSetCellStylePermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}),$e=e=>({icon:"ReduceDigitsSingle",id:m.SubtractDecimalCommand.id,title:"sheet.numfmt.subtractDecimal",tooltip:"sheet.numfmt.subtractDecimal",type:P.MenuItemType.BUTTON,hidden$:P.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:R.getCurrentRangeDisable$(e,{workbookTypes:[S.WorkbookEditablePermission],worksheetTypes:[S.WorksheetEditPermission,S.WorksheetSetCellStylePermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}),qe=e=>({icon:"PercentSingle",id:m.SetPercentCommand.id,title:"sheet.numfmt.percent",tooltip:"sheet.numfmt.percent",type:P.MenuItemType.BUTTON,hidden$:P.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:R.getCurrentRangeDisable$(e,{workbookTypes:[S.WorkbookEditablePermission],worksheetTypes:[S.WorksheetEditPermission,S.WorksheetSetCellStylePermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}),et=e=>{const t=e.get(s.IUniverInstanceService),r=e.get(s.ICommandService),n=e.get(s.LocaleService),i=e.get(S.SheetsSelectionsService),a=R.deriveStateFromActiveSheet$(t,"",({workbook:o,worksheet:c})=>new O.Observable(l=>O.merge(i.selectionMoveEnd$,new O.Observable(v=>{const f=[S.RemoveNumfmtMutation.id,S.SetNumfmtMutation.id],d=r.onCommandExecuted(p=>{f.includes(p.id)&&v.next(null)});return()=>d.dispose()})).subscribe(()=>{var f,d;const v=i.getCurrentSelections();if(v&&v[0]){const p=v[0].range,y=p.startRow,_=p.startColumn,h=(d=o.getStyles().get((f=c.getCell(y,_))==null?void 0:f.s))==null?void 0:d.n,T=h==null?void 0:h.pattern;let C=n.t("sheet.numfmt.general");if(T){const M=V.filter(D=>typeof D=="object"&&D.pattern).find(D=>m.isPatternEqualWithoutDecimal(T,D.pattern));M&&typeof M=="object"&&M.pattern?C=n.t(M.label):C=n.t("sheet.numfmt.moreFmt")}l.next(C)}})));return{label:le,id:w.id,tooltip:"sheet.numfmt.title",type:P.MenuItemType.SELECTOR,selections:[{label:{name:ue,hoverable:!1}}],value$:a,hidden$:P.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:R.getCurrentRangeDisable$(e,{workbookTypes:[S.WorkbookEditablePermission],worksheetTypes:[S.WorksheetSetCellStylePermission,S.WorksheetEditPermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}},le="sheet.numfmt.moreNumfmtType",ue="sheet.numfmt.moreNumfmtType.options",tt=e=>{var n;const t=s.useDependency(s.LocaleService),r=(n=e.value)!=null?n:t.t("sheet.numfmt.general");return u.jsx("span",{className:"more-numfmt-type",children:r})},nt=()=>{const e=s.useDependency(s.ICommandService),t=s.useDependency(s.LocaleService),r=s.useDependency(P.ILayoutService);s.useInjector();const n=s.useDependency(S.SheetsSelectionsService),i=c=>{const l=n.getCurrentLastSelection();if(!l)return;const v=l.range,f=[];s.Range.foreach(v,(d,p)=>{c?f.push({row:d,col:p,pattern:c,type:m.getPatternType(c)}):f.push({row:d,col:p})}),e.executeCommand(m.SetNumfmtCommand.id,{values:f}),r.focus()},a=c=>{if(c===0)i(null);else if(c===V.length-1)e.executeCommand(w.id);else{const l=V[c];l.pattern&&i(l.pattern)}},o=1220;return u.jsx("div",{className:"more-numfmt-type-options",children:V.map((c,l)=>c==="|"?u.jsx("div",{className:"line m-t-4",onClick:v=>v.stopPropagation()},l):u.jsxs("div",{className:"option-item m-t-4",onClick:()=>{a(l)},children:[u.jsx("div",{children:t.t(c.label)}),u.jsx("div",{className:"m-l-26",children:c.pattern?m.getPatternPreview(c.pattern||"",o,t.getCurrentLocale()).result:""})]},l))})},rt={[P.RibbonStartGroup.FORMULAS_INSERT]:{[m.SetCurrencyCommand.id]:{order:4,menuItemFactory:Ze},[m.AddDecimalCommand.id]:{order:5,menuItemFactory:Qe},[m.SubtractDecimalCommand.id]:{order:6,menuItemFactory:$e},[m.SetPercentCommand.id]:{order:7,menuItemFactory:qe},[w.id]:{order:8,menuItemFactory:et}}};var it=Object.defineProperty,st=Object.getOwnPropertyDescriptor,at=(e,t,r,n)=>{for(var i=n>1?void 0:n?st(t,r):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=(n?o(t,r,i):o(i))||i);return n&&i&&it(t,r,i),i},me=(e,t)=>(r,n)=>t(r,n,e);let G=class extends s.Disposable{constructor(e,t){super(),this._componentManager=e,this._menuManagerService=t,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(rt),this.disposeWithMe(this._componentManager.register(le,tt)),this.disposeWithMe(this._componentManager.register(ue,nt))}};G=at([me(0,s.Inject(P.ComponentManager)),me(1,P.IMenuManagerService)],G);var de=Object.defineProperty,ot=Object.getOwnPropertyDescriptor,ct=(e,t,r)=>t in e?de(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,lt=(e,t,r,n)=>{for(var i=n>1?void 0:n?ot(t,r):t,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=(n?o(t,r,i):o(i))||i);return n&&i&&de(t,r,i),i},pe=(e,t)=>(r,n)=>t(r,n,e),fe=(e,t,r)=>ct(e,typeof t!="symbol"?t+"":t,r);const ut="SHEET_NUMFMT_UI_PLUGIN";b.UniverSheetsNumfmtUIPlugin=class extends s.Plugin{constructor(t=te,r,n){super(),this._config=t,this._injector=r,this._configService=n;const{menu:i,...a}=s.merge({},te,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(P.UI_PLUGIN_CONFIG_KEY,a)}onStarting(){s.registerDependencies(this._injector,[[k],[B],[L],[G]])}onRendered(){s.touchDependencies(this._injector,[[k],[B],[G]])}},fe(b.UniverSheetsNumfmtUIPlugin,"pluginName",ut),fe(b.UniverSheetsNumfmtUIPlugin,"type",s.UniverInstanceType.UNIVER_SHEET),b.UniverSheetsNumfmtUIPlugin=lt([s.DependentOn(R.UniverSheetsUIPlugin,m.UniverSheetsNumfmtPlugin),pe(1,s.Inject(s.Injector)),pe(2,s.IConfigService)],b.UniverSheetsNumfmtUIPlugin),Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
9
+ */var ne;function he(){if(ne)return F;ne=1;var t=g,e=Symbol.for("react.element"),r=Symbol.for("react.fragment"),n=Object.prototype.hasOwnProperty,i=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a={key:!0,ref:!0,__self:!0,__source:!0};function o(c,l,v){var f,d={},p=null,y=null;v!==void 0&&(p=""+v),l.key!==void 0&&(p=""+l.key),l.ref!==void 0&&(y=l.ref);for(f in l)n.call(l,f)&&!a.hasOwnProperty(f)&&(d[f]=l[f]);if(c&&c.defaultProps)for(f in l=c.defaultProps,l)d[f]===void 0&&(d[f]=l[f]);return{$$typeof:e,type:c,key:p,ref:y,props:d,_owner:i.current}}return F.Fragment=r,F.jsx=o,F.jsxs=o,F}var re;function Se(){return re||(re=1,z.exports=he()),z.exports}var u=Se(),ye=Object.defineProperty,ge=Object.getOwnPropertyDescriptor,_e=(t,e,r,n)=>{for(var i=n>1?void 0:n?ge(e,r):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(n?o(e,r,i):o(i))||i);return n&&i&&ye(e,r,i),i},be=(t,e)=>(r,n)=>e(r,n,t);const X=g.createContext([]);let L=class{constructor(t){this._localStorageService=t}_getKey(t){return`userHabitController_${t}`}async addHabit(t,e){const r=this._getKey(t);return this._localStorageService.getItem(r).then(n=>{n||this._localStorageService.setItem(r,e)})}markHabit(t,e){const r=this._getKey(t);this._localStorageService.getItem(r).then(n=>{if(n){const i=n.findIndex(a=>a===e);i>-1&&n.splice(i,1),n.unshift(e),this._localStorageService.setItem(r,n)}})}async getHabit(t,e){const r=this._getKey(t),n=await this._localStorageService.getItem(r);if(e&&n){const i=n.map((a,o,c)=>{const l=c.length;return{value:a,priority:l-o}});return e.sort((a,o)=>{var v,f;const c=((v=i.find(d=>d.value===a))==null?void 0:v.priority)||-1;return(((f=i.find(d=>d.value===o))==null?void 0:f.priority)||-1)-c})}return n||[]}deleteHabit(t){this._localStorageService.removeItem(t)}};L=_e([be(0,s.Inject(s.ILocalStorageService))],L);const ie="numfmtCurrency",Ce=t=>{const e=s.useDependency(L),[r,n]=g.useState(m.currencySymbols);return g.useEffect(()=>{e.addHabit("numfmtCurrency",[]).then(()=>{e.getHabit(ie,[...m.currencySymbols]).then(a=>{n(a),t(a)})})},[]),{userHabitCurrency:r,mark:a=>{e.markHabit(ie,a)}}},Ie=()=>{const t=g.useRef([]),[e,r]=g.useState({});return g.useEffect(()=>{t.current.forEach(i=>{i()}),t.current=[]},[e]),i=>{t.current.push(i),r({})}},Pe=t=>!!m.getCurrencyType(t)&&t.startsWith("_("),Te=t=>{const{defaultPattern:e,action:r,onChange:n}=t,[i,a]=g.useState(()=>m.getDecimalFromPattern(e||"",2)),o=g.useContext(X),[c,l]=g.useState(()=>m.getCurrencyType(e)||o[0]),v=g.useMemo(()=>o.map(_=>({label:_,value:_})),[]),d=s.useDependency(s.LocaleService).t;r.current=()=>m.setPatternDecimal(`_("${c}"* #,##0${i>0?".0":""}_)`,i);const p=_=>{l(_),n(m.setPatternDecimal(`_("${_}"* #,##0${i>0?".0":""}_)`,i))},y=_=>{const h=_||0;a(h),n(m.setPatternDecimal(`_("${c}"* #,##0${h>0?".0":""}_)`,h))};return u.jsxs("div",{children:[u.jsxs("div",{className:"m-t-16 options",children:[u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:d("sheet.numfmt.decimalLength")}),u.jsx("div",{className:"m-t-8 w-120",children:u.jsx(E.InputNumber,{value:i,max:20,min:0,onChange:y})})]}),u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:d("sheet.numfmt.currencyType")}),u.jsx("div",{className:"m-t-8 w-140",children:u.jsx(E.Select,{onChange:p,options:v,value:c})})]})]}),u.jsx("div",{className:"describe m-t-14",children:d("sheet.numfmt.accountingDes")})]})},Ee=t=>!!m.getCurrencyType(t)&&!t.startsWith("_("),je=t=>{const r=s.useDependency(s.LocaleService).t,n=g.useContext(X),[i,a]=g.useState(()=>m.getCurrencyType(t.defaultPattern)||n[0]),[o,c]=g.useState(()=>m.getDecimalFromPattern(t.defaultPattern||"",2)),[l,v]=g.useState(()=>{var C;const h=m.getCurrencyFormatOptions(i);return((C=h.find(M=>m.isPatternEqualWithoutDecimal(M.value,t.defaultPattern)))==null?void 0:C.value)||h[0].value}),f=g.useMemo(()=>m.getCurrencyFormatOptions(i),[i]),d=g.useMemo(()=>n.map(h=>({label:h,value:h})),[n]);t.action.current=()=>m.setPatternDecimal(l,o);const p=h=>{if(h===void 0)return;a(h);const T=m.getCurrencyFormatOptions(h)[0].value;v(T),t.onChange(m.setPatternDecimal(T,o))},y=h=>{h!==void 0&&(v(h),t.onChange(m.setPatternDecimal(h,o)))},_=h=>{c(h||0),t.onChange(m.setPatternDecimal(l,h||0))};return u.jsxs("div",{children:[u.jsxs("div",{className:"m-t-16 options",children:[u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:r("sheet.numfmt.decimalLength")}),u.jsx("div",{className:"m-t-8 w-120",children:u.jsx(E.InputNumber,{value:o,max:20,min:0,onChange:_})})]}),u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:r("sheet.numfmt.currencyType")}),u.jsx("div",{className:"m-t-8 w-140",children:u.jsx(E.Select,{onChange:p,options:d,value:i})})]})]}),u.jsx("div",{className:"m-t-16 label",children:r("sheet.numfmt.negType")}),u.jsx("div",{className:"m-t-8",children:u.jsx(E.SelectList,{onChange:y,options:f,value:l})}),u.jsx("div",{className:"describe m-t-14",children:r("sheet.numfmt.currencyDes")})]})};var j=function(){return j=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++){e=arguments[r];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},j.apply(this,arguments)},Me=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},se=g.forwardRef(function(t,e){var r=t.icon,n=t.id,i=t.className,a=t.extend,o=Me(t,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(n," ").concat(i||"").trim(),l=g.useRef("_".concat(Re()));return ae(r,"".concat(n),{defIds:r.defIds,idSuffix:l.current},j({ref:e,className:c},o),a)});function ae(t,e,r,n,i){return g.createElement(t.tag,j(j({key:e},xe(t,r,i)),n),(De(t,r).children||[]).map(function(a,o){return ae(a,"".concat(e,"-").concat(t.tag,"-").concat(o),r,void 0,i)}))}function xe(t,e,r){var n=j({},t.attrs);r!=null&&r.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=r.colorChannel1);var i=e.defIds;return!i||i.length===0||(t.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+e.idSuffix),Object.entries(n).forEach(function(a){var o=a[0],c=a[1];typeof c=="string"&&(n[o]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),n}function De(t,e){var r,n=e.defIds;return!n||n.length===0?t:t.tag==="defs"&&(!((r=t.children)===null||r===void 0)&&r.length)?j(j({},t),{children:t.children.map(function(i){return typeof i.attrs.id=="string"&&n&&n.indexOf(i.attrs.id)>-1?j(j({},i),{attrs:j(j({},i.attrs),{id:i.attrs.id+e.idSuffix})}):i})}):t}function Re(){return Math.random().toString(36).substring(2,8)}se.displayName="UniverIcon";var Oe={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},oe=g.forwardRef(function(t,e){return g.createElement(se,Object.assign({},t,{id:"check-mark-single",ref:e,icon:Oe}))});oe.displayName="CheckMarkSingle";const U={customFormatTitle:"univer-custom-format-title",customFormatInput:"univer-custom-format-input",customFormatHistoryList:"univer-custom-format-history-list",customFormatHistoryListItem:"univer-custom-format-history-list-item",customFormatHistoryListItemIconWrap:"univer-custom-format-history-list-item-icon-wrap",customFormatDes:"univer-custom-format-des"},Z="customFormat",Q="numfmt_custom_pattern";function Ue(t){const{defaultPattern:e,action:r,onChange:n}=t,i=s.useDependency(L),a=s.useDependency(s.ILocalStorageService),o=s.useDependency(s.LocaleService),[c,l]=g.useState(e);r.current=()=>(i.markHabit(Z,c),a.getItem(Q).then((y=[])=>{const _=[...new Set([c,...y||[]])].splice(0,10).filter(h=>!!h);a.setItem(Q,_)}),c);const[v,f]=g.useState([]);g.useEffect(()=>{a.getItem(Q).then(y=>{const _=[...m.CURRENCYFORMAT.map(h=>h.suffix("$")),...m.DATEFMTLISG.map(h=>h.suffix),...m.NUMBERFORMAT.map(h=>h.suffix)];_.push(...y||[]),i.addHabit(Z,[]).finally(()=>{i.getHabit(Z,_).then(h=>{f([...new Set(h)])})})})},[]);const d=y=>{l(y),n(y)},p=()=>{n(c)};return u.jsxs("div",{className:U.customFormat,children:[u.jsx("div",{className:U.customFormatTitle,children:o.t("sheet.numfmt.customFormat")}),u.jsx(E.Input,{placeholder:o.t("sheet.numfmt.customFormat"),onBlur:p,value:c,onChange:l,className:U.customFormatInput}),u.jsx("div",{className:U.customFormatHistoryList,children:v.map(y=>u.jsxs("div",{onClick:()=>d(y),className:U.customFormatHistoryListItem,children:[u.jsx("div",{className:U.customFormatHistoryListItemIconWrap,children:c===y&&u.jsx(oe,{})}),u.jsx("div",{children:y})]},y))}),u.jsx("div",{className:U.customFormatDes,children:o.t("sheet.numfmt.customFormatDes")})]})}const Ne=t=>{const e=s.numfmt.getInfo(t);return m.getDateFormatOptions().map(r=>r.value).includes(t)||["date","datetime","time"].includes(e.type)},we=t=>{const e=g.useMemo(m.getDateFormatOptions,[]),n=s.useDependency(s.LocaleService).t,[i,a]=g.useState(()=>{if(t.defaultPattern){const c=e.find(l=>l.value===t.defaultPattern);if(c)return c.value}return e[0].value});t.action.current=()=>i;const o=c=>{c!==void 0&&(a(c),t.onChange(c))};return u.jsxs("div",{children:[u.jsx("div",{className:"m-t-16 label",children:n("sheet.numfmt.dateType")}),u.jsx("div",{className:"m-t-8",children:u.jsx(E.SelectList,{value:i,options:e,onChange:o})}),u.jsx("div",{className:"describe m-t-14",children:n("sheet.numfmt.dateDes")})]})},Fe=t=>!t,Le=t=>{const r=s.useDependency(s.LocaleService).t;return t.action.current=()=>"",u.jsx("div",{children:u.jsx("div",{className:"describe m-t-14",children:r("sheet.numfmt.generalDes")})})},ke=t=>m.getNumberFormatOptions().some(e=>m.isPatternEqualWithoutDecimal(e.value,t)),He=t=>{const e=s.useDependency(s.LocaleService),r=g.useMemo(m.getNumberFormatOptions,[]),[n,i]=g.useState(()=>m.getDecimalFromPattern(t.defaultPattern||"",0)),[a,o]=g.useState(()=>{const d=r.find(p=>m.isPatternEqualWithoutDecimal(p.value,t.defaultPattern||""));return(d==null?void 0:d.value)||r[0].value}),c=g.useMemo(()=>m.setPatternDecimal(a,Number(n||0)),[a,n]),l=g.useMemo(()=>!m.isPatternHasDecimal(a),[a]),v=d=>{i(d||0),t.onChange(m.setPatternDecimal(a,Number(d||0)))},f=d=>{d!==void 0&&(i(m.getDecimalFromPattern(d,0)),o(d),t.onChange(d))};return t.action.current=()=>c,u.jsxs("div",{children:[u.jsx("div",{className:"m-t-16 label",children:e.t("sheet.numfmt.decimalLength")}),u.jsx("div",{className:"m-t-8",children:u.jsx(E.InputNumber,{disabled:l,value:n,max:20,min:0,onChange:v})}),u.jsxs("div",{className:"m-t-16 label",children:[" ",e.t("sheet.numfmt.negType")]}),u.jsx("div",{className:"m-t-8",children:u.jsx(E.SelectList,{onChange:f,options:r,value:a})}),u.jsx("div",{className:"describe m-t-14",children:e.t("sheet.numfmt.thousandthPercentileDes")})]})},We=t=>{const{defaultValue:e,defaultPattern:r,row:n,col:i}=t.value,a=s.useDependency(s.LocaleService),o=g.useRef(()=>""),c=a.t,l=Ie(),v=g.useMemo(()=>[{label:"sheet.numfmt.general",component:Le},{label:"sheet.numfmt.accounting",component:Te},{label:"sheet.numfmt.currency",component:je},{label:"sheet.numfmt.date",component:we},{label:"sheet.numfmt.thousandthPercentile",component:He},{label:"sheet.numfmt.customFormat",component:Ue}].map(I=>({...I,label:c(I.label)})),[]),[f,d]=g.useState(C),[p,y]=g.useState(()=>`${n}_${i}`),{mark:_,userHabitCurrency:h}=Ce(()=>y(`${n}_${i}_userCurrency'`)),T=g.useMemo(()=>{var I;return(I=v.find(N=>N.label===f))==null?void 0:I.component},[f]);function C(){return[Fe,Pe,Ee,Ne,ke].reduce((N,mt,dt)=>N||(mt(r)?v[dt].label:""),"")||v[0].label}const M=v.map(I=>({label:I.label,value:I.label})),D=I=>{d(I),l(()=>t.onChange({type:"change",value:o.current()||""}))},K=I=>{t.onChange({type:"change",value:I})},$=()=>{const I=o.current()||"",N=m.getCurrencyType(I);N&&_(N),t.onChange({type:"confirm",value:I})},W=()=>{t.onChange({type:"cancel",value:""})},q={onChange:K,defaultValue:e,defaultPattern:r,action:o};return g.useEffect(()=>{d(C()),y(`${n}_${i}`)},[n,i]),u.jsxs("div",{className:"numfmt-panel p-b-20",children:[u.jsxs("div",{children:[u.jsx("div",{className:"label m-t-14",children:c("sheet.numfmt.numfmtType")}),u.jsx("div",{className:"m-t-8",children:u.jsx(E.Select,{onChange:D,options:M,value:f,style:{width:"100%"}})}),u.jsx("div",{children:T&&u.jsx(X.Provider,{value:h,children:g.createElement(T,{...q,key:p})})})]}),u.jsxs("div",{className:"btn-list m-t-14 m-b-20",children:[u.jsx(E.Button,{size:"small",onClick:W,className:"m-r-12",children:c("sheet.numfmt.cancel")}),u.jsx(E.Button,{type:"primary",size:"small",onClick:$,children:c("sheet.numfmt.confirm")})]})]})};var Ae=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,Ve=(t,e,r,n)=>{for(var i=n>1?void 0:n?Be(e,r):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(n?o(e,r,i):o(i))||i);return n&&i&&Ae(e,r,i),i},x=(t,e)=>(r,n)=>e(r,n,t);const ce="SHEET_NUMFMT_PANEL";let k=class extends s.Disposable{constructor(e,r,n,i,a,o,c,l,v,f){super();Y(this,"_previewPattern","");Y(this,"_sidebarDisposable",null);this._sheetInterceptorService=e,this._themeService=r,this._univerInstanceService=n,this._commandService=i,this._selectionManagerService=a,this._renderManagerService=o,this._numfmtService=c,this._componentManager=l,this._sidebarService=v,this._localeService=f,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener()}openPanel(){var T;const e=this._sidebarService,r=this._selectionManagerService,n=this._commandService,i=this._univerInstanceService,a=this._numfmtService,o=this._localeService,l=(((T=r.getCurrentSelections())==null?void 0:T.map(C=>C.range))||[])[0];if(!l)return!1;const v=i.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),f=v.getActiveSheet();if(!f)return!1;const d=f.getCellRaw(l.startRow,l.startColumn),p=a.getValue(v.getUnitId(),f.getSheetId(),l.startRow,l.startColumn);let y="";p&&(y=p.pattern);const _=(d==null?void 0:d.t)===s.CellValueType.NUMBER?d.v:12345678,h={onChange:C=>{var M;if(C.type==="change")this._previewPattern=C.value,this._forceUpdate();else if(C.type==="confirm"){const D=((M=r.getCurrentSelections())==null?void 0:M.map(W=>W.range))||[],K={values:[]},$=m.getPatternType(C.value);D.forEach(W=>{s.Range.foreach(W,(q,I)=>{K.values.push({row:q,col:I,pattern:C.value,type:$})})}),n.executeCommand(m.SetNumfmtCommand.id,K),e.close()}else C.type==="cancel"&&e.close()},value:{defaultPattern:y,defaultValue:_,row:l.startRow,col:l.startColumn}};return this._sidebarDisposable=e.open({header:{title:o.t("sheet.numfmt.title")},children:{label:ce,...h},onClose:()=>{this._forceUpdate(),n.executeCommand(J.id)}}),!0}_forceUpdate(e){var n;const r=this._renderManagerService.getRenderById(e!=null?e:this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET).getUnitId());r==null||r.with(R.SheetSkeletonManagerService).reCalculate(),(n=r==null?void 0:r.mainComponent)==null||n.makeDirty()}_initCommands(){[w,J].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initPanel(){this._componentManager.register(ce,We)}_initRealTimeRenderingInterceptor(){const e=new O.Observable(n=>{this._commandService.onCommandExecuted(i=>{i.id===w.id&&n.next(!0),i.id===J.id&&n.next(!1)})}),r=O.combineLatest([e,this._selectionManagerService.selectionMoveEnd$.pipe(A.map(n=>n?n.map(i=>i.range):[]))]);this.disposeWithMe(s.toDisposable(r.pipe(A.switchMap(([n,i])=>new O.Observable(a=>{const o=new s.DisposableCollection;return n&&i.length&&a.next({selectionRanges:i,disposableCollection:o}),()=>{o.dispose()}})),A.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:n,selectionRanges:i})=>{var o,c;const a=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);this.openPanel(),n.add(this._sheetInterceptorService.intercept(S.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,effect:s.InterceptorEffectEnum.Value|s.InterceptorEffectEnum.Style,handler:(l,v,f)=>{const{row:d,col:p}=v,y=f(l)||{};if(i.find(_=>_.startColumn<=p&&_.endColumn>=p&&_.startRow<=d&&_.endRow>=d)){const _=v.worksheet.getCellRaw(d,p),h=_==null?void 0:_.v,T=_==null?void 0:_.t;if(h==null||T!==s.CellValueType.NUMBER||this._previewPattern===null)return y;const C=m.getPatternPreviewIgnoreGeneral(this._previewPattern,h,this._localeService.getCurrentLocale());if(C.color){const D=this._themeService.getCurrentTheme()[`${C.color}500`];return{...y,v:C.result,t:s.CellValueType.STRING,s:{cl:{rgb:D}}}}return{...y,v:C.result,t:s.CellValueType.STRING}}return y}})),(c=(o=this._renderManagerService.getRenderById(a.getUnitId()))==null?void 0:o.mainComponent)==null||c.makeDirty()})))}_commandExecutedListener(){const e=[S.RemoveNumfmtMutation.id,S.SetNumfmtMutation.id];this.disposeWithMe(new O.Observable(r=>{const n=this._commandService.onCommandExecuted(i=>{if(e.includes(i.id)){const a=i.params;r.next(a.unitId)}});return()=>n.dispose()}).pipe(A.debounceTime(16)).subscribe(r=>this._forceUpdate(r)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_SHEET).subscribe(e=>{var r;e||((r=this._sidebarDisposable)==null||r.dispose(),this._sidebarDisposable=null)})}};k=Ve([x(0,s.Inject(S.SheetInterceptorService)),x(1,s.Inject(s.ThemeService)),x(2,s.IUniverInstanceService),x(3,s.ICommandService),x(4,s.Inject(S.SheetsSelectionsService)),x(5,ve.IRenderManagerService),x(6,S.INumfmtService),x(7,s.Inject(P.ComponentManager)),x(8,P.ISidebarService),x(9,s.Inject(s.LocaleService))],k);var Ge=Object.defineProperty,Ke=Object.getOwnPropertyDescriptor,Ye=(t,e,r,n)=>{for(var i=n>1?void 0:n?Ke(e,r):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(n?o(e,r,i):o(i))||i);return n&&i&&Ge(e,r,i),i},H=(t,e)=>(r,n)=>e(r,n,t);const Je=()=>{let t=[];return{add:(i,a,o,c,l)=>t.push({unitId:i,subUnitId:a,row:o,col:c,value:l}),getEffects:()=>t,clean:()=>{t=[]}}};let B=class extends s.Disposable{constructor(e,r,n,i,a){super();Y(this,"_collectEffectMutation",Je());this._sheetInterceptorService=e,this._numfmtService=r,this._univerInstanceService=n,this._injector=i,this._editorBridgeService=a,this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(s.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(S.BEFORE_CELL_EDIT,{handler:(e,r,n)=>{const i=r.row,a=r.col,o=this._numfmtService.getValue(r.unitId,r.subUnitId,i,a);if(o)switch(m.getPatternType(o.pattern)){case"scientific":case"currency":case"grouped":case"number":return r.worksheet.getCellRaw(i,a);case"percent":case"date":case"time":case"datetime":default:return n&&n(e)}return n(e)}})))}_initInterceptorEditorEnd(){this.disposeWithMe(s.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(S.AFTER_CELL_EDIT,{handler:(e,r,n)=>{var f,d,p,y;this._collectEffectMutation.clean();const i=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col),a=(f=i&&m.getPatternType(i.pattern))!=null?f:"",o=()=>{i&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,null)};if(!(e!=null&&e.v)&&!(e!=null&&e.p)||(i==null?void 0:i.pattern)===ee.DEFAULT_TEXT_FORMAT)return n(e);const c=(d=e.p)==null?void 0:d.body,l=(y=(p=e==null?void 0:e.p)==null?void 0:p.body)!=null&&y.dataStream?e.p.body.dataStream.replace(/\r\n$/,""):String(e.v),v=s.numfmt.parseDate(l)||s.numfmt.parseTime(l)||s.numfmt.parseNumber(l);if(c)if(Xe(c)){const{dataStream:_}=c,h=_.replace(/\r\n$/,""),T=Number(h);if(Number.isNaN(T)&&!v)return n(e)}else return n(e);if(v){v.z&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:v.z});const _=Number(v.v);return n({...e,p:void 0,v:_,t:s.CellValueType.NUMBER})}else(["date","time","datetime","percent"].includes(a)||!ze(l))&&o();return n(e)}})))}_initInterceptorCommands(){const e=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(r){var n;switch(r.id){case S.SetRangeValuesCommand.id:{const i=e._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),a=i.getUnitId(),o=(n=i.getActiveSheet())==null?void 0:n.getSheetId();if(!o)return{redos:[],undos:[]};const c=e._collectEffectMutation.getEffects();if(e._collectEffectMutation.clean(),!c.length)return{redos:[],undos:[]};const l=c.filter(p=>{var y;return!!((y=p.value)!=null&&y.pattern)}).map(p=>({row:p.row,col:p.col,pattern:p.value.pattern})),v=c.filter(p=>{var y;return!((y=p.value)!=null&&y.pattern)}).map(p=>({startRow:p.row,endColumn:p.col,startColumn:p.col,endRow:p.row})),f=[],d=[];if(l.length){const p={id:S.SetNumfmtMutation.id,params:S.transformCellsToRange(a,o,l)};f.push(p),d.push(...S.factorySetNumfmtUndoMutation(e._injector,p.params))}if(v.length){const p={id:S.RemoveNumfmtMutation.id,params:{unitId:a,subUnitId:o,ranges:v}};f.push(p),d.push(...S.factoryRemoveNumfmtUndoMutation(e._injector,p.params))}return{redos:f,undos:d.reverse()}}}return{redos:[],undos:[]}}}))}};B=Ye([H(0,s.Inject(S.SheetInterceptorService)),H(1,s.Inject(S.INumfmtService)),H(2,s.Inject(s.IUniverInstanceService)),H(3,s.Inject(s.Injector)),H(4,s.Optional(R.IEditorBridgeService))],B);function ze(t){return/^-?\d+(\.\d+)?$/.test(t)}function Xe(t){const{textRuns:e=[],paragraphs:r=[],customRanges:n,customBlocks:i=[]}=t,a=["va"];return!(e.some(o=>!!(o.ts&&Object.keys(o.ts).some(l=>a.includes(l))))||r.some(o=>o.bullet)||r.length>=2||n!=null&&n.length||i.length>0)}const V=[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:ee.DEFAULT_TEXT_FORMAT},"|",{label:"sheet.numfmt.number",pattern:"0"},"|",{label:"sheet.numfmt.accounting",pattern:'"¥" #,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.financialValue",pattern:"#,##0.00;[Red]#,##0.00"},{label:"sheet.numfmt.currency",pattern:'"¥"#,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.roundingCurrency",pattern:'"¥"#,##0;[Red]"¥"#,##0'},"|",{label:"sheet.numfmt.date",pattern:"yyyy-mm-dd;@"},{label:"sheet.numfmt.time",pattern:'am/pm h":"mm":"ss'},{label:"sheet.numfmt.dateTime",pattern:"yyyy-m-d am/pm h:mm"},{label:"sheet.numfmt.timeDuration",pattern:"h:mm:ss"},"|",{label:"sheet.numfmt.moreFmt",pattern:""}],Ze=t=>({icon:new O.Observable(e=>{const r=t.get(m.MenuCurrencyService);function n(a){return{[m.countryCurrencyMap.US]:"DollarSingle",[m.countryCurrencyMap.RU]:"RoubleSingle",[m.countryCurrencyMap.CN]:"RmbSingle",[m.countryCurrencyMap.AT]:"EuroSingle"}[a]||"DollarSingle"}const i=m.countryCurrencyMap[r.getCurrencySymbol()]||"$";return e.next(n(i)),r.currencySymbol$.subscribe(a=>{const o=m.countryCurrencyMap[a]||"$";e.next(n(o))})}),id:m.SetCurrencyCommand.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:P.MenuItemType.BUTTON,hidden$:P.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:R.getCurrentRangeDisable$(t,{workbookTypes:[S.WorkbookEditablePermission],worksheetTypes:[S.WorksheetEditPermission,S.WorksheetSetCellStylePermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}),Qe=t=>({icon:"AddDigitsSingle",id:m.AddDecimalCommand.id,title:"sheet.numfmt.addDecimal",tooltip:"sheet.numfmt.addDecimal",type:P.MenuItemType.BUTTON,hidden$:P.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:R.getCurrentRangeDisable$(t,{workbookTypes:[S.WorkbookEditablePermission],worksheetTypes:[S.WorksheetEditPermission,S.WorksheetSetCellStylePermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}),$e=t=>({icon:"ReduceDigitsSingle",id:m.SubtractDecimalCommand.id,title:"sheet.numfmt.subtractDecimal",tooltip:"sheet.numfmt.subtractDecimal",type:P.MenuItemType.BUTTON,hidden$:P.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:R.getCurrentRangeDisable$(t,{workbookTypes:[S.WorkbookEditablePermission],worksheetTypes:[S.WorksheetEditPermission,S.WorksheetSetCellStylePermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}),qe=t=>({icon:"PercentSingle",id:m.SetPercentCommand.id,title:"sheet.numfmt.percent",tooltip:"sheet.numfmt.percent",type:P.MenuItemType.BUTTON,hidden$:P.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:R.getCurrentRangeDisable$(t,{workbookTypes:[S.WorkbookEditablePermission],worksheetTypes:[S.WorksheetEditPermission,S.WorksheetSetCellStylePermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}),et=t=>{const e=t.get(s.IUniverInstanceService),r=t.get(s.ICommandService),n=t.get(s.LocaleService),i=t.get(S.SheetsSelectionsService),a=R.deriveStateFromActiveSheet$(e,"",({workbook:o,worksheet:c})=>new O.Observable(l=>O.merge(i.selectionMoveEnd$,new O.Observable(v=>{const f=[S.RemoveNumfmtMutation.id,S.SetNumfmtMutation.id],d=r.onCommandExecuted(p=>{f.includes(p.id)&&v.next(null)});return()=>d.dispose()})).subscribe(()=>{var f,d;const v=i.getCurrentSelections();if(v&&v[0]){const p=v[0].range,y=p.startRow,_=p.startColumn,h=(d=o.getStyles().get((f=c.getCell(y,_))==null?void 0:f.s))==null?void 0:d.n,T=h==null?void 0:h.pattern;let C=n.t("sheet.numfmt.general");if(T){const M=V.filter(D=>typeof D=="object"&&D.pattern).find(D=>m.isPatternEqualWithoutDecimal(T,D.pattern));M&&typeof M=="object"&&M.pattern?C=n.t(M.label):C=n.t("sheet.numfmt.moreFmt")}l.next(C)}})));return{label:le,id:w.id,tooltip:"sheet.numfmt.title",type:P.MenuItemType.SELECTOR,selections:[{label:{name:ue,hoverable:!1}}],value$:a,hidden$:P.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:R.getCurrentRangeDisable$(t,{workbookTypes:[S.WorkbookEditablePermission],worksheetTypes:[S.WorksheetSetCellStylePermission,S.WorksheetEditPermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}},le="sheet.numfmt.moreNumfmtType",ue="sheet.numfmt.moreNumfmtType.options",tt=t=>{var n;const e=s.useDependency(s.LocaleService),r=(n=t.value)!=null?n:e.t("sheet.numfmt.general");return u.jsx("span",{className:"more-numfmt-type",children:r})},nt=()=>{const t=s.useDependency(s.ICommandService),e=s.useDependency(s.LocaleService),r=s.useDependency(P.ILayoutService);s.useInjector();const n=s.useDependency(S.SheetsSelectionsService),i=c=>{const l=n.getCurrentLastSelection();if(!l)return;const v=l.range,f=[];s.Range.foreach(v,(d,p)=>{c?f.push({row:d,col:p,pattern:c,type:m.getPatternType(c)}):f.push({row:d,col:p})}),t.executeCommand(m.SetNumfmtCommand.id,{values:f}),r.focus()},a=c=>{if(c===0)i(null);else if(c===V.length-1)t.executeCommand(w.id);else{const l=V[c];l.pattern&&i(l.pattern)}},o=1220;return u.jsx("div",{className:"more-numfmt-type-options",children:V.map((c,l)=>c==="|"?u.jsx("div",{className:"line m-t-4",onClick:v=>v.stopPropagation()},l):u.jsxs("div",{className:"option-item m-t-4",onClick:()=>{a(l)},children:[u.jsx("div",{children:e.t(c.label)}),u.jsx("div",{className:"m-l-26",children:c.pattern?m.getPatternPreview(c.pattern||"",o,e.getCurrentLocale()).result:""})]},l))})},rt={[P.RibbonStartGroup.FORMULAS_INSERT]:{[m.SetCurrencyCommand.id]:{order:4,menuItemFactory:Ze},[m.AddDecimalCommand.id]:{order:5,menuItemFactory:Qe},[m.SubtractDecimalCommand.id]:{order:6,menuItemFactory:$e},[m.SetPercentCommand.id]:{order:7,menuItemFactory:qe},[w.id]:{order:8,menuItemFactory:et}}};var it=Object.defineProperty,st=Object.getOwnPropertyDescriptor,at=(t,e,r,n)=>{for(var i=n>1?void 0:n?st(e,r):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(n?o(e,r,i):o(i))||i);return n&&i&&it(e,r,i),i},me=(t,e)=>(r,n)=>e(r,n,t);let G=class extends s.Disposable{constructor(t,e){super(),this._componentManager=t,this._menuManagerService=e,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(rt),this.disposeWithMe(this._componentManager.register(le,tt)),this.disposeWithMe(this._componentManager.register(ue,nt))}};G=at([me(0,s.Inject(P.ComponentManager)),me(1,P.IMenuManagerService)],G);var de=Object.defineProperty,ot=Object.getOwnPropertyDescriptor,ct=(t,e,r)=>e in t?de(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,lt=(t,e,r,n)=>{for(var i=n>1?void 0:n?ot(e,r):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(n?o(e,r,i):o(i))||i);return n&&i&&de(e,r,i),i},pe=(t,e)=>(r,n)=>e(r,n,t),fe=(t,e,r)=>ct(t,typeof e!="symbol"?e+"":e,r);const ut="SHEET_NUMFMT_UI_PLUGIN";b.UniverSheetsNumfmtUIPlugin=class extends s.Plugin{constructor(e=te,r,n){super(),this._config=e,this._injector=r,this._configService=n;const{menu:i,...a}=s.merge({},te,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(P.UI_PLUGIN_CONFIG_KEY,a)}onStarting(){s.registerDependencies(this._injector,[[k],[B],[L],[G]])}onRendered(){s.touchDependencies(this._injector,[[k],[B],[G]])}},fe(b.UniverSheetsNumfmtUIPlugin,"pluginName",ut),fe(b.UniverSheetsNumfmtUIPlugin,"type",s.UniverInstanceType.UNIVER_SHEET),b.UniverSheetsNumfmtUIPlugin=lt([s.DependentOn(R.UniverSheetsUIPlugin,m.UniverSheetsNumfmtPlugin),pe(1,s.Inject(s.Injector)),pe(2,s.IConfigService)],b.UniverSheetsNumfmtUIPlugin),Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-numfmt-ui",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "private": false,
5
5
  "description": "UniverSheet numfmt plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -54,45 +54,26 @@
54
54
  "rxjs": ">=7.0.0"
55
55
  },
56
56
  "dependencies": {
57
- "@univerjs/icons": "^0.2.8",
58
- "@univerjs/core": "0.5.2",
59
- "@univerjs/design": "0.5.2",
60
- "@univerjs/engine-numfmt": "0.5.2",
61
- "@univerjs/engine-render": "0.5.2",
62
- "@univerjs/sheets": "0.5.2",
63
- "@univerjs/sheets-numfmt": "0.5.2",
64
- "@univerjs/sheets-ui": "0.5.2",
65
- "@univerjs/ui": "0.5.2"
57
+ "@univerjs/icons": "^0.2.10",
58
+ "@univerjs/core": "0.5.3",
59
+ "@univerjs/design": "0.5.3",
60
+ "@univerjs/engine-render": "0.5.3",
61
+ "@univerjs/sheets": "0.5.3",
62
+ "@univerjs/sheets-ui": "0.5.3",
63
+ "@univerjs/engine-numfmt": "0.5.3",
64
+ "@univerjs/sheets-numfmt": "0.5.3",
65
+ "@univerjs/ui": "0.5.3"
66
66
  },
67
67
  "devDependencies": {
68
68
  "less": "^4.2.1",
69
69
  "postcss": "^8.4.49",
70
70
  "react": "18.3.1",
71
71
  "rxjs": "^7.8.1",
72
- "tailwindcss": "^3.4.16",
73
72
  "typescript": "^5.7.2",
74
- "vite": "^6.0.3",
73
+ "vite": "^6.0.6",
75
74
  "vitest": "^2.1.8",
76
- "@univerjs-infra/shared": "0.5.2",
77
- "@univerjs/engine-formula": "0.5.2"
78
- },
79
- "space": {
80
- ".": {
81
- "import": "./lib/es/index.js",
82
- "require": "./lib/cjs/index.js",
83
- "types": "./lib/types/index.d.ts"
84
- },
85
- "./*": {
86
- "import": "./lib/es/*",
87
- "require": "./lib/cjs/*",
88
- "types": "./lib/types/index.d.ts"
89
- },
90
- "./locale/*": {
91
- "import": "./lib/es/locale/*.js",
92
- "require": "./lib/cjs/locale/*.js",
93
- "types": "./lib/types/locale/*.d.ts"
94
- },
95
- "./lib/*": "./lib/*"
75
+ "@univerjs-infra/shared": "0.5.3",
76
+ "@univerjs/engine-formula": "0.5.3"
96
77
  },
97
78
  "scripts": {
98
79
  "test": "vitest run",