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