@univerjs/sheets-hyper-link 0.6.0 → 0.6.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.
@@ -7,37 +7,52 @@ import { FWorkbook, FWorksheet } from '@univerjs/sheets/facade';
7
7
  interface IFSheetLinkEvent {
8
8
  /**
9
9
  * Event triggered before adding a link
10
- *
10
+ * @see {@link IBeforeSheetLinkAddEvent}
11
11
  * @example
12
12
  * ```ts
13
- * univerAPI.addEvent(univerAPI.Event.BeforeSheetLinkAdd, (params) => {
14
- * const { workbook, worksheet, row, col, link } = params;
15
- * console.log('before sheet link add', params);
13
+ * const disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetLinkAdd, (params) => {
14
+ * const { workbook, worksheet, row, col, link } = params;
15
+ * console.log('before sheet link add', params);
16
+ *
17
+ * // Cancel the sheet link add operation
18
+ * params.cancel = true;
16
19
  * });
20
+ *
21
+ * // Remove the event listener, use `disposable.dispose()`
17
22
  * ```
18
23
  */
19
24
  readonly BeforeSheetLinkAdd: 'BeforeSheetLinkAdd';
20
25
  /**
21
26
  * Event triggered before canceling a link
22
- *
27
+ * @see {@link IBeforeSheetLinkCancelEvent}
23
28
  * @example
24
29
  * ```ts
25
- * univerAPI.addEvent(univerAPI.Event.BeforeSheetLinkCancel, (params) => {
26
- * const { workbook, worksheet, row, column, id } = params;
27
- * console.log('before sheet link cancel', params);
30
+ * const disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetLinkCancel, (params) => {
31
+ * const { workbook, worksheet, row, column, id } = params;
32
+ * console.log('before sheet link cancel', params);
33
+ *
34
+ * // Cancel the sheet link cancel operation
35
+ * params.cancel = true;
28
36
  * });
37
+ *
38
+ * // Remove the event listener, use `disposable.dispose()`
29
39
  * ```
30
40
  */
31
41
  readonly BeforeSheetLinkCancel: 'BeforeSheetLinkCancel';
32
42
  /**
33
43
  * Event triggered before updating a link
34
- *
44
+ * @see {@link IBeforeSheetLinkUpdateEvent}
35
45
  * @example
36
46
  * ```ts
37
- * univerAPI.addEvent(univerAPI.Event.BeforeSheetLinkUpdate, (params) => {
38
- * const { workbook, worksheet, row, column, id, payload } = params;
39
- * console.log('before sheet link update', params);
47
+ * const disposable = univerAPI.addEvent(univerAPI.Event.BeforeSheetLinkUpdate, (params) => {
48
+ * const { workbook, worksheet, row, column, id, payload } = params;
49
+ * console.log('before sheet link update', params);
50
+ *
51
+ * // Cancel the sheet link update operation
52
+ * params.cancel = true;
40
53
  * });
54
+ *
55
+ * // Remove the event listener, use `disposable.dispose()`
41
56
  * ```
42
57
  */
43
58
  readonly BeforeSheetLinkUpdate: 'BeforeSheetLinkUpdate';
@@ -12,22 +12,85 @@ export interface ICellHyperLink {
12
12
  export interface IFRangeHyperlinkMixin {
13
13
  /**
14
14
  * @deprecated use `range.setRichTextValueForCell(univerAPI.newRichText().insertLink(label, url))` instead
15
+ * @example
16
+ * ```ts
17
+ * const fWorkbook = univerAPI.getActiveWorkbook();
18
+ * const fWorksheet = fWorkbook.getActiveSheet();
19
+ * const fRange = fWorksheet.getRange('A1');
20
+ * const richText = univerAPI.newRichText().insertLink('Univer', 'https://univer.ai/');
21
+ * fRange.setRichTextValueForCell(richText);
22
+ * ```
15
23
  */
16
24
  setHyperLink(url: string, label?: string): Promise<boolean>;
17
25
  /**
18
26
  * @deprecated use `range.setRichTextValueForCell(range.getValue(true).getLinks())` instead
27
+ * @example
28
+ * ```ts
29
+ * const fWorkbook = univerAPI.getActiveWorkbook();
30
+ * const fWorksheet = fWorkbook.getActiveSheet();
31
+ * const fRange = fWorksheet.getRange('A1');
32
+ * const richText = univerAPI.newRichText().insertLink('Univer', 'https://univer.ai/');
33
+ * fRange.setRichTextValueForCell(richText);
34
+ *
35
+ * // Get hyperlinks
36
+ * console.log(fRange.getValue(true).getLinks());
37
+ * ```
19
38
  */
20
39
  getHyperLinks(): ICellHyperLink[];
21
40
  /**
22
41
  * @deprecated use `range.setRichTextValueForCell(range.getValue(true).copy().updateLink(id, url))` instead
42
+ * @example
43
+ * ```ts
44
+ * const fWorkbook = univerAPI.getActiveWorkbook();
45
+ * const fWorksheet = fWorkbook.getActiveSheet();
46
+ * const fRange = fWorksheet.getRange('A1');
47
+ * const richText = univerAPI.newRichText().insertLink('Univer', 'https://univer.ai/');
48
+ * fRange.setRichTextValueForCell(richText);
49
+ *
50
+ * // Update hyperlink after 3 seconds
51
+ * setTimeout(() => {
52
+ * const cellValue = fRange.getValue(true);
53
+ * const hyperlinks = cellValue.getLinks();
54
+ * const id = hyperlinks[0].rangeId;
55
+ * const newUrl = 'https://go.univer.ai/';
56
+ * const newRichText = cellValue.copy().updateLink(id, newUrl);
57
+ * fRange.setRichTextValueForCell(newRichText);
58
+ * }, 3000);
59
+ * ```
23
60
  */
24
61
  updateHyperLink(id: string, url: string, label?: string): Promise<boolean>;
25
62
  /**
26
63
  * @deprecated use `range.setRichTextValueForCell(range.getValue(true).copy().cancelLink(id))` instead
64
+ * @example
65
+ * ```ts
66
+ * const fWorkbook = univerAPI.getActiveWorkbook();
67
+ * const fWorksheet = fWorkbook.getActiveSheet();
68
+ * const fRange = fWorksheet.getRange('A1');
69
+ * const richText = univerAPI.newRichText().insertLink('Univer', 'https://univer.ai/');
70
+ * fRange.setRichTextValueForCell(richText);
71
+ *
72
+ * // Cancel hyperlink after 3 seconds
73
+ * setTimeout(() => {
74
+ * const cellValue = fRange.getValue(true);
75
+ * const hyperlinks = cellValue.getLinks();
76
+ * const id = hyperlinks[0].rangeId;
77
+ * const newRichText = cellValue.copy().cancelLink(id);
78
+ * fRange.setRichTextValueForCell(newRichText);
79
+ * }, 3000);
80
+ * ```
27
81
  */
28
82
  cancelHyperLink(id: string): boolean;
29
83
  /**
30
- * Get the url of this range.
84
+ * Create a hyperlink url to this range
85
+ * @returns {string} The url of this range
86
+ * @example
87
+ * ```ts
88
+ * const fWorkbook = univerAPI.getActiveWorkbook();
89
+ * const fWorksheet = fWorkbook.getActiveSheet();
90
+ * const fRange = fWorksheet.getRange('A1');
91
+ * const url = fRange.getUrl();
92
+ * console.log(url);
93
+ * ```
31
94
  */
32
95
  getUrl(): string;
33
96
  }
@@ -1,6 +1,6 @@
1
+ import { IRange } from '@univerjs/core';
1
2
  import { ISheetHyperLinkInfo, SheetsHyperLinkParserService } from '@univerjs/sheets-hyper-link';
2
3
  import { FRange, FWorkbook } from '@univerjs/sheets/facade';
3
- import { IRange } from '@univerjs/core';
4
4
  /**
5
5
  * @hideconstructor
6
6
  */
@@ -20,11 +20,19 @@ export interface IFWorkbookHyperlinkMixin {
20
20
  createSheetHyperlink(this: FWorkbook, sheetId: string, range?: string | IRange): string;
21
21
  /**
22
22
  * Parse the hyperlink string to get the hyperlink info.
23
- * @param hyperlink the hyperlink string
24
- * @returns the hyperlink info
23
+ * @param {string} hyperlink - The hyperlink string.
24
+ * @returns {ISheetHyperLinkInfo} The hyperlink info.
25
25
  * @example
26
26
  * ``` ts
27
- * univerAPI.getActiveWorkbook().parseSheetHyperlink('#gid=sheet_Id&range=F6')
27
+ * // Create a hyperlink to the range A1:D10 of the current sheet
28
+ * const fWorkbook = univerAPI.getActiveWorkbook();
29
+ * const fWorksheet = fWorkbook.getActiveSheet();
30
+ * const fRange = fWorksheet.getRange('A1:D10');
31
+ * const hyperlink = fRange.getUrl();
32
+ *
33
+ * // Parse the hyperlink
34
+ * const hyperlinkInfo = fWorkbook.parseSheetHyperlink(hyperlink);
35
+ * console.log(hyperlinkInfo);
28
36
  * ```
29
37
  */
30
38
  parseSheetHyperlink(this: FWorkbook, hyperlink: string): ISheetHyperLinkInfo;
@@ -4,7 +4,15 @@ import { FWorksheet } from '@univerjs/sheets/facade';
4
4
  */
5
5
  export interface IFWorksheetHyperlinkMixin {
6
6
  /**
7
- * Get the url of this sheet
7
+ * Create a hyperlink url to this sheet
8
+ * @returns {string} The url of this sheet
9
+ * @example
10
+ * ```ts
11
+ * const fWorkbook = univerAPI.getActiveWorkbook();
12
+ * const fWorksheet = fWorkbook.getActiveSheet();
13
+ * const url = fWorksheet.getUrl();
14
+ * console.log(url);
15
+ * ```
8
16
  */
9
17
  getUrl(): string;
10
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-hyper-link",
3
- "version": "0.6.0",
3
+ "version": "0.6.1",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -52,17 +52,17 @@
52
52
  },
53
53
  "dependencies": {
54
54
  "@univerjs/protocol": "0.1.43",
55
- "@univerjs/engine-formula": "0.6.0",
56
- "@univerjs/core": "0.6.0",
57
- "@univerjs/sheets": "0.6.0",
58
- "@univerjs/docs": "0.6.0"
55
+ "@univerjs/core": "0.6.1",
56
+ "@univerjs/docs": "0.6.1",
57
+ "@univerjs/engine-formula": "0.6.1",
58
+ "@univerjs/sheets": "0.6.1"
59
59
  },
60
60
  "devDependencies": {
61
61
  "rxjs": "^7.8.1",
62
62
  "typescript": "^5.7.3",
63
- "vite": "^6.1.0",
64
- "vitest": "^3.0.5",
65
- "@univerjs-infra/shared": "0.6.0"
63
+ "vite": "^6.1.1",
64
+ "vitest": "^3.0.6",
65
+ "@univerjs-infra/shared": "0.6.1"
66
66
  },
67
67
  "scripts": {
68
68
  "test": "vitest run",