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