@univerjs/sheets-numfmt-ui 0.20.1 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1609 -1
- package/lib/cjs/locale/ca-ES.js +40 -1
- package/lib/cjs/locale/en-US.js +55 -1
- package/lib/cjs/locale/es-ES.js +40 -1
- package/lib/cjs/locale/fa-IR.js +40 -1
- package/lib/cjs/locale/fr-FR.js +40 -1
- package/lib/cjs/locale/ja-JP.js +40 -1
- package/lib/cjs/locale/ko-KR.js +40 -1
- package/lib/cjs/locale/ru-RU.js +40 -1
- package/lib/cjs/locale/sk-SK.js +40 -1
- package/lib/cjs/locale/vi-VN.js +40 -1
- package/lib/cjs/locale/zh-CN.js +40 -1
- package/lib/cjs/locale/zh-TW.js +40 -1
- package/lib/es/index.js +1603 -1
- package/lib/es/locale/ca-ES.js +39 -1
- package/lib/es/locale/en-US.js +54 -1
- package/lib/es/locale/es-ES.js +39 -1
- package/lib/es/locale/fa-IR.js +39 -1
- package/lib/es/locale/fr-FR.js +39 -1
- package/lib/es/locale/ja-JP.js +39 -1
- package/lib/es/locale/ko-KR.js +39 -1
- package/lib/es/locale/ru-RU.js +39 -1
- package/lib/es/locale/sk-SK.js +39 -1
- package/lib/es/locale/vi-VN.js +39 -1
- package/lib/es/locale/zh-CN.js +39 -1
- package/lib/es/locale/zh-TW.js +39 -1
- package/lib/index.js +1603 -1
- package/lib/locale/ca-ES.js +39 -1
- package/lib/locale/en-US.js +54 -1
- package/lib/locale/es-ES.js +39 -1
- package/lib/locale/fa-IR.js +39 -1
- package/lib/locale/fr-FR.js +39 -1
- package/lib/locale/ja-JP.js +39 -1
- package/lib/locale/ko-KR.js +39 -1
- package/lib/locale/ru-RU.js +39 -1
- package/lib/locale/sk-SK.js +39 -1
- package/lib/locale/vi-VN.js +39 -1
- package/lib/locale/zh-CN.js +39 -1
- package/lib/locale/zh-TW.js +39 -1
- package/lib/types/controllers/numfmt-repeat-last-action-controller.d.ts +2 -2
- package/lib/umd/index.js +1 -1
- package/package.json +12 -12
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1,1609 @@
|
|
|
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.20.1`;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 $}});
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _univerjs_core = require("@univerjs/core");
|
|
3
|
+
let _univerjs_engine_render = require("@univerjs/engine-render");
|
|
4
|
+
let _univerjs_sheets_numfmt = require("@univerjs/sheets-numfmt");
|
|
5
|
+
let _univerjs_sheets_ui = require("@univerjs/sheets-ui");
|
|
6
|
+
let _univerjs_sheets = require("@univerjs/sheets");
|
|
7
|
+
let _univerjs_ui = require("@univerjs/ui");
|
|
8
|
+
let rxjs = require("rxjs");
|
|
9
|
+
let rxjs_operators = require("rxjs/operators");
|
|
10
|
+
let _univerjs_design = require("@univerjs/design");
|
|
11
|
+
let react = require("react");
|
|
12
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
13
|
+
let _univerjs_icons = require("@univerjs/icons");
|
|
14
|
+
let _univerjs_engine_formula = require("@univerjs/engine-formula");
|
|
15
|
+
|
|
16
|
+
//#region package.json
|
|
17
|
+
var name = "@univerjs/sheets-numfmt-ui";
|
|
18
|
+
var version = "0.21.0";
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
//#region src/config/config.ts
|
|
22
|
+
const SHEETS_NUMFMT_UI_PLUGIN_CONFIG_KEY = "sheets-numfmt-ui.config";
|
|
23
|
+
const configSymbol = Symbol(SHEETS_NUMFMT_UI_PLUGIN_CONFIG_KEY);
|
|
24
|
+
const defaultPluginConfig = {};
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
|
|
28
|
+
function __decorateParam(paramIndex, decorator) {
|
|
29
|
+
return function(target, key) {
|
|
30
|
+
decorator(target, key, paramIndex);
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
|
|
36
|
+
function __decorate(decorators, target, key, desc) {
|
|
37
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
38
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
39
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
40
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/controllers/numfmt-alert-render.controller.ts
|
|
45
|
+
const ALERT_KEY = "SHEET_NUMFMT_ALERT";
|
|
46
|
+
let NumfmtAlertRenderController = class NumfmtAlertRenderController extends _univerjs_core.Disposable {
|
|
47
|
+
constructor(_context, _hoverManagerService, _cellAlertManagerService, _localeService, _zenZoneService, _numfmtService, _configService) {
|
|
48
|
+
super();
|
|
49
|
+
this._context = _context;
|
|
50
|
+
this._hoverManagerService = _hoverManagerService;
|
|
51
|
+
this._cellAlertManagerService = _cellAlertManagerService;
|
|
52
|
+
this._localeService = _localeService;
|
|
53
|
+
this._zenZoneService = _zenZoneService;
|
|
54
|
+
this._numfmtService = _numfmtService;
|
|
55
|
+
this._configService = _configService;
|
|
56
|
+
this._init();
|
|
57
|
+
}
|
|
58
|
+
_init() {
|
|
59
|
+
this._initCellAlertPopup();
|
|
60
|
+
this._initZenService();
|
|
61
|
+
}
|
|
62
|
+
_initCellAlertPopup() {
|
|
63
|
+
this.disposeWithMe(this._hoverManagerService.currentCell$.pipe((0, rxjs.debounceTime)(100)).subscribe((cellPos) => {
|
|
64
|
+
if (cellPos) {
|
|
65
|
+
const location = cellPos.location;
|
|
66
|
+
const workbook = this._context.unit;
|
|
67
|
+
const worksheet = workbook.getActiveSheet();
|
|
68
|
+
if (!worksheet) return this._hideAlert();
|
|
69
|
+
const unitId = location.unitId;
|
|
70
|
+
const sheetId = location.subUnitId;
|
|
71
|
+
let numfmtValue;
|
|
72
|
+
const cellData = worksheet.getCell(location.row, location.col);
|
|
73
|
+
if (cellData === null || cellData === void 0 ? void 0 : cellData.s) {
|
|
74
|
+
const style = workbook.getStyles().get(cellData.s);
|
|
75
|
+
if (style === null || style === void 0 ? void 0 : style.n) numfmtValue = style.n;
|
|
76
|
+
}
|
|
77
|
+
if (!numfmtValue) numfmtValue = this._numfmtService.getValue(unitId, sheetId, location.row, location.col);
|
|
78
|
+
if (!numfmtValue) {
|
|
79
|
+
this._hideAlert();
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if ((0, _univerjs_core.isTextFormat)(numfmtValue.pattern) && _univerjs_core.Tools.isDefine(cellData === null || cellData === void 0 ? void 0 : cellData.v) && (0, _univerjs_core.isRealNum)(cellData.v)) {
|
|
83
|
+
var _this$_configService$, _currentAlert$alert;
|
|
84
|
+
if ((_this$_configService$ = this._configService.getConfig(_univerjs_sheets_numfmt.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY)) === null || _this$_configService$ === void 0 ? void 0 : _this$_configService$.disableTextFormatAlert) return;
|
|
85
|
+
const currentAlert = this._cellAlertManagerService.currentAlert.get(ALERT_KEY);
|
|
86
|
+
const currentLoc = currentAlert === null || currentAlert === void 0 || (_currentAlert$alert = currentAlert.alert) === null || _currentAlert$alert === void 0 ? void 0 : _currentAlert$alert.location;
|
|
87
|
+
if (currentLoc && currentLoc.row === location.row && currentLoc.col === location.col && currentLoc.subUnitId === location.subUnitId && currentLoc.unitId === location.unitId) {
|
|
88
|
+
this._hideAlert();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
this._cellAlertManagerService.showAlert({
|
|
92
|
+
type: _univerjs_sheets_ui.CellAlertType.ERROR,
|
|
93
|
+
title: this._localeService.t("info.error"),
|
|
94
|
+
message: this._localeService.t("info.forceStringInfo"),
|
|
95
|
+
location,
|
|
96
|
+
width: 200,
|
|
97
|
+
height: 74,
|
|
98
|
+
key: ALERT_KEY
|
|
99
|
+
});
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
this._hideAlert();
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
_initZenService() {
|
|
107
|
+
this.disposeWithMe(this._zenZoneService.visible$.subscribe((visible) => {
|
|
108
|
+
if (visible) this._hideAlert();
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
_hideAlert() {
|
|
112
|
+
this._cellAlertManagerService.removeAlert(ALERT_KEY);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
NumfmtAlertRenderController = __decorate([
|
|
116
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.HoverManagerService)),
|
|
117
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.CellAlertManagerService)),
|
|
118
|
+
__decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
|
|
119
|
+
__decorateParam(4, _univerjs_ui.IZenZoneService),
|
|
120
|
+
__decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_sheets.INumfmtService)),
|
|
121
|
+
__decorateParam(6, _univerjs_core.IConfigService)
|
|
122
|
+
], NumfmtAlertRenderController);
|
|
123
|
+
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region src/controllers/numfmt-repeat-last-action-controller.ts
|
|
126
|
+
let NumfmtRepeatLastActionController = class NumfmtRepeatLastActionController extends _univerjs_core.Disposable {
|
|
127
|
+
constructor(_repeatLastActionService) {
|
|
128
|
+
super();
|
|
129
|
+
this._repeatLastActionService = _repeatLastActionService;
|
|
130
|
+
this._initCommandRecording();
|
|
131
|
+
}
|
|
132
|
+
_initCommandRecording() {
|
|
133
|
+
if (!this._repeatLastActionService) return;
|
|
134
|
+
const handler = (selections, params) => {
|
|
135
|
+
if (!params) return;
|
|
136
|
+
const { values } = params;
|
|
137
|
+
const numfmtCell = values.find((cell) => cell.pattern);
|
|
138
|
+
if (!numfmtCell) return;
|
|
139
|
+
const { pattern, type } = numfmtCell;
|
|
140
|
+
const newValues = [];
|
|
141
|
+
const cache = /* @__PURE__ */ new Set();
|
|
142
|
+
for (const selection of selections) {
|
|
143
|
+
const { startRow, startColumn, endRow, endColumn } = selection;
|
|
144
|
+
for (let row = startRow; row <= endRow; row++) for (let col = startColumn; col <= endColumn; col++) {
|
|
145
|
+
const key = `${row}-${col}`;
|
|
146
|
+
if (cache.has(key)) continue;
|
|
147
|
+
cache.add(key);
|
|
148
|
+
newValues.push({
|
|
149
|
+
row,
|
|
150
|
+
col,
|
|
151
|
+
pattern,
|
|
152
|
+
type
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
...params,
|
|
158
|
+
values: newValues
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
this.disposeWithMe(this._repeatLastActionService.registerRepeatableCommand(_univerjs_sheets_numfmt.SetNumfmtCommand.id, handler, _univerjs_sheets_ui.RepeatLastActionPermission.CellStyle));
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
NumfmtRepeatLastActionController = __decorate([__decorateParam(0, (0, _univerjs_core.Optional)(_univerjs_sheets_ui.IRepeatLastActionService))], NumfmtRepeatLastActionController);
|
|
165
|
+
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region src/commands/operations/close.numfmt.panel.operation.ts
|
|
168
|
+
const CloseNumfmtPanelOperator = {
|
|
169
|
+
id: "sheet.operation.close.numfmt.panel",
|
|
170
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
171
|
+
handler: () => true
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region src/commands/operations/open.numfmt.panel.operation.ts
|
|
176
|
+
const OpenNumfmtPanelOperator = {
|
|
177
|
+
id: "sheet.operation.open.numfmt.panel",
|
|
178
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
179
|
+
handler: (accessor) => {
|
|
180
|
+
accessor.get(SheetNumfmtUIController).openPanel();
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region src/controllers/user-habit.controller.ts
|
|
187
|
+
/**
|
|
188
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
189
|
+
*
|
|
190
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
191
|
+
* you may not use this file except in compliance with the License.
|
|
192
|
+
* You may obtain a copy of the License at
|
|
193
|
+
*
|
|
194
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
195
|
+
*
|
|
196
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
197
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
198
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
199
|
+
* See the License for the specific language governing permissions and
|
|
200
|
+
* limitations under the License.
|
|
201
|
+
*/
|
|
202
|
+
const UserHabitCurrencyContext = (0, react.createContext)([]);
|
|
203
|
+
let UserHabitController = class UserHabitController {
|
|
204
|
+
constructor(_localStorageService) {
|
|
205
|
+
this._localStorageService = _localStorageService;
|
|
206
|
+
}
|
|
207
|
+
_getKey(habit) {
|
|
208
|
+
return `userHabitController_${habit}`;
|
|
209
|
+
}
|
|
210
|
+
async addHabit(habit, initValue) {
|
|
211
|
+
const key = this._getKey(habit);
|
|
212
|
+
return this._localStorageService.getItem(key).then((item) => {
|
|
213
|
+
if (!item) this._localStorageService.setItem(key, initValue);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
markHabit(habit, value) {
|
|
217
|
+
const key = this._getKey(habit);
|
|
218
|
+
this._localStorageService.getItem(key).then((list) => {
|
|
219
|
+
if (list) {
|
|
220
|
+
const index = list.findIndex((item) => item === value);
|
|
221
|
+
index > -1 && list.splice(index, 1);
|
|
222
|
+
list.unshift(value);
|
|
223
|
+
this._localStorageService.setItem(key, list);
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
async getHabit(habit, sortList) {
|
|
228
|
+
const key = this._getKey(habit);
|
|
229
|
+
const result = await this._localStorageService.getItem(key);
|
|
230
|
+
if (sortList && result) {
|
|
231
|
+
const priority = result.map((item, index, arr) => {
|
|
232
|
+
return {
|
|
233
|
+
value: item,
|
|
234
|
+
priority: arr.length - index
|
|
235
|
+
};
|
|
236
|
+
});
|
|
237
|
+
return sortList.sort((a, b) => {
|
|
238
|
+
var _priority$find, _priority$find2;
|
|
239
|
+
const ap = ((_priority$find = priority.find((item) => item.value === a)) === null || _priority$find === void 0 ? void 0 : _priority$find.priority) || -1;
|
|
240
|
+
return (((_priority$find2 = priority.find((item) => item.value === b)) === null || _priority$find2 === void 0 ? void 0 : _priority$find2.priority) || -1) - ap;
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
return result || [];
|
|
244
|
+
}
|
|
245
|
+
deleteHabit(habit) {
|
|
246
|
+
this._localStorageService.removeItem(habit);
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
UserHabitController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.ILocalStorageService))], UserHabitController);
|
|
250
|
+
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/views/hooks/use-currency-options.ts
|
|
253
|
+
/**
|
|
254
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
255
|
+
*
|
|
256
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
257
|
+
* you may not use this file except in compliance with the License.
|
|
258
|
+
* You may obtain a copy of the License at
|
|
259
|
+
*
|
|
260
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
261
|
+
*
|
|
262
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
263
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
264
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
265
|
+
* See the License for the specific language governing permissions and
|
|
266
|
+
* limitations under the License.
|
|
267
|
+
*/
|
|
268
|
+
const key$1 = "numfmtCurrency";
|
|
269
|
+
const useCurrencyOptions = (onOptionChange) => {
|
|
270
|
+
const userHabitController = (0, _univerjs_ui.useDependency)(UserHabitController);
|
|
271
|
+
const [options, setOptions] = (0, react.useState)(_univerjs_sheets_numfmt.currencySymbols);
|
|
272
|
+
(0, react.useEffect)(() => {
|
|
273
|
+
userHabitController.addHabit("numfmtCurrency", []).then(() => {
|
|
274
|
+
userHabitController.getHabit(key$1, [..._univerjs_sheets_numfmt.currencySymbols]).then((list) => {
|
|
275
|
+
setOptions(list);
|
|
276
|
+
onOptionChange && onOptionChange(list);
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
}, []);
|
|
280
|
+
const mark = (v) => {
|
|
281
|
+
userHabitController.markHabit(key$1, v);
|
|
282
|
+
};
|
|
283
|
+
return {
|
|
284
|
+
userHabitCurrency: options,
|
|
285
|
+
mark
|
|
286
|
+
};
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
//#endregion
|
|
290
|
+
//#region src/views/hooks/use-next-tick.ts
|
|
291
|
+
/**
|
|
292
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
293
|
+
*
|
|
294
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
295
|
+
* you may not use this file except in compliance with the License.
|
|
296
|
+
* You may obtain a copy of the License at
|
|
297
|
+
*
|
|
298
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
299
|
+
*
|
|
300
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
301
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
302
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
303
|
+
* See the License for the specific language governing permissions and
|
|
304
|
+
* limitations under the License.
|
|
305
|
+
*/
|
|
306
|
+
const useNextTick = () => {
|
|
307
|
+
const effectList = (0, react.useRef)([]);
|
|
308
|
+
const [value, dispatch] = (0, react.useState)({});
|
|
309
|
+
(0, react.useEffect)(() => {
|
|
310
|
+
effectList.current.forEach((fn) => {
|
|
311
|
+
fn();
|
|
312
|
+
});
|
|
313
|
+
effectList.current = [];
|
|
314
|
+
}, [value]);
|
|
315
|
+
const nextTick = (fn) => {
|
|
316
|
+
effectList.current.push(fn);
|
|
317
|
+
dispatch({});
|
|
318
|
+
};
|
|
319
|
+
return nextTick;
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
//#endregion
|
|
323
|
+
//#region src/views/components/Accounting.tsx
|
|
324
|
+
const isAccountingPanel = (pattern) => {
|
|
325
|
+
return !!(0, _univerjs_sheets_numfmt.getCurrencyType)(pattern) && pattern.startsWith("_(");
|
|
326
|
+
};
|
|
327
|
+
const AccountingPanel = (props) => {
|
|
328
|
+
const { defaultPattern, action, onChange } = props;
|
|
329
|
+
const [decimal, setDecimal] = (0, react.useState)(() => (0, _univerjs_sheets_numfmt.getDecimalFromPattern)(defaultPattern || "", 2));
|
|
330
|
+
const userHabitCurrency = (0, react.useContext)(UserHabitCurrencyContext);
|
|
331
|
+
const [suffix, setSuffix] = (0, react.useState)(() => (0, _univerjs_sheets_numfmt.getCurrencyType)(defaultPattern) || userHabitCurrency[0]);
|
|
332
|
+
const options = (0, react.useMemo)(() => userHabitCurrency.map((key) => ({
|
|
333
|
+
label: key,
|
|
334
|
+
value: key
|
|
335
|
+
})), []);
|
|
336
|
+
const t = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService).t;
|
|
337
|
+
action.current = () => (0, _univerjs_sheets_numfmt.setPatternDecimal)(`_("${suffix}"* #,##0${decimal > 0 ? ".0" : ""}_)`, decimal);
|
|
338
|
+
const handleSelect = (v) => {
|
|
339
|
+
setSuffix(v);
|
|
340
|
+
onChange((0, _univerjs_sheets_numfmt.setPatternDecimal)(`_("${v}"* #,##0${decimal > 0 ? ".0" : ""}_)`, decimal));
|
|
341
|
+
};
|
|
342
|
+
const handleDecimalChange = (v) => {
|
|
343
|
+
const decimal = v || 0;
|
|
344
|
+
setDecimal(decimal);
|
|
345
|
+
onChange((0, _univerjs_sheets_numfmt.setPatternDecimal)(`_("${suffix}"* #,##0${decimal > 0 ? ".0" : ""}_)`, decimal));
|
|
346
|
+
};
|
|
347
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
348
|
+
className: "univer-mt-4 univer-flex univer-justify-between",
|
|
349
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
350
|
+
className: "option",
|
|
351
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
352
|
+
className: "univer-text-sm univer-text-gray-400",
|
|
353
|
+
children: t("sheet.numfmt.decimalLength")
|
|
354
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
355
|
+
className: "univer-mt-2 univer-w-32",
|
|
356
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
|
|
357
|
+
value: decimal,
|
|
358
|
+
step: 1,
|
|
359
|
+
precision: 0,
|
|
360
|
+
max: 20,
|
|
361
|
+
min: 0,
|
|
362
|
+
onChange: handleDecimalChange
|
|
363
|
+
})
|
|
364
|
+
})]
|
|
365
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
366
|
+
className: "option",
|
|
367
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
368
|
+
className: "univer-text-sm univer-text-gray-400",
|
|
369
|
+
children: t("sheet.numfmt.currencyType")
|
|
370
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
371
|
+
className: "univer-mt-2 univer-w-36",
|
|
372
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Select, {
|
|
373
|
+
options,
|
|
374
|
+
value: suffix,
|
|
375
|
+
onChange: handleSelect
|
|
376
|
+
})
|
|
377
|
+
})]
|
|
378
|
+
})]
|
|
379
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
380
|
+
className: "univer-mt-4 univer-text-sm univer-text-gray-400",
|
|
381
|
+
children: t("sheet.numfmt.accountingDes")
|
|
382
|
+
})] });
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
//#endregion
|
|
386
|
+
//#region src/views/components/Currency.tsx
|
|
387
|
+
const isCurrencyPanel = (pattern) => {
|
|
388
|
+
return !!(0, _univerjs_sheets_numfmt.getCurrencyType)(pattern) && !pattern.startsWith("_(");
|
|
389
|
+
};
|
|
390
|
+
const CurrencyPanel = (props) => {
|
|
391
|
+
const t = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService).t;
|
|
392
|
+
const userHabitCurrency = (0, react.useContext)(UserHabitCurrencyContext);
|
|
393
|
+
const [suffix, setSuffix] = (0, react.useState)(() => (0, _univerjs_sheets_numfmt.getCurrencyType)(props.defaultPattern) || userHabitCurrency[0]);
|
|
394
|
+
const [decimal, setDecimal] = (0, react.useState)(() => (0, _univerjs_sheets_numfmt.getDecimalFromPattern)(props.defaultPattern || "", 2));
|
|
395
|
+
const [pattern, setPattern] = (0, react.useState)(() => {
|
|
396
|
+
var _negativeOptions$find;
|
|
397
|
+
const negativeOptions = (0, _univerjs_sheets_numfmt.getCurrencyFormatOptions)(suffix);
|
|
398
|
+
return ((_negativeOptions$find = negativeOptions.find((item) => (0, _univerjs_core.isPatternEqualWithoutDecimal)(item.value, props.defaultPattern))) === null || _negativeOptions$find === void 0 ? void 0 : _negativeOptions$find.value) || negativeOptions[0].value;
|
|
399
|
+
});
|
|
400
|
+
const negativeOptions = (0, react.useMemo)(() => (0, _univerjs_sheets_numfmt.getCurrencyFormatOptions)(suffix), [suffix]);
|
|
401
|
+
const options = (0, react.useMemo)(() => userHabitCurrency.map((key) => ({
|
|
402
|
+
label: key,
|
|
403
|
+
value: key
|
|
404
|
+
})), [userHabitCurrency]);
|
|
405
|
+
props.action.current = () => (0, _univerjs_sheets_numfmt.setPatternDecimal)(pattern, decimal);
|
|
406
|
+
const onSelect = (value) => {
|
|
407
|
+
if (value === void 0) return;
|
|
408
|
+
setSuffix(value);
|
|
409
|
+
const pattern = (0, _univerjs_sheets_numfmt.getCurrencyFormatOptions)(value)[0].value;
|
|
410
|
+
setPattern(pattern);
|
|
411
|
+
props.onChange((0, _univerjs_sheets_numfmt.setPatternDecimal)(pattern, decimal));
|
|
412
|
+
};
|
|
413
|
+
const onChange = (value) => {
|
|
414
|
+
if (value === void 0) return;
|
|
415
|
+
setPattern(value);
|
|
416
|
+
props.onChange((0, _univerjs_sheets_numfmt.setPatternDecimal)(value, decimal));
|
|
417
|
+
};
|
|
418
|
+
const onDecimalChange = (v) => {
|
|
419
|
+
setDecimal(v || 0);
|
|
420
|
+
props.onChange((0, _univerjs_sheets_numfmt.setPatternDecimal)(pattern, v || 0));
|
|
421
|
+
};
|
|
422
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [
|
|
423
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
424
|
+
className: "univer-mt-4 univer-flex univer-justify-between",
|
|
425
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
426
|
+
className: "option",
|
|
427
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
428
|
+
className: "univer-text-sm univer-text-gray-400",
|
|
429
|
+
children: t("sheet.numfmt.decimalLength")
|
|
430
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
431
|
+
className: "univer-mt-2 univer-w-32",
|
|
432
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
|
|
433
|
+
value: decimal,
|
|
434
|
+
max: 20,
|
|
435
|
+
min: 0,
|
|
436
|
+
onChange: onDecimalChange
|
|
437
|
+
})
|
|
438
|
+
})]
|
|
439
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
440
|
+
className: "option",
|
|
441
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
442
|
+
className: "univer-text-sm univer-text-gray-400",
|
|
443
|
+
children: t("sheet.numfmt.currencyType")
|
|
444
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
445
|
+
className: "univer-mt-2 univer-w-36",
|
|
446
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Select, {
|
|
447
|
+
value: suffix,
|
|
448
|
+
options,
|
|
449
|
+
onChange: onSelect
|
|
450
|
+
})
|
|
451
|
+
})]
|
|
452
|
+
})]
|
|
453
|
+
}),
|
|
454
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
455
|
+
className: "label univer-mt-4",
|
|
456
|
+
children: t("sheet.numfmt.negType")
|
|
457
|
+
}),
|
|
458
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
459
|
+
className: "univer-mt-2",
|
|
460
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.SelectList, {
|
|
461
|
+
value: pattern,
|
|
462
|
+
options: negativeOptions,
|
|
463
|
+
onChange
|
|
464
|
+
})
|
|
465
|
+
}),
|
|
466
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
467
|
+
className: "univer-mt-4 univer-text-sm univer-text-gray-400",
|
|
468
|
+
children: t("sheet.numfmt.currencyDes")
|
|
469
|
+
})
|
|
470
|
+
] });
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
//#endregion
|
|
474
|
+
//#region src/views/components/CustomFormat.tsx
|
|
475
|
+
const key = "customFormat";
|
|
476
|
+
const historyPatternKey = "numfmt_custom_pattern";
|
|
477
|
+
function CustomFormat(props) {
|
|
478
|
+
const { defaultPattern, action, onChange } = props;
|
|
479
|
+
const userHabitController = (0, _univerjs_ui.useDependency)(UserHabitController);
|
|
480
|
+
const localStorageService = (0, _univerjs_ui.useDependency)(_univerjs_core.ILocalStorageService);
|
|
481
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
482
|
+
const [pattern, setPattern] = (0, react.useState)(defaultPattern);
|
|
483
|
+
action.current = () => {
|
|
484
|
+
userHabitController.markHabit(key, pattern);
|
|
485
|
+
localStorageService.getItem(historyPatternKey).then((list = []) => {
|
|
486
|
+
const _list = [...new Set([pattern, ...list || []])].splice(0, 10).filter((e) => !!e);
|
|
487
|
+
localStorageService.setItem(historyPatternKey, _list);
|
|
488
|
+
});
|
|
489
|
+
return pattern;
|
|
490
|
+
};
|
|
491
|
+
const [options, setOptions] = (0, react.useState)([]);
|
|
492
|
+
(0, react.useEffect)(() => {
|
|
493
|
+
localStorageService.getItem(historyPatternKey).then((historyList) => {
|
|
494
|
+
const list = [
|
|
495
|
+
..._univerjs_sheets_numfmt.CURRENCYFORMAT.map((item) => item.suffix("$")),
|
|
496
|
+
..._univerjs_sheets_numfmt.DATEFMTLISG.map((item) => item.suffix),
|
|
497
|
+
..._univerjs_sheets_numfmt.NUMBERFORMAT.map((item) => item.suffix)
|
|
498
|
+
];
|
|
499
|
+
list.push(...historyList || []);
|
|
500
|
+
userHabitController.addHabit(key, []).finally(() => {
|
|
501
|
+
userHabitController.getHabit(key, list).then((list) => {
|
|
502
|
+
setOptions([...new Set(list)]);
|
|
503
|
+
});
|
|
504
|
+
});
|
|
505
|
+
});
|
|
506
|
+
}, []);
|
|
507
|
+
const handleClick = (p) => {
|
|
508
|
+
setPattern(p);
|
|
509
|
+
onChange(p);
|
|
510
|
+
};
|
|
511
|
+
const handleBlur = () => {
|
|
512
|
+
onChange(pattern);
|
|
513
|
+
};
|
|
514
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [
|
|
515
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
516
|
+
className: "univer-mt-4 univer-text-sm univer-text-gray-400",
|
|
517
|
+
children: localeService.t("sheet.numfmt.customFormat")
|
|
518
|
+
}),
|
|
519
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
|
|
520
|
+
placeholder: localeService.t("sheet.numfmt.customFormat"),
|
|
521
|
+
onBlur: handleBlur,
|
|
522
|
+
value: pattern,
|
|
523
|
+
onChange: setPattern,
|
|
524
|
+
className: "univer-mt-2 univer-w-full"
|
|
525
|
+
}),
|
|
526
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
527
|
+
className: (0, _univerjs_design.clsx)("univer-mt-2 univer-max-h-[400px] univer-overflow-auto univer-rounded-lg univer-p-2", _univerjs_design.borderClassName),
|
|
528
|
+
children: options.map((p) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
529
|
+
onClick: () => handleClick(p),
|
|
530
|
+
className: "univer-flex univer-cursor-pointer univer-items-center univer-gap-1.5 univer-py-1.5 univer-text-sm",
|
|
531
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
532
|
+
className: "univer-flex univer-w-4 univer-items-center univer-text-primary-600",
|
|
533
|
+
children: pattern === p && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CheckMarkIcon, {})
|
|
534
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: p })]
|
|
535
|
+
}, p))
|
|
536
|
+
}),
|
|
537
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
538
|
+
className: "univer-mt-3 univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200",
|
|
539
|
+
children: localeService.t("sheet.numfmt.customFormatDes")
|
|
540
|
+
})
|
|
541
|
+
] });
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
//#endregion
|
|
545
|
+
//#region src/views/components/Date.tsx
|
|
546
|
+
const isDatePanel = (pattern) => {
|
|
547
|
+
const info = _univerjs_core.numfmt.getFormatInfo(pattern);
|
|
548
|
+
return (0, _univerjs_sheets_numfmt.getDateFormatOptions)().map((item) => item.value).includes(pattern) || [
|
|
549
|
+
"date",
|
|
550
|
+
"datetime",
|
|
551
|
+
"time"
|
|
552
|
+
].includes(info.type);
|
|
553
|
+
};
|
|
554
|
+
function DatePanel(props) {
|
|
555
|
+
const { onChange, defaultPattern } = props;
|
|
556
|
+
const options = (0, react.useMemo)(_univerjs_sheets_numfmt.getDateFormatOptions, []);
|
|
557
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
558
|
+
const [suffix, setSuffix] = (0, react.useState)(() => {
|
|
559
|
+
if (defaultPattern) {
|
|
560
|
+
const item = options.find((item) => item.value === defaultPattern);
|
|
561
|
+
if (item) return item.value;
|
|
562
|
+
}
|
|
563
|
+
return options[0].value;
|
|
564
|
+
});
|
|
565
|
+
props.action.current = () => suffix;
|
|
566
|
+
const handleChange = (v) => {
|
|
567
|
+
if (v === void 0) return;
|
|
568
|
+
setSuffix(v);
|
|
569
|
+
onChange(v);
|
|
570
|
+
};
|
|
571
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [
|
|
572
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
573
|
+
className: "univer-mt-4 univer-text-sm univer-text-gray-400",
|
|
574
|
+
children: localeService.t("sheet.numfmt.dateType")
|
|
575
|
+
}),
|
|
576
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
577
|
+
className: "univer-mt-2",
|
|
578
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.SelectList, {
|
|
579
|
+
value: suffix,
|
|
580
|
+
options,
|
|
581
|
+
onChange: handleChange
|
|
582
|
+
})
|
|
583
|
+
}),
|
|
584
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
585
|
+
className: "univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",
|
|
586
|
+
children: localeService.t("sheet.numfmt.dateDes")
|
|
587
|
+
})
|
|
588
|
+
] });
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
//#endregion
|
|
592
|
+
//#region src/views/components/General.tsx
|
|
593
|
+
const isGeneralPanel = (pattern) => !pattern;
|
|
594
|
+
const GeneralPanel = (props) => {
|
|
595
|
+
const t = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService).t;
|
|
596
|
+
props.action.current = () => "";
|
|
597
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
598
|
+
className: "univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",
|
|
599
|
+
children: t("sheet.numfmt.generalDes")
|
|
600
|
+
}) });
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
//#endregion
|
|
604
|
+
//#region src/views/components/ThousandthPercentile.tsx
|
|
605
|
+
const isThousandthPercentilePanel = (pattern) => (0, _univerjs_sheets_numfmt.getNumberFormatOptions)().some((item) => (0, _univerjs_core.isPatternEqualWithoutDecimal)(item.value, pattern));
|
|
606
|
+
function ThousandthPercentilePanel(props) {
|
|
607
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
608
|
+
const options = (0, react.useMemo)(_univerjs_sheets_numfmt.getNumberFormatOptions, []);
|
|
609
|
+
const [decimal, setDecimal] = (0, react.useState)(() => (0, _univerjs_sheets_numfmt.getDecimalFromPattern)(props.defaultPattern || "", 0));
|
|
610
|
+
const [suffix, setSuffix] = (0, react.useState)(() => {
|
|
611
|
+
const item = options.find((item) => (0, _univerjs_core.isPatternEqualWithoutDecimal)(item.value, props.defaultPattern || ""));
|
|
612
|
+
return (item === null || item === void 0 ? void 0 : item.value) || options[0].value;
|
|
613
|
+
});
|
|
614
|
+
const pattern = (0, react.useMemo)(() => (0, _univerjs_sheets_numfmt.setPatternDecimal)(suffix, Number(decimal || 0)), [suffix, decimal]);
|
|
615
|
+
const isInputDisable = (0, react.useMemo)(() => !(0, _univerjs_sheets_numfmt.isPatternHasDecimal)(suffix), [suffix]);
|
|
616
|
+
const handleDecimalChange = (decimal) => {
|
|
617
|
+
setDecimal(decimal || 0);
|
|
618
|
+
props.onChange((0, _univerjs_sheets_numfmt.setPatternDecimal)(suffix, Number(decimal || 0)));
|
|
619
|
+
};
|
|
620
|
+
const handleClick = (v) => {
|
|
621
|
+
if (v === void 0) return;
|
|
622
|
+
setDecimal((0, _univerjs_sheets_numfmt.getDecimalFromPattern)(v, 0));
|
|
623
|
+
setSuffix(v);
|
|
624
|
+
props.onChange(v);
|
|
625
|
+
};
|
|
626
|
+
props.action.current = () => pattern;
|
|
627
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [
|
|
628
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
629
|
+
className: "univer-mt-4 univer-text-sm univer-text-gray-400",
|
|
630
|
+
children: localeService.t("sheet.numfmt.decimalLength")
|
|
631
|
+
}),
|
|
632
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
633
|
+
className: "univer-mt-2",
|
|
634
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
|
|
635
|
+
disabled: isInputDisable,
|
|
636
|
+
value: decimal,
|
|
637
|
+
max: 20,
|
|
638
|
+
min: 0,
|
|
639
|
+
onChange: handleDecimalChange
|
|
640
|
+
})
|
|
641
|
+
}),
|
|
642
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
643
|
+
className: "univer-mt-4 univer-text-sm univer-text-gray-400",
|
|
644
|
+
children: [" ", localeService.t("sheet.numfmt.negType")]
|
|
645
|
+
}),
|
|
646
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
647
|
+
className: "univer-mt-2",
|
|
648
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.SelectList, {
|
|
649
|
+
onChange: handleClick,
|
|
650
|
+
options,
|
|
651
|
+
value: suffix
|
|
652
|
+
})
|
|
653
|
+
}),
|
|
654
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
655
|
+
className: "univer-mt-3.5 univer-text-sm/5 univer-text-gray-600 dark:!univer-text-gray-200",
|
|
656
|
+
children: localeService.t("sheet.numfmt.thousandthPercentileDes")
|
|
657
|
+
})
|
|
658
|
+
] });
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
//#endregion
|
|
662
|
+
//#region src/views/components/index.tsx
|
|
663
|
+
const SheetNumfmtPanel = (props) => {
|
|
664
|
+
const { defaultValue, defaultPattern, row, col } = props.value;
|
|
665
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
666
|
+
const getCurrentPattern = (0, react.useRef)(() => "");
|
|
667
|
+
const t = localeService.t;
|
|
668
|
+
const nextTick = useNextTick();
|
|
669
|
+
const typeOptions = (0, react.useMemo)(() => [
|
|
670
|
+
{
|
|
671
|
+
label: "sheet.numfmt.general",
|
|
672
|
+
component: GeneralPanel
|
|
673
|
+
},
|
|
674
|
+
{
|
|
675
|
+
label: "sheet.numfmt.accounting",
|
|
676
|
+
component: AccountingPanel
|
|
677
|
+
},
|
|
678
|
+
{
|
|
679
|
+
label: "sheet.numfmt.currency",
|
|
680
|
+
component: CurrencyPanel
|
|
681
|
+
},
|
|
682
|
+
{
|
|
683
|
+
label: "sheet.numfmt.date",
|
|
684
|
+
component: DatePanel
|
|
685
|
+
},
|
|
686
|
+
{
|
|
687
|
+
label: "sheet.numfmt.thousandthPercentile",
|
|
688
|
+
component: ThousandthPercentilePanel
|
|
689
|
+
},
|
|
690
|
+
{
|
|
691
|
+
label: "sheet.numfmt.customFormat",
|
|
692
|
+
component: CustomFormat
|
|
693
|
+
}
|
|
694
|
+
].map((item) => ({
|
|
695
|
+
...item,
|
|
696
|
+
label: t(item.label)
|
|
697
|
+
})), []);
|
|
698
|
+
const [type, setType] = (0, react.useState)(findDefaultType);
|
|
699
|
+
const [key, setKey] = (0, react.useState)(() => `${row}_${col}`);
|
|
700
|
+
const { mark, userHabitCurrency } = useCurrencyOptions(() => setKey(`${row}_${col}_userCurrency'`));
|
|
701
|
+
const BusinessComponent = (0, react.useMemo)(() => {
|
|
702
|
+
var _typeOptions$find;
|
|
703
|
+
return (_typeOptions$find = typeOptions.find((item) => item.label === type)) === null || _typeOptions$find === void 0 ? void 0 : _typeOptions$find.component;
|
|
704
|
+
}, [type]);
|
|
705
|
+
function findDefaultType() {
|
|
706
|
+
return [
|
|
707
|
+
isGeneralPanel,
|
|
708
|
+
isAccountingPanel,
|
|
709
|
+
isCurrencyPanel,
|
|
710
|
+
isDatePanel,
|
|
711
|
+
isThousandthPercentilePanel
|
|
712
|
+
].reduce((pre, curFn, index) => pre || (curFn(defaultPattern) ? typeOptions[index].label : ""), "") || typeOptions[0].label;
|
|
713
|
+
}
|
|
714
|
+
const selectOptions = typeOptions.map((option) => ({
|
|
715
|
+
label: option.label,
|
|
716
|
+
value: option.label
|
|
717
|
+
}));
|
|
718
|
+
const handleSelect = (value) => {
|
|
719
|
+
setType(value);
|
|
720
|
+
nextTick(() => props.onChange({
|
|
721
|
+
type: "change",
|
|
722
|
+
value: getCurrentPattern.current() || ""
|
|
723
|
+
}));
|
|
724
|
+
};
|
|
725
|
+
const handleChange = (0, react.useCallback)((v) => {
|
|
726
|
+
props.onChange({
|
|
727
|
+
type: "change",
|
|
728
|
+
value: v
|
|
729
|
+
});
|
|
730
|
+
}, []);
|
|
731
|
+
const handleConfirm = () => {
|
|
732
|
+
const pattern = getCurrentPattern.current() || "";
|
|
733
|
+
const currency = (0, _univerjs_sheets_numfmt.getCurrencyType)(pattern);
|
|
734
|
+
if (currency) mark(currency);
|
|
735
|
+
props.onChange({
|
|
736
|
+
type: "confirm",
|
|
737
|
+
value: pattern
|
|
738
|
+
});
|
|
739
|
+
};
|
|
740
|
+
const handleCancel = () => {
|
|
741
|
+
props.onChange({
|
|
742
|
+
type: "cancel",
|
|
743
|
+
value: ""
|
|
744
|
+
});
|
|
745
|
+
};
|
|
746
|
+
const subProps = {
|
|
747
|
+
onChange: handleChange,
|
|
748
|
+
defaultValue,
|
|
749
|
+
defaultPattern,
|
|
750
|
+
action: getCurrentPattern
|
|
751
|
+
};
|
|
752
|
+
(0, react.useEffect)(() => {
|
|
753
|
+
setType(findDefaultType());
|
|
754
|
+
setKey(`${row}_${col}`);
|
|
755
|
+
}, [row, col]);
|
|
756
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
757
|
+
className: (0, _univerjs_design.clsx)("univer-flex univer-h-full univer-flex-col univer-justify-between univer-overflow-y-auto univer-pb-5", _univerjs_design.scrollbarClassName),
|
|
758
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [
|
|
759
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
760
|
+
className: "univer-mt-3.5 univer-text-sm univer-text-gray-400",
|
|
761
|
+
children: t("sheet.numfmt.numfmtType")
|
|
762
|
+
}),
|
|
763
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
764
|
+
className: "univer-mt-2",
|
|
765
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Select, {
|
|
766
|
+
className: "univer-w-full",
|
|
767
|
+
value: type,
|
|
768
|
+
options: selectOptions,
|
|
769
|
+
onChange: handleSelect
|
|
770
|
+
})
|
|
771
|
+
}),
|
|
772
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: BusinessComponent && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(UserHabitCurrencyContext.Provider, {
|
|
773
|
+
value: userHabitCurrency,
|
|
774
|
+
children: /* @__PURE__ */ (0, react.createElement)(BusinessComponent, {
|
|
775
|
+
...subProps,
|
|
776
|
+
key
|
|
777
|
+
})
|
|
778
|
+
}) })
|
|
779
|
+
] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
780
|
+
className: "univer-mb-5 univer-mt-3.5 univer-flex univer-justify-end",
|
|
781
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
|
|
782
|
+
onClick: handleCancel,
|
|
783
|
+
className: "univer-mr-3",
|
|
784
|
+
children: t("sheet.numfmt.cancel")
|
|
785
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
|
|
786
|
+
variant: "primary",
|
|
787
|
+
onClick: handleConfirm,
|
|
788
|
+
children: t("sheet.numfmt.confirm")
|
|
789
|
+
})]
|
|
790
|
+
})]
|
|
791
|
+
});
|
|
792
|
+
};
|
|
793
|
+
|
|
794
|
+
//#endregion
|
|
795
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
|
|
796
|
+
function _typeof(o) {
|
|
797
|
+
"@babel/helpers - typeof";
|
|
798
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
799
|
+
return typeof o;
|
|
800
|
+
} : function(o) {
|
|
801
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
802
|
+
}, _typeof(o);
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
//#endregion
|
|
806
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
|
|
807
|
+
function toPrimitive(t, r) {
|
|
808
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
809
|
+
var e = t[Symbol.toPrimitive];
|
|
810
|
+
if (void 0 !== e) {
|
|
811
|
+
var i = e.call(t, r || "default");
|
|
812
|
+
if ("object" != _typeof(i)) return i;
|
|
813
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
814
|
+
}
|
|
815
|
+
return ("string" === r ? String : Number)(t);
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
//#endregion
|
|
819
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
|
|
820
|
+
function toPropertyKey(t) {
|
|
821
|
+
var i = toPrimitive(t, "string");
|
|
822
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
//#endregion
|
|
826
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
|
|
827
|
+
function _defineProperty(e, r, t) {
|
|
828
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
829
|
+
value: t,
|
|
830
|
+
enumerable: !0,
|
|
831
|
+
configurable: !0,
|
|
832
|
+
writable: !0
|
|
833
|
+
}) : e[r] = t, e;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
//#endregion
|
|
837
|
+
//#region src/controllers/numfmt.controller.ts
|
|
838
|
+
const SHEET_NUMFMT_PANEL = "SHEET_NUMFMT_PANEL";
|
|
839
|
+
let SheetNumfmtUIController = class SheetNumfmtUIController extends _univerjs_core.Disposable {
|
|
840
|
+
constructor(_sheetInterceptorService, _themeService, _univerInstanceService, _commandService, _selectionManagerService, _renderManagerService, _numfmtService, _componentManager, _sidebarService, _localeService, _sheetsNumfmtCellContentController) {
|
|
841
|
+
super();
|
|
842
|
+
this._sheetInterceptorService = _sheetInterceptorService;
|
|
843
|
+
this._themeService = _themeService;
|
|
844
|
+
this._univerInstanceService = _univerInstanceService;
|
|
845
|
+
this._commandService = _commandService;
|
|
846
|
+
this._selectionManagerService = _selectionManagerService;
|
|
847
|
+
this._renderManagerService = _renderManagerService;
|
|
848
|
+
this._numfmtService = _numfmtService;
|
|
849
|
+
this._componentManager = _componentManager;
|
|
850
|
+
this._sidebarService = _sidebarService;
|
|
851
|
+
this._localeService = _localeService;
|
|
852
|
+
this._sheetsNumfmtCellContentController = _sheetsNumfmtCellContentController;
|
|
853
|
+
_defineProperty(this, "_previewPattern", "");
|
|
854
|
+
_defineProperty(this, "_sidebarDisposable", null);
|
|
855
|
+
this._initRealTimeRenderingInterceptor();
|
|
856
|
+
this._initPanel();
|
|
857
|
+
this._initCommands();
|
|
858
|
+
this._initCloseListener();
|
|
859
|
+
this._commandExecutedListener();
|
|
860
|
+
this._initNumfmtLocalChange();
|
|
861
|
+
}
|
|
862
|
+
_initNumfmtLocalChange() {
|
|
863
|
+
this.disposeWithMe((0, rxjs.merge)(this._sheetsNumfmtCellContentController.locale$, this._localeService.currentLocale$).subscribe(() => {
|
|
864
|
+
this._forceUpdate();
|
|
865
|
+
}));
|
|
866
|
+
}
|
|
867
|
+
openPanel() {
|
|
868
|
+
var _selectionManagerServ;
|
|
869
|
+
const sidebarService = this._sidebarService;
|
|
870
|
+
const selectionManagerService = this._selectionManagerService;
|
|
871
|
+
const commandService = this._commandService;
|
|
872
|
+
const univerInstanceService = this._univerInstanceService;
|
|
873
|
+
const numfmtService = this._numfmtService;
|
|
874
|
+
const localeService = this._localeService;
|
|
875
|
+
const range = (((_selectionManagerServ = selectionManagerService.getCurrentSelections()) === null || _selectionManagerServ === void 0 ? void 0 : _selectionManagerServ.map((s) => s.range)) || [])[0];
|
|
876
|
+
if (!range) return false;
|
|
877
|
+
const workbook = univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
878
|
+
const sheet = workbook.getActiveSheet();
|
|
879
|
+
if (!sheet) return false;
|
|
880
|
+
const cellValue = sheet.getCellRaw(range.startRow, range.startColumn);
|
|
881
|
+
const numfmtValue = numfmtService.getValue(workbook.getUnitId(), sheet.getSheetId(), range.startRow, range.startColumn);
|
|
882
|
+
let pattern = "";
|
|
883
|
+
if (numfmtValue) pattern = numfmtValue.pattern;
|
|
884
|
+
const defaultValue = (cellValue === null || cellValue === void 0 ? void 0 : cellValue.t) === _univerjs_core.CellValueType.NUMBER ? cellValue.v : 12345678;
|
|
885
|
+
const props = {
|
|
886
|
+
onChange: (config) => {
|
|
887
|
+
if (config.type === "change") {
|
|
888
|
+
this._previewPattern = config.value;
|
|
889
|
+
this._forceUpdate();
|
|
890
|
+
} else if (config.type === "confirm") {
|
|
891
|
+
var _selectionManagerServ2;
|
|
892
|
+
const selections = ((_selectionManagerServ2 = selectionManagerService.getCurrentSelections()) === null || _selectionManagerServ2 === void 0 ? void 0 : _selectionManagerServ2.map((s) => s.range)) || [];
|
|
893
|
+
const params = { values: [] };
|
|
894
|
+
const patternType = (0, _univerjs_sheets_numfmt.getPatternType)(config.value);
|
|
895
|
+
selections.forEach((rangeInfo) => {
|
|
896
|
+
_univerjs_core.Range.foreach(rangeInfo, (row, col) => {
|
|
897
|
+
params.values.push({
|
|
898
|
+
row,
|
|
899
|
+
col,
|
|
900
|
+
pattern: config.value,
|
|
901
|
+
type: patternType
|
|
902
|
+
});
|
|
903
|
+
});
|
|
904
|
+
});
|
|
905
|
+
commandService.executeCommand(_univerjs_sheets_numfmt.SetNumfmtCommand.id, params);
|
|
906
|
+
sidebarService.close();
|
|
907
|
+
} else if (config.type === "cancel") sidebarService.close();
|
|
908
|
+
},
|
|
909
|
+
value: {
|
|
910
|
+
defaultPattern: pattern,
|
|
911
|
+
defaultValue,
|
|
912
|
+
row: range.startRow,
|
|
913
|
+
col: range.startColumn
|
|
914
|
+
}
|
|
915
|
+
};
|
|
916
|
+
this._sidebarDisposable = sidebarService.open({
|
|
917
|
+
header: { title: localeService.t("sheet.numfmt.title") },
|
|
918
|
+
children: {
|
|
919
|
+
label: SHEET_NUMFMT_PANEL,
|
|
920
|
+
...props
|
|
921
|
+
},
|
|
922
|
+
onClose: () => {
|
|
923
|
+
this._forceUpdate();
|
|
924
|
+
commandService.executeCommand(CloseNumfmtPanelOperator.id);
|
|
925
|
+
}
|
|
926
|
+
});
|
|
927
|
+
return true;
|
|
928
|
+
}
|
|
929
|
+
_forceUpdate(unitId) {
|
|
930
|
+
var _renderUnit$mainCompo;
|
|
931
|
+
const renderUnit = this._renderManagerService.getRenderById(unitId !== null && unitId !== void 0 ? unitId : this._univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET).getUnitId());
|
|
932
|
+
renderUnit === null || renderUnit === void 0 || renderUnit.with(_univerjs_sheets_ui.SheetSkeletonManagerService).reCalculate();
|
|
933
|
+
renderUnit === null || renderUnit === void 0 || (_renderUnit$mainCompo = renderUnit.mainComponent) === null || _renderUnit$mainCompo === void 0 || _renderUnit$mainCompo.makeDirty();
|
|
934
|
+
}
|
|
935
|
+
_initCommands() {
|
|
936
|
+
[OpenNumfmtPanelOperator, CloseNumfmtPanelOperator].forEach((config) => {
|
|
937
|
+
this.disposeWithMe(this._commandService.registerCommand(config));
|
|
938
|
+
});
|
|
939
|
+
}
|
|
940
|
+
_initPanel() {
|
|
941
|
+
this.disposeWithMe(this._componentManager.register(SHEET_NUMFMT_PANEL, SheetNumfmtPanel));
|
|
942
|
+
}
|
|
943
|
+
_initRealTimeRenderingInterceptor() {
|
|
944
|
+
const combineOpenAndSelection$ = (0, rxjs.combineLatest)([new rxjs.Observable((subscriber) => {
|
|
945
|
+
this._commandService.onCommandExecuted((commandInfo) => {
|
|
946
|
+
if (commandInfo.id === OpenNumfmtPanelOperator.id) subscriber.next(true);
|
|
947
|
+
if (commandInfo.id === CloseNumfmtPanelOperator.id) subscriber.next(false);
|
|
948
|
+
});
|
|
949
|
+
}), this._selectionManagerService.selectionMoveEnd$.pipe((0, rxjs_operators.map)((selectionInfos) => {
|
|
950
|
+
if (!selectionInfos) return [];
|
|
951
|
+
return selectionInfos.map((selectionInfo) => selectionInfo.range);
|
|
952
|
+
}))]);
|
|
953
|
+
this.disposeWithMe((0, _univerjs_core.toDisposable)(combineOpenAndSelection$.pipe((0, rxjs_operators.switchMap)(([isOpen, selectionRanges]) => new rxjs.Observable((subscribe) => {
|
|
954
|
+
const disposableCollection = new _univerjs_core.DisposableCollection();
|
|
955
|
+
isOpen && selectionRanges.length && subscribe.next({
|
|
956
|
+
selectionRanges,
|
|
957
|
+
disposableCollection
|
|
958
|
+
});
|
|
959
|
+
return () => {
|
|
960
|
+
disposableCollection.dispose();
|
|
961
|
+
};
|
|
962
|
+
})), (0, rxjs_operators.tap)(() => {
|
|
963
|
+
this._previewPattern = null;
|
|
964
|
+
})).subscribe(({ disposableCollection, selectionRanges }) => {
|
|
965
|
+
var _this$_renderManagerS;
|
|
966
|
+
const workbook = this._univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
967
|
+
this.openPanel();
|
|
968
|
+
disposableCollection.add(this._sheetInterceptorService.intercept(_univerjs_sheets.INTERCEPTOR_POINT.CELL_CONTENT, {
|
|
969
|
+
priority: 99,
|
|
970
|
+
effect: _univerjs_core.InterceptorEffectEnum.Value | _univerjs_core.InterceptorEffectEnum.Style,
|
|
971
|
+
handler: (cell, location, next) => {
|
|
972
|
+
const { row, col } = location;
|
|
973
|
+
const defaultValue = next(cell) || {};
|
|
974
|
+
if (selectionRanges.find((range) => range.startColumn <= col && range.endColumn >= col && range.startRow <= row && range.endRow >= row)) {
|
|
975
|
+
const rawValue = location.worksheet.getCellRaw(row, col);
|
|
976
|
+
const value = rawValue === null || rawValue === void 0 ? void 0 : rawValue.v;
|
|
977
|
+
const type = rawValue === null || rawValue === void 0 ? void 0 : rawValue.t;
|
|
978
|
+
if (value === void 0 || value === null || type !== _univerjs_core.CellValueType.NUMBER || this._previewPattern === null) return defaultValue;
|
|
979
|
+
const info = (0, _univerjs_sheets_numfmt.getPatternPreviewIgnoreGeneral)(this._previewPattern, value, this._sheetsNumfmtCellContentController.locale);
|
|
980
|
+
if (info.color) {
|
|
981
|
+
var _this$_themeService$g;
|
|
982
|
+
const color = (_this$_themeService$g = this._themeService.getColorFromTheme(`${info.color}.500`)) !== null && _this$_themeService$g !== void 0 ? _this$_themeService$g : info.color;
|
|
983
|
+
return {
|
|
984
|
+
...defaultValue,
|
|
985
|
+
v: info.result,
|
|
986
|
+
t: _univerjs_core.CellValueType.STRING,
|
|
987
|
+
s: { cl: { rgb: color } }
|
|
988
|
+
};
|
|
989
|
+
}
|
|
990
|
+
return {
|
|
991
|
+
...defaultValue,
|
|
992
|
+
v: info.result,
|
|
993
|
+
t: _univerjs_core.CellValueType.STRING
|
|
994
|
+
};
|
|
995
|
+
}
|
|
996
|
+
return defaultValue;
|
|
997
|
+
}
|
|
998
|
+
}));
|
|
999
|
+
(_this$_renderManagerS = this._renderManagerService.getRenderById(workbook.getUnitId())) === null || _this$_renderManagerS === void 0 || (_this$_renderManagerS = _this$_renderManagerS.mainComponent) === null || _this$_renderManagerS === void 0 || _this$_renderManagerS.makeDirty();
|
|
1000
|
+
})));
|
|
1001
|
+
}
|
|
1002
|
+
_commandExecutedListener() {
|
|
1003
|
+
const commandList = [_univerjs_sheets.RemoveNumfmtMutation.id, _univerjs_sheets.SetNumfmtMutation.id];
|
|
1004
|
+
this.disposeWithMe(new rxjs.Observable((subscribe) => {
|
|
1005
|
+
const disposable = this._commandService.onCommandExecuted((command) => {
|
|
1006
|
+
if (commandList.includes(command.id)) {
|
|
1007
|
+
const params = command.params;
|
|
1008
|
+
subscribe.next(params.unitId);
|
|
1009
|
+
}
|
|
1010
|
+
});
|
|
1011
|
+
return () => disposable.dispose();
|
|
1012
|
+
}).pipe((0, rxjs_operators.debounceTime)(16)).subscribe((unitId) => this._forceUpdate(unitId)));
|
|
1013
|
+
}
|
|
1014
|
+
_initCloseListener() {
|
|
1015
|
+
this._univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).subscribe((unit) => {
|
|
1016
|
+
if (!unit) {
|
|
1017
|
+
var _this$_sidebarDisposa;
|
|
1018
|
+
(_this$_sidebarDisposa = this._sidebarDisposable) === null || _this$_sidebarDisposa === void 0 || _this$_sidebarDisposa.dispose();
|
|
1019
|
+
this._sidebarDisposable = null;
|
|
1020
|
+
}
|
|
1021
|
+
});
|
|
1022
|
+
}
|
|
1023
|
+
};
|
|
1024
|
+
SheetNumfmtUIController = __decorate([
|
|
1025
|
+
__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
|
|
1026
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.ThemeService)),
|
|
1027
|
+
__decorateParam(2, _univerjs_core.IUniverInstanceService),
|
|
1028
|
+
__decorateParam(3, _univerjs_core.ICommandService),
|
|
1029
|
+
__decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetsSelectionsService)),
|
|
1030
|
+
__decorateParam(5, _univerjs_engine_render.IRenderManagerService),
|
|
1031
|
+
__decorateParam(6, _univerjs_sheets.INumfmtService),
|
|
1032
|
+
__decorateParam(7, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)),
|
|
1033
|
+
__decorateParam(8, _univerjs_ui.ISidebarService),
|
|
1034
|
+
__decorateParam(9, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
|
|
1035
|
+
__decorateParam(10, (0, _univerjs_core.Inject)(_univerjs_sheets_numfmt.SheetsNumfmtCellContentController))
|
|
1036
|
+
], SheetNumfmtUIController);
|
|
1037
|
+
|
|
1038
|
+
//#endregion
|
|
1039
|
+
//#region src/controllers/numfmt.editor.controller.ts
|
|
1040
|
+
const createCollectEffectMutation = () => {
|
|
1041
|
+
let list = [];
|
|
1042
|
+
const add = (unitId, subUnitId, row, col, value) => list.push({
|
|
1043
|
+
unitId,
|
|
1044
|
+
subUnitId,
|
|
1045
|
+
row,
|
|
1046
|
+
col,
|
|
1047
|
+
value
|
|
1048
|
+
});
|
|
1049
|
+
const getEffects = () => list;
|
|
1050
|
+
const clean = () => {
|
|
1051
|
+
list = [];
|
|
1052
|
+
};
|
|
1053
|
+
return {
|
|
1054
|
+
add,
|
|
1055
|
+
getEffects,
|
|
1056
|
+
clean
|
|
1057
|
+
};
|
|
1058
|
+
};
|
|
1059
|
+
let NumfmtEditorController = class NumfmtEditorController extends _univerjs_core.Disposable {
|
|
1060
|
+
constructor(_sheetInterceptorService, _numfmtService, _univerInstanceService, _injector, _editorBridgeService) {
|
|
1061
|
+
super();
|
|
1062
|
+
this._sheetInterceptorService = _sheetInterceptorService;
|
|
1063
|
+
this._numfmtService = _numfmtService;
|
|
1064
|
+
this._univerInstanceService = _univerInstanceService;
|
|
1065
|
+
this._injector = _injector;
|
|
1066
|
+
this._editorBridgeService = _editorBridgeService;
|
|
1067
|
+
_defineProperty(this, "_collectEffectMutation", createCollectEffectMutation());
|
|
1068
|
+
this._initInterceptorEditorStart();
|
|
1069
|
+
this._initInterceptorEditorEnd();
|
|
1070
|
+
this._initInterceptorCommands();
|
|
1071
|
+
}
|
|
1072
|
+
_initInterceptorEditorStart() {
|
|
1073
|
+
if (!this._editorBridgeService) return;
|
|
1074
|
+
this.disposeWithMe((0, _univerjs_core.toDisposable)(this._sheetInterceptorService.writeCellInterceptor.intercept(_univerjs_sheets.BEFORE_CELL_EDIT, { handler: (value, context, next) => {
|
|
1075
|
+
/**
|
|
1076
|
+
* This value is get by `worksheet.getCell()`, it has been processed by cell content interceptor, and used to display in cell render, so it should be the final value after all the processing of number format.
|
|
1077
|
+
* But the editor has different requirement for different number format type, so we need to get the raw cell value and number format value to determine the final value for editor.
|
|
1078
|
+
*/
|
|
1079
|
+
const row = context.row;
|
|
1080
|
+
const col = context.col;
|
|
1081
|
+
const numfmtCell = this._numfmtService.getValue(context.unitId, context.subUnitId, row, col);
|
|
1082
|
+
if (numfmtCell) switch ((0, _univerjs_sheets_numfmt.getPatternType)(numfmtCell.pattern)) {
|
|
1083
|
+
/**
|
|
1084
|
+
* For scientific, currency, grouped and number format, the editor should display the raw number value without format, unlike the cell render which display the formatted value.
|
|
1085
|
+
*/
|
|
1086
|
+
case "scientific":
|
|
1087
|
+
case "currency":
|
|
1088
|
+
case "grouped":
|
|
1089
|
+
case "number": {
|
|
1090
|
+
const cell = { ...context.worksheet.getCellRaw(row, col) };
|
|
1091
|
+
if ((cell === null || cell === void 0 ? void 0 : cell.t) === _univerjs_core.CellValueType.NUMBER && (0, _univerjs_core.isRealNum)(cell.v)) cell.v = (0, _univerjs_engine_formula.stripErrorMargin)(Number(cell.v));
|
|
1092
|
+
return next && next(cell);
|
|
1093
|
+
}
|
|
1094
|
+
/**
|
|
1095
|
+
* For percent format, the editor should display the full percent value, unlike the cell render which display the limited decimal places.
|
|
1096
|
+
* e.g. { v: 1.001234567, t: 2, s: { n: { pattern: '0.00%' } } } should display as '100.12%' in cell render, but when edit this cell, the editor should display '100.1234567%' rather than '100.12%'.
|
|
1097
|
+
* If the editor also display '100.12%', will lose precision when before edit.
|
|
1098
|
+
*/
|
|
1099
|
+
case "percent": {
|
|
1100
|
+
const cell = { ...context.worksheet.getCellRaw(row, col) };
|
|
1101
|
+
if ((cell === null || cell === void 0 ? void 0 : cell.t) === _univerjs_core.CellValueType.NUMBER && (0, _univerjs_core.isRealNum)(cell.v)) cell.v = `${(0, _univerjs_engine_formula.stripErrorMargin)(Number(cell.v) * 100)}%`;
|
|
1102
|
+
return next && next(cell);
|
|
1103
|
+
}
|
|
1104
|
+
default: return next && next(value);
|
|
1105
|
+
}
|
|
1106
|
+
return next(value);
|
|
1107
|
+
} })));
|
|
1108
|
+
}
|
|
1109
|
+
/**
|
|
1110
|
+
* Process the values after edit
|
|
1111
|
+
* @private
|
|
1112
|
+
* @memberof NumfmtService
|
|
1113
|
+
*/
|
|
1114
|
+
_initInterceptorEditorEnd() {
|
|
1115
|
+
this.disposeWithMe((0, _univerjs_core.toDisposable)(this._sheetInterceptorService.writeCellInterceptor.intercept(_univerjs_sheets.AFTER_CELL_EDIT, { handler: (value, context, next) => {
|
|
1116
|
+
var _value$p, _value$p2;
|
|
1117
|
+
if (!(value === null || value === void 0 ? void 0 : value.v) && !(value === null || value === void 0 ? void 0 : value.p)) return next(value);
|
|
1118
|
+
this._collectEffectMutation.clean();
|
|
1119
|
+
const currentNumfmtValue = this._numfmtService.getValue(context.unitId, context.subUnitId, context.row, context.col);
|
|
1120
|
+
const originCell = context.worksheet.getCellRaw(context.row, context.col);
|
|
1121
|
+
if ((0, _univerjs_core.isTextFormat)(currentNumfmtValue === null || currentNumfmtValue === void 0 ? void 0 : currentNumfmtValue.pattern) || value.t === _univerjs_core.CellValueType.FORCE_STRING) return next(value);
|
|
1122
|
+
const body = (_value$p = value.p) === null || _value$p === void 0 ? void 0 : _value$p.body;
|
|
1123
|
+
const content = (value === null || value === void 0 || (_value$p2 = value.p) === null || _value$p2 === void 0 || (_value$p2 = _value$p2.body) === null || _value$p2 === void 0 ? void 0 : _value$p2.dataStream) ? value.p.body.dataStream.replace(/\r\n$/, "") : String(value.v);
|
|
1124
|
+
const numfmtInfo = (0, _univerjs_core.getNumfmtParseValueFilter)(content);
|
|
1125
|
+
if (body) if (!canConvertRichTextToNumfmt(body)) return next(value);
|
|
1126
|
+
else {
|
|
1127
|
+
const { dataStream } = body;
|
|
1128
|
+
const dataStreamWithoutEnd = dataStream.replace(/\r\n$/, "");
|
|
1129
|
+
const num = Number(dataStreamWithoutEnd);
|
|
1130
|
+
if (Number.isNaN(num) && !numfmtInfo) return next(value);
|
|
1131
|
+
}
|
|
1132
|
+
if (numfmtInfo) {
|
|
1133
|
+
if (!numfmtInfo.z && !(currentNumfmtValue === null || currentNumfmtValue === void 0 ? void 0 : currentNumfmtValue.pattern) && (originCell === null || originCell === void 0 ? void 0 : originCell.t) !== _univerjs_core.CellValueType.STRING && (originCell === null || originCell === void 0 ? void 0 : originCell.t) !== _univerjs_core.CellValueType.FORCE_STRING && (0, _univerjs_core.willLoseNumericPrecision)(content)) return next({
|
|
1134
|
+
...value,
|
|
1135
|
+
p: void 0,
|
|
1136
|
+
v: content,
|
|
1137
|
+
t: _univerjs_core.CellValueType.FORCE_STRING
|
|
1138
|
+
});
|
|
1139
|
+
/**
|
|
1140
|
+
* Only when the content has number format pattern but the current cell has no pattern, or the pattern type is different, need to update the number format.
|
|
1141
|
+
* Different currency symbols also should not be updated in Excel.
|
|
1142
|
+
*/
|
|
1143
|
+
if (numfmtInfo.z && (!(currentNumfmtValue === null || currentNumfmtValue === void 0 ? void 0 : currentNumfmtValue.pattern) || (0, _univerjs_sheets_numfmt.getPatternType)(numfmtInfo.z) !== (0, _univerjs_sheets_numfmt.getPatternType)(currentNumfmtValue.pattern))) this._collectEffectMutation.add(context.unitId, context.subUnitId, context.row, context.col, { pattern: numfmtInfo.z });
|
|
1144
|
+
const v = (0, _univerjs_engine_formula.stripErrorMargin)(Number(numfmtInfo.v), 16);
|
|
1145
|
+
return next({
|
|
1146
|
+
...value,
|
|
1147
|
+
p: void 0,
|
|
1148
|
+
v,
|
|
1149
|
+
t: _univerjs_core.CellValueType.NUMBER
|
|
1150
|
+
});
|
|
1151
|
+
}
|
|
1152
|
+
return next(value);
|
|
1153
|
+
} })));
|
|
1154
|
+
}
|
|
1155
|
+
_initInterceptorCommands() {
|
|
1156
|
+
const self = this;
|
|
1157
|
+
this.disposeWithMe(this._sheetInterceptorService.interceptCommand({ getMutations(command) {
|
|
1158
|
+
switch (command.id) {
|
|
1159
|
+
case _univerjs_sheets.SetRangeValuesCommand.id: {
|
|
1160
|
+
var _workbook$getActiveSh;
|
|
1161
|
+
const workbook = self._univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
1162
|
+
const unitId = workbook.getUnitId();
|
|
1163
|
+
const subUnitId = (_workbook$getActiveSh = workbook.getActiveSheet()) === null || _workbook$getActiveSh === void 0 ? void 0 : _workbook$getActiveSh.getSheetId();
|
|
1164
|
+
if (!subUnitId) return {
|
|
1165
|
+
redos: [],
|
|
1166
|
+
undos: []
|
|
1167
|
+
};
|
|
1168
|
+
const list = self._collectEffectMutation.getEffects();
|
|
1169
|
+
self._collectEffectMutation.clean();
|
|
1170
|
+
if (!list.length) return {
|
|
1171
|
+
redos: [],
|
|
1172
|
+
undos: []
|
|
1173
|
+
};
|
|
1174
|
+
const cells = list.filter((item) => {
|
|
1175
|
+
var _item$value;
|
|
1176
|
+
return !!((_item$value = item.value) === null || _item$value === void 0 ? void 0 : _item$value.pattern);
|
|
1177
|
+
}).map((item) => ({
|
|
1178
|
+
row: item.row,
|
|
1179
|
+
col: item.col,
|
|
1180
|
+
pattern: item.value.pattern
|
|
1181
|
+
}));
|
|
1182
|
+
const removeCells = list.filter((item) => {
|
|
1183
|
+
var _item$value2;
|
|
1184
|
+
return !((_item$value2 = item.value) === null || _item$value2 === void 0 ? void 0 : _item$value2.pattern);
|
|
1185
|
+
}).map((item) => ({
|
|
1186
|
+
startRow: item.row,
|
|
1187
|
+
endColumn: item.col,
|
|
1188
|
+
startColumn: item.col,
|
|
1189
|
+
endRow: item.row
|
|
1190
|
+
}));
|
|
1191
|
+
const redos = [];
|
|
1192
|
+
const undos = [];
|
|
1193
|
+
if (cells.length) {
|
|
1194
|
+
const redo = {
|
|
1195
|
+
id: _univerjs_sheets.SetNumfmtMutation.id,
|
|
1196
|
+
params: (0, _univerjs_sheets.transformCellsToRange)(unitId, subUnitId, cells)
|
|
1197
|
+
};
|
|
1198
|
+
redos.push(redo);
|
|
1199
|
+
undos.push(...(0, _univerjs_sheets.factorySetNumfmtUndoMutation)(self._injector, redo.params));
|
|
1200
|
+
}
|
|
1201
|
+
if (removeCells.length) {
|
|
1202
|
+
const redo = {
|
|
1203
|
+
id: _univerjs_sheets.RemoveNumfmtMutation.id,
|
|
1204
|
+
params: {
|
|
1205
|
+
unitId,
|
|
1206
|
+
subUnitId,
|
|
1207
|
+
ranges: removeCells
|
|
1208
|
+
}
|
|
1209
|
+
};
|
|
1210
|
+
redos.push(redo);
|
|
1211
|
+
undos.push(...(0, _univerjs_sheets.factoryRemoveNumfmtUndoMutation)(self._injector, redo.params));
|
|
1212
|
+
}
|
|
1213
|
+
return {
|
|
1214
|
+
redos,
|
|
1215
|
+
undos: undos.reverse()
|
|
1216
|
+
};
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
return {
|
|
1220
|
+
redos: [],
|
|
1221
|
+
undos: []
|
|
1222
|
+
};
|
|
1223
|
+
} }));
|
|
1224
|
+
}
|
|
1225
|
+
dispose() {
|
|
1226
|
+
super.dispose();
|
|
1227
|
+
this._collectEffectMutation.clean();
|
|
1228
|
+
}
|
|
1229
|
+
};
|
|
1230
|
+
NumfmtEditorController = __decorate([
|
|
1231
|
+
__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
|
|
1232
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets.INumfmtService)),
|
|
1233
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_core.IUniverInstanceService)),
|
|
1234
|
+
__decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
|
|
1235
|
+
__decorateParam(4, (0, _univerjs_core.Optional)(_univerjs_sheets_ui.IEditorBridgeService))
|
|
1236
|
+
], NumfmtEditorController);
|
|
1237
|
+
function canConvertRichTextToNumfmt(body) {
|
|
1238
|
+
const { textRuns = [], paragraphs = [], customRanges, customBlocks = [] } = body;
|
|
1239
|
+
const richTextStyle = ["va"];
|
|
1240
|
+
return !(textRuns.some((textRun) => {
|
|
1241
|
+
return Boolean(textRun.ts && Object.keys(textRun.ts).some((property) => {
|
|
1242
|
+
return richTextStyle.includes(property);
|
|
1243
|
+
}));
|
|
1244
|
+
}) || paragraphs.some((paragraph) => paragraph.bullet) || paragraphs.length >= 2 || Boolean(customRanges === null || customRanges === void 0 ? void 0 : customRanges.length) || customBlocks.length > 0);
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
//#endregion
|
|
1248
|
+
//#region src/menu/menu.ts
|
|
1249
|
+
const MENU_OPTIONS = (currencySymbol) => {
|
|
1250
|
+
return [
|
|
1251
|
+
{
|
|
1252
|
+
label: "sheet.numfmt.general",
|
|
1253
|
+
pattern: null
|
|
1254
|
+
},
|
|
1255
|
+
{
|
|
1256
|
+
label: "sheet.numfmt.text",
|
|
1257
|
+
pattern: _univerjs_core.DEFAULT_TEXT_FORMAT_EXCEL
|
|
1258
|
+
},
|
|
1259
|
+
"|",
|
|
1260
|
+
{
|
|
1261
|
+
label: "sheet.numfmt.number",
|
|
1262
|
+
pattern: "0"
|
|
1263
|
+
},
|
|
1264
|
+
{
|
|
1265
|
+
label: "sheet.numfmt.percent",
|
|
1266
|
+
pattern: "0.00%"
|
|
1267
|
+
},
|
|
1268
|
+
{
|
|
1269
|
+
label: "sheet.numfmt.scientific",
|
|
1270
|
+
pattern: "0.00E+00"
|
|
1271
|
+
},
|
|
1272
|
+
"|",
|
|
1273
|
+
{
|
|
1274
|
+
label: "sheet.numfmt.accounting",
|
|
1275
|
+
pattern: `"${currencySymbol}" #,##0.00_);[Red]("${currencySymbol}"#,##0.00)`
|
|
1276
|
+
},
|
|
1277
|
+
{
|
|
1278
|
+
label: "sheet.numfmt.financialValue",
|
|
1279
|
+
pattern: "#,##0.00;[Red]#,##0.00"
|
|
1280
|
+
},
|
|
1281
|
+
{
|
|
1282
|
+
label: "sheet.numfmt.currency",
|
|
1283
|
+
pattern: `"${currencySymbol}"#,##0.00_);[Red]("${currencySymbol}"#,##0.00)`
|
|
1284
|
+
},
|
|
1285
|
+
{
|
|
1286
|
+
label: "sheet.numfmt.roundingCurrency",
|
|
1287
|
+
pattern: `"${currencySymbol}"#,##0;[Red]"${currencySymbol}"#,##0`
|
|
1288
|
+
},
|
|
1289
|
+
"|",
|
|
1290
|
+
{
|
|
1291
|
+
label: "sheet.numfmt.date",
|
|
1292
|
+
pattern: "yyyy-mm-dd;@"
|
|
1293
|
+
},
|
|
1294
|
+
{
|
|
1295
|
+
label: "sheet.numfmt.time",
|
|
1296
|
+
pattern: "am/pm h\":\"mm\":\"ss"
|
|
1297
|
+
},
|
|
1298
|
+
{
|
|
1299
|
+
label: "sheet.numfmt.dateTime",
|
|
1300
|
+
pattern: "yyyy-m-d am/pm h:mm"
|
|
1301
|
+
},
|
|
1302
|
+
{
|
|
1303
|
+
label: "sheet.numfmt.timeDuration",
|
|
1304
|
+
pattern: "h:mm:ss"
|
|
1305
|
+
},
|
|
1306
|
+
"|",
|
|
1307
|
+
{
|
|
1308
|
+
label: "sheet.numfmt.moreFmt",
|
|
1309
|
+
pattern: ""
|
|
1310
|
+
}
|
|
1311
|
+
];
|
|
1312
|
+
};
|
|
1313
|
+
const CurrencySymbolIconMenuItem = (accessor) => {
|
|
1314
|
+
return {
|
|
1315
|
+
icon: new rxjs.Observable((subscribe) => {
|
|
1316
|
+
const localeService = accessor.get(_univerjs_core.LocaleService);
|
|
1317
|
+
subscribe.next((0, _univerjs_sheets_numfmt.getCurrencySymbolIconByLocale)(localeService.getCurrentLocale()).icon);
|
|
1318
|
+
return localeService.localeChanged$.subscribe(() => {
|
|
1319
|
+
subscribe.next((0, _univerjs_sheets_numfmt.getCurrencySymbolIconByLocale)(localeService.getCurrentLocale()).icon);
|
|
1320
|
+
});
|
|
1321
|
+
}),
|
|
1322
|
+
id: _univerjs_sheets_numfmt.SetCurrencyCommand.id,
|
|
1323
|
+
title: "sheet.numfmt.currency",
|
|
1324
|
+
tooltip: "sheet.numfmt.currency",
|
|
1325
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
1326
|
+
hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET),
|
|
1327
|
+
disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
|
|
1328
|
+
workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
|
|
1329
|
+
worksheetTypes: [_univerjs_sheets.WorksheetEditPermission, _univerjs_sheets.WorksheetSetCellStylePermission],
|
|
1330
|
+
rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint]
|
|
1331
|
+
})
|
|
1332
|
+
};
|
|
1333
|
+
};
|
|
1334
|
+
const AddDecimalMenuItem = (accessor) => {
|
|
1335
|
+
return {
|
|
1336
|
+
icon: "AddDigitsIcon",
|
|
1337
|
+
id: _univerjs_sheets_numfmt.AddDecimalCommand.id,
|
|
1338
|
+
title: "sheet.numfmt.addDecimal",
|
|
1339
|
+
tooltip: "sheet.numfmt.addDecimal",
|
|
1340
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
1341
|
+
hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET),
|
|
1342
|
+
disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
|
|
1343
|
+
workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
|
|
1344
|
+
worksheetTypes: [_univerjs_sheets.WorksheetEditPermission, _univerjs_sheets.WorksheetSetCellStylePermission],
|
|
1345
|
+
rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint]
|
|
1346
|
+
})
|
|
1347
|
+
};
|
|
1348
|
+
};
|
|
1349
|
+
const SubtractDecimalMenuItem = (accessor) => {
|
|
1350
|
+
return {
|
|
1351
|
+
icon: "ReduceDigitsIcon",
|
|
1352
|
+
id: _univerjs_sheets_numfmt.SubtractDecimalCommand.id,
|
|
1353
|
+
title: "sheet.numfmt.subtractDecimal",
|
|
1354
|
+
tooltip: "sheet.numfmt.subtractDecimal",
|
|
1355
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
1356
|
+
hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET),
|
|
1357
|
+
disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
|
|
1358
|
+
workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
|
|
1359
|
+
worksheetTypes: [_univerjs_sheets.WorksheetEditPermission, _univerjs_sheets.WorksheetSetCellStylePermission],
|
|
1360
|
+
rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint]
|
|
1361
|
+
})
|
|
1362
|
+
};
|
|
1363
|
+
};
|
|
1364
|
+
const PercentMenuItem = (accessor) => {
|
|
1365
|
+
return {
|
|
1366
|
+
icon: "PercentIcon",
|
|
1367
|
+
id: _univerjs_sheets_numfmt.SetPercentCommand.id,
|
|
1368
|
+
title: "sheet.numfmt.percent",
|
|
1369
|
+
tooltip: "sheet.numfmt.percent",
|
|
1370
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
1371
|
+
hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET),
|
|
1372
|
+
disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
|
|
1373
|
+
workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
|
|
1374
|
+
worksheetTypes: [_univerjs_sheets.WorksheetEditPermission, _univerjs_sheets.WorksheetSetCellStylePermission],
|
|
1375
|
+
rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint]
|
|
1376
|
+
})
|
|
1377
|
+
};
|
|
1378
|
+
};
|
|
1379
|
+
const FactoryOtherMenuItem = (accessor) => {
|
|
1380
|
+
const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
1381
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
1382
|
+
const localeService = accessor.get(_univerjs_core.LocaleService);
|
|
1383
|
+
const selectionManagerService = accessor.get(_univerjs_sheets.SheetsSelectionsService);
|
|
1384
|
+
const commandList = [_univerjs_sheets.RemoveNumfmtMutation.id, _univerjs_sheets.SetNumfmtMutation.id];
|
|
1385
|
+
const value$ = (0, _univerjs_sheets_ui.deriveStateFromActiveSheet$)(univerInstanceService, "", ({ workbook, worksheet }) => new rxjs.Observable((subscribe) => (0, rxjs.merge)(selectionManagerService.selectionMoveEnd$, (0, _univerjs_core.fromCallback)(commandService.onCommandExecuted.bind(commandService)).pipe((0, rxjs.filter)(([commandInfo]) => commandList.includes(commandInfo.id)))).subscribe(() => {
|
|
1386
|
+
const selections = selectionManagerService.getCurrentSelections();
|
|
1387
|
+
if (selections && selections[0]) {
|
|
1388
|
+
var _workbook$getStyles$g, _worksheet$getCell;
|
|
1389
|
+
const range = selections[0].range;
|
|
1390
|
+
const row = range.startRow;
|
|
1391
|
+
const col = range.startColumn;
|
|
1392
|
+
const numfmtValue = (_workbook$getStyles$g = workbook.getStyles().get((_worksheet$getCell = worksheet.getCell(row, col)) === null || _worksheet$getCell === void 0 ? void 0 : _worksheet$getCell.s)) === null || _workbook$getStyles$g === void 0 ? void 0 : _workbook$getStyles$g.n;
|
|
1393
|
+
const pattern = numfmtValue === null || numfmtValue === void 0 ? void 0 : numfmtValue.pattern;
|
|
1394
|
+
const currencySymbol = (0, _univerjs_sheets_numfmt.getCurrencySymbolByLocale)(localeService.getCurrentLocale());
|
|
1395
|
+
let value = localeService.t("sheet.numfmt.general");
|
|
1396
|
+
if ((0, _univerjs_core.isDefaultFormat)(pattern)) {
|
|
1397
|
+
subscribe.next(value);
|
|
1398
|
+
return;
|
|
1399
|
+
}
|
|
1400
|
+
if (pattern) {
|
|
1401
|
+
const item = MENU_OPTIONS(currencySymbol).filter((item) => typeof item === "object" && item.pattern).find((item) => (0, _univerjs_core.isPatternEqualWithoutDecimal)(pattern, item.pattern));
|
|
1402
|
+
if (item && typeof item === "object" && item.pattern) value = localeService.t(item.label);
|
|
1403
|
+
else value = localeService.t("sheet.numfmt.moreFmt");
|
|
1404
|
+
}
|
|
1405
|
+
subscribe.next(value);
|
|
1406
|
+
}
|
|
1407
|
+
})));
|
|
1408
|
+
return {
|
|
1409
|
+
label: MORE_NUMFMT_TYPE_KEY,
|
|
1410
|
+
id: OpenNumfmtPanelOperator.id,
|
|
1411
|
+
tooltip: "sheet.numfmt.title",
|
|
1412
|
+
type: _univerjs_ui.MenuItemType.SELECTOR,
|
|
1413
|
+
slot: true,
|
|
1414
|
+
selections: [{ label: {
|
|
1415
|
+
name: OPTIONS_KEY,
|
|
1416
|
+
hoverable: false,
|
|
1417
|
+
selectable: false
|
|
1418
|
+
} }],
|
|
1419
|
+
value$,
|
|
1420
|
+
hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET),
|
|
1421
|
+
disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {
|
|
1422
|
+
workbookTypes: [_univerjs_sheets.WorkbookEditablePermission],
|
|
1423
|
+
worksheetTypes: [_univerjs_sheets.WorksheetSetCellStylePermission, _univerjs_sheets.WorksheetEditPermission],
|
|
1424
|
+
rangeTypes: [_univerjs_sheets.RangeProtectionPermissionEditPoint]
|
|
1425
|
+
})
|
|
1426
|
+
};
|
|
1427
|
+
};
|
|
1428
|
+
|
|
1429
|
+
//#endregion
|
|
1430
|
+
//#region src/views/components/MoreNumfmtType.tsx
|
|
1431
|
+
const MORE_NUMFMT_TYPE_KEY = "sheet.numfmt.moreNumfmtType";
|
|
1432
|
+
const OPTIONS_KEY = "sheet.numfmt.moreNumfmtType.options";
|
|
1433
|
+
function MoreNumfmtType(props) {
|
|
1434
|
+
const { value } = props;
|
|
1435
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
1436
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1437
|
+
className: "univer-text-sm",
|
|
1438
|
+
children: value !== null && value !== void 0 ? value : localeService.t("sheet.numfmt.general")
|
|
1439
|
+
});
|
|
1440
|
+
}
|
|
1441
|
+
function Options() {
|
|
1442
|
+
const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
|
|
1443
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
1444
|
+
const layoutService = (0, _univerjs_ui.useDependency)(_univerjs_ui.ILayoutService);
|
|
1445
|
+
const sheetsNumfmtCellContentController = (0, _univerjs_ui.useDependency)(_univerjs_sheets_numfmt.SheetsNumfmtCellContentController);
|
|
1446
|
+
const selectionManagerService = (0, _univerjs_ui.useDependency)(_univerjs_sheets.SheetsSelectionsService);
|
|
1447
|
+
const setNumfmt = (pattern) => {
|
|
1448
|
+
const selection = selectionManagerService.getCurrentLastSelection();
|
|
1449
|
+
if (!selection) return;
|
|
1450
|
+
const range = selection.range;
|
|
1451
|
+
const values = [];
|
|
1452
|
+
_univerjs_core.Range.foreach(range, (row, col) => {
|
|
1453
|
+
if (pattern) values.push({
|
|
1454
|
+
row,
|
|
1455
|
+
col,
|
|
1456
|
+
pattern,
|
|
1457
|
+
type: (0, _univerjs_sheets_numfmt.getPatternType)(pattern)
|
|
1458
|
+
});
|
|
1459
|
+
else values.push({
|
|
1460
|
+
row,
|
|
1461
|
+
col
|
|
1462
|
+
});
|
|
1463
|
+
});
|
|
1464
|
+
commandService.executeCommand(_univerjs_sheets_numfmt.SetNumfmtCommand.id, { values });
|
|
1465
|
+
layoutService.focus();
|
|
1466
|
+
};
|
|
1467
|
+
const menuOptions = (0, react.useMemo)(() => {
|
|
1468
|
+
return MENU_OPTIONS(_univerjs_sheets_numfmt.localeCurrencySymbolMap.get(localeService.getCurrentLocale()));
|
|
1469
|
+
}, [localeService]);
|
|
1470
|
+
const handleClick = (index) => {
|
|
1471
|
+
if (index === 0) setNumfmt(null);
|
|
1472
|
+
else if (index === menuOptions.length - 1) {
|
|
1473
|
+
commandService.executeCommand(OpenNumfmtPanelOperator.id);
|
|
1474
|
+
layoutService.focus();
|
|
1475
|
+
} else {
|
|
1476
|
+
const item = menuOptions[index];
|
|
1477
|
+
item.pattern && setNumfmt(item.pattern);
|
|
1478
|
+
}
|
|
1479
|
+
};
|
|
1480
|
+
const defaultValue = 1220;
|
|
1481
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1482
|
+
className: "univer-grid univer-gap-1 univer-p-1.5",
|
|
1483
|
+
children: menuOptions.map((item, index) => {
|
|
1484
|
+
if (item === "|") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Separator, {}, index);
|
|
1485
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1486
|
+
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",
|
|
1487
|
+
onClick: () => handleClick(index),
|
|
1488
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: localeService.t(item.label) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1489
|
+
className: "univer-text-xs univer-text-gray-500 dark:!univer-text-gray-400",
|
|
1490
|
+
children: item.pattern ? (0, _univerjs_sheets_numfmt.getPatternPreview)(item.pattern || "", defaultValue, sheetsNumfmtCellContentController.locale).result.trim() : ""
|
|
1491
|
+
})]
|
|
1492
|
+
}, index);
|
|
1493
|
+
})
|
|
1494
|
+
});
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
//#endregion
|
|
1498
|
+
//#region src/menu/schema.ts
|
|
1499
|
+
const menuSchema = { [_univerjs_ui.RibbonStartGroup.LAYOUT]: {
|
|
1500
|
+
[OpenNumfmtPanelOperator.id]: {
|
|
1501
|
+
order: 9,
|
|
1502
|
+
menuItemFactory: FactoryOtherMenuItem
|
|
1503
|
+
},
|
|
1504
|
+
[_univerjs_sheets_numfmt.SetPercentCommand.id]: {
|
|
1505
|
+
order: 9.1,
|
|
1506
|
+
menuItemFactory: PercentMenuItem
|
|
1507
|
+
},
|
|
1508
|
+
[_univerjs_sheets_numfmt.SetCurrencyCommand.id]: {
|
|
1509
|
+
order: 9.2,
|
|
1510
|
+
menuItemFactory: CurrencySymbolIconMenuItem
|
|
1511
|
+
},
|
|
1512
|
+
[_univerjs_sheets_numfmt.AddDecimalCommand.id]: {
|
|
1513
|
+
order: 9.3,
|
|
1514
|
+
menuItemFactory: AddDecimalMenuItem
|
|
1515
|
+
},
|
|
1516
|
+
[_univerjs_sheets_numfmt.SubtractDecimalCommand.id]: {
|
|
1517
|
+
order: 9.4,
|
|
1518
|
+
menuItemFactory: SubtractDecimalMenuItem
|
|
1519
|
+
}
|
|
1520
|
+
} };
|
|
1521
|
+
|
|
1522
|
+
//#endregion
|
|
1523
|
+
//#region src/menu/numfmt.menu.controller.ts
|
|
1524
|
+
/**
|
|
1525
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1526
|
+
*
|
|
1527
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1528
|
+
* you may not use this file except in compliance with the License.
|
|
1529
|
+
* You may obtain a copy of the License at
|
|
1530
|
+
*
|
|
1531
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1532
|
+
*
|
|
1533
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1534
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1535
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1536
|
+
* See the License for the specific language governing permissions and
|
|
1537
|
+
* limitations under the License.
|
|
1538
|
+
*/
|
|
1539
|
+
let NumfmtMenuController = class NumfmtMenuController extends _univerjs_core.Disposable {
|
|
1540
|
+
constructor(_componentManager, _menuManagerService) {
|
|
1541
|
+
super();
|
|
1542
|
+
this._componentManager = _componentManager;
|
|
1543
|
+
this._menuManagerService = _menuManagerService;
|
|
1544
|
+
this._initMenu();
|
|
1545
|
+
}
|
|
1546
|
+
_initMenu() {
|
|
1547
|
+
this._menuManagerService.mergeMenu(menuSchema);
|
|
1548
|
+
[[MORE_NUMFMT_TYPE_KEY, MoreNumfmtType], [OPTIONS_KEY, Options]].forEach(([key, comp]) => {
|
|
1549
|
+
this.disposeWithMe(this._componentManager.register(key, comp));
|
|
1550
|
+
});
|
|
1551
|
+
}
|
|
1552
|
+
};
|
|
1553
|
+
NumfmtMenuController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)), __decorateParam(1, _univerjs_ui.IMenuManagerService)], NumfmtMenuController);
|
|
1554
|
+
|
|
1555
|
+
//#endregion
|
|
1556
|
+
//#region src/plugin.ts
|
|
1557
|
+
let UniverSheetsNumfmtUIPlugin = class UniverSheetsNumfmtUIPlugin extends _univerjs_core.Plugin {
|
|
1558
|
+
constructor(_config = defaultPluginConfig, _injector, _configService, _renderManagerService) {
|
|
1559
|
+
super();
|
|
1560
|
+
this._config = _config;
|
|
1561
|
+
this._injector = _injector;
|
|
1562
|
+
this._configService = _configService;
|
|
1563
|
+
this._renderManagerService = _renderManagerService;
|
|
1564
|
+
const { menu, ...rest } = (0, _univerjs_core.merge)({}, defaultPluginConfig, this._config);
|
|
1565
|
+
if (menu) this._configService.setConfig("menu", menu, { merge: true });
|
|
1566
|
+
this._configService.setConfig("sheets-numfmt-ui.config", rest);
|
|
1567
|
+
}
|
|
1568
|
+
onStarting() {
|
|
1569
|
+
(0, _univerjs_core.registerDependencies)(this._injector, [
|
|
1570
|
+
[SheetNumfmtUIController],
|
|
1571
|
+
[NumfmtEditorController],
|
|
1572
|
+
[UserHabitController],
|
|
1573
|
+
[NumfmtMenuController],
|
|
1574
|
+
[NumfmtRepeatLastActionController]
|
|
1575
|
+
]);
|
|
1576
|
+
}
|
|
1577
|
+
onRendered() {
|
|
1578
|
+
this._registerRenderModules();
|
|
1579
|
+
(0, _univerjs_core.touchDependencies)(this._injector, [
|
|
1580
|
+
[SheetNumfmtUIController],
|
|
1581
|
+
[NumfmtEditorController],
|
|
1582
|
+
[NumfmtMenuController],
|
|
1583
|
+
[NumfmtRepeatLastActionController]
|
|
1584
|
+
]);
|
|
1585
|
+
}
|
|
1586
|
+
_registerRenderModules() {
|
|
1587
|
+
[[NumfmtAlertRenderController]].forEach((m) => {
|
|
1588
|
+
this.disposeWithMe(this._renderManagerService.registerRenderModule(_univerjs_core.UniverInstanceType.UNIVER_SHEET, m));
|
|
1589
|
+
});
|
|
1590
|
+
}
|
|
1591
|
+
};
|
|
1592
|
+
_defineProperty(UniverSheetsNumfmtUIPlugin, "pluginName", "SHEET_NUMFMT_UI_PLUGIN");
|
|
1593
|
+
_defineProperty(UniverSheetsNumfmtUIPlugin, "packageName", name);
|
|
1594
|
+
_defineProperty(UniverSheetsNumfmtUIPlugin, "version", version);
|
|
1595
|
+
_defineProperty(UniverSheetsNumfmtUIPlugin, "type", _univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
1596
|
+
UniverSheetsNumfmtUIPlugin = __decorate([
|
|
1597
|
+
(0, _univerjs_core.DependentOn)(_univerjs_sheets_ui.UniverSheetsUIPlugin, _univerjs_sheets_numfmt.UniverSheetsNumfmtPlugin),
|
|
1598
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
|
|
1599
|
+
__decorateParam(2, _univerjs_core.IConfigService),
|
|
1600
|
+
__decorateParam(3, _univerjs_engine_render.IRenderManagerService)
|
|
1601
|
+
], UniverSheetsNumfmtUIPlugin);
|
|
1602
|
+
|
|
1603
|
+
//#endregion
|
|
1604
|
+
Object.defineProperty(exports, 'UniverSheetsNumfmtUIPlugin', {
|
|
1605
|
+
enumerable: true,
|
|
1606
|
+
get: function () {
|
|
1607
|
+
return UniverSheetsNumfmtUIPlugin;
|
|
1608
|
+
}
|
|
1609
|
+
});
|