@univerjs/sheets-hyper-link 1.0.0-rc.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/facade.js +8 -5
- package/lib/cjs/index.js +25 -14
- package/lib/cjs/locale/ar-SA.js +0 -1
- package/lib/cjs/locale/ca-ES.js +0 -1
- package/lib/cjs/locale/de-DE.js +0 -1
- package/lib/cjs/locale/en-US.js +0 -1
- package/lib/cjs/locale/es-ES.js +0 -1
- package/lib/cjs/locale/fa-IR.js +0 -1
- package/lib/cjs/locale/fr-FR.js +0 -1
- package/lib/cjs/locale/id-ID.js +0 -1
- package/lib/cjs/locale/it-IT.js +0 -1
- package/lib/cjs/locale/ja-JP.js +0 -1
- package/lib/cjs/locale/ko-KR.js +0 -1
- package/lib/cjs/locale/pl-PL.js +0 -1
- package/lib/cjs/locale/pt-BR.js +0 -1
- package/lib/cjs/locale/ru-RU.js +0 -1
- package/lib/cjs/locale/sk-SK.js +0 -1
- package/lib/cjs/locale/vi-VN.js +0 -1
- package/lib/cjs/locale/zh-CN.js +0 -1
- package/lib/cjs/locale/zh-HK.js +0 -1
- package/lib/cjs/locale/zh-TW.js +0 -1
- package/lib/es/facade.js +8 -5
- package/lib/es/index.js +25 -14
- package/lib/facade.js +8 -5
- package/lib/index.js +25 -14
- package/lib/types/facade/f-range.d.ts +13 -8
- package/lib/types/models/hyper-link.model.d.ts +1 -0
- package/lib/types/types/interfaces/i-hyper-link.d.ts +2 -0
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +7 -7
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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: {
|
|
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: {
|
|
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: {
|
|
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
|
|
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.
|
|
721
|
+
var version = "1.0.1";
|
|
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)(() => {
|
package/lib/cjs/locale/ar-SA.js
CHANGED
package/lib/cjs/locale/ca-ES.js
CHANGED
package/lib/cjs/locale/de-DE.js
CHANGED
package/lib/cjs/locale/en-US.js
CHANGED
package/lib/cjs/locale/es-ES.js
CHANGED
package/lib/cjs/locale/fa-IR.js
CHANGED
package/lib/cjs/locale/fr-FR.js
CHANGED
package/lib/cjs/locale/id-ID.js
CHANGED
package/lib/cjs/locale/it-IT.js
CHANGED
package/lib/cjs/locale/ja-JP.js
CHANGED
package/lib/cjs/locale/ko-KR.js
CHANGED
package/lib/cjs/locale/pl-PL.js
CHANGED
package/lib/cjs/locale/pt-BR.js
CHANGED
package/lib/cjs/locale/ru-RU.js
CHANGED
package/lib/cjs/locale/sk-SK.js
CHANGED
package/lib/cjs/locale/vi-VN.js
CHANGED
package/lib/cjs/locale/zh-CN.js
CHANGED
package/lib/cjs/locale/zh-HK.js
CHANGED
package/lib/cjs/locale/zh-TW.js
CHANGED
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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: {
|
|
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: {
|
|
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: {
|
|
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
|
|
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.
|
|
720
|
+
var version = "1.0.1";
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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: {
|
|
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: {
|
|
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: {
|
|
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
|
|
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.
|
|
720
|
+
var version = "1.0.1";
|
|
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
|
|
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
|
-
*
|
|
68
|
-
* @
|
|
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
|
|
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
|
}
|
|
@@ -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
|
|
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-rc.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);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.1`;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.
|
|
3
|
+
"version": "1.0.1",
|
|
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/
|
|
71
|
-
"@univerjs/
|
|
72
|
-
"@univerjs/engine-formula": "1.0.
|
|
73
|
-
"@univerjs/
|
|
70
|
+
"@univerjs/core": "1.0.1",
|
|
71
|
+
"@univerjs/docs": "1.0.1",
|
|
72
|
+
"@univerjs/engine-formula": "1.0.1",
|
|
73
|
+
"@univerjs/sheets": "1.0.1"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
|
+
"@univerjs-infra/shared": "1.0.1",
|
|
76
77
|
"rxjs": "^7.8.2",
|
|
77
78
|
"typescript": "^6.0.3",
|
|
78
|
-
"vitest": "^5.0.0"
|
|
79
|
-
"@univerjs-infra/shared": "1.0.0-rc.0"
|
|
79
|
+
"vitest": "^5.0.0"
|
|
80
80
|
},
|
|
81
81
|
"scripts": {
|
|
82
82
|
"test": "vitest run",
|