@univerjs/sheets-source-binding 0.5.4-nightly.202501160647 → 0.5.4-nightly.202501160704

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