@univerjs/sheets-source-binding 0.5.4-nightly.202501151606 → 0.5.4-nightly.202501160704
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 +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/es/facade.js +22 -13
- package/lib/es/index.js +383 -255
- package/lib/types/controllers/binding-manager.d.ts +11 -4
- package/lib/types/controllers/source-manager.d.ts +4 -1
- package/lib/types/facade/f-workbook.d.ts +29 -3
- package/lib/types/index.d.ts +2 -1
- package/lib/types/model/binding-model.d.ts +4 -4
- package/lib/types/model/source-model.d.ts +7 -4
- package/lib/types/services/source-binding-service.d.ts +7 -1
- package/lib/types/types.d.ts +15 -0
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +3 -3
package/lib/cjs/facade.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";const d=require("@univerjs/core"),n=require("@univerjs/sheets-source-binding"),
|
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())}}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 O=(d,r,e)=>r in d?j(d,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[r]=e;var u=(d,r,e)=>O(d,typeof r!="symbol"?r+"":r,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("@univerjs/core"),U=require("rxjs"),y=require("@univerjs/sheets");class w{constructor(r){u(this,"_matrix",{});u(this,"_nodeMap",new Map);u(this,"_sourceIdMap",new Map);r&&this._init(r)}_init(r){this.fromJSON()}getBindingNodesBySourceId(r){const e=this._sourceIdMap.get(r);if(e)return e.map(t=>this._nodeMap.get(t))}setBindingNode(r,e,t){this._matrix[r]||(this._matrix[r]={}),this._matrix[r][e]||(this._matrix[r][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(r,e){var t;return(t=this._matrix[r])==null?void 0:t[e]}removeBindingNode(r,e){var n;const t=(n=this._matrix[r])==null?void 0:n[e];if(t){this._matrix[r][e]=void 0,this._nodeMap.delete(t.nodeId);const o=this._sourceIdMap.get(t.sourceId);if(o){const s=o.indexOf(t.nodeId);s>=0&&o.splice(s,1),o.length===0&&this._sourceIdMap.delete(t.sourceId)}}}getBindingNodeById(r){return this._nodeMap.get(r)}fromJSON(){}toJSON(){}}var S=(d=>(d.List="list",d.Object="object",d))(S||{}),m=(d=>(d.Path="path",d.Value="value",d))(m||{}),M=(d=>(d.Add="add",d.Remove="remove",d.Update="update",d))(M||{});class b{constructor(r){u(this,"_data");u(this,"id");u(this,"_hasData",!1);u(this,"type");this.id=r}getId(){return this.id}getType(){return this.type}hasData(){return this._hasData}setSourceData(r){this._data=r,this._hasData=!0}}class $ extends b{constructor(e,t){super(e);u(this,"type",S.List);u(this,"_isListObject");u(this,"_fieldIndexMap",new Map);u(this,"_data",{fields:[],records:[]});this._isListObject=t!=null?t:!0}toggleListObject(e){this._isListObject=e}getData(e,t){const{path:n,row:o}=e,s=this._fieldIndexMap.get(n),i=t-o;return i===0?this._data.fields[s]:this._isListObject?this._data.records[i-1][n]:this._data.records[i-1][s]}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 E extends b{constructor(e){super(e);u(this,"type",S.Object)}getData(e){const n=e.path.split(".");let o=this._data;for(const s of n)if(o=o[s],o===void 0)return null;return o}getSourceInfo(){return{sourceId:this.id,sourceType:S.Object}}}class T extends h.Disposable{constructor(){super();u(this,"modelMap",new Map);u(this,"_cellBindInfoUpdate$",new U.Subject);u(this,"cellBindInfoUpdate$",this._cellBindInfoUpdate$.asObservable())}getBindingModelBySourceId(e){const t=[];return this.modelMap.forEach((n,o)=>{n.forEach((s,i)=>{const c=s.getBindingNodesBySourceId(e);if(c)for(const a of c)t.push({unitId:o,subunitId:i,sourceId:e,nodeId:a.nodeId,row:a.row,column:a.column})})}),t}addModel(e,t,n){var o;this.modelMap.has(e)||this.modelMap.set(e,new Map),(o=this.modelMap.get(e))==null||o.set(t,n)}getModel(e,t){var n;return(n=this.modelMap.get(e))==null?void 0:n.get(t)}setBindingNode(e,t,n){let o=this.getModel(e,t);o||(o=new w,this.addModel(e,t,o)),n.nodeId||(n.nodeId=h.generateRandomId());const{row:s,column:i}=n;if(s===void 0||i===void 0)throw new Error("row and column is required");const c=o.getBindingNode(s,i);o.setBindingNode(s,i,{...n,row:s,column:i}),this._cellBindInfoUpdate$.next({unitId:e,subunitId:t,sourceId:n.sourceId,nodeId:n.nodeId,row:s,column:i,changeType:c?M.Update:M.Add,oldSourceId:c==null?void 0:c.sourceId})}removeBindingNode(e,t,n,o){const s=this.getModel(e,t);if(s){const i=s.getBindingNode(n,o);i&&(s.removeBindingNode(n,o),this._cellBindInfoUpdate$.next({unitId:e,subunitId:t,sourceId:i.sourceId,nodeId:i.nodeId,row:n,column:o,changeType:M.Remove}))}}getBindingNode(e,t,n,o){const s=this.getModel(e,t);if(s)return s.getBindingNode(n,o)}createModel(e,t,n){const o=new w(n);return this.addModel(e,t,o),o}dispose(){this.modelMap.clear()}}class N extends h.Disposable{constructor(){super();u(this,"sourceMap",new Map);u(this,"_sourceDataUpdate$",new U.Subject);u(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 s=o===void 0?h.generateRandomId():o;let i;switch(t){case S.List:i=new $(s,n);break;case S.Object:i=new E(s);break;default:throw new Error(`Invalid source type: ${t}`)}return this._ensureUnitMap(e).set(s,i),i}updateSourceData(e,t,n){const o=this._getUnitMap(e),s=t instanceof b?t.getId():t,i=o==null?void 0:o.get(s);if(i)i.setSourceData(n),this._sourceDataUpdate$.next({...i.getSourceInfo(),unitId:e,changeType:M.Add});else throw new Error(`Source not found: ${s}`)}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:M.Remove}))}}var V=Object.defineProperty,L=Object.getOwnPropertyDescriptor,A=(d,r,e,t)=>{for(var n=t>1?void 0:t?L(r,e):r,o=d.length-1,s;o>=0;o--)(s=d[o])&&(n=(t?s(r,e,n):s(n))||n);return t&&n&&V(r,e,n),n},R=(d,r)=>(e,t)=>r(e,t,d);exports.SheetsSourceBindService=class extends h.Disposable{constructor(e,t,n){super();u(this,"_bindingModel",m.Value);u(this,"_bindModelRTreeCollection",new Map);this._sheetInterceptorService=e,this._sheetsBindingManager=t,this._sheetsSourceManager=n,this._registerInterceptor(),this._registerSourceChange()}usePathMode(){this._bindingModel=m.Path}useValueMode(){this._bindingModel=m.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)}_ensureRTreeCollection(e){return this._bindModelRTreeCollection.has(e)||this._bindModelRTreeCollection.set(e,new h.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:s}=e;if(n===S.List){if(s===M.Remove){const c=this._sheetsBindingManager.getBindingModelBySourceId(t),a=e.recordCount;for(const{unitId:l,subunitId:f,nodeId:g,row:p,column:_}of c){const I=this._getRTeeCollection(o);if(I){const B={startRow:p,startColumn:_,endRow:p+a,endColumn:_};I.remove({unitId:l,sheetId:f,id:g,range:B})}}return}if(s===M.Update){const c=e.oldRecordCount,a=this._sheetsBindingManager.getBindingModelBySourceId(t);for(const{unitId:l,subunitId:f,nodeId:g,row:p,column:_}of a){const I=this._getRTeeCollection(o);if(I){const B={startRow:p,startColumn:_,endRow:p+c,endColumn:_},v={startRow:p,startColumn:_,endRow:p+e.recordCount,endColumn:_};I.remove({unitId:l,sheetId:f,id:g,range:B}),I.insert({unitId:l,sheetId:f,id:g,range:v})}}return}const i=this._sheetsSourceManager.getSource(o,t);if(i&&i.hasData()){const a=i.getSourceInfo().recordCount,l=this._sheetsBindingManager.getBindingModelBySourceId(t);for(const{unitId:f,subunitId:g,nodeId:p,row:_,column:I}of l){const B=this._ensureRTreeCollection(f),v={startRow:_,startColumn:I,endRow:_+a,endColumn:I};B.insert({unitId:f,sheetId:g,id:p,range:v})}}}})),this.disposeWithMe(this._sheetsBindingManager.cellBindInfoUpdate$.subscribe(e=>{const{unitId:t,subunitId:n,sourceId:o,nodeId:s,row:i,column:c,changeType:a}=e,l=this._ensureRTreeCollection(t),f=this._sheetsSourceManager.getSource(t,o);if(f&&f.hasData()){const g=f.getSourceInfo();if(g.sourceType===S.List){const p=g.recordCount,_={startRow:i,startColumn:c,endRow:i+p,endColumn:c};if(a===M.Add)l.insert({unitId:t,sheetId:n,id:s,range:_});else if(a===M.Remove)l.remove({unitId:t,sheetId:n,id:s,range:_});else if(a===M.Update){const I=e.oldSourceId,B=this._sheetsSourceManager.getSource(t,I);if(B&&B.hasData()){const x=B.getSourceInfo().recordCount,P={startRow:i,startColumn:c,endRow:i+x,endColumn:c};l.remove({unitId:t,sheetId:n,id:s,range:P})}l.insert({unitId:t,sheetId:n,id:s,range:_})}}}}))}_getPathModeCellValue(e,t,n,o){const s=this._sheetsBindingManager.getModel(e,t),i=s==null?void 0:s.getBindingNode(n,o);if(i){const c=i.type;if(c===S.List)return{v:`#{${i.path}}`,s:{cl:{rgb:"blue"}}};if(c===S.Object)return{v:`[${i.path}]`,s:{cl:{rgb:"blue"}}}}}_getValueModeCellValue(e,t,n,o){const s=this._sheetsBindingManager.getModel(e,t);if(s){const c=s.getBindingNode(n,o);if(c){const{sourceId:a}=c,l=this._sheetsSourceManager.getSource(e,a);if(l&&l.hasData())return{v:(l==null?void 0:l.getData(c,n,o))||""}}}const i=this._getRTeeCollection(e);if(s&&i){const c={startRow:n,startColumn:o,endRow:n,endColumn:o},a=Array.from(i.bulkSearch([{unitId:e,sheetId:t,range:c}]));if(a.length>0){const l=s.getBindingNodeById(a[0]);if(l){const{sourceId:f}=l,g=this._sheetsSourceManager.getSource(e,f);if(g&&g.hasData())return{v:(g==null?void 0:g.getData(l,n,o))||""}}}}}_registerInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(y.INTERCEPTOR_POINT.CELL_CONTENT,{effect:h.InterceptorEffectEnum.Value,handler:(e,t,n)=>{const{row:o,col:s,unitId:i,subUnitId:c}=t;let a=null;return this._bindingModel===m.Path?a=this._getPathModeCellValue(i,c,o,s):a=this._getValueModeCellValue(i,c,o,s),n(a!==null?{...e,...a}:e)}}))}};exports.SheetsSourceBindService=A([R(0,h.Inject(y.SheetInterceptorService)),R(1,h.Inject(T)),R(2,h.Inject(N))],exports.SheetsSourceBindService);var q=Object.defineProperty,J=Object.getOwnPropertyDescriptor,W=(d,r,e,t)=>{for(var n=t>1?void 0:t?J(r,e):r,o=d.length-1,s;o>=0;o--)(s=d[o])&&(n=(t?s(r,e,n):s(n))||n);return t&&n&&q(r,e,n),n},D=(d,r)=>(e,t)=>r(e,t,d),C;exports.UniverSheetsBindingSourcePlugin=(C=class extends h.Plugin{constructor(r={},e,t){super(),this._config=r,this._injector=e,this._configService=t}onStarting(){[[T],[N],[exports.SheetsSourceBindService]].forEach(r=>this._injector.add(r))}onReady(){h.touchDependencies(this._injector,[[T],[N],[exports.SheetsSourceBindService]])}},u(C,"type",h.UniverInstanceType.UNIVER_SHEET),u(C,"pluginName","SHEET_BINDING_SOURCE_PLUGIN"),C);exports.UniverSheetsBindingSourcePlugin=W([D(1,h.Inject(h.Injector)),D(2,h.IConfigService)],exports.UniverSheetsBindingSourcePlugin);exports.BindModeEnum=m;exports.BindingModel=w;exports.DataBindingNodeTypeEnum=S;exports.SourceModelBase=b;
|
1
|
+
"use strict";var J=Object.defineProperty;var V=(i,o,e)=>o in i?J(i,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[o]=e;var u=(i,o,e)=>V(i,typeof o!="symbol"?o+"":o,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("@univerjs/core"),v=require("@univerjs/sheets"),j=require("rxjs");class T{constructor(o){u(this,"_matrix",{});u(this,"_nodeMap",new Map);u(this,"_sourceIdMap",new Map);o&&this._init(o)}_init(o){this.fromJSON(o)}getBindingNodesBySourceId(o){const e=this._sourceIdMap.get(o);if(e)return e.map(t=>this._nodeMap.get(t))}setBindingNode(o,e,t){this._matrix[o]||(this._matrix[o]={}),this._matrix[o][e]||(this._matrix[o][e]=t),this._nodeMap.set(t.nodeId,t);const n=this._sourceIdMap.get(t.sourceId);n?n.push(t.nodeId):this._sourceIdMap.set(t.sourceId,[t.nodeId])}getBindingNode(o,e){var t;return(t=this._matrix[o])==null?void 0:t[e]}removeBindingNode(o,e){var n;const t=(n=this._matrix[o])==null?void 0:n[e];if(t){this._matrix[o][e]=void 0,this._nodeMap.delete(t.nodeId);const s=this._sourceIdMap.get(t.sourceId);if(s){const r=s.indexOf(t.nodeId);r>=0&&s.splice(r,1),s.length===0&&this._sourceIdMap.delete(t.sourceId)}}}getBindingNodeById(o){return this._nodeMap.get(o)}fromJSON(o){o.forEach(e=>{this.setBindingNode(e.row,e.column,e)})}toJSON(){return Array.from(this._nodeMap.values())}}var _=(i=>(i.List="list",i.Object="object",i))(_||{}),B=(i=>(i.Path="path",i.Value="value",i))(B||{}),I=(i=>(i.Add="add",i.Remove="remove",i.Update="update",i))(I||{});function L(i){return i instanceof Date&&!isNaN(i.getTime())}function $(i){const o=new Date(i);if(!L(o))return i;const e=new Date(Date.UTC(1900,0,1,0,0,0)),t=new Date(Date.UTC(1900,1,28,0,0,0));let s=(o.getTime()-e.getTime())/(1e3*3600*24);return o>t&&(s+=1),s+1}class y{constructor(o){u(this,"_data");u(this,"id");u(this,"_hasData",!1);u(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 O extends y{constructor(e,t){super(e);u(this,"type",_.List);u(this,"_isListObject");u(this,"_fieldIndexMap",new Map);u(this,"_data",{fields:[],records:[]});this._isListObject=t!=null?t:!0}toggleListObject(e){this._isListObject=e}getData(e,t){const{path:n,row:s}=e,r=this._fieldIndexMap.get(n),d=t-s;if(d===0)return{v:this._data.fields[r]};let c;return this._isListObject&&(c=this._data.records[d-1][n]),c=this._data.records[d-1][r],e.isDate===!0?{v:$(c),s:{n:{pattern:"yyyy-m-d am/pm h:mm"}},t:l.CellValueType.NUMBER}:{v:c}}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 U extends y{constructor(e){super(e);u(this,"type",_.Object)}getData(e){const n=e.path.split(".");let s=this._data;for(const r of n)if(s=s[r],s===void 0)return null;return e.isDate===!0?{v:$(s),s:{n:{pattern:"yyyy-m-d am/pm h:mm"}},t:l.CellValueType.NUMBER}:{v:s}}getSourceInfo(){return{sourceId:this.id,sourceType:_.Object}}}var A=Object.defineProperty,q=Object.getOwnPropertyDescriptor,W=(i,o,e,t)=>{for(var n=t>1?void 0:t?q(o,e):o,s=i.length-1,r;s>=0;s--)(r=i[s])&&(n=(t?r(o,e,n):r(n))||n);return t&&n&&A(o,e,n),n},R=(i,o)=>(e,t)=>o(e,t,i);let C=class extends l.Disposable{constructor(o,e,t){super();u(this,"modelMap",new Map);u(this,"_cellBindInfoUpdate$",new j.Subject);u(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=v.getSheetCommandTarget(this._univerInstanceService);if(!s||!n||n.length===0)return{redos:[],undos:[]};const{unitId:r,subUnitId:d}=s;return(o.id===v.ClearSelectionContentCommand.id||o.id===v.ClearSelectionAllCommand.id)&&n.forEach(({range:c})=>{l.Range.foreach(c,(h,a)=>{this.getBindingNode(r,d,h,a)&&this.removeBindingNode(r,d,h,a)})}),{redos:e,undos:t}}}))}getBindingModelBySourceId(o){const e=[];return this.modelMap.forEach((t,n)=>{t.forEach((s,r)=>{const d=s.getBindingNodesBySourceId(o);if(d)for(const c of d)e.push({unitId:n,subunitId:r,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 T,this.addModel(o,e,n)),t.nodeId||(t.nodeId=l.generateRandomId());const{row:s,column:r}=t;if(s===void 0||r===void 0)throw new Error("row and column is required");const d=n.getBindingNode(s,r);n.setBindingNode(s,r,{...t,row:s,column:r}),this._cellBindInfoUpdate$.next({unitId:o,subunitId:e,sourceId:t.sourceId,nodeId:t.nodeId,row:s,column:r,changeType:d?I.Update:I.Add,oldSourceId:d==null?void 0:d.sourceId})}removeBindingNode(o,e,t,n){const s=this.getModel(o,e);if(s){const r=s.getBindingNode(t,n);r&&(s.removeBindingNode(t,n),this._cellBindInfoUpdate$.next({unitId:o,subunitId:e,sourceId:r.sourceId,nodeId:r.nodeId,row:t,column:n,changeType:I.Remove}))}}getBindingNode(o,e,t,n){const s=this.getModel(o,e);if(s)return s.getBindingNode(t,n)}createModel(o,e,t){const n=new T(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()}};C=W([R(0,l.IUniverInstanceService),R(1,l.Inject(v.SheetInterceptorService)),R(2,l.Inject(v.SheetsSelectionsService))],C);class w extends l.Disposable{constructor(){super();u(this,"sourceMap",new Map);u(this,"_sourceDataUpdate$",new j.Subject);u(this,"sourceDataUpdate$",this._sourceDataUpdate$.asObservable())}_ensureUnitMap(e){let t=this.sourceMap.get(e);return t||(t=new Map,this.sourceMap.set(e,t)),t}_getUnitMap(e){return this.sourceMap.get(e)}getSource(e,t){const n=this._getUnitMap(e);return n==null?void 0:n.get(t)}createSource(e,t,n,s){const r=s===void 0?l.generateRandomId():s;let d;switch(t){case _.List:d=new O(r,n);break;case _.Object:d=new U(r);break;default:throw new Error(`Invalid source type: ${t}`)}return this._ensureUnitMap(e).set(r,d),d}updateSourceData(e,t,n){const s=this._getUnitMap(e),r=t instanceof y?t.getId():t,d=s==null?void 0:s.get(r);if(d)d.setSourceData(n),this._sourceDataUpdate$.next({...d.getSourceInfo(),unitId:e,changeType:I.Add});else throw new Error(`Source not found: ${r}`)}removeSource(e,t){const n=this._getUnitMap(e),s=n==null?void 0:n.get(t);s&&(n==null||n.delete(t),this._sourceDataUpdate$.next({...s.getSourceInfo(),unitId:e,changeType:I.Remove}))}toJSON(e){const t=[],n=this._getUnitMap(e);if(n)for(const s of n.values())t.push(s.toJSON());return t}fromJSON(e,t){const n=this._ensureUnitMap(e);for(const s of t){let r;switch(s.type){case _.List:r=new O(s.id);break;case _.Object:r=new U(s.id);break;default:throw new Error(`Invalid source type: ${s.type}`)}r.fromJSON(s),n.set(s.id,r)}}dispose(){this._sourceDataUpdate$.complete(),this.sourceMap.clear()}}var G=Object.defineProperty,H=Object.getOwnPropertyDescriptor,z=(i,o,e,t)=>{for(var n=t>1?void 0:t?H(o,e):o,s=i.length-1,r;s>=0;s--)(r=i[s])&&(n=(t?r(o,e,n):r(n))||n);return t&&n&&G(o,e,n),n},D=(i,o)=>(e,t)=>o(e,t,i);exports.SheetsSourceBindService=class extends l.Disposable{constructor(e,t,n){super();u(this,"_bindingModel",B.Value);u(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 l.RTree),this._bindModelRTreeCollection.get(e)}_getRTeeCollection(e){return this._bindModelRTreeCollection.get(e)}_registerSourceChange(){this.disposeWithMe(this._sheetsSourceManager.sourceDataUpdate$.subscribe(e=>{const{sourceId:t,sourceType:n,unitId:s,changeType:r}=e;if(n===_.List){if(r===I.Remove){const c=this._sheetsBindingManager.getBindingModelBySourceId(t),h=e.recordCount;for(const{unitId:a,subunitId:f,nodeId:g,row:S,column:p}of c){const M=this._getRTeeCollection(s);if(M){const m={startRow:S,startColumn:p,endRow:S+h,endColumn:p};M.remove({unitId:a,sheetId:f,id:g,range:m})}}return}if(r===I.Update){const c=e.oldRecordCount,h=this._sheetsBindingManager.getBindingModelBySourceId(t);for(const{unitId:a,subunitId:f,nodeId:g,row:S,column:p}of h){const M=this._getRTeeCollection(s);if(M){const m={startRow:S,startColumn:p,endRow:S+c,endColumn:p},b={startRow:S,startColumn:p,endRow:S+e.recordCount,endColumn:p};M.remove({unitId:a,sheetId:f,id:g,range:m}),M.insert({unitId:a,sheetId:f,id:g,range:b})}}return}const d=this._sheetsSourceManager.getSource(s,t);if(d&&d.hasData()){const h=d.getSourceInfo().recordCount,a=this._sheetsBindingManager.getBindingModelBySourceId(t);for(const{unitId:f,subunitId:g,nodeId:S,row:p,column:M}of a){const m=this._ensureRTreeCollection(f),b={startRow:p,startColumn:M,endRow:p+h,endColumn:M};m.insert({unitId:f,sheetId:g,id:S,range:b})}}}})),this.disposeWithMe(this._sheetsBindingManager.cellBindInfoUpdate$.subscribe(e=>{const{unitId:t,subunitId:n,sourceId:s,nodeId:r,row:d,column:c,changeType:h}=e,a=this._ensureRTreeCollection(t),f=this._sheetsSourceManager.getSource(t,s);if(f&&f.hasData()){const g=f.getSourceInfo();if(g.sourceType===_.List){const S=g.recordCount,p={startRow:d,startColumn:c,endRow:d+S,endColumn:c};if(h===I.Add)a.insert({unitId:t,sheetId:n,id:r,range:p});else if(h===I.Remove)a.remove({unitId:t,sheetId:n,id:r,range:p});else if(h===I.Update){const M=e.oldSourceId,m=this._sheetsSourceManager.getSource(t,M);if(m&&m.hasData()){const x=m.getSourceInfo().recordCount,E={startRow:d,startColumn:c,endRow:d+x,endColumn:c};a.remove({unitId:t,sheetId:n,id:r,range:E})}a.insert({unitId:t,sheetId:n,id:r,range:p})}}}}))}_getPathModeCellValue(e,t,n,s){const r=this._sheetsBindingManager.getModel(e,t),d=r==null?void 0:r.getBindingNode(n,s);if(d){const c=d.type;if(c===_.List)return{v:`#{${d.path}}`,s:{cl:{rgb:"blue"}}};if(c===_.Object)return{v:`[${d.path}]`,s:{cl:{rgb:"blue"}}}}}_getValueModeCellValue(e,t,n,s){const r=this._sheetsBindingManager.getModel(e,t);if(r){const c=r.getBindingNode(n,s);if(c){const{sourceId:h}=c,a=this._sheetsSourceManager.getSource(e,h);if(a&&a.hasData())return(a==null?void 0:a.getData(c,n,s))||{v:""}}}const d=this._getRTeeCollection(e);if(r&&d){const c={startRow:n,startColumn:s,endRow:n,endColumn:s},h=Array.from(d.bulkSearch([{unitId:e,sheetId:t,range:c}]));if(h.length>0){const a=r.getBindingNodeById(h[0]);if(a){const{sourceId:f}=a,g=this._sheetsSourceManager.getSource(e,f);if(g&&g.hasData())return(g==null?void 0:g.getData(a,n,s))||{v:""}}}}}_registerInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(v.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Value|l.InterceptorEffectEnum.Style,priority:102,handler:(e,t,n)=>{const{row:s,col:r,unitId:d,subUnitId:c}=t;let h=null;return this._bindingModel===B.Path?h=this._getPathModeCellValue(d,c,s,r):h=this._getValueModeCellValue(d,c,s,r),n(h!==null?{...e,...h}:e)}}))}dispose(){this._bindModelRTreeCollection.clear()}};exports.SheetsSourceBindService=z([D(0,l.Inject(v.SheetInterceptorService)),D(1,l.Inject(C)),D(2,l.Inject(w))],exports.SheetsSourceBindService);var F=Object.defineProperty,K=Object.getOwnPropertyDescriptor,Q=(i,o,e,t)=>{for(var n=t>1?void 0:t?K(o,e):o,s=i.length-1,r;s>=0;s--)(r=i[s])&&(n=(t?r(o,e,n):r(n))||n);return t&&n&&F(o,e,n),n},P=(i,o)=>(e,t)=>o(e,t,i),N;exports.UniverSheetsBindingSourcePlugin=(N=class extends l.Plugin{constructor(o={},e,t){super(),this._config=o,this._injector=e,this._configService=t}onStarting(){[[C],[w],[exports.SheetsSourceBindService]].forEach(o=>this._injector.add(o))}onReady(){l.touchDependencies(this._injector,[[C],[w],[exports.SheetsSourceBindService]])}},u(N,"type",l.UniverInstanceType.UNIVER_SHEET),u(N,"pluginName","SHEET_BINDING_SOURCE_PLUGIN"),N);exports.UniverSheetsBindingSourcePlugin=Q([P(1,l.Inject(l.Injector)),P(2,l.IConfigService)],exports.UniverSheetsBindingSourcePlugin);exports.BindModeEnum=B;exports.BindingModel=T;exports.DataBindingNodeTypeEnum=_;exports.SheetsSourceManager=w;exports.SourceModelBase=y;
|
package/lib/es/facade.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { FEnum as s } from "@univerjs/core";
|
2
|
-
import { DataBindingNodeTypeEnum as S, BindModeEnum as h, SheetsSourceBindService as n } from "@univerjs/sheets-source-binding";
|
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
|
-
class
|
4
|
+
class B extends s {
|
5
5
|
get DataBindingNodeTypeEnum() {
|
6
6
|
return S;
|
7
7
|
}
|
@@ -9,34 +9,43 @@ class g extends s {
|
|
9
9
|
return h;
|
10
10
|
}
|
11
11
|
}
|
12
|
-
s.extend(
|
13
|
-
class
|
14
|
-
createSource(e, t) {
|
15
|
-
return this._injector.get(n).createSource(this.getId(), e, t);
|
12
|
+
s.extend(B);
|
13
|
+
class a extends d {
|
14
|
+
createSource(e, t, o) {
|
15
|
+
return this._injector.get(n).createSource(this.getId(), e, t, o);
|
16
16
|
}
|
17
17
|
getSource(e) {
|
18
18
|
return this._injector.get(n).getSource(this.getId(), e);
|
19
19
|
}
|
20
|
+
setSourceData(e, t) {
|
21
|
+
this._injector.get(g).updateSourceData(this.getId(), e, t);
|
22
|
+
}
|
20
23
|
usePathMode() {
|
21
24
|
this._injector.get(n).usePathMode();
|
22
25
|
}
|
23
26
|
useValueMode() {
|
24
27
|
this._injector.get(n).useValueMode();
|
25
28
|
}
|
29
|
+
loadSourceBindingPathInfo(e) {
|
30
|
+
this._injector.get(n).loadSourceBindingPathInfo(this.getId(), e);
|
31
|
+
}
|
32
|
+
saveSourceBindingPathInfo() {
|
33
|
+
return this._injector.get(n).getSourceBindingPathInfo(this.getId());
|
34
|
+
}
|
26
35
|
}
|
27
|
-
d.extend(
|
36
|
+
d.extend(a);
|
28
37
|
class j extends u {
|
29
38
|
setBindingNode(e) {
|
30
|
-
const
|
31
|
-
|
39
|
+
const o = this._injector.get(n), i = this._workbook.getUnitId();
|
40
|
+
o.setBindingNode(i, this.getSheetId(), e);
|
32
41
|
}
|
33
42
|
removeBindingNode(e, t) {
|
34
|
-
const
|
35
|
-
|
43
|
+
const i = this._injector.get(n), r = this._workbook.getUnitId();
|
44
|
+
i.removeBindingNode(r, this.getSheetId(), e, t);
|
36
45
|
}
|
37
46
|
getBindingNode(e, t) {
|
38
|
-
const
|
39
|
-
return
|
47
|
+
const i = this._injector.get(n), r = this._workbook.getUnitId();
|
48
|
+
return i.getBindingNode(r, this.getSheetId(), e, t);
|
40
49
|
}
|
41
50
|
}
|
42
51
|
u.extend(j);
|