@univerjs/sheets-numfmt-ui 0.18.0 → 0.19.0-insiders.20260403-3e0e122

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1,26 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/engine-render`),n=require(`@univerjs/sheets-numfmt`),r=require(`@univerjs/sheets-ui`),i=require(`@univerjs/sheets`),a=require(`@univerjs/ui`),o=require(`rxjs`),s=require(`rxjs/operators`),c=require(`@univerjs/design`),l=require(`react`),u=require(`react/jsx-runtime`),d=require(`@univerjs/icons`),f=require(`@univerjs/engine-formula`);var p=`@univerjs/sheets-numfmt-ui`,m=`0.18.0`;const h={};function g(e,t){return function(n,r){t(n,r,e)}}function _(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}const v=`SHEET_NUMFMT_ALERT`;let y=class extends e.Disposable{constructor(e,t,n,r,i,a,o){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=n,this._localeService=r,this._zenZoneService=i,this._numfmtService=a,this._configService=o,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0,o.debounceTime)(100)).subscribe(t=>{if(t){let o=t.location,s=this._context.unit,c=s.getActiveSheet();if(!c)return this._hideAlert();let l=o.unitId,u=o.subUnitId,d,f=c.getCell(o.row,o.col);if(f!=null&&f.s){let e=s.getStyles().get(f.s);e!=null&&e.n&&(d=e.n)}if(d||(d=this._numfmtService.getValue(l,u,o.row,o.col)),!d){this._hideAlert();return}if((0,e.isTextFormat)(d.pattern)&&e.Tools.isDefine(f==null?void 0:f.v)&&(0,e.isRealNum)(f.v)){var i,a;if((i=this._configService.getConfig(n.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY))!=null&&i.disableTextFormatAlert)return;let e=this._cellAlertManagerService.currentAlert.get(v),t=e==null||(a=e.alert)==null?void 0:a.location;if(t&&t.row===o.row&&t.col===o.col&&t.subUnitId===o.subUnitId&&t.unitId===o.unitId){this._hideAlert();return}this._cellAlertManagerService.showAlert({type:r.CellAlertType.ERROR,title:this._localeService.t(`info.error`),message:this._localeService.t(`info.forceStringInfo`),location:o,width:200,height:74,key:v});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(v)}};y=_([g(1,(0,e.Inject)(r.HoverManagerService)),g(2,(0,e.Inject)(r.CellAlertManagerService)),g(3,(0,e.Inject)(e.LocaleService)),g(4,a.IZenZoneService),g(5,(0,e.Inject)(i.INumfmtService)),g(6,e.IConfigService)],y);const b={id:`sheet.operation.close.numfmt.panel`,type:e.CommandType.OPERATION,handler:()=>!0},x={id:`sheet.operation.open.numfmt.panel`,type:e.CommandType.OPERATION,handler:e=>(e.get(H).openPanel(),!0)},S=(0,l.createContext)([]);let C=class{constructor(e){this._localStorageService=e}_getKey(e){return`userHabitController_${e}`}async addHabit(e,t){let n=this._getKey(e);return this._localStorageService.getItem(n).then(e=>{e||this._localStorageService.setItem(n,t)})}markHabit(e,t){let n=this._getKey(e);this._localStorageService.getItem(n).then(e=>{if(e){let r=e.findIndex(e=>e===t);r>-1&&e.splice(r,1),e.unshift(t),this._localStorageService.setItem(n,e)}})}async getHabit(e,t){let n=this._getKey(e),r=await this._localStorageService.getItem(n);if(t&&r){let e=r.map((e,t,n)=>({value:e,priority:n.length-t}));return t.sort((t,n)=>{var r,i;let a=((r=e.find(e=>e.value===t))==null?void 0:r.priority)||-1;return(((i=e.find(e=>e.value===n))==null?void 0:i.priority)||-1)-a})}return r||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};C=_([g(0,(0,e.Inject)(e.ILocalStorageService))],C);const w=`numfmtCurrency`,T=e=>{let t=(0,a.useDependency)(C),[r,i]=(0,l.useState)(n.currencySymbols);return(0,l.useEffect)(()=>{t.addHabit(`numfmtCurrency`,[]).then(()=>{t.getHabit(w,[...n.currencySymbols]).then(t=>{i(t),e&&e(t)})})},[]),{userHabitCurrency:r,mark:e=>{t.markHabit(w,e)}}},E=()=>{let e=(0,l.useRef)([]),[t,n]=(0,l.useState)({});return(0,l.useEffect)(()=>{e.current.forEach(e=>{e()}),e.current=[]},[t]),t=>{e.current.push(t),n({})}},ee=e=>!!(0,n.getCurrencyType)(e)&&e.startsWith(`_(`),D=t=>{let{defaultPattern:r,action:i,onChange:o}=t,[s,d]=(0,l.useState)(()=>(0,n.getDecimalFromPattern)(r||``,2)),f=(0,l.useContext)(S),[p,m]=(0,l.useState)(()=>(0,n.getCurrencyType)(r)||f[0]),h=(0,l.useMemo)(()=>f.map(e=>({label:e,value:e})),[]),g=(0,a.useDependency)(e.LocaleService).t;return i.current=()=>(0,n.setPatternDecimal)(`_("${p}"* #,##0${s>0?`.0`:``}_)`,s),(0,u.jsxs)(`div`,{children:[(0,u.jsxs)(`div`,{className:`univer-mt-4 univer-flex univer-justify-between`,children:[(0,u.jsxs)(`div`,{className:`option`,children:[(0,u.jsx)(`div`,{className:`univer-text-sm univer-text-gray-400`,children:g(`sheet.numfmt.decimalLength`)}),(0,u.jsx)(`div`,{className:`univer-mt-2 univer-w-32`,children:(0,u.jsx)(c.InputNumber,{value:s,step:1,precision:0,max:20,min:0,onChange:e=>{let t=e||0;d(t),o((0,n.setPatternDecimal)(`_("${p}"* #,##0${t>0?`.0`:``}_)`,t))}})})]}),(0,u.jsxs)(`div`,{className:`option`,children:[(0,u.jsx)(`div`,{className:`univer-text-sm univer-text-gray-400`,children:g(`sheet.numfmt.currencyType`)}),(0,u.jsx)(`div`,{className:`univer-mt-2 univer-w-36`,children:(0,u.jsx)(c.Select,{options:h,value:p,onChange:e=>{m(e),o((0,n.setPatternDecimal)(`_("${e}"* #,##0${s>0?`.0`:``}_)`,s))}})})]})]}),(0,u.jsx)(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:g(`sheet.numfmt.accountingDes`)})]})},O=e=>!!(0,n.getCurrencyType)(e)&&!e.startsWith(`_(`),k=t=>{let r=(0,a.useDependency)(e.LocaleService).t,i=(0,l.useContext)(S),[o,s]=(0,l.useState)(()=>(0,n.getCurrencyType)(t.defaultPattern)||i[0]),[d,f]=(0,l.useState)(()=>(0,n.getDecimalFromPattern)(t.defaultPattern||``,2)),[p,m]=(0,l.useState)(()=>{var r;let i=(0,n.getCurrencyFormatOptions)(o);return((r=i.find(n=>(0,e.isPatternEqualWithoutDecimal)(n.value,t.defaultPattern)))==null?void 0:r.value)||i[0].value}),h=(0,l.useMemo)(()=>(0,n.getCurrencyFormatOptions)(o),[o]),g=(0,l.useMemo)(()=>i.map(e=>({label:e,value:e})),[i]);return t.action.current=()=>(0,n.setPatternDecimal)(p,d),(0,u.jsxs)(`div`,{children:[(0,u.jsxs)(`div`,{className:`univer-mt-4 univer-flex univer-justify-between`,children:[(0,u.jsxs)(`div`,{className:`option`,children:[(0,u.jsx)(`div`,{className:`univer-text-sm univer-text-gray-400`,children:r(`sheet.numfmt.decimalLength`)}),(0,u.jsx)(`div`,{className:`univer-mt-2 univer-w-32`,children:(0,u.jsx)(c.InputNumber,{value:d,max:20,min:0,onChange:e=>{f(e||0),t.onChange((0,n.setPatternDecimal)(p,e||0))}})})]}),(0,u.jsxs)(`div`,{className:`option`,children:[(0,u.jsx)(`div`,{className:`univer-text-sm univer-text-gray-400`,children:r(`sheet.numfmt.currencyType`)}),(0,u.jsx)(`div`,{className:`univer-mt-2 univer-w-36`,children:(0,u.jsx)(c.Select,{value:o,options:g,onChange:e=>{if(e===void 0)return;s(e);let r=(0,n.getCurrencyFormatOptions)(e)[0].value;m(r),t.onChange((0,n.setPatternDecimal)(r,d))}})})]})]}),(0,u.jsx)(`div`,{className:`label univer-mt-4`,children:r(`sheet.numfmt.negType`)}),(0,u.jsx)(`div`,{className:`univer-mt-2`,children:(0,u.jsx)(c.SelectList,{value:p,options:h,onChange:e=>{e!==void 0&&(m(e),t.onChange((0,n.setPatternDecimal)(e,d)))}})}),(0,u.jsx)(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:r(`sheet.numfmt.currencyDes`)})]})},A=`customFormat`,j=`numfmt_custom_pattern`;function M(t){let{defaultPattern:r,action:i,onChange:o}=t,s=(0,a.useDependency)(C),f=(0,a.useDependency)(e.ILocalStorageService),p=(0,a.useDependency)(e.LocaleService),[m,h]=(0,l.useState)(r);i.current=()=>(s.markHabit(A,m),f.getItem(j).then((e=[])=>{let t=[...new Set([m,...e||[]])].splice(0,10).filter(e=>!!e);f.setItem(j,t)}),m);let[g,_]=(0,l.useState)([]);(0,l.useEffect)(()=>{f.getItem(j).then(e=>{let t=[...n.CURRENCYFORMAT.map(e=>e.suffix(`$`)),...n.DATEFMTLISG.map(e=>e.suffix),...n.NUMBERFORMAT.map(e=>e.suffix)];t.push(...e||[]),s.addHabit(A,[]).finally(()=>{s.getHabit(A,t).then(e=>{_([...new Set(e)])})})})},[]);let v=e=>{h(e),o(e)};return(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:p.t(`sheet.numfmt.customFormat`)}),(0,u.jsx)(c.Input,{placeholder:p.t(`sheet.numfmt.customFormat`),onBlur:()=>{o(m)},value:m,onChange:h,className:`univer-mt-2 univer-w-full`}),(0,u.jsx)(`div`,{className:(0,c.clsx)(`univer-mt-2 univer-max-h-[400px] univer-overflow-auto univer-rounded-lg univer-p-2`,c.borderClassName),children:g.map(e=>(0,u.jsxs)(`div`,{onClick:()=>v(e),className:`
2
- univer-flex univer-cursor-pointer univer-items-center univer-gap-1.5 univer-py-1.5
3
- univer-text-sm
4
- `,children:[(0,u.jsx)(`div`,{className:`univer-flex univer-w-4 univer-items-center univer-text-primary-600`,children:m===e&&(0,u.jsx)(d.CheckMarkIcon,{})}),(0,u.jsx)(`div`,{children:e})]},e))}),(0,u.jsx)(`div`,{className:`
5
- univer-mt-3 univer-text-sm univer-text-gray-600
6
- dark:!univer-text-gray-200
7
- `,children:p.t(`sheet.numfmt.customFormatDes`)})]})}const N=t=>{let r=e.numfmt.getFormatInfo(t);return(0,n.getDateFormatOptions)().map(e=>e.value).includes(t)||[`date`,`datetime`,`time`].includes(r.type)};function P(t){let{onChange:r,defaultPattern:i}=t,o=(0,l.useMemo)(n.getDateFormatOptions,[]),s=(0,a.useDependency)(e.LocaleService),[d,f]=(0,l.useState)(()=>{if(i){let e=o.find(e=>e.value===i);if(e)return e.value}return o[0].value});return t.action.current=()=>d,(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:s.t(`sheet.numfmt.dateType`)}),(0,u.jsx)(`div`,{className:`univer-mt-2`,children:(0,u.jsx)(c.SelectList,{value:d,options:o,onChange:e=>{e!==void 0&&(f(e),r(e))}})}),(0,u.jsx)(`div`,{className:`
8
- univer-mt-3.5 univer-text-sm/5 univer-text-gray-600
9
- dark:!univer-text-gray-200
10
- `,children:s.t(`sheet.numfmt.dateDes`)})]})}const F=e=>!e,te=t=>{let n=(0,a.useDependency)(e.LocaleService).t;return t.action.current=()=>``,(0,u.jsx)(`div`,{children:(0,u.jsx)(`div`,{className:`
11
- univer-mt-3.5 univer-text-sm/5 univer-text-gray-600
12
- dark:!univer-text-gray-200
13
- `,children:n(`sheet.numfmt.generalDes`)})})},ne=t=>(0,n.getNumberFormatOptions)().some(n=>(0,e.isPatternEqualWithoutDecimal)(n.value,t));function re(t){let r=(0,a.useDependency)(e.LocaleService),i=(0,l.useMemo)(n.getNumberFormatOptions,[]),[o,s]=(0,l.useState)(()=>(0,n.getDecimalFromPattern)(t.defaultPattern||``,0)),[d,f]=(0,l.useState)(()=>{let n=i.find(n=>(0,e.isPatternEqualWithoutDecimal)(n.value,t.defaultPattern||``));return(n==null?void 0:n.value)||i[0].value}),p=(0,l.useMemo)(()=>(0,n.setPatternDecimal)(d,Number(o||0)),[d,o]),m=(0,l.useMemo)(()=>!(0,n.isPatternHasDecimal)(d),[d]),h=e=>{s(e||0),t.onChange((0,n.setPatternDecimal)(d,Number(e||0)))},g=e=>{e!==void 0&&(s((0,n.getDecimalFromPattern)(e,0)),f(e),t.onChange(e))};return t.action.current=()=>p,(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:r.t(`sheet.numfmt.decimalLength`)}),(0,u.jsx)(`div`,{className:`univer-mt-2`,children:(0,u.jsx)(c.InputNumber,{disabled:m,value:o,max:20,min:0,onChange:h})}),(0,u.jsxs)(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:[` `,r.t(`sheet.numfmt.negType`)]}),(0,u.jsx)(`div`,{className:`univer-mt-2`,children:(0,u.jsx)(c.SelectList,{onChange:g,options:i,value:d})}),(0,u.jsx)(`div`,{className:`
14
- univer-mt-3.5 univer-text-sm/5 univer-text-gray-600
15
- dark:!univer-text-gray-200
16
- `,children:r.t(`sheet.numfmt.thousandthPercentileDes`)})]})}const I=t=>{let{defaultValue:r,defaultPattern:i,row:o,col:s}=t.value,d=(0,a.useDependency)(e.LocaleService),f=(0,l.useRef)(()=>``),p=d.t,m=E(),h=(0,l.useMemo)(()=>[{label:`sheet.numfmt.general`,component:te},{label:`sheet.numfmt.accounting`,component:D},{label:`sheet.numfmt.currency`,component:k},{label:`sheet.numfmt.date`,component:P},{label:`sheet.numfmt.thousandthPercentile`,component:re},{label:`sheet.numfmt.customFormat`,component:M}].map(e=>({...e,label:p(e.label)})),[]),[g,_]=(0,l.useState)(w),[v,y]=(0,l.useState)(()=>`${o}_${s}`),{mark:b,userHabitCurrency:x}=T(()=>y(`${o}_${s}_userCurrency'`)),C=(0,l.useMemo)(()=>{var e;return(e=h.find(e=>e.label===g))==null?void 0:e.component},[g]);function w(){return[F,ee,O,N,ne].reduce((e,t,n)=>e||(t(i)?h[n].label:``),``)||h[0].label}let A=h.map(e=>({label:e.label,value:e.label})),j=e=>{_(e),m(()=>t.onChange({type:`change`,value:f.current()||``}))},I=(0,l.useCallback)(e=>{t.onChange({type:`change`,value:e})},[]),L=()=>{let e=f.current()||``,r=(0,n.getCurrencyType)(e);r&&b(r),t.onChange({type:`confirm`,value:e})},R=()=>{t.onChange({type:`cancel`,value:``})},z={onChange:I,defaultValue:r,defaultPattern:i,action:f};return(0,l.useEffect)(()=>{_(w()),y(`${o}_${s}`)},[o,s]),(0,u.jsxs)(`div`,{className:(0,c.clsx)(`
17
- univer-flex univer-h-full univer-flex-col univer-justify-between univer-overflow-y-auto univer-pb-5
18
- `,c.scrollbarClassName),children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`div`,{className:`univer-mt-3.5 univer-text-sm univer-text-gray-400`,children:p(`sheet.numfmt.numfmtType`)}),(0,u.jsx)(`div`,{className:`univer-mt-2`,children:(0,u.jsx)(c.Select,{className:`univer-w-full`,value:g,options:A,onChange:j})}),(0,u.jsx)(`div`,{children:C&&(0,u.jsx)(S.Provider,{value:x,children:(0,l.createElement)(C,{...z,key:v})})})]}),(0,u.jsxs)(`div`,{className:`univer-mb-5 univer-mt-3.5 univer-flex univer-justify-end`,children:[(0,u.jsx)(c.Button,{onClick:R,className:`univer-mr-3`,children:p(`sheet.numfmt.cancel`)}),(0,u.jsx)(c.Button,{variant:`primary`,onClick:L,children:p(`sheet.numfmt.confirm`)})]})]})};function L(e){"@babel/helpers - typeof";return L=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},L(e)}function R(e,t){if(L(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(L(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function z(e){var t=R(e,`string`);return L(t)==`symbol`?t:t+``}function B(e,t,n){return(t=z(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const V=`SHEET_NUMFMT_PANEL`;let H=class extends e.Disposable{constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._sheetInterceptorService=e,this._themeService=t,this._univerInstanceService=n,this._commandService=r,this._selectionManagerService=i,this._renderManagerService=a,this._numfmtService=o,this._componentManager=s,this._sidebarService=c,this._localeService=l,this._sheetsNumfmtCellContentController=u,B(this,`_previewPattern`,``),B(this,`_sidebarDisposable`,null),this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener(),this._initNumfmtLocalChange()}_initNumfmtLocalChange(){this.disposeWithMe((0,o.merge)(this._sheetsNumfmtCellContentController.locale$,this._localeService.currentLocale$).subscribe(()=>{this._forceUpdate()}))}openPanel(){var t;let r=this._sidebarService,i=this._selectionManagerService,a=this._commandService,o=this._univerInstanceService,s=this._numfmtService,c=this._localeService,l=(((t=i.getCurrentSelections())==null?void 0:t.map(e=>e.range))||[])[0];if(!l)return!1;let u=o.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SHEET),d=u.getActiveSheet();if(!d)return!1;let f=d.getCellRaw(l.startRow,l.startColumn),p=s.getValue(u.getUnitId(),d.getSheetId(),l.startRow,l.startColumn),m=``;p&&(m=p.pattern);let h=(f==null?void 0:f.t)===e.CellValueType.NUMBER?f.v:12345678,g={onChange:t=>{if(t.type===`change`)this._previewPattern=t.value,this._forceUpdate();else if(t.type===`confirm`){var o;let s=((o=i.getCurrentSelections())==null?void 0:o.map(e=>e.range))||[],c={values:[]},l=(0,n.getPatternType)(t.value);s.forEach(n=>{e.Range.foreach(n,(e,n)=>{c.values.push({row:e,col:n,pattern:t.value,type:l})})}),a.executeCommand(n.SetNumfmtCommand.id,c),r.close()}else t.type===`cancel`&&r.close()},value:{defaultPattern:m,defaultValue:h,row:l.startRow,col:l.startColumn}};return this._sidebarDisposable=r.open({header:{title:c.t(`sheet.numfmt.title`)},children:{label:V,...g},onClose:()=>{this._forceUpdate(),a.executeCommand(b.id)}}),!0}_forceUpdate(t){var n;let i=this._renderManagerService.getRenderById(t==null?this._univerInstanceService.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SHEET).getUnitId():t);i==null||i.with(r.SheetSkeletonManagerService).reCalculate(),i==null||(n=i.mainComponent)==null||n.makeDirty()}_initCommands(){[x,b].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initPanel(){this.disposeWithMe(this._componentManager.register(V,I))}_initRealTimeRenderingInterceptor(){let t=(0,o.combineLatest)([new o.Observable(e=>{this._commandService.onCommandExecuted(t=>{t.id===x.id&&e.next(!0),t.id===b.id&&e.next(!1)})}),this._selectionManagerService.selectionMoveEnd$.pipe((0,s.map)(e=>e?e.map(e=>e.range):[]))]);this.disposeWithMe((0,e.toDisposable)(t.pipe((0,s.switchMap)(([t,n])=>new o.Observable(r=>{let i=new e.DisposableCollection;return t&&n.length&&r.next({selectionRanges:n,disposableCollection:i}),()=>{i.dispose()}})),(0,s.tap)(()=>{this._previewPattern=null})).subscribe(({disposableCollection:t,selectionRanges:r})=>{var a;let o=this._univerInstanceService.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SHEET);this.openPanel(),t.add(this._sheetInterceptorService.intercept(i.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,effect:e.InterceptorEffectEnum.Value|e.InterceptorEffectEnum.Style,handler:(t,i,a)=>{let{row:o,col:s}=i,c=a(t)||{};if(r.find(e=>e.startColumn<=s&&e.endColumn>=s&&e.startRow<=o&&e.endRow>=o)){let t=i.worksheet.getCellRaw(o,s),r=t==null?void 0:t.v,a=t==null?void 0:t.t;if(r==null||a!==e.CellValueType.NUMBER||this._previewPattern===null)return c;let u=(0,n.getPatternPreviewIgnoreGeneral)(this._previewPattern,r,this._sheetsNumfmtCellContentController.locale);if(u.color){var l;let t=(l=this._themeService.getColorFromTheme(`${u.color}.500`))==null?u.color:l;return{...c,v:u.result,t:e.CellValueType.STRING,s:{cl:{rgb:t}}}}return{...c,v:u.result,t:e.CellValueType.STRING}}return c}})),(a=this._renderManagerService.getRenderById(o.getUnitId()))==null||(a=a.mainComponent)==null||a.makeDirty()})))}_commandExecutedListener(){let e=[i.RemoveNumfmtMutation.id,i.SetNumfmtMutation.id];this.disposeWithMe(new o.Observable(t=>{let n=this._commandService.onCommandExecuted(n=>{if(e.includes(n.id)){let e=n.params;t.next(e.unitId)}});return()=>n.dispose()}).pipe((0,s.debounceTime)(16)).subscribe(e=>this._forceUpdate(e)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(e.UniverInstanceType.UNIVER_SHEET).subscribe(e=>{if(!e){var t;(t=this._sidebarDisposable)==null||t.dispose(),this._sidebarDisposable=null}})}};H=_([g(0,(0,e.Inject)(i.SheetInterceptorService)),g(1,(0,e.Inject)(e.ThemeService)),g(2,e.IUniverInstanceService),g(3,e.ICommandService),g(4,(0,e.Inject)(i.SheetsSelectionsService)),g(5,t.IRenderManagerService),g(6,i.INumfmtService),g(7,(0,e.Inject)(a.ComponentManager)),g(8,a.ISidebarService),g(9,(0,e.Inject)(e.LocaleService)),g(10,(0,e.Inject)(n.SheetsNumfmtCellContentController))],H);const U=()=>{let e=[];return{add:(t,n,r,i,a)=>e.push({unitId:t,subUnitId:n,row:r,col:i,value:a}),getEffects:()=>e,clean:()=>{e=[]}}};let W=class extends e.Disposable{constructor(e,t,n,r,i){super(),this._sheetInterceptorService=e,this._numfmtService=t,this._univerInstanceService=n,this._injector=r,this._editorBridgeService=i,B(this,`_collectEffectMutation`,U()),this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe((0,e.toDisposable)(this._sheetInterceptorService.writeCellInterceptor.intercept(i.BEFORE_CELL_EDIT,{handler:(t,r,i)=>{let a=r.row,o=r.col,s=this._numfmtService.getValue(r.unitId,r.subUnitId,a,o);if(s)switch((0,n.getPatternType)(s.pattern)){case`scientific`:case`currency`:case`grouped`:case`number`:{let t={...r.worksheet.getCellRaw(a,o)};return(t==null?void 0:t.t)===e.CellValueType.NUMBER&&(0,e.isRealNum)(t.v)&&(t.v=(0,f.stripErrorMargin)(Number(t.v))),i&&i(t)}case`percent`:{let t={...r.worksheet.getCellRaw(a,o)};return(t==null?void 0:t.t)===e.CellValueType.NUMBER&&(0,e.isRealNum)(t.v)&&(t.v=`${(0,f.stripErrorMargin)(Number(t.v)*100)}%`),i&&i(t)}default:return i&&i(t)}return i(t)}})))}_initInterceptorEditorEnd(){this.disposeWithMe((0,e.toDisposable)(this._sheetInterceptorService.writeCellInterceptor.intercept(i.AFTER_CELL_EDIT,{handler:(t,r,i)=>{var a,o;if(!(t!=null&&t.v)&&!(t!=null&&t.p))return i(t);this._collectEffectMutation.clean();let s=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col),c=r.worksheet.getCellRaw(r.row,r.col);if((0,e.isTextFormat)(s==null?void 0:s.pattern)||t.t===e.CellValueType.FORCE_STRING)return i(t);let l=(a=t.p)==null?void 0:a.body,u=!(t==null||(o=t.p)==null||(o=o.body)==null)&&o.dataStream?t.p.body.dataStream.replace(/\r\n$/,``):String(t.v),d=(0,e.getNumfmtParseValueFilter)(u);if(l)if(G(l)){let{dataStream:e}=l,n=e.replace(/\r\n$/,``),r=Number(n);if(Number.isNaN(r)&&!d)return i(t)}else return i(t);if(d){if(!d.z&&!(s!=null&&s.pattern)&&(c==null?void 0:c.t)!==e.CellValueType.STRING&&(c==null?void 0:c.t)!==e.CellValueType.FORCE_STRING&&(0,e.willLoseNumericPrecision)(u))return i({...t,p:void 0,v:u,t:e.CellValueType.FORCE_STRING});d.z&&(!(s!=null&&s.pattern)||(0,n.getPatternType)(d.z)!==(0,n.getPatternType)(s.pattern))&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:d.z});let a=(0,f.stripErrorMargin)(Number(d.v),16);return i({...t,p:void 0,v:a,t:e.CellValueType.NUMBER})}return i(t)}})))}_initInterceptorCommands(){let t=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(n){switch(n.id){case i.SetRangeValuesCommand.id:{var r;let n=t._univerInstanceService.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SHEET),a=n.getUnitId(),o=(r=n.getActiveSheet())==null?void 0:r.getSheetId();if(!o)return{redos:[],undos:[]};let s=t._collectEffectMutation.getEffects();if(t._collectEffectMutation.clean(),!s.length)return{redos:[],undos:[]};let c=s.filter(e=>{var t;return!!((t=e.value)!=null&&t.pattern)}).map(e=>({row:e.row,col:e.col,pattern:e.value.pattern})),l=s.filter(e=>{var t;return!((t=e.value)!=null&&t.pattern)}).map(e=>({startRow:e.row,endColumn:e.col,startColumn:e.col,endRow:e.row})),u=[],d=[];if(c.length){let e={id:i.SetNumfmtMutation.id,params:(0,i.transformCellsToRange)(a,o,c)};u.push(e),d.push(...(0,i.factorySetNumfmtUndoMutation)(t._injector,e.params))}if(l.length){let e={id:i.RemoveNumfmtMutation.id,params:{unitId:a,subUnitId:o,ranges:l}};u.push(e),d.push(...(0,i.factoryRemoveNumfmtUndoMutation)(t._injector,e.params))}return{redos:u,undos:d.reverse()}}}return{redos:[],undos:[]}}}))}dispose(){super.dispose(),this._collectEffectMutation.clean()}};W=_([g(0,(0,e.Inject)(i.SheetInterceptorService)),g(1,(0,e.Inject)(i.INumfmtService)),g(2,(0,e.Inject)(e.IUniverInstanceService)),g(3,(0,e.Inject)(e.Injector)),g(4,(0,e.Optional)(r.IEditorBridgeService))],W);function G(e){let{textRuns:t=[],paragraphs:n=[],customRanges:r,customBlocks:i=[]}=e,a=[`va`];return!(t.some(e=>!!(e.ts&&Object.keys(e.ts).some(e=>a.includes(e))))||n.some(e=>e.bullet)||n.length>=2||r!=null&&r.length||i.length>0)}const K=t=>[{label:`sheet.numfmt.general`,pattern:null},{label:`sheet.numfmt.text`,pattern:e.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:`"${t}" #,##0.00_);[Red]("${t}"#,##0.00)`},{label:`sheet.numfmt.financialValue`,pattern:`#,##0.00;[Red]#,##0.00`},{label:`sheet.numfmt.currency`,pattern:`"${t}"#,##0.00_);[Red]("${t}"#,##0.00)`},{label:`sheet.numfmt.roundingCurrency`,pattern:`"${t}"#,##0;[Red]"${t}"#,##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:``}],q=t=>({icon:new o.Observable(r=>{let i=t.get(e.LocaleService);return r.next((0,n.getCurrencySymbolIconByLocale)(i.getCurrentLocale()).icon),i.localeChanged$.subscribe(()=>{r.next((0,n.getCurrencySymbolIconByLocale)(i.getCurrentLocale()).icon)})}),id:n.SetCurrencyCommand.id,title:`sheet.numfmt.currency`,tooltip:`sheet.numfmt.currency`,type:a.MenuItemType.BUTTON,hidden$:(0,a.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_SHEET),disabled$:(0,r.getCurrentRangeDisable$)(t,{workbookTypes:[i.WorkbookEditablePermission],worksheetTypes:[i.WorksheetEditPermission,i.WorksheetSetCellStylePermission],rangeTypes:[i.RangeProtectionPermissionEditPoint]})}),J=t=>({icon:`AddDigitsIcon`,id:n.AddDecimalCommand.id,title:`sheet.numfmt.addDecimal`,tooltip:`sheet.numfmt.addDecimal`,type:a.MenuItemType.BUTTON,hidden$:(0,a.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_SHEET),disabled$:(0,r.getCurrentRangeDisable$)(t,{workbookTypes:[i.WorkbookEditablePermission],worksheetTypes:[i.WorksheetEditPermission,i.WorksheetSetCellStylePermission],rangeTypes:[i.RangeProtectionPermissionEditPoint]})}),Y=t=>({icon:`ReduceDigitsIcon`,id:n.SubtractDecimalCommand.id,title:`sheet.numfmt.subtractDecimal`,tooltip:`sheet.numfmt.subtractDecimal`,type:a.MenuItemType.BUTTON,hidden$:(0,a.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_SHEET),disabled$:(0,r.getCurrentRangeDisable$)(t,{workbookTypes:[i.WorkbookEditablePermission],worksheetTypes:[i.WorksheetEditPermission,i.WorksheetSetCellStylePermission],rangeTypes:[i.RangeProtectionPermissionEditPoint]})}),ie=t=>({icon:`PercentIcon`,id:n.SetPercentCommand.id,title:`sheet.numfmt.percent`,tooltip:`sheet.numfmt.percent`,type:a.MenuItemType.BUTTON,hidden$:(0,a.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_SHEET),disabled$:(0,r.getCurrentRangeDisable$)(t,{workbookTypes:[i.WorkbookEditablePermission],worksheetTypes:[i.WorksheetEditPermission,i.WorksheetSetCellStylePermission],rangeTypes:[i.RangeProtectionPermissionEditPoint]})}),ae=t=>{let s=t.get(e.IUniverInstanceService),c=t.get(e.ICommandService),l=t.get(e.LocaleService),u=t.get(i.SheetsSelectionsService),d=[i.RemoveNumfmtMutation.id,i.SetNumfmtMutation.id],f=(0,r.deriveStateFromActiveSheet$)(s,``,({workbook:t,worksheet:r})=>new o.Observable(i=>(0,o.merge)(u.selectionMoveEnd$,(0,e.fromCallback)(c.onCommandExecuted.bind(c)).pipe((0,o.filter)(([e])=>d.includes(e.id)))).subscribe(()=>{let a=u.getCurrentSelections();if(a&&a[0]){var o,s;let c=a[0].range,u=c.startRow,d=c.startColumn,f=(o=t.getStyles().get((s=r.getCell(u,d))==null?void 0:s.s))==null?void 0:o.n,p=f==null?void 0:f.pattern,m=(0,n.getCurrencySymbolByLocale)(l.getCurrentLocale()),h=l.t(`sheet.numfmt.general`);if((0,e.isDefaultFormat)(p)){i.next(h);return}if(p){let t=K(m).filter(e=>typeof e==`object`&&e.pattern).find(t=>(0,e.isPatternEqualWithoutDecimal)(p,t.pattern));h=t&&typeof t==`object`&&t.pattern?l.t(t.label):l.t(`sheet.numfmt.moreFmt`)}i.next(h)}})));return{label:X,id:x.id,tooltip:`sheet.numfmt.title`,type:a.MenuItemType.SELECTOR,slot:!0,selections:[{label:{name:Z,hoverable:!1,selectable:!1}}],value$:f,hidden$:(0,a.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_SHEET),disabled$:(0,r.getCurrentRangeDisable$)(t,{workbookTypes:[i.WorkbookEditablePermission],worksheetTypes:[i.WorksheetSetCellStylePermission,i.WorksheetEditPermission],rangeTypes:[i.RangeProtectionPermissionEditPoint]})}},X=`sheet.numfmt.moreNumfmtType`,Z=`sheet.numfmt.moreNumfmtType.options`;function oe(t){let{value:n}=t,r=(0,a.useDependency)(e.LocaleService);return(0,u.jsx)(`span`,{className:`univer-text-sm`,children:n==null?r.t(`sheet.numfmt.general`):n})}function se(){let t=(0,a.useDependency)(e.ICommandService),r=(0,a.useDependency)(e.LocaleService),o=(0,a.useDependency)(a.ILayoutService),s=(0,a.useDependency)(n.SheetsNumfmtCellContentController),d=(0,a.useDependency)(i.SheetsSelectionsService),f=r=>{let i=d.getCurrentLastSelection();if(!i)return;let a=i.range,s=[];e.Range.foreach(a,(e,t)=>{r?s.push({row:e,col:t,pattern:r,type:(0,n.getPatternType)(r)}):s.push({row:e,col:t})}),t.executeCommand(n.SetNumfmtCommand.id,{values:s}),o.focus()},p=(0,l.useMemo)(()=>K(n.localeCurrencySymbolMap.get(r.getCurrentLocale())),[r]),m=e=>{if(e===0)f(null);else if(e===p.length-1)t.executeCommand(x.id),o.focus();else{let t=p[e];t.pattern&&f(t.pattern)}};return(0,u.jsx)(`div`,{className:`univer-grid univer-gap-1 univer-p-1.5`,children:p.map((e,t)=>e===`|`?(0,u.jsx)(c.Separator,{},t):(0,u.jsxs)(`div`,{className:`
19
- univer-flex univer-h-7 univer-cursor-default univer-items-center univer-justify-between
20
- univer-gap-6 univer-rounded univer-px-2 univer-text-sm
21
- hover:univer-bg-gray-100
22
- dark:hover:!univer-bg-gray-700
23
- `,onClick:()=>m(t),children:[(0,u.jsx)(`span`,{children:r.t(e.label)}),(0,u.jsx)(`span`,{className:`
24
- univer-text-xs univer-text-gray-500
25
- dark:!univer-text-gray-400
26
- `,children:e.pattern?(0,n.getPatternPreview)(e.pattern||``,1220,s.locale).result.trim():``})]},t))})}const ce={[a.RibbonStartGroup.LAYOUT]:{[x.id]:{order:9,menuItemFactory:ae},[n.SetPercentCommand.id]:{order:9.1,menuItemFactory:ie},[n.SetCurrencyCommand.id]:{order:9.2,menuItemFactory:q},[n.AddDecimalCommand.id]:{order:9.3,menuItemFactory:J},[n.SubtractDecimalCommand.id]:{order:9.4,menuItemFactory:Y}}};let Q=class extends e.Disposable{constructor(e,t){super(),this._componentManager=e,this._menuManagerService=t,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(ce),[[X,oe],[Z,se]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};Q=_([g(0,(0,e.Inject)(a.ComponentManager)),g(1,a.IMenuManagerService)],Q);let $=class extends e.Plugin{constructor(t=h,n,r,i){super(),this._config=t,this._injector=n,this._configService=r,this._renderManagerService=i;let{menu:a,...o}=(0,e.merge)({},h,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(`sheets-numfmt-ui.config`,o)}onStarting(){(0,e.registerDependencies)(this._injector,[[H],[W],[C],[Q]])}onRendered(){this._registerRenderModules(),(0,e.touchDependencies)(this._injector,[[H],[W],[Q]])}_registerRenderModules(){[[y]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(e.UniverInstanceType.UNIVER_SHEET,t))})}};B($,`pluginName`,`SHEET_NUMFMT_UI_PLUGIN`),B($,`packageName`,p),B($,`version`,m),B($,`type`,e.UniverInstanceType.UNIVER_SHEET),$=_([(0,e.DependentOn)(r.UniverSheetsUIPlugin,n.UniverSheetsNumfmtPlugin),g(1,(0,e.Inject)(e.Injector)),g(2,e.IConfigService),g(3,t.IRenderManagerService)],$),Object.defineProperty(exports,`UniverSheetsNumfmtUIPlugin`,{enumerable:!0,get:function(){return $}});
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/engine-render`),n=require(`@univerjs/sheets-numfmt`),r=require(`@univerjs/sheets-ui`),i=require(`@univerjs/sheets`),a=require(`@univerjs/ui`),o=require(`rxjs`),s=require(`rxjs/operators`),c=require(`@univerjs/design`),l=require(`react`),u=require(`react/jsx-runtime`),d=require(`@univerjs/icons`),f=require(`@univerjs/engine-formula`);var p=`@univerjs/sheets-numfmt-ui`,m=`0.19.0-insiders.20260403-3e0e122`;const h={};function g(e,t){return function(n,r){t(n,r,e)}}function _(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}const v=`SHEET_NUMFMT_ALERT`;let y=class extends e.Disposable{constructor(e,t,n,r,i,a,o){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=n,this._localeService=r,this._zenZoneService=i,this._numfmtService=a,this._configService=o,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0,o.debounceTime)(100)).subscribe(t=>{if(t){let o=t.location,s=this._context.unit,c=s.getActiveSheet();if(!c)return this._hideAlert();let l=o.unitId,u=o.subUnitId,d,f=c.getCell(o.row,o.col);if(f!=null&&f.s){let e=s.getStyles().get(f.s);e!=null&&e.n&&(d=e.n)}if(d||(d=this._numfmtService.getValue(l,u,o.row,o.col)),!d){this._hideAlert();return}if((0,e.isTextFormat)(d.pattern)&&e.Tools.isDefine(f==null?void 0:f.v)&&(0,e.isRealNum)(f.v)){var i,a;if((i=this._configService.getConfig(n.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY))!=null&&i.disableTextFormatAlert)return;let e=this._cellAlertManagerService.currentAlert.get(v),t=e==null||(a=e.alert)==null?void 0:a.location;if(t&&t.row===o.row&&t.col===o.col&&t.subUnitId===o.subUnitId&&t.unitId===o.unitId){this._hideAlert();return}this._cellAlertManagerService.showAlert({type:r.CellAlertType.ERROR,title:this._localeService.t(`info.error`),message:this._localeService.t(`info.forceStringInfo`),location:o,width:200,height:74,key:v});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(v)}};y=_([g(1,(0,e.Inject)(r.HoverManagerService)),g(2,(0,e.Inject)(r.CellAlertManagerService)),g(3,(0,e.Inject)(e.LocaleService)),g(4,a.IZenZoneService),g(5,(0,e.Inject)(i.INumfmtService)),g(6,e.IConfigService)],y);let b=class extends e.Disposable{constructor(e){super(),this._repeatLastActionService=e,this._initCommandRecording()}_initCommandRecording(){this.disposeWithMe(this._repeatLastActionService.registerRepeatableCommand(n.SetNumfmtCommand.id,(e,t)=>{if(!t)return;let{values:n}=t,r=n.find(e=>e.pattern);if(!r)return;let{pattern:i,type:a}=r,o=[],s=new Set;for(let t of e){let{startRow:e,startColumn:n,endRow:r,endColumn:c}=t;for(let t=e;t<=r;t++)for(let e=n;e<=c;e++){let n=`${t}-${e}`;s.has(n)||(s.add(n),o.push({row:t,col:e,pattern:i,type:a}))}}return{...t,values:o}},r.RepeatLastActionPermission.CellStyle))}};b=_([g(0,(0,e.Inject)(r.IRepeatLastActionService))],b);const x={id:`sheet.operation.close.numfmt.panel`,type:e.CommandType.OPERATION,handler:()=>!0},S={id:`sheet.operation.open.numfmt.panel`,type:e.CommandType.OPERATION,handler:e=>(e.get(H).openPanel(),!0)},C=(0,l.createContext)([]);let w=class{constructor(e){this._localStorageService=e}_getKey(e){return`userHabitController_${e}`}async addHabit(e,t){let n=this._getKey(e);return this._localStorageService.getItem(n).then(e=>{e||this._localStorageService.setItem(n,t)})}markHabit(e,t){let n=this._getKey(e);this._localStorageService.getItem(n).then(e=>{if(e){let r=e.findIndex(e=>e===t);r>-1&&e.splice(r,1),e.unshift(t),this._localStorageService.setItem(n,e)}})}async getHabit(e,t){let n=this._getKey(e),r=await this._localStorageService.getItem(n);if(t&&r){let e=r.map((e,t,n)=>({value:e,priority:n.length-t}));return t.sort((t,n)=>{var r,i;let a=((r=e.find(e=>e.value===t))==null?void 0:r.priority)||-1;return(((i=e.find(e=>e.value===n))==null?void 0:i.priority)||-1)-a})}return r||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};w=_([g(0,(0,e.Inject)(e.ILocalStorageService))],w);const T=`numfmtCurrency`,E=e=>{let t=(0,a.useDependency)(w),[r,i]=(0,l.useState)(n.currencySymbols);return(0,l.useEffect)(()=>{t.addHabit(`numfmtCurrency`,[]).then(()=>{t.getHabit(T,[...n.currencySymbols]).then(t=>{i(t),e&&e(t)})})},[]),{userHabitCurrency:r,mark:e=>{t.markHabit(T,e)}}},D=()=>{let e=(0,l.useRef)([]),[t,n]=(0,l.useState)({});return(0,l.useEffect)(()=>{e.current.forEach(e=>{e()}),e.current=[]},[t]),t=>{e.current.push(t),n({})}},O=e=>!!(0,n.getCurrencyType)(e)&&e.startsWith(`_(`),k=t=>{let{defaultPattern:r,action:i,onChange:o}=t,[s,d]=(0,l.useState)(()=>(0,n.getDecimalFromPattern)(r||``,2)),f=(0,l.useContext)(C),[p,m]=(0,l.useState)(()=>(0,n.getCurrencyType)(r)||f[0]),h=(0,l.useMemo)(()=>f.map(e=>({label:e,value:e})),[]),g=(0,a.useDependency)(e.LocaleService).t;return i.current=()=>(0,n.setPatternDecimal)(`_("${p}"* #,##0${s>0?`.0`:``}_)`,s),(0,u.jsxs)(`div`,{children:[(0,u.jsxs)(`div`,{className:`univer-mt-4 univer-flex univer-justify-between`,children:[(0,u.jsxs)(`div`,{className:`option`,children:[(0,u.jsx)(`div`,{className:`univer-text-sm univer-text-gray-400`,children:g(`sheet.numfmt.decimalLength`)}),(0,u.jsx)(`div`,{className:`univer-mt-2 univer-w-32`,children:(0,u.jsx)(c.InputNumber,{value:s,step:1,precision:0,max:20,min:0,onChange:e=>{let t=e||0;d(t),o((0,n.setPatternDecimal)(`_("${p}"* #,##0${t>0?`.0`:``}_)`,t))}})})]}),(0,u.jsxs)(`div`,{className:`option`,children:[(0,u.jsx)(`div`,{className:`univer-text-sm univer-text-gray-400`,children:g(`sheet.numfmt.currencyType`)}),(0,u.jsx)(`div`,{className:`univer-mt-2 univer-w-36`,children:(0,u.jsx)(c.Select,{options:h,value:p,onChange:e=>{m(e),o((0,n.setPatternDecimal)(`_("${e}"* #,##0${s>0?`.0`:``}_)`,s))}})})]})]}),(0,u.jsx)(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:g(`sheet.numfmt.accountingDes`)})]})},A=e=>!!(0,n.getCurrencyType)(e)&&!e.startsWith(`_(`),j=t=>{let r=(0,a.useDependency)(e.LocaleService).t,i=(0,l.useContext)(C),[o,s]=(0,l.useState)(()=>(0,n.getCurrencyType)(t.defaultPattern)||i[0]),[d,f]=(0,l.useState)(()=>(0,n.getDecimalFromPattern)(t.defaultPattern||``,2)),[p,m]=(0,l.useState)(()=>{var r;let i=(0,n.getCurrencyFormatOptions)(o);return((r=i.find(n=>(0,e.isPatternEqualWithoutDecimal)(n.value,t.defaultPattern)))==null?void 0:r.value)||i[0].value}),h=(0,l.useMemo)(()=>(0,n.getCurrencyFormatOptions)(o),[o]),g=(0,l.useMemo)(()=>i.map(e=>({label:e,value:e})),[i]);return t.action.current=()=>(0,n.setPatternDecimal)(p,d),(0,u.jsxs)(`div`,{children:[(0,u.jsxs)(`div`,{className:`univer-mt-4 univer-flex univer-justify-between`,children:[(0,u.jsxs)(`div`,{className:`option`,children:[(0,u.jsx)(`div`,{className:`univer-text-sm univer-text-gray-400`,children:r(`sheet.numfmt.decimalLength`)}),(0,u.jsx)(`div`,{className:`univer-mt-2 univer-w-32`,children:(0,u.jsx)(c.InputNumber,{value:d,max:20,min:0,onChange:e=>{f(e||0),t.onChange((0,n.setPatternDecimal)(p,e||0))}})})]}),(0,u.jsxs)(`div`,{className:`option`,children:[(0,u.jsx)(`div`,{className:`univer-text-sm univer-text-gray-400`,children:r(`sheet.numfmt.currencyType`)}),(0,u.jsx)(`div`,{className:`univer-mt-2 univer-w-36`,children:(0,u.jsx)(c.Select,{value:o,options:g,onChange:e=>{if(e===void 0)return;s(e);let r=(0,n.getCurrencyFormatOptions)(e)[0].value;m(r),t.onChange((0,n.setPatternDecimal)(r,d))}})})]})]}),(0,u.jsx)(`div`,{className:`label univer-mt-4`,children:r(`sheet.numfmt.negType`)}),(0,u.jsx)(`div`,{className:`univer-mt-2`,children:(0,u.jsx)(c.SelectList,{value:p,options:h,onChange:e=>{e!==void 0&&(m(e),t.onChange((0,n.setPatternDecimal)(e,d)))}})}),(0,u.jsx)(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:r(`sheet.numfmt.currencyDes`)})]})},M=`customFormat`,N=`numfmt_custom_pattern`;function P(t){let{defaultPattern:r,action:i,onChange:o}=t,s=(0,a.useDependency)(w),f=(0,a.useDependency)(e.ILocalStorageService),p=(0,a.useDependency)(e.LocaleService),[m,h]=(0,l.useState)(r);i.current=()=>(s.markHabit(M,m),f.getItem(N).then((e=[])=>{let t=[...new Set([m,...e||[]])].splice(0,10).filter(e=>!!e);f.setItem(N,t)}),m);let[g,_]=(0,l.useState)([]);(0,l.useEffect)(()=>{f.getItem(N).then(e=>{let t=[...n.CURRENCYFORMAT.map(e=>e.suffix(`$`)),...n.DATEFMTLISG.map(e=>e.suffix),...n.NUMBERFORMAT.map(e=>e.suffix)];t.push(...e||[]),s.addHabit(M,[]).finally(()=>{s.getHabit(M,t).then(e=>{_([...new Set(e)])})})})},[]);let v=e=>{h(e),o(e)};return(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:p.t(`sheet.numfmt.customFormat`)}),(0,u.jsx)(c.Input,{placeholder:p.t(`sheet.numfmt.customFormat`),onBlur:()=>{o(m)},value:m,onChange:h,className:`univer-mt-2 univer-w-full`}),(0,u.jsx)(`div`,{className:(0,c.clsx)(`univer-mt-2 univer-max-h-[400px] univer-overflow-auto univer-rounded-lg univer-p-2`,c.borderClassName),children:g.map(e=>(0,u.jsxs)(`div`,{onClick:()=>v(e),className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-1.5 univer-py-1.5 univer-text-sm`,children:[(0,u.jsx)(`div`,{className:`univer-flex univer-w-4 univer-items-center univer-text-primary-600`,children:m===e&&(0,u.jsx)(d.CheckMarkIcon,{})}),(0,u.jsx)(`div`,{children:e})]},e))}),(0,u.jsx)(`div`,{className:`univer-mt-3 univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200`,children:p.t(`sheet.numfmt.customFormatDes`)})]})}const F=t=>{let r=e.numfmt.getFormatInfo(t);return(0,n.getDateFormatOptions)().map(e=>e.value).includes(t)||[`date`,`datetime`,`time`].includes(r.type)};function ee(t){let{onChange:r,defaultPattern:i}=t,o=(0,l.useMemo)(n.getDateFormatOptions,[]),s=(0,a.useDependency)(e.LocaleService),[d,f]=(0,l.useState)(()=>{if(i){let e=o.find(e=>e.value===i);if(e)return e.value}return o[0].value});return t.action.current=()=>d,(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:s.t(`sheet.numfmt.dateType`)}),(0,u.jsx)(`div`,{className:`univer-mt-2`,children:(0,u.jsx)(c.SelectList,{value:d,options:o,onChange:e=>{e!==void 0&&(f(e),r(e))}})}),(0,u.jsx)(`div`,{className:`univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200`,children:s.t(`sheet.numfmt.dateDes`)})]})}const te=e=>!e,ne=t=>{let n=(0,a.useDependency)(e.LocaleService).t;return t.action.current=()=>``,(0,u.jsx)(`div`,{children:(0,u.jsx)(`div`,{className:`univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200`,children:n(`sheet.numfmt.generalDes`)})})},re=t=>(0,n.getNumberFormatOptions)().some(n=>(0,e.isPatternEqualWithoutDecimal)(n.value,t));function ie(t){let r=(0,a.useDependency)(e.LocaleService),i=(0,l.useMemo)(n.getNumberFormatOptions,[]),[o,s]=(0,l.useState)(()=>(0,n.getDecimalFromPattern)(t.defaultPattern||``,0)),[d,f]=(0,l.useState)(()=>{let n=i.find(n=>(0,e.isPatternEqualWithoutDecimal)(n.value,t.defaultPattern||``));return(n==null?void 0:n.value)||i[0].value}),p=(0,l.useMemo)(()=>(0,n.setPatternDecimal)(d,Number(o||0)),[d,o]),m=(0,l.useMemo)(()=>!(0,n.isPatternHasDecimal)(d),[d]),h=e=>{s(e||0),t.onChange((0,n.setPatternDecimal)(d,Number(e||0)))},g=e=>{e!==void 0&&(s((0,n.getDecimalFromPattern)(e,0)),f(e),t.onChange(e))};return t.action.current=()=>p,(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:r.t(`sheet.numfmt.decimalLength`)}),(0,u.jsx)(`div`,{className:`univer-mt-2`,children:(0,u.jsx)(c.InputNumber,{disabled:m,value:o,max:20,min:0,onChange:h})}),(0,u.jsxs)(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:[` `,r.t(`sheet.numfmt.negType`)]}),(0,u.jsx)(`div`,{className:`univer-mt-2`,children:(0,u.jsx)(c.SelectList,{onChange:g,options:i,value:d})}),(0,u.jsx)(`div`,{className:`univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200`,children:r.t(`sheet.numfmt.thousandthPercentileDes`)})]})}const I=t=>{let{defaultValue:r,defaultPattern:i,row:o,col:s}=t.value,d=(0,a.useDependency)(e.LocaleService),f=(0,l.useRef)(()=>``),p=d.t,m=D(),h=(0,l.useMemo)(()=>[{label:`sheet.numfmt.general`,component:ne},{label:`sheet.numfmt.accounting`,component:k},{label:`sheet.numfmt.currency`,component:j},{label:`sheet.numfmt.date`,component:ee},{label:`sheet.numfmt.thousandthPercentile`,component:ie},{label:`sheet.numfmt.customFormat`,component:P}].map(e=>({...e,label:p(e.label)})),[]),[g,_]=(0,l.useState)(w),[v,y]=(0,l.useState)(()=>`${o}_${s}`),{mark:b,userHabitCurrency:x}=E(()=>y(`${o}_${s}_userCurrency'`)),S=(0,l.useMemo)(()=>{var e;return(e=h.find(e=>e.label===g))==null?void 0:e.component},[g]);function w(){return[te,O,A,F,re].reduce((e,t,n)=>e||(t(i)?h[n].label:``),``)||h[0].label}let T=h.map(e=>({label:e.label,value:e.label})),M=e=>{_(e),m(()=>t.onChange({type:`change`,value:f.current()||``}))},N=(0,l.useCallback)(e=>{t.onChange({type:`change`,value:e})},[]),I=()=>{let e=f.current()||``,r=(0,n.getCurrencyType)(e);r&&b(r),t.onChange({type:`confirm`,value:e})},L=()=>{t.onChange({type:`cancel`,value:``})},R={onChange:N,defaultValue:r,defaultPattern:i,action:f};return(0,l.useEffect)(()=>{_(w()),y(`${o}_${s}`)},[o,s]),(0,u.jsxs)(`div`,{className:(0,c.clsx)(`univer-flex univer-h-full univer-flex-col univer-justify-between univer-overflow-y-auto univer-pb-5`,c.scrollbarClassName),children:[(0,u.jsxs)(`div`,{children:[(0,u.jsx)(`div`,{className:`univer-mt-3.5 univer-text-sm univer-text-gray-400`,children:p(`sheet.numfmt.numfmtType`)}),(0,u.jsx)(`div`,{className:`univer-mt-2`,children:(0,u.jsx)(c.Select,{className:`univer-w-full`,value:g,options:T,onChange:M})}),(0,u.jsx)(`div`,{children:S&&(0,u.jsx)(C.Provider,{value:x,children:(0,l.createElement)(S,{...R,key:v})})})]}),(0,u.jsxs)(`div`,{className:`univer-mb-5 univer-mt-3.5 univer-flex univer-justify-end`,children:[(0,u.jsx)(c.Button,{onClick:L,className:`univer-mr-3`,children:p(`sheet.numfmt.cancel`)}),(0,u.jsx)(c.Button,{variant:`primary`,onClick:I,children:p(`sheet.numfmt.confirm`)})]})]})};function L(e){"@babel/helpers - typeof";return L=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},L(e)}function R(e,t){if(L(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(L(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function z(e){var t=R(e,`string`);return L(t)==`symbol`?t:t+``}function B(e,t,n){return(t=z(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const V=`SHEET_NUMFMT_PANEL`;let H=class extends e.Disposable{constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._sheetInterceptorService=e,this._themeService=t,this._univerInstanceService=n,this._commandService=r,this._selectionManagerService=i,this._renderManagerService=a,this._numfmtService=o,this._componentManager=s,this._sidebarService=c,this._localeService=l,this._sheetsNumfmtCellContentController=u,B(this,`_previewPattern`,``),B(this,`_sidebarDisposable`,null),this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener(),this._initNumfmtLocalChange()}_initNumfmtLocalChange(){this.disposeWithMe((0,o.merge)(this._sheetsNumfmtCellContentController.locale$,this._localeService.currentLocale$).subscribe(()=>{this._forceUpdate()}))}openPanel(){var t;let r=this._sidebarService,i=this._selectionManagerService,a=this._commandService,o=this._univerInstanceService,s=this._numfmtService,c=this._localeService,l=(((t=i.getCurrentSelections())==null?void 0:t.map(e=>e.range))||[])[0];if(!l)return!1;let u=o.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SHEET),d=u.getActiveSheet();if(!d)return!1;let f=d.getCellRaw(l.startRow,l.startColumn),p=s.getValue(u.getUnitId(),d.getSheetId(),l.startRow,l.startColumn),m=``;p&&(m=p.pattern);let h=(f==null?void 0:f.t)===e.CellValueType.NUMBER?f.v:12345678,g={onChange:t=>{if(t.type===`change`)this._previewPattern=t.value,this._forceUpdate();else if(t.type===`confirm`){var o;let s=((o=i.getCurrentSelections())==null?void 0:o.map(e=>e.range))||[],c={values:[]},l=(0,n.getPatternType)(t.value);s.forEach(n=>{e.Range.foreach(n,(e,n)=>{c.values.push({row:e,col:n,pattern:t.value,type:l})})}),a.executeCommand(n.SetNumfmtCommand.id,c),r.close()}else t.type===`cancel`&&r.close()},value:{defaultPattern:m,defaultValue:h,row:l.startRow,col:l.startColumn}};return this._sidebarDisposable=r.open({header:{title:c.t(`sheet.numfmt.title`)},children:{label:V,...g},onClose:()=>{this._forceUpdate(),a.executeCommand(x.id)}}),!0}_forceUpdate(t){var n;let i=this._renderManagerService.getRenderById(t==null?this._univerInstanceService.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SHEET).getUnitId():t);i==null||i.with(r.SheetSkeletonManagerService).reCalculate(),i==null||(n=i.mainComponent)==null||n.makeDirty()}_initCommands(){[S,x].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initPanel(){this.disposeWithMe(this._componentManager.register(V,I))}_initRealTimeRenderingInterceptor(){let t=(0,o.combineLatest)([new o.Observable(e=>{this._commandService.onCommandExecuted(t=>{t.id===S.id&&e.next(!0),t.id===x.id&&e.next(!1)})}),this._selectionManagerService.selectionMoveEnd$.pipe((0,s.map)(e=>e?e.map(e=>e.range):[]))]);this.disposeWithMe((0,e.toDisposable)(t.pipe((0,s.switchMap)(([t,n])=>new o.Observable(r=>{let i=new e.DisposableCollection;return t&&n.length&&r.next({selectionRanges:n,disposableCollection:i}),()=>{i.dispose()}})),(0,s.tap)(()=>{this._previewPattern=null})).subscribe(({disposableCollection:t,selectionRanges:r})=>{var a;let o=this._univerInstanceService.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SHEET);this.openPanel(),t.add(this._sheetInterceptorService.intercept(i.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,effect:e.InterceptorEffectEnum.Value|e.InterceptorEffectEnum.Style,handler:(t,i,a)=>{let{row:o,col:s}=i,c=a(t)||{};if(r.find(e=>e.startColumn<=s&&e.endColumn>=s&&e.startRow<=o&&e.endRow>=o)){let t=i.worksheet.getCellRaw(o,s),r=t==null?void 0:t.v,a=t==null?void 0:t.t;if(r==null||a!==e.CellValueType.NUMBER||this._previewPattern===null)return c;let u=(0,n.getPatternPreviewIgnoreGeneral)(this._previewPattern,r,this._sheetsNumfmtCellContentController.locale);if(u.color){var l;let t=(l=this._themeService.getColorFromTheme(`${u.color}.500`))==null?u.color:l;return{...c,v:u.result,t:e.CellValueType.STRING,s:{cl:{rgb:t}}}}return{...c,v:u.result,t:e.CellValueType.STRING}}return c}})),(a=this._renderManagerService.getRenderById(o.getUnitId()))==null||(a=a.mainComponent)==null||a.makeDirty()})))}_commandExecutedListener(){let e=[i.RemoveNumfmtMutation.id,i.SetNumfmtMutation.id];this.disposeWithMe(new o.Observable(t=>{let n=this._commandService.onCommandExecuted(n=>{if(e.includes(n.id)){let e=n.params;t.next(e.unitId)}});return()=>n.dispose()}).pipe((0,s.debounceTime)(16)).subscribe(e=>this._forceUpdate(e)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(e.UniverInstanceType.UNIVER_SHEET).subscribe(e=>{if(!e){var t;(t=this._sidebarDisposable)==null||t.dispose(),this._sidebarDisposable=null}})}};H=_([g(0,(0,e.Inject)(i.SheetInterceptorService)),g(1,(0,e.Inject)(e.ThemeService)),g(2,e.IUniverInstanceService),g(3,e.ICommandService),g(4,(0,e.Inject)(i.SheetsSelectionsService)),g(5,t.IRenderManagerService),g(6,i.INumfmtService),g(7,(0,e.Inject)(a.ComponentManager)),g(8,a.ISidebarService),g(9,(0,e.Inject)(e.LocaleService)),g(10,(0,e.Inject)(n.SheetsNumfmtCellContentController))],H);const U=()=>{let e=[];return{add:(t,n,r,i,a)=>e.push({unitId:t,subUnitId:n,row:r,col:i,value:a}),getEffects:()=>e,clean:()=>{e=[]}}};let W=class extends e.Disposable{constructor(e,t,n,r,i){super(),this._sheetInterceptorService=e,this._numfmtService=t,this._univerInstanceService=n,this._injector=r,this._editorBridgeService=i,B(this,`_collectEffectMutation`,U()),this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe((0,e.toDisposable)(this._sheetInterceptorService.writeCellInterceptor.intercept(i.BEFORE_CELL_EDIT,{handler:(t,r,i)=>{let a=r.row,o=r.col,s=this._numfmtService.getValue(r.unitId,r.subUnitId,a,o);if(s)switch((0,n.getPatternType)(s.pattern)){case`scientific`:case`currency`:case`grouped`:case`number`:{let t={...r.worksheet.getCellRaw(a,o)};return(t==null?void 0:t.t)===e.CellValueType.NUMBER&&(0,e.isRealNum)(t.v)&&(t.v=(0,f.stripErrorMargin)(Number(t.v))),i&&i(t)}case`percent`:{let t={...r.worksheet.getCellRaw(a,o)};return(t==null?void 0:t.t)===e.CellValueType.NUMBER&&(0,e.isRealNum)(t.v)&&(t.v=`${(0,f.stripErrorMargin)(Number(t.v)*100)}%`),i&&i(t)}default:return i&&i(t)}return i(t)}})))}_initInterceptorEditorEnd(){this.disposeWithMe((0,e.toDisposable)(this._sheetInterceptorService.writeCellInterceptor.intercept(i.AFTER_CELL_EDIT,{handler:(t,r,i)=>{var a,o;if(!(t!=null&&t.v)&&!(t!=null&&t.p))return i(t);this._collectEffectMutation.clean();let s=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col),c=r.worksheet.getCellRaw(r.row,r.col);if((0,e.isTextFormat)(s==null?void 0:s.pattern)||t.t===e.CellValueType.FORCE_STRING)return i(t);let l=(a=t.p)==null?void 0:a.body,u=!(t==null||(o=t.p)==null||(o=o.body)==null)&&o.dataStream?t.p.body.dataStream.replace(/\r\n$/,``):String(t.v),d=(0,e.getNumfmtParseValueFilter)(u);if(l)if(G(l)){let{dataStream:e}=l,n=e.replace(/\r\n$/,``),r=Number(n);if(Number.isNaN(r)&&!d)return i(t)}else return i(t);if(d){if(!d.z&&!(s!=null&&s.pattern)&&(c==null?void 0:c.t)!==e.CellValueType.STRING&&(c==null?void 0:c.t)!==e.CellValueType.FORCE_STRING&&(0,e.willLoseNumericPrecision)(u))return i({...t,p:void 0,v:u,t:e.CellValueType.FORCE_STRING});d.z&&(!(s!=null&&s.pattern)||(0,n.getPatternType)(d.z)!==(0,n.getPatternType)(s.pattern))&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:d.z});let a=(0,f.stripErrorMargin)(Number(d.v),16);return i({...t,p:void 0,v:a,t:e.CellValueType.NUMBER})}return i(t)}})))}_initInterceptorCommands(){let t=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(n){switch(n.id){case i.SetRangeValuesCommand.id:{var r;let n=t._univerInstanceService.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SHEET),a=n.getUnitId(),o=(r=n.getActiveSheet())==null?void 0:r.getSheetId();if(!o)return{redos:[],undos:[]};let s=t._collectEffectMutation.getEffects();if(t._collectEffectMutation.clean(),!s.length)return{redos:[],undos:[]};let c=s.filter(e=>{var t;return!!((t=e.value)!=null&&t.pattern)}).map(e=>({row:e.row,col:e.col,pattern:e.value.pattern})),l=s.filter(e=>{var t;return!((t=e.value)!=null&&t.pattern)}).map(e=>({startRow:e.row,endColumn:e.col,startColumn:e.col,endRow:e.row})),u=[],d=[];if(c.length){let e={id:i.SetNumfmtMutation.id,params:(0,i.transformCellsToRange)(a,o,c)};u.push(e),d.push(...(0,i.factorySetNumfmtUndoMutation)(t._injector,e.params))}if(l.length){let e={id:i.RemoveNumfmtMutation.id,params:{unitId:a,subUnitId:o,ranges:l}};u.push(e),d.push(...(0,i.factoryRemoveNumfmtUndoMutation)(t._injector,e.params))}return{redos:u,undos:d.reverse()}}}return{redos:[],undos:[]}}}))}dispose(){super.dispose(),this._collectEffectMutation.clean()}};W=_([g(0,(0,e.Inject)(i.SheetInterceptorService)),g(1,(0,e.Inject)(i.INumfmtService)),g(2,(0,e.Inject)(e.IUniverInstanceService)),g(3,(0,e.Inject)(e.Injector)),g(4,(0,e.Optional)(r.IEditorBridgeService))],W);function G(e){let{textRuns:t=[],paragraphs:n=[],customRanges:r,customBlocks:i=[]}=e,a=[`va`];return!(t.some(e=>!!(e.ts&&Object.keys(e.ts).some(e=>a.includes(e))))||n.some(e=>e.bullet)||n.length>=2||r!=null&&r.length||i.length>0)}const K=t=>[{label:`sheet.numfmt.general`,pattern:null},{label:`sheet.numfmt.text`,pattern:e.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:`"${t}" #,##0.00_);[Red]("${t}"#,##0.00)`},{label:`sheet.numfmt.financialValue`,pattern:`#,##0.00;[Red]#,##0.00`},{label:`sheet.numfmt.currency`,pattern:`"${t}"#,##0.00_);[Red]("${t}"#,##0.00)`},{label:`sheet.numfmt.roundingCurrency`,pattern:`"${t}"#,##0;[Red]"${t}"#,##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:``}],q=t=>({icon:new o.Observable(r=>{let i=t.get(e.LocaleService);return r.next((0,n.getCurrencySymbolIconByLocale)(i.getCurrentLocale()).icon),i.localeChanged$.subscribe(()=>{r.next((0,n.getCurrencySymbolIconByLocale)(i.getCurrentLocale()).icon)})}),id:n.SetCurrencyCommand.id,title:`sheet.numfmt.currency`,tooltip:`sheet.numfmt.currency`,type:a.MenuItemType.BUTTON,hidden$:(0,a.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_SHEET),disabled$:(0,r.getCurrentRangeDisable$)(t,{workbookTypes:[i.WorkbookEditablePermission],worksheetTypes:[i.WorksheetEditPermission,i.WorksheetSetCellStylePermission],rangeTypes:[i.RangeProtectionPermissionEditPoint]})}),J=t=>({icon:`AddDigitsIcon`,id:n.AddDecimalCommand.id,title:`sheet.numfmt.addDecimal`,tooltip:`sheet.numfmt.addDecimal`,type:a.MenuItemType.BUTTON,hidden$:(0,a.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_SHEET),disabled$:(0,r.getCurrentRangeDisable$)(t,{workbookTypes:[i.WorkbookEditablePermission],worksheetTypes:[i.WorksheetEditPermission,i.WorksheetSetCellStylePermission],rangeTypes:[i.RangeProtectionPermissionEditPoint]})}),ae=t=>({icon:`ReduceDigitsIcon`,id:n.SubtractDecimalCommand.id,title:`sheet.numfmt.subtractDecimal`,tooltip:`sheet.numfmt.subtractDecimal`,type:a.MenuItemType.BUTTON,hidden$:(0,a.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_SHEET),disabled$:(0,r.getCurrentRangeDisable$)(t,{workbookTypes:[i.WorkbookEditablePermission],worksheetTypes:[i.WorksheetEditPermission,i.WorksheetSetCellStylePermission],rangeTypes:[i.RangeProtectionPermissionEditPoint]})}),oe=t=>({icon:`PercentIcon`,id:n.SetPercentCommand.id,title:`sheet.numfmt.percent`,tooltip:`sheet.numfmt.percent`,type:a.MenuItemType.BUTTON,hidden$:(0,a.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_SHEET),disabled$:(0,r.getCurrentRangeDisable$)(t,{workbookTypes:[i.WorkbookEditablePermission],worksheetTypes:[i.WorksheetEditPermission,i.WorksheetSetCellStylePermission],rangeTypes:[i.RangeProtectionPermissionEditPoint]})}),se=t=>{let s=t.get(e.IUniverInstanceService),c=t.get(e.ICommandService),l=t.get(e.LocaleService),u=t.get(i.SheetsSelectionsService),d=[i.RemoveNumfmtMutation.id,i.SetNumfmtMutation.id],f=(0,r.deriveStateFromActiveSheet$)(s,``,({workbook:t,worksheet:r})=>new o.Observable(i=>(0,o.merge)(u.selectionMoveEnd$,(0,e.fromCallback)(c.onCommandExecuted.bind(c)).pipe((0,o.filter)(([e])=>d.includes(e.id)))).subscribe(()=>{let a=u.getCurrentSelections();if(a&&a[0]){var o,s;let c=a[0].range,u=c.startRow,d=c.startColumn,f=(o=t.getStyles().get((s=r.getCell(u,d))==null?void 0:s.s))==null?void 0:o.n,p=f==null?void 0:f.pattern,m=(0,n.getCurrencySymbolByLocale)(l.getCurrentLocale()),h=l.t(`sheet.numfmt.general`);if((0,e.isDefaultFormat)(p)){i.next(h);return}if(p){let t=K(m).filter(e=>typeof e==`object`&&e.pattern).find(t=>(0,e.isPatternEqualWithoutDecimal)(p,t.pattern));h=t&&typeof t==`object`&&t.pattern?l.t(t.label):l.t(`sheet.numfmt.moreFmt`)}i.next(h)}})));return{label:Y,id:S.id,tooltip:`sheet.numfmt.title`,type:a.MenuItemType.SELECTOR,slot:!0,selections:[{label:{name:X,hoverable:!1,selectable:!1}}],value$:f,hidden$:(0,a.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_SHEET),disabled$:(0,r.getCurrentRangeDisable$)(t,{workbookTypes:[i.WorkbookEditablePermission],worksheetTypes:[i.WorksheetSetCellStylePermission,i.WorksheetEditPermission],rangeTypes:[i.RangeProtectionPermissionEditPoint]})}},Y=`sheet.numfmt.moreNumfmtType`,X=`sheet.numfmt.moreNumfmtType.options`;function ce(t){let{value:n}=t,r=(0,a.useDependency)(e.LocaleService);return(0,u.jsx)(`span`,{className:`univer-text-sm`,children:n==null?r.t(`sheet.numfmt.general`):n})}function Z(){let t=(0,a.useDependency)(e.ICommandService),r=(0,a.useDependency)(e.LocaleService),o=(0,a.useDependency)(a.ILayoutService),s=(0,a.useDependency)(n.SheetsNumfmtCellContentController),d=(0,a.useDependency)(i.SheetsSelectionsService),f=r=>{let i=d.getCurrentLastSelection();if(!i)return;let a=i.range,s=[];e.Range.foreach(a,(e,t)=>{r?s.push({row:e,col:t,pattern:r,type:(0,n.getPatternType)(r)}):s.push({row:e,col:t})}),t.executeCommand(n.SetNumfmtCommand.id,{values:s}),o.focus()},p=(0,l.useMemo)(()=>K(n.localeCurrencySymbolMap.get(r.getCurrentLocale())),[r]),m=e=>{if(e===0)f(null);else if(e===p.length-1)t.executeCommand(S.id),o.focus();else{let t=p[e];t.pattern&&f(t.pattern)}};return(0,u.jsx)(`div`,{className:`univer-grid univer-gap-1 univer-p-1.5`,children:p.map((e,t)=>e===`|`?(0,u.jsx)(c.Separator,{},t):(0,u.jsxs)(`div`,{className:`univer-flex univer-h-7 univer-cursor-default univer-items-center univer-justify-between univer-gap-6 univer-rounded univer-px-2 univer-text-sm hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700`,onClick:()=>m(t),children:[(0,u.jsx)(`span`,{children:r.t(e.label)}),(0,u.jsx)(`span`,{className:`univer-text-xs univer-text-gray-500 dark:!univer-text-gray-400`,children:e.pattern?(0,n.getPatternPreview)(e.pattern||``,1220,s.locale).result.trim():``})]},t))})}const le={[a.RibbonStartGroup.LAYOUT]:{[S.id]:{order:9,menuItemFactory:se},[n.SetPercentCommand.id]:{order:9.1,menuItemFactory:oe},[n.SetCurrencyCommand.id]:{order:9.2,menuItemFactory:q},[n.AddDecimalCommand.id]:{order:9.3,menuItemFactory:J},[n.SubtractDecimalCommand.id]:{order:9.4,menuItemFactory:ae}}};let Q=class extends e.Disposable{constructor(e,t){super(),this._componentManager=e,this._menuManagerService=t,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(le),[[Y,ce],[X,Z]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};Q=_([g(0,(0,e.Inject)(a.ComponentManager)),g(1,a.IMenuManagerService)],Q);let $=class extends e.Plugin{constructor(t=h,n,r,i){super(),this._config=t,this._injector=n,this._configService=r,this._renderManagerService=i;let{menu:a,...o}=(0,e.merge)({},h,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(`sheets-numfmt-ui.config`,o)}onStarting(){(0,e.registerDependencies)(this._injector,[[H],[W],[w],[Q],[b]])}onRendered(){this._registerRenderModules(),(0,e.touchDependencies)(this._injector,[[H],[W],[Q],[b]])}_registerRenderModules(){[[y]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(e.UniverInstanceType.UNIVER_SHEET,t))})}};B($,`pluginName`,`SHEET_NUMFMT_UI_PLUGIN`),B($,`packageName`,p),B($,`version`,m),B($,`type`,e.UniverInstanceType.UNIVER_SHEET),$=_([(0,e.DependentOn)(r.UniverSheetsUIPlugin,n.UniverSheetsNumfmtPlugin),g(1,(0,e.Inject)(e.Injector)),g(2,e.IConfigService),g(3,t.IRenderManagerService)],$),Object.defineProperty(exports,`UniverSheetsNumfmtUIPlugin`,{enumerable:!0,get:function(){return $}});
package/lib/es/index.js CHANGED
@@ -1,26 +1 @@
1
- import{CellValueType as e,CommandType as t,DEFAULT_TEXT_FORMAT_EXCEL as n,DependentOn as r,Disposable as i,DisposableCollection as a,ICommandService as o,IConfigService as s,ILocalStorageService as c,IUniverInstanceService as l,Inject as u,Injector as d,InterceptorEffectEnum as f,LocaleService as p,Optional as m,Plugin as h,Range as ee,ThemeService as g,Tools as _,UniverInstanceType as v,fromCallback as te,getNumfmtParseValueFilter as ne,isDefaultFormat as re,isPatternEqualWithoutDecimal as y,isRealNum as b,isTextFormat as ie,merge as ae,numfmt as oe,registerDependencies as se,toDisposable as ce,touchDependencies as le,willLoseNumericPrecision as ue}from"@univerjs/core";import{IRenderManagerService as de}from"@univerjs/engine-render";import{AddDecimalCommand as fe,CURRENCYFORMAT as pe,DATEFMTLISG as me,NUMBERFORMAT as he,SHEETS_NUMFMT_PLUGIN_CONFIG_KEY as ge,SetCurrencyCommand as _e,SetNumfmtCommand as ve,SetPercentCommand as ye,SheetsNumfmtCellContentController as be,SubtractDecimalCommand as xe,UniverSheetsNumfmtPlugin as Se,currencySymbols as Ce,getCurrencyFormatOptions as x,getCurrencySymbolByLocale as we,getCurrencySymbolIconByLocale as Te,getCurrencyType as S,getDateFormatOptions as Ee,getDecimalFromPattern as C,getNumberFormatOptions as De,getPatternPreview as Oe,getPatternPreviewIgnoreGeneral as ke,getPatternType as w,isPatternHasDecimal as Ae,localeCurrencySymbolMap as je,setPatternDecimal as T}from"@univerjs/sheets-numfmt";import{CellAlertManagerService as Me,CellAlertType as Ne,HoverManagerService as Pe,IEditorBridgeService as Fe,SheetSkeletonManagerService as Ie,UniverSheetsUIPlugin as Le,deriveStateFromActiveSheet$ as Re,getCurrentRangeDisable$ as E}from"@univerjs/sheets-ui";import{AFTER_CELL_EDIT as ze,BEFORE_CELL_EDIT as Be,INTERCEPTOR_POINT as Ve,INumfmtService as He,RangeProtectionPermissionEditPoint as D,RemoveNumfmtMutation as O,SetNumfmtMutation as Ue,SetRangeValuesCommand as We,SheetInterceptorService as Ge,SheetsSelectionsService as Ke,WorkbookEditablePermission as k,WorksheetEditPermission as A,WorksheetSetCellStylePermission as j,factoryRemoveNumfmtUndoMutation as qe,factorySetNumfmtUndoMutation as Je,transformCellsToRange as Ye}from"@univerjs/sheets";import{ComponentManager as Xe,ILayoutService as Ze,IMenuManagerService as Qe,ISidebarService as $e,IZenZoneService as et,MenuItemType as M,RibbonStartGroup as tt,getMenuHiddenObservable as N,useDependency as P}from"@univerjs/ui";import{Observable as F,combineLatest as nt,debounceTime as rt,filter as it,merge as at}from"rxjs";import{debounceTime as ot,map as st,switchMap as ct,tap as lt}from"rxjs/operators";import{Button as ut,Input as dt,InputNumber as ft,Select as I,SelectList as pt,Separator as mt,borderClassName as ht,clsx as gt,scrollbarClassName as _t}from"@univerjs/design";import{createContext as vt,createElement as yt,useCallback as bt,useContext as xt,useEffect as L,useMemo as R,useRef as St,useState as z}from"react";import{jsx as B,jsxs as V}from"react/jsx-runtime";import{CheckMarkIcon as Ct}from"@univerjs/icons";import{stripErrorMargin as H}from"@univerjs/engine-formula";var wt=`@univerjs/sheets-numfmt-ui`,Tt=`0.18.0`;const Et={};function U(e,t){return function(n,r){t(n,r,e)}}function W(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}const G=`SHEET_NUMFMT_ALERT`;let Dt=class extends i{constructor(e,t,n,r,i,a,o){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=n,this._localeService=r,this._zenZoneService=i,this._numfmtService=a,this._configService=o,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(rt(100)).subscribe(e=>{if(e){let r=e.location,i=this._context.unit,a=i.getActiveSheet();if(!a)return this._hideAlert();let o=r.unitId,s=r.subUnitId,c,l=a.getCell(r.row,r.col);if(l!=null&&l.s){let e=i.getStyles().get(l.s);e!=null&&e.n&&(c=e.n)}if(c||(c=this._numfmtService.getValue(o,s,r.row,r.col)),!c){this._hideAlert();return}if(ie(c.pattern)&&_.isDefine(l==null?void 0:l.v)&&b(l.v)){var t,n;if((t=this._configService.getConfig(ge))!=null&&t.disableTextFormatAlert)return;let e=this._cellAlertManagerService.currentAlert.get(G),i=e==null||(n=e.alert)==null?void 0:n.location;if(i&&i.row===r.row&&i.col===r.col&&i.subUnitId===r.subUnitId&&i.unitId===r.unitId){this._hideAlert();return}this._cellAlertManagerService.showAlert({type:Ne.ERROR,title:this._localeService.t(`info.error`),message:this._localeService.t(`info.forceStringInfo`),location:r,width:200,height:74,key:G});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(G)}};Dt=W([U(1,u(Pe)),U(2,u(Me)),U(3,u(p)),U(4,et),U(5,u(He)),U(6,s)],Dt);const Ot={id:`sheet.operation.close.numfmt.panel`,type:t.OPERATION,handler:()=>!0},K={id:`sheet.operation.open.numfmt.panel`,type:t.OPERATION,handler:e=>(e.get(X).openPanel(),!0)},kt=vt([]);let q=class{constructor(e){this._localStorageService=e}_getKey(e){return`userHabitController_${e}`}async addHabit(e,t){let n=this._getKey(e);return this._localStorageService.getItem(n).then(e=>{e||this._localStorageService.setItem(n,t)})}markHabit(e,t){let n=this._getKey(e);this._localStorageService.getItem(n).then(e=>{if(e){let r=e.findIndex(e=>e===t);r>-1&&e.splice(r,1),e.unshift(t),this._localStorageService.setItem(n,e)}})}async getHabit(e,t){let n=this._getKey(e),r=await this._localStorageService.getItem(n);if(t&&r){let e=r.map((e,t,n)=>({value:e,priority:n.length-t}));return t.sort((t,n)=>{var r,i;let a=((r=e.find(e=>e.value===t))==null?void 0:r.priority)||-1;return(((i=e.find(e=>e.value===n))==null?void 0:i.priority)||-1)-a})}return r||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};q=W([U(0,u(c))],q);const At=`numfmtCurrency`,jt=e=>{let t=P(q),[n,r]=z(Ce);return L(()=>{t.addHabit(`numfmtCurrency`,[]).then(()=>{t.getHabit(At,[...Ce]).then(t=>{r(t),e&&e(t)})})},[]),{userHabitCurrency:n,mark:e=>{t.markHabit(At,e)}}},Mt=()=>{let e=St([]),[t,n]=z({});return L(()=>{e.current.forEach(e=>{e()}),e.current=[]},[t]),t=>{e.current.push(t),n({})}},Nt=e=>!!S(e)&&e.startsWith(`_(`),Pt=e=>{let{defaultPattern:t,action:n,onChange:r}=e,[i,a]=z(()=>C(t||``,2)),o=xt(kt),[s,c]=z(()=>S(t)||o[0]),l=R(()=>o.map(e=>({label:e,value:e})),[]),u=P(p).t;return n.current=()=>T(`_("${s}"* #,##0${i>0?`.0`:``}_)`,i),V(`div`,{children:[V(`div`,{className:`univer-mt-4 univer-flex univer-justify-between`,children:[V(`div`,{className:`option`,children:[B(`div`,{className:`univer-text-sm univer-text-gray-400`,children:u(`sheet.numfmt.decimalLength`)}),B(`div`,{className:`univer-mt-2 univer-w-32`,children:B(ft,{value:i,step:1,precision:0,max:20,min:0,onChange:e=>{let t=e||0;a(t),r(T(`_("${s}"* #,##0${t>0?`.0`:``}_)`,t))}})})]}),V(`div`,{className:`option`,children:[B(`div`,{className:`univer-text-sm univer-text-gray-400`,children:u(`sheet.numfmt.currencyType`)}),B(`div`,{className:`univer-mt-2 univer-w-36`,children:B(I,{options:l,value:s,onChange:e=>{c(e),r(T(`_("${e}"* #,##0${i>0?`.0`:``}_)`,i))}})})]})]}),B(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:u(`sheet.numfmt.accountingDes`)})]})},Ft=e=>!!S(e)&&!e.startsWith(`_(`),It=e=>{let t=P(p).t,n=xt(kt),[r,i]=z(()=>S(e.defaultPattern)||n[0]),[a,o]=z(()=>C(e.defaultPattern||``,2)),[s,c]=z(()=>{var t;let n=x(r);return((t=n.find(t=>y(t.value,e.defaultPattern)))==null?void 0:t.value)||n[0].value}),l=R(()=>x(r),[r]),u=R(()=>n.map(e=>({label:e,value:e})),[n]);return e.action.current=()=>T(s,a),V(`div`,{children:[V(`div`,{className:`univer-mt-4 univer-flex univer-justify-between`,children:[V(`div`,{className:`option`,children:[B(`div`,{className:`univer-text-sm univer-text-gray-400`,children:t(`sheet.numfmt.decimalLength`)}),B(`div`,{className:`univer-mt-2 univer-w-32`,children:B(ft,{value:a,max:20,min:0,onChange:t=>{o(t||0),e.onChange(T(s,t||0))}})})]}),V(`div`,{className:`option`,children:[B(`div`,{className:`univer-text-sm univer-text-gray-400`,children:t(`sheet.numfmt.currencyType`)}),B(`div`,{className:`univer-mt-2 univer-w-36`,children:B(I,{value:r,options:u,onChange:t=>{if(t===void 0)return;i(t);let n=x(t)[0].value;c(n),e.onChange(T(n,a))}})})]})]}),B(`div`,{className:`label univer-mt-4`,children:t(`sheet.numfmt.negType`)}),B(`div`,{className:`univer-mt-2`,children:B(pt,{value:s,options:l,onChange:t=>{t!==void 0&&(c(t),e.onChange(T(t,a)))}})}),B(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:t(`sheet.numfmt.currencyDes`)})]})},Lt=`customFormat`,Rt=`numfmt_custom_pattern`;function zt(e){let{defaultPattern:t,action:n,onChange:r}=e,i=P(q),a=P(c),o=P(p),[s,l]=z(t);n.current=()=>(i.markHabit(Lt,s),a.getItem(Rt).then((e=[])=>{let t=[...new Set([s,...e||[]])].splice(0,10).filter(e=>!!e);a.setItem(Rt,t)}),s);let[u,d]=z([]);L(()=>{a.getItem(Rt).then(e=>{let t=[...pe.map(e=>e.suffix(`$`)),...me.map(e=>e.suffix),...he.map(e=>e.suffix)];t.push(...e||[]),i.addHabit(Lt,[]).finally(()=>{i.getHabit(Lt,t).then(e=>{d([...new Set(e)])})})})},[]);let f=e=>{l(e),r(e)};return V(`div`,{children:[B(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:o.t(`sheet.numfmt.customFormat`)}),B(dt,{placeholder:o.t(`sheet.numfmt.customFormat`),onBlur:()=>{r(s)},value:s,onChange:l,className:`univer-mt-2 univer-w-full`}),B(`div`,{className:gt(`univer-mt-2 univer-max-h-[400px] univer-overflow-auto univer-rounded-lg univer-p-2`,ht),children:u.map(e=>V(`div`,{onClick:()=>f(e),className:`
2
- univer-flex univer-cursor-pointer univer-items-center univer-gap-1.5 univer-py-1.5
3
- univer-text-sm
4
- `,children:[B(`div`,{className:`univer-flex univer-w-4 univer-items-center univer-text-primary-600`,children:s===e&&B(Ct,{})}),B(`div`,{children:e})]},e))}),B(`div`,{className:`
5
- univer-mt-3 univer-text-sm univer-text-gray-600
6
- dark:!univer-text-gray-200
7
- `,children:o.t(`sheet.numfmt.customFormatDes`)})]})}const Bt=e=>{let t=oe.getFormatInfo(e);return Ee().map(e=>e.value).includes(e)||[`date`,`datetime`,`time`].includes(t.type)};function Vt(e){let{onChange:t,defaultPattern:n}=e,r=R(Ee,[]),i=P(p),[a,o]=z(()=>{if(n){let e=r.find(e=>e.value===n);if(e)return e.value}return r[0].value});return e.action.current=()=>a,V(`div`,{children:[B(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:i.t(`sheet.numfmt.dateType`)}),B(`div`,{className:`univer-mt-2`,children:B(pt,{value:a,options:r,onChange:e=>{e!==void 0&&(o(e),t(e))}})}),B(`div`,{className:`
8
- univer-mt-3.5 univer-text-sm/5 univer-text-gray-600
9
- dark:!univer-text-gray-200
10
- `,children:i.t(`sheet.numfmt.dateDes`)})]})}const Ht=e=>!e,Ut=e=>{let t=P(p).t;return e.action.current=()=>``,B(`div`,{children:B(`div`,{className:`
11
- univer-mt-3.5 univer-text-sm/5 univer-text-gray-600
12
- dark:!univer-text-gray-200
13
- `,children:t(`sheet.numfmt.generalDes`)})})},Wt=e=>De().some(t=>y(t.value,e));function Gt(e){let t=P(p),n=R(De,[]),[r,i]=z(()=>C(e.defaultPattern||``,0)),[a,o]=z(()=>{let t=n.find(t=>y(t.value,e.defaultPattern||``));return(t==null?void 0:t.value)||n[0].value}),s=R(()=>T(a,Number(r||0)),[a,r]),c=R(()=>!Ae(a),[a]),l=t=>{i(t||0),e.onChange(T(a,Number(t||0)))},u=t=>{t!==void 0&&(i(C(t,0)),o(t),e.onChange(t))};return e.action.current=()=>s,V(`div`,{children:[B(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:t.t(`sheet.numfmt.decimalLength`)}),B(`div`,{className:`univer-mt-2`,children:B(ft,{disabled:c,value:r,max:20,min:0,onChange:l})}),V(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:[` `,t.t(`sheet.numfmt.negType`)]}),B(`div`,{className:`univer-mt-2`,children:B(pt,{onChange:u,options:n,value:a})}),B(`div`,{className:`
14
- univer-mt-3.5 univer-text-sm/5 univer-text-gray-600
15
- dark:!univer-text-gray-200
16
- `,children:t.t(`sheet.numfmt.thousandthPercentileDes`)})]})}const Kt=e=>{let{defaultValue:t,defaultPattern:n,row:r,col:i}=e.value,a=P(p),o=St(()=>``),s=a.t,c=Mt(),l=R(()=>[{label:`sheet.numfmt.general`,component:Ut},{label:`sheet.numfmt.accounting`,component:Pt},{label:`sheet.numfmt.currency`,component:It},{label:`sheet.numfmt.date`,component:Vt},{label:`sheet.numfmt.thousandthPercentile`,component:Gt},{label:`sheet.numfmt.customFormat`,component:zt}].map(e=>({...e,label:s(e.label)})),[]),[u,d]=z(_),[f,m]=z(()=>`${r}_${i}`),{mark:h,userHabitCurrency:ee}=jt(()=>m(`${r}_${i}_userCurrency'`)),g=R(()=>{var e;return(e=l.find(e=>e.label===u))==null?void 0:e.component},[u]);function _(){return[Ht,Nt,Ft,Bt,Wt].reduce((e,t,r)=>e||(t(n)?l[r].label:``),``)||l[0].label}let v=l.map(e=>({label:e.label,value:e.label})),te=t=>{d(t),c(()=>e.onChange({type:`change`,value:o.current()||``}))},ne=bt(t=>{e.onChange({type:`change`,value:t})},[]),re=()=>{let t=o.current()||``,n=S(t);n&&h(n),e.onChange({type:`confirm`,value:t})},y=()=>{e.onChange({type:`cancel`,value:``})},b={onChange:ne,defaultValue:t,defaultPattern:n,action:o};return L(()=>{d(_()),m(`${r}_${i}`)},[r,i]),V(`div`,{className:gt(`
17
- univer-flex univer-h-full univer-flex-col univer-justify-between univer-overflow-y-auto univer-pb-5
18
- `,_t),children:[V(`div`,{children:[B(`div`,{className:`univer-mt-3.5 univer-text-sm univer-text-gray-400`,children:s(`sheet.numfmt.numfmtType`)}),B(`div`,{className:`univer-mt-2`,children:B(I,{className:`univer-w-full`,value:u,options:v,onChange:te})}),B(`div`,{children:g&&B(kt.Provider,{value:ee,children:yt(g,{...b,key:f})})})]}),V(`div`,{className:`univer-mb-5 univer-mt-3.5 univer-flex univer-justify-end`,children:[B(ut,{onClick:y,className:`univer-mr-3`,children:s(`sheet.numfmt.cancel`)}),B(ut,{variant:`primary`,onClick:re,children:s(`sheet.numfmt.confirm`)})]})]})};function J(e){"@babel/helpers - typeof";return J=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},J(e)}function qt(e,t){if(J(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(J(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Jt(e){var t=qt(e,`string`);return J(t)==`symbol`?t:t+``}function Y(e,t,n){return(t=Jt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const Yt=`SHEET_NUMFMT_PANEL`;let X=class extends i{constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._sheetInterceptorService=e,this._themeService=t,this._univerInstanceService=n,this._commandService=r,this._selectionManagerService=i,this._renderManagerService=a,this._numfmtService=o,this._componentManager=s,this._sidebarService=c,this._localeService=l,this._sheetsNumfmtCellContentController=u,Y(this,`_previewPattern`,``),Y(this,`_sidebarDisposable`,null),this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener(),this._initNumfmtLocalChange()}_initNumfmtLocalChange(){this.disposeWithMe(at(this._sheetsNumfmtCellContentController.locale$,this._localeService.currentLocale$).subscribe(()=>{this._forceUpdate()}))}openPanel(){var t;let n=this._sidebarService,r=this._selectionManagerService,i=this._commandService,a=this._univerInstanceService,o=this._numfmtService,s=this._localeService,c=(((t=r.getCurrentSelections())==null?void 0:t.map(e=>e.range))||[])[0];if(!c)return!1;let l=a.getCurrentUnitForType(v.UNIVER_SHEET),u=l.getActiveSheet();if(!u)return!1;let d=u.getCellRaw(c.startRow,c.startColumn),f=o.getValue(l.getUnitId(),u.getSheetId(),c.startRow,c.startColumn),p=``;f&&(p=f.pattern);let m=(d==null?void 0:d.t)===e.NUMBER?d.v:12345678,h={onChange:e=>{if(e.type===`change`)this._previewPattern=e.value,this._forceUpdate();else if(e.type===`confirm`){var t;let a=((t=r.getCurrentSelections())==null?void 0:t.map(e=>e.range))||[],o={values:[]},s=w(e.value);a.forEach(t=>{ee.foreach(t,(t,n)=>{o.values.push({row:t,col:n,pattern:e.value,type:s})})}),i.executeCommand(ve.id,o),n.close()}else e.type===`cancel`&&n.close()},value:{defaultPattern:p,defaultValue:m,row:c.startRow,col:c.startColumn}};return this._sidebarDisposable=n.open({header:{title:s.t(`sheet.numfmt.title`)},children:{label:Yt,...h},onClose:()=>{this._forceUpdate(),i.executeCommand(Ot.id)}}),!0}_forceUpdate(e){var t;let n=this._renderManagerService.getRenderById(e==null?this._univerInstanceService.getCurrentUnitForType(v.UNIVER_SHEET).getUnitId():e);n==null||n.with(Ie).reCalculate(),n==null||(t=n.mainComponent)==null||t.makeDirty()}_initCommands(){[K,Ot].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initPanel(){this.disposeWithMe(this._componentManager.register(Yt,Kt))}_initRealTimeRenderingInterceptor(){let t=nt([new F(e=>{this._commandService.onCommandExecuted(t=>{t.id===K.id&&e.next(!0),t.id===Ot.id&&e.next(!1)})}),this._selectionManagerService.selectionMoveEnd$.pipe(st(e=>e?e.map(e=>e.range):[]))]);this.disposeWithMe(ce(t.pipe(ct(([e,t])=>new F(n=>{let r=new a;return e&&t.length&&n.next({selectionRanges:t,disposableCollection:r}),()=>{r.dispose()}})),lt(()=>{this._previewPattern=null})).subscribe(({disposableCollection:t,selectionRanges:n})=>{var r;let i=this._univerInstanceService.getCurrentUnitForType(v.UNIVER_SHEET);this.openPanel(),t.add(this._sheetInterceptorService.intercept(Ve.CELL_CONTENT,{priority:99,effect:f.Value|f.Style,handler:(t,r,i)=>{let{row:a,col:o}=r,s=i(t)||{};if(n.find(e=>e.startColumn<=o&&e.endColumn>=o&&e.startRow<=a&&e.endRow>=a)){let t=r.worksheet.getCellRaw(a,o),n=t==null?void 0:t.v,i=t==null?void 0:t.t;if(n==null||i!==e.NUMBER||this._previewPattern===null)return s;let l=ke(this._previewPattern,n,this._sheetsNumfmtCellContentController.locale);if(l.color){var c;let t=(c=this._themeService.getColorFromTheme(`${l.color}.500`))==null?l.color:c;return{...s,v:l.result,t:e.STRING,s:{cl:{rgb:t}}}}return{...s,v:l.result,t:e.STRING}}return s}})),(r=this._renderManagerService.getRenderById(i.getUnitId()))==null||(r=r.mainComponent)==null||r.makeDirty()})))}_commandExecutedListener(){let e=[O.id,Ue.id];this.disposeWithMe(new F(t=>{let n=this._commandService.onCommandExecuted(n=>{if(e.includes(n.id)){let e=n.params;t.next(e.unitId)}});return()=>n.dispose()}).pipe(ot(16)).subscribe(e=>this._forceUpdate(e)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(v.UNIVER_SHEET).subscribe(e=>{if(!e){var t;(t=this._sidebarDisposable)==null||t.dispose(),this._sidebarDisposable=null}})}};X=W([U(0,u(Ge)),U(1,u(g)),U(2,l),U(3,o),U(4,u(Ke)),U(5,de),U(6,He),U(7,u(Xe)),U(8,$e),U(9,u(p)),U(10,u(be))],X);const Xt=()=>{let e=[];return{add:(t,n,r,i,a)=>e.push({unitId:t,subUnitId:n,row:r,col:i,value:a}),getEffects:()=>e,clean:()=>{e=[]}}};let Z=class extends i{constructor(e,t,n,r,i){super(),this._sheetInterceptorService=e,this._numfmtService=t,this._univerInstanceService=n,this._injector=r,this._editorBridgeService=i,Y(this,`_collectEffectMutation`,Xt()),this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(ce(this._sheetInterceptorService.writeCellInterceptor.intercept(Be,{handler:(t,n,r)=>{let i=n.row,a=n.col,o=this._numfmtService.getValue(n.unitId,n.subUnitId,i,a);if(o)switch(w(o.pattern)){case`scientific`:case`currency`:case`grouped`:case`number`:{let t={...n.worksheet.getCellRaw(i,a)};return(t==null?void 0:t.t)===e.NUMBER&&b(t.v)&&(t.v=H(Number(t.v))),r&&r(t)}case`percent`:{let t={...n.worksheet.getCellRaw(i,a)};return(t==null?void 0:t.t)===e.NUMBER&&b(t.v)&&(t.v=`${H(Number(t.v)*100)}%`),r&&r(t)}default:return r&&r(t)}return r(t)}})))}_initInterceptorEditorEnd(){this.disposeWithMe(ce(this._sheetInterceptorService.writeCellInterceptor.intercept(ze,{handler:(t,n,r)=>{var i,a;if(!(t!=null&&t.v)&&!(t!=null&&t.p))return r(t);this._collectEffectMutation.clean();let o=this._numfmtService.getValue(n.unitId,n.subUnitId,n.row,n.col),s=n.worksheet.getCellRaw(n.row,n.col);if(ie(o==null?void 0:o.pattern)||t.t===e.FORCE_STRING)return r(t);let c=(i=t.p)==null?void 0:i.body,l=!(t==null||(a=t.p)==null||(a=a.body)==null)&&a.dataStream?t.p.body.dataStream.replace(/\r\n$/,``):String(t.v),u=ne(l);if(c)if(Zt(c)){let{dataStream:e}=c,n=e.replace(/\r\n$/,``),i=Number(n);if(Number.isNaN(i)&&!u)return r(t)}else return r(t);if(u){if(!u.z&&!(o!=null&&o.pattern)&&(s==null?void 0:s.t)!==e.STRING&&(s==null?void 0:s.t)!==e.FORCE_STRING&&ue(l))return r({...t,p:void 0,v:l,t:e.FORCE_STRING});u.z&&(!(o!=null&&o.pattern)||w(u.z)!==w(o.pattern))&&this._collectEffectMutation.add(n.unitId,n.subUnitId,n.row,n.col,{pattern:u.z});let i=H(Number(u.v),16);return r({...t,p:void 0,v:i,t:e.NUMBER})}return r(t)}})))}_initInterceptorCommands(){let e=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(t){switch(t.id){case We.id:{var n;let t=e._univerInstanceService.getCurrentUnitForType(v.UNIVER_SHEET),r=t.getUnitId(),i=(n=t.getActiveSheet())==null?void 0:n.getSheetId();if(!i)return{redos:[],undos:[]};let a=e._collectEffectMutation.getEffects();if(e._collectEffectMutation.clean(),!a.length)return{redos:[],undos:[]};let o=a.filter(e=>{var t;return!!((t=e.value)!=null&&t.pattern)}).map(e=>({row:e.row,col:e.col,pattern:e.value.pattern})),s=a.filter(e=>{var t;return!((t=e.value)!=null&&t.pattern)}).map(e=>({startRow:e.row,endColumn:e.col,startColumn:e.col,endRow:e.row})),c=[],l=[];if(o.length){let t={id:Ue.id,params:Ye(r,i,o)};c.push(t),l.push(...Je(e._injector,t.params))}if(s.length){let t={id:O.id,params:{unitId:r,subUnitId:i,ranges:s}};c.push(t),l.push(...qe(e._injector,t.params))}return{redos:c,undos:l.reverse()}}}return{redos:[],undos:[]}}}))}dispose(){super.dispose(),this._collectEffectMutation.clean()}};Z=W([U(0,u(Ge)),U(1,u(He)),U(2,u(l)),U(3,u(d)),U(4,m(Fe))],Z);function Zt(e){let{textRuns:t=[],paragraphs:n=[],customRanges:r,customBlocks:i=[]}=e,a=[`va`];return!(t.some(e=>!!(e.ts&&Object.keys(e.ts).some(e=>a.includes(e))))||n.some(e=>e.bullet)||n.length>=2||r!=null&&r.length||i.length>0)}const Qt=e=>[{label:`sheet.numfmt.general`,pattern:null},{label:`sheet.numfmt.text`,pattern:n},`|`,{label:`sheet.numfmt.number`,pattern:`0`},{label:`sheet.numfmt.percent`,pattern:`0.00%`},{label:`sheet.numfmt.scientific`,pattern:`0.00E+00`},`|`,{label:`sheet.numfmt.accounting`,pattern:`"${e}" #,##0.00_);[Red]("${e}"#,##0.00)`},{label:`sheet.numfmt.financialValue`,pattern:`#,##0.00;[Red]#,##0.00`},{label:`sheet.numfmt.currency`,pattern:`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`},{label:`sheet.numfmt.roundingCurrency`,pattern:`"${e}"#,##0;[Red]"${e}"#,##0`},`|`,{label:`sheet.numfmt.date`,pattern:`yyyy-mm-dd;@`},{label:`sheet.numfmt.time`,pattern:`am/pm h":"mm":"ss`},{label:`sheet.numfmt.dateTime`,pattern:`yyyy-m-d am/pm h:mm`},{label:`sheet.numfmt.timeDuration`,pattern:`h:mm:ss`},`|`,{label:`sheet.numfmt.moreFmt`,pattern:``}],$t=e=>({icon:new F(t=>{let n=e.get(p);return t.next(Te(n.getCurrentLocale()).icon),n.localeChanged$.subscribe(()=>{t.next(Te(n.getCurrentLocale()).icon)})}),id:_e.id,title:`sheet.numfmt.currency`,tooltip:`sheet.numfmt.currency`,type:M.BUTTON,hidden$:N(e,v.UNIVER_SHEET),disabled$:E(e,{workbookTypes:[k],worksheetTypes:[A,j],rangeTypes:[D]})}),en=e=>({icon:`AddDigitsIcon`,id:fe.id,title:`sheet.numfmt.addDecimal`,tooltip:`sheet.numfmt.addDecimal`,type:M.BUTTON,hidden$:N(e,v.UNIVER_SHEET),disabled$:E(e,{workbookTypes:[k],worksheetTypes:[A,j],rangeTypes:[D]})}),tn=e=>({icon:`ReduceDigitsIcon`,id:xe.id,title:`sheet.numfmt.subtractDecimal`,tooltip:`sheet.numfmt.subtractDecimal`,type:M.BUTTON,hidden$:N(e,v.UNIVER_SHEET),disabled$:E(e,{workbookTypes:[k],worksheetTypes:[A,j],rangeTypes:[D]})}),nn=e=>({icon:`PercentIcon`,id:ye.id,title:`sheet.numfmt.percent`,tooltip:`sheet.numfmt.percent`,type:M.BUTTON,hidden$:N(e,v.UNIVER_SHEET),disabled$:E(e,{workbookTypes:[k],worksheetTypes:[A,j],rangeTypes:[D]})}),rn=e=>{let t=e.get(l),n=e.get(o),r=e.get(p),i=e.get(Ke),a=[O.id,Ue.id],s=Re(t,``,({workbook:e,worksheet:t})=>new F(o=>at(i.selectionMoveEnd$,te(n.onCommandExecuted.bind(n)).pipe(it(([e])=>a.includes(e.id)))).subscribe(()=>{let n=i.getCurrentSelections();if(n&&n[0]){var a,s;let i=n[0].range,c=i.startRow,l=i.startColumn,u=(a=e.getStyles().get((s=t.getCell(c,l))==null?void 0:s.s))==null?void 0:a.n,d=u==null?void 0:u.pattern,f=we(r.getCurrentLocale()),p=r.t(`sheet.numfmt.general`);if(re(d)){o.next(p);return}if(d){let e=Qt(f).filter(e=>typeof e==`object`&&e.pattern).find(e=>y(d,e.pattern));p=e&&typeof e==`object`&&e.pattern?r.t(e.label):r.t(`sheet.numfmt.moreFmt`)}o.next(p)}})));return{label:an,id:K.id,tooltip:`sheet.numfmt.title`,type:M.SELECTOR,slot:!0,selections:[{label:{name:on,hoverable:!1,selectable:!1}}],value$:s,hidden$:N(e,v.UNIVER_SHEET),disabled$:E(e,{workbookTypes:[k],worksheetTypes:[j,A],rangeTypes:[D]})}},an=`sheet.numfmt.moreNumfmtType`,on=`sheet.numfmt.moreNumfmtType.options`;function sn(e){let{value:t}=e,n=P(p);return B(`span`,{className:`univer-text-sm`,children:t==null?n.t(`sheet.numfmt.general`):t})}function cn(){let e=P(o),t=P(p),n=P(Ze),r=P(be),i=P(Ke),a=t=>{let r=i.getCurrentLastSelection();if(!r)return;let a=r.range,o=[];ee.foreach(a,(e,n)=>{t?o.push({row:e,col:n,pattern:t,type:w(t)}):o.push({row:e,col:n})}),e.executeCommand(ve.id,{values:o}),n.focus()},s=R(()=>Qt(je.get(t.getCurrentLocale())),[t]),c=t=>{if(t===0)a(null);else if(t===s.length-1)e.executeCommand(K.id),n.focus();else{let e=s[t];e.pattern&&a(e.pattern)}};return B(`div`,{className:`univer-grid univer-gap-1 univer-p-1.5`,children:s.map((e,n)=>e===`|`?B(mt,{},n):V(`div`,{className:`
19
- univer-flex univer-h-7 univer-cursor-default univer-items-center univer-justify-between
20
- univer-gap-6 univer-rounded univer-px-2 univer-text-sm
21
- hover:univer-bg-gray-100
22
- dark:hover:!univer-bg-gray-700
23
- `,onClick:()=>c(n),children:[B(`span`,{children:t.t(e.label)}),B(`span`,{className:`
24
- univer-text-xs univer-text-gray-500
25
- dark:!univer-text-gray-400
26
- `,children:e.pattern?Oe(e.pattern||``,1220,r.locale).result.trim():``})]},n))})}const ln={[tt.LAYOUT]:{[K.id]:{order:9,menuItemFactory:rn},[ye.id]:{order:9.1,menuItemFactory:nn},[_e.id]:{order:9.2,menuItemFactory:$t},[fe.id]:{order:9.3,menuItemFactory:en},[xe.id]:{order:9.4,menuItemFactory:tn}}};let Q=class extends i{constructor(e,t){super(),this._componentManager=e,this._menuManagerService=t,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(ln),[[an,sn],[on,cn]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};Q=W([U(0,u(Xe)),U(1,Qe)],Q);let $=class extends h{constructor(e=Et,t,n,r){super(),this._config=e,this._injector=t,this._configService=n,this._renderManagerService=r;let{menu:i,...a}=ae({},Et,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(`sheets-numfmt-ui.config`,a)}onStarting(){se(this._injector,[[X],[Z],[q],[Q]])}onRendered(){this._registerRenderModules(),le(this._injector,[[X],[Z],[Q]])}_registerRenderModules(){[[Dt]].forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(v.UNIVER_SHEET,e))})}};Y($,`pluginName`,`SHEET_NUMFMT_UI_PLUGIN`),Y($,`packageName`,wt),Y($,`version`,Tt),Y($,`type`,v.UNIVER_SHEET),$=W([r(Le,Se),U(1,u(d)),U(2,s),U(3,de)],$);export{$ as UniverSheetsNumfmtUIPlugin};
1
+ import{CellValueType as e,CommandType as t,DEFAULT_TEXT_FORMAT_EXCEL as n,DependentOn as r,Disposable as i,DisposableCollection as a,ICommandService as o,IConfigService as s,ILocalStorageService as c,IUniverInstanceService as l,Inject as u,Injector as d,InterceptorEffectEnum as f,LocaleService as p,Optional as m,Plugin as h,Range as ee,ThemeService as g,Tools as _,UniverInstanceType as v,fromCallback as te,getNumfmtParseValueFilter as ne,isDefaultFormat as re,isPatternEqualWithoutDecimal as y,isRealNum as b,isTextFormat as ie,merge as ae,numfmt as oe,registerDependencies as se,toDisposable as ce,touchDependencies as le,willLoseNumericPrecision as ue}from"@univerjs/core";import{IRenderManagerService as de}from"@univerjs/engine-render";import{AddDecimalCommand as fe,CURRENCYFORMAT as pe,DATEFMTLISG as me,NUMBERFORMAT as he,SHEETS_NUMFMT_PLUGIN_CONFIG_KEY as ge,SetCurrencyCommand as _e,SetNumfmtCommand as ve,SetPercentCommand as ye,SheetsNumfmtCellContentController as be,SubtractDecimalCommand as xe,UniverSheetsNumfmtPlugin as Se,currencySymbols as Ce,getCurrencyFormatOptions as we,getCurrencySymbolByLocale as Te,getCurrencySymbolIconByLocale as Ee,getCurrencyType as x,getDateFormatOptions as De,getDecimalFromPattern as S,getNumberFormatOptions as Oe,getPatternPreview as ke,getPatternPreviewIgnoreGeneral as Ae,getPatternType as C,isPatternHasDecimal as je,localeCurrencySymbolMap as Me,setPatternDecimal as w}from"@univerjs/sheets-numfmt";import{CellAlertManagerService as Ne,CellAlertType as Pe,HoverManagerService as Fe,IEditorBridgeService as Ie,IRepeatLastActionService as Le,RepeatLastActionPermission as Re,SheetSkeletonManagerService as ze,UniverSheetsUIPlugin as Be,deriveStateFromActiveSheet$ as Ve,getCurrentRangeDisable$ as T}from"@univerjs/sheets-ui";import{AFTER_CELL_EDIT as He,BEFORE_CELL_EDIT as Ue,INTERCEPTOR_POINT as We,INumfmtService as Ge,RangeProtectionPermissionEditPoint as E,RemoveNumfmtMutation as Ke,SetNumfmtMutation as D,SetRangeValuesCommand as qe,SheetInterceptorService as Je,SheetsSelectionsService as Ye,WorkbookEditablePermission as O,WorksheetEditPermission as k,WorksheetSetCellStylePermission as A,factoryRemoveNumfmtUndoMutation as Xe,factorySetNumfmtUndoMutation as Ze,transformCellsToRange as Qe}from"@univerjs/sheets";import{ComponentManager as $e,ILayoutService as et,IMenuManagerService as tt,ISidebarService as nt,IZenZoneService as rt,MenuItemType as j,RibbonStartGroup as it,getMenuHiddenObservable as M,useDependency as N}from"@univerjs/ui";import{Observable as P,combineLatest as at,debounceTime as ot,filter as st,merge as ct}from"rxjs";import{debounceTime as lt,map as ut,switchMap as dt,tap as ft}from"rxjs/operators";import{Button as pt,Input as mt,InputNumber as F,Select as I,SelectList as L,Separator as ht,borderClassName as gt,clsx as _t,scrollbarClassName as vt}from"@univerjs/design";import{createContext as yt,createElement as bt,useCallback as xt,useContext as St,useEffect as R,useMemo as z,useRef as Ct,useState as B}from"react";import{jsx as V,jsxs as H}from"react/jsx-runtime";import{CheckMarkIcon as wt}from"@univerjs/icons";import{stripErrorMargin as Tt}from"@univerjs/engine-formula";var Et=`@univerjs/sheets-numfmt-ui`,Dt=`0.19.0-insiders.20260403-3e0e122`;const Ot={};function U(e,t){return function(n,r){t(n,r,e)}}function W(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}const kt=`SHEET_NUMFMT_ALERT`;let At=class extends i{constructor(e,t,n,r,i,a,o){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=n,this._localeService=r,this._zenZoneService=i,this._numfmtService=a,this._configService=o,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(ot(100)).subscribe(e=>{if(e){let r=e.location,i=this._context.unit,a=i.getActiveSheet();if(!a)return this._hideAlert();let o=r.unitId,s=r.subUnitId,c,l=a.getCell(r.row,r.col);if(l!=null&&l.s){let e=i.getStyles().get(l.s);e!=null&&e.n&&(c=e.n)}if(c||(c=this._numfmtService.getValue(o,s,r.row,r.col)),!c){this._hideAlert();return}if(ie(c.pattern)&&_.isDefine(l==null?void 0:l.v)&&b(l.v)){var t,n;if((t=this._configService.getConfig(ge))!=null&&t.disableTextFormatAlert)return;let e=this._cellAlertManagerService.currentAlert.get(kt),i=e==null||(n=e.alert)==null?void 0:n.location;if(i&&i.row===r.row&&i.col===r.col&&i.subUnitId===r.subUnitId&&i.unitId===r.unitId){this._hideAlert();return}this._cellAlertManagerService.showAlert({type:Pe.ERROR,title:this._localeService.t(`info.error`),message:this._localeService.t(`info.forceStringInfo`),location:r,width:200,height:74,key:kt});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(kt)}};At=W([U(1,u(Fe)),U(2,u(Ne)),U(3,u(p)),U(4,rt),U(5,u(Ge)),U(6,s)],At);let G=class extends i{constructor(e){super(),this._repeatLastActionService=e,this._initCommandRecording()}_initCommandRecording(){this.disposeWithMe(this._repeatLastActionService.registerRepeatableCommand(ve.id,(e,t)=>{if(!t)return;let{values:n}=t,r=n.find(e=>e.pattern);if(!r)return;let{pattern:i,type:a}=r,o=[],s=new Set;for(let t of e){let{startRow:e,startColumn:n,endRow:r,endColumn:c}=t;for(let t=e;t<=r;t++)for(let e=n;e<=c;e++){let n=`${t}-${e}`;s.has(n)||(s.add(n),o.push({row:t,col:e,pattern:i,type:a}))}}return{...t,values:o}},Re.CellStyle))}};G=W([U(0,u(Le))],G);const jt={id:`sheet.operation.close.numfmt.panel`,type:t.OPERATION,handler:()=>!0},K={id:`sheet.operation.open.numfmt.panel`,type:t.OPERATION,handler:e=>(e.get(X).openPanel(),!0)},Mt=yt([]);let q=class{constructor(e){this._localStorageService=e}_getKey(e){return`userHabitController_${e}`}async addHabit(e,t){let n=this._getKey(e);return this._localStorageService.getItem(n).then(e=>{e||this._localStorageService.setItem(n,t)})}markHabit(e,t){let n=this._getKey(e);this._localStorageService.getItem(n).then(e=>{if(e){let r=e.findIndex(e=>e===t);r>-1&&e.splice(r,1),e.unshift(t),this._localStorageService.setItem(n,e)}})}async getHabit(e,t){let n=this._getKey(e),r=await this._localStorageService.getItem(n);if(t&&r){let e=r.map((e,t,n)=>({value:e,priority:n.length-t}));return t.sort((t,n)=>{var r,i;let a=((r=e.find(e=>e.value===t))==null?void 0:r.priority)||-1;return(((i=e.find(e=>e.value===n))==null?void 0:i.priority)||-1)-a})}return r||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};q=W([U(0,u(c))],q);const Nt=`numfmtCurrency`,Pt=e=>{let t=N(q),[n,r]=B(Ce);return R(()=>{t.addHabit(`numfmtCurrency`,[]).then(()=>{t.getHabit(Nt,[...Ce]).then(t=>{r(t),e&&e(t)})})},[]),{userHabitCurrency:n,mark:e=>{t.markHabit(Nt,e)}}},Ft=()=>{let e=Ct([]),[t,n]=B({});return R(()=>{e.current.forEach(e=>{e()}),e.current=[]},[t]),t=>{e.current.push(t),n({})}},It=e=>!!x(e)&&e.startsWith(`_(`),Lt=e=>{let{defaultPattern:t,action:n,onChange:r}=e,[i,a]=B(()=>S(t||``,2)),o=St(Mt),[s,c]=B(()=>x(t)||o[0]),l=z(()=>o.map(e=>({label:e,value:e})),[]),u=N(p).t;return n.current=()=>w(`_("${s}"* #,##0${i>0?`.0`:``}_)`,i),H(`div`,{children:[H(`div`,{className:`univer-mt-4 univer-flex univer-justify-between`,children:[H(`div`,{className:`option`,children:[V(`div`,{className:`univer-text-sm univer-text-gray-400`,children:u(`sheet.numfmt.decimalLength`)}),V(`div`,{className:`univer-mt-2 univer-w-32`,children:V(F,{value:i,step:1,precision:0,max:20,min:0,onChange:e=>{let t=e||0;a(t),r(w(`_("${s}"* #,##0${t>0?`.0`:``}_)`,t))}})})]}),H(`div`,{className:`option`,children:[V(`div`,{className:`univer-text-sm univer-text-gray-400`,children:u(`sheet.numfmt.currencyType`)}),V(`div`,{className:`univer-mt-2 univer-w-36`,children:V(I,{options:l,value:s,onChange:e=>{c(e),r(w(`_("${e}"* #,##0${i>0?`.0`:``}_)`,i))}})})]})]}),V(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:u(`sheet.numfmt.accountingDes`)})]})},Rt=e=>!!x(e)&&!e.startsWith(`_(`),zt=e=>{let t=N(p).t,n=St(Mt),[r,i]=B(()=>x(e.defaultPattern)||n[0]),[a,o]=B(()=>S(e.defaultPattern||``,2)),[s,c]=B(()=>{var t;let n=we(r);return((t=n.find(t=>y(t.value,e.defaultPattern)))==null?void 0:t.value)||n[0].value}),l=z(()=>we(r),[r]),u=z(()=>n.map(e=>({label:e,value:e})),[n]);return e.action.current=()=>w(s,a),H(`div`,{children:[H(`div`,{className:`univer-mt-4 univer-flex univer-justify-between`,children:[H(`div`,{className:`option`,children:[V(`div`,{className:`univer-text-sm univer-text-gray-400`,children:t(`sheet.numfmt.decimalLength`)}),V(`div`,{className:`univer-mt-2 univer-w-32`,children:V(F,{value:a,max:20,min:0,onChange:t=>{o(t||0),e.onChange(w(s,t||0))}})})]}),H(`div`,{className:`option`,children:[V(`div`,{className:`univer-text-sm univer-text-gray-400`,children:t(`sheet.numfmt.currencyType`)}),V(`div`,{className:`univer-mt-2 univer-w-36`,children:V(I,{value:r,options:u,onChange:t=>{if(t===void 0)return;i(t);let n=we(t)[0].value;c(n),e.onChange(w(n,a))}})})]})]}),V(`div`,{className:`label univer-mt-4`,children:t(`sheet.numfmt.negType`)}),V(`div`,{className:`univer-mt-2`,children:V(L,{value:s,options:l,onChange:t=>{t!==void 0&&(c(t),e.onChange(w(t,a)))}})}),V(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:t(`sheet.numfmt.currencyDes`)})]})},Bt=`customFormat`,Vt=`numfmt_custom_pattern`;function Ht(e){let{defaultPattern:t,action:n,onChange:r}=e,i=N(q),a=N(c),o=N(p),[s,l]=B(t);n.current=()=>(i.markHabit(Bt,s),a.getItem(Vt).then((e=[])=>{let t=[...new Set([s,...e||[]])].splice(0,10).filter(e=>!!e);a.setItem(Vt,t)}),s);let[u,d]=B([]);R(()=>{a.getItem(Vt).then(e=>{let t=[...pe.map(e=>e.suffix(`$`)),...me.map(e=>e.suffix),...he.map(e=>e.suffix)];t.push(...e||[]),i.addHabit(Bt,[]).finally(()=>{i.getHabit(Bt,t).then(e=>{d([...new Set(e)])})})})},[]);let f=e=>{l(e),r(e)};return H(`div`,{children:[V(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:o.t(`sheet.numfmt.customFormat`)}),V(mt,{placeholder:o.t(`sheet.numfmt.customFormat`),onBlur:()=>{r(s)},value:s,onChange:l,className:`univer-mt-2 univer-w-full`}),V(`div`,{className:_t(`univer-mt-2 univer-max-h-[400px] univer-overflow-auto univer-rounded-lg univer-p-2`,gt),children:u.map(e=>H(`div`,{onClick:()=>f(e),className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-1.5 univer-py-1.5 univer-text-sm`,children:[V(`div`,{className:`univer-flex univer-w-4 univer-items-center univer-text-primary-600`,children:s===e&&V(wt,{})}),V(`div`,{children:e})]},e))}),V(`div`,{className:`univer-mt-3 univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200`,children:o.t(`sheet.numfmt.customFormatDes`)})]})}const Ut=e=>{let t=oe.getFormatInfo(e);return De().map(e=>e.value).includes(e)||[`date`,`datetime`,`time`].includes(t.type)};function Wt(e){let{onChange:t,defaultPattern:n}=e,r=z(De,[]),i=N(p),[a,o]=B(()=>{if(n){let e=r.find(e=>e.value===n);if(e)return e.value}return r[0].value});return e.action.current=()=>a,H(`div`,{children:[V(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:i.t(`sheet.numfmt.dateType`)}),V(`div`,{className:`univer-mt-2`,children:V(L,{value:a,options:r,onChange:e=>{e!==void 0&&(o(e),t(e))}})}),V(`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 Gt=e=>!e,Kt=e=>{let t=N(p).t;return e.action.current=()=>``,V(`div`,{children:V(`div`,{className:`univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200`,children:t(`sheet.numfmt.generalDes`)})})},qt=e=>Oe().some(t=>y(t.value,e));function Jt(e){let t=N(p),n=z(Oe,[]),[r,i]=B(()=>S(e.defaultPattern||``,0)),[a,o]=B(()=>{let t=n.find(t=>y(t.value,e.defaultPattern||``));return(t==null?void 0:t.value)||n[0].value}),s=z(()=>w(a,Number(r||0)),[a,r]),c=z(()=>!je(a),[a]),l=t=>{i(t||0),e.onChange(w(a,Number(t||0)))},u=t=>{t!==void 0&&(i(S(t,0)),o(t),e.onChange(t))};return e.action.current=()=>s,H(`div`,{children:[V(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:t.t(`sheet.numfmt.decimalLength`)}),V(`div`,{className:`univer-mt-2`,children:V(F,{disabled:c,value:r,max:20,min:0,onChange:l})}),H(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:[` `,t.t(`sheet.numfmt.negType`)]}),V(`div`,{className:`univer-mt-2`,children:V(L,{onChange:u,options:n,value:a})}),V(`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 Yt=e=>{let{defaultValue:t,defaultPattern:n,row:r,col:i}=e.value,a=N(p),o=Ct(()=>``),s=a.t,c=Ft(),l=z(()=>[{label:`sheet.numfmt.general`,component:Kt},{label:`sheet.numfmt.accounting`,component:Lt},{label:`sheet.numfmt.currency`,component:zt},{label:`sheet.numfmt.date`,component:Wt},{label:`sheet.numfmt.thousandthPercentile`,component:Jt},{label:`sheet.numfmt.customFormat`,component:Ht}].map(e=>({...e,label:s(e.label)})),[]),[u,d]=B(_),[f,m]=B(()=>`${r}_${i}`),{mark:h,userHabitCurrency:ee}=Pt(()=>m(`${r}_${i}_userCurrency'`)),g=z(()=>{var e;return(e=l.find(e=>e.label===u))==null?void 0:e.component},[u]);function _(){return[Gt,It,Rt,Ut,qt].reduce((e,t,r)=>e||(t(n)?l[r].label:``),``)||l[0].label}let v=l.map(e=>({label:e.label,value:e.label})),te=t=>{d(t),c(()=>e.onChange({type:`change`,value:o.current()||``}))},ne=xt(t=>{e.onChange({type:`change`,value:t})},[]),re=()=>{let t=o.current()||``,n=x(t);n&&h(n),e.onChange({type:`confirm`,value:t})},y=()=>{e.onChange({type:`cancel`,value:``})},b={onChange:ne,defaultValue:t,defaultPattern:n,action:o};return R(()=>{d(_()),m(`${r}_${i}`)},[r,i]),H(`div`,{className:_t(`univer-flex univer-h-full univer-flex-col univer-justify-between univer-overflow-y-auto univer-pb-5`,vt),children:[H(`div`,{children:[V(`div`,{className:`univer-mt-3.5 univer-text-sm univer-text-gray-400`,children:s(`sheet.numfmt.numfmtType`)}),V(`div`,{className:`univer-mt-2`,children:V(I,{className:`univer-w-full`,value:u,options:v,onChange:te})}),V(`div`,{children:g&&V(Mt.Provider,{value:ee,children:bt(g,{...b,key:f})})})]}),H(`div`,{className:`univer-mb-5 univer-mt-3.5 univer-flex univer-justify-end`,children:[V(pt,{onClick:y,className:`univer-mr-3`,children:s(`sheet.numfmt.cancel`)}),V(pt,{variant:`primary`,onClick:re,children:s(`sheet.numfmt.confirm`)})]})]})};function J(e){"@babel/helpers - typeof";return J=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},J(e)}function Xt(e,t){if(J(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(J(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Zt(e){var t=Xt(e,`string`);return J(t)==`symbol`?t:t+``}function Y(e,t,n){return(t=Zt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const Qt=`SHEET_NUMFMT_PANEL`;let X=class extends i{constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._sheetInterceptorService=e,this._themeService=t,this._univerInstanceService=n,this._commandService=r,this._selectionManagerService=i,this._renderManagerService=a,this._numfmtService=o,this._componentManager=s,this._sidebarService=c,this._localeService=l,this._sheetsNumfmtCellContentController=u,Y(this,`_previewPattern`,``),Y(this,`_sidebarDisposable`,null),this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener(),this._initNumfmtLocalChange()}_initNumfmtLocalChange(){this.disposeWithMe(ct(this._sheetsNumfmtCellContentController.locale$,this._localeService.currentLocale$).subscribe(()=>{this._forceUpdate()}))}openPanel(){var t;let n=this._sidebarService,r=this._selectionManagerService,i=this._commandService,a=this._univerInstanceService,o=this._numfmtService,s=this._localeService,c=(((t=r.getCurrentSelections())==null?void 0:t.map(e=>e.range))||[])[0];if(!c)return!1;let l=a.getCurrentUnitForType(v.UNIVER_SHEET),u=l.getActiveSheet();if(!u)return!1;let d=u.getCellRaw(c.startRow,c.startColumn),f=o.getValue(l.getUnitId(),u.getSheetId(),c.startRow,c.startColumn),p=``;f&&(p=f.pattern);let m=(d==null?void 0:d.t)===e.NUMBER?d.v:12345678,h={onChange:e=>{if(e.type===`change`)this._previewPattern=e.value,this._forceUpdate();else if(e.type===`confirm`){var t;let a=((t=r.getCurrentSelections())==null?void 0:t.map(e=>e.range))||[],o={values:[]},s=C(e.value);a.forEach(t=>{ee.foreach(t,(t,n)=>{o.values.push({row:t,col:n,pattern:e.value,type:s})})}),i.executeCommand(ve.id,o),n.close()}else e.type===`cancel`&&n.close()},value:{defaultPattern:p,defaultValue:m,row:c.startRow,col:c.startColumn}};return this._sidebarDisposable=n.open({header:{title:s.t(`sheet.numfmt.title`)},children:{label:Qt,...h},onClose:()=>{this._forceUpdate(),i.executeCommand(jt.id)}}),!0}_forceUpdate(e){var t;let n=this._renderManagerService.getRenderById(e==null?this._univerInstanceService.getCurrentUnitForType(v.UNIVER_SHEET).getUnitId():e);n==null||n.with(ze).reCalculate(),n==null||(t=n.mainComponent)==null||t.makeDirty()}_initCommands(){[K,jt].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initPanel(){this.disposeWithMe(this._componentManager.register(Qt,Yt))}_initRealTimeRenderingInterceptor(){let t=at([new P(e=>{this._commandService.onCommandExecuted(t=>{t.id===K.id&&e.next(!0),t.id===jt.id&&e.next(!1)})}),this._selectionManagerService.selectionMoveEnd$.pipe(ut(e=>e?e.map(e=>e.range):[]))]);this.disposeWithMe(ce(t.pipe(dt(([e,t])=>new P(n=>{let r=new a;return e&&t.length&&n.next({selectionRanges:t,disposableCollection:r}),()=>{r.dispose()}})),ft(()=>{this._previewPattern=null})).subscribe(({disposableCollection:t,selectionRanges:n})=>{var r;let i=this._univerInstanceService.getCurrentUnitForType(v.UNIVER_SHEET);this.openPanel(),t.add(this._sheetInterceptorService.intercept(We.CELL_CONTENT,{priority:99,effect:f.Value|f.Style,handler:(t,r,i)=>{let{row:a,col:o}=r,s=i(t)||{};if(n.find(e=>e.startColumn<=o&&e.endColumn>=o&&e.startRow<=a&&e.endRow>=a)){let t=r.worksheet.getCellRaw(a,o),n=t==null?void 0:t.v,i=t==null?void 0:t.t;if(n==null||i!==e.NUMBER||this._previewPattern===null)return s;let l=Ae(this._previewPattern,n,this._sheetsNumfmtCellContentController.locale);if(l.color){var c;let t=(c=this._themeService.getColorFromTheme(`${l.color}.500`))==null?l.color:c;return{...s,v:l.result,t:e.STRING,s:{cl:{rgb:t}}}}return{...s,v:l.result,t:e.STRING}}return s}})),(r=this._renderManagerService.getRenderById(i.getUnitId()))==null||(r=r.mainComponent)==null||r.makeDirty()})))}_commandExecutedListener(){let e=[Ke.id,D.id];this.disposeWithMe(new P(t=>{let n=this._commandService.onCommandExecuted(n=>{if(e.includes(n.id)){let e=n.params;t.next(e.unitId)}});return()=>n.dispose()}).pipe(lt(16)).subscribe(e=>this._forceUpdate(e)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(v.UNIVER_SHEET).subscribe(e=>{if(!e){var t;(t=this._sidebarDisposable)==null||t.dispose(),this._sidebarDisposable=null}})}};X=W([U(0,u(Je)),U(1,u(g)),U(2,l),U(3,o),U(4,u(Ye)),U(5,de),U(6,Ge),U(7,u($e)),U(8,nt),U(9,u(p)),U(10,u(be))],X);const $t=()=>{let e=[];return{add:(t,n,r,i,a)=>e.push({unitId:t,subUnitId:n,row:r,col:i,value:a}),getEffects:()=>e,clean:()=>{e=[]}}};let Z=class extends i{constructor(e,t,n,r,i){super(),this._sheetInterceptorService=e,this._numfmtService=t,this._univerInstanceService=n,this._injector=r,this._editorBridgeService=i,Y(this,`_collectEffectMutation`,$t()),this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(ce(this._sheetInterceptorService.writeCellInterceptor.intercept(Ue,{handler:(t,n,r)=>{let i=n.row,a=n.col,o=this._numfmtService.getValue(n.unitId,n.subUnitId,i,a);if(o)switch(C(o.pattern)){case`scientific`:case`currency`:case`grouped`:case`number`:{let t={...n.worksheet.getCellRaw(i,a)};return(t==null?void 0:t.t)===e.NUMBER&&b(t.v)&&(t.v=Tt(Number(t.v))),r&&r(t)}case`percent`:{let t={...n.worksheet.getCellRaw(i,a)};return(t==null?void 0:t.t)===e.NUMBER&&b(t.v)&&(t.v=`${Tt(Number(t.v)*100)}%`),r&&r(t)}default:return r&&r(t)}return r(t)}})))}_initInterceptorEditorEnd(){this.disposeWithMe(ce(this._sheetInterceptorService.writeCellInterceptor.intercept(He,{handler:(t,n,r)=>{var i,a;if(!(t!=null&&t.v)&&!(t!=null&&t.p))return r(t);this._collectEffectMutation.clean();let o=this._numfmtService.getValue(n.unitId,n.subUnitId,n.row,n.col),s=n.worksheet.getCellRaw(n.row,n.col);if(ie(o==null?void 0:o.pattern)||t.t===e.FORCE_STRING)return r(t);let c=(i=t.p)==null?void 0:i.body,l=!(t==null||(a=t.p)==null||(a=a.body)==null)&&a.dataStream?t.p.body.dataStream.replace(/\r\n$/,``):String(t.v),u=ne(l);if(c)if(en(c)){let{dataStream:e}=c,n=e.replace(/\r\n$/,``),i=Number(n);if(Number.isNaN(i)&&!u)return r(t)}else return r(t);if(u){if(!u.z&&!(o!=null&&o.pattern)&&(s==null?void 0:s.t)!==e.STRING&&(s==null?void 0:s.t)!==e.FORCE_STRING&&ue(l))return r({...t,p:void 0,v:l,t:e.FORCE_STRING});u.z&&(!(o!=null&&o.pattern)||C(u.z)!==C(o.pattern))&&this._collectEffectMutation.add(n.unitId,n.subUnitId,n.row,n.col,{pattern:u.z});let i=Tt(Number(u.v),16);return r({...t,p:void 0,v:i,t:e.NUMBER})}return r(t)}})))}_initInterceptorCommands(){let e=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(t){switch(t.id){case qe.id:{var n;let t=e._univerInstanceService.getCurrentUnitForType(v.UNIVER_SHEET),r=t.getUnitId(),i=(n=t.getActiveSheet())==null?void 0:n.getSheetId();if(!i)return{redos:[],undos:[]};let a=e._collectEffectMutation.getEffects();if(e._collectEffectMutation.clean(),!a.length)return{redos:[],undos:[]};let o=a.filter(e=>{var t;return!!((t=e.value)!=null&&t.pattern)}).map(e=>({row:e.row,col:e.col,pattern:e.value.pattern})),s=a.filter(e=>{var t;return!((t=e.value)!=null&&t.pattern)}).map(e=>({startRow:e.row,endColumn:e.col,startColumn:e.col,endRow:e.row})),c=[],l=[];if(o.length){let t={id:D.id,params:Qe(r,i,o)};c.push(t),l.push(...Ze(e._injector,t.params))}if(s.length){let t={id:Ke.id,params:{unitId:r,subUnitId:i,ranges:s}};c.push(t),l.push(...Xe(e._injector,t.params))}return{redos:c,undos:l.reverse()}}}return{redos:[],undos:[]}}}))}dispose(){super.dispose(),this._collectEffectMutation.clean()}};Z=W([U(0,u(Je)),U(1,u(Ge)),U(2,u(l)),U(3,u(d)),U(4,m(Ie))],Z);function en(e){let{textRuns:t=[],paragraphs:n=[],customRanges:r,customBlocks:i=[]}=e,a=[`va`];return!(t.some(e=>!!(e.ts&&Object.keys(e.ts).some(e=>a.includes(e))))||n.some(e=>e.bullet)||n.length>=2||r!=null&&r.length||i.length>0)}const tn=e=>[{label:`sheet.numfmt.general`,pattern:null},{label:`sheet.numfmt.text`,pattern:n},`|`,{label:`sheet.numfmt.number`,pattern:`0`},{label:`sheet.numfmt.percent`,pattern:`0.00%`},{label:`sheet.numfmt.scientific`,pattern:`0.00E+00`},`|`,{label:`sheet.numfmt.accounting`,pattern:`"${e}" #,##0.00_);[Red]("${e}"#,##0.00)`},{label:`sheet.numfmt.financialValue`,pattern:`#,##0.00;[Red]#,##0.00`},{label:`sheet.numfmt.currency`,pattern:`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`},{label:`sheet.numfmt.roundingCurrency`,pattern:`"${e}"#,##0;[Red]"${e}"#,##0`},`|`,{label:`sheet.numfmt.date`,pattern:`yyyy-mm-dd;@`},{label:`sheet.numfmt.time`,pattern:`am/pm h":"mm":"ss`},{label:`sheet.numfmt.dateTime`,pattern:`yyyy-m-d am/pm h:mm`},{label:`sheet.numfmt.timeDuration`,pattern:`h:mm:ss`},`|`,{label:`sheet.numfmt.moreFmt`,pattern:``}],nn=e=>({icon:new P(t=>{let n=e.get(p);return t.next(Ee(n.getCurrentLocale()).icon),n.localeChanged$.subscribe(()=>{t.next(Ee(n.getCurrentLocale()).icon)})}),id:_e.id,title:`sheet.numfmt.currency`,tooltip:`sheet.numfmt.currency`,type:j.BUTTON,hidden$:M(e,v.UNIVER_SHEET),disabled$:T(e,{workbookTypes:[O],worksheetTypes:[k,A],rangeTypes:[E]})}),rn=e=>({icon:`AddDigitsIcon`,id:fe.id,title:`sheet.numfmt.addDecimal`,tooltip:`sheet.numfmt.addDecimal`,type:j.BUTTON,hidden$:M(e,v.UNIVER_SHEET),disabled$:T(e,{workbookTypes:[O],worksheetTypes:[k,A],rangeTypes:[E]})}),an=e=>({icon:`ReduceDigitsIcon`,id:xe.id,title:`sheet.numfmt.subtractDecimal`,tooltip:`sheet.numfmt.subtractDecimal`,type:j.BUTTON,hidden$:M(e,v.UNIVER_SHEET),disabled$:T(e,{workbookTypes:[O],worksheetTypes:[k,A],rangeTypes:[E]})}),on=e=>({icon:`PercentIcon`,id:ye.id,title:`sheet.numfmt.percent`,tooltip:`sheet.numfmt.percent`,type:j.BUTTON,hidden$:M(e,v.UNIVER_SHEET),disabled$:T(e,{workbookTypes:[O],worksheetTypes:[k,A],rangeTypes:[E]})}),sn=e=>{let t=e.get(l),n=e.get(o),r=e.get(p),i=e.get(Ye),a=[Ke.id,D.id],s=Ve(t,``,({workbook:e,worksheet:t})=>new P(o=>ct(i.selectionMoveEnd$,te(n.onCommandExecuted.bind(n)).pipe(st(([e])=>a.includes(e.id)))).subscribe(()=>{let n=i.getCurrentSelections();if(n&&n[0]){var a,s;let i=n[0].range,c=i.startRow,l=i.startColumn,u=(a=e.getStyles().get((s=t.getCell(c,l))==null?void 0:s.s))==null?void 0:a.n,d=u==null?void 0:u.pattern,f=Te(r.getCurrentLocale()),p=r.t(`sheet.numfmt.general`);if(re(d)){o.next(p);return}if(d){let e=tn(f).filter(e=>typeof e==`object`&&e.pattern).find(e=>y(d,e.pattern));p=e&&typeof e==`object`&&e.pattern?r.t(e.label):r.t(`sheet.numfmt.moreFmt`)}o.next(p)}})));return{label:cn,id:K.id,tooltip:`sheet.numfmt.title`,type:j.SELECTOR,slot:!0,selections:[{label:{name:ln,hoverable:!1,selectable:!1}}],value$:s,hidden$:M(e,v.UNIVER_SHEET),disabled$:T(e,{workbookTypes:[O],worksheetTypes:[A,k],rangeTypes:[E]})}},cn=`sheet.numfmt.moreNumfmtType`,ln=`sheet.numfmt.moreNumfmtType.options`;function un(e){let{value:t}=e,n=N(p);return V(`span`,{className:`univer-text-sm`,children:t==null?n.t(`sheet.numfmt.general`):t})}function dn(){let e=N(o),t=N(p),n=N(et),r=N(be),i=N(Ye),a=t=>{let r=i.getCurrentLastSelection();if(!r)return;let a=r.range,o=[];ee.foreach(a,(e,n)=>{t?o.push({row:e,col:n,pattern:t,type:C(t)}):o.push({row:e,col:n})}),e.executeCommand(ve.id,{values:o}),n.focus()},s=z(()=>tn(Me.get(t.getCurrentLocale())),[t]),c=t=>{if(t===0)a(null);else if(t===s.length-1)e.executeCommand(K.id),n.focus();else{let e=s[t];e.pattern&&a(e.pattern)}};return V(`div`,{className:`univer-grid univer-gap-1 univer-p-1.5`,children:s.map((e,n)=>e===`|`?V(ht,{},n):H(`div`,{className:`univer-flex univer-h-7 univer-cursor-default 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(n),children:[V(`span`,{children:t.t(e.label)}),V(`span`,{className:`univer-text-xs univer-text-gray-500 dark:!univer-text-gray-400`,children:e.pattern?ke(e.pattern||``,1220,r.locale).result.trim():``})]},n))})}const fn={[it.LAYOUT]:{[K.id]:{order:9,menuItemFactory:sn},[ye.id]:{order:9.1,menuItemFactory:on},[_e.id]:{order:9.2,menuItemFactory:nn},[fe.id]:{order:9.3,menuItemFactory:rn},[xe.id]:{order:9.4,menuItemFactory:an}}};let Q=class extends i{constructor(e,t){super(),this._componentManager=e,this._menuManagerService=t,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(fn),[[cn,un],[ln,dn]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};Q=W([U(0,u($e)),U(1,tt)],Q);let $=class extends h{constructor(e=Ot,t,n,r){super(),this._config=e,this._injector=t,this._configService=n,this._renderManagerService=r;let{menu:i,...a}=ae({},Ot,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(`sheets-numfmt-ui.config`,a)}onStarting(){se(this._injector,[[X],[Z],[q],[Q],[G]])}onRendered(){this._registerRenderModules(),le(this._injector,[[X],[Z],[Q],[G]])}_registerRenderModules(){[[At]].forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(v.UNIVER_SHEET,e))})}};Y($,`pluginName`,`SHEET_NUMFMT_UI_PLUGIN`),Y($,`packageName`,Et),Y($,`version`,Dt),Y($,`type`,v.UNIVER_SHEET),$=W([r(Be,Se),U(1,u(d)),U(2,s),U(3,de)],$);export{$ as UniverSheetsNumfmtUIPlugin};
package/lib/index.js CHANGED
@@ -1,26 +1 @@
1
- import{CellValueType as e,CommandType as t,DEFAULT_TEXT_FORMAT_EXCEL as n,DependentOn as r,Disposable as i,DisposableCollection as a,ICommandService as o,IConfigService as s,ILocalStorageService as c,IUniverInstanceService as l,Inject as u,Injector as d,InterceptorEffectEnum as f,LocaleService as p,Optional as m,Plugin as h,Range as ee,ThemeService as g,Tools as _,UniverInstanceType as v,fromCallback as te,getNumfmtParseValueFilter as ne,isDefaultFormat as re,isPatternEqualWithoutDecimal as y,isRealNum as b,isTextFormat as ie,merge as ae,numfmt as oe,registerDependencies as se,toDisposable as ce,touchDependencies as le,willLoseNumericPrecision as ue}from"@univerjs/core";import{IRenderManagerService as de}from"@univerjs/engine-render";import{AddDecimalCommand as fe,CURRENCYFORMAT as pe,DATEFMTLISG as me,NUMBERFORMAT as he,SHEETS_NUMFMT_PLUGIN_CONFIG_KEY as ge,SetCurrencyCommand as _e,SetNumfmtCommand as ve,SetPercentCommand as ye,SheetsNumfmtCellContentController as be,SubtractDecimalCommand as xe,UniverSheetsNumfmtPlugin as Se,currencySymbols as Ce,getCurrencyFormatOptions as x,getCurrencySymbolByLocale as we,getCurrencySymbolIconByLocale as Te,getCurrencyType as S,getDateFormatOptions as Ee,getDecimalFromPattern as C,getNumberFormatOptions as De,getPatternPreview as Oe,getPatternPreviewIgnoreGeneral as ke,getPatternType as w,isPatternHasDecimal as Ae,localeCurrencySymbolMap as je,setPatternDecimal as T}from"@univerjs/sheets-numfmt";import{CellAlertManagerService as Me,CellAlertType as Ne,HoverManagerService as Pe,IEditorBridgeService as Fe,SheetSkeletonManagerService as Ie,UniverSheetsUIPlugin as Le,deriveStateFromActiveSheet$ as Re,getCurrentRangeDisable$ as E}from"@univerjs/sheets-ui";import{AFTER_CELL_EDIT as ze,BEFORE_CELL_EDIT as Be,INTERCEPTOR_POINT as Ve,INumfmtService as He,RangeProtectionPermissionEditPoint as D,RemoveNumfmtMutation as O,SetNumfmtMutation as Ue,SetRangeValuesCommand as We,SheetInterceptorService as Ge,SheetsSelectionsService as Ke,WorkbookEditablePermission as k,WorksheetEditPermission as A,WorksheetSetCellStylePermission as j,factoryRemoveNumfmtUndoMutation as qe,factorySetNumfmtUndoMutation as Je,transformCellsToRange as Ye}from"@univerjs/sheets";import{ComponentManager as Xe,ILayoutService as Ze,IMenuManagerService as Qe,ISidebarService as $e,IZenZoneService as et,MenuItemType as M,RibbonStartGroup as tt,getMenuHiddenObservable as N,useDependency as P}from"@univerjs/ui";import{Observable as F,combineLatest as nt,debounceTime as rt,filter as it,merge as at}from"rxjs";import{debounceTime as ot,map as st,switchMap as ct,tap as lt}from"rxjs/operators";import{Button as ut,Input as dt,InputNumber as ft,Select as I,SelectList as pt,Separator as mt,borderClassName as ht,clsx as gt,scrollbarClassName as _t}from"@univerjs/design";import{createContext as vt,createElement as yt,useCallback as bt,useContext as xt,useEffect as L,useMemo as R,useRef as St,useState as z}from"react";import{jsx as B,jsxs as V}from"react/jsx-runtime";import{CheckMarkIcon as Ct}from"@univerjs/icons";import{stripErrorMargin as H}from"@univerjs/engine-formula";var wt=`@univerjs/sheets-numfmt-ui`,Tt=`0.18.0`;const Et={};function U(e,t){return function(n,r){t(n,r,e)}}function W(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}const G=`SHEET_NUMFMT_ALERT`;let Dt=class extends i{constructor(e,t,n,r,i,a,o){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=n,this._localeService=r,this._zenZoneService=i,this._numfmtService=a,this._configService=o,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(rt(100)).subscribe(e=>{if(e){let r=e.location,i=this._context.unit,a=i.getActiveSheet();if(!a)return this._hideAlert();let o=r.unitId,s=r.subUnitId,c,l=a.getCell(r.row,r.col);if(l!=null&&l.s){let e=i.getStyles().get(l.s);e!=null&&e.n&&(c=e.n)}if(c||(c=this._numfmtService.getValue(o,s,r.row,r.col)),!c){this._hideAlert();return}if(ie(c.pattern)&&_.isDefine(l==null?void 0:l.v)&&b(l.v)){var t,n;if((t=this._configService.getConfig(ge))!=null&&t.disableTextFormatAlert)return;let e=this._cellAlertManagerService.currentAlert.get(G),i=e==null||(n=e.alert)==null?void 0:n.location;if(i&&i.row===r.row&&i.col===r.col&&i.subUnitId===r.subUnitId&&i.unitId===r.unitId){this._hideAlert();return}this._cellAlertManagerService.showAlert({type:Ne.ERROR,title:this._localeService.t(`info.error`),message:this._localeService.t(`info.forceStringInfo`),location:r,width:200,height:74,key:G});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(G)}};Dt=W([U(1,u(Pe)),U(2,u(Me)),U(3,u(p)),U(4,et),U(5,u(He)),U(6,s)],Dt);const Ot={id:`sheet.operation.close.numfmt.panel`,type:t.OPERATION,handler:()=>!0},K={id:`sheet.operation.open.numfmt.panel`,type:t.OPERATION,handler:e=>(e.get(X).openPanel(),!0)},kt=vt([]);let q=class{constructor(e){this._localStorageService=e}_getKey(e){return`userHabitController_${e}`}async addHabit(e,t){let n=this._getKey(e);return this._localStorageService.getItem(n).then(e=>{e||this._localStorageService.setItem(n,t)})}markHabit(e,t){let n=this._getKey(e);this._localStorageService.getItem(n).then(e=>{if(e){let r=e.findIndex(e=>e===t);r>-1&&e.splice(r,1),e.unshift(t),this._localStorageService.setItem(n,e)}})}async getHabit(e,t){let n=this._getKey(e),r=await this._localStorageService.getItem(n);if(t&&r){let e=r.map((e,t,n)=>({value:e,priority:n.length-t}));return t.sort((t,n)=>{var r,i;let a=((r=e.find(e=>e.value===t))==null?void 0:r.priority)||-1;return(((i=e.find(e=>e.value===n))==null?void 0:i.priority)||-1)-a})}return r||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};q=W([U(0,u(c))],q);const At=`numfmtCurrency`,jt=e=>{let t=P(q),[n,r]=z(Ce);return L(()=>{t.addHabit(`numfmtCurrency`,[]).then(()=>{t.getHabit(At,[...Ce]).then(t=>{r(t),e&&e(t)})})},[]),{userHabitCurrency:n,mark:e=>{t.markHabit(At,e)}}},Mt=()=>{let e=St([]),[t,n]=z({});return L(()=>{e.current.forEach(e=>{e()}),e.current=[]},[t]),t=>{e.current.push(t),n({})}},Nt=e=>!!S(e)&&e.startsWith(`_(`),Pt=e=>{let{defaultPattern:t,action:n,onChange:r}=e,[i,a]=z(()=>C(t||``,2)),o=xt(kt),[s,c]=z(()=>S(t)||o[0]),l=R(()=>o.map(e=>({label:e,value:e})),[]),u=P(p).t;return n.current=()=>T(`_("${s}"* #,##0${i>0?`.0`:``}_)`,i),V(`div`,{children:[V(`div`,{className:`univer-mt-4 univer-flex univer-justify-between`,children:[V(`div`,{className:`option`,children:[B(`div`,{className:`univer-text-sm univer-text-gray-400`,children:u(`sheet.numfmt.decimalLength`)}),B(`div`,{className:`univer-mt-2 univer-w-32`,children:B(ft,{value:i,step:1,precision:0,max:20,min:0,onChange:e=>{let t=e||0;a(t),r(T(`_("${s}"* #,##0${t>0?`.0`:``}_)`,t))}})})]}),V(`div`,{className:`option`,children:[B(`div`,{className:`univer-text-sm univer-text-gray-400`,children:u(`sheet.numfmt.currencyType`)}),B(`div`,{className:`univer-mt-2 univer-w-36`,children:B(I,{options:l,value:s,onChange:e=>{c(e),r(T(`_("${e}"* #,##0${i>0?`.0`:``}_)`,i))}})})]})]}),B(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:u(`sheet.numfmt.accountingDes`)})]})},Ft=e=>!!S(e)&&!e.startsWith(`_(`),It=e=>{let t=P(p).t,n=xt(kt),[r,i]=z(()=>S(e.defaultPattern)||n[0]),[a,o]=z(()=>C(e.defaultPattern||``,2)),[s,c]=z(()=>{var t;let n=x(r);return((t=n.find(t=>y(t.value,e.defaultPattern)))==null?void 0:t.value)||n[0].value}),l=R(()=>x(r),[r]),u=R(()=>n.map(e=>({label:e,value:e})),[n]);return e.action.current=()=>T(s,a),V(`div`,{children:[V(`div`,{className:`univer-mt-4 univer-flex univer-justify-between`,children:[V(`div`,{className:`option`,children:[B(`div`,{className:`univer-text-sm univer-text-gray-400`,children:t(`sheet.numfmt.decimalLength`)}),B(`div`,{className:`univer-mt-2 univer-w-32`,children:B(ft,{value:a,max:20,min:0,onChange:t=>{o(t||0),e.onChange(T(s,t||0))}})})]}),V(`div`,{className:`option`,children:[B(`div`,{className:`univer-text-sm univer-text-gray-400`,children:t(`sheet.numfmt.currencyType`)}),B(`div`,{className:`univer-mt-2 univer-w-36`,children:B(I,{value:r,options:u,onChange:t=>{if(t===void 0)return;i(t);let n=x(t)[0].value;c(n),e.onChange(T(n,a))}})})]})]}),B(`div`,{className:`label univer-mt-4`,children:t(`sheet.numfmt.negType`)}),B(`div`,{className:`univer-mt-2`,children:B(pt,{value:s,options:l,onChange:t=>{t!==void 0&&(c(t),e.onChange(T(t,a)))}})}),B(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:t(`sheet.numfmt.currencyDes`)})]})},Lt=`customFormat`,Rt=`numfmt_custom_pattern`;function zt(e){let{defaultPattern:t,action:n,onChange:r}=e,i=P(q),a=P(c),o=P(p),[s,l]=z(t);n.current=()=>(i.markHabit(Lt,s),a.getItem(Rt).then((e=[])=>{let t=[...new Set([s,...e||[]])].splice(0,10).filter(e=>!!e);a.setItem(Rt,t)}),s);let[u,d]=z([]);L(()=>{a.getItem(Rt).then(e=>{let t=[...pe.map(e=>e.suffix(`$`)),...me.map(e=>e.suffix),...he.map(e=>e.suffix)];t.push(...e||[]),i.addHabit(Lt,[]).finally(()=>{i.getHabit(Lt,t).then(e=>{d([...new Set(e)])})})})},[]);let f=e=>{l(e),r(e)};return V(`div`,{children:[B(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:o.t(`sheet.numfmt.customFormat`)}),B(dt,{placeholder:o.t(`sheet.numfmt.customFormat`),onBlur:()=>{r(s)},value:s,onChange:l,className:`univer-mt-2 univer-w-full`}),B(`div`,{className:gt(`univer-mt-2 univer-max-h-[400px] univer-overflow-auto univer-rounded-lg univer-p-2`,ht),children:u.map(e=>V(`div`,{onClick:()=>f(e),className:`
2
- univer-flex univer-cursor-pointer univer-items-center univer-gap-1.5 univer-py-1.5
3
- univer-text-sm
4
- `,children:[B(`div`,{className:`univer-flex univer-w-4 univer-items-center univer-text-primary-600`,children:s===e&&B(Ct,{})}),B(`div`,{children:e})]},e))}),B(`div`,{className:`
5
- univer-mt-3 univer-text-sm univer-text-gray-600
6
- dark:!univer-text-gray-200
7
- `,children:o.t(`sheet.numfmt.customFormatDes`)})]})}const Bt=e=>{let t=oe.getFormatInfo(e);return Ee().map(e=>e.value).includes(e)||[`date`,`datetime`,`time`].includes(t.type)};function Vt(e){let{onChange:t,defaultPattern:n}=e,r=R(Ee,[]),i=P(p),[a,o]=z(()=>{if(n){let e=r.find(e=>e.value===n);if(e)return e.value}return r[0].value});return e.action.current=()=>a,V(`div`,{children:[B(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:i.t(`sheet.numfmt.dateType`)}),B(`div`,{className:`univer-mt-2`,children:B(pt,{value:a,options:r,onChange:e=>{e!==void 0&&(o(e),t(e))}})}),B(`div`,{className:`
8
- univer-mt-3.5 univer-text-sm/5 univer-text-gray-600
9
- dark:!univer-text-gray-200
10
- `,children:i.t(`sheet.numfmt.dateDes`)})]})}const Ht=e=>!e,Ut=e=>{let t=P(p).t;return e.action.current=()=>``,B(`div`,{children:B(`div`,{className:`
11
- univer-mt-3.5 univer-text-sm/5 univer-text-gray-600
12
- dark:!univer-text-gray-200
13
- `,children:t(`sheet.numfmt.generalDes`)})})},Wt=e=>De().some(t=>y(t.value,e));function Gt(e){let t=P(p),n=R(De,[]),[r,i]=z(()=>C(e.defaultPattern||``,0)),[a,o]=z(()=>{let t=n.find(t=>y(t.value,e.defaultPattern||``));return(t==null?void 0:t.value)||n[0].value}),s=R(()=>T(a,Number(r||0)),[a,r]),c=R(()=>!Ae(a),[a]),l=t=>{i(t||0),e.onChange(T(a,Number(t||0)))},u=t=>{t!==void 0&&(i(C(t,0)),o(t),e.onChange(t))};return e.action.current=()=>s,V(`div`,{children:[B(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:t.t(`sheet.numfmt.decimalLength`)}),B(`div`,{className:`univer-mt-2`,children:B(ft,{disabled:c,value:r,max:20,min:0,onChange:l})}),V(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:[` `,t.t(`sheet.numfmt.negType`)]}),B(`div`,{className:`univer-mt-2`,children:B(pt,{onChange:u,options:n,value:a})}),B(`div`,{className:`
14
- univer-mt-3.5 univer-text-sm/5 univer-text-gray-600
15
- dark:!univer-text-gray-200
16
- `,children:t.t(`sheet.numfmt.thousandthPercentileDes`)})]})}const Kt=e=>{let{defaultValue:t,defaultPattern:n,row:r,col:i}=e.value,a=P(p),o=St(()=>``),s=a.t,c=Mt(),l=R(()=>[{label:`sheet.numfmt.general`,component:Ut},{label:`sheet.numfmt.accounting`,component:Pt},{label:`sheet.numfmt.currency`,component:It},{label:`sheet.numfmt.date`,component:Vt},{label:`sheet.numfmt.thousandthPercentile`,component:Gt},{label:`sheet.numfmt.customFormat`,component:zt}].map(e=>({...e,label:s(e.label)})),[]),[u,d]=z(_),[f,m]=z(()=>`${r}_${i}`),{mark:h,userHabitCurrency:ee}=jt(()=>m(`${r}_${i}_userCurrency'`)),g=R(()=>{var e;return(e=l.find(e=>e.label===u))==null?void 0:e.component},[u]);function _(){return[Ht,Nt,Ft,Bt,Wt].reduce((e,t,r)=>e||(t(n)?l[r].label:``),``)||l[0].label}let v=l.map(e=>({label:e.label,value:e.label})),te=t=>{d(t),c(()=>e.onChange({type:`change`,value:o.current()||``}))},ne=bt(t=>{e.onChange({type:`change`,value:t})},[]),re=()=>{let t=o.current()||``,n=S(t);n&&h(n),e.onChange({type:`confirm`,value:t})},y=()=>{e.onChange({type:`cancel`,value:``})},b={onChange:ne,defaultValue:t,defaultPattern:n,action:o};return L(()=>{d(_()),m(`${r}_${i}`)},[r,i]),V(`div`,{className:gt(`
17
- univer-flex univer-h-full univer-flex-col univer-justify-between univer-overflow-y-auto univer-pb-5
18
- `,_t),children:[V(`div`,{children:[B(`div`,{className:`univer-mt-3.5 univer-text-sm univer-text-gray-400`,children:s(`sheet.numfmt.numfmtType`)}),B(`div`,{className:`univer-mt-2`,children:B(I,{className:`univer-w-full`,value:u,options:v,onChange:te})}),B(`div`,{children:g&&B(kt.Provider,{value:ee,children:yt(g,{...b,key:f})})})]}),V(`div`,{className:`univer-mb-5 univer-mt-3.5 univer-flex univer-justify-end`,children:[B(ut,{onClick:y,className:`univer-mr-3`,children:s(`sheet.numfmt.cancel`)}),B(ut,{variant:`primary`,onClick:re,children:s(`sheet.numfmt.confirm`)})]})]})};function J(e){"@babel/helpers - typeof";return J=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},J(e)}function qt(e,t){if(J(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(J(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Jt(e){var t=qt(e,`string`);return J(t)==`symbol`?t:t+``}function Y(e,t,n){return(t=Jt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const Yt=`SHEET_NUMFMT_PANEL`;let X=class extends i{constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._sheetInterceptorService=e,this._themeService=t,this._univerInstanceService=n,this._commandService=r,this._selectionManagerService=i,this._renderManagerService=a,this._numfmtService=o,this._componentManager=s,this._sidebarService=c,this._localeService=l,this._sheetsNumfmtCellContentController=u,Y(this,`_previewPattern`,``),Y(this,`_sidebarDisposable`,null),this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener(),this._initNumfmtLocalChange()}_initNumfmtLocalChange(){this.disposeWithMe(at(this._sheetsNumfmtCellContentController.locale$,this._localeService.currentLocale$).subscribe(()=>{this._forceUpdate()}))}openPanel(){var t;let n=this._sidebarService,r=this._selectionManagerService,i=this._commandService,a=this._univerInstanceService,o=this._numfmtService,s=this._localeService,c=(((t=r.getCurrentSelections())==null?void 0:t.map(e=>e.range))||[])[0];if(!c)return!1;let l=a.getCurrentUnitForType(v.UNIVER_SHEET),u=l.getActiveSheet();if(!u)return!1;let d=u.getCellRaw(c.startRow,c.startColumn),f=o.getValue(l.getUnitId(),u.getSheetId(),c.startRow,c.startColumn),p=``;f&&(p=f.pattern);let m=(d==null?void 0:d.t)===e.NUMBER?d.v:12345678,h={onChange:e=>{if(e.type===`change`)this._previewPattern=e.value,this._forceUpdate();else if(e.type===`confirm`){var t;let a=((t=r.getCurrentSelections())==null?void 0:t.map(e=>e.range))||[],o={values:[]},s=w(e.value);a.forEach(t=>{ee.foreach(t,(t,n)=>{o.values.push({row:t,col:n,pattern:e.value,type:s})})}),i.executeCommand(ve.id,o),n.close()}else e.type===`cancel`&&n.close()},value:{defaultPattern:p,defaultValue:m,row:c.startRow,col:c.startColumn}};return this._sidebarDisposable=n.open({header:{title:s.t(`sheet.numfmt.title`)},children:{label:Yt,...h},onClose:()=>{this._forceUpdate(),i.executeCommand(Ot.id)}}),!0}_forceUpdate(e){var t;let n=this._renderManagerService.getRenderById(e==null?this._univerInstanceService.getCurrentUnitForType(v.UNIVER_SHEET).getUnitId():e);n==null||n.with(Ie).reCalculate(),n==null||(t=n.mainComponent)==null||t.makeDirty()}_initCommands(){[K,Ot].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initPanel(){this.disposeWithMe(this._componentManager.register(Yt,Kt))}_initRealTimeRenderingInterceptor(){let t=nt([new F(e=>{this._commandService.onCommandExecuted(t=>{t.id===K.id&&e.next(!0),t.id===Ot.id&&e.next(!1)})}),this._selectionManagerService.selectionMoveEnd$.pipe(st(e=>e?e.map(e=>e.range):[]))]);this.disposeWithMe(ce(t.pipe(ct(([e,t])=>new F(n=>{let r=new a;return e&&t.length&&n.next({selectionRanges:t,disposableCollection:r}),()=>{r.dispose()}})),lt(()=>{this._previewPattern=null})).subscribe(({disposableCollection:t,selectionRanges:n})=>{var r;let i=this._univerInstanceService.getCurrentUnitForType(v.UNIVER_SHEET);this.openPanel(),t.add(this._sheetInterceptorService.intercept(Ve.CELL_CONTENT,{priority:99,effect:f.Value|f.Style,handler:(t,r,i)=>{let{row:a,col:o}=r,s=i(t)||{};if(n.find(e=>e.startColumn<=o&&e.endColumn>=o&&e.startRow<=a&&e.endRow>=a)){let t=r.worksheet.getCellRaw(a,o),n=t==null?void 0:t.v,i=t==null?void 0:t.t;if(n==null||i!==e.NUMBER||this._previewPattern===null)return s;let l=ke(this._previewPattern,n,this._sheetsNumfmtCellContentController.locale);if(l.color){var c;let t=(c=this._themeService.getColorFromTheme(`${l.color}.500`))==null?l.color:c;return{...s,v:l.result,t:e.STRING,s:{cl:{rgb:t}}}}return{...s,v:l.result,t:e.STRING}}return s}})),(r=this._renderManagerService.getRenderById(i.getUnitId()))==null||(r=r.mainComponent)==null||r.makeDirty()})))}_commandExecutedListener(){let e=[O.id,Ue.id];this.disposeWithMe(new F(t=>{let n=this._commandService.onCommandExecuted(n=>{if(e.includes(n.id)){let e=n.params;t.next(e.unitId)}});return()=>n.dispose()}).pipe(ot(16)).subscribe(e=>this._forceUpdate(e)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(v.UNIVER_SHEET).subscribe(e=>{if(!e){var t;(t=this._sidebarDisposable)==null||t.dispose(),this._sidebarDisposable=null}})}};X=W([U(0,u(Ge)),U(1,u(g)),U(2,l),U(3,o),U(4,u(Ke)),U(5,de),U(6,He),U(7,u(Xe)),U(8,$e),U(9,u(p)),U(10,u(be))],X);const Xt=()=>{let e=[];return{add:(t,n,r,i,a)=>e.push({unitId:t,subUnitId:n,row:r,col:i,value:a}),getEffects:()=>e,clean:()=>{e=[]}}};let Z=class extends i{constructor(e,t,n,r,i){super(),this._sheetInterceptorService=e,this._numfmtService=t,this._univerInstanceService=n,this._injector=r,this._editorBridgeService=i,Y(this,`_collectEffectMutation`,Xt()),this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(ce(this._sheetInterceptorService.writeCellInterceptor.intercept(Be,{handler:(t,n,r)=>{let i=n.row,a=n.col,o=this._numfmtService.getValue(n.unitId,n.subUnitId,i,a);if(o)switch(w(o.pattern)){case`scientific`:case`currency`:case`grouped`:case`number`:{let t={...n.worksheet.getCellRaw(i,a)};return(t==null?void 0:t.t)===e.NUMBER&&b(t.v)&&(t.v=H(Number(t.v))),r&&r(t)}case`percent`:{let t={...n.worksheet.getCellRaw(i,a)};return(t==null?void 0:t.t)===e.NUMBER&&b(t.v)&&(t.v=`${H(Number(t.v)*100)}%`),r&&r(t)}default:return r&&r(t)}return r(t)}})))}_initInterceptorEditorEnd(){this.disposeWithMe(ce(this._sheetInterceptorService.writeCellInterceptor.intercept(ze,{handler:(t,n,r)=>{var i,a;if(!(t!=null&&t.v)&&!(t!=null&&t.p))return r(t);this._collectEffectMutation.clean();let o=this._numfmtService.getValue(n.unitId,n.subUnitId,n.row,n.col),s=n.worksheet.getCellRaw(n.row,n.col);if(ie(o==null?void 0:o.pattern)||t.t===e.FORCE_STRING)return r(t);let c=(i=t.p)==null?void 0:i.body,l=!(t==null||(a=t.p)==null||(a=a.body)==null)&&a.dataStream?t.p.body.dataStream.replace(/\r\n$/,``):String(t.v),u=ne(l);if(c)if(Zt(c)){let{dataStream:e}=c,n=e.replace(/\r\n$/,``),i=Number(n);if(Number.isNaN(i)&&!u)return r(t)}else return r(t);if(u){if(!u.z&&!(o!=null&&o.pattern)&&(s==null?void 0:s.t)!==e.STRING&&(s==null?void 0:s.t)!==e.FORCE_STRING&&ue(l))return r({...t,p:void 0,v:l,t:e.FORCE_STRING});u.z&&(!(o!=null&&o.pattern)||w(u.z)!==w(o.pattern))&&this._collectEffectMutation.add(n.unitId,n.subUnitId,n.row,n.col,{pattern:u.z});let i=H(Number(u.v),16);return r({...t,p:void 0,v:i,t:e.NUMBER})}return r(t)}})))}_initInterceptorCommands(){let e=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(t){switch(t.id){case We.id:{var n;let t=e._univerInstanceService.getCurrentUnitForType(v.UNIVER_SHEET),r=t.getUnitId(),i=(n=t.getActiveSheet())==null?void 0:n.getSheetId();if(!i)return{redos:[],undos:[]};let a=e._collectEffectMutation.getEffects();if(e._collectEffectMutation.clean(),!a.length)return{redos:[],undos:[]};let o=a.filter(e=>{var t;return!!((t=e.value)!=null&&t.pattern)}).map(e=>({row:e.row,col:e.col,pattern:e.value.pattern})),s=a.filter(e=>{var t;return!((t=e.value)!=null&&t.pattern)}).map(e=>({startRow:e.row,endColumn:e.col,startColumn:e.col,endRow:e.row})),c=[],l=[];if(o.length){let t={id:Ue.id,params:Ye(r,i,o)};c.push(t),l.push(...Je(e._injector,t.params))}if(s.length){let t={id:O.id,params:{unitId:r,subUnitId:i,ranges:s}};c.push(t),l.push(...qe(e._injector,t.params))}return{redos:c,undos:l.reverse()}}}return{redos:[],undos:[]}}}))}dispose(){super.dispose(),this._collectEffectMutation.clean()}};Z=W([U(0,u(Ge)),U(1,u(He)),U(2,u(l)),U(3,u(d)),U(4,m(Fe))],Z);function Zt(e){let{textRuns:t=[],paragraphs:n=[],customRanges:r,customBlocks:i=[]}=e,a=[`va`];return!(t.some(e=>!!(e.ts&&Object.keys(e.ts).some(e=>a.includes(e))))||n.some(e=>e.bullet)||n.length>=2||r!=null&&r.length||i.length>0)}const Qt=e=>[{label:`sheet.numfmt.general`,pattern:null},{label:`sheet.numfmt.text`,pattern:n},`|`,{label:`sheet.numfmt.number`,pattern:`0`},{label:`sheet.numfmt.percent`,pattern:`0.00%`},{label:`sheet.numfmt.scientific`,pattern:`0.00E+00`},`|`,{label:`sheet.numfmt.accounting`,pattern:`"${e}" #,##0.00_);[Red]("${e}"#,##0.00)`},{label:`sheet.numfmt.financialValue`,pattern:`#,##0.00;[Red]#,##0.00`},{label:`sheet.numfmt.currency`,pattern:`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`},{label:`sheet.numfmt.roundingCurrency`,pattern:`"${e}"#,##0;[Red]"${e}"#,##0`},`|`,{label:`sheet.numfmt.date`,pattern:`yyyy-mm-dd;@`},{label:`sheet.numfmt.time`,pattern:`am/pm h":"mm":"ss`},{label:`sheet.numfmt.dateTime`,pattern:`yyyy-m-d am/pm h:mm`},{label:`sheet.numfmt.timeDuration`,pattern:`h:mm:ss`},`|`,{label:`sheet.numfmt.moreFmt`,pattern:``}],$t=e=>({icon:new F(t=>{let n=e.get(p);return t.next(Te(n.getCurrentLocale()).icon),n.localeChanged$.subscribe(()=>{t.next(Te(n.getCurrentLocale()).icon)})}),id:_e.id,title:`sheet.numfmt.currency`,tooltip:`sheet.numfmt.currency`,type:M.BUTTON,hidden$:N(e,v.UNIVER_SHEET),disabled$:E(e,{workbookTypes:[k],worksheetTypes:[A,j],rangeTypes:[D]})}),en=e=>({icon:`AddDigitsIcon`,id:fe.id,title:`sheet.numfmt.addDecimal`,tooltip:`sheet.numfmt.addDecimal`,type:M.BUTTON,hidden$:N(e,v.UNIVER_SHEET),disabled$:E(e,{workbookTypes:[k],worksheetTypes:[A,j],rangeTypes:[D]})}),tn=e=>({icon:`ReduceDigitsIcon`,id:xe.id,title:`sheet.numfmt.subtractDecimal`,tooltip:`sheet.numfmt.subtractDecimal`,type:M.BUTTON,hidden$:N(e,v.UNIVER_SHEET),disabled$:E(e,{workbookTypes:[k],worksheetTypes:[A,j],rangeTypes:[D]})}),nn=e=>({icon:`PercentIcon`,id:ye.id,title:`sheet.numfmt.percent`,tooltip:`sheet.numfmt.percent`,type:M.BUTTON,hidden$:N(e,v.UNIVER_SHEET),disabled$:E(e,{workbookTypes:[k],worksheetTypes:[A,j],rangeTypes:[D]})}),rn=e=>{let t=e.get(l),n=e.get(o),r=e.get(p),i=e.get(Ke),a=[O.id,Ue.id],s=Re(t,``,({workbook:e,worksheet:t})=>new F(o=>at(i.selectionMoveEnd$,te(n.onCommandExecuted.bind(n)).pipe(it(([e])=>a.includes(e.id)))).subscribe(()=>{let n=i.getCurrentSelections();if(n&&n[0]){var a,s;let i=n[0].range,c=i.startRow,l=i.startColumn,u=(a=e.getStyles().get((s=t.getCell(c,l))==null?void 0:s.s))==null?void 0:a.n,d=u==null?void 0:u.pattern,f=we(r.getCurrentLocale()),p=r.t(`sheet.numfmt.general`);if(re(d)){o.next(p);return}if(d){let e=Qt(f).filter(e=>typeof e==`object`&&e.pattern).find(e=>y(d,e.pattern));p=e&&typeof e==`object`&&e.pattern?r.t(e.label):r.t(`sheet.numfmt.moreFmt`)}o.next(p)}})));return{label:an,id:K.id,tooltip:`sheet.numfmt.title`,type:M.SELECTOR,slot:!0,selections:[{label:{name:on,hoverable:!1,selectable:!1}}],value$:s,hidden$:N(e,v.UNIVER_SHEET),disabled$:E(e,{workbookTypes:[k],worksheetTypes:[j,A],rangeTypes:[D]})}},an=`sheet.numfmt.moreNumfmtType`,on=`sheet.numfmt.moreNumfmtType.options`;function sn(e){let{value:t}=e,n=P(p);return B(`span`,{className:`univer-text-sm`,children:t==null?n.t(`sheet.numfmt.general`):t})}function cn(){let e=P(o),t=P(p),n=P(Ze),r=P(be),i=P(Ke),a=t=>{let r=i.getCurrentLastSelection();if(!r)return;let a=r.range,o=[];ee.foreach(a,(e,n)=>{t?o.push({row:e,col:n,pattern:t,type:w(t)}):o.push({row:e,col:n})}),e.executeCommand(ve.id,{values:o}),n.focus()},s=R(()=>Qt(je.get(t.getCurrentLocale())),[t]),c=t=>{if(t===0)a(null);else if(t===s.length-1)e.executeCommand(K.id),n.focus();else{let e=s[t];e.pattern&&a(e.pattern)}};return B(`div`,{className:`univer-grid univer-gap-1 univer-p-1.5`,children:s.map((e,n)=>e===`|`?B(mt,{},n):V(`div`,{className:`
19
- univer-flex univer-h-7 univer-cursor-default univer-items-center univer-justify-between
20
- univer-gap-6 univer-rounded univer-px-2 univer-text-sm
21
- hover:univer-bg-gray-100
22
- dark:hover:!univer-bg-gray-700
23
- `,onClick:()=>c(n),children:[B(`span`,{children:t.t(e.label)}),B(`span`,{className:`
24
- univer-text-xs univer-text-gray-500
25
- dark:!univer-text-gray-400
26
- `,children:e.pattern?Oe(e.pattern||``,1220,r.locale).result.trim():``})]},n))})}const ln={[tt.LAYOUT]:{[K.id]:{order:9,menuItemFactory:rn},[ye.id]:{order:9.1,menuItemFactory:nn},[_e.id]:{order:9.2,menuItemFactory:$t},[fe.id]:{order:9.3,menuItemFactory:en},[xe.id]:{order:9.4,menuItemFactory:tn}}};let Q=class extends i{constructor(e,t){super(),this._componentManager=e,this._menuManagerService=t,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(ln),[[an,sn],[on,cn]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};Q=W([U(0,u(Xe)),U(1,Qe)],Q);let $=class extends h{constructor(e=Et,t,n,r){super(),this._config=e,this._injector=t,this._configService=n,this._renderManagerService=r;let{menu:i,...a}=ae({},Et,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(`sheets-numfmt-ui.config`,a)}onStarting(){se(this._injector,[[X],[Z],[q],[Q]])}onRendered(){this._registerRenderModules(),le(this._injector,[[X],[Z],[Q]])}_registerRenderModules(){[[Dt]].forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(v.UNIVER_SHEET,e))})}};Y($,`pluginName`,`SHEET_NUMFMT_UI_PLUGIN`),Y($,`packageName`,wt),Y($,`version`,Tt),Y($,`type`,v.UNIVER_SHEET),$=W([r(Le,Se),U(1,u(d)),U(2,s),U(3,de)],$);export{$ as UniverSheetsNumfmtUIPlugin};
1
+ import{CellValueType as e,CommandType as t,DEFAULT_TEXT_FORMAT_EXCEL as n,DependentOn as r,Disposable as i,DisposableCollection as a,ICommandService as o,IConfigService as s,ILocalStorageService as c,IUniverInstanceService as l,Inject as u,Injector as d,InterceptorEffectEnum as f,LocaleService as p,Optional as m,Plugin as h,Range as ee,ThemeService as g,Tools as _,UniverInstanceType as v,fromCallback as te,getNumfmtParseValueFilter as ne,isDefaultFormat as re,isPatternEqualWithoutDecimal as y,isRealNum as b,isTextFormat as ie,merge as ae,numfmt as oe,registerDependencies as se,toDisposable as ce,touchDependencies as le,willLoseNumericPrecision as ue}from"@univerjs/core";import{IRenderManagerService as de}from"@univerjs/engine-render";import{AddDecimalCommand as fe,CURRENCYFORMAT as pe,DATEFMTLISG as me,NUMBERFORMAT as he,SHEETS_NUMFMT_PLUGIN_CONFIG_KEY as ge,SetCurrencyCommand as _e,SetNumfmtCommand as ve,SetPercentCommand as ye,SheetsNumfmtCellContentController as be,SubtractDecimalCommand as xe,UniverSheetsNumfmtPlugin as Se,currencySymbols as Ce,getCurrencyFormatOptions as we,getCurrencySymbolByLocale as Te,getCurrencySymbolIconByLocale as Ee,getCurrencyType as x,getDateFormatOptions as De,getDecimalFromPattern as S,getNumberFormatOptions as Oe,getPatternPreview as ke,getPatternPreviewIgnoreGeneral as Ae,getPatternType as C,isPatternHasDecimal as je,localeCurrencySymbolMap as Me,setPatternDecimal as w}from"@univerjs/sheets-numfmt";import{CellAlertManagerService as Ne,CellAlertType as Pe,HoverManagerService as Fe,IEditorBridgeService as Ie,IRepeatLastActionService as Le,RepeatLastActionPermission as Re,SheetSkeletonManagerService as ze,UniverSheetsUIPlugin as Be,deriveStateFromActiveSheet$ as Ve,getCurrentRangeDisable$ as T}from"@univerjs/sheets-ui";import{AFTER_CELL_EDIT as He,BEFORE_CELL_EDIT as Ue,INTERCEPTOR_POINT as We,INumfmtService as Ge,RangeProtectionPermissionEditPoint as E,RemoveNumfmtMutation as Ke,SetNumfmtMutation as D,SetRangeValuesCommand as qe,SheetInterceptorService as Je,SheetsSelectionsService as Ye,WorkbookEditablePermission as O,WorksheetEditPermission as k,WorksheetSetCellStylePermission as A,factoryRemoveNumfmtUndoMutation as Xe,factorySetNumfmtUndoMutation as Ze,transformCellsToRange as Qe}from"@univerjs/sheets";import{ComponentManager as $e,ILayoutService as et,IMenuManagerService as tt,ISidebarService as nt,IZenZoneService as rt,MenuItemType as j,RibbonStartGroup as it,getMenuHiddenObservable as M,useDependency as N}from"@univerjs/ui";import{Observable as P,combineLatest as at,debounceTime as ot,filter as st,merge as ct}from"rxjs";import{debounceTime as lt,map as ut,switchMap as dt,tap as ft}from"rxjs/operators";import{Button as pt,Input as mt,InputNumber as F,Select as I,SelectList as L,Separator as ht,borderClassName as gt,clsx as _t,scrollbarClassName as vt}from"@univerjs/design";import{createContext as yt,createElement as bt,useCallback as xt,useContext as St,useEffect as R,useMemo as z,useRef as Ct,useState as B}from"react";import{jsx as V,jsxs as H}from"react/jsx-runtime";import{CheckMarkIcon as wt}from"@univerjs/icons";import{stripErrorMargin as Tt}from"@univerjs/engine-formula";var Et=`@univerjs/sheets-numfmt-ui`,Dt=`0.19.0-insiders.20260403-3e0e122`;const Ot={};function U(e,t){return function(n,r){t(n,r,e)}}function W(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}const kt=`SHEET_NUMFMT_ALERT`;let At=class extends i{constructor(e,t,n,r,i,a,o){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=n,this._localeService=r,this._zenZoneService=i,this._numfmtService=a,this._configService=o,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(ot(100)).subscribe(e=>{if(e){let r=e.location,i=this._context.unit,a=i.getActiveSheet();if(!a)return this._hideAlert();let o=r.unitId,s=r.subUnitId,c,l=a.getCell(r.row,r.col);if(l!=null&&l.s){let e=i.getStyles().get(l.s);e!=null&&e.n&&(c=e.n)}if(c||(c=this._numfmtService.getValue(o,s,r.row,r.col)),!c){this._hideAlert();return}if(ie(c.pattern)&&_.isDefine(l==null?void 0:l.v)&&b(l.v)){var t,n;if((t=this._configService.getConfig(ge))!=null&&t.disableTextFormatAlert)return;let e=this._cellAlertManagerService.currentAlert.get(kt),i=e==null||(n=e.alert)==null?void 0:n.location;if(i&&i.row===r.row&&i.col===r.col&&i.subUnitId===r.subUnitId&&i.unitId===r.unitId){this._hideAlert();return}this._cellAlertManagerService.showAlert({type:Pe.ERROR,title:this._localeService.t(`info.error`),message:this._localeService.t(`info.forceStringInfo`),location:r,width:200,height:74,key:kt});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(kt)}};At=W([U(1,u(Fe)),U(2,u(Ne)),U(3,u(p)),U(4,rt),U(5,u(Ge)),U(6,s)],At);let G=class extends i{constructor(e){super(),this._repeatLastActionService=e,this._initCommandRecording()}_initCommandRecording(){this.disposeWithMe(this._repeatLastActionService.registerRepeatableCommand(ve.id,(e,t)=>{if(!t)return;let{values:n}=t,r=n.find(e=>e.pattern);if(!r)return;let{pattern:i,type:a}=r,o=[],s=new Set;for(let t of e){let{startRow:e,startColumn:n,endRow:r,endColumn:c}=t;for(let t=e;t<=r;t++)for(let e=n;e<=c;e++){let n=`${t}-${e}`;s.has(n)||(s.add(n),o.push({row:t,col:e,pattern:i,type:a}))}}return{...t,values:o}},Re.CellStyle))}};G=W([U(0,u(Le))],G);const jt={id:`sheet.operation.close.numfmt.panel`,type:t.OPERATION,handler:()=>!0},K={id:`sheet.operation.open.numfmt.panel`,type:t.OPERATION,handler:e=>(e.get(X).openPanel(),!0)},Mt=yt([]);let q=class{constructor(e){this._localStorageService=e}_getKey(e){return`userHabitController_${e}`}async addHabit(e,t){let n=this._getKey(e);return this._localStorageService.getItem(n).then(e=>{e||this._localStorageService.setItem(n,t)})}markHabit(e,t){let n=this._getKey(e);this._localStorageService.getItem(n).then(e=>{if(e){let r=e.findIndex(e=>e===t);r>-1&&e.splice(r,1),e.unshift(t),this._localStorageService.setItem(n,e)}})}async getHabit(e,t){let n=this._getKey(e),r=await this._localStorageService.getItem(n);if(t&&r){let e=r.map((e,t,n)=>({value:e,priority:n.length-t}));return t.sort((t,n)=>{var r,i;let a=((r=e.find(e=>e.value===t))==null?void 0:r.priority)||-1;return(((i=e.find(e=>e.value===n))==null?void 0:i.priority)||-1)-a})}return r||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};q=W([U(0,u(c))],q);const Nt=`numfmtCurrency`,Pt=e=>{let t=N(q),[n,r]=B(Ce);return R(()=>{t.addHabit(`numfmtCurrency`,[]).then(()=>{t.getHabit(Nt,[...Ce]).then(t=>{r(t),e&&e(t)})})},[]),{userHabitCurrency:n,mark:e=>{t.markHabit(Nt,e)}}},Ft=()=>{let e=Ct([]),[t,n]=B({});return R(()=>{e.current.forEach(e=>{e()}),e.current=[]},[t]),t=>{e.current.push(t),n({})}},It=e=>!!x(e)&&e.startsWith(`_(`),Lt=e=>{let{defaultPattern:t,action:n,onChange:r}=e,[i,a]=B(()=>S(t||``,2)),o=St(Mt),[s,c]=B(()=>x(t)||o[0]),l=z(()=>o.map(e=>({label:e,value:e})),[]),u=N(p).t;return n.current=()=>w(`_("${s}"* #,##0${i>0?`.0`:``}_)`,i),H(`div`,{children:[H(`div`,{className:`univer-mt-4 univer-flex univer-justify-between`,children:[H(`div`,{className:`option`,children:[V(`div`,{className:`univer-text-sm univer-text-gray-400`,children:u(`sheet.numfmt.decimalLength`)}),V(`div`,{className:`univer-mt-2 univer-w-32`,children:V(F,{value:i,step:1,precision:0,max:20,min:0,onChange:e=>{let t=e||0;a(t),r(w(`_("${s}"* #,##0${t>0?`.0`:``}_)`,t))}})})]}),H(`div`,{className:`option`,children:[V(`div`,{className:`univer-text-sm univer-text-gray-400`,children:u(`sheet.numfmt.currencyType`)}),V(`div`,{className:`univer-mt-2 univer-w-36`,children:V(I,{options:l,value:s,onChange:e=>{c(e),r(w(`_("${e}"* #,##0${i>0?`.0`:``}_)`,i))}})})]})]}),V(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:u(`sheet.numfmt.accountingDes`)})]})},Rt=e=>!!x(e)&&!e.startsWith(`_(`),zt=e=>{let t=N(p).t,n=St(Mt),[r,i]=B(()=>x(e.defaultPattern)||n[0]),[a,o]=B(()=>S(e.defaultPattern||``,2)),[s,c]=B(()=>{var t;let n=we(r);return((t=n.find(t=>y(t.value,e.defaultPattern)))==null?void 0:t.value)||n[0].value}),l=z(()=>we(r),[r]),u=z(()=>n.map(e=>({label:e,value:e})),[n]);return e.action.current=()=>w(s,a),H(`div`,{children:[H(`div`,{className:`univer-mt-4 univer-flex univer-justify-between`,children:[H(`div`,{className:`option`,children:[V(`div`,{className:`univer-text-sm univer-text-gray-400`,children:t(`sheet.numfmt.decimalLength`)}),V(`div`,{className:`univer-mt-2 univer-w-32`,children:V(F,{value:a,max:20,min:0,onChange:t=>{o(t||0),e.onChange(w(s,t||0))}})})]}),H(`div`,{className:`option`,children:[V(`div`,{className:`univer-text-sm univer-text-gray-400`,children:t(`sheet.numfmt.currencyType`)}),V(`div`,{className:`univer-mt-2 univer-w-36`,children:V(I,{value:r,options:u,onChange:t=>{if(t===void 0)return;i(t);let n=we(t)[0].value;c(n),e.onChange(w(n,a))}})})]})]}),V(`div`,{className:`label univer-mt-4`,children:t(`sheet.numfmt.negType`)}),V(`div`,{className:`univer-mt-2`,children:V(L,{value:s,options:l,onChange:t=>{t!==void 0&&(c(t),e.onChange(w(t,a)))}})}),V(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:t(`sheet.numfmt.currencyDes`)})]})},Bt=`customFormat`,Vt=`numfmt_custom_pattern`;function Ht(e){let{defaultPattern:t,action:n,onChange:r}=e,i=N(q),a=N(c),o=N(p),[s,l]=B(t);n.current=()=>(i.markHabit(Bt,s),a.getItem(Vt).then((e=[])=>{let t=[...new Set([s,...e||[]])].splice(0,10).filter(e=>!!e);a.setItem(Vt,t)}),s);let[u,d]=B([]);R(()=>{a.getItem(Vt).then(e=>{let t=[...pe.map(e=>e.suffix(`$`)),...me.map(e=>e.suffix),...he.map(e=>e.suffix)];t.push(...e||[]),i.addHabit(Bt,[]).finally(()=>{i.getHabit(Bt,t).then(e=>{d([...new Set(e)])})})})},[]);let f=e=>{l(e),r(e)};return H(`div`,{children:[V(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:o.t(`sheet.numfmt.customFormat`)}),V(mt,{placeholder:o.t(`sheet.numfmt.customFormat`),onBlur:()=>{r(s)},value:s,onChange:l,className:`univer-mt-2 univer-w-full`}),V(`div`,{className:_t(`univer-mt-2 univer-max-h-[400px] univer-overflow-auto univer-rounded-lg univer-p-2`,gt),children:u.map(e=>H(`div`,{onClick:()=>f(e),className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-1.5 univer-py-1.5 univer-text-sm`,children:[V(`div`,{className:`univer-flex univer-w-4 univer-items-center univer-text-primary-600`,children:s===e&&V(wt,{})}),V(`div`,{children:e})]},e))}),V(`div`,{className:`univer-mt-3 univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200`,children:o.t(`sheet.numfmt.customFormatDes`)})]})}const Ut=e=>{let t=oe.getFormatInfo(e);return De().map(e=>e.value).includes(e)||[`date`,`datetime`,`time`].includes(t.type)};function Wt(e){let{onChange:t,defaultPattern:n}=e,r=z(De,[]),i=N(p),[a,o]=B(()=>{if(n){let e=r.find(e=>e.value===n);if(e)return e.value}return r[0].value});return e.action.current=()=>a,H(`div`,{children:[V(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:i.t(`sheet.numfmt.dateType`)}),V(`div`,{className:`univer-mt-2`,children:V(L,{value:a,options:r,onChange:e=>{e!==void 0&&(o(e),t(e))}})}),V(`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 Gt=e=>!e,Kt=e=>{let t=N(p).t;return e.action.current=()=>``,V(`div`,{children:V(`div`,{className:`univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200`,children:t(`sheet.numfmt.generalDes`)})})},qt=e=>Oe().some(t=>y(t.value,e));function Jt(e){let t=N(p),n=z(Oe,[]),[r,i]=B(()=>S(e.defaultPattern||``,0)),[a,o]=B(()=>{let t=n.find(t=>y(t.value,e.defaultPattern||``));return(t==null?void 0:t.value)||n[0].value}),s=z(()=>w(a,Number(r||0)),[a,r]),c=z(()=>!je(a),[a]),l=t=>{i(t||0),e.onChange(w(a,Number(t||0)))},u=t=>{t!==void 0&&(i(S(t,0)),o(t),e.onChange(t))};return e.action.current=()=>s,H(`div`,{children:[V(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:t.t(`sheet.numfmt.decimalLength`)}),V(`div`,{className:`univer-mt-2`,children:V(F,{disabled:c,value:r,max:20,min:0,onChange:l})}),H(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:[` `,t.t(`sheet.numfmt.negType`)]}),V(`div`,{className:`univer-mt-2`,children:V(L,{onChange:u,options:n,value:a})}),V(`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 Yt=e=>{let{defaultValue:t,defaultPattern:n,row:r,col:i}=e.value,a=N(p),o=Ct(()=>``),s=a.t,c=Ft(),l=z(()=>[{label:`sheet.numfmt.general`,component:Kt},{label:`sheet.numfmt.accounting`,component:Lt},{label:`sheet.numfmt.currency`,component:zt},{label:`sheet.numfmt.date`,component:Wt},{label:`sheet.numfmt.thousandthPercentile`,component:Jt},{label:`sheet.numfmt.customFormat`,component:Ht}].map(e=>({...e,label:s(e.label)})),[]),[u,d]=B(_),[f,m]=B(()=>`${r}_${i}`),{mark:h,userHabitCurrency:ee}=Pt(()=>m(`${r}_${i}_userCurrency'`)),g=z(()=>{var e;return(e=l.find(e=>e.label===u))==null?void 0:e.component},[u]);function _(){return[Gt,It,Rt,Ut,qt].reduce((e,t,r)=>e||(t(n)?l[r].label:``),``)||l[0].label}let v=l.map(e=>({label:e.label,value:e.label})),te=t=>{d(t),c(()=>e.onChange({type:`change`,value:o.current()||``}))},ne=xt(t=>{e.onChange({type:`change`,value:t})},[]),re=()=>{let t=o.current()||``,n=x(t);n&&h(n),e.onChange({type:`confirm`,value:t})},y=()=>{e.onChange({type:`cancel`,value:``})},b={onChange:ne,defaultValue:t,defaultPattern:n,action:o};return R(()=>{d(_()),m(`${r}_${i}`)},[r,i]),H(`div`,{className:_t(`univer-flex univer-h-full univer-flex-col univer-justify-between univer-overflow-y-auto univer-pb-5`,vt),children:[H(`div`,{children:[V(`div`,{className:`univer-mt-3.5 univer-text-sm univer-text-gray-400`,children:s(`sheet.numfmt.numfmtType`)}),V(`div`,{className:`univer-mt-2`,children:V(I,{className:`univer-w-full`,value:u,options:v,onChange:te})}),V(`div`,{children:g&&V(Mt.Provider,{value:ee,children:bt(g,{...b,key:f})})})]}),H(`div`,{className:`univer-mb-5 univer-mt-3.5 univer-flex univer-justify-end`,children:[V(pt,{onClick:y,className:`univer-mr-3`,children:s(`sheet.numfmt.cancel`)}),V(pt,{variant:`primary`,onClick:re,children:s(`sheet.numfmt.confirm`)})]})]})};function J(e){"@babel/helpers - typeof";return J=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},J(e)}function Xt(e,t){if(J(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(J(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Zt(e){var t=Xt(e,`string`);return J(t)==`symbol`?t:t+``}function Y(e,t,n){return(t=Zt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const Qt=`SHEET_NUMFMT_PANEL`;let X=class extends i{constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._sheetInterceptorService=e,this._themeService=t,this._univerInstanceService=n,this._commandService=r,this._selectionManagerService=i,this._renderManagerService=a,this._numfmtService=o,this._componentManager=s,this._sidebarService=c,this._localeService=l,this._sheetsNumfmtCellContentController=u,Y(this,`_previewPattern`,``),Y(this,`_sidebarDisposable`,null),this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener(),this._initNumfmtLocalChange()}_initNumfmtLocalChange(){this.disposeWithMe(ct(this._sheetsNumfmtCellContentController.locale$,this._localeService.currentLocale$).subscribe(()=>{this._forceUpdate()}))}openPanel(){var t;let n=this._sidebarService,r=this._selectionManagerService,i=this._commandService,a=this._univerInstanceService,o=this._numfmtService,s=this._localeService,c=(((t=r.getCurrentSelections())==null?void 0:t.map(e=>e.range))||[])[0];if(!c)return!1;let l=a.getCurrentUnitForType(v.UNIVER_SHEET),u=l.getActiveSheet();if(!u)return!1;let d=u.getCellRaw(c.startRow,c.startColumn),f=o.getValue(l.getUnitId(),u.getSheetId(),c.startRow,c.startColumn),p=``;f&&(p=f.pattern);let m=(d==null?void 0:d.t)===e.NUMBER?d.v:12345678,h={onChange:e=>{if(e.type===`change`)this._previewPattern=e.value,this._forceUpdate();else if(e.type===`confirm`){var t;let a=((t=r.getCurrentSelections())==null?void 0:t.map(e=>e.range))||[],o={values:[]},s=C(e.value);a.forEach(t=>{ee.foreach(t,(t,n)=>{o.values.push({row:t,col:n,pattern:e.value,type:s})})}),i.executeCommand(ve.id,o),n.close()}else e.type===`cancel`&&n.close()},value:{defaultPattern:p,defaultValue:m,row:c.startRow,col:c.startColumn}};return this._sidebarDisposable=n.open({header:{title:s.t(`sheet.numfmt.title`)},children:{label:Qt,...h},onClose:()=>{this._forceUpdate(),i.executeCommand(jt.id)}}),!0}_forceUpdate(e){var t;let n=this._renderManagerService.getRenderById(e==null?this._univerInstanceService.getCurrentUnitForType(v.UNIVER_SHEET).getUnitId():e);n==null||n.with(ze).reCalculate(),n==null||(t=n.mainComponent)==null||t.makeDirty()}_initCommands(){[K,jt].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initPanel(){this.disposeWithMe(this._componentManager.register(Qt,Yt))}_initRealTimeRenderingInterceptor(){let t=at([new P(e=>{this._commandService.onCommandExecuted(t=>{t.id===K.id&&e.next(!0),t.id===jt.id&&e.next(!1)})}),this._selectionManagerService.selectionMoveEnd$.pipe(ut(e=>e?e.map(e=>e.range):[]))]);this.disposeWithMe(ce(t.pipe(dt(([e,t])=>new P(n=>{let r=new a;return e&&t.length&&n.next({selectionRanges:t,disposableCollection:r}),()=>{r.dispose()}})),ft(()=>{this._previewPattern=null})).subscribe(({disposableCollection:t,selectionRanges:n})=>{var r;let i=this._univerInstanceService.getCurrentUnitForType(v.UNIVER_SHEET);this.openPanel(),t.add(this._sheetInterceptorService.intercept(We.CELL_CONTENT,{priority:99,effect:f.Value|f.Style,handler:(t,r,i)=>{let{row:a,col:o}=r,s=i(t)||{};if(n.find(e=>e.startColumn<=o&&e.endColumn>=o&&e.startRow<=a&&e.endRow>=a)){let t=r.worksheet.getCellRaw(a,o),n=t==null?void 0:t.v,i=t==null?void 0:t.t;if(n==null||i!==e.NUMBER||this._previewPattern===null)return s;let l=Ae(this._previewPattern,n,this._sheetsNumfmtCellContentController.locale);if(l.color){var c;let t=(c=this._themeService.getColorFromTheme(`${l.color}.500`))==null?l.color:c;return{...s,v:l.result,t:e.STRING,s:{cl:{rgb:t}}}}return{...s,v:l.result,t:e.STRING}}return s}})),(r=this._renderManagerService.getRenderById(i.getUnitId()))==null||(r=r.mainComponent)==null||r.makeDirty()})))}_commandExecutedListener(){let e=[Ke.id,D.id];this.disposeWithMe(new P(t=>{let n=this._commandService.onCommandExecuted(n=>{if(e.includes(n.id)){let e=n.params;t.next(e.unitId)}});return()=>n.dispose()}).pipe(lt(16)).subscribe(e=>this._forceUpdate(e)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(v.UNIVER_SHEET).subscribe(e=>{if(!e){var t;(t=this._sidebarDisposable)==null||t.dispose(),this._sidebarDisposable=null}})}};X=W([U(0,u(Je)),U(1,u(g)),U(2,l),U(3,o),U(4,u(Ye)),U(5,de),U(6,Ge),U(7,u($e)),U(8,nt),U(9,u(p)),U(10,u(be))],X);const $t=()=>{let e=[];return{add:(t,n,r,i,a)=>e.push({unitId:t,subUnitId:n,row:r,col:i,value:a}),getEffects:()=>e,clean:()=>{e=[]}}};let Z=class extends i{constructor(e,t,n,r,i){super(),this._sheetInterceptorService=e,this._numfmtService=t,this._univerInstanceService=n,this._injector=r,this._editorBridgeService=i,Y(this,`_collectEffectMutation`,$t()),this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(ce(this._sheetInterceptorService.writeCellInterceptor.intercept(Ue,{handler:(t,n,r)=>{let i=n.row,a=n.col,o=this._numfmtService.getValue(n.unitId,n.subUnitId,i,a);if(o)switch(C(o.pattern)){case`scientific`:case`currency`:case`grouped`:case`number`:{let t={...n.worksheet.getCellRaw(i,a)};return(t==null?void 0:t.t)===e.NUMBER&&b(t.v)&&(t.v=Tt(Number(t.v))),r&&r(t)}case`percent`:{let t={...n.worksheet.getCellRaw(i,a)};return(t==null?void 0:t.t)===e.NUMBER&&b(t.v)&&(t.v=`${Tt(Number(t.v)*100)}%`),r&&r(t)}default:return r&&r(t)}return r(t)}})))}_initInterceptorEditorEnd(){this.disposeWithMe(ce(this._sheetInterceptorService.writeCellInterceptor.intercept(He,{handler:(t,n,r)=>{var i,a;if(!(t!=null&&t.v)&&!(t!=null&&t.p))return r(t);this._collectEffectMutation.clean();let o=this._numfmtService.getValue(n.unitId,n.subUnitId,n.row,n.col),s=n.worksheet.getCellRaw(n.row,n.col);if(ie(o==null?void 0:o.pattern)||t.t===e.FORCE_STRING)return r(t);let c=(i=t.p)==null?void 0:i.body,l=!(t==null||(a=t.p)==null||(a=a.body)==null)&&a.dataStream?t.p.body.dataStream.replace(/\r\n$/,``):String(t.v),u=ne(l);if(c)if(en(c)){let{dataStream:e}=c,n=e.replace(/\r\n$/,``),i=Number(n);if(Number.isNaN(i)&&!u)return r(t)}else return r(t);if(u){if(!u.z&&!(o!=null&&o.pattern)&&(s==null?void 0:s.t)!==e.STRING&&(s==null?void 0:s.t)!==e.FORCE_STRING&&ue(l))return r({...t,p:void 0,v:l,t:e.FORCE_STRING});u.z&&(!(o!=null&&o.pattern)||C(u.z)!==C(o.pattern))&&this._collectEffectMutation.add(n.unitId,n.subUnitId,n.row,n.col,{pattern:u.z});let i=Tt(Number(u.v),16);return r({...t,p:void 0,v:i,t:e.NUMBER})}return r(t)}})))}_initInterceptorCommands(){let e=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(t){switch(t.id){case qe.id:{var n;let t=e._univerInstanceService.getCurrentUnitForType(v.UNIVER_SHEET),r=t.getUnitId(),i=(n=t.getActiveSheet())==null?void 0:n.getSheetId();if(!i)return{redos:[],undos:[]};let a=e._collectEffectMutation.getEffects();if(e._collectEffectMutation.clean(),!a.length)return{redos:[],undos:[]};let o=a.filter(e=>{var t;return!!((t=e.value)!=null&&t.pattern)}).map(e=>({row:e.row,col:e.col,pattern:e.value.pattern})),s=a.filter(e=>{var t;return!((t=e.value)!=null&&t.pattern)}).map(e=>({startRow:e.row,endColumn:e.col,startColumn:e.col,endRow:e.row})),c=[],l=[];if(o.length){let t={id:D.id,params:Qe(r,i,o)};c.push(t),l.push(...Ze(e._injector,t.params))}if(s.length){let t={id:Ke.id,params:{unitId:r,subUnitId:i,ranges:s}};c.push(t),l.push(...Xe(e._injector,t.params))}return{redos:c,undos:l.reverse()}}}return{redos:[],undos:[]}}}))}dispose(){super.dispose(),this._collectEffectMutation.clean()}};Z=W([U(0,u(Je)),U(1,u(Ge)),U(2,u(l)),U(3,u(d)),U(4,m(Ie))],Z);function en(e){let{textRuns:t=[],paragraphs:n=[],customRanges:r,customBlocks:i=[]}=e,a=[`va`];return!(t.some(e=>!!(e.ts&&Object.keys(e.ts).some(e=>a.includes(e))))||n.some(e=>e.bullet)||n.length>=2||r!=null&&r.length||i.length>0)}const tn=e=>[{label:`sheet.numfmt.general`,pattern:null},{label:`sheet.numfmt.text`,pattern:n},`|`,{label:`sheet.numfmt.number`,pattern:`0`},{label:`sheet.numfmt.percent`,pattern:`0.00%`},{label:`sheet.numfmt.scientific`,pattern:`0.00E+00`},`|`,{label:`sheet.numfmt.accounting`,pattern:`"${e}" #,##0.00_);[Red]("${e}"#,##0.00)`},{label:`sheet.numfmt.financialValue`,pattern:`#,##0.00;[Red]#,##0.00`},{label:`sheet.numfmt.currency`,pattern:`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`},{label:`sheet.numfmt.roundingCurrency`,pattern:`"${e}"#,##0;[Red]"${e}"#,##0`},`|`,{label:`sheet.numfmt.date`,pattern:`yyyy-mm-dd;@`},{label:`sheet.numfmt.time`,pattern:`am/pm h":"mm":"ss`},{label:`sheet.numfmt.dateTime`,pattern:`yyyy-m-d am/pm h:mm`},{label:`sheet.numfmt.timeDuration`,pattern:`h:mm:ss`},`|`,{label:`sheet.numfmt.moreFmt`,pattern:``}],nn=e=>({icon:new P(t=>{let n=e.get(p);return t.next(Ee(n.getCurrentLocale()).icon),n.localeChanged$.subscribe(()=>{t.next(Ee(n.getCurrentLocale()).icon)})}),id:_e.id,title:`sheet.numfmt.currency`,tooltip:`sheet.numfmt.currency`,type:j.BUTTON,hidden$:M(e,v.UNIVER_SHEET),disabled$:T(e,{workbookTypes:[O],worksheetTypes:[k,A],rangeTypes:[E]})}),rn=e=>({icon:`AddDigitsIcon`,id:fe.id,title:`sheet.numfmt.addDecimal`,tooltip:`sheet.numfmt.addDecimal`,type:j.BUTTON,hidden$:M(e,v.UNIVER_SHEET),disabled$:T(e,{workbookTypes:[O],worksheetTypes:[k,A],rangeTypes:[E]})}),an=e=>({icon:`ReduceDigitsIcon`,id:xe.id,title:`sheet.numfmt.subtractDecimal`,tooltip:`sheet.numfmt.subtractDecimal`,type:j.BUTTON,hidden$:M(e,v.UNIVER_SHEET),disabled$:T(e,{workbookTypes:[O],worksheetTypes:[k,A],rangeTypes:[E]})}),on=e=>({icon:`PercentIcon`,id:ye.id,title:`sheet.numfmt.percent`,tooltip:`sheet.numfmt.percent`,type:j.BUTTON,hidden$:M(e,v.UNIVER_SHEET),disabled$:T(e,{workbookTypes:[O],worksheetTypes:[k,A],rangeTypes:[E]})}),sn=e=>{let t=e.get(l),n=e.get(o),r=e.get(p),i=e.get(Ye),a=[Ke.id,D.id],s=Ve(t,``,({workbook:e,worksheet:t})=>new P(o=>ct(i.selectionMoveEnd$,te(n.onCommandExecuted.bind(n)).pipe(st(([e])=>a.includes(e.id)))).subscribe(()=>{let n=i.getCurrentSelections();if(n&&n[0]){var a,s;let i=n[0].range,c=i.startRow,l=i.startColumn,u=(a=e.getStyles().get((s=t.getCell(c,l))==null?void 0:s.s))==null?void 0:a.n,d=u==null?void 0:u.pattern,f=Te(r.getCurrentLocale()),p=r.t(`sheet.numfmt.general`);if(re(d)){o.next(p);return}if(d){let e=tn(f).filter(e=>typeof e==`object`&&e.pattern).find(e=>y(d,e.pattern));p=e&&typeof e==`object`&&e.pattern?r.t(e.label):r.t(`sheet.numfmt.moreFmt`)}o.next(p)}})));return{label:cn,id:K.id,tooltip:`sheet.numfmt.title`,type:j.SELECTOR,slot:!0,selections:[{label:{name:ln,hoverable:!1,selectable:!1}}],value$:s,hidden$:M(e,v.UNIVER_SHEET),disabled$:T(e,{workbookTypes:[O],worksheetTypes:[A,k],rangeTypes:[E]})}},cn=`sheet.numfmt.moreNumfmtType`,ln=`sheet.numfmt.moreNumfmtType.options`;function un(e){let{value:t}=e,n=N(p);return V(`span`,{className:`univer-text-sm`,children:t==null?n.t(`sheet.numfmt.general`):t})}function dn(){let e=N(o),t=N(p),n=N(et),r=N(be),i=N(Ye),a=t=>{let r=i.getCurrentLastSelection();if(!r)return;let a=r.range,o=[];ee.foreach(a,(e,n)=>{t?o.push({row:e,col:n,pattern:t,type:C(t)}):o.push({row:e,col:n})}),e.executeCommand(ve.id,{values:o}),n.focus()},s=z(()=>tn(Me.get(t.getCurrentLocale())),[t]),c=t=>{if(t===0)a(null);else if(t===s.length-1)e.executeCommand(K.id),n.focus();else{let e=s[t];e.pattern&&a(e.pattern)}};return V(`div`,{className:`univer-grid univer-gap-1 univer-p-1.5`,children:s.map((e,n)=>e===`|`?V(ht,{},n):H(`div`,{className:`univer-flex univer-h-7 univer-cursor-default 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(n),children:[V(`span`,{children:t.t(e.label)}),V(`span`,{className:`univer-text-xs univer-text-gray-500 dark:!univer-text-gray-400`,children:e.pattern?ke(e.pattern||``,1220,r.locale).result.trim():``})]},n))})}const fn={[it.LAYOUT]:{[K.id]:{order:9,menuItemFactory:sn},[ye.id]:{order:9.1,menuItemFactory:on},[_e.id]:{order:9.2,menuItemFactory:nn},[fe.id]:{order:9.3,menuItemFactory:rn},[xe.id]:{order:9.4,menuItemFactory:an}}};let Q=class extends i{constructor(e,t){super(),this._componentManager=e,this._menuManagerService=t,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(fn),[[cn,un],[ln,dn]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};Q=W([U(0,u($e)),U(1,tt)],Q);let $=class extends h{constructor(e=Ot,t,n,r){super(),this._config=e,this._injector=t,this._configService=n,this._renderManagerService=r;let{menu:i,...a}=ae({},Ot,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(`sheets-numfmt-ui.config`,a)}onStarting(){se(this._injector,[[X],[Z],[q],[Q],[G]])}onRendered(){this._registerRenderModules(),le(this._injector,[[X],[Z],[Q],[G]])}_registerRenderModules(){[[At]].forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(v.UNIVER_SHEET,e))})}};Y($,`pluginName`,`SHEET_NUMFMT_UI_PLUGIN`),Y($,`packageName`,Et),Y($,`version`,Dt),Y($,`type`,v.UNIVER_SHEET),$=W([r(Be,Se),U(1,u(d)),U(2,s),U(3,de)],$);export{$ as UniverSheetsNumfmtUIPlugin};
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { Disposable } from '@univerjs/core';
17
+ import { IRepeatLastActionService } from '@univerjs/sheets-ui';
18
+ export declare class NumfmtRepeatLastActionController extends Disposable {
19
+ private readonly _repeatLastActionService;
20
+ constructor(_repeatLastActionService: IRepeatLastActionService);
21
+ private _initCommandRecording;
22
+ }
package/lib/umd/index.js CHANGED
@@ -1,26 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/engine-render`),require(`@univerjs/sheets-numfmt`),require(`@univerjs/sheets-ui`),require(`@univerjs/sheets`),require(`@univerjs/ui`),require(`rxjs`),require(`rxjs/operators`),require(`@univerjs/design`),require(`react`),require(`react/jsx-runtime`),require(`@univerjs/engine-formula`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/engine-render`,`@univerjs/sheets-numfmt`,`@univerjs/sheets-ui`,`@univerjs/sheets`,`@univerjs/ui`,`rxjs`,`rxjs/operators`,`@univerjs/design`,`react`,`react/jsx-runtime`,`@univerjs/engine-formula`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsNumfmtUi={},e.UniverCore,e.UniverEngineRender,e.UniverSheetsNumfmt,e.UniverSheetsUi,e.UniverSheets,e.UniverUi,e.rxjs,e.rxjs.operators,e.UniverDesign,e.React,e.React,e.UniverEngineFormula))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var p=`@univerjs/sheets-numfmt-ui`,m=`0.18.0`;let h={};function g(e,t){return function(n,r){t(n,r,e)}}function _(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let v=`SHEET_NUMFMT_ALERT`,y=class extends t.Disposable{constructor(e,t,n,r,i,a,o){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=n,this._localeService=r,this._zenZoneService=i,this._numfmtService=a,this._configService=o,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0,s.debounceTime)(100)).subscribe(e=>{if(e){let o=e.location,s=this._context.unit,c=s.getActiveSheet();if(!c)return this._hideAlert();let l=o.unitId,u=o.subUnitId,d,f=c.getCell(o.row,o.col);if(f!=null&&f.s){let e=s.getStyles().get(f.s);e!=null&&e.n&&(d=e.n)}if(d||(d=this._numfmtService.getValue(l,u,o.row,o.col)),!d){this._hideAlert();return}if((0,t.isTextFormat)(d.pattern)&&t.Tools.isDefine(f==null?void 0:f.v)&&(0,t.isRealNum)(f.v)){var n,a;if((n=this._configService.getConfig(r.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY))!=null&&n.disableTextFormatAlert)return;let e=this._cellAlertManagerService.currentAlert.get(v),t=e==null||(a=e.alert)==null?void 0:a.location;if(t&&t.row===o.row&&t.col===o.col&&t.subUnitId===o.subUnitId&&t.unitId===o.unitId){this._hideAlert();return}this._cellAlertManagerService.showAlert({type:i.CellAlertType.ERROR,title:this._localeService.t(`info.error`),message:this._localeService.t(`info.forceStringInfo`),location:o,width:200,height:74,key:v});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(v)}};y=_([g(1,(0,t.Inject)(i.HoverManagerService)),g(2,(0,t.Inject)(i.CellAlertManagerService)),g(3,(0,t.Inject)(t.LocaleService)),g(4,o.IZenZoneService),g(5,(0,t.Inject)(a.INumfmtService)),g(6,t.IConfigService)],y);let b={id:`sheet.operation.close.numfmt.panel`,type:t.CommandType.OPERATION,handler:()=>!0},x={id:`sheet.operation.open.numfmt.panel`,type:t.CommandType.OPERATION,handler:e=>(e.get(K).openPanel(),!0)},S=(0,u.createContext)([]),C=class{constructor(e){this._localStorageService=e}_getKey(e){return`userHabitController_${e}`}async addHabit(e,t){let n=this._getKey(e);return this._localStorageService.getItem(n).then(e=>{e||this._localStorageService.setItem(n,t)})}markHabit(e,t){let n=this._getKey(e);this._localStorageService.getItem(n).then(e=>{if(e){let r=e.findIndex(e=>e===t);r>-1&&e.splice(r,1),e.unshift(t),this._localStorageService.setItem(n,e)}})}async getHabit(e,t){let n=this._getKey(e),r=await this._localStorageService.getItem(n);if(t&&r){let e=r.map((e,t,n)=>({value:e,priority:n.length-t}));return t.sort((t,n)=>{var r,i;let a=((r=e.find(e=>e.value===t))==null?void 0:r.priority)||-1;return(((i=e.find(e=>e.value===n))==null?void 0:i.priority)||-1)-a})}return r||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};C=_([g(0,(0,t.Inject)(t.ILocalStorageService))],C);let w=`numfmtCurrency`,T=e=>{let t=(0,o.useDependency)(C),[n,i]=(0,u.useState)(r.currencySymbols);return(0,u.useEffect)(()=>{t.addHabit(`numfmtCurrency`,[]).then(()=>{t.getHabit(w,[...r.currencySymbols]).then(t=>{i(t),e&&e(t)})})},[]),{userHabitCurrency:n,mark:e=>{t.markHabit(w,e)}}},E=()=>{let e=(0,u.useRef)([]),[t,n]=(0,u.useState)({});return(0,u.useEffect)(()=>{e.current.forEach(e=>{e()}),e.current=[]},[t]),t=>{e.current.push(t),n({})}},D=e=>!!(0,r.getCurrencyType)(e)&&e.startsWith(`_(`),ee=e=>{let{defaultPattern:n,action:i,onChange:a}=e,[s,c]=(0,u.useState)(()=>(0,r.getDecimalFromPattern)(n||``,2)),f=(0,u.useContext)(S),[p,m]=(0,u.useState)(()=>(0,r.getCurrencyType)(n)||f[0]),h=(0,u.useMemo)(()=>f.map(e=>({label:e,value:e})),[]),g=(0,o.useDependency)(t.LocaleService).t;return i.current=()=>(0,r.setPatternDecimal)(`_("${p}"* #,##0${s>0?`.0`:``}_)`,s),(0,d.jsxs)(`div`,{children:[(0,d.jsxs)(`div`,{className:`univer-mt-4 univer-flex univer-justify-between`,children:[(0,d.jsxs)(`div`,{className:`option`,children:[(0,d.jsx)(`div`,{className:`univer-text-sm univer-text-gray-400`,children:g(`sheet.numfmt.decimalLength`)}),(0,d.jsx)(`div`,{className:`univer-mt-2 univer-w-32`,children:(0,d.jsx)(l.InputNumber,{value:s,step:1,precision:0,max:20,min:0,onChange:e=>{let t=e||0;c(t),a((0,r.setPatternDecimal)(`_("${p}"* #,##0${t>0?`.0`:``}_)`,t))}})})]}),(0,d.jsxs)(`div`,{className:`option`,children:[(0,d.jsx)(`div`,{className:`univer-text-sm univer-text-gray-400`,children:g(`sheet.numfmt.currencyType`)}),(0,d.jsx)(`div`,{className:`univer-mt-2 univer-w-36`,children:(0,d.jsx)(l.Select,{options:h,value:p,onChange:e=>{m(e),a((0,r.setPatternDecimal)(`_("${e}"* #,##0${s>0?`.0`:``}_)`,s))}})})]})]}),(0,d.jsx)(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:g(`sheet.numfmt.accountingDes`)})]})},te=e=>!!(0,r.getCurrencyType)(e)&&!e.startsWith(`_(`),ne=e=>{let n=(0,o.useDependency)(t.LocaleService).t,i=(0,u.useContext)(S),[a,s]=(0,u.useState)(()=>(0,r.getCurrencyType)(e.defaultPattern)||i[0]),[c,f]=(0,u.useState)(()=>(0,r.getDecimalFromPattern)(e.defaultPattern||``,2)),[p,m]=(0,u.useState)(()=>{var n;let i=(0,r.getCurrencyFormatOptions)(a);return((n=i.find(n=>(0,t.isPatternEqualWithoutDecimal)(n.value,e.defaultPattern)))==null?void 0:n.value)||i[0].value}),h=(0,u.useMemo)(()=>(0,r.getCurrencyFormatOptions)(a),[a]),g=(0,u.useMemo)(()=>i.map(e=>({label:e,value:e})),[i]);return e.action.current=()=>(0,r.setPatternDecimal)(p,c),(0,d.jsxs)(`div`,{children:[(0,d.jsxs)(`div`,{className:`univer-mt-4 univer-flex univer-justify-between`,children:[(0,d.jsxs)(`div`,{className:`option`,children:[(0,d.jsx)(`div`,{className:`univer-text-sm univer-text-gray-400`,children:n(`sheet.numfmt.decimalLength`)}),(0,d.jsx)(`div`,{className:`univer-mt-2 univer-w-32`,children:(0,d.jsx)(l.InputNumber,{value:c,max:20,min:0,onChange:t=>{f(t||0),e.onChange((0,r.setPatternDecimal)(p,t||0))}})})]}),(0,d.jsxs)(`div`,{className:`option`,children:[(0,d.jsx)(`div`,{className:`univer-text-sm univer-text-gray-400`,children:n(`sheet.numfmt.currencyType`)}),(0,d.jsx)(`div`,{className:`univer-mt-2 univer-w-36`,children:(0,d.jsx)(l.Select,{value:a,options:g,onChange:t=>{if(t===void 0)return;s(t);let n=(0,r.getCurrencyFormatOptions)(t)[0].value;m(n),e.onChange((0,r.setPatternDecimal)(n,c))}})})]})]}),(0,d.jsx)(`div`,{className:`label univer-mt-4`,children:n(`sheet.numfmt.negType`)}),(0,d.jsx)(`div`,{className:`univer-mt-2`,children:(0,d.jsx)(l.SelectList,{value:p,options:h,onChange:t=>{t!==void 0&&(m(t),e.onChange((0,r.setPatternDecimal)(t,c)))}})}),(0,d.jsx)(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:n(`sheet.numfmt.currencyDes`)})]})};function O({ref:e,...t}){let{icon:n,id:r,className:i,extend:a,...o}=t,s=`univerjs-icon univerjs-icon-${r} ${i||``}`.trim(),c=(0,u.useRef)(`_${M()}`);return k(n,`${r}`,{defIds:n.defIds,idSuffix:c.current},{ref:e,className:s,...o},a)}function k(e,t,n,r,i){return(0,u.createElement)(e.tag,{key:t,...A(e,n,i),...r},(j(e,n).children||[]).map((r,a)=>k(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function A(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function j(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function M(){return Math.random().toString(36).substring(2,8)}O.displayName=`UniverIcon`;let N={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`}}]},P=(0,u.forwardRef)(function(e,t){return(0,u.createElement)(O,Object.assign({},e,{id:`check-mark-icon`,ref:t,icon:N}))});P.displayName=`CheckMarkIcon`;let F=`customFormat`,I=`numfmt_custom_pattern`;function L(e){let{defaultPattern:n,action:i,onChange:a}=e,s=(0,o.useDependency)(C),c=(0,o.useDependency)(t.ILocalStorageService),f=(0,o.useDependency)(t.LocaleService),[p,m]=(0,u.useState)(n);i.current=()=>(s.markHabit(F,p),c.getItem(I).then((e=[])=>{let t=[...new Set([p,...e||[]])].splice(0,10).filter(e=>!!e);c.setItem(I,t)}),p);let[h,g]=(0,u.useState)([]);(0,u.useEffect)(()=>{c.getItem(I).then(e=>{let t=[...r.CURRENCYFORMAT.map(e=>e.suffix(`$`)),...r.DATEFMTLISG.map(e=>e.suffix),...r.NUMBERFORMAT.map(e=>e.suffix)];t.push(...e||[]),s.addHabit(F,[]).finally(()=>{s.getHabit(F,t).then(e=>{g([...new Set(e)])})})})},[]);let _=e=>{m(e),a(e)};return(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:f.t(`sheet.numfmt.customFormat`)}),(0,d.jsx)(l.Input,{placeholder:f.t(`sheet.numfmt.customFormat`),onBlur:()=>{a(p)},value:p,onChange:m,className:`univer-mt-2 univer-w-full`}),(0,d.jsx)(`div`,{className:(0,l.clsx)(`univer-mt-2 univer-max-h-[400px] univer-overflow-auto univer-rounded-lg univer-p-2`,l.borderClassName),children:h.map(e=>(0,d.jsxs)(`div`,{onClick:()=>_(e),className:`
2
- univer-flex univer-cursor-pointer univer-items-center univer-gap-1.5 univer-py-1.5
3
- univer-text-sm
4
- `,children:[(0,d.jsx)(`div`,{className:`univer-flex univer-w-4 univer-items-center univer-text-primary-600`,children:p===e&&(0,d.jsx)(P,{})}),(0,d.jsx)(`div`,{children:e})]},e))}),(0,d.jsx)(`div`,{className:`
5
- univer-mt-3 univer-text-sm univer-text-gray-600
6
- dark:!univer-text-gray-200
7
- `,children:f.t(`sheet.numfmt.customFormatDes`)})]})}let re=e=>{let n=t.numfmt.getFormatInfo(e);return(0,r.getDateFormatOptions)().map(e=>e.value).includes(e)||[`date`,`datetime`,`time`].includes(n.type)};function ie(e){let{onChange:n,defaultPattern:i}=e,a=(0,u.useMemo)(r.getDateFormatOptions,[]),s=(0,o.useDependency)(t.LocaleService),[c,f]=(0,u.useState)(()=>{if(i){let e=a.find(e=>e.value===i);if(e)return e.value}return a[0].value});return e.action.current=()=>c,(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:s.t(`sheet.numfmt.dateType`)}),(0,d.jsx)(`div`,{className:`univer-mt-2`,children:(0,d.jsx)(l.SelectList,{value:c,options:a,onChange:e=>{e!==void 0&&(f(e),n(e))}})}),(0,d.jsx)(`div`,{className:`
8
- univer-mt-3.5 univer-text-sm/5 univer-text-gray-600
9
- dark:!univer-text-gray-200
10
- `,children:s.t(`sheet.numfmt.dateDes`)})]})}let ae=e=>!e,oe=e=>{let n=(0,o.useDependency)(t.LocaleService).t;return e.action.current=()=>``,(0,d.jsx)(`div`,{children:(0,d.jsx)(`div`,{className:`
11
- univer-mt-3.5 univer-text-sm/5 univer-text-gray-600
12
- dark:!univer-text-gray-200
13
- `,children:n(`sheet.numfmt.generalDes`)})})},R=e=>(0,r.getNumberFormatOptions)().some(n=>(0,t.isPatternEqualWithoutDecimal)(n.value,e));function z(e){let n=(0,o.useDependency)(t.LocaleService),i=(0,u.useMemo)(r.getNumberFormatOptions,[]),[a,s]=(0,u.useState)(()=>(0,r.getDecimalFromPattern)(e.defaultPattern||``,0)),[c,f]=(0,u.useState)(()=>{let n=i.find(n=>(0,t.isPatternEqualWithoutDecimal)(n.value,e.defaultPattern||``));return(n==null?void 0:n.value)||i[0].value}),p=(0,u.useMemo)(()=>(0,r.setPatternDecimal)(c,Number(a||0)),[c,a]),m=(0,u.useMemo)(()=>!(0,r.isPatternHasDecimal)(c),[c]),h=t=>{s(t||0),e.onChange((0,r.setPatternDecimal)(c,Number(t||0)))},g=t=>{t!==void 0&&(s((0,r.getDecimalFromPattern)(t,0)),f(t),e.onChange(t))};return e.action.current=()=>p,(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:n.t(`sheet.numfmt.decimalLength`)}),(0,d.jsx)(`div`,{className:`univer-mt-2`,children:(0,d.jsx)(l.InputNumber,{disabled:m,value:a,max:20,min:0,onChange:h})}),(0,d.jsxs)(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:[` `,n.t(`sheet.numfmt.negType`)]}),(0,d.jsx)(`div`,{className:`univer-mt-2`,children:(0,d.jsx)(l.SelectList,{onChange:g,options:i,value:c})}),(0,d.jsx)(`div`,{className:`
14
- univer-mt-3.5 univer-text-sm/5 univer-text-gray-600
15
- dark:!univer-text-gray-200
16
- `,children:n.t(`sheet.numfmt.thousandthPercentileDes`)})]})}let B=e=>{let{defaultValue:n,defaultPattern:i,row:a,col:s}=e.value,c=(0,o.useDependency)(t.LocaleService),f=(0,u.useRef)(()=>``),p=c.t,m=E(),h=(0,u.useMemo)(()=>[{label:`sheet.numfmt.general`,component:oe},{label:`sheet.numfmt.accounting`,component:ee},{label:`sheet.numfmt.currency`,component:ne},{label:`sheet.numfmt.date`,component:ie},{label:`sheet.numfmt.thousandthPercentile`,component:z},{label:`sheet.numfmt.customFormat`,component:L}].map(e=>({...e,label:p(e.label)})),[]),[g,_]=(0,u.useState)(w),[v,y]=(0,u.useState)(()=>`${a}_${s}`),{mark:b,userHabitCurrency:x}=T(()=>y(`${a}_${s}_userCurrency'`)),C=(0,u.useMemo)(()=>{var e;return(e=h.find(e=>e.label===g))==null?void 0:e.component},[g]);function w(){return[ae,D,te,re,R].reduce((e,t,n)=>e||(t(i)?h[n].label:``),``)||h[0].label}let O=h.map(e=>({label:e.label,value:e.label})),k=t=>{_(t),m(()=>e.onChange({type:`change`,value:f.current()||``}))},A=(0,u.useCallback)(t=>{e.onChange({type:`change`,value:t})},[]),j=()=>{let t=f.current()||``,n=(0,r.getCurrencyType)(t);n&&b(n),e.onChange({type:`confirm`,value:t})},M=()=>{e.onChange({type:`cancel`,value:``})},N={onChange:A,defaultValue:n,defaultPattern:i,action:f};return(0,u.useEffect)(()=>{_(w()),y(`${a}_${s}`)},[a,s]),(0,d.jsxs)(`div`,{className:(0,l.clsx)(`
17
- univer-flex univer-h-full univer-flex-col univer-justify-between univer-overflow-y-auto univer-pb-5
18
- `,l.scrollbarClassName),children:[(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`univer-mt-3.5 univer-text-sm univer-text-gray-400`,children:p(`sheet.numfmt.numfmtType`)}),(0,d.jsx)(`div`,{className:`univer-mt-2`,children:(0,d.jsx)(l.Select,{className:`univer-w-full`,value:g,options:O,onChange:k})}),(0,d.jsx)(`div`,{children:C&&(0,d.jsx)(S.Provider,{value:x,children:(0,u.createElement)(C,{...N,key:v})})})]}),(0,d.jsxs)(`div`,{className:`univer-mb-5 univer-mt-3.5 univer-flex univer-justify-end`,children:[(0,d.jsx)(l.Button,{onClick:M,className:`univer-mr-3`,children:p(`sheet.numfmt.cancel`)}),(0,d.jsx)(l.Button,{variant:`primary`,onClick:j,children:p(`sheet.numfmt.confirm`)})]})]})};function V(e){"@babel/helpers - typeof";return V=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},V(e)}function H(e,t){if(V(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(V(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function U(e){var t=H(e,`string`);return V(t)==`symbol`?t:t+``}function W(e,t,n){return(t=U(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let G=`SHEET_NUMFMT_PANEL`,K=class extends t.Disposable{constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._sheetInterceptorService=e,this._themeService=t,this._univerInstanceService=n,this._commandService=r,this._selectionManagerService=i,this._renderManagerService=a,this._numfmtService=o,this._componentManager=s,this._sidebarService=c,this._localeService=l,this._sheetsNumfmtCellContentController=u,W(this,`_previewPattern`,``),W(this,`_sidebarDisposable`,null),this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener(),this._initNumfmtLocalChange()}_initNumfmtLocalChange(){this.disposeWithMe((0,s.merge)(this._sheetsNumfmtCellContentController.locale$,this._localeService.currentLocale$).subscribe(()=>{this._forceUpdate()}))}openPanel(){var e;let n=this._sidebarService,i=this._selectionManagerService,a=this._commandService,o=this._univerInstanceService,s=this._numfmtService,c=this._localeService,l=(((e=i.getCurrentSelections())==null?void 0:e.map(e=>e.range))||[])[0];if(!l)return!1;let u=o.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET),d=u.getActiveSheet();if(!d)return!1;let f=d.getCellRaw(l.startRow,l.startColumn),p=s.getValue(u.getUnitId(),d.getSheetId(),l.startRow,l.startColumn),m=``;p&&(m=p.pattern);let h=(f==null?void 0:f.t)===t.CellValueType.NUMBER?f.v:12345678,g={onChange:e=>{if(e.type===`change`)this._previewPattern=e.value,this._forceUpdate();else if(e.type===`confirm`){var o;let s=((o=i.getCurrentSelections())==null?void 0:o.map(e=>e.range))||[],c={values:[]},l=(0,r.getPatternType)(e.value);s.forEach(n=>{t.Range.foreach(n,(t,n)=>{c.values.push({row:t,col:n,pattern:e.value,type:l})})}),a.executeCommand(r.SetNumfmtCommand.id,c),n.close()}else e.type===`cancel`&&n.close()},value:{defaultPattern:m,defaultValue:h,row:l.startRow,col:l.startColumn}};return this._sidebarDisposable=n.open({header:{title:c.t(`sheet.numfmt.title`)},children:{label:G,...g},onClose:()=>{this._forceUpdate(),a.executeCommand(b.id)}}),!0}_forceUpdate(e){var n;let r=this._renderManagerService.getRenderById(e==null?this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET).getUnitId():e);r==null||r.with(i.SheetSkeletonManagerService).reCalculate(),r==null||(n=r.mainComponent)==null||n.makeDirty()}_initCommands(){[x,b].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initPanel(){this.disposeWithMe(this._componentManager.register(G,B))}_initRealTimeRenderingInterceptor(){let e=(0,s.combineLatest)([new s.Observable(e=>{this._commandService.onCommandExecuted(t=>{t.id===x.id&&e.next(!0),t.id===b.id&&e.next(!1)})}),this._selectionManagerService.selectionMoveEnd$.pipe((0,c.map)(e=>e?e.map(e=>e.range):[]))]);this.disposeWithMe((0,t.toDisposable)(e.pipe((0,c.switchMap)(([e,n])=>new s.Observable(r=>{let i=new t.DisposableCollection;return e&&n.length&&r.next({selectionRanges:n,disposableCollection:i}),()=>{i.dispose()}})),(0,c.tap)(()=>{this._previewPattern=null})).subscribe(({disposableCollection:e,selectionRanges:n})=>{var i;let o=this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET);this.openPanel(),e.add(this._sheetInterceptorService.intercept(a.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(e,i,a)=>{let{row:o,col:s}=i,c=a(e)||{};if(n.find(e=>e.startColumn<=s&&e.endColumn>=s&&e.startRow<=o&&e.endRow>=o)){let e=i.worksheet.getCellRaw(o,s),n=e==null?void 0:e.v,a=e==null?void 0:e.t;if(n==null||a!==t.CellValueType.NUMBER||this._previewPattern===null)return c;let u=(0,r.getPatternPreviewIgnoreGeneral)(this._previewPattern,n,this._sheetsNumfmtCellContentController.locale);if(u.color){var l;let e=(l=this._themeService.getColorFromTheme(`${u.color}.500`))==null?u.color:l;return{...c,v:u.result,t:t.CellValueType.STRING,s:{cl:{rgb:e}}}}return{...c,v:u.result,t:t.CellValueType.STRING}}return c}})),(i=this._renderManagerService.getRenderById(o.getUnitId()))==null||(i=i.mainComponent)==null||i.makeDirty()})))}_commandExecutedListener(){let e=[a.RemoveNumfmtMutation.id,a.SetNumfmtMutation.id];this.disposeWithMe(new s.Observable(t=>{let n=this._commandService.onCommandExecuted(n=>{if(e.includes(n.id)){let e=n.params;t.next(e.unitId)}});return()=>n.dispose()}).pipe((0,c.debounceTime)(16)).subscribe(e=>this._forceUpdate(e)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).subscribe(e=>{if(!e){var t;(t=this._sidebarDisposable)==null||t.dispose(),this._sidebarDisposable=null}})}};K=_([g(0,(0,t.Inject)(a.SheetInterceptorService)),g(1,(0,t.Inject)(t.ThemeService)),g(2,t.IUniverInstanceService),g(3,t.ICommandService),g(4,(0,t.Inject)(a.SheetsSelectionsService)),g(5,n.IRenderManagerService),g(6,a.INumfmtService),g(7,(0,t.Inject)(o.ComponentManager)),g(8,o.ISidebarService),g(9,(0,t.Inject)(t.LocaleService)),g(10,(0,t.Inject)(r.SheetsNumfmtCellContentController))],K);let se=()=>{let e=[];return{add:(t,n,r,i,a)=>e.push({unitId:t,subUnitId:n,row:r,col:i,value:a}),getEffects:()=>e,clean:()=>{e=[]}}},q=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._sheetInterceptorService=e,this._numfmtService=t,this._univerInstanceService=n,this._injector=r,this._editorBridgeService=i,W(this,`_collectEffectMutation`,se()),this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe((0,t.toDisposable)(this._sheetInterceptorService.writeCellInterceptor.intercept(a.BEFORE_CELL_EDIT,{handler:(e,n,i)=>{let a=n.row,o=n.col,s=this._numfmtService.getValue(n.unitId,n.subUnitId,a,o);if(s)switch((0,r.getPatternType)(s.pattern)){case`scientific`:case`currency`:case`grouped`:case`number`:{let e={...n.worksheet.getCellRaw(a,o)};return(e==null?void 0:e.t)===t.CellValueType.NUMBER&&(0,t.isRealNum)(e.v)&&(e.v=(0,f.stripErrorMargin)(Number(e.v))),i&&i(e)}case`percent`:{let e={...n.worksheet.getCellRaw(a,o)};return(e==null?void 0:e.t)===t.CellValueType.NUMBER&&(0,t.isRealNum)(e.v)&&(e.v=`${(0,f.stripErrorMargin)(Number(e.v)*100)}%`),i&&i(e)}default:return i&&i(e)}return i(e)}})))}_initInterceptorEditorEnd(){this.disposeWithMe((0,t.toDisposable)(this._sheetInterceptorService.writeCellInterceptor.intercept(a.AFTER_CELL_EDIT,{handler:(e,n,i)=>{var a,o;if(!(e!=null&&e.v)&&!(e!=null&&e.p))return i(e);this._collectEffectMutation.clean();let s=this._numfmtService.getValue(n.unitId,n.subUnitId,n.row,n.col),c=n.worksheet.getCellRaw(n.row,n.col);if((0,t.isTextFormat)(s==null?void 0:s.pattern)||e.t===t.CellValueType.FORCE_STRING)return i(e);let l=(a=e.p)==null?void 0:a.body,u=!(e==null||(o=e.p)==null||(o=o.body)==null)&&o.dataStream?e.p.body.dataStream.replace(/\r\n$/,``):String(e.v),d=(0,t.getNumfmtParseValueFilter)(u);if(l)if(ce(l)){let{dataStream:t}=l,n=t.replace(/\r\n$/,``),r=Number(n);if(Number.isNaN(r)&&!d)return i(e)}else return i(e);if(d){if(!d.z&&!(s!=null&&s.pattern)&&(c==null?void 0:c.t)!==t.CellValueType.STRING&&(c==null?void 0:c.t)!==t.CellValueType.FORCE_STRING&&(0,t.willLoseNumericPrecision)(u))return i({...e,p:void 0,v:u,t:t.CellValueType.FORCE_STRING});d.z&&(!(s!=null&&s.pattern)||(0,r.getPatternType)(d.z)!==(0,r.getPatternType)(s.pattern))&&this._collectEffectMutation.add(n.unitId,n.subUnitId,n.row,n.col,{pattern:d.z});let a=(0,f.stripErrorMargin)(Number(d.v),16);return i({...e,p:void 0,v:a,t:t.CellValueType.NUMBER})}return i(e)}})))}_initInterceptorCommands(){let e=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(n){switch(n.id){case a.SetRangeValuesCommand.id:{var r;let n=e._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET),i=n.getUnitId(),o=(r=n.getActiveSheet())==null?void 0:r.getSheetId();if(!o)return{redos:[],undos:[]};let s=e._collectEffectMutation.getEffects();if(e._collectEffectMutation.clean(),!s.length)return{redos:[],undos:[]};let c=s.filter(e=>{var t;return!!((t=e.value)!=null&&t.pattern)}).map(e=>({row:e.row,col:e.col,pattern:e.value.pattern})),l=s.filter(e=>{var t;return!((t=e.value)!=null&&t.pattern)}).map(e=>({startRow:e.row,endColumn:e.col,startColumn:e.col,endRow:e.row})),u=[],d=[];if(c.length){let t={id:a.SetNumfmtMutation.id,params:(0,a.transformCellsToRange)(i,o,c)};u.push(t),d.push(...(0,a.factorySetNumfmtUndoMutation)(e._injector,t.params))}if(l.length){let t={id:a.RemoveNumfmtMutation.id,params:{unitId:i,subUnitId:o,ranges:l}};u.push(t),d.push(...(0,a.factoryRemoveNumfmtUndoMutation)(e._injector,t.params))}return{redos:u,undos:d.reverse()}}}return{redos:[],undos:[]}}}))}dispose(){super.dispose(),this._collectEffectMutation.clean()}};q=_([g(0,(0,t.Inject)(a.SheetInterceptorService)),g(1,(0,t.Inject)(a.INumfmtService)),g(2,(0,t.Inject)(t.IUniverInstanceService)),g(3,(0,t.Inject)(t.Injector)),g(4,(0,t.Optional)(i.IEditorBridgeService))],q);function ce(e){let{textRuns:t=[],paragraphs:n=[],customRanges:r,customBlocks:i=[]}=e,a=[`va`];return!(t.some(e=>!!(e.ts&&Object.keys(e.ts).some(e=>a.includes(e))))||n.some(e=>e.bullet)||n.length>=2||r!=null&&r.length||i.length>0)}let J=e=>[{label:`sheet.numfmt.general`,pattern:null},{label:`sheet.numfmt.text`,pattern:t.DEFAULT_TEXT_FORMAT_EXCEL},`|`,{label:`sheet.numfmt.number`,pattern:`0`},{label:`sheet.numfmt.percent`,pattern:`0.00%`},{label:`sheet.numfmt.scientific`,pattern:`0.00E+00`},`|`,{label:`sheet.numfmt.accounting`,pattern:`"${e}" #,##0.00_);[Red]("${e}"#,##0.00)`},{label:`sheet.numfmt.financialValue`,pattern:`#,##0.00;[Red]#,##0.00`},{label:`sheet.numfmt.currency`,pattern:`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`},{label:`sheet.numfmt.roundingCurrency`,pattern:`"${e}"#,##0;[Red]"${e}"#,##0`},`|`,{label:`sheet.numfmt.date`,pattern:`yyyy-mm-dd;@`},{label:`sheet.numfmt.time`,pattern:`am/pm h":"mm":"ss`},{label:`sheet.numfmt.dateTime`,pattern:`yyyy-m-d am/pm h:mm`},{label:`sheet.numfmt.timeDuration`,pattern:`h:mm:ss`},`|`,{label:`sheet.numfmt.moreFmt`,pattern:``}],le=e=>({icon:new s.Observable(n=>{let i=e.get(t.LocaleService);return n.next((0,r.getCurrencySymbolIconByLocale)(i.getCurrentLocale()).icon),i.localeChanged$.subscribe(()=>{n.next((0,r.getCurrencySymbolIconByLocale)(i.getCurrentLocale()).icon)})}),id:r.SetCurrencyCommand.id,title:`sheet.numfmt.currency`,tooltip:`sheet.numfmt.currency`,type:o.MenuItemType.BUTTON,hidden$:(0,o.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,i.getCurrentRangeDisable$)(e,{workbookTypes:[a.WorkbookEditablePermission],worksheetTypes:[a.WorksheetEditPermission,a.WorksheetSetCellStylePermission],rangeTypes:[a.RangeProtectionPermissionEditPoint]})}),Y=e=>({icon:`AddDigitsIcon`,id:r.AddDecimalCommand.id,title:`sheet.numfmt.addDecimal`,tooltip:`sheet.numfmt.addDecimal`,type:o.MenuItemType.BUTTON,hidden$:(0,o.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,i.getCurrentRangeDisable$)(e,{workbookTypes:[a.WorkbookEditablePermission],worksheetTypes:[a.WorksheetEditPermission,a.WorksheetSetCellStylePermission],rangeTypes:[a.RangeProtectionPermissionEditPoint]})}),ue=e=>({icon:`ReduceDigitsIcon`,id:r.SubtractDecimalCommand.id,title:`sheet.numfmt.subtractDecimal`,tooltip:`sheet.numfmt.subtractDecimal`,type:o.MenuItemType.BUTTON,hidden$:(0,o.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,i.getCurrentRangeDisable$)(e,{workbookTypes:[a.WorkbookEditablePermission],worksheetTypes:[a.WorksheetEditPermission,a.WorksheetSetCellStylePermission],rangeTypes:[a.RangeProtectionPermissionEditPoint]})}),de=e=>({icon:`PercentIcon`,id:r.SetPercentCommand.id,title:`sheet.numfmt.percent`,tooltip:`sheet.numfmt.percent`,type:o.MenuItemType.BUTTON,hidden$:(0,o.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,i.getCurrentRangeDisable$)(e,{workbookTypes:[a.WorkbookEditablePermission],worksheetTypes:[a.WorksheetEditPermission,a.WorksheetSetCellStylePermission],rangeTypes:[a.RangeProtectionPermissionEditPoint]})}),fe=e=>{let n=e.get(t.IUniverInstanceService),c=e.get(t.ICommandService),l=e.get(t.LocaleService),u=e.get(a.SheetsSelectionsService),d=[a.RemoveNumfmtMutation.id,a.SetNumfmtMutation.id],f=(0,i.deriveStateFromActiveSheet$)(n,``,({workbook:e,worksheet:n})=>new s.Observable(i=>(0,s.merge)(u.selectionMoveEnd$,(0,t.fromCallback)(c.onCommandExecuted.bind(c)).pipe((0,s.filter)(([e])=>d.includes(e.id)))).subscribe(()=>{let a=u.getCurrentSelections();if(a&&a[0]){var o,s;let c=a[0].range,u=c.startRow,d=c.startColumn,f=(o=e.getStyles().get((s=n.getCell(u,d))==null?void 0:s.s))==null?void 0:o.n,p=f==null?void 0:f.pattern,m=(0,r.getCurrencySymbolByLocale)(l.getCurrentLocale()),h=l.t(`sheet.numfmt.general`);if((0,t.isDefaultFormat)(p)){i.next(h);return}if(p){let e=J(m).filter(e=>typeof e==`object`&&e.pattern).find(e=>(0,t.isPatternEqualWithoutDecimal)(p,e.pattern));h=e&&typeof e==`object`&&e.pattern?l.t(e.label):l.t(`sheet.numfmt.moreFmt`)}i.next(h)}})));return{label:X,id:x.id,tooltip:`sheet.numfmt.title`,type:o.MenuItemType.SELECTOR,slot:!0,selections:[{label:{name:Z,hoverable:!1,selectable:!1}}],value$:f,hidden$:(0,o.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,i.getCurrentRangeDisable$)(e,{workbookTypes:[a.WorkbookEditablePermission],worksheetTypes:[a.WorksheetSetCellStylePermission,a.WorksheetEditPermission],rangeTypes:[a.RangeProtectionPermissionEditPoint]})}},X=`sheet.numfmt.moreNumfmtType`,Z=`sheet.numfmt.moreNumfmtType.options`;function pe(e){let{value:n}=e,r=(0,o.useDependency)(t.LocaleService);return(0,d.jsx)(`span`,{className:`univer-text-sm`,children:n==null?r.t(`sheet.numfmt.general`):n})}function me(){let e=(0,o.useDependency)(t.ICommandService),n=(0,o.useDependency)(t.LocaleService),i=(0,o.useDependency)(o.ILayoutService),s=(0,o.useDependency)(r.SheetsNumfmtCellContentController),c=(0,o.useDependency)(a.SheetsSelectionsService),f=n=>{let a=c.getCurrentLastSelection();if(!a)return;let o=a.range,s=[];t.Range.foreach(o,(e,t)=>{n?s.push({row:e,col:t,pattern:n,type:(0,r.getPatternType)(n)}):s.push({row:e,col:t})}),e.executeCommand(r.SetNumfmtCommand.id,{values:s}),i.focus()},p=(0,u.useMemo)(()=>J(r.localeCurrencySymbolMap.get(n.getCurrentLocale())),[n]),m=t=>{if(t===0)f(null);else if(t===p.length-1)e.executeCommand(x.id),i.focus();else{let e=p[t];e.pattern&&f(e.pattern)}};return(0,d.jsx)(`div`,{className:`univer-grid univer-gap-1 univer-p-1.5`,children:p.map((e,t)=>e===`|`?(0,d.jsx)(l.Separator,{},t):(0,d.jsxs)(`div`,{className:`
19
- univer-flex univer-h-7 univer-cursor-default univer-items-center univer-justify-between
20
- univer-gap-6 univer-rounded univer-px-2 univer-text-sm
21
- hover:univer-bg-gray-100
22
- dark:hover:!univer-bg-gray-700
23
- `,onClick:()=>m(t),children:[(0,d.jsx)(`span`,{children:n.t(e.label)}),(0,d.jsx)(`span`,{className:`
24
- univer-text-xs univer-text-gray-500
25
- dark:!univer-text-gray-400
26
- `,children:e.pattern?(0,r.getPatternPreview)(e.pattern||``,1220,s.locale).result.trim():``})]},t))})}let he={[o.RibbonStartGroup.LAYOUT]:{[x.id]:{order:9,menuItemFactory:fe},[r.SetPercentCommand.id]:{order:9.1,menuItemFactory:de},[r.SetCurrencyCommand.id]:{order:9.2,menuItemFactory:le},[r.AddDecimalCommand.id]:{order:9.3,menuItemFactory:Y},[r.SubtractDecimalCommand.id]:{order:9.4,menuItemFactory:ue}}},Q=class extends t.Disposable{constructor(e,t){super(),this._componentManager=e,this._menuManagerService=t,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(he),[[X,pe],[Z,me]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};Q=_([g(0,(0,t.Inject)(o.ComponentManager)),g(1,o.IMenuManagerService)],Q);let $=class extends t.Plugin{constructor(e=h,n,r,i){super(),this._config=e,this._injector=n,this._configService=r,this._renderManagerService=i;let{menu:a,...o}=(0,t.merge)({},h,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(`sheets-numfmt-ui.config`,o)}onStarting(){(0,t.registerDependencies)(this._injector,[[K],[q],[C],[Q]])}onRendered(){this._registerRenderModules(),(0,t.touchDependencies)(this._injector,[[K],[q],[Q]])}_registerRenderModules(){[[y]].forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(t.UniverInstanceType.UNIVER_SHEET,e))})}};W($,`pluginName`,`SHEET_NUMFMT_UI_PLUGIN`),W($,`packageName`,p),W($,`version`,m),W($,`type`,t.UniverInstanceType.UNIVER_SHEET),$=_([(0,t.DependentOn)(i.UniverSheetsUIPlugin,r.UniverSheetsNumfmtPlugin),g(1,(0,t.Inject)(t.Injector)),g(2,t.IConfigService),g(3,n.IRenderManagerService)],$),Object.defineProperty(e,`UniverSheetsNumfmtUIPlugin`,{enumerable:!0,get:function(){return $}})});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/engine-render`),require(`@univerjs/sheets-numfmt`),require(`@univerjs/sheets-ui`),require(`@univerjs/sheets`),require(`@univerjs/ui`),require(`rxjs`),require(`rxjs/operators`),require(`@univerjs/design`),require(`react`),require(`react/jsx-runtime`),require(`@univerjs/engine-formula`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/engine-render`,`@univerjs/sheets-numfmt`,`@univerjs/sheets-ui`,`@univerjs/sheets`,`@univerjs/ui`,`rxjs`,`rxjs/operators`,`@univerjs/design`,`react`,`react/jsx-runtime`,`@univerjs/engine-formula`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsNumfmtUi={},e.UniverCore,e.UniverEngineRender,e.UniverSheetsNumfmt,e.UniverSheetsUi,e.UniverSheets,e.UniverUi,e.rxjs,e.rxjs.operators,e.UniverDesign,e.React,e.React,e.UniverEngineFormula))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var p=`@univerjs/sheets-numfmt-ui`,m=`0.19.0-insiders.20260403-3e0e122`;let h={};function g(e,t){return function(n,r){t(n,r,e)}}function _(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let v=`SHEET_NUMFMT_ALERT`,y=class extends t.Disposable{constructor(e,t,n,r,i,a,o){super(),this._context=e,this._hoverManagerService=t,this._cellAlertManagerService=n,this._localeService=r,this._zenZoneService=i,this._numfmtService=a,this._configService=o,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0,s.debounceTime)(100)).subscribe(e=>{if(e){let o=e.location,s=this._context.unit,c=s.getActiveSheet();if(!c)return this._hideAlert();let l=o.unitId,u=o.subUnitId,d,f=c.getCell(o.row,o.col);if(f!=null&&f.s){let e=s.getStyles().get(f.s);e!=null&&e.n&&(d=e.n)}if(d||(d=this._numfmtService.getValue(l,u,o.row,o.col)),!d){this._hideAlert();return}if((0,t.isTextFormat)(d.pattern)&&t.Tools.isDefine(f==null?void 0:f.v)&&(0,t.isRealNum)(f.v)){var n,a;if((n=this._configService.getConfig(r.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY))!=null&&n.disableTextFormatAlert)return;let e=this._cellAlertManagerService.currentAlert.get(v),t=e==null||(a=e.alert)==null?void 0:a.location;if(t&&t.row===o.row&&t.col===o.col&&t.subUnitId===o.subUnitId&&t.unitId===o.unitId){this._hideAlert();return}this._cellAlertManagerService.showAlert({type:i.CellAlertType.ERROR,title:this._localeService.t(`info.error`),message:this._localeService.t(`info.forceStringInfo`),location:o,width:200,height:74,key:v});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(v)}};y=_([g(1,(0,t.Inject)(i.HoverManagerService)),g(2,(0,t.Inject)(i.CellAlertManagerService)),g(3,(0,t.Inject)(t.LocaleService)),g(4,o.IZenZoneService),g(5,(0,t.Inject)(a.INumfmtService)),g(6,t.IConfigService)],y);let b=class extends t.Disposable{constructor(e){super(),this._repeatLastActionService=e,this._initCommandRecording()}_initCommandRecording(){this.disposeWithMe(this._repeatLastActionService.registerRepeatableCommand(r.SetNumfmtCommand.id,(e,t)=>{if(!t)return;let{values:n}=t,r=n.find(e=>e.pattern);if(!r)return;let{pattern:i,type:a}=r,o=[],s=new Set;for(let t of e){let{startRow:e,startColumn:n,endRow:r,endColumn:c}=t;for(let t=e;t<=r;t++)for(let e=n;e<=c;e++){let n=`${t}-${e}`;s.has(n)||(s.add(n),o.push({row:t,col:e,pattern:i,type:a}))}}return{...t,values:o}},i.RepeatLastActionPermission.CellStyle))}};b=_([g(0,(0,t.Inject)(i.IRepeatLastActionService))],b);let x={id:`sheet.operation.close.numfmt.panel`,type:t.CommandType.OPERATION,handler:()=>!0},S={id:`sheet.operation.open.numfmt.panel`,type:t.CommandType.OPERATION,handler:e=>(e.get(q).openPanel(),!0)},C=(0,u.createContext)([]),w=class{constructor(e){this._localStorageService=e}_getKey(e){return`userHabitController_${e}`}async addHabit(e,t){let n=this._getKey(e);return this._localStorageService.getItem(n).then(e=>{e||this._localStorageService.setItem(n,t)})}markHabit(e,t){let n=this._getKey(e);this._localStorageService.getItem(n).then(e=>{if(e){let r=e.findIndex(e=>e===t);r>-1&&e.splice(r,1),e.unshift(t),this._localStorageService.setItem(n,e)}})}async getHabit(e,t){let n=this._getKey(e),r=await this._localStorageService.getItem(n);if(t&&r){let e=r.map((e,t,n)=>({value:e,priority:n.length-t}));return t.sort((t,n)=>{var r,i;let a=((r=e.find(e=>e.value===t))==null?void 0:r.priority)||-1;return(((i=e.find(e=>e.value===n))==null?void 0:i.priority)||-1)-a})}return r||[]}deleteHabit(e){this._localStorageService.removeItem(e)}};w=_([g(0,(0,t.Inject)(t.ILocalStorageService))],w);let T=`numfmtCurrency`,E=e=>{let t=(0,o.useDependency)(w),[n,i]=(0,u.useState)(r.currencySymbols);return(0,u.useEffect)(()=>{t.addHabit(`numfmtCurrency`,[]).then(()=>{t.getHabit(T,[...r.currencySymbols]).then(t=>{i(t),e&&e(t)})})},[]),{userHabitCurrency:n,mark:e=>{t.markHabit(T,e)}}},ee=()=>{let e=(0,u.useRef)([]),[t,n]=(0,u.useState)({});return(0,u.useEffect)(()=>{e.current.forEach(e=>{e()}),e.current=[]},[t]),t=>{e.current.push(t),n({})}},te=e=>!!(0,r.getCurrencyType)(e)&&e.startsWith(`_(`),ne=e=>{let{defaultPattern:n,action:i,onChange:a}=e,[s,c]=(0,u.useState)(()=>(0,r.getDecimalFromPattern)(n||``,2)),f=(0,u.useContext)(C),[p,m]=(0,u.useState)(()=>(0,r.getCurrencyType)(n)||f[0]),h=(0,u.useMemo)(()=>f.map(e=>({label:e,value:e})),[]),g=(0,o.useDependency)(t.LocaleService).t;return i.current=()=>(0,r.setPatternDecimal)(`_("${p}"* #,##0${s>0?`.0`:``}_)`,s),(0,d.jsxs)(`div`,{children:[(0,d.jsxs)(`div`,{className:`univer-mt-4 univer-flex univer-justify-between`,children:[(0,d.jsxs)(`div`,{className:`option`,children:[(0,d.jsx)(`div`,{className:`univer-text-sm univer-text-gray-400`,children:g(`sheet.numfmt.decimalLength`)}),(0,d.jsx)(`div`,{className:`univer-mt-2 univer-w-32`,children:(0,d.jsx)(l.InputNumber,{value:s,step:1,precision:0,max:20,min:0,onChange:e=>{let t=e||0;c(t),a((0,r.setPatternDecimal)(`_("${p}"* #,##0${t>0?`.0`:``}_)`,t))}})})]}),(0,d.jsxs)(`div`,{className:`option`,children:[(0,d.jsx)(`div`,{className:`univer-text-sm univer-text-gray-400`,children:g(`sheet.numfmt.currencyType`)}),(0,d.jsx)(`div`,{className:`univer-mt-2 univer-w-36`,children:(0,d.jsx)(l.Select,{options:h,value:p,onChange:e=>{m(e),a((0,r.setPatternDecimal)(`_("${e}"* #,##0${s>0?`.0`:``}_)`,s))}})})]})]}),(0,d.jsx)(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:g(`sheet.numfmt.accountingDes`)})]})},re=e=>!!(0,r.getCurrencyType)(e)&&!e.startsWith(`_(`),D=e=>{let n=(0,o.useDependency)(t.LocaleService).t,i=(0,u.useContext)(C),[a,s]=(0,u.useState)(()=>(0,r.getCurrencyType)(e.defaultPattern)||i[0]),[c,f]=(0,u.useState)(()=>(0,r.getDecimalFromPattern)(e.defaultPattern||``,2)),[p,m]=(0,u.useState)(()=>{var n;let i=(0,r.getCurrencyFormatOptions)(a);return((n=i.find(n=>(0,t.isPatternEqualWithoutDecimal)(n.value,e.defaultPattern)))==null?void 0:n.value)||i[0].value}),h=(0,u.useMemo)(()=>(0,r.getCurrencyFormatOptions)(a),[a]),g=(0,u.useMemo)(()=>i.map(e=>({label:e,value:e})),[i]);return e.action.current=()=>(0,r.setPatternDecimal)(p,c),(0,d.jsxs)(`div`,{children:[(0,d.jsxs)(`div`,{className:`univer-mt-4 univer-flex univer-justify-between`,children:[(0,d.jsxs)(`div`,{className:`option`,children:[(0,d.jsx)(`div`,{className:`univer-text-sm univer-text-gray-400`,children:n(`sheet.numfmt.decimalLength`)}),(0,d.jsx)(`div`,{className:`univer-mt-2 univer-w-32`,children:(0,d.jsx)(l.InputNumber,{value:c,max:20,min:0,onChange:t=>{f(t||0),e.onChange((0,r.setPatternDecimal)(p,t||0))}})})]}),(0,d.jsxs)(`div`,{className:`option`,children:[(0,d.jsx)(`div`,{className:`univer-text-sm univer-text-gray-400`,children:n(`sheet.numfmt.currencyType`)}),(0,d.jsx)(`div`,{className:`univer-mt-2 univer-w-36`,children:(0,d.jsx)(l.Select,{value:a,options:g,onChange:t=>{if(t===void 0)return;s(t);let n=(0,r.getCurrencyFormatOptions)(t)[0].value;m(n),e.onChange((0,r.setPatternDecimal)(n,c))}})})]})]}),(0,d.jsx)(`div`,{className:`label univer-mt-4`,children:n(`sheet.numfmt.negType`)}),(0,d.jsx)(`div`,{className:`univer-mt-2`,children:(0,d.jsx)(l.SelectList,{value:p,options:h,onChange:t=>{t!==void 0&&(m(t),e.onChange((0,r.setPatternDecimal)(t,c)))}})}),(0,d.jsx)(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:n(`sheet.numfmt.currencyDes`)})]})};function O({ref:e,...t}){let{icon:n,id:r,className:i,extend:a,...o}=t,s=`univerjs-icon univerjs-icon-${r} ${i||``}`.trim(),c=(0,u.useRef)(`_${M()}`);return k(n,`${r}`,{defIds:n.defIds,idSuffix:c.current},{ref:e,className:s,...o},a)}function k(e,t,n,r,i){return(0,u.createElement)(e.tag,{key:t,...A(e,n,i),...r},(j(e,n).children||[]).map((r,a)=>k(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function A(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function j(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function M(){return Math.random().toString(36).substring(2,8)}O.displayName=`UniverIcon`;let N={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`}}]},P=(0,u.forwardRef)(function(e,t){return(0,u.createElement)(O,Object.assign({},e,{id:`check-mark-icon`,ref:t,icon:N}))});P.displayName=`CheckMarkIcon`;let F=`customFormat`,I=`numfmt_custom_pattern`;function L(e){let{defaultPattern:n,action:i,onChange:a}=e,s=(0,o.useDependency)(w),c=(0,o.useDependency)(t.ILocalStorageService),f=(0,o.useDependency)(t.LocaleService),[p,m]=(0,u.useState)(n);i.current=()=>(s.markHabit(F,p),c.getItem(I).then((e=[])=>{let t=[...new Set([p,...e||[]])].splice(0,10).filter(e=>!!e);c.setItem(I,t)}),p);let[h,g]=(0,u.useState)([]);(0,u.useEffect)(()=>{c.getItem(I).then(e=>{let t=[...r.CURRENCYFORMAT.map(e=>e.suffix(`$`)),...r.DATEFMTLISG.map(e=>e.suffix),...r.NUMBERFORMAT.map(e=>e.suffix)];t.push(...e||[]),s.addHabit(F,[]).finally(()=>{s.getHabit(F,t).then(e=>{g([...new Set(e)])})})})},[]);let _=e=>{m(e),a(e)};return(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:f.t(`sheet.numfmt.customFormat`)}),(0,d.jsx)(l.Input,{placeholder:f.t(`sheet.numfmt.customFormat`),onBlur:()=>{a(p)},value:p,onChange:m,className:`univer-mt-2 univer-w-full`}),(0,d.jsx)(`div`,{className:(0,l.clsx)(`univer-mt-2 univer-max-h-[400px] univer-overflow-auto univer-rounded-lg univer-p-2`,l.borderClassName),children:h.map(e=>(0,d.jsxs)(`div`,{onClick:()=>_(e),className:`univer-flex univer-cursor-pointer univer-items-center univer-gap-1.5 univer-py-1.5 univer-text-sm`,children:[(0,d.jsx)(`div`,{className:`univer-flex univer-w-4 univer-items-center univer-text-primary-600`,children:p===e&&(0,d.jsx)(P,{})}),(0,d.jsx)(`div`,{children:e})]},e))}),(0,d.jsx)(`div`,{className:`univer-mt-3 univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200`,children:f.t(`sheet.numfmt.customFormatDes`)})]})}let ie=e=>{let n=t.numfmt.getFormatInfo(e);return(0,r.getDateFormatOptions)().map(e=>e.value).includes(e)||[`date`,`datetime`,`time`].includes(n.type)};function ae(e){let{onChange:n,defaultPattern:i}=e,a=(0,u.useMemo)(r.getDateFormatOptions,[]),s=(0,o.useDependency)(t.LocaleService),[c,f]=(0,u.useState)(()=>{if(i){let e=a.find(e=>e.value===i);if(e)return e.value}return a[0].value});return e.action.current=()=>c,(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:s.t(`sheet.numfmt.dateType`)}),(0,d.jsx)(`div`,{className:`univer-mt-2`,children:(0,d.jsx)(l.SelectList,{value:c,options:a,onChange:e=>{e!==void 0&&(f(e),n(e))}})}),(0,d.jsx)(`div`,{className:`univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200`,children:s.t(`sheet.numfmt.dateDes`)})]})}let oe=e=>!e,R=e=>{let n=(0,o.useDependency)(t.LocaleService).t;return e.action.current=()=>``,(0,d.jsx)(`div`,{children:(0,d.jsx)(`div`,{className:`univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200`,children:n(`sheet.numfmt.generalDes`)})})},z=e=>(0,r.getNumberFormatOptions)().some(n=>(0,t.isPatternEqualWithoutDecimal)(n.value,e));function B(e){let n=(0,o.useDependency)(t.LocaleService),i=(0,u.useMemo)(r.getNumberFormatOptions,[]),[a,s]=(0,u.useState)(()=>(0,r.getDecimalFromPattern)(e.defaultPattern||``,0)),[c,f]=(0,u.useState)(()=>{let n=i.find(n=>(0,t.isPatternEqualWithoutDecimal)(n.value,e.defaultPattern||``));return(n==null?void 0:n.value)||i[0].value}),p=(0,u.useMemo)(()=>(0,r.setPatternDecimal)(c,Number(a||0)),[c,a]),m=(0,u.useMemo)(()=>!(0,r.isPatternHasDecimal)(c),[c]),h=t=>{s(t||0),e.onChange((0,r.setPatternDecimal)(c,Number(t||0)))},g=t=>{t!==void 0&&(s((0,r.getDecimalFromPattern)(t,0)),f(t),e.onChange(t))};return e.action.current=()=>p,(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:n.t(`sheet.numfmt.decimalLength`)}),(0,d.jsx)(`div`,{className:`univer-mt-2`,children:(0,d.jsx)(l.InputNumber,{disabled:m,value:a,max:20,min:0,onChange:h})}),(0,d.jsxs)(`div`,{className:`univer-mt-4 univer-text-sm univer-text-gray-400`,children:[` `,n.t(`sheet.numfmt.negType`)]}),(0,d.jsx)(`div`,{className:`univer-mt-2`,children:(0,d.jsx)(l.SelectList,{onChange:g,options:i,value:c})}),(0,d.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`)})]})}let V=e=>{let{defaultValue:n,defaultPattern:i,row:a,col:s}=e.value,c=(0,o.useDependency)(t.LocaleService),f=(0,u.useRef)(()=>``),p=c.t,m=ee(),h=(0,u.useMemo)(()=>[{label:`sheet.numfmt.general`,component:R},{label:`sheet.numfmt.accounting`,component:ne},{label:`sheet.numfmt.currency`,component:D},{label:`sheet.numfmt.date`,component:ae},{label:`sheet.numfmt.thousandthPercentile`,component:B},{label:`sheet.numfmt.customFormat`,component:L}].map(e=>({...e,label:p(e.label)})),[]),[g,_]=(0,u.useState)(w),[v,y]=(0,u.useState)(()=>`${a}_${s}`),{mark:b,userHabitCurrency:x}=E(()=>y(`${a}_${s}_userCurrency'`)),S=(0,u.useMemo)(()=>{var e;return(e=h.find(e=>e.label===g))==null?void 0:e.component},[g]);function w(){return[oe,te,re,ie,z].reduce((e,t,n)=>e||(t(i)?h[n].label:``),``)||h[0].label}let T=h.map(e=>({label:e.label,value:e.label})),O=t=>{_(t),m(()=>e.onChange({type:`change`,value:f.current()||``}))},k=(0,u.useCallback)(t=>{e.onChange({type:`change`,value:t})},[]),A=()=>{let t=f.current()||``,n=(0,r.getCurrencyType)(t);n&&b(n),e.onChange({type:`confirm`,value:t})},j=()=>{e.onChange({type:`cancel`,value:``})},M={onChange:k,defaultValue:n,defaultPattern:i,action:f};return(0,u.useEffect)(()=>{_(w()),y(`${a}_${s}`)},[a,s]),(0,d.jsxs)(`div`,{className:(0,l.clsx)(`univer-flex univer-h-full univer-flex-col univer-justify-between univer-overflow-y-auto univer-pb-5`,l.scrollbarClassName),children:[(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`div`,{className:`univer-mt-3.5 univer-text-sm univer-text-gray-400`,children:p(`sheet.numfmt.numfmtType`)}),(0,d.jsx)(`div`,{className:`univer-mt-2`,children:(0,d.jsx)(l.Select,{className:`univer-w-full`,value:g,options:T,onChange:O})}),(0,d.jsx)(`div`,{children:S&&(0,d.jsx)(C.Provider,{value:x,children:(0,u.createElement)(S,{...M,key:v})})})]}),(0,d.jsxs)(`div`,{className:`univer-mb-5 univer-mt-3.5 univer-flex univer-justify-end`,children:[(0,d.jsx)(l.Button,{onClick:j,className:`univer-mr-3`,children:p(`sheet.numfmt.cancel`)}),(0,d.jsx)(l.Button,{variant:`primary`,onClick:A,children:p(`sheet.numfmt.confirm`)})]})]})};function H(e){"@babel/helpers - typeof";return H=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},H(e)}function U(e,t){if(H(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(H(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function W(e){var t=U(e,`string`);return H(t)==`symbol`?t:t+``}function G(e,t,n){return(t=W(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let K=`SHEET_NUMFMT_PANEL`,q=class extends t.Disposable{constructor(e,t,n,r,i,a,o,s,c,l,u){super(),this._sheetInterceptorService=e,this._themeService=t,this._univerInstanceService=n,this._commandService=r,this._selectionManagerService=i,this._renderManagerService=a,this._numfmtService=o,this._componentManager=s,this._sidebarService=c,this._localeService=l,this._sheetsNumfmtCellContentController=u,G(this,`_previewPattern`,``),G(this,`_sidebarDisposable`,null),this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener(),this._initNumfmtLocalChange()}_initNumfmtLocalChange(){this.disposeWithMe((0,s.merge)(this._sheetsNumfmtCellContentController.locale$,this._localeService.currentLocale$).subscribe(()=>{this._forceUpdate()}))}openPanel(){var e;let n=this._sidebarService,i=this._selectionManagerService,a=this._commandService,o=this._univerInstanceService,s=this._numfmtService,c=this._localeService,l=(((e=i.getCurrentSelections())==null?void 0:e.map(e=>e.range))||[])[0];if(!l)return!1;let u=o.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET),d=u.getActiveSheet();if(!d)return!1;let f=d.getCellRaw(l.startRow,l.startColumn),p=s.getValue(u.getUnitId(),d.getSheetId(),l.startRow,l.startColumn),m=``;p&&(m=p.pattern);let h=(f==null?void 0:f.t)===t.CellValueType.NUMBER?f.v:12345678,g={onChange:e=>{if(e.type===`change`)this._previewPattern=e.value,this._forceUpdate();else if(e.type===`confirm`){var o;let s=((o=i.getCurrentSelections())==null?void 0:o.map(e=>e.range))||[],c={values:[]},l=(0,r.getPatternType)(e.value);s.forEach(n=>{t.Range.foreach(n,(t,n)=>{c.values.push({row:t,col:n,pattern:e.value,type:l})})}),a.executeCommand(r.SetNumfmtCommand.id,c),n.close()}else e.type===`cancel`&&n.close()},value:{defaultPattern:m,defaultValue:h,row:l.startRow,col:l.startColumn}};return this._sidebarDisposable=n.open({header:{title:c.t(`sheet.numfmt.title`)},children:{label:K,...g},onClose:()=>{this._forceUpdate(),a.executeCommand(x.id)}}),!0}_forceUpdate(e){var n;let r=this._renderManagerService.getRenderById(e==null?this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET).getUnitId():e);r==null||r.with(i.SheetSkeletonManagerService).reCalculate(),r==null||(n=r.mainComponent)==null||n.makeDirty()}_initCommands(){[S,x].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initPanel(){this.disposeWithMe(this._componentManager.register(K,V))}_initRealTimeRenderingInterceptor(){let e=(0,s.combineLatest)([new s.Observable(e=>{this._commandService.onCommandExecuted(t=>{t.id===S.id&&e.next(!0),t.id===x.id&&e.next(!1)})}),this._selectionManagerService.selectionMoveEnd$.pipe((0,c.map)(e=>e?e.map(e=>e.range):[]))]);this.disposeWithMe((0,t.toDisposable)(e.pipe((0,c.switchMap)(([e,n])=>new s.Observable(r=>{let i=new t.DisposableCollection;return e&&n.length&&r.next({selectionRanges:n,disposableCollection:i}),()=>{i.dispose()}})),(0,c.tap)(()=>{this._previewPattern=null})).subscribe(({disposableCollection:e,selectionRanges:n})=>{var i;let o=this._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET);this.openPanel(),e.add(this._sheetInterceptorService.intercept(a.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(e,i,a)=>{let{row:o,col:s}=i,c=a(e)||{};if(n.find(e=>e.startColumn<=s&&e.endColumn>=s&&e.startRow<=o&&e.endRow>=o)){let e=i.worksheet.getCellRaw(o,s),n=e==null?void 0:e.v,a=e==null?void 0:e.t;if(n==null||a!==t.CellValueType.NUMBER||this._previewPattern===null)return c;let u=(0,r.getPatternPreviewIgnoreGeneral)(this._previewPattern,n,this._sheetsNumfmtCellContentController.locale);if(u.color){var l;let e=(l=this._themeService.getColorFromTheme(`${u.color}.500`))==null?u.color:l;return{...c,v:u.result,t:t.CellValueType.STRING,s:{cl:{rgb:e}}}}return{...c,v:u.result,t:t.CellValueType.STRING}}return c}})),(i=this._renderManagerService.getRenderById(o.getUnitId()))==null||(i=i.mainComponent)==null||i.makeDirty()})))}_commandExecutedListener(){let e=[a.RemoveNumfmtMutation.id,a.SetNumfmtMutation.id];this.disposeWithMe(new s.Observable(t=>{let n=this._commandService.onCommandExecuted(n=>{if(e.includes(n.id)){let e=n.params;t.next(e.unitId)}});return()=>n.dispose()}).pipe((0,c.debounceTime)(16)).subscribe(e=>this._forceUpdate(e)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).subscribe(e=>{if(!e){var t;(t=this._sidebarDisposable)==null||t.dispose(),this._sidebarDisposable=null}})}};q=_([g(0,(0,t.Inject)(a.SheetInterceptorService)),g(1,(0,t.Inject)(t.ThemeService)),g(2,t.IUniverInstanceService),g(3,t.ICommandService),g(4,(0,t.Inject)(a.SheetsSelectionsService)),g(5,n.IRenderManagerService),g(6,a.INumfmtService),g(7,(0,t.Inject)(o.ComponentManager)),g(8,o.ISidebarService),g(9,(0,t.Inject)(t.LocaleService)),g(10,(0,t.Inject)(r.SheetsNumfmtCellContentController))],q);let se=()=>{let e=[];return{add:(t,n,r,i,a)=>e.push({unitId:t,subUnitId:n,row:r,col:i,value:a}),getEffects:()=>e,clean:()=>{e=[]}}},J=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._sheetInterceptorService=e,this._numfmtService=t,this._univerInstanceService=n,this._injector=r,this._editorBridgeService=i,G(this,`_collectEffectMutation`,se()),this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe((0,t.toDisposable)(this._sheetInterceptorService.writeCellInterceptor.intercept(a.BEFORE_CELL_EDIT,{handler:(e,n,i)=>{let a=n.row,o=n.col,s=this._numfmtService.getValue(n.unitId,n.subUnitId,a,o);if(s)switch((0,r.getPatternType)(s.pattern)){case`scientific`:case`currency`:case`grouped`:case`number`:{let e={...n.worksheet.getCellRaw(a,o)};return(e==null?void 0:e.t)===t.CellValueType.NUMBER&&(0,t.isRealNum)(e.v)&&(e.v=(0,f.stripErrorMargin)(Number(e.v))),i&&i(e)}case`percent`:{let e={...n.worksheet.getCellRaw(a,o)};return(e==null?void 0:e.t)===t.CellValueType.NUMBER&&(0,t.isRealNum)(e.v)&&(e.v=`${(0,f.stripErrorMargin)(Number(e.v)*100)}%`),i&&i(e)}default:return i&&i(e)}return i(e)}})))}_initInterceptorEditorEnd(){this.disposeWithMe((0,t.toDisposable)(this._sheetInterceptorService.writeCellInterceptor.intercept(a.AFTER_CELL_EDIT,{handler:(e,n,i)=>{var a,o;if(!(e!=null&&e.v)&&!(e!=null&&e.p))return i(e);this._collectEffectMutation.clean();let s=this._numfmtService.getValue(n.unitId,n.subUnitId,n.row,n.col),c=n.worksheet.getCellRaw(n.row,n.col);if((0,t.isTextFormat)(s==null?void 0:s.pattern)||e.t===t.CellValueType.FORCE_STRING)return i(e);let l=(a=e.p)==null?void 0:a.body,u=!(e==null||(o=e.p)==null||(o=o.body)==null)&&o.dataStream?e.p.body.dataStream.replace(/\r\n$/,``):String(e.v),d=(0,t.getNumfmtParseValueFilter)(u);if(l)if(ce(l)){let{dataStream:t}=l,n=t.replace(/\r\n$/,``),r=Number(n);if(Number.isNaN(r)&&!d)return i(e)}else return i(e);if(d){if(!d.z&&!(s!=null&&s.pattern)&&(c==null?void 0:c.t)!==t.CellValueType.STRING&&(c==null?void 0:c.t)!==t.CellValueType.FORCE_STRING&&(0,t.willLoseNumericPrecision)(u))return i({...e,p:void 0,v:u,t:t.CellValueType.FORCE_STRING});d.z&&(!(s!=null&&s.pattern)||(0,r.getPatternType)(d.z)!==(0,r.getPatternType)(s.pattern))&&this._collectEffectMutation.add(n.unitId,n.subUnitId,n.row,n.col,{pattern:d.z});let a=(0,f.stripErrorMargin)(Number(d.v),16);return i({...e,p:void 0,v:a,t:t.CellValueType.NUMBER})}return i(e)}})))}_initInterceptorCommands(){let e=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(n){switch(n.id){case a.SetRangeValuesCommand.id:{var r;let n=e._univerInstanceService.getCurrentUnitForType(t.UniverInstanceType.UNIVER_SHEET),i=n.getUnitId(),o=(r=n.getActiveSheet())==null?void 0:r.getSheetId();if(!o)return{redos:[],undos:[]};let s=e._collectEffectMutation.getEffects();if(e._collectEffectMutation.clean(),!s.length)return{redos:[],undos:[]};let c=s.filter(e=>{var t;return!!((t=e.value)!=null&&t.pattern)}).map(e=>({row:e.row,col:e.col,pattern:e.value.pattern})),l=s.filter(e=>{var t;return!((t=e.value)!=null&&t.pattern)}).map(e=>({startRow:e.row,endColumn:e.col,startColumn:e.col,endRow:e.row})),u=[],d=[];if(c.length){let t={id:a.SetNumfmtMutation.id,params:(0,a.transformCellsToRange)(i,o,c)};u.push(t),d.push(...(0,a.factorySetNumfmtUndoMutation)(e._injector,t.params))}if(l.length){let t={id:a.RemoveNumfmtMutation.id,params:{unitId:i,subUnitId:o,ranges:l}};u.push(t),d.push(...(0,a.factoryRemoveNumfmtUndoMutation)(e._injector,t.params))}return{redos:u,undos:d.reverse()}}}return{redos:[],undos:[]}}}))}dispose(){super.dispose(),this._collectEffectMutation.clean()}};J=_([g(0,(0,t.Inject)(a.SheetInterceptorService)),g(1,(0,t.Inject)(a.INumfmtService)),g(2,(0,t.Inject)(t.IUniverInstanceService)),g(3,(0,t.Inject)(t.Injector)),g(4,(0,t.Optional)(i.IEditorBridgeService))],J);function ce(e){let{textRuns:t=[],paragraphs:n=[],customRanges:r,customBlocks:i=[]}=e,a=[`va`];return!(t.some(e=>!!(e.ts&&Object.keys(e.ts).some(e=>a.includes(e))))||n.some(e=>e.bullet)||n.length>=2||r!=null&&r.length||i.length>0)}let Y=e=>[{label:`sheet.numfmt.general`,pattern:null},{label:`sheet.numfmt.text`,pattern:t.DEFAULT_TEXT_FORMAT_EXCEL},`|`,{label:`sheet.numfmt.number`,pattern:`0`},{label:`sheet.numfmt.percent`,pattern:`0.00%`},{label:`sheet.numfmt.scientific`,pattern:`0.00E+00`},`|`,{label:`sheet.numfmt.accounting`,pattern:`"${e}" #,##0.00_);[Red]("${e}"#,##0.00)`},{label:`sheet.numfmt.financialValue`,pattern:`#,##0.00;[Red]#,##0.00`},{label:`sheet.numfmt.currency`,pattern:`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`},{label:`sheet.numfmt.roundingCurrency`,pattern:`"${e}"#,##0;[Red]"${e}"#,##0`},`|`,{label:`sheet.numfmt.date`,pattern:`yyyy-mm-dd;@`},{label:`sheet.numfmt.time`,pattern:`am/pm h":"mm":"ss`},{label:`sheet.numfmt.dateTime`,pattern:`yyyy-m-d am/pm h:mm`},{label:`sheet.numfmt.timeDuration`,pattern:`h:mm:ss`},`|`,{label:`sheet.numfmt.moreFmt`,pattern:``}],le=e=>({icon:new s.Observable(n=>{let i=e.get(t.LocaleService);return n.next((0,r.getCurrencySymbolIconByLocale)(i.getCurrentLocale()).icon),i.localeChanged$.subscribe(()=>{n.next((0,r.getCurrencySymbolIconByLocale)(i.getCurrentLocale()).icon)})}),id:r.SetCurrencyCommand.id,title:`sheet.numfmt.currency`,tooltip:`sheet.numfmt.currency`,type:o.MenuItemType.BUTTON,hidden$:(0,o.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,i.getCurrentRangeDisable$)(e,{workbookTypes:[a.WorkbookEditablePermission],worksheetTypes:[a.WorksheetEditPermission,a.WorksheetSetCellStylePermission],rangeTypes:[a.RangeProtectionPermissionEditPoint]})}),ue=e=>({icon:`AddDigitsIcon`,id:r.AddDecimalCommand.id,title:`sheet.numfmt.addDecimal`,tooltip:`sheet.numfmt.addDecimal`,type:o.MenuItemType.BUTTON,hidden$:(0,o.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,i.getCurrentRangeDisable$)(e,{workbookTypes:[a.WorkbookEditablePermission],worksheetTypes:[a.WorksheetEditPermission,a.WorksheetSetCellStylePermission],rangeTypes:[a.RangeProtectionPermissionEditPoint]})}),de=e=>({icon:`ReduceDigitsIcon`,id:r.SubtractDecimalCommand.id,title:`sheet.numfmt.subtractDecimal`,tooltip:`sheet.numfmt.subtractDecimal`,type:o.MenuItemType.BUTTON,hidden$:(0,o.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,i.getCurrentRangeDisable$)(e,{workbookTypes:[a.WorkbookEditablePermission],worksheetTypes:[a.WorksheetEditPermission,a.WorksheetSetCellStylePermission],rangeTypes:[a.RangeProtectionPermissionEditPoint]})}),fe=e=>({icon:`PercentIcon`,id:r.SetPercentCommand.id,title:`sheet.numfmt.percent`,tooltip:`sheet.numfmt.percent`,type:o.MenuItemType.BUTTON,hidden$:(0,o.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,i.getCurrentRangeDisable$)(e,{workbookTypes:[a.WorkbookEditablePermission],worksheetTypes:[a.WorksheetEditPermission,a.WorksheetSetCellStylePermission],rangeTypes:[a.RangeProtectionPermissionEditPoint]})}),pe=e=>{let n=e.get(t.IUniverInstanceService),c=e.get(t.ICommandService),l=e.get(t.LocaleService),u=e.get(a.SheetsSelectionsService),d=[a.RemoveNumfmtMutation.id,a.SetNumfmtMutation.id],f=(0,i.deriveStateFromActiveSheet$)(n,``,({workbook:e,worksheet:n})=>new s.Observable(i=>(0,s.merge)(u.selectionMoveEnd$,(0,t.fromCallback)(c.onCommandExecuted.bind(c)).pipe((0,s.filter)(([e])=>d.includes(e.id)))).subscribe(()=>{let a=u.getCurrentSelections();if(a&&a[0]){var o,s;let c=a[0].range,u=c.startRow,d=c.startColumn,f=(o=e.getStyles().get((s=n.getCell(u,d))==null?void 0:s.s))==null?void 0:o.n,p=f==null?void 0:f.pattern,m=(0,r.getCurrencySymbolByLocale)(l.getCurrentLocale()),h=l.t(`sheet.numfmt.general`);if((0,t.isDefaultFormat)(p)){i.next(h);return}if(p){let e=Y(m).filter(e=>typeof e==`object`&&e.pattern).find(e=>(0,t.isPatternEqualWithoutDecimal)(p,e.pattern));h=e&&typeof e==`object`&&e.pattern?l.t(e.label):l.t(`sheet.numfmt.moreFmt`)}i.next(h)}})));return{label:X,id:S.id,tooltip:`sheet.numfmt.title`,type:o.MenuItemType.SELECTOR,slot:!0,selections:[{label:{name:Z,hoverable:!1,selectable:!1}}],value$:f,hidden$:(0,o.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,i.getCurrentRangeDisable$)(e,{workbookTypes:[a.WorkbookEditablePermission],worksheetTypes:[a.WorksheetSetCellStylePermission,a.WorksheetEditPermission],rangeTypes:[a.RangeProtectionPermissionEditPoint]})}},X=`sheet.numfmt.moreNumfmtType`,Z=`sheet.numfmt.moreNumfmtType.options`;function me(e){let{value:n}=e,r=(0,o.useDependency)(t.LocaleService);return(0,d.jsx)(`span`,{className:`univer-text-sm`,children:n==null?r.t(`sheet.numfmt.general`):n})}function he(){let e=(0,o.useDependency)(t.ICommandService),n=(0,o.useDependency)(t.LocaleService),i=(0,o.useDependency)(o.ILayoutService),s=(0,o.useDependency)(r.SheetsNumfmtCellContentController),c=(0,o.useDependency)(a.SheetsSelectionsService),f=n=>{let a=c.getCurrentLastSelection();if(!a)return;let o=a.range,s=[];t.Range.foreach(o,(e,t)=>{n?s.push({row:e,col:t,pattern:n,type:(0,r.getPatternType)(n)}):s.push({row:e,col:t})}),e.executeCommand(r.SetNumfmtCommand.id,{values:s}),i.focus()},p=(0,u.useMemo)(()=>Y(r.localeCurrencySymbolMap.get(n.getCurrentLocale())),[n]),m=t=>{if(t===0)f(null);else if(t===p.length-1)e.executeCommand(S.id),i.focus();else{let e=p[t];e.pattern&&f(e.pattern)}};return(0,d.jsx)(`div`,{className:`univer-grid univer-gap-1 univer-p-1.5`,children:p.map((e,t)=>e===`|`?(0,d.jsx)(l.Separator,{},t):(0,d.jsxs)(`div`,{className:`univer-flex univer-h-7 univer-cursor-default univer-items-center univer-justify-between univer-gap-6 univer-rounded univer-px-2 univer-text-sm hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-700`,onClick:()=>m(t),children:[(0,d.jsx)(`span`,{children:n.t(e.label)}),(0,d.jsx)(`span`,{className:`univer-text-xs univer-text-gray-500 dark:!univer-text-gray-400`,children:e.pattern?(0,r.getPatternPreview)(e.pattern||``,1220,s.locale).result.trim():``})]},t))})}let ge={[o.RibbonStartGroup.LAYOUT]:{[S.id]:{order:9,menuItemFactory:pe},[r.SetPercentCommand.id]:{order:9.1,menuItemFactory:fe},[r.SetCurrencyCommand.id]:{order:9.2,menuItemFactory:le},[r.AddDecimalCommand.id]:{order:9.3,menuItemFactory:ue},[r.SubtractDecimalCommand.id]:{order:9.4,menuItemFactory:de}}},Q=class extends t.Disposable{constructor(e,t){super(),this._componentManager=e,this._menuManagerService=t,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(ge),[[X,me],[Z,he]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};Q=_([g(0,(0,t.Inject)(o.ComponentManager)),g(1,o.IMenuManagerService)],Q);let $=class extends t.Plugin{constructor(e=h,n,r,i){super(),this._config=e,this._injector=n,this._configService=r,this._renderManagerService=i;let{menu:a,...o}=(0,t.merge)({},h,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(`sheets-numfmt-ui.config`,o)}onStarting(){(0,t.registerDependencies)(this._injector,[[q],[J],[w],[Q],[b]])}onRendered(){this._registerRenderModules(),(0,t.touchDependencies)(this._injector,[[q],[J],[Q],[b]])}_registerRenderModules(){[[y]].forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(t.UniverInstanceType.UNIVER_SHEET,e))})}};G($,`pluginName`,`SHEET_NUMFMT_UI_PLUGIN`),G($,`packageName`,p),G($,`version`,m),G($,`type`,t.UniverInstanceType.UNIVER_SHEET),$=_([(0,t.DependentOn)(i.UniverSheetsUIPlugin,r.UniverSheetsNumfmtPlugin),g(1,(0,t.Inject)(t.Injector)),g(2,t.IConfigService),g(3,n.IRenderManagerService)],$),Object.defineProperty(e,`UniverSheetsNumfmtUIPlugin`,{enumerable:!0,get:function(){return $}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-numfmt-ui",
3
- "version": "0.18.0",
3
+ "version": "0.19.0-insiders.20260403-3e0e122",
4
4
  "private": false,
5
5
  "description": "UniverSheet numfmt plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -55,23 +55,23 @@
55
55
  },
56
56
  "dependencies": {
57
57
  "@univerjs/icons": "^1.1.1",
58
- "@univerjs/core": "0.18.0",
59
- "@univerjs/design": "0.18.0",
60
- "@univerjs/engine-render": "0.18.0",
61
- "@univerjs/engine-formula": "0.18.0",
62
- "@univerjs/sheets": "0.18.0",
63
- "@univerjs/sheets-ui": "0.18.0",
64
- "@univerjs/ui": "0.18.0",
65
- "@univerjs/sheets-numfmt": "0.18.0"
58
+ "@univerjs/core": "0.19.0-insiders.20260403-3e0e122",
59
+ "@univerjs/design": "0.19.0-insiders.20260403-3e0e122",
60
+ "@univerjs/engine-render": "0.19.0-insiders.20260403-3e0e122",
61
+ "@univerjs/sheets": "0.19.0-insiders.20260403-3e0e122",
62
+ "@univerjs/engine-formula": "0.19.0-insiders.20260403-3e0e122",
63
+ "@univerjs/sheets-numfmt": "0.19.0-insiders.20260403-3e0e122",
64
+ "@univerjs/sheets-ui": "0.19.0-insiders.20260403-3e0e122",
65
+ "@univerjs/ui": "0.19.0-insiders.20260403-3e0e122"
66
66
  },
67
67
  "devDependencies": {
68
68
  "postcss": "^8.5.8",
69
69
  "react": "18.3.1",
70
70
  "rxjs": "^7.8.2",
71
71
  "tailwindcss": "3.4.18",
72
- "typescript": "^5.9.3",
73
- "vitest": "^4.1.0",
74
- "@univerjs-infra/shared": "0.18.0"
72
+ "typescript": "^6.0.2",
73
+ "vitest": "^4.1.1",
74
+ "@univerjs-infra/shared": "0.19.0"
75
75
  },
76
76
  "scripts": {
77
77
  "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