@univerjs/docs-hyper-link-ui 1.0.0-beta.1 → 1.0.0-beta.2
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/cjs/index.js +39 -21
- package/lib/es/index.js +39 -21
- package/lib/index.js +39 -21
- package/lib/types/controllers/render-controllers/hyper-link-event.render-controller.d.ts +1 -0
- package/lib/types/services/hyper-link-popup.service.d.ts +3 -0
- package/lib/umd/index.js +1 -1
- package/package.json +10 -10
package/lib/cjs/index.js
CHANGED
|
@@ -388,7 +388,10 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends _univerjs_
|
|
|
388
388
|
_defineProperty(this, "showingLink$", this._showingLink$.asObservable());
|
|
389
389
|
_defineProperty(this, "_editPopup", null);
|
|
390
390
|
_defineProperty(this, "_infoPopup", null);
|
|
391
|
+
_defineProperty(this, "_infoPopupSuppressed", false);
|
|
392
|
+
_defineProperty(this, "_infoPopupSuppressionTimer", null);
|
|
391
393
|
this.disposeWithMe(() => {
|
|
394
|
+
if (this._infoPopupSuppressionTimer !== null) clearTimeout(this._infoPopupSuppressionTimer);
|
|
392
395
|
this._editingLink$.complete();
|
|
393
396
|
this._showingLink$.complete();
|
|
394
397
|
});
|
|
@@ -424,7 +427,8 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends _univerjs_
|
|
|
424
427
|
if (activeRange) {
|
|
425
428
|
this._editPopup = this._docCanvasPopupManagerService.attachPopupToRange(activeRange, {
|
|
426
429
|
componentKey: DocHyperLinkEdit.componentKey,
|
|
427
|
-
direction: "bottom"
|
|
430
|
+
direction: "bottom",
|
|
431
|
+
offset: [0, 10]
|
|
428
432
|
}, unitId);
|
|
429
433
|
return this._editPopup;
|
|
430
434
|
}
|
|
@@ -437,6 +441,7 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends _univerjs_
|
|
|
437
441
|
}
|
|
438
442
|
showInfoPopup(info) {
|
|
439
443
|
var _this$showing, _this$showing2, _this$showing3, _this$showing4, _this$showing5, _this$showing6;
|
|
444
|
+
if (this._infoPopupSuppressed) return;
|
|
440
445
|
const { linkId, unitId, segmentId, segmentPage, startIndex, endIndex } = info;
|
|
441
446
|
if (((_this$showing = this.showing) === null || _this$showing === void 0 ? void 0 : _this$showing.linkId) === linkId && ((_this$showing2 = this.showing) === null || _this$showing2 === void 0 ? void 0 : _this$showing2.unitId) === unitId && ((_this$showing3 = this.showing) === null || _this$showing3 === void 0 ? void 0 : _this$showing3.segmentId) === segmentId && ((_this$showing4 = this.showing) === null || _this$showing4 === void 0 ? void 0 : _this$showing4.segmentPage) === segmentPage && ((_this$showing5 = this.showing) === null || _this$showing5 === void 0 ? void 0 : _this$showing5.startIndex) === startIndex && ((_this$showing6 = this.showing) === null || _this$showing6 === void 0 ? void 0 : _this$showing6.endIndex) === endIndex) return;
|
|
442
447
|
if (this._infoPopup) this._infoPopup.dispose();
|
|
@@ -459,6 +464,7 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends _univerjs_
|
|
|
459
464
|
componentKey: DocLinkPopup.componentKey,
|
|
460
465
|
direction: "top-center",
|
|
461
466
|
multipleDirection: "top",
|
|
467
|
+
offset: [0, 10],
|
|
462
468
|
onClickOutside: () => {
|
|
463
469
|
this.hideInfoPopup();
|
|
464
470
|
}
|
|
@@ -470,6 +476,15 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends _univerjs_
|
|
|
470
476
|
this._showingLink$.next(null);
|
|
471
477
|
(_this$_infoPopup = this._infoPopup) === null || _this$_infoPopup === void 0 || _this$_infoPopup.dispose();
|
|
472
478
|
}
|
|
479
|
+
hideInfoPopupOnPointerDown() {
|
|
480
|
+
this._infoPopupSuppressed = true;
|
|
481
|
+
if (this._infoPopupSuppressionTimer !== null) clearTimeout(this._infoPopupSuppressionTimer);
|
|
482
|
+
this.hideInfoPopup();
|
|
483
|
+
this._infoPopupSuppressionTimer = setTimeout(() => {
|
|
484
|
+
this._infoPopupSuppressed = false;
|
|
485
|
+
this._infoPopupSuppressionTimer = null;
|
|
486
|
+
}, 0);
|
|
487
|
+
}
|
|
473
488
|
};
|
|
474
489
|
DocHyperLinkPopupService = __decorate([
|
|
475
490
|
__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_docs_ui.DocCanvasPopManagerService)),
|
|
@@ -589,7 +604,7 @@ const menuSchema = {
|
|
|
589
604
|
//#endregion
|
|
590
605
|
//#region package.json
|
|
591
606
|
var name = "@univerjs/docs-hyper-link-ui";
|
|
592
|
-
var version = "1.0.0-beta.
|
|
607
|
+
var version = "1.0.0-beta.2";
|
|
593
608
|
|
|
594
609
|
//#endregion
|
|
595
610
|
//#region src/config/config.ts
|
|
@@ -649,25 +664,21 @@ let DocHyperLinkSelectionController = class DocHyperLinkSelectionController exte
|
|
|
649
664
|
const { unitId, ranges, segmentId } = commandInfo.params;
|
|
650
665
|
const doc = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
|
|
651
666
|
const primary = ranges[0];
|
|
652
|
-
if (primary && doc) {
|
|
667
|
+
if ((primary === null || primary === void 0 ? void 0 : primary.collapsed) && doc) {
|
|
653
668
|
var _doc$getSelfOrHeaderF;
|
|
654
|
-
const { startOffset, endOffset,
|
|
655
|
-
const
|
|
656
|
-
if (
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
});
|
|
668
|
-
return;
|
|
669
|
-
}
|
|
670
|
-
} else if (customRanges === null || customRanges === void 0 ? void 0 : customRanges.find((value) => value.startIndex <= startOffset && value.endIndex >= endOffset - 1)) return;
|
|
669
|
+
const { startOffset, endOffset, segmentPage } = primary;
|
|
670
|
+
const customRange = (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 || (_doc$getSelfOrHeaderF = _doc$getSelfOrHeaderF.getBody()) === null || _doc$getSelfOrHeaderF === void 0 || (_doc$getSelfOrHeaderF = _doc$getSelfOrHeaderF.customRanges) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.find((value) => value.rangeType === _univerjs_core.CustomRangeType.HYPERLINK && value.startIndex < startOffset && value.endIndex > endOffset - 1);
|
|
671
|
+
if (customRange) {
|
|
672
|
+
this._docHyperLinkService.showInfoPopup({
|
|
673
|
+
unitId,
|
|
674
|
+
linkId: customRange.rangeId,
|
|
675
|
+
segmentId,
|
|
676
|
+
segmentPage,
|
|
677
|
+
startIndex: customRange.startIndex,
|
|
678
|
+
endIndex: customRange.endIndex
|
|
679
|
+
});
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
671
682
|
}
|
|
672
683
|
this._docHyperLinkService.hideInfoPopup();
|
|
673
684
|
this._docHyperLinkService.hideEditPopup();
|
|
@@ -696,12 +707,18 @@ let DocHyperLinkEventRenderController = class DocHyperLinkEventRenderController
|
|
|
696
707
|
this._docSkeletonManagerService = _docSkeletonManagerService;
|
|
697
708
|
this._docSelectionManagerService = _docSelectionManagerService;
|
|
698
709
|
if (this._context.unitId === _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY) return;
|
|
710
|
+
this._initPointerDown();
|
|
699
711
|
this._initHover();
|
|
700
712
|
this._initClick();
|
|
701
713
|
}
|
|
702
714
|
_hideInfoPopup() {
|
|
703
715
|
if (this._hyperLinkPopupService.showing) this._commandService.executeCommand(ToggleDocHyperLinkInfoPopupOperation.id);
|
|
704
716
|
}
|
|
717
|
+
_initPointerDown() {
|
|
718
|
+
this.disposeWithMe(this._docEventManagerService.pointerDownCustomRanges$.subscribe((ranges) => {
|
|
719
|
+
if (!ranges.some((range) => range.range.rangeType === _univerjs_core.CustomRangeType.HYPERLINK)) this._hyperLinkPopupService.hideInfoPopupOnPointerDown();
|
|
720
|
+
}));
|
|
721
|
+
}
|
|
705
722
|
_initHover() {
|
|
706
723
|
this.disposeWithMe(this._docEventManagerService.hoverCustomRanges$.subscribe((ranges) => {
|
|
707
724
|
var _activeRanges$;
|
|
@@ -727,7 +744,8 @@ let DocHyperLinkEventRenderController = class DocHyperLinkEventRenderController
|
|
|
727
744
|
_initClick() {
|
|
728
745
|
this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe((range) => {
|
|
729
746
|
const link = range.range;
|
|
730
|
-
if (link
|
|
747
|
+
if (link.rangeType !== _univerjs_core.CustomRangeType.HYPERLINK || !range.ctrlKey && !range.metaKey) return;
|
|
748
|
+
this._commandService.executeCommand(ClickDocHyperLinkOperation.id, {
|
|
731
749
|
unitId: this._context.unitId,
|
|
732
750
|
linkId: link.rangeId,
|
|
733
751
|
segmentId: range.segmentId
|
package/lib/es/index.js
CHANGED
|
@@ -387,7 +387,10 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends Disposable
|
|
|
387
387
|
_defineProperty(this, "showingLink$", this._showingLink$.asObservable());
|
|
388
388
|
_defineProperty(this, "_editPopup", null);
|
|
389
389
|
_defineProperty(this, "_infoPopup", null);
|
|
390
|
+
_defineProperty(this, "_infoPopupSuppressed", false);
|
|
391
|
+
_defineProperty(this, "_infoPopupSuppressionTimer", null);
|
|
390
392
|
this.disposeWithMe(() => {
|
|
393
|
+
if (this._infoPopupSuppressionTimer !== null) clearTimeout(this._infoPopupSuppressionTimer);
|
|
391
394
|
this._editingLink$.complete();
|
|
392
395
|
this._showingLink$.complete();
|
|
393
396
|
});
|
|
@@ -423,7 +426,8 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends Disposable
|
|
|
423
426
|
if (activeRange) {
|
|
424
427
|
this._editPopup = this._docCanvasPopupManagerService.attachPopupToRange(activeRange, {
|
|
425
428
|
componentKey: DocHyperLinkEdit.componentKey,
|
|
426
|
-
direction: "bottom"
|
|
429
|
+
direction: "bottom",
|
|
430
|
+
offset: [0, 10]
|
|
427
431
|
}, unitId);
|
|
428
432
|
return this._editPopup;
|
|
429
433
|
}
|
|
@@ -436,6 +440,7 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends Disposable
|
|
|
436
440
|
}
|
|
437
441
|
showInfoPopup(info) {
|
|
438
442
|
var _this$showing, _this$showing2, _this$showing3, _this$showing4, _this$showing5, _this$showing6;
|
|
443
|
+
if (this._infoPopupSuppressed) return;
|
|
439
444
|
const { linkId, unitId, segmentId, segmentPage, startIndex, endIndex } = info;
|
|
440
445
|
if (((_this$showing = this.showing) === null || _this$showing === void 0 ? void 0 : _this$showing.linkId) === linkId && ((_this$showing2 = this.showing) === null || _this$showing2 === void 0 ? void 0 : _this$showing2.unitId) === unitId && ((_this$showing3 = this.showing) === null || _this$showing3 === void 0 ? void 0 : _this$showing3.segmentId) === segmentId && ((_this$showing4 = this.showing) === null || _this$showing4 === void 0 ? void 0 : _this$showing4.segmentPage) === segmentPage && ((_this$showing5 = this.showing) === null || _this$showing5 === void 0 ? void 0 : _this$showing5.startIndex) === startIndex && ((_this$showing6 = this.showing) === null || _this$showing6 === void 0 ? void 0 : _this$showing6.endIndex) === endIndex) return;
|
|
441
446
|
if (this._infoPopup) this._infoPopup.dispose();
|
|
@@ -458,6 +463,7 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends Disposable
|
|
|
458
463
|
componentKey: DocLinkPopup.componentKey,
|
|
459
464
|
direction: "top-center",
|
|
460
465
|
multipleDirection: "top",
|
|
466
|
+
offset: [0, 10],
|
|
461
467
|
onClickOutside: () => {
|
|
462
468
|
this.hideInfoPopup();
|
|
463
469
|
}
|
|
@@ -469,6 +475,15 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends Disposable
|
|
|
469
475
|
this._showingLink$.next(null);
|
|
470
476
|
(_this$_infoPopup = this._infoPopup) === null || _this$_infoPopup === void 0 || _this$_infoPopup.dispose();
|
|
471
477
|
}
|
|
478
|
+
hideInfoPopupOnPointerDown() {
|
|
479
|
+
this._infoPopupSuppressed = true;
|
|
480
|
+
if (this._infoPopupSuppressionTimer !== null) clearTimeout(this._infoPopupSuppressionTimer);
|
|
481
|
+
this.hideInfoPopup();
|
|
482
|
+
this._infoPopupSuppressionTimer = setTimeout(() => {
|
|
483
|
+
this._infoPopupSuppressed = false;
|
|
484
|
+
this._infoPopupSuppressionTimer = null;
|
|
485
|
+
}, 0);
|
|
486
|
+
}
|
|
472
487
|
};
|
|
473
488
|
DocHyperLinkPopupService = __decorate([
|
|
474
489
|
__decorateParam(0, Inject(DocCanvasPopManagerService)),
|
|
@@ -588,7 +603,7 @@ const menuSchema = {
|
|
|
588
603
|
//#endregion
|
|
589
604
|
//#region package.json
|
|
590
605
|
var name = "@univerjs/docs-hyper-link-ui";
|
|
591
|
-
var version = "1.0.0-beta.
|
|
606
|
+
var version = "1.0.0-beta.2";
|
|
592
607
|
|
|
593
608
|
//#endregion
|
|
594
609
|
//#region src/config/config.ts
|
|
@@ -648,25 +663,21 @@ let DocHyperLinkSelectionController = class DocHyperLinkSelectionController exte
|
|
|
648
663
|
const { unitId, ranges, segmentId } = commandInfo.params;
|
|
649
664
|
const doc = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
650
665
|
const primary = ranges[0];
|
|
651
|
-
if (primary && doc) {
|
|
666
|
+
if ((primary === null || primary === void 0 ? void 0 : primary.collapsed) && doc) {
|
|
652
667
|
var _doc$getSelfOrHeaderF;
|
|
653
|
-
const { startOffset, endOffset,
|
|
654
|
-
const
|
|
655
|
-
if (
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
});
|
|
667
|
-
return;
|
|
668
|
-
}
|
|
669
|
-
} else if (customRanges === null || customRanges === void 0 ? void 0 : customRanges.find((value) => value.startIndex <= startOffset && value.endIndex >= endOffset - 1)) return;
|
|
668
|
+
const { startOffset, endOffset, segmentPage } = primary;
|
|
669
|
+
const customRange = (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 || (_doc$getSelfOrHeaderF = _doc$getSelfOrHeaderF.getBody()) === null || _doc$getSelfOrHeaderF === void 0 || (_doc$getSelfOrHeaderF = _doc$getSelfOrHeaderF.customRanges) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.find((value) => value.rangeType === CustomRangeType.HYPERLINK && value.startIndex < startOffset && value.endIndex > endOffset - 1);
|
|
670
|
+
if (customRange) {
|
|
671
|
+
this._docHyperLinkService.showInfoPopup({
|
|
672
|
+
unitId,
|
|
673
|
+
linkId: customRange.rangeId,
|
|
674
|
+
segmentId,
|
|
675
|
+
segmentPage,
|
|
676
|
+
startIndex: customRange.startIndex,
|
|
677
|
+
endIndex: customRange.endIndex
|
|
678
|
+
});
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
670
681
|
}
|
|
671
682
|
this._docHyperLinkService.hideInfoPopup();
|
|
672
683
|
this._docHyperLinkService.hideEditPopup();
|
|
@@ -695,12 +706,18 @@ let DocHyperLinkEventRenderController = class DocHyperLinkEventRenderController
|
|
|
695
706
|
this._docSkeletonManagerService = _docSkeletonManagerService;
|
|
696
707
|
this._docSelectionManagerService = _docSelectionManagerService;
|
|
697
708
|
if (this._context.unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY) return;
|
|
709
|
+
this._initPointerDown();
|
|
698
710
|
this._initHover();
|
|
699
711
|
this._initClick();
|
|
700
712
|
}
|
|
701
713
|
_hideInfoPopup() {
|
|
702
714
|
if (this._hyperLinkPopupService.showing) this._commandService.executeCommand(ToggleDocHyperLinkInfoPopupOperation.id);
|
|
703
715
|
}
|
|
716
|
+
_initPointerDown() {
|
|
717
|
+
this.disposeWithMe(this._docEventManagerService.pointerDownCustomRanges$.subscribe((ranges) => {
|
|
718
|
+
if (!ranges.some((range) => range.range.rangeType === CustomRangeType.HYPERLINK)) this._hyperLinkPopupService.hideInfoPopupOnPointerDown();
|
|
719
|
+
}));
|
|
720
|
+
}
|
|
704
721
|
_initHover() {
|
|
705
722
|
this.disposeWithMe(this._docEventManagerService.hoverCustomRanges$.subscribe((ranges) => {
|
|
706
723
|
var _activeRanges$;
|
|
@@ -726,7 +743,8 @@ let DocHyperLinkEventRenderController = class DocHyperLinkEventRenderController
|
|
|
726
743
|
_initClick() {
|
|
727
744
|
this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe((range) => {
|
|
728
745
|
const link = range.range;
|
|
729
|
-
if (link
|
|
746
|
+
if (link.rangeType !== CustomRangeType.HYPERLINK || !range.ctrlKey && !range.metaKey) return;
|
|
747
|
+
this._commandService.executeCommand(ClickDocHyperLinkOperation.id, {
|
|
730
748
|
unitId: this._context.unitId,
|
|
731
749
|
linkId: link.rangeId,
|
|
732
750
|
segmentId: range.segmentId
|
package/lib/index.js
CHANGED
|
@@ -387,7 +387,10 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends Disposable
|
|
|
387
387
|
_defineProperty(this, "showingLink$", this._showingLink$.asObservable());
|
|
388
388
|
_defineProperty(this, "_editPopup", null);
|
|
389
389
|
_defineProperty(this, "_infoPopup", null);
|
|
390
|
+
_defineProperty(this, "_infoPopupSuppressed", false);
|
|
391
|
+
_defineProperty(this, "_infoPopupSuppressionTimer", null);
|
|
390
392
|
this.disposeWithMe(() => {
|
|
393
|
+
if (this._infoPopupSuppressionTimer !== null) clearTimeout(this._infoPopupSuppressionTimer);
|
|
391
394
|
this._editingLink$.complete();
|
|
392
395
|
this._showingLink$.complete();
|
|
393
396
|
});
|
|
@@ -423,7 +426,8 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends Disposable
|
|
|
423
426
|
if (activeRange) {
|
|
424
427
|
this._editPopup = this._docCanvasPopupManagerService.attachPopupToRange(activeRange, {
|
|
425
428
|
componentKey: DocHyperLinkEdit.componentKey,
|
|
426
|
-
direction: "bottom"
|
|
429
|
+
direction: "bottom",
|
|
430
|
+
offset: [0, 10]
|
|
427
431
|
}, unitId);
|
|
428
432
|
return this._editPopup;
|
|
429
433
|
}
|
|
@@ -436,6 +440,7 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends Disposable
|
|
|
436
440
|
}
|
|
437
441
|
showInfoPopup(info) {
|
|
438
442
|
var _this$showing, _this$showing2, _this$showing3, _this$showing4, _this$showing5, _this$showing6;
|
|
443
|
+
if (this._infoPopupSuppressed) return;
|
|
439
444
|
const { linkId, unitId, segmentId, segmentPage, startIndex, endIndex } = info;
|
|
440
445
|
if (((_this$showing = this.showing) === null || _this$showing === void 0 ? void 0 : _this$showing.linkId) === linkId && ((_this$showing2 = this.showing) === null || _this$showing2 === void 0 ? void 0 : _this$showing2.unitId) === unitId && ((_this$showing3 = this.showing) === null || _this$showing3 === void 0 ? void 0 : _this$showing3.segmentId) === segmentId && ((_this$showing4 = this.showing) === null || _this$showing4 === void 0 ? void 0 : _this$showing4.segmentPage) === segmentPage && ((_this$showing5 = this.showing) === null || _this$showing5 === void 0 ? void 0 : _this$showing5.startIndex) === startIndex && ((_this$showing6 = this.showing) === null || _this$showing6 === void 0 ? void 0 : _this$showing6.endIndex) === endIndex) return;
|
|
441
446
|
if (this._infoPopup) this._infoPopup.dispose();
|
|
@@ -458,6 +463,7 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends Disposable
|
|
|
458
463
|
componentKey: DocLinkPopup.componentKey,
|
|
459
464
|
direction: "top-center",
|
|
460
465
|
multipleDirection: "top",
|
|
466
|
+
offset: [0, 10],
|
|
461
467
|
onClickOutside: () => {
|
|
462
468
|
this.hideInfoPopup();
|
|
463
469
|
}
|
|
@@ -469,6 +475,15 @@ let DocHyperLinkPopupService = class DocHyperLinkPopupService extends Disposable
|
|
|
469
475
|
this._showingLink$.next(null);
|
|
470
476
|
(_this$_infoPopup = this._infoPopup) === null || _this$_infoPopup === void 0 || _this$_infoPopup.dispose();
|
|
471
477
|
}
|
|
478
|
+
hideInfoPopupOnPointerDown() {
|
|
479
|
+
this._infoPopupSuppressed = true;
|
|
480
|
+
if (this._infoPopupSuppressionTimer !== null) clearTimeout(this._infoPopupSuppressionTimer);
|
|
481
|
+
this.hideInfoPopup();
|
|
482
|
+
this._infoPopupSuppressionTimer = setTimeout(() => {
|
|
483
|
+
this._infoPopupSuppressed = false;
|
|
484
|
+
this._infoPopupSuppressionTimer = null;
|
|
485
|
+
}, 0);
|
|
486
|
+
}
|
|
472
487
|
};
|
|
473
488
|
DocHyperLinkPopupService = __decorate([
|
|
474
489
|
__decorateParam(0, Inject(DocCanvasPopManagerService)),
|
|
@@ -588,7 +603,7 @@ const menuSchema = {
|
|
|
588
603
|
//#endregion
|
|
589
604
|
//#region package.json
|
|
590
605
|
var name = "@univerjs/docs-hyper-link-ui";
|
|
591
|
-
var version = "1.0.0-beta.
|
|
606
|
+
var version = "1.0.0-beta.2";
|
|
592
607
|
|
|
593
608
|
//#endregion
|
|
594
609
|
//#region src/config/config.ts
|
|
@@ -648,25 +663,21 @@ let DocHyperLinkSelectionController = class DocHyperLinkSelectionController exte
|
|
|
648
663
|
const { unitId, ranges, segmentId } = commandInfo.params;
|
|
649
664
|
const doc = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
650
665
|
const primary = ranges[0];
|
|
651
|
-
if (primary && doc) {
|
|
666
|
+
if ((primary === null || primary === void 0 ? void 0 : primary.collapsed) && doc) {
|
|
652
667
|
var _doc$getSelfOrHeaderF;
|
|
653
|
-
const { startOffset, endOffset,
|
|
654
|
-
const
|
|
655
|
-
if (
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
});
|
|
667
|
-
return;
|
|
668
|
-
}
|
|
669
|
-
} else if (customRanges === null || customRanges === void 0 ? void 0 : customRanges.find((value) => value.startIndex <= startOffset && value.endIndex >= endOffset - 1)) return;
|
|
668
|
+
const { startOffset, endOffset, segmentPage } = primary;
|
|
669
|
+
const customRange = (_doc$getSelfOrHeaderF = doc.getSelfOrHeaderFooterModel(segmentId)) === null || _doc$getSelfOrHeaderF === void 0 || (_doc$getSelfOrHeaderF = _doc$getSelfOrHeaderF.getBody()) === null || _doc$getSelfOrHeaderF === void 0 || (_doc$getSelfOrHeaderF = _doc$getSelfOrHeaderF.customRanges) === null || _doc$getSelfOrHeaderF === void 0 ? void 0 : _doc$getSelfOrHeaderF.find((value) => value.rangeType === CustomRangeType.HYPERLINK && value.startIndex < startOffset && value.endIndex > endOffset - 1);
|
|
670
|
+
if (customRange) {
|
|
671
|
+
this._docHyperLinkService.showInfoPopup({
|
|
672
|
+
unitId,
|
|
673
|
+
linkId: customRange.rangeId,
|
|
674
|
+
segmentId,
|
|
675
|
+
segmentPage,
|
|
676
|
+
startIndex: customRange.startIndex,
|
|
677
|
+
endIndex: customRange.endIndex
|
|
678
|
+
});
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
670
681
|
}
|
|
671
682
|
this._docHyperLinkService.hideInfoPopup();
|
|
672
683
|
this._docHyperLinkService.hideEditPopup();
|
|
@@ -695,12 +706,18 @@ let DocHyperLinkEventRenderController = class DocHyperLinkEventRenderController
|
|
|
695
706
|
this._docSkeletonManagerService = _docSkeletonManagerService;
|
|
696
707
|
this._docSelectionManagerService = _docSelectionManagerService;
|
|
697
708
|
if (this._context.unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY) return;
|
|
709
|
+
this._initPointerDown();
|
|
698
710
|
this._initHover();
|
|
699
711
|
this._initClick();
|
|
700
712
|
}
|
|
701
713
|
_hideInfoPopup() {
|
|
702
714
|
if (this._hyperLinkPopupService.showing) this._commandService.executeCommand(ToggleDocHyperLinkInfoPopupOperation.id);
|
|
703
715
|
}
|
|
716
|
+
_initPointerDown() {
|
|
717
|
+
this.disposeWithMe(this._docEventManagerService.pointerDownCustomRanges$.subscribe((ranges) => {
|
|
718
|
+
if (!ranges.some((range) => range.range.rangeType === CustomRangeType.HYPERLINK)) this._hyperLinkPopupService.hideInfoPopupOnPointerDown();
|
|
719
|
+
}));
|
|
720
|
+
}
|
|
704
721
|
_initHover() {
|
|
705
722
|
this.disposeWithMe(this._docEventManagerService.hoverCustomRanges$.subscribe((ranges) => {
|
|
706
723
|
var _activeRanges$;
|
|
@@ -726,7 +743,8 @@ let DocHyperLinkEventRenderController = class DocHyperLinkEventRenderController
|
|
|
726
743
|
_initClick() {
|
|
727
744
|
this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe((range) => {
|
|
728
745
|
const link = range.range;
|
|
729
|
-
if (link
|
|
746
|
+
if (link.rangeType !== CustomRangeType.HYPERLINK || !range.ctrlKey && !range.metaKey) return;
|
|
747
|
+
this._commandService.executeCommand(ClickDocHyperLinkOperation.id, {
|
|
730
748
|
unitId: this._context.unitId,
|
|
731
749
|
linkId: link.rangeId,
|
|
732
750
|
segmentId: range.segmentId
|
|
@@ -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 _initPointerDown;
|
|
32
33
|
private _initHover;
|
|
33
34
|
private _initClick;
|
|
34
35
|
}
|
|
@@ -35,6 +35,8 @@ export declare class DocHyperLinkPopupService extends Disposable {
|
|
|
35
35
|
readonly showingLink$: import("rxjs").Observable<Nullable<ILinkInfo>>;
|
|
36
36
|
private _editPopup;
|
|
37
37
|
private _infoPopup;
|
|
38
|
+
private _infoPopupSuppressed;
|
|
39
|
+
private _infoPopupSuppressionTimer;
|
|
38
40
|
constructor(_docCanvasPopupManagerService: DocCanvasPopManagerService, _textSelectionManagerService: DocSelectionManagerService, _univerInstanceService: IUniverInstanceService);
|
|
39
41
|
get editing(): Nullable<ILinkInfo>;
|
|
40
42
|
get showing(): Nullable<ILinkInfo>;
|
|
@@ -42,4 +44,5 @@ export declare class DocHyperLinkPopupService extends Disposable {
|
|
|
42
44
|
hideEditPopup(): void;
|
|
43
45
|
showInfoPopup(info: ILinkInfo): Nullable<IDisposable>;
|
|
44
46
|
hideInfoPopup(): void;
|
|
47
|
+
hideInfoPopupOnPointerDown(): void;
|
|
45
48
|
}
|
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("rxjs"),require("@univerjs/design"),require("react"),require("react/jsx-runtime"),require("@univerjs/docs-hyper-link"),require("@univerjs/engine-render")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/docs-ui`,`@univerjs/ui`,`@univerjs/core`,`@univerjs/docs`,`rxjs`,`@univerjs/design`,`react`,`react/jsx-runtime`,`@univerjs/docs-hyper-link`,`@univerjs/engine-render`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsHyperLinkUi={},e.UniverDocsUi,e.UniverUi,e.UniverCore,e.UniverDocs,e.rxjs,e.UniverDesign,e.React,e.React,e.UniverDocsHyperLink,e.UniverEngineRender))})(this,function(e,t,n,r,i,a,o,s,c,l,u){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let d={type:r.CommandType.COMMAND,id:`docs.command.add-hyper-link`,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}},f={id:`docs.command.update-hyper-link`,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 p(e){return e.trim().length===0}function m(e){return/^[a-zA-Z]+:\/\//.test(e)}function h(e){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(e)}function g(e){return m(e)?e:h(e)?`mailto://${e}`:`https://${e}`}let _=()=>{let e=(0,n.useDependency)(L),t=(0,n.useDependency)(r.LocaleService),a=(0,n.useObservable)(e.editingLink$),l=(0,n.useDependency)(r.ICommandService),u=(0,n.useDependency)(r.IUniverInstanceService),m=(0,n.useDependency)(i.DocSelectionManagerService),[h,_]=(0,s.useState)(``),[v,y]=(0,s.useState)(``),[b,x]=(0,s.useState)(!1),S=r.Tools.isLegalUrl(h),C=a?u.getUnit(a.unitId,r.UniverInstanceType.UNIVER_DOC):u.getCurrentUnitOfType(r.UniverInstanceType.UNIVER_DOC);(0,s.useEffect)(()=>{var e,t;let n=m.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;_(((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 d;_((u==null||(d=u.properties)==null?void 0:d.url)??``)}},[C,a,m,u]);let w=()=>{e.hideEditPopup()},T=()=>{if(x(!0),!S||!C)return;let t=g(h);if(!a)l.executeCommand(d.id,{unitId:C.getUnitId(),payload:t});else{if(p(v))return;l.executeCommand(f.id,{unitId:C.getUnitId(),payload:t,linkId:a.linkId,label:v,segmentId:a.segmentId})}e.hideEditPopup()};if(C)return(0,c.jsxs)(`div`,{className:(0,o.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`,o.borderClassName),children:[(0,c.jsxs)(`div`,{children:[a?(0,c.jsx)(o.FormLayout,{label:t.t(`docs-hyper-link-ui.edit.label`),error:b&&p(v)?t.t(`docs-hyper-link-ui.edit.labelError`):``,children:(0,c.jsx)(o.Input,{value:v,onChange:y,autoFocus:!0,onKeyDown:e=>{e.keyCode===n.KeyCode.ENTER&&T()}})}):null,(0,c.jsx)(o.FormLayout,{label:t.t(`docs-hyper-link-ui.edit.address`),error:b&&!S?t.t(`docs-hyper-link-ui.edit.addressError`):``,children:(0,c.jsx)(o.Input,{value:h,onChange:_,autoFocus:!0,onKeyDown:e=>{e.keyCode===n.KeyCode.ENTER&&T()}})})]}),(0,c.jsxs)(`div`,{className:`univer-flex univer-justify-end univer-gap-3`,children:[(0,c.jsx)(o.Button,{onClick:w,children:t.t(`docs-hyper-link-ui.edit.cancel`)}),(0,c.jsx)(o.Button,{variant:`primary`,disabled:p(h),onClick:T,children:t.t(`docs-hyper-link-ui.edit.confirm`)})]})]})};_.componentKey=`docs-hyper-link-edit`;function v({ref:e,...t}){let{icon:n,id:r,className:i,extend:a,...o}=t,c=`univerjs-icon univerjs-icon-${r} ${i||``}`.trim(),l=(0,s.useRef)(`_${S()}`);return y(n,`${r}`,{defIds:n.defIds,idSuffix:l.current},{ref:e,className:c,...o},a)}function y(e,t,n,r,i){return(0,s.createElement)(e.tag,{key:t,...b(e,n,i),...r},(x(e,n).children||[]).map((r,a)=>y(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function b(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 x(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 S(){return Math.random().toString(36).substring(2,8)}v.displayName=`UniverIcon`;let C={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`}}]},w=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(v,Object.assign({},e,{id:`copy-icon`,ref:t,icon:C}))});w.displayName=`CopyIcon`;let T={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:`M9.8816 1.97978C11.0177 0.843607 12.862 0.884962 14.0004 2.02342C15.1389 3.16188 15.1803 5.00612 14.0441 6.14228L11.399 8.78737C11.1608 9.02559 10.7746 9.02559 10.5363 8.78737C10.2981 8.54915 10.2981 8.16292 10.5363 7.9247L13.1814 5.2796C13.8195 4.64155 13.8217 3.57006 13.1378 2.8861C12.4538 2.20211 11.3823 2.20438 10.7443 2.84245L7.6976 5.88911L7.69317 5.89349C7.05959 6.53211 7.05894 7.60014 7.74132 8.28252C7.97954 8.52074 7.97954 8.90697 7.74132 9.14519C7.5031 9.38341 7.11687 9.38341 6.87865 9.14519C5.74016 8.00671 5.69884 6.16251 6.83497 5.02633L6.84021 5.02116L9.8816 1.97978Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M4.61426 7.2364C4.85248 6.99818 5.23871 6.99818 5.47693 7.2364C5.71515 7.47462 5.71515 7.86085 5.47693 8.09907L2.83183 10.7442C2.19375 11.3823 2.1915 12.4537 2.87547 13.1377C3.55945 13.8217 4.6309 13.8194 5.26899 13.1813L8.31566 10.1347C8.32262 10.1277 8.32971 10.121 8.33691 10.1144C8.34408 10.1064 8.3515 10.0986 8.35916 10.091C8.99721 9.45291 8.99949 8.38145 8.3155 7.69746C8.07728 7.45924 8.07728 7.07301 8.3155 6.83479C8.55372 6.59657 8.93995 6.59657 9.17817 6.83479C10.3166 7.97327 10.358 9.81748 9.22183 10.9536C9.21487 10.9606 9.20779 10.9673 9.20058 10.9739C9.19341 10.9819 9.18599 10.9897 9.17833 10.9973L6.13166 14.044C4.99548 15.1802 3.15127 15.1389 2.01279 14.0004C0.874362 12.8619 0.83297 11.0177 1.96916 9.8815L4.61426 7.2364Z`}}]},E=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(v,Object.assign({},e,{id:`link-icon`,ref:t,icon:T}))});E.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`}}]},D=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(v,Object.assign({},e,{id:`unlink-icon`,ref:t,icon:ee}))});D.displayName=`UnlinkIcon`;let O={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`}}]},k=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(v,Object.assign({},e,{id:`write-icon`,ref:t,icon:O}))});k.displayName=`WriteIcon`;let A={type:r.CommandType.COMMAND,id:`docs.command.delete-hyper-link`,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}},j=()=>{var e,t,i;let a=(0,n.useDependency)(L),s=(0,n.useDependency)(r.ICommandService),l=(0,n.useDependency)(n.IMessageService),u=(0,n.useDependency)(r.LocaleService),d=(0,n.useObservable)(a.showingLink$),f=(0,n.useDependency)(r.IUniverInstanceService);if(!d)return null;let{unitId:p,linkId:m,segmentId:h,startIndex:g,endIndex:_}=d,v=f.getUnit(p,r.UniverInstanceType.UNIVER_DOC),y=v==null||(e=v.getSelfOrHeaderFooterModel(h))==null?void 0:e.getBody(),b=y==null||(t=y.customRanges)==null?void 0:t.find(e=>e.rangeId===m&&e.rangeType===r.CustomRangeType.HYPERLINK&&e.startIndex===g&&e.endIndex===_);if(!b)return null;let x=(i=b.properties)==null?void 0:i.url;return(0,c.jsxs)(`div`,{className:(0,o.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`,o.borderClassName),onClick:()=>{a.hideInfoPopup()},children:[(0,c.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(x,void 0,`noopener noreferrer`),children:[(0,c.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,c.jsx)(E,{})}),(0,c.jsx)(o.Tooltip,{showIfEllipsis:!0,title:x,children:(0,c.jsx)(`span`,{className:`univer-flex-1 univer-truncate`,children:x})})]}),(0,c.jsxs)(`div`,{className:`univer-flex univer-h-6 univer-flex-[0_0_auto] univer-items-center univer-justify-center`,children:[(0,c.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:()=>{navigator.clipboard.writeText(x),l.show({content:u.t(`docs-hyper-link-ui.info.coped`),type:o.MessageType.Info})},children:(0,c.jsx)(o.Tooltip,{placement:`bottom`,title:u.t(`docs-hyper-link-ui.info.copy`),children:(0,c.jsx)(w,{})})}),(0,c.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:()=>{s.executeCommand(z.id,{link:d})},children:(0,c.jsx)(o.Tooltip,{placement:`bottom`,title:u.t(`docs-hyper-link-ui.info.edit`),children:(0,c.jsx)(k,{})})}),(0,c.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:()=>{s.executeCommand(A.id,{unitId:p,linkId:b.rangeId,segmentId:h})},children:(0,c.jsx)(o.Tooltip,{placement:`bottom`,title:u.t(`docs-hyper-link-ui.info.cancel`),children:(0,c.jsx)(D,{})})})]})]})};j.componentKey=`univer.doc.link-info-popup`;function M(e){"@babel/helpers - typeof";return M=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},M(e)}function te(e,t){if(M(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(M(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function N(e){var t=te(e,`string`);return M(t)==`symbol`?t:t+``}function P(e,t,n){return(t=N(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}let L=class extends r.Disposable{constructor(e,t,n){super(),this._docCanvasPopupManagerService=e,this._textSelectionManagerService=t,this._univerInstanceService=n,P(this,`_editingLink$`,new a.BehaviorSubject(null)),P(this,`_showingLink$`,new a.BehaviorSubject(null)),P(this,`editingLink$`,this._editingLink$.asObservable()),P(this,`showingLink$`,this._showingLink$.asObservable()),P(this,`_editPopup`,null),P(this,`_infoPopup`,null),this.disposeWithMe(()=>{this._editingLink$.complete(),this._showingLink$.complete()})}get editing(){return this._editingLink$.value}get showing(){return this._showingLink$.value}showEditPopup(e,t){this._editPopup&&this._editPopup.dispose(),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:_.componentKey,direction:`bottom`},e),this._editPopup):null}hideEditPopup(){var e;this._editingLink$.next(null),(e=this._editPopup)==null||e.dispose()}showInfoPopup(e){var t,n,i,a,o,s;let{linkId:c,unitId:l,segmentId:u,segmentPage:d,startIndex:f,endIndex:p}=e;if((((t=this.showing)==null?void 0:t.linkId)!==c||((n=this.showing)==null?void 0:n.unitId)!==l||((i=this.showing)==null?void 0:i.segmentId)!==u||((a=this.showing)==null?void 0:a.segmentPage)!==d||((o=this.showing)==null?void 0:o.startIndex)!==f||((s=this.showing)==null?void 0:s.endIndex)!==p)&&(this._infoPopup&&this._infoPopup.dispose(),this._univerInstanceService.getUnit(l,r.UniverInstanceType.UNIVER_DOC)))return this._showingLink$.next({unitId:l,linkId:c,segmentId:u,segmentPage:d,startIndex:f,endIndex:p}),this._infoPopup=this._docCanvasPopupManagerService.attachPopupToRange({collapsed:!1,startOffset:f,endOffset:p+1,segmentId:u,segmentPage:d},{componentKey:j.componentKey,direction:`top-center`,multipleDirection:`top`,onClickOutside:()=>{this.hideInfoPopup()}},l),this._infoPopup}hideInfoPopup(){var e;this._showingLink$.next(null),(e=this._infoPopup)==null||e.dispose()}};L=I([F(0,(0,r.Inject)(t.DocCanvasPopManagerService)),F(1,(0,r.Inject)(i.DocSelectionManagerService)),F(2,r.IUniverInstanceService)],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),!0):!1}},B={type:r.CommandType.OPERATION,id:`doc.operation.toggle-hyper-link-info-popup`,handler(e,t){let n=e.get(L);return t?(n.showInfoPopup(t),!0):(n.hideInfoPopup(),!0)}},V={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 H(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 a.Observable(function(t){let n=e.get(i.DocSelectionManagerService).textSelection$.pipe((0,a.debounceTime)(16)).subscribe(()=>{t.next(R(e))});return()=>{n.unsubscribe()}})}}let U={id:z.id,binding:n.MetaKeys.CTRL_COMMAND|n.KeyCode.K,description:`docs-hyper-link-ui.menu.tooltip`,preconditions:t.whenDocAndEditorFocused},W={[n.RibbonInsertGroup.MEDIA]:{[z.id]:{order:1,menuItemFactory:H}},[t.FLOAT_TOOLBAR_MENU_POSITION]:{[z.id]:{order:20,menuItemFactory:H}},[n.ContextMenuPosition.MAIN_AREA]:{[n.ContextMenuGroup.DATA]:{[z.id]:{order:0,menuItemFactory:H}}},[n.ContextMenuPosition.PARAGRAPH]:{[n.ContextMenuGroup.LAYOUT]:{[t.INSERT_BELLOW_MENU_ID]:{[z.id]:{order:6,menuItemFactory:H}}},[t.EMPTY_PARAGRAPH_MENU_ID]:{[n.ContextMenuGroup.LAYOUT]:{[z.id]:{order:6,menuItemFactory:H}}}}};var G=`@univerjs/docs-hyper-link-ui`,K=`1.0.0-beta.1`;let q={},J=class extends r.Disposable{constructor(e,t){super(),this._componentManager=e,this._iconManager=t,this._registerComponents(),this._registerIcons()}_registerComponents(){[[_.componentKey,_],[j.componentKey,j]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_registerIcons(){this.disposeWithMe(this._iconManager.register({LinkIcon:E}))}};J=I([F(0,(0,r.Inject)(n.ComponentManager)),F(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&&o){var t;let{startOffset:e,endOffset:r,collapsed:i,segmentPage:c}=s,l=(t=o.getSelfOrHeaderFooterModel(a))==null||(t=t.getBody())==null?void 0:t.customRanges;if(i){let t=(l==null?void 0:l.findIndex(t=>t.startIndex<e&&t.endIndex>r-1))??-1;if(t>-1){let e=l[t];this._docHyperLinkService.showInfoPopup({unitId:n,linkId:e.rangeId,segmentId:a,segmentPage:c,startIndex:e.startIndex,endIndex:e.endIndex});return}}else if(l!=null&&l.find(t=>t.startIndex<=e&&t.endIndex>=r-1))return}this._docHyperLinkService.hideInfoPopup(),this._docHyperLinkService.hideEditPopup()}}))}};Y=I([F(0,r.ICommandService),F(1,r.IUniverInstanceService),F(2,(0,r.Inject)(L))],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._initHover(),this._initClick())}_hideInfoPopup(){this._hyperLinkPopupService.showing&&this._commandService.executeCommand(B.id)}_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(B.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;t&&this._commandService.executeCommand(V.id,{unitId:this._context.unitId,linkId:t.rangeId,segmentId:e.segmentId})}))}};X=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))],X);let Z=class extends r.Disposable{constructor(e,t,n,r){super(),this._context=e,this._docInterceptorService=t,this._hyperLinkService=n,this._docRenderController=r,this._init(),this._initReRender()}_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})}})}_initReRender(){this.disposeWithMe(this._hyperLinkService.showingLink$.pipe((0,a.distinctUntilChanged)((e,t)=>(e==null?void 0:e.linkId)===(t==null?void 0:t.linkId)&&(e==null?void 0:e.unitId)===(t==null?void 0:t.unitId)&&(e==null?void 0:e.startIndex)===(t==null?void 0:t.startIndex)),(0,a.pairwise)()).subscribe(([e,t])=>{t?t.unitId===this._context.unitId&&this._docRenderController.reRender(t.unitId):e&&e.unitId===this._context.unitId&&this._docRenderController.reRender(e.unitId)}))}};Z=I([F(1,(0,r.Inject)(i.DocInterceptorService)),F(2,(0,r.Inject)(L)),F(3,(0,r.Inject)(t.DocRenderController))],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(){[d,f,A,z,B,V].forEach(e=>{this._commandService.registerCommand(e)})}_initShortcut(){[U].forEach(e=>{this._shortcutService.registerShortcut(e)})}_initMenus(){this._menuManagerService.appendRootMenu({[t.FLOAT_TOOLBAR_MENU_POSITION]:{}}),this._menuManagerService.mergeMenu(W)}};Q=I([F(0,r.ICommandService),F(1,n.IMenuManagerService),F(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),[[L],[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)})}};P($,`pluginName`,`DOC_HYPER_LINK_UI_PLUGIN`),P($,`packageName`,G),P($,`version`,K),P($,`type`,r.UniverInstanceType.UNIVER_DOC),$=I([(0,r.DependentOn)(i.UniverDocsPlugin,u.UniverRenderEnginePlugin,l.UniverDocsHyperLinkPlugin,t.UniverDocsUIPlugin),F(1,(0,r.Inject)(r.Injector)),F(2,u.IRenderManagerService),F(3,r.IConfigService)],$),e.DocsHyperLinkUIMenuSchema=W,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("rxjs"),require("@univerjs/design"),require("react"),require("react/jsx-runtime"),require("@univerjs/docs-hyper-link"),require("@univerjs/engine-render")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/docs-ui`,`@univerjs/ui`,`@univerjs/core`,`@univerjs/docs`,`rxjs`,`@univerjs/design`,`react`,`react/jsx-runtime`,`@univerjs/docs-hyper-link`,`@univerjs/engine-render`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDocsHyperLinkUi={},e.UniverDocsUi,e.UniverUi,e.UniverCore,e.UniverDocs,e.rxjs,e.UniverDesign,e.React,e.React,e.UniverDocsHyperLink,e.UniverEngineRender))})(this,function(e,t,n,r,i,a,o,s,c,l,u){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let d={type:r.CommandType.COMMAND,id:`docs.command.add-hyper-link`,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}},f={id:`docs.command.update-hyper-link`,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 p(e){return e.trim().length===0}function m(e){return/^[a-zA-Z]+:\/\//.test(e)}function h(e){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(e)}function g(e){return m(e)?e:h(e)?`mailto://${e}`:`https://${e}`}let _=()=>{let e=(0,n.useDependency)(B),t=(0,n.useDependency)(r.LocaleService),a=(0,n.useObservable)(e.editingLink$),l=(0,n.useDependency)(r.ICommandService),u=(0,n.useDependency)(r.IUniverInstanceService),m=(0,n.useDependency)(i.DocSelectionManagerService),[h,_]=(0,s.useState)(``),[v,y]=(0,s.useState)(``),[b,x]=(0,s.useState)(!1),S=r.Tools.isLegalUrl(h),C=a?u.getUnit(a.unitId,r.UniverInstanceType.UNIVER_DOC):u.getCurrentUnitOfType(r.UniverInstanceType.UNIVER_DOC);(0,s.useEffect)(()=>{var e,t;let n=m.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;_(((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 d;_((u==null||(d=u.properties)==null?void 0:d.url)??``)}},[C,a,m,u]);let w=()=>{e.hideEditPopup()},T=()=>{if(x(!0),!S||!C)return;let t=g(h);if(!a)l.executeCommand(d.id,{unitId:C.getUnitId(),payload:t});else{if(p(v))return;l.executeCommand(f.id,{unitId:C.getUnitId(),payload:t,linkId:a.linkId,label:v,segmentId:a.segmentId})}e.hideEditPopup()};if(C)return(0,c.jsxs)(`div`,{className:(0,o.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`,o.borderClassName),children:[(0,c.jsxs)(`div`,{children:[a?(0,c.jsx)(o.FormLayout,{label:t.t(`docs-hyper-link-ui.edit.label`),error:b&&p(v)?t.t(`docs-hyper-link-ui.edit.labelError`):``,children:(0,c.jsx)(o.Input,{value:v,onChange:y,autoFocus:!0,onKeyDown:e=>{e.keyCode===n.KeyCode.ENTER&&T()}})}):null,(0,c.jsx)(o.FormLayout,{label:t.t(`docs-hyper-link-ui.edit.address`),error:b&&!S?t.t(`docs-hyper-link-ui.edit.addressError`):``,children:(0,c.jsx)(o.Input,{value:h,onChange:_,autoFocus:!0,onKeyDown:e=>{e.keyCode===n.KeyCode.ENTER&&T()}})})]}),(0,c.jsxs)(`div`,{className:`univer-flex univer-justify-end univer-gap-3`,children:[(0,c.jsx)(o.Button,{onClick:w,children:t.t(`docs-hyper-link-ui.edit.cancel`)}),(0,c.jsx)(o.Button,{variant:`primary`,disabled:p(h),onClick:T,children:t.t(`docs-hyper-link-ui.edit.confirm`)})]})]})};_.componentKey=`docs-hyper-link-edit`;function v({ref:e,...t}){let{preserveStrokeWidth:n,icon:r,id:i,className:a,extend:o,...c}=t,l=`univerjs-icon univerjs-icon-${i} ${a||``}`.trim(),u=`_${(0,s.useId)()}`,d=(0,s.useRef)(null);return(0,s.useImperativeHandle)(e,()=>d.current),(0,s.useLayoutEffect)(()=>{if(!(!n||!d.current||d.current.localName!==r.tag))return S(d.current)},[n,r]),y(r,`${i}`,{defIds:r.defIds,idSuffix:u},{ref:d,className:l,...c},o)}function y(e,t,n,r,i){return(0,s.createElement)(e.tag,{key:t,...b(e,n,i),...r},(x(e,n).children||[]).map((r,a)=>y(r,`${t}-${e.tag}-${a}`,n,void 0,i)))}function b(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 x(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 S(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:C(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&&(w(e.element.style,`stroke-width`,e.appliedStrokeWidth,e.strokeWidth.priority,e.strokeWidth),!e.hadStyleAttribute&&e.element.style.length===0&&e.element.removeAttribute(`style`))})}}function C(e,t){return{priority:e.getPropertyPriority(t),value:e.getPropertyValue(t)}}function w(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))}v.displayName=`UniverIcon`;let T={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`}}]},E=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(v,Object.assign({},e,{id:`copy-icon`,ref:t,icon:T}))});E.displayName=`CopyIcon`;let D={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}}]},O=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(v,Object.assign({},e,{id:`link-icon`,ref:t,icon:D}))});O.displayName=`LinkIcon`;let k={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,s.forwardRef)(function(e,t){return(0,s.createElement)(v,Object.assign({},e,{id:`unlink-icon`,ref:t,icon:k}))});A.displayName=`UnlinkIcon`;let j={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`}}]},M=(0,s.forwardRef)(function(e,t){return(0,s.createElement)(v,Object.assign({},e,{id:`write-icon`,ref:t,icon:j}))});M.displayName=`WriteIcon`;let N={type:r.CommandType.COMMAND,id:`docs.command.delete-hyper-link`,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=()=>{var e,t,i;let a=(0,n.useDependency)(B),s=(0,n.useDependency)(r.ICommandService),l=(0,n.useDependency)(n.IMessageService),u=(0,n.useDependency)(r.LocaleService),d=(0,n.useObservable)(a.showingLink$),f=(0,n.useDependency)(r.IUniverInstanceService);if(!d)return null;let{unitId:p,linkId:m,segmentId:h,startIndex:g,endIndex:_}=d,v=f.getUnit(p,r.UniverInstanceType.UNIVER_DOC),y=v==null||(e=v.getSelfOrHeaderFooterModel(h))==null?void 0:e.getBody(),b=y==null||(t=y.customRanges)==null?void 0:t.find(e=>e.rangeId===m&&e.rangeType===r.CustomRangeType.HYPERLINK&&e.startIndex===g&&e.endIndex===_);if(!b)return null;let x=(i=b.properties)==null?void 0:i.url;return(0,c.jsxs)(`div`,{className:(0,o.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`,o.borderClassName),onClick:()=>{a.hideInfoPopup()},children:[(0,c.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(x,void 0,`noopener noreferrer`),children:[(0,c.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,c.jsx)(O,{})}),(0,c.jsx)(o.Tooltip,{showIfEllipsis:!0,title:x,children:(0,c.jsx)(`span`,{className:`univer-flex-1 univer-truncate`,children:x})})]}),(0,c.jsxs)(`div`,{className:`univer-flex univer-h-6 univer-flex-[0_0_auto] univer-items-center univer-justify-center`,children:[(0,c.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:()=>{navigator.clipboard.writeText(x),l.show({content:u.t(`docs-hyper-link-ui.info.coped`),type:o.MessageType.Info})},children:(0,c.jsx)(o.Tooltip,{placement:`bottom`,title:u.t(`docs-hyper-link-ui.info.copy`),children:(0,c.jsx)(E,{})})}),(0,c.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:()=>{s.executeCommand(H.id,{link:d})},children:(0,c.jsx)(o.Tooltip,{placement:`bottom`,title:u.t(`docs-hyper-link-ui.info.edit`),children:(0,c.jsx)(M,{})})}),(0,c.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:()=>{s.executeCommand(N.id,{unitId:p,linkId:b.rangeId,segmentId:h})},children:(0,c.jsx)(o.Tooltip,{placement:`bottom`,title:u.t(`docs-hyper-link-ui.info.cancel`),children:(0,c.jsx)(A,{})})})]})]})};P.componentKey=`univer.doc.link-info-popup`;function F(e){"@babel/helpers - typeof";return F=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},F(e)}function ee(e,t){if(F(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(F(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function I(e){var t=ee(e,`string`);return F(t)==`symbol`?t:t+``}function L(e,t,n){return(t=I(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function R(e,t){return function(n,r){t(n,r,e)}}function z(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}let B=class extends r.Disposable{constructor(e,t,n){super(),this._docCanvasPopupManagerService=e,this._textSelectionManagerService=t,this._univerInstanceService=n,L(this,`_editingLink$`,new a.BehaviorSubject(null)),L(this,`_showingLink$`,new a.BehaviorSubject(null)),L(this,`editingLink$`,this._editingLink$.asObservable()),L(this,`showingLink$`,this._showingLink$.asObservable()),L(this,`_editPopup`,null),L(this,`_infoPopup`,null),L(this,`_infoPopupSuppressed`,!1),L(this,`_infoPopupSuppressionTimer`,null),this.disposeWithMe(()=>{this._infoPopupSuppressionTimer!==null&&clearTimeout(this._infoPopupSuppressionTimer),this._editingLink$.complete(),this._showingLink$.complete()})}get editing(){return this._editingLink$.value}get showing(){return this._showingLink$.value}showEditPopup(e,t){this._editPopup&&this._editPopup.dispose(),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:_.componentKey,direction:`bottom`,offset:[0,10]},e),this._editPopup):null}hideEditPopup(){var e;this._editingLink$.next(null),(e=this._editPopup)==null||e.dispose()}showInfoPopup(e){var t,n,i,a,o,s;if(this._infoPopupSuppressed)return;let{linkId:c,unitId:l,segmentId:u,segmentPage:d,startIndex:f,endIndex:p}=e;if((((t=this.showing)==null?void 0:t.linkId)!==c||((n=this.showing)==null?void 0:n.unitId)!==l||((i=this.showing)==null?void 0:i.segmentId)!==u||((a=this.showing)==null?void 0:a.segmentPage)!==d||((o=this.showing)==null?void 0:o.startIndex)!==f||((s=this.showing)==null?void 0:s.endIndex)!==p)&&(this._infoPopup&&this._infoPopup.dispose(),this._univerInstanceService.getUnit(l,r.UniverInstanceType.UNIVER_DOC)))return this._showingLink$.next({unitId:l,linkId:c,segmentId:u,segmentPage:d,startIndex:f,endIndex:p}),this._infoPopup=this._docCanvasPopupManagerService.attachPopupToRange({collapsed:!1,startOffset:f,endOffset:p+1,segmentId:u,segmentPage:d},{componentKey:P.componentKey,direction:`top-center`,multipleDirection:`top`,offset:[0,10],onClickOutside:()=>{this.hideInfoPopup()}},l),this._infoPopup}hideInfoPopup(){var e;this._showingLink$.next(null),(e=this._infoPopup)==null||e.dispose()}hideInfoPopupOnPointerDown(){this._infoPopupSuppressed=!0,this._infoPopupSuppressionTimer!==null&&clearTimeout(this._infoPopupSuppressionTimer),this.hideInfoPopup(),this._infoPopupSuppressionTimer=setTimeout(()=>{this._infoPopupSuppressed=!1,this._infoPopupSuppressionTimer=null},0)}};B=z([R(0,(0,r.Inject)(t.DocCanvasPopManagerService)),R(1,(0,r.Inject)(i.DocSelectionManagerService)),R(2,r.IUniverInstanceService)],B);let V=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)},H={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(V(e)&&!i)return!1;let o=e.get(B),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),!0):!1}},U={type:r.CommandType.OPERATION,id:`doc.operation.toggle-hyper-link-info-popup`,handler(e,t){let n=e.get(B);return t?(n.showInfoPopup(t),!0):(n.hideInfoPopup(),!0)}},W={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 G(e){return{id:H.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 a.Observable(function(t){let n=e.get(i.DocSelectionManagerService).textSelection$.pipe((0,a.debounceTime)(16)).subscribe(()=>{t.next(V(e))});return()=>{n.unsubscribe()}})}}let te={id:H.id,binding:n.MetaKeys.CTRL_COMMAND|n.KeyCode.K,description:`docs-hyper-link-ui.menu.tooltip`,preconditions:t.whenDocAndEditorFocused},K={[n.RibbonInsertGroup.MEDIA]:{[H.id]:{order:1,menuItemFactory:G}},[t.FLOAT_TOOLBAR_MENU_POSITION]:{[H.id]:{order:20,menuItemFactory:G}},[n.ContextMenuPosition.MAIN_AREA]:{[n.ContextMenuGroup.DATA]:{[H.id]:{order:0,menuItemFactory:G}}},[n.ContextMenuPosition.PARAGRAPH]:{[n.ContextMenuGroup.LAYOUT]:{[t.INSERT_BELLOW_MENU_ID]:{[H.id]:{order:6,menuItemFactory:G}}},[t.EMPTY_PARAGRAPH_MENU_ID]:{[n.ContextMenuGroup.LAYOUT]:{[H.id]:{order:6,menuItemFactory:G}}}}};var ne=`@univerjs/docs-hyper-link-ui`,re=`1.0.0-beta.2`;let q={},J=class extends r.Disposable{constructor(e,t){super(),this._componentManager=e,this._iconManager=t,this._registerComponents(),this._registerIcons()}_registerComponents(){[[_.componentKey,_],[P.componentKey,P]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_registerIcons(){this.disposeWithMe(this._iconManager.register({LinkIcon:O}))}};J=z([R(0,(0,r.Inject)(n.ComponentManager)),R(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||(t=t.customRanges)==null?void 0:t.find(t=>t.rangeType===r.CustomRangeType.HYPERLINK&&t.startIndex<e&&t.endIndex>i-1);if(l){this._docHyperLinkService.showInfoPopup({unitId:n,linkId:l.rangeId,segmentId:a,segmentPage:c,startIndex:l.startIndex,endIndex:l.endIndex});return}}this._docHyperLinkService.hideInfoPopup(),this._docHyperLinkService.hideEditPopup()}}))}};Y=z([R(0,r.ICommandService),R(1,r.IUniverInstanceService),R(2,(0,r.Inject)(B))],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.showing&&this._commandService.executeCommand(U.id)}_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(U.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;t.rangeType!==r.CustomRangeType.HYPERLINK||!e.ctrlKey&&!e.metaKey||this._commandService.executeCommand(W.id,{unitId:this._context.unitId,linkId:t.rangeId,segmentId:e.segmentId})}))}};X=z([R(1,(0,r.Inject)(t.DocEventManagerService)),R(2,r.ICommandService),R(3,(0,r.Inject)(B)),R(4,(0,r.Inject)(i.DocSkeletonManagerService)),R(5,(0,r.Inject)(i.DocSelectionManagerService))],X);let Z=class extends r.Disposable{constructor(e,t,n,r){super(),this._context=e,this._docInterceptorService=t,this._hyperLinkService=n,this._docRenderController=r,this._init(),this._initReRender()}_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})}})}_initReRender(){this.disposeWithMe(this._hyperLinkService.showingLink$.pipe((0,a.distinctUntilChanged)((e,t)=>(e==null?void 0:e.linkId)===(t==null?void 0:t.linkId)&&(e==null?void 0:e.unitId)===(t==null?void 0:t.unitId)&&(e==null?void 0:e.startIndex)===(t==null?void 0:t.startIndex)),(0,a.pairwise)()).subscribe(([e,t])=>{t?t.unitId===this._context.unitId&&this._docRenderController.reRender(t.unitId):e&&e.unitId===this._context.unitId&&this._docRenderController.reRender(e.unitId)}))}};Z=z([R(1,(0,r.Inject)(i.DocInterceptorService)),R(2,(0,r.Inject)(B)),R(3,(0,r.Inject)(t.DocRenderController))],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(){[d,f,N,H,U,W].forEach(e=>{this._commandService.registerCommand(e)})}_initShortcut(){[te].forEach(e=>{this._shortcutService.registerShortcut(e)})}_initMenus(){this._menuManagerService.appendRootMenu({[t.FLOAT_TOOLBAR_MENU_POSITION]:{}}),this._menuManagerService.mergeMenu(K)}};Q=z([R(0,r.ICommandService),R(1,n.IMenuManagerService),R(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),[[B],[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)})}};L($,`pluginName`,`DOC_HYPER_LINK_UI_PLUGIN`),L($,`packageName`,ne),L($,`version`,re),L($,`type`,r.UniverInstanceType.UNIVER_DOC),$=z([(0,r.DependentOn)(i.UniverDocsPlugin,u.UniverRenderEnginePlugin,l.UniverDocsHyperLinkPlugin,t.UniverDocsUIPlugin),R(1,(0,r.Inject)(r.Injector)),R(2,u.IRenderManagerService),R(3,r.IConfigService)],$),e.DocsHyperLinkUIMenuSchema=K,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-beta.
|
|
3
|
+
"version": "1.0.0-beta.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Hyperlink editing UI for Univer Docs.",
|
|
6
6
|
"author": "DreamNum Co., Ltd. <developer@univer.ai>",
|
|
@@ -58,14 +58,14 @@
|
|
|
58
58
|
"rxjs": ">=7.0.0"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@univerjs/icons": "1.
|
|
62
|
-
"@univerjs/core": "1.0.0-beta.
|
|
63
|
-
"@univerjs/
|
|
64
|
-
"@univerjs/
|
|
65
|
-
"@univerjs/docs-hyper-link": "1.0.0-beta.
|
|
66
|
-
"@univerjs/docs-ui": "1.0.0-beta.
|
|
67
|
-
"@univerjs/
|
|
68
|
-
"@univerjs/
|
|
61
|
+
"@univerjs/icons": "1.38.0",
|
|
62
|
+
"@univerjs/core": "1.0.0-beta.2",
|
|
63
|
+
"@univerjs/design": "1.0.0-beta.2",
|
|
64
|
+
"@univerjs/docs": "1.0.0-beta.2",
|
|
65
|
+
"@univerjs/docs-hyper-link": "1.0.0-beta.2",
|
|
66
|
+
"@univerjs/docs-ui": "1.0.0-beta.2",
|
|
67
|
+
"@univerjs/ui": "1.0.0-beta.2",
|
|
68
|
+
"@univerjs/engine-render": "1.0.0-beta.2"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"postcss": "^8.5.25",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"tailwindcss": "3.4.18",
|
|
75
75
|
"typescript": "^6.0.3",
|
|
76
76
|
"vitest": "^4.1.10",
|
|
77
|
-
"@univerjs-infra/shared": "1.0.0-beta.
|
|
77
|
+
"@univerjs-infra/shared": "1.0.0-beta.2"
|
|
78
78
|
},
|
|
79
79
|
"scripts": {
|
|
80
80
|
"test": "vitest run",
|