@univerjs/sheets-hyper-link 1.0.0-insiders.20260813-7c9aa50 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,176 @@
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/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  | Package | UMD global | CSS | Locales | Facade entry |
12
12
  | --- | --- | :---: | :---: | :---: |
13
- | `@univerjs/sheets-hyper-link` | `UniverSheetsHyperLink` | No | No | Yes |
13
+ | `@univerjs/sheets-hyper-link` | `UniverSheetsHyperLink` | No | Yes | Yes |
14
14
 
15
15
  ## Installation
16
16
 
@@ -25,7 +25,16 @@ Keep all `@univerjs/*` packages on the same version.
25
25
  ## Usage
26
26
 
27
27
  ```ts
28
+ import { LocaleType, mergeLocales, Univer } from '@univerjs/core';
28
29
  import { UniverSheetsHyperLinkPlugin } from '@univerjs/sheets-hyper-link';
30
+ import EnUS from '@univerjs/sheets-hyper-link/locale/en-US';
31
+
32
+ const univer = new Univer({
33
+ locale: LocaleType.EN_US,
34
+ locales: {
35
+ [LocaleType.EN_US]: mergeLocales(EnUS),
36
+ },
37
+ });
29
38
 
30
39
  univer.registerPlugin(UniverSheetsHyperLinkPlugin);
31
40
  ```
@@ -39,4 +48,3 @@ Use this package with `@univerjs/sheets-hyper-link-ui` when users need hyperlink
39
48
  - [Documentation](https://docs.univer.ai)
40
49
  - [NPM package](https://npmjs.com/package/@univerjs/sheets-hyper-link)
41
50
  - [GitHub repository](https://github.com/dream-num/univer)
42
-
package/lib/cjs/facade.js CHANGED
@@ -48,7 +48,7 @@ _univerjs_sheets_facade.FWorksheet.extend(FWorksheetHyperlinkMixin);
48
48
  //#endregion
49
49
  //#region src/facade/f-range.ts
50
50
  var FRangeSheetsHyperlinkMixin = class extends _univerjs_sheets_facade.FRange {
51
- setHyperLink(url, label) {
51
+ setHyperLink(url, label, tooltip) {
52
52
  return this._commandService.executeCommand(_univerjs_sheets_hyper_link.AddHyperLinkCommand.id, {
53
53
  unitId: this.getUnitId(),
54
54
  subUnitId: this._worksheet.getSheetId(),
@@ -57,7 +57,8 @@ var FRangeSheetsHyperlinkMixin = class extends _univerjs_sheets_facade.FRange {
57
57
  row: this._range.startRow,
58
58
  column: this._range.startColumn,
59
59
  payload: url,
60
- display: label
60
+ display: label,
61
+ tooltip
61
62
  }
62
63
  });
63
64
  }
@@ -78,13 +79,14 @@ var FRangeSheetsHyperlinkMixin = class extends _univerjs_sheets_facade.FRange {
78
79
  row,
79
80
  column,
80
81
  url,
81
- label
82
+ label,
83
+ tooltip: (properties === null || properties === void 0 ? void 0 : properties.tooltip) ?? (properties === null || properties === void 0 ? void 0 : properties._xlsxHyperlinkTooltip)
82
84
  });
83
85
  }
84
86
  });
85
87
  return hyperlinks;
86
88
  }
87
- updateHyperLink(url, label) {
89
+ updateHyperLink(url, label, tooltip) {
88
90
  const hyperlink = this.getHyperLinks().find((link) => link.row === this._range.startRow && link.column === this._range.startColumn);
89
91
  if (!hyperlink) return Promise.reject(/* @__PURE__ */ new Error("No hyperlink found in the top left cell of the range"));
90
92
  const { id, row, column } = hyperlink;
@@ -96,7 +98,8 @@ var FRangeSheetsHyperlinkMixin = class extends _univerjs_sheets_facade.FRange {
96
98
  column,
97
99
  payload: {
98
100
  payload: url,
99
- display: label
101
+ display: label ?? hyperlink.label,
102
+ tooltip
100
103
  }
101
104
  });
102
105
  }
package/lib/cjs/index.js CHANGED
@@ -5,7 +5,7 @@ let _univerjs_sheets = require("@univerjs/sheets");
5
5
  let rxjs = require("rxjs");
6
6
  let _univerjs_engine_formula = require("@univerjs/engine-formula");
7
7
 
8
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
8
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
9
9
  function _typeof(o) {
10
10
  "@babel/helpers - typeof";
11
11
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -16,7 +16,7 @@ function _typeof(o) {
16
16
  }
17
17
 
18
18
  //#endregion
19
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPrimitive.js
19
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
20
20
  function toPrimitive(t, r) {
21
21
  if ("object" != _typeof(t) || !t) return t;
22
22
  var e = t[Symbol.toPrimitive];
@@ -29,14 +29,14 @@ function toPrimitive(t, r) {
29
29
  }
30
30
 
31
31
  //#endregion
32
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPropertyKey.js
32
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
33
33
  function toPropertyKey(t) {
34
34
  var i = toPrimitive(t, "string");
35
35
  return "symbol" == _typeof(i) ? i : i + "";
36
36
  }
37
37
 
38
38
  //#endregion
39
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/defineProperty.js
39
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
40
40
  function _defineProperty(e, r, t) {
41
41
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
42
42
  value: t,
@@ -47,7 +47,7 @@ function _defineProperty(e, r, t) {
47
47
  }
48
48
 
49
49
  //#endregion
50
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorateParam.js
50
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
51
51
  function __decorateParam(paramIndex, decorator) {
52
52
  return function(target, key) {
53
53
  decorator(target, key, paramIndex);
@@ -55,7 +55,7 @@ function __decorateParam(paramIndex, decorator) {
55
55
  }
56
56
 
57
57
  //#endregion
58
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorate.js
58
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
59
59
  function __decorate(decorators, target, key, desc) {
60
60
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
61
61
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -300,7 +300,10 @@ const AddHyperLinkCommand = {
300
300
  endIndex: display.length - 1,
301
301
  rangeType: _univerjs_core.CustomRangeType.HYPERLINK,
302
302
  rangeId: id,
303
- properties: { url: payload }
303
+ properties: {
304
+ url: payload,
305
+ tooltip: link.tooltip
306
+ }
304
307
  }]
305
308
  },
306
309
  doc: doc.documentModel
@@ -316,6 +319,7 @@ const AddHyperLinkCommand = {
316
319
  rangeType: _univerjs_core.CustomRangeType.HYPERLINK,
317
320
  properties: {
318
321
  url: payload,
322
+ tooltip: link.tooltip,
319
323
  refId: id
320
324
  }
321
325
  });
@@ -394,6 +398,7 @@ const AddRichHyperLinkCommand = {
394
398
  rangeType: _univerjs_core.CustomRangeType.HYPERLINK,
395
399
  properties: {
396
400
  url: payload,
401
+ tooltip: link.tooltip,
397
402
  refId: newId
398
403
  }
399
404
  });
@@ -511,7 +516,7 @@ const UpdateHyperLinkCommand = {
511
516
  type: _univerjs_core.CommandType.COMMAND,
512
517
  id: "sheets.command.update-hyper-link",
513
518
  async handler(accessor, params) {
514
- var _snapshot$body, _oldBody$textRuns;
519
+ var _snapshot$body, _oldBody$textRuns, _range$properties, _range$properties2;
515
520
  if (!params) return false;
516
521
  const commandService = accessor.get(_univerjs_core.ICommandService);
517
522
  const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
@@ -545,7 +550,10 @@ const UpdateHyperLinkCommand = {
545
550
  rangeType: _univerjs_core.CustomRangeType.HYPERLINK,
546
551
  startIndex: 0,
547
552
  endIndex: display.length - 1,
548
- properties: { url: payload }
553
+ properties: {
554
+ url: payload,
555
+ tooltip: link.tooltip ?? ((_range$properties = range.properties) === null || _range$properties === void 0 ? void 0 : _range$properties.tooltip) ?? ((_range$properties2 = range.properties) === null || _range$properties2 === void 0 ? void 0 : _range$properties2._xlsxHyperlinkTooltip)
556
+ }
549
557
  }],
550
558
  textRuns: textRun ? [textRun] : void 0
551
559
  },
@@ -619,7 +627,7 @@ const UpdateRichHyperLinkCommand = {
619
627
  type: _univerjs_core.CommandType.COMMAND,
620
628
  id: "sheets.command.update-rich-hyper-link",
621
629
  handler: (accessor, params) => {
622
- var _doc$getBody, _oldBody$textRuns2;
630
+ var _doc$getBody, _oldBody$textRuns2, _range$properties3, _range$properties4;
623
631
  if (!params) return false;
624
632
  const { documentId: unitId, payload, id: rangeId } = params;
625
633
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
@@ -641,7 +649,10 @@ const UpdateRichHyperLinkCommand = {
641
649
  rangeType: _univerjs_core.CustomRangeType.HYPERLINK,
642
650
  startIndex: 0,
643
651
  endIndex: display.length - 1,
644
- properties: { url: payload.payload }
652
+ properties: {
653
+ url: payload.payload,
654
+ tooltip: payload.tooltip ?? ((_range$properties3 = range.properties) === null || _range$properties3 === void 0 ? void 0 : _range$properties3.tooltip) ?? ((_range$properties4 = range.properties) === null || _range$properties4 === void 0 ? void 0 : _range$properties4._xlsxHyperlinkTooltip)
655
+ }
645
656
  }],
646
657
  textRuns: textRun ? [textRun] : void 0
647
658
  },
@@ -689,7 +700,8 @@ const UpdateRichHyperLinkMutation = {
689
700
  var _cell$p;
690
701
  if (!params) return false;
691
702
  const { unitId, subUnitId, row, col, id, url } = params;
692
- const sheetTarget = (0, _univerjs_sheets.getSheetCommandTarget)(accessor.get(_univerjs_core.IUniverInstanceService), {
703
+ const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
704
+ const sheetTarget = (0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService, {
693
705
  unitId,
694
706
  subUnitId
695
707
  });
@@ -706,7 +718,7 @@ const UpdateRichHyperLinkMutation = {
706
718
  //#endregion
707
719
  //#region package.json
708
720
  var name = "@univerjs/sheets-hyper-link";
709
- var version = "1.0.0-insiders.20260813-7c9aa50";
721
+ var version = "1.0.0";
710
722
 
711
723
  //#endregion
712
724
  //#region src/config/config.ts
@@ -969,7 +981,6 @@ let SheetsHyperLinkRefRangeController = class SheetsHyperLinkRefRangeController
969
981
  if (!option.silent) this._unwatchRange(option.id);
970
982
  this._unregisterRange(option.id);
971
983
  this._registerRange(option.unitId, option.id, option.payload.payload, option.silent);
972
- break;
973
984
  }
974
985
  }));
975
986
  this.disposeWithMe((0, _univerjs_core.toDisposable)(() => {
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/locale/ar-SA.ts
3
2
  const locale = { "sheets-hyper-link": { message: { refError: "نطاق غير صالح" } } };
4
3
 
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/locale/ca-ES.ts
3
2
  const locale = { "sheets-hyper-link": { message: { refError: "Interval no vàlid" } } };
4
3
 
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/locale/de-DE.ts
3
2
  const locale = { "sheets-hyper-link": { message: { refError: "Ungültiger Bereich" } } };
4
3
 
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/locale/en-US.ts
3
2
  /**
4
3
  * Copyright 2023-present DreamNum Co., Ltd.
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/locale/es-ES.ts
3
2
  const locale = { "sheets-hyper-link": { message: { refError: "Rango no válido" } } };
4
3
 
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/locale/fa-IR.ts
3
2
  const locale = { "sheets-hyper-link": { message: { refError: "محدوده نامعتبر" } } };
4
3
 
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/locale/fr-FR.ts
3
2
  const locale = { "sheets-hyper-link": { message: { refError: "Plage invalide" } } };
4
3
 
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/locale/id-ID.ts
3
2
  const locale = { "sheets-hyper-link": { message: { refError: "Rentang Tidak Valid" } } };
4
3
 
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/locale/it-IT.ts
3
2
  const locale = { "sheets-hyper-link": { message: { refError: "Intervallo non valido" } } };
4
3
 
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/locale/ja-JP.ts
3
2
  const locale = { "sheets-hyper-link": { message: { refError: "無効な範囲です" } } };
4
3
 
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/locale/ko-KR.ts
3
2
  const locale = { "sheets-hyper-link": { message: { refError: "잘못된 범위입니다" } } };
4
3
 
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/locale/pl-PL.ts
3
2
  const locale = { "sheets-hyper-link": { message: { refError: "Nieprawidłowy zakres" } } };
4
3
 
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/locale/pt-BR.ts
3
2
  const locale = { "sheets-hyper-link": { message: { refError: "Intervalo Inválido" } } };
4
3
 
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/locale/ru-RU.ts
3
2
  const locale = { "sheets-hyper-link": { message: { refError: "Недопустимый диапазон" } } };
4
3
 
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/locale/sk-SK.ts
3
2
  const locale = { "sheets-hyper-link": { message: { refError: "Neplatný rozsah" } } };
4
3
 
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/locale/vi-VN.ts
3
2
  const locale = { "sheets-hyper-link": { message: { refError: "Tham chiếu lỗi" } } };
4
3
 
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/locale/zh-CN.ts
3
2
  const locale = { "sheets-hyper-link": { message: { refError: "错误的引用" } } };
4
3
 
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/locale/zh-HK.ts
3
2
  const locale = { "sheets-hyper-link": { message: { refError: "錯誤的引用" } } };
4
3
 
@@ -1,4 +1,3 @@
1
-
2
1
  //#region src/locale/zh-TW.ts
3
2
  const locale = { "sheets-hyper-link": { message: { refError: "錯誤的引用" } } };
4
3
 
package/lib/es/facade.js CHANGED
@@ -47,7 +47,7 @@ FWorksheet.extend(FWorksheetHyperlinkMixin);
47
47
  //#endregion
48
48
  //#region src/facade/f-range.ts
49
49
  var FRangeSheetsHyperlinkMixin = class extends FRange {
50
- setHyperLink(url, label) {
50
+ setHyperLink(url, label, tooltip) {
51
51
  return this._commandService.executeCommand(AddHyperLinkCommand.id, {
52
52
  unitId: this.getUnitId(),
53
53
  subUnitId: this._worksheet.getSheetId(),
@@ -56,7 +56,8 @@ var FRangeSheetsHyperlinkMixin = class extends FRange {
56
56
  row: this._range.startRow,
57
57
  column: this._range.startColumn,
58
58
  payload: url,
59
- display: label
59
+ display: label,
60
+ tooltip
60
61
  }
61
62
  });
62
63
  }
@@ -77,13 +78,14 @@ var FRangeSheetsHyperlinkMixin = class extends FRange {
77
78
  row,
78
79
  column,
79
80
  url,
80
- label
81
+ label,
82
+ tooltip: (properties === null || properties === void 0 ? void 0 : properties.tooltip) ?? (properties === null || properties === void 0 ? void 0 : properties._xlsxHyperlinkTooltip)
81
83
  });
82
84
  }
83
85
  });
84
86
  return hyperlinks;
85
87
  }
86
- updateHyperLink(url, label) {
88
+ updateHyperLink(url, label, tooltip) {
87
89
  const hyperlink = this.getHyperLinks().find((link) => link.row === this._range.startRow && link.column === this._range.startColumn);
88
90
  if (!hyperlink) return Promise.reject(/* @__PURE__ */ new Error("No hyperlink found in the top left cell of the range"));
89
91
  const { id, row, column } = hyperlink;
@@ -95,7 +97,8 @@ var FRangeSheetsHyperlinkMixin = class extends FRange {
95
97
  column,
96
98
  payload: {
97
99
  payload: url,
98
- display: label
100
+ display: label ?? hyperlink.label,
101
+ tooltip
99
102
  }
100
103
  });
101
104
  }
package/lib/es/index.js CHANGED
@@ -4,7 +4,7 @@ import { AFTER_CELL_EDIT, ClearSelectionAllCommand, ClearSelectionContentCommand
4
4
  import { Subject } from "rxjs";
5
5
  import { IDefinedNamesService, UniverFormulaEnginePlugin, deserializeRangeWithSheet, serializeRange, serializeRangeWithSheet } from "@univerjs/engine-formula";
6
6
 
7
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
7
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
8
8
  function _typeof(o) {
9
9
  "@babel/helpers - typeof";
10
10
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -15,7 +15,7 @@ function _typeof(o) {
15
15
  }
16
16
 
17
17
  //#endregion
18
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPrimitive.js
18
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
19
19
  function toPrimitive(t, r) {
20
20
  if ("object" != _typeof(t) || !t) return t;
21
21
  var e = t[Symbol.toPrimitive];
@@ -28,14 +28,14 @@ function toPrimitive(t, r) {
28
28
  }
29
29
 
30
30
  //#endregion
31
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPropertyKey.js
31
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
32
32
  function toPropertyKey(t) {
33
33
  var i = toPrimitive(t, "string");
34
34
  return "symbol" == _typeof(i) ? i : i + "";
35
35
  }
36
36
 
37
37
  //#endregion
38
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/defineProperty.js
38
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
39
39
  function _defineProperty(e, r, t) {
40
40
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
41
41
  value: t,
@@ -46,7 +46,7 @@ function _defineProperty(e, r, t) {
46
46
  }
47
47
 
48
48
  //#endregion
49
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorateParam.js
49
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
50
50
  function __decorateParam(paramIndex, decorator) {
51
51
  return function(target, key) {
52
52
  decorator(target, key, paramIndex);
@@ -54,7 +54,7 @@ function __decorateParam(paramIndex, decorator) {
54
54
  }
55
55
 
56
56
  //#endregion
57
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorate.js
57
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
58
58
  function __decorate(decorators, target, key, desc) {
59
59
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
60
60
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -299,7 +299,10 @@ const AddHyperLinkCommand = {
299
299
  endIndex: display.length - 1,
300
300
  rangeType: CustomRangeType.HYPERLINK,
301
301
  rangeId: id,
302
- properties: { url: payload }
302
+ properties: {
303
+ url: payload,
304
+ tooltip: link.tooltip
305
+ }
303
306
  }]
304
307
  },
305
308
  doc: doc.documentModel
@@ -315,6 +318,7 @@ const AddHyperLinkCommand = {
315
318
  rangeType: CustomRangeType.HYPERLINK,
316
319
  properties: {
317
320
  url: payload,
321
+ tooltip: link.tooltip,
318
322
  refId: id
319
323
  }
320
324
  });
@@ -393,6 +397,7 @@ const AddRichHyperLinkCommand = {
393
397
  rangeType: CustomRangeType.HYPERLINK,
394
398
  properties: {
395
399
  url: payload,
400
+ tooltip: link.tooltip,
396
401
  refId: newId
397
402
  }
398
403
  });
@@ -510,7 +515,7 @@ const UpdateHyperLinkCommand = {
510
515
  type: CommandType.COMMAND,
511
516
  id: "sheets.command.update-hyper-link",
512
517
  async handler(accessor, params) {
513
- var _snapshot$body, _oldBody$textRuns;
518
+ var _snapshot$body, _oldBody$textRuns, _range$properties, _range$properties2;
514
519
  if (!params) return false;
515
520
  const commandService = accessor.get(ICommandService);
516
521
  const undoRedoService = accessor.get(IUndoRedoService);
@@ -544,7 +549,10 @@ const UpdateHyperLinkCommand = {
544
549
  rangeType: CustomRangeType.HYPERLINK,
545
550
  startIndex: 0,
546
551
  endIndex: display.length - 1,
547
- properties: { url: payload }
552
+ properties: {
553
+ url: payload,
554
+ tooltip: link.tooltip ?? ((_range$properties = range.properties) === null || _range$properties === void 0 ? void 0 : _range$properties.tooltip) ?? ((_range$properties2 = range.properties) === null || _range$properties2 === void 0 ? void 0 : _range$properties2._xlsxHyperlinkTooltip)
555
+ }
548
556
  }],
549
557
  textRuns: textRun ? [textRun] : void 0
550
558
  },
@@ -618,7 +626,7 @@ const UpdateRichHyperLinkCommand = {
618
626
  type: CommandType.COMMAND,
619
627
  id: "sheets.command.update-rich-hyper-link",
620
628
  handler: (accessor, params) => {
621
- var _doc$getBody, _oldBody$textRuns2;
629
+ var _doc$getBody, _oldBody$textRuns2, _range$properties3, _range$properties4;
622
630
  if (!params) return false;
623
631
  const { documentId: unitId, payload, id: rangeId } = params;
624
632
  const univerInstanceService = accessor.get(IUniverInstanceService);
@@ -640,7 +648,10 @@ const UpdateRichHyperLinkCommand = {
640
648
  rangeType: CustomRangeType.HYPERLINK,
641
649
  startIndex: 0,
642
650
  endIndex: display.length - 1,
643
- properties: { url: payload.payload }
651
+ properties: {
652
+ url: payload.payload,
653
+ tooltip: payload.tooltip ?? ((_range$properties3 = range.properties) === null || _range$properties3 === void 0 ? void 0 : _range$properties3.tooltip) ?? ((_range$properties4 = range.properties) === null || _range$properties4 === void 0 ? void 0 : _range$properties4._xlsxHyperlinkTooltip)
654
+ }
644
655
  }],
645
656
  textRuns: textRun ? [textRun] : void 0
646
657
  },
@@ -688,7 +699,8 @@ const UpdateRichHyperLinkMutation = {
688
699
  var _cell$p;
689
700
  if (!params) return false;
690
701
  const { unitId, subUnitId, row, col, id, url } = params;
691
- const sheetTarget = getSheetCommandTarget(accessor.get(IUniverInstanceService), {
702
+ const univerInstanceService = accessor.get(IUniverInstanceService);
703
+ const sheetTarget = getSheetCommandTarget(univerInstanceService, {
692
704
  unitId,
693
705
  subUnitId
694
706
  });
@@ -705,7 +717,7 @@ const UpdateRichHyperLinkMutation = {
705
717
  //#endregion
706
718
  //#region package.json
707
719
  var name = "@univerjs/sheets-hyper-link";
708
- var version = "1.0.0-insiders.20260813-7c9aa50";
720
+ var version = "1.0.0";
709
721
 
710
722
  //#endregion
711
723
  //#region src/config/config.ts
@@ -968,7 +980,6 @@ let SheetsHyperLinkRefRangeController = class SheetsHyperLinkRefRangeController
968
980
  if (!option.silent) this._unwatchRange(option.id);
969
981
  this._unregisterRange(option.id);
970
982
  this._registerRange(option.unitId, option.id, option.payload.payload, option.silent);
971
- break;
972
983
  }
973
984
  }));
974
985
  this.disposeWithMe(toDisposable(() => {
package/lib/facade.js CHANGED
@@ -47,7 +47,7 @@ FWorksheet.extend(FWorksheetHyperlinkMixin);
47
47
  //#endregion
48
48
  //#region src/facade/f-range.ts
49
49
  var FRangeSheetsHyperlinkMixin = class extends FRange {
50
- setHyperLink(url, label) {
50
+ setHyperLink(url, label, tooltip) {
51
51
  return this._commandService.executeCommand(AddHyperLinkCommand.id, {
52
52
  unitId: this.getUnitId(),
53
53
  subUnitId: this._worksheet.getSheetId(),
@@ -56,7 +56,8 @@ var FRangeSheetsHyperlinkMixin = class extends FRange {
56
56
  row: this._range.startRow,
57
57
  column: this._range.startColumn,
58
58
  payload: url,
59
- display: label
59
+ display: label,
60
+ tooltip
60
61
  }
61
62
  });
62
63
  }
@@ -77,13 +78,14 @@ var FRangeSheetsHyperlinkMixin = class extends FRange {
77
78
  row,
78
79
  column,
79
80
  url,
80
- label
81
+ label,
82
+ tooltip: (properties === null || properties === void 0 ? void 0 : properties.tooltip) ?? (properties === null || properties === void 0 ? void 0 : properties._xlsxHyperlinkTooltip)
81
83
  });
82
84
  }
83
85
  });
84
86
  return hyperlinks;
85
87
  }
86
- updateHyperLink(url, label) {
88
+ updateHyperLink(url, label, tooltip) {
87
89
  const hyperlink = this.getHyperLinks().find((link) => link.row === this._range.startRow && link.column === this._range.startColumn);
88
90
  if (!hyperlink) return Promise.reject(/* @__PURE__ */ new Error("No hyperlink found in the top left cell of the range"));
89
91
  const { id, row, column } = hyperlink;
@@ -95,7 +97,8 @@ var FRangeSheetsHyperlinkMixin = class extends FRange {
95
97
  column,
96
98
  payload: {
97
99
  payload: url,
98
- display: label
100
+ display: label ?? hyperlink.label,
101
+ tooltip
99
102
  }
100
103
  });
101
104
  }
package/lib/index.js CHANGED
@@ -4,7 +4,7 @@ import { AFTER_CELL_EDIT, ClearSelectionAllCommand, ClearSelectionContentCommand
4
4
  import { Subject } from "rxjs";
5
5
  import { IDefinedNamesService, UniverFormulaEnginePlugin, deserializeRangeWithSheet, serializeRange, serializeRangeWithSheet } from "@univerjs/engine-formula";
6
6
 
7
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
7
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
8
8
  function _typeof(o) {
9
9
  "@babel/helpers - typeof";
10
10
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -15,7 +15,7 @@ function _typeof(o) {
15
15
  }
16
16
 
17
17
  //#endregion
18
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPrimitive.js
18
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
19
19
  function toPrimitive(t, r) {
20
20
  if ("object" != _typeof(t) || !t) return t;
21
21
  var e = t[Symbol.toPrimitive];
@@ -28,14 +28,14 @@ function toPrimitive(t, r) {
28
28
  }
29
29
 
30
30
  //#endregion
31
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPropertyKey.js
31
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
32
32
  function toPropertyKey(t) {
33
33
  var i = toPrimitive(t, "string");
34
34
  return "symbol" == _typeof(i) ? i : i + "";
35
35
  }
36
36
 
37
37
  //#endregion
38
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/defineProperty.js
38
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
39
39
  function _defineProperty(e, r, t) {
40
40
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
41
41
  value: t,
@@ -46,7 +46,7 @@ function _defineProperty(e, r, t) {
46
46
  }
47
47
 
48
48
  //#endregion
49
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorateParam.js
49
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
50
50
  function __decorateParam(paramIndex, decorator) {
51
51
  return function(target, key) {
52
52
  decorator(target, key, paramIndex);
@@ -54,7 +54,7 @@ function __decorateParam(paramIndex, decorator) {
54
54
  }
55
55
 
56
56
  //#endregion
57
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorate.js
57
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
58
58
  function __decorate(decorators, target, key, desc) {
59
59
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
60
60
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -299,7 +299,10 @@ const AddHyperLinkCommand = {
299
299
  endIndex: display.length - 1,
300
300
  rangeType: CustomRangeType.HYPERLINK,
301
301
  rangeId: id,
302
- properties: { url: payload }
302
+ properties: {
303
+ url: payload,
304
+ tooltip: link.tooltip
305
+ }
303
306
  }]
304
307
  },
305
308
  doc: doc.documentModel
@@ -315,6 +318,7 @@ const AddHyperLinkCommand = {
315
318
  rangeType: CustomRangeType.HYPERLINK,
316
319
  properties: {
317
320
  url: payload,
321
+ tooltip: link.tooltip,
318
322
  refId: id
319
323
  }
320
324
  });
@@ -393,6 +397,7 @@ const AddRichHyperLinkCommand = {
393
397
  rangeType: CustomRangeType.HYPERLINK,
394
398
  properties: {
395
399
  url: payload,
400
+ tooltip: link.tooltip,
396
401
  refId: newId
397
402
  }
398
403
  });
@@ -510,7 +515,7 @@ const UpdateHyperLinkCommand = {
510
515
  type: CommandType.COMMAND,
511
516
  id: "sheets.command.update-hyper-link",
512
517
  async handler(accessor, params) {
513
- var _snapshot$body, _oldBody$textRuns;
518
+ var _snapshot$body, _oldBody$textRuns, _range$properties, _range$properties2;
514
519
  if (!params) return false;
515
520
  const commandService = accessor.get(ICommandService);
516
521
  const undoRedoService = accessor.get(IUndoRedoService);
@@ -544,7 +549,10 @@ const UpdateHyperLinkCommand = {
544
549
  rangeType: CustomRangeType.HYPERLINK,
545
550
  startIndex: 0,
546
551
  endIndex: display.length - 1,
547
- properties: { url: payload }
552
+ properties: {
553
+ url: payload,
554
+ tooltip: link.tooltip ?? ((_range$properties = range.properties) === null || _range$properties === void 0 ? void 0 : _range$properties.tooltip) ?? ((_range$properties2 = range.properties) === null || _range$properties2 === void 0 ? void 0 : _range$properties2._xlsxHyperlinkTooltip)
555
+ }
548
556
  }],
549
557
  textRuns: textRun ? [textRun] : void 0
550
558
  },
@@ -618,7 +626,7 @@ const UpdateRichHyperLinkCommand = {
618
626
  type: CommandType.COMMAND,
619
627
  id: "sheets.command.update-rich-hyper-link",
620
628
  handler: (accessor, params) => {
621
- var _doc$getBody, _oldBody$textRuns2;
629
+ var _doc$getBody, _oldBody$textRuns2, _range$properties3, _range$properties4;
622
630
  if (!params) return false;
623
631
  const { documentId: unitId, payload, id: rangeId } = params;
624
632
  const univerInstanceService = accessor.get(IUniverInstanceService);
@@ -640,7 +648,10 @@ const UpdateRichHyperLinkCommand = {
640
648
  rangeType: CustomRangeType.HYPERLINK,
641
649
  startIndex: 0,
642
650
  endIndex: display.length - 1,
643
- properties: { url: payload.payload }
651
+ properties: {
652
+ url: payload.payload,
653
+ tooltip: payload.tooltip ?? ((_range$properties3 = range.properties) === null || _range$properties3 === void 0 ? void 0 : _range$properties3.tooltip) ?? ((_range$properties4 = range.properties) === null || _range$properties4 === void 0 ? void 0 : _range$properties4._xlsxHyperlinkTooltip)
654
+ }
644
655
  }],
645
656
  textRuns: textRun ? [textRun] : void 0
646
657
  },
@@ -688,7 +699,8 @@ const UpdateRichHyperLinkMutation = {
688
699
  var _cell$p;
689
700
  if (!params) return false;
690
701
  const { unitId, subUnitId, row, col, id, url } = params;
691
- const sheetTarget = getSheetCommandTarget(accessor.get(IUniverInstanceService), {
702
+ const univerInstanceService = accessor.get(IUniverInstanceService);
703
+ const sheetTarget = getSheetCommandTarget(univerInstanceService, {
692
704
  unitId,
693
705
  subUnitId
694
706
  });
@@ -705,7 +717,7 @@ const UpdateRichHyperLinkMutation = {
705
717
  //#endregion
706
718
  //#region package.json
707
719
  var name = "@univerjs/sheets-hyper-link";
708
- var version = "1.0.0-insiders.20260813-7c9aa50";
720
+ var version = "1.0.0";
709
721
 
710
722
  //#endregion
711
723
  //#region src/config/config.ts
@@ -968,7 +980,6 @@ let SheetsHyperLinkRefRangeController = class SheetsHyperLinkRefRangeController
968
980
  if (!option.silent) this._unwatchRange(option.id);
969
981
  this._unregisterRange(option.id);
970
982
  this._registerRange(option.unitId, option.id, option.payload.payload, option.silent);
971
- break;
972
983
  }
973
984
  }));
974
985
  this.disposeWithMe(toDisposable(() => {
@@ -20,6 +20,7 @@ export interface ICellHyperLink {
20
20
  column: number;
21
21
  url: string;
22
22
  label: string;
23
+ tooltip?: string;
23
24
  }
24
25
  /**
25
26
  * @ignore
@@ -30,7 +31,8 @@ export interface IFRangeSheetsHyperlinkMixin {
30
31
  * The hyperlink can be a URL, a range link, or a sheet link.
31
32
  * When the hyperlink is a range link or a sheet link, the url should be the url of the target range or sheet.
32
33
  * @param {string} url - The hyperlink url, can be a URL, a range link, or a sheet link.
33
- * @param {string} [label] - The display text of the hyperlink. If not provided, the url will be used as the display text.
34
+ * @param {string} [label] - The display text of the hyperlink. If omitted, the existing cell text is linked. Supply a label when linking an empty cell.
35
+ * @param {string} [tooltip] - Optional text shown inside the hyperlink popup.
34
36
  * @return {Promise<boolean>} A promise that resolves to true if the hyperlink is set successfully, otherwise false.
35
37
  *
36
38
  * @example
@@ -62,10 +64,10 @@ export interface IFRangeSheetsHyperlinkMixin {
62
64
  * await fRange4.setHyperLink(definedNameHyperlinkUrl, 'Link to MyDefinedName');
63
65
  * ```
64
66
  */
65
- setHyperLink(url: string, label?: string): Promise<boolean>;
67
+ setHyperLink(url: string, label?: string, tooltip?: string): Promise<boolean>;
66
68
  /**
67
- * Get all hyperlinks in this range.
68
- * @return {ICellHyperLink[]} An array of hyperlinks in this range.
69
+ * Gets the first hyperlink from each cell containing hyperlinks in this range.
70
+ * @returns {ICellHyperLink[]} At most one hyperlink per cell, with absolute, zero-based worksheet coordinates.
69
71
  *
70
72
  * @example
71
73
  * ```ts
@@ -79,8 +81,11 @@ export interface IFRangeSheetsHyperlinkMixin {
79
81
  /**
80
82
  * Update the hyperlink of this range top left cell.
81
83
  * @param {string} url - The new hyperlink url, can be a URL, a range link, or a sheet link.
82
- * @param {string} [label] - The new display text of the hyperlink. If not provided, the url will be used as the display text.
84
+ * @param {string} [label] - The new display text of the hyperlink. If omitted, the existing hyperlink label is preserved.
85
+ * @param {string} [tooltip] - Omit to preserve the current tooltip; use an empty string to clear it.
83
86
  *
87
+ * @returns {Promise<boolean>} A promise resolving to whether the update succeeded.
88
+ * @throws {Error} The promise rejects if the top-left cell contains no hyperlink.
84
89
  * @example
85
90
  * ```ts
86
91
  * const fWorkbook = univerAPI.getActiveWorkbook();
@@ -98,7 +103,7 @@ export interface IFRangeSheetsHyperlinkMixin {
98
103
  * await fRange.updateHyperLink(rangeUrl, 'Link to B2:D4');
99
104
  * ```
100
105
  */
101
- updateHyperLink(url: string, label?: string): Promise<boolean>;
106
+ updateHyperLink(url: string, label?: string, tooltip?: string): Promise<boolean>;
102
107
  /**
103
108
  * Cancel all hyperlinks in this range. If a hyperlink is provided, only cancel the specified hyperlink.
104
109
  * @param {ICellHyperLink} [hyperlink] - The hyperlink to be cancelled. If not provided, all hyperlinks in this range will be cancelled.
@@ -144,9 +149,9 @@ export interface IFRangeSheetsHyperlinkMixin {
144
149
  getUrl(): string;
145
150
  }
146
151
  export declare class FRangeSheetsHyperlinkMixin extends FRange implements IFRangeSheetsHyperlinkMixin {
147
- setHyperLink(url: string, label?: string): Promise<boolean>;
152
+ setHyperLink(url: string, label?: string, tooltip?: string): Promise<boolean>;
148
153
  getHyperLinks(): ICellHyperLink[];
149
- updateHyperLink(url: string, label?: string): Promise<boolean>;
154
+ updateHyperLink(url: string, label?: string, tooltip?: string): Promise<boolean>;
150
155
  cancelHyperLink(hyperlink?: ICellHyperLink): boolean;
151
156
  getUrl(): string;
152
157
  }
@@ -77,6 +77,7 @@ export declare class HyperLinkModel extends Disposable {
77
77
  row: number;
78
78
  column: number;
79
79
  payload: string;
80
+ tooltip?: string;
80
81
  } | undefined;
81
82
  getSubUnit(unitId: string, subUnitId: string): ISheetHyperLink[];
82
83
  getUnit(unitId: string): {
@@ -22,6 +22,8 @@ export interface ICellLinkContent {
22
22
  * file: file://a.xlsx
23
23
  */
24
24
  payload: string;
25
+ /** Optional text shown inside the hyperlink popup. Empty string clears it on update. */
26
+ tooltip?: string;
25
27
  /**
26
28
  * only for notify, if you wan't to read the display of text, use cell-value of cell-matrix instead
27
29
  */
package/lib/umd/facade.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/engine-formula"),require("@univerjs/sheets-hyper-link"),require("@univerjs/sheets/facade"),require("@univerjs/core"),require("@univerjs/core/facade")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/engine-formula`,`@univerjs/sheets-hyper-link`,`@univerjs/sheets/facade`,`@univerjs/core`,`@univerjs/core/facade`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsHyperLinkFacade={},e.UniverEngineFormula,e.UniverSheetsHyperLink,e.UniverSheetsFacade,e.UniverCore,e.UniverCoreFacade))})(this,function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var o=class extends r.FWorkbook{getUrlOfDefineName(e){let r=this._injector.get(t.IDefinedNamesService),i=this._injector.get(n.SheetsHyperLinkParserService),a=r.getValueByName(this._workbook.getUnitId(),e);if(!a)throw Error(`Defined name "${e}" does not exist.`);if(a.formulaOrRefString.startsWith(t.operatorToken.EQUALS))throw Error(`Defined name "${e}" is not a reference range, cannot be converted to hyperlink.`);return i.buildHyperLink(a.id)}parseSheetHyperlink(e){return this._injector.get(n.SheetsHyperLinkParserService).parseHyperLink(e)}};r.FWorkbook.extend(o);var s=class extends r.FWorksheet{getUrl(){return this._injector.get(n.SheetsHyperLinkParserService).buildHyperLink(null,this._worksheet.getSheetId())}};r.FWorksheet.extend(s);var c=class extends r.FRange{setHyperLink(e,t){return this._commandService.executeCommand(n.AddHyperLinkCommand.id,{unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),link:{id:(0,i.generateRandomId)(),row:this._range.startRow,column:this._range.startColumn,payload:e,display:t}})}getHyperLinks(){let e=[];return this.forEach((t,n,r)=>{var a;if(!r.p)return;let o=((a=r.p.body)==null||(a=a.customRanges)==null?void 0:a.filter(e=>e.rangeType===i.CustomRangeType.HYPERLINK))??[];if(o.length>0){var s;let a=(s=r.p)==null||(s=s.body)==null?void 0:s.dataStream,{rangeId:c,properties:l,startIndex:u,endIndex:d}=o[0],f=(l==null?void 0:l.url)??``,p=(a==null?void 0:a.slice(u,d+1).replaceAll(i.DataStreamTreeTokenType.CUSTOM_RANGE_START,``).replaceAll(i.DataStreamTreeTokenType.CUSTOM_RANGE_END,``))??``;e.push({id:`${c}`,row:t,column:n,url:f,label:p})}}),e}updateHyperLink(e,t){let r=this.getHyperLinks().find(e=>e.row===this._range.startRow&&e.column===this._range.startColumn);if(!r)return Promise.reject(Error(`No hyperlink found in the top left cell of the range`));let{id:i,row:a,column:o}=r;return this._commandService.executeCommand(n.UpdateHyperLinkCommand.id,{unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),id:i,row:a,column:o,payload:{payload:e,display:t}})}cancelHyperLink(e){if(e){let{id:t,row:r,column:i}=e;return this._commandService.syncExecuteCommand(n.CancelHyperLinkCommand.id,{unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),id:t,row:r,column:i})}else{let e=this.getHyperLinks();return e.length===0||e.every(e=>{let{id:t,row:r,column:i}=e;return this._commandService.syncExecuteCommand(n.CancelHyperLinkCommand.id,{unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),id:t,row:r,column:i})})}}getUrl(){return this._injector.get(n.SheetsHyperLinkParserService).buildHyperLink(this.getRange(),this.getSheetId())}};r.FRange.extend(c);var l=class extends a.FEventName{get BeforeSheetLinkAdd(){return`BeforeSheetLinkAdd`}get BeforeSheetLinkCancel(){return`BeforeSheetLinkCancel`}get BeforeSheetLinkUpdate(){return`BeforeSheetLinkUpdate`}};a.FEventName.extend(l);var u=class extends a.FUniver{_initialize(e){let t=e.get(i.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetLinkAdd,()=>t.beforeCommandExecuted(e=>{if(e.id!==n.AddHyperLinkCommand.id)return;let t=e.params,r=this.getSheetCommandTarget(t);if(!r)return;let{workbook:a,worksheet:o}=r,{link:s}=t,{row:c,column:l}=s,u={workbook:a,worksheet:o,row:c,col:l,link:s};if(this.fireEvent(this.Event.BeforeSheetLinkAdd,u),u.cancel)throw new i.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetLinkUpdate,()=>t.beforeCommandExecuted(e=>{if(e.id!==n.UpdateHyperLinkCommand.id)return;let t=e.params,r=this.getSheetCommandTarget(t);if(!r)return;let{workbook:a,worksheet:o}=r,{row:s,column:c,id:l,payload:u}=t,d={workbook:a,worksheet:o,row:s,column:c,id:l,payload:u};if(this.fireEvent(this.Event.BeforeSheetLinkUpdate,d),d.cancel)throw new i.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetLinkCancel,()=>t.beforeCommandExecuted(e=>{if(e.id!==n.CancelHyperLinkCommand.id)return;let t=e.params,r=this.getSheetCommandTarget(t);if(!r)return;let{workbook:a,worksheet:o}=r,{row:s,column:c,id:l}=t,u={workbook:a,worksheet:o,row:s,column:c,id:l};if(this.fireEvent(this.Event.BeforeSheetLinkCancel,u),u.cancel)throw new i.CanceledError})))}};a.FUniver.extend(u),e.FWorkbookHyperlinkMixin=o});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/engine-formula"),require("@univerjs/sheets-hyper-link"),require("@univerjs/sheets/facade"),require("@univerjs/core"),require("@univerjs/core/facade")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/engine-formula`,`@univerjs/sheets-hyper-link`,`@univerjs/sheets/facade`,`@univerjs/core`,`@univerjs/core/facade`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsHyperLinkFacade={},e.UniverEngineFormula,e.UniverSheetsHyperLink,e.UniverSheetsFacade,e.UniverCore,e.UniverCoreFacade))})(this,function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var o=class extends r.FWorkbook{getUrlOfDefineName(e){let r=this._injector.get(t.IDefinedNamesService),i=this._injector.get(n.SheetsHyperLinkParserService),a=r.getValueByName(this._workbook.getUnitId(),e);if(!a)throw Error(`Defined name "${e}" does not exist.`);if(a.formulaOrRefString.startsWith(t.operatorToken.EQUALS))throw Error(`Defined name "${e}" is not a reference range, cannot be converted to hyperlink.`);return i.buildHyperLink(a.id)}parseSheetHyperlink(e){return this._injector.get(n.SheetsHyperLinkParserService).parseHyperLink(e)}};r.FWorkbook.extend(o);var s=class extends r.FWorksheet{getUrl(){return this._injector.get(n.SheetsHyperLinkParserService).buildHyperLink(null,this._worksheet.getSheetId())}};r.FWorksheet.extend(s);var c=class extends r.FRange{setHyperLink(e,t,r){return this._commandService.executeCommand(n.AddHyperLinkCommand.id,{unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),link:{id:(0,i.generateRandomId)(),row:this._range.startRow,column:this._range.startColumn,payload:e,display:t,tooltip:r}})}getHyperLinks(){let e=[];return this.forEach((t,n,r)=>{var a;if(!r.p)return;let o=((a=r.p.body)==null||(a=a.customRanges)==null?void 0:a.filter(e=>e.rangeType===i.CustomRangeType.HYPERLINK))??[];if(o.length>0){var s;let a=(s=r.p)==null||(s=s.body)==null?void 0:s.dataStream,{rangeId:c,properties:l,startIndex:u,endIndex:d}=o[0],f=(l==null?void 0:l.url)??``,p=(a==null?void 0:a.slice(u,d+1).replaceAll(i.DataStreamTreeTokenType.CUSTOM_RANGE_START,``).replaceAll(i.DataStreamTreeTokenType.CUSTOM_RANGE_END,``))??``;e.push({id:`${c}`,row:t,column:n,url:f,label:p,tooltip:(l==null?void 0:l.tooltip)??(l==null?void 0:l._xlsxHyperlinkTooltip)})}}),e}updateHyperLink(e,t,r){let i=this.getHyperLinks().find(e=>e.row===this._range.startRow&&e.column===this._range.startColumn);if(!i)return Promise.reject(Error(`No hyperlink found in the top left cell of the range`));let{id:a,row:o,column:s}=i;return this._commandService.executeCommand(n.UpdateHyperLinkCommand.id,{unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),id:a,row:o,column:s,payload:{payload:e,display:t??i.label,tooltip:r}})}cancelHyperLink(e){if(e){let{id:t,row:r,column:i}=e;return this._commandService.syncExecuteCommand(n.CancelHyperLinkCommand.id,{unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),id:t,row:r,column:i})}{let e=this.getHyperLinks();return e.length===0||e.every(e=>{let{id:t,row:r,column:i}=e;return this._commandService.syncExecuteCommand(n.CancelHyperLinkCommand.id,{unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),id:t,row:r,column:i})})}}getUrl(){return this._injector.get(n.SheetsHyperLinkParserService).buildHyperLink(this.getRange(),this.getSheetId())}};r.FRange.extend(c);var l=class extends a.FEventName{get BeforeSheetLinkAdd(){return`BeforeSheetLinkAdd`}get BeforeSheetLinkCancel(){return`BeforeSheetLinkCancel`}get BeforeSheetLinkUpdate(){return`BeforeSheetLinkUpdate`}};a.FEventName.extend(l);var u=class extends a.FUniver{_initialize(e){let t=e.get(i.ICommandService);this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetLinkAdd,()=>t.beforeCommandExecuted(e=>{if(e.id!==n.AddHyperLinkCommand.id)return;let t=e.params,r=this.getSheetCommandTarget(t);if(!r)return;let{workbook:a,worksheet:o}=r,{link:s}=t,{row:c,column:l}=s,u={workbook:a,worksheet:o,row:c,col:l,link:s};if(this.fireEvent(this.Event.BeforeSheetLinkAdd,u),u.cancel)throw new i.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetLinkUpdate,()=>t.beforeCommandExecuted(e=>{if(e.id!==n.UpdateHyperLinkCommand.id)return;let t=e.params,r=this.getSheetCommandTarget(t);if(!r)return;let{workbook:a,worksheet:o}=r,{row:s,column:c,id:l,payload:u}=t,d={workbook:a,worksheet:o,row:s,column:c,id:l,payload:u};if(this.fireEvent(this.Event.BeforeSheetLinkUpdate,d),d.cancel)throw new i.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetLinkCancel,()=>t.beforeCommandExecuted(e=>{if(e.id!==n.CancelHyperLinkCommand.id)return;let t=e.params,r=this.getSheetCommandTarget(t);if(!r)return;let{workbook:a,worksheet:o}=r,{row:s,column:c,id:l}=t,u={workbook:a,worksheet:o,row:s,column:c,id:l};if(this.fireEvent(this.Event.BeforeSheetLinkCancel,u),u.cancel)throw new i.CanceledError})))}};a.FUniver.extend(u),e.FWorkbookHyperlinkMixin=o});
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/docs"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-formula")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/docs`,`@univerjs/sheets`,`rxjs`,`@univerjs/engine-formula`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsHyperLink={},e.UniverCore,e.UniverDocs,e.UniverSheets,e.rxjs,e.UniverEngineFormula))})(this,function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function o(e){"@babel/helpers - typeof";return o=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},o(e)}function s(e,t){if(o(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(o(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function c(e){var t=s(e,`string`);return o(t)==`symbol`?t:t+``}function l(e,t,n){return(t=c(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function u(e,t){return function(n,r){t(n,r,e)}}function d(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let f=class extends t.Disposable{constructor(e){super(),this._univerInstanceService=e,l(this,`_linkUpdate$`,new i.Subject),l(this,`linkUpdate$`,this._linkUpdate$.asObservable()),l(this,`_linkMap`,new Map),l(this,`_linkPositionMap`,new Map),this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let r=this._linkMap.get(e);r||(r=new Map,this._linkMap.set(e,r));let i=r.get(n);i||(i=new t.ObjectMatrix,r.set(n,i));let a=this._linkPositionMap.get(e);a||(a=new Map,this._linkPositionMap.set(e,a));let o=a.get(n);return o||(o=new Map,a.set(n,o)),{matrix:i,positionMap:o}}addHyperLink(e,t,n){let{matrix:r,positionMap:i}=this._ensureMap(e,t);return r.setValue(n.row,n.column,n),i.set(n.id,{row:n.row,column:n.column,link:n}),this._linkUpdate$.next({unitId:e,subUnitId:t,payload:n,type:`add`}),!0}updateHyperLink(e,t,n,r,i=!1){let{matrix:a,positionMap:o}=this._ensureMap(e,t),s=o.get(n);if(!s)return!0;let c=a.getValue(s.row,s.column);return c?(Object.assign(c,r),this._linkUpdate$.next({unitId:e,subUnitId:t,payload:{display:c.display,payload:c.payload},id:n,type:`update`,silent:i}),!0):!0}updateHyperLinkRef(e,t,n,r,i=!1){let{matrix:a,positionMap:o}=this._ensureMap(e,t),s=o.get(n);if(!s)return!0;let c=a.getValue(s.row,s.column);return!c||c.id!==n?c=s.link:a.realDeleteValue(s.row,s.column),Object.assign(c,r),o.set(n,{...r,link:c}),a.setValue(r.row,r.column,c),this._linkUpdate$.next({unitId:e,subUnitId:t,payload:r,id:n,type:`updateRef`,silent:i}),!0}removeHyperLink(e,t,n){let{matrix:r,positionMap:i}=this._ensureMap(e,t),a=i.get(n);if(!a)return!1;i.delete(n);let o=r.getValue(a.row,a.column);return o&&o.id===n&&r.realDeleteValue(a.row,a.column),this._linkUpdate$.next({unitId:e,subUnitId:t,payload:a.link,type:`remove`}),!0}getHyperLink(e,t,n){let{matrix:r,positionMap:i}=this._ensureMap(e,t),a=i.get(n);if(a)return r.getValue(a.row,a.column)}getHyperLinkByLocation(e,t,n,r){let{matrix:i}=this._ensureMap(e,t);return i.getValue(n,r)}getHyperLinkByLocationSync(e,n,r,i){var a,o;let{matrix:s}=this._ensureMap(e,n),c=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET),l=c==null||(a=c.getSheetBySheetId(n))==null?void 0:a.getCellRaw(r,i),u=((l==null?void 0:l.v)??(l==null||(o=l.p)==null||(o=o.body)==null?void 0:o.dataStream.slice(0,-2))??``).toString(),d=s.getValue(r,i);if(d)return{...d,display:u}}getSubUnit(e,t){let{matrix:n}=this._ensureMap(e,t),r=[];return n.forValue((e,t,n)=>{n&&r.push(n)}),r}getUnit(e){let t=this._linkMap.get(e);return t?Array.from(t.keys()).map(t=>({unitId:e,subUnitId:t,links:this.getSubUnit(e,t)})):[]}deleteUnit(e){let t=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:`unload`,unitId:e,unitLinks:t})}getAll(){return Array.from(this._linkMap.keys()).map(e=>this.getUnit(e))}};f=d([u(0,t.IUniverInstanceService)],f);let p={type:t.CommandType.MUTATION,id:`sheets.mutation.add-hyper-link`,handler(e,t){if(!t)return!1;let n=e.get(f),{unitId:r,subUnitId:i,link:a}=t;return n.addHyperLink(r,i,a)}},m={type:t.CommandType.MUTATION,id:`sheets.mutation.remove-hyper-link`,handler(e,t){if(!t)return!1;let n=e.get(f),{unitId:r,subUnitId:i,id:a}=t;return n.removeHyperLink(r,i,a)}},h={type:t.CommandType.COMMAND,id:`sheets.command.add-hyper-link`,async handler(e,n){if(!n)return!1;let i=e.get(t.ICommandService),a=e.get(t.IUndoRedoService),o=e.get(t.IUniverInstanceService),s=e.get(f),c=e.get(r.SheetInterceptorService),l=(0,r.getSheetCommandTarget)(o,n);if(!l)return!1;let{unitId:u,subUnitId:d,workbook:h,worksheet:g}=l,{link:_}=n,{payload:v,display:y,row:b,column:x,id:S}=_,C=g.getCell(b,x),w=g.getBlankCellDocumentModel(C,b,x),T=w.documentModel.getSnapshot(),E=t.Tools.deepClone(T.body);if(!E)return!1;let D;if(D=y?t.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:E.dataStream.length-2,collapsed:E.dataStream.length-2==0},body:{dataStream:`${y}`,customRanges:[{startIndex:0,endIndex:y.length-1,rangeType:t.CustomRangeType.HYPERLINK,rangeId:S,properties:{url:v}}]},doc:w.documentModel}):t.BuildTextUtils.customRange.add({body:E,ranges:[{startOffset:0,endOffset:E.dataStream.length-2,collapsed:!1}],rangeId:S,rangeType:t.CustomRangeType.HYPERLINK,properties:{url:v,refId:S}}),!D)return!1;let O=t.TextX.apply(E,D.serialize()),k={p:{...T,body:O},t:t.CellValueType.STRING},A=c.onWriteCell(h,g,b,x,k),j={unitId:u,subUnitId:d,cellValue:{[_.row]:{[_.column]:A}}},M={id:r.SetRangeValuesMutation.id,params:j},N=(0,r.SetRangeValuesUndoMutationFactory)(e,j),P={id:r.SetRangeValuesMutation.id,params:N},F=[M],I=[P],L=s.getHyperLinkByLocation(u,d,b,x);return L&&(F.push({id:m.id,params:{unitId:u,subUnitId:d,id:L.id}}),I.push({id:p.id,params:{unitId:u,subUnitId:d,link:L}})),await(0,t.sequenceExecute)(F,i)?await c.onValidateCell(h,g,b,x)===!1?((0,t.sequenceExecute)(I,i),!1):(a.pushUndoRedo({redoMutations:F,undoMutations:I,unitID:u}),!0):!1}},g={id:`sheets.command.add-rich-hyper-link`,type:t.CommandType.COMMAND,handler:async(e,r)=>{if(!r)return!1;let{documentId:i,link:a}=r,o=e.get(t.ICommandService),s=(0,t.generateRandomId)(),{payload:c}=a,l=(0,n.addCustomRangeBySelectionFactory)(e,{unitId:i,rangeId:s,rangeType:t.CustomRangeType.HYPERLINK,properties:{url:c,refId:s}});return l?o.syncExecuteCommand(l.id,l.params):!1}},_={type:t.CommandType.COMMAND,id:`sheets.command.cancel-hyper-link`,handler(e,n){var i;if(!n)return!1;let a=e.get(t.ICommandService),o=e.get(t.IUndoRedoService),s=e.get(t.IUniverInstanceService),c=e.get(f),l=(0,r.getSheetCommandTarget)(s,n);if(!l)return!1;let{row:u,column:d,id:h}=n,{unitId:g,subUnitId:_,worksheet:v}=l,y=v.getCell(u,d);if(!y)return!1;let b=v.getCellDocumentModelWithFormula(y,u,d);if(!(b!=null&&b.documentModel))return!1;let x=t.Tools.deepClone(b.documentModel.getSnapshot()),S=(i=x.body)==null||(i=i.customRanges)==null?void 0:i.find(e=>`${e.rangeId}`===h);if(!S)return!1;let C=t.BuildTextUtils.customRange.delete({documentDataModel:b.documentModel,rangeId:S.rangeId});if(!C)return!1;let w=t.TextX.apply(x.body,C.serialize()),T=[],E=[],D={unitId:g,subUnitId:_,cellValue:{[u]:{[d]:{p:{...x,body:w},t:t.CellValueType.STRING}}}};T.push({id:r.SetRangeValuesMutation.id,params:D});let O=(0,r.SetRangeValuesUndoMutationFactory)(e,D);E.push({id:r.SetRangeValuesMutation.id,params:O});let k=c.getHyperLinkByLocation(g,_,u,d);return k&&(T.push({id:m.id,params:{unitId:g,subUnitId:_,id:k.id}}),E.push({id:p.id,params:{unitId:g,subUnitId:_,link:{...k}}})),(0,t.sequenceExecute)(T,a).result?(o.pushUndoRedo({redoMutations:T,undoMutations:E,unitID:g}),!0):!1}},v={type:t.CommandType.COMMAND,id:`sheets.command.cancel-rich-hyper-link`,handler(e,r){var i;if(!r)return!1;let{id:a,documentId:o}=r,s=e.get(t.ICommandService),c=e.get(t.IUniverInstanceService).getUnit(o,t.UniverInstanceType.UNIVER_DOC),l=c==null||(i=c.getBody())==null||(i=i.customRanges)==null?void 0:i.find(e=>e.rangeId===a),u=null;l&&l.endIndex===c.getBody().dataStream.length-3&&(u={dataStream:` `});let d=(0,n.deleteCustomRangeFactory)(e,{unitId:o,rangeId:a,insert:u});return d?s.syncExecuteCommand(d.id,d.params):!1}},y={type:t.CommandType.COMMAND,id:`sheets.command.update-hyper-link`,async handler(e,i){var a,o;if(!i)return!1;let s=e.get(t.ICommandService),c=e.get(t.IUndoRedoService),l=e.get(t.IUniverInstanceService),u=e.get(f),d=e.get(r.SheetInterceptorService),h=(0,r.getSheetCommandTarget)(l,{unitId:i.unitId,subUnitId:i.subUnitId});if(!h)return!1;let{payload:g,row:_,column:v,id:y}=i,{workbook:b,worksheet:x,unitId:S,subUnitId:C}=h,{payload:w,display:T=``}=g,E=x.getCell(_,v);if(!E)return!1;let D=x.getCellDocumentModelWithFormula(E,_,v);if(!(D!=null&&D.documentModel))return!1;let O=D.documentModel.getSnapshot(),k=(a=O.body)==null||(a=a.customRanges)==null?void 0:a.find(e=>`${e.rangeId}`===y);if(!k)return!1;let A=(0,t.generateRandomId)(),j=(o=(0,t.getBodySlice)(D.documentModel.getBody(),k.startIndex,k.endIndex+1).textRuns)==null?void 0:o[0];j&&(j.ed=T.length+1);let M=(0,n.replaceSelectionFactory)(e,{unitId:S,body:{dataStream:`${T}`,customRanges:[{rangeId:A,rangeType:t.CustomRangeType.HYPERLINK,startIndex:0,endIndex:T.length-1,properties:{url:w}}],textRuns:j?[j]:void 0},selection:{startOffset:k.startIndex,endOffset:k.endIndex+1,collapsed:!1},doc:D.documentModel});if(!M)return!1;let N=t.TextX.apply(t.Tools.deepClone(O.body),M.textX.serialize()),P={p:{...O,body:N},t:t.CellValueType.STRING},F=d.onWriteCell(b,x,_,v,P),I={id:r.SetRangeValuesMutation.id,params:{unitId:S,subUnitId:C,cellValue:{[_]:{[v]:F}}}},L=(0,r.SetRangeValuesUndoMutationFactory)(e,I.params),R={id:r.SetRangeValuesMutation.id,params:L},z=[I],B=[R],V=u.getHyperLinkByLocation(S,C,_,v);return V&&(z.push({id:m.id,params:{unitId:S,subUnitId:C,id:V.id}}),B.push({id:p.id,params:{unitId:S,subUnitId:C,link:V}})),(0,t.sequenceExecute)(z,s).result?await d.onValidateCell(b,x,_,v)===!1?((0,t.sequenceExecute)(B,s),!1):(c.pushUndoRedo({redoMutations:z,undoMutations:B,unitID:S}),!0):!1}},b={type:t.CommandType.COMMAND,id:`sheets.command.update-rich-hyper-link`,handler:(e,r)=>{var i,a;if(!r)return!1;let{documentId:o,payload:s,id:c}=r,l=e.get(t.IUniverInstanceService),u=e.get(t.ICommandService),d=l.getUnit(o,t.UniverInstanceType.UNIVER_DOC);if(!d)return!1;let f=(i=d.getBody())==null||(i=i.customRanges)==null?void 0:i.find(e=>e.rangeId===c);if(!f)return!1;let p=r.payload.display??``,m=(0,t.generateRandomId)(),h=(a=(0,t.getBodySlice)(d.getBody(),f.startIndex,f.endIndex+1).textRuns)==null?void 0:a[0];h&&(h.ed=p.length+1);let g=(0,n.replaceSelectionFactory)(e,{unitId:o,body:{dataStream:`${p}`,customRanges:[{rangeId:m,rangeType:t.CustomRangeType.HYPERLINK,startIndex:0,endIndex:p.length-1,properties:{url:s.payload}}],textRuns:h?[h]:void 0},selection:{startOffset:f.startIndex,endOffset:f.endIndex+1,collapsed:!1},doc:d});return g?u.syncExecuteCommand(g.id,g.params):!1}},x={type:t.CommandType.MUTATION,id:`sheets.mutation.update-hyper-link`,handler(e,t){if(!t)return!1;let n=e.get(f),{unitId:r,subUnitId:i,payload:a,id:o}=t;return n.updateHyperLink(r,i,o,a,!1)}},S={type:t.CommandType.MUTATION,id:`sheets.mutation.update-hyper-link-ref`,handler(e,t){if(!t)return!1;let n=e.get(f),{unitId:r,subUnitId:i,id:a,row:o,column:s,silent:c}=t;return n.updateHyperLinkRef(r,i,a,{row:o,column:s},c)}},C={type:t.CommandType.MUTATION,id:`sheets.mutation.update-rich-hyper-link`,handler(e,n){var i;if(!n)return!1;let{unitId:a,subUnitId:o,row:s,col:c,id:l,url:u}=n,d=(0,r.getSheetCommandTarget)(e.get(t.IUniverInstanceService),{unitId:a,subUnitId:o});if(!d)return!1;let{worksheet:f}=d,p=f.getCellRaw(s,c),m=p==null||(i=p.p)==null||(i=i.body)==null||(i=i.customRanges)==null?void 0:i.find(e=>e.rangeType===t.CustomRangeType.HYPERLINK&&e.rangeId===l);return m&&(m.properties.url=u),!0}};var w=`@univerjs/sheets-hyper-link`,T=`1.0.0-insiders.20260813-7c9aa50`;let E={},D=class extends t.Disposable{constructor(e,t,n,r){super(),this._refRangeService=e,this._hyperLinkModel=t,this._selectionManagerService=n,this._commandService=r,l(this,`_disposableMap`,new Map),l(this,`_watchDisposableMap`,new Map),l(this,`_rangeDisableMap`,new Map),l(this,`_rangeWatcherMap`,new Map),l(this,`_handlePositionChange`,(e,t,n,r,i)=>{let a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return r?{redos:[{id:S.id,params:{unitId:e,subUnitId:t,id:n.id,row:r.startRow,column:r.startColumn,silent:i}}],undos:[{id:S.id,params:{unitId:e,subUnitId:t,id:n.id,row:a.startRow,column:a.startColumn,silent:i}}]}:{redos:[{id:m.id,params:{unitId:e,subUnitId:t,id:n.id}}],undos:[{id:p.id,params:{unitId:e,subUnitId:t,link:n}}]}}),this._initData(),this._initRefRange()}_registerPosition(e,t,n){let i=n.id,a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._disposableMap.set(i,this._refRangeService.registerRefRange(a,i=>{let o=(0,r.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests)(a,i,{selectionManagerService:this._selectionManagerService}),s=Array.isArray(o)?o[0]:o;return s&&s.startColumn===a.startColumn&&s.startRow===a.startRow?{undos:[],redos:[]}:this._handlePositionChange(e,t,n,s,!1)},e,t))}_watchPosition(e,n,r){let i=r.id,a={startColumn:r.column,endColumn:r.column,startRow:r.row,endRow:r.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(e,n,a,(i,a)=>{let{redos:o}=this._handlePositionChange(e,n,r,a,!0);(0,t.sequenceExecuteAsync)(o,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(e){let t=this._disposableMap.get(e);t==null||t.dispose(),this._disposableMap.delete(e)}_unwatchPosition(e){let t=this._watchDisposableMap.get(e);t==null||t.dispose(),this._watchDisposableMap.delete(e)}_registerRange(e,n,i,o=!1){if(i.startsWith(`#`)){let s=new URLSearchParams(i.slice(1)),c={gid:s.get(`gid`)??``,range:s.get(`range`)??``,rangeid:s.get(`rangeid`)??``};if(c.range&&c.gid){let s=c.gid,l=(0,a.deserializeRangeWithSheet)(c.range).range;(0,t.isValidRange)(l)&&c.range!==`err`&&(this._rangeDisableMap.set(n,this._refRangeService.registerRefRange(l,t=>{let o=(0,r.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests)(l,t,{selectionManagerService:this._selectionManagerService});return o&&(0,a.serializeRange)(o)===(0,a.serializeRange)(l)?{redos:[],undos:[]}:{redos:[{id:x.id,params:{unitId:e,subUnitId:s,id:n,payload:{payload:`#gid=${s}&range=${o?(0,a.serializeRange)(o):`err`}`}}}],undos:[{id:x.id,params:{unitId:e,subUnitId:s,id:n,payload:{payload:i}}}]}},e,s)),o||this._rangeWatcherMap.set(n,this._refRangeService.watchRange(e,s,l,(t,r)=>{this._hyperLinkModel.updateHyperLink(e,s,n,{payload:`#gid=${s}&range=${r?(0,a.serializeRange)(r):`err`}`},!0)},!0)))}}}_unregisterRange(e){let t=this._rangeDisableMap.get(e);t==null||t.dispose(),this._rangeDisableMap.delete(e)}_unwatchRange(e){let t=this._rangeWatcherMap.get(e);t==null||t.dispose(),this._rangeWatcherMap.delete(e)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,links:r}=e;r.forEach(e=>{this._registerPosition(t,n,e),this._watchPosition(t,n,e),this._registerRange(t,e.id,e.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(e=>{switch(e.type){case`add`:this._registerPosition(e.unitId,e.subUnitId,e.payload),this._watchPosition(e.unitId,e.subUnitId,e.payload),this._registerRange(e.unitId,e.payload.id,e.payload.payload);break;case`remove`:this._unregisterPosition(e.payload.id),this._unwatchPosition(e.payload.id),this._unregisterRange(e.payload.id),this._unwatchRange(e.payload.id);break;case`updateRef`:{let{unitId:t,subUnitId:n,id:r,silent:i}=e,a=this._hyperLinkModel.getHyperLink(t,n,r);if(!a)return;this._unregisterPosition(r),this._registerPosition(t,n,a),i||(this._unwatchPosition(r),this._watchPosition(t,n,a));break}case`unload`:{let{unitLinks:t}=e;t.forEach(e=>{let{links:t}=e;t.forEach(e=>{this._unregisterPosition(e.id),this._unwatchPosition(e.id),this._unregisterRange(e.id),this._unwatchRange(e.id)})});break}case`update`:e.silent||this._unwatchRange(e.id),this._unregisterRange(e.id),this._registerRange(e.unitId,e.id,e.payload.payload,e.silent);break}})),this.disposeWithMe((0,t.toDisposable)(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};D=d([u(0,(0,t.Inject)(r.RefRangeService)),u(1,(0,t.Inject)(f)),u(2,(0,t.Inject)(r.SheetsSelectionsService)),u(3,t.ICommandService)],D);let O=class extends t.Disposable{constructor(e,t,n){super(),this._sheetInterceptorService=e,this._univerInstanceService=t,this._hyperLinkModel=n,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===r.RemoveSheetCommand.id){var n;let r=e.params,i=r.unitId?this._univerInstanceService.getUnit(r.unitId):this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!i)return{redos:[],undos:[]};let a=i.getUnitId(),o=r.subUnitId||((n=i.getActiveSheet())==null?void 0:n.getSheetId());if(!o)return{redos:[],undos:[]};let s=this._hyperLinkModel.getSubUnit(a,o);return{redos:s.map(e=>({id:m.id,params:{unitId:a,subUnitId:o,id:e.id}})),undos:s.map(e=>({id:p.id,params:{unitId:a,subUnitId:o,link:e}}))}}return{redos:[],undos:[]}}}))}};O=d([u(0,(0,t.Inject)(r.SheetInterceptorService)),u(1,t.IUniverInstanceService),u(2,(0,t.Inject)(f))],O);let k=class extends t.Disposable{constructor(e,t,n){super(),this._commandService=e,this._univerInstanceService=t,this._refRangeService=n,l(this,`_refRangeMap`,new Map),this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(e,n){let r=this._refRangeMap.get(e);r||(r=new Map,this._refRangeMap.set(e,r));let i=r.get(n);return i||(i=new t.ObjectMatrix,r.set(n,i)),i}_isLegalRangeUrl(e,n){let r=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!r)return null;if(n&&n.startsWith(`#`)){let e=new URLSearchParams(n.slice(1)),i={gid:e.get(`gid`)??``,range:e.get(`range`)??``,rangeid:e.get(`rangeid`)??``};if(i.range&&i.gid){let e=i.gid,n=r.getSheetBySheetId(e);if(!n)return null;let o=(0,a.deserializeRangeWithSheet)(i.range).range;if((0,t.isValidRange)(o,n)&&i.range!==`err`)return{range:o,worksheet:n}}}return null}_registerRange(e,n,i,o,s){var c;let l=this._enusreMap(e,n);if((c=s.body)!=null&&(c=c.customRanges)!=null&&c.some(n=>{var r;return n.rangeType===t.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(e,(r=n.properties)==null?void 0:r.url)})){var u;let c=new t.DisposableCollection,d=!1;(u=s.body)==null||(u=u.customRanges)==null||u.forEach(s=>{if(s.rangeType===t.CustomRangeType.HYPERLINK){var l;let u=(l=s.properties)==null?void 0:l.url,f=this._isLegalRangeUrl(e,u);if(f){let{range:l,worksheet:p}=f;d=!0,c.add(this._refRangeService.registerRefRange(l,c=>{let d=(0,r.handleDefaultRangeChangeWithEffectRefCommands)(l,c);return d&&t.Rectangle.equals(d,l)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:C.id,params:{unitId:e,subUnitId:n,row:i,col:o,id:s.rangeId,url:`#gid=${n}&range=${d?(0,a.serializeRange)(d):`err`}`}}],undos:[{id:C.id,params:{unitId:e,subUnitId:n,row:i,col:o,id:s.rangeId,url:u}}],redos:[]}},p.getUnitId(),p.getSheetId()))}}}),d&&l.setValue(i,o,c)}}_initWorkbookLoad(){let e=e=>{let t=e.getUnitId();e.getSheets().forEach(e=>{let n=e.getSheetId(),r=this._enusreMap(t,n);e.getCellMatrix().forValue((e,i,a)=>{let o=r.getValue(e,i);o&&o.dispose(),a&&a.p&&this._registerRange(t,n,e,i,a.p)})})};this._univerInstanceService.getAllUnitsForType(t.UniverInstanceType.UNIVER_SHEET).forEach(t=>{e(t)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(n=>{let{unit:r}=n;r.type===t.UniverInstanceType.UNIVER_SHEET&&e(r)}))}_initWorkbookUnload(){this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(e=>{if(e.type===t.UniverInstanceType.UNIVER_SHEET){let t=e,n=t.getUnitId();t.getSheets().forEach(e=>{let t=e.getSheetId();this._enusreMap(n,t).forValue((e,t,n)=>{n&&n.dispose()})}),this._refRangeMap.delete(n)}}))}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===r.SetRangeValuesMutation.id){let{unitId:n,subUnitId:r,cellValue:i}=e.params,a=this._enusreMap(n,r);i&&new t.ObjectMatrix(i).forValue((e,t,i)=>{let o=a.getValue(e,t);o&&o.dispose(),i&&i.p&&this._registerRange(n,r,e,t,i.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===C.id){let{unitId:t,subUnitId:n,row:i,col:a}=e.params,o=(0,r.getSheetCommandTarget)(this._univerInstanceService,{unitId:t,subUnitId:n}),s=this._enusreMap(t,n).getValue(i,a);if(s&&s.dispose(),o){let{worksheet:e}=o,r=e.getCellRaw(i,a);r&&r.p&&this._registerRange(t,n,i,a,r.p)}}}))}};k=d([u(0,t.ICommandService),u(1,t.IUniverInstanceService),u(2,(0,t.Inject)(r.RefRangeService))],k);let A=class extends t.Disposable{constructor(e,t,n,r){super(),this._sheetInterceptorService=e,this._hyperLinkModel=t,this._selectionManagerService=n,this._univerInstanceService=r,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===r.SetRangeValuesCommand.id){let n=e.params,{unitId:r,subUnitId:i}=n,a=[],o=[];return n.cellValue&&new t.ObjectMatrix(n.cellValue).forValue((e,t)=>{let n=this._hyperLinkModel.getHyperLinkByLocation(r,i,e,t);n&&(a.push({id:m.id,params:{unitId:r,subUnitId:i,id:n.id}}),o.push({id:p.id,params:{unitId:r,subUnitId:i,link:n}}))}),{undos:o,redos:a}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===r.ClearSelectionContentCommand.id||e.id===r.ClearSelectionAllCommand.id||e.id===r.ClearSelectionFormatCommand.id){let n=[],i=[],a=this._selectionManagerService.getCurrentLastSelection(),o=(0,r.getSheetCommandTarget)(this._univerInstanceService,e.params);if(a&&o){let{unitId:e,subUnitId:r}=o;t.Range.foreach(a.range,(t,a)=>{let o=this._hyperLinkModel.getHyperLinkByLocation(e,r,t,a);o&&(n.push({id:m.id,params:{unitId:e,subUnitId:r,id:o.id}}),i.push({id:p.id,params:{unitId:e,subUnitId:r,link:o}}))})}return{redos:n,undos:i}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(r.AFTER_CELL_EDIT,{handler:(e,n,r)=>{if(!e||e.p)return r(e);if(typeof e.v==`string`&&t.Tools.isLegalUrl(e.v)&&e.v[e.v.length-1]!==` `){let{unitId:i,subUnitId:a,row:o,col:s}=n,c=t.Tools.normalizeUrl(e.v),l=this._univerInstanceService.getUnit(i,t.UniverInstanceType.UNIVER_SHEET),u=l==null?void 0:l.getSheetBySheetId(a);if(!u)return r(e);let d=u.getBlankCellDocumentModel(e,o,s);if(!d.documentModel)return r(e);let f=t.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:e.v.length,collapsed:!1},body:{dataStream:`${e.v}`,customRanges:[{startIndex:0,endIndex:e.v.length-1,rangeId:(0,t.generateRandomId)(),rangeType:t.CustomRangeType.HYPERLINK,properties:{url:c}}]},doc:d.documentModel});if(!f)return r(e);let p=d.documentModel.getBody();return t.TextX.apply(p,f.serialize()),r({...e,p:{id:t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:p,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return r(e)}}))}};A=d([u(0,(0,t.Inject)(r.SheetInterceptorService)),u(1,(0,t.Inject)(f)),u(2,(0,t.Inject)(r.SheetsSelectionsService)),u(3,t.IUniverInstanceService)],A);let j=class extends t.Disposable{constructor(e){super(),this._commandService=e,this._registerCommands()}_registerCommands(){[h,y,_,b,v,g,p,x,m,S,C].forEach(e=>{this._commandService.registerCommand(e)})}};j=d([u(0,t.ICommandService)],j);let M=function(e){return e.SHEET=`gid`,e.RANGE=`range`,e.DEFINE_NAME=`rangeid`,e.INVALID=`invalid`,e.URL=`url`,e}({}),N=class{constructor(e,t,n){this._univerInstanceService=e,this._localeService=t,this._definedNamesService=n}buildHyperLink(e,t){if(typeof e==`string`)return`#rangeid=${e}`;let n=`#gid=${t}`;return e&&(n+=`&range=${(0,a.serializeRange)(e)}`),n}parseHyperLink(e){if(e.startsWith(`#`)){let t=new URLSearchParams(e.slice(1)),n={gid:t.get(`gid`)??``,range:t.get(`range`)??``,rangeid:t.get(`rangeid`)??``,unitid:t.get(`unitid`)??``},r=this._getURLName(n);return{type:r.type,name:r.name,url:e,searchObj:n}}else return{type:`url`,name:e,url:e,searchObj:null}}_getURLName(e){let{gid:n,range:r,rangeid:i,unitid:o}=e,s=o?this._univerInstanceService.getUnit(o,t.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET),c={type:`invalid`,name:this._localeService.t(`sheets-hyper-link.message.refError`)};if(!s)return c;let l=n?s.getSheetBySheetId(n):s.getActiveSheet(),u=(l==null?void 0:l.getName())??``;if(r){if(!l)return c;let e=(0,a.deserializeRangeWithSheet)(r).range;return(0,t.isValidRange)(e,l)&&r!==`err`?{type:`range`,name:(0,a.serializeRangeWithSheet)(u,e)}:c}if(i){let e=this._definedNamesService.getValueById(s.getUnitId(),i);return e?{type:`rangeid`,name:e.formulaOrRefString}:c}if(n){let e=s.getSheetBySheetId(n);return e?{type:`gid`,name:e.getName()}:c}return c}};N=d([u(0,t.IUniverInstanceService),u(1,(0,t.Inject)(t.LocaleService)),u(2,a.IDefinedNamesService)],N);let P=class extends t.Plugin{constructor(e=E,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},E,this._config);this._configService.setConfig(`sheets-hyper-link.config`,i)}onStarting(){(0,t.registerDependencies)(this._injector,[[f],[N],[j],[D],[A],[O],[k]]),(0,t.touchDependencies)(this._injector,[[D],[j],[A],[O],[k]])}};l(P,`pluginName`,`SHEET_HYPER_LINK_PLUGIN`),l(P,`packageName`,w),l(P,`version`,T),l(P,`type`,t.UniverInstanceType.UNIVER_SHEET),P=d([(0,t.DependentOn)(a.UniverFormulaEnginePlugin,r.UniverSheetsPlugin),u(1,(0,t.Inject)(t.Injector)),u(2,t.IConfigService)],P),e.AddHyperLinkCommand=h,e.AddHyperLinkMutation=p,e.AddRichHyperLinkCommand=g,e.CancelHyperLinkCommand=_,e.CancelRichHyperLinkCommand=v,e.ERROR_RANGE=`err`,Object.defineProperty(e,"HyperLinkModel",{enumerable:!0,get:function(){return f}}),e.RemoveHyperLinkMutation=m,e.SheetHyperLinkType=M,Object.defineProperty(e,"SheetsHyperLinkParserService",{enumerable:!0,get:function(){return N}}),Object.defineProperty(e,"UniverSheetsHyperLinkPlugin",{enumerable:!0,get:function(){return P}}),e.UpdateHyperLinkCommand=y,e.UpdateHyperLinkMutation=x,e.UpdateHyperLinkRefMutation=S,e.UpdateRichHyperLinkCommand=b});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/docs"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-formula")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/docs`,`@univerjs/sheets`,`rxjs`,`@univerjs/engine-formula`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsHyperLink={},e.UniverCore,e.UniverDocs,e.UniverSheets,e.rxjs,e.UniverEngineFormula))})(this,function(e,t,n,r,i,a){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function o(e){"@babel/helpers - typeof";return o=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},o(e)}function s(e,t){if(o(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(o(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function c(e){var t=s(e,`string`);return o(t)==`symbol`?t:t+``}function l(e,t,n){return(t=c(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function u(e,t){return function(n,r){t(n,r,e)}}function d(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let f=class extends t.Disposable{constructor(e){super(),this._univerInstanceService=e,l(this,`_linkUpdate$`,new i.Subject),l(this,`linkUpdate$`,this._linkUpdate$.asObservable()),l(this,`_linkMap`,new Map),l(this,`_linkPositionMap`,new Map),this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let r=this._linkMap.get(e);r||(r=new Map,this._linkMap.set(e,r));let i=r.get(n);i||(i=new t.ObjectMatrix,r.set(n,i));let a=this._linkPositionMap.get(e);a||(a=new Map,this._linkPositionMap.set(e,a));let o=a.get(n);return o||(o=new Map,a.set(n,o)),{matrix:i,positionMap:o}}addHyperLink(e,t,n){let{matrix:r,positionMap:i}=this._ensureMap(e,t);return r.setValue(n.row,n.column,n),i.set(n.id,{row:n.row,column:n.column,link:n}),this._linkUpdate$.next({unitId:e,subUnitId:t,payload:n,type:`add`}),!0}updateHyperLink(e,t,n,r,i=!1){let{matrix:a,positionMap:o}=this._ensureMap(e,t),s=o.get(n);if(!s)return!0;let c=a.getValue(s.row,s.column);return!c||(Object.assign(c,r),this._linkUpdate$.next({unitId:e,subUnitId:t,payload:{display:c.display,payload:c.payload},id:n,type:`update`,silent:i}),!0)}updateHyperLinkRef(e,t,n,r,i=!1){let{matrix:a,positionMap:o}=this._ensureMap(e,t),s=o.get(n);if(!s)return!0;let c=a.getValue(s.row,s.column);return!c||c.id!==n?c=s.link:a.realDeleteValue(s.row,s.column),Object.assign(c,r),o.set(n,{...r,link:c}),a.setValue(r.row,r.column,c),this._linkUpdate$.next({unitId:e,subUnitId:t,payload:r,id:n,type:`updateRef`,silent:i}),!0}removeHyperLink(e,t,n){let{matrix:r,positionMap:i}=this._ensureMap(e,t),a=i.get(n);if(!a)return!1;i.delete(n);let o=r.getValue(a.row,a.column);return o&&o.id===n&&r.realDeleteValue(a.row,a.column),this._linkUpdate$.next({unitId:e,subUnitId:t,payload:a.link,type:`remove`}),!0}getHyperLink(e,t,n){let{matrix:r,positionMap:i}=this._ensureMap(e,t),a=i.get(n);if(a)return r.getValue(a.row,a.column)}getHyperLinkByLocation(e,t,n,r){let{matrix:i}=this._ensureMap(e,t);return i.getValue(n,r)}getHyperLinkByLocationSync(e,n,r,i){var a,o;let{matrix:s}=this._ensureMap(e,n),c=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET),l=c==null||(a=c.getSheetBySheetId(n))==null?void 0:a.getCellRaw(r,i),u=((l==null?void 0:l.v)??(l==null||(o=l.p)==null||(o=o.body)==null?void 0:o.dataStream.slice(0,-2))??``).toString(),d=s.getValue(r,i);if(d)return{...d,display:u}}getSubUnit(e,t){let{matrix:n}=this._ensureMap(e,t),r=[];return n.forValue((e,t,n)=>{n&&r.push(n)}),r}getUnit(e){let t=this._linkMap.get(e);return t?Array.from(t.keys()).map(t=>({unitId:e,subUnitId:t,links:this.getSubUnit(e,t)})):[]}deleteUnit(e){let t=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:`unload`,unitId:e,unitLinks:t})}getAll(){return Array.from(this._linkMap.keys()).map(e=>this.getUnit(e))}};f=d([u(0,t.IUniverInstanceService)],f);let p={type:t.CommandType.MUTATION,id:`sheets.mutation.add-hyper-link`,handler(e,t){if(!t)return!1;let n=e.get(f),{unitId:r,subUnitId:i,link:a}=t;return n.addHyperLink(r,i,a)}},m={type:t.CommandType.MUTATION,id:`sheets.mutation.remove-hyper-link`,handler(e,t){if(!t)return!1;let n=e.get(f),{unitId:r,subUnitId:i,id:a}=t;return n.removeHyperLink(r,i,a)}},h={type:t.CommandType.COMMAND,id:`sheets.command.add-hyper-link`,async handler(e,n){if(!n)return!1;let i=e.get(t.ICommandService),a=e.get(t.IUndoRedoService),o=e.get(t.IUniverInstanceService),s=e.get(f),c=e.get(r.SheetInterceptorService),l=(0,r.getSheetCommandTarget)(o,n);if(!l)return!1;let{unitId:u,subUnitId:d,workbook:h,worksheet:g}=l,{link:_}=n,{payload:v,display:y,row:b,column:x,id:S}=_,C=g.getCell(b,x),w=g.getBlankCellDocumentModel(C,b,x),T=w.documentModel.getSnapshot(),E=t.Tools.deepClone(T.body);if(!E)return!1;let D;if(D=y?t.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:E.dataStream.length-2,collapsed:E.dataStream.length-2==0},body:{dataStream:`${y}`,customRanges:[{startIndex:0,endIndex:y.length-1,rangeType:t.CustomRangeType.HYPERLINK,rangeId:S,properties:{url:v,tooltip:_.tooltip}}]},doc:w.documentModel}):t.BuildTextUtils.customRange.add({body:E,ranges:[{startOffset:0,endOffset:E.dataStream.length-2,collapsed:!1}],rangeId:S,rangeType:t.CustomRangeType.HYPERLINK,properties:{url:v,tooltip:_.tooltip,refId:S}}),!D)return!1;let O=t.TextX.apply(E,D.serialize()),k={p:{...T,body:O},t:t.CellValueType.STRING},A=c.onWriteCell(h,g,b,x,k),j={unitId:u,subUnitId:d,cellValue:{[_.row]:{[_.column]:A}}},M={id:r.SetRangeValuesMutation.id,params:j},N=(0,r.SetRangeValuesUndoMutationFactory)(e,j),P={id:r.SetRangeValuesMutation.id,params:N},F=[M],I=[P],L=s.getHyperLinkByLocation(u,d,b,x);return L&&(F.push({id:m.id,params:{unitId:u,subUnitId:d,id:L.id}}),I.push({id:p.id,params:{unitId:u,subUnitId:d,link:L}})),await(0,t.sequenceExecute)(F,i)?await c.onValidateCell(h,g,b,x)===!1?((0,t.sequenceExecute)(I,i),!1):(a.pushUndoRedo({redoMutations:F,undoMutations:I,unitID:u}),!0):!1}},g={id:`sheets.command.add-rich-hyper-link`,type:t.CommandType.COMMAND,handler:async(e,r)=>{if(!r)return!1;let{documentId:i,link:a}=r,o=e.get(t.ICommandService),s=(0,t.generateRandomId)(),{payload:c}=a,l=(0,n.addCustomRangeBySelectionFactory)(e,{unitId:i,rangeId:s,rangeType:t.CustomRangeType.HYPERLINK,properties:{url:c,tooltip:a.tooltip,refId:s}});return l?o.syncExecuteCommand(l.id,l.params):!1}},_={type:t.CommandType.COMMAND,id:`sheets.command.cancel-hyper-link`,handler(e,n){var i;if(!n)return!1;let a=e.get(t.ICommandService),o=e.get(t.IUndoRedoService),s=e.get(t.IUniverInstanceService),c=e.get(f),l=(0,r.getSheetCommandTarget)(s,n);if(!l)return!1;let{row:u,column:d,id:h}=n,{unitId:g,subUnitId:_,worksheet:v}=l,y=v.getCell(u,d);if(!y)return!1;let b=v.getCellDocumentModelWithFormula(y,u,d);if(!(b!=null&&b.documentModel))return!1;let x=t.Tools.deepClone(b.documentModel.getSnapshot()),S=(i=x.body)==null||(i=i.customRanges)==null?void 0:i.find(e=>`${e.rangeId}`===h);if(!S)return!1;let C=t.BuildTextUtils.customRange.delete({documentDataModel:b.documentModel,rangeId:S.rangeId});if(!C)return!1;let w=t.TextX.apply(x.body,C.serialize()),T=[],E=[],D={unitId:g,subUnitId:_,cellValue:{[u]:{[d]:{p:{...x,body:w},t:t.CellValueType.STRING}}}};T.push({id:r.SetRangeValuesMutation.id,params:D});let O=(0,r.SetRangeValuesUndoMutationFactory)(e,D);E.push({id:r.SetRangeValuesMutation.id,params:O});let k=c.getHyperLinkByLocation(g,_,u,d);return k&&(T.push({id:m.id,params:{unitId:g,subUnitId:_,id:k.id}}),E.push({id:p.id,params:{unitId:g,subUnitId:_,link:{...k}}})),(0,t.sequenceExecute)(T,a).result?(o.pushUndoRedo({redoMutations:T,undoMutations:E,unitID:g}),!0):!1}},v={type:t.CommandType.COMMAND,id:`sheets.command.cancel-rich-hyper-link`,handler(e,r){var i;if(!r)return!1;let{id:a,documentId:o}=r,s=e.get(t.ICommandService),c=e.get(t.IUniverInstanceService).getUnit(o,t.UniverInstanceType.UNIVER_DOC),l=c==null||(i=c.getBody())==null||(i=i.customRanges)==null?void 0:i.find(e=>e.rangeId===a),u=null;l&&l.endIndex===c.getBody().dataStream.length-3&&(u={dataStream:` `});let d=(0,n.deleteCustomRangeFactory)(e,{unitId:o,rangeId:a,insert:u});return d?s.syncExecuteCommand(d.id,d.params):!1}},y={type:t.CommandType.COMMAND,id:`sheets.command.update-hyper-link`,async handler(e,i){var a,o,s,c;if(!i)return!1;let l=e.get(t.ICommandService),u=e.get(t.IUndoRedoService),d=e.get(t.IUniverInstanceService),h=e.get(f),g=e.get(r.SheetInterceptorService),_=(0,r.getSheetCommandTarget)(d,{unitId:i.unitId,subUnitId:i.subUnitId});if(!_)return!1;let{payload:v,row:y,column:b,id:x}=i,{workbook:S,worksheet:C,unitId:w,subUnitId:T}=_,{payload:E,display:D=``}=v,O=C.getCell(y,b);if(!O)return!1;let k=C.getCellDocumentModelWithFormula(O,y,b);if(!(k!=null&&k.documentModel))return!1;let A=k.documentModel.getSnapshot(),j=(a=A.body)==null||(a=a.customRanges)==null?void 0:a.find(e=>`${e.rangeId}`===x);if(!j)return!1;let M=(0,t.generateRandomId)(),N=(o=(0,t.getBodySlice)(k.documentModel.getBody(),j.startIndex,j.endIndex+1).textRuns)==null?void 0:o[0];N&&(N.ed=D.length+1);let P=(0,n.replaceSelectionFactory)(e,{unitId:w,body:{dataStream:`${D}`,customRanges:[{rangeId:M,rangeType:t.CustomRangeType.HYPERLINK,startIndex:0,endIndex:D.length-1,properties:{url:E,tooltip:v.tooltip??((s=j.properties)==null?void 0:s.tooltip)??((c=j.properties)==null?void 0:c._xlsxHyperlinkTooltip)}}],textRuns:N?[N]:void 0},selection:{startOffset:j.startIndex,endOffset:j.endIndex+1,collapsed:!1},doc:k.documentModel});if(!P)return!1;let F=t.TextX.apply(t.Tools.deepClone(A.body),P.textX.serialize()),I={p:{...A,body:F},t:t.CellValueType.STRING},L=g.onWriteCell(S,C,y,b,I),R={id:r.SetRangeValuesMutation.id,params:{unitId:w,subUnitId:T,cellValue:{[y]:{[b]:L}}}},z=(0,r.SetRangeValuesUndoMutationFactory)(e,R.params),B={id:r.SetRangeValuesMutation.id,params:z},V=[R],H=[B],U=h.getHyperLinkByLocation(w,T,y,b);return U&&(V.push({id:m.id,params:{unitId:w,subUnitId:T,id:U.id}}),H.push({id:p.id,params:{unitId:w,subUnitId:T,link:U}})),(0,t.sequenceExecute)(V,l).result?await g.onValidateCell(S,C,y,b)===!1?((0,t.sequenceExecute)(H,l),!1):(u.pushUndoRedo({redoMutations:V,undoMutations:H,unitID:w}),!0):!1}},b={type:t.CommandType.COMMAND,id:`sheets.command.update-rich-hyper-link`,handler:(e,r)=>{var i,a,o,s;if(!r)return!1;let{documentId:c,payload:l,id:u}=r,d=e.get(t.IUniverInstanceService),f=e.get(t.ICommandService),p=d.getUnit(c,t.UniverInstanceType.UNIVER_DOC);if(!p)return!1;let m=(i=p.getBody())==null||(i=i.customRanges)==null?void 0:i.find(e=>e.rangeId===u);if(!m)return!1;let h=r.payload.display??``,g=(0,t.generateRandomId)(),_=(a=(0,t.getBodySlice)(p.getBody(),m.startIndex,m.endIndex+1).textRuns)==null?void 0:a[0];_&&(_.ed=h.length+1);let v=(0,n.replaceSelectionFactory)(e,{unitId:c,body:{dataStream:`${h}`,customRanges:[{rangeId:g,rangeType:t.CustomRangeType.HYPERLINK,startIndex:0,endIndex:h.length-1,properties:{url:l.payload,tooltip:l.tooltip??((o=m.properties)==null?void 0:o.tooltip)??((s=m.properties)==null?void 0:s._xlsxHyperlinkTooltip)}}],textRuns:_?[_]:void 0},selection:{startOffset:m.startIndex,endOffset:m.endIndex+1,collapsed:!1},doc:p});return v?f.syncExecuteCommand(v.id,v.params):!1}},x={type:t.CommandType.MUTATION,id:`sheets.mutation.update-hyper-link`,handler(e,t){if(!t)return!1;let n=e.get(f),{unitId:r,subUnitId:i,payload:a,id:o}=t;return n.updateHyperLink(r,i,o,a,!1)}},S={type:t.CommandType.MUTATION,id:`sheets.mutation.update-hyper-link-ref`,handler(e,t){if(!t)return!1;let n=e.get(f),{unitId:r,subUnitId:i,id:a,row:o,column:s,silent:c}=t;return n.updateHyperLinkRef(r,i,a,{row:o,column:s},c)}},C={type:t.CommandType.MUTATION,id:`sheets.mutation.update-rich-hyper-link`,handler(e,n){var i;if(!n)return!1;let{unitId:a,subUnitId:o,row:s,col:c,id:l,url:u}=n,d=e.get(t.IUniverInstanceService),f=(0,r.getSheetCommandTarget)(d,{unitId:a,subUnitId:o});if(!f)return!1;let{worksheet:p}=f,m=p.getCellRaw(s,c),h=m==null||(i=m.p)==null||(i=i.body)==null||(i=i.customRanges)==null?void 0:i.find(e=>e.rangeType===t.CustomRangeType.HYPERLINK&&e.rangeId===l);return h&&(h.properties.url=u),!0}};var w=`@univerjs/sheets-hyper-link`,T=`1.0.0`;let E={},D=class extends t.Disposable{constructor(e,t,n,r){super(),this._refRangeService=e,this._hyperLinkModel=t,this._selectionManagerService=n,this._commandService=r,l(this,`_disposableMap`,new Map),l(this,`_watchDisposableMap`,new Map),l(this,`_rangeDisableMap`,new Map),l(this,`_rangeWatcherMap`,new Map),l(this,`_handlePositionChange`,(e,t,n,r,i)=>{let a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return r?{redos:[{id:S.id,params:{unitId:e,subUnitId:t,id:n.id,row:r.startRow,column:r.startColumn,silent:i}}],undos:[{id:S.id,params:{unitId:e,subUnitId:t,id:n.id,row:a.startRow,column:a.startColumn,silent:i}}]}:{redos:[{id:m.id,params:{unitId:e,subUnitId:t,id:n.id}}],undos:[{id:p.id,params:{unitId:e,subUnitId:t,link:n}}]}}),this._initData(),this._initRefRange()}_registerPosition(e,t,n){let i=n.id,a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._disposableMap.set(i,this._refRangeService.registerRefRange(a,i=>{let o=(0,r.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests)(a,i,{selectionManagerService:this._selectionManagerService}),s=Array.isArray(o)?o[0]:o;return s&&s.startColumn===a.startColumn&&s.startRow===a.startRow?{undos:[],redos:[]}:this._handlePositionChange(e,t,n,s,!1)},e,t))}_watchPosition(e,n,r){let i=r.id,a={startColumn:r.column,endColumn:r.column,startRow:r.row,endRow:r.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(e,n,a,(i,a)=>{let{redos:o}=this._handlePositionChange(e,n,r,a,!0);(0,t.sequenceExecuteAsync)(o,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(e){let t=this._disposableMap.get(e);t==null||t.dispose(),this._disposableMap.delete(e)}_unwatchPosition(e){let t=this._watchDisposableMap.get(e);t==null||t.dispose(),this._watchDisposableMap.delete(e)}_registerRange(e,n,i,o=!1){if(i.startsWith(`#`)){let s=new URLSearchParams(i.slice(1)),c={gid:s.get(`gid`)??``,range:s.get(`range`)??``,rangeid:s.get(`rangeid`)??``};if(c.range&&c.gid){let s=c.gid,l=(0,a.deserializeRangeWithSheet)(c.range).range;(0,t.isValidRange)(l)&&c.range!==`err`&&(this._rangeDisableMap.set(n,this._refRangeService.registerRefRange(l,t=>{let o=(0,r.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests)(l,t,{selectionManagerService:this._selectionManagerService});return o&&(0,a.serializeRange)(o)===(0,a.serializeRange)(l)?{redos:[],undos:[]}:{redos:[{id:x.id,params:{unitId:e,subUnitId:s,id:n,payload:{payload:`#gid=${s}&range=${o?(0,a.serializeRange)(o):`err`}`}}}],undos:[{id:x.id,params:{unitId:e,subUnitId:s,id:n,payload:{payload:i}}}]}},e,s)),o||this._rangeWatcherMap.set(n,this._refRangeService.watchRange(e,s,l,(t,r)=>{this._hyperLinkModel.updateHyperLink(e,s,n,{payload:`#gid=${s}&range=${r?(0,a.serializeRange)(r):`err`}`},!0)},!0)))}}}_unregisterRange(e){let t=this._rangeDisableMap.get(e);t==null||t.dispose(),this._rangeDisableMap.delete(e)}_unwatchRange(e){let t=this._rangeWatcherMap.get(e);t==null||t.dispose(),this._rangeWatcherMap.delete(e)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,links:r}=e;r.forEach(e=>{this._registerPosition(t,n,e),this._watchPosition(t,n,e),this._registerRange(t,e.id,e.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(e=>{switch(e.type){case`add`:this._registerPosition(e.unitId,e.subUnitId,e.payload),this._watchPosition(e.unitId,e.subUnitId,e.payload),this._registerRange(e.unitId,e.payload.id,e.payload.payload);break;case`remove`:this._unregisterPosition(e.payload.id),this._unwatchPosition(e.payload.id),this._unregisterRange(e.payload.id),this._unwatchRange(e.payload.id);break;case`updateRef`:{let{unitId:t,subUnitId:n,id:r,silent:i}=e,a=this._hyperLinkModel.getHyperLink(t,n,r);if(!a)return;this._unregisterPosition(r),this._registerPosition(t,n,a),i||(this._unwatchPosition(r),this._watchPosition(t,n,a));break}case`unload`:{let{unitLinks:t}=e;t.forEach(e=>{let{links:t}=e;t.forEach(e=>{this._unregisterPosition(e.id),this._unwatchPosition(e.id),this._unregisterRange(e.id),this._unwatchRange(e.id)})});break}case`update`:e.silent||this._unwatchRange(e.id),this._unregisterRange(e.id),this._registerRange(e.unitId,e.id,e.payload.payload,e.silent)}})),this.disposeWithMe((0,t.toDisposable)(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};D=d([u(0,(0,t.Inject)(r.RefRangeService)),u(1,(0,t.Inject)(f)),u(2,(0,t.Inject)(r.SheetsSelectionsService)),u(3,t.ICommandService)],D);let O=class extends t.Disposable{constructor(e,t,n){super(),this._sheetInterceptorService=e,this._univerInstanceService=t,this._hyperLinkModel=n,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===r.RemoveSheetCommand.id){var n;let r=e.params,i=r.unitId?this._univerInstanceService.getUnit(r.unitId):this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!i)return{redos:[],undos:[]};let a=i.getUnitId(),o=r.subUnitId||((n=i.getActiveSheet())==null?void 0:n.getSheetId());if(!o)return{redos:[],undos:[]};let s=this._hyperLinkModel.getSubUnit(a,o);return{redos:s.map(e=>({id:m.id,params:{unitId:a,subUnitId:o,id:e.id}})),undos:s.map(e=>({id:p.id,params:{unitId:a,subUnitId:o,link:e}}))}}return{redos:[],undos:[]}}}))}};O=d([u(0,(0,t.Inject)(r.SheetInterceptorService)),u(1,t.IUniverInstanceService),u(2,(0,t.Inject)(f))],O);let k=class extends t.Disposable{constructor(e,t,n){super(),this._commandService=e,this._univerInstanceService=t,this._refRangeService=n,l(this,`_refRangeMap`,new Map),this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(e,n){let r=this._refRangeMap.get(e);r||(r=new Map,this._refRangeMap.set(e,r));let i=r.get(n);return i||(i=new t.ObjectMatrix,r.set(n,i)),i}_isLegalRangeUrl(e,n){let r=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!r)return null;if(n&&n.startsWith(`#`)){let e=new URLSearchParams(n.slice(1)),i={gid:e.get(`gid`)??``,range:e.get(`range`)??``,rangeid:e.get(`rangeid`)??``};if(i.range&&i.gid){let e=i.gid,n=r.getSheetBySheetId(e);if(!n)return null;let o=(0,a.deserializeRangeWithSheet)(i.range).range;if((0,t.isValidRange)(o,n)&&i.range!==`err`)return{range:o,worksheet:n}}}return null}_registerRange(e,n,i,o,s){var c;let l=this._enusreMap(e,n);if((c=s.body)!=null&&(c=c.customRanges)!=null&&c.some(n=>{var r;return n.rangeType===t.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(e,(r=n.properties)==null?void 0:r.url)})){var u;let c=new t.DisposableCollection,d=!1;(u=s.body)==null||(u=u.customRanges)==null||u.forEach(s=>{if(s.rangeType===t.CustomRangeType.HYPERLINK){var l;let u=(l=s.properties)==null?void 0:l.url,f=this._isLegalRangeUrl(e,u);if(f){let{range:l,worksheet:p}=f;d=!0,c.add(this._refRangeService.registerRefRange(l,c=>{let d=(0,r.handleDefaultRangeChangeWithEffectRefCommands)(l,c);return d&&t.Rectangle.equals(d,l)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:C.id,params:{unitId:e,subUnitId:n,row:i,col:o,id:s.rangeId,url:`#gid=${n}&range=${d?(0,a.serializeRange)(d):`err`}`}}],undos:[{id:C.id,params:{unitId:e,subUnitId:n,row:i,col:o,id:s.rangeId,url:u}}],redos:[]}},p.getUnitId(),p.getSheetId()))}}}),d&&l.setValue(i,o,c)}}_initWorkbookLoad(){let e=e=>{let t=e.getUnitId();e.getSheets().forEach(e=>{let n=e.getSheetId(),r=this._enusreMap(t,n);e.getCellMatrix().forValue((e,i,a)=>{let o=r.getValue(e,i);o&&o.dispose(),a&&a.p&&this._registerRange(t,n,e,i,a.p)})})};this._univerInstanceService.getAllUnitsForType(t.UniverInstanceType.UNIVER_SHEET).forEach(t=>{e(t)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(n=>{let{unit:r}=n;r.type===t.UniverInstanceType.UNIVER_SHEET&&e(r)}))}_initWorkbookUnload(){this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(e=>{if(e.type===t.UniverInstanceType.UNIVER_SHEET){let t=e,n=t.getUnitId();t.getSheets().forEach(e=>{let t=e.getSheetId();this._enusreMap(n,t).forValue((e,t,n)=>{n&&n.dispose()})}),this._refRangeMap.delete(n)}}))}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===r.SetRangeValuesMutation.id){let{unitId:n,subUnitId:r,cellValue:i}=e.params,a=this._enusreMap(n,r);i&&new t.ObjectMatrix(i).forValue((e,t,i)=>{let o=a.getValue(e,t);o&&o.dispose(),i&&i.p&&this._registerRange(n,r,e,t,i.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===C.id){let{unitId:t,subUnitId:n,row:i,col:a}=e.params,o=(0,r.getSheetCommandTarget)(this._univerInstanceService,{unitId:t,subUnitId:n}),s=this._enusreMap(t,n).getValue(i,a);if(s&&s.dispose(),o){let{worksheet:e}=o,r=e.getCellRaw(i,a);r&&r.p&&this._registerRange(t,n,i,a,r.p)}}}))}};k=d([u(0,t.ICommandService),u(1,t.IUniverInstanceService),u(2,(0,t.Inject)(r.RefRangeService))],k);let A=class extends t.Disposable{constructor(e,t,n,r){super(),this._sheetInterceptorService=e,this._hyperLinkModel=t,this._selectionManagerService=n,this._univerInstanceService=r,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===r.SetRangeValuesCommand.id){let n=e.params,{unitId:r,subUnitId:i}=n,a=[],o=[];return n.cellValue&&new t.ObjectMatrix(n.cellValue).forValue((e,t)=>{let n=this._hyperLinkModel.getHyperLinkByLocation(r,i,e,t);n&&(a.push({id:m.id,params:{unitId:r,subUnitId:i,id:n.id}}),o.push({id:p.id,params:{unitId:r,subUnitId:i,link:n}}))}),{undos:o,redos:a}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===r.ClearSelectionContentCommand.id||e.id===r.ClearSelectionAllCommand.id||e.id===r.ClearSelectionFormatCommand.id){let n=[],i=[],a=this._selectionManagerService.getCurrentLastSelection(),o=(0,r.getSheetCommandTarget)(this._univerInstanceService,e.params);if(a&&o){let{unitId:e,subUnitId:r}=o;t.Range.foreach(a.range,(t,a)=>{let o=this._hyperLinkModel.getHyperLinkByLocation(e,r,t,a);o&&(n.push({id:m.id,params:{unitId:e,subUnitId:r,id:o.id}}),i.push({id:p.id,params:{unitId:e,subUnitId:r,link:o}}))})}return{redos:n,undos:i}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(r.AFTER_CELL_EDIT,{handler:(e,n,r)=>{if(!e||e.p)return r(e);if(typeof e.v==`string`&&t.Tools.isLegalUrl(e.v)&&e.v[e.v.length-1]!==` `){let{unitId:i,subUnitId:a,row:o,col:s}=n,c=t.Tools.normalizeUrl(e.v),l=this._univerInstanceService.getUnit(i,t.UniverInstanceType.UNIVER_SHEET),u=l==null?void 0:l.getSheetBySheetId(a);if(!u)return r(e);let d=u.getBlankCellDocumentModel(e,o,s);if(!d.documentModel)return r(e);let f=t.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:e.v.length,collapsed:!1},body:{dataStream:`${e.v}`,customRanges:[{startIndex:0,endIndex:e.v.length-1,rangeId:(0,t.generateRandomId)(),rangeType:t.CustomRangeType.HYPERLINK,properties:{url:c}}]},doc:d.documentModel});if(!f)return r(e);let p=d.documentModel.getBody();return t.TextX.apply(p,f.serialize()),r({...e,p:{id:t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:p,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return r(e)}}))}};A=d([u(0,(0,t.Inject)(r.SheetInterceptorService)),u(1,(0,t.Inject)(f)),u(2,(0,t.Inject)(r.SheetsSelectionsService)),u(3,t.IUniverInstanceService)],A);let j=class extends t.Disposable{constructor(e){super(),this._commandService=e,this._registerCommands()}_registerCommands(){[h,y,_,b,v,g,p,x,m,S,C].forEach(e=>{this._commandService.registerCommand(e)})}};j=d([u(0,t.ICommandService)],j);let M=function(e){return e.SHEET=`gid`,e.RANGE=`range`,e.DEFINE_NAME=`rangeid`,e.INVALID=`invalid`,e.URL=`url`,e}({}),N=class{constructor(e,t,n){this._univerInstanceService=e,this._localeService=t,this._definedNamesService=n}buildHyperLink(e,t){if(typeof e==`string`)return`#rangeid=${e}`;let n=`#gid=${t}`;return e&&(n+=`&range=${(0,a.serializeRange)(e)}`),n}parseHyperLink(e){if(e.startsWith(`#`)){let t=new URLSearchParams(e.slice(1)),n={gid:t.get(`gid`)??``,range:t.get(`range`)??``,rangeid:t.get(`rangeid`)??``,unitid:t.get(`unitid`)??``},r=this._getURLName(n);return{type:r.type,name:r.name,url:e,searchObj:n}}return{type:`url`,name:e,url:e,searchObj:null}}_getURLName(e){let{gid:n,range:r,rangeid:i,unitid:o}=e,s=o?this._univerInstanceService.getUnit(o,t.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET),c={type:`invalid`,name:this._localeService.t(`sheets-hyper-link.message.refError`)};if(!s)return c;let l=n?s.getSheetBySheetId(n):s.getActiveSheet(),u=(l==null?void 0:l.getName())??``;if(r){if(!l)return c;let e=(0,a.deserializeRangeWithSheet)(r).range;return(0,t.isValidRange)(e,l)&&r!==`err`?{type:`range`,name:(0,a.serializeRangeWithSheet)(u,e)}:c}if(i){let e=this._definedNamesService.getValueById(s.getUnitId(),i);return e?{type:`rangeid`,name:e.formulaOrRefString}:c}if(n){let e=s.getSheetBySheetId(n);return e?{type:`gid`,name:e.getName()}:c}return c}};N=d([u(0,t.IUniverInstanceService),u(1,(0,t.Inject)(t.LocaleService)),u(2,a.IDefinedNamesService)],N);let P=class extends t.Plugin{constructor(e=E,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},E,this._config);this._configService.setConfig(`sheets-hyper-link.config`,i)}onStarting(){(0,t.registerDependencies)(this._injector,[[f],[N],[j],[D],[A],[O],[k]]),(0,t.touchDependencies)(this._injector,[[D],[j],[A],[O],[k]])}};l(P,`pluginName`,`SHEET_HYPER_LINK_PLUGIN`),l(P,`packageName`,w),l(P,`version`,T),l(P,`type`,t.UniverInstanceType.UNIVER_SHEET),P=d([(0,t.DependentOn)(a.UniverFormulaEnginePlugin,r.UniverSheetsPlugin),u(1,(0,t.Inject)(t.Injector)),u(2,t.IConfigService)],P),e.AddHyperLinkCommand=h,e.AddHyperLinkMutation=p,e.AddRichHyperLinkCommand=g,e.CancelHyperLinkCommand=_,e.CancelRichHyperLinkCommand=v,e.ERROR_RANGE=`err`,Object.defineProperty(e,"HyperLinkModel",{enumerable:!0,get:function(){return f}}),e.RemoveHyperLinkMutation=m,e.SheetHyperLinkType=M,Object.defineProperty(e,"SheetsHyperLinkParserService",{enumerable:!0,get:function(){return N}}),Object.defineProperty(e,"UniverSheetsHyperLinkPlugin",{enumerable:!0,get:function(){return P}}),e.UpdateHyperLinkCommand=y,e.UpdateHyperLinkMutation=x,e.UpdateHyperLinkRefMutation=S,e.UpdateRichHyperLinkCommand=b});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-hyper-link",
3
- "version": "1.0.0-insiders.20260813-7c9aa50",
3
+ "version": "1.0.0",
4
4
  "private": false,
5
5
  "description": "Hyperlink model and commands for Univer Sheets.",
6
6
  "author": "DreamNum Co., Ltd. <developer@univer.ai>",
@@ -67,16 +67,16 @@
67
67
  "rxjs": ">=7.0.0"
68
68
  },
69
69
  "dependencies": {
70
- "@univerjs/core": "1.0.0-insiders.20260813-7c9aa50",
71
- "@univerjs/docs": "1.0.0-insiders.20260813-7c9aa50",
72
- "@univerjs/sheets": "1.0.0-insiders.20260813-7c9aa50",
73
- "@univerjs/engine-formula": "1.0.0-insiders.20260813-7c9aa50"
70
+ "@univerjs/core": "1.0.0",
71
+ "@univerjs/docs": "1.0.0",
72
+ "@univerjs/engine-formula": "1.0.0",
73
+ "@univerjs/sheets": "1.0.0"
74
74
  },
75
75
  "devDependencies": {
76
+ "@univerjs-infra/shared": "1.0.0",
76
77
  "rxjs": "^7.8.2",
77
78
  "typescript": "^6.0.3",
78
- "vitest": "^4.1.10",
79
- "@univerjs-infra/shared": "1.0.0-beta.0"
79
+ "vitest": "^5.0.0"
80
80
  },
81
81
  "scripts": {
82
82
  "test": "vitest run",