@univerjs/sheets-source-binding 0.5.5-nightly.202501201606 → 0.5.5-nightly.202501210337

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;return this._isListObject?h=this._data.records[a-c][n]:h=this._data.records[a-c][d],e.isDate===!0?{v:x(h),s:{n:{pattern:"yyyy-m-d am/pm h:mm"}},t:u.CellValueType.NUMBER}:{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;return e.isDate===!0?{v:x(o),s:{n:{pattern:"yyyy-m-d am/pm h:mm"}},t:u.CellValueType.NUMBER}:{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:""}}}}}_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 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,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;return this._isListObject?h=this._data.records[a-c][n]:h=this._data.records[a-c][d],e.isDate===!0?{v:x(h),s:{n:{pattern:"yyyy-m-d am/pm h:mm"}},t:u.CellValueType.NUMBER}:{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;return e.isDate===!0?{v:x(o),s:{n:{pattern:"yyyy-m-d am/pm h:mm"}},t:u.CellValueType.NUMBER}:{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:""}}}}}_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;
package/lib/es/index.js CHANGED
@@ -1,14 +1,14 @@
1
1
  var q = Object.defineProperty;
2
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 h = (i, e, t) => z(i, typeof e != "symbol" ? e + "" : e, t);
3
+ var l = (i, e, t) => z(i, typeof e != "symbol" ? e + "" : e, t);
4
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 oe, ClearSelectionAllCommand as se, INTERCEPTOR_POINT as re } from "@univerjs/sheets";
5
+ import { SheetInterceptorService as V, SheetsSelectionsService as te, getSheetCommandTarget as ne, ClearSelectionContentCommand as se, ClearSelectionAllCommand as oe, INTERCEPTOR_POINT as re } from "@univerjs/sheets";
6
6
  import { Subject as H } from "rxjs";
7
7
  class $ {
8
8
  constructor(e) {
9
- h(this, "_matrix", {});
10
- h(this, "_nodeMap", /* @__PURE__ */ new Map());
11
- h(this, "_sourceIdMap", /* @__PURE__ */ new Map());
9
+ l(this, "_matrix", {});
10
+ l(this, "_nodeMap", /* @__PURE__ */ new Map());
11
+ l(this, "_sourceIdMap", /* @__PURE__ */ new Map());
12
12
  e && this._init(e);
13
13
  }
14
14
  _init(e) {
@@ -21,22 +21,22 @@ class $ {
21
21
  }
22
22
  setBindingNode(e, t, n) {
23
23
  this._matrix[e] || (this._matrix[e] = {}), this._matrix[e][t] || (this._matrix[e][t] = n), this._nodeMap.set(n.nodeId, n);
24
- const o = this._sourceIdMap.get(n.sourceId);
25
- o ? o.push(n.nodeId) : this._sourceIdMap.set(n.sourceId, [n.nodeId]);
24
+ const s = this._sourceIdMap.get(n.sourceId);
25
+ s ? s.push(n.nodeId) : this._sourceIdMap.set(n.sourceId, [n.nodeId]);
26
26
  }
27
27
  getBindingNode(e, t) {
28
28
  var n;
29
29
  return (n = this._matrix[e]) == null ? void 0 : n[t];
30
30
  }
31
31
  removeBindingNode(e, t) {
32
- var o;
33
- const n = (o = this._matrix[e]) == null ? void 0 : o[t];
32
+ var s;
33
+ const n = (s = this._matrix[e]) == null ? void 0 : s[t];
34
34
  if (n) {
35
35
  this._matrix[e][t] = void 0, this._nodeMap.delete(n.nodeId);
36
- const s = this._sourceIdMap.get(n.sourceId);
37
- if (s) {
38
- const r = s.indexOf(n.nodeId);
39
- r >= 0 && s.splice(r, 1), s.length === 0 && this._sourceIdMap.delete(n.sourceId);
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);
40
40
  }
41
41
  }
42
42
  }
@@ -61,15 +61,15 @@ function A(i) {
61
61
  if (!ie(e))
62
62
  return i;
63
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 s = (e.getTime() - t.getTime()) / (1e3 * 3600 * 24);
65
- return e > n && (s += 1), s + 1;
64
+ let o = (e.getTime() - t.getTime()) / (1e3 * 3600 * 24);
65
+ return e > n && (o += 1), o + 1;
66
66
  }
67
67
  class U {
68
68
  constructor(e) {
69
- h(this, "_data");
70
- h(this, "id");
71
- h(this, "_hasData", !1);
72
- h(this, "type");
69
+ l(this, "_data");
70
+ l(this, "id");
71
+ l(this, "_hasData", !1);
72
+ l(this, "type");
73
73
  this.id = e;
74
74
  }
75
75
  getId() {
@@ -97,10 +97,10 @@ class U {
97
97
  class x extends U {
98
98
  constructor(t, n) {
99
99
  super(t);
100
- h(this, "type", g.List);
101
- h(this, "_isListObject");
102
- h(this, "_fieldIndexMap", /* @__PURE__ */ new Map());
103
- h(this, "_data", { fields: [], records: [] });
100
+ l(this, "type", g.List);
101
+ l(this, "_isListObject");
102
+ l(this, "_fieldIndexMap", /* @__PURE__ */ new Map());
103
+ l(this, "_data", { fields: [], records: [] });
104
104
  this._isListObject = n != null ? n : !0;
105
105
  }
106
106
  /**
@@ -112,14 +112,14 @@ class x extends U {
112
112
  this._isListObject = t;
113
113
  }
114
114
  getData(t, n) {
115
- const { path: o, row: s, containHeader: r } = t, d = this._fieldIndexMap.get(o), c = n - s;
115
+ const { path: s, row: o, containHeader: r } = t, d = this._fieldIndexMap.get(s), c = n - o;
116
116
  if (r && c === 0)
117
117
  return {
118
118
  v: this._data.fields[d]
119
119
  };
120
120
  let a;
121
121
  const u = r ? 1 : 0;
122
- return this._isListObject ? a = this._data.records[c - u][o] : a = this._data.records[c - u][d], t.isDate === !0 ? {
122
+ return this._isListObject ? a = this._data.records[c - u][s] : a = this._data.records[c - u][d], t.isDate === !0 ? {
123
123
  v: A(a),
124
124
  s: {
125
125
  n: {
@@ -135,8 +135,8 @@ class x extends U {
135
135
  setSourceData(t) {
136
136
  super.setSourceData(t);
137
137
  const { fields: n } = t;
138
- this._fieldIndexMap.clear(), n.forEach((o, s) => {
139
- this._fieldIndexMap.set(o, s);
138
+ this._fieldIndexMap.clear(), n.forEach((s, o) => {
139
+ this._fieldIndexMap.set(s, o);
140
140
  });
141
141
  }
142
142
  getSourceInfo() {
@@ -151,16 +151,16 @@ class x extends U {
151
151
  class E extends U {
152
152
  constructor(t) {
153
153
  super(t);
154
- h(this, "type", g.Object);
154
+ l(this, "type", g.Object);
155
155
  }
156
156
  getData(t) {
157
- const o = t.path.split(".");
158
- let s = this._data;
159
- for (const r of o)
160
- if (s = s[r], s === void 0)
157
+ const s = t.path.split(".");
158
+ let o = this._data;
159
+ for (const r of s)
160
+ if (o = o[r], o === void 0)
161
161
  return null;
162
162
  return t.isDate === !0 ? {
163
- v: A(s),
163
+ v: A(o),
164
164
  s: {
165
165
  n: {
166
166
  pattern: "yyyy-m-d am/pm h:mm"
@@ -168,8 +168,8 @@ class E extends U {
168
168
  },
169
169
  t: v.NUMBER
170
170
  } : {
171
- v: s,
172
- t: typeof s == "number" ? v.NUMBER : v.STRING
171
+ v: o,
172
+ t: typeof o == "number" ? v.NUMBER : v.STRING
173
173
  };
174
174
  }
175
175
  getSourceInfo() {
@@ -180,30 +180,30 @@ class E extends U {
180
180
  }
181
181
  }
182
182
  var de = Object.defineProperty, ae = Object.getOwnPropertyDescriptor, ce = (i, e, t, n) => {
183
- for (var o = n > 1 ? void 0 : n ? ae(e, t) : e, s = i.length - 1, r; s >= 0; s--)
184
- (r = i[s]) && (o = (n ? r(e, t, o) : r(o)) || o);
185
- return n && o && de(e, t, o), o;
186
- }, b = (i, e) => (t, n) => e(t, n, i);
183
+ for (var s = n > 1 ? void 0 : n ? ae(e, t) : e, o = i.length - 1, r; o >= 0; o--)
184
+ (r = i[o]) && (s = (n ? r(e, t, s) : r(s)) || s);
185
+ return n && s && de(e, t, s), s;
186
+ }, R = (i, e) => (t, n) => e(t, n, i);
187
187
  let N = class extends O {
188
188
  constructor(e, t, n) {
189
189
  super();
190
- h(this, "modelMap", /* @__PURE__ */ new Map());
191
- h(this, "_cellBindInfoUpdate$", new H());
192
- h(this, "cellBindInfoUpdate$", this._cellBindInfoUpdate$.asObservable());
190
+ l(this, "modelMap", /* @__PURE__ */ new Map());
191
+ l(this, "_cellBindInfoUpdate$", new H());
192
+ l(this, "cellBindInfoUpdate$", this._cellBindInfoUpdate$.asObservable());
193
193
  this._univerInstanceService = e, this._sheetInterceptorService = t, this._sheetsSelectionsService = n, this._initRemoveCommand();
194
194
  }
195
195
  _initRemoveCommand() {
196
196
  this.disposeWithMe(
197
197
  this._sheetInterceptorService.interceptCommand({
198
198
  getMutations: (e) => {
199
- const t = [], n = [], o = this._sheetsSelectionsService.getCurrentSelections(), s = ne(this._univerInstanceService);
200
- if (!s || !o || o.length === 0)
199
+ const t = [], n = [], s = this._sheetsSelectionsService.getCurrentSelections(), o = ne(this._univerInstanceService);
200
+ if (!o || !s || s.length === 0)
201
201
  return {
202
202
  redos: [],
203
203
  undos: []
204
204
  };
205
- const { unitId: r, subUnitId: d } = s;
206
- return (e.id === oe.id || e.id === se.id) && o.forEach(({ range: c }) => {
205
+ const { unitId: r, subUnitId: d } = o;
206
+ return (e.id === se.id || e.id === oe.id) && s.forEach(({ range: c }) => {
207
207
  F.foreach(c, (a, u) => {
208
208
  this.getBindingNode(r, d, a, u) && this.removeBindingNode(r, d, a, u);
209
209
  });
@@ -214,13 +214,13 @@ let N = class extends O {
214
214
  }
215
215
  getBindingModelBySourceId(e) {
216
216
  const t = [];
217
- return this.modelMap.forEach((n, o) => {
218
- n.forEach((s, r) => {
219
- const d = s.getBindingNodesBySourceId(e);
217
+ return this.modelMap.forEach((n, s) => {
218
+ n.forEach((o, r) => {
219
+ const d = o.getBindingNodesBySourceId(e);
220
220
  if (d)
221
221
  for (const c of d)
222
222
  t.push({
223
- unitId: o,
223
+ unitId: s,
224
224
  subunitId: r,
225
225
  sourceId: e,
226
226
  nodeId: c.nodeId,
@@ -231,26 +231,26 @@ let N = class extends O {
231
231
  }), t;
232
232
  }
233
233
  addModel(e, t, n) {
234
- var o;
235
- this.modelMap.has(e) || this.modelMap.set(e, /* @__PURE__ */ new Map()), (o = this.modelMap.get(e)) == null || o.set(t, n);
234
+ var s;
235
+ this.modelMap.has(e) || this.modelMap.set(e, /* @__PURE__ */ new Map()), (s = this.modelMap.get(e)) == null || s.set(t, n);
236
236
  }
237
237
  getModel(e, t) {
238
238
  var n;
239
239
  return (n = this.modelMap.get(e)) == null ? void 0 : n.get(t);
240
240
  }
241
241
  setBindingNode(e, t, n) {
242
- let o = this.getModel(e, t);
243
- o || (o = new $(), this.addModel(e, t, o)), n.nodeId || (n.nodeId = J());
244
- const { row: s, column: r } = n;
245
- if (s === void 0 || r === void 0)
242
+ let s = this.getModel(e, t);
243
+ s || (s = new $(), this.addModel(e, t, s)), n.nodeId || (n.nodeId = J());
244
+ const { row: o, column: r } = n;
245
+ if (o === void 0 || r === void 0)
246
246
  throw new Error("row and column is required");
247
- const d = o.getBindingNode(s, r), c = n.type === g.List ? !!n.containHeader : !1;
248
- o.setBindingNode(s, r, { ...n, row: s, column: r }), this._cellBindInfoUpdate$.next({
247
+ const d = s.getBindingNode(o, r), c = n.type === g.List ? !!n.containHeader : !1;
248
+ s.setBindingNode(o, r, { ...n, row: o, column: r }), this._cellBindInfoUpdate$.next({
249
249
  unitId: e,
250
250
  subunitId: t,
251
251
  sourceId: n.sourceId,
252
252
  nodeId: n.nodeId,
253
- row: s,
253
+ row: o,
254
254
  column: r,
255
255
  containHeader: c,
256
256
  changeType: d ? S.Update : S.Add,
@@ -258,44 +258,44 @@ let N = class extends O {
258
258
  oldNodeContainHeader: (d == null ? void 0 : d.type) === g.List ? !!d.containHeader : !1
259
259
  });
260
260
  }
261
- removeBindingNode(e, t, n, o) {
262
- const s = this.getModel(e, t);
263
- if (s) {
264
- const r = s.getBindingNode(n, o);
265
- r && (s.removeBindingNode(n, o), this._cellBindInfoUpdate$.next({
261
+ removeBindingNode(e, t, n, s) {
262
+ const o = this.getModel(e, t);
263
+ if (o) {
264
+ const r = o.getBindingNode(n, s);
265
+ r && (o.removeBindingNode(n, s), this._cellBindInfoUpdate$.next({
266
266
  unitId: e,
267
267
  subunitId: t,
268
268
  sourceId: r.sourceId,
269
269
  nodeId: r.nodeId,
270
270
  row: n,
271
- column: o,
271
+ column: s,
272
272
  changeType: S.Remove
273
273
  }));
274
274
  }
275
275
  }
276
- getBindingNode(e, t, n, o) {
277
- const s = this.getModel(e, t);
278
- if (s)
279
- return s.getBindingNode(n, o);
280
- }
281
- getBindingNodeById(e, t, n) {
276
+ getBindingNode(e, t, n, s) {
282
277
  const o = this.getModel(e, t);
283
278
  if (o)
284
- return o.getBindingNodeById(n);
279
+ return o.getBindingNode(n, s);
280
+ }
281
+ getBindingNodeById(e, t, n) {
282
+ const s = this.getModel(e, t);
283
+ if (s)
284
+ return s.getBindingNodeById(n);
285
285
  }
286
286
  createModel(e, t, n) {
287
- const o = new $(n);
288
- return this.addModel(e, t, o), o;
287
+ const s = new $(n);
288
+ return this.addModel(e, t, s), s;
289
289
  }
290
290
  toJSON(e) {
291
291
  const t = {}, n = this.modelMap.get(e);
292
- return n && n.forEach((o, s) => {
293
- t[s] = o.toJSON();
292
+ return n && n.forEach((s, o) => {
293
+ t[o] = s.toJSON();
294
294
  }), t;
295
295
  }
296
296
  fromJSON(e, t) {
297
- Object.entries(t).forEach(([n, o]) => {
298
- this.createModel(e, n, o);
297
+ Object.entries(t).forEach(([n, s]) => {
298
+ this.createModel(e, n, s);
299
299
  });
300
300
  }
301
301
  dispose() {
@@ -303,16 +303,16 @@ let N = class extends O {
303
303
  }
304
304
  };
305
305
  N = ce([
306
- b(0, K),
307
- b(1, C(V)),
308
- b(2, C(te))
306
+ R(0, K),
307
+ R(1, C(V)),
308
+ R(2, C(te))
309
309
  ], N);
310
310
  class T extends O {
311
311
  constructor() {
312
312
  super();
313
- h(this, "sourceMap", /* @__PURE__ */ new Map());
314
- h(this, "_sourceDataUpdate$", new H());
315
- h(this, "sourceDataUpdate$", this._sourceDataUpdate$.asObservable());
313
+ l(this, "sourceMap", /* @__PURE__ */ new Map());
314
+ l(this, "_sourceDataUpdate$", new H());
315
+ l(this, "sourceDataUpdate$", this._sourceDataUpdate$.asObservable());
316
316
  }
317
317
  _ensureUnitMap(t) {
318
318
  let n = this.sourceMap.get(t);
@@ -322,15 +322,15 @@ class T extends O {
322
322
  return this.sourceMap.get(t);
323
323
  }
324
324
  getSource(t, n) {
325
- const o = this._getUnitMap(t);
326
- return o == null ? void 0 : o.get(n);
325
+ const s = this._getUnitMap(t);
326
+ return s == null ? void 0 : s.get(n);
327
327
  }
328
- createSource(t, n, o, s) {
329
- const r = s === void 0 ? J() : s;
328
+ createSource(t, n, s, o) {
329
+ const r = o === void 0 ? J() : o;
330
330
  let d;
331
331
  switch (n) {
332
332
  case g.List:
333
- d = new x(r, o);
333
+ d = new x(r, s);
334
334
  break;
335
335
  case g.Object:
336
336
  d = new E(r);
@@ -340,39 +340,39 @@ class T extends O {
340
340
  }
341
341
  return this._ensureUnitMap(t).set(r, d), d;
342
342
  }
343
- updateSourceData(t, n, o) {
344
- const s = this._getUnitMap(t), r = n instanceof U ? n.getId() : n, d = s == null ? void 0 : s.get(r);
343
+ updateSourceData(t, n, s) {
344
+ const o = this._getUnitMap(t), r = n instanceof U ? n.getId() : n, d = o == null ? void 0 : o.get(r);
345
345
  if (d)
346
- d.setSourceData(o), this._sourceDataUpdate$.next({ ...d.getSourceInfo(), unitId: t, changeType: S.Add });
346
+ d.setSourceData(s), this._sourceDataUpdate$.next({ ...d.getSourceInfo(), unitId: t, changeType: S.Add });
347
347
  else
348
348
  throw new Error(`Source not found: ${r}`);
349
349
  }
350
350
  removeSource(t, n) {
351
- const o = this._getUnitMap(t), s = o == null ? void 0 : o.get(n);
352
- s && (o == null || o.delete(n), this._sourceDataUpdate$.next({ ...s.getSourceInfo(), unitId: t, changeType: S.Remove }));
351
+ const s = this._getUnitMap(t), o = s == null ? void 0 : s.get(n);
352
+ o && (s == null || s.delete(n), this._sourceDataUpdate$.next({ ...o.getSourceInfo(), unitId: t, changeType: S.Remove }));
353
353
  }
354
354
  toJSON(t) {
355
- const n = [], o = this._getUnitMap(t);
356
- if (o)
357
- for (const s of o.values())
358
- n.push(s.toJSON());
355
+ const n = [], s = this._getUnitMap(t);
356
+ if (s)
357
+ for (const o of s.values())
358
+ n.push(o.toJSON());
359
359
  return n;
360
360
  }
361
361
  fromJSON(t, n) {
362
- const o = this._ensureUnitMap(t);
363
- for (const s of n) {
362
+ const s = this._ensureUnitMap(t);
363
+ for (const o of n) {
364
364
  let r;
365
- switch (s.type) {
365
+ switch (o.type) {
366
366
  case g.List:
367
- r = new x(s.id);
367
+ r = new x(o.id);
368
368
  break;
369
369
  case g.Object:
370
- r = new E(s.id);
370
+ r = new E(o.id);
371
371
  break;
372
372
  default:
373
- throw new Error(`Invalid source type: ${s.type}`);
373
+ throw new Error(`Invalid source type: ${o.type}`);
374
374
  }
375
- r.fromJSON(s), o.set(s.id, r);
375
+ r.fromJSON(o), s.set(o.id, r);
376
376
  }
377
377
  }
378
378
  dispose() {
@@ -380,15 +380,15 @@ class T extends O {
380
380
  }
381
381
  }
382
382
  var ue = Object.defineProperty, he = Object.getOwnPropertyDescriptor, le = (i, e, t, n) => {
383
- for (var o = n > 1 ? void 0 : n ? he(e, t) : e, s = i.length - 1, r; s >= 0; s--)
384
- (r = i[s]) && (o = (n ? r(e, t, o) : r(o)) || o);
385
- return n && o && ue(e, t, o), o;
383
+ for (var s = n > 1 ? void 0 : n ? he(e, t) : e, o = i.length - 1, r; o >= 0; o--)
384
+ (r = i[o]) && (s = (n ? r(e, t, s) : r(s)) || s);
385
+ return n && s && ue(e, t, s), s;
386
386
  }, D = (i, e) => (t, n) => e(t, n, i);
387
- let R = class extends O {
387
+ let w = class extends O {
388
388
  constructor(e, t, n) {
389
389
  super();
390
- h(this, "_bindingModel", y.Value);
391
- h(this, "_bindModelRTreeCollection", /* @__PURE__ */ new Map());
390
+ l(this, "_bindingModel", y.Value);
391
+ l(this, "_bindModelRTreeCollection", /* @__PURE__ */ new Map());
392
392
  this._sheetInterceptorService = e, this._sheetsBindingManager = t, this._sheetsSourceManager = n, this._registerInterceptor(), this._registerSourceChange();
393
393
  }
394
394
  /**
@@ -416,17 +416,17 @@ let R = class extends O {
416
416
  setBindingNode(e, t, n) {
417
417
  this._sheetsBindingManager.setBindingNode(e, t, n);
418
418
  }
419
- removeBindingNode(e, t, n, o) {
420
- this._sheetsBindingManager.removeBindingNode(e, t, n, o);
419
+ removeBindingNode(e, t, n, s) {
420
+ this._sheetsBindingManager.removeBindingNode(e, t, n, s);
421
421
  }
422
- getBindingNode(e, t, n, o) {
423
- return this._sheetsBindingManager.getBindingNode(e, t, n, o);
422
+ getBindingNode(e, t, n, s) {
423
+ return this._sheetsBindingManager.getBindingNode(e, t, n, s);
424
424
  }
425
425
  getSource(e, t) {
426
426
  return this._sheetsSourceManager.getSource(e, t);
427
427
  }
428
- createSource(e, t, n, o) {
429
- return this._sheetsSourceManager.createSource(e, t, n, o);
428
+ createSource(e, t, n, s) {
429
+ return this._sheetsSourceManager.createSource(e, t, n, s);
430
430
  }
431
431
  getSourceBindingPathInfo(e) {
432
432
  return {
@@ -446,66 +446,66 @@ let R = class extends O {
446
446
  // eslint-disable-next-line max-lines-per-function
447
447
  _registerSourceChange() {
448
448
  this.disposeWithMe(this._sheetsSourceManager.sourceDataUpdate$.subscribe((e) => {
449
- const { sourceId: t, sourceType: n, unitId: o, changeType: s } = e;
449
+ const { sourceId: t, sourceType: n, unitId: s, changeType: o } = e;
450
450
  if (n === g.List) {
451
- if (s === S.Remove) {
451
+ if (o === S.Remove) {
452
452
  const d = this._sheetsBindingManager.getBindingModelBySourceId(t), c = e.recordCount;
453
- for (const { unitId: a, subunitId: u, nodeId: l, row: p, column: _ } of d) {
454
- const M = this._getRTeeCollection(o), f = this._sheetsBindingManager.getBindingNodeById(a, u, l);
453
+ for (const { unitId: a, subunitId: u, nodeId: h, row: p, column: _ } of d) {
454
+ const M = this._getRTeeCollection(s), f = this._sheetsBindingManager.getBindingNodeById(a, u, h);
455
455
  if (M && (f == null ? void 0 : f.type) === g.List) {
456
456
  const I = f.containHeader ? 0 : 1, m = { startRow: p, startColumn: _, endRow: p + c - I, endColumn: _ };
457
- M.remove({ unitId: a, sheetId: u, id: l, range: m });
457
+ M.remove({ unitId: a, sheetId: u, id: h, range: m });
458
458
  }
459
459
  }
460
460
  return;
461
461
  }
462
- if (s === S.Update) {
462
+ if (o === S.Update) {
463
463
  const d = e.oldRecordCount, c = this._sheetsBindingManager.getBindingModelBySourceId(t);
464
- for (const { unitId: a, subunitId: u, nodeId: l, row: p, column: _ } of c) {
465
- const M = this._getRTeeCollection(o), f = this._sheetsBindingManager.getBindingNodeById(a, u, l);
464
+ for (const { unitId: a, subunitId: u, nodeId: h, row: p, column: _ } of c) {
465
+ const M = this._getRTeeCollection(s), f = this._sheetsBindingManager.getBindingNodeById(a, u, h);
466
466
  if (M && (f == null ? void 0 : f.type) === g.List) {
467
467
  const I = f.containHeader ? 0 : 1, m = { startRow: p, startColumn: _, endRow: p + d - I, endColumn: _ }, B = { startRow: p, startColumn: _, endRow: p + e.recordCount - I, endColumn: _ };
468
- M.remove({ unitId: a, sheetId: u, id: l, range: m }), M.insert({ unitId: a, sheetId: u, id: l, range: B });
468
+ M.remove({ unitId: a, sheetId: u, id: h, range: m }), M.insert({ unitId: a, sheetId: u, id: h, range: B });
469
469
  }
470
470
  }
471
471
  return;
472
472
  }
473
- const r = this._sheetsSourceManager.getSource(o, t);
473
+ const r = this._sheetsSourceManager.getSource(s, t);
474
474
  if (r && r.hasData()) {
475
475
  const c = r.getSourceInfo().recordCount, a = this._sheetsBindingManager.getBindingModelBySourceId(t);
476
- for (const { unitId: u, subunitId: l, nodeId: p, row: _, column: M } of a) {
477
- const f = this._ensureRTreeCollection(u), I = this._sheetsBindingManager.getBindingNodeById(u, l, p);
476
+ for (const { unitId: u, subunitId: h, nodeId: p, row: _, column: M } of a) {
477
+ const f = this._ensureRTreeCollection(u), I = this._sheetsBindingManager.getBindingNodeById(u, h, p);
478
478
  if (f && (I == null ? void 0 : I.type) === g.List) {
479
479
  const m = I.containHeader ? 0 : 1, B = { startRow: _, startColumn: M, endRow: _ + c - m, endColumn: M };
480
- f.insert({ unitId: u, sheetId: l, id: p, range: B });
480
+ f.insert({ unitId: u, sheetId: h, id: p, range: B });
481
481
  }
482
482
  }
483
483
  }
484
484
  }
485
485
  })), this.disposeWithMe(this._sheetsBindingManager.cellBindInfoUpdate$.subscribe((e) => {
486
- const { unitId: t, subunitId: n, sourceId: o, nodeId: s, row: r, column: d, changeType: c, containHeader: a } = e, u = this._ensureRTreeCollection(t), l = this._sheetsSourceManager.getSource(t, o);
487
- if (l && l.hasData()) {
488
- const p = l.getSourceInfo();
486
+ const { unitId: t, subunitId: n, sourceId: s, nodeId: o, row: r, column: d, changeType: c, containHeader: a } = e, u = this._ensureRTreeCollection(t), h = this._sheetsSourceManager.getSource(t, s);
487
+ if (h && h.hasData()) {
488
+ const p = h.getSourceInfo();
489
489
  if (p.sourceType === g.List) {
490
490
  const _ = p.recordCount, M = a ? 0 : 1, f = { startRow: r, startColumn: d, endRow: r + _ - M, endColumn: d };
491
491
  if (c === S.Add)
492
- u.insert({ unitId: t, sheetId: n, id: s, range: f });
492
+ u.insert({ unitId: t, sheetId: n, id: o, range: f });
493
493
  else if (c === S.Remove)
494
- u.remove({ unitId: t, sheetId: n, id: s, range: f });
494
+ u.remove({ unitId: t, sheetId: n, id: o, range: f });
495
495
  else if (c === S.Update) {
496
496
  const I = e.oldSourceId, m = e.oldNodeContainHeader ? 0 : 1, B = this._sheetsSourceManager.getSource(t, I);
497
497
  if (B && B.hasData()) {
498
498
  const G = B.getSourceInfo().recordCount, W = { startRow: r, startColumn: d, endRow: r + G - m, endColumn: d };
499
- u.remove({ unitId: t, sheetId: n, id: s, range: W });
499
+ u.remove({ unitId: t, sheetId: n, id: o, range: W });
500
500
  }
501
- u.insert({ unitId: t, sheetId: n, id: s, range: f });
501
+ u.insert({ unitId: t, sheetId: n, id: o, range: f });
502
502
  }
503
503
  }
504
504
  }
505
505
  }));
506
506
  }
507
- _getPathModeCellValue(e, t, n, o) {
508
- const s = this._sheetsBindingManager.getModel(e, t), r = s == null ? void 0 : s.getBindingNode(n, o);
507
+ _getPathModeCellValue(e, t, n, s) {
508
+ const o = this._sheetsBindingManager.getModel(e, t), r = o == null ? void 0 : o.getBindingNode(n, s);
509
509
  if (r) {
510
510
  const d = r.type;
511
511
  if (d === g.List)
@@ -520,25 +520,25 @@ let R = class extends O {
520
520
  };
521
521
  }
522
522
  }
523
- _getValueModeCellValue(e, t, n, o) {
524
- const s = this._sheetsBindingManager.getModel(e, t);
525
- if (s) {
526
- const d = s.getBindingNode(n, o);
523
+ _getValueModeCellValue(e, t, n, s) {
524
+ const o = this._sheetsBindingManager.getModel(e, t);
525
+ if (o) {
526
+ const d = o.getBindingNode(n, s);
527
527
  if (d) {
528
528
  const { sourceId: c } = d, a = this._sheetsSourceManager.getSource(e, c);
529
529
  if (a && a.hasData())
530
- return (a == null ? void 0 : a.getData(d, n, o)) || { v: "" };
530
+ return (a == null ? void 0 : a.getData(d, n, s)) || { v: "" };
531
531
  }
532
532
  }
533
533
  const r = this._getRTeeCollection(e);
534
- if (s && r) {
535
- const d = { startRow: n, startColumn: o, endRow: n, endColumn: o }, c = Array.from(r.bulkSearch([{ unitId: e, sheetId: t, range: d }]));
534
+ if (o && r) {
535
+ const d = { startRow: n, startColumn: s, endRow: n, endColumn: s }, c = Array.from(r.bulkSearch([{ unitId: e, sheetId: t, range: d }]));
536
536
  if (c.length > 0) {
537
- const a = s.getBindingNodeById(c[0]);
537
+ const a = o.getBindingNodeById(c[0]);
538
538
  if (a) {
539
- const { sourceId: u } = a, l = this._sheetsSourceManager.getSource(e, u);
540
- if (l && l.hasData())
541
- return (l == null ? void 0 : l.getData(a, n, o)) || { v: "" };
539
+ const { sourceId: u } = a, h = this._sheetsSourceManager.getSource(e, u);
540
+ if (h && h.hasData())
541
+ return (h == null ? void 0 : h.getData(a, n, s)) || { v: "" };
542
542
  }
543
543
  }
544
544
  }
@@ -548,11 +548,11 @@ let R = class extends O {
548
548
  effect: P.Value | P.Style,
549
549
  priority: 102,
550
550
  handler: (e, t, n) => {
551
- const { row: o, col: s, unitId: r, subUnitId: d, workbook: c } = t;
551
+ const { row: s, col: o, unitId: r, subUnitId: d, workbook: c } = t;
552
552
  let a = null;
553
- if (this._bindingModel === y.Path ? a = this._getPathModeCellValue(r, d, o, s) : a = this._getValueModeCellValue(r, d, o, s), a !== null) {
554
- const l = { ...(typeof (e == null ? void 0 : e.s) == "string" ? c.getStyles().get(e == null ? void 0 : e.s) : e == null ? void 0 : e.s) || {} };
555
- return n({ ...e, ...a, s: l });
553
+ if (this._bindingModel === y.Path ? a = this._getPathModeCellValue(r, d, s, o) : a = this._getValueModeCellValue(r, d, s, o), a !== null) {
554
+ const h = { ...(typeof (e == null ? void 0 : e.s) == "string" ? c.getStyles().get(e == null ? void 0 : e.s) : e == null ? void 0 : e.s) || {} };
555
+ return a && a.s && Object.assign(h, a.s), n({ ...e, ...a, s: h });
556
556
  }
557
557
  return n(e);
558
558
  }
@@ -562,17 +562,17 @@ let R = class extends O {
562
562
  this._bindModelRTreeCollection.clear();
563
563
  }
564
564
  };
565
- R = le([
565
+ w = le([
566
566
  D(0, C(V)),
567
567
  D(1, C(N)),
568
568
  D(2, C(T))
569
- ], R);
569
+ ], w);
570
570
  var ge = Object.defineProperty, fe = Object.getOwnPropertyDescriptor, pe = (i, e, t, n) => {
571
- for (var o = n > 1 ? void 0 : n ? fe(e, t) : e, s = i.length - 1, r; s >= 0; s--)
572
- (r = i[s]) && (o = (n ? r(e, t, o) : r(o)) || o);
573
- return n && o && ge(e, t, o), o;
574
- }, j = (i, e) => (t, n) => e(t, n, i), w;
575
- let L = (w = class extends X {
571
+ for (var s = n > 1 ? void 0 : n ? fe(e, t) : e, o = i.length - 1, r; o >= 0; o--)
572
+ (r = i[o]) && (s = (n ? r(e, t, s) : r(s)) || s);
573
+ return n && s && ge(e, t, s), s;
574
+ }, j = (i, e) => (t, n) => e(t, n, i), b;
575
+ let L = (b = class extends X {
576
576
  constructor(i = {}, e, t) {
577
577
  super(), this._config = i, this._injector = e, this._configService = t;
578
578
  }
@@ -580,17 +580,17 @@ let L = (w = class extends X {
580
580
  [
581
581
  [N],
582
582
  [T],
583
- [R]
583
+ [w]
584
584
  ].forEach((i) => this._injector.add(i));
585
585
  }
586
586
  onReady() {
587
587
  Z(this._injector, [
588
588
  [N],
589
589
  [T],
590
- [R]
590
+ [w]
591
591
  ]);
592
592
  }
593
- }, h(w, "type", Y.UNIVER_SHEET), h(w, "pluginName", "SHEET_BINDING_SOURCE_PLUGIN"), w);
593
+ }, l(b, "type", Y.UNIVER_SHEET), l(b, "pluginName", "SHEET_BINDING_SOURCE_PLUGIN"), b);
594
594
  L = pe([
595
595
  j(1, C(k)),
596
596
  j(2, ee)
@@ -599,7 +599,7 @@ export {
599
599
  y as BindModeEnum,
600
600
  $ as BindingModel,
601
601
  g as DataBindingNodeTypeEnum,
602
- R as SheetsSourceBindService,
602
+ w as SheetsSourceBindService,
603
603
  T as SheetsSourceManager,
604
604
  U as SourceModelBase,
605
605
  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;return this._isListObject?l=this._data.records[c-u][n]:l=this._data.records[c-u][r],e.isDate===!0?{v:E(l),s:{n:{pattern:"yyyy-m-d am/pm h:mm"}},t:a.CellValueType.NUMBER}:{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;return e.isDate===!0?{v:E(s),s:{n:{pattern:"yyyy-m-d am/pm h:mm"}},t:a.CellValueType.NUMBER}:{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 C=S.containHeader?0:1,y={startRow:M,startColumn:m,endRow:M+l-C,endColumn:m};v.remove({unitId:u,sheetId:p,id:f,range:y})}}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 C=S.containHeader?0:1,y={startRow:M,startColumn:m,endRow:M+c-C,endColumn:m},N={startRow:M,startColumn:m,endRow:M+e.recordCount-C,endColumn:m};v.remove({unitId:u,sheetId:p,id:f,range:y}),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),C=this._sheetsBindingManager.getBindingNodeById(p,f,M);if(S&&(C==null?void 0:C.type)===_.List){const y=C.containHeader?0:1,N={startRow:m,startColumn:v,endRow:m+l-y,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 C=e.oldSourceId,y=e.oldNodeContainHeader?0:1,N=this._sheetsSourceManager.getSource(t,C);if(N&&N.hasData()){const Q=N.getSourceInfo().recordCount,X={startRow:r,startColumn:c,endRow:r+Q-y,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:""}}}}}_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 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,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;return this._isListObject?l=this._data.records[c-u][n]:l=this._data.records[c-u][r],e.isDate===!0?{v:E(l),s:{n:{pattern:"yyyy-m-d am/pm h:mm"}},t:a.CellValueType.NUMBER}:{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;return e.isDate===!0?{v:E(s),s:{n:{pattern:"yyyy-m-d am/pm h:mm"}},t:a.CellValueType.NUMBER}:{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 C=S.containHeader?0:1,y={startRow:M,startColumn:m,endRow:M+l-C,endColumn:m};v.remove({unitId:u,sheetId:p,id:f,range:y})}}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 C=S.containHeader?0:1,y={startRow:M,startColumn:m,endRow:M+c-C,endColumn:m},N={startRow:M,startColumn:m,endRow:M+e.recordCount-C,endColumn:m};v.remove({unitId:u,sheetId:p,id:f,range:y}),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),C=this._sheetsBindingManager.getBindingNodeById(p,f,M);if(S&&(C==null?void 0:C.type)===_.List){const y=C.containHeader?0:1,N={startRow:m,startColumn:v,endRow:m+l-y,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 C=e.oldSourceId,y=e.oldNodeContainHeader?0:1,N=this._sheetsSourceManager.getSource(t,C);if(N&&N.hasData()){const Q=N.getSourceInfo().recordCount,X={startRow:r,startColumn:c,endRow:r+Q-y,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:""}}}}}_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"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-source-binding",
3
- "version": "0.5.5-nightly.202501201606",
3
+ "version": "0.5.5-nightly.202501210337",
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,8 +51,8 @@
51
51
  "rxjs": ">=7.0.0"
52
52
  },
53
53
  "dependencies": {
54
- "@univerjs/core": "0.5.5-nightly.202501201606",
55
- "@univerjs/sheets": "0.5.5-nightly.202501201606"
54
+ "@univerjs/core": "0.5.5-nightly.202501210337",
55
+ "@univerjs/sheets": "0.5.5-nightly.202501210337"
56
56
  },
57
57
  "devDependencies": {
58
58
  "rxjs": "^7.8.1",