@univerjs/sheets-source-binding 0.5.5-nightly.202501210925 → 0.5.5-nightly.202501220324

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/facade.js CHANGED
@@ -1 +1 @@
1
- "use strict";const d=require("@univerjs/core"),n=require("@univerjs/sheets-source-binding"),c=require("@univerjs/sheets/facade");class S extends d.FEnum{get DataBindingNodeTypeEnum(){return n.DataBindingNodeTypeEnum}get BindModeEnum(){return n.BindModeEnum}}d.FEnum.extend(S);class u extends c.FWorkbook{createSource(e,t,i){return this._injector.get(n.SheetsSourceBindService).createSource(this.getId(),e,t,i)}getSource(e){return this._injector.get(n.SheetsSourceBindService).getSource(this.getId(),e)}setSourceData(e,t){this._injector.get(n.SheetsSourceManager).updateSourceData(this.getId(),e,t)}usePathMode(){this._injector.get(n.SheetsSourceBindService).usePathMode()}useValueMode(){this._injector.get(n.SheetsSourceBindService).useValueMode()}loadSourceBindingPathInfo(e){this._injector.get(n.SheetsSourceBindService).loadSourceBindingPathInfo(this.getId(),e)}saveSourceBindingPathInfo(){return this._injector.get(n.SheetsSourceBindService).getSourceBindingPathInfo(this.getId())}getBindingModelBySourceId(e){return this._injector.get(n.SheetsSourceBindService).getBindingModelBySourceId(e)}}c.FWorkbook.extend(u);class h extends c.FWorksheet{setBindingNode(e){const i=this._injector.get(n.SheetsSourceBindService),o=this._workbook.getUnitId();i.setBindingNode(o,this.getSheetId(),e)}removeBindingNode(e,t){const o=this._injector.get(n.SheetsSourceBindService),r=this._workbook.getUnitId();o.removeBindingNode(r,this.getSheetId(),e,t)}getBindingNode(e,t){const o=this._injector.get(n.SheetsSourceBindService),r=this._workbook.getUnitId();return o.getBindingNode(r,this.getSheetId(),e,t)}}c.FWorksheet.extend(h);
1
+ "use strict";var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});const core=require("@univerjs/core"),sheetsSourceBinding=require("@univerjs/sheets-source-binding"),facade=require("@univerjs/sheets/facade"),_FSourceBindingEnum=class _FSourceBindingEnum extends core.FEnum{get DataBindingNodeTypeEnum(){return sheetsSourceBinding.DataBindingNodeTypeEnum}get BindModeEnum(){return sheetsSourceBinding.BindModeEnum}};__name(_FSourceBindingEnum,"FSourceBindingEnum");let FSourceBindingEnum=_FSourceBindingEnum;core.FEnum.extend(FSourceBindingEnum);const _FWorkbookSourceBinding=class _FWorkbookSourceBinding extends facade.FWorkbook{createSource(type,isListObject,id){return this._injector.get(sheetsSourceBinding.SheetsSourceBindService).createSource(this.getId(),type,isListObject,id)}getSource(sourceId){return this._injector.get(sheetsSourceBinding.SheetsSourceBindService).getSource(this.getId(),sourceId)}setSourceData(sourceId,data){this._injector.get(sheetsSourceBinding.SheetsSourceManager).updateSourceData(this.getId(),sourceId,data)}usePathMode(){this._injector.get(sheetsSourceBinding.SheetsSourceBindService).usePathMode()}useValueMode(){this._injector.get(sheetsSourceBinding.SheetsSourceBindService).useValueMode()}loadSourceBindingPathInfo(obj){this._injector.get(sheetsSourceBinding.SheetsSourceBindService).loadSourceBindingPathInfo(this.getId(),obj)}saveSourceBindingPathInfo(){return this._injector.get(sheetsSourceBinding.SheetsSourceBindService).getSourceBindingPathInfo(this.getId())}getBindingModelBySourceId(sourceId){return this._injector.get(sheetsSourceBinding.SheetsSourceBindService).getBindingModelBySourceId(sourceId)}};__name(_FWorkbookSourceBinding,"FWorkbookSourceBinding");let FWorkbookSourceBinding=_FWorkbookSourceBinding;facade.FWorkbook.extend(FWorkbookSourceBinding);const _FWorksheetSourceBinding=class _FWorksheetSourceBinding extends facade.FWorksheet{setBindingNode(bindingNode){const sheetsSourceBindService=this._injector.get(sheetsSourceBinding.SheetsSourceBindService),unitId=this._workbook.getUnitId();sheetsSourceBindService.setBindingNode(unitId,this.getSheetId(),bindingNode)}removeBindingNode(row,column){const sheetsSourceBindService=this._injector.get(sheetsSourceBinding.SheetsSourceBindService),unitId=this._workbook.getUnitId();sheetsSourceBindService.removeBindingNode(unitId,this.getSheetId(),row,column)}getBindingNode(row,column){const sheetsSourceBindService=this._injector.get(sheetsSourceBinding.SheetsSourceBindService),unitId=this._workbook.getUnitId();return sheetsSourceBindService.getBindingNode(unitId,this.getSheetId(),row,column)}};__name(_FWorksheetSourceBinding,"FWorksheetSourceBinding");let FWorksheetSourceBinding=_FWorksheetSourceBinding;facade.FWorksheet.extend(FWorksheetSourceBinding);
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:""}}}}}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 __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const core=require("@univerjs/core"),sheets=require("@univerjs/sheets"),rxjs=require("rxjs"),_SheetBindingModel=class _SheetBindingModel{constructor(json){__publicField(this,"_matrix",{});__publicField(this,"_nodeMap",new Map);__publicField(this,"_sourceIdMap",new Map);json&&this._init(json)}_init(json){this.fromJSON(json)}getBindingNodesBySourceId(sourceId){const nodeIds=this._sourceIdMap.get(sourceId);if(nodeIds)return nodeIds.map(nodeId=>this._nodeMap.get(nodeId))}setBindingNode(row,column,node){this._matrix[row]||(this._matrix[row]={}),this._matrix[row][column]||(this._matrix[row][column]=node),this._nodeMap.set(node.nodeId,node);const nodeIds=this._sourceIdMap.get(node.sourceId);nodeIds?nodeIds.push(node.nodeId):this._sourceIdMap.set(node.sourceId,[node.nodeId])}getBindingNode(row,column){var _a4;return(_a4=this._matrix[row])==null?void 0:_a4[column]}removeBindingNode(row,column){var _a4;const node=(_a4=this._matrix[row])==null?void 0:_a4[column];if(node){this._matrix[row][column]=void 0,this._nodeMap.delete(node.nodeId);const nodeIds=this._sourceIdMap.get(node.sourceId);if(nodeIds){const index=nodeIds.indexOf(node.nodeId);index>=0&&nodeIds.splice(index,1),nodeIds.length===0&&this._sourceIdMap.delete(node.sourceId)}}}getBindingNodeById(nodeId){return this._nodeMap.get(nodeId)}fromJSON(nodes){nodes.forEach(node=>{this.setBindingNode(node.row,node.column,node)})}toJSON(){return Array.from(this._nodeMap.values())}};__name(_SheetBindingModel,"SheetBindingModel");let SheetBindingModel=_SheetBindingModel;var DataBindingNodeTypeEnum=(DataBindingNodeTypeEnum2=>(DataBindingNodeTypeEnum2.List="list",DataBindingNodeTypeEnum2.Object="object",DataBindingNodeTypeEnum2))(DataBindingNodeTypeEnum||{}),BindModeEnum=(BindModeEnum2=>(BindModeEnum2.Path="path",BindModeEnum2.Value="value",BindModeEnum2))(BindModeEnum||{}),BindingSourceChangeTypeEnum=(BindingSourceChangeTypeEnum2=>(BindingSourceChangeTypeEnum2.Add="add",BindingSourceChangeTypeEnum2.Remove="remove",BindingSourceChangeTypeEnum2.Update="update",BindingSourceChangeTypeEnum2))(BindingSourceChangeTypeEnum||{});function isValidDate(date){return date instanceof Date&&!isNaN(date.getTime())}__name(isValidDate,"isValidDate");function transformDate(dateString){const date=new Date(dateString);if(!isValidDate(date))return dateString;const baseDate=new Date(Date.UTC(1900,0,1,0,0,0)),leapDayDate=new Date(Date.UTC(1900,1,28,0,0,0));let dayDifference=(date.getTime()-baseDate.getTime())/(1e3*3600*24);return date>leapDayDate&&(dayDifference+=1),dayDifference+1}__name(transformDate,"transformDate");const _SourceModelBase=class _SourceModelBase{constructor(id){__publicField(this,"_data");__publicField(this,"id");__publicField(this,"_hasData",!1);__publicField(this,"type");this.id=id}getId(){return this.id}getType(){return this.type}hasData(){return this._hasData}setSourceData(data){this._data=data,this._hasData=!0}toJSON(){return{id:this.id,type:this.type}}fromJSON(info){this.id=info.id,this.type=info.type}};__name(_SourceModelBase,"SourceModelBase");let SourceModelBase=_SourceModelBase;const _ListSourceModel=class _ListSourceModel extends SourceModelBase{constructor(id,isListObject){super(id);__publicField(this,"type",DataBindingNodeTypeEnum.List);__publicField(this,"_isListObject");__publicField(this,"_fieldIndexMap",new Map);__publicField(this,"_data",{fields:[],records:[]});this._isListObject=isListObject!=null?isListObject:!0}toggleListObject(isListObject){this._isListObject=isListObject}getData(node,row){const{path,row:baseRow,containHeader}=node,colIndex=this._fieldIndexMap.get(path),rowIndex=row-baseRow;if(containHeader&&rowIndex===0)return{v:this._data.fields[colIndex]};let data;const offset=containHeader?1:0;return this._isListObject?data=this._data.records[rowIndex-offset][path]:data=this._data.records[rowIndex-offset][colIndex],node.isDate===!0?{v:transformDate(data),s:{n:{pattern:"yyyy-m-d am/pm h:mm"}},t:core.CellValueType.NUMBER}:{t:typeof data=="number"?core.CellValueType.NUMBER:core.CellValueType.STRING,v:data}}setSourceData(data){super.setSourceData(data);const{fields}=data;this._fieldIndexMap.clear(),fields.forEach((field,index)=>{this._fieldIndexMap.set(field,index)})}getSourceInfo(){return{sourceId:this.id,sourceType:this.type,fields:this._data.fields,recordCount:this._data.records.length}}};__name(_ListSourceModel,"ListSourceModel");let ListSourceModel=_ListSourceModel;const _ObjectSourceModel=class _ObjectSourceModel extends SourceModelBase{constructor(id){super(id);__publicField(this,"type",DataBindingNodeTypeEnum.Object)}getData(node){const paths=node.path.split(".");let data=this._data;for(const p of paths)if(data=data[p],data===void 0)return null;return node.isDate===!0?{v:transformDate(data),s:{n:{pattern:"yyyy-m-d am/pm h:mm"}},t:core.CellValueType.NUMBER}:{v:data,t:typeof data=="number"?core.CellValueType.NUMBER:core.CellValueType.STRING}}getSourceInfo(){return{sourceId:this.id,sourceType:DataBindingNodeTypeEnum.Object}}};__name(_ObjectSourceModel,"ObjectSourceModel");let ObjectSourceModel=_ObjectSourceModel;var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2"),_a;let SheetsBindingManager=(_a=class extends core.Disposable{constructor(_univerInstanceService,_sheetInterceptorService,_sheetsSelectionsService){super();__publicField(this,"modelMap",new Map);__publicField(this,"_cellBindInfoUpdate$",new rxjs.Subject);__publicField(this,"cellBindInfoUpdate$",this._cellBindInfoUpdate$.asObservable());this._univerInstanceService=_univerInstanceService,this._sheetInterceptorService=_sheetInterceptorService,this._sheetsSelectionsService=_sheetsSelectionsService,this._initRemoveCommand()}_initRemoveCommand(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:__name(command=>{const redos=[],undos=[],selections=this._sheetsSelectionsService.getCurrentSelections(),target=sheets.getSheetCommandTarget(this._univerInstanceService);if(!target||!selections||selections.length===0)return{redos:[],undos:[]};const{unitId,subUnitId}=target;return(command.id===sheets.ClearSelectionContentCommand.id||command.id===sheets.ClearSelectionAllCommand.id)&&selections.forEach(({range})=>{core.Range.foreach(range,(row,column)=>{this.getBindingNode(unitId,subUnitId,row,column)&&this.removeBindingNode(unitId,subUnitId,row,column)})}),{redos,undos}},"getMutations")}))}getBindingModelBySourceId(sourceId){const rs=[];return this.modelMap.forEach((subMap,unitId)=>{subMap.forEach((model,subunitId)=>{const nodes=model.getBindingNodesBySourceId(sourceId);if(nodes)for(const node of nodes)rs.push({unitId,subunitId,sourceId,nodeId:node.nodeId,row:node.row,column:node.column})})}),rs}addModel(unitId,subunitId,model){var _a4;this.modelMap.has(unitId)||this.modelMap.set(unitId,new Map),(_a4=this.modelMap.get(unitId))==null||_a4.set(subunitId,model)}getModel(unitId,subunitId){var _a4;return(_a4=this.modelMap.get(unitId))==null?void 0:_a4.get(subunitId)}setBindingNode(unitId,subunitId,node){let model=this.getModel(unitId,subunitId);model||(model=new SheetBindingModel,this.addModel(unitId,subunitId,model)),node.nodeId||(node.nodeId=core.generateRandomId());const{row,column}=node;if(row===void 0||column===void 0)throw new Error("row and column is required");const oldNode=model.getBindingNode(row,column),containHeader=node.type===DataBindingNodeTypeEnum.List?!!node.containHeader:!1;model.setBindingNode(row,column,{...node,row,column}),this._cellBindInfoUpdate$.next({unitId,subunitId,sourceId:node.sourceId,nodeId:node.nodeId,row,column,containHeader,changeType:oldNode?BindingSourceChangeTypeEnum.Update:BindingSourceChangeTypeEnum.Add,oldSourceId:oldNode==null?void 0:oldNode.sourceId,oldNodeContainHeader:(oldNode==null?void 0:oldNode.type)===DataBindingNodeTypeEnum.List?!!oldNode.containHeader:!1})}removeBindingNode(unitId,subunitId,row,column){const model=this.getModel(unitId,subunitId);if(model){const node=model.getBindingNode(row,column);node&&(model.removeBindingNode(row,column),this._cellBindInfoUpdate$.next({unitId,subunitId,sourceId:node.sourceId,nodeId:node.nodeId,row,column,changeType:BindingSourceChangeTypeEnum.Remove}))}}getBindingNode(unitId,subunitId,row,column){const model=this.getModel(unitId,subunitId);if(model)return model.getBindingNode(row,column)}getBindingNodeById(unitId,subunitId,nodeId){const model=this.getModel(unitId,subunitId);if(model)return model.getBindingNodeById(nodeId)}createModel(unitId,subunitId,json){const model=new SheetBindingModel(json);return this.addModel(unitId,subunitId,model),model}toJSON(unitId){const rs={},subMap=this.modelMap.get(unitId);return subMap&&subMap.forEach((model,subunitId)=>{rs[subunitId]=model.toJSON()}),rs}fromJSON(unitId,json){Object.entries(json).forEach(([subunitId,nodes])=>{this.createModel(unitId,subunitId,nodes)})}dispose(){this.modelMap.clear(),this._cellBindInfoUpdate$.complete()}},__name(_a,"SheetsBindingManager"),_a);SheetsBindingManager=__decorateClass$2([__decorateParam$2(0,core.IUniverInstanceService),__decorateParam$2(1,core.Inject(sheets.SheetInterceptorService)),__decorateParam$2(2,core.Inject(sheets.SheetsSelectionsService))],SheetsBindingManager);const _SheetsSourceManager=class _SheetsSourceManager extends core.Disposable{constructor(){super();__publicField(this,"sourceMap",new Map);__publicField(this,"_sourceDataUpdate$",new rxjs.Subject);__publicField(this,"sourceDataUpdate$",this._sourceDataUpdate$.asObservable())}_ensureUnitMap(unitId){let unit=this.sourceMap.get(unitId);return unit||(unit=new Map,this.sourceMap.set(unitId,unit)),unit}_getUnitMap(unitId){return this.sourceMap.get(unitId)}getSource(unitId,id){const unitMap=this._getUnitMap(unitId);return unitMap==null?void 0:unitMap.get(id)}createSource(unitId,type,isListObject,id){const sourceId=id===void 0?core.generateRandomId():id;let source;switch(type){case DataBindingNodeTypeEnum.List:source=new ListSourceModel(sourceId,isListObject);break;case DataBindingNodeTypeEnum.Object:source=new ObjectSourceModel(sourceId);break;default:throw new Error(`Invalid source type: ${type}`)}return this._ensureUnitMap(unitId).set(sourceId,source),source}updateSourceData(unitId,idOrInstance,data){const unitMap=this._getUnitMap(unitId),sourceId=idOrInstance instanceof SourceModelBase?idOrInstance.getId():idOrInstance,source=unitMap==null?void 0:unitMap.get(sourceId);if(source)source.setSourceData(data),this._sourceDataUpdate$.next({...source.getSourceInfo(),unitId,changeType:BindingSourceChangeTypeEnum.Add});else throw new Error(`Source not found: ${sourceId}`)}removeSource(unitId,id){const unitMap=this._getUnitMap(unitId),source=unitMap==null?void 0:unitMap.get(id);source&&(unitMap==null||unitMap.delete(id),this._sourceDataUpdate$.next({...source.getSourceInfo(),unitId,changeType:BindingSourceChangeTypeEnum.Remove}))}toJSON(unitId){const sourceList=[],unitMap=this._getUnitMap(unitId);if(unitMap)for(const source of unitMap.values())sourceList.push(source.toJSON());return sourceList}fromJSON(unitId,sources){const unitMap=this._ensureUnitMap(unitId);for(const source of sources){let model;switch(source.type){case DataBindingNodeTypeEnum.List:model=new ListSourceModel(source.id);break;case DataBindingNodeTypeEnum.Object:model=new ObjectSourceModel(source.id);break;default:throw new Error(`Invalid source type: ${source.type}`)}model.fromJSON(source),unitMap.set(source.id,model)}}dispose(){this._sourceDataUpdate$.complete(),this.sourceMap.clear()}};__name(_SheetsSourceManager,"SheetsSourceManager");let SheetsSourceManager=_SheetsSourceManager;var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1"),_a2;exports.SheetsSourceBindService=(_a2=class extends core.Disposable{constructor(_sheetInterceptorService,_sheetsBindingManager,_sheetsSourceManager){super();__publicField(this,"_bindingModel",BindModeEnum.Value);__publicField(this,"_bindModelRTreeCollection",new Map);this._sheetInterceptorService=_sheetInterceptorService,this._sheetsBindingManager=_sheetsBindingManager,this._sheetsSourceManager=_sheetsSourceManager,this._registerInterceptor(),this._registerSourceChange()}usePathMode(){this._bindingModel=BindModeEnum.Path}useValueMode(){this._bindingModel=BindModeEnum.Value}getBindingModel(){return this._bindingModel}createBindModel(unitId,subUnitId){return this._sheetsBindingManager.createModel(unitId,subUnitId)}setBindingNode(unitId,subUnitId,node){this._sheetsBindingManager.setBindingNode(unitId,subUnitId,node)}removeBindingNode(unitId,subUnitId,row,column){this._sheetsBindingManager.removeBindingNode(unitId,subUnitId,row,column)}getBindingNode(unitId,subUnitId,row,column){return this._sheetsBindingManager.getBindingNode(unitId,subUnitId,row,column)}getSource(unitId,id){return this._sheetsSourceManager.getSource(unitId,id)}createSource(unitId,type,isListObject,id){return this._sheetsSourceManager.createSource(unitId,type,isListObject,id)}getSourceBindingPathInfo(unitId){return{source:this._sheetsSourceManager.toJSON(unitId),cellBinding:this._sheetsBindingManager.toJSON(unitId)}}loadSourceBindingPathInfo(unitId,obj){this._sheetsSourceManager.fromJSON(unitId,obj.source),this._sheetsBindingManager.fromJSON(unitId,obj.cellBinding)}_ensureRTreeCollection(unitId){return this._bindModelRTreeCollection.has(unitId)||this._bindModelRTreeCollection.set(unitId,new core.RTree),this._bindModelRTreeCollection.get(unitId)}_getRTeeCollection(unitId){return this._bindModelRTreeCollection.get(unitId)}_registerSourceChange(){this.disposeWithMe(this._sheetsSourceManager.sourceDataUpdate$.subscribe(sourceInfo=>{const{sourceId,sourceType,unitId:sourceUnitId,changeType}=sourceInfo;if(sourceType===DataBindingNodeTypeEnum.List){if(changeType===BindingSourceChangeTypeEnum.Remove){const nodeInfo=this._sheetsBindingManager.getBindingModelBySourceId(sourceId),recordCount=sourceInfo.recordCount;for(const{unitId,subunitId,nodeId,row,column}of nodeInfo){const rTreeCollection=this._getRTeeCollection(sourceUnitId),node=this._sheetsBindingManager.getBindingNodeById(unitId,subunitId,nodeId);if(rTreeCollection&&(node==null?void 0:node.type)===DataBindingNodeTypeEnum.List){const offset=node.containHeader?0:1,range={startRow:row,startColumn:column,endRow:row+recordCount-offset,endColumn:column};rTreeCollection.remove({unitId,sheetId:subunitId,id:nodeId,range})}}return}if(changeType===BindingSourceChangeTypeEnum.Update){const oldRecordCount=sourceInfo.oldRecordCount,nodeInfo=this._sheetsBindingManager.getBindingModelBySourceId(sourceId);for(const{unitId,subunitId,nodeId,row,column}of nodeInfo){const rTreeCollection=this._getRTeeCollection(sourceUnitId),node=this._sheetsBindingManager.getBindingNodeById(unitId,subunitId,nodeId);if(rTreeCollection&&(node==null?void 0:node.type)===DataBindingNodeTypeEnum.List){const offset=node.containHeader?0:1,oldRange={startRow:row,startColumn:column,endRow:row+oldRecordCount-offset,endColumn:column},range={startRow:row,startColumn:column,endRow:row+sourceInfo.recordCount-offset,endColumn:column};rTreeCollection.remove({unitId,sheetId:subunitId,id:nodeId,range:oldRange}),rTreeCollection.insert({unitId,sheetId:subunitId,id:nodeId,range})}}return}const source=this._sheetsSourceManager.getSource(sourceUnitId,sourceId);if(source&&source.hasData()){const recordCount=source.getSourceInfo().recordCount,nodeInfo=this._sheetsBindingManager.getBindingModelBySourceId(sourceId);for(const{unitId,subunitId,nodeId,row,column}of nodeInfo){const rTreeCollection=this._ensureRTreeCollection(unitId),node=this._sheetsBindingManager.getBindingNodeById(unitId,subunitId,nodeId);if(rTreeCollection&&(node==null?void 0:node.type)===DataBindingNodeTypeEnum.List){const offset=node.containHeader?0:1,range={startRow:row,startColumn:column,endRow:row+recordCount-offset,endColumn:column};rTreeCollection.insert({unitId,sheetId:subunitId,id:nodeId,range})}}}}})),this.disposeWithMe(this._sheetsBindingManager.cellBindInfoUpdate$.subscribe(nodeInfo=>{const{unitId,subunitId,sourceId,nodeId,row,column,changeType,containHeader}=nodeInfo,rTreeCollection=this._ensureRTreeCollection(unitId),source=this._sheetsSourceManager.getSource(unitId,sourceId);if(source&&source.hasData()){const sourceInfo=source.getSourceInfo();if(sourceInfo.sourceType===DataBindingNodeTypeEnum.List){const recordCount=sourceInfo.recordCount,offset=containHeader?0:1,range={startRow:row,startColumn:column,endRow:row+recordCount-offset,endColumn:column};if(changeType===BindingSourceChangeTypeEnum.Add)rTreeCollection.insert({unitId,sheetId:subunitId,id:nodeId,range});else if(changeType===BindingSourceChangeTypeEnum.Remove)rTreeCollection.remove({unitId,sheetId:subunitId,id:nodeId,range});else if(changeType===BindingSourceChangeTypeEnum.Update){const oldSourceId=nodeInfo.oldSourceId,offset2=nodeInfo.oldNodeContainHeader?0:1,oldSource=this._sheetsSourceManager.getSource(unitId,oldSourceId);if(oldSource&&oldSource.hasData()){const oldRecordCount=oldSource.getSourceInfo().recordCount,oldRange={startRow:row,startColumn:column,endRow:row+oldRecordCount-offset2,endColumn:column};rTreeCollection.remove({unitId,sheetId:subunitId,id:nodeId,range:oldRange})}rTreeCollection.insert({unitId,sheetId:subunitId,id:nodeId,range})}}}}))}_getPathModeCellValue(unitId,subUnitId,row,col){const model=this._sheetsBindingManager.getModel(unitId,subUnitId),node=model==null?void 0:model.getBindingNode(row,col);if(node){const nodeType=node.type;if(nodeType===DataBindingNodeTypeEnum.List)return{v:`#{${node.path}}`,s:{cl:{rgb:"blue"}}};if(nodeType===DataBindingNodeTypeEnum.Object)return{v:`[${node.path}]`,s:{cl:{rgb:"blue"}}}}}_getValueModeCellValue(unitId,subUnitId,row,col){const model=this._sheetsBindingManager.getModel(unitId,subUnitId);if(model){const node=model.getBindingNode(row,col);if(node){const{sourceId}=node,source=this._sheetsSourceManager.getSource(unitId,sourceId);if(source&&source.hasData())return(source==null?void 0:source.getData(node,row,col))||{v:""}}}const rTreeCollection=this._getRTeeCollection(unitId);if(model&&rTreeCollection){const range={startRow:row,startColumn:col,endRow:row,endColumn:col},nodeIds=Array.from(rTreeCollection.bulkSearch([{unitId,sheetId:subUnitId,range}]));if(nodeIds.length>0){const node=model.getBindingNodeById(nodeIds[0]);if(node){const{sourceId}=node,source=this._sheetsSourceManager.getSource(unitId,sourceId);if(source&&source.hasData())return(source==null?void 0:source.getData(node,row,col))||{v:""}}}}}getBindingModelBySourceId(sourceId){return this._sheetsBindingManager.getBindingModelBySourceId(sourceId)}_registerInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(sheets.INTERCEPTOR_POINT.CELL_CONTENT,{effect:core.InterceptorEffectEnum.Value|core.InterceptorEffectEnum.Style,priority:102,handler:__name((cell,context,next)=>{const{row,col,unitId,subUnitId,workbook}=context;let value=null;if(this._bindingModel===BindModeEnum.Path?value=this._getPathModeCellValue(unitId,subUnitId,row,col):value=this._getValueModeCellValue(unitId,subUnitId,row,col),value!==null){const newStyle={...(typeof(cell==null?void 0:cell.s)=="string"?workbook.getStyles().get(cell==null?void 0:cell.s):cell==null?void 0:cell.s)||{}};return value&&value.s&&Object.assign(newStyle,value.s),next({...cell,...value,s:newStyle})}return next(cell)},"handler")}))}dispose(){this._bindModelRTreeCollection.clear()}},__name(_a2,"SheetsSourceBindService"),_a2);exports.SheetsSourceBindService=__decorateClass$1([__decorateParam$1(0,core.Inject(sheets.SheetInterceptorService)),__decorateParam$1(1,core.Inject(SheetsBindingManager)),__decorateParam$1(2,core.Inject(SheetsSourceManager))],exports.SheetsSourceBindService);var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),_a3;exports.UniverSheetsBindingSourcePlugin=(_a3=class extends core.Plugin{constructor(_config={},_injector,_configService){super(),this._config=_config,this._injector=_injector,this._configService=_configService}onStarting(){[[SheetsBindingManager],[SheetsSourceManager],[exports.SheetsSourceBindService]].forEach(d=>this._injector.add(d))}onReady(){core.touchDependencies(this._injector,[[SheetsBindingManager],[SheetsSourceManager],[exports.SheetsSourceBindService]])}},__name(_a3,"UniverSheetsBindingSourcePlugin"),__publicField(_a3,"type",core.UniverInstanceType.UNIVER_SHEET),__publicField(_a3,"pluginName","SHEET_BINDING_SOURCE_PLUGIN"),_a3);exports.UniverSheetsBindingSourcePlugin=__decorateClass([__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService)],exports.UniverSheetsBindingSourcePlugin);exports.BindModeEnum=BindModeEnum;exports.BindingModel=SheetBindingModel;exports.DataBindingNodeTypeEnum=DataBindingNodeTypeEnum;exports.SheetsSourceManager=SheetsSourceManager;exports.SourceModelBase=SourceModelBase;
package/lib/umd/facade.js CHANGED
@@ -1 +1 @@
1
- (function(o,t){typeof exports=="object"&&typeof module<"u"?t(require("@univerjs/core"),require("@univerjs/sheets-source-binding"),require("@univerjs/sheets/facade")):typeof define=="function"&&define.amd?define(["@univerjs/core","@univerjs/sheets-source-binding","@univerjs/sheets/facade"],t):(o=typeof globalThis<"u"?globalThis:o||self,t(o.UniverCore,o.UniverSheetsSourceBinding,o.UniverSheetsFacade))})(this,function(o,t,c){"use strict";class S extends o.FEnum{get DataBindingNodeTypeEnum(){return t.DataBindingNodeTypeEnum}get BindModeEnum(){return t.BindModeEnum}}o.FEnum.extend(S);class u extends c.FWorkbook{createSource(e,n,i){return this._injector.get(t.SheetsSourceBindService).createSource(this.getId(),e,n,i)}getSource(e){return this._injector.get(t.SheetsSourceBindService).getSource(this.getId(),e)}setSourceData(e,n){this._injector.get(t.SheetsSourceManager).updateSourceData(this.getId(),e,n)}usePathMode(){this._injector.get(t.SheetsSourceBindService).usePathMode()}useValueMode(){this._injector.get(t.SheetsSourceBindService).useValueMode()}loadSourceBindingPathInfo(e){this._injector.get(t.SheetsSourceBindService).loadSourceBindingPathInfo(this.getId(),e)}saveSourceBindingPathInfo(){return this._injector.get(t.SheetsSourceBindService).getSourceBindingPathInfo(this.getId())}getBindingModelBySourceId(e){return this._injector.get(t.SheetsSourceBindService).getBindingModelBySourceId(e)}}c.FWorkbook.extend(u);class h extends c.FWorksheet{setBindingNode(e){const i=this._injector.get(t.SheetsSourceBindService),r=this._workbook.getUnitId();i.setBindingNode(r,this.getSheetId(),e)}removeBindingNode(e,n){const r=this._injector.get(t.SheetsSourceBindService),s=this._workbook.getUnitId();r.removeBindingNode(s,this.getSheetId(),e,n)}getBindingNode(e,n){const r=this._injector.get(t.SheetsSourceBindService),s=this._workbook.getUnitId();return r.getBindingNode(s,this.getSheetId(),e,n)}}c.FWorksheet.extend(h)});
1
+ (function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(require("@univerjs/core"),require("@univerjs/sheets-source-binding"),require("@univerjs/sheets/facade")):typeof define=="function"&&define.amd?define(["@univerjs/core","@univerjs/sheets-source-binding","@univerjs/sheets/facade"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverCore,global.UniverSheetsSourceBinding,global.UniverSheetsFacade))})(this,function(core,sheetsSourceBinding,facade){"use strict";var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});const _FSourceBindingEnum=class _FSourceBindingEnum extends core.FEnum{get DataBindingNodeTypeEnum(){return sheetsSourceBinding.DataBindingNodeTypeEnum}get BindModeEnum(){return sheetsSourceBinding.BindModeEnum}};__name(_FSourceBindingEnum,"FSourceBindingEnum");let FSourceBindingEnum=_FSourceBindingEnum;core.FEnum.extend(FSourceBindingEnum);const _FWorkbookSourceBinding=class _FWorkbookSourceBinding extends facade.FWorkbook{createSource(type,isListObject,id){return this._injector.get(sheetsSourceBinding.SheetsSourceBindService).createSource(this.getId(),type,isListObject,id)}getSource(sourceId){return this._injector.get(sheetsSourceBinding.SheetsSourceBindService).getSource(this.getId(),sourceId)}setSourceData(sourceId,data){this._injector.get(sheetsSourceBinding.SheetsSourceManager).updateSourceData(this.getId(),sourceId,data)}usePathMode(){this._injector.get(sheetsSourceBinding.SheetsSourceBindService).usePathMode()}useValueMode(){this._injector.get(sheetsSourceBinding.SheetsSourceBindService).useValueMode()}loadSourceBindingPathInfo(obj){this._injector.get(sheetsSourceBinding.SheetsSourceBindService).loadSourceBindingPathInfo(this.getId(),obj)}saveSourceBindingPathInfo(){return this._injector.get(sheetsSourceBinding.SheetsSourceBindService).getSourceBindingPathInfo(this.getId())}getBindingModelBySourceId(sourceId){return this._injector.get(sheetsSourceBinding.SheetsSourceBindService).getBindingModelBySourceId(sourceId)}};__name(_FWorkbookSourceBinding,"FWorkbookSourceBinding");let FWorkbookSourceBinding=_FWorkbookSourceBinding;facade.FWorkbook.extend(FWorkbookSourceBinding);const _FWorksheetSourceBinding=class _FWorksheetSourceBinding extends facade.FWorksheet{setBindingNode(bindingNode){const sheetsSourceBindService=this._injector.get(sheetsSourceBinding.SheetsSourceBindService),unitId=this._workbook.getUnitId();sheetsSourceBindService.setBindingNode(unitId,this.getSheetId(),bindingNode)}removeBindingNode(row,column){const sheetsSourceBindService=this._injector.get(sheetsSourceBinding.SheetsSourceBindService),unitId=this._workbook.getUnitId();sheetsSourceBindService.removeBindingNode(unitId,this.getSheetId(),row,column)}getBindingNode(row,column){const sheetsSourceBindService=this._injector.get(sheetsSourceBinding.SheetsSourceBindService),unitId=this._workbook.getUnitId();return sheetsSourceBindService.getBindingNode(unitId,this.getSheetId(),row,column)}};__name(_FWorksheetSourceBinding,"FWorksheetSourceBinding");let FWorksheetSourceBinding=_FWorksheetSourceBinding;facade.FWorksheet.extend(FWorksheetSourceBinding)});
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 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(global,factory){typeof exports=="object"&&typeof module<"u"?factory(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverSheetsSourceBinding={},global.UniverCore,global.UniverSheets,global.rxjs))})(this,function(exports2,core,sheets,rxjs){"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);var _a,_b,_c;const _SheetBindingModel=class _SheetBindingModel{constructor(json){__publicField(this,"_matrix",{});__publicField(this,"_nodeMap",new Map);__publicField(this,"_sourceIdMap",new Map);json&&this._init(json)}_init(json){this.fromJSON(json)}getBindingNodesBySourceId(sourceId){const nodeIds=this._sourceIdMap.get(sourceId);if(nodeIds)return nodeIds.map(nodeId=>this._nodeMap.get(nodeId))}setBindingNode(row,column,node){this._matrix[row]||(this._matrix[row]={}),this._matrix[row][column]||(this._matrix[row][column]=node),this._nodeMap.set(node.nodeId,node);const nodeIds=this._sourceIdMap.get(node.sourceId);nodeIds?nodeIds.push(node.nodeId):this._sourceIdMap.set(node.sourceId,[node.nodeId])}getBindingNode(row,column){var _a2;return(_a2=this._matrix[row])==null?void 0:_a2[column]}removeBindingNode(row,column){var _a2;const node=(_a2=this._matrix[row])==null?void 0:_a2[column];if(node){this._matrix[row][column]=void 0,this._nodeMap.delete(node.nodeId);const nodeIds=this._sourceIdMap.get(node.sourceId);if(nodeIds){const index=nodeIds.indexOf(node.nodeId);index>=0&&nodeIds.splice(index,1),nodeIds.length===0&&this._sourceIdMap.delete(node.sourceId)}}}getBindingNodeById(nodeId){return this._nodeMap.get(nodeId)}fromJSON(nodes){nodes.forEach(node=>{this.setBindingNode(node.row,node.column,node)})}toJSON(){return Array.from(this._nodeMap.values())}};__name(_SheetBindingModel,"SheetBindingModel");let SheetBindingModel=_SheetBindingModel;var DataBindingNodeTypeEnum=(DataBindingNodeTypeEnum2=>(DataBindingNodeTypeEnum2.List="list",DataBindingNodeTypeEnum2.Object="object",DataBindingNodeTypeEnum2))(DataBindingNodeTypeEnum||{}),BindModeEnum=(BindModeEnum2=>(BindModeEnum2.Path="path",BindModeEnum2.Value="value",BindModeEnum2))(BindModeEnum||{}),BindingSourceChangeTypeEnum=(BindingSourceChangeTypeEnum2=>(BindingSourceChangeTypeEnum2.Add="add",BindingSourceChangeTypeEnum2.Remove="remove",BindingSourceChangeTypeEnum2.Update="update",BindingSourceChangeTypeEnum2))(BindingSourceChangeTypeEnum||{});function isValidDate(date){return date instanceof Date&&!isNaN(date.getTime())}__name(isValidDate,"isValidDate");function transformDate(dateString){const date=new Date(dateString);if(!isValidDate(date))return dateString;const baseDate=new Date(Date.UTC(1900,0,1,0,0,0)),leapDayDate=new Date(Date.UTC(1900,1,28,0,0,0));let dayDifference=(date.getTime()-baseDate.getTime())/(1e3*3600*24);return date>leapDayDate&&(dayDifference+=1),dayDifference+1}__name(transformDate,"transformDate");const _SourceModelBase=class _SourceModelBase{constructor(id){__publicField(this,"_data");__publicField(this,"id");__publicField(this,"_hasData",!1);__publicField(this,"type");this.id=id}getId(){return this.id}getType(){return this.type}hasData(){return this._hasData}setSourceData(data){this._data=data,this._hasData=!0}toJSON(){return{id:this.id,type:this.type}}fromJSON(info){this.id=info.id,this.type=info.type}};__name(_SourceModelBase,"SourceModelBase");let SourceModelBase=_SourceModelBase;const _ListSourceModel=class _ListSourceModel extends SourceModelBase{constructor(id,isListObject){super(id);__publicField(this,"type",DataBindingNodeTypeEnum.List);__publicField(this,"_isListObject");__publicField(this,"_fieldIndexMap",new Map);__publicField(this,"_data",{fields:[],records:[]});this._isListObject=isListObject!=null?isListObject:!0}toggleListObject(isListObject){this._isListObject=isListObject}getData(node,row){const{path,row:baseRow,containHeader}=node,colIndex=this._fieldIndexMap.get(path),rowIndex=row-baseRow;if(containHeader&&rowIndex===0)return{v:this._data.fields[colIndex]};let data;const offset=containHeader?1:0;return this._isListObject?data=this._data.records[rowIndex-offset][path]:data=this._data.records[rowIndex-offset][colIndex],node.isDate===!0?{v:transformDate(data),s:{n:{pattern:"yyyy-m-d am/pm h:mm"}},t:core.CellValueType.NUMBER}:{t:typeof data=="number"?core.CellValueType.NUMBER:core.CellValueType.STRING,v:data}}setSourceData(data){super.setSourceData(data);const{fields}=data;this._fieldIndexMap.clear(),fields.forEach((field,index)=>{this._fieldIndexMap.set(field,index)})}getSourceInfo(){return{sourceId:this.id,sourceType:this.type,fields:this._data.fields,recordCount:this._data.records.length}}};__name(_ListSourceModel,"ListSourceModel");let ListSourceModel=_ListSourceModel;const _ObjectSourceModel=class _ObjectSourceModel extends SourceModelBase{constructor(id){super(id);__publicField(this,"type",DataBindingNodeTypeEnum.Object)}getData(node){const paths=node.path.split(".");let data=this._data;for(const p of paths)if(data=data[p],data===void 0)return null;return node.isDate===!0?{v:transformDate(data),s:{n:{pattern:"yyyy-m-d am/pm h:mm"}},t:core.CellValueType.NUMBER}:{v:data,t:typeof data=="number"?core.CellValueType.NUMBER:core.CellValueType.STRING}}getSourceInfo(){return{sourceId:this.id,sourceType:DataBindingNodeTypeEnum.Object}}};__name(_ObjectSourceModel,"ObjectSourceModel");let ObjectSourceModel=_ObjectSourceModel;var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2");let SheetsBindingManager=(_a=class extends core.Disposable{constructor(_univerInstanceService,_sheetInterceptorService,_sheetsSelectionsService){super();__publicField(this,"modelMap",new Map);__publicField(this,"_cellBindInfoUpdate$",new rxjs.Subject);__publicField(this,"cellBindInfoUpdate$",this._cellBindInfoUpdate$.asObservable());this._univerInstanceService=_univerInstanceService,this._sheetInterceptorService=_sheetInterceptorService,this._sheetsSelectionsService=_sheetsSelectionsService,this._initRemoveCommand()}_initRemoveCommand(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:__name(command=>{const redos=[],undos=[],selections=this._sheetsSelectionsService.getCurrentSelections(),target=sheets.getSheetCommandTarget(this._univerInstanceService);if(!target||!selections||selections.length===0)return{redos:[],undos:[]};const{unitId,subUnitId}=target;return(command.id===sheets.ClearSelectionContentCommand.id||command.id===sheets.ClearSelectionAllCommand.id)&&selections.forEach(({range})=>{core.Range.foreach(range,(row,column)=>{this.getBindingNode(unitId,subUnitId,row,column)&&this.removeBindingNode(unitId,subUnitId,row,column)})}),{redos,undos}},"getMutations")}))}getBindingModelBySourceId(sourceId){const rs=[];return this.modelMap.forEach((subMap,unitId)=>{subMap.forEach((model,subunitId)=>{const nodes=model.getBindingNodesBySourceId(sourceId);if(nodes)for(const node of nodes)rs.push({unitId,subunitId,sourceId,nodeId:node.nodeId,row:node.row,column:node.column})})}),rs}addModel(unitId,subunitId,model){var _a2;this.modelMap.has(unitId)||this.modelMap.set(unitId,new Map),(_a2=this.modelMap.get(unitId))==null||_a2.set(subunitId,model)}getModel(unitId,subunitId){var _a2;return(_a2=this.modelMap.get(unitId))==null?void 0:_a2.get(subunitId)}setBindingNode(unitId,subunitId,node){let model=this.getModel(unitId,subunitId);model||(model=new SheetBindingModel,this.addModel(unitId,subunitId,model)),node.nodeId||(node.nodeId=core.generateRandomId());const{row,column}=node;if(row===void 0||column===void 0)throw new Error("row and column is required");const oldNode=model.getBindingNode(row,column),containHeader=node.type===DataBindingNodeTypeEnum.List?!!node.containHeader:!1;model.setBindingNode(row,column,{...node,row,column}),this._cellBindInfoUpdate$.next({unitId,subunitId,sourceId:node.sourceId,nodeId:node.nodeId,row,column,containHeader,changeType:oldNode?BindingSourceChangeTypeEnum.Update:BindingSourceChangeTypeEnum.Add,oldSourceId:oldNode==null?void 0:oldNode.sourceId,oldNodeContainHeader:(oldNode==null?void 0:oldNode.type)===DataBindingNodeTypeEnum.List?!!oldNode.containHeader:!1})}removeBindingNode(unitId,subunitId,row,column){const model=this.getModel(unitId,subunitId);if(model){const node=model.getBindingNode(row,column);node&&(model.removeBindingNode(row,column),this._cellBindInfoUpdate$.next({unitId,subunitId,sourceId:node.sourceId,nodeId:node.nodeId,row,column,changeType:BindingSourceChangeTypeEnum.Remove}))}}getBindingNode(unitId,subunitId,row,column){const model=this.getModel(unitId,subunitId);if(model)return model.getBindingNode(row,column)}getBindingNodeById(unitId,subunitId,nodeId){const model=this.getModel(unitId,subunitId);if(model)return model.getBindingNodeById(nodeId)}createModel(unitId,subunitId,json){const model=new SheetBindingModel(json);return this.addModel(unitId,subunitId,model),model}toJSON(unitId){const rs={},subMap=this.modelMap.get(unitId);return subMap&&subMap.forEach((model,subunitId)=>{rs[subunitId]=model.toJSON()}),rs}fromJSON(unitId,json){Object.entries(json).forEach(([subunitId,nodes])=>{this.createModel(unitId,subunitId,nodes)})}dispose(){this.modelMap.clear(),this._cellBindInfoUpdate$.complete()}},__name(_a,"SheetsBindingManager"),_a);SheetsBindingManager=__decorateClass$2([__decorateParam$2(0,core.IUniverInstanceService),__decorateParam$2(1,core.Inject(sheets.SheetInterceptorService)),__decorateParam$2(2,core.Inject(sheets.SheetsSelectionsService))],SheetsBindingManager);const _SheetsSourceManager=class _SheetsSourceManager extends core.Disposable{constructor(){super();__publicField(this,"sourceMap",new Map);__publicField(this,"_sourceDataUpdate$",new rxjs.Subject);__publicField(this,"sourceDataUpdate$",this._sourceDataUpdate$.asObservable())}_ensureUnitMap(unitId){let unit=this.sourceMap.get(unitId);return unit||(unit=new Map,this.sourceMap.set(unitId,unit)),unit}_getUnitMap(unitId){return this.sourceMap.get(unitId)}getSource(unitId,id){const unitMap=this._getUnitMap(unitId);return unitMap==null?void 0:unitMap.get(id)}createSource(unitId,type,isListObject,id){const sourceId=id===void 0?core.generateRandomId():id;let source;switch(type){case DataBindingNodeTypeEnum.List:source=new ListSourceModel(sourceId,isListObject);break;case DataBindingNodeTypeEnum.Object:source=new ObjectSourceModel(sourceId);break;default:throw new Error(`Invalid source type: ${type}`)}return this._ensureUnitMap(unitId).set(sourceId,source),source}updateSourceData(unitId,idOrInstance,data){const unitMap=this._getUnitMap(unitId),sourceId=idOrInstance instanceof SourceModelBase?idOrInstance.getId():idOrInstance,source=unitMap==null?void 0:unitMap.get(sourceId);if(source)source.setSourceData(data),this._sourceDataUpdate$.next({...source.getSourceInfo(),unitId,changeType:BindingSourceChangeTypeEnum.Add});else throw new Error(`Source not found: ${sourceId}`)}removeSource(unitId,id){const unitMap=this._getUnitMap(unitId),source=unitMap==null?void 0:unitMap.get(id);source&&(unitMap==null||unitMap.delete(id),this._sourceDataUpdate$.next({...source.getSourceInfo(),unitId,changeType:BindingSourceChangeTypeEnum.Remove}))}toJSON(unitId){const sourceList=[],unitMap=this._getUnitMap(unitId);if(unitMap)for(const source of unitMap.values())sourceList.push(source.toJSON());return sourceList}fromJSON(unitId,sources){const unitMap=this._ensureUnitMap(unitId);for(const source of sources){let model;switch(source.type){case DataBindingNodeTypeEnum.List:model=new ListSourceModel(source.id);break;case DataBindingNodeTypeEnum.Object:model=new ObjectSourceModel(source.id);break;default:throw new Error(`Invalid source type: ${source.type}`)}model.fromJSON(source),unitMap.set(source.id,model)}}dispose(){this._sourceDataUpdate$.complete(),this.sourceMap.clear()}};__name(_SheetsSourceManager,"SheetsSourceManager");let SheetsSourceManager=_SheetsSourceManager;var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1");exports2.SheetsSourceBindService=(_b=class extends core.Disposable{constructor(_sheetInterceptorService,_sheetsBindingManager,_sheetsSourceManager){super();__publicField(this,"_bindingModel",BindModeEnum.Value);__publicField(this,"_bindModelRTreeCollection",new Map);this._sheetInterceptorService=_sheetInterceptorService,this._sheetsBindingManager=_sheetsBindingManager,this._sheetsSourceManager=_sheetsSourceManager,this._registerInterceptor(),this._registerSourceChange()}usePathMode(){this._bindingModel=BindModeEnum.Path}useValueMode(){this._bindingModel=BindModeEnum.Value}getBindingModel(){return this._bindingModel}createBindModel(unitId,subUnitId){return this._sheetsBindingManager.createModel(unitId,subUnitId)}setBindingNode(unitId,subUnitId,node){this._sheetsBindingManager.setBindingNode(unitId,subUnitId,node)}removeBindingNode(unitId,subUnitId,row,column){this._sheetsBindingManager.removeBindingNode(unitId,subUnitId,row,column)}getBindingNode(unitId,subUnitId,row,column){return this._sheetsBindingManager.getBindingNode(unitId,subUnitId,row,column)}getSource(unitId,id){return this._sheetsSourceManager.getSource(unitId,id)}createSource(unitId,type,isListObject,id){return this._sheetsSourceManager.createSource(unitId,type,isListObject,id)}getSourceBindingPathInfo(unitId){return{source:this._sheetsSourceManager.toJSON(unitId),cellBinding:this._sheetsBindingManager.toJSON(unitId)}}loadSourceBindingPathInfo(unitId,obj){this._sheetsSourceManager.fromJSON(unitId,obj.source),this._sheetsBindingManager.fromJSON(unitId,obj.cellBinding)}_ensureRTreeCollection(unitId){return this._bindModelRTreeCollection.has(unitId)||this._bindModelRTreeCollection.set(unitId,new core.RTree),this._bindModelRTreeCollection.get(unitId)}_getRTeeCollection(unitId){return this._bindModelRTreeCollection.get(unitId)}_registerSourceChange(){this.disposeWithMe(this._sheetsSourceManager.sourceDataUpdate$.subscribe(sourceInfo=>{const{sourceId,sourceType,unitId:sourceUnitId,changeType}=sourceInfo;if(sourceType===DataBindingNodeTypeEnum.List){if(changeType===BindingSourceChangeTypeEnum.Remove){const nodeInfo=this._sheetsBindingManager.getBindingModelBySourceId(sourceId),recordCount=sourceInfo.recordCount;for(const{unitId,subunitId,nodeId,row,column}of nodeInfo){const rTreeCollection=this._getRTeeCollection(sourceUnitId),node=this._sheetsBindingManager.getBindingNodeById(unitId,subunitId,nodeId);if(rTreeCollection&&(node==null?void 0:node.type)===DataBindingNodeTypeEnum.List){const offset=node.containHeader?0:1,range={startRow:row,startColumn:column,endRow:row+recordCount-offset,endColumn:column};rTreeCollection.remove({unitId,sheetId:subunitId,id:nodeId,range})}}return}if(changeType===BindingSourceChangeTypeEnum.Update){const oldRecordCount=sourceInfo.oldRecordCount,nodeInfo=this._sheetsBindingManager.getBindingModelBySourceId(sourceId);for(const{unitId,subunitId,nodeId,row,column}of nodeInfo){const rTreeCollection=this._getRTeeCollection(sourceUnitId),node=this._sheetsBindingManager.getBindingNodeById(unitId,subunitId,nodeId);if(rTreeCollection&&(node==null?void 0:node.type)===DataBindingNodeTypeEnum.List){const offset=node.containHeader?0:1,oldRange={startRow:row,startColumn:column,endRow:row+oldRecordCount-offset,endColumn:column},range={startRow:row,startColumn:column,endRow:row+sourceInfo.recordCount-offset,endColumn:column};rTreeCollection.remove({unitId,sheetId:subunitId,id:nodeId,range:oldRange}),rTreeCollection.insert({unitId,sheetId:subunitId,id:nodeId,range})}}return}const source=this._sheetsSourceManager.getSource(sourceUnitId,sourceId);if(source&&source.hasData()){const recordCount=source.getSourceInfo().recordCount,nodeInfo=this._sheetsBindingManager.getBindingModelBySourceId(sourceId);for(const{unitId,subunitId,nodeId,row,column}of nodeInfo){const rTreeCollection=this._ensureRTreeCollection(unitId),node=this._sheetsBindingManager.getBindingNodeById(unitId,subunitId,nodeId);if(rTreeCollection&&(node==null?void 0:node.type)===DataBindingNodeTypeEnum.List){const offset=node.containHeader?0:1,range={startRow:row,startColumn:column,endRow:row+recordCount-offset,endColumn:column};rTreeCollection.insert({unitId,sheetId:subunitId,id:nodeId,range})}}}}})),this.disposeWithMe(this._sheetsBindingManager.cellBindInfoUpdate$.subscribe(nodeInfo=>{const{unitId,subunitId,sourceId,nodeId,row,column,changeType,containHeader}=nodeInfo,rTreeCollection=this._ensureRTreeCollection(unitId),source=this._sheetsSourceManager.getSource(unitId,sourceId);if(source&&source.hasData()){const sourceInfo=source.getSourceInfo();if(sourceInfo.sourceType===DataBindingNodeTypeEnum.List){const recordCount=sourceInfo.recordCount,offset=containHeader?0:1,range={startRow:row,startColumn:column,endRow:row+recordCount-offset,endColumn:column};if(changeType===BindingSourceChangeTypeEnum.Add)rTreeCollection.insert({unitId,sheetId:subunitId,id:nodeId,range});else if(changeType===BindingSourceChangeTypeEnum.Remove)rTreeCollection.remove({unitId,sheetId:subunitId,id:nodeId,range});else if(changeType===BindingSourceChangeTypeEnum.Update){const oldSourceId=nodeInfo.oldSourceId,offset2=nodeInfo.oldNodeContainHeader?0:1,oldSource=this._sheetsSourceManager.getSource(unitId,oldSourceId);if(oldSource&&oldSource.hasData()){const oldRecordCount=oldSource.getSourceInfo().recordCount,oldRange={startRow:row,startColumn:column,endRow:row+oldRecordCount-offset2,endColumn:column};rTreeCollection.remove({unitId,sheetId:subunitId,id:nodeId,range:oldRange})}rTreeCollection.insert({unitId,sheetId:subunitId,id:nodeId,range})}}}}))}_getPathModeCellValue(unitId,subUnitId,row,col){const model=this._sheetsBindingManager.getModel(unitId,subUnitId),node=model==null?void 0:model.getBindingNode(row,col);if(node){const nodeType=node.type;if(nodeType===DataBindingNodeTypeEnum.List)return{v:`#{${node.path}}`,s:{cl:{rgb:"blue"}}};if(nodeType===DataBindingNodeTypeEnum.Object)return{v:`[${node.path}]`,s:{cl:{rgb:"blue"}}}}}_getValueModeCellValue(unitId,subUnitId,row,col){const model=this._sheetsBindingManager.getModel(unitId,subUnitId);if(model){const node=model.getBindingNode(row,col);if(node){const{sourceId}=node,source=this._sheetsSourceManager.getSource(unitId,sourceId);if(source&&source.hasData())return(source==null?void 0:source.getData(node,row,col))||{v:""}}}const rTreeCollection=this._getRTeeCollection(unitId);if(model&&rTreeCollection){const range={startRow:row,startColumn:col,endRow:row,endColumn:col},nodeIds=Array.from(rTreeCollection.bulkSearch([{unitId,sheetId:subUnitId,range}]));if(nodeIds.length>0){const node=model.getBindingNodeById(nodeIds[0]);if(node){const{sourceId}=node,source=this._sheetsSourceManager.getSource(unitId,sourceId);if(source&&source.hasData())return(source==null?void 0:source.getData(node,row,col))||{v:""}}}}}getBindingModelBySourceId(sourceId){return this._sheetsBindingManager.getBindingModelBySourceId(sourceId)}_registerInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(sheets.INTERCEPTOR_POINT.CELL_CONTENT,{effect:core.InterceptorEffectEnum.Value|core.InterceptorEffectEnum.Style,priority:102,handler:__name((cell,context,next)=>{const{row,col,unitId,subUnitId,workbook}=context;let value=null;if(this._bindingModel===BindModeEnum.Path?value=this._getPathModeCellValue(unitId,subUnitId,row,col):value=this._getValueModeCellValue(unitId,subUnitId,row,col),value!==null){const newStyle={...(typeof(cell==null?void 0:cell.s)=="string"?workbook.getStyles().get(cell==null?void 0:cell.s):cell==null?void 0:cell.s)||{}};return value&&value.s&&Object.assign(newStyle,value.s),next({...cell,...value,s:newStyle})}return next(cell)},"handler")}))}dispose(){this._bindModelRTreeCollection.clear()}},__name(_b,"SheetsSourceBindService"),_b),exports2.SheetsSourceBindService=__decorateClass$1([__decorateParam$1(0,core.Inject(sheets.SheetInterceptorService)),__decorateParam$1(1,core.Inject(SheetsBindingManager)),__decorateParam$1(2,core.Inject(SheetsSourceManager))],exports2.SheetsSourceBindService);var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam");exports2.UniverSheetsBindingSourcePlugin=(_c=class extends core.Plugin{constructor(_config={},_injector,_configService){super(),this._config=_config,this._injector=_injector,this._configService=_configService}onStarting(){[[SheetsBindingManager],[SheetsSourceManager],[exports2.SheetsSourceBindService]].forEach(d=>this._injector.add(d))}onReady(){core.touchDependencies(this._injector,[[SheetsBindingManager],[SheetsSourceManager],[exports2.SheetsSourceBindService]])}},__name(_c,"UniverSheetsBindingSourcePlugin"),__publicField(_c,"type",core.UniverInstanceType.UNIVER_SHEET),__publicField(_c,"pluginName","SHEET_BINDING_SOURCE_PLUGIN"),_c),exports2.UniverSheetsBindingSourcePlugin=__decorateClass([__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService)],exports2.UniverSheetsBindingSourcePlugin),exports2.BindModeEnum=BindModeEnum,exports2.BindingModel=SheetBindingModel,exports2.DataBindingNodeTypeEnum=DataBindingNodeTypeEnum,exports2.SheetsSourceManager=SheetsSourceManager,exports2.SourceModelBase=SourceModelBase,Object.defineProperty(exports2,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.202501210925",
3
+ "version": "0.5.5-nightly.202501220324",
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.202501210925",
55
- "@univerjs/sheets": "0.5.5-nightly.202501210925"
54
+ "@univerjs/core": "0.5.5-nightly.202501220324",
55
+ "@univerjs/sheets": "0.5.5-nightly.202501220324"
56
56
  },
57
57
  "devDependencies": {
58
58
  "rxjs": "^7.8.1",