@univerjs/docs-hyper-link-ui 0.2.5 → 0.2.7

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