@univerjs/docs-hyper-link-ui 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +8 -11
- package/lib/umd/index.js +1 -1
- package/package.json +10 -10
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"),docsHyperLink=require("@univerjs/docs-hyper-link"),engineRender=require("@univerjs/engine-render"),docs=require("@univerjs/docs"),docsUi=require("@univerjs/docs-ui"),rxjs=require("rxjs"),design=require("@univerjs/design"),ui=require("@univerjs/ui"),React=require("react"),PLUGIN_CONFIG_KEY="docs-hyper-link-ui.config",defaultPluginConfig={},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}},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$1={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(core.BuildTextUtils.transform.getPlainText(core.getBodySlice(body,matchedRange2.startIndex,matchedRange2.endIndex).dataStream)));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$1.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$1.docsLinkEditButtons},React.createElement(design.Button,{className:styles$1.docsLinkEditButton,onClick:handleCancel},localeService.t("docLink.edit.cancel")),React.createElement(design.Button,{disabled:!link,className:styles$1.docsLinkEditButton,type:"primary",onClick:handleConfirm},localeService.t("docLink.edit.confirm"))))},"DocHyperLinkEdit");DocHyperLinkEdit.componentKey="docs-hyper-link-edit";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";function r(e){var t,f,n="";if(typeof e=="string"||typeof e=="number")n+=e;else if(typeof e=="object")if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f)}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}__name(r,"r");function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}__name(clsx,"clsx");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=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={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.docLink,onClick:__name(()=>{hyperLinkService.hideInfoPopup()},"onClick")},React.createElement("div",{className:clsx(styles.docLinkContent),onClick:__name(()=>window.open(url),"onClick")},React.createElement("div",{className:styles.docLinkType},React.createElement(LinkSingle,null)),React.createElement(design.Tooltip,{showIfEllipsis:!0,title:url},React.createElement("span",{className:styles.docLinkUrl},url))),React.createElement("div",{className:styles.docLinkOperations},React.createElement("div",{className:clsx(styles.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.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.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);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 DocHyperLinkSelectionController=(_a2=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(_a2,"DocHyperLinkSelectionController"),_a2);DocHyperLinkSelectionController=__decorateClass$4([__decorateParam$4(0,core.ICommandService),__decorateParam$4(1,core.IUniverInstanceService),__decorateParam$4(2,core.Inject(DocHyperLinkPopupService))],DocHyperLinkSelectionController);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 DocHyperLinkEventRenderController=(_a3=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.getTextRanges(),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(_a3,"DocHyperLinkEventRenderController"),_a3);DocHyperLinkEventRenderController=__decorateClass$3([__decorateParam$3(1,core.Inject(docsUi.DocEventManagerService)),__decorateParam$3(2,core.ICommandService),__decorateParam$3(3,core.Inject(DocHyperLinkPopupService)),__decorateParam$3(4,core.Inject(docs.DocSkeletonManagerService)),__decorateParam$3(5,core.Inject(docs.DocSelectionManagerService))],DocHyperLinkEventRenderController);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);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$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 DocHyperLinkUIController=(_a5=class extends core.Disposable{constructor(_componentManager,_commandService,_menuManagerService,_shortcutService){super(),this._componentManager=_componentManager,this._commandService=_commandService,this._menuManagerService=_menuManagerService,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(_a5,"DocHyperLinkUIController"),_a5);DocHyperLinkUIController=__decorateClass$1([__decorateParam$1(0,core.Inject(ui.ComponentManager)),__decorateParam$1(1,core.ICommandService),__decorateParam$1(2,ui.IMenuManagerService),__decorateParam$1(3,ui.IShortcutService)],DocHyperLinkUIController);const DOC_HYPER_LINK_UI_PLUGIN="DOC_HYPER_LINK_UI_PLUGIN";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)}),this._injector.get(DocHyperLinkUIController)}onReady(){this._injector.get(DocHyperLinkSelectionController)}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"),docsHyperLink=require("@univerjs/docs-hyper-link"),engineRender=require("@univerjs/engine-render"),docs=require("@univerjs/docs"),docsUi=require("@univerjs/docs-ui"),rxjs=require("rxjs"),design=require("@univerjs/design"),ui=require("@univerjs/ui"),React=require("react"),PLUGIN_CONFIG_KEY="docs-hyper-link-ui.config",defaultPluginConfig={},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}},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$1={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),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);React.useEffect(()=>{var _a7,_b,_c,_d,_e,_f,_g,_h,_i;const activeRange=docSelectionManagerService.getActiveTextRange();if(!activeRange)return;if(editing){const body2=(_a7=doc==null?void 0:doc.getSelfOrHeaderFooterModel(editing.segmentId))==null?void 0:_a7.getBody(),matchedRange2=(_b=body2==null?void 0:body2.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(core.BuildTextUtils.transform.getPlainText(core.getBodySlice(body2,matchedRange2.startIndex,matchedRange2.endIndex).dataStream)));return}const body=(_e=doc==null?void 0:doc.getSelfOrHeaderFooterModel(activeRange.segmentId))==null?void 0:_e.getBody(),selection=body?core.BuildTextUtils.selection.getInsertSelection(activeRange,body):null,matchedRange=selection&&((_g=core.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(selection,(_f=body==null?void 0:body.customRanges)!=null?_f:[]))==null?void 0:_g[0]);doc&&matchedRange&&setLink((_i=(_h=matchedRange==null?void 0:matchedRange.properties)==null?void 0:_h.url)!=null?_i:"")},[doc,editing,docSelectionManagerService,univerInstanceService]);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$1.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$1.docsLinkEditButtons},React.createElement(design.Button,{className:styles$1.docsLinkEditButton,onClick:handleCancel},localeService.t("docLink.edit.cancel")),React.createElement(design.Button,{disabled:!link,className:styles$1.docsLinkEditButton,type:"primary",onClick:handleConfirm},localeService.t("docLink.edit.confirm"))))},"DocHyperLinkEdit");DocHyperLinkEdit.componentKey="docs-hyper-link-edit";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";function r(e){var t,f,n="";if(typeof e=="string"||typeof e=="number")n+=e;else if(typeof e=="object")if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f)}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}__name(r,"r");function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}__name(clsx,"clsx");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=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.getCustomRangesInterestsWithSelection(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={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.docLink,onClick:__name(()=>{hyperLinkService.hideInfoPopup()},"onClick")},React.createElement("div",{className:clsx(styles.docLinkContent),onClick:__name(()=>window.open(url),"onClick")},React.createElement("div",{className:styles.docLinkType},React.createElement(LinkSingle,null)),React.createElement(design.Tooltip,{showIfEllipsis:!0,title:url},React.createElement("span",{className:styles.docLinkUrl},url))),React.createElement("div",{className:styles.docLinkOperations},React.createElement("div",{className:clsx(styles.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.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.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);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 DocHyperLinkSelectionController=(_a2=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(_a2,"DocHyperLinkSelectionController"),_a2);DocHyperLinkSelectionController=__decorateClass$4([__decorateParam$4(0,core.ICommandService),__decorateParam$4(1,core.IUniverInstanceService),__decorateParam$4(2,core.Inject(DocHyperLinkPopupService))],DocHyperLinkSelectionController);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 DocHyperLinkEventRenderController=(_a3=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.getTextRanges(),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(_a3,"DocHyperLinkEventRenderController"),_a3);DocHyperLinkEventRenderController=__decorateClass$3([__decorateParam$3(1,core.Inject(docsUi.DocEventManagerService)),__decorateParam$3(2,core.ICommandService),__decorateParam$3(3,core.Inject(DocHyperLinkPopupService)),__decorateParam$3(4,core.Inject(docs.DocSkeletonManagerService)),__decorateParam$3(5,core.Inject(docs.DocSelectionManagerService))],DocHyperLinkEventRenderController);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);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$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 DocHyperLinkUIController=(_a5=class extends core.Disposable{constructor(_componentManager,_commandService,_menuManagerService,_shortcutService){super(),this._componentManager=_componentManager,this._commandService=_commandService,this._menuManagerService=_menuManagerService,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(_a5,"DocHyperLinkUIController"),_a5);DocHyperLinkUIController=__decorateClass$1([__decorateParam$1(0,core.Inject(ui.ComponentManager)),__decorateParam$1(1,core.ICommandService),__decorateParam$1(2,ui.IMenuManagerService),__decorateParam$1(3,ui.IShortcutService)],DocHyperLinkUIController);const DOC_HYPER_LINK_UI_PLUGIN="DOC_HYPER_LINK_UI_PLUGIN";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)}),this._injector.get(DocHyperLinkUIController)}onReady(){this._injector.get(DocHyperLinkSelectionController)}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
|
@@ -6,7 +6,7 @@ import { CommandType, ICommandService, generateRandomId, CustomRangeType, IUnive
|
|
|
6
6
|
import { UniverDocsHyperLinkPlugin } from "@univerjs/docs-hyper-link";
|
|
7
7
|
import { IRenderManagerService } from "@univerjs/engine-render";
|
|
8
8
|
import { DocSelectionManagerService, SetTextSelectionsOperation, DocSkeletonManagerService, DocInterceptorService, DOC_INTERCEPTOR_POINT } from "@univerjs/docs";
|
|
9
|
-
import { addCustomRangeBySelectionFactory, replaceSelectionFactory,
|
|
9
|
+
import { addCustomRangeBySelectionFactory, replaceSelectionFactory, deleteCustomRangeFactory, DocCanvasPopManagerService, DocEventManagerService, DocRenderController, whenDocAndEditorFocused } from "@univerjs/docs-ui";
|
|
10
10
|
import { BehaviorSubject, distinctUntilChanged, pairwise, Observable, debounceTime } from "rxjs";
|
|
11
11
|
import { FormLayout, Input, Button, Tooltip, MessageType } from "@univerjs/design";
|
|
12
12
|
import { KeyCode, IMessageService, useObservable as useObservable$1, MetaKeys, MenuItemType, getMenuHiddenObservable, RibbonStartGroup, ContextMenuPosition, ContextMenuGroup, ComponentManager, IMenuManagerService, IShortcutService } from "@univerjs/ui";
|
|
@@ -87,23 +87,20 @@ function transformUrl(urlStr) {
|
|
|
87
87
|
}
|
|
88
88
|
__name(transformUrl, "transformUrl");
|
|
89
89
|
const DocHyperLinkEdit = /* @__PURE__ */ __name(() => {
|
|
90
|
-
|
|
91
|
-
const hyperLinkService = useDependency(DocHyperLinkPopupService), localeService = useDependency(LocaleService), editing = useObservable(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);
|
|
90
|
+
const hyperLinkService = useDependency(DocHyperLinkPopupService), localeService = useDependency(LocaleService), editing = useObservable(hyperLinkService.editingLink$), commandService = useDependency(ICommandService), univerInstanceService = useDependency(IUniverInstanceService), 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);
|
|
92
91
|
useEffect(() => {
|
|
93
|
-
var
|
|
92
|
+
var _a7, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
94
93
|
const activeRange = docSelectionManagerService.getActiveTextRange();
|
|
95
94
|
if (!activeRange)
|
|
96
95
|
return;
|
|
97
96
|
if (editing) {
|
|
98
|
-
const
|
|
99
|
-
doc && matchedRange2 && (setLink((_d = (_c = matchedRange2.properties) == null ? void 0 : _c.url) != null ? _d : ""), setLabel(BuildTextUtils.transform.getPlainText(getBodySlice(
|
|
97
|
+
const body2 = (_a7 = doc == null ? void 0 : doc.getSelfOrHeaderFooterModel(editing.segmentId)) == null ? void 0 : _a7.getBody(), matchedRange2 = (_b = body2 == null ? void 0 : body2.customRanges) == null ? void 0 : _b.find((i) => (editing == null ? void 0 : editing.linkId) === i.rangeId);
|
|
98
|
+
doc && matchedRange2 && (setLink((_d = (_c = matchedRange2.properties) == null ? void 0 : _c.url) != null ? _d : ""), setLabel(BuildTextUtils.transform.getPlainText(getBodySlice(body2, matchedRange2.startIndex, matchedRange2.endIndex).dataStream)));
|
|
100
99
|
return;
|
|
101
100
|
}
|
|
102
|
-
const
|
|
101
|
+
const body = (_e = doc == null ? void 0 : doc.getSelfOrHeaderFooterModel(activeRange.segmentId)) == null ? void 0 : _e.getBody(), selection = body ? BuildTextUtils.selection.getInsertSelection(activeRange, body) : null, matchedRange = selection && ((_g = BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(selection, (_f = body == null ? void 0 : body.customRanges) != null ? _f : [])) == null ? void 0 : _g[0]);
|
|
103
102
|
doc && matchedRange && setLink((_i = (_h = matchedRange == null ? void 0 : matchedRange.properties) == null ? void 0 : _h.url) != null ? _i : "");
|
|
104
|
-
}, [doc, editing, docSelectionManagerService, univerInstanceService])
|
|
105
|
-
docSelectionRenderService && docSelectionRenderService.focusEditor();
|
|
106
|
-
}), [docSelectionRenderService]);
|
|
103
|
+
}, [doc, editing, docSelectionManagerService, univerInstanceService]);
|
|
107
104
|
const handleCancel = /* @__PURE__ */ __name(() => {
|
|
108
105
|
hyperLinkService.hideEditPopup();
|
|
109
106
|
}, "handleCancel"), handleConfirm = /* @__PURE__ */ __name(() => {
|
|
@@ -303,7 +300,7 @@ const DeleteDocHyperLinkCommand = {
|
|
|
303
300
|
if (p.startIndex > activeRange.endOffset)
|
|
304
301
|
break;
|
|
305
302
|
}
|
|
306
|
-
return !BuildTextUtils.customRange.
|
|
303
|
+
return !BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(activeRange, (_a7 = body.customRanges) != null ? _a7 : []).every((range) => range.rangeType === CustomRangeType.HYPERLINK);
|
|
307
304
|
}, "shouldDisableAddLink"), ShowDocHyperLinkEditPopupOperation = {
|
|
308
305
|
type: CommandType.OPERATION,
|
|
309
306
|
id: "doc.operation.show-hyper-link-edit-popup",
|
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/docs-hyper-link"),require("@univerjs/engine-render"),require("@univerjs/docs"),require("@univerjs/docs-ui"),require("rxjs"),require("@univerjs/design"),require("@univerjs/ui"),require("react")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs-hyper-link","@univerjs/engine-render","@univerjs/docs","@univerjs/docs-ui","rxjs","@univerjs/design","@univerjs/ui","react"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverDocsHyperLinkUi={},global.UniverCore,global.UniverDocsHyperLink,global.UniverEngineRender,global.UniverDocs,global.UniverDocsUi,global.rxjs,global.UniverDesign,global.UniverUi,global.React))})(this,function(exports2,core,docsHyperLink,engineRender,docs,docsUi,rxjs,design,ui,React){"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 PLUGIN_CONFIG_KEY="docs-hyper-link-ui.config",defaultPluginConfig={},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}},styles$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"};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(core.BuildTextUtils.transform.getPlainText(core.getBodySlice(body,matchedRange2.startIndex,matchedRange2.endIndex).dataStream)));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$1.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$1.docsLinkEditButtons},React.createElement(design.Button,{className:styles$1.docsLinkEditButton,onClick:handleCancel},localeService.t("docLink.edit.cancel")),React.createElement(design.Button,{disabled:!link,className:styles$1.docsLinkEditButton,type:"primary",onClick:handleConfirm},localeService.t("docLink.edit.confirm"))))},"DocHyperLinkEdit");DocHyperLinkEdit.componentKey="docs-hyper-link-edit";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";function r(e){var t,f,n="";if(typeof e=="string"||typeof e=="number")n+=e;else if(typeof e=="object")if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f)}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}__name(r,"r");function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}__name(clsx,"clsx");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=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={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.docLink,onClick:__name(()=>{hyperLinkService.hideInfoPopup()},"onClick")},React.createElement("div",{className:clsx(styles.docLinkContent),onClick:__name(()=>window.open(url),"onClick")},React.createElement("div",{className:styles.docLinkType},React.createElement(LinkSingle,null)),React.createElement(design.Tooltip,{showIfEllipsis:!0,title:url},React.createElement("span",{className:styles.docLinkUrl},url))),React.createElement("div",{className:styles.docLinkOperations},React.createElement("div",{className:clsx(styles.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.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.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);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 DocHyperLinkSelectionController=(_b=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(_b,"DocHyperLinkSelectionController"),_b);DocHyperLinkSelectionController=__decorateClass$4([__decorateParam$4(0,core.ICommandService),__decorateParam$4(1,core.IUniverInstanceService),__decorateParam$4(2,core.Inject(DocHyperLinkPopupService))],DocHyperLinkSelectionController);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 DocHyperLinkEventRenderController=(_c=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.getTextRanges(),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(_c,"DocHyperLinkEventRenderController"),_c);DocHyperLinkEventRenderController=__decorateClass$3([__decorateParam$3(1,core.Inject(docsUi.DocEventManagerService)),__decorateParam$3(2,core.ICommandService),__decorateParam$3(3,core.Inject(DocHyperLinkPopupService)),__decorateParam$3(4,core.Inject(docs.DocSkeletonManagerService)),__decorateParam$3(5,core.Inject(docs.DocSelectionManagerService))],DocHyperLinkEventRenderController);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);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$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 DocHyperLinkUIController=(_e=class extends core.Disposable{constructor(_componentManager,_commandService,_menuManagerService,_shortcutService){super(),this._componentManager=_componentManager,this._commandService=_commandService,this._menuManagerService=_menuManagerService,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(_e,"DocHyperLinkUIController"),_e);DocHyperLinkUIController=__decorateClass$1([__decorateParam$1(0,core.Inject(ui.ComponentManager)),__decorateParam$1(1,core.ICommandService),__decorateParam$1(2,ui.IMenuManagerService),__decorateParam$1(3,ui.IShortcutService)],DocHyperLinkUIController);const DOC_HYPER_LINK_UI_PLUGIN="DOC_HYPER_LINK_UI_PLUGIN";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)}),this._injector.get(DocHyperLinkUIController)}onReady(){this._injector.get(DocHyperLinkSelectionController)}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/docs-hyper-link"),require("@univerjs/engine-render"),require("@univerjs/docs"),require("@univerjs/docs-ui"),require("rxjs"),require("@univerjs/design"),require("@univerjs/ui"),require("react")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs-hyper-link","@univerjs/engine-render","@univerjs/docs","@univerjs/docs-ui","rxjs","@univerjs/design","@univerjs/ui","react"],factory):(global=typeof globalThis<"u"?globalThis:global||self,factory(global.UniverDocsHyperLinkUi={},global.UniverCore,global.UniverDocsHyperLink,global.UniverEngineRender,global.UniverDocs,global.UniverDocsUi,global.rxjs,global.UniverDesign,global.UniverUi,global.React))})(this,function(exports2,core,docsHyperLink,engineRender,docs,docsUi,rxjs,design,ui,React){"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 PLUGIN_CONFIG_KEY="docs-hyper-link-ui.config",defaultPluginConfig={},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}},styles$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"};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),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);React.useEffect(()=>{var _a2,_b2,_c2,_d2,_e2,_f2,_g,_h,_i;const activeRange=docSelectionManagerService.getActiveTextRange();if(!activeRange)return;if(editing){const body2=(_a2=doc==null?void 0:doc.getSelfOrHeaderFooterModel(editing.segmentId))==null?void 0:_a2.getBody(),matchedRange2=(_b2=body2==null?void 0:body2.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(core.BuildTextUtils.transform.getPlainText(core.getBodySlice(body2,matchedRange2.startIndex,matchedRange2.endIndex).dataStream)));return}const body=(_e2=doc==null?void 0:doc.getSelfOrHeaderFooterModel(activeRange.segmentId))==null?void 0:_e2.getBody(),selection=body?core.BuildTextUtils.selection.getInsertSelection(activeRange,body):null,matchedRange=selection&&((_g=core.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(selection,(_f2=body==null?void 0:body.customRanges)!=null?_f2:[]))==null?void 0:_g[0]);doc&&matchedRange&&setLink((_i=(_h=matchedRange==null?void 0:matchedRange.properties)==null?void 0:_h.url)!=null?_i:"")},[doc,editing,docSelectionManagerService,univerInstanceService]);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$1.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$1.docsLinkEditButtons},React.createElement(design.Button,{className:styles$1.docsLinkEditButton,onClick:handleCancel},localeService.t("docLink.edit.cancel")),React.createElement(design.Button,{disabled:!link,className:styles$1.docsLinkEditButton,type:"primary",onClick:handleConfirm},localeService.t("docLink.edit.confirm"))))},"DocHyperLinkEdit");DocHyperLinkEdit.componentKey="docs-hyper-link-edit";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";function r(e){var t,f,n="";if(typeof e=="string"||typeof e=="number")n+=e;else if(typeof e=="object")if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f)}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}__name(r,"r");function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}__name(clsx,"clsx");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=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.getCustomRangesInterestsWithSelection(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={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.docLink,onClick:__name(()=>{hyperLinkService.hideInfoPopup()},"onClick")},React.createElement("div",{className:clsx(styles.docLinkContent),onClick:__name(()=>window.open(url),"onClick")},React.createElement("div",{className:styles.docLinkType},React.createElement(LinkSingle,null)),React.createElement(design.Tooltip,{showIfEllipsis:!0,title:url},React.createElement("span",{className:styles.docLinkUrl},url))),React.createElement("div",{className:styles.docLinkOperations},React.createElement("div",{className:clsx(styles.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.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.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);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 DocHyperLinkSelectionController=(_b=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(_b,"DocHyperLinkSelectionController"),_b);DocHyperLinkSelectionController=__decorateClass$4([__decorateParam$4(0,core.ICommandService),__decorateParam$4(1,core.IUniverInstanceService),__decorateParam$4(2,core.Inject(DocHyperLinkPopupService))],DocHyperLinkSelectionController);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 DocHyperLinkEventRenderController=(_c=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.getTextRanges(),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(_c,"DocHyperLinkEventRenderController"),_c);DocHyperLinkEventRenderController=__decorateClass$3([__decorateParam$3(1,core.Inject(docsUi.DocEventManagerService)),__decorateParam$3(2,core.ICommandService),__decorateParam$3(3,core.Inject(DocHyperLinkPopupService)),__decorateParam$3(4,core.Inject(docs.DocSkeletonManagerService)),__decorateParam$3(5,core.Inject(docs.DocSelectionManagerService))],DocHyperLinkEventRenderController);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);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$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 DocHyperLinkUIController=(_e=class extends core.Disposable{constructor(_componentManager,_commandService,_menuManagerService,_shortcutService){super(),this._componentManager=_componentManager,this._commandService=_commandService,this._menuManagerService=_menuManagerService,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(_e,"DocHyperLinkUIController"),_e);DocHyperLinkUIController=__decorateClass$1([__decorateParam$1(0,core.Inject(ui.ComponentManager)),__decorateParam$1(1,core.ICommandService),__decorateParam$1(2,ui.IMenuManagerService),__decorateParam$1(3,ui.IShortcutService)],DocHyperLinkUIController);const DOC_HYPER_LINK_UI_PLUGIN="DOC_HYPER_LINK_UI_PLUGIN";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)}),this._injector.get(DocHyperLinkUIController)}onReady(){this._injector.get(DocHyperLinkSelectionController)}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.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Univer thread comment plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -49,15 +49,15 @@
|
|
|
49
49
|
"rxjs": ">=7.0.0"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@univerjs/icons": "^0.1.
|
|
52
|
+
"@univerjs/icons": "^0.1.84",
|
|
53
53
|
"clsx": "^2.1.1",
|
|
54
|
-
"@univerjs/core": "0.4.
|
|
55
|
-
"@univerjs/design": "0.4.
|
|
56
|
-
"@univerjs/docs
|
|
57
|
-
"@univerjs/docs": "0.4.
|
|
58
|
-
"@univerjs/
|
|
59
|
-
"@univerjs/engine-render": "0.4.
|
|
60
|
-
"@univerjs/
|
|
54
|
+
"@univerjs/core": "0.4.2",
|
|
55
|
+
"@univerjs/design": "0.4.2",
|
|
56
|
+
"@univerjs/docs": "0.4.2",
|
|
57
|
+
"@univerjs/docs-ui": "0.4.2",
|
|
58
|
+
"@univerjs/docs-hyper-link": "0.4.2",
|
|
59
|
+
"@univerjs/engine-render": "0.4.2",
|
|
60
|
+
"@univerjs/ui": "0.4.2"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"react": "18.3.1",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"typescript": "^5.6.3",
|
|
66
66
|
"vite": "^5.4.8",
|
|
67
67
|
"vitest": "^2.1.2",
|
|
68
|
-
"@univerjs-infra/shared": "0.4.
|
|
68
|
+
"@univerjs-infra/shared": "0.4.2"
|
|
69
69
|
},
|
|
70
70
|
"univerSpace": {
|
|
71
71
|
".": {
|