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