@univerjs/docs-hyper-link-ui 0.2.5 → 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,215 +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 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, 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]);
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;
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)
114
119
  return !0;
115
- const a = i.getCurrentUnitForType(_.UNIVER_DOC);
116
- if (!a || !n || n.collapsed)
120
+ const 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 = (_a8 = doc.getBody()) == null ? void 0 : _a8.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"), _a;
208
+ let DocHyperLinkPopupService = (_a = class extends Disposable {
209
+ constructor(_docCanvasPopupManagerService, _textSelectionManagerService, _docHyperLinkModel, _univerInstanceService, _commandService) {
205
210
  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(() => {
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(() => {
213
218
  this._editingLink$.complete(), this._showingLink$.complete();
214
219
  });
215
220
  }
@@ -219,282 +224,286 @@ let S = class extends $ {
219
224
  get showing() {
220
225
  return this._showingLink$.value;
221
226
  }
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 = {
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 = {
229
234
  collapsed: !1,
230
- startOffset: a.startIndex,
231
- endOffset: a.endIndex + 1
235
+ startOffset: range.startIndex,
236
+ endOffset: range.endIndex + 1
232
237
  }, this._textSelectionManagerService.replaceTextRanges([{
233
- startOffset: a.startIndex,
234
- endOffset: a.endIndex + 1
238
+ startOffset: range.startIndex,
239
+ endOffset: range.endIndex + 1
235
240
  }]));
236
241
  }
237
- return i ? (this._editPopup = this._docCanvasPopupManagerService.attachPopupToRange(
238
- i,
242
+ return activeRange ? (this._editPopup = this._docCanvasPopupManagerService.attachPopupToRange(
243
+ activeRange,
239
244
  {
240
- componentKey: Z.componentKey,
245
+ componentKey: DocHyperLinkEdit.componentKey,
241
246
  direction: "bottom"
242
247
  }
243
248
  ), this._editPopup) : null;
244
249
  }
245
250
  hideEditPopup() {
246
- var t;
247
- this._editingLink$.next(null), (t = this._editPopup) == null || t.dispose();
251
+ var _a8;
252
+ this._editingLink$.next(null), (_a8 = this._editPopup) == null || _a8.dispose();
248
253
  }
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)
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)
253
258
  return;
254
259
  this._infoPopup && this._infoPopup.dispose();
255
- const o = this._docHyperLinkModel.getLink(n, i), c = this._univerInstanceService.getUnit(n, _.UNIVER_DOC);
256
- if (!c || !o)
260
+ const link = this._docHyperLinkModel.getLink(unitId, linkId), doc = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
261
+ if (!doc || !link)
257
262
  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)
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)
260
265
  return this._infoPopup = this._docCanvasPopupManagerService.attachPopupToRange(
261
266
  {
262
267
  collapsed: !1,
263
- startOffset: s.startIndex,
264
- endOffset: s.endIndex + 1
268
+ startOffset: range.startIndex,
269
+ endOffset: range.endIndex + 1
265
270
  },
266
271
  {
267
- componentKey: Y.componentKey,
272
+ componentKey: DocLinkPopup.componentKey,
268
273
  direction: "top",
269
274
  closeOnSelfTarget: !0,
270
- onClickOutside: () => {
275
+ onClickOutside: /* @__PURE__ */ __name(() => {
271
276
  this.hideInfoPopup();
272
- }
277
+ }, "onClickOutside")
273
278
  }
274
279
  ), this._infoPopup;
275
280
  }
276
281
  hideInfoPopup() {
277
- var t;
278
- this._showingLink$.next(null), (t = this._infoPopup) == null || t.dispose();
282
+ var _a8;
283
+ this._showingLink$.next(null), (_a8 = this._infoPopup) == null || _a8.dispose();
279
284
  }
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,
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,
290
295
  id: "docs.command.add-hyper-link",
291
- async handler(e, t) {
292
- if (!t)
296
+ async handler(accessor, params) {
297
+ if (!params)
293
298
  return !1;
294
- const { payload: i, unitId: n } = t, r = e.get(O), o = Ne(), c = rt(
295
- e,
299
+ const { payload, unitId } = params, commandService = accessor.get(ICommandService), id = generateRandomId(), doMutation = addCustomRangeBySelectionFactory(
300
+ accessor,
296
301
  {
297
- rangeId: o,
298
- rangeType: P.HYPERLINK
302
+ rangeId: id,
303
+ rangeType: CustomRangeType.HYPERLINK
299
304
  }
300
305
  );
301
- if (c) {
302
- const s = {
303
- id: Ae.id,
304
- params: { unitId: n, link: { payload: i, id: o } }
306
+ if (doMutation) {
307
+ const hyperLinkMutation = {
308
+ id: AddDocHyperLinkMutation.id,
309
+ params: { unitId, link: { payload, id } }
305
310
  };
306
- return (await De([s, c], r)).result;
311
+ return (await sequenceExecuteAsync([hyperLinkMutation, doMutation], commandService)).result;
307
312
  }
308
313
  return !1;
309
314
  }
310
- }, Me = {
315
+ }, UpdateDocHyperLinkCommand = {
311
316
  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;
317
+ type: CommandType.COMMAND,
318
+ handler(accessor, params) {
319
+ return params ? accessor.get(ICommandService).syncExecuteCommand(UpdateDocHyperLinkMutation.id, params) : !1;
315
320
  }
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
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
322
327
  };
323
- function At(e) {
324
- return /^[a-zA-Z]+:\/\//.test(e);
328
+ function hasProtocol(urlString) {
329
+ return /^[a-zA-Z]+:\/\//.test(urlString);
325
330
  }
326
- function jt(e) {
327
- 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);
328
334
  }
329
- function Bt(e) {
330
- 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}`;
331
338
  }
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 : "");
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 : "");
339
347
  return;
340
348
  }
341
- const L = s.getActiveRange();
342
- if (!L)
349
+ const activeRange = textSelectionManagerService.getActiveRange();
350
+ if (!activeRange)
343
351
  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 : "");
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 : "");
348
356
  }
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)
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)
356
364
  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,
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,
370
378
  {
371
- label: t.t("docLink.edit.address"),
372
- error: u && !l ? t.t("docLink.edit.addressError") : ""
379
+ label: localeService.t("docLink.edit.address"),
380
+ error: showError && !isLegal ? localeService.t("docLink.edit.addressError") : ""
373
381
  },
374
- /* @__PURE__ */ d.createElement(tt, { value: a, onChange: p, autoFocus: !0 })
375
- )), /* @__PURE__ */ d.createElement("div", { className: M.docsLinkEditButtons }, /* @__PURE__ */ d.createElement(
376
- 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,
377
385
  {
378
- className: M.docsLinkEditButton,
379
- onClick: C
386
+ className: styles.docsLinkEditButton,
387
+ onClick: handleCancel
380
388
  },
381
- t.t("docLink.edit.cancel")
382
- ), /* @__PURE__ */ d.createElement(
383
- ae,
389
+ localeService.t("docLink.edit.cancel")
390
+ ), /* @__PURE__ */ React.createElement(
391
+ Button,
384
392
  {
385
- disabled: !a,
386
- className: M.docsLinkEditButton,
393
+ disabled: !link,
394
+ className: styles.docsLinkEditButton,
387
395
  type: "primary",
388
- onClick: k
396
+ onClick: handleConfirm
389
397
  },
390
- t.t("docLink.edit.confirm")
398
+ localeService.t("docLink.edit.confirm")
391
399
  )));
392
- };
393
- Z.componentKey = "docs-hyper-link-edit";
394
- const Pe = "doc-hyper-link-icon";
395
- 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) {
396
404
  return {
397
- id: G.id,
398
- group: We.CONTEXT_MENU_DATA,
399
- type: ze.BUTTON,
400
- icon: Pe,
405
+ id: ShowDocHyperLinkEditPopupOperation.id,
406
+ group: MenuGroup.CONTEXT_MENU_DATA,
407
+ type: MenuItemType.BUTTON,
408
+ icon: DOC_LINK_ICON,
401
409
  title: "docLink.menu.tooltip",
402
410
  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));
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));
408
416
  });
409
417
  return () => {
410
- n.unsubscribe();
418
+ observer.unsubscribe();
411
419
  };
412
420
  })
413
421
  };
414
422
  }
415
- const Vt = {
416
- id: G.id,
417
- binding: Ye.CTRL_COMMAND | Ze.K,
423
+ __name(AddHyperLinkMenuItemFactory, "AddHyperLinkMenuItemFactory");
424
+ const addLinkShortcut = {
425
+ id: ShowDocHyperLinkEditPopupOperation.id,
426
+ binding: MetaKeys.CTRL_COMMAND | KeyCode.K,
418
427
  description: "docLink.menu.tooltip",
419
- preconditions: dt
428
+ preconditions: whenDocAndEditorFocused
420
429
  };
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();
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();
429
438
  }
430
439
  _initComponents() {
431
440
  [
432
- [Z, Z.componentKey],
433
- [Y, Y.componentKey],
434
- [te, Pe]
435
- ].forEach(([e, t]) => {
436
- 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);
437
446
  });
438
447
  }
439
448
  _initCommands() {
440
449
  [
441
- Ee,
442
- Me,
443
- Se,
444
- G
445
- ].forEach((e) => {
446
- this._commandService.registerCommand(e);
450
+ AddDocHyperLinkCommand,
451
+ UpdateDocHyperLinkCommand,
452
+ DeleteDocHyperLinkCommand,
453
+ ShowDocHyperLinkEditPopupOperation
454
+ ].forEach((command) => {
455
+ this._commandService.registerCommand(command);
447
456
  });
448
457
  }
449
458
  _initShortcut() {
450
- [Vt].forEach((e) => {
451
- this._shortcutService.registerShortcut(e);
459
+ [addLinkShortcut].forEach((shortcut) => {
460
+ this._shortcutService.registerShortcut(shortcut);
452
461
  });
453
462
  }
454
463
  _initMenus() {
455
- [Kt].forEach((e) => {
456
- this.disposeWithMe(this._menuService.addMenuItem(e(this._injector), {}));
464
+ [AddHyperLinkMenuItemFactory].forEach((menuFactory) => {
465
+ this.disposeWithMe(this._menuService.addMenuItem(menuFactory(this._injector), {}));
457
466
  });
458
467
  }
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();
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();
476
485
  }
477
486
  _initSelectionChange() {
478
487
  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) {
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) {
484
493
  this._docHyperLinkService.hideInfoPopup(), this._docHyperLinkService.hideEditPopup();
485
494
  return;
486
495
  }
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 });
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 });
495
504
  return;
496
505
  }
497
- } 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))
498
507
  return;
499
508
  }
500
509
  this._docHyperLinkService.hideInfoPopup(), this._docHyperLinkService.hideEditPopup();
@@ -502,144 +511,220 @@ let V = class extends $ {
502
511
  })
503
512
  );
504
513
  }
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();
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();
521
530
  }
522
531
  _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
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
531
540
  });
532
- }
541
+ }, "handler")
533
542
  });
534
543
  }
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();
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();
548
557
  }
549
558
  _initClipboard() {
550
559
  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
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
559
568
  ) : 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)
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)
563
572
  };
564
- for (let l = 0; l < u.length; l++)
565
- Te(f, 1, u[l] - l);
566
- return f;
573
+ for (let i = 0; i < deleteIndexes.length; i++)
574
+ updateAttributeByDelete(bodyWithoutLink, 1, deleteIndexes[i] - i);
575
+ return bodyWithoutLink;
567
576
  } 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;
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;
580
595
  }
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
- });
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
+ );
587
608
  }
588
609
  }
589
610
  });
590
611
  }
591
- return e;
592
- }
612
+ return body;
613
+ }, "onBeforePaste")
593
614
  }));
594
615
  }
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;
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();
611
633
  }
612
- 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() {
613
697
  [
614
- [S],
698
+ [DocHyperLinkPopupService],
615
699
  [
616
- U,
700
+ DocHyperLinkUIController,
617
701
  {
618
- useFactory: () => this._injector.createInstance(U, this._config)
702
+ useFactory: /* @__PURE__ */ __name(() => this._injector.createInstance(DocHyperLinkUIController, this._config), "useFactory")
619
703
  }
620
704
  ],
621
- [V],
622
- [F]
623
- ].forEach((i) => {
624
- e.add(i);
705
+ [DocHyperLinkSelectionController],
706
+ [DocHyperLinkClipboardController],
707
+ [DocHyperLinkCustomRangeController]
708
+ ].forEach((dep) => {
709
+ this._injector.add(dep);
625
710
  });
626
711
  }
627
712
  onRendered() {
628
713
  this._initRenderModule();
629
714
  }
630
715
  _initRenderModule() {
631
- [q].forEach((e) => {
632
- this._renderManagerSrv.registerRenderModule(_.UNIVER_DOC, e);
716
+ [DocHyperLinkRenderController].forEach((dep) => {
717
+ this._renderManagerSrv.registerRenderModule(UniverInstanceType.UNIVER_DOC, dep);
633
718
  });
634
719
  }
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);
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);
643
728
  export {
644
- W as UniverDocsHyperLinkUIPlugin
729
+ UniverDocsHyperLinkUIPlugin
645
730
  };