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