@univerjs/sheets-source-binding 0.5.4-nightly.202501150735
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/README.md +16 -0
- package/lib/cjs/facade.js +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/es/facade.js +42 -0
- package/lib/es/index.js +461 -0
- package/lib/types/controllers/binding-manager.d.ts +29 -0
- package/lib/types/controllers/source-manager.d.ts +15 -0
- package/lib/types/facade/f-enum.d.ts +15 -0
- package/lib/types/facade/f-workbook.d.ts +34 -0
- package/lib/types/facade/f-worksheet.d.ts +31 -0
- package/lib/types/facade/index.d.ts +18 -0
- package/lib/types/index.d.ts +21 -0
- package/lib/types/model/binding-model.d.ts +15 -0
- package/lib/types/model/source-model.d.ts +36 -0
- package/lib/types/plugin.d.ts +14 -0
- package/lib/types/services/source-binding-service.d.ts +38 -0
- package/lib/types/types.d.ts +146 -0
- package/lib/umd/facade.js +1 -0
- package/lib/umd/index.js +1 -0
- package/package.json +72 -0
package/README.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# @univerjs/sheets-source-binding
|
2
|
+
|
3
|
+
[](https://npmjs.org/packages/@univerjs/sheets-source-binding)
|
4
|
+
[](https://img.shields.io/npm/l/@univerjs/sheets-source-binding)
|
5
|
+
|
6
|
+
## Introduction
|
7
|
+
|
8
|
+
> TODO: Introduction
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
### Installation
|
13
|
+
|
14
|
+
```shell
|
15
|
+
npm i @univerjs/sheets-source-binding
|
16
|
+
```
|
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";const d=require("@univerjs/core"),n=require("@univerjs/sheets-source-binding"),r=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 r.FWorkbook{createSource(e,t){return this._injector.get(n.SheetsSourceBindService).createSource(this.getId(),e,t)}getSource(e){return this._injector.get(n.SheetsSourceBindService).getSource(this.getId(),e)}usePathMode(){this._injector.get(n.SheetsSourceBindService).usePathMode()}useValueMode(){this._injector.get(n.SheetsSourceBindService).useValueMode()}}r.FWorkbook.extend(u);class h extends r.FWorksheet{setBindingNode(e){const o=this._injector.get(n.SheetsSourceBindService),i=this._workbook.getUnitId();o.setBindingNode(i,this.getSheetId(),e)}removeBindingNode(e,t){const i=this._injector.get(n.SheetsSourceBindService),c=this._workbook.getUnitId();i.removeBindingNode(c,this.getSheetId(),e,t)}getBindingNode(e,t){const i=this._injector.get(n.SheetsSourceBindService),c=this._workbook.getUnitId();return i.getBindingNode(c,this.getSheetId(),e,t)}}r.FWorksheet.extend(h);
|
package/lib/cjs/index.js
ADDED
@@ -0,0 +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;
|
package/lib/es/facade.js
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
import { FEnum as s } from "@univerjs/core";
|
2
|
+
import { DataBindingNodeTypeEnum as S, BindModeEnum as h, SheetsSourceBindService as n } from "@univerjs/sheets-source-binding";
|
3
|
+
import { FWorkbook as d, FWorksheet as u } from "@univerjs/sheets/facade";
|
4
|
+
class g extends s {
|
5
|
+
get DataBindingNodeTypeEnum() {
|
6
|
+
return S;
|
7
|
+
}
|
8
|
+
get BindModeEnum() {
|
9
|
+
return h;
|
10
|
+
}
|
11
|
+
}
|
12
|
+
s.extend(g);
|
13
|
+
class B extends d {
|
14
|
+
createSource(e, t) {
|
15
|
+
return this._injector.get(n).createSource(this.getId(), e, t);
|
16
|
+
}
|
17
|
+
getSource(e) {
|
18
|
+
return this._injector.get(n).getSource(this.getId(), e);
|
19
|
+
}
|
20
|
+
usePathMode() {
|
21
|
+
this._injector.get(n).usePathMode();
|
22
|
+
}
|
23
|
+
useValueMode() {
|
24
|
+
this._injector.get(n).useValueMode();
|
25
|
+
}
|
26
|
+
}
|
27
|
+
d.extend(B);
|
28
|
+
class j extends u {
|
29
|
+
setBindingNode(e) {
|
30
|
+
const i = this._injector.get(n), o = this._workbook.getUnitId();
|
31
|
+
i.setBindingNode(o, this.getSheetId(), e);
|
32
|
+
}
|
33
|
+
removeBindingNode(e, t) {
|
34
|
+
const o = this._injector.get(n), r = this._workbook.getUnitId();
|
35
|
+
o.removeBindingNode(r, this.getSheetId(), e, t);
|
36
|
+
}
|
37
|
+
getBindingNode(e, t) {
|
38
|
+
const o = this._injector.get(n), r = this._workbook.getUnitId();
|
39
|
+
return o.getBindingNode(r, this.getSheetId(), e, t);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
u.extend(j);
|
package/lib/es/index.js
ADDED
@@ -0,0 +1,461 @@
|
|
1
|
+
var j = Object.defineProperty;
|
2
|
+
var E = (d, o, e) => o in d ? j(d, o, { enumerable: !0, configurable: !0, writable: !0, value: e }) : d[o] = e;
|
3
|
+
var u = (d, o, e) => E(d, typeof o != "symbol" ? o + "" : o, e);
|
4
|
+
import { Disposable as T, generateRandomId as x, Inject as C, RTree as V, InterceptorEffectEnum as L, Plugin as A, UniverInstanceType as J, touchDependencies as W, Injector as G, IConfigService as H } from "@univerjs/core";
|
5
|
+
import { Subject as O } from "rxjs";
|
6
|
+
import { SheetInterceptorService as q, INTERCEPTOR_POINT as z } from "@univerjs/sheets";
|
7
|
+
class D {
|
8
|
+
constructor(o) {
|
9
|
+
u(this, "_matrix", {});
|
10
|
+
u(this, "_nodeMap", /* @__PURE__ */ new Map());
|
11
|
+
u(this, "_sourceIdMap", /* @__PURE__ */ new Map());
|
12
|
+
o && this._init(o);
|
13
|
+
}
|
14
|
+
_init(o) {
|
15
|
+
this.fromJSON();
|
16
|
+
}
|
17
|
+
getBindingNodesBySourceId(o) {
|
18
|
+
const e = this._sourceIdMap.get(o);
|
19
|
+
if (e)
|
20
|
+
return e.map((t) => this._nodeMap.get(t));
|
21
|
+
}
|
22
|
+
setBindingNode(o, e, t) {
|
23
|
+
this._matrix[o] || (this._matrix[o] = {}), this._matrix[o][e] || (this._matrix[o][e] = t), this._nodeMap.set(t.nodeId, t);
|
24
|
+
const n = this._sourceIdMap.get(t.sourceId);
|
25
|
+
n ? n.push(t.nodeId) : this._sourceIdMap.set(t.sourceId, [t.nodeId]);
|
26
|
+
}
|
27
|
+
getBindingNode(o, e) {
|
28
|
+
var t;
|
29
|
+
return (t = this._matrix[o]) == null ? void 0 : t[e];
|
30
|
+
}
|
31
|
+
removeBindingNode(o, e) {
|
32
|
+
var n;
|
33
|
+
const t = (n = this._matrix[o]) == null ? void 0 : n[e];
|
34
|
+
if (t) {
|
35
|
+
this._matrix[o][e] = void 0, this._nodeMap.delete(t.nodeId);
|
36
|
+
const s = this._sourceIdMap.get(t.sourceId);
|
37
|
+
if (s) {
|
38
|
+
const r = s.indexOf(t.nodeId);
|
39
|
+
r >= 0 && s.splice(r, 1), s.length === 0 && this._sourceIdMap.delete(t.sourceId);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
getBindingNodeById(o) {
|
44
|
+
return this._nodeMap.get(o);
|
45
|
+
}
|
46
|
+
fromJSON() {
|
47
|
+
}
|
48
|
+
toJSON() {
|
49
|
+
}
|
50
|
+
}
|
51
|
+
var M = /* @__PURE__ */ ((d) => (d.List = "list", d.Object = "object", d))(M || {}), S = /* @__PURE__ */ ((d) => (d.Path = "path", d.Value = "value", d))(S || {}), p = /* @__PURE__ */ ((d) => (d.Add = "add", d.Remove = "remove", d.Update = "update", d))(p || {});
|
52
|
+
class N {
|
53
|
+
constructor(o) {
|
54
|
+
u(this, "_data");
|
55
|
+
u(this, "id");
|
56
|
+
u(this, "_hasData", !1);
|
57
|
+
u(this, "type");
|
58
|
+
this.id = o;
|
59
|
+
}
|
60
|
+
getId() {
|
61
|
+
return this.id;
|
62
|
+
}
|
63
|
+
getType() {
|
64
|
+
return this.type;
|
65
|
+
}
|
66
|
+
hasData() {
|
67
|
+
return this._hasData;
|
68
|
+
}
|
69
|
+
setSourceData(o) {
|
70
|
+
this._data = o, this._hasData = !0;
|
71
|
+
}
|
72
|
+
}
|
73
|
+
class F extends N {
|
74
|
+
constructor(e, t) {
|
75
|
+
super(e);
|
76
|
+
u(this, "type", M.List);
|
77
|
+
u(this, "_isListObject");
|
78
|
+
u(this, "_fieldIndexMap", /* @__PURE__ */ new Map());
|
79
|
+
u(this, "_data", { fields: [], records: [] });
|
80
|
+
this._isListObject = t != null ? t : !0;
|
81
|
+
}
|
82
|
+
/**
|
83
|
+
* Toggle the list object mode. The default value is true.
|
84
|
+
* In the list object mode, the records is an array of objects. Such as [{name: 'Tom', age: 20}, {name: 'Jerry', age: 18}].
|
85
|
+
* In the list array mode, the records is an array of arrays. Such as [['Tom', 20], ['Jerry', 18]].
|
86
|
+
*/
|
87
|
+
toggleListObject(e) {
|
88
|
+
this._isListObject = e;
|
89
|
+
}
|
90
|
+
getData(e, t) {
|
91
|
+
const { path: n, row: s } = e, r = this._fieldIndexMap.get(n), i = t - s;
|
92
|
+
return i === 0 ? this._data.fields[r] : this._isListObject ? this._data.records[i - 1][n] : this._data.records[i - 1][r];
|
93
|
+
}
|
94
|
+
setSourceData(e) {
|
95
|
+
super.setSourceData(e);
|
96
|
+
const { fields: t } = e;
|
97
|
+
this._fieldIndexMap.clear(), t.forEach((n, s) => {
|
98
|
+
this._fieldIndexMap.set(n, s);
|
99
|
+
});
|
100
|
+
}
|
101
|
+
getSourceInfo() {
|
102
|
+
return {
|
103
|
+
sourceId: this.id,
|
104
|
+
sourceType: this.type,
|
105
|
+
fields: this._data.fields,
|
106
|
+
recordCount: this._data.records.length
|
107
|
+
};
|
108
|
+
}
|
109
|
+
}
|
110
|
+
class K extends N {
|
111
|
+
constructor(e) {
|
112
|
+
super(e);
|
113
|
+
u(this, "type", M.Object);
|
114
|
+
}
|
115
|
+
getData(e) {
|
116
|
+
const n = e.path.split(".");
|
117
|
+
let s = this._data;
|
118
|
+
for (const r of n)
|
119
|
+
if (s = s[r], s === void 0)
|
120
|
+
return null;
|
121
|
+
return s;
|
122
|
+
}
|
123
|
+
getSourceInfo() {
|
124
|
+
return {
|
125
|
+
sourceId: this.id,
|
126
|
+
sourceType: M.Object
|
127
|
+
};
|
128
|
+
}
|
129
|
+
}
|
130
|
+
class w extends T {
|
131
|
+
constructor() {
|
132
|
+
super();
|
133
|
+
u(this, "modelMap", /* @__PURE__ */ new Map());
|
134
|
+
u(this, "_cellBindInfoUpdate$", new O());
|
135
|
+
u(this, "cellBindInfoUpdate$", this._cellBindInfoUpdate$.asObservable());
|
136
|
+
}
|
137
|
+
getBindingModelBySourceId(e) {
|
138
|
+
const t = [];
|
139
|
+
return this.modelMap.forEach((n, s) => {
|
140
|
+
n.forEach((r, i) => {
|
141
|
+
const a = r.getBindingNodesBySourceId(e);
|
142
|
+
if (a)
|
143
|
+
for (const c of a)
|
144
|
+
t.push({
|
145
|
+
unitId: s,
|
146
|
+
subunitId: i,
|
147
|
+
sourceId: e,
|
148
|
+
nodeId: c.nodeId,
|
149
|
+
row: c.row,
|
150
|
+
column: c.column
|
151
|
+
});
|
152
|
+
});
|
153
|
+
}), t;
|
154
|
+
}
|
155
|
+
addModel(e, t, n) {
|
156
|
+
var s;
|
157
|
+
this.modelMap.has(e) || this.modelMap.set(e, /* @__PURE__ */ new Map()), (s = this.modelMap.get(e)) == null || s.set(t, n);
|
158
|
+
}
|
159
|
+
getModel(e, t) {
|
160
|
+
var n;
|
161
|
+
return (n = this.modelMap.get(e)) == null ? void 0 : n.get(t);
|
162
|
+
}
|
163
|
+
setBindingNode(e, t, n) {
|
164
|
+
let s = this.getModel(e, t);
|
165
|
+
s || (s = new D(), this.addModel(e, t, s)), n.nodeId || (n.nodeId = x());
|
166
|
+
const { row: r, column: i } = n;
|
167
|
+
if (r === void 0 || i === void 0)
|
168
|
+
throw new Error("row and column is required");
|
169
|
+
const a = s.getBindingNode(r, i);
|
170
|
+
s.setBindingNode(r, i, { ...n, row: r, column: i }), this._cellBindInfoUpdate$.next({
|
171
|
+
unitId: e,
|
172
|
+
subunitId: t,
|
173
|
+
sourceId: n.sourceId,
|
174
|
+
nodeId: n.nodeId,
|
175
|
+
row: r,
|
176
|
+
column: i,
|
177
|
+
changeType: a ? p.Update : p.Add,
|
178
|
+
oldSourceId: a == null ? void 0 : a.sourceId
|
179
|
+
});
|
180
|
+
}
|
181
|
+
removeBindingNode(e, t, n, s) {
|
182
|
+
const r = this.getModel(e, t);
|
183
|
+
if (r) {
|
184
|
+
const i = r.getBindingNode(n, s);
|
185
|
+
i && (r.removeBindingNode(n, s), this._cellBindInfoUpdate$.next({
|
186
|
+
unitId: e,
|
187
|
+
subunitId: t,
|
188
|
+
sourceId: i.sourceId,
|
189
|
+
nodeId: i.nodeId,
|
190
|
+
row: n,
|
191
|
+
column: s,
|
192
|
+
changeType: p.Remove
|
193
|
+
}));
|
194
|
+
}
|
195
|
+
}
|
196
|
+
getBindingNode(e, t, n, s) {
|
197
|
+
const r = this.getModel(e, t);
|
198
|
+
if (r)
|
199
|
+
return r.getBindingNode(n, s);
|
200
|
+
}
|
201
|
+
createModel(e, t, n) {
|
202
|
+
const s = new D(n);
|
203
|
+
return this.addModel(e, t, s), s;
|
204
|
+
}
|
205
|
+
dispose() {
|
206
|
+
this.modelMap.clear();
|
207
|
+
}
|
208
|
+
}
|
209
|
+
class b extends T {
|
210
|
+
constructor() {
|
211
|
+
super();
|
212
|
+
u(this, "sourceMap", /* @__PURE__ */ new Map());
|
213
|
+
u(this, "_sourceDataUpdate$", new O());
|
214
|
+
u(this, "sourceDataUpdate$", this._sourceDataUpdate$.asObservable());
|
215
|
+
}
|
216
|
+
_ensureUnitMap(e) {
|
217
|
+
let t = this.sourceMap.get(e);
|
218
|
+
return t || (t = /* @__PURE__ */ new Map(), this.sourceMap.set(e, t)), t;
|
219
|
+
}
|
220
|
+
_getUnitMap(e) {
|
221
|
+
return this.sourceMap.get(e);
|
222
|
+
}
|
223
|
+
getSource(e, t) {
|
224
|
+
const n = this._getUnitMap(e);
|
225
|
+
return n == null ? void 0 : n.get(t);
|
226
|
+
}
|
227
|
+
createSource(e, t, n, s) {
|
228
|
+
const r = s === void 0 ? x() : s;
|
229
|
+
let i;
|
230
|
+
switch (t) {
|
231
|
+
case M.List:
|
232
|
+
i = new F(r, n);
|
233
|
+
break;
|
234
|
+
case M.Object:
|
235
|
+
i = new K(r);
|
236
|
+
break;
|
237
|
+
default:
|
238
|
+
throw new Error(`Invalid source type: ${t}`);
|
239
|
+
}
|
240
|
+
return this._ensureUnitMap(e).set(r, i), i;
|
241
|
+
}
|
242
|
+
updateSourceData(e, t, n) {
|
243
|
+
const s = this._getUnitMap(e), r = t instanceof N ? t.getId() : t, i = s == null ? void 0 : s.get(r);
|
244
|
+
if (i)
|
245
|
+
i.setSourceData(n), this._sourceDataUpdate$.next({ ...i.getSourceInfo(), unitId: e, changeType: p.Add });
|
246
|
+
else
|
247
|
+
throw new Error(`Source not found: ${r}`);
|
248
|
+
}
|
249
|
+
removeSource(e, t) {
|
250
|
+
const n = this._getUnitMap(e), s = n == null ? void 0 : n.get(t);
|
251
|
+
s && (n == null || n.delete(t), this._sourceDataUpdate$.next({ ...s.getSourceInfo(), unitId: e, changeType: p.Remove }));
|
252
|
+
}
|
253
|
+
}
|
254
|
+
var Q = Object.defineProperty, X = Object.getOwnPropertyDescriptor, Y = (d, o, e, t) => {
|
255
|
+
for (var n = t > 1 ? void 0 : t ? X(o, e) : o, s = d.length - 1, r; s >= 0; s--)
|
256
|
+
(r = d[s]) && (n = (t ? r(o, e, n) : r(n)) || n);
|
257
|
+
return t && n && Q(o, e, n), n;
|
258
|
+
}, R = (d, o) => (e, t) => o(e, t, d);
|
259
|
+
let v = class extends T {
|
260
|
+
constructor(o, e, t) {
|
261
|
+
super();
|
262
|
+
u(this, "_bindingModel", S.Value);
|
263
|
+
u(this, "_bindModelRTreeCollection", /* @__PURE__ */ new Map());
|
264
|
+
this._sheetInterceptorService = o, this._sheetsBindingManager = e, this._sheetsSourceManager = t, this._registerInterceptor(), this._registerSourceChange();
|
265
|
+
}
|
266
|
+
/**
|
267
|
+
* Set the binding model to path mode, in this mode, the binding path will show in the cell.
|
268
|
+
*/
|
269
|
+
usePathMode() {
|
270
|
+
this._bindingModel = S.Path;
|
271
|
+
}
|
272
|
+
/**
|
273
|
+
* Set the binding model to value mode, in this mode, the value of source will show in the cell.
|
274
|
+
*/
|
275
|
+
useValueMode() {
|
276
|
+
this._bindingModel = S.Value;
|
277
|
+
}
|
278
|
+
/**
|
279
|
+
* Get the current binding model.
|
280
|
+
* @returns the current binding model
|
281
|
+
*/
|
282
|
+
getBindingModel() {
|
283
|
+
return this._bindingModel;
|
284
|
+
}
|
285
|
+
createBindModel(o, e) {
|
286
|
+
return this._sheetsBindingManager.createModel(o, e);
|
287
|
+
}
|
288
|
+
setBindingNode(o, e, t) {
|
289
|
+
this._sheetsBindingManager.setBindingNode(o, e, t);
|
290
|
+
}
|
291
|
+
removeBindingNode(o, e, t, n) {
|
292
|
+
this._sheetsBindingManager.removeBindingNode(o, e, t, n);
|
293
|
+
}
|
294
|
+
getBindingNode(o, e, t, n) {
|
295
|
+
return this._sheetsBindingManager.getBindingNode(o, e, t, n);
|
296
|
+
}
|
297
|
+
getSource(o, e) {
|
298
|
+
return this._sheetsSourceManager.getSource(o, e);
|
299
|
+
}
|
300
|
+
createSource(o, e, t, n) {
|
301
|
+
return this._sheetsSourceManager.createSource(o, e, t, n);
|
302
|
+
}
|
303
|
+
_ensureRTreeCollection(o) {
|
304
|
+
return this._bindModelRTreeCollection.has(o) || this._bindModelRTreeCollection.set(o, new V()), this._bindModelRTreeCollection.get(o);
|
305
|
+
}
|
306
|
+
_getRTeeCollection(o) {
|
307
|
+
return this._bindModelRTreeCollection.get(o);
|
308
|
+
}
|
309
|
+
// eslint-disable-next-line max-lines-per-function
|
310
|
+
_registerSourceChange() {
|
311
|
+
this.disposeWithMe(this._sheetsSourceManager.sourceDataUpdate$.subscribe((o) => {
|
312
|
+
const { sourceId: e, sourceType: t, unitId: n, changeType: s } = o;
|
313
|
+
if (t === M.List) {
|
314
|
+
if (s === p.Remove) {
|
315
|
+
const i = this._sheetsBindingManager.getBindingModelBySourceId(e), a = o.recordCount;
|
316
|
+
for (const { unitId: c, subunitId: g, nodeId: l, row: _, column: h } of i) {
|
317
|
+
const f = this._getRTeeCollection(n);
|
318
|
+
if (f) {
|
319
|
+
const I = { startRow: _, startColumn: h, endRow: _ + a, endColumn: h };
|
320
|
+
f.remove({ unitId: c, sheetId: g, id: l, range: I });
|
321
|
+
}
|
322
|
+
}
|
323
|
+
return;
|
324
|
+
}
|
325
|
+
if (s === p.Update) {
|
326
|
+
const i = o.oldRecordCount, a = this._sheetsBindingManager.getBindingModelBySourceId(e);
|
327
|
+
for (const { unitId: c, subunitId: g, nodeId: l, row: _, column: h } of a) {
|
328
|
+
const f = this._getRTeeCollection(n);
|
329
|
+
if (f) {
|
330
|
+
const I = { startRow: _, startColumn: h, endRow: _ + i, endColumn: h }, m = { startRow: _, startColumn: h, endRow: _ + o.recordCount, endColumn: h };
|
331
|
+
f.remove({ unitId: c, sheetId: g, id: l, range: I }), f.insert({ unitId: c, sheetId: g, id: l, range: m });
|
332
|
+
}
|
333
|
+
}
|
334
|
+
return;
|
335
|
+
}
|
336
|
+
const r = this._sheetsSourceManager.getSource(n, e);
|
337
|
+
if (r && r.hasData()) {
|
338
|
+
const a = r.getSourceInfo().recordCount, c = this._sheetsBindingManager.getBindingModelBySourceId(e);
|
339
|
+
for (const { unitId: g, subunitId: l, nodeId: _, row: h, column: f } of c) {
|
340
|
+
const I = this._ensureRTreeCollection(g), m = { startRow: h, startColumn: f, endRow: h + a, endColumn: f };
|
341
|
+
I.insert({ unitId: g, sheetId: l, id: _, range: m });
|
342
|
+
}
|
343
|
+
}
|
344
|
+
}
|
345
|
+
})), this.disposeWithMe(this._sheetsBindingManager.cellBindInfoUpdate$.subscribe((o) => {
|
346
|
+
const { unitId: e, subunitId: t, sourceId: n, nodeId: s, row: r, column: i, changeType: a } = o, c = this._ensureRTreeCollection(e), g = this._sheetsSourceManager.getSource(e, n);
|
347
|
+
if (g && g.hasData()) {
|
348
|
+
const l = g.getSourceInfo();
|
349
|
+
if (l.sourceType === M.List) {
|
350
|
+
const _ = l.recordCount, h = { startRow: r, startColumn: i, endRow: r + _, endColumn: i };
|
351
|
+
if (a === p.Add)
|
352
|
+
c.insert({ unitId: e, sheetId: t, id: s, range: h });
|
353
|
+
else if (a === p.Remove)
|
354
|
+
c.remove({ unitId: e, sheetId: t, id: s, range: h });
|
355
|
+
else if (a === p.Update) {
|
356
|
+
const f = o.oldSourceId, I = this._sheetsSourceManager.getSource(e, f);
|
357
|
+
if (I && I.hasData()) {
|
358
|
+
const P = I.getSourceInfo().recordCount, $ = { startRow: r, startColumn: i, endRow: r + P, endColumn: i };
|
359
|
+
c.remove({ unitId: e, sheetId: t, id: s, range: $ });
|
360
|
+
}
|
361
|
+
c.insert({ unitId: e, sheetId: t, id: s, range: h });
|
362
|
+
}
|
363
|
+
}
|
364
|
+
}
|
365
|
+
}));
|
366
|
+
}
|
367
|
+
_getPathModeCellValue(o, e, t, n) {
|
368
|
+
const s = this._sheetsBindingManager.getModel(o, e), r = s == null ? void 0 : s.getBindingNode(t, n);
|
369
|
+
if (r) {
|
370
|
+
const i = r.type;
|
371
|
+
if (i === M.List)
|
372
|
+
return {
|
373
|
+
v: `#{${r.path}}`,
|
374
|
+
s: { cl: { rgb: "blue" } }
|
375
|
+
};
|
376
|
+
if (i === M.Object)
|
377
|
+
return {
|
378
|
+
v: `[${r.path}]`,
|
379
|
+
s: { cl: { rgb: "blue" } }
|
380
|
+
};
|
381
|
+
}
|
382
|
+
}
|
383
|
+
_getValueModeCellValue(o, e, t, n) {
|
384
|
+
const s = this._sheetsBindingManager.getModel(o, e);
|
385
|
+
if (s) {
|
386
|
+
const i = s.getBindingNode(t, n);
|
387
|
+
if (i) {
|
388
|
+
const { sourceId: a } = i, c = this._sheetsSourceManager.getSource(o, a);
|
389
|
+
if (c && c.hasData())
|
390
|
+
return {
|
391
|
+
v: (c == null ? void 0 : c.getData(i, t, n)) || ""
|
392
|
+
};
|
393
|
+
}
|
394
|
+
}
|
395
|
+
const r = this._getRTeeCollection(o);
|
396
|
+
if (s && r) {
|
397
|
+
const i = { startRow: t, startColumn: n, endRow: t, endColumn: n }, a = Array.from(r.bulkSearch([{ unitId: o, sheetId: e, range: i }]));
|
398
|
+
if (a.length > 0) {
|
399
|
+
const c = s.getBindingNodeById(a[0]);
|
400
|
+
if (c) {
|
401
|
+
const { sourceId: g } = c, l = this._sheetsSourceManager.getSource(o, g);
|
402
|
+
if (l && l.hasData())
|
403
|
+
return {
|
404
|
+
v: (l == null ? void 0 : l.getData(c, t, n)) || ""
|
405
|
+
};
|
406
|
+
}
|
407
|
+
}
|
408
|
+
}
|
409
|
+
}
|
410
|
+
_registerInterceptor() {
|
411
|
+
this.disposeWithMe(this._sheetInterceptorService.intercept(z.CELL_CONTENT, {
|
412
|
+
effect: L.Value,
|
413
|
+
handler: (o, e, t) => {
|
414
|
+
const { row: n, col: s, unitId: r, subUnitId: i } = e;
|
415
|
+
let a = null;
|
416
|
+
return this._bindingModel === S.Path ? a = this._getPathModeCellValue(r, i, n, s) : a = this._getValueModeCellValue(r, i, n, s), t(a !== null ? { ...o, ...a } : o);
|
417
|
+
}
|
418
|
+
}));
|
419
|
+
}
|
420
|
+
};
|
421
|
+
v = Y([
|
422
|
+
R(0, C(q)),
|
423
|
+
R(1, C(w)),
|
424
|
+
R(2, C(b))
|
425
|
+
], v);
|
426
|
+
var Z = Object.defineProperty, k = Object.getOwnPropertyDescriptor, ee = (d, o, e, t) => {
|
427
|
+
for (var n = t > 1 ? void 0 : t ? k(o, e) : o, s = d.length - 1, r; s >= 0; s--)
|
428
|
+
(r = d[s]) && (n = (t ? r(o, e, n) : r(n)) || n);
|
429
|
+
return t && n && Z(o, e, n), n;
|
430
|
+
}, U = (d, o) => (e, t) => o(e, t, d), B;
|
431
|
+
let y = (B = class extends A {
|
432
|
+
constructor(d = {}, o, e) {
|
433
|
+
super(), this._config = d, this._injector = o, this._configService = e;
|
434
|
+
}
|
435
|
+
onStarting() {
|
436
|
+
[
|
437
|
+
[w],
|
438
|
+
[b],
|
439
|
+
[v]
|
440
|
+
].forEach((d) => this._injector.add(d));
|
441
|
+
}
|
442
|
+
onReady() {
|
443
|
+
W(this._injector, [
|
444
|
+
[w],
|
445
|
+
[b],
|
446
|
+
[v]
|
447
|
+
]);
|
448
|
+
}
|
449
|
+
}, u(B, "type", J.UNIVER_SHEET), u(B, "pluginName", "SHEET_BINDING_SOURCE_PLUGIN"), B);
|
450
|
+
y = ee([
|
451
|
+
U(1, C(G)),
|
452
|
+
U(2, H)
|
453
|
+
], y);
|
454
|
+
export {
|
455
|
+
S as BindModeEnum,
|
456
|
+
D as BindingModel,
|
457
|
+
M as DataBindingNodeTypeEnum,
|
458
|
+
v as SheetsSourceBindService,
|
459
|
+
N as SourceModelBase,
|
460
|
+
y as UniverSheetsBindingSourcePlugin
|
461
|
+
};
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { ICellBindingNode, ICellBindingNodeParam, BindingSourceChangeTypeEnum } from '../types';
|
2
|
+
import { Disposable } from '@univerjs/core';
|
3
|
+
import { SheetBindingModel } from '../model/binding-model';
|
4
|
+
interface IBindingNodeInfo {
|
5
|
+
unitId: string;
|
6
|
+
subunitId: string;
|
7
|
+
sourceId: string;
|
8
|
+
nodeId: string;
|
9
|
+
row: number;
|
10
|
+
column: number;
|
11
|
+
}
|
12
|
+
export declare class SheetsBindingManager extends Disposable {
|
13
|
+
modelMap: Map<string, Map<string, SheetBindingModel>>;
|
14
|
+
private _cellBindInfoUpdate$;
|
15
|
+
cellBindInfoUpdate$: import('rxjs').Observable<IBindingNodeInfo & {
|
16
|
+
changeType: BindingSourceChangeTypeEnum;
|
17
|
+
oldSourceId?: string;
|
18
|
+
}>;
|
19
|
+
constructor();
|
20
|
+
getBindingModelBySourceId(sourceId: string): IBindingNodeInfo[];
|
21
|
+
addModel(unitId: string, subunitId: string, model: SheetBindingModel): void;
|
22
|
+
getModel(unitId: string, subunitId: string): SheetBindingModel | undefined;
|
23
|
+
setBindingNode(unitId: string, subunitId: string, node: ICellBindingNodeParam): void;
|
24
|
+
removeBindingNode(unitId: string, subunitId: string, row: number, column: number): void;
|
25
|
+
getBindingNode(unitId: string, subunitId: string, row: number, column: number): ICellBindingNode | undefined;
|
26
|
+
createModel(unitId: string, subunitId: string, json?: any): SheetBindingModel;
|
27
|
+
dispose(): void;
|
28
|
+
}
|
29
|
+
export {};
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { ISourceEvent, DataBindingNodeTypeEnum } from '../types';
|
2
|
+
import { Disposable } from '@univerjs/core';
|
3
|
+
import { SourceModelBase } from '../model/source-model';
|
4
|
+
export declare class SheetsSourceManager extends Disposable {
|
5
|
+
sourceMap: Map<string, Map<string, SourceModelBase>>;
|
6
|
+
private _sourceDataUpdate$;
|
7
|
+
sourceDataUpdate$: import('rxjs').Observable<ISourceEvent>;
|
8
|
+
constructor();
|
9
|
+
private _ensureUnitMap;
|
10
|
+
private _getUnitMap;
|
11
|
+
getSource(unitId: string, id: string): SourceModelBase | undefined;
|
12
|
+
createSource(unitId: string, type: DataBindingNodeTypeEnum, isListObject?: boolean, id?: string): SourceModelBase;
|
13
|
+
updateSourceData(unitId: string, idOrInstance: string | SourceModelBase, data: any): void;
|
14
|
+
removeSource(unitId: string, id: string): void;
|
15
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { BindModeEnum, DataBindingNodeTypeEnum } from '@univerjs/sheets-source-binding';
|
2
|
+
export interface ISourceBindingEnumMixin {
|
3
|
+
/**
|
4
|
+
* Represents the type of data binding node.{@link DataBindingNodeTypeEnum}
|
5
|
+
*/
|
6
|
+
DataBindingNodeTypeEnum: typeof DataBindingNodeTypeEnum;
|
7
|
+
/**
|
8
|
+
* Represents the type of data binding node. {@link BindModeEnum}
|
9
|
+
*/
|
10
|
+
BindModeEnum: typeof BindModeEnum;
|
11
|
+
}
|
12
|
+
declare module '@univerjs/core' {
|
13
|
+
interface FEnum extends ISourceBindingEnumMixin {
|
14
|
+
}
|
15
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import { DataBindingNodeTypeEnum, SourceModelBase } from '@univerjs/sheets-source-binding';
|
2
|
+
import { FWorkbook } from '@univerjs/sheets/facade';
|
3
|
+
export interface IFWorkbookSourceBindingMixin {
|
4
|
+
/**
|
5
|
+
* Create a source model with the specified type.
|
6
|
+
* @param {DataBindingNodeTypeEnum} type The source type.
|
7
|
+
* @param {boolean} [isListObject] Whether the source is a list object.
|
8
|
+
* @returns {SourceModelBase} The source data of sheet.
|
9
|
+
*/
|
10
|
+
createSource(type: DataBindingNodeTypeEnum, isListObject?: boolean): SourceModelBase;
|
11
|
+
/**
|
12
|
+
* Switch to path mode.In this mode, the path will show in cell.
|
13
|
+
*/
|
14
|
+
usePathMode(): void;
|
15
|
+
/**
|
16
|
+
* Switch to value mode.This is the default mode. In this mode, the cell value will fulfill by source values.
|
17
|
+
*/
|
18
|
+
useValueMode(): void;
|
19
|
+
/**
|
20
|
+
* Get the source model by the specified source id.
|
21
|
+
* @param {string} sourceId The source id.
|
22
|
+
*/
|
23
|
+
getSource(sourceId: string): SourceModelBase | undefined;
|
24
|
+
}
|
25
|
+
export declare class FWorkbookSourceBinding extends FWorkbook implements IFWorkbookSourceBindingMixin {
|
26
|
+
createSource(type: DataBindingNodeTypeEnum, isListObject?: boolean): SourceModelBase;
|
27
|
+
getSource(sourceId: string): SourceModelBase | undefined;
|
28
|
+
usePathMode(): void;
|
29
|
+
useValueMode(): void;
|
30
|
+
}
|
31
|
+
declare module '@univerjs/sheets/facade' {
|
32
|
+
interface FWorkbook extends IFWorkbookSourceBindingMixin {
|
33
|
+
}
|
34
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { ICellBindingNode, ICellBindingNodeParam } from '@univerjs/sheets-source-binding';
|
2
|
+
import { FWorksheet } from '@univerjs/sheets/facade';
|
3
|
+
export interface IFworksheetSourceBindingMixin {
|
4
|
+
/**
|
5
|
+
* Set the binding node for the specified cell.
|
6
|
+
* @param bindingNode The binding node to set. {@link ICellBindingNodeParam}
|
7
|
+
*/
|
8
|
+
setBindingNode(bindingNode: ICellBindingNodeParam): void;
|
9
|
+
/**
|
10
|
+
* Remove the binding node for the specified cell.
|
11
|
+
* @param {number} row The row index of the cell.
|
12
|
+
* @param {number} column The column index of the cell.
|
13
|
+
*/
|
14
|
+
removeBindingNode(row: number, column: number): void;
|
15
|
+
/**
|
16
|
+
* Get the binding node for the specified cell.
|
17
|
+
* @param {number} row The row index of the cell.
|
18
|
+
* @param {number} column The column index of the cell.
|
19
|
+
* @returns The binding node of the cell. {@link ICellBindingNode} or undefined if not found.
|
20
|
+
*/
|
21
|
+
getBindingNode(row: number, column: number): ICellBindingNode | undefined;
|
22
|
+
}
|
23
|
+
export declare class FWorksheetSourceBinding extends FWorksheet implements IFworksheetSourceBindingMixin {
|
24
|
+
setBindingNode(bindingNode: ICellBindingNodeParam): void;
|
25
|
+
removeBindingNode(row: number, column: number): void;
|
26
|
+
getBindingNode(row: number, column: number): ICellBindingNode | undefined;
|
27
|
+
}
|
28
|
+
declare module '@univerjs/sheets/facade' {
|
29
|
+
interface FWorksheet extends IFworksheetSourceBindingMixin {
|
30
|
+
}
|
31
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright 2023-present DreamNum Inc.
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
import './f-enum';
|
17
|
+
import './f-workbook';
|
18
|
+
import './f-worksheet';
|
@@ -0,0 +1,21 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright 2023-present DreamNum Inc.
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
export { SheetBindingModel as BindingModel } from './model/binding-model';
|
17
|
+
export { SourceModelBase } from './model/source-model';
|
18
|
+
export { UniverSheetsBindingSourcePlugin } from './plugin';
|
19
|
+
export { BindModeEnum, DataBindingNodeTypeEnum } from './types';
|
20
|
+
export { SheetsSourceBindService } from './services/source-binding-service';
|
21
|
+
export type { ICellBindingNode, ICellBindingNodeParam } from './types';
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { ICellBindingNode } from '../types';
|
2
|
+
export declare class SheetBindingModel {
|
3
|
+
private _matrix;
|
4
|
+
private _nodeMap;
|
5
|
+
private _sourceIdMap;
|
6
|
+
constructor(json?: any);
|
7
|
+
_init(json: any): void;
|
8
|
+
getBindingNodesBySourceId(sourceId: string): ICellBindingNode[] | undefined;
|
9
|
+
setBindingNode(row: number, column: number, node: ICellBindingNode): void;
|
10
|
+
getBindingNode(row: number, column: number): ICellBindingNode;
|
11
|
+
removeBindingNode(row: number, column: number): void;
|
12
|
+
getBindingNodeById(nodeId: string): ICellBindingNode | undefined;
|
13
|
+
fromJSON(): void;
|
14
|
+
toJSON(): void;
|
15
|
+
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { ICellBindingNode, IListDataBindingNode, IListSourceData, IListSourceInfo, IObjectSourceInfo, DataBindingNodeTypeEnum } from '../types';
|
2
|
+
export declare abstract class SourceModelBase {
|
3
|
+
protected _data: any;
|
4
|
+
readonly id: string;
|
5
|
+
private _hasData;
|
6
|
+
readonly type: DataBindingNodeTypeEnum;
|
7
|
+
constructor(id: string);
|
8
|
+
getId(): string;
|
9
|
+
getType(): DataBindingNodeTypeEnum;
|
10
|
+
hasData(): boolean;
|
11
|
+
setSourceData(data: any): void;
|
12
|
+
abstract getSourceInfo(): any;
|
13
|
+
abstract getData(node: ICellBindingNode, row: number, col: number): string | number | boolean | null;
|
14
|
+
}
|
15
|
+
export declare class ListSourceModel extends SourceModelBase {
|
16
|
+
readonly type = DataBindingNodeTypeEnum.List;
|
17
|
+
private _isListObject;
|
18
|
+
private _fieldIndexMap;
|
19
|
+
protected _data: IListSourceData;
|
20
|
+
constructor(id: string, isListObject?: boolean);
|
21
|
+
/**
|
22
|
+
* Toggle the list object mode. The default value is true.
|
23
|
+
* In the list object mode, the records is an array of objects. Such as [{name: 'Tom', age: 20}, {name: 'Jerry', age: 18}].
|
24
|
+
* In the list array mode, the records is an array of arrays. Such as [['Tom', 20], ['Jerry', 18]].
|
25
|
+
*/
|
26
|
+
toggleListObject(isListObject: boolean): void;
|
27
|
+
getData(node: IListDataBindingNode, row: number): string | number | boolean | null;
|
28
|
+
setSourceData(data: IListSourceData): void;
|
29
|
+
getSourceInfo(): IListSourceInfo;
|
30
|
+
}
|
31
|
+
export declare class ObjectSourceModel extends SourceModelBase {
|
32
|
+
readonly type = DataBindingNodeTypeEnum.Object;
|
33
|
+
constructor(id: string);
|
34
|
+
getData(node: ICellBindingNode): string | number | boolean | null;
|
35
|
+
getSourceInfo(): IObjectSourceInfo;
|
36
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { IConfigService, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
|
2
|
+
interface IUniverSheetsBindingSourceConfig {
|
3
|
+
}
|
4
|
+
export declare class UniverSheetsBindingSourcePlugin extends Plugin {
|
5
|
+
private readonly _config;
|
6
|
+
readonly _injector: Injector;
|
7
|
+
private readonly _configService;
|
8
|
+
static type: UniverInstanceType;
|
9
|
+
static pluginName: string;
|
10
|
+
constructor(_config: Partial<IUniverSheetsBindingSourceConfig> | undefined, _injector: Injector, _configService: IConfigService);
|
11
|
+
onStarting(): void;
|
12
|
+
onReady(): void;
|
13
|
+
}
|
14
|
+
export {};
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import { ICellBindingNodeParam, BindModeEnum, DataBindingNodeTypeEnum } from '../types';
|
2
|
+
import { Disposable } from '@univerjs/core';
|
3
|
+
import { SheetInterceptorService } from '@univerjs/sheets';
|
4
|
+
import { SheetsBindingManager } from '../controllers/binding-manager';
|
5
|
+
import { SheetsSourceManager } from '../controllers/source-manager';
|
6
|
+
export declare class SheetsSourceBindService extends Disposable {
|
7
|
+
private _sheetInterceptorService;
|
8
|
+
private _sheetsBindingManager;
|
9
|
+
private _sheetsSourceManager;
|
10
|
+
private _bindingModel;
|
11
|
+
private _bindModelRTreeCollection;
|
12
|
+
constructor(_sheetInterceptorService: SheetInterceptorService, _sheetsBindingManager: SheetsBindingManager, _sheetsSourceManager: SheetsSourceManager);
|
13
|
+
/**
|
14
|
+
* Set the binding model to path mode, in this mode, the binding path will show in the cell.
|
15
|
+
*/
|
16
|
+
usePathMode(): void;
|
17
|
+
/**
|
18
|
+
* Set the binding model to value mode, in this mode, the value of source will show in the cell.
|
19
|
+
*/
|
20
|
+
useValueMode(): void;
|
21
|
+
/**
|
22
|
+
* Get the current binding model.
|
23
|
+
* @returns the current binding model
|
24
|
+
*/
|
25
|
+
getBindingModel(): BindModeEnum;
|
26
|
+
createBindModel(unitId: string, subUnitId: string): import('..').BindingModel;
|
27
|
+
setBindingNode(unitId: string, subUnitId: string, node: ICellBindingNodeParam): void;
|
28
|
+
removeBindingNode(unitId: string, subUnitId: string, row: number, column: number): void;
|
29
|
+
getBindingNode(unitId: string, subUnitId: string, row: number, column: number): import('..').ICellBindingNode | undefined;
|
30
|
+
getSource(unitId: string, id: string): import('..').SourceModelBase | undefined;
|
31
|
+
createSource(unitId: string, type: DataBindingNodeTypeEnum, isListObject?: boolean, id?: string): import('..').SourceModelBase;
|
32
|
+
private _ensureRTreeCollection;
|
33
|
+
private _getRTeeCollection;
|
34
|
+
private _registerSourceChange;
|
35
|
+
private _getPathModeCellValue;
|
36
|
+
private _getValueModeCellValue;
|
37
|
+
private _registerInterceptor;
|
38
|
+
}
|
@@ -0,0 +1,146 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright 2023-present DreamNum Inc.
|
3
|
+
*
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
* you may not use this file except in compliance with the License.
|
6
|
+
* You may obtain a copy of the License at
|
7
|
+
*
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
*
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
* See the License for the specific language governing permissions and
|
14
|
+
* limitations under the License.
|
15
|
+
*/
|
16
|
+
/**
|
17
|
+
* Represents the type of data binding node.Which config the array or object like data source or path.
|
18
|
+
*/
|
19
|
+
export declare enum DataBindingNodeTypeEnum {
|
20
|
+
/**
|
21
|
+
* The array like data source.
|
22
|
+
*/
|
23
|
+
List = "list",
|
24
|
+
/**
|
25
|
+
* The object like data source.
|
26
|
+
*/
|
27
|
+
Object = "object"
|
28
|
+
}
|
29
|
+
export declare enum ListDataBindingNodeDirectionEnum {
|
30
|
+
Horizontal = "horizontal",
|
31
|
+
Vertical = "vertical"
|
32
|
+
}
|
33
|
+
/**
|
34
|
+
* Represents the type of data binding node.Which config show Binding path or value.
|
35
|
+
*/
|
36
|
+
export declare enum BindModeEnum {
|
37
|
+
/**
|
38
|
+
* The path mode, show the binding path.
|
39
|
+
*/
|
40
|
+
Path = "path",
|
41
|
+
/**
|
42
|
+
* The value mode, show the binding value.
|
43
|
+
*/
|
44
|
+
Value = "value"
|
45
|
+
}
|
46
|
+
export type sourceDataType = string | number | boolean | object | null;
|
47
|
+
export interface IDataSource {
|
48
|
+
id: string;
|
49
|
+
getData(row: number, column: number): sourceDataType;
|
50
|
+
}
|
51
|
+
export interface IListDataSource extends IDataSource {
|
52
|
+
getLength(): number;
|
53
|
+
getColumns(): string[];
|
54
|
+
}
|
55
|
+
export interface IDataBindingModelMatrix {
|
56
|
+
[row: number]: {
|
57
|
+
[column: number]: ICellBindingNode;
|
58
|
+
};
|
59
|
+
}
|
60
|
+
export interface IDataBindingModel {
|
61
|
+
themeName?: string;
|
62
|
+
matrix: IDataBindingModelMatrix;
|
63
|
+
setBindingNode(row: number, column: number, node: ICellBindingNode): void;
|
64
|
+
}
|
65
|
+
/**
|
66
|
+
* The binding node of cell, which config the source id, path, row, column.
|
67
|
+
*/
|
68
|
+
export interface ICellBindingNodeParam {
|
69
|
+
/**
|
70
|
+
* The binding node type, the node type should be same as provide source type.
|
71
|
+
*/
|
72
|
+
type: DataBindingNodeTypeEnum;
|
73
|
+
/**
|
74
|
+
* The path of the binding node, the path should be same as provide source path.
|
75
|
+
* @example
|
76
|
+
* for object type : the source is :{user: {name :'Tom'}}, we can set path 'user.name' to represent the Tom.
|
77
|
+
* for list type : the source is :{fields:['name', 'age'], records:[['Tom', 18],['Jerry', 20]]}, we can set path 'name' to represent the all names in data.
|
78
|
+
*/
|
79
|
+
path: string;
|
80
|
+
/**
|
81
|
+
* The source id of the binding node, the source id should be same as provide source id.
|
82
|
+
*/
|
83
|
+
sourceId: string;
|
84
|
+
/**
|
85
|
+
* The target row of the binding node.
|
86
|
+
*/
|
87
|
+
row: number;
|
88
|
+
/**
|
89
|
+
* The target column of the binding node.
|
90
|
+
*/
|
91
|
+
column: number;
|
92
|
+
nodeId?: string;
|
93
|
+
}
|
94
|
+
export interface ICellBindingNode extends ICellBindingNodeParam {
|
95
|
+
/**
|
96
|
+
* The node id of ICellBindingNode, if not provide, will generate a random id.
|
97
|
+
*/
|
98
|
+
nodeId: string;
|
99
|
+
}
|
100
|
+
export interface IListDataBindingNode extends ICellBindingNode {
|
101
|
+
type: DataBindingNodeTypeEnum.List;
|
102
|
+
limit?: number;
|
103
|
+
direction?: ListDataBindingNodeDirectionEnum;
|
104
|
+
range?: {
|
105
|
+
startRow: number;
|
106
|
+
startColumn: number;
|
107
|
+
endRow: number;
|
108
|
+
endColumn: number;
|
109
|
+
};
|
110
|
+
displayName?: string;
|
111
|
+
}
|
112
|
+
export interface IDataBindingService {
|
113
|
+
/**
|
114
|
+
* A flag to control show path or show value
|
115
|
+
*/
|
116
|
+
isBindingMode: boolean;
|
117
|
+
/**
|
118
|
+
* Change the binding mode
|
119
|
+
* @param {BindModeEnum} mode Update the binding mode
|
120
|
+
*/
|
121
|
+
setBindingMode(mode: BindModeEnum): void;
|
122
|
+
}
|
123
|
+
export interface IListSourceInfo {
|
124
|
+
sourceId: string;
|
125
|
+
sourceType: DataBindingNodeTypeEnum.List;
|
126
|
+
fields: string[];
|
127
|
+
recordCount: number;
|
128
|
+
}
|
129
|
+
export interface IObjectSourceInfo {
|
130
|
+
sourceId: string;
|
131
|
+
sourceType: DataBindingNodeTypeEnum.Object;
|
132
|
+
}
|
133
|
+
export type ISourceEvent = (IListSourceInfo | IObjectSourceInfo) & {
|
134
|
+
unitId: string;
|
135
|
+
changeType: BindingSourceChangeTypeEnum;
|
136
|
+
oldRecordCount?: number;
|
137
|
+
};
|
138
|
+
export interface IListSourceData {
|
139
|
+
fields: string[];
|
140
|
+
records: any[][] | Record<string | number, any>[];
|
141
|
+
}
|
142
|
+
export declare enum BindingSourceChangeTypeEnum {
|
143
|
+
Add = "add",
|
144
|
+
Remove = "remove",
|
145
|
+
Update = "update"
|
146
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
(function(n,e){typeof exports=="object"&&typeof module<"u"?e(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"],e):(n=typeof globalThis<"u"?globalThis:n||self,e(n.UniverCore,n.UniverSheetsSourceBinding,n.UniverSheetsFacade))})(this,function(n,e,s){"use strict";class u extends n.FEnum{get DataBindingNodeTypeEnum(){return e.DataBindingNodeTypeEnum}get BindModeEnum(){return e.BindModeEnum}}n.FEnum.extend(u);class S extends s.FWorkbook{createSource(t,i){return this._injector.get(e.SheetsSourceBindService).createSource(this.getId(),t,i)}getSource(t){return this._injector.get(e.SheetsSourceBindService).getSource(this.getId(),t)}usePathMode(){this._injector.get(e.SheetsSourceBindService).usePathMode()}useValueMode(){this._injector.get(e.SheetsSourceBindService).useValueMode()}}s.FWorkbook.extend(S);class h extends s.FWorksheet{setBindingNode(t){const r=this._injector.get(e.SheetsSourceBindService),o=this._workbook.getUnitId();r.setBindingNode(o,this.getSheetId(),t)}removeBindingNode(t,i){const o=this._injector.get(e.SheetsSourceBindService),c=this._workbook.getUnitId();o.removeBindingNode(c,this.getSheetId(),t,i)}getBindingNode(t,i){const o=this._injector.get(e.SheetsSourceBindService),c=this._workbook.getUnitId();return o.getBindingNode(c,this.getSheetId(),t,i)}}s.FWorksheet.extend(h)});
|
package/lib/umd/index.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
(function(u,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("rxjs"),require("@univerjs/sheets")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","@univerjs/sheets"],a):(u=typeof globalThis<"u"?globalThis:u||self,a(u.UniverSheetsSourceBinding={},u.UniverCore,u.rxjs,u.UniverSheets))})(this,function(u,a,v,y){"use strict";var W=Object.defineProperty;var G=(u,a,v)=>a in u?W(u,a,{enumerable:!0,configurable:!0,writable:!0,value:v}):u[a]=v;var l=(u,a,v)=>G(u,typeof a!="symbol"?a+"":a,v);var b;class T{constructor(r){l(this,"_matrix",{});l(this,"_nodeMap",new Map);l(this,"_sourceIdMap",new Map);r&&this._init(r)}_init(r){this.fromJSON()}getBindingNodesBySourceId(r){const t=this._sourceIdMap.get(r);if(t)return t.map(e=>this._nodeMap.get(e))}setBindingNode(r,t,e){this._matrix[r]||(this._matrix[r]={}),this._matrix[r][t]||(this._matrix[r][t]=e),this._nodeMap.set(e.nodeId,e);const n=this._sourceIdMap.get(e.sourceId);n?n.push(e.nodeId):this._sourceIdMap.set(e.sourceId,[e.nodeId])}getBindingNode(r,t){var e;return(e=this._matrix[r])==null?void 0:e[t]}removeBindingNode(r,t){var n;const e=(n=this._matrix[r])==null?void 0:n[t];if(e){this._matrix[r][t]=void 0,this._nodeMap.delete(e.nodeId);const o=this._sourceIdMap.get(e.sourceId);if(o){const s=o.indexOf(e.nodeId);s>=0&&o.splice(s,1),o.length===0&&this._sourceIdMap.delete(e.sourceId)}}}getBindingNodeById(r){return this._nodeMap.get(r)}fromJSON(){}toJSON(){}}var I=(d=>(d.List="list",d.Object="object",d))(I||{}),C=(d=>(d.Path="path",d.Value="value",d))(C||{}),M=(d=>(d.Add="add",d.Remove="remove",d.Update="update",d))(M||{});class R{constructor(r){l(this,"_data");l(this,"id");l(this,"_hasData",!1);l(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 P extends R{constructor(t,e){super(t);l(this,"type",I.List);l(this,"_isListObject");l(this,"_fieldIndexMap",new Map);l(this,"_data",{fields:[],records:[]});this._isListObject=e!=null?e:!0}toggleListObject(t){this._isListObject=t}getData(t,e){const{path:n,row:o}=t,s=this._fieldIndexMap.get(n),i=e-o;return i===0?this._data.fields[s]:this._isListObject?this._data.records[i-1][n]:this._data.records[i-1][s]}setSourceData(t){super.setSourceData(t);const{fields:e}=t;this._fieldIndexMap.clear(),e.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 O extends R{constructor(t){super(t);l(this,"type",I.Object)}getData(t){const n=t.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:I.Object}}}class N extends a.Disposable{constructor(){super();l(this,"modelMap",new Map);l(this,"_cellBindInfoUpdate$",new v.Subject);l(this,"cellBindInfoUpdate$",this._cellBindInfoUpdate$.asObservable())}getBindingModelBySourceId(t){const e=[];return this.modelMap.forEach((n,o)=>{n.forEach((s,i)=>{const c=s.getBindingNodesBySourceId(t);if(c)for(const h of c)e.push({unitId:o,subunitId:i,sourceId:t,nodeId:h.nodeId,row:h.row,column:h.column})})}),e}addModel(t,e,n){var o;this.modelMap.has(t)||this.modelMap.set(t,new Map),(o=this.modelMap.get(t))==null||o.set(e,n)}getModel(t,e){var n;return(n=this.modelMap.get(t))==null?void 0:n.get(e)}setBindingNode(t,e,n){let o=this.getModel(t,e);o||(o=new T,this.addModel(t,e,o)),n.nodeId||(n.nodeId=a.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:t,subunitId:e,sourceId:n.sourceId,nodeId:n.nodeId,row:s,column:i,changeType:c?M.Update:M.Add,oldSourceId:c==null?void 0:c.sourceId})}removeBindingNode(t,e,n,o){const s=this.getModel(t,e);if(s){const i=s.getBindingNode(n,o);i&&(s.removeBindingNode(n,o),this._cellBindInfoUpdate$.next({unitId:t,subunitId:e,sourceId:i.sourceId,nodeId:i.nodeId,row:n,column:o,changeType:M.Remove}))}}getBindingNode(t,e,n,o){const s=this.getModel(t,e);if(s)return s.getBindingNode(n,o)}createModel(t,e,n){const o=new T(n);return this.addModel(t,e,o),o}dispose(){this.modelMap.clear()}}class U extends a.Disposable{constructor(){super();l(this,"sourceMap",new Map);l(this,"_sourceDataUpdate$",new v.Subject);l(this,"sourceDataUpdate$",this._sourceDataUpdate$.asObservable())}_ensureUnitMap(t){let e=this.sourceMap.get(t);return e||(e=new Map,this.sourceMap.set(t,e)),e}_getUnitMap(t){return this.sourceMap.get(t)}getSource(t,e){const n=this._getUnitMap(t);return n==null?void 0:n.get(e)}createSource(t,e,n,o){const s=o===void 0?a.generateRandomId():o;let i;switch(e){case I.List:i=new P(s,n);break;case I.Object:i=new O(s);break;default:throw new Error(`Invalid source type: ${e}`)}return this._ensureUnitMap(t).set(s,i),i}updateSourceData(t,e,n){const o=this._getUnitMap(t),s=e instanceof R?e.getId():e,i=o==null?void 0:o.get(s);if(i)i.setSourceData(n),this._sourceDataUpdate$.next({...i.getSourceInfo(),unitId:t,changeType:M.Add});else throw new Error(`Source not found: ${s}`)}removeSource(t,e){const n=this._getUnitMap(t),o=n==null?void 0:n.get(e);o&&(n==null||n.delete(e),this._sourceDataUpdate$.next({...o.getSourceInfo(),unitId:t,changeType:M.Remove}))}}var $=Object.defineProperty,x=Object.getOwnPropertyDescriptor,E=(d,r,t,e)=>{for(var n=e>1?void 0:e?x(r,t):r,o=d.length-1,s;o>=0;o--)(s=d[o])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&$(r,t,n),n},D=(d,r)=>(t,e)=>r(t,e,d);u.SheetsSourceBindService=class extends a.Disposable{constructor(t,e,n){super();l(this,"_bindingModel",C.Value);l(this,"_bindModelRTreeCollection",new Map);this._sheetInterceptorService=t,this._sheetsBindingManager=e,this._sheetsSourceManager=n,this._registerInterceptor(),this._registerSourceChange()}usePathMode(){this._bindingModel=C.Path}useValueMode(){this._bindingModel=C.Value}getBindingModel(){return this._bindingModel}createBindModel(t,e){return this._sheetsBindingManager.createModel(t,e)}setBindingNode(t,e,n){this._sheetsBindingManager.setBindingNode(t,e,n)}removeBindingNode(t,e,n,o){this._sheetsBindingManager.removeBindingNode(t,e,n,o)}getBindingNode(t,e,n,o){return this._sheetsBindingManager.getBindingNode(t,e,n,o)}getSource(t,e){return this._sheetsSourceManager.getSource(t,e)}createSource(t,e,n,o){return this._sheetsSourceManager.createSource(t,e,n,o)}_ensureRTreeCollection(t){return this._bindModelRTreeCollection.has(t)||this._bindModelRTreeCollection.set(t,new a.RTree),this._bindModelRTreeCollection.get(t)}_getRTeeCollection(t){return this._bindModelRTreeCollection.get(t)}_registerSourceChange(){this.disposeWithMe(this._sheetsSourceManager.sourceDataUpdate$.subscribe(t=>{const{sourceId:e,sourceType:n,unitId:o,changeType:s}=t;if(n===I.List){if(s===M.Remove){const c=this._sheetsBindingManager.getBindingModelBySourceId(e),h=t.recordCount;for(const{unitId:g,subunitId:p,nodeId:f,row:S,column:_}of c){const B=this._getRTeeCollection(o);if(B){const m={startRow:S,startColumn:_,endRow:S+h,endColumn:_};B.remove({unitId:g,sheetId:p,id:f,range:m})}}return}if(s===M.Update){const c=t.oldRecordCount,h=this._sheetsBindingManager.getBindingModelBySourceId(e);for(const{unitId:g,subunitId:p,nodeId:f,row:S,column:_}of h){const B=this._getRTeeCollection(o);if(B){const m={startRow:S,startColumn:_,endRow:S+c,endColumn:_},w={startRow:S,startColumn:_,endRow:S+t.recordCount,endColumn:_};B.remove({unitId:g,sheetId:p,id:f,range:m}),B.insert({unitId:g,sheetId:p,id:f,range:w})}}return}const i=this._sheetsSourceManager.getSource(o,e);if(i&&i.hasData()){const h=i.getSourceInfo().recordCount,g=this._sheetsBindingManager.getBindingModelBySourceId(e);for(const{unitId:p,subunitId:f,nodeId:S,row:_,column:B}of g){const m=this._ensureRTreeCollection(p),w={startRow:_,startColumn:B,endRow:_+h,endColumn:B};m.insert({unitId:p,sheetId:f,id:S,range:w})}}}})),this.disposeWithMe(this._sheetsBindingManager.cellBindInfoUpdate$.subscribe(t=>{const{unitId:e,subunitId:n,sourceId:o,nodeId:s,row:i,column:c,changeType:h}=t,g=this._ensureRTreeCollection(e),p=this._sheetsSourceManager.getSource(e,o);if(p&&p.hasData()){const f=p.getSourceInfo();if(f.sourceType===I.List){const S=f.recordCount,_={startRow:i,startColumn:c,endRow:i+S,endColumn:c};if(h===M.Add)g.insert({unitId:e,sheetId:n,id:s,range:_});else if(h===M.Remove)g.remove({unitId:e,sheetId:n,id:s,range:_});else if(h===M.Update){const B=t.oldSourceId,m=this._sheetsSourceManager.getSource(e,B);if(m&&m.hasData()){const q=m.getSourceInfo().recordCount,J={startRow:i,startColumn:c,endRow:i+q,endColumn:c};g.remove({unitId:e,sheetId:n,id:s,range:J})}g.insert({unitId:e,sheetId:n,id:s,range:_})}}}}))}_getPathModeCellValue(t,e,n,o){const s=this._sheetsBindingManager.getModel(t,e),i=s==null?void 0:s.getBindingNode(n,o);if(i){const c=i.type;if(c===I.List)return{v:`#{${i.path}}`,s:{cl:{rgb:"blue"}}};if(c===I.Object)return{v:`[${i.path}]`,s:{cl:{rgb:"blue"}}}}}_getValueModeCellValue(t,e,n,o){const s=this._sheetsBindingManager.getModel(t,e);if(s){const c=s.getBindingNode(n,o);if(c){const{sourceId:h}=c,g=this._sheetsSourceManager.getSource(t,h);if(g&&g.hasData())return{v:(g==null?void 0:g.getData(c,n,o))||""}}}const i=this._getRTeeCollection(t);if(s&&i){const c={startRow:n,startColumn:o,endRow:n,endColumn:o},h=Array.from(i.bulkSearch([{unitId:t,sheetId:e,range:c}]));if(h.length>0){const g=s.getBindingNodeById(h[0]);if(g){const{sourceId:p}=g,f=this._sheetsSourceManager.getSource(t,p);if(f&&f.hasData())return{v:(f==null?void 0:f.getData(g,n,o))||""}}}}}_registerInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(y.INTERCEPTOR_POINT.CELL_CONTENT,{effect:a.InterceptorEffectEnum.Value,handler:(t,e,n)=>{const{row:o,col:s,unitId:i,subUnitId:c}=e;let h=null;return this._bindingModel===C.Path?h=this._getPathModeCellValue(i,c,o,s):h=this._getValueModeCellValue(i,c,o,s),n(h!==null?{...t,...h}:t)}}))}},u.SheetsSourceBindService=E([D(0,a.Inject(y.SheetInterceptorService)),D(1,a.Inject(N)),D(2,a.Inject(U))],u.SheetsSourceBindService);var V=Object.defineProperty,L=Object.getOwnPropertyDescriptor,A=(d,r,t,e)=>{for(var n=e>1?void 0:e?L(r,t):r,o=d.length-1,s;o>=0;o--)(s=d[o])&&(n=(e?s(r,t,n):s(n))||n);return e&&n&&V(r,t,n),n},j=(d,r)=>(t,e)=>r(t,e,d);u.UniverSheetsBindingSourcePlugin=(b=class extends a.Plugin{constructor(r={},t,e){super(),this._config=r,this._injector=t,this._configService=e}onStarting(){[[N],[U],[u.SheetsSourceBindService]].forEach(r=>this._injector.add(r))}onReady(){a.touchDependencies(this._injector,[[N],[U],[u.SheetsSourceBindService]])}},l(b,"type",a.UniverInstanceType.UNIVER_SHEET),l(b,"pluginName","SHEET_BINDING_SOURCE_PLUGIN"),b),u.UniverSheetsBindingSourcePlugin=A([j(1,a.Inject(a.Injector)),j(2,a.IConfigService)],u.UniverSheetsBindingSourcePlugin),u.BindModeEnum=C,u.BindingModel=T,u.DataBindingNodeTypeEnum=I,u.SourceModelBase=R,Object.defineProperty(u,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
{
|
2
|
+
"name": "@univerjs/sheets-source-binding",
|
3
|
+
"version": "0.5.4-nightly.202501150735",
|
4
|
+
"private": false,
|
5
|
+
"description": "A library for connect and bind data from other sources to Univer Sheets",
|
6
|
+
"author": "DreamNum <developer@univer.ai>",
|
7
|
+
"license": "Apache-2.0",
|
8
|
+
"funding": {
|
9
|
+
"type": "opencollective",
|
10
|
+
"url": "https://opencollective.com/univer"
|
11
|
+
},
|
12
|
+
"homepage": "https://univer.ai",
|
13
|
+
"repository": {
|
14
|
+
"type": "git",
|
15
|
+
"url": "https://github.com/dream-num/univer"
|
16
|
+
},
|
17
|
+
"bugs": {
|
18
|
+
"url": "https://github.com/dream-num/univer/issues"
|
19
|
+
},
|
20
|
+
"keywords": [],
|
21
|
+
"exports": {
|
22
|
+
".": {
|
23
|
+
"import": "./lib/es/index.js",
|
24
|
+
"require": "./lib/cjs/index.js",
|
25
|
+
"types": "./lib/types/index.d.ts"
|
26
|
+
},
|
27
|
+
"./*": {
|
28
|
+
"import": "./lib/es/*",
|
29
|
+
"require": "./lib/cjs/*",
|
30
|
+
"types": "./lib/types/index.d.ts"
|
31
|
+
},
|
32
|
+
"./facade": {
|
33
|
+
"import": "./lib/es/facade.js",
|
34
|
+
"require": "./lib/cjs/facade.js",
|
35
|
+
"types": "./lib/types/facade/index.d.ts"
|
36
|
+
},
|
37
|
+
"./lib/*": "./lib/*"
|
38
|
+
},
|
39
|
+
"main": "./lib/es/index.js",
|
40
|
+
"types": "./lib/types/index.d.ts",
|
41
|
+
"publishConfig": {
|
42
|
+
"access": "public"
|
43
|
+
},
|
44
|
+
"directories": {
|
45
|
+
"lib": "lib"
|
46
|
+
},
|
47
|
+
"files": [
|
48
|
+
"lib"
|
49
|
+
],
|
50
|
+
"peerDependencies": {
|
51
|
+
"rxjs": ">=7.0.0"
|
52
|
+
},
|
53
|
+
"dependencies": {
|
54
|
+
"@univerjs/core": "0.5.4-nightly.202501150735",
|
55
|
+
"@univerjs/sheets": "0.5.4-nightly.202501150735"
|
56
|
+
},
|
57
|
+
"devDependencies": {
|
58
|
+
"rxjs": "^7.8.1",
|
59
|
+
"typescript": "^5.7.2",
|
60
|
+
"vite": "^6.0.7",
|
61
|
+
"vitest": "^2.1.8",
|
62
|
+
"@univerjs-infra/shared": "0.5.4"
|
63
|
+
},
|
64
|
+
"scripts": {
|
65
|
+
"test": "vitest run",
|
66
|
+
"test:watch": "vitest",
|
67
|
+
"coverage": "vitest run --coverage",
|
68
|
+
"lint:types": "tsc --noEmit",
|
69
|
+
"build": "univer-cli build"
|
70
|
+
},
|
71
|
+
"module": "./lib/es/index.js"
|
72
|
+
}
|