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