@univerjs/sheets-hyper-link 0.5.4 → 0.5.5-experimental.20250123-34738ff

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,749 +1,750 @@
1
- var Ae = Object.defineProperty;
2
- var We = (s, e, t) => e in s ? Ae(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
- var w = (s, e, t) => We(s, typeof e != "symbol" ? e + "" : e, t);
4
- import { Disposable as V, ObjectMatrix as q, UniverInstanceType as v, IUniverInstanceService as E, CommandType as L, CustomRangeType as b, Inject as M, ICommandService as P, sequenceExecuteAsync as Re, isValidRange as Se, toDisposable as Be, DisposableCollection as je, Rectangle as Fe, Range as Ke, Tools as oe, BuildTextUtils as Z, generateRandomId as de, TextX as ce, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as Ye, IResourceManagerService as Ge, IUndoRedoService as Ie, CellValueType as ve, sequenceExecute as ze, getBodySlice as Ne, LocaleService as Je, DependentOn as Xe, Injector as qe, Plugin as Ze, merge as Qe, registerDependencies as et, touchDependencies as tt, IConfigService as nt } from "@univerjs/core";
5
- import { Subject as rt } from "rxjs";
6
- import { getSheetCommandTarget as j, RefRangeService as Oe, SheetsSelectionsService as ke, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as st, handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests as it, SheetInterceptorService as le, RemoveSheetCommand as at, handleDefaultRangeChangeWithEffectRefCommands as ot, SetRangeValuesMutation as H, SetRangeValuesCommand as dt, ClearSelectionContentCommand as ct, ClearSelectionAllCommand as lt, ClearSelectionFormatCommand as ut, AFTER_CELL_EDIT as pt, SetRangeValuesUndoMutationFactory as Me, UniverSheetsPlugin as ht } from "@univerjs/sheets";
7
- import { deserializeRangeWithSheet as Ce, serializeRange as B, serializeRangeWithSheet as gt, IDefinedNamesService as ft } from "@univerjs/engine-formula";
8
- import { addCustomRangeBySelectionFactory as _t, deleteCustomRangeFactory as mt, replaceSelectionFactory as De } from "@univerjs/docs";
9
- var yt = Object.defineProperty, Rt = Object.getOwnPropertyDescriptor, St = (s, e, t, n) => {
10
- for (var r = n > 1 ? void 0 : n ? Rt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
11
- (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
12
- return n && r && yt(e, t, r), r;
13
- }, It = (s, e) => (t, n) => e(t, n, s);
14
- let I = class extends V {
15
- constructor(e) {
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 { Disposable, ObjectMatrix, UniverInstanceType, IUniverInstanceService, CommandType, CustomRangeType, Inject, ICommandService, sequenceExecuteAsync, isValidRange, toDisposable, DisposableCollection, Rectangle, Range, Tools, BuildTextUtils, generateRandomId, TextX, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, IResourceManagerService, IUndoRedoService, CellValueType, sequenceExecute, getBodySlice, LocaleService, DependentOn, Injector, Plugin, merge, registerDependencies, touchDependencies, IConfigService } from "@univerjs/core";
6
+ import { Subject } from "rxjs";
7
+ import { getSheetCommandTarget, RefRangeService, SheetsSelectionsService, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests, handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests, SheetInterceptorService, RemoveSheetCommand, handleDefaultRangeChangeWithEffectRefCommands, SetRangeValuesMutation, SetRangeValuesCommand, ClearSelectionContentCommand, ClearSelectionAllCommand, ClearSelectionFormatCommand, AFTER_CELL_EDIT, SetRangeValuesUndoMutationFactory, UniverSheetsPlugin } from "@univerjs/sheets";
8
+ import { deserializeRangeWithSheet, serializeRange, serializeRangeWithSheet, IDefinedNamesService } from "@univerjs/engine-formula";
9
+ import { addCustomRangeBySelectionFactory, deleteCustomRangeFactory, replaceSelectionFactory } from "@univerjs/docs";
10
+ var __defProp$8 = Object.defineProperty, __getOwnPropDesc$8 = Object.getOwnPropertyDescriptor, __decorateClass$8 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
11
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$8(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
12
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
13
+ return kind && result && __defProp$8(target, key, result), result;
14
+ }, "__decorateClass$8"), __decorateParam$8 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$8"), _a;
15
+ let HyperLinkModel = (_a = class extends Disposable {
16
+ constructor(_univerInstanceService) {
16
17
  super();
17
- w(this, "_linkUpdate$", new rt());
18
- w(this, "linkUpdate$", this._linkUpdate$.asObservable());
19
- w(this, "_linkMap", /* @__PURE__ */ new Map());
20
- w(this, "_linkPositionMap", /* @__PURE__ */ new Map());
21
- this._univerInstanceService = e, this.disposeWithMe({
22
- dispose: () => {
18
+ __publicField(this, "_linkUpdate$", new Subject());
19
+ __publicField(this, "linkUpdate$", this._linkUpdate$.asObservable());
20
+ __publicField(this, "_linkMap", /* @__PURE__ */ new Map());
21
+ __publicField(this, "_linkPositionMap", /* @__PURE__ */ new Map());
22
+ this._univerInstanceService = _univerInstanceService, this.disposeWithMe({
23
+ dispose: /* @__PURE__ */ __name(() => {
23
24
  this._linkUpdate$.complete();
24
- }
25
+ }, "dispose")
25
26
  });
26
27
  }
27
- _ensureMap(e, t) {
28
- let n = this._linkMap.get(e);
29
- n || (n = /* @__PURE__ */ new Map(), this._linkMap.set(e, n));
30
- let r = n.get(t);
31
- r || (r = new q(), n.set(t, r));
32
- let i = this._linkPositionMap.get(e);
33
- i || (i = /* @__PURE__ */ new Map(), this._linkPositionMap.set(e, i));
34
- let a = i.get(t);
35
- return a || (a = /* @__PURE__ */ new Map(), i.set(t, a)), {
36
- matrix: r,
37
- positionMap: a
28
+ _ensureMap(unitId, subUnitId) {
29
+ let unitMap = this._linkMap.get(unitId);
30
+ unitMap || (unitMap = /* @__PURE__ */ new Map(), this._linkMap.set(unitId, unitMap));
31
+ let matrix = unitMap.get(subUnitId);
32
+ matrix || (matrix = new ObjectMatrix(), unitMap.set(subUnitId, matrix));
33
+ let positionUnitMap = this._linkPositionMap.get(unitId);
34
+ positionUnitMap || (positionUnitMap = /* @__PURE__ */ new Map(), this._linkPositionMap.set(unitId, positionUnitMap));
35
+ let positionSubUnitMap = positionUnitMap.get(subUnitId);
36
+ return positionSubUnitMap || (positionSubUnitMap = /* @__PURE__ */ new Map(), positionUnitMap.set(subUnitId, positionSubUnitMap)), {
37
+ matrix,
38
+ positionMap: positionSubUnitMap
38
39
  };
39
40
  }
40
- addHyperLink(e, t, n) {
41
- const { matrix: r, positionMap: i } = this._ensureMap(e, t);
42
- return r.setValue(n.row, n.column, n), i.set(n.id, { row: n.row, column: n.column, link: n }), this._linkUpdate$.next({
43
- unitId: e,
44
- subUnitId: t,
45
- payload: n,
41
+ addHyperLink(unitId, subUnitId, link) {
42
+ const { matrix, positionMap } = this._ensureMap(unitId, subUnitId);
43
+ return matrix.setValue(link.row, link.column, link), positionMap.set(link.id, { row: link.row, column: link.column, link }), this._linkUpdate$.next({
44
+ unitId,
45
+ subUnitId,
46
+ payload: link,
46
47
  type: "add"
47
48
  }), !0;
48
49
  }
49
- updateHyperLink(e, t, n, r, i = !1) {
50
- const { matrix: a, positionMap: o } = this._ensureMap(e, t), c = o.get(n);
51
- if (!c)
50
+ updateHyperLink(unitId, subUnitId, id, payload, silent = !1) {
51
+ const { matrix, positionMap } = this._ensureMap(unitId, subUnitId), position = positionMap.get(id);
52
+ if (!position)
52
53
  return !0;
53
- const d = a.getValue(c.row, c.column);
54
- return d && (Object.assign(d, r), this._linkUpdate$.next({
55
- unitId: e,
56
- subUnitId: t,
54
+ const link = matrix.getValue(position.row, position.column);
55
+ return link && (Object.assign(link, payload), this._linkUpdate$.next({
56
+ unitId,
57
+ subUnitId,
57
58
  payload: {
58
- display: d.display,
59
- payload: d.payload
59
+ display: link.display,
60
+ payload: link.payload
60
61
  },
61
- id: n,
62
+ id,
62
63
  type: "update",
63
- silent: i
64
+ silent
64
65
  })), !0;
65
66
  }
66
- updateHyperLinkRef(e, t, n, r, i = !1) {
67
- const { matrix: a, positionMap: o } = this._ensureMap(e, t), c = o.get(n);
68
- if (!c)
67
+ updateHyperLinkRef(unitId, subUnitId, id, payload, silent = !1) {
68
+ const { matrix, positionMap } = this._ensureMap(unitId, subUnitId), position = positionMap.get(id);
69
+ if (!position)
69
70
  return !0;
70
- let d = a.getValue(c.row, c.column);
71
- return !d || d.id !== n ? d = c.link : a.realDeleteValue(c.row, c.column), Object.assign(d, r), o.set(n, { ...r, link: d }), a.setValue(r.row, r.column, d), this._linkUpdate$.next({
72
- unitId: e,
73
- subUnitId: t,
74
- payload: r,
75
- id: n,
71
+ let link = matrix.getValue(position.row, position.column);
72
+ return !link || link.id !== id ? link = position.link : matrix.realDeleteValue(position.row, position.column), Object.assign(link, payload), positionMap.set(id, { ...payload, link }), matrix.setValue(payload.row, payload.column, link), this._linkUpdate$.next({
73
+ unitId,
74
+ subUnitId,
75
+ payload,
76
+ id,
76
77
  type: "updateRef",
77
- silent: i
78
+ silent
78
79
  }), !0;
79
80
  }
80
- removeHyperLink(e, t, n) {
81
- const { matrix: r, positionMap: i } = this._ensureMap(e, t), a = i.get(n);
82
- if (!a)
81
+ removeHyperLink(unitId, subUnitId, id) {
82
+ const { matrix, positionMap } = this._ensureMap(unitId, subUnitId), position = positionMap.get(id);
83
+ if (!position)
83
84
  return !1;
84
- i.delete(n);
85
- const o = r.getValue(a.row, a.column);
86
- return o && o.id === n && r.realDeleteValue(a.row, a.column), this._linkUpdate$.next({
87
- unitId: e,
88
- subUnitId: t,
89
- payload: a.link,
85
+ positionMap.delete(id);
86
+ const link = matrix.getValue(position.row, position.column);
87
+ return link && link.id === id && matrix.realDeleteValue(position.row, position.column), this._linkUpdate$.next({
88
+ unitId,
89
+ subUnitId,
90
+ payload: position.link,
90
91
  type: "remove"
91
92
  }), !0;
92
93
  }
93
- getHyperLink(e, t, n) {
94
- const { matrix: r, positionMap: i } = this._ensureMap(e, t), a = i.get(n);
95
- if (a)
96
- return r.getValue(a.row, a.column);
94
+ getHyperLink(unitId, subUnitId, id) {
95
+ const { matrix, positionMap } = this._ensureMap(unitId, subUnitId), position = positionMap.get(id);
96
+ if (position)
97
+ return matrix.getValue(position.row, position.column);
97
98
  }
98
- getHyperLinkByLocation(e, t, n, r) {
99
- const { matrix: i } = this._ensureMap(e, t);
100
- return i.getValue(n, r);
99
+ getHyperLinkByLocation(unitId, subUnitId, row, column) {
100
+ const { matrix } = this._ensureMap(unitId, subUnitId);
101
+ return matrix.getValue(row, column);
101
102
  }
102
- getHyperLinkByLocationSync(e, t, n, r) {
103
- var l, u, h, g, p;
104
- const { matrix: i } = this._ensureMap(e, t), a = this._univerInstanceService.getUnit(e, v.UNIVER_SHEET), o = (l = a == null ? void 0 : a.getSheetBySheetId(t)) == null ? void 0 : l.getCellRaw(n, r), c = ((p = (g = o == null ? void 0 : o.v) != null ? g : (h = (u = o == null ? void 0 : o.p) == null ? void 0 : u.body) == null ? void 0 : h.dataStream.slice(0, -2)) != null ? p : "").toString(), d = i.getValue(n, r);
105
- if (d)
103
+ getHyperLinkByLocationSync(unitId, subUnitId, row, column) {
104
+ var _a10, _b, _c, _d, _e;
105
+ const { matrix } = this._ensureMap(unitId, subUnitId), workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET), cell = (_a10 = workbook == null ? void 0 : workbook.getSheetBySheetId(subUnitId)) == null ? void 0 : _a10.getCellRaw(row, column), cellValueStr = ((_e = (_d = cell == null ? void 0 : cell.v) != null ? _d : (_c = (_b = cell == null ? void 0 : cell.p) == null ? void 0 : _b.body) == null ? void 0 : _c.dataStream.slice(0, -2)) != null ? _e : "").toString(), link = matrix.getValue(row, column);
106
+ if (link)
106
107
  return {
107
- ...d,
108
- display: c
108
+ ...link,
109
+ display: cellValueStr
109
110
  };
110
111
  }
111
- getSubUnit(e, t) {
112
- const { matrix: n } = this._ensureMap(e, t), r = [];
113
- return n.forValue((i, a, o) => {
114
- o && r.push(o);
115
- }), r;
112
+ getSubUnit(unitId, subUnitId) {
113
+ const { matrix } = this._ensureMap(unitId, subUnitId), links = [];
114
+ return matrix.forValue((row, col, value) => {
115
+ value && links.push(value);
116
+ }), links;
116
117
  }
117
- getUnit(e) {
118
- const t = this._linkMap.get(e);
119
- return t ? Array.from(t.keys()).map((n) => {
120
- const r = this.getSubUnit(e, n);
118
+ getUnit(unitId) {
119
+ const unitMap = this._linkMap.get(unitId);
120
+ return unitMap ? Array.from(unitMap.keys()).map((subUnitId) => {
121
+ const links = this.getSubUnit(unitId, subUnitId);
121
122
  return {
122
- unitId: e,
123
- subUnitId: n,
124
- links: r
123
+ unitId,
124
+ subUnitId,
125
+ links
125
126
  };
126
127
  }) : [];
127
128
  }
128
- deleteUnit(e) {
129
- const t = this.getUnit(e);
130
- this._linkMap.delete(e), this._linkPositionMap.delete(e), this._linkUpdate$.next({
129
+ deleteUnit(unitId) {
130
+ const links = this.getUnit(unitId);
131
+ this._linkMap.delete(unitId), this._linkPositionMap.delete(unitId), this._linkUpdate$.next({
131
132
  type: "unload",
132
- unitId: e,
133
- unitLinks: t
133
+ unitId,
134
+ unitLinks: links
134
135
  });
135
136
  }
136
137
  getAll() {
137
- return Array.from(this._linkMap.keys()).map((t) => this.getUnit(t));
138
+ return Array.from(this._linkMap.keys()).map((unitId) => this.getUnit(unitId));
138
139
  }
139
- };
140
- I = St([
141
- It(0, E)
142
- ], I);
143
- var U = /* @__PURE__ */ ((s) => (s.SHEET = "gid", s.RANGE = "range", s.DEFINE_NAME = "rangeid", s.INVALID = "invalid", s.URL = "url", s))(U || {});
144
- const vt = "sheets-hyper-link.config", Ue = {}, O = {
145
- type: L.MUTATION,
140
+ }, __name(_a, "HyperLinkModel"), _a);
141
+ HyperLinkModel = __decorateClass$8([
142
+ __decorateParam$8(0, IUniverInstanceService)
143
+ ], HyperLinkModel);
144
+ var SheetHyperLinkType = /* @__PURE__ */ ((SheetHyperLinkType2) => (SheetHyperLinkType2.SHEET = "gid", SheetHyperLinkType2.RANGE = "range", SheetHyperLinkType2.DEFINE_NAME = "rangeid", SheetHyperLinkType2.INVALID = "invalid", SheetHyperLinkType2.URL = "url", SheetHyperLinkType2))(SheetHyperLinkType || {});
145
+ const SHEETS_HYPER_LINK_PLUGIN_CONFIG_KEY = "sheets-hyper-link.config", defaultPluginConfig = {}, AddHyperLinkMutation = {
146
+ type: CommandType.MUTATION,
146
147
  id: "sheets.mutation.add-hyper-link",
147
- handler(s, e) {
148
- if (!e)
148
+ handler(accessor, params) {
149
+ if (!params)
149
150
  return !1;
150
- const t = s.get(I), { unitId: n, subUnitId: r, link: i } = e;
151
- return t.addHyperLink(n, r, i);
151
+ const model = accessor.get(HyperLinkModel), { unitId, subUnitId, link } = params;
152
+ return model.addHyperLink(unitId, subUnitId, link);
152
153
  }
153
- }, k = {
154
- type: L.MUTATION,
154
+ }, RemoveHyperLinkMutation = {
155
+ type: CommandType.MUTATION,
155
156
  id: "sheets.mutation.remove-hyper-link",
156
- handler(s, e) {
157
- if (!e)
157
+ handler(accessor, params) {
158
+ if (!params)
158
159
  return !1;
159
- const t = s.get(I), { unitId: n, subUnitId: r, id: i } = e;
160
- return t.removeHyperLink(n, r, i);
160
+ const model = accessor.get(HyperLinkModel), { unitId, subUnitId, id } = params;
161
+ return model.removeHyperLink(unitId, subUnitId, id);
161
162
  }
162
- }, _e = {
163
- type: L.MUTATION,
163
+ }, UpdateHyperLinkMutation = {
164
+ type: CommandType.MUTATION,
164
165
  id: "sheets.mutation.update-hyper-link",
165
- handler(s, e) {
166
- if (!e)
166
+ handler(accessor, params) {
167
+ if (!params)
167
168
  return !1;
168
- const t = s.get(I), { unitId: n, subUnitId: r, payload: i, id: a } = e;
169
- return t.updateHyperLink(n, r, a, i, !1);
169
+ const model = accessor.get(HyperLinkModel), { unitId, subUnitId, payload, id } = params;
170
+ return model.updateHyperLink(unitId, subUnitId, id, payload, !1);
170
171
  }
171
- }, me = {
172
- type: L.MUTATION,
172
+ }, UpdateHyperLinkRefMutation = {
173
+ type: CommandType.MUTATION,
173
174
  id: "sheets.mutation.update-hyper-link-ref",
174
- handler(s, e) {
175
- if (!e)
175
+ handler(accessor, params) {
176
+ if (!params)
176
177
  return !1;
177
- const t = s.get(I), { unitId: n, subUnitId: r, id: i, row: a, column: o, silent: c } = e;
178
- return t.updateHyperLinkRef(n, r, i, { row: a, column: o }, c);
178
+ const model = accessor.get(HyperLinkModel), { unitId, subUnitId, id, row, column, silent } = params;
179
+ return model.updateHyperLinkRef(unitId, subUnitId, id, { row, column }, silent);
179
180
  }
180
- }, X = {
181
- type: L.MUTATION,
181
+ }, UpdateRichHyperLinkMutation = {
182
+ type: CommandType.MUTATION,
182
183
  id: "sheets.mutation.update-rich-hyper-link",
183
- handler(s, e) {
184
- var g, p, f;
185
- if (!e)
184
+ handler(accessor, params) {
185
+ var _a10, _b, _c;
186
+ if (!params)
186
187
  return !1;
187
- const { unitId: t, subUnitId: n, row: r, col: i, id: a, url: o } = e, c = s.get(E), d = j(c, { unitId: t, subUnitId: n });
188
- if (!d)
188
+ const { unitId, subUnitId, row, col, id, url } = params, univerInstanceService = accessor.get(IUniverInstanceService), sheetTarget = getSheetCommandTarget(univerInstanceService, { unitId, subUnitId });
189
+ if (!sheetTarget)
189
190
  return !1;
190
- const { worksheet: l } = d, u = l.getCellRaw(r, i), h = (f = (p = (g = u == null ? void 0 : u.p) == null ? void 0 : g.body) == null ? void 0 : p.customRanges) == null ? void 0 : f.find((_) => _.rangeType === b.HYPERLINK && _.rangeId === a);
191
- return h && (h.properties.url = o), !0;
191
+ const { worksheet } = sheetTarget, cell = worksheet.getCellRaw(row, col), link = (_c = (_b = (_a10 = cell == null ? void 0 : cell.p) == null ? void 0 : _a10.body) == null ? void 0 : _b.customRanges) == null ? void 0 : _c.find((range) => range.rangeType === CustomRangeType.HYPERLINK && range.rangeId === id);
192
+ return link && (link.properties.url = url), !0;
192
193
  }
193
- }, He = "SHEET_HYPER_LINK_PLUGIN", Q = "err";
194
- var Mt = Object.defineProperty, Ct = Object.getOwnPropertyDescriptor, wt = (s, e, t, n) => {
195
- for (var r = n > 1 ? void 0 : n ? Ct(e, t) : e, i = s.length - 1, a; i >= 0; i--)
196
- (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
197
- return n && r && Mt(e, t, r), r;
198
- }, z = (s, e) => (t, n) => e(t, n, s);
199
- let ee = class extends V {
200
- constructor(e, t, n, r) {
194
+ }, SHEET_HYPER_LINK_PLUGIN = "SHEET_HYPER_LINK_PLUGIN", ERROR_RANGE = "err";
195
+ var __defProp$7 = Object.defineProperty, __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor, __decorateClass$7 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
196
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
197
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
198
+ return kind && result && __defProp$7(target, key, result), result;
199
+ }, "__decorateClass$7"), __decorateParam$7 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$7"), _a2;
200
+ let SheetsHyperLinkRefRangeController = (_a2 = class extends Disposable {
201
+ constructor(_refRangeService, _hyperLinkModel, _selectionManagerService, _commandService) {
201
202
  super();
202
- w(this, "_disposableMap", /* @__PURE__ */ new Map());
203
- w(this, "_watchDisposableMap", /* @__PURE__ */ new Map());
204
- w(this, "_rangeDisableMap", /* @__PURE__ */ new Map());
205
- w(this, "_rangeWatcherMap", /* @__PURE__ */ new Map());
206
- w(this, "_handlePositionChange", (e, t, n, r, i) => {
207
- const a = {
208
- startColumn: n.column,
209
- endColumn: n.column,
210
- startRow: n.row,
211
- endRow: n.row
203
+ __publicField(this, "_disposableMap", /* @__PURE__ */ new Map());
204
+ __publicField(this, "_watchDisposableMap", /* @__PURE__ */ new Map());
205
+ __publicField(this, "_rangeDisableMap", /* @__PURE__ */ new Map());
206
+ __publicField(this, "_rangeWatcherMap", /* @__PURE__ */ new Map());
207
+ __publicField(this, "_handlePositionChange", /* @__PURE__ */ __name((unitId, subUnitId, link, resultRange, silent) => {
208
+ const oldRange = {
209
+ startColumn: link.column,
210
+ endColumn: link.column,
211
+ startRow: link.row,
212
+ endRow: link.row
212
213
  };
213
- return r ? {
214
+ return resultRange ? {
214
215
  redos: [{
215
- id: me.id,
216
+ id: UpdateHyperLinkRefMutation.id,
216
217
  params: {
217
- unitId: e,
218
- subUnitId: t,
219
- id: n.id,
220
- row: r.startRow,
221
- column: r.startColumn,
222
- silent: i
218
+ unitId,
219
+ subUnitId,
220
+ id: link.id,
221
+ row: resultRange.startRow,
222
+ column: resultRange.startColumn,
223
+ silent
223
224
  }
224
225
  }],
225
226
  undos: [{
226
- id: me.id,
227
+ id: UpdateHyperLinkRefMutation.id,
227
228
  params: {
228
- unitId: e,
229
- subUnitId: t,
230
- id: n.id,
231
- row: a.startRow,
232
- column: a.startColumn,
233
- silent: i
229
+ unitId,
230
+ subUnitId,
231
+ id: link.id,
232
+ row: oldRange.startRow,
233
+ column: oldRange.startColumn,
234
+ silent
234
235
  }
235
236
  }]
236
237
  } : {
237
238
  redos: [{
238
- id: k.id,
239
+ id: RemoveHyperLinkMutation.id,
239
240
  params: {
240
- unitId: e,
241
- subUnitId: t,
242
- id: n.id
241
+ unitId,
242
+ subUnitId,
243
+ id: link.id
243
244
  }
244
245
  }],
245
246
  undos: [{
246
- id: O.id,
247
+ id: AddHyperLinkMutation.id,
247
248
  params: {
248
- unitId: e,
249
- subUnitId: t,
250
- link: n
249
+ unitId,
250
+ subUnitId,
251
+ link
251
252
  }
252
253
  }]
253
254
  };
254
- });
255
- this._refRangeService = e, this._hyperLinkModel = t, this._selectionManagerService = n, this._commandService = r, this._initData(), this._initRefRange();
255
+ }, "_handlePositionChange"));
256
+ this._refRangeService = _refRangeService, this._hyperLinkModel = _hyperLinkModel, this._selectionManagerService = _selectionManagerService, this._commandService = _commandService, this._initData(), this._initRefRange();
256
257
  }
257
- _registerPosition(e, t, n) {
258
- const r = n.id, i = {
259
- startColumn: n.column,
260
- endColumn: n.column,
261
- startRow: n.row,
262
- endRow: n.row
263
- }, a = (o) => {
264
- const c = st(i, o, { selectionManagerService: this._selectionManagerService }), d = Array.isArray(c) ? c[0] : c;
265
- return d && d.startColumn === i.startColumn && d.startRow === i.startRow ? {
258
+ _registerPosition(unitId, subUnitId, link) {
259
+ const id = link.id, oldRange = {
260
+ startColumn: link.column,
261
+ endColumn: link.column,
262
+ startRow: link.row,
263
+ endRow: link.row
264
+ }, handleRefRangeChange = /* @__PURE__ */ __name((commandInfo) => {
265
+ const resultRanges = handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(oldRange, commandInfo, { selectionManagerService: this._selectionManagerService }), resultRange = Array.isArray(resultRanges) ? resultRanges[0] : resultRanges;
266
+ return resultRange && resultRange.startColumn === oldRange.startColumn && resultRange.startRow === oldRange.startRow ? {
266
267
  undos: [],
267
268
  redos: []
268
- } : this._handlePositionChange(e, t, n, d, !1);
269
- };
270
- this._disposableMap.set(r, this._refRangeService.registerRefRange(i, a, e, t));
269
+ } : this._handlePositionChange(unitId, subUnitId, link, resultRange, !1);
270
+ }, "handleRefRangeChange");
271
+ this._disposableMap.set(id, this._refRangeService.registerRefRange(oldRange, handleRefRangeChange, unitId, subUnitId));
271
272
  }
272
- _watchPosition(e, t, n) {
273
- const r = n.id, i = {
274
- startColumn: n.column,
275
- endColumn: n.column,
276
- startRow: n.row,
277
- endRow: n.row
273
+ _watchPosition(unitId, subUnitId, link) {
274
+ const id = link.id, oldRange = {
275
+ startColumn: link.column,
276
+ endColumn: link.column,
277
+ startRow: link.row,
278
+ endRow: link.row
278
279
  };
279
280
  this._watchDisposableMap.set(
280
- r,
281
- this._refRangeService.watchRange(e, t, i, (a, o) => {
282
- const { redos: c } = this._handlePositionChange(e, t, n, o, !0);
283
- Re(c, this._commandService, { onlyLocal: !0 });
281
+ id,
282
+ this._refRangeService.watchRange(unitId, subUnitId, oldRange, (before, after) => {
283
+ const { redos } = this._handlePositionChange(unitId, subUnitId, link, after, !0);
284
+ sequenceExecuteAsync(redos, this._commandService, { onlyLocal: !0 });
284
285
  }, !0)
285
286
  );
286
287
  }
287
- _unregisterPosition(e) {
288
- const t = this._disposableMap.get(e);
289
- t == null || t.dispose(), this._disposableMap.delete(e);
288
+ _unregisterPosition(id) {
289
+ const disposable = this._disposableMap.get(id);
290
+ disposable == null || disposable.dispose(), this._disposableMap.delete(id);
290
291
  }
291
- _unwatchPosition(e) {
292
- const t = this._watchDisposableMap.get(e);
293
- t == null || t.dispose(), this._watchDisposableMap.delete(e);
292
+ _unwatchPosition(id) {
293
+ const disposable = this._watchDisposableMap.get(id);
294
+ disposable == null || disposable.dispose(), this._watchDisposableMap.delete(id);
294
295
  }
295
- _registerRange(e, t, n, r = !1) {
296
- var i, a, o;
297
- if (n.startsWith("#")) {
298
- const c = new URLSearchParams(n.slice(1)), d = {
299
- gid: (i = c.get("gid")) != null ? i : "",
300
- range: (a = c.get("range")) != null ? a : "",
301
- rangeid: (o = c.get("rangeid")) != null ? o : ""
296
+ _registerRange(unitId, id, payload, silent = !1) {
297
+ var _a10, _b, _c;
298
+ if (payload.startsWith("#")) {
299
+ const search = new URLSearchParams(payload.slice(1)), searchObj = {
300
+ gid: (_a10 = search.get("gid")) != null ? _a10 : "",
301
+ range: (_b = search.get("range")) != null ? _b : "",
302
+ rangeid: (_c = search.get("rangeid")) != null ? _c : ""
302
303
  };
303
- if (d.range && d.gid) {
304
- const l = d.gid, u = Ce(d.range).range;
305
- if (Se(u) && d.range !== Q) {
306
- const h = (g) => {
307
- const p = it(u, g, { selectionManagerService: this._selectionManagerService });
308
- return p && B(p) === B(u) ? {
304
+ if (searchObj.range && searchObj.gid) {
305
+ const subUnitId = searchObj.gid, range = deserializeRangeWithSheet(searchObj.range).range;
306
+ if (isValidRange(range) && searchObj.range !== ERROR_RANGE) {
307
+ const handleRangeChange = /* @__PURE__ */ __name((commandInfo) => {
308
+ const resultRange = handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(range, commandInfo, { selectionManagerService: this._selectionManagerService });
309
+ return resultRange && serializeRange(resultRange) === serializeRange(range) ? {
309
310
  redos: [],
310
311
  undos: []
311
312
  } : {
312
313
  redos: [{
313
- id: _e.id,
314
+ id: UpdateHyperLinkMutation.id,
314
315
  params: {
315
- unitId: e,
316
- subUnitId: l,
317
- id: t,
316
+ unitId,
317
+ subUnitId,
318
+ id,
318
319
  payload: {
319
- payload: `#gid=${l}&range=${p ? B(p) : "err"}`
320
+ payload: `#gid=${subUnitId}&range=${resultRange ? serializeRange(resultRange) : "err"}`
320
321
  }
321
322
  }
322
323
  }],
323
324
  undos: [{
324
- id: _e.id,
325
+ id: UpdateHyperLinkMutation.id,
325
326
  params: {
326
- unitId: e,
327
- subUnitId: l,
328
- id: t,
327
+ unitId,
328
+ subUnitId,
329
+ id,
329
330
  payload: {
330
- payload: n
331
+ payload
331
332
  }
332
333
  }
333
334
  }]
334
335
  };
335
- };
336
- this._rangeDisableMap.set(t, this._refRangeService.registerRefRange(u, h, e, l)), r || this._rangeWatcherMap.set(t, this._refRangeService.watchRange(e, l, u, (g, p) => {
337
- this._hyperLinkModel.updateHyperLink(e, l, t, {
338
- payload: `#gid=${l}&range=${p ? B(p) : "err"}`
336
+ }, "handleRangeChange");
337
+ this._rangeDisableMap.set(id, this._refRangeService.registerRefRange(range, handleRangeChange, unitId, subUnitId)), silent || this._rangeWatcherMap.set(id, this._refRangeService.watchRange(unitId, subUnitId, range, (before, after) => {
338
+ this._hyperLinkModel.updateHyperLink(unitId, subUnitId, id, {
339
+ payload: `#gid=${subUnitId}&range=${after ? serializeRange(after) : "err"}`
339
340
  }, !0);
340
341
  }, !0));
341
342
  }
342
343
  }
343
344
  }
344
345
  }
345
- _unregisterRange(e) {
346
- const t = this._rangeDisableMap.get(e);
347
- t == null || t.dispose(), this._rangeDisableMap.delete(e);
346
+ _unregisterRange(id) {
347
+ const disposable = this._rangeDisableMap.get(id);
348
+ disposable == null || disposable.dispose(), this._rangeDisableMap.delete(id);
348
349
  }
349
- _unwatchRange(e) {
350
- const t = this._rangeWatcherMap.get(e);
351
- t == null || t.dispose(), this._rangeWatcherMap.delete(e);
350
+ _unwatchRange(id) {
351
+ const disposable = this._rangeWatcherMap.get(id);
352
+ disposable == null || disposable.dispose(), this._rangeWatcherMap.delete(id);
352
353
  }
353
354
  _initData() {
354
- this._hyperLinkModel.getAll().forEach((t) => {
355
- t.forEach((n) => {
356
- const { unitId: r, subUnitId: i, links: a } = n;
357
- a.forEach((o) => {
358
- this._registerPosition(r, i, o), this._watchPosition(r, i, o), this._registerRange(r, o.id, o.payload);
355
+ this._hyperLinkModel.getAll().forEach((unitData) => {
356
+ unitData.forEach((subUnitData) => {
357
+ const { unitId, subUnitId, links } = subUnitData;
358
+ links.forEach((link) => {
359
+ this._registerPosition(unitId, subUnitId, link), this._watchPosition(unitId, subUnitId, link), this._registerRange(unitId, link.id, link.payload);
359
360
  });
360
361
  });
361
362
  });
362
363
  }
363
364
  _initRefRange() {
364
365
  this.disposeWithMe(
365
- this._hyperLinkModel.linkUpdate$.subscribe((e) => {
366
- switch (e.type) {
366
+ this._hyperLinkModel.linkUpdate$.subscribe((option) => {
367
+ switch (option.type) {
367
368
  case "add": {
368
- this._registerPosition(e.unitId, e.subUnitId, e.payload), this._watchPosition(e.unitId, e.subUnitId, e.payload), this._registerRange(e.unitId, e.payload.id, e.payload.payload);
369
+ this._registerPosition(option.unitId, option.subUnitId, option.payload), this._watchPosition(option.unitId, option.subUnitId, option.payload), this._registerRange(option.unitId, option.payload.id, option.payload.payload);
369
370
  break;
370
371
  }
371
372
  case "remove": {
372
- this._unregisterPosition(e.payload.id), this._unwatchPosition(e.payload.id), this._unregisterRange(e.payload.id), this._unwatchRange(e.payload.id);
373
+ this._unregisterPosition(option.payload.id), this._unwatchPosition(option.payload.id), this._unregisterRange(option.payload.id), this._unwatchRange(option.payload.id);
373
374
  break;
374
375
  }
375
376
  case "updateRef": {
376
- const { unitId: t, subUnitId: n, id: r, silent: i } = e, a = this._hyperLinkModel.getHyperLink(t, n, r);
377
- if (!a)
377
+ const { unitId, subUnitId, id, silent } = option, link = this._hyperLinkModel.getHyperLink(unitId, subUnitId, id);
378
+ if (!link)
378
379
  return;
379
- this._unregisterPosition(r), this._registerPosition(t, n, a), i || (this._unwatchPosition(r), this._watchPosition(t, n, a));
380
+ this._unregisterPosition(id), this._registerPosition(unitId, subUnitId, link), silent || (this._unwatchPosition(id), this._watchPosition(unitId, subUnitId, link));
380
381
  break;
381
382
  }
382
383
  case "unload": {
383
- const { unitLinks: t } = e;
384
- t.forEach((n) => {
385
- const { links: r } = n;
386
- r.forEach((i) => {
387
- this._unregisterPosition(i.id), this._unwatchPosition(i.id), this._unregisterRange(i.id), this._unwatchRange(i.id);
384
+ const { unitLinks } = option;
385
+ unitLinks.forEach((subUnitData) => {
386
+ const { links } = subUnitData;
387
+ links.forEach((link) => {
388
+ this._unregisterPosition(link.id), this._unwatchPosition(link.id), this._unregisterRange(link.id), this._unwatchRange(link.id);
388
389
  });
389
390
  });
390
391
  break;
391
392
  }
392
393
  case "update": {
393
- e.silent || this._unwatchRange(e.id), this._unregisterRange(e.id), this._registerRange(e.unitId, e.id, e.payload.payload, e.silent);
394
+ option.silent || this._unwatchRange(option.id), this._unregisterRange(option.id), this._registerRange(option.unitId, option.id, option.payload.payload, option.silent);
394
395
  break;
395
396
  }
396
397
  }
397
398
  })
398
- ), this.disposeWithMe(Be(() => {
399
- this._disposableMap.forEach((e) => {
400
- e.dispose();
399
+ ), this.disposeWithMe(toDisposable(() => {
400
+ this._disposableMap.forEach((item) => {
401
+ item.dispose();
401
402
  }), this._disposableMap.clear();
402
403
  }));
403
404
  }
404
- };
405
- ee = wt([
406
- z(0, M(Oe)),
407
- z(1, M(I)),
408
- z(2, M(ke)),
409
- z(3, P)
410
- ], ee);
411
- var Et = Object.defineProperty, Lt = Object.getOwnPropertyDescriptor, Ut = (s, e, t, n) => {
412
- for (var r = n > 1 ? void 0 : n ? Lt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
413
- (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
414
- return n && r && Et(e, t, r), r;
415
- }, he = (s, e) => (t, n) => e(t, n, s);
416
- let te = class extends V {
417
- constructor(s, e, t) {
418
- super(), this._sheetInterceptorService = s, this._univerInstanceService = e, this._hyperLinkModel = t, this._initSheetChange();
405
+ }, __name(_a2, "SheetsHyperLinkRefRangeController"), _a2);
406
+ SheetsHyperLinkRefRangeController = __decorateClass$7([
407
+ __decorateParam$7(0, Inject(RefRangeService)),
408
+ __decorateParam$7(1, Inject(HyperLinkModel)),
409
+ __decorateParam$7(2, Inject(SheetsSelectionsService)),
410
+ __decorateParam$7(3, ICommandService)
411
+ ], SheetsHyperLinkRefRangeController);
412
+ var __defProp$6 = Object.defineProperty, __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor, __decorateClass$6 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
413
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
414
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
415
+ return kind && result && __defProp$6(target, key, result), result;
416
+ }, "__decorateClass$6"), __decorateParam$6 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$6"), _a3;
417
+ let SheetsHyperLinkRemoveSheetController = (_a3 = class extends Disposable {
418
+ constructor(_sheetInterceptorService, _univerInstanceService, _hyperLinkModel) {
419
+ super(), this._sheetInterceptorService = _sheetInterceptorService, this._univerInstanceService = _univerInstanceService, this._hyperLinkModel = _hyperLinkModel, this._initSheetChange();
419
420
  }
420
421
  _initSheetChange() {
421
422
  this.disposeWithMe(
422
423
  this._sheetInterceptorService.interceptCommand({
423
- getMutations: (s) => {
424
- var e;
425
- if (s.id === at.id) {
426
- const t = s.params, n = t.unitId ? this._univerInstanceService.getUnit(t.unitId) : this._univerInstanceService.getCurrentUnitForType(v.UNIVER_SHEET);
427
- if (!n)
424
+ getMutations: /* @__PURE__ */ __name((commandInfo) => {
425
+ var _a10;
426
+ if (commandInfo.id === RemoveSheetCommand.id) {
427
+ const params = commandInfo.params, workbook = params.unitId ? this._univerInstanceService.getUnit(params.unitId) : this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
428
+ if (!workbook)
428
429
  return { redos: [], undos: [] };
429
- const r = n.getUnitId(), i = t.subUnitId || ((e = n.getActiveSheet()) == null ? void 0 : e.getSheetId());
430
- if (!i)
430
+ const unitId = workbook.getUnitId(), subUnitId = params.subUnitId || ((_a10 = workbook.getActiveSheet()) == null ? void 0 : _a10.getSheetId());
431
+ if (!subUnitId)
431
432
  return { redos: [], undos: [] };
432
- const a = this._hyperLinkModel.getSubUnit(r, i), o = a.map((d) => ({
433
- id: k.id,
433
+ const links = this._hyperLinkModel.getSubUnit(unitId, subUnitId), redos = links.map((link) => ({
434
+ id: RemoveHyperLinkMutation.id,
434
435
  params: {
435
- unitId: r,
436
- subUnitId: i,
437
- id: d.id
436
+ unitId,
437
+ subUnitId,
438
+ id: link.id
438
439
  }
439
- })), c = a.map((d) => ({
440
- id: O.id,
440
+ })), undos = links.map((link) => ({
441
+ id: AddHyperLinkMutation.id,
441
442
  params: {
442
- unitId: r,
443
- subUnitId: i,
444
- link: d
443
+ unitId,
444
+ subUnitId,
445
+ link
445
446
  }
446
447
  }));
447
- return { redos: o, undos: c };
448
+ return { redos, undos };
448
449
  }
449
450
  return { redos: [], undos: [] };
450
- }
451
+ }, "getMutations")
451
452
  })
452
453
  );
453
454
  }
454
- };
455
- te = Ut([
456
- he(0, M(le)),
457
- he(1, E),
458
- he(2, M(I))
459
- ], te);
460
- var bt = Object.defineProperty, Pt = Object.getOwnPropertyDescriptor, Nt = (s, e, t, n) => {
461
- for (var r = n > 1 ? void 0 : n ? Pt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
462
- (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
463
- return n && r && bt(e, t, r), r;
464
- }, ge = (s, e) => (t, n) => e(t, n, s);
465
- let ne = class extends V {
466
- constructor(e, t, n) {
455
+ }, __name(_a3, "SheetsHyperLinkRemoveSheetController"), _a3);
456
+ SheetsHyperLinkRemoveSheetController = __decorateClass$6([
457
+ __decorateParam$6(0, Inject(SheetInterceptorService)),
458
+ __decorateParam$6(1, IUniverInstanceService),
459
+ __decorateParam$6(2, Inject(HyperLinkModel))
460
+ ], SheetsHyperLinkRemoveSheetController);
461
+ var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
462
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
463
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
464
+ return kind && result && __defProp$5(target, key, result), result;
465
+ }, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$5"), _a4;
466
+ let SheetsHyperLinkRichTextRefRangeController = (_a4 = class extends Disposable {
467
+ constructor(_commandService, _univerInstanceService, _refRangeService) {
467
468
  super();
468
- w(this, "_refRangeMap", /* @__PURE__ */ new Map());
469
- this._commandService = e, this._univerInstanceService = t, this._refRangeService = n, this._initWorkbookLoad(), this._initWorkbookUnload(), this._initSetRangesListener();
469
+ __publicField(this, "_refRangeMap", /* @__PURE__ */ new Map());
470
+ this._commandService = _commandService, this._univerInstanceService = _univerInstanceService, this._refRangeService = _refRangeService, this._initWorkbookLoad(), this._initWorkbookUnload(), this._initSetRangesListener();
470
471
  }
471
- _enusreMap(e, t) {
472
- let n = this._refRangeMap.get(e);
473
- n || (n = /* @__PURE__ */ new Map(), this._refRangeMap.set(e, n));
474
- let r = n.get(t);
475
- return r || (r = new q(), n.set(t, r)), r;
472
+ _enusreMap(unitId, subUnitId) {
473
+ let unitMap = this._refRangeMap.get(unitId);
474
+ unitMap || (unitMap = /* @__PURE__ */ new Map(), this._refRangeMap.set(unitId, unitMap));
475
+ let subUnitMap = unitMap.get(subUnitId);
476
+ return subUnitMap || (subUnitMap = new ObjectMatrix(), unitMap.set(subUnitId, subUnitMap)), subUnitMap;
476
477
  }
477
- _isLegalRangeUrl(e, t) {
478
- var r, i, a;
479
- const n = this._univerInstanceService.getUnit(e, v.UNIVER_SHEET);
480
- if (!n)
478
+ _isLegalRangeUrl(unitId, payload) {
479
+ var _a10, _b, _c;
480
+ const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
481
+ if (!workbook)
481
482
  return null;
482
- if (t && t.startsWith("#")) {
483
- const o = new URLSearchParams(t.slice(1)), c = {
484
- gid: (r = o.get("gid")) != null ? r : "",
485
- range: (i = o.get("range")) != null ? i : "",
486
- rangeid: (a = o.get("rangeid")) != null ? a : ""
483
+ if (payload && payload.startsWith("#")) {
484
+ const search = new URLSearchParams(payload.slice(1)), searchObj = {
485
+ gid: (_a10 = search.get("gid")) != null ? _a10 : "",
486
+ range: (_b = search.get("range")) != null ? _b : "",
487
+ rangeid: (_c = search.get("rangeid")) != null ? _c : ""
487
488
  };
488
- if (c.range && c.gid) {
489
- const d = c.gid, l = n.getSheetBySheetId(d);
490
- if (!l)
489
+ if (searchObj.range && searchObj.gid) {
490
+ const subUnitId = searchObj.gid, worksheet = workbook.getSheetBySheetId(subUnitId);
491
+ if (!worksheet)
491
492
  return null;
492
- const u = Ce(c.range).range;
493
- if (Se(u, l) && c.range !== Q)
493
+ const range = deserializeRangeWithSheet(searchObj.range).range;
494
+ if (isValidRange(range, worksheet) && searchObj.range !== ERROR_RANGE)
494
495
  return {
495
- range: u,
496
- worksheet: l
496
+ range,
497
+ worksheet
497
498
  };
498
499
  }
499
500
  }
500
501
  return null;
501
502
  }
502
- _registerRange(e, t, n, r, i) {
503
- var o, c, d, l;
504
- const a = this._enusreMap(e, t);
505
- if ((c = (o = i.body) == null ? void 0 : o.customRanges) != null && c.some((u) => {
506
- var h;
507
- return u.rangeType === b.HYPERLINK && this._isLegalRangeUrl(e, (h = u.properties) == null ? void 0 : h.url);
503
+ _registerRange(unitId, subUnitId, row, col, p) {
504
+ var _a10, _b, _c, _d;
505
+ const map = this._enusreMap(unitId, subUnitId);
506
+ if ((_b = (_a10 = p.body) == null ? void 0 : _a10.customRanges) != null && _b.some((customRange) => {
507
+ var _a11;
508
+ return customRange.rangeType === CustomRangeType.HYPERLINK && this._isLegalRangeUrl(unitId, (_a11 = customRange.properties) == null ? void 0 : _a11.url);
508
509
  })) {
509
- const u = new je();
510
- let h = !1;
511
- (l = (d = i.body) == null ? void 0 : d.customRanges) == null || l.forEach((g) => {
512
- var p;
513
- if (g.rangeType === b.HYPERLINK) {
514
- const f = (p = g.properties) == null ? void 0 : p.url, _ = this._isLegalRangeUrl(e, f);
515
- if (_) {
516
- const { range: m, worksheet: C } = _;
517
- h = !0, u.add(
510
+ const disposableCollection = new DisposableCollection();
511
+ let hasWatch = !1;
512
+ (_d = (_c = p.body) == null ? void 0 : _c.customRanges) == null || _d.forEach((customRange) => {
513
+ var _a11;
514
+ if (customRange.rangeType === CustomRangeType.HYPERLINK) {
515
+ const payload = (_a11 = customRange.properties) == null ? void 0 : _a11.url, rangeInfo = this._isLegalRangeUrl(unitId, payload);
516
+ if (rangeInfo) {
517
+ const { range, worksheet } = rangeInfo;
518
+ hasWatch = !0, disposableCollection.add(
518
519
  this._refRangeService.registerRefRange(
519
- m,
520
- (y) => {
521
- const R = ot(m, y);
522
- return R && Fe.equals(R, m) ? {
520
+ range,
521
+ (commandInfo) => {
522
+ const newRange = handleDefaultRangeChangeWithEffectRefCommands(range, commandInfo);
523
+ return newRange && Rectangle.equals(newRange, range) ? {
523
524
  preRedos: [],
524
525
  preUndos: [],
525
526
  redos: [],
526
527
  undos: []
527
528
  } : {
528
529
  preRedos: [{
529
- id: X.id,
530
+ id: UpdateRichHyperLinkMutation.id,
530
531
  params: {
531
- unitId: e,
532
- subUnitId: t,
533
- row: n,
534
- col: r,
535
- id: g.rangeId,
536
- url: `#gid=${t}&range=${R ? B(R) : Q}`
532
+ unitId,
533
+ subUnitId,
534
+ row,
535
+ col,
536
+ id: customRange.rangeId,
537
+ url: `#gid=${subUnitId}&range=${newRange ? serializeRange(newRange) : ERROR_RANGE}`
537
538
  }
538
539
  }],
539
540
  undos: [{
540
- id: X.id,
541
+ id: UpdateRichHyperLinkMutation.id,
541
542
  params: {
542
- unitId: e,
543
- subUnitId: t,
544
- row: n,
545
- col: r,
546
- id: g.rangeId,
547
- url: f
543
+ unitId,
544
+ subUnitId,
545
+ row,
546
+ col,
547
+ id: customRange.rangeId,
548
+ url: payload
548
549
  }
549
550
  }],
550
551
  redos: []
551
552
  };
552
553
  },
553
- C.getUnitId(),
554
- C.getSheetId()
554
+ worksheet.getUnitId(),
555
+ worksheet.getSheetId()
555
556
  )
556
557
  );
557
558
  }
558
559
  }
559
- }), h && a.setValue(n, r, u);
560
+ }), hasWatch && map.setValue(row, col, disposableCollection);
560
561
  }
561
562
  }
562
563
  _initWorkbookLoad() {
563
- const e = (t) => {
564
- const n = t.getUnitId();
565
- t.getSheets().forEach((r) => {
566
- const i = r.getSheetId(), a = this._enusreMap(n, i);
567
- r.getCellMatrix().forValue((o, c, d) => {
568
- const l = a.getValue(o, c);
569
- l && l.dispose(), d && d.p && this._registerRange(n, i, o, c, d.p);
564
+ const handleWorkbook = /* @__PURE__ */ __name((workbook) => {
565
+ const unitId = workbook.getUnitId();
566
+ workbook.getSheets().forEach((sheet) => {
567
+ const subUnitId = sheet.getSheetId(), map = this._enusreMap(unitId, subUnitId);
568
+ sheet.getCellMatrix().forValue((row, col, cell) => {
569
+ const dispose = map.getValue(row, col);
570
+ dispose && dispose.dispose(), cell && cell.p && this._registerRange(unitId, subUnitId, row, col, cell.p);
570
571
  });
571
572
  });
572
- };
573
- this._univerInstanceService.getAllUnitsForType(v.UNIVER_SHEET).forEach((t) => {
574
- e(t);
573
+ }, "handleWorkbook");
574
+ this._univerInstanceService.getAllUnitsForType(UniverInstanceType.UNIVER_SHEET).forEach((workbook) => {
575
+ handleWorkbook(workbook);
575
576
  }), this.disposeWithMe(
576
- this._univerInstanceService.unitAdded$.subscribe((t) => {
577
- t.type === v.UNIVER_SHEET && e(t);
577
+ this._univerInstanceService.unitAdded$.subscribe((unit) => {
578
+ unit.type === UniverInstanceType.UNIVER_SHEET && handleWorkbook(unit);
578
579
  })
579
580
  );
580
581
  }
581
582
  _initWorkbookUnload() {
582
- this._univerInstanceService.unitDisposed$.subscribe((e) => {
583
- if (e.type === v.UNIVER_SHEET) {
584
- const t = e, n = t.getUnitId();
585
- t.getSheets().forEach((r) => {
586
- const i = r.getSheetId();
587
- this._enusreMap(n, i).forValue((o, c, d) => {
588
- d && d.dispose();
583
+ this._univerInstanceService.unitDisposed$.subscribe((unit) => {
584
+ if (unit.type === UniverInstanceType.UNIVER_SHEET) {
585
+ const workbook = unit, unitId = workbook.getUnitId();
586
+ workbook.getSheets().forEach((sheet) => {
587
+ const subUnitId = sheet.getSheetId();
588
+ this._enusreMap(unitId, subUnitId).forValue((row, col, dispose) => {
589
+ dispose && dispose.dispose();
589
590
  });
590
- }), this._refRangeMap.delete(n);
591
+ }), this._refRangeMap.delete(unitId);
591
592
  }
592
593
  });
593
594
  }
594
595
  _initSetRangesListener() {
595
596
  this.disposeWithMe(
596
- this._commandService.onCommandExecuted((e) => {
597
- if (e.id === H.id) {
598
- const t = e.params, { unitId: n, subUnitId: r, cellValue: i } = t, a = this._enusreMap(n, r);
599
- i && new q(i).forValue((o, c, d) => {
600
- const l = a.getValue(o, c);
601
- l && l.dispose(), d && d.p && this._registerRange(n, r, o, c, d.p);
597
+ this._commandService.onCommandExecuted((commandInfo) => {
598
+ if (commandInfo.id === SetRangeValuesMutation.id) {
599
+ const params = commandInfo.params, { unitId, subUnitId, cellValue } = params, map = this._enusreMap(unitId, subUnitId);
600
+ cellValue && new ObjectMatrix(cellValue).forValue((row, col, cell) => {
601
+ const dispose = map.getValue(row, col);
602
+ dispose && dispose.dispose(), cell && cell.p && this._registerRange(unitId, subUnitId, row, col, cell.p);
602
603
  });
603
604
  }
604
605
  })
605
606
  ), this.disposeWithMe(
606
- this._commandService.onCommandExecuted((e) => {
607
- if (e.id === X.id) {
608
- const t = e.params, { unitId: n, subUnitId: r, row: i, col: a } = t, o = j(this._univerInstanceService, { unitId: n, subUnitId: r }), d = this._enusreMap(n, r).getValue(i, a);
609
- if (d && d.dispose(), o) {
610
- const { worksheet: l } = o, u = l.getCellRaw(i, a);
611
- u && u.p && this._registerRange(n, r, i, a, u.p);
607
+ this._commandService.onCommandExecuted((commandInfo) => {
608
+ if (commandInfo.id === UpdateRichHyperLinkMutation.id) {
609
+ const params = commandInfo.params, { unitId, subUnitId, row, col } = params, sheetTarget = getSheetCommandTarget(this._univerInstanceService, { unitId, subUnitId }), dispose = this._enusreMap(unitId, subUnitId).getValue(row, col);
610
+ if (dispose && dispose.dispose(), sheetTarget) {
611
+ const { worksheet } = sheetTarget, cell = worksheet.getCellRaw(row, col);
612
+ cell && cell.p && this._registerRange(unitId, subUnitId, row, col, cell.p);
612
613
  }
613
614
  }
614
615
  })
615
616
  );
616
617
  }
617
- };
618
- ne = Nt([
619
- ge(0, P),
620
- ge(1, E),
621
- ge(2, M(Oe))
622
- ], ne);
623
- var Ot = Object.defineProperty, kt = Object.getOwnPropertyDescriptor, Dt = (s, e, t, n) => {
624
- for (var r = n > 1 ? void 0 : n ? kt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
625
- (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
626
- return n && r && Ot(e, t, r), r;
627
- }, J = (s, e) => (t, n) => e(t, n, s);
628
- let re = class extends V {
629
- constructor(s, e, t, n) {
630
- super(), this._sheetInterceptorService = s, this._hyperLinkModel = e, this._selectionManagerService = t, this._univerInstanceService = n, this._initCommandInterceptor(), this._initAfterEditor();
618
+ }, __name(_a4, "SheetsHyperLinkRichTextRefRangeController"), _a4);
619
+ SheetsHyperLinkRichTextRefRangeController = __decorateClass$5([
620
+ __decorateParam$5(0, ICommandService),
621
+ __decorateParam$5(1, IUniverInstanceService),
622
+ __decorateParam$5(2, Inject(RefRangeService))
623
+ ], SheetsHyperLinkRichTextRefRangeController);
624
+ var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
625
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
626
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
627
+ return kind && result && __defProp$4(target, key, result), result;
628
+ }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a5;
629
+ let SheetHyperLinkSetRangeController = (_a5 = class extends Disposable {
630
+ constructor(_sheetInterceptorService, _hyperLinkModel, _selectionManagerService, _univerInstanceService) {
631
+ super(), this._sheetInterceptorService = _sheetInterceptorService, this._hyperLinkModel = _hyperLinkModel, this._selectionManagerService = _selectionManagerService, this._univerInstanceService = _univerInstanceService, this._initCommandInterceptor(), this._initAfterEditor();
631
632
  }
632
633
  _initCommandInterceptor() {
633
634
  this._initSetRangeValuesCommandInterceptor(), this._initClearSelectionCommandInterceptor();
634
635
  }
635
636
  _initSetRangeValuesCommandInterceptor() {
636
637
  this.disposeWithMe(this._sheetInterceptorService.interceptCommand({
637
- getMutations: (s) => {
638
- if (s.id === dt.id) {
639
- const e = s.params, { unitId: t, subUnitId: n } = e, r = [], i = [];
640
- return e.cellValue && new q(e.cellValue).forValue((a, o) => {
641
- const c = this._hyperLinkModel.getHyperLinkByLocation(t, n, a, o);
642
- c && (r.push({
643
- id: k.id,
638
+ getMutations: /* @__PURE__ */ __name((command) => {
639
+ if (command.id === SetRangeValuesCommand.id) {
640
+ const params = command.params, { unitId, subUnitId } = params, redos = [], undos = [];
641
+ return params.cellValue && new ObjectMatrix(params.cellValue).forValue((row, col) => {
642
+ const link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, col);
643
+ link && (redos.push({
644
+ id: RemoveHyperLinkMutation.id,
644
645
  params: {
645
- unitId: t,
646
- subUnitId: n,
647
- id: c.id
646
+ unitId,
647
+ subUnitId,
648
+ id: link.id
648
649
  }
649
- }), i.push({
650
- id: O.id,
650
+ }), undos.push({
651
+ id: AddHyperLinkMutation.id,
651
652
  params: {
652
- unitId: t,
653
- subUnitId: n,
654
- link: c
653
+ unitId,
654
+ subUnitId,
655
+ link
655
656
  }
656
657
  }));
657
658
  }), {
658
- undos: i,
659
- redos: r
659
+ undos,
660
+ redos
660
661
  };
661
662
  }
662
663
  return {
663
664
  redos: [],
664
665
  undos: []
665
666
  };
666
- }
667
+ }, "getMutations")
667
668
  }));
668
669
  }
669
670
  _initClearSelectionCommandInterceptor() {
670
671
  this.disposeWithMe(this._sheetInterceptorService.interceptCommand({
671
- getMutations: (s) => {
672
- if (s.id === ct.id || s.id === lt.id || s.id === ut.id) {
673
- const e = [], t = [], n = this._selectionManagerService.getCurrentLastSelection(), r = j(this._univerInstanceService);
674
- if (n && r) {
675
- const { unitId: i, subUnitId: a } = r;
676
- Ke.foreach(n.range, (o, c) => {
677
- const d = this._hyperLinkModel.getHyperLinkByLocation(i, a, o, c);
678
- d && (e.push({
679
- id: k.id,
672
+ getMutations: /* @__PURE__ */ __name((command) => {
673
+ if (command.id === ClearSelectionContentCommand.id || command.id === ClearSelectionAllCommand.id || command.id === ClearSelectionFormatCommand.id) {
674
+ const redos = [], undos = [], selection = this._selectionManagerService.getCurrentLastSelection(), target = getSheetCommandTarget(this._univerInstanceService);
675
+ if (selection && target) {
676
+ const { unitId, subUnitId } = target;
677
+ Range.foreach(selection.range, (row, col) => {
678
+ const link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, col);
679
+ link && (redos.push({
680
+ id: RemoveHyperLinkMutation.id,
680
681
  params: {
681
- unitId: i,
682
- subUnitId: a,
683
- id: d.id
682
+ unitId,
683
+ subUnitId,
684
+ id: link.id
684
685
  }
685
- }), t.push({
686
- id: O.id,
686
+ }), undos.push({
687
+ id: AddHyperLinkMutation.id,
687
688
  params: {
688
- unitId: i,
689
- subUnitId: a,
690
- link: d
689
+ unitId,
690
+ subUnitId,
691
+ link
691
692
  }
692
693
  }));
693
694
  });
694
695
  }
695
696
  return {
696
- redos: e,
697
- undos: t
697
+ redos,
698
+ undos
698
699
  };
699
700
  }
700
701
  return {
701
702
  redos: [],
702
703
  undos: []
703
704
  };
704
- }
705
+ }, "getMutations")
705
706
  }));
706
707
  }
707
708
  _initAfterEditor() {
708
- this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(pt, {
709
- handler: (s, e, t) => {
710
- if (!s || s.p)
711
- return t(s);
712
- if (typeof s.v == "string" && oe.isLegalUrl(s.v) && s.v[s.v.length - 1] !== " ") {
713
- const { unitId: n, subUnitId: r } = e, i = this._univerInstanceService.getUnit(n, v.UNIVER_SHEET), a = i == null ? void 0 : i.getSheetBySheetId(r);
714
- if (!a)
715
- return t(s);
716
- const o = a.getBlankCellDocumentModel(s);
717
- if (!o.documentModel)
718
- return t(s);
719
- const c = Z.selection.replace({
709
+ this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(AFTER_CELL_EDIT, {
710
+ handler: /* @__PURE__ */ __name((cell, context, next) => {
711
+ if (!cell || cell.p)
712
+ return next(cell);
713
+ if (typeof cell.v == "string" && Tools.isLegalUrl(cell.v) && cell.v[cell.v.length - 1] !== " ") {
714
+ const { unitId, subUnitId } = context, workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET), worksheet = workbook == null ? void 0 : workbook.getSheetBySheetId(subUnitId);
715
+ if (!worksheet)
716
+ return next(cell);
717
+ const doc = worksheet.getBlankCellDocumentModel(cell);
718
+ if (!doc.documentModel)
719
+ return next(cell);
720
+ const textX = BuildTextUtils.selection.replace({
720
721
  selection: {
721
722
  startOffset: 0,
722
- endOffset: s.v.length,
723
+ endOffset: cell.v.length,
723
724
  collapsed: !1
724
725
  },
725
726
  body: {
726
- dataStream: `${s.v}`,
727
+ dataStream: `${cell.v}`,
727
728
  customRanges: [{
728
729
  startIndex: 0,
729
- endIndex: s.v.length - 1,
730
- rangeId: de(),
731
- rangeType: b.HYPERLINK,
730
+ endIndex: cell.v.length - 1,
731
+ rangeId: generateRandomId(),
732
+ rangeType: CustomRangeType.HYPERLINK,
732
733
  properties: {
733
- url: s.v
734
+ url: cell.v
734
735
  }
735
736
  }]
736
737
  },
737
- doc: o.documentModel
738
+ doc: doc.documentModel
738
739
  });
739
- if (!c)
740
- return t(s);
741
- const d = o.documentModel.getBody();
742
- return ce.apply(d, c.serialize()), t({
743
- ...s,
740
+ if (!textX)
741
+ return next(cell);
742
+ const body = doc.documentModel.getBody();
743
+ return TextX.apply(body, textX.serialize()), next({
744
+ ...cell,
744
745
  p: {
745
- id: Ye,
746
- body: d,
746
+ id: DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
747
+ body,
747
748
  documentStyle: {
748
749
  pageSize: {
749
750
  width: 1 / 0,
@@ -753,528 +754,528 @@ let re = class extends V {
753
754
  }
754
755
  });
755
756
  }
756
- return t(s);
757
- }
757
+ return next(cell);
758
+ }, "handler")
758
759
  }));
759
760
  }
760
- };
761
- re = Dt([
762
- J(0, M(le)),
763
- J(1, M(I)),
764
- J(2, M(ke)),
765
- J(3, E)
766
- ], re);
767
- var Ve = /* @__PURE__ */ ((s) => (s[s.UNIVER_UNKNOWN = 0] = "UNIVER_UNKNOWN", s[s.UNIVER_DOC = 1] = "UNIVER_DOC", s[s.UNIVER_SHEET = 2] = "UNIVER_SHEET", s[s.UNIVER_SLIDE = 3] = "UNIVER_SLIDE", s[s.UNIVER_PROJECT = 4] = "UNIVER_PROJECT", s[s.UNRECOGNIZED = -1] = "UNRECOGNIZED", s))(Ve || {}), Ht = Object.defineProperty, Vt = Object.getOwnPropertyDescriptor, $t = (s, e, t, n) => {
768
- for (var r = n > 1 ? void 0 : n ? Vt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
769
- (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
770
- return n && r && Ht(e, t, r), r;
771
- }, be = (s, e) => (t, n) => e(t, n, s);
772
- let se = class extends V {
773
- constructor(s, e) {
774
- super(), this._resourceManagerService = s, this._hyperLinkModel = e, this._initSnapshot();
761
+ }, __name(_a5, "SheetHyperLinkSetRangeController"), _a5);
762
+ SheetHyperLinkSetRangeController = __decorateClass$4([
763
+ __decorateParam$4(0, Inject(SheetInterceptorService)),
764
+ __decorateParam$4(1, Inject(HyperLinkModel)),
765
+ __decorateParam$4(2, Inject(SheetsSelectionsService)),
766
+ __decorateParam$4(3, IUniverInstanceService)
767
+ ], SheetHyperLinkSetRangeController);
768
+ var _ = /* @__PURE__ */ ((E) => (E[E.UNIVER_UNKNOWN = 0] = "UNIVER_UNKNOWN", E[E.UNIVER_DOC = 1] = "UNIVER_DOC", E[E.UNIVER_SHEET = 2] = "UNIVER_SHEET", E[E.UNIVER_SLIDE = 3] = "UNIVER_SLIDE", E[E.UNIVER_PROJECT = 4] = "UNIVER_PROJECT", E[E.UNRECOGNIZED = -1] = "UNRECOGNIZED", E))(_ || {}), __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
769
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
770
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
771
+ return kind && result && __defProp$3(target, key, result), result;
772
+ }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a6;
773
+ let SheetsHyperLinkResourceController = (_a6 = class extends Disposable {
774
+ constructor(_resourceManagerService, _hyperLinkModel) {
775
+ super(), this._resourceManagerService = _resourceManagerService, this._hyperLinkModel = _hyperLinkModel, this._initSnapshot();
775
776
  }
776
777
  _initSnapshot() {
777
- const s = (t) => {
778
- const n = this._hyperLinkModel.getUnit(t), r = {};
779
- return n ? (n.forEach((i) => {
780
- r[i.subUnitId] = i.links.map(({ display: a, ...o }) => o);
781
- }), JSON.stringify(r)) : "";
782
- }, e = (t) => {
783
- if (!t)
778
+ const toJson = /* @__PURE__ */ __name((unitID) => {
779
+ const map = this._hyperLinkModel.getUnit(unitID), resultMap = {};
780
+ return map ? (map.forEach((info) => {
781
+ resultMap[info.subUnitId] = info.links.map(({ display, ...link }) => link);
782
+ }), JSON.stringify(resultMap)) : "";
783
+ }, "toJson"), parseJson = /* @__PURE__ */ __name((json) => {
784
+ if (!json)
784
785
  return {};
785
786
  try {
786
- return JSON.parse(t);
787
+ return JSON.parse(json);
787
788
  } catch {
788
789
  return {};
789
790
  }
790
- };
791
+ }, "parseJson");
791
792
  this.disposeWithMe(
792
793
  this._resourceManagerService.registerPluginResource({
793
- pluginName: He,
794
- businesses: [Ve.UNIVER_SHEET],
795
- toJson: (t) => s(t),
796
- parseJson: (t) => e(t),
797
- onUnLoad: (t) => {
798
- this._hyperLinkModel.deleteUnit(t);
799
- },
800
- onLoad: async (t, n) => {
801
- Object.keys(n).forEach((r) => {
802
- n[r].forEach((a) => {
803
- this._hyperLinkModel.addHyperLink(t, r, a);
794
+ pluginName: SHEET_HYPER_LINK_PLUGIN,
795
+ businesses: [_.UNIVER_SHEET],
796
+ toJson: /* @__PURE__ */ __name((unitID) => toJson(unitID), "toJson"),
797
+ parseJson: /* @__PURE__ */ __name((json) => parseJson(json), "parseJson"),
798
+ onUnLoad: /* @__PURE__ */ __name((unitID) => {
799
+ this._hyperLinkModel.deleteUnit(unitID);
800
+ }, "onUnLoad"),
801
+ onLoad: /* @__PURE__ */ __name(async (unitID, value) => {
802
+ Object.keys(value).forEach((subunitId) => {
803
+ value[subunitId].forEach((link) => {
804
+ this._hyperLinkModel.addHyperLink(unitID, subunitId, link);
804
805
  });
805
806
  });
806
- }
807
+ }, "onLoad")
807
808
  })
808
809
  );
809
810
  }
810
- };
811
- se = $t([
812
- be(0, Ge),
813
- be(1, M(I))
814
- ], se);
815
- const xt = {
816
- type: L.COMMAND,
811
+ }, __name(_a6, "SheetsHyperLinkResourceController"), _a6);
812
+ SheetsHyperLinkResourceController = __decorateClass$3([
813
+ __decorateParam$3(0, IResourceManagerService),
814
+ __decorateParam$3(1, Inject(HyperLinkModel))
815
+ ], SheetsHyperLinkResourceController);
816
+ const AddHyperLinkCommand = {
817
+ type: CommandType.COMMAND,
817
818
  id: "sheets.command.add-hyper-link",
818
819
  // eslint-disable-next-line max-lines-per-function
819
- async handler(s, e) {
820
- if (!e) return !1;
821
- const t = s.get(P), n = s.get(Ie), r = s.get(E), i = s.get(I), a = s.get(le), o = j(r, e);
822
- if (!o) return !1;
823
- const { unitId: c, subUnitId: d, workbook: l, worksheet: u } = o, { link: h } = e, { payload: g, display: p, row: f, column: _, id: m } = h, C = u.getCell(f, _), y = u.getBlankCellDocumentModel(C), R = y.documentModel.getSnapshot(), S = oe.deepClone(R.body);
824
- if (!S) return !1;
825
- let N;
826
- if (p ? N = Z.selection.replace({
820
+ async handler(accessor, params) {
821
+ if (!params) return !1;
822
+ const commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), univerInstanceService = accessor.get(IUniverInstanceService), hyperLinkModel = accessor.get(HyperLinkModel), sheetInterceptorService = accessor.get(SheetInterceptorService), target = getSheetCommandTarget(univerInstanceService, params);
823
+ if (!target) return !1;
824
+ const { unitId, subUnitId, workbook, worksheet } = target, { link } = params, { payload, display, row, column, id } = link, cellData = worksheet.getCell(row, column), doc = worksheet.getBlankCellDocumentModel(cellData), snapshot = doc.documentModel.getSnapshot(), body = Tools.deepClone(snapshot.body);
825
+ if (!body) return !1;
826
+ let textX;
827
+ if (display ? textX = BuildTextUtils.selection.replace({
827
828
  selection: {
828
829
  startOffset: 0,
829
- endOffset: S.dataStream.length - 2,
830
- collapsed: S.dataStream.length - 2 === 0
830
+ endOffset: body.dataStream.length - 2,
831
+ collapsed: body.dataStream.length - 2 === 0
831
832
  },
832
833
  body: {
833
- dataStream: `${p}`,
834
+ dataStream: `${display}`,
834
835
  customRanges: [{
835
836
  startIndex: 0,
836
- endIndex: p.length - 1,
837
- rangeType: b.HYPERLINK,
838
- rangeId: m,
837
+ endIndex: display.length - 1,
838
+ rangeType: CustomRangeType.HYPERLINK,
839
+ rangeId: id,
839
840
  properties: {
840
- url: g
841
+ url: payload
841
842
  // refId: id,
842
843
  }
843
844
  }]
844
845
  },
845
- doc: y.documentModel
846
- }) : N = Z.customRange.add({
847
- body: S,
848
- ranges: [{ startOffset: 0, endOffset: S.dataStream.length - 2, collapsed: !1 }],
849
- rangeId: m,
850
- rangeType: b.HYPERLINK,
846
+ doc: doc.documentModel
847
+ }) : textX = BuildTextUtils.customRange.add({
848
+ body,
849
+ ranges: [{ startOffset: 0, endOffset: body.dataStream.length - 2, collapsed: !1 }],
850
+ rangeId: id,
851
+ rangeType: CustomRangeType.HYPERLINK,
851
852
  properties: {
852
- url: g,
853
- refId: m
853
+ url: payload,
854
+ refId: id
854
855
  }
855
- }), !N) return !1;
856
- const F = ce.apply(S, N.serialize()), D = {
856
+ }), !textX) return !1;
857
+ const newBody = TextX.apply(body, textX.serialize()), newCellData = {
857
858
  p: {
858
- ...R,
859
- body: F
859
+ ...snapshot,
860
+ body: newBody
860
861
  },
861
- t: ve.STRING
862
- }, x = await a.onWriteCell(l, u, f, _, D), T = {
863
- unitId: c,
864
- subUnitId: d,
862
+ t: CellValueType.STRING
863
+ }, finalCellData = await sheetInterceptorService.onWriteCell(workbook, worksheet, row, column, newCellData), redoParams = {
864
+ unitId,
865
+ subUnitId,
865
866
  cellValue: {
866
- [h.row]: {
867
- [h.column]: x
867
+ [link.row]: {
868
+ [link.column]: finalCellData
868
869
  }
869
870
  }
870
- }, ue = {
871
- id: H.id,
872
- params: T
873
- }, Y = Me(s, T), pe = {
874
- id: H.id,
875
- params: Y
876
- }, K = [ue], A = [pe], W = i.getHyperLinkByLocation(c, d, f, _);
877
- return W && (K.push({
878
- id: k.id,
871
+ }, redo = {
872
+ id: SetRangeValuesMutation.id,
873
+ params: redoParams
874
+ }, undoParams = SetRangeValuesUndoMutationFactory(accessor, redoParams), undo = {
875
+ id: SetRangeValuesMutation.id,
876
+ params: undoParams
877
+ }, redos = [redo], undos = [undo], modelLink = hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
878
+ return modelLink && (redos.push({
879
+ id: RemoveHyperLinkMutation.id,
879
880
  params: {
880
- unitId: c,
881
- subUnitId: d,
882
- id: W.id
881
+ unitId,
882
+ subUnitId,
883
+ id: modelLink.id
883
884
  }
884
- }), A.push({
885
- id: O.id,
885
+ }), undos.push({
886
+ id: AddHyperLinkMutation.id,
886
887
  params: {
887
- unitId: c,
888
- subUnitId: d,
889
- link: W
888
+ unitId,
889
+ subUnitId,
890
+ link: modelLink
890
891
  }
891
- })), await Re(K, t) ? (n.pushUndoRedo({
892
- redoMutations: K,
893
- undoMutations: A,
894
- unitID: c
892
+ })), await sequenceExecuteAsync(redos, commandService) ? (undoRedoService.pushUndoRedo({
893
+ redoMutations: redos,
894
+ undoMutations: undos,
895
+ unitID: unitId
895
896
  }), !0) : !1;
896
897
  }
897
- }, Tt = {
898
+ }, AddRichHyperLinkCommand = {
898
899
  id: "sheets.command.add-rich-hyper-link",
899
- type: L.COMMAND,
900
- handler: async (s, e) => {
901
- if (!e)
900
+ type: CommandType.COMMAND,
901
+ handler: /* @__PURE__ */ __name(async (accessor, params) => {
902
+ if (!params)
902
903
  return !1;
903
- const { documentId: t, link: n } = e, r = s.get(P), i = de(), { payload: a } = n, o = _t(s, {
904
- unitId: t,
905
- rangeId: i,
906
- rangeType: b.HYPERLINK,
904
+ const { documentId, link } = params, commandService = accessor.get(ICommandService), newId = generateRandomId(), { payload } = link, replaceSelection = addCustomRangeBySelectionFactory(accessor, {
905
+ unitId: documentId,
906
+ rangeId: newId,
907
+ rangeType: CustomRangeType.HYPERLINK,
907
908
  properties: {
908
- url: a,
909
- refId: i
909
+ url: payload,
910
+ refId: newId
910
911
  }
911
912
  });
912
- return o ? r.syncExecuteCommand(o.id, o.params) : !1;
913
- }
914
- }, At = {
915
- type: L.COMMAND,
913
+ return replaceSelection ? commandService.syncExecuteCommand(replaceSelection.id, replaceSelection.params) : !1;
914
+ }, "handler")
915
+ }, CancelHyperLinkCommand = {
916
+ type: CommandType.COMMAND,
916
917
  id: "sheets.command.cancel-hyper-link",
917
918
  // eslint-disable-next-line max-lines-per-function
918
- handler(s, e) {
919
- var D, x;
920
- if (!e) return !1;
921
- const t = s.get(P), n = s.get(Ie), r = s.get(E), i = s.get(I), a = j(r, e);
922
- if (!a) return !1;
923
- const { row: o, column: c, id: d } = e, { unitId: l, subUnitId: u, worksheet: h } = a, g = h.getCell(o, c);
924
- if (!g) return !1;
925
- const p = h.getCellDocumentModelWithFormula(g);
926
- if (!(p != null && p.documentModel)) return !1;
927
- const f = oe.deepClone(p.documentModel.getSnapshot()), _ = (x = (D = f.body) == null ? void 0 : D.customRanges) == null ? void 0 : x.find((T) => `${T.rangeId}` === d);
928
- if (!_) return !1;
929
- const m = Z.customRange.delete({ documentDataModel: p.documentModel, rangeId: _.rangeId });
930
- if (!m) return !1;
931
- const C = ce.apply(f.body, m.serialize()), y = [], R = [], S = {
932
- unitId: l,
933
- subUnitId: u,
919
+ handler(accessor, params) {
920
+ var _a10, _b;
921
+ if (!params) return !1;
922
+ const commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), instanceSrv = accessor.get(IUniverInstanceService), hyperLinkModel = accessor.get(HyperLinkModel), target = getSheetCommandTarget(instanceSrv, params);
923
+ if (!target) return !1;
924
+ const { row, column, id } = params, { unitId, subUnitId, worksheet } = target, cellData = worksheet.getCell(row, column);
925
+ if (!cellData) return !1;
926
+ const doc = worksheet.getCellDocumentModelWithFormula(cellData);
927
+ if (!(doc != null && doc.documentModel)) return !1;
928
+ const snapshot = Tools.deepClone(doc.documentModel.getSnapshot()), range = (_b = (_a10 = snapshot.body) == null ? void 0 : _a10.customRanges) == null ? void 0 : _b.find((range2) => `${range2.rangeId}` === id);
929
+ if (!range) return !1;
930
+ const textX = BuildTextUtils.customRange.delete({ documentDataModel: doc.documentModel, rangeId: range.rangeId });
931
+ if (!textX) return !1;
932
+ const newBody = TextX.apply(snapshot.body, textX.serialize()), redos = [], undos = [], setRangeParams = {
933
+ unitId,
934
+ subUnitId,
934
935
  cellValue: {
935
- [o]: {
936
- [c]: {
936
+ [row]: {
937
+ [column]: {
937
938
  p: {
938
- ...f,
939
- body: C
939
+ ...snapshot,
940
+ body: newBody
940
941
  },
941
- t: ve.STRING
942
+ t: CellValueType.STRING
942
943
  }
943
944
  }
944
945
  }
945
946
  };
946
- y.push({
947
- id: H.id,
948
- params: S
947
+ redos.push({
948
+ id: SetRangeValuesMutation.id,
949
+ params: setRangeParams
949
950
  });
950
- const N = Me(s, S);
951
- R.push({
952
- id: H.id,
953
- params: N
951
+ const undoParams = SetRangeValuesUndoMutationFactory(accessor, setRangeParams);
952
+ undos.push({
953
+ id: SetRangeValuesMutation.id,
954
+ params: undoParams
954
955
  });
955
- const F = i.getHyperLinkByLocation(l, u, o, c);
956
- return F && (y.push({
957
- id: k.id,
956
+ const link = hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
957
+ return link && (redos.push({
958
+ id: RemoveHyperLinkMutation.id,
958
959
  params: {
959
- unitId: l,
960
- subUnitId: u,
961
- id: d
960
+ unitId,
961
+ subUnitId,
962
+ id
962
963
  }
963
- }), R.push({
964
- id: O.id,
964
+ }), undos.push({
965
+ id: AddHyperLinkMutation.id,
965
966
  params: {
966
- unitId: l,
967
- subUnitId: u,
967
+ unitId,
968
+ subUnitId,
968
969
  link: {
969
- ...F
970
+ ...link
970
971
  }
971
972
  }
972
- })), ze(y, t).result ? (n.pushUndoRedo({
973
- redoMutations: y,
974
- undoMutations: R,
975
- unitID: l
973
+ })), sequenceExecute(redos, commandService).result ? (undoRedoService.pushUndoRedo({
974
+ redoMutations: redos,
975
+ undoMutations: undos,
976
+ unitID: unitId
976
977
  }), !0) : !1;
977
978
  }
978
- }, Wt = {
979
- type: L.COMMAND,
979
+ }, CancelRichHyperLinkCommand = {
980
+ type: CommandType.COMMAND,
980
981
  id: "sheets.command.cancel-rich-hyper-link",
981
- handler(s, e) {
982
- var l, u;
983
- if (!e)
982
+ handler(accessor, params) {
983
+ var _a10, _b;
984
+ if (!params)
984
985
  return !1;
985
- const { id: t, documentId: n } = e, r = s.get(P), a = s.get(E).getUnit(n, v.UNIVER_DOC), o = (u = (l = a == null ? void 0 : a.getBody()) == null ? void 0 : l.customRanges) == null ? void 0 : u.find((h) => h.rangeId === t);
986
- let c = null;
987
- o && o.endIndex === a.getBody().dataStream.length - 3 && (c = {
986
+ const { id: linkId, documentId } = params, commandService = accessor.get(ICommandService), doc = accessor.get(IUniverInstanceService).getUnit(documentId, UniverInstanceType.UNIVER_DOC), link = (_b = (_a10 = doc == null ? void 0 : doc.getBody()) == null ? void 0 : _a10.customRanges) == null ? void 0 : _b.find((i) => i.rangeId === linkId);
987
+ let insert = null;
988
+ link && link.endIndex === doc.getBody().dataStream.length - 3 && (insert = {
988
989
  dataStream: " "
989
990
  });
990
- const d = mt(s, { unitId: n, rangeId: t, insert: c });
991
- return d ? r.syncExecuteCommand(d.id, d.params) : !1;
991
+ const doMutation = deleteCustomRangeFactory(accessor, { unitId: documentId, rangeId: linkId, insert });
992
+ return doMutation ? commandService.syncExecuteCommand(doMutation.id, doMutation.params) : !1;
992
993
  }
993
- }, Bt = {
994
- type: L.COMMAND,
994
+ }, UpdateHyperLinkCommand = {
995
+ type: CommandType.COMMAND,
995
996
  id: "sheets.command.update-hyper-link",
996
997
  // eslint-disable-next-line max-lines-per-function
997
- async handler(s, e) {
998
- var we, Ee, Le;
999
- if (!e) return !1;
1000
- const t = s.get(P), n = s.get(Ie), r = s.get(E), i = s.get(I), a = s.get(le), o = j(r, {
1001
- unitId: e.unitId,
1002
- subUnitId: e.subUnitId
998
+ async handler(accessor, params) {
999
+ var _a10, _b, _c;
1000
+ if (!params) return !1;
1001
+ const commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), instanceSrv = accessor.get(IUniverInstanceService), hyperLinkModel = accessor.get(HyperLinkModel), interceptorService = accessor.get(SheetInterceptorService), target = getSheetCommandTarget(instanceSrv, {
1002
+ unitId: params.unitId,
1003
+ subUnitId: params.subUnitId
1003
1004
  });
1004
- if (!o) return !1;
1005
- const { payload: c, row: d, column: l, id: u } = e, { workbook: h, worksheet: g, unitId: p, subUnitId: f } = o, { payload: _, display: m = "" } = c, C = g.getCell(d, l);
1006
- if (!C) return !1;
1007
- const y = g.getCellDocumentModelWithFormula(C);
1008
- if (!(y != null && y.documentModel)) return !1;
1009
- const R = y.documentModel.getSnapshot(), S = (Ee = (we = R.body) == null ? void 0 : we.customRanges) == null ? void 0 : Ee.find((Te) => `${Te.rangeId}` === u);
1010
- if (!S) return !1;
1011
- const N = de(), $ = (Le = Ne(y.documentModel.getBody(), S.startIndex, S.endIndex + 1).textRuns) == null ? void 0 : Le[0];
1012
- $ && ($.ed = m.length + 1);
1013
- const D = De(s, {
1014
- unitId: p,
1005
+ if (!target) return !1;
1006
+ const { payload: link, row, column, id } = params, { workbook, worksheet, unitId, subUnitId } = target, { payload, display = "" } = link, cellData = worksheet.getCell(row, column);
1007
+ if (!cellData) return !1;
1008
+ const doc = worksheet.getCellDocumentModelWithFormula(cellData);
1009
+ if (!(doc != null && doc.documentModel)) return !1;
1010
+ const snapshot = doc.documentModel.getSnapshot(), range = (_b = (_a10 = snapshot.body) == null ? void 0 : _a10.customRanges) == null ? void 0 : _b.find((range2) => `${range2.rangeId}` === id);
1011
+ if (!range) return !1;
1012
+ const newId = generateRandomId(), textRun = (_c = getBodySlice(doc.documentModel.getBody(), range.startIndex, range.endIndex + 1).textRuns) == null ? void 0 : _c[0];
1013
+ textRun && (textRun.ed = display.length + 1);
1014
+ const replaceSelection = replaceSelectionFactory(accessor, {
1015
+ unitId,
1015
1016
  body: {
1016
- dataStream: `${m}`,
1017
+ dataStream: `${display}`,
1017
1018
  customRanges: [{
1018
- rangeId: N,
1019
- rangeType: b.HYPERLINK,
1019
+ rangeId: newId,
1020
+ rangeType: CustomRangeType.HYPERLINK,
1020
1021
  startIndex: 0,
1021
- endIndex: m.length - 1,
1022
+ endIndex: display.length - 1,
1022
1023
  properties: {
1023
- url: _
1024
+ url: payload
1024
1025
  }
1025
1026
  }],
1026
- textRuns: $ ? [$] : void 0
1027
+ textRuns: textRun ? [textRun] : void 0
1027
1028
  },
1028
1029
  selection: {
1029
- startOffset: S.startIndex,
1030
- endOffset: S.endIndex + 1,
1030
+ startOffset: range.startIndex,
1031
+ endOffset: range.endIndex + 1,
1031
1032
  collapsed: !1
1032
1033
  },
1033
- doc: y.documentModel
1034
+ doc: doc.documentModel
1034
1035
  });
1035
- if (!D)
1036
+ if (!replaceSelection)
1036
1037
  return !1;
1037
- const x = ce.apply(oe.deepClone(R.body), D.textX.serialize()), T = {
1038
+ const newBody = TextX.apply(Tools.deepClone(snapshot.body), replaceSelection.textX.serialize()), newCellData = {
1038
1039
  p: {
1039
- ...R,
1040
- body: x
1040
+ ...snapshot,
1041
+ body: newBody
1041
1042
  },
1042
- t: ve.STRING
1043
- }, ue = await a.onWriteCell(h, g, d, l, T), Y = {
1044
- id: H.id,
1043
+ t: CellValueType.STRING
1044
+ }, finalCellData = await interceptorService.onWriteCell(workbook, worksheet, row, column, newCellData), redo = {
1045
+ id: SetRangeValuesMutation.id,
1045
1046
  params: {
1046
- unitId: p,
1047
- subUnitId: f,
1047
+ unitId,
1048
+ subUnitId,
1048
1049
  cellValue: {
1049
- [d]: {
1050
- [l]: ue
1050
+ [row]: {
1051
+ [column]: finalCellData
1051
1052
  }
1052
1053
  }
1053
1054
  }
1054
- }, pe = Me(s, Y.params), K = {
1055
- id: H.id,
1056
- params: pe
1057
- }, A = [Y], W = [K], G = i.getHyperLinkByLocation(p, f, d, l);
1058
- return G && (A.push({
1059
- id: k.id,
1055
+ }, undoParams = SetRangeValuesUndoMutationFactory(accessor, redo.params), undo = {
1056
+ id: SetRangeValuesMutation.id,
1057
+ params: undoParams
1058
+ }, redos = [redo], undos = [undo], modelLink = hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
1059
+ return modelLink && (redos.push({
1060
+ id: RemoveHyperLinkMutation.id,
1060
1061
  params: {
1061
- unitId: p,
1062
- subUnitId: f,
1063
- id: G.id
1062
+ unitId,
1063
+ subUnitId,
1064
+ id: modelLink.id
1064
1065
  }
1065
- }), W.push({
1066
- id: O.id,
1066
+ }), undos.push({
1067
+ id: AddHyperLinkMutation.id,
1067
1068
  params: {
1068
- unitId: p,
1069
- subUnitId: f,
1070
- link: G
1069
+ unitId,
1070
+ subUnitId,
1071
+ link: modelLink
1071
1072
  }
1072
- })), await Re(A, t) ? (n.pushUndoRedo({
1073
- redoMutations: A,
1074
- undoMutations: W,
1075
- unitID: p
1073
+ })), await sequenceExecuteAsync(redos, commandService) ? (undoRedoService.pushUndoRedo({
1074
+ redoMutations: redos,
1075
+ undoMutations: undos,
1076
+ unitID: unitId
1076
1077
  }), !0) : !1;
1077
1078
  }
1078
- }, jt = {
1079
- type: L.COMMAND,
1079
+ }, UpdateRichHyperLinkCommand = {
1080
+ type: CommandType.COMMAND,
1080
1081
  id: "sheets.command.update-rich-hyper-link",
1081
- handler: (s, e) => {
1082
- var p, f, _, m;
1083
- if (!e)
1082
+ handler: /* @__PURE__ */ __name((accessor, params) => {
1083
+ var _a10, _b, _c, _d;
1084
+ if (!params)
1084
1085
  return !1;
1085
- const { documentId: t, payload: n, id: r } = e, i = s.get(E), a = s.get(P), o = i.getUnit(t, v.UNIVER_DOC);
1086
- if (!o)
1086
+ const { documentId: unitId, payload, id: rangeId } = params, univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), doc = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
1087
+ if (!doc)
1087
1088
  return !1;
1088
- const c = (f = (p = o.getBody()) == null ? void 0 : p.customRanges) == null ? void 0 : f.find((C) => C.rangeId === r);
1089
- if (!c)
1089
+ const range = (_b = (_a10 = doc.getBody()) == null ? void 0 : _a10.customRanges) == null ? void 0 : _b.find((range2) => range2.rangeId === rangeId);
1090
+ if (!range)
1090
1091
  return !1;
1091
- const d = (_ = e.payload.display) != null ? _ : "", l = de(), h = (m = Ne(o.getBody(), c.startIndex, c.endIndex + 1).textRuns) == null ? void 0 : m[0];
1092
- h && (h.ed = d.length + 1);
1093
- const g = De(s, {
1094
- unitId: t,
1092
+ const display = (_c = params.payload.display) != null ? _c : "", newId = generateRandomId(), textRun = (_d = getBodySlice(doc.getBody(), range.startIndex, range.endIndex + 1).textRuns) == null ? void 0 : _d[0];
1093
+ textRun && (textRun.ed = display.length + 1);
1094
+ const replaceSelection = replaceSelectionFactory(accessor, {
1095
+ unitId,
1095
1096
  body: {
1096
- dataStream: `${d}`,
1097
+ dataStream: `${display}`,
1097
1098
  customRanges: [{
1098
- rangeId: l,
1099
- rangeType: b.HYPERLINK,
1099
+ rangeId: newId,
1100
+ rangeType: CustomRangeType.HYPERLINK,
1100
1101
  startIndex: 0,
1101
- endIndex: d.length - 1,
1102
+ endIndex: display.length - 1,
1102
1103
  properties: {
1103
- url: n.payload
1104
+ url: payload.payload
1104
1105
  }
1105
1106
  }],
1106
- textRuns: h ? [h] : void 0
1107
+ textRuns: textRun ? [textRun] : void 0
1107
1108
  },
1108
1109
  selection: {
1109
- startOffset: c.startIndex,
1110
- endOffset: c.endIndex + 1,
1110
+ startOffset: range.startIndex,
1111
+ endOffset: range.endIndex + 1,
1111
1112
  collapsed: !1
1112
1113
  },
1113
- doc: o
1114
+ doc
1114
1115
  });
1115
- return g ? a.syncExecuteCommand(g.id, g.params) : !1;
1116
- }
1116
+ return replaceSelection ? commandService.syncExecuteCommand(replaceSelection.id, replaceSelection.params) : !1;
1117
+ }, "handler")
1117
1118
  };
1118
- var Ft = Object.defineProperty, Kt = Object.getOwnPropertyDescriptor, Yt = (s, e, t, n) => {
1119
- for (var r = n > 1 ? void 0 : n ? Kt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
1120
- (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
1121
- return n && r && Ft(e, t, r), r;
1122
- }, Gt = (s, e) => (t, n) => e(t, n, s);
1123
- let ie = class extends V {
1124
- constructor(s) {
1125
- super(), this._commandService = s, this._registerCommands();
1119
+ var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1120
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1121
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1122
+ return kind && result && __defProp$2(target, key, result), result;
1123
+ }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a7;
1124
+ let SheetsHyperLinkController = (_a7 = class extends Disposable {
1125
+ constructor(_commandService) {
1126
+ super(), this._commandService = _commandService, this._registerCommands();
1126
1127
  }
1127
1128
  _registerCommands() {
1128
1129
  [
1129
- xt,
1130
- Bt,
1131
- At,
1132
- jt,
1133
- Wt,
1134
- Tt,
1135
- O,
1136
- _e,
1137
- k,
1138
- me,
1139
- X
1140
- ].forEach((s) => {
1141
- this._commandService.registerCommand(s);
1130
+ AddHyperLinkCommand,
1131
+ UpdateHyperLinkCommand,
1132
+ CancelHyperLinkCommand,
1133
+ UpdateRichHyperLinkCommand,
1134
+ CancelRichHyperLinkCommand,
1135
+ AddRichHyperLinkCommand,
1136
+ AddHyperLinkMutation,
1137
+ UpdateHyperLinkMutation,
1138
+ RemoveHyperLinkMutation,
1139
+ UpdateHyperLinkRefMutation,
1140
+ UpdateRichHyperLinkMutation
1141
+ ].forEach((command) => {
1142
+ this._commandService.registerCommand(command);
1142
1143
  });
1143
1144
  }
1144
- };
1145
- ie = Yt([
1146
- Gt(0, P)
1147
- ], ie);
1148
- var zt = Object.defineProperty, Jt = Object.getOwnPropertyDescriptor, Xt = (s, e, t, n) => {
1149
- for (var r = n > 1 ? void 0 : n ? Jt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
1150
- (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
1151
- return n && r && zt(e, t, r), r;
1152
- }, fe = (s, e) => (t, n) => e(t, n, s);
1153
- let ye = class {
1154
- constructor(s, e, t) {
1155
- this._univerInstanceService = s, this._localeService = e, this._definedNamesService = t;
1145
+ }, __name(_a7, "SheetsHyperLinkController"), _a7);
1146
+ SheetsHyperLinkController = __decorateClass$2([
1147
+ __decorateParam$2(0, ICommandService)
1148
+ ], SheetsHyperLinkController);
1149
+ var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1150
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1151
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1152
+ return kind && result && __defProp$1(target, key, result), result;
1153
+ }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a8;
1154
+ let SheetsHyperLinkParserService = (_a8 = class {
1155
+ constructor(_univerInstanceService, _localeService, _definedNamesService) {
1156
+ this._univerInstanceService = _univerInstanceService, this._localeService = _localeService, this._definedNamesService = _definedNamesService;
1156
1157
  }
1157
- buildHyperLink(s, e, t) {
1158
- return `#${U.SHEET}=${e}${t ? `&${typeof t == "string" ? U.DEFINE_NAME : U.RANGE}=${typeof t == "string" ? t : B(t)}` : ""}`;
1158
+ buildHyperLink(unitId, sheetId, range) {
1159
+ return `#${SheetHyperLinkType.SHEET}=${sheetId}${range ? `&${typeof range == "string" ? SheetHyperLinkType.DEFINE_NAME : SheetHyperLinkType.RANGE}=${typeof range == "string" ? range : serializeRange(range)}` : ""}`;
1159
1160
  }
1160
- parseHyperLink(s) {
1161
- var e, t, n, r;
1162
- if (s.startsWith("#")) {
1163
- const i = new URLSearchParams(s.slice(1)), a = {
1164
- gid: (e = i.get("gid")) != null ? e : "",
1165
- range: (t = i.get("range")) != null ? t : "",
1166
- rangeid: (n = i.get("rangeid")) != null ? n : "",
1167
- unitid: (r = i.get("unitid")) != null ? r : ""
1168
- }, o = this._getURLName(a);
1161
+ parseHyperLink(urlStr) {
1162
+ var _a10, _b, _c, _d;
1163
+ if (urlStr.startsWith("#")) {
1164
+ const search = new URLSearchParams(urlStr.slice(1)), searchObj = {
1165
+ gid: (_a10 = search.get("gid")) != null ? _a10 : "",
1166
+ range: (_b = search.get("range")) != null ? _b : "",
1167
+ rangeid: (_c = search.get("rangeid")) != null ? _c : "",
1168
+ unitid: (_d = search.get("unitid")) != null ? _d : ""
1169
+ }, urlInfo = this._getURLName(searchObj);
1169
1170
  return {
1170
- type: o.type,
1171
- name: o.name,
1172
- url: s,
1173
- searchObj: a
1171
+ type: urlInfo.type,
1172
+ name: urlInfo.name,
1173
+ url: urlStr,
1174
+ searchObj
1174
1175
  };
1175
1176
  } else
1176
1177
  return {
1177
- type: U.URL,
1178
- name: s,
1179
- url: s,
1178
+ type: SheetHyperLinkType.URL,
1179
+ name: urlStr,
1180
+ url: urlStr,
1180
1181
  searchObj: null
1181
1182
  };
1182
1183
  }
1183
- _getURLName(s) {
1184
- var d;
1185
- const { gid: e, range: t, rangeid: n, unitid: r } = s, i = r ? this._univerInstanceService.getUnit(r, v.UNIVER_SHEET) : this._univerInstanceService.getCurrentUnitForType(v.UNIVER_SHEET), a = {
1186
- type: U.INVALID,
1184
+ _getURLName(params) {
1185
+ var _a10;
1186
+ const { gid, range, rangeid, unitid } = params, workbook = unitid ? this._univerInstanceService.getUnit(unitid, UniverInstanceType.UNIVER_SHEET) : this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), invalidLink = {
1187
+ type: SheetHyperLinkType.INVALID,
1187
1188
  name: this._localeService.t("hyperLink.message.refError")
1188
1189
  };
1189
- if (!i)
1190
- return a;
1191
- const o = e ? i.getSheetBySheetId(e) : i.getActiveSheet(), c = (d = o == null ? void 0 : o.getName()) != null ? d : "";
1192
- if (t) {
1193
- if (!o) return a;
1194
- const l = Ce(t).range;
1195
- return Se(l, o) && t !== Q ? {
1196
- type: U.RANGE,
1197
- name: gt(c, l)
1198
- } : a;
1190
+ if (!workbook)
1191
+ return invalidLink;
1192
+ const sheet = gid ? workbook.getSheetBySheetId(gid) : workbook.getActiveSheet(), sheetName = (_a10 = sheet == null ? void 0 : sheet.getName()) != null ? _a10 : "";
1193
+ if (range) {
1194
+ if (!sheet) return invalidLink;
1195
+ const rangeObj = deserializeRangeWithSheet(range).range;
1196
+ return isValidRange(rangeObj, sheet) && range !== ERROR_RANGE ? {
1197
+ type: SheetHyperLinkType.RANGE,
1198
+ name: serializeRangeWithSheet(sheetName, rangeObj)
1199
+ } : invalidLink;
1199
1200
  }
1200
- if (n) {
1201
- const l = this._definedNamesService.getValueById(i.getUnitId(), n);
1202
- return l ? {
1203
- type: U.DEFINE_NAME,
1204
- name: l.formulaOrRefString
1205
- } : a;
1201
+ if (rangeid) {
1202
+ const range2 = this._definedNamesService.getValueById(workbook.getUnitId(), rangeid);
1203
+ return range2 ? {
1204
+ type: SheetHyperLinkType.DEFINE_NAME,
1205
+ name: range2.formulaOrRefString
1206
+ } : invalidLink;
1206
1207
  }
1207
- if (e) {
1208
- const l = i.getSheetBySheetId(e);
1209
- return l ? {
1210
- type: U.SHEET,
1211
- name: l.getName()
1212
- } : a;
1208
+ if (gid) {
1209
+ const worksheet = workbook.getSheetBySheetId(gid);
1210
+ return worksheet ? {
1211
+ type: SheetHyperLinkType.SHEET,
1212
+ name: worksheet.getName()
1213
+ } : invalidLink;
1213
1214
  }
1214
- return a;
1215
+ return invalidLink;
1215
1216
  }
1216
- };
1217
- ye = Xt([
1218
- fe(0, E),
1219
- fe(1, M(Je)),
1220
- fe(2, ft)
1221
- ], ye);
1222
- var $e = Object.defineProperty, qt = Object.getOwnPropertyDescriptor, Zt = (s, e, t) => e in s ? $e(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, Qt = (s, e, t, n) => {
1223
- for (var r = n > 1 ? void 0 : n ? qt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
1224
- (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
1225
- return n && r && $e(e, t, r), r;
1226
- }, Pe = (s, e) => (t, n) => e(t, n, s), xe = (s, e, t) => Zt(s, typeof e != "symbol" ? e + "" : e, t);
1227
- let ae = class extends Ze {
1228
- constructor(s = Ue, e, t) {
1229
- super(), this._config = s, this._injector = e, this._configService = t;
1230
- const { ...n } = Qe(
1217
+ }, __name(_a8, "SheetsHyperLinkParserService"), _a8);
1218
+ SheetsHyperLinkParserService = __decorateClass$1([
1219
+ __decorateParam$1(0, IUniverInstanceService),
1220
+ __decorateParam$1(1, Inject(LocaleService)),
1221
+ __decorateParam$1(2, IDefinedNamesService)
1222
+ ], SheetsHyperLinkParserService);
1223
+ var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __defNormalProp2 = /* @__PURE__ */ __name((obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, "__defNormalProp"), __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
1224
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
1225
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
1226
+ return kind && result && __defProp2(target, key, result), result;
1227
+ }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), __publicField2 = /* @__PURE__ */ __name((obj, key, value) => __defNormalProp2(obj, typeof key != "symbol" ? key + "" : key, value), "__publicField"), _a9;
1228
+ let UniverSheetsHyperLinkPlugin = (_a9 = class extends Plugin {
1229
+ constructor(_config = defaultPluginConfig, _injector, _configService) {
1230
+ super(), this._config = _config, this._injector = _injector, this._configService = _configService;
1231
+ const { ...rest } = merge(
1231
1232
  {},
1232
- Ue,
1233
+ defaultPluginConfig,
1233
1234
  this._config
1234
1235
  );
1235
- this._configService.setConfig(vt, n);
1236
+ this._configService.setConfig(SHEETS_HYPER_LINK_PLUGIN_CONFIG_KEY, rest);
1236
1237
  }
1237
1238
  onStarting() {
1238
- et(this._injector, [
1239
- [I],
1240
- [ye],
1241
- [se],
1242
- [ie],
1243
- [ee],
1244
- [re],
1245
- [te],
1246
- [ne]
1247
- ]), tt(this._injector, [
1248
- [ee],
1249
- [se],
1250
- [ie],
1251
- [re],
1252
- [te],
1253
- [ne]
1239
+ registerDependencies(this._injector, [
1240
+ [HyperLinkModel],
1241
+ [SheetsHyperLinkParserService],
1242
+ [SheetsHyperLinkResourceController],
1243
+ [SheetsHyperLinkController],
1244
+ [SheetsHyperLinkRefRangeController],
1245
+ [SheetHyperLinkSetRangeController],
1246
+ [SheetsHyperLinkRemoveSheetController],
1247
+ [SheetsHyperLinkRichTextRefRangeController]
1248
+ ]), touchDependencies(this._injector, [
1249
+ [SheetsHyperLinkRefRangeController],
1250
+ [SheetsHyperLinkResourceController],
1251
+ [SheetsHyperLinkController],
1252
+ [SheetHyperLinkSetRangeController],
1253
+ [SheetsHyperLinkRemoveSheetController],
1254
+ [SheetsHyperLinkRichTextRefRangeController]
1254
1255
  ]);
1255
1256
  }
1256
- };
1257
- xe(ae, "pluginName", He);
1258
- xe(ae, "type", v.UNIVER_SHEET);
1259
- ae = Qt([
1260
- Xe(ht),
1261
- Pe(1, M(qe)),
1262
- Pe(2, nt)
1263
- ], ae);
1257
+ }, __name(_a9, "UniverSheetsHyperLinkPlugin"), _a9);
1258
+ __publicField2(UniverSheetsHyperLinkPlugin, "pluginName", SHEET_HYPER_LINK_PLUGIN);
1259
+ __publicField2(UniverSheetsHyperLinkPlugin, "type", UniverInstanceType.UNIVER_SHEET);
1260
+ UniverSheetsHyperLinkPlugin = __decorateClass([
1261
+ DependentOn(UniverSheetsPlugin),
1262
+ __decorateParam(1, Inject(Injector)),
1263
+ __decorateParam(2, IConfigService)
1264
+ ], UniverSheetsHyperLinkPlugin);
1264
1265
  export {
1265
- xt as AddHyperLinkCommand,
1266
- O as AddHyperLinkMutation,
1267
- Tt as AddRichHyperLinkCommand,
1268
- At as CancelHyperLinkCommand,
1269
- Wt as CancelRichHyperLinkCommand,
1270
- Q as ERROR_RANGE,
1271
- I as HyperLinkModel,
1272
- k as RemoveHyperLinkMutation,
1273
- U as SheetHyperLinkType,
1274
- ye as SheetsHyperLinkParserService,
1275
- ae as UniverSheetsHyperLinkPlugin,
1276
- Bt as UpdateHyperLinkCommand,
1277
- _e as UpdateHyperLinkMutation,
1278
- me as UpdateHyperLinkRefMutation,
1279
- jt as UpdateRichHyperLinkCommand
1266
+ AddHyperLinkCommand,
1267
+ AddHyperLinkMutation,
1268
+ AddRichHyperLinkCommand,
1269
+ CancelHyperLinkCommand,
1270
+ CancelRichHyperLinkCommand,
1271
+ ERROR_RANGE,
1272
+ HyperLinkModel,
1273
+ RemoveHyperLinkMutation,
1274
+ SheetHyperLinkType,
1275
+ SheetsHyperLinkParserService,
1276
+ UniverSheetsHyperLinkPlugin,
1277
+ UpdateHyperLinkCommand,
1278
+ UpdateHyperLinkMutation,
1279
+ UpdateHyperLinkRefMutation,
1280
+ UpdateRichHyperLinkCommand
1280
1281
  };