@univerjs/docs-hyper-link-ui 1.0.0-rc.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/lib/cjs/index.js +586 -165
  2. package/lib/cjs/locale/ar-SA.js +0 -1
  3. package/lib/cjs/locale/ca-ES.js +0 -1
  4. package/lib/cjs/locale/de-DE.js +0 -1
  5. package/lib/cjs/locale/en-US.js +0 -1
  6. package/lib/cjs/locale/es-ES.js +0 -1
  7. package/lib/cjs/locale/fa-IR.js +0 -1
  8. package/lib/cjs/locale/fr-FR.js +0 -1
  9. package/lib/cjs/locale/id-ID.js +0 -1
  10. package/lib/cjs/locale/it-IT.js +0 -1
  11. package/lib/cjs/locale/ja-JP.js +0 -1
  12. package/lib/cjs/locale/ko-KR.js +0 -1
  13. package/lib/cjs/locale/pl-PL.js +0 -1
  14. package/lib/cjs/locale/pt-BR.js +0 -1
  15. package/lib/cjs/locale/ru-RU.js +0 -1
  16. package/lib/cjs/locale/sk-SK.js +0 -1
  17. package/lib/cjs/locale/vi-VN.js +0 -1
  18. package/lib/cjs/locale/zh-CN.js +0 -1
  19. package/lib/cjs/locale/zh-HK.js +0 -1
  20. package/lib/cjs/locale/zh-TW.js +0 -1
  21. package/lib/es/index.js +585 -170
  22. package/lib/index.css +29 -0
  23. package/lib/index.js +585 -170
  24. package/lib/types/commands/operations/popup.operation.d.ts +1 -0
  25. package/lib/types/controllers/doc-hyper-link-selection.controller.d.ts +1 -0
  26. package/lib/types/controllers/mobile/components.controller.d.ts +24 -0
  27. package/lib/types/controllers/render-controllers/hyper-link-event.render-controller.d.ts +1 -0
  28. package/lib/types/controllers/render-controllers/mobile/hyper-link-event.render-controller.d.ts +33 -0
  29. package/lib/types/index.d.ts +1 -0
  30. package/lib/types/mobile-plugin.d.ts +32 -0
  31. package/lib/types/services/hyper-link-popup.service.d.ts +13 -7
  32. package/lib/types/services/mobile/hyper-link-popup.service.d.ts +22 -0
  33. package/lib/types/views/MobileDocHyperLinkEdit.d.ts +19 -0
  34. package/lib/types/views/MobileDocLinkPopup.d.ts +19 -0
  35. package/lib/types/views/hyper-link-edit/use-doc-hyper-link-edit.d.ts +28 -0
  36. package/lib/umd/index.js +1 -1
  37. package/package.json +13 -13
@@ -33,6 +33,7 @@ export interface IShowDocHyperLinkInfoPopupOperationParams {
33
33
  segmentPage?: number;
34
34
  startIndex: number;
35
35
  endIndex: number;
36
+ fromHover?: boolean;
36
37
  }
37
38
  export declare const ToggleDocHyperLinkInfoPopupOperation: ICommand<IShowDocHyperLinkInfoPopupOperationParams>;
38
39
  export declare const ClickDocHyperLinkOperation: ICommand<{
@@ -19,6 +19,7 @@ export declare class DocHyperLinkSelectionController extends Disposable {
19
19
  private readonly _commandService;
20
20
  private readonly _univerInstanceService;
21
21
  private readonly _docHyperLinkService;
22
+ private _selection;
22
23
  constructor(_commandService: ICommandService, _univerInstanceService: IUniverInstanceService, _docHyperLinkService: DocHyperLinkPopupService);
23
24
  private _initSelectionChange;
24
25
  }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { Disposable } from '@univerjs/core';
17
+ import { ComponentManager, IconManager } from '@univerjs/ui';
18
+ export declare class MobileComponentsController extends Disposable {
19
+ private readonly _componentManager;
20
+ private readonly _iconManager;
21
+ constructor(_componentManager: ComponentManager, _iconManager: IconManager);
22
+ private _registerComponents;
23
+ private _registerIcons;
24
+ }
@@ -29,6 +29,7 @@ export declare class DocHyperLinkEventRenderController extends Disposable implem
29
29
  get _skeleton(): import("@univerjs/engine-render").DocumentSkeleton;
30
30
  constructor(_context: IRenderContext<DocumentDataModel>, _docEventManagerService: DocEventManagerService, _commandService: ICommandService, _hyperLinkPopupService: DocHyperLinkPopupService, _docSkeletonManagerService: DocSkeletonManagerService, _docSelectionManagerService: DocSelectionManagerService);
31
31
  private _hideInfoPopup;
32
+ private _normalizeSegmentId;
32
33
  private _initPointerDown;
33
34
  private _initHover;
34
35
  private _initClick;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { DocumentDataModel } from '@univerjs/core';
17
+ import type { IRenderContext, IRenderModule } from '@univerjs/engine-render';
18
+ import { Disposable, ICommandService } from '@univerjs/core';
19
+ import { DocSkeletonManagerService } from '@univerjs/docs';
20
+ import { DocEventManagerService, DocMobileElementMenuService } from '@univerjs/docs-ui';
21
+ import { DocHyperLinkPopupService } from '../../../services/hyper-link-popup.service';
22
+ export declare class MobileDocHyperLinkEventRenderController extends Disposable implements IRenderModule {
23
+ private readonly _context;
24
+ private readonly _docEventManagerService;
25
+ private readonly _commandService;
26
+ private readonly _hyperLinkPopupService;
27
+ private readonly _docSkeletonManagerService;
28
+ private readonly _mobileElementMenuService;
29
+ get _skeleton(): import("@univerjs/engine-render").DocumentSkeleton;
30
+ constructor(_context: IRenderContext<DocumentDataModel>, _docEventManagerService: DocEventManagerService, _commandService: ICommandService, _hyperLinkPopupService: DocHyperLinkPopupService, _docSkeletonManagerService: DocSkeletonManagerService, _mobileElementMenuService: DocMobileElementMenuService);
31
+ private _initPointerDown;
32
+ private _initClick;
33
+ }
@@ -16,4 +16,5 @@
16
16
  import './global.css';
17
17
  export type { IUniverDocsHyperLinkUIConfig } from './config/config';
18
18
  export { menuSchema as DocsHyperLinkUIMenuSchema } from './menu/schema';
19
+ export { UniverDocsHyperLinkMobileUIPlugin } from './mobile-plugin';
19
20
  export { UniverDocsHyperLinkUIPlugin } from './plugin';
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { IUniverDocsHyperLinkUIConfig } from './config/config';
17
+ import { IConfigService, Injector, Plugin, UniverInstanceType } from '@univerjs/core';
18
+ import { IRenderManagerService } from '@univerjs/engine-render';
19
+ export declare class UniverDocsHyperLinkMobileUIPlugin extends Plugin {
20
+ private readonly _config;
21
+ protected _injector: Injector;
22
+ private readonly _renderManagerSrv;
23
+ private readonly _configService;
24
+ static pluginName: string;
25
+ static packageName: string;
26
+ static version: string;
27
+ static type: UniverInstanceType;
28
+ constructor(_config: Partial<IUniverDocsHyperLinkUIConfig> | undefined, _injector: Injector, _renderManagerSrv: IRenderManagerService, _configService: IConfigService);
29
+ onStarting(): void;
30
+ onReady(): void;
31
+ onRendered(): void;
32
+ }
@@ -13,10 +13,12 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { Disposable, IPermissionService, IUniverInstanceService } from '@univerjs/core';
16
+ import type { IDisposable, ITextRangeParam } from '@univerjs/core';
17
+ import { Disposable, ICommandService, IPermissionService, IUniverInstanceService, LocaleService } from '@univerjs/core';
17
18
  import { DocSelectionManagerService } from '@univerjs/docs';
18
19
  import { DocCanvasPopManagerService } from '@univerjs/docs-ui';
19
20
  import { IRenderManagerService } from '@univerjs/engine-render';
21
+ import { IDialogService } from '@univerjs/ui';
20
22
  export interface ILinkInfo {
21
23
  unitId: string;
22
24
  linkId: string;
@@ -25,13 +27,15 @@ export interface ILinkInfo {
25
27
  startIndex: number;
26
28
  endIndex: number;
27
29
  }
28
- type LinkPopupDisposable = ReturnType<DocCanvasPopManagerService['attachPopupToRange']>;
29
30
  export declare class DocHyperLinkPopupService extends Disposable {
30
- private readonly _docCanvasPopupManagerService;
31
+ protected readonly _docCanvasPopupManagerService: DocCanvasPopManagerService;
31
32
  private readonly _textSelectionManagerService;
32
33
  private readonly _univerInstanceService;
33
34
  private readonly _permissionService;
34
35
  private readonly _renderManagerService;
36
+ protected readonly _dialogService: IDialogService;
37
+ protected readonly _localeService: LocaleService;
38
+ private readonly _commandService;
35
39
  private readonly _editingLink$;
36
40
  private readonly _showingLink$;
37
41
  readonly editingLink$: import("rxjs").Observable<ILinkInfo | null>;
@@ -43,20 +47,22 @@ export declare class DocHyperLinkPopupService extends Disposable {
43
47
  private _infoPopupHideTimer;
44
48
  private _infoPopupSuppressed;
45
49
  private _infoPopupSuppressionTimer;
46
- constructor(_docCanvasPopupManagerService: DocCanvasPopManagerService, _textSelectionManagerService: DocSelectionManagerService, _univerInstanceService: IUniverInstanceService, _permissionService: IPermissionService, _renderManagerService: IRenderManagerService);
50
+ constructor(_docCanvasPopupManagerService: DocCanvasPopManagerService, _textSelectionManagerService: DocSelectionManagerService, _univerInstanceService: IUniverInstanceService, _permissionService: IPermissionService, _renderManagerService: IRenderManagerService, _dialogService: IDialogService, _localeService: LocaleService, _commandService: ICommandService);
47
51
  dispose(): void;
48
52
  get editing(): ILinkInfo | null;
49
53
  get showing(): ILinkInfo | null;
50
54
  get infoPopupPinned(): boolean;
51
- showEditPopup(unitId: string, linkInfo: ILinkInfo | null): LinkPopupDisposable | null;
55
+ showEditPopup(unitId: string, linkInfo: ILinkInfo | null): IDisposable | null;
52
56
  hideEditPopup(): void;
53
57
  showInfoPopup(info: ILinkInfo, options?: {
54
58
  pinned?: boolean;
55
- }): LinkPopupDisposable | null | undefined;
59
+ }): IDisposable | null | undefined;
60
+ protected _openEditSurface(activeRange: ITextRangeParam, unitId: string): IDisposable;
61
+ protected _openInfoSurface(info: ILinkInfo, componentKey?: string): IDisposable;
62
+ showInfoPopupFromHover(info: ILinkInfo): void;
56
63
  hideInfoPopup(): void;
57
64
  scheduleHideInfoPopup(): void;
58
65
  cancelScheduledHideInfoPopup(): void;
59
66
  hideInfoPopupOnPointerDown(): void;
60
67
  canEditLink(unitId: string, linkInfo: ILinkInfo | null): boolean;
61
68
  }
62
- export {};
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { IDisposable, ITextRangeParam } from '@univerjs/core';
17
+ import type { ILinkInfo } from '../hyper-link-popup.service';
18
+ import { DocHyperLinkPopupService } from '../hyper-link-popup.service';
19
+ export declare class MobileDocHyperLinkPopupService extends DocHyperLinkPopupService {
20
+ protected _openEditSurface(_activeRange: ITextRangeParam, _unitId: string): IDisposable;
21
+ protected _openInfoSurface(info: ILinkInfo): IDisposable;
22
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export declare function MobileDocHyperLinkEdit(): import("react").JSX.Element | undefined;
17
+ export declare namespace MobileDocHyperLinkEdit {
18
+ var componentKey: string;
19
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ export declare function MobileDocLinkPopup(): import("react").JSX.Element | null;
17
+ export declare namespace MobileDocLinkPopup {
18
+ var componentKey: string;
19
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Copyright 2023-present DreamNum Co., Ltd.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { DocumentDataModel } from '@univerjs/core';
17
+ export declare function useDocHyperLinkEdit(): {
18
+ doc: import("@univerjs/core").Nullable<DocumentDataModel>;
19
+ editing: import("../../services/hyper-link-popup.service").ILinkInfo | null;
20
+ handleCancel: () => void;
21
+ handleConfirm: () => void;
22
+ isLegal: boolean;
23
+ label: string;
24
+ link: string;
25
+ setLabel: import("react").Dispatch<import("react").SetStateAction<string>>;
26
+ setLink: import("react").Dispatch<import("react").SetStateAction<string>>;
27
+ showError: boolean;
28
+ };
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/docs-ui"),require("@univerjs/ui"),require("@univerjs/core"),require("@univerjs/docs"),require("@univerjs/engine-render"),require("rxjs"),require("@univerjs/design"),require("react"),require("@univerjs/docs-hyper-link"),require("react/jsx-runtime"),require("@univerjs/protocol")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/docs-ui`,`@univerjs/ui`,`@univerjs/core`,`@univerjs/docs`,`@univerjs/engine-render`,`rxjs`,`@univerjs/design`,`react`,`@univerjs/docs-hyper-link`,`react/jsx-runtime`,`@univerjs/protocol`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsHyperLinkUi={},e.UniverDocsUi,e.UniverUi,e.UniverCore,e.UniverDocs,e.UniverEngineRender,e.rxjs,e.UniverDesign,e.React,e.UniverDocsHyperLink,e.React,e.UniverProtocol))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let f={type:r.CommandType.COMMAND,id:l.DocHyperLinkCommandId.Add,async handler(e,t){if(!t)return!1;let{payload:n,unitId:a,selections:o}=t,s=e.get(r.ICommandService),c=(0,i.addCustomRangeBySelectionFactory)(e,{rangeId:(0,r.generateRandomId)(),rangeType:r.CustomRangeType.HYPERLINK,properties:{url:n},unitId:a,selections:o});return c?s.syncExecuteCommand(c.id,c.params):!1}},p={id:l.DocHyperLinkCommandId.Update,type:r.CommandType.COMMAND,handler(e,t){var n,a;if(!t)return!1;let{unitId:o,payload:s,segmentId:c,linkId:l}=t,u=e.get(r.ICommandService),d=e.get(r.IUniverInstanceService),f=e.get(i.DocSelectionManagerService).getActiveTextRange(),p=d.getUnit(o,r.UniverInstanceType.UNIVER_DOC);if(!f||!p)return!1;let m=(n=p.getSelfOrHeaderFooterModel(c))==null?void 0:n.getBody();if(!m)return!1;let h=(a=(0,r.getBodySlice)(m,f.startOffset,f.endOffset).textRuns)==null?void 0:a[0];h&&(h.ed=t.label.length+1);let g=(0,i.replaceSelectionFactory)(e,{unitId:o,body:{dataStream:`${t.label}`,customRanges:[{rangeId:l,rangeType:r.CustomRangeType.HYPERLINK,startIndex:0,endIndex:t.label.length+1,properties:{url:s}}],textRuns:h?[h]:void 0},selection:{startOffset:f.startOffset,endOffset:f.endOffset,collapsed:!1,segmentId:c}});return g?u.syncExecuteCommand(g.id,g.params):!1}};function m(e){return e.trim().length===0}function h(e){return/^[a-zA-Z]+:\/\//.test(e)}function g(e){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(e)}function _(e){return h(e)?e:g(e)?`mailto://${e}`:`https://${e}`}let v=()=>{let e=(0,n.useDependency)(R),t=(0,n.useDependency)(r.LocaleService),a=(0,n.useObservable)(e.editingLink$),o=(0,n.useDependency)(r.ICommandService),l=(0,n.useDependency)(r.IUniverInstanceService),d=(0,n.useDependency)(i.DocSelectionManagerService),[h,g]=(0,c.useState)(``),[v,y]=(0,c.useState)(``),[b,x]=(0,c.useState)(!1),S=r.Tools.isLegalUrl(h),C=a?l.getUnit(a.unitId,r.UniverInstanceType.UNIVER_DOC):l.getCurrentUnitOfType(r.UniverInstanceType.UNIVER_DOC);(0,c.useEffect)(()=>{var e,t;let n=d.getActiveTextRange();if(!n)return;if(a){var i,o;let e=C==null||(i=C.getSelfOrHeaderFooterModel(a.segmentId))==null?void 0:i.getBody(),t=e==null||(o=e.customRanges)==null?void 0:o.find(e=>(a==null?void 0:a.linkId)===e.rangeId&&e.startIndex===a.startIndex&&e.endIndex===a.endIndex);if(C&&t){var s;g(((s=t.properties)==null?void 0:s.url)??``),y(r.BuildTextUtils.transform.getPlainText((0,r.getBodySlice)(e,t.startIndex,t.endIndex+1).dataStream))}return}let c=C==null||(e=C.getSelfOrHeaderFooterModel(n.segmentId))==null?void 0:e.getBody(),l=c?n:null,u=l&&((t=r.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(l,(c==null?void 0:c.customRanges)??[]))==null?void 0:t[0]);if(C&&u){var f;g((u==null||(f=u.properties)==null?void 0:f.url)??``)}},[C,a,d,l]);let w=()=>{e.hideEditPopup()},T=()=>{if(x(!0),!S||!C)return;let t=_(h);if(!a)o.executeCommand(f.id,{unitId:C.getUnitId(),payload:t});else{if(m(v))return;o.executeCommand(p.id,{unitId:C.getUnitId(),payload:t,linkId:a.linkId,label:v,segmentId:a.segmentId})}e.hideEditPopup()};if(C)return(0,u.jsxs)(`div`,{className:(0,s.clsx)(`univer-box-border univer-w-[328px] univer-rounded-xl univer-bg-gray-0 univer-px-6 univer-py-5 univer-shadow dark:!univer-bg-gray-900`,s.borderClassName),children:[(0,u.jsxs)(`div`,{children:[a?(0,u.jsx)(s.FormLayout,{label:t.t(`docs-hyper-link-ui.edit.label`),error:b&&m(v)?t.t(`docs-hyper-link-ui.edit.labelError`):``,children:(0,u.jsx)(s.Input,{value:v,onChange:y,autoFocus:!0,onKeyDown:e=>{e.keyCode===n.KeyCode.ENTER&&T()}})}):null,(0,u.jsx)(s.FormLayout,{label:t.t(`docs-hyper-link-ui.edit.address`),error:b&&!S?t.t(`docs-hyper-link-ui.edit.addressError`):``,children:(0,u.jsx)(s.Input,{value:h,onChange:g,autoFocus:!0,onKeyDown:e=>{e.keyCode===n.KeyCode.ENTER&&T()}})})]}),(0,u.jsxs)(`div`,{className:`univer-flex univer-justify-end univer-gap-3`,children:[(0,u.jsx)(s.Button,{onClick:w,children:t.t(`docs-hyper-link-ui.edit.cancel`)}),(0,u.jsx)(s.Button,{variant:`primary`,disabled:m(h),onClick:T,children:t.t(`docs-hyper-link-ui.edit.confirm`)})]})]})};v.componentKey=`docs-hyper-link-edit`;function y({ref:e,...t}){let{preserveStrokeWidth:n,icon:r,id:i,className:a,extend:o,...s}=t,l=`univerjs-icon univerjs-icon-${i} ${a||``}`.trim(),u=`_${(0,c.useId)()}`,d=(0,c.useRef)(null);return(0,c.useImperativeHandle)(e,()=>d.current),(0,c.useLayoutEffect)(()=>{if(!(!n||!d.current||d.current.localName!==r.tag))return C(d.current)},[n,r]),b(r,`${i}`,{defIds:r.defIds,idSuffix:u},{ref:d,className:l,...s},o)}function b(e,t,n,r,i){return(0,c.createElement)(e.tag,{key:t,...x(e,n,i),...r},(S(e,n).children||[]).map((r,a)=>b(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function x(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),n!=null&&n.colorChannel1&&r.stroke===`colorChannel1`&&(r.stroke=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function S(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function C(e){let t=e.viewBox.baseVal,n=Math.max(t.width,t.height);if(!Number.isFinite(n)||n<=0||t.width<=0||t.height<=0)return()=>void 0;let r=16/n,i=Array.from(e.querySelectorAll(`circle, ellipse, line, path, polygon, polyline, rect, text, textPath, tspan, use`)).flatMap(e=>{let t=getComputedStyle(e),n=Number.parseFloat(t.strokeWidth);return t.stroke===`none`||Number.parseFloat(t.strokeOpacity)===0||t.vectorEffect===`non-scaling-stroke`||!Number.isFinite(n)||n<=0?[]:[{element:e,hadStyleAttribute:e.hasAttribute(`style`),originalStrokeWidth:n,strokeWidth:w(e.style,`stroke-width`)}]}).map(e=>({appliedStrokeWidth:null,element:e.element,hadStyleAttribute:e.hadStyleAttribute,isReleased:!1,originalStrokeWidth:e.originalStrokeWidth,strokeWidth:e.strokeWidth}));if(i.length===0)return()=>void 0;let a=(e,n)=>{if(t.width<=0||t.height<=0||e<=0||n<=0)return;let a=Math.min(e/t.width,n/t.height);!Number.isFinite(a)||a<=0||i.forEach(e=>{if(e.isReleased)return;if(e.appliedStrokeWidth!==null&&(e.element.style.getPropertyValue(`stroke-width`)!==e.appliedStrokeWidth||e.element.style.getPropertyPriority(`stroke-width`)!==e.strokeWidth.priority)){e.appliedStrokeWidth=null,e.isReleased=!0;return}let t=e.originalStrokeWidth*r/a,n=`${Number(t.toFixed(12))}px`;e.element.style.setProperty(`stroke-width`,n,e.strokeWidth.priority),e.appliedStrokeWidth=n})},o=e.getBoundingClientRect();a(o.width,o.height);let s=typeof ResizeObserver>`u`?null:new ResizeObserver(t=>{if(t.some(t=>t.target===e)){let t=e.getBoundingClientRect();a(t.width,t.height)}});return s==null||s.observe(e),()=>{s==null||s.disconnect(),i.forEach(e=>{e.appliedStrokeWidth!==null&&(T(e.element.style,`stroke-width`,e.appliedStrokeWidth,e.strokeWidth.priority,e.strokeWidth),!e.hadStyleAttribute&&e.element.style.length===0&&e.element.removeAttribute(`style`))})}}function w(e,t){return{priority:e.getPropertyPriority(t),value:e.getPropertyValue(t)}}function T(e,t,n,r,i){e.getPropertyValue(t)===n&&e.getPropertyPriority(t)===r&&(i.value?e.setProperty(t,i.value,i.priority):e.removeProperty(t))}y.displayName=`UniverIcon`;let E={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,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`}}]},D=(0,c.forwardRef)(function(e,t){return(0,c.createElement)(y,Object.assign({},e,{id:`copy-icon`,ref:t,icon:E}))});D.displayName=`CopyIcon`;let O={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M7.30999 8.71386C6.39955 7.80343 6.37922 6.34731 7.26629 5.45772L10.313 2.41112C11.2111 1.51303 12.6799 1.51258 13.5691 2.45476C14.4811 3.36679 14.4798 4.84384 13.6128 5.71094L10.9677 8.35604`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.22}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M5.0456 7.66774L2.4005 10.3128C1.50242 11.2109 1.50197 12.6798 2.44413 13.5691C3.35615 14.4811 4.8332 14.4798 5.70033 13.6127L8.747 10.566C9.65743 9.65558 9.67776 8.19945 8.7905 7.30999`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.22}}]},k=(0,c.forwardRef)(function(e,t){return(0,c.createElement)(y,Object.assign({},e,{id:`link-icon`,ref:t,icon:O}))});k.displayName=`LinkIcon`;let ee={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,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.76157C6.75249 4.52725 6.75249 4.14735 6.98681 3.91304L8.27535 2.62449C9.70209 1.19776 12.0153 1.19776 13.442 2.62449C14.8688 4.05123 14.8688 6.36442 13.442 7.79116L12.1535 9.0797C11.9192 9.31402 11.5393 9.31402 11.3049 9.0797C11.0706 8.84539 11.0706 8.46549 11.3049 8.23117L12.5935 6.94263C13.5516 5.98452 13.5516 4.43113 12.5935 3.47302Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M3.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.05395C4.4606 6.81963 4.0807 6.81963 3.84639 7.05395L2.55784 8.34249C1.13111 9.76923 1.13111 12.0824 2.55784 13.5092C3.98458 14.9359 6.29777 14.9359 7.72451 13.5092L9.01305 12.2206C9.24737 11.9863 9.24737 11.6064 9.01305 11.3721C8.77874 11.1378 8.39884 11.1378 8.16452 11.3721L6.87598 12.6606C5.91787 13.6187 4.36448 13.6187 3.40637 12.6606Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M3.5852 2.80332C3.35088 2.569 2.97098 2.569 2.73667 2.80332C2.50235 3.03763 2.50235 3.41753 2.73667 3.65185L12.4151 13.3302C12.6494 13.5646 13.0293 13.5646 13.2636 13.3302C13.4979 13.0959 13.4979 12.716 13.2636 12.4817L3.5852 2.80332Z`}}]},A=(0,c.forwardRef)(function(e,t){return(0,c.createElement)(y,Object.assign({},e,{id:`unlink-icon`,ref:t,icon:ee}))});A.displayName=`UnlinkIcon`;let te={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,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`}}]},j=(0,c.forwardRef)(function(e,t){return(0,c.createElement)(y,Object.assign({},e,{id:`write-icon`,ref:t,icon:te}))});j.displayName=`WriteIcon`;let M={type:r.CommandType.COMMAND,id:l.DocHyperLinkCommandId.Delete,async handler(e,t){if(!t)return!1;let{unitId:n,linkId:a,segmentId:o}=t,s=e.get(r.ICommandService),c=(0,i.deleteCustomRangeFactory)(e,{unitId:n,rangeId:a,segmentId:o});return c?await s.syncExecuteCommand(c.id,c.params):!1}},N=()=>{var e,t,a;let o=(0,n.useDependency)(R),c=(0,n.useDependency)(r.ICommandService),l=(0,n.useDependency)(n.IMessageService),f=(0,n.useDependency)(r.LocaleService),p=(0,n.useObservable)(o.showingLink$),m=(0,n.useDependency)(r.IUniverInstanceService),h=(0,n.useDependency)(r.IPermissionService);if(!p)return null;let{unitId:g,linkId:_,segmentId:v,startIndex:y,endIndex:b}=p,x=m.getUnit(g,r.UniverInstanceType.UNIVER_DOC),S=x instanceof r.DocumentDataModel?(e=x.getSelfOrHeaderFooterModel(v))==null?void 0:e.getBody():void 0,C=S==null||(t=S.customRanges)==null?void 0:t.find(e=>e.rangeId===_&&e.rangeType===r.CustomRangeType.HYPERLINK&&e.startIndex===y&&e.endIndex===b);if(!C)return null;let w=(a=C.properties)==null?void 0:a.url,T=o.canEditLink(g,p),E=(0,i.getDocumentPermissionValue)(h,g,g,d.UnitAction.Copy);return(0,u.jsxs)(`div`,{className:(0,s.clsx)(`univer-box-border univer-flex univer-max-w-80 univer-items-center univer-justify-between univer-overflow-hidden univer-rounded-lg univer-bg-gray-0 univer-p-3 univer-shadow dark:!univer-bg-gray-900`,s.borderClassName),onPointerEnter:()=>{o.cancelScheduledHideInfoPopup()},onPointerLeave:()=>{o.scheduleHideInfoPopup()},onClick:()=>{o.hideInfoPopup()},children:[(0,u.jsxs)(`div`,{className:`univer-flex univer-h-6 univer-flex-1 univer-cursor-pointer univer-items-center univer-truncate univer-text-sm univer-leading-5 univer-text-primary-500`,onClick:()=>window.open(w,void 0,`noopener noreferrer`),children:[(0,u.jsx)(`div`,{className:`univer-mr-2 univer-flex univer-size-5 univer-flex-[0_0_auto] univer-items-center univer-justify-center univer-text-base univer-text-gray-900 dark:!univer-text-gray-0`,children:(0,u.jsx)(k,{})}),(0,u.jsx)(s.Tooltip,{showIfEllipsis:!0,title:w,children:(0,u.jsx)(`span`,{className:`univer-flex-1 univer-truncate`,children:w})})]}),(0,u.jsxs)(`div`,{className:`univer-flex univer-h-6 univer-flex-[0_0_auto] univer-items-center univer-justify-center`,children:[(0,u.jsx)(s.Button,{type:`button`,variant:`text`,size:`small`,"aria-label":f.t(`docs-hyper-link-ui.info.copy`),className:`univer-ml-2 !univer-flex univer-size-6 !univer-rounded !univer-border-0 !univer-bg-transparent !univer-p-0 !univer-text-base !univer-font-normal hover:!univer-bg-transparent active:!univer-bg-transparent disabled:!univer-pointer-events-auto disabled:!univer-opacity-40`,disabled:!E,onClick:()=>{navigator.clipboard.writeText(w),l.show({content:f.t(`docs-hyper-link-ui.info.coped`),type:s.MessageType.Info})},children:(0,u.jsx)(s.Tooltip,{placement:`bottom`,title:f.t(`docs-hyper-link-ui.info.copy`),children:(0,u.jsx)(D,{})})}),T&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`div`,{className:`univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base`,onClick:()=>{c.executeCommand(B.id,{link:p})},children:(0,u.jsx)(s.Tooltip,{placement:`bottom`,title:f.t(`docs-hyper-link-ui.info.edit`),children:(0,u.jsx)(j,{})})}),(0,u.jsx)(`div`,{className:`univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base`,onClick:()=>{c.executeCommand(M.id,{unitId:g,linkId:C.rangeId,segmentId:v})},children:(0,u.jsx)(s.Tooltip,{placement:`bottom`,title:f.t(`docs-hyper-link-ui.info.cancel`),children:(0,u.jsx)(A,{})})})]})]})]})};N.componentKey=`univer.doc.link-info-popup`;function P(e){"@babel/helpers - typeof";return P=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},P(e)}function ne(e,t){if(P(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(P(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function re(e){var t=ne(e,`string`);return P(t)==`symbol`?t:t+``}function F(e,t,n){return(t=re(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function I(e,t){return function(n,r){t(n,r,e)}}function L(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function ie(e,t){return(e==null?void 0:e.linkId)===t.linkId&&e.unitId===t.unitId&&(e.segmentId??``)===(t.segmentId??``)&&e.segmentPage===t.segmentPage&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex}let R=class extends r.Disposable{constructor(e,t,n,r,i){super(),this._docCanvasPopupManagerService=e,this._textSelectionManagerService=t,this._univerInstanceService=n,this._permissionService=r,this._renderManagerService=i,F(this,`_editingLink$`,new o.BehaviorSubject(null)),F(this,`_showingLink$`,new o.BehaviorSubject(null)),F(this,`editingLink$`,this._editingLink$.asObservable()),F(this,`showingLink$`,this._showingLink$.asObservable()),F(this,`_editPopup`,null),F(this,`_editPopupUnitId`,null),F(this,`_infoPopup`,null),F(this,`_infoPopupPinned`,!1),F(this,`_infoPopupHideTimer`,null),F(this,`_infoPopupSuppressed`,!1),F(this,`_infoPopupSuppressionTimer`,null),this.disposeWithMe(()=>{this.cancelScheduledHideInfoPopup(),this._infoPopupSuppressionTimer!==null&&clearTimeout(this._infoPopupSuppressionTimer),this._editingLink$.complete(),this._showingLink$.complete()}),this.disposeWithMe(this._permissionService.permissionPointUpdate$.subscribe(()=>{let e=this.editing;e&&!this.canEditLink(e.unitId,e)&&this.hideEditPopup();let t=this.showing;t&&this._showingLink$.next({...t})})),this.disposeWithMe(this._renderManagerService.disposed$.subscribe(e=>{var t;this._editPopupUnitId===e&&this.hideEditPopup(),((t=this.showing)==null?void 0:t.unitId)===e&&this.hideInfoPopup()}))}dispose(){this.hideEditPopup(),this.hideInfoPopup(),super.dispose()}get editing(){return this._editingLink$.value}get showing(){return this._showingLink$.value}get infoPopupPinned(){return this._infoPopupPinned}showEditPopup(e,t){if(!this.canEditLink(e,t))return null;this._editPopup&&(this._editPopup.dispose(),this._editPopup=null,this._editPopupUnitId=null),this._editingLink$.next(t);let n=this._textSelectionManagerService.getTextRanges({unitId:e,subUnitId:e}),r=n==null?void 0:n[n.length-1];if(t){let{segmentId:e,segmentPage:n,startIndex:i,endIndex:a}=t;r={collapsed:!1,startOffset:i,endOffset:a+1,segmentId:e,segmentPage:n},this._textSelectionManagerService.replaceDocRanges([{startOffset:i,endOffset:a+1}])}return r?(this._editPopup=this._docCanvasPopupManagerService.attachPopupToRange(r,{componentKey:v.componentKey,direction:`bottom`,offset:[0,10]},e),this._editPopupUnitId=e,this._editPopup):null}hideEditPopup(){var e;this._editingLink$.next(null),(e=this._editPopup)==null||e.dispose(),this._editPopup=null,this._editPopupUnitId=null}showInfoPopup(e,t){if(this.cancelScheduledHideInfoPopup(),this._infoPopupSuppressed)return;let{linkId:n,unitId:i,segmentId:a,segmentPage:o,startIndex:s,endIndex:c}=e;if(ie(this.showing,e)){t!=null&&t.pinned&&(this._infoPopupPinned=!0);return}if(this._infoPopup&&=(this._infoPopup.dispose(),null),this._univerInstanceService.getUnit(i,r.UniverInstanceType.UNIVER_DOC)instanceof r.DocumentDataModel)return this._infoPopupPinned=(t==null?void 0:t.pinned)??!1,this._showingLink$.next({unitId:i,linkId:n,segmentId:a,segmentPage:o,startIndex:s,endIndex:c}),this._infoPopup=this._docCanvasPopupManagerService.attachPopupToRange({collapsed:!1,startOffset:s,endOffset:c+1,segmentId:a,segmentPage:o},{componentKey:N.componentKey,direction:`top-center`,multipleDirection:`top`,offset:[0,10],onClickOutside:()=>{this.hideInfoPopup()}},i),this._infoPopup}hideInfoPopup(){var e;this.cancelScheduledHideInfoPopup(),this._infoPopupPinned=!1,this._showingLink$.next(null),(e=this._infoPopup)==null||e.dispose(),this._infoPopup=null}scheduleHideInfoPopup(){this._infoPopupPinned||!this.showing||(this.cancelScheduledHideInfoPopup(),this._infoPopupHideTimer=setTimeout(()=>{this._infoPopupHideTimer=null,this._infoPopupPinned||this.hideInfoPopup()},150))}cancelScheduledHideInfoPopup(){this._infoPopupHideTimer!==null&&(clearTimeout(this._infoPopupHideTimer),this._infoPopupHideTimer=null)}hideInfoPopupOnPointerDown(){this._infoPopupSuppressed=!0,this._infoPopupSuppressionTimer!==null&&clearTimeout(this._infoPopupSuppressionTimer),this.hideInfoPopup(),this._infoPopupSuppressionTimer=setTimeout(()=>{this._infoPopupSuppressed=!1,this._infoPopupSuppressionTimer=null},0)}canEditLink(e,t){let n=this._univerInstanceService.getUnit(e,r.UniverInstanceType.UNIVER_DOC);if(!(n instanceof r.DocumentDataModel))return!1;if(!t)return(0,i.canEditDocumentTargets)(this._permissionService,e,[]);let a=t.segmentId??``;return(0,i.canEditDocumentTargets)(this._permissionService,e,[...(0,i.getDocumentEntityParentPermissionObjectIds)(n,a,`custom-range`,t.linkId),(0,i.getDocumentEntityPermissionObjectId)(a,`custom-range`,t.linkId)])}};R=L([I(0,(0,r.Inject)(t.DocCanvasPopManagerService)),I(1,(0,r.Inject)(i.DocSelectionManagerService)),I(2,r.IUniverInstanceService),I(3,r.IPermissionService),I(4,a.IRenderManagerService)],R);let z=e=>{let t=e.get(i.DocSelectionManagerService),n=e.get(r.IUniverInstanceService),a=t.getTextRanges();if(!(a!=null&&a.length))return!0;let o=a[0];return!!(!n.getCurrentUnitOfType(r.UniverInstanceType.UNIVER_DOC)||!o||o.collapsed)},B={type:r.CommandType.OPERATION,id:`doc.operation.show-hyper-link-edit-popup`,handler(e,t){var n;let i=t==null?void 0:t.link,a=e.get(r.IUniverInstanceService);if(z(e)&&!i)return!1;let o=e.get(R),s=(i==null?void 0:i.unitId)||((n=a.getCurrentUnitOfType(r.UniverInstanceType.UNIVER_DOC))==null?void 0:n.getUnitId());return s?(o.showEditPopup(s,i??null),!0):!1}},V={type:r.CommandType.OPERATION,id:`doc.operation.toggle-hyper-link-info-popup`,handler(e,t){let n=e.get(R);return t?(n.showInfoPopup(t),!0):(n.hideInfoPopup(),!0)}},H={type:r.CommandType.OPERATION,id:`doc.operation.click-hyper-link`,handler(e,t){var n,i;if(!t)return!1;let{unitId:a,linkId:o,segmentId:s}=t,c=e.get(r.IUniverInstanceService).getUnit(a,r.UniverInstanceType.UNIVER_DOC),l=c==null||(n=c.getSelfOrHeaderFooterModel(s))==null?void 0:n.getBody(),u=l==null||(i=l.customRanges)==null||(i=i.find(e=>e.rangeId===o&&e.rangeType===r.CustomRangeType.HYPERLINK))==null||(i=i.properties)==null?void 0:i.url;return(0,r.isSafeUrl)(u)?(window.open(u,`_blank`,`noopener noreferrer`),!0):!1}};function U(e){return{id:B.id,type:n.MenuItemType.BUTTON,icon:`LinkIcon`,title:`docs-hyper-link-ui.menu.tooltip`,tooltip:`docs-hyper-link-ui.menu.tooltip`,hidden$:(0,n.getMenuHiddenObservable)(e,r.UniverInstanceType.UNIVER_DOC),disabled$:new o.Observable(function(t){let n=e.get(i.DocSelectionManagerService).textSelection$.pipe((0,o.debounceTime)(16)).subscribe(()=>{t.next(z(e))});return()=>{n.unsubscribe()}})}}let W={id:B.id,binding:n.MetaKeys.CTRL_COMMAND|n.KeyCode.K,description:`docs-hyper-link-ui.menu.tooltip`,preconditions:t.whenDocAndEditorFocused},G={[n.RibbonInsertGroup.MEDIA]:{[B.id]:{order:1,menuItemFactory:U}},[t.FLOAT_TOOLBAR_MENU_POSITION]:{[B.id]:{order:20,menuItemFactory:U}},[n.ContextMenuPosition.MAIN_AREA]:{[n.ContextMenuGroup.DATA]:{[B.id]:{order:0,menuItemFactory:U}}},[n.ContextMenuPosition.PARAGRAPH]:{[n.ContextMenuGroup.LAYOUT]:{[t.INSERT_BELLOW_MENU_ID]:{[B.id]:{order:6,menuItemFactory:U}}},[t.EMPTY_PARAGRAPH_MENU_ID]:{[n.ContextMenuGroup.LAYOUT]:{[B.id]:{order:6,menuItemFactory:U}}}}};var ae=`@univerjs/docs-hyper-link-ui`,K=`1.0.0-rc.0`;let q={},J=class extends r.Disposable{constructor(e,t){super(),this._componentManager=e,this._iconManager=t,this._registerComponents(),this._registerIcons()}_registerComponents(){[[v.componentKey,v],[N.componentKey,N]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_registerIcons(){this.disposeWithMe(this._iconManager.register({LinkIcon:k}))}};J=L([I(0,(0,r.Inject)(n.ComponentManager)),I(1,(0,r.Inject)(n.IconManager))],J);let Y=class extends r.Disposable{constructor(e,t,n){super(),this._commandService=e,this._univerInstanceService=t,this._docHyperLinkService=n,this._initSelectionChange()}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===i.SetTextSelectionsOperation.id){let{unitId:n,ranges:i,segmentId:a}=e.params,o=this._univerInstanceService.getUnit(n,r.UniverInstanceType.UNIVER_DOC),s=i[0];if(s!=null&&s.collapsed&&o){var t;let{startOffset:e,endOffset:i,segmentPage:c}=s,l=(t=o.getSelfOrHeaderFooterModel(a))==null||(t=t.getBody())==null?void 0:t.customRanges,u=this._docHyperLinkService.showing,d=((u==null?void 0:u.unitId)===n&&(u.segmentId??``)===a&&u.segmentPage===c&&u.endIndex===i-1?l==null?void 0:l.find(t=>t.rangeId===u.linkId&&t.rangeType===r.CustomRangeType.HYPERLINK&&t.startIndex<=e&&t.endIndex===i-1):void 0)??(l==null?void 0:l.find(t=>t.rangeType===r.CustomRangeType.HYPERLINK&&t.startIndex<=e&&t.endIndex>i-1));if(d){this._docHyperLinkService.showInfoPopup({unitId:n,linkId:d.rangeId,segmentId:a,segmentPage:c,startIndex:d.startIndex,endIndex:d.endIndex});return}}this._docHyperLinkService.hideInfoPopup(),this._docHyperLinkService.hideEditPopup()}}))}};Y=L([I(0,r.ICommandService),I(1,r.IUniverInstanceService),I(2,(0,r.Inject)(R))],Y);let X=class extends r.Disposable{get _skeleton(){return this._docSkeletonManagerService.getSkeleton()}constructor(e,t,n,i,a,o){super(),this._context=e,this._docEventManagerService=t,this._commandService=n,this._hyperLinkPopupService=i,this._docSkeletonManagerService=a,this._docSelectionManagerService=o,this._context.unitId!==r.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&(this._initPointerDown(),this._initHover(),this._initClick())}_hideInfoPopup(){this._hyperLinkPopupService.infoPopupPinned||this._hyperLinkPopupService.showing&&this._hyperLinkPopupService.scheduleHideInfoPopup()}_initPointerDown(){this.disposeWithMe(this._docEventManagerService.pointerDownCustomRanges$.subscribe(e=>{e.some(e=>e.range.rangeType===r.CustomRangeType.HYPERLINK)||this._hyperLinkPopupService.hideInfoPopupOnPointerDown()}))}_initHover(){this.disposeWithMe(this._docEventManagerService.hoverCustomRanges$.subscribe(e=>{var t;let n=e.find(e=>e.range.rangeType===r.CustomRangeType.HYPERLINK),i=this._docSelectionManagerService.getTextRanges(),a=i==null||(t=i[0])==null?void 0:t.segmentId;if(((n==null?void 0:n.segmentId)??``)!==a){this._hideInfoPopup();return}n?this._commandService.executeCommand(V.id,{unitId:this._context.unitId,linkId:n.range.rangeId,segmentId:n.segmentId,segmentPage:n.segmentPageIndex,rangeId:n.range.rangeId,startIndex:n.range.startIndex,endIndex:n.range.endIndex}):this._hideInfoPopup()}))}_initClick(){this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe(e=>{let t=e.range;if(t.rangeType===r.CustomRangeType.HYPERLINK){if(!e.ctrlKey&&!e.metaKey){this._hyperLinkPopupService.showInfoPopup({unitId:this._context.unitId,linkId:t.rangeId,segmentId:e.segmentId,segmentPage:e.segmentPageIndex,startIndex:t.startIndex,endIndex:t.endIndex},{pinned:!0});return}this._commandService.executeCommand(H.id,{unitId:this._context.unitId,linkId:t.rangeId,segmentId:e.segmentId})}}))}};X=L([I(1,(0,r.Inject)(t.DocEventManagerService)),I(2,r.ICommandService),I(3,(0,r.Inject)(R)),I(4,(0,r.Inject)(i.DocSkeletonManagerService)),I(5,(0,r.Inject)(i.DocSelectionManagerService))],X);let Z=class extends r.Disposable{constructor(e,t,n){super(),this._docInterceptorService=t,this._hyperLinkService=n,this._init()}_init(){this._docInterceptorService.intercept(i.DOC_INTERCEPTOR_POINT.CUSTOM_RANGE,{handler:(e,t,n)=>{if(!e)return n(e);let{unitId:r,index:i}=t,a=this._hyperLinkService.showing;if(!a)return n({...e,active:!1});let{linkId:o,unitId:s,startIndex:c,endIndex:l}=a,u=s===r&&e.rangeId===o&&i>=c&&i<=l;return n({...e,active:u})}})}};Z=L([I(1,(0,r.Inject)(i.DocInterceptorService)),I(2,(0,r.Inject)(R))],Z);let Q=class extends r.Disposable{constructor(e,t,n){super(),this._commandService=e,this._menuManagerService=t,this._shortcutService=n,this._initCommands(),this._initMenus(),this._initShortcut()}_initCommands(){[f,p,M,B,V,H].forEach(e=>{this._commandService.registerCommand(e)})}_initShortcut(){[W].forEach(e=>{this._shortcutService.registerShortcut(e)})}_initMenus(){this._menuManagerService.appendRootMenu({[t.FLOAT_TOOLBAR_MENU_POSITION]:{}}),this._menuManagerService.mergeMenu(G)}};Q=L([I(0,r.ICommandService),I(1,n.IMenuManagerService),I(2,n.IShortcutService)],Q);let $=class extends r.Plugin{constructor(e=q,t,n,i){super(),this._config=e,this._injector=t,this._renderManagerSrv=n,this._configService=i;let{menu:a,...o}=(0,r.merge)({},q,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(`docs-hyper-link-ui.config`,o)}onStarting(){this._injector.add([J]),this._injector.get(J),[[R],[Q],[Y]].forEach(e=>{this._injector.add(e)}),this._injector.get(Q)}onReady(){this._injector.get(Y)}onRendered(){this._initRenderModule()}_initRenderModule(){[[Z],[X]].forEach(e=>{this._renderManagerSrv.registerRenderModule(r.UniverInstanceType.UNIVER_DOC,e)})}};F($,`pluginName`,`DOC_HYPER_LINK_UI_PLUGIN`),F($,`packageName`,ae),F($,`version`,K),F($,`type`,r.UniverInstanceType.UNIVER_DOC),$=L([(0,r.DependentOn)(i.UniverDocsPlugin,a.UniverRenderEnginePlugin,l.UniverDocsHyperLinkPlugin,t.UniverDocsUIPlugin),I(1,(0,r.Inject)(r.Injector)),I(2,a.IRenderManagerService),I(3,r.IConfigService)],$),e.DocsHyperLinkUIMenuSchema=G,Object.defineProperty(e,"UniverDocsHyperLinkUIPlugin",{enumerable:!0,get:function(){return $}})});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/docs-ui"),require("@univerjs/ui"),require("@univerjs/core"),require("@univerjs/docs"),require("@univerjs/engine-render"),require("rxjs"),require("@univerjs/docs-hyper-link"),require("@univerjs/design"),require("react"),require("react/jsx-runtime"),require("@univerjs/protocol")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/docs-ui`,`@univerjs/ui`,`@univerjs/core`,`@univerjs/docs`,`@univerjs/engine-render`,`rxjs`,`@univerjs/docs-hyper-link`,`@univerjs/design`,`react`,`react/jsx-runtime`,`@univerjs/protocol`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsHyperLinkUi={},e.UniverDocsUi,e.UniverUi,e.UniverCore,e.UniverDocs,e.UniverEngineRender,e.rxjs,e.UniverDocsHyperLink,e.UniverDesign,e.React,e.React,e.UniverProtocol))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let f={type:r.CommandType.COMMAND,id:s.DocHyperLinkCommandId.Delete,async handler(e,t){if(!t)return!1;let{unitId:n,linkId:a,segmentId:o}=t,s=e.get(r.ICommandService),c=(0,i.deleteCustomRangeFactory)(e,{unitId:n,rangeId:a,segmentId:o});return c?await s.syncExecuteCommand(c.id,c.params):!1}},p={type:r.CommandType.COMMAND,id:s.DocHyperLinkCommandId.Add,async handler(e,t){if(!t)return!1;let{payload:n,unitId:a,selections:o}=t,s=e.get(r.ICommandService),c=(0,r.generateRandomId)(),l=(0,i.addCustomRangeBySelectionFactory)(e,{rangeId:c,rangeType:r.CustomRangeType.HYPERLINK,properties:{url:n},unitId:a,selections:o});return l?s.syncExecuteCommand(l.id,l.params):!1}},m={id:s.DocHyperLinkCommandId.Update,type:r.CommandType.COMMAND,handler(e,t){var n,a,o,s,c;if(!t)return!1;let{unitId:l,payload:u,segmentId:d,linkId:f}=t,p=e.get(r.ICommandService),m=e.get(r.IUniverInstanceService),h=e.get(i.DocSelectionManagerService).getActiveTextRange(),g=m.getUnit(l,r.UniverInstanceType.UNIVER_DOC);if(!h||!g)return!1;let _=(n=g.getSelfOrHeaderFooterModel(d))==null?void 0:n.getBody();if(!_)return!1;let v=(a=_.customRanges)==null?void 0:a.find(e=>e.rangeId===f&&e.rangeType===r.CustomRangeType.HYPERLINK),y=(o=(0,r.getBodySlice)(_,h.startOffset,h.endOffset).textRuns)==null?void 0:o[0];y&&(y.ed=t.label.length+1);let b=(0,i.replaceSelectionFactory)(e,{unitId:l,body:{dataStream:`${t.label}`,customRanges:[{rangeId:f,rangeType:r.CustomRangeType.HYPERLINK,startIndex:0,endIndex:t.label.length+1,properties:{url:u,...v!=null&&(s=v.properties)!=null&&s.textStyleMode?{textStyleMode:v.properties.textStyleMode}:null,...v!=null&&(c=v.properties)!=null&&c.textColorMode?{textColorMode:v.properties.textColorMode}:null}}],textRuns:y?[y]:void 0},selection:{startOffset:h.startOffset,endOffset:h.endOffset,collapsed:!1,segmentId:d}});return b?p.syncExecuteCommand(b.id,b.params):!1}};function h(e){return e.trim().length===0}function g(e){return/^[a-zA-Z]+:\/\//.test(e)}function _(e){return/^[\w.-]+@([\w-]+\.)+[\w-]{2,4}$/.test(e)}function v(e){return g(e)?e:_(e)?`mailto://${e}`:`https://${e}`}function y(){let e=(0,n.useDependency)(L),t=(0,n.useObservable)(e.editingLink$,e.editing),a=(0,n.useDependency)(r.ICommandService),o=(0,n.useDependency)(r.IUniverInstanceService),s=(0,n.useDependency)(i.DocSelectionManagerService),[c,u]=(0,l.useState)(``),[d,f]=(0,l.useState)(``),[g,_]=(0,l.useState)(!1),y=r.Tools.isLegalUrl(c),b=t?o.getUnit(t.unitId,r.UniverInstanceType.UNIVER_DOC):o.getCurrentUnitOfType(r.UniverInstanceType.UNIVER_DOC);return(0,l.useEffect)(()=>{var e,n;let i=s.getActiveTextRange();if(!i)return;if(t){var a,o;let e=b==null||(a=b.getSelfOrHeaderFooterModel(t.segmentId))==null?void 0:a.getBody(),n=e==null||(o=e.customRanges)==null?void 0:o.find(e=>t.linkId===e.rangeId&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex);if(b&&n){var c;u(((c=n.properties)==null?void 0:c.url)??``),f(r.BuildTextUtils.transform.getPlainText((0,r.getBodySlice)(e,n.startIndex,n.endIndex+1).dataStream))}return}let l=b==null||(e=b.getSelfOrHeaderFooterModel(i.segmentId))==null?void 0:e.getBody(),d=l?i:null,p=d&&((n=r.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(d,(l==null?void 0:l.customRanges)??[]))==null?void 0:n[0]);if(b&&p){var m;u(((m=p.properties)==null?void 0:m.url)??``)}},[b,s,t]),{doc:b,editing:t,handleCancel:()=>e.hideEditPopup(),handleConfirm:()=>{if(_(!0),!y||!b)return;let n=v(c);if(t){if(h(d))return;a.executeCommand(m.id,{unitId:b.getUnitId(),payload:n,linkId:t.linkId,label:d,segmentId:t.segmentId}).catch(()=>void 0)}else a.executeCommand(p.id,{unitId:b.getUnitId(),payload:n}).catch(()=>void 0);e.hideEditPopup()},isLegal:y,label:d,link:c,setLabel:f,setLink:u,showError:g}}let b=()=>{let e=(0,n.useDependency)(r.LocaleService),{doc:t,editing:i,handleCancel:a,handleConfirm:o,isLegal:s,label:l,link:d,setLabel:f,setLink:p,showError:m}=y();if(t)return(0,u.jsxs)(`div`,{className:(0,c.clsx)(`univer-box-border univer-w-[328px] univer-rounded-xl univer-bg-gray-0 univer-px-6 univer-py-5 univer-shadow dark:!univer-bg-gray-900`,c.borderClassName),children:[(0,u.jsxs)(`div`,{children:[i?(0,u.jsx)(c.FormLayout,{label:e.t(`docs-hyper-link-ui.edit.label`),error:m&&h(l)?e.t(`docs-hyper-link-ui.edit.labelError`):``,children:(0,u.jsx)(c.Input,{value:l,onChange:f,autoFocus:!0,onKeyDown:e=>{e.keyCode===n.KeyCode.ENTER&&o()}})}):null,(0,u.jsx)(c.FormLayout,{label:e.t(`docs-hyper-link-ui.edit.address`),error:m&&!s?e.t(`docs-hyper-link-ui.edit.addressError`):``,children:(0,u.jsx)(c.Input,{value:d,onChange:p,autoFocus:!0,onKeyDown:e=>{e.keyCode===n.KeyCode.ENTER&&o()}})})]}),(0,u.jsxs)(`div`,{className:`univer-flex univer-justify-end univer-gap-3`,children:[(0,u.jsx)(c.Button,{onClick:a,children:e.t(`docs-hyper-link-ui.edit.cancel`)}),(0,u.jsx)(c.Button,{variant:`primary`,disabled:h(d),onClick:o,children:e.t(`docs-hyper-link-ui.edit.confirm`)})]})]})};b.componentKey=`docs-hyper-link-edit`;function x({ref:e,...t}){let{preserveStrokeWidth:n,icon:r,id:i,className:a,extend:o,...s}=t,c=`univerjs-icon univerjs-icon-${i} ${a||``}`.trim(),u=`_${(0,l.useId)()}`,d=(0,l.useRef)(null);return(0,l.useImperativeHandle)(e,()=>d.current),(0,l.useLayoutEffect)(()=>{if(n&&d.current&&d.current.localName===r.tag)return T(d.current)},[n,r]),S(r,`${i}`,{defIds:r.defIds,idSuffix:u},{ref:d,className:c,...s},o)}function S(e,t,n,r,i){return(0,l.createElement)(e.tag,{key:t,...C(e,n,i),...r},(w(e,n).children||[]).map((r,a)=>S(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function C(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),n!=null&&n.colorChannel1&&r.stroke===`colorChannel1`&&(r.stroke=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function w(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function T(e){let t=e.viewBox.baseVal,n=Math.max(t.width,t.height);if(!Number.isFinite(n)||n<=0||t.width<=0||t.height<=0)return()=>void 0;let r=16/n,i=Array.from(e.querySelectorAll(`circle, ellipse, line, path, polygon, polyline, rect, text, textPath, tspan, use`)).flatMap(e=>{let t=getComputedStyle(e),n=Number.parseFloat(t.strokeWidth);return t.stroke===`none`||Number.parseFloat(t.strokeOpacity)===0||t.vectorEffect===`non-scaling-stroke`||!Number.isFinite(n)||n<=0?[]:[{element:e,hadStyleAttribute:e.hasAttribute(`style`),originalStrokeWidth:n,strokeWidth:E(e.style,`stroke-width`)}]}).map(e=>({appliedStrokeWidth:null,element:e.element,hadStyleAttribute:e.hadStyleAttribute,isReleased:!1,originalStrokeWidth:e.originalStrokeWidth,strokeWidth:e.strokeWidth}));if(i.length===0)return()=>void 0;let a=(e,n)=>{if(t.width<=0||t.height<=0||e<=0||n<=0)return;let a=Math.min(e/t.width,n/t.height);!Number.isFinite(a)||a<=0||i.forEach(e=>{if(e.isReleased)return;if(e.appliedStrokeWidth!==null&&(e.element.style.getPropertyValue(`stroke-width`)!==e.appliedStrokeWidth||e.element.style.getPropertyPriority(`stroke-width`)!==e.strokeWidth.priority)){e.appliedStrokeWidth=null,e.isReleased=!0;return}let t=e.originalStrokeWidth*r/a,n=`${Number(t.toFixed(12))}px`;e.element.style.setProperty(`stroke-width`,n,e.strokeWidth.priority),e.appliedStrokeWidth=n})},o=e.getBoundingClientRect();a(o.width,o.height);let s=typeof ResizeObserver>`u`?null:new ResizeObserver(t=>{if(t.some(t=>t.target===e)){let t=e.getBoundingClientRect();a(t.width,t.height)}});return s==null||s.observe(e),()=>{s==null||s.disconnect(),i.forEach(e=>{e.appliedStrokeWidth!==null&&(D(e.element.style,`stroke-width`,e.appliedStrokeWidth,e.strokeWidth.priority,e.strokeWidth),!e.hadStyleAttribute&&e.element.style.length===0&&e.element.removeAttribute(`style`))})}}function E(e,t){return{priority:e.getPropertyPriority(t),value:e.getPropertyValue(t)}}function D(e,t,n,r,i){e.getPropertyValue(t)===n&&e.getPropertyPriority(t)===r&&(i.value?e.setProperty(t,i.value,i.priority):e.removeProperty(t))}x.displayName=`UniverIcon`;let O={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,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`}}]},k=(0,l.forwardRef)(function(e,t){return(0,l.createElement)(x,Object.assign({},e,{id:`copy-icon`,ref:t,icon:O}))});k.displayName=`CopyIcon`;let A={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{stroke:`currentColor`,d:`M7.30999 8.71386C6.39955 7.80343 6.37922 6.34731 7.26629 5.45772L10.313 2.41112C11.2111 1.51303 12.6799 1.51258 13.5691 2.45476C14.4811 3.36679 14.4798 4.84384 13.6128 5.71094L10.9677 8.35604`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.22}},{tag:`path`,attrs:{stroke:`currentColor`,d:`M5.0456 7.66774L2.4005 10.3128C1.50242 11.2109 1.50197 12.6798 2.44413 13.5691C3.35615 14.4811 4.8332 14.4798 5.70033 13.6127L8.747 10.566C9.65743 9.65558 9.67776 8.19945 8.7905 7.30999`,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:1.22}}]},j=(0,l.forwardRef)(function(e,t){return(0,l.createElement)(x,Object.assign({},e,{id:`link-icon`,ref:t,icon:A}))});j.displayName=`LinkIcon`;let ee={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,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.76157C6.75249 4.52725 6.75249 4.14735 6.98681 3.91304L8.27535 2.62449C9.70209 1.19776 12.0153 1.19776 13.442 2.62449C14.8688 4.05123 14.8688 6.36442 13.442 7.79116L12.1535 9.0797C11.9192 9.31402 11.5393 9.31402 11.3049 9.0797C11.0706 8.84539 11.0706 8.46549 11.3049 8.23117L12.5935 6.94263C13.5516 5.98452 13.5516 4.43113 12.5935 3.47302Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M3.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.05395C4.4606 6.81963 4.0807 6.81963 3.84639 7.05395L2.55784 8.34249C1.13111 9.76923 1.13111 12.0824 2.55784 13.5092C3.98458 14.9359 6.29777 14.9359 7.72451 13.5092L9.01305 12.2206C9.24737 11.9863 9.24737 11.6064 9.01305 11.3721C8.77874 11.1378 8.39884 11.1378 8.16452 11.3721L6.87598 12.6606C5.91787 13.6187 4.36448 13.6187 3.40637 12.6606Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M3.5852 2.80332C3.35088 2.569 2.97098 2.569 2.73667 2.80332C2.50235 3.03763 2.50235 3.41753 2.73667 3.65185L12.4151 13.3302C12.6494 13.5646 13.0293 13.5646 13.2636 13.3302C13.4979 13.0959 13.4979 12.716 13.2636 12.4817L3.5852 2.80332Z`}}]},te=(0,l.forwardRef)(function(e,t){return(0,l.createElement)(x,Object.assign({},e,{id:`unlink-icon`,ref:t,icon:ee}))});te.displayName=`UnlinkIcon`;let ne={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,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`}}]},re=(0,l.forwardRef)(function(e,t){return(0,l.createElement)(x,Object.assign({},e,{id:`write-icon`,ref:t,icon:ne}))});re.displayName=`WriteIcon`;let M=()=>{var e,t,a,o,s;let l=(0,n.useDependency)(L),p=(0,n.useDependency)(r.ICommandService),m=(0,n.useDependency)(n.IMessageService),h=(0,n.useDependency)(r.LocaleService),g=(0,n.useObservable)(l.showingLink$,l.showing),_=(0,n.useDependency)(r.IUniverInstanceService),v=(0,n.useDependency)(r.IPermissionService);if(!g)return null;let{unitId:y,linkId:b,segmentId:x,startIndex:S,endIndex:C}=g,w=_.getUnit(y,r.UniverInstanceType.UNIVER_DOC),T=w instanceof r.DocumentDataModel?(e=w.getSelfOrHeaderFooterModel(x))==null?void 0:e.getBody():void 0,E=T==null||(t=T.customRanges)==null?void 0:t.find(e=>e.rangeId===b&&e.rangeType===r.CustomRangeType.HYPERLINK&&e.startIndex===S&&e.endIndex===C);if(!E)return null;let D=((a=E.properties)==null?void 0:a.url)??`#${((o=E.properties)==null?void 0:o.bookmarkId)??((s=E.properties)==null?void 0:s.headingId)??``}`,O=l.canEditLink(y,g),A=(0,i.getDocumentPermissionValue)(v,y,y,d.UnitAction.Copy);return(0,u.jsxs)(`div`,{className:(0,c.clsx)(`univer-box-border univer-flex univer-max-w-80 univer-items-center univer-justify-between univer-overflow-hidden univer-rounded-lg univer-bg-gray-0 univer-p-3 univer-shadow dark:!univer-bg-gray-900`,c.borderClassName),onPointerEnter:()=>{l.cancelScheduledHideInfoPopup()},onPointerLeave:()=>{l.scheduleHideInfoPopup()},onClick:()=>{l.hideInfoPopup()},children:[(0,u.jsxs)(`div`,{className:`univer-flex univer-h-6 univer-flex-1 univer-cursor-pointer univer-items-center univer-truncate univer-text-sm univer-leading-5 univer-text-primary-500`,onClick:()=>p.executeCommand(B.id,{unitId:y,linkId:b,segmentId:x}),children:[(0,u.jsx)(`div`,{className:`univer-mr-2 univer-flex univer-size-5 univer-flex-[0_0_auto] univer-items-center univer-justify-center univer-text-base univer-text-gray-900 dark:!univer-text-gray-0`,children:(0,u.jsx)(j,{})}),(0,u.jsx)(c.Tooltip,{showIfEllipsis:!0,title:D,children:(0,u.jsx)(`span`,{className:`univer-flex-1 univer-truncate`,children:D})})]}),(0,u.jsxs)(`div`,{className:`univer-flex univer-h-6 univer-flex-[0_0_auto] univer-items-center univer-justify-center`,children:[(0,u.jsx)(c.Button,{type:`button`,variant:`text`,size:`small`,"aria-label":h.t(`docs-hyper-link-ui.info.copy`),className:`univer-ml-2 !univer-flex univer-size-6 !univer-rounded !univer-border-0 !univer-bg-transparent !univer-p-0 !univer-text-base !univer-font-normal hover:!univer-bg-transparent active:!univer-bg-transparent disabled:!univer-pointer-events-auto disabled:!univer-opacity-40`,disabled:!A,onClick:()=>{navigator.clipboard.writeText(D),m.show({content:h.t(`docs-hyper-link-ui.info.coped`),type:c.MessageType.Info})},children:(0,u.jsx)(c.Tooltip,{placement:`bottom`,title:h.t(`docs-hyper-link-ui.info.copy`),children:(0,u.jsx)(k,{})})}),O&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(`div`,{className:`univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base`,onClick:()=>{p.executeCommand(z.id,{link:g})},children:(0,u.jsx)(c.Tooltip,{placement:`bottom`,title:h.t(`docs-hyper-link-ui.info.edit`),children:(0,u.jsx)(re,{})})}),(0,u.jsx)(`div`,{className:`univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base`,onClick:()=>{p.executeCommand(f.id,{unitId:y,linkId:E.rangeId,segmentId:x})},children:(0,u.jsx)(c.Tooltip,{placement:`bottom`,title:h.t(`docs-hyper-link-ui.info.cancel`),children:(0,u.jsx)(te,{})})})]})]})]})};M.componentKey=`univer.doc.link-info-popup`;function N(e){"@babel/helpers - typeof";return N=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},N(e)}function ie(e,t){if(N(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(N(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function ae(e){var t=ie(e,`string`);return N(t)==`symbol`?t:t+``}function P(e,t,n){return(t=ae(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function F(e,t){return function(n,r){t(n,r,e)}}function I(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function oe(e,t){return(e==null?void 0:e.linkId)===t.linkId&&e.unitId===t.unitId&&(e.segmentId??``)===(t.segmentId??``)&&e.segmentPage===t.segmentPage&&e.startIndex===t.startIndex&&e.endIndex===t.endIndex}let L=class extends r.Disposable{constructor(e,t,n,r,i,a,s,c){super(),this._docCanvasPopupManagerService=e,this._textSelectionManagerService=t,this._univerInstanceService=n,this._permissionService=r,this._renderManagerService=i,this._dialogService=a,this._localeService=s,this._commandService=c,P(this,`_editingLink$`,new o.BehaviorSubject(null)),P(this,`_showingLink$`,new o.BehaviorSubject(null)),P(this,`editingLink$`,this._editingLink$.asObservable()),P(this,`showingLink$`,this._showingLink$.asObservable()),P(this,`_editPopup`,null),P(this,`_editPopupUnitId`,null),P(this,`_infoPopup`,null),P(this,`_infoPopupPinned`,!1),P(this,`_infoPopupHideTimer`,null),P(this,`_infoPopupSuppressed`,!1),P(this,`_infoPopupSuppressionTimer`,null),this.disposeWithMe(()=>{this.cancelScheduledHideInfoPopup(),this._infoPopupSuppressionTimer!==null&&clearTimeout(this._infoPopupSuppressionTimer),this._editingLink$.complete(),this._showingLink$.complete()}),this.disposeWithMe(this._permissionService.permissionPointUpdate$.subscribe(()=>{let e=this.editing;e&&!this.canEditLink(e.unitId,e)&&this.hideEditPopup();let t=this.showing;t&&this._showingLink$.next({...t})})),this.disposeWithMe(this._renderManagerService.disposed$.subscribe(e=>{var t;this._editPopupUnitId===e&&this.hideEditPopup(),((t=this.showing)==null?void 0:t.unitId)===e&&this.hideInfoPopup()}))}dispose(){this.hideEditPopup(),this.hideInfoPopup(),super.dispose()}get editing(){return this._editingLink$.value}get showing(){return this._showingLink$.value}get infoPopupPinned(){return this._infoPopupPinned}showEditPopup(e,t){if(!this.canEditLink(e,t))return null;this._editPopup&&(this._editPopup.dispose(),this._editPopup=null,this._editPopupUnitId=null),this._editingLink$.next(t);let n=this._textSelectionManagerService.getTextRanges({unitId:e,subUnitId:e}),r=n==null?void 0:n[n.length-1];if(t){let{segmentId:e,segmentPage:n,startIndex:i,endIndex:a}=t;r={collapsed:!1,startOffset:i,endOffset:a+1,segmentId:e,segmentPage:n},this._textSelectionManagerService.replaceDocRanges([{startOffset:i,endOffset:a+1}])}return r?(this._editPopup=this._openEditSurface(r,e),this._editPopupUnitId=e,this._editPopup):null}hideEditPopup(){this._editingLink$.next(null);let e=this._editPopup;this._editPopup=null,e==null||e.dispose(),this._editPopupUnitId=null}showInfoPopup(e,t){if(this.cancelScheduledHideInfoPopup(),this._infoPopupSuppressed)return;let{linkId:n,unitId:i,segmentId:a,segmentPage:o,startIndex:s,endIndex:c}=e;if(oe(this.showing,e)){t!=null&&t.pinned&&(this._infoPopupPinned=!0);return}if(this._infoPopup&&=(this._infoPopup.dispose(),null),this._univerInstanceService.getUnit(i,r.UniverInstanceType.UNIVER_DOC)instanceof r.DocumentDataModel)return this._infoPopupPinned=(t==null?void 0:t.pinned)??!1,this._showingLink$.next({unitId:i,linkId:n,segmentId:a,segmentPage:o,startIndex:s,endIndex:c}),this._infoPopup=this._openInfoSurface(e),this._infoPopup}_openEditSurface(e,t){return this._docCanvasPopupManagerService.attachPopupToRange(e,{componentKey:b.componentKey,direction:`bottom`,offset:[0,10]},t)}_openInfoSurface(e,t=M.componentKey){let{unitId:n,linkId:r,segmentId:i,segmentPage:a,startIndex:o,endIndex:s}=e;return this._docCanvasPopupManagerService.attachPopupToRange({collapsed:!1,startOffset:o,endOffset:s+1,segmentId:i,segmentPage:a},{componentKey:t,extraProps:{onEdit:()=>{this.hideInfoPopup(),this.showEditPopup(n,e)},onDelete:async()=>{await this._commandService.executeCommand(f.id,{unitId:n,linkId:r,segmentId:i})&&this.hideInfoPopup()}},direction:`top-center`,multipleDirection:`top`,offset:[0,10],onClickOutside:()=>{this.hideInfoPopup()}},n)}showInfoPopupFromHover(e){this.cancelScheduledHideInfoPopup(),!(this._infoPopupPinned||this._infoPopupSuppressed)&&(this.showing||this.showInfoPopup(e))}hideInfoPopup(){this.cancelScheduledHideInfoPopup(),this._infoPopupPinned=!1,this._showingLink$.next(null);let e=this._infoPopup;this._infoPopup=null,e==null||e.dispose()}scheduleHideInfoPopup(){!this._infoPopupPinned&&this.showing&&(this.cancelScheduledHideInfoPopup(),this._infoPopupHideTimer=setTimeout(()=>{this._infoPopupHideTimer=null,this._infoPopupPinned||this.hideInfoPopup()},150))}cancelScheduledHideInfoPopup(){this._infoPopupHideTimer!==null&&(clearTimeout(this._infoPopupHideTimer),this._infoPopupHideTimer=null)}hideInfoPopupOnPointerDown(){this._infoPopupSuppressed=!0,this._infoPopupSuppressionTimer!==null&&clearTimeout(this._infoPopupSuppressionTimer),this.hideInfoPopup(),this._infoPopupSuppressionTimer=setTimeout(()=>{this._infoPopupSuppressed=!1,this._infoPopupSuppressionTimer=null},0)}canEditLink(e,t){let n=this._univerInstanceService.getUnit(e,r.UniverInstanceType.UNIVER_DOC);if(!(n instanceof r.DocumentDataModel))return!1;if(!t)return(0,i.canEditDocumentTargets)(this._permissionService,e,[]);let a=t.segmentId??``;return(0,i.canEditDocumentTargets)(this._permissionService,e,[...(0,i.getDocumentEntityParentPermissionObjectIds)(n,a,`custom-range`,t.linkId),(0,i.getDocumentEntityPermissionObjectId)(a,`custom-range`,t.linkId)])}};L=I([F(0,(0,r.Inject)(t.DocCanvasPopManagerService)),F(1,(0,r.Inject)(i.DocSelectionManagerService)),F(2,r.IUniverInstanceService),F(3,r.IPermissionService),F(4,a.IRenderManagerService),F(5,n.IDialogService),F(6,(0,r.Inject)(r.LocaleService)),F(7,r.ICommandService)],L);let R=e=>{let t=e.get(i.DocSelectionManagerService),n=e.get(r.IUniverInstanceService),a=t.getTextRanges();if(!(a!=null&&a.length))return!0;let o=a[0];return!(n.getCurrentUnitOfType(r.UniverInstanceType.UNIVER_DOC)&&o&&!o.collapsed)},z={type:r.CommandType.OPERATION,id:`doc.operation.show-hyper-link-edit-popup`,handler(e,t){var n;let i=t==null?void 0:t.link,a=e.get(r.IUniverInstanceService);if(R(e)&&!i)return!1;let o=e.get(L),s=(i==null?void 0:i.unitId)||((n=a.getCurrentUnitOfType(r.UniverInstanceType.UNIVER_DOC))==null?void 0:n.getUnitId());return s?(o.showEditPopup(s,i??null),!0):!1}},se={type:r.CommandType.OPERATION,id:`doc.operation.toggle-hyper-link-info-popup`,handler(e,t){let n=e.get(L);return t?(t.fromHover?n.showInfoPopupFromHover(t):n.showInfoPopup(t),!0):(n.hideInfoPopup(),!0)}},B={type:r.CommandType.OPERATION,id:`doc.operation.click-hyper-link`,handler(e,n){var o,s;if(!n)return!1;let{unitId:c,linkId:l,segmentId:u}=n,d=e.get(r.IUniverInstanceService).getUnit(c,r.UniverInstanceType.UNIVER_DOC),f=d==null||(o=d.getSelfOrHeaderFooterModel(u))==null?void 0:o.getBody(),p=f==null||(s=f.customRanges)==null||(s=s.find(e=>e.rangeId===l&&e.rangeType===r.CustomRangeType.HYPERLINK))==null?void 0:s.properties;if(p!=null&&p.bookmarkId||p!=null&&p.headingId){var m;let n=ce(d==null?void 0:d.getBody(),p.bookmarkId,p.headingId);if(n==null)return!1;let r={startOffset:n,endOffset:n,collapsed:!0},o=e.get(i.DocSelectionManagerService),s=()=>o.replaceDocRanges([r],{unitId:c,subUnitId:c},!1,{[i.DOC_SELECTION_OPTION_PRESERVE_CARET]:!0}),l=e.get(a.IRenderManagerService).getRenderUnitById(c),u=l==null||(m=l.getInjector)==null?void 0:m.call(l),f=u!=null&&u.has(t.DocBackScrollRenderController)?l==null?void 0:l.with(t.DocBackScrollRenderController):null;return f?f.scrollToRange(r,s):s(),!0}return!(p!=null&&p.url)||!(0,r.isSafeUrl)(p.url)?!1:(window.open(p.url,`_blank`,`noopener noreferrer`),!0)}};function ce(e,t,n){if(e){if(t){var i;let n=(i=e.customRanges)==null?void 0:i.find(e=>{var n;return e.rangeType===r.CustomRangeType.BOOKMARK&&(e.rangeId===t||((n=e.properties)==null?void 0:n.bookmarkId)===t)});if(n)return n.startIndex}if(n){var a;let t=((a=e.paragraphs)==null?void 0:a.findIndex(e=>{var t;return((t=e.paragraphStyle)==null?void 0:t.headingId)===n}))??-1;if(t>=0)return t===0?0:e.paragraphs[t-1].startIndex+1}}}function V(e){return{id:z.id,type:n.MenuItemType.BUTTON,icon:`LinkIcon`,title:`docs-hyper-link-ui.menu.tooltip`,tooltip:`docs-hyper-link-ui.menu.tooltip`,hidden$:(0,n.getMenuHiddenObservable)(e,r.UniverInstanceType.UNIVER_DOC),disabled$:new o.Observable(function(t){let n=e.get(i.DocSelectionManagerService).textSelection$.pipe((0,o.debounceTime)(16)).subscribe(()=>{t.next(R(e))});return()=>{n.unsubscribe()}})}}let le={id:z.id,binding:n.MetaKeys.CTRL_COMMAND|n.KeyCode.K,description:`docs-hyper-link-ui.menu.tooltip`,preconditions:t.whenDocAndEditorFocused},ue={[n.RibbonInsertGroup.MEDIA]:{[z.id]:{order:1,gridLayout:{row:1,column:5},menuItemFactory:V}},[t.FLOAT_TOOLBAR_MENU_POSITION]:{[z.id]:{order:20,menuItemFactory:V}},[n.ContextMenuPosition.MAIN_AREA]:{[n.ContextMenuGroup.DATA]:{[z.id]:{order:0,menuItemFactory:V}}},[n.ContextMenuPosition.PARAGRAPH]:{[n.ContextMenuGroup.LAYOUT]:{[t.INSERT_BELLOW_MENU_ID]:{[z.id]:{order:6,menuItemFactory:V}}},[t.EMPTY_PARAGRAPH_MENU_ID]:{[n.ContextMenuGroup.LAYOUT]:{[z.id]:{order:6,menuItemFactory:V}}}}};var de=`@univerjs/docs-hyper-link-ui`,fe=`1.0.1`;let pe=`docs-hyper-link-ui.config`,H={},U=class extends r.Disposable{constructor(e,t,n){super(),this._commandService=e,this._univerInstanceService=t,this._docHyperLinkService=n,P(this,`_selection`,null),this._initSelectionChange(),this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(e=>{var t;((t=this._selection)==null?void 0:t.unitId)===e.getUnitId()&&(this._selection=null)}))}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===i.RichTextEditingMutation.id){var t;e.params.unitId===((t=this._docHyperLinkService.showing)==null?void 0:t.unitId)&&this._docHyperLinkService.hideInfoPopup();return}if(e.id===i.SetTextSelectionsOperation.id){var n;let t=e.params,{unitId:i,ranges:o,segmentId:s}=t,c=this._univerInstanceService.getUnit(i,r.UniverInstanceType.UNIVER_DOC),l=o[0],u=JSON.stringify([i,s??``,l==null?void 0:l.startOffset,l==null?void 0:l.endOffset,l==null?void 0:l.segmentPage]),d=u===((n=this._selection)==null?void 0:n.key);this._selection={unitId:i,key:u};let f=this._docHyperLinkService.editing;if((f==null?void 0:f.unitId)===i&&(f.segmentId??``)===(s??``)&&(l==null?void 0:l.startOffset)===f.startIndex&&l.endOffset===f.endIndex+1)return;if(t.isEditing){this._docHyperLinkService.hideInfoPopup();return}if(d)return;if(l!=null&&l.collapsed&&c){var a;let{startOffset:e,endOffset:t,segmentPage:n}=l,o=(a=c.getSelfOrHeaderFooterModel(s))==null||(a=a.getBody())==null?void 0:a.customRanges,u=this._docHyperLinkService.showing,d=((u==null?void 0:u.unitId)===i&&(u.segmentId??``)===s&&u.segmentPage===n&&u.endIndex===t-1?o==null?void 0:o.find(n=>n.rangeId===u.linkId&&n.rangeType===r.CustomRangeType.HYPERLINK&&n.startIndex<=e&&n.endIndex===t-1):void 0)??(o==null?void 0:o.find(n=>n.rangeType===r.CustomRangeType.HYPERLINK&&n.startIndex<=e&&n.endIndex>t-1));if(d){this._docHyperLinkService.showInfoPopup({unitId:i,linkId:d.rangeId,segmentId:s,segmentPage:n,startIndex:d.startIndex,endIndex:d.endIndex});return}}this._docHyperLinkService.hideInfoPopup(),this._docHyperLinkService.hideEditPopup()}}))}};U=I([F(0,r.ICommandService),F(1,r.IUniverInstanceService),F(2,(0,r.Inject)(L))],U);function W(){let e=(0,n.useDependency)(r.LocaleService),{doc:t,editing:i,handleCancel:a,handleConfirm:o,isLegal:s,label:l,link:d,setLabel:f,setLink:p,showError:m}=y();if(t)return(0,u.jsxs)(`div`,{className:`univer-box-border univer-w-full univer-bg-gray-0 univer-py-2 dark:!univer-bg-gray-900`,children:[(0,u.jsxs)(`div`,{children:[i?(0,u.jsx)(c.FormLayout,{label:e.t(`docs-hyper-link-ui.edit.label`),error:m&&h(l)?e.t(`docs-hyper-link-ui.edit.labelError`):``,children:(0,u.jsx)(c.Input,{value:l,onChange:f,autoFocus:!0,onKeyDown:e=>{e.keyCode===n.KeyCode.ENTER&&o()}})}):null,(0,u.jsx)(c.FormLayout,{label:e.t(`docs-hyper-link-ui.edit.address`),error:m&&!s?e.t(`docs-hyper-link-ui.edit.addressError`):``,children:(0,u.jsx)(c.Input,{value:d,onChange:p,autoFocus:!i,onKeyDown:e=>{e.keyCode===n.KeyCode.ENTER&&o()}})})]}),(0,u.jsxs)(`div`,{className:`univer-mt-5 univer-flex univer-gap-3`,children:[(0,u.jsx)(c.Button,{className:`univer-h-12 univer-flex-1`,onClick:a,children:e.t(`docs-hyper-link-ui.edit.cancel`)}),(0,u.jsx)(c.Button,{variant:`primary`,className:`univer-h-12 univer-flex-1`,disabled:h(d),onClick:o,children:e.t(`docs-hyper-link-ui.edit.confirm`)})]})]})}W.componentKey=`univer.doc.mobile-hyper-link-edit`;function G(){var e,t,a;let o=(0,n.useDependency)(r.ICommandService),s=(0,n.useDependency)(L),l=(0,n.useDependency)(r.LocaleService),p=(0,n.useDependency)(n.IMessageService),m=(0,n.useDependency)(r.IPermissionService),h=(0,n.useDependency)(r.IUniverInstanceService),g=(0,n.useObservable)(s.showingLink$,s.showing);if(!g)return null;let{unitId:_,linkId:v,segmentId:y,startIndex:b,endIndex:x}=g,S=h.getUnit(_,r.UniverInstanceType.UNIVER_DOC),C=S instanceof r.DocumentDataModel?(e=S.getSelfOrHeaderFooterModel(y))==null?void 0:e.getBody():void 0,w=C==null||(t=C.customRanges)==null?void 0:t.find(e=>e.rangeId===v&&e.rangeType===r.CustomRangeType.HYPERLINK&&e.startIndex===b&&e.endIndex===x);if(!w)return null;let T=(a=w.properties)==null?void 0:a.url,E=s.canEditLink(_,g),D=(0,i.getDocumentPermissionValue)(m,_,_,d.UnitAction.Copy);return(0,u.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-2 univer-py-2`,children:[(0,u.jsx)(c.MobileActionRow,{title:(0,u.jsx)(`span`,{className:`univer-truncate univer-text-primary-600`,children:T}),"aria-label":T,variant:`subtle`,onClick:()=>window.open(T,void 0,`noopener noreferrer`)}),D&&(0,u.jsx)(c.MobileActionRow,{title:l.t(`docs-hyper-link-ui.info.copy`),"aria-label":l.t(`docs-hyper-link-ui.info.copy`),variant:`subtle`,onClick:()=>navigator.clipboard.writeText(T).then(()=>{p.show({content:l.t(`docs-hyper-link-ui.info.coped`),type:c.MessageType.Info})}).catch(()=>void 0)}),E&&(0,u.jsxs)(u.Fragment,{children:[(0,u.jsx)(c.MobileActionRow,{title:l.t(`docs-hyper-link-ui.info.edit`),"aria-label":l.t(`docs-hyper-link-ui.info.edit`),variant:`subtle`,onClick:()=>{o.executeCommand(z.id,{link:g}).catch(()=>void 0)}}),(0,u.jsx)(c.MobileActionRow,{title:l.t(`docs-hyper-link-ui.info.cancel`),"aria-label":l.t(`docs-hyper-link-ui.info.cancel`),variant:`subtle`,onClick:()=>{o.executeCommand(f.id,{unitId:_,linkId:w.rangeId,segmentId:y}).catch(()=>void 0)}})]})]})}G.componentKey=`univer.doc.mobile-link-info-popup`;let K=class extends r.Disposable{constructor(e,t){super(),this._componentManager=e,this._iconManager=t,this._registerComponents(),this._registerIcons()}_registerComponents(){[[W.componentKey,W],[G.componentKey,G]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_registerIcons(){this.disposeWithMe(this._iconManager.register({LinkIcon:j}))}};K=I([F(0,(0,r.Inject)(n.ComponentManager)),F(1,(0,r.Inject)(n.IconManager))],K);let q=class extends r.Disposable{get _skeleton(){return this._docSkeletonManagerService.getSkeleton()}constructor(e,t,n,i,a,o){super(),this._context=e,this._docEventManagerService=t,this._commandService=n,this._hyperLinkPopupService=i,this._docSkeletonManagerService=a,this._mobileElementMenuService=o,this._context.unitId!==r.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&(this._initPointerDown(),this._initClick())}_initPointerDown(){this.disposeWithMe(this._docEventManagerService.pointerDownCustomRanges$.subscribe(e=>{let t=e.find(e=>e.range.rangeType===r.CustomRangeType.HYPERLINK);if(!t){this._hyperLinkPopupService.hideInfoPopupOnPointerDown();return}let n={unitId:this._context.unitId,linkId:t.range.rangeId,segmentId:t.segmentId,segmentPage:t.segmentPageIndex,startIndex:t.range.startIndex,endIndex:t.range.endIndex},i=t.rects[0];i&&this._hyperLinkPopupService.canEditLink(n.unitId,n)&&this._mobileElementMenuService.capture({unitId:n.unitId,rect:i,onEdit:()=>this._hyperLinkPopupService.showEditPopup(n.unitId,n),onDelete:()=>this._commandService.executeCommand(f.id,n)})}))}_initClick(){this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe(e=>{let t=e.range;if(t.rangeType===r.CustomRangeType.HYPERLINK){if(!e.ctrlKey&&!e.metaKey){this._hyperLinkPopupService.showInfoPopup({unitId:this._context.unitId,linkId:t.rangeId,segmentId:e.segmentId,segmentPage:e.segmentPageIndex,startIndex:t.startIndex,endIndex:t.endIndex},{pinned:!0});return}this._commandService.executeCommand(B.id,{unitId:this._context.unitId,linkId:t.rangeId,segmentId:e.segmentId})}}))}};q=I([F(1,(0,r.Inject)(t.DocEventManagerService)),F(2,r.ICommandService),F(3,(0,r.Inject)(L)),F(4,(0,r.Inject)(i.DocSkeletonManagerService)),F(5,(0,r.Inject)(t.DocMobileElementMenuService))],q);let J=class extends r.Disposable{constructor(e,t,n){super(),this._docInterceptorService=t,this._hyperLinkService=n,this._init()}_init(){this._docInterceptorService.intercept(i.DOC_INTERCEPTOR_POINT.CUSTOM_RANGE,{handler:(e,t,n)=>{if(!e)return n(e);let{unitId:r,index:i}=t,a=this._hyperLinkService.showing;if(!a)return n({...e,active:!1});let{linkId:o,unitId:s,startIndex:c,endIndex:l}=a,u=s===r&&e.rangeId===o&&i>=c&&i<=l;return n({...e,active:u})}})}};J=I([F(1,(0,r.Inject)(i.DocInterceptorService)),F(2,(0,r.Inject)(L))],J);let Y=class extends r.Disposable{constructor(e,t,n){super(),this._commandService=e,this._menuManagerService=t,this._shortcutService=n,this._initCommands(),this._initMenus(),this._initShortcut()}_initCommands(){[p,m,f,z,se,B].forEach(e=>{this._commandService.registerCommand(e)})}_initShortcut(){[le].forEach(e=>{this._shortcutService.registerShortcut(e)})}_initMenus(){this._menuManagerService.appendRootMenu({[t.FLOAT_TOOLBAR_MENU_POSITION]:{}}),this._menuManagerService.mergeMenu(ue)}};Y=I([F(0,r.ICommandService),F(1,n.IMenuManagerService),F(2,n.IShortcutService)],Y);var me=class extends L{_openEditSurface(e,t){return this._dialogService.open({id:`doc-mobile-hyper-link-editor`,title:{title:this._localeService.t(`docs-hyper-link-ui.menu.tooltip`)},children:{label:W.componentKey},maskClosable:!1,onClose:()=>this.hideEditPopup()})}_openInfoSurface(e){return this.canEditLink(e.unitId,e)?super._openInfoSurface(e,t.MOBILE_DOC_ELEMENT_MENU):this._dialogService.open({id:`doc-mobile-hyper-link-viewer`,title:{title:this._localeService.t(`docs-hyper-link-ui.menu.tooltip`)},children:{label:G.componentKey},onClose:()=>this.hideInfoPopup()})}};let he=`DOC_HYPER_LINK_UI_PLUGIN`,X=class extends r.Plugin{constructor(e=H,t,n,i){super(),this._config=e,this._injector=t,this._renderManagerSrv=n,this._configService=i;let{menu:a,...o}=(0,r.merge)({},H,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(pe,o)}onStarting(){[[K],[L,{useClass:me}],[Y],[U]].forEach(e=>this._injector.add(e)),this._injector.get(K),this._injector.get(Y)}onReady(){this._injector.get(U)}onRendered(){[[J],[q]].forEach(e=>{this._renderManagerSrv.registerRenderModule(r.UniverInstanceType.UNIVER_DOC,e)})}};P(X,`pluginName`,he),P(X,`packageName`,de),P(X,`version`,fe),P(X,`type`,r.UniverInstanceType.UNIVER_DOC),X=I([(0,r.DependentOn)(i.UniverDocsPlugin,a.UniverRenderEnginePlugin,s.UniverDocsHyperLinkPlugin,t.UniverDocsMobileUIPlugin),F(1,(0,r.Inject)(r.Injector)),F(2,a.IRenderManagerService),F(3,r.IConfigService)],X);let Z=class extends r.Disposable{constructor(e,t){super(),this._componentManager=e,this._iconManager=t,this._registerComponents(),this._registerIcons()}_registerComponents(){[[b.componentKey,b],[M.componentKey,M]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_registerIcons(){this.disposeWithMe(this._iconManager.register({LinkIcon:j}))}};Z=I([F(0,(0,r.Inject)(n.ComponentManager)),F(1,(0,r.Inject)(n.IconManager))],Z);let Q=class extends r.Disposable{get _skeleton(){return this._docSkeletonManagerService.getSkeleton()}constructor(e,t,n,i,a,o){super(),this._context=e,this._docEventManagerService=t,this._commandService=n,this._hyperLinkPopupService=i,this._docSkeletonManagerService=a,this._docSelectionManagerService=o,this._context.unitId!==r.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&(this._initPointerDown(),this._initHover(),this._initClick())}_hideInfoPopup(){this._hyperLinkPopupService.infoPopupPinned||this._hyperLinkPopupService.showing&&this._hyperLinkPopupService.scheduleHideInfoPopup()}_normalizeSegmentId(e){var t;return e?(t=this._context.unit.getBody())!=null&&(t=t.tables)!=null&&t.some(t=>t.tableId===e)?``:e:``}_initPointerDown(){this.disposeWithMe(this._docEventManagerService.pointerDownCustomRanges$.subscribe(e=>{e.find(e=>e.range.rangeType===r.CustomRangeType.HYPERLINK)||this._hyperLinkPopupService.hideInfoPopupOnPointerDown()}))}_initHover(){this.disposeWithMe(this._docEventManagerService.hoverCustomRanges$.subscribe(e=>{var t;let n=e.find(e=>e.range.rangeType===r.CustomRangeType.HYPERLINK),i=this._docSelectionManagerService.getTextRanges(),a=i==null||(t=i[0])==null?void 0:t.segmentId;if(this._normalizeSegmentId(n==null?void 0:n.segmentId)!==this._normalizeSegmentId(a)){this._hideInfoPopup();return}if(n){let e={unitId:this._context.unitId,linkId:n.range.rangeId,segmentId:n.segmentId,segmentPage:n.segmentPageIndex,startIndex:n.range.startIndex,endIndex:n.range.endIndex};this._commandService.executeCommand(se.id,{...e,fromHover:!0})}else this._hideInfoPopup()}))}_initClick(){this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe(e=>{let t=e.range;if(t.rangeType===r.CustomRangeType.HYPERLINK){if(!e.ctrlKey&&!e.metaKey){this._hyperLinkPopupService.showInfoPopup({unitId:this._context.unitId,linkId:t.rangeId,segmentId:e.segmentId,segmentPage:e.segmentPageIndex,startIndex:t.startIndex,endIndex:t.endIndex},{pinned:!0});return}this._commandService.executeCommand(B.id,{unitId:this._context.unitId,linkId:t.rangeId,segmentId:e.segmentId})}}))}};Q=I([F(1,(0,r.Inject)(t.DocEventManagerService)),F(2,r.ICommandService),F(3,(0,r.Inject)(L)),F(4,(0,r.Inject)(i.DocSkeletonManagerService)),F(5,(0,r.Inject)(i.DocSelectionManagerService))],Q);let $=class extends r.Plugin{constructor(e=H,t,n,i){super(),this._config=e,this._injector=t,this._renderManagerSrv=n,this._configService=i;let{menu:a,...o}=(0,r.merge)({},H,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(pe,o)}onStarting(){[[Z],[L],[Y],[U]].forEach(e=>{this._injector.add(e)}),this._injector.get(Z),this._injector.get(Y)}onReady(){this._injector.get(U)}onRendered(){this._initRenderModule()}_initRenderModule(){[[J],[Q]].forEach(e=>{this._renderManagerSrv.registerRenderModule(r.UniverInstanceType.UNIVER_DOC,e)})}};P($,`pluginName`,he),P($,`packageName`,de),P($,`version`,fe),P($,`type`,r.UniverInstanceType.UNIVER_DOC),$=I([(0,r.DependentOn)(i.UniverDocsPlugin,a.UniverRenderEnginePlugin,s.UniverDocsHyperLinkPlugin,t.UniverDocsUIPlugin),F(1,(0,r.Inject)(r.Injector)),F(2,a.IRenderManagerService),F(3,r.IConfigService)],$),e.DocsHyperLinkUIMenuSchema=ue,Object.defineProperty(e,"UniverDocsHyperLinkMobileUIPlugin",{enumerable:!0,get:function(){return X}}),Object.defineProperty(e,"UniverDocsHyperLinkUIPlugin",{enumerable:!0,get:function(){return $}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/docs-hyper-link-ui",
3
- "version": "1.0.0-rc.0",
3
+ "version": "1.0.1",
4
4
  "private": false,
5
5
  "description": "Hyperlink editing UI for Univer Docs.",
6
6
  "author": "DreamNum Co., Ltd. <developer@univer.ai>",
@@ -58,24 +58,24 @@
58
58
  "rxjs": ">=7.0.0"
59
59
  },
60
60
  "dependencies": {
61
- "@univerjs/icons": "1.38.0",
62
- "@univerjs/core": "1.0.0-rc.0",
63
- "@univerjs/engine-render": "1.0.0-rc.0",
64
- "@univerjs/docs": "1.0.0-rc.0",
65
- "@univerjs/docs-ui": "1.0.0-rc.0",
66
- "@univerjs/ui": "1.0.0-rc.0",
67
- "@univerjs/docs-hyper-link": "1.0.0-rc.0",
68
- "@univerjs/design": "1.0.0-rc.0",
69
- "@univerjs/protocol": "1.0.0-rc.0"
61
+ "@univerjs/core": "1.0.1",
62
+ "@univerjs/design": "1.0.1",
63
+ "@univerjs/docs": "1.0.1",
64
+ "@univerjs/docs-hyper-link": "1.0.1",
65
+ "@univerjs/docs-ui": "1.0.1",
66
+ "@univerjs/engine-render": "1.0.1",
67
+ "@univerjs/icons": "1.43.0",
68
+ "@univerjs/protocol": "1.0.1",
69
+ "@univerjs/ui": "1.0.1"
70
70
  },
71
71
  "devDependencies": {
72
- "postcss": "^8.5.26",
72
+ "@univerjs-infra/shared": "1.0.1",
73
+ "postcss": "^8.5.28",
73
74
  "react": "18.3.1",
74
75
  "rxjs": "^7.8.2",
75
76
  "tailwindcss": "3.4.18",
76
77
  "typescript": "^6.0.3",
77
- "vitest": "^5.0.0",
78
- "@univerjs-infra/shared": "1.0.0-rc.0"
78
+ "vitest": "^5.0.0"
79
79
  },
80
80
  "scripts": {
81
81
  "test": "vitest run",