@univerjs/sheets-hyper-link 0.6.7 → 0.6.9

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.
Files changed (3) hide show
  1. package/lib/facade.js +174 -0
  2. package/lib/index.js +1277 -0
  3. package/package.json +6 -6
package/lib/facade.js ADDED
@@ -0,0 +1,174 @@
1
+ import { Inject as L, generateRandomId as f, CustomRangeType as C, DataStreamTreeTokenType as p, ICommandService as b, CanceledError as d } from "@univerjs/core";
2
+ import { SheetsHyperLinkParserService as a, AddHyperLinkCommand as u, UpdateHyperLinkCommand as g, CancelHyperLinkCommand as S } from "@univerjs/sheets-hyper-link";
3
+ import { FWorkbook as v, FWorksheet as w, FRange as _ } from "@univerjs/sheets/facade";
4
+ import { FEventName as x, FUniver as y } from "@univerjs/core/facade";
5
+ var I = Object.getOwnPropertyDescriptor, E = (s, e, i, r) => {
6
+ for (var n = r > 1 ? void 0 : r ? I(e, i) : e, t = s.length - 1, o; t >= 0; t--)
7
+ (o = s[t]) && (n = o(n) || n);
8
+ return n;
9
+ }, H = (s, e) => (i, r) => e(i, r, s);
10
+ let m = class {
11
+ constructor(s, e) {
12
+ this._workbook = s, this._parserService = e;
13
+ }
14
+ getRangeUrl(s) {
15
+ return this._parserService.buildHyperLink(this._workbook.getId(), s.getSheetId(), s.getRange()), this;
16
+ }
17
+ };
18
+ m = E([
19
+ H(1, L(a))
20
+ ], m);
21
+ class U extends v {
22
+ createSheetHyperlink(e, i) {
23
+ return this._injector.get(a).buildHyperLink(this.getId(), e, i);
24
+ }
25
+ /**
26
+ * Parse the hyperlink string to get the hyperlink info.
27
+ * @param {string} hyperlink the hyperlink string
28
+ * @returns {ISheetHyperLinkInfo} the hyperlink info
29
+ */
30
+ parseSheetHyperlink(e) {
31
+ return this._injector.get(a).parseHyperLink(e);
32
+ }
33
+ }
34
+ v.extend(U);
35
+ class R extends w {
36
+ getUrl() {
37
+ return this._injector.get(a).buildHyperLink(this._workbook.getUnitId(), this._worksheet.getSheetId());
38
+ }
39
+ }
40
+ w.extend(R);
41
+ class T extends _ {
42
+ // #region hyperlink
43
+ setHyperLink(e, i) {
44
+ const r = {
45
+ unitId: this.getUnitId(),
46
+ subUnitId: this._worksheet.getSheetId(),
47
+ link: {
48
+ row: this._range.startRow,
49
+ column: this._range.startColumn,
50
+ payload: e,
51
+ display: i,
52
+ id: f()
53
+ }
54
+ };
55
+ return this._commandService.executeCommand(u.id, r);
56
+ }
57
+ getHyperLinks() {
58
+ var i, r, n;
59
+ const e = this._worksheet.getCellRaw(this._range.startRow, this._range.startColumn);
60
+ return e != null && e.p ? (n = (r = (i = e.p.body) == null ? void 0 : i.customRanges) == null ? void 0 : r.filter((t) => t.rangeType === C.HYPERLINK).map((t) => {
61
+ var o, h, c, l, k;
62
+ return {
63
+ id: `${t.rangeId}`,
64
+ startIndex: t.startIndex,
65
+ endIndex: t.endIndex,
66
+ url: (h = (o = t.properties) == null ? void 0 : o.url) != null ? h : "",
67
+ label: (k = (l = (c = e.p) == null ? void 0 : c.body) == null ? void 0 : l.dataStream.slice(t.startIndex, t.endIndex + 1).replaceAll(p.CUSTOM_RANGE_START, "").replaceAll(p.CUSTOM_RANGE_END, "")) != null ? k : ""
68
+ };
69
+ })) != null ? n : [] : [];
70
+ }
71
+ updateHyperLink(e, i, r) {
72
+ const n = {
73
+ unitId: this.getUnitId(),
74
+ subUnitId: this._worksheet.getSheetId(),
75
+ row: this._range.startRow,
76
+ column: this._range.startColumn,
77
+ id: e,
78
+ payload: {
79
+ payload: i,
80
+ display: r
81
+ }
82
+ };
83
+ return this._commandService.executeCommand(g.id, n);
84
+ }
85
+ cancelHyperLink(e) {
86
+ const i = {
87
+ unitId: this.getUnitId(),
88
+ subUnitId: this._worksheet.getSheetId(),
89
+ row: this._range.startRow,
90
+ column: this._range.startColumn,
91
+ id: e
92
+ };
93
+ return this._commandService.syncExecuteCommand(S.id, i);
94
+ }
95
+ getUrl() {
96
+ return this._injector.get(a).buildHyperLink(this.getUnitId(), this.getSheetId(), this.getRange());
97
+ }
98
+ // #endregion
99
+ }
100
+ _.extend(T);
101
+ class B {
102
+ get BeforeSheetLinkAdd() {
103
+ return "BeforeSheetLinkAdd";
104
+ }
105
+ get BeforeSheetLinkCancel() {
106
+ return "BeforeSheetLinkCancel";
107
+ }
108
+ get BeforeSheetLinkUpdate() {
109
+ return "BeforeSheetLinkUpdate";
110
+ }
111
+ }
112
+ x.extend(B);
113
+ class A extends y {
114
+ /**
115
+ * @ignore
116
+ */
117
+ _initialize(e) {
118
+ const i = e.get(b);
119
+ this.registerEventHandler(
120
+ this.Event.BeforeSheetLinkAdd,
121
+ () => i.beforeCommandExecuted((r) => {
122
+ if (r.id !== u.id) return;
123
+ const n = this.getCommandSheetTarget(r);
124
+ if (!n) return;
125
+ const t = r.params, o = {
126
+ workbook: n.workbook,
127
+ worksheet: n.worksheet,
128
+ row: t.link.row,
129
+ col: t.link.column,
130
+ link: t.link
131
+ };
132
+ if (this.fireEvent(this.Event.BeforeSheetLinkAdd, o), o.cancel)
133
+ throw new d();
134
+ })
135
+ ), this.registerEventHandler(
136
+ this.Event.BeforeSheetLinkUpdate,
137
+ () => i.beforeCommandExecuted((r) => {
138
+ if (r.id !== g.id) return;
139
+ const n = this.getCommandSheetTarget(r);
140
+ if (!n) return;
141
+ const t = r.params, o = {
142
+ workbook: n.workbook,
143
+ worksheet: n.worksheet,
144
+ row: t.row,
145
+ column: t.column,
146
+ id: t.id,
147
+ payload: t.payload
148
+ };
149
+ if (this.fireEvent(this.Event.BeforeSheetLinkUpdate, o), o.cancel)
150
+ throw new d();
151
+ })
152
+ ), this.registerEventHandler(
153
+ this.Event.BeforeSheetLinkCancel,
154
+ () => i.beforeCommandExecuted((r) => {
155
+ if (r.id !== S.id) return;
156
+ const n = this.getCommandSheetTarget(r);
157
+ if (!n) return;
158
+ const t = r.params, o = {
159
+ workbook: n.workbook,
160
+ worksheet: n.worksheet,
161
+ row: t.row,
162
+ column: t.column,
163
+ id: t.id
164
+ };
165
+ if (this.fireEvent(this.Event.BeforeSheetLinkCancel, o), o.cancel)
166
+ throw new d();
167
+ })
168
+ );
169
+ }
170
+ }
171
+ y.extend(A);
172
+ export {
173
+ U as FWorkbookHyperLinkMixin
174
+ };