@univerjs/docs-hyper-link-ui 0.2.4 → 0.2.6

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,217 +1,220 @@
1
- var be = Object.defineProperty;
2
- var we = (e, t, i) => t in e ? be(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
3
- var E = (e, t, i) => we(e, typeof t != "symbol" ? t + "" : t, i);
4
- import { CommandType as z, ICommandService as O, IUniverInstanceService as $, UniverInstanceType as _, LocaleService as ge, Disposable as T, generateRandomId as De, CustomRangeType as P, sequenceExecuteAsync as Ne, Tools as ve, OnLifecycle as J, LifecycleStages as Q, updateAttributeByDelete as Ue, DependentOn as $e, Plugin as Te } from "@univerjs/core";
5
- import { Inject as m, Injector as me } from "@wendellhu/redi";
6
- import { DocHyperLinkModel as H, AddDocHyperLinkMutation as He, UpdateDocHyperLinkMutation as Ae, UniverDocsHyperLinkPlugin as je } from "@univerjs/docs-hyper-link";
7
- import { IRenderManagerService as ee, DocumentEditArea as q, ITextSelectionRenderManager as Be } from "@univerjs/engine-render";
8
- import { IMessageService as Ke, useObservable as Ve, MetaKeys as Fe, KeyCode as Ye, MenuGroup as Ze, MenuItemType as We, MenuPosition as se, getMenuHiddenObservable as ze, ComponentManager as Ge, IMenuService as qe, IShortcutService as Xe } from "@univerjs/ui";
9
- import { Tooltip as j, MessageType as Je, FormLayout as Qe, Input as et, Button as ae } from "@univerjs/design";
10
- import d, { forwardRef as x, useRef as tt, createElement as R, useState as de, useEffect as le } from "react";
11
- import { useDependency as g, useObservable as nt } from "@wendellhu/redi/react-bindings";
12
- import { deleteCustomRangeFactory as it, TextSelectionManagerService as A, DocSkeletonManagerService as Le, addCustomRangeBySelectionFactory as rt, SetTextSelectionsOperation as ot, DocInterceptorService as ct, DOC_INTERCEPTOR_POINT as st } from "@univerjs/docs";
13
- import { DocCanvasPopManagerService as at, whenDocAndEditorFocused as dt, IDocClipboardService as lt } from "@univerjs/docs-ui";
14
- import { BehaviorSubject as ue, Observable as ut, debounceTime as pt } from "rxjs";
15
- import pe from "clsx";
16
- const ft = "DOC_HYPER_LINK_UI_PLUGIN";
17
- var v = function() {
18
- return v = Object.assign || function(e) {
19
- for (var t, i = 1, n = arguments.length; i < n; i++) {
20
- t = arguments[i];
21
- for (var r in t) Object.prototype.hasOwnProperty.call(t, r) && (e[r] = t[r]);
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, IUniverInstanceService, UniverInstanceType, useDependency, LocaleService, Disposable, Inject, generateRandomId, CustomRangeType, sequenceExecuteAsync, useObservable as useObservable$1, Tools, OnLifecycle, LifecycleStages, Injector, updateAttributeByDelete, DependentOn, Plugin } from "@univerjs/core";
6
+ import { DocHyperLinkModel, AddDocHyperLinkMutation, UpdateDocHyperLinkMutation, UniverDocsHyperLinkPlugin } from "@univerjs/docs-hyper-link";
7
+ import { IRenderManagerService, DocumentEditArea, ITextSelectionRenderManager } from "@univerjs/engine-render";
8
+ import { IMessageService, useObservable, MetaKeys, KeyCode, MenuGroup, MenuItemType, MenuPosition, getMenuHiddenObservable, ComponentManager, IMenuService, IShortcutService } from "@univerjs/ui";
9
+ import { Tooltip, MessageType, FormLayout, Input, Button } from "@univerjs/design";
10
+ import React, { forwardRef, useRef, createElement, useState, useEffect } from "react";
11
+ import { deleteCustomRangeFactory, TextSelectionManagerService, DocSkeletonManagerService, addCustomRangeBySelectionFactory, SetTextSelectionsOperation, DocInterceptorService, DOC_INTERCEPTOR_POINT, DocCustomRangeService } from "@univerjs/docs";
12
+ import { DocCanvasPopManagerService, whenDocAndEditorFocused, IDocClipboardService } from "@univerjs/docs-ui";
13
+ import { BehaviorSubject, Observable, debounceTime } from "rxjs";
14
+ import cs from "clsx";
15
+ const DOC_HYPER_LINK_UI_PLUGIN = "DOC_HYPER_LINK_UI_PLUGIN";
16
+ var __assign = function() {
17
+ return __assign = Object.assign || function(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && (t[p] = s[p]);
22
21
  }
23
- return e;
24
- }, v.apply(this, arguments);
25
- }, ht = function(e, t) {
26
- var i = {};
27
- for (var n in e) Object.prototype.hasOwnProperty.call(e, n) && t.indexOf(n) < 0 && (i[n] = e[n]);
28
- if (e != null && typeof Object.getOwnPropertySymbols == "function")
29
- for (var r = 0, n = Object.getOwnPropertySymbols(e); r < n.length; r++)
30
- t.indexOf(n[r]) < 0 && Object.prototype.propertyIsEnumerable.call(e, n[r]) && (i[n[r]] = e[n[r]]);
31
- return i;
32
- }, b = x(function(e, t) {
33
- var i = e.icon, n = e.id, r = e.className, o = e.extend, c = ht(e, ["icon", "id", "className", "extend"]), s = "univerjs-icon univerjs-icon-".concat(n, " ").concat(r || "").trim(), a = tt("_".concat(mt()));
34
- return _e(i, "".concat(n), { defIds: i.defIds, idSuffix: a.current }, v({ ref: t, className: s }, c), o);
22
+ return t;
23
+ }, __assign.apply(this, arguments);
24
+ }, __rest = function(s, e) {
25
+ var t = {};
26
+ for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0 && (t[p] = s[p]);
27
+ if (s != null && typeof Object.getOwnPropertySymbols == "function")
28
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++)
29
+ e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]) && (t[p[i]] = s[p[i]]);
30
+ return t;
31
+ }, IconBase = forwardRef(function(props, ref) {
32
+ 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()));
33
+ return render(icon, "".concat(id), { defIds: icon.defIds, idSuffix: idSuffix.current }, __assign({ ref, className: cls }, restProps), extend);
35
34
  });
36
- function _e(e, t, i, n, r) {
37
- return R(e.tag, v(v({ key: t }, gt(e, i, r)), n), (vt(e, i).children || []).map(function(o, c) {
38
- return _e(o, "".concat(t, "-").concat(e.tag, "-").concat(c), i, void 0, r);
35
+ function render(node, id, runtimeProps, rootProps, extend) {
36
+ return createElement(node.tag, __assign(__assign({ key: id }, replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend)), rootProps), (replaceRuntimeIdsInDefs(node, runtimeProps).children || []).map(function(child, index) {
37
+ return render(child, "".concat(id, "-").concat(node.tag, "-").concat(index), runtimeProps, void 0, extend);
39
38
  }));
40
39
  }
41
- function gt(e, t, i) {
42
- var n = v({}, e.attrs);
43
- i != null && i.colorChannel1 && n.fill === "colorChannel1" && (n.fill = i.colorChannel1);
44
- var r = t.defIds;
45
- return !r || r.length === 0 || (e.tag === "use" && n["xlink:href"] && (n["xlink:href"] = n["xlink:href"] + t.idSuffix), Object.entries(n).forEach(function(o) {
46
- var c = o[0], s = o[1];
47
- typeof s == "string" && (n[c] = s.replace(/url\(#(.*)\)/, "url(#$1".concat(t.idSuffix, ")")));
48
- })), n;
40
+ __name(render, "render");
41
+ function replaceRuntimeIdsAndExtInAttrs(node, runtimeProps, extend) {
42
+ var attrs = __assign({}, node.attrs);
43
+ extend != null && extend.colorChannel1 && attrs.fill === "colorChannel1" && (attrs.fill = extend.colorChannel1);
44
+ var defIds = runtimeProps.defIds;
45
+ return !defIds || defIds.length === 0 || (node.tag === "use" && attrs["xlink:href"] && (attrs["xlink:href"] = attrs["xlink:href"] + runtimeProps.idSuffix), Object.entries(attrs).forEach(function(_a8) {
46
+ var key = _a8[0], value = _a8[1];
47
+ typeof value == "string" && (attrs[key] = value.replace(/url\(#(.*)\)/, "url(#$1".concat(runtimeProps.idSuffix, ")")));
48
+ })), attrs;
49
49
  }
50
- function vt(e, t) {
51
- var i, n = t.defIds;
52
- return !n || n.length === 0 ? e : e.tag === "defs" && (!((i = e.children) === null || i === void 0) && i.length) ? v(v({}, e), { children: e.children.map(function(r) {
53
- return typeof r.attrs.id == "string" && n && n.indexOf(r.attrs.id) > -1 ? v(v({}, r), { attrs: v(v({}, r.attrs), { id: r.attrs.id + t.idSuffix }) }) : r;
54
- }) }) : e;
50
+ __name(replaceRuntimeIdsAndExtInAttrs, "replaceRuntimeIdsAndExtInAttrs");
51
+ function replaceRuntimeIdsInDefs(node, runtimeProps) {
52
+ var _a8, defIds = runtimeProps.defIds;
53
+ return !defIds || defIds.length === 0 ? node : node.tag === "defs" && (!((_a8 = node.children) === null || _a8 === void 0) && _a8.length) ? __assign(__assign({}, node), { children: node.children.map(function(child) {
54
+ 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;
55
+ }) }) : node;
55
56
  }
56
- function mt() {
57
+ __name(replaceRuntimeIdsInDefs, "replaceRuntimeIdsInDefs");
58
+ function generateShortUuid() {
57
59
  return Math.random().toString(36).substring(2, 8);
58
60
  }
59
- b.displayName = "UniverIcon";
60
- var Lt = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M3.71274 2.86421C3.47843 2.6299 3.09853 2.6299 2.86421 2.86421C2.6299 3.09853 2.6299 3.47843 2.86421 3.71274L7.15154 8.00007L2.86421 12.2874C2.6299 12.5217 2.6299 12.9016 2.86421 13.1359C3.09853 13.3702 3.47843 13.3702 3.71274 13.1359L8.00007 8.84859L12.2874 13.1359C12.5217 13.3702 12.9016 13.3702 13.1359 13.1359C13.3702 12.9016 13.3702 12.5217 13.1359 12.2874L8.84859 8.00007L13.1359 3.71274C13.3702 3.47843 13.3702 3.09853 13.1359 2.86421C12.9016 2.6299 12.5217 2.6299 12.2874 2.86421L8.00007 7.15154L3.71274 2.86421Z" } }] }, Ce = x(function(e, t) {
61
- return R(b, Object.assign({}, e, {
61
+ __name(generateShortUuid, "generateShortUuid");
62
+ IconBase.displayName = "UniverIcon";
63
+ var element$4 = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M3.71274 2.86421C3.47843 2.6299 3.09853 2.6299 2.86421 2.86421C2.6299 3.09853 2.6299 3.47843 2.86421 3.71274L7.15154 8.00007L2.86421 12.2874C2.6299 12.5217 2.6299 12.9016 2.86421 13.1359C3.09853 13.3702 3.47843 13.3702 3.71274 13.1359L8.00007 8.84859L12.2874 13.1359C12.5217 13.3702 12.9016 13.3702 13.1359 13.1359C13.3702 12.9016 13.3702 12.5217 13.1359 12.2874L8.84859 8.00007L13.1359 3.71274C13.3702 3.47843 13.3702 3.09853 13.1359 2.86421C12.9016 2.6299 12.5217 2.6299 12.2874 2.86421L8.00007 7.15154L3.71274 2.86421Z" } }] }, CloseSingle = forwardRef(function(props, ref) {
64
+ return createElement(IconBase, Object.assign({}, props, {
62
65
  id: "close-single",
63
- ref: t,
64
- icon: Lt
66
+ ref,
67
+ icon: element$4
65
68
  }));
66
69
  });
67
- Ce.displayName = "CloseSingle";
68
- var _t = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 17 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M5.02547 12.4251C5.15328 13.7417 6.26305 14.7708 7.61318 14.7708H12.6132C14.0491 14.7708 15.2132 13.6067 15.2132 12.1708V6.1708C15.2132 4.78586 14.1303 3.65383 12.7651 3.57517C12.6373 2.25858 11.5275 1.22949 10.1774 1.22949H5.17739C3.74145 1.22949 2.57739 2.39355 2.57739 3.82949V9.82949C2.57739 11.2144 3.66024 12.3465 5.02547 12.4251ZM11.5535 3.5708H7.61318C6.17724 3.5708 5.01318 4.73486 5.01318 6.1708V11.22C4.31736 11.1387 3.77739 10.5471 3.77739 9.82949V3.82949C3.77739 3.05629 4.40419 2.42949 5.17739 2.42949H10.1774C10.8622 2.42949 11.4322 2.92119 11.5535 3.5708ZM14.0132 6.1708C14.0132 5.3976 13.3864 4.7708 12.6132 4.7708H7.61318C6.83998 4.7708 6.21318 5.3976 6.21318 6.1708V12.1708C6.21318 12.944 6.83998 13.5708 7.61318 13.5708H12.6132C13.3864 13.5708 14.0132 12.944 14.0132 12.1708V6.1708Z", fillRule: "evenodd", clipRule: "evenodd" } }] }, Ie = x(function(e, t) {
69
- return R(b, Object.assign({}, e, {
70
+ CloseSingle.displayName = "CloseSingle";
71
+ 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) {
72
+ return createElement(IconBase, Object.assign({}, props, {
70
73
  id: "copy-single",
71
- ref: t,
72
- icon: _t
74
+ ref,
75
+ icon: element$3
73
76
  }));
74
77
  });
75
- Ie.displayName = "CopySingle";
76
- var Ct = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M5.9564 2.91332C4.91407 1.87102 3.22413 1.87101 2.18182 2.91333L2.18182 2.91333C1.13953 3.95567 1.13952 5.6456 2.18182 6.68791L8.27777 12.7838C9.72408 14.2302 12.069 14.2302 13.5154 12.7839L13.0911 12.3596L13.5154 12.7839C14.9617 11.3375 14.9617 8.99257 13.5154 7.54626L8.39476 2.42566C8.16044 2.19134 7.78054 2.19134 7.54623 2.42566C7.31191 2.65997 7.31191 3.03987 7.54623 3.27419L12.6668 8.39479L13.0911 7.97052L12.6668 8.39479C13.6445 9.37247 13.6445 10.9576 12.6668 11.9353L13.0399 12.3084L12.6668 11.9353C11.6891 12.913 10.104 12.913 9.1263 11.9353L3.03035 5.83938C2.45668 5.26571 2.45667 4.33556 3.03036 3.76184C3.60403 3.18818 4.53416 3.18817 5.10788 3.76185C5.10788 3.76186 5.10788 3.76186 5.10789 3.76186L11.2038 9.8578L11.601 9.46061L11.2038 9.8578C11.3735 10.0275 11.3735 10.3026 11.2038 10.4723L11.2038 10.4723C11.0341 10.642 10.759 10.642 10.5893 10.4723L5.46874 5.35171C5.23442 5.1174 4.85452 5.1174 4.62021 5.35171C4.38589 5.58602 4.38589 5.96592 4.62021 6.20024L9.74078 11.3208C10.3791 11.9591 11.414 11.9591 12.0523 11.3208C12.0523 11.3208 12.0523 11.3208 12.0523 11.3208M12.0523 11.3208C12.6907 10.6825 12.6906 9.64757 12.0523 9.00927L5.95641 2.91333L5.9564 2.91332", fillRule: "evenodd", clipRule: "evenodd" } }] }, te = x(function(e, t) {
77
- return R(b, Object.assign({}, e, {
78
+ CopySingle.displayName = "CopySingle";
79
+ var element$2 = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em", height: "1em" }, children: [{ tag: "path", attrs: { fill: "currentColor", d: "M5.9564 2.91332C4.91407 1.87102 3.22413 1.87101 2.18182 2.91333L2.18182 2.91333C1.13953 3.95567 1.13952 5.6456 2.18182 6.68791L8.27777 12.7838C9.72408 14.2302 12.069 14.2302 13.5154 12.7839L13.0911 12.3596L13.5154 12.7839C14.9617 11.3375 14.9617 8.99257 13.5154 7.54626L8.39476 2.42566C8.16044 2.19134 7.78054 2.19134 7.54623 2.42566C7.31191 2.65997 7.31191 3.03987 7.54623 3.27419L12.6668 8.39479L13.0911 7.97052L12.6668 8.39479C13.6445 9.37247 13.6445 10.9576 12.6668 11.9353L13.0399 12.3084L12.6668 11.9353C11.6891 12.913 10.104 12.913 9.1263 11.9353L3.03035 5.83938C2.45668 5.26571 2.45667 4.33556 3.03036 3.76184C3.60403 3.18818 4.53416 3.18817 5.10788 3.76185C5.10788 3.76186 5.10788 3.76186 5.10789 3.76186L11.2038 9.8578L11.601 9.46061L11.2038 9.8578C11.3735 10.0275 11.3735 10.3026 11.2038 10.4723L11.2038 10.4723C11.0341 10.642 10.759 10.642 10.5893 10.4723L5.46874 5.35171C5.23442 5.1174 4.85452 5.1174 4.62021 5.35171C4.38589 5.58602 4.38589 5.96592 4.62021 6.20024L9.74078 11.3208C10.3791 11.9591 11.414 11.9591 12.0523 11.3208C12.0523 11.3208 12.0523 11.3208 12.0523 11.3208M12.0523 11.3208C12.6907 10.6825 12.6906 9.64757 12.0523 9.00927L5.95641 2.91333L5.9564 2.91332", fillRule: "evenodd", clipRule: "evenodd" } }] }, LinkSingle = forwardRef(function(props, ref) {
80
+ return createElement(IconBase, Object.assign({}, props, {
78
81
  id: "link-single",
79
- ref: t,
80
- icon: Ct
82
+ ref,
83
+ icon: element$2
81
84
  }));
82
85
  });
83
- te.displayName = "LinkSingle";
84
- var It = { 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" } }] }, ke = x(function(e, t) {
85
- return R(b, Object.assign({}, e, {
86
+ LinkSingle.displayName = "LinkSingle";
87
+ 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) {
88
+ return createElement(IconBase, Object.assign({}, props, {
86
89
  id: "unlink-single",
87
- ref: t,
88
- icon: It
90
+ ref,
91
+ icon: element$1
89
92
  }));
90
93
  });
91
- ke.displayName = "UnlinkSingle";
92
- var kt = { 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" } }] }, ye = x(function(e, t) {
93
- return R(b, Object.assign({}, e, {
94
+ UnlinkSingle.displayName = "UnlinkSingle";
95
+ 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) {
96
+ return createElement(IconBase, Object.assign({}, props, {
94
97
  id: "write-single",
95
- ref: t,
96
- icon: kt
98
+ ref,
99
+ icon: element
97
100
  }));
98
101
  });
99
- ye.displayName = "WriteSingle";
100
- const Se = {
101
- type: z.COMMAND,
102
+ WriteSingle.displayName = "WriteSingle";
103
+ const DeleteDocHyperLinkCommand = {
104
+ type: CommandType.COMMAND,
102
105
  id: "docs.command.delete-hyper-link",
103
- async handler(e, t) {
104
- if (!t)
106
+ async handler(accessor, params) {
107
+ if (!params)
105
108
  return !1;
106
- const { unitId: i, linkId: n } = t, r = e.get(O);
107
- if (!e.get(H).getLink(i, n))
109
+ const { unitId, linkId } = params, commandService = accessor.get(ICommandService);
110
+ if (!accessor.get(DocHyperLinkModel).getLink(unitId, linkId))
108
111
  return !1;
109
- const s = it(e, { unitId: i, rangeId: n });
110
- return s ? await r.syncExecuteCommand(s.id, s.params) : !1;
112
+ const doMutation = deleteCustomRangeFactory(accessor, { unitId, rangeId: linkId });
113
+ return doMutation ? await commandService.syncExecuteCommand(doMutation.id, doMutation.params) : !1;
111
114
  }
112
- }, Oe = (e) => {
113
- var u;
114
- const t = e.get(A), i = e.get($), n = t.getActiveRange(), o = e.get(ee).getCurrent(), c = o == null ? void 0 : o.with(Le).getSkeleton(), s = c == null ? void 0 : c.getViewModel().getEditArea();
115
- if (s === q.FOOTER || s === q.HEADER)
115
+ }, shouldDisableAddLink = /* @__PURE__ */ __name((accessor) => {
116
+ var _a8;
117
+ const textSelectionService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), activeRange = textSelectionService.getActiveRange(), render2 = accessor.get(IRenderManagerService).getCurrent(), skeleton = render2 == null ? void 0 : render2.with(DocSkeletonManagerService).getSkeleton(), editArea = skeleton == null ? void 0 : skeleton.getViewModel().getEditArea();
118
+ if (editArea === DocumentEditArea.FOOTER || editArea === DocumentEditArea.HEADER)
116
119
  return !0;
117
- const a = i.getCurrentUnitForType(_.UNIVER_DOC);
118
- if (!a || !n || n.collapsed)
120
+ const doc = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
121
+ if (!doc || !activeRange || activeRange.collapsed)
119
122
  return !0;
120
- const p = (u = a.getBody()) == null ? void 0 : u.paragraphs;
121
- if (!p)
123
+ const paragraphs = (_a8 = doc.getBody()) == null ? void 0 : _a8.paragraphs;
124
+ if (!paragraphs)
122
125
  return !0;
123
- for (let f = 0, l = p.length; f < l; f++) {
124
- const h = p[f];
125
- if (n.startOffset <= h.startIndex && n.endOffset > h.startIndex)
126
+ for (let i = 0, len = paragraphs.length; i < len; i++) {
127
+ const p = paragraphs[i];
128
+ if (activeRange.startOffset <= p.startIndex && activeRange.endOffset > p.startIndex)
126
129
  return !0;
127
- if (h.startIndex > n.endOffset)
130
+ if (p.startIndex > activeRange.endOffset)
128
131
  break;
129
132
  }
130
133
  return !1;
131
- }, G = {
132
- type: z.OPERATION,
134
+ }, "shouldDisableAddLink"), ShowDocHyperLinkEditPopupOperation = {
135
+ type: CommandType.OPERATION,
133
136
  id: "docs.operation.show-hyper-link-edit-popup",
134
- handler(e, t) {
135
- const i = t == null ? void 0 : t.link;
136
- return Oe(e) && !i ? !1 : (e.get(S).showEditPopup(i), !0);
137
+ handler(accessor, params) {
138
+ const linkInfo = params == null ? void 0 : params.link;
139
+ return shouldDisableAddLink(accessor) && !linkInfo ? !1 : (accessor.get(DocHyperLinkPopupService).showEditPopup(linkInfo), !0);
137
140
  }
138
- }, yt = "univer-doc-link", St = "univer-doc-link-type", Ot = "univer-doc-link-content", Et = "univer-doc-link-content-error", Mt = "univer-doc-link-url", Pt = "univer-doc-link-operations", xt = "univer-doc-link-operation", Rt = "univer-doc-link-operation-error", y = {
139
- docLink: yt,
140
- docLinkType: St,
141
- docLinkContent: Ot,
142
- docLinkContentError: Et,
143
- docLinkUrl: Mt,
144
- docLinkOperations: Pt,
145
- docLinkOperation: xt,
146
- docLinkOperationError: Rt
147
- }, Y = () => {
148
- const e = g(S), t = g(H), i = g(O), n = g(Ke), r = g(ge), o = Ve(e.showingLink$);
149
- if (!o)
141
+ }, 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$1 = {
142
+ docLink,
143
+ docLinkType,
144
+ docLinkContent,
145
+ docLinkContentError,
146
+ docLinkUrl,
147
+ docLinkOperations,
148
+ docLinkOperation,
149
+ docLinkOperationError
150
+ }, DocLinkPopup = /* @__PURE__ */ __name(() => {
151
+ const hyperLinkService = useDependency(DocHyperLinkPopupService), hyperLinkModel = useDependency(DocHyperLinkModel), commandService = useDependency(ICommandService), messageService = useDependency(IMessageService), localeService = useDependency(LocaleService), currentPopup = useObservable(hyperLinkService.showingLink$);
152
+ if (!currentPopup)
150
153
  return null;
151
- const { unitId: c, linkId: s } = o, a = t.getLink(c, s);
152
- return a ? /* @__PURE__ */ d.createElement(
154
+ const { unitId, linkId } = currentPopup, link = hyperLinkModel.getLink(unitId, linkId);
155
+ return link ? /* @__PURE__ */ React.createElement(
153
156
  "div",
154
157
  {
155
- className: y.docLink,
156
- onClick: () => {
157
- e.hideInfoPopup();
158
- }
158
+ className: styles$1.docLink,
159
+ onClick: /* @__PURE__ */ __name(() => {
160
+ hyperLinkService.hideInfoPopup();
161
+ }, "onClick")
159
162
  },
160
- /* @__PURE__ */ d.createElement("div", { className: pe(y.docLinkContent), onClick: () => window.open(a.payload) }, /* @__PURE__ */ d.createElement("div", { className: y.docLinkType }, /* @__PURE__ */ d.createElement(te, null)), /* @__PURE__ */ d.createElement(j, { showIfEllipsis: !0, title: a.payload }, /* @__PURE__ */ d.createElement("span", { className: y.docLinkUrl }, a.payload))),
161
- /* @__PURE__ */ d.createElement("div", { className: y.docLinkOperations }, /* @__PURE__ */ d.createElement(
163
+ /* @__PURE__ */ React.createElement("div", { className: cs(styles$1.docLinkContent), onClick: /* @__PURE__ */ __name(() => window.open(link.payload), "onClick") }, /* @__PURE__ */ React.createElement("div", { className: styles$1.docLinkType }, /* @__PURE__ */ React.createElement(LinkSingle, null)), /* @__PURE__ */ React.createElement(Tooltip, { showIfEllipsis: !0, title: link.payload }, /* @__PURE__ */ React.createElement("span", { className: styles$1.docLinkUrl }, link.payload))),
164
+ /* @__PURE__ */ React.createElement("div", { className: styles$1.docLinkOperations }, /* @__PURE__ */ React.createElement(
162
165
  "div",
163
166
  {
164
- className: pe(y.docLinkOperation),
165
- onClick: () => {
166
- navigator.clipboard.writeText(a.payload), n.show({
167
- content: r.t("docLink.info.coped"),
168
- type: Je.Info
167
+ className: cs(styles$1.docLinkOperation),
168
+ onClick: /* @__PURE__ */ __name(() => {
169
+ navigator.clipboard.writeText(link.payload), messageService.show({
170
+ content: localeService.t("docLink.info.coped"),
171
+ type: MessageType.Info
169
172
  });
170
- }
173
+ }, "onClick")
171
174
  },
172
- /* @__PURE__ */ d.createElement(j, { placement: "bottom", title: r.t("docLink.info.copy") }, /* @__PURE__ */ d.createElement(Ie, null))
173
- ), /* @__PURE__ */ d.createElement(
175
+ /* @__PURE__ */ React.createElement(Tooltip, { placement: "bottom", title: localeService.t("docLink.info.copy") }, /* @__PURE__ */ React.createElement(CopySingle, null))
176
+ ), /* @__PURE__ */ React.createElement(
174
177
  "div",
175
178
  {
176
- className: y.docLinkOperation,
177
- onClick: () => {
178
- i.executeCommand(G.id, {
179
- link: o
179
+ className: styles$1.docLinkOperation,
180
+ onClick: /* @__PURE__ */ __name(() => {
181
+ commandService.executeCommand(ShowDocHyperLinkEditPopupOperation.id, {
182
+ link: currentPopup
180
183
  });
181
- }
184
+ }, "onClick")
182
185
  },
183
- /* @__PURE__ */ d.createElement(j, { placement: "bottom", title: r.t("docLink.info.edit") }, /* @__PURE__ */ d.createElement(ye, null))
184
- ), /* @__PURE__ */ d.createElement(
186
+ /* @__PURE__ */ React.createElement(Tooltip, { placement: "bottom", title: localeService.t("docLink.info.edit") }, /* @__PURE__ */ React.createElement(WriteSingle, null))
187
+ ), /* @__PURE__ */ React.createElement(
185
188
  "div",
186
189
  {
187
- className: y.docLinkOperation,
188
- onClick: () => {
189
- i.executeCommand(Se.id, {
190
- unitId: c,
191
- linkId: a.id
190
+ className: styles$1.docLinkOperation,
191
+ onClick: /* @__PURE__ */ __name(() => {
192
+ commandService.executeCommand(DeleteDocHyperLinkCommand.id, {
193
+ unitId,
194
+ linkId: link.id
192
195
  });
193
- }
196
+ }, "onClick")
194
197
  },
195
- /* @__PURE__ */ d.createElement(j, { placement: "bottom", title: r.t("docLink.info.cancel") }, /* @__PURE__ */ d.createElement(ke, null))
198
+ /* @__PURE__ */ React.createElement(Tooltip, { placement: "bottom", title: localeService.t("docLink.info.cancel") }, /* @__PURE__ */ React.createElement(UnlinkSingle, null))
196
199
  ))
197
200
  ) : null;
198
- };
199
- Y.componentKey = "univer.doc.link-info-popup";
200
- var bt = Object.defineProperty, wt = Object.getOwnPropertyDescriptor, Dt = (e, t, i, n) => {
201
- for (var r = n > 1 ? void 0 : n ? wt(t, i) : t, o = e.length - 1, c; o >= 0; o--)
202
- (c = e[o]) && (r = (n ? c(t, i, r) : c(r)) || r);
203
- return n && r && bt(t, i, r), r;
204
- }, D = (e, t) => (i, n) => t(i, n, e);
205
- let S = class extends T {
206
- constructor(t, i, n, r, o) {
201
+ }, "DocLinkPopup");
202
+ DocLinkPopup.componentKey = "univer.doc.link-info-popup";
203
+ var __defProp$6 = Object.defineProperty, __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor, __decorateClass$6 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
204
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
205
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
206
+ return kind && result && __defProp$6(target, key, result), result;
207
+ }, "__decorateClass$6"), __decorateParam$6 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$6"), _a;
208
+ let DocHyperLinkPopupService = (_a = class extends Disposable {
209
+ constructor(_docCanvasPopupManagerService, _textSelectionManagerService, _docHyperLinkModel, _univerInstanceService, _commandService) {
207
210
  super();
208
- E(this, "_editingLink$", new ue(null));
209
- E(this, "_showingLink$", new ue(null));
210
- E(this, "editingLink$", this._editingLink$.asObservable());
211
- E(this, "showingLink$", this._showingLink$.asObservable());
212
- E(this, "_editPopup", null);
213
- E(this, "_infoPopup", null);
214
- this._docCanvasPopupManagerService = t, this._textSelectionManagerService = i, this._docHyperLinkModel = n, this._univerInstanceService = r, this._commandService = o, this.disposeWithMe(() => {
211
+ __publicField(this, "_editingLink$", new BehaviorSubject(null));
212
+ __publicField(this, "_showingLink$", new BehaviorSubject(null));
213
+ __publicField(this, "editingLink$", this._editingLink$.asObservable());
214
+ __publicField(this, "showingLink$", this._showingLink$.asObservable());
215
+ __publicField(this, "_editPopup", null);
216
+ __publicField(this, "_infoPopup", null);
217
+ this._docCanvasPopupManagerService = _docCanvasPopupManagerService, this._textSelectionManagerService = _textSelectionManagerService, this._docHyperLinkModel = _docHyperLinkModel, this._univerInstanceService = _univerInstanceService, this._commandService = _commandService, this.disposeWithMe(() => {
215
218
  this._editingLink$.complete(), this._showingLink$.complete();
216
219
  });
217
220
  }
@@ -221,282 +224,286 @@ let S = class extends T {
221
224
  get showing() {
222
225
  return this._showingLink$.value;
223
226
  }
224
- showEditPopup(t) {
225
- var n, r;
226
- this._editPopup && this._editPopup.dispose(), this._editingLink$.next(t);
227
- let i = this._textSelectionManagerService.getActiveRange();
228
- if (t) {
229
- const { unitId: o, rangeIndex: c } = t, s = this._univerInstanceService.getUnit(o, _.UNIVER_DOC), a = (r = (n = s == null ? void 0 : s.getBody()) == null ? void 0 : n.customRanges) == null ? void 0 : r[c];
230
- a && (i = {
227
+ showEditPopup(linkInfo) {
228
+ var _a8, _b;
229
+ this._editPopup && this._editPopup.dispose(), this._editingLink$.next(linkInfo);
230
+ let activeRange = this._textSelectionManagerService.getActiveRange();
231
+ if (linkInfo) {
232
+ const { unitId, rangeIndex } = linkInfo, doc = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC), range = (_b = (_a8 = doc == null ? void 0 : doc.getBody()) == null ? void 0 : _a8.customRanges) == null ? void 0 : _b[rangeIndex];
233
+ range && (activeRange = {
231
234
  collapsed: !1,
232
- startOffset: a.startIndex,
233
- endOffset: a.endIndex + 1
235
+ startOffset: range.startIndex,
236
+ endOffset: range.endIndex + 1
234
237
  }, this._textSelectionManagerService.replaceTextRanges([{
235
- startOffset: a.startIndex,
236
- endOffset: a.endIndex + 1
238
+ startOffset: range.startIndex,
239
+ endOffset: range.endIndex + 1
237
240
  }]));
238
241
  }
239
- return i ? (this._editPopup = this._docCanvasPopupManagerService.attachPopupToRange(
240
- i,
242
+ return activeRange ? (this._editPopup = this._docCanvasPopupManagerService.attachPopupToRange(
243
+ activeRange,
241
244
  {
242
- componentKey: Z.componentKey,
245
+ componentKey: DocHyperLinkEdit.componentKey,
243
246
  direction: "bottom"
244
247
  }
245
248
  ), this._editPopup) : null;
246
249
  }
247
250
  hideEditPopup() {
248
- var t;
249
- this._editingLink$.next(null), (t = this._editPopup) == null || t.dispose();
251
+ var _a8;
252
+ this._editingLink$.next(null), (_a8 = this._editPopup) == null || _a8.dispose();
250
253
  }
251
- showInfoPopup(t) {
252
- var a, p, u, f;
253
- const { linkId: i, unitId: n, rangeIndex: r } = t;
254
- if (((a = this.showing) == null ? void 0 : a.linkId) === i && ((p = this.showing) == null ? void 0 : p.unitId) === n && this.showing.rangeIndex === r)
254
+ showInfoPopup(info) {
255
+ var _a8, _b, _c, _d;
256
+ const { linkId, unitId, rangeIndex } = info;
257
+ if (((_a8 = this.showing) == null ? void 0 : _a8.linkId) === linkId && ((_b = this.showing) == null ? void 0 : _b.unitId) === unitId && this.showing.rangeIndex === rangeIndex)
255
258
  return;
256
259
  this._infoPopup && this._infoPopup.dispose();
257
- const o = this._docHyperLinkModel.getLink(n, i), c = this._univerInstanceService.getUnit(n, _.UNIVER_DOC);
258
- if (!c || !o)
260
+ const link = this._docHyperLinkModel.getLink(unitId, linkId), doc = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
261
+ if (!doc || !link)
259
262
  return;
260
- const s = (f = (u = c.getBody()) == null ? void 0 : u.customRanges) == null ? void 0 : f[r];
261
- if (this._showingLink$.next({ unitId: n, linkId: i, rangeIndex: r }), !!s)
263
+ const range = (_d = (_c = doc.getBody()) == null ? void 0 : _c.customRanges) == null ? void 0 : _d[rangeIndex];
264
+ if (this._showingLink$.next({ unitId, linkId, rangeIndex }), !!range)
262
265
  return this._infoPopup = this._docCanvasPopupManagerService.attachPopupToRange(
263
266
  {
264
267
  collapsed: !1,
265
- startOffset: s.startIndex,
266
- endOffset: s.endIndex + 1
268
+ startOffset: range.startIndex,
269
+ endOffset: range.endIndex + 1
267
270
  },
268
271
  {
269
- componentKey: Y.componentKey,
272
+ componentKey: DocLinkPopup.componentKey,
270
273
  direction: "top",
271
274
  closeOnSelfTarget: !0,
272
- onClickOutside: () => {
275
+ onClickOutside: /* @__PURE__ */ __name(() => {
273
276
  this.hideInfoPopup();
274
- }
277
+ }, "onClickOutside")
275
278
  }
276
279
  ), this._infoPopup;
277
280
  }
278
281
  hideInfoPopup() {
279
- var t;
280
- this._showingLink$.next(null), (t = this._infoPopup) == null || t.dispose();
282
+ var _a8;
283
+ this._showingLink$.next(null), (_a8 = this._infoPopup) == null || _a8.dispose();
281
284
  }
282
- };
283
- S = Dt([
284
- D(0, m(at)),
285
- D(1, m(A)),
286
- D(2, m(H)),
287
- D(3, $),
288
- D(4, O)
289
- ], S);
290
- const Ee = {
291
- type: z.COMMAND,
285
+ }, __name(_a, "DocHyperLinkPopupService"), _a);
286
+ DocHyperLinkPopupService = __decorateClass$6([
287
+ __decorateParam$6(0, Inject(DocCanvasPopManagerService)),
288
+ __decorateParam$6(1, Inject(TextSelectionManagerService)),
289
+ __decorateParam$6(2, Inject(DocHyperLinkModel)),
290
+ __decorateParam$6(3, IUniverInstanceService),
291
+ __decorateParam$6(4, ICommandService)
292
+ ], DocHyperLinkPopupService);
293
+ const AddDocHyperLinkCommand = {
294
+ type: CommandType.COMMAND,
292
295
  id: "docs.command.add-hyper-link",
293
- async handler(e, t) {
294
- if (!t)
296
+ async handler(accessor, params) {
297
+ if (!params)
295
298
  return !1;
296
- const { payload: i, unitId: n } = t, r = e.get(O), o = De(), c = rt(
297
- e,
299
+ const { payload, unitId } = params, commandService = accessor.get(ICommandService), id = generateRandomId(), doMutation = addCustomRangeBySelectionFactory(
300
+ accessor,
298
301
  {
299
- rangeId: o,
300
- rangeType: P.HYPERLINK
302
+ rangeId: id,
303
+ rangeType: CustomRangeType.HYPERLINK
301
304
  }
302
305
  );
303
- if (c) {
304
- const s = {
305
- id: He.id,
306
- params: { unitId: n, link: { payload: i, id: o } }
306
+ if (doMutation) {
307
+ const hyperLinkMutation = {
308
+ id: AddDocHyperLinkMutation.id,
309
+ params: { unitId, link: { payload, id } }
307
310
  };
308
- return (await Ne([s, c], r)).result;
311
+ return (await sequenceExecuteAsync([hyperLinkMutation, doMutation], commandService)).result;
309
312
  }
310
313
  return !1;
311
314
  }
312
- }, Me = {
315
+ }, UpdateDocHyperLinkCommand = {
313
316
  id: "docs.command.update-hyper-link",
314
- type: z.COMMAND,
315
- handler(e, t) {
316
- return t ? e.get(O).syncExecuteCommand(Ae.id, t) : !1;
317
+ type: CommandType.COMMAND,
318
+ handler(accessor, params) {
319
+ return params ? accessor.get(ICommandService).syncExecuteCommand(UpdateDocHyperLinkMutation.id, params) : !1;
317
320
  }
318
- }, Nt = "univer-docs-link-edit", Ut = "univer-docs-link-edit-title", $t = "univer-docs-link-edit-close", Tt = "univer-docs-link-edit-buttons", Ht = "univer-docs-link-edit-button", M = {
319
- docsLinkEdit: Nt,
320
- docsLinkEditTitle: Ut,
321
- docsLinkEditClose: $t,
322
- docsLinkEditButtons: Tt,
323
- docsLinkEditButton: Ht
321
+ }, 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 = {
322
+ docsLinkEdit,
323
+ docsLinkEditTitle,
324
+ docsLinkEditClose,
325
+ docsLinkEditButtons,
326
+ docsLinkEditButton
324
327
  };
325
- function At(e) {
326
- return /^[a-zA-Z]+:\/\//.test(e);
328
+ function hasProtocol(urlString) {
329
+ return /^[a-zA-Z]+:\/\//.test(urlString);
327
330
  }
328
- function jt(e) {
329
- return /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(e);
331
+ __name(hasProtocol, "hasProtocol");
332
+ function isEmail(url) {
333
+ return /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(url);
330
334
  }
331
- function Bt(e) {
332
- return At(e) ? e : jt(e) ? `mailto://${e}` : `https://${e}`;
335
+ __name(isEmail, "isEmail");
336
+ function transformUrl(urlStr) {
337
+ return hasProtocol(urlStr) ? urlStr : isEmail(urlStr) ? `mailto://${urlStr}` : `https://${urlStr}`;
333
338
  }
334
- const Z = () => {
335
- const e = g(S), t = g(ge), i = g(H), n = nt(e.editingLink$), r = g(O), o = g($), c = g(Be), s = g(A), [a, p] = de(""), [u, f] = de(!1), l = ve.isLegalUrl(a), h = n ? o.getUnit(n.unitId, _.UNIVER_DOC) : o.getCurrentUnitForType(_.UNIVER_DOC);
336
- le(() => {
337
- var ie, re, oe, ce;
338
- if (n) {
339
- const I = n ? i.getLink(n.unitId, n.linkId) : null;
340
- p((ie = I == null ? void 0 : I.payload) != null ? ie : "");
339
+ __name(transformUrl, "transformUrl");
340
+ const DocHyperLinkEdit = /* @__PURE__ */ __name(() => {
341
+ const hyperLinkService = useDependency(DocHyperLinkPopupService), localeService = useDependency(LocaleService), hyperLinkModel = useDependency(DocHyperLinkModel), editingId = useObservable$1(hyperLinkService.editingLink$), commandService = useDependency(ICommandService), univerInstanceService = useDependency(IUniverInstanceService), textSelectionRenderManager = useDependency(ITextSelectionRenderManager), textSelectionManagerService = useDependency(TextSelectionManagerService), [link, setLink] = useState(""), [showError, setShowError] = useState(!1), isLegal = Tools.isLegalUrl(link), doc = editingId ? univerInstanceService.getUnit(editingId.unitId, UniverInstanceType.UNIVER_DOC) : univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
342
+ useEffect(() => {
343
+ var _a8, _b, _c, _d;
344
+ if (editingId) {
345
+ const linkDetail = editingId ? hyperLinkModel.getLink(editingId.unitId, editingId.linkId) : null;
346
+ setLink((_a8 = linkDetail == null ? void 0 : linkDetail.payload) != null ? _a8 : "");
341
347
  return;
342
348
  }
343
- const L = s.getActiveRange();
344
- if (!L)
349
+ const activeRange = textSelectionManagerService.getActiveRange();
350
+ if (!activeRange)
345
351
  return;
346
- const w = o.getCurrentUnitForType(_.UNIVER_DOC), ne = (oe = (re = w == null ? void 0 : w.getBody()) == null ? void 0 : re.customRanges) == null ? void 0 : oe.find((I) => Math.max(L.startOffset, I.startIndex) <= Math.min(L.endOffset - 1, I.endIndex));
347
- if (w && ne) {
348
- const I = i.getLink(w.getUnitId(), ne.rangeId);
349
- p((ce = I == null ? void 0 : I.payload) != null ? ce : "");
352
+ const doc2 = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC), matchedRange = (_c = (_b = doc2 == null ? void 0 : doc2.getBody()) == null ? void 0 : _b.customRanges) == null ? void 0 : _c.find((i) => Math.max(activeRange.startOffset, i.startIndex) <= Math.min(activeRange.endOffset - 1, i.endIndex));
353
+ if (doc2 && matchedRange) {
354
+ const linkDetail = hyperLinkModel.getLink(doc2.getUnitId(), matchedRange.rangeId);
355
+ setLink((_d = linkDetail == null ? void 0 : linkDetail.payload) != null ? _d : "");
350
356
  }
351
- }, [n, i, s, o]), le(() => (c.blur(), () => {
352
- c.focus();
353
- }), [c]);
354
- const C = () => {
355
- e.hideEditPopup();
356
- }, k = () => {
357
- if (f(!0), !l || !h)
357
+ }, [editingId, hyperLinkModel, textSelectionManagerService, univerInstanceService]), useEffect(() => (textSelectionRenderManager.blurEditor(), () => {
358
+ textSelectionRenderManager.focusEditor();
359
+ }), [textSelectionRenderManager]);
360
+ const handleCancel = /* @__PURE__ */ __name(() => {
361
+ hyperLinkService.hideEditPopup();
362
+ }, "handleCancel"), handleConfirm = /* @__PURE__ */ __name(() => {
363
+ if (setShowError(!0), !isLegal || !doc)
358
364
  return;
359
- const L = Bt(a);
360
- n ? r.executeCommand(Me.id, {
361
- unitId: h.getUnitId(),
362
- payload: L,
363
- linkId: n.linkId
364
- }) : r.executeCommand(Ee.id, {
365
- unitId: h.getUnitId(),
366
- payload: L
367
- }), e.hideEditPopup();
368
- };
369
- if (h)
370
- return /* @__PURE__ */ d.createElement("div", { className: M.docsLinkEdit }, /* @__PURE__ */ d.createElement("div", { className: M.docsLinkEditTitle }, /* @__PURE__ */ d.createElement("span", null, t.t("docLink.edit.title")), /* @__PURE__ */ d.createElement(Ce, { className: M.docsLinkEditClose, onClick: C })), /* @__PURE__ */ d.createElement("div", null, /* @__PURE__ */ d.createElement(
371
- Qe,
365
+ const linkFinal = transformUrl(link);
366
+ editingId ? commandService.executeCommand(UpdateDocHyperLinkCommand.id, {
367
+ unitId: doc.getUnitId(),
368
+ payload: linkFinal,
369
+ linkId: editingId.linkId
370
+ }) : commandService.executeCommand(AddDocHyperLinkCommand.id, {
371
+ unitId: doc.getUnitId(),
372
+ payload: linkFinal
373
+ }), hyperLinkService.hideEditPopup();
374
+ }, "handleConfirm");
375
+ if (doc)
376
+ return /* @__PURE__ */ React.createElement("div", { className: styles.docsLinkEdit }, /* @__PURE__ */ React.createElement("div", { className: styles.docsLinkEditTitle }, /* @__PURE__ */ React.createElement("span", null, localeService.t("docLink.edit.title")), /* @__PURE__ */ React.createElement(CloseSingle, { className: styles.docsLinkEditClose, onClick: handleCancel })), /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(
377
+ FormLayout,
372
378
  {
373
- label: t.t("docLink.edit.address"),
374
- error: u && !l ? t.t("docLink.edit.addressError") : ""
379
+ label: localeService.t("docLink.edit.address"),
380
+ error: showError && !isLegal ? localeService.t("docLink.edit.addressError") : ""
375
381
  },
376
- /* @__PURE__ */ d.createElement(et, { value: a, onChange: p, autoFocus: !0 })
377
- )), /* @__PURE__ */ d.createElement("div", { className: M.docsLinkEditButtons }, /* @__PURE__ */ d.createElement(
378
- ae,
382
+ /* @__PURE__ */ React.createElement(Input, { value: link, onChange: setLink, autoFocus: !0 })
383
+ )), /* @__PURE__ */ React.createElement("div", { className: styles.docsLinkEditButtons }, /* @__PURE__ */ React.createElement(
384
+ Button,
379
385
  {
380
- className: M.docsLinkEditButton,
381
- onClick: C
386
+ className: styles.docsLinkEditButton,
387
+ onClick: handleCancel
382
388
  },
383
- t.t("docLink.edit.cancel")
384
- ), /* @__PURE__ */ d.createElement(
385
- ae,
389
+ localeService.t("docLink.edit.cancel")
390
+ ), /* @__PURE__ */ React.createElement(
391
+ Button,
386
392
  {
387
- disabled: !a,
388
- className: M.docsLinkEditButton,
393
+ disabled: !link,
394
+ className: styles.docsLinkEditButton,
389
395
  type: "primary",
390
- onClick: k
396
+ onClick: handleConfirm
391
397
  },
392
- t.t("docLink.edit.confirm")
398
+ localeService.t("docLink.edit.confirm")
393
399
  )));
394
- };
395
- Z.componentKey = "docs-hyper-link-edit";
396
- const Pe = "doc-hyper-link-icon";
397
- function Kt(e) {
400
+ }, "DocHyperLinkEdit");
401
+ DocHyperLinkEdit.componentKey = "docs-hyper-link-edit";
402
+ const DOC_LINK_ICON = "doc-hyper-link-icon";
403
+ function AddHyperLinkMenuItemFactory(accessor) {
398
404
  return {
399
- id: G.id,
400
- group: Ze.TOOLBAR_LAYOUT,
401
- type: We.BUTTON,
402
- icon: Pe,
405
+ id: ShowDocHyperLinkEditPopupOperation.id,
406
+ group: MenuGroup.CONTEXT_MENU_DATA,
407
+ type: MenuItemType.BUTTON,
408
+ icon: DOC_LINK_ICON,
403
409
  title: "docLink.menu.tooltip",
404
410
  tooltip: "docLink.menu.tooltip",
405
- positions: [se.TOOLBAR_START, se.CONTEXT_MENU],
406
- hidden$: ze(e, _.UNIVER_DOC),
407
- disabled$: new ut(function(t) {
408
- const n = e.get(A).textSelection$.pipe(pt(16)).subscribe(() => {
409
- t.next(Oe(e));
411
+ positions: [MenuPosition.TOOLBAR_START, MenuPosition.CONTEXT_MENU],
412
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
413
+ disabled$: new Observable(function(subscribe) {
414
+ const observer = accessor.get(TextSelectionManagerService).textSelection$.pipe(debounceTime(16)).subscribe(() => {
415
+ subscribe.next(shouldDisableAddLink(accessor));
410
416
  });
411
417
  return () => {
412
- n.unsubscribe();
418
+ observer.unsubscribe();
413
419
  };
414
420
  })
415
421
  };
416
422
  }
417
- const Vt = {
418
- id: G.id,
419
- binding: Fe.CTRL_COMMAND | Ye.K,
423
+ __name(AddHyperLinkMenuItemFactory, "AddHyperLinkMenuItemFactory");
424
+ const addLinkShortcut = {
425
+ id: ShowDocHyperLinkEditPopupOperation.id,
426
+ binding: MetaKeys.CTRL_COMMAND | KeyCode.K,
420
427
  description: "docLink.menu.tooltip",
421
- preconditions: dt
428
+ preconditions: whenDocAndEditorFocused
422
429
  };
423
- var Ft = Object.defineProperty, Yt = Object.getOwnPropertyDescriptor, Zt = (e, t, i, n) => {
424
- for (var r = n > 1 ? void 0 : n ? Yt(t, i) : t, o = e.length - 1, c; o >= 0; o--)
425
- (c = e[o]) && (r = (n ? c(t, i, r) : c(r)) || r);
426
- return n && r && Ft(t, i, r), r;
427
- }, N = (e, t) => (i, n) => t(i, n, e);
428
- let U = class extends T {
429
- constructor(e, t, i, n, r, o) {
430
- super(), this._config = e, this._componentManager = t, this._commandService = i, this._menuService = n, this._injector = r, this._shortcutService = o, this._initComponents(), this._initCommands(), this._initMenus(), this._initShortcut();
430
+ var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
431
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
432
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
433
+ return kind && result && __defProp$5(target, key, result), result;
434
+ }, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$5"), _a2;
435
+ let DocHyperLinkUIController = (_a2 = class extends Disposable {
436
+ constructor(_config, _componentManager, _commandService, _menuService, _injector, _shortcutService) {
437
+ super(), this._config = _config, this._componentManager = _componentManager, this._commandService = _commandService, this._menuService = _menuService, this._injector = _injector, this._shortcutService = _shortcutService, this._initComponents(), this._initCommands(), this._initMenus(), this._initShortcut();
431
438
  }
432
439
  _initComponents() {
433
440
  [
434
- [Z, Z.componentKey],
435
- [Y, Y.componentKey],
436
- [te, Pe]
437
- ].forEach(([e, t]) => {
438
- this._componentManager.register(t, e);
441
+ [DocHyperLinkEdit, DocHyperLinkEdit.componentKey],
442
+ [DocLinkPopup, DocLinkPopup.componentKey],
443
+ [LinkSingle, DOC_LINK_ICON]
444
+ ].forEach(([comp, key]) => {
445
+ this._componentManager.register(key, comp);
439
446
  });
440
447
  }
441
448
  _initCommands() {
442
449
  [
443
- Ee,
444
- Me,
445
- Se,
446
- G
447
- ].forEach((e) => {
448
- this._commandService.registerCommand(e);
450
+ AddDocHyperLinkCommand,
451
+ UpdateDocHyperLinkCommand,
452
+ DeleteDocHyperLinkCommand,
453
+ ShowDocHyperLinkEditPopupOperation
454
+ ].forEach((command) => {
455
+ this._commandService.registerCommand(command);
449
456
  });
450
457
  }
451
458
  _initShortcut() {
452
- [Vt].forEach((e) => {
453
- this._shortcutService.registerShortcut(e);
459
+ [addLinkShortcut].forEach((shortcut) => {
460
+ this._shortcutService.registerShortcut(shortcut);
454
461
  });
455
462
  }
456
463
  _initMenus() {
457
- [Kt].forEach((e) => {
458
- this.disposeWithMe(this._menuService.addMenuItem(e(this._injector), {}));
464
+ [AddHyperLinkMenuItemFactory].forEach((menuFactory) => {
465
+ this.disposeWithMe(this._menuService.addMenuItem(menuFactory(this._injector), {}));
459
466
  });
460
467
  }
461
- };
462
- U = Zt([
463
- J(Q.Starting, U),
464
- N(1, m(Ge)),
465
- N(2, O),
466
- N(3, qe),
467
- N(4, m(me)),
468
- N(5, Xe)
469
- ], U);
470
- var Wt = Object.defineProperty, zt = Object.getOwnPropertyDescriptor, Gt = (e, t, i, n) => {
471
- for (var r = n > 1 ? void 0 : n ? zt(t, i) : t, o = e.length - 1, c; o >= 0; o--)
472
- (c = e[o]) && (r = (n ? c(t, i, r) : c(r)) || r);
473
- return n && r && Wt(t, i, r), r;
474
- }, B = (e, t) => (i, n) => t(i, n, e);
475
- let V = class extends T {
476
- constructor(e, t, i, n) {
477
- super(), this._commandService = e, this._univerInstanceService = t, this._docHyperLinkService = i, this._renderMangerService = n, this._initSelectionChange();
468
+ }, __name(_a2, "DocHyperLinkUIController"), _a2);
469
+ DocHyperLinkUIController = __decorateClass$5([
470
+ OnLifecycle(LifecycleStages.Starting, DocHyperLinkUIController),
471
+ __decorateParam$5(1, Inject(ComponentManager)),
472
+ __decorateParam$5(2, ICommandService),
473
+ __decorateParam$5(3, IMenuService),
474
+ __decorateParam$5(4, Inject(Injector)),
475
+ __decorateParam$5(5, IShortcutService)
476
+ ], DocHyperLinkUIController);
477
+ var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
478
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
479
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
480
+ return kind && result && __defProp$4(target, key, result), result;
481
+ }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a3;
482
+ let DocHyperLinkSelectionController = (_a3 = class extends Disposable {
483
+ constructor(_commandService, _univerInstanceService, _docHyperLinkService, _renderMangerService) {
484
+ super(), this._commandService = _commandService, this._univerInstanceService = _univerInstanceService, this._docHyperLinkService = _docHyperLinkService, this._renderMangerService = _renderMangerService, this._initSelectionChange();
478
485
  }
479
486
  _initSelectionChange() {
480
487
  this.disposeWithMe(
481
- this._commandService.onCommandExecuted((e) => {
482
- var t, i;
483
- if (e.id === ot.id) {
484
- const n = e.params, { unitId: r, ranges: o } = n, c = this._renderMangerService.getRenderById(r), s = c == null ? void 0 : c.with(Le).getSkeleton();
485
- if ((s == null ? void 0 : s.getViewModel().getEditArea()) !== q.BODY) {
488
+ this._commandService.onCommandExecuted((commandInfo) => {
489
+ var _a8, _b;
490
+ if (commandInfo.id === SetTextSelectionsOperation.id) {
491
+ const params = commandInfo.params, { unitId, ranges } = params, render2 = this._renderMangerService.getRenderById(unitId), skeleton = render2 == null ? void 0 : render2.with(DocSkeletonManagerService).getSkeleton();
492
+ if ((skeleton == null ? void 0 : skeleton.getViewModel().getEditArea()) !== DocumentEditArea.BODY) {
486
493
  this._docHyperLinkService.hideInfoPopup(), this._docHyperLinkService.hideEditPopup();
487
494
  return;
488
495
  }
489
- const p = this._univerInstanceService.getUnit(r, _.UNIVER_DOC), u = o[0];
490
- if (u && p) {
491
- const { startOffset: f, endOffset: l, collapsed: h } = u, C = (t = p.getBody()) == null ? void 0 : t.customRanges;
492
- if (h) {
493
- const k = (i = C == null ? void 0 : C.findIndex((L) => L.startIndex < f && L.endIndex > l - 1)) != null ? i : -1;
494
- if (k > -1) {
495
- const L = C[k];
496
- this._docHyperLinkService.showInfoPopup({ unitId: r, linkId: L.rangeId, rangeIndex: k });
496
+ const doc = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC), primary = ranges[0];
497
+ if (primary && doc) {
498
+ const { startOffset, endOffset, collapsed } = primary, customRanges = (_a8 = doc.getBody()) == null ? void 0 : _a8.customRanges;
499
+ if (collapsed) {
500
+ const index = (_b = customRanges == null ? void 0 : customRanges.findIndex((value) => value.startIndex < startOffset && value.endIndex > endOffset - 1)) != null ? _b : -1;
501
+ if (index > -1) {
502
+ const customRange = customRanges[index];
503
+ this._docHyperLinkService.showInfoPopup({ unitId, linkId: customRange.rangeId, rangeIndex: index });
497
504
  return;
498
505
  }
499
- } else if (C != null && C.find((k) => k.startIndex <= f && k.endIndex >= l - 1))
506
+ } else if (customRanges != null && customRanges.find((value) => value.startIndex <= startOffset && value.endIndex >= endOffset - 1))
500
507
  return;
501
508
  }
502
509
  this._docHyperLinkService.hideInfoPopup(), this._docHyperLinkService.hideEditPopup();
@@ -504,144 +511,220 @@ let V = class extends T {
504
511
  })
505
512
  );
506
513
  }
507
- };
508
- V = Gt([
509
- J(Q.Ready, V),
510
- B(0, O),
511
- B(1, $),
512
- B(2, m(S)),
513
- B(3, ee)
514
- ], V);
515
- var qt = Object.defineProperty, Xt = Object.getOwnPropertyDescriptor, Jt = (e, t, i, n) => {
516
- for (var r = n > 1 ? void 0 : n ? Xt(t, i) : t, o = e.length - 1, c; o >= 0; o--)
517
- (c = e[o]) && (r = (n ? c(t, i, r) : c(r)) || r);
518
- return n && r && qt(t, i, r), r;
519
- }, fe = (e, t) => (i, n) => t(i, n, e);
520
- let X = class extends T {
521
- constructor(e, t, i) {
522
- super(), this._context = e, this._docInterceptorService = t, this._hyperLinkService = i, this._init();
514
+ }, __name(_a3, "DocHyperLinkSelectionController"), _a3);
515
+ DocHyperLinkSelectionController = __decorateClass$4([
516
+ OnLifecycle(LifecycleStages.Ready, DocHyperLinkSelectionController),
517
+ __decorateParam$4(0, ICommandService),
518
+ __decorateParam$4(1, IUniverInstanceService),
519
+ __decorateParam$4(2, Inject(DocHyperLinkPopupService)),
520
+ __decorateParam$4(3, IRenderManagerService)
521
+ ], DocHyperLinkSelectionController);
522
+ var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
523
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
524
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
525
+ return kind && result && __defProp$3(target, key, result), result;
526
+ }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a4;
527
+ let DocHyperLinkRenderController = (_a4 = class extends Disposable {
528
+ constructor(_context, _docInterceptorService, _hyperLinkService) {
529
+ super(), this._context = _context, this._docInterceptorService = _docInterceptorService, this._hyperLinkService = _hyperLinkService, this._init();
523
530
  }
524
531
  _init() {
525
- this._docInterceptorService.intercept(st.CUSTOM_RANGE, {
526
- handler: (e, t, i) => {
527
- if (!e)
528
- return i(e);
529
- const { unitId: n } = t, r = this._hyperLinkService.showing, { linkId: o, unitId: c } = r || {}, s = c === n && e.rangeId === o;
530
- return i({
531
- ...e,
532
- active: s
532
+ this._docInterceptorService.intercept(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE, {
533
+ handler: /* @__PURE__ */ __name((data, pos, next) => {
534
+ if (!data)
535
+ return next(data);
536
+ const { unitId } = pos, activeLink = this._hyperLinkService.showing, { linkId, unitId: linkUnitId } = activeLink || {}, isActive = linkUnitId === unitId && data.rangeId === linkId;
537
+ return next({
538
+ ...data,
539
+ active: isActive
533
540
  });
534
- }
541
+ }, "handler")
535
542
  });
536
543
  }
537
- };
538
- X = Jt([
539
- fe(1, m(ct)),
540
- fe(2, m(S))
541
- ], X);
542
- var Qt = Object.defineProperty, en = Object.getOwnPropertyDescriptor, tn = (e, t, i, n) => {
543
- for (var r = n > 1 ? void 0 : n ? en(t, i) : t, o = e.length - 1, c; o >= 0; o--)
544
- (c = e[o]) && (r = (n ? c(t, i, r) : c(r)) || r);
545
- return n && r && Qt(t, i, r), r;
546
- }, K = (e, t) => (i, n) => t(i, n, e);
547
- let F = class extends T {
548
- constructor(e, t, i, n) {
549
- super(), this._docClipboardService = e, this._univerInstanceService = t, this._hyperLinkModel = i, this._textSelectionManagerService = n, this._initClipboard();
544
+ }, __name(_a4, "DocHyperLinkRenderController"), _a4);
545
+ DocHyperLinkRenderController = __decorateClass$3([
546
+ __decorateParam$3(1, Inject(DocInterceptorService)),
547
+ __decorateParam$3(2, Inject(DocHyperLinkPopupService))
548
+ ], DocHyperLinkRenderController);
549
+ var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
550
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
551
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
552
+ return kind && result && __defProp$2(target, key, result), result;
553
+ }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a5;
554
+ let DocHyperLinkClipboardController = (_a5 = class extends Disposable {
555
+ constructor(_docClipboardService, _univerInstanceService, _hyperLinkModel, _textSelectionManagerService, _commandService) {
556
+ super(), this._docClipboardService = _docClipboardService, this._univerInstanceService = _univerInstanceService, this._hyperLinkModel = _hyperLinkModel, this._textSelectionManagerService = _textSelectionManagerService, this._commandService = _commandService, this._initClipboard();
550
557
  }
551
558
  _initClipboard() {
552
559
  this.disposeWithMe(this._docClipboardService.addClipboardHook({
553
- onBeforePaste: (e) => {
554
- var o, c;
555
- const t = this._univerInstanceService.getCurrentUnitForType(_.UNIVER_DOC);
556
- if (!t)
557
- return e;
558
- const i = this._textSelectionManagerService.getActiveRange(), n = (o = t.getBody()) == null ? void 0 : o.customRanges;
559
- if (i ? n == null ? void 0 : n.find(
560
- (s) => s.rangeType === P.HYPERLINK && s.startIndex <= i.startOffset && s.endIndex >= i.endOffset - 1
560
+ onBeforePaste: /* @__PURE__ */ __name((body) => {
561
+ var _a8, _b;
562
+ const doc = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
563
+ if (!doc)
564
+ return body;
565
+ const activeRange = this._textSelectionManagerService.getActiveRange(), customRanges = (_a8 = doc.getBody()) == null ? void 0 : _a8.customRanges;
566
+ if (activeRange ? customRanges == null ? void 0 : customRanges.find(
567
+ (range) => range.rangeType === CustomRangeType.HYPERLINK && range.startIndex <= activeRange.startOffset && range.endIndex >= activeRange.endOffset - 1
561
568
  ) : null) {
562
- const { customRanges: s = [], ...a } = e, u = s.filter((l) => l.rangeType === P.HYPERLINK).map((l) => [l.startIndex, l.endIndex]).flat().sort((l, h) => l - h), f = {
563
- ...a,
564
- customRanges: s.filter((l) => l.rangeType !== P.HYPERLINK)
569
+ const { customRanges: customRanges2 = [], ...extBody } = body, deleteIndexes = customRanges2.filter((range) => range.rangeType === CustomRangeType.HYPERLINK).map((i) => [i.startIndex, i.endIndex]).flat().sort((pre, aft) => pre - aft), bodyWithoutLink = {
570
+ ...extBody,
571
+ customRanges: customRanges2.filter((range) => range.rangeType !== CustomRangeType.HYPERLINK)
565
572
  };
566
- for (let l = 0; l < u.length; l++)
567
- Ue(f, 1, u[l] - l);
568
- return f;
573
+ for (let i = 0; i < deleteIndexes.length; i++)
574
+ updateAttributeByDelete(bodyWithoutLink, 1, deleteIndexes[i] - i);
575
+ return bodyWithoutLink;
569
576
  } else {
570
- const s = new Set(n == null ? void 0 : n.map((a) => a.rangeType === P.HYPERLINK && a.rangeId));
571
- (c = e.customRanges) == null || c.forEach((a) => {
572
- var p;
573
- if (a.rangeType === P.HYPERLINK) {
574
- if (s.has(a.rangeId)) {
575
- const u = this._hyperLinkModel.getLink(t.getUnitId(), a.rangeId);
576
- if (u) {
577
- const f = ve.generateRandomId();
578
- this._hyperLinkModel.addLink(t.getUnitId(), {
579
- payload: u.payload,
580
- id: f
581
- }), a.rangeId = f;
577
+ const unitId = doc.getUnitId(), customRangeIds = new Set(customRanges == null ? void 0 : customRanges.map((i) => i.rangeType === CustomRangeType.HYPERLINK && i.rangeId));
578
+ (_b = body.customRanges) == null || _b.forEach((range) => {
579
+ var _a9;
580
+ if (range.rangeType === CustomRangeType.HYPERLINK) {
581
+ if (customRangeIds.has(range.rangeId)) {
582
+ const link = this._hyperLinkModel.getLink(unitId, range.rangeId);
583
+ if (link) {
584
+ const newId = Tools.generateRandomId();
585
+ this._commandService.executeCommand(
586
+ AddDocHyperLinkMutation.id,
587
+ {
588
+ unitId,
589
+ link: {
590
+ id: newId,
591
+ payload: link.payload
592
+ }
593
+ }
594
+ ), range.rangeId = newId;
582
595
  }
583
- } else if ((p = e.payloads) != null && p[a.rangeId]) {
584
- const u = e.payloads[a.rangeId];
585
- this._hyperLinkModel.addLink(t.getUnitId(), {
586
- payload: u,
587
- id: a.rangeId
588
- });
596
+ } else if ((_a9 = body.payloads) != null && _a9[range.rangeId]) {
597
+ const url = body.payloads[range.rangeId];
598
+ this._commandService.executeCommand(
599
+ AddDocHyperLinkMutation.id,
600
+ {
601
+ unitId,
602
+ link: {
603
+ id: range.rangeId,
604
+ payload: url
605
+ }
606
+ }
607
+ );
589
608
  }
590
609
  }
591
610
  });
592
611
  }
593
- return e;
594
- }
612
+ return body;
613
+ }, "onBeforePaste")
595
614
  }));
596
615
  }
597
- };
598
- F = tn([
599
- J(Q.Ready, F),
600
- K(0, m(lt)),
601
- K(1, $),
602
- K(2, m(H)),
603
- K(3, m(A))
604
- ], F);
605
- var xe = Object.defineProperty, nn = Object.getOwnPropertyDescriptor, rn = (e, t, i) => t in e ? xe(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i, on = (e, t, i, n) => {
606
- for (var r = n > 1 ? void 0 : n ? nn(t, i) : t, o = e.length - 1, c; o >= 0; o--)
607
- (c = e[o]) && (r = (n ? c(t, i, r) : c(r)) || r);
608
- return n && r && xe(t, i, r), r;
609
- }, he = (e, t) => (i, n) => t(i, n, e), Re = (e, t, i) => rn(e, typeof t != "symbol" ? t + "" : t, i);
610
- let W = class extends Te {
611
- constructor(e = { menu: {} }, t, i) {
612
- super(), this._config = e, this._injector = t, this._renderManagerSrv = i;
616
+ }, __name(_a5, "DocHyperLinkClipboardController"), _a5);
617
+ DocHyperLinkClipboardController = __decorateClass$2([
618
+ OnLifecycle(LifecycleStages.Ready, DocHyperLinkClipboardController),
619
+ __decorateParam$2(0, Inject(IDocClipboardService)),
620
+ __decorateParam$2(1, IUniverInstanceService),
621
+ __decorateParam$2(2, Inject(DocHyperLinkModel)),
622
+ __decorateParam$2(3, Inject(TextSelectionManagerService)),
623
+ __decorateParam$2(4, ICommandService)
624
+ ], DocHyperLinkClipboardController);
625
+ var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
626
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
627
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
628
+ return kind && result && __defProp$1(target, key, result), result;
629
+ }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a6;
630
+ let DocHyperLinkCustomRangeController = (_a6 = class extends Disposable {
631
+ constructor(_docCustomRangeService, _docHyperLinkModel, _commandService) {
632
+ super(), this._docCustomRangeService = _docCustomRangeService, this._docHyperLinkModel = _docHyperLinkModel, this._commandService = _commandService, this._initCustomRangeHooks();
613
633
  }
614
- onStarting(e) {
634
+ _initCustomRangeHooks() {
635
+ this.disposeWithMe(
636
+ this._docCustomRangeService.addClipboardHook({
637
+ onCopyCustomRange: /* @__PURE__ */ __name((unitId, range) => {
638
+ const { rangeId, rangeType, data, ...ext } = range;
639
+ if (rangeType === CustomRangeType.HYPERLINK) {
640
+ if (data) {
641
+ const id = Tools.generateRandomId();
642
+ return this._commandService.executeCommand(
643
+ AddDocHyperLinkMutation.id,
644
+ {
645
+ unitId,
646
+ link: {
647
+ id,
648
+ payload: data
649
+ }
650
+ }
651
+ ), {
652
+ ...range,
653
+ rangeId: id
654
+ };
655
+ }
656
+ const link = this._docHyperLinkModel.getLink(unitId, rangeId);
657
+ if (!link)
658
+ return range;
659
+ const newId = Tools.generateRandomId();
660
+ return this._commandService.executeCommand(
661
+ AddDocHyperLinkMutation.id,
662
+ {
663
+ unitId,
664
+ link: {
665
+ id: newId,
666
+ payload: link.payload
667
+ }
668
+ }
669
+ ), {
670
+ ...ext,
671
+ rangeId: newId,
672
+ rangeType
673
+ };
674
+ }
675
+ return range;
676
+ }, "onCopyCustomRange")
677
+ })
678
+ );
679
+ }
680
+ }, __name(_a6, "DocHyperLinkCustomRangeController"), _a6);
681
+ DocHyperLinkCustomRangeController = __decorateClass$1([
682
+ OnLifecycle(LifecycleStages.Ready, DocHyperLinkCustomRangeController),
683
+ __decorateParam$1(0, Inject(DocCustomRangeService)),
684
+ __decorateParam$1(1, Inject(DocHyperLinkModel)),
685
+ __decorateParam$1(2, ICommandService)
686
+ ], DocHyperLinkCustomRangeController);
687
+ 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) => {
688
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
689
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
690
+ return kind && result && __defProp2(target, key, result), result;
691
+ }, "__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"), _a7;
692
+ let UniverDocsHyperLinkUIPlugin = (_a7 = class extends Plugin {
693
+ constructor(_config = { menu: {} }, _injector, _renderManagerSrv) {
694
+ super(), this._config = _config, this._injector = _injector, this._renderManagerSrv = _renderManagerSrv;
695
+ }
696
+ onStarting() {
615
697
  [
616
- [S],
698
+ [DocHyperLinkPopupService],
617
699
  [
618
- U,
700
+ DocHyperLinkUIController,
619
701
  {
620
- useFactory: () => this._injector.createInstance(U, this._config)
702
+ useFactory: /* @__PURE__ */ __name(() => this._injector.createInstance(DocHyperLinkUIController, this._config), "useFactory")
621
703
  }
622
704
  ],
623
- [V],
624
- [F]
625
- ].forEach((i) => {
626
- e.add(i);
705
+ [DocHyperLinkSelectionController],
706
+ [DocHyperLinkClipboardController],
707
+ [DocHyperLinkCustomRangeController]
708
+ ].forEach((dep) => {
709
+ this._injector.add(dep);
627
710
  });
628
711
  }
629
712
  onRendered() {
630
713
  this._initRenderModule();
631
714
  }
632
715
  _initRenderModule() {
633
- [X].forEach((e) => {
634
- this._renderManagerSrv.registerRenderModule(_.UNIVER_DOC, e);
716
+ [DocHyperLinkRenderController].forEach((dep) => {
717
+ this._renderManagerSrv.registerRenderModule(UniverInstanceType.UNIVER_DOC, dep);
635
718
  });
636
719
  }
637
- };
638
- Re(W, "pluginName", ft);
639
- Re(W, "type", _.UNIVER_DOC);
640
- W = on([
641
- $e(je),
642
- he(1, m(me)),
643
- he(2, ee)
644
- ], W);
720
+ }, __name(_a7, "UniverDocsHyperLinkUIPlugin"), _a7);
721
+ __publicField2(UniverDocsHyperLinkUIPlugin, "pluginName", DOC_HYPER_LINK_UI_PLUGIN);
722
+ __publicField2(UniverDocsHyperLinkUIPlugin, "type", UniverInstanceType.UNIVER_DOC);
723
+ UniverDocsHyperLinkUIPlugin = __decorateClass([
724
+ DependentOn(UniverDocsHyperLinkPlugin),
725
+ __decorateParam(1, Inject(Injector)),
726
+ __decorateParam(2, IRenderManagerService)
727
+ ], UniverDocsHyperLinkUIPlugin);
645
728
  export {
646
- W as UniverDocsHyperLinkUIPlugin
729
+ UniverDocsHyperLinkUIPlugin
647
730
  };