@univerjs/sheets-source-binding 0.6.0-experimental.20250212-dbe9830 → 0.6.0-experimental.20250220-d9a8e74

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";const d=require("@univerjs/core/facade"),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 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 J=Object.defineProperty;var H=(i,s,e)=>s in i?J(i,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[s]=e;var l=(i,s,e)=>H(i,typeof s!="symbol"?s+"":s,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@univerjs/core"),y=require("@univerjs/sheets"),$=require("rxjs");class U{constructor(s){l(this,"_matrix",{});l(this,"_nodeMap",new Map);l(this,"_sourceIdMap",new Map);s&&this._init(s)}_init(s){this.fromJSON(s)}getBindingNodesBySourceId(s){const e=this._sourceIdMap.get(s);if(e)return e.map(t=>this._nodeMap.get(t))}setBindingNode(s,e,t){this._matrix[s]||(this._matrix[s]={}),this._matrix[s][e]||(this._matrix[s][e]=t),this._nodeMap.set(t.nodeId,t);const n=this._sourceIdMap.get(t.sourceId);n?n.push(t.nodeId):this._sourceIdMap.set(t.sourceId,[t.nodeId])}getBindingNode(s,e){var t;return(t=this._matrix[s])==null?void 0:t[e]}removeBindingNode(s,e){var n;const t=(n=this._matrix[s])==null?void 0:n[e];if(t){this._matrix[s][e]=void 0,this._nodeMap.delete(t.nodeId);const o=this._sourceIdMap.get(t.sourceId);if(o){const r=o.indexOf(t.nodeId);r>=0&&o.splice(r,1),o.length===0&&this._sourceIdMap.delete(t.sourceId)}}}getBindingNodeById(s){return this._nodeMap.get(s)}fromJSON(s){s.forEach(e=>{this.setBindingNode(e.row,e.column,e)})}toJSON(){return Array.from(this._nodeMap.values())}}var p=(i=>(i.List="list",i.Object="object",i))(p||{}),N=(i=>(i.Path="path",i.Value="value",i))(N||{}),B=(i=>(i.Add="add",i.Remove="remove",i.Update="update",i))(B||{});function A(i){return i instanceof Date&&!isNaN(i.getTime())}function x(i){const s=new Date(i);if(!A(s))return i;const e=new Date(Date.UTC(1900,0,1,0,0,0)),t=new Date(Date.UTC(1900,1,28,0,0,0));let o=(s.getTime()-e.getTime())/(1e3*3600*24);return s>t&&(o+=1),o+1}class T{constructor(s){l(this,"_data");l(this,"id");l(this,"_hasData",!1);l(this,"type");this.id=s}getId(){return this.id}getType(){return this.type}hasData(){return this._hasData}setSourceData(s){this._data=s,this._hasData=!0}toJSON(){return{id:this.id,type:this.type}}fromJSON(s){this.id=s.id,this.type=s.type}}class P extends T{constructor(e,t){super(e);l(this,"type",p.List);l(this,"_isListObject");l(this,"_fieldIndexMap",new Map);l(this,"_data",{fields:[],records:[]});this._isListObject=t!=null?t:!0}toggleListObject(e){this._isListObject=e}getData(e,t){const{path:n,row:o,containHeader:r}=e,d=this._fieldIndexMap.get(n),a=t-o;if(r&&a===0)return{v:this._data.fields[d]};let h;const c=r?1:0;if(this._isListObject?h=this._data.records[a-c][n]:h=this._data.records[a-c][d],e.isDate===!0){const f=e.formatter||"yyyy-m-d am/pm h:mm";return{v:x(h),s:{n:{pattern:f}},t:u.CellValueType.NUMBER}}else return e.formatter?{v:h,s:{n:{pattern:e.formatter}}}:{t:typeof h=="number"?u.CellValueType.NUMBER:u.CellValueType.STRING,v:h}}setSourceData(e){super.setSourceData(e);const{fields:t}=e;this._fieldIndexMap.clear(),t.forEach((n,o)=>{this._fieldIndexMap.set(n,o)})}getSourceInfo(){return{sourceId:this.id,sourceType:this.type,fields:this._data.fields,recordCount:this._data.records.length}}}class j extends T{constructor(e){super(e);l(this,"type",p.Object)}getData(e){const n=e.path.split(".");let o=this._data;for(const r of n)if(o=o[r],o===void 0)return null;if(e.isDate===!0){const r=e.formatter||"yyyy-m-d am/pm h:mm";return{v:x(o),s:{n:{pattern:r}},t:u.CellValueType.NUMBER}}else return e.formatter?{v:o,s:{n:{pattern:e.formatter}}}:{v:o,t:typeof o=="number"?u.CellValueType.NUMBER:u.CellValueType.STRING}}getSourceInfo(){return{sourceId:this.id,sourceType:p.Object}}}var q=Object.defineProperty,G=Object.getOwnPropertyDescriptor,W=(i,s,e,t)=>{for(var n=t>1?void 0:t?G(s,e):s,o=i.length-1,r;o>=0;o--)(r=i[o])&&(n=(t?r(s,e,n):r(n))||n);return t&&n&&q(s,e,n),n},D=(i,s)=>(e,t)=>s(e,t,i);let b=class extends u.Disposable{constructor(s,e,t){super();l(this,"modelMap",new Map);l(this,"_cellBindInfoUpdate$",new $.Subject);l(this,"cellBindInfoUpdate$",this._cellBindInfoUpdate$.asObservable());this._univerInstanceService=s,this._sheetInterceptorService=e,this._sheetsSelectionsService=t,this._initRemoveCommand()}_initRemoveCommand(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:s=>{const e=[],t=[],n=this._sheetsSelectionsService.getCurrentSelections(),o=y.getSheetCommandTarget(this._univerInstanceService);if(!o||!n||n.length===0)return{redos:[],undos:[]};const{unitId:r,subUnitId:d}=o;return(s.id===y.ClearSelectionContentCommand.id||s.id===y.ClearSelectionAllCommand.id)&&n.forEach(({range:a})=>{u.Range.foreach(a,(h,c)=>{this.getBindingNode(r,d,h,c)&&this.removeBindingNode(r,d,h,c)})}),{redos:e,undos:t}}}))}getBindingModelBySourceId(s){const e=[];return this.modelMap.forEach((t,n)=>{t.forEach((o,r)=>{const d=o.getBindingNodesBySourceId(s);if(d)for(const a of d)e.push({unitId:n,subunitId:r,sourceId:s,nodeId:a.nodeId,row:a.row,column:a.column})})}),e}addModel(s,e,t){var n;this.modelMap.has(s)||this.modelMap.set(s,new Map),(n=this.modelMap.get(s))==null||n.set(e,t)}getModel(s,e){var t;return(t=this.modelMap.get(s))==null?void 0:t.get(e)}setBindingNode(s,e,t){let n=this.getModel(s,e);n||(n=new U,this.addModel(s,e,n)),t.nodeId||(t.nodeId=u.generateRandomId());const{row:o,column:r}=t;if(o===void 0||r===void 0)throw new Error("row and column is required");const d=n.getBindingNode(o,r),a=t.type===p.List?!!t.containHeader:!1;n.setBindingNode(o,r,{...t,row:o,column:r}),this._cellBindInfoUpdate$.next({unitId:s,subunitId:e,sourceId:t.sourceId,nodeId:t.nodeId,row:o,column:r,containHeader:a,changeType:d?B.Update:B.Add,oldSourceId:d==null?void 0:d.sourceId,oldNodeContainHeader:(d==null?void 0:d.type)===p.List?!!d.containHeader:!1})}removeBindingNode(s,e,t,n){const o=this.getModel(s,e);if(o){const r=o.getBindingNode(t,n);r&&(o.removeBindingNode(t,n),this._cellBindInfoUpdate$.next({unitId:s,subunitId:e,sourceId:r.sourceId,nodeId:r.nodeId,row:t,column:n,changeType:B.Remove}))}}getBindingNode(s,e,t,n){const o=this.getModel(s,e);if(o)return o.getBindingNode(t,n)}getBindingNodeById(s,e,t){const n=this.getModel(s,e);if(n)return n.getBindingNodeById(t)}createModel(s,e,t){const n=new U(t);return this.addModel(s,e,n),n}toJSON(s){const e={},t=this.modelMap.get(s);return t&&t.forEach((n,o)=>{e[o]=n.toJSON()}),e}fromJSON(s,e){Object.entries(e).forEach(([t,n])=>{this.createModel(s,t,n)})}dispose(){this.modelMap.clear(),this._cellBindInfoUpdate$.complete()}};b=W([D(0,u.IUniverInstanceService),D(1,u.Inject(y.SheetInterceptorService)),D(2,u.Inject(y.SheetsSelectionsService))],b);class w extends u.Disposable{constructor(){super();l(this,"sourceMap",new Map);l(this,"_sourceDataUpdate$",new $.Subject);l(this,"sourceDataUpdate$",this._sourceDataUpdate$.asObservable())}_ensureUnitMap(e){let t=this.sourceMap.get(e);return t||(t=new Map,this.sourceMap.set(e,t)),t}_getUnitMap(e){return this.sourceMap.get(e)}getSource(e,t){const n=this._getUnitMap(e);return n==null?void 0:n.get(t)}createSource(e,t,n,o){const r=o===void 0?u.generateRandomId():o;let d;switch(t){case p.List:d=new P(r,n);break;case p.Object:d=new j(r);break;default:throw new Error(`Invalid source type: ${t}`)}return this._ensureUnitMap(e).set(r,d),d}updateSourceData(e,t,n){const o=this._getUnitMap(e),r=t instanceof T?t.getId():t,d=o==null?void 0:o.get(r);if(d)d.setSourceData(n),this._sourceDataUpdate$.next({...d.getSourceInfo(),unitId:e,changeType:B.Add});else throw new Error(`Source not found: ${r}`)}removeSource(e,t){const n=this._getUnitMap(e),o=n==null?void 0:n.get(t);o&&(n==null||n.delete(t),this._sourceDataUpdate$.next({...o.getSourceInfo(),unitId:e,changeType:B.Remove}))}toJSON(e){const t=[],n=this._getUnitMap(e);if(n)for(const o of n.values())t.push(o.toJSON());return t}fromJSON(e,t){const n=this._ensureUnitMap(e);for(const o of t){let r;switch(o.type){case p.List:r=new P(o.id);break;case p.Object:r=new j(o.id);break;default:throw new Error(`Invalid source type: ${o.type}`)}r.fromJSON(o),n.set(o.id,r)}}dispose(){this._sourceDataUpdate$.complete(),this.sourceMap.clear()}}var z=Object.defineProperty,F=Object.getOwnPropertyDescriptor,K=(i,s,e,t)=>{for(var n=t>1?void 0:t?F(s,e):s,o=i.length-1,r;o>=0;o--)(r=i[o])&&(n=(t?r(s,e,n):r(n))||n);return t&&n&&z(s,e,n),n},O=(i,s)=>(e,t)=>s(e,t,i);exports.SheetsSourceBindService=class extends u.Disposable{constructor(e,t,n){super();l(this,"_bindingModel",N.Value);l(this,"_bindModelRTreeCollection",new Map);this._sheetInterceptorService=e,this._sheetsBindingManager=t,this._sheetsSourceManager=n,this._registerInterceptor(),this._registerSourceChange()}usePathMode(){this._bindingModel=N.Path}useValueMode(){this._bindingModel=N.Value}getBindingModel(){return this._bindingModel}createBindModel(e,t){return this._sheetsBindingManager.createModel(e,t)}setBindingNode(e,t,n){this._sheetsBindingManager.setBindingNode(e,t,n)}removeBindingNode(e,t,n,o){this._sheetsBindingManager.removeBindingNode(e,t,n,o)}getBindingNode(e,t,n,o){return this._sheetsBindingManager.getBindingNode(e,t,n,o)}getSource(e,t){return this._sheetsSourceManager.getSource(e,t)}createSource(e,t,n,o){return this._sheetsSourceManager.createSource(e,t,n,o)}getSourceBindingPathInfo(e){return{source:this._sheetsSourceManager.toJSON(e),cellBinding:this._sheetsBindingManager.toJSON(e)}}loadSourceBindingPathInfo(e,t){this._sheetsSourceManager.fromJSON(e,t.source),this._sheetsBindingManager.fromJSON(e,t.cellBinding)}_ensureRTreeCollection(e){return this._bindModelRTreeCollection.has(e)||this._bindModelRTreeCollection.set(e,new u.RTree),this._bindModelRTreeCollection.get(e)}_getRTeeCollection(e){return this._bindModelRTreeCollection.get(e)}_registerSourceChange(){this.disposeWithMe(this._sheetsSourceManager.sourceDataUpdate$.subscribe(e=>{const{sourceId:t,sourceType:n,unitId:o,changeType:r}=e;if(n===p.List){if(r===B.Remove){const a=this._sheetsBindingManager.getBindingModelBySourceId(t),h=e.recordCount;for(const{unitId:c,subunitId:f,nodeId:g,row:S,column:M}of a){const I=this._getRTeeCollection(o),_=this._sheetsBindingManager.getBindingNodeById(c,f,g);if(I&&(_==null?void 0:_.type)===p.List){const m=_.containHeader?0:1,v={startRow:S,startColumn:M,endRow:S+h-m,endColumn:M};I.remove({unitId:c,sheetId:f,id:g,range:v})}}return}if(r===B.Update){const a=e.oldRecordCount,h=this._sheetsBindingManager.getBindingModelBySourceId(t);for(const{unitId:c,subunitId:f,nodeId:g,row:S,column:M}of h){const I=this._getRTeeCollection(o),_=this._sheetsBindingManager.getBindingNodeById(c,f,g);if(I&&(_==null?void 0:_.type)===p.List){const m=_.containHeader?0:1,v={startRow:S,startColumn:M,endRow:S+a-m,endColumn:M},C={startRow:S,startColumn:M,endRow:S+e.recordCount-m,endColumn:M};I.remove({unitId:c,sheetId:f,id:g,range:v}),I.insert({unitId:c,sheetId:f,id:g,range:C})}}return}const d=this._sheetsSourceManager.getSource(o,t);if(d&&d.hasData()){const h=d.getSourceInfo().recordCount,c=this._sheetsBindingManager.getBindingModelBySourceId(t);for(const{unitId:f,subunitId:g,nodeId:S,row:M,column:I}of c){const _=this._ensureRTreeCollection(f),m=this._sheetsBindingManager.getBindingNodeById(f,g,S);if(_&&(m==null?void 0:m.type)===p.List){const v=m.containHeader?0:1,C={startRow:M,startColumn:I,endRow:M+h-v,endColumn:I};_.insert({unitId:f,sheetId:g,id:S,range:C})}}}}})),this.disposeWithMe(this._sheetsBindingManager.cellBindInfoUpdate$.subscribe(e=>{const{unitId:t,subunitId:n,sourceId:o,nodeId:r,row:d,column:a,changeType:h,containHeader:c}=e,f=this._ensureRTreeCollection(t),g=this._sheetsSourceManager.getSource(t,o);if(g&&g.hasData()){const S=g.getSourceInfo();if(S.sourceType===p.List){const M=S.recordCount,I=c?0:1,_={startRow:d,startColumn:a,endRow:d+M-I,endColumn:a};if(h===B.Add)f.insert({unitId:t,sheetId:n,id:r,range:_});else if(h===B.Remove)f.remove({unitId:t,sheetId:n,id:r,range:_});else if(h===B.Update){const m=e.oldSourceId,v=e.oldNodeContainHeader?0:1,C=this._sheetsSourceManager.getSource(t,m);if(C&&C.hasData()){const V=C.getSourceInfo().recordCount,L={startRow:d,startColumn:a,endRow:d+V-v,endColumn:a};f.remove({unitId:t,sheetId:n,id:r,range:L})}f.insert({unitId:t,sheetId:n,id:r,range:_})}}}}))}_getPathModeCellValue(e,t,n,o){const r=this._sheetsBindingManager.getModel(e,t),d=r==null?void 0:r.getBindingNode(n,o);if(d){const a=d.type;if(a===p.List)return{v:`#{${d.path}}`,s:{cl:{rgb:"blue"}}};if(a===p.Object)return{v:`[${d.path}]`,s:{cl:{rgb:"blue"}}}}}_getValueModeCellValue(e,t,n,o){const r=this._sheetsBindingManager.getModel(e,t);if(r){const a=r.getBindingNode(n,o);if(a){const{sourceId:h}=a,c=this._sheetsSourceManager.getSource(e,h);if(c&&c.hasData())return(c==null?void 0:c.getData(a,n,o))||{v:""}}}const d=this._getRTeeCollection(e);if(r&&d){const a={startRow:n,startColumn:o,endRow:n,endColumn:o},h=Array.from(d.bulkSearch([{unitId:e,sheetId:t,range:a}]));if(h.length>0){const c=r.getBindingNodeById(h[0]);if(c){const{sourceId:f}=c,g=this._sheetsSourceManager.getSource(e,f);if(g&&g.hasData())return(g==null?void 0:g.getData(c,n,o))||{v:""}}}}}getBindingModelBySourceId(e){return this._sheetsBindingManager.getBindingModelBySourceId(e)}_registerInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(y.INTERCEPTOR_POINT.CELL_CONTENT,{effect:u.InterceptorEffectEnum.Value|u.InterceptorEffectEnum.Style,priority:102,handler:(e,t,n)=>{const{row:o,col:r,unitId:d,subUnitId:a,workbook:h}=t;let c=null;if(this._bindingModel===N.Path?c=this._getPathModeCellValue(d,a,o,r):c=this._getValueModeCellValue(d,a,o,r),c!==null){const g={...(typeof(e==null?void 0:e.s)=="string"?h.getStyles().get(e==null?void 0:e.s):e==null?void 0:e.s)||{}};return c&&c.s&&Object.assign(g,c.s),n({...e,...c,s:g})}return n(e)}}))}dispose(){this._bindModelRTreeCollection.clear()}};exports.SheetsSourceBindService=K([O(0,u.Inject(y.SheetInterceptorService)),O(1,u.Inject(b)),O(2,u.Inject(w))],exports.SheetsSourceBindService);var Q=Object.defineProperty,X=Object.getOwnPropertyDescriptor,Y=(i,s,e,t)=>{for(var n=t>1?void 0:t?X(s,e):s,o=i.length-1,r;o>=0;o--)(r=i[o])&&(n=(t?r(s,e,n):r(n))||n);return t&&n&&Q(s,e,n),n},E=(i,s)=>(e,t)=>s(e,t,i),R;exports.UniverSheetsBindingSourcePlugin=(R=class extends u.Plugin{constructor(s={},e,t){super(),this._config=s,this._injector=e,this._configService=t}onStarting(){[[b],[w],[exports.SheetsSourceBindService]].forEach(s=>this._injector.add(s))}onReady(){u.touchDependencies(this._injector,[[b],[w],[exports.SheetsSourceBindService]])}},l(R,"type",u.UniverInstanceType.UNIVER_SHEET),l(R,"pluginName","SHEET_BINDING_SOURCE_PLUGIN"),R);exports.UniverSheetsBindingSourcePlugin=Y([E(1,u.Inject(u.Injector)),E(2,u.IConfigService)],exports.UniverSheetsBindingSourcePlugin);exports.BindModeEnum=N;exports.BindingModel=U;exports.DataBindingNodeTypeEnum=p;exports.SheetsSourceManager=w;exports.SourceModelBase=T;
package/lib/es/facade.js CHANGED
@@ -1,4 +1,4 @@
1
- import { FEnum as s } from "@univerjs/core";
1
+ import { FEnum as s } from "@univerjs/core/facade";
2
2
  import { DataBindingNodeTypeEnum as S, BindModeEnum as h, SheetsSourceBindService as n, SheetsSourceManager as g } from "@univerjs/sheets-source-binding";
3
3
  import { FWorkbook as d, FWorksheet as u } from "@univerjs/sheets/facade";
4
4
  class B extends s {
package/lib/es/index.js CHANGED
@@ -52,7 +52,7 @@ class $ {
52
52
  return Array.from(this._nodeMap.values());
53
53
  }
54
54
  }
55
- var g = /* @__PURE__ */ ((i) => (i.List = "list", i.Object = "object", i))(g || {}), y = /* @__PURE__ */ ((i) => (i.Path = "path", i.Value = "value", i))(y || {}), S = /* @__PURE__ */ ((i) => (i.Add = "add", i.Remove = "remove", i.Update = "update", i))(S || {});
55
+ var g = /* @__PURE__ */ ((i) => (i.List = "list", i.Object = "object", i))(g || {}), y = /* @__PURE__ */ ((i) => (i.Path = "path", i.Value = "value", i))(y || {}), m = /* @__PURE__ */ ((i) => (i.Add = "add", i.Remove = "remove", i.Update = "update", i))(m || {});
56
56
  function ie(i) {
57
57
  return i instanceof Date && !isNaN(i.getTime());
58
58
  }
@@ -118,19 +118,30 @@ class x extends U {
118
118
  v: this._data.fields[d]
119
119
  };
120
120
  let a;
121
- const u = r ? 1 : 0;
122
- return this._isListObject ? a = this._data.records[c - u][s] : a = this._data.records[c - u][d], t.isDate === !0 ? {
123
- v: A(a),
124
- s: {
125
- n: {
126
- pattern: "yyyy-m-d am/pm h:mm"
121
+ const h = r ? 1 : 0;
122
+ if (this._isListObject ? a = this._data.records[c - h][s] : a = this._data.records[c - h][d], t.isDate === !0) {
123
+ const u = t.formatter || "yyyy-m-d am/pm h:mm";
124
+ return {
125
+ v: A(a),
126
+ s: {
127
+ n: {
128
+ pattern: u
129
+ }
130
+ },
131
+ t: v.NUMBER
132
+ };
133
+ } else
134
+ return t.formatter ? {
135
+ v: a,
136
+ s: {
137
+ n: {
138
+ pattern: t.formatter
139
+ }
127
140
  }
128
- },
129
- t: v.NUMBER
130
- } : {
131
- t: typeof a == "number" ? v.NUMBER : v.STRING,
132
- v: a
133
- };
141
+ } : {
142
+ t: typeof a == "number" ? v.NUMBER : v.STRING,
143
+ v: a
144
+ };
134
145
  }
135
146
  setSourceData(t) {
136
147
  super.setSourceData(t);
@@ -159,18 +170,29 @@ class E extends U {
159
170
  for (const r of s)
160
171
  if (o = o[r], o === void 0)
161
172
  return null;
162
- return t.isDate === !0 ? {
163
- v: A(o),
164
- s: {
165
- n: {
166
- pattern: "yyyy-m-d am/pm h:mm"
173
+ if (t.isDate === !0) {
174
+ const r = t.formatter || "yyyy-m-d am/pm h:mm";
175
+ return {
176
+ v: A(o),
177
+ s: {
178
+ n: {
179
+ pattern: r
180
+ }
181
+ },
182
+ t: v.NUMBER
183
+ };
184
+ } else
185
+ return t.formatter ? {
186
+ v: o,
187
+ s: {
188
+ n: {
189
+ pattern: t.formatter
190
+ }
167
191
  }
168
- },
169
- t: v.NUMBER
170
- } : {
171
- v: o,
172
- t: typeof o == "number" ? v.NUMBER : v.STRING
173
- };
192
+ } : {
193
+ v: o,
194
+ t: typeof o == "number" ? v.NUMBER : v.STRING
195
+ };
174
196
  }
175
197
  getSourceInfo() {
176
198
  return {
@@ -204,8 +226,8 @@ let N = class extends O {
204
226
  };
205
227
  const { unitId: r, subUnitId: d } = o;
206
228
  return (e.id === se.id || e.id === oe.id) && s.forEach(({ range: c }) => {
207
- F.foreach(c, (a, u) => {
208
- this.getBindingNode(r, d, a, u) && this.removeBindingNode(r, d, a, u);
229
+ F.foreach(c, (a, h) => {
230
+ this.getBindingNode(r, d, a, h) && this.removeBindingNode(r, d, a, h);
209
231
  });
210
232
  }), { redos: t, undos: n };
211
233
  }
@@ -253,7 +275,7 @@ let N = class extends O {
253
275
  row: o,
254
276
  column: r,
255
277
  containHeader: c,
256
- changeType: d ? S.Update : S.Add,
278
+ changeType: d ? m.Update : m.Add,
257
279
  oldSourceId: d == null ? void 0 : d.sourceId,
258
280
  oldNodeContainHeader: (d == null ? void 0 : d.type) === g.List ? !!d.containHeader : !1
259
281
  });
@@ -269,7 +291,7 @@ let N = class extends O {
269
291
  nodeId: r.nodeId,
270
292
  row: n,
271
293
  column: s,
272
- changeType: S.Remove
294
+ changeType: m.Remove
273
295
  }));
274
296
  }
275
297
  }
@@ -343,13 +365,13 @@ class T extends O {
343
365
  updateSourceData(t, n, s) {
344
366
  const o = this._getUnitMap(t), r = n instanceof U ? n.getId() : n, d = o == null ? void 0 : o.get(r);
345
367
  if (d)
346
- d.setSourceData(s), this._sourceDataUpdate$.next({ ...d.getSourceInfo(), unitId: t, changeType: S.Add });
368
+ d.setSourceData(s), this._sourceDataUpdate$.next({ ...d.getSourceInfo(), unitId: t, changeType: m.Add });
347
369
  else
348
370
  throw new Error(`Source not found: ${r}`);
349
371
  }
350
372
  removeSource(t, n) {
351
373
  const s = this._getUnitMap(t), o = s == null ? void 0 : s.get(n);
352
- o && (s == null || s.delete(n), this._sourceDataUpdate$.next({ ...o.getSourceInfo(), unitId: t, changeType: S.Remove }));
374
+ o && (s == null || s.delete(n), this._sourceDataUpdate$.next({ ...o.getSourceInfo(), unitId: t, changeType: m.Remove }));
353
375
  }
354
376
  toJSON(t) {
355
377
  const n = [], s = this._getUnitMap(t);
@@ -448,24 +470,24 @@ let w = class extends O {
448
470
  this.disposeWithMe(this._sheetsSourceManager.sourceDataUpdate$.subscribe((e) => {
449
471
  const { sourceId: t, sourceType: n, unitId: s, changeType: o } = e;
450
472
  if (n === g.List) {
451
- if (o === S.Remove) {
473
+ if (o === m.Remove) {
452
474
  const d = this._sheetsBindingManager.getBindingModelBySourceId(t), c = e.recordCount;
453
- for (const { unitId: a, subunitId: u, nodeId: h, row: p, column: _ } of d) {
454
- const M = this._getRTeeCollection(s), f = this._sheetsBindingManager.getBindingNodeById(a, u, h);
475
+ for (const { unitId: a, subunitId: h, nodeId: u, row: p, column: _ } of d) {
476
+ const M = this._getRTeeCollection(s), f = this._sheetsBindingManager.getBindingNodeById(a, h, u);
455
477
  if (M && (f == null ? void 0 : f.type) === g.List) {
456
- const I = f.containHeader ? 0 : 1, m = { startRow: p, startColumn: _, endRow: p + c - I, endColumn: _ };
457
- M.remove({ unitId: a, sheetId: u, id: h, range: m });
478
+ const I = f.containHeader ? 0 : 1, S = { startRow: p, startColumn: _, endRow: p + c - I, endColumn: _ };
479
+ M.remove({ unitId: a, sheetId: h, id: u, range: S });
458
480
  }
459
481
  }
460
482
  return;
461
483
  }
462
- if (o === S.Update) {
484
+ if (o === m.Update) {
463
485
  const d = e.oldRecordCount, c = this._sheetsBindingManager.getBindingModelBySourceId(t);
464
- for (const { unitId: a, subunitId: u, nodeId: h, row: p, column: _ } of c) {
465
- const M = this._getRTeeCollection(s), f = this._sheetsBindingManager.getBindingNodeById(a, u, h);
486
+ for (const { unitId: a, subunitId: h, nodeId: u, row: p, column: _ } of c) {
487
+ const M = this._getRTeeCollection(s), f = this._sheetsBindingManager.getBindingNodeById(a, h, u);
466
488
  if (M && (f == null ? void 0 : f.type) === g.List) {
467
- const I = f.containHeader ? 0 : 1, m = { startRow: p, startColumn: _, endRow: p + d - I, endColumn: _ }, B = { startRow: p, startColumn: _, endRow: p + e.recordCount - I, endColumn: _ };
468
- M.remove({ unitId: a, sheetId: u, id: h, range: m }), M.insert({ unitId: a, sheetId: u, id: h, range: B });
489
+ const I = f.containHeader ? 0 : 1, S = { startRow: p, startColumn: _, endRow: p + d - I, endColumn: _ }, B = { startRow: p, startColumn: _, endRow: p + e.recordCount - I, endColumn: _ };
490
+ M.remove({ unitId: a, sheetId: h, id: u, range: S }), M.insert({ unitId: a, sheetId: h, id: u, range: B });
469
491
  }
470
492
  }
471
493
  return;
@@ -473,32 +495,32 @@ let w = class extends O {
473
495
  const r = this._sheetsSourceManager.getSource(s, t);
474
496
  if (r && r.hasData()) {
475
497
  const c = r.getSourceInfo().recordCount, a = this._sheetsBindingManager.getBindingModelBySourceId(t);
476
- for (const { unitId: u, subunitId: h, nodeId: p, row: _, column: M } of a) {
477
- const f = this._ensureRTreeCollection(u), I = this._sheetsBindingManager.getBindingNodeById(u, h, p);
498
+ for (const { unitId: h, subunitId: u, nodeId: p, row: _, column: M } of a) {
499
+ const f = this._ensureRTreeCollection(h), I = this._sheetsBindingManager.getBindingNodeById(h, u, p);
478
500
  if (f && (I == null ? void 0 : I.type) === g.List) {
479
- const m = I.containHeader ? 0 : 1, B = { startRow: _, startColumn: M, endRow: _ + c - m, endColumn: M };
480
- f.insert({ unitId: u, sheetId: h, id: p, range: B });
501
+ const S = I.containHeader ? 0 : 1, B = { startRow: _, startColumn: M, endRow: _ + c - S, endColumn: M };
502
+ f.insert({ unitId: h, sheetId: u, id: p, range: B });
481
503
  }
482
504
  }
483
505
  }
484
506
  }
485
507
  })), this.disposeWithMe(this._sheetsBindingManager.cellBindInfoUpdate$.subscribe((e) => {
486
- const { unitId: t, subunitId: n, sourceId: s, nodeId: o, row: r, column: d, changeType: c, containHeader: a } = e, u = this._ensureRTreeCollection(t), h = this._sheetsSourceManager.getSource(t, s);
487
- if (h && h.hasData()) {
488
- const p = h.getSourceInfo();
508
+ const { unitId: t, subunitId: n, sourceId: s, nodeId: o, row: r, column: d, changeType: c, containHeader: a } = e, h = this._ensureRTreeCollection(t), u = this._sheetsSourceManager.getSource(t, s);
509
+ if (u && u.hasData()) {
510
+ const p = u.getSourceInfo();
489
511
  if (p.sourceType === g.List) {
490
512
  const _ = p.recordCount, M = a ? 0 : 1, f = { startRow: r, startColumn: d, endRow: r + _ - M, endColumn: d };
491
- if (c === S.Add)
492
- u.insert({ unitId: t, sheetId: n, id: o, range: f });
493
- else if (c === S.Remove)
494
- u.remove({ unitId: t, sheetId: n, id: o, range: f });
495
- else if (c === S.Update) {
496
- const I = e.oldSourceId, m = e.oldNodeContainHeader ? 0 : 1, B = this._sheetsSourceManager.getSource(t, I);
513
+ if (c === m.Add)
514
+ h.insert({ unitId: t, sheetId: n, id: o, range: f });
515
+ else if (c === m.Remove)
516
+ h.remove({ unitId: t, sheetId: n, id: o, range: f });
517
+ else if (c === m.Update) {
518
+ const I = e.oldSourceId, S = e.oldNodeContainHeader ? 0 : 1, B = this._sheetsSourceManager.getSource(t, I);
497
519
  if (B && B.hasData()) {
498
- const G = B.getSourceInfo().recordCount, W = { startRow: r, startColumn: d, endRow: r + G - m, endColumn: d };
499
- u.remove({ unitId: t, sheetId: n, id: o, range: W });
520
+ const G = B.getSourceInfo().recordCount, W = { startRow: r, startColumn: d, endRow: r + G - S, endColumn: d };
521
+ h.remove({ unitId: t, sheetId: n, id: o, range: W });
500
522
  }
501
- u.insert({ unitId: t, sheetId: n, id: o, range: f });
523
+ h.insert({ unitId: t, sheetId: n, id: o, range: f });
502
524
  }
503
525
  }
504
526
  }
@@ -536,9 +558,9 @@ let w = class extends O {
536
558
  if (c.length > 0) {
537
559
  const a = o.getBindingNodeById(c[0]);
538
560
  if (a) {
539
- const { sourceId: u } = a, h = this._sheetsSourceManager.getSource(e, u);
540
- if (h && h.hasData())
541
- return (h == null ? void 0 : h.getData(a, n, s)) || { v: "" };
561
+ const { sourceId: h } = a, u = this._sheetsSourceManager.getSource(e, h);
562
+ if (u && u.hasData())
563
+ return (u == null ? void 0 : u.getData(a, n, s)) || { v: "" };
542
564
  }
543
565
  }
544
566
  }
@@ -554,8 +576,8 @@ let w = class extends O {
554
576
  const { row: s, col: o, unitId: r, subUnitId: d, workbook: c } = t;
555
577
  let a = null;
556
578
  if (this._bindingModel === y.Path ? a = this._getPathModeCellValue(r, d, s, o) : a = this._getValueModeCellValue(r, d, s, o), a !== null) {
557
- const h = { ...(typeof (e == null ? void 0 : e.s) == "string" ? c.getStyles().get(e == null ? void 0 : e.s) : e == null ? void 0 : e.s) || {} };
558
- return a && a.s && Object.assign(h, a.s), n({ ...e, ...a, s: h });
579
+ const u = { ...(typeof (e == null ? void 0 : e.s) == "string" ? c.getStyles().get(e == null ? void 0 : e.s) : e == null ? void 0 : e.s) || {} };
580
+ return a && a.s && Object.assign(u, a.s), n({ ...e, ...a, s: u });
559
581
  }
560
582
  return n(e);
561
583
  }
@@ -12,7 +12,7 @@ export interface ISourceBindingEnumMixin {
12
12
  */
13
13
  BindModeEnum: typeof BindModeEnum;
14
14
  }
15
- declare module '@univerjs/core' {
15
+ declare module '@univerjs/core/facade' {
16
16
  interface FEnum extends ISourceBindingEnumMixin {
17
17
  }
18
18
  }
@@ -94,6 +94,10 @@ export interface ICellBindingNodeParam {
94
94
  */
95
95
  isDate?: boolean;
96
96
  nodeId?: string;
97
+ /**
98
+ * The formatter of the binding node, the formatter will be applied to the binding value.
99
+ */
100
+ formatter?: string;
97
101
  }
98
102
  export interface ICellBindingNode extends ICellBindingNodeParam {
99
103
  /**
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(o,t){typeof exports=="object"&&typeof module<"u"?t(require("@univerjs/core/facade"),require("@univerjs/sheets-source-binding"),require("@univerjs/sheets/facade")):typeof define=="function"&&define.amd?define(["@univerjs/core/facade","@univerjs/sheets-source-binding","@univerjs/sheets/facade"],t):(o=typeof globalThis<"u"?globalThis:o||self,t(o.UniverCoreFacade,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)});
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(h,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs"],a):(h=typeof globalThis<"u"?globalThis:h||self,a(h.UniverSheetsSourceBinding={},h.UniverCore,h.UniverSheets,h.rxjs))})(this,function(h,a,I,P){"use strict";var Y=Object.defineProperty;var Z=(h,a,I)=>a in h?Y(h,a,{enumerable:!0,configurable:!0,writable:!0,value:I}):h[a]=I;var g=(h,a,I)=>Z(h,typeof a!="symbol"?a+"":a,I);var D;class U{constructor(o){g(this,"_matrix",{});g(this,"_nodeMap",new Map);g(this,"_sourceIdMap",new Map);o&&this._init(o)}_init(o){this.fromJSON(o)}getBindingNodesBySourceId(o){const e=this._sourceIdMap.get(o);if(e)return e.map(t=>this._nodeMap.get(t))}setBindingNode(o,e,t){this._matrix[o]||(this._matrix[o]={}),this._matrix[o][e]||(this._matrix[o][e]=t),this._nodeMap.set(t.nodeId,t);const n=this._sourceIdMap.get(t.sourceId);n?n.push(t.nodeId):this._sourceIdMap.set(t.sourceId,[t.nodeId])}getBindingNode(o,e){var t;return(t=this._matrix[o])==null?void 0:t[e]}removeBindingNode(o,e){var n;const t=(n=this._matrix[o])==null?void 0:n[e];if(t){this._matrix[o][e]=void 0,this._nodeMap.delete(t.nodeId);const s=this._sourceIdMap.get(t.sourceId);if(s){const i=s.indexOf(t.nodeId);i>=0&&s.splice(i,1),s.length===0&&this._sourceIdMap.delete(t.sourceId)}}}getBindingNodeById(o){return this._nodeMap.get(o)}fromJSON(o){o.forEach(e=>{this.setBindingNode(e.row,e.column,e)})}toJSON(){return Array.from(this._nodeMap.values())}}var _=(d=>(d.List="list",d.Object="object",d))(_||{}),b=(d=>(d.Path="path",d.Value="value",d))(b||{}),B=(d=>(d.Add="add",d.Remove="remove",d.Update="update",d))(B||{});function x(d){return d instanceof Date&&!isNaN(d.getTime())}function E(d){const o=new Date(d);if(!x(o))return d;const e=new Date(Date.UTC(1900,0,1,0,0,0)),t=new Date(Date.UTC(1900,1,28,0,0,0));let s=(o.getTime()-e.getTime())/(1e3*3600*24);return o>t&&(s+=1),s+1}class w{constructor(o){g(this,"_data");g(this,"id");g(this,"_hasData",!1);g(this,"type");this.id=o}getId(){return this.id}getType(){return this.type}hasData(){return this._hasData}setSourceData(o){this._data=o,this._hasData=!0}toJSON(){return{id:this.id,type:this.type}}fromJSON(o){this.id=o.id,this.type=o.type}}class $ extends w{constructor(e,t){super(e);g(this,"type",_.List);g(this,"_isListObject");g(this,"_fieldIndexMap",new Map);g(this,"_data",{fields:[],records:[]});this._isListObject=t!=null?t:!0}toggleListObject(e){this._isListObject=e}getData(e,t){const{path:n,row:s,containHeader:i}=e,r=this._fieldIndexMap.get(n),c=t-s;if(i&&c===0)return{v:this._data.fields[r]};let l;const u=i?1:0;if(this._isListObject?l=this._data.records[c-u][n]:l=this._data.records[c-u][r],e.isDate===!0){const p=e.formatter||"yyyy-m-d am/pm h:mm";return{v:E(l),s:{n:{pattern:p}},t:a.CellValueType.NUMBER}}else return e.formatter?{v:l,s:{n:{pattern:e.formatter}}}:{t:typeof l=="number"?a.CellValueType.NUMBER:a.CellValueType.STRING,v:l}}setSourceData(e){super.setSourceData(e);const{fields:t}=e;this._fieldIndexMap.clear(),t.forEach((n,s)=>{this._fieldIndexMap.set(n,s)})}getSourceInfo(){return{sourceId:this.id,sourceType:this.type,fields:this._data.fields,recordCount:this._data.records.length}}}class V extends w{constructor(e){super(e);g(this,"type",_.Object)}getData(e){const n=e.path.split(".");let s=this._data;for(const i of n)if(s=s[i],s===void 0)return null;if(e.isDate===!0){const i=e.formatter||"yyyy-m-d am/pm h:mm";return{v:E(s),s:{n:{pattern:i}},t:a.CellValueType.NUMBER}}else return e.formatter?{v:s,s:{n:{pattern:e.formatter}}}:{v:s,t:typeof s=="number"?a.CellValueType.NUMBER:a.CellValueType.STRING}}getSourceInfo(){return{sourceId:this.id,sourceType:_.Object}}}var J=Object.defineProperty,H=Object.getOwnPropertyDescriptor,A=(d,o,e,t)=>{for(var n=t>1?void 0:t?H(o,e):o,s=d.length-1,i;s>=0;s--)(i=d[s])&&(n=(t?i(o,e,n):i(n))||n);return t&&n&&J(o,e,n),n},O=(d,o)=>(e,t)=>o(e,t,d);let R=class extends a.Disposable{constructor(o,e,t){super();g(this,"modelMap",new Map);g(this,"_cellBindInfoUpdate$",new P.Subject);g(this,"cellBindInfoUpdate$",this._cellBindInfoUpdate$.asObservable());this._univerInstanceService=o,this._sheetInterceptorService=e,this._sheetsSelectionsService=t,this._initRemoveCommand()}_initRemoveCommand(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:o=>{const e=[],t=[],n=this._sheetsSelectionsService.getCurrentSelections(),s=I.getSheetCommandTarget(this._univerInstanceService);if(!s||!n||n.length===0)return{redos:[],undos:[]};const{unitId:i,subUnitId:r}=s;return(o.id===I.ClearSelectionContentCommand.id||o.id===I.ClearSelectionAllCommand.id)&&n.forEach(({range:c})=>{a.Range.foreach(c,(l,u)=>{this.getBindingNode(i,r,l,u)&&this.removeBindingNode(i,r,l,u)})}),{redos:e,undos:t}}}))}getBindingModelBySourceId(o){const e=[];return this.modelMap.forEach((t,n)=>{t.forEach((s,i)=>{const r=s.getBindingNodesBySourceId(o);if(r)for(const c of r)e.push({unitId:n,subunitId:i,sourceId:o,nodeId:c.nodeId,row:c.row,column:c.column})})}),e}addModel(o,e,t){var n;this.modelMap.has(o)||this.modelMap.set(o,new Map),(n=this.modelMap.get(o))==null||n.set(e,t)}getModel(o,e){var t;return(t=this.modelMap.get(o))==null?void 0:t.get(e)}setBindingNode(o,e,t){let n=this.getModel(o,e);n||(n=new U,this.addModel(o,e,n)),t.nodeId||(t.nodeId=a.generateRandomId());const{row:s,column:i}=t;if(s===void 0||i===void 0)throw new Error("row and column is required");const r=n.getBindingNode(s,i),c=t.type===_.List?!!t.containHeader:!1;n.setBindingNode(s,i,{...t,row:s,column:i}),this._cellBindInfoUpdate$.next({unitId:o,subunitId:e,sourceId:t.sourceId,nodeId:t.nodeId,row:s,column:i,containHeader:c,changeType:r?B.Update:B.Add,oldSourceId:r==null?void 0:r.sourceId,oldNodeContainHeader:(r==null?void 0:r.type)===_.List?!!r.containHeader:!1})}removeBindingNode(o,e,t,n){const s=this.getModel(o,e);if(s){const i=s.getBindingNode(t,n);i&&(s.removeBindingNode(t,n),this._cellBindInfoUpdate$.next({unitId:o,subunitId:e,sourceId:i.sourceId,nodeId:i.nodeId,row:t,column:n,changeType:B.Remove}))}}getBindingNode(o,e,t,n){const s=this.getModel(o,e);if(s)return s.getBindingNode(t,n)}getBindingNodeById(o,e,t){const n=this.getModel(o,e);if(n)return n.getBindingNodeById(t)}createModel(o,e,t){const n=new U(t);return this.addModel(o,e,n),n}toJSON(o){const e={},t=this.modelMap.get(o);return t&&t.forEach((n,s)=>{e[s]=n.toJSON()}),e}fromJSON(o,e){Object.entries(e).forEach(([t,n])=>{this.createModel(o,t,n)})}dispose(){this.modelMap.clear(),this._cellBindInfoUpdate$.complete()}};R=A([O(0,a.IUniverInstanceService),O(1,a.Inject(I.SheetInterceptorService)),O(2,a.Inject(I.SheetsSelectionsService))],R);class T extends a.Disposable{constructor(){super();g(this,"sourceMap",new Map);g(this,"_sourceDataUpdate$",new P.Subject);g(this,"sourceDataUpdate$",this._sourceDataUpdate$.asObservable())}_ensureUnitMap(e){let t=this.sourceMap.get(e);return t||(t=new Map,this.sourceMap.set(e,t)),t}_getUnitMap(e){return this.sourceMap.get(e)}getSource(e,t){const n=this._getUnitMap(e);return n==null?void 0:n.get(t)}createSource(e,t,n,s){const i=s===void 0?a.generateRandomId():s;let r;switch(t){case _.List:r=new $(i,n);break;case _.Object:r=new V(i);break;default:throw new Error(`Invalid source type: ${t}`)}return this._ensureUnitMap(e).set(i,r),r}updateSourceData(e,t,n){const s=this._getUnitMap(e),i=t instanceof w?t.getId():t,r=s==null?void 0:s.get(i);if(r)r.setSourceData(n),this._sourceDataUpdate$.next({...r.getSourceInfo(),unitId:e,changeType:B.Add});else throw new Error(`Source not found: ${i}`)}removeSource(e,t){const n=this._getUnitMap(e),s=n==null?void 0:n.get(t);s&&(n==null||n.delete(t),this._sourceDataUpdate$.next({...s.getSourceInfo(),unitId:e,changeType:B.Remove}))}toJSON(e){const t=[],n=this._getUnitMap(e);if(n)for(const s of n.values())t.push(s.toJSON());return t}fromJSON(e,t){const n=this._ensureUnitMap(e);for(const s of t){let i;switch(s.type){case _.List:i=new $(s.id);break;case _.Object:i=new V(s.id);break;default:throw new Error(`Invalid source type: ${s.type}`)}i.fromJSON(s),n.set(s.id,i)}}dispose(){this._sourceDataUpdate$.complete(),this.sourceMap.clear()}}var q=Object.defineProperty,G=Object.getOwnPropertyDescriptor,W=(d,o,e,t)=>{for(var n=t>1?void 0:t?G(o,e):o,s=d.length-1,i;s>=0;s--)(i=d[s])&&(n=(t?i(o,e,n):i(n))||n);return t&&n&&q(o,e,n),n},j=(d,o)=>(e,t)=>o(e,t,d);h.SheetsSourceBindService=class extends a.Disposable{constructor(e,t,n){super();g(this,"_bindingModel",b.Value);g(this,"_bindModelRTreeCollection",new Map);this._sheetInterceptorService=e,this._sheetsBindingManager=t,this._sheetsSourceManager=n,this._registerInterceptor(),this._registerSourceChange()}usePathMode(){this._bindingModel=b.Path}useValueMode(){this._bindingModel=b.Value}getBindingModel(){return this._bindingModel}createBindModel(e,t){return this._sheetsBindingManager.createModel(e,t)}setBindingNode(e,t,n){this._sheetsBindingManager.setBindingNode(e,t,n)}removeBindingNode(e,t,n,s){this._sheetsBindingManager.removeBindingNode(e,t,n,s)}getBindingNode(e,t,n,s){return this._sheetsBindingManager.getBindingNode(e,t,n,s)}getSource(e,t){return this._sheetsSourceManager.getSource(e,t)}createSource(e,t,n,s){return this._sheetsSourceManager.createSource(e,t,n,s)}getSourceBindingPathInfo(e){return{source:this._sheetsSourceManager.toJSON(e),cellBinding:this._sheetsBindingManager.toJSON(e)}}loadSourceBindingPathInfo(e,t){this._sheetsSourceManager.fromJSON(e,t.source),this._sheetsBindingManager.fromJSON(e,t.cellBinding)}_ensureRTreeCollection(e){return this._bindModelRTreeCollection.has(e)||this._bindModelRTreeCollection.set(e,new a.RTree),this._bindModelRTreeCollection.get(e)}_getRTeeCollection(e){return this._bindModelRTreeCollection.get(e)}_registerSourceChange(){this.disposeWithMe(this._sheetsSourceManager.sourceDataUpdate$.subscribe(e=>{const{sourceId:t,sourceType:n,unitId:s,changeType:i}=e;if(n===_.List){if(i===B.Remove){const c=this._sheetsBindingManager.getBindingModelBySourceId(t),l=e.recordCount;for(const{unitId:u,subunitId:p,nodeId:f,row:M,column:m}of c){const v=this._getRTeeCollection(s),S=this._sheetsBindingManager.getBindingNodeById(u,p,f);if(v&&(S==null?void 0:S.type)===_.List){const y=S.containHeader?0:1,C={startRow:M,startColumn:m,endRow:M+l-y,endColumn:m};v.remove({unitId:u,sheetId:p,id:f,range:C})}}return}if(i===B.Update){const c=e.oldRecordCount,l=this._sheetsBindingManager.getBindingModelBySourceId(t);for(const{unitId:u,subunitId:p,nodeId:f,row:M,column:m}of l){const v=this._getRTeeCollection(s),S=this._sheetsBindingManager.getBindingNodeById(u,p,f);if(v&&(S==null?void 0:S.type)===_.List){const y=S.containHeader?0:1,C={startRow:M,startColumn:m,endRow:M+c-y,endColumn:m},N={startRow:M,startColumn:m,endRow:M+e.recordCount-y,endColumn:m};v.remove({unitId:u,sheetId:p,id:f,range:C}),v.insert({unitId:u,sheetId:p,id:f,range:N})}}return}const r=this._sheetsSourceManager.getSource(s,t);if(r&&r.hasData()){const l=r.getSourceInfo().recordCount,u=this._sheetsBindingManager.getBindingModelBySourceId(t);for(const{unitId:p,subunitId:f,nodeId:M,row:m,column:v}of u){const S=this._ensureRTreeCollection(p),y=this._sheetsBindingManager.getBindingNodeById(p,f,M);if(S&&(y==null?void 0:y.type)===_.List){const C=y.containHeader?0:1,N={startRow:m,startColumn:v,endRow:m+l-C,endColumn:v};S.insert({unitId:p,sheetId:f,id:M,range:N})}}}}})),this.disposeWithMe(this._sheetsBindingManager.cellBindInfoUpdate$.subscribe(e=>{const{unitId:t,subunitId:n,sourceId:s,nodeId:i,row:r,column:c,changeType:l,containHeader:u}=e,p=this._ensureRTreeCollection(t),f=this._sheetsSourceManager.getSource(t,s);if(f&&f.hasData()){const M=f.getSourceInfo();if(M.sourceType===_.List){const m=M.recordCount,v=u?0:1,S={startRow:r,startColumn:c,endRow:r+m-v,endColumn:c};if(l===B.Add)p.insert({unitId:t,sheetId:n,id:i,range:S});else if(l===B.Remove)p.remove({unitId:t,sheetId:n,id:i,range:S});else if(l===B.Update){const y=e.oldSourceId,C=e.oldNodeContainHeader?0:1,N=this._sheetsSourceManager.getSource(t,y);if(N&&N.hasData()){const Q=N.getSourceInfo().recordCount,X={startRow:r,startColumn:c,endRow:r+Q-C,endColumn:c};p.remove({unitId:t,sheetId:n,id:i,range:X})}p.insert({unitId:t,sheetId:n,id:i,range:S})}}}}))}_getPathModeCellValue(e,t,n,s){const i=this._sheetsBindingManager.getModel(e,t),r=i==null?void 0:i.getBindingNode(n,s);if(r){const c=r.type;if(c===_.List)return{v:`#{${r.path}}`,s:{cl:{rgb:"blue"}}};if(c===_.Object)return{v:`[${r.path}]`,s:{cl:{rgb:"blue"}}}}}_getValueModeCellValue(e,t,n,s){const i=this._sheetsBindingManager.getModel(e,t);if(i){const c=i.getBindingNode(n,s);if(c){const{sourceId:l}=c,u=this._sheetsSourceManager.getSource(e,l);if(u&&u.hasData())return(u==null?void 0:u.getData(c,n,s))||{v:""}}}const r=this._getRTeeCollection(e);if(i&&r){const c={startRow:n,startColumn:s,endRow:n,endColumn:s},l=Array.from(r.bulkSearch([{unitId:e,sheetId:t,range:c}]));if(l.length>0){const u=i.getBindingNodeById(l[0]);if(u){const{sourceId:p}=u,f=this._sheetsSourceManager.getSource(e,p);if(f&&f.hasData())return(f==null?void 0:f.getData(u,n,s))||{v:""}}}}}getBindingModelBySourceId(e){return this._sheetsBindingManager.getBindingModelBySourceId(e)}_registerInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(I.INTERCEPTOR_POINT.CELL_CONTENT,{effect:a.InterceptorEffectEnum.Value|a.InterceptorEffectEnum.Style,priority:102,handler:(e,t,n)=>{const{row:s,col:i,unitId:r,subUnitId:c,workbook:l}=t;let u=null;if(this._bindingModel===b.Path?u=this._getPathModeCellValue(r,c,s,i):u=this._getValueModeCellValue(r,c,s,i),u!==null){const f={...(typeof(e==null?void 0:e.s)=="string"?l.getStyles().get(e==null?void 0:e.s):e==null?void 0:e.s)||{}};return u&&u.s&&Object.assign(f,u.s),n({...e,...u,s:f})}return n(e)}}))}dispose(){this._bindModelRTreeCollection.clear()}},h.SheetsSourceBindService=W([j(0,a.Inject(I.SheetInterceptorService)),j(1,a.Inject(R)),j(2,a.Inject(T))],h.SheetsSourceBindService);var z=Object.defineProperty,F=Object.getOwnPropertyDescriptor,K=(d,o,e,t)=>{for(var n=t>1?void 0:t?F(o,e):o,s=d.length-1,i;s>=0;s--)(i=d[s])&&(n=(t?i(o,e,n):i(n))||n);return t&&n&&z(o,e,n),n},L=(d,o)=>(e,t)=>o(e,t,d);h.UniverSheetsBindingSourcePlugin=(D=class extends a.Plugin{constructor(o={},e,t){super(),this._config=o,this._injector=e,this._configService=t}onStarting(){[[R],[T],[h.SheetsSourceBindService]].forEach(o=>this._injector.add(o))}onReady(){a.touchDependencies(this._injector,[[R],[T],[h.SheetsSourceBindService]])}},g(D,"type",a.UniverInstanceType.UNIVER_SHEET),g(D,"pluginName","SHEET_BINDING_SOURCE_PLUGIN"),D),h.UniverSheetsBindingSourcePlugin=K([L(1,a.Inject(a.Injector)),L(2,a.IConfigService)],h.UniverSheetsBindingSourcePlugin),h.BindModeEnum=b,h.BindingModel=U,h.DataBindingNodeTypeEnum=_,h.SheetsSourceManager=T,h.SourceModelBase=w,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-source-binding",
3
- "version": "0.6.0-experimental.20250212-dbe9830",
3
+ "version": "0.6.0-experimental.20250220-d9a8e74",
4
4
  "private": false,
5
5
  "description": "A library for connect and bind data from other sources to Univer Sheets",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -51,15 +51,15 @@
51
51
  "rxjs": ">=7.0.0"
52
52
  },
53
53
  "dependencies": {
54
- "@univerjs/core": "0.6.0-experimental.20250212-dbe9830",
55
- "@univerjs/sheets": "0.6.0-experimental.20250212-dbe9830"
54
+ "@univerjs/core": "0.6.0-experimental.20250220-d9a8e74",
55
+ "@univerjs/sheets": "0.6.0-experimental.20250220-d9a8e74"
56
56
  },
57
57
  "devDependencies": {
58
58
  "rxjs": "^7.8.1",
59
59
  "typescript": "^5.7.3",
60
- "vite": "^6.0.11",
61
- "vitest": "^3.0.4",
62
- "@univerjs-infra/shared": "0.6.0-alpha.0"
60
+ "vite": "^6.1.0",
61
+ "vitest": "^3.0.5",
62
+ "@univerjs-infra/shared": "0.6.0"
63
63
  },
64
64
  "scripts": {
65
65
  "test": "vitest run",