@univerjs/sheets-source-binding 0.5.5-nightly.202501210734 → 0.5.5-nightly.202501210849
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/es/facade.js +49 -41
- package/lib/es/index.js +423 -410
- package/package.json +3 -3
package/lib/es/facade.js
CHANGED
@@ -1,54 +1,62 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
import {
|
4
|
-
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
3
|
+
import { FEnum } from "@univerjs/core";
|
4
|
+
import { DataBindingNodeTypeEnum, BindModeEnum, SheetsSourceBindService, SheetsSourceManager } from "@univerjs/sheets-source-binding";
|
5
|
+
import { FWorkbook, FWorksheet } from "@univerjs/sheets/facade";
|
6
|
+
const _FSourceBindingEnum = class _FSourceBindingEnum extends FEnum {
|
5
7
|
get DataBindingNodeTypeEnum() {
|
6
|
-
return
|
8
|
+
return DataBindingNodeTypeEnum;
|
7
9
|
}
|
8
10
|
get BindModeEnum() {
|
9
|
-
return
|
11
|
+
return BindModeEnum;
|
10
12
|
}
|
11
|
-
}
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
};
|
14
|
+
__name(_FSourceBindingEnum, "FSourceBindingEnum");
|
15
|
+
let FSourceBindingEnum = _FSourceBindingEnum;
|
16
|
+
FEnum.extend(FSourceBindingEnum);
|
17
|
+
const _FWorkbookSourceBinding = class _FWorkbookSourceBinding extends FWorkbook {
|
18
|
+
createSource(type, isListObject, id) {
|
19
|
+
return this._injector.get(SheetsSourceBindService).createSource(this.getId(), type, isListObject, id);
|
16
20
|
}
|
17
|
-
getSource(
|
18
|
-
return this._injector.get(
|
21
|
+
getSource(sourceId) {
|
22
|
+
return this._injector.get(SheetsSourceBindService).getSource(this.getId(), sourceId);
|
19
23
|
}
|
20
|
-
setSourceData(
|
21
|
-
this._injector.get(
|
24
|
+
setSourceData(sourceId, data) {
|
25
|
+
this._injector.get(SheetsSourceManager).updateSourceData(this.getId(), sourceId, data);
|
22
26
|
}
|
23
27
|
usePathMode() {
|
24
|
-
this._injector.get(
|
28
|
+
this._injector.get(SheetsSourceBindService).usePathMode();
|
25
29
|
}
|
26
30
|
useValueMode() {
|
27
|
-
this._injector.get(
|
31
|
+
this._injector.get(SheetsSourceBindService).useValueMode();
|
28
32
|
}
|
29
|
-
loadSourceBindingPathInfo(
|
30
|
-
this._injector.get(
|
33
|
+
loadSourceBindingPathInfo(obj) {
|
34
|
+
this._injector.get(SheetsSourceBindService).loadSourceBindingPathInfo(this.getId(), obj);
|
31
35
|
}
|
32
36
|
saveSourceBindingPathInfo() {
|
33
|
-
return this._injector.get(
|
34
|
-
}
|
35
|
-
getBindingModelBySourceId(
|
36
|
-
return this._injector.get(
|
37
|
-
}
|
38
|
-
}
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
37
|
+
return this._injector.get(SheetsSourceBindService).getSourceBindingPathInfo(this.getId());
|
38
|
+
}
|
39
|
+
getBindingModelBySourceId(sourceId) {
|
40
|
+
return this._injector.get(SheetsSourceBindService).getBindingModelBySourceId(sourceId);
|
41
|
+
}
|
42
|
+
};
|
43
|
+
__name(_FWorkbookSourceBinding, "FWorkbookSourceBinding");
|
44
|
+
let FWorkbookSourceBinding = _FWorkbookSourceBinding;
|
45
|
+
FWorkbook.extend(FWorkbookSourceBinding);
|
46
|
+
const _FWorksheetSourceBinding = class _FWorksheetSourceBinding extends FWorksheet {
|
47
|
+
setBindingNode(bindingNode) {
|
48
|
+
const sheetsSourceBindService = this._injector.get(SheetsSourceBindService), unitId = this._workbook.getUnitId();
|
49
|
+
sheetsSourceBindService.setBindingNode(unitId, this.getSheetId(), bindingNode);
|
50
|
+
}
|
51
|
+
removeBindingNode(row, column) {
|
52
|
+
const sheetsSourceBindService = this._injector.get(SheetsSourceBindService), unitId = this._workbook.getUnitId();
|
53
|
+
sheetsSourceBindService.removeBindingNode(unitId, this.getSheetId(), row, column);
|
54
|
+
}
|
55
|
+
getBindingNode(row, column) {
|
56
|
+
const sheetsSourceBindService = this._injector.get(SheetsSourceBindService), unitId = this._workbook.getUnitId();
|
57
|
+
return sheetsSourceBindService.getBindingNode(unitId, this.getSheetId(), row, column);
|
58
|
+
}
|
59
|
+
};
|
60
|
+
__name(_FWorksheetSourceBinding, "FWorksheetSourceBinding");
|
61
|
+
let FWorksheetSourceBinding = _FWorksheetSourceBinding;
|
62
|
+
FWorksheet.extend(FWorksheetSourceBinding);
|
package/lib/es/index.js
CHANGED
@@ -1,76 +1,81 @@
|
|
1
|
-
var
|
2
|
-
var
|
3
|
-
var
|
4
|
-
|
5
|
-
import {
|
6
|
-
import {
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
|
5
|
+
import { CellValueType, Inject, Disposable, Range, generateRandomId, IUniverInstanceService, RTree, InterceptorEffectEnum, Plugin, UniverInstanceType, touchDependencies, Injector, IConfigService } from "@univerjs/core";
|
6
|
+
import { SheetInterceptorService, SheetsSelectionsService, getSheetCommandTarget, ClearSelectionContentCommand, ClearSelectionAllCommand, INTERCEPTOR_POINT } from "@univerjs/sheets";
|
7
|
+
import { Subject } from "rxjs";
|
8
|
+
const _SheetBindingModel = class _SheetBindingModel {
|
9
|
+
constructor(json) {
|
10
|
+
__publicField(this, "_matrix", {});
|
11
|
+
__publicField(this, "_nodeMap", /* @__PURE__ */ new Map());
|
12
|
+
__publicField(this, "_sourceIdMap", /* @__PURE__ */ new Map());
|
13
|
+
json && this._init(json);
|
14
|
+
}
|
15
|
+
_init(json) {
|
16
|
+
this.fromJSON(json);
|
17
|
+
}
|
18
|
+
getBindingNodesBySourceId(sourceId) {
|
19
|
+
const nodeIds = this._sourceIdMap.get(sourceId);
|
20
|
+
if (nodeIds)
|
21
|
+
return nodeIds.map((nodeId) => this._nodeMap.get(nodeId));
|
22
|
+
}
|
23
|
+
setBindingNode(row, column, node) {
|
24
|
+
this._matrix[row] || (this._matrix[row] = {}), this._matrix[row][column] || (this._matrix[row][column] = node), this._nodeMap.set(node.nodeId, node);
|
25
|
+
const nodeIds = this._sourceIdMap.get(node.sourceId);
|
26
|
+
nodeIds ? nodeIds.push(node.nodeId) : this._sourceIdMap.set(node.sourceId, [node.nodeId]);
|
27
|
+
}
|
28
|
+
getBindingNode(row, column) {
|
29
|
+
var _a4;
|
30
|
+
return (_a4 = this._matrix[row]) == null ? void 0 : _a4[column];
|
31
|
+
}
|
32
|
+
removeBindingNode(row, column) {
|
33
|
+
var _a4;
|
34
|
+
const node = (_a4 = this._matrix[row]) == null ? void 0 : _a4[column];
|
35
|
+
if (node) {
|
36
|
+
this._matrix[row][column] = void 0, this._nodeMap.delete(node.nodeId);
|
37
|
+
const nodeIds = this._sourceIdMap.get(node.sourceId);
|
38
|
+
if (nodeIds) {
|
39
|
+
const index = nodeIds.indexOf(node.nodeId);
|
40
|
+
index >= 0 && nodeIds.splice(index, 1), nodeIds.length === 0 && this._sourceIdMap.delete(node.sourceId);
|
40
41
|
}
|
41
42
|
}
|
42
43
|
}
|
43
|
-
getBindingNodeById(
|
44
|
-
return this._nodeMap.get(
|
44
|
+
getBindingNodeById(nodeId) {
|
45
|
+
return this._nodeMap.get(nodeId);
|
45
46
|
}
|
46
|
-
fromJSON(
|
47
|
-
|
48
|
-
this.setBindingNode(
|
47
|
+
fromJSON(nodes) {
|
48
|
+
nodes.forEach((node) => {
|
49
|
+
this.setBindingNode(node.row, node.column, node);
|
49
50
|
});
|
50
51
|
}
|
51
52
|
toJSON() {
|
52
53
|
return Array.from(this._nodeMap.values());
|
53
54
|
}
|
55
|
+
};
|
56
|
+
__name(_SheetBindingModel, "SheetBindingModel");
|
57
|
+
let SheetBindingModel = _SheetBindingModel;
|
58
|
+
var DataBindingNodeTypeEnum = /* @__PURE__ */ ((DataBindingNodeTypeEnum2) => (DataBindingNodeTypeEnum2.List = "list", DataBindingNodeTypeEnum2.Object = "object", DataBindingNodeTypeEnum2))(DataBindingNodeTypeEnum || {}), BindModeEnum = /* @__PURE__ */ ((BindModeEnum2) => (BindModeEnum2.Path = "path", BindModeEnum2.Value = "value", BindModeEnum2))(BindModeEnum || {}), BindingSourceChangeTypeEnum = /* @__PURE__ */ ((BindingSourceChangeTypeEnum2) => (BindingSourceChangeTypeEnum2.Add = "add", BindingSourceChangeTypeEnum2.Remove = "remove", BindingSourceChangeTypeEnum2.Update = "update", BindingSourceChangeTypeEnum2))(BindingSourceChangeTypeEnum || {});
|
59
|
+
function isValidDate(date) {
|
60
|
+
return date instanceof Date && !isNaN(date.getTime());
|
54
61
|
}
|
55
|
-
|
56
|
-
function
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
const
|
61
|
-
|
62
|
-
|
63
|
-
const t = new Date(Date.UTC(1900, 0, 1, 0, 0, 0)), n = new Date(Date.UTC(1900, 1, 28, 0, 0, 0));
|
64
|
-
let o = (e.getTime() - t.getTime()) / (1e3 * 3600 * 24);
|
65
|
-
return e > n && (o += 1), o + 1;
|
62
|
+
__name(isValidDate, "isValidDate");
|
63
|
+
function transformDate(dateString) {
|
64
|
+
const date = new Date(dateString);
|
65
|
+
if (!isValidDate(date))
|
66
|
+
return dateString;
|
67
|
+
const baseDate = new Date(Date.UTC(1900, 0, 1, 0, 0, 0)), leapDayDate = new Date(Date.UTC(1900, 1, 28, 0, 0, 0));
|
68
|
+
let dayDifference = (date.getTime() - baseDate.getTime()) / (1e3 * 3600 * 24);
|
69
|
+
return date > leapDayDate && (dayDifference += 1), dayDifference + 1;
|
66
70
|
}
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
this
|
71
|
+
__name(transformDate, "transformDate");
|
72
|
+
const _SourceModelBase = class _SourceModelBase {
|
73
|
+
constructor(id) {
|
74
|
+
__publicField(this, "_data");
|
75
|
+
__publicField(this, "id");
|
76
|
+
__publicField(this, "_hasData", !1);
|
77
|
+
__publicField(this, "type");
|
78
|
+
this.id = id;
|
74
79
|
}
|
75
80
|
getId() {
|
76
81
|
return this.id;
|
@@ -81,8 +86,8 @@ class U {
|
|
81
86
|
hasData() {
|
82
87
|
return this._hasData;
|
83
88
|
}
|
84
|
-
setSourceData(
|
85
|
-
this._data =
|
89
|
+
setSourceData(data) {
|
90
|
+
this._data = data, this._hasData = !0;
|
86
91
|
}
|
87
92
|
toJSON() {
|
88
93
|
return {
|
@@ -90,53 +95,55 @@ class U {
|
|
90
95
|
type: this.type
|
91
96
|
};
|
92
97
|
}
|
93
|
-
fromJSON(
|
94
|
-
this.id =
|
98
|
+
fromJSON(info) {
|
99
|
+
this.id = info.id, this.type = info.type;
|
95
100
|
}
|
96
|
-
}
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
this
|
101
|
+
};
|
102
|
+
__name(_SourceModelBase, "SourceModelBase");
|
103
|
+
let SourceModelBase = _SourceModelBase;
|
104
|
+
const _ListSourceModel = class _ListSourceModel extends SourceModelBase {
|
105
|
+
constructor(id, isListObject) {
|
106
|
+
super(id);
|
107
|
+
__publicField(this, "type", DataBindingNodeTypeEnum.List);
|
108
|
+
__publicField(this, "_isListObject");
|
109
|
+
__publicField(this, "_fieldIndexMap", /* @__PURE__ */ new Map());
|
110
|
+
__publicField(this, "_data", { fields: [], records: [] });
|
111
|
+
this._isListObject = isListObject != null ? isListObject : !0;
|
105
112
|
}
|
106
113
|
/**
|
107
114
|
* Toggle the list object mode. The default value is true.
|
108
115
|
* In the list object mode, the records is an array of objects. Such as [{name: 'Tom', age: 20}, {name: 'Jerry', age: 18}].
|
109
116
|
* In the list array mode, the records is an array of arrays. Such as [['Tom', 20], ['Jerry', 18]].
|
110
117
|
*/
|
111
|
-
toggleListObject(
|
112
|
-
this._isListObject =
|
118
|
+
toggleListObject(isListObject) {
|
119
|
+
this._isListObject = isListObject;
|
113
120
|
}
|
114
|
-
getData(
|
115
|
-
const { path
|
116
|
-
if (
|
121
|
+
getData(node, row) {
|
122
|
+
const { path, row: baseRow, containHeader } = node, colIndex = this._fieldIndexMap.get(path), rowIndex = row - baseRow;
|
123
|
+
if (containHeader && rowIndex === 0)
|
117
124
|
return {
|
118
|
-
v: this._data.fields[
|
125
|
+
v: this._data.fields[colIndex]
|
119
126
|
};
|
120
|
-
let
|
121
|
-
const
|
122
|
-
return this._isListObject ?
|
123
|
-
v:
|
127
|
+
let data;
|
128
|
+
const offset = containHeader ? 1 : 0;
|
129
|
+
return this._isListObject ? data = this._data.records[rowIndex - offset][path] : data = this._data.records[rowIndex - offset][colIndex], node.isDate === !0 ? {
|
130
|
+
v: transformDate(data),
|
124
131
|
s: {
|
125
132
|
n: {
|
126
133
|
pattern: "yyyy-m-d am/pm h:mm"
|
127
134
|
}
|
128
135
|
},
|
129
|
-
t:
|
136
|
+
t: CellValueType.NUMBER
|
130
137
|
} : {
|
131
|
-
t: typeof
|
132
|
-
v:
|
138
|
+
t: typeof data == "number" ? CellValueType.NUMBER : CellValueType.STRING,
|
139
|
+
v: data
|
133
140
|
};
|
134
141
|
}
|
135
|
-
setSourceData(
|
136
|
-
super.setSourceData(
|
137
|
-
const { fields
|
138
|
-
this._fieldIndexMap.clear(),
|
139
|
-
this._fieldIndexMap.set(
|
142
|
+
setSourceData(data) {
|
143
|
+
super.setSourceData(data);
|
144
|
+
const { fields } = data;
|
145
|
+
this._fieldIndexMap.clear(), fields.forEach((field, index) => {
|
146
|
+
this._fieldIndexMap.set(field, index);
|
140
147
|
});
|
141
148
|
}
|
142
149
|
getSourceInfo() {
|
@@ -147,261 +154,267 @@ class x extends U {
|
|
147
154
|
recordCount: this._data.records.length
|
148
155
|
};
|
149
156
|
}
|
150
|
-
}
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
157
|
+
};
|
158
|
+
__name(_ListSourceModel, "ListSourceModel");
|
159
|
+
let ListSourceModel = _ListSourceModel;
|
160
|
+
const _ObjectSourceModel = class _ObjectSourceModel extends SourceModelBase {
|
161
|
+
constructor(id) {
|
162
|
+
super(id);
|
163
|
+
__publicField(this, "type", DataBindingNodeTypeEnum.Object);
|
164
|
+
}
|
165
|
+
getData(node) {
|
166
|
+
const paths = node.path.split(".");
|
167
|
+
let data = this._data;
|
168
|
+
for (const p of paths)
|
169
|
+
if (data = data[p], data === void 0)
|
161
170
|
return null;
|
162
|
-
return
|
163
|
-
v:
|
171
|
+
return node.isDate === !0 ? {
|
172
|
+
v: transformDate(data),
|
164
173
|
s: {
|
165
174
|
n: {
|
166
175
|
pattern: "yyyy-m-d am/pm h:mm"
|
167
176
|
}
|
168
177
|
},
|
169
|
-
t:
|
178
|
+
t: CellValueType.NUMBER
|
170
179
|
} : {
|
171
|
-
v:
|
172
|
-
t: typeof
|
180
|
+
v: data,
|
181
|
+
t: typeof data == "number" ? CellValueType.NUMBER : CellValueType.STRING
|
173
182
|
};
|
174
183
|
}
|
175
184
|
getSourceInfo() {
|
176
185
|
return {
|
177
186
|
sourceId: this.id,
|
178
|
-
sourceType:
|
187
|
+
sourceType: DataBindingNodeTypeEnum.Object
|
179
188
|
};
|
180
189
|
}
|
181
|
-
}
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
190
|
+
};
|
191
|
+
__name(_ObjectSourceModel, "ObjectSourceModel");
|
192
|
+
let ObjectSourceModel = _ObjectSourceModel;
|
193
|
+
var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
194
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
195
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
196
|
+
return kind && result && __defProp$2(target, key, result), result;
|
197
|
+
}, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a;
|
198
|
+
let SheetsBindingManager = (_a = class extends Disposable {
|
199
|
+
constructor(_univerInstanceService, _sheetInterceptorService, _sheetsSelectionsService) {
|
189
200
|
super();
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
this._univerInstanceService =
|
201
|
+
__publicField(this, "modelMap", /* @__PURE__ */ new Map());
|
202
|
+
__publicField(this, "_cellBindInfoUpdate$", new Subject());
|
203
|
+
__publicField(this, "cellBindInfoUpdate$", this._cellBindInfoUpdate$.asObservable());
|
204
|
+
this._univerInstanceService = _univerInstanceService, this._sheetInterceptorService = _sheetInterceptorService, this._sheetsSelectionsService = _sheetsSelectionsService, this._initRemoveCommand();
|
194
205
|
}
|
195
206
|
_initRemoveCommand() {
|
196
207
|
this.disposeWithMe(
|
197
208
|
this._sheetInterceptorService.interceptCommand({
|
198
|
-
getMutations: (
|
199
|
-
const
|
200
|
-
if (!
|
209
|
+
getMutations: /* @__PURE__ */ __name((command) => {
|
210
|
+
const redos = [], undos = [], selections = this._sheetsSelectionsService.getCurrentSelections(), target = getSheetCommandTarget(this._univerInstanceService);
|
211
|
+
if (!target || !selections || selections.length === 0)
|
201
212
|
return {
|
202
213
|
redos: [],
|
203
214
|
undos: []
|
204
215
|
};
|
205
|
-
const { unitId
|
206
|
-
return (
|
207
|
-
|
208
|
-
this.getBindingNode(
|
216
|
+
const { unitId, subUnitId } = target;
|
217
|
+
return (command.id === ClearSelectionContentCommand.id || command.id === ClearSelectionAllCommand.id) && selections.forEach(({ range }) => {
|
218
|
+
Range.foreach(range, (row, column) => {
|
219
|
+
this.getBindingNode(unitId, subUnitId, row, column) && this.removeBindingNode(unitId, subUnitId, row, column);
|
209
220
|
});
|
210
|
-
}), { redos
|
211
|
-
}
|
221
|
+
}), { redos, undos };
|
222
|
+
}, "getMutations")
|
212
223
|
})
|
213
224
|
);
|
214
225
|
}
|
215
|
-
getBindingModelBySourceId(
|
216
|
-
const
|
217
|
-
return this.modelMap.forEach((
|
218
|
-
|
219
|
-
const
|
220
|
-
if (
|
221
|
-
for (const
|
222
|
-
|
223
|
-
unitId
|
224
|
-
subunitId
|
225
|
-
sourceId
|
226
|
-
nodeId:
|
227
|
-
row:
|
228
|
-
column:
|
226
|
+
getBindingModelBySourceId(sourceId) {
|
227
|
+
const rs = [];
|
228
|
+
return this.modelMap.forEach((subMap, unitId) => {
|
229
|
+
subMap.forEach((model, subunitId) => {
|
230
|
+
const nodes = model.getBindingNodesBySourceId(sourceId);
|
231
|
+
if (nodes)
|
232
|
+
for (const node of nodes)
|
233
|
+
rs.push({
|
234
|
+
unitId,
|
235
|
+
subunitId,
|
236
|
+
sourceId,
|
237
|
+
nodeId: node.nodeId,
|
238
|
+
row: node.row,
|
239
|
+
column: node.column
|
229
240
|
});
|
230
241
|
});
|
231
|
-
}),
|
242
|
+
}), rs;
|
232
243
|
}
|
233
|
-
addModel(
|
234
|
-
var
|
235
|
-
this.modelMap.has(
|
244
|
+
addModel(unitId, subunitId, model) {
|
245
|
+
var _a4;
|
246
|
+
this.modelMap.has(unitId) || this.modelMap.set(unitId, /* @__PURE__ */ new Map()), (_a4 = this.modelMap.get(unitId)) == null || _a4.set(subunitId, model);
|
236
247
|
}
|
237
|
-
getModel(
|
238
|
-
var
|
239
|
-
return (
|
248
|
+
getModel(unitId, subunitId) {
|
249
|
+
var _a4;
|
250
|
+
return (_a4 = this.modelMap.get(unitId)) == null ? void 0 : _a4.get(subunitId);
|
240
251
|
}
|
241
|
-
setBindingNode(
|
242
|
-
let
|
243
|
-
|
244
|
-
const { row
|
245
|
-
if (
|
252
|
+
setBindingNode(unitId, subunitId, node) {
|
253
|
+
let model = this.getModel(unitId, subunitId);
|
254
|
+
model || (model = new SheetBindingModel(), this.addModel(unitId, subunitId, model)), node.nodeId || (node.nodeId = generateRandomId());
|
255
|
+
const { row, column } = node;
|
256
|
+
if (row === void 0 || column === void 0)
|
246
257
|
throw new Error("row and column is required");
|
247
|
-
const
|
248
|
-
|
249
|
-
unitId
|
250
|
-
subunitId
|
251
|
-
sourceId:
|
252
|
-
nodeId:
|
253
|
-
row
|
254
|
-
column
|
255
|
-
containHeader
|
256
|
-
changeType:
|
257
|
-
oldSourceId:
|
258
|
-
oldNodeContainHeader: (
|
258
|
+
const oldNode = model.getBindingNode(row, column), containHeader = node.type === DataBindingNodeTypeEnum.List ? !!node.containHeader : !1;
|
259
|
+
model.setBindingNode(row, column, { ...node, row, column }), this._cellBindInfoUpdate$.next({
|
260
|
+
unitId,
|
261
|
+
subunitId,
|
262
|
+
sourceId: node.sourceId,
|
263
|
+
nodeId: node.nodeId,
|
264
|
+
row,
|
265
|
+
column,
|
266
|
+
containHeader,
|
267
|
+
changeType: oldNode ? BindingSourceChangeTypeEnum.Update : BindingSourceChangeTypeEnum.Add,
|
268
|
+
oldSourceId: oldNode == null ? void 0 : oldNode.sourceId,
|
269
|
+
oldNodeContainHeader: (oldNode == null ? void 0 : oldNode.type) === DataBindingNodeTypeEnum.List ? !!oldNode.containHeader : !1
|
259
270
|
});
|
260
271
|
}
|
261
|
-
removeBindingNode(
|
262
|
-
const
|
263
|
-
if (
|
264
|
-
const
|
265
|
-
|
266
|
-
unitId
|
267
|
-
subunitId
|
268
|
-
sourceId:
|
269
|
-
nodeId:
|
270
|
-
row
|
271
|
-
column
|
272
|
-
changeType:
|
272
|
+
removeBindingNode(unitId, subunitId, row, column) {
|
273
|
+
const model = this.getModel(unitId, subunitId);
|
274
|
+
if (model) {
|
275
|
+
const node = model.getBindingNode(row, column);
|
276
|
+
node && (model.removeBindingNode(row, column), this._cellBindInfoUpdate$.next({
|
277
|
+
unitId,
|
278
|
+
subunitId,
|
279
|
+
sourceId: node.sourceId,
|
280
|
+
nodeId: node.nodeId,
|
281
|
+
row,
|
282
|
+
column,
|
283
|
+
changeType: BindingSourceChangeTypeEnum.Remove
|
273
284
|
}));
|
274
285
|
}
|
275
286
|
}
|
276
|
-
getBindingNode(
|
277
|
-
const
|
278
|
-
if (
|
279
|
-
return
|
280
|
-
}
|
281
|
-
getBindingNodeById(
|
282
|
-
const
|
283
|
-
if (
|
284
|
-
return
|
285
|
-
}
|
286
|
-
createModel(
|
287
|
-
const
|
288
|
-
return this.addModel(
|
289
|
-
}
|
290
|
-
toJSON(
|
291
|
-
const
|
292
|
-
return
|
293
|
-
|
294
|
-
}),
|
295
|
-
}
|
296
|
-
fromJSON(
|
297
|
-
Object.entries(
|
298
|
-
this.createModel(
|
287
|
+
getBindingNode(unitId, subunitId, row, column) {
|
288
|
+
const model = this.getModel(unitId, subunitId);
|
289
|
+
if (model)
|
290
|
+
return model.getBindingNode(row, column);
|
291
|
+
}
|
292
|
+
getBindingNodeById(unitId, subunitId, nodeId) {
|
293
|
+
const model = this.getModel(unitId, subunitId);
|
294
|
+
if (model)
|
295
|
+
return model.getBindingNodeById(nodeId);
|
296
|
+
}
|
297
|
+
createModel(unitId, subunitId, json) {
|
298
|
+
const model = new SheetBindingModel(json);
|
299
|
+
return this.addModel(unitId, subunitId, model), model;
|
300
|
+
}
|
301
|
+
toJSON(unitId) {
|
302
|
+
const rs = {}, subMap = this.modelMap.get(unitId);
|
303
|
+
return subMap && subMap.forEach((model, subunitId) => {
|
304
|
+
rs[subunitId] = model.toJSON();
|
305
|
+
}), rs;
|
306
|
+
}
|
307
|
+
fromJSON(unitId, json) {
|
308
|
+
Object.entries(json).forEach(([subunitId, nodes]) => {
|
309
|
+
this.createModel(unitId, subunitId, nodes);
|
299
310
|
});
|
300
311
|
}
|
301
312
|
dispose() {
|
302
313
|
this.modelMap.clear(), this._cellBindInfoUpdate$.complete();
|
303
314
|
}
|
304
|
-
};
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
],
|
310
|
-
class
|
315
|
+
}, __name(_a, "SheetsBindingManager"), _a);
|
316
|
+
SheetsBindingManager = __decorateClass$2([
|
317
|
+
__decorateParam$2(0, IUniverInstanceService),
|
318
|
+
__decorateParam$2(1, Inject(SheetInterceptorService)),
|
319
|
+
__decorateParam$2(2, Inject(SheetsSelectionsService))
|
320
|
+
], SheetsBindingManager);
|
321
|
+
const _SheetsSourceManager = class _SheetsSourceManager extends Disposable {
|
311
322
|
constructor() {
|
312
323
|
super();
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
}
|
317
|
-
_ensureUnitMap(
|
318
|
-
let
|
319
|
-
return
|
320
|
-
}
|
321
|
-
_getUnitMap(
|
322
|
-
return this.sourceMap.get(
|
323
|
-
}
|
324
|
-
getSource(
|
325
|
-
const
|
326
|
-
return
|
327
|
-
}
|
328
|
-
createSource(
|
329
|
-
const
|
330
|
-
let
|
331
|
-
switch (
|
332
|
-
case
|
333
|
-
|
324
|
+
__publicField(this, "sourceMap", /* @__PURE__ */ new Map());
|
325
|
+
__publicField(this, "_sourceDataUpdate$", new Subject());
|
326
|
+
__publicField(this, "sourceDataUpdate$", this._sourceDataUpdate$.asObservable());
|
327
|
+
}
|
328
|
+
_ensureUnitMap(unitId) {
|
329
|
+
let unit = this.sourceMap.get(unitId);
|
330
|
+
return unit || (unit = /* @__PURE__ */ new Map(), this.sourceMap.set(unitId, unit)), unit;
|
331
|
+
}
|
332
|
+
_getUnitMap(unitId) {
|
333
|
+
return this.sourceMap.get(unitId);
|
334
|
+
}
|
335
|
+
getSource(unitId, id) {
|
336
|
+
const unitMap = this._getUnitMap(unitId);
|
337
|
+
return unitMap == null ? void 0 : unitMap.get(id);
|
338
|
+
}
|
339
|
+
createSource(unitId, type, isListObject, id) {
|
340
|
+
const sourceId = id === void 0 ? generateRandomId() : id;
|
341
|
+
let source;
|
342
|
+
switch (type) {
|
343
|
+
case DataBindingNodeTypeEnum.List:
|
344
|
+
source = new ListSourceModel(sourceId, isListObject);
|
334
345
|
break;
|
335
|
-
case
|
336
|
-
|
346
|
+
case DataBindingNodeTypeEnum.Object:
|
347
|
+
source = new ObjectSourceModel(sourceId);
|
337
348
|
break;
|
338
349
|
default:
|
339
|
-
throw new Error(`Invalid source type: ${
|
350
|
+
throw new Error(`Invalid source type: ${type}`);
|
340
351
|
}
|
341
|
-
return this._ensureUnitMap(
|
352
|
+
return this._ensureUnitMap(unitId).set(sourceId, source), source;
|
342
353
|
}
|
343
|
-
updateSourceData(
|
344
|
-
const
|
345
|
-
if (
|
346
|
-
|
354
|
+
updateSourceData(unitId, idOrInstance, data) {
|
355
|
+
const unitMap = this._getUnitMap(unitId), sourceId = idOrInstance instanceof SourceModelBase ? idOrInstance.getId() : idOrInstance, source = unitMap == null ? void 0 : unitMap.get(sourceId);
|
356
|
+
if (source)
|
357
|
+
source.setSourceData(data), this._sourceDataUpdate$.next({ ...source.getSourceInfo(), unitId, changeType: BindingSourceChangeTypeEnum.Add });
|
347
358
|
else
|
348
|
-
throw new Error(`Source not found: ${
|
349
|
-
}
|
350
|
-
removeSource(
|
351
|
-
const
|
352
|
-
|
353
|
-
}
|
354
|
-
toJSON(
|
355
|
-
const
|
356
|
-
if (
|
357
|
-
for (const
|
358
|
-
|
359
|
-
return
|
360
|
-
}
|
361
|
-
fromJSON(
|
362
|
-
const
|
363
|
-
for (const
|
364
|
-
let
|
365
|
-
switch (
|
366
|
-
case
|
367
|
-
|
359
|
+
throw new Error(`Source not found: ${sourceId}`);
|
360
|
+
}
|
361
|
+
removeSource(unitId, id) {
|
362
|
+
const unitMap = this._getUnitMap(unitId), source = unitMap == null ? void 0 : unitMap.get(id);
|
363
|
+
source && (unitMap == null || unitMap.delete(id), this._sourceDataUpdate$.next({ ...source.getSourceInfo(), unitId, changeType: BindingSourceChangeTypeEnum.Remove }));
|
364
|
+
}
|
365
|
+
toJSON(unitId) {
|
366
|
+
const sourceList = [], unitMap = this._getUnitMap(unitId);
|
367
|
+
if (unitMap)
|
368
|
+
for (const source of unitMap.values())
|
369
|
+
sourceList.push(source.toJSON());
|
370
|
+
return sourceList;
|
371
|
+
}
|
372
|
+
fromJSON(unitId, sources) {
|
373
|
+
const unitMap = this._ensureUnitMap(unitId);
|
374
|
+
for (const source of sources) {
|
375
|
+
let model;
|
376
|
+
switch (source.type) {
|
377
|
+
case DataBindingNodeTypeEnum.List:
|
378
|
+
model = new ListSourceModel(source.id);
|
368
379
|
break;
|
369
|
-
case
|
370
|
-
|
380
|
+
case DataBindingNodeTypeEnum.Object:
|
381
|
+
model = new ObjectSourceModel(source.id);
|
371
382
|
break;
|
372
383
|
default:
|
373
|
-
throw new Error(`Invalid source type: ${
|
384
|
+
throw new Error(`Invalid source type: ${source.type}`);
|
374
385
|
}
|
375
|
-
|
386
|
+
model.fromJSON(source), unitMap.set(source.id, model);
|
376
387
|
}
|
377
388
|
}
|
378
389
|
dispose() {
|
379
390
|
this._sourceDataUpdate$.complete(), this.sourceMap.clear();
|
380
391
|
}
|
381
|
-
}
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
392
|
+
};
|
393
|
+
__name(_SheetsSourceManager, "SheetsSourceManager");
|
394
|
+
let SheetsSourceManager = _SheetsSourceManager;
|
395
|
+
var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
396
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
397
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
398
|
+
return kind && result && __defProp$1(target, key, result), result;
|
399
|
+
}, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a2;
|
400
|
+
let SheetsSourceBindService = (_a2 = class extends Disposable {
|
401
|
+
constructor(_sheetInterceptorService, _sheetsBindingManager, _sheetsSourceManager) {
|
389
402
|
super();
|
390
|
-
|
391
|
-
|
392
|
-
this._sheetInterceptorService =
|
403
|
+
__publicField(this, "_bindingModel", BindModeEnum.Value);
|
404
|
+
__publicField(this, "_bindModelRTreeCollection", /* @__PURE__ */ new Map());
|
405
|
+
this._sheetInterceptorService = _sheetInterceptorService, this._sheetsBindingManager = _sheetsBindingManager, this._sheetsSourceManager = _sheetsSourceManager, this._registerInterceptor(), this._registerSourceChange();
|
393
406
|
}
|
394
407
|
/**
|
395
408
|
* Set the binding model to path mode, in this mode, the binding path will show in the cell.
|
396
409
|
*/
|
397
410
|
usePathMode() {
|
398
|
-
this._bindingModel =
|
411
|
+
this._bindingModel = BindModeEnum.Path;
|
399
412
|
}
|
400
413
|
/**
|
401
414
|
* Set the binding model to value mode, in this mode, the value of source will show in the cell.
|
402
415
|
*/
|
403
416
|
useValueMode() {
|
404
|
-
this._bindingModel =
|
417
|
+
this._bindingModel = BindModeEnum.Value;
|
405
418
|
}
|
406
419
|
/**
|
407
420
|
* Get the current binding model.
|
@@ -410,200 +423,200 @@ let w = class extends O {
|
|
410
423
|
getBindingModel() {
|
411
424
|
return this._bindingModel;
|
412
425
|
}
|
413
|
-
createBindModel(
|
414
|
-
return this._sheetsBindingManager.createModel(
|
426
|
+
createBindModel(unitId, subUnitId) {
|
427
|
+
return this._sheetsBindingManager.createModel(unitId, subUnitId);
|
415
428
|
}
|
416
|
-
setBindingNode(
|
417
|
-
this._sheetsBindingManager.setBindingNode(
|
429
|
+
setBindingNode(unitId, subUnitId, node) {
|
430
|
+
this._sheetsBindingManager.setBindingNode(unitId, subUnitId, node);
|
418
431
|
}
|
419
|
-
removeBindingNode(
|
420
|
-
this._sheetsBindingManager.removeBindingNode(
|
432
|
+
removeBindingNode(unitId, subUnitId, row, column) {
|
433
|
+
this._sheetsBindingManager.removeBindingNode(unitId, subUnitId, row, column);
|
421
434
|
}
|
422
|
-
getBindingNode(
|
423
|
-
return this._sheetsBindingManager.getBindingNode(
|
435
|
+
getBindingNode(unitId, subUnitId, row, column) {
|
436
|
+
return this._sheetsBindingManager.getBindingNode(unitId, subUnitId, row, column);
|
424
437
|
}
|
425
|
-
getSource(
|
426
|
-
return this._sheetsSourceManager.getSource(
|
438
|
+
getSource(unitId, id) {
|
439
|
+
return this._sheetsSourceManager.getSource(unitId, id);
|
427
440
|
}
|
428
|
-
createSource(
|
429
|
-
return this._sheetsSourceManager.createSource(
|
441
|
+
createSource(unitId, type, isListObject, id) {
|
442
|
+
return this._sheetsSourceManager.createSource(unitId, type, isListObject, id);
|
430
443
|
}
|
431
|
-
getSourceBindingPathInfo(
|
444
|
+
getSourceBindingPathInfo(unitId) {
|
432
445
|
return {
|
433
|
-
source: this._sheetsSourceManager.toJSON(
|
434
|
-
cellBinding: this._sheetsBindingManager.toJSON(
|
446
|
+
source: this._sheetsSourceManager.toJSON(unitId),
|
447
|
+
cellBinding: this._sheetsBindingManager.toJSON(unitId)
|
435
448
|
};
|
436
449
|
}
|
437
|
-
loadSourceBindingPathInfo(
|
438
|
-
this._sheetsSourceManager.fromJSON(
|
450
|
+
loadSourceBindingPathInfo(unitId, obj) {
|
451
|
+
this._sheetsSourceManager.fromJSON(unitId, obj.source), this._sheetsBindingManager.fromJSON(unitId, obj.cellBinding);
|
439
452
|
}
|
440
|
-
_ensureRTreeCollection(
|
441
|
-
return this._bindModelRTreeCollection.has(
|
453
|
+
_ensureRTreeCollection(unitId) {
|
454
|
+
return this._bindModelRTreeCollection.has(unitId) || this._bindModelRTreeCollection.set(unitId, new RTree()), this._bindModelRTreeCollection.get(unitId);
|
442
455
|
}
|
443
|
-
_getRTeeCollection(
|
444
|
-
return this._bindModelRTreeCollection.get(
|
456
|
+
_getRTeeCollection(unitId) {
|
457
|
+
return this._bindModelRTreeCollection.get(unitId);
|
445
458
|
}
|
446
459
|
// eslint-disable-next-line max-lines-per-function
|
447
460
|
_registerSourceChange() {
|
448
|
-
this.disposeWithMe(this._sheetsSourceManager.sourceDataUpdate$.subscribe((
|
449
|
-
const { sourceId
|
450
|
-
if (
|
451
|
-
if (
|
452
|
-
const
|
453
|
-
for (const { unitId
|
454
|
-
const
|
455
|
-
if (
|
456
|
-
const
|
457
|
-
|
461
|
+
this.disposeWithMe(this._sheetsSourceManager.sourceDataUpdate$.subscribe((sourceInfo) => {
|
462
|
+
const { sourceId, sourceType, unitId: sourceUnitId, changeType } = sourceInfo;
|
463
|
+
if (sourceType === DataBindingNodeTypeEnum.List) {
|
464
|
+
if (changeType === BindingSourceChangeTypeEnum.Remove) {
|
465
|
+
const nodeInfo = this._sheetsBindingManager.getBindingModelBySourceId(sourceId), recordCount = sourceInfo.recordCount;
|
466
|
+
for (const { unitId, subunitId, nodeId, row, column } of nodeInfo) {
|
467
|
+
const rTreeCollection = this._getRTeeCollection(sourceUnitId), node = this._sheetsBindingManager.getBindingNodeById(unitId, subunitId, nodeId);
|
468
|
+
if (rTreeCollection && (node == null ? void 0 : node.type) === DataBindingNodeTypeEnum.List) {
|
469
|
+
const offset = node.containHeader ? 0 : 1, range = { startRow: row, startColumn: column, endRow: row + recordCount - offset, endColumn: column };
|
470
|
+
rTreeCollection.remove({ unitId, sheetId: subunitId, id: nodeId, range });
|
458
471
|
}
|
459
472
|
}
|
460
473
|
return;
|
461
474
|
}
|
462
|
-
if (
|
463
|
-
const
|
464
|
-
for (const { unitId
|
465
|
-
const
|
466
|
-
if (
|
467
|
-
const
|
468
|
-
|
475
|
+
if (changeType === BindingSourceChangeTypeEnum.Update) {
|
476
|
+
const oldRecordCount = sourceInfo.oldRecordCount, nodeInfo = this._sheetsBindingManager.getBindingModelBySourceId(sourceId);
|
477
|
+
for (const { unitId, subunitId, nodeId, row, column } of nodeInfo) {
|
478
|
+
const rTreeCollection = this._getRTeeCollection(sourceUnitId), node = this._sheetsBindingManager.getBindingNodeById(unitId, subunitId, nodeId);
|
479
|
+
if (rTreeCollection && (node == null ? void 0 : node.type) === DataBindingNodeTypeEnum.List) {
|
480
|
+
const offset = node.containHeader ? 0 : 1, oldRange = { startRow: row, startColumn: column, endRow: row + oldRecordCount - offset, endColumn: column }, range = { startRow: row, startColumn: column, endRow: row + sourceInfo.recordCount - offset, endColumn: column };
|
481
|
+
rTreeCollection.remove({ unitId, sheetId: subunitId, id: nodeId, range: oldRange }), rTreeCollection.insert({ unitId, sheetId: subunitId, id: nodeId, range });
|
469
482
|
}
|
470
483
|
}
|
471
484
|
return;
|
472
485
|
}
|
473
|
-
const
|
474
|
-
if (
|
475
|
-
const
|
476
|
-
for (const { unitId
|
477
|
-
const
|
478
|
-
if (
|
479
|
-
const
|
480
|
-
|
486
|
+
const source = this._sheetsSourceManager.getSource(sourceUnitId, sourceId);
|
487
|
+
if (source && source.hasData()) {
|
488
|
+
const recordCount = source.getSourceInfo().recordCount, nodeInfo = this._sheetsBindingManager.getBindingModelBySourceId(sourceId);
|
489
|
+
for (const { unitId, subunitId, nodeId, row, column } of nodeInfo) {
|
490
|
+
const rTreeCollection = this._ensureRTreeCollection(unitId), node = this._sheetsBindingManager.getBindingNodeById(unitId, subunitId, nodeId);
|
491
|
+
if (rTreeCollection && (node == null ? void 0 : node.type) === DataBindingNodeTypeEnum.List) {
|
492
|
+
const offset = node.containHeader ? 0 : 1, range = { startRow: row, startColumn: column, endRow: row + recordCount - offset, endColumn: column };
|
493
|
+
rTreeCollection.insert({ unitId, sheetId: subunitId, id: nodeId, range });
|
481
494
|
}
|
482
495
|
}
|
483
496
|
}
|
484
497
|
}
|
485
|
-
})), this.disposeWithMe(this._sheetsBindingManager.cellBindInfoUpdate$.subscribe((
|
486
|
-
const { unitId
|
487
|
-
if (
|
488
|
-
const
|
489
|
-
if (
|
490
|
-
const
|
491
|
-
if (
|
492
|
-
|
493
|
-
else if (
|
494
|
-
|
495
|
-
else if (
|
496
|
-
const
|
497
|
-
if (
|
498
|
-
const
|
499
|
-
|
498
|
+
})), this.disposeWithMe(this._sheetsBindingManager.cellBindInfoUpdate$.subscribe((nodeInfo) => {
|
499
|
+
const { unitId, subunitId, sourceId, nodeId, row, column, changeType, containHeader } = nodeInfo, rTreeCollection = this._ensureRTreeCollection(unitId), source = this._sheetsSourceManager.getSource(unitId, sourceId);
|
500
|
+
if (source && source.hasData()) {
|
501
|
+
const sourceInfo = source.getSourceInfo();
|
502
|
+
if (sourceInfo.sourceType === DataBindingNodeTypeEnum.List) {
|
503
|
+
const recordCount = sourceInfo.recordCount, offset = containHeader ? 0 : 1, range = { startRow: row, startColumn: column, endRow: row + recordCount - offset, endColumn: column };
|
504
|
+
if (changeType === BindingSourceChangeTypeEnum.Add)
|
505
|
+
rTreeCollection.insert({ unitId, sheetId: subunitId, id: nodeId, range });
|
506
|
+
else if (changeType === BindingSourceChangeTypeEnum.Remove)
|
507
|
+
rTreeCollection.remove({ unitId, sheetId: subunitId, id: nodeId, range });
|
508
|
+
else if (changeType === BindingSourceChangeTypeEnum.Update) {
|
509
|
+
const oldSourceId = nodeInfo.oldSourceId, offset2 = nodeInfo.oldNodeContainHeader ? 0 : 1, oldSource = this._sheetsSourceManager.getSource(unitId, oldSourceId);
|
510
|
+
if (oldSource && oldSource.hasData()) {
|
511
|
+
const oldRecordCount = oldSource.getSourceInfo().recordCount, oldRange = { startRow: row, startColumn: column, endRow: row + oldRecordCount - offset2, endColumn: column };
|
512
|
+
rTreeCollection.remove({ unitId, sheetId: subunitId, id: nodeId, range: oldRange });
|
500
513
|
}
|
501
|
-
|
514
|
+
rTreeCollection.insert({ unitId, sheetId: subunitId, id: nodeId, range });
|
502
515
|
}
|
503
516
|
}
|
504
517
|
}
|
505
518
|
}));
|
506
519
|
}
|
507
|
-
_getPathModeCellValue(
|
508
|
-
const
|
509
|
-
if (
|
510
|
-
const
|
511
|
-
if (
|
520
|
+
_getPathModeCellValue(unitId, subUnitId, row, col) {
|
521
|
+
const model = this._sheetsBindingManager.getModel(unitId, subUnitId), node = model == null ? void 0 : model.getBindingNode(row, col);
|
522
|
+
if (node) {
|
523
|
+
const nodeType = node.type;
|
524
|
+
if (nodeType === DataBindingNodeTypeEnum.List)
|
512
525
|
return {
|
513
|
-
v: `#{${
|
526
|
+
v: `#{${node.path}}`,
|
514
527
|
s: { cl: { rgb: "blue" } }
|
515
528
|
};
|
516
|
-
if (
|
529
|
+
if (nodeType === DataBindingNodeTypeEnum.Object)
|
517
530
|
return {
|
518
|
-
v: `[${
|
531
|
+
v: `[${node.path}]`,
|
519
532
|
s: { cl: { rgb: "blue" } }
|
520
533
|
};
|
521
534
|
}
|
522
535
|
}
|
523
|
-
_getValueModeCellValue(
|
524
|
-
const
|
525
|
-
if (
|
526
|
-
const
|
527
|
-
if (
|
528
|
-
const { sourceId
|
529
|
-
if (
|
530
|
-
return (
|
536
|
+
_getValueModeCellValue(unitId, subUnitId, row, col) {
|
537
|
+
const model = this._sheetsBindingManager.getModel(unitId, subUnitId);
|
538
|
+
if (model) {
|
539
|
+
const node = model.getBindingNode(row, col);
|
540
|
+
if (node) {
|
541
|
+
const { sourceId } = node, source = this._sheetsSourceManager.getSource(unitId, sourceId);
|
542
|
+
if (source && source.hasData())
|
543
|
+
return (source == null ? void 0 : source.getData(node, row, col)) || { v: "" };
|
531
544
|
}
|
532
545
|
}
|
533
|
-
const
|
534
|
-
if (
|
535
|
-
const
|
536
|
-
if (
|
537
|
-
const
|
538
|
-
if (
|
539
|
-
const { sourceId
|
540
|
-
if (
|
541
|
-
return (
|
546
|
+
const rTreeCollection = this._getRTeeCollection(unitId);
|
547
|
+
if (model && rTreeCollection) {
|
548
|
+
const range = { startRow: row, startColumn: col, endRow: row, endColumn: col }, nodeIds = Array.from(rTreeCollection.bulkSearch([{ unitId, sheetId: subUnitId, range }]));
|
549
|
+
if (nodeIds.length > 0) {
|
550
|
+
const node = model.getBindingNodeById(nodeIds[0]);
|
551
|
+
if (node) {
|
552
|
+
const { sourceId } = node, source = this._sheetsSourceManager.getSource(unitId, sourceId);
|
553
|
+
if (source && source.hasData())
|
554
|
+
return (source == null ? void 0 : source.getData(node, row, col)) || { v: "" };
|
542
555
|
}
|
543
556
|
}
|
544
557
|
}
|
545
558
|
}
|
546
|
-
getBindingModelBySourceId(
|
547
|
-
return this._sheetsBindingManager.getBindingModelBySourceId(
|
559
|
+
getBindingModelBySourceId(sourceId) {
|
560
|
+
return this._sheetsBindingManager.getBindingModelBySourceId(sourceId);
|
548
561
|
}
|
549
562
|
_registerInterceptor() {
|
550
|
-
this.disposeWithMe(this._sheetInterceptorService.intercept(
|
551
|
-
effect:
|
563
|
+
this.disposeWithMe(this._sheetInterceptorService.intercept(INTERCEPTOR_POINT.CELL_CONTENT, {
|
564
|
+
effect: InterceptorEffectEnum.Value | InterceptorEffectEnum.Style,
|
552
565
|
priority: 102,
|
553
|
-
handler: (
|
554
|
-
const { row
|
555
|
-
let
|
556
|
-
if (this._bindingModel ===
|
557
|
-
const
|
558
|
-
return
|
566
|
+
handler: /* @__PURE__ */ __name((cell, context, next) => {
|
567
|
+
const { row, col, unitId, subUnitId, workbook } = context;
|
568
|
+
let value = null;
|
569
|
+
if (this._bindingModel === BindModeEnum.Path ? value = this._getPathModeCellValue(unitId, subUnitId, row, col) : value = this._getValueModeCellValue(unitId, subUnitId, row, col), value !== null) {
|
570
|
+
const newStyle = { ...(typeof (cell == null ? void 0 : cell.s) == "string" ? workbook.getStyles().get(cell == null ? void 0 : cell.s) : cell == null ? void 0 : cell.s) || {} };
|
571
|
+
return value && value.s && Object.assign(newStyle, value.s), next({ ...cell, ...value, s: newStyle });
|
559
572
|
}
|
560
|
-
return
|
561
|
-
}
|
573
|
+
return next(cell);
|
574
|
+
}, "handler")
|
562
575
|
}));
|
563
576
|
}
|
564
577
|
dispose() {
|
565
578
|
this._bindModelRTreeCollection.clear();
|
566
579
|
}
|
567
|
-
};
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
],
|
573
|
-
var
|
574
|
-
for (var
|
575
|
-
(
|
576
|
-
return
|
577
|
-
},
|
578
|
-
let
|
579
|
-
constructor(
|
580
|
-
super(), this._config =
|
580
|
+
}, __name(_a2, "SheetsSourceBindService"), _a2);
|
581
|
+
SheetsSourceBindService = __decorateClass$1([
|
582
|
+
__decorateParam$1(0, Inject(SheetInterceptorService)),
|
583
|
+
__decorateParam$1(1, Inject(SheetsBindingManager)),
|
584
|
+
__decorateParam$1(2, Inject(SheetsSourceManager))
|
585
|
+
], SheetsSourceBindService);
|
586
|
+
var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
587
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
588
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
589
|
+
return kind && result && __defProp2(target, key, result), result;
|
590
|
+
}, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), _a3;
|
591
|
+
let UniverSheetsBindingSourcePlugin = (_a3 = class extends Plugin {
|
592
|
+
constructor(_config = {}, _injector, _configService) {
|
593
|
+
super(), this._config = _config, this._injector = _injector, this._configService = _configService;
|
581
594
|
}
|
582
595
|
onStarting() {
|
583
596
|
[
|
584
|
-
[
|
585
|
-
[
|
586
|
-
[
|
587
|
-
].forEach((
|
597
|
+
[SheetsBindingManager],
|
598
|
+
[SheetsSourceManager],
|
599
|
+
[SheetsSourceBindService]
|
600
|
+
].forEach((d) => this._injector.add(d));
|
588
601
|
}
|
589
602
|
onReady() {
|
590
|
-
|
591
|
-
[
|
592
|
-
[
|
593
|
-
[
|
603
|
+
touchDependencies(this._injector, [
|
604
|
+
[SheetsBindingManager],
|
605
|
+
[SheetsSourceManager],
|
606
|
+
[SheetsSourceBindService]
|
594
607
|
]);
|
595
608
|
}
|
596
|
-
},
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
],
|
609
|
+
}, __name(_a3, "UniverSheetsBindingSourcePlugin"), __publicField(_a3, "type", UniverInstanceType.UNIVER_SHEET), __publicField(_a3, "pluginName", "SHEET_BINDING_SOURCE_PLUGIN"), _a3);
|
610
|
+
UniverSheetsBindingSourcePlugin = __decorateClass([
|
611
|
+
__decorateParam(1, Inject(Injector)),
|
612
|
+
__decorateParam(2, IConfigService)
|
613
|
+
], UniverSheetsBindingSourcePlugin);
|
601
614
|
export {
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
615
|
+
BindModeEnum,
|
616
|
+
SheetBindingModel as BindingModel,
|
617
|
+
DataBindingNodeTypeEnum,
|
618
|
+
SheetsSourceBindService,
|
619
|
+
SheetsSourceManager,
|
620
|
+
SourceModelBase,
|
621
|
+
UniverSheetsBindingSourcePlugin
|
609
622
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@univerjs/sheets-source-binding",
|
3
|
-
"version": "0.5.5-nightly.
|
3
|
+
"version": "0.5.5-nightly.202501210849",
|
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,8 +51,8 @@
|
|
51
51
|
"rxjs": ">=7.0.0"
|
52
52
|
},
|
53
53
|
"dependencies": {
|
54
|
-
"@univerjs/
|
55
|
-
"@univerjs/
|
54
|
+
"@univerjs/core": "0.5.5-nightly.202501210849",
|
55
|
+
"@univerjs/sheets": "0.5.5-nightly.202501210849"
|
56
56
|
},
|
57
57
|
"devDependencies": {
|
58
58
|
"rxjs": "^7.8.1",
|