@univerjs/sheets-numfmt-ui 0.10.7 → 0.10.8-nightly.202509200616
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 +18 -18
- package/lib/index.js +18 -18
- package/lib/umd/index.js +1 -1
- package/package.json +11 -11
- package/LICENSE +0 -176
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var he=Object.defineProperty;var ve=(e,t,r)=>t in e?he(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 a=require("@univerjs/core"),re=require("@univerjs/engine-render"),h=require("@univerjs/sheets-numfmt"),P=require("@univerjs/sheets-ui"),g=require("@univerjs/sheets"),_=require("@univerjs/ui"),R=require("rxjs"),W=require("rxjs/operators"),l=require("react/jsx-runtime"),y=require("react"),N=require("@univerjs/design"),fe=require("@univerjs/engine-formula"),Q={};var pe=Object.getOwnPropertyDescriptor,ge=(e,t,r,n)=>{for(var i=n>1?void 0:n?pe(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=c(i)||i);return i},U=(e,t)=>(r,n)=>t(r,n,e);const G="SHEET_NUMFMT_ALERT";let X=class extends a.Disposable{constructor(e,t,r,n,i,s,c){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=r,this._localeService=n,this._zenZoneService=i,this._numfmtService=s,this._configService=c,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(R.debounceTime(100)).subscribe(e=>{var t,r;if(e){const n=e.location,i=this._context.unit,s=i.getActiveSheet();if(!s)return;const c=n.unitId,m=n.subUnitId;let o;const u=s.getCell(n.row,n.col);if(u!=null&&u.s){const v=i.getStyles().get(u.s);v!=null&&v.n&&(o=v.n)}if(o||(o=this._numfmtService.getValue(c,m,n.row,n.col)),!o){this._hideAlert();return}if(a.isTextFormat(o.pattern)&&a.Tools.isDefine(u==null?void 0:u.v)&&a.isRealNum(u.v)){if((t=this._configService.getConfig(h.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY))!=null&&t.disableTextFormatAlert)return;const v=this._cellAlertManagerService.currentAlert.get(G),d=(r=v==null?void 0:v.alert)==null?void 0:r.location;if(d&&d.row===n.row&&d.col===n.col&&d.subUnitId===n.subUnitId&&d.unitId===n.unitId)return;this._cellAlertManagerService.showAlert({type:P.CellAlertType.ERROR,title:this._localeService.t("info.error"),message:this._localeService.t("info.forceStringInfo"),location:n,width:200,height:74,key:G});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(G)}};X=ge([U(1,a.Inject(P.HoverManagerService)),U(2,a.Inject(P.CellAlertManagerService)),U(3,a.Inject(a.LocaleService)),U(4,_.IZenZoneService),U(5,a.Inject(g.INumfmtService)),U(6,a.IConfigService)],X);const K={id:"sheet.operation.close.numfmt.panel",type:a.CommandType.OPERATION,handler:()=>!0},L={id:"sheet.operation.open.numfmt.panel",type:a.CommandType.OPERATION,handler:e=>(e.get(H).openPanel(),!0)};var Se=Object.getOwnPropertyDescriptor,ye=(e,t,r,n)=>{for(var i=n>1?void 0:n?Se(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=c(i)||i);return i},_e=(e,t)=>(r,n)=>t(r,n,e);const J=y.createContext([]);let F=class{constructor(e){this._localStorageService=e}_getKey(e){return`userHabitController_${e}`}async addHabit(e,t){const r=this._getKey(e);return this._localStorageService.getItem(r).then(n=>{n||this._localStorageService.setItem(r,t)})}markHabit(e,t){const r=this._getKey(e);this._localStorageService.getItem(r).then(n=>{if(n){const i=n.findIndex(s=>s===t);i>-1&&n.splice(i,1),n.unshift(t),this._localStorageService.setItem(r,n)}})}async getHabit(e,t){const r=this._getKey(e),n=await this._localStorageService.getItem(r);if(t&&n){const i=n.map((s,c,m)=>{const o=m.length;return{value:s,priority:o-c}});return t.sort((s,c)=>{var u,v;const m=((u=i.find(d=>d.value===s))==null?void 0:u.priority)||-1;return(((v=i.find(d=>d.value===c))==null?void 0:v.priority)||-1)-m})}return n||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};F=ye([_e(0,a.Inject(a.ILocalStorageService))],F);const ee="numfmtCurrency",Ce=e=>{const t=_.useDependency(F),[r,n]=y.useState(h.currencySymbols);return y.useEffect(()=>{t.addHabit("numfmtCurrency",[]).then(()=>{t.getHabit(ee,[...h.currencySymbols]).then(s=>{n(s),e&&e(s)})})},[]),{userHabitCurrency:r,mark:s=>{t.markHabit(ee,s)}}},be=()=>{const e=y.useRef([]),[t,r]=y.useState({});return y.useEffect(()=>{e.current.forEach(i=>{i()}),e.current=[]},[t]),i=>{e.current.push(i),r({})}},Ie=e=>!!h.getCurrencyType(e)&&e.startsWith("_("),xe=e=>{const{defaultPattern:t,action:r,onChange:n}=e,[i,s]=y.useState(()=>h.getDecimalFromPattern(t||"",2)),c=y.useContext(J),[m,o]=y.useState(()=>h.getCurrencyType(t)||c[0]),u=y.useMemo(()=>c.map(C=>({label:C,value:C})),[]),d=_.useDependency(a.LocaleService).t;r.current=()=>h.setPatternDecimal(`_("${m}"* #,##0${i>0?".0":""}_)`,i);const p=C=>{o(C),n(h.setPatternDecimal(`_("${C}"* #,##0${i>0?".0":""}_)`,i))},S=C=>{const f=C||0;s(f),n(h.setPatternDecimal(`_("${m}"* #,##0${f>0?".0":""}_)`,f))};return l.jsxs("div",{children:[l.jsxs("div",{className:"univer-mt-4 univer-flex univer-justify-between",children:[l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:d("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2 univer-w-32",children:l.jsx(N.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(N.Select,{options:u,value:m,onChange:p})})]})]}),l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:d("sheet.numfmt.accountingDes")})]})},Ne=e=>!!h.getCurrencyType(e)&&!e.startsWith("_("),Te=e=>{const r=_.useDependency(a.LocaleService).t,n=y.useContext(J),[i,s]=y.useState(()=>h.getCurrencyType(e.defaultPattern)||n[0]),[c,m]=y.useState(()=>h.getDecimalFromPattern(e.defaultPattern||"",2)),[o,u]=y.useState(()=>{var b;const f=h.getCurrencyFormatOptions(i);return((b=f.find(T=>a.isPatternEqualWithoutDecimal(T.value,e.defaultPattern)))==null?void 0:b.value)||f[0].value}),v=y.useMemo(()=>h.getCurrencyFormatOptions(i),[i]),d=y.useMemo(()=>n.map(f=>({label:f,value:f})),[n]);e.action.current=()=>h.setPatternDecimal(o,c);const p=f=>{if(f===void 0)return;s(f);const x=h.getCurrencyFormatOptions(f)[0].value;u(x),e.onChange(h.setPatternDecimal(x,c))},S=f=>{f!==void 0&&(u(f),e.onChange(h.setPatternDecimal(f,c)))},C=f=>{m(f||0),e.onChange(h.setPatternDecimal(o,f||0))};return l.jsxs("div",{children:[l.jsxs("div",{className:"univer-mt-4 univer-flex univer-justify-between",children:[l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:r("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2 univer-w-32",children:l.jsx(N.InputNumber,{value:c,max:20,min:0,onChange:C})})]}),l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:r("sheet.numfmt.currencyType")}),l.jsx("div",{className:"univer-mt-2 univer-w-36",children:l.jsx(N.Select,{value:i,options:d,onChange:p})})]})]}),l.jsx("div",{className:"label univer-mt-4",children:r("sheet.numfmt.negType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(N.SelectList,{value:o,options:v,onChange:S})}),l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",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 i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},E.apply(this,arguments)},Ee=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r},ie=y.forwardRef(function(e,t){var r=e.icon,n=e.id,i=e.className,s=e.extend,c=Ee(e,["icon","id","className","extend"]),m="univerjs-icon univerjs-icon-".concat(n," ").concat(i||"").trim(),o=y.useRef("_".concat(je()));return se(r,"".concat(n),{defIds:r.defIds,idSuffix:o.current},E({ref:t,className:m},c),s)});function se(e,t,r,n,i){return y.createElement(e.tag,E(E({key:t},Pe(e,r,i)),n),(Me(e,r).children||[]).map(function(s,c){return se(s,"".concat(t,"-").concat(e.tag,"-").concat(c),r,void 0,i)}))}function Pe(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(s){var c=s[0],m=s[1];c==="mask"&&typeof m=="string"&&(n[c]=m.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var i=t.defIds;return!i||i.length===0||(e.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(function(s){var c=s[0],m=s[1];typeof m=="string"&&(n[c]=m.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function Me(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(i){return typeof i.attrs.id=="string"&&n&&n.includes(i.attrs.id)?E(E({},i),{attrs:E(E({},i.attrs),{id:i.attrs.id+t.idSuffix})}):i})}):e}function je(){return Math.random().toString(36).substring(2,8)}ie.displayName="UniverIcon";var Re={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},ae=y.forwardRef(function(e,t){return y.createElement(ie,Object.assign({},e,{id:"check-mark-icon",ref:t,icon:Re}))});ae.displayName="CheckMarkIcon";const Z="customFormat",Y="numfmt_custom_pattern";function we(e){const{defaultPattern:t,action:r,onChange:n}=e,i=_.useDependency(F),s=_.useDependency(a.ILocalStorageService),c=_.useDependency(a.LocaleService),[m,o]=y.useState(t);r.current=()=>(i.markHabit(Z,m),s.getItem(Y).then((S=[])=>{const C=[...new Set([m,...S||[]])].splice(0,10).filter(f=>!!f);s.setItem(Y,C)}),m);const[u,v]=y.useState([]);y.useEffect(()=>{s.getItem(Y).then(S=>{const C=[...h.CURRENCYFORMAT.map(f=>f.suffix("$")),...h.DATEFMTLISG.map(f=>f.suffix),...h.NUMBERFORMAT.map(f=>f.suffix)];C.push(...S||[]),i.addHabit(Z,[]).finally(()=>{i.getHabit(Z,C).then(f=>{v([...new Set(f)])})})})},[]);const d=S=>{o(S),n(S)},p=()=>{n(m)};return l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:c.t("sheet.numfmt.customFormat")}),l.jsx(N.Input,{placeholder:c.t("sheet.numfmt.customFormat"),onBlur:p,value:m,onChange:o,className:"univer-mt-2 univer-w-full"}),l.jsx("div",{className:N.clsx("univer-mt-2 univer-max-h-[400px] univer-overflow-auto univer-rounded-lg univer-p-2",N.borderClassName),children:u.map(S=>l.jsxs("div",{onClick:()=>d(S),className:"univer-flex univer-cursor-pointer univer-items-center univer-gap-1.5 univer-py-1.5 univer-text-sm",children:[l.jsx("div",{className:"univer-flex univer-w-4 univer-items-center univer-text-primary-600",children:m===S&&l.jsx(ae,{})}),l.jsx("div",{children:S})]},S))}),l.jsx("div",{className:"univer-mt-3 univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200",children:c.t("sheet.numfmt.customFormatDes")})]})}const De=e=>{const t=a.numfmt.getFormatInfo(e);return h.getDateFormatOptions().map(r=>r.value).includes(e)||["date","datetime","time"].includes(t.type)};function Oe(e){const{onChange:t,defaultPattern:r}=e,n=y.useMemo(h.getDateFormatOptions,[]),i=_.useDependency(a.LocaleService),[s,c]=y.useState(()=>{if(r){const o=n.find(u=>u.value===r);if(o)return o.value}return n[0].value});e.action.current=()=>s;const m=o=>{o!==void 0&&(c(o),t(o))};return l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:i.t("sheet.numfmt.dateType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(N.SelectList,{value:s,options:n,onChange:m})}),l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:i.t("sheet.numfmt.dateDes")})]})}const Ue=e=>!e,ke=e=>{const r=_.useDependency(a.LocaleService).t;return e.action.current=()=>"",l.jsx("div",{children:l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:r("sheet.numfmt.generalDes")})})},$e=e=>h.getNumberFormatOptions().some(t=>a.isPatternEqualWithoutDecimal(t.value,e));function Le(e){const t=_.useDependency(a.LocaleService),r=y.useMemo(h.getNumberFormatOptions,[]),[n,i]=y.useState(()=>h.getDecimalFromPattern(e.defaultPattern||"",0)),[s,c]=y.useState(()=>{const d=r.find(p=>a.isPatternEqualWithoutDecimal(p.value,e.defaultPattern||""));return(d==null?void 0:d.value)||r[0].value}),m=y.useMemo(()=>h.setPatternDecimal(s,Number(n||0)),[s,n]),o=y.useMemo(()=>!h.isPatternHasDecimal(s),[s]),u=d=>{i(d||0),e.onChange(h.setPatternDecimal(s,Number(d||0)))},v=d=>{d!==void 0&&(i(h.getDecimalFromPattern(d,0)),c(d),e.onChange(d))};return e.action.current=()=>m,l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:t.t("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(N.InputNumber,{disabled:o,value:n,max:20,min:0,onChange:u})}),l.jsxs("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:[" ",t.t("sheet.numfmt.negType")]}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(N.SelectList,{onChange:v,options:r,value:s})}),l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:t.t("sheet.numfmt.thousandthPercentileDes")})]})}const Fe=e=>{const{defaultValue:t,defaultPattern:r,row:n,col:i}=e.value,s=_.useDependency(a.LocaleService),c=y.useRef(()=>""),m=s.t,o=be(),u=y.useMemo(()=>[{label:"sheet.numfmt.general",component:ke},{label:"sheet.numfmt.accounting",component:xe},{label:"sheet.numfmt.currency",component:Te},{label:"sheet.numfmt.date",component:Oe},{label:"sheet.numfmt.thousandthPercentile",component:Le},{label:"sheet.numfmt.customFormat",component:we}].map(I=>({...I,label:m(I.label)})),[]),[v,d]=y.useState(b),[p,S]=y.useState(()=>`${n}_${i}`),{mark:C,userHabitCurrency:f}=Ce(()=>S(`${n}_${i}_userCurrency'`)),x=y.useMemo(()=>{var I;return(I=u.find(O=>O.label===v))==null?void 0:I.component},[v]);function b(){return[Ue,Ie,Ne,De,$e].reduce((O,me,de)=>O||(me(r)?u[de].label:""),"")||u[0].label}const T=u.map(I=>({label:I.label,value:I.label})),j=I=>{d(I),o(()=>e.onChange({type:"change",value:c.current()||""}))},w=y.useCallback(I=>{e.onChange({type:"change",value:I})},[]),D=()=>{const I=c.current()||"",O=h.getCurrencyType(I);O&&C(O),e.onChange({type:"confirm",value:I})},k=()=>{e.onChange({type:"cancel",value:""})},q={onChange:w,defaultValue:t,defaultPattern:r,action:c};return y.useEffect(()=>{d(b()),S(`${n}_${i}`)},[n,i]),l.jsxs("div",{className:N.clsx("univer-flex univer-h-full univer-flex-col univer-justify-between univer-overflow-y-auto univer-pb-5",N.scrollbarClassName),children:[l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-3.5 univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.numfmtType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(N.Select,{className:"univer-w-full",value:v,options:T,onChange:j})}),l.jsx("div",{children:x&&l.jsx(J.Provider,{value:f,children:y.createElement(x,{...q,key:p})})})]}),l.jsxs("div",{className:"univer-mb-5 univer-mt-3.5 univer-flex univer-justify-end",children:[l.jsx(N.Button,{onClick:k,className:"univer-mr-3",children:m("sheet.numfmt.cancel")}),l.jsx(N.Button,{variant:"primary",onClick:D,children:m("sheet.numfmt.confirm")})]})]})};var He=Object.getOwnPropertyDescriptor,Ae=(e,t,r,n)=>{for(var i=n>1?void 0:n?He(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=c(i)||i);return i},M=(e,t)=>(r,n)=>t(r,n,e);const te="SHEET_NUMFMT_PANEL";let H=class extends a.Disposable{constructor(t,r,n,i,s,c,m,o,u,v,d){super();A(this,"_previewPattern","");A(this,"_sidebarDisposable",null);this._sheetInterceptorService=t,this._themeService=r,this._univerInstanceService=n,this._commandService=i,this._selectionManagerService=s,this._renderManagerService=c,this._numfmtService=m,this._componentManager=o,this._sidebarService=u,this._localeService=v,this._sheetsNumfmtCellContentController=d,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener(),this._initNumfmtLocalChange()}_initNumfmtLocalChange(){this.disposeWithMe(R.merge(this._sheetsNumfmtCellContentController.locale$,this._localeService.currentLocale$).subscribe(()=>{this._forceUpdate()}))}openPanel(){var x;const t=this._sidebarService,r=this._selectionManagerService,n=this._commandService,i=this._univerInstanceService,s=this._numfmtService,c=this._localeService,o=(((x=r.getCurrentSelections())==null?void 0:x.map(b=>b.range))||[])[0];if(!o)return!1;const u=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),v=u.getActiveSheet();if(!v)return!1;const d=v.getCellRaw(o.startRow,o.startColumn),p=s.getValue(u.getUnitId(),v.getSheetId(),o.startRow,o.startColumn);let S="";p&&(S=p.pattern);const C=(d==null?void 0:d.t)===a.CellValueType.NUMBER?d.v:12345678,f={onChange:b=>{var T;if(b.type==="change")this._previewPattern=b.value,this._forceUpdate();else if(b.type==="confirm"){const j=((T=r.getCurrentSelections())==null?void 0:T.map(k=>k.range))||[],w={values:[]},D=h.getPatternType(b.value);j.forEach(k=>{a.Range.foreach(k,(q,I)=>{w.values.push({row:q,col:I,pattern:b.value,type:D})})}),n.executeCommand(h.SetNumfmtCommand.id,w),t.close()}else b.type==="cancel"&&t.close()},value:{defaultPattern:S,defaultValue:C,row:o.startRow,col:o.startColumn}};return this._sidebarDisposable=t.open({header:{title:c.t("sheet.numfmt.title")},children:{label:te,...f},onClose:()=>{this._forceUpdate(),n.executeCommand(K.id)}}),!0}_forceUpdate(t){var n;const r=this._renderManagerService.getRenderById(t!=null?t:this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId());r==null||r.with(P.SheetSkeletonManagerService).reCalculate(),(n=r==null?void 0:r.mainComponent)==null||n.makeDirty()}_initCommands(){[L,K].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initPanel(){this.disposeWithMe(this._componentManager.register(te,Fe))}_initRealTimeRenderingInterceptor(){const t=new R.Observable(n=>{this._commandService.onCommandExecuted(i=>{i.id===L.id&&n.next(!0),i.id===K.id&&n.next(!1)})}),r=R.combineLatest([t,this._selectionManagerService.selectionMoveEnd$.pipe(W.map(n=>n?n.map(i=>i.range):[]))]);this.disposeWithMe(a.toDisposable(r.pipe(W.switchMap(([n,i])=>new R.Observable(s=>{const c=new a.DisposableCollection;return n&&i.length&&s.next({selectionRanges:i,disposableCollection:c}),()=>{c.dispose()}})),W.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:n,selectionRanges:i})=>{var c,m;const s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);this.openPanel(),n.add(this._sheetInterceptorService.intercept(g.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,effect:a.InterceptorEffectEnum.Value|a.InterceptorEffectEnum.Style,handler:(o,u,v)=>{var C;const{row:d,col:p}=u,S=v(o)||{};if(i.find(f=>f.startColumn<=p&&f.endColumn>=p&&f.startRow<=d&&f.endRow>=d)){const f=u.worksheet.getCellRaw(d,p),x=f==null?void 0:f.v,b=f==null?void 0:f.t;if(x==null||b!==a.CellValueType.NUMBER||this._previewPattern===null)return S;const T=h.getPatternPreviewIgnoreGeneral(this._previewPattern,x,this._sheetsNumfmtCellContentController.locale);if(T.color){const j=(C=this._themeService.getColorFromTheme(`${T.color}.500`))!=null?C:T.color;return{...S,v:T.result,t:a.CellValueType.STRING,s:{cl:{rgb:j}}}}return{...S,v:T.result,t:a.CellValueType.STRING}}return S}})),(m=(c=this._renderManagerService.getRenderById(s.getUnitId()))==null?void 0:c.mainComponent)==null||m.makeDirty()})))}_commandExecutedListener(){const t=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id];this.disposeWithMe(new R.Observable(r=>{const n=this._commandService.onCommandExecuted(i=>{if(t.includes(i.id)){const s=i.params;r.next(s.unitId)}});return()=>n.dispose()}).pipe(W.debounceTime(16)).subscribe(r=>this._forceUpdate(r)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(t=>{var r;t||((r=this._sidebarDisposable)==null||r.dispose(),this._sidebarDisposable=null)})}};H=Ae([M(0,a.Inject(g.SheetInterceptorService)),M(1,a.Inject(a.ThemeService)),M(2,a.IUniverInstanceService),M(3,a.ICommandService),M(4,a.Inject(g.SheetsSelectionsService)),M(5,re.IRenderManagerService),M(6,g.INumfmtService),M(7,a.Inject(_.ComponentManager)),M(8,_.ISidebarService),M(9,a.Inject(a.LocaleService)),M(10,a.Inject(h.SheetsNumfmtCellContentController))],H);var We=Object.getOwnPropertyDescriptor,Be=(e,t,r,n)=>{for(var i=n>1?void 0:n?We(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=c(i)||i);return i},$=(e,t)=>(r,n)=>t(r,n,e);const Ve=()=>{let e=[];return{add:(i,s,c,m,o)=>e.push({unitId:i,subUnitId:s,row:c,col:m,value:o}),getEffects:()=>e,clean:()=>{e=[]}}};let B=class extends a.Disposable{constructor(t,r,n,i,s){super();A(this,"_collectEffectMutation",Ve());this._sheetInterceptorService=t,this._numfmtService=r,this._univerInstanceService=n,this._injector=i,this._editorBridgeService=s,this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(a.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.BEFORE_CELL_EDIT,{handler:(t,r,n)=>{const i=r.row,s=r.col,c=this._numfmtService.getValue(r.unitId,r.subUnitId,i,s);if(c)switch(h.getPatternType(c.pattern)){case"scientific":case"currency":case"grouped":case"number":{const o=r.worksheet.getCellRaw(i,s);return(o==null?void 0:o.t)===a.CellValueType.NUMBER&&(o==null?void 0:o.v)!==void 0&&o.v!==null&&a.isRealNum(o.v)&&(o.v=fe.stripErrorMargin(Number(o.v))),n&&n(o)}case"percent":case"date":case"time":case"datetime":default:return n&&n(t)}return n(t)}})))}_initInterceptorEditorEnd(){this.disposeWithMe(a.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.AFTER_CELL_EDIT,{handler:(t,r,n)=>{var u,v,d;if(!(t!=null&&t.v)&&!(t!=null&&t.p))return n(t);this._collectEffectMutation.clean();const i=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col),s=r.worksheet.getCellRaw(r.row,r.col);if(a.isTextFormat(i==null?void 0:i.pattern)||t.t===a.CellValueType.FORCE_STRING)return n(t);const c=(u=t.p)==null?void 0:u.body,m=(d=(v=t==null?void 0:t.p)==null?void 0:v.body)!=null&&d.dataStream?t.p.body.dataStream.replace(/\r\n$/,""):String(t.v),o=h.getNumfmtParseValueFilter(m);if(c)if(qe(c)){const{dataStream:p}=c,S=p.replace(/\r\n$/,""),C=Number(S);if(Number.isNaN(C)&&!o)return n(t)}else return n(t);if(o){if(!o.z&&!(i!=null&&i.pattern)&&(s==null?void 0:s.t)!==a.CellValueType.STRING&&(s==null?void 0:s.t)!==a.CellValueType.FORCE_STRING&&a.willLoseNumericPrecision(m))return n({...t,p:void 0,v:m,t:a.CellValueType.FORCE_STRING});o.z&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:o.z});const p=Number(o.v);return n({...t,p:void 0,v:p,t:a.CellValueType.NUMBER})}return n(t)}})))}_initInterceptorCommands(){const t=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(r){var n;switch(r.id){case g.SetRangeValuesCommand.id:{const i=t._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=i.getUnitId(),c=(n=i.getActiveSheet())==null?void 0:n.getSheetId();if(!c)return{redos:[],undos:[]};const m=t._collectEffectMutation.getEffects();if(t._collectEffectMutation.clean(),!m.length)return{redos:[],undos:[]};const o=m.filter(p=>{var S;return!!((S=p.value)!=null&&S.pattern)}).map(p=>({row:p.row,col:p.col,pattern:p.value.pattern})),u=m.filter(p=>{var S;return!((S=p.value)!=null&&S.pattern)}).map(p=>({startRow:p.row,endColumn:p.col,startColumn:p.col,endRow:p.row})),v=[],d=[];if(o.length){const p={id:g.SetNumfmtMutation.id,params:g.transformCellsToRange(s,c,o)};v.push(p),d.push(...g.factorySetNumfmtUndoMutation(t._injector,p.params))}if(u.length){const p={id:g.RemoveNumfmtMutation.id,params:{unitId:s,subUnitId:c,ranges:u}};v.push(p),d.push(...g.factoryRemoveNumfmtUndoMutation(t._injector,p.params))}return{redos:v,undos:d.reverse()}}}return{redos:[],undos:[]}}}))}};B=Be([$(0,a.Inject(g.SheetInterceptorService)),$(1,a.Inject(g.INumfmtService)),$(2,a.Inject(a.IUniverInstanceService)),$(3,a.Inject(a.Injector)),$(4,a.Optional(P.IEditorBridgeService))],B);function qe(e){const{textRuns:t=[],paragraphs:r=[],customRanges:n,customBlocks:i=[]}=e,s=["va"];return!(t.some(c=>!!(c.ts&&Object.keys(c.ts).some(o=>s.includes(o))))||r.some(c=>c.bullet)||r.length>=2||n!=null&&n.length||i.length>0)}const ce=e=>[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:a.DEFAULT_TEXT_FORMAT_EXCEL},"|",{label:"sheet.numfmt.number",pattern:"0"},{label:"sheet.numfmt.percent",pattern:"0.00%"},{label:"sheet.numfmt.scientific",pattern:"0.00E+00"},"|",{label:"sheet.numfmt.accounting",pattern:`"${e}" #,##0.00_);[Red]("${e}"#,##0.00)`},{label:"sheet.numfmt.financialValue",pattern:"#,##0.00;[Red]#,##0.00"},{label:"sheet.numfmt.currency",pattern:`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`},{label:"sheet.numfmt.roundingCurrency",pattern:`"${e}"#,##0;[Red]"${e}"#,##0`},"|",{label:"sheet.numfmt.date",pattern:"yyyy-mm-dd;@"},{label:"sheet.numfmt.time",pattern:'am/pm h":"mm":"ss'},{label:"sheet.numfmt.dateTime",pattern:"yyyy-m-d am/pm h:mm"},{label:"sheet.numfmt.timeDuration",pattern:"h:mm:ss"},"|",{label:"sheet.numfmt.moreFmt",pattern:""}],Ge=e=>({icon:new R.Observable(t=>{const r=e.get(a.LocaleService);return t.next(h.getCurrencySymbolIconByLocale(r.getCurrentLocale()).icon),r.localeChanged$.subscribe(()=>{t.next(h.getCurrencySymbolIconByLocale(r.getCurrentLocale()).icon)})}),id:h.SetCurrencyCommand.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:P.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Ke=e=>({icon:"AddDigitsIcon",id:h.AddDecimalCommand.id,title:"sheet.numfmt.addDecimal",tooltip:"sheet.numfmt.addDecimal",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:P.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Ze=e=>({icon:"ReduceDigitsIcon",id:h.SubtractDecimalCommand.id,title:"sheet.numfmt.subtractDecimal",tooltip:"sheet.numfmt.subtractDecimal",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:P.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Ye=e=>({icon:"PercentIcon",id:h.SetPercentCommand.id,title:"sheet.numfmt.percent",tooltip:"sheet.numfmt.percent",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:P.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),ze=e=>{const t=e.get(a.IUniverInstanceService),r=e.get(a.ICommandService),n=e.get(a.LocaleService),i=e.get(g.SheetsSelectionsService),s=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id],c=P.deriveStateFromActiveSheet$(t,"",({workbook:m,worksheet:o})=>new R.Observable(u=>R.merge(i.selectionMoveEnd$,a.fromCallback(r.onCommandExecuted.bind(r)).pipe(R.filter(([v])=>s.includes(v.id)))).subscribe(()=>{var d,p;const v=i.getCurrentSelections();if(v&&v[0]){const S=v[0].range,C=S.startRow,f=S.startColumn,x=(p=m.getStyles().get((d=o.getCell(C,f))==null?void 0:d.s))==null?void 0:p.n,b=x==null?void 0:x.pattern,T=h.getCurrencySymbolByLocale(n.getCurrentLocale());let j=n.t("sheet.numfmt.general");if(a.isDefaultFormat(b)){u.next(j);return}if(b){const w=ce(T).filter(D=>typeof D=="object"&&D.pattern).find(D=>a.isPatternEqualWithoutDecimal(b,D.pattern));w&&typeof w=="object"&&w.pattern?j=n.t(w.label):j=n.t("sheet.numfmt.moreFmt")}u.next(j)}})));return{label:oe,id:L.id,tooltip:"sheet.numfmt.title",type:_.MenuItemType.SELECTOR,slot:!0,selections:[{label:{name:le,hoverable:!1,selectable:!1}}],value$:c,hidden$:_.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:P.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetSetCellStylePermission,g.WorksheetEditPermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}},oe="sheet.numfmt.moreNumfmtType",le="sheet.numfmt.moreNumfmtType.options",Xe=e=>{const{value:t}=e,r=_.useDependency(a.LocaleService),n=t!=null?t:r.t("sheet.numfmt.general");return l.jsx("span",{className:"univer-text-sm",children:n})},Je=()=>{const e=_.useDependency(a.ICommandService),t=_.useDependency(a.LocaleService),r=_.useDependency(_.ILayoutService),n=_.useDependency(h.SheetsNumfmtCellContentController),i=_.useDependency(g.SheetsSelectionsService),s=u=>{const v=i.getCurrentLastSelection();if(!v)return;const d=v.range,p=[];a.Range.foreach(d,(S,C)=>{u?p.push({row:S,col:C,pattern:u,type:h.getPatternType(u)}):p.push({row:S,col:C})}),e.executeCommand(h.SetNumfmtCommand.id,{values:p}),r.focus()},c=y.useMemo(()=>{const u=h.localeCurrencySymbolMap.get(t.getCurrentLocale());return ce(u)},[t]),m=u=>{if(u===0)s(null);else if(u===c.length-1)e.executeCommand(L.id),r.focus();else{const v=c[u];v.pattern&&s(v.pattern)}},o=1220;return l.jsx("div",{className:"univer-grid univer-gap-1 univer-p-1.5",children:c.map((u,v)=>u==="|"?l.jsx(N.Separator,{},v):l.jsxs("div",{className:"univer-flex univer-h-7 univer-items-center univer-justify-between univer-gap-6 univer-rounded univer-px-2 univer-text-sm hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",onClick:()=>{m(v)},children:[l.jsx("span",{children:t.t(u.label)}),l.jsx("span",{className:"univer-text-xs univer-text-gray-500",children:u.pattern?h.getPatternPreview(u.pattern||"",o,n.locale).result.trim():""})]},v))})},Qe={[_.RibbonDataGroup.FORMULAS]:{[h.SetCurrencyCommand.id]:{order:0,menuItemFactory:Ge},[h.AddDecimalCommand.id]:{order:1,menuItemFactory:Ke},[h.SubtractDecimalCommand.id]:{order:2,menuItemFactory:Ze},[h.SetPercentCommand.id]:{order:3,menuItemFactory:Ye},[L.id]:{order:4,menuItemFactory:ze}}};var et=Object.getOwnPropertyDescriptor,tt=(e,t,r,n)=>{for(var i=n>1?void 0:n?et(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=c(i)||i);return i},ne=(e,t)=>(r,n)=>t(r,n,e);let V=class extends a.Disposable{constructor(e,t){super(),this._componentManager=e,this._menuManagerService=t,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(Qe),[[oe,Xe],[le,Je]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};V=tt([ne(0,a.Inject(_.ComponentManager)),ne(1,_.IMenuManagerService)],V);var nt=Object.defineProperty,rt=Object.getOwnPropertyDescriptor,it=(e,t,r)=>t in e?nt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,st=(e,t,r,n)=>{for(var i=n>1?void 0:n?rt(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=c(i)||i);return i},z=(e,t)=>(r,n)=>t(r,n,e),ue=(e,t,r)=>it(e,typeof t!="symbol"?t+"":t,r);const at="SHEET_NUMFMT_UI_PLUGIN";exports.UniverSheetsNumfmtUIPlugin=class extends a.Plugin{constructor(t=Q,r,n,i){super(),this._config=t,this._injector=r,this._configService=n,this._renderManagerService=i;const{menu:s,...c}=a.merge({},Q,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig("sheets-numfmt-ui.config",c)}onStarting(){a.registerDependencies(this._injector,[[H],[B],[F],[V]])}onRendered(){this._registerRenderModules(),a.touchDependencies(this._injector,[[H],[B],[V]])}_registerRenderModules(){[[X]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,r))})}};ue(exports.UniverSheetsNumfmtUIPlugin,"pluginName",at);ue(exports.UniverSheetsNumfmtUIPlugin,"type",a.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtUIPlugin=st([a.DependentOn(P.UniverSheetsUIPlugin,h.UniverSheetsNumfmtPlugin),z(1,a.Inject(a.Injector)),z(2,a.IConfigService),z(3,re.IRenderManagerService)],exports.UniverSheetsNumfmtUIPlugin);
|
|
1
|
+
"use strict";var he=Object.defineProperty;var ve=(e,t,r)=>t in e?he(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 a=require("@univerjs/core"),re=require("@univerjs/engine-render"),h=require("@univerjs/sheets-numfmt"),P=require("@univerjs/sheets-ui"),g=require("@univerjs/sheets"),_=require("@univerjs/ui"),R=require("rxjs"),W=require("rxjs/operators"),l=require("react/jsx-runtime"),y=require("react"),N=require("@univerjs/design"),fe=require("@univerjs/engine-formula"),Q={};var pe=Object.getOwnPropertyDescriptor,ge=(e,t,r,n)=>{for(var i=n>1?void 0:n?pe(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=c(i)||i);return i},U=(e,t)=>(r,n)=>t(r,n,e);const G="SHEET_NUMFMT_ALERT";let X=class extends a.Disposable{constructor(e,t,r,n,i,s,c){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=r,this._localeService=n,this._zenZoneService=i,this._numfmtService=s,this._configService=c,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(R.debounceTime(100)).subscribe(e=>{var t,r;if(e){const n=e.location,i=this._context.unit,s=i.getActiveSheet();if(!s)return;const c=n.unitId,m=n.subUnitId;let o;const u=s.getCell(n.row,n.col);if(u!=null&&u.s){const v=i.getStyles().get(u.s);v!=null&&v.n&&(o=v.n)}if(o||(o=this._numfmtService.getValue(c,m,n.row,n.col)),!o){this._hideAlert();return}if(a.isTextFormat(o.pattern)&&a.Tools.isDefine(u==null?void 0:u.v)&&a.isRealNum(u.v)){if((t=this._configService.getConfig(h.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY))!=null&&t.disableTextFormatAlert)return;const v=this._cellAlertManagerService.currentAlert.get(G),d=(r=v==null?void 0:v.alert)==null?void 0:r.location;if(d&&d.row===n.row&&d.col===n.col&&d.subUnitId===n.subUnitId&&d.unitId===n.unitId)return;this._cellAlertManagerService.showAlert({type:P.CellAlertType.ERROR,title:this._localeService.t("info.error"),message:this._localeService.t("info.forceStringInfo"),location:n,width:200,height:74,key:G});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(G)}};X=ge([U(1,a.Inject(P.HoverManagerService)),U(2,a.Inject(P.CellAlertManagerService)),U(3,a.Inject(a.LocaleService)),U(4,_.IZenZoneService),U(5,a.Inject(g.INumfmtService)),U(6,a.IConfigService)],X);const K={id:"sheet.operation.close.numfmt.panel",type:a.CommandType.OPERATION,handler:()=>!0},L={id:"sheet.operation.open.numfmt.panel",type:a.CommandType.OPERATION,handler:e=>(e.get(H).openPanel(),!0)};var Se=Object.getOwnPropertyDescriptor,ye=(e,t,r,n)=>{for(var i=n>1?void 0:n?Se(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=c(i)||i);return i},_e=(e,t)=>(r,n)=>t(r,n,e);const J=y.createContext([]);let F=class{constructor(e){this._localStorageService=e}_getKey(e){return`userHabitController_${e}`}async addHabit(e,t){const r=this._getKey(e);return this._localStorageService.getItem(r).then(n=>{n||this._localStorageService.setItem(r,t)})}markHabit(e,t){const r=this._getKey(e);this._localStorageService.getItem(r).then(n=>{if(n){const i=n.findIndex(s=>s===t);i>-1&&n.splice(i,1),n.unshift(t),this._localStorageService.setItem(r,n)}})}async getHabit(e,t){const r=this._getKey(e),n=await this._localStorageService.getItem(r);if(t&&n){const i=n.map((s,c,m)=>{const o=m.length;return{value:s,priority:o-c}});return t.sort((s,c)=>{var u,v;const m=((u=i.find(d=>d.value===s))==null?void 0:u.priority)||-1;return(((v=i.find(d=>d.value===c))==null?void 0:v.priority)||-1)-m})}return n||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};F=ye([_e(0,a.Inject(a.ILocalStorageService))],F);const ee="numfmtCurrency",Ce=e=>{const t=_.useDependency(F),[r,n]=y.useState(h.currencySymbols);return y.useEffect(()=>{t.addHabit("numfmtCurrency",[]).then(()=>{t.getHabit(ee,[...h.currencySymbols]).then(s=>{n(s),e&&e(s)})})},[]),{userHabitCurrency:r,mark:s=>{t.markHabit(ee,s)}}},be=()=>{const e=y.useRef([]),[t,r]=y.useState({});return y.useEffect(()=>{e.current.forEach(i=>{i()}),e.current=[]},[t]),i=>{e.current.push(i),r({})}},Ie=e=>!!h.getCurrencyType(e)&&e.startsWith("_("),xe=e=>{const{defaultPattern:t,action:r,onChange:n}=e,[i,s]=y.useState(()=>h.getDecimalFromPattern(t||"",2)),c=y.useContext(J),[m,o]=y.useState(()=>h.getCurrencyType(t)||c[0]),u=y.useMemo(()=>c.map(C=>({label:C,value:C})),[]),d=_.useDependency(a.LocaleService).t;r.current=()=>h.setPatternDecimal(`_("${m}"* #,##0${i>0?".0":""}_)`,i);const p=C=>{o(C),n(h.setPatternDecimal(`_("${C}"* #,##0${i>0?".0":""}_)`,i))},S=C=>{const f=C||0;s(f),n(h.setPatternDecimal(`_("${m}"* #,##0${f>0?".0":""}_)`,f))};return l.jsxs("div",{children:[l.jsxs("div",{className:"univer-mt-4 univer-flex univer-justify-between",children:[l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:d("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2 univer-w-32",children:l.jsx(N.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(N.Select,{options:u,value:m,onChange:p})})]})]}),l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:d("sheet.numfmt.accountingDes")})]})},Ne=e=>!!h.getCurrencyType(e)&&!e.startsWith("_("),Te=e=>{const r=_.useDependency(a.LocaleService).t,n=y.useContext(J),[i,s]=y.useState(()=>h.getCurrencyType(e.defaultPattern)||n[0]),[c,m]=y.useState(()=>h.getDecimalFromPattern(e.defaultPattern||"",2)),[o,u]=y.useState(()=>{var b;const f=h.getCurrencyFormatOptions(i);return((b=f.find(T=>a.isPatternEqualWithoutDecimal(T.value,e.defaultPattern)))==null?void 0:b.value)||f[0].value}),v=y.useMemo(()=>h.getCurrencyFormatOptions(i),[i]),d=y.useMemo(()=>n.map(f=>({label:f,value:f})),[n]);e.action.current=()=>h.setPatternDecimal(o,c);const p=f=>{if(f===void 0)return;s(f);const x=h.getCurrencyFormatOptions(f)[0].value;u(x),e.onChange(h.setPatternDecimal(x,c))},S=f=>{f!==void 0&&(u(f),e.onChange(h.setPatternDecimal(f,c)))},C=f=>{m(f||0),e.onChange(h.setPatternDecimal(o,f||0))};return l.jsxs("div",{children:[l.jsxs("div",{className:"univer-mt-4 univer-flex univer-justify-between",children:[l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:r("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2 univer-w-32",children:l.jsx(N.InputNumber,{value:c,max:20,min:0,onChange:C})})]}),l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:r("sheet.numfmt.currencyType")}),l.jsx("div",{className:"univer-mt-2 univer-w-36",children:l.jsx(N.Select,{value:i,options:d,onChange:p})})]})]}),l.jsx("div",{className:"label univer-mt-4",children:r("sheet.numfmt.negType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(N.SelectList,{value:o,options:v,onChange:S})}),l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",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 i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},E.apply(this,arguments)},Ee=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r},ie=y.forwardRef(function(e,t){var r=e.icon,n=e.id,i=e.className,s=e.extend,c=Ee(e,["icon","id","className","extend"]),m="univerjs-icon univerjs-icon-".concat(n," ").concat(i||"").trim(),o=y.useRef("_".concat(je()));return se(r,"".concat(n),{defIds:r.defIds,idSuffix:o.current},E({ref:t,className:m},c),s)});function se(e,t,r,n,i){return y.createElement(e.tag,E(E({key:t},Pe(e,r,i)),n),(Me(e,r).children||[]).map(function(s,c){return se(s,"".concat(t,"-").concat(e.tag,"-").concat(c),r,void 0,i)}))}function Pe(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(s){var c=s[0],m=s[1];c==="mask"&&typeof m=="string"&&(n[c]=m.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var i=t.defIds;return!i||i.length===0||(e.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(function(s){var c=s[0],m=s[1];typeof m=="string"&&(n[c]=m.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function Me(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(i){return typeof i.attrs.id=="string"&&n&&n.includes(i.attrs.id)?E(E({},i),{attrs:E(E({},i.attrs),{id:i.attrs.id+t.idSuffix})}):i})}):e}function je(){return Math.random().toString(36).substring(2,8)}ie.displayName="UniverIcon";var Re={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},ae=y.forwardRef(function(e,t){return y.createElement(ie,Object.assign({},e,{id:"check-mark-icon",ref:t,icon:Re}))});ae.displayName="CheckMarkIcon";const Z="customFormat",Y="numfmt_custom_pattern";function we(e){const{defaultPattern:t,action:r,onChange:n}=e,i=_.useDependency(F),s=_.useDependency(a.ILocalStorageService),c=_.useDependency(a.LocaleService),[m,o]=y.useState(t);r.current=()=>(i.markHabit(Z,m),s.getItem(Y).then((S=[])=>{const C=[...new Set([m,...S||[]])].splice(0,10).filter(f=>!!f);s.setItem(Y,C)}),m);const[u,v]=y.useState([]);y.useEffect(()=>{s.getItem(Y).then(S=>{const C=[...h.CURRENCYFORMAT.map(f=>f.suffix("$")),...h.DATEFMTLISG.map(f=>f.suffix),...h.NUMBERFORMAT.map(f=>f.suffix)];C.push(...S||[]),i.addHabit(Z,[]).finally(()=>{i.getHabit(Z,C).then(f=>{v([...new Set(f)])})})})},[]);const d=S=>{o(S),n(S)},p=()=>{n(m)};return l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:c.t("sheet.numfmt.customFormat")}),l.jsx(N.Input,{placeholder:c.t("sheet.numfmt.customFormat"),onBlur:p,value:m,onChange:o,className:"univer-mt-2 univer-w-full"}),l.jsx("div",{className:N.clsx("univer-mt-2 univer-max-h-[400px] univer-overflow-auto univer-rounded-lg univer-p-2",N.borderClassName),children:u.map(S=>l.jsxs("div",{onClick:()=>d(S),className:"univer-flex univer-cursor-pointer univer-items-center univer-gap-1.5 univer-py-1.5 univer-text-sm",children:[l.jsx("div",{className:"univer-flex univer-w-4 univer-items-center univer-text-primary-600",children:m===S&&l.jsx(ae,{})}),l.jsx("div",{children:S})]},S))}),l.jsx("div",{className:"univer-mt-3 univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200",children:c.t("sheet.numfmt.customFormatDes")})]})}const De=e=>{const t=a.numfmt.getFormatInfo(e);return h.getDateFormatOptions().map(r=>r.value).includes(e)||["date","datetime","time"].includes(t.type)};function Oe(e){const{onChange:t,defaultPattern:r}=e,n=y.useMemo(h.getDateFormatOptions,[]),i=_.useDependency(a.LocaleService),[s,c]=y.useState(()=>{if(r){const o=n.find(u=>u.value===r);if(o)return o.value}return n[0].value});e.action.current=()=>s;const m=o=>{o!==void 0&&(c(o),t(o))};return l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:i.t("sheet.numfmt.dateType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(N.SelectList,{value:s,options:n,onChange:m})}),l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:i.t("sheet.numfmt.dateDes")})]})}const Ue=e=>!e,ke=e=>{const r=_.useDependency(a.LocaleService).t;return e.action.current=()=>"",l.jsx("div",{children:l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:r("sheet.numfmt.generalDes")})})},$e=e=>h.getNumberFormatOptions().some(t=>a.isPatternEqualWithoutDecimal(t.value,e));function Le(e){const t=_.useDependency(a.LocaleService),r=y.useMemo(h.getNumberFormatOptions,[]),[n,i]=y.useState(()=>h.getDecimalFromPattern(e.defaultPattern||"",0)),[s,c]=y.useState(()=>{const d=r.find(p=>a.isPatternEqualWithoutDecimal(p.value,e.defaultPattern||""));return(d==null?void 0:d.value)||r[0].value}),m=y.useMemo(()=>h.setPatternDecimal(s,Number(n||0)),[s,n]),o=y.useMemo(()=>!h.isPatternHasDecimal(s),[s]),u=d=>{i(d||0),e.onChange(h.setPatternDecimal(s,Number(d||0)))},v=d=>{d!==void 0&&(i(h.getDecimalFromPattern(d,0)),c(d),e.onChange(d))};return e.action.current=()=>m,l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:t.t("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(N.InputNumber,{disabled:o,value:n,max:20,min:0,onChange:u})}),l.jsxs("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:[" ",t.t("sheet.numfmt.negType")]}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(N.SelectList,{onChange:v,options:r,value:s})}),l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:t.t("sheet.numfmt.thousandthPercentileDes")})]})}const Fe=e=>{const{defaultValue:t,defaultPattern:r,row:n,col:i}=e.value,s=_.useDependency(a.LocaleService),c=y.useRef(()=>""),m=s.t,o=be(),u=y.useMemo(()=>[{label:"sheet.numfmt.general",component:ke},{label:"sheet.numfmt.accounting",component:xe},{label:"sheet.numfmt.currency",component:Te},{label:"sheet.numfmt.date",component:Oe},{label:"sheet.numfmt.thousandthPercentile",component:Le},{label:"sheet.numfmt.customFormat",component:we}].map(I=>({...I,label:m(I.label)})),[]),[v,d]=y.useState(b),[p,S]=y.useState(()=>`${n}_${i}`),{mark:C,userHabitCurrency:f}=Ce(()=>S(`${n}_${i}_userCurrency'`)),x=y.useMemo(()=>{var I;return(I=u.find(O=>O.label===v))==null?void 0:I.component},[v]);function b(){return[Ue,Ie,Ne,De,$e].reduce((O,me,de)=>O||(me(r)?u[de].label:""),"")||u[0].label}const T=u.map(I=>({label:I.label,value:I.label})),j=I=>{d(I),o(()=>e.onChange({type:"change",value:c.current()||""}))},w=y.useCallback(I=>{e.onChange({type:"change",value:I})},[]),D=()=>{const I=c.current()||"",O=h.getCurrencyType(I);O&&C(O),e.onChange({type:"confirm",value:I})},k=()=>{e.onChange({type:"cancel",value:""})},q={onChange:w,defaultValue:t,defaultPattern:r,action:c};return y.useEffect(()=>{d(b()),S(`${n}_${i}`)},[n,i]),l.jsxs("div",{className:N.clsx("univer-flex univer-h-full univer-flex-col univer-justify-between univer-overflow-y-auto univer-pb-5",N.scrollbarClassName),children:[l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-3.5 univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.numfmtType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(N.Select,{className:"univer-w-full",value:v,options:T,onChange:j})}),l.jsx("div",{children:x&&l.jsx(J.Provider,{value:f,children:y.createElement(x,{...q,key:p})})})]}),l.jsxs("div",{className:"univer-mb-5 univer-mt-3.5 univer-flex univer-justify-end",children:[l.jsx(N.Button,{onClick:k,className:"univer-mr-3",children:m("sheet.numfmt.cancel")}),l.jsx(N.Button,{variant:"primary",onClick:D,children:m("sheet.numfmt.confirm")})]})]})};var He=Object.getOwnPropertyDescriptor,Ae=(e,t,r,n)=>{for(var i=n>1?void 0:n?He(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=c(i)||i);return i},M=(e,t)=>(r,n)=>t(r,n,e);const te="SHEET_NUMFMT_PANEL";let H=class extends a.Disposable{constructor(t,r,n,i,s,c,m,o,u,v,d){super();A(this,"_previewPattern","");A(this,"_sidebarDisposable",null);this._sheetInterceptorService=t,this._themeService=r,this._univerInstanceService=n,this._commandService=i,this._selectionManagerService=s,this._renderManagerService=c,this._numfmtService=m,this._componentManager=o,this._sidebarService=u,this._localeService=v,this._sheetsNumfmtCellContentController=d,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener(),this._initNumfmtLocalChange()}_initNumfmtLocalChange(){this.disposeWithMe(R.merge(this._sheetsNumfmtCellContentController.locale$,this._localeService.currentLocale$).subscribe(()=>{this._forceUpdate()}))}openPanel(){var x;const t=this._sidebarService,r=this._selectionManagerService,n=this._commandService,i=this._univerInstanceService,s=this._numfmtService,c=this._localeService,o=(((x=r.getCurrentSelections())==null?void 0:x.map(b=>b.range))||[])[0];if(!o)return!1;const u=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),v=u.getActiveSheet();if(!v)return!1;const d=v.getCellRaw(o.startRow,o.startColumn),p=s.getValue(u.getUnitId(),v.getSheetId(),o.startRow,o.startColumn);let S="";p&&(S=p.pattern);const C=(d==null?void 0:d.t)===a.CellValueType.NUMBER?d.v:12345678,f={onChange:b=>{var T;if(b.type==="change")this._previewPattern=b.value,this._forceUpdate();else if(b.type==="confirm"){const j=((T=r.getCurrentSelections())==null?void 0:T.map(k=>k.range))||[],w={values:[]},D=h.getPatternType(b.value);j.forEach(k=>{a.Range.foreach(k,(q,I)=>{w.values.push({row:q,col:I,pattern:b.value,type:D})})}),n.executeCommand(h.SetNumfmtCommand.id,w),t.close()}else b.type==="cancel"&&t.close()},value:{defaultPattern:S,defaultValue:C,row:o.startRow,col:o.startColumn}};return this._sidebarDisposable=t.open({header:{title:c.t("sheet.numfmt.title")},children:{label:te,...f},onClose:()=>{this._forceUpdate(),n.executeCommand(K.id)}}),!0}_forceUpdate(t){var n;const r=this._renderManagerService.getRenderById(t!=null?t:this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId());r==null||r.with(P.SheetSkeletonManagerService).reCalculate(),(n=r==null?void 0:r.mainComponent)==null||n.makeDirty()}_initCommands(){[L,K].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initPanel(){this.disposeWithMe(this._componentManager.register(te,Fe))}_initRealTimeRenderingInterceptor(){const t=new R.Observable(n=>{this._commandService.onCommandExecuted(i=>{i.id===L.id&&n.next(!0),i.id===K.id&&n.next(!1)})}),r=R.combineLatest([t,this._selectionManagerService.selectionMoveEnd$.pipe(W.map(n=>n?n.map(i=>i.range):[]))]);this.disposeWithMe(a.toDisposable(r.pipe(W.switchMap(([n,i])=>new R.Observable(s=>{const c=new a.DisposableCollection;return n&&i.length&&s.next({selectionRanges:i,disposableCollection:c}),()=>{c.dispose()}})),W.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:n,selectionRanges:i})=>{var c,m;const s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);this.openPanel(),n.add(this._sheetInterceptorService.intercept(g.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,effect:a.InterceptorEffectEnum.Value|a.InterceptorEffectEnum.Style,handler:(o,u,v)=>{var C;const{row:d,col:p}=u,S=v(o)||{};if(i.find(f=>f.startColumn<=p&&f.endColumn>=p&&f.startRow<=d&&f.endRow>=d)){const f=u.worksheet.getCellRaw(d,p),x=f==null?void 0:f.v,b=f==null?void 0:f.t;if(x==null||b!==a.CellValueType.NUMBER||this._previewPattern===null)return S;const T=h.getPatternPreviewIgnoreGeneral(this._previewPattern,x,this._sheetsNumfmtCellContentController.locale);if(T.color){const j=(C=this._themeService.getColorFromTheme(`${T.color}.500`))!=null?C:T.color;return{...S,v:T.result,t:a.CellValueType.STRING,s:{cl:{rgb:j}}}}return{...S,v:T.result,t:a.CellValueType.STRING}}return S}})),(m=(c=this._renderManagerService.getRenderById(s.getUnitId()))==null?void 0:c.mainComponent)==null||m.makeDirty()})))}_commandExecutedListener(){const t=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id];this.disposeWithMe(new R.Observable(r=>{const n=this._commandService.onCommandExecuted(i=>{if(t.includes(i.id)){const s=i.params;r.next(s.unitId)}});return()=>n.dispose()}).pipe(W.debounceTime(16)).subscribe(r=>this._forceUpdate(r)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(t=>{var r;t||((r=this._sidebarDisposable)==null||r.dispose(),this._sidebarDisposable=null)})}};H=Ae([M(0,a.Inject(g.SheetInterceptorService)),M(1,a.Inject(a.ThemeService)),M(2,a.IUniverInstanceService),M(3,a.ICommandService),M(4,a.Inject(g.SheetsSelectionsService)),M(5,re.IRenderManagerService),M(6,g.INumfmtService),M(7,a.Inject(_.ComponentManager)),M(8,_.ISidebarService),M(9,a.Inject(a.LocaleService)),M(10,a.Inject(h.SheetsNumfmtCellContentController))],H);var We=Object.getOwnPropertyDescriptor,Be=(e,t,r,n)=>{for(var i=n>1?void 0:n?We(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=c(i)||i);return i},$=(e,t)=>(r,n)=>t(r,n,e);const Ve=()=>{let e=[];return{add:(i,s,c,m,o)=>e.push({unitId:i,subUnitId:s,row:c,col:m,value:o}),getEffects:()=>e,clean:()=>{e=[]}}};let B=class extends a.Disposable{constructor(t,r,n,i,s){super();A(this,"_collectEffectMutation",Ve());this._sheetInterceptorService=t,this._numfmtService=r,this._univerInstanceService=n,this._injector=i,this._editorBridgeService=s,this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(a.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.BEFORE_CELL_EDIT,{handler:(t,r,n)=>{const i=r.row,s=r.col,c=this._numfmtService.getValue(r.unitId,r.subUnitId,i,s);if(c)switch(h.getPatternType(c.pattern)){case"scientific":case"currency":case"grouped":case"number":{const o=r.worksheet.getCellRaw(i,s);return(o==null?void 0:o.t)===a.CellValueType.NUMBER&&(o==null?void 0:o.v)!==void 0&&o.v!==null&&a.isRealNum(o.v)&&(o.v=fe.stripErrorMargin(Number(o.v))),n&&n(o)}case"percent":case"date":case"time":case"datetime":default:return n&&n(t)}return n(t)}})))}_initInterceptorEditorEnd(){this.disposeWithMe(a.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.AFTER_CELL_EDIT,{handler:(t,r,n)=>{var u,v,d;if(!(t!=null&&t.v)&&!(t!=null&&t.p))return n(t);this._collectEffectMutation.clean();const i=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col),s=r.worksheet.getCellRaw(r.row,r.col);if(a.isTextFormat(i==null?void 0:i.pattern)||t.t===a.CellValueType.FORCE_STRING)return n(t);const c=(u=t.p)==null?void 0:u.body,m=(d=(v=t==null?void 0:t.p)==null?void 0:v.body)!=null&&d.dataStream?t.p.body.dataStream.replace(/\r\n$/,""):String(t.v),o=a.getNumfmtParseValueFilter(m);if(c)if(qe(c)){const{dataStream:p}=c,S=p.replace(/\r\n$/,""),C=Number(S);if(Number.isNaN(C)&&!o)return n(t)}else return n(t);if(o){if(!o.z&&!(i!=null&&i.pattern)&&(s==null?void 0:s.t)!==a.CellValueType.STRING&&(s==null?void 0:s.t)!==a.CellValueType.FORCE_STRING&&a.willLoseNumericPrecision(m))return n({...t,p:void 0,v:m,t:a.CellValueType.FORCE_STRING});o.z&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:o.z});const p=Number(o.v);return n({...t,p:void 0,v:p,t:a.CellValueType.NUMBER})}return n(t)}})))}_initInterceptorCommands(){const t=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(r){var n;switch(r.id){case g.SetRangeValuesCommand.id:{const i=t._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=i.getUnitId(),c=(n=i.getActiveSheet())==null?void 0:n.getSheetId();if(!c)return{redos:[],undos:[]};const m=t._collectEffectMutation.getEffects();if(t._collectEffectMutation.clean(),!m.length)return{redos:[],undos:[]};const o=m.filter(p=>{var S;return!!((S=p.value)!=null&&S.pattern)}).map(p=>({row:p.row,col:p.col,pattern:p.value.pattern})),u=m.filter(p=>{var S;return!((S=p.value)!=null&&S.pattern)}).map(p=>({startRow:p.row,endColumn:p.col,startColumn:p.col,endRow:p.row})),v=[],d=[];if(o.length){const p={id:g.SetNumfmtMutation.id,params:g.transformCellsToRange(s,c,o)};v.push(p),d.push(...g.factorySetNumfmtUndoMutation(t._injector,p.params))}if(u.length){const p={id:g.RemoveNumfmtMutation.id,params:{unitId:s,subUnitId:c,ranges:u}};v.push(p),d.push(...g.factoryRemoveNumfmtUndoMutation(t._injector,p.params))}return{redos:v,undos:d.reverse()}}}return{redos:[],undos:[]}}}))}};B=Be([$(0,a.Inject(g.SheetInterceptorService)),$(1,a.Inject(g.INumfmtService)),$(2,a.Inject(a.IUniverInstanceService)),$(3,a.Inject(a.Injector)),$(4,a.Optional(P.IEditorBridgeService))],B);function qe(e){const{textRuns:t=[],paragraphs:r=[],customRanges:n,customBlocks:i=[]}=e,s=["va"];return!(t.some(c=>!!(c.ts&&Object.keys(c.ts).some(o=>s.includes(o))))||r.some(c=>c.bullet)||r.length>=2||n!=null&&n.length||i.length>0)}const ce=e=>[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:a.DEFAULT_TEXT_FORMAT_EXCEL},"|",{label:"sheet.numfmt.number",pattern:"0"},{label:"sheet.numfmt.percent",pattern:"0.00%"},{label:"sheet.numfmt.scientific",pattern:"0.00E+00"},"|",{label:"sheet.numfmt.accounting",pattern:`"${e}" #,##0.00_);[Red]("${e}"#,##0.00)`},{label:"sheet.numfmt.financialValue",pattern:"#,##0.00;[Red]#,##0.00"},{label:"sheet.numfmt.currency",pattern:`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`},{label:"sheet.numfmt.roundingCurrency",pattern:`"${e}"#,##0;[Red]"${e}"#,##0`},"|",{label:"sheet.numfmt.date",pattern:"yyyy-mm-dd;@"},{label:"sheet.numfmt.time",pattern:'am/pm h":"mm":"ss'},{label:"sheet.numfmt.dateTime",pattern:"yyyy-m-d am/pm h:mm"},{label:"sheet.numfmt.timeDuration",pattern:"h:mm:ss"},"|",{label:"sheet.numfmt.moreFmt",pattern:""}],Ge=e=>({icon:new R.Observable(t=>{const r=e.get(a.LocaleService);return t.next(h.getCurrencySymbolIconByLocale(r.getCurrentLocale()).icon),r.localeChanged$.subscribe(()=>{t.next(h.getCurrencySymbolIconByLocale(r.getCurrentLocale()).icon)})}),id:h.SetCurrencyCommand.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:P.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Ke=e=>({icon:"AddDigitsIcon",id:h.AddDecimalCommand.id,title:"sheet.numfmt.addDecimal",tooltip:"sheet.numfmt.addDecimal",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:P.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Ze=e=>({icon:"ReduceDigitsIcon",id:h.SubtractDecimalCommand.id,title:"sheet.numfmt.subtractDecimal",tooltip:"sheet.numfmt.subtractDecimal",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:P.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Ye=e=>({icon:"PercentIcon",id:h.SetPercentCommand.id,title:"sheet.numfmt.percent",tooltip:"sheet.numfmt.percent",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:P.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),ze=e=>{const t=e.get(a.IUniverInstanceService),r=e.get(a.ICommandService),n=e.get(a.LocaleService),i=e.get(g.SheetsSelectionsService),s=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id],c=P.deriveStateFromActiveSheet$(t,"",({workbook:m,worksheet:o})=>new R.Observable(u=>R.merge(i.selectionMoveEnd$,a.fromCallback(r.onCommandExecuted.bind(r)).pipe(R.filter(([v])=>s.includes(v.id)))).subscribe(()=>{var d,p;const v=i.getCurrentSelections();if(v&&v[0]){const S=v[0].range,C=S.startRow,f=S.startColumn,x=(p=m.getStyles().get((d=o.getCell(C,f))==null?void 0:d.s))==null?void 0:p.n,b=x==null?void 0:x.pattern,T=h.getCurrencySymbolByLocale(n.getCurrentLocale());let j=n.t("sheet.numfmt.general");if(a.isDefaultFormat(b)){u.next(j);return}if(b){const w=ce(T).filter(D=>typeof D=="object"&&D.pattern).find(D=>a.isPatternEqualWithoutDecimal(b,D.pattern));w&&typeof w=="object"&&w.pattern?j=n.t(w.label):j=n.t("sheet.numfmt.moreFmt")}u.next(j)}})));return{label:oe,id:L.id,tooltip:"sheet.numfmt.title",type:_.MenuItemType.SELECTOR,slot:!0,selections:[{label:{name:le,hoverable:!1,selectable:!1}}],value$:c,hidden$:_.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:P.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetSetCellStylePermission,g.WorksheetEditPermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}},oe="sheet.numfmt.moreNumfmtType",le="sheet.numfmt.moreNumfmtType.options",Xe=e=>{const{value:t}=e,r=_.useDependency(a.LocaleService),n=t!=null?t:r.t("sheet.numfmt.general");return l.jsx("span",{className:"univer-text-sm",children:n})},Je=()=>{const e=_.useDependency(a.ICommandService),t=_.useDependency(a.LocaleService),r=_.useDependency(_.ILayoutService),n=_.useDependency(h.SheetsNumfmtCellContentController),i=_.useDependency(g.SheetsSelectionsService),s=u=>{const v=i.getCurrentLastSelection();if(!v)return;const d=v.range,p=[];a.Range.foreach(d,(S,C)=>{u?p.push({row:S,col:C,pattern:u,type:h.getPatternType(u)}):p.push({row:S,col:C})}),e.executeCommand(h.SetNumfmtCommand.id,{values:p}),r.focus()},c=y.useMemo(()=>{const u=h.localeCurrencySymbolMap.get(t.getCurrentLocale());return ce(u)},[t]),m=u=>{if(u===0)s(null);else if(u===c.length-1)e.executeCommand(L.id),r.focus();else{const v=c[u];v.pattern&&s(v.pattern)}},o=1220;return l.jsx("div",{className:"univer-grid univer-gap-1 univer-p-1.5",children:c.map((u,v)=>u==="|"?l.jsx(N.Separator,{},v):l.jsxs("div",{className:"univer-flex univer-h-7 univer-items-center univer-justify-between univer-gap-6 univer-rounded univer-px-2 univer-text-sm hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",onClick:()=>{m(v)},children:[l.jsx("span",{children:t.t(u.label)}),l.jsx("span",{className:"univer-text-xs univer-text-gray-500",children:u.pattern?h.getPatternPreview(u.pattern||"",o,n.locale).result.trim():""})]},v))})},Qe={[_.RibbonDataGroup.FORMULAS]:{[h.SetCurrencyCommand.id]:{order:0,menuItemFactory:Ge},[h.AddDecimalCommand.id]:{order:1,menuItemFactory:Ke},[h.SubtractDecimalCommand.id]:{order:2,menuItemFactory:Ze},[h.SetPercentCommand.id]:{order:3,menuItemFactory:Ye},[L.id]:{order:4,menuItemFactory:ze}}};var et=Object.getOwnPropertyDescriptor,tt=(e,t,r,n)=>{for(var i=n>1?void 0:n?et(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=c(i)||i);return i},ne=(e,t)=>(r,n)=>t(r,n,e);let V=class extends a.Disposable{constructor(e,t){super(),this._componentManager=e,this._menuManagerService=t,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(Qe),[[oe,Xe],[le,Je]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};V=tt([ne(0,a.Inject(_.ComponentManager)),ne(1,_.IMenuManagerService)],V);var nt=Object.defineProperty,rt=Object.getOwnPropertyDescriptor,it=(e,t,r)=>t in e?nt(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,st=(e,t,r,n)=>{for(var i=n>1?void 0:n?rt(t,r):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(i=c(i)||i);return i},z=(e,t)=>(r,n)=>t(r,n,e),ue=(e,t,r)=>it(e,typeof t!="symbol"?t+"":t,r);const at="SHEET_NUMFMT_UI_PLUGIN";exports.UniverSheetsNumfmtUIPlugin=class extends a.Plugin{constructor(t=Q,r,n,i){super(),this._config=t,this._injector=r,this._configService=n,this._renderManagerService=i;const{menu:s,...c}=a.merge({},Q,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig("sheets-numfmt-ui.config",c)}onStarting(){a.registerDependencies(this._injector,[[H],[B],[F],[V]])}onRendered(){this._registerRenderModules(),a.touchDependencies(this._injector,[[H],[B],[V]])}_registerRenderModules(){[[X]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,r))})}};ue(exports.UniverSheetsNumfmtUIPlugin,"pluginName",at);ue(exports.UniverSheetsNumfmtUIPlugin,"type",a.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtUIPlugin=st([a.DependentOn(P.UniverSheetsUIPlugin,h.UniverSheetsNumfmtPlugin),z(1,a.Inject(a.Injector)),z(2,a.IConfigService),z(3,re.IRenderManagerService)],exports.UniverSheetsNumfmtUIPlugin);
|
package/lib/es/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
var dt = Object.defineProperty;
|
|
2
2
|
var ht = (e, t, r) => t in e ? dt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
3
|
var q = (e, t, r) => ht(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
-
import { Inject as y, LocaleService as E, IConfigService as $e, Disposable as ne, isTextFormat as De, Tools as vt, isRealNum as Fe, CommandType as Le, ILocalStorageService as Ae, isPatternEqualWithoutDecimal as re, numfmt as ft, ThemeService as pt, IUniverInstanceService as ve, ICommandService as fe, UniverInstanceType as w, CellValueType as x, toDisposable as de, DisposableCollection as gt, InterceptorEffectEnum as we, Range as He, Injector as je, Optional as _t,
|
|
4
|
+
import { Inject as y, LocaleService as E, IConfigService as $e, Disposable as ne, isTextFormat as De, Tools as vt, isRealNum as Fe, CommandType as Le, ILocalStorageService as Ae, isPatternEqualWithoutDecimal as re, numfmt as ft, ThemeService as pt, IUniverInstanceService as ve, ICommandService as fe, UniverInstanceType as w, CellValueType as x, toDisposable as de, DisposableCollection as gt, InterceptorEffectEnum as we, Range as He, Injector as je, Optional as _t, getNumfmtParseValueFilter as St, willLoseNumericPrecision as yt, fromCallback as Ct, isDefaultFormat as bt, DEFAULT_TEXT_FORMAT_EXCEL as It, DependentOn as Nt, Plugin as Et, merge as Tt, registerDependencies as wt, touchDependencies as Mt } from "@univerjs/core";
|
|
5
5
|
import { IRenderManagerService as Be } from "@univerjs/engine-render";
|
|
6
|
-
import { SHEETS_NUMFMT_PLUGIN_CONFIG_KEY as
|
|
6
|
+
import { SHEETS_NUMFMT_PLUGIN_CONFIG_KEY as Pt, currencySymbols as Me, getDecimalFromPattern as J, getCurrencyType as V, setPatternDecimal as k, getCurrencyFormatOptions as oe, CURRENCYFORMAT as xt, DATEFMTLISG as Rt, NUMBERFORMAT as Ot, getDateFormatOptions as Ve, getNumberFormatOptions as We, isPatternHasDecimal as kt, SheetsNumfmtCellContentController as Ge, getPatternPreviewIgnoreGeneral as Ut, getPatternType as pe, SetNumfmtCommand as Ke, getCurrencySymbolByLocale as $t, SetPercentCommand as Ze, SubtractDecimalCommand as Ye, AddDecimalCommand as ze, SetCurrencyCommand as Xe, getCurrencySymbolIconByLocale as Pe, localeCurrencySymbolMap as Dt, getPatternPreview as Ft, UniverSheetsNumfmtPlugin as Lt } from "@univerjs/sheets-numfmt";
|
|
7
7
|
import { HoverManagerService as At, CellAlertManagerService as Ht, CellAlertType as jt, SheetSkeletonManagerService as Bt, IEditorBridgeService as Vt, deriveStateFromActiveSheet$ as Wt, getCurrentRangeDisable$ as W, UniverSheetsUIPlugin as Gt } from "@univerjs/sheets-ui";
|
|
8
8
|
import { INumfmtService as ge, SheetInterceptorService as qe, SheetsSelectionsService as _e, INTERCEPTOR_POINT as Kt, RemoveNumfmtMutation as Se, SetNumfmtMutation as ye, BEFORE_CELL_EDIT as Zt, AFTER_CELL_EDIT as Yt, SetRangeValuesCommand as zt, transformCellsToRange as Xt, factorySetNumfmtUndoMutation as qt, factoryRemoveNumfmtUndoMutation as Jt, RangeProtectionPermissionEditPoint as G, WorksheetSetCellStylePermission as K, WorksheetEditPermission as Z, WorkbookEditablePermission as Y } from "@univerjs/sheets";
|
|
9
9
|
import { IZenZoneService as Qt, useDependency as b, ComponentManager as Je, ISidebarService as en, getMenuHiddenObservable as z, MenuItemType as X, ILayoutService as tn, RibbonDataGroup as nn, IMenuManagerService as rn } from "@univerjs/ui";
|
|
@@ -45,7 +45,7 @@ let he = class extends ne {
|
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
47
|
if (De(a.pattern) && vt.isDefine(c == null ? void 0 : c.v) && Fe(c.v)) {
|
|
48
|
-
if ((t = this._configService.getConfig(
|
|
48
|
+
if ((t = this._configService.getConfig(Pt)) != null && t.disableTextFormatAlert)
|
|
49
49
|
return;
|
|
50
50
|
const m = this._cellAlertManagerService.currentAlert.get(ae), u = (r = m == null ? void 0 : m.alert) == null ? void 0 : r.location;
|
|
51
51
|
if (u && u.row === n.row && u.col === n.col && u.subUnitId === n.subUnitId && u.unitId === n.unitId)
|
|
@@ -320,9 +320,9 @@ function $n(e) {
|
|
|
320
320
|
ie(() => {
|
|
321
321
|
s.getItem(ue).then((f) => {
|
|
322
322
|
const p = [
|
|
323
|
-
...
|
|
324
|
-
...
|
|
325
|
-
...
|
|
323
|
+
...xt.map((d) => d.suffix("$")),
|
|
324
|
+
...Rt.map((d) => d.suffix),
|
|
325
|
+
...Ot.map((d) => d.suffix)
|
|
326
326
|
];
|
|
327
327
|
p.push(...f || []), i.addHabit(le, []).finally(() => {
|
|
328
328
|
i.getHabit(le, p).then((d) => {
|
|
@@ -418,7 +418,7 @@ function jn(e) {
|
|
|
418
418
|
const t = b(E), r = R(We, []), [n, i] = N(() => J(e.defaultPattern || "", 0)), [s, o] = N(() => {
|
|
419
419
|
const u = r.find((v) => re(v.value, e.defaultPattern || ""));
|
|
420
420
|
return (u == null ? void 0 : u.value) || r[0].value;
|
|
421
|
-
}), l = R(() => k(s, Number(n || 0)), [s, n]), a = R(() => !
|
|
421
|
+
}), l = R(() => k(s, Number(n || 0)), [s, n]), a = R(() => !kt(s), [s]), c = (u) => {
|
|
422
422
|
i(u || 0), e.onChange(k(s, Number(u || 0)));
|
|
423
423
|
}, m = (u) => {
|
|
424
424
|
u !== void 0 && (i(J(u, 0)), o(u), e.onChange(u));
|
|
@@ -640,7 +640,7 @@ let B = class extends ne {
|
|
|
640
640
|
const d = c.worksheet.getCellRaw(u, v), S = d == null ? void 0 : d.v, g = d == null ? void 0 : d.t;
|
|
641
641
|
if (S == null || g !== x.NUMBER || this._previewPattern === null)
|
|
642
642
|
return f;
|
|
643
|
-
const I =
|
|
643
|
+
const I = Ut(this._previewPattern, S, this._sheetsNumfmtCellContentController.locale);
|
|
644
644
|
if (I.color) {
|
|
645
645
|
const P = (p = this._themeService.getColorFromTheme(`${I.color}.500`)) != null ? p : I.color;
|
|
646
646
|
return {
|
|
@@ -777,7 +777,7 @@ let Q = class extends ne {
|
|
|
777
777
|
), s = r.worksheet.getCellRaw(r.row, r.col);
|
|
778
778
|
if (De(i == null ? void 0 : i.pattern) || t.t === x.FORCE_STRING)
|
|
779
779
|
return n(t);
|
|
780
|
-
const o = (c = t.p) == null ? void 0 : c.body, l = (u = (m = t == null ? void 0 : t.p) == null ? void 0 : m.body) != null && u.dataStream ? t.p.body.dataStream.replace(/\r\n$/, "") : String(t.v), a =
|
|
780
|
+
const o = (c = t.p) == null ? void 0 : c.body, l = (u = (m = t == null ? void 0 : t.p) == null ? void 0 : m.body) != null && u.dataStream ? t.p.body.dataStream.replace(/\r\n$/, "") : String(t.v), a = St(l);
|
|
781
781
|
if (o)
|
|
782
782
|
if (Yn(o)) {
|
|
783
783
|
const { dataStream: v } = o, f = v.replace(/\r\n$/, ""), p = Number(f);
|
|
@@ -786,7 +786,7 @@ let Q = class extends ne {
|
|
|
786
786
|
} else
|
|
787
787
|
return n(t);
|
|
788
788
|
if (a) {
|
|
789
|
-
if (!a.z && !(i != null && i.pattern) && (s == null ? void 0 : s.t) !== x.STRING && (s == null ? void 0 : s.t) !== x.FORCE_STRING &&
|
|
789
|
+
if (!a.z && !(i != null && i.pattern) && (s == null ? void 0 : s.t) !== x.STRING && (s == null ? void 0 : s.t) !== x.FORCE_STRING && yt(l))
|
|
790
790
|
return n({
|
|
791
791
|
...t,
|
|
792
792
|
p: void 0,
|
|
@@ -898,7 +898,7 @@ const ot = (e) => [
|
|
|
898
898
|
},
|
|
899
899
|
{
|
|
900
900
|
label: "sheet.numfmt.text",
|
|
901
|
-
pattern:
|
|
901
|
+
pattern: It
|
|
902
902
|
},
|
|
903
903
|
"|",
|
|
904
904
|
{
|
|
@@ -996,7 +996,7 @@ const ot = (e) => [
|
|
|
996
996
|
({ workbook: l, worksheet: a }) => new A(
|
|
997
997
|
(c) => Qe(
|
|
998
998
|
i.selectionMoveEnd$,
|
|
999
|
-
|
|
999
|
+
Ct(r.onCommandExecuted.bind(r)).pipe(
|
|
1000
1000
|
an(([m]) => s.includes(m.id))
|
|
1001
1001
|
)
|
|
1002
1002
|
).subscribe(() => {
|
|
@@ -1005,7 +1005,7 @@ const ot = (e) => [
|
|
|
1005
1005
|
if (m && m[0]) {
|
|
1006
1006
|
const f = m[0].range, p = f.startRow, d = f.startColumn, S = (v = l.getStyles().get((u = a.getCell(p, d)) == null ? void 0 : u.s)) == null ? void 0 : v.n, g = S == null ? void 0 : S.pattern, I = $t(n.getCurrentLocale());
|
|
1007
1007
|
let P = n.t("sheet.numfmt.general");
|
|
1008
|
-
if (
|
|
1008
|
+
if (bt(g)) {
|
|
1009
1009
|
c.next(P);
|
|
1010
1010
|
return;
|
|
1011
1011
|
}
|
|
@@ -1132,10 +1132,10 @@ var sr = Object.defineProperty, or = Object.getOwnPropertyDescriptor, ar = (e, t
|
|
|
1132
1132
|
return i;
|
|
1133
1133
|
}, me = (e, t) => (r, n) => t(r, n, e), lt = (e, t, r) => ar(e, typeof t != "symbol" ? t + "" : t, r);
|
|
1134
1134
|
const lr = "SHEET_NUMFMT_UI_PLUGIN";
|
|
1135
|
-
let te = class extends
|
|
1135
|
+
let te = class extends Et {
|
|
1136
1136
|
constructor(e = Re, t, r, n) {
|
|
1137
1137
|
super(), this._config = e, this._injector = t, this._configService = r, this._renderManagerService = n;
|
|
1138
|
-
const { menu: i, ...s } =
|
|
1138
|
+
const { menu: i, ...s } = Tt(
|
|
1139
1139
|
{},
|
|
1140
1140
|
Re,
|
|
1141
1141
|
this._config
|
|
@@ -1143,7 +1143,7 @@ let te = class extends Nt {
|
|
|
1143
1143
|
i && this._configService.setConfig("menu", i, { merge: !0 }), this._configService.setConfig("sheets-numfmt-ui.config", s);
|
|
1144
1144
|
}
|
|
1145
1145
|
onStarting() {
|
|
1146
|
-
|
|
1146
|
+
wt(this._injector, [
|
|
1147
1147
|
[B],
|
|
1148
1148
|
[Q],
|
|
1149
1149
|
[j],
|
|
@@ -1151,7 +1151,7 @@ let te = class extends Nt {
|
|
|
1151
1151
|
]);
|
|
1152
1152
|
}
|
|
1153
1153
|
onRendered() {
|
|
1154
|
-
this._registerRenderModules(),
|
|
1154
|
+
this._registerRenderModules(), Mt(this._injector, [
|
|
1155
1155
|
[B],
|
|
1156
1156
|
[Q],
|
|
1157
1157
|
[ee]
|
|
@@ -1168,7 +1168,7 @@ let te = class extends Nt {
|
|
|
1168
1168
|
lt(te, "pluginName", lr);
|
|
1169
1169
|
lt(te, "type", w.UNIVER_SHEET);
|
|
1170
1170
|
te = cr([
|
|
1171
|
-
|
|
1171
|
+
Nt(Gt, Lt),
|
|
1172
1172
|
me(1, y(je)),
|
|
1173
1173
|
me(2, $e),
|
|
1174
1174
|
me(3, Be)
|
package/lib/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
var dt = Object.defineProperty;
|
|
2
2
|
var ht = (e, t, r) => t in e ? dt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
3
|
var q = (e, t, r) => ht(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
-
import { Inject as y, LocaleService as E, IConfigService as $e, Disposable as ne, isTextFormat as De, Tools as vt, isRealNum as Fe, CommandType as Le, ILocalStorageService as Ae, isPatternEqualWithoutDecimal as re, numfmt as ft, ThemeService as pt, IUniverInstanceService as ve, ICommandService as fe, UniverInstanceType as w, CellValueType as x, toDisposable as de, DisposableCollection as gt, InterceptorEffectEnum as we, Range as He, Injector as je, Optional as _t,
|
|
4
|
+
import { Inject as y, LocaleService as E, IConfigService as $e, Disposable as ne, isTextFormat as De, Tools as vt, isRealNum as Fe, CommandType as Le, ILocalStorageService as Ae, isPatternEqualWithoutDecimal as re, numfmt as ft, ThemeService as pt, IUniverInstanceService as ve, ICommandService as fe, UniverInstanceType as w, CellValueType as x, toDisposable as de, DisposableCollection as gt, InterceptorEffectEnum as we, Range as He, Injector as je, Optional as _t, getNumfmtParseValueFilter as St, willLoseNumericPrecision as yt, fromCallback as Ct, isDefaultFormat as bt, DEFAULT_TEXT_FORMAT_EXCEL as It, DependentOn as Nt, Plugin as Et, merge as Tt, registerDependencies as wt, touchDependencies as Mt } from "@univerjs/core";
|
|
5
5
|
import { IRenderManagerService as Be } from "@univerjs/engine-render";
|
|
6
|
-
import { SHEETS_NUMFMT_PLUGIN_CONFIG_KEY as
|
|
6
|
+
import { SHEETS_NUMFMT_PLUGIN_CONFIG_KEY as Pt, currencySymbols as Me, getDecimalFromPattern as J, getCurrencyType as V, setPatternDecimal as k, getCurrencyFormatOptions as oe, CURRENCYFORMAT as xt, DATEFMTLISG as Rt, NUMBERFORMAT as Ot, getDateFormatOptions as Ve, getNumberFormatOptions as We, isPatternHasDecimal as kt, SheetsNumfmtCellContentController as Ge, getPatternPreviewIgnoreGeneral as Ut, getPatternType as pe, SetNumfmtCommand as Ke, getCurrencySymbolByLocale as $t, SetPercentCommand as Ze, SubtractDecimalCommand as Ye, AddDecimalCommand as ze, SetCurrencyCommand as Xe, getCurrencySymbolIconByLocale as Pe, localeCurrencySymbolMap as Dt, getPatternPreview as Ft, UniverSheetsNumfmtPlugin as Lt } from "@univerjs/sheets-numfmt";
|
|
7
7
|
import { HoverManagerService as At, CellAlertManagerService as Ht, CellAlertType as jt, SheetSkeletonManagerService as Bt, IEditorBridgeService as Vt, deriveStateFromActiveSheet$ as Wt, getCurrentRangeDisable$ as W, UniverSheetsUIPlugin as Gt } from "@univerjs/sheets-ui";
|
|
8
8
|
import { INumfmtService as ge, SheetInterceptorService as qe, SheetsSelectionsService as _e, INTERCEPTOR_POINT as Kt, RemoveNumfmtMutation as Se, SetNumfmtMutation as ye, BEFORE_CELL_EDIT as Zt, AFTER_CELL_EDIT as Yt, SetRangeValuesCommand as zt, transformCellsToRange as Xt, factorySetNumfmtUndoMutation as qt, factoryRemoveNumfmtUndoMutation as Jt, RangeProtectionPermissionEditPoint as G, WorksheetSetCellStylePermission as K, WorksheetEditPermission as Z, WorkbookEditablePermission as Y } from "@univerjs/sheets";
|
|
9
9
|
import { IZenZoneService as Qt, useDependency as b, ComponentManager as Je, ISidebarService as en, getMenuHiddenObservable as z, MenuItemType as X, ILayoutService as tn, RibbonDataGroup as nn, IMenuManagerService as rn } from "@univerjs/ui";
|
|
@@ -45,7 +45,7 @@ let he = class extends ne {
|
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
47
|
if (De(a.pattern) && vt.isDefine(c == null ? void 0 : c.v) && Fe(c.v)) {
|
|
48
|
-
if ((t = this._configService.getConfig(
|
|
48
|
+
if ((t = this._configService.getConfig(Pt)) != null && t.disableTextFormatAlert)
|
|
49
49
|
return;
|
|
50
50
|
const m = this._cellAlertManagerService.currentAlert.get(ae), u = (r = m == null ? void 0 : m.alert) == null ? void 0 : r.location;
|
|
51
51
|
if (u && u.row === n.row && u.col === n.col && u.subUnitId === n.subUnitId && u.unitId === n.unitId)
|
|
@@ -320,9 +320,9 @@ function $n(e) {
|
|
|
320
320
|
ie(() => {
|
|
321
321
|
s.getItem(ue).then((f) => {
|
|
322
322
|
const p = [
|
|
323
|
-
...
|
|
324
|
-
...
|
|
325
|
-
...
|
|
323
|
+
...xt.map((d) => d.suffix("$")),
|
|
324
|
+
...Rt.map((d) => d.suffix),
|
|
325
|
+
...Ot.map((d) => d.suffix)
|
|
326
326
|
];
|
|
327
327
|
p.push(...f || []), i.addHabit(le, []).finally(() => {
|
|
328
328
|
i.getHabit(le, p).then((d) => {
|
|
@@ -418,7 +418,7 @@ function jn(e) {
|
|
|
418
418
|
const t = b(E), r = R(We, []), [n, i] = N(() => J(e.defaultPattern || "", 0)), [s, o] = N(() => {
|
|
419
419
|
const u = r.find((v) => re(v.value, e.defaultPattern || ""));
|
|
420
420
|
return (u == null ? void 0 : u.value) || r[0].value;
|
|
421
|
-
}), l = R(() => k(s, Number(n || 0)), [s, n]), a = R(() => !
|
|
421
|
+
}), l = R(() => k(s, Number(n || 0)), [s, n]), a = R(() => !kt(s), [s]), c = (u) => {
|
|
422
422
|
i(u || 0), e.onChange(k(s, Number(u || 0)));
|
|
423
423
|
}, m = (u) => {
|
|
424
424
|
u !== void 0 && (i(J(u, 0)), o(u), e.onChange(u));
|
|
@@ -640,7 +640,7 @@ let B = class extends ne {
|
|
|
640
640
|
const d = c.worksheet.getCellRaw(u, v), S = d == null ? void 0 : d.v, g = d == null ? void 0 : d.t;
|
|
641
641
|
if (S == null || g !== x.NUMBER || this._previewPattern === null)
|
|
642
642
|
return f;
|
|
643
|
-
const I =
|
|
643
|
+
const I = Ut(this._previewPattern, S, this._sheetsNumfmtCellContentController.locale);
|
|
644
644
|
if (I.color) {
|
|
645
645
|
const P = (p = this._themeService.getColorFromTheme(`${I.color}.500`)) != null ? p : I.color;
|
|
646
646
|
return {
|
|
@@ -777,7 +777,7 @@ let Q = class extends ne {
|
|
|
777
777
|
), s = r.worksheet.getCellRaw(r.row, r.col);
|
|
778
778
|
if (De(i == null ? void 0 : i.pattern) || t.t === x.FORCE_STRING)
|
|
779
779
|
return n(t);
|
|
780
|
-
const o = (c = t.p) == null ? void 0 : c.body, l = (u = (m = t == null ? void 0 : t.p) == null ? void 0 : m.body) != null && u.dataStream ? t.p.body.dataStream.replace(/\r\n$/, "") : String(t.v), a =
|
|
780
|
+
const o = (c = t.p) == null ? void 0 : c.body, l = (u = (m = t == null ? void 0 : t.p) == null ? void 0 : m.body) != null && u.dataStream ? t.p.body.dataStream.replace(/\r\n$/, "") : String(t.v), a = St(l);
|
|
781
781
|
if (o)
|
|
782
782
|
if (Yn(o)) {
|
|
783
783
|
const { dataStream: v } = o, f = v.replace(/\r\n$/, ""), p = Number(f);
|
|
@@ -786,7 +786,7 @@ let Q = class extends ne {
|
|
|
786
786
|
} else
|
|
787
787
|
return n(t);
|
|
788
788
|
if (a) {
|
|
789
|
-
if (!a.z && !(i != null && i.pattern) && (s == null ? void 0 : s.t) !== x.STRING && (s == null ? void 0 : s.t) !== x.FORCE_STRING &&
|
|
789
|
+
if (!a.z && !(i != null && i.pattern) && (s == null ? void 0 : s.t) !== x.STRING && (s == null ? void 0 : s.t) !== x.FORCE_STRING && yt(l))
|
|
790
790
|
return n({
|
|
791
791
|
...t,
|
|
792
792
|
p: void 0,
|
|
@@ -898,7 +898,7 @@ const ot = (e) => [
|
|
|
898
898
|
},
|
|
899
899
|
{
|
|
900
900
|
label: "sheet.numfmt.text",
|
|
901
|
-
pattern:
|
|
901
|
+
pattern: It
|
|
902
902
|
},
|
|
903
903
|
"|",
|
|
904
904
|
{
|
|
@@ -996,7 +996,7 @@ const ot = (e) => [
|
|
|
996
996
|
({ workbook: l, worksheet: a }) => new A(
|
|
997
997
|
(c) => Qe(
|
|
998
998
|
i.selectionMoveEnd$,
|
|
999
|
-
|
|
999
|
+
Ct(r.onCommandExecuted.bind(r)).pipe(
|
|
1000
1000
|
an(([m]) => s.includes(m.id))
|
|
1001
1001
|
)
|
|
1002
1002
|
).subscribe(() => {
|
|
@@ -1005,7 +1005,7 @@ const ot = (e) => [
|
|
|
1005
1005
|
if (m && m[0]) {
|
|
1006
1006
|
const f = m[0].range, p = f.startRow, d = f.startColumn, S = (v = l.getStyles().get((u = a.getCell(p, d)) == null ? void 0 : u.s)) == null ? void 0 : v.n, g = S == null ? void 0 : S.pattern, I = $t(n.getCurrentLocale());
|
|
1007
1007
|
let P = n.t("sheet.numfmt.general");
|
|
1008
|
-
if (
|
|
1008
|
+
if (bt(g)) {
|
|
1009
1009
|
c.next(P);
|
|
1010
1010
|
return;
|
|
1011
1011
|
}
|
|
@@ -1132,10 +1132,10 @@ var sr = Object.defineProperty, or = Object.getOwnPropertyDescriptor, ar = (e, t
|
|
|
1132
1132
|
return i;
|
|
1133
1133
|
}, me = (e, t) => (r, n) => t(r, n, e), lt = (e, t, r) => ar(e, typeof t != "symbol" ? t + "" : t, r);
|
|
1134
1134
|
const lr = "SHEET_NUMFMT_UI_PLUGIN";
|
|
1135
|
-
let te = class extends
|
|
1135
|
+
let te = class extends Et {
|
|
1136
1136
|
constructor(e = Re, t, r, n) {
|
|
1137
1137
|
super(), this._config = e, this._injector = t, this._configService = r, this._renderManagerService = n;
|
|
1138
|
-
const { menu: i, ...s } =
|
|
1138
|
+
const { menu: i, ...s } = Tt(
|
|
1139
1139
|
{},
|
|
1140
1140
|
Re,
|
|
1141
1141
|
this._config
|
|
@@ -1143,7 +1143,7 @@ let te = class extends Nt {
|
|
|
1143
1143
|
i && this._configService.setConfig("menu", i, { merge: !0 }), this._configService.setConfig("sheets-numfmt-ui.config", s);
|
|
1144
1144
|
}
|
|
1145
1145
|
onStarting() {
|
|
1146
|
-
|
|
1146
|
+
wt(this._injector, [
|
|
1147
1147
|
[B],
|
|
1148
1148
|
[Q],
|
|
1149
1149
|
[j],
|
|
@@ -1151,7 +1151,7 @@ let te = class extends Nt {
|
|
|
1151
1151
|
]);
|
|
1152
1152
|
}
|
|
1153
1153
|
onRendered() {
|
|
1154
|
-
this._registerRenderModules(),
|
|
1154
|
+
this._registerRenderModules(), Mt(this._injector, [
|
|
1155
1155
|
[B],
|
|
1156
1156
|
[Q],
|
|
1157
1157
|
[ee]
|
|
@@ -1168,7 +1168,7 @@ let te = class extends Nt {
|
|
|
1168
1168
|
lt(te, "pluginName", lr);
|
|
1169
1169
|
lt(te, "type", w.UNIVER_SHEET);
|
|
1170
1170
|
te = cr([
|
|
1171
|
-
|
|
1171
|
+
Nt(Gt, Lt),
|
|
1172
1172
|
me(1, y(je)),
|
|
1173
1173
|
me(2, $e),
|
|
1174
1174
|
me(3, Be)
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(C,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/sheets-numfmt"),require("@univerjs/sheets-ui"),require("@univerjs/sheets"),require("@univerjs/ui"),require("rxjs"),require("rxjs/operators"),require("react/jsx-runtime"),require("react"),require("@univerjs/design"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","@univerjs/sheets-numfmt","@univerjs/sheets-ui","@univerjs/sheets","@univerjs/ui","rxjs","rxjs/operators","react/jsx-runtime","react","@univerjs/design","@univerjs/engine-formula"],a):(C=typeof globalThis<"u"?globalThis:C||self,a(C.UniverSheetsNumfmtUi={},C.UniverCore,C.UniverEngineRender,C.UniverSheetsNumfmt,C.UniverSheetsUi,C.UniverSheets,C.UniverUi,C.rxjs,C.rxjs.operators,C.React,C.React,C.UniverDesign,C.UniverEngineFormula))})(this,(function(C,a,j,m,w,g,_,O,B,l,S,E,me){"use strict";var st=Object.defineProperty;var ot=(C,a,j)=>a in C?st(C,a,{enumerable:!0,configurable:!0,writable:!0,value:j}):C[a]=j;var G=(C,a,j)=>ot(C,typeof a!="symbol"?a+"":a,j);const te={};var ve=Object.getOwnPropertyDescriptor,fe=(e,t,r,n)=>{for(var i=n>1?void 0:n?ve(t,r):t,s=e.length-1,o;s>=0;s--)(o=e[s])&&(i=o(i)||i);return i},$=(e,t)=>(r,n)=>t(r,n,e);const K="SHEET_NUMFMT_ALERT";let Z=class extends a.Disposable{constructor(e,t,r,n,i,s,o){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=r,this._localeService=n,this._zenZoneService=i,this._numfmtService=s,this._configService=o,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(O.debounceTime(100)).subscribe(e=>{var t,r;if(e){const n=e.location,i=this._context.unit,s=i.getActiveSheet();if(!s)return;const o=n.unitId,d=n.subUnitId;let c;const u=s.getCell(n.row,n.col);if(u!=null&&u.s){const f=i.getStyles().get(u.s);f!=null&&f.n&&(c=f.n)}if(c||(c=this._numfmtService.getValue(o,d,n.row,n.col)),!c){this._hideAlert();return}if(a.isTextFormat(c.pattern)&&a.Tools.isDefine(u==null?void 0:u.v)&&a.isRealNum(u.v)){if((t=this._configService.getConfig(m.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY))!=null&&t.disableTextFormatAlert)return;const f=this._cellAlertManagerService.currentAlert.get(K),v=(r=f==null?void 0:f.alert)==null?void 0:r.location;if(v&&v.row===n.row&&v.col===n.col&&v.subUnitId===n.subUnitId&&v.unitId===n.unitId)return;this._cellAlertManagerService.showAlert({type:w.CellAlertType.ERROR,title:this._localeService.t("info.error"),message:this._localeService.t("info.forceStringInfo"),location:n,width:200,height:74,key:K});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(K)}};Z=fe([$(1,a.Inject(w.HoverManagerService)),$(2,a.Inject(w.CellAlertManagerService)),$(3,a.Inject(a.LocaleService)),$(4,_.IZenZoneService),$(5,a.Inject(g.INumfmtService)),$(6,a.IConfigService)],Z);const Y={id:"sheet.operation.close.numfmt.panel",type:a.CommandType.OPERATION,handler:()=>!0},F={id:"sheet.operation.open.numfmt.panel",type:a.CommandType.OPERATION,handler:e=>(e.get(R).openPanel(),!0)};var pe=Object.getOwnPropertyDescriptor,he=(e,t,r,n)=>{for(var i=n>1?void 0:n?pe(t,r):t,s=e.length-1,o;s>=0;s--)(o=e[s])&&(i=o(i)||i);return i},ge=(e,t)=>(r,n)=>t(r,n,e);const z=S.createContext([]);let H=class{constructor(e){this._localStorageService=e}_getKey(e){return`userHabitController_${e}`}async addHabit(e,t){const r=this._getKey(e);return this._localStorageService.getItem(r).then(n=>{n||this._localStorageService.setItem(r,t)})}markHabit(e,t){const r=this._getKey(e);this._localStorageService.getItem(r).then(n=>{if(n){const i=n.findIndex(s=>s===t);i>-1&&n.splice(i,1),n.unshift(t),this._localStorageService.setItem(r,n)}})}async getHabit(e,t){const r=this._getKey(e),n=await this._localStorageService.getItem(r);if(t&&n){const i=n.map((s,o,d)=>{const c=d.length;return{value:s,priority:c-o}});return t.sort((s,o)=>{var u,f;const d=((u=i.find(v=>v.value===s))==null?void 0:u.priority)||-1;return(((f=i.find(v=>v.value===o))==null?void 0:f.priority)||-1)-d})}return n||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};H=he([ge(0,a.Inject(a.ILocalStorageService))],H);const ne="numfmtCurrency",Se=e=>{const t=_.useDependency(H),[r,n]=S.useState(m.currencySymbols);return S.useEffect(()=>{t.addHabit("numfmtCurrency",[]).then(()=>{t.getHabit(ne,[...m.currencySymbols]).then(s=>{n(s),e&&e(s)})})},[]),{userHabitCurrency:r,mark:s=>{t.markHabit(ne,s)}}},ye=()=>{const e=S.useRef([]),[t,r]=S.useState({});return S.useEffect(()=>{e.current.forEach(i=>{i()}),e.current=[]},[t]),i=>{e.current.push(i),r({})}},_e=e=>!!m.getCurrencyType(e)&&e.startsWith("_("),Ce=e=>{const{defaultPattern:t,action:r,onChange:n}=e,[i,s]=S.useState(()=>m.getDecimalFromPattern(t||"",2)),o=S.useContext(z),[d,c]=S.useState(()=>m.getCurrencyType(t)||o[0]),u=S.useMemo(()=>o.map(b=>({label:b,value:b})),[]),v=_.useDependency(a.LocaleService).t;r.current=()=>m.setPatternDecimal(`_("${d}"* #,##0${i>0?".0":""}_)`,i);const h=b=>{c(b),n(m.setPatternDecimal(`_("${b}"* #,##0${i>0?".0":""}_)`,i))},y=b=>{const p=b||0;s(p),n(m.setPatternDecimal(`_("${d}"* #,##0${p>0?".0":""}_)`,p))};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:v("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2 univer-w-32",children:l.jsx(E.InputNumber,{value:i,step:1,precision:0,max:20,min:0,onChange:y})})]}),l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:v("sheet.numfmt.currencyType")}),l.jsx("div",{className:"univer-mt-2 univer-w-36",children:l.jsx(E.Select,{options:u,value:d,onChange:h})})]})]}),l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:v("sheet.numfmt.accountingDes")})]})},be=e=>!!m.getCurrencyType(e)&&!e.startsWith("_("),Ie=e=>{const r=_.useDependency(a.LocaleService).t,n=S.useContext(z),[i,s]=S.useState(()=>m.getCurrencyType(e.defaultPattern)||n[0]),[o,d]=S.useState(()=>m.getDecimalFromPattern(e.defaultPattern||"",2)),[c,u]=S.useState(()=>{var I;const p=m.getCurrencyFormatOptions(i);return((I=p.find(M=>a.isPatternEqualWithoutDecimal(M.value,e.defaultPattern)))==null?void 0:I.value)||p[0].value}),f=S.useMemo(()=>m.getCurrencyFormatOptions(i),[i]),v=S.useMemo(()=>n.map(p=>({label:p,value:p})),[n]);e.action.current=()=>m.setPatternDecimal(c,o);const h=p=>{if(p===void 0)return;s(p);const P=m.getCurrencyFormatOptions(p)[0].value;u(P),e.onChange(m.setPatternDecimal(P,o))},y=p=>{p!==void 0&&(u(p),e.onChange(m.setPatternDecimal(p,o)))},b=p=>{d(p||0),e.onChange(m.setPatternDecimal(c,p||0))};return l.jsxs("div",{children:[l.jsxs("div",{className:"univer-mt-4 univer-flex univer-justify-between",children:[l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:r("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2 univer-w-32",children:l.jsx(E.InputNumber,{value:o,max:20,min:0,onChange:b})})]}),l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:r("sheet.numfmt.currencyType")}),l.jsx("div",{className:"univer-mt-2 univer-w-36",children:l.jsx(E.Select,{value:i,options:v,onChange:h})})]})]}),l.jsx("div",{className:"label univer-mt-4",children:r("sheet.numfmt.negType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(E.SelectList,{value:c,options:f,onChange:y})}),l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:r("sheet.numfmt.currencyDes")})]})};var N=function(){return N=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},N.apply(this,arguments)},Te=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r},re=S.forwardRef(function(e,t){var r=e.icon,n=e.id,i=e.className,s=e.extend,o=Te(e,["icon","id","className","extend"]),d="univerjs-icon univerjs-icon-".concat(n," ").concat(i||"").trim(),c=S.useRef("_".concat(Me()));return ie(r,"".concat(n),{defIds:r.defIds,idSuffix:c.current},N({ref:t,className:d},o),s)});function ie(e,t,r,n,i){return S.createElement(e.tag,N(N({key:t},Ee(e,r,i)),n),(Pe(e,r).children||[]).map(function(s,o){return ie(s,"".concat(t,"-").concat(e.tag,"-").concat(o),r,void 0,i)}))}function Ee(e,t,r){var n=N({},e.attrs);r!=null&&r.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=r.colorChannel1),e.tag==="mask"&&n.id&&(n.id=n.id+t.idSuffix),Object.entries(n).forEach(function(s){var o=s[0],d=s[1];o==="mask"&&typeof d=="string"&&(n[o]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var i=t.defIds;return!i||i.length===0||(e.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(function(s){var o=s[0],d=s[1];typeof d=="string"&&(n[o]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function Pe(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)?N(N({},e),{children:e.children.map(function(i){return typeof i.attrs.id=="string"&&n&&n.includes(i.attrs.id)?N(N({},i),{attrs:N(N({},i.attrs),{id:i.attrs.id+t.idSuffix})}):i})}):e}function Me(){return Math.random().toString(36).substring(2,8)}re.displayName="UniverIcon";var we={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},ae=S.forwardRef(function(e,t){return S.createElement(re,Object.assign({},e,{id:"check-mark-icon",ref:t,icon:we}))});ae.displayName="CheckMarkIcon";const X="customFormat",J="numfmt_custom_pattern";function Ne(e){const{defaultPattern:t,action:r,onChange:n}=e,i=_.useDependency(H),s=_.useDependency(a.ILocalStorageService),o=_.useDependency(a.LocaleService),[d,c]=S.useState(t);r.current=()=>(i.markHabit(X,d),s.getItem(J).then((y=[])=>{const b=[...new Set([d,...y||[]])].splice(0,10).filter(p=>!!p);s.setItem(J,b)}),d);const[u,f]=S.useState([]);S.useEffect(()=>{s.getItem(J).then(y=>{const b=[...m.CURRENCYFORMAT.map(p=>p.suffix("$")),...m.DATEFMTLISG.map(p=>p.suffix),...m.NUMBERFORMAT.map(p=>p.suffix)];b.push(...y||[]),i.addHabit(X,[]).finally(()=>{i.getHabit(X,b).then(p=>{f([...new Set(p)])})})})},[]);const v=y=>{c(y),n(y)},h=()=>{n(d)};return l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:o.t("sheet.numfmt.customFormat")}),l.jsx(E.Input,{placeholder:o.t("sheet.numfmt.customFormat"),onBlur:h,value:d,onChange:c,className:"univer-mt-2 univer-w-full"}),l.jsx("div",{className:E.clsx("univer-mt-2 univer-max-h-[400px] univer-overflow-auto univer-rounded-lg univer-p-2",E.borderClassName),children:u.map(y=>l.jsxs("div",{onClick:()=>v(y),className:"univer-flex univer-cursor-pointer univer-items-center univer-gap-1.5 univer-py-1.5 univer-text-sm",children:[l.jsx("div",{className:"univer-flex univer-w-4 univer-items-center univer-text-primary-600",children:d===y&&l.jsx(ae,{})}),l.jsx("div",{children:y})]},y))}),l.jsx("div",{className:"univer-mt-3 univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200",children:o.t("sheet.numfmt.customFormatDes")})]})}const De=e=>{const t=a.numfmt.getFormatInfo(e);return m.getDateFormatOptions().map(r=>r.value).includes(e)||["date","datetime","time"].includes(t.type)};function Oe(e){const{onChange:t,defaultPattern:r}=e,n=S.useMemo(m.getDateFormatOptions,[]),i=_.useDependency(a.LocaleService),[s,o]=S.useState(()=>{if(r){const c=n.find(u=>u.value===r);if(c)return c.value}return n[0].value});e.action.current=()=>s;const d=c=>{c!==void 0&&(o(c),t(c))};return l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:i.t("sheet.numfmt.dateType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(E.SelectList,{value:s,options:n,onChange:d})}),l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:i.t("sheet.numfmt.dateDes")})]})}const xe=e=>!e,Ue=e=>{const r=_.useDependency(a.LocaleService).t;return e.action.current=()=>"",l.jsx("div",{children:l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:r("sheet.numfmt.generalDes")})})},ke=e=>m.getNumberFormatOptions().some(t=>a.isPatternEqualWithoutDecimal(t.value,e));function je(e){const t=_.useDependency(a.LocaleService),r=S.useMemo(m.getNumberFormatOptions,[]),[n,i]=S.useState(()=>m.getDecimalFromPattern(e.defaultPattern||"",0)),[s,o]=S.useState(()=>{const v=r.find(h=>a.isPatternEqualWithoutDecimal(h.value,e.defaultPattern||""));return(v==null?void 0:v.value)||r[0].value}),d=S.useMemo(()=>m.setPatternDecimal(s,Number(n||0)),[s,n]),c=S.useMemo(()=>!m.isPatternHasDecimal(s),[s]),u=v=>{i(v||0),e.onChange(m.setPatternDecimal(s,Number(v||0)))},f=v=>{v!==void 0&&(i(m.getDecimalFromPattern(v,0)),o(v),e.onChange(v))};return e.action.current=()=>d,l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:t.t("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(E.InputNumber,{disabled:c,value:n,max:20,min:0,onChange:u})}),l.jsxs("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:[" ",t.t("sheet.numfmt.negType")]}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(E.SelectList,{onChange:f,options:r,value:s})}),l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:t.t("sheet.numfmt.thousandthPercentileDes")})]})}const $e=e=>{const{defaultValue:t,defaultPattern:r,row:n,col:i}=e.value,s=_.useDependency(a.LocaleService),o=S.useRef(()=>""),d=s.t,c=ye(),u=S.useMemo(()=>[{label:"sheet.numfmt.general",component:Ue},{label:"sheet.numfmt.accounting",component:Ce},{label:"sheet.numfmt.currency",component:Ie},{label:"sheet.numfmt.date",component:Oe},{label:"sheet.numfmt.thousandthPercentile",component:je},{label:"sheet.numfmt.customFormat",component:Ne}].map(T=>({...T,label:d(T.label)})),[]),[f,v]=S.useState(I),[h,y]=S.useState(()=>`${n}_${i}`),{mark:b,userHabitCurrency:p}=Se(()=>y(`${n}_${i}_userCurrency'`)),P=S.useMemo(()=>{var T;return(T=u.find(L=>L.label===f))==null?void 0:T.component},[f]);function I(){return[xe,_e,be,De,ke].reduce((L,it,at)=>L||(it(r)?u[at].label:""),"")||u[0].label}const M=u.map(T=>({label:T.label,value:T.label})),x=T=>{v(T),c(()=>e.onChange({type:"change",value:o.current()||""}))},U=S.useCallback(T=>{e.onChange({type:"change",value:T})},[]),k=()=>{const T=o.current()||"",L=m.getCurrencyType(T);L&&b(L),e.onChange({type:"confirm",value:T})},W=()=>{e.onChange({type:"cancel",value:""})},ee={onChange:U,defaultValue:t,defaultPattern:r,action:o};return S.useEffect(()=>{v(I()),y(`${n}_${i}`)},[n,i]),l.jsxs("div",{className:E.clsx("univer-flex univer-h-full univer-flex-col univer-justify-between univer-overflow-y-auto univer-pb-5",E.scrollbarClassName),children:[l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-3.5 univer-text-sm univer-text-gray-400",children:d("sheet.numfmt.numfmtType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(E.Select,{className:"univer-w-full",value:f,options:M,onChange:x})}),l.jsx("div",{children:P&&l.jsx(z.Provider,{value:p,children:S.createElement(P,{...ee,key:h})})})]}),l.jsxs("div",{className:"univer-mb-5 univer-mt-3.5 univer-flex univer-justify-end",children:[l.jsx(E.Button,{onClick:W,className:"univer-mr-3",children:d("sheet.numfmt.cancel")}),l.jsx(E.Button,{variant:"primary",onClick:k,children:d("sheet.numfmt.confirm")})]})]})};var Le=Object.getOwnPropertyDescriptor,Fe=(e,t,r,n)=>{for(var i=n>1?void 0:n?Le(t,r):t,s=e.length-1,o;s>=0;s--)(o=e[s])&&(i=o(i)||i);return i},D=(e,t)=>(r,n)=>t(r,n,e);const se="SHEET_NUMFMT_PANEL";let R=class extends a.Disposable{constructor(t,r,n,i,s,o,d,c,u,f,v){super();G(this,"_previewPattern","");G(this,"_sidebarDisposable",null);this._sheetInterceptorService=t,this._themeService=r,this._univerInstanceService=n,this._commandService=i,this._selectionManagerService=s,this._renderManagerService=o,this._numfmtService=d,this._componentManager=c,this._sidebarService=u,this._localeService=f,this._sheetsNumfmtCellContentController=v,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener(),this._initNumfmtLocalChange()}_initNumfmtLocalChange(){this.disposeWithMe(O.merge(this._sheetsNumfmtCellContentController.locale$,this._localeService.currentLocale$).subscribe(()=>{this._forceUpdate()}))}openPanel(){var P;const t=this._sidebarService,r=this._selectionManagerService,n=this._commandService,i=this._univerInstanceService,s=this._numfmtService,o=this._localeService,c=(((P=r.getCurrentSelections())==null?void 0:P.map(I=>I.range))||[])[0];if(!c)return!1;const u=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),f=u.getActiveSheet();if(!f)return!1;const v=f.getCellRaw(c.startRow,c.startColumn),h=s.getValue(u.getUnitId(),f.getSheetId(),c.startRow,c.startColumn);let y="";h&&(y=h.pattern);const b=(v==null?void 0:v.t)===a.CellValueType.NUMBER?v.v:12345678,p={onChange:I=>{var M;if(I.type==="change")this._previewPattern=I.value,this._forceUpdate();else if(I.type==="confirm"){const x=((M=r.getCurrentSelections())==null?void 0:M.map(W=>W.range))||[],U={values:[]},k=m.getPatternType(I.value);x.forEach(W=>{a.Range.foreach(W,(ee,T)=>{U.values.push({row:ee,col:T,pattern:I.value,type:k})})}),n.executeCommand(m.SetNumfmtCommand.id,U),t.close()}else I.type==="cancel"&&t.close()},value:{defaultPattern:y,defaultValue:b,row:c.startRow,col:c.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(a.UniverInstanceType.UNIVER_SHEET).getUnitId());r==null||r.with(w.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.disposeWithMe(this._componentManager.register(se,$e))}_initRealTimeRenderingInterceptor(){const t=new O.Observable(n=>{this._commandService.onCommandExecuted(i=>{i.id===F.id&&n.next(!0),i.id===Y.id&&n.next(!1)})}),r=O.combineLatest([t,this._selectionManagerService.selectionMoveEnd$.pipe(B.map(n=>n?n.map(i=>i.range):[]))]);this.disposeWithMe(a.toDisposable(r.pipe(B.switchMap(([n,i])=>new O.Observable(s=>{const o=new a.DisposableCollection;return n&&i.length&&s.next({selectionRanges:i,disposableCollection:o}),()=>{o.dispose()}})),B.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:n,selectionRanges:i})=>{var o,d;const s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);this.openPanel(),n.add(this._sheetInterceptorService.intercept(g.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,effect:a.InterceptorEffectEnum.Value|a.InterceptorEffectEnum.Style,handler:(c,u,f)=>{var b;const{row:v,col:h}=u,y=f(c)||{};if(i.find(p=>p.startColumn<=h&&p.endColumn>=h&&p.startRow<=v&&p.endRow>=v)){const p=u.worksheet.getCellRaw(v,h),P=p==null?void 0:p.v,I=p==null?void 0:p.t;if(P==null||I!==a.CellValueType.NUMBER||this._previewPattern===null)return y;const M=m.getPatternPreviewIgnoreGeneral(this._previewPattern,P,this._sheetsNumfmtCellContentController.locale);if(M.color){const x=(b=this._themeService.getColorFromTheme(`${M.color}.500`))!=null?b:M.color;return{...y,v:M.result,t:a.CellValueType.STRING,s:{cl:{rgb:x}}}}return{...y,v:M.result,t:a.CellValueType.STRING}}return y}})),(d=(o=this._renderManagerService.getRenderById(s.getUnitId()))==null?void 0:o.mainComponent)==null||d.makeDirty()})))}_commandExecutedListener(){const t=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id];this.disposeWithMe(new O.Observable(r=>{const n=this._commandService.onCommandExecuted(i=>{if(t.includes(i.id)){const s=i.params;r.next(s.unitId)}});return()=>n.dispose()}).pipe(B.debounceTime(16)).subscribe(r=>this._forceUpdate(r)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(t=>{var r;t||((r=this._sidebarDisposable)==null||r.dispose(),this._sidebarDisposable=null)})}};R=Fe([D(0,a.Inject(g.SheetInterceptorService)),D(1,a.Inject(a.ThemeService)),D(2,a.IUniverInstanceService),D(3,a.ICommandService),D(4,a.Inject(g.SheetsSelectionsService)),D(5,j.IRenderManagerService),D(6,g.INumfmtService),D(7,a.Inject(_.ComponentManager)),D(8,_.ISidebarService),D(9,a.Inject(a.LocaleService)),D(10,a.Inject(m.SheetsNumfmtCellContentController))],R);var He=Object.getOwnPropertyDescriptor,Re=(e,t,r,n)=>{for(var i=n>1?void 0:n?He(t,r):t,s=e.length-1,o;s>=0;s--)(o=e[s])&&(i=o(i)||i);return i},A=(e,t)=>(r,n)=>t(r,n,e);const Ae=()=>{let e=[];return{add:(i,s,o,d,c)=>e.push({unitId:i,subUnitId:s,row:o,col:d,value:c}),getEffects:()=>e,clean:()=>{e=[]}}};let V=class extends a.Disposable{constructor(t,r,n,i,s){super();G(this,"_collectEffectMutation",Ae());this._sheetInterceptorService=t,this._numfmtService=r,this._univerInstanceService=n,this._injector=i,this._editorBridgeService=s,this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(a.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.BEFORE_CELL_EDIT,{handler:(t,r,n)=>{const i=r.row,s=r.col,o=this._numfmtService.getValue(r.unitId,r.subUnitId,i,s);if(o)switch(m.getPatternType(o.pattern)){case"scientific":case"currency":case"grouped":case"number":{const c=r.worksheet.getCellRaw(i,s);return(c==null?void 0:c.t)===a.CellValueType.NUMBER&&(c==null?void 0:c.v)!==void 0&&c.v!==null&&a.isRealNum(c.v)&&(c.v=me.stripErrorMargin(Number(c.v))),n&&n(c)}case"percent":case"date":case"time":case"datetime":default:return n&&n(t)}return n(t)}})))}_initInterceptorEditorEnd(){this.disposeWithMe(a.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.AFTER_CELL_EDIT,{handler:(t,r,n)=>{var u,f,v;if(!(t!=null&&t.v)&&!(t!=null&&t.p))return n(t);this._collectEffectMutation.clean();const i=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col),s=r.worksheet.getCellRaw(r.row,r.col);if(a.isTextFormat(i==null?void 0:i.pattern)||t.t===a.CellValueType.FORCE_STRING)return n(t);const o=(u=t.p)==null?void 0:u.body,d=(v=(f=t==null?void 0:t.p)==null?void 0:f.body)!=null&&v.dataStream?t.p.body.dataStream.replace(/\r\n$/,""):String(t.v),c=m.getNumfmtParseValueFilter(d);if(o)if(We(o)){const{dataStream:h}=o,y=h.replace(/\r\n$/,""),b=Number(y);if(Number.isNaN(b)&&!c)return n(t)}else return n(t);if(c){if(!c.z&&!(i!=null&&i.pattern)&&(s==null?void 0:s.t)!==a.CellValueType.STRING&&(s==null?void 0:s.t)!==a.CellValueType.FORCE_STRING&&a.willLoseNumericPrecision(d))return n({...t,p:void 0,v:d,t:a.CellValueType.FORCE_STRING});c.z&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:c.z});const h=Number(c.v);return n({...t,p:void 0,v:h,t:a.CellValueType.NUMBER})}return n(t)}})))}_initInterceptorCommands(){const t=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(r){var n;switch(r.id){case g.SetRangeValuesCommand.id:{const i=t._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=i.getUnitId(),o=(n=i.getActiveSheet())==null?void 0:n.getSheetId();if(!o)return{redos:[],undos:[]};const d=t._collectEffectMutation.getEffects();if(t._collectEffectMutation.clean(),!d.length)return{redos:[],undos:[]};const c=d.filter(h=>{var y;return!!((y=h.value)!=null&&y.pattern)}).map(h=>({row:h.row,col:h.col,pattern:h.value.pattern})),u=d.filter(h=>{var y;return!((y=h.value)!=null&&y.pattern)}).map(h=>({startRow:h.row,endColumn:h.col,startColumn:h.col,endRow:h.row})),f=[],v=[];if(c.length){const h={id:g.SetNumfmtMutation.id,params:g.transformCellsToRange(s,o,c)};f.push(h),v.push(...g.factorySetNumfmtUndoMutation(t._injector,h.params))}if(u.length){const h={id:g.RemoveNumfmtMutation.id,params:{unitId:s,subUnitId:o,ranges:u}};f.push(h),v.push(...g.factoryRemoveNumfmtUndoMutation(t._injector,h.params))}return{redos:f,undos:v.reverse()}}}return{redos:[],undos:[]}}}))}};V=Re([A(0,a.Inject(g.SheetInterceptorService)),A(1,a.Inject(g.INumfmtService)),A(2,a.Inject(a.IUniverInstanceService)),A(3,a.Inject(a.Injector)),A(4,a.Optional(w.IEditorBridgeService))],V);function We(e){const{textRuns:t=[],paragraphs:r=[],customRanges:n,customBlocks:i=[]}=e,s=["va"];return!(t.some(o=>!!(o.ts&&Object.keys(o.ts).some(c=>s.includes(c))))||r.some(o=>o.bullet)||r.length>=2||n!=null&&n.length||i.length>0)}const oe=e=>[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:a.DEFAULT_TEXT_FORMAT_EXCEL},"|",{label:"sheet.numfmt.number",pattern:"0"},{label:"sheet.numfmt.percent",pattern:"0.00%"},{label:"sheet.numfmt.scientific",pattern:"0.00E+00"},"|",{label:"sheet.numfmt.accounting",pattern:`"${e}" #,##0.00_);[Red]("${e}"#,##0.00)`},{label:"sheet.numfmt.financialValue",pattern:"#,##0.00;[Red]#,##0.00"},{label:"sheet.numfmt.currency",pattern:`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`},{label:"sheet.numfmt.roundingCurrency",pattern:`"${e}"#,##0;[Red]"${e}"#,##0`},"|",{label:"sheet.numfmt.date",pattern:"yyyy-mm-dd;@"},{label:"sheet.numfmt.time",pattern:'am/pm h":"mm":"ss'},{label:"sheet.numfmt.dateTime",pattern:"yyyy-m-d am/pm h:mm"},{label:"sheet.numfmt.timeDuration",pattern:"h:mm:ss"},"|",{label:"sheet.numfmt.moreFmt",pattern:""}],Be=e=>({icon:new O.Observable(t=>{const r=e.get(a.LocaleService);return t.next(m.getCurrencySymbolIconByLocale(r.getCurrentLocale()).icon),r.localeChanged$.subscribe(()=>{t.next(m.getCurrencySymbolIconByLocale(r.getCurrentLocale()).icon)})}),id:m.SetCurrencyCommand.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:w.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Ve=e=>({icon:"AddDigitsIcon",id:m.AddDecimalCommand.id,title:"sheet.numfmt.addDecimal",tooltip:"sheet.numfmt.addDecimal",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:w.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),qe=e=>({icon:"ReduceDigitsIcon",id:m.SubtractDecimalCommand.id,title:"sheet.numfmt.subtractDecimal",tooltip:"sheet.numfmt.subtractDecimal",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:w.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Ge=e=>({icon:"PercentIcon",id:m.SetPercentCommand.id,title:"sheet.numfmt.percent",tooltip:"sheet.numfmt.percent",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:w.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Ke=e=>{const t=e.get(a.IUniverInstanceService),r=e.get(a.ICommandService),n=e.get(a.LocaleService),i=e.get(g.SheetsSelectionsService),s=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id],o=w.deriveStateFromActiveSheet$(t,"",({workbook:d,worksheet:c})=>new O.Observable(u=>O.merge(i.selectionMoveEnd$,a.fromCallback(r.onCommandExecuted.bind(r)).pipe(O.filter(([f])=>s.includes(f.id)))).subscribe(()=>{var v,h;const f=i.getCurrentSelections();if(f&&f[0]){const y=f[0].range,b=y.startRow,p=y.startColumn,P=(h=d.getStyles().get((v=c.getCell(b,p))==null?void 0:v.s))==null?void 0:h.n,I=P==null?void 0:P.pattern,M=m.getCurrencySymbolByLocale(n.getCurrentLocale());let x=n.t("sheet.numfmt.general");if(a.isDefaultFormat(I)){u.next(x);return}if(I){const U=oe(M).filter(k=>typeof k=="object"&&k.pattern).find(k=>a.isPatternEqualWithoutDecimal(I,k.pattern));U&&typeof U=="object"&&U.pattern?x=n.t(U.label):x=n.t("sheet.numfmt.moreFmt")}u.next(x)}})));return{label:ce,id:F.id,tooltip:"sheet.numfmt.title",type:_.MenuItemType.SELECTOR,slot:!0,selections:[{label:{name:le,hoverable:!1,selectable:!1}}],value$:o,hidden$:_.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:w.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetSetCellStylePermission,g.WorksheetEditPermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}},ce="sheet.numfmt.moreNumfmtType",le="sheet.numfmt.moreNumfmtType.options",Ze=e=>{const{value:t}=e,r=_.useDependency(a.LocaleService),n=t!=null?t:r.t("sheet.numfmt.general");return l.jsx("span",{className:"univer-text-sm",children:n})},Ye=()=>{const e=_.useDependency(a.ICommandService),t=_.useDependency(a.LocaleService),r=_.useDependency(_.ILayoutService),n=_.useDependency(m.SheetsNumfmtCellContentController),i=_.useDependency(g.SheetsSelectionsService),s=u=>{const f=i.getCurrentLastSelection();if(!f)return;const v=f.range,h=[];a.Range.foreach(v,(y,b)=>{u?h.push({row:y,col:b,pattern:u,type:m.getPatternType(u)}):h.push({row:y,col:b})}),e.executeCommand(m.SetNumfmtCommand.id,{values:h}),r.focus()},o=S.useMemo(()=>{const u=m.localeCurrencySymbolMap.get(t.getCurrentLocale());return oe(u)},[t]),d=u=>{if(u===0)s(null);else if(u===o.length-1)e.executeCommand(F.id),r.focus();else{const f=o[u];f.pattern&&s(f.pattern)}},c=1220;return l.jsx("div",{className:"univer-grid univer-gap-1 univer-p-1.5",children:o.map((u,f)=>u==="|"?l.jsx(E.Separator,{},f):l.jsxs("div",{className:"univer-flex univer-h-7 univer-items-center univer-justify-between univer-gap-6 univer-rounded univer-px-2 univer-text-sm hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",onClick:()=>{d(f)},children:[l.jsx("span",{children:t.t(u.label)}),l.jsx("span",{className:"univer-text-xs univer-text-gray-500",children:u.pattern?m.getPatternPreview(u.pattern||"",c,n.locale).result.trim():""})]},f))})},ze={[_.RibbonDataGroup.FORMULAS]:{[m.SetCurrencyCommand.id]:{order:0,menuItemFactory:Be},[m.AddDecimalCommand.id]:{order:1,menuItemFactory:Ve},[m.SubtractDecimalCommand.id]:{order:2,menuItemFactory:qe},[m.SetPercentCommand.id]:{order:3,menuItemFactory:Ge},[F.id]:{order:4,menuItemFactory:Ke}}};var Xe=Object.getOwnPropertyDescriptor,Je=(e,t,r,n)=>{for(var i=n>1?void 0:n?Xe(t,r):t,s=e.length-1,o;s>=0;s--)(o=e[s])&&(i=o(i)||i);return i},ue=(e,t)=>(r,n)=>t(r,n,e);let q=class extends a.Disposable{constructor(e,t){super(),this._componentManager=e,this._menuManagerService=t,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(ze),[[ce,Ze],[le,Ye]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};q=Je([ue(0,a.Inject(_.ComponentManager)),ue(1,_.IMenuManagerService)],q);var Qe=Object.defineProperty,et=Object.getOwnPropertyDescriptor,tt=(e,t,r)=>t in e?Qe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,nt=(e,t,r,n)=>{for(var i=n>1?void 0:n?et(t,r):t,s=e.length-1,o;s>=0;s--)(o=e[s])&&(i=o(i)||i);return i},Q=(e,t)=>(r,n)=>t(r,n,e),de=(e,t,r)=>tt(e,typeof t!="symbol"?t+"":t,r);const rt="SHEET_NUMFMT_UI_PLUGIN";C.UniverSheetsNumfmtUIPlugin=class extends a.Plugin{constructor(t=te,r,n,i){super(),this._config=t,this._injector=r,this._configService=n,this._renderManagerService=i;const{menu:s,...o}=a.merge({},te,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig("sheets-numfmt-ui.config",o)}onStarting(){a.registerDependencies(this._injector,[[R],[V],[H],[q]])}onRendered(){this._registerRenderModules(),a.touchDependencies(this._injector,[[R],[V],[q]])}_registerRenderModules(){[[Z]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,r))})}},de(C.UniverSheetsNumfmtUIPlugin,"pluginName",rt),de(C.UniverSheetsNumfmtUIPlugin,"type",a.UniverInstanceType.UNIVER_SHEET),C.UniverSheetsNumfmtUIPlugin=nt([a.DependentOn(w.UniverSheetsUIPlugin,m.UniverSheetsNumfmtPlugin),Q(1,a.Inject(a.Injector)),Q(2,a.IConfigService),Q(3,j.IRenderManagerService)],C.UniverSheetsNumfmtUIPlugin),Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(C,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/sheets-numfmt"),require("@univerjs/sheets-ui"),require("@univerjs/sheets"),require("@univerjs/ui"),require("rxjs"),require("rxjs/operators"),require("react/jsx-runtime"),require("react"),require("@univerjs/design"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","@univerjs/sheets-numfmt","@univerjs/sheets-ui","@univerjs/sheets","@univerjs/ui","rxjs","rxjs/operators","react/jsx-runtime","react","@univerjs/design","@univerjs/engine-formula"],a):(C=typeof globalThis<"u"?globalThis:C||self,a(C.UniverSheetsNumfmtUi={},C.UniverCore,C.UniverEngineRender,C.UniverSheetsNumfmt,C.UniverSheetsUi,C.UniverSheets,C.UniverUi,C.rxjs,C.rxjs.operators,C.React,C.React,C.UniverDesign,C.UniverEngineFormula))})(this,(function(C,a,j,v,N,g,_,O,B,l,S,E,me){"use strict";var st=Object.defineProperty;var ot=(C,a,j)=>a in C?st(C,a,{enumerable:!0,configurable:!0,writable:!0,value:j}):C[a]=j;var G=(C,a,j)=>ot(C,typeof a!="symbol"?a+"":a,j);const te={};var ve=Object.getOwnPropertyDescriptor,fe=(e,t,r,n)=>{for(var i=n>1?void 0:n?ve(t,r):t,s=e.length-1,o;s>=0;s--)(o=e[s])&&(i=o(i)||i);return i},$=(e,t)=>(r,n)=>t(r,n,e);const K="SHEET_NUMFMT_ALERT";let Z=class extends a.Disposable{constructor(e,t,r,n,i,s,o){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=r,this._localeService=n,this._zenZoneService=i,this._numfmtService=s,this._configService=o,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(O.debounceTime(100)).subscribe(e=>{var t,r;if(e){const n=e.location,i=this._context.unit,s=i.getActiveSheet();if(!s)return;const o=n.unitId,d=n.subUnitId;let c;const u=s.getCell(n.row,n.col);if(u!=null&&u.s){const f=i.getStyles().get(u.s);f!=null&&f.n&&(c=f.n)}if(c||(c=this._numfmtService.getValue(o,d,n.row,n.col)),!c){this._hideAlert();return}if(a.isTextFormat(c.pattern)&&a.Tools.isDefine(u==null?void 0:u.v)&&a.isRealNum(u.v)){if((t=this._configService.getConfig(v.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY))!=null&&t.disableTextFormatAlert)return;const f=this._cellAlertManagerService.currentAlert.get(K),m=(r=f==null?void 0:f.alert)==null?void 0:r.location;if(m&&m.row===n.row&&m.col===n.col&&m.subUnitId===n.subUnitId&&m.unitId===n.unitId)return;this._cellAlertManagerService.showAlert({type:N.CellAlertType.ERROR,title:this._localeService.t("info.error"),message:this._localeService.t("info.forceStringInfo"),location:n,width:200,height:74,key:K});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(K)}};Z=fe([$(1,a.Inject(N.HoverManagerService)),$(2,a.Inject(N.CellAlertManagerService)),$(3,a.Inject(a.LocaleService)),$(4,_.IZenZoneService),$(5,a.Inject(g.INumfmtService)),$(6,a.IConfigService)],Z);const Y={id:"sheet.operation.close.numfmt.panel",type:a.CommandType.OPERATION,handler:()=>!0},F={id:"sheet.operation.open.numfmt.panel",type:a.CommandType.OPERATION,handler:e=>(e.get(R).openPanel(),!0)};var pe=Object.getOwnPropertyDescriptor,he=(e,t,r,n)=>{for(var i=n>1?void 0:n?pe(t,r):t,s=e.length-1,o;s>=0;s--)(o=e[s])&&(i=o(i)||i);return i},ge=(e,t)=>(r,n)=>t(r,n,e);const z=S.createContext([]);let H=class{constructor(e){this._localStorageService=e}_getKey(e){return`userHabitController_${e}`}async addHabit(e,t){const r=this._getKey(e);return this._localStorageService.getItem(r).then(n=>{n||this._localStorageService.setItem(r,t)})}markHabit(e,t){const r=this._getKey(e);this._localStorageService.getItem(r).then(n=>{if(n){const i=n.findIndex(s=>s===t);i>-1&&n.splice(i,1),n.unshift(t),this._localStorageService.setItem(r,n)}})}async getHabit(e,t){const r=this._getKey(e),n=await this._localStorageService.getItem(r);if(t&&n){const i=n.map((s,o,d)=>{const c=d.length;return{value:s,priority:c-o}});return t.sort((s,o)=>{var u,f;const d=((u=i.find(m=>m.value===s))==null?void 0:u.priority)||-1;return(((f=i.find(m=>m.value===o))==null?void 0:f.priority)||-1)-d})}return n||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};H=he([ge(0,a.Inject(a.ILocalStorageService))],H);const ne="numfmtCurrency",Se=e=>{const t=_.useDependency(H),[r,n]=S.useState(v.currencySymbols);return S.useEffect(()=>{t.addHabit("numfmtCurrency",[]).then(()=>{t.getHabit(ne,[...v.currencySymbols]).then(s=>{n(s),e&&e(s)})})},[]),{userHabitCurrency:r,mark:s=>{t.markHabit(ne,s)}}},ye=()=>{const e=S.useRef([]),[t,r]=S.useState({});return S.useEffect(()=>{e.current.forEach(i=>{i()}),e.current=[]},[t]),i=>{e.current.push(i),r({})}},_e=e=>!!v.getCurrencyType(e)&&e.startsWith("_("),Ce=e=>{const{defaultPattern:t,action:r,onChange:n}=e,[i,s]=S.useState(()=>v.getDecimalFromPattern(t||"",2)),o=S.useContext(z),[d,c]=S.useState(()=>v.getCurrencyType(t)||o[0]),u=S.useMemo(()=>o.map(b=>({label:b,value:b})),[]),m=_.useDependency(a.LocaleService).t;r.current=()=>v.setPatternDecimal(`_("${d}"* #,##0${i>0?".0":""}_)`,i);const h=b=>{c(b),n(v.setPatternDecimal(`_("${b}"* #,##0${i>0?".0":""}_)`,i))},y=b=>{const p=b||0;s(p),n(v.setPatternDecimal(`_("${d}"* #,##0${p>0?".0":""}_)`,p))};return l.jsxs("div",{children:[l.jsxs("div",{className:"univer-mt-4 univer-flex univer-justify-between",children:[l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2 univer-w-32",children:l.jsx(E.InputNumber,{value:i,step:1,precision:0,max:20,min:0,onChange:y})})]}),l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.currencyType")}),l.jsx("div",{className:"univer-mt-2 univer-w-36",children:l.jsx(E.Select,{options:u,value:d,onChange:h})})]})]}),l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.accountingDes")})]})},be=e=>!!v.getCurrencyType(e)&&!e.startsWith("_("),Ie=e=>{const r=_.useDependency(a.LocaleService).t,n=S.useContext(z),[i,s]=S.useState(()=>v.getCurrencyType(e.defaultPattern)||n[0]),[o,d]=S.useState(()=>v.getDecimalFromPattern(e.defaultPattern||"",2)),[c,u]=S.useState(()=>{var I;const p=v.getCurrencyFormatOptions(i);return((I=p.find(M=>a.isPatternEqualWithoutDecimal(M.value,e.defaultPattern)))==null?void 0:I.value)||p[0].value}),f=S.useMemo(()=>v.getCurrencyFormatOptions(i),[i]),m=S.useMemo(()=>n.map(p=>({label:p,value:p})),[n]);e.action.current=()=>v.setPatternDecimal(c,o);const h=p=>{if(p===void 0)return;s(p);const P=v.getCurrencyFormatOptions(p)[0].value;u(P),e.onChange(v.setPatternDecimal(P,o))},y=p=>{p!==void 0&&(u(p),e.onChange(v.setPatternDecimal(p,o)))},b=p=>{d(p||0),e.onChange(v.setPatternDecimal(c,p||0))};return l.jsxs("div",{children:[l.jsxs("div",{className:"univer-mt-4 univer-flex univer-justify-between",children:[l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:r("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2 univer-w-32",children:l.jsx(E.InputNumber,{value:o,max:20,min:0,onChange:b})})]}),l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:r("sheet.numfmt.currencyType")}),l.jsx("div",{className:"univer-mt-2 univer-w-36",children:l.jsx(E.Select,{value:i,options:m,onChange:h})})]})]}),l.jsx("div",{className:"label univer-mt-4",children:r("sheet.numfmt.negType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(E.SelectList,{value:c,options:f,onChange:y})}),l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:r("sheet.numfmt.currencyDes")})]})};var w=function(){return w=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])}return e},w.apply(this,arguments)},Te=function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r},re=S.forwardRef(function(e,t){var r=e.icon,n=e.id,i=e.className,s=e.extend,o=Te(e,["icon","id","className","extend"]),d="univerjs-icon univerjs-icon-".concat(n," ").concat(i||"").trim(),c=S.useRef("_".concat(Me()));return ie(r,"".concat(n),{defIds:r.defIds,idSuffix:c.current},w({ref:t,className:d},o),s)});function ie(e,t,r,n,i){return S.createElement(e.tag,w(w({key:t},Ee(e,r,i)),n),(Pe(e,r).children||[]).map(function(s,o){return ie(s,"".concat(t,"-").concat(e.tag,"-").concat(o),r,void 0,i)}))}function Ee(e,t,r){var n=w({},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(s){var o=s[0],d=s[1];o==="mask"&&typeof d=="string"&&(n[o]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))});var i=t.defIds;return!i||i.length===0||(e.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(function(s){var o=s[0],d=s[1];typeof d=="string"&&(n[o]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function Pe(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)?w(w({},e),{children:e.children.map(function(i){return typeof i.attrs.id=="string"&&n&&n.includes(i.attrs.id)?w(w({},i),{attrs:w(w({},i.attrs),{id:i.attrs.id+t.idSuffix})}):i})}):e}function Me(){return Math.random().toString(36).substring(2,8)}re.displayName="UniverIcon";var Ne={tag:"svg",attrs:{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},ae=S.forwardRef(function(e,t){return S.createElement(re,Object.assign({},e,{id:"check-mark-icon",ref:t,icon:Ne}))});ae.displayName="CheckMarkIcon";const X="customFormat",J="numfmt_custom_pattern";function we(e){const{defaultPattern:t,action:r,onChange:n}=e,i=_.useDependency(H),s=_.useDependency(a.ILocalStorageService),o=_.useDependency(a.LocaleService),[d,c]=S.useState(t);r.current=()=>(i.markHabit(X,d),s.getItem(J).then((y=[])=>{const b=[...new Set([d,...y||[]])].splice(0,10).filter(p=>!!p);s.setItem(J,b)}),d);const[u,f]=S.useState([]);S.useEffect(()=>{s.getItem(J).then(y=>{const b=[...v.CURRENCYFORMAT.map(p=>p.suffix("$")),...v.DATEFMTLISG.map(p=>p.suffix),...v.NUMBERFORMAT.map(p=>p.suffix)];b.push(...y||[]),i.addHabit(X,[]).finally(()=>{i.getHabit(X,b).then(p=>{f([...new Set(p)])})})})},[]);const m=y=>{c(y),n(y)},h=()=>{n(d)};return l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:o.t("sheet.numfmt.customFormat")}),l.jsx(E.Input,{placeholder:o.t("sheet.numfmt.customFormat"),onBlur:h,value:d,onChange:c,className:"univer-mt-2 univer-w-full"}),l.jsx("div",{className:E.clsx("univer-mt-2 univer-max-h-[400px] univer-overflow-auto univer-rounded-lg univer-p-2",E.borderClassName),children:u.map(y=>l.jsxs("div",{onClick:()=>m(y),className:"univer-flex univer-cursor-pointer univer-items-center univer-gap-1.5 univer-py-1.5 univer-text-sm",children:[l.jsx("div",{className:"univer-flex univer-w-4 univer-items-center univer-text-primary-600",children:d===y&&l.jsx(ae,{})}),l.jsx("div",{children:y})]},y))}),l.jsx("div",{className:"univer-mt-3 univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200",children:o.t("sheet.numfmt.customFormatDes")})]})}const De=e=>{const t=a.numfmt.getFormatInfo(e);return v.getDateFormatOptions().map(r=>r.value).includes(e)||["date","datetime","time"].includes(t.type)};function Oe(e){const{onChange:t,defaultPattern:r}=e,n=S.useMemo(v.getDateFormatOptions,[]),i=_.useDependency(a.LocaleService),[s,o]=S.useState(()=>{if(r){const c=n.find(u=>u.value===r);if(c)return c.value}return n[0].value});e.action.current=()=>s;const d=c=>{c!==void 0&&(o(c),t(c))};return l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:i.t("sheet.numfmt.dateType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(E.SelectList,{value:s,options:n,onChange:d})}),l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:i.t("sheet.numfmt.dateDes")})]})}const xe=e=>!e,Ue=e=>{const r=_.useDependency(a.LocaleService).t;return e.action.current=()=>"",l.jsx("div",{children:l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:r("sheet.numfmt.generalDes")})})},ke=e=>v.getNumberFormatOptions().some(t=>a.isPatternEqualWithoutDecimal(t.value,e));function je(e){const t=_.useDependency(a.LocaleService),r=S.useMemo(v.getNumberFormatOptions,[]),[n,i]=S.useState(()=>v.getDecimalFromPattern(e.defaultPattern||"",0)),[s,o]=S.useState(()=>{const m=r.find(h=>a.isPatternEqualWithoutDecimal(h.value,e.defaultPattern||""));return(m==null?void 0:m.value)||r[0].value}),d=S.useMemo(()=>v.setPatternDecimal(s,Number(n||0)),[s,n]),c=S.useMemo(()=>!v.isPatternHasDecimal(s),[s]),u=m=>{i(m||0),e.onChange(v.setPatternDecimal(s,Number(m||0)))},f=m=>{m!==void 0&&(i(v.getDecimalFromPattern(m,0)),o(m),e.onChange(m))};return e.action.current=()=>d,l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:t.t("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(E.InputNumber,{disabled:c,value:n,max:20,min:0,onChange:u})}),l.jsxs("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:[" ",t.t("sheet.numfmt.negType")]}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(E.SelectList,{onChange:f,options:r,value:s})}),l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:t.t("sheet.numfmt.thousandthPercentileDes")})]})}const $e=e=>{const{defaultValue:t,defaultPattern:r,row:n,col:i}=e.value,s=_.useDependency(a.LocaleService),o=S.useRef(()=>""),d=s.t,c=ye(),u=S.useMemo(()=>[{label:"sheet.numfmt.general",component:Ue},{label:"sheet.numfmt.accounting",component:Ce},{label:"sheet.numfmt.currency",component:Ie},{label:"sheet.numfmt.date",component:Oe},{label:"sheet.numfmt.thousandthPercentile",component:je},{label:"sheet.numfmt.customFormat",component:we}].map(T=>({...T,label:d(T.label)})),[]),[f,m]=S.useState(I),[h,y]=S.useState(()=>`${n}_${i}`),{mark:b,userHabitCurrency:p}=Se(()=>y(`${n}_${i}_userCurrency'`)),P=S.useMemo(()=>{var T;return(T=u.find(L=>L.label===f))==null?void 0:T.component},[f]);function I(){return[xe,_e,be,De,ke].reduce((L,it,at)=>L||(it(r)?u[at].label:""),"")||u[0].label}const M=u.map(T=>({label:T.label,value:T.label})),x=T=>{m(T),c(()=>e.onChange({type:"change",value:o.current()||""}))},U=S.useCallback(T=>{e.onChange({type:"change",value:T})},[]),k=()=>{const T=o.current()||"",L=v.getCurrencyType(T);L&&b(L),e.onChange({type:"confirm",value:T})},W=()=>{e.onChange({type:"cancel",value:""})},ee={onChange:U,defaultValue:t,defaultPattern:r,action:o};return S.useEffect(()=>{m(I()),y(`${n}_${i}`)},[n,i]),l.jsxs("div",{className:E.clsx("univer-flex univer-h-full univer-flex-col univer-justify-between univer-overflow-y-auto univer-pb-5",E.scrollbarClassName),children:[l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-3.5 univer-text-sm univer-text-gray-400",children:d("sheet.numfmt.numfmtType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(E.Select,{className:"univer-w-full",value:f,options:M,onChange:x})}),l.jsx("div",{children:P&&l.jsx(z.Provider,{value:p,children:S.createElement(P,{...ee,key:h})})})]}),l.jsxs("div",{className:"univer-mb-5 univer-mt-3.5 univer-flex univer-justify-end",children:[l.jsx(E.Button,{onClick:W,className:"univer-mr-3",children:d("sheet.numfmt.cancel")}),l.jsx(E.Button,{variant:"primary",onClick:k,children:d("sheet.numfmt.confirm")})]})]})};var Le=Object.getOwnPropertyDescriptor,Fe=(e,t,r,n)=>{for(var i=n>1?void 0:n?Le(t,r):t,s=e.length-1,o;s>=0;s--)(o=e[s])&&(i=o(i)||i);return i},D=(e,t)=>(r,n)=>t(r,n,e);const se="SHEET_NUMFMT_PANEL";let R=class extends a.Disposable{constructor(t,r,n,i,s,o,d,c,u,f,m){super();G(this,"_previewPattern","");G(this,"_sidebarDisposable",null);this._sheetInterceptorService=t,this._themeService=r,this._univerInstanceService=n,this._commandService=i,this._selectionManagerService=s,this._renderManagerService=o,this._numfmtService=d,this._componentManager=c,this._sidebarService=u,this._localeService=f,this._sheetsNumfmtCellContentController=m,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener(),this._initNumfmtLocalChange()}_initNumfmtLocalChange(){this.disposeWithMe(O.merge(this._sheetsNumfmtCellContentController.locale$,this._localeService.currentLocale$).subscribe(()=>{this._forceUpdate()}))}openPanel(){var P;const t=this._sidebarService,r=this._selectionManagerService,n=this._commandService,i=this._univerInstanceService,s=this._numfmtService,o=this._localeService,c=(((P=r.getCurrentSelections())==null?void 0:P.map(I=>I.range))||[])[0];if(!c)return!1;const u=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),f=u.getActiveSheet();if(!f)return!1;const m=f.getCellRaw(c.startRow,c.startColumn),h=s.getValue(u.getUnitId(),f.getSheetId(),c.startRow,c.startColumn);let y="";h&&(y=h.pattern);const b=(m==null?void 0:m.t)===a.CellValueType.NUMBER?m.v:12345678,p={onChange:I=>{var M;if(I.type==="change")this._previewPattern=I.value,this._forceUpdate();else if(I.type==="confirm"){const x=((M=r.getCurrentSelections())==null?void 0:M.map(W=>W.range))||[],U={values:[]},k=v.getPatternType(I.value);x.forEach(W=>{a.Range.foreach(W,(ee,T)=>{U.values.push({row:ee,col:T,pattern:I.value,type:k})})}),n.executeCommand(v.SetNumfmtCommand.id,U),t.close()}else I.type==="cancel"&&t.close()},value:{defaultPattern:y,defaultValue:b,row:c.startRow,col:c.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(a.UniverInstanceType.UNIVER_SHEET).getUnitId());r==null||r.with(N.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.disposeWithMe(this._componentManager.register(se,$e))}_initRealTimeRenderingInterceptor(){const t=new O.Observable(n=>{this._commandService.onCommandExecuted(i=>{i.id===F.id&&n.next(!0),i.id===Y.id&&n.next(!1)})}),r=O.combineLatest([t,this._selectionManagerService.selectionMoveEnd$.pipe(B.map(n=>n?n.map(i=>i.range):[]))]);this.disposeWithMe(a.toDisposable(r.pipe(B.switchMap(([n,i])=>new O.Observable(s=>{const o=new a.DisposableCollection;return n&&i.length&&s.next({selectionRanges:i,disposableCollection:o}),()=>{o.dispose()}})),B.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:n,selectionRanges:i})=>{var o,d;const s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);this.openPanel(),n.add(this._sheetInterceptorService.intercept(g.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,effect:a.InterceptorEffectEnum.Value|a.InterceptorEffectEnum.Style,handler:(c,u,f)=>{var b;const{row:m,col:h}=u,y=f(c)||{};if(i.find(p=>p.startColumn<=h&&p.endColumn>=h&&p.startRow<=m&&p.endRow>=m)){const p=u.worksheet.getCellRaw(m,h),P=p==null?void 0:p.v,I=p==null?void 0:p.t;if(P==null||I!==a.CellValueType.NUMBER||this._previewPattern===null)return y;const M=v.getPatternPreviewIgnoreGeneral(this._previewPattern,P,this._sheetsNumfmtCellContentController.locale);if(M.color){const x=(b=this._themeService.getColorFromTheme(`${M.color}.500`))!=null?b:M.color;return{...y,v:M.result,t:a.CellValueType.STRING,s:{cl:{rgb:x}}}}return{...y,v:M.result,t:a.CellValueType.STRING}}return y}})),(d=(o=this._renderManagerService.getRenderById(s.getUnitId()))==null?void 0:o.mainComponent)==null||d.makeDirty()})))}_commandExecutedListener(){const t=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id];this.disposeWithMe(new O.Observable(r=>{const n=this._commandService.onCommandExecuted(i=>{if(t.includes(i.id)){const s=i.params;r.next(s.unitId)}});return()=>n.dispose()}).pipe(B.debounceTime(16)).subscribe(r=>this._forceUpdate(r)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(t=>{var r;t||((r=this._sidebarDisposable)==null||r.dispose(),this._sidebarDisposable=null)})}};R=Fe([D(0,a.Inject(g.SheetInterceptorService)),D(1,a.Inject(a.ThemeService)),D(2,a.IUniverInstanceService),D(3,a.ICommandService),D(4,a.Inject(g.SheetsSelectionsService)),D(5,j.IRenderManagerService),D(6,g.INumfmtService),D(7,a.Inject(_.ComponentManager)),D(8,_.ISidebarService),D(9,a.Inject(a.LocaleService)),D(10,a.Inject(v.SheetsNumfmtCellContentController))],R);var He=Object.getOwnPropertyDescriptor,Re=(e,t,r,n)=>{for(var i=n>1?void 0:n?He(t,r):t,s=e.length-1,o;s>=0;s--)(o=e[s])&&(i=o(i)||i);return i},A=(e,t)=>(r,n)=>t(r,n,e);const Ae=()=>{let e=[];return{add:(i,s,o,d,c)=>e.push({unitId:i,subUnitId:s,row:o,col:d,value:c}),getEffects:()=>e,clean:()=>{e=[]}}};let V=class extends a.Disposable{constructor(t,r,n,i,s){super();G(this,"_collectEffectMutation",Ae());this._sheetInterceptorService=t,this._numfmtService=r,this._univerInstanceService=n,this._injector=i,this._editorBridgeService=s,this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(a.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.BEFORE_CELL_EDIT,{handler:(t,r,n)=>{const i=r.row,s=r.col,o=this._numfmtService.getValue(r.unitId,r.subUnitId,i,s);if(o)switch(v.getPatternType(o.pattern)){case"scientific":case"currency":case"grouped":case"number":{const c=r.worksheet.getCellRaw(i,s);return(c==null?void 0:c.t)===a.CellValueType.NUMBER&&(c==null?void 0:c.v)!==void 0&&c.v!==null&&a.isRealNum(c.v)&&(c.v=me.stripErrorMargin(Number(c.v))),n&&n(c)}case"percent":case"date":case"time":case"datetime":default:return n&&n(t)}return n(t)}})))}_initInterceptorEditorEnd(){this.disposeWithMe(a.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.AFTER_CELL_EDIT,{handler:(t,r,n)=>{var u,f,m;if(!(t!=null&&t.v)&&!(t!=null&&t.p))return n(t);this._collectEffectMutation.clean();const i=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col),s=r.worksheet.getCellRaw(r.row,r.col);if(a.isTextFormat(i==null?void 0:i.pattern)||t.t===a.CellValueType.FORCE_STRING)return n(t);const o=(u=t.p)==null?void 0:u.body,d=(m=(f=t==null?void 0:t.p)==null?void 0:f.body)!=null&&m.dataStream?t.p.body.dataStream.replace(/\r\n$/,""):String(t.v),c=a.getNumfmtParseValueFilter(d);if(o)if(We(o)){const{dataStream:h}=o,y=h.replace(/\r\n$/,""),b=Number(y);if(Number.isNaN(b)&&!c)return n(t)}else return n(t);if(c){if(!c.z&&!(i!=null&&i.pattern)&&(s==null?void 0:s.t)!==a.CellValueType.STRING&&(s==null?void 0:s.t)!==a.CellValueType.FORCE_STRING&&a.willLoseNumericPrecision(d))return n({...t,p:void 0,v:d,t:a.CellValueType.FORCE_STRING});c.z&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:c.z});const h=Number(c.v);return n({...t,p:void 0,v:h,t:a.CellValueType.NUMBER})}return n(t)}})))}_initInterceptorCommands(){const t=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(r){var n;switch(r.id){case g.SetRangeValuesCommand.id:{const i=t._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=i.getUnitId(),o=(n=i.getActiveSheet())==null?void 0:n.getSheetId();if(!o)return{redos:[],undos:[]};const d=t._collectEffectMutation.getEffects();if(t._collectEffectMutation.clean(),!d.length)return{redos:[],undos:[]};const c=d.filter(h=>{var y;return!!((y=h.value)!=null&&y.pattern)}).map(h=>({row:h.row,col:h.col,pattern:h.value.pattern})),u=d.filter(h=>{var y;return!((y=h.value)!=null&&y.pattern)}).map(h=>({startRow:h.row,endColumn:h.col,startColumn:h.col,endRow:h.row})),f=[],m=[];if(c.length){const h={id:g.SetNumfmtMutation.id,params:g.transformCellsToRange(s,o,c)};f.push(h),m.push(...g.factorySetNumfmtUndoMutation(t._injector,h.params))}if(u.length){const h={id:g.RemoveNumfmtMutation.id,params:{unitId:s,subUnitId:o,ranges:u}};f.push(h),m.push(...g.factoryRemoveNumfmtUndoMutation(t._injector,h.params))}return{redos:f,undos:m.reverse()}}}return{redos:[],undos:[]}}}))}};V=Re([A(0,a.Inject(g.SheetInterceptorService)),A(1,a.Inject(g.INumfmtService)),A(2,a.Inject(a.IUniverInstanceService)),A(3,a.Inject(a.Injector)),A(4,a.Optional(N.IEditorBridgeService))],V);function We(e){const{textRuns:t=[],paragraphs:r=[],customRanges:n,customBlocks:i=[]}=e,s=["va"];return!(t.some(o=>!!(o.ts&&Object.keys(o.ts).some(c=>s.includes(c))))||r.some(o=>o.bullet)||r.length>=2||n!=null&&n.length||i.length>0)}const oe=e=>[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:a.DEFAULT_TEXT_FORMAT_EXCEL},"|",{label:"sheet.numfmt.number",pattern:"0"},{label:"sheet.numfmt.percent",pattern:"0.00%"},{label:"sheet.numfmt.scientific",pattern:"0.00E+00"},"|",{label:"sheet.numfmt.accounting",pattern:`"${e}" #,##0.00_);[Red]("${e}"#,##0.00)`},{label:"sheet.numfmt.financialValue",pattern:"#,##0.00;[Red]#,##0.00"},{label:"sheet.numfmt.currency",pattern:`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`},{label:"sheet.numfmt.roundingCurrency",pattern:`"${e}"#,##0;[Red]"${e}"#,##0`},"|",{label:"sheet.numfmt.date",pattern:"yyyy-mm-dd;@"},{label:"sheet.numfmt.time",pattern:'am/pm h":"mm":"ss'},{label:"sheet.numfmt.dateTime",pattern:"yyyy-m-d am/pm h:mm"},{label:"sheet.numfmt.timeDuration",pattern:"h:mm:ss"},"|",{label:"sheet.numfmt.moreFmt",pattern:""}],Be=e=>({icon:new O.Observable(t=>{const r=e.get(a.LocaleService);return t.next(v.getCurrencySymbolIconByLocale(r.getCurrentLocale()).icon),r.localeChanged$.subscribe(()=>{t.next(v.getCurrencySymbolIconByLocale(r.getCurrentLocale()).icon)})}),id:v.SetCurrencyCommand.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:N.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Ve=e=>({icon:"AddDigitsIcon",id:v.AddDecimalCommand.id,title:"sheet.numfmt.addDecimal",tooltip:"sheet.numfmt.addDecimal",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:N.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),qe=e=>({icon:"ReduceDigitsIcon",id:v.SubtractDecimalCommand.id,title:"sheet.numfmt.subtractDecimal",tooltip:"sheet.numfmt.subtractDecimal",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:N.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Ge=e=>({icon:"PercentIcon",id:v.SetPercentCommand.id,title:"sheet.numfmt.percent",tooltip:"sheet.numfmt.percent",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:N.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Ke=e=>{const t=e.get(a.IUniverInstanceService),r=e.get(a.ICommandService),n=e.get(a.LocaleService),i=e.get(g.SheetsSelectionsService),s=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id],o=N.deriveStateFromActiveSheet$(t,"",({workbook:d,worksheet:c})=>new O.Observable(u=>O.merge(i.selectionMoveEnd$,a.fromCallback(r.onCommandExecuted.bind(r)).pipe(O.filter(([f])=>s.includes(f.id)))).subscribe(()=>{var m,h;const f=i.getCurrentSelections();if(f&&f[0]){const y=f[0].range,b=y.startRow,p=y.startColumn,P=(h=d.getStyles().get((m=c.getCell(b,p))==null?void 0:m.s))==null?void 0:h.n,I=P==null?void 0:P.pattern,M=v.getCurrencySymbolByLocale(n.getCurrentLocale());let x=n.t("sheet.numfmt.general");if(a.isDefaultFormat(I)){u.next(x);return}if(I){const U=oe(M).filter(k=>typeof k=="object"&&k.pattern).find(k=>a.isPatternEqualWithoutDecimal(I,k.pattern));U&&typeof U=="object"&&U.pattern?x=n.t(U.label):x=n.t("sheet.numfmt.moreFmt")}u.next(x)}})));return{label:ce,id:F.id,tooltip:"sheet.numfmt.title",type:_.MenuItemType.SELECTOR,slot:!0,selections:[{label:{name:le,hoverable:!1,selectable:!1}}],value$:o,hidden$:_.getMenuHiddenObservable(e,a.UniverInstanceType.UNIVER_SHEET),disabled$:N.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetSetCellStylePermission,g.WorksheetEditPermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}},ce="sheet.numfmt.moreNumfmtType",le="sheet.numfmt.moreNumfmtType.options",Ze=e=>{const{value:t}=e,r=_.useDependency(a.LocaleService),n=t!=null?t:r.t("sheet.numfmt.general");return l.jsx("span",{className:"univer-text-sm",children:n})},Ye=()=>{const e=_.useDependency(a.ICommandService),t=_.useDependency(a.LocaleService),r=_.useDependency(_.ILayoutService),n=_.useDependency(v.SheetsNumfmtCellContentController),i=_.useDependency(g.SheetsSelectionsService),s=u=>{const f=i.getCurrentLastSelection();if(!f)return;const m=f.range,h=[];a.Range.foreach(m,(y,b)=>{u?h.push({row:y,col:b,pattern:u,type:v.getPatternType(u)}):h.push({row:y,col:b})}),e.executeCommand(v.SetNumfmtCommand.id,{values:h}),r.focus()},o=S.useMemo(()=>{const u=v.localeCurrencySymbolMap.get(t.getCurrentLocale());return oe(u)},[t]),d=u=>{if(u===0)s(null);else if(u===o.length-1)e.executeCommand(F.id),r.focus();else{const f=o[u];f.pattern&&s(f.pattern)}},c=1220;return l.jsx("div",{className:"univer-grid univer-gap-1 univer-p-1.5",children:o.map((u,f)=>u==="|"?l.jsx(E.Separator,{},f):l.jsxs("div",{className:"univer-flex univer-h-7 univer-items-center univer-justify-between univer-gap-6 univer-rounded univer-px-2 univer-text-sm hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",onClick:()=>{d(f)},children:[l.jsx("span",{children:t.t(u.label)}),l.jsx("span",{className:"univer-text-xs univer-text-gray-500",children:u.pattern?v.getPatternPreview(u.pattern||"",c,n.locale).result.trim():""})]},f))})},ze={[_.RibbonDataGroup.FORMULAS]:{[v.SetCurrencyCommand.id]:{order:0,menuItemFactory:Be},[v.AddDecimalCommand.id]:{order:1,menuItemFactory:Ve},[v.SubtractDecimalCommand.id]:{order:2,menuItemFactory:qe},[v.SetPercentCommand.id]:{order:3,menuItemFactory:Ge},[F.id]:{order:4,menuItemFactory:Ke}}};var Xe=Object.getOwnPropertyDescriptor,Je=(e,t,r,n)=>{for(var i=n>1?void 0:n?Xe(t,r):t,s=e.length-1,o;s>=0;s--)(o=e[s])&&(i=o(i)||i);return i},ue=(e,t)=>(r,n)=>t(r,n,e);let q=class extends a.Disposable{constructor(e,t){super(),this._componentManager=e,this._menuManagerService=t,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(ze),[[ce,Ze],[le,Ye]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};q=Je([ue(0,a.Inject(_.ComponentManager)),ue(1,_.IMenuManagerService)],q);var Qe=Object.defineProperty,et=Object.getOwnPropertyDescriptor,tt=(e,t,r)=>t in e?Qe(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,nt=(e,t,r,n)=>{for(var i=n>1?void 0:n?et(t,r):t,s=e.length-1,o;s>=0;s--)(o=e[s])&&(i=o(i)||i);return i},Q=(e,t)=>(r,n)=>t(r,n,e),de=(e,t,r)=>tt(e,typeof t!="symbol"?t+"":t,r);const rt="SHEET_NUMFMT_UI_PLUGIN";C.UniverSheetsNumfmtUIPlugin=class extends a.Plugin{constructor(t=te,r,n,i){super(),this._config=t,this._injector=r,this._configService=n,this._renderManagerService=i;const{menu:s,...o}=a.merge({},te,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig("sheets-numfmt-ui.config",o)}onStarting(){a.registerDependencies(this._injector,[[R],[V],[H],[q]])}onRendered(){this._registerRenderModules(),a.touchDependencies(this._injector,[[R],[V],[q]])}_registerRenderModules(){[[Z]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,r))})}},de(C.UniverSheetsNumfmtUIPlugin,"pluginName",rt),de(C.UniverSheetsNumfmtUIPlugin,"type",a.UniverInstanceType.UNIVER_SHEET),C.UniverSheetsNumfmtUIPlugin=nt([a.DependentOn(N.UniverSheetsUIPlugin,v.UniverSheetsNumfmtPlugin),Q(1,a.Inject(a.Injector)),Q(2,a.IConfigService),Q(3,j.IRenderManagerService)],C.UniverSheetsNumfmtUIPlugin),Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-numfmt-ui",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.8-nightly.202509200616",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "UniverSheet numfmt plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -54,15 +54,15 @@
|
|
|
54
54
|
"rxjs": ">=7.0.0"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@univerjs/icons": "^0.4.
|
|
58
|
-
"@univerjs/core": "0.10.
|
|
59
|
-
"@univerjs/design": "0.10.
|
|
60
|
-
"@univerjs/
|
|
61
|
-
"@univerjs/
|
|
62
|
-
"@univerjs/
|
|
63
|
-
"@univerjs/
|
|
64
|
-
"@univerjs/ui": "0.10.
|
|
65
|
-
"@univerjs/sheets-
|
|
57
|
+
"@univerjs/icons": "^0.4.8",
|
|
58
|
+
"@univerjs/core": "0.10.8-nightly.202509200616",
|
|
59
|
+
"@univerjs/design": "0.10.8-nightly.202509200616",
|
|
60
|
+
"@univerjs/engine-render": "0.10.8-nightly.202509200616",
|
|
61
|
+
"@univerjs/sheets": "0.10.8-nightly.202509200616",
|
|
62
|
+
"@univerjs/sheets-numfmt": "0.10.8-nightly.202509200616",
|
|
63
|
+
"@univerjs/engine-formula": "0.10.8-nightly.202509200616",
|
|
64
|
+
"@univerjs/ui": "0.10.8-nightly.202509200616",
|
|
65
|
+
"@univerjs/sheets-ui": "0.10.8-nightly.202509200616"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
68
|
"postcss": "^8.5.6",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"typescript": "^5.9.2",
|
|
73
73
|
"vite": "^7.1.4",
|
|
74
74
|
"vitest": "^3.2.4",
|
|
75
|
-
"@univerjs-infra/shared": "0.10.
|
|
75
|
+
"@univerjs-infra/shared": "0.10.8"
|
|
76
76
|
},
|
|
77
77
|
"scripts": {
|
|
78
78
|
"test": "vitest run",
|
package/LICENSE
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|