@univerjs/sheets-hyper-link 0.4.1 → 0.4.2-nightly.202410301606

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,88 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
3
+ import { FWorkbook, FRange } from "@univerjs/sheets/facade";
4
+ import { d as SheetsHyperLinkParserService, A as AddHyperLinkCommand, U as UpdateHyperLinkCommand, C as CancelHyperLinkCommand } from "../parser.service-BQCD3XSg.mjs";
5
+ import { generateRandomId, CustomRangeType } from "@univerjs/core";
6
+ const _FWorkbookHyperLinkMixin = class _FWorkbookHyperLinkMixin extends FWorkbook {
7
+ createSheetHyperlink(sheetId, range) {
8
+ return this._injector.get(SheetsHyperLinkParserService).buildHyperLink(this.getId(), sheetId, range);
9
+ }
10
+ /**
11
+ * parse the hyperlink string to get the hyperlink info
12
+ * @param hyperlink the hyperlink string
13
+ * @returns the hyperlink info
14
+ */
15
+ parseSheetHyperlink(hyperlink) {
16
+ return this._injector.get(SheetsHyperLinkParserService).parseHyperLink(hyperlink);
17
+ }
18
+ };
19
+ __name(_FWorkbookHyperLinkMixin, "FWorkbookHyperLinkMixin");
20
+ let FWorkbookHyperLinkMixin = _FWorkbookHyperLinkMixin;
21
+ FWorkbook.extend(FWorkbookHyperLinkMixin);
22
+ const _FRangeHyperlinkMixin = class _FRangeHyperlinkMixin extends FRange {
23
+ // #region hyperlink
24
+ setHyperLink(url, label) {
25
+ const params = {
26
+ unitId: this.getUnitId(),
27
+ subUnitId: this._worksheet.getSheetId(),
28
+ link: {
29
+ row: this._range.startRow,
30
+ column: this._range.startColumn,
31
+ payload: url,
32
+ display: label,
33
+ id: generateRandomId()
34
+ }
35
+ };
36
+ return this._commandService.executeCommand(AddHyperLinkCommand.id, params);
37
+ }
38
+ getHyperLinks() {
39
+ var _a, _b, _c;
40
+ const cellValue = this._worksheet.getCellRaw(this._range.startRow, this._range.startColumn);
41
+ return cellValue != null && cellValue.p ? (_c = (_b = (_a = cellValue.p.body) == null ? void 0 : _a.customRanges) == null ? void 0 : _b.filter((range) => range.rangeType === CustomRangeType.HYPERLINK).map((range) => {
42
+ var _a2, _b2, _c2, _d, _e;
43
+ return {
44
+ id: range.rangeId,
45
+ startIndex: range.startIndex,
46
+ endIndex: range.endIndex,
47
+ url: (_b2 = (_a2 = range.properties) == null ? void 0 : _a2.url) != null ? _b2 : "",
48
+ label: (_e = (_d = (_c2 = cellValue.p) == null ? void 0 : _c2.body) == null ? void 0 : _d.dataStream.slice(range.startIndex + 1, range.endIndex)) != null ? _e : ""
49
+ };
50
+ })) != null ? _c : [] : [];
51
+ }
52
+ updateHyperLink(id, url, label) {
53
+ const params = {
54
+ unitId: this.getUnitId(),
55
+ subUnitId: this._worksheet.getSheetId(),
56
+ row: this._range.startRow,
57
+ column: this._range.startColumn,
58
+ id,
59
+ payload: {
60
+ payload: url,
61
+ display: label
62
+ }
63
+ };
64
+ return this._commandService.executeCommand(UpdateHyperLinkCommand.id, params);
65
+ }
66
+ /**
67
+ * Cancel hyperlink in the cell in the range.
68
+ * @param id id of the hyperlink
69
+ * @returns success or not
70
+ */
71
+ cancelHyperLink(id) {
72
+ const params = {
73
+ unitId: this.getUnitId(),
74
+ subUnitId: this._worksheet.getSheetId(),
75
+ row: this._range.startRow,
76
+ column: this._range.startColumn,
77
+ id
78
+ };
79
+ return this._commandService.executeCommand(CancelHyperLinkCommand.id, params);
80
+ }
81
+ // #endregion
82
+ };
83
+ __name(_FRangeHyperlinkMixin, "FRangeHyperlinkMixin");
84
+ let FRangeHyperlinkMixin = _FRangeHyperlinkMixin;
85
+ FRange.extend(FRangeHyperlinkMixin);
86
+ export {
87
+ FWorkbookHyperLinkMixin
88
+ };
package/lib/es/index.js CHANGED
@@ -2,8 +2,10 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
4
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
- import { Disposable, ObjectMatrix, UniverInstanceType, IUniverInstanceService, CommandType, Inject, ICommandService, sequenceExecuteAsync, isValidRange, toDisposable, IResourceManagerService, DependentOn, Injector, Plugin, IConfigService } from "@univerjs/core";
5
+ import { Disposable, ObjectMatrix, UniverInstanceType, IUniverInstanceService, CommandType, Inject, ICommandService, sequenceExecuteAsync, isValidRange, toDisposable, IResourceManagerService, DependentOn, Injector, Plugin, registerDependencies, touchDependencies, IConfigService } from "@univerjs/core";
6
6
  import { Subject } from "rxjs";
7
+ import { E as ERROR_RANGE, A as AddHyperLinkCommand, U as UpdateHyperLinkCommand, C as CancelHyperLinkCommand, a as UpdateRichHyperLinkCommand, b as CancelRichHyperLinkCommand, c as AddRichHyperLinkCommand, S as SHEET_HYPER_LINK_PLUGIN, d as SheetsHyperLinkParserService } from "../parser.service-BQCD3XSg.mjs";
8
+ import { e } from "../parser.service-BQCD3XSg.mjs";
7
9
  import { RefRangeService, SheetsSelectionsService, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests, handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests, UniverSheetsPlugin } from "@univerjs/sheets";
8
10
  import { deserializeRangeWithSheet, serializeRange } from "@univerjs/engine-formula";
9
11
  var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
@@ -140,7 +142,6 @@ let HyperLinkModel = (_a = class extends Disposable {
140
142
  HyperLinkModel = __decorateClass$4([
141
143
  __decorateParam$4(0, IUniverInstanceService)
142
144
  ], HyperLinkModel);
143
- var SheetHyperLinkType = /* @__PURE__ */ ((SheetHyperLinkType2) => (SheetHyperLinkType2.SHEET = "gid", SheetHyperLinkType2.RANGE = "range", SheetHyperLinkType2.DEFINE_NAME = "rangeid", SheetHyperLinkType2.INVALID = "invalid", SheetHyperLinkType2.URL = "url", SheetHyperLinkType2))(SheetHyperLinkType || {});
144
145
  const PLUGIN_CONFIG_KEY = "sheets-hyper-link.config", defaultPluginConfig = {}, AddHyperLinkMutation = {
145
146
  type: CommandType.MUTATION,
146
147
  id: "sheets.mutation.add-hyper-link",
@@ -177,7 +178,7 @@ const PLUGIN_CONFIG_KEY = "sheets-hyper-link.config", defaultPluginConfig = {},
177
178
  const model = accessor.get(HyperLinkModel), { unitId, subUnitId, id, row, column, silent } = params;
178
179
  return model.updateHyperLinkRef(unitId, subUnitId, id, { row, column }, silent);
179
180
  }
180
- }, SHEET_HYPER_LINK_PLUGIN = "SHEET_HYPER_LINK_PLUGIN", ERROR_RANGE = "err";
181
+ };
181
182
  var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
182
183
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
183
184
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
@@ -406,6 +407,12 @@ let SheetsHyperLinkController = (_a3 = class extends Disposable {
406
407
  }
407
408
  _registerCommands() {
408
409
  [
410
+ AddHyperLinkCommand,
411
+ UpdateHyperLinkCommand,
412
+ CancelHyperLinkCommand,
413
+ UpdateRichHyperLinkCommand,
414
+ CancelRichHyperLinkCommand,
415
+ AddRichHyperLinkCommand,
409
416
  AddHyperLinkMutation,
410
417
  UpdateHyperLinkMutation,
411
418
  RemoveHyperLinkMutation,
@@ -418,7 +425,7 @@ let SheetsHyperLinkController = (_a3 = class extends Disposable {
418
425
  SheetsHyperLinkController = __decorateClass$2([
419
426
  __decorateParam$2(0, ICommandService)
420
427
  ], SheetsHyperLinkController);
421
- var R = /* @__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))(R || {}), __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
428
+ 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$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
422
429
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
423
430
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
424
431
  return kind && result && __defProp$1(target, key, result), result;
@@ -445,7 +452,7 @@ let SheetsHyperLinkResourceController = (_a4 = class extends Disposable {
445
452
  this.disposeWithMe(
446
453
  this._resourceManagerService.registerPluginResource({
447
454
  pluginName: SHEET_HYPER_LINK_PLUGIN,
448
- businesses: [R.UNIVER_SHEET],
455
+ businesses: [_.UNIVER_SHEET],
449
456
  toJson: /* @__PURE__ */ __name((unitID) => toJson(unitID), "toJson"),
450
457
  parseJson: /* @__PURE__ */ __name((json) => parseJson(json), "parseJson"),
451
458
  onUnLoad: /* @__PURE__ */ __name((unitID) => {
@@ -478,14 +485,17 @@ let UniverSheetsHyperLinkPlugin = (_a5 = class extends Plugin {
478
485
  this._configService.setConfig(PLUGIN_CONFIG_KEY, rest);
479
486
  }
480
487
  onStarting() {
481
- [
488
+ registerDependencies(this._injector, [
489
+ [SheetsHyperLinkParserService],
482
490
  [SheetsHyperLinkResourceController],
483
491
  [SheetsHyperLinkController],
484
492
  [SheetsHyperLinkRefRangeController],
485
493
  [HyperLinkModel]
486
- ].forEach((dep) => {
487
- this._injector.add(dep);
488
- }), this._injector.get(SheetsHyperLinkRefRangeController), this._injector.get(SheetsHyperLinkResourceController), this._injector.get(SheetsHyperLinkController);
494
+ ]), touchDependencies(this._injector, [
495
+ [SheetsHyperLinkRefRangeController],
496
+ [SheetsHyperLinkResourceController],
497
+ [SheetsHyperLinkController]
498
+ ]);
489
499
  }
490
500
  }, __name(_a5, "UniverSheetsHyperLinkPlugin"), _a5);
491
501
  __publicField2(UniverSheetsHyperLinkPlugin, "pluginName", SHEET_HYPER_LINK_PLUGIN);
@@ -496,12 +506,19 @@ UniverSheetsHyperLinkPlugin = __decorateClass([
496
506
  __decorateParam(2, IConfigService)
497
507
  ], UniverSheetsHyperLinkPlugin);
498
508
  export {
509
+ AddHyperLinkCommand,
499
510
  AddHyperLinkMutation,
511
+ AddRichHyperLinkCommand,
512
+ CancelHyperLinkCommand,
513
+ CancelRichHyperLinkCommand,
500
514
  ERROR_RANGE,
501
515
  HyperLinkModel,
502
516
  RemoveHyperLinkMutation,
503
- SheetHyperLinkType,
517
+ e as SheetHyperLinkType,
518
+ SheetsHyperLinkParserService,
504
519
  UniverSheetsHyperLinkPlugin,
520
+ UpdateHyperLinkCommand,
505
521
  UpdateHyperLinkMutation,
506
- UpdateHyperLinkRefMutation
522
+ UpdateHyperLinkRefMutation,
523
+ UpdateRichHyperLinkCommand
507
524
  };
@@ -0,0 +1,394 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
3
+ import { CommandType, ICommandService, IUndoRedoService, IUniverInstanceService, Tools, BuildTextUtils, DataStreamTreeTokenType, CustomRangeType, TextX, CellValueType, sequenceExecuteAsync, generateRandomId, sequenceExecute, UniverInstanceType, getBodySlice, Inject, LocaleService, isValidRange } from "@univerjs/core";
4
+ import { addCustomRangeBySelectionFactory, deleteCustomRangeFactory, replaceSelectionFactory } from "@univerjs/docs";
5
+ import { SheetInterceptorService, getSheetCommandTarget, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory } from "@univerjs/sheets";
6
+ import { HyperLinkModel, RemoveHyperLinkMutation, AddHyperLinkMutation } from "@univerjs/sheets-hyper-link";
7
+ import { serializeRange, deserializeRangeWithSheet, serializeRangeWithSheet, IDefinedNamesService } from "@univerjs/engine-formula";
8
+ var SheetHyperLinkType = /* @__PURE__ */ ((SheetHyperLinkType2) => (SheetHyperLinkType2.SHEET = "gid", SheetHyperLinkType2.RANGE = "range", SheetHyperLinkType2.DEFINE_NAME = "rangeid", SheetHyperLinkType2.INVALID = "invalid", SheetHyperLinkType2.URL = "url", SheetHyperLinkType2))(SheetHyperLinkType || {});
9
+ const SHEET_HYPER_LINK_PLUGIN = "SHEET_HYPER_LINK_PLUGIN", ERROR_RANGE = "err", AddHyperLinkCommand = {
10
+ type: CommandType.COMMAND,
11
+ id: "sheets.command.add-hyper-link",
12
+ // eslint-disable-next-line max-lines-per-function
13
+ async handler(accessor, params) {
14
+ if (!params) return !1;
15
+ 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);
16
+ if (!target) return !1;
17
+ 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);
18
+ if (!body) return !1;
19
+ let textX;
20
+ if (display ? textX = BuildTextUtils.selection.replace({
21
+ selection: {
22
+ startOffset: 0,
23
+ endOffset: body.dataStream.length - 2,
24
+ collapsed: !0
25
+ },
26
+ body: {
27
+ dataStream: `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${display}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`,
28
+ customRanges: [{
29
+ startIndex: 0,
30
+ endIndex: display.length + 1,
31
+ rangeType: CustomRangeType.HYPERLINK,
32
+ rangeId: id,
33
+ properties: {
34
+ url: payload
35
+ // refId: id,
36
+ }
37
+ }]
38
+ },
39
+ doc: doc.documentModel
40
+ }) : textX = BuildTextUtils.customRange.add({
41
+ body,
42
+ range: { startOffset: 0, endOffset: body.dataStream.length - 2, collapsed: !1 },
43
+ rangeId: id,
44
+ rangeType: CustomRangeType.HYPERLINK,
45
+ properties: {
46
+ url: payload,
47
+ refId: id
48
+ }
49
+ }), !textX) return !1;
50
+ const newBody = TextX.apply(body, textX.serialize()), newCellData = {
51
+ p: {
52
+ ...snapshot,
53
+ body: newBody
54
+ },
55
+ t: CellValueType.STRING
56
+ }, finalCellData = await sheetInterceptorService.onWriteCell(workbook, worksheet, row, column, newCellData), redoParams = {
57
+ unitId,
58
+ subUnitId,
59
+ cellValue: {
60
+ [link.row]: {
61
+ [link.column]: finalCellData
62
+ }
63
+ }
64
+ }, redo = {
65
+ id: SetRangeValuesMutation.id,
66
+ params: redoParams
67
+ }, undoParams = SetRangeValuesUndoMutationFactory(accessor, redoParams), undo = {
68
+ id: SetRangeValuesMutation.id,
69
+ params: undoParams
70
+ }, redos = [redo], undos = [undo], modelLink = hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
71
+ return modelLink && (redos.push({
72
+ id: RemoveHyperLinkMutation.id,
73
+ params: {
74
+ unitId,
75
+ subUnitId,
76
+ id: modelLink.id
77
+ }
78
+ }), undos.push({
79
+ id: AddHyperLinkMutation.id,
80
+ params: {
81
+ unitId,
82
+ subUnitId,
83
+ link: modelLink
84
+ }
85
+ })), await sequenceExecuteAsync(redos, commandService) ? (undoRedoService.pushUndoRedo({
86
+ redoMutations: redos,
87
+ undoMutations: undos,
88
+ unitID: unitId
89
+ }), !0) : !1;
90
+ }
91
+ }, AddRichHyperLinkCommand = {
92
+ id: "sheets.command.add-rich-hyper-link",
93
+ type: CommandType.COMMAND,
94
+ handler: /* @__PURE__ */ __name(async (accessor, params) => {
95
+ if (!params)
96
+ return !1;
97
+ const { documentId, link } = params, commandService = accessor.get(ICommandService), newId = generateRandomId(), { payload } = link, replaceSelection = addCustomRangeBySelectionFactory(accessor, {
98
+ unitId: documentId,
99
+ rangeId: newId,
100
+ rangeType: CustomRangeType.HYPERLINK,
101
+ properties: {
102
+ url: payload,
103
+ refId: newId
104
+ }
105
+ });
106
+ return replaceSelection ? commandService.syncExecuteCommand(replaceSelection.id, replaceSelection.params) : !1;
107
+ }, "handler")
108
+ }, CancelHyperLinkCommand = {
109
+ type: CommandType.COMMAND,
110
+ id: "sheets.command.cancel-hyper-link",
111
+ // eslint-disable-next-line max-lines-per-function
112
+ handler(accessor, params) {
113
+ var _a2, _b;
114
+ if (!params) return !1;
115
+ const commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), instanceSrv = accessor.get(IUniverInstanceService), hyperLinkModel = accessor.get(HyperLinkModel), target = getSheetCommandTarget(instanceSrv, params);
116
+ if (!target) return !1;
117
+ const { row, column, id } = params, { unitId, subUnitId, worksheet } = target, cellData = worksheet.getCell(row, column);
118
+ if (!cellData) return !1;
119
+ const doc = worksheet.getCellDocumentModelWithFormula(cellData);
120
+ if (!(doc != null && doc.documentModel)) return !1;
121
+ const snapshot = Tools.deepClone(doc.documentModel.getSnapshot());
122
+ if (!((_b = (_a2 = snapshot.body) == null ? void 0 : _a2.customRanges) == null ? void 0 : _b.find((range2) => range2.rangeId === id))) return !1;
123
+ const textX = BuildTextUtils.customRange.delete(accessor, { documentDataModel: doc.documentModel, rangeId: id });
124
+ if (!textX) return !1;
125
+ const newBody = TextX.apply(snapshot.body, textX.serialize()), redos = [], undos = [], setRangeParams = {
126
+ unitId,
127
+ subUnitId,
128
+ cellValue: {
129
+ [row]: {
130
+ [column]: {
131
+ p: {
132
+ ...snapshot,
133
+ body: newBody
134
+ },
135
+ t: CellValueType.STRING
136
+ }
137
+ }
138
+ }
139
+ };
140
+ redos.push({
141
+ id: SetRangeValuesMutation.id,
142
+ params: setRangeParams
143
+ });
144
+ const undoParams = SetRangeValuesUndoMutationFactory(accessor, setRangeParams);
145
+ undos.push({
146
+ id: SetRangeValuesMutation.id,
147
+ params: undoParams
148
+ });
149
+ const link = hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
150
+ return link && (redos.push({
151
+ id: RemoveHyperLinkMutation.id,
152
+ params: {
153
+ unitId,
154
+ subUnitId,
155
+ id
156
+ }
157
+ }), undos.push({
158
+ id: AddHyperLinkMutation.id,
159
+ params: {
160
+ unitId,
161
+ subUnitId,
162
+ link: {
163
+ ...link
164
+ }
165
+ }
166
+ })), sequenceExecute(redos, commandService).result ? (undoRedoService.pushUndoRedo({
167
+ redoMutations: redos,
168
+ undoMutations: undos,
169
+ unitID: unitId
170
+ }), !0) : !1;
171
+ }
172
+ }, CancelRichHyperLinkCommand = {
173
+ type: CommandType.COMMAND,
174
+ id: "sheets.command.cancel-rich-hyper-link",
175
+ handler(accessor, params) {
176
+ var _a2, _b;
177
+ if (!params)
178
+ return !1;
179
+ const { id: linkId, documentId } = params, commandService = accessor.get(ICommandService), doc = accessor.get(IUniverInstanceService).getUnit(documentId, UniverInstanceType.UNIVER_DOC), link = (_b = (_a2 = doc == null ? void 0 : doc.getBody()) == null ? void 0 : _a2.customRanges) == null ? void 0 : _b.find((i) => i.rangeId === linkId);
180
+ let insert = null;
181
+ link && link.endIndex === doc.getBody().dataStream.length - 3 && (insert = {
182
+ dataStream: " "
183
+ });
184
+ const doMutation = deleteCustomRangeFactory(accessor, { unitId: documentId, rangeId: linkId, insert });
185
+ return doMutation ? commandService.syncExecuteCommand(doMutation.id, doMutation.params) : !1;
186
+ }
187
+ }, UpdateHyperLinkCommand = {
188
+ type: CommandType.COMMAND,
189
+ id: "sheets.command.update-hyper-link",
190
+ // eslint-disable-next-line max-lines-per-function
191
+ async handler(accessor, params) {
192
+ var _a2, _b, _c;
193
+ if (!params) return !1;
194
+ const commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), instanceSrv = accessor.get(IUniverInstanceService), hyperLinkModel = accessor.get(HyperLinkModel), interceptorService = accessor.get(SheetInterceptorService), target = getSheetCommandTarget(instanceSrv);
195
+ if (!target) return !1;
196
+ const { payload: link, row, column, id } = params, { workbook, worksheet, unitId, subUnitId } = target, { payload, display = "" } = link, cellData = worksheet.getCell(row, column);
197
+ if (!cellData) return !1;
198
+ const doc = worksheet.getCellDocumentModelWithFormula(cellData);
199
+ if (!(doc != null && doc.documentModel)) return !1;
200
+ const snapshot = doc.documentModel.getSnapshot(), range = (_b = (_a2 = snapshot.body) == null ? void 0 : _a2.customRanges) == null ? void 0 : _b.find((range2) => range2.rangeId === id);
201
+ if (!range) return !1;
202
+ const newId = generateRandomId(), textRun = (_c = getBodySlice(doc.documentModel.getBody(), range.startIndex, range.endIndex + 1).textRuns) == null ? void 0 : _c[0];
203
+ textRun && (textRun.ed = display.length + 1);
204
+ const replaceSelection = replaceSelectionFactory(accessor, {
205
+ unitId,
206
+ body: {
207
+ dataStream: `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${display}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`,
208
+ customRanges: [{
209
+ rangeId: newId,
210
+ rangeType: CustomRangeType.HYPERLINK,
211
+ startIndex: 0,
212
+ endIndex: display.length + 1,
213
+ properties: {
214
+ url: payload
215
+ }
216
+ }],
217
+ textRuns: textRun ? [textRun] : void 0
218
+ },
219
+ selection: {
220
+ startOffset: range.startIndex,
221
+ endOffset: range.endIndex + 1,
222
+ collapsed: !1
223
+ },
224
+ doc: doc.documentModel
225
+ });
226
+ if (!replaceSelection)
227
+ return !1;
228
+ const newBody = TextX.apply(Tools.deepClone(snapshot.body), replaceSelection.textX.serialize()), newCellData = {
229
+ p: {
230
+ ...snapshot,
231
+ body: newBody
232
+ },
233
+ t: CellValueType.STRING
234
+ }, finalCellData = await interceptorService.onWriteCell(workbook, worksheet, row, column, newCellData), redo = {
235
+ id: SetRangeValuesMutation.id,
236
+ params: {
237
+ unitId,
238
+ subUnitId,
239
+ cellValue: {
240
+ [row]: {
241
+ [column]: finalCellData
242
+ }
243
+ }
244
+ }
245
+ }, undoParams = SetRangeValuesUndoMutationFactory(accessor, redo.params), undo = {
246
+ id: SetRangeValuesMutation.id,
247
+ params: undoParams
248
+ }, redos = [redo], undos = [undo], modelLink = hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
249
+ return modelLink && (redos.push({
250
+ id: RemoveHyperLinkMutation.id,
251
+ params: {
252
+ unitId,
253
+ subUnitId,
254
+ id: modelLink.id
255
+ }
256
+ }), undos.push({
257
+ id: AddHyperLinkMutation.id,
258
+ params: {
259
+ unitId,
260
+ subUnitId,
261
+ link: modelLink
262
+ }
263
+ })), await sequenceExecuteAsync(redos, commandService) ? (undoRedoService.pushUndoRedo({
264
+ redoMutations: redos,
265
+ undoMutations: undos,
266
+ unitID: unitId
267
+ }), !0) : !1;
268
+ }
269
+ }, UpdateRichHyperLinkCommand = {
270
+ type: CommandType.COMMAND,
271
+ id: "sheets.command.update-rich-hyper-link",
272
+ handler: /* @__PURE__ */ __name((accessor, params) => {
273
+ var _a2, _b, _c, _d;
274
+ if (!params)
275
+ return !1;
276
+ const { documentId: unitId, payload, id: rangeId } = params, univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), doc = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
277
+ if (!doc)
278
+ return !1;
279
+ const range = (_b = (_a2 = doc.getBody()) == null ? void 0 : _a2.customRanges) == null ? void 0 : _b.find((range2) => range2.rangeId === rangeId);
280
+ if (!range)
281
+ return !1;
282
+ 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];
283
+ textRun && (textRun.ed = display.length + 1);
284
+ const replaceSelection = replaceSelectionFactory(accessor, {
285
+ unitId,
286
+ body: {
287
+ dataStream: `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${display}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`,
288
+ customRanges: [{
289
+ rangeId: newId,
290
+ rangeType: CustomRangeType.HYPERLINK,
291
+ startIndex: 0,
292
+ endIndex: display.length + 1,
293
+ properties: {
294
+ url: payload.payload
295
+ }
296
+ }],
297
+ textRuns: textRun ? [textRun] : void 0
298
+ },
299
+ selection: {
300
+ startOffset: range.startIndex,
301
+ endOffset: range.endIndex + 1,
302
+ collapsed: !1
303
+ },
304
+ doc
305
+ });
306
+ return replaceSelection ? commandService.syncExecuteCommand(replaceSelection.id, replaceSelection.params) : !1;
307
+ }, "handler")
308
+ };
309
+ var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
310
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
311
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
312
+ return kind && result && __defProp2(target, key, result), result;
313
+ }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), _a;
314
+ let SheetsHyperLinkParserService = (_a = class {
315
+ constructor(_univerInstanceService, _localeService, _definedNamesService) {
316
+ this._univerInstanceService = _univerInstanceService, this._localeService = _localeService, this._definedNamesService = _definedNamesService;
317
+ }
318
+ buildHyperLink(unitId, sheetId, range) {
319
+ return `#${SheetHyperLinkType.SHEET}=${sheetId}${range ? `&${typeof range == "string" ? SheetHyperLinkType.DEFINE_NAME : SheetHyperLinkType.RANGE}=${typeof range == "string" ? range : serializeRange(range)}` : ""}`;
320
+ }
321
+ parseHyperLink(urlStr) {
322
+ var _a2, _b, _c, _d;
323
+ if (urlStr.startsWith("#")) {
324
+ const search = new URLSearchParams(urlStr.slice(1)), searchObj = {
325
+ gid: (_a2 = search.get("gid")) != null ? _a2 : "",
326
+ range: (_b = search.get("range")) != null ? _b : "",
327
+ rangeid: (_c = search.get("rangeid")) != null ? _c : "",
328
+ unitid: (_d = search.get("unitid")) != null ? _d : ""
329
+ }, urlInfo = this._getURLName(searchObj);
330
+ return {
331
+ type: urlInfo.type,
332
+ name: urlInfo.name,
333
+ url: urlStr,
334
+ searchObj
335
+ };
336
+ } else
337
+ return {
338
+ type: SheetHyperLinkType.URL,
339
+ name: urlStr,
340
+ url: urlStr,
341
+ searchObj: null
342
+ };
343
+ }
344
+ _getURLName(params) {
345
+ var _a2;
346
+ const { gid, range, rangeid, unitid } = params, workbook = unitid ? this._univerInstanceService.getUnit(unitid, UniverInstanceType.UNIVER_SHEET) : this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET), invalidLink = {
347
+ type: SheetHyperLinkType.INVALID,
348
+ name: this._localeService.t("hyperLink.message.refError")
349
+ };
350
+ if (!workbook)
351
+ return invalidLink;
352
+ const sheet = gid ? workbook.getSheetBySheetId(gid) : workbook.getActiveSheet(), sheetName = (_a2 = sheet == null ? void 0 : sheet.getName()) != null ? _a2 : "";
353
+ if (range) {
354
+ if (!sheet) return invalidLink;
355
+ const rangeObj = deserializeRangeWithSheet(range).range;
356
+ return isValidRange(rangeObj, sheet) && range !== ERROR_RANGE ? {
357
+ type: SheetHyperLinkType.RANGE,
358
+ name: serializeRangeWithSheet(sheetName, rangeObj)
359
+ } : invalidLink;
360
+ }
361
+ if (rangeid) {
362
+ const range2 = this._definedNamesService.getValueById(workbook.getUnitId(), rangeid);
363
+ return range2 ? {
364
+ type: SheetHyperLinkType.DEFINE_NAME,
365
+ name: range2.formulaOrRefString
366
+ } : invalidLink;
367
+ }
368
+ if (gid) {
369
+ const worksheet = workbook.getSheetBySheetId(gid);
370
+ return worksheet ? {
371
+ type: SheetHyperLinkType.SHEET,
372
+ name: worksheet.getName()
373
+ } : invalidLink;
374
+ }
375
+ return invalidLink;
376
+ }
377
+ }, __name(_a, "SheetsHyperLinkParserService"), _a);
378
+ SheetsHyperLinkParserService = __decorateClass([
379
+ __decorateParam(0, IUniverInstanceService),
380
+ __decorateParam(1, Inject(LocaleService)),
381
+ __decorateParam(2, IDefinedNamesService)
382
+ ], SheetsHyperLinkParserService);
383
+ export {
384
+ AddHyperLinkCommand as A,
385
+ CancelHyperLinkCommand as C,
386
+ ERROR_RANGE as E,
387
+ SHEET_HYPER_LINK_PLUGIN as S,
388
+ UpdateHyperLinkCommand as U,
389
+ UpdateRichHyperLinkCommand as a,
390
+ CancelRichHyperLinkCommand as b,
391
+ AddRichHyperLinkCommand as c,
392
+ SheetsHyperLinkParserService as d,
393
+ SheetHyperLinkType as e
394
+ };
@@ -0,0 +1,19 @@
1
+ import { ICommand } from '@univerjs/core';
2
+ import { ICellHyperLink } from '@univerjs/sheets-hyper-link';
3
+ export interface IAddHyperLinkCommandParams {
4
+ unitId: string;
5
+ subUnitId: string;
6
+ link: ICellHyperLink;
7
+ }
8
+ /**
9
+ * Command for add hyperlink
10
+ */
11
+ export declare const AddHyperLinkCommand: ICommand<IAddHyperLinkCommandParams>;
12
+ export interface IAddRichHyperLinkCommandParams {
13
+ /**
14
+ * url of link
15
+ */
16
+ documentId: string;
17
+ link: ICellHyperLink;
18
+ }
19
+ export declare const AddRichHyperLinkCommand: ICommand<IAddRichHyperLinkCommandParams>;
@@ -0,0 +1,19 @@
1
+ import { ICommand } from '@univerjs/core';
2
+ export interface ICancelHyperLinkCommandParams {
3
+ unitId: string;
4
+ subUnitId: string;
5
+ /**
6
+ * id of link
7
+ */
8
+ id: string;
9
+ row: number;
10
+ column: number;
11
+ }
12
+ export declare const CancelHyperLinkCommand: ICommand<ICancelHyperLinkCommandParams>;
13
+ export interface ICancelRichHyperLinkCommandParams extends ICancelHyperLinkCommandParams {
14
+ /**
15
+ * document id
16
+ */
17
+ documentId: string;
18
+ }
19
+ export declare const CancelRichHyperLinkCommand: ICommand<ICancelRichHyperLinkCommandParams>;
@@ -0,0 +1,17 @@
1
+ import { ICommand } from '@univerjs/core';
2
+ import { ICellLinkContent } from '@univerjs/sheets-hyper-link';
3
+ export interface IUpdateHyperLinkCommandParams {
4
+ unitId: string;
5
+ subUnitId: string;
6
+ id: string;
7
+ payload: ICellLinkContent;
8
+ row: number;
9
+ column: number;
10
+ }
11
+ export declare const UpdateHyperLinkCommand: ICommand<IUpdateHyperLinkCommandParams>;
12
+ export interface IUpdateRichHyperLinkCommandParams {
13
+ documentId: string;
14
+ id: string;
15
+ payload: ICellLinkContent;
16
+ }
17
+ export declare const UpdateRichHyperLinkCommand: ICommand<IUpdateRichHyperLinkCommandParams>;
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export interface ICellHyperLink {
17
+ id: string;
18
+ startIndex: number;
19
+ endIndex: number;
20
+ url: string;
21
+ label: string;
22
+ }
23
+ interface IFRangeHyperlinkMixin {
24
+ /**
25
+ * Get all hyperlinks in the cell in the range.
26
+ * @returns hyperlinks
27
+ */
28
+ getHyperLinks(): ICellHyperLink[];
29
+ /**
30
+ * Update hyperlink in the cell in the range.
31
+ * @param id id of the hyperlink
32
+ * @param url url
33
+ * @param label optional, label of the url
34
+ * @returns success or not
35
+ */
36
+ updateHyperLink(id: string, url: string, label?: string): Promise<boolean>;
37
+ /**
38
+ * Cancel hyperlink in the cell in the range.
39
+ * @param id id of the hyperlink
40
+ * @returns success or not
41
+ */
42
+ cancelHyperLink(id: string): Promise<boolean>;
43
+ }
44
+ declare module '@univerjs/sheets/facade' {
45
+ interface FRange extends IFRangeHyperlinkMixin {
46
+ }
47
+ }
48
+ export {};
@@ -0,0 +1,32 @@
1
+ import { IRange } from '@univerjs/core';
2
+ import { ISheetHyperLinkInfo } from '../services/parser.service';
3
+ import { FWorkbook } from '@univerjs/sheets/facade';
4
+ interface IFWorkbookHyperlinkMixin {
5
+ /**
6
+ * create a hyperlink for the sheet
7
+ * @param sheetId the sheet id to link
8
+ * @param range the range to link, or define-name id
9
+ * @returns the hyperlink string
10
+ */
11
+ createSheetHyperlink(this: FWorkbook, sheetId: string, range?: string | IRange): string;
12
+ /**
13
+ * parse the hyperlink string to get the hyperlink info
14
+ * @param hyperlink the hyperlink string
15
+ * @returns the hyperlink info
16
+ */
17
+ parseSheetHyperlink(this: FWorkbook, hyperlink: string): ISheetHyperLinkInfo;
18
+ }
19
+ export declare class FWorkbookHyperLinkMixin extends FWorkbook implements IFWorkbookHyperlinkMixin {
20
+ createSheetHyperlink(sheetId: string, range?: string | IRange): string;
21
+ /**
22
+ * parse the hyperlink string to get the hyperlink info
23
+ * @param hyperlink the hyperlink string
24
+ * @returns the hyperlink info
25
+ */
26
+ parseSheetHyperlink(hyperlink: string): ISheetHyperLinkInfo;
27
+ }
28
+ declare module '@univerjs/sheets/facade' {
29
+ interface FWorkbook extends IFWorkbookHyperlinkMixin {
30
+ }
31
+ }
32
+ export {};
@@ -0,0 +1 @@
1
+ export { FWorkbookHyperLinkMixin } from './f-workbook';
@@ -17,7 +17,11 @@ export { HyperLinkModel } from './models/hyper-link.model';
17
17
  export { SheetHyperLinkType } from './types/enums/hyper-link-type';
18
18
  export { UniverSheetsHyperLinkPlugin } from './plugin';
19
19
  export type { ICellHyperLink, ICellLinkContent } from './types/interfaces/i-hyper-link';
20
+ export { type ISheetHyperLinkInfo, type ISheetUrlParams, SheetsHyperLinkParserService } from './services/parser.service';
20
21
  export { ERROR_RANGE } from './types/const';
22
+ export { AddHyperLinkCommand, AddRichHyperLinkCommand, type IAddHyperLinkCommandParams, type IAddRichHyperLinkCommandParams } from './commands/commands/add-hyper-link.command';
23
+ export { CancelHyperLinkCommand, CancelRichHyperLinkCommand, type ICancelHyperLinkCommandParams, type ICancelRichHyperLinkCommandParams } from './commands/commands/remove-hyper-link.command';
24
+ export { type IUpdateHyperLinkCommandParams, type IUpdateRichHyperLinkCommandParams, UpdateHyperLinkCommand, UpdateRichHyperLinkCommand } from './commands/commands/update-hyper-link.command';
21
25
  export { AddHyperLinkMutation, type IAddHyperLinkMutationParams } from './commands/mutations/add-hyper-link.mutation';
22
26
  export { type IRemoveHyperLinkMutationParams, RemoveHyperLinkMutation } from './commands/mutations/remove-hyper-link.mutation';
23
27
  export { type IUpdateHyperLinkMutationParams, type IUpdateHyperLinkRefMutationParams, UpdateHyperLinkMutation, UpdateHyperLinkRefMutation, } from './commands/mutations/update-hyper-link.mutation';
@@ -0,0 +1,24 @@
1
+ import { IRange, Nullable, IUniverInstanceService, LocaleService } from '@univerjs/core';
2
+ import { IDefinedNamesService } from '@univerjs/engine-formula';
3
+ import { SheetHyperLinkType } from '../types/enums/hyper-link-type';
4
+ export interface ISheetUrlParams {
5
+ gid?: string;
6
+ range?: string;
7
+ rangeid?: string;
8
+ unitid?: string;
9
+ }
10
+ export interface ISheetHyperLinkInfo {
11
+ type: SheetHyperLinkType;
12
+ name: string;
13
+ url: string;
14
+ searchObj: Nullable<ISheetUrlParams>;
15
+ }
16
+ export declare class SheetsHyperLinkParserService {
17
+ private _univerInstanceService;
18
+ private _localeService;
19
+ private _definedNamesService;
20
+ constructor(_univerInstanceService: IUniverInstanceService, _localeService: LocaleService, _definedNamesService: IDefinedNamesService);
21
+ buildHyperLink(unitId: string, sheetId: string, range?: string | IRange): string;
22
+ parseHyperLink(urlStr: string): ISheetHyperLinkInfo;
23
+ private _getURLName;
24
+ }
@@ -0,0 +1 @@
1
+ (function(R,U){typeof exports=="object"&&typeof module<"u"?U(exports,require("@univerjs/sheets/facade"),require("@univerjs/core"),require("@univerjs/engine-formula"),require("@univerjs/docs"),require("@univerjs/sheets"),require("@univerjs/sheets-hyper-link")):typeof define=="function"&&define.amd?define(["exports","@univerjs/sheets/facade","@univerjs/core","@univerjs/engine-formula","@univerjs/docs","@univerjs/sheets","@univerjs/sheets-hyper-link"],U):(R=typeof globalThis<"u"?globalThis:R||self,U(R.UniverSheetsHyperLinkFacade={},R["UniverSheets/facade"],R.UniverCore,R.UniverEngineFormula,R.UniverDocs,R.UniverSheets,R.UniverSheetsHyperLink))})(this,function(R,U,e,H,B,y,C){"use strict";const X="err";var k=(t=>(t.SHEET="gid",t.RANGE="range",t.DEFINE_NAME="rangeid",t.INVALID="invalid",t.URL="url",t))(k||{}),Y=Object.defineProperty,J=Object.getOwnPropertyDescriptor,Q=(t,n,a,r)=>{for(var s=r>1?void 0:r?J(n,a):n,i=t.length-1,o;i>=0;i--)(o=t[i])&&(s=(r?o(n,a,s):o(s))||s);return r&&s&&Y(n,a,s),s},P=(t,n)=>(a,r)=>n(a,r,t);let V=class{constructor(t,n,a){this._univerInstanceService=t,this._localeService=n,this._definedNamesService=a}buildHyperLink(t,n,a){return`#${k.SHEET}=${n}${a?`&${typeof a=="string"?k.DEFINE_NAME:k.RANGE}=${typeof a=="string"?a:H.serializeRange(a)}`:""}`}parseHyperLink(t){var n,a,r,s;if(t.startsWith("#")){const i=new URLSearchParams(t.slice(1)),o={gid:(n=i.get("gid"))!=null?n:"",range:(a=i.get("range"))!=null?a:"",rangeid:(r=i.get("rangeid"))!=null?r:"",unitid:(s=i.get("unitid"))!=null?s:""},d=this._getURLName(o);return{type:d.type,name:d.name,url:t,searchObj:o}}else return{type:k.URL,name:t,url:t,searchObj:null}}_getURLName(t){var u;const{gid:n,range:a,rangeid:r,unitid:s}=t,i=s?this._univerInstanceService.getUnit(s,e.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SHEET),o={type:k.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!i)return o;const d=n?i.getSheetBySheetId(n):i.getActiveSheet(),c=(u=d==null?void 0:d.getName())!=null?u:"";if(a){if(!d)return o;const l=H.deserializeRangeWithSheet(a).range;return e.isValidRange(l,d)&&a!==X?{type:k.RANGE,name:H.serializeRangeWithSheet(c,l)}:o}if(r){const l=this._definedNamesService.getValueById(i.getUnitId(),r);return l?{type:k.DEFINE_NAME,name:l.formulaOrRefString}:o}if(n){const l=i.getSheetBySheetId(n);return l?{type:k.SHEET,name:l.getName()}:o}return o}};V=Q([P(0,e.IUniverInstanceService),P(1,e.Inject(e.LocaleService)),P(2,H.IDefinedNamesService)],V);class W extends U.FWorkbook{createSheetHyperlink(n,a){return this._injector.get(V).buildHyperLink(this.getId(),n,a)}parseSheetHyperlink(n){return this._injector.get(V).parseHyperLink(n)}}U.FWorkbook.extend(W);const Z={type:e.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(t,n){if(!n)return!1;const a=t.get(e.ICommandService),r=t.get(e.IUndoRedoService),s=t.get(e.IUniverInstanceService),i=t.get(C.HyperLinkModel),o=t.get(y.SheetInterceptorService),d=y.getSheetCommandTarget(s,n);if(!d)return!1;const{unitId:c,subUnitId:u,workbook:l,worksheet:I}=d,{link:p}=n,{payload:h,display:m,row:g,column:M,id:v}=p,x=I.getCell(g,M),f=I.getBlankCellDocumentModel(x),T=f.documentModel.getSnapshot(),S=e.Tools.deepClone(T.body);if(!S)return!1;let _;if(m?_=e.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:S.dataStream.length-2,collapsed:!0},body:{dataStream:`${e.DataStreamTreeTokenType.CUSTOM_RANGE_START}${m}${e.DataStreamTreeTokenType.CUSTOM_RANGE_END}`,customRanges:[{startIndex:0,endIndex:m.length+1,rangeType:e.CustomRangeType.HYPERLINK,rangeId:v,properties:{url:h}}]},doc:f.documentModel}):_=e.BuildTextUtils.customRange.add({body:S,range:{startOffset:0,endOffset:S.dataStream.length-2,collapsed:!1},rangeId:v,rangeType:e.CustomRangeType.HYPERLINK,properties:{url:h,refId:v}}),!_)return!1;const O=e.TextX.apply(S,_.serialize()),E={p:{...T,body:O},t:e.CellValueType.STRING},D=await o.onWriteCell(l,I,g,M,E),L={unitId:c,subUnitId:u,cellValue:{[p.row]:{[p.column]:D}}},$={id:y.SetRangeValuesMutation.id,params:L},j=y.SetRangeValuesUndoMutationFactory(t,L),G={id:y.SetRangeValuesMutation.id,params:j},A=[$],w=[G],b=i.getHyperLinkByLocation(c,u,g,M);return b&&(A.push({id:C.RemoveHyperLinkMutation.id,params:{unitId:c,subUnitId:u,id:b.id}}),w.push({id:C.AddHyperLinkMutation.id,params:{unitId:c,subUnitId:u,link:b}})),await e.sequenceExecuteAsync(A,a)?(r.pushUndoRedo({redoMutations:A,undoMutations:w,unitID:c}),!0):!1}};e.CommandType.COMMAND;const ee={type:e.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(t,n){var E,D;if(!n)return!1;const a=t.get(e.ICommandService),r=t.get(e.IUndoRedoService),s=t.get(e.IUniverInstanceService),i=t.get(C.HyperLinkModel),o=y.getSheetCommandTarget(s,n);if(!o)return!1;const{row:d,column:c,id:u}=n,{unitId:l,subUnitId:I,worksheet:p}=o,h=p.getCell(d,c);if(!h)return!1;const m=p.getCellDocumentModelWithFormula(h);if(!(m!=null&&m.documentModel))return!1;const g=e.Tools.deepClone(m.documentModel.getSnapshot());if(!((D=(E=g.body)==null?void 0:E.customRanges)==null?void 0:D.find(L=>L.rangeId===u)))return!1;const v=e.BuildTextUtils.customRange.delete(t,{documentDataModel:m.documentModel,rangeId:u});if(!v)return!1;const x=e.TextX.apply(g.body,v.serialize()),f=[],T=[],S={unitId:l,subUnitId:I,cellValue:{[d]:{[c]:{p:{...g,body:x},t:e.CellValueType.STRING}}}};f.push({id:y.SetRangeValuesMutation.id,params:S});const _=y.SetRangeValuesUndoMutationFactory(t,S);T.push({id:y.SetRangeValuesMutation.id,params:_});const O=i.getHyperLinkByLocation(l,I,d,c);return O&&(f.push({id:C.RemoveHyperLinkMutation.id,params:{unitId:l,subUnitId:I,id:u}}),T.push({id:C.AddHyperLinkMutation.id,params:{unitId:l,subUnitId:I,link:{...O}}})),e.sequenceExecute(f,a).result?(r.pushUndoRedo({redoMutations:f,undoMutations:T,unitID:l}),!0):!1}};e.CommandType.COMMAND;const te={type:e.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(t,n){var q,z,K;if(!n)return!1;const a=t.get(e.ICommandService),r=t.get(e.IUndoRedoService),s=t.get(e.IUniverInstanceService),i=t.get(C.HyperLinkModel),o=t.get(y.SheetInterceptorService),d=y.getSheetCommandTarget(s);if(!d)return!1;const{payload:c,row:u,column:l,id:I}=n,{workbook:p,worksheet:h,unitId:m,subUnitId:g}=d,{payload:M,display:v=""}=c,x=h.getCell(u,l);if(!x)return!1;const f=h.getCellDocumentModelWithFormula(x);if(!(f!=null&&f.documentModel))return!1;const T=f.documentModel.getSnapshot(),S=(z=(q=T.body)==null?void 0:q.customRanges)==null?void 0:z.find(ae=>ae.rangeId===I);if(!S)return!1;const _=e.generateRandomId(),N=(K=e.getBodySlice(f.documentModel.getBody(),S.startIndex,S.endIndex+1).textRuns)==null?void 0:K[0];N&&(N.ed=v.length+1);const E=B.replaceSelectionFactory(t,{unitId:m,body:{dataStream:`${e.DataStreamTreeTokenType.CUSTOM_RANGE_START}${v}${e.DataStreamTreeTokenType.CUSTOM_RANGE_END}`,customRanges:[{rangeId:_,rangeType:e.CustomRangeType.HYPERLINK,startIndex:0,endIndex:v.length+1,properties:{url:M}}],textRuns:N?[N]:void 0},selection:{startOffset:S.startIndex,endOffset:S.endIndex+1,collapsed:!1},doc:f.documentModel});if(!E)return!1;const D=e.TextX.apply(e.Tools.deepClone(T.body),E.textX.serialize()),L={p:{...T,body:D},t:e.CellValueType.STRING},$=await o.onWriteCell(p,h,u,l,L),j={id:y.SetRangeValuesMutation.id,params:{unitId:m,subUnitId:g,cellValue:{[u]:{[l]:$}}}},G=y.SetRangeValuesUndoMutationFactory(t,j.params),A={id:y.SetRangeValuesMutation.id,params:G},w=[j],b=[A],F=i.getHyperLinkByLocation(m,g,u,l);return F&&(w.push({id:C.RemoveHyperLinkMutation.id,params:{unitId:m,subUnitId:g,id:F.id}}),b.push({id:C.AddHyperLinkMutation.id,params:{unitId:m,subUnitId:g,link:F}})),await e.sequenceExecuteAsync(w,a)?(r.pushUndoRedo({redoMutations:w,undoMutations:b,unitID:m}),!0):!1}};e.CommandType.COMMAND;class ne extends U.FRange{setHyperLink(n,a){const r={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),link:{row:this._range.startRow,column:this._range.startColumn,payload:n,display:a,id:e.generateRandomId()}};return this._commandService.executeCommand(Z.id,r)}getHyperLinks(){var a,r,s;const n=this._worksheet.getCellRaw(this._range.startRow,this._range.startColumn);return n!=null&&n.p?(s=(r=(a=n.p.body)==null?void 0:a.customRanges)==null?void 0:r.filter(i=>i.rangeType===e.CustomRangeType.HYPERLINK).map(i=>{var o,d,c,u,l;return{id:i.rangeId,startIndex:i.startIndex,endIndex:i.endIndex,url:(d=(o=i.properties)==null?void 0:o.url)!=null?d:"",label:(l=(u=(c=n.p)==null?void 0:c.body)==null?void 0:u.dataStream.slice(i.startIndex+1,i.endIndex))!=null?l:""}}))!=null?s:[]:[]}updateHyperLink(n,a,r){const s={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id:n,payload:{payload:a,display:r}};return this._commandService.executeCommand(te.id,s)}cancelHyperLink(n){const a={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id:n};return this._commandService.executeCommand(ee.id,a)}}U.FRange.extend(ne),R.FWorkbookHyperLinkMixin=W,Object.defineProperty(R,Symbol.toStringTag,{value:"Module"})});
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(exports,require("@univerjs/core"),require("rxjs"),require("@univerjs/sheets"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","@univerjs/sheets","@univerjs/engine-formula"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverSheetsHyperLink={},global.UniverCore,global.rxjs,global.UniverSheets,global.UniverEngineFormula))})(this,function(exports2,core,rxjs,sheets,engineFormula){"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);var _a,_b,_c,_d,_e;var __defProp$4=Object.defineProperty,__getOwnPropDesc$4=Object.getOwnPropertyDescriptor,__decorateClass$4=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$4(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$4(target,key,result),result},"__decorateClass$4"),__decorateParam$4=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$4");exports2.HyperLinkModel=(_a=class extends core.Disposable{constructor(_univerInstanceService){super();__publicField(this,"_linkUpdate$",new rxjs.Subject);__publicField(this,"linkUpdate$",this._linkUpdate$.asObservable());__publicField(this,"_linkMap",new Map);__publicField(this,"_linkPositionMap",new Map);this._univerInstanceService=_univerInstanceService,this.disposeWithMe({dispose:__name(()=>{this._linkUpdate$.complete()},"dispose")})}_ensureMap(unitId,subUnitId){let unitMap=this._linkMap.get(unitId);unitMap||(unitMap=new Map,this._linkMap.set(unitId,unitMap));let matrix=unitMap.get(subUnitId);matrix||(matrix=new core.ObjectMatrix,unitMap.set(subUnitId,matrix));let positionUnitMap=this._linkPositionMap.get(unitId);positionUnitMap||(positionUnitMap=new Map,this._linkPositionMap.set(unitId,positionUnitMap));let positionSubUnitMap=positionUnitMap.get(subUnitId);return positionSubUnitMap||(positionSubUnitMap=new Map,positionUnitMap.set(subUnitId,positionSubUnitMap)),{matrix,positionMap:positionSubUnitMap}}addHyperLink(unitId,subUnitId,link){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId);return matrix.setValue(link.row,link.column,link),positionMap.set(link.id,{row:link.row,column:link.column,link}),this._linkUpdate$.next({unitId,subUnitId,payload:link,type:"add"}),!0}updateHyperLink(unitId,subUnitId,id,payload,silent=!1){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(!position)return!0;const link=matrix.getValue(position.row,position.column);return link&&(Object.assign(link,payload),this._linkUpdate$.next({unitId,subUnitId,payload:{display:link.display,payload:link.payload},id,type:"update",silent})),!0}updateHyperLinkRef(unitId,subUnitId,id,payload,silent=!1){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(!position)return!0;let link=matrix.getValue(position.row,position.column);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({unitId,subUnitId,payload,id,type:"updateRef",silent}),!0}removeHyperLink(unitId,subUnitId,id){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(!position)return!1;positionMap.delete(id);const link=matrix.getValue(position.row,position.column);return link&&link.id===id&&matrix.realDeleteValue(position.row,position.column),this._linkUpdate$.next({unitId,subUnitId,payload:position.link,type:"remove"}),!0}getHyperLink(unitId,subUnitId,id){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(position)return matrix.getValue(position.row,position.column)}getHyperLinkByLocation(unitId,subUnitId,row,column){const{matrix}=this._ensureMap(unitId,subUnitId);return matrix.getValue(row,column)}getHyperLinkByLocationSync(unitId,subUnitId,row,column){var _a2,_b2,_c2,_d2,_e2;const{matrix}=this._ensureMap(unitId,subUnitId),workbook=this._univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_SHEET),cell=(_a2=workbook==null?void 0:workbook.getSheetBySheetId(subUnitId))==null?void 0:_a2.getCellRaw(row,column),cellValueStr=((_e2=(_d2=cell==null?void 0:cell.v)!=null?_d2:(_c2=(_b2=cell==null?void 0:cell.p)==null?void 0:_b2.body)==null?void 0:_c2.dataStream.slice(0,-2))!=null?_e2:"").toString(),link=matrix.getValue(row,column);if(link)return{...link,display:cellValueStr}}getSubUnit(unitId,subUnitId){const{matrix}=this._ensureMap(unitId,subUnitId),links=[];return matrix.forValue((row,col,value)=>{value&&links.push(value)}),links}getUnit(unitId){const unitMap=this._linkMap.get(unitId);return unitMap?Array.from(unitMap.keys()).map(subUnitId=>{const links=this.getSubUnit(unitId,subUnitId);return{unitId,subUnitId,links}}):[]}deleteUnit(unitId){const links=this.getUnit(unitId);this._linkMap.delete(unitId),this._linkPositionMap.delete(unitId),this._linkUpdate$.next({type:"unload",unitId,unitLinks:links})}getAll(){return Array.from(this._linkMap.keys()).map(unitId=>this.getUnit(unitId))}},__name(_a,"HyperLinkModel"),_a),exports2.HyperLinkModel=__decorateClass$4([__decorateParam$4(0,core.IUniverInstanceService)],exports2.HyperLinkModel);var SheetHyperLinkType=(SheetHyperLinkType2=>(SheetHyperLinkType2.SHEET="gid",SheetHyperLinkType2.RANGE="range",SheetHyperLinkType2.DEFINE_NAME="rangeid",SheetHyperLinkType2.INVALID="invalid",SheetHyperLinkType2.URL="url",SheetHyperLinkType2))(SheetHyperLinkType||{});const PLUGIN_CONFIG_KEY="sheets-hyper-link.config",defaultPluginConfig={},AddHyperLinkMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports2.HyperLinkModel),{unitId,subUnitId,link}=params;return model.addHyperLink(unitId,subUnitId,link)}},RemoveHyperLinkMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports2.HyperLinkModel),{unitId,subUnitId,id}=params;return model.removeHyperLink(unitId,subUnitId,id)}},UpdateHyperLinkMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports2.HyperLinkModel),{unitId,subUnitId,payload,id}=params;return model.updateHyperLink(unitId,subUnitId,id,payload,!1)}},UpdateHyperLinkRefMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports2.HyperLinkModel),{unitId,subUnitId,id,row,column,silent}=params;return model.updateHyperLinkRef(unitId,subUnitId,id,{row,column},silent)}},SHEET_HYPER_LINK_PLUGIN="SHEET_HYPER_LINK_PLUGIN",ERROR_RANGE="err";var __defProp$3=Object.defineProperty,__getOwnPropDesc$3=Object.getOwnPropertyDescriptor,__decorateClass$3=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$3(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$3(target,key,result),result},"__decorateClass$3"),__decorateParam$3=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$3");let SheetsHyperLinkRefRangeController=(_b=class extends core.Disposable{constructor(_refRangeService,_hyperLinkModel,_selectionManagerService,_commandService){super();__publicField(this,"_disposableMap",new Map);__publicField(this,"_watchDisposableMap",new Map);__publicField(this,"_rangeDisableMap",new Map);__publicField(this,"_rangeWatcherMap",new Map);__publicField(this,"_handlePositionChange",__name((unitId,subUnitId,link,resultRange,silent)=>{const oldRange={startColumn:link.column,endColumn:link.column,startRow:link.row,endRow:link.row};return resultRange?{redos:[{id:UpdateHyperLinkRefMutation.id,params:{unitId,subUnitId,id:link.id,row:resultRange.startRow,column:resultRange.startColumn,silent}}],undos:[{id:UpdateHyperLinkRefMutation.id,params:{unitId,subUnitId,id:link.id,row:oldRange.startRow,column:oldRange.startColumn,silent}}]}:{redos:[{id:RemoveHyperLinkMutation.id,params:{unitId,subUnitId,id:link.id}}],undos:[{id:AddHyperLinkMutation.id,params:{unitId,subUnitId,link}}]}},"_handlePositionChange"));this._refRangeService=_refRangeService,this._hyperLinkModel=_hyperLinkModel,this._selectionManagerService=_selectionManagerService,this._commandService=_commandService,this._initData(),this._initRefRange()}_registerPosition(unitId,subUnitId,link){const id=link.id,oldRange={startColumn:link.column,endColumn:link.column,startRow:link.row,endRow:link.row},handleRefRangeChange=__name(commandInfo=>{const resultRanges=sheets.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(oldRange,commandInfo,{selectionManagerService:this._selectionManagerService}),resultRange=Array.isArray(resultRanges)?resultRanges[0]:resultRanges;return resultRange&&resultRange.startColumn===oldRange.startColumn&&resultRange.startRow===oldRange.startRow?{undos:[],redos:[]}:this._handlePositionChange(unitId,subUnitId,link,resultRange,!1)},"handleRefRangeChange");this._disposableMap.set(id,this._refRangeService.registerRefRange(oldRange,handleRefRangeChange,unitId,subUnitId))}_watchPosition(unitId,subUnitId,link){const id=link.id,oldRange={startColumn:link.column,endColumn:link.column,startRow:link.row,endRow:link.row};this._watchDisposableMap.set(id,this._refRangeService.watchRange(unitId,subUnitId,oldRange,(before,after)=>{const{redos}=this._handlePositionChange(unitId,subUnitId,link,after,!0);core.sequenceExecuteAsync(redos,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(id){const disposable=this._disposableMap.get(id);disposable==null||disposable.dispose(),this._disposableMap.delete(id)}_unwatchPosition(id){const disposable=this._watchDisposableMap.get(id);disposable==null||disposable.dispose(),this._watchDisposableMap.delete(id)}_registerRange(unitId,id,payload,silent=!1){var _a2,_b2,_c2;if(payload.startsWith("#")){const search=new URLSearchParams(payload.slice(1)),searchObj={gid:(_a2=search.get("gid"))!=null?_a2:"",range:(_b2=search.get("range"))!=null?_b2:"",rangeid:(_c2=search.get("rangeid"))!=null?_c2:""};if(searchObj.range&&searchObj.gid){const subUnitId=searchObj.gid,range=engineFormula.deserializeRangeWithSheet(searchObj.range).range;if(core.isValidRange(range)&&searchObj.range!==ERROR_RANGE){const handleRangeChange=__name(commandInfo=>{const resultRange=sheets.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(range,commandInfo,{selectionManagerService:this._selectionManagerService});return resultRange&&engineFormula.serializeRange(resultRange)===engineFormula.serializeRange(range)?{redos:[],undos:[]}:{redos:[{id:UpdateHyperLinkMutation.id,params:{unitId,subUnitId,id,payload:{payload:`#gid=${subUnitId}&range=${resultRange?engineFormula.serializeRange(resultRange):"err"}`}}}],undos:[{id:UpdateHyperLinkMutation.id,params:{unitId,subUnitId,id,payload:{payload}}}]}},"handleRangeChange");this._rangeDisableMap.set(id,this._refRangeService.registerRefRange(range,handleRangeChange,unitId,subUnitId)),silent||this._rangeWatcherMap.set(id,this._refRangeService.watchRange(unitId,subUnitId,range,(before,after)=>{this._hyperLinkModel.updateHyperLink(unitId,subUnitId,id,{payload:`#gid=${subUnitId}&range=${after?engineFormula.serializeRange(after):"err"}`},!0)},!0))}}}}_unregisterRange(id){const disposable=this._rangeDisableMap.get(id);disposable==null||disposable.dispose(),this._rangeDisableMap.delete(id)}_unwatchRange(id){const disposable=this._rangeWatcherMap.get(id);disposable==null||disposable.dispose(),this._rangeWatcherMap.delete(id)}_initData(){this._hyperLinkModel.getAll().forEach(unitData=>{unitData.forEach(subUnitData=>{const{unitId,subUnitId,links}=subUnitData;links.forEach(link=>{this._registerPosition(unitId,subUnitId,link),this._watchPosition(unitId,subUnitId,link),this._registerRange(unitId,link.id,link.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(option=>{switch(option.type){case"add":{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);break}case"remove":{this._unregisterPosition(option.payload.id),this._unwatchPosition(option.payload.id),this._unregisterRange(option.payload.id),this._unwatchRange(option.payload.id);break}case"updateRef":{const{unitId,subUnitId,id,silent}=option,link=this._hyperLinkModel.getHyperLink(unitId,subUnitId,id);if(!link)return;this._unregisterPosition(id),this._registerPosition(unitId,subUnitId,link),silent||(this._unwatchPosition(id),this._watchPosition(unitId,subUnitId,link));break}case"unload":{const{unitLinks}=option;unitLinks.forEach(subUnitData=>{const{links}=subUnitData;links.forEach(link=>{this._unregisterPosition(link.id),this._unwatchPosition(link.id),this._unregisterRange(link.id),this._unwatchRange(link.id)})});break}case"update":{option.silent||this._unwatchRange(option.id),this._unregisterRange(option.id),this._registerRange(option.unitId,option.id,option.payload.payload,option.silent);break}}})),this.disposeWithMe(core.toDisposable(()=>{this._disposableMap.forEach(item=>{item.dispose()}),this._disposableMap.clear()}))}},__name(_b,"SheetsHyperLinkRefRangeController"),_b);SheetsHyperLinkRefRangeController=__decorateClass$3([__decorateParam$3(0,core.Inject(sheets.RefRangeService)),__decorateParam$3(1,core.Inject(exports2.HyperLinkModel)),__decorateParam$3(2,core.Inject(sheets.SheetsSelectionsService)),__decorateParam$3(3,core.ICommandService)],SheetsHyperLinkRefRangeController);var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2");let SheetsHyperLinkController=(_c=class extends core.Disposable{constructor(_commandService){super(),this._commandService=_commandService,this._registerCommands()}_registerCommands(){[AddHyperLinkMutation,UpdateHyperLinkMutation,RemoveHyperLinkMutation,UpdateHyperLinkRefMutation].forEach(command=>{this._commandService.registerCommand(command)})}},__name(_c,"SheetsHyperLinkController"),_c);SheetsHyperLinkController=__decorateClass$2([__decorateParam$2(0,core.ICommandService)],SheetsHyperLinkController);var R=(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))(R||{}),__defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1");let SheetsHyperLinkResourceController=(_d=class extends core.Disposable{constructor(_resourceManagerService,_hyperLinkModel){super(),this._resourceManagerService=_resourceManagerService,this._hyperLinkModel=_hyperLinkModel,this._initSnapshot()}_initSnapshot(){const toJson=__name(unitID=>{const map=this._hyperLinkModel.getUnit(unitID),resultMap={};return map?(map.forEach(info=>{resultMap[info.subUnitId]=info.links.map(({display,...link})=>link)}),JSON.stringify(resultMap)):""},"toJson"),parseJson=__name(json=>{if(!json)return{};try{return JSON.parse(json)}catch{return{}}},"parseJson");this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:SHEET_HYPER_LINK_PLUGIN,businesses:[R.UNIVER_SHEET],toJson:__name(unitID=>toJson(unitID),"toJson"),parseJson:__name(json=>parseJson(json),"parseJson"),onUnLoad:__name(unitID=>{this._hyperLinkModel.deleteUnit(unitID)},"onUnLoad"),onLoad:__name(async(unitID,value)=>{Object.keys(value).forEach(subunitId=>{value[subunitId].forEach(link=>{this._hyperLinkModel.addHyperLink(unitID,subunitId,link)})})},"onLoad")}))}},__name(_d,"SheetsHyperLinkResourceController"),_d);SheetsHyperLinkResourceController=__decorateClass$1([__decorateParam$1(0,core.IResourceManagerService),__decorateParam$1(1,core.Inject(exports2.HyperLinkModel))],SheetsHyperLinkResourceController);var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key,value)=>key in obj?__defProp2(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),__publicField2=__name((obj,key,value)=>__defNormalProp2(obj,typeof key!="symbol"?key+"":key,value),"__publicField");exports2.UniverSheetsHyperLinkPlugin=(_e=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_configService){super(),this._config=_config,this._injector=_injector,this._configService=_configService;const{...rest}=this._config;this._configService.setConfig(PLUGIN_CONFIG_KEY,rest)}onStarting(){[[SheetsHyperLinkResourceController],[SheetsHyperLinkController],[SheetsHyperLinkRefRangeController],[exports2.HyperLinkModel]].forEach(dep=>{this._injector.add(dep)}),this._injector.get(SheetsHyperLinkRefRangeController),this._injector.get(SheetsHyperLinkResourceController),this._injector.get(SheetsHyperLinkController)}},__name(_e,"UniverSheetsHyperLinkPlugin"),_e),__publicField2(exports2.UniverSheetsHyperLinkPlugin,"pluginName",SHEET_HYPER_LINK_PLUGIN),__publicField2(exports2.UniverSheetsHyperLinkPlugin,"type",core.UniverInstanceType.UNIVER_SHEET),exports2.UniverSheetsHyperLinkPlugin=__decorateClass([core.DependentOn(sheets.UniverSheetsPlugin),__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService)],exports2.UniverSheetsHyperLinkPlugin),exports2.AddHyperLinkMutation=AddHyperLinkMutation,exports2.ERROR_RANGE=ERROR_RANGE,exports2.RemoveHyperLinkMutation=RemoveHyperLinkMutation,exports2.SheetHyperLinkType=SheetHyperLinkType,exports2.UpdateHyperLinkMutation=UpdateHyperLinkMutation,exports2.UpdateHyperLinkRefMutation=UpdateHyperLinkRefMutation,Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
1
+ (function(c,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("rxjs"),require("@univerjs/sheets"),require("@univerjs/engine-formula"),require("@univerjs/docs"),require("@univerjs/sheets-hyper-link")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","@univerjs/sheets","@univerjs/engine-formula","@univerjs/docs","@univerjs/sheets-hyper-link"],s):(c=typeof globalThis<"u"?globalThis:c||self,s(c.UniverSheetsHyperLink={},c.UniverCore,c.rxjs,c.UniverSheets,c.UniverEngineFormula,c.UniverDocs,c.UniverSheetsHyperLink))})(this,function(c,s,P,y,L,$,U){"use strict";var Ae=Object.defineProperty;var $e=(c,s,P)=>s in c?Ae(c,s,{enumerable:!0,configurable:!0,writable:!0,value:P}):c[s]=P;var C=(c,s,P)=>$e(c,typeof s!="symbol"?s+"":s,P);var me=Object.defineProperty,ye=Object.getOwnPropertyDescriptor,fe=(a,t,e,n)=>{for(var i=n>1?void 0:n?ye(t,e):t,r=a.length-1,o;r>=0;r--)(o=a[r])&&(i=(n?o(t,e,i):o(i))||i);return n&&i&&me(t,e,i),i},_e=(a,t)=>(e,n)=>t(e,n,a);c.HyperLinkModel=class extends s.Disposable{constructor(e){super();C(this,"_linkUpdate$",new P.Subject);C(this,"linkUpdate$",this._linkUpdate$.asObservable());C(this,"_linkMap",new Map);C(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let i=this._linkMap.get(e);i||(i=new Map,this._linkMap.set(e,i));let r=i.get(n);r||(r=new s.ObjectMatrix,i.set(n,r));let o=this._linkPositionMap.get(e);o||(o=new Map,this._linkPositionMap.set(e,o));let d=o.get(n);return d||(d=new Map,o.set(n,d)),{matrix:r,positionMap:d}}addHyperLink(e,n,i){const{matrix:r,positionMap:o}=this._ensureMap(e,n);return r.setValue(i.row,i.column,i),o.set(i.id,{row:i.row,column:i.column,link:i}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:i,type:"add"}),!0}updateHyperLink(e,n,i,r,o=!1){const{matrix:d,positionMap:l}=this._ensureMap(e,n),u=l.get(i);if(!u)return!0;const p=d.getValue(u.row,u.column);return p&&(Object.assign(p,r),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:p.display,payload:p.payload},id:i,type:"update",silent:o})),!0}updateHyperLinkRef(e,n,i,r,o=!1){const{matrix:d,positionMap:l}=this._ensureMap(e,n),u=l.get(i);if(!u)return!0;let p=d.getValue(u.row,u.column);return!p||p.id!==i?p=u.link:d.realDeleteValue(u.row,u.column),Object.assign(p,r),l.set(i,{...r,link:p}),d.setValue(r.row,r.column,p),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:r,id:i,type:"updateRef",silent:o}),!0}removeHyperLink(e,n,i){const{matrix:r,positionMap:o}=this._ensureMap(e,n),d=o.get(i);if(!d)return!1;o.delete(i);const l=r.getValue(d.row,d.column);return l&&l.id===i&&r.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,i){const{matrix:r,positionMap:o}=this._ensureMap(e,n),d=o.get(i);if(d)return r.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,i,r){const{matrix:o}=this._ensureMap(e,n);return o.getValue(i,r)}getHyperLinkByLocationSync(e,n,i,r){var g,m,f,h,_;const{matrix:o}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,s.UniverInstanceType.UNIVER_SHEET),l=(g=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:g.getCellRaw(i,r),u=((_=(h=l==null?void 0:l.v)!=null?h:(f=(m=l==null?void 0:l.p)==null?void 0:m.body)==null?void 0:f.dataStream.slice(0,-2))!=null?_:"").toString(),p=o.getValue(i,r);if(p)return{...p,display:u}}getSubUnit(e,n){const{matrix:i}=this._ensureMap(e,n),r=[];return i.forValue((o,d,l)=>{l&&r.push(l)}),r}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(i=>{const r=this.getSubUnit(e,i);return{unitId:e,subUnitId:i,links:r}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}},c.HyperLinkModel=fe([_e(0,s.IUniverInstanceService)],c.HyperLinkModel);var M=(a=>(a.SHEET="gid",a.RANGE="range",a.DEFINE_NAME="rangeid",a.INVALID="invalid",a.URL="url",a))(M||{});const Re="sheets-hyper-link.config",ve={},F={type:s.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(a,t){if(!t)return!1;const e=a.get(c.HyperLinkModel),{unitId:n,subUnitId:i,link:r}=t;return e.addHyperLink(n,i,r)}},J={type:s.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(a,t){if(!t)return!1;const e=a.get(c.HyperLinkModel),{unitId:n,subUnitId:i,id:r}=t;return e.removeHyperLink(n,i,r)}},j={type:s.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(a,t){if(!t)return!1;const e=a.get(c.HyperLinkModel),{unitId:n,subUnitId:i,payload:r,id:o}=t;return e.updateHyperLink(n,i,o,r,!1)}},x={type:s.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(a,t){if(!t)return!1;const e=a.get(c.HyperLinkModel),{unitId:n,subUnitId:i,id:r,row:o,column:d,silent:l}=t;return e.updateHyperLinkRef(n,i,r,{row:o,column:d},l)}},ee="SHEET_HYPER_LINK_PLUGIN",Y="err";var Se=Object.defineProperty,Me=Object.getOwnPropertyDescriptor,Ie=(a,t,e,n)=>{for(var i=n>1?void 0:n?Me(t,e):t,r=a.length-1,o;r>=0;r--)(o=a[r])&&(i=(n?o(t,e,i):o(i))||i);return n&&i&&Se(t,e,i),i},B=(a,t)=>(e,n)=>t(e,n,a);let W=class extends s.Disposable{constructor(t,e,n,i){super();C(this,"_disposableMap",new Map);C(this,"_watchDisposableMap",new Map);C(this,"_rangeDisableMap",new Map);C(this,"_rangeWatcherMap",new Map);C(this,"_handlePositionChange",(t,e,n,i,r)=>{const o={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return i?{redos:[{id:x.id,params:{unitId:t,subUnitId:e,id:n.id,row:i.startRow,column:i.startColumn,silent:r}}],undos:[{id:x.id,params:{unitId:t,subUnitId:e,id:n.id,row:o.startRow,column:o.startColumn,silent:r}}]}:{redos:[{id:J.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:F.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=i,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const i=n.id,r={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},o=d=>{const l=y.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(r,d,{selectionManagerService:this._selectionManagerService}),u=Array.isArray(l)?l[0]:l;return u&&u.startColumn===r.startColumn&&u.startRow===r.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,u,!1)};this._disposableMap.set(i,this._refRangeService.registerRefRange(r,o,t,e))}_watchPosition(t,e,n){const i=n.id,r={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(t,e,r,(o,d)=>{const{redos:l}=this._handlePositionChange(t,e,n,d,!0);s.sequenceExecuteAsync(l,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(t){const e=this._disposableMap.get(t);e==null||e.dispose(),this._disposableMap.delete(t)}_unwatchPosition(t){const e=this._watchDisposableMap.get(t);e==null||e.dispose(),this._watchDisposableMap.delete(t)}_registerRange(t,e,n,i=!1){var r,o,d;if(n.startsWith("#")){const l=new URLSearchParams(n.slice(1)),u={gid:(r=l.get("gid"))!=null?r:"",range:(o=l.get("range"))!=null?o:"",rangeid:(d=l.get("rangeid"))!=null?d:""};if(u.range&&u.gid){const p=u.gid,g=L.deserializeRangeWithSheet(u.range).range;if(s.isValidRange(g)&&u.range!==Y){const m=f=>{const h=y.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(g,f,{selectionManagerService:this._selectionManagerService});return h&&L.serializeRange(h)===L.serializeRange(g)?{redos:[],undos:[]}:{redos:[{id:j.id,params:{unitId:t,subUnitId:p,id:e,payload:{payload:`#gid=${p}&range=${h?L.serializeRange(h):"err"}`}}}],undos:[{id:j.id,params:{unitId:t,subUnitId:p,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(g,m,t,p)),i||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,p,g,(f,h)=>{this._hyperLinkModel.updateHyperLink(t,p,e,{payload:`#gid=${p}&range=${h?L.serializeRange(h):"err"}`},!0)},!0))}}}}_unregisterRange(t){const e=this._rangeDisableMap.get(t);e==null||e.dispose(),this._rangeDisableMap.delete(t)}_unwatchRange(t){const e=this._rangeWatcherMap.get(t);e==null||e.dispose(),this._rangeWatcherMap.delete(t)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(n=>{const{unitId:i,subUnitId:r,links:o}=n;o.forEach(d=>{this._registerPosition(i,r,d),this._watchPosition(i,r,d),this._registerRange(i,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:i,silent:r}=t,o=this._hyperLinkModel.getHyperLink(e,n,i);if(!o)return;this._unregisterPosition(i),this._registerPosition(e,n,o),r||(this._unwatchPosition(i),this._watchPosition(e,n,o));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:i}=n;i.forEach(r=>{this._unregisterPosition(r.id),this._unwatchPosition(r.id),this._unregisterRange(r.id),this._unwatchRange(r.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(s.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};W=Ie([B(0,s.Inject(y.RefRangeService)),B(1,s.Inject(c.HyperLinkModel)),B(2,s.Inject(y.SheetsSelectionsService)),B(3,s.ICommandService)],W);const te={type:s.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(a,t){if(!t)return!1;const e=a.get(s.ICommandService),n=a.get(s.IUndoRedoService),i=a.get(s.IUniverInstanceService),r=a.get(U.HyperLinkModel),o=a.get(y.SheetInterceptorService),d=y.getSheetCommandTarget(i,t);if(!d)return!1;const{unitId:l,subUnitId:u,workbook:p,worksheet:g}=d,{link:m}=t,{payload:f,display:h,row:_,column:k,id:S}=m,w=g.getCell(_,k),R=g.getBlankCellDocumentModel(w),I=R.documentModel.getSnapshot(),v=s.Tools.deepClone(I.body);if(!v)return!1;let T;if(h?T=s.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:v.dataStream.length-2,collapsed:!0},body:{dataStream:`${s.DataStreamTreeTokenType.CUSTOM_RANGE_START}${h}${s.DataStreamTreeTokenType.CUSTOM_RANGE_END}`,customRanges:[{startIndex:0,endIndex:h.length+1,rangeType:s.CustomRangeType.HYPERLINK,rangeId:S,properties:{url:f}}]},doc:R.documentModel}):T=s.BuildTextUtils.customRange.add({body:v,range:{startOffset:0,endOffset:v.dataStream.length-2,collapsed:!1},rangeId:S,rangeType:s.CustomRangeType.HYPERLINK,properties:{url:f,refId:S}}),!T)return!1;const V=s.TextX.apply(v,T.serialize()),E={p:{...I,body:V},t:s.CellValueType.STRING},H=await o.onWriteCell(p,g,_,k,E),D={unitId:l,subUnitId:u,cellValue:{[m.row]:{[m.column]:H}}},Z={id:y.SetRangeValuesMutation.id,params:D},q=y.SetRangeValuesUndoMutationFactory(a,D),Q={id:y.SetRangeValuesMutation.id,params:q},A=[Z],O=[Q],b=r.getHyperLinkByLocation(l,u,_,k);return b&&(A.push({id:U.RemoveHyperLinkMutation.id,params:{unitId:l,subUnitId:u,id:b.id}}),O.push({id:U.AddHyperLinkMutation.id,params:{unitId:l,subUnitId:u,link:b}})),await s.sequenceExecuteAsync(A,e)?(n.pushUndoRedo({redoMutations:A,undoMutations:O,unitID:l}),!0):!1}},ne={id:"sheets.command.add-rich-hyper-link",type:s.CommandType.COMMAND,handler:async(a,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,i=a.get(s.ICommandService),r=s.generateRandomId(),{payload:o}=n,d=$.addCustomRangeBySelectionFactory(a,{unitId:e,rangeId:r,rangeType:s.CustomRangeType.HYPERLINK,properties:{url:o,refId:r}});return d?i.syncExecuteCommand(d.id,d.params):!1}},ie={type:s.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(a,t){var E,H;if(!t)return!1;const e=a.get(s.ICommandService),n=a.get(s.IUndoRedoService),i=a.get(s.IUniverInstanceService),r=a.get(U.HyperLinkModel),o=y.getSheetCommandTarget(i,t);if(!o)return!1;const{row:d,column:l,id:u}=t,{unitId:p,subUnitId:g,worksheet:m}=o,f=m.getCell(d,l);if(!f)return!1;const h=m.getCellDocumentModelWithFormula(f);if(!(h!=null&&h.documentModel))return!1;const _=s.Tools.deepClone(h.documentModel.getSnapshot());if(!((H=(E=_.body)==null?void 0:E.customRanges)==null?void 0:H.find(D=>D.rangeId===u)))return!1;const S=s.BuildTextUtils.customRange.delete(a,{documentDataModel:h.documentModel,rangeId:u});if(!S)return!1;const w=s.TextX.apply(_.body,S.serialize()),R=[],I=[],v={unitId:p,subUnitId:g,cellValue:{[d]:{[l]:{p:{..._,body:w},t:s.CellValueType.STRING}}}};R.push({id:y.SetRangeValuesMutation.id,params:v});const T=y.SetRangeValuesUndoMutationFactory(a,v);I.push({id:y.SetRangeValuesMutation.id,params:T});const V=r.getHyperLinkByLocation(p,g,d,l);return V&&(R.push({id:U.RemoveHyperLinkMutation.id,params:{unitId:p,subUnitId:g,id:u}}),I.push({id:U.AddHyperLinkMutation.id,params:{unitId:p,subUnitId:g,link:{...V}}})),s.sequenceExecute(R,e).result?(n.pushUndoRedo({redoMutations:R,undoMutations:I,unitID:p}),!0):!1}},ae={type:s.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(a,t){var p,g;if(!t)return!1;const{id:e,documentId:n}=t,i=a.get(s.ICommandService),o=a.get(s.IUniverInstanceService).getUnit(n,s.UniverInstanceType.UNIVER_DOC),d=(g=(p=o==null?void 0:o.getBody())==null?void 0:p.customRanges)==null?void 0:g.find(m=>m.rangeId===e);let l=null;d&&d.endIndex===o.getBody().dataStream.length-3&&(l={dataStream:" "});const u=$.deleteCustomRangeFactory(a,{unitId:n,rangeId:e,insert:l});return u?i.syncExecuteCommand(u.id,u.params):!1}},re={type:s.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(a,t){var pe,ge,he;if(!t)return!1;const e=a.get(s.ICommandService),n=a.get(s.IUndoRedoService),i=a.get(s.IUniverInstanceService),r=a.get(U.HyperLinkModel),o=a.get(y.SheetInterceptorService),d=y.getSheetCommandTarget(i);if(!d)return!1;const{payload:l,row:u,column:p,id:g}=t,{workbook:m,worksheet:f,unitId:h,subUnitId:_}=d,{payload:k,display:S=""}=l,w=f.getCell(u,p);if(!w)return!1;const R=f.getCellDocumentModelWithFormula(w);if(!(R!=null&&R.documentModel))return!1;const I=R.documentModel.getSnapshot(),v=(ge=(pe=I.body)==null?void 0:pe.customRanges)==null?void 0:ge.find(Ve=>Ve.rangeId===g);if(!v)return!1;const T=s.generateRandomId(),N=(he=s.getBodySlice(R.documentModel.getBody(),v.startIndex,v.endIndex+1).textRuns)==null?void 0:he[0];N&&(N.ed=S.length+1);const E=$.replaceSelectionFactory(a,{unitId:h,body:{dataStream:`${s.DataStreamTreeTokenType.CUSTOM_RANGE_START}${S}${s.DataStreamTreeTokenType.CUSTOM_RANGE_END}`,customRanges:[{rangeId:T,rangeType:s.CustomRangeType.HYPERLINK,startIndex:0,endIndex:S.length+1,properties:{url:k}}],textRuns:N?[N]:void 0},selection:{startOffset:v.startIndex,endOffset:v.endIndex+1,collapsed:!1},doc:R.documentModel});if(!E)return!1;const H=s.TextX.apply(s.Tools.deepClone(I.body),E.textX.serialize()),D={p:{...I,body:H},t:s.CellValueType.STRING},Z=await o.onWriteCell(m,f,u,p,D),q={id:y.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:_,cellValue:{[u]:{[p]:Z}}}},Q=y.SetRangeValuesUndoMutationFactory(a,q.params),A={id:y.SetRangeValuesMutation.id,params:Q},O=[q],b=[A],K=r.getHyperLinkByLocation(h,_,u,p);return K&&(O.push({id:U.RemoveHyperLinkMutation.id,params:{unitId:h,subUnitId:_,id:K.id}}),b.push({id:U.AddHyperLinkMutation.id,params:{unitId:h,subUnitId:_,link:K}})),await s.sequenceExecuteAsync(O,e)?(n.pushUndoRedo({redoMutations:O,undoMutations:b,unitID:h}),!0):!1}},se={type:s.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(a,t)=>{var h,_,k,S;if(!t)return!1;const{documentId:e,payload:n,id:i}=t,r=a.get(s.IUniverInstanceService),o=a.get(s.ICommandService),d=r.getUnit(e,s.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const l=(_=(h=d.getBody())==null?void 0:h.customRanges)==null?void 0:_.find(w=>w.rangeId===i);if(!l)return!1;const u=(k=t.payload.display)!=null?k:"",p=s.generateRandomId(),m=(S=s.getBodySlice(d.getBody(),l.startIndex,l.endIndex+1).textRuns)==null?void 0:S[0];m&&(m.ed=u.length+1);const f=$.replaceSelectionFactory(a,{unitId:e,body:{dataStream:`${s.DataStreamTreeTokenType.CUSTOM_RANGE_START}${u}${s.DataStreamTreeTokenType.CUSTOM_RANGE_END}`,customRanges:[{rangeId:p,rangeType:s.CustomRangeType.HYPERLINK,startIndex:0,endIndex:u.length+1,properties:{url:n.payload}}],textRuns:m?[m]:void 0},selection:{startOffset:l.startIndex,endOffset:l.endIndex+1,collapsed:!1},doc:d});return f?o.syncExecuteCommand(f.id,f.params):!1}};var Ce=Object.defineProperty,Le=Object.getOwnPropertyDescriptor,Ue=(a,t,e,n)=>{for(var i=n>1?void 0:n?Le(t,e):t,r=a.length-1,o;r>=0;r--)(o=a[r])&&(i=(n?o(t,e,i):o(i))||i);return n&&i&&Ce(t,e,i),i},ke=(a,t)=>(e,n)=>t(e,n,a);let G=class extends s.Disposable{constructor(a){super(),this._commandService=a,this._registerCommands()}_registerCommands(){[te,re,ie,se,ae,ne,F,j,J,x].forEach(a=>{this._commandService.registerCommand(a)})}};G=Ue([ke(0,s.ICommandService)],G);var oe=(a=>(a[a.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",a[a.UNIVER_DOC=1]="UNIVER_DOC",a[a.UNIVER_SHEET=2]="UNIVER_SHEET",a[a.UNIVER_SLIDE=3]="UNIVER_SLIDE",a[a.UNIVER_PROJECT=4]="UNIVER_PROJECT",a[a.UNRECOGNIZED=-1]="UNRECOGNIZED",a))(oe||{}),we=Object.defineProperty,Te=Object.getOwnPropertyDescriptor,Ee=(a,t,e,n)=>{for(var i=n>1?void 0:n?Te(t,e):t,r=a.length-1,o;r>=0;r--)(o=a[r])&&(i=(n?o(t,e,i):o(i))||i);return n&&i&&we(t,e,i),i},de=(a,t)=>(e,n)=>t(e,n,a);let z=class extends s.Disposable{constructor(a,t){super(),this._resourceManagerService=a,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const a=e=>{const n=this._hyperLinkModel.getUnit(e),i={};return n?(n.forEach(r=>{i[r.subUnitId]=r.links.map(({display:o,...d})=>d)}),JSON.stringify(i)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:ee,businesses:[oe.UNIVER_SHEET],toJson:e=>a(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(i=>{n[i].forEach(o=>{this._hyperLinkModel.addHyperLink(e,i,o)})})}}))}};z=Ee([de(0,s.IResourceManagerService),de(1,s.Inject(c.HyperLinkModel))],z);var Pe=Object.defineProperty,Ne=Object.getOwnPropertyDescriptor,He=(a,t,e,n)=>{for(var i=n>1?void 0:n?Ne(t,e):t,r=a.length-1,o;r>=0;r--)(o=a[r])&&(i=(n?o(t,e,i):o(i))||i);return n&&i&&Pe(t,e,i),i},X=(a,t)=>(e,n)=>t(e,n,a);c.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${M.SHEET}=${e}${n?`&${typeof n=="string"?M.DEFINE_NAME:M.RANGE}=${typeof n=="string"?n:L.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,i,r;if(t.startsWith("#")){const o=new URLSearchParams(t.slice(1)),d={gid:(e=o.get("gid"))!=null?e:"",range:(n=o.get("range"))!=null?n:"",rangeid:(i=o.get("rangeid"))!=null?i:"",unitid:(r=o.get("unitid"))!=null?r:""},l=this._getURLName(d);return{type:l.type,name:l.name,url:t,searchObj:d}}else return{type:M.URL,name:t,url:t,searchObj:null}}_getURLName(t){var p;const{gid:e,range:n,rangeid:i,unitid:r}=t,o=r?this._univerInstanceService.getUnit(r,s.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(s.UniverInstanceType.UNIVER_SHEET),d={type:M.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!o)return d;const l=e?o.getSheetBySheetId(e):o.getActiveSheet(),u=(p=l==null?void 0:l.getName())!=null?p:"";if(n){if(!l)return d;const g=L.deserializeRangeWithSheet(n).range;return s.isValidRange(g,l)&&n!==Y?{type:M.RANGE,name:L.serializeRangeWithSheet(u,g)}:d}if(i){const g=this._definedNamesService.getValueById(o.getUnitId(),i);return g?{type:M.DEFINE_NAME,name:g.formulaOrRefString}:d}if(e){const g=o.getSheetBySheetId(e);return g?{type:M.SHEET,name:g.getName()}:d}return d}},c.SheetsHyperLinkParserService=He([X(0,s.IUniverInstanceService),X(1,s.Inject(s.LocaleService)),X(2,L.IDefinedNamesService)],c.SheetsHyperLinkParserService);var le=Object.defineProperty,De=Object.getOwnPropertyDescriptor,Oe=(a,t,e)=>t in a?le(a,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[t]=e,be=(a,t,e,n)=>{for(var i=n>1?void 0:n?De(t,e):t,r=a.length-1,o;r>=0;r--)(o=a[r])&&(i=(n?o(t,e,i):o(i))||i);return n&&i&&le(t,e,i),i},ce=(a,t)=>(e,n)=>t(e,n,a),ue=(a,t,e)=>Oe(a,typeof t!="symbol"?t+"":t,e);c.UniverSheetsHyperLinkPlugin=class extends s.Plugin{constructor(t=ve,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...i}=this._config;this._configService.setConfig(Re,i)}onStarting(){s.registerDependencies(this._injector,[[c.SheetsHyperLinkParserService],[z],[G],[W],[c.HyperLinkModel]]),s.touchDependencies(this._injector,[[W],[z],[G]])}},ue(c.UniverSheetsHyperLinkPlugin,"pluginName",ee),ue(c.UniverSheetsHyperLinkPlugin,"type",s.UniverInstanceType.UNIVER_SHEET),c.UniverSheetsHyperLinkPlugin=be([s.DependentOn(y.UniverSheetsPlugin),ce(1,s.Inject(s.Injector)),ce(2,s.IConfigService)],c.UniverSheetsHyperLinkPlugin),c.AddHyperLinkCommand=te,c.AddHyperLinkMutation=F,c.AddRichHyperLinkCommand=ne,c.CancelHyperLinkCommand=ie,c.CancelRichHyperLinkCommand=ae,c.ERROR_RANGE=Y,c.RemoveHyperLinkMutation=J,c.SheetHyperLinkType=M,c.UpdateHyperLinkCommand=re,c.UpdateHyperLinkMutation=j,c.UpdateHyperLinkRefMutation=x,c.UpdateRichHyperLinkCommand=se,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-hyper-link",
3
- "version": "0.4.1",
3
+ "version": "0.4.2-nightly.202410301606",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -21,18 +21,15 @@
21
21
  "exports": {
22
22
  ".": {
23
23
  "import": "./lib/es/index.js",
24
- "require": "./lib/cjs/index.js",
25
24
  "types": "./lib/types/index.d.ts"
26
25
  },
27
26
  "./*": {
28
27
  "import": "./lib/es/*",
29
- "require": "./lib/cjs/*",
30
28
  "types": "./lib/types/index.d.ts"
31
29
  },
32
30
  "./lib/*": "./lib/*"
33
31
  },
34
- "main": "./lib/cjs/index.js",
35
- "module": "./lib/es/index.js",
32
+ "main": "./lib/es/index.js",
36
33
  "types": "./lib/types/index.d.ts",
37
34
  "publishConfig": {
38
35
  "access": "public"
@@ -47,27 +44,27 @@
47
44
  "rxjs": ">=7.0.0"
48
45
  },
49
46
  "dependencies": {
50
- "@univerjs/protocol": "0.1.39-alpha.30",
51
- "@univerjs/core": "0.4.1",
52
- "@univerjs/sheets": "0.4.1",
53
- "@univerjs/engine-formula": "0.4.1"
47
+ "@univerjs/protocol": "0.1.39-alpha.38",
48
+ "@vitejs/plugin-react": "4.3.3",
49
+ "@univerjs/core": "0.4.2-nightly.202410301606",
50
+ "@univerjs/docs": "0.4.2-nightly.202410301606",
51
+ "@univerjs/sheets": "0.4.2-nightly.202410301606",
52
+ "@univerjs/engine-formula": "0.4.2-nightly.202410301606"
54
53
  },
55
54
  "devDependencies": {
56
55
  "rxjs": "^7.8.1",
57
56
  "typescript": "^5.6.3",
58
- "vite": "^5.4.8",
59
- "vitest": "^2.1.2",
60
- "@univerjs-infra/shared": "0.4.1"
57
+ "vite": "^5.4.10",
58
+ "vitest": "^2.1.4",
59
+ "@univerjs-infra/shared": "0.4.2"
61
60
  },
62
61
  "univerSpace": {
63
62
  ".": {
64
63
  "import": "./lib/es/index.js",
65
- "require": "./lib/cjs/index.js",
66
64
  "types": "./lib/types/index.d.ts"
67
65
  },
68
66
  "./*": {
69
67
  "import": "./lib/es/*",
70
- "require": "./lib/cjs/*",
71
68
  "types": "./lib/types/index.d.ts"
72
69
  },
73
70
  "./lib/*": "./lib/*"
@@ -78,5 +75,6 @@
78
75
  "coverage": "vitest run --coverage",
79
76
  "lint:types": "tsc --noEmit",
80
77
  "build": "tsc && vite build"
81
- }
78
+ },
79
+ "module": "./lib/es/index.js"
82
80
  }
package/LICENSE DELETED
@@ -1,176 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
package/lib/cjs/index.js DELETED
@@ -1 +0,0 @@
1
- "use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const core=require("@univerjs/core"),rxjs=require("rxjs"),sheets=require("@univerjs/sheets"),engineFormula=require("@univerjs/engine-formula");var __defProp$4=Object.defineProperty,__getOwnPropDesc$4=Object.getOwnPropertyDescriptor,__decorateClass$4=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$4(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$4(target,key,result),result},"__decorateClass$4"),__decorateParam$4=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$4"),_a;exports.HyperLinkModel=(_a=class extends core.Disposable{constructor(_univerInstanceService){super();__publicField(this,"_linkUpdate$",new rxjs.Subject);__publicField(this,"linkUpdate$",this._linkUpdate$.asObservable());__publicField(this,"_linkMap",new Map);__publicField(this,"_linkPositionMap",new Map);this._univerInstanceService=_univerInstanceService,this.disposeWithMe({dispose:__name(()=>{this._linkUpdate$.complete()},"dispose")})}_ensureMap(unitId,subUnitId){let unitMap=this._linkMap.get(unitId);unitMap||(unitMap=new Map,this._linkMap.set(unitId,unitMap));let matrix=unitMap.get(subUnitId);matrix||(matrix=new core.ObjectMatrix,unitMap.set(subUnitId,matrix));let positionUnitMap=this._linkPositionMap.get(unitId);positionUnitMap||(positionUnitMap=new Map,this._linkPositionMap.set(unitId,positionUnitMap));let positionSubUnitMap=positionUnitMap.get(subUnitId);return positionSubUnitMap||(positionSubUnitMap=new Map,positionUnitMap.set(subUnitId,positionSubUnitMap)),{matrix,positionMap:positionSubUnitMap}}addHyperLink(unitId,subUnitId,link){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId);return matrix.setValue(link.row,link.column,link),positionMap.set(link.id,{row:link.row,column:link.column,link}),this._linkUpdate$.next({unitId,subUnitId,payload:link,type:"add"}),!0}updateHyperLink(unitId,subUnitId,id,payload,silent=!1){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(!position)return!0;const link=matrix.getValue(position.row,position.column);return link&&(Object.assign(link,payload),this._linkUpdate$.next({unitId,subUnitId,payload:{display:link.display,payload:link.payload},id,type:"update",silent})),!0}updateHyperLinkRef(unitId,subUnitId,id,payload,silent=!1){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(!position)return!0;let link=matrix.getValue(position.row,position.column);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({unitId,subUnitId,payload,id,type:"updateRef",silent}),!0}removeHyperLink(unitId,subUnitId,id){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(!position)return!1;positionMap.delete(id);const link=matrix.getValue(position.row,position.column);return link&&link.id===id&&matrix.realDeleteValue(position.row,position.column),this._linkUpdate$.next({unitId,subUnitId,payload:position.link,type:"remove"}),!0}getHyperLink(unitId,subUnitId,id){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(position)return matrix.getValue(position.row,position.column)}getHyperLinkByLocation(unitId,subUnitId,row,column){const{matrix}=this._ensureMap(unitId,subUnitId);return matrix.getValue(row,column)}getHyperLinkByLocationSync(unitId,subUnitId,row,column){var _a6,_b,_c,_d,_e;const{matrix}=this._ensureMap(unitId,subUnitId),workbook=this._univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_SHEET),cell=(_a6=workbook==null?void 0:workbook.getSheetBySheetId(subUnitId))==null?void 0:_a6.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);if(link)return{...link,display:cellValueStr}}getSubUnit(unitId,subUnitId){const{matrix}=this._ensureMap(unitId,subUnitId),links=[];return matrix.forValue((row,col,value)=>{value&&links.push(value)}),links}getUnit(unitId){const unitMap=this._linkMap.get(unitId);return unitMap?Array.from(unitMap.keys()).map(subUnitId=>{const links=this.getSubUnit(unitId,subUnitId);return{unitId,subUnitId,links}}):[]}deleteUnit(unitId){const links=this.getUnit(unitId);this._linkMap.delete(unitId),this._linkPositionMap.delete(unitId),this._linkUpdate$.next({type:"unload",unitId,unitLinks:links})}getAll(){return Array.from(this._linkMap.keys()).map(unitId=>this.getUnit(unitId))}},__name(_a,"HyperLinkModel"),_a);exports.HyperLinkModel=__decorateClass$4([__decorateParam$4(0,core.IUniverInstanceService)],exports.HyperLinkModel);var SheetHyperLinkType=(SheetHyperLinkType2=>(SheetHyperLinkType2.SHEET="gid",SheetHyperLinkType2.RANGE="range",SheetHyperLinkType2.DEFINE_NAME="rangeid",SheetHyperLinkType2.INVALID="invalid",SheetHyperLinkType2.URL="url",SheetHyperLinkType2))(SheetHyperLinkType||{});const PLUGIN_CONFIG_KEY="sheets-hyper-link.config",defaultPluginConfig={},AddHyperLinkMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports.HyperLinkModel),{unitId,subUnitId,link}=params;return model.addHyperLink(unitId,subUnitId,link)}},RemoveHyperLinkMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports.HyperLinkModel),{unitId,subUnitId,id}=params;return model.removeHyperLink(unitId,subUnitId,id)}},UpdateHyperLinkMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports.HyperLinkModel),{unitId,subUnitId,payload,id}=params;return model.updateHyperLink(unitId,subUnitId,id,payload,!1)}},UpdateHyperLinkRefMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports.HyperLinkModel),{unitId,subUnitId,id,row,column,silent}=params;return model.updateHyperLinkRef(unitId,subUnitId,id,{row,column},silent)}},SHEET_HYPER_LINK_PLUGIN="SHEET_HYPER_LINK_PLUGIN",ERROR_RANGE="err";var __defProp$3=Object.defineProperty,__getOwnPropDesc$3=Object.getOwnPropertyDescriptor,__decorateClass$3=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$3(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$3(target,key,result),result},"__decorateClass$3"),__decorateParam$3=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$3"),_a2;let SheetsHyperLinkRefRangeController=(_a2=class extends core.Disposable{constructor(_refRangeService,_hyperLinkModel,_selectionManagerService,_commandService){super();__publicField(this,"_disposableMap",new Map);__publicField(this,"_watchDisposableMap",new Map);__publicField(this,"_rangeDisableMap",new Map);__publicField(this,"_rangeWatcherMap",new Map);__publicField(this,"_handlePositionChange",__name((unitId,subUnitId,link,resultRange,silent)=>{const oldRange={startColumn:link.column,endColumn:link.column,startRow:link.row,endRow:link.row};return resultRange?{redos:[{id:UpdateHyperLinkRefMutation.id,params:{unitId,subUnitId,id:link.id,row:resultRange.startRow,column:resultRange.startColumn,silent}}],undos:[{id:UpdateHyperLinkRefMutation.id,params:{unitId,subUnitId,id:link.id,row:oldRange.startRow,column:oldRange.startColumn,silent}}]}:{redos:[{id:RemoveHyperLinkMutation.id,params:{unitId,subUnitId,id:link.id}}],undos:[{id:AddHyperLinkMutation.id,params:{unitId,subUnitId,link}}]}},"_handlePositionChange"));this._refRangeService=_refRangeService,this._hyperLinkModel=_hyperLinkModel,this._selectionManagerService=_selectionManagerService,this._commandService=_commandService,this._initData(),this._initRefRange()}_registerPosition(unitId,subUnitId,link){const id=link.id,oldRange={startColumn:link.column,endColumn:link.column,startRow:link.row,endRow:link.row},handleRefRangeChange=__name(commandInfo=>{const resultRanges=sheets.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(oldRange,commandInfo,{selectionManagerService:this._selectionManagerService}),resultRange=Array.isArray(resultRanges)?resultRanges[0]:resultRanges;return resultRange&&resultRange.startColumn===oldRange.startColumn&&resultRange.startRow===oldRange.startRow?{undos:[],redos:[]}:this._handlePositionChange(unitId,subUnitId,link,resultRange,!1)},"handleRefRangeChange");this._disposableMap.set(id,this._refRangeService.registerRefRange(oldRange,handleRefRangeChange,unitId,subUnitId))}_watchPosition(unitId,subUnitId,link){const id=link.id,oldRange={startColumn:link.column,endColumn:link.column,startRow:link.row,endRow:link.row};this._watchDisposableMap.set(id,this._refRangeService.watchRange(unitId,subUnitId,oldRange,(before,after)=>{const{redos}=this._handlePositionChange(unitId,subUnitId,link,after,!0);core.sequenceExecuteAsync(redos,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(id){const disposable=this._disposableMap.get(id);disposable==null||disposable.dispose(),this._disposableMap.delete(id)}_unwatchPosition(id){const disposable=this._watchDisposableMap.get(id);disposable==null||disposable.dispose(),this._watchDisposableMap.delete(id)}_registerRange(unitId,id,payload,silent=!1){var _a6,_b,_c;if(payload.startsWith("#")){const search=new URLSearchParams(payload.slice(1)),searchObj={gid:(_a6=search.get("gid"))!=null?_a6:"",range:(_b=search.get("range"))!=null?_b:"",rangeid:(_c=search.get("rangeid"))!=null?_c:""};if(searchObj.range&&searchObj.gid){const subUnitId=searchObj.gid,range=engineFormula.deserializeRangeWithSheet(searchObj.range).range;if(core.isValidRange(range)&&searchObj.range!==ERROR_RANGE){const handleRangeChange=__name(commandInfo=>{const resultRange=sheets.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(range,commandInfo,{selectionManagerService:this._selectionManagerService});return resultRange&&engineFormula.serializeRange(resultRange)===engineFormula.serializeRange(range)?{redos:[],undos:[]}:{redos:[{id:UpdateHyperLinkMutation.id,params:{unitId,subUnitId,id,payload:{payload:`#gid=${subUnitId}&range=${resultRange?engineFormula.serializeRange(resultRange):"err"}`}}}],undos:[{id:UpdateHyperLinkMutation.id,params:{unitId,subUnitId,id,payload:{payload}}}]}},"handleRangeChange");this._rangeDisableMap.set(id,this._refRangeService.registerRefRange(range,handleRangeChange,unitId,subUnitId)),silent||this._rangeWatcherMap.set(id,this._refRangeService.watchRange(unitId,subUnitId,range,(before,after)=>{this._hyperLinkModel.updateHyperLink(unitId,subUnitId,id,{payload:`#gid=${subUnitId}&range=${after?engineFormula.serializeRange(after):"err"}`},!0)},!0))}}}}_unregisterRange(id){const disposable=this._rangeDisableMap.get(id);disposable==null||disposable.dispose(),this._rangeDisableMap.delete(id)}_unwatchRange(id){const disposable=this._rangeWatcherMap.get(id);disposable==null||disposable.dispose(),this._rangeWatcherMap.delete(id)}_initData(){this._hyperLinkModel.getAll().forEach(unitData=>{unitData.forEach(subUnitData=>{const{unitId,subUnitId,links}=subUnitData;links.forEach(link=>{this._registerPosition(unitId,subUnitId,link),this._watchPosition(unitId,subUnitId,link),this._registerRange(unitId,link.id,link.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(option=>{switch(option.type){case"add":{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);break}case"remove":{this._unregisterPosition(option.payload.id),this._unwatchPosition(option.payload.id),this._unregisterRange(option.payload.id),this._unwatchRange(option.payload.id);break}case"updateRef":{const{unitId,subUnitId,id,silent}=option,link=this._hyperLinkModel.getHyperLink(unitId,subUnitId,id);if(!link)return;this._unregisterPosition(id),this._registerPosition(unitId,subUnitId,link),silent||(this._unwatchPosition(id),this._watchPosition(unitId,subUnitId,link));break}case"unload":{const{unitLinks}=option;unitLinks.forEach(subUnitData=>{const{links}=subUnitData;links.forEach(link=>{this._unregisterPosition(link.id),this._unwatchPosition(link.id),this._unregisterRange(link.id),this._unwatchRange(link.id)})});break}case"update":{option.silent||this._unwatchRange(option.id),this._unregisterRange(option.id),this._registerRange(option.unitId,option.id,option.payload.payload,option.silent);break}}})),this.disposeWithMe(core.toDisposable(()=>{this._disposableMap.forEach(item=>{item.dispose()}),this._disposableMap.clear()}))}},__name(_a2,"SheetsHyperLinkRefRangeController"),_a2);SheetsHyperLinkRefRangeController=__decorateClass$3([__decorateParam$3(0,core.Inject(sheets.RefRangeService)),__decorateParam$3(1,core.Inject(exports.HyperLinkModel)),__decorateParam$3(2,core.Inject(sheets.SheetsSelectionsService)),__decorateParam$3(3,core.ICommandService)],SheetsHyperLinkRefRangeController);var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2"),_a3;let SheetsHyperLinkController=(_a3=class extends core.Disposable{constructor(_commandService){super(),this._commandService=_commandService,this._registerCommands()}_registerCommands(){[AddHyperLinkMutation,UpdateHyperLinkMutation,RemoveHyperLinkMutation,UpdateHyperLinkRefMutation].forEach(command=>{this._commandService.registerCommand(command)})}},__name(_a3,"SheetsHyperLinkController"),_a3);SheetsHyperLinkController=__decorateClass$2([__decorateParam$2(0,core.ICommandService)],SheetsHyperLinkController);var R=(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))(R||{}),__defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1"),_a4;let SheetsHyperLinkResourceController=(_a4=class extends core.Disposable{constructor(_resourceManagerService,_hyperLinkModel){super(),this._resourceManagerService=_resourceManagerService,this._hyperLinkModel=_hyperLinkModel,this._initSnapshot()}_initSnapshot(){const toJson=__name(unitID=>{const map=this._hyperLinkModel.getUnit(unitID),resultMap={};return map?(map.forEach(info=>{resultMap[info.subUnitId]=info.links.map(({display,...link})=>link)}),JSON.stringify(resultMap)):""},"toJson"),parseJson=__name(json=>{if(!json)return{};try{return JSON.parse(json)}catch{return{}}},"parseJson");this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:SHEET_HYPER_LINK_PLUGIN,businesses:[R.UNIVER_SHEET],toJson:__name(unitID=>toJson(unitID),"toJson"),parseJson:__name(json=>parseJson(json),"parseJson"),onUnLoad:__name(unitID=>{this._hyperLinkModel.deleteUnit(unitID)},"onUnLoad"),onLoad:__name(async(unitID,value)=>{Object.keys(value).forEach(subunitId=>{value[subunitId].forEach(link=>{this._hyperLinkModel.addHyperLink(unitID,subunitId,link)})})},"onLoad")}))}},__name(_a4,"SheetsHyperLinkResourceController"),_a4);SheetsHyperLinkResourceController=__decorateClass$1([__decorateParam$1(0,core.IResourceManagerService),__decorateParam$1(1,core.Inject(exports.HyperLinkModel))],SheetsHyperLinkResourceController);var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key,value)=>key in obj?__defProp2(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),__publicField2=__name((obj,key,value)=>__defNormalProp2(obj,typeof key!="symbol"?key+"":key,value),"__publicField"),_a5;exports.UniverSheetsHyperLinkPlugin=(_a5=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_configService){super(),this._config=_config,this._injector=_injector,this._configService=_configService;const{...rest}=this._config;this._configService.setConfig(PLUGIN_CONFIG_KEY,rest)}onStarting(){[[SheetsHyperLinkResourceController],[SheetsHyperLinkController],[SheetsHyperLinkRefRangeController],[exports.HyperLinkModel]].forEach(dep=>{this._injector.add(dep)}),this._injector.get(SheetsHyperLinkRefRangeController),this._injector.get(SheetsHyperLinkResourceController),this._injector.get(SheetsHyperLinkController)}},__name(_a5,"UniverSheetsHyperLinkPlugin"),_a5);__publicField2(exports.UniverSheetsHyperLinkPlugin,"pluginName",SHEET_HYPER_LINK_PLUGIN);__publicField2(exports.UniverSheetsHyperLinkPlugin,"type",core.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsHyperLinkPlugin=__decorateClass([core.DependentOn(sheets.UniverSheetsPlugin),__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService)],exports.UniverSheetsHyperLinkPlugin);exports.AddHyperLinkMutation=AddHyperLinkMutation;exports.ERROR_RANGE=ERROR_RANGE;exports.RemoveHyperLinkMutation=RemoveHyperLinkMutation;exports.SheetHyperLinkType=SheetHyperLinkType;exports.UpdateHyperLinkMutation=UpdateHyperLinkMutation;exports.UpdateHyperLinkRefMutation=UpdateHyperLinkRefMutation;