@univerjs/sheets-source-binding 0.5.4-nightly.202501191605 → 0.5.5-experimental.20250122-3362a4a

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