@univerjs/docs-hyper-link-ui 0.2.12 → 0.2.14
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 +1 -1
- package/lib/es/index.js +79 -73
- package/lib/types/commands/commands/add-link.command.d.ts +2 -1
- package/lib/types/controllers/render-controllers/hyper-link-event.render-controller.d.ts +4 -4
- package/lib/types/plugin.d.ts +1 -1
- package/lib/types/services/hyper-link-popup.service.d.ts +3 -3
- package/lib/umd/index.js +1 -1
- package/package.json +19 -19
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const core=require("@univerjs/core"),engineRender=require("@univerjs/engine-render"),docsHyperLink=require("@univerjs/docs-hyper-link"),ui=require("@univerjs/ui"),design=require("@univerjs/design"),React=require("react"),docs=require("@univerjs/docs"),docsUi=require("@univerjs/docs-ui"),rxjs=require("rxjs"),cs=require("clsx"),DOC_HYPER_LINK_UI_PLUGIN="DOC_HYPER_LINK_UI_PLUGIN";var __assign=function(){return __assign=Object.assign||function(t){for(var s,i=1,n=arguments.length;i<n;i++){s=arguments[i];for(var p in s)Object.prototype.hasOwnProperty.call(s,p)&&(t[p]=s[p])}return t},__assign.apply(this,arguments)},__rest=function(s,e){var t={};for(var p in s)Object.prototype.hasOwnProperty.call(s,p)&&e.indexOf(p)<0&&(t[p]=s[p]);if(s!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,p=Object.getOwnPropertySymbols(s);i<p.length;i++)e.indexOf(p[i])<0&&Object.prototype.propertyIsEnumerable.call(s,p[i])&&(t[p[i]]=s[p[i]]);return t},IconBase=React.forwardRef(function(props,ref){var icon=props.icon,id=props.id,className=props.className,extend=props.extend,restProps=__rest(props,["icon","id","className","extend"]),cls="univerjs-icon univerjs-icon-".concat(id," ").concat(className||"").trim(),idSuffix=React.useRef("_".concat(generateShortUuid()));return render(icon,"".concat(id),{defIds:icon.defIds,idSuffix:idSuffix.current},__assign({ref,className:cls},restProps),extend)});function render(node,id,runtimeProps,rootProps,extend){return React.createElement(node.tag,__assign(__assign({key:id},replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend)),rootProps),(replaceRuntimeIdsInDefs(node,runtimeProps).children||[]).map(function(child,index){return render(child,"".concat(id,"-").concat(node.tag,"-").concat(index),runtimeProps,void 0,extend)}))}__name(render,"render");function replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend){var attrs=__assign({},node.attrs);extend!=null&&extend.colorChannel1&&attrs.fill==="colorChannel1"&&(attrs.fill=extend.colorChannel1);var defIds=runtimeProps.defIds;return!defIds||defIds.length===0||(node.tag==="use"&&attrs["xlink:href"]&&(attrs["xlink:href"]=attrs["xlink:href"]+runtimeProps.idSuffix),Object.entries(attrs).forEach(function(_a7){var key=_a7[0],value=_a7[1];typeof value=="string"&&(attrs[key]=value.replace(/url\(#(.*)\)/,"url(#$1".concat(runtimeProps.idSuffix,")")))})),attrs}__name(replaceRuntimeIdsAndExtInAttrs,"replaceRuntimeIdsAndExtInAttrs");function replaceRuntimeIdsInDefs(node,runtimeProps){var _a7,defIds=runtimeProps.defIds;return!defIds||defIds.length===0?node:node.tag==="defs"&&(!((_a7=node.children)===null||_a7===void 0)&&_a7.length)?__assign(__assign({},node),{children:node.children.map(function(child){return typeof child.attrs.id=="string"&&defIds&&defIds.indexOf(child.attrs.id)>-1?__assign(__assign({},child),{attrs:__assign(__assign({},child.attrs),{id:child.attrs.id+runtimeProps.idSuffix})}):child})}):node}__name(replaceRuntimeIdsInDefs,"replaceRuntimeIdsInDefs");function generateShortUuid(){return Math.random().toString(36).substring(2,8)}__name(generateShortUuid,"generateShortUuid");IconBase.displayName="UniverIcon";var element$3={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M4.1302 12.4251C4.25802 13.7417 5.36779 14.7708 6.71792 14.7708H11.7179C13.1539 14.7708 14.3179 13.6067 14.3179 12.1708V6.1708C14.3179 4.78586 13.2351 3.65383 11.8698 3.57517C11.742 2.25858 10.6323 1.22949 9.28213 1.22949H4.28213C2.84619 1.22949 1.68213 2.39355 1.68213 3.82949V9.82949C1.68213 11.2144 2.76497 12.3465 4.1302 12.4251ZM10.6583 3.5708H6.71792C5.28198 3.5708 4.11792 4.73486 4.11792 6.1708V11.22C3.4221 11.1387 2.88213 10.5471 2.88213 9.82949V3.82949C2.88213 3.05629 3.50893 2.42949 4.28213 2.42949H9.28213C9.96695 2.42949 10.5369 2.92119 10.6583 3.5708ZM13.1179 6.1708C13.1179 5.3976 12.4911 4.7708 11.7179 4.7708H6.71792C5.94472 4.7708 5.31792 5.3976 5.31792 6.1708V12.1708C5.31792 12.944 5.94472 13.5708 6.71792 13.5708H11.7179C12.4911 13.5708 13.1179 12.944 13.1179 12.1708V6.1708Z",fillRule:"evenodd",clipRule:"evenodd"}}]},CopySingle=React.forwardRef(function(props,ref){return React.createElement(IconBase,Object.assign({},props,{id:"copy-single",ref,icon:element$3}))});CopySingle.displayName="CopySingle";var element$2={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.9564 2.91332C4.91407 1.87102 3.22413 1.87101 2.18182 2.91333L2.18182 2.91333C1.13953 3.95567 1.13952 5.6456 2.18182 6.68791L8.27777 12.7838C9.72408 14.2302 12.069 14.2302 13.5154 12.7839L13.0911 12.3596L13.5154 12.7839C14.9617 11.3375 14.9617 8.99257 13.5154 7.54626L8.39476 2.42566C8.16044 2.19134 7.78054 2.19134 7.54623 2.42566C7.31191 2.65997 7.31191 3.03987 7.54623 3.27419L12.6668 8.39479L13.0911 7.97052L12.6668 8.39479C13.6445 9.37247 13.6445 10.9576 12.6668 11.9353L13.0399 12.3084L12.6668 11.9353C11.6891 12.913 10.104 12.913 9.1263 11.9353L3.03035 5.83938C2.45668 5.26571 2.45667 4.33556 3.03036 3.76184C3.60403 3.18818 4.53416 3.18817 5.10788 3.76185C5.10788 3.76186 5.10788 3.76186 5.10789 3.76186L11.2038 9.8578L11.601 9.46061L11.2038 9.8578C11.3735 10.0275 11.3735 10.3026 11.2038 10.4723L11.2038 10.4723C11.0341 10.642 10.759 10.642 10.5893 10.4723L5.46874 5.35171C5.23442 5.1174 4.85452 5.1174 4.62021 5.35171C4.38589 5.58602 4.38589 5.96592 4.62021 6.20024L9.74078 11.3208C10.3791 11.9591 11.414 11.9591 12.0523 11.3208C12.0523 11.3208 12.0523 11.3208 12.0523 11.3208M12.0523 11.3208C12.6907 10.6825 12.6906 9.64757 12.0523 9.00927L5.95641 2.91333L5.9564 2.91332",fillRule:"evenodd",clipRule:"evenodd"}}]},LinkSingle=React.forwardRef(function(props,ref){return React.createElement(IconBase,Object.assign({},props,{id:"link-single",ref,icon:element$2}))});LinkSingle.displayName="LinkSingle";var element$1={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.5935 3.47302C11.6354 2.51492 10.082 2.51492 9.12388 3.47302L7.83534 4.76157C7.60102 4.99588 7.22112 4.99588 6.98681 4.76157 6.75249 4.52725 6.75249 4.14735 6.98681 3.91304L8.27535 2.62449C9.70209 1.19776 12.0153 1.19776 13.442 2.62449 14.8688 4.05123 14.8688 6.36442 13.442 7.79116L12.1535 9.0797C11.9192 9.31402 11.5393 9.31402 11.3049 9.0797 11.0706 8.84539 11.0706 8.46549 11.3049 8.23117L12.5935 6.94263C13.5516 5.98452 13.5516 4.43113 12.5935 3.47302zM3.40637 12.6606C2.44827 11.7025 2.44827 10.1491 3.40637 9.19102L4.69492 7.90248C4.92923 7.66816 4.92923 7.28826 4.69492 7.05395 4.4606 6.81963 4.0807 6.81963 3.84639 7.05395L2.55784 8.34249C1.13111 9.76923 1.13111 12.0824 2.55784 13.5092 3.98458 14.9359 6.29777 14.9359 7.72451 13.5092L9.01305 12.2206C9.24737 11.9863 9.24737 11.6064 9.01305 11.3721 8.77874 11.1378 8.39884 11.1378 8.16452 11.3721L6.87598 12.6606C5.91787 13.6187 4.36448 13.6187 3.40637 12.6606zM3.5852 2.80332C3.35088 2.569 2.97098 2.569 2.73667 2.80332 2.50235 3.03763 2.50235 3.41753 2.73667 3.65185L12.4151 13.3302C12.6494 13.5646 13.0293 13.5646 13.2636 13.3302 13.4979 13.0959 13.4979 12.716 13.2636 12.4817L3.5852 2.80332z"}}]},UnlinkSingle=React.forwardRef(function(props,ref){return React.createElement(IconBase,Object.assign({},props,{id:"unlink-single",ref,icon:element$1}))});UnlinkSingle.displayName="UnlinkSingle";var element={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.6551 1.98906C11.7476 1.08113 10.2757 1.08149 9.3686 1.98987L4.82542 6.53955C4.75087 6.61421 4.69336 6.70411 4.65682 6.80309L3.2461 10.625C3.16506 10.8446 3.21909 11.0912 3.3845 11.2568C3.54991 11.4224 3.79651 11.4767 4.01616 11.3959L7.85031 9.98517C7.94979 9.94856 8.04014 9.89077 8.11508 9.81579L12.6552 5.27327C13.5618 4.36621 13.5618 2.89607 12.6551 1.98906ZM10.2177 2.83779C10.6562 2.39869 11.3677 2.39851 11.8064 2.8374C12.2447 3.27584 12.2447 3.9865 11.8065 4.42497L7.3392 8.89457L4.82213 9.82068L5.74706 7.31487L10.2177 2.83779Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.79238 13.2999C1.46101 13.2999 1.19238 13.5685 1.19238 13.8999C1.19238 14.2313 1.46101 14.4999 1.79238 14.4999H14.4924C14.8238 14.4999 15.0924 14.2313 15.0924 13.8999C15.0924 13.5685 14.8238 13.2999 14.4924 13.2999H1.79238Z"}}]},WriteSingle=React.forwardRef(function(props,ref){return React.createElement(IconBase,Object.assign({},props,{id:"write-single",ref,icon:element}))});WriteSingle.displayName="WriteSingle";const DeleteDocHyperLinkCommand={type:core.CommandType.COMMAND,id:"docs.command.delete-hyper-link",async handler(accessor,params){if(!params)return!1;const{unitId,linkId,segmentId}=params,commandService=accessor.get(core.ICommandService),doMutation=docs.deleteCustomRangeFactory(accessor,{unitId,rangeId:linkId,segmentId});return doMutation?await commandService.syncExecuteCommand(doMutation.id,doMutation.params):!1}},shouldDisableAddLink=__name(accessor=>{var _a7;const textSelectionService=accessor.get(docs.TextSelectionManagerService),univerInstanceService=accessor.get(core.IUniverInstanceService),textRanges=textSelectionService.getDocRanges();if(!textRanges.length||textRanges.length>1)return!0;const activeRange=textRanges[0],doc=univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_DOC);if(!doc||!activeRange||activeRange.collapsed)return!0;const body=doc.getSelfOrHeaderFooterModel(activeRange.segmentId).getBody(),paragraphs=body==null?void 0:body.paragraphs;if(!paragraphs)return!0;for(let i=0,len=paragraphs.length;i<len;i++){const p=paragraphs[i];if(activeRange.startOffset<=p.startIndex&&activeRange.endOffset>p.startIndex)return!0;if(p.startIndex>activeRange.endOffset)break}return!docs.getCustomRangesInterestsWithRange(activeRange,(_a7=body.customRanges)!=null?_a7:[]).every(range=>range.rangeType===core.CustomRangeType.HYPERLINK)},"shouldDisableAddLink"),ShowDocHyperLinkEditPopupOperation={type:core.CommandType.OPERATION,id:"doc.operation.show-hyper-link-edit-popup",handler(accessor,params){var _a7;const linkInfo=params==null?void 0:params.link,univerInstanceService=accessor.get(core.IUniverInstanceService);if(shouldDisableAddLink(accessor)&&!linkInfo)return!1;const hyperLinkService=accessor.get(DocHyperLinkPopupService),unitId=(linkInfo==null?void 0:linkInfo.unitId)||((_a7=univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_DOC))==null?void 0:_a7.getUnitId());return unitId?(hyperLinkService.showEditPopup(unitId,linkInfo),!0):!1}},ToggleDocHyperLinkInfoPopupOperation={type:core.CommandType.OPERATION,id:"doc.operation.toggle-hyper-link-info-popup",handler(accessor,params){const hyperLinkService=accessor.get(DocHyperLinkPopupService);return params?(hyperLinkService.showInfoPopup(params),!0):(hyperLinkService.hideInfoPopup(),!0)}},ClickDocHyperLinkOperation={type:core.CommandType.OPERATION,id:"doc.operation.click-hyper-link",handler(accessor,params){var _a7,_b,_c;if(!params)return!1;const{unitId,linkId,segmentId}=params,doc=accessor.get(core.IUniverInstanceService).getUnit(unitId,core.UniverInstanceType.UNIVER_DOC),body=doc==null?void 0:doc.getSelfOrHeaderFooterModel(segmentId).getBody(),link=(_c=(_b=(_a7=body==null?void 0:body.customRanges)==null?void 0:_a7.find(range=>range.rangeId===linkId&&range.rangeType===core.CustomRangeType.HYPERLINK))==null?void 0:_b.properties)==null?void 0:_c.url;return link&&window.open(link,"_blank","noopener noreferrer"),!0}},docLink="univer-doc-link",docLinkType="univer-doc-link-type",docLinkContent="univer-doc-link-content",docLinkContentError="univer-doc-link-content-error",docLinkUrl="univer-doc-link-url",docLinkOperations="univer-doc-link-operations",docLinkOperation="univer-doc-link-operation",docLinkOperationError="univer-doc-link-operation-error",styles$1={docLink,docLinkType,docLinkContent,docLinkContentError,docLinkUrl,docLinkOperations,docLinkOperation,docLinkOperationError},DocLinkPopup=__name(()=>{var _a7,_b;const hyperLinkService=core.useDependency(DocHyperLinkPopupService),commandService=core.useDependency(core.ICommandService),messageService=core.useDependency(ui.IMessageService),localeService=core.useDependency(core.LocaleService),currentPopup=ui.useObservable(hyperLinkService.showingLink$),univerInstanceService=core.useDependency(core.IUniverInstanceService);if(!currentPopup)return null;const{unitId,linkId,segmentId}=currentPopup,doc=univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_DOC),body=doc==null?void 0:doc.getSelfOrHeaderFooterModel(segmentId).getBody(),link=(_a7=body==null?void 0:body.customRanges)==null?void 0:_a7.find(range=>range.rangeId===linkId&&range.rangeType===core.CustomRangeType.HYPERLINK);if(!link)return null;const url=(_b=link.properties)==null?void 0:_b.url;return React.createElement("div",{className:styles$1.docLink,onClick:__name(()=>{hyperLinkService.hideInfoPopup()},"onClick")},React.createElement("div",{className:cs(styles$1.docLinkContent),onClick:__name(()=>window.open(url),"onClick")},React.createElement("div",{className:styles$1.docLinkType},React.createElement(LinkSingle,null)),React.createElement(design.Tooltip,{showIfEllipsis:!0,title:url},React.createElement("span",{className:styles$1.docLinkUrl},url))),React.createElement("div",{className:styles$1.docLinkOperations},React.createElement("div",{className:cs(styles$1.docLinkOperation),onClick:__name(()=>{navigator.clipboard.writeText(url),messageService.show({content:localeService.t("docLink.info.coped"),type:design.MessageType.Info})},"onClick")},React.createElement(design.Tooltip,{placement:"bottom",title:localeService.t("docLink.info.copy")},React.createElement(CopySingle,null))),React.createElement("div",{className:styles$1.docLinkOperation,onClick:__name(()=>{commandService.executeCommand(ShowDocHyperLinkEditPopupOperation.id,{link:currentPopup})},"onClick")},React.createElement(design.Tooltip,{placement:"bottom",title:localeService.t("docLink.info.edit")},React.createElement(WriteSingle,null))),React.createElement("div",{className:styles$1.docLinkOperation,onClick:__name(()=>{commandService.executeCommand(DeleteDocHyperLinkCommand.id,{unitId,linkId:link.rangeId,segmentId})},"onClick")},React.createElement(design.Tooltip,{placement:"bottom",title:localeService.t("docLink.info.cancel")},React.createElement(UnlinkSingle,null)))))},"DocLinkPopup");DocLinkPopup.componentKey="univer.doc.link-info-popup";var __defProp$5=Object.defineProperty,__getOwnPropDesc$5=Object.getOwnPropertyDescriptor,__decorateClass$5=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$5(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$5(target,key,result),result},"__decorateClass$5"),__decorateParam$5=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$5");const SKIT_PLACEHOLDER=0;var _a;let DocHyperLinkPopupService=(_a=class extends core.Disposable{constructor(_docCanvasPopupManagerService,_textSelectionManagerService,_univerInstanceService){super();__publicField(this,"_editingLink$",new rxjs.BehaviorSubject(null));__publicField(this,"_showingLink$",new rxjs.BehaviorSubject(null));__publicField(this,"editingLink$",this._editingLink$.asObservable());__publicField(this,"showingLink$",this._showingLink$.asObservable());__publicField(this,"_editPopup",null);__publicField(this,"_infoPopup",null);this._docCanvasPopupManagerService=_docCanvasPopupManagerService,this._textSelectionManagerService=_textSelectionManagerService,this._univerInstanceService=_univerInstanceService,this.disposeWithMe(()=>{this._editingLink$.complete(),this._showingLink$.complete()})}get editing(){return this._editingLink$.value}get showing(){return this._showingLink$.value}showEditPopup(unitId,linkInfo){var _a7,_b,_c;this._editPopup&&this._editPopup.dispose(),this._editingLink$.next(linkInfo);let activeRange=this._textSelectionManagerService.getActiveTextRangeWithStyle();if(linkInfo){const{unitId:unitId2,linkId,segmentId,segmentPage}=linkInfo,doc=this._univerInstanceService.getUnit(unitId2,core.UniverInstanceType.UNIVER_DOC),range=(_c=(_b=(_a7=doc==null?void 0:doc.getSelfOrHeaderFooterModel(segmentId))==null?void 0:_a7.getBody())==null?void 0:_b.customRanges)==null?void 0:_c.find(i=>i.rangeId===linkId);range&&(activeRange={collapsed:!1,startOffset:range.startIndex+SKIT_PLACEHOLDER,endOffset:range.endIndex+1,segmentId,segmentPage},this._textSelectionManagerService.replaceTextRanges([{startOffset:range.startIndex,endOffset:range.endIndex+1}]))}return activeRange?(this._editPopup=this._docCanvasPopupManagerService.attachPopupToRange(activeRange,{componentKey:DocHyperLinkEdit.componentKey,direction:"bottom"},unitId),this._editPopup):null}hideEditPopup(){var _a7;this._editingLink$.next(null),(_a7=this._editPopup)==null||_a7.dispose()}showInfoPopup(info){var _a7,_b,_c,_d,_e,_f;const{linkId,unitId,segmentId,segmentPage}=info;if(((_a7=this.showing)==null?void 0:_a7.linkId)===linkId&&((_b=this.showing)==null?void 0:_b.unitId)===unitId&&((_c=this.showing)==null?void 0:_c.segmentId)===segmentId&&((_d=this.showing)==null?void 0:_d.segmentPage)===segmentPage)return;this._infoPopup&&this._infoPopup.dispose();const doc=this._univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_DOC);if(!doc)return;const range=(_f=(_e=doc.getSelfOrHeaderFooterModel(info.segmentId).getBody())==null?void 0:_e.customRanges)==null?void 0:_f.find(i=>i.rangeId===linkId);if(this._showingLink$.next({unitId,linkId,segmentId,segmentPage}),!!range)return this._infoPopup=this._docCanvasPopupManagerService.attachPopupToRange({collapsed:!1,startOffset:range.startIndex+SKIT_PLACEHOLDER,endOffset:range.endIndex+1,segmentId:info.segmentId,segmentPage:info.segmentPage},{componentKey:DocLinkPopup.componentKey,direction:"top-center",multipleDirection:"top",closeOnSelfTarget:!0,onClickOutside:__name(()=>{this.hideInfoPopup()},"onClickOutside")},info.unitId),this._infoPopup}hideInfoPopup(){var _a7;this._showingLink$.next(null),(_a7=this._infoPopup)==null||_a7.dispose()}},__name(_a,"DocHyperLinkPopupService"),_a);DocHyperLinkPopupService=__decorateClass$5([__decorateParam$5(0,core.Inject(docsUi.DocCanvasPopManagerService)),__decorateParam$5(1,core.Inject(docs.TextSelectionManagerService)),__decorateParam$5(2,core.IUniverInstanceService)],DocHyperLinkPopupService);const AddDocHyperLinkCommand={type:core.CommandType.COMMAND,id:"docs.command.add-hyper-link",async handler(accessor,params){if(!params)return!1;const{payload,unitId}=params,commandService=accessor.get(core.ICommandService),id=core.generateRandomId(),doMutation=docs.addCustomRangeBySelectionFactory(accessor,{rangeId:id,rangeType:core.CustomRangeType.HYPERLINK,properties:{url:payload}});return doMutation?commandService.syncExecuteCommand(doMutation.id,doMutation.params):!1}},UpdateDocHyperLinkCommand={id:"docs.command.update-hyper-link",type:core.CommandType.COMMAND,handler(accessor,params){if(!params)return!1;const{unitId,payload,segmentId}=params,commandService=accessor.get(core.ICommandService),currentSelection=accessor.get(docs.TextSelectionManagerService).getActiveTextRange();if(!currentSelection)return!1;const newId=core.generateRandomId(),replaceSelection=docs.replaceSelectionFactory(accessor,{unitId,body:{dataStream:`${core.DataStreamTreeTokenType.CUSTOM_RANGE_START}${params.label}${core.DataStreamTreeTokenType.CUSTOM_RANGE_END}`,customRanges:[{rangeId:newId,rangeType:core.CustomRangeType.HYPERLINK,startIndex:0,endIndex:params.label.length+1,properties:{url:payload}}]},selection:{startOffset:currentSelection.startOffset,endOffset:currentSelection.endOffset,collapsed:!1,segmentId}});return replaceSelection?commandService.syncExecuteCommand(replaceSelection.id,replaceSelection.params):!1}},docsLinkEdit="univer-docs-link-edit",docsLinkEditTitle="univer-docs-link-edit-title",docsLinkEditClose="univer-docs-link-edit-close",docsLinkEditButtons="univer-docs-link-edit-buttons",docsLinkEditButton="univer-docs-link-edit-button",styles={docsLinkEdit,docsLinkEditTitle,docsLinkEditClose,docsLinkEditButtons,docsLinkEditButton};function hasProtocol(urlString){return/^[a-zA-Z]+:\/\//.test(urlString)}__name(hasProtocol,"hasProtocol");function isEmail(url){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(url)}__name(isEmail,"isEmail");function transformUrl(urlStr){return hasProtocol(urlStr)?urlStr:isEmail(urlStr)?`mailto://${urlStr}`:`https://${urlStr}`}__name(transformUrl,"transformUrl");const DocHyperLinkEdit=__name(()=>{const hyperLinkService=core.useDependency(DocHyperLinkPopupService),localeService=core.useDependency(core.LocaleService),editing=core.useObservable(hyperLinkService.editingLink$),commandService=core.useDependency(core.ICommandService),univerInstanceService=core.useDependency(core.IUniverInstanceService),textSelectionRenderManager=core.useDependency(engineRender.ITextSelectionRenderManager),textSelectionManagerService=core.useDependency(docs.TextSelectionManagerService),[link,setLink]=React.useState(""),[label,setLabel]=React.useState(""),[showError,setShowError]=React.useState(!1),isLegal=core.Tools.isLegalUrl(link),doc=editing?univerInstanceService.getUnit(editing.unitId,core.UniverInstanceType.UNIVER_DOC):univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_DOC);React.useEffect(()=>{var _a7,_b,_c,_d,_e,_f,_g,_h,_i;const activeRange=textSelectionManagerService.getActiveTextRangeWithStyle();if(!activeRange)return;if(editing){const body=(_a7=doc==null?void 0:doc.getSelfOrHeaderFooterModel(editing.segmentId))==null?void 0:_a7.getBody(),matchedRange2=(_b=body==null?void 0:body.customRanges)==null?void 0:_b.find(i=>(editing==null?void 0:editing.linkId)===i.rangeId);doc&&matchedRange2&&(setLink((_d=(_c=matchedRange2.properties)==null?void 0:_c.url)!=null?_d:""),setLabel(docs.getPlainTextFormBody(core.getBodySlice(body,matchedRange2.startIndex,matchedRange2.endIndex))));return}const matchedRange=(_g=(_f=(_e=doc==null?void 0:doc.getSelfOrHeaderFooterModel(activeRange.segmentId))==null?void 0:_e.getBody())==null?void 0:_f.customRanges)==null?void 0:_g.find(i=>Math.max(activeRange.startOffset,i.startIndex)<=Math.min(activeRange.endOffset-1,i.endIndex));doc&&matchedRange&&setLink((_i=(_h=matchedRange==null?void 0:matchedRange.properties)==null?void 0:_h.url)!=null?_i:"")},[doc,editing,textSelectionManagerService,univerInstanceService]),React.useEffect(()=>(textSelectionRenderManager.blurEditor(),()=>{textSelectionRenderManager.focusEditor()}),[textSelectionRenderManager]);const handleCancel=__name(()=>{hyperLinkService.hideEditPopup()},"handleCancel"),handleConfirm=__name(()=>{if(setShowError(!0),!isLegal||!doc)return;const linkFinal=transformUrl(link);if(!editing)commandService.executeCommand(AddDocHyperLinkCommand.id,{unitId:doc.getUnitId(),payload:linkFinal});else{if(!label)return;commandService.executeCommand(UpdateDocHyperLinkCommand.id,{unitId:doc.getUnitId(),payload:linkFinal,linkId:editing.linkId,label,segmentId:editing.segmentId})}hyperLinkService.hideEditPopup()},"handleConfirm");if(doc)return React.createElement("div",{className:styles.docsLinkEdit},React.createElement("div",null,editing?React.createElement(design.FormLayout,{label:localeService.t("docLink.edit.label"),error:showError&&!label?localeService.t("docLink.edit.labelError"):""},React.createElement(design.Input,{value:label,onChange:setLabel,autoFocus:!0,onKeyDown:__name(evt=>{evt.keyCode===ui.KeyCode.ENTER&&handleConfirm()},"onKeyDown")})):null,React.createElement(design.FormLayout,{label:localeService.t("docLink.edit.address"),error:showError&&!isLegal?localeService.t("docLink.edit.addressError"):""},React.createElement(design.Input,{value:link,onChange:setLink,autoFocus:!0,onKeyDown:__name(evt=>{evt.keyCode===ui.KeyCode.ENTER&&handleConfirm()},"onKeyDown")}))),React.createElement("div",{className:styles.docsLinkEditButtons},React.createElement(design.Button,{className:styles.docsLinkEditButton,onClick:handleCancel},localeService.t("docLink.edit.cancel")),React.createElement(design.Button,{disabled:!link,className:styles.docsLinkEditButton,type:"primary",onClick:handleConfirm},localeService.t("docLink.edit.confirm"))))},"DocHyperLinkEdit");DocHyperLinkEdit.componentKey="docs-hyper-link-edit";const DOC_LINK_ICON="doc-hyper-link-icon";function AddHyperLinkMenuItemFactory(accessor){return{id:ShowDocHyperLinkEditPopupOperation.id,type:ui.MenuItemType.BUTTON,icon:DOC_LINK_ICON,title:"docLink.menu.tooltip",tooltip:"docLink.menu.tooltip",hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_DOC),disabled$:new rxjs.Observable(function(subscribe){const observer=accessor.get(docs.TextSelectionManagerService).textSelection$.pipe(rxjs.debounceTime(16)).subscribe(()=>{subscribe.next(shouldDisableAddLink(accessor))});return()=>{observer.unsubscribe()}})}}__name(AddHyperLinkMenuItemFactory,"AddHyperLinkMenuItemFactory");const addLinkShortcut={id:ShowDocHyperLinkEditPopupOperation.id,binding:ui.MetaKeys.CTRL_COMMAND|ui.KeyCode.K,description:"docLink.menu.tooltip",preconditions:docsUi.whenDocAndEditorFocused},menuSchema={[ui.RibbonStartGroup.OTHERS]:{[ShowDocHyperLinkEditPopupOperation.id]:{order:0,menuItemFactory:AddHyperLinkMenuItemFactory}},[ui.ContextMenuPosition.MAIN_AREA]:{[ui.ContextMenuGroup.DATA]:{[ShowDocHyperLinkEditPopupOperation.id]:{order:0,menuItemFactory:AddHyperLinkMenuItemFactory}}}};var __defProp$4=Object.defineProperty,__getOwnPropDesc$4=Object.getOwnPropertyDescriptor,__decorateClass$4=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$4(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$4(target,key,result),result},"__decorateClass$4"),__decorateParam$4=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$4"),_a2;let DocHyperLinkUIController=(_a2=class extends core.Disposable{constructor(_componentManager,_commandService,_menuManagerService,_injector,_shortcutService){super(),this._componentManager=_componentManager,this._commandService=_commandService,this._menuManagerService=_menuManagerService,this._injector=_injector,this._shortcutService=_shortcutService,this._initComponents(),this._initCommands(),this._initMenus(),this._initShortcut()}_initComponents(){[[DocHyperLinkEdit,DocHyperLinkEdit.componentKey],[DocLinkPopup,DocLinkPopup.componentKey],[LinkSingle,DOC_LINK_ICON]].forEach(([comp,key])=>{this._componentManager.register(key,comp)})}_initCommands(){[AddDocHyperLinkCommand,UpdateDocHyperLinkCommand,DeleteDocHyperLinkCommand,ShowDocHyperLinkEditPopupOperation,ToggleDocHyperLinkInfoPopupOperation,ClickDocHyperLinkOperation].forEach(command=>{this._commandService.registerCommand(command)})}_initShortcut(){[addLinkShortcut].forEach(shortcut=>{this._shortcutService.registerShortcut(shortcut)})}_initMenus(){this._menuManagerService.mergeMenu(menuSchema)}},__name(_a2,"DocHyperLinkUIController"),_a2);DocHyperLinkUIController=__decorateClass$4([core.OnLifecycle(core.LifecycleStages.Starting,DocHyperLinkUIController),__decorateParam$4(0,core.Inject(ui.ComponentManager)),__decorateParam$4(1,core.ICommandService),__decorateParam$4(2,ui.IMenuManagerService),__decorateParam$4(3,core.Inject(core.Injector)),__decorateParam$4(4,ui.IShortcutService)],DocHyperLinkUIController);var __defProp$3=Object.defineProperty,__getOwnPropDesc$3=Object.getOwnPropertyDescriptor,__decorateClass$3=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$3(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$3(target,key,result),result},"__decorateClass$3"),__decorateParam$3=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$3"),_a3;let DocHyperLinkSelectionController=(_a3=class extends core.Disposable{constructor(_commandService,_univerInstanceService,_docHyperLinkService){super(),this._commandService=_commandService,this._univerInstanceService=_univerInstanceService,this._docHyperLinkService=_docHyperLinkService,this._initSelectionChange()}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(commandInfo=>{var _a7,_b,_c;if(commandInfo.id===docs.SetTextSelectionsOperation.id){const params=commandInfo.params,{unitId,ranges,segmentId}=params,doc=this._univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_DOC),primary=ranges[0];if(primary&&doc){const{startOffset,endOffset,collapsed,segmentPage}=primary,customRanges=(_b=(_a7=doc.getSelfOrHeaderFooterModel(segmentId))==null?void 0:_a7.getBody())==null?void 0:_b.customRanges;if(collapsed){const index=(_c=customRanges==null?void 0:customRanges.findIndex(value=>value.startIndex<startOffset&&value.endIndex>endOffset-1))!=null?_c:-1;if(index>-1){const customRange=customRanges[index];this._docHyperLinkService.showInfoPopup({unitId,linkId:customRange.rangeId,segmentId,segmentPage});return}}else if(customRanges==null?void 0:customRanges.find(value=>value.startIndex<=startOffset&&value.endIndex>=endOffset-1))return}this._docHyperLinkService.hideInfoPopup(),this._docHyperLinkService.hideEditPopup()}}))}},__name(_a3,"DocHyperLinkSelectionController"),_a3);DocHyperLinkSelectionController=__decorateClass$3([core.OnLifecycle(core.LifecycleStages.Ready,DocHyperLinkSelectionController),__decorateParam$3(0,core.ICommandService),__decorateParam$3(1,core.IUniverInstanceService),__decorateParam$3(2,core.Inject(DocHyperLinkPopupService))],DocHyperLinkSelectionController);var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2"),_a4;let DocHyperLinkRenderController=(_a4=class extends core.Disposable{constructor(_context,_docInterceptorService,_hyperLinkService,_docRenderController){super(),this._context=_context,this._docInterceptorService=_docInterceptorService,this._hyperLinkService=_hyperLinkService,this._docRenderController=_docRenderController,this._init(),this._initReRender()}_init(){this._docInterceptorService.intercept(docs.DOC_INTERCEPTOR_POINT.CUSTOM_RANGE,{handler:__name((data,pos,next)=>{if(!data)return next(data);const{unitId}=pos,activeLink=this._hyperLinkService.showing,{linkId,unitId:linkUnitId}=activeLink||{},isActive=linkUnitId===unitId&&data.rangeId===linkId;return next({...data,active:isActive})},"handler")})}_initReRender(){this.disposeWithMe(this._hyperLinkService.showingLink$.pipe(rxjs.distinctUntilChanged((prev,aft)=>(prev==null?void 0:prev.linkId)===(aft==null?void 0:aft.linkId)&&(prev==null?void 0:prev.unitId)===(aft==null?void 0:aft.unitId)),rxjs.pairwise()).subscribe(([preLink,link])=>{link?link.unitId===this._context.unitId&&this._docRenderController.reRender(link.unitId):preLink&&preLink.unitId===this._context.unitId&&this._docRenderController.reRender(preLink.unitId)}))}},__name(_a4,"DocHyperLinkRenderController"),_a4);DocHyperLinkRenderController=__decorateClass$2([__decorateParam$2(1,core.Inject(docs.DocInterceptorService)),__decorateParam$2(2,core.Inject(DocHyperLinkPopupService)),__decorateParam$2(3,core.Inject(docsUi.DocRenderController))],DocHyperLinkRenderController);var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1"),_a5;let DocHyperLinkEventRenderController=(_a5=class extends core.Disposable{constructor(_context,_docEventManagerService,_commandService,_hyperLinkPopupService,_docSkeletonManagerService,_textSelectionManagerService){super(),this._context=_context,this._docEventManagerService=_docEventManagerService,this._commandService=_commandService,this._hyperLinkPopupService=_hyperLinkPopupService,this._docSkeletonManagerService=_docSkeletonManagerService,this._textSelectionManagerService=_textSelectionManagerService,this._initHover(),this._initClick()}get _skeleton(){return this._docSkeletonManagerService.getSkeleton()}_hideInfoPopup(){this._hyperLinkPopupService.showing&&this._commandService.executeCommand(ToggleDocHyperLinkInfoPopupOperation.id)}_initHover(){this.disposeWithMe(this._docEventManagerService.hoverCustomRanges$.subscribe(ranges=>{var _a7;const link=ranges.find(range=>range.range.rangeType===core.CustomRangeType.HYPERLINK),activeRanges=this._textSelectionManagerService.getCurrentTextRanges(),currentSegmentId=activeRanges==null?void 0:activeRanges[0].segmentId;if(((_a7=link==null?void 0:link.segmentId)!=null?_a7:"")!==currentSegmentId){this._hideInfoPopup();return}link?this._commandService.executeCommand(ToggleDocHyperLinkInfoPopupOperation.id,{unitId:this._context.unitId,linkId:link.range.rangeId,segmentId:link.segmentId,segmentPage:link.segmentPageIndex,rangeId:link.range.rangeId}):this._hideInfoPopup()}))}_initClick(){this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe(range=>{const link=range.range;link&&this._commandService.executeCommand(ClickDocHyperLinkOperation.id,{unitId:this._context.unitId,linkId:link.rangeId,segmentId:range.segmentId})}))}},__name(_a5,"DocHyperLinkEventRenderController"),_a5);DocHyperLinkEventRenderController=__decorateClass$1([__decorateParam$1(1,core.Inject(docsUi.DocEventManagerService)),__decorateParam$1(2,core.ICommandService),__decorateParam$1(3,core.Inject(DocHyperLinkPopupService)),__decorateParam$1(4,core.Inject(docs.DocSkeletonManagerService)),__decorateParam$1(5,core.Inject(docs.TextSelectionManagerService))],DocHyperLinkEventRenderController);const PLUGIN_CONFIG_KEY="docs-hyper-link-ui.config",defaultPluginConfig={};var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key,value)=>key in obj?__defProp2(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),__publicField2=__name((obj,key,value)=>__defNormalProp2(obj,typeof key!="symbol"?key+"":key,value),"__publicField"),_a6;exports.UniverDocsHyperLinkUIPlugin=(_a6=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_renderManagerSrv,_configService){super(),this._config=_config,this._injector=_injector,this._renderManagerSrv=_renderManagerSrv,this._configService=_configService;const{menu,...rest}=this._config;menu&&this._configService.setConfig("menu",menu,{merge:!0}),this._configService.setConfig(PLUGIN_CONFIG_KEY,rest)}onStarting(){[[DocHyperLinkPopupService],[DocHyperLinkUIController],[DocHyperLinkSelectionController]].forEach(dep=>{this._injector.add(dep)})}onRendered(){this._initRenderModule()}_initRenderModule(){[[DocHyperLinkRenderController],[DocHyperLinkEventRenderController]].forEach(dep=>{this._renderManagerSrv.registerRenderModule(core.UniverInstanceType.UNIVER_DOC,dep)})}},__name(_a6,"UniverDocsHyperLinkUIPlugin"),_a6);__publicField2(exports.UniverDocsHyperLinkUIPlugin,"pluginName",DOC_HYPER_LINK_UI_PLUGIN);__publicField2(exports.UniverDocsHyperLinkUIPlugin,"type",core.UniverInstanceType.UNIVER_DOC);exports.UniverDocsHyperLinkUIPlugin=__decorateClass([core.DependentOn(docsHyperLink.UniverDocsHyperLinkPlugin),__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,engineRender.IRenderManagerService),__decorateParam(3,core.IConfigService)],exports.UniverDocsHyperLinkUIPlugin);
|
|
1
|
+
"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const core=require("@univerjs/core"),engineRender=require("@univerjs/engine-render"),docsHyperLink=require("@univerjs/docs-hyper-link"),ui=require("@univerjs/ui"),design=require("@univerjs/design"),docs=require("@univerjs/docs"),docsUi=require("@univerjs/docs-ui"),React=require("react"),rxjs=require("rxjs"),cs=require("clsx"),DOC_HYPER_LINK_UI_PLUGIN="DOC_HYPER_LINK_UI_PLUGIN";var __assign=function(){return __assign=Object.assign||function(t){for(var s,i=1,n=arguments.length;i<n;i++){s=arguments[i];for(var p in s)Object.prototype.hasOwnProperty.call(s,p)&&(t[p]=s[p])}return t},__assign.apply(this,arguments)},__rest=function(s,e){var t={};for(var p in s)Object.prototype.hasOwnProperty.call(s,p)&&e.indexOf(p)<0&&(t[p]=s[p]);if(s!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,p=Object.getOwnPropertySymbols(s);i<p.length;i++)e.indexOf(p[i])<0&&Object.prototype.propertyIsEnumerable.call(s,p[i])&&(t[p[i]]=s[p[i]]);return t},IconBase=React.forwardRef(function(props,ref){var icon=props.icon,id=props.id,className=props.className,extend=props.extend,restProps=__rest(props,["icon","id","className","extend"]),cls="univerjs-icon univerjs-icon-".concat(id," ").concat(className||"").trim(),idSuffix=React.useRef("_".concat(generateShortUuid()));return render(icon,"".concat(id),{defIds:icon.defIds,idSuffix:idSuffix.current},__assign({ref,className:cls},restProps),extend)});function render(node,id,runtimeProps,rootProps,extend){return React.createElement(node.tag,__assign(__assign({key:id},replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend)),rootProps),(replaceRuntimeIdsInDefs(node,runtimeProps).children||[]).map(function(child,index){return render(child,"".concat(id,"-").concat(node.tag,"-").concat(index),runtimeProps,void 0,extend)}))}__name(render,"render");function replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend){var attrs=__assign({},node.attrs);extend!=null&&extend.colorChannel1&&attrs.fill==="colorChannel1"&&(attrs.fill=extend.colorChannel1);var defIds=runtimeProps.defIds;return!defIds||defIds.length===0||(node.tag==="use"&&attrs["xlink:href"]&&(attrs["xlink:href"]=attrs["xlink:href"]+runtimeProps.idSuffix),Object.entries(attrs).forEach(function(_a7){var key=_a7[0],value=_a7[1];typeof value=="string"&&(attrs[key]=value.replace(/url\(#(.*)\)/,"url(#$1".concat(runtimeProps.idSuffix,")")))})),attrs}__name(replaceRuntimeIdsAndExtInAttrs,"replaceRuntimeIdsAndExtInAttrs");function replaceRuntimeIdsInDefs(node,runtimeProps){var _a7,defIds=runtimeProps.defIds;return!defIds||defIds.length===0?node:node.tag==="defs"&&(!((_a7=node.children)===null||_a7===void 0)&&_a7.length)?__assign(__assign({},node),{children:node.children.map(function(child){return typeof child.attrs.id=="string"&&defIds&&defIds.indexOf(child.attrs.id)>-1?__assign(__assign({},child),{attrs:__assign(__assign({},child.attrs),{id:child.attrs.id+runtimeProps.idSuffix})}):child})}):node}__name(replaceRuntimeIdsInDefs,"replaceRuntimeIdsInDefs");function generateShortUuid(){return Math.random().toString(36).substring(2,8)}__name(generateShortUuid,"generateShortUuid");IconBase.displayName="UniverIcon";var element$3={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M4.1302 12.4251C4.25802 13.7417 5.36779 14.7708 6.71792 14.7708H11.7179C13.1539 14.7708 14.3179 13.6067 14.3179 12.1708V6.1708C14.3179 4.78586 13.2351 3.65383 11.8698 3.57517C11.742 2.25858 10.6323 1.22949 9.28213 1.22949H4.28213C2.84619 1.22949 1.68213 2.39355 1.68213 3.82949V9.82949C1.68213 11.2144 2.76497 12.3465 4.1302 12.4251ZM10.6583 3.5708H6.71792C5.28198 3.5708 4.11792 4.73486 4.11792 6.1708V11.22C3.4221 11.1387 2.88213 10.5471 2.88213 9.82949V3.82949C2.88213 3.05629 3.50893 2.42949 4.28213 2.42949H9.28213C9.96695 2.42949 10.5369 2.92119 10.6583 3.5708ZM13.1179 6.1708C13.1179 5.3976 12.4911 4.7708 11.7179 4.7708H6.71792C5.94472 4.7708 5.31792 5.3976 5.31792 6.1708V12.1708C5.31792 12.944 5.94472 13.5708 6.71792 13.5708H11.7179C12.4911 13.5708 13.1179 12.944 13.1179 12.1708V6.1708Z",fillRule:"evenodd",clipRule:"evenodd"}}]},CopySingle=React.forwardRef(function(props,ref){return React.createElement(IconBase,Object.assign({},props,{id:"copy-single",ref,icon:element$3}))});CopySingle.displayName="CopySingle";var element$2={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.9564 2.91332C4.91407 1.87102 3.22413 1.87101 2.18182 2.91333L2.18182 2.91333C1.13953 3.95567 1.13952 5.6456 2.18182 6.68791L8.27777 12.7838C9.72408 14.2302 12.069 14.2302 13.5154 12.7839L13.0911 12.3596L13.5154 12.7839C14.9617 11.3375 14.9617 8.99257 13.5154 7.54626L8.39476 2.42566C8.16044 2.19134 7.78054 2.19134 7.54623 2.42566C7.31191 2.65997 7.31191 3.03987 7.54623 3.27419L12.6668 8.39479L13.0911 7.97052L12.6668 8.39479C13.6445 9.37247 13.6445 10.9576 12.6668 11.9353L13.0399 12.3084L12.6668 11.9353C11.6891 12.913 10.104 12.913 9.1263 11.9353L3.03035 5.83938C2.45668 5.26571 2.45667 4.33556 3.03036 3.76184C3.60403 3.18818 4.53416 3.18817 5.10788 3.76185C5.10788 3.76186 5.10788 3.76186 5.10789 3.76186L11.2038 9.8578L11.601 9.46061L11.2038 9.8578C11.3735 10.0275 11.3735 10.3026 11.2038 10.4723L11.2038 10.4723C11.0341 10.642 10.759 10.642 10.5893 10.4723L5.46874 5.35171C5.23442 5.1174 4.85452 5.1174 4.62021 5.35171C4.38589 5.58602 4.38589 5.96592 4.62021 6.20024L9.74078 11.3208C10.3791 11.9591 11.414 11.9591 12.0523 11.3208C12.0523 11.3208 12.0523 11.3208 12.0523 11.3208M12.0523 11.3208C12.6907 10.6825 12.6906 9.64757 12.0523 9.00927L5.95641 2.91333L5.9564 2.91332",fillRule:"evenodd",clipRule:"evenodd"}}]},LinkSingle=React.forwardRef(function(props,ref){return React.createElement(IconBase,Object.assign({},props,{id:"link-single",ref,icon:element$2}))});LinkSingle.displayName="LinkSingle";var element$1={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.5935 3.47302C11.6354 2.51492 10.082 2.51492 9.12388 3.47302L7.83534 4.76157C7.60102 4.99588 7.22112 4.99588 6.98681 4.76157 6.75249 4.52725 6.75249 4.14735 6.98681 3.91304L8.27535 2.62449C9.70209 1.19776 12.0153 1.19776 13.442 2.62449 14.8688 4.05123 14.8688 6.36442 13.442 7.79116L12.1535 9.0797C11.9192 9.31402 11.5393 9.31402 11.3049 9.0797 11.0706 8.84539 11.0706 8.46549 11.3049 8.23117L12.5935 6.94263C13.5516 5.98452 13.5516 4.43113 12.5935 3.47302zM3.40637 12.6606C2.44827 11.7025 2.44827 10.1491 3.40637 9.19102L4.69492 7.90248C4.92923 7.66816 4.92923 7.28826 4.69492 7.05395 4.4606 6.81963 4.0807 6.81963 3.84639 7.05395L2.55784 8.34249C1.13111 9.76923 1.13111 12.0824 2.55784 13.5092 3.98458 14.9359 6.29777 14.9359 7.72451 13.5092L9.01305 12.2206C9.24737 11.9863 9.24737 11.6064 9.01305 11.3721 8.77874 11.1378 8.39884 11.1378 8.16452 11.3721L6.87598 12.6606C5.91787 13.6187 4.36448 13.6187 3.40637 12.6606zM3.5852 2.80332C3.35088 2.569 2.97098 2.569 2.73667 2.80332 2.50235 3.03763 2.50235 3.41753 2.73667 3.65185L12.4151 13.3302C12.6494 13.5646 13.0293 13.5646 13.2636 13.3302 13.4979 13.0959 13.4979 12.716 13.2636 12.4817L3.5852 2.80332z"}}]},UnlinkSingle=React.forwardRef(function(props,ref){return React.createElement(IconBase,Object.assign({},props,{id:"unlink-single",ref,icon:element$1}))});UnlinkSingle.displayName="UnlinkSingle";var element={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.6551 1.98906C11.7476 1.08113 10.2757 1.08149 9.3686 1.98987L4.82542 6.53955C4.75087 6.61421 4.69336 6.70411 4.65682 6.80309L3.2461 10.625C3.16506 10.8446 3.21909 11.0912 3.3845 11.2568C3.54991 11.4224 3.79651 11.4767 4.01616 11.3959L7.85031 9.98517C7.94979 9.94856 8.04014 9.89077 8.11508 9.81579L12.6552 5.27327C13.5618 4.36621 13.5618 2.89607 12.6551 1.98906ZM10.2177 2.83779C10.6562 2.39869 11.3677 2.39851 11.8064 2.8374C12.2447 3.27584 12.2447 3.9865 11.8065 4.42497L7.3392 8.89457L4.82213 9.82068L5.74706 7.31487L10.2177 2.83779Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.79238 13.2999C1.46101 13.2999 1.19238 13.5685 1.19238 13.8999C1.19238 14.2313 1.46101 14.4999 1.79238 14.4999H14.4924C14.8238 14.4999 15.0924 14.2313 15.0924 13.8999C15.0924 13.5685 14.8238 13.2999 14.4924 13.2999H1.79238Z"}}]},WriteSingle=React.forwardRef(function(props,ref){return React.createElement(IconBase,Object.assign({},props,{id:"write-single",ref,icon:element}))});WriteSingle.displayName="WriteSingle";const AddDocHyperLinkCommand={type:core.CommandType.COMMAND,id:"docs.command.add-hyper-link",async handler(accessor,params){if(!params)return!1;const{payload,unitId,selection}=params,commandService=accessor.get(core.ICommandService),id=core.generateRandomId(),doMutation=docsUi.addCustomRangeBySelectionFactory(accessor,{rangeId:id,rangeType:core.CustomRangeType.HYPERLINK,properties:{url:payload},unitId,selection});return doMutation?commandService.syncExecuteCommand(doMutation.id,doMutation.params):!1}},UpdateDocHyperLinkCommand={id:"docs.command.update-hyper-link",type:core.CommandType.COMMAND,handler(accessor,params){var _a7;if(!params)return!1;const{unitId,payload,segmentId}=params,commandService=accessor.get(core.ICommandService),univerInstanceService=accessor.get(core.IUniverInstanceService),currentSelection=accessor.get(docs.DocSelectionManagerService).getActiveTextRange(),doc=univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_DOC);if(!currentSelection||!doc)return!1;const newId=core.generateRandomId(),textRun=(_a7=core.getBodySlice(doc.getSelfOrHeaderFooterModel(segmentId).getBody(),currentSelection.startOffset,currentSelection.endOffset).textRuns)==null?void 0:_a7[0];textRun&&(textRun.ed=params.label.length+1);const replaceSelection=docsUi.replaceSelectionFactory(accessor,{unitId,body:{dataStream:`${core.DataStreamTreeTokenType.CUSTOM_RANGE_START}${params.label}${core.DataStreamTreeTokenType.CUSTOM_RANGE_END}`,customRanges:[{rangeId:newId,rangeType:core.CustomRangeType.HYPERLINK,startIndex:0,endIndex:params.label.length+1,properties:{url:payload}}],textRuns:textRun?[textRun]:void 0},selection:{startOffset:currentSelection.startOffset,endOffset:currentSelection.endOffset,collapsed:!1,segmentId}});return replaceSelection?commandService.syncExecuteCommand(replaceSelection.id,replaceSelection.params):!1}},DeleteDocHyperLinkCommand={type:core.CommandType.COMMAND,id:"docs.command.delete-hyper-link",async handler(accessor,params){if(!params)return!1;const{unitId,linkId,segmentId}=params,commandService=accessor.get(core.ICommandService),doMutation=docsUi.deleteCustomRangeFactory(accessor,{unitId,rangeId:linkId,segmentId});return doMutation?await commandService.syncExecuteCommand(doMutation.id,doMutation.params):!1}},shouldDisableAddLink=__name(accessor=>{var _a7;const textSelectionService=accessor.get(docs.DocSelectionManagerService),univerInstanceService=accessor.get(core.IUniverInstanceService),textRanges=textSelectionService.getDocRanges();if(!textRanges.length||textRanges.length>1)return!0;const activeRange=textRanges[0],doc=univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_DOC);if(!doc||!activeRange||activeRange.collapsed)return!0;const body=doc.getSelfOrHeaderFooterModel(activeRange.segmentId).getBody(),paragraphs=body==null?void 0:body.paragraphs;if(!paragraphs)return!0;for(let i=0,len=paragraphs.length;i<len;i++){const p=paragraphs[i];if(activeRange.startOffset<=p.startIndex&&activeRange.endOffset>p.startIndex)return!0;if(p.startIndex>activeRange.endOffset)break}return!core.BuildTextUtils.customRange.getCustomRangesInterestsWithRange(activeRange,(_a7=body.customRanges)!=null?_a7:[]).every(range=>range.rangeType===core.CustomRangeType.HYPERLINK)},"shouldDisableAddLink"),ShowDocHyperLinkEditPopupOperation={type:core.CommandType.OPERATION,id:"doc.operation.show-hyper-link-edit-popup",handler(accessor,params){var _a7;const linkInfo=params==null?void 0:params.link,univerInstanceService=accessor.get(core.IUniverInstanceService);if(shouldDisableAddLink(accessor)&&!linkInfo)return!1;const hyperLinkService=accessor.get(DocHyperLinkPopupService),unitId=(linkInfo==null?void 0:linkInfo.unitId)||((_a7=univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_DOC))==null?void 0:_a7.getUnitId());return unitId?(hyperLinkService.showEditPopup(unitId,linkInfo),!0):!1}},ToggleDocHyperLinkInfoPopupOperation={type:core.CommandType.OPERATION,id:"doc.operation.toggle-hyper-link-info-popup",handler(accessor,params){const hyperLinkService=accessor.get(DocHyperLinkPopupService);return params?(hyperLinkService.showInfoPopup(params),!0):(hyperLinkService.hideInfoPopup(),!0)}},ClickDocHyperLinkOperation={type:core.CommandType.OPERATION,id:"doc.operation.click-hyper-link",handler(accessor,params){var _a7,_b,_c;if(!params)return!1;const{unitId,linkId,segmentId}=params,doc=accessor.get(core.IUniverInstanceService).getUnit(unitId,core.UniverInstanceType.UNIVER_DOC),body=doc==null?void 0:doc.getSelfOrHeaderFooterModel(segmentId).getBody(),link=(_c=(_b=(_a7=body==null?void 0:body.customRanges)==null?void 0:_a7.find(range=>range.rangeId===linkId&&range.rangeType===core.CustomRangeType.HYPERLINK))==null?void 0:_b.properties)==null?void 0:_c.url;return link&&window.open(link,"_blank","noopener noreferrer"),!0}},docLink="univer-doc-link",docLinkType="univer-doc-link-type",docLinkContent="univer-doc-link-content",docLinkContentError="univer-doc-link-content-error",docLinkUrl="univer-doc-link-url",docLinkOperations="univer-doc-link-operations",docLinkOperation="univer-doc-link-operation",docLinkOperationError="univer-doc-link-operation-error",styles$1={docLink,docLinkType,docLinkContent,docLinkContentError,docLinkUrl,docLinkOperations,docLinkOperation,docLinkOperationError},DocLinkPopup=__name(()=>{var _a7,_b;const hyperLinkService=core.useDependency(DocHyperLinkPopupService),commandService=core.useDependency(core.ICommandService),messageService=core.useDependency(ui.IMessageService),localeService=core.useDependency(core.LocaleService),currentPopup=ui.useObservable(hyperLinkService.showingLink$),univerInstanceService=core.useDependency(core.IUniverInstanceService);if(!currentPopup)return null;const{unitId,linkId,segmentId}=currentPopup,doc=univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_DOC),body=doc==null?void 0:doc.getSelfOrHeaderFooterModel(segmentId).getBody(),link=(_a7=body==null?void 0:body.customRanges)==null?void 0:_a7.find(range=>range.rangeId===linkId&&range.rangeType===core.CustomRangeType.HYPERLINK);if(!link)return null;const url=(_b=link.properties)==null?void 0:_b.url;return React.createElement("div",{className:styles$1.docLink,onClick:__name(()=>{hyperLinkService.hideInfoPopup()},"onClick")},React.createElement("div",{className:cs(styles$1.docLinkContent),onClick:__name(()=>window.open(url),"onClick")},React.createElement("div",{className:styles$1.docLinkType},React.createElement(LinkSingle,null)),React.createElement(design.Tooltip,{showIfEllipsis:!0,title:url},React.createElement("span",{className:styles$1.docLinkUrl},url))),React.createElement("div",{className:styles$1.docLinkOperations},React.createElement("div",{className:cs(styles$1.docLinkOperation),onClick:__name(()=>{navigator.clipboard.writeText(url),messageService.show({content:localeService.t("docLink.info.coped"),type:design.MessageType.Info})},"onClick")},React.createElement(design.Tooltip,{placement:"bottom",title:localeService.t("docLink.info.copy")},React.createElement(CopySingle,null))),React.createElement("div",{className:styles$1.docLinkOperation,onClick:__name(()=>{commandService.executeCommand(ShowDocHyperLinkEditPopupOperation.id,{link:currentPopup})},"onClick")},React.createElement(design.Tooltip,{placement:"bottom",title:localeService.t("docLink.info.edit")},React.createElement(WriteSingle,null))),React.createElement("div",{className:styles$1.docLinkOperation,onClick:__name(()=>{commandService.executeCommand(DeleteDocHyperLinkCommand.id,{unitId,linkId:link.rangeId,segmentId})},"onClick")},React.createElement(design.Tooltip,{placement:"bottom",title:localeService.t("docLink.info.cancel")},React.createElement(UnlinkSingle,null)))))},"DocLinkPopup");DocLinkPopup.componentKey="univer.doc.link-info-popup";var __defProp$5=Object.defineProperty,__getOwnPropDesc$5=Object.getOwnPropertyDescriptor,__decorateClass$5=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$5(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$5(target,key,result),result},"__decorateClass$5"),__decorateParam$5=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$5");const SKIT_PLACEHOLDER=0;var _a;let DocHyperLinkPopupService=(_a=class extends core.Disposable{constructor(_docCanvasPopupManagerService,_textSelectionManagerService,_univerInstanceService){super();__publicField(this,"_editingLink$",new rxjs.BehaviorSubject(null));__publicField(this,"_showingLink$",new rxjs.BehaviorSubject(null));__publicField(this,"editingLink$",this._editingLink$.asObservable());__publicField(this,"showingLink$",this._showingLink$.asObservable());__publicField(this,"_editPopup",null);__publicField(this,"_infoPopup",null);this._docCanvasPopupManagerService=_docCanvasPopupManagerService,this._textSelectionManagerService=_textSelectionManagerService,this._univerInstanceService=_univerInstanceService,this.disposeWithMe(()=>{this._editingLink$.complete(),this._showingLink$.complete()})}get editing(){return this._editingLink$.value}get showing(){return this._showingLink$.value}showEditPopup(unitId,linkInfo){var _a7,_b,_c;this._editPopup&&this._editPopup.dispose(),this._editingLink$.next(linkInfo);let activeRange=this._textSelectionManagerService.getActiveTextRange();if(linkInfo){const{unitId:unitId2,linkId,segmentId,segmentPage}=linkInfo,doc=this._univerInstanceService.getUnit(unitId2,core.UniverInstanceType.UNIVER_DOC),range=(_c=(_b=(_a7=doc==null?void 0:doc.getSelfOrHeaderFooterModel(segmentId))==null?void 0:_a7.getBody())==null?void 0:_b.customRanges)==null?void 0:_c.find(i=>i.rangeId===linkId);range&&(activeRange={collapsed:!1,startOffset:range.startIndex+SKIT_PLACEHOLDER,endOffset:range.endIndex+1,segmentId,segmentPage},this._textSelectionManagerService.replaceTextRanges([{startOffset:range.startIndex,endOffset:range.endIndex+1}]))}return activeRange?(this._editPopup=this._docCanvasPopupManagerService.attachPopupToRange(activeRange,{componentKey:DocHyperLinkEdit.componentKey,direction:"bottom"},unitId),this._editPopup):null}hideEditPopup(){var _a7;this._editingLink$.next(null),(_a7=this._editPopup)==null||_a7.dispose()}showInfoPopup(info){var _a7,_b,_c,_d,_e,_f;const{linkId,unitId,segmentId,segmentPage}=info;if(((_a7=this.showing)==null?void 0:_a7.linkId)===linkId&&((_b=this.showing)==null?void 0:_b.unitId)===unitId&&((_c=this.showing)==null?void 0:_c.segmentId)===segmentId&&((_d=this.showing)==null?void 0:_d.segmentPage)===segmentPage)return;this._infoPopup&&this._infoPopup.dispose();const doc=this._univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_DOC);if(!doc)return;const range=(_f=(_e=doc.getSelfOrHeaderFooterModel(info.segmentId).getBody())==null?void 0:_e.customRanges)==null?void 0:_f.find(i=>i.rangeId===linkId);if(this._showingLink$.next({unitId,linkId,segmentId,segmentPage}),!!range)return this._infoPopup=this._docCanvasPopupManagerService.attachPopupToRange({collapsed:!1,startOffset:range.startIndex+SKIT_PLACEHOLDER,endOffset:range.endIndex+1,segmentId:info.segmentId,segmentPage:info.segmentPage},{componentKey:DocLinkPopup.componentKey,direction:"top-center",multipleDirection:"top",onClickOutside:__name(()=>{this.hideInfoPopup()},"onClickOutside")},info.unitId),this._infoPopup}hideInfoPopup(){var _a7;this._showingLink$.next(null),(_a7=this._infoPopup)==null||_a7.dispose()}},__name(_a,"DocHyperLinkPopupService"),_a);DocHyperLinkPopupService=__decorateClass$5([__decorateParam$5(0,core.Inject(docsUi.DocCanvasPopManagerService)),__decorateParam$5(1,core.Inject(docs.DocSelectionManagerService)),__decorateParam$5(2,core.IUniverInstanceService)],DocHyperLinkPopupService);const docsLinkEdit="univer-docs-link-edit",docsLinkEditTitle="univer-docs-link-edit-title",docsLinkEditClose="univer-docs-link-edit-close",docsLinkEditButtons="univer-docs-link-edit-buttons",docsLinkEditButton="univer-docs-link-edit-button",styles={docsLinkEdit,docsLinkEditTitle,docsLinkEditClose,docsLinkEditButtons,docsLinkEditButton};function hasProtocol(urlString){return/^[a-zA-Z]+:\/\//.test(urlString)}__name(hasProtocol,"hasProtocol");function isEmail(url){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(url)}__name(isEmail,"isEmail");function transformUrl(urlStr){return hasProtocol(urlStr)?urlStr:isEmail(urlStr)?`mailto://${urlStr}`:`https://${urlStr}`}__name(transformUrl,"transformUrl");const DocHyperLinkEdit=__name(()=>{var _a7;const hyperLinkService=core.useDependency(DocHyperLinkPopupService),localeService=core.useDependency(core.LocaleService),editing=core.useObservable(hyperLinkService.editingLink$),commandService=core.useDependency(core.ICommandService),univerInstanceService=core.useDependency(core.IUniverInstanceService),renderManagerService=core.useDependency(engineRender.IRenderManagerService),docSelectionManagerService=core.useDependency(docs.DocSelectionManagerService),[link,setLink]=React.useState(""),[label,setLabel]=React.useState(""),[showError,setShowError]=React.useState(!1),isLegal=core.Tools.isLegalUrl(link),doc=editing?univerInstanceService.getUnit(editing.unitId,core.UniverInstanceType.UNIVER_DOC):univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_DOC),docSelectionRenderService=(_a7=renderManagerService.getRenderById(doc.getUnitId()))==null?void 0:_a7.with(docsUi.DocSelectionRenderService);React.useEffect(()=>{var _a8,_b,_c,_d,_e,_f,_g,_h,_i;const activeRange=docSelectionManagerService.getActiveTextRange();if(!activeRange)return;if(editing){const body=(_a8=doc==null?void 0:doc.getSelfOrHeaderFooterModel(editing.segmentId))==null?void 0:_a8.getBody(),matchedRange2=(_b=body==null?void 0:body.customRanges)==null?void 0:_b.find(i=>(editing==null?void 0:editing.linkId)===i.rangeId);doc&&matchedRange2&&(setLink((_d=(_c=matchedRange2.properties)==null?void 0:_c.url)!=null?_d:""),setLabel(docsUi.getPlainTextFormBody(core.getBodySlice(body,matchedRange2.startIndex,matchedRange2.endIndex))));return}const matchedRange=(_g=(_f=(_e=doc==null?void 0:doc.getSelfOrHeaderFooterModel(activeRange.segmentId))==null?void 0:_e.getBody())==null?void 0:_f.customRanges)==null?void 0:_g.find(i=>Math.max(activeRange.startOffset,i.startIndex)<=Math.min(activeRange.endOffset-1,i.endIndex));doc&&matchedRange&&setLink((_i=(_h=matchedRange==null?void 0:matchedRange.properties)==null?void 0:_h.url)!=null?_i:"")},[doc,editing,docSelectionManagerService,univerInstanceService]),React.useEffect(()=>(docSelectionRenderService&&docSelectionRenderService.blurEditor(),()=>{docSelectionRenderService&&docSelectionRenderService.focusEditor()}),[docSelectionRenderService]);const handleCancel=__name(()=>{hyperLinkService.hideEditPopup()},"handleCancel"),handleConfirm=__name(()=>{if(setShowError(!0),!isLegal||!doc)return;const linkFinal=transformUrl(link);if(!editing)commandService.executeCommand(AddDocHyperLinkCommand.id,{unitId:doc.getUnitId(),payload:linkFinal});else{if(!label)return;commandService.executeCommand(UpdateDocHyperLinkCommand.id,{unitId:doc.getUnitId(),payload:linkFinal,linkId:editing.linkId,label,segmentId:editing.segmentId})}hyperLinkService.hideEditPopup()},"handleConfirm");if(doc)return React.createElement("div",{className:styles.docsLinkEdit},React.createElement("div",null,editing?React.createElement(design.FormLayout,{label:localeService.t("docLink.edit.label"),error:showError&&!label?localeService.t("docLink.edit.labelError"):""},React.createElement(design.Input,{value:label,onChange:setLabel,autoFocus:!0,onKeyDown:__name(evt=>{evt.keyCode===ui.KeyCode.ENTER&&handleConfirm()},"onKeyDown")})):null,React.createElement(design.FormLayout,{label:localeService.t("docLink.edit.address"),error:showError&&!isLegal?localeService.t("docLink.edit.addressError"):""},React.createElement(design.Input,{value:link,onChange:setLink,autoFocus:!0,onKeyDown:__name(evt=>{evt.keyCode===ui.KeyCode.ENTER&&handleConfirm()},"onKeyDown")}))),React.createElement("div",{className:styles.docsLinkEditButtons},React.createElement(design.Button,{className:styles.docsLinkEditButton,onClick:handleCancel},localeService.t("docLink.edit.cancel")),React.createElement(design.Button,{disabled:!link,className:styles.docsLinkEditButton,type:"primary",onClick:handleConfirm},localeService.t("docLink.edit.confirm"))))},"DocHyperLinkEdit");DocHyperLinkEdit.componentKey="docs-hyper-link-edit";const DOC_LINK_ICON="doc-hyper-link-icon";function AddHyperLinkMenuItemFactory(accessor){return{id:ShowDocHyperLinkEditPopupOperation.id,type:ui.MenuItemType.BUTTON,icon:DOC_LINK_ICON,title:"docLink.menu.tooltip",tooltip:"docLink.menu.tooltip",hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_DOC),disabled$:new rxjs.Observable(function(subscribe){const observer=accessor.get(docs.DocSelectionManagerService).textSelection$.pipe(rxjs.debounceTime(16)).subscribe(()=>{subscribe.next(shouldDisableAddLink(accessor))});return()=>{observer.unsubscribe()}})}}__name(AddHyperLinkMenuItemFactory,"AddHyperLinkMenuItemFactory");const addLinkShortcut={id:ShowDocHyperLinkEditPopupOperation.id,binding:ui.MetaKeys.CTRL_COMMAND|ui.KeyCode.K,description:"docLink.menu.tooltip",preconditions:docsUi.whenDocAndEditorFocused},menuSchema={[ui.RibbonStartGroup.OTHERS]:{[ShowDocHyperLinkEditPopupOperation.id]:{order:0,menuItemFactory:AddHyperLinkMenuItemFactory}},[ui.ContextMenuPosition.MAIN_AREA]:{[ui.ContextMenuGroup.DATA]:{[ShowDocHyperLinkEditPopupOperation.id]:{order:0,menuItemFactory:AddHyperLinkMenuItemFactory}}}};var __defProp$4=Object.defineProperty,__getOwnPropDesc$4=Object.getOwnPropertyDescriptor,__decorateClass$4=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$4(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$4(target,key,result),result},"__decorateClass$4"),__decorateParam$4=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$4"),_a2;let DocHyperLinkUIController=(_a2=class extends core.Disposable{constructor(_componentManager,_commandService,_menuManagerService,_injector,_shortcutService){super(),this._componentManager=_componentManager,this._commandService=_commandService,this._menuManagerService=_menuManagerService,this._injector=_injector,this._shortcutService=_shortcutService,this._initComponents(),this._initCommands(),this._initMenus(),this._initShortcut()}_initComponents(){[[DocHyperLinkEdit,DocHyperLinkEdit.componentKey],[DocLinkPopup,DocLinkPopup.componentKey],[LinkSingle,DOC_LINK_ICON]].forEach(([comp,key])=>{this._componentManager.register(key,comp)})}_initCommands(){[AddDocHyperLinkCommand,UpdateDocHyperLinkCommand,DeleteDocHyperLinkCommand,ShowDocHyperLinkEditPopupOperation,ToggleDocHyperLinkInfoPopupOperation,ClickDocHyperLinkOperation].forEach(command=>{this._commandService.registerCommand(command)})}_initShortcut(){[addLinkShortcut].forEach(shortcut=>{this._shortcutService.registerShortcut(shortcut)})}_initMenus(){this._menuManagerService.mergeMenu(menuSchema)}},__name(_a2,"DocHyperLinkUIController"),_a2);DocHyperLinkUIController=__decorateClass$4([core.OnLifecycle(core.LifecycleStages.Starting,DocHyperLinkUIController),__decorateParam$4(0,core.Inject(ui.ComponentManager)),__decorateParam$4(1,core.ICommandService),__decorateParam$4(2,ui.IMenuManagerService),__decorateParam$4(3,core.Inject(core.Injector)),__decorateParam$4(4,ui.IShortcutService)],DocHyperLinkUIController);var __defProp$3=Object.defineProperty,__getOwnPropDesc$3=Object.getOwnPropertyDescriptor,__decorateClass$3=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$3(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$3(target,key,result),result},"__decorateClass$3"),__decorateParam$3=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$3"),_a3;let DocHyperLinkSelectionController=(_a3=class extends core.Disposable{constructor(_commandService,_univerInstanceService,_docHyperLinkService){super(),this._commandService=_commandService,this._univerInstanceService=_univerInstanceService,this._docHyperLinkService=_docHyperLinkService,this._initSelectionChange()}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(commandInfo=>{var _a7,_b,_c;if(commandInfo.id===docs.SetTextSelectionsOperation.id){const params=commandInfo.params,{unitId,ranges,segmentId}=params,doc=this._univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_DOC),primary=ranges[0];if(primary&&doc){const{startOffset,endOffset,collapsed,segmentPage}=primary,customRanges=(_b=(_a7=doc.getSelfOrHeaderFooterModel(segmentId))==null?void 0:_a7.getBody())==null?void 0:_b.customRanges;if(collapsed){const index=(_c=customRanges==null?void 0:customRanges.findIndex(value=>value.startIndex<startOffset&&value.endIndex>endOffset-1))!=null?_c:-1;if(index>-1){const customRange=customRanges[index];this._docHyperLinkService.showInfoPopup({unitId,linkId:customRange.rangeId,segmentId,segmentPage});return}}else if(customRanges==null?void 0:customRanges.find(value=>value.startIndex<=startOffset&&value.endIndex>=endOffset-1))return}this._docHyperLinkService.hideInfoPopup(),this._docHyperLinkService.hideEditPopup()}}))}},__name(_a3,"DocHyperLinkSelectionController"),_a3);DocHyperLinkSelectionController=__decorateClass$3([core.OnLifecycle(core.LifecycleStages.Ready,DocHyperLinkSelectionController),__decorateParam$3(0,core.ICommandService),__decorateParam$3(1,core.IUniverInstanceService),__decorateParam$3(2,core.Inject(DocHyperLinkPopupService))],DocHyperLinkSelectionController);var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2"),_a4;let DocHyperLinkRenderController=(_a4=class extends core.Disposable{constructor(_context,_docInterceptorService,_hyperLinkService,_docRenderController){super(),this._context=_context,this._docInterceptorService=_docInterceptorService,this._hyperLinkService=_hyperLinkService,this._docRenderController=_docRenderController,this._init(),this._initReRender()}_init(){this._docInterceptorService.intercept(docs.DOC_INTERCEPTOR_POINT.CUSTOM_RANGE,{handler:__name((data,pos,next)=>{if(!data)return next(data);const{unitId}=pos,activeLink=this._hyperLinkService.showing,{linkId,unitId:linkUnitId}=activeLink||{},isActive=linkUnitId===unitId&&data.rangeId===linkId;return next({...data,active:isActive})},"handler")})}_initReRender(){this.disposeWithMe(this._hyperLinkService.showingLink$.pipe(rxjs.distinctUntilChanged((prev,aft)=>(prev==null?void 0:prev.linkId)===(aft==null?void 0:aft.linkId)&&(prev==null?void 0:prev.unitId)===(aft==null?void 0:aft.unitId)),rxjs.pairwise()).subscribe(([preLink,link])=>{link?link.unitId===this._context.unitId&&this._docRenderController.reRender(link.unitId):preLink&&preLink.unitId===this._context.unitId&&this._docRenderController.reRender(preLink.unitId)}))}},__name(_a4,"DocHyperLinkRenderController"),_a4);DocHyperLinkRenderController=__decorateClass$2([__decorateParam$2(1,core.Inject(docs.DocInterceptorService)),__decorateParam$2(2,core.Inject(DocHyperLinkPopupService)),__decorateParam$2(3,core.Inject(docsUi.DocRenderController))],DocHyperLinkRenderController);var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1"),_a5;let DocHyperLinkEventRenderController=(_a5=class extends core.Disposable{constructor(_context,_docEventManagerService,_commandService,_hyperLinkPopupService,_docSkeletonManagerService,_docSelectionManagerService){super(),this._context=_context,this._docEventManagerService=_docEventManagerService,this._commandService=_commandService,this._hyperLinkPopupService=_hyperLinkPopupService,this._docSkeletonManagerService=_docSkeletonManagerService,this._docSelectionManagerService=_docSelectionManagerService,this._initHover(),this._initClick()}get _skeleton(){return this._docSkeletonManagerService.getSkeleton()}_hideInfoPopup(){this._hyperLinkPopupService.showing&&this._commandService.executeCommand(ToggleDocHyperLinkInfoPopupOperation.id)}_initHover(){this.disposeWithMe(this._docEventManagerService.hoverCustomRanges$.subscribe(ranges=>{var _a7;const link=ranges.find(range=>range.range.rangeType===core.CustomRangeType.HYPERLINK),activeRanges=this._docSelectionManagerService.getCurrentTextRanges(),currentSegmentId=activeRanges==null?void 0:activeRanges[0].segmentId;if(((_a7=link==null?void 0:link.segmentId)!=null?_a7:"")!==currentSegmentId){this._hideInfoPopup();return}link?this._commandService.executeCommand(ToggleDocHyperLinkInfoPopupOperation.id,{unitId:this._context.unitId,linkId:link.range.rangeId,segmentId:link.segmentId,segmentPage:link.segmentPageIndex,rangeId:link.range.rangeId}):this._hideInfoPopup()}))}_initClick(){this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe(range=>{const link=range.range;link&&this._commandService.executeCommand(ClickDocHyperLinkOperation.id,{unitId:this._context.unitId,linkId:link.rangeId,segmentId:range.segmentId})}))}},__name(_a5,"DocHyperLinkEventRenderController"),_a5);DocHyperLinkEventRenderController=__decorateClass$1([__decorateParam$1(1,core.Inject(docsUi.DocEventManagerService)),__decorateParam$1(2,core.ICommandService),__decorateParam$1(3,core.Inject(DocHyperLinkPopupService)),__decorateParam$1(4,core.Inject(docs.DocSkeletonManagerService)),__decorateParam$1(5,core.Inject(docs.DocSelectionManagerService))],DocHyperLinkEventRenderController);const PLUGIN_CONFIG_KEY="docs-hyper-link-ui.config",defaultPluginConfig={};var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key,value)=>key in obj?__defProp2(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),__publicField2=__name((obj,key,value)=>__defNormalProp2(obj,typeof key!="symbol"?key+"":key,value),"__publicField"),_a6;exports.UniverDocsHyperLinkUIPlugin=(_a6=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_renderManagerSrv,_configService){super(),this._config=_config,this._injector=_injector,this._renderManagerSrv=_renderManagerSrv,this._configService=_configService;const{menu,...rest}=this._config;menu&&this._configService.setConfig("menu",menu,{merge:!0}),this._configService.setConfig(PLUGIN_CONFIG_KEY,rest)}onStarting(){[[DocHyperLinkPopupService],[DocHyperLinkUIController],[DocHyperLinkSelectionController]].forEach(dep=>{this._injector.add(dep)})}onRendered(){this._initRenderModule()}_initRenderModule(){[[DocHyperLinkRenderController],[DocHyperLinkEventRenderController]].forEach(dep=>{this._renderManagerSrv.registerRenderModule(core.UniverInstanceType.UNIVER_DOC,dep)})}},__name(_a6,"UniverDocsHyperLinkUIPlugin"),_a6);__publicField2(exports.UniverDocsHyperLinkUIPlugin,"pluginName",DOC_HYPER_LINK_UI_PLUGIN);__publicField2(exports.UniverDocsHyperLinkUIPlugin,"type",core.UniverInstanceType.UNIVER_DOC);exports.UniverDocsHyperLinkUIPlugin=__decorateClass([core.DependentOn(docsHyperLink.UniverDocsHyperLinkPlugin),__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,engineRender.IRenderManagerService),__decorateParam(3,core.IConfigService)],exports.UniverDocsHyperLinkUIPlugin);
|
package/lib/es/index.js
CHANGED
|
@@ -2,14 +2,14 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
|
|
3
3
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
|
4
4
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
5
|
-
import { CommandType, ICommandService, IUniverInstanceService, UniverInstanceType,
|
|
6
|
-
import {
|
|
5
|
+
import { CommandType, ICommandService, generateRandomId, CustomRangeType, IUniverInstanceService, UniverInstanceType, getBodySlice, DataStreamTreeTokenType, BuildTextUtils, useDependency, LocaleService, Disposable, Inject, useObservable as useObservable$1, Tools, OnLifecycle, LifecycleStages, Injector, DependentOn, Plugin, IConfigService } from "@univerjs/core";
|
|
6
|
+
import { IRenderManagerService } from "@univerjs/engine-render";
|
|
7
7
|
import { UniverDocsHyperLinkPlugin } from "@univerjs/docs-hyper-link";
|
|
8
8
|
import { IMessageService, useObservable, KeyCode, MetaKeys, MenuItemType, getMenuHiddenObservable, RibbonStartGroup, ContextMenuPosition, ContextMenuGroup, ComponentManager, IMenuManagerService, IShortcutService } from "@univerjs/ui";
|
|
9
9
|
import { Tooltip, MessageType, FormLayout, Input, Button } from "@univerjs/design";
|
|
10
|
+
import { DocSelectionManagerService, SetTextSelectionsOperation, DocInterceptorService, DOC_INTERCEPTOR_POINT, DocSkeletonManagerService } from "@univerjs/docs";
|
|
11
|
+
import { addCustomRangeBySelectionFactory, replaceSelectionFactory, deleteCustomRangeFactory, DocCanvasPopManagerService, DocSelectionRenderService, getPlainTextFormBody, whenDocAndEditorFocused, DocRenderController, DocEventManagerService } from "@univerjs/docs-ui";
|
|
10
12
|
import React, { forwardRef, useRef, createElement, useState, useEffect } from "react";
|
|
11
|
-
import { deleteCustomRangeFactory, TextSelectionManagerService, getCustomRangesInterestsWithRange, addCustomRangeBySelectionFactory, replaceSelectionFactory, getPlainTextFormBody, SetTextSelectionsOperation, DocInterceptorService, DOC_INTERCEPTOR_POINT, DocSkeletonManagerService } from "@univerjs/docs";
|
|
12
|
-
import { DocCanvasPopManagerService, whenDocAndEditorFocused, DocRenderController, DocEventManagerService } from "@univerjs/docs-ui";
|
|
13
13
|
import { BehaviorSubject, Observable, debounceTime, distinctUntilChanged, pairwise } from "rxjs";
|
|
14
14
|
import cs from "clsx";
|
|
15
15
|
const DOC_HYPER_LINK_UI_PLUGIN = "DOC_HYPER_LINK_UI_PLUGIN";
|
|
@@ -92,7 +92,63 @@ var element = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 17 16", width:
|
|
|
92
92
|
}));
|
|
93
93
|
});
|
|
94
94
|
WriteSingle.displayName = "WriteSingle";
|
|
95
|
-
const
|
|
95
|
+
const AddDocHyperLinkCommand = {
|
|
96
|
+
type: CommandType.COMMAND,
|
|
97
|
+
id: "docs.command.add-hyper-link",
|
|
98
|
+
async handler(accessor, params) {
|
|
99
|
+
if (!params)
|
|
100
|
+
return !1;
|
|
101
|
+
const { payload, unitId, selection } = params, commandService = accessor.get(ICommandService), id = generateRandomId(), doMutation = addCustomRangeBySelectionFactory(
|
|
102
|
+
accessor,
|
|
103
|
+
{
|
|
104
|
+
rangeId: id,
|
|
105
|
+
rangeType: CustomRangeType.HYPERLINK,
|
|
106
|
+
properties: {
|
|
107
|
+
url: payload
|
|
108
|
+
},
|
|
109
|
+
unitId,
|
|
110
|
+
selection
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
return doMutation ? commandService.syncExecuteCommand(doMutation.id, doMutation.params) : !1;
|
|
114
|
+
}
|
|
115
|
+
}, UpdateDocHyperLinkCommand = {
|
|
116
|
+
id: "docs.command.update-hyper-link",
|
|
117
|
+
type: CommandType.COMMAND,
|
|
118
|
+
handler(accessor, params) {
|
|
119
|
+
var _a7;
|
|
120
|
+
if (!params)
|
|
121
|
+
return !1;
|
|
122
|
+
const { unitId, payload, segmentId } = params, commandService = accessor.get(ICommandService), univerInstanceService = accessor.get(IUniverInstanceService), currentSelection = accessor.get(DocSelectionManagerService).getActiveTextRange(), doc = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
123
|
+
if (!currentSelection || !doc)
|
|
124
|
+
return !1;
|
|
125
|
+
const newId = generateRandomId(), textRun = (_a7 = getBodySlice(doc.getSelfOrHeaderFooterModel(segmentId).getBody(), currentSelection.startOffset, currentSelection.endOffset).textRuns) == null ? void 0 : _a7[0];
|
|
126
|
+
textRun && (textRun.ed = params.label.length + 1);
|
|
127
|
+
const replaceSelection = replaceSelectionFactory(accessor, {
|
|
128
|
+
unitId,
|
|
129
|
+
body: {
|
|
130
|
+
dataStream: `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${params.label}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`,
|
|
131
|
+
customRanges: [{
|
|
132
|
+
rangeId: newId,
|
|
133
|
+
rangeType: CustomRangeType.HYPERLINK,
|
|
134
|
+
startIndex: 0,
|
|
135
|
+
endIndex: params.label.length + 1,
|
|
136
|
+
properties: {
|
|
137
|
+
url: payload
|
|
138
|
+
}
|
|
139
|
+
}],
|
|
140
|
+
textRuns: textRun ? [textRun] : void 0
|
|
141
|
+
},
|
|
142
|
+
selection: {
|
|
143
|
+
startOffset: currentSelection.startOffset,
|
|
144
|
+
endOffset: currentSelection.endOffset,
|
|
145
|
+
collapsed: !1,
|
|
146
|
+
segmentId
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
return replaceSelection ? commandService.syncExecuteCommand(replaceSelection.id, replaceSelection.params) : !1;
|
|
150
|
+
}
|
|
151
|
+
}, DeleteDocHyperLinkCommand = {
|
|
96
152
|
type: CommandType.COMMAND,
|
|
97
153
|
id: "docs.command.delete-hyper-link",
|
|
98
154
|
async handler(accessor, params) {
|
|
@@ -103,7 +159,7 @@ const DeleteDocHyperLinkCommand = {
|
|
|
103
159
|
}
|
|
104
160
|
}, shouldDisableAddLink = /* @__PURE__ */ __name((accessor) => {
|
|
105
161
|
var _a7;
|
|
106
|
-
const textSelectionService = accessor.get(
|
|
162
|
+
const textSelectionService = accessor.get(DocSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), textRanges = textSelectionService.getDocRanges();
|
|
107
163
|
if (!textRanges.length || textRanges.length > 1)
|
|
108
164
|
return !0;
|
|
109
165
|
const activeRange = textRanges[0], doc = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
|
|
@@ -119,7 +175,7 @@ const DeleteDocHyperLinkCommand = {
|
|
|
119
175
|
if (p.startIndex > activeRange.endOffset)
|
|
120
176
|
break;
|
|
121
177
|
}
|
|
122
|
-
return !getCustomRangesInterestsWithRange(activeRange, (_a7 = body.customRanges) != null ? _a7 : []).every((range) => range.rangeType === CustomRangeType.HYPERLINK);
|
|
178
|
+
return !BuildTextUtils.customRange.getCustomRangesInterestsWithRange(activeRange, (_a7 = body.customRanges) != null ? _a7 : []).every((range) => range.rangeType === CustomRangeType.HYPERLINK);
|
|
123
179
|
}, "shouldDisableAddLink"), ShowDocHyperLinkEditPopupOperation = {
|
|
124
180
|
type: CommandType.OPERATION,
|
|
125
181
|
id: "doc.operation.show-hyper-link-edit-popup",
|
|
@@ -244,7 +300,7 @@ let DocHyperLinkPopupService = (_a = class extends Disposable {
|
|
|
244
300
|
showEditPopup(unitId, linkInfo) {
|
|
245
301
|
var _a7, _b, _c;
|
|
246
302
|
this._editPopup && this._editPopup.dispose(), this._editingLink$.next(linkInfo);
|
|
247
|
-
let activeRange = this._textSelectionManagerService.
|
|
303
|
+
let activeRange = this._textSelectionManagerService.getActiveTextRange();
|
|
248
304
|
if (linkInfo) {
|
|
249
305
|
const { unitId: unitId2, linkId, segmentId, segmentPage } = linkInfo, doc = this._univerInstanceService.getUnit(unitId2, UniverInstanceType.UNIVER_DOC), range = (_c = (_b = (_a7 = doc == null ? void 0 : doc.getSelfOrHeaderFooterModel(segmentId)) == null ? void 0 : _a7.getBody()) == null ? void 0 : _b.customRanges) == null ? void 0 : _c.find((i) => i.rangeId === linkId);
|
|
250
306
|
range && (activeRange = {
|
|
@@ -294,7 +350,6 @@ let DocHyperLinkPopupService = (_a = class extends Disposable {
|
|
|
294
350
|
componentKey: DocLinkPopup.componentKey,
|
|
295
351
|
direction: "top-center",
|
|
296
352
|
multipleDirection: "top",
|
|
297
|
-
closeOnSelfTarget: !0,
|
|
298
353
|
onClickOutside: /* @__PURE__ */ __name(() => {
|
|
299
354
|
this.hideInfoPopup();
|
|
300
355
|
}, "onClickOutside")
|
|
@@ -309,60 +364,10 @@ let DocHyperLinkPopupService = (_a = class extends Disposable {
|
|
|
309
364
|
}, __name(_a, "DocHyperLinkPopupService"), _a);
|
|
310
365
|
DocHyperLinkPopupService = __decorateClass$5([
|
|
311
366
|
__decorateParam$5(0, Inject(DocCanvasPopManagerService)),
|
|
312
|
-
__decorateParam$5(1, Inject(
|
|
367
|
+
__decorateParam$5(1, Inject(DocSelectionManagerService)),
|
|
313
368
|
__decorateParam$5(2, IUniverInstanceService)
|
|
314
369
|
], DocHyperLinkPopupService);
|
|
315
|
-
const
|
|
316
|
-
type: CommandType.COMMAND,
|
|
317
|
-
id: "docs.command.add-hyper-link",
|
|
318
|
-
async handler(accessor, params) {
|
|
319
|
-
if (!params)
|
|
320
|
-
return !1;
|
|
321
|
-
const { payload, unitId } = params, commandService = accessor.get(ICommandService), id = generateRandomId(), doMutation = addCustomRangeBySelectionFactory(
|
|
322
|
-
accessor,
|
|
323
|
-
{
|
|
324
|
-
rangeId: id,
|
|
325
|
-
rangeType: CustomRangeType.HYPERLINK,
|
|
326
|
-
properties: {
|
|
327
|
-
url: payload
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
);
|
|
331
|
-
return doMutation ? commandService.syncExecuteCommand(doMutation.id, doMutation.params) : !1;
|
|
332
|
-
}
|
|
333
|
-
}, UpdateDocHyperLinkCommand = {
|
|
334
|
-
id: "docs.command.update-hyper-link",
|
|
335
|
-
type: CommandType.COMMAND,
|
|
336
|
-
handler(accessor, params) {
|
|
337
|
-
if (!params)
|
|
338
|
-
return !1;
|
|
339
|
-
const { unitId, payload, segmentId } = params, commandService = accessor.get(ICommandService), currentSelection = accessor.get(TextSelectionManagerService).getActiveTextRange();
|
|
340
|
-
if (!currentSelection)
|
|
341
|
-
return !1;
|
|
342
|
-
const newId = generateRandomId(), replaceSelection = replaceSelectionFactory(accessor, {
|
|
343
|
-
unitId,
|
|
344
|
-
body: {
|
|
345
|
-
dataStream: `${DataStreamTreeTokenType.CUSTOM_RANGE_START}${params.label}${DataStreamTreeTokenType.CUSTOM_RANGE_END}`,
|
|
346
|
-
customRanges: [{
|
|
347
|
-
rangeId: newId,
|
|
348
|
-
rangeType: CustomRangeType.HYPERLINK,
|
|
349
|
-
startIndex: 0,
|
|
350
|
-
endIndex: params.label.length + 1,
|
|
351
|
-
properties: {
|
|
352
|
-
url: payload
|
|
353
|
-
}
|
|
354
|
-
}]
|
|
355
|
-
},
|
|
356
|
-
selection: {
|
|
357
|
-
startOffset: currentSelection.startOffset,
|
|
358
|
-
endOffset: currentSelection.endOffset,
|
|
359
|
-
collapsed: !1,
|
|
360
|
-
segmentId
|
|
361
|
-
}
|
|
362
|
-
});
|
|
363
|
-
return replaceSelection ? commandService.syncExecuteCommand(replaceSelection.id, replaceSelection.params) : !1;
|
|
364
|
-
}
|
|
365
|
-
}, docsLinkEdit = "univer-docs-link-edit", docsLinkEditTitle = "univer-docs-link-edit-title", docsLinkEditClose = "univer-docs-link-edit-close", docsLinkEditButtons = "univer-docs-link-edit-buttons", docsLinkEditButton = "univer-docs-link-edit-button", styles = {
|
|
370
|
+
const docsLinkEdit = "univer-docs-link-edit", docsLinkEditTitle = "univer-docs-link-edit-title", docsLinkEditClose = "univer-docs-link-edit-close", docsLinkEditButtons = "univer-docs-link-edit-buttons", docsLinkEditButton = "univer-docs-link-edit-button", styles = {
|
|
366
371
|
docsLinkEdit,
|
|
367
372
|
docsLinkEditTitle,
|
|
368
373
|
docsLinkEditClose,
|
|
@@ -382,22 +387,23 @@ function transformUrl(urlStr) {
|
|
|
382
387
|
}
|
|
383
388
|
__name(transformUrl, "transformUrl");
|
|
384
389
|
const DocHyperLinkEdit = /* @__PURE__ */ __name(() => {
|
|
385
|
-
|
|
390
|
+
var _a7;
|
|
391
|
+
const hyperLinkService = useDependency(DocHyperLinkPopupService), localeService = useDependency(LocaleService), editing = useObservable$1(hyperLinkService.editingLink$), commandService = useDependency(ICommandService), univerInstanceService = useDependency(IUniverInstanceService), renderManagerService = useDependency(IRenderManagerService), docSelectionManagerService = useDependency(DocSelectionManagerService), [link, setLink] = useState(""), [label, setLabel] = useState(""), [showError, setShowError] = useState(!1), isLegal = Tools.isLegalUrl(link), doc = editing ? univerInstanceService.getUnit(editing.unitId, UniverInstanceType.UNIVER_DOC) : univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC), docSelectionRenderService = (_a7 = renderManagerService.getRenderById(doc.getUnitId())) == null ? void 0 : _a7.with(DocSelectionRenderService);
|
|
386
392
|
useEffect(() => {
|
|
387
|
-
var
|
|
388
|
-
const activeRange =
|
|
393
|
+
var _a8, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
394
|
+
const activeRange = docSelectionManagerService.getActiveTextRange();
|
|
389
395
|
if (!activeRange)
|
|
390
396
|
return;
|
|
391
397
|
if (editing) {
|
|
392
|
-
const body = (
|
|
398
|
+
const body = (_a8 = doc == null ? void 0 : doc.getSelfOrHeaderFooterModel(editing.segmentId)) == null ? void 0 : _a8.getBody(), matchedRange2 = (_b = body == null ? void 0 : body.customRanges) == null ? void 0 : _b.find((i) => (editing == null ? void 0 : editing.linkId) === i.rangeId);
|
|
393
399
|
doc && matchedRange2 && (setLink((_d = (_c = matchedRange2.properties) == null ? void 0 : _c.url) != null ? _d : ""), setLabel(getPlainTextFormBody(getBodySlice(body, matchedRange2.startIndex, matchedRange2.endIndex))));
|
|
394
400
|
return;
|
|
395
401
|
}
|
|
396
402
|
const matchedRange = (_g = (_f = (_e = doc == null ? void 0 : doc.getSelfOrHeaderFooterModel(activeRange.segmentId)) == null ? void 0 : _e.getBody()) == null ? void 0 : _f.customRanges) == null ? void 0 : _g.find((i) => Math.max(activeRange.startOffset, i.startIndex) <= Math.min(activeRange.endOffset - 1, i.endIndex));
|
|
397
403
|
doc && matchedRange && setLink((_i = (_h = matchedRange == null ? void 0 : matchedRange.properties) == null ? void 0 : _h.url) != null ? _i : "");
|
|
398
|
-
}, [doc, editing,
|
|
399
|
-
|
|
400
|
-
}), [
|
|
404
|
+
}, [doc, editing, docSelectionManagerService, univerInstanceService]), useEffect(() => (docSelectionRenderService && docSelectionRenderService.blurEditor(), () => {
|
|
405
|
+
docSelectionRenderService && docSelectionRenderService.focusEditor();
|
|
406
|
+
}), [docSelectionRenderService]);
|
|
401
407
|
const handleCancel = /* @__PURE__ */ __name(() => {
|
|
402
408
|
hyperLinkService.hideEditPopup();
|
|
403
409
|
}, "handleCancel"), handleConfirm = /* @__PURE__ */ __name(() => {
|
|
@@ -486,7 +492,7 @@ function AddHyperLinkMenuItemFactory(accessor) {
|
|
|
486
492
|
tooltip: "docLink.menu.tooltip",
|
|
487
493
|
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.UNIVER_DOC),
|
|
488
494
|
disabled$: new Observable(function(subscribe) {
|
|
489
|
-
const observer = accessor.get(
|
|
495
|
+
const observer = accessor.get(DocSelectionManagerService).textSelection$.pipe(debounceTime(16)).subscribe(() => {
|
|
490
496
|
subscribe.next(shouldDisableAddLink(accessor));
|
|
491
497
|
});
|
|
492
498
|
return () => {
|
|
@@ -645,8 +651,8 @@ var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPrope
|
|
|
645
651
|
return kind && result && __defProp$1(target, key, result), result;
|
|
646
652
|
}, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1"), _a5;
|
|
647
653
|
let DocHyperLinkEventRenderController = (_a5 = class extends Disposable {
|
|
648
|
-
constructor(_context, _docEventManagerService, _commandService, _hyperLinkPopupService, _docSkeletonManagerService,
|
|
649
|
-
super(), this._context = _context, this._docEventManagerService = _docEventManagerService, this._commandService = _commandService, this._hyperLinkPopupService = _hyperLinkPopupService, this._docSkeletonManagerService = _docSkeletonManagerService, this.
|
|
654
|
+
constructor(_context, _docEventManagerService, _commandService, _hyperLinkPopupService, _docSkeletonManagerService, _docSelectionManagerService) {
|
|
655
|
+
super(), this._context = _context, this._docEventManagerService = _docEventManagerService, this._commandService = _commandService, this._hyperLinkPopupService = _hyperLinkPopupService, this._docSkeletonManagerService = _docSkeletonManagerService, this._docSelectionManagerService = _docSelectionManagerService, this._initHover(), this._initClick();
|
|
650
656
|
}
|
|
651
657
|
get _skeleton() {
|
|
652
658
|
return this._docSkeletonManagerService.getSkeleton();
|
|
@@ -660,7 +666,7 @@ let DocHyperLinkEventRenderController = (_a5 = class extends Disposable {
|
|
|
660
666
|
this.disposeWithMe(
|
|
661
667
|
this._docEventManagerService.hoverCustomRanges$.subscribe((ranges) => {
|
|
662
668
|
var _a7;
|
|
663
|
-
const link = ranges.find((range) => range.range.rangeType === CustomRangeType.HYPERLINK), activeRanges = this.
|
|
669
|
+
const link = ranges.find((range) => range.range.rangeType === CustomRangeType.HYPERLINK), activeRanges = this._docSelectionManagerService.getCurrentTextRanges(), currentSegmentId = activeRanges == null ? void 0 : activeRanges[0].segmentId;
|
|
664
670
|
if (((_a7 = link == null ? void 0 : link.segmentId) != null ? _a7 : "") !== currentSegmentId) {
|
|
665
671
|
this._hideInfoPopup();
|
|
666
672
|
return;
|
|
@@ -699,7 +705,7 @@ DocHyperLinkEventRenderController = __decorateClass$1([
|
|
|
699
705
|
__decorateParam$1(2, ICommandService),
|
|
700
706
|
__decorateParam$1(3, Inject(DocHyperLinkPopupService)),
|
|
701
707
|
__decorateParam$1(4, Inject(DocSkeletonManagerService)),
|
|
702
|
-
__decorateParam$1(5, Inject(
|
|
708
|
+
__decorateParam$1(5, Inject(DocSelectionManagerService))
|
|
703
709
|
], DocHyperLinkEventRenderController);
|
|
704
710
|
const PLUGIN_CONFIG_KEY = "docs-hyper-link-ui.config", defaultPluginConfig = {};
|
|
705
711
|
var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __defNormalProp2 = /* @__PURE__ */ __name((obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value, "__defNormalProp"), __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { ICommand } from '@univerjs/core';
|
|
1
|
+
import { ICommand, ITextRangeParam } from '@univerjs/core';
|
|
2
2
|
export interface IAddDocHyperLinkCommandParams {
|
|
3
3
|
payload: string;
|
|
4
4
|
unitId: string;
|
|
5
|
+
selection?: ITextRangeParam;
|
|
5
6
|
}
|
|
6
7
|
export declare const AddDocHyperLinkCommand: ICommand<IAddDocHyperLinkCommandParams>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Disposable, ICommandService, DocumentDataModel } from '@univerjs/core';
|
|
2
|
+
import { DocSelectionManagerService, DocSkeletonManagerService } from '@univerjs/docs';
|
|
2
3
|
import { DocEventManagerService } from '@univerjs/docs-ui';
|
|
3
4
|
import { IRenderContext, IRenderModule } from '@univerjs/engine-render';
|
|
4
|
-
import { DocSkeletonManagerService, TextSelectionManagerService } from '@univerjs/docs';
|
|
5
5
|
import { DocHyperLinkPopupService } from '../../services/hyper-link-popup.service';
|
|
6
6
|
export declare class DocHyperLinkEventRenderController extends Disposable implements IRenderModule {
|
|
7
7
|
private readonly _context;
|
|
@@ -9,9 +9,9 @@ export declare class DocHyperLinkEventRenderController extends Disposable implem
|
|
|
9
9
|
private readonly _commandService;
|
|
10
10
|
private readonly _hyperLinkPopupService;
|
|
11
11
|
private readonly _docSkeletonManagerService;
|
|
12
|
-
private readonly
|
|
12
|
+
private readonly _docSelectionManagerService;
|
|
13
13
|
get _skeleton(): import('@univerjs/engine-render').DocumentSkeleton;
|
|
14
|
-
constructor(_context: IRenderContext<DocumentDataModel>, _docEventManagerService: DocEventManagerService, _commandService: ICommandService, _hyperLinkPopupService: DocHyperLinkPopupService, _docSkeletonManagerService: DocSkeletonManagerService,
|
|
14
|
+
constructor(_context: IRenderContext<DocumentDataModel>, _docEventManagerService: DocEventManagerService, _commandService: ICommandService, _hyperLinkPopupService: DocHyperLinkPopupService, _docSkeletonManagerService: DocSkeletonManagerService, _docSelectionManagerService: DocSelectionManagerService);
|
|
15
15
|
private _hideInfoPopup;
|
|
16
16
|
private _initHover;
|
|
17
17
|
private _initClick;
|
package/lib/types/plugin.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export declare class UniverDocsHyperLinkUIPlugin extends Plugin {
|
|
|
8
8
|
private readonly _configService;
|
|
9
9
|
static pluginName: string;
|
|
10
10
|
static type: UniverInstanceType;
|
|
11
|
-
constructor(_config: Partial<IUniverDocsHyperLinkUIConfig
|
|
11
|
+
constructor(_config: Partial<IUniverDocsHyperLinkUIConfig> | undefined, _injector: Injector, _renderManagerSrv: IRenderManagerService, _configService: IConfigService);
|
|
12
12
|
onStarting(): void;
|
|
13
13
|
onRendered(): void;
|
|
14
14
|
private _initRenderModule;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Disposable, IUniverInstanceService, IDisposable, Nullable } from '@univerjs/core';
|
|
2
|
+
import { DocSelectionManagerService } from '@univerjs/docs';
|
|
3
3
|
import { DocCanvasPopManagerService } from '@univerjs/docs-ui';
|
|
4
4
|
export interface ILinkInfo {
|
|
5
5
|
unitId: string;
|
|
@@ -17,7 +17,7 @@ export declare class DocHyperLinkPopupService extends Disposable {
|
|
|
17
17
|
readonly showingLink$: import('rxjs').Observable<Nullable<ILinkInfo>>;
|
|
18
18
|
private _editPopup;
|
|
19
19
|
private _infoPopup;
|
|
20
|
-
constructor(_docCanvasPopupManagerService: DocCanvasPopManagerService, _textSelectionManagerService:
|
|
20
|
+
constructor(_docCanvasPopupManagerService: DocCanvasPopManagerService, _textSelectionManagerService: DocSelectionManagerService, _univerInstanceService: IUniverInstanceService);
|
|
21
21
|
get editing(): Nullable<ILinkInfo>;
|
|
22
22
|
get showing(): Nullable<ILinkInfo>;
|
|
23
23
|
showEditPopup(unitId: string, linkInfo: Nullable<ILinkInfo>): Nullable<IDisposable>;
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/docs-hyper-link"),require("@univerjs/ui"),require("@univerjs/design"),require("react"),require("@univerjs/docs"),require("@univerjs/docs-ui"),require("rxjs"),require("clsx")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","@univerjs/docs-hyper-link","@univerjs/ui","@univerjs/design","react","@univerjs/docs","@univerjs/docs-ui","rxjs","clsx"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverDocsHyperLinkUi={},global.UniverCore,global.UniverEngineRender,global.UniverDocsHyperLink,global.UniverUi,global.UniverDesign,global.React,global.UniverDocs,global.UniverDocsUi,global.rxjs,global.clsx))})(this,function(exports2,core,engineRender,docsHyperLink,ui,design,React,docs,docsUi,rxjs,cs){"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);var _a,_b,_c,_d,_e,_f;const DOC_HYPER_LINK_UI_PLUGIN="DOC_HYPER_LINK_UI_PLUGIN";var __assign=function(){return __assign=Object.assign||function(t){for(var s,i=1,n=arguments.length;i<n;i++){s=arguments[i];for(var p in s)Object.prototype.hasOwnProperty.call(s,p)&&(t[p]=s[p])}return t},__assign.apply(this,arguments)},__rest=function(s,e){var t={};for(var p in s)Object.prototype.hasOwnProperty.call(s,p)&&e.indexOf(p)<0&&(t[p]=s[p]);if(s!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,p=Object.getOwnPropertySymbols(s);i<p.length;i++)e.indexOf(p[i])<0&&Object.prototype.propertyIsEnumerable.call(s,p[i])&&(t[p[i]]=s[p[i]]);return t},IconBase=React.forwardRef(function(props,ref){var icon=props.icon,id=props.id,className=props.className,extend=props.extend,restProps=__rest(props,["icon","id","className","extend"]),cls="univerjs-icon univerjs-icon-".concat(id," ").concat(className||"").trim(),idSuffix=React.useRef("_".concat(generateShortUuid()));return render(icon,"".concat(id),{defIds:icon.defIds,idSuffix:idSuffix.current},__assign({ref,className:cls},restProps),extend)});function render(node,id,runtimeProps,rootProps,extend){return React.createElement(node.tag,__assign(__assign({key:id},replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend)),rootProps),(replaceRuntimeIdsInDefs(node,runtimeProps).children||[]).map(function(child,index){return render(child,"".concat(id,"-").concat(node.tag,"-").concat(index),runtimeProps,void 0,extend)}))}__name(render,"render");function replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend){var attrs=__assign({},node.attrs);extend!=null&&extend.colorChannel1&&attrs.fill==="colorChannel1"&&(attrs.fill=extend.colorChannel1);var defIds=runtimeProps.defIds;return!defIds||defIds.length===0||(node.tag==="use"&&attrs["xlink:href"]&&(attrs["xlink:href"]=attrs["xlink:href"]+runtimeProps.idSuffix),Object.entries(attrs).forEach(function(_a2){var key=_a2[0],value=_a2[1];typeof value=="string"&&(attrs[key]=value.replace(/url\(#(.*)\)/,"url(#$1".concat(runtimeProps.idSuffix,")")))})),attrs}__name(replaceRuntimeIdsAndExtInAttrs,"replaceRuntimeIdsAndExtInAttrs");function replaceRuntimeIdsInDefs(node,runtimeProps){var _a2,defIds=runtimeProps.defIds;return!defIds||defIds.length===0?node:node.tag==="defs"&&(!((_a2=node.children)===null||_a2===void 0)&&_a2.length)?__assign(__assign({},node),{children:node.children.map(function(child){return typeof child.attrs.id=="string"&&defIds&&defIds.indexOf(child.attrs.id)>-1?__assign(__assign({},child),{attrs:__assign(__assign({},child.attrs),{id:child.attrs.id+runtimeProps.idSuffix})}):child})}):node}__name(replaceRuntimeIdsInDefs,"replaceRuntimeIdsInDefs");function generateShortUuid(){return Math.random().toString(36).substring(2,8)}__name(generateShortUuid,"generateShortUuid"),IconBase.displayName="UniverIcon";var element$3={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M4.1302 12.4251C4.25802 13.7417 5.36779 14.7708 6.71792 14.7708H11.7179C13.1539 14.7708 14.3179 13.6067 14.3179 12.1708V6.1708C14.3179 4.78586 13.2351 3.65383 11.8698 3.57517C11.742 2.25858 10.6323 1.22949 9.28213 1.22949H4.28213C2.84619 1.22949 1.68213 2.39355 1.68213 3.82949V9.82949C1.68213 11.2144 2.76497 12.3465 4.1302 12.4251ZM10.6583 3.5708H6.71792C5.28198 3.5708 4.11792 4.73486 4.11792 6.1708V11.22C3.4221 11.1387 2.88213 10.5471 2.88213 9.82949V3.82949C2.88213 3.05629 3.50893 2.42949 4.28213 2.42949H9.28213C9.96695 2.42949 10.5369 2.92119 10.6583 3.5708ZM13.1179 6.1708C13.1179 5.3976 12.4911 4.7708 11.7179 4.7708H6.71792C5.94472 4.7708 5.31792 5.3976 5.31792 6.1708V12.1708C5.31792 12.944 5.94472 13.5708 6.71792 13.5708H11.7179C12.4911 13.5708 13.1179 12.944 13.1179 12.1708V6.1708Z",fillRule:"evenodd",clipRule:"evenodd"}}]},CopySingle=React.forwardRef(function(props,ref){return React.createElement(IconBase,Object.assign({},props,{id:"copy-single",ref,icon:element$3}))});CopySingle.displayName="CopySingle";var element$2={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.9564 2.91332C4.91407 1.87102 3.22413 1.87101 2.18182 2.91333L2.18182 2.91333C1.13953 3.95567 1.13952 5.6456 2.18182 6.68791L8.27777 12.7838C9.72408 14.2302 12.069 14.2302 13.5154 12.7839L13.0911 12.3596L13.5154 12.7839C14.9617 11.3375 14.9617 8.99257 13.5154 7.54626L8.39476 2.42566C8.16044 2.19134 7.78054 2.19134 7.54623 2.42566C7.31191 2.65997 7.31191 3.03987 7.54623 3.27419L12.6668 8.39479L13.0911 7.97052L12.6668 8.39479C13.6445 9.37247 13.6445 10.9576 12.6668 11.9353L13.0399 12.3084L12.6668 11.9353C11.6891 12.913 10.104 12.913 9.1263 11.9353L3.03035 5.83938C2.45668 5.26571 2.45667 4.33556 3.03036 3.76184C3.60403 3.18818 4.53416 3.18817 5.10788 3.76185C5.10788 3.76186 5.10788 3.76186 5.10789 3.76186L11.2038 9.8578L11.601 9.46061L11.2038 9.8578C11.3735 10.0275 11.3735 10.3026 11.2038 10.4723L11.2038 10.4723C11.0341 10.642 10.759 10.642 10.5893 10.4723L5.46874 5.35171C5.23442 5.1174 4.85452 5.1174 4.62021 5.35171C4.38589 5.58602 4.38589 5.96592 4.62021 6.20024L9.74078 11.3208C10.3791 11.9591 11.414 11.9591 12.0523 11.3208C12.0523 11.3208 12.0523 11.3208 12.0523 11.3208M12.0523 11.3208C12.6907 10.6825 12.6906 9.64757 12.0523 9.00927L5.95641 2.91333L5.9564 2.91332",fillRule:"evenodd",clipRule:"evenodd"}}]},LinkSingle=React.forwardRef(function(props,ref){return React.createElement(IconBase,Object.assign({},props,{id:"link-single",ref,icon:element$2}))});LinkSingle.displayName="LinkSingle";var element$1={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.5935 3.47302C11.6354 2.51492 10.082 2.51492 9.12388 3.47302L7.83534 4.76157C7.60102 4.99588 7.22112 4.99588 6.98681 4.76157 6.75249 4.52725 6.75249 4.14735 6.98681 3.91304L8.27535 2.62449C9.70209 1.19776 12.0153 1.19776 13.442 2.62449 14.8688 4.05123 14.8688 6.36442 13.442 7.79116L12.1535 9.0797C11.9192 9.31402 11.5393 9.31402 11.3049 9.0797 11.0706 8.84539 11.0706 8.46549 11.3049 8.23117L12.5935 6.94263C13.5516 5.98452 13.5516 4.43113 12.5935 3.47302zM3.40637 12.6606C2.44827 11.7025 2.44827 10.1491 3.40637 9.19102L4.69492 7.90248C4.92923 7.66816 4.92923 7.28826 4.69492 7.05395 4.4606 6.81963 4.0807 6.81963 3.84639 7.05395L2.55784 8.34249C1.13111 9.76923 1.13111 12.0824 2.55784 13.5092 3.98458 14.9359 6.29777 14.9359 7.72451 13.5092L9.01305 12.2206C9.24737 11.9863 9.24737 11.6064 9.01305 11.3721 8.77874 11.1378 8.39884 11.1378 8.16452 11.3721L6.87598 12.6606C5.91787 13.6187 4.36448 13.6187 3.40637 12.6606zM3.5852 2.80332C3.35088 2.569 2.97098 2.569 2.73667 2.80332 2.50235 3.03763 2.50235 3.41753 2.73667 3.65185L12.4151 13.3302C12.6494 13.5646 13.0293 13.5646 13.2636 13.3302 13.4979 13.0959 13.4979 12.716 13.2636 12.4817L3.5852 2.80332z"}}]},UnlinkSingle=React.forwardRef(function(props,ref){return React.createElement(IconBase,Object.assign({},props,{id:"unlink-single",ref,icon:element$1}))});UnlinkSingle.displayName="UnlinkSingle";var element={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.6551 1.98906C11.7476 1.08113 10.2757 1.08149 9.3686 1.98987L4.82542 6.53955C4.75087 6.61421 4.69336 6.70411 4.65682 6.80309L3.2461 10.625C3.16506 10.8446 3.21909 11.0912 3.3845 11.2568C3.54991 11.4224 3.79651 11.4767 4.01616 11.3959L7.85031 9.98517C7.94979 9.94856 8.04014 9.89077 8.11508 9.81579L12.6552 5.27327C13.5618 4.36621 13.5618 2.89607 12.6551 1.98906ZM10.2177 2.83779C10.6562 2.39869 11.3677 2.39851 11.8064 2.8374C12.2447 3.27584 12.2447 3.9865 11.8065 4.42497L7.3392 8.89457L4.82213 9.82068L5.74706 7.31487L10.2177 2.83779Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.79238 13.2999C1.46101 13.2999 1.19238 13.5685 1.19238 13.8999C1.19238 14.2313 1.46101 14.4999 1.79238 14.4999H14.4924C14.8238 14.4999 15.0924 14.2313 15.0924 13.8999C15.0924 13.5685 14.8238 13.2999 14.4924 13.2999H1.79238Z"}}]},WriteSingle=React.forwardRef(function(props,ref){return React.createElement(IconBase,Object.assign({},props,{id:"write-single",ref,icon:element}))});WriteSingle.displayName="WriteSingle";const DeleteDocHyperLinkCommand={type:core.CommandType.COMMAND,id:"docs.command.delete-hyper-link",async handler(accessor,params){if(!params)return!1;const{unitId,linkId,segmentId}=params,commandService=accessor.get(core.ICommandService),doMutation=docs.deleteCustomRangeFactory(accessor,{unitId,rangeId:linkId,segmentId});return doMutation?await commandService.syncExecuteCommand(doMutation.id,doMutation.params):!1}},shouldDisableAddLink=__name(accessor=>{var _a2;const textSelectionService=accessor.get(docs.TextSelectionManagerService),univerInstanceService=accessor.get(core.IUniverInstanceService),textRanges=textSelectionService.getDocRanges();if(!textRanges.length||textRanges.length>1)return!0;const activeRange=textRanges[0],doc=univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_DOC);if(!doc||!activeRange||activeRange.collapsed)return!0;const body=doc.getSelfOrHeaderFooterModel(activeRange.segmentId).getBody(),paragraphs=body==null?void 0:body.paragraphs;if(!paragraphs)return!0;for(let i=0,len=paragraphs.length;i<len;i++){const p=paragraphs[i];if(activeRange.startOffset<=p.startIndex&&activeRange.endOffset>p.startIndex)return!0;if(p.startIndex>activeRange.endOffset)break}return!docs.getCustomRangesInterestsWithRange(activeRange,(_a2=body.customRanges)!=null?_a2:[]).every(range=>range.rangeType===core.CustomRangeType.HYPERLINK)},"shouldDisableAddLink"),ShowDocHyperLinkEditPopupOperation={type:core.CommandType.OPERATION,id:"doc.operation.show-hyper-link-edit-popup",handler(accessor,params){var _a2;const linkInfo=params==null?void 0:params.link,univerInstanceService=accessor.get(core.IUniverInstanceService);if(shouldDisableAddLink(accessor)&&!linkInfo)return!1;const hyperLinkService=accessor.get(DocHyperLinkPopupService),unitId=(linkInfo==null?void 0:linkInfo.unitId)||((_a2=univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_DOC))==null?void 0:_a2.getUnitId());return unitId?(hyperLinkService.showEditPopup(unitId,linkInfo),!0):!1}},ToggleDocHyperLinkInfoPopupOperation={type:core.CommandType.OPERATION,id:"doc.operation.toggle-hyper-link-info-popup",handler(accessor,params){const hyperLinkService=accessor.get(DocHyperLinkPopupService);return params?(hyperLinkService.showInfoPopup(params),!0):(hyperLinkService.hideInfoPopup(),!0)}},ClickDocHyperLinkOperation={type:core.CommandType.OPERATION,id:"doc.operation.click-hyper-link",handler(accessor,params){var _a2,_b2,_c2;if(!params)return!1;const{unitId,linkId,segmentId}=params,doc=accessor.get(core.IUniverInstanceService).getUnit(unitId,core.UniverInstanceType.UNIVER_DOC),body=doc==null?void 0:doc.getSelfOrHeaderFooterModel(segmentId).getBody(),link=(_c2=(_b2=(_a2=body==null?void 0:body.customRanges)==null?void 0:_a2.find(range=>range.rangeId===linkId&&range.rangeType===core.CustomRangeType.HYPERLINK))==null?void 0:_b2.properties)==null?void 0:_c2.url;return link&&window.open(link,"_blank","noopener noreferrer"),!0}},styles$1={docLink:"univer-doc-link",docLinkType:"univer-doc-link-type",docLinkContent:"univer-doc-link-content",docLinkContentError:"univer-doc-link-content-error",docLinkUrl:"univer-doc-link-url",docLinkOperations:"univer-doc-link-operations",docLinkOperation:"univer-doc-link-operation",docLinkOperationError:"univer-doc-link-operation-error"},DocLinkPopup=__name(()=>{var _a2,_b2;const hyperLinkService=core.useDependency(DocHyperLinkPopupService),commandService=core.useDependency(core.ICommandService),messageService=core.useDependency(ui.IMessageService),localeService=core.useDependency(core.LocaleService),currentPopup=ui.useObservable(hyperLinkService.showingLink$),univerInstanceService=core.useDependency(core.IUniverInstanceService);if(!currentPopup)return null;const{unitId,linkId,segmentId}=currentPopup,doc=univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_DOC),body=doc==null?void 0:doc.getSelfOrHeaderFooterModel(segmentId).getBody(),link=(_a2=body==null?void 0:body.customRanges)==null?void 0:_a2.find(range=>range.rangeId===linkId&&range.rangeType===core.CustomRangeType.HYPERLINK);if(!link)return null;const url=(_b2=link.properties)==null?void 0:_b2.url;return React.createElement("div",{className:styles$1.docLink,onClick:__name(()=>{hyperLinkService.hideInfoPopup()},"onClick")},React.createElement("div",{className:cs(styles$1.docLinkContent),onClick:__name(()=>window.open(url),"onClick")},React.createElement("div",{className:styles$1.docLinkType},React.createElement(LinkSingle,null)),React.createElement(design.Tooltip,{showIfEllipsis:!0,title:url},React.createElement("span",{className:styles$1.docLinkUrl},url))),React.createElement("div",{className:styles$1.docLinkOperations},React.createElement("div",{className:cs(styles$1.docLinkOperation),onClick:__name(()=>{navigator.clipboard.writeText(url),messageService.show({content:localeService.t("docLink.info.coped"),type:design.MessageType.Info})},"onClick")},React.createElement(design.Tooltip,{placement:"bottom",title:localeService.t("docLink.info.copy")},React.createElement(CopySingle,null))),React.createElement("div",{className:styles$1.docLinkOperation,onClick:__name(()=>{commandService.executeCommand(ShowDocHyperLinkEditPopupOperation.id,{link:currentPopup})},"onClick")},React.createElement(design.Tooltip,{placement:"bottom",title:localeService.t("docLink.info.edit")},React.createElement(WriteSingle,null))),React.createElement("div",{className:styles$1.docLinkOperation,onClick:__name(()=>{commandService.executeCommand(DeleteDocHyperLinkCommand.id,{unitId,linkId:link.rangeId,segmentId})},"onClick")},React.createElement(design.Tooltip,{placement:"bottom",title:localeService.t("docLink.info.cancel")},React.createElement(UnlinkSingle,null)))))},"DocLinkPopup");DocLinkPopup.componentKey="univer.doc.link-info-popup";var __defProp$5=Object.defineProperty,__getOwnPropDesc$5=Object.getOwnPropertyDescriptor,__decorateClass$5=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$5(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$5(target,key,result),result},"__decorateClass$5"),__decorateParam$5=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$5");const SKIT_PLACEHOLDER=0;let DocHyperLinkPopupService=(_a=class extends core.Disposable{constructor(_docCanvasPopupManagerService,_textSelectionManagerService,_univerInstanceService){super();__publicField(this,"_editingLink$",new rxjs.BehaviorSubject(null));__publicField(this,"_showingLink$",new rxjs.BehaviorSubject(null));__publicField(this,"editingLink$",this._editingLink$.asObservable());__publicField(this,"showingLink$",this._showingLink$.asObservable());__publicField(this,"_editPopup",null);__publicField(this,"_infoPopup",null);this._docCanvasPopupManagerService=_docCanvasPopupManagerService,this._textSelectionManagerService=_textSelectionManagerService,this._univerInstanceService=_univerInstanceService,this.disposeWithMe(()=>{this._editingLink$.complete(),this._showingLink$.complete()})}get editing(){return this._editingLink$.value}get showing(){return this._showingLink$.value}showEditPopup(unitId,linkInfo){var _a2,_b2,_c2;this._editPopup&&this._editPopup.dispose(),this._editingLink$.next(linkInfo);let activeRange=this._textSelectionManagerService.getActiveTextRangeWithStyle();if(linkInfo){const{unitId:unitId2,linkId,segmentId,segmentPage}=linkInfo,doc=this._univerInstanceService.getUnit(unitId2,core.UniverInstanceType.UNIVER_DOC),range=(_c2=(_b2=(_a2=doc==null?void 0:doc.getSelfOrHeaderFooterModel(segmentId))==null?void 0:_a2.getBody())==null?void 0:_b2.customRanges)==null?void 0:_c2.find(i=>i.rangeId===linkId);range&&(activeRange={collapsed:!1,startOffset:range.startIndex+SKIT_PLACEHOLDER,endOffset:range.endIndex+1,segmentId,segmentPage},this._textSelectionManagerService.replaceTextRanges([{startOffset:range.startIndex,endOffset:range.endIndex+1}]))}return activeRange?(this._editPopup=this._docCanvasPopupManagerService.attachPopupToRange(activeRange,{componentKey:DocHyperLinkEdit.componentKey,direction:"bottom"},unitId),this._editPopup):null}hideEditPopup(){var _a2;this._editingLink$.next(null),(_a2=this._editPopup)==null||_a2.dispose()}showInfoPopup(info){var _a2,_b2,_c2,_d2,_e2,_f2;const{linkId,unitId,segmentId,segmentPage}=info;if(((_a2=this.showing)==null?void 0:_a2.linkId)===linkId&&((_b2=this.showing)==null?void 0:_b2.unitId)===unitId&&((_c2=this.showing)==null?void 0:_c2.segmentId)===segmentId&&((_d2=this.showing)==null?void 0:_d2.segmentPage)===segmentPage)return;this._infoPopup&&this._infoPopup.dispose();const doc=this._univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_DOC);if(!doc)return;const range=(_f2=(_e2=doc.getSelfOrHeaderFooterModel(info.segmentId).getBody())==null?void 0:_e2.customRanges)==null?void 0:_f2.find(i=>i.rangeId===linkId);if(this._showingLink$.next({unitId,linkId,segmentId,segmentPage}),!!range)return this._infoPopup=this._docCanvasPopupManagerService.attachPopupToRange({collapsed:!1,startOffset:range.startIndex+SKIT_PLACEHOLDER,endOffset:range.endIndex+1,segmentId:info.segmentId,segmentPage:info.segmentPage},{componentKey:DocLinkPopup.componentKey,direction:"top-center",multipleDirection:"top",closeOnSelfTarget:!0,onClickOutside:__name(()=>{this.hideInfoPopup()},"onClickOutside")},info.unitId),this._infoPopup}hideInfoPopup(){var _a2;this._showingLink$.next(null),(_a2=this._infoPopup)==null||_a2.dispose()}},__name(_a,"DocHyperLinkPopupService"),_a);DocHyperLinkPopupService=__decorateClass$5([__decorateParam$5(0,core.Inject(docsUi.DocCanvasPopManagerService)),__decorateParam$5(1,core.Inject(docs.TextSelectionManagerService)),__decorateParam$5(2,core.IUniverInstanceService)],DocHyperLinkPopupService);const AddDocHyperLinkCommand={type:core.CommandType.COMMAND,id:"docs.command.add-hyper-link",async handler(accessor,params){if(!params)return!1;const{payload,unitId}=params,commandService=accessor.get(core.ICommandService),id=core.generateRandomId(),doMutation=docs.addCustomRangeBySelectionFactory(accessor,{rangeId:id,rangeType:core.CustomRangeType.HYPERLINK,properties:{url:payload}});return doMutation?commandService.syncExecuteCommand(doMutation.id,doMutation.params):!1}},UpdateDocHyperLinkCommand={id:"docs.command.update-hyper-link",type:core.CommandType.COMMAND,handler(accessor,params){if(!params)return!1;const{unitId,payload,segmentId}=params,commandService=accessor.get(core.ICommandService),currentSelection=accessor.get(docs.TextSelectionManagerService).getActiveTextRange();if(!currentSelection)return!1;const newId=core.generateRandomId(),replaceSelection=docs.replaceSelectionFactory(accessor,{unitId,body:{dataStream:`${core.DataStreamTreeTokenType.CUSTOM_RANGE_START}${params.label}${core.DataStreamTreeTokenType.CUSTOM_RANGE_END}`,customRanges:[{rangeId:newId,rangeType:core.CustomRangeType.HYPERLINK,startIndex:0,endIndex:params.label.length+1,properties:{url:payload}}]},selection:{startOffset:currentSelection.startOffset,endOffset:currentSelection.endOffset,collapsed:!1,segmentId}});return replaceSelection?commandService.syncExecuteCommand(replaceSelection.id,replaceSelection.params):!1}},styles={docsLinkEdit:"univer-docs-link-edit",docsLinkEditTitle:"univer-docs-link-edit-title",docsLinkEditClose:"univer-docs-link-edit-close",docsLinkEditButtons:"univer-docs-link-edit-buttons",docsLinkEditButton:"univer-docs-link-edit-button"};function hasProtocol(urlString){return/^[a-zA-Z]+:\/\//.test(urlString)}__name(hasProtocol,"hasProtocol");function isEmail(url){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(url)}__name(isEmail,"isEmail");function transformUrl(urlStr){return hasProtocol(urlStr)?urlStr:isEmail(urlStr)?`mailto://${urlStr}`:`https://${urlStr}`}__name(transformUrl,"transformUrl");const DocHyperLinkEdit=__name(()=>{const hyperLinkService=core.useDependency(DocHyperLinkPopupService),localeService=core.useDependency(core.LocaleService),editing=core.useObservable(hyperLinkService.editingLink$),commandService=core.useDependency(core.ICommandService),univerInstanceService=core.useDependency(core.IUniverInstanceService),textSelectionRenderManager=core.useDependency(engineRender.ITextSelectionRenderManager),textSelectionManagerService=core.useDependency(docs.TextSelectionManagerService),[link,setLink]=React.useState(""),[label,setLabel]=React.useState(""),[showError,setShowError]=React.useState(!1),isLegal=core.Tools.isLegalUrl(link),doc=editing?univerInstanceService.getUnit(editing.unitId,core.UniverInstanceType.UNIVER_DOC):univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_DOC);React.useEffect(()=>{var _a2,_b2,_c2,_d2,_e2,_f2,_g,_h,_i;const activeRange=textSelectionManagerService.getActiveTextRangeWithStyle();if(!activeRange)return;if(editing){const body=(_a2=doc==null?void 0:doc.getSelfOrHeaderFooterModel(editing.segmentId))==null?void 0:_a2.getBody(),matchedRange2=(_b2=body==null?void 0:body.customRanges)==null?void 0:_b2.find(i=>(editing==null?void 0:editing.linkId)===i.rangeId);doc&&matchedRange2&&(setLink((_d2=(_c2=matchedRange2.properties)==null?void 0:_c2.url)!=null?_d2:""),setLabel(docs.getPlainTextFormBody(core.getBodySlice(body,matchedRange2.startIndex,matchedRange2.endIndex))));return}const matchedRange=(_g=(_f2=(_e2=doc==null?void 0:doc.getSelfOrHeaderFooterModel(activeRange.segmentId))==null?void 0:_e2.getBody())==null?void 0:_f2.customRanges)==null?void 0:_g.find(i=>Math.max(activeRange.startOffset,i.startIndex)<=Math.min(activeRange.endOffset-1,i.endIndex));doc&&matchedRange&&setLink((_i=(_h=matchedRange==null?void 0:matchedRange.properties)==null?void 0:_h.url)!=null?_i:"")},[doc,editing,textSelectionManagerService,univerInstanceService]),React.useEffect(()=>(textSelectionRenderManager.blurEditor(),()=>{textSelectionRenderManager.focusEditor()}),[textSelectionRenderManager]);const handleCancel=__name(()=>{hyperLinkService.hideEditPopup()},"handleCancel"),handleConfirm=__name(()=>{if(setShowError(!0),!isLegal||!doc)return;const linkFinal=transformUrl(link);if(!editing)commandService.executeCommand(AddDocHyperLinkCommand.id,{unitId:doc.getUnitId(),payload:linkFinal});else{if(!label)return;commandService.executeCommand(UpdateDocHyperLinkCommand.id,{unitId:doc.getUnitId(),payload:linkFinal,linkId:editing.linkId,label,segmentId:editing.segmentId})}hyperLinkService.hideEditPopup()},"handleConfirm");if(doc)return React.createElement("div",{className:styles.docsLinkEdit},React.createElement("div",null,editing?React.createElement(design.FormLayout,{label:localeService.t("docLink.edit.label"),error:showError&&!label?localeService.t("docLink.edit.labelError"):""},React.createElement(design.Input,{value:label,onChange:setLabel,autoFocus:!0,onKeyDown:__name(evt=>{evt.keyCode===ui.KeyCode.ENTER&&handleConfirm()},"onKeyDown")})):null,React.createElement(design.FormLayout,{label:localeService.t("docLink.edit.address"),error:showError&&!isLegal?localeService.t("docLink.edit.addressError"):""},React.createElement(design.Input,{value:link,onChange:setLink,autoFocus:!0,onKeyDown:__name(evt=>{evt.keyCode===ui.KeyCode.ENTER&&handleConfirm()},"onKeyDown")}))),React.createElement("div",{className:styles.docsLinkEditButtons},React.createElement(design.Button,{className:styles.docsLinkEditButton,onClick:handleCancel},localeService.t("docLink.edit.cancel")),React.createElement(design.Button,{disabled:!link,className:styles.docsLinkEditButton,type:"primary",onClick:handleConfirm},localeService.t("docLink.edit.confirm"))))},"DocHyperLinkEdit");DocHyperLinkEdit.componentKey="docs-hyper-link-edit";const DOC_LINK_ICON="doc-hyper-link-icon";function AddHyperLinkMenuItemFactory(accessor){return{id:ShowDocHyperLinkEditPopupOperation.id,type:ui.MenuItemType.BUTTON,icon:DOC_LINK_ICON,title:"docLink.menu.tooltip",tooltip:"docLink.menu.tooltip",hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_DOC),disabled$:new rxjs.Observable(function(subscribe){const observer=accessor.get(docs.TextSelectionManagerService).textSelection$.pipe(rxjs.debounceTime(16)).subscribe(()=>{subscribe.next(shouldDisableAddLink(accessor))});return()=>{observer.unsubscribe()}})}}__name(AddHyperLinkMenuItemFactory,"AddHyperLinkMenuItemFactory");const addLinkShortcut={id:ShowDocHyperLinkEditPopupOperation.id,binding:ui.MetaKeys.CTRL_COMMAND|ui.KeyCode.K,description:"docLink.menu.tooltip",preconditions:docsUi.whenDocAndEditorFocused},menuSchema={[ui.RibbonStartGroup.OTHERS]:{[ShowDocHyperLinkEditPopupOperation.id]:{order:0,menuItemFactory:AddHyperLinkMenuItemFactory}},[ui.ContextMenuPosition.MAIN_AREA]:{[ui.ContextMenuGroup.DATA]:{[ShowDocHyperLinkEditPopupOperation.id]:{order:0,menuItemFactory:AddHyperLinkMenuItemFactory}}}};var __defProp$4=Object.defineProperty,__getOwnPropDesc$4=Object.getOwnPropertyDescriptor,__decorateClass$4=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$4(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$4(target,key,result),result},"__decorateClass$4"),__decorateParam$4=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$4");let DocHyperLinkUIController=(_b=class extends core.Disposable{constructor(_componentManager,_commandService,_menuManagerService,_injector,_shortcutService){super(),this._componentManager=_componentManager,this._commandService=_commandService,this._menuManagerService=_menuManagerService,this._injector=_injector,this._shortcutService=_shortcutService,this._initComponents(),this._initCommands(),this._initMenus(),this._initShortcut()}_initComponents(){[[DocHyperLinkEdit,DocHyperLinkEdit.componentKey],[DocLinkPopup,DocLinkPopup.componentKey],[LinkSingle,DOC_LINK_ICON]].forEach(([comp,key])=>{this._componentManager.register(key,comp)})}_initCommands(){[AddDocHyperLinkCommand,UpdateDocHyperLinkCommand,DeleteDocHyperLinkCommand,ShowDocHyperLinkEditPopupOperation,ToggleDocHyperLinkInfoPopupOperation,ClickDocHyperLinkOperation].forEach(command=>{this._commandService.registerCommand(command)})}_initShortcut(){[addLinkShortcut].forEach(shortcut=>{this._shortcutService.registerShortcut(shortcut)})}_initMenus(){this._menuManagerService.mergeMenu(menuSchema)}},__name(_b,"DocHyperLinkUIController"),_b);DocHyperLinkUIController=__decorateClass$4([core.OnLifecycle(core.LifecycleStages.Starting,DocHyperLinkUIController),__decorateParam$4(0,core.Inject(ui.ComponentManager)),__decorateParam$4(1,core.ICommandService),__decorateParam$4(2,ui.IMenuManagerService),__decorateParam$4(3,core.Inject(core.Injector)),__decorateParam$4(4,ui.IShortcutService)],DocHyperLinkUIController);var __defProp$3=Object.defineProperty,__getOwnPropDesc$3=Object.getOwnPropertyDescriptor,__decorateClass$3=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$3(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$3(target,key,result),result},"__decorateClass$3"),__decorateParam$3=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$3");let DocHyperLinkSelectionController=(_c=class extends core.Disposable{constructor(_commandService,_univerInstanceService,_docHyperLinkService){super(),this._commandService=_commandService,this._univerInstanceService=_univerInstanceService,this._docHyperLinkService=_docHyperLinkService,this._initSelectionChange()}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(commandInfo=>{var _a2,_b2,_c2;if(commandInfo.id===docs.SetTextSelectionsOperation.id){const params=commandInfo.params,{unitId,ranges,segmentId}=params,doc=this._univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_DOC),primary=ranges[0];if(primary&&doc){const{startOffset,endOffset,collapsed,segmentPage}=primary,customRanges=(_b2=(_a2=doc.getSelfOrHeaderFooterModel(segmentId))==null?void 0:_a2.getBody())==null?void 0:_b2.customRanges;if(collapsed){const index=(_c2=customRanges==null?void 0:customRanges.findIndex(value=>value.startIndex<startOffset&&value.endIndex>endOffset-1))!=null?_c2:-1;if(index>-1){const customRange=customRanges[index];this._docHyperLinkService.showInfoPopup({unitId,linkId:customRange.rangeId,segmentId,segmentPage});return}}else if(customRanges==null?void 0:customRanges.find(value=>value.startIndex<=startOffset&&value.endIndex>=endOffset-1))return}this._docHyperLinkService.hideInfoPopup(),this._docHyperLinkService.hideEditPopup()}}))}},__name(_c,"DocHyperLinkSelectionController"),_c);DocHyperLinkSelectionController=__decorateClass$3([core.OnLifecycle(core.LifecycleStages.Ready,DocHyperLinkSelectionController),__decorateParam$3(0,core.ICommandService),__decorateParam$3(1,core.IUniverInstanceService),__decorateParam$3(2,core.Inject(DocHyperLinkPopupService))],DocHyperLinkSelectionController);var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2");let DocHyperLinkRenderController=(_d=class extends core.Disposable{constructor(_context,_docInterceptorService,_hyperLinkService,_docRenderController){super(),this._context=_context,this._docInterceptorService=_docInterceptorService,this._hyperLinkService=_hyperLinkService,this._docRenderController=_docRenderController,this._init(),this._initReRender()}_init(){this._docInterceptorService.intercept(docs.DOC_INTERCEPTOR_POINT.CUSTOM_RANGE,{handler:__name((data,pos,next)=>{if(!data)return next(data);const{unitId}=pos,activeLink=this._hyperLinkService.showing,{linkId,unitId:linkUnitId}=activeLink||{},isActive=linkUnitId===unitId&&data.rangeId===linkId;return next({...data,active:isActive})},"handler")})}_initReRender(){this.disposeWithMe(this._hyperLinkService.showingLink$.pipe(rxjs.distinctUntilChanged((prev,aft)=>(prev==null?void 0:prev.linkId)===(aft==null?void 0:aft.linkId)&&(prev==null?void 0:prev.unitId)===(aft==null?void 0:aft.unitId)),rxjs.pairwise()).subscribe(([preLink,link])=>{link?link.unitId===this._context.unitId&&this._docRenderController.reRender(link.unitId):preLink&&preLink.unitId===this._context.unitId&&this._docRenderController.reRender(preLink.unitId)}))}},__name(_d,"DocHyperLinkRenderController"),_d);DocHyperLinkRenderController=__decorateClass$2([__decorateParam$2(1,core.Inject(docs.DocInterceptorService)),__decorateParam$2(2,core.Inject(DocHyperLinkPopupService)),__decorateParam$2(3,core.Inject(docsUi.DocRenderController))],DocHyperLinkRenderController);var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1");let DocHyperLinkEventRenderController=(_e=class extends core.Disposable{constructor(_context,_docEventManagerService,_commandService,_hyperLinkPopupService,_docSkeletonManagerService,_textSelectionManagerService){super(),this._context=_context,this._docEventManagerService=_docEventManagerService,this._commandService=_commandService,this._hyperLinkPopupService=_hyperLinkPopupService,this._docSkeletonManagerService=_docSkeletonManagerService,this._textSelectionManagerService=_textSelectionManagerService,this._initHover(),this._initClick()}get _skeleton(){return this._docSkeletonManagerService.getSkeleton()}_hideInfoPopup(){this._hyperLinkPopupService.showing&&this._commandService.executeCommand(ToggleDocHyperLinkInfoPopupOperation.id)}_initHover(){this.disposeWithMe(this._docEventManagerService.hoverCustomRanges$.subscribe(ranges=>{var _a2;const link=ranges.find(range=>range.range.rangeType===core.CustomRangeType.HYPERLINK),activeRanges=this._textSelectionManagerService.getCurrentTextRanges(),currentSegmentId=activeRanges==null?void 0:activeRanges[0].segmentId;if(((_a2=link==null?void 0:link.segmentId)!=null?_a2:"")!==currentSegmentId){this._hideInfoPopup();return}link?this._commandService.executeCommand(ToggleDocHyperLinkInfoPopupOperation.id,{unitId:this._context.unitId,linkId:link.range.rangeId,segmentId:link.segmentId,segmentPage:link.segmentPageIndex,rangeId:link.range.rangeId}):this._hideInfoPopup()}))}_initClick(){this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe(range=>{const link=range.range;link&&this._commandService.executeCommand(ClickDocHyperLinkOperation.id,{unitId:this._context.unitId,linkId:link.rangeId,segmentId:range.segmentId})}))}},__name(_e,"DocHyperLinkEventRenderController"),_e);DocHyperLinkEventRenderController=__decorateClass$1([__decorateParam$1(1,core.Inject(docsUi.DocEventManagerService)),__decorateParam$1(2,core.ICommandService),__decorateParam$1(3,core.Inject(DocHyperLinkPopupService)),__decorateParam$1(4,core.Inject(docs.DocSkeletonManagerService)),__decorateParam$1(5,core.Inject(docs.TextSelectionManagerService))],DocHyperLinkEventRenderController);const PLUGIN_CONFIG_KEY="docs-hyper-link-ui.config",defaultPluginConfig={};var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key,value)=>key in obj?__defProp2(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),__publicField2=__name((obj,key,value)=>__defNormalProp2(obj,typeof key!="symbol"?key+"":key,value),"__publicField");exports2.UniverDocsHyperLinkUIPlugin=(_f=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_renderManagerSrv,_configService){super(),this._config=_config,this._injector=_injector,this._renderManagerSrv=_renderManagerSrv,this._configService=_configService;const{menu,...rest}=this._config;menu&&this._configService.setConfig("menu",menu,{merge:!0}),this._configService.setConfig(PLUGIN_CONFIG_KEY,rest)}onStarting(){[[DocHyperLinkPopupService],[DocHyperLinkUIController],[DocHyperLinkSelectionController]].forEach(dep=>{this._injector.add(dep)})}onRendered(){this._initRenderModule()}_initRenderModule(){[[DocHyperLinkRenderController],[DocHyperLinkEventRenderController]].forEach(dep=>{this._renderManagerSrv.registerRenderModule(core.UniverInstanceType.UNIVER_DOC,dep)})}},__name(_f,"UniverDocsHyperLinkUIPlugin"),_f),__publicField2(exports2.UniverDocsHyperLinkUIPlugin,"pluginName",DOC_HYPER_LINK_UI_PLUGIN),__publicField2(exports2.UniverDocsHyperLinkUIPlugin,"type",core.UniverInstanceType.UNIVER_DOC),exports2.UniverDocsHyperLinkUIPlugin=__decorateClass([core.DependentOn(docsHyperLink.UniverDocsHyperLinkPlugin),__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,engineRender.IRenderManagerService),__decorateParam(3,core.IConfigService)],exports2.UniverDocsHyperLinkUIPlugin),Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(global,factory){typeof exports=="object"&&typeof module<"u"?factory(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("@univerjs/docs-hyper-link"),require("@univerjs/ui"),require("@univerjs/design"),require("@univerjs/docs"),require("@univerjs/docs-ui"),require("react"),require("rxjs"),require("clsx")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","@univerjs/docs-hyper-link","@univerjs/ui","@univerjs/design","@univerjs/docs","@univerjs/docs-ui","react","rxjs","clsx"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverDocsHyperLinkUi={},global.UniverCore,global.UniverEngineRender,global.UniverDocsHyperLink,global.UniverUi,global.UniverDesign,global.UniverDocs,global.UniverDocsUi,global.React,global.rxjs,global.clsx))})(this,function(exports2,core,engineRender,docsHyperLink,ui,design,docs,docsUi,React,rxjs,cs){"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);var _a,_b,_c,_d,_e,_f;const DOC_HYPER_LINK_UI_PLUGIN="DOC_HYPER_LINK_UI_PLUGIN";var __assign=function(){return __assign=Object.assign||function(t){for(var s,i=1,n=arguments.length;i<n;i++){s=arguments[i];for(var p in s)Object.prototype.hasOwnProperty.call(s,p)&&(t[p]=s[p])}return t},__assign.apply(this,arguments)},__rest=function(s,e){var t={};for(var p in s)Object.prototype.hasOwnProperty.call(s,p)&&e.indexOf(p)<0&&(t[p]=s[p]);if(s!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,p=Object.getOwnPropertySymbols(s);i<p.length;i++)e.indexOf(p[i])<0&&Object.prototype.propertyIsEnumerable.call(s,p[i])&&(t[p[i]]=s[p[i]]);return t},IconBase=React.forwardRef(function(props,ref){var icon=props.icon,id=props.id,className=props.className,extend=props.extend,restProps=__rest(props,["icon","id","className","extend"]),cls="univerjs-icon univerjs-icon-".concat(id," ").concat(className||"").trim(),idSuffix=React.useRef("_".concat(generateShortUuid()));return render(icon,"".concat(id),{defIds:icon.defIds,idSuffix:idSuffix.current},__assign({ref,className:cls},restProps),extend)});function render(node,id,runtimeProps,rootProps,extend){return React.createElement(node.tag,__assign(__assign({key:id},replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend)),rootProps),(replaceRuntimeIdsInDefs(node,runtimeProps).children||[]).map(function(child,index){return render(child,"".concat(id,"-").concat(node.tag,"-").concat(index),runtimeProps,void 0,extend)}))}__name(render,"render");function replaceRuntimeIdsAndExtInAttrs(node,runtimeProps,extend){var attrs=__assign({},node.attrs);extend!=null&&extend.colorChannel1&&attrs.fill==="colorChannel1"&&(attrs.fill=extend.colorChannel1);var defIds=runtimeProps.defIds;return!defIds||defIds.length===0||(node.tag==="use"&&attrs["xlink:href"]&&(attrs["xlink:href"]=attrs["xlink:href"]+runtimeProps.idSuffix),Object.entries(attrs).forEach(function(_a2){var key=_a2[0],value=_a2[1];typeof value=="string"&&(attrs[key]=value.replace(/url\(#(.*)\)/,"url(#$1".concat(runtimeProps.idSuffix,")")))})),attrs}__name(replaceRuntimeIdsAndExtInAttrs,"replaceRuntimeIdsAndExtInAttrs");function replaceRuntimeIdsInDefs(node,runtimeProps){var _a2,defIds=runtimeProps.defIds;return!defIds||defIds.length===0?node:node.tag==="defs"&&(!((_a2=node.children)===null||_a2===void 0)&&_a2.length)?__assign(__assign({},node),{children:node.children.map(function(child){return typeof child.attrs.id=="string"&&defIds&&defIds.indexOf(child.attrs.id)>-1?__assign(__assign({},child),{attrs:__assign(__assign({},child.attrs),{id:child.attrs.id+runtimeProps.idSuffix})}):child})}):node}__name(replaceRuntimeIdsInDefs,"replaceRuntimeIdsInDefs");function generateShortUuid(){return Math.random().toString(36).substring(2,8)}__name(generateShortUuid,"generateShortUuid"),IconBase.displayName="UniverIcon";var element$3={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M4.1302 12.4251C4.25802 13.7417 5.36779 14.7708 6.71792 14.7708H11.7179C13.1539 14.7708 14.3179 13.6067 14.3179 12.1708V6.1708C14.3179 4.78586 13.2351 3.65383 11.8698 3.57517C11.742 2.25858 10.6323 1.22949 9.28213 1.22949H4.28213C2.84619 1.22949 1.68213 2.39355 1.68213 3.82949V9.82949C1.68213 11.2144 2.76497 12.3465 4.1302 12.4251ZM10.6583 3.5708H6.71792C5.28198 3.5708 4.11792 4.73486 4.11792 6.1708V11.22C3.4221 11.1387 2.88213 10.5471 2.88213 9.82949V3.82949C2.88213 3.05629 3.50893 2.42949 4.28213 2.42949H9.28213C9.96695 2.42949 10.5369 2.92119 10.6583 3.5708ZM13.1179 6.1708C13.1179 5.3976 12.4911 4.7708 11.7179 4.7708H6.71792C5.94472 4.7708 5.31792 5.3976 5.31792 6.1708V12.1708C5.31792 12.944 5.94472 13.5708 6.71792 13.5708H11.7179C12.4911 13.5708 13.1179 12.944 13.1179 12.1708V6.1708Z",fillRule:"evenodd",clipRule:"evenodd"}}]},CopySingle=React.forwardRef(function(props,ref){return React.createElement(IconBase,Object.assign({},props,{id:"copy-single",ref,icon:element$3}))});CopySingle.displayName="CopySingle";var element$2={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.9564 2.91332C4.91407 1.87102 3.22413 1.87101 2.18182 2.91333L2.18182 2.91333C1.13953 3.95567 1.13952 5.6456 2.18182 6.68791L8.27777 12.7838C9.72408 14.2302 12.069 14.2302 13.5154 12.7839L13.0911 12.3596L13.5154 12.7839C14.9617 11.3375 14.9617 8.99257 13.5154 7.54626L8.39476 2.42566C8.16044 2.19134 7.78054 2.19134 7.54623 2.42566C7.31191 2.65997 7.31191 3.03987 7.54623 3.27419L12.6668 8.39479L13.0911 7.97052L12.6668 8.39479C13.6445 9.37247 13.6445 10.9576 12.6668 11.9353L13.0399 12.3084L12.6668 11.9353C11.6891 12.913 10.104 12.913 9.1263 11.9353L3.03035 5.83938C2.45668 5.26571 2.45667 4.33556 3.03036 3.76184C3.60403 3.18818 4.53416 3.18817 5.10788 3.76185C5.10788 3.76186 5.10788 3.76186 5.10789 3.76186L11.2038 9.8578L11.601 9.46061L11.2038 9.8578C11.3735 10.0275 11.3735 10.3026 11.2038 10.4723L11.2038 10.4723C11.0341 10.642 10.759 10.642 10.5893 10.4723L5.46874 5.35171C5.23442 5.1174 4.85452 5.1174 4.62021 5.35171C4.38589 5.58602 4.38589 5.96592 4.62021 6.20024L9.74078 11.3208C10.3791 11.9591 11.414 11.9591 12.0523 11.3208C12.0523 11.3208 12.0523 11.3208 12.0523 11.3208M12.0523 11.3208C12.6907 10.6825 12.6906 9.64757 12.0523 9.00927L5.95641 2.91333L5.9564 2.91332",fillRule:"evenodd",clipRule:"evenodd"}}]},LinkSingle=React.forwardRef(function(props,ref){return React.createElement(IconBase,Object.assign({},props,{id:"link-single",ref,icon:element$2}))});LinkSingle.displayName="LinkSingle";var element$1={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.5935 3.47302C11.6354 2.51492 10.082 2.51492 9.12388 3.47302L7.83534 4.76157C7.60102 4.99588 7.22112 4.99588 6.98681 4.76157 6.75249 4.52725 6.75249 4.14735 6.98681 3.91304L8.27535 2.62449C9.70209 1.19776 12.0153 1.19776 13.442 2.62449 14.8688 4.05123 14.8688 6.36442 13.442 7.79116L12.1535 9.0797C11.9192 9.31402 11.5393 9.31402 11.3049 9.0797 11.0706 8.84539 11.0706 8.46549 11.3049 8.23117L12.5935 6.94263C13.5516 5.98452 13.5516 4.43113 12.5935 3.47302zM3.40637 12.6606C2.44827 11.7025 2.44827 10.1491 3.40637 9.19102L4.69492 7.90248C4.92923 7.66816 4.92923 7.28826 4.69492 7.05395 4.4606 6.81963 4.0807 6.81963 3.84639 7.05395L2.55784 8.34249C1.13111 9.76923 1.13111 12.0824 2.55784 13.5092 3.98458 14.9359 6.29777 14.9359 7.72451 13.5092L9.01305 12.2206C9.24737 11.9863 9.24737 11.6064 9.01305 11.3721 8.77874 11.1378 8.39884 11.1378 8.16452 11.3721L6.87598 12.6606C5.91787 13.6187 4.36448 13.6187 3.40637 12.6606zM3.5852 2.80332C3.35088 2.569 2.97098 2.569 2.73667 2.80332 2.50235 3.03763 2.50235 3.41753 2.73667 3.65185L12.4151 13.3302C12.6494 13.5646 13.0293 13.5646 13.2636 13.3302 13.4979 13.0959 13.4979 12.716 13.2636 12.4817L3.5852 2.80332z"}}]},UnlinkSingle=React.forwardRef(function(props,ref){return React.createElement(IconBase,Object.assign({},props,{id:"unlink-single",ref,icon:element$1}))});UnlinkSingle.displayName="UnlinkSingle";var element={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.6551 1.98906C11.7476 1.08113 10.2757 1.08149 9.3686 1.98987L4.82542 6.53955C4.75087 6.61421 4.69336 6.70411 4.65682 6.80309L3.2461 10.625C3.16506 10.8446 3.21909 11.0912 3.3845 11.2568C3.54991 11.4224 3.79651 11.4767 4.01616 11.3959L7.85031 9.98517C7.94979 9.94856 8.04014 9.89077 8.11508 9.81579L12.6552 5.27327C13.5618 4.36621 13.5618 2.89607 12.6551 1.98906ZM10.2177 2.83779C10.6562 2.39869 11.3677 2.39851 11.8064 2.8374C12.2447 3.27584 12.2447 3.9865 11.8065 4.42497L7.3392 8.89457L4.82213 9.82068L5.74706 7.31487L10.2177 2.83779Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.79238 13.2999C1.46101 13.2999 1.19238 13.5685 1.19238 13.8999C1.19238 14.2313 1.46101 14.4999 1.79238 14.4999H14.4924C14.8238 14.4999 15.0924 14.2313 15.0924 13.8999C15.0924 13.5685 14.8238 13.2999 14.4924 13.2999H1.79238Z"}}]},WriteSingle=React.forwardRef(function(props,ref){return React.createElement(IconBase,Object.assign({},props,{id:"write-single",ref,icon:element}))});WriteSingle.displayName="WriteSingle";const AddDocHyperLinkCommand={type:core.CommandType.COMMAND,id:"docs.command.add-hyper-link",async handler(accessor,params){if(!params)return!1;const{payload,unitId,selection}=params,commandService=accessor.get(core.ICommandService),id=core.generateRandomId(),doMutation=docsUi.addCustomRangeBySelectionFactory(accessor,{rangeId:id,rangeType:core.CustomRangeType.HYPERLINK,properties:{url:payload},unitId,selection});return doMutation?commandService.syncExecuteCommand(doMutation.id,doMutation.params):!1}},UpdateDocHyperLinkCommand={id:"docs.command.update-hyper-link",type:core.CommandType.COMMAND,handler(accessor,params){var _a2;if(!params)return!1;const{unitId,payload,segmentId}=params,commandService=accessor.get(core.ICommandService),univerInstanceService=accessor.get(core.IUniverInstanceService),currentSelection=accessor.get(docs.DocSelectionManagerService).getActiveTextRange(),doc=univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_DOC);if(!currentSelection||!doc)return!1;const newId=core.generateRandomId(),textRun=(_a2=core.getBodySlice(doc.getSelfOrHeaderFooterModel(segmentId).getBody(),currentSelection.startOffset,currentSelection.endOffset).textRuns)==null?void 0:_a2[0];textRun&&(textRun.ed=params.label.length+1);const replaceSelection=docsUi.replaceSelectionFactory(accessor,{unitId,body:{dataStream:`${core.DataStreamTreeTokenType.CUSTOM_RANGE_START}${params.label}${core.DataStreamTreeTokenType.CUSTOM_RANGE_END}`,customRanges:[{rangeId:newId,rangeType:core.CustomRangeType.HYPERLINK,startIndex:0,endIndex:params.label.length+1,properties:{url:payload}}],textRuns:textRun?[textRun]:void 0},selection:{startOffset:currentSelection.startOffset,endOffset:currentSelection.endOffset,collapsed:!1,segmentId}});return replaceSelection?commandService.syncExecuteCommand(replaceSelection.id,replaceSelection.params):!1}},DeleteDocHyperLinkCommand={type:core.CommandType.COMMAND,id:"docs.command.delete-hyper-link",async handler(accessor,params){if(!params)return!1;const{unitId,linkId,segmentId}=params,commandService=accessor.get(core.ICommandService),doMutation=docsUi.deleteCustomRangeFactory(accessor,{unitId,rangeId:linkId,segmentId});return doMutation?await commandService.syncExecuteCommand(doMutation.id,doMutation.params):!1}},shouldDisableAddLink=__name(accessor=>{var _a2;const textSelectionService=accessor.get(docs.DocSelectionManagerService),univerInstanceService=accessor.get(core.IUniverInstanceService),textRanges=textSelectionService.getDocRanges();if(!textRanges.length||textRanges.length>1)return!0;const activeRange=textRanges[0],doc=univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_DOC);if(!doc||!activeRange||activeRange.collapsed)return!0;const body=doc.getSelfOrHeaderFooterModel(activeRange.segmentId).getBody(),paragraphs=body==null?void 0:body.paragraphs;if(!paragraphs)return!0;for(let i=0,len=paragraphs.length;i<len;i++){const p=paragraphs[i];if(activeRange.startOffset<=p.startIndex&&activeRange.endOffset>p.startIndex)return!0;if(p.startIndex>activeRange.endOffset)break}return!core.BuildTextUtils.customRange.getCustomRangesInterestsWithRange(activeRange,(_a2=body.customRanges)!=null?_a2:[]).every(range=>range.rangeType===core.CustomRangeType.HYPERLINK)},"shouldDisableAddLink"),ShowDocHyperLinkEditPopupOperation={type:core.CommandType.OPERATION,id:"doc.operation.show-hyper-link-edit-popup",handler(accessor,params){var _a2;const linkInfo=params==null?void 0:params.link,univerInstanceService=accessor.get(core.IUniverInstanceService);if(shouldDisableAddLink(accessor)&&!linkInfo)return!1;const hyperLinkService=accessor.get(DocHyperLinkPopupService),unitId=(linkInfo==null?void 0:linkInfo.unitId)||((_a2=univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_DOC))==null?void 0:_a2.getUnitId());return unitId?(hyperLinkService.showEditPopup(unitId,linkInfo),!0):!1}},ToggleDocHyperLinkInfoPopupOperation={type:core.CommandType.OPERATION,id:"doc.operation.toggle-hyper-link-info-popup",handler(accessor,params){const hyperLinkService=accessor.get(DocHyperLinkPopupService);return params?(hyperLinkService.showInfoPopup(params),!0):(hyperLinkService.hideInfoPopup(),!0)}},ClickDocHyperLinkOperation={type:core.CommandType.OPERATION,id:"doc.operation.click-hyper-link",handler(accessor,params){var _a2,_b2,_c2;if(!params)return!1;const{unitId,linkId,segmentId}=params,doc=accessor.get(core.IUniverInstanceService).getUnit(unitId,core.UniverInstanceType.UNIVER_DOC),body=doc==null?void 0:doc.getSelfOrHeaderFooterModel(segmentId).getBody(),link=(_c2=(_b2=(_a2=body==null?void 0:body.customRanges)==null?void 0:_a2.find(range=>range.rangeId===linkId&&range.rangeType===core.CustomRangeType.HYPERLINK))==null?void 0:_b2.properties)==null?void 0:_c2.url;return link&&window.open(link,"_blank","noopener noreferrer"),!0}},styles$1={docLink:"univer-doc-link",docLinkType:"univer-doc-link-type",docLinkContent:"univer-doc-link-content",docLinkContentError:"univer-doc-link-content-error",docLinkUrl:"univer-doc-link-url",docLinkOperations:"univer-doc-link-operations",docLinkOperation:"univer-doc-link-operation",docLinkOperationError:"univer-doc-link-operation-error"},DocLinkPopup=__name(()=>{var _a2,_b2;const hyperLinkService=core.useDependency(DocHyperLinkPopupService),commandService=core.useDependency(core.ICommandService),messageService=core.useDependency(ui.IMessageService),localeService=core.useDependency(core.LocaleService),currentPopup=ui.useObservable(hyperLinkService.showingLink$),univerInstanceService=core.useDependency(core.IUniverInstanceService);if(!currentPopup)return null;const{unitId,linkId,segmentId}=currentPopup,doc=univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_DOC),body=doc==null?void 0:doc.getSelfOrHeaderFooterModel(segmentId).getBody(),link=(_a2=body==null?void 0:body.customRanges)==null?void 0:_a2.find(range=>range.rangeId===linkId&&range.rangeType===core.CustomRangeType.HYPERLINK);if(!link)return null;const url=(_b2=link.properties)==null?void 0:_b2.url;return React.createElement("div",{className:styles$1.docLink,onClick:__name(()=>{hyperLinkService.hideInfoPopup()},"onClick")},React.createElement("div",{className:cs(styles$1.docLinkContent),onClick:__name(()=>window.open(url),"onClick")},React.createElement("div",{className:styles$1.docLinkType},React.createElement(LinkSingle,null)),React.createElement(design.Tooltip,{showIfEllipsis:!0,title:url},React.createElement("span",{className:styles$1.docLinkUrl},url))),React.createElement("div",{className:styles$1.docLinkOperations},React.createElement("div",{className:cs(styles$1.docLinkOperation),onClick:__name(()=>{navigator.clipboard.writeText(url),messageService.show({content:localeService.t("docLink.info.coped"),type:design.MessageType.Info})},"onClick")},React.createElement(design.Tooltip,{placement:"bottom",title:localeService.t("docLink.info.copy")},React.createElement(CopySingle,null))),React.createElement("div",{className:styles$1.docLinkOperation,onClick:__name(()=>{commandService.executeCommand(ShowDocHyperLinkEditPopupOperation.id,{link:currentPopup})},"onClick")},React.createElement(design.Tooltip,{placement:"bottom",title:localeService.t("docLink.info.edit")},React.createElement(WriteSingle,null))),React.createElement("div",{className:styles$1.docLinkOperation,onClick:__name(()=>{commandService.executeCommand(DeleteDocHyperLinkCommand.id,{unitId,linkId:link.rangeId,segmentId})},"onClick")},React.createElement(design.Tooltip,{placement:"bottom",title:localeService.t("docLink.info.cancel")},React.createElement(UnlinkSingle,null)))))},"DocLinkPopup");DocLinkPopup.componentKey="univer.doc.link-info-popup";var __defProp$5=Object.defineProperty,__getOwnPropDesc$5=Object.getOwnPropertyDescriptor,__decorateClass$5=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$5(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$5(target,key,result),result},"__decorateClass$5"),__decorateParam$5=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$5");const SKIT_PLACEHOLDER=0;let DocHyperLinkPopupService=(_a=class extends core.Disposable{constructor(_docCanvasPopupManagerService,_textSelectionManagerService,_univerInstanceService){super();__publicField(this,"_editingLink$",new rxjs.BehaviorSubject(null));__publicField(this,"_showingLink$",new rxjs.BehaviorSubject(null));__publicField(this,"editingLink$",this._editingLink$.asObservable());__publicField(this,"showingLink$",this._showingLink$.asObservable());__publicField(this,"_editPopup",null);__publicField(this,"_infoPopup",null);this._docCanvasPopupManagerService=_docCanvasPopupManagerService,this._textSelectionManagerService=_textSelectionManagerService,this._univerInstanceService=_univerInstanceService,this.disposeWithMe(()=>{this._editingLink$.complete(),this._showingLink$.complete()})}get editing(){return this._editingLink$.value}get showing(){return this._showingLink$.value}showEditPopup(unitId,linkInfo){var _a2,_b2,_c2;this._editPopup&&this._editPopup.dispose(),this._editingLink$.next(linkInfo);let activeRange=this._textSelectionManagerService.getActiveTextRange();if(linkInfo){const{unitId:unitId2,linkId,segmentId,segmentPage}=linkInfo,doc=this._univerInstanceService.getUnit(unitId2,core.UniverInstanceType.UNIVER_DOC),range=(_c2=(_b2=(_a2=doc==null?void 0:doc.getSelfOrHeaderFooterModel(segmentId))==null?void 0:_a2.getBody())==null?void 0:_b2.customRanges)==null?void 0:_c2.find(i=>i.rangeId===linkId);range&&(activeRange={collapsed:!1,startOffset:range.startIndex+SKIT_PLACEHOLDER,endOffset:range.endIndex+1,segmentId,segmentPage},this._textSelectionManagerService.replaceTextRanges([{startOffset:range.startIndex,endOffset:range.endIndex+1}]))}return activeRange?(this._editPopup=this._docCanvasPopupManagerService.attachPopupToRange(activeRange,{componentKey:DocHyperLinkEdit.componentKey,direction:"bottom"},unitId),this._editPopup):null}hideEditPopup(){var _a2;this._editingLink$.next(null),(_a2=this._editPopup)==null||_a2.dispose()}showInfoPopup(info){var _a2,_b2,_c2,_d2,_e2,_f2;const{linkId,unitId,segmentId,segmentPage}=info;if(((_a2=this.showing)==null?void 0:_a2.linkId)===linkId&&((_b2=this.showing)==null?void 0:_b2.unitId)===unitId&&((_c2=this.showing)==null?void 0:_c2.segmentId)===segmentId&&((_d2=this.showing)==null?void 0:_d2.segmentPage)===segmentPage)return;this._infoPopup&&this._infoPopup.dispose();const doc=this._univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_DOC);if(!doc)return;const range=(_f2=(_e2=doc.getSelfOrHeaderFooterModel(info.segmentId).getBody())==null?void 0:_e2.customRanges)==null?void 0:_f2.find(i=>i.rangeId===linkId);if(this._showingLink$.next({unitId,linkId,segmentId,segmentPage}),!!range)return this._infoPopup=this._docCanvasPopupManagerService.attachPopupToRange({collapsed:!1,startOffset:range.startIndex+SKIT_PLACEHOLDER,endOffset:range.endIndex+1,segmentId:info.segmentId,segmentPage:info.segmentPage},{componentKey:DocLinkPopup.componentKey,direction:"top-center",multipleDirection:"top",onClickOutside:__name(()=>{this.hideInfoPopup()},"onClickOutside")},info.unitId),this._infoPopup}hideInfoPopup(){var _a2;this._showingLink$.next(null),(_a2=this._infoPopup)==null||_a2.dispose()}},__name(_a,"DocHyperLinkPopupService"),_a);DocHyperLinkPopupService=__decorateClass$5([__decorateParam$5(0,core.Inject(docsUi.DocCanvasPopManagerService)),__decorateParam$5(1,core.Inject(docs.DocSelectionManagerService)),__decorateParam$5(2,core.IUniverInstanceService)],DocHyperLinkPopupService);const styles={docsLinkEdit:"univer-docs-link-edit",docsLinkEditTitle:"univer-docs-link-edit-title",docsLinkEditClose:"univer-docs-link-edit-close",docsLinkEditButtons:"univer-docs-link-edit-buttons",docsLinkEditButton:"univer-docs-link-edit-button"};function hasProtocol(urlString){return/^[a-zA-Z]+:\/\//.test(urlString)}__name(hasProtocol,"hasProtocol");function isEmail(url){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(url)}__name(isEmail,"isEmail");function transformUrl(urlStr){return hasProtocol(urlStr)?urlStr:isEmail(urlStr)?`mailto://${urlStr}`:`https://${urlStr}`}__name(transformUrl,"transformUrl");const DocHyperLinkEdit=__name(()=>{var _a2;const hyperLinkService=core.useDependency(DocHyperLinkPopupService),localeService=core.useDependency(core.LocaleService),editing=core.useObservable(hyperLinkService.editingLink$),commandService=core.useDependency(core.ICommandService),univerInstanceService=core.useDependency(core.IUniverInstanceService),renderManagerService=core.useDependency(engineRender.IRenderManagerService),docSelectionManagerService=core.useDependency(docs.DocSelectionManagerService),[link,setLink]=React.useState(""),[label,setLabel]=React.useState(""),[showError,setShowError]=React.useState(!1),isLegal=core.Tools.isLegalUrl(link),doc=editing?univerInstanceService.getUnit(editing.unitId,core.UniverInstanceType.UNIVER_DOC):univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_DOC),docSelectionRenderService=(_a2=renderManagerService.getRenderById(doc.getUnitId()))==null?void 0:_a2.with(docsUi.DocSelectionRenderService);React.useEffect(()=>{var _a3,_b2,_c2,_d2,_e2,_f2,_g,_h,_i;const activeRange=docSelectionManagerService.getActiveTextRange();if(!activeRange)return;if(editing){const body=(_a3=doc==null?void 0:doc.getSelfOrHeaderFooterModel(editing.segmentId))==null?void 0:_a3.getBody(),matchedRange2=(_b2=body==null?void 0:body.customRanges)==null?void 0:_b2.find(i=>(editing==null?void 0:editing.linkId)===i.rangeId);doc&&matchedRange2&&(setLink((_d2=(_c2=matchedRange2.properties)==null?void 0:_c2.url)!=null?_d2:""),setLabel(docsUi.getPlainTextFormBody(core.getBodySlice(body,matchedRange2.startIndex,matchedRange2.endIndex))));return}const matchedRange=(_g=(_f2=(_e2=doc==null?void 0:doc.getSelfOrHeaderFooterModel(activeRange.segmentId))==null?void 0:_e2.getBody())==null?void 0:_f2.customRanges)==null?void 0:_g.find(i=>Math.max(activeRange.startOffset,i.startIndex)<=Math.min(activeRange.endOffset-1,i.endIndex));doc&&matchedRange&&setLink((_i=(_h=matchedRange==null?void 0:matchedRange.properties)==null?void 0:_h.url)!=null?_i:"")},[doc,editing,docSelectionManagerService,univerInstanceService]),React.useEffect(()=>(docSelectionRenderService&&docSelectionRenderService.blurEditor(),()=>{docSelectionRenderService&&docSelectionRenderService.focusEditor()}),[docSelectionRenderService]);const handleCancel=__name(()=>{hyperLinkService.hideEditPopup()},"handleCancel"),handleConfirm=__name(()=>{if(setShowError(!0),!isLegal||!doc)return;const linkFinal=transformUrl(link);if(!editing)commandService.executeCommand(AddDocHyperLinkCommand.id,{unitId:doc.getUnitId(),payload:linkFinal});else{if(!label)return;commandService.executeCommand(UpdateDocHyperLinkCommand.id,{unitId:doc.getUnitId(),payload:linkFinal,linkId:editing.linkId,label,segmentId:editing.segmentId})}hyperLinkService.hideEditPopup()},"handleConfirm");if(doc)return React.createElement("div",{className:styles.docsLinkEdit},React.createElement("div",null,editing?React.createElement(design.FormLayout,{label:localeService.t("docLink.edit.label"),error:showError&&!label?localeService.t("docLink.edit.labelError"):""},React.createElement(design.Input,{value:label,onChange:setLabel,autoFocus:!0,onKeyDown:__name(evt=>{evt.keyCode===ui.KeyCode.ENTER&&handleConfirm()},"onKeyDown")})):null,React.createElement(design.FormLayout,{label:localeService.t("docLink.edit.address"),error:showError&&!isLegal?localeService.t("docLink.edit.addressError"):""},React.createElement(design.Input,{value:link,onChange:setLink,autoFocus:!0,onKeyDown:__name(evt=>{evt.keyCode===ui.KeyCode.ENTER&&handleConfirm()},"onKeyDown")}))),React.createElement("div",{className:styles.docsLinkEditButtons},React.createElement(design.Button,{className:styles.docsLinkEditButton,onClick:handleCancel},localeService.t("docLink.edit.cancel")),React.createElement(design.Button,{disabled:!link,className:styles.docsLinkEditButton,type:"primary",onClick:handleConfirm},localeService.t("docLink.edit.confirm"))))},"DocHyperLinkEdit");DocHyperLinkEdit.componentKey="docs-hyper-link-edit";const DOC_LINK_ICON="doc-hyper-link-icon";function AddHyperLinkMenuItemFactory(accessor){return{id:ShowDocHyperLinkEditPopupOperation.id,type:ui.MenuItemType.BUTTON,icon:DOC_LINK_ICON,title:"docLink.menu.tooltip",tooltip:"docLink.menu.tooltip",hidden$:ui.getMenuHiddenObservable(accessor,core.UniverInstanceType.UNIVER_DOC),disabled$:new rxjs.Observable(function(subscribe){const observer=accessor.get(docs.DocSelectionManagerService).textSelection$.pipe(rxjs.debounceTime(16)).subscribe(()=>{subscribe.next(shouldDisableAddLink(accessor))});return()=>{observer.unsubscribe()}})}}__name(AddHyperLinkMenuItemFactory,"AddHyperLinkMenuItemFactory");const addLinkShortcut={id:ShowDocHyperLinkEditPopupOperation.id,binding:ui.MetaKeys.CTRL_COMMAND|ui.KeyCode.K,description:"docLink.menu.tooltip",preconditions:docsUi.whenDocAndEditorFocused},menuSchema={[ui.RibbonStartGroup.OTHERS]:{[ShowDocHyperLinkEditPopupOperation.id]:{order:0,menuItemFactory:AddHyperLinkMenuItemFactory}},[ui.ContextMenuPosition.MAIN_AREA]:{[ui.ContextMenuGroup.DATA]:{[ShowDocHyperLinkEditPopupOperation.id]:{order:0,menuItemFactory:AddHyperLinkMenuItemFactory}}}};var __defProp$4=Object.defineProperty,__getOwnPropDesc$4=Object.getOwnPropertyDescriptor,__decorateClass$4=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$4(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$4(target,key,result),result},"__decorateClass$4"),__decorateParam$4=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$4");let DocHyperLinkUIController=(_b=class extends core.Disposable{constructor(_componentManager,_commandService,_menuManagerService,_injector,_shortcutService){super(),this._componentManager=_componentManager,this._commandService=_commandService,this._menuManagerService=_menuManagerService,this._injector=_injector,this._shortcutService=_shortcutService,this._initComponents(),this._initCommands(),this._initMenus(),this._initShortcut()}_initComponents(){[[DocHyperLinkEdit,DocHyperLinkEdit.componentKey],[DocLinkPopup,DocLinkPopup.componentKey],[LinkSingle,DOC_LINK_ICON]].forEach(([comp,key])=>{this._componentManager.register(key,comp)})}_initCommands(){[AddDocHyperLinkCommand,UpdateDocHyperLinkCommand,DeleteDocHyperLinkCommand,ShowDocHyperLinkEditPopupOperation,ToggleDocHyperLinkInfoPopupOperation,ClickDocHyperLinkOperation].forEach(command=>{this._commandService.registerCommand(command)})}_initShortcut(){[addLinkShortcut].forEach(shortcut=>{this._shortcutService.registerShortcut(shortcut)})}_initMenus(){this._menuManagerService.mergeMenu(menuSchema)}},__name(_b,"DocHyperLinkUIController"),_b);DocHyperLinkUIController=__decorateClass$4([core.OnLifecycle(core.LifecycleStages.Starting,DocHyperLinkUIController),__decorateParam$4(0,core.Inject(ui.ComponentManager)),__decorateParam$4(1,core.ICommandService),__decorateParam$4(2,ui.IMenuManagerService),__decorateParam$4(3,core.Inject(core.Injector)),__decorateParam$4(4,ui.IShortcutService)],DocHyperLinkUIController);var __defProp$3=Object.defineProperty,__getOwnPropDesc$3=Object.getOwnPropertyDescriptor,__decorateClass$3=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$3(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$3(target,key,result),result},"__decorateClass$3"),__decorateParam$3=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$3");let DocHyperLinkSelectionController=(_c=class extends core.Disposable{constructor(_commandService,_univerInstanceService,_docHyperLinkService){super(),this._commandService=_commandService,this._univerInstanceService=_univerInstanceService,this._docHyperLinkService=_docHyperLinkService,this._initSelectionChange()}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(commandInfo=>{var _a2,_b2,_c2;if(commandInfo.id===docs.SetTextSelectionsOperation.id){const params=commandInfo.params,{unitId,ranges,segmentId}=params,doc=this._univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_DOC),primary=ranges[0];if(primary&&doc){const{startOffset,endOffset,collapsed,segmentPage}=primary,customRanges=(_b2=(_a2=doc.getSelfOrHeaderFooterModel(segmentId))==null?void 0:_a2.getBody())==null?void 0:_b2.customRanges;if(collapsed){const index=(_c2=customRanges==null?void 0:customRanges.findIndex(value=>value.startIndex<startOffset&&value.endIndex>endOffset-1))!=null?_c2:-1;if(index>-1){const customRange=customRanges[index];this._docHyperLinkService.showInfoPopup({unitId,linkId:customRange.rangeId,segmentId,segmentPage});return}}else if(customRanges==null?void 0:customRanges.find(value=>value.startIndex<=startOffset&&value.endIndex>=endOffset-1))return}this._docHyperLinkService.hideInfoPopup(),this._docHyperLinkService.hideEditPopup()}}))}},__name(_c,"DocHyperLinkSelectionController"),_c);DocHyperLinkSelectionController=__decorateClass$3([core.OnLifecycle(core.LifecycleStages.Ready,DocHyperLinkSelectionController),__decorateParam$3(0,core.ICommandService),__decorateParam$3(1,core.IUniverInstanceService),__decorateParam$3(2,core.Inject(DocHyperLinkPopupService))],DocHyperLinkSelectionController);var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2");let DocHyperLinkRenderController=(_d=class extends core.Disposable{constructor(_context,_docInterceptorService,_hyperLinkService,_docRenderController){super(),this._context=_context,this._docInterceptorService=_docInterceptorService,this._hyperLinkService=_hyperLinkService,this._docRenderController=_docRenderController,this._init(),this._initReRender()}_init(){this._docInterceptorService.intercept(docs.DOC_INTERCEPTOR_POINT.CUSTOM_RANGE,{handler:__name((data,pos,next)=>{if(!data)return next(data);const{unitId}=pos,activeLink=this._hyperLinkService.showing,{linkId,unitId:linkUnitId}=activeLink||{},isActive=linkUnitId===unitId&&data.rangeId===linkId;return next({...data,active:isActive})},"handler")})}_initReRender(){this.disposeWithMe(this._hyperLinkService.showingLink$.pipe(rxjs.distinctUntilChanged((prev,aft)=>(prev==null?void 0:prev.linkId)===(aft==null?void 0:aft.linkId)&&(prev==null?void 0:prev.unitId)===(aft==null?void 0:aft.unitId)),rxjs.pairwise()).subscribe(([preLink,link])=>{link?link.unitId===this._context.unitId&&this._docRenderController.reRender(link.unitId):preLink&&preLink.unitId===this._context.unitId&&this._docRenderController.reRender(preLink.unitId)}))}},__name(_d,"DocHyperLinkRenderController"),_d);DocHyperLinkRenderController=__decorateClass$2([__decorateParam$2(1,core.Inject(docs.DocInterceptorService)),__decorateParam$2(2,core.Inject(DocHyperLinkPopupService)),__decorateParam$2(3,core.Inject(docsUi.DocRenderController))],DocHyperLinkRenderController);var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1");let DocHyperLinkEventRenderController=(_e=class extends core.Disposable{constructor(_context,_docEventManagerService,_commandService,_hyperLinkPopupService,_docSkeletonManagerService,_docSelectionManagerService){super(),this._context=_context,this._docEventManagerService=_docEventManagerService,this._commandService=_commandService,this._hyperLinkPopupService=_hyperLinkPopupService,this._docSkeletonManagerService=_docSkeletonManagerService,this._docSelectionManagerService=_docSelectionManagerService,this._initHover(),this._initClick()}get _skeleton(){return this._docSkeletonManagerService.getSkeleton()}_hideInfoPopup(){this._hyperLinkPopupService.showing&&this._commandService.executeCommand(ToggleDocHyperLinkInfoPopupOperation.id)}_initHover(){this.disposeWithMe(this._docEventManagerService.hoverCustomRanges$.subscribe(ranges=>{var _a2;const link=ranges.find(range=>range.range.rangeType===core.CustomRangeType.HYPERLINK),activeRanges=this._docSelectionManagerService.getCurrentTextRanges(),currentSegmentId=activeRanges==null?void 0:activeRanges[0].segmentId;if(((_a2=link==null?void 0:link.segmentId)!=null?_a2:"")!==currentSegmentId){this._hideInfoPopup();return}link?this._commandService.executeCommand(ToggleDocHyperLinkInfoPopupOperation.id,{unitId:this._context.unitId,linkId:link.range.rangeId,segmentId:link.segmentId,segmentPage:link.segmentPageIndex,rangeId:link.range.rangeId}):this._hideInfoPopup()}))}_initClick(){this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe(range=>{const link=range.range;link&&this._commandService.executeCommand(ClickDocHyperLinkOperation.id,{unitId:this._context.unitId,linkId:link.rangeId,segmentId:range.segmentId})}))}},__name(_e,"DocHyperLinkEventRenderController"),_e);DocHyperLinkEventRenderController=__decorateClass$1([__decorateParam$1(1,core.Inject(docsUi.DocEventManagerService)),__decorateParam$1(2,core.ICommandService),__decorateParam$1(3,core.Inject(DocHyperLinkPopupService)),__decorateParam$1(4,core.Inject(docs.DocSkeletonManagerService)),__decorateParam$1(5,core.Inject(docs.DocSelectionManagerService))],DocHyperLinkEventRenderController);const PLUGIN_CONFIG_KEY="docs-hyper-link-ui.config",defaultPluginConfig={};var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key,value)=>key in obj?__defProp2(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),__publicField2=__name((obj,key,value)=>__defNormalProp2(obj,typeof key!="symbol"?key+"":key,value),"__publicField");exports2.UniverDocsHyperLinkUIPlugin=(_f=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_renderManagerSrv,_configService){super(),this._config=_config,this._injector=_injector,this._renderManagerSrv=_renderManagerSrv,this._configService=_configService;const{menu,...rest}=this._config;menu&&this._configService.setConfig("menu",menu,{merge:!0}),this._configService.setConfig(PLUGIN_CONFIG_KEY,rest)}onStarting(){[[DocHyperLinkPopupService],[DocHyperLinkUIController],[DocHyperLinkSelectionController]].forEach(dep=>{this._injector.add(dep)})}onRendered(){this._initRenderModule()}_initRenderModule(){[[DocHyperLinkRenderController],[DocHyperLinkEventRenderController]].forEach(dep=>{this._renderManagerSrv.registerRenderModule(core.UniverInstanceType.UNIVER_DOC,dep)})}},__name(_f,"UniverDocsHyperLinkUIPlugin"),_f),__publicField2(exports2.UniverDocsHyperLinkUIPlugin,"pluginName",DOC_HYPER_LINK_UI_PLUGIN),__publicField2(exports2.UniverDocsHyperLinkUIPlugin,"type",core.UniverInstanceType.UNIVER_DOC),exports2.UniverDocsHyperLinkUIPlugin=__decorateClass([core.DependentOn(docsHyperLink.UniverDocsHyperLinkPlugin),__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,engineRender.IRenderManagerService),__decorateParam(3,core.IConfigService)],exports2.UniverDocsHyperLinkUIPlugin),Object.defineProperty(exports2,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/docs-hyper-link-ui",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.14",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Univer thread comment plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -48,31 +48,31 @@
|
|
|
48
48
|
"clsx": ">=2.0.0",
|
|
49
49
|
"react": "^16.9.0 || ^17.0.0 || ^18.0.0",
|
|
50
50
|
"rxjs": ">=7.0.0",
|
|
51
|
-
"@univerjs/core": "0.2.
|
|
52
|
-
"@univerjs/
|
|
53
|
-
"@univerjs/docs
|
|
54
|
-
"@univerjs/
|
|
55
|
-
"@univerjs/docs-
|
|
56
|
-
"@univerjs/
|
|
57
|
-
"@univerjs/
|
|
51
|
+
"@univerjs/core": "0.2.14",
|
|
52
|
+
"@univerjs/design": "0.2.14",
|
|
53
|
+
"@univerjs/docs": "0.2.14",
|
|
54
|
+
"@univerjs/engine-render": "0.2.14",
|
|
55
|
+
"@univerjs/docs-ui": "0.2.14",
|
|
56
|
+
"@univerjs/ui": "0.2.14",
|
|
57
|
+
"@univerjs/docs-hyper-link": "0.2.14"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@univerjs/icons": "^0.1.
|
|
60
|
+
"@univerjs/icons": "^0.1.78",
|
|
61
|
+
"clsx": "^2.1.1",
|
|
62
|
+
"@univerjs/core": "0.2.14",
|
|
63
|
+
"@univerjs/design": "0.2.14",
|
|
64
|
+
"@univerjs/docs": "0.2.14",
|
|
65
|
+
"@univerjs/engine-render": "0.2.14",
|
|
66
|
+
"@univerjs/ui": "0.2.14",
|
|
67
|
+
"@univerjs/docs-hyper-link": "0.2.14"
|
|
61
68
|
},
|
|
62
69
|
"devDependencies": {
|
|
63
|
-
"clsx": "^2.1.1",
|
|
64
70
|
"react": "18.3.1",
|
|
65
71
|
"rxjs": "^7.8.1",
|
|
66
|
-
"typescript": "^5.
|
|
67
|
-
"vite": "^5.4.
|
|
72
|
+
"typescript": "^5.6.2",
|
|
73
|
+
"vite": "^5.4.4",
|
|
68
74
|
"vitest": "^2.0.5",
|
|
69
|
-
"@univerjs/
|
|
70
|
-
"@univerjs/design": "0.2.12",
|
|
71
|
-
"@univerjs/docs-hyper-link": "0.2.12",
|
|
72
|
-
"@univerjs/engine-render": "0.2.12",
|
|
73
|
-
"@univerjs/shared": "0.2.12",
|
|
74
|
-
"@univerjs/ui": "0.2.12",
|
|
75
|
-
"@univerjs/core": "0.2.12"
|
|
75
|
+
"@univerjs-infra/shared": "0.2.14"
|
|
76
76
|
},
|
|
77
77
|
"univerSpace": {
|
|
78
78
|
".": {
|