@univerjs/sheets-source-binding 0.5.5-nightly.202501241606 → 0.6.0-nightly.202501251605

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";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);
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);
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
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;
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;
package/lib/es/facade.js CHANGED
@@ -1,62 +1,54 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
3
- import { FEnum } from "@univerjs/core";
4
- import { DataBindingNodeTypeEnum, BindModeEnum, SheetsSourceBindService, SheetsSourceManager } from "@univerjs/sheets-source-binding";
5
- import { FWorkbook, FWorksheet } from "@univerjs/sheets/facade";
6
- const _FSourceBindingEnum = class _FSourceBindingEnum extends FEnum {
1
+ import { FEnum as s } from "@univerjs/core";
2
+ import { DataBindingNodeTypeEnum as S, BindModeEnum as h, SheetsSourceBindService as n, SheetsSourceManager as g } from "@univerjs/sheets-source-binding";
3
+ import { FWorkbook as d, FWorksheet as u } from "@univerjs/sheets/facade";
4
+ class B extends s {
7
5
  get DataBindingNodeTypeEnum() {
8
- return DataBindingNodeTypeEnum;
6
+ return S;
9
7
  }
10
8
  get BindModeEnum() {
11
- return BindModeEnum;
9
+ return h;
12
10
  }
13
- };
14
- __name(_FSourceBindingEnum, "FSourceBindingEnum");
15
- let FSourceBindingEnum = _FSourceBindingEnum;
16
- FEnum.extend(FSourceBindingEnum);
17
- const _FWorkbookSourceBinding = class _FWorkbookSourceBinding extends FWorkbook {
18
- createSource(type, isListObject, id) {
19
- return this._injector.get(SheetsSourceBindService).createSource(this.getId(), type, isListObject, id);
11
+ }
12
+ s.extend(B);
13
+ class j extends d {
14
+ createSource(e, t, o) {
15
+ return this._injector.get(n).createSource(this.getId(), e, t, o);
20
16
  }
21
- getSource(sourceId) {
22
- return this._injector.get(SheetsSourceBindService).getSource(this.getId(), sourceId);
17
+ getSource(e) {
18
+ return this._injector.get(n).getSource(this.getId(), e);
23
19
  }
24
- setSourceData(sourceId, data) {
25
- this._injector.get(SheetsSourceManager).updateSourceData(this.getId(), sourceId, data);
20
+ setSourceData(e, t) {
21
+ this._injector.get(g).updateSourceData(this.getId(), e, t);
26
22
  }
27
23
  usePathMode() {
28
- this._injector.get(SheetsSourceBindService).usePathMode();
24
+ this._injector.get(n).usePathMode();
29
25
  }
30
26
  useValueMode() {
31
- this._injector.get(SheetsSourceBindService).useValueMode();
27
+ this._injector.get(n).useValueMode();
32
28
  }
33
- loadSourceBindingPathInfo(obj) {
34
- this._injector.get(SheetsSourceBindService).loadSourceBindingPathInfo(this.getId(), obj);
29
+ loadSourceBindingPathInfo(e) {
30
+ this._injector.get(n).loadSourceBindingPathInfo(this.getId(), e);
35
31
  }
36
32
  saveSourceBindingPathInfo() {
37
- return this._injector.get(SheetsSourceBindService).getSourceBindingPathInfo(this.getId());
38
- }
39
- getBindingModelBySourceId(sourceId) {
40
- return this._injector.get(SheetsSourceBindService).getBindingModelBySourceId(sourceId);
41
- }
42
- };
43
- __name(_FWorkbookSourceBinding, "FWorkbookSourceBinding");
44
- let FWorkbookSourceBinding = _FWorkbookSourceBinding;
45
- FWorkbook.extend(FWorkbookSourceBinding);
46
- const _FWorksheetSourceBinding = class _FWorksheetSourceBinding extends FWorksheet {
47
- setBindingNode(bindingNode) {
48
- const sheetsSourceBindService = this._injector.get(SheetsSourceBindService), unitId = this._workbook.getUnitId();
49
- sheetsSourceBindService.setBindingNode(unitId, this.getSheetId(), bindingNode);
50
- }
51
- removeBindingNode(row, column) {
52
- const sheetsSourceBindService = this._injector.get(SheetsSourceBindService), unitId = this._workbook.getUnitId();
53
- sheetsSourceBindService.removeBindingNode(unitId, this.getSheetId(), row, column);
54
- }
55
- getBindingNode(row, column) {
56
- const sheetsSourceBindService = this._injector.get(SheetsSourceBindService), unitId = this._workbook.getUnitId();
57
- return sheetsSourceBindService.getBindingNode(unitId, this.getSheetId(), row, column);
58
- }
59
- };
60
- __name(_FWorksheetSourceBinding, "FWorksheetSourceBinding");
61
- let FWorksheetSourceBinding = _FWorksheetSourceBinding;
62
- FWorksheet.extend(FWorksheetSourceBinding);
33
+ return this._injector.get(n).getSourceBindingPathInfo(this.getId());
34
+ }
35
+ getBindingModelBySourceId(e) {
36
+ return this._injector.get(n).getBindingModelBySourceId(e);
37
+ }
38
+ }
39
+ d.extend(j);
40
+ class a extends u {
41
+ setBindingNode(e) {
42
+ const o = this._injector.get(n), i = this._workbook.getUnitId();
43
+ o.setBindingNode(i, this.getSheetId(), e);
44
+ }
45
+ removeBindingNode(e, t) {
46
+ const i = this._injector.get(n), r = this._workbook.getUnitId();
47
+ i.removeBindingNode(r, this.getSheetId(), e, t);
48
+ }
49
+ getBindingNode(e, t) {
50
+ const i = this._injector.get(n), r = this._workbook.getUnitId();
51
+ return i.getBindingNode(r, this.getSheetId(), e, t);
52
+ }
53
+ }
54
+ u.extend(a);