@univerjs/docs-hyper-link-ui 0.5.4 → 0.5.5-experimental.20250123-34738ff

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/es/index.js CHANGED
@@ -1,441 +1,422 @@
1
- var Ke = Object.defineProperty;
2
- var Fe = (n, e, t) => e in n ? Ke(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var P = (n, e, t) => Fe(n, typeof e != "symbol" ? e + "" : e, t);
4
- import { CommandType as E, ICommandService as x, generateRandomId as Ve, CustomRangeType as D, IUniverInstanceService as O, UniverInstanceType as I, getBodySlice as Pe, useDependency as S, LocaleService as Re, useObservable as Ye, Tools as Ze, BuildTextUtils as _e, Disposable as N, Inject as v, DOCS_ZEN_EDITOR_UNIT_ID_KEY as We, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as Ge, DependentOn as qe, Injector as Je, Plugin as ze, merge as Qe, IConfigService as Xe } from "@univerjs/core";
5
- import { UniverDocsHyperLinkPlugin as en } from "@univerjs/docs-hyper-link";
6
- import { IRenderManagerService as nn } from "@univerjs/engine-render";
7
- import { addCustomRangeBySelectionFactory as tn, DocSelectionManagerService as b, replaceSelectionFactory as rn, deleteCustomRangeFactory as on, SetTextSelectionsOperation as sn, DocSkeletonManagerService as cn, DocInterceptorService as dn, DOC_INTERCEPTOR_POINT as an } from "@univerjs/docs";
8
- import { DocCanvasPopManagerService as ln, DocEventManagerService as un, DocRenderController as pn, whenDocAndEditorFocused as fn } from "@univerjs/docs-ui";
9
- import { BehaviorSubject as ve, distinctUntilChanged as gn, pairwise as hn, Observable as mn, debounceTime as _n } from "rxjs";
10
- import vn, { useState as J, useEffect as In, forwardRef as j, useRef as Cn, createElement as U } from "react";
11
- import { FormLayout as Ie, Input as Ce, Button as Se, Tooltip as B, MessageType as Sn } from "@univerjs/design";
12
- import { KeyCode as te, IMessageService as Ln, useObservable as yn, MetaKeys as kn, MenuItemType as xn, getMenuHiddenObservable as On, RibbonStartGroup as Pn, ContextMenuPosition as Rn, ContextMenuGroup as En, ComponentManager as bn, IMenuManagerService as Mn, IShortcutService as wn } from "@univerjs/ui";
13
- const Dn = "docs-hyper-link-ui.config", Le = {};
14
- var z = { exports: {} }, M = {};
15
- /**
16
- * @license React
17
- * react-jsx-runtime.production.min.js
18
- *
19
- * Copyright (c) Facebook, Inc. and its affiliates.
20
- *
21
- * This source code is licensed under the MIT license found in the
22
- * LICENSE file in the root directory of this source tree.
23
- */
24
- var ye;
25
- function Nn() {
26
- if (ye) return M;
27
- ye = 1;
28
- var n = vn, e = Symbol.for("react.element"), t = Symbol.for("react.fragment"), i = Object.prototype.hasOwnProperty, r = n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, o = { key: !0, ref: !0, __self: !0, __source: !0 };
29
- function s(c, d, p) {
30
- var l, h = {}, f = null, a = null;
31
- p !== void 0 && (f = "" + p), d.key !== void 0 && (f = "" + d.key), d.ref !== void 0 && (a = d.ref);
32
- for (l in d) i.call(d, l) && !o.hasOwnProperty(l) && (h[l] = d[l]);
33
- if (c && c.defaultProps) for (l in d = c.defaultProps, d) h[l] === void 0 && (h[l] = d[l]);
34
- return { $$typeof: e, type: c, key: f, ref: a, props: h, _owner: r.current };
35
- }
36
- return M.Fragment = t, M.jsx = s, M.jsxs = s, M;
37
- }
38
- var ke;
39
- function jn() {
40
- return ke || (ke = 1, z.exports = Nn()), z.exports;
41
- }
42
- var u = jn();
43
- const Ee = {
44
- type: E.COMMAND,
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
+ import { CommandType, ICommandService, generateRandomId, CustomRangeType, IUniverInstanceService, UniverInstanceType, getBodySlice, useDependency, LocaleService, useObservable, Tools, BuildTextUtils, Disposable, Inject, DOCS_ZEN_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DependentOn, Injector, Plugin, merge, IConfigService } from "@univerjs/core";
6
+ import { UniverDocsHyperLinkPlugin } from "@univerjs/docs-hyper-link";
7
+ import { IRenderManagerService } from "@univerjs/engine-render";
8
+ import { addCustomRangeBySelectionFactory, DocSelectionManagerService, replaceSelectionFactory, deleteCustomRangeFactory, SetTextSelectionsOperation, DocSkeletonManagerService, DocInterceptorService, DOC_INTERCEPTOR_POINT } from "@univerjs/docs";
9
+ import { DocCanvasPopManagerService, DocEventManagerService, DocRenderController, whenDocAndEditorFocused } from "@univerjs/docs-ui";
10
+ import { BehaviorSubject, distinctUntilChanged, pairwise, Observable, debounceTime } from "rxjs";
11
+ import { jsxs, jsx } from "react/jsx-runtime";
12
+ import { FormLayout, Input, Button, Tooltip, MessageType } from "@univerjs/design";
13
+ import { KeyCode, IMessageService, useObservable as useObservable$1, MetaKeys, MenuItemType, getMenuHiddenObservable, RibbonStartGroup, ContextMenuPosition, ContextMenuGroup, ComponentManager, IMenuManagerService, IShortcutService } from "@univerjs/ui";
14
+ import { useState, useEffect, forwardRef, useRef, createElement } from "react";
15
+ const DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY = "docs-hyper-link-ui.config", defaultPluginConfig = {}, AddDocHyperLinkCommand = {
16
+ type: CommandType.COMMAND,
45
17
  id: "docs.command.add-hyper-link",
46
- async handler(n, e) {
47
- if (!e)
18
+ async handler(accessor, params) {
19
+ if (!params)
48
20
  return !1;
49
- const { payload: t, unitId: i, selections: r } = e, o = n.get(x), s = Ve(), c = tn(
50
- n,
21
+ const { payload, unitId, selections } = params, commandService = accessor.get(ICommandService), id = generateRandomId(), doMutation = addCustomRangeBySelectionFactory(
22
+ accessor,
51
23
  {
52
- rangeId: s,
53
- rangeType: D.HYPERLINK,
24
+ rangeId: id,
25
+ rangeType: CustomRangeType.HYPERLINK,
54
26
  properties: {
55
- url: t
27
+ url: payload
56
28
  },
57
- unitId: i,
58
- selections: r
29
+ unitId,
30
+ selections
59
31
  }
60
32
  );
61
- return c ? o.syncExecuteCommand(c.id, c.params) : !1;
33
+ return doMutation ? commandService.syncExecuteCommand(doMutation.id, doMutation.params) : !1;
62
34
  }
63
- }, be = {
35
+ }, UpdateDocHyperLinkCommand = {
64
36
  id: "docs.command.update-hyper-link",
65
- type: E.COMMAND,
66
- handler(n, e) {
67
- var m;
68
- if (!e)
37
+ type: CommandType.COMMAND,
38
+ handler(accessor, params) {
39
+ var _a7;
40
+ if (!params)
69
41
  return !1;
70
- const { unitId: t, payload: i, segmentId: r, linkId: o } = e, s = n.get(x), c = n.get(O), p = n.get(b).getActiveTextRange(), l = c.getUnit(t, I.UNIVER_DOC);
71
- if (!p || !l)
42
+ const { unitId, payload, segmentId, linkId } = params, commandService = accessor.get(ICommandService), univerInstanceService = accessor.get(IUniverInstanceService), currentSelection = accessor.get(DocSelectionManagerService).getActiveTextRange(), doc = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
43
+ if (!currentSelection || !doc)
72
44
  return !1;
73
- const f = (m = Pe(l.getSelfOrHeaderFooterModel(r).getBody(), p.startOffset, p.endOffset).textRuns) == null ? void 0 : m[0];
74
- f && (f.ed = e.label.length + 1);
75
- const a = rn(n, {
76
- unitId: t,
45
+ const textRun = (_a7 = getBodySlice(doc.getSelfOrHeaderFooterModel(segmentId).getBody(), currentSelection.startOffset, currentSelection.endOffset).textRuns) == null ? void 0 : _a7[0];
46
+ textRun && (textRun.ed = params.label.length + 1);
47
+ const replaceSelection = replaceSelectionFactory(accessor, {
48
+ unitId,
77
49
  body: {
78
- dataStream: `${e.label}`,
50
+ dataStream: `${params.label}`,
79
51
  customRanges: [{
80
- rangeId: o,
81
- rangeType: D.HYPERLINK,
52
+ rangeId: linkId,
53
+ rangeType: CustomRangeType.HYPERLINK,
82
54
  startIndex: 0,
83
- endIndex: e.label.length + 1,
55
+ endIndex: params.label.length + 1,
84
56
  properties: {
85
- url: i
57
+ url: payload
86
58
  }
87
59
  }],
88
- textRuns: f ? [f] : void 0
60
+ textRuns: textRun ? [textRun] : void 0
89
61
  },
90
62
  selection: {
91
- startOffset: p.startOffset,
92
- endOffset: p.endOffset,
63
+ startOffset: currentSelection.startOffset,
64
+ endOffset: currentSelection.endOffset,
93
65
  collapsed: !1,
94
- segmentId: r
66
+ segmentId
95
67
  }
96
68
  });
97
- return a ? s.syncExecuteCommand(a.id, a.params) : !1;
98
- }
99
- }, Un = "univer-docs-link-edit", $n = "univer-docs-link-edit-title", Tn = "univer-docs-link-edit-close", Hn = "univer-docs-link-edit-buttons", An = "univer-docs-link-edit-button", K = {
100
- docsLinkEdit: Un,
101
- docsLinkEditTitle: $n,
102
- docsLinkEditClose: Tn,
103
- docsLinkEditButtons: Hn,
104
- docsLinkEditButton: An
69
+ return replaceSelection ? commandService.syncExecuteCommand(replaceSelection.id, replaceSelection.params) : !1;
70
+ }
71
+ }, docsLinkEdit = "univer-docs-link-edit", docsLinkEditTitle = "univer-docs-link-edit-title", docsLinkEditClose = "univer-docs-link-edit-close", docsLinkEditButtons = "univer-docs-link-edit-buttons", docsLinkEditButton = "univer-docs-link-edit-button", styles$1 = {
72
+ docsLinkEdit,
73
+ docsLinkEditTitle,
74
+ docsLinkEditClose,
75
+ docsLinkEditButtons,
76
+ docsLinkEditButton
105
77
  };
106
- function Bn(n) {
107
- return /^[a-zA-Z]+:\/\//.test(n);
78
+ function hasProtocol(urlString) {
79
+ return /^[a-zA-Z]+:\/\//.test(urlString);
108
80
  }
109
- function Kn(n) {
110
- return /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(n);
81
+ __name(hasProtocol, "hasProtocol");
82
+ function isEmail(url) {
83
+ return /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(url);
111
84
  }
112
- function Fn(n) {
113
- return Bn(n) ? n : Kn(n) ? `mailto://${n}` : `https://${n}`;
85
+ __name(isEmail, "isEmail");
86
+ function transformUrl(urlStr) {
87
+ return hasProtocol(urlStr) ? urlStr : isEmail(urlStr) ? `mailto://${urlStr}` : `https://${urlStr}`;
114
88
  }
115
- const V = () => {
116
- const n = S(L), e = S(Re), t = Ye(n.editingLink$), i = S(x), r = S(O), o = S(b), [s, c] = J(""), [d, p] = J(""), [l, h] = J(!1), f = Ze.isLegalUrl(s), a = t ? r.getUnit(t.unitId, I.UNIVER_DOC) : r.getCurrentUnitForType(I.UNIVER_DOC);
117
- In(() => {
118
- var de, ae, le, ue, pe, fe, ge, he, me;
119
- const g = o.getActiveTextRange();
120
- if (!g)
89
+ __name(transformUrl, "transformUrl");
90
+ const DocHyperLinkEdit = /* @__PURE__ */ __name(() => {
91
+ const hyperLinkService = useDependency(DocHyperLinkPopupService), localeService = useDependency(LocaleService), editing = useObservable(hyperLinkService.editingLink$), commandService = useDependency(ICommandService), univerInstanceService = useDependency(IUniverInstanceService), docSelectionManagerService = useDependency(DocSelectionManagerService), [link, setLink] = useState(""), [label, setLabel] = useState(""), [showError, setShowError] = useState(!1), isLegal = Tools.isLegalUrl(link), doc = editing ? univerInstanceService.getUnit(editing.unitId, UniverInstanceType.UNIVER_DOC) : univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
92
+ useEffect(() => {
93
+ var _a7, _b, _c, _d, _e, _f, _g, _h, _i;
94
+ const activeRange = docSelectionManagerService.getActiveTextRange();
95
+ if (!activeRange)
121
96
  return;
122
- if (t) {
123
- const H = (de = a == null ? void 0 : a.getSelfOrHeaderFooterModel(t.segmentId)) == null ? void 0 : de.getBody(), A = (ae = H == null ? void 0 : H.customRanges) == null ? void 0 : ae.find((q) => (t == null ? void 0 : t.linkId) === q.rangeId && q.startIndex === t.startIndex && q.endIndex === t.endIndex);
124
- a && A && (c((ue = (le = A.properties) == null ? void 0 : le.url) != null ? ue : ""), p(_e.transform.getPlainText(Pe(H, A.startIndex, A.endIndex + 1).dataStream)));
97
+ if (editing) {
98
+ const body2 = (_a7 = doc == null ? void 0 : doc.getSelfOrHeaderFooterModel(editing.segmentId)) == null ? void 0 : _a7.getBody(), matchedRange2 = (_b = body2 == null ? void 0 : body2.customRanges) == null ? void 0 : _b.find((i) => (editing == null ? void 0 : editing.linkId) === i.rangeId && i.startIndex === editing.startIndex && i.endIndex === editing.endIndex);
99
+ doc && matchedRange2 && (setLink((_d = (_c = matchedRange2.properties) == null ? void 0 : _c.url) != null ? _d : ""), setLabel(BuildTextUtils.transform.getPlainText(getBodySlice(body2, matchedRange2.startIndex, matchedRange2.endIndex + 1).dataStream)));
125
100
  return;
126
101
  }
127
- const y = (pe = a == null ? void 0 : a.getSelfOrHeaderFooterModel(g.segmentId)) == null ? void 0 : pe.getBody(), ce = y ? g : null, T = ce && ((ge = _e.customRange.getCustomRangesInterestsWithSelection(ce, (fe = y == null ? void 0 : y.customRanges) != null ? fe : [])) == null ? void 0 : ge[0]);
128
- a && T && c((me = (he = T == null ? void 0 : T.properties) == null ? void 0 : he.url) != null ? me : "");
129
- }, [a, t, o, r]);
130
- const m = () => {
131
- n.hideEditPopup();
132
- }, C = () => {
133
- if (h(!0), !f || !a)
102
+ const body = (_e = doc == null ? void 0 : doc.getSelfOrHeaderFooterModel(activeRange.segmentId)) == null ? void 0 : _e.getBody(), selection = body ? activeRange : null, matchedRange = selection && ((_g = BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(selection, (_f = body == null ? void 0 : body.customRanges) != null ? _f : [])) == null ? void 0 : _g[0]);
103
+ doc && matchedRange && setLink((_i = (_h = matchedRange == null ? void 0 : matchedRange.properties) == null ? void 0 : _h.url) != null ? _i : "");
104
+ }, [doc, editing, docSelectionManagerService, univerInstanceService]);
105
+ const handleCancel = /* @__PURE__ */ __name(() => {
106
+ hyperLinkService.hideEditPopup();
107
+ }, "handleCancel"), handleConfirm = /* @__PURE__ */ __name(() => {
108
+ if (setShowError(!0), !isLegal || !doc)
134
109
  return;
135
- const g = Fn(s);
136
- if (!t)
137
- i.executeCommand(Ee.id, {
138
- unitId: a.getUnitId(),
139
- payload: g
110
+ const linkFinal = transformUrl(link);
111
+ if (!editing)
112
+ commandService.executeCommand(AddDocHyperLinkCommand.id, {
113
+ unitId: doc.getUnitId(),
114
+ payload: linkFinal
140
115
  });
141
116
  else {
142
- if (!d)
117
+ if (!label)
143
118
  return;
144
- i.executeCommand(be.id, {
145
- unitId: a.getUnitId(),
146
- payload: g,
147
- linkId: t.linkId,
148
- label: d,
149
- segmentId: t.segmentId
119
+ commandService.executeCommand(UpdateDocHyperLinkCommand.id, {
120
+ unitId: doc.getUnitId(),
121
+ payload: linkFinal,
122
+ linkId: editing.linkId,
123
+ label,
124
+ segmentId: editing.segmentId
150
125
  });
151
126
  }
152
- n.hideEditPopup();
153
- };
154
- if (a)
155
- return /* @__PURE__ */ u.jsxs("div", { className: K.docsLinkEdit, children: [
156
- /* @__PURE__ */ u.jsxs("div", { children: [
157
- t ? /* @__PURE__ */ u.jsx(
158
- Ie,
127
+ hyperLinkService.hideEditPopup();
128
+ }, "handleConfirm");
129
+ if (doc)
130
+ return /* @__PURE__ */ jsxs("div", { className: styles$1.docsLinkEdit, children: [
131
+ /* @__PURE__ */ jsxs("div", { children: [
132
+ editing ? /* @__PURE__ */ jsx(
133
+ FormLayout,
159
134
  {
160
- label: e.t("docLink.edit.label"),
161
- error: l && !d ? e.t("docLink.edit.labelError") : "",
162
- children: /* @__PURE__ */ u.jsx(
163
- Ce,
135
+ label: localeService.t("docLink.edit.label"),
136
+ error: showError && !label ? localeService.t("docLink.edit.labelError") : "",
137
+ children: /* @__PURE__ */ jsx(
138
+ Input,
164
139
  {
165
- value: d,
166
- onChange: p,
140
+ value: label,
141
+ onChange: setLabel,
167
142
  autoFocus: !0,
168
- onKeyDown: (g) => {
169
- g.keyCode === te.ENTER && C();
170
- }
143
+ onKeyDown: /* @__PURE__ */ __name((evt) => {
144
+ evt.keyCode === KeyCode.ENTER && handleConfirm();
145
+ }, "onKeyDown")
171
146
  }
172
147
  )
173
148
  }
174
149
  ) : null,
175
- /* @__PURE__ */ u.jsx(
176
- Ie,
150
+ /* @__PURE__ */ jsx(
151
+ FormLayout,
177
152
  {
178
- label: e.t("docLink.edit.address"),
179
- error: l && !f ? e.t("docLink.edit.addressError") : "",
180
- children: /* @__PURE__ */ u.jsx(
181
- Ce,
153
+ label: localeService.t("docLink.edit.address"),
154
+ error: showError && !isLegal ? localeService.t("docLink.edit.addressError") : "",
155
+ children: /* @__PURE__ */ jsx(
156
+ Input,
182
157
  {
183
- value: s,
184
- onChange: c,
158
+ value: link,
159
+ onChange: setLink,
185
160
  autoFocus: !0,
186
- onKeyDown: (g) => {
187
- g.keyCode === te.ENTER && C();
188
- }
161
+ onKeyDown: /* @__PURE__ */ __name((evt) => {
162
+ evt.keyCode === KeyCode.ENTER && handleConfirm();
163
+ }, "onKeyDown")
189
164
  }
190
165
  )
191
166
  }
192
167
  )
193
168
  ] }),
194
- /* @__PURE__ */ u.jsxs("div", { className: K.docsLinkEditButtons, children: [
195
- /* @__PURE__ */ u.jsx(
196
- Se,
169
+ /* @__PURE__ */ jsxs("div", { className: styles$1.docsLinkEditButtons, children: [
170
+ /* @__PURE__ */ jsx(
171
+ Button,
197
172
  {
198
- className: K.docsLinkEditButton,
199
- onClick: m,
200
- children: e.t("docLink.edit.cancel")
173
+ className: styles$1.docsLinkEditButton,
174
+ onClick: handleCancel,
175
+ children: localeService.t("docLink.edit.cancel")
201
176
  }
202
177
  ),
203
- /* @__PURE__ */ u.jsx(
204
- Se,
178
+ /* @__PURE__ */ jsx(
179
+ Button,
205
180
  {
206
- disabled: !s,
207
- className: K.docsLinkEditButton,
181
+ disabled: !link,
182
+ className: styles$1.docsLinkEditButton,
208
183
  type: "primary",
209
- onClick: C,
210
- children: e.t("docLink.edit.confirm")
184
+ onClick: handleConfirm,
185
+ children: localeService.t("docLink.edit.confirm")
211
186
  }
212
187
  )
213
188
  ] })
214
189
  ] });
215
- };
216
- V.componentKey = "docs-hyper-link-edit";
217
- var _ = function() {
218
- return _ = Object.assign || function(n) {
219
- for (var e, t = 1, i = arguments.length; t < i; t++) {
220
- e = arguments[t];
221
- for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && (n[r] = e[r]);
190
+ }, "DocHyperLinkEdit");
191
+ DocHyperLinkEdit.componentKey = "docs-hyper-link-edit";
192
+ var __assign = function() {
193
+ return __assign = Object.assign || function(t) {
194
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
195
+ s = arguments[i];
196
+ for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && (t[p] = s[p]);
222
197
  }
223
- return n;
224
- }, _.apply(this, arguments);
225
- }, Vn = function(n, e) {
198
+ return t;
199
+ }, __assign.apply(this, arguments);
200
+ }, __rest = function(s, e) {
226
201
  var t = {};
227
- for (var i in n) Object.prototype.hasOwnProperty.call(n, i) && e.indexOf(i) < 0 && (t[i] = n[i]);
228
- if (n != null && typeof Object.getOwnPropertySymbols == "function")
229
- for (var r = 0, i = Object.getOwnPropertySymbols(n); r < i.length; r++)
230
- e.indexOf(i[r]) < 0 && Object.prototype.propertyIsEnumerable.call(n, i[r]) && (t[i[r]] = n[i[r]]);
202
+ for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0 && (t[p] = s[p]);
203
+ if (s != null && typeof Object.getOwnPropertySymbols == "function")
204
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++)
205
+ e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]) && (t[p[i]] = s[p[i]]);
231
206
  return t;
232
- }, $ = j(function(n, e) {
233
- var t = n.icon, i = n.id, r = n.className, o = n.extend, s = Vn(n, ["icon", "id", "className", "extend"]), c = "univerjs-icon univerjs-icon-".concat(i, " ").concat(r || "").trim(), d = Cn("_".concat(Wn()));
234
- return Me(t, "".concat(i), { defIds: t.defIds, idSuffix: d.current }, _({ ref: e, className: c }, s), o);
207
+ }, IconBase = forwardRef(function(props, ref) {
208
+ var icon = props.icon, id = props.id, className = props.className, extend = props.extend, restProps = __rest(props, ["icon", "id", "className", "extend"]), cls = "univerjs-icon univerjs-icon-".concat(id, " ").concat(className || "").trim(), idSuffix = useRef("_".concat(generateShortUuid()));
209
+ return render(icon, "".concat(id), { defIds: icon.defIds, idSuffix: idSuffix.current }, __assign({ ref, className: cls }, restProps), extend);
235
210
  });
236
- function Me(n, e, t, i, r) {
237
- return U(n.tag, _(_({ key: e }, Yn(n, t, r)), i), (Zn(n, t).children || []).map(function(o, s) {
238
- return Me(o, "".concat(e, "-").concat(n.tag, "-").concat(s), t, void 0, r);
211
+ function render(node, id, runtimeProps, rootProps, extend) {
212
+ return createElement(node.tag, __assign(__assign({ key: id }, replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend)), rootProps), (replaceRuntimeIdsInDefs(node, runtimeProps).children || []).map(function(child, index) {
213
+ return render(child, "".concat(id, "-").concat(node.tag, "-").concat(index), runtimeProps, void 0, extend);
239
214
  }));
240
215
  }
241
- function Yn(n, e, t) {
242
- var i = _({}, n.attrs);
243
- t != null && t.colorChannel1 && i.fill === "colorChannel1" && (i.fill = t.colorChannel1);
244
- var r = e.defIds;
245
- return !r || r.length === 0 || (n.tag === "use" && i["xlink:href"] && (i["xlink:href"] = i["xlink:href"] + e.idSuffix), Object.entries(i).forEach(function(o) {
246
- var s = o[0], c = o[1];
247
- typeof c == "string" && (i[s] = c.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")")));
248
- })), i;
216
+ __name(render, "render");
217
+ function replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend) {
218
+ var attrs = __assign({}, node.attrs);
219
+ extend != null && extend.colorChannel1 && attrs.fill === "colorChannel1" && (attrs.fill = extend.colorChannel1);
220
+ var defIds = runtimeProps.defIds;
221
+ return !defIds || defIds.length === 0 || (node.tag === "use" && attrs["xlink:href"] && (attrs["xlink:href"] = attrs["xlink:href"] + runtimeProps.idSuffix), Object.entries(attrs).forEach(function(_a7) {
222
+ var key = _a7[0], value = _a7[1];
223
+ typeof value == "string" && (attrs[key] = value.replace(/url\(#(.*)\)/, "url(#$1".concat(runtimeProps.idSuffix, ")")));
224
+ })), attrs;
249
225
  }
250
- function Zn(n, e) {
251
- var t, i = e.defIds;
252
- return !i || i.length === 0 ? n : n.tag === "defs" && (!((t = n.children) === null || t === void 0) && t.length) ? _(_({}, n), { children: n.children.map(function(r) {
253
- return typeof r.attrs.id == "string" && i && i.indexOf(r.attrs.id) > -1 ? _(_({}, r), { attrs: _(_({}, r.attrs), { id: r.attrs.id + e.idSuffix }) }) : r;
254
- }) }) : n;
226
+ __name(replaceRuntimeIdsAndExtInAttrs, "replaceRuntimeIdsAndExtInAttrs");
227
+ function replaceRuntimeIdsInDefs(node, runtimeProps) {
228
+ var _a7, defIds = runtimeProps.defIds;
229
+ return !defIds || defIds.length === 0 ? node : node.tag === "defs" && (!((_a7 = node.children) === null || _a7 === void 0) && _a7.length) ? __assign(__assign({}, node), { children: node.children.map(function(child) {
230
+ return typeof child.attrs.id == "string" && defIds && defIds.indexOf(child.attrs.id) > -1 ? __assign(__assign({}, child), { attrs: __assign(__assign({}, child.attrs), { id: child.attrs.id + runtimeProps.idSuffix }) }) : child;
231
+ }) }) : node;
255
232
  }
256
- function Wn() {
233
+ __name(replaceRuntimeIdsInDefs, "replaceRuntimeIdsInDefs");
234
+ function generateShortUuid() {
257
235
  return Math.random().toString(36).substring(2, 8);
258
236
  }
259
- $.displayName = "UniverIcon";
260
- var Gn = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M4.1302 12.4251C4.25802 13.7417 5.36779 14.7708 6.71792 14.7708H11.7179C13.1539 14.7708 14.3179 13.6067 14.3179 12.1708V6.1708C14.3179 4.78586 13.2351 3.65383 11.8698 3.57517C11.742 2.25858 10.6323 1.22949 9.28213 1.22949H4.28213C2.84619 1.22949 1.68213 2.39355 1.68213 3.82949V9.82949C1.68213 11.2144 2.76497 12.3465 4.1302 12.4251ZM10.6583 3.5708H6.71792C5.28198 3.5708 4.11792 4.73486 4.11792 6.1708V11.22C3.4221 11.1387 2.88213 10.5471 2.88213 9.82949V3.82949C2.88213 3.05629 3.50893 2.42949 4.28213 2.42949H9.28213C9.96695 2.42949 10.5369 2.92119 10.6583 3.5708ZM13.1179 6.1708C13.1179 5.3976 12.4911 4.7708 11.7179 4.7708H6.71792C5.94472 4.7708 5.31792 5.3976 5.31792 6.1708V12.1708C5.31792 12.944 5.94472 13.5708 6.71792 13.5708H11.7179C12.4911 13.5708 13.1179 12.944 13.1179 12.1708V6.1708Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, we = j(function(n, e) {
261
- return U($, Object.assign({}, n, {
237
+ __name(generateShortUuid, "generateShortUuid");
238
+ IconBase.displayName = "UniverIcon";
239
+ var element$3 = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M4.1302 12.4251C4.25802 13.7417 5.36779 14.7708 6.71792 14.7708H11.7179C13.1539 14.7708 14.3179 13.6067 14.3179 12.1708V6.1708C14.3179 4.78586 13.2351 3.65383 11.8698 3.57517C11.742 2.25858 10.6323 1.22949 9.28213 1.22949H4.28213C2.84619 1.22949 1.68213 2.39355 1.68213 3.82949V9.82949C1.68213 11.2144 2.76497 12.3465 4.1302 12.4251ZM10.6583 3.5708H6.71792C5.28198 3.5708 4.11792 4.73486 4.11792 6.1708V11.22C3.4221 11.1387 2.88213 10.5471 2.88213 9.82949V3.82949C2.88213 3.05629 3.50893 2.42949 4.28213 2.42949H9.28213C9.96695 2.42949 10.5369 2.92119 10.6583 3.5708ZM13.1179 6.1708C13.1179 5.3976 12.4911 4.7708 11.7179 4.7708H6.71792C5.94472 4.7708 5.31792 5.3976 5.31792 6.1708V12.1708C5.31792 12.944 5.94472 13.5708 6.71792 13.5708H11.7179C12.4911 13.5708 13.1179 12.944 13.1179 12.1708V6.1708Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, CopySingle = forwardRef(function(props, ref) {
240
+ return createElement(IconBase, Object.assign({}, props, {
262
241
  id: "copy-single",
263
- ref: e,
264
- icon: Gn
242
+ ref,
243
+ icon: element$3
265
244
  }));
266
245
  });
267
- we.displayName = "CopySingle";
268
- var qn = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M9.8816 1.97978C11.0177 0.843607 12.862 0.884962 14.0004 2.02342C15.1389 3.16188 15.1803 5.00612 14.0441 6.14228L11.399 8.78737C11.1608 9.02559 10.7746 9.02559 10.5363 8.78737C10.2981 8.54915 10.2981 8.16292 10.5363 7.9247L13.1814 5.2796C13.8195 4.64155 13.8217 3.57006 13.1378 2.8861C12.4538 2.20211 11.3823 2.20438 10.7443 2.84245L7.6976 5.88911L7.69317 5.89349C7.05959 6.53211 7.05894 7.60014 7.74132 8.28252C7.97954 8.52074 7.97954 8.90697 7.74132 9.14519C7.5031 9.38341 7.11687 9.38341 6.87865 9.14519C5.74016 8.00671 5.69884 6.16251 6.83497 5.02633L6.84021 5.02116L9.8816 1.97978Z" } }, { tag: "path", attrs: { fill: "currentColor", d: "M4.61426 7.2364C4.85248 6.99818 5.23871 6.99818 5.47693 7.2364C5.71515 7.47462 5.71515 7.86085 5.47693 8.09907L2.83183 10.7442C2.19375 11.3823 2.1915 12.4537 2.87547 13.1377C3.55945 13.8217 4.6309 13.8194 5.26899 13.1813L8.31566 10.1347C8.32262 10.1277 8.32971 10.121 8.33691 10.1144C8.34408 10.1064 8.3515 10.0986 8.35916 10.091C8.99721 9.45291 8.99949 8.38145 8.3155 7.69746C8.07728 7.45924 8.07728 7.07301 8.3155 6.83479C8.55372 6.59657 8.93995 6.59657 9.17817 6.83479C10.3166 7.97327 10.358 9.81748 9.22183 10.9536C9.21487 10.9606 9.20779 10.9673 9.20058 10.9739C9.19341 10.9819 9.18599 10.9897 9.17833 10.9973L6.13166 14.044C4.99548 15.1802 3.15127 15.1389 2.01279 14.0004C0.874362 12.8619 0.83297 11.0177 1.96916 9.8815L4.61426 7.2364Z" } }] }, se = j(function(n, e) {
269
- return U($, Object.assign({}, n, {
246
+ CopySingle.displayName = "CopySingle";
247
+ var element$2 = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M9.8816 1.97978C11.0177 0.843607 12.862 0.884962 14.0004 2.02342C15.1389 3.16188 15.1803 5.00612 14.0441 6.14228L11.399 8.78737C11.1608 9.02559 10.7746 9.02559 10.5363 8.78737C10.2981 8.54915 10.2981 8.16292 10.5363 7.9247L13.1814 5.2796C13.8195 4.64155 13.8217 3.57006 13.1378 2.8861C12.4538 2.20211 11.3823 2.20438 10.7443 2.84245L7.6976 5.88911L7.69317 5.89349C7.05959 6.53211 7.05894 7.60014 7.74132 8.28252C7.97954 8.52074 7.97954 8.90697 7.74132 9.14519C7.5031 9.38341 7.11687 9.38341 6.87865 9.14519C5.74016 8.00671 5.69884 6.16251 6.83497 5.02633L6.84021 5.02116L9.8816 1.97978Z" } }, { tag: "path", attrs: { fill: "currentColor", d: "M4.61426 7.2364C4.85248 6.99818 5.23871 6.99818 5.47693 7.2364C5.71515 7.47462 5.71515 7.86085 5.47693 8.09907L2.83183 10.7442C2.19375 11.3823 2.1915 12.4537 2.87547 13.1377C3.55945 13.8217 4.6309 13.8194 5.26899 13.1813L8.31566 10.1347C8.32262 10.1277 8.32971 10.121 8.33691 10.1144C8.34408 10.1064 8.3515 10.0986 8.35916 10.091C8.99721 9.45291 8.99949 8.38145 8.3155 7.69746C8.07728 7.45924 8.07728 7.07301 8.3155 6.83479C8.55372 6.59657 8.93995 6.59657 9.17817 6.83479C10.3166 7.97327 10.358 9.81748 9.22183 10.9536C9.21487 10.9606 9.20779 10.9673 9.20058 10.9739C9.19341 10.9819 9.18599 10.9897 9.17833 10.9973L6.13166 14.044C4.99548 15.1802 3.15127 15.1389 2.01279 14.0004C0.874362 12.8619 0.83297 11.0177 1.96916 9.8815L4.61426 7.2364Z" } }] }, LinkSingle = forwardRef(function(props, ref) {
248
+ return createElement(IconBase, Object.assign({}, props, {
270
249
  id: "link-single",
271
- ref: e,
272
- icon: qn
250
+ ref,
251
+ icon: element$2
273
252
  }));
274
253
  });
275
- se.displayName = "LinkSingle";
276
- var Jn = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 17", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M12.5935 3.47302C11.6354 2.51492 10.082 2.51492 9.12388 3.47302L7.83534 4.76157C7.60102 4.99588 7.22112 4.99588 6.98681 4.76157 6.75249 4.52725 6.75249 4.14735 6.98681 3.91304L8.27535 2.62449C9.70209 1.19776 12.0153 1.19776 13.442 2.62449 14.8688 4.05123 14.8688 6.36442 13.442 7.79116L12.1535 9.0797C11.9192 9.31402 11.5393 9.31402 11.3049 9.0797 11.0706 8.84539 11.0706 8.46549 11.3049 8.23117L12.5935 6.94263C13.5516 5.98452 13.5516 4.43113 12.5935 3.47302zM3.40637 12.6606C2.44827 11.7025 2.44827 10.1491 3.40637 9.19102L4.69492 7.90248C4.92923 7.66816 4.92923 7.28826 4.69492 7.05395 4.4606 6.81963 4.0807 6.81963 3.84639 7.05395L2.55784 8.34249C1.13111 9.76923 1.13111 12.0824 2.55784 13.5092 3.98458 14.9359 6.29777 14.9359 7.72451 13.5092L9.01305 12.2206C9.24737 11.9863 9.24737 11.6064 9.01305 11.3721 8.77874 11.1378 8.39884 11.1378 8.16452 11.3721L6.87598 12.6606C5.91787 13.6187 4.36448 13.6187 3.40637 12.6606zM3.5852 2.80332C3.35088 2.569 2.97098 2.569 2.73667 2.80332 2.50235 3.03763 2.50235 3.41753 2.73667 3.65185L12.4151 13.3302C12.6494 13.5646 13.0293 13.5646 13.2636 13.3302 13.4979 13.0959 13.4979 12.716 13.2636 12.4817L3.5852 2.80332z" } }] }, De = j(function(n, e) {
277
- return U($, Object.assign({}, n, {
254
+ LinkSingle.displayName = "LinkSingle";
255
+ var element$1 = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 17", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M12.5935 3.47302C11.6354 2.51492 10.082 2.51492 9.12388 3.47302L7.83534 4.76157C7.60102 4.99588 7.22112 4.99588 6.98681 4.76157 6.75249 4.52725 6.75249 4.14735 6.98681 3.91304L8.27535 2.62449C9.70209 1.19776 12.0153 1.19776 13.442 2.62449 14.8688 4.05123 14.8688 6.36442 13.442 7.79116L12.1535 9.0797C11.9192 9.31402 11.5393 9.31402 11.3049 9.0797 11.0706 8.84539 11.0706 8.46549 11.3049 8.23117L12.5935 6.94263C13.5516 5.98452 13.5516 4.43113 12.5935 3.47302zM3.40637 12.6606C2.44827 11.7025 2.44827 10.1491 3.40637 9.19102L4.69492 7.90248C4.92923 7.66816 4.92923 7.28826 4.69492 7.05395 4.4606 6.81963 4.0807 6.81963 3.84639 7.05395L2.55784 8.34249C1.13111 9.76923 1.13111 12.0824 2.55784 13.5092 3.98458 14.9359 6.29777 14.9359 7.72451 13.5092L9.01305 12.2206C9.24737 11.9863 9.24737 11.6064 9.01305 11.3721 8.77874 11.1378 8.39884 11.1378 8.16452 11.3721L6.87598 12.6606C5.91787 13.6187 4.36448 13.6187 3.40637 12.6606zM3.5852 2.80332C3.35088 2.569 2.97098 2.569 2.73667 2.80332 2.50235 3.03763 2.50235 3.41753 2.73667 3.65185L12.4151 13.3302C12.6494 13.5646 13.0293 13.5646 13.2636 13.3302 13.4979 13.0959 13.4979 12.716 13.2636 12.4817L3.5852 2.80332z" } }] }, UnlinkSingle = forwardRef(function(props, ref) {
256
+ return createElement(IconBase, Object.assign({}, props, {
278
257
  id: "unlink-single",
279
- ref: e,
280
- icon: Jn
258
+ ref,
259
+ icon: element$1
281
260
  }));
282
261
  });
283
- De.displayName = "UnlinkSingle";
284
- var zn = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 17 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M12.6551 1.98906C11.7476 1.08113 10.2757 1.08149 9.3686 1.98987L4.82542 6.53955C4.75087 6.61421 4.69336 6.70411 4.65682 6.80309L3.2461 10.625C3.16506 10.8446 3.21909 11.0912 3.3845 11.2568C3.54991 11.4224 3.79651 11.4767 4.01616 11.3959L7.85031 9.98517C7.94979 9.94856 8.04014 9.89077 8.11508 9.81579L12.6552 5.27327C13.5618 4.36621 13.5618 2.89607 12.6551 1.98906ZM10.2177 2.83779C10.6562 2.39869 11.3677 2.39851 11.8064 2.8374C12.2447 3.27584 12.2447 3.9865 11.8065 4.42497L7.3392 8.89457L4.82213 9.82068L5.74706 7.31487L10.2177 2.83779Z", fillRule: "evenodd", clipRule: "evenodd" } }, { tag: "path", attrs: { fill: "currentColor", d: "M1.79238 13.2999C1.46101 13.2999 1.19238 13.5685 1.19238 13.8999C1.19238 14.2313 1.46101 14.4999 1.79238 14.4999H14.4924C14.8238 14.4999 15.0924 14.2313 15.0924 13.8999C15.0924 13.5685 14.8238 13.2999 14.4924 13.2999H1.79238Z" } }] }, Ne = j(function(n, e) {
285
- return U($, Object.assign({}, n, {
262
+ UnlinkSingle.displayName = "UnlinkSingle";
263
+ var element = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 17 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M12.6551 1.98906C11.7476 1.08113 10.2757 1.08149 9.3686 1.98987L4.82542 6.53955C4.75087 6.61421 4.69336 6.70411 4.65682 6.80309L3.2461 10.625C3.16506 10.8446 3.21909 11.0912 3.3845 11.2568C3.54991 11.4224 3.79651 11.4767 4.01616 11.3959L7.85031 9.98517C7.94979 9.94856 8.04014 9.89077 8.11508 9.81579L12.6552 5.27327C13.5618 4.36621 13.5618 2.89607 12.6551 1.98906ZM10.2177 2.83779C10.6562 2.39869 11.3677 2.39851 11.8064 2.8374C12.2447 3.27584 12.2447 3.9865 11.8065 4.42497L7.3392 8.89457L4.82213 9.82068L5.74706 7.31487L10.2177 2.83779Z", fillRule: "evenodd", clipRule: "evenodd" } }, { tag: "path", attrs: { fill: "currentColor", d: "M1.79238 13.2999C1.46101 13.2999 1.19238 13.5685 1.19238 13.8999C1.19238 14.2313 1.46101 14.4999 1.79238 14.4999H14.4924C14.8238 14.4999 15.0924 14.2313 15.0924 13.8999C15.0924 13.5685 14.8238 13.2999 14.4924 13.2999H1.79238Z" } }] }, WriteSingle = forwardRef(function(props, ref) {
264
+ return createElement(IconBase, Object.assign({}, props, {
286
265
  id: "write-single",
287
- ref: e,
288
- icon: zn
266
+ ref,
267
+ icon: element
289
268
  }));
290
269
  });
291
- Ne.displayName = "WriteSingle";
292
- function je(n) {
293
- var e, t, i = "";
294
- if (typeof n == "string" || typeof n == "number") i += n;
295
- else if (typeof n == "object") if (Array.isArray(n)) {
296
- var r = n.length;
297
- for (e = 0; e < r; e++) n[e] && (t = je(n[e])) && (i && (i += " "), i += t);
298
- } else for (t in n) n[t] && (i && (i += " "), i += t);
299
- return i;
270
+ WriteSingle.displayName = "WriteSingle";
271
+ function r(e) {
272
+ var t, f, n = "";
273
+ if (typeof e == "string" || typeof e == "number") n += e;
274
+ else if (typeof e == "object") if (Array.isArray(e)) {
275
+ var o = e.length;
276
+ for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
277
+ } else for (f in e) e[f] && (n && (n += " "), n += f);
278
+ return n;
300
279
  }
301
- function xe() {
302
- for (var n, e, t = 0, i = "", r = arguments.length; t < r; t++) (n = arguments[t]) && (e = je(n)) && (i && (i += " "), i += e);
303
- return i;
280
+ __name(r, "r");
281
+ function clsx() {
282
+ for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
283
+ return n;
304
284
  }
305
- const Ue = {
306
- type: E.COMMAND,
285
+ __name(clsx, "clsx");
286
+ const DeleteDocHyperLinkCommand = {
287
+ type: CommandType.COMMAND,
307
288
  id: "docs.command.delete-hyper-link",
308
- async handler(n, e) {
309
- if (!e)
289
+ async handler(accessor, params) {
290
+ if (!params)
310
291
  return !1;
311
- const { unitId: t, linkId: i, segmentId: r } = e, o = n.get(x), s = on(n, { unitId: t, rangeId: i, segmentId: r });
312
- return s ? await o.syncExecuteCommand(s.id, s.params) : !1;
292
+ const { unitId, linkId, segmentId } = params, commandService = accessor.get(ICommandService), doMutation = deleteCustomRangeFactory(accessor, { unitId, rangeId: linkId, segmentId });
293
+ return doMutation ? await commandService.syncExecuteCommand(doMutation.id, doMutation.params) : !1;
313
294
  }
314
- }, $e = (n) => {
315
- const e = n.get(b), t = n.get(O), i = e.getTextRanges();
316
- if (!(i != null && i.length))
295
+ }, shouldDisableAddLink = /* @__PURE__ */ __name((accessor) => {
296
+ const textSelectionService = accessor.get(DocSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), textRanges = textSelectionService.getTextRanges();
297
+ if (!(textRanges != null && textRanges.length))
317
298
  return !0;
318
- const r = i[0];
319
- return !!(!t.getCurrentUnitForType(I.UNIVER_DOC) || !r || r.collapsed);
320
- }, R = {
321
- type: E.OPERATION,
299
+ const activeRange = textRanges[0];
300
+ return !!(!univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC) || !activeRange || activeRange.collapsed);
301
+ }, "shouldDisableAddLink"), ShowDocHyperLinkEditPopupOperation = {
302
+ type: CommandType.OPERATION,
322
303
  id: "doc.operation.show-hyper-link-edit-popup",
323
- handler(n, e) {
324
- var s;
325
- const t = e == null ? void 0 : e.link, i = n.get(O);
326
- if ($e(n) && !t)
304
+ handler(accessor, params) {
305
+ var _a7;
306
+ const linkInfo = params == null ? void 0 : params.link, univerInstanceService = accessor.get(IUniverInstanceService);
307
+ if (shouldDisableAddLink(accessor) && !linkInfo)
327
308
  return !1;
328
- const r = n.get(L), o = (t == null ? void 0 : t.unitId) || ((s = i.getCurrentUnitForType(I.UNIVER_DOC)) == null ? void 0 : s.getUnitId());
329
- return o ? (r.showEditPopup(o, t), !0) : !1;
309
+ const hyperLinkService = accessor.get(DocHyperLinkPopupService), unitId = (linkInfo == null ? void 0 : linkInfo.unitId) || ((_a7 = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC)) == null ? void 0 : _a7.getUnitId());
310
+ return unitId ? (hyperLinkService.showEditPopup(unitId, linkInfo), !0) : !1;
330
311
  }
331
- }, ie = {
332
- type: E.OPERATION,
312
+ }, ToggleDocHyperLinkInfoPopupOperation = {
313
+ type: CommandType.OPERATION,
333
314
  id: "doc.operation.toggle-hyper-link-info-popup",
334
- handler(n, e) {
335
- const t = n.get(L);
336
- return e ? (t.showInfoPopup(e), !0) : (t.hideInfoPopup(), !0);
315
+ handler(accessor, params) {
316
+ const hyperLinkService = accessor.get(DocHyperLinkPopupService);
317
+ return params ? (hyperLinkService.showInfoPopup(params), !0) : (hyperLinkService.hideInfoPopup(), !0);
337
318
  }
338
- }, Te = {
339
- type: E.OPERATION,
319
+ }, ClickDocHyperLinkOperation = {
320
+ type: CommandType.OPERATION,
340
321
  id: "doc.operation.click-hyper-link",
341
- handler(n, e) {
342
- var p, l, h;
343
- if (!e)
322
+ handler(accessor, params) {
323
+ var _a7, _b, _c;
324
+ if (!params)
344
325
  return !1;
345
- const { unitId: t, linkId: i, segmentId: r } = e, s = n.get(O).getUnit(t, I.UNIVER_DOC), c = s == null ? void 0 : s.getSelfOrHeaderFooterModel(r).getBody(), d = (h = (l = (p = c == null ? void 0 : c.customRanges) == null ? void 0 : p.find((f) => f.rangeId === i && f.rangeType === D.HYPERLINK)) == null ? void 0 : l.properties) == null ? void 0 : h.url;
346
- return d && window.open(d, "_blank", "noopener noreferrer"), !0;
347
- }
348
- }, Qn = "univer-doc-link", Xn = "univer-doc-link-type", et = "univer-doc-link-content", nt = "univer-doc-link-content-error", tt = "univer-doc-link-url", it = "univer-doc-link-operations", rt = "univer-doc-link-operation", ot = "univer-doc-link-operation-error", k = {
349
- docLink: Qn,
350
- docLinkType: Xn,
351
- docLinkContent: et,
352
- docLinkContentError: nt,
353
- docLinkUrl: tt,
354
- docLinkOperations: it,
355
- docLinkOperation: rt,
356
- docLinkOperationError: ot
357
- }, Y = () => {
358
- var C, g;
359
- const n = S(L), e = S(x), t = S(Ln), i = S(Re), r = yn(n.showingLink$), o = S(O);
360
- if (!r)
326
+ const { unitId, linkId, segmentId } = params, doc = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC), body = doc == null ? void 0 : doc.getSelfOrHeaderFooterModel(segmentId).getBody(), link = (_c = (_b = (_a7 = body == null ? void 0 : body.customRanges) == null ? void 0 : _a7.find((range) => range.rangeId === linkId && range.rangeType === CustomRangeType.HYPERLINK)) == null ? void 0 : _b.properties) == null ? void 0 : _c.url;
327
+ return link && window.open(link, "_blank", "noopener noreferrer"), !0;
328
+ }
329
+ }, docLink = "univer-doc-link", docLinkType = "univer-doc-link-type", docLinkContent = "univer-doc-link-content", docLinkContentError = "univer-doc-link-content-error", docLinkUrl = "univer-doc-link-url", docLinkOperations = "univer-doc-link-operations", docLinkOperation = "univer-doc-link-operation", docLinkOperationError = "univer-doc-link-operation-error", styles = {
330
+ docLink,
331
+ docLinkType,
332
+ docLinkContent,
333
+ docLinkContentError,
334
+ docLinkUrl,
335
+ docLinkOperations,
336
+ docLinkOperation,
337
+ docLinkOperationError
338
+ }, DocLinkPopup = /* @__PURE__ */ __name(() => {
339
+ var _a7, _b;
340
+ const hyperLinkService = useDependency(DocHyperLinkPopupService), commandService = useDependency(ICommandService), messageService = useDependency(IMessageService), localeService = useDependency(LocaleService), currentPopup = useObservable$1(hyperLinkService.showingLink$), univerInstanceService = useDependency(IUniverInstanceService);
341
+ if (!currentPopup)
361
342
  return null;
362
- const { unitId: s, linkId: c, segmentId: d, startIndex: p, endIndex: l } = r, h = o.getUnit(s, I.UNIVER_DOC), f = h == null ? void 0 : h.getSelfOrHeaderFooterModel(d).getBody(), a = (C = f == null ? void 0 : f.customRanges) == null ? void 0 : C.find((y) => y.rangeId === c && y.rangeType === D.HYPERLINK && y.startIndex === p && y.endIndex === l);
363
- if (!a)
343
+ const { unitId, linkId, segmentId, startIndex, endIndex } = currentPopup, doc = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC), body = doc == null ? void 0 : doc.getSelfOrHeaderFooterModel(segmentId).getBody(), link = (_a7 = body == null ? void 0 : body.customRanges) == null ? void 0 : _a7.find((range) => range.rangeId === linkId && range.rangeType === CustomRangeType.HYPERLINK && range.startIndex === startIndex && range.endIndex === endIndex);
344
+ if (!link)
364
345
  return null;
365
- const m = (g = a.properties) == null ? void 0 : g.url;
366
- return /* @__PURE__ */ u.jsxs(
346
+ const url = (_b = link.properties) == null ? void 0 : _b.url;
347
+ return /* @__PURE__ */ jsxs(
367
348
  "div",
368
349
  {
369
- className: k.docLink,
370
- onClick: () => {
371
- n.hideInfoPopup();
372
- },
350
+ className: styles.docLink,
351
+ onClick: /* @__PURE__ */ __name(() => {
352
+ hyperLinkService.hideInfoPopup();
353
+ }, "onClick"),
373
354
  children: [
374
- /* @__PURE__ */ u.jsxs("div", { className: xe(k.docLinkContent), onClick: () => window.open(m), children: [
375
- /* @__PURE__ */ u.jsx("div", { className: k.docLinkType, children: /* @__PURE__ */ u.jsx(se, {}) }),
376
- /* @__PURE__ */ u.jsx(B, { showIfEllipsis: !0, title: m, children: /* @__PURE__ */ u.jsx("span", { className: k.docLinkUrl, children: m }) })
355
+ /* @__PURE__ */ jsxs("div", { className: clsx(styles.docLinkContent), onClick: /* @__PURE__ */ __name(() => window.open(url), "onClick"), children: [
356
+ /* @__PURE__ */ jsx("div", { className: styles.docLinkType, children: /* @__PURE__ */ jsx(LinkSingle, {}) }),
357
+ /* @__PURE__ */ jsx(Tooltip, { showIfEllipsis: !0, title: url, children: /* @__PURE__ */ jsx("span", { className: styles.docLinkUrl, children: url }) })
377
358
  ] }),
378
- /* @__PURE__ */ u.jsxs("div", { className: k.docLinkOperations, children: [
379
- /* @__PURE__ */ u.jsx(
359
+ /* @__PURE__ */ jsxs("div", { className: styles.docLinkOperations, children: [
360
+ /* @__PURE__ */ jsx(
380
361
  "div",
381
362
  {
382
- className: xe(k.docLinkOperation),
383
- onClick: () => {
384
- navigator.clipboard.writeText(m), t.show({
385
- content: i.t("docLink.info.coped"),
386
- type: Sn.Info
363
+ className: clsx(styles.docLinkOperation),
364
+ onClick: /* @__PURE__ */ __name(() => {
365
+ navigator.clipboard.writeText(url), messageService.show({
366
+ content: localeService.t("docLink.info.coped"),
367
+ type: MessageType.Info
387
368
  });
388
- },
389
- children: /* @__PURE__ */ u.jsx(B, { placement: "bottom", title: i.t("docLink.info.copy"), children: /* @__PURE__ */ u.jsx(we, {}) })
369
+ }, "onClick"),
370
+ children: /* @__PURE__ */ jsx(Tooltip, { placement: "bottom", title: localeService.t("docLink.info.copy"), children: /* @__PURE__ */ jsx(CopySingle, {}) })
390
371
  }
391
372
  ),
392
- /* @__PURE__ */ u.jsx(
373
+ /* @__PURE__ */ jsx(
393
374
  "div",
394
375
  {
395
- className: k.docLinkOperation,
396
- onClick: () => {
397
- e.executeCommand(R.id, {
398
- link: r
376
+ className: styles.docLinkOperation,
377
+ onClick: /* @__PURE__ */ __name(() => {
378
+ commandService.executeCommand(ShowDocHyperLinkEditPopupOperation.id, {
379
+ link: currentPopup
399
380
  });
400
- },
401
- children: /* @__PURE__ */ u.jsx(B, { placement: "bottom", title: i.t("docLink.info.edit"), children: /* @__PURE__ */ u.jsx(Ne, {}) })
381
+ }, "onClick"),
382
+ children: /* @__PURE__ */ jsx(Tooltip, { placement: "bottom", title: localeService.t("docLink.info.edit"), children: /* @__PURE__ */ jsx(WriteSingle, {}) })
402
383
  }
403
384
  ),
404
- /* @__PURE__ */ u.jsx(
385
+ /* @__PURE__ */ jsx(
405
386
  "div",
406
387
  {
407
- className: k.docLinkOperation,
408
- onClick: () => {
409
- e.executeCommand(Ue.id, {
410
- unitId: s,
411
- linkId: a.rangeId,
412
- segmentId: d
388
+ className: styles.docLinkOperation,
389
+ onClick: /* @__PURE__ */ __name(() => {
390
+ commandService.executeCommand(DeleteDocHyperLinkCommand.id, {
391
+ unitId,
392
+ linkId: link.rangeId,
393
+ segmentId
413
394
  });
414
- },
415
- children: /* @__PURE__ */ u.jsx(B, { placement: "bottom", title: i.t("docLink.info.cancel"), children: /* @__PURE__ */ u.jsx(De, {}) })
395
+ }, "onClick"),
396
+ children: /* @__PURE__ */ jsx(Tooltip, { placement: "bottom", title: localeService.t("docLink.info.cancel"), children: /* @__PURE__ */ jsx(UnlinkSingle, {}) })
416
397
  }
417
398
  )
418
399
  ] })
419
400
  ]
420
401
  }
421
402
  );
422
- };
423
- Y.componentKey = "univer.doc.link-info-popup";
424
- var st = Object.defineProperty, ct = Object.getOwnPropertyDescriptor, dt = (n, e, t, i) => {
425
- for (var r = i > 1 ? void 0 : i ? ct(e, t) : e, o = n.length - 1, s; o >= 0; o--)
426
- (s = n[o]) && (r = (i ? s(e, t, r) : s(r)) || r);
427
- return i && r && st(e, t, r), r;
428
- }, Q = (n, e) => (t, i) => e(t, i, n);
429
- let L = class extends N {
430
- constructor(e, t, i) {
403
+ }, "DocLinkPopup");
404
+ DocLinkPopup.componentKey = "univer.doc.link-info-popup";
405
+ var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
406
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
407
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
408
+ return kind && result && __defProp$5(target, key, result), result;
409
+ }, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$5"), _a;
410
+ let DocHyperLinkPopupService = (_a = class extends Disposable {
411
+ constructor(_docCanvasPopupManagerService, _textSelectionManagerService, _univerInstanceService) {
431
412
  super();
432
- P(this, "_editingLink$", new ve(null));
433
- P(this, "_showingLink$", new ve(null));
434
- P(this, "editingLink$", this._editingLink$.asObservable());
435
- P(this, "showingLink$", this._showingLink$.asObservable());
436
- P(this, "_editPopup", null);
437
- P(this, "_infoPopup", null);
438
- this._docCanvasPopupManagerService = e, this._textSelectionManagerService = t, this._univerInstanceService = i, this.disposeWithMe(() => {
413
+ __publicField(this, "_editingLink$", new BehaviorSubject(null));
414
+ __publicField(this, "_showingLink$", new BehaviorSubject(null));
415
+ __publicField(this, "editingLink$", this._editingLink$.asObservable());
416
+ __publicField(this, "showingLink$", this._showingLink$.asObservable());
417
+ __publicField(this, "_editPopup", null);
418
+ __publicField(this, "_infoPopup", null);
419
+ this._docCanvasPopupManagerService = _docCanvasPopupManagerService, this._textSelectionManagerService = _textSelectionManagerService, this._univerInstanceService = _univerInstanceService, this.disposeWithMe(() => {
439
420
  this._editingLink$.complete(), this._showingLink$.complete();
440
421
  });
441
422
  }
@@ -445,94 +426,94 @@ let L = class extends N {
445
426
  get showing() {
446
427
  return this._showingLink$.value;
447
428
  }
448
- showEditPopup(e, t) {
449
- this._editPopup && this._editPopup.dispose(), this._editingLink$.next(t);
450
- const i = this._textSelectionManagerService.getTextRanges({ unitId: e, subUnitId: e });
451
- let r = i == null ? void 0 : i[i.length - 1];
452
- if (t) {
453
- const { segmentId: o, segmentPage: s, startIndex: c, endIndex: d } = t;
454
- r = {
429
+ showEditPopup(unitId, linkInfo) {
430
+ this._editPopup && this._editPopup.dispose(), this._editingLink$.next(linkInfo);
431
+ const textRanges = this._textSelectionManagerService.getTextRanges({ unitId, subUnitId: unitId });
432
+ let activeRange = textRanges == null ? void 0 : textRanges[textRanges.length - 1];
433
+ if (linkInfo) {
434
+ const { segmentId, segmentPage, startIndex, endIndex } = linkInfo;
435
+ activeRange = {
455
436
  collapsed: !1,
456
- startOffset: c,
457
- endOffset: d + 1,
458
- segmentId: o,
459
- segmentPage: s
437
+ startOffset: startIndex,
438
+ endOffset: endIndex + 1,
439
+ segmentId,
440
+ segmentPage
460
441
  }, this._textSelectionManagerService.replaceDocRanges([{
461
- startOffset: c,
462
- endOffset: d + 1
442
+ startOffset: startIndex,
443
+ endOffset: endIndex + 1
463
444
  }]);
464
445
  }
465
- return r ? (this._editPopup = this._docCanvasPopupManagerService.attachPopupToRange(
466
- r,
446
+ return activeRange ? (this._editPopup = this._docCanvasPopupManagerService.attachPopupToRange(
447
+ activeRange,
467
448
  {
468
- componentKey: V.componentKey,
449
+ componentKey: DocHyperLinkEdit.componentKey,
469
450
  direction: "bottom"
470
451
  },
471
- e
452
+ unitId
472
453
  ), this._editPopup) : null;
473
454
  }
474
455
  hideEditPopup() {
475
- var e;
476
- this._editingLink$.next(null), (e = this._editPopup) == null || e.dispose();
477
- }
478
- showInfoPopup(e) {
479
- var p, l, h, f, a, m;
480
- const { linkId: t, unitId: i, segmentId: r, segmentPage: o, startIndex: s, endIndex: c } = e;
481
- if (!(((p = this.showing) == null ? void 0 : p.linkId) === t && ((l = this.showing) == null ? void 0 : l.unitId) === i && ((h = this.showing) == null ? void 0 : h.segmentId) === r && ((f = this.showing) == null ? void 0 : f.segmentPage) === o && ((a = this.showing) == null ? void 0 : a.startIndex) === s && ((m = this.showing) == null ? void 0 : m.endIndex) === c || (this._infoPopup && this._infoPopup.dispose(), !this._univerInstanceService.getUnit(i, I.UNIVER_DOC))))
482
- return this._showingLink$.next({ unitId: i, linkId: t, segmentId: r, segmentPage: o, startIndex: s, endIndex: c }), this._infoPopup = this._docCanvasPopupManagerService.attachPopupToRange(
456
+ var _a7;
457
+ this._editingLink$.next(null), (_a7 = this._editPopup) == null || _a7.dispose();
458
+ }
459
+ showInfoPopup(info) {
460
+ var _a7, _b, _c, _d, _e, _f;
461
+ const { linkId, unitId, segmentId, segmentPage, startIndex, endIndex } = info;
462
+ if (!(((_a7 = this.showing) == null ? void 0 : _a7.linkId) === linkId && ((_b = this.showing) == null ? void 0 : _b.unitId) === unitId && ((_c = this.showing) == null ? void 0 : _c.segmentId) === segmentId && ((_d = this.showing) == null ? void 0 : _d.segmentPage) === segmentPage && ((_e = this.showing) == null ? void 0 : _e.startIndex) === startIndex && ((_f = this.showing) == null ? void 0 : _f.endIndex) === endIndex || (this._infoPopup && this._infoPopup.dispose(), !this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC))))
463
+ return this._showingLink$.next({ unitId, linkId, segmentId, segmentPage, startIndex, endIndex }), this._infoPopup = this._docCanvasPopupManagerService.attachPopupToRange(
483
464
  {
484
465
  collapsed: !1,
485
- startOffset: s,
486
- endOffset: c + 1,
487
- segmentId: r,
488
- segmentPage: o
466
+ startOffset: startIndex,
467
+ endOffset: endIndex + 1,
468
+ segmentId,
469
+ segmentPage
489
470
  },
490
471
  {
491
- componentKey: Y.componentKey,
472
+ componentKey: DocLinkPopup.componentKey,
492
473
  direction: "top-center",
493
474
  multipleDirection: "top",
494
- onClickOutside: () => {
475
+ onClickOutside: /* @__PURE__ */ __name(() => {
495
476
  this.hideInfoPopup();
496
- }
477
+ }, "onClickOutside")
497
478
  },
498
- i
479
+ unitId
499
480
  ), this._infoPopup;
500
481
  }
501
482
  hideInfoPopup() {
502
- var e;
503
- this._showingLink$.next(null), (e = this._infoPopup) == null || e.dispose();
504
- }
505
- };
506
- L = dt([
507
- Q(0, v(ln)),
508
- Q(1, v(b)),
509
- Q(2, O)
510
- ], L);
511
- var at = Object.defineProperty, lt = Object.getOwnPropertyDescriptor, ut = (n, e, t, i) => {
512
- for (var r = i > 1 ? void 0 : i ? lt(e, t) : e, o = n.length - 1, s; o >= 0; o--)
513
- (s = n[o]) && (r = (i ? s(e, t, r) : s(r)) || r);
514
- return i && r && at(e, t, r), r;
515
- }, X = (n, e) => (t, i) => e(t, i, n);
516
- let Z = class extends N {
517
- constructor(n, e, t) {
518
- super(), this._commandService = n, this._univerInstanceService = e, this._docHyperLinkService = t, this._initSelectionChange();
483
+ var _a7;
484
+ this._showingLink$.next(null), (_a7 = this._infoPopup) == null || _a7.dispose();
485
+ }
486
+ }, __name(_a, "DocHyperLinkPopupService"), _a);
487
+ DocHyperLinkPopupService = __decorateClass$5([
488
+ __decorateParam$5(0, Inject(DocCanvasPopManagerService)),
489
+ __decorateParam$5(1, Inject(DocSelectionManagerService)),
490
+ __decorateParam$5(2, IUniverInstanceService)
491
+ ], DocHyperLinkPopupService);
492
+ var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
493
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
494
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
495
+ return kind && result && __defProp$4(target, key, result), result;
496
+ }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a2;
497
+ let DocHyperLinkSelectionController = (_a2 = class extends Disposable {
498
+ constructor(_commandService, _univerInstanceService, _docHyperLinkService) {
499
+ super(), this._commandService = _commandService, this._univerInstanceService = _univerInstanceService, this._docHyperLinkService = _docHyperLinkService, this._initSelectionChange();
519
500
  }
520
501
  _initSelectionChange() {
521
502
  this.disposeWithMe(
522
- this._commandService.onCommandExecuted((n) => {
523
- var e, t, i;
524
- if (n.id === sn.id) {
525
- const r = n.params, { unitId: o, ranges: s, segmentId: c } = r, d = this._univerInstanceService.getUnit(o, I.UNIVER_DOC), p = s[0];
526
- if (p && d) {
527
- const { startOffset: l, endOffset: h, collapsed: f, segmentPage: a } = p, m = (t = (e = d.getSelfOrHeaderFooterModel(c)) == null ? void 0 : e.getBody()) == null ? void 0 : t.customRanges;
528
- if (f) {
529
- const C = (i = m == null ? void 0 : m.findIndex((g) => g.startIndex < l && g.endIndex > h - 1)) != null ? i : -1;
530
- if (C > -1) {
531
- const g = m[C];
532
- this._docHyperLinkService.showInfoPopup({ unitId: o, linkId: g.rangeId, segmentId: c, segmentPage: a, startIndex: g.startIndex, endIndex: g.endIndex });
503
+ this._commandService.onCommandExecuted((commandInfo) => {
504
+ var _a7, _b, _c;
505
+ if (commandInfo.id === SetTextSelectionsOperation.id) {
506
+ const params = commandInfo.params, { unitId, ranges, segmentId } = params, doc = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC), primary = ranges[0];
507
+ if (primary && doc) {
508
+ const { startOffset, endOffset, collapsed, segmentPage } = primary, customRanges = (_b = (_a7 = doc.getSelfOrHeaderFooterModel(segmentId)) == null ? void 0 : _a7.getBody()) == null ? void 0 : _b.customRanges;
509
+ if (collapsed) {
510
+ const index = (_c = customRanges == null ? void 0 : customRanges.findIndex((value) => value.startIndex < startOffset && value.endIndex > endOffset - 1)) != null ? _c : -1;
511
+ if (index > -1) {
512
+ const customRange = customRanges[index];
513
+ this._docHyperLinkService.showInfoPopup({ unitId, linkId: customRange.rangeId, segmentId, segmentPage, startIndex: customRange.startIndex, endIndex: customRange.endIndex });
533
514
  return;
534
515
  }
535
- } else if (m == null ? void 0 : m.find((g) => g.startIndex <= l && g.endIndex >= h - 1))
516
+ } else if (customRanges == null ? void 0 : customRanges.find((value) => value.startIndex <= startOffset && value.endIndex >= endOffset - 1))
536
517
  return;
537
518
  }
538
519
  this._docHyperLinkService.hideInfoPopup(), this._docHyperLinkService.hideEditPopup();
@@ -540,48 +521,48 @@ let Z = class extends N {
540
521
  })
541
522
  );
542
523
  }
543
- };
544
- Z = ut([
545
- X(0, x),
546
- X(1, O),
547
- X(2, v(L))
548
- ], Z);
549
- var pt = Object.defineProperty, ft = Object.getOwnPropertyDescriptor, gt = (n, e, t, i) => {
550
- for (var r = i > 1 ? void 0 : i ? ft(e, t) : e, o = n.length - 1, s; o >= 0; o--)
551
- (s = n[o]) && (r = (i ? s(e, t, r) : s(r)) || r);
552
- return i && r && pt(e, t, r), r;
553
- }, w = (n, e) => (t, i) => e(t, i, n);
554
- let re = class extends N {
555
- constructor(n, e, t, i, r, o) {
556
- super(), this._context = n, this._docEventManagerService = e, this._commandService = t, this._hyperLinkPopupService = i, this._docSkeletonManagerService = r, this._docSelectionManagerService = o, !(this._context.unitId === We || this._context.unitId === Ge) && (this._initHover(), this._initClick());
524
+ }, __name(_a2, "DocHyperLinkSelectionController"), _a2);
525
+ DocHyperLinkSelectionController = __decorateClass$4([
526
+ __decorateParam$4(0, ICommandService),
527
+ __decorateParam$4(1, IUniverInstanceService),
528
+ __decorateParam$4(2, Inject(DocHyperLinkPopupService))
529
+ ], DocHyperLinkSelectionController);
530
+ var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
531
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
532
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
533
+ return kind && result && __defProp$3(target, key, result), result;
534
+ }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a3;
535
+ let DocHyperLinkEventRenderController = (_a3 = class extends Disposable {
536
+ constructor(_context, _docEventManagerService, _commandService, _hyperLinkPopupService, _docSkeletonManagerService, _docSelectionManagerService) {
537
+ super(), this._context = _context, this._docEventManagerService = _docEventManagerService, this._commandService = _commandService, this._hyperLinkPopupService = _hyperLinkPopupService, this._docSkeletonManagerService = _docSkeletonManagerService, this._docSelectionManagerService = _docSelectionManagerService, !(this._context.unitId === DOCS_ZEN_EDITOR_UNIT_ID_KEY || this._context.unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY) && (this._initHover(), this._initClick());
557
538
  }
558
539
  get _skeleton() {
559
540
  return this._docSkeletonManagerService.getSkeleton();
560
541
  }
561
542
  _hideInfoPopup() {
562
543
  this._hyperLinkPopupService.showing && this._commandService.executeCommand(
563
- ie.id
544
+ ToggleDocHyperLinkInfoPopupOperation.id
564
545
  );
565
546
  }
566
547
  _initHover() {
567
548
  this.disposeWithMe(
568
- this._docEventManagerService.hoverCustomRanges$.subscribe((n) => {
569
- var r;
570
- const e = n.find((o) => o.range.rangeType === D.HYPERLINK), t = this._docSelectionManagerService.getTextRanges(), i = t == null ? void 0 : t[0].segmentId;
571
- if (((r = e == null ? void 0 : e.segmentId) != null ? r : "") !== i) {
549
+ this._docEventManagerService.hoverCustomRanges$.subscribe((ranges) => {
550
+ var _a7;
551
+ const link = ranges.find((range) => range.range.rangeType === CustomRangeType.HYPERLINK), activeRanges = this._docSelectionManagerService.getTextRanges(), currentSegmentId = activeRanges == null ? void 0 : activeRanges[0].segmentId;
552
+ if (((_a7 = link == null ? void 0 : link.segmentId) != null ? _a7 : "") !== currentSegmentId) {
572
553
  this._hideInfoPopup();
573
554
  return;
574
555
  }
575
- e ? this._commandService.executeCommand(
576
- ie.id,
556
+ link ? this._commandService.executeCommand(
557
+ ToggleDocHyperLinkInfoPopupOperation.id,
577
558
  {
578
559
  unitId: this._context.unitId,
579
- linkId: e.range.rangeId,
580
- segmentId: e.segmentId,
581
- segmentPage: e.segmentPageIndex,
582
- rangeId: e.range.rangeId,
583
- startIndex: e.range.startIndex,
584
- endIndex: e.range.endIndex
560
+ linkId: link.range.rangeId,
561
+ segmentId: link.segmentId,
562
+ segmentPage: link.segmentPageIndex,
563
+ rangeId: link.range.rangeId,
564
+ startIndex: link.range.startIndex,
565
+ endIndex: link.range.endIndex
585
566
  }
586
567
  ) : this._hideInfoPopup();
587
568
  })
@@ -589,202 +570,203 @@ let re = class extends N {
589
570
  }
590
571
  _initClick() {
591
572
  this.disposeWithMe(
592
- this._docEventManagerService.clickCustomRanges$.subscribe((n) => {
593
- const e = n.range;
594
- e && this._commandService.executeCommand(
595
- Te.id,
573
+ this._docEventManagerService.clickCustomRanges$.subscribe((range) => {
574
+ const link = range.range;
575
+ link && this._commandService.executeCommand(
576
+ ClickDocHyperLinkOperation.id,
596
577
  {
597
578
  unitId: this._context.unitId,
598
- linkId: e.rangeId,
599
- segmentId: n.segmentId
579
+ linkId: link.rangeId,
580
+ segmentId: range.segmentId
600
581
  }
601
582
  );
602
583
  })
603
584
  );
604
585
  }
605
- };
606
- re = gt([
607
- w(1, v(un)),
608
- w(2, x),
609
- w(3, v(L)),
610
- w(4, v(cn)),
611
- w(5, v(b))
612
- ], re);
613
- var ht = Object.defineProperty, mt = Object.getOwnPropertyDescriptor, _t = (n, e, t, i) => {
614
- for (var r = i > 1 ? void 0 : i ? mt(e, t) : e, o = n.length - 1, s; o >= 0; o--)
615
- (s = n[o]) && (r = (i ? s(e, t, r) : s(r)) || r);
616
- return i && r && ht(e, t, r), r;
617
- }, ee = (n, e) => (t, i) => e(t, i, n);
618
- let oe = class extends N {
619
- constructor(n, e, t, i) {
620
- super(), this._context = n, this._docInterceptorService = e, this._hyperLinkService = t, this._docRenderController = i, this._init(), this._initReRender();
586
+ }, __name(_a3, "DocHyperLinkEventRenderController"), _a3);
587
+ DocHyperLinkEventRenderController = __decorateClass$3([
588
+ __decorateParam$3(1, Inject(DocEventManagerService)),
589
+ __decorateParam$3(2, ICommandService),
590
+ __decorateParam$3(3, Inject(DocHyperLinkPopupService)),
591
+ __decorateParam$3(4, Inject(DocSkeletonManagerService)),
592
+ __decorateParam$3(5, Inject(DocSelectionManagerService))
593
+ ], DocHyperLinkEventRenderController);
594
+ var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
595
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
596
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
597
+ return kind && result && __defProp$2(target, key, result), result;
598
+ }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a4;
599
+ let DocHyperLinkRenderController = (_a4 = class extends Disposable {
600
+ constructor(_context, _docInterceptorService, _hyperLinkService, _docRenderController) {
601
+ super(), this._context = _context, this._docInterceptorService = _docInterceptorService, this._hyperLinkService = _hyperLinkService, this._docRenderController = _docRenderController, this._init(), this._initReRender();
621
602
  }
622
603
  _init() {
623
- this._docInterceptorService.intercept(an.CUSTOM_RANGE, {
624
- handler: (n, e, t) => {
625
- if (!n)
626
- return t(n);
627
- const { unitId: i, index: r } = e, o = this._hyperLinkService.showing;
628
- if (!o)
629
- return t({
630
- ...n,
604
+ this._docInterceptorService.intercept(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE, {
605
+ handler: /* @__PURE__ */ __name((data, pos, next) => {
606
+ if (!data)
607
+ return next(data);
608
+ const { unitId, index } = pos, activeLink = this._hyperLinkService.showing;
609
+ if (!activeLink)
610
+ return next({
611
+ ...data,
631
612
  active: !1
632
613
  });
633
- const { linkId: s, unitId: c, startIndex: d, endIndex: p } = o, l = c === i && n.rangeId === s && r >= d && r <= p;
634
- return t({
635
- ...n,
636
- active: l
614
+ const { linkId, unitId: linkUnitId, startIndex, endIndex } = activeLink, isActive = linkUnitId === unitId && data.rangeId === linkId && index >= startIndex && index <= endIndex;
615
+ return next({
616
+ ...data,
617
+ active: isActive
637
618
  });
638
- }
619
+ }, "handler")
639
620
  });
640
621
  }
641
622
  _initReRender() {
642
623
  this.disposeWithMe(this._hyperLinkService.showingLink$.pipe(
643
- gn((n, e) => (n == null ? void 0 : n.linkId) === (e == null ? void 0 : e.linkId) && (n == null ? void 0 : n.unitId) === (e == null ? void 0 : e.unitId) && (n == null ? void 0 : n.startIndex) === (e == null ? void 0 : e.startIndex)),
644
- hn()
645
- ).subscribe(([n, e]) => {
646
- e ? e.unitId === this._context.unitId && this._docRenderController.reRender(e.unitId) : n && n.unitId === this._context.unitId && this._docRenderController.reRender(n.unitId);
624
+ distinctUntilChanged((prev, aft) => (prev == null ? void 0 : prev.linkId) === (aft == null ? void 0 : aft.linkId) && (prev == null ? void 0 : prev.unitId) === (aft == null ? void 0 : aft.unitId) && (prev == null ? void 0 : prev.startIndex) === (aft == null ? void 0 : aft.startIndex)),
625
+ pairwise()
626
+ ).subscribe(([preLink, link]) => {
627
+ link ? link.unitId === this._context.unitId && this._docRenderController.reRender(link.unitId) : preLink && preLink.unitId === this._context.unitId && this._docRenderController.reRender(preLink.unitId);
647
628
  }));
648
629
  }
649
- };
650
- oe = _t([
651
- ee(1, v(dn)),
652
- ee(2, v(L)),
653
- ee(3, v(pn))
654
- ], oe);
655
- const He = "doc-hyper-link-icon";
656
- function Oe(n) {
630
+ }, __name(_a4, "DocHyperLinkRenderController"), _a4);
631
+ DocHyperLinkRenderController = __decorateClass$2([
632
+ __decorateParam$2(1, Inject(DocInterceptorService)),
633
+ __decorateParam$2(2, Inject(DocHyperLinkPopupService)),
634
+ __decorateParam$2(3, Inject(DocRenderController))
635
+ ], DocHyperLinkRenderController);
636
+ const DOC_LINK_ICON = "doc-hyper-link-icon";
637
+ function AddHyperLinkMenuItemFactory(accessor) {
657
638
  return {
658
- id: R.id,
659
- type: xn.BUTTON,
660
- icon: He,
639
+ id: ShowDocHyperLinkEditPopupOperation.id,
640
+ type: MenuItemType.BUTTON,
641
+ icon: DOC_LINK_ICON,
661
642
  title: "docLink.menu.tooltip",
662
643
  tooltip: "docLink.menu.tooltip",
663
- hidden$: On(n, I.UNIVER_DOC),
664
- disabled$: new mn(function(e) {
665
- const i = n.get(b).textSelection$.pipe(_n(16)).subscribe(() => {
666
- e.next($e(n));
644
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
645
+ disabled$: new Observable(function(subscribe) {
646
+ const observer = accessor.get(DocSelectionManagerService).textSelection$.pipe(debounceTime(16)).subscribe(() => {
647
+ subscribe.next(shouldDisableAddLink(accessor));
667
648
  });
668
649
  return () => {
669
- i.unsubscribe();
650
+ observer.unsubscribe();
670
651
  };
671
652
  })
672
653
  };
673
654
  }
674
- const vt = {
675
- id: R.id,
676
- binding: kn.CTRL_COMMAND | te.K,
655
+ __name(AddHyperLinkMenuItemFactory, "AddHyperLinkMenuItemFactory");
656
+ const addLinkShortcut = {
657
+ id: ShowDocHyperLinkEditPopupOperation.id,
658
+ binding: MetaKeys.CTRL_COMMAND | KeyCode.K,
677
659
  description: "docLink.menu.tooltip",
678
- preconditions: fn
679
- }, It = {
680
- [Pn.OTHERS]: {
681
- [R.id]: {
660
+ preconditions: whenDocAndEditorFocused
661
+ }, menuSchema = {
662
+ [RibbonStartGroup.OTHERS]: {
663
+ [ShowDocHyperLinkEditPopupOperation.id]: {
682
664
  order: 0,
683
- menuItemFactory: Oe
665
+ menuItemFactory: AddHyperLinkMenuItemFactory
684
666
  }
685
667
  },
686
- [Rn.MAIN_AREA]: {
687
- [En.DATA]: {
688
- [R.id]: {
668
+ [ContextMenuPosition.MAIN_AREA]: {
669
+ [ContextMenuGroup.DATA]: {
670
+ [ShowDocHyperLinkEditPopupOperation.id]: {
689
671
  order: 0,
690
- menuItemFactory: Oe
672
+ menuItemFactory: AddHyperLinkMenuItemFactory
691
673
  }
692
674
  }
693
675
  }
694
676
  };
695
- var Ct = Object.defineProperty, St = Object.getOwnPropertyDescriptor, Lt = (n, e, t, i) => {
696
- for (var r = i > 1 ? void 0 : i ? St(e, t) : e, o = n.length - 1, s; o >= 0; o--)
697
- (s = n[o]) && (r = (i ? s(e, t, r) : s(r)) || r);
698
- return i && r && Ct(e, t, r), r;
699
- }, F = (n, e) => (t, i) => e(t, i, n);
700
- let W = class extends N {
701
- constructor(n, e, t, i) {
702
- super(), this._componentManager = n, this._commandService = e, this._menuManagerService = t, this._shortcutService = i, this._initComponents(), this._initCommands(), this._initMenus(), this._initShortcut();
677
+ var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
678
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
679
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
680
+ return kind && result && __defProp$1(target, key, result), result;
681
+ }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a5;
682
+ let DocHyperLinkUIController = (_a5 = class extends Disposable {
683
+ constructor(_componentManager, _commandService, _menuManagerService, _shortcutService) {
684
+ super(), this._componentManager = _componentManager, this._commandService = _commandService, this._menuManagerService = _menuManagerService, this._shortcutService = _shortcutService, this._initComponents(), this._initCommands(), this._initMenus(), this._initShortcut();
703
685
  }
704
686
  _initComponents() {
705
687
  [
706
- [V, V.componentKey],
707
- [Y, Y.componentKey],
708
- [se, He]
709
- ].forEach(([n, e]) => {
710
- this._componentManager.register(e, n);
688
+ [DocHyperLinkEdit, DocHyperLinkEdit.componentKey],
689
+ [DocLinkPopup, DocLinkPopup.componentKey],
690
+ [LinkSingle, DOC_LINK_ICON]
691
+ ].forEach(([comp, key]) => {
692
+ this._componentManager.register(key, comp);
711
693
  });
712
694
  }
713
695
  _initCommands() {
714
696
  [
715
- Ee,
716
- be,
717
- Ue,
718
- R,
719
- ie,
720
- Te
721
- ].forEach((n) => {
722
- this._commandService.registerCommand(n);
697
+ AddDocHyperLinkCommand,
698
+ UpdateDocHyperLinkCommand,
699
+ DeleteDocHyperLinkCommand,
700
+ ShowDocHyperLinkEditPopupOperation,
701
+ ToggleDocHyperLinkInfoPopupOperation,
702
+ ClickDocHyperLinkOperation
703
+ ].forEach((command) => {
704
+ this._commandService.registerCommand(command);
723
705
  });
724
706
  }
725
707
  _initShortcut() {
726
- [vt].forEach((n) => {
727
- this._shortcutService.registerShortcut(n);
708
+ [addLinkShortcut].forEach((shortcut) => {
709
+ this._shortcutService.registerShortcut(shortcut);
728
710
  });
729
711
  }
730
712
  _initMenus() {
731
- this._menuManagerService.mergeMenu(It);
732
- }
733
- };
734
- W = Lt([
735
- F(0, v(bn)),
736
- F(1, x),
737
- F(2, Mn),
738
- F(3, wn)
739
- ], W);
740
- const yt = "DOC_HYPER_LINK_UI_PLUGIN";
741
- var Ae = Object.defineProperty, kt = Object.getOwnPropertyDescriptor, xt = (n, e, t) => e in n ? Ae(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, Ot = (n, e, t, i) => {
742
- for (var r = i > 1 ? void 0 : i ? kt(e, t) : e, o = n.length - 1, s; o >= 0; o--)
743
- (s = n[o]) && (r = (i ? s(e, t, r) : s(r)) || r);
744
- return i && r && Ae(e, t, r), r;
745
- }, ne = (n, e) => (t, i) => e(t, i, n), Be = (n, e, t) => xt(n, typeof e != "symbol" ? e + "" : e, t);
746
- let G = class extends ze {
747
- constructor(n = Le, e, t, i) {
748
- super(), this._config = n, this._injector = e, this._renderManagerSrv = t, this._configService = i;
749
- const { menu: r, ...o } = Qe(
713
+ this._menuManagerService.mergeMenu(menuSchema);
714
+ }
715
+ }, __name(_a5, "DocHyperLinkUIController"), _a5);
716
+ DocHyperLinkUIController = __decorateClass$1([
717
+ __decorateParam$1(0, Inject(ComponentManager)),
718
+ __decorateParam$1(1, ICommandService),
719
+ __decorateParam$1(2, IMenuManagerService),
720
+ __decorateParam$1(3, IShortcutService)
721
+ ], DocHyperLinkUIController);
722
+ const DOC_HYPER_LINK_UI_PLUGIN = "DOC_HYPER_LINK_UI_PLUGIN";
723
+ var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __defNormalProp2 = /* @__PURE__ */ __name((obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, "__defNormalProp"), __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
724
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
725
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
726
+ return kind && result && __defProp2(target, key, result), result;
727
+ }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), __publicField2 = /* @__PURE__ */ __name((obj, key, value) => __defNormalProp2(obj, typeof key != "symbol" ? key + "" : key, value), "__publicField"), _a6;
728
+ let UniverDocsHyperLinkUIPlugin = (_a6 = class extends Plugin {
729
+ constructor(_config = defaultPluginConfig, _injector, _renderManagerSrv, _configService) {
730
+ super(), this._config = _config, this._injector = _injector, this._renderManagerSrv = _renderManagerSrv, this._configService = _configService;
731
+ const { menu, ...rest } = merge(
750
732
  {},
751
- Le,
733
+ defaultPluginConfig,
752
734
  this._config
753
735
  );
754
- r && this._configService.setConfig("menu", r, { merge: !0 }), this._configService.setConfig(Dn, o);
736
+ menu && this._configService.setConfig("menu", menu, { merge: !0 }), this._configService.setConfig(DOCS_HYPER_LINK_UI_PLUGIN_CONFIG_KEY, rest);
755
737
  }
756
738
  onStarting() {
757
739
  [
758
- [L],
759
- [W],
760
- [Z]
761
- ].forEach((e) => {
762
- this._injector.add(e);
763
- }), this._injector.get(W);
740
+ [DocHyperLinkPopupService],
741
+ [DocHyperLinkUIController],
742
+ [DocHyperLinkSelectionController]
743
+ ].forEach((dep) => {
744
+ this._injector.add(dep);
745
+ }), this._injector.get(DocHyperLinkUIController);
764
746
  }
765
747
  onReady() {
766
- this._injector.get(Z);
748
+ this._injector.get(DocHyperLinkSelectionController);
767
749
  }
768
750
  onRendered() {
769
751
  this._initRenderModule();
770
752
  }
771
753
  _initRenderModule() {
772
754
  [
773
- [oe],
774
- [re]
775
- ].forEach((n) => {
776
- this._renderManagerSrv.registerRenderModule(I.UNIVER_DOC, n);
755
+ [DocHyperLinkRenderController],
756
+ [DocHyperLinkEventRenderController]
757
+ ].forEach((dep) => {
758
+ this._renderManagerSrv.registerRenderModule(UniverInstanceType.UNIVER_DOC, dep);
777
759
  });
778
760
  }
779
- };
780
- Be(G, "pluginName", yt);
781
- Be(G, "type", I.UNIVER_DOC);
782
- G = Ot([
783
- qe(en),
784
- ne(1, v(Je)),
785
- ne(2, nn),
786
- ne(3, Xe)
787
- ], G);
761
+ }, __name(_a6, "UniverDocsHyperLinkUIPlugin"), _a6);
762
+ __publicField2(UniverDocsHyperLinkUIPlugin, "pluginName", DOC_HYPER_LINK_UI_PLUGIN);
763
+ __publicField2(UniverDocsHyperLinkUIPlugin, "type", UniverInstanceType.UNIVER_DOC);
764
+ UniverDocsHyperLinkUIPlugin = __decorateClass([
765
+ DependentOn(UniverDocsHyperLinkPlugin),
766
+ __decorateParam(1, Inject(Injector)),
767
+ __decorateParam(2, IRenderManagerService),
768
+ __decorateParam(3, IConfigService)
769
+ ], UniverDocsHyperLinkUIPlugin);
788
770
  export {
789
- G as UniverDocsHyperLinkUIPlugin
771
+ UniverDocsHyperLinkUIPlugin
790
772
  };