@univerjs/sheets-hyper-link 0.20.1 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/facade.js +208 -1
- package/lib/cjs/index.js +1600 -1
- package/lib/es/facade.js +207 -1
- package/lib/es/index.js +1570 -1
- package/lib/facade.js +207 -1
- package/lib/index.js +1570 -1
- package/lib/umd/index.js +1 -1
- package/package.json +7 -7
package/lib/facade.js
CHANGED
|
@@ -1 +1,207 @@
|
|
|
1
|
-
import{CanceledError
|
|
1
|
+
import { CanceledError, CustomRangeType, DataStreamTreeTokenType, ICommandService, Inject, generateRandomId } from "@univerjs/core";
|
|
2
|
+
import { AddHyperLinkCommand, CancelHyperLinkCommand, SheetsHyperLinkParserService, UpdateHyperLinkCommand } from "@univerjs/sheets-hyper-link";
|
|
3
|
+
import { FRange, FWorkbook, FWorksheet } from "@univerjs/sheets/facade";
|
|
4
|
+
import { FEventName, FUniver } from "@univerjs/core/facade";
|
|
5
|
+
|
|
6
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
|
|
7
|
+
function __decorateParam(paramIndex, decorator) {
|
|
8
|
+
return function(target, key) {
|
|
9
|
+
decorator(target, key, paramIndex);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
|
|
15
|
+
function __decorate(decorators, target, key, desc) {
|
|
16
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
17
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
18
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
19
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/facade/f-workbook.ts
|
|
24
|
+
let SheetHyperLinkBuilder = class SheetHyperLinkBuilder {
|
|
25
|
+
constructor(_workbook, _parserService) {
|
|
26
|
+
this._workbook = _workbook;
|
|
27
|
+
this._parserService = _parserService;
|
|
28
|
+
}
|
|
29
|
+
getRangeUrl(range) {
|
|
30
|
+
this._parserService.buildHyperLink(this._workbook.getId(), range.getSheetId(), range.getRange());
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
SheetHyperLinkBuilder = __decorate([__decorateParam(1, Inject(SheetsHyperLinkParserService))], SheetHyperLinkBuilder);
|
|
35
|
+
var FWorkbookHyperlinkMixin = class extends FWorkbook {
|
|
36
|
+
/**
|
|
37
|
+
* Parse the hyperlink string to get the hyperlink info.
|
|
38
|
+
* @param {string} hyperlink the hyperlink string
|
|
39
|
+
* @returns {ISheetHyperLinkInfo} the hyperlink info
|
|
40
|
+
*/
|
|
41
|
+
parseSheetHyperlink(hyperlink) {
|
|
42
|
+
return this._injector.get(SheetsHyperLinkParserService).parseHyperLink(hyperlink);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
FWorkbook.extend(FWorkbookHyperlinkMixin);
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/facade/f-worksheet.ts
|
|
49
|
+
/**
|
|
50
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
51
|
+
*
|
|
52
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
53
|
+
* you may not use this file except in compliance with the License.
|
|
54
|
+
* You may obtain a copy of the License at
|
|
55
|
+
*
|
|
56
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
57
|
+
*
|
|
58
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
59
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
60
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
61
|
+
* See the License for the specific language governing permissions and
|
|
62
|
+
* limitations under the License.
|
|
63
|
+
*/
|
|
64
|
+
var FWorksheetHyperlinkMixin = class extends FWorksheet {
|
|
65
|
+
getUrl() {
|
|
66
|
+
return this._injector.get(SheetsHyperLinkParserService).buildHyperLink(this._workbook.getUnitId(), this._worksheet.getSheetId());
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
FWorksheet.extend(FWorksheetHyperlinkMixin);
|
|
70
|
+
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/facade/f-range.ts
|
|
73
|
+
var FRangeSheetsHyperlinkMixin = class extends FRange {
|
|
74
|
+
setHyperLink(url, label) {
|
|
75
|
+
const params = {
|
|
76
|
+
unitId: this.getUnitId(),
|
|
77
|
+
subUnitId: this._worksheet.getSheetId(),
|
|
78
|
+
link: {
|
|
79
|
+
row: this._range.startRow,
|
|
80
|
+
column: this._range.startColumn,
|
|
81
|
+
payload: url,
|
|
82
|
+
display: label,
|
|
83
|
+
id: generateRandomId()
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
return this._commandService.executeCommand(AddHyperLinkCommand.id, params);
|
|
87
|
+
}
|
|
88
|
+
getHyperLinks() {
|
|
89
|
+
var _cellValue$p$body$cus, _cellValue$p$body;
|
|
90
|
+
const cellValue = this._worksheet.getCellRaw(this._range.startRow, this._range.startColumn);
|
|
91
|
+
if (!(cellValue === null || cellValue === void 0 ? void 0 : cellValue.p)) return [];
|
|
92
|
+
return (_cellValue$p$body$cus = (_cellValue$p$body = cellValue.p.body) === null || _cellValue$p$body === void 0 || (_cellValue$p$body = _cellValue$p$body.customRanges) === null || _cellValue$p$body === void 0 ? void 0 : _cellValue$p$body.filter((range) => range.rangeType === CustomRangeType.HYPERLINK).map((range) => {
|
|
93
|
+
var _range$properties$url, _range$properties, _cellValue$p$body$dat, _cellValue$p;
|
|
94
|
+
return {
|
|
95
|
+
id: `${range.rangeId}`,
|
|
96
|
+
startIndex: range.startIndex,
|
|
97
|
+
endIndex: range.endIndex,
|
|
98
|
+
url: (_range$properties$url = (_range$properties = range.properties) === null || _range$properties === void 0 ? void 0 : _range$properties.url) !== null && _range$properties$url !== void 0 ? _range$properties$url : "",
|
|
99
|
+
label: (_cellValue$p$body$dat = (_cellValue$p = cellValue.p) === null || _cellValue$p === void 0 || (_cellValue$p = _cellValue$p.body) === null || _cellValue$p === void 0 ? void 0 : _cellValue$p.dataStream.slice(range.startIndex, range.endIndex + 1).replaceAll(DataStreamTreeTokenType.CUSTOM_RANGE_START, "").replaceAll(DataStreamTreeTokenType.CUSTOM_RANGE_END, "")) !== null && _cellValue$p$body$dat !== void 0 ? _cellValue$p$body$dat : ""
|
|
100
|
+
};
|
|
101
|
+
})) !== null && _cellValue$p$body$cus !== void 0 ? _cellValue$p$body$cus : [];
|
|
102
|
+
}
|
|
103
|
+
updateHyperLink(id, url, label) {
|
|
104
|
+
const params = {
|
|
105
|
+
unitId: this.getUnitId(),
|
|
106
|
+
subUnitId: this._worksheet.getSheetId(),
|
|
107
|
+
row: this._range.startRow,
|
|
108
|
+
column: this._range.startColumn,
|
|
109
|
+
id,
|
|
110
|
+
payload: {
|
|
111
|
+
payload: url,
|
|
112
|
+
display: label
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
return this._commandService.executeCommand(UpdateHyperLinkCommand.id, params);
|
|
116
|
+
}
|
|
117
|
+
cancelHyperLink(id) {
|
|
118
|
+
const params = {
|
|
119
|
+
unitId: this.getUnitId(),
|
|
120
|
+
subUnitId: this._worksheet.getSheetId(),
|
|
121
|
+
row: this._range.startRow,
|
|
122
|
+
column: this._range.startColumn,
|
|
123
|
+
id
|
|
124
|
+
};
|
|
125
|
+
return this._commandService.syncExecuteCommand(CancelHyperLinkCommand.id, params);
|
|
126
|
+
}
|
|
127
|
+
getUrl() {
|
|
128
|
+
return this._injector.get(SheetsHyperLinkParserService).buildHyperLink(this.getUnitId(), this.getSheetId(), this.getRange());
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
FRange.extend(FRangeSheetsHyperlinkMixin);
|
|
132
|
+
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/facade/f-event.ts
|
|
135
|
+
var FSheetsHyperlinkEventNameMixin = class extends FEventName {
|
|
136
|
+
get BeforeSheetLinkAdd() {
|
|
137
|
+
return "BeforeSheetLinkAdd";
|
|
138
|
+
}
|
|
139
|
+
get BeforeSheetLinkCancel() {
|
|
140
|
+
return "BeforeSheetLinkCancel";
|
|
141
|
+
}
|
|
142
|
+
get BeforeSheetLinkUpdate() {
|
|
143
|
+
return "BeforeSheetLinkUpdate";
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
FEventName.extend(FSheetsHyperlinkEventNameMixin);
|
|
147
|
+
|
|
148
|
+
//#endregion
|
|
149
|
+
//#region src/facade/f-univer.ts
|
|
150
|
+
var FUniverSheetsHyperlinkMixin = class extends FUniver {
|
|
151
|
+
/**
|
|
152
|
+
* @ignore
|
|
153
|
+
*/
|
|
154
|
+
_initialize(injector) {
|
|
155
|
+
const commandService = injector.get(ICommandService);
|
|
156
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetLinkAdd, () => commandService.beforeCommandExecuted((commandInfo) => {
|
|
157
|
+
if (commandInfo.id !== AddHyperLinkCommand.id) return;
|
|
158
|
+
const eventTarget = this.getCommandSheetTarget(commandInfo);
|
|
159
|
+
if (!eventTarget) return;
|
|
160
|
+
const params = commandInfo.params;
|
|
161
|
+
const eventParams = {
|
|
162
|
+
workbook: eventTarget.workbook,
|
|
163
|
+
worksheet: eventTarget.worksheet,
|
|
164
|
+
row: params.link.row,
|
|
165
|
+
col: params.link.column,
|
|
166
|
+
link: params.link
|
|
167
|
+
};
|
|
168
|
+
this.fireEvent(this.Event.BeforeSheetLinkAdd, eventParams);
|
|
169
|
+
if (eventParams.cancel) throw new CanceledError();
|
|
170
|
+
})));
|
|
171
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetLinkUpdate, () => commandService.beforeCommandExecuted((commandInfo) => {
|
|
172
|
+
if (commandInfo.id !== UpdateHyperLinkCommand.id) return;
|
|
173
|
+
const eventTarget = this.getCommandSheetTarget(commandInfo);
|
|
174
|
+
if (!eventTarget) return;
|
|
175
|
+
const params = commandInfo.params;
|
|
176
|
+
const eventParams = {
|
|
177
|
+
workbook: eventTarget.workbook,
|
|
178
|
+
worksheet: eventTarget.worksheet,
|
|
179
|
+
row: params.row,
|
|
180
|
+
column: params.column,
|
|
181
|
+
id: params.id,
|
|
182
|
+
payload: params.payload
|
|
183
|
+
};
|
|
184
|
+
this.fireEvent(this.Event.BeforeSheetLinkUpdate, eventParams);
|
|
185
|
+
if (eventParams.cancel) throw new CanceledError();
|
|
186
|
+
})));
|
|
187
|
+
this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetLinkCancel, () => commandService.beforeCommandExecuted((commandInfo) => {
|
|
188
|
+
if (commandInfo.id !== CancelHyperLinkCommand.id) return;
|
|
189
|
+
const eventTarget = this.getCommandSheetTarget(commandInfo);
|
|
190
|
+
if (!eventTarget) return;
|
|
191
|
+
const params = commandInfo.params;
|
|
192
|
+
const eventParams = {
|
|
193
|
+
workbook: eventTarget.workbook,
|
|
194
|
+
worksheet: eventTarget.worksheet,
|
|
195
|
+
row: params.row,
|
|
196
|
+
column: params.column,
|
|
197
|
+
id: params.id
|
|
198
|
+
};
|
|
199
|
+
this.fireEvent(this.Event.BeforeSheetLinkCancel, eventParams);
|
|
200
|
+
if (eventParams.cancel) throw new CanceledError();
|
|
201
|
+
})));
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
FUniver.extend(FUniverSheetsHyperlinkMixin);
|
|
205
|
+
|
|
206
|
+
//#endregion
|
|
207
|
+
export { FWorkbookHyperlinkMixin };
|