@univerjs/sheets-source-binding 0.5.3

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.
@@ -0,0 +1,606 @@
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);
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 || {}), 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;
66
+ }
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;
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 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;
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, n) {
115
+ const { path: o, row: s, containHeader: r } = t, d = this._fieldIndexMap.get(o), c = n - s;
116
+ if (r && c === 0)
117
+ return {
118
+ v: this._data.fields[d]
119
+ };
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),
124
+ s: {
125
+ n: {
126
+ pattern: "yyyy-m-d am/pm h:mm"
127
+ }
128
+ },
129
+ t: v.NUMBER
130
+ } : {
131
+ t: typeof a == "number" ? v.NUMBER : v.STRING,
132
+ v: a
133
+ };
134
+ }
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);
140
+ });
141
+ }
142
+ getSourceInfo() {
143
+ return {
144
+ sourceId: this.id,
145
+ sourceType: this.type,
146
+ fields: this._data.fields,
147
+ recordCount: this._data.records.length
148
+ };
149
+ }
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)
161
+ return null;
162
+ return t.isDate === !0 ? {
163
+ v: A(s),
164
+ s: {
165
+ n: {
166
+ pattern: "yyyy-m-d am/pm h:mm"
167
+ }
168
+ },
169
+ t: v.NUMBER
170
+ } : {
171
+ v: s,
172
+ t: typeof s == "number" ? v.NUMBER : v.STRING
173
+ };
174
+ }
175
+ getSourceInfo() {
176
+ return {
177
+ sourceId: this.id,
178
+ sourceType: g.Object
179
+ };
180
+ }
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) {
189
+ super();
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();
194
+ }
195
+ _initRemoveCommand() {
196
+ this.disposeWithMe(
197
+ this._sheetInterceptorService.interceptCommand({
198
+ getMutations: (e) => {
199
+ const t = [], n = [], o = this._sheetsSelectionsService.getCurrentSelections(), s = ne(this._univerInstanceService);
200
+ if (!s || !o || o.length === 0)
201
+ return {
202
+ redos: [],
203
+ undos: []
204
+ };
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);
209
+ });
210
+ }), { redos: t, undos: n };
211
+ }
212
+ })
213
+ );
214
+ }
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
229
+ });
230
+ });
231
+ }), t;
232
+ }
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);
236
+ }
237
+ getModel(e, t) {
238
+ var n;
239
+ return (n = this.modelMap.get(e)) == null ? void 0 : n.get(t);
240
+ }
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)
246
+ throw new Error("row and column is required");
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
259
+ });
260
+ }
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
273
+ }));
274
+ }
275
+ }
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);
299
+ });
300
+ }
301
+ dispose() {
302
+ this.modelMap.clear(), this._cellBindInfoUpdate$.complete();
303
+ }
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 {
311
+ constructor() {
312
+ super();
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);
334
+ break;
335
+ case g.Object:
336
+ d = new E(r);
337
+ break;
338
+ default:
339
+ throw new Error(`Invalid source type: ${n}`);
340
+ }
341
+ return this._ensureUnitMap(t).set(r, d), d;
342
+ }
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 });
347
+ else
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);
368
+ break;
369
+ case g.Object:
370
+ r = new E(s.id);
371
+ break;
372
+ default:
373
+ throw new Error(`Invalid source type: ${s.type}`);
374
+ }
375
+ r.fromJSON(s), o.set(s.id, r);
376
+ }
377
+ }
378
+ dispose() {
379
+ this._sourceDataUpdate$.complete(), this.sourceMap.clear();
380
+ }
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) {
389
+ super();
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();
393
+ }
394
+ /**
395
+ * Set the binding model to path mode, in this mode, the binding path will show in the cell.
396
+ */
397
+ usePathMode() {
398
+ this._bindingModel = y.Path;
399
+ }
400
+ /**
401
+ * Set the binding model to value mode, in this mode, the value of source will show in the cell.
402
+ */
403
+ useValueMode() {
404
+ this._bindingModel = y.Value;
405
+ }
406
+ /**
407
+ * Get the current binding model.
408
+ * @returns the current binding model
409
+ */
410
+ getBindingModel() {
411
+ return this._bindingModel;
412
+ }
413
+ createBindModel(e, t) {
414
+ return this._sheetsBindingManager.createModel(e, t);
415
+ }
416
+ setBindingNode(e, t, n) {
417
+ this._sheetsBindingManager.setBindingNode(e, t, n);
418
+ }
419
+ removeBindingNode(e, t, n, o) {
420
+ this._sheetsBindingManager.removeBindingNode(e, t, n, o);
421
+ }
422
+ getBindingNode(e, t, n, o) {
423
+ return this._sheetsBindingManager.getBindingNode(e, t, n, o);
424
+ }
425
+ getSource(e, t) {
426
+ return this._sheetsSourceManager.getSource(e, t);
427
+ }
428
+ createSource(e, t, n, o) {
429
+ return this._sheetsSourceManager.createSource(e, t, n, o);
430
+ }
431
+ getSourceBindingPathInfo(e) {
432
+ return {
433
+ source: this._sheetsSourceManager.toJSON(e),
434
+ cellBinding: this._sheetsBindingManager.toJSON(e)
435
+ };
436
+ }
437
+ loadSourceBindingPathInfo(e, t) {
438
+ this._sheetsSourceManager.fromJSON(e, t.source), this._sheetsBindingManager.fromJSON(e, t.cellBinding);
439
+ }
440
+ _ensureRTreeCollection(e) {
441
+ return this._bindModelRTreeCollection.has(e) || this._bindModelRTreeCollection.set(e, new Q()), this._bindModelRTreeCollection.get(e);
442
+ }
443
+ _getRTeeCollection(e) {
444
+ return this._bindModelRTreeCollection.get(e);
445
+ }
446
+ // eslint-disable-next-line max-lines-per-function
447
+ _registerSourceChange() {
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 });
458
+ }
459
+ }
460
+ return;
461
+ }
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 });
469
+ }
470
+ }
471
+ return;
472
+ }
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 });
481
+ }
482
+ }
483
+ }
484
+ }
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 });
500
+ }
501
+ u.insert({ unitId: t, sheetId: n, id: s, range: f });
502
+ }
503
+ }
504
+ }
505
+ }));
506
+ }
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)
512
+ return {
513
+ v: `#{${r.path}}`,
514
+ s: { cl: { rgb: "blue" } }
515
+ };
516
+ if (d === g.Object)
517
+ return {
518
+ v: `[${r.path}]`,
519
+ s: { cl: { rgb: "blue" } }
520
+ };
521
+ }
522
+ }
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: "" };
531
+ }
532
+ }
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: "" };
542
+ }
543
+ }
544
+ }
545
+ }
546
+ _registerInterceptor() {
547
+ this.disposeWithMe(this._sheetInterceptorService.intercept(re.CELL_CONTENT, {
548
+ effect: P.Value | P.Style,
549
+ priority: 102,
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 });
556
+ }
557
+ return n(e);
558
+ }
559
+ }));
560
+ }
561
+ dispose() {
562
+ this._bindModelRTreeCollection.clear();
563
+ }
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;
578
+ }
579
+ onStarting() {
580
+ [
581
+ [N],
582
+ [T],
583
+ [R]
584
+ ].forEach((i) => this._injector.add(i));
585
+ }
586
+ onReady() {
587
+ Z(this._injector, [
588
+ [N],
589
+ [T],
590
+ [R]
591
+ ]);
592
+ }
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);
598
+ export {
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
606
+ };
@@ -0,0 +1,39 @@
1
+ import { ICellBindingJSON, ICellBindingNode, ICellBindingNodeParam, BindingSourceChangeTypeEnum } from '../types';
2
+ import { Disposable, IUniverInstanceService } from '@univerjs/core';
3
+ import { SheetInterceptorService, SheetsSelectionsService } from '@univerjs/sheets';
4
+ import { SheetBindingModel } from '../model/binding-model';
5
+ interface IBindingNodeInfo {
6
+ unitId: string;
7
+ subunitId: string;
8
+ sourceId: string;
9
+ nodeId: string;
10
+ row: number;
11
+ column: number;
12
+ }
13
+ export declare class SheetsBindingManager extends Disposable {
14
+ private readonly _univerInstanceService;
15
+ private readonly _sheetInterceptorService;
16
+ private readonly _sheetsSelectionsService;
17
+ modelMap: Map<string, Map<string, SheetBindingModel>>;
18
+ private _cellBindInfoUpdate$;
19
+ cellBindInfoUpdate$: import('rxjs').Observable<IBindingNodeInfo & {
20
+ changeType: BindingSourceChangeTypeEnum;
21
+ oldSourceId?: string;
22
+ containHeader?: boolean;
23
+ oldNodeContainHeader?: boolean;
24
+ }>;
25
+ constructor(_univerInstanceService: IUniverInstanceService, _sheetInterceptorService: SheetInterceptorService, _sheetsSelectionsService: SheetsSelectionsService);
26
+ private _initRemoveCommand;
27
+ getBindingModelBySourceId(sourceId: string): IBindingNodeInfo[];
28
+ addModel(unitId: string, subunitId: string, model: SheetBindingModel): void;
29
+ getModel(unitId: string, subunitId: string): SheetBindingModel | undefined;
30
+ setBindingNode(unitId: string, subunitId: string, node: ICellBindingNodeParam): void;
31
+ removeBindingNode(unitId: string, subunitId: string, row: number, column: number): void;
32
+ getBindingNode(unitId: string, subunitId: string, row: number, column: number): ICellBindingNode | undefined;
33
+ getBindingNodeById(unitId: string, subunitId: string, nodeId: string): ICellBindingNode | undefined;
34
+ createModel(unitId: string, subunitId: string, json?: ICellBindingNode[]): SheetBindingModel;
35
+ toJSON(unitId: string): ICellBindingJSON;
36
+ fromJSON(unitId: string, json: ICellBindingJSON): void;
37
+ dispose(): void;
38
+ }
39
+ export {};
@@ -0,0 +1,18 @@
1
+ import { ISourceEvent, ISourceJSON, DataBindingNodeTypeEnum } from '../types';
2
+ import { Disposable } from '@univerjs/core';
3
+ import { SourceModelBase } from '../model/source-model';
4
+ export declare class SheetsSourceManager extends Disposable {
5
+ sourceMap: Map<string, Map<string, SourceModelBase>>;
6
+ private _sourceDataUpdate$;
7
+ sourceDataUpdate$: import('rxjs').Observable<ISourceEvent>;
8
+ constructor();
9
+ private _ensureUnitMap;
10
+ private _getUnitMap;
11
+ getSource(unitId: string, id: string): SourceModelBase | undefined;
12
+ createSource(unitId: string, type: DataBindingNodeTypeEnum, isListObject?: boolean, id?: string): SourceModelBase;
13
+ updateSourceData(unitId: string, idOrInstance: string | SourceModelBase, data: any): void;
14
+ removeSource(unitId: string, id: string): void;
15
+ toJSON(unitId: string): ISourceJSON[];
16
+ fromJSON(unitId: string, sources: ISourceJSON[]): void;
17
+ dispose(): void;
18
+ }
@@ -0,0 +1,15 @@
1
+ import { BindModeEnum, DataBindingNodeTypeEnum } from '@univerjs/sheets-source-binding';
2
+ export interface ISourceBindingEnumMixin {
3
+ /**
4
+ * Represents the type of data binding node.{@link DataBindingNodeTypeEnum}
5
+ */
6
+ DataBindingNodeTypeEnum: typeof DataBindingNodeTypeEnum;
7
+ /**
8
+ * Represents the type of data binding node. {@link BindModeEnum}
9
+ */
10
+ BindModeEnum: typeof BindModeEnum;
11
+ }
12
+ declare module '@univerjs/core' {
13
+ interface FEnum extends ISourceBindingEnumMixin {
14
+ }
15
+ }