@univerjs/sheets-table 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/facade.js +207 -1
- package/lib/cjs/index.js +3944 -1
- package/lib/es/facade.js +208 -1
- package/lib/es/index.js +3893 -1
- package/lib/facade.js +208 -1
- package/lib/index.js +3893 -1
- package/lib/umd/index.js +1 -1
- package/package.json +6 -6
package/lib/es/index.js
CHANGED
|
@@ -1 +1,3893 @@
|
|
|
1
|
-
import{BorderStyleTypes as e,CellValueType as t,CommandType as n,Disposable as r,ICommandService as i,IConfigService as a,ILogService as o,IResourceManagerService as s,IUndoRedoService as c,IUniverInstanceService as l,Inject as u,Injector as d,InterceptorEffectEnum as f,LocaleService as p,Plugin as m,RTree as h,Rectangle as g,UniverInstanceType as _,createREGEXFromWildChar as v,customNameCharacterCheck as y,generateRandomId as b,merge as ee,registerDependencies as te,sequenceExecute as x,touchDependencies as ne}from"@univerjs/core";import{IDefinedNamesService as re,RemoveSuperTableMutation as ie,SetSuperTableMutation as ae}from"@univerjs/engine-formula";import{AddRangeThemeMutation as oe,CopySheetCommand as se,IExclusiveRangeService as ce,INTERCEPTOR_POINT as le,InsertColCommand as ue,InsertColMutation as de,InsertRowCommand as fe,InsertRowMutation as pe,RangeThemeStyle as me,RefRangeService as he,RemoveColCommand as ge,RemoveColMutation as _e,RemoveRangeThemeMutation as ve,RemoveRowCommand as ye,RemoveRowMutation as be,RemoveSheetCommand as xe,SheetInterceptorService as Se,SheetRangeThemeModel as Ce,SheetRangeThemeService as we,SheetsSelectionsService as S,ZebraCrossingCacheController as Te,getMoveRangeUndoRedoMutations as C,getSheetCommandTarget as w}from"@univerjs/sheets";import{BehaviorSubject as Ee,Subject as T,filter as De,switchMap as Oe}from"rxjs";let E=function(e){return e.Insert=`insert`,e.Delete=`delete`,e}({}),D=function(e){return e.Row=`row`,e.Col=`column`,e}({}),ke=function(e){return e.None=`none`,e.String=`string`,e.Number=`number`,e.Date=`date`,e.Bool=`bool`,e.Checkbox=`checkbox`,e.List=`list`,e}({}),O=function(e){return e.manual=`manual`,e.condition=`condition`,e}({}),k=function(e){return e.Date=`date`,e.Number=`number`,e.String=`string`,e.Logic=`logic`,e}({}),A=function(e){return e.Equal=`equal`,e.NotEqual=`notEqual`,e.GreaterThan=`greaterThan`,e.GreaterThanOrEqual=`greaterThanOrEqual`,e.LessThan=`lessThan`,e.LessThanOrEqual=`lessThanOrEqual`,e.Between=`between`,e.NotBetween=`notBetween`,e.Above=`above`,e.Below=`below`,e.TopN=`topN`,e}({}),j=function(e){return e.Equal=`equal`,e.NotEqual=`notEqual`,e.Contains=`contains`,e.NotContains=`notContains`,e.StartsWith=`startsWith`,e.EndsWith=`endsWith`,e}({}),M=function(e){return e.Equal=`equal`,e.NotEqual=`notEqual`,e.After=`after`,e.AfterOrEqual=`afterOrEqual`,e.Before=`before`,e.BeforeOrEqual=`beforeOrEqual`,e.Between=`between`,e.NotBetween=`notBetween`,e.Today=`today`,e.Yesterday=`yesterday`,e.Tomorrow=`tomorrow`,e.ThisWeek=`thisWeek`,e.LastWeek=`lastWeek`,e.NextWeek=`nextWeek`,e.ThisMonth=`thisMonth`,e.LastMonth=`lastMonth`,e.NextMonth=`nextMonth`,e.ThisQuarter=`thisQuarter`,e.LastQuarter=`lastQuarter`,e.NextQuarter=`nextQuarter`,e.ThisYear=`thisYear`,e.LastYear=`lastYear`,e.NextYear=`nextYear`,e.YearToDate=`yearToDate`,e.Quarter=`quarter`,e.Month=`month`,e.M1=`m1`,e.M2=`m2`,e.M3=`m3`,e.M4=`m4`,e.M5=`m5`,e.M6=`m6`,e.M7=`m7`,e.M8=`m8`,e.M9=`m9`,e.M10=`m10`,e.M11=`m11`,e.M12=`m12`,e.Q1=`q1`,e.Q2=`q2`,e.Q3=`q3`,e.Q4=`q4`,e}({}),N=function(e){return e[e.FilteredSortNone=1]=`FilteredSortNone`,e[e.FilteredSortAsc=2]=`FilteredSortAsc`,e[e.FilteredSortDesc=3]=`FilteredSortDesc`,e[e.FilterNoneSortNone=4]=`FilterNoneSortNone`,e[e.FilterNoneSortAsc=5]=`FilterNoneSortAsc`,e[e.FilterNoneSortDesc=6]=`FilterNoneSortDesc`,e}({}),P=function(e){return e.Asc=`asc`,e.Desc=`desc`,e.None=`none`,e}({});function F(e,t){return`${t} ${e}`}const Ae=`TRUE`,je=`FALSE`,Me=e=>{var t;return((t=e.body)==null?void 0:t.dataStream.replace(/\r\n$/,``))||``};function Ne(e){if(e){let{v:n,t:r,p:i}=e;return i?Me(i):(r===t.FORCE_STRING||r===t.STRING)&&n!=null?String(n):r===t.BOOLEAN?n?Ae:je:r===t.NUMBER?String(n):typeof n==`boolean`?n?Ae:je:n==null?``:String(n)}return``}function Pe(e,t){if(e!=null)switch(t){case P.Asc:return N.FilteredSortAsc;case P.Desc:return N.FilteredSortDesc;default:return N.FilteredSortNone}else switch(t){case P.Asc:return N.FilterNoneSortAsc;case P.Desc:return N.FilterNoneSortDesc;default:return N.FilterNoneSortNone}}function Fe(e){return e?e.filterType===O.condition:!1}function Ie(e){return e?e.filterType===O.manual:!1}function Le(e,t){let{univerInstanceService:n,tableManager:r,definedNamesService:i}=t,a=new Set,o=n==null?void 0:n.getUnit(e,_.UNIVER_SHEET);o&&o.getSheets().forEach(e=>{a.add(e.getName().toLowerCase())});let s=r==null?void 0:r.getTableList(e);s&&s.length>0&&s.forEach(e=>{a.add(e.name.toLowerCase())});let c=i==null?void 0:i.getDefinedNameMap(e);return c&&Object.values(c).forEach(e=>{a.add(e.name.toLowerCase())}),a}const I={s:e.THIN,cl:{rgb:`rgb(95, 101, 116)`}},Re=`sheets-table.config`;Symbol(Re);const ze={},Be={headerRowStyle:{bd:{t:I}},headerColumnStyle:{bd:{l:I}},lastColumnStyle:{bd:{r:I}},lastRowStyle:{bd:{b:I}}},Ve=(e,t)=>{if(e===`headerRowStyle`){if(!t.bd)return{...t,bd:{t:I}}}else if(e===`lastRowStyle`){if(!t.bd)return{...t,bd:{b:I}}}else if(e===`lastColumnStyle`){if(!t.bd)return{...t,bd:{r:I}}}else if(e===`headerColumnStyle`&&!t.bd)return{...t,bd:{l:I}};return t},He=[[[`#6280F9`,`#FFFFFF`,`#BAC6F8`,`#D2DAFA`],[`#fff`]],[[`#16BDCA`,`#FFFFFF`,`#EDFAFA`,`#AFECEF`],[`#000`]],[[`#31C48D`,`#FFFFFF`,`#F3FAF7`,`#BCF0DA`],[`#fff`]],[[`#AC94FA`,`#FFFFFF`,`#F6F5FF`,`#EDEBFE`],[`#fff`]],[[`#F17EBB`,`#FFFFFF`,`#FDF2F8`,`#FCE8F3`],[`#fff`]],[[`#F98080`,`#FFFFFF`,`#FDF2F2`,`#FDE8E8`],[`#fff`]]].map((e,t)=>{let[n,r]=e,[i,a,o,s]=n,[c]=r;return{name:`table-default-${t}`,style:{headerRowStyle:{bg:{rgb:i},cl:{rgb:c},bd:{t:I}},headerColumnStyle:{bd:{l:I}},firstRowStyle:{bg:{rgb:a}},secondRowStyle:{bg:{rgb:o}},lastRowStyle:{bg:{rgb:s},bd:{b:I}},lastColumnStyle:{bd:{r:I}}}}});function L(e){"@babel/helpers - typeof";return L=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},L(e)}function Ue(e,t){if(L(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(L(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function We(e){var t=Ue(e,`string`);return L(t)==`symbol`?t:t+``}function R(e,t,n){return(t=We(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var z=class{constructor(e,t){R(this,`dataType`,void 0),R(this,`id`,void 0),R(this,`displayName`,void 0),R(this,`formula`,void 0),R(this,`meta`,void 0),R(this,`style`,void 0),this.id=e,this.displayName=t,this.dataType=ke.String,this.formula=``,this.meta={},this.style={}}getMeta(){return this.meta}setMeta(e){this.meta=e}getDisplayName(){return this.displayName}toJSON(){return{id:this.id,displayName:this.displayName,dataType:this.dataType,formula:this.formula,meta:this.meta,style:this.style}}fromJSON(e){this.id=e.id,this.displayName=e.displayName,this.dataType=e.dataType,this.formula=e.formula,this.meta=e.meta,this.style=e.style}};const Ge=e=>e.getMonth()<=2,Ke=e=>{let t=e.getMonth();return t>2&&t<=5},qe=e=>{let t=e.getMonth();return t>5&&t<=8},Je=e=>{let t=e.getMonth();return t>8&&t<=11},Ye=e=>e.getMonth()===0,Xe=e=>e.getMonth()===1,Ze=e=>e.getMonth()===2,Qe=e=>e.getMonth()===3,$e=e=>e.getMonth()===4,et=e=>e.getMonth()===5,tt=e=>e.getMonth()===6,nt=e=>e.getMonth()===7,rt=e=>e.getMonth()===8,it=e=>e.getMonth()===9,at=e=>e.getMonth()===10,ot=e=>e.getMonth()===11,st=(e,t=new Date)=>e.toDateString()===t.toDateString(),ct=(e,t=new Date)=>{let n=new Date(t);return n.setDate(n.getDate()+1),e.toDateString()===n.toDateString()},lt=(e,t=new Date)=>{let n=new Date(t);return n.setDate(n.getDate()-1),e.toDateString()===n.toDateString()},B=e=>{let t=e.getDay(),n=e.getDate()-t+(t===0?-6:1),r=new Date(e);return r.setDate(n),r},ut=10080*60*1e3,dt=(e,t=new Date)=>{let n=B(e),r=B(t);return n.toDateString()===r.toDateString()},ft=(e,t=new Date)=>{let n=B(e),r=new Date(B(t).getTime()+ut);return n.toDateString()===r.toDateString()},pt=(e,t=new Date)=>{let n=B(e),r=new Date(B(t).getTime()-ut);return n.toDateString()===r.toDateString()},mt=(e,t=new Date)=>e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth(),ht=e=>{let t=new Date(e);return t.setHours(0,0,0,0),t.setDate(1),t},gt=(e,t=new Date)=>{let n=new Date(t);n.setHours(0,0,0,0),n.setMonth(n.getMonth()+1,1);let r=new Date(n);r.setMonth(r.getMonth()+1,0);let i=e.getTime();return i>=n.getTime()&&i<r.getTime()},_t=(e,t=new Date)=>{let n=ht(t),r=new Date(n);r.setMonth(r.getMonth()+1,0);let i=e.getTime();return i>=n.getTime()&&i<r.getTime()},vt=e=>{let t=new Date(e);t.setHours(0,0,0,0),t.setDate(1);let n=t.getMonth();return t.setMonth(n-n%3),t},yt=(e,t=new Date)=>{let n=vt(t),r=new Date(n);r.setMonth(r.getMonth()+3);let i=e.getTime();return i>=n.getTime()&&i<r.getTime()},bt=(e,t=new Date)=>{let n=vt(t),r=new Date(n);r.setMonth(r.getMonth()+3);let i=new Date(r);i.setMonth(i.getMonth()+3,0);let a=e.getTime();return a>=r.getTime()&&a<i.getTime()},xt=(e,t=new Date)=>{let n=vt(t),r=new Date(n);r.setMonth(r.getMonth()-3);let i=new Date(n);i.setDate(0);let a=e.getTime();return a>=r.getTime()&&a<i.getTime()},St=(e,t=new Date)=>e.getFullYear()===t.getFullYear(),Ct=(e,t=new Date)=>e.getFullYear()===t.getFullYear()+1,wt=(e,t=new Date)=>e.getFullYear()===t.getFullYear()-1,Tt=(e,t=new Date)=>{let n=new Date(t);n.setHours(0,0,0,0),n.setMonth(0,1);let r=e.getTime();return r>=n.getTime()&&r<t.getTime()};function Et(e){switch(e.compareType){case M.Equal:{let t=new Date(e.expectedValue);return e=>e.getTime()===t.getTime()}case M.NotEqual:{let t=new Date(e.expectedValue);return e=>e.getTime()!==t.getTime()}case M.After:{let t=new Date(e.expectedValue);return e=>e.getTime()>t.getTime()}case M.Before:{let t=new Date(e.expectedValue);return e=>e.getTime()<t.getTime()}case M.AfterOrEqual:{let t=new Date(e.expectedValue);return e=>e.getTime()>=t.getTime()}case M.BeforeOrEqual:{let t=new Date(e.expectedValue);return e=>e.getTime()<=t.getTime()}case M.Between:return t=>{let[n,r]=e.expectedValue;return t.getTime()>=new Date(n).getTime()&&t.getTime()<=new Date(r).getTime()};case M.NotBetween:return t=>{let[n,r]=e.expectedValue;return t.getTime()<new Date(n).getTime()||t.getTime()>new Date(r).getTime()};case M.Today:{let t=e.anchorTime?new Date(e.anchorTime):new Date;return e=>st(e,t)}case M.Yesterday:{let t=e.anchorTime?new Date(e.anchorTime):new Date;return e=>lt(e,t)}case M.Tomorrow:{let t=e.anchorTime?new Date(e.anchorTime):new Date;return e=>ct(e,t)}case M.ThisWeek:{let t=e.anchorTime?new Date(e.anchorTime):new Date;return e=>dt(e,t)}case M.LastWeek:{let t=e.anchorTime?new Date(e.anchorTime):new Date;return e=>pt(e,t)}case M.NextWeek:{let t=e.anchorTime?new Date(e.anchorTime):new Date;return e=>ft(e,t)}case M.ThisMonth:{let t=e.anchorTime?new Date(e.anchorTime):new Date;return e=>mt(e,t)}case M.LastMonth:{let t=e.anchorTime?new Date(e.anchorTime):new Date;return e=>_t(e,t)}case M.NextMonth:{let t=e.anchorTime?new Date(e.anchorTime):new Date;return e=>gt(e,t)}case M.ThisQuarter:{let t=e.anchorTime?new Date(e.anchorTime):new Date;return e=>yt(e,t)}case M.LastQuarter:{let t=e.anchorTime?new Date(e.anchorTime):new Date;return e=>xt(e,t)}case M.NextQuarter:{let t=e.anchorTime?new Date(e.anchorTime):new Date;return e=>bt(e,t)}case M.ThisYear:{let t=e.anchorTime?new Date(e.anchorTime):new Date;return e=>St(e,t)}case M.LastYear:{let t=e.anchorTime?new Date(e.anchorTime):new Date;return e=>wt(e,t)}case M.NextYear:{let t=e.anchorTime?new Date(e.anchorTime):new Date;return e=>Ct(e,t)}case M.YearToDate:{let t=e.anchorTime?new Date(e.anchorTime):new Date;return e=>Tt(e,t)}case M.M1:return Ye;case M.M2:return Xe;case M.M3:return Ze;case M.M4:return Qe;case M.M5:return $e;case M.M6:return et;case M.M7:return tt;case M.M8:return nt;case M.M9:return rt;case M.M10:return it;case M.M11:return at;case M.M12:return ot;case M.Q1:return Ge;case M.Q2:return Ke;case M.Q3:return qe;case M.Q4:return Je;default:throw Error(`Unsupported compare type`)}}var Dt=class{constructor(){R(this,`heap`,void 0),this.heap=[]}swap(e,t){let n=this.heap[e];this.heap[e]=this.heap[t],this.heap[t]=n}getParentIndex(e){return Math.floor((e-1)/2)}getLeftIndex(e){return e*2+1}getRightIndex(e){return e*2+2}size(){return this.heap.length}peek(){return this.heap[0]}include(e){return this.heap.includes(e)}},Ot=class extends Dt{constructor(){super()}shiftUp(e){if(e===0)return;let t=this.getParentIndex(e);this.heap[t]>this.heap[e]&&(this.swap(t,e),this.shiftUp(t))}shiftDown(e){let t=this.getLeftIndex(e),n=this.getRightIndex(e);this.heap[t]<this.heap[e]&&(this.swap(t,e),this.shiftDown(t)),this.heap[n]<this.heap[e]&&(this.swap(n,e),this.shiftDown(n))}insert(e){this.heap.push(e),this.shiftUp(this.heap.length-1)}pop(){this.heap[0]=this.heap.pop(),this.shiftDown(0)}};const kt=(e,t)=>{let n=new Ot;for(let r of e)n.insert(r),n.size()>t&&n.pop();return n.heap},At=(e,t)=>e>t,jt=(e,t)=>e<t,Mt=(e,t,n)=>kt(e,t).includes(n);function Nt(e,t){switch(e.compareType){case A.Equal:{let t=Number(e.expectedValue);return e=>e===t}case A.NotEqual:{let t=Number(e.expectedValue);return e=>e!==t}case A.GreaterThan:{let t=Number(e.expectedValue);return e=>e>t}case A.GreaterThanOrEqual:{let t=Number(e.expectedValue);return e=>e>=t}case A.LessThan:{let t=Number(e.expectedValue);return e=>e<t}case A.LessThanOrEqual:{let t=Number(e.expectedValue);return e=>e<=t}case A.Between:{let[t,n]=e.expectedValue,r=Number(t),i=Number(n);return r>i?e=>e>=i&&e<=r:e=>e>=r&&e<=i}case A.NotBetween:{let[t,n]=e.expectedValue,r=Number(t),i=Number(n);return r>i?e=>e<i||e>r:e=>e<r||e>i}case A.Above:{let e=t.average;return t=>At(t,e)}case A.Below:{let e=t.average;return t=>jt(t,e)}case A.TopN:{let n=t.list,r=Number(e.expectedValue);return e=>Mt(n,r,e)}}}const Pt=(e,t)=>v(t).test(e),Ft=(e,t)=>!v(t).test(e),It=(e,t)=>v(`*${t}*`).test(e),Lt=(e,t)=>!v(`*${t}*`).test(e),Rt=(e,t)=>v(`${t}*`).test(e),zt=(e,t)=>v(`*${t}`).test(e);function Bt(e){switch(e.compareType){case j.Equal:return t=>Pt(t,e.expectedValue);case j.NotEqual:return t=>Ft(t,e.expectedValue);case j.Contains:return t=>It(t,e.expectedValue);case j.NotContains:return t=>Lt(t,e.expectedValue);case j.StartsWith:return t=>Rt(t,e.expectedValue);case j.EndsWith:return t=>zt(t,e.expectedValue);default:return console.error(`Unknown filter operator: ${e.compareType}`),e=>!0}}const Vt=new Set([A.Above,A.Below,A.TopN]);new Set([M.Today,M.Yesterday,M.Tomorrow,M.ThisWeek,M.LastWeek,M.NextWeek,M.ThisMonth,M.LastMonth,M.NextMonth,M.ThisQuarter,M.LastQuarter,M.NextQuarter,M.NextYear,M.ThisYear,M.LastYear,M.YearToDate]);function Ht(e){return Vt.has(e)}function Ut(e,t){if(Ht(e.filterInfo.compareType))return e=>!0;switch(e.filterInfo.conditionType){case k.Date:return Et(e.filterInfo);case k.Number:return Nt(e.filterInfo,t);case k.String:return Bt(e.filterInfo);case k.Logic:default:return e=>!0}}function V(e,t,n,r){switch(r){case k.Date:{let r=Kt(e,t,n);return r?qt(r):null}case k.Number:return Kt(e,t,n);case k.String:default:return Gt(e,t,n)}}const Wt=e=>{var t;return((t=e.body)==null?void 0:t.dataStream.replace(/\r\n$/,``))||``};function Gt(e,n,r){let i=e.getCell(n,r);if(!i)return null;let{v:a,t:o,p:s}=i;if(s)return Wt(s);if(typeof a==`string`)return o===t.BOOLEAN?a.toUpperCase():a;if(typeof a==`number`)return o===t.BOOLEAN?a?`TRUE`:`FALSE`:a;if(typeof a==`boolean`)return a?`TRUE`:`FALSE`;if(a!==void 0)return String(a)}function Kt(e,n,r){let i=e.getCell(n,r);if(!i)return null;let{v:a,t:o,p:s}=i;return s?null:typeof a==`string`&&o===t.NUMBER?Number(e.getCellRaw(n,r).v):Number(a)}function qt(e){let t=new Date(Date.UTC(1900,0,1,0,0,0)),n=new Date(Date.UTC(1900,1,28,0,0,0)),r=e-1;return r>(n.getTime()-t.getTime())/(1e3*3600*24)&&--r,r<0&&(r=e),new Date(t.getTime()+1e3*3600*24*r)}var Jt=class{constructor(){R(this,`_tableColumnFilterList`,void 0),R(this,`_tableSortInfo`,void 0),R(this,`_filterOutRows`,void 0),this._tableColumnFilterList=[]}setColumnFilter(e,t){t?this._tableColumnFilterList[e]=t:this._tableColumnFilterList[e]=void 0}setSortState(e,t){this._tableSortInfo={columnIndex:e,sortState:t}}getColumnFilter(e){return this._tableColumnFilterList[e]}getFilterState(e){var t;let n=((t=this._tableSortInfo)==null?void 0:t.columnIndex)===e?this._tableSortInfo.sortState:P.None;return Pe(this._tableColumnFilterList[e],n)}getSortState(){var e;return(e=this._tableSortInfo)==null?{}:e}getFilterStates(e){let t=[],{startColumn:n,endColumn:r}=e;for(let e=n;e<=r;e++)t.push(this.getFilterState(e-n));return t}getFilterOutRows(){return this._filterOutRows}doFilter(e,t){let n=new Set,r=this._tableColumnFilterList;for(let i=0;i<r.length;i++)r[i]&&this.doColumnFilter(e,t,i,n);return this._filterOutRows=n,n}doColumnFilter(e,t,n,r){let i=this._tableColumnFilterList[n];if(i&&e){let{startRow:a,endRow:o,startColumn:s}=t,c=s+n,l=this.getExecuteFunc(e,t,n,i);for(let t=a;t<=o;t++){let n=Fe(i)?i.filterInfo.conditionType:k.String;V(e,t,c,n)===null?r.add(t):l(V(e,t,c,n))||r.add(t)}}}_getNumberCalculatedOptions(e,t,n){let{startRow:r,endRow:i,startColumn:a}=t,o=a+n,s=[],c=0,l=0;for(let t=r;t<=i;t++){let n=V(e,t,o,k.Number);n!==null&&(s.push(n),c++,l+=n)}return{list:s,average:c>0?l/c:0}}getExecuteFunc(e,t,n,r){if(r.filterType===O.manual){let e=new Set(r.values);return t=>e.has(t)}else if(r.filterType===O.condition)return Ut(r,Ht(r.filterInfo.compareType)?this._getNumberCalculatedOptions(e,t,n):void 0);else return e=>!0}toJSON(){return{tableColumnFilterList:this._tableColumnFilterList,tableSortInfo:this._tableSortInfo}}fromJSON(e){var t;this._tableColumnFilterList=(t=e.tableColumnFilterList)==null?[]:t,e.tableSortInfo&&(this._tableSortInfo=e.tableSortInfo)}dispose(){this._tableColumnFilterList=[]}},Yt=class{constructor(e,t,n,r,i={}){R(this,`_id`,void 0),R(this,`_name`,void 0),R(this,`_tableStyleId`,void 0),R(this,`_showHeader`,void 0),R(this,`_showFooter`,void 0),R(this,`_range`,void 0),R(this,`_columns`,new Map),R(this,`_columnOrder`,[]),R(this,`tableMeta`,void 0),R(this,`_tableFilters`,void 0),R(this,`_subUnitId`,void 0),this._id=e,this._range=n,this._name=t,this._tableFilters=new Jt,this._init(r,i)}_init(e,t){var n;this._tableStyleId=t==null?void 0:t.tableStyleId,this._showHeader=(n=t==null?void 0:t.showHeader)==null?!0:n,this._showFooter=!1;let r=this.getRange(),i=r.startColumn,a=r.endColumn;for(let n=i;n<=a;n++){var o;let r=n-i,a,s;(o=t.columns)!=null&&o[r]?(a=t.columns[r].id,s=t.columns[r].displayName):(a=b(),s=e[n-i]);let c=new z(a,s);this._columns.set(a,c),this._columnOrder.push(a)}t.filters&&t.filters.forEach((e,t)=>{e&&this._tableFilters.setColumnFilter(t,e)})}setTableFilterColumn(e,t){this._tableFilters.setColumnFilter(e,t)}getTableFilterColumn(e){return this._tableFilters.getColumnFilter(e)}getTableFilters(){return this._tableFilters}getTableFilterRange(){let e=this.getRange(),t=this.isShowHeader(),n=this.isShowFooter(),{startRow:r,startColumn:i,endRow:a,endColumn:o}=e;return{startRow:t?r+1:r,startColumn:i,endRow:n?a-1:a,endColumn:o}}setColumns(e){this._columns.clear(),this._columnOrder=[],e.forEach(e=>{let t=new z(e.id,e.displayName);t.fromJSON(e),this._columns.set(e.id,t),this._columnOrder.push(e.id)})}getColumnsCount(){return this._columnOrder.length}insertColumn(e,t){let n=t.id;this._columns.set(n,t),this._columnOrder.splice(e,0,n)}removeColumn(e){let t=this._columnOrder[e];this._columns.delete(t),this._columnOrder.splice(e,1)}setTableMeta(e){this.tableMeta=e}getTableMeta(){return this.tableMeta}getColumn(e){return this._columns.get(e)}getTableColumnByIndex(e){let t=this._columnOrder[e];return this.getColumn(t)}getColumnNameByIndex(e){var t;let n=this._columnOrder[e];return((t=this.getColumn(n))==null?void 0:t.getDisplayName())||``}getId(){return this._id}getRangeInfo(){return{...this._range}}getRange(){return{...this._range}}setRange(e){this._range=e}setDisplayName(e){this._name=e}getDisplayName(){return this._name}getSubunitId(){return this._subUnitId}setSubunitId(e){this._subUnitId=e}getTableStyleId(){var e;return(e=this._tableStyleId)==null?He[0].name:e}setTableStyleId(e){this._tableStyleId=e}isShowHeader(){var e;return(e=this._showHeader)==null?!0:e}setShowHeader(e){this._showHeader=e}isShowFooter(){var e;return(e=this._showFooter)==null?!1:e}getTableInfo(){return{id:this._id,subUnitId:this._subUnitId,name:this._name,range:this.getRangeInfo(),meta:this.tableMeta,showHeader:this._showHeader,columns:this._columnOrder.map(e=>this._columns.get(e).toJSON())}}getTableConfig(){return{name:this.getDisplayName(),range:this.getRangeInfo(),options:{showHeader:this._showHeader,showFooter:this._showFooter},tableStyleId:this._tableStyleId}}getFilterStates(e){return this._tableFilters.getFilterStates(e)}toJSON(){let e=[];return this._columns.forEach(t=>{e.push(t.toJSON())}),{id:this._id,name:this._name,range:this.getRangeInfo(),options:{showHeader:this._showHeader,showFooter:this._showFooter,tableStyleId:this._tableStyleId},filters:this._tableFilters.toJSON(),columns:e,meta:this.tableMeta}}fromJSON(e){var t,n;this._id=e.id,this._name=e.name,this._range=e.range,this.tableMeta=e.meta,this._tableStyleId=e.options.tableStyleId||``,this._showHeader=(t=e.options.showHeader)==null?!0:t,this._showFooter=(n=e.options.showFooter)==null?!0:n,e.columns.forEach(e=>{let t=new z(e.id,e.displayName);t.fromJSON(e),this._columns.set(e.id,t),this._columnOrder.push(e.id)}),this._tableFilters=new Jt,this._tableFilters.fromJSON(e.filters)}dispose(){this._id=``,this._name=``,this._tableStyleId=``,this._showHeader=!0,this._showFooter=!0,delete this._range,this._columns.clear(),this._columnOrder=[]}};function H(e,t){return function(n,r){t(n,r,e)}}function U(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let W=class extends r{constructor(e,t){super(),this._univerInstanceService=e,this._localeService=t,R(this,`_tableMap`,void 0),R(this,`_tableAdd$`,new T),R(this,`tableAdd$`,this._tableAdd$.asObservable()),R(this,`_tableDelete$`,new T),R(this,`tableDelete$`,this._tableDelete$.asObservable()),R(this,`_tableNameChanged$`,new T),R(this,`tableNameChanged$`,this._tableNameChanged$.asObservable()),R(this,`_tableRangeChanged$`,new T),R(this,`tableRangeChanged$`,this._tableRangeChanged$.asObservable()),R(this,`_tableThemeChanged$`,new T),R(this,`tableThemeChanged$`,this._tableThemeChanged$.asObservable()),R(this,`_tableFilterChanged$`,new T),R(this,`tableFilterChanged$`,this._tableFilterChanged$.asObservable()),R(this,`_tableInitStatus`,new Ee(!1)),R(this,`tableInitStatus$`,this._tableInitStatus.asObservable()),this._tableMap=new Map}_ensureUnit(e){return this._tableMap.has(e)||this._tableMap.set(e,new Map),this._tableMap.get(e)}getColumnHeader(e,t,n,r){var i;let a=(i=this._univerInstanceService.getUnit(e))==null?void 0:i.getSheetBySheetId(t),{startRow:o,startColumn:s,endColumn:c}=n,l=[],u=r==null?`Column`:r;for(let e=s;e<=c;e++)l.push(Ne(a==null?void 0:a.getCell(o,e))||F(e-s+1,u));return l}addTable(e,t,n,r,i,a,o){let s=a==null?b():a,c=new Yt(s,n,r,i||this.getColumnHeader(e,t,r),o);if(c.setSubunitId(t),this._ensureUnit(e).set(s,c),this._tableAdd$.next({unitId:e,subUnitId:t,range:r,tableName:n,tableId:s,tableStyleId:o==null?void 0:o.tableStyleId}),o!=null&&o.filters){var l;let n=(l=this._univerInstanceService.getUnit(e))==null?void 0:l.getSheetBySheetId(t);c.getTableFilters().doFilter(n,r),this._tableFilterChanged$.next({unitId:e,subUnitId:t,tableId:s})}return s}addFilter(e,t,n,r){let i=this.getTable(e,t);if(i){i.getTableFilters().setColumnFilter(n,r);let a=i.getSubunitId();this._tableFilterChanged$.next({unitId:e,subUnitId:a,tableId:t})}}getFilterRanges(e,t){let n=this._tableMap.get(e);if(!n)return[];let r=[];return n.forEach(e=>{e.getSubunitId()===t&&e.isShowHeader()&&r.push(e.getRange())}),r}getSheetFilterRangeWithState(e,t){let n=this._tableMap.get(e);if(!n)return[];let r=[];return n.forEach(e=>{e.getSubunitId()===t&&e.isShowHeader()&&r.push({tableId:e.getId(),range:e.getRange(),states:e.getFilterStates(e.getRange())})}),r}getTable(e,t){let n=this._tableMap.get(e);if(n)return n.get(t)}getUniqueTableName(e,t){let n=this._tableMap.get(e);if(!n)return t;let r=new Set(Array.from(n.values()).map(e=>e.getDisplayName())),i=t,a=1;for(;r.has(i);)i=`${t}-${a}`,a++;return i}getTableById(e,t){return this.getTable(e,t)}getTableList(e){let t=this._tableMap.get(e);return t?Array.from(t.values()).map(t=>({...t.getTableInfo(),unitId:e})):[]}getTablesBySubunitId(e,t){let n=this._tableMap.get(e);return n?Array.from(n.values()).filter(e=>e.getSubunitId()===t):[]}getTablesInfoBySubunitId(e,t){return this.getTablesBySubunitId(e,t).map(e=>({id:e.getId(),name:e.getDisplayName(),range:e.getRange()}))}deleteTable(e,t){let n=this._tableMap.get(e),r=n==null?void 0:n.get(t);if(r){let i=r.getTableInfo(),a=r.getTableStyleId();n==null||n.delete(t);let{subUnitId:o,range:s,name:c}=i;this._tableDelete$.next({unitId:e,subUnitId:o,tableId:t,range:s,tableName:c,tableStyleId:a})}}operationTableRowCol(e,t,n){let r=this.getTableById(e,t);if(!r)return;let{operationType:i,rowColType:a,index:o,count:s,columnsJson:c}=n,l=r.getRange(),u={...l};if(i===E.Insert){if(a===`row`)u.endRow+=s;else if(a===`column`){u.endColumn+=s;for(let e=0;e<s;e++){let t=this._localeService.t(`sheets-table.columnPrefix`),n=new z(b(),F(r.getColumnsCount()+1+e,t));c!=null&&c[e]&&n.fromJSON(c[e]);let i=o+e-l.startColumn;r.insertColumn(i,n)}}}else if(a===`row`)u.endRow-=s;else if(a===`column`){u.endColumn-=s;for(let e=s-1;e>=0;e--){let t=o+e-l.startColumn;r.removeColumn(t)}}r.setRange(u),this._tableRangeChanged$.next({unitId:e,subUnitId:r.getSubunitId(),tableId:t,range:u,oldRange:l})}updateTableRange(e,t,n){let r=this.getTableById(e,t);if(!r)return;let i=r.getRange(),a=n.newRange;if(a.startColumn<i.startColumn){let e=i.startColumn-a.startColumn,t=this._localeService.t(`sheets-table.columnPrefix`);for(let n=0;n<e;n++)r.insertColumn(i.startColumn,new z(b(),F(r.getColumnsCount()+1,t)))}else if(a.startColumn>i.startColumn){let e=a.startColumn-i.startColumn;for(let t=e-1;t>=0;t--){let e=a.startColumn+t-i.startColumn;r.removeColumn(e)}}if(a.endColumn<i.endColumn){let e=i.endColumn-a.endColumn;for(let t=e-1;t>=0;t--){let e=a.endColumn+t-i.startColumn;r.removeColumn(e)}}else if(a.endColumn>i.endColumn){let e=a.endColumn-i.endColumn;for(let t=0;t<e;t++)r.insertColumn(i.endColumn,new z(b(),F(r.getColumnsCount()+1,`Column`)))}r.setRange(a),this._tableRangeChanged$.next({unitId:e,subUnitId:r.getSubunitId(),tableId:t,range:a,oldRange:i})}setTableByConfig(e,t,n){let r=this._tableMap.get(e),i=r==null?void 0:r.get(t);if(!i)return;let a=i.getSubunitId(),{name:o,updateRange:s,rowColOperation:c,theme:l,options:u}=n;if(o){let n=i.getDisplayName();i.setDisplayName(o),this._tableNameChanged$.next({unitId:e,subUnitId:a,tableId:t,tableName:o,oldTableName:n})}if(c&&this.operationTableRowCol(e,t,c),s&&this.updateTableRange(e,t,s),l){var d;let n=(d=i.getTableStyleId())==null?`default`:d;i.setTableStyleId(l),this._tableThemeChanged$.next({unitId:e,subUnitId:a,tableId:t,theme:l,oldTheme:n})}u&&u.showHeader!==void 0&&i.setShowHeader(u.showHeader)}toJSON(e){let t={},n=this._tableMap.get(e);return n&&n.forEach(n=>{let r=n.getSubunitId();if(!t[r]){let n=new Set;this.getTablesBySubunitId(e,r).forEach(e=>{let t=e.getTableFilters().getFilterOutRows();if(t)for(let e of t)n.add(e)}),t[r]={tables:[],tableFilteredOutRows:Array.from(n)}}t[r].tables.push(n.toJSON())}),t}fromJSON(e,t){let n=this._ensureUnit(e);Object.keys(t).forEach(r=>{let i=w(this._univerInstanceService,{unitId:e,subUnitId:r});if(!i)return;let a=i.worksheet,o;t[r].tables?o=t[r].tables:Array.isArray(t[r])&&(o=t[r]),o&&o.forEach(t=>{let i=this.getColumnHeader(e,r,t.range),o=new Yt(t.id,t.name,t.range,i,t.options);if(o.setTableMeta(t.meta),t.columns.length&&o.setColumns(t.columns),t.filters){let e=o.getTableFilters();e.fromJSON(t.filters),e.doFilter(a,o.getTableFilterRange())}o.setSubunitId(r),n.set(t.id,o),this._tableAdd$.next({unitId:e,subUnitId:r,range:t.range,tableName:t.name,tableId:t.id})})}),this._tableInitStatus.next(!0)}deleteUnitId(e){let t=this._tableMap.get(e);t&&t.forEach(e=>e.dispose()),this._tableMap.delete(e)}dispose(){super.dispose(),this._tableAdd$.complete(),this._tableDelete$.complete(),this._tableNameChanged$.complete(),this._tableRangeChanged$.complete(),this._tableThemeChanged$.complete(),this._tableFilterChanged$.complete(),this._tableInitStatus.complete(),this._tableMap.forEach(e=>{e.forEach(e=>e.dispose()),e.clear()}),this._tableMap.clear()}};W=U([H(0,l),H(1,u(p))],W);let G=class extends r{constructor(e){super(),this._tableManager=e}getTableInfo(e,t){let n=this._tableManager.getTable(e,t);if(n)return{unitId:e,...n.getTableInfo()}}getTableList(e){return this._tableManager.getTableList(e)}addTable(e,t,n,r,i,a,o){return this._tableManager.addTable(e,t,n,r,i,a,o)}deleteTable(e,t,n){this._tableManager.deleteTable(e,n)}getTableMeta(e,t){var n;return(n=this._tableManager.getTable(e,t))==null?void 0:n.getTableMeta()}setTableMeta(e,t,n){var r;(r=this._tableManager.getTable(e,t))==null||r.setTableMeta(n)}getTableColumnMeta(e,t,n){var r;return(r=this._tableManager.getTable(e,t))==null||(r=r.getTableColumnByIndex(n))==null?void 0:r.getMeta()}selTableColumnMeta(e,t,n,r){var i;(i=this._tableManager.getTable(e,t))==null||(i=i.getTableColumnByIndex(n))==null||i.setMeta(r)}addFilter(e,t,n,r){this._tableManager.addFilter(e,t,n,r)}getCellValueWithConditionType(e,t,n,r=k.String){return V(e,t,n,r)}};G=U([H(0,u(W))],G);const K={id:`sheet.mutation.add-table`,type:n.MUTATION,handler:(e,t)=>{let{tableId:n,unitId:r,subUnitId:i,name:a,range:o,header:s,options:c}=t;return e.get(G).addTable(r,i,a,o,s,n,c),!0}},q={id:`sheet.mutation.delete-table`,type:n.MUTATION,handler:(e,t)=>{let{unitId:n,subUnitId:r,tableId:i}=t;return e.get(G).deleteTable(n,r,i),!0}},Xt={id:`sheet.command.add-table`,type:n.COMMAND,handler:(e,t)=>{var n;if(!t)return!1;let r=e.get(c),a=e.get(i),o=e.get(p),s=e.get(W),u=(n=t.id)==null?b():n,d=Le(t.unitId,{univerInstanceService:e.get(l),tableManager:s,definedNamesService:e.get(re)}),f=t.name;if(!f||!y(f.toLowerCase(),d)){let e=o.t(`sheets-table.tablePrefix`),n=s.getTableList(t.unitId).length+1;for(let t of d)if(t.startsWith(e.toLowerCase())){let r=Number(t.slice(e.length));Number.isInteger(r)&&r>=n&&(n=r+1)}f=`${e}${n}`}let m=[],h=[],{unitId:g,subUnitId:_,range:v}=t,ee=s.getColumnHeader(g,_,v,o.t(`sheets-table.columnPrefix`));return m.push({id:K.id,params:{...t,tableId:u,name:f,header:ee}}),h.push({id:q.id,params:{tableId:u,unitId:t.unitId}}),x(m,a)&&r.pushUndoRedo({unitID:t.unitId,undoMutations:h,redoMutations:m}),!0}},J={id:`sheet.mutation.set-sheet-table`,type:n.MUTATION,handler:(e,t)=>{if(!t)return!1;let{unitId:n,tableId:r,config:i}=t;return e.get(W).setTableByConfig(n,r,i),!0}},Zt={id:`sheet.command.add-table-theme`,type:n.COMMAND,handler:(e,t)=>{if(!t)return!1;let n=e.get(W),{unitId:r,tableId:a,themeStyle:o}=t,s=[],l=[],u=n.getTableById(r,a);if(!u)return!1;let d=u.getSubunitId();return s.push({id:oe.id,params:{unitId:r,subUnitId:d,styleJSON:o.toJson()}}),s.push({id:J.id,params:{unitId:r,subUnitId:d,tableId:a,config:{theme:o.getName()}}}),l.push({id:J.id,params:{unitId:r,subUnitId:d,tableId:a,config:{themeStyle:u.getTableStyleId()}}}),l.push({id:ve.id,params:{unitId:r,subUnitId:d,styleName:o.getName()}}),x(s,e.get(i))&&e.get(c).pushUndoRedo({unitID:r,undoMutations:l,redoMutations:s}),!0}},Qt={id:`sheet.command.delete-table`,type:n.COMMAND,handler:(e,t)=>{if(!t)return!1;let n=e.get(c),r=e.get(i),a=e.get(W),s=e.get(o),l=[],u=[],d=a.getTable(t.unitId,t.tableId),f=d==null?void 0:d.toJSON();return f?(l.push({id:q.id,params:{...t}}),u.push({id:K.id,params:{unitId:t.unitId,subUnitId:t.subUnitId,tableId:t.tableId,name:f.name,range:f.range,options:f.options}}),x(l,r)&&n.pushUndoRedo({unitID:t.unitId,undoMutations:u,redoMutations:l}),!0):(s.error(`[TableManager]: Table not found`),!1)}},$t=`SHEET_TABLE_PLUGIN`,Y=`SHEET_TABLE`,en=`table-custom`,tn={id:`sheet.command.remove-table-theme`,type:n.COMMAND,handler:(e,t)=>{if(!t)return!1;let{unitId:n,tableId:r,themeName:a}=t,o=e.get(W),s=e.get(Ce),l=o.getTableById(n,r);if(!l)return!1;let u=l.getSubunitId(),d=[],f=[],p=s.getRegisteredRangeThemes().filter(e=>e==null?void 0:e.startsWith(`table-default`)),m=s.getRegisteredRangeThemes().filter(e=>e==null?void 0:e.startsWith(en)).find(e=>e!==a);m||(m=p[0]),d.push({id:J.id,params:{unitId:n,subUnitId:u,tableId:r,config:{theme:m}}}),d.push({id:ve.id,params:{unitId:n,subUnitId:u,styleName:a}});let h=s.getDefaultRangeThemeStyle(a);return h&&(f.push({id:oe.id,params:{unitId:n,subUnitId:u,styleJSON:h.toJson()}}),f.push({id:J.id,params:{unitId:n,subUnitId:u,tableId:r,config:{theme:a}}})),x(d,e.get(i))&&e.get(c).pushUndoRedo({unitID:n,redoMutations:d,undoMutations:f}),!0}},nn={id:`sheet.command.set-table-config`,type:n.COMMAND,handler:(e,t)=>{if(!t)return!1;let{unitId:n,tableId:r,name:a,updateRange:s,rowColOperation:u,theme:d}=t,f=e.get(W),m=f.getTableById(n,r);if(!m)return!1;let h={},g={},_=e.get(p),v=Le(n,{univerInstanceService:e.get(l),tableManager:f,definedNamesService:e.get(re)});if(a){if(!y(a.toLowerCase(),v))return e.get(o).warn(_.t(`sheets-table.tableNameError`)),!1;h.name=m.getDisplayName(),g.name=a}u&&(h.rowColOperation={operationType:u.operationType===E.Insert?E.Delete:E.Insert,rowColType:u.rowColType,index:u.index,count:u.count},g.rowColOperation=u),s&&(h.updateRange={newRange:m.getRange()},g.updateRange=s),d&&(h.theme=m.getTableStyleId(),g.theme=d);let b={unitId:n,subUnitId:m.getSubunitId(),tableId:r,config:g};return e.get(i).executeCommand(J.id,b),e.get(c).pushUndoRedo({unitID:n,undoMutations:[{id:J.id,params:{unitId:n,subUnitId:m.getSubunitId(),tableId:r,config:h}}],redoMutations:[{id:J.id,params:b}]}),!0}},X={id:`sheet.mutation.set-table-filter`,type:n.MUTATION,handler:(e,t)=>{let{tableId:n,unitId:r,column:i,tableFilter:a}=t;return e.get(W).addFilter(r,n,i,a),!0}},rn={id:`sheet.command.set-table-filter`,type:n.COMMAND,handler:(e,t)=>{if(!t)return!1;let n=e.get(c),r=e.get(i),a=t.tableId||b(),o=[],s=[];return o.push({id:X.id,params:{...t,tableId:a}}),s.push({id:X.id,params:{...t,tableId:a,tableFilter:void 0}}),x(o,r)&&n.pushUndoRedo({unitID:t.unitId,undoMutations:s,redoMutations:o}),!0}};let Z=class extends r{constructor(e,t,n,r){super(),this._univerInstanceService=e,this._sheetInterceptorService=t,this._tableManager=n,this._resourceManagerService=r,R(this,`_tableRangeRTree`,new Map),this._initSnapshot(),this._initSheetChange(),this.registerTableChangeEvent(),this.registerTableHeaderInterceptor()}getContainerTableWithRange(e,t,n){let r=this._ensureTableRangeRTree(e),i=Array.from(r.bulkSearch([{unitId:e,sheetId:t,range:n}])).find(t=>{let r=this._tableManager.getTable(e,String(t));return r?g.contains(r.getRange(),n):!1});if(i)return this._tableManager.getTable(e,String(i))}_ensureTableRangeRTree(e){return this._tableRangeRTree.has(e)||this._tableRangeRTree.set(e,new h),this._tableRangeRTree.get(e)}registerTableChangeEvent(){this.disposeWithMe(this._tableManager.tableAdd$.subscribe(e=>{let{range:t,tableId:n,unitId:r,subUnitId:i}=e;this._ensureTableRangeRTree(r).insert({unitId:r,sheetId:i,id:n,range:{...t}})})),this.disposeWithMe(this._tableManager.tableRangeChanged$.subscribe(e=>{let{range:t,tableId:n,unitId:r,subUnitId:i,oldRange:a}=e,o=this._ensureTableRangeRTree(r);o.remove({unitId:r,sheetId:i,id:n,range:{...a}}),o.insert({unitId:r,sheetId:i,id:n,range:{...t}})})),this.disposeWithMe(this._tableManager.tableDelete$.subscribe(e=>{let{tableId:t,unitId:n,subUnitId:r,range:i}=e;this._ensureTableRangeRTree(n).remove({unitId:n,sheetId:r,id:t,range:{...i}})}))}registerTableHeaderInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(le.CELL_CONTENT,{effect:f.Value,handler:(e,t,n)=>{let{row:r,col:i,unitId:a,subUnitId:o}=t,s=this._ensureTableRangeRTree(a);if((e==null?void 0:e.v)===void 0&&s){let c=Array.from(s.bulkSearch([{unitId:a,sheetId:o,range:{startColumn:i,endColumn:i,startRow:r,endRow:r}}]));if(c.length>0){let o=this._tableManager.getTable(a,c[0]);if(o){let a=o.getRange(),s=i-a.startColumn;if(a.startRow===r){let r=o.getColumnNameByIndex(s);return(!e||e===t.rawData)&&(e={...t.rawData}),e.v=r,n(e)}}}}return n(e)}}))}_toJson(e){return this._tableManager.toJSON(e)}_fromJSON(e,t){return this._tableManager.fromJSON(e,t)}_deleteUnitId(e){this._tableManager.deleteUnitId(e)}_initSnapshot(){this.disposeWithMe(this._resourceManagerService.registerPluginResource({toJson:e=>JSON.stringify(this._toJson(e)),parseJson:e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}},businesses:[_.UNIVER_SHEET],pluginName:$t,onLoad:(e,t)=>{this._fromJSON(e,t)},onUnLoad:e=>{this._deleteUnitId(e)}}))}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===xe.id){var t;let n=e.params,r=n.unitId||this._univerInstanceService.getCurrentUnitOfType(_.UNIVER_SHEET).getUnitId(),i=n.subUnitId||((t=this._univerInstanceService.getCurrentUnitOfType(_.UNIVER_SHEET).getActiveSheet())==null?void 0:t.getSheetId());if(!r||!i)return{redos:[],undos:[]};let a=this._tableManager.getTablesBySubunitId(r,i);if(a.length===0)return{redos:[],undos:[]};let o=[],s=[];return a.forEach(e=>{let t=e.toJSON();o.push({id:q.id,params:{unitId:r,subUnitId:i,tableId:t.id}}),s.push({id:K.id,params:{unitId:r,subUnitId:i,name:t.name,range:t.range,tableId:t.id,options:{...t.options,columns:t.columns,filters:t.filters.tableColumnFilterList}}})}),{redos:o,undos:s}}else if(e.id===se.id){let{unitId:t,subUnitId:n,targetSubUnitId:r}=e.params;if(!t||!n||!r)return{redos:[],undos:[]};let i=this._tableManager.getTablesBySubunitId(t,n);if(i.length===0)return{redos:[],undos:[]};let a=[],o=[];return i.forEach(e=>{let n=e.toJSON(),i=b();a.push({id:K.id,params:{unitId:t,subUnitId:r,name:n.name,range:{...n.range,sheetId:r},tableId:i,options:{...n.options,columns:n.columns,filters:n.filters.tableColumnFilterList}}}),o.push({id:q.id,params:{unitId:t,subUnitId:r,tableId:i}})}),{redos:a,undos:o}}return{redos:[],undos:[]}}}))}dispose(){super.dispose(),this._tableRangeRTree.clear()}};Z=U([H(0,u(l)),H(1,u(Se)),H(2,u(W)),H(3,u(s))],Z);const an={id:`sheet.command.table-insert-row`,type:n.COMMAND,handler:e=>{let t=w(e.get(l));if(!t)return!1;let{workbook:n,worksheet:r,unitId:a,subUnitId:o}=t,s=e.get(S).getCurrentSelections();if(!s.length||s.length>1)return!1;e.get(W);let u=s[0].range,d=e.get(Z).getContainerTableWithRange(a,o,u);if(!d)return!1;let f=u.endRow-u.startRow+1,p=r.getRowCount()-1,m=r.getCellMatrix().getDataRange().endRow,h=[],g=[];if(p-m<f)h.push({id:pe.id,params:{unitId:a,subUnitId:o,range:{...u}}}),h.push({id:J.id,params:{unitId:a,subUnitId:o,tableId:d.getId(),config:{updateRange:{newRange:{...d.getRange(),endRow:d.getRange().endRow+f}}}}}),g.push({id:J.id,params:{unitId:a,subUnitId:o,tableId:d.getId(),config:{updateRange:{newRange:d.getRange()}}}}),g.push({id:be.id,params:{unitId:a,subUnitId:o,range:{...u}}});else{let t={...d.getRange()};h.push({id:J.id,params:{unitId:a,subUnitId:o,tableId:d.getId(),config:{updateRange:{newRange:{...t,endRow:t.endRow+f}}}}}),g.push({id:J.id,params:{unitId:a,subUnitId:o,tableId:d.getId(),config:{updateRange:{newRange:{...t}}}}});let n=C(e,{unitId:a,subUnitId:o,range:{startRow:u.startRow,endRow:m,startColumn:t.startColumn,endColumn:t.endColumn}},{unitId:a,subUnitId:o,range:{startRow:u.startRow+f,endRow:m+f,startColumn:t.startColumn,endColumn:t.endColumn}});n&&(h.push(...n.redos),g.push(...n.undos))}return x(h,e.get(i))&&e.get(c).pushUndoRedo({unitID:a,undoMutations:g,redoMutations:h}),!0}},on={id:`sheet.command.table-insert-col`,type:n.COMMAND,handler:e=>{let t=w(e.get(l));if(!t)return!1;let{worksheet:n,unitId:r,subUnitId:a}=t,o=e.get(S).getCurrentSelections();if(!o.length||o.length>1)return!1;let s=o[0].range,u=e.get(Z).getContainerTableWithRange(r,a,s);if(!u)return!1;let d=s.endColumn-s.startColumn+1,f=n.getColumnCount()-1,p=n.getCellMatrix().getDataRange().endColumn,m=[],h=[];if(f-p<d)m.push({id:de.id,params:{unitId:r,subUnitId:a,range:{...s}}}),m.push({id:J.id,params:{unitId:r,subUnitId:a,tableId:u.getId(),config:{rowColOperation:{operationType:E.Insert,rowColType:D.Col,index:s.startColumn,count:d}}}}),h.push({id:J.id,params:{unitId:r,subUnitId:a,tableId:u.getId(),config:{rowColOperation:{operationType:E.Delete,rowColType:D.Col,index:s.startColumn,count:d}}}}),h.push({id:_e.id,params:{unitId:r,subUnitId:a,range:{...s}}});else{let t=u.getRange();m.push({id:J.id,params:{unitId:r,subUnitId:a,tableId:u.getId(),config:{rowColOperation:{operationType:E.Insert,rowColType:D.Col,index:s.startColumn,count:d}}}}),h.push({id:J.id,params:{unitId:r,subUnitId:a,tableId:u.getId(),config:{rowColOperation:{operationType:E.Delete,rowColType:D.Col,index:s.startColumn,count:d}}}});let n=C(e,{unitId:r,subUnitId:a,range:{startRow:t.startRow,endRow:t.endRow,startColumn:s.startColumn,endColumn:p}},{unitId:r,subUnitId:a,range:{startRow:t.startRow,endRow:t.endRow,startColumn:s.startColumn+d,endColumn:p+d}});n&&(m.push(...n.redos),h.push(...n.undos))}return x(m,e.get(i))&&e.get(c).pushUndoRedo({unitID:r,undoMutations:h,redoMutations:m}),!0}},sn={id:`sheet.command.table-remove-row`,type:n.COMMAND,handler:(e,t)=>{if(!t)return!1;let n=w(e.get(l),t);if(!n)return!1;let{unitId:r,subUnitId:a}=n,o=e.get(S).getCurrentSelections();if(!o.length||o.length>1)return!1;let s=o[0].range,u=e.get(Z).getContainerTableWithRange(r,a,s);if(!u)return!1;let d=s.endRow-s.startRow+1,f=[],p=[],m=u.getRange();f.push({id:J.id,params:{unitId:r,subUnitId:a,tableId:u.getId(),config:{updateRange:{newRange:{...m,endRow:m.endRow-d}}}}}),p.push({id:J.id,params:{unitId:r,subUnitId:a,tableId:u.getId(),config:{updateRange:{newRange:{...m}}}}});let h=n.worksheet.getCellMatrix().getDataRange().endRow,g=C(e,{unitId:r,subUnitId:a,range:{startRow:s.endRow+1,endRow:h,startColumn:m.startColumn,endColumn:m.endColumn}},{unitId:r,subUnitId:a,range:{startRow:s.startRow,endRow:h-d,startColumn:m.startColumn,endColumn:m.endColumn}});return g&&(f.push(...g.redos),p.push(...g.undos)),x(f,e.get(i))&&e.get(c).pushUndoRedo({unitID:r,undoMutations:p,redoMutations:f}),!0}},cn={id:`sheet.command.table-remove-col`,type:n.COMMAND,handler:(e,t)=>{if(!t)return!1;let n=w(e.get(l),t);if(!n)return!1;let{workbook:r,unitId:a,subUnitId:o}=n;e.get(W);let s=e.get(S).getCurrentSelections();if(!s.length||s.length>1)return!1;let u=s[0].range,d=e.get(Z).getContainerTableWithRange(a,o,u);if(!d)return!1;let f=u.endColumn-u.startColumn+1,p=[],m=[],h=d.getRange();p.push({id:J.id,params:{unitId:a,subUnitId:o,tableId:d.getId(),config:{rowColOperation:{operationType:E.Delete,rowColType:D.Col,index:u.startColumn,count:f}}}});let g=[],_=u.startColumn-h.startColumn;for(let e=0;e<f;e++){let t=d.getTableInfo().columns[_+e];t&&g.push(t)}m.push({id:J.id,params:{unitId:a,subUnitId:o,tableId:d.getId(),config:{rowColOperation:{operationType:E.Insert,rowColType:D.Col,index:u.startColumn,count:f,columnsJson:g}}}});let v=n.worksheet.getCellMatrix().getDataRange().endColumn,y=C(e,{unitId:a,subUnitId:o,range:{startRow:h.startRow,endRow:h.endRow,startColumn:u.endColumn+1,endColumn:v}},{unitId:a,subUnitId:o,range:{startRow:h.startRow,endRow:h.endRow,startColumn:u.startColumn,endColumn:v-f}});return y&&(p.push(...y.redos),m.push(...y.undos)),x(p,e.get(i))&&e.get(c).pushUndoRedo({unitID:a,undoMutations:m,redoMutations:p}),!0}};var ln=`@univerjs/sheets-table`,un=`0.20.1`;let Q=class extends r{constructor(e,t){super(),this._tableManager=e,this._commandService=t,this._initRangeListener()}_initRangeListener(){this.disposeWithMe(this._tableManager.tableRangeChanged$.subscribe(e=>{let{tableId:t,unitId:n}=e,r=this._tableManager.getTableById(n,t);r&&this._updateSuperTable(n,r)})),this.disposeWithMe(this._tableManager.tableAdd$.subscribe(e=>{let{tableId:t,unitId:n}=e,r=this._tableManager.getTableById(n,t);r&&this._updateSuperTable(n,r)})),this.disposeWithMe(this._tableManager.tableDelete$.subscribe(e=>{let{unitId:t,tableName:n}=e;this._commandService.executeCommand(ie.id,{unitId:t,tableName:n})})),this.disposeWithMe(this._tableManager.tableNameChanged$.subscribe(e=>{let{tableId:t,unitId:n,oldTableName:r}=e;this._commandService.executeCommand(ie.id,{unitId:n,tableName:r});let i=this._tableManager.getTableById(n,t);i&&this._updateSuperTable(n,i)}))}_updateSuperTable(e,t){let n=t.getTableInfo(),r=n.name,i=n.columns,a=new Map;i.forEach((e,t)=>{a.set(e.displayName,t)}),this._commandService.executeCommand(ae.id,{unitId:e,tableName:r,reference:{range:n.range,sheetId:n.subUnitId,titleMap:a}})}};Q=U([H(0,u(W)),H(1,i)],Q);let dn=class extends r{constructor(e,t){super(),this._tableManager=e,this._exclusiveRangeService=t,this._initRangeListener()}_initRangeListener(){this.disposeWithMe(this._tableManager.tableRangeChanged$.subscribe(e=>{let{range:t,tableId:n,unitId:r,subUnitId:i}=e;this._exclusiveRangeService.clearExclusiveRangesByGroupId(r,i,Y,n),this._exclusiveRangeService.addExclusiveRange(r,i,Y,[{range:{...t},groupId:n}])})),this.disposeWithMe(this._tableManager.tableAdd$.subscribe(e=>{let{tableId:t,unitId:n,subUnitId:r,range:i}=e;this._exclusiveRangeService.addExclusiveRange(n,r,Y,[{range:{...i},groupId:t}])})),this.disposeWithMe(this._tableManager.tableDelete$.subscribe(e=>{let{tableId:t,unitId:n,subUnitId:r}=e;this._exclusiveRangeService.clearExclusiveRangesByGroupId(n,r,Y,t)}))}};dn=U([H(0,u(W)),H(1,u(ce))],dn);let fn=class extends r{constructor(e,t,n,r,i,a,o){super(),this._commandService=e,this._refRangeService=t,this._univerInstanceService=n,this._injector=r,this._sheetInterceptorService=i,this._tableManager=a,this._localeService=o,this._initCommandInterceptor(),this._initCommandListener()}_initCommandInterceptor(){let e=this;this._sheetInterceptorService.interceptCommand({getMutations(t){let n={redos:[],undos:[]},{id:r,params:i}=t;switch(r){case fe.id:return e._generateTableMutationWithInsertRow(i);case ue.id:return e._generateTableMutationWithInsertCol(i);case ye.id:return e._generateTableMutationWithRemoveRow(i);case ge.id:return e._generateTableMutationWithRemoveCol(i)}return n}})}_generateTableMutationWithInsertRow(e){let t=[],n=[],r=w(this._univerInstanceService,e);if(!r)return{undos:t,redos:n};let{unitId:i,subUnitId:a}=r,o=this._tableManager.getTablesBySubunitId(i,a);if(!o.length)return{undos:t,redos:n};let{range:s}=e;return o.forEach(e=>{let r=e.getRange();if(s.startRow>r.startRow&&s.startRow<=r.endRow){let o=s.endRow-s.startRow+1;n.push({id:J.id,params:{unitId:i,subUnitId:a,tableId:e.getId(),config:{updateRange:{newRange:{...r,endRow:r.endRow+o}}}}}),t.push({id:J.id,params:{unitId:i,subUnitId:a,tableId:e.getId(),config:{updateRange:{newRange:{...r}}}}})}}),{undos:t,redos:n}}_generateTableMutationWithInsertCol(e){let t=[],n=[],r=w(this._univerInstanceService,e);if(!r)return{undos:t,redos:n};let{unitId:i,subUnitId:a}=r,o=this._tableManager.getTablesBySubunitId(i,a);if(!o.length)return{undos:t,redos:n};let{range:s}=e;return o.forEach(e=>{let r=e.getRange();if(s.startColumn>r.startColumn&&s.startColumn<=r.endColumn){let r=s.endColumn-s.startColumn+1;n.push({id:J.id,params:{unitId:i,subUnitId:a,tableId:e.getId(),config:{rowColOperation:{operationType:E.Insert,rowColType:D.Col,index:s.startColumn,count:r}}}}),t.push({id:J.id,params:{unitId:i,subUnitId:a,tableId:e.getId(),config:{rowColOperation:{operationType:E.Delete,rowColType:D.Col,index:s.startColumn,count:r}}}})}}),{undos:t,redos:n}}_generateTableMutationWithRemoveRow(e){let t=[],n=[],r=[],i=[],a=w(this._univerInstanceService);if(!a)return{undos:t,redos:n,preRedos:r,preUndos:i};let{unitId:o,subUnitId:s}=a,c=this._tableManager.getTablesBySubunitId(o,s);if(!c.length)return{undos:t,redos:n,preRedos:r,preUndos:i};let{range:l}=e,u=l.endRow-l.startRow+1;return c.forEach(e=>{let i=e.getRange();if(g.intersects(i,l))if(l.startRow<=i.startRow&&l.endRow>=i.startRow){r.push({id:q.id,params:{unitId:o,subUnitId:s,tableId:e.getId()}});let n=e.toJSON();t.push({id:K.id,params:{unitId:o,subUnitId:s,tableId:n.id,name:n.name,range:n.range,options:n.options}})}else l.startRow>i.startRow&&l.startRow<=i.endRow?(n.push({id:J.id,params:{unitId:o,subUnitId:s,tableId:e.getId(),config:{updateRange:{newRange:{...i,endRow:i.endRow-u}}}}}),t.push({id:J.id,params:{unitId:o,subUnitId:s,tableId:e.getId(),config:{updateRange:{newRange:{...i}}}}})):l.startRow<i.endRow&&l.endRow>=i.endRow&&(n.push({id:J.id,params:{unitId:o,subUnitId:s,tableId:e.getId(),config:{updateRange:{newRange:{...i,endRow:l.startRow-1}}}}}),t.push({id:J.id,params:{unitId:o,subUnitId:s,tableId:e.getId(),config:{updateRange:{newRange:{...i}}}}}))}),{undos:t,redos:n,preRedos:r,preUndos:i}}_generateTableMutationWithRemoveCol(e){let t=[],n=[],r=[],i=[],a=w(this._univerInstanceService);if(!a)return{undos:t,redos:n,preRedos:r,preUndos:i};let{unitId:o,subUnitId:s}=a,c=this._tableManager.getTablesBySubunitId(o,s);if(!c.length)return{undos:t,redos:n,preRedos:r,preUndos:i};let{range:l}=e,u=l.endColumn-l.startColumn+1;return c.forEach(e=>{let a=e.getRange();if(g.intersects(a,l)){if(l.startColumn<=a.startColumn&&l.endColumn>=a.endColumn){r.push({id:q.id,params:{unitId:o,subUnitId:s,tableId:e.getId()}});let a=e.toJSON(),{startRow:c,startColumn:l,endColumn:u}=a.range,d=this._univerInstanceService.getUnit(o),f=d==null?void 0:d.getSheetBySheetId(s);if(!f)return{undos:t,redos:n,preRedos:r,preUndos:i};let p=[];for(let e=l;e<=u;e++)p.push(Ne(f==null?void 0:f.getCell(c,e))||F(e-l+1,this._localeService.t(`sheets-table.columnPrefix`)));t.push({id:K.id,params:{unitId:o,subUnitId:s,tableId:a.id,name:a.name,header:p,range:a.range,options:a.options}})}else if(l.startColumn<=a.startColumn&&l.endColumn>=a.startColumn){let r=l.endColumn-a.startColumn+1;n.push({id:J.id,params:{unitId:o,subUnitId:s,tableId:e.getId(),config:{rowColOperation:{operationType:E.Delete,rowColType:D.Col,index:a.startColumn,count:r}}}});let i=[];for(let t=0;t<r;t++){let n=e.getTableColumnByIndex(t);n&&i.push(n.toJSON())}t.push({id:J.id,params:{unitId:o,subUnitId:s,tableId:e.getId(),config:{rowColOperation:{operationType:E.Insert,rowColType:D.Col,index:a.startColumn,count:r,columnsJson:i}}}})}else if(l.startColumn>a.startColumn&&l.endColumn>a.endColumn){let r=a.endColumn-l.startColumn+1;n.push({id:J.id,params:{unitId:o,subUnitId:s,tableId:e.getId(),config:{rowColOperation:{operationType:E.Delete,rowColType:D.Col,index:l.startColumn,count:r}}}});let i=[],c=l.startColumn-a.startColumn;for(let t=0;t<r;t++){let n=e.getTableColumnByIndex(t+c);n&&i.push(n.toJSON())}t.push({id:J.id,params:{unitId:o,subUnitId:s,tableId:e.getId(),config:{rowColOperation:{operationType:E.Insert,rowColType:D.Col,index:l.startColumn,count:u,columnsJson:i}}}})}else if(l.startColumn>a.startColumn&&l.endColumn<=a.endColumn){n.push({id:J.id,params:{unitId:o,subUnitId:s,tableId:e.getId(),config:{rowColOperation:{operationType:E.Delete,rowColType:D.Col,index:l.startColumn,count:u}}}});let r=[],i=l.startColumn-a.startColumn;for(let t=0;t<u;t++){let n=e.getTableColumnByIndex(t+i);n&&r.push(n.toJSON())}t.push({id:J.id,params:{unitId:o,subUnitId:s,tableId:e.getId(),config:{rowColOperation:{operationType:E.Insert,rowColType:D.Col,index:l.startColumn,count:u,columnsJson:r}}}})}}}),{undos:t,redos:n,preRedos:r,preUndos:i}}_initCommandListener(){this._commandService.onCommandExecuted(e=>{if(e.id===pe.id){let{unitId:t,subUnitId:n,range:r}=e.params,i=r.endRow-r.startRow+1;this._tableManager.getTablesBySubunitId(t,n).forEach(e=>{let n=e.getRange();r.startRow<=n.startRow&&this._tableManager.updateTableRange(t,e.getId(),{newRange:{...n,startRow:n.startRow+i,endRow:n.endRow+i}})})}else if(e.id===de.id){let{unitId:t,subUnitId:n,range:r}=e.params,i=r.endColumn-r.startColumn+1;this._tableManager.getTablesBySubunitId(t,n).forEach(e=>{let n=e.getRange();r.startColumn<=n.startColumn&&this._tableManager.updateTableRange(t,e.getId(),{newRange:{...n,startColumn:n.startColumn+i,endColumn:n.endColumn+i}})})}else if(e.id===be.id){let{unitId:t,subUnitId:n,range:r}=e.params,i=r.endRow-r.startRow+1;this._tableManager.getTablesBySubunitId(t,n).forEach(e=>{let n=e.getRange();r.startRow<n.startRow&&this._tableManager.updateTableRange(t,e.getId(),{newRange:{...n,startRow:n.startRow-i,endRow:n.endRow-i}})})}else if(e.id===_e.id){let{unitId:t,subUnitId:n,range:r}=e.params,i=r.endColumn-r.startColumn+1;this._tableManager.getTablesBySubunitId(t,n).forEach(e=>{let n=e.getRange();r.startColumn<n.startColumn&&this._tableManager.updateTableRange(t,e.getId(),{newRange:{...n,startColumn:n.startColumn-i,endColumn:n.endColumn-i}})})}})}};fn=U([H(0,u(i)),H(1,u(he)),H(2,u(l)),H(3,u(d)),H(4,u(Se)),H(5,u(W)),H(6,u(p))],fn);let pn=class extends r{constructor(e,t,n,r){super(),this._tableManager=e,this._sheetRangeThemeService=t,this._sheetRangeThemeModel=n,this._configService=r,R(this,`_defaultThemeIndex`,0),R(this,`_allThemes`,[]),this._initUserTableTheme(),this.registerTableChangeEvent(),this._initDefaultTableTheme()}registerTableChangeEvent(){this.disposeWithMe(this._tableManager.tableAdd$.subscribe(e=>{let{range:t,tableId:n,unitId:r,subUnitId:i,tableStyleId:a}=e,o=this._tableManager.getTable(r,n),s=a||this._allThemes[this._defaultThemeIndex].name;o.setTableStyleId(s),this._sheetRangeThemeService.registerRangeThemeStyle(s,{unitId:r,subUnitId:i,range:{...t}})})),this.disposeWithMe(this._tableManager.tableRangeChanged$.subscribe(e=>{let{range:t,oldRange:n,tableId:r,unitId:i,subUnitId:a}=e,o=this._tableManager.getTable(i,r),s=o.getTableStyleId();s||(s=this._allThemes[this._defaultThemeIndex].name,o.setTableStyleId(s)),this._sheetRangeThemeService.removeRangeThemeRule(s,{unitId:i,subUnitId:a,range:{...n}}),this._sheetRangeThemeService.registerRangeThemeStyle(s,{unitId:i,subUnitId:a,range:{...t}})})),this.disposeWithMe(this._tableManager.tableThemeChanged$.subscribe(e=>{let{theme:t,oldTheme:n,tableId:r,unitId:i,subUnitId:a}=e,o=this._tableManager.getTable(i,r).getRange();this._sheetRangeThemeService.removeRangeThemeRule(n,{unitId:i,subUnitId:a,range:{...o}}),this._sheetRangeThemeService.registerRangeThemeStyle(t,{unitId:i,subUnitId:a,range:{...o}})})),this.disposeWithMe(this._tableManager.tableDelete$.subscribe(e=>{let{range:t,unitId:n,subUnitId:r,tableStyleId:i=this._allThemes[this._defaultThemeIndex].name}=e;this._sheetRangeThemeService.removeRangeThemeRule(i,{unitId:n,subUnitId:r,range:{...t}})}))}_initUserTableTheme(){let e=this._configService.getConfig(`sheets-table.config`)||{},t=e.defaultThemeIndex||0,n=e.userThemes||[];this._defaultThemeIndex=t,this._allThemes=n.concat(He)}_initDefaultTableTheme(){for(let e=0;e<this._allThemes.length;e++){let{name:t,style:n}=this._allThemes[e],r=new me(t,n);this._sheetRangeThemeModel.registerDefaultRangeTheme(r)}}dispose(){super.dispose(),this._allThemes=[],this._defaultThemeIndex=0}};pn=U([H(0,u(W)),H(1,u(we)),H(2,u(Ce)),H(3,a)],pn);let mn=class extends r{constructor(e,t,n,r){super(),this._tableManager=e,this._sheetInterceptorService=t,this._univerInstanceService=n,this._zebraCrossingCacheController=r,R(this,`_tableFilteredOutRows$`,new Ee(new Set)),R(this,`tableFilteredOutRows$`,this._tableFilteredOutRows$.asObservable()),R(this,`_subscription`,null),this.registerFilterChangeEvent(),this.initTableHiddenRowIntercept(),this._initFilteredOutRows()}get tableFilteredOutRows(){return this._tableFilteredOutRows$.value}set tableFilteredOutRows(e){this._tableFilteredOutRows$.next(e)}initTableHiddenRowIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(le.ROW_FILTERED,{priority:100,handler:(e,t,n)=>{if(e)return!0;let r=this.tableFilteredOutRows.has(t.row);return r?!0:n(r)}}))}_initFilteredOutRows(){this._tableManager.tableInitStatus$.pipe(De(e=>e),Oe(()=>this._univerInstanceService.getCurrentTypeOfUnit$(_.UNIVER_SHEET)),De(e=>e!=null),Oe(e=>e.activeSheet$),De(e=>e!=null)).subscribe(()=>{let e=w(this._univerInstanceService);if(!e)return;let{unitId:t,subUnitId:n}=e;this.tableFilteredOutRows.clear(),this._tableManager.getTablesBySubunitId(t,n).forEach(e=>{let t=e.getTableFilters().getFilterOutRows();if(t)for(let e of t)this.tableFilteredOutRows.add(e)})})}registerFilterChangeEvent(){this.disposeWithMe(this._tableManager.tableFilterChanged$.subscribe(e=>{var t;let{unitId:n,subUnitId:r,tableId:i}=e,a=(t=this._univerInstanceService.getUnit(n))==null?void 0:t.getSheetBySheetId(r),o=this._tableManager.getTable(n,i);!a||!o||(this.tableFilteredOutRows.clear(),o.getTableFilters().doFilter(a,o.getTableFilterRange()),this._tableManager.getTablesBySubunitId(n,r).forEach(e=>{let t=e.getTableFilters().getFilterOutRows();if(t)for(let e of t)this.tableFilteredOutRows.add(e)}),this._zebraCrossingCacheController.updateZebraCrossingCache(n,r))}))}dispose(){var e;super.dispose(),(e=this._subscription)==null||e.unsubscribe()}};mn=U([H(0,u(W)),H(1,u(Se)),H(2,u(l)),H(3,u(Te))],mn);let $=class extends m{constructor(e=ze,t,n,r){super(),this._config=e,this._injector=t,this._configService=n,this._commandService=r;let{...i}=ee({},ze,this._config);this._configService.setConfig(Re,i),this._initRegisterCommand()}onStarting(){te(this._injector,[[W],[pn],[Z],[G],[mn],[dn],[fn],[Q]])}onReady(){ne(this._injector,[[Q],[dn],[fn],[pn],[Z],[G],[mn]]),ne(this._injector,[[W]])}_initRegisterCommand(){[Xt,K,Qt,q,X,rn,nn,J,Zt,tn,an,on,sn,cn].forEach(e=>this._commandService.registerCommand(e))}};R($,`pluginName`,$t),R($,`packageName`,ln),R($,`version`,un),R($,`type`,_.UNIVER_SHEET),$=U([H(1,u(d)),H(2,a),H(3,u(i))],$);export{Xt as AddSheetTableCommand,K as AddSheetTableMutation,Zt as AddTableThemeCommand,Qt as DeleteSheetTableCommand,q as DeleteSheetTableMutation,tn as RemoveTableThemeCommand,en as SHEET_TABLE_CUSTOM_THEME_PREFIX,nn as SetSheetTableCommand,rn as SetSheetTableFilterCommand,X as SetSheetTableFilterMutation,J as SetSheetTableMutation,on as SheetTableInsertColCommand,an as SheetTableInsertRowCommand,cn as SheetTableRemoveColCommand,sn as SheetTableRemoveRowCommand,G as SheetTableService,N as SheetsTableButtonStateEnum,Z as SheetsTableController,P as SheetsTableSortStateEnum,ke as TableColumnDataTypeEnum,O as TableColumnFilterTypeEnum,k as TableConditionTypeEnum,M as TableDateCompareTypeEnum,W as TableManager,A as TableNumberCompareTypeEnum,j as TableStringCompareTypeEnum,$ as UniverSheetsTablePlugin,Be as customEmptyThemeWithBorderStyle,Fe as isConditionFilter,Ie as isManualTableFilter,Ve as processStyleWithBorderStyle};
|
|
1
|
+
import { BorderStyleTypes, CellValueType, CommandType, Disposable, ICommandService, IConfigService, ILogService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, InterceptorEffectEnum, LocaleService, Plugin, RTree, Rectangle, UniverInstanceType, createREGEXFromWildChar, customNameCharacterCheck, generateRandomId, merge, registerDependencies, sequenceExecute, touchDependencies } from "@univerjs/core";
|
|
2
|
+
import { IDefinedNamesService, RemoveSuperTableMutation, SetSuperTableMutation } from "@univerjs/engine-formula";
|
|
3
|
+
import { AddRangeThemeMutation, CopySheetCommand, IExclusiveRangeService, INTERCEPTOR_POINT, InsertColCommand, InsertColMutation, InsertRowCommand, InsertRowMutation, RangeThemeStyle, RefRangeService, RemoveColCommand, RemoveColMutation, RemoveRangeThemeMutation, RemoveRowCommand, RemoveRowMutation, RemoveSheetCommand, SheetInterceptorService, SheetRangeThemeModel, SheetRangeThemeService, SheetsSelectionsService, ZebraCrossingCacheController, getMoveRangeUndoRedoMutations, getSheetCommandTarget } from "@univerjs/sheets";
|
|
4
|
+
import { BehaviorSubject, Subject, filter, switchMap } from "rxjs";
|
|
5
|
+
|
|
6
|
+
//#region src/types/type.ts
|
|
7
|
+
let IRangeOperationTypeEnum = /* @__PURE__ */ function(IRangeOperationTypeEnum) {
|
|
8
|
+
IRangeOperationTypeEnum["Insert"] = "insert";
|
|
9
|
+
IRangeOperationTypeEnum["Delete"] = "delete";
|
|
10
|
+
return IRangeOperationTypeEnum;
|
|
11
|
+
}({});
|
|
12
|
+
let IRowColTypeEnum = /* @__PURE__ */ function(IRowColTypeEnum) {
|
|
13
|
+
IRowColTypeEnum["Row"] = "row";
|
|
14
|
+
IRowColTypeEnum["Col"] = "column";
|
|
15
|
+
return IRowColTypeEnum;
|
|
16
|
+
}({});
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/types/enum.ts
|
|
20
|
+
/**
|
|
21
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
22
|
+
*
|
|
23
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
24
|
+
* you may not use this file except in compliance with the License.
|
|
25
|
+
* You may obtain a copy of the License at
|
|
26
|
+
*
|
|
27
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
28
|
+
*
|
|
29
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
30
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
31
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
32
|
+
* See the License for the specific language governing permissions and
|
|
33
|
+
* limitations under the License.
|
|
34
|
+
*/
|
|
35
|
+
let TableColumnDataTypeEnum = /* @__PURE__ */ function(TableColumnDataTypeEnum) {
|
|
36
|
+
TableColumnDataTypeEnum["None"] = "none";
|
|
37
|
+
TableColumnDataTypeEnum["String"] = "string";
|
|
38
|
+
TableColumnDataTypeEnum["Number"] = "number";
|
|
39
|
+
TableColumnDataTypeEnum["Date"] = "date";
|
|
40
|
+
TableColumnDataTypeEnum["Bool"] = "bool";
|
|
41
|
+
TableColumnDataTypeEnum["Checkbox"] = "checkbox";
|
|
42
|
+
TableColumnDataTypeEnum["List"] = "list";
|
|
43
|
+
return TableColumnDataTypeEnum;
|
|
44
|
+
}({});
|
|
45
|
+
let TableColumnFilterTypeEnum = /* @__PURE__ */ function(TableColumnFilterTypeEnum) {
|
|
46
|
+
TableColumnFilterTypeEnum["manual"] = "manual";
|
|
47
|
+
TableColumnFilterTypeEnum["condition"] = "condition";
|
|
48
|
+
return TableColumnFilterTypeEnum;
|
|
49
|
+
}({});
|
|
50
|
+
let TableConditionTypeEnum = /* @__PURE__ */ function(TableConditionTypeEnum) {
|
|
51
|
+
TableConditionTypeEnum["Date"] = "date";
|
|
52
|
+
TableConditionTypeEnum["Number"] = "number";
|
|
53
|
+
TableConditionTypeEnum["String"] = "string";
|
|
54
|
+
TableConditionTypeEnum["Logic"] = "logic";
|
|
55
|
+
return TableConditionTypeEnum;
|
|
56
|
+
}({});
|
|
57
|
+
let TableNumberCompareTypeEnum = /* @__PURE__ */ function(TableNumberCompareTypeEnum) {
|
|
58
|
+
TableNumberCompareTypeEnum["Equal"] = "equal";
|
|
59
|
+
TableNumberCompareTypeEnum["NotEqual"] = "notEqual";
|
|
60
|
+
TableNumberCompareTypeEnum["GreaterThan"] = "greaterThan";
|
|
61
|
+
TableNumberCompareTypeEnum["GreaterThanOrEqual"] = "greaterThanOrEqual";
|
|
62
|
+
TableNumberCompareTypeEnum["LessThan"] = "lessThan";
|
|
63
|
+
TableNumberCompareTypeEnum["LessThanOrEqual"] = "lessThanOrEqual";
|
|
64
|
+
TableNumberCompareTypeEnum["Between"] = "between";
|
|
65
|
+
TableNumberCompareTypeEnum["NotBetween"] = "notBetween";
|
|
66
|
+
TableNumberCompareTypeEnum["Above"] = "above";
|
|
67
|
+
TableNumberCompareTypeEnum["Below"] = "below";
|
|
68
|
+
TableNumberCompareTypeEnum["TopN"] = "topN";
|
|
69
|
+
return TableNumberCompareTypeEnum;
|
|
70
|
+
}({});
|
|
71
|
+
let TableStringCompareTypeEnum = /* @__PURE__ */ function(TableStringCompareTypeEnum) {
|
|
72
|
+
TableStringCompareTypeEnum["Equal"] = "equal";
|
|
73
|
+
TableStringCompareTypeEnum["NotEqual"] = "notEqual";
|
|
74
|
+
TableStringCompareTypeEnum["Contains"] = "contains";
|
|
75
|
+
TableStringCompareTypeEnum["NotContains"] = "notContains";
|
|
76
|
+
TableStringCompareTypeEnum["StartsWith"] = "startsWith";
|
|
77
|
+
TableStringCompareTypeEnum["EndsWith"] = "endsWith";
|
|
78
|
+
return TableStringCompareTypeEnum;
|
|
79
|
+
}({});
|
|
80
|
+
let TableDateCompareTypeEnum = /* @__PURE__ */ function(TableDateCompareTypeEnum) {
|
|
81
|
+
TableDateCompareTypeEnum["Equal"] = "equal";
|
|
82
|
+
TableDateCompareTypeEnum["NotEqual"] = "notEqual";
|
|
83
|
+
TableDateCompareTypeEnum["After"] = "after";
|
|
84
|
+
TableDateCompareTypeEnum["AfterOrEqual"] = "afterOrEqual";
|
|
85
|
+
TableDateCompareTypeEnum["Before"] = "before";
|
|
86
|
+
TableDateCompareTypeEnum["BeforeOrEqual"] = "beforeOrEqual";
|
|
87
|
+
TableDateCompareTypeEnum["Between"] = "between";
|
|
88
|
+
TableDateCompareTypeEnum["NotBetween"] = "notBetween";
|
|
89
|
+
TableDateCompareTypeEnum["Today"] = "today";
|
|
90
|
+
TableDateCompareTypeEnum["Yesterday"] = "yesterday";
|
|
91
|
+
TableDateCompareTypeEnum["Tomorrow"] = "tomorrow";
|
|
92
|
+
TableDateCompareTypeEnum["ThisWeek"] = "thisWeek";
|
|
93
|
+
TableDateCompareTypeEnum["LastWeek"] = "lastWeek";
|
|
94
|
+
TableDateCompareTypeEnum["NextWeek"] = "nextWeek";
|
|
95
|
+
TableDateCompareTypeEnum["ThisMonth"] = "thisMonth";
|
|
96
|
+
TableDateCompareTypeEnum["LastMonth"] = "lastMonth";
|
|
97
|
+
TableDateCompareTypeEnum["NextMonth"] = "nextMonth";
|
|
98
|
+
TableDateCompareTypeEnum["ThisQuarter"] = "thisQuarter";
|
|
99
|
+
TableDateCompareTypeEnum["LastQuarter"] = "lastQuarter";
|
|
100
|
+
TableDateCompareTypeEnum["NextQuarter"] = "nextQuarter";
|
|
101
|
+
TableDateCompareTypeEnum["ThisYear"] = "thisYear";
|
|
102
|
+
TableDateCompareTypeEnum["LastYear"] = "lastYear";
|
|
103
|
+
TableDateCompareTypeEnum["NextYear"] = "nextYear";
|
|
104
|
+
TableDateCompareTypeEnum["YearToDate"] = "yearToDate";
|
|
105
|
+
TableDateCompareTypeEnum["Quarter"] = "quarter";
|
|
106
|
+
TableDateCompareTypeEnum["Month"] = "month";
|
|
107
|
+
TableDateCompareTypeEnum["M1"] = "m1";
|
|
108
|
+
TableDateCompareTypeEnum["M2"] = "m2";
|
|
109
|
+
TableDateCompareTypeEnum["M3"] = "m3";
|
|
110
|
+
TableDateCompareTypeEnum["M4"] = "m4";
|
|
111
|
+
TableDateCompareTypeEnum["M5"] = "m5";
|
|
112
|
+
TableDateCompareTypeEnum["M6"] = "m6";
|
|
113
|
+
TableDateCompareTypeEnum["M7"] = "m7";
|
|
114
|
+
TableDateCompareTypeEnum["M8"] = "m8";
|
|
115
|
+
TableDateCompareTypeEnum["M9"] = "m9";
|
|
116
|
+
TableDateCompareTypeEnum["M10"] = "m10";
|
|
117
|
+
TableDateCompareTypeEnum["M11"] = "m11";
|
|
118
|
+
TableDateCompareTypeEnum["M12"] = "m12";
|
|
119
|
+
TableDateCompareTypeEnum["Q1"] = "q1";
|
|
120
|
+
TableDateCompareTypeEnum["Q2"] = "q2";
|
|
121
|
+
TableDateCompareTypeEnum["Q3"] = "q3";
|
|
122
|
+
TableDateCompareTypeEnum["Q4"] = "q4";
|
|
123
|
+
return TableDateCompareTypeEnum;
|
|
124
|
+
}({});
|
|
125
|
+
/**
|
|
126
|
+
* Represents the pivot cell style type enum
|
|
127
|
+
*/
|
|
128
|
+
let SheetsTableButtonStateEnum = /* @__PURE__ */ function(SheetsTableButtonStateEnum) {
|
|
129
|
+
SheetsTableButtonStateEnum[SheetsTableButtonStateEnum["FilteredSortNone"] = 1] = "FilteredSortNone";
|
|
130
|
+
SheetsTableButtonStateEnum[SheetsTableButtonStateEnum["FilteredSortAsc"] = 2] = "FilteredSortAsc";
|
|
131
|
+
SheetsTableButtonStateEnum[SheetsTableButtonStateEnum["FilteredSortDesc"] = 3] = "FilteredSortDesc";
|
|
132
|
+
SheetsTableButtonStateEnum[SheetsTableButtonStateEnum["FilterNoneSortNone"] = 4] = "FilterNoneSortNone";
|
|
133
|
+
SheetsTableButtonStateEnum[SheetsTableButtonStateEnum["FilterNoneSortAsc"] = 5] = "FilterNoneSortAsc";
|
|
134
|
+
SheetsTableButtonStateEnum[SheetsTableButtonStateEnum["FilterNoneSortDesc"] = 6] = "FilterNoneSortDesc";
|
|
135
|
+
return SheetsTableButtonStateEnum;
|
|
136
|
+
}({});
|
|
137
|
+
let SheetsTableSortStateEnum = /* @__PURE__ */ function(SheetsTableSortStateEnum) {
|
|
138
|
+
SheetsTableSortStateEnum["Asc"] = "asc";
|
|
139
|
+
SheetsTableSortStateEnum["Desc"] = "desc";
|
|
140
|
+
SheetsTableSortStateEnum["None"] = "none";
|
|
141
|
+
return SheetsTableSortStateEnum;
|
|
142
|
+
}({});
|
|
143
|
+
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region src/util.ts
|
|
146
|
+
function getColumnName(columnIndex, columnText) {
|
|
147
|
+
return `${columnText} ${columnIndex}`;
|
|
148
|
+
}
|
|
149
|
+
const BooleanTrue = "TRUE";
|
|
150
|
+
const BooleanFalse = "FALSE";
|
|
151
|
+
const getStringFromDataStream$1 = (data) => {
|
|
152
|
+
var _data$body;
|
|
153
|
+
return ((_data$body = data.body) === null || _data$body === void 0 ? void 0 : _data$body.dataStream.replace(/\r\n$/, "")) || "";
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* transform cell data to dimension name
|
|
157
|
+
* @param cellData the sheet cell data
|
|
158
|
+
* @param styles workBook styles collection
|
|
159
|
+
* @param patternInfoRecord The cache record for pattern info
|
|
160
|
+
* @returns {string} The dimension name
|
|
161
|
+
*/
|
|
162
|
+
function convertCellDataToString(cellData) {
|
|
163
|
+
if (cellData) {
|
|
164
|
+
const { v, t, p } = cellData;
|
|
165
|
+
if (p) return getStringFromDataStream$1(p);
|
|
166
|
+
if ((t === CellValueType.FORCE_STRING || t === CellValueType.STRING) && v !== void 0 && v !== null) return String(v);
|
|
167
|
+
else if (t === CellValueType.BOOLEAN) return v ? BooleanTrue : BooleanFalse;
|
|
168
|
+
else if (t === CellValueType.NUMBER) return String(v);
|
|
169
|
+
else {
|
|
170
|
+
if (typeof v === "boolean") return v ? BooleanTrue : BooleanFalse;
|
|
171
|
+
return v === void 0 || v === null ? "" : String(v);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return "";
|
|
175
|
+
}
|
|
176
|
+
function getTableFilterState(tableFilter, sortState) {
|
|
177
|
+
if (tableFilter !== void 0 && tableFilter !== null) switch (sortState) {
|
|
178
|
+
case SheetsTableSortStateEnum.Asc: return SheetsTableButtonStateEnum.FilteredSortAsc;
|
|
179
|
+
case SheetsTableSortStateEnum.Desc: return SheetsTableButtonStateEnum.FilteredSortDesc;
|
|
180
|
+
default: return SheetsTableButtonStateEnum.FilteredSortNone;
|
|
181
|
+
}
|
|
182
|
+
else switch (sortState) {
|
|
183
|
+
case SheetsTableSortStateEnum.Asc: return SheetsTableButtonStateEnum.FilterNoneSortAsc;
|
|
184
|
+
case SheetsTableSortStateEnum.Desc: return SheetsTableButtonStateEnum.FilterNoneSortDesc;
|
|
185
|
+
default: return SheetsTableButtonStateEnum.FilterNoneSortNone;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function isConditionFilter(filter) {
|
|
189
|
+
if (!filter) return false;
|
|
190
|
+
return filter.filterType === TableColumnFilterTypeEnum.condition;
|
|
191
|
+
}
|
|
192
|
+
function isManualTableFilter(filter) {
|
|
193
|
+
if (!filter) return false;
|
|
194
|
+
return filter.filterType === TableColumnFilterTypeEnum.manual;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Get existing names including sheet names, table names and defined names to check for duplicates table name.
|
|
198
|
+
*/
|
|
199
|
+
function getExistingNamesSet(unitId, options) {
|
|
200
|
+
const { univerInstanceService, tableManager, definedNamesService } = options;
|
|
201
|
+
const existingNamesSet = /* @__PURE__ */ new Set();
|
|
202
|
+
const workbook = univerInstanceService === null || univerInstanceService === void 0 ? void 0 : univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
|
|
203
|
+
if (workbook) workbook.getSheets().forEach((sheet) => {
|
|
204
|
+
existingNamesSet.add(sheet.getName().toLowerCase());
|
|
205
|
+
});
|
|
206
|
+
const tableList = tableManager === null || tableManager === void 0 ? void 0 : tableManager.getTableList(unitId);
|
|
207
|
+
if (tableList && tableList.length > 0) tableList.forEach((tableItem) => {
|
|
208
|
+
existingNamesSet.add(tableItem.name.toLowerCase());
|
|
209
|
+
});
|
|
210
|
+
const definedNames = definedNamesService === null || definedNamesService === void 0 ? void 0 : definedNamesService.getDefinedNameMap(unitId);
|
|
211
|
+
if (definedNames) Object.values(definedNames).forEach((definedName) => {
|
|
212
|
+
existingNamesSet.add(definedName.name.toLowerCase());
|
|
213
|
+
});
|
|
214
|
+
return existingNamesSet;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
//#endregion
|
|
218
|
+
//#region src/config/config.ts
|
|
219
|
+
const tableDefaultBorderStyle = {
|
|
220
|
+
s: BorderStyleTypes.THIN,
|
|
221
|
+
cl: { rgb: "rgb(95, 101, 116)" }
|
|
222
|
+
};
|
|
223
|
+
const SHEETS_TABLE_PLUGIN_CONFIG_KEY = "sheets-table.config";
|
|
224
|
+
const configSymbol = Symbol(SHEETS_TABLE_PLUGIN_CONFIG_KEY);
|
|
225
|
+
const defaultPluginConfig = {};
|
|
226
|
+
|
|
227
|
+
//#endregion
|
|
228
|
+
//#region src/controllers/table-theme.factory.ts
|
|
229
|
+
const customEmptyThemeWithBorderStyle = {
|
|
230
|
+
headerRowStyle: { bd: { t: tableDefaultBorderStyle } },
|
|
231
|
+
headerColumnStyle: { bd: { l: tableDefaultBorderStyle } },
|
|
232
|
+
lastColumnStyle: { bd: { r: tableDefaultBorderStyle } },
|
|
233
|
+
lastRowStyle: { bd: { b: tableDefaultBorderStyle } }
|
|
234
|
+
};
|
|
235
|
+
const processStyleWithBorderStyle = (key, style) => {
|
|
236
|
+
if (key === "headerRowStyle") {
|
|
237
|
+
if (!style.bd) return {
|
|
238
|
+
...style,
|
|
239
|
+
bd: { t: tableDefaultBorderStyle }
|
|
240
|
+
};
|
|
241
|
+
} else if (key === "lastRowStyle") {
|
|
242
|
+
if (!style.bd) return {
|
|
243
|
+
...style,
|
|
244
|
+
bd: { b: tableDefaultBorderStyle }
|
|
245
|
+
};
|
|
246
|
+
} else if (key === "lastColumnStyle") {
|
|
247
|
+
if (!style.bd) return {
|
|
248
|
+
...style,
|
|
249
|
+
bd: { r: tableDefaultBorderStyle }
|
|
250
|
+
};
|
|
251
|
+
} else if (key === "headerColumnStyle") {
|
|
252
|
+
if (!style.bd) return {
|
|
253
|
+
...style,
|
|
254
|
+
bd: { l: tableDefaultBorderStyle }
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
return style;
|
|
258
|
+
};
|
|
259
|
+
const tableDefaultThemeStyleArr = [
|
|
260
|
+
[[
|
|
261
|
+
"#6280F9",
|
|
262
|
+
"#FFFFFF",
|
|
263
|
+
"#BAC6F8",
|
|
264
|
+
"#D2DAFA"
|
|
265
|
+
], ["#fff"]],
|
|
266
|
+
[[
|
|
267
|
+
"#16BDCA",
|
|
268
|
+
"#FFFFFF",
|
|
269
|
+
"#EDFAFA",
|
|
270
|
+
"#AFECEF"
|
|
271
|
+
], ["#000"]],
|
|
272
|
+
[[
|
|
273
|
+
"#31C48D",
|
|
274
|
+
"#FFFFFF",
|
|
275
|
+
"#F3FAF7",
|
|
276
|
+
"#BCF0DA"
|
|
277
|
+
], ["#fff"]],
|
|
278
|
+
[[
|
|
279
|
+
"#AC94FA",
|
|
280
|
+
"#FFFFFF",
|
|
281
|
+
"#F6F5FF",
|
|
282
|
+
"#EDEBFE"
|
|
283
|
+
], ["#fff"]],
|
|
284
|
+
[[
|
|
285
|
+
"#F17EBB",
|
|
286
|
+
"#FFFFFF",
|
|
287
|
+
"#FDF2F8",
|
|
288
|
+
"#FCE8F3"
|
|
289
|
+
], ["#fff"]],
|
|
290
|
+
[[
|
|
291
|
+
"#F98080",
|
|
292
|
+
"#FFFFFF",
|
|
293
|
+
"#FDF2F2",
|
|
294
|
+
"#FDE8E8"
|
|
295
|
+
], ["#fff"]]
|
|
296
|
+
];
|
|
297
|
+
const tableThemeConfig = tableDefaultThemeStyleArr.map((item, index) => {
|
|
298
|
+
const [backgroundArr, colorArr] = item;
|
|
299
|
+
const [headerRowBg, firstRowBg, secondRowBg, lastRowBg] = backgroundArr;
|
|
300
|
+
const [headerCl] = colorArr;
|
|
301
|
+
return {
|
|
302
|
+
name: `table-default-${index}`,
|
|
303
|
+
style: {
|
|
304
|
+
headerRowStyle: {
|
|
305
|
+
bg: { rgb: headerRowBg },
|
|
306
|
+
cl: { rgb: headerCl },
|
|
307
|
+
bd: { t: tableDefaultBorderStyle }
|
|
308
|
+
},
|
|
309
|
+
headerColumnStyle: { bd: { l: tableDefaultBorderStyle } },
|
|
310
|
+
firstRowStyle: { bg: { rgb: firstRowBg } },
|
|
311
|
+
secondRowStyle: { bg: { rgb: secondRowBg } },
|
|
312
|
+
lastRowStyle: {
|
|
313
|
+
bg: { rgb: lastRowBg },
|
|
314
|
+
bd: { b: tableDefaultBorderStyle }
|
|
315
|
+
},
|
|
316
|
+
lastColumnStyle: { bd: { r: tableDefaultBorderStyle } }
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
//#endregion
|
|
322
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
|
|
323
|
+
function _typeof(o) {
|
|
324
|
+
"@babel/helpers - typeof";
|
|
325
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
326
|
+
return typeof o;
|
|
327
|
+
} : function(o) {
|
|
328
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
329
|
+
}, _typeof(o);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
//#endregion
|
|
333
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
|
|
334
|
+
function toPrimitive(t, r) {
|
|
335
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
336
|
+
var e = t[Symbol.toPrimitive];
|
|
337
|
+
if (void 0 !== e) {
|
|
338
|
+
var i = e.call(t, r || "default");
|
|
339
|
+
if ("object" != _typeof(i)) return i;
|
|
340
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
341
|
+
}
|
|
342
|
+
return ("string" === r ? String : Number)(t);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
//#endregion
|
|
346
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
|
|
347
|
+
function toPropertyKey(t) {
|
|
348
|
+
var i = toPrimitive(t, "string");
|
|
349
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
//#endregion
|
|
353
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
|
|
354
|
+
function _defineProperty(e, r, t) {
|
|
355
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
356
|
+
value: t,
|
|
357
|
+
enumerable: !0,
|
|
358
|
+
configurable: !0,
|
|
359
|
+
writable: !0
|
|
360
|
+
}) : e[r] = t, e;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
//#endregion
|
|
364
|
+
//#region src/model/table-column.ts
|
|
365
|
+
var TableColumn = class {
|
|
366
|
+
constructor(id, name) {
|
|
367
|
+
_defineProperty(this, "dataType", void 0);
|
|
368
|
+
_defineProperty(this, "id", void 0);
|
|
369
|
+
_defineProperty(this, "displayName", void 0);
|
|
370
|
+
_defineProperty(this, "formula", void 0);
|
|
371
|
+
_defineProperty(this, "meta", void 0);
|
|
372
|
+
_defineProperty(this, "style", void 0);
|
|
373
|
+
this.id = id;
|
|
374
|
+
this.displayName = name;
|
|
375
|
+
this.dataType = TableColumnDataTypeEnum.String;
|
|
376
|
+
this.formula = "";
|
|
377
|
+
this.meta = {};
|
|
378
|
+
this.style = {};
|
|
379
|
+
}
|
|
380
|
+
getMeta() {
|
|
381
|
+
return this.meta;
|
|
382
|
+
}
|
|
383
|
+
setMeta(meta) {
|
|
384
|
+
this.meta = meta;
|
|
385
|
+
}
|
|
386
|
+
getDisplayName() {
|
|
387
|
+
return this.displayName;
|
|
388
|
+
}
|
|
389
|
+
toJSON() {
|
|
390
|
+
return {
|
|
391
|
+
id: this.id,
|
|
392
|
+
displayName: this.displayName,
|
|
393
|
+
dataType: this.dataType,
|
|
394
|
+
formula: this.formula,
|
|
395
|
+
meta: this.meta,
|
|
396
|
+
style: this.style
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
fromJSON(json) {
|
|
400
|
+
this.id = json.id;
|
|
401
|
+
this.displayName = json.displayName;
|
|
402
|
+
this.dataType = json.dataType;
|
|
403
|
+
this.formula = json.formula;
|
|
404
|
+
this.meta = json.meta;
|
|
405
|
+
this.style = json.style;
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
//#endregion
|
|
410
|
+
//#region src/model/filter-util/date-filter-util.ts
|
|
411
|
+
/**
|
|
412
|
+
* The provided date is a date in Q1 of the year.
|
|
413
|
+
* @param {Date} date - The date to compare.
|
|
414
|
+
* @returns {boolean} return the date is match
|
|
415
|
+
*/
|
|
416
|
+
const dateQ1 = (date) => {
|
|
417
|
+
return date.getMonth() <= 2;
|
|
418
|
+
};
|
|
419
|
+
/**
|
|
420
|
+
* The provided date is a date in Q2 of the year.
|
|
421
|
+
* @param {Date} date - The date to compare.
|
|
422
|
+
* @returns {boolean} return the date is match
|
|
423
|
+
*/
|
|
424
|
+
const dateQ2 = (date) => {
|
|
425
|
+
const month = date.getMonth();
|
|
426
|
+
return month > 2 && month <= 5;
|
|
427
|
+
};
|
|
428
|
+
/**
|
|
429
|
+
* The provided date is a date in Q3 of the year.
|
|
430
|
+
* @param {Date} date - The date to compare.
|
|
431
|
+
* @returns {boolean} return the date is match
|
|
432
|
+
*/
|
|
433
|
+
const dateQ3 = (date) => {
|
|
434
|
+
const month = date.getMonth();
|
|
435
|
+
return month > 5 && month <= 8;
|
|
436
|
+
};
|
|
437
|
+
/**
|
|
438
|
+
* The provided date is a date in Q4 of the year.
|
|
439
|
+
* @param {Date} date - The date to compare.
|
|
440
|
+
* @returns {boolean} return the date is match
|
|
441
|
+
*/
|
|
442
|
+
const dateQ4 = (date) => {
|
|
443
|
+
const month = date.getMonth();
|
|
444
|
+
return month > 8 && month <= 11;
|
|
445
|
+
};
|
|
446
|
+
/**
|
|
447
|
+
* The provided date is a date in January.
|
|
448
|
+
* @param {Date} date - The date to compare.
|
|
449
|
+
* @returns {boolean} return the date is match
|
|
450
|
+
*/
|
|
451
|
+
const dateM1 = (date) => {
|
|
452
|
+
return date.getMonth() === 0;
|
|
453
|
+
};
|
|
454
|
+
/**
|
|
455
|
+
* The provided date is a date in February.
|
|
456
|
+
* @param {Date} date - The date to compare.
|
|
457
|
+
* @returns {boolean} return the date is match
|
|
458
|
+
*/
|
|
459
|
+
const dateM2 = (date) => {
|
|
460
|
+
return date.getMonth() === 1;
|
|
461
|
+
};
|
|
462
|
+
/**
|
|
463
|
+
* The provided date is a date in March.
|
|
464
|
+
* @param {Date} date - The date to compare.
|
|
465
|
+
* @returns {boolean} return the date is match
|
|
466
|
+
*/
|
|
467
|
+
const dateM3 = (date) => {
|
|
468
|
+
return date.getMonth() === 2;
|
|
469
|
+
};
|
|
470
|
+
/**
|
|
471
|
+
* The provided date is a date in April.
|
|
472
|
+
* @param {Date} date - The date to compare.
|
|
473
|
+
* @returns {boolean} return the date is match
|
|
474
|
+
*/
|
|
475
|
+
const dateM4 = (date) => {
|
|
476
|
+
return date.getMonth() === 3;
|
|
477
|
+
};
|
|
478
|
+
/**
|
|
479
|
+
* The provided date is a date in May.
|
|
480
|
+
* @param {Date} date - The date to compare.
|
|
481
|
+
* @returns {boolean} return the date is match
|
|
482
|
+
*/
|
|
483
|
+
const dateM5 = (date) => {
|
|
484
|
+
return date.getMonth() === 4;
|
|
485
|
+
};
|
|
486
|
+
/**
|
|
487
|
+
* The provided date is a date in June.
|
|
488
|
+
* @param {Date} date - The date to compare.
|
|
489
|
+
* @returns {boolean} return the date is match
|
|
490
|
+
*/
|
|
491
|
+
const dateM6 = (date) => {
|
|
492
|
+
return date.getMonth() === 5;
|
|
493
|
+
};
|
|
494
|
+
/**
|
|
495
|
+
* The provided date is a date in July.
|
|
496
|
+
* @param {Date} date - The date to compare.
|
|
497
|
+
* @returns {boolean} return the date is match
|
|
498
|
+
*/
|
|
499
|
+
const dateM7 = (date) => {
|
|
500
|
+
return date.getMonth() === 6;
|
|
501
|
+
};
|
|
502
|
+
/**
|
|
503
|
+
* The provided date is a date in August.
|
|
504
|
+
* @param {Date} date - The date to compare.
|
|
505
|
+
* @returns {boolean} return the date is match
|
|
506
|
+
*/
|
|
507
|
+
const dateM8 = (date) => {
|
|
508
|
+
return date.getMonth() === 7;
|
|
509
|
+
};
|
|
510
|
+
/**
|
|
511
|
+
* The provided date is a date in September.
|
|
512
|
+
* @param {Date} date - The date to compare.
|
|
513
|
+
* @returns {boolean} return the date is match
|
|
514
|
+
*/
|
|
515
|
+
const dateM9 = (date) => {
|
|
516
|
+
return date.getMonth() === 8;
|
|
517
|
+
};
|
|
518
|
+
/**
|
|
519
|
+
* The provided date is a date in October.
|
|
520
|
+
* @param {Date} date - The date to compare.
|
|
521
|
+
* @returns {boolean} return the date is match
|
|
522
|
+
*/
|
|
523
|
+
const dateM10 = (date) => {
|
|
524
|
+
return date.getMonth() === 9;
|
|
525
|
+
};
|
|
526
|
+
/**
|
|
527
|
+
* The provided date is a date in November.
|
|
528
|
+
* @param {Date} date - The date to compare.
|
|
529
|
+
* @returns {boolean} return the date is match
|
|
530
|
+
*/
|
|
531
|
+
const dateM11 = (date) => {
|
|
532
|
+
return date.getMonth() === 10;
|
|
533
|
+
};
|
|
534
|
+
/**
|
|
535
|
+
* The provided date is a date in December.
|
|
536
|
+
* @param {Date} date - The date to compare.
|
|
537
|
+
* @returns {boolean} return the date is match
|
|
538
|
+
*/
|
|
539
|
+
const dateM12 = (date) => {
|
|
540
|
+
return date.getMonth() === 11;
|
|
541
|
+
};
|
|
542
|
+
/**
|
|
543
|
+
* The provided date is today.
|
|
544
|
+
* @param {Date} expectedDate - The date to compare.
|
|
545
|
+
* @param {Date} [anchorTime] - The reference date.
|
|
546
|
+
* @returns {boolean} return the date is match
|
|
547
|
+
*/
|
|
548
|
+
const today = (expectedDate, anchorTime = /* @__PURE__ */ new Date()) => {
|
|
549
|
+
return expectedDate.toDateString() === anchorTime.toDateString();
|
|
550
|
+
};
|
|
551
|
+
/**
|
|
552
|
+
* The provided date is tomorrow.
|
|
553
|
+
* @param {Date} date - The date to compare.
|
|
554
|
+
* @param {Date} [anchorTime] - The reference date.
|
|
555
|
+
* @returns {boolean} return the date is match
|
|
556
|
+
*/
|
|
557
|
+
const tomorrow = (date, anchorTime = /* @__PURE__ */ new Date()) => {
|
|
558
|
+
const tomorrow = new Date(anchorTime);
|
|
559
|
+
tomorrow.setDate(tomorrow.getDate() + 1);
|
|
560
|
+
return date.toDateString() === tomorrow.toDateString();
|
|
561
|
+
};
|
|
562
|
+
/**
|
|
563
|
+
* The provided date is yesterday.
|
|
564
|
+
* @param {Date} date - The date to compare.
|
|
565
|
+
* @param {Date} [anchorTime] - The reference date.
|
|
566
|
+
* @returns {boolean} return the date is match
|
|
567
|
+
*/
|
|
568
|
+
const yesterday = (date, anchorTime = /* @__PURE__ */ new Date()) => {
|
|
569
|
+
const yesterday = new Date(anchorTime);
|
|
570
|
+
yesterday.setDate(yesterday.getDate() - 1);
|
|
571
|
+
return date.toDateString() === yesterday.toDateString();
|
|
572
|
+
};
|
|
573
|
+
/**
|
|
574
|
+
* Get the start date of the week for the provided date.
|
|
575
|
+
* @param {Date} date - The date to get the week start.
|
|
576
|
+
* @returns {Date} The start date of the week.
|
|
577
|
+
*/
|
|
578
|
+
const getWeekStart = (date) => {
|
|
579
|
+
const day = date.getDay();
|
|
580
|
+
const diff = date.getDate() - day + (day === 0 ? -6 : 1);
|
|
581
|
+
const weekStart = new Date(date);
|
|
582
|
+
weekStart.setDate(diff);
|
|
583
|
+
return weekStart;
|
|
584
|
+
};
|
|
585
|
+
const perWeek = 10080 * 60 * 1e3;
|
|
586
|
+
/**
|
|
587
|
+
* The provided date is in the current week.
|
|
588
|
+
* @param {Date} date - The date to compare.
|
|
589
|
+
* @param {Date} [anchorTime] - The reference date.
|
|
590
|
+
* @returns {boolean} return the date is match
|
|
591
|
+
*/
|
|
592
|
+
const thisWeek = (date, anchorTime = /* @__PURE__ */ new Date()) => {
|
|
593
|
+
const weekStart = getWeekStart(date);
|
|
594
|
+
const anchorTimeWeekStart = getWeekStart(anchorTime);
|
|
595
|
+
return weekStart.toDateString() === anchorTimeWeekStart.toDateString();
|
|
596
|
+
};
|
|
597
|
+
/**
|
|
598
|
+
* The provided date is in the next week.
|
|
599
|
+
* @param {Date} date - The date to compare.
|
|
600
|
+
* @param {Date} [anchorTime] - The reference date.
|
|
601
|
+
* @returns {boolean} return the date is match
|
|
602
|
+
*/
|
|
603
|
+
const nextWeek = (date, anchorTime = /* @__PURE__ */ new Date()) => {
|
|
604
|
+
const weekStart = getWeekStart(date);
|
|
605
|
+
const anchorTimeNextWeekStart = new Date(getWeekStart(anchorTime).getTime() + perWeek);
|
|
606
|
+
return weekStart.toDateString() === anchorTimeNextWeekStart.toDateString();
|
|
607
|
+
};
|
|
608
|
+
/**
|
|
609
|
+
* The provided date is in the last week.
|
|
610
|
+
* @param {Date} date - The date to compare.
|
|
611
|
+
* @param {Date} [anchorTime] - The reference date.
|
|
612
|
+
* @returns {boolean} return the date is match
|
|
613
|
+
*/
|
|
614
|
+
const lastWeek = (date, anchorTime = /* @__PURE__ */ new Date()) => {
|
|
615
|
+
const weekStart = getWeekStart(date);
|
|
616
|
+
const anchorTimeLastWeekStart = new Date(getWeekStart(anchorTime).getTime() - perWeek);
|
|
617
|
+
return weekStart.toDateString() === anchorTimeLastWeekStart.toDateString();
|
|
618
|
+
};
|
|
619
|
+
/**
|
|
620
|
+
* The provided date is in the current month.
|
|
621
|
+
* @param {Date} date - The date to compare.
|
|
622
|
+
* @param {Date} [anchorTime] - The reference date.
|
|
623
|
+
* @returns {boolean} return the date is match
|
|
624
|
+
*/
|
|
625
|
+
const thisMonth = (date, anchorTime = /* @__PURE__ */ new Date()) => {
|
|
626
|
+
return date.getFullYear() === anchorTime.getFullYear() && date.getMonth() === anchorTime.getMonth();
|
|
627
|
+
};
|
|
628
|
+
/**
|
|
629
|
+
* Get the start date of the month for the provided date.
|
|
630
|
+
* @param {Date} date - The date to get the month start.
|
|
631
|
+
* @returns {Date} The start date of the month.
|
|
632
|
+
*/
|
|
633
|
+
const getMonthStart = (date) => {
|
|
634
|
+
const monthStart = new Date(date);
|
|
635
|
+
monthStart.setHours(0, 0, 0, 0);
|
|
636
|
+
monthStart.setDate(1);
|
|
637
|
+
return monthStart;
|
|
638
|
+
};
|
|
639
|
+
/**
|
|
640
|
+
* The provided date is in the next month.
|
|
641
|
+
* @param {Date} date - The date to compare.
|
|
642
|
+
* @param {Date} [anchorTime] - The reference date.
|
|
643
|
+
* @returns {boolean} return the date is match
|
|
644
|
+
*/
|
|
645
|
+
const nextMonth = (date, anchorTime = /* @__PURE__ */ new Date()) => {
|
|
646
|
+
const nextMonthStart = new Date(anchorTime);
|
|
647
|
+
nextMonthStart.setHours(0, 0, 0, 0);
|
|
648
|
+
nextMonthStart.setMonth(nextMonthStart.getMonth() + 1, 1);
|
|
649
|
+
const monthEnd = new Date(nextMonthStart);
|
|
650
|
+
monthEnd.setMonth(monthEnd.getMonth() + 1, 0);
|
|
651
|
+
const dateTime = date.getTime();
|
|
652
|
+
return dateTime >= nextMonthStart.getTime() && dateTime < monthEnd.getTime();
|
|
653
|
+
};
|
|
654
|
+
/**
|
|
655
|
+
* The provided date is in the last month.
|
|
656
|
+
* @param {Date} date - The date to compare.
|
|
657
|
+
* @param {Date} [anchorTime] - The reference date.
|
|
658
|
+
* @returns {boolean} return the date is match
|
|
659
|
+
*/
|
|
660
|
+
const lastMonth = (date, anchorTime = /* @__PURE__ */ new Date()) => {
|
|
661
|
+
const lastMonthStart = getMonthStart(anchorTime);
|
|
662
|
+
const monthEnd = new Date(lastMonthStart);
|
|
663
|
+
monthEnd.setMonth(monthEnd.getMonth() + 1, 0);
|
|
664
|
+
const dateTime = date.getTime();
|
|
665
|
+
return dateTime >= lastMonthStart.getTime() && dateTime < monthEnd.getTime();
|
|
666
|
+
};
|
|
667
|
+
/**
|
|
668
|
+
* Get the start date of the quarter for the provided date.
|
|
669
|
+
* @param {Date} date - The date to get the quarter start.
|
|
670
|
+
* @returns {Date} The start date of the quarter.
|
|
671
|
+
*/
|
|
672
|
+
const getQuarterStart = (date) => {
|
|
673
|
+
const quarterStart = new Date(date);
|
|
674
|
+
quarterStart.setHours(0, 0, 0, 0);
|
|
675
|
+
quarterStart.setDate(1);
|
|
676
|
+
const month = quarterStart.getMonth();
|
|
677
|
+
quarterStart.setMonth(month - month % 3);
|
|
678
|
+
return quarterStart;
|
|
679
|
+
};
|
|
680
|
+
/**
|
|
681
|
+
* The provided date is in the current quarter.
|
|
682
|
+
* @param {Date} date - The date to compare.
|
|
683
|
+
* @param {Date} [anchorTime] - The reference date.
|
|
684
|
+
* @returns {boolean} return the date is match
|
|
685
|
+
*/
|
|
686
|
+
const thisQuarter = (date, anchorTime = /* @__PURE__ */ new Date()) => {
|
|
687
|
+
const quarterStart = getQuarterStart(anchorTime);
|
|
688
|
+
const nextQuarterStart = new Date(quarterStart);
|
|
689
|
+
nextQuarterStart.setMonth(nextQuarterStart.getMonth() + 3);
|
|
690
|
+
const dateTime = date.getTime();
|
|
691
|
+
return dateTime >= quarterStart.getTime() && dateTime < nextQuarterStart.getTime();
|
|
692
|
+
};
|
|
693
|
+
/**
|
|
694
|
+
* The provided date is in the next quarter.
|
|
695
|
+
* @param {Date} date - The date to compare.
|
|
696
|
+
* @param {Date} [anchorTime] - The reference date.
|
|
697
|
+
* @returns {boolean} return the date is match
|
|
698
|
+
*/
|
|
699
|
+
const nextQuarter = (date, anchorTime = /* @__PURE__ */ new Date()) => {
|
|
700
|
+
const quarterStart = getQuarterStart(anchorTime);
|
|
701
|
+
const nextQuarterStart = new Date(quarterStart);
|
|
702
|
+
nextQuarterStart.setMonth(nextQuarterStart.getMonth() + 3);
|
|
703
|
+
const nextQuarterEnd = new Date(nextQuarterStart);
|
|
704
|
+
nextQuarterEnd.setMonth(nextQuarterEnd.getMonth() + 3, 0);
|
|
705
|
+
const dateTime = date.getTime();
|
|
706
|
+
return dateTime >= nextQuarterStart.getTime() && dateTime < nextQuarterEnd.getTime();
|
|
707
|
+
};
|
|
708
|
+
/**
|
|
709
|
+
* The provided date is in the last quarter.
|
|
710
|
+
* @param {Date} date - The date to compare.
|
|
711
|
+
* @param {Date} [anchorTime] - The reference date.
|
|
712
|
+
* @returns {boolean} return the date is match
|
|
713
|
+
*/
|
|
714
|
+
const lastQuarter = (date, anchorTime = /* @__PURE__ */ new Date()) => {
|
|
715
|
+
const quarterStart = getQuarterStart(anchorTime);
|
|
716
|
+
const lastQuarterStart = new Date(quarterStart);
|
|
717
|
+
lastQuarterStart.setMonth(lastQuarterStart.getMonth() - 3);
|
|
718
|
+
const lastQuarterEnd = new Date(quarterStart);
|
|
719
|
+
lastQuarterEnd.setDate(0);
|
|
720
|
+
const dateTime = date.getTime();
|
|
721
|
+
return dateTime >= lastQuarterStart.getTime() && dateTime < lastQuarterEnd.getTime();
|
|
722
|
+
};
|
|
723
|
+
/**
|
|
724
|
+
* The provided date is in the current year.
|
|
725
|
+
* @param {Date} date - The date to compare.
|
|
726
|
+
* @param {Date} [anchorTime] - The reference date.
|
|
727
|
+
* @returns {boolean} return the date is match
|
|
728
|
+
*/
|
|
729
|
+
const thisYear = (date, anchorTime = /* @__PURE__ */ new Date()) => {
|
|
730
|
+
return date.getFullYear() === anchorTime.getFullYear();
|
|
731
|
+
};
|
|
732
|
+
/**
|
|
733
|
+
* The provided date is in the next year.
|
|
734
|
+
* @param {Date} date - The date to compare.
|
|
735
|
+
* @param {Date} [anchorTime] - The reference date.
|
|
736
|
+
* @returns {boolean} return the date is match
|
|
737
|
+
*/
|
|
738
|
+
const nextYear = (date, anchorTime = /* @__PURE__ */ new Date()) => {
|
|
739
|
+
return date.getFullYear() === anchorTime.getFullYear() + 1;
|
|
740
|
+
};
|
|
741
|
+
/**
|
|
742
|
+
* The provided date is in the last year.
|
|
743
|
+
* @param {Date} date - The date to compare.
|
|
744
|
+
* @param {Date} [anchorTime] - The reference date.
|
|
745
|
+
* @returns {boolean} return the date is match
|
|
746
|
+
*/
|
|
747
|
+
const lastYear = (date, anchorTime = /* @__PURE__ */ new Date()) => {
|
|
748
|
+
return date.getFullYear() === anchorTime.getFullYear() - 1;
|
|
749
|
+
};
|
|
750
|
+
/**
|
|
751
|
+
* The provided date is in the year to date.
|
|
752
|
+
* @param {Date} date - The date to compare.
|
|
753
|
+
* @param {Date} [anchorTime] - The reference date.
|
|
754
|
+
* @returns {boolean} return the date is match
|
|
755
|
+
*/
|
|
756
|
+
const yearToDate = (date, anchorTime = /* @__PURE__ */ new Date()) => {
|
|
757
|
+
const yearStart = new Date(anchorTime);
|
|
758
|
+
yearStart.setHours(0, 0, 0, 0);
|
|
759
|
+
yearStart.setMonth(0, 1);
|
|
760
|
+
const dateTime = date.getTime();
|
|
761
|
+
return dateTime >= yearStart.getTime() && dateTime < anchorTime.getTime();
|
|
762
|
+
};
|
|
763
|
+
function getDateFilterExecuteFunc(filterInfo) {
|
|
764
|
+
switch (filterInfo.compareType) {
|
|
765
|
+
case TableDateCompareTypeEnum.Equal: {
|
|
766
|
+
const expected = new Date(filterInfo.expectedValue);
|
|
767
|
+
return (date) => date.getTime() === expected.getTime();
|
|
768
|
+
}
|
|
769
|
+
case TableDateCompareTypeEnum.NotEqual: {
|
|
770
|
+
const expected = new Date(filterInfo.expectedValue);
|
|
771
|
+
return (date) => date.getTime() !== expected.getTime();
|
|
772
|
+
}
|
|
773
|
+
case TableDateCompareTypeEnum.After: {
|
|
774
|
+
const expected = new Date(filterInfo.expectedValue);
|
|
775
|
+
return (date) => date.getTime() > expected.getTime();
|
|
776
|
+
}
|
|
777
|
+
case TableDateCompareTypeEnum.Before: {
|
|
778
|
+
const expected = new Date(filterInfo.expectedValue);
|
|
779
|
+
return (date) => date.getTime() < expected.getTime();
|
|
780
|
+
}
|
|
781
|
+
case TableDateCompareTypeEnum.AfterOrEqual: {
|
|
782
|
+
const expected = new Date(filterInfo.expectedValue);
|
|
783
|
+
return (date) => date.getTime() >= expected.getTime();
|
|
784
|
+
}
|
|
785
|
+
case TableDateCompareTypeEnum.BeforeOrEqual: {
|
|
786
|
+
const expected = new Date(filterInfo.expectedValue);
|
|
787
|
+
return (date) => date.getTime() <= expected.getTime();
|
|
788
|
+
}
|
|
789
|
+
case TableDateCompareTypeEnum.Between: return (date) => {
|
|
790
|
+
const [start, end] = filterInfo.expectedValue;
|
|
791
|
+
return date.getTime() >= new Date(start).getTime() && date.getTime() <= new Date(end).getTime();
|
|
792
|
+
};
|
|
793
|
+
case TableDateCompareTypeEnum.NotBetween: return (date) => {
|
|
794
|
+
const [start, end] = filterInfo.expectedValue;
|
|
795
|
+
return date.getTime() < new Date(start).getTime() || date.getTime() > new Date(end).getTime();
|
|
796
|
+
};
|
|
797
|
+
case TableDateCompareTypeEnum.Today: {
|
|
798
|
+
const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
|
|
799
|
+
return (date) => today(date, anchorTime);
|
|
800
|
+
}
|
|
801
|
+
case TableDateCompareTypeEnum.Yesterday: {
|
|
802
|
+
const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
|
|
803
|
+
return (date) => yesterday(date, anchorTime);
|
|
804
|
+
}
|
|
805
|
+
case TableDateCompareTypeEnum.Tomorrow: {
|
|
806
|
+
const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
|
|
807
|
+
return (date) => tomorrow(date, anchorTime);
|
|
808
|
+
}
|
|
809
|
+
case TableDateCompareTypeEnum.ThisWeek: {
|
|
810
|
+
const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
|
|
811
|
+
return (date) => thisWeek(date, anchorTime);
|
|
812
|
+
}
|
|
813
|
+
case TableDateCompareTypeEnum.LastWeek: {
|
|
814
|
+
const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
|
|
815
|
+
return (date) => lastWeek(date, anchorTime);
|
|
816
|
+
}
|
|
817
|
+
case TableDateCompareTypeEnum.NextWeek: {
|
|
818
|
+
const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
|
|
819
|
+
return (date) => nextWeek(date, anchorTime);
|
|
820
|
+
}
|
|
821
|
+
case TableDateCompareTypeEnum.ThisMonth: {
|
|
822
|
+
const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
|
|
823
|
+
return (date) => thisMonth(date, anchorTime);
|
|
824
|
+
}
|
|
825
|
+
case TableDateCompareTypeEnum.LastMonth: {
|
|
826
|
+
const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
|
|
827
|
+
return (date) => lastMonth(date, anchorTime);
|
|
828
|
+
}
|
|
829
|
+
case TableDateCompareTypeEnum.NextMonth: {
|
|
830
|
+
const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
|
|
831
|
+
return (date) => nextMonth(date, anchorTime);
|
|
832
|
+
}
|
|
833
|
+
case TableDateCompareTypeEnum.ThisQuarter: {
|
|
834
|
+
const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
|
|
835
|
+
return (date) => thisQuarter(date, anchorTime);
|
|
836
|
+
}
|
|
837
|
+
case TableDateCompareTypeEnum.LastQuarter: {
|
|
838
|
+
const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
|
|
839
|
+
return (date) => lastQuarter(date, anchorTime);
|
|
840
|
+
}
|
|
841
|
+
case TableDateCompareTypeEnum.NextQuarter: {
|
|
842
|
+
const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
|
|
843
|
+
return (date) => nextQuarter(date, anchorTime);
|
|
844
|
+
}
|
|
845
|
+
case TableDateCompareTypeEnum.ThisYear: {
|
|
846
|
+
const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
|
|
847
|
+
return (date) => thisYear(date, anchorTime);
|
|
848
|
+
}
|
|
849
|
+
case TableDateCompareTypeEnum.LastYear: {
|
|
850
|
+
const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
|
|
851
|
+
return (date) => lastYear(date, anchorTime);
|
|
852
|
+
}
|
|
853
|
+
case TableDateCompareTypeEnum.NextYear: {
|
|
854
|
+
const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
|
|
855
|
+
return (date) => nextYear(date, anchorTime);
|
|
856
|
+
}
|
|
857
|
+
case TableDateCompareTypeEnum.YearToDate: {
|
|
858
|
+
const anchorTime = filterInfo.anchorTime ? new Date(filterInfo.anchorTime) : /* @__PURE__ */ new Date();
|
|
859
|
+
return (date) => yearToDate(date, anchorTime);
|
|
860
|
+
}
|
|
861
|
+
case TableDateCompareTypeEnum.M1: return dateM1;
|
|
862
|
+
case TableDateCompareTypeEnum.M2: return dateM2;
|
|
863
|
+
case TableDateCompareTypeEnum.M3: return dateM3;
|
|
864
|
+
case TableDateCompareTypeEnum.M4: return dateM4;
|
|
865
|
+
case TableDateCompareTypeEnum.M5: return dateM5;
|
|
866
|
+
case TableDateCompareTypeEnum.M6: return dateM6;
|
|
867
|
+
case TableDateCompareTypeEnum.M7: return dateM7;
|
|
868
|
+
case TableDateCompareTypeEnum.M8: return dateM8;
|
|
869
|
+
case TableDateCompareTypeEnum.M9: return dateM9;
|
|
870
|
+
case TableDateCompareTypeEnum.M10: return dateM10;
|
|
871
|
+
case TableDateCompareTypeEnum.M11: return dateM11;
|
|
872
|
+
case TableDateCompareTypeEnum.M12: return dateM12;
|
|
873
|
+
case TableDateCompareTypeEnum.Q1: return dateQ1;
|
|
874
|
+
case TableDateCompareTypeEnum.Q2: return dateQ2;
|
|
875
|
+
case TableDateCompareTypeEnum.Q3: return dateQ3;
|
|
876
|
+
case TableDateCompareTypeEnum.Q4: return dateQ4;
|
|
877
|
+
default: throw new Error("Unsupported compare type");
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
//#endregion
|
|
882
|
+
//#region src/model/filter-util/top-n.ts
|
|
883
|
+
/**
|
|
884
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
885
|
+
*
|
|
886
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
887
|
+
* you may not use this file except in compliance with the License.
|
|
888
|
+
* You may obtain a copy of the License at
|
|
889
|
+
*
|
|
890
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
891
|
+
*
|
|
892
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
893
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
894
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
895
|
+
* See the License for the specific language governing permissions and
|
|
896
|
+
* limitations under the License.
|
|
897
|
+
*/
|
|
898
|
+
/**
|
|
899
|
+
* @description Represents a heap data structure.
|
|
900
|
+
* A heap is a complete binary tree that satisfies the heap property.
|
|
901
|
+
* The heap property states that the parent node is always smaller or bigger than its children.
|
|
902
|
+
* The root node is the smallest or biggest element in the heap.
|
|
903
|
+
* The heap is used to find the kth largest or smallest element in a list.
|
|
904
|
+
* A array can be used to represent a heap.
|
|
905
|
+
* The root node is at index 0, and the left child of a node at index i is at index 2i + 1.
|
|
906
|
+
* The right child of a node at index i is at index 2i + 2.
|
|
907
|
+
* The parent node of a node at index i is at index (i - 1) / 2.
|
|
908
|
+
* @example
|
|
909
|
+
* const maxHeap = [5, 3, 4, 1, 2];
|
|
910
|
+
* // const minHeap = [6, 8, 7, 10, 9];
|
|
911
|
+
* // the root node in maxHeap is 5
|
|
912
|
+
* // the root child is 3, 4, then the child of 3 is 1, 2
|
|
913
|
+
*/
|
|
914
|
+
var Heap = class {
|
|
915
|
+
/**
|
|
916
|
+
* Initializes a new instance of the Heap class.
|
|
917
|
+
*/
|
|
918
|
+
constructor() {
|
|
919
|
+
_defineProperty(this, "heap", void 0);
|
|
920
|
+
this.heap = [];
|
|
921
|
+
}
|
|
922
|
+
/**
|
|
923
|
+
* Swaps the elements at the given indices in the heap.
|
|
924
|
+
* @param index1 The index of the first element.
|
|
925
|
+
* @param index2 The index of the second element.
|
|
926
|
+
*/
|
|
927
|
+
swap(index1, index2) {
|
|
928
|
+
const temp = this.heap[index1];
|
|
929
|
+
this.heap[index1] = this.heap[index2];
|
|
930
|
+
this.heap[index2] = temp;
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* Returns the index of the parent node for the given index.
|
|
934
|
+
* @param index The index of the node.
|
|
935
|
+
* @returns The index of the parent node.
|
|
936
|
+
*/
|
|
937
|
+
getParentIndex(index) {
|
|
938
|
+
return Math.floor((index - 1) / 2);
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* Returns the index of the left child node for the given index.
|
|
942
|
+
* @param index The index of the node.
|
|
943
|
+
* @returns The index of the left child node.
|
|
944
|
+
*/
|
|
945
|
+
getLeftIndex(index) {
|
|
946
|
+
return index * 2 + 1;
|
|
947
|
+
}
|
|
948
|
+
/**
|
|
949
|
+
* Returns the index of the right child node for the given index.
|
|
950
|
+
* @param index The index of the node.
|
|
951
|
+
* @returns The index of the right child node.
|
|
952
|
+
*/
|
|
953
|
+
getRightIndex(index) {
|
|
954
|
+
return index * 2 + 2;
|
|
955
|
+
}
|
|
956
|
+
/**
|
|
957
|
+
* Returns the number of elements in the heap.
|
|
958
|
+
* @returns The number of elements in the heap.
|
|
959
|
+
*/
|
|
960
|
+
size() {
|
|
961
|
+
return this.heap.length;
|
|
962
|
+
}
|
|
963
|
+
/**
|
|
964
|
+
* Returns the minimum value in the heap without removing it.
|
|
965
|
+
* @returns The minimum value in the heap.
|
|
966
|
+
*/
|
|
967
|
+
peek() {
|
|
968
|
+
return this.heap[0];
|
|
969
|
+
}
|
|
970
|
+
/**
|
|
971
|
+
* @description Returns whether the heap includes the given value.
|
|
972
|
+
* @param {number} value The value to be checked.
|
|
973
|
+
* @returns {boolean} return true if the heap includes the given value
|
|
974
|
+
*/
|
|
975
|
+
include(value) {
|
|
976
|
+
return this.heap.includes(value);
|
|
977
|
+
}
|
|
978
|
+
};
|
|
979
|
+
/**
|
|
980
|
+
* @description Represents a min heap data structure.
|
|
981
|
+
* in MinHeap, the parent node is always smaller than its children.
|
|
982
|
+
* The root node is the smallest element in the heap.
|
|
983
|
+
* The min heap is used to find the kth largest element in a list.
|
|
984
|
+
*/
|
|
985
|
+
var MinHeap = class extends Heap {
|
|
986
|
+
/**
|
|
987
|
+
* Initializes a new instance of the MinHeap class.
|
|
988
|
+
*/
|
|
989
|
+
constructor() {
|
|
990
|
+
super();
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* Moves the element at the given index up the heap until it satisfies the min heap property.
|
|
994
|
+
* @param index The index of the element to be shifted up.
|
|
995
|
+
*/
|
|
996
|
+
shiftUp(index) {
|
|
997
|
+
if (index === 0) return;
|
|
998
|
+
const parentIndex = this.getParentIndex(index);
|
|
999
|
+
if (this.heap[parentIndex] > this.heap[index]) {
|
|
1000
|
+
this.swap(parentIndex, index);
|
|
1001
|
+
this.shiftUp(parentIndex);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
/**
|
|
1005
|
+
* Moves the element at the given index down the heap until it satisfies the min heap property.
|
|
1006
|
+
* @param index The index of the element to be shifted down.
|
|
1007
|
+
*/
|
|
1008
|
+
shiftDown(index) {
|
|
1009
|
+
const leftIndex = this.getLeftIndex(index);
|
|
1010
|
+
const rightIndex = this.getRightIndex(index);
|
|
1011
|
+
if (this.heap[leftIndex] < this.heap[index]) {
|
|
1012
|
+
this.swap(leftIndex, index);
|
|
1013
|
+
this.shiftDown(leftIndex);
|
|
1014
|
+
}
|
|
1015
|
+
if (this.heap[rightIndex] < this.heap[index]) {
|
|
1016
|
+
this.swap(rightIndex, index);
|
|
1017
|
+
this.shiftDown(rightIndex);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
/**
|
|
1021
|
+
* Inserts a new value into the min heap.
|
|
1022
|
+
* @param value The value to be inserted.
|
|
1023
|
+
*/
|
|
1024
|
+
insert(value) {
|
|
1025
|
+
this.heap.push(value);
|
|
1026
|
+
this.shiftUp(this.heap.length - 1);
|
|
1027
|
+
}
|
|
1028
|
+
/**
|
|
1029
|
+
* Removes and returns the minimum value from the min heap.
|
|
1030
|
+
*/
|
|
1031
|
+
pop() {
|
|
1032
|
+
this.heap[0] = this.heap.pop();
|
|
1033
|
+
this.shiftDown(0);
|
|
1034
|
+
}
|
|
1035
|
+
};
|
|
1036
|
+
/**
|
|
1037
|
+
* Returns the kth largest element from the given list using a min heap.
|
|
1038
|
+
* @param {number[]} list The list of numbers.
|
|
1039
|
+
* @param {number} k The value of k.
|
|
1040
|
+
* @returns The kth largest element.
|
|
1041
|
+
*/
|
|
1042
|
+
const getLargestK = (list, k) => {
|
|
1043
|
+
const minHeap = new MinHeap();
|
|
1044
|
+
for (const item of list) {
|
|
1045
|
+
minHeap.insert(item);
|
|
1046
|
+
if (minHeap.size() > k) minHeap.pop();
|
|
1047
|
+
}
|
|
1048
|
+
return minHeap.heap;
|
|
1049
|
+
};
|
|
1050
|
+
|
|
1051
|
+
//#endregion
|
|
1052
|
+
//#region src/model/filter-util/number-filter-util.ts
|
|
1053
|
+
/**
|
|
1054
|
+
* @description Checks if a value is above the average.
|
|
1055
|
+
* @param {number} value - The value to check.
|
|
1056
|
+
* @param {number} average - The average value.
|
|
1057
|
+
* @returns {boolean} A boolean value indicating whether the value is above the average.
|
|
1058
|
+
*/
|
|
1059
|
+
const above = (value, average) => {
|
|
1060
|
+
return value > average;
|
|
1061
|
+
};
|
|
1062
|
+
/**
|
|
1063
|
+
* @description Checks if a value is below the average.
|
|
1064
|
+
* @param {number} value - The value to check.
|
|
1065
|
+
* @param {number} average - The average value.
|
|
1066
|
+
* @returns {boolean} A boolean value indicating whether the value is below the average.
|
|
1067
|
+
*/
|
|
1068
|
+
const below = (value, average) => {
|
|
1069
|
+
return value < average;
|
|
1070
|
+
};
|
|
1071
|
+
/**
|
|
1072
|
+
* @description Gets the largest N values from a list and checks if the expected value is included.
|
|
1073
|
+
* @param {number[]} list - The list of numbers.
|
|
1074
|
+
* @param {number} top - The number of top values to retrieve.
|
|
1075
|
+
* @param {number} expectedValue - The expected value to check for inclusion.
|
|
1076
|
+
* @returns {boolean} A boolean value indicating whether the expected value is included in the top N values.
|
|
1077
|
+
*/
|
|
1078
|
+
const getTopN = (list, top, expectedValue) => {
|
|
1079
|
+
return getLargestK(list, top).includes(expectedValue);
|
|
1080
|
+
};
|
|
1081
|
+
function getNumberFilterExecuteFunc(filter, calculatedOptions) {
|
|
1082
|
+
switch (filter.compareType) {
|
|
1083
|
+
case TableNumberCompareTypeEnum.Equal: {
|
|
1084
|
+
const expectedValue = Number(filter.expectedValue);
|
|
1085
|
+
return (value) => value === expectedValue;
|
|
1086
|
+
}
|
|
1087
|
+
case TableNumberCompareTypeEnum.NotEqual: {
|
|
1088
|
+
const expectedValue = Number(filter.expectedValue);
|
|
1089
|
+
return (value) => value !== expectedValue;
|
|
1090
|
+
}
|
|
1091
|
+
case TableNumberCompareTypeEnum.GreaterThan: {
|
|
1092
|
+
const expectedValue = Number(filter.expectedValue);
|
|
1093
|
+
return (value) => value > expectedValue;
|
|
1094
|
+
}
|
|
1095
|
+
case TableNumberCompareTypeEnum.GreaterThanOrEqual: {
|
|
1096
|
+
const expectedValue = Number(filter.expectedValue);
|
|
1097
|
+
return (value) => value >= expectedValue;
|
|
1098
|
+
}
|
|
1099
|
+
case TableNumberCompareTypeEnum.LessThan: {
|
|
1100
|
+
const expectedValue = Number(filter.expectedValue);
|
|
1101
|
+
return (value) => value < expectedValue;
|
|
1102
|
+
}
|
|
1103
|
+
case TableNumberCompareTypeEnum.LessThanOrEqual: {
|
|
1104
|
+
const expectedValue = Number(filter.expectedValue);
|
|
1105
|
+
return (value) => value <= expectedValue;
|
|
1106
|
+
}
|
|
1107
|
+
case TableNumberCompareTypeEnum.Between: {
|
|
1108
|
+
const [min, max] = filter.expectedValue;
|
|
1109
|
+
const minValue = Number(min);
|
|
1110
|
+
const maxValue = Number(max);
|
|
1111
|
+
if (minValue > maxValue) return (value) => value >= maxValue && value <= minValue;
|
|
1112
|
+
return (value) => value >= minValue && value <= maxValue;
|
|
1113
|
+
}
|
|
1114
|
+
case TableNumberCompareTypeEnum.NotBetween: {
|
|
1115
|
+
const [min, max] = filter.expectedValue;
|
|
1116
|
+
const minValue = Number(min);
|
|
1117
|
+
const maxValue = Number(max);
|
|
1118
|
+
if (minValue > maxValue) return (value) => value < maxValue || value > minValue;
|
|
1119
|
+
return (value) => value < minValue || value > maxValue;
|
|
1120
|
+
}
|
|
1121
|
+
case TableNumberCompareTypeEnum.Above: {
|
|
1122
|
+
const average = calculatedOptions.average;
|
|
1123
|
+
return (value) => above(value, average);
|
|
1124
|
+
}
|
|
1125
|
+
case TableNumberCompareTypeEnum.Below: {
|
|
1126
|
+
const average = calculatedOptions.average;
|
|
1127
|
+
return (value) => below(value, average);
|
|
1128
|
+
}
|
|
1129
|
+
case TableNumberCompareTypeEnum.TopN: {
|
|
1130
|
+
const list = calculatedOptions.list;
|
|
1131
|
+
const top = Number(filter.expectedValue);
|
|
1132
|
+
return (value) => getTopN(list, top, value);
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
//#endregion
|
|
1138
|
+
//#region src/model/filter-util/text-filter-util.ts
|
|
1139
|
+
const textEqual = (compareValue, expectedValue) => {
|
|
1140
|
+
return createREGEXFromWildChar(expectedValue).test(compareValue);
|
|
1141
|
+
};
|
|
1142
|
+
const textNotEqual = (compareValue, expectedValue) => {
|
|
1143
|
+
return !createREGEXFromWildChar(expectedValue).test(compareValue);
|
|
1144
|
+
};
|
|
1145
|
+
const textContain = (compareValue, expectedValue) => {
|
|
1146
|
+
return createREGEXFromWildChar(`*${expectedValue}*`).test(compareValue);
|
|
1147
|
+
};
|
|
1148
|
+
const textNotContain = (compareValue, expectedValue) => {
|
|
1149
|
+
return !createREGEXFromWildChar(`*${expectedValue}*`).test(compareValue);
|
|
1150
|
+
};
|
|
1151
|
+
const textStartWith = (compareValue, expectedValue) => {
|
|
1152
|
+
return createREGEXFromWildChar(`${expectedValue}*`).test(compareValue);
|
|
1153
|
+
};
|
|
1154
|
+
const textEndWith = (compareValue, expectedValue) => {
|
|
1155
|
+
return createREGEXFromWildChar(`*${expectedValue}`).test(compareValue);
|
|
1156
|
+
};
|
|
1157
|
+
function getTextFilterExecuteFunc(filter) {
|
|
1158
|
+
switch (filter.compareType) {
|
|
1159
|
+
case TableStringCompareTypeEnum.Equal: return (value) => textEqual(value, filter.expectedValue);
|
|
1160
|
+
case TableStringCompareTypeEnum.NotEqual: return (value) => textNotEqual(value, filter.expectedValue);
|
|
1161
|
+
case TableStringCompareTypeEnum.Contains: return (value) => textContain(value, filter.expectedValue);
|
|
1162
|
+
case TableStringCompareTypeEnum.NotContains: return (value) => textNotContain(value, filter.expectedValue);
|
|
1163
|
+
case TableStringCompareTypeEnum.StartsWith: return (value) => textStartWith(value, filter.expectedValue);
|
|
1164
|
+
case TableStringCompareTypeEnum.EndsWith: return (value) => textEndWith(value, filter.expectedValue);
|
|
1165
|
+
default:
|
|
1166
|
+
console.error(`Unknown filter operator: ${filter.compareType}`);
|
|
1167
|
+
return (value) => true;
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
//#endregion
|
|
1172
|
+
//#region src/model/filter-util/condition.ts
|
|
1173
|
+
const NumberDynamicFilterCompareTypeSet = new Set([
|
|
1174
|
+
TableNumberCompareTypeEnum.Above,
|
|
1175
|
+
TableNumberCompareTypeEnum.Below,
|
|
1176
|
+
TableNumberCompareTypeEnum.TopN
|
|
1177
|
+
]);
|
|
1178
|
+
const DateDynamicFilterCompareTypeSet = new Set([
|
|
1179
|
+
TableDateCompareTypeEnum.Today,
|
|
1180
|
+
TableDateCompareTypeEnum.Yesterday,
|
|
1181
|
+
TableDateCompareTypeEnum.Tomorrow,
|
|
1182
|
+
TableDateCompareTypeEnum.ThisWeek,
|
|
1183
|
+
TableDateCompareTypeEnum.LastWeek,
|
|
1184
|
+
TableDateCompareTypeEnum.NextWeek,
|
|
1185
|
+
TableDateCompareTypeEnum.ThisMonth,
|
|
1186
|
+
TableDateCompareTypeEnum.LastMonth,
|
|
1187
|
+
TableDateCompareTypeEnum.NextMonth,
|
|
1188
|
+
TableDateCompareTypeEnum.ThisQuarter,
|
|
1189
|
+
TableDateCompareTypeEnum.LastQuarter,
|
|
1190
|
+
TableDateCompareTypeEnum.NextQuarter,
|
|
1191
|
+
TableDateCompareTypeEnum.NextYear,
|
|
1192
|
+
TableDateCompareTypeEnum.ThisYear,
|
|
1193
|
+
TableDateCompareTypeEnum.LastYear,
|
|
1194
|
+
TableDateCompareTypeEnum.YearToDate
|
|
1195
|
+
]);
|
|
1196
|
+
function isNumberDynamicFilter(compareType) {
|
|
1197
|
+
return NumberDynamicFilterCompareTypeSet.has(compareType);
|
|
1198
|
+
}
|
|
1199
|
+
function getConditionExecuteFunc(filter, calculatedOptions) {
|
|
1200
|
+
if (isNumberDynamicFilter(filter.filterInfo.compareType)) return (value) => true;
|
|
1201
|
+
else switch (filter.filterInfo.conditionType) {
|
|
1202
|
+
case TableConditionTypeEnum.Date: return getDateFilterExecuteFunc(filter.filterInfo);
|
|
1203
|
+
case TableConditionTypeEnum.Number: return getNumberFilterExecuteFunc(filter.filterInfo, calculatedOptions);
|
|
1204
|
+
case TableConditionTypeEnum.String: return getTextFilterExecuteFunc(filter.filterInfo);
|
|
1205
|
+
case TableConditionTypeEnum.Logic:
|
|
1206
|
+
default: return (value) => true;
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
function getCellValueWithConditionType(sheet, row, col, conditionType) {
|
|
1210
|
+
switch (conditionType) {
|
|
1211
|
+
case TableConditionTypeEnum.Date: {
|
|
1212
|
+
const dateNumber = getNumberCellValue(sheet, row, col);
|
|
1213
|
+
return dateNumber ? excelSerialToDateTime(dateNumber) : null;
|
|
1214
|
+
}
|
|
1215
|
+
case TableConditionTypeEnum.Number: return getNumberCellValue(sheet, row, col);
|
|
1216
|
+
case TableConditionTypeEnum.String:
|
|
1217
|
+
default: return getStringCellValue(sheet, row, col);
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
const getStringFromDataStream = (data) => {
|
|
1221
|
+
var _data$body;
|
|
1222
|
+
return ((_data$body = data.body) === null || _data$body === void 0 ? void 0 : _data$body.dataStream.replace(/\r\n$/, "")) || "";
|
|
1223
|
+
};
|
|
1224
|
+
function getStringCellValue(sheet, row, col) {
|
|
1225
|
+
const cellData = sheet.getCell(row, col);
|
|
1226
|
+
if (!cellData) return null;
|
|
1227
|
+
const { v, t, p } = cellData;
|
|
1228
|
+
if (p) return getStringFromDataStream(p);
|
|
1229
|
+
if (typeof v === "string") {
|
|
1230
|
+
if (t === CellValueType.BOOLEAN) return v.toUpperCase();
|
|
1231
|
+
return v;
|
|
1232
|
+
}
|
|
1233
|
+
if (typeof v === "number") {
|
|
1234
|
+
if (t === CellValueType.BOOLEAN) return v ? "TRUE" : "FALSE";
|
|
1235
|
+
return v;
|
|
1236
|
+
}
|
|
1237
|
+
if (typeof v === "boolean") return v ? "TRUE" : "FALSE";
|
|
1238
|
+
if (v === void 0) return;
|
|
1239
|
+
return String(v);
|
|
1240
|
+
}
|
|
1241
|
+
function getNumberCellValue(sheet, row, col) {
|
|
1242
|
+
const cellData = sheet.getCell(row, col);
|
|
1243
|
+
if (!cellData) return null;
|
|
1244
|
+
const { v, t, p } = cellData;
|
|
1245
|
+
if (p) return null;
|
|
1246
|
+
if (typeof v === "string" && t === CellValueType.NUMBER) return Number(sheet.getCellRaw(row, col).v);
|
|
1247
|
+
return Number(v);
|
|
1248
|
+
}
|
|
1249
|
+
function excelSerialToDateTime(serial) {
|
|
1250
|
+
const baseDate = new Date(Date.UTC(1900, 0, 1, 0, 0, 0));
|
|
1251
|
+
const leapDayDate = new Date(Date.UTC(1900, 1, 28, 0, 0, 0));
|
|
1252
|
+
let dayDifference = serial - 1;
|
|
1253
|
+
if (dayDifference > (leapDayDate.getTime() - baseDate.getTime()) / (1e3 * 3600 * 24)) dayDifference -= 1;
|
|
1254
|
+
if (dayDifference < 0) dayDifference = serial;
|
|
1255
|
+
return new Date(baseDate.getTime() + dayDifference * (1e3 * 3600 * 24));
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
//#endregion
|
|
1259
|
+
//#region src/model/table-filter.ts
|
|
1260
|
+
var TableFilters = class {
|
|
1261
|
+
constructor() {
|
|
1262
|
+
_defineProperty(this, "_tableColumnFilterList", void 0);
|
|
1263
|
+
_defineProperty(this, "_tableSortInfo", void 0);
|
|
1264
|
+
_defineProperty(this, "_filterOutRows", void 0);
|
|
1265
|
+
this._tableColumnFilterList = [];
|
|
1266
|
+
}
|
|
1267
|
+
setColumnFilter(columnIndex, filter) {
|
|
1268
|
+
if (!filter) this._tableColumnFilterList[columnIndex] = void 0;
|
|
1269
|
+
else this._tableColumnFilterList[columnIndex] = filter;
|
|
1270
|
+
}
|
|
1271
|
+
setSortState(columnIndex, sortState) {
|
|
1272
|
+
this._tableSortInfo = {
|
|
1273
|
+
columnIndex,
|
|
1274
|
+
sortState
|
|
1275
|
+
};
|
|
1276
|
+
}
|
|
1277
|
+
getColumnFilter(columnIndex) {
|
|
1278
|
+
return this._tableColumnFilterList[columnIndex];
|
|
1279
|
+
}
|
|
1280
|
+
getFilterState(columnIndex) {
|
|
1281
|
+
var _this$_tableSortInfo;
|
|
1282
|
+
const sortState = ((_this$_tableSortInfo = this._tableSortInfo) === null || _this$_tableSortInfo === void 0 ? void 0 : _this$_tableSortInfo.columnIndex) === columnIndex ? this._tableSortInfo.sortState : SheetsTableSortStateEnum.None;
|
|
1283
|
+
return getTableFilterState(this._tableColumnFilterList[columnIndex], sortState);
|
|
1284
|
+
}
|
|
1285
|
+
getSortState() {
|
|
1286
|
+
var _this$_tableSortInfo2;
|
|
1287
|
+
return (_this$_tableSortInfo2 = this._tableSortInfo) !== null && _this$_tableSortInfo2 !== void 0 ? _this$_tableSortInfo2 : {};
|
|
1288
|
+
}
|
|
1289
|
+
getFilterStates(range) {
|
|
1290
|
+
const states = [];
|
|
1291
|
+
const { startColumn, endColumn } = range;
|
|
1292
|
+
for (let i = startColumn; i <= endColumn; i++) states.push(this.getFilterState(i - startColumn));
|
|
1293
|
+
return states;
|
|
1294
|
+
}
|
|
1295
|
+
getFilterOutRows() {
|
|
1296
|
+
return this._filterOutRows;
|
|
1297
|
+
}
|
|
1298
|
+
doFilter(sheet, range) {
|
|
1299
|
+
const filterOutRows = /* @__PURE__ */ new Set();
|
|
1300
|
+
const tableColumnFilterList = this._tableColumnFilterList;
|
|
1301
|
+
for (let i = 0; i < tableColumnFilterList.length; i++) if (tableColumnFilterList[i]) this.doColumnFilter(sheet, range, i, filterOutRows);
|
|
1302
|
+
this._filterOutRows = filterOutRows;
|
|
1303
|
+
return filterOutRows;
|
|
1304
|
+
}
|
|
1305
|
+
doColumnFilter(sheet, range, columnIndex, filterOutRows) {
|
|
1306
|
+
const filter = this._tableColumnFilterList[columnIndex];
|
|
1307
|
+
if (filter && sheet) {
|
|
1308
|
+
const { startRow, endRow, startColumn } = range;
|
|
1309
|
+
const column = startColumn + columnIndex;
|
|
1310
|
+
const executeFunc = this.getExecuteFunc(sheet, range, columnIndex, filter);
|
|
1311
|
+
for (let row = startRow; row <= endRow; row++) {
|
|
1312
|
+
const conditionType = isConditionFilter(filter) ? filter.filterInfo.conditionType : TableConditionTypeEnum.String;
|
|
1313
|
+
if (getCellValueWithConditionType(sheet, row, column, conditionType) === null) filterOutRows.add(row);
|
|
1314
|
+
else if (!executeFunc(getCellValueWithConditionType(sheet, row, column, conditionType))) filterOutRows.add(row);
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
_getNumberCalculatedOptions(sheet, range, columnIndex) {
|
|
1319
|
+
const { startRow, endRow, startColumn } = range;
|
|
1320
|
+
const column = startColumn + columnIndex;
|
|
1321
|
+
const list = [];
|
|
1322
|
+
let count = 0;
|
|
1323
|
+
let sum = 0;
|
|
1324
|
+
for (let row = startRow; row <= endRow; row++) {
|
|
1325
|
+
const val = getCellValueWithConditionType(sheet, row, column, TableConditionTypeEnum.Number);
|
|
1326
|
+
if (val !== null) {
|
|
1327
|
+
list.push(val);
|
|
1328
|
+
count++;
|
|
1329
|
+
sum += val;
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
return {
|
|
1333
|
+
list,
|
|
1334
|
+
average: count > 0 ? sum / count : 0
|
|
1335
|
+
};
|
|
1336
|
+
}
|
|
1337
|
+
getExecuteFunc(sheet, range, columnIndex, filter) {
|
|
1338
|
+
if (filter.filterType === TableColumnFilterTypeEnum.manual) {
|
|
1339
|
+
const valuesSet = new Set(filter.values);
|
|
1340
|
+
return (value) => {
|
|
1341
|
+
return valuesSet.has(value);
|
|
1342
|
+
};
|
|
1343
|
+
} else if (filter.filterType === TableColumnFilterTypeEnum.condition) return getConditionExecuteFunc(filter, isNumberDynamicFilter(filter.filterInfo.compareType) ? this._getNumberCalculatedOptions(sheet, range, columnIndex) : void 0);
|
|
1344
|
+
else return (value) => {
|
|
1345
|
+
return true;
|
|
1346
|
+
};
|
|
1347
|
+
}
|
|
1348
|
+
toJSON() {
|
|
1349
|
+
return {
|
|
1350
|
+
tableColumnFilterList: this._tableColumnFilterList,
|
|
1351
|
+
tableSortInfo: this._tableSortInfo
|
|
1352
|
+
};
|
|
1353
|
+
}
|
|
1354
|
+
fromJSON(json) {
|
|
1355
|
+
var _json$tableColumnFilt;
|
|
1356
|
+
this._tableColumnFilterList = (_json$tableColumnFilt = json.tableColumnFilterList) !== null && _json$tableColumnFilt !== void 0 ? _json$tableColumnFilt : [];
|
|
1357
|
+
if (json.tableSortInfo) this._tableSortInfo = json.tableSortInfo;
|
|
1358
|
+
}
|
|
1359
|
+
dispose() {
|
|
1360
|
+
this._tableColumnFilterList = [];
|
|
1361
|
+
}
|
|
1362
|
+
};
|
|
1363
|
+
|
|
1364
|
+
//#endregion
|
|
1365
|
+
//#region src/model/table.ts
|
|
1366
|
+
var Table = class {
|
|
1367
|
+
constructor(id, name, range, header, options = {}) {
|
|
1368
|
+
_defineProperty(this, "_id", void 0);
|
|
1369
|
+
_defineProperty(this, "_name", void 0);
|
|
1370
|
+
_defineProperty(this, "_tableStyleId", void 0);
|
|
1371
|
+
_defineProperty(this, "_showHeader", void 0);
|
|
1372
|
+
_defineProperty(this, "_showFooter", void 0);
|
|
1373
|
+
_defineProperty(this, "_range", void 0);
|
|
1374
|
+
_defineProperty(this, "_columns", /* @__PURE__ */ new Map());
|
|
1375
|
+
_defineProperty(this, "_columnOrder", []);
|
|
1376
|
+
_defineProperty(this, "tableMeta", void 0);
|
|
1377
|
+
_defineProperty(this, "_tableFilters", void 0);
|
|
1378
|
+
_defineProperty(this, "_subUnitId", void 0);
|
|
1379
|
+
this._id = id;
|
|
1380
|
+
this._range = range;
|
|
1381
|
+
this._name = name;
|
|
1382
|
+
this._tableFilters = new TableFilters();
|
|
1383
|
+
this._init(header, options);
|
|
1384
|
+
}
|
|
1385
|
+
_init(header, options) {
|
|
1386
|
+
var _options$showHeader;
|
|
1387
|
+
this._tableStyleId = options === null || options === void 0 ? void 0 : options.tableStyleId;
|
|
1388
|
+
this._showHeader = (_options$showHeader = options === null || options === void 0 ? void 0 : options.showHeader) !== null && _options$showHeader !== void 0 ? _options$showHeader : true;
|
|
1389
|
+
this._showFooter = false;
|
|
1390
|
+
const range = this.getRange();
|
|
1391
|
+
const startColumn = range.startColumn;
|
|
1392
|
+
const endColumn = range.endColumn;
|
|
1393
|
+
for (let i = startColumn; i <= endColumn; i++) {
|
|
1394
|
+
var _options$columns;
|
|
1395
|
+
const index = i - startColumn;
|
|
1396
|
+
let id;
|
|
1397
|
+
let columnName;
|
|
1398
|
+
if ((_options$columns = options.columns) === null || _options$columns === void 0 ? void 0 : _options$columns[index]) {
|
|
1399
|
+
id = options.columns[index].id;
|
|
1400
|
+
columnName = options.columns[index].displayName;
|
|
1401
|
+
} else {
|
|
1402
|
+
id = generateRandomId();
|
|
1403
|
+
columnName = header[i - startColumn];
|
|
1404
|
+
}
|
|
1405
|
+
const column = new TableColumn(id, columnName);
|
|
1406
|
+
this._columns.set(id, column);
|
|
1407
|
+
this._columnOrder.push(id);
|
|
1408
|
+
}
|
|
1409
|
+
if (options.filters) options.filters.forEach((filter, index) => {
|
|
1410
|
+
if (filter) this._tableFilters.setColumnFilter(index, filter);
|
|
1411
|
+
});
|
|
1412
|
+
}
|
|
1413
|
+
setTableFilterColumn(columnIndex, filter) {
|
|
1414
|
+
this._tableFilters.setColumnFilter(columnIndex, filter);
|
|
1415
|
+
}
|
|
1416
|
+
getTableFilterColumn(columnIndex) {
|
|
1417
|
+
return this._tableFilters.getColumnFilter(columnIndex);
|
|
1418
|
+
}
|
|
1419
|
+
getTableFilters() {
|
|
1420
|
+
return this._tableFilters;
|
|
1421
|
+
}
|
|
1422
|
+
getTableFilterRange() {
|
|
1423
|
+
const tableRange = this.getRange();
|
|
1424
|
+
const showHeader = this.isShowHeader();
|
|
1425
|
+
const isShowFooter = this.isShowFooter();
|
|
1426
|
+
const { startRow, startColumn, endRow, endColumn } = tableRange;
|
|
1427
|
+
return {
|
|
1428
|
+
startRow: showHeader ? startRow + 1 : startRow,
|
|
1429
|
+
startColumn,
|
|
1430
|
+
endRow: isShowFooter ? endRow - 1 : endRow,
|
|
1431
|
+
endColumn
|
|
1432
|
+
};
|
|
1433
|
+
}
|
|
1434
|
+
setColumns(columns) {
|
|
1435
|
+
this._columns.clear();
|
|
1436
|
+
this._columnOrder = [];
|
|
1437
|
+
columns.forEach((columnJson) => {
|
|
1438
|
+
const column = new TableColumn(columnJson.id, columnJson.displayName);
|
|
1439
|
+
column.fromJSON(columnJson);
|
|
1440
|
+
this._columns.set(columnJson.id, column);
|
|
1441
|
+
this._columnOrder.push(columnJson.id);
|
|
1442
|
+
});
|
|
1443
|
+
}
|
|
1444
|
+
getColumnsCount() {
|
|
1445
|
+
return this._columnOrder.length;
|
|
1446
|
+
}
|
|
1447
|
+
insertColumn(index, column) {
|
|
1448
|
+
const columnId = column.id;
|
|
1449
|
+
this._columns.set(columnId, column);
|
|
1450
|
+
this._columnOrder.splice(index, 0, columnId);
|
|
1451
|
+
}
|
|
1452
|
+
removeColumn(index) {
|
|
1453
|
+
const columnId = this._columnOrder[index];
|
|
1454
|
+
this._columns.delete(columnId);
|
|
1455
|
+
this._columnOrder.splice(index, 1);
|
|
1456
|
+
}
|
|
1457
|
+
setTableMeta(meta) {
|
|
1458
|
+
this.tableMeta = meta;
|
|
1459
|
+
}
|
|
1460
|
+
getTableMeta() {
|
|
1461
|
+
return this.tableMeta;
|
|
1462
|
+
}
|
|
1463
|
+
getColumn(columnId) {
|
|
1464
|
+
return this._columns.get(columnId);
|
|
1465
|
+
}
|
|
1466
|
+
getTableColumnByIndex(index) {
|
|
1467
|
+
const id = this._columnOrder[index];
|
|
1468
|
+
return this.getColumn(id);
|
|
1469
|
+
}
|
|
1470
|
+
getColumnNameByIndex(index) {
|
|
1471
|
+
var _this$getColumn;
|
|
1472
|
+
const id = this._columnOrder[index];
|
|
1473
|
+
return ((_this$getColumn = this.getColumn(id)) === null || _this$getColumn === void 0 ? void 0 : _this$getColumn.getDisplayName()) || "";
|
|
1474
|
+
}
|
|
1475
|
+
getId() {
|
|
1476
|
+
return this._id;
|
|
1477
|
+
}
|
|
1478
|
+
getRangeInfo() {
|
|
1479
|
+
return { ...this._range };
|
|
1480
|
+
}
|
|
1481
|
+
getRange() {
|
|
1482
|
+
return { ...this._range };
|
|
1483
|
+
}
|
|
1484
|
+
setRange(range) {
|
|
1485
|
+
this._range = range;
|
|
1486
|
+
}
|
|
1487
|
+
setDisplayName(name) {
|
|
1488
|
+
this._name = name;
|
|
1489
|
+
}
|
|
1490
|
+
getDisplayName() {
|
|
1491
|
+
return this._name;
|
|
1492
|
+
}
|
|
1493
|
+
getSubunitId() {
|
|
1494
|
+
return this._subUnitId;
|
|
1495
|
+
}
|
|
1496
|
+
setSubunitId(subUnitId) {
|
|
1497
|
+
this._subUnitId = subUnitId;
|
|
1498
|
+
}
|
|
1499
|
+
getTableStyleId() {
|
|
1500
|
+
var _this$_tableStyleId;
|
|
1501
|
+
return (_this$_tableStyleId = this._tableStyleId) !== null && _this$_tableStyleId !== void 0 ? _this$_tableStyleId : tableThemeConfig[0].name;
|
|
1502
|
+
}
|
|
1503
|
+
setTableStyleId(tableStyleId) {
|
|
1504
|
+
this._tableStyleId = tableStyleId;
|
|
1505
|
+
}
|
|
1506
|
+
isShowHeader() {
|
|
1507
|
+
var _this$_showHeader;
|
|
1508
|
+
return (_this$_showHeader = this._showHeader) !== null && _this$_showHeader !== void 0 ? _this$_showHeader : true;
|
|
1509
|
+
}
|
|
1510
|
+
setShowHeader(showHeader) {
|
|
1511
|
+
this._showHeader = showHeader;
|
|
1512
|
+
}
|
|
1513
|
+
isShowFooter() {
|
|
1514
|
+
var _this$_showFooter;
|
|
1515
|
+
return (_this$_showFooter = this._showFooter) !== null && _this$_showFooter !== void 0 ? _this$_showFooter : false;
|
|
1516
|
+
}
|
|
1517
|
+
getTableInfo() {
|
|
1518
|
+
return {
|
|
1519
|
+
id: this._id,
|
|
1520
|
+
subUnitId: this._subUnitId,
|
|
1521
|
+
name: this._name,
|
|
1522
|
+
range: this.getRangeInfo(),
|
|
1523
|
+
meta: this.tableMeta,
|
|
1524
|
+
showHeader: this._showHeader,
|
|
1525
|
+
columns: this._columnOrder.map((columnId) => this._columns.get(columnId).toJSON())
|
|
1526
|
+
};
|
|
1527
|
+
}
|
|
1528
|
+
getTableConfig() {
|
|
1529
|
+
return {
|
|
1530
|
+
name: this.getDisplayName(),
|
|
1531
|
+
range: this.getRangeInfo(),
|
|
1532
|
+
options: {
|
|
1533
|
+
showHeader: this._showHeader,
|
|
1534
|
+
showFooter: this._showFooter
|
|
1535
|
+
},
|
|
1536
|
+
tableStyleId: this._tableStyleId
|
|
1537
|
+
};
|
|
1538
|
+
}
|
|
1539
|
+
getFilterStates(range) {
|
|
1540
|
+
return this._tableFilters.getFilterStates(range);
|
|
1541
|
+
}
|
|
1542
|
+
toJSON() {
|
|
1543
|
+
const columns = [];
|
|
1544
|
+
this._columns.forEach((column) => {
|
|
1545
|
+
columns.push(column.toJSON());
|
|
1546
|
+
});
|
|
1547
|
+
return {
|
|
1548
|
+
id: this._id,
|
|
1549
|
+
name: this._name,
|
|
1550
|
+
range: this.getRangeInfo(),
|
|
1551
|
+
options: {
|
|
1552
|
+
showHeader: this._showHeader,
|
|
1553
|
+
showFooter: this._showFooter,
|
|
1554
|
+
tableStyleId: this._tableStyleId
|
|
1555
|
+
},
|
|
1556
|
+
filters: this._tableFilters.toJSON(),
|
|
1557
|
+
columns,
|
|
1558
|
+
meta: this.tableMeta
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1561
|
+
fromJSON(json) {
|
|
1562
|
+
var _json$options$showHea, _json$options$showFoo;
|
|
1563
|
+
this._id = json.id;
|
|
1564
|
+
this._name = json.name;
|
|
1565
|
+
this._range = json.range;
|
|
1566
|
+
this.tableMeta = json.meta;
|
|
1567
|
+
this._tableStyleId = json.options.tableStyleId || "";
|
|
1568
|
+
this._showHeader = (_json$options$showHea = json.options.showHeader) !== null && _json$options$showHea !== void 0 ? _json$options$showHea : true;
|
|
1569
|
+
this._showFooter = (_json$options$showFoo = json.options.showFooter) !== null && _json$options$showFoo !== void 0 ? _json$options$showFoo : true;
|
|
1570
|
+
json.columns.forEach((column) => {
|
|
1571
|
+
const tableColumn = new TableColumn(column.id, column.displayName);
|
|
1572
|
+
tableColumn.fromJSON(column);
|
|
1573
|
+
this._columns.set(column.id, tableColumn);
|
|
1574
|
+
this._columnOrder.push(column.id);
|
|
1575
|
+
});
|
|
1576
|
+
this._tableFilters = new TableFilters();
|
|
1577
|
+
this._tableFilters.fromJSON(json.filters);
|
|
1578
|
+
}
|
|
1579
|
+
dispose() {
|
|
1580
|
+
this._id = "";
|
|
1581
|
+
this._name = "";
|
|
1582
|
+
this._tableStyleId = "";
|
|
1583
|
+
this._showHeader = true;
|
|
1584
|
+
this._showFooter = true;
|
|
1585
|
+
delete this._range;
|
|
1586
|
+
this._columns.clear();
|
|
1587
|
+
this._columnOrder = [];
|
|
1588
|
+
}
|
|
1589
|
+
};
|
|
1590
|
+
|
|
1591
|
+
//#endregion
|
|
1592
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
|
|
1593
|
+
function __decorateParam(paramIndex, decorator) {
|
|
1594
|
+
return function(target, key) {
|
|
1595
|
+
decorator(target, key, paramIndex);
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
//#endregion
|
|
1600
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
|
|
1601
|
+
function __decorate(decorators, target, key, desc) {
|
|
1602
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1603
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1604
|
+
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;
|
|
1605
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
//#endregion
|
|
1609
|
+
//#region src/model/table-manager.ts
|
|
1610
|
+
let TableManager = class TableManager extends Disposable {
|
|
1611
|
+
constructor(_univerInstanceService, _localeService) {
|
|
1612
|
+
super();
|
|
1613
|
+
this._univerInstanceService = _univerInstanceService;
|
|
1614
|
+
this._localeService = _localeService;
|
|
1615
|
+
_defineProperty(this, "_tableMap", void 0);
|
|
1616
|
+
_defineProperty(this, "_tableAdd$", new Subject());
|
|
1617
|
+
_defineProperty(this, "tableAdd$", this._tableAdd$.asObservable());
|
|
1618
|
+
_defineProperty(this, "_tableDelete$", new Subject());
|
|
1619
|
+
_defineProperty(this, "tableDelete$", this._tableDelete$.asObservable());
|
|
1620
|
+
_defineProperty(this, "_tableNameChanged$", new Subject());
|
|
1621
|
+
_defineProperty(this, "tableNameChanged$", this._tableNameChanged$.asObservable());
|
|
1622
|
+
_defineProperty(this, "_tableRangeChanged$", new Subject());
|
|
1623
|
+
_defineProperty(this, "tableRangeChanged$", this._tableRangeChanged$.asObservable());
|
|
1624
|
+
_defineProperty(this, "_tableThemeChanged$", new Subject());
|
|
1625
|
+
_defineProperty(this, "tableThemeChanged$", this._tableThemeChanged$.asObservable());
|
|
1626
|
+
_defineProperty(this, "_tableFilterChanged$", new Subject());
|
|
1627
|
+
_defineProperty(this, "tableFilterChanged$", this._tableFilterChanged$.asObservable());
|
|
1628
|
+
_defineProperty(this, "_tableInitStatus", new BehaviorSubject(false));
|
|
1629
|
+
_defineProperty(this, "tableInitStatus$", this._tableInitStatus.asObservable());
|
|
1630
|
+
this._tableMap = /* @__PURE__ */ new Map();
|
|
1631
|
+
}
|
|
1632
|
+
_ensureUnit(unitId) {
|
|
1633
|
+
if (!this._tableMap.has(unitId)) this._tableMap.set(unitId, /* @__PURE__ */ new Map());
|
|
1634
|
+
return this._tableMap.get(unitId);
|
|
1635
|
+
}
|
|
1636
|
+
getColumnHeader(unitId, subUnitId, range, prefixText) {
|
|
1637
|
+
var _this$_univerInstance;
|
|
1638
|
+
const worksheet = (_this$_univerInstance = this._univerInstanceService.getUnit(unitId)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getSheetBySheetId(subUnitId);
|
|
1639
|
+
const { startRow, startColumn, endColumn } = range;
|
|
1640
|
+
const header = [];
|
|
1641
|
+
const columnText = prefixText !== null && prefixText !== void 0 ? prefixText : "Column";
|
|
1642
|
+
for (let i = startColumn; i <= endColumn; i++) header.push(convertCellDataToString(worksheet === null || worksheet === void 0 ? void 0 : worksheet.getCell(startRow, i)) || getColumnName(i - startColumn + 1, columnText));
|
|
1643
|
+
return header;
|
|
1644
|
+
}
|
|
1645
|
+
/**
|
|
1646
|
+
* Add a table to univer.
|
|
1647
|
+
* @param {string} unitId The unit id of the table.
|
|
1648
|
+
* @param {string} subUnitId The subunit id of the table.
|
|
1649
|
+
* @param {string} name The table name, it should be unique in the unit or it will be appended with a number.
|
|
1650
|
+
* @param {ITableRange} range The range of the table, it contains the unit id and subunit id.
|
|
1651
|
+
* @param {string[]} [header] The header of the table, if not provided, it will be generated based on the range.
|
|
1652
|
+
* @param {string} [initId] The initial id of the table, if not provided, a random id will be generated.
|
|
1653
|
+
* @param {ITableOptions} [options] Other options of the table.
|
|
1654
|
+
* @returns {string} The table id.
|
|
1655
|
+
*/
|
|
1656
|
+
addTable(unitId, subUnitId, name, range, header, initId, options) {
|
|
1657
|
+
const id = initId !== null && initId !== void 0 ? initId : generateRandomId();
|
|
1658
|
+
const table = new Table(id, name, range, header || this.getColumnHeader(unitId, subUnitId, range), options);
|
|
1659
|
+
table.setSubunitId(subUnitId);
|
|
1660
|
+
this._ensureUnit(unitId).set(id, table);
|
|
1661
|
+
this._tableAdd$.next({
|
|
1662
|
+
unitId,
|
|
1663
|
+
subUnitId,
|
|
1664
|
+
range,
|
|
1665
|
+
tableName: name,
|
|
1666
|
+
tableId: id,
|
|
1667
|
+
tableStyleId: options === null || options === void 0 ? void 0 : options.tableStyleId
|
|
1668
|
+
});
|
|
1669
|
+
if (options === null || options === void 0 ? void 0 : options.filters) {
|
|
1670
|
+
var _this$_univerInstance2;
|
|
1671
|
+
const worksheet = (_this$_univerInstance2 = this._univerInstanceService.getUnit(unitId)) === null || _this$_univerInstance2 === void 0 ? void 0 : _this$_univerInstance2.getSheetBySheetId(subUnitId);
|
|
1672
|
+
table.getTableFilters().doFilter(worksheet, range);
|
|
1673
|
+
this._tableFilterChanged$.next({
|
|
1674
|
+
unitId,
|
|
1675
|
+
subUnitId,
|
|
1676
|
+
tableId: id
|
|
1677
|
+
});
|
|
1678
|
+
}
|
|
1679
|
+
return id;
|
|
1680
|
+
}
|
|
1681
|
+
addFilter(unitId, tableId, column, filter) {
|
|
1682
|
+
const table = this.getTable(unitId, tableId);
|
|
1683
|
+
if (table) {
|
|
1684
|
+
table.getTableFilters().setColumnFilter(column, filter);
|
|
1685
|
+
const subUnitId = table.getSubunitId();
|
|
1686
|
+
this._tableFilterChanged$.next({
|
|
1687
|
+
unitId,
|
|
1688
|
+
subUnitId,
|
|
1689
|
+
tableId
|
|
1690
|
+
});
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
getFilterRanges(unitId, subUnitId) {
|
|
1694
|
+
const unitMap = this._tableMap.get(unitId);
|
|
1695
|
+
if (!unitMap) return [];
|
|
1696
|
+
const filterRanges = [];
|
|
1697
|
+
unitMap.forEach((table) => {
|
|
1698
|
+
if (table.getSubunitId() === subUnitId && table.isShowHeader()) filterRanges.push(table.getRange());
|
|
1699
|
+
});
|
|
1700
|
+
return filterRanges;
|
|
1701
|
+
}
|
|
1702
|
+
getSheetFilterRangeWithState(unitId, subUnitId) {
|
|
1703
|
+
const unitMap = this._tableMap.get(unitId);
|
|
1704
|
+
if (!unitMap) return [];
|
|
1705
|
+
const filterRanges = [];
|
|
1706
|
+
unitMap.forEach((table) => {
|
|
1707
|
+
if (table.getSubunitId() === subUnitId && table.isShowHeader()) filterRanges.push({
|
|
1708
|
+
tableId: table.getId(),
|
|
1709
|
+
range: table.getRange(),
|
|
1710
|
+
states: table.getFilterStates(table.getRange())
|
|
1711
|
+
});
|
|
1712
|
+
});
|
|
1713
|
+
return filterRanges;
|
|
1714
|
+
}
|
|
1715
|
+
getTable(unitId, tableId) {
|
|
1716
|
+
const unitMap = this._tableMap.get(unitId);
|
|
1717
|
+
if (!unitMap) return;
|
|
1718
|
+
return unitMap.get(tableId);
|
|
1719
|
+
}
|
|
1720
|
+
/**
|
|
1721
|
+
* Get the unique table name, in excel, the table name should be unique because it is used as a reference.
|
|
1722
|
+
* @param {string} unitId The unit id of the table.
|
|
1723
|
+
* @param {string} baseName The base name of the table.
|
|
1724
|
+
* @returns {string} The unique table name
|
|
1725
|
+
*/
|
|
1726
|
+
getUniqueTableName(unitId, baseName) {
|
|
1727
|
+
const unitMap = this._tableMap.get(unitId);
|
|
1728
|
+
if (!unitMap) return baseName;
|
|
1729
|
+
const tableNamesSet = new Set(Array.from(unitMap.values()).map((table) => table.getDisplayName()));
|
|
1730
|
+
let newName = baseName;
|
|
1731
|
+
let count = 1;
|
|
1732
|
+
while (tableNamesSet.has(newName)) {
|
|
1733
|
+
newName = `${baseName}-${count}`;
|
|
1734
|
+
count++;
|
|
1735
|
+
}
|
|
1736
|
+
return newName;
|
|
1737
|
+
}
|
|
1738
|
+
/**
|
|
1739
|
+
* Get table by unit id and table id.
|
|
1740
|
+
* @param {string} unitId The unit id of the table.
|
|
1741
|
+
* @param {string} tableId The table id.
|
|
1742
|
+
* @returns {Table} The table.
|
|
1743
|
+
*/
|
|
1744
|
+
getTableById(unitId, tableId) {
|
|
1745
|
+
return this.getTable(unitId, tableId);
|
|
1746
|
+
}
|
|
1747
|
+
getTableList(unitId) {
|
|
1748
|
+
const unitMap = this._tableMap.get(unitId);
|
|
1749
|
+
if (!unitMap) return [];
|
|
1750
|
+
return Array.from(unitMap.values()).map((table) => {
|
|
1751
|
+
return {
|
|
1752
|
+
...table.getTableInfo(),
|
|
1753
|
+
unitId
|
|
1754
|
+
};
|
|
1755
|
+
});
|
|
1756
|
+
}
|
|
1757
|
+
/**
|
|
1758
|
+
* Get the table list by unit id and subunit id.
|
|
1759
|
+
* @param {string} unitId The unit id of the table.
|
|
1760
|
+
* @param {string} subUnitId The subunit id of the table.
|
|
1761
|
+
* @returns {Table[]} The table list.
|
|
1762
|
+
*/
|
|
1763
|
+
getTablesBySubunitId(unitId, subUnitId) {
|
|
1764
|
+
const unitMap = this._tableMap.get(unitId);
|
|
1765
|
+
if (!unitMap) return [];
|
|
1766
|
+
return Array.from(unitMap.values()).filter((table) => table.getSubunitId() === subUnitId);
|
|
1767
|
+
}
|
|
1768
|
+
getTablesInfoBySubunitId(unitId, subUnitId) {
|
|
1769
|
+
return this.getTablesBySubunitId(unitId, subUnitId).map((table) => {
|
|
1770
|
+
return {
|
|
1771
|
+
id: table.getId(),
|
|
1772
|
+
name: table.getDisplayName(),
|
|
1773
|
+
range: table.getRange()
|
|
1774
|
+
};
|
|
1775
|
+
});
|
|
1776
|
+
}
|
|
1777
|
+
deleteTable(unitId, tableId) {
|
|
1778
|
+
const unitMap = this._tableMap.get(unitId);
|
|
1779
|
+
const table = unitMap === null || unitMap === void 0 ? void 0 : unitMap.get(tableId);
|
|
1780
|
+
if (table) {
|
|
1781
|
+
const tableInfo = table.getTableInfo();
|
|
1782
|
+
const tableStyleId = table.getTableStyleId();
|
|
1783
|
+
unitMap === null || unitMap === void 0 || unitMap.delete(tableId);
|
|
1784
|
+
const { subUnitId, range, name } = tableInfo;
|
|
1785
|
+
this._tableDelete$.next({
|
|
1786
|
+
unitId,
|
|
1787
|
+
subUnitId,
|
|
1788
|
+
tableId,
|
|
1789
|
+
range,
|
|
1790
|
+
tableName: name,
|
|
1791
|
+
tableStyleId
|
|
1792
|
+
});
|
|
1793
|
+
}
|
|
1794
|
+
}
|
|
1795
|
+
operationTableRowCol(unitId, tableId, config) {
|
|
1796
|
+
const table = this.getTableById(unitId, tableId);
|
|
1797
|
+
if (!table) return;
|
|
1798
|
+
const { operationType, rowColType, index, count, columnsJson } = config;
|
|
1799
|
+
const oldRange = table.getRange();
|
|
1800
|
+
const newRange = { ...oldRange };
|
|
1801
|
+
if (operationType === IRangeOperationTypeEnum.Insert) {
|
|
1802
|
+
if (rowColType === "row") newRange.endRow += count;
|
|
1803
|
+
else if (rowColType === "column") {
|
|
1804
|
+
newRange.endColumn += count;
|
|
1805
|
+
for (let i = 0; i < count; i++) {
|
|
1806
|
+
const columnPrefix = this._localeService.t("sheets-table.columnPrefix");
|
|
1807
|
+
const column = new TableColumn(generateRandomId(), getColumnName(table.getColumnsCount() + 1 + i, columnPrefix));
|
|
1808
|
+
if (columnsJson === null || columnsJson === void 0 ? void 0 : columnsJson[i]) column.fromJSON(columnsJson[i]);
|
|
1809
|
+
const columnIndex = index + i - oldRange.startColumn;
|
|
1810
|
+
table.insertColumn(columnIndex, column);
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
} else if (rowColType === "row") newRange.endRow -= count;
|
|
1814
|
+
else if (rowColType === "column") {
|
|
1815
|
+
newRange.endColumn -= count;
|
|
1816
|
+
for (let i = count - 1; i >= 0; i--) {
|
|
1817
|
+
const columnIndex = index + i - oldRange.startColumn;
|
|
1818
|
+
table.removeColumn(columnIndex);
|
|
1819
|
+
}
|
|
1820
|
+
}
|
|
1821
|
+
table.setRange(newRange);
|
|
1822
|
+
this._tableRangeChanged$.next({
|
|
1823
|
+
unitId,
|
|
1824
|
+
subUnitId: table.getSubunitId(),
|
|
1825
|
+
tableId,
|
|
1826
|
+
range: newRange,
|
|
1827
|
+
oldRange
|
|
1828
|
+
});
|
|
1829
|
+
}
|
|
1830
|
+
updateTableRange(unitId, tableId, config) {
|
|
1831
|
+
const table = this.getTableById(unitId, tableId);
|
|
1832
|
+
if (!table) return;
|
|
1833
|
+
const oldRange = table.getRange();
|
|
1834
|
+
const newRange = config.newRange;
|
|
1835
|
+
if (newRange.startColumn < oldRange.startColumn) {
|
|
1836
|
+
const diff = oldRange.startColumn - newRange.startColumn;
|
|
1837
|
+
const columnPrefix = this._localeService.t("sheets-table.columnPrefix");
|
|
1838
|
+
for (let i = 0; i < diff; i++) table.insertColumn(oldRange.startColumn, new TableColumn(generateRandomId(), getColumnName(table.getColumnsCount() + 1, columnPrefix)));
|
|
1839
|
+
} else if (newRange.startColumn > oldRange.startColumn) {
|
|
1840
|
+
const diff = newRange.startColumn - oldRange.startColumn;
|
|
1841
|
+
for (let i = diff - 1; i >= 0; i--) {
|
|
1842
|
+
const columnIndex = newRange.startColumn + i - oldRange.startColumn;
|
|
1843
|
+
table.removeColumn(columnIndex);
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
if (newRange.endColumn < oldRange.endColumn) {
|
|
1847
|
+
const diff = oldRange.endColumn - newRange.endColumn;
|
|
1848
|
+
for (let i = diff - 1; i >= 0; i--) {
|
|
1849
|
+
const columnIndex = newRange.endColumn + i - oldRange.startColumn;
|
|
1850
|
+
table.removeColumn(columnIndex);
|
|
1851
|
+
}
|
|
1852
|
+
} else if (newRange.endColumn > oldRange.endColumn) {
|
|
1853
|
+
const diff = newRange.endColumn - oldRange.endColumn;
|
|
1854
|
+
for (let i = 0; i < diff; i++) table.insertColumn(oldRange.endColumn, new TableColumn(generateRandomId(), getColumnName(table.getColumnsCount() + 1, "Column")));
|
|
1855
|
+
}
|
|
1856
|
+
table.setRange(newRange);
|
|
1857
|
+
this._tableRangeChanged$.next({
|
|
1858
|
+
unitId,
|
|
1859
|
+
subUnitId: table.getSubunitId(),
|
|
1860
|
+
tableId,
|
|
1861
|
+
range: newRange,
|
|
1862
|
+
oldRange
|
|
1863
|
+
});
|
|
1864
|
+
}
|
|
1865
|
+
setTableByConfig(unitId, tableId, config) {
|
|
1866
|
+
const unitMap = this._tableMap.get(unitId);
|
|
1867
|
+
const table = unitMap === null || unitMap === void 0 ? void 0 : unitMap.get(tableId);
|
|
1868
|
+
if (!table) return;
|
|
1869
|
+
const subUnitId = table.getSubunitId();
|
|
1870
|
+
const { name, updateRange, rowColOperation, theme, options } = config;
|
|
1871
|
+
if (name) {
|
|
1872
|
+
const oldTableName = table.getDisplayName();
|
|
1873
|
+
table.setDisplayName(name);
|
|
1874
|
+
this._tableNameChanged$.next({
|
|
1875
|
+
unitId,
|
|
1876
|
+
subUnitId,
|
|
1877
|
+
tableId,
|
|
1878
|
+
tableName: name,
|
|
1879
|
+
oldTableName
|
|
1880
|
+
});
|
|
1881
|
+
}
|
|
1882
|
+
if (rowColOperation) this.operationTableRowCol(unitId, tableId, rowColOperation);
|
|
1883
|
+
if (updateRange) this.updateTableRange(unitId, tableId, updateRange);
|
|
1884
|
+
if (theme) {
|
|
1885
|
+
var _table$getTableStyleI;
|
|
1886
|
+
const oldTheme = (_table$getTableStyleI = table.getTableStyleId()) !== null && _table$getTableStyleI !== void 0 ? _table$getTableStyleI : "default";
|
|
1887
|
+
table.setTableStyleId(theme);
|
|
1888
|
+
this._tableThemeChanged$.next({
|
|
1889
|
+
unitId,
|
|
1890
|
+
subUnitId,
|
|
1891
|
+
tableId,
|
|
1892
|
+
theme,
|
|
1893
|
+
oldTheme
|
|
1894
|
+
});
|
|
1895
|
+
}
|
|
1896
|
+
if (options) {
|
|
1897
|
+
if (options.showHeader !== void 0) table.setShowHeader(options.showHeader);
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
toJSON(unitId) {
|
|
1901
|
+
const result = {};
|
|
1902
|
+
const unitMap = this._tableMap.get(unitId);
|
|
1903
|
+
if (unitMap) unitMap.forEach((table) => {
|
|
1904
|
+
const subUnitId = table.getSubunitId();
|
|
1905
|
+
if (!result[subUnitId]) {
|
|
1906
|
+
const tableFilteredOutRows = /* @__PURE__ */ new Set();
|
|
1907
|
+
this.getTablesBySubunitId(unitId, subUnitId).forEach((table) => {
|
|
1908
|
+
const tableFilteredRows = table.getTableFilters().getFilterOutRows();
|
|
1909
|
+
if (!tableFilteredRows) return;
|
|
1910
|
+
for (const row of tableFilteredRows) tableFilteredOutRows.add(row);
|
|
1911
|
+
});
|
|
1912
|
+
result[subUnitId] = {
|
|
1913
|
+
tables: [],
|
|
1914
|
+
tableFilteredOutRows: Array.from(tableFilteredOutRows)
|
|
1915
|
+
};
|
|
1916
|
+
}
|
|
1917
|
+
result[subUnitId].tables.push(table.toJSON());
|
|
1918
|
+
});
|
|
1919
|
+
return result;
|
|
1920
|
+
}
|
|
1921
|
+
fromJSON(unitId, data) {
|
|
1922
|
+
const unitMap = this._ensureUnit(unitId);
|
|
1923
|
+
Object.keys(data).forEach((subUnitId) => {
|
|
1924
|
+
const target = getSheetCommandTarget(this._univerInstanceService, {
|
|
1925
|
+
unitId,
|
|
1926
|
+
subUnitId
|
|
1927
|
+
});
|
|
1928
|
+
if (!target) return;
|
|
1929
|
+
const sheet = target.worksheet;
|
|
1930
|
+
let tables;
|
|
1931
|
+
if (data[subUnitId].tables) tables = data[subUnitId].tables;
|
|
1932
|
+
else if (Array.isArray(data[subUnitId])) tables = data[subUnitId];
|
|
1933
|
+
if (!tables) return;
|
|
1934
|
+
tables.forEach((table) => {
|
|
1935
|
+
const header = this.getColumnHeader(unitId, subUnitId, table.range);
|
|
1936
|
+
const tableInstance = new Table(table.id, table.name, table.range, header, table.options);
|
|
1937
|
+
tableInstance.setTableMeta(table.meta);
|
|
1938
|
+
if (table.columns.length) tableInstance.setColumns(table.columns);
|
|
1939
|
+
if (table.filters) {
|
|
1940
|
+
const tableFilter = tableInstance.getTableFilters();
|
|
1941
|
+
tableFilter.fromJSON(table.filters);
|
|
1942
|
+
tableFilter.doFilter(sheet, tableInstance.getTableFilterRange());
|
|
1943
|
+
}
|
|
1944
|
+
tableInstance.setSubunitId(subUnitId);
|
|
1945
|
+
unitMap.set(table.id, tableInstance);
|
|
1946
|
+
this._tableAdd$.next({
|
|
1947
|
+
unitId,
|
|
1948
|
+
subUnitId,
|
|
1949
|
+
range: table.range,
|
|
1950
|
+
tableName: table.name,
|
|
1951
|
+
tableId: table.id
|
|
1952
|
+
});
|
|
1953
|
+
});
|
|
1954
|
+
});
|
|
1955
|
+
this._tableInitStatus.next(true);
|
|
1956
|
+
}
|
|
1957
|
+
deleteUnitId(unitId) {
|
|
1958
|
+
const unitMap = this._tableMap.get(unitId);
|
|
1959
|
+
if (unitMap) unitMap.forEach((table) => table.dispose());
|
|
1960
|
+
this._tableMap.delete(unitId);
|
|
1961
|
+
}
|
|
1962
|
+
dispose() {
|
|
1963
|
+
super.dispose();
|
|
1964
|
+
this._tableAdd$.complete();
|
|
1965
|
+
this._tableDelete$.complete();
|
|
1966
|
+
this._tableNameChanged$.complete();
|
|
1967
|
+
this._tableRangeChanged$.complete();
|
|
1968
|
+
this._tableThemeChanged$.complete();
|
|
1969
|
+
this._tableFilterChanged$.complete();
|
|
1970
|
+
this._tableInitStatus.complete();
|
|
1971
|
+
this._tableMap.forEach((unitMap) => {
|
|
1972
|
+
unitMap.forEach((table) => table.dispose());
|
|
1973
|
+
unitMap.clear();
|
|
1974
|
+
});
|
|
1975
|
+
this._tableMap.clear();
|
|
1976
|
+
}
|
|
1977
|
+
};
|
|
1978
|
+
TableManager = __decorate([__decorateParam(0, IUniverInstanceService), __decorateParam(1, Inject(LocaleService))], TableManager);
|
|
1979
|
+
|
|
1980
|
+
//#endregion
|
|
1981
|
+
//#region src/services/table-service.ts
|
|
1982
|
+
let SheetTableService = class SheetTableService extends Disposable {
|
|
1983
|
+
constructor(_tableManager) {
|
|
1984
|
+
super();
|
|
1985
|
+
this._tableManager = _tableManager;
|
|
1986
|
+
}
|
|
1987
|
+
getTableInfo(unitId, tableId) {
|
|
1988
|
+
const table = this._tableManager.getTable(unitId, tableId);
|
|
1989
|
+
if (!table) return;
|
|
1990
|
+
return {
|
|
1991
|
+
unitId,
|
|
1992
|
+
...table.getTableInfo()
|
|
1993
|
+
};
|
|
1994
|
+
}
|
|
1995
|
+
getTableList(unitId) {
|
|
1996
|
+
return this._tableManager.getTableList(unitId);
|
|
1997
|
+
}
|
|
1998
|
+
addTable(unitId, subUnitId, tableName, rangeInfo, tableHeader, tableId, options) {
|
|
1999
|
+
return this._tableManager.addTable(unitId, subUnitId, tableName, rangeInfo, tableHeader, tableId, options);
|
|
2000
|
+
}
|
|
2001
|
+
deleteTable(unitId, subUnitId, tableId) {
|
|
2002
|
+
this._tableManager.deleteTable(unitId, tableId);
|
|
2003
|
+
}
|
|
2004
|
+
getTableMeta(unitId, tableId) {
|
|
2005
|
+
var _this$_tableManager$g;
|
|
2006
|
+
return (_this$_tableManager$g = this._tableManager.getTable(unitId, tableId)) === null || _this$_tableManager$g === void 0 ? void 0 : _this$_tableManager$g.getTableMeta();
|
|
2007
|
+
}
|
|
2008
|
+
setTableMeta(unitId, tableId, meta) {
|
|
2009
|
+
var _this$_tableManager$g2;
|
|
2010
|
+
(_this$_tableManager$g2 = this._tableManager.getTable(unitId, tableId)) === null || _this$_tableManager$g2 === void 0 || _this$_tableManager$g2.setTableMeta(meta);
|
|
2011
|
+
}
|
|
2012
|
+
getTableColumnMeta(unitId, tableId, index) {
|
|
2013
|
+
var _this$_tableManager$g3;
|
|
2014
|
+
return (_this$_tableManager$g3 = this._tableManager.getTable(unitId, tableId)) === null || _this$_tableManager$g3 === void 0 || (_this$_tableManager$g3 = _this$_tableManager$g3.getTableColumnByIndex(index)) === null || _this$_tableManager$g3 === void 0 ? void 0 : _this$_tableManager$g3.getMeta();
|
|
2015
|
+
}
|
|
2016
|
+
selTableColumnMeta(unitId, tableId, index, meta) {
|
|
2017
|
+
var _this$_tableManager$g4;
|
|
2018
|
+
(_this$_tableManager$g4 = this._tableManager.getTable(unitId, tableId)) === null || _this$_tableManager$g4 === void 0 || (_this$_tableManager$g4 = _this$_tableManager$g4.getTableColumnByIndex(index)) === null || _this$_tableManager$g4 === void 0 || _this$_tableManager$g4.setMeta(meta);
|
|
2019
|
+
}
|
|
2020
|
+
addFilter(unitId, tableId, column, filter) {
|
|
2021
|
+
this._tableManager.addFilter(unitId, tableId, column, filter);
|
|
2022
|
+
}
|
|
2023
|
+
getCellValueWithConditionType(sheet, row, col, conditionType = TableConditionTypeEnum.String) {
|
|
2024
|
+
return getCellValueWithConditionType(sheet, row, col, conditionType);
|
|
2025
|
+
}
|
|
2026
|
+
};
|
|
2027
|
+
SheetTableService = __decorate([__decorateParam(0, Inject(TableManager))], SheetTableService);
|
|
2028
|
+
|
|
2029
|
+
//#endregion
|
|
2030
|
+
//#region src/commands/mutations/add-sheet-table.mutation.ts
|
|
2031
|
+
const AddSheetTableMutation = {
|
|
2032
|
+
id: "sheet.mutation.add-table",
|
|
2033
|
+
type: CommandType.MUTATION,
|
|
2034
|
+
handler: (accessor, params) => {
|
|
2035
|
+
const { tableId, unitId, subUnitId, name, range, header, options } = params;
|
|
2036
|
+
accessor.get(SheetTableService).addTable(unitId, subUnitId, name, range, header, tableId, options);
|
|
2037
|
+
return true;
|
|
2038
|
+
}
|
|
2039
|
+
};
|
|
2040
|
+
|
|
2041
|
+
//#endregion
|
|
2042
|
+
//#region src/commands/mutations/delete-sheet-table.mutation.ts
|
|
2043
|
+
const DeleteSheetTableMutation = {
|
|
2044
|
+
id: "sheet.mutation.delete-table",
|
|
2045
|
+
type: CommandType.MUTATION,
|
|
2046
|
+
handler: (accessor, params) => {
|
|
2047
|
+
const { unitId, subUnitId, tableId } = params;
|
|
2048
|
+
accessor.get(SheetTableService).deleteTable(unitId, subUnitId, tableId);
|
|
2049
|
+
return true;
|
|
2050
|
+
}
|
|
2051
|
+
};
|
|
2052
|
+
|
|
2053
|
+
//#endregion
|
|
2054
|
+
//#region src/commands/commands/add-sheet-table.command.ts
|
|
2055
|
+
const AddSheetTableCommand = {
|
|
2056
|
+
id: "sheet.command.add-table",
|
|
2057
|
+
type: CommandType.COMMAND,
|
|
2058
|
+
handler: (accessor, params) => {
|
|
2059
|
+
var _params$id;
|
|
2060
|
+
if (!params) return false;
|
|
2061
|
+
const undoRedoService = accessor.get(IUndoRedoService);
|
|
2062
|
+
const commandService = accessor.get(ICommandService);
|
|
2063
|
+
const localeService = accessor.get(LocaleService);
|
|
2064
|
+
const tableManager = accessor.get(TableManager);
|
|
2065
|
+
const tableId = (_params$id = params.id) !== null && _params$id !== void 0 ? _params$id : generateRandomId();
|
|
2066
|
+
const existingNamesSet = getExistingNamesSet(params.unitId, {
|
|
2067
|
+
univerInstanceService: accessor.get(IUniverInstanceService),
|
|
2068
|
+
tableManager,
|
|
2069
|
+
definedNamesService: accessor.get(IDefinedNamesService)
|
|
2070
|
+
});
|
|
2071
|
+
let tableName = params.name;
|
|
2072
|
+
if (!tableName || !customNameCharacterCheck(tableName.toLowerCase(), existingNamesSet)) {
|
|
2073
|
+
const prefix = localeService.t("sheets-table.tablePrefix");
|
|
2074
|
+
let index = tableManager.getTableList(params.unitId).length + 1;
|
|
2075
|
+
for (const name of existingNamesSet) if (name.startsWith(prefix.toLowerCase())) {
|
|
2076
|
+
const n = Number(name.slice(prefix.length));
|
|
2077
|
+
if (Number.isInteger(n) && n >= index) index = n + 1;
|
|
2078
|
+
}
|
|
2079
|
+
tableName = `${prefix}${index}`;
|
|
2080
|
+
}
|
|
2081
|
+
const redos = [];
|
|
2082
|
+
const undos = [];
|
|
2083
|
+
const { unitId, subUnitId, range } = params;
|
|
2084
|
+
const header = tableManager.getColumnHeader(unitId, subUnitId, range, localeService.t("sheets-table.columnPrefix"));
|
|
2085
|
+
redos.push({
|
|
2086
|
+
id: AddSheetTableMutation.id,
|
|
2087
|
+
params: {
|
|
2088
|
+
...params,
|
|
2089
|
+
tableId,
|
|
2090
|
+
name: tableName,
|
|
2091
|
+
header
|
|
2092
|
+
}
|
|
2093
|
+
});
|
|
2094
|
+
undos.push({
|
|
2095
|
+
id: DeleteSheetTableMutation.id,
|
|
2096
|
+
params: {
|
|
2097
|
+
tableId,
|
|
2098
|
+
unitId: params.unitId
|
|
2099
|
+
}
|
|
2100
|
+
});
|
|
2101
|
+
if (sequenceExecute(redos, commandService)) undoRedoService.pushUndoRedo({
|
|
2102
|
+
unitID: params.unitId,
|
|
2103
|
+
undoMutations: undos,
|
|
2104
|
+
redoMutations: redos
|
|
2105
|
+
});
|
|
2106
|
+
return true;
|
|
2107
|
+
}
|
|
2108
|
+
};
|
|
2109
|
+
|
|
2110
|
+
//#endregion
|
|
2111
|
+
//#region src/commands/mutations/set-sheet-table.mutation.ts
|
|
2112
|
+
const SetSheetTableMutation = {
|
|
2113
|
+
id: "sheet.mutation.set-sheet-table",
|
|
2114
|
+
type: CommandType.MUTATION,
|
|
2115
|
+
handler: (accessor, params) => {
|
|
2116
|
+
if (!params) return false;
|
|
2117
|
+
const { unitId, tableId, config } = params;
|
|
2118
|
+
accessor.get(TableManager).setTableByConfig(unitId, tableId, config);
|
|
2119
|
+
return true;
|
|
2120
|
+
}
|
|
2121
|
+
};
|
|
2122
|
+
|
|
2123
|
+
//#endregion
|
|
2124
|
+
//#region src/commands/commands/add-table-theme.command.ts
|
|
2125
|
+
const AddTableThemeCommand = {
|
|
2126
|
+
id: "sheet.command.add-table-theme",
|
|
2127
|
+
type: CommandType.COMMAND,
|
|
2128
|
+
handler: (accessor, params) => {
|
|
2129
|
+
if (!params) return false;
|
|
2130
|
+
const tableManager = accessor.get(TableManager);
|
|
2131
|
+
const { unitId, tableId, themeStyle } = params;
|
|
2132
|
+
const redos = [];
|
|
2133
|
+
const undos = [];
|
|
2134
|
+
const table = tableManager.getTableById(unitId, tableId);
|
|
2135
|
+
if (!table) return false;
|
|
2136
|
+
const subUnitId = table.getSubunitId();
|
|
2137
|
+
redos.push({
|
|
2138
|
+
id: AddRangeThemeMutation.id,
|
|
2139
|
+
params: {
|
|
2140
|
+
unitId,
|
|
2141
|
+
subUnitId,
|
|
2142
|
+
styleJSON: themeStyle.toJson()
|
|
2143
|
+
}
|
|
2144
|
+
});
|
|
2145
|
+
redos.push({
|
|
2146
|
+
id: SetSheetTableMutation.id,
|
|
2147
|
+
params: {
|
|
2148
|
+
unitId,
|
|
2149
|
+
subUnitId,
|
|
2150
|
+
tableId,
|
|
2151
|
+
config: { theme: themeStyle.getName() }
|
|
2152
|
+
}
|
|
2153
|
+
});
|
|
2154
|
+
undos.push({
|
|
2155
|
+
id: SetSheetTableMutation.id,
|
|
2156
|
+
params: {
|
|
2157
|
+
unitId,
|
|
2158
|
+
subUnitId,
|
|
2159
|
+
tableId,
|
|
2160
|
+
config: { themeStyle: table.getTableStyleId() }
|
|
2161
|
+
}
|
|
2162
|
+
});
|
|
2163
|
+
undos.push({
|
|
2164
|
+
id: RemoveRangeThemeMutation.id,
|
|
2165
|
+
params: {
|
|
2166
|
+
unitId,
|
|
2167
|
+
subUnitId,
|
|
2168
|
+
styleName: themeStyle.getName()
|
|
2169
|
+
}
|
|
2170
|
+
});
|
|
2171
|
+
if (sequenceExecute(redos, accessor.get(ICommandService))) accessor.get(IUndoRedoService).pushUndoRedo({
|
|
2172
|
+
unitID: unitId,
|
|
2173
|
+
undoMutations: undos,
|
|
2174
|
+
redoMutations: redos
|
|
2175
|
+
});
|
|
2176
|
+
return true;
|
|
2177
|
+
}
|
|
2178
|
+
};
|
|
2179
|
+
|
|
2180
|
+
//#endregion
|
|
2181
|
+
//#region src/commands/commands/delete-sheet-table.command.ts
|
|
2182
|
+
const DeleteSheetTableCommand = {
|
|
2183
|
+
id: "sheet.command.delete-table",
|
|
2184
|
+
type: CommandType.COMMAND,
|
|
2185
|
+
handler: (accessor, params) => {
|
|
2186
|
+
if (!params) return false;
|
|
2187
|
+
const undoRedoService = accessor.get(IUndoRedoService);
|
|
2188
|
+
const commandService = accessor.get(ICommandService);
|
|
2189
|
+
const sheetTableManager = accessor.get(TableManager);
|
|
2190
|
+
const logService = accessor.get(ILogService);
|
|
2191
|
+
const redos = [];
|
|
2192
|
+
const undos = [];
|
|
2193
|
+
const tableInstance = sheetTableManager.getTable(params.unitId, params.tableId);
|
|
2194
|
+
const tableConfig = tableInstance === null || tableInstance === void 0 ? void 0 : tableInstance.toJSON();
|
|
2195
|
+
if (!tableConfig) {
|
|
2196
|
+
logService.error("[TableManager]: Table not found");
|
|
2197
|
+
return false;
|
|
2198
|
+
}
|
|
2199
|
+
redos.push({
|
|
2200
|
+
id: DeleteSheetTableMutation.id,
|
|
2201
|
+
params: { ...params }
|
|
2202
|
+
});
|
|
2203
|
+
undos.push({
|
|
2204
|
+
id: AddSheetTableMutation.id,
|
|
2205
|
+
params: {
|
|
2206
|
+
unitId: params.unitId,
|
|
2207
|
+
subUnitId: params.subUnitId,
|
|
2208
|
+
tableId: params.tableId,
|
|
2209
|
+
name: tableConfig.name,
|
|
2210
|
+
range: tableConfig.range,
|
|
2211
|
+
options: tableConfig.options
|
|
2212
|
+
}
|
|
2213
|
+
});
|
|
2214
|
+
if (sequenceExecute(redos, commandService)) undoRedoService.pushUndoRedo({
|
|
2215
|
+
unitID: params.unitId,
|
|
2216
|
+
undoMutations: undos,
|
|
2217
|
+
redoMutations: redos
|
|
2218
|
+
});
|
|
2219
|
+
return true;
|
|
2220
|
+
}
|
|
2221
|
+
};
|
|
2222
|
+
|
|
2223
|
+
//#endregion
|
|
2224
|
+
//#region src/const.ts
|
|
2225
|
+
/**
|
|
2226
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
2227
|
+
*
|
|
2228
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2229
|
+
* you may not use this file except in compliance with the License.
|
|
2230
|
+
* You may obtain a copy of the License at
|
|
2231
|
+
*
|
|
2232
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2233
|
+
*
|
|
2234
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
2235
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2236
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2237
|
+
* See the License for the specific language governing permissions and
|
|
2238
|
+
* limitations under the License.
|
|
2239
|
+
*/
|
|
2240
|
+
const PLUGIN_NAME = "SHEET_TABLE_PLUGIN";
|
|
2241
|
+
const FEATURE_TABLE_ID = "SHEET_TABLE";
|
|
2242
|
+
const SHEET_TABLE_CUSTOM_THEME_PREFIX = "table-custom";
|
|
2243
|
+
|
|
2244
|
+
//#endregion
|
|
2245
|
+
//#region src/commands/commands/remove-table-theme.command.ts
|
|
2246
|
+
const RemoveTableThemeCommand = {
|
|
2247
|
+
id: "sheet.command.remove-table-theme",
|
|
2248
|
+
type: CommandType.COMMAND,
|
|
2249
|
+
handler: (accessor, params) => {
|
|
2250
|
+
if (!params) return false;
|
|
2251
|
+
const { unitId, tableId, themeName } = params;
|
|
2252
|
+
const tableManager = accessor.get(TableManager);
|
|
2253
|
+
const rangeThemeModel = accessor.get(SheetRangeThemeModel);
|
|
2254
|
+
const table = tableManager.getTableById(unitId, tableId);
|
|
2255
|
+
if (!table) return false;
|
|
2256
|
+
const subUnitId = table.getSubunitId();
|
|
2257
|
+
const redos = [];
|
|
2258
|
+
const undos = [];
|
|
2259
|
+
const defaultRangeThemes = rangeThemeModel.getRegisteredRangeThemes().filter((item) => item === null || item === void 0 ? void 0 : item.startsWith("table-default"));
|
|
2260
|
+
let shouldBeSelectedTheme = rangeThemeModel.getRegisteredRangeThemes().filter((item) => item === null || item === void 0 ? void 0 : item.startsWith(SHEET_TABLE_CUSTOM_THEME_PREFIX)).find((item) => item !== themeName);
|
|
2261
|
+
if (!shouldBeSelectedTheme) shouldBeSelectedTheme = defaultRangeThemes[0];
|
|
2262
|
+
redos.push({
|
|
2263
|
+
id: SetSheetTableMutation.id,
|
|
2264
|
+
params: {
|
|
2265
|
+
unitId,
|
|
2266
|
+
subUnitId,
|
|
2267
|
+
tableId,
|
|
2268
|
+
config: { theme: shouldBeSelectedTheme }
|
|
2269
|
+
}
|
|
2270
|
+
});
|
|
2271
|
+
redos.push({
|
|
2272
|
+
id: RemoveRangeThemeMutation.id,
|
|
2273
|
+
params: {
|
|
2274
|
+
unitId,
|
|
2275
|
+
subUnitId,
|
|
2276
|
+
styleName: themeName
|
|
2277
|
+
}
|
|
2278
|
+
});
|
|
2279
|
+
const themeStyle = rangeThemeModel.getDefaultRangeThemeStyle(themeName);
|
|
2280
|
+
if (themeStyle) {
|
|
2281
|
+
undos.push({
|
|
2282
|
+
id: AddRangeThemeMutation.id,
|
|
2283
|
+
params: {
|
|
2284
|
+
unitId,
|
|
2285
|
+
subUnitId,
|
|
2286
|
+
styleJSON: themeStyle.toJson()
|
|
2287
|
+
}
|
|
2288
|
+
});
|
|
2289
|
+
undos.push({
|
|
2290
|
+
id: SetSheetTableMutation.id,
|
|
2291
|
+
params: {
|
|
2292
|
+
unitId,
|
|
2293
|
+
subUnitId,
|
|
2294
|
+
tableId,
|
|
2295
|
+
config: { theme: themeName }
|
|
2296
|
+
}
|
|
2297
|
+
});
|
|
2298
|
+
}
|
|
2299
|
+
if (sequenceExecute(redos, accessor.get(ICommandService))) accessor.get(IUndoRedoService).pushUndoRedo({
|
|
2300
|
+
unitID: unitId,
|
|
2301
|
+
redoMutations: redos,
|
|
2302
|
+
undoMutations: undos
|
|
2303
|
+
});
|
|
2304
|
+
return true;
|
|
2305
|
+
}
|
|
2306
|
+
};
|
|
2307
|
+
|
|
2308
|
+
//#endregion
|
|
2309
|
+
//#region src/commands/commands/set-sheet-table.command.ts
|
|
2310
|
+
const SetSheetTableCommand = {
|
|
2311
|
+
id: "sheet.command.set-table-config",
|
|
2312
|
+
type: CommandType.COMMAND,
|
|
2313
|
+
handler: (accessor, params) => {
|
|
2314
|
+
if (!params) return false;
|
|
2315
|
+
const { unitId, tableId, name, updateRange, rowColOperation, theme } = params;
|
|
2316
|
+
const tableManager = accessor.get(TableManager);
|
|
2317
|
+
const table = tableManager.getTableById(unitId, tableId);
|
|
2318
|
+
if (!table) return false;
|
|
2319
|
+
const oldTableConfig = {};
|
|
2320
|
+
const newTableConfig = {};
|
|
2321
|
+
const localeService = accessor.get(LocaleService);
|
|
2322
|
+
const existingNamesSet = getExistingNamesSet(unitId, {
|
|
2323
|
+
univerInstanceService: accessor.get(IUniverInstanceService),
|
|
2324
|
+
tableManager,
|
|
2325
|
+
definedNamesService: accessor.get(IDefinedNamesService)
|
|
2326
|
+
});
|
|
2327
|
+
if (name) {
|
|
2328
|
+
if (!customNameCharacterCheck(name.toLowerCase(), existingNamesSet)) {
|
|
2329
|
+
accessor.get(ILogService).warn(localeService.t("sheets-table.tableNameError"));
|
|
2330
|
+
return false;
|
|
2331
|
+
}
|
|
2332
|
+
oldTableConfig.name = table.getDisplayName();
|
|
2333
|
+
newTableConfig.name = name;
|
|
2334
|
+
}
|
|
2335
|
+
if (rowColOperation) {
|
|
2336
|
+
oldTableConfig.rowColOperation = {
|
|
2337
|
+
operationType: rowColOperation.operationType === IRangeOperationTypeEnum.Insert ? IRangeOperationTypeEnum.Delete : IRangeOperationTypeEnum.Insert,
|
|
2338
|
+
rowColType: rowColOperation.rowColType,
|
|
2339
|
+
index: rowColOperation.index,
|
|
2340
|
+
count: rowColOperation.count
|
|
2341
|
+
};
|
|
2342
|
+
newTableConfig.rowColOperation = rowColOperation;
|
|
2343
|
+
}
|
|
2344
|
+
if (updateRange) {
|
|
2345
|
+
oldTableConfig.updateRange = { newRange: table.getRange() };
|
|
2346
|
+
newTableConfig.updateRange = updateRange;
|
|
2347
|
+
}
|
|
2348
|
+
if (theme) {
|
|
2349
|
+
oldTableConfig.theme = table.getTableStyleId();
|
|
2350
|
+
newTableConfig.theme = theme;
|
|
2351
|
+
}
|
|
2352
|
+
const redoParams = {
|
|
2353
|
+
unitId,
|
|
2354
|
+
subUnitId: table.getSubunitId(),
|
|
2355
|
+
tableId,
|
|
2356
|
+
config: newTableConfig
|
|
2357
|
+
};
|
|
2358
|
+
accessor.get(ICommandService).executeCommand(SetSheetTableMutation.id, redoParams);
|
|
2359
|
+
accessor.get(IUndoRedoService).pushUndoRedo({
|
|
2360
|
+
unitID: unitId,
|
|
2361
|
+
undoMutations: [{
|
|
2362
|
+
id: SetSheetTableMutation.id,
|
|
2363
|
+
params: {
|
|
2364
|
+
unitId,
|
|
2365
|
+
subUnitId: table.getSubunitId(),
|
|
2366
|
+
tableId,
|
|
2367
|
+
config: oldTableConfig
|
|
2368
|
+
}
|
|
2369
|
+
}],
|
|
2370
|
+
redoMutations: [{
|
|
2371
|
+
id: SetSheetTableMutation.id,
|
|
2372
|
+
params: redoParams
|
|
2373
|
+
}]
|
|
2374
|
+
});
|
|
2375
|
+
return true;
|
|
2376
|
+
}
|
|
2377
|
+
};
|
|
2378
|
+
|
|
2379
|
+
//#endregion
|
|
2380
|
+
//#region src/commands/mutations/set-table-filter.mutation.ts
|
|
2381
|
+
const SetSheetTableFilterMutation = {
|
|
2382
|
+
id: "sheet.mutation.set-table-filter",
|
|
2383
|
+
type: CommandType.MUTATION,
|
|
2384
|
+
handler: (accessor, params) => {
|
|
2385
|
+
const { tableId, unitId, column, tableFilter } = params;
|
|
2386
|
+
accessor.get(TableManager).addFilter(unitId, tableId, column, tableFilter);
|
|
2387
|
+
return true;
|
|
2388
|
+
}
|
|
2389
|
+
};
|
|
2390
|
+
|
|
2391
|
+
//#endregion
|
|
2392
|
+
//#region src/commands/commands/set-table-filter.command.ts
|
|
2393
|
+
const SetSheetTableFilterCommand = {
|
|
2394
|
+
id: "sheet.command.set-table-filter",
|
|
2395
|
+
type: CommandType.COMMAND,
|
|
2396
|
+
handler: (accessor, params) => {
|
|
2397
|
+
if (!params) return false;
|
|
2398
|
+
const undoRedoService = accessor.get(IUndoRedoService);
|
|
2399
|
+
const commandService = accessor.get(ICommandService);
|
|
2400
|
+
const tableId = params.tableId || generateRandomId();
|
|
2401
|
+
const redos = [];
|
|
2402
|
+
const undos = [];
|
|
2403
|
+
redos.push({
|
|
2404
|
+
id: SetSheetTableFilterMutation.id,
|
|
2405
|
+
params: {
|
|
2406
|
+
...params,
|
|
2407
|
+
tableId
|
|
2408
|
+
}
|
|
2409
|
+
});
|
|
2410
|
+
undos.push({
|
|
2411
|
+
id: SetSheetTableFilterMutation.id,
|
|
2412
|
+
params: {
|
|
2413
|
+
...params,
|
|
2414
|
+
tableId,
|
|
2415
|
+
tableFilter: void 0
|
|
2416
|
+
}
|
|
2417
|
+
});
|
|
2418
|
+
if (sequenceExecute(redos, commandService)) undoRedoService.pushUndoRedo({
|
|
2419
|
+
unitID: params.unitId,
|
|
2420
|
+
undoMutations: undos,
|
|
2421
|
+
redoMutations: redos
|
|
2422
|
+
});
|
|
2423
|
+
return true;
|
|
2424
|
+
}
|
|
2425
|
+
};
|
|
2426
|
+
|
|
2427
|
+
//#endregion
|
|
2428
|
+
//#region src/controllers/sheets-table.controller.ts
|
|
2429
|
+
let SheetsTableController = class SheetsTableController extends Disposable {
|
|
2430
|
+
constructor(_univerInstanceService, _sheetInterceptorService, _tableManager, _resourceManagerService) {
|
|
2431
|
+
super();
|
|
2432
|
+
this._univerInstanceService = _univerInstanceService;
|
|
2433
|
+
this._sheetInterceptorService = _sheetInterceptorService;
|
|
2434
|
+
this._tableManager = _tableManager;
|
|
2435
|
+
this._resourceManagerService = _resourceManagerService;
|
|
2436
|
+
_defineProperty(this, "_tableRangeRTree", /* @__PURE__ */ new Map());
|
|
2437
|
+
this._initSnapshot();
|
|
2438
|
+
this._initSheetChange();
|
|
2439
|
+
this.registerTableChangeEvent();
|
|
2440
|
+
this.registerTableHeaderInterceptor();
|
|
2441
|
+
}
|
|
2442
|
+
getContainerTableWithRange(unitId, subUnitId, range) {
|
|
2443
|
+
const rTree = this._ensureTableRangeRTree(unitId);
|
|
2444
|
+
const wrapperTableId = Array.from(rTree.bulkSearch([{
|
|
2445
|
+
unitId,
|
|
2446
|
+
sheetId: subUnitId,
|
|
2447
|
+
range
|
|
2448
|
+
}])).find((id) => {
|
|
2449
|
+
const table = this._tableManager.getTable(unitId, String(id));
|
|
2450
|
+
if (table) return Rectangle.contains(table.getRange(), range);
|
|
2451
|
+
return false;
|
|
2452
|
+
});
|
|
2453
|
+
if (wrapperTableId) return this._tableManager.getTable(unitId, String(wrapperTableId));
|
|
2454
|
+
}
|
|
2455
|
+
_ensureTableRangeRTree(unitId) {
|
|
2456
|
+
if (!this._tableRangeRTree.has(unitId)) this._tableRangeRTree.set(unitId, new RTree());
|
|
2457
|
+
return this._tableRangeRTree.get(unitId);
|
|
2458
|
+
}
|
|
2459
|
+
registerTableChangeEvent() {
|
|
2460
|
+
this.disposeWithMe(this._tableManager.tableAdd$.subscribe((event) => {
|
|
2461
|
+
const { range, tableId, unitId, subUnitId } = event;
|
|
2462
|
+
this._ensureTableRangeRTree(unitId).insert({
|
|
2463
|
+
unitId,
|
|
2464
|
+
sheetId: subUnitId,
|
|
2465
|
+
id: tableId,
|
|
2466
|
+
range: { ...range }
|
|
2467
|
+
});
|
|
2468
|
+
}));
|
|
2469
|
+
this.disposeWithMe(this._tableManager.tableRangeChanged$.subscribe((event) => {
|
|
2470
|
+
const { range, tableId, unitId, subUnitId, oldRange } = event;
|
|
2471
|
+
const rTree = this._ensureTableRangeRTree(unitId);
|
|
2472
|
+
rTree.remove({
|
|
2473
|
+
unitId,
|
|
2474
|
+
sheetId: subUnitId,
|
|
2475
|
+
id: tableId,
|
|
2476
|
+
range: { ...oldRange }
|
|
2477
|
+
});
|
|
2478
|
+
rTree.insert({
|
|
2479
|
+
unitId,
|
|
2480
|
+
sheetId: subUnitId,
|
|
2481
|
+
id: tableId,
|
|
2482
|
+
range: { ...range }
|
|
2483
|
+
});
|
|
2484
|
+
}));
|
|
2485
|
+
this.disposeWithMe(this._tableManager.tableDelete$.subscribe((event) => {
|
|
2486
|
+
const { tableId, unitId, subUnitId, range } = event;
|
|
2487
|
+
this._ensureTableRangeRTree(unitId).remove({
|
|
2488
|
+
unitId,
|
|
2489
|
+
sheetId: subUnitId,
|
|
2490
|
+
id: tableId,
|
|
2491
|
+
range: { ...range }
|
|
2492
|
+
});
|
|
2493
|
+
}));
|
|
2494
|
+
}
|
|
2495
|
+
registerTableHeaderInterceptor() {
|
|
2496
|
+
this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
|
|
2497
|
+
effect: InterceptorEffectEnum.Value,
|
|
2498
|
+
handler: (cell, context, next) => {
|
|
2499
|
+
const { row, col, unitId, subUnitId } = context;
|
|
2500
|
+
const rTree = this._ensureTableRangeRTree(unitId);
|
|
2501
|
+
if ((cell === null || cell === void 0 ? void 0 : cell.v) === void 0 && rTree) {
|
|
2502
|
+
const ids = Array.from(rTree.bulkSearch([{
|
|
2503
|
+
unitId,
|
|
2504
|
+
sheetId: subUnitId,
|
|
2505
|
+
range: {
|
|
2506
|
+
startColumn: col,
|
|
2507
|
+
endColumn: col,
|
|
2508
|
+
startRow: row,
|
|
2509
|
+
endRow: row
|
|
2510
|
+
}
|
|
2511
|
+
}]));
|
|
2512
|
+
if (ids.length > 0) {
|
|
2513
|
+
const table = this._tableManager.getTable(unitId, ids[0]);
|
|
2514
|
+
if (table) {
|
|
2515
|
+
const tableRange = table.getRange();
|
|
2516
|
+
const index = col - tableRange.startColumn;
|
|
2517
|
+
if (tableRange.startRow === row) {
|
|
2518
|
+
const columnName = table.getColumnNameByIndex(index);
|
|
2519
|
+
if (!cell || cell === context.rawData) cell = { ...context.rawData };
|
|
2520
|
+
cell.v = columnName;
|
|
2521
|
+
return next(cell);
|
|
2522
|
+
}
|
|
2523
|
+
}
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
2526
|
+
return next(cell);
|
|
2527
|
+
}
|
|
2528
|
+
}));
|
|
2529
|
+
}
|
|
2530
|
+
_toJson(unitId) {
|
|
2531
|
+
return this._tableManager.toJSON(unitId);
|
|
2532
|
+
}
|
|
2533
|
+
_fromJSON(unitId, resources) {
|
|
2534
|
+
return this._tableManager.fromJSON(unitId, resources);
|
|
2535
|
+
}
|
|
2536
|
+
_deleteUnitId(unitId) {
|
|
2537
|
+
this._tableManager.deleteUnitId(unitId);
|
|
2538
|
+
}
|
|
2539
|
+
_initSnapshot() {
|
|
2540
|
+
this.disposeWithMe(this._resourceManagerService.registerPluginResource({
|
|
2541
|
+
toJson: (unitId) => {
|
|
2542
|
+
return JSON.stringify(this._toJson(unitId));
|
|
2543
|
+
},
|
|
2544
|
+
parseJson: (json) => {
|
|
2545
|
+
if (!json) return {};
|
|
2546
|
+
try {
|
|
2547
|
+
return JSON.parse(json);
|
|
2548
|
+
} catch (error) {
|
|
2549
|
+
return {};
|
|
2550
|
+
}
|
|
2551
|
+
},
|
|
2552
|
+
businesses: [UniverInstanceType.UNIVER_SHEET],
|
|
2553
|
+
pluginName: PLUGIN_NAME,
|
|
2554
|
+
onLoad: (unitId, resources) => {
|
|
2555
|
+
this._fromJSON(unitId, resources);
|
|
2556
|
+
},
|
|
2557
|
+
onUnLoad: (unitId) => {
|
|
2558
|
+
this._deleteUnitId(unitId);
|
|
2559
|
+
}
|
|
2560
|
+
}));
|
|
2561
|
+
}
|
|
2562
|
+
_initSheetChange() {
|
|
2563
|
+
this.disposeWithMe(this._sheetInterceptorService.interceptCommand({ getMutations: (commandInfo) => {
|
|
2564
|
+
if (commandInfo.id === RemoveSheetCommand.id) {
|
|
2565
|
+
var _getActiveSheet;
|
|
2566
|
+
const params = commandInfo.params;
|
|
2567
|
+
const unitId = params.unitId || this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET).getUnitId();
|
|
2568
|
+
const subUnitId = params.subUnitId || ((_getActiveSheet = this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET).getActiveSheet()) === null || _getActiveSheet === void 0 ? void 0 : _getActiveSheet.getSheetId());
|
|
2569
|
+
if (!unitId || !subUnitId) return {
|
|
2570
|
+
redos: [],
|
|
2571
|
+
undos: []
|
|
2572
|
+
};
|
|
2573
|
+
const tables = this._tableManager.getTablesBySubunitId(unitId, subUnitId);
|
|
2574
|
+
if (tables.length === 0) return {
|
|
2575
|
+
redos: [],
|
|
2576
|
+
undos: []
|
|
2577
|
+
};
|
|
2578
|
+
const redos = [];
|
|
2579
|
+
const undos = [];
|
|
2580
|
+
tables.forEach((table) => {
|
|
2581
|
+
const tableJson = table.toJSON();
|
|
2582
|
+
redos.push({
|
|
2583
|
+
id: DeleteSheetTableMutation.id,
|
|
2584
|
+
params: {
|
|
2585
|
+
unitId,
|
|
2586
|
+
subUnitId,
|
|
2587
|
+
tableId: tableJson.id
|
|
2588
|
+
}
|
|
2589
|
+
});
|
|
2590
|
+
undos.push({
|
|
2591
|
+
id: AddSheetTableMutation.id,
|
|
2592
|
+
params: {
|
|
2593
|
+
unitId,
|
|
2594
|
+
subUnitId,
|
|
2595
|
+
name: tableJson.name,
|
|
2596
|
+
range: tableJson.range,
|
|
2597
|
+
tableId: tableJson.id,
|
|
2598
|
+
options: {
|
|
2599
|
+
...tableJson.options,
|
|
2600
|
+
columns: tableJson.columns,
|
|
2601
|
+
filters: tableJson.filters.tableColumnFilterList
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
});
|
|
2605
|
+
});
|
|
2606
|
+
return {
|
|
2607
|
+
redos,
|
|
2608
|
+
undos
|
|
2609
|
+
};
|
|
2610
|
+
} else if (commandInfo.id === CopySheetCommand.id) {
|
|
2611
|
+
const { unitId, subUnitId, targetSubUnitId } = commandInfo.params;
|
|
2612
|
+
if (!unitId || !subUnitId || !targetSubUnitId) return {
|
|
2613
|
+
redos: [],
|
|
2614
|
+
undos: []
|
|
2615
|
+
};
|
|
2616
|
+
const tables = this._tableManager.getTablesBySubunitId(unitId, subUnitId);
|
|
2617
|
+
if (tables.length === 0) return {
|
|
2618
|
+
redos: [],
|
|
2619
|
+
undos: []
|
|
2620
|
+
};
|
|
2621
|
+
const redos = [];
|
|
2622
|
+
const undos = [];
|
|
2623
|
+
tables.forEach((table) => {
|
|
2624
|
+
const tableJson = table.toJSON();
|
|
2625
|
+
const tableId = generateRandomId();
|
|
2626
|
+
redos.push({
|
|
2627
|
+
id: AddSheetTableMutation.id,
|
|
2628
|
+
params: {
|
|
2629
|
+
unitId,
|
|
2630
|
+
subUnitId: targetSubUnitId,
|
|
2631
|
+
name: tableJson.name,
|
|
2632
|
+
range: {
|
|
2633
|
+
...tableJson.range,
|
|
2634
|
+
sheetId: targetSubUnitId
|
|
2635
|
+
},
|
|
2636
|
+
tableId,
|
|
2637
|
+
options: {
|
|
2638
|
+
...tableJson.options,
|
|
2639
|
+
columns: tableJson.columns,
|
|
2640
|
+
filters: tableJson.filters.tableColumnFilterList
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
});
|
|
2644
|
+
undos.push({
|
|
2645
|
+
id: DeleteSheetTableMutation.id,
|
|
2646
|
+
params: {
|
|
2647
|
+
unitId,
|
|
2648
|
+
subUnitId: targetSubUnitId,
|
|
2649
|
+
tableId
|
|
2650
|
+
}
|
|
2651
|
+
});
|
|
2652
|
+
});
|
|
2653
|
+
return {
|
|
2654
|
+
redos,
|
|
2655
|
+
undos
|
|
2656
|
+
};
|
|
2657
|
+
}
|
|
2658
|
+
return {
|
|
2659
|
+
redos: [],
|
|
2660
|
+
undos: []
|
|
2661
|
+
};
|
|
2662
|
+
} }));
|
|
2663
|
+
}
|
|
2664
|
+
dispose() {
|
|
2665
|
+
super.dispose();
|
|
2666
|
+
this._tableRangeRTree.clear();
|
|
2667
|
+
}
|
|
2668
|
+
};
|
|
2669
|
+
SheetsTableController = __decorate([
|
|
2670
|
+
__decorateParam(0, Inject(IUniverInstanceService)),
|
|
2671
|
+
__decorateParam(1, Inject(SheetInterceptorService)),
|
|
2672
|
+
__decorateParam(2, Inject(TableManager)),
|
|
2673
|
+
__decorateParam(3, Inject(IResourceManagerService))
|
|
2674
|
+
], SheetsTableController);
|
|
2675
|
+
|
|
2676
|
+
//#endregion
|
|
2677
|
+
//#region src/commands/commands/sheet-table-row-col.command.ts
|
|
2678
|
+
const SheetTableInsertRowCommand = {
|
|
2679
|
+
id: "sheet.command.table-insert-row",
|
|
2680
|
+
type: CommandType.COMMAND,
|
|
2681
|
+
handler: (accessor) => {
|
|
2682
|
+
const target = getSheetCommandTarget(accessor.get(IUniverInstanceService));
|
|
2683
|
+
if (!target) return false;
|
|
2684
|
+
const { workbook, worksheet, unitId, subUnitId } = target;
|
|
2685
|
+
const selections = accessor.get(SheetsSelectionsService).getCurrentSelections();
|
|
2686
|
+
if (!selections.length || selections.length > 1) return false;
|
|
2687
|
+
accessor.get(TableManager);
|
|
2688
|
+
const range = selections[0].range;
|
|
2689
|
+
const table = accessor.get(SheetsTableController).getContainerTableWithRange(unitId, subUnitId, range);
|
|
2690
|
+
if (!table) return false;
|
|
2691
|
+
const insertRowCount = range.endRow - range.startRow + 1;
|
|
2692
|
+
const worksheetLastRowIndex = worksheet.getRowCount() - 1;
|
|
2693
|
+
const rowContentIndex = worksheet.getCellMatrix().getDataRange().endRow;
|
|
2694
|
+
const redos = [];
|
|
2695
|
+
const undos = [];
|
|
2696
|
+
if (worksheetLastRowIndex - rowContentIndex < insertRowCount) {
|
|
2697
|
+
redos.push({
|
|
2698
|
+
id: InsertRowMutation.id,
|
|
2699
|
+
params: {
|
|
2700
|
+
unitId,
|
|
2701
|
+
subUnitId,
|
|
2702
|
+
range: { ...range }
|
|
2703
|
+
}
|
|
2704
|
+
});
|
|
2705
|
+
redos.push({
|
|
2706
|
+
id: SetSheetTableMutation.id,
|
|
2707
|
+
params: {
|
|
2708
|
+
unitId,
|
|
2709
|
+
subUnitId,
|
|
2710
|
+
tableId: table.getId(),
|
|
2711
|
+
config: { updateRange: { newRange: {
|
|
2712
|
+
...table.getRange(),
|
|
2713
|
+
endRow: table.getRange().endRow + insertRowCount
|
|
2714
|
+
} } }
|
|
2715
|
+
}
|
|
2716
|
+
});
|
|
2717
|
+
undos.push({
|
|
2718
|
+
id: SetSheetTableMutation.id,
|
|
2719
|
+
params: {
|
|
2720
|
+
unitId,
|
|
2721
|
+
subUnitId,
|
|
2722
|
+
tableId: table.getId(),
|
|
2723
|
+
config: { updateRange: { newRange: table.getRange() } }
|
|
2724
|
+
}
|
|
2725
|
+
});
|
|
2726
|
+
undos.push({
|
|
2727
|
+
id: RemoveRowMutation.id,
|
|
2728
|
+
params: {
|
|
2729
|
+
unitId,
|
|
2730
|
+
subUnitId,
|
|
2731
|
+
range: { ...range }
|
|
2732
|
+
}
|
|
2733
|
+
});
|
|
2734
|
+
} else {
|
|
2735
|
+
const oldRange = { ...table.getRange() };
|
|
2736
|
+
redos.push({
|
|
2737
|
+
id: SetSheetTableMutation.id,
|
|
2738
|
+
params: {
|
|
2739
|
+
unitId,
|
|
2740
|
+
subUnitId,
|
|
2741
|
+
tableId: table.getId(),
|
|
2742
|
+
config: { updateRange: { newRange: {
|
|
2743
|
+
...oldRange,
|
|
2744
|
+
endRow: oldRange.endRow + insertRowCount
|
|
2745
|
+
} } }
|
|
2746
|
+
}
|
|
2747
|
+
});
|
|
2748
|
+
undos.push({
|
|
2749
|
+
id: SetSheetTableMutation.id,
|
|
2750
|
+
params: {
|
|
2751
|
+
unitId,
|
|
2752
|
+
subUnitId,
|
|
2753
|
+
tableId: table.getId(),
|
|
2754
|
+
config: { updateRange: { newRange: { ...oldRange } } }
|
|
2755
|
+
}
|
|
2756
|
+
});
|
|
2757
|
+
const moveRangeMutations = getMoveRangeUndoRedoMutations(accessor, {
|
|
2758
|
+
unitId,
|
|
2759
|
+
subUnitId,
|
|
2760
|
+
range: {
|
|
2761
|
+
startRow: range.startRow,
|
|
2762
|
+
endRow: rowContentIndex,
|
|
2763
|
+
startColumn: oldRange.startColumn,
|
|
2764
|
+
endColumn: oldRange.endColumn
|
|
2765
|
+
}
|
|
2766
|
+
}, {
|
|
2767
|
+
unitId,
|
|
2768
|
+
subUnitId,
|
|
2769
|
+
range: {
|
|
2770
|
+
startRow: range.startRow + insertRowCount,
|
|
2771
|
+
endRow: rowContentIndex + insertRowCount,
|
|
2772
|
+
startColumn: oldRange.startColumn,
|
|
2773
|
+
endColumn: oldRange.endColumn
|
|
2774
|
+
}
|
|
2775
|
+
});
|
|
2776
|
+
if (moveRangeMutations) {
|
|
2777
|
+
redos.push(...moveRangeMutations.redos);
|
|
2778
|
+
undos.push(...moveRangeMutations.undos);
|
|
2779
|
+
}
|
|
2780
|
+
}
|
|
2781
|
+
if (sequenceExecute(redos, accessor.get(ICommandService))) accessor.get(IUndoRedoService).pushUndoRedo({
|
|
2782
|
+
unitID: unitId,
|
|
2783
|
+
undoMutations: undos,
|
|
2784
|
+
redoMutations: redos
|
|
2785
|
+
});
|
|
2786
|
+
return true;
|
|
2787
|
+
}
|
|
2788
|
+
};
|
|
2789
|
+
const SheetTableInsertColCommand = {
|
|
2790
|
+
id: "sheet.command.table-insert-col",
|
|
2791
|
+
type: CommandType.COMMAND,
|
|
2792
|
+
handler: (accessor) => {
|
|
2793
|
+
const target = getSheetCommandTarget(accessor.get(IUniverInstanceService));
|
|
2794
|
+
if (!target) return false;
|
|
2795
|
+
const { worksheet, unitId, subUnitId } = target;
|
|
2796
|
+
const selections = accessor.get(SheetsSelectionsService).getCurrentSelections();
|
|
2797
|
+
if (!selections.length || selections.length > 1) return false;
|
|
2798
|
+
const range = selections[0].range;
|
|
2799
|
+
const table = accessor.get(SheetsTableController).getContainerTableWithRange(unitId, subUnitId, range);
|
|
2800
|
+
if (!table) return false;
|
|
2801
|
+
const insertColCount = range.endColumn - range.startColumn + 1;
|
|
2802
|
+
const worksheetLastColIndex = worksheet.getColumnCount() - 1;
|
|
2803
|
+
const colContentIndex = worksheet.getCellMatrix().getDataRange().endColumn;
|
|
2804
|
+
const redos = [];
|
|
2805
|
+
const undos = [];
|
|
2806
|
+
if (worksheetLastColIndex - colContentIndex < insertColCount) {
|
|
2807
|
+
redos.push({
|
|
2808
|
+
id: InsertColMutation.id,
|
|
2809
|
+
params: {
|
|
2810
|
+
unitId,
|
|
2811
|
+
subUnitId,
|
|
2812
|
+
range: { ...range }
|
|
2813
|
+
}
|
|
2814
|
+
});
|
|
2815
|
+
redos.push({
|
|
2816
|
+
id: SetSheetTableMutation.id,
|
|
2817
|
+
params: {
|
|
2818
|
+
unitId,
|
|
2819
|
+
subUnitId,
|
|
2820
|
+
tableId: table.getId(),
|
|
2821
|
+
config: { rowColOperation: {
|
|
2822
|
+
operationType: IRangeOperationTypeEnum.Insert,
|
|
2823
|
+
rowColType: IRowColTypeEnum.Col,
|
|
2824
|
+
index: range.startColumn,
|
|
2825
|
+
count: insertColCount
|
|
2826
|
+
} }
|
|
2827
|
+
}
|
|
2828
|
+
});
|
|
2829
|
+
undos.push({
|
|
2830
|
+
id: SetSheetTableMutation.id,
|
|
2831
|
+
params: {
|
|
2832
|
+
unitId,
|
|
2833
|
+
subUnitId,
|
|
2834
|
+
tableId: table.getId(),
|
|
2835
|
+
config: { rowColOperation: {
|
|
2836
|
+
operationType: IRangeOperationTypeEnum.Delete,
|
|
2837
|
+
rowColType: IRowColTypeEnum.Col,
|
|
2838
|
+
index: range.startColumn,
|
|
2839
|
+
count: insertColCount
|
|
2840
|
+
} }
|
|
2841
|
+
}
|
|
2842
|
+
});
|
|
2843
|
+
undos.push({
|
|
2844
|
+
id: RemoveColMutation.id,
|
|
2845
|
+
params: {
|
|
2846
|
+
unitId,
|
|
2847
|
+
subUnitId,
|
|
2848
|
+
range: { ...range }
|
|
2849
|
+
}
|
|
2850
|
+
});
|
|
2851
|
+
} else {
|
|
2852
|
+
const oldRange = table.getRange();
|
|
2853
|
+
redos.push({
|
|
2854
|
+
id: SetSheetTableMutation.id,
|
|
2855
|
+
params: {
|
|
2856
|
+
unitId,
|
|
2857
|
+
subUnitId,
|
|
2858
|
+
tableId: table.getId(),
|
|
2859
|
+
config: { rowColOperation: {
|
|
2860
|
+
operationType: IRangeOperationTypeEnum.Insert,
|
|
2861
|
+
rowColType: IRowColTypeEnum.Col,
|
|
2862
|
+
index: range.startColumn,
|
|
2863
|
+
count: insertColCount
|
|
2864
|
+
} }
|
|
2865
|
+
}
|
|
2866
|
+
});
|
|
2867
|
+
undos.push({
|
|
2868
|
+
id: SetSheetTableMutation.id,
|
|
2869
|
+
params: {
|
|
2870
|
+
unitId,
|
|
2871
|
+
subUnitId,
|
|
2872
|
+
tableId: table.getId(),
|
|
2873
|
+
config: { rowColOperation: {
|
|
2874
|
+
operationType: IRangeOperationTypeEnum.Delete,
|
|
2875
|
+
rowColType: IRowColTypeEnum.Col,
|
|
2876
|
+
index: range.startColumn,
|
|
2877
|
+
count: insertColCount
|
|
2878
|
+
} }
|
|
2879
|
+
}
|
|
2880
|
+
});
|
|
2881
|
+
const moveRangeMutations = getMoveRangeUndoRedoMutations(accessor, {
|
|
2882
|
+
unitId,
|
|
2883
|
+
subUnitId,
|
|
2884
|
+
range: {
|
|
2885
|
+
startRow: oldRange.startRow,
|
|
2886
|
+
endRow: oldRange.endRow,
|
|
2887
|
+
startColumn: range.startColumn,
|
|
2888
|
+
endColumn: colContentIndex
|
|
2889
|
+
}
|
|
2890
|
+
}, {
|
|
2891
|
+
unitId,
|
|
2892
|
+
subUnitId,
|
|
2893
|
+
range: {
|
|
2894
|
+
startRow: oldRange.startRow,
|
|
2895
|
+
endRow: oldRange.endRow,
|
|
2896
|
+
startColumn: range.startColumn + insertColCount,
|
|
2897
|
+
endColumn: colContentIndex + insertColCount
|
|
2898
|
+
}
|
|
2899
|
+
});
|
|
2900
|
+
if (moveRangeMutations) {
|
|
2901
|
+
redos.push(...moveRangeMutations.redos);
|
|
2902
|
+
undos.push(...moveRangeMutations.undos);
|
|
2903
|
+
}
|
|
2904
|
+
}
|
|
2905
|
+
if (sequenceExecute(redos, accessor.get(ICommandService))) accessor.get(IUndoRedoService).pushUndoRedo({
|
|
2906
|
+
unitID: unitId,
|
|
2907
|
+
undoMutations: undos,
|
|
2908
|
+
redoMutations: redos
|
|
2909
|
+
});
|
|
2910
|
+
return true;
|
|
2911
|
+
}
|
|
2912
|
+
};
|
|
2913
|
+
const SheetTableRemoveRowCommand = {
|
|
2914
|
+
id: "sheet.command.table-remove-row",
|
|
2915
|
+
type: CommandType.COMMAND,
|
|
2916
|
+
handler: (accessor, params) => {
|
|
2917
|
+
if (!params) return false;
|
|
2918
|
+
const target = getSheetCommandTarget(accessor.get(IUniverInstanceService), params);
|
|
2919
|
+
if (!target) return false;
|
|
2920
|
+
const { unitId, subUnitId } = target;
|
|
2921
|
+
const selections = accessor.get(SheetsSelectionsService).getCurrentSelections();
|
|
2922
|
+
if (!selections.length || selections.length > 1) return false;
|
|
2923
|
+
const range = selections[0].range;
|
|
2924
|
+
const table = accessor.get(SheetsTableController).getContainerTableWithRange(unitId, subUnitId, range);
|
|
2925
|
+
if (!table) return false;
|
|
2926
|
+
const removeRowCount = range.endRow - range.startRow + 1;
|
|
2927
|
+
const redos = [];
|
|
2928
|
+
const undos = [];
|
|
2929
|
+
const oldRange = table.getRange();
|
|
2930
|
+
redos.push({
|
|
2931
|
+
id: SetSheetTableMutation.id,
|
|
2932
|
+
params: {
|
|
2933
|
+
unitId,
|
|
2934
|
+
subUnitId,
|
|
2935
|
+
tableId: table.getId(),
|
|
2936
|
+
config: { updateRange: { newRange: {
|
|
2937
|
+
...oldRange,
|
|
2938
|
+
endRow: oldRange.endRow - removeRowCount
|
|
2939
|
+
} } }
|
|
2940
|
+
}
|
|
2941
|
+
});
|
|
2942
|
+
undos.push({
|
|
2943
|
+
id: SetSheetTableMutation.id,
|
|
2944
|
+
params: {
|
|
2945
|
+
unitId,
|
|
2946
|
+
subUnitId,
|
|
2947
|
+
tableId: table.getId(),
|
|
2948
|
+
config: { updateRange: { newRange: { ...oldRange } } }
|
|
2949
|
+
}
|
|
2950
|
+
});
|
|
2951
|
+
const rowContentIndex = target.worksheet.getCellMatrix().getDataRange().endRow;
|
|
2952
|
+
const moveRangeMutations = getMoveRangeUndoRedoMutations(accessor, {
|
|
2953
|
+
unitId,
|
|
2954
|
+
subUnitId,
|
|
2955
|
+
range: {
|
|
2956
|
+
startRow: range.endRow + 1,
|
|
2957
|
+
endRow: rowContentIndex,
|
|
2958
|
+
startColumn: oldRange.startColumn,
|
|
2959
|
+
endColumn: oldRange.endColumn
|
|
2960
|
+
}
|
|
2961
|
+
}, {
|
|
2962
|
+
unitId,
|
|
2963
|
+
subUnitId,
|
|
2964
|
+
range: {
|
|
2965
|
+
startRow: range.startRow,
|
|
2966
|
+
endRow: rowContentIndex - removeRowCount,
|
|
2967
|
+
startColumn: oldRange.startColumn,
|
|
2968
|
+
endColumn: oldRange.endColumn
|
|
2969
|
+
}
|
|
2970
|
+
});
|
|
2971
|
+
if (moveRangeMutations) {
|
|
2972
|
+
redos.push(...moveRangeMutations.redos);
|
|
2973
|
+
undos.push(...moveRangeMutations.undos);
|
|
2974
|
+
}
|
|
2975
|
+
if (sequenceExecute(redos, accessor.get(ICommandService))) accessor.get(IUndoRedoService).pushUndoRedo({
|
|
2976
|
+
unitID: unitId,
|
|
2977
|
+
undoMutations: undos,
|
|
2978
|
+
redoMutations: redos
|
|
2979
|
+
});
|
|
2980
|
+
return true;
|
|
2981
|
+
}
|
|
2982
|
+
};
|
|
2983
|
+
const SheetTableRemoveColCommand = {
|
|
2984
|
+
id: "sheet.command.table-remove-col",
|
|
2985
|
+
type: CommandType.COMMAND,
|
|
2986
|
+
handler: (accessor, params) => {
|
|
2987
|
+
if (!params) return false;
|
|
2988
|
+
const target = getSheetCommandTarget(accessor.get(IUniverInstanceService), params);
|
|
2989
|
+
if (!target) return false;
|
|
2990
|
+
const { workbook, unitId, subUnitId } = target;
|
|
2991
|
+
accessor.get(TableManager);
|
|
2992
|
+
const selections = accessor.get(SheetsSelectionsService).getCurrentSelections();
|
|
2993
|
+
if (!selections.length || selections.length > 1) return false;
|
|
2994
|
+
const range = selections[0].range;
|
|
2995
|
+
const table = accessor.get(SheetsTableController).getContainerTableWithRange(unitId, subUnitId, range);
|
|
2996
|
+
if (!table) return false;
|
|
2997
|
+
const removeColCount = range.endColumn - range.startColumn + 1;
|
|
2998
|
+
const redos = [];
|
|
2999
|
+
const undos = [];
|
|
3000
|
+
const oldRange = table.getRange();
|
|
3001
|
+
redos.push({
|
|
3002
|
+
id: SetSheetTableMutation.id,
|
|
3003
|
+
params: {
|
|
3004
|
+
unitId,
|
|
3005
|
+
subUnitId,
|
|
3006
|
+
tableId: table.getId(),
|
|
3007
|
+
config: { rowColOperation: {
|
|
3008
|
+
operationType: IRangeOperationTypeEnum.Delete,
|
|
3009
|
+
rowColType: IRowColTypeEnum.Col,
|
|
3010
|
+
index: range.startColumn,
|
|
3011
|
+
count: removeColCount
|
|
3012
|
+
} }
|
|
3013
|
+
}
|
|
3014
|
+
});
|
|
3015
|
+
const columns = [];
|
|
3016
|
+
const gap = range.startColumn - oldRange.startColumn;
|
|
3017
|
+
for (let i = 0; i < removeColCount; i++) {
|
|
3018
|
+
const column = table.getTableInfo().columns[gap + i];
|
|
3019
|
+
if (column) columns.push(column);
|
|
3020
|
+
}
|
|
3021
|
+
undos.push({
|
|
3022
|
+
id: SetSheetTableMutation.id,
|
|
3023
|
+
params: {
|
|
3024
|
+
unitId,
|
|
3025
|
+
subUnitId,
|
|
3026
|
+
tableId: table.getId(),
|
|
3027
|
+
config: { rowColOperation: {
|
|
3028
|
+
operationType: IRangeOperationTypeEnum.Insert,
|
|
3029
|
+
rowColType: IRowColTypeEnum.Col,
|
|
3030
|
+
index: range.startColumn,
|
|
3031
|
+
count: removeColCount,
|
|
3032
|
+
columnsJson: columns
|
|
3033
|
+
} }
|
|
3034
|
+
}
|
|
3035
|
+
});
|
|
3036
|
+
const colContentIndex = target.worksheet.getCellMatrix().getDataRange().endColumn;
|
|
3037
|
+
const moveRangeMutations = getMoveRangeUndoRedoMutations(accessor, {
|
|
3038
|
+
unitId,
|
|
3039
|
+
subUnitId,
|
|
3040
|
+
range: {
|
|
3041
|
+
startRow: oldRange.startRow,
|
|
3042
|
+
endRow: oldRange.endRow,
|
|
3043
|
+
startColumn: range.endColumn + 1,
|
|
3044
|
+
endColumn: colContentIndex
|
|
3045
|
+
}
|
|
3046
|
+
}, {
|
|
3047
|
+
unitId,
|
|
3048
|
+
subUnitId,
|
|
3049
|
+
range: {
|
|
3050
|
+
startRow: oldRange.startRow,
|
|
3051
|
+
endRow: oldRange.endRow,
|
|
3052
|
+
startColumn: range.startColumn,
|
|
3053
|
+
endColumn: colContentIndex - removeColCount
|
|
3054
|
+
}
|
|
3055
|
+
});
|
|
3056
|
+
if (moveRangeMutations) {
|
|
3057
|
+
redos.push(...moveRangeMutations.redos);
|
|
3058
|
+
undos.push(...moveRangeMutations.undos);
|
|
3059
|
+
}
|
|
3060
|
+
if (sequenceExecute(redos, accessor.get(ICommandService))) accessor.get(IUndoRedoService).pushUndoRedo({
|
|
3061
|
+
unitID: unitId,
|
|
3062
|
+
undoMutations: undos,
|
|
3063
|
+
redoMutations: redos
|
|
3064
|
+
});
|
|
3065
|
+
return true;
|
|
3066
|
+
}
|
|
3067
|
+
};
|
|
3068
|
+
|
|
3069
|
+
//#endregion
|
|
3070
|
+
//#region package.json
|
|
3071
|
+
var name = "@univerjs/sheets-table";
|
|
3072
|
+
var version = "0.21.0";
|
|
3073
|
+
|
|
3074
|
+
//#endregion
|
|
3075
|
+
//#region src/controllers/sheet-table-formula.controller.ts
|
|
3076
|
+
let SheetTableFormulaController = class SheetTableFormulaController extends Disposable {
|
|
3077
|
+
constructor(_tableManager, _commandService) {
|
|
3078
|
+
super();
|
|
3079
|
+
this._tableManager = _tableManager;
|
|
3080
|
+
this._commandService = _commandService;
|
|
3081
|
+
this._initRangeListener();
|
|
3082
|
+
}
|
|
3083
|
+
_initRangeListener() {
|
|
3084
|
+
this.disposeWithMe(this._tableManager.tableRangeChanged$.subscribe((event) => {
|
|
3085
|
+
const { tableId, unitId } = event;
|
|
3086
|
+
const table = this._tableManager.getTableById(unitId, tableId);
|
|
3087
|
+
if (!table) return;
|
|
3088
|
+
this._updateSuperTable(unitId, table);
|
|
3089
|
+
}));
|
|
3090
|
+
this.disposeWithMe(this._tableManager.tableAdd$.subscribe((event) => {
|
|
3091
|
+
const { tableId, unitId } = event;
|
|
3092
|
+
const table = this._tableManager.getTableById(unitId, tableId);
|
|
3093
|
+
if (!table) return;
|
|
3094
|
+
this._updateSuperTable(unitId, table);
|
|
3095
|
+
}));
|
|
3096
|
+
this.disposeWithMe(this._tableManager.tableDelete$.subscribe((event) => {
|
|
3097
|
+
const { unitId, tableName } = event;
|
|
3098
|
+
this._commandService.executeCommand(RemoveSuperTableMutation.id, {
|
|
3099
|
+
unitId,
|
|
3100
|
+
tableName
|
|
3101
|
+
});
|
|
3102
|
+
}));
|
|
3103
|
+
this.disposeWithMe(this._tableManager.tableNameChanged$.subscribe((event) => {
|
|
3104
|
+
const { tableId, unitId, oldTableName } = event;
|
|
3105
|
+
this._commandService.executeCommand(RemoveSuperTableMutation.id, {
|
|
3106
|
+
unitId,
|
|
3107
|
+
tableName: oldTableName
|
|
3108
|
+
});
|
|
3109
|
+
const table = this._tableManager.getTableById(unitId, tableId);
|
|
3110
|
+
if (!table) return;
|
|
3111
|
+
this._updateSuperTable(unitId, table);
|
|
3112
|
+
}));
|
|
3113
|
+
}
|
|
3114
|
+
_updateSuperTable(unitId, table) {
|
|
3115
|
+
const tableInfo = table.getTableInfo();
|
|
3116
|
+
const name = tableInfo.name;
|
|
3117
|
+
const columns = tableInfo.columns;
|
|
3118
|
+
const titleMap = /* @__PURE__ */ new Map();
|
|
3119
|
+
columns.forEach((column, index) => {
|
|
3120
|
+
titleMap.set(column.displayName, index);
|
|
3121
|
+
});
|
|
3122
|
+
this._commandService.executeCommand(SetSuperTableMutation.id, {
|
|
3123
|
+
unitId,
|
|
3124
|
+
tableName: name,
|
|
3125
|
+
reference: {
|
|
3126
|
+
range: tableInfo.range,
|
|
3127
|
+
sheetId: tableInfo.subUnitId,
|
|
3128
|
+
titleMap
|
|
3129
|
+
}
|
|
3130
|
+
});
|
|
3131
|
+
}
|
|
3132
|
+
};
|
|
3133
|
+
SheetTableFormulaController = __decorate([__decorateParam(0, Inject(TableManager)), __decorateParam(1, ICommandService)], SheetTableFormulaController);
|
|
3134
|
+
|
|
3135
|
+
//#endregion
|
|
3136
|
+
//#region src/controllers/sheet-table-range.controller.ts
|
|
3137
|
+
/**
|
|
3138
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3139
|
+
*
|
|
3140
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
3141
|
+
* you may not use this file except in compliance with the License.
|
|
3142
|
+
* You may obtain a copy of the License at
|
|
3143
|
+
*
|
|
3144
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
3145
|
+
*
|
|
3146
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
3147
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
3148
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
3149
|
+
* See the License for the specific language governing permissions and
|
|
3150
|
+
* limitations under the License.
|
|
3151
|
+
*/
|
|
3152
|
+
let SheetTableRangeController = class SheetTableRangeController extends Disposable {
|
|
3153
|
+
constructor(_tableManager, _exclusiveRangeService) {
|
|
3154
|
+
super();
|
|
3155
|
+
this._tableManager = _tableManager;
|
|
3156
|
+
this._exclusiveRangeService = _exclusiveRangeService;
|
|
3157
|
+
this._initRangeListener();
|
|
3158
|
+
}
|
|
3159
|
+
_initRangeListener() {
|
|
3160
|
+
this.disposeWithMe(this._tableManager.tableRangeChanged$.subscribe((event) => {
|
|
3161
|
+
const { range, tableId, unitId, subUnitId } = event;
|
|
3162
|
+
this._exclusiveRangeService.clearExclusiveRangesByGroupId(unitId, subUnitId, FEATURE_TABLE_ID, tableId);
|
|
3163
|
+
this._exclusiveRangeService.addExclusiveRange(unitId, subUnitId, FEATURE_TABLE_ID, [{
|
|
3164
|
+
range: { ...range },
|
|
3165
|
+
groupId: tableId
|
|
3166
|
+
}]);
|
|
3167
|
+
}));
|
|
3168
|
+
this.disposeWithMe(this._tableManager.tableAdd$.subscribe((event) => {
|
|
3169
|
+
const { tableId, unitId, subUnitId, range } = event;
|
|
3170
|
+
this._exclusiveRangeService.addExclusiveRange(unitId, subUnitId, FEATURE_TABLE_ID, [{
|
|
3171
|
+
range: { ...range },
|
|
3172
|
+
groupId: tableId
|
|
3173
|
+
}]);
|
|
3174
|
+
}));
|
|
3175
|
+
this.disposeWithMe(this._tableManager.tableDelete$.subscribe((event) => {
|
|
3176
|
+
const { tableId, unitId, subUnitId } = event;
|
|
3177
|
+
this._exclusiveRangeService.clearExclusiveRangesByGroupId(unitId, subUnitId, FEATURE_TABLE_ID, tableId);
|
|
3178
|
+
}));
|
|
3179
|
+
}
|
|
3180
|
+
};
|
|
3181
|
+
SheetTableRangeController = __decorate([__decorateParam(0, Inject(TableManager)), __decorateParam(1, Inject(IExclusiveRangeService))], SheetTableRangeController);
|
|
3182
|
+
|
|
3183
|
+
//#endregion
|
|
3184
|
+
//#region src/controllers/sheet-table-ref-range.controller.ts
|
|
3185
|
+
let SheetTableRefRangeController = class SheetTableRefRangeController extends Disposable {
|
|
3186
|
+
constructor(_commandService, _refRangeService, _univerInstanceService, _injector, _sheetInterceptorService, _tableManager, _localeService) {
|
|
3187
|
+
super();
|
|
3188
|
+
this._commandService = _commandService;
|
|
3189
|
+
this._refRangeService = _refRangeService;
|
|
3190
|
+
this._univerInstanceService = _univerInstanceService;
|
|
3191
|
+
this._injector = _injector;
|
|
3192
|
+
this._sheetInterceptorService = _sheetInterceptorService;
|
|
3193
|
+
this._tableManager = _tableManager;
|
|
3194
|
+
this._localeService = _localeService;
|
|
3195
|
+
this._initCommandInterceptor();
|
|
3196
|
+
this._initCommandListener();
|
|
3197
|
+
}
|
|
3198
|
+
_initCommandInterceptor() {
|
|
3199
|
+
const self = this;
|
|
3200
|
+
this._sheetInterceptorService.interceptCommand({ getMutations(commandInfo) {
|
|
3201
|
+
const defaultReturn = {
|
|
3202
|
+
redos: [],
|
|
3203
|
+
undos: []
|
|
3204
|
+
};
|
|
3205
|
+
const { id, params } = commandInfo;
|
|
3206
|
+
switch (id) {
|
|
3207
|
+
case InsertRowCommand.id: return self._generateTableMutationWithInsertRow(params);
|
|
3208
|
+
case InsertColCommand.id: return self._generateTableMutationWithInsertCol(params);
|
|
3209
|
+
case RemoveRowCommand.id: return self._generateTableMutationWithRemoveRow(params);
|
|
3210
|
+
case RemoveColCommand.id: return self._generateTableMutationWithRemoveCol(params);
|
|
3211
|
+
}
|
|
3212
|
+
return defaultReturn;
|
|
3213
|
+
} });
|
|
3214
|
+
}
|
|
3215
|
+
_generateTableMutationWithInsertRow(insertParams) {
|
|
3216
|
+
const undos = [];
|
|
3217
|
+
const redos = [];
|
|
3218
|
+
const target = getSheetCommandTarget(this._univerInstanceService, insertParams);
|
|
3219
|
+
if (!target) return {
|
|
3220
|
+
undos,
|
|
3221
|
+
redos
|
|
3222
|
+
};
|
|
3223
|
+
const { unitId, subUnitId } = target;
|
|
3224
|
+
const allSubUnitTables = this._tableManager.getTablesBySubunitId(unitId, subUnitId);
|
|
3225
|
+
if (!allSubUnitTables.length) return {
|
|
3226
|
+
undos,
|
|
3227
|
+
redos
|
|
3228
|
+
};
|
|
3229
|
+
const { range } = insertParams;
|
|
3230
|
+
allSubUnitTables.forEach((table) => {
|
|
3231
|
+
const tableRange = table.getRange();
|
|
3232
|
+
if (range.startRow > tableRange.startRow && range.startRow <= tableRange.endRow) {
|
|
3233
|
+
const insertRowCount = range.endRow - range.startRow + 1;
|
|
3234
|
+
redos.push({
|
|
3235
|
+
id: SetSheetTableMutation.id,
|
|
3236
|
+
params: {
|
|
3237
|
+
unitId,
|
|
3238
|
+
subUnitId,
|
|
3239
|
+
tableId: table.getId(),
|
|
3240
|
+
config: { updateRange: { newRange: {
|
|
3241
|
+
...tableRange,
|
|
3242
|
+
endRow: tableRange.endRow + insertRowCount
|
|
3243
|
+
} } }
|
|
3244
|
+
}
|
|
3245
|
+
});
|
|
3246
|
+
undos.push({
|
|
3247
|
+
id: SetSheetTableMutation.id,
|
|
3248
|
+
params: {
|
|
3249
|
+
unitId,
|
|
3250
|
+
subUnitId,
|
|
3251
|
+
tableId: table.getId(),
|
|
3252
|
+
config: { updateRange: { newRange: { ...tableRange } } }
|
|
3253
|
+
}
|
|
3254
|
+
});
|
|
3255
|
+
}
|
|
3256
|
+
});
|
|
3257
|
+
return {
|
|
3258
|
+
undos,
|
|
3259
|
+
redos
|
|
3260
|
+
};
|
|
3261
|
+
}
|
|
3262
|
+
_generateTableMutationWithInsertCol(insertParams) {
|
|
3263
|
+
const undos = [];
|
|
3264
|
+
const redos = [];
|
|
3265
|
+
const target = getSheetCommandTarget(this._univerInstanceService, insertParams);
|
|
3266
|
+
if (!target) return {
|
|
3267
|
+
undos,
|
|
3268
|
+
redos
|
|
3269
|
+
};
|
|
3270
|
+
const { unitId, subUnitId } = target;
|
|
3271
|
+
const allSubUnitTables = this._tableManager.getTablesBySubunitId(unitId, subUnitId);
|
|
3272
|
+
if (!allSubUnitTables.length) return {
|
|
3273
|
+
undos,
|
|
3274
|
+
redos
|
|
3275
|
+
};
|
|
3276
|
+
const { range } = insertParams;
|
|
3277
|
+
allSubUnitTables.forEach((table) => {
|
|
3278
|
+
const tableRange = table.getRange();
|
|
3279
|
+
if (range.startColumn > tableRange.startColumn && range.startColumn <= tableRange.endColumn) {
|
|
3280
|
+
const insertColCount = range.endColumn - range.startColumn + 1;
|
|
3281
|
+
redos.push({
|
|
3282
|
+
id: SetSheetTableMutation.id,
|
|
3283
|
+
params: {
|
|
3284
|
+
unitId,
|
|
3285
|
+
subUnitId,
|
|
3286
|
+
tableId: table.getId(),
|
|
3287
|
+
config: { rowColOperation: {
|
|
3288
|
+
operationType: IRangeOperationTypeEnum.Insert,
|
|
3289
|
+
rowColType: IRowColTypeEnum.Col,
|
|
3290
|
+
index: range.startColumn,
|
|
3291
|
+
count: insertColCount
|
|
3292
|
+
} }
|
|
3293
|
+
}
|
|
3294
|
+
});
|
|
3295
|
+
undos.push({
|
|
3296
|
+
id: SetSheetTableMutation.id,
|
|
3297
|
+
params: {
|
|
3298
|
+
unitId,
|
|
3299
|
+
subUnitId,
|
|
3300
|
+
tableId: table.getId(),
|
|
3301
|
+
config: { rowColOperation: {
|
|
3302
|
+
operationType: IRangeOperationTypeEnum.Delete,
|
|
3303
|
+
rowColType: IRowColTypeEnum.Col,
|
|
3304
|
+
index: range.startColumn,
|
|
3305
|
+
count: insertColCount
|
|
3306
|
+
} }
|
|
3307
|
+
}
|
|
3308
|
+
});
|
|
3309
|
+
}
|
|
3310
|
+
});
|
|
3311
|
+
return {
|
|
3312
|
+
undos,
|
|
3313
|
+
redos
|
|
3314
|
+
};
|
|
3315
|
+
}
|
|
3316
|
+
_generateTableMutationWithRemoveRow(removeParams) {
|
|
3317
|
+
const undos = [];
|
|
3318
|
+
const redos = [];
|
|
3319
|
+
const preRedos = [];
|
|
3320
|
+
const preUndos = [];
|
|
3321
|
+
const target = getSheetCommandTarget(this._univerInstanceService);
|
|
3322
|
+
if (!target) return {
|
|
3323
|
+
undos,
|
|
3324
|
+
redos,
|
|
3325
|
+
preRedos,
|
|
3326
|
+
preUndos
|
|
3327
|
+
};
|
|
3328
|
+
const { unitId, subUnitId } = target;
|
|
3329
|
+
const allSubUnitTables = this._tableManager.getTablesBySubunitId(unitId, subUnitId);
|
|
3330
|
+
if (!allSubUnitTables.length) return {
|
|
3331
|
+
undos,
|
|
3332
|
+
redos,
|
|
3333
|
+
preRedos,
|
|
3334
|
+
preUndos
|
|
3335
|
+
};
|
|
3336
|
+
const { range } = removeParams;
|
|
3337
|
+
const removeRowCount = range.endRow - range.startRow + 1;
|
|
3338
|
+
allSubUnitTables.forEach((table) => {
|
|
3339
|
+
const tableRange = table.getRange();
|
|
3340
|
+
if (Rectangle.intersects(tableRange, range)) {
|
|
3341
|
+
if (range.startRow <= tableRange.startRow && range.endRow >= tableRange.startRow) {
|
|
3342
|
+
preRedos.push({
|
|
3343
|
+
id: DeleteSheetTableMutation.id,
|
|
3344
|
+
params: {
|
|
3345
|
+
unitId,
|
|
3346
|
+
subUnitId,
|
|
3347
|
+
tableId: table.getId()
|
|
3348
|
+
}
|
|
3349
|
+
});
|
|
3350
|
+
const tableJson = table.toJSON();
|
|
3351
|
+
undos.push({
|
|
3352
|
+
id: AddSheetTableMutation.id,
|
|
3353
|
+
params: {
|
|
3354
|
+
unitId,
|
|
3355
|
+
subUnitId,
|
|
3356
|
+
tableId: tableJson.id,
|
|
3357
|
+
name: tableJson.name,
|
|
3358
|
+
range: tableJson.range,
|
|
3359
|
+
options: tableJson.options
|
|
3360
|
+
}
|
|
3361
|
+
});
|
|
3362
|
+
} else if (range.startRow > tableRange.startRow && range.startRow <= tableRange.endRow) {
|
|
3363
|
+
redos.push({
|
|
3364
|
+
id: SetSheetTableMutation.id,
|
|
3365
|
+
params: {
|
|
3366
|
+
unitId,
|
|
3367
|
+
subUnitId,
|
|
3368
|
+
tableId: table.getId(),
|
|
3369
|
+
config: { updateRange: { newRange: {
|
|
3370
|
+
...tableRange,
|
|
3371
|
+
endRow: tableRange.endRow - removeRowCount
|
|
3372
|
+
} } }
|
|
3373
|
+
}
|
|
3374
|
+
});
|
|
3375
|
+
undos.push({
|
|
3376
|
+
id: SetSheetTableMutation.id,
|
|
3377
|
+
params: {
|
|
3378
|
+
unitId,
|
|
3379
|
+
subUnitId,
|
|
3380
|
+
tableId: table.getId(),
|
|
3381
|
+
config: { updateRange: { newRange: { ...tableRange } } }
|
|
3382
|
+
}
|
|
3383
|
+
});
|
|
3384
|
+
} else if (range.startRow < tableRange.endRow && range.endRow >= tableRange.endRow) {
|
|
3385
|
+
redos.push({
|
|
3386
|
+
id: SetSheetTableMutation.id,
|
|
3387
|
+
params: {
|
|
3388
|
+
unitId,
|
|
3389
|
+
subUnitId,
|
|
3390
|
+
tableId: table.getId(),
|
|
3391
|
+
config: { updateRange: { newRange: {
|
|
3392
|
+
...tableRange,
|
|
3393
|
+
endRow: range.startRow - 1
|
|
3394
|
+
} } }
|
|
3395
|
+
}
|
|
3396
|
+
});
|
|
3397
|
+
undos.push({
|
|
3398
|
+
id: SetSheetTableMutation.id,
|
|
3399
|
+
params: {
|
|
3400
|
+
unitId,
|
|
3401
|
+
subUnitId,
|
|
3402
|
+
tableId: table.getId(),
|
|
3403
|
+
config: { updateRange: { newRange: { ...tableRange } } }
|
|
3404
|
+
}
|
|
3405
|
+
});
|
|
3406
|
+
}
|
|
3407
|
+
}
|
|
3408
|
+
});
|
|
3409
|
+
return {
|
|
3410
|
+
undos,
|
|
3411
|
+
redos,
|
|
3412
|
+
preRedos,
|
|
3413
|
+
preUndos
|
|
3414
|
+
};
|
|
3415
|
+
}
|
|
3416
|
+
_generateTableMutationWithRemoveCol(removeParams) {
|
|
3417
|
+
const undos = [];
|
|
3418
|
+
const redos = [];
|
|
3419
|
+
const preRedos = [];
|
|
3420
|
+
const preUndos = [];
|
|
3421
|
+
const target = getSheetCommandTarget(this._univerInstanceService);
|
|
3422
|
+
if (!target) return {
|
|
3423
|
+
undos,
|
|
3424
|
+
redos,
|
|
3425
|
+
preRedos,
|
|
3426
|
+
preUndos
|
|
3427
|
+
};
|
|
3428
|
+
const { unitId, subUnitId } = target;
|
|
3429
|
+
const allSubUnitTables = this._tableManager.getTablesBySubunitId(unitId, subUnitId);
|
|
3430
|
+
if (!allSubUnitTables.length) return {
|
|
3431
|
+
undos,
|
|
3432
|
+
redos,
|
|
3433
|
+
preRedos,
|
|
3434
|
+
preUndos
|
|
3435
|
+
};
|
|
3436
|
+
const { range } = removeParams;
|
|
3437
|
+
const removeColCount = range.endColumn - range.startColumn + 1;
|
|
3438
|
+
allSubUnitTables.forEach((table) => {
|
|
3439
|
+
const tableRange = table.getRange();
|
|
3440
|
+
if (Rectangle.intersects(tableRange, range)) {
|
|
3441
|
+
if (range.startColumn <= tableRange.startColumn && range.endColumn >= tableRange.endColumn) {
|
|
3442
|
+
preRedos.push({
|
|
3443
|
+
id: DeleteSheetTableMutation.id,
|
|
3444
|
+
params: {
|
|
3445
|
+
unitId,
|
|
3446
|
+
subUnitId,
|
|
3447
|
+
tableId: table.getId()
|
|
3448
|
+
}
|
|
3449
|
+
});
|
|
3450
|
+
const tableJson = table.toJSON();
|
|
3451
|
+
const { startRow, startColumn, endColumn } = tableJson.range;
|
|
3452
|
+
const workbook = this._univerInstanceService.getUnit(unitId);
|
|
3453
|
+
const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
|
|
3454
|
+
if (!worksheet) return {
|
|
3455
|
+
undos,
|
|
3456
|
+
redos,
|
|
3457
|
+
preRedos,
|
|
3458
|
+
preUndos
|
|
3459
|
+
};
|
|
3460
|
+
const header = [];
|
|
3461
|
+
for (let i = startColumn; i <= endColumn; i++) header.push(convertCellDataToString(worksheet === null || worksheet === void 0 ? void 0 : worksheet.getCell(startRow, i)) || getColumnName(i - startColumn + 1, this._localeService.t("sheets-table.columnPrefix")));
|
|
3462
|
+
undos.push({
|
|
3463
|
+
id: AddSheetTableMutation.id,
|
|
3464
|
+
params: {
|
|
3465
|
+
unitId,
|
|
3466
|
+
subUnitId,
|
|
3467
|
+
tableId: tableJson.id,
|
|
3468
|
+
name: tableJson.name,
|
|
3469
|
+
header,
|
|
3470
|
+
range: tableJson.range,
|
|
3471
|
+
options: tableJson.options
|
|
3472
|
+
}
|
|
3473
|
+
});
|
|
3474
|
+
} else if (range.startColumn <= tableRange.startColumn && range.endColumn >= tableRange.startColumn) {
|
|
3475
|
+
const removeColumnCount = range.endColumn - tableRange.startColumn + 1;
|
|
3476
|
+
redos.push({
|
|
3477
|
+
id: SetSheetTableMutation.id,
|
|
3478
|
+
params: {
|
|
3479
|
+
unitId,
|
|
3480
|
+
subUnitId,
|
|
3481
|
+
tableId: table.getId(),
|
|
3482
|
+
config: { rowColOperation: {
|
|
3483
|
+
operationType: IRangeOperationTypeEnum.Delete,
|
|
3484
|
+
rowColType: IRowColTypeEnum.Col,
|
|
3485
|
+
index: tableRange.startColumn,
|
|
3486
|
+
count: removeColumnCount
|
|
3487
|
+
} }
|
|
3488
|
+
}
|
|
3489
|
+
});
|
|
3490
|
+
const columns = [];
|
|
3491
|
+
for (let i = 0; i < removeColumnCount; i++) {
|
|
3492
|
+
const column = table.getTableColumnByIndex(i);
|
|
3493
|
+
if (column) columns.push(column.toJSON());
|
|
3494
|
+
}
|
|
3495
|
+
undos.push({
|
|
3496
|
+
id: SetSheetTableMutation.id,
|
|
3497
|
+
params: {
|
|
3498
|
+
unitId,
|
|
3499
|
+
subUnitId,
|
|
3500
|
+
tableId: table.getId(),
|
|
3501
|
+
config: { rowColOperation: {
|
|
3502
|
+
operationType: IRangeOperationTypeEnum.Insert,
|
|
3503
|
+
rowColType: IRowColTypeEnum.Col,
|
|
3504
|
+
index: tableRange.startColumn,
|
|
3505
|
+
count: removeColumnCount,
|
|
3506
|
+
columnsJson: columns
|
|
3507
|
+
} }
|
|
3508
|
+
}
|
|
3509
|
+
});
|
|
3510
|
+
} else if (range.startColumn > tableRange.startColumn && range.endColumn > tableRange.endColumn) {
|
|
3511
|
+
const removeColumnCount = tableRange.endColumn - range.startColumn + 1;
|
|
3512
|
+
redos.push({
|
|
3513
|
+
id: SetSheetTableMutation.id,
|
|
3514
|
+
params: {
|
|
3515
|
+
unitId,
|
|
3516
|
+
subUnitId,
|
|
3517
|
+
tableId: table.getId(),
|
|
3518
|
+
config: { rowColOperation: {
|
|
3519
|
+
operationType: IRangeOperationTypeEnum.Delete,
|
|
3520
|
+
rowColType: IRowColTypeEnum.Col,
|
|
3521
|
+
index: range.startColumn,
|
|
3522
|
+
count: removeColumnCount
|
|
3523
|
+
} }
|
|
3524
|
+
}
|
|
3525
|
+
});
|
|
3526
|
+
const columns = [];
|
|
3527
|
+
const gap = range.startColumn - tableRange.startColumn;
|
|
3528
|
+
for (let i = 0; i < removeColumnCount; i++) {
|
|
3529
|
+
const column = table.getTableColumnByIndex(i + gap);
|
|
3530
|
+
if (column) columns.push(column.toJSON());
|
|
3531
|
+
}
|
|
3532
|
+
undos.push({
|
|
3533
|
+
id: SetSheetTableMutation.id,
|
|
3534
|
+
params: {
|
|
3535
|
+
unitId,
|
|
3536
|
+
subUnitId,
|
|
3537
|
+
tableId: table.getId(),
|
|
3538
|
+
config: { rowColOperation: {
|
|
3539
|
+
operationType: IRangeOperationTypeEnum.Insert,
|
|
3540
|
+
rowColType: IRowColTypeEnum.Col,
|
|
3541
|
+
index: range.startColumn,
|
|
3542
|
+
count: removeColCount,
|
|
3543
|
+
columnsJson: columns
|
|
3544
|
+
} }
|
|
3545
|
+
}
|
|
3546
|
+
});
|
|
3547
|
+
} else if (range.startColumn > tableRange.startColumn && range.endColumn <= tableRange.endColumn) {
|
|
3548
|
+
redos.push({
|
|
3549
|
+
id: SetSheetTableMutation.id,
|
|
3550
|
+
params: {
|
|
3551
|
+
unitId,
|
|
3552
|
+
subUnitId,
|
|
3553
|
+
tableId: table.getId(),
|
|
3554
|
+
config: { rowColOperation: {
|
|
3555
|
+
operationType: IRangeOperationTypeEnum.Delete,
|
|
3556
|
+
rowColType: IRowColTypeEnum.Col,
|
|
3557
|
+
index: range.startColumn,
|
|
3558
|
+
count: removeColCount
|
|
3559
|
+
} }
|
|
3560
|
+
}
|
|
3561
|
+
});
|
|
3562
|
+
const columns = [];
|
|
3563
|
+
const gap = range.startColumn - tableRange.startColumn;
|
|
3564
|
+
for (let i = 0; i < removeColCount; i++) {
|
|
3565
|
+
const column = table.getTableColumnByIndex(i + gap);
|
|
3566
|
+
if (column) columns.push(column.toJSON());
|
|
3567
|
+
}
|
|
3568
|
+
undos.push({
|
|
3569
|
+
id: SetSheetTableMutation.id,
|
|
3570
|
+
params: {
|
|
3571
|
+
unitId,
|
|
3572
|
+
subUnitId,
|
|
3573
|
+
tableId: table.getId(),
|
|
3574
|
+
config: { rowColOperation: {
|
|
3575
|
+
operationType: IRangeOperationTypeEnum.Insert,
|
|
3576
|
+
rowColType: IRowColTypeEnum.Col,
|
|
3577
|
+
index: range.startColumn,
|
|
3578
|
+
count: removeColCount,
|
|
3579
|
+
columnsJson: columns
|
|
3580
|
+
} }
|
|
3581
|
+
}
|
|
3582
|
+
});
|
|
3583
|
+
}
|
|
3584
|
+
}
|
|
3585
|
+
});
|
|
3586
|
+
return {
|
|
3587
|
+
undos,
|
|
3588
|
+
redos,
|
|
3589
|
+
preRedos,
|
|
3590
|
+
preUndos
|
|
3591
|
+
};
|
|
3592
|
+
}
|
|
3593
|
+
_initCommandListener() {
|
|
3594
|
+
this._commandService.onCommandExecuted((commandInfo) => {
|
|
3595
|
+
if (commandInfo.id === InsertRowMutation.id) {
|
|
3596
|
+
const { unitId, subUnitId, range } = commandInfo.params;
|
|
3597
|
+
const insertCount = range.endRow - range.startRow + 1;
|
|
3598
|
+
this._tableManager.getTablesBySubunitId(unitId, subUnitId).forEach((table) => {
|
|
3599
|
+
const tableRange = table.getRange();
|
|
3600
|
+
if (range.startRow <= tableRange.startRow) this._tableManager.updateTableRange(unitId, table.getId(), { newRange: {
|
|
3601
|
+
...tableRange,
|
|
3602
|
+
startRow: tableRange.startRow + insertCount,
|
|
3603
|
+
endRow: tableRange.endRow + insertCount
|
|
3604
|
+
} });
|
|
3605
|
+
});
|
|
3606
|
+
} else if (commandInfo.id === InsertColMutation.id) {
|
|
3607
|
+
const { unitId, subUnitId, range } = commandInfo.params;
|
|
3608
|
+
const insertCount = range.endColumn - range.startColumn + 1;
|
|
3609
|
+
this._tableManager.getTablesBySubunitId(unitId, subUnitId).forEach((table) => {
|
|
3610
|
+
const tableRange = table.getRange();
|
|
3611
|
+
if (range.startColumn <= tableRange.startColumn) this._tableManager.updateTableRange(unitId, table.getId(), { newRange: {
|
|
3612
|
+
...tableRange,
|
|
3613
|
+
startColumn: tableRange.startColumn + insertCount,
|
|
3614
|
+
endColumn: tableRange.endColumn + insertCount
|
|
3615
|
+
} });
|
|
3616
|
+
});
|
|
3617
|
+
} else if (commandInfo.id === RemoveRowMutation.id) {
|
|
3618
|
+
const { unitId, subUnitId, range } = commandInfo.params;
|
|
3619
|
+
const removeCount = range.endRow - range.startRow + 1;
|
|
3620
|
+
this._tableManager.getTablesBySubunitId(unitId, subUnitId).forEach((table) => {
|
|
3621
|
+
const tableRange = table.getRange();
|
|
3622
|
+
if (range.startRow < tableRange.startRow) this._tableManager.updateTableRange(unitId, table.getId(), { newRange: {
|
|
3623
|
+
...tableRange,
|
|
3624
|
+
startRow: tableRange.startRow - removeCount,
|
|
3625
|
+
endRow: tableRange.endRow - removeCount
|
|
3626
|
+
} });
|
|
3627
|
+
});
|
|
3628
|
+
} else if (commandInfo.id === RemoveColMutation.id) {
|
|
3629
|
+
const { unitId, subUnitId, range } = commandInfo.params;
|
|
3630
|
+
const removeCount = range.endColumn - range.startColumn + 1;
|
|
3631
|
+
this._tableManager.getTablesBySubunitId(unitId, subUnitId).forEach((table) => {
|
|
3632
|
+
const tableRange = table.getRange();
|
|
3633
|
+
if (range.startColumn < tableRange.startColumn) this._tableManager.updateTableRange(unitId, table.getId(), { newRange: {
|
|
3634
|
+
...tableRange,
|
|
3635
|
+
startColumn: tableRange.startColumn - removeCount,
|
|
3636
|
+
endColumn: tableRange.endColumn - removeCount
|
|
3637
|
+
} });
|
|
3638
|
+
});
|
|
3639
|
+
}
|
|
3640
|
+
});
|
|
3641
|
+
}
|
|
3642
|
+
};
|
|
3643
|
+
SheetTableRefRangeController = __decorate([
|
|
3644
|
+
__decorateParam(0, Inject(ICommandService)),
|
|
3645
|
+
__decorateParam(1, Inject(RefRangeService)),
|
|
3646
|
+
__decorateParam(2, Inject(IUniverInstanceService)),
|
|
3647
|
+
__decorateParam(3, Inject(Injector)),
|
|
3648
|
+
__decorateParam(4, Inject(SheetInterceptorService)),
|
|
3649
|
+
__decorateParam(5, Inject(TableManager)),
|
|
3650
|
+
__decorateParam(6, Inject(LocaleService))
|
|
3651
|
+
], SheetTableRefRangeController);
|
|
3652
|
+
|
|
3653
|
+
//#endregion
|
|
3654
|
+
//#region src/controllers/sheet-table-theme.controller.ts
|
|
3655
|
+
let SheetsTableThemeController = class SheetsTableThemeController extends Disposable {
|
|
3656
|
+
constructor(_tableManager, _sheetRangeThemeService, _sheetRangeThemeModel, _configService) {
|
|
3657
|
+
super();
|
|
3658
|
+
this._tableManager = _tableManager;
|
|
3659
|
+
this._sheetRangeThemeService = _sheetRangeThemeService;
|
|
3660
|
+
this._sheetRangeThemeModel = _sheetRangeThemeModel;
|
|
3661
|
+
this._configService = _configService;
|
|
3662
|
+
_defineProperty(this, "_defaultThemeIndex", 0);
|
|
3663
|
+
_defineProperty(this, "_allThemes", []);
|
|
3664
|
+
this._initUserTableTheme();
|
|
3665
|
+
this.registerTableChangeEvent();
|
|
3666
|
+
this._initDefaultTableTheme();
|
|
3667
|
+
}
|
|
3668
|
+
registerTableChangeEvent() {
|
|
3669
|
+
this.disposeWithMe(this._tableManager.tableAdd$.subscribe((event) => {
|
|
3670
|
+
const { range, tableId, unitId, subUnitId, tableStyleId } = event;
|
|
3671
|
+
const table = this._tableManager.getTable(unitId, tableId);
|
|
3672
|
+
const _tableStyleId = tableStyleId || this._allThemes[this._defaultThemeIndex].name;
|
|
3673
|
+
table.setTableStyleId(_tableStyleId);
|
|
3674
|
+
this._sheetRangeThemeService.registerRangeThemeStyle(_tableStyleId, {
|
|
3675
|
+
unitId,
|
|
3676
|
+
subUnitId,
|
|
3677
|
+
range: { ...range }
|
|
3678
|
+
});
|
|
3679
|
+
}));
|
|
3680
|
+
this.disposeWithMe(this._tableManager.tableRangeChanged$.subscribe((event) => {
|
|
3681
|
+
const { range, oldRange, tableId, unitId, subUnitId } = event;
|
|
3682
|
+
const table = this._tableManager.getTable(unitId, tableId);
|
|
3683
|
+
let tableStyleId = table.getTableStyleId();
|
|
3684
|
+
if (!tableStyleId) {
|
|
3685
|
+
tableStyleId = this._allThemes[this._defaultThemeIndex].name;
|
|
3686
|
+
table.setTableStyleId(tableStyleId);
|
|
3687
|
+
}
|
|
3688
|
+
this._sheetRangeThemeService.removeRangeThemeRule(tableStyleId, {
|
|
3689
|
+
unitId,
|
|
3690
|
+
subUnitId,
|
|
3691
|
+
range: { ...oldRange }
|
|
3692
|
+
});
|
|
3693
|
+
this._sheetRangeThemeService.registerRangeThemeStyle(tableStyleId, {
|
|
3694
|
+
unitId,
|
|
3695
|
+
subUnitId,
|
|
3696
|
+
range: { ...range }
|
|
3697
|
+
});
|
|
3698
|
+
}));
|
|
3699
|
+
this.disposeWithMe(this._tableManager.tableThemeChanged$.subscribe((event) => {
|
|
3700
|
+
const { theme, oldTheme, tableId, unitId, subUnitId } = event;
|
|
3701
|
+
const range = this._tableManager.getTable(unitId, tableId).getRange();
|
|
3702
|
+
this._sheetRangeThemeService.removeRangeThemeRule(oldTheme, {
|
|
3703
|
+
unitId,
|
|
3704
|
+
subUnitId,
|
|
3705
|
+
range: { ...range }
|
|
3706
|
+
});
|
|
3707
|
+
this._sheetRangeThemeService.registerRangeThemeStyle(theme, {
|
|
3708
|
+
unitId,
|
|
3709
|
+
subUnitId,
|
|
3710
|
+
range: { ...range }
|
|
3711
|
+
});
|
|
3712
|
+
}));
|
|
3713
|
+
this.disposeWithMe(this._tableManager.tableDelete$.subscribe((event) => {
|
|
3714
|
+
const { range, unitId, subUnitId, tableStyleId = this._allThemes[this._defaultThemeIndex].name } = event;
|
|
3715
|
+
this._sheetRangeThemeService.removeRangeThemeRule(tableStyleId, {
|
|
3716
|
+
unitId,
|
|
3717
|
+
subUnitId,
|
|
3718
|
+
range: { ...range }
|
|
3719
|
+
});
|
|
3720
|
+
}));
|
|
3721
|
+
}
|
|
3722
|
+
_initUserTableTheme() {
|
|
3723
|
+
const tableConfig = this._configService.getConfig("sheets-table.config") || {};
|
|
3724
|
+
const defaultThemeIndex = tableConfig.defaultThemeIndex || 0;
|
|
3725
|
+
const userThemes = tableConfig.userThemes || [];
|
|
3726
|
+
this._defaultThemeIndex = defaultThemeIndex;
|
|
3727
|
+
this._allThemes = userThemes.concat(tableThemeConfig);
|
|
3728
|
+
}
|
|
3729
|
+
_initDefaultTableTheme() {
|
|
3730
|
+
for (let i = 0; i < this._allThemes.length; i++) {
|
|
3731
|
+
const { name, style } = this._allThemes[i];
|
|
3732
|
+
const rangeThemeStyle = new RangeThemeStyle(name, style);
|
|
3733
|
+
this._sheetRangeThemeModel.registerDefaultRangeTheme(rangeThemeStyle);
|
|
3734
|
+
}
|
|
3735
|
+
}
|
|
3736
|
+
dispose() {
|
|
3737
|
+
super.dispose();
|
|
3738
|
+
this._allThemes = [];
|
|
3739
|
+
this._defaultThemeIndex = 0;
|
|
3740
|
+
}
|
|
3741
|
+
};
|
|
3742
|
+
SheetsTableThemeController = __decorate([
|
|
3743
|
+
__decorateParam(0, Inject(TableManager)),
|
|
3744
|
+
__decorateParam(1, Inject(SheetRangeThemeService)),
|
|
3745
|
+
__decorateParam(2, Inject(SheetRangeThemeModel)),
|
|
3746
|
+
__decorateParam(3, IConfigService)
|
|
3747
|
+
], SheetsTableThemeController);
|
|
3748
|
+
|
|
3749
|
+
//#endregion
|
|
3750
|
+
//#region src/controllers/table-filter.controller.ts
|
|
3751
|
+
let TableFilterController = class TableFilterController extends Disposable {
|
|
3752
|
+
constructor(_tableManager, _sheetInterceptorService, _univerInstanceService, _zebraCrossingCacheController) {
|
|
3753
|
+
super();
|
|
3754
|
+
this._tableManager = _tableManager;
|
|
3755
|
+
this._sheetInterceptorService = _sheetInterceptorService;
|
|
3756
|
+
this._univerInstanceService = _univerInstanceService;
|
|
3757
|
+
this._zebraCrossingCacheController = _zebraCrossingCacheController;
|
|
3758
|
+
_defineProperty(this, "_tableFilteredOutRows$", new BehaviorSubject(/* @__PURE__ */ new Set()));
|
|
3759
|
+
_defineProperty(this, "tableFilteredOutRows$", this._tableFilteredOutRows$.asObservable());
|
|
3760
|
+
_defineProperty(this, "_subscription", null);
|
|
3761
|
+
this.registerFilterChangeEvent();
|
|
3762
|
+
this.initTableHiddenRowIntercept();
|
|
3763
|
+
this._initFilteredOutRows();
|
|
3764
|
+
}
|
|
3765
|
+
get tableFilteredOutRows() {
|
|
3766
|
+
return this._tableFilteredOutRows$.value;
|
|
3767
|
+
}
|
|
3768
|
+
set tableFilteredOutRows(value) {
|
|
3769
|
+
this._tableFilteredOutRows$.next(value);
|
|
3770
|
+
}
|
|
3771
|
+
initTableHiddenRowIntercept() {
|
|
3772
|
+
this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.ROW_FILTERED, {
|
|
3773
|
+
priority: 100,
|
|
3774
|
+
handler: (filtered, rowLocation, next) => {
|
|
3775
|
+
if (filtered) return true;
|
|
3776
|
+
const isTableFiltered = this.tableFilteredOutRows.has(rowLocation.row);
|
|
3777
|
+
return isTableFiltered ? true : next(isTableFiltered);
|
|
3778
|
+
}
|
|
3779
|
+
}));
|
|
3780
|
+
}
|
|
3781
|
+
_initFilteredOutRows() {
|
|
3782
|
+
this._tableManager.tableInitStatus$.pipe(filter((initialized) => initialized), switchMap(() => {
|
|
3783
|
+
return this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET);
|
|
3784
|
+
}), filter((workbook) => workbook !== null && workbook !== void 0), switchMap((workbook) => workbook.activeSheet$), filter((sheet) => sheet !== null && sheet !== void 0)).subscribe(() => {
|
|
3785
|
+
const target = getSheetCommandTarget(this._univerInstanceService);
|
|
3786
|
+
if (!target) return;
|
|
3787
|
+
const { unitId, subUnitId } = target;
|
|
3788
|
+
this.tableFilteredOutRows.clear();
|
|
3789
|
+
this._tableManager.getTablesBySubunitId(unitId, subUnitId).forEach((table) => {
|
|
3790
|
+
const tableFilteredRows = table.getTableFilters().getFilterOutRows();
|
|
3791
|
+
if (!tableFilteredRows) return;
|
|
3792
|
+
for (const row of tableFilteredRows) this.tableFilteredOutRows.add(row);
|
|
3793
|
+
});
|
|
3794
|
+
});
|
|
3795
|
+
}
|
|
3796
|
+
registerFilterChangeEvent() {
|
|
3797
|
+
this.disposeWithMe(this._tableManager.tableFilterChanged$.subscribe((event) => {
|
|
3798
|
+
var _this$_univerInstance;
|
|
3799
|
+
const { unitId, subUnitId, tableId } = event;
|
|
3800
|
+
const worksheet = (_this$_univerInstance = this._univerInstanceService.getUnit(unitId)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getSheetBySheetId(subUnitId);
|
|
3801
|
+
const table = this._tableManager.getTable(unitId, tableId);
|
|
3802
|
+
if (!worksheet || !table) return;
|
|
3803
|
+
this.tableFilteredOutRows.clear();
|
|
3804
|
+
table.getTableFilters().doFilter(worksheet, table.getTableFilterRange());
|
|
3805
|
+
this._tableManager.getTablesBySubunitId(unitId, subUnitId).forEach((table) => {
|
|
3806
|
+
const tableFilteredRows = table.getTableFilters().getFilterOutRows();
|
|
3807
|
+
if (!tableFilteredRows) return;
|
|
3808
|
+
for (const row of tableFilteredRows) this.tableFilteredOutRows.add(row);
|
|
3809
|
+
});
|
|
3810
|
+
this._zebraCrossingCacheController.updateZebraCrossingCache(unitId, subUnitId);
|
|
3811
|
+
}));
|
|
3812
|
+
}
|
|
3813
|
+
dispose() {
|
|
3814
|
+
var _this$_subscription;
|
|
3815
|
+
super.dispose();
|
|
3816
|
+
(_this$_subscription = this._subscription) === null || _this$_subscription === void 0 || _this$_subscription.unsubscribe();
|
|
3817
|
+
}
|
|
3818
|
+
};
|
|
3819
|
+
TableFilterController = __decorate([
|
|
3820
|
+
__decorateParam(0, Inject(TableManager)),
|
|
3821
|
+
__decorateParam(1, Inject(SheetInterceptorService)),
|
|
3822
|
+
__decorateParam(2, Inject(IUniverInstanceService)),
|
|
3823
|
+
__decorateParam(3, Inject(ZebraCrossingCacheController))
|
|
3824
|
+
], TableFilterController);
|
|
3825
|
+
|
|
3826
|
+
//#endregion
|
|
3827
|
+
//#region src/plugin.ts
|
|
3828
|
+
let UniverSheetsTablePlugin = class UniverSheetsTablePlugin extends Plugin {
|
|
3829
|
+
constructor(_config = defaultPluginConfig, _injector, _configService, _commandService) {
|
|
3830
|
+
super();
|
|
3831
|
+
this._config = _config;
|
|
3832
|
+
this._injector = _injector;
|
|
3833
|
+
this._configService = _configService;
|
|
3834
|
+
this._commandService = _commandService;
|
|
3835
|
+
const { ...rest } = merge({}, defaultPluginConfig, this._config);
|
|
3836
|
+
this._configService.setConfig(SHEETS_TABLE_PLUGIN_CONFIG_KEY, rest);
|
|
3837
|
+
this._initRegisterCommand();
|
|
3838
|
+
}
|
|
3839
|
+
onStarting() {
|
|
3840
|
+
registerDependencies(this._injector, [
|
|
3841
|
+
[TableManager],
|
|
3842
|
+
[SheetsTableThemeController],
|
|
3843
|
+
[SheetsTableController],
|
|
3844
|
+
[SheetTableService],
|
|
3845
|
+
[TableFilterController],
|
|
3846
|
+
[SheetTableRangeController],
|
|
3847
|
+
[SheetTableRefRangeController],
|
|
3848
|
+
[SheetTableFormulaController]
|
|
3849
|
+
]);
|
|
3850
|
+
}
|
|
3851
|
+
onReady() {
|
|
3852
|
+
touchDependencies(this._injector, [
|
|
3853
|
+
[SheetTableFormulaController],
|
|
3854
|
+
[SheetTableRangeController],
|
|
3855
|
+
[SheetTableRefRangeController],
|
|
3856
|
+
[SheetsTableThemeController],
|
|
3857
|
+
[SheetsTableController],
|
|
3858
|
+
[SheetTableService],
|
|
3859
|
+
[TableFilterController]
|
|
3860
|
+
]);
|
|
3861
|
+
touchDependencies(this._injector, [[TableManager]]);
|
|
3862
|
+
}
|
|
3863
|
+
_initRegisterCommand() {
|
|
3864
|
+
[
|
|
3865
|
+
AddSheetTableCommand,
|
|
3866
|
+
AddSheetTableMutation,
|
|
3867
|
+
DeleteSheetTableCommand,
|
|
3868
|
+
DeleteSheetTableMutation,
|
|
3869
|
+
SetSheetTableFilterMutation,
|
|
3870
|
+
SetSheetTableFilterCommand,
|
|
3871
|
+
SetSheetTableCommand,
|
|
3872
|
+
SetSheetTableMutation,
|
|
3873
|
+
AddTableThemeCommand,
|
|
3874
|
+
RemoveTableThemeCommand,
|
|
3875
|
+
SheetTableInsertRowCommand,
|
|
3876
|
+
SheetTableInsertColCommand,
|
|
3877
|
+
SheetTableRemoveRowCommand,
|
|
3878
|
+
SheetTableRemoveColCommand
|
|
3879
|
+
].forEach((m) => this._commandService.registerCommand(m));
|
|
3880
|
+
}
|
|
3881
|
+
};
|
|
3882
|
+
_defineProperty(UniverSheetsTablePlugin, "pluginName", PLUGIN_NAME);
|
|
3883
|
+
_defineProperty(UniverSheetsTablePlugin, "packageName", name);
|
|
3884
|
+
_defineProperty(UniverSheetsTablePlugin, "version", version);
|
|
3885
|
+
_defineProperty(UniverSheetsTablePlugin, "type", UniverInstanceType.UNIVER_SHEET);
|
|
3886
|
+
UniverSheetsTablePlugin = __decorate([
|
|
3887
|
+
__decorateParam(1, Inject(Injector)),
|
|
3888
|
+
__decorateParam(2, IConfigService),
|
|
3889
|
+
__decorateParam(3, Inject(ICommandService))
|
|
3890
|
+
], UniverSheetsTablePlugin);
|
|
3891
|
+
|
|
3892
|
+
//#endregion
|
|
3893
|
+
export { AddSheetTableCommand, AddSheetTableMutation, AddTableThemeCommand, DeleteSheetTableCommand, DeleteSheetTableMutation, RemoveTableThemeCommand, SHEET_TABLE_CUSTOM_THEME_PREFIX, SetSheetTableCommand, SetSheetTableFilterCommand, SetSheetTableFilterMutation, SetSheetTableMutation, SheetTableInsertColCommand, SheetTableInsertRowCommand, SheetTableRemoveColCommand, SheetTableRemoveRowCommand, SheetTableService, SheetsTableButtonStateEnum, SheetsTableController, SheetsTableSortStateEnum, TableColumnDataTypeEnum, TableColumnFilterTypeEnum, TableConditionTypeEnum, TableDateCompareTypeEnum, TableManager, TableNumberCompareTypeEnum, TableStringCompareTypeEnum, UniverSheetsTablePlugin, customEmptyThemeWithBorderStyle, isConditionFilter, isManualTableFilter, processStyleWithBorderStyle };
|