@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/facade.js CHANGED
@@ -1 +1,207 @@
1
- import{CanceledError as e,CustomRangeType as t,DataStreamTreeTokenType as n,ICommandService as r,Inject as i,generateRandomId as a}from"@univerjs/core";import{AddHyperLinkCommand as o,CancelHyperLinkCommand as s,SheetsHyperLinkParserService as c,UpdateHyperLinkCommand as l}from"@univerjs/sheets-hyper-link";import{FRange as u,FWorkbook as d,FWorksheet as f}from"@univerjs/sheets/facade";import{FEventName as p,FUniver as m}from"@univerjs/core/facade";function h(e,t){return function(n,r){t(n,r,e)}}function g(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 _=class{constructor(e,t){this._workbook=e,this._parserService=t}getRangeUrl(e){return this._parserService.buildHyperLink(this._workbook.getId(),e.getSheetId(),e.getRange()),this}};_=g([h(1,i(c))],_);var v=class extends d{parseSheetHyperlink(e){return this._injector.get(c).parseHyperLink(e)}};d.extend(v);var y=class extends f{getUrl(){return this._injector.get(c).buildHyperLink(this._workbook.getUnitId(),this._worksheet.getSheetId())}};f.extend(y);var b=class extends u{setHyperLink(e,t){let n={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),link:{row:this._range.startRow,column:this._range.startColumn,payload:e,display:t,id:a()}};return this._commandService.executeCommand(o.id,n)}getHyperLinks(){var e,r;let i=this._worksheet.getCellRaw(this._range.startRow,this._range.startColumn);return i!=null&&i.p?(e=(r=i.p.body)==null||(r=r.customRanges)==null?void 0:r.filter(e=>e.rangeType===t.HYPERLINK).map(e=>{var t,r,a,o;return{id:`${e.rangeId}`,startIndex:e.startIndex,endIndex:e.endIndex,url:(t=(r=e.properties)==null?void 0:r.url)==null?``:t,label:(a=(o=i.p)==null||(o=o.body)==null?void 0:o.dataStream.slice(e.startIndex,e.endIndex+1).replaceAll(n.CUSTOM_RANGE_START,``).replaceAll(n.CUSTOM_RANGE_END,``))==null?``:a}}))==null?[]:e:[]}updateHyperLink(e,t,n){let r={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id:e,payload:{payload:t,display:n}};return this._commandService.executeCommand(l.id,r)}cancelHyperLink(e){let t={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id:e};return this._commandService.syncExecuteCommand(s.id,t)}getUrl(){return this._injector.get(c).buildHyperLink(this.getUnitId(),this.getSheetId(),this.getRange())}};u.extend(b);var x=class extends p{get BeforeSheetLinkAdd(){return`BeforeSheetLinkAdd`}get BeforeSheetLinkCancel(){return`BeforeSheetLinkCancel`}get BeforeSheetLinkUpdate(){return`BeforeSheetLinkUpdate`}};p.extend(x);var S=class extends m{_initialize(t){let n=t.get(r);this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetLinkAdd,()=>n.beforeCommandExecuted(t=>{if(t.id!==o.id)return;let n=this.getCommandSheetTarget(t);if(!n)return;let r=t.params,i={workbook:n.workbook,worksheet:n.worksheet,row:r.link.row,col:r.link.column,link:r.link};if(this.fireEvent(this.Event.BeforeSheetLinkAdd,i),i.cancel)throw new e}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetLinkUpdate,()=>n.beforeCommandExecuted(t=>{if(t.id!==l.id)return;let n=this.getCommandSheetTarget(t);if(!n)return;let r=t.params,i={workbook:n.workbook,worksheet:n.worksheet,row:r.row,column:r.column,id:r.id,payload:r.payload};if(this.fireEvent(this.Event.BeforeSheetLinkUpdate,i),i.cancel)throw new e}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeSheetLinkCancel,()=>n.beforeCommandExecuted(t=>{if(t.id!==s.id)return;let n=this.getCommandSheetTarget(t);if(!n)return;let r=t.params,i={workbook:n.workbook,worksheet:n.worksheet,row:r.row,column:r.column,id:r.id};if(this.fireEvent(this.Event.BeforeSheetLinkCancel,i),i.cancel)throw new e})))}};m.extend(S);export{v as FWorkbookHyperlinkMixin};
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 };