@univerjs/sheets-numfmt-ui 0.8.0 → 0.8.1-nightly.202506131607
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 +2 -2
- package/lib/index.js +2 -2
- package/lib/umd/index.js +1 -1
- package/package.json +12 -12
- package/LICENSE +0 -176
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var ve=Object.defineProperty;var fe=(e,t,r)=>t in e?ve(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var H=(e,t,r)=>fe(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),se=require("@univerjs/engine-render"),d=require("@univerjs/sheets-numfmt"),P=require("@univerjs/sheets-ui"),q=require("@univerjs/engine-numfmt"),g=require("@univerjs/sheets"),_=require("@univerjs/ui"),D=require("rxjs"),A=require("rxjs/operators"),l=require("react/jsx-runtime"),y=require("react"),E=require("@univerjs/design"),te={};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},O=(e,t)=>(r,n)=>t(r,n,e);const Z="SHEET_NUMFMT_ALERT";let Q=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(D.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,u=n.subUnitId;let o;const h=s.getCell(n.row,n.col);if(h!=null&&h.s){const f=i.getStyles().get(h.s);f!=null&&f.n&&(o=f.n)}if(o||(o=this._numfmtService.getValue(c,u,n.row,n.col)),!o){this._hideAlert();return}if(q.isTextFormat(o.pattern)&&(h!=null&&h.v)&&a.isRealNum(h.v)){if((t=this._configService.getConfig(d.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY))!=null&&t.disableTextFormatAlert)return;const f=this._cellAlertManagerService.currentAlert.get(Z),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:P.CellAlertType.ERROR,title:this._localeService.t("info.error"),message:this._localeService.t("info.forceStringInfo"),location:n,width:200,height:74,key:Z});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(Z)}};Q=ge([O(1,a.Inject(P.HoverManagerService)),O(2,a.Inject(P.CellAlertManagerService)),O(3,a.Inject(a.LocaleService)),O(4,_.IZenZoneService),O(5,a.Inject(g.INumfmtService)),O(6,a.IConfigService)],Q);const Y={id:"sheet.operation.close.numfmt.panel",type:a.CommandType.OPERATION,handler:()=>!0},$={id:"sheet.operation.open.numfmt.panel",type:a.CommandType.OPERATION,handler:e=>(e.get(F).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 ee=y.createContext([]);let L=class{constructor(e){this._localStorageService=e}_getKey(e){return`userHabitController_${e}`}async addHabit(e,t){const r=this._getKey(e);return this._localStorageService.getItem(r).then(n=>{n||this._localStorageService.setItem(r,t)})}markHabit(e,t){const r=this._getKey(e);this._localStorageService.getItem(r).then(n=>{if(n){const i=n.findIndex(s=>s===t);i>-1&&n.splice(i,1),n.unshift(t),this._localStorageService.setItem(r,n)}})}async getHabit(e,t){const r=this._getKey(e),n=await this._localStorageService.getItem(r);if(t&&n){const i=n.map((s,c,u)=>{const o=u.length;return{value:s,priority:o-c}});return t.sort((s,c)=>{var h,f;const u=((h=i.find(m=>m.value===s))==null?void 0:h.priority)||-1;return(((f=i.find(m=>m.value===c))==null?void 0:f.priority)||-1)-u})}return n||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};L=ye([_e(0,a.Inject(a.ILocalStorageService))],L);const ne="numfmtCurrency",Ce=e=>{const t=_.useDependency(L),[r,n]=y.useState(d.currencySymbols);return y.useEffect(()=>{t.addHabit("numfmtCurrency",[]).then(()=>{t.getHabit(ne,[...d.currencySymbols]).then(s=>{n(s),e&&e(s)})})},[]),{userHabitCurrency:r,mark:s=>{t.markHabit(ne,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=>!!d.getCurrencyType(e)&&e.startsWith("_("),xe=e=>{const{defaultPattern:t,action:r,onChange:n}=e,[i,s]=y.useState(()=>d.getDecimalFromPattern(t||"",2)),c=y.useContext(ee),[u,o]=y.useState(()=>d.getCurrencyType(t)||c[0]),h=y.useMemo(()=>c.map(C=>({label:C,value:C})),[]),m=_.useDependency(a.LocaleService).t;r.current=()=>d.setPatternDecimal(`_("${u}"* #,##0${i>0?".0":""}_)`,i);const p=C=>{o(C),n(d.setPatternDecimal(`_("${C}"* #,##0${i>0?".0":""}_)`,i))},S=C=>{const v=C||0;s(v),n(d.setPatternDecimal(`_("${u}"* #,##0${v>0?".0":""}_)`,v))};return l.jsxs("div",{children:[l.jsxs("div",{className:"univer-mt-4 univer-flex univer-justify-between",children:[l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2 univer-w-32",children:l.jsx(E.InputNumber,{value:i,step:1,precision:0,max:20,min:0,onChange:S})})]}),l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.currencyType")}),l.jsx("div",{className:"univer-mt-2 univer-w-36",children:l.jsx(E.Select,{options:h,value:u,onChange:p})})]})]}),l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.accountingDes")})]})},Ne=e=>!!d.getCurrencyType(e)&&!e.startsWith("_("),Ee=e=>{const r=_.useDependency(a.LocaleService).t,n=y.useContext(ee),[i,s]=y.useState(()=>d.getCurrencyType(e.defaultPattern)||n[0]),[c,u]=y.useState(()=>d.getDecimalFromPattern(e.defaultPattern||"",2)),[o,h]=y.useState(()=>{var b;const v=d.getCurrencyFormatOptions(i);return((b=v.find(N=>a.isPatternEqualWithoutDecimal(N.value,e.defaultPattern)))==null?void 0:b.value)||v[0].value}),f=y.useMemo(()=>d.getCurrencyFormatOptions(i),[i]),m=y.useMemo(()=>n.map(v=>({label:v,value:v})),[n]);e.action.current=()=>d.setPatternDecimal(o,c);const p=v=>{if(v===void 0)return;s(v);const x=d.getCurrencyFormatOptions(v)[0].value;h(x),e.onChange(d.setPatternDecimal(x,c))},S=v=>{v!==void 0&&(h(v),e.onChange(d.setPatternDecimal(v,c)))},C=v=>{u(v||0),e.onChange(d.setPatternDecimal(o,v||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: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(E.Select,{value:i,options:m,onChange:p})})]})]}),l.jsx("div",{className:"univer-mt-4 label",children:r("sheet.numfmt.negType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(E.SelectList,{value:o,options:f,onChange:S})}),l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:r("sheet.numfmt.currencyDes")})]})};var T=function(){return T=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},T.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},ce=y.forwardRef(function(e,t){var r=e.icon,n=e.id,i=e.className,s=e.extend,c=Te(e,["icon","id","className","extend"]),u="univerjs-icon univerjs-icon-".concat(n," ").concat(i||"").trim(),o=y.useRef("_".concat(je()));return ae(r,"".concat(n),{defIds:r.defIds,idSuffix:o.current},T({ref:t,className:u},c),s)});function ae(e,t,r,n,i){return y.createElement(e.tag,T(T({key:t},Pe(e,r,i)),n),(Me(e,r).children||[]).map(function(s,c){return ae(s,"".concat(t,"-").concat(e.tag,"-").concat(c),r,void 0,i)}))}function Pe(e,t,r){var n=T({},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],u=s[1];c==="mask"&&typeof u=="string"&&(n[c]=u.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],u=s[1];typeof u=="string"&&(n[c]=u.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)?T(T({},e),{children:e.children.map(function(i){return typeof i.attrs.id=="string"&&n&&n.includes(i.attrs.id)?T(T({},i),{attrs:T(T({},i.attrs),{id:i.attrs.id+t.idSuffix})}):i})}):e}function je(){return Math.random().toString(36).substring(2,8)}ce.displayName="UniverIcon";var De={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"}}]},oe=y.forwardRef(function(e,t){return y.createElement(ce,Object.assign({},e,{id:"check-mark-icon",ref:t,icon:De}))});oe.displayName="CheckMarkIcon";const z="customFormat",X="numfmt_custom_pattern";function Re(e){const{defaultPattern:t,action:r,onChange:n}=e,i=_.useDependency(L),s=_.useDependency(a.ILocalStorageService),c=_.useDependency(a.LocaleService),[u,o]=y.useState(t);r.current=()=>(i.markHabit(z,u),s.getItem(X).then((S=[])=>{const C=[...new Set([u,...S||[]])].splice(0,10).filter(v=>!!v);s.setItem(X,C)}),u);const[h,f]=y.useState([]);y.useEffect(()=>{s.getItem(X).then(S=>{const C=[...d.CURRENCYFORMAT.map(v=>v.suffix("$")),...d.DATEFMTLISG.map(v=>v.suffix),...d.NUMBERFORMAT.map(v=>v.suffix)];C.push(...S||[]),i.addHabit(z,[]).finally(()=>{i.getHabit(z,C).then(v=>{f([...new Set(v)])})})})},[]);const m=S=>{o(S),n(S)},p=()=>{n(u)};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(E.Input,{placeholder:c.t("sheet.numfmt.customFormat"),onBlur:p,value:u,onChange:o,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:h.map(S=>l.jsxs("div",{onClick:()=>m(S),className:"univer-flex univer-cursor-pointer univer-items-center univer-gap-1.5 univer-py-1.5 univer-text-sm",children:[l.jsx("div",{className:"univer-flex univer-w-4 univer-items-center univer-text-primary-600",children:u===S&&l.jsx(oe,{})}),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 we=e=>{const t=a.numfmt.getFormatInfo(e);return d.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(d.getDateFormatOptions,[]),i=_.useDependency(a.LocaleService),[s,c]=y.useState(()=>{if(r){const o=n.find(h=>h.value===r);if(o)return o.value}return n[0].value});e.action.current=()=>s;const u=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(E.SelectList,{value:s,options:n,onChange:u})}),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=>d.getNumberFormatOptions().some(t=>a.isPatternEqualWithoutDecimal(t.value,e));function Le(e){const t=_.useDependency(a.LocaleService),r=y.useMemo(d.getNumberFormatOptions,[]),[n,i]=y.useState(()=>d.getDecimalFromPattern(e.defaultPattern||"",0)),[s,c]=y.useState(()=>{const m=r.find(p=>a.isPatternEqualWithoutDecimal(p.value,e.defaultPattern||""));return(m==null?void 0:m.value)||r[0].value}),u=y.useMemo(()=>d.setPatternDecimal(s,Number(n||0)),[s,n]),o=y.useMemo(()=>!d.isPatternHasDecimal(s),[s]),h=m=>{i(m||0),e.onChange(d.setPatternDecimal(s,Number(m||0)))},f=m=>{m!==void 0&&(i(d.getDecimalFromPattern(m,0)),c(m),e.onChange(m))};return e.action.current=()=>u,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:o,value:n,max:20,min:0,onChange:h})}),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 Fe=e=>{const{defaultValue:t,defaultPattern:r,row:n,col:i}=e.value,s=_.useDependency(a.LocaleService),c=y.useRef(()=>""),u=s.t,o=be(),h=y.useMemo(()=>[{label:"sheet.numfmt.general",component:ke},{label:"sheet.numfmt.accounting",component:xe},{label:"sheet.numfmt.currency",component:Ee},{label:"sheet.numfmt.date",component:Oe},{label:"sheet.numfmt.thousandthPercentile",component:Le},{label:"sheet.numfmt.customFormat",component:Re}].map(I=>({...I,label:u(I.label)})),[]),[f,m]=y.useState(b),[p,S]=y.useState(()=>`${n}_${i}`),{mark:C,userHabitCurrency:v}=Ce(()=>S(`${n}_${i}_userCurrency'`)),x=y.useMemo(()=>{var I;return(I=h.find(w=>w.label===f))==null?void 0:I.component},[f]);function b(){return[Ue,Ie,Ne,we,$e].reduce((w,de,he)=>w||(de(r)?h[he].label:""),"")||h[0].label}const N=h.map(I=>({label:I.label,value:I.label})),j=I=>{m(I),o(()=>e.onChange({type:"change",value:c.current()||""}))},R=y.useCallback(I=>{e.onChange({type:"change",value:I})},[]),G=()=>{const I=c.current()||"",w=d.getCurrencyType(I);w&&C(w),e.onChange({type:"confirm",value:I})},U=()=>{e.onChange({type:"cancel",value:""})},K={onChange:R,defaultValue:t,defaultPattern:r,action:c};return y.useEffect(()=>{m(b()),S(`${n}_${i}`)},[n,i]),l.jsxs("div",{className:E.clsx("univer-flex univer-h-full univer-flex-col univer-justify-between univer-overflow-y-auto univer-pb-5",E.scrollbarClassName),children:[l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-3.5 univer-text-sm univer-text-gray-400",children:u("sheet.numfmt.numfmtType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(E.Select,{className:"univer-w-full",value:f,options:N,onChange:j})}),l.jsx("div",{children:x&&l.jsx(ee.Provider,{value:v,children:y.createElement(x,{...K,key:p})})})]}),l.jsxs("div",{className:"univer-mb-5 univer-mt-3.5 univer-flex univer-justify-end",children:[l.jsx(E.Button,{onClick:U,className:"univer-mr-3",children:u("sheet.numfmt.cancel")}),l.jsx(E.Button,{variant:"primary",onClick:G,children:u("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 re="SHEET_NUMFMT_PANEL";let F=class extends a.Disposable{constructor(t,r,n,i,s,c,u,o,h,f,m){super();H(this,"_previewPattern","");H(this,"_sidebarDisposable",null);this._sheetInterceptorService=t,this._themeService=r,this._univerInstanceService=n,this._commandService=i,this._selectionManagerService=s,this._renderManagerService=c,this._numfmtService=u,this._componentManager=o,this._sidebarService=h,this._localeService=f,this._sheetsNumfmtCellContentController=m,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener(),this._initNumfmtLocalChange()}_initNumfmtLocalChange(){this.disposeWithMe(D.merge(this._sheetsNumfmtCellContentController.local$,this._localeService.currentLocale$).subscribe(()=>{this._forceUpdate()}))}openPanel(){var 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 h=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),f=h.getActiveSheet();if(!f)return!1;const m=f.getCellRaw(o.startRow,o.startColumn),p=s.getValue(h.getUnitId(),f.getSheetId(),o.startRow,o.startColumn);let S="";p&&(S=p.pattern);const C=(m==null?void 0:m.t)===a.CellValueType.NUMBER?m.v:12345678,v={onChange:b=>{var N;if(b.type==="change")this._previewPattern=b.value,this._forceUpdate();else if(b.type==="confirm"){const j=((N=r.getCurrentSelections())==null?void 0:N.map(U=>U.range))||[],R={values:[]},G=d.getPatternType(b.value);j.forEach(U=>{a.Range.foreach(U,(K,I)=>{R.values.push({row:K,col:I,pattern:b.value,type:G})})}),n.executeCommand(d.SetNumfmtCommand.id,R),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:re,...v},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(P.SheetSkeletonManagerService).reCalculate(),(n=r==null?void 0:r.mainComponent)==null||n.makeDirty()}_initCommands(){[$,Y].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initPanel(){this.disposeWithMe(this._componentManager.register(re,Fe))}_initRealTimeRenderingInterceptor(){const t=new D.Observable(n=>{this._commandService.onCommandExecuted(i=>{i.id===$.id&&n.next(!0),i.id===Y.id&&n.next(!1)})}),r=D.combineLatest([t,this._selectionManagerService.selectionMoveEnd$.pipe(A.map(n=>n?n.map(i=>i.range):[]))]);this.disposeWithMe(a.toDisposable(r.pipe(A.switchMap(([n,i])=>new D.Observable(s=>{const c=new a.DisposableCollection;return n&&i.length&&s.next({selectionRanges:i,disposableCollection:c}),()=>{c.dispose()}})),A.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:n,selectionRanges:i})=>{var c,u;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,h,f)=>{var C;const{row:m,col:p}=h,S=f(o)||{};if(i.find(v=>v.startColumn<=p&&v.endColumn>=p&&v.startRow<=m&&v.endRow>=m)){const v=h.worksheet.getCellRaw(m,p),x=v==null?void 0:v.v,b=v==null?void 0:v.t;if(x==null||b!==a.CellValueType.NUMBER||this._previewPattern===null)return S;const N=d.getPatternPreviewIgnoreGeneral(this._previewPattern,x,this._sheetsNumfmtCellContentController.local);if(N.color){const j=(C=this._themeService.getColorFromTheme(`${N.color}.500`))!=null?C:N.color;return{...S,v:N.result,t:a.CellValueType.STRING,s:{cl:{rgb:j}}}}return{...S,v:N.result,t:a.CellValueType.STRING}}return S}})),(u=(c=this._renderManagerService.getRenderById(s.getUnitId()))==null?void 0:c.mainComponent)==null||u.makeDirty()})))}_commandExecutedListener(){const t=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id];this.disposeWithMe(new D.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(A.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)})}};F=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,se.IRenderManagerService),M(6,g.INumfmtService),M(7,a.Inject(_.ComponentManager)),M(8,_.ISidebarService),M(9,a.Inject(a.LocaleService)),M(10,a.Inject(d.SheetsNumfmtCellContentController))],F);var We=Object.getOwnPropertyDescriptor,Ve=(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},k=(e,t)=>(r,n)=>t(r,n,e);const Be=()=>{let e=[];return{add:(i,s,c,u,o)=>e.push({unitId:i,subUnitId:s,row:c,col:u,value:o}),getEffects:()=>e,clean:()=>{e=[]}}};let V=class extends a.Disposable{constructor(t,r,n,i,s){super();H(this,"_collectEffectMutation",Be());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(d.getPatternType(c.pattern)){case"scientific":case"currency":case"grouped":case"number":{const o=r.worksheet.getCellRaw(i,s);return 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 o,h,f;this._collectEffectMutation.clean();const i=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col);if(!(t!=null&&t.v)&&!(t!=null&&t.p)||q.isTextFormat(i==null?void 0:i.pattern)||t.t===a.CellValueType.FORCE_STRING)return n(t);const s=(o=t.p)==null?void 0:o.body,c=(f=(h=t==null?void 0:t.p)==null?void 0:h.body)!=null&&f.dataStream?t.p.body.dataStream.replace(/\r\n$/,""):String(t.v),u=a.numfmt.parseDate(c)||a.numfmt.parseTime(c)||a.numfmt.parseNumber(c);if(s)if(qe(s)){const{dataStream:m}=s,p=m.replace(/\r\n$/,""),S=Number(p);if(Number.isNaN(S)&&!u)return n(t)}else return n(t);if(u){if(!u.z&&a.willLoseNumericPrecision(c))return n({...t,p:void 0,v:c,t:a.CellValueType.FORCE_STRING});u.z&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:u.z});const m=Number(u.v);return n({...t,p:void 0,v:m,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 u=t._collectEffectMutation.getEffects();if(t._collectEffectMutation.clean(),!u.length)return{redos:[],undos:[]};const o=u.filter(p=>{var S;return!!((S=p.value)!=null&&S.pattern)}).map(p=>({row:p.row,col:p.col,pattern:p.value.pattern})),h=u.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})),f=[],m=[];if(o.length){const p={id:g.SetNumfmtMutation.id,params:g.transformCellsToRange(s,c,o)};f.push(p),m.push(...g.factorySetNumfmtUndoMutation(t._injector,p.params))}if(h.length){const p={id:g.RemoveNumfmtMutation.id,params:{unitId:s,subUnitId:c,ranges:h}};f.push(p),m.push(...g.factoryRemoveNumfmtUndoMutation(t._injector,p.params))}return{redos:f,undos:m.reverse()}}}return{redos:[],undos:[]}}}))}};V=Ve([k(0,a.Inject(g.SheetInterceptorService)),k(1,a.Inject(g.INumfmtService)),k(2,a.Inject(a.IUniverInstanceService)),k(3,a.Inject(a.Injector)),k(4,a.Optional(P.IEditorBridgeService))],V);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 W=[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:q.DEFAULT_TEXT_FORMAT_EXCEL},"|",{label:"sheet.numfmt.number",pattern:"0"},{label:"sheet.numfmt.percent",pattern:"0.00%"},{label:"sheet.numfmt.scientific",pattern:"0.00E+00"},"|",{label:"sheet.numfmt.accounting",pattern:'"¥" #,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.financialValue",pattern:"#,##0.00;[Red]#,##0.00"},{label:"sheet.numfmt.currency",pattern:'"¥"#,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.roundingCurrency",pattern:'"¥"#,##0;[Red]"¥"#,##0'},"|",{label:"sheet.numfmt.date",pattern:"yyyy-mm-dd;@"},{label:"sheet.numfmt.time",pattern:'am/pm h":"mm":"ss'},{label:"sheet.numfmt.dateTime",pattern:"yyyy-m-d am/pm h:mm"},{label:"sheet.numfmt.timeDuration",pattern:"h:mm:ss"},"|",{label:"sheet.numfmt.moreFmt",pattern:""}],Ge=e=>({icon:new D.Observable(t=>{var s;const r=e.get(d.MenuCurrencyService);function n(c){var o;return(o={[d.countryCurrencyMap.US]:"DollarIcon",[d.countryCurrencyMap.RU]:"RoubleIcon",[d.countryCurrencyMap.CN]:"RmbIcon",[d.countryCurrencyMap.AT]:"EuroIcon"}[c])!=null?o:"DollarIcon"}const i=(s=d.countryCurrencyMap[r.getCurrencySymbol()])!=null?s:"$";return t.next(n(i)),r.currencySymbol$.subscribe(c=>{var o;const u=(o=d.countryCurrencyMap[c])!=null?o:"$";t.next(n(u))})}),id:d.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:d.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:d.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:d.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:u,worksheet:o})=>new D.Observable(h=>D.merge(i.selectionMoveEnd$,a.fromCallback(r.onCommandExecuted.bind(r)).pipe(D.filter(([f])=>s.includes(f.id)))).subscribe(()=>{var m,p;const f=i.getCurrentSelections();if(f&&f[0]){const S=f[0].range,C=S.startRow,v=S.startColumn,x=(p=u.getStyles().get((m=o.getCell(C,v))==null?void 0:m.s))==null?void 0:p.n,b=x==null?void 0:x.pattern;let N=n.t("sheet.numfmt.general");if(q.isDefaultFormat(b)){h.next(N);return}if(b){const j=W.filter(R=>typeof R=="object"&&R.pattern).find(R=>a.isPatternEqualWithoutDecimal(b,R.pattern));j&&typeof j=="object"&&j.pattern?N=n.t(j.label):N=n.t("sheet.numfmt.moreFmt")}h.next(N)}})));return{label:le,id:$.id,tooltip:"sheet.numfmt.title",type:_.MenuItemType.SELECTOR,slot:!0,selections:[{label:{name:ue,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]})}},le="sheet.numfmt.moreNumfmtType",ue="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(d.SheetsNumfmtCellContentController),i=_.useDependency(g.SheetsSelectionsService),s=o=>{const h=i.getCurrentLastSelection();if(!h)return;const f=h.range,m=[];a.Range.foreach(f,(p,S)=>{o?m.push({row:p,col:S,pattern:o,type:d.getPatternType(o)}):m.push({row:p,col:S})}),e.executeCommand(d.SetNumfmtCommand.id,{values:m}),r.focus()},c=o=>{if(o===0)s(null);else if(o===W.length-1)e.executeCommand($.id),r.focus();else{const h=W[o];h.pattern&&s(h.pattern)}},u=1220;return l.jsx("div",{className:"univer-grid univer-gap-1 univer-p-1.5",children:W.map((o,h)=>o==="|"?l.jsx(E.Separator,{},h):l.jsxs("div",{className:"univer-flex univer-h-7 univer-items-center univer-justify-between univer-gap-6 univer-rounded univer-px-2 univer-text-sm dark:hover:!univer-bg-gray-700 hover:univer-bg-gray-100",onClick:()=>{c(h)},children:[l.jsx("span",{children:t.t(o.label)}),l.jsx("span",{className:"univer-text-xs univer-text-gray-500",children:o.pattern?d.getPatternPreview(o.pattern||"",u,n.local).result.trim():""})]},h))})},Qe={[_.RibbonDataGroup.FORMULAS]:{[d.SetCurrencyCommand.id]:{order:0,menuItemFactory:Ge},[d.AddDecimalCommand.id]:{order:1,menuItemFactory:Ke},[d.SubtractDecimalCommand.id]:{order:2,menuItemFactory:Ze},[d.SetPercentCommand.id]:{order:3,menuItemFactory:Ye},[$.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},ie=(e,t)=>(r,n)=>t(r,n,e);let B=class extends a.Disposable{constructor(e,t){super(),this._componentManager=e,this._menuManagerService=t,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(Qe),[[le,Xe],[ue,Je]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};B=tt([ie(0,a.Inject(_.ComponentManager)),ie(1,_.IMenuManagerService)],B);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},J=(e,t)=>(r,n)=>t(r,n,e),me=(e,t,r)=>it(e,typeof t!="symbol"?t+"":t,r);const ct="SHEET_NUMFMT_UI_PLUGIN";exports.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,...c}=a.merge({},te,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig("sheets-numfmt-ui.config",c)}onStarting(){a.registerDependencies(this._injector,[[F],[V],[L],[B]])}onRendered(){this._registerRenderModules(),a.touchDependencies(this._injector,[[F],[V],[B]])}_registerRenderModules(){[[Q]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,r))})}};me(exports.UniverSheetsNumfmtUIPlugin,"pluginName",ct);me(exports.UniverSheetsNumfmtUIPlugin,"type",a.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtUIPlugin=st([a.DependentOn(P.UniverSheetsUIPlugin,d.UniverSheetsNumfmtPlugin),J(1,a.Inject(a.Injector)),J(2,a.IConfigService),J(3,se.IRenderManagerService)],exports.UniverSheetsNumfmtUIPlugin);
|
|
1
|
+
"use strict";var ve=Object.defineProperty;var fe=(e,t,r)=>t in e?ve(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var H=(e,t,r)=>fe(e,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),se=require("@univerjs/engine-render"),d=require("@univerjs/sheets-numfmt"),P=require("@univerjs/sheets-ui"),q=require("@univerjs/engine-numfmt"),g=require("@univerjs/sheets"),_=require("@univerjs/ui"),D=require("rxjs"),A=require("rxjs/operators"),l=require("react/jsx-runtime"),y=require("react"),E=require("@univerjs/design"),te={};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},O=(e,t)=>(r,n)=>t(r,n,e);const Z="SHEET_NUMFMT_ALERT";let Q=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(D.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,u=n.subUnitId;let o;const h=s.getCell(n.row,n.col);if(h!=null&&h.s){const f=i.getStyles().get(h.s);f!=null&&f.n&&(o=f.n)}if(o||(o=this._numfmtService.getValue(c,u,n.row,n.col)),!o){this._hideAlert();return}if(q.isTextFormat(o.pattern)&&(h!=null&&h.v)&&a.isRealNum(h.v)){if((t=this._configService.getConfig(d.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY))!=null&&t.disableTextFormatAlert)return;const f=this._cellAlertManagerService.currentAlert.get(Z),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:P.CellAlertType.ERROR,title:this._localeService.t("info.error"),message:this._localeService.t("info.forceStringInfo"),location:n,width:200,height:74,key:Z});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(Z)}};Q=ge([O(1,a.Inject(P.HoverManagerService)),O(2,a.Inject(P.CellAlertManagerService)),O(3,a.Inject(a.LocaleService)),O(4,_.IZenZoneService),O(5,a.Inject(g.INumfmtService)),O(6,a.IConfigService)],Q);const Y={id:"sheet.operation.close.numfmt.panel",type:a.CommandType.OPERATION,handler:()=>!0},$={id:"sheet.operation.open.numfmt.panel",type:a.CommandType.OPERATION,handler:e=>(e.get(F).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 ee=y.createContext([]);let L=class{constructor(e){this._localStorageService=e}_getKey(e){return`userHabitController_${e}`}async addHabit(e,t){const r=this._getKey(e);return this._localStorageService.getItem(r).then(n=>{n||this._localStorageService.setItem(r,t)})}markHabit(e,t){const r=this._getKey(e);this._localStorageService.getItem(r).then(n=>{if(n){const i=n.findIndex(s=>s===t);i>-1&&n.splice(i,1),n.unshift(t),this._localStorageService.setItem(r,n)}})}async getHabit(e,t){const r=this._getKey(e),n=await this._localStorageService.getItem(r);if(t&&n){const i=n.map((s,c,u)=>{const o=u.length;return{value:s,priority:o-c}});return t.sort((s,c)=>{var h,f;const u=((h=i.find(m=>m.value===s))==null?void 0:h.priority)||-1;return(((f=i.find(m=>m.value===c))==null?void 0:f.priority)||-1)-u})}return n||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};L=ye([_e(0,a.Inject(a.ILocalStorageService))],L);const ne="numfmtCurrency",Ce=e=>{const t=_.useDependency(L),[r,n]=y.useState(d.currencySymbols);return y.useEffect(()=>{t.addHabit("numfmtCurrency",[]).then(()=>{t.getHabit(ne,[...d.currencySymbols]).then(s=>{n(s),e&&e(s)})})},[]),{userHabitCurrency:r,mark:s=>{t.markHabit(ne,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=>!!d.getCurrencyType(e)&&e.startsWith("_("),xe=e=>{const{defaultPattern:t,action:r,onChange:n}=e,[i,s]=y.useState(()=>d.getDecimalFromPattern(t||"",2)),c=y.useContext(ee),[u,o]=y.useState(()=>d.getCurrencyType(t)||c[0]),h=y.useMemo(()=>c.map(C=>({label:C,value:C})),[]),m=_.useDependency(a.LocaleService).t;r.current=()=>d.setPatternDecimal(`_("${u}"* #,##0${i>0?".0":""}_)`,i);const p=C=>{o(C),n(d.setPatternDecimal(`_("${C}"* #,##0${i>0?".0":""}_)`,i))},S=C=>{const v=C||0;s(v),n(d.setPatternDecimal(`_("${u}"* #,##0${v>0?".0":""}_)`,v))};return l.jsxs("div",{children:[l.jsxs("div",{className:"univer-mt-4 univer-flex univer-justify-between",children:[l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2 univer-w-32",children:l.jsx(E.InputNumber,{value:i,step:1,precision:0,max:20,min:0,onChange:S})})]}),l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.currencyType")}),l.jsx("div",{className:"univer-mt-2 univer-w-36",children:l.jsx(E.Select,{options:h,value:u,onChange:p})})]})]}),l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.accountingDes")})]})},Ne=e=>!!d.getCurrencyType(e)&&!e.startsWith("_("),Ee=e=>{const r=_.useDependency(a.LocaleService).t,n=y.useContext(ee),[i,s]=y.useState(()=>d.getCurrencyType(e.defaultPattern)||n[0]),[c,u]=y.useState(()=>d.getDecimalFromPattern(e.defaultPattern||"",2)),[o,h]=y.useState(()=>{var b;const v=d.getCurrencyFormatOptions(i);return((b=v.find(N=>a.isPatternEqualWithoutDecimal(N.value,e.defaultPattern)))==null?void 0:b.value)||v[0].value}),f=y.useMemo(()=>d.getCurrencyFormatOptions(i),[i]),m=y.useMemo(()=>n.map(v=>({label:v,value:v})),[n]);e.action.current=()=>d.setPatternDecimal(o,c);const p=v=>{if(v===void 0)return;s(v);const x=d.getCurrencyFormatOptions(v)[0].value;h(x),e.onChange(d.setPatternDecimal(x,c))},S=v=>{v!==void 0&&(h(v),e.onChange(d.setPatternDecimal(v,c)))},C=v=>{u(v||0),e.onChange(d.setPatternDecimal(o,v||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: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(E.Select,{value:i,options:m,onChange:p})})]})]}),l.jsx("div",{className:"label univer-mt-4",children:r("sheet.numfmt.negType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(E.SelectList,{value:o,options:f,onChange:S})}),l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:r("sheet.numfmt.currencyDes")})]})};var T=function(){return T=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},T.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},ce=y.forwardRef(function(e,t){var r=e.icon,n=e.id,i=e.className,s=e.extend,c=Te(e,["icon","id","className","extend"]),u="univerjs-icon univerjs-icon-".concat(n," ").concat(i||"").trim(),o=y.useRef("_".concat(je()));return ae(r,"".concat(n),{defIds:r.defIds,idSuffix:o.current},T({ref:t,className:u},c),s)});function ae(e,t,r,n,i){return y.createElement(e.tag,T(T({key:t},Pe(e,r,i)),n),(Me(e,r).children||[]).map(function(s,c){return ae(s,"".concat(t,"-").concat(e.tag,"-").concat(c),r,void 0,i)}))}function Pe(e,t,r){var n=T({},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],u=s[1];c==="mask"&&typeof u=="string"&&(n[c]=u.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],u=s[1];typeof u=="string"&&(n[c]=u.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)?T(T({},e),{children:e.children.map(function(i){return typeof i.attrs.id=="string"&&n&&n.includes(i.attrs.id)?T(T({},i),{attrs:T(T({},i.attrs),{id:i.attrs.id+t.idSuffix})}):i})}):e}function je(){return Math.random().toString(36).substring(2,8)}ce.displayName="UniverIcon";var De={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"}}]},oe=y.forwardRef(function(e,t){return y.createElement(ce,Object.assign({},e,{id:"check-mark-icon",ref:t,icon:De}))});oe.displayName="CheckMarkIcon";const z="customFormat",X="numfmt_custom_pattern";function Re(e){const{defaultPattern:t,action:r,onChange:n}=e,i=_.useDependency(L),s=_.useDependency(a.ILocalStorageService),c=_.useDependency(a.LocaleService),[u,o]=y.useState(t);r.current=()=>(i.markHabit(z,u),s.getItem(X).then((S=[])=>{const C=[...new Set([u,...S||[]])].splice(0,10).filter(v=>!!v);s.setItem(X,C)}),u);const[h,f]=y.useState([]);y.useEffect(()=>{s.getItem(X).then(S=>{const C=[...d.CURRENCYFORMAT.map(v=>v.suffix("$")),...d.DATEFMTLISG.map(v=>v.suffix),...d.NUMBERFORMAT.map(v=>v.suffix)];C.push(...S||[]),i.addHabit(z,[]).finally(()=>{i.getHabit(z,C).then(v=>{f([...new Set(v)])})})})},[]);const m=S=>{o(S),n(S)},p=()=>{n(u)};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(E.Input,{placeholder:c.t("sheet.numfmt.customFormat"),onBlur:p,value:u,onChange:o,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:h.map(S=>l.jsxs("div",{onClick:()=>m(S),className:"univer-flex univer-cursor-pointer univer-items-center univer-gap-1.5 univer-py-1.5 univer-text-sm",children:[l.jsx("div",{className:"univer-flex univer-w-4 univer-items-center univer-text-primary-600",children:u===S&&l.jsx(oe,{})}),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 we=e=>{const t=a.numfmt.getFormatInfo(e);return d.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(d.getDateFormatOptions,[]),i=_.useDependency(a.LocaleService),[s,c]=y.useState(()=>{if(r){const o=n.find(h=>h.value===r);if(o)return o.value}return n[0].value});e.action.current=()=>s;const u=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(E.SelectList,{value:s,options:n,onChange:u})}),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=>d.getNumberFormatOptions().some(t=>a.isPatternEqualWithoutDecimal(t.value,e));function Le(e){const t=_.useDependency(a.LocaleService),r=y.useMemo(d.getNumberFormatOptions,[]),[n,i]=y.useState(()=>d.getDecimalFromPattern(e.defaultPattern||"",0)),[s,c]=y.useState(()=>{const m=r.find(p=>a.isPatternEqualWithoutDecimal(p.value,e.defaultPattern||""));return(m==null?void 0:m.value)||r[0].value}),u=y.useMemo(()=>d.setPatternDecimal(s,Number(n||0)),[s,n]),o=y.useMemo(()=>!d.isPatternHasDecimal(s),[s]),h=m=>{i(m||0),e.onChange(d.setPatternDecimal(s,Number(m||0)))},f=m=>{m!==void 0&&(i(d.getDecimalFromPattern(m,0)),c(m),e.onChange(m))};return e.action.current=()=>u,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:o,value:n,max:20,min:0,onChange:h})}),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 Fe=e=>{const{defaultValue:t,defaultPattern:r,row:n,col:i}=e.value,s=_.useDependency(a.LocaleService),c=y.useRef(()=>""),u=s.t,o=be(),h=y.useMemo(()=>[{label:"sheet.numfmt.general",component:ke},{label:"sheet.numfmt.accounting",component:xe},{label:"sheet.numfmt.currency",component:Ee},{label:"sheet.numfmt.date",component:Oe},{label:"sheet.numfmt.thousandthPercentile",component:Le},{label:"sheet.numfmt.customFormat",component:Re}].map(I=>({...I,label:u(I.label)})),[]),[f,m]=y.useState(b),[p,S]=y.useState(()=>`${n}_${i}`),{mark:C,userHabitCurrency:v}=Ce(()=>S(`${n}_${i}_userCurrency'`)),x=y.useMemo(()=>{var I;return(I=h.find(w=>w.label===f))==null?void 0:I.component},[f]);function b(){return[Ue,Ie,Ne,we,$e].reduce((w,de,he)=>w||(de(r)?h[he].label:""),"")||h[0].label}const N=h.map(I=>({label:I.label,value:I.label})),j=I=>{m(I),o(()=>e.onChange({type:"change",value:c.current()||""}))},R=y.useCallback(I=>{e.onChange({type:"change",value:I})},[]),G=()=>{const I=c.current()||"",w=d.getCurrencyType(I);w&&C(w),e.onChange({type:"confirm",value:I})},U=()=>{e.onChange({type:"cancel",value:""})},K={onChange:R,defaultValue:t,defaultPattern:r,action:c};return y.useEffect(()=>{m(b()),S(`${n}_${i}`)},[n,i]),l.jsxs("div",{className:E.clsx("univer-flex univer-h-full univer-flex-col univer-justify-between univer-overflow-y-auto univer-pb-5",E.scrollbarClassName),children:[l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-3.5 univer-text-sm univer-text-gray-400",children:u("sheet.numfmt.numfmtType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(E.Select,{className:"univer-w-full",value:f,options:N,onChange:j})}),l.jsx("div",{children:x&&l.jsx(ee.Provider,{value:v,children:y.createElement(x,{...K,key:p})})})]}),l.jsxs("div",{className:"univer-mb-5 univer-mt-3.5 univer-flex univer-justify-end",children:[l.jsx(E.Button,{onClick:U,className:"univer-mr-3",children:u("sheet.numfmt.cancel")}),l.jsx(E.Button,{variant:"primary",onClick:G,children:u("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 re="SHEET_NUMFMT_PANEL";let F=class extends a.Disposable{constructor(t,r,n,i,s,c,u,o,h,f,m){super();H(this,"_previewPattern","");H(this,"_sidebarDisposable",null);this._sheetInterceptorService=t,this._themeService=r,this._univerInstanceService=n,this._commandService=i,this._selectionManagerService=s,this._renderManagerService=c,this._numfmtService=u,this._componentManager=o,this._sidebarService=h,this._localeService=f,this._sheetsNumfmtCellContentController=m,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener(),this._initNumfmtLocalChange()}_initNumfmtLocalChange(){this.disposeWithMe(D.merge(this._sheetsNumfmtCellContentController.local$,this._localeService.currentLocale$).subscribe(()=>{this._forceUpdate()}))}openPanel(){var 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 h=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),f=h.getActiveSheet();if(!f)return!1;const m=f.getCellRaw(o.startRow,o.startColumn),p=s.getValue(h.getUnitId(),f.getSheetId(),o.startRow,o.startColumn);let S="";p&&(S=p.pattern);const C=(m==null?void 0:m.t)===a.CellValueType.NUMBER?m.v:12345678,v={onChange:b=>{var N;if(b.type==="change")this._previewPattern=b.value,this._forceUpdate();else if(b.type==="confirm"){const j=((N=r.getCurrentSelections())==null?void 0:N.map(U=>U.range))||[],R={values:[]},G=d.getPatternType(b.value);j.forEach(U=>{a.Range.foreach(U,(K,I)=>{R.values.push({row:K,col:I,pattern:b.value,type:G})})}),n.executeCommand(d.SetNumfmtCommand.id,R),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:re,...v},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(P.SheetSkeletonManagerService).reCalculate(),(n=r==null?void 0:r.mainComponent)==null||n.makeDirty()}_initCommands(){[$,Y].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}_initPanel(){this.disposeWithMe(this._componentManager.register(re,Fe))}_initRealTimeRenderingInterceptor(){const t=new D.Observable(n=>{this._commandService.onCommandExecuted(i=>{i.id===$.id&&n.next(!0),i.id===Y.id&&n.next(!1)})}),r=D.combineLatest([t,this._selectionManagerService.selectionMoveEnd$.pipe(A.map(n=>n?n.map(i=>i.range):[]))]);this.disposeWithMe(a.toDisposable(r.pipe(A.switchMap(([n,i])=>new D.Observable(s=>{const c=new a.DisposableCollection;return n&&i.length&&s.next({selectionRanges:i,disposableCollection:c}),()=>{c.dispose()}})),A.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:n,selectionRanges:i})=>{var c,u;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,h,f)=>{var C;const{row:m,col:p}=h,S=f(o)||{};if(i.find(v=>v.startColumn<=p&&v.endColumn>=p&&v.startRow<=m&&v.endRow>=m)){const v=h.worksheet.getCellRaw(m,p),x=v==null?void 0:v.v,b=v==null?void 0:v.t;if(x==null||b!==a.CellValueType.NUMBER||this._previewPattern===null)return S;const N=d.getPatternPreviewIgnoreGeneral(this._previewPattern,x,this._sheetsNumfmtCellContentController.local);if(N.color){const j=(C=this._themeService.getColorFromTheme(`${N.color}.500`))!=null?C:N.color;return{...S,v:N.result,t:a.CellValueType.STRING,s:{cl:{rgb:j}}}}return{...S,v:N.result,t:a.CellValueType.STRING}}return S}})),(u=(c=this._renderManagerService.getRenderById(s.getUnitId()))==null?void 0:c.mainComponent)==null||u.makeDirty()})))}_commandExecutedListener(){const t=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id];this.disposeWithMe(new D.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(A.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)})}};F=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,se.IRenderManagerService),M(6,g.INumfmtService),M(7,a.Inject(_.ComponentManager)),M(8,_.ISidebarService),M(9,a.Inject(a.LocaleService)),M(10,a.Inject(d.SheetsNumfmtCellContentController))],F);var We=Object.getOwnPropertyDescriptor,Ve=(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},k=(e,t)=>(r,n)=>t(r,n,e);const Be=()=>{let e=[];return{add:(i,s,c,u,o)=>e.push({unitId:i,subUnitId:s,row:c,col:u,value:o}),getEffects:()=>e,clean:()=>{e=[]}}};let V=class extends a.Disposable{constructor(t,r,n,i,s){super();H(this,"_collectEffectMutation",Be());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(d.getPatternType(c.pattern)){case"scientific":case"currency":case"grouped":case"number":{const o=r.worksheet.getCellRaw(i,s);return 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 o,h,f;this._collectEffectMutation.clean();const i=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col);if(!(t!=null&&t.v)&&!(t!=null&&t.p)||q.isTextFormat(i==null?void 0:i.pattern)||t.t===a.CellValueType.FORCE_STRING)return n(t);const s=(o=t.p)==null?void 0:o.body,c=(f=(h=t==null?void 0:t.p)==null?void 0:h.body)!=null&&f.dataStream?t.p.body.dataStream.replace(/\r\n$/,""):String(t.v),u=a.numfmt.parseDate(c)||a.numfmt.parseTime(c)||a.numfmt.parseNumber(c);if(s)if(qe(s)){const{dataStream:m}=s,p=m.replace(/\r\n$/,""),S=Number(p);if(Number.isNaN(S)&&!u)return n(t)}else return n(t);if(u){if(!u.z&&a.willLoseNumericPrecision(c))return n({...t,p:void 0,v:c,t:a.CellValueType.FORCE_STRING});u.z&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:u.z});const m=Number(u.v);return n({...t,p:void 0,v:m,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 u=t._collectEffectMutation.getEffects();if(t._collectEffectMutation.clean(),!u.length)return{redos:[],undos:[]};const o=u.filter(p=>{var S;return!!((S=p.value)!=null&&S.pattern)}).map(p=>({row:p.row,col:p.col,pattern:p.value.pattern})),h=u.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})),f=[],m=[];if(o.length){const p={id:g.SetNumfmtMutation.id,params:g.transformCellsToRange(s,c,o)};f.push(p),m.push(...g.factorySetNumfmtUndoMutation(t._injector,p.params))}if(h.length){const p={id:g.RemoveNumfmtMutation.id,params:{unitId:s,subUnitId:c,ranges:h}};f.push(p),m.push(...g.factoryRemoveNumfmtUndoMutation(t._injector,p.params))}return{redos:f,undos:m.reverse()}}}return{redos:[],undos:[]}}}))}};V=Ve([k(0,a.Inject(g.SheetInterceptorService)),k(1,a.Inject(g.INumfmtService)),k(2,a.Inject(a.IUniverInstanceService)),k(3,a.Inject(a.Injector)),k(4,a.Optional(P.IEditorBridgeService))],V);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 W=[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:q.DEFAULT_TEXT_FORMAT_EXCEL},"|",{label:"sheet.numfmt.number",pattern:"0"},{label:"sheet.numfmt.percent",pattern:"0.00%"},{label:"sheet.numfmt.scientific",pattern:"0.00E+00"},"|",{label:"sheet.numfmt.accounting",pattern:'"¥" #,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.financialValue",pattern:"#,##0.00;[Red]#,##0.00"},{label:"sheet.numfmt.currency",pattern:'"¥"#,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.roundingCurrency",pattern:'"¥"#,##0;[Red]"¥"#,##0'},"|",{label:"sheet.numfmt.date",pattern:"yyyy-mm-dd;@"},{label:"sheet.numfmt.time",pattern:'am/pm h":"mm":"ss'},{label:"sheet.numfmt.dateTime",pattern:"yyyy-m-d am/pm h:mm"},{label:"sheet.numfmt.timeDuration",pattern:"h:mm:ss"},"|",{label:"sheet.numfmt.moreFmt",pattern:""}],Ge=e=>({icon:new D.Observable(t=>{var s;const r=e.get(d.MenuCurrencyService);function n(c){var o;return(o={[d.countryCurrencyMap.US]:"DollarIcon",[d.countryCurrencyMap.RU]:"RoubleIcon",[d.countryCurrencyMap.CN]:"RmbIcon",[d.countryCurrencyMap.AT]:"EuroIcon"}[c])!=null?o:"DollarIcon"}const i=(s=d.countryCurrencyMap[r.getCurrencySymbol()])!=null?s:"$";return t.next(n(i)),r.currencySymbol$.subscribe(c=>{var o;const u=(o=d.countryCurrencyMap[c])!=null?o:"$";t.next(n(u))})}),id:d.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:d.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:d.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:d.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:u,worksheet:o})=>new D.Observable(h=>D.merge(i.selectionMoveEnd$,a.fromCallback(r.onCommandExecuted.bind(r)).pipe(D.filter(([f])=>s.includes(f.id)))).subscribe(()=>{var m,p;const f=i.getCurrentSelections();if(f&&f[0]){const S=f[0].range,C=S.startRow,v=S.startColumn,x=(p=u.getStyles().get((m=o.getCell(C,v))==null?void 0:m.s))==null?void 0:p.n,b=x==null?void 0:x.pattern;let N=n.t("sheet.numfmt.general");if(q.isDefaultFormat(b)){h.next(N);return}if(b){const j=W.filter(R=>typeof R=="object"&&R.pattern).find(R=>a.isPatternEqualWithoutDecimal(b,R.pattern));j&&typeof j=="object"&&j.pattern?N=n.t(j.label):N=n.t("sheet.numfmt.moreFmt")}h.next(N)}})));return{label:le,id:$.id,tooltip:"sheet.numfmt.title",type:_.MenuItemType.SELECTOR,slot:!0,selections:[{label:{name:ue,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]})}},le="sheet.numfmt.moreNumfmtType",ue="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(d.SheetsNumfmtCellContentController),i=_.useDependency(g.SheetsSelectionsService),s=o=>{const h=i.getCurrentLastSelection();if(!h)return;const f=h.range,m=[];a.Range.foreach(f,(p,S)=>{o?m.push({row:p,col:S,pattern:o,type:d.getPatternType(o)}):m.push({row:p,col:S})}),e.executeCommand(d.SetNumfmtCommand.id,{values:m}),r.focus()},c=o=>{if(o===0)s(null);else if(o===W.length-1)e.executeCommand($.id),r.focus();else{const h=W[o];h.pattern&&s(h.pattern)}},u=1220;return l.jsx("div",{className:"univer-grid univer-gap-1 univer-p-1.5",children:W.map((o,h)=>o==="|"?l.jsx(E.Separator,{},h):l.jsxs("div",{className:"univer-flex univer-h-7 univer-items-center univer-justify-between univer-gap-6 univer-rounded univer-px-2 univer-text-sm hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700",onClick:()=>{c(h)},children:[l.jsx("span",{children:t.t(o.label)}),l.jsx("span",{className:"univer-text-xs univer-text-gray-500",children:o.pattern?d.getPatternPreview(o.pattern||"",u,n.local).result.trim():""})]},h))})},Qe={[_.RibbonDataGroup.FORMULAS]:{[d.SetCurrencyCommand.id]:{order:0,menuItemFactory:Ge},[d.AddDecimalCommand.id]:{order:1,menuItemFactory:Ke},[d.SubtractDecimalCommand.id]:{order:2,menuItemFactory:Ze},[d.SetPercentCommand.id]:{order:3,menuItemFactory:Ye},[$.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},ie=(e,t)=>(r,n)=>t(r,n,e);let B=class extends a.Disposable{constructor(e,t){super(),this._componentManager=e,this._menuManagerService=t,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(Qe),[[le,Xe],[ue,Je]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};B=tt([ie(0,a.Inject(_.ComponentManager)),ie(1,_.IMenuManagerService)],B);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},J=(e,t)=>(r,n)=>t(r,n,e),me=(e,t,r)=>it(e,typeof t!="symbol"?t+"":t,r);const ct="SHEET_NUMFMT_UI_PLUGIN";exports.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,...c}=a.merge({},te,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig("sheets-numfmt-ui.config",c)}onStarting(){a.registerDependencies(this._injector,[[F],[V],[L],[B]])}onRendered(){this._registerRenderModules(),a.touchDependencies(this._injector,[[F],[V],[B]])}_registerRenderModules(){[[Q]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,r))})}};me(exports.UniverSheetsNumfmtUIPlugin,"pluginName",ct);me(exports.UniverSheetsNumfmtUIPlugin,"type",a.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtUIPlugin=st([a.DependentOn(P.UniverSheetsUIPlugin,d.UniverSheetsNumfmtPlugin),J(1,a.Inject(a.Injector)),J(2,a.IConfigService),J(3,se.IRenderManagerService)],exports.UniverSheetsNumfmtUIPlugin);
|
package/lib/es/index.js
CHANGED
|
@@ -250,7 +250,7 @@ const ke = "numfmtCurrency", yn = (e) => {
|
|
|
250
250
|
) })
|
|
251
251
|
] })
|
|
252
252
|
] }),
|
|
253
|
-
/* @__PURE__ */ d("div", { className: "univer-mt-4
|
|
253
|
+
/* @__PURE__ */ d("div", { className: "label univer-mt-4", children: r("sheet.numfmt.negType") }),
|
|
254
254
|
/* @__PURE__ */ d("div", { className: "univer-mt-2", children: /* @__PURE__ */ d(we, { value: c, options: h, onChange: v }) }),
|
|
255
255
|
/* @__PURE__ */ d("div", { className: "univer-mt-4 univer-text-sm univer-text-gray-400", children: r("sheet.numfmt.currencyDes") })
|
|
256
256
|
] });
|
|
@@ -1075,7 +1075,7 @@ const Q = [
|
|
|
1075
1075
|
return /* @__PURE__ */ d("div", { className: "univer-grid univer-gap-1 univer-p-1.5", children: Q.map((c, u) => c === "|" ? /* @__PURE__ */ d(fn, {}, u) : /* @__PURE__ */ b(
|
|
1076
1076
|
"div",
|
|
1077
1077
|
{
|
|
1078
|
-
className: "univer-flex univer-h-7 univer-items-center univer-justify-between univer-gap-6 univer-rounded univer-px-2 univer-text-sm
|
|
1078
|
+
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",
|
|
1079
1079
|
onClick: () => {
|
|
1080
1080
|
o(u);
|
|
1081
1081
|
},
|
package/lib/index.js
CHANGED
|
@@ -250,7 +250,7 @@ const ke = "numfmtCurrency", yn = (e) => {
|
|
|
250
250
|
) })
|
|
251
251
|
] })
|
|
252
252
|
] }),
|
|
253
|
-
/* @__PURE__ */ d("div", { className: "univer-mt-4
|
|
253
|
+
/* @__PURE__ */ d("div", { className: "label univer-mt-4", children: r("sheet.numfmt.negType") }),
|
|
254
254
|
/* @__PURE__ */ d("div", { className: "univer-mt-2", children: /* @__PURE__ */ d(we, { value: c, options: h, onChange: v }) }),
|
|
255
255
|
/* @__PURE__ */ d("div", { className: "univer-mt-4 univer-text-sm univer-text-gray-400", children: r("sheet.numfmt.currencyDes") })
|
|
256
256
|
] });
|
|
@@ -1075,7 +1075,7 @@ const Q = [
|
|
|
1075
1075
|
return /* @__PURE__ */ d("div", { className: "univer-grid univer-gap-1 univer-p-1.5", children: Q.map((c, u) => c === "|" ? /* @__PURE__ */ d(fn, {}, u) : /* @__PURE__ */ b(
|
|
1076
1076
|
"div",
|
|
1077
1077
|
{
|
|
1078
|
-
className: "univer-flex univer-h-7 univer-items-center univer-justify-between univer-gap-6 univer-rounded univer-px-2 univer-text-sm
|
|
1078
|
+
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",
|
|
1079
1079
|
onClick: () => {
|
|
1080
1080
|
o(u);
|
|
1081
1081
|
},
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(C,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/sheets-numfmt"),require("@univerjs/sheets-ui"),require("@univerjs/engine-numfmt"),require("@univerjs/sheets"),require("@univerjs/ui"),require("rxjs"),require("rxjs/operators"),require("react/jsx-runtime"),require("react"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","@univerjs/sheets-numfmt","@univerjs/sheets-ui","@univerjs/engine-numfmt","@univerjs/sheets","@univerjs/ui","rxjs","rxjs/operators","react/jsx-runtime","react","@univerjs/design"],s):(C=typeof globalThis<"u"?globalThis:C||self,s(C.UniverSheetsNumfmtUi={},C.UniverCore,C.UniverEngineRender,C.UniverSheetsNumfmt,C.UniverSheetsUi,C.UniverEngineNumfmt,C.UniverSheets,C.UniverUi,C.rxjs,C.rxjs.operators,C.React,C.React,C.UniverDesign))})(this,function(C,s,k,d,D,W,g,_,x,V,l,y,T){"use strict";var st=Object.defineProperty;var ot=(C,s,k)=>s in C?st(C,s,{enumerable:!0,configurable:!0,writable:!0,value:k}):C[s]=k;var K=(C,s,k)=>ot(C,typeof s!="symbol"?s+"":s,k);const re={};var ve=Object.getOwnPropertyDescriptor,pe=(e,n,r,t)=>{for(var i=t>1?void 0:t?ve(n,r):n,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=o(i)||i);return i},j=(e,n)=>(r,t)=>n(r,t,e);const Z="SHEET_NUMFMT_ALERT";let Y=class extends s.Disposable{constructor(e,n,r,t,i,a,o){super(),this._context=e,this._hoverManagerService=n,this._cellAlertManagerService=r,this._localeService=t,this._zenZoneService=i,this._numfmtService=a,this._configService=o,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(x.debounceTime(100)).subscribe(e=>{var n,r;if(e){const t=e.location,i=this._context.unit,a=i.getActiveSheet();if(!a)return;const o=t.unitId,u=t.subUnitId;let c;const v=a.getCell(t.row,t.col);if(v!=null&&v.s){const f=i.getStyles().get(v.s);f!=null&&f.n&&(c=f.n)}if(c||(c=this._numfmtService.getValue(o,u,t.row,t.col)),!c){this._hideAlert();return}if(W.isTextFormat(c.pattern)&&(v!=null&&v.v)&&s.isRealNum(v.v)){if((n=this._configService.getConfig(d.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY))!=null&&n.disableTextFormatAlert)return;const f=this._cellAlertManagerService.currentAlert.get(Z),m=(r=f==null?void 0:f.alert)==null?void 0:r.location;if(m&&m.row===t.row&&m.col===t.col&&m.subUnitId===t.subUnitId&&m.unitId===t.unitId)return;this._cellAlertManagerService.showAlert({type:D.CellAlertType.ERROR,title:this._localeService.t("info.error"),message:this._localeService.t("info.forceStringInfo"),location:t,width:200,height:74,key:Z});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(Z)}};Y=pe([j(1,s.Inject(D.HoverManagerService)),j(2,s.Inject(D.CellAlertManagerService)),j(3,s.Inject(s.LocaleService)),j(4,_.IZenZoneService),j(5,s.Inject(g.INumfmtService)),j(6,s.IConfigService)],Y);const z={id:"sheet.operation.close.numfmt.panel",type:s.CommandType.OPERATION,handler:()=>!0},L={id:"sheet.operation.open.numfmt.panel",type:s.CommandType.OPERATION,handler:e=>(e.get(H).openPanel(),!0)};var fe=Object.getOwnPropertyDescriptor,he=(e,n,r,t)=>{for(var i=t>1?void 0:t?fe(n,r):n,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=o(i)||i);return i},ge=(e,n)=>(r,t)=>n(r,t,e);const X=y.createContext([]);let F=class{constructor(e){this._localStorageService=e}_getKey(e){return`userHabitController_${e}`}async addHabit(e,n){const r=this._getKey(e);return this._localStorageService.getItem(r).then(t=>{t||this._localStorageService.setItem(r,n)})}markHabit(e,n){const r=this._getKey(e);this._localStorageService.getItem(r).then(t=>{if(t){const i=t.findIndex(a=>a===n);i>-1&&t.splice(i,1),t.unshift(n),this._localStorageService.setItem(r,t)}})}async getHabit(e,n){const r=this._getKey(e),t=await this._localStorageService.getItem(r);if(n&&t){const i=t.map((a,o,u)=>{const c=u.length;return{value:a,priority:c-o}});return n.sort((a,o)=>{var v,f;const u=((v=i.find(m=>m.value===a))==null?void 0:v.priority)||-1;return(((f=i.find(m=>m.value===o))==null?void 0:f.priority)||-1)-u})}return t||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};F=he([ge(0,s.Inject(s.ILocalStorageService))],F);const ie="numfmtCurrency",Se=e=>{const n=_.useDependency(F),[r,t]=y.useState(d.currencySymbols);return y.useEffect(()=>{n.addHabit("numfmtCurrency",[]).then(()=>{n.getHabit(ie,[...d.currencySymbols]).then(a=>{t(a),e&&e(a)})})},[]),{userHabitCurrency:r,mark:a=>{n.markHabit(ie,a)}}},ye=()=>{const e=y.useRef([]),[n,r]=y.useState({});return y.useEffect(()=>{e.current.forEach(i=>{i()}),e.current=[]},[n]),i=>{e.current.push(i),r({})}},_e=e=>!!d.getCurrencyType(e)&&e.startsWith("_("),Ce=e=>{const{defaultPattern:n,action:r,onChange:t}=e,[i,a]=y.useState(()=>d.getDecimalFromPattern(n||"",2)),o=y.useContext(X),[u,c]=y.useState(()=>d.getCurrencyType(n)||o[0]),v=y.useMemo(()=>o.map(b=>({label:b,value:b})),[]),m=_.useDependency(s.LocaleService).t;r.current=()=>d.setPatternDecimal(`_("${u}"* #,##0${i>0?".0":""}_)`,i);const h=b=>{c(b),t(d.setPatternDecimal(`_("${b}"* #,##0${i>0?".0":""}_)`,i))},S=b=>{const p=b||0;a(p),t(d.setPatternDecimal(`_("${u}"* #,##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(T.InputNumber,{value:i,step:1,precision:0,max:20,min:0,onChange:S})})]}),l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.currencyType")}),l.jsx("div",{className:"univer-mt-2 univer-w-36",children:l.jsx(T.Select,{options:v,value:u,onChange:h})})]})]}),l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.accountingDes")})]})},be=e=>!!d.getCurrencyType(e)&&!e.startsWith("_("),Ie=e=>{const r=_.useDependency(s.LocaleService).t,t=y.useContext(X),[i,a]=y.useState(()=>d.getCurrencyType(e.defaultPattern)||t[0]),[o,u]=y.useState(()=>d.getDecimalFromPattern(e.defaultPattern||"",2)),[c,v]=y.useState(()=>{var I;const p=d.getCurrencyFormatOptions(i);return((I=p.find(M=>s.isPatternEqualWithoutDecimal(M.value,e.defaultPattern)))==null?void 0:I.value)||p[0].value}),f=y.useMemo(()=>d.getCurrencyFormatOptions(i),[i]),m=y.useMemo(()=>t.map(p=>({label:p,value:p})),[t]);e.action.current=()=>d.setPatternDecimal(c,o);const h=p=>{if(p===void 0)return;a(p);const P=d.getCurrencyFormatOptions(p)[0].value;v(P),e.onChange(d.setPatternDecimal(P,o))},S=p=>{p!==void 0&&(v(p),e.onChange(d.setPatternDecimal(p,o)))},b=p=>{u(p||0),e.onChange(d.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(T.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(T.Select,{value:i,options:m,onChange:h})})]})]}),l.jsx("div",{className:"univer-mt-4 label",children:r("sheet.numfmt.negType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(T.SelectList,{value:c,options:f,onChange:S})}),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 n,r=1,t=arguments.length;r<t;r++){n=arguments[r];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},w.apply(this,arguments)},Ee=function(e,n){var r={};for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&n.indexOf(t)<0&&(r[t]=e[t]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,t=Object.getOwnPropertySymbols(e);i<t.length;i++)n.indexOf(t[i])<0&&Object.prototype.propertyIsEnumerable.call(e,t[i])&&(r[t[i]]=e[t[i]]);return r},ae=y.forwardRef(function(e,n){var r=e.icon,t=e.id,i=e.className,a=e.extend,o=Ee(e,["icon","id","className","extend"]),u="univerjs-icon univerjs-icon-".concat(t," ").concat(i||"").trim(),c=y.useRef("_".concat(Me()));return se(r,"".concat(t),{defIds:r.defIds,idSuffix:c.current},w({ref:n,className:u},o),a)});function se(e,n,r,t,i){return y.createElement(e.tag,w(w({key:n},Te(e,r,i)),t),(Pe(e,r).children||[]).map(function(a,o){return se(a,"".concat(n,"-").concat(e.tag,"-").concat(o),r,void 0,i)}))}function Te(e,n,r){var t=w({},e.attrs);r!=null&&r.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=r.colorChannel1),e.tag==="mask"&&t.id&&(t.id=t.id+n.idSuffix),Object.entries(t).forEach(function(a){var o=a[0],u=a[1];o==="mask"&&typeof u=="string"&&(t[o]=u.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))});var i=n.defIds;return!i||i.length===0||(e.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+n.idSuffix),Object.entries(t).forEach(function(a){var o=a[0],u=a[1];typeof u=="string"&&(t[o]=u.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),t}function Pe(e,n){var r,t=n.defIds;return!t||t.length===0?e:e.tag==="defs"&&(!((r=e.children)===null||r===void 0)&&r.length)?w(w({},e),{children:e.children.map(function(i){return typeof i.attrs.id=="string"&&t&&t.includes(i.attrs.id)?w(w({},i),{attrs:w(w({},i.attrs),{id:i.attrs.id+n.idSuffix})}):i})}):e}function Me(){return Math.random().toString(36).substring(2,8)}ae.displayName="UniverIcon";var De={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"}}]},oe=y.forwardRef(function(e,n){return y.createElement(ae,Object.assign({},e,{id:"check-mark-icon",ref:n,icon:De}))});oe.displayName="CheckMarkIcon";const J="customFormat",Q="numfmt_custom_pattern";function we(e){const{defaultPattern:n,action:r,onChange:t}=e,i=_.useDependency(F),a=_.useDependency(s.ILocalStorageService),o=_.useDependency(s.LocaleService),[u,c]=y.useState(n);r.current=()=>(i.markHabit(J,u),a.getItem(Q).then((S=[])=>{const b=[...new Set([u,...S||[]])].splice(0,10).filter(p=>!!p);a.setItem(Q,b)}),u);const[v,f]=y.useState([]);y.useEffect(()=>{a.getItem(Q).then(S=>{const b=[...d.CURRENCYFORMAT.map(p=>p.suffix("$")),...d.DATEFMTLISG.map(p=>p.suffix),...d.NUMBERFORMAT.map(p=>p.suffix)];b.push(...S||[]),i.addHabit(J,[]).finally(()=>{i.getHabit(J,b).then(p=>{f([...new Set(p)])})})})},[]);const m=S=>{c(S),t(S)},h=()=>{t(u)};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(T.Input,{placeholder:o.t("sheet.numfmt.customFormat"),onBlur:h,value:u,onChange:c,className:"univer-mt-2 univer-w-full"}),l.jsx("div",{className:T.clsx("univer-mt-2 univer-max-h-[400px] univer-overflow-auto univer-rounded-lg univer-p-2",T.borderClassName),children:v.map(S=>l.jsxs("div",{onClick:()=>m(S),className:"univer-flex univer-cursor-pointer univer-items-center univer-gap-1.5 univer-py-1.5 univer-text-sm",children:[l.jsx("div",{className:"univer-flex univer-w-4 univer-items-center univer-text-primary-600",children:u===S&&l.jsx(oe,{})}),l.jsx("div",{children:S})]},S))}),l.jsx("div",{className:"univer-mt-3 univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200",children:o.t("sheet.numfmt.customFormatDes")})]})}const Ne=e=>{const n=s.numfmt.getFormatInfo(e);return d.getDateFormatOptions().map(r=>r.value).includes(e)||["date","datetime","time"].includes(n.type)};function xe(e){const{onChange:n,defaultPattern:r}=e,t=y.useMemo(d.getDateFormatOptions,[]),i=_.useDependency(s.LocaleService),[a,o]=y.useState(()=>{if(r){const c=t.find(v=>v.value===r);if(c)return c.value}return t[0].value});e.action.current=()=>a;const u=c=>{c!==void 0&&(o(c),n(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(T.SelectList,{value:a,options:t,onChange:u})}),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 Oe=e=>!e,Ue=e=>{const r=_.useDependency(s.LocaleService).t;return e.action.current=()=>"",l.jsx("div",{children:l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:r("sheet.numfmt.generalDes")})})},ke=e=>d.getNumberFormatOptions().some(n=>s.isPatternEqualWithoutDecimal(n.value,e));function je(e){const n=_.useDependency(s.LocaleService),r=y.useMemo(d.getNumberFormatOptions,[]),[t,i]=y.useState(()=>d.getDecimalFromPattern(e.defaultPattern||"",0)),[a,o]=y.useState(()=>{const m=r.find(h=>s.isPatternEqualWithoutDecimal(h.value,e.defaultPattern||""));return(m==null?void 0:m.value)||r[0].value}),u=y.useMemo(()=>d.setPatternDecimal(a,Number(t||0)),[a,t]),c=y.useMemo(()=>!d.isPatternHasDecimal(a),[a]),v=m=>{i(m||0),e.onChange(d.setPatternDecimal(a,Number(m||0)))},f=m=>{m!==void 0&&(i(d.getDecimalFromPattern(m,0)),o(m),e.onChange(m))};return e.action.current=()=>u,l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:n.t("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(T.InputNumber,{disabled:c,value:t,max:20,min:0,onChange:v})}),l.jsxs("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:[" ",n.t("sheet.numfmt.negType")]}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(T.SelectList,{onChange:f,options:r,value:a})}),l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:n.t("sheet.numfmt.thousandthPercentileDes")})]})}const $e=e=>{const{defaultValue:n,defaultPattern:r,row:t,col:i}=e.value,a=_.useDependency(s.LocaleService),o=y.useRef(()=>""),u=a.t,c=ye(),v=y.useMemo(()=>[{label:"sheet.numfmt.general",component:Ue},{label:"sheet.numfmt.accounting",component:Ce},{label:"sheet.numfmt.currency",component:Ie},{label:"sheet.numfmt.date",component:xe},{label:"sheet.numfmt.thousandthPercentile",component:je},{label:"sheet.numfmt.customFormat",component:we}].map(E=>({...E,label:u(E.label)})),[]),[f,m]=y.useState(I),[h,S]=y.useState(()=>`${t}_${i}`),{mark:b,userHabitCurrency:p}=Se(()=>S(`${t}_${i}_userCurrency'`)),P=y.useMemo(()=>{var E;return(E=v.find($=>$.label===f))==null?void 0:E.component},[f]);function I(){return[Oe,_e,be,Ne,ke].reduce(($,it,at)=>$||(it(r)?v[at].label:""),"")||v[0].label}const M=v.map(E=>({label:E.label,value:E.label})),O=E=>{m(E),c(()=>e.onChange({type:"change",value:o.current()||""}))},U=y.useCallback(E=>{e.onChange({type:"change",value:E})},[]),te=()=>{const E=o.current()||"",$=d.getCurrencyType(E);$&&b($),e.onChange({type:"confirm",value:E})},R=()=>{e.onChange({type:"cancel",value:""})},ne={onChange:U,defaultValue:n,defaultPattern:r,action:o};return y.useEffect(()=>{m(I()),S(`${t}_${i}`)},[t,i]),l.jsxs("div",{className:T.clsx("univer-flex univer-h-full univer-flex-col univer-justify-between univer-overflow-y-auto univer-pb-5",T.scrollbarClassName),children:[l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-3.5 univer-text-sm univer-text-gray-400",children:u("sheet.numfmt.numfmtType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(T.Select,{className:"univer-w-full",value:f,options:M,onChange:O})}),l.jsx("div",{children:P&&l.jsx(X.Provider,{value:p,children:y.createElement(P,{...ne,key:h})})})]}),l.jsxs("div",{className:"univer-mb-5 univer-mt-3.5 univer-flex univer-justify-end",children:[l.jsx(T.Button,{onClick:R,className:"univer-mr-3",children:u("sheet.numfmt.cancel")}),l.jsx(T.Button,{variant:"primary",onClick:te,children:u("sheet.numfmt.confirm")})]})]})};var Le=Object.getOwnPropertyDescriptor,Fe=(e,n,r,t)=>{for(var i=t>1?void 0:t?Le(n,r):n,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=o(i)||i);return i},N=(e,n)=>(r,t)=>n(r,t,e);const ce="SHEET_NUMFMT_PANEL";let H=class extends s.Disposable{constructor(n,r,t,i,a,o,u,c,v,f,m){super();K(this,"_previewPattern","");K(this,"_sidebarDisposable",null);this._sheetInterceptorService=n,this._themeService=r,this._univerInstanceService=t,this._commandService=i,this._selectionManagerService=a,this._renderManagerService=o,this._numfmtService=u,this._componentManager=c,this._sidebarService=v,this._localeService=f,this._sheetsNumfmtCellContentController=m,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener(),this._initNumfmtLocalChange()}_initNumfmtLocalChange(){this.disposeWithMe(x.merge(this._sheetsNumfmtCellContentController.local$,this._localeService.currentLocale$).subscribe(()=>{this._forceUpdate()}))}openPanel(){var P;const n=this._sidebarService,r=this._selectionManagerService,t=this._commandService,i=this._univerInstanceService,a=this._numfmtService,o=this._localeService,c=(((P=r.getCurrentSelections())==null?void 0:P.map(I=>I.range))||[])[0];if(!c)return!1;const v=i.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),f=v.getActiveSheet();if(!f)return!1;const m=f.getCellRaw(c.startRow,c.startColumn),h=a.getValue(v.getUnitId(),f.getSheetId(),c.startRow,c.startColumn);let S="";h&&(S=h.pattern);const b=(m==null?void 0:m.t)===s.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 O=((M=r.getCurrentSelections())==null?void 0:M.map(R=>R.range))||[],U={values:[]},te=d.getPatternType(I.value);O.forEach(R=>{s.Range.foreach(R,(ne,E)=>{U.values.push({row:ne,col:E,pattern:I.value,type:te})})}),t.executeCommand(d.SetNumfmtCommand.id,U),n.close()}else I.type==="cancel"&&n.close()},value:{defaultPattern:S,defaultValue:b,row:c.startRow,col:c.startColumn}};return this._sidebarDisposable=n.open({header:{title:o.t("sheet.numfmt.title")},children:{label:ce,...p},onClose:()=>{this._forceUpdate(),t.executeCommand(z.id)}}),!0}_forceUpdate(n){var t;const r=this._renderManagerService.getRenderById(n!=null?n:this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET).getUnitId());r==null||r.with(D.SheetSkeletonManagerService).reCalculate(),(t=r==null?void 0:r.mainComponent)==null||t.makeDirty()}_initCommands(){[L,z].forEach(n=>{this.disposeWithMe(this._commandService.registerCommand(n))})}_initPanel(){this.disposeWithMe(this._componentManager.register(ce,$e))}_initRealTimeRenderingInterceptor(){const n=new x.Observable(t=>{this._commandService.onCommandExecuted(i=>{i.id===L.id&&t.next(!0),i.id===z.id&&t.next(!1)})}),r=x.combineLatest([n,this._selectionManagerService.selectionMoveEnd$.pipe(V.map(t=>t?t.map(i=>i.range):[]))]);this.disposeWithMe(s.toDisposable(r.pipe(V.switchMap(([t,i])=>new x.Observable(a=>{const o=new s.DisposableCollection;return t&&i.length&&a.next({selectionRanges:i,disposableCollection:o}),()=>{o.dispose()}})),V.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:t,selectionRanges:i})=>{var o,u;const a=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);this.openPanel(),t.add(this._sheetInterceptorService.intercept(g.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,effect:s.InterceptorEffectEnum.Value|s.InterceptorEffectEnum.Style,handler:(c,v,f)=>{var b;const{row:m,col:h}=v,S=f(c)||{};if(i.find(p=>p.startColumn<=h&&p.endColumn>=h&&p.startRow<=m&&p.endRow>=m)){const p=v.worksheet.getCellRaw(m,h),P=p==null?void 0:p.v,I=p==null?void 0:p.t;if(P==null||I!==s.CellValueType.NUMBER||this._previewPattern===null)return S;const M=d.getPatternPreviewIgnoreGeneral(this._previewPattern,P,this._sheetsNumfmtCellContentController.local);if(M.color){const O=(b=this._themeService.getColorFromTheme(`${M.color}.500`))!=null?b:M.color;return{...S,v:M.result,t:s.CellValueType.STRING,s:{cl:{rgb:O}}}}return{...S,v:M.result,t:s.CellValueType.STRING}}return S}})),(u=(o=this._renderManagerService.getRenderById(a.getUnitId()))==null?void 0:o.mainComponent)==null||u.makeDirty()})))}_commandExecutedListener(){const n=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id];this.disposeWithMe(new x.Observable(r=>{const t=this._commandService.onCommandExecuted(i=>{if(n.includes(i.id)){const a=i.params;r.next(a.unitId)}});return()=>t.dispose()}).pipe(V.debounceTime(16)).subscribe(r=>this._forceUpdate(r)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_SHEET).subscribe(n=>{var r;n||((r=this._sidebarDisposable)==null||r.dispose(),this._sidebarDisposable=null)})}};H=Fe([N(0,s.Inject(g.SheetInterceptorService)),N(1,s.Inject(s.ThemeService)),N(2,s.IUniverInstanceService),N(3,s.ICommandService),N(4,s.Inject(g.SheetsSelectionsService)),N(5,k.IRenderManagerService),N(6,g.INumfmtService),N(7,s.Inject(_.ComponentManager)),N(8,_.ISidebarService),N(9,s.Inject(s.LocaleService)),N(10,s.Inject(d.SheetsNumfmtCellContentController))],H);var He=Object.getOwnPropertyDescriptor,Ae=(e,n,r,t)=>{for(var i=t>1?void 0:t?He(n,r):n,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=o(i)||i);return i},A=(e,n)=>(r,t)=>n(r,t,e);const Re=()=>{let e=[];return{add:(i,a,o,u,c)=>e.push({unitId:i,subUnitId:a,row:o,col:u,value:c}),getEffects:()=>e,clean:()=>{e=[]}}};let B=class extends s.Disposable{constructor(n,r,t,i,a){super();K(this,"_collectEffectMutation",Re());this._sheetInterceptorService=n,this._numfmtService=r,this._univerInstanceService=t,this._injector=i,this._editorBridgeService=a,this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(s.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.BEFORE_CELL_EDIT,{handler:(n,r,t)=>{const i=r.row,a=r.col,o=this._numfmtService.getValue(r.unitId,r.subUnitId,i,a);if(o)switch(d.getPatternType(o.pattern)){case"scientific":case"currency":case"grouped":case"number":{const c=r.worksheet.getCellRaw(i,a);return t&&t(c)}case"percent":case"date":case"time":case"datetime":default:return t&&t(n)}return t(n)}})))}_initInterceptorEditorEnd(){this.disposeWithMe(s.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.AFTER_CELL_EDIT,{handler:(n,r,t)=>{var c,v,f;this._collectEffectMutation.clean();const i=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col);if(!(n!=null&&n.v)&&!(n!=null&&n.p)||W.isTextFormat(i==null?void 0:i.pattern)||n.t===s.CellValueType.FORCE_STRING)return t(n);const a=(c=n.p)==null?void 0:c.body,o=(f=(v=n==null?void 0:n.p)==null?void 0:v.body)!=null&&f.dataStream?n.p.body.dataStream.replace(/\r\n$/,""):String(n.v),u=s.numfmt.parseDate(o)||s.numfmt.parseTime(o)||s.numfmt.parseNumber(o);if(a)if(We(a)){const{dataStream:m}=a,h=m.replace(/\r\n$/,""),S=Number(h);if(Number.isNaN(S)&&!u)return t(n)}else return t(n);if(u){if(!u.z&&s.willLoseNumericPrecision(o))return t({...n,p:void 0,v:o,t:s.CellValueType.FORCE_STRING});u.z&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:u.z});const m=Number(u.v);return t({...n,p:void 0,v:m,t:s.CellValueType.NUMBER})}return t(n)}})))}_initInterceptorCommands(){const n=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(r){var t;switch(r.id){case g.SetRangeValuesCommand.id:{const i=n._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),a=i.getUnitId(),o=(t=i.getActiveSheet())==null?void 0:t.getSheetId();if(!o)return{redos:[],undos:[]};const u=n._collectEffectMutation.getEffects();if(n._collectEffectMutation.clean(),!u.length)return{redos:[],undos:[]};const c=u.filter(h=>{var S;return!!((S=h.value)!=null&&S.pattern)}).map(h=>({row:h.row,col:h.col,pattern:h.value.pattern})),v=u.filter(h=>{var S;return!((S=h.value)!=null&&S.pattern)}).map(h=>({startRow:h.row,endColumn:h.col,startColumn:h.col,endRow:h.row})),f=[],m=[];if(c.length){const h={id:g.SetNumfmtMutation.id,params:g.transformCellsToRange(a,o,c)};f.push(h),m.push(...g.factorySetNumfmtUndoMutation(n._injector,h.params))}if(v.length){const h={id:g.RemoveNumfmtMutation.id,params:{unitId:a,subUnitId:o,ranges:v}};f.push(h),m.push(...g.factoryRemoveNumfmtUndoMutation(n._injector,h.params))}return{redos:f,undos:m.reverse()}}}return{redos:[],undos:[]}}}))}};B=Ae([A(0,s.Inject(g.SheetInterceptorService)),A(1,s.Inject(g.INumfmtService)),A(2,s.Inject(s.IUniverInstanceService)),A(3,s.Inject(s.Injector)),A(4,s.Optional(D.IEditorBridgeService))],B);function We(e){const{textRuns:n=[],paragraphs:r=[],customRanges:t,customBlocks:i=[]}=e,a=["va"];return!(n.some(o=>!!(o.ts&&Object.keys(o.ts).some(c=>a.includes(c))))||r.some(o=>o.bullet)||r.length>=2||t!=null&&t.length||i.length>0)}const q=[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:W.DEFAULT_TEXT_FORMAT_EXCEL},"|",{label:"sheet.numfmt.number",pattern:"0"},{label:"sheet.numfmt.percent",pattern:"0.00%"},{label:"sheet.numfmt.scientific",pattern:"0.00E+00"},"|",{label:"sheet.numfmt.accounting",pattern:'"¥" #,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.financialValue",pattern:"#,##0.00;[Red]#,##0.00"},{label:"sheet.numfmt.currency",pattern:'"¥"#,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.roundingCurrency",pattern:'"¥"#,##0;[Red]"¥"#,##0'},"|",{label:"sheet.numfmt.date",pattern:"yyyy-mm-dd;@"},{label:"sheet.numfmt.time",pattern:'am/pm h":"mm":"ss'},{label:"sheet.numfmt.dateTime",pattern:"yyyy-m-d am/pm h:mm"},{label:"sheet.numfmt.timeDuration",pattern:"h:mm:ss"},"|",{label:"sheet.numfmt.moreFmt",pattern:""}],Ve=e=>({icon:new x.Observable(n=>{var a;const r=e.get(d.MenuCurrencyService);function t(o){var c;return(c={[d.countryCurrencyMap.US]:"DollarIcon",[d.countryCurrencyMap.RU]:"RoubleIcon",[d.countryCurrencyMap.CN]:"RmbIcon",[d.countryCurrencyMap.AT]:"EuroIcon"}[o])!=null?c:"DollarIcon"}const i=(a=d.countryCurrencyMap[r.getCurrencySymbol()])!=null?a:"$";return n.next(t(i)),r.currencySymbol$.subscribe(o=>{var c;const u=(c=d.countryCurrencyMap[o])!=null?c:"$";n.next(t(u))})}),id:d.SetCurrencyCommand.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Be=e=>({icon:"AddDigitsIcon",id:d.AddDecimalCommand.id,title:"sheet.numfmt.addDecimal",tooltip:"sheet.numfmt.addDecimal",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),qe=e=>({icon:"ReduceDigitsIcon",id:d.SubtractDecimalCommand.id,title:"sheet.numfmt.subtractDecimal",tooltip:"sheet.numfmt.subtractDecimal",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Ge=e=>({icon:"PercentIcon",id:d.SetPercentCommand.id,title:"sheet.numfmt.percent",tooltip:"sheet.numfmt.percent",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Ke=e=>{const n=e.get(s.IUniverInstanceService),r=e.get(s.ICommandService),t=e.get(s.LocaleService),i=e.get(g.SheetsSelectionsService),a=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id],o=D.deriveStateFromActiveSheet$(n,"",({workbook:u,worksheet:c})=>new x.Observable(v=>x.merge(i.selectionMoveEnd$,s.fromCallback(r.onCommandExecuted.bind(r)).pipe(x.filter(([f])=>a.includes(f.id)))).subscribe(()=>{var m,h;const f=i.getCurrentSelections();if(f&&f[0]){const S=f[0].range,b=S.startRow,p=S.startColumn,P=(h=u.getStyles().get((m=c.getCell(b,p))==null?void 0:m.s))==null?void 0:h.n,I=P==null?void 0:P.pattern;let M=t.t("sheet.numfmt.general");if(W.isDefaultFormat(I)){v.next(M);return}if(I){const O=q.filter(U=>typeof U=="object"&&U.pattern).find(U=>s.isPatternEqualWithoutDecimal(I,U.pattern));O&&typeof O=="object"&&O.pattern?M=t.t(O.label):M=t.t("sheet.numfmt.moreFmt")}v.next(M)}})));return{label:le,id:L.id,tooltip:"sheet.numfmt.title",type:_.MenuItemType.SELECTOR,slot:!0,selections:[{label:{name:ue,hoverable:!1,selectable:!1}}],value$:o,hidden$:_.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetSetCellStylePermission,g.WorksheetEditPermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}},le="sheet.numfmt.moreNumfmtType",ue="sheet.numfmt.moreNumfmtType.options",Ze=e=>{const{value:n}=e,r=_.useDependency(s.LocaleService),t=n!=null?n:r.t("sheet.numfmt.general");return l.jsx("span",{className:"univer-text-sm",children:t})},Ye=()=>{const e=_.useDependency(s.ICommandService),n=_.useDependency(s.LocaleService),r=_.useDependency(_.ILayoutService),t=_.useDependency(d.SheetsNumfmtCellContentController),i=_.useDependency(g.SheetsSelectionsService),a=c=>{const v=i.getCurrentLastSelection();if(!v)return;const f=v.range,m=[];s.Range.foreach(f,(h,S)=>{c?m.push({row:h,col:S,pattern:c,type:d.getPatternType(c)}):m.push({row:h,col:S})}),e.executeCommand(d.SetNumfmtCommand.id,{values:m}),r.focus()},o=c=>{if(c===0)a(null);else if(c===q.length-1)e.executeCommand(L.id),r.focus();else{const v=q[c];v.pattern&&a(v.pattern)}},u=1220;return l.jsx("div",{className:"univer-grid univer-gap-1 univer-p-1.5",children:q.map((c,v)=>c==="|"?l.jsx(T.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 dark:hover:!univer-bg-gray-700 hover:univer-bg-gray-100",onClick:()=>{o(v)},children:[l.jsx("span",{children:n.t(c.label)}),l.jsx("span",{className:"univer-text-xs univer-text-gray-500",children:c.pattern?d.getPatternPreview(c.pattern||"",u,t.local).result.trim():""})]},v))})},ze={[_.RibbonDataGroup.FORMULAS]:{[d.SetCurrencyCommand.id]:{order:0,menuItemFactory:Ve},[d.AddDecimalCommand.id]:{order:1,menuItemFactory:Be},[d.SubtractDecimalCommand.id]:{order:2,menuItemFactory:qe},[d.SetPercentCommand.id]:{order:3,menuItemFactory:Ge},[L.id]:{order:4,menuItemFactory:Ke}}};var Xe=Object.getOwnPropertyDescriptor,Je=(e,n,r,t)=>{for(var i=t>1?void 0:t?Xe(n,r):n,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=o(i)||i);return i},me=(e,n)=>(r,t)=>n(r,t,e);let G=class extends s.Disposable{constructor(e,n){super(),this._componentManager=e,this._menuManagerService=n,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(ze),[[le,Ze],[ue,Ye]].forEach(([e,n])=>{this.disposeWithMe(this._componentManager.register(e,n))})}};G=Je([me(0,s.Inject(_.ComponentManager)),me(1,_.IMenuManagerService)],G);var Qe=Object.defineProperty,et=Object.getOwnPropertyDescriptor,tt=(e,n,r)=>n in e?Qe(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r,nt=(e,n,r,t)=>{for(var i=t>1?void 0:t?et(n,r):n,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=o(i)||i);return i},ee=(e,n)=>(r,t)=>n(r,t,e),de=(e,n,r)=>tt(e,typeof n!="symbol"?n+"":n,r);const rt="SHEET_NUMFMT_UI_PLUGIN";C.UniverSheetsNumfmtUIPlugin=class extends s.Plugin{constructor(n=re,r,t,i){super(),this._config=n,this._injector=r,this._configService=t,this._renderManagerService=i;const{menu:a,...o}=s.merge({},re,this._config);a&&this._configService.setConfig("menu",a,{merge:!0}),this._configService.setConfig("sheets-numfmt-ui.config",o)}onStarting(){s.registerDependencies(this._injector,[[H],[B],[F],[G]])}onRendered(){this._registerRenderModules(),s.touchDependencies(this._injector,[[H],[B],[G]])}_registerRenderModules(){[[Y]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(s.UniverInstanceType.UNIVER_SHEET,r))})}},de(C.UniverSheetsNumfmtUIPlugin,"pluginName",rt),de(C.UniverSheetsNumfmtUIPlugin,"type",s.UniverInstanceType.UNIVER_SHEET),C.UniverSheetsNumfmtUIPlugin=nt([s.DependentOn(D.UniverSheetsUIPlugin,d.UniverSheetsNumfmtPlugin),ee(1,s.Inject(s.Injector)),ee(2,s.IConfigService),ee(3,k.IRenderManagerService)],C.UniverSheetsNumfmtUIPlugin),Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(C,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/sheets-numfmt"),require("@univerjs/sheets-ui"),require("@univerjs/engine-numfmt"),require("@univerjs/sheets"),require("@univerjs/ui"),require("rxjs"),require("rxjs/operators"),require("react/jsx-runtime"),require("react"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","@univerjs/sheets-numfmt","@univerjs/sheets-ui","@univerjs/engine-numfmt","@univerjs/sheets","@univerjs/ui","rxjs","rxjs/operators","react/jsx-runtime","react","@univerjs/design"],s):(C=typeof globalThis<"u"?globalThis:C||self,s(C.UniverSheetsNumfmtUi={},C.UniverCore,C.UniverEngineRender,C.UniverSheetsNumfmt,C.UniverSheetsUi,C.UniverEngineNumfmt,C.UniverSheets,C.UniverUi,C.rxjs,C.rxjs.operators,C.React,C.React,C.UniverDesign))})(this,function(C,s,k,d,D,W,g,_,x,V,l,y,T){"use strict";var st=Object.defineProperty;var ot=(C,s,k)=>s in C?st(C,s,{enumerable:!0,configurable:!0,writable:!0,value:k}):C[s]=k;var K=(C,s,k)=>ot(C,typeof s!="symbol"?s+"":s,k);const re={};var ve=Object.getOwnPropertyDescriptor,pe=(e,n,r,t)=>{for(var i=t>1?void 0:t?ve(n,r):n,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=o(i)||i);return i},j=(e,n)=>(r,t)=>n(r,t,e);const Z="SHEET_NUMFMT_ALERT";let Y=class extends s.Disposable{constructor(e,n,r,t,i,a,o){super(),this._context=e,this._hoverManagerService=n,this._cellAlertManagerService=r,this._localeService=t,this._zenZoneService=i,this._numfmtService=a,this._configService=o,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(x.debounceTime(100)).subscribe(e=>{var n,r;if(e){const t=e.location,i=this._context.unit,a=i.getActiveSheet();if(!a)return;const o=t.unitId,u=t.subUnitId;let c;const v=a.getCell(t.row,t.col);if(v!=null&&v.s){const f=i.getStyles().get(v.s);f!=null&&f.n&&(c=f.n)}if(c||(c=this._numfmtService.getValue(o,u,t.row,t.col)),!c){this._hideAlert();return}if(W.isTextFormat(c.pattern)&&(v!=null&&v.v)&&s.isRealNum(v.v)){if((n=this._configService.getConfig(d.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY))!=null&&n.disableTextFormatAlert)return;const f=this._cellAlertManagerService.currentAlert.get(Z),m=(r=f==null?void 0:f.alert)==null?void 0:r.location;if(m&&m.row===t.row&&m.col===t.col&&m.subUnitId===t.subUnitId&&m.unitId===t.unitId)return;this._cellAlertManagerService.showAlert({type:D.CellAlertType.ERROR,title:this._localeService.t("info.error"),message:this._localeService.t("info.forceStringInfo"),location:t,width:200,height:74,key:Z});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(Z)}};Y=pe([j(1,s.Inject(D.HoverManagerService)),j(2,s.Inject(D.CellAlertManagerService)),j(3,s.Inject(s.LocaleService)),j(4,_.IZenZoneService),j(5,s.Inject(g.INumfmtService)),j(6,s.IConfigService)],Y);const z={id:"sheet.operation.close.numfmt.panel",type:s.CommandType.OPERATION,handler:()=>!0},L={id:"sheet.operation.open.numfmt.panel",type:s.CommandType.OPERATION,handler:e=>(e.get(H).openPanel(),!0)};var fe=Object.getOwnPropertyDescriptor,he=(e,n,r,t)=>{for(var i=t>1?void 0:t?fe(n,r):n,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=o(i)||i);return i},ge=(e,n)=>(r,t)=>n(r,t,e);const X=y.createContext([]);let F=class{constructor(e){this._localStorageService=e}_getKey(e){return`userHabitController_${e}`}async addHabit(e,n){const r=this._getKey(e);return this._localStorageService.getItem(r).then(t=>{t||this._localStorageService.setItem(r,n)})}markHabit(e,n){const r=this._getKey(e);this._localStorageService.getItem(r).then(t=>{if(t){const i=t.findIndex(a=>a===n);i>-1&&t.splice(i,1),t.unshift(n),this._localStorageService.setItem(r,t)}})}async getHabit(e,n){const r=this._getKey(e),t=await this._localStorageService.getItem(r);if(n&&t){const i=t.map((a,o,u)=>{const c=u.length;return{value:a,priority:c-o}});return n.sort((a,o)=>{var v,f;const u=((v=i.find(m=>m.value===a))==null?void 0:v.priority)||-1;return(((f=i.find(m=>m.value===o))==null?void 0:f.priority)||-1)-u})}return t||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};F=he([ge(0,s.Inject(s.ILocalStorageService))],F);const ie="numfmtCurrency",Se=e=>{const n=_.useDependency(F),[r,t]=y.useState(d.currencySymbols);return y.useEffect(()=>{n.addHabit("numfmtCurrency",[]).then(()=>{n.getHabit(ie,[...d.currencySymbols]).then(a=>{t(a),e&&e(a)})})},[]),{userHabitCurrency:r,mark:a=>{n.markHabit(ie,a)}}},ye=()=>{const e=y.useRef([]),[n,r]=y.useState({});return y.useEffect(()=>{e.current.forEach(i=>{i()}),e.current=[]},[n]),i=>{e.current.push(i),r({})}},_e=e=>!!d.getCurrencyType(e)&&e.startsWith("_("),Ce=e=>{const{defaultPattern:n,action:r,onChange:t}=e,[i,a]=y.useState(()=>d.getDecimalFromPattern(n||"",2)),o=y.useContext(X),[u,c]=y.useState(()=>d.getCurrencyType(n)||o[0]),v=y.useMemo(()=>o.map(b=>({label:b,value:b})),[]),m=_.useDependency(s.LocaleService).t;r.current=()=>d.setPatternDecimal(`_("${u}"* #,##0${i>0?".0":""}_)`,i);const h=b=>{c(b),t(d.setPatternDecimal(`_("${b}"* #,##0${i>0?".0":""}_)`,i))},S=b=>{const p=b||0;a(p),t(d.setPatternDecimal(`_("${u}"* #,##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(T.InputNumber,{value:i,step:1,precision:0,max:20,min:0,onChange:S})})]}),l.jsxs("div",{className:"option",children:[l.jsx("div",{className:"univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.currencyType")}),l.jsx("div",{className:"univer-mt-2 univer-w-36",children:l.jsx(T.Select,{options:v,value:u,onChange:h})})]})]}),l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:m("sheet.numfmt.accountingDes")})]})},be=e=>!!d.getCurrencyType(e)&&!e.startsWith("_("),Ie=e=>{const r=_.useDependency(s.LocaleService).t,t=y.useContext(X),[i,a]=y.useState(()=>d.getCurrencyType(e.defaultPattern)||t[0]),[o,u]=y.useState(()=>d.getDecimalFromPattern(e.defaultPattern||"",2)),[c,v]=y.useState(()=>{var I;const p=d.getCurrencyFormatOptions(i);return((I=p.find(M=>s.isPatternEqualWithoutDecimal(M.value,e.defaultPattern)))==null?void 0:I.value)||p[0].value}),f=y.useMemo(()=>d.getCurrencyFormatOptions(i),[i]),m=y.useMemo(()=>t.map(p=>({label:p,value:p})),[t]);e.action.current=()=>d.setPatternDecimal(c,o);const h=p=>{if(p===void 0)return;a(p);const P=d.getCurrencyFormatOptions(p)[0].value;v(P),e.onChange(d.setPatternDecimal(P,o))},S=p=>{p!==void 0&&(v(p),e.onChange(d.setPatternDecimal(p,o)))},b=p=>{u(p||0),e.onChange(d.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(T.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(T.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(T.SelectList,{value:c,options:f,onChange:S})}),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 n,r=1,t=arguments.length;r<t;r++){n=arguments[r];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e},w.apply(this,arguments)},Ee=function(e,n){var r={};for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&n.indexOf(t)<0&&(r[t]=e[t]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,t=Object.getOwnPropertySymbols(e);i<t.length;i++)n.indexOf(t[i])<0&&Object.prototype.propertyIsEnumerable.call(e,t[i])&&(r[t[i]]=e[t[i]]);return r},ae=y.forwardRef(function(e,n){var r=e.icon,t=e.id,i=e.className,a=e.extend,o=Ee(e,["icon","id","className","extend"]),u="univerjs-icon univerjs-icon-".concat(t," ").concat(i||"").trim(),c=y.useRef("_".concat(Me()));return se(r,"".concat(t),{defIds:r.defIds,idSuffix:c.current},w({ref:n,className:u},o),a)});function se(e,n,r,t,i){return y.createElement(e.tag,w(w({key:n},Te(e,r,i)),t),(Pe(e,r).children||[]).map(function(a,o){return se(a,"".concat(n,"-").concat(e.tag,"-").concat(o),r,void 0,i)}))}function Te(e,n,r){var t=w({},e.attrs);r!=null&&r.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=r.colorChannel1),e.tag==="mask"&&t.id&&(t.id=t.id+n.idSuffix),Object.entries(t).forEach(function(a){var o=a[0],u=a[1];o==="mask"&&typeof u=="string"&&(t[o]=u.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))});var i=n.defIds;return!i||i.length===0||(e.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+n.idSuffix),Object.entries(t).forEach(function(a){var o=a[0],u=a[1];typeof u=="string"&&(t[o]=u.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),t}function Pe(e,n){var r,t=n.defIds;return!t||t.length===0?e:e.tag==="defs"&&(!((r=e.children)===null||r===void 0)&&r.length)?w(w({},e),{children:e.children.map(function(i){return typeof i.attrs.id=="string"&&t&&t.includes(i.attrs.id)?w(w({},i),{attrs:w(w({},i.attrs),{id:i.attrs.id+n.idSuffix})}):i})}):e}function Me(){return Math.random().toString(36).substring(2,8)}ae.displayName="UniverIcon";var De={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"}}]},oe=y.forwardRef(function(e,n){return y.createElement(ae,Object.assign({},e,{id:"check-mark-icon",ref:n,icon:De}))});oe.displayName="CheckMarkIcon";const J="customFormat",Q="numfmt_custom_pattern";function we(e){const{defaultPattern:n,action:r,onChange:t}=e,i=_.useDependency(F),a=_.useDependency(s.ILocalStorageService),o=_.useDependency(s.LocaleService),[u,c]=y.useState(n);r.current=()=>(i.markHabit(J,u),a.getItem(Q).then((S=[])=>{const b=[...new Set([u,...S||[]])].splice(0,10).filter(p=>!!p);a.setItem(Q,b)}),u);const[v,f]=y.useState([]);y.useEffect(()=>{a.getItem(Q).then(S=>{const b=[...d.CURRENCYFORMAT.map(p=>p.suffix("$")),...d.DATEFMTLISG.map(p=>p.suffix),...d.NUMBERFORMAT.map(p=>p.suffix)];b.push(...S||[]),i.addHabit(J,[]).finally(()=>{i.getHabit(J,b).then(p=>{f([...new Set(p)])})})})},[]);const m=S=>{c(S),t(S)},h=()=>{t(u)};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(T.Input,{placeholder:o.t("sheet.numfmt.customFormat"),onBlur:h,value:u,onChange:c,className:"univer-mt-2 univer-w-full"}),l.jsx("div",{className:T.clsx("univer-mt-2 univer-max-h-[400px] univer-overflow-auto univer-rounded-lg univer-p-2",T.borderClassName),children:v.map(S=>l.jsxs("div",{onClick:()=>m(S),className:"univer-flex univer-cursor-pointer univer-items-center univer-gap-1.5 univer-py-1.5 univer-text-sm",children:[l.jsx("div",{className:"univer-flex univer-w-4 univer-items-center univer-text-primary-600",children:u===S&&l.jsx(oe,{})}),l.jsx("div",{children:S})]},S))}),l.jsx("div",{className:"univer-mt-3 univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200",children:o.t("sheet.numfmt.customFormatDes")})]})}const Ne=e=>{const n=s.numfmt.getFormatInfo(e);return d.getDateFormatOptions().map(r=>r.value).includes(e)||["date","datetime","time"].includes(n.type)};function xe(e){const{onChange:n,defaultPattern:r}=e,t=y.useMemo(d.getDateFormatOptions,[]),i=_.useDependency(s.LocaleService),[a,o]=y.useState(()=>{if(r){const c=t.find(v=>v.value===r);if(c)return c.value}return t[0].value});e.action.current=()=>a;const u=c=>{c!==void 0&&(o(c),n(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(T.SelectList,{value:a,options:t,onChange:u})}),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 Oe=e=>!e,Ue=e=>{const r=_.useDependency(s.LocaleService).t;return e.action.current=()=>"",l.jsx("div",{children:l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:r("sheet.numfmt.generalDes")})})},ke=e=>d.getNumberFormatOptions().some(n=>s.isPatternEqualWithoutDecimal(n.value,e));function je(e){const n=_.useDependency(s.LocaleService),r=y.useMemo(d.getNumberFormatOptions,[]),[t,i]=y.useState(()=>d.getDecimalFromPattern(e.defaultPattern||"",0)),[a,o]=y.useState(()=>{const m=r.find(h=>s.isPatternEqualWithoutDecimal(h.value,e.defaultPattern||""));return(m==null?void 0:m.value)||r[0].value}),u=y.useMemo(()=>d.setPatternDecimal(a,Number(t||0)),[a,t]),c=y.useMemo(()=>!d.isPatternHasDecimal(a),[a]),v=m=>{i(m||0),e.onChange(d.setPatternDecimal(a,Number(m||0)))},f=m=>{m!==void 0&&(i(d.getDecimalFromPattern(m,0)),o(m),e.onChange(m))};return e.action.current=()=>u,l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:n.t("sheet.numfmt.decimalLength")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(T.InputNumber,{disabled:c,value:t,max:20,min:0,onChange:v})}),l.jsxs("div",{className:"univer-mt-4 univer-text-sm univer-text-gray-400",children:[" ",n.t("sheet.numfmt.negType")]}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(T.SelectList,{onChange:f,options:r,value:a})}),l.jsx("div",{className:"univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",children:n.t("sheet.numfmt.thousandthPercentileDes")})]})}const $e=e=>{const{defaultValue:n,defaultPattern:r,row:t,col:i}=e.value,a=_.useDependency(s.LocaleService),o=y.useRef(()=>""),u=a.t,c=ye(),v=y.useMemo(()=>[{label:"sheet.numfmt.general",component:Ue},{label:"sheet.numfmt.accounting",component:Ce},{label:"sheet.numfmt.currency",component:Ie},{label:"sheet.numfmt.date",component:xe},{label:"sheet.numfmt.thousandthPercentile",component:je},{label:"sheet.numfmt.customFormat",component:we}].map(E=>({...E,label:u(E.label)})),[]),[f,m]=y.useState(I),[h,S]=y.useState(()=>`${t}_${i}`),{mark:b,userHabitCurrency:p}=Se(()=>S(`${t}_${i}_userCurrency'`)),P=y.useMemo(()=>{var E;return(E=v.find($=>$.label===f))==null?void 0:E.component},[f]);function I(){return[Oe,_e,be,Ne,ke].reduce(($,it,at)=>$||(it(r)?v[at].label:""),"")||v[0].label}const M=v.map(E=>({label:E.label,value:E.label})),O=E=>{m(E),c(()=>e.onChange({type:"change",value:o.current()||""}))},U=y.useCallback(E=>{e.onChange({type:"change",value:E})},[]),te=()=>{const E=o.current()||"",$=d.getCurrencyType(E);$&&b($),e.onChange({type:"confirm",value:E})},R=()=>{e.onChange({type:"cancel",value:""})},ne={onChange:U,defaultValue:n,defaultPattern:r,action:o};return y.useEffect(()=>{m(I()),S(`${t}_${i}`)},[t,i]),l.jsxs("div",{className:T.clsx("univer-flex univer-h-full univer-flex-col univer-justify-between univer-overflow-y-auto univer-pb-5",T.scrollbarClassName),children:[l.jsxs("div",{children:[l.jsx("div",{className:"univer-mt-3.5 univer-text-sm univer-text-gray-400",children:u("sheet.numfmt.numfmtType")}),l.jsx("div",{className:"univer-mt-2",children:l.jsx(T.Select,{className:"univer-w-full",value:f,options:M,onChange:O})}),l.jsx("div",{children:P&&l.jsx(X.Provider,{value:p,children:y.createElement(P,{...ne,key:h})})})]}),l.jsxs("div",{className:"univer-mb-5 univer-mt-3.5 univer-flex univer-justify-end",children:[l.jsx(T.Button,{onClick:R,className:"univer-mr-3",children:u("sheet.numfmt.cancel")}),l.jsx(T.Button,{variant:"primary",onClick:te,children:u("sheet.numfmt.confirm")})]})]})};var Le=Object.getOwnPropertyDescriptor,Fe=(e,n,r,t)=>{for(var i=t>1?void 0:t?Le(n,r):n,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=o(i)||i);return i},N=(e,n)=>(r,t)=>n(r,t,e);const ce="SHEET_NUMFMT_PANEL";let H=class extends s.Disposable{constructor(n,r,t,i,a,o,u,c,v,f,m){super();K(this,"_previewPattern","");K(this,"_sidebarDisposable",null);this._sheetInterceptorService=n,this._themeService=r,this._univerInstanceService=t,this._commandService=i,this._selectionManagerService=a,this._renderManagerService=o,this._numfmtService=u,this._componentManager=c,this._sidebarService=v,this._localeService=f,this._sheetsNumfmtCellContentController=m,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener(),this._initNumfmtLocalChange()}_initNumfmtLocalChange(){this.disposeWithMe(x.merge(this._sheetsNumfmtCellContentController.local$,this._localeService.currentLocale$).subscribe(()=>{this._forceUpdate()}))}openPanel(){var P;const n=this._sidebarService,r=this._selectionManagerService,t=this._commandService,i=this._univerInstanceService,a=this._numfmtService,o=this._localeService,c=(((P=r.getCurrentSelections())==null?void 0:P.map(I=>I.range))||[])[0];if(!c)return!1;const v=i.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),f=v.getActiveSheet();if(!f)return!1;const m=f.getCellRaw(c.startRow,c.startColumn),h=a.getValue(v.getUnitId(),f.getSheetId(),c.startRow,c.startColumn);let S="";h&&(S=h.pattern);const b=(m==null?void 0:m.t)===s.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 O=((M=r.getCurrentSelections())==null?void 0:M.map(R=>R.range))||[],U={values:[]},te=d.getPatternType(I.value);O.forEach(R=>{s.Range.foreach(R,(ne,E)=>{U.values.push({row:ne,col:E,pattern:I.value,type:te})})}),t.executeCommand(d.SetNumfmtCommand.id,U),n.close()}else I.type==="cancel"&&n.close()},value:{defaultPattern:S,defaultValue:b,row:c.startRow,col:c.startColumn}};return this._sidebarDisposable=n.open({header:{title:o.t("sheet.numfmt.title")},children:{label:ce,...p},onClose:()=>{this._forceUpdate(),t.executeCommand(z.id)}}),!0}_forceUpdate(n){var t;const r=this._renderManagerService.getRenderById(n!=null?n:this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET).getUnitId());r==null||r.with(D.SheetSkeletonManagerService).reCalculate(),(t=r==null?void 0:r.mainComponent)==null||t.makeDirty()}_initCommands(){[L,z].forEach(n=>{this.disposeWithMe(this._commandService.registerCommand(n))})}_initPanel(){this.disposeWithMe(this._componentManager.register(ce,$e))}_initRealTimeRenderingInterceptor(){const n=new x.Observable(t=>{this._commandService.onCommandExecuted(i=>{i.id===L.id&&t.next(!0),i.id===z.id&&t.next(!1)})}),r=x.combineLatest([n,this._selectionManagerService.selectionMoveEnd$.pipe(V.map(t=>t?t.map(i=>i.range):[]))]);this.disposeWithMe(s.toDisposable(r.pipe(V.switchMap(([t,i])=>new x.Observable(a=>{const o=new s.DisposableCollection;return t&&i.length&&a.next({selectionRanges:i,disposableCollection:o}),()=>{o.dispose()}})),V.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:t,selectionRanges:i})=>{var o,u;const a=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);this.openPanel(),t.add(this._sheetInterceptorService.intercept(g.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,effect:s.InterceptorEffectEnum.Value|s.InterceptorEffectEnum.Style,handler:(c,v,f)=>{var b;const{row:m,col:h}=v,S=f(c)||{};if(i.find(p=>p.startColumn<=h&&p.endColumn>=h&&p.startRow<=m&&p.endRow>=m)){const p=v.worksheet.getCellRaw(m,h),P=p==null?void 0:p.v,I=p==null?void 0:p.t;if(P==null||I!==s.CellValueType.NUMBER||this._previewPattern===null)return S;const M=d.getPatternPreviewIgnoreGeneral(this._previewPattern,P,this._sheetsNumfmtCellContentController.local);if(M.color){const O=(b=this._themeService.getColorFromTheme(`${M.color}.500`))!=null?b:M.color;return{...S,v:M.result,t:s.CellValueType.STRING,s:{cl:{rgb:O}}}}return{...S,v:M.result,t:s.CellValueType.STRING}}return S}})),(u=(o=this._renderManagerService.getRenderById(a.getUnitId()))==null?void 0:o.mainComponent)==null||u.makeDirty()})))}_commandExecutedListener(){const n=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id];this.disposeWithMe(new x.Observable(r=>{const t=this._commandService.onCommandExecuted(i=>{if(n.includes(i.id)){const a=i.params;r.next(a.unitId)}});return()=>t.dispose()}).pipe(V.debounceTime(16)).subscribe(r=>this._forceUpdate(r)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_SHEET).subscribe(n=>{var r;n||((r=this._sidebarDisposable)==null||r.dispose(),this._sidebarDisposable=null)})}};H=Fe([N(0,s.Inject(g.SheetInterceptorService)),N(1,s.Inject(s.ThemeService)),N(2,s.IUniverInstanceService),N(3,s.ICommandService),N(4,s.Inject(g.SheetsSelectionsService)),N(5,k.IRenderManagerService),N(6,g.INumfmtService),N(7,s.Inject(_.ComponentManager)),N(8,_.ISidebarService),N(9,s.Inject(s.LocaleService)),N(10,s.Inject(d.SheetsNumfmtCellContentController))],H);var He=Object.getOwnPropertyDescriptor,Ae=(e,n,r,t)=>{for(var i=t>1?void 0:t?He(n,r):n,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=o(i)||i);return i},A=(e,n)=>(r,t)=>n(r,t,e);const Re=()=>{let e=[];return{add:(i,a,o,u,c)=>e.push({unitId:i,subUnitId:a,row:o,col:u,value:c}),getEffects:()=>e,clean:()=>{e=[]}}};let B=class extends s.Disposable{constructor(n,r,t,i,a){super();K(this,"_collectEffectMutation",Re());this._sheetInterceptorService=n,this._numfmtService=r,this._univerInstanceService=t,this._injector=i,this._editorBridgeService=a,this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(s.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.BEFORE_CELL_EDIT,{handler:(n,r,t)=>{const i=r.row,a=r.col,o=this._numfmtService.getValue(r.unitId,r.subUnitId,i,a);if(o)switch(d.getPatternType(o.pattern)){case"scientific":case"currency":case"grouped":case"number":{const c=r.worksheet.getCellRaw(i,a);return t&&t(c)}case"percent":case"date":case"time":case"datetime":default:return t&&t(n)}return t(n)}})))}_initInterceptorEditorEnd(){this.disposeWithMe(s.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(g.AFTER_CELL_EDIT,{handler:(n,r,t)=>{var c,v,f;this._collectEffectMutation.clean();const i=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col);if(!(n!=null&&n.v)&&!(n!=null&&n.p)||W.isTextFormat(i==null?void 0:i.pattern)||n.t===s.CellValueType.FORCE_STRING)return t(n);const a=(c=n.p)==null?void 0:c.body,o=(f=(v=n==null?void 0:n.p)==null?void 0:v.body)!=null&&f.dataStream?n.p.body.dataStream.replace(/\r\n$/,""):String(n.v),u=s.numfmt.parseDate(o)||s.numfmt.parseTime(o)||s.numfmt.parseNumber(o);if(a)if(We(a)){const{dataStream:m}=a,h=m.replace(/\r\n$/,""),S=Number(h);if(Number.isNaN(S)&&!u)return t(n)}else return t(n);if(u){if(!u.z&&s.willLoseNumericPrecision(o))return t({...n,p:void 0,v:o,t:s.CellValueType.FORCE_STRING});u.z&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:u.z});const m=Number(u.v);return t({...n,p:void 0,v:m,t:s.CellValueType.NUMBER})}return t(n)}})))}_initInterceptorCommands(){const n=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(r){var t;switch(r.id){case g.SetRangeValuesCommand.id:{const i=n._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),a=i.getUnitId(),o=(t=i.getActiveSheet())==null?void 0:t.getSheetId();if(!o)return{redos:[],undos:[]};const u=n._collectEffectMutation.getEffects();if(n._collectEffectMutation.clean(),!u.length)return{redos:[],undos:[]};const c=u.filter(h=>{var S;return!!((S=h.value)!=null&&S.pattern)}).map(h=>({row:h.row,col:h.col,pattern:h.value.pattern})),v=u.filter(h=>{var S;return!((S=h.value)!=null&&S.pattern)}).map(h=>({startRow:h.row,endColumn:h.col,startColumn:h.col,endRow:h.row})),f=[],m=[];if(c.length){const h={id:g.SetNumfmtMutation.id,params:g.transformCellsToRange(a,o,c)};f.push(h),m.push(...g.factorySetNumfmtUndoMutation(n._injector,h.params))}if(v.length){const h={id:g.RemoveNumfmtMutation.id,params:{unitId:a,subUnitId:o,ranges:v}};f.push(h),m.push(...g.factoryRemoveNumfmtUndoMutation(n._injector,h.params))}return{redos:f,undos:m.reverse()}}}return{redos:[],undos:[]}}}))}};B=Ae([A(0,s.Inject(g.SheetInterceptorService)),A(1,s.Inject(g.INumfmtService)),A(2,s.Inject(s.IUniverInstanceService)),A(3,s.Inject(s.Injector)),A(4,s.Optional(D.IEditorBridgeService))],B);function We(e){const{textRuns:n=[],paragraphs:r=[],customRanges:t,customBlocks:i=[]}=e,a=["va"];return!(n.some(o=>!!(o.ts&&Object.keys(o.ts).some(c=>a.includes(c))))||r.some(o=>o.bullet)||r.length>=2||t!=null&&t.length||i.length>0)}const q=[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:W.DEFAULT_TEXT_FORMAT_EXCEL},"|",{label:"sheet.numfmt.number",pattern:"0"},{label:"sheet.numfmt.percent",pattern:"0.00%"},{label:"sheet.numfmt.scientific",pattern:"0.00E+00"},"|",{label:"sheet.numfmt.accounting",pattern:'"¥" #,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.financialValue",pattern:"#,##0.00;[Red]#,##0.00"},{label:"sheet.numfmt.currency",pattern:'"¥"#,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.roundingCurrency",pattern:'"¥"#,##0;[Red]"¥"#,##0'},"|",{label:"sheet.numfmt.date",pattern:"yyyy-mm-dd;@"},{label:"sheet.numfmt.time",pattern:'am/pm h":"mm":"ss'},{label:"sheet.numfmt.dateTime",pattern:"yyyy-m-d am/pm h:mm"},{label:"sheet.numfmt.timeDuration",pattern:"h:mm:ss"},"|",{label:"sheet.numfmt.moreFmt",pattern:""}],Ve=e=>({icon:new x.Observable(n=>{var a;const r=e.get(d.MenuCurrencyService);function t(o){var c;return(c={[d.countryCurrencyMap.US]:"DollarIcon",[d.countryCurrencyMap.RU]:"RoubleIcon",[d.countryCurrencyMap.CN]:"RmbIcon",[d.countryCurrencyMap.AT]:"EuroIcon"}[o])!=null?c:"DollarIcon"}const i=(a=d.countryCurrencyMap[r.getCurrencySymbol()])!=null?a:"$";return n.next(t(i)),r.currencySymbol$.subscribe(o=>{var c;const u=(c=d.countryCurrencyMap[o])!=null?c:"$";n.next(t(u))})}),id:d.SetCurrencyCommand.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Be=e=>({icon:"AddDigitsIcon",id:d.AddDecimalCommand.id,title:"sheet.numfmt.addDecimal",tooltip:"sheet.numfmt.addDecimal",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),qe=e=>({icon:"ReduceDigitsIcon",id:d.SubtractDecimalCommand.id,title:"sheet.numfmt.subtractDecimal",tooltip:"sheet.numfmt.subtractDecimal",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Ge=e=>({icon:"PercentIcon",id:d.SetPercentCommand.id,title:"sheet.numfmt.percent",tooltip:"sheet.numfmt.percent",type:_.MenuItemType.BUTTON,hidden$:_.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetEditPermission,g.WorksheetSetCellStylePermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}),Ke=e=>{const n=e.get(s.IUniverInstanceService),r=e.get(s.ICommandService),t=e.get(s.LocaleService),i=e.get(g.SheetsSelectionsService),a=[g.RemoveNumfmtMutation.id,g.SetNumfmtMutation.id],o=D.deriveStateFromActiveSheet$(n,"",({workbook:u,worksheet:c})=>new x.Observable(v=>x.merge(i.selectionMoveEnd$,s.fromCallback(r.onCommandExecuted.bind(r)).pipe(x.filter(([f])=>a.includes(f.id)))).subscribe(()=>{var m,h;const f=i.getCurrentSelections();if(f&&f[0]){const S=f[0].range,b=S.startRow,p=S.startColumn,P=(h=u.getStyles().get((m=c.getCell(b,p))==null?void 0:m.s))==null?void 0:h.n,I=P==null?void 0:P.pattern;let M=t.t("sheet.numfmt.general");if(W.isDefaultFormat(I)){v.next(M);return}if(I){const O=q.filter(U=>typeof U=="object"&&U.pattern).find(U=>s.isPatternEqualWithoutDecimal(I,U.pattern));O&&typeof O=="object"&&O.pattern?M=t.t(O.label):M=t.t("sheet.numfmt.moreFmt")}v.next(M)}})));return{label:le,id:L.id,tooltip:"sheet.numfmt.title",type:_.MenuItemType.SELECTOR,slot:!0,selections:[{label:{name:ue,hoverable:!1,selectable:!1}}],value$:o,hidden$:_.getMenuHiddenObservable(e,s.UniverInstanceType.UNIVER_SHEET),disabled$:D.getCurrentRangeDisable$(e,{workbookTypes:[g.WorkbookEditablePermission],worksheetTypes:[g.WorksheetSetCellStylePermission,g.WorksheetEditPermission],rangeTypes:[g.RangeProtectionPermissionEditPoint]})}},le="sheet.numfmt.moreNumfmtType",ue="sheet.numfmt.moreNumfmtType.options",Ze=e=>{const{value:n}=e,r=_.useDependency(s.LocaleService),t=n!=null?n:r.t("sheet.numfmt.general");return l.jsx("span",{className:"univer-text-sm",children:t})},Ye=()=>{const e=_.useDependency(s.ICommandService),n=_.useDependency(s.LocaleService),r=_.useDependency(_.ILayoutService),t=_.useDependency(d.SheetsNumfmtCellContentController),i=_.useDependency(g.SheetsSelectionsService),a=c=>{const v=i.getCurrentLastSelection();if(!v)return;const f=v.range,m=[];s.Range.foreach(f,(h,S)=>{c?m.push({row:h,col:S,pattern:c,type:d.getPatternType(c)}):m.push({row:h,col:S})}),e.executeCommand(d.SetNumfmtCommand.id,{values:m}),r.focus()},o=c=>{if(c===0)a(null);else if(c===q.length-1)e.executeCommand(L.id),r.focus();else{const v=q[c];v.pattern&&a(v.pattern)}},u=1220;return l.jsx("div",{className:"univer-grid univer-gap-1 univer-p-1.5",children:q.map((c,v)=>c==="|"?l.jsx(T.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:()=>{o(v)},children:[l.jsx("span",{children:n.t(c.label)}),l.jsx("span",{className:"univer-text-xs univer-text-gray-500",children:c.pattern?d.getPatternPreview(c.pattern||"",u,t.local).result.trim():""})]},v))})},ze={[_.RibbonDataGroup.FORMULAS]:{[d.SetCurrencyCommand.id]:{order:0,menuItemFactory:Ve},[d.AddDecimalCommand.id]:{order:1,menuItemFactory:Be},[d.SubtractDecimalCommand.id]:{order:2,menuItemFactory:qe},[d.SetPercentCommand.id]:{order:3,menuItemFactory:Ge},[L.id]:{order:4,menuItemFactory:Ke}}};var Xe=Object.getOwnPropertyDescriptor,Je=(e,n,r,t)=>{for(var i=t>1?void 0:t?Xe(n,r):n,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=o(i)||i);return i},me=(e,n)=>(r,t)=>n(r,t,e);let G=class extends s.Disposable{constructor(e,n){super(),this._componentManager=e,this._menuManagerService=n,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(ze),[[le,Ze],[ue,Ye]].forEach(([e,n])=>{this.disposeWithMe(this._componentManager.register(e,n))})}};G=Je([me(0,s.Inject(_.ComponentManager)),me(1,_.IMenuManagerService)],G);var Qe=Object.defineProperty,et=Object.getOwnPropertyDescriptor,tt=(e,n,r)=>n in e?Qe(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r,nt=(e,n,r,t)=>{for(var i=t>1?void 0:t?et(n,r):n,a=e.length-1,o;a>=0;a--)(o=e[a])&&(i=o(i)||i);return i},ee=(e,n)=>(r,t)=>n(r,t,e),de=(e,n,r)=>tt(e,typeof n!="symbol"?n+"":n,r);const rt="SHEET_NUMFMT_UI_PLUGIN";C.UniverSheetsNumfmtUIPlugin=class extends s.Plugin{constructor(n=re,r,t,i){super(),this._config=n,this._injector=r,this._configService=t,this._renderManagerService=i;const{menu:a,...o}=s.merge({},re,this._config);a&&this._configService.setConfig("menu",a,{merge:!0}),this._configService.setConfig("sheets-numfmt-ui.config",o)}onStarting(){s.registerDependencies(this._injector,[[H],[B],[F],[G]])}onRendered(){this._registerRenderModules(),s.touchDependencies(this._injector,[[H],[B],[G]])}_registerRenderModules(){[[Y]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(s.UniverInstanceType.UNIVER_SHEET,r))})}},de(C.UniverSheetsNumfmtUIPlugin,"pluginName",rt),de(C.UniverSheetsNumfmtUIPlugin,"type",s.UniverInstanceType.UNIVER_SHEET),C.UniverSheetsNumfmtUIPlugin=nt([s.DependentOn(D.UniverSheetsUIPlugin,d.UniverSheetsNumfmtPlugin),ee(1,s.Inject(s.Injector)),ee(2,s.IConfigService),ee(3,k.IRenderManagerService)],C.UniverSheetsNumfmtUIPlugin),Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-numfmt-ui",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1-nightly.202506131607",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "UniverSheet numfmt plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -55,25 +55,25 @@
|
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@univerjs/icons": "^0.4.4",
|
|
58
|
-
"@univerjs/core": "0.8.
|
|
59
|
-
"@univerjs/design": "0.8.
|
|
60
|
-
"@univerjs/engine-numfmt": "0.8.
|
|
61
|
-
"@univerjs/engine-render": "0.8.
|
|
62
|
-
"@univerjs/sheets": "0.8.
|
|
63
|
-
"@univerjs/sheets-numfmt": "0.8.
|
|
64
|
-
"@univerjs/sheets-ui": "0.8.
|
|
65
|
-
"@univerjs/ui": "0.8.
|
|
58
|
+
"@univerjs/core": "0.8.1-nightly.202506131607",
|
|
59
|
+
"@univerjs/design": "0.8.1-nightly.202506131607",
|
|
60
|
+
"@univerjs/engine-numfmt": "0.8.1-nightly.202506131607",
|
|
61
|
+
"@univerjs/engine-render": "0.8.1-nightly.202506131607",
|
|
62
|
+
"@univerjs/sheets": "0.8.1-nightly.202506131607",
|
|
63
|
+
"@univerjs/sheets-numfmt": "0.8.1-nightly.202506131607",
|
|
64
|
+
"@univerjs/sheets-ui": "0.8.1-nightly.202506131607",
|
|
65
|
+
"@univerjs/ui": "0.8.1-nightly.202506131607"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"postcss": "^8.5.
|
|
68
|
+
"postcss": "^8.5.4",
|
|
69
69
|
"react": "18.3.1",
|
|
70
70
|
"rxjs": "^7.8.2",
|
|
71
71
|
"tailwindcss": "^3.4.17",
|
|
72
72
|
"typescript": "^5.8.3",
|
|
73
73
|
"vite": "^6.3.5",
|
|
74
74
|
"vitest": "^3.1.4",
|
|
75
|
-
"@univerjs/
|
|
76
|
-
"@univerjs-
|
|
75
|
+
"@univerjs-infra/shared": "0.8.1",
|
|
76
|
+
"@univerjs/engine-formula": "0.8.1-nightly.202506131607"
|
|
77
77
|
},
|
|
78
78
|
"scripts": {
|
|
79
79
|
"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
|