@univerjs/sheets-source-binding 0.6.0-nightly.202502191606 → 0.6.1-nightly.202502211606

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var J=Object.defineProperty;var H=(i,s,e)=>s in i?J(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e;var l=(i,s,e)=>H(i,typeof s!="symbol"?s+"":s,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@univerjs/core"),y=require("@univerjs/sheets"),$=require("rxjs");class U{constructor(s){l(this,"_matrix",{});l(this,"_nodeMap",new Map);l(this,"_sourceIdMap",new Map);s&&this._init(s)}_init(s){this.fromJSON(s)}getBindingNodesBySourceId(s){const e=this._sourceIdMap.get(s);if(e)return e.map(t=>this._nodeMap.get(t))}setBindingNode(s,e,t){this._matrix[s]||(this._matrix[s]={}),this._matrix[s][e]||(this._matrix[s][e]=t),this._nodeMap.set(t.nodeId,t);const n=this._sourceIdMap.get(t.sourceId);n?n.push(t.nodeId):this._sourceIdMap.set(t.sourceId,[t.nodeId])}getBindingNode(s,e){var t;return(t=this._matrix[s])==null?void 0:t[e]}removeBindingNode(s,e){var n;const t=(n=this._matrix[s])==null?void 0:n[e];if(t){this._matrix[s][e]=void 0,this._nodeMap.delete(t.nodeId);const o=this._sourceIdMap.get(t.sourceId);if(o){const r=o.indexOf(t.nodeId);r>=0&&o.splice(r,1),o.length===0&&this._sourceIdMap.delete(t.sourceId)}}}getBindingNodeById(s){return this._nodeMap.get(s)}fromJSON(s){s.forEach(e=>{this.setBindingNode(e.row,e.column,e)})}toJSON(){return Array.from(this._nodeMap.values())}}var p=(i=>(i.List="list",i.Object="object",i))(p||{}),N=(i=>(i.Path="path",i.Value="value",i))(N||{}),B=(i=>(i.Add="add",i.Remove="remove",i.Update="update",i))(B||{});function A(i){return i instanceof Date&&!isNaN(i.getTime())}function x(i){const s=new Date(i);if(!A(s))return i;const e=new Date(Date.UTC(1900,0,1,0,0,0)),t=new Date(Date.UTC(1900,1,28,0,0,0));let o=(s.getTime()-e.getTime())/(1e3*3600*24);return s>t&&(o+=1),o+1}class T{constructor(s){l(this,"_data");l(this,"id");l(this,"_hasData",!1);l(this,"type");this.id=s}getId(){return this.id}getType(){return this.type}hasData(){return this._hasData}setSourceData(s){this._data=s,this._hasData=!0}toJSON(){return{id:this.id,type:this.type}}fromJSON(s){this.id=s.id,this.type=s.type}}class P extends T{constructor(e,t){super(e);l(this,"type",p.List);l(this,"_isListObject");l(this,"_fieldIndexMap",new Map);l(this,"_data",{fields:[],records:[]});this._isListObject=t!=null?t:!0}toggleListObject(e){this._isListObject=e}getData(e,t){const{path:n,row:o,containHeader:r}=e,d=this._fieldIndexMap.get(n),a=t-o;if(r&&a===0)return{v:this._data.fields[d]};let h;const c=r?1:0;if(this._isListObject?h=this._data.records[a-c][n]:h=this._data.records[a-c][d],e.isDate===!0){const f=e.formatter||"yyyy-m-d am/pm h:mm";return{v:x(h),s:{n:{pattern:f}},t:u.CellValueType.NUMBER}}else return e.formatter?{v:h,s:{n:{pattern:e.formatter}}}:{t:typeof h=="number"?u.CellValueType.NUMBER:u.CellValueType.STRING,v:h}}setSourceData(e){super.setSourceData(e);const{fields:t}=e;this._fieldIndexMap.clear(),t.forEach((n,o)=>{this._fieldIndexMap.set(n,o)})}getSourceInfo(){return{sourceId:this.id,sourceType:this.type,fields:this._data.fields,recordCount:this._data.records.length}}}class j extends T{constructor(e){super(e);l(this,"type",p.Object)}getData(e){const n=e.path.split(".");let o=this._data;for(const r of n)if(o=o[r],o===void 0)return null;if(e.isDate===!0){const r=e.formatter||"yyyy-m-d am/pm h:mm";return{v:x(o),s:{n:{pattern:r}},t:u.CellValueType.NUMBER}}else return e.formatter?{v:o,s:{n:{pattern:e.formatter}}}:{v:o,t:typeof o=="number"?u.CellValueType.NUMBER:u.CellValueType.STRING}}getSourceInfo(){return{sourceId:this.id,sourceType:p.Object}}}var q=Object.defineProperty,G=Object.getOwnPropertyDescriptor,W=(i,s,e,t)=>{for(var n=t>1?void 0:t?G(s,e):s,o=i.length-1,r;o>=0;o--)(r=i[o])&&(n=(t?r(s,e,n):r(n))||n);return t&&n&&q(s,e,n),n},D=(i,s)=>(e,t)=>s(e,t,i);let b=class extends u.Disposable{constructor(s,e,t){super();l(this,"modelMap",new Map);l(this,"_cellBindInfoUpdate$",new $.Subject);l(this,"cellBindInfoUpdate$",this._cellBindInfoUpdate$.asObservable());this._univerInstanceService=s,this._sheetInterceptorService=e,this._sheetsSelectionsService=t,this._initRemoveCommand()}_initRemoveCommand(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:s=>{const e=[],t=[],n=this._sheetsSelectionsService.getCurrentSelections(),o=y.getSheetCommandTarget(this._univerInstanceService);if(!o||!n||n.length===0)return{redos:[],undos:[]};const{unitId:r,subUnitId:d}=o;return(s.id===y.ClearSelectionContentCommand.id||s.id===y.ClearSelectionAllCommand.id)&&n.forEach(({range:a})=>{u.Range.foreach(a,(h,c)=>{this.getBindingNode(r,d,h,c)&&this.removeBindingNode(r,d,h,c)})}),{redos:e,undos:t}}}))}getBindingModelBySourceId(s){const e=[];return this.modelMap.forEach((t,n)=>{t.forEach((o,r)=>{const d=o.getBindingNodesBySourceId(s);if(d)for(const a of d)e.push({unitId:n,subunitId:r,sourceId:s,nodeId:a.nodeId,row:a.row,column:a.column})})}),e}addModel(s,e,t){var n;this.modelMap.has(s)||this.modelMap.set(s,new Map),(n=this.modelMap.get(s))==null||n.set(e,t)}getModel(s,e){var t;return(t=this.modelMap.get(s))==null?void 0:t.get(e)}setBindingNode(s,e,t){let n=this.getModel(s,e);n||(n=new U,this.addModel(s,e,n)),t.nodeId||(t.nodeId=u.generateRandomId());const{row:o,column:r}=t;if(o===void 0||r===void 0)throw new Error("row and column is required");const d=n.getBindingNode(o,r),a=t.type===p.List?!!t.containHeader:!1;n.setBindingNode(o,r,{...t,row:o,column:r}),this._cellBindInfoUpdate$.next({unitId:s,subunitId:e,sourceId:t.sourceId,nodeId:t.nodeId,row:o,column:r,containHeader:a,changeType:d?B.Update:B.Add,oldSourceId:d==null?void 0:d.sourceId,oldNodeContainHeader:(d==null?void 0:d.type)===p.List?!!d.containHeader:!1})}removeBindingNode(s,e,t,n){const o=this.getModel(s,e);if(o){const r=o.getBindingNode(t,n);r&&(o.removeBindingNode(t,n),this._cellBindInfoUpdate$.next({unitId:s,subunitId:e,sourceId:r.sourceId,nodeId:r.nodeId,row:t,column:n,changeType:B.Remove}))}}getBindingNode(s,e,t,n){const o=this.getModel(s,e);if(o)return o.getBindingNode(t,n)}getBindingNodeById(s,e,t){const n=this.getModel(s,e);if(n)return n.getBindingNodeById(t)}createModel(s,e,t){const n=new U(t);return this.addModel(s,e,n),n}toJSON(s){const e={},t=this.modelMap.get(s);return t&&t.forEach((n,o)=>{e[o]=n.toJSON()}),e}fromJSON(s,e){Object.entries(e).forEach(([t,n])=>{this.createModel(s,t,n)})}dispose(){this.modelMap.clear(),this._cellBindInfoUpdate$.complete()}};b=W([D(0,u.IUniverInstanceService),D(1,u.Inject(y.SheetInterceptorService)),D(2,u.Inject(y.SheetsSelectionsService))],b);class w extends u.Disposable{constructor(){super();l(this,"sourceMap",new Map);l(this,"_sourceDataUpdate$",new $.Subject);l(this,"sourceDataUpdate$",this._sourceDataUpdate$.asObservable())}_ensureUnitMap(e){let t=this.sourceMap.get(e);return t||(t=new Map,this.sourceMap.set(e,t)),t}_getUnitMap(e){return this.sourceMap.get(e)}getSource(e,t){const n=this._getUnitMap(e);return n==null?void 0:n.get(t)}createSource(e,t,n,o){const r=o===void 0?u.generateRandomId():o;let d;switch(t){case p.List:d=new P(r,n);break;case p.Object:d=new j(r);break;default:throw new Error(`Invalid source type: ${t}`)}return this._ensureUnitMap(e).set(r,d),d}updateSourceData(e,t,n){const o=this._getUnitMap(e),r=t instanceof T?t.getId():t,d=o==null?void 0:o.get(r);if(d)d.setSourceData(n),this._sourceDataUpdate$.next({...d.getSourceInfo(),unitId:e,changeType:B.Add});else throw new Error(`Source not found: ${r}`)}removeSource(e,t){const n=this._getUnitMap(e),o=n==null?void 0:n.get(t);o&&(n==null||n.delete(t),this._sourceDataUpdate$.next({...o.getSourceInfo(),unitId:e,changeType:B.Remove}))}toJSON(e){const t=[],n=this._getUnitMap(e);if(n)for(const o of n.values())t.push(o.toJSON());return t}fromJSON(e,t){const n=this._ensureUnitMap(e);for(const o of t){let r;switch(o.type){case p.List:r=new P(o.id);break;case p.Object:r=new j(o.id);break;default:throw new Error(`Invalid source type: ${o.type}`)}r.fromJSON(o),n.set(o.id,r)}}dispose(){this._sourceDataUpdate$.complete(),this.sourceMap.clear()}}var z=Object.defineProperty,F=Object.getOwnPropertyDescriptor,K=(i,s,e,t)=>{for(var n=t>1?void 0:t?F(s,e):s,o=i.length-1,r;o>=0;o--)(r=i[o])&&(n=(t?r(s,e,n):r(n))||n);return t&&n&&z(s,e,n),n},O=(i,s)=>(e,t)=>s(e,t,i);exports.SheetsSourceBindService=class extends u.Disposable{constructor(e,t,n){super();l(this,"_bindingModel",N.Value);l(this,"_bindModelRTreeCollection",new Map);this._sheetInterceptorService=e,this._sheetsBindingManager=t,this._sheetsSourceManager=n,this._registerInterceptor(),this._registerSourceChange()}usePathMode(){this._bindingModel=N.Path}useValueMode(){this._bindingModel=N.Value}getBindingModel(){return this._bindingModel}createBindModel(e,t){return this._sheetsBindingManager.createModel(e,t)}setBindingNode(e,t,n){this._sheetsBindingManager.setBindingNode(e,t,n)}removeBindingNode(e,t,n,o){this._sheetsBindingManager.removeBindingNode(e,t,n,o)}getBindingNode(e,t,n,o){return this._sheetsBindingManager.getBindingNode(e,t,n,o)}getSource(e,t){return this._sheetsSourceManager.getSource(e,t)}createSource(e,t,n,o){return this._sheetsSourceManager.createSource(e,t,n,o)}getSourceBindingPathInfo(e){return{source:this._sheetsSourceManager.toJSON(e),cellBinding:this._sheetsBindingManager.toJSON(e)}}loadSourceBindingPathInfo(e,t){this._sheetsSourceManager.fromJSON(e,t.source),this._sheetsBindingManager.fromJSON(e,t.cellBinding)}_ensureRTreeCollection(e){return this._bindModelRTreeCollection.has(e)||this._bindModelRTreeCollection.set(e,new u.RTree),this._bindModelRTreeCollection.get(e)}_getRTeeCollection(e){return this._bindModelRTreeCollection.get(e)}_registerSourceChange(){this.disposeWithMe(this._sheetsSourceManager.sourceDataUpdate$.subscribe(e=>{const{sourceId:t,sourceType:n,unitId:o,changeType:r}=e;if(n===p.List){if(r===B.Remove){const a=this._sheetsBindingManager.getBindingModelBySourceId(t),h=e.recordCount;for(const{unitId:c,subunitId:f,nodeId:g,row:S,column:M}of a){const I=this._getRTeeCollection(o),_=this._sheetsBindingManager.getBindingNodeById(c,f,g);if(I&&(_==null?void 0:_.type)===p.List){const m=_.containHeader?0:1,v={startRow:S,startColumn:M,endRow:S+h-m,endColumn:M};I.remove({unitId:c,sheetId:f,id:g,range:v})}}return}if(r===B.Update){const a=e.oldRecordCount,h=this._sheetsBindingManager.getBindingModelBySourceId(t);for(const{unitId:c,subunitId:f,nodeId:g,row:S,column:M}of h){const I=this._getRTeeCollection(o),_=this._sheetsBindingManager.getBindingNodeById(c,f,g);if(I&&(_==null?void 0:_.type)===p.List){const m=_.containHeader?0:1,v={startRow:S,startColumn:M,endRow:S+a-m,endColumn:M},C={startRow:S,startColumn:M,endRow:S+e.recordCount-m,endColumn:M};I.remove({unitId:c,sheetId:f,id:g,range:v}),I.insert({unitId:c,sheetId:f,id:g,range:C})}}return}const d=this._sheetsSourceManager.getSource(o,t);if(d&&d.hasData()){const h=d.getSourceInfo().recordCount,c=this._sheetsBindingManager.getBindingModelBySourceId(t);for(const{unitId:f,subunitId:g,nodeId:S,row:M,column:I}of c){const _=this._ensureRTreeCollection(f),m=this._sheetsBindingManager.getBindingNodeById(f,g,S);if(_&&(m==null?void 0:m.type)===p.List){const v=m.containHeader?0:1,C={startRow:M,startColumn:I,endRow:M+h-v,endColumn:I};_.insert({unitId:f,sheetId:g,id:S,range:C})}}}}})),this.disposeWithMe(this._sheetsBindingManager.cellBindInfoUpdate$.subscribe(e=>{const{unitId:t,subunitId:n,sourceId:o,nodeId:r,row:d,column:a,changeType:h,containHeader:c}=e,f=this._ensureRTreeCollection(t),g=this._sheetsSourceManager.getSource(t,o);if(g&&g.hasData()){const S=g.getSourceInfo();if(S.sourceType===p.List){const M=S.recordCount,I=c?0:1,_={startRow:d,startColumn:a,endRow:d+M-I,endColumn:a};if(h===B.Add)f.insert({unitId:t,sheetId:n,id:r,range:_});else if(h===B.Remove)f.remove({unitId:t,sheetId:n,id:r,range:_});else if(h===B.Update){const m=e.oldSourceId,v=e.oldNodeContainHeader?0:1,C=this._sheetsSourceManager.getSource(t,m);if(C&&C.hasData()){const V=C.getSourceInfo().recordCount,L={startRow:d,startColumn:a,endRow:d+V-v,endColumn:a};f.remove({unitId:t,sheetId:n,id:r,range:L})}f.insert({unitId:t,sheetId:n,id:r,range:_})}}}}))}_getPathModeCellValue(e,t,n,o){const r=this._sheetsBindingManager.getModel(e,t),d=r==null?void 0:r.getBindingNode(n,o);if(d){const a=d.type;if(a===p.List)return{v:`#{${d.path}}`,s:{cl:{rgb:"blue"}}};if(a===p.Object)return{v:`[${d.path}]`,s:{cl:{rgb:"blue"}}}}}_getValueModeCellValue(e,t,n,o){const r=this._sheetsBindingManager.getModel(e,t);if(r){const a=r.getBindingNode(n,o);if(a){const{sourceId:h}=a,c=this._sheetsSourceManager.getSource(e,h);if(c&&c.hasData())return(c==null?void 0:c.getData(a,n,o))||{v:""}}}const d=this._getRTeeCollection(e);if(r&&d){const a={startRow:n,startColumn:o,endRow:n,endColumn:o},h=Array.from(d.bulkSearch([{unitId:e,sheetId:t,range:a}]));if(h.length>0){const c=r.getBindingNodeById(h[0]);if(c){const{sourceId:f}=c,g=this._sheetsSourceManager.getSource(e,f);if(g&&g.hasData())return(g==null?void 0:g.getData(c,n,o))||{v:""}}}}}getBindingModelBySourceId(e){return this._sheetsBindingManager.getBindingModelBySourceId(e)}_registerInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(y.INTERCEPTOR_POINT.CELL_CONTENT,{effect:u.InterceptorEffectEnum.Value|u.InterceptorEffectEnum.Style,priority:102,handler:(e,t,n)=>{const{row:o,col:r,unitId:d,subUnitId:a,workbook:h}=t;let c=null;if(this._bindingModel===N.Path?c=this._getPathModeCellValue(d,a,o,r):c=this._getValueModeCellValue(d,a,o,r),c!==null){const g={...(typeof(e==null?void 0:e.s)=="string"?h.getStyles().get(e==null?void 0:e.s):e==null?void 0:e.s)||{}};return c&&c.s&&Object.assign(g,c.s),n({...e,...c,s:g})}return n(e)}}))}dispose(){this._bindModelRTreeCollection.clear()}};exports.SheetsSourceBindService=K([O(0,u.Inject(y.SheetInterceptorService)),O(1,u.Inject(b)),O(2,u.Inject(w))],exports.SheetsSourceBindService);var Q=Object.defineProperty,X=Object.getOwnPropertyDescriptor,Y=(i,s,e,t)=>{for(var n=t>1?void 0:t?X(s,e):s,o=i.length-1,r;o>=0;o--)(r=i[o])&&(n=(t?r(s,e,n):r(n))||n);return t&&n&&Q(s,e,n),n},E=(i,s)=>(e,t)=>s(e,t,i),R;exports.UniverSheetsBindingSourcePlugin=(R=class extends u.Plugin{constructor(s={},e,t){super(),this._config=s,this._injector=e,this._configService=t}onStarting(){[[b],[w],[exports.SheetsSourceBindService]].forEach(s=>this._injector.add(s))}onReady(){u.touchDependencies(this._injector,[[b],[w],[exports.SheetsSourceBindService]])}},l(R,"type",u.UniverInstanceType.UNIVER_SHEET),l(R,"pluginName","SHEET_BINDING_SOURCE_PLUGIN"),R);exports.UniverSheetsBindingSourcePlugin=Y([E(1,u.Inject(u.Injector)),E(2,u.IConfigService)],exports.UniverSheetsBindingSourcePlugin);exports.BindModeEnum=N;exports.BindingModel=U;exports.DataBindingNodeTypeEnum=p;exports.SheetsSourceManager=w;exports.SourceModelBase=T;
1
+ "use strict";var J=Object.defineProperty;var H=(i,o,e)=>o in i?J(i,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[o]=e;var l=(i,o,e)=>H(i,typeof o!="symbol"?o+"":o,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@univerjs/core"),C=require("@univerjs/sheets"),P=require("rxjs");class O{constructor(o){l(this,"_matrix",{});l(this,"_nodeMap",new Map);l(this,"_sourceIdMap",new Map);o&&this._init(o)}_init(o){this.fromJSON(o)}getBindingNodesBySourceId(o){const e=this._sourceIdMap.get(o);if(e)return e.map(t=>this._nodeMap.get(t))}setBindingNode(o,e,t){this._matrix[o]||(this._matrix[o]={}),this._matrix[o][e]||(this._matrix[o][e]=t),this._nodeMap.set(t.nodeId,t);const n=this._sourceIdMap.get(t.sourceId);n?n.push(t.nodeId):this._sourceIdMap.set(t.sourceId,[t.nodeId])}getBindingNode(o,e){var t;return(t=this._matrix[o])==null?void 0:t[e]}removeBindingNode(o,e){var n;const t=(n=this._matrix[o])==null?void 0:n[e];if(t){this._matrix[o][e]=void 0,this._nodeMap.delete(t.nodeId);const s=this._sourceIdMap.get(t.sourceId);if(s){const r=s.indexOf(t.nodeId);r>=0&&s.splice(r,1),s.length===0&&this._sourceIdMap.delete(t.sourceId)}}}getBindingNodeById(o){return this._nodeMap.get(o)}fromJSON(o){o.forEach(e=>{this.setBindingNode(e.row,e.column,e)})}toJSON(){return Array.from(this._nodeMap.values())}}var p=(i=>(i.List="list",i.Object="object",i))(p||{}),N=(i=>(i.Path="path",i.Value="value",i))(N||{}),B=(i=>(i.Add="add",i.Remove="remove",i.Update="update",i))(B||{});function A(i){return i instanceof Date&&!isNaN(i.getTime())}function $(i){const o=new Date(i);if(!A(o))return i;const e=new Date(Date.UTC(1900,0,1,0,0,0)),t=new Date(Date.UTC(1900,1,28,0,0,0));let s=(o.getTime()-e.getTime())/(1e3*3600*24);return o>t&&(s+=1),s+1}class T{constructor(o){l(this,"_data");l(this,"id");l(this,"_hasData",!1);l(this,"type");this.id=o}getId(){return this.id}getType(){return this.type}hasData(){return this._hasData}setSourceData(o){this._data=o,this._hasData=!0}toJSON(){return{id:this.id,type:this.type}}fromJSON(o){this.id=o.id,this.type=o.type}}class E extends T{constructor(e,t){super(e);l(this,"type",p.List);l(this,"_isListObject");l(this,"_fieldIndexMap",new Map);l(this,"_data",{fields:[],records:[]});this._isListObject=t!=null?t:!0}toggleListObject(e){this._isListObject=e}getData(e,t){const{path:n,row:s,containHeader:r}=e,a=this._fieldIndexMap.get(n),d=t-s;if(r&&d===0)return{v:this._data.fields[a]};let h;const c=r?1:0;if(this._isListObject?h=this._data.records[d-c][n]:h=this._data.records[d-c][a],e.isDate===!0){const f=e.formatter||"yyyy-m-d am/pm h:mm";return{v:$(h),s:{n:{pattern:f}},t:u.CellValueType.NUMBER}}else return e.formatter?{v:h,s:{n:{pattern:e.formatter}}}:{t:typeof h=="number"?u.CellValueType.NUMBER:u.CellValueType.STRING,v:h}}setSourceData(e){super.setSourceData(e);const{fields:t}=e;this._fieldIndexMap.clear(),t.forEach((n,s)=>{this._fieldIndexMap.set(n,s)})}getSourceInfo(){return{sourceId:this.id,sourceType:this.type,fields:this._data.fields,recordCount:this._data.records.length}}}class j extends T{constructor(e){super(e);l(this,"type",p.Object)}getData(e){const n=e.path.split(".");let s=this._data;for(const r of n)if(s=s[r],s===void 0)return null;if(e.isDate===!0){const r=e.formatter||"yyyy-m-d am/pm h:mm";return{v:$(s),s:{n:{pattern:r}},t:u.CellValueType.NUMBER}}else return e.formatter?{v:s,s:{n:{pattern:e.formatter}}}:{v:s,t:typeof s=="number"?u.CellValueType.NUMBER:u.CellValueType.STRING}}getSourceInfo(){return{sourceId:this.id,sourceType:p.Object}}}var k=Object.getOwnPropertyDescriptor,q=(i,o,e,t)=>{for(var n=t>1?void 0:t?k(o,e):o,s=i.length-1,r;s>=0;s--)(r=i[s])&&(n=r(n)||n);return n},D=(i,o)=>(e,t)=>o(e,t,i);let b=class extends u.Disposable{constructor(o,e,t){super();l(this,"modelMap",new Map);l(this,"_cellBindInfoUpdate$",new P.Subject);l(this,"cellBindInfoUpdate$",this._cellBindInfoUpdate$.asObservable());this._univerInstanceService=o,this._sheetInterceptorService=e,this._sheetsSelectionsService=t,this._initRemoveCommand()}_initRemoveCommand(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:o=>{const e=[],t=[],n=this._sheetsSelectionsService.getCurrentSelections(),s=C.getSheetCommandTarget(this._univerInstanceService);if(!s||!n||n.length===0)return{redos:[],undos:[]};const{unitId:r,subUnitId:a}=s;return(o.id===C.ClearSelectionContentCommand.id||o.id===C.ClearSelectionAllCommand.id)&&n.forEach(({range:d})=>{u.Range.foreach(d,(h,c)=>{this.getBindingNode(r,a,h,c)&&this.removeBindingNode(r,a,h,c)})}),{redos:e,undos:t}}}))}getBindingModelBySourceId(o){const e=[];return this.modelMap.forEach((t,n)=>{t.forEach((s,r)=>{const a=s.getBindingNodesBySourceId(o);if(a)for(const d of a)e.push({unitId:n,subunitId:r,sourceId:o,nodeId:d.nodeId,row:d.row,column:d.column})})}),e}addModel(o,e,t){var n;this.modelMap.has(o)||this.modelMap.set(o,new Map),(n=this.modelMap.get(o))==null||n.set(e,t)}getModel(o,e){var t;return(t=this.modelMap.get(o))==null?void 0:t.get(e)}setBindingNode(o,e,t){let n=this.getModel(o,e);n||(n=new O,this.addModel(o,e,n)),t.nodeId||(t.nodeId=u.generateRandomId());const{row:s,column:r}=t;if(s===void 0||r===void 0)throw new Error("row and column is required");const a=n.getBindingNode(s,r),d=t.type===p.List?!!t.containHeader:!1;n.setBindingNode(s,r,{...t,row:s,column:r}),this._cellBindInfoUpdate$.next({unitId:o,subunitId:e,sourceId:t.sourceId,nodeId:t.nodeId,row:s,column:r,containHeader:d,changeType:a?B.Update:B.Add,oldSourceId:a==null?void 0:a.sourceId,oldNodeContainHeader:(a==null?void 0:a.type)===p.List?!!a.containHeader:!1})}removeBindingNode(o,e,t,n){const s=this.getModel(o,e);if(s){const r=s.getBindingNode(t,n);r&&(s.removeBindingNode(t,n),this._cellBindInfoUpdate$.next({unitId:o,subunitId:e,sourceId:r.sourceId,nodeId:r.nodeId,row:t,column:n,changeType:B.Remove}))}}getBindingNode(o,e,t,n){const s=this.getModel(o,e);if(s)return s.getBindingNode(t,n)}getBindingNodeById(o,e,t){const n=this.getModel(o,e);if(n)return n.getBindingNodeById(t)}createModel(o,e,t){const n=new O(t);return this.addModel(o,e,n),n}toJSON(o){const e={},t=this.modelMap.get(o);return t&&t.forEach((n,s)=>{e[s]=n.toJSON()}),e}fromJSON(o,e){Object.entries(e).forEach(([t,n])=>{this.createModel(o,t,n)})}dispose(){this.modelMap.clear(),this._cellBindInfoUpdate$.complete()}};b=q([D(0,u.IUniverInstanceService),D(1,u.Inject(C.SheetInterceptorService)),D(2,u.Inject(C.SheetsSelectionsService))],b);class w extends u.Disposable{constructor(){super();l(this,"sourceMap",new Map);l(this,"_sourceDataUpdate$",new P.Subject);l(this,"sourceDataUpdate$",this._sourceDataUpdate$.asObservable())}_ensureUnitMap(e){let t=this.sourceMap.get(e);return t||(t=new Map,this.sourceMap.set(e,t)),t}_getUnitMap(e){return this.sourceMap.get(e)}getSource(e,t){const n=this._getUnitMap(e);return n==null?void 0:n.get(t)}createSource(e,t,n,s){const r=s===void 0?u.generateRandomId():s;let a;switch(t){case p.List:a=new E(r,n);break;case p.Object:a=new j(r);break;default:throw new Error(`Invalid source type: ${t}`)}return this._ensureUnitMap(e).set(r,a),a}updateSourceData(e,t,n){const s=this._getUnitMap(e),r=t instanceof T?t.getId():t,a=s==null?void 0:s.get(r);if(a)a.setSourceData(n),this._sourceDataUpdate$.next({...a.getSourceInfo(),unitId:e,changeType:B.Add});else throw new Error(`Source not found: ${r}`)}removeSource(e,t){const n=this._getUnitMap(e),s=n==null?void 0:n.get(t);s&&(n==null||n.delete(t),this._sourceDataUpdate$.next({...s.getSourceInfo(),unitId:e,changeType:B.Remove}))}toJSON(e){const t=[],n=this._getUnitMap(e);if(n)for(const s of n.values())t.push(s.toJSON());return t}fromJSON(e,t){const n=this._ensureUnitMap(e);for(const s of t){let r;switch(s.type){case p.List:r=new E(s.id);break;case p.Object:r=new j(s.id);break;default:throw new Error(`Invalid source type: ${s.type}`)}r.fromJSON(s),n.set(s.id,r)}}dispose(){this._sourceDataUpdate$.complete(),this.sourceMap.clear()}}var G=Object.getOwnPropertyDescriptor,W=(i,o,e,t)=>{for(var n=t>1?void 0:t?G(o,e):o,s=i.length-1,r;s>=0;s--)(r=i[s])&&(n=r(n)||n);return n},U=(i,o)=>(e,t)=>o(e,t,i);exports.SheetsSourceBindService=class extends u.Disposable{constructor(e,t,n){super();l(this,"_bindingModel",N.Value);l(this,"_bindModelRTreeCollection",new Map);this._sheetInterceptorService=e,this._sheetsBindingManager=t,this._sheetsSourceManager=n,this._registerInterceptor(),this._registerSourceChange()}usePathMode(){this._bindingModel=N.Path}useValueMode(){this._bindingModel=N.Value}getBindingModel(){return this._bindingModel}createBindModel(e,t){return this._sheetsBindingManager.createModel(e,t)}setBindingNode(e,t,n){this._sheetsBindingManager.setBindingNode(e,t,n)}removeBindingNode(e,t,n,s){this._sheetsBindingManager.removeBindingNode(e,t,n,s)}getBindingNode(e,t,n,s){return this._sheetsBindingManager.getBindingNode(e,t,n,s)}getSource(e,t){return this._sheetsSourceManager.getSource(e,t)}createSource(e,t,n,s){return this._sheetsSourceManager.createSource(e,t,n,s)}getSourceBindingPathInfo(e){return{source:this._sheetsSourceManager.toJSON(e),cellBinding:this._sheetsBindingManager.toJSON(e)}}loadSourceBindingPathInfo(e,t){this._sheetsSourceManager.fromJSON(e,t.source),this._sheetsBindingManager.fromJSON(e,t.cellBinding)}_ensureRTreeCollection(e){return this._bindModelRTreeCollection.has(e)||this._bindModelRTreeCollection.set(e,new u.RTree),this._bindModelRTreeCollection.get(e)}_getRTeeCollection(e){return this._bindModelRTreeCollection.get(e)}_registerSourceChange(){this.disposeWithMe(this._sheetsSourceManager.sourceDataUpdate$.subscribe(e=>{const{sourceId:t,sourceType:n,unitId:s,changeType:r}=e;if(n===p.List){if(r===B.Remove){const d=this._sheetsBindingManager.getBindingModelBySourceId(t),h=e.recordCount;for(const{unitId:c,subunitId:f,nodeId:g,row:S,column:M}of d){const I=this._getRTeeCollection(s),_=this._sheetsBindingManager.getBindingNodeById(c,f,g);if(I&&(_==null?void 0:_.type)===p.List){const m=_.containHeader?0:1,v={startRow:S,startColumn:M,endRow:S+h-m,endColumn:M};I.remove({unitId:c,sheetId:f,id:g,range:v})}}return}if(r===B.Update){const d=e.oldRecordCount,h=this._sheetsBindingManager.getBindingModelBySourceId(t);for(const{unitId:c,subunitId:f,nodeId:g,row:S,column:M}of h){const I=this._getRTeeCollection(s),_=this._sheetsBindingManager.getBindingNodeById(c,f,g);if(I&&(_==null?void 0:_.type)===p.List){const m=_.containHeader?0:1,v={startRow:S,startColumn:M,endRow:S+d-m,endColumn:M},y={startRow:S,startColumn:M,endRow:S+e.recordCount-m,endColumn:M};I.remove({unitId:c,sheetId:f,id:g,range:v}),I.insert({unitId:c,sheetId:f,id:g,range:y})}}return}const a=this._sheetsSourceManager.getSource(s,t);if(a&&a.hasData()){const h=a.getSourceInfo().recordCount,c=this._sheetsBindingManager.getBindingModelBySourceId(t);for(const{unitId:f,subunitId:g,nodeId:S,row:M,column:I}of c){const _=this._ensureRTreeCollection(f),m=this._sheetsBindingManager.getBindingNodeById(f,g,S);if(_&&(m==null?void 0:m.type)===p.List){const v=m.containHeader?0:1,y={startRow:M,startColumn:I,endRow:M+h-v,endColumn:I};_.insert({unitId:f,sheetId:g,id:S,range:y})}}}}})),this.disposeWithMe(this._sheetsBindingManager.cellBindInfoUpdate$.subscribe(e=>{const{unitId:t,subunitId:n,sourceId:s,nodeId:r,row:a,column:d,changeType:h,containHeader:c}=e,f=this._ensureRTreeCollection(t),g=this._sheetsSourceManager.getSource(t,s);if(g&&g.hasData()){const S=g.getSourceInfo();if(S.sourceType===p.List){const M=S.recordCount,I=c?0:1,_={startRow:a,startColumn:d,endRow:a+M-I,endColumn:d};if(h===B.Add)f.insert({unitId:t,sheetId:n,id:r,range:_});else if(h===B.Remove)f.remove({unitId:t,sheetId:n,id:r,range:_});else if(h===B.Update){const m=e.oldSourceId,v=e.oldNodeContainHeader?0:1,y=this._sheetsSourceManager.getSource(t,m);if(y&&y.hasData()){const V=y.getSourceInfo().recordCount,L={startRow:a,startColumn:d,endRow:a+V-v,endColumn:d};f.remove({unitId:t,sheetId:n,id:r,range:L})}f.insert({unitId:t,sheetId:n,id:r,range:_})}}}}))}_getPathModeCellValue(e,t,n,s){const r=this._sheetsBindingManager.getModel(e,t),a=r==null?void 0:r.getBindingNode(n,s);if(a){const d=a.type;if(d===p.List)return{v:`#{${a.path}}`,s:{cl:{rgb:"blue"}}};if(d===p.Object)return{v:`[${a.path}]`,s:{cl:{rgb:"blue"}}}}}_getValueModeCellValue(e,t,n,s){const r=this._sheetsBindingManager.getModel(e,t);if(r){const d=r.getBindingNode(n,s);if(d){const{sourceId:h}=d,c=this._sheetsSourceManager.getSource(e,h);if(c&&c.hasData())return(c==null?void 0:c.getData(d,n,s))||{v:""}}}const a=this._getRTeeCollection(e);if(r&&a){const d={startRow:n,startColumn:s,endRow:n,endColumn:s},h=Array.from(a.bulkSearch([{unitId:e,sheetId:t,range:d}]));if(h.length>0){const c=r.getBindingNodeById(h[0]);if(c){const{sourceId:f}=c,g=this._sheetsSourceManager.getSource(e,f);if(g&&g.hasData())return(g==null?void 0:g.getData(c,n,s))||{v:""}}}}}getBindingModelBySourceId(e){return this._sheetsBindingManager.getBindingModelBySourceId(e)}_registerInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(C.INTERCEPTOR_POINT.CELL_CONTENT,{effect:u.InterceptorEffectEnum.Value|u.InterceptorEffectEnum.Style,priority:102,handler:(e,t,n)=>{const{row:s,col:r,unitId:a,subUnitId:d,workbook:h}=t;let c=null;if(this._bindingModel===N.Path?c=this._getPathModeCellValue(a,d,s,r):c=this._getValueModeCellValue(a,d,s,r),c!==null){const g={...(typeof(e==null?void 0:e.s)=="string"?h.getStyles().get(e==null?void 0:e.s):e==null?void 0:e.s)||{}};return c&&c.s&&Object.assign(g,c.s),n({...e,...c,s:g})}return n(e)}}))}dispose(){this._bindModelRTreeCollection.clear()}};exports.SheetsSourceBindService=W([U(0,u.Inject(C.SheetInterceptorService)),U(1,u.Inject(b)),U(2,u.Inject(w))],exports.SheetsSourceBindService);var z=Object.getOwnPropertyDescriptor,F=(i,o,e,t)=>{for(var n=t>1?void 0:t?z(o,e):o,s=i.length-1,r;s>=0;s--)(r=i[s])&&(n=r(n)||n);return n},x=(i,o)=>(e,t)=>o(e,t,i),R;exports.UniverSheetsBindingSourcePlugin=(R=class extends u.Plugin{constructor(o={},e,t){super(),this._config=o,this._injector=e,this._configService=t}onStarting(){[[b],[w],[exports.SheetsSourceBindService]].forEach(o=>this._injector.add(o))}onReady(){u.touchDependencies(this._injector,[[b],[w],[exports.SheetsSourceBindService]])}},l(R,"type",u.UniverInstanceType.UNIVER_SHEET),l(R,"pluginName","SHEET_BINDING_SOURCE_PLUGIN"),R);exports.UniverSheetsBindingSourcePlugin=F([x(1,u.Inject(u.Injector)),x(2,u.IConfigService)],exports.UniverSheetsBindingSourcePlugin);exports.BindModeEnum=N;exports.BindingModel=O;exports.DataBindingNodeTypeEnum=p;exports.SheetsSourceManager=w;exports.SourceModelBase=T;
package/lib/es/index.js CHANGED
@@ -1,8 +1,8 @@
1
- var q = Object.defineProperty;
2
- var z = (i, e, t) => e in i ? q(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
- var l = (i, e, t) => z(i, typeof e != "symbol" ? e + "" : e, t);
4
- import { CellValueType as v, Inject as C, Disposable as O, Range as F, generateRandomId as J, IUniverInstanceService as K, RTree as Q, InterceptorEffectEnum as P, Plugin as X, UniverInstanceType as Y, touchDependencies as Z, Injector as k, IConfigService as ee } from "@univerjs/core";
5
- import { SheetInterceptorService as V, SheetsSelectionsService as te, getSheetCommandTarget as ne, ClearSelectionContentCommand as se, ClearSelectionAllCommand as oe, INTERCEPTOR_POINT as re } from "@univerjs/sheets";
1
+ var W = Object.defineProperty;
2
+ var q = (i, e, t) => e in i ? W(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
+ var l = (i, e, t) => q(i, typeof e != "symbol" ? e + "" : e, t);
4
+ import { CellValueType as v, IUniverInstanceService as z, Inject as C, Disposable as O, Range as F, generateRandomId as J, RTree as K, InterceptorEffectEnum as x, Plugin as Q, UniverInstanceType as X, touchDependencies as Y, Injector as Z, IConfigService as ee } from "@univerjs/core";
5
+ import { SheetInterceptorService as V, SheetsSelectionsService as te, getSheetCommandTarget as oe, ClearSelectionContentCommand as ne, ClearSelectionAllCommand as se, INTERCEPTOR_POINT as re } from "@univerjs/sheets";
6
6
  import { Subject as H } from "rxjs";
7
7
  class $ {
8
8
  constructor(e) {
@@ -17,26 +17,26 @@ class $ {
17
17
  getBindingNodesBySourceId(e) {
18
18
  const t = this._sourceIdMap.get(e);
19
19
  if (t)
20
- return t.map((n) => this._nodeMap.get(n));
20
+ return t.map((o) => this._nodeMap.get(o));
21
21
  }
22
- setBindingNode(e, t, n) {
23
- this._matrix[e] || (this._matrix[e] = {}), this._matrix[e][t] || (this._matrix[e][t] = n), this._nodeMap.set(n.nodeId, n);
24
- const s = this._sourceIdMap.get(n.sourceId);
25
- s ? s.push(n.nodeId) : this._sourceIdMap.set(n.sourceId, [n.nodeId]);
22
+ setBindingNode(e, t, o) {
23
+ this._matrix[e] || (this._matrix[e] = {}), this._matrix[e][t] || (this._matrix[e][t] = o), this._nodeMap.set(o.nodeId, o);
24
+ const n = this._sourceIdMap.get(o.sourceId);
25
+ n ? n.push(o.nodeId) : this._sourceIdMap.set(o.sourceId, [o.nodeId]);
26
26
  }
27
27
  getBindingNode(e, t) {
28
- var n;
29
- return (n = this._matrix[e]) == null ? void 0 : n[t];
28
+ var o;
29
+ return (o = this._matrix[e]) == null ? void 0 : o[t];
30
30
  }
31
31
  removeBindingNode(e, t) {
32
- var s;
33
- const n = (s = this._matrix[e]) == null ? void 0 : s[t];
34
- if (n) {
35
- this._matrix[e][t] = void 0, this._nodeMap.delete(n.nodeId);
36
- const o = this._sourceIdMap.get(n.sourceId);
37
- if (o) {
38
- const r = o.indexOf(n.nodeId);
39
- r >= 0 && o.splice(r, 1), o.length === 0 && this._sourceIdMap.delete(n.sourceId);
32
+ var n;
33
+ const o = (n = this._matrix[e]) == null ? void 0 : n[t];
34
+ if (o) {
35
+ this._matrix[e][t] = void 0, this._nodeMap.delete(o.nodeId);
36
+ const s = this._sourceIdMap.get(o.sourceId);
37
+ if (s) {
38
+ const r = s.indexOf(o.nodeId);
39
+ r >= 0 && s.splice(r, 1), s.length === 0 && this._sourceIdMap.delete(o.sourceId);
40
40
  }
41
41
  }
42
42
  }
@@ -60,9 +60,9 @@ function A(i) {
60
60
  const e = new Date(i);
61
61
  if (!ie(e))
62
62
  return i;
63
- const t = new Date(Date.UTC(1900, 0, 1, 0, 0, 0)), n = new Date(Date.UTC(1900, 1, 28, 0, 0, 0));
64
- let o = (e.getTime() - t.getTime()) / (1e3 * 3600 * 24);
65
- return e > n && (o += 1), o + 1;
63
+ const t = new Date(Date.UTC(1900, 0, 1, 0, 0, 0)), o = new Date(Date.UTC(1900, 1, 28, 0, 0, 0));
64
+ let s = (e.getTime() - t.getTime()) / (1e3 * 3600 * 24);
65
+ return e > o && (s += 1), s + 1;
66
66
  }
67
67
  class U {
68
68
  constructor(e) {
@@ -94,14 +94,14 @@ class U {
94
94
  this.id = e.id, this.type = e.type;
95
95
  }
96
96
  }
97
- class x extends U {
98
- constructor(t, n) {
97
+ class E extends U {
98
+ constructor(t, o) {
99
99
  super(t);
100
100
  l(this, "type", g.List);
101
101
  l(this, "_isListObject");
102
102
  l(this, "_fieldIndexMap", /* @__PURE__ */ new Map());
103
103
  l(this, "_data", { fields: [], records: [] });
104
- this._isListObject = n != null ? n : !0;
104
+ this._isListObject = o != null ? o : !0;
105
105
  }
106
106
  /**
107
107
  * Toggle the list object mode. The default value is true.
@@ -111,18 +111,18 @@ class x extends U {
111
111
  toggleListObject(t) {
112
112
  this._isListObject = t;
113
113
  }
114
- getData(t, n) {
115
- const { path: s, row: o, containHeader: r } = t, d = this._fieldIndexMap.get(s), c = n - o;
114
+ getData(t, o) {
115
+ const { path: n, row: s, containHeader: r } = t, a = this._fieldIndexMap.get(n), c = o - s;
116
116
  if (r && c === 0)
117
117
  return {
118
- v: this._data.fields[d]
118
+ v: this._data.fields[a]
119
119
  };
120
- let a;
120
+ let d;
121
121
  const h = r ? 1 : 0;
122
- if (this._isListObject ? a = this._data.records[c - h][s] : a = this._data.records[c - h][d], t.isDate === !0) {
122
+ if (this._isListObject ? d = this._data.records[c - h][n] : d = this._data.records[c - h][a], t.isDate === !0) {
123
123
  const u = t.formatter || "yyyy-m-d am/pm h:mm";
124
124
  return {
125
- v: A(a),
125
+ v: A(d),
126
126
  s: {
127
127
  n: {
128
128
  pattern: u
@@ -132,22 +132,22 @@ class x extends U {
132
132
  };
133
133
  } else
134
134
  return t.formatter ? {
135
- v: a,
135
+ v: d,
136
136
  s: {
137
137
  n: {
138
138
  pattern: t.formatter
139
139
  }
140
140
  }
141
141
  } : {
142
- t: typeof a == "number" ? v.NUMBER : v.STRING,
143
- v: a
142
+ t: typeof d == "number" ? v.NUMBER : v.STRING,
143
+ v: d
144
144
  };
145
145
  }
146
146
  setSourceData(t) {
147
147
  super.setSourceData(t);
148
- const { fields: n } = t;
149
- this._fieldIndexMap.clear(), n.forEach((s, o) => {
150
- this._fieldIndexMap.set(s, o);
148
+ const { fields: o } = t;
149
+ this._fieldIndexMap.clear(), o.forEach((n, s) => {
150
+ this._fieldIndexMap.set(n, s);
151
151
  });
152
152
  }
153
153
  getSourceInfo() {
@@ -159,21 +159,21 @@ class x extends U {
159
159
  };
160
160
  }
161
161
  }
162
- class E extends U {
162
+ class P extends U {
163
163
  constructor(t) {
164
164
  super(t);
165
165
  l(this, "type", g.Object);
166
166
  }
167
167
  getData(t) {
168
- const s = t.path.split(".");
169
- let o = this._data;
170
- for (const r of s)
171
- if (o = o[r], o === void 0)
168
+ const n = t.path.split(".");
169
+ let s = this._data;
170
+ for (const r of n)
171
+ if (s = s[r], s === void 0)
172
172
  return null;
173
173
  if (t.isDate === !0) {
174
174
  const r = t.formatter || "yyyy-m-d am/pm h:mm";
175
175
  return {
176
- v: A(o),
176
+ v: A(s),
177
177
  s: {
178
178
  n: {
179
179
  pattern: r
@@ -183,15 +183,15 @@ class E extends U {
183
183
  };
184
184
  } else
185
185
  return t.formatter ? {
186
- v: o,
186
+ v: s,
187
187
  s: {
188
188
  n: {
189
189
  pattern: t.formatter
190
190
  }
191
191
  }
192
192
  } : {
193
- v: o,
194
- t: typeof o == "number" ? v.NUMBER : v.STRING
193
+ v: s,
194
+ t: typeof s == "number" ? v.NUMBER : v.STRING
195
195
  };
196
196
  }
197
197
  getSourceInfo() {
@@ -201,48 +201,48 @@ class E extends U {
201
201
  };
202
202
  }
203
203
  }
204
- var de = Object.defineProperty, ae = Object.getOwnPropertyDescriptor, ce = (i, e, t, n) => {
205
- for (var s = n > 1 ? void 0 : n ? ae(e, t) : e, o = i.length - 1, r; o >= 0; o--)
206
- (r = i[o]) && (s = (n ? r(e, t, s) : r(s)) || s);
207
- return n && s && de(e, t, s), s;
208
- }, R = (i, e) => (t, n) => e(t, n, i);
204
+ var ae = Object.getOwnPropertyDescriptor, de = (i, e, t, o) => {
205
+ for (var n = o > 1 ? void 0 : o ? ae(e, t) : e, s = i.length - 1, r; s >= 0; s--)
206
+ (r = i[s]) && (n = r(n) || n);
207
+ return n;
208
+ }, b = (i, e) => (t, o) => e(t, o, i);
209
209
  let N = class extends O {
210
- constructor(e, t, n) {
210
+ constructor(e, t, o) {
211
211
  super();
212
212
  l(this, "modelMap", /* @__PURE__ */ new Map());
213
213
  l(this, "_cellBindInfoUpdate$", new H());
214
214
  l(this, "cellBindInfoUpdate$", this._cellBindInfoUpdate$.asObservable());
215
- this._univerInstanceService = e, this._sheetInterceptorService = t, this._sheetsSelectionsService = n, this._initRemoveCommand();
215
+ this._univerInstanceService = e, this._sheetInterceptorService = t, this._sheetsSelectionsService = o, this._initRemoveCommand();
216
216
  }
217
217
  _initRemoveCommand() {
218
218
  this.disposeWithMe(
219
219
  this._sheetInterceptorService.interceptCommand({
220
220
  getMutations: (e) => {
221
- const t = [], n = [], s = this._sheetsSelectionsService.getCurrentSelections(), o = ne(this._univerInstanceService);
222
- if (!o || !s || s.length === 0)
221
+ const t = [], o = [], n = this._sheetsSelectionsService.getCurrentSelections(), s = oe(this._univerInstanceService);
222
+ if (!s || !n || n.length === 0)
223
223
  return {
224
224
  redos: [],
225
225
  undos: []
226
226
  };
227
- const { unitId: r, subUnitId: d } = o;
228
- return (e.id === se.id || e.id === oe.id) && s.forEach(({ range: c }) => {
229
- F.foreach(c, (a, h) => {
230
- this.getBindingNode(r, d, a, h) && this.removeBindingNode(r, d, a, h);
227
+ const { unitId: r, subUnitId: a } = s;
228
+ return (e.id === ne.id || e.id === se.id) && n.forEach(({ range: c }) => {
229
+ F.foreach(c, (d, h) => {
230
+ this.getBindingNode(r, a, d, h) && this.removeBindingNode(r, a, d, h);
231
231
  });
232
- }), { redos: t, undos: n };
232
+ }), { redos: t, undos: o };
233
233
  }
234
234
  })
235
235
  );
236
236
  }
237
237
  getBindingModelBySourceId(e) {
238
238
  const t = [];
239
- return this.modelMap.forEach((n, s) => {
240
- n.forEach((o, r) => {
241
- const d = o.getBindingNodesBySourceId(e);
242
- if (d)
243
- for (const c of d)
239
+ return this.modelMap.forEach((o, n) => {
240
+ o.forEach((s, r) => {
241
+ const a = s.getBindingNodesBySourceId(e);
242
+ if (a)
243
+ for (const c of a)
244
244
  t.push({
245
- unitId: s,
245
+ unitId: n,
246
246
  subunitId: r,
247
247
  sourceId: e,
248
248
  nodeId: c.nodeId,
@@ -252,82 +252,82 @@ let N = class extends O {
252
252
  });
253
253
  }), t;
254
254
  }
255
- addModel(e, t, n) {
256
- var s;
257
- this.modelMap.has(e) || this.modelMap.set(e, /* @__PURE__ */ new Map()), (s = this.modelMap.get(e)) == null || s.set(t, n);
258
- }
259
- getModel(e, t) {
255
+ addModel(e, t, o) {
260
256
  var n;
261
- return (n = this.modelMap.get(e)) == null ? void 0 : n.get(t);
257
+ this.modelMap.has(e) || this.modelMap.set(e, /* @__PURE__ */ new Map()), (n = this.modelMap.get(e)) == null || n.set(t, o);
262
258
  }
263
- setBindingNode(e, t, n) {
264
- let s = this.getModel(e, t);
265
- s || (s = new $(), this.addModel(e, t, s)), n.nodeId || (n.nodeId = J());
266
- const { row: o, column: r } = n;
267
- if (o === void 0 || r === void 0)
259
+ getModel(e, t) {
260
+ var o;
261
+ return (o = this.modelMap.get(e)) == null ? void 0 : o.get(t);
262
+ }
263
+ setBindingNode(e, t, o) {
264
+ let n = this.getModel(e, t);
265
+ n || (n = new $(), this.addModel(e, t, n)), o.nodeId || (o.nodeId = J());
266
+ const { row: s, column: r } = o;
267
+ if (s === void 0 || r === void 0)
268
268
  throw new Error("row and column is required");
269
- const d = s.getBindingNode(o, r), c = n.type === g.List ? !!n.containHeader : !1;
270
- s.setBindingNode(o, r, { ...n, row: o, column: r }), this._cellBindInfoUpdate$.next({
269
+ const a = n.getBindingNode(s, r), c = o.type === g.List ? !!o.containHeader : !1;
270
+ n.setBindingNode(s, r, { ...o, row: s, column: r }), this._cellBindInfoUpdate$.next({
271
271
  unitId: e,
272
272
  subunitId: t,
273
- sourceId: n.sourceId,
274
- nodeId: n.nodeId,
275
- row: o,
273
+ sourceId: o.sourceId,
274
+ nodeId: o.nodeId,
275
+ row: s,
276
276
  column: r,
277
277
  containHeader: c,
278
- changeType: d ? m.Update : m.Add,
279
- oldSourceId: d == null ? void 0 : d.sourceId,
280
- oldNodeContainHeader: (d == null ? void 0 : d.type) === g.List ? !!d.containHeader : !1
278
+ changeType: a ? m.Update : m.Add,
279
+ oldSourceId: a == null ? void 0 : a.sourceId,
280
+ oldNodeContainHeader: (a == null ? void 0 : a.type) === g.List ? !!a.containHeader : !1
281
281
  });
282
282
  }
283
- removeBindingNode(e, t, n, s) {
284
- const o = this.getModel(e, t);
285
- if (o) {
286
- const r = o.getBindingNode(n, s);
287
- r && (o.removeBindingNode(n, s), this._cellBindInfoUpdate$.next({
283
+ removeBindingNode(e, t, o, n) {
284
+ const s = this.getModel(e, t);
285
+ if (s) {
286
+ const r = s.getBindingNode(o, n);
287
+ r && (s.removeBindingNode(o, n), this._cellBindInfoUpdate$.next({
288
288
  unitId: e,
289
289
  subunitId: t,
290
290
  sourceId: r.sourceId,
291
291
  nodeId: r.nodeId,
292
- row: n,
293
- column: s,
292
+ row: o,
293
+ column: n,
294
294
  changeType: m.Remove
295
295
  }));
296
296
  }
297
297
  }
298
- getBindingNode(e, t, n, s) {
299
- const o = this.getModel(e, t);
300
- if (o)
301
- return o.getBindingNode(n, s);
302
- }
303
- getBindingNodeById(e, t, n) {
298
+ getBindingNode(e, t, o, n) {
304
299
  const s = this.getModel(e, t);
305
300
  if (s)
306
- return s.getBindingNodeById(n);
301
+ return s.getBindingNode(o, n);
307
302
  }
308
- createModel(e, t, n) {
309
- const s = new $(n);
310
- return this.addModel(e, t, s), s;
303
+ getBindingNodeById(e, t, o) {
304
+ const n = this.getModel(e, t);
305
+ if (n)
306
+ return n.getBindingNodeById(o);
307
+ }
308
+ createModel(e, t, o) {
309
+ const n = new $(o);
310
+ return this.addModel(e, t, n), n;
311
311
  }
312
312
  toJSON(e) {
313
- const t = {}, n = this.modelMap.get(e);
314
- return n && n.forEach((s, o) => {
315
- t[o] = s.toJSON();
313
+ const t = {}, o = this.modelMap.get(e);
314
+ return o && o.forEach((n, s) => {
315
+ t[s] = n.toJSON();
316
316
  }), t;
317
317
  }
318
318
  fromJSON(e, t) {
319
- Object.entries(t).forEach(([n, s]) => {
320
- this.createModel(e, n, s);
319
+ Object.entries(t).forEach(([o, n]) => {
320
+ this.createModel(e, o, n);
321
321
  });
322
322
  }
323
323
  dispose() {
324
324
  this.modelMap.clear(), this._cellBindInfoUpdate$.complete();
325
325
  }
326
326
  };
327
- N = ce([
328
- R(0, K),
329
- R(1, C(V)),
330
- R(2, C(te))
327
+ N = de([
328
+ b(0, z),
329
+ b(1, C(V)),
330
+ b(2, C(te))
331
331
  ], N);
332
332
  class T extends O {
333
333
  constructor() {
@@ -337,81 +337,81 @@ class T extends O {
337
337
  l(this, "sourceDataUpdate$", this._sourceDataUpdate$.asObservable());
338
338
  }
339
339
  _ensureUnitMap(t) {
340
- let n = this.sourceMap.get(t);
341
- return n || (n = /* @__PURE__ */ new Map(), this.sourceMap.set(t, n)), n;
340
+ let o = this.sourceMap.get(t);
341
+ return o || (o = /* @__PURE__ */ new Map(), this.sourceMap.set(t, o)), o;
342
342
  }
343
343
  _getUnitMap(t) {
344
344
  return this.sourceMap.get(t);
345
345
  }
346
- getSource(t, n) {
347
- const s = this._getUnitMap(t);
348
- return s == null ? void 0 : s.get(n);
346
+ getSource(t, o) {
347
+ const n = this._getUnitMap(t);
348
+ return n == null ? void 0 : n.get(o);
349
349
  }
350
- createSource(t, n, s, o) {
351
- const r = o === void 0 ? J() : o;
352
- let d;
353
- switch (n) {
350
+ createSource(t, o, n, s) {
351
+ const r = s === void 0 ? J() : s;
352
+ let a;
353
+ switch (o) {
354
354
  case g.List:
355
- d = new x(r, s);
355
+ a = new E(r, n);
356
356
  break;
357
357
  case g.Object:
358
- d = new E(r);
358
+ a = new P(r);
359
359
  break;
360
360
  default:
361
- throw new Error(`Invalid source type: ${n}`);
361
+ throw new Error(`Invalid source type: ${o}`);
362
362
  }
363
- return this._ensureUnitMap(t).set(r, d), d;
363
+ return this._ensureUnitMap(t).set(r, a), a;
364
364
  }
365
- updateSourceData(t, n, s) {
366
- const o = this._getUnitMap(t), r = n instanceof U ? n.getId() : n, d = o == null ? void 0 : o.get(r);
367
- if (d)
368
- d.setSourceData(s), this._sourceDataUpdate$.next({ ...d.getSourceInfo(), unitId: t, changeType: m.Add });
365
+ updateSourceData(t, o, n) {
366
+ const s = this._getUnitMap(t), r = o instanceof U ? o.getId() : o, a = s == null ? void 0 : s.get(r);
367
+ if (a)
368
+ a.setSourceData(n), this._sourceDataUpdate$.next({ ...a.getSourceInfo(), unitId: t, changeType: m.Add });
369
369
  else
370
370
  throw new Error(`Source not found: ${r}`);
371
371
  }
372
- removeSource(t, n) {
373
- const s = this._getUnitMap(t), o = s == null ? void 0 : s.get(n);
374
- o && (s == null || s.delete(n), this._sourceDataUpdate$.next({ ...o.getSourceInfo(), unitId: t, changeType: m.Remove }));
372
+ removeSource(t, o) {
373
+ const n = this._getUnitMap(t), s = n == null ? void 0 : n.get(o);
374
+ s && (n == null || n.delete(o), this._sourceDataUpdate$.next({ ...s.getSourceInfo(), unitId: t, changeType: m.Remove }));
375
375
  }
376
376
  toJSON(t) {
377
- const n = [], s = this._getUnitMap(t);
378
- if (s)
379
- for (const o of s.values())
380
- n.push(o.toJSON());
381
- return n;
382
- }
383
- fromJSON(t, n) {
384
- const s = this._ensureUnitMap(t);
385
- for (const o of n) {
377
+ const o = [], n = this._getUnitMap(t);
378
+ if (n)
379
+ for (const s of n.values())
380
+ o.push(s.toJSON());
381
+ return o;
382
+ }
383
+ fromJSON(t, o) {
384
+ const n = this._ensureUnitMap(t);
385
+ for (const s of o) {
386
386
  let r;
387
- switch (o.type) {
387
+ switch (s.type) {
388
388
  case g.List:
389
- r = new x(o.id);
389
+ r = new E(s.id);
390
390
  break;
391
391
  case g.Object:
392
- r = new E(o.id);
392
+ r = new P(s.id);
393
393
  break;
394
394
  default:
395
- throw new Error(`Invalid source type: ${o.type}`);
395
+ throw new Error(`Invalid source type: ${s.type}`);
396
396
  }
397
- r.fromJSON(o), s.set(o.id, r);
397
+ r.fromJSON(s), n.set(s.id, r);
398
398
  }
399
399
  }
400
400
  dispose() {
401
401
  this._sourceDataUpdate$.complete(), this.sourceMap.clear();
402
402
  }
403
403
  }
404
- var ue = Object.defineProperty, he = Object.getOwnPropertyDescriptor, le = (i, e, t, n) => {
405
- for (var s = n > 1 ? void 0 : n ? he(e, t) : e, o = i.length - 1, r; o >= 0; o--)
406
- (r = i[o]) && (s = (n ? r(e, t, s) : r(s)) || s);
407
- return n && s && ue(e, t, s), s;
408
- }, D = (i, e) => (t, n) => e(t, n, i);
409
- let w = class extends O {
410
- constructor(e, t, n) {
404
+ var ce = Object.getOwnPropertyDescriptor, ue = (i, e, t, o) => {
405
+ for (var n = o > 1 ? void 0 : o ? ce(e, t) : e, s = i.length - 1, r; s >= 0; s--)
406
+ (r = i[s]) && (n = r(n) || n);
407
+ return n;
408
+ }, D = (i, e) => (t, o) => e(t, o, i);
409
+ let R = class extends O {
410
+ constructor(e, t, o) {
411
411
  super();
412
412
  l(this, "_bindingModel", y.Value);
413
413
  l(this, "_bindModelRTreeCollection", /* @__PURE__ */ new Map());
414
- this._sheetInterceptorService = e, this._sheetsBindingManager = t, this._sheetsSourceManager = n, this._registerInterceptor(), this._registerSourceChange();
414
+ this._sheetInterceptorService = e, this._sheetsBindingManager = t, this._sheetsSourceManager = o, this._registerInterceptor(), this._registerSourceChange();
415
415
  }
416
416
  /**
417
417
  * Set the binding model to path mode, in this mode, the binding path will show in the cell.
@@ -435,20 +435,20 @@ let w = class extends O {
435
435
  createBindModel(e, t) {
436
436
  return this._sheetsBindingManager.createModel(e, t);
437
437
  }
438
- setBindingNode(e, t, n) {
439
- this._sheetsBindingManager.setBindingNode(e, t, n);
438
+ setBindingNode(e, t, o) {
439
+ this._sheetsBindingManager.setBindingNode(e, t, o);
440
440
  }
441
- removeBindingNode(e, t, n, s) {
442
- this._sheetsBindingManager.removeBindingNode(e, t, n, s);
441
+ removeBindingNode(e, t, o, n) {
442
+ this._sheetsBindingManager.removeBindingNode(e, t, o, n);
443
443
  }
444
- getBindingNode(e, t, n, s) {
445
- return this._sheetsBindingManager.getBindingNode(e, t, n, s);
444
+ getBindingNode(e, t, o, n) {
445
+ return this._sheetsBindingManager.getBindingNode(e, t, o, n);
446
446
  }
447
447
  getSource(e, t) {
448
448
  return this._sheetsSourceManager.getSource(e, t);
449
449
  }
450
- createSource(e, t, n, s) {
451
- return this._sheetsSourceManager.createSource(e, t, n, s);
450
+ createSource(e, t, o, n) {
451
+ return this._sheetsSourceManager.createSource(e, t, o, n);
452
452
  }
453
453
  getSourceBindingPathInfo(e) {
454
454
  return {
@@ -460,7 +460,7 @@ let w = class extends O {
460
460
  this._sheetsSourceManager.fromJSON(e, t.source), this._sheetsBindingManager.fromJSON(e, t.cellBinding);
461
461
  }
462
462
  _ensureRTreeCollection(e) {
463
- return this._bindModelRTreeCollection.has(e) || this._bindModelRTreeCollection.set(e, new Q()), this._bindModelRTreeCollection.get(e);
463
+ return this._bindModelRTreeCollection.has(e) || this._bindModelRTreeCollection.set(e, new K()), this._bindModelRTreeCollection.get(e);
464
464
  }
465
465
  _getRTeeCollection(e) {
466
466
  return this._bindModelRTreeCollection.get(e);
@@ -468,34 +468,34 @@ let w = class extends O {
468
468
  // eslint-disable-next-line max-lines-per-function
469
469
  _registerSourceChange() {
470
470
  this.disposeWithMe(this._sheetsSourceManager.sourceDataUpdate$.subscribe((e) => {
471
- const { sourceId: t, sourceType: n, unitId: s, changeType: o } = e;
472
- if (n === g.List) {
473
- if (o === m.Remove) {
474
- const d = this._sheetsBindingManager.getBindingModelBySourceId(t), c = e.recordCount;
475
- for (const { unitId: a, subunitId: h, nodeId: u, row: p, column: _ } of d) {
476
- const M = this._getRTeeCollection(s), f = this._sheetsBindingManager.getBindingNodeById(a, h, u);
471
+ const { sourceId: t, sourceType: o, unitId: n, changeType: s } = e;
472
+ if (o === g.List) {
473
+ if (s === m.Remove) {
474
+ const a = this._sheetsBindingManager.getBindingModelBySourceId(t), c = e.recordCount;
475
+ for (const { unitId: d, subunitId: h, nodeId: u, row: p, column: _ } of a) {
476
+ const M = this._getRTeeCollection(n), f = this._sheetsBindingManager.getBindingNodeById(d, h, u);
477
477
  if (M && (f == null ? void 0 : f.type) === g.List) {
478
478
  const I = f.containHeader ? 0 : 1, S = { startRow: p, startColumn: _, endRow: p + c - I, endColumn: _ };
479
- M.remove({ unitId: a, sheetId: h, id: u, range: S });
479
+ M.remove({ unitId: d, sheetId: h, id: u, range: S });
480
480
  }
481
481
  }
482
482
  return;
483
483
  }
484
- if (o === m.Update) {
485
- const d = e.oldRecordCount, c = this._sheetsBindingManager.getBindingModelBySourceId(t);
486
- for (const { unitId: a, subunitId: h, nodeId: u, row: p, column: _ } of c) {
487
- const M = this._getRTeeCollection(s), f = this._sheetsBindingManager.getBindingNodeById(a, h, u);
484
+ if (s === m.Update) {
485
+ const a = e.oldRecordCount, c = this._sheetsBindingManager.getBindingModelBySourceId(t);
486
+ for (const { unitId: d, subunitId: h, nodeId: u, row: p, column: _ } of c) {
487
+ const M = this._getRTeeCollection(n), f = this._sheetsBindingManager.getBindingNodeById(d, h, u);
488
488
  if (M && (f == null ? void 0 : f.type) === g.List) {
489
- const I = f.containHeader ? 0 : 1, S = { startRow: p, startColumn: _, endRow: p + d - I, endColumn: _ }, B = { startRow: p, startColumn: _, endRow: p + e.recordCount - I, endColumn: _ };
490
- M.remove({ unitId: a, sheetId: h, id: u, range: S }), M.insert({ unitId: a, sheetId: h, id: u, range: B });
489
+ const I = f.containHeader ? 0 : 1, S = { startRow: p, startColumn: _, endRow: p + a - I, endColumn: _ }, B = { startRow: p, startColumn: _, endRow: p + e.recordCount - I, endColumn: _ };
490
+ M.remove({ unitId: d, sheetId: h, id: u, range: S }), M.insert({ unitId: d, sheetId: h, id: u, range: B });
491
491
  }
492
492
  }
493
493
  return;
494
494
  }
495
- const r = this._sheetsSourceManager.getSource(s, t);
495
+ const r = this._sheetsSourceManager.getSource(n, t);
496
496
  if (r && r.hasData()) {
497
- const c = r.getSourceInfo().recordCount, a = this._sheetsBindingManager.getBindingModelBySourceId(t);
498
- for (const { unitId: h, subunitId: u, nodeId: p, row: _, column: M } of a) {
497
+ const c = r.getSourceInfo().recordCount, d = this._sheetsBindingManager.getBindingModelBySourceId(t);
498
+ for (const { unitId: h, subunitId: u, nodeId: p, row: _, column: M } of d) {
499
499
  const f = this._ensureRTreeCollection(h), I = this._sheetsBindingManager.getBindingNodeById(h, u, p);
500
500
  if (f && (I == null ? void 0 : I.type) === g.List) {
501
501
  const S = I.containHeader ? 0 : 1, B = { startRow: _, startColumn: M, endRow: _ + c - S, endColumn: M };
@@ -505,62 +505,62 @@ let w = class extends O {
505
505
  }
506
506
  }
507
507
  })), this.disposeWithMe(this._sheetsBindingManager.cellBindInfoUpdate$.subscribe((e) => {
508
- const { unitId: t, subunitId: n, sourceId: s, nodeId: o, row: r, column: d, changeType: c, containHeader: a } = e, h = this._ensureRTreeCollection(t), u = this._sheetsSourceManager.getSource(t, s);
508
+ const { unitId: t, subunitId: o, sourceId: n, nodeId: s, row: r, column: a, changeType: c, containHeader: d } = e, h = this._ensureRTreeCollection(t), u = this._sheetsSourceManager.getSource(t, n);
509
509
  if (u && u.hasData()) {
510
510
  const p = u.getSourceInfo();
511
511
  if (p.sourceType === g.List) {
512
- const _ = p.recordCount, M = a ? 0 : 1, f = { startRow: r, startColumn: d, endRow: r + _ - M, endColumn: d };
512
+ const _ = p.recordCount, M = d ? 0 : 1, f = { startRow: r, startColumn: a, endRow: r + _ - M, endColumn: a };
513
513
  if (c === m.Add)
514
- h.insert({ unitId: t, sheetId: n, id: o, range: f });
514
+ h.insert({ unitId: t, sheetId: o, id: s, range: f });
515
515
  else if (c === m.Remove)
516
- h.remove({ unitId: t, sheetId: n, id: o, range: f });
516
+ h.remove({ unitId: t, sheetId: o, id: s, range: f });
517
517
  else if (c === m.Update) {
518
518
  const I = e.oldSourceId, S = e.oldNodeContainHeader ? 0 : 1, B = this._sheetsSourceManager.getSource(t, I);
519
519
  if (B && B.hasData()) {
520
- const G = B.getSourceInfo().recordCount, W = { startRow: r, startColumn: d, endRow: r + G - S, endColumn: d };
521
- h.remove({ unitId: t, sheetId: n, id: o, range: W });
520
+ const k = B.getSourceInfo().recordCount, G = { startRow: r, startColumn: a, endRow: r + k - S, endColumn: a };
521
+ h.remove({ unitId: t, sheetId: o, id: s, range: G });
522
522
  }
523
- h.insert({ unitId: t, sheetId: n, id: o, range: f });
523
+ h.insert({ unitId: t, sheetId: o, id: s, range: f });
524
524
  }
525
525
  }
526
526
  }
527
527
  }));
528
528
  }
529
- _getPathModeCellValue(e, t, n, s) {
530
- const o = this._sheetsBindingManager.getModel(e, t), r = o == null ? void 0 : o.getBindingNode(n, s);
529
+ _getPathModeCellValue(e, t, o, n) {
530
+ const s = this._sheetsBindingManager.getModel(e, t), r = s == null ? void 0 : s.getBindingNode(o, n);
531
531
  if (r) {
532
- const d = r.type;
533
- if (d === g.List)
532
+ const a = r.type;
533
+ if (a === g.List)
534
534
  return {
535
535
  v: `#{${r.path}}`,
536
536
  s: { cl: { rgb: "blue" } }
537
537
  };
538
- if (d === g.Object)
538
+ if (a === g.Object)
539
539
  return {
540
540
  v: `[${r.path}]`,
541
541
  s: { cl: { rgb: "blue" } }
542
542
  };
543
543
  }
544
544
  }
545
- _getValueModeCellValue(e, t, n, s) {
546
- const o = this._sheetsBindingManager.getModel(e, t);
547
- if (o) {
548
- const d = o.getBindingNode(n, s);
549
- if (d) {
550
- const { sourceId: c } = d, a = this._sheetsSourceManager.getSource(e, c);
551
- if (a && a.hasData())
552
- return (a == null ? void 0 : a.getData(d, n, s)) || { v: "" };
545
+ _getValueModeCellValue(e, t, o, n) {
546
+ const s = this._sheetsBindingManager.getModel(e, t);
547
+ if (s) {
548
+ const a = s.getBindingNode(o, n);
549
+ if (a) {
550
+ const { sourceId: c } = a, d = this._sheetsSourceManager.getSource(e, c);
551
+ if (d && d.hasData())
552
+ return (d == null ? void 0 : d.getData(a, o, n)) || { v: "" };
553
553
  }
554
554
  }
555
555
  const r = this._getRTeeCollection(e);
556
- if (o && r) {
557
- const d = { startRow: n, startColumn: s, endRow: n, endColumn: s }, c = Array.from(r.bulkSearch([{ unitId: e, sheetId: t, range: d }]));
556
+ if (s && r) {
557
+ const a = { startRow: o, startColumn: n, endRow: o, endColumn: n }, c = Array.from(r.bulkSearch([{ unitId: e, sheetId: t, range: a }]));
558
558
  if (c.length > 0) {
559
- const a = o.getBindingNodeById(c[0]);
560
- if (a) {
561
- const { sourceId: h } = a, u = this._sheetsSourceManager.getSource(e, h);
559
+ const d = s.getBindingNodeById(c[0]);
560
+ if (d) {
561
+ const { sourceId: h } = d, u = this._sheetsSourceManager.getSource(e, h);
562
562
  if (u && u.hasData())
563
- return (u == null ? void 0 : u.getData(a, n, s)) || { v: "" };
563
+ return (u == null ? void 0 : u.getData(d, o, n)) || { v: "" };
564
564
  }
565
565
  }
566
566
  }
@@ -570,16 +570,16 @@ let w = class extends O {
570
570
  }
571
571
  _registerInterceptor() {
572
572
  this.disposeWithMe(this._sheetInterceptorService.intercept(re.CELL_CONTENT, {
573
- effect: P.Value | P.Style,
573
+ effect: x.Value | x.Style,
574
574
  priority: 102,
575
- handler: (e, t, n) => {
576
- const { row: s, col: o, unitId: r, subUnitId: d, workbook: c } = t;
577
- let a = null;
578
- if (this._bindingModel === y.Path ? a = this._getPathModeCellValue(r, d, s, o) : a = this._getValueModeCellValue(r, d, s, o), a !== null) {
575
+ handler: (e, t, o) => {
576
+ const { row: n, col: s, unitId: r, subUnitId: a, workbook: c } = t;
577
+ let d = null;
578
+ if (this._bindingModel === y.Path ? d = this._getPathModeCellValue(r, a, n, s) : d = this._getValueModeCellValue(r, a, n, s), d !== null) {
579
579
  const u = { ...(typeof (e == null ? void 0 : e.s) == "string" ? c.getStyles().get(e == null ? void 0 : e.s) : e == null ? void 0 : e.s) || {} };
580
- return a && a.s && Object.assign(u, a.s), n({ ...e, ...a, s: u });
580
+ return d && d.s && Object.assign(u, d.s), o({ ...e, ...d, s: u });
581
581
  }
582
- return n(e);
582
+ return o(e);
583
583
  }
584
584
  }));
585
585
  }
@@ -587,17 +587,17 @@ let w = class extends O {
587
587
  this._bindModelRTreeCollection.clear();
588
588
  }
589
589
  };
590
- w = le([
590
+ R = ue([
591
591
  D(0, C(V)),
592
592
  D(1, C(N)),
593
593
  D(2, C(T))
594
- ], w);
595
- var ge = Object.defineProperty, fe = Object.getOwnPropertyDescriptor, pe = (i, e, t, n) => {
596
- for (var s = n > 1 ? void 0 : n ? fe(e, t) : e, o = i.length - 1, r; o >= 0; o--)
597
- (r = i[o]) && (s = (n ? r(e, t, s) : r(s)) || s);
598
- return n && s && ge(e, t, s), s;
599
- }, j = (i, e) => (t, n) => e(t, n, i), b;
600
- let L = (b = class extends X {
594
+ ], R);
595
+ var he = Object.getOwnPropertyDescriptor, le = (i, e, t, o) => {
596
+ for (var n = o > 1 ? void 0 : o ? he(e, t) : e, s = i.length - 1, r; s >= 0; s--)
597
+ (r = i[s]) && (n = r(n) || n);
598
+ return n;
599
+ }, j = (i, e) => (t, o) => e(t, o, i), w;
600
+ let L = (w = class extends Q {
601
601
  constructor(i = {}, e, t) {
602
602
  super(), this._config = i, this._injector = e, this._configService = t;
603
603
  }
@@ -605,26 +605,26 @@ let L = (b = class extends X {
605
605
  [
606
606
  [N],
607
607
  [T],
608
- [w]
608
+ [R]
609
609
  ].forEach((i) => this._injector.add(i));
610
610
  }
611
611
  onReady() {
612
- Z(this._injector, [
612
+ Y(this._injector, [
613
613
  [N],
614
614
  [T],
615
- [w]
615
+ [R]
616
616
  ]);
617
617
  }
618
- }, l(b, "type", Y.UNIVER_SHEET), l(b, "pluginName", "SHEET_BINDING_SOURCE_PLUGIN"), b);
619
- L = pe([
620
- j(1, C(k)),
618
+ }, l(w, "type", X.UNIVER_SHEET), l(w, "pluginName", "SHEET_BINDING_SOURCE_PLUGIN"), w);
619
+ L = le([
620
+ j(1, C(Z)),
621
621
  j(2, ee)
622
622
  ], L);
623
623
  export {
624
624
  y as BindModeEnum,
625
625
  $ as BindingModel,
626
626
  g as DataBindingNodeTypeEnum,
627
- w as SheetsSourceBindService,
627
+ R as SheetsSourceBindService,
628
628
  T as SheetsSourceManager,
629
629
  U as SourceModelBase,
630
630
  L as UniverSheetsBindingSourcePlugin
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(h,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs"],a):(h=typeof globalThis<"u"?globalThis:h||self,a(h.UniverSheetsSourceBinding={},h.UniverCore,h.UniverSheets,h.rxjs))})(this,function(h,a,I,P){"use strict";var Y=Object.defineProperty;var Z=(h,a,I)=>a in h?Y(h,a,{enumerable:!0,configurable:!0,writable:!0,value:I}):h[a]=I;var g=(h,a,I)=>Z(h,typeof a!="symbol"?a+"":a,I);var D;class U{constructor(o){g(this,"_matrix",{});g(this,"_nodeMap",new Map);g(this,"_sourceIdMap",new Map);o&&this._init(o)}_init(o){this.fromJSON(o)}getBindingNodesBySourceId(o){const e=this._sourceIdMap.get(o);if(e)return e.map(t=>this._nodeMap.get(t))}setBindingNode(o,e,t){this._matrix[o]||(this._matrix[o]={}),this._matrix[o][e]||(this._matrix[o][e]=t),this._nodeMap.set(t.nodeId,t);const n=this._sourceIdMap.get(t.sourceId);n?n.push(t.nodeId):this._sourceIdMap.set(t.sourceId,[t.nodeId])}getBindingNode(o,e){var t;return(t=this._matrix[o])==null?void 0:t[e]}removeBindingNode(o,e){var n;const t=(n=this._matrix[o])==null?void 0:n[e];if(t){this._matrix[o][e]=void 0,this._nodeMap.delete(t.nodeId);const s=this._sourceIdMap.get(t.sourceId);if(s){const i=s.indexOf(t.nodeId);i>=0&&s.splice(i,1),s.length===0&&this._sourceIdMap.delete(t.sourceId)}}}getBindingNodeById(o){return this._nodeMap.get(o)}fromJSON(o){o.forEach(e=>{this.setBindingNode(e.row,e.column,e)})}toJSON(){return Array.from(this._nodeMap.values())}}var _=(d=>(d.List="list",d.Object="object",d))(_||{}),b=(d=>(d.Path="path",d.Value="value",d))(b||{}),B=(d=>(d.Add="add",d.Remove="remove",d.Update="update",d))(B||{});function x(d){return d instanceof Date&&!isNaN(d.getTime())}function E(d){const o=new Date(d);if(!x(o))return d;const e=new Date(Date.UTC(1900,0,1,0,0,0)),t=new Date(Date.UTC(1900,1,28,0,0,0));let s=(o.getTime()-e.getTime())/(1e3*3600*24);return o>t&&(s+=1),s+1}class w{constructor(o){g(this,"_data");g(this,"id");g(this,"_hasData",!1);g(this,"type");this.id=o}getId(){return this.id}getType(){return this.type}hasData(){return this._hasData}setSourceData(o){this._data=o,this._hasData=!0}toJSON(){return{id:this.id,type:this.type}}fromJSON(o){this.id=o.id,this.type=o.type}}class $ extends w{constructor(e,t){super(e);g(this,"type",_.List);g(this,"_isListObject");g(this,"_fieldIndexMap",new Map);g(this,"_data",{fields:[],records:[]});this._isListObject=t!=null?t:!0}toggleListObject(e){this._isListObject=e}getData(e,t){const{path:n,row:s,containHeader:i}=e,r=this._fieldIndexMap.get(n),c=t-s;if(i&&c===0)return{v:this._data.fields[r]};let l;const u=i?1:0;if(this._isListObject?l=this._data.records[c-u][n]:l=this._data.records[c-u][r],e.isDate===!0){const p=e.formatter||"yyyy-m-d am/pm h:mm";return{v:E(l),s:{n:{pattern:p}},t:a.CellValueType.NUMBER}}else return e.formatter?{v:l,s:{n:{pattern:e.formatter}}}:{t:typeof l=="number"?a.CellValueType.NUMBER:a.CellValueType.STRING,v:l}}setSourceData(e){super.setSourceData(e);const{fields:t}=e;this._fieldIndexMap.clear(),t.forEach((n,s)=>{this._fieldIndexMap.set(n,s)})}getSourceInfo(){return{sourceId:this.id,sourceType:this.type,fields:this._data.fields,recordCount:this._data.records.length}}}class V extends w{constructor(e){super(e);g(this,"type",_.Object)}getData(e){const n=e.path.split(".");let s=this._data;for(const i of n)if(s=s[i],s===void 0)return null;if(e.isDate===!0){const i=e.formatter||"yyyy-m-d am/pm h:mm";return{v:E(s),s:{n:{pattern:i}},t:a.CellValueType.NUMBER}}else return e.formatter?{v:s,s:{n:{pattern:e.formatter}}}:{v:s,t:typeof s=="number"?a.CellValueType.NUMBER:a.CellValueType.STRING}}getSourceInfo(){return{sourceId:this.id,sourceType:_.Object}}}var J=Object.defineProperty,H=Object.getOwnPropertyDescriptor,A=(d,o,e,t)=>{for(var n=t>1?void 0:t?H(o,e):o,s=d.length-1,i;s>=0;s--)(i=d[s])&&(n=(t?i(o,e,n):i(n))||n);return t&&n&&J(o,e,n),n},O=(d,o)=>(e,t)=>o(e,t,d);let R=class extends a.Disposable{constructor(o,e,t){super();g(this,"modelMap",new Map);g(this,"_cellBindInfoUpdate$",new P.Subject);g(this,"cellBindInfoUpdate$",this._cellBindInfoUpdate$.asObservable());this._univerInstanceService=o,this._sheetInterceptorService=e,this._sheetsSelectionsService=t,this._initRemoveCommand()}_initRemoveCommand(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:o=>{const e=[],t=[],n=this._sheetsSelectionsService.getCurrentSelections(),s=I.getSheetCommandTarget(this._univerInstanceService);if(!s||!n||n.length===0)return{redos:[],undos:[]};const{unitId:i,subUnitId:r}=s;return(o.id===I.ClearSelectionContentCommand.id||o.id===I.ClearSelectionAllCommand.id)&&n.forEach(({range:c})=>{a.Range.foreach(c,(l,u)=>{this.getBindingNode(i,r,l,u)&&this.removeBindingNode(i,r,l,u)})}),{redos:e,undos:t}}}))}getBindingModelBySourceId(o){const e=[];return this.modelMap.forEach((t,n)=>{t.forEach((s,i)=>{const r=s.getBindingNodesBySourceId(o);if(r)for(const c of r)e.push({unitId:n,subunitId:i,sourceId:o,nodeId:c.nodeId,row:c.row,column:c.column})})}),e}addModel(o,e,t){var n;this.modelMap.has(o)||this.modelMap.set(o,new Map),(n=this.modelMap.get(o))==null||n.set(e,t)}getModel(o,e){var t;return(t=this.modelMap.get(o))==null?void 0:t.get(e)}setBindingNode(o,e,t){let n=this.getModel(o,e);n||(n=new U,this.addModel(o,e,n)),t.nodeId||(t.nodeId=a.generateRandomId());const{row:s,column:i}=t;if(s===void 0||i===void 0)throw new Error("row and column is required");const r=n.getBindingNode(s,i),c=t.type===_.List?!!t.containHeader:!1;n.setBindingNode(s,i,{...t,row:s,column:i}),this._cellBindInfoUpdate$.next({unitId:o,subunitId:e,sourceId:t.sourceId,nodeId:t.nodeId,row:s,column:i,containHeader:c,changeType:r?B.Update:B.Add,oldSourceId:r==null?void 0:r.sourceId,oldNodeContainHeader:(r==null?void 0:r.type)===_.List?!!r.containHeader:!1})}removeBindingNode(o,e,t,n){const s=this.getModel(o,e);if(s){const i=s.getBindingNode(t,n);i&&(s.removeBindingNode(t,n),this._cellBindInfoUpdate$.next({unitId:o,subunitId:e,sourceId:i.sourceId,nodeId:i.nodeId,row:t,column:n,changeType:B.Remove}))}}getBindingNode(o,e,t,n){const s=this.getModel(o,e);if(s)return s.getBindingNode(t,n)}getBindingNodeById(o,e,t){const n=this.getModel(o,e);if(n)return n.getBindingNodeById(t)}createModel(o,e,t){const n=new U(t);return this.addModel(o,e,n),n}toJSON(o){const e={},t=this.modelMap.get(o);return t&&t.forEach((n,s)=>{e[s]=n.toJSON()}),e}fromJSON(o,e){Object.entries(e).forEach(([t,n])=>{this.createModel(o,t,n)})}dispose(){this.modelMap.clear(),this._cellBindInfoUpdate$.complete()}};R=A([O(0,a.IUniverInstanceService),O(1,a.Inject(I.SheetInterceptorService)),O(2,a.Inject(I.SheetsSelectionsService))],R);class T extends a.Disposable{constructor(){super();g(this,"sourceMap",new Map);g(this,"_sourceDataUpdate$",new P.Subject);g(this,"sourceDataUpdate$",this._sourceDataUpdate$.asObservable())}_ensureUnitMap(e){let t=this.sourceMap.get(e);return t||(t=new Map,this.sourceMap.set(e,t)),t}_getUnitMap(e){return this.sourceMap.get(e)}getSource(e,t){const n=this._getUnitMap(e);return n==null?void 0:n.get(t)}createSource(e,t,n,s){const i=s===void 0?a.generateRandomId():s;let r;switch(t){case _.List:r=new $(i,n);break;case _.Object:r=new V(i);break;default:throw new Error(`Invalid source type: ${t}`)}return this._ensureUnitMap(e).set(i,r),r}updateSourceData(e,t,n){const s=this._getUnitMap(e),i=t instanceof w?t.getId():t,r=s==null?void 0:s.get(i);if(r)r.setSourceData(n),this._sourceDataUpdate$.next({...r.getSourceInfo(),unitId:e,changeType:B.Add});else throw new Error(`Source not found: ${i}`)}removeSource(e,t){const n=this._getUnitMap(e),s=n==null?void 0:n.get(t);s&&(n==null||n.delete(t),this._sourceDataUpdate$.next({...s.getSourceInfo(),unitId:e,changeType:B.Remove}))}toJSON(e){const t=[],n=this._getUnitMap(e);if(n)for(const s of n.values())t.push(s.toJSON());return t}fromJSON(e,t){const n=this._ensureUnitMap(e);for(const s of t){let i;switch(s.type){case _.List:i=new $(s.id);break;case _.Object:i=new V(s.id);break;default:throw new Error(`Invalid source type: ${s.type}`)}i.fromJSON(s),n.set(s.id,i)}}dispose(){this._sourceDataUpdate$.complete(),this.sourceMap.clear()}}var q=Object.defineProperty,G=Object.getOwnPropertyDescriptor,W=(d,o,e,t)=>{for(var n=t>1?void 0:t?G(o,e):o,s=d.length-1,i;s>=0;s--)(i=d[s])&&(n=(t?i(o,e,n):i(n))||n);return t&&n&&q(o,e,n),n},j=(d,o)=>(e,t)=>o(e,t,d);h.SheetsSourceBindService=class extends a.Disposable{constructor(e,t,n){super();g(this,"_bindingModel",b.Value);g(this,"_bindModelRTreeCollection",new Map);this._sheetInterceptorService=e,this._sheetsBindingManager=t,this._sheetsSourceManager=n,this._registerInterceptor(),this._registerSourceChange()}usePathMode(){this._bindingModel=b.Path}useValueMode(){this._bindingModel=b.Value}getBindingModel(){return this._bindingModel}createBindModel(e,t){return this._sheetsBindingManager.createModel(e,t)}setBindingNode(e,t,n){this._sheetsBindingManager.setBindingNode(e,t,n)}removeBindingNode(e,t,n,s){this._sheetsBindingManager.removeBindingNode(e,t,n,s)}getBindingNode(e,t,n,s){return this._sheetsBindingManager.getBindingNode(e,t,n,s)}getSource(e,t){return this._sheetsSourceManager.getSource(e,t)}createSource(e,t,n,s){return this._sheetsSourceManager.createSource(e,t,n,s)}getSourceBindingPathInfo(e){return{source:this._sheetsSourceManager.toJSON(e),cellBinding:this._sheetsBindingManager.toJSON(e)}}loadSourceBindingPathInfo(e,t){this._sheetsSourceManager.fromJSON(e,t.source),this._sheetsBindingManager.fromJSON(e,t.cellBinding)}_ensureRTreeCollection(e){return this._bindModelRTreeCollection.has(e)||this._bindModelRTreeCollection.set(e,new a.RTree),this._bindModelRTreeCollection.get(e)}_getRTeeCollection(e){return this._bindModelRTreeCollection.get(e)}_registerSourceChange(){this.disposeWithMe(this._sheetsSourceManager.sourceDataUpdate$.subscribe(e=>{const{sourceId:t,sourceType:n,unitId:s,changeType:i}=e;if(n===_.List){if(i===B.Remove){const c=this._sheetsBindingManager.getBindingModelBySourceId(t),l=e.recordCount;for(const{unitId:u,subunitId:p,nodeId:f,row:M,column:m}of c){const v=this._getRTeeCollection(s),S=this._sheetsBindingManager.getBindingNodeById(u,p,f);if(v&&(S==null?void 0:S.type)===_.List){const y=S.containHeader?0:1,C={startRow:M,startColumn:m,endRow:M+l-y,endColumn:m};v.remove({unitId:u,sheetId:p,id:f,range:C})}}return}if(i===B.Update){const c=e.oldRecordCount,l=this._sheetsBindingManager.getBindingModelBySourceId(t);for(const{unitId:u,subunitId:p,nodeId:f,row:M,column:m}of l){const v=this._getRTeeCollection(s),S=this._sheetsBindingManager.getBindingNodeById(u,p,f);if(v&&(S==null?void 0:S.type)===_.List){const y=S.containHeader?0:1,C={startRow:M,startColumn:m,endRow:M+c-y,endColumn:m},N={startRow:M,startColumn:m,endRow:M+e.recordCount-y,endColumn:m};v.remove({unitId:u,sheetId:p,id:f,range:C}),v.insert({unitId:u,sheetId:p,id:f,range:N})}}return}const r=this._sheetsSourceManager.getSource(s,t);if(r&&r.hasData()){const l=r.getSourceInfo().recordCount,u=this._sheetsBindingManager.getBindingModelBySourceId(t);for(const{unitId:p,subunitId:f,nodeId:M,row:m,column:v}of u){const S=this._ensureRTreeCollection(p),y=this._sheetsBindingManager.getBindingNodeById(p,f,M);if(S&&(y==null?void 0:y.type)===_.List){const C=y.containHeader?0:1,N={startRow:m,startColumn:v,endRow:m+l-C,endColumn:v};S.insert({unitId:p,sheetId:f,id:M,range:N})}}}}})),this.disposeWithMe(this._sheetsBindingManager.cellBindInfoUpdate$.subscribe(e=>{const{unitId:t,subunitId:n,sourceId:s,nodeId:i,row:r,column:c,changeType:l,containHeader:u}=e,p=this._ensureRTreeCollection(t),f=this._sheetsSourceManager.getSource(t,s);if(f&&f.hasData()){const M=f.getSourceInfo();if(M.sourceType===_.List){const m=M.recordCount,v=u?0:1,S={startRow:r,startColumn:c,endRow:r+m-v,endColumn:c};if(l===B.Add)p.insert({unitId:t,sheetId:n,id:i,range:S});else if(l===B.Remove)p.remove({unitId:t,sheetId:n,id:i,range:S});else if(l===B.Update){const y=e.oldSourceId,C=e.oldNodeContainHeader?0:1,N=this._sheetsSourceManager.getSource(t,y);if(N&&N.hasData()){const Q=N.getSourceInfo().recordCount,X={startRow:r,startColumn:c,endRow:r+Q-C,endColumn:c};p.remove({unitId:t,sheetId:n,id:i,range:X})}p.insert({unitId:t,sheetId:n,id:i,range:S})}}}}))}_getPathModeCellValue(e,t,n,s){const i=this._sheetsBindingManager.getModel(e,t),r=i==null?void 0:i.getBindingNode(n,s);if(r){const c=r.type;if(c===_.List)return{v:`#{${r.path}}`,s:{cl:{rgb:"blue"}}};if(c===_.Object)return{v:`[${r.path}]`,s:{cl:{rgb:"blue"}}}}}_getValueModeCellValue(e,t,n,s){const i=this._sheetsBindingManager.getModel(e,t);if(i){const c=i.getBindingNode(n,s);if(c){const{sourceId:l}=c,u=this._sheetsSourceManager.getSource(e,l);if(u&&u.hasData())return(u==null?void 0:u.getData(c,n,s))||{v:""}}}const r=this._getRTeeCollection(e);if(i&&r){const c={startRow:n,startColumn:s,endRow:n,endColumn:s},l=Array.from(r.bulkSearch([{unitId:e,sheetId:t,range:c}]));if(l.length>0){const u=i.getBindingNodeById(l[0]);if(u){const{sourceId:p}=u,f=this._sheetsSourceManager.getSource(e,p);if(f&&f.hasData())return(f==null?void 0:f.getData(u,n,s))||{v:""}}}}}getBindingModelBySourceId(e){return this._sheetsBindingManager.getBindingModelBySourceId(e)}_registerInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(I.INTERCEPTOR_POINT.CELL_CONTENT,{effect:a.InterceptorEffectEnum.Value|a.InterceptorEffectEnum.Style,priority:102,handler:(e,t,n)=>{const{row:s,col:i,unitId:r,subUnitId:c,workbook:l}=t;let u=null;if(this._bindingModel===b.Path?u=this._getPathModeCellValue(r,c,s,i):u=this._getValueModeCellValue(r,c,s,i),u!==null){const f={...(typeof(e==null?void 0:e.s)=="string"?l.getStyles().get(e==null?void 0:e.s):e==null?void 0:e.s)||{}};return u&&u.s&&Object.assign(f,u.s),n({...e,...u,s:f})}return n(e)}}))}dispose(){this._bindModelRTreeCollection.clear()}},h.SheetsSourceBindService=W([j(0,a.Inject(I.SheetInterceptorService)),j(1,a.Inject(R)),j(2,a.Inject(T))],h.SheetsSourceBindService);var z=Object.defineProperty,F=Object.getOwnPropertyDescriptor,K=(d,o,e,t)=>{for(var n=t>1?void 0:t?F(o,e):o,s=d.length-1,i;s>=0;s--)(i=d[s])&&(n=(t?i(o,e,n):i(n))||n);return t&&n&&z(o,e,n),n},L=(d,o)=>(e,t)=>o(e,t,d);h.UniverSheetsBindingSourcePlugin=(D=class extends a.Plugin{constructor(o={},e,t){super(),this._config=o,this._injector=e,this._configService=t}onStarting(){[[R],[T],[h.SheetsSourceBindService]].forEach(o=>this._injector.add(o))}onReady(){a.touchDependencies(this._injector,[[R],[T],[h.SheetsSourceBindService]])}},g(D,"type",a.UniverInstanceType.UNIVER_SHEET),g(D,"pluginName","SHEET_BINDING_SOURCE_PLUGIN"),D),h.UniverSheetsBindingSourcePlugin=K([L(1,a.Inject(a.Injector)),L(2,a.IConfigService)],h.UniverSheetsBindingSourcePlugin),h.BindModeEnum=b,h.BindingModel=U,h.DataBindingNodeTypeEnum=_,h.SheetsSourceManager=T,h.SourceModelBase=w,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
1
+ (function(h,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs"],a):(h=typeof globalThis<"u"?globalThis:h||self,a(h.UniverSheetsSourceBinding={},h.UniverCore,h.UniverSheets,h.rxjs))})(this,function(h,a,I,E){"use strict";var F=Object.defineProperty;var K=(h,a,I)=>a in h?F(h,a,{enumerable:!0,configurable:!0,writable:!0,value:I}):h[a]=I;var g=(h,a,I)=>K(h,typeof a!="symbol"?a+"":a,I);var D;class U{constructor(o){g(this,"_matrix",{});g(this,"_nodeMap",new Map);g(this,"_sourceIdMap",new Map);o&&this._init(o)}_init(o){this.fromJSON(o)}getBindingNodesBySourceId(o){const e=this._sourceIdMap.get(o);if(e)return e.map(t=>this._nodeMap.get(t))}setBindingNode(o,e,t){this._matrix[o]||(this._matrix[o]={}),this._matrix[o][e]||(this._matrix[o][e]=t),this._nodeMap.set(t.nodeId,t);const n=this._sourceIdMap.get(t.sourceId);n?n.push(t.nodeId):this._sourceIdMap.set(t.sourceId,[t.nodeId])}getBindingNode(o,e){var t;return(t=this._matrix[o])==null?void 0:t[e]}removeBindingNode(o,e){var n;const t=(n=this._matrix[o])==null?void 0:n[e];if(t){this._matrix[o][e]=void 0,this._nodeMap.delete(t.nodeId);const s=this._sourceIdMap.get(t.sourceId);if(s){const i=s.indexOf(t.nodeId);i>=0&&s.splice(i,1),s.length===0&&this._sourceIdMap.delete(t.sourceId)}}}getBindingNodeById(o){return this._nodeMap.get(o)}fromJSON(o){o.forEach(e=>{this.setBindingNode(e.row,e.column,e)})}toJSON(){return Array.from(this._nodeMap.values())}}var _=(d=>(d.List="list",d.Object="object",d))(_||{}),R=(d=>(d.Path="path",d.Value="value",d))(R||{}),v=(d=>(d.Add="add",d.Remove="remove",d.Update="update",d))(v||{});function x(d){return d instanceof Date&&!isNaN(d.getTime())}function P(d){const o=new Date(d);if(!x(o))return d;const e=new Date(Date.UTC(1900,0,1,0,0,0)),t=new Date(Date.UTC(1900,1,28,0,0,0));let s=(o.getTime()-e.getTime())/(1e3*3600*24);return o>t&&(s+=1),s+1}class w{constructor(o){g(this,"_data");g(this,"id");g(this,"_hasData",!1);g(this,"type");this.id=o}getId(){return this.id}getType(){return this.type}hasData(){return this._hasData}setSourceData(o){this._data=o,this._hasData=!0}toJSON(){return{id:this.id,type:this.type}}fromJSON(o){this.id=o.id,this.type=o.type}}class $ extends w{constructor(e,t){super(e);g(this,"type",_.List);g(this,"_isListObject");g(this,"_fieldIndexMap",new Map);g(this,"_data",{fields:[],records:[]});this._isListObject=t!=null?t:!0}toggleListObject(e){this._isListObject=e}getData(e,t){const{path:n,row:s,containHeader:i}=e,r=this._fieldIndexMap.get(n),c=t-s;if(i&&c===0)return{v:this._data.fields[r]};let l;const u=i?1:0;if(this._isListObject?l=this._data.records[c-u][n]:l=this._data.records[c-u][r],e.isDate===!0){const p=e.formatter||"yyyy-m-d am/pm h:mm";return{v:P(l),s:{n:{pattern:p}},t:a.CellValueType.NUMBER}}else return e.formatter?{v:l,s:{n:{pattern:e.formatter}}}:{t:typeof l=="number"?a.CellValueType.NUMBER:a.CellValueType.STRING,v:l}}setSourceData(e){super.setSourceData(e);const{fields:t}=e;this._fieldIndexMap.clear(),t.forEach((n,s)=>{this._fieldIndexMap.set(n,s)})}getSourceInfo(){return{sourceId:this.id,sourceType:this.type,fields:this._data.fields,recordCount:this._data.records.length}}}class V extends w{constructor(e){super(e);g(this,"type",_.Object)}getData(e){const n=e.path.split(".");let s=this._data;for(const i of n)if(s=s[i],s===void 0)return null;if(e.isDate===!0){const i=e.formatter||"yyyy-m-d am/pm h:mm";return{v:P(s),s:{n:{pattern:i}},t:a.CellValueType.NUMBER}}else return e.formatter?{v:s,s:{n:{pattern:e.formatter}}}:{v:s,t:typeof s=="number"?a.CellValueType.NUMBER:a.CellValueType.STRING}}getSourceInfo(){return{sourceId:this.id,sourceType:_.Object}}}var J=Object.getOwnPropertyDescriptor,H=(d,o,e,t)=>{for(var n=t>1?void 0:t?J(o,e):o,s=d.length-1,i;s>=0;s--)(i=d[s])&&(n=i(n)||n);return n},O=(d,o)=>(e,t)=>o(e,t,d);let b=class extends a.Disposable{constructor(o,e,t){super();g(this,"modelMap",new Map);g(this,"_cellBindInfoUpdate$",new E.Subject);g(this,"cellBindInfoUpdate$",this._cellBindInfoUpdate$.asObservable());this._univerInstanceService=o,this._sheetInterceptorService=e,this._sheetsSelectionsService=t,this._initRemoveCommand()}_initRemoveCommand(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:o=>{const e=[],t=[],n=this._sheetsSelectionsService.getCurrentSelections(),s=I.getSheetCommandTarget(this._univerInstanceService);if(!s||!n||n.length===0)return{redos:[],undos:[]};const{unitId:i,subUnitId:r}=s;return(o.id===I.ClearSelectionContentCommand.id||o.id===I.ClearSelectionAllCommand.id)&&n.forEach(({range:c})=>{a.Range.foreach(c,(l,u)=>{this.getBindingNode(i,r,l,u)&&this.removeBindingNode(i,r,l,u)})}),{redos:e,undos:t}}}))}getBindingModelBySourceId(o){const e=[];return this.modelMap.forEach((t,n)=>{t.forEach((s,i)=>{const r=s.getBindingNodesBySourceId(o);if(r)for(const c of r)e.push({unitId:n,subunitId:i,sourceId:o,nodeId:c.nodeId,row:c.row,column:c.column})})}),e}addModel(o,e,t){var n;this.modelMap.has(o)||this.modelMap.set(o,new Map),(n=this.modelMap.get(o))==null||n.set(e,t)}getModel(o,e){var t;return(t=this.modelMap.get(o))==null?void 0:t.get(e)}setBindingNode(o,e,t){let n=this.getModel(o,e);n||(n=new U,this.addModel(o,e,n)),t.nodeId||(t.nodeId=a.generateRandomId());const{row:s,column:i}=t;if(s===void 0||i===void 0)throw new Error("row and column is required");const r=n.getBindingNode(s,i),c=t.type===_.List?!!t.containHeader:!1;n.setBindingNode(s,i,{...t,row:s,column:i}),this._cellBindInfoUpdate$.next({unitId:o,subunitId:e,sourceId:t.sourceId,nodeId:t.nodeId,row:s,column:i,containHeader:c,changeType:r?v.Update:v.Add,oldSourceId:r==null?void 0:r.sourceId,oldNodeContainHeader:(r==null?void 0:r.type)===_.List?!!r.containHeader:!1})}removeBindingNode(o,e,t,n){const s=this.getModel(o,e);if(s){const i=s.getBindingNode(t,n);i&&(s.removeBindingNode(t,n),this._cellBindInfoUpdate$.next({unitId:o,subunitId:e,sourceId:i.sourceId,nodeId:i.nodeId,row:t,column:n,changeType:v.Remove}))}}getBindingNode(o,e,t,n){const s=this.getModel(o,e);if(s)return s.getBindingNode(t,n)}getBindingNodeById(o,e,t){const n=this.getModel(o,e);if(n)return n.getBindingNodeById(t)}createModel(o,e,t){const n=new U(t);return this.addModel(o,e,n),n}toJSON(o){const e={},t=this.modelMap.get(o);return t&&t.forEach((n,s)=>{e[s]=n.toJSON()}),e}fromJSON(o,e){Object.entries(e).forEach(([t,n])=>{this.createModel(o,t,n)})}dispose(){this.modelMap.clear(),this._cellBindInfoUpdate$.complete()}};b=H([O(0,a.IUniverInstanceService),O(1,a.Inject(I.SheetInterceptorService)),O(2,a.Inject(I.SheetsSelectionsService))],b);class T extends a.Disposable{constructor(){super();g(this,"sourceMap",new Map);g(this,"_sourceDataUpdate$",new E.Subject);g(this,"sourceDataUpdate$",this._sourceDataUpdate$.asObservable())}_ensureUnitMap(e){let t=this.sourceMap.get(e);return t||(t=new Map,this.sourceMap.set(e,t)),t}_getUnitMap(e){return this.sourceMap.get(e)}getSource(e,t){const n=this._getUnitMap(e);return n==null?void 0:n.get(t)}createSource(e,t,n,s){const i=s===void 0?a.generateRandomId():s;let r;switch(t){case _.List:r=new $(i,n);break;case _.Object:r=new V(i);break;default:throw new Error(`Invalid source type: ${t}`)}return this._ensureUnitMap(e).set(i,r),r}updateSourceData(e,t,n){const s=this._getUnitMap(e),i=t instanceof w?t.getId():t,r=s==null?void 0:s.get(i);if(r)r.setSourceData(n),this._sourceDataUpdate$.next({...r.getSourceInfo(),unitId:e,changeType:v.Add});else throw new Error(`Source not found: ${i}`)}removeSource(e,t){const n=this._getUnitMap(e),s=n==null?void 0:n.get(t);s&&(n==null||n.delete(t),this._sourceDataUpdate$.next({...s.getSourceInfo(),unitId:e,changeType:v.Remove}))}toJSON(e){const t=[],n=this._getUnitMap(e);if(n)for(const s of n.values())t.push(s.toJSON());return t}fromJSON(e,t){const n=this._ensureUnitMap(e);for(const s of t){let i;switch(s.type){case _.List:i=new $(s.id);break;case _.Object:i=new V(s.id);break;default:throw new Error(`Invalid source type: ${s.type}`)}i.fromJSON(s),n.set(s.id,i)}}dispose(){this._sourceDataUpdate$.complete(),this.sourceMap.clear()}}var A=Object.getOwnPropertyDescriptor,k=(d,o,e,t)=>{for(var n=t>1?void 0:t?A(o,e):o,s=d.length-1,i;s>=0;s--)(i=d[s])&&(n=i(n)||n);return n},j=(d,o)=>(e,t)=>o(e,t,d);h.SheetsSourceBindService=class extends a.Disposable{constructor(e,t,n){super();g(this,"_bindingModel",R.Value);g(this,"_bindModelRTreeCollection",new Map);this._sheetInterceptorService=e,this._sheetsBindingManager=t,this._sheetsSourceManager=n,this._registerInterceptor(),this._registerSourceChange()}usePathMode(){this._bindingModel=R.Path}useValueMode(){this._bindingModel=R.Value}getBindingModel(){return this._bindingModel}createBindModel(e,t){return this._sheetsBindingManager.createModel(e,t)}setBindingNode(e,t,n){this._sheetsBindingManager.setBindingNode(e,t,n)}removeBindingNode(e,t,n,s){this._sheetsBindingManager.removeBindingNode(e,t,n,s)}getBindingNode(e,t,n,s){return this._sheetsBindingManager.getBindingNode(e,t,n,s)}getSource(e,t){return this._sheetsSourceManager.getSource(e,t)}createSource(e,t,n,s){return this._sheetsSourceManager.createSource(e,t,n,s)}getSourceBindingPathInfo(e){return{source:this._sheetsSourceManager.toJSON(e),cellBinding:this._sheetsBindingManager.toJSON(e)}}loadSourceBindingPathInfo(e,t){this._sheetsSourceManager.fromJSON(e,t.source),this._sheetsBindingManager.fromJSON(e,t.cellBinding)}_ensureRTreeCollection(e){return this._bindModelRTreeCollection.has(e)||this._bindModelRTreeCollection.set(e,new a.RTree),this._bindModelRTreeCollection.get(e)}_getRTeeCollection(e){return this._bindModelRTreeCollection.get(e)}_registerSourceChange(){this.disposeWithMe(this._sheetsSourceManager.sourceDataUpdate$.subscribe(e=>{const{sourceId:t,sourceType:n,unitId:s,changeType:i}=e;if(n===_.List){if(i===v.Remove){const c=this._sheetsBindingManager.getBindingModelBySourceId(t),l=e.recordCount;for(const{unitId:u,subunitId:p,nodeId:f,row:M,column:m}of c){const B=this._getRTeeCollection(s),S=this._sheetsBindingManager.getBindingNodeById(u,p,f);if(B&&(S==null?void 0:S.type)===_.List){const y=S.containHeader?0:1,C={startRow:M,startColumn:m,endRow:M+l-y,endColumn:m};B.remove({unitId:u,sheetId:p,id:f,range:C})}}return}if(i===v.Update){const c=e.oldRecordCount,l=this._sheetsBindingManager.getBindingModelBySourceId(t);for(const{unitId:u,subunitId:p,nodeId:f,row:M,column:m}of l){const B=this._getRTeeCollection(s),S=this._sheetsBindingManager.getBindingNodeById(u,p,f);if(B&&(S==null?void 0:S.type)===_.List){const y=S.containHeader?0:1,C={startRow:M,startColumn:m,endRow:M+c-y,endColumn:m},N={startRow:M,startColumn:m,endRow:M+e.recordCount-y,endColumn:m};B.remove({unitId:u,sheetId:p,id:f,range:C}),B.insert({unitId:u,sheetId:p,id:f,range:N})}}return}const r=this._sheetsSourceManager.getSource(s,t);if(r&&r.hasData()){const l=r.getSourceInfo().recordCount,u=this._sheetsBindingManager.getBindingModelBySourceId(t);for(const{unitId:p,subunitId:f,nodeId:M,row:m,column:B}of u){const S=this._ensureRTreeCollection(p),y=this._sheetsBindingManager.getBindingNodeById(p,f,M);if(S&&(y==null?void 0:y.type)===_.List){const C=y.containHeader?0:1,N={startRow:m,startColumn:B,endRow:m+l-C,endColumn:B};S.insert({unitId:p,sheetId:f,id:M,range:N})}}}}})),this.disposeWithMe(this._sheetsBindingManager.cellBindInfoUpdate$.subscribe(e=>{const{unitId:t,subunitId:n,sourceId:s,nodeId:i,row:r,column:c,changeType:l,containHeader:u}=e,p=this._ensureRTreeCollection(t),f=this._sheetsSourceManager.getSource(t,s);if(f&&f.hasData()){const M=f.getSourceInfo();if(M.sourceType===_.List){const m=M.recordCount,B=u?0:1,S={startRow:r,startColumn:c,endRow:r+m-B,endColumn:c};if(l===v.Add)p.insert({unitId:t,sheetId:n,id:i,range:S});else if(l===v.Remove)p.remove({unitId:t,sheetId:n,id:i,range:S});else if(l===v.Update){const y=e.oldSourceId,C=e.oldNodeContainHeader?0:1,N=this._sheetsSourceManager.getSource(t,y);if(N&&N.hasData()){const W=N.getSourceInfo().recordCount,z={startRow:r,startColumn:c,endRow:r+W-C,endColumn:c};p.remove({unitId:t,sheetId:n,id:i,range:z})}p.insert({unitId:t,sheetId:n,id:i,range:S})}}}}))}_getPathModeCellValue(e,t,n,s){const i=this._sheetsBindingManager.getModel(e,t),r=i==null?void 0:i.getBindingNode(n,s);if(r){const c=r.type;if(c===_.List)return{v:`#{${r.path}}`,s:{cl:{rgb:"blue"}}};if(c===_.Object)return{v:`[${r.path}]`,s:{cl:{rgb:"blue"}}}}}_getValueModeCellValue(e,t,n,s){const i=this._sheetsBindingManager.getModel(e,t);if(i){const c=i.getBindingNode(n,s);if(c){const{sourceId:l}=c,u=this._sheetsSourceManager.getSource(e,l);if(u&&u.hasData())return(u==null?void 0:u.getData(c,n,s))||{v:""}}}const r=this._getRTeeCollection(e);if(i&&r){const c={startRow:n,startColumn:s,endRow:n,endColumn:s},l=Array.from(r.bulkSearch([{unitId:e,sheetId:t,range:c}]));if(l.length>0){const u=i.getBindingNodeById(l[0]);if(u){const{sourceId:p}=u,f=this._sheetsSourceManager.getSource(e,p);if(f&&f.hasData())return(f==null?void 0:f.getData(u,n,s))||{v:""}}}}}getBindingModelBySourceId(e){return this._sheetsBindingManager.getBindingModelBySourceId(e)}_registerInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(I.INTERCEPTOR_POINT.CELL_CONTENT,{effect:a.InterceptorEffectEnum.Value|a.InterceptorEffectEnum.Style,priority:102,handler:(e,t,n)=>{const{row:s,col:i,unitId:r,subUnitId:c,workbook:l}=t;let u=null;if(this._bindingModel===R.Path?u=this._getPathModeCellValue(r,c,s,i):u=this._getValueModeCellValue(r,c,s,i),u!==null){const f={...(typeof(e==null?void 0:e.s)=="string"?l.getStyles().get(e==null?void 0:e.s):e==null?void 0:e.s)||{}};return u&&u.s&&Object.assign(f,u.s),n({...e,...u,s:f})}return n(e)}}))}dispose(){this._bindModelRTreeCollection.clear()}},h.SheetsSourceBindService=k([j(0,a.Inject(I.SheetInterceptorService)),j(1,a.Inject(b)),j(2,a.Inject(T))],h.SheetsSourceBindService);var q=Object.getOwnPropertyDescriptor,G=(d,o,e,t)=>{for(var n=t>1?void 0:t?q(o,e):o,s=d.length-1,i;s>=0;s--)(i=d[s])&&(n=i(n)||n);return n},L=(d,o)=>(e,t)=>o(e,t,d);h.UniverSheetsBindingSourcePlugin=(D=class extends a.Plugin{constructor(o={},e,t){super(),this._config=o,this._injector=e,this._configService=t}onStarting(){[[b],[T],[h.SheetsSourceBindService]].forEach(o=>this._injector.add(o))}onReady(){a.touchDependencies(this._injector,[[b],[T],[h.SheetsSourceBindService]])}},g(D,"type",a.UniverInstanceType.UNIVER_SHEET),g(D,"pluginName","SHEET_BINDING_SOURCE_PLUGIN"),D),h.UniverSheetsBindingSourcePlugin=G([L(1,a.Inject(a.Injector)),L(2,a.IConfigService)],h.UniverSheetsBindingSourcePlugin),h.BindModeEnum=R,h.BindingModel=U,h.DataBindingNodeTypeEnum=_,h.SheetsSourceManager=T,h.SourceModelBase=w,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-source-binding",
3
- "version": "0.6.0-nightly.202502191606",
3
+ "version": "0.6.1-nightly.202502211606",
4
4
  "private": false,
5
5
  "description": "A library for connect and bind data from other sources to Univer Sheets",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -51,15 +51,15 @@
51
51
  "rxjs": ">=7.0.0"
52
52
  },
53
53
  "dependencies": {
54
- "@univerjs/core": "0.6.0-nightly.202502191606",
55
- "@univerjs/sheets": "0.6.0-nightly.202502191606"
54
+ "@univerjs/core": "0.6.1-nightly.202502211606",
55
+ "@univerjs/sheets": "0.6.1-nightly.202502211606"
56
56
  },
57
57
  "devDependencies": {
58
58
  "rxjs": "^7.8.1",
59
59
  "typescript": "^5.7.3",
60
- "vite": "^6.1.0",
61
- "vitest": "^3.0.5",
62
- "@univerjs-infra/shared": "0.6.0"
60
+ "vite": "^6.1.1",
61
+ "vitest": "^3.0.6",
62
+ "@univerjs-infra/shared": "0.6.1"
63
63
  },
64
64
  "scripts": {
65
65
  "test": "vitest run",