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