@univerjs/sheets-numfmt-ui 0.5.3 → 0.5.4
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 +2 -2
- package/lib/es/index.js +599 -523
- package/lib/types/controllers/numfmt-alert-render.controller.d.ts +20 -0
- package/lib/types/plugin.d.ts +4 -1
- package/lib/umd/index.js +2 -2
- package/package.json +14 -13
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Workbook, Disposable, LocaleService } from '@univerjs/core';
|
|
2
|
+
import { IRenderContext, IRenderModule } from '@univerjs/engine-render';
|
|
3
|
+
import { FormulaDataModel } from '@univerjs/engine-formula';
|
|
4
|
+
import { INumfmtService } from '@univerjs/sheets';
|
|
5
|
+
import { CellAlertManagerService, HoverManagerService } from '@univerjs/sheets-ui';
|
|
6
|
+
import { IZenZoneService } from '@univerjs/ui';
|
|
7
|
+
export declare class NumfmtAlertRenderController extends Disposable implements IRenderModule {
|
|
8
|
+
private readonly _context;
|
|
9
|
+
private readonly _hoverManagerService;
|
|
10
|
+
private readonly _cellAlertManagerService;
|
|
11
|
+
private readonly _localeService;
|
|
12
|
+
private readonly _formulaDataModel;
|
|
13
|
+
private readonly _zenZoneService;
|
|
14
|
+
private _numfmtService;
|
|
15
|
+
constructor(_context: IRenderContext<Workbook>, _hoverManagerService: HoverManagerService, _cellAlertManagerService: CellAlertManagerService, _localeService: LocaleService, _formulaDataModel: FormulaDataModel, _zenZoneService: IZenZoneService, _numfmtService: INumfmtService);
|
|
16
|
+
private _init;
|
|
17
|
+
private _initCellAlertPopup;
|
|
18
|
+
private _initZenService;
|
|
19
|
+
private _hideAlert;
|
|
20
|
+
}
|
package/lib/types/plugin.d.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { IUniverSheetsNumfmtUIConfig } from './controllers/config.schema';
|
|
2
2
|
import { IConfigService, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
|
|
3
|
+
import { IRenderManagerService } from '@univerjs/engine-render';
|
|
3
4
|
export declare const SHEET_NUMFMT_UI_PLUGIN = "SHEET_NUMFMT_UI_PLUGIN";
|
|
4
5
|
export declare class UniverSheetsNumfmtUIPlugin extends Plugin {
|
|
5
6
|
private readonly _config;
|
|
6
7
|
readonly _injector: Injector;
|
|
7
8
|
private readonly _configService;
|
|
9
|
+
private readonly _renderManagerService;
|
|
8
10
|
static pluginName: string;
|
|
9
11
|
static type: UniverInstanceType;
|
|
10
|
-
constructor(_config: Partial<IUniverSheetsNumfmtUIConfig> | undefined, _injector: Injector, _configService: IConfigService);
|
|
12
|
+
constructor(_config: Partial<IUniverSheetsNumfmtUIConfig> | undefined, _injector: Injector, _configService: IConfigService, _renderManagerService: IRenderManagerService);
|
|
11
13
|
onStarting(): void;
|
|
12
14
|
onRendered(): void;
|
|
15
|
+
private _registerRenderModules;
|
|
13
16
|
}
|
package/lib/umd/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(b,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/sheets-numfmt"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("@univerjs/engine-
|
|
1
|
+
(function(b,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/sheets-numfmt"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("@univerjs/engine-formula"),require("@univerjs/engine-numfmt"),require("@univerjs/sheets"),require("rxjs"),require("rxjs/operators"),require("react"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","@univerjs/sheets-numfmt","@univerjs/sheets-ui","@univerjs/ui","@univerjs/engine-formula","@univerjs/engine-numfmt","@univerjs/sheets","rxjs","rxjs/operators","react","@univerjs/design"],s):(b=typeof globalThis<"u"?globalThis:b||self,s(b.UniverSheetsNumfmtUi={},b.UniverCore,b.UniverEngineRender,b.UniverSheetsNumfmt,b.UniverSheetsUi,b.UniverUi,b.UniverEngineFormula,b.UniverEngineNumfmt,b.UniverSheets,b.rxjs,b.rxjs.operators,b.React,b.UniverDesign))})(this,function(b,s,U,m,E,I,_e,J,S,O,V,_,M){"use strict";var yt=Object.defineProperty;var bt=(b,s,U)=>s in b?yt(b,s,{enumerable:!0,configurable:!0,writable:!0,value:U}):b[s]=U;var z=(b,s,U)=>bt(b,typeof s!="symbol"?s+"":s,U);const ae={};var ye=Object.defineProperty,be=Object.getOwnPropertyDescriptor,Ce=(t,e,n,r)=>{for(var i=r>1?void 0:r?be(e,n):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(r?o(e,n,i):o(i))||i);return r&&i&&ye(e,n,i),i},N=(t,e)=>(n,r)=>e(n,r,t);const X="SHEET_NUMFMT_ALERT";let Q=class extends s.Disposable{constructor(t,e,n,r,i,a,o){super(),this._context=t,this._hoverManagerService=e,this._cellAlertManagerService=n,this._localeService=r,this._formulaDataModel=i,this._zenZoneService=a,this._numfmtService=o,this._init()}_init(){this._initCellAlertPopup(),this._initZenService()}_initCellAlertPopup(){this.disposeWithMe(this._hoverManagerService.currentCell$.pipe(O.debounceTime(100)).subscribe(t=>{var e;if(t){const n=t.location,r=this._context.unit,i=r.getActiveSheet();if(!i)return;const a=n.unitId,o=n.subUnitId;let c;const l=i.getCell(n.row,n.col);if(l!=null&&l.s){const d=r.getStyles().get(l.s);d!=null&&d.n&&(c=d.n)}if(c||(c=this._numfmtService.getValue(a,o,n.row,n.col)),!c){this._hideAlert();return}if(c.pattern===J.DEFAULT_TEXT_FORMAT&&(l!=null&&l.v)&&s.isRealNum(l.v)){const d=this._cellAlertManagerService.currentAlert.get(X),f=(e=d==null?void 0:d.alert)==null?void 0:e.location;if(f&&f.row===n.row&&f.col===n.col&&f.subUnitId===n.subUnitId&&f.unitId===n.unitId)return;this._cellAlertManagerService.showAlert({type:E.CellAlertType.ERROR,title:this._localeService.t("info.error"),message:this._localeService.t("info.forceStringInfo"),location:n,width:200,height:74,key:X});return}}this._hideAlert()}))}_initZenService(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(t=>{t&&this._hideAlert()}))}_hideAlert(){this._cellAlertManagerService.removeAlert(X)}};Q=Ce([N(1,s.Inject(E.HoverManagerService)),N(2,s.Inject(E.CellAlertManagerService)),N(3,s.Inject(s.LocaleService)),N(4,s.Inject(_e.FormulaDataModel)),N(5,I.IZenZoneService),N(6,s.Inject(S.INumfmtService))],Q);const $={id:"sheet.operation.close.numfmt.panel",type:s.CommandType.OPERATION,handler:()=>!0},L={id:"sheet.operation.open.numfmt.panel",type:s.CommandType.OPERATION,handler:t=>(t.get(A).openPanel(),!0)};var q={exports:{}},k={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var ne;function he(){if(ne)return F;ne=1;var t=g,e=Symbol.for("react.element"),r=Symbol.for("react.fragment"),n=Object.prototype.hasOwnProperty,i=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a={key:!0,ref:!0,__self:!0,__source:!0};function o(c,l,v){var f,d={},p=null,y=null;v!==void 0&&(p=""+v),l.key!==void 0&&(p=""+l.key),l.ref!==void 0&&(y=l.ref);for(f in l)n.call(l,f)&&!a.hasOwnProperty(f)&&(d[f]=l[f]);if(c&&c.defaultProps)for(f in l=c.defaultProps,l)d[f]===void 0&&(d[f]=l[f]);return{$$typeof:e,type:c,key:p,ref:y,props:d,_owner:i.current}}return F.Fragment=r,F.jsx=o,F.jsxs=o,F}var re;function Se(){return re||(re=1,z.exports=he()),z.exports}var u=Se(),ye=Object.defineProperty,ge=Object.getOwnPropertyDescriptor,_e=(t,e,r,n)=>{for(var i=n>1?void 0:n?ge(e,r):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(n?o(e,r,i):o(i))||i);return n&&i&&ye(e,r,i),i},be=(t,e)=>(r,n)=>e(r,n,t);const X=g.createContext([]);let L=class{constructor(t){this._localStorageService=t}_getKey(t){return`userHabitController_${t}`}async addHabit(t,e){const r=this._getKey(t);return this._localStorageService.getItem(r).then(n=>{n||this._localStorageService.setItem(r,e)})}markHabit(t,e){const r=this._getKey(t);this._localStorageService.getItem(r).then(n=>{if(n){const i=n.findIndex(a=>a===e);i>-1&&n.splice(i,1),n.unshift(e),this._localStorageService.setItem(r,n)}})}async getHabit(t,e){const r=this._getKey(t),n=await this._localStorageService.getItem(r);if(e&&n){const i=n.map((a,o,c)=>{const l=c.length;return{value:a,priority:l-o}});return e.sort((a,o)=>{var v,f;const c=((v=i.find(d=>d.value===a))==null?void 0:v.priority)||-1;return(((f=i.find(d=>d.value===o))==null?void 0:f.priority)||-1)-c})}return n||[]}deleteHabit(t){this._localStorageService.removeItem(t)}};L=_e([be(0,s.Inject(s.ILocalStorageService))],L);const ie="numfmtCurrency",Ce=t=>{const e=s.useDependency(L),[r,n]=g.useState(m.currencySymbols);return g.useEffect(()=>{e.addHabit("numfmtCurrency",[]).then(()=>{e.getHabit(ie,[...m.currencySymbols]).then(a=>{n(a),t(a)})})},[]),{userHabitCurrency:r,mark:a=>{e.markHabit(ie,a)}}},Ie=()=>{const t=g.useRef([]),[e,r]=g.useState({});return g.useEffect(()=>{t.current.forEach(i=>{i()}),t.current=[]},[e]),i=>{t.current.push(i),r({})}},Pe=t=>!!m.getCurrencyType(t)&&t.startsWith("_("),Te=t=>{const{defaultPattern:e,action:r,onChange:n}=t,[i,a]=g.useState(()=>m.getDecimalFromPattern(e||"",2)),o=g.useContext(X),[c,l]=g.useState(()=>m.getCurrencyType(e)||o[0]),v=g.useMemo(()=>o.map(_=>({label:_,value:_})),[]),d=s.useDependency(s.LocaleService).t;r.current=()=>m.setPatternDecimal(`_("${c}"* #,##0${i>0?".0":""}_)`,i);const p=_=>{l(_),n(m.setPatternDecimal(`_("${_}"* #,##0${i>0?".0":""}_)`,i))},y=_=>{const h=_||0;a(h),n(m.setPatternDecimal(`_("${c}"* #,##0${h>0?".0":""}_)`,h))};return u.jsxs("div",{children:[u.jsxs("div",{className:"m-t-16 options",children:[u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:d("sheet.numfmt.decimalLength")}),u.jsx("div",{className:"m-t-8 w-120",children:u.jsx(E.InputNumber,{value:i,max:20,min:0,onChange:y})})]}),u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:d("sheet.numfmt.currencyType")}),u.jsx("div",{className:"m-t-8 w-140",children:u.jsx(E.Select,{onChange:p,options:v,value:c})})]})]}),u.jsx("div",{className:"describe m-t-14",children:d("sheet.numfmt.accountingDes")})]})},Ee=t=>!!m.getCurrencyType(t)&&!t.startsWith("_("),je=t=>{const r=s.useDependency(s.LocaleService).t,n=g.useContext(X),[i,a]=g.useState(()=>m.getCurrencyType(t.defaultPattern)||n[0]),[o,c]=g.useState(()=>m.getDecimalFromPattern(t.defaultPattern||"",2)),[l,v]=g.useState(()=>{var C;const h=m.getCurrencyFormatOptions(i);return((C=h.find(M=>m.isPatternEqualWithoutDecimal(M.value,t.defaultPattern)))==null?void 0:C.value)||h[0].value}),f=g.useMemo(()=>m.getCurrencyFormatOptions(i),[i]),d=g.useMemo(()=>n.map(h=>({label:h,value:h})),[n]);t.action.current=()=>m.setPatternDecimal(l,o);const p=h=>{if(h===void 0)return;a(h);const T=m.getCurrencyFormatOptions(h)[0].value;v(T),t.onChange(m.setPatternDecimal(T,o))},y=h=>{h!==void 0&&(v(h),t.onChange(m.setPatternDecimal(h,o)))},_=h=>{c(h||0),t.onChange(m.setPatternDecimal(l,h||0))};return u.jsxs("div",{children:[u.jsxs("div",{className:"m-t-16 options",children:[u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:r("sheet.numfmt.decimalLength")}),u.jsx("div",{className:"m-t-8 w-120",children:u.jsx(E.InputNumber,{value:o,max:20,min:0,onChange:_})})]}),u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:r("sheet.numfmt.currencyType")}),u.jsx("div",{className:"m-t-8 w-140",children:u.jsx(E.Select,{onChange:p,options:d,value:i})})]})]}),u.jsx("div",{className:"m-t-16 label",children:r("sheet.numfmt.negType")}),u.jsx("div",{className:"m-t-8",children:u.jsx(E.SelectList,{onChange:y,options:f,value:l})}),u.jsx("div",{className:"describe m-t-14",children:r("sheet.numfmt.currencyDes")})]})};var j=function(){return j=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++){e=arguments[r];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},j.apply(this,arguments)},Me=function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r},se=g.forwardRef(function(t,e){var r=t.icon,n=t.id,i=t.className,a=t.extend,o=Me(t,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(n," ").concat(i||"").trim(),l=g.useRef("_".concat(Re()));return ae(r,"".concat(n),{defIds:r.defIds,idSuffix:l.current},j({ref:e,className:c},o),a)});function ae(t,e,r,n,i){return g.createElement(t.tag,j(j({key:e},xe(t,r,i)),n),(De(t,r).children||[]).map(function(a,o){return ae(a,"".concat(e,"-").concat(t.tag,"-").concat(o),r,void 0,i)}))}function xe(t,e,r){var n=j({},t.attrs);r!=null&&r.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=r.colorChannel1);var i=e.defIds;return!i||i.length===0||(t.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+e.idSuffix),Object.entries(n).forEach(function(a){var o=a[0],c=a[1];typeof c=="string"&&(n[o]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),n}function De(t,e){var r,n=e.defIds;return!n||n.length===0?t:t.tag==="defs"&&(!((r=t.children)===null||r===void 0)&&r.length)?j(j({},t),{children:t.children.map(function(i){return typeof i.attrs.id=="string"&&n&&n.indexOf(i.attrs.id)>-1?j(j({},i),{attrs:j(j({},i.attrs),{id:i.attrs.id+e.idSuffix})}):i})}):t}function Re(){return Math.random().toString(36).substring(2,8)}se.displayName="UniverIcon";var Oe={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},oe=g.forwardRef(function(t,e){return g.createElement(se,Object.assign({},t,{id:"check-mark-single",ref:e,icon:Oe}))});oe.displayName="CheckMarkSingle";const U={customFormatTitle:"univer-custom-format-title",customFormatInput:"univer-custom-format-input",customFormatHistoryList:"univer-custom-format-history-list",customFormatHistoryListItem:"univer-custom-format-history-list-item",customFormatHistoryListItemIconWrap:"univer-custom-format-history-list-item-icon-wrap",customFormatDes:"univer-custom-format-des"},Z="customFormat",Q="numfmt_custom_pattern";function Ue(t){const{defaultPattern:e,action:r,onChange:n}=t,i=s.useDependency(L),a=s.useDependency(s.ILocalStorageService),o=s.useDependency(s.LocaleService),[c,l]=g.useState(e);r.current=()=>(i.markHabit(Z,c),a.getItem(Q).then((y=[])=>{const _=[...new Set([c,...y||[]])].splice(0,10).filter(h=>!!h);a.setItem(Q,_)}),c);const[v,f]=g.useState([]);g.useEffect(()=>{a.getItem(Q).then(y=>{const _=[...m.CURRENCYFORMAT.map(h=>h.suffix("$")),...m.DATEFMTLISG.map(h=>h.suffix),...m.NUMBERFORMAT.map(h=>h.suffix)];_.push(...y||[]),i.addHabit(Z,[]).finally(()=>{i.getHabit(Z,_).then(h=>{f([...new Set(h)])})})})},[]);const d=y=>{l(y),n(y)},p=()=>{n(c)};return u.jsxs("div",{className:U.customFormat,children:[u.jsx("div",{className:U.customFormatTitle,children:o.t("sheet.numfmt.customFormat")}),u.jsx(E.Input,{placeholder:o.t("sheet.numfmt.customFormat"),onBlur:p,value:c,onChange:l,className:U.customFormatInput}),u.jsx("div",{className:U.customFormatHistoryList,children:v.map(y=>u.jsxs("div",{onClick:()=>d(y),className:U.customFormatHistoryListItem,children:[u.jsx("div",{className:U.customFormatHistoryListItemIconWrap,children:c===y&&u.jsx(oe,{})}),u.jsx("div",{children:y})]},y))}),u.jsx("div",{className:U.customFormatDes,children:o.t("sheet.numfmt.customFormatDes")})]})}const Ne=t=>{const e=s.numfmt.getInfo(t);return m.getDateFormatOptions().map(r=>r.value).includes(t)||["date","datetime","time"].includes(e.type)},we=t=>{const e=g.useMemo(m.getDateFormatOptions,[]),n=s.useDependency(s.LocaleService).t,[i,a]=g.useState(()=>{if(t.defaultPattern){const c=e.find(l=>l.value===t.defaultPattern);if(c)return c.value}return e[0].value});t.action.current=()=>i;const o=c=>{c!==void 0&&(a(c),t.onChange(c))};return u.jsxs("div",{children:[u.jsx("div",{className:"m-t-16 label",children:n("sheet.numfmt.dateType")}),u.jsx("div",{className:"m-t-8",children:u.jsx(E.SelectList,{value:i,options:e,onChange:o})}),u.jsx("div",{className:"describe m-t-14",children:n("sheet.numfmt.dateDes")})]})},Fe=t=>!t,Le=t=>{const r=s.useDependency(s.LocaleService).t;return t.action.current=()=>"",u.jsx("div",{children:u.jsx("div",{className:"describe m-t-14",children:r("sheet.numfmt.generalDes")})})},ke=t=>m.getNumberFormatOptions().some(e=>m.isPatternEqualWithoutDecimal(e.value,t)),He=t=>{const e=s.useDependency(s.LocaleService),r=g.useMemo(m.getNumberFormatOptions,[]),[n,i]=g.useState(()=>m.getDecimalFromPattern(t.defaultPattern||"",0)),[a,o]=g.useState(()=>{const d=r.find(p=>m.isPatternEqualWithoutDecimal(p.value,t.defaultPattern||""));return(d==null?void 0:d.value)||r[0].value}),c=g.useMemo(()=>m.setPatternDecimal(a,Number(n||0)),[a,n]),l=g.useMemo(()=>!m.isPatternHasDecimal(a),[a]),v=d=>{i(d||0),t.onChange(m.setPatternDecimal(a,Number(d||0)))},f=d=>{d!==void 0&&(i(m.getDecimalFromPattern(d,0)),o(d),t.onChange(d))};return t.action.current=()=>c,u.jsxs("div",{children:[u.jsx("div",{className:"m-t-16 label",children:e.t("sheet.numfmt.decimalLength")}),u.jsx("div",{className:"m-t-8",children:u.jsx(E.InputNumber,{disabled:l,value:n,max:20,min:0,onChange:v})}),u.jsxs("div",{className:"m-t-16 label",children:[" ",e.t("sheet.numfmt.negType")]}),u.jsx("div",{className:"m-t-8",children:u.jsx(E.SelectList,{onChange:f,options:r,value:a})}),u.jsx("div",{className:"describe m-t-14",children:e.t("sheet.numfmt.thousandthPercentileDes")})]})},We=t=>{const{defaultValue:e,defaultPattern:r,row:n,col:i}=t.value,a=s.useDependency(s.LocaleService),o=g.useRef(()=>""),c=a.t,l=Ie(),v=g.useMemo(()=>[{label:"sheet.numfmt.general",component:Le},{label:"sheet.numfmt.accounting",component:Te},{label:"sheet.numfmt.currency",component:je},{label:"sheet.numfmt.date",component:we},{label:"sheet.numfmt.thousandthPercentile",component:He},{label:"sheet.numfmt.customFormat",component:Ue}].map(I=>({...I,label:c(I.label)})),[]),[f,d]=g.useState(C),[p,y]=g.useState(()=>`${n}_${i}`),{mark:_,userHabitCurrency:h}=Ce(()=>y(`${n}_${i}_userCurrency'`)),T=g.useMemo(()=>{var I;return(I=v.find(N=>N.label===f))==null?void 0:I.component},[f]);function C(){return[Fe,Pe,Ee,Ne,ke].reduce((N,mt,dt)=>N||(mt(r)?v[dt].label:""),"")||v[0].label}const M=v.map(I=>({label:I.label,value:I.label})),D=I=>{d(I),l(()=>t.onChange({type:"change",value:o.current()||""}))},K=I=>{t.onChange({type:"change",value:I})},$=()=>{const I=o.current()||"",N=m.getCurrencyType(I);N&&_(N),t.onChange({type:"confirm",value:I})},W=()=>{t.onChange({type:"cancel",value:""})},q={onChange:K,defaultValue:e,defaultPattern:r,action:o};return g.useEffect(()=>{d(C()),y(`${n}_${i}`)},[n,i]),u.jsxs("div",{className:"numfmt-panel p-b-20",children:[u.jsxs("div",{children:[u.jsx("div",{className:"label m-t-14",children:c("sheet.numfmt.numfmtType")}),u.jsx("div",{className:"m-t-8",children:u.jsx(E.Select,{onChange:D,options:M,value:f,style:{width:"100%"}})}),u.jsx("div",{children:T&&u.jsx(X.Provider,{value:h,children:g.createElement(T,{...q,key:p})})})]}),u.jsxs("div",{className:"btn-list m-t-14 m-b-20",children:[u.jsx(E.Button,{size:"small",onClick:W,className:"m-r-12",children:c("sheet.numfmt.cancel")}),u.jsx(E.Button,{type:"primary",size:"small",onClick:$,children:c("sheet.numfmt.confirm")})]})]})};var Ae=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,Ve=(t,e,r,n)=>{for(var i=n>1?void 0:n?Be(e,r):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(n?o(e,r,i):o(i))||i);return n&&i&&Ae(e,r,i),i},x=(t,e)=>(r,n)=>e(r,n,t);const ce="SHEET_NUMFMT_PANEL";let k=class extends s.Disposable{constructor(e,r,n,i,a,o,c,l,v,f){super();Y(this,"_previewPattern","");Y(this,"_sidebarDisposable",null);this._sheetInterceptorService=e,this._themeService=r,this._univerInstanceService=n,this._commandService=i,this._selectionManagerService=a,this._renderManagerService=o,this._numfmtService=c,this._componentManager=l,this._sidebarService=v,this._localeService=f,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener()}openPanel(){var T;const e=this._sidebarService,r=this._selectionManagerService,n=this._commandService,i=this._univerInstanceService,a=this._numfmtService,o=this._localeService,l=(((T=r.getCurrentSelections())==null?void 0:T.map(C=>C.range))||[])[0];if(!l)return!1;const v=i.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),f=v.getActiveSheet();if(!f)return!1;const d=f.getCellRaw(l.startRow,l.startColumn),p=a.getValue(v.getUnitId(),f.getSheetId(),l.startRow,l.startColumn);let y="";p&&(y=p.pattern);const _=(d==null?void 0:d.t)===s.CellValueType.NUMBER?d.v:12345678,h={onChange:C=>{var M;if(C.type==="change")this._previewPattern=C.value,this._forceUpdate();else if(C.type==="confirm"){const D=((M=r.getCurrentSelections())==null?void 0:M.map(W=>W.range))||[],K={values:[]},$=m.getPatternType(C.value);D.forEach(W=>{s.Range.foreach(W,(q,I)=>{K.values.push({row:q,col:I,pattern:C.value,type:$})})}),n.executeCommand(m.SetNumfmtCommand.id,K),e.close()}else C.type==="cancel"&&e.close()},value:{defaultPattern:y,defaultValue:_,row:l.startRow,col:l.startColumn}};return this._sidebarDisposable=e.open({header:{title:o.t("sheet.numfmt.title")},children:{label:ce,...h},onClose:()=>{this._forceUpdate(),n.executeCommand(J.id)}}),!0}_forceUpdate(e){var n;const r=this._renderManagerService.getRenderById(e!=null?e:this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET).getUnitId());r==null||r.with(R.SheetSkeletonManagerService).reCalculate(),(n=r==null?void 0:r.mainComponent)==null||n.makeDirty()}_initCommands(){[w,J].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initPanel(){this._componentManager.register(ce,We)}_initRealTimeRenderingInterceptor(){const e=new O.Observable(n=>{this._commandService.onCommandExecuted(i=>{i.id===w.id&&n.next(!0),i.id===J.id&&n.next(!1)})}),r=O.combineLatest([e,this._selectionManagerService.selectionMoveEnd$.pipe(A.map(n=>n?n.map(i=>i.range):[]))]);this.disposeWithMe(s.toDisposable(r.pipe(A.switchMap(([n,i])=>new O.Observable(a=>{const o=new s.DisposableCollection;return n&&i.length&&a.next({selectionRanges:i,disposableCollection:o}),()=>{o.dispose()}})),A.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:n,selectionRanges:i})=>{var o,c;const a=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);this.openPanel(),n.add(this._sheetInterceptorService.intercept(S.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,effect:s.InterceptorEffectEnum.Value|s.InterceptorEffectEnum.Style,handler:(l,v,f)=>{const{row:d,col:p}=v,y=f(l)||{};if(i.find(_=>_.startColumn<=p&&_.endColumn>=p&&_.startRow<=d&&_.endRow>=d)){const _=v.worksheet.getCellRaw(d,p),h=_==null?void 0:_.v,T=_==null?void 0:_.t;if(h==null||T!==s.CellValueType.NUMBER||this._previewPattern===null)return y;const C=m.getPatternPreviewIgnoreGeneral(this._previewPattern,h,this._localeService.getCurrentLocale());if(C.color){const D=this._themeService.getCurrentTheme()[`${C.color}500`];return{...y,v:C.result,t:s.CellValueType.STRING,s:{cl:{rgb:D}}}}return{...y,v:C.result,t:s.CellValueType.STRING}}return y}})),(c=(o=this._renderManagerService.getRenderById(a.getUnitId()))==null?void 0:o.mainComponent)==null||c.makeDirty()})))}_commandExecutedListener(){const e=[S.RemoveNumfmtMutation.id,S.SetNumfmtMutation.id];this.disposeWithMe(new O.Observable(r=>{const n=this._commandService.onCommandExecuted(i=>{if(e.includes(i.id)){const a=i.params;r.next(a.unitId)}});return()=>n.dispose()}).pipe(A.debounceTime(16)).subscribe(r=>this._forceUpdate(r)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_SHEET).subscribe(e=>{var r;e||((r=this._sidebarDisposable)==null||r.dispose(),this._sidebarDisposable=null)})}};k=Ve([x(0,s.Inject(S.SheetInterceptorService)),x(1,s.Inject(s.ThemeService)),x(2,s.IUniverInstanceService),x(3,s.ICommandService),x(4,s.Inject(S.SheetsSelectionsService)),x(5,ve.IRenderManagerService),x(6,S.INumfmtService),x(7,s.Inject(P.ComponentManager)),x(8,P.ISidebarService),x(9,s.Inject(s.LocaleService))],k);var Ge=Object.defineProperty,Ke=Object.getOwnPropertyDescriptor,Ye=(t,e,r,n)=>{for(var i=n>1?void 0:n?Ke(e,r):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(n?o(e,r,i):o(i))||i);return n&&i&&Ge(e,r,i),i},H=(t,e)=>(r,n)=>e(r,n,t);const Je=()=>{let t=[];return{add:(i,a,o,c,l)=>t.push({unitId:i,subUnitId:a,row:o,col:c,value:l}),getEffects:()=>t,clean:()=>{t=[]}}};let B=class extends s.Disposable{constructor(e,r,n,i,a){super();Y(this,"_collectEffectMutation",Je());this._sheetInterceptorService=e,this._numfmtService=r,this._univerInstanceService=n,this._injector=i,this._editorBridgeService=a,this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(s.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(S.BEFORE_CELL_EDIT,{handler:(e,r,n)=>{const i=r.row,a=r.col,o=this._numfmtService.getValue(r.unitId,r.subUnitId,i,a);if(o)switch(m.getPatternType(o.pattern)){case"scientific":case"currency":case"grouped":case"number":return r.worksheet.getCellRaw(i,a);case"percent":case"date":case"time":case"datetime":default:return n&&n(e)}return n(e)}})))}_initInterceptorEditorEnd(){this.disposeWithMe(s.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(S.AFTER_CELL_EDIT,{handler:(e,r,n)=>{var f,d,p,y;this._collectEffectMutation.clean();const i=this._numfmtService.getValue(r.unitId,r.subUnitId,r.row,r.col),a=(f=i&&m.getPatternType(i.pattern))!=null?f:"",o=()=>{i&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,null)};if(!(e!=null&&e.v)&&!(e!=null&&e.p)||(i==null?void 0:i.pattern)===ee.DEFAULT_TEXT_FORMAT)return n(e);const c=(d=e.p)==null?void 0:d.body,l=(y=(p=e==null?void 0:e.p)==null?void 0:p.body)!=null&&y.dataStream?e.p.body.dataStream.replace(/\r\n$/,""):String(e.v),v=s.numfmt.parseDate(l)||s.numfmt.parseTime(l)||s.numfmt.parseNumber(l);if(c)if(Xe(c)){const{dataStream:_}=c,h=_.replace(/\r\n$/,""),T=Number(h);if(Number.isNaN(T)&&!v)return n(e)}else return n(e);if(v){v.z&&this._collectEffectMutation.add(r.unitId,r.subUnitId,r.row,r.col,{pattern:v.z});const _=Number(v.v);return n({...e,p:void 0,v:_,t:s.CellValueType.NUMBER})}else(["date","time","datetime","percent"].includes(a)||!ze(l))&&o();return n(e)}})))}_initInterceptorCommands(){const e=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(r){var n;switch(r.id){case S.SetRangeValuesCommand.id:{const i=e._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),a=i.getUnitId(),o=(n=i.getActiveSheet())==null?void 0:n.getSheetId();if(!o)return{redos:[],undos:[]};const c=e._collectEffectMutation.getEffects();if(e._collectEffectMutation.clean(),!c.length)return{redos:[],undos:[]};const l=c.filter(p=>{var y;return!!((y=p.value)!=null&&y.pattern)}).map(p=>({row:p.row,col:p.col,pattern:p.value.pattern})),v=c.filter(p=>{var y;return!((y=p.value)!=null&&y.pattern)}).map(p=>({startRow:p.row,endColumn:p.col,startColumn:p.col,endRow:p.row})),f=[],d=[];if(l.length){const p={id:S.SetNumfmtMutation.id,params:S.transformCellsToRange(a,o,l)};f.push(p),d.push(...S.factorySetNumfmtUndoMutation(e._injector,p.params))}if(v.length){const p={id:S.RemoveNumfmtMutation.id,params:{unitId:a,subUnitId:o,ranges:v}};f.push(p),d.push(...S.factoryRemoveNumfmtUndoMutation(e._injector,p.params))}return{redos:f,undos:d.reverse()}}}return{redos:[],undos:[]}}}))}};B=Ye([H(0,s.Inject(S.SheetInterceptorService)),H(1,s.Inject(S.INumfmtService)),H(2,s.Inject(s.IUniverInstanceService)),H(3,s.Inject(s.Injector)),H(4,s.Optional(R.IEditorBridgeService))],B);function ze(t){return/^-?\d+(\.\d+)?$/.test(t)}function Xe(t){const{textRuns:e=[],paragraphs:r=[],customRanges:n,customBlocks:i=[]}=t,a=["va"];return!(e.some(o=>!!(o.ts&&Object.keys(o.ts).some(l=>a.includes(l))))||r.some(o=>o.bullet)||r.length>=2||n!=null&&n.length||i.length>0)}const V=[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:ee.DEFAULT_TEXT_FORMAT},"|",{label:"sheet.numfmt.number",pattern:"0"},"|",{label:"sheet.numfmt.accounting",pattern:'"¥" #,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.financialValue",pattern:"#,##0.00;[Red]#,##0.00"},{label:"sheet.numfmt.currency",pattern:'"¥"#,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.roundingCurrency",pattern:'"¥"#,##0;[Red]"¥"#,##0'},"|",{label:"sheet.numfmt.date",pattern:"yyyy-mm-dd;@"},{label:"sheet.numfmt.time",pattern:'am/pm h":"mm":"ss'},{label:"sheet.numfmt.dateTime",pattern:"yyyy-m-d am/pm h:mm"},{label:"sheet.numfmt.timeDuration",pattern:"h:mm:ss"},"|",{label:"sheet.numfmt.moreFmt",pattern:""}],Ze=t=>({icon:new O.Observable(e=>{const r=t.get(m.MenuCurrencyService);function n(a){return{[m.countryCurrencyMap.US]:"DollarSingle",[m.countryCurrencyMap.RU]:"RoubleSingle",[m.countryCurrencyMap.CN]:"RmbSingle",[m.countryCurrencyMap.AT]:"EuroSingle"}[a]||"DollarSingle"}const i=m.countryCurrencyMap[r.getCurrencySymbol()]||"$";return e.next(n(i)),r.currencySymbol$.subscribe(a=>{const o=m.countryCurrencyMap[a]||"$";e.next(n(o))})}),id:m.SetCurrencyCommand.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:P.MenuItemType.BUTTON,hidden$:P.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:R.getCurrentRangeDisable$(t,{workbookTypes:[S.WorkbookEditablePermission],worksheetTypes:[S.WorksheetEditPermission,S.WorksheetSetCellStylePermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}),Qe=t=>({icon:"AddDigitsSingle",id:m.AddDecimalCommand.id,title:"sheet.numfmt.addDecimal",tooltip:"sheet.numfmt.addDecimal",type:P.MenuItemType.BUTTON,hidden$:P.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:R.getCurrentRangeDisable$(t,{workbookTypes:[S.WorkbookEditablePermission],worksheetTypes:[S.WorksheetEditPermission,S.WorksheetSetCellStylePermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}),$e=t=>({icon:"ReduceDigitsSingle",id:m.SubtractDecimalCommand.id,title:"sheet.numfmt.subtractDecimal",tooltip:"sheet.numfmt.subtractDecimal",type:P.MenuItemType.BUTTON,hidden$:P.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:R.getCurrentRangeDisable$(t,{workbookTypes:[S.WorkbookEditablePermission],worksheetTypes:[S.WorksheetEditPermission,S.WorksheetSetCellStylePermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}),qe=t=>({icon:"PercentSingle",id:m.SetPercentCommand.id,title:"sheet.numfmt.percent",tooltip:"sheet.numfmt.percent",type:P.MenuItemType.BUTTON,hidden$:P.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:R.getCurrentRangeDisable$(t,{workbookTypes:[S.WorkbookEditablePermission],worksheetTypes:[S.WorksheetEditPermission,S.WorksheetSetCellStylePermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}),et=t=>{const e=t.get(s.IUniverInstanceService),r=t.get(s.ICommandService),n=t.get(s.LocaleService),i=t.get(S.SheetsSelectionsService),a=R.deriveStateFromActiveSheet$(e,"",({workbook:o,worksheet:c})=>new O.Observable(l=>O.merge(i.selectionMoveEnd$,new O.Observable(v=>{const f=[S.RemoveNumfmtMutation.id,S.SetNumfmtMutation.id],d=r.onCommandExecuted(p=>{f.includes(p.id)&&v.next(null)});return()=>d.dispose()})).subscribe(()=>{var f,d;const v=i.getCurrentSelections();if(v&&v[0]){const p=v[0].range,y=p.startRow,_=p.startColumn,h=(d=o.getStyles().get((f=c.getCell(y,_))==null?void 0:f.s))==null?void 0:d.n,T=h==null?void 0:h.pattern;let C=n.t("sheet.numfmt.general");if(T){const M=V.filter(D=>typeof D=="object"&&D.pattern).find(D=>m.isPatternEqualWithoutDecimal(T,D.pattern));M&&typeof M=="object"&&M.pattern?C=n.t(M.label):C=n.t("sheet.numfmt.moreFmt")}l.next(C)}})));return{label:le,id:w.id,tooltip:"sheet.numfmt.title",type:P.MenuItemType.SELECTOR,selections:[{label:{name:ue,hoverable:!1}}],value$:a,hidden$:P.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:R.getCurrentRangeDisable$(t,{workbookTypes:[S.WorkbookEditablePermission],worksheetTypes:[S.WorksheetSetCellStylePermission,S.WorksheetEditPermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}},le="sheet.numfmt.moreNumfmtType",ue="sheet.numfmt.moreNumfmtType.options",tt=t=>{var n;const e=s.useDependency(s.LocaleService),r=(n=t.value)!=null?n:e.t("sheet.numfmt.general");return u.jsx("span",{className:"more-numfmt-type",children:r})},nt=()=>{const t=s.useDependency(s.ICommandService),e=s.useDependency(s.LocaleService),r=s.useDependency(P.ILayoutService);s.useInjector();const n=s.useDependency(S.SheetsSelectionsService),i=c=>{const l=n.getCurrentLastSelection();if(!l)return;const v=l.range,f=[];s.Range.foreach(v,(d,p)=>{c?f.push({row:d,col:p,pattern:c,type:m.getPatternType(c)}):f.push({row:d,col:p})}),t.executeCommand(m.SetNumfmtCommand.id,{values:f}),r.focus()},a=c=>{if(c===0)i(null);else if(c===V.length-1)t.executeCommand(w.id);else{const l=V[c];l.pattern&&i(l.pattern)}},o=1220;return u.jsx("div",{className:"more-numfmt-type-options",children:V.map((c,l)=>c==="|"?u.jsx("div",{className:"line m-t-4",onClick:v=>v.stopPropagation()},l):u.jsxs("div",{className:"option-item m-t-4",onClick:()=>{a(l)},children:[u.jsx("div",{children:e.t(c.label)}),u.jsx("div",{className:"m-l-26",children:c.pattern?m.getPatternPreview(c.pattern||"",o,e.getCurrentLocale()).result:""})]},l))})},rt={[P.RibbonStartGroup.FORMULAS_INSERT]:{[m.SetCurrencyCommand.id]:{order:4,menuItemFactory:Ze},[m.AddDecimalCommand.id]:{order:5,menuItemFactory:Qe},[m.SubtractDecimalCommand.id]:{order:6,menuItemFactory:$e},[m.SetPercentCommand.id]:{order:7,menuItemFactory:qe},[w.id]:{order:8,menuItemFactory:et}}};var it=Object.defineProperty,st=Object.getOwnPropertyDescriptor,at=(t,e,r,n)=>{for(var i=n>1?void 0:n?st(e,r):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(n?o(e,r,i):o(i))||i);return n&&i&&it(e,r,i),i},me=(t,e)=>(r,n)=>e(r,n,t);let G=class extends s.Disposable{constructor(t,e){super(),this._componentManager=t,this._menuManagerService=e,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(rt),this.disposeWithMe(this._componentManager.register(le,tt)),this.disposeWithMe(this._componentManager.register(ue,nt))}};G=at([me(0,s.Inject(P.ComponentManager)),me(1,P.IMenuManagerService)],G);var de=Object.defineProperty,ot=Object.getOwnPropertyDescriptor,ct=(t,e,r)=>e in t?de(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,lt=(t,e,r,n)=>{for(var i=n>1?void 0:n?ot(e,r):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(n?o(e,r,i):o(i))||i);return n&&i&&de(e,r,i),i},pe=(t,e)=>(r,n)=>e(r,n,t),fe=(t,e,r)=>ct(t,typeof e!="symbol"?e+"":e,r);const ut="SHEET_NUMFMT_UI_PLUGIN";b.UniverSheetsNumfmtUIPlugin=class extends s.Plugin{constructor(e=te,r,n){super(),this._config=e,this._injector=r,this._configService=n;const{menu:i,...a}=s.merge({},te,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(P.UI_PLUGIN_CONFIG_KEY,a)}onStarting(){s.registerDependencies(this._injector,[[k],[B],[L],[G]])}onRendered(){s.touchDependencies(this._injector,[[k],[B],[G]])}},fe(b.UniverSheetsNumfmtUIPlugin,"pluginName",ut),fe(b.UniverSheetsNumfmtUIPlugin,"type",s.UniverInstanceType.UNIVER_SHEET),b.UniverSheetsNumfmtUIPlugin=lt([s.DependentOn(R.UniverSheetsUIPlugin,m.UniverSheetsNumfmtPlugin),pe(1,s.Inject(s.Injector)),pe(2,s.IConfigService)],b.UniverSheetsNumfmtUIPlugin),Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
|
|
9
|
+
*/var oe;function Ie(){if(oe)return k;oe=1;var t=_,e=Symbol.for("react.element"),n=Symbol.for("react.fragment"),r=Object.prototype.hasOwnProperty,i=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a={key:!0,ref:!0,__self:!0,__source:!0};function o(c,l,d){var f,p={},v=null,g=null;d!==void 0&&(v=""+d),l.key!==void 0&&(v=""+l.key),l.ref!==void 0&&(g=l.ref);for(f in l)r.call(l,f)&&!a.hasOwnProperty(f)&&(p[f]=l[f]);if(c&&c.defaultProps)for(f in l=c.defaultProps,l)p[f]===void 0&&(p[f]=l[f]);return{$$typeof:e,type:c,key:v,ref:g,props:p,_owner:i.current}}return k.Fragment=n,k.jsx=o,k.jsxs=o,k}var ce;function Te(){return ce||(ce=1,q.exports=Ie()),q.exports}var u=Te(),Pe=Object.defineProperty,Ee=Object.getOwnPropertyDescriptor,Me=(t,e,n,r)=>{for(var i=r>1?void 0:r?Ee(e,n):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(r?o(e,n,i):o(i))||i);return r&&i&&Pe(e,n,i),i},je=(t,e)=>(n,r)=>e(n,r,t);const ee=_.createContext([]);let H=class{constructor(t){this._localStorageService=t}_getKey(t){return`userHabitController_${t}`}async addHabit(t,e){const n=this._getKey(t);return this._localStorageService.getItem(n).then(r=>{r||this._localStorageService.setItem(n,e)})}markHabit(t,e){const n=this._getKey(t);this._localStorageService.getItem(n).then(r=>{if(r){const i=r.findIndex(a=>a===e);i>-1&&r.splice(i,1),r.unshift(e),this._localStorageService.setItem(n,r)}})}async getHabit(t,e){const n=this._getKey(t),r=await this._localStorageService.getItem(n);if(e&&r){const i=r.map((a,o,c)=>{const l=c.length;return{value:a,priority:l-o}});return e.sort((a,o)=>{var d,f;const c=((d=i.find(p=>p.value===a))==null?void 0:d.priority)||-1;return(((f=i.find(p=>p.value===o))==null?void 0:f.priority)||-1)-c})}return r||[]}deleteHabit(t){this._localStorageService.removeItem(t)}};H=Me([je(0,s.Inject(s.ILocalStorageService))],H);const le="numfmtCurrency",Re=t=>{const e=s.useDependency(H),[n,r]=_.useState(m.currencySymbols);return _.useEffect(()=>{e.addHabit("numfmtCurrency",[]).then(()=>{e.getHabit(le,[...m.currencySymbols]).then(a=>{r(a),t(a)})})},[]),{userHabitCurrency:n,mark:a=>{e.markHabit(le,a)}}},xe=()=>{const t=_.useRef([]),[e,n]=_.useState({});return _.useEffect(()=>{t.current.forEach(i=>{i()}),t.current=[]},[e]),i=>{t.current.push(i),n({})}},De=t=>!!m.getCurrencyType(t)&&t.startsWith("_("),Oe=t=>{const{defaultPattern:e,action:n,onChange:r}=t,[i,a]=_.useState(()=>m.getDecimalFromPattern(e||"",2)),o=_.useContext(ee),[c,l]=_.useState(()=>m.getCurrencyType(e)||o[0]),d=_.useMemo(()=>o.map(y=>({label:y,value:y})),[]),p=s.useDependency(s.LocaleService).t;n.current=()=>m.setPatternDecimal(`_("${c}"* #,##0${i>0?".0":""}_)`,i);const v=y=>{l(y),r(m.setPatternDecimal(`_("${y}"* #,##0${i>0?".0":""}_)`,i))},g=y=>{const h=y||0;a(h),r(m.setPatternDecimal(`_("${c}"* #,##0${h>0?".0":""}_)`,h))};return u.jsxs("div",{children:[u.jsxs("div",{className:"m-t-16 options",children:[u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:p("sheet.numfmt.decimalLength")}),u.jsx("div",{className:"m-t-8 w-120",children:u.jsx(M.InputNumber,{value:i,max:20,min:0,onChange:g})})]}),u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:p("sheet.numfmt.currencyType")}),u.jsx("div",{className:"m-t-8 w-140",children:u.jsx(M.Select,{onChange:v,options:d,value:c})})]})]}),u.jsx("div",{className:"describe m-t-14",children:p("sheet.numfmt.accountingDes")})]})},Ue=t=>!!m.getCurrencyType(t)&&!t.startsWith("_("),we=t=>{const n=s.useDependency(s.LocaleService).t,r=_.useContext(ee),[i,a]=_.useState(()=>m.getCurrencyType(t.defaultPattern)||r[0]),[o,c]=_.useState(()=>m.getDecimalFromPattern(t.defaultPattern||"",2)),[l,d]=_.useState(()=>{var C;const h=m.getCurrencyFormatOptions(i);return((C=h.find(R=>m.isPatternEqualWithoutDecimal(R.value,t.defaultPattern)))==null?void 0:C.value)||h[0].value}),f=_.useMemo(()=>m.getCurrencyFormatOptions(i),[i]),p=_.useMemo(()=>r.map(h=>({label:h,value:h})),[r]);t.action.current=()=>m.setPatternDecimal(l,o);const v=h=>{if(h===void 0)return;a(h);const P=m.getCurrencyFormatOptions(h)[0].value;d(P),t.onChange(m.setPatternDecimal(P,o))},g=h=>{h!==void 0&&(d(h),t.onChange(m.setPatternDecimal(h,o)))},y=h=>{c(h||0),t.onChange(m.setPatternDecimal(l,h||0))};return u.jsxs("div",{children:[u.jsxs("div",{className:"m-t-16 options",children:[u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:n("sheet.numfmt.decimalLength")}),u.jsx("div",{className:"m-t-8 w-120",children:u.jsx(M.InputNumber,{value:o,max:20,min:0,onChange:y})})]}),u.jsxs("div",{className:"option",children:[u.jsx("div",{className:"label",children:n("sheet.numfmt.currencyType")}),u.jsx("div",{className:"m-t-8 w-140",children:u.jsx(M.Select,{onChange:v,options:p,value:i})})]})]}),u.jsx("div",{className:"m-t-16 label",children:n("sheet.numfmt.negType")}),u.jsx("div",{className:"m-t-8",children:u.jsx(M.SelectList,{onChange:g,options:f,value:l})}),u.jsx("div",{className:"describe m-t-14",children:n("sheet.numfmt.currencyDes")})]})};var j=function(){return j=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++){e=arguments[n];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},j.apply(this,arguments)},Ne=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]]);return n},ue=_.forwardRef(function(t,e){var n=t.icon,r=t.id,i=t.className,a=t.extend,o=Ne(t,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(r," ").concat(i||"").trim(),l=_.useRef("_".concat(ke()));return me(n,"".concat(r),{defIds:n.defIds,idSuffix:l.current},j({ref:e,className:c},o),a)});function me(t,e,n,r,i){return _.createElement(t.tag,j(j({key:e},Fe(t,n,i)),r),(Le(t,n).children||[]).map(function(a,o){return me(a,"".concat(e,"-").concat(t.tag,"-").concat(o),n,void 0,i)}))}function Fe(t,e,n){var r=j({},t.attrs);n!=null&&n.colorChannel1&&r.fill==="colorChannel1"&&(r.fill=n.colorChannel1);var i=e.defIds;return!i||i.length===0||(t.tag==="use"&&r["xlink:href"]&&(r["xlink:href"]=r["xlink:href"]+e.idSuffix),Object.entries(r).forEach(function(a){var o=a[0],c=a[1];typeof c=="string"&&(r[o]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),r}function Le(t,e){var n,r=e.defIds;return!r||r.length===0?t:t.tag==="defs"&&(!((n=t.children)===null||n===void 0)&&n.length)?j(j({},t),{children:t.children.map(function(i){return typeof i.attrs.id=="string"&&r&&r.indexOf(i.attrs.id)>-1?j(j({},i),{attrs:j(j({},i.attrs),{id:i.attrs.id+e.idSuffix})}):i})}):t}function ke(){return Math.random().toString(36).substring(2,8)}ue.displayName="UniverIcon";var He={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},de=_.forwardRef(function(t,e){return _.createElement(ue,Object.assign({},t,{id:"check-mark-single",ref:e,icon:He}))});de.displayName="CheckMarkSingle";const w={customFormatTitle:"univer-custom-format-title",customFormatInput:"univer-custom-format-input",customFormatHistoryList:"univer-custom-format-history-list",customFormatHistoryListItem:"univer-custom-format-history-list-item",customFormatHistoryListItemIconWrap:"univer-custom-format-history-list-item-icon-wrap",customFormatDes:"univer-custom-format-des"},te="customFormat",ne="numfmt_custom_pattern";function Ae(t){const{defaultPattern:e,action:n,onChange:r}=t,i=s.useDependency(H),a=s.useDependency(s.ILocalStorageService),o=s.useDependency(s.LocaleService),[c,l]=_.useState(e);n.current=()=>(i.markHabit(te,c),a.getItem(ne).then((g=[])=>{const y=[...new Set([c,...g||[]])].splice(0,10).filter(h=>!!h);a.setItem(ne,y)}),c);const[d,f]=_.useState([]);_.useEffect(()=>{a.getItem(ne).then(g=>{const y=[...m.CURRENCYFORMAT.map(h=>h.suffix("$")),...m.DATEFMTLISG.map(h=>h.suffix),...m.NUMBERFORMAT.map(h=>h.suffix)];y.push(...g||[]),i.addHabit(te,[]).finally(()=>{i.getHabit(te,y).then(h=>{f([...new Set(h)])})})})},[]);const p=g=>{l(g),r(g)},v=()=>{r(c)};return u.jsxs("div",{className:w.customFormat,children:[u.jsx("div",{className:w.customFormatTitle,children:o.t("sheet.numfmt.customFormat")}),u.jsx(M.Input,{placeholder:o.t("sheet.numfmt.customFormat"),onBlur:v,value:c,onChange:l,className:w.customFormatInput}),u.jsx("div",{className:w.customFormatHistoryList,children:d.map(g=>u.jsxs("div",{onClick:()=>p(g),className:w.customFormatHistoryListItem,children:[u.jsx("div",{className:w.customFormatHistoryListItemIconWrap,children:c===g&&u.jsx(de,{})}),u.jsx("div",{children:g})]},g))}),u.jsx("div",{className:w.customFormatDes,children:o.t("sheet.numfmt.customFormatDes")})]})}const We=t=>{const e=s.numfmt.getInfo(t);return m.getDateFormatOptions().map(n=>n.value).includes(t)||["date","datetime","time"].includes(e.type)},Be=t=>{const e=_.useMemo(m.getDateFormatOptions,[]),r=s.useDependency(s.LocaleService).t,[i,a]=_.useState(()=>{if(t.defaultPattern){const c=e.find(l=>l.value===t.defaultPattern);if(c)return c.value}return e[0].value});t.action.current=()=>i;const o=c=>{c!==void 0&&(a(c),t.onChange(c))};return u.jsxs("div",{children:[u.jsx("div",{className:"m-t-16 label",children:r("sheet.numfmt.dateType")}),u.jsx("div",{className:"m-t-8",children:u.jsx(M.SelectList,{value:i,options:e,onChange:o})}),u.jsx("div",{className:"describe m-t-14",children:r("sheet.numfmt.dateDes")})]})},Ve=t=>!t,Ge=t=>{const n=s.useDependency(s.LocaleService).t;return t.action.current=()=>"",u.jsx("div",{children:u.jsx("div",{className:"describe m-t-14",children:n("sheet.numfmt.generalDes")})})},Ke=t=>m.getNumberFormatOptions().some(e=>m.isPatternEqualWithoutDecimal(e.value,t)),Ye=t=>{const e=s.useDependency(s.LocaleService),n=_.useMemo(m.getNumberFormatOptions,[]),[r,i]=_.useState(()=>m.getDecimalFromPattern(t.defaultPattern||"",0)),[a,o]=_.useState(()=>{const p=n.find(v=>m.isPatternEqualWithoutDecimal(v.value,t.defaultPattern||""));return(p==null?void 0:p.value)||n[0].value}),c=_.useMemo(()=>m.setPatternDecimal(a,Number(r||0)),[a,r]),l=_.useMemo(()=>!m.isPatternHasDecimal(a),[a]),d=p=>{i(p||0),t.onChange(m.setPatternDecimal(a,Number(p||0)))},f=p=>{p!==void 0&&(i(m.getDecimalFromPattern(p,0)),o(p),t.onChange(p))};return t.action.current=()=>c,u.jsxs("div",{children:[u.jsx("div",{className:"m-t-16 label",children:e.t("sheet.numfmt.decimalLength")}),u.jsx("div",{className:"m-t-8",children:u.jsx(M.InputNumber,{disabled:l,value:r,max:20,min:0,onChange:d})}),u.jsxs("div",{className:"m-t-16 label",children:[" ",e.t("sheet.numfmt.negType")]}),u.jsx("div",{className:"m-t-8",children:u.jsx(M.SelectList,{onChange:f,options:n,value:a})}),u.jsx("div",{className:"describe m-t-14",children:e.t("sheet.numfmt.thousandthPercentileDes")})]})},Ze=t=>{const{defaultValue:e,defaultPattern:n,row:r,col:i}=t.value,a=s.useDependency(s.LocaleService),o=_.useRef(()=>""),c=a.t,l=xe(),d=_.useMemo(()=>[{label:"sheet.numfmt.general",component:Ge},{label:"sheet.numfmt.accounting",component:Oe},{label:"sheet.numfmt.currency",component:we},{label:"sheet.numfmt.date",component:Be},{label:"sheet.numfmt.thousandthPercentile",component:Ye},{label:"sheet.numfmt.customFormat",component:Ae}].map(T=>({...T,label:c(T.label)})),[]),[f,p]=_.useState(C),[v,g]=_.useState(()=>`${r}_${i}`),{mark:y,userHabitCurrency:h}=Re(()=>g(`${r}_${i}_userCurrency'`)),P=_.useMemo(()=>{var T;return(T=d.find(F=>F.label===f))==null?void 0:T.component},[f]);function C(){return[Ve,De,Ue,We,Ke].reduce((F,gt,_t)=>F||(gt(n)?d[_t].label:""),"")||d[0].label}const R=d.map(T=>({label:T.label,value:T.label})),D=T=>{p(T),l(()=>t.onChange({type:"change",value:o.current()||""}))},Z=T=>{t.onChange({type:"change",value:T})},ie=()=>{const T=o.current()||"",F=m.getCurrencyType(T);F&&y(F),t.onChange({type:"confirm",value:T})},B=()=>{t.onChange({type:"cancel",value:""})},se={onChange:Z,defaultValue:e,defaultPattern:n,action:o};return _.useEffect(()=>{p(C()),g(`${r}_${i}`)},[r,i]),u.jsxs("div",{className:"numfmt-panel p-b-20",children:[u.jsxs("div",{children:[u.jsx("div",{className:"label m-t-14",children:c("sheet.numfmt.numfmtType")}),u.jsx("div",{className:"m-t-8",children:u.jsx(M.Select,{onChange:D,options:R,value:f,style:{width:"100%"}})}),u.jsx("div",{children:P&&u.jsx(ee.Provider,{value:h,children:_.createElement(P,{...se,key:v})})})]}),u.jsxs("div",{className:"btn-list m-t-14 m-b-20",children:[u.jsx(M.Button,{size:"small",onClick:B,className:"m-r-12",children:c("sheet.numfmt.cancel")}),u.jsx(M.Button,{type:"primary",size:"small",onClick:ie,children:c("sheet.numfmt.confirm")})]})]})};var ze=Object.defineProperty,Je=Object.getOwnPropertyDescriptor,Xe=(t,e,n,r)=>{for(var i=r>1?void 0:r?Je(e,n):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(r?o(e,n,i):o(i))||i);return r&&i&&ze(e,n,i),i},x=(t,e)=>(n,r)=>e(n,r,t);const pe="SHEET_NUMFMT_PANEL";let A=class extends s.Disposable{constructor(e,n,r,i,a,o,c,l,d,f){super();z(this,"_previewPattern","");z(this,"_sidebarDisposable",null);this._sheetInterceptorService=e,this._themeService=n,this._univerInstanceService=r,this._commandService=i,this._selectionManagerService=a,this._renderManagerService=o,this._numfmtService=c,this._componentManager=l,this._sidebarService=d,this._localeService=f,this._initRealTimeRenderingInterceptor(),this._initPanel(),this._initCommands(),this._initCloseListener(),this._commandExecutedListener()}openPanel(){var P;const e=this._sidebarService,n=this._selectionManagerService,r=this._commandService,i=this._univerInstanceService,a=this._numfmtService,o=this._localeService,l=(((P=n.getCurrentSelections())==null?void 0:P.map(C=>C.range))||[])[0];if(!l)return!1;const d=i.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),f=d.getActiveSheet();if(!f)return!1;const p=f.getCellRaw(l.startRow,l.startColumn),v=a.getValue(d.getUnitId(),f.getSheetId(),l.startRow,l.startColumn);let g="";v&&(g=v.pattern);const y=(p==null?void 0:p.t)===s.CellValueType.NUMBER?p.v:12345678,h={onChange:C=>{var R;if(C.type==="change")this._previewPattern=C.value,this._forceUpdate();else if(C.type==="confirm"){const D=((R=n.getCurrentSelections())==null?void 0:R.map(B=>B.range))||[],Z={values:[]},ie=m.getPatternType(C.value);D.forEach(B=>{s.Range.foreach(B,(se,T)=>{Z.values.push({row:se,col:T,pattern:C.value,type:ie})})}),r.executeCommand(m.SetNumfmtCommand.id,Z),e.close()}else C.type==="cancel"&&e.close()},value:{defaultPattern:g,defaultValue:y,row:l.startRow,col:l.startColumn}};return this._sidebarDisposable=e.open({header:{title:o.t("sheet.numfmt.title")},children:{label:pe,...h},onClose:()=>{this._forceUpdate(),r.executeCommand($.id)}}),!0}_forceUpdate(e){var r;const n=this._renderManagerService.getRenderById(e!=null?e:this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET).getUnitId());n==null||n.with(E.SheetSkeletonManagerService).reCalculate(),(r=n==null?void 0:n.mainComponent)==null||r.makeDirty()}_initCommands(){[L,$].forEach(e=>{this.disposeWithMe(this._commandService.registerCommand(e))})}_initPanel(){this._componentManager.register(pe,Ze)}_initRealTimeRenderingInterceptor(){const e=new O.Observable(r=>{this._commandService.onCommandExecuted(i=>{i.id===L.id&&r.next(!0),i.id===$.id&&r.next(!1)})}),n=O.combineLatest([e,this._selectionManagerService.selectionMoveEnd$.pipe(V.map(r=>r?r.map(i=>i.range):[]))]);this.disposeWithMe(s.toDisposable(n.pipe(V.switchMap(([r,i])=>new O.Observable(a=>{const o=new s.DisposableCollection;return r&&i.length&&a.next({selectionRanges:i,disposableCollection:o}),()=>{o.dispose()}})),V.tap(()=>{this._previewPattern=null})).subscribe(({disposableCollection:r,selectionRanges:i})=>{var o,c;const a=this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET);this.openPanel(),r.add(this._sheetInterceptorService.intercept(S.INTERCEPTOR_POINT.CELL_CONTENT,{priority:99,effect:s.InterceptorEffectEnum.Value|s.InterceptorEffectEnum.Style,handler:(l,d,f)=>{const{row:p,col:v}=d,g=f(l)||{};if(i.find(y=>y.startColumn<=v&&y.endColumn>=v&&y.startRow<=p&&y.endRow>=p)){const y=d.worksheet.getCellRaw(p,v),h=y==null?void 0:y.v,P=y==null?void 0:y.t;if(h==null||P!==s.CellValueType.NUMBER||this._previewPattern===null)return g;const C=m.getPatternPreviewIgnoreGeneral(this._previewPattern,h,this._localeService.getCurrentLocale());if(C.color){const D=this._themeService.getCurrentTheme()[`${C.color}500`];return{...g,v:C.result,t:s.CellValueType.STRING,s:{cl:{rgb:D}}}}return{...g,v:C.result,t:s.CellValueType.STRING}}return g}})),(c=(o=this._renderManagerService.getRenderById(a.getUnitId()))==null?void 0:o.mainComponent)==null||c.makeDirty()})))}_commandExecutedListener(){const e=[S.RemoveNumfmtMutation.id,S.SetNumfmtMutation.id];this.disposeWithMe(new O.Observable(n=>{const r=this._commandService.onCommandExecuted(i=>{if(e.includes(i.id)){const a=i.params;n.next(a.unitId)}});return()=>r.dispose()}).pipe(V.debounceTime(16)).subscribe(n=>this._forceUpdate(n)))}_initCloseListener(){this._univerInstanceService.getCurrentTypeOfUnit$(s.UniverInstanceType.UNIVER_SHEET).subscribe(e=>{var n;e||((n=this._sidebarDisposable)==null||n.dispose(),this._sidebarDisposable=null)})}};A=Xe([x(0,s.Inject(S.SheetInterceptorService)),x(1,s.Inject(s.ThemeService)),x(2,s.IUniverInstanceService),x(3,s.ICommandService),x(4,s.Inject(S.SheetsSelectionsService)),x(5,U.IRenderManagerService),x(6,S.INumfmtService),x(7,s.Inject(I.ComponentManager)),x(8,I.ISidebarService),x(9,s.Inject(s.LocaleService))],A);var Qe=Object.defineProperty,$e=Object.getOwnPropertyDescriptor,qe=(t,e,n,r)=>{for(var i=r>1?void 0:r?$e(e,n):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(r?o(e,n,i):o(i))||i);return r&&i&&Qe(e,n,i),i},W=(t,e)=>(n,r)=>e(n,r,t);const et=()=>{let t=[];return{add:(i,a,o,c,l)=>t.push({unitId:i,subUnitId:a,row:o,col:c,value:l}),getEffects:()=>t,clean:()=>{t=[]}}};let G=class extends s.Disposable{constructor(e,n,r,i,a){super();z(this,"_collectEffectMutation",et());this._sheetInterceptorService=e,this._numfmtService=n,this._univerInstanceService=r,this._injector=i,this._editorBridgeService=a,this._initInterceptorEditorStart(),this._initInterceptorEditorEnd(),this._initInterceptorCommands()}_initInterceptorEditorStart(){this._editorBridgeService&&this.disposeWithMe(s.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(S.BEFORE_CELL_EDIT,{handler:(e,n,r)=>{const i=n.row,a=n.col,o=this._numfmtService.getValue(n.unitId,n.subUnitId,i,a);if(o)switch(m.getPatternType(o.pattern)){case"scientific":case"currency":case"grouped":case"number":return n.worksheet.getCellRaw(i,a);case"percent":case"date":case"time":case"datetime":default:return r&&r(e)}return r(e)}})))}_initInterceptorEditorEnd(){this.disposeWithMe(s.toDisposable(this._sheetInterceptorService.writeCellInterceptor.intercept(S.AFTER_CELL_EDIT,{handler:(e,n,r)=>{var f,p,v,g;this._collectEffectMutation.clean();const i=this._numfmtService.getValue(n.unitId,n.subUnitId,n.row,n.col),a=(f=i&&m.getPatternType(i.pattern))!=null?f:"",o=()=>{i&&this._collectEffectMutation.add(n.unitId,n.subUnitId,n.row,n.col,null)};if(!(e!=null&&e.v)&&!(e!=null&&e.p)||(i==null?void 0:i.pattern)===J.DEFAULT_TEXT_FORMAT||e.t===s.CellValueType.FORCE_STRING)return r(e);const c=(p=e.p)==null?void 0:p.body,l=(g=(v=e==null?void 0:e.p)==null?void 0:v.body)!=null&&g.dataStream?e.p.body.dataStream.replace(/\r\n$/,""):String(e.v),d=s.numfmt.parseDate(l)||s.numfmt.parseTime(l)||s.numfmt.parseNumber(l);if(c)if(nt(c)){const{dataStream:y}=c,h=y.replace(/\r\n$/,""),P=Number(h);if(Number.isNaN(P)&&!d)return r(e)}else return r(e);if(d){d.z&&this._collectEffectMutation.add(n.unitId,n.subUnitId,n.row,n.col,{pattern:d.z});const y=Number(d.v);return r({...e,p:void 0,v:y,t:s.CellValueType.NUMBER})}else(["date","time","datetime","percent"].includes(a)||!tt(l))&&o();return r(e)}})))}_initInterceptorCommands(){const e=this;this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations(n){var r;switch(n.id){case S.SetRangeValuesCommand.id:{const i=e._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),a=i.getUnitId(),o=(r=i.getActiveSheet())==null?void 0:r.getSheetId();if(!o)return{redos:[],undos:[]};const c=e._collectEffectMutation.getEffects();if(e._collectEffectMutation.clean(),!c.length)return{redos:[],undos:[]};const l=c.filter(v=>{var g;return!!((g=v.value)!=null&&g.pattern)}).map(v=>({row:v.row,col:v.col,pattern:v.value.pattern})),d=c.filter(v=>{var g;return!((g=v.value)!=null&&g.pattern)}).map(v=>({startRow:v.row,endColumn:v.col,startColumn:v.col,endRow:v.row})),f=[],p=[];if(l.length){const v={id:S.SetNumfmtMutation.id,params:S.transformCellsToRange(a,o,l)};f.push(v),p.push(...S.factorySetNumfmtUndoMutation(e._injector,v.params))}if(d.length){const v={id:S.RemoveNumfmtMutation.id,params:{unitId:a,subUnitId:o,ranges:d}};f.push(v),p.push(...S.factoryRemoveNumfmtUndoMutation(e._injector,v.params))}return{redos:f,undos:p.reverse()}}}return{redos:[],undos:[]}}}))}};G=qe([W(0,s.Inject(S.SheetInterceptorService)),W(1,s.Inject(S.INumfmtService)),W(2,s.Inject(s.IUniverInstanceService)),W(3,s.Inject(s.Injector)),W(4,s.Optional(E.IEditorBridgeService))],G);function tt(t){return/^-?\d+(\.\d+)?$/.test(t)}function nt(t){const{textRuns:e=[],paragraphs:n=[],customRanges:r,customBlocks:i=[]}=t,a=["va"];return!(e.some(o=>!!(o.ts&&Object.keys(o.ts).some(l=>a.includes(l))))||n.some(o=>o.bullet)||n.length>=2||r!=null&&r.length||i.length>0)}const K=[{label:"sheet.numfmt.general",pattern:null},{label:"sheet.numfmt.text",pattern:J.DEFAULT_TEXT_FORMAT},"|",{label:"sheet.numfmt.number",pattern:"0"},"|",{label:"sheet.numfmt.accounting",pattern:'"¥" #,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.financialValue",pattern:"#,##0.00;[Red]#,##0.00"},{label:"sheet.numfmt.currency",pattern:'"¥"#,##0.00_);[Red]("¥"#,##0.00)'},{label:"sheet.numfmt.roundingCurrency",pattern:'"¥"#,##0;[Red]"¥"#,##0'},"|",{label:"sheet.numfmt.date",pattern:"yyyy-mm-dd;@"},{label:"sheet.numfmt.time",pattern:'am/pm h":"mm":"ss'},{label:"sheet.numfmt.dateTime",pattern:"yyyy-m-d am/pm h:mm"},{label:"sheet.numfmt.timeDuration",pattern:"h:mm:ss"},"|",{label:"sheet.numfmt.moreFmt",pattern:""}],rt=t=>({icon:new O.Observable(e=>{const n=t.get(m.MenuCurrencyService);function r(a){return{[m.countryCurrencyMap.US]:"DollarSingle",[m.countryCurrencyMap.RU]:"RoubleSingle",[m.countryCurrencyMap.CN]:"RmbSingle",[m.countryCurrencyMap.AT]:"EuroSingle"}[a]||"DollarSingle"}const i=m.countryCurrencyMap[n.getCurrencySymbol()]||"$";return e.next(r(i)),n.currencySymbol$.subscribe(a=>{const o=m.countryCurrencyMap[a]||"$";e.next(r(o))})}),id:m.SetCurrencyCommand.id,title:"sheet.numfmt.currency",tooltip:"sheet.numfmt.currency",type:I.MenuItemType.BUTTON,hidden$:I.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(t,{workbookTypes:[S.WorkbookEditablePermission],worksheetTypes:[S.WorksheetEditPermission,S.WorksheetSetCellStylePermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}),it=t=>({icon:"AddDigitsSingle",id:m.AddDecimalCommand.id,title:"sheet.numfmt.addDecimal",tooltip:"sheet.numfmt.addDecimal",type:I.MenuItemType.BUTTON,hidden$:I.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(t,{workbookTypes:[S.WorkbookEditablePermission],worksheetTypes:[S.WorksheetEditPermission,S.WorksheetSetCellStylePermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}),st=t=>({icon:"ReduceDigitsSingle",id:m.SubtractDecimalCommand.id,title:"sheet.numfmt.subtractDecimal",tooltip:"sheet.numfmt.subtractDecimal",type:I.MenuItemType.BUTTON,hidden$:I.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(t,{workbookTypes:[S.WorkbookEditablePermission],worksheetTypes:[S.WorksheetEditPermission,S.WorksheetSetCellStylePermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}),at=t=>({icon:"PercentSingle",id:m.SetPercentCommand.id,title:"sheet.numfmt.percent",tooltip:"sheet.numfmt.percent",type:I.MenuItemType.BUTTON,hidden$:I.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(t,{workbookTypes:[S.WorkbookEditablePermission],worksheetTypes:[S.WorksheetEditPermission,S.WorksheetSetCellStylePermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}),ot=t=>{const e=t.get(s.IUniverInstanceService),n=t.get(s.ICommandService),r=t.get(s.LocaleService),i=t.get(S.SheetsSelectionsService),a=E.deriveStateFromActiveSheet$(e,"",({workbook:o,worksheet:c})=>new O.Observable(l=>O.merge(i.selectionMoveEnd$,new O.Observable(d=>{const f=[S.RemoveNumfmtMutation.id,S.SetNumfmtMutation.id],p=n.onCommandExecuted(v=>{f.includes(v.id)&&d.next(null)});return()=>p.dispose()})).subscribe(()=>{var f,p;const d=i.getCurrentSelections();if(d&&d[0]){const v=d[0].range,g=v.startRow,y=v.startColumn,h=(p=o.getStyles().get((f=c.getCell(g,y))==null?void 0:f.s))==null?void 0:p.n,P=h==null?void 0:h.pattern;let C=r.t("sheet.numfmt.general");if(P){const R=K.filter(D=>typeof D=="object"&&D.pattern).find(D=>m.isPatternEqualWithoutDecimal(P,D.pattern));R&&typeof R=="object"&&R.pattern?C=r.t(R.label):C=r.t("sheet.numfmt.moreFmt")}l.next(C)}})));return{label:fe,id:L.id,tooltip:"sheet.numfmt.title",type:I.MenuItemType.SELECTOR,selections:[{label:{name:ve,hoverable:!1}}],value$:a,hidden$:I.getMenuHiddenObservable(t,s.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(t,{workbookTypes:[S.WorkbookEditablePermission],worksheetTypes:[S.WorksheetSetCellStylePermission,S.WorksheetEditPermission],rangeTypes:[S.RangeProtectionPermissionEditPoint]})}},fe="sheet.numfmt.moreNumfmtType",ve="sheet.numfmt.moreNumfmtType.options",ct=t=>{var r;const e=s.useDependency(s.LocaleService),n=(r=t.value)!=null?r:e.t("sheet.numfmt.general");return u.jsx("span",{className:"more-numfmt-type",children:n})},lt=()=>{const t=s.useDependency(s.ICommandService),e=s.useDependency(s.LocaleService),n=s.useDependency(I.ILayoutService);s.useInjector();const r=s.useDependency(S.SheetsSelectionsService),i=c=>{const l=r.getCurrentLastSelection();if(!l)return;const d=l.range,f=[];s.Range.foreach(d,(p,v)=>{c?f.push({row:p,col:v,pattern:c,type:m.getPatternType(c)}):f.push({row:p,col:v})}),t.executeCommand(m.SetNumfmtCommand.id,{values:f}),n.focus()},a=c=>{if(c===0)i(null);else if(c===K.length-1)t.executeCommand(L.id);else{const l=K[c];l.pattern&&i(l.pattern)}},o=1220;return u.jsx("div",{className:"more-numfmt-type-options",children:K.map((c,l)=>c==="|"?u.jsx("div",{className:"line m-t-4",onClick:d=>d.stopPropagation()},l):u.jsxs("div",{className:"option-item m-t-4",onClick:()=>{a(l)},children:[u.jsx("div",{children:e.t(c.label)}),u.jsx("div",{className:"m-l-26",children:c.pattern?m.getPatternPreview(c.pattern||"",o,e.getCurrentLocale()).result:""})]},l))})},ut={[I.RibbonStartGroup.FORMULAS_INSERT]:{[m.SetCurrencyCommand.id]:{order:4,menuItemFactory:rt},[m.AddDecimalCommand.id]:{order:5,menuItemFactory:it},[m.SubtractDecimalCommand.id]:{order:6,menuItemFactory:st},[m.SetPercentCommand.id]:{order:7,menuItemFactory:at},[L.id]:{order:8,menuItemFactory:ot}}};var mt=Object.defineProperty,dt=Object.getOwnPropertyDescriptor,pt=(t,e,n,r)=>{for(var i=r>1?void 0:r?dt(e,n):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(r?o(e,n,i):o(i))||i);return r&&i&&mt(e,n,i),i},he=(t,e)=>(n,r)=>e(n,r,t);let Y=class extends s.Disposable{constructor(t,e){super(),this._componentManager=t,this._menuManagerService=e,this._initMenu()}_initMenu(){this._menuManagerService.mergeMenu(ut),this.disposeWithMe(this._componentManager.register(fe,ct)),this.disposeWithMe(this._componentManager.register(ve,lt))}};Y=pt([he(0,s.Inject(I.ComponentManager)),he(1,I.IMenuManagerService)],Y);var Se=Object.defineProperty,ft=Object.getOwnPropertyDescriptor,vt=(t,e,n)=>e in t?Se(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ht=(t,e,n,r)=>{for(var i=r>1?void 0:r?ft(e,n):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(r?o(e,n,i):o(i))||i);return r&&i&&Se(e,n,i),i},re=(t,e)=>(n,r)=>e(n,r,t),ge=(t,e,n)=>vt(t,typeof e!="symbol"?e+"":e,n);const St="SHEET_NUMFMT_UI_PLUGIN";b.UniverSheetsNumfmtUIPlugin=class extends s.Plugin{constructor(e=ae,n,r,i){super(),this._config=e,this._injector=n,this._configService=r,this._renderManagerService=i;const{menu:a,...o}=s.merge({},ae,this._config);a&&this._configService.setConfig("menu",a,{merge:!0}),this._configService.setConfig(I.UI_PLUGIN_CONFIG_KEY,o)}onStarting(){s.registerDependencies(this._injector,[[A],[G],[H],[Y]])}onRendered(){this._registerRenderModules(),s.touchDependencies(this._injector,[[A],[G],[Y]])}_registerRenderModules(){[[Q]].forEach(n=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(s.UniverInstanceType.UNIVER_SHEET,n))})}},ge(b.UniverSheetsNumfmtUIPlugin,"pluginName",St),ge(b.UniverSheetsNumfmtUIPlugin,"type",s.UniverInstanceType.UNIVER_SHEET),b.UniverSheetsNumfmtUIPlugin=ht([s.DependentOn(E.UniverSheetsUIPlugin,m.UniverSheetsNumfmtPlugin),re(1,s.Inject(s.Injector)),re(2,s.IConfigService),re(3,U.IRenderManagerService)],b.UniverSheetsNumfmtUIPlugin),Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-numfmt-ui",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "UniverSheet numfmt plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -54,26 +54,27 @@
|
|
|
54
54
|
"rxjs": ">=7.0.0"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@univerjs/icons": "^0.2.
|
|
58
|
-
"@univerjs/core": "0.5.
|
|
59
|
-
"@univerjs/design": "0.5.
|
|
60
|
-
"@univerjs/engine-
|
|
61
|
-
"@univerjs/
|
|
62
|
-
"@univerjs/
|
|
63
|
-
"@univerjs/
|
|
64
|
-
"@univerjs/sheets-numfmt": "0.5.
|
|
65
|
-
"@univerjs/ui": "0.5.
|
|
57
|
+
"@univerjs/icons": "^0.2.12",
|
|
58
|
+
"@univerjs/core": "0.5.4",
|
|
59
|
+
"@univerjs/design": "0.5.4",
|
|
60
|
+
"@univerjs/engine-formula": "0.5.4",
|
|
61
|
+
"@univerjs/engine-numfmt": "0.5.4",
|
|
62
|
+
"@univerjs/engine-render": "0.5.4",
|
|
63
|
+
"@univerjs/sheets": "0.5.4",
|
|
64
|
+
"@univerjs/sheets-numfmt": "0.5.4",
|
|
65
|
+
"@univerjs/sheets-ui": "0.5.4",
|
|
66
|
+
"@univerjs/ui": "0.5.4"
|
|
66
67
|
},
|
|
67
68
|
"devDependencies": {
|
|
68
69
|
"less": "^4.2.1",
|
|
69
70
|
"postcss": "^8.4.49",
|
|
70
71
|
"react": "18.3.1",
|
|
71
72
|
"rxjs": "^7.8.1",
|
|
73
|
+
"tailwindcss": "^3.4.17",
|
|
72
74
|
"typescript": "^5.7.2",
|
|
73
|
-
"vite": "^6.0.
|
|
75
|
+
"vite": "^6.0.7",
|
|
74
76
|
"vitest": "^2.1.8",
|
|
75
|
-
"@univerjs-infra/shared": "0.5.
|
|
76
|
-
"@univerjs/engine-formula": "0.5.3"
|
|
77
|
+
"@univerjs-infra/shared": "0.5.4"
|
|
77
78
|
},
|
|
78
79
|
"scripts": {
|
|
79
80
|
"test": "vitest run",
|