@univerjs/docs-hyper-link-ui 0.7.0-nightly.202505201607 → 0.7.0-nightly.202505221607

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 CHANGED
@@ -1 +1 @@
1
- "use strict";var me=Object.defineProperty;var _e=(n,e,t)=>e in n?me(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var O=(n,e,t)=>_e(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),Ce=require("@univerjs/docs-hyper-link"),ye=require("@univerjs/engine-render"),y=require("@univerjs/docs"),$=require("@univerjs/docs-ui"),D=require("rxjs"),u=require("react/jsx-runtime"),_=require("@univerjs/design"),l=require("@univerjs/ui"),C=require("react"),Se="docs-hyper-link-ui.config",oe={},ce={type:o.CommandType.COMMAND,id:"docs.command.add-hyper-link",async handler(n,e){if(!e)return!1;const{payload:t,unitId:i,selections:r}=e,s=n.get(o.ICommandService),c=o.generateRandomId(),a=y.addCustomRangeBySelectionFactory(n,{rangeId:c,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:t},unitId:i,selections:r});return a?s.syncExecuteCommand(a.id,a.params):!1}},ae={id:"docs.command.update-hyper-link",type:o.CommandType.COMMAND,handler(n,e){var h;if(!e)return!1;const{unitId:t,payload:i,segmentId:r,linkId:s}=e,c=n.get(o.ICommandService),a=n.get(o.IUniverInstanceService),g=n.get(y.DocSelectionManagerService).getActiveTextRange(),I=a.getUnit(t,o.UniverInstanceType.UNIVER_DOC);if(!g||!I)return!1;const f=(h=o.getBodySlice(I.getSelfOrHeaderFooterModel(r).getBody(),g.startOffset,g.endOffset).textRuns)==null?void 0:h[0];f&&(f.ed=e.label.length+1);const d=y.replaceSelectionFactory(n,{unitId:t,body:{dataStream:`${e.label}`,customRanges:[{rangeId:s,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:e.label.length+1,properties:{url:i}}],textRuns:f?[f]:void 0},selection:{startOffset:g.startOffset,endOffset:g.endOffset,collapsed:!1,segmentId:r}});return d?c.syncExecuteCommand(d.id,d.params):!1}};function xe(n){return/^[a-zA-Z]+:\/\//.test(n)}function ke(n){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(n)}function Le(n){return xe(n)?n:ke(n)?`mailto://${n}`:`https://${n}`}const j=()=>{const n=l.useDependency(k),e=l.useDependency(o.LocaleService),t=l.useObservable(n.editingLink$),i=l.useDependency(o.ICommandService),r=l.useDependency(o.IUniverInstanceService),s=l.useDependency(y.DocSelectionManagerService),[c,a]=C.useState(""),[v,g]=C.useState(""),[I,m]=C.useState(!1),f=o.Tools.isLegalUrl(c),d=t?r.getUnit(t.unitId,o.UniverInstanceType.UNIVER_DOC):r.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC);C.useEffect(()=>{var G,J,Q,X,ee,ne,te,ie,re;const p=s.getActiveTextRange();if(!p)return;if(t){const w=(G=d==null?void 0:d.getSelfOrHeaderFooterModel(t.segmentId))==null?void 0:G.getBody(),U=(J=w==null?void 0:w.customRanges)==null?void 0:J.find(K=>(t==null?void 0:t.linkId)===K.rangeId&&K.startIndex===t.startIndex&&K.endIndex===t.endIndex);d&&U&&(a((X=(Q=U.properties)==null?void 0:Q.url)!=null?X:""),g(o.BuildTextUtils.transform.getPlainText(o.getBodySlice(w,U.startIndex,U.endIndex+1).dataStream)));return}const L=(ee=d==null?void 0:d.getSelfOrHeaderFooterModel(p.segmentId))==null?void 0:ee.getBody(),W=L?p:null,M=W&&((te=o.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(W,(ne=L==null?void 0:L.customRanges)!=null?ne:[]))==null?void 0:te[0]);d&&M&&a((re=(ie=M==null?void 0:M.properties)==null?void 0:ie.url)!=null?re:"")},[d,t,s,r]);const h=()=>{n.hideEditPopup()},x=()=>{if(m(!0),!f||!d)return;const p=Le(c);if(!t)i.executeCommand(ce.id,{unitId:d.getUnitId(),payload:p});else{if(!v)return;i.executeCommand(ae.id,{unitId:d.getUnitId(),payload:p,linkId:t.linkId,label:v,segmentId:t.segmentId})}n.hideEditPopup()};if(d)return u.jsxs("div",{className:_.clsx("univer-box-border univer-w-[328px] univer-rounded-xl univer-bg-white univer-px-6 univer-py-5 univer-shadow dark:!univer-bg-gray-900",_.borderClassName),children:[u.jsxs("div",{children:[t?u.jsx(_.FormLayout,{label:e.t("docLink.edit.label"),error:I&&!v?e.t("docLink.edit.labelError"):"",children:u.jsx(_.Input,{value:v,onChange:g,autoFocus:!0,onKeyDown:p=>{p.keyCode===l.KeyCode.ENTER&&x()}})}):null,u.jsx(_.FormLayout,{label:e.t("docLink.edit.address"),error:I&&!f?e.t("docLink.edit.addressError"):"",children:u.jsx(_.Input,{value:c,onChange:a,autoFocus:!0,onKeyDown:p=>{p.keyCode===l.KeyCode.ENTER&&x()}})})]}),u.jsxs("div",{className:"univer-flex univer-justify-end univer-gap-3",children:[u.jsx(_.Button,{onClick:h,children:e.t("docLink.edit.cancel")}),u.jsx(_.Button,{variant:"primary",disabled:!c,onClick:x,children:e.t("docLink.edit.confirm")})]})]})};j.componentKey="docs-hyper-link-edit";var S=function(){return S=Object.assign||function(n){for(var e,t=1,i=arguments.length;t<i;t++){e=arguments[t];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r])}return n},S.apply(this,arguments)},Oe=function(n,e){var t={};for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&e.indexOf(i)<0&&(t[i]=n[i]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,i=Object.getOwnPropertySymbols(n);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(n,i[r])&&(t[i[r]]=n[i[r]]);return t},R=C.forwardRef(function(n,e){var t=n.icon,i=n.id,r=n.className,s=n.extend,c=Oe(n,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(i," ").concat(r||"").trim(),v=C.useRef("_".concat(be()));return de(t,"".concat(i),{defIds:t.defIds,idSuffix:v.current},S({ref:e,className:a},c),s)});function de(n,e,t,i,r){return C.createElement(n.tag,S(S({key:e},De(n,t,r)),i),(Pe(n,t).children||[]).map(function(s,c){return de(s,"".concat(e,"-").concat(n.tag,"-").concat(c),t,void 0,r)}))}function De(n,e,t){var i=S({},n.attrs);t!=null&&t.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=t.colorChannel1),n.tag==="mask"&&i.id&&(i.id=i.id+e.idSuffix),Object.entries(i).forEach(function(s){var c=s[0],a=s[1];c==="mask"&&typeof a=="string"&&(i[c]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))});var r=e.defIds;return!r||r.length===0||(n.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+e.idSuffix),Object.entries(i).forEach(function(s){var c=s[0],a=s[1];typeof a=="string"&&(i[c]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),i}function Pe(n,e){var t,i=e.defIds;return!i||i.length===0?n:n.tag==="defs"&&(!((t=n.children)===null||t===void 0)&&t.length)?S(S({},n),{children:n.children.map(function(r){return typeof r.attrs.id=="string"&&i&&i.indexOf(r.attrs.id)>-1?S(S({},r),{attrs:S(S({},r.attrs),{id:r.attrs.id+e.idSuffix})}):r})}):n}function be(){return Math.random().toString(36).substring(2,8)}R.displayName="UniverIcon";var Re={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"}}]},ue=C.forwardRef(function(n,e){return C.createElement(R,Object.assign({},n,{id:"copy-single",ref:e,icon:Re}))});ue.displayName="CopySingle";var Me={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M9.8816 1.97978C11.0177 0.843607 12.862 0.884962 14.0004 2.02342C15.1389 3.16188 15.1803 5.00612 14.0441 6.14228L11.399 8.78737C11.1608 9.02559 10.7746 9.02559 10.5363 8.78737C10.2981 8.54915 10.2981 8.16292 10.5363 7.9247L13.1814 5.2796C13.8195 4.64155 13.8217 3.57006 13.1378 2.8861C12.4538 2.20211 11.3823 2.20438 10.7443 2.84245L7.6976 5.88911L7.69317 5.89349C7.05959 6.53211 7.05894 7.60014 7.74132 8.28252C7.97954 8.52074 7.97954 8.90697 7.74132 9.14519C7.5031 9.38341 7.11687 9.38341 6.87865 9.14519C5.74016 8.00671 5.69884 6.16251 6.83497 5.02633L6.84021 5.02116L9.8816 1.97978Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.61426 7.2364C4.85248 6.99818 5.23871 6.99818 5.47693 7.2364C5.71515 7.47462 5.71515 7.86085 5.47693 8.09907L2.83183 10.7442C2.19375 11.3823 2.1915 12.4537 2.87547 13.1377C3.55945 13.8217 4.6309 13.8194 5.26899 13.1813L8.31566 10.1347C8.32262 10.1277 8.32971 10.121 8.33691 10.1144C8.34408 10.1064 8.3515 10.0986 8.35916 10.091C8.99721 9.45291 8.99949 8.38145 8.3155 7.69746C8.07728 7.45924 8.07728 7.07301 8.3155 6.83479C8.55372 6.59657 8.93995 6.59657 9.17817 6.83479C10.3166 7.97327 10.358 9.81748 9.22183 10.9536C9.21487 10.9606 9.20779 10.9673 9.20058 10.9739C9.19341 10.9819 9.18599 10.9897 9.17833 10.9973L6.13166 14.044C4.99548 15.1802 3.15127 15.1389 2.01279 14.0004C0.874362 12.8619 0.83297 11.0177 1.96916 9.8815L4.61426 7.2364Z"}}]},z=C.forwardRef(function(n,e){return C.createElement(R,Object.assign({},n,{id:"link-single",ref:e,icon:Me}))});z.displayName="LinkSingle";var we={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"}}]},le=C.forwardRef(function(n,e){return C.createElement(R,Object.assign({},n,{id:"unlink-single",ref:e,icon:we}))});le.displayName="UnlinkSingle";var Ue={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"}}]},pe=C.forwardRef(function(n,e){return C.createElement(R,Object.assign({},n,{id:"write-single",ref:e,icon:Ue}))});pe.displayName="WriteSingle";const ve={type:o.CommandType.COMMAND,id:"docs.command.delete-hyper-link",async handler(n,e){if(!e)return!1;const{unitId:t,linkId:i,segmentId:r}=e,s=n.get(o.ICommandService),c=y.deleteCustomRangeFactory(n,{unitId:t,rangeId:i,segmentId:r});return c?await s.syncExecuteCommand(c.id,c.params):!1}},ge=n=>{const e=n.get(y.DocSelectionManagerService),t=n.get(o.IUniverInstanceService),i=e.getTextRanges();if(!(i!=null&&i.length))return!0;const r=i[0];return!!(!t.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC)||!r||r.collapsed)},P={type:o.CommandType.OPERATION,id:"doc.operation.show-hyper-link-edit-popup",handler(n,e){var c;const t=e==null?void 0:e.link,i=n.get(o.IUniverInstanceService);if(ge(n)&&!t)return!1;const r=n.get(k),s=(t==null?void 0:t.unitId)||((c=i.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC))==null?void 0:c.getUnitId());return s?(r.showEditPopup(s,t),!0):!1}},Y={type:o.CommandType.OPERATION,id:"doc.operation.toggle-hyper-link-info-popup",handler(n,e){const t=n.get(k);return e?(t.showInfoPopup(e),!0):(t.hideInfoPopup(),!0)}},he={type:o.CommandType.OPERATION,id:"doc.operation.click-hyper-link",handler(n,e){var g,I,m;if(!e)return!1;const{unitId:t,linkId:i,segmentId:r}=e,c=n.get(o.IUniverInstanceService).getUnit(t,o.UniverInstanceType.UNIVER_DOC),a=c==null?void 0:c.getSelfOrHeaderFooterModel(r).getBody(),v=(m=(I=(g=a==null?void 0:a.customRanges)==null?void 0:g.find(f=>f.rangeId===i&&f.rangeType===o.CustomRangeType.HYPERLINK))==null?void 0:I.properties)==null?void 0:m.url;return v&&window.open(v,"_blank","noopener noreferrer"),!0}},T=()=>{var x,p;const n=l.useDependency(k),e=l.useDependency(o.ICommandService),t=l.useDependency(l.IMessageService),i=l.useDependency(o.LocaleService),r=l.useObservable(n.showingLink$),s=l.useDependency(o.IUniverInstanceService);if(!r)return null;const{unitId:c,linkId:a,segmentId:v,startIndex:g,endIndex:I}=r,m=s.getUnit(c,o.UniverInstanceType.UNIVER_DOC),f=m==null?void 0:m.getSelfOrHeaderFooterModel(v).getBody(),d=(x=f==null?void 0:f.customRanges)==null?void 0:x.find(L=>L.rangeId===a&&L.rangeType===o.CustomRangeType.HYPERLINK&&L.startIndex===g&&L.endIndex===I);if(!d)return null;const h=(p=d.properties)==null?void 0:p.url;return u.jsxs("div",{className:_.clsx("univer-box-border univer-flex univer-max-w-80 univer-items-center univer-justify-between univer-overflow-hidden univer-rounded-lg univer-bg-white univer-p-3 univer-shadow dark:!univer-bg-gray-900",_.borderClassName),onClick:()=>{n.hideInfoPopup()},children:[u.jsxs("div",{className:"univer-flex univer-h-6 univer-flex-1 univer-cursor-pointer univer-items-center univer-truncate univer-text-sm univer-leading-5 univer-text-primary-500",onClick:()=>window.open(h,void 0,"noopener noreferrer"),children:[u.jsx("div",{className:"univer-mr-2 univer-flex univer-size-5 univer-flex-[0_0_auto] univer-items-center univer-justify-center univer-text-base univer-text-gray-900 dark:!univer-text-white",children:u.jsx(z,{})}),u.jsx(_.Tooltip,{showIfEllipsis:!0,title:h,children:u.jsx("span",{className:"univer-flex-1 univer-truncate",children:h})})]}),u.jsxs("div",{className:"univer-flex univer-h-6 univer-flex-[0_0_auto] univer-items-center univer-justify-center",children:[u.jsx("div",{className:"univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",onClick:()=>{navigator.clipboard.writeText(h),t.show({content:i.t("docLink.info.coped"),type:_.MessageType.Info})},children:u.jsx(_.Tooltip,{placement:"bottom",title:i.t("docLink.info.copy"),children:u.jsx(ue,{})})}),u.jsx("div",{className:"univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",onClick:()=>{e.executeCommand(P.id,{link:r})},children:u.jsx(_.Tooltip,{placement:"bottom",title:i.t("docLink.info.edit"),children:u.jsx(pe,{})})}),u.jsx("div",{className:"univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",onClick:()=>{e.executeCommand(ve.id,{unitId:c,linkId:d.rangeId,segmentId:v})},children:u.jsx(_.Tooltip,{placement:"bottom",title:i.t("docLink.info.cancel"),children:u.jsx(le,{})})})]})]})};T.componentKey="univer.doc.link-info-popup";var Ee=Object.getOwnPropertyDescriptor,je=(n,e,t,i)=>{for(var r=i>1?void 0:i?Ee(e,t):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(r=c(r)||r);return r},A=(n,e)=>(t,i)=>e(t,i,n);let k=class extends o.Disposable{constructor(e,t,i){super();O(this,"_editingLink$",new D.BehaviorSubject(null));O(this,"_showingLink$",new D.BehaviorSubject(null));O(this,"editingLink$",this._editingLink$.asObservable());O(this,"showingLink$",this._showingLink$.asObservable());O(this,"_editPopup",null);O(this,"_infoPopup",null);this._docCanvasPopupManagerService=e,this._textSelectionManagerService=t,this._univerInstanceService=i,this.disposeWithMe(()=>{this._editingLink$.complete(),this._showingLink$.complete()})}get editing(){return this._editingLink$.value}get showing(){return this._showingLink$.value}showEditPopup(e,t){this._editPopup&&this._editPopup.dispose(),this._editingLink$.next(t);const i=this._textSelectionManagerService.getTextRanges({unitId:e,subUnitId:e});let r=i==null?void 0:i[i.length-1];if(t){const{segmentId:s,segmentPage:c,startIndex:a,endIndex:v}=t;r={collapsed:!1,startOffset:a,endOffset:v+1,segmentId:s,segmentPage:c},this._textSelectionManagerService.replaceDocRanges([{startOffset:a,endOffset:v+1}])}return r?(this._editPopup=this._docCanvasPopupManagerService.attachPopupToRange(r,{componentKey:j.componentKey,direction:"bottom"},e),this._editPopup):null}hideEditPopup(){var e;this._editingLink$.next(null),(e=this._editPopup)==null||e.dispose()}showInfoPopup(e){var g,I,m,f,d,h;const{linkId:t,unitId:i,segmentId:r,segmentPage:s,startIndex:c,endIndex:a}=e;if(!(((g=this.showing)==null?void 0:g.linkId)===t&&((I=this.showing)==null?void 0:I.unitId)===i&&((m=this.showing)==null?void 0:m.segmentId)===r&&((f=this.showing)==null?void 0:f.segmentPage)===s&&((d=this.showing)==null?void 0:d.startIndex)===c&&((h=this.showing)==null?void 0:h.endIndex)===a||(this._infoPopup&&this._infoPopup.dispose(),!this._univerInstanceService.getUnit(i,o.UniverInstanceType.UNIVER_DOC))))return this._showingLink$.next({unitId:i,linkId:t,segmentId:r,segmentPage:s,startIndex:c,endIndex:a}),this._infoPopup=this._docCanvasPopupManagerService.attachPopupToRange({collapsed:!1,startOffset:c,endOffset:a+1,segmentId:r,segmentPage:s},{componentKey:T.componentKey,direction:"top-center",multipleDirection:"top",onClickOutside:()=>{this.hideInfoPopup()}},i),this._infoPopup}hideInfoPopup(){var e;this._showingLink$.next(null),(e=this._infoPopup)==null||e.dispose()}};k=je([A(0,o.Inject($.DocCanvasPopManagerService)),A(1,o.Inject(y.DocSelectionManagerService)),A(2,o.IUniverInstanceService)],k);var Te=Object.getOwnPropertyDescriptor,Ne=(n,e,t,i)=>{for(var r=i>1?void 0:i?Te(e,t):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(r=c(r)||r);return r},B=(n,e)=>(t,i)=>e(t,i,n);let N=class extends o.Disposable{constructor(n,e,t){super(),this._commandService=n,this._univerInstanceService=e,this._docHyperLinkService=t,this._initSelectionChange()}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(n=>{var e,t,i;if(n.id===y.SetTextSelectionsOperation.id){const r=n.params,{unitId:s,ranges:c,segmentId:a}=r,v=this._univerInstanceService.getUnit(s,o.UniverInstanceType.UNIVER_DOC),g=c[0];if(g&&v){const{startOffset:I,endOffset:m,collapsed:f,segmentPage:d}=g,h=(t=(e=v.getSelfOrHeaderFooterModel(a))==null?void 0:e.getBody())==null?void 0:t.customRanges;if(f){const x=(i=h==null?void 0:h.findIndex(p=>p.startIndex<I&&p.endIndex>m-1))!=null?i:-1;if(x>-1){const p=h[x];this._docHyperLinkService.showInfoPopup({unitId:s,linkId:p.rangeId,segmentId:a,segmentPage:d,startIndex:p.startIndex,endIndex:p.endIndex});return}}else if(h==null?void 0:h.find(p=>p.startIndex<=I&&p.endIndex>=m-1))return}this._docHyperLinkService.hideInfoPopup(),this._docHyperLinkService.hideEditPopup()}}))}};N=Ne([B(0,o.ICommandService),B(1,o.IUniverInstanceService),B(2,o.Inject(k))],N);var He=Object.getOwnPropertyDescriptor,$e=(n,e,t,i)=>{for(var r=i>1?void 0:i?He(e,t):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(r=c(r)||r);return r},b=(n,e)=>(t,i)=>e(t,i,n);let q=class extends o.Disposable{constructor(n,e,t,i,r,s){super(),this._context=n,this._docEventManagerService=e,this._commandService=t,this._hyperLinkPopupService=i,this._docSkeletonManagerService=r,this._docSelectionManagerService=s,!(this._context.unitId===o.DOCS_ZEN_EDITOR_UNIT_ID_KEY||this._context.unitId===o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)&&(this._initHover(),this._initClick())}get _skeleton(){return this._docSkeletonManagerService.getSkeleton()}_hideInfoPopup(){this._hyperLinkPopupService.showing&&this._commandService.executeCommand(Y.id)}_initHover(){this.disposeWithMe(this._docEventManagerService.hoverCustomRanges$.subscribe(n=>{var r;const e=n.find(s=>s.range.rangeType===o.CustomRangeType.HYPERLINK),t=this._docSelectionManagerService.getTextRanges(),i=t==null?void 0:t[0].segmentId;if(((r=e==null?void 0:e.segmentId)!=null?r:"")!==i){this._hideInfoPopup();return}e?this._commandService.executeCommand(Y.id,{unitId:this._context.unitId,linkId:e.range.rangeId,segmentId:e.segmentId,segmentPage:e.segmentPageIndex,rangeId:e.range.rangeId,startIndex:e.range.startIndex,endIndex:e.range.endIndex}):this._hideInfoPopup()}))}_initClick(){this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe(n=>{const e=n.range;e&&this._commandService.executeCommand(he.id,{unitId:this._context.unitId,linkId:e.rangeId,segmentId:n.segmentId})}))}};q=$e([b(1,o.Inject($.DocEventManagerService)),b(2,o.ICommandService),b(3,o.Inject(k)),b(4,o.Inject(y.DocSkeletonManagerService)),b(5,o.Inject(y.DocSelectionManagerService))],q);var Ke=Object.getOwnPropertyDescriptor,Ae=(n,e,t,i)=>{for(var r=i>1?void 0:i?Ke(e,t):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(r=c(r)||r);return r},F=(n,e)=>(t,i)=>e(t,i,n);let Z=class extends o.Disposable{constructor(n,e,t,i){super(),this._context=n,this._docInterceptorService=e,this._hyperLinkService=t,this._docRenderController=i,this._init(),this._initReRender()}_init(){this._docInterceptorService.intercept(y.DOC_INTERCEPTOR_POINT.CUSTOM_RANGE,{handler:(n,e,t)=>{if(!n)return t(n);const{unitId:i,index:r}=e,s=this._hyperLinkService.showing;if(!s)return t({...n,active:!1});const{linkId:c,unitId:a,startIndex:v,endIndex:g}=s,I=a===i&&n.rangeId===c&&r>=v&&r<=g;return t({...n,active:I})}})}_initReRender(){this.disposeWithMe(this._hyperLinkService.showingLink$.pipe(D.distinctUntilChanged((n,e)=>(n==null?void 0:n.linkId)===(e==null?void 0:e.linkId)&&(n==null?void 0:n.unitId)===(e==null?void 0:e.unitId)&&(n==null?void 0:n.startIndex)===(e==null?void 0:e.startIndex)),D.pairwise()).subscribe(([n,e])=>{e?e.unitId===this._context.unitId&&this._docRenderController.reRender(e.unitId):n&&n.unitId===this._context.unitId&&this._docRenderController.reRender(n.unitId)}))}};Z=Ae([F(1,o.Inject(y.DocInterceptorService)),F(2,o.Inject(k)),F(3,o.Inject($.DocRenderController))],Z);const fe="doc-hyper-link-icon";function se(n){return{id:P.id,type:l.MenuItemType.BUTTON,icon:fe,title:"docLink.menu.tooltip",tooltip:"docLink.menu.tooltip",hidden$:l.getMenuHiddenObservable(n,o.UniverInstanceType.UNIVER_DOC),disabled$:new D.Observable(function(e){const i=n.get(y.DocSelectionManagerService).textSelection$.pipe(D.debounceTime(16)).subscribe(()=>{e.next(ge(n))});return()=>{i.unsubscribe()}})}}const Be={id:P.id,binding:l.MetaKeys.CTRL_COMMAND|l.KeyCode.K,description:"docLink.menu.tooltip",preconditions:$.whenDocAndEditorFocused},Fe={[l.RibbonInsertGroup.MEDIA]:{[P.id]:{order:1,menuItemFactory:se}},[l.ContextMenuPosition.MAIN_AREA]:{[l.ContextMenuGroup.DATA]:{[P.id]:{order:0,menuItemFactory:se}}}};var Ve=Object.getOwnPropertyDescriptor,Ye=(n,e,t,i)=>{for(var r=i>1?void 0:i?Ve(e,t):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(r=c(r)||r);return r},E=(n,e)=>(t,i)=>e(t,i,n);let H=class extends o.Disposable{constructor(n,e,t,i){super(),this._componentManager=n,this._commandService=e,this._menuManagerService=t,this._shortcutService=i,this._initComponents(),this._initCommands(),this._initMenus(),this._initShortcut()}_initComponents(){[[j,j.componentKey],[T,T.componentKey],[z,fe]].forEach(([n,e])=>{this._componentManager.register(e,n)})}_initCommands(){[ce,ae,ve,P,Y,he].forEach(n=>{this._commandService.registerCommand(n)})}_initShortcut(){[Be].forEach(n=>{this._shortcutService.registerShortcut(n)})}_initMenus(){this._menuManagerService.mergeMenu(Fe)}};H=Ye([E(0,o.Inject(l.ComponentManager)),E(1,o.ICommandService),E(2,l.IMenuManagerService),E(3,l.IShortcutService)],H);const qe="DOC_HYPER_LINK_UI_PLUGIN";var Ze=Object.defineProperty,ze=Object.getOwnPropertyDescriptor,We=(n,e,t)=>e in n?Ze(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Ge=(n,e,t,i)=>{for(var r=i>1?void 0:i?ze(e,t):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(r=c(r)||r);return r},V=(n,e)=>(t,i)=>e(t,i,n),Ie=(n,e,t)=>We(n,typeof e!="symbol"?e+"":e,t);exports.UniverDocsHyperLinkUIPlugin=class extends o.Plugin{constructor(e=oe,t,i,r){super(),this._config=e,this._injector=t,this._renderManagerSrv=i,this._configService=r;const{menu:s,...c}=o.merge({},oe,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig(Se,c)}onStarting(){[[k],[H],[N]].forEach(t=>{this._injector.add(t)}),this._injector.get(H)}onReady(){this._injector.get(N)}onRendered(){this._initRenderModule()}_initRenderModule(){[[Z],[q]].forEach(e=>{this._renderManagerSrv.registerRenderModule(o.UniverInstanceType.UNIVER_DOC,e)})}};Ie(exports.UniverDocsHyperLinkUIPlugin,"pluginName",qe);Ie(exports.UniverDocsHyperLinkUIPlugin,"type",o.UniverInstanceType.UNIVER_DOC);exports.UniverDocsHyperLinkUIPlugin=Ge([o.DependentOn(Ce.UniverDocsHyperLinkPlugin),V(1,o.Inject(o.Injector)),V(2,ye.IRenderManagerService),V(3,o.IConfigService)],exports.UniverDocsHyperLinkUIPlugin);
1
+ "use strict";var me=Object.defineProperty;var _e=(n,e,t)=>e in n?me(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var O=(n,e,t)=>_e(n,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),Ce=require("@univerjs/docs-hyper-link"),ye=require("@univerjs/engine-render"),y=require("@univerjs/docs"),$=require("@univerjs/docs-ui"),D=require("rxjs"),u=require("react/jsx-runtime"),_=require("@univerjs/design"),l=require("@univerjs/ui"),C=require("react"),Se="docs-hyper-link-ui.config",oe={},ce={type:o.CommandType.COMMAND,id:"docs.command.add-hyper-link",async handler(n,e){if(!e)return!1;const{payload:t,unitId:i,selections:r}=e,s=n.get(o.ICommandService),c=o.generateRandomId(),a=y.addCustomRangeBySelectionFactory(n,{rangeId:c,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:t},unitId:i,selections:r});return a?s.syncExecuteCommand(a.id,a.params):!1}},ae={id:"docs.command.update-hyper-link",type:o.CommandType.COMMAND,handler(n,e){var h;if(!e)return!1;const{unitId:t,payload:i,segmentId:r,linkId:s}=e,c=n.get(o.ICommandService),a=n.get(o.IUniverInstanceService),g=n.get(y.DocSelectionManagerService).getActiveTextRange(),I=a.getUnit(t,o.UniverInstanceType.UNIVER_DOC);if(!g||!I)return!1;const f=(h=o.getBodySlice(I.getSelfOrHeaderFooterModel(r).getBody(),g.startOffset,g.endOffset).textRuns)==null?void 0:h[0];f&&(f.ed=e.label.length+1);const d=y.replaceSelectionFactory(n,{unitId:t,body:{dataStream:`${e.label}`,customRanges:[{rangeId:s,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:e.label.length+1,properties:{url:i}}],textRuns:f?[f]:void 0},selection:{startOffset:g.startOffset,endOffset:g.endOffset,collapsed:!1,segmentId:r}});return d?c.syncExecuteCommand(d.id,d.params):!1}};function xe(n){return/^[a-zA-Z]+:\/\//.test(n)}function ke(n){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(n)}function Le(n){return xe(n)?n:ke(n)?`mailto://${n}`:`https://${n}`}const j=()=>{const n=l.useDependency(k),e=l.useDependency(o.LocaleService),t=l.useObservable(n.editingLink$),i=l.useDependency(o.ICommandService),r=l.useDependency(o.IUniverInstanceService),s=l.useDependency(y.DocSelectionManagerService),[c,a]=C.useState(""),[v,g]=C.useState(""),[I,m]=C.useState(!1),f=o.Tools.isLegalUrl(c),d=t?r.getUnit(t.unitId,o.UniverInstanceType.UNIVER_DOC):r.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC);C.useEffect(()=>{var G,J,Q,X,ee,ne,te,ie,re;const p=s.getActiveTextRange();if(!p)return;if(t){const w=(G=d==null?void 0:d.getSelfOrHeaderFooterModel(t.segmentId))==null?void 0:G.getBody(),U=(J=w==null?void 0:w.customRanges)==null?void 0:J.find(K=>(t==null?void 0:t.linkId)===K.rangeId&&K.startIndex===t.startIndex&&K.endIndex===t.endIndex);d&&U&&(a((X=(Q=U.properties)==null?void 0:Q.url)!=null?X:""),g(o.BuildTextUtils.transform.getPlainText(o.getBodySlice(w,U.startIndex,U.endIndex+1).dataStream)));return}const L=(ee=d==null?void 0:d.getSelfOrHeaderFooterModel(p.segmentId))==null?void 0:ee.getBody(),z=L?p:null,M=z&&((te=o.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(z,(ne=L==null?void 0:L.customRanges)!=null?ne:[]))==null?void 0:te[0]);d&&M&&a((re=(ie=M==null?void 0:M.properties)==null?void 0:ie.url)!=null?re:"")},[d,t,s,r]);const h=()=>{n.hideEditPopup()},x=()=>{if(m(!0),!f||!d)return;const p=Le(c);if(!t)i.executeCommand(ce.id,{unitId:d.getUnitId(),payload:p});else{if(!v)return;i.executeCommand(ae.id,{unitId:d.getUnitId(),payload:p,linkId:t.linkId,label:v,segmentId:t.segmentId})}n.hideEditPopup()};if(d)return u.jsxs("div",{className:_.clsx("univer-box-border univer-w-[328px] univer-rounded-xl univer-bg-white univer-px-6 univer-py-5 univer-shadow dark:!univer-bg-gray-900",_.borderClassName),children:[u.jsxs("div",{children:[t?u.jsx(_.FormLayout,{label:e.t("docLink.edit.label"),error:I&&!v?e.t("docLink.edit.labelError"):"",children:u.jsx(_.Input,{value:v,onChange:g,autoFocus:!0,onKeyDown:p=>{p.keyCode===l.KeyCode.ENTER&&x()}})}):null,u.jsx(_.FormLayout,{label:e.t("docLink.edit.address"),error:I&&!f?e.t("docLink.edit.addressError"):"",children:u.jsx(_.Input,{value:c,onChange:a,autoFocus:!0,onKeyDown:p=>{p.keyCode===l.KeyCode.ENTER&&x()}})})]}),u.jsxs("div",{className:"univer-flex univer-justify-end univer-gap-3",children:[u.jsx(_.Button,{onClick:h,children:e.t("docLink.edit.cancel")}),u.jsx(_.Button,{variant:"primary",disabled:!c,onClick:x,children:e.t("docLink.edit.confirm")})]})]})};j.componentKey="docs-hyper-link-edit";var S=function(){return S=Object.assign||function(n){for(var e,t=1,i=arguments.length;t<i;t++){e=arguments[t];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r])}return n},S.apply(this,arguments)},Oe=function(n,e){var t={};for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&e.indexOf(i)<0&&(t[i]=n[i]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,i=Object.getOwnPropertySymbols(n);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(n,i[r])&&(t[i[r]]=n[i[r]]);return t},R=C.forwardRef(function(n,e){var t=n.icon,i=n.id,r=n.className,s=n.extend,c=Oe(n,["icon","id","className","extend"]),a="univerjs-icon univerjs-icon-".concat(i," ").concat(r||"").trim(),v=C.useRef("_".concat(be()));return de(t,"".concat(i),{defIds:t.defIds,idSuffix:v.current},S({ref:e,className:a},c),s)});function de(n,e,t,i,r){return C.createElement(n.tag,S(S({key:e},De(n,t,r)),i),(Pe(n,t).children||[]).map(function(s,c){return de(s,"".concat(e,"-").concat(n.tag,"-").concat(c),t,void 0,r)}))}function De(n,e,t){var i=S({},n.attrs);t!=null&&t.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=t.colorChannel1),n.tag==="mask"&&i.id&&(i.id=i.id+e.idSuffix),Object.entries(i).forEach(function(s){var c=s[0],a=s[1];c==="mask"&&typeof a=="string"&&(i[c]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))});var r=e.defIds;return!r||r.length===0||(n.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+e.idSuffix),Object.entries(i).forEach(function(s){var c=s[0],a=s[1];typeof a=="string"&&(i[c]=a.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),i}function Pe(n,e){var t,i=e.defIds;return!i||i.length===0?n:n.tag==="defs"&&(!((t=n.children)===null||t===void 0)&&t.length)?S(S({},n),{children:n.children.map(function(r){return typeof r.attrs.id=="string"&&i&&i.indexOf(r.attrs.id)>-1?S(S({},r),{attrs:S(S({},r.attrs),{id:r.attrs.id+e.idSuffix})}):r})}):n}function be(){return Math.random().toString(36).substring(2,8)}R.displayName="UniverIcon";var Re={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"}}]},ue=C.forwardRef(function(n,e){return C.createElement(R,Object.assign({},n,{id:"copy-single",ref:e,icon:Re}))});ue.displayName="CopySingle";var Me={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M9.8816 1.97978C11.0177 0.843607 12.862 0.884962 14.0004 2.02342C15.1389 3.16188 15.1803 5.00612 14.0441 6.14228L11.399 8.78737C11.1608 9.02559 10.7746 9.02559 10.5363 8.78737C10.2981 8.54915 10.2981 8.16292 10.5363 7.9247L13.1814 5.2796C13.8195 4.64155 13.8217 3.57006 13.1378 2.8861C12.4538 2.20211 11.3823 2.20438 10.7443 2.84245L7.6976 5.88911L7.69317 5.89349C7.05959 6.53211 7.05894 7.60014 7.74132 8.28252C7.97954 8.52074 7.97954 8.90697 7.74132 9.14519C7.5031 9.38341 7.11687 9.38341 6.87865 9.14519C5.74016 8.00671 5.69884 6.16251 6.83497 5.02633L6.84021 5.02116L9.8816 1.97978Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.61426 7.2364C4.85248 6.99818 5.23871 6.99818 5.47693 7.2364C5.71515 7.47462 5.71515 7.86085 5.47693 8.09907L2.83183 10.7442C2.19375 11.3823 2.1915 12.4537 2.87547 13.1377C3.55945 13.8217 4.6309 13.8194 5.26899 13.1813L8.31566 10.1347C8.32262 10.1277 8.32971 10.121 8.33691 10.1144C8.34408 10.1064 8.3515 10.0986 8.35916 10.091C8.99721 9.45291 8.99949 8.38145 8.3155 7.69746C8.07728 7.45924 8.07728 7.07301 8.3155 6.83479C8.55372 6.59657 8.93995 6.59657 9.17817 6.83479C10.3166 7.97327 10.358 9.81748 9.22183 10.9536C9.21487 10.9606 9.20779 10.9673 9.20058 10.9739C9.19341 10.9819 9.18599 10.9897 9.17833 10.9973L6.13166 14.044C4.99548 15.1802 3.15127 15.1389 2.01279 14.0004C0.874362 12.8619 0.83297 11.0177 1.96916 9.8815L4.61426 7.2364Z"}}]},W=C.forwardRef(function(n,e){return C.createElement(R,Object.assign({},n,{id:"link-single",ref:e,icon:Me}))});W.displayName="LinkSingle";var we={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"}}]},le=C.forwardRef(function(n,e){return C.createElement(R,Object.assign({},n,{id:"unlink-single",ref:e,icon:we}))});le.displayName="UnlinkSingle";var Ue={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"}}]},pe=C.forwardRef(function(n,e){return C.createElement(R,Object.assign({},n,{id:"write-single",ref:e,icon:Ue}))});pe.displayName="WriteSingle";const ve={type:o.CommandType.COMMAND,id:"docs.command.delete-hyper-link",async handler(n,e){if(!e)return!1;const{unitId:t,linkId:i,segmentId:r}=e,s=n.get(o.ICommandService),c=y.deleteCustomRangeFactory(n,{unitId:t,rangeId:i,segmentId:r});return c?await s.syncExecuteCommand(c.id,c.params):!1}},ge=n=>{const e=n.get(y.DocSelectionManagerService),t=n.get(o.IUniverInstanceService),i=e.getTextRanges();if(!(i!=null&&i.length))return!0;const r=i[0];return!!(!t.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC)||!r||r.collapsed)},P={type:o.CommandType.OPERATION,id:"doc.operation.show-hyper-link-edit-popup",handler(n,e){var c;const t=e==null?void 0:e.link,i=n.get(o.IUniverInstanceService);if(ge(n)&&!t)return!1;const r=n.get(k),s=(t==null?void 0:t.unitId)||((c=i.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC))==null?void 0:c.getUnitId());return s?(r.showEditPopup(s,t),!0):!1}},Y={type:o.CommandType.OPERATION,id:"doc.operation.toggle-hyper-link-info-popup",handler(n,e){const t=n.get(k);return e?(t.showInfoPopup(e),!0):(t.hideInfoPopup(),!0)}},he={type:o.CommandType.OPERATION,id:"doc.operation.click-hyper-link",handler(n,e){var g,I,m;if(!e)return!1;const{unitId:t,linkId:i,segmentId:r}=e,c=n.get(o.IUniverInstanceService).getUnit(t,o.UniverInstanceType.UNIVER_DOC),a=c==null?void 0:c.getSelfOrHeaderFooterModel(r).getBody(),v=(m=(I=(g=a==null?void 0:a.customRanges)==null?void 0:g.find(f=>f.rangeId===i&&f.rangeType===o.CustomRangeType.HYPERLINK))==null?void 0:I.properties)==null?void 0:m.url;return v&&window.open(v,"_blank","noopener noreferrer"),!0}},T=()=>{var x,p;const n=l.useDependency(k),e=l.useDependency(o.ICommandService),t=l.useDependency(l.IMessageService),i=l.useDependency(o.LocaleService),r=l.useObservable(n.showingLink$),s=l.useDependency(o.IUniverInstanceService);if(!r)return null;const{unitId:c,linkId:a,segmentId:v,startIndex:g,endIndex:I}=r,m=s.getUnit(c,o.UniverInstanceType.UNIVER_DOC),f=m==null?void 0:m.getSelfOrHeaderFooterModel(v).getBody(),d=(x=f==null?void 0:f.customRanges)==null?void 0:x.find(L=>L.rangeId===a&&L.rangeType===o.CustomRangeType.HYPERLINK&&L.startIndex===g&&L.endIndex===I);if(!d)return null;const h=(p=d.properties)==null?void 0:p.url;return u.jsxs("div",{className:_.clsx("univer-box-border univer-flex univer-max-w-80 univer-items-center univer-justify-between univer-overflow-hidden univer-rounded-lg univer-bg-white univer-p-3 univer-shadow dark:!univer-bg-gray-900",_.borderClassName),onClick:()=>{n.hideInfoPopup()},children:[u.jsxs("div",{className:"univer-flex univer-h-6 univer-flex-1 univer-cursor-pointer univer-items-center univer-truncate univer-text-sm univer-leading-5 univer-text-primary-500",onClick:()=>window.open(h,void 0,"noopener noreferrer"),children:[u.jsx("div",{className:"univer-mr-2 univer-flex univer-size-5 univer-flex-[0_0_auto] univer-items-center univer-justify-center univer-text-base univer-text-gray-900 dark:!univer-text-white",children:u.jsx(W,{})}),u.jsx(_.Tooltip,{showIfEllipsis:!0,title:h,children:u.jsx("span",{className:"univer-flex-1 univer-truncate",children:h})})]}),u.jsxs("div",{className:"univer-flex univer-h-6 univer-flex-[0_0_auto] univer-items-center univer-justify-center",children:[u.jsx("div",{className:"univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",onClick:()=>{navigator.clipboard.writeText(h),t.show({content:i.t("docLink.info.coped"),type:_.MessageType.Info})},children:u.jsx(_.Tooltip,{placement:"bottom",title:i.t("docLink.info.copy"),children:u.jsx(ue,{})})}),u.jsx("div",{className:"univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",onClick:()=>{e.executeCommand(P.id,{link:r})},children:u.jsx(_.Tooltip,{placement:"bottom",title:i.t("docLink.info.edit"),children:u.jsx(pe,{})})}),u.jsx("div",{className:"univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",onClick:()=>{e.executeCommand(ve.id,{unitId:c,linkId:d.rangeId,segmentId:v})},children:u.jsx(_.Tooltip,{placement:"bottom",title:i.t("docLink.info.cancel"),children:u.jsx(le,{})})})]})]})};T.componentKey="univer.doc.link-info-popup";var Ee=Object.getOwnPropertyDescriptor,je=(n,e,t,i)=>{for(var r=i>1?void 0:i?Ee(e,t):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(r=c(r)||r);return r},A=(n,e)=>(t,i)=>e(t,i,n);let k=class extends o.Disposable{constructor(e,t,i){super();O(this,"_editingLink$",new D.BehaviorSubject(null));O(this,"_showingLink$",new D.BehaviorSubject(null));O(this,"editingLink$",this._editingLink$.asObservable());O(this,"showingLink$",this._showingLink$.asObservable());O(this,"_editPopup",null);O(this,"_infoPopup",null);this._docCanvasPopupManagerService=e,this._textSelectionManagerService=t,this._univerInstanceService=i,this.disposeWithMe(()=>{this._editingLink$.complete(),this._showingLink$.complete()})}get editing(){return this._editingLink$.value}get showing(){return this._showingLink$.value}showEditPopup(e,t){this._editPopup&&this._editPopup.dispose(),this._editingLink$.next(t);const i=this._textSelectionManagerService.getTextRanges({unitId:e,subUnitId:e});let r=i==null?void 0:i[i.length-1];if(t){const{segmentId:s,segmentPage:c,startIndex:a,endIndex:v}=t;r={collapsed:!1,startOffset:a,endOffset:v+1,segmentId:s,segmentPage:c},this._textSelectionManagerService.replaceDocRanges([{startOffset:a,endOffset:v+1}])}return r?(this._editPopup=this._docCanvasPopupManagerService.attachPopupToRange(r,{componentKey:j.componentKey,direction:"bottom"},e),this._editPopup):null}hideEditPopup(){var e;this._editingLink$.next(null),(e=this._editPopup)==null||e.dispose()}showInfoPopup(e){var g,I,m,f,d,h;const{linkId:t,unitId:i,segmentId:r,segmentPage:s,startIndex:c,endIndex:a}=e;if(!(((g=this.showing)==null?void 0:g.linkId)===t&&((I=this.showing)==null?void 0:I.unitId)===i&&((m=this.showing)==null?void 0:m.segmentId)===r&&((f=this.showing)==null?void 0:f.segmentPage)===s&&((d=this.showing)==null?void 0:d.startIndex)===c&&((h=this.showing)==null?void 0:h.endIndex)===a||(this._infoPopup&&this._infoPopup.dispose(),!this._univerInstanceService.getUnit(i,o.UniverInstanceType.UNIVER_DOC))))return this._showingLink$.next({unitId:i,linkId:t,segmentId:r,segmentPage:s,startIndex:c,endIndex:a}),this._infoPopup=this._docCanvasPopupManagerService.attachPopupToRange({collapsed:!1,startOffset:c,endOffset:a+1,segmentId:r,segmentPage:s},{componentKey:T.componentKey,direction:"top-center",multipleDirection:"top",onClickOutside:()=>{this.hideInfoPopup()}},i),this._infoPopup}hideInfoPopup(){var e;this._showingLink$.next(null),(e=this._infoPopup)==null||e.dispose()}};k=je([A(0,o.Inject($.DocCanvasPopManagerService)),A(1,o.Inject(y.DocSelectionManagerService)),A(2,o.IUniverInstanceService)],k);var Te=Object.getOwnPropertyDescriptor,Ne=(n,e,t,i)=>{for(var r=i>1?void 0:i?Te(e,t):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(r=c(r)||r);return r},B=(n,e)=>(t,i)=>e(t,i,n);let N=class extends o.Disposable{constructor(n,e,t){super(),this._commandService=n,this._univerInstanceService=e,this._docHyperLinkService=t,this._initSelectionChange()}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(n=>{var e,t,i;if(n.id===y.SetTextSelectionsOperation.id){const r=n.params,{unitId:s,ranges:c,segmentId:a}=r,v=this._univerInstanceService.getUnit(s,o.UniverInstanceType.UNIVER_DOC),g=c[0];if(g&&v){const{startOffset:I,endOffset:m,collapsed:f,segmentPage:d}=g,h=(t=(e=v.getSelfOrHeaderFooterModel(a))==null?void 0:e.getBody())==null?void 0:t.customRanges;if(f){const x=(i=h==null?void 0:h.findIndex(p=>p.startIndex<I&&p.endIndex>m-1))!=null?i:-1;if(x>-1){const p=h[x];this._docHyperLinkService.showInfoPopup({unitId:s,linkId:p.rangeId,segmentId:a,segmentPage:d,startIndex:p.startIndex,endIndex:p.endIndex});return}}else if(h==null?void 0:h.find(p=>p.startIndex<=I&&p.endIndex>=m-1))return}this._docHyperLinkService.hideInfoPopup(),this._docHyperLinkService.hideEditPopup()}}))}};N=Ne([B(0,o.ICommandService),B(1,o.IUniverInstanceService),B(2,o.Inject(k))],N);var He=Object.getOwnPropertyDescriptor,$e=(n,e,t,i)=>{for(var r=i>1?void 0:i?He(e,t):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(r=c(r)||r);return r},b=(n,e)=>(t,i)=>e(t,i,n);let q=class extends o.Disposable{constructor(n,e,t,i,r,s){super(),this._context=n,this._docEventManagerService=e,this._commandService=t,this._hyperLinkPopupService=i,this._docSkeletonManagerService=r,this._docSelectionManagerService=s,!(this._context.unitId===o.DOCS_ZEN_EDITOR_UNIT_ID_KEY||this._context.unitId===o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)&&(this._initHover(),this._initClick())}get _skeleton(){return this._docSkeletonManagerService.getSkeleton()}_hideInfoPopup(){this._hyperLinkPopupService.showing&&this._commandService.executeCommand(Y.id)}_initHover(){this.disposeWithMe(this._docEventManagerService.hoverCustomRanges$.subscribe(n=>{var r;const e=n.find(s=>s.range.rangeType===o.CustomRangeType.HYPERLINK),t=this._docSelectionManagerService.getTextRanges(),i=t==null?void 0:t[0].segmentId;if(((r=e==null?void 0:e.segmentId)!=null?r:"")!==i){this._hideInfoPopup();return}e?this._commandService.executeCommand(Y.id,{unitId:this._context.unitId,linkId:e.range.rangeId,segmentId:e.segmentId,segmentPage:e.segmentPageIndex,rangeId:e.range.rangeId,startIndex:e.range.startIndex,endIndex:e.range.endIndex}):this._hideInfoPopup()}))}_initClick(){this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe(n=>{const e=n.range;e&&this._commandService.executeCommand(he.id,{unitId:this._context.unitId,linkId:e.rangeId,segmentId:n.segmentId})}))}};q=$e([b(1,o.Inject($.DocEventManagerService)),b(2,o.ICommandService),b(3,o.Inject(k)),b(4,o.Inject(y.DocSkeletonManagerService)),b(5,o.Inject(y.DocSelectionManagerService))],q);var Ke=Object.getOwnPropertyDescriptor,Ae=(n,e,t,i)=>{for(var r=i>1?void 0:i?Ke(e,t):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(r=c(r)||r);return r},F=(n,e)=>(t,i)=>e(t,i,n);let Z=class extends o.Disposable{constructor(n,e,t,i){super(),this._context=n,this._docInterceptorService=e,this._hyperLinkService=t,this._docRenderController=i,this._init(),this._initReRender()}_init(){this._docInterceptorService.intercept(y.DOC_INTERCEPTOR_POINT.CUSTOM_RANGE,{handler:(n,e,t)=>{if(!n)return t(n);const{unitId:i,index:r}=e,s=this._hyperLinkService.showing;if(!s)return t({...n,active:!1});const{linkId:c,unitId:a,startIndex:v,endIndex:g}=s,I=a===i&&n.rangeId===c&&r>=v&&r<=g;return t({...n,active:I})}})}_initReRender(){this.disposeWithMe(this._hyperLinkService.showingLink$.pipe(D.distinctUntilChanged((n,e)=>(n==null?void 0:n.linkId)===(e==null?void 0:e.linkId)&&(n==null?void 0:n.unitId)===(e==null?void 0:e.unitId)&&(n==null?void 0:n.startIndex)===(e==null?void 0:e.startIndex)),D.pairwise()).subscribe(([n,e])=>{e?e.unitId===this._context.unitId&&this._docRenderController.reRender(e.unitId):n&&n.unitId===this._context.unitId&&this._docRenderController.reRender(n.unitId)}))}};Z=Ae([F(1,o.Inject(y.DocInterceptorService)),F(2,o.Inject(k)),F(3,o.Inject($.DocRenderController))],Z);const fe="doc-hyper-link-icon";function se(n){return{id:P.id,type:l.MenuItemType.BUTTON,icon:fe,title:"docLink.menu.tooltip",tooltip:"docLink.menu.tooltip",hidden$:l.getMenuHiddenObservable(n,o.UniverInstanceType.UNIVER_DOC),disabled$:new D.Observable(function(e){const i=n.get(y.DocSelectionManagerService).textSelection$.pipe(D.debounceTime(16)).subscribe(()=>{e.next(ge(n))});return()=>{i.unsubscribe()}})}}const Be={id:P.id,binding:l.MetaKeys.CTRL_COMMAND|l.KeyCode.K,description:"docLink.menu.tooltip",preconditions:$.whenDocAndEditorFocused},Fe={[l.RibbonInsertGroup.MEDIA]:{[P.id]:{order:1,menuItemFactory:se}},[l.ContextMenuPosition.MAIN_AREA]:{[l.ContextMenuGroup.DATA]:{[P.id]:{order:0,menuItemFactory:se}}}};var Ve=Object.getOwnPropertyDescriptor,Ye=(n,e,t,i)=>{for(var r=i>1?void 0:i?Ve(e,t):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(r=c(r)||r);return r},E=(n,e)=>(t,i)=>e(t,i,n);let H=class extends o.Disposable{constructor(n,e,t,i){super(),this._componentManager=n,this._commandService=e,this._menuManagerService=t,this._shortcutService=i,this._initComponents(),this._initCommands(),this._initMenus(),this._initShortcut()}_initComponents(){[[j,j.componentKey],[T,T.componentKey],[W,fe]].forEach(([n,e])=>{this.disposeWithMe(this._componentManager.register(e,n))})}_initCommands(){[ce,ae,ve,P,Y,he].forEach(n=>{this._commandService.registerCommand(n)})}_initShortcut(){[Be].forEach(n=>{this._shortcutService.registerShortcut(n)})}_initMenus(){this._menuManagerService.mergeMenu(Fe)}};H=Ye([E(0,o.Inject(l.ComponentManager)),E(1,o.ICommandService),E(2,l.IMenuManagerService),E(3,l.IShortcutService)],H);const qe="DOC_HYPER_LINK_UI_PLUGIN";var Ze=Object.defineProperty,We=Object.getOwnPropertyDescriptor,ze=(n,e,t)=>e in n?Ze(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Ge=(n,e,t,i)=>{for(var r=i>1?void 0:i?We(e,t):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(r=c(r)||r);return r},V=(n,e)=>(t,i)=>e(t,i,n),Ie=(n,e,t)=>ze(n,typeof e!="symbol"?e+"":e,t);exports.UniverDocsHyperLinkUIPlugin=class extends o.Plugin{constructor(e=oe,t,i,r){super(),this._config=e,this._injector=t,this._renderManagerSrv=i,this._configService=r;const{menu:s,...c}=o.merge({},oe,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig(Se,c)}onStarting(){[[k],[H],[N]].forEach(t=>{this._injector.add(t)}),this._injector.get(H)}onReady(){this._injector.get(N)}onRendered(){this._initRenderModule()}_initRenderModule(){[[Z],[q]].forEach(e=>{this._renderManagerSrv.registerRenderModule(o.UniverInstanceType.UNIVER_DOC,e)})}};Ie(exports.UniverDocsHyperLinkUIPlugin,"pluginName",qe);Ie(exports.UniverDocsHyperLinkUIPlugin,"type",o.UniverInstanceType.UNIVER_DOC);exports.UniverDocsHyperLinkUIPlugin=Ge([o.DependentOn(Ce.UniverDocsHyperLinkPlugin),V(1,o.Inject(o.Injector)),V(2,ye.IRenderManagerService),V(3,o.IConfigService)],exports.UniverDocsHyperLinkUIPlugin);
package/lib/es/index.js CHANGED
@@ -1,16 +1,16 @@
1
1
  var Te = Object.defineProperty;
2
2
  var He = (n, e, t) => e in n ? Te(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
3
  var O = (n, e, t) => He(n, typeof e != "symbol" ? e + "" : e, t);
4
- import { CommandType as R, ICommandService as k, generateRandomId as je, CustomRangeType as D, IUniverInstanceService as L, UniverInstanceType as _, getBodySlice as Se, LocaleService as ye, Tools as Ae, BuildTextUtils as fe, Inject as I, Disposable as E, DOCS_ZEN_EDITOR_UNIT_ID_KEY as Ke, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as Fe, DependentOn as Be, Injector as Ve, IConfigService as Ye, Plugin as Ze, merge as ze } from "@univerjs/core";
5
- import { UniverDocsHyperLinkPlugin as We } from "@univerjs/docs-hyper-link";
4
+ import { CommandType as R, ICommandService as k, generateRandomId as je, CustomRangeType as D, IUniverInstanceService as L, UniverInstanceType as _, getBodySlice as Se, LocaleService as ye, Tools as Ae, BuildTextUtils as he, Inject as I, Disposable as E, DOCS_ZEN_EDITOR_UNIT_ID_KEY as Ke, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as Fe, DependentOn as Be, Injector as Ve, IConfigService as Ye, Plugin as Ze, merge as We } from "@univerjs/core";
5
+ import { UniverDocsHyperLinkPlugin as ze } from "@univerjs/docs-hyper-link";
6
6
  import { IRenderManagerService as Ge } from "@univerjs/engine-render";
7
- import { addCustomRangeBySelectionFactory as qe, DocSelectionManagerService as w, replaceSelectionFactory as Je, deleteCustomRangeFactory as Qe, SetTextSelectionsOperation as Xe, DocSkeletonManagerService as en, DocInterceptorService as nn, DOC_INTERCEPTOR_POINT as tn } from "@univerjs/docs";
7
+ import { addCustomRangeBySelectionFactory as qe, DocSelectionManagerService as M, replaceSelectionFactory as Je, deleteCustomRangeFactory as Qe, SetTextSelectionsOperation as Xe, DocSkeletonManagerService as en, DocInterceptorService as nn, DOC_INTERCEPTOR_POINT as tn } from "@univerjs/docs";
8
8
  import { DocCanvasPopManagerService as rn, DocEventManagerService as on, DocRenderController as sn, whenDocAndEditorFocused as cn } from "@univerjs/docs-ui";
9
- import { BehaviorSubject as he, distinctUntilChanged as dn, pairwise as an, Observable as ln, debounceTime as un } from "rxjs";
10
- import { jsxs as P, jsx as f } from "react/jsx-runtime";
9
+ import { BehaviorSubject as fe, distinctUntilChanged as dn, pairwise as an, Observable as ln, debounceTime as un } from "rxjs";
10
+ import { jsxs as P, jsx as h } from "react/jsx-runtime";
11
11
  import { clsx as xe, FormLayout as ve, Input as me, Button as Ie, borderClassName as ke, Tooltip as A, MessageType as pn } from "@univerjs/design";
12
- import { useDependency as S, useObservable as Le, KeyCode as X, IMessageService as gn, MetaKeys as fn, getMenuHiddenObservable as hn, MenuItemType as vn, ContextMenuPosition as mn, ContextMenuGroup as In, RibbonInsertGroup as _n, ComponentManager as Cn, IMenuManagerService as Sn, IShortcutService as yn } from "@univerjs/ui";
13
- import { useState as W, useEffect as xn, forwardRef as N, useRef as kn, createElement as U } from "react";
12
+ import { useDependency as S, useObservable as Le, KeyCode as X, IMessageService as gn, MetaKeys as hn, getMenuHiddenObservable as fn, MenuItemType as vn, ContextMenuPosition as mn, ContextMenuGroup as In, RibbonInsertGroup as _n, ComponentManager as Cn, IMenuManagerService as Sn, IShortcutService as yn } from "@univerjs/ui";
13
+ import { useState as z, useEffect as xn, forwardRef as N, useRef as kn, createElement as U } from "react";
14
14
  const Ln = "docs-hyper-link-ui.config", _e = {}, Oe = {
15
15
  type: R.COMMAND,
16
16
  id: "docs.command.add-hyper-link",
@@ -38,10 +38,10 @@ const Ln = "docs-hyper-link-ui.config", _e = {}, Oe = {
38
38
  var p;
39
39
  if (!e)
40
40
  return !1;
41
- const { unitId: t, payload: i, segmentId: r, linkId: o } = e, s = n.get(k), c = n.get(L), u = n.get(w).getActiveTextRange(), h = c.getUnit(t, _.UNIVER_DOC);
42
- if (!u || !h)
41
+ const { unitId: t, payload: i, segmentId: r, linkId: o } = e, s = n.get(k), c = n.get(L), u = n.get(M).getActiveTextRange(), f = c.getUnit(t, _.UNIVER_DOC);
42
+ if (!u || !f)
43
43
  return !1;
44
- const g = (p = Se(h.getSelfOrHeaderFooterModel(r).getBody(), u.startOffset, u.endOffset).textRuns) == null ? void 0 : p[0];
44
+ const g = (p = Se(f.getSelfOrHeaderFooterModel(r).getBody(), u.startOffset, u.endOffset).textRuns) == null ? void 0 : p[0];
45
45
  g && (g.ed = e.label.length + 1);
46
46
  const d = Je(n, {
47
47
  unitId: t,
@@ -78,18 +78,18 @@ function bn(n) {
78
78
  return On(n) ? n : Pn(n) ? `mailto://${n}` : `https://${n}`;
79
79
  }
80
80
  const F = () => {
81
- const n = S(y), e = S(ye), t = Le(n.editingLink$), i = S(k), r = S(L), o = S(w), [s, c] = W(""), [l, u] = W(""), [h, v] = W(!1), g = Ae.isLegalUrl(s), d = t ? r.getUnit(t.unitId, _.UNIVER_DOC) : r.getCurrentUnitForType(_.UNIVER_DOC);
81
+ const n = S(y), e = S(ye), t = Le(n.editingLink$), i = S(k), r = S(L), o = S(M), [s, c] = z(""), [l, u] = z(""), [f, v] = z(!1), g = Ae.isLegalUrl(s), d = t ? r.getUnit(t.unitId, _.UNIVER_DOC) : r.getCurrentUnitForType(_.UNIVER_DOC);
82
82
  xn(() => {
83
83
  var oe, se, ce, de, ae, le, ue, pe, ge;
84
84
  const a = o.getActiveTextRange();
85
85
  if (!a)
86
86
  return;
87
87
  if (t) {
88
- const H = (oe = d == null ? void 0 : d.getSelfOrHeaderFooterModel(t.segmentId)) == null ? void 0 : oe.getBody(), j = (se = H == null ? void 0 : H.customRanges) == null ? void 0 : se.find((z) => (t == null ? void 0 : t.linkId) === z.rangeId && z.startIndex === t.startIndex && z.endIndex === t.endIndex);
89
- d && j && (c((de = (ce = j.properties) == null ? void 0 : ce.url) != null ? de : ""), u(fe.transform.getPlainText(Se(H, j.startIndex, j.endIndex + 1).dataStream)));
88
+ const H = (oe = d == null ? void 0 : d.getSelfOrHeaderFooterModel(t.segmentId)) == null ? void 0 : oe.getBody(), j = (se = H == null ? void 0 : H.customRanges) == null ? void 0 : se.find((W) => (t == null ? void 0 : t.linkId) === W.rangeId && W.startIndex === t.startIndex && W.endIndex === t.endIndex);
89
+ d && j && (c((de = (ce = j.properties) == null ? void 0 : ce.url) != null ? de : ""), u(he.transform.getPlainText(Se(H, j.startIndex, j.endIndex + 1).dataStream)));
90
90
  return;
91
91
  }
92
- const x = (ae = d == null ? void 0 : d.getSelfOrHeaderFooterModel(a.segmentId)) == null ? void 0 : ae.getBody(), re = x ? a : null, T = re && ((ue = fe.customRange.getCustomRangesInterestsWithSelection(re, (le = x == null ? void 0 : x.customRanges) != null ? le : [])) == null ? void 0 : ue[0]);
92
+ const x = (ae = d == null ? void 0 : d.getSelfOrHeaderFooterModel(a.segmentId)) == null ? void 0 : ae.getBody(), re = x ? a : null, T = re && ((ue = he.customRange.getCustomRangesInterestsWithSelection(re, (le = x == null ? void 0 : x.customRanges) != null ? le : [])) == null ? void 0 : ue[0]);
93
93
  d && T && c((ge = (pe = T == null ? void 0 : T.properties) == null ? void 0 : pe.url) != null ? ge : "");
94
94
  }, [d, t, o, r]);
95
95
  const p = () => {
@@ -123,12 +123,12 @@ const F = () => {
123
123
  className: xe("univer-box-border univer-w-[328px] univer-rounded-xl univer-bg-white univer-px-6 univer-py-5 univer-shadow dark:!univer-bg-gray-900", ke),
124
124
  children: [
125
125
  /* @__PURE__ */ P("div", { children: [
126
- t ? /* @__PURE__ */ f(
126
+ t ? /* @__PURE__ */ h(
127
127
  ve,
128
128
  {
129
129
  label: e.t("docLink.edit.label"),
130
- error: h && !l ? e.t("docLink.edit.labelError") : "",
131
- children: /* @__PURE__ */ f(
130
+ error: f && !l ? e.t("docLink.edit.labelError") : "",
131
+ children: /* @__PURE__ */ h(
132
132
  me,
133
133
  {
134
134
  value: l,
@@ -141,12 +141,12 @@ const F = () => {
141
141
  )
142
142
  }
143
143
  ) : null,
144
- /* @__PURE__ */ f(
144
+ /* @__PURE__ */ h(
145
145
  ve,
146
146
  {
147
147
  label: e.t("docLink.edit.address"),
148
- error: h && !g ? e.t("docLink.edit.addressError") : "",
149
- children: /* @__PURE__ */ f(
148
+ error: f && !g ? e.t("docLink.edit.addressError") : "",
149
+ children: /* @__PURE__ */ h(
150
150
  me,
151
151
  {
152
152
  value: s,
@@ -161,8 +161,8 @@ const F = () => {
161
161
  )
162
162
  ] }),
163
163
  /* @__PURE__ */ P("div", { className: "univer-flex univer-justify-end univer-gap-3", children: [
164
- /* @__PURE__ */ f(Ie, { onClick: p, children: e.t("docLink.edit.cancel") }),
165
- /* @__PURE__ */ f(
164
+ /* @__PURE__ */ h(Ie, { onClick: p, children: e.t("docLink.edit.cancel") }),
165
+ /* @__PURE__ */ h(
166
166
  Ie,
167
167
  {
168
168
  variant: "primary",
@@ -197,11 +197,11 @@ var m = function() {
197
197
  return be(t, "".concat(i), { defIds: t.defIds, idSuffix: l.current }, m({ ref: e, className: c }, s), o);
198
198
  });
199
199
  function be(n, e, t, i, r) {
200
- return U(n.tag, m(m({ key: e }, wn(n, t, r)), i), (Mn(n, t).children || []).map(function(o, s) {
200
+ return U(n.tag, m(m({ key: e }, Mn(n, t, r)), i), (wn(n, t).children || []).map(function(o, s) {
201
201
  return be(o, "".concat(e, "-").concat(n.tag, "-").concat(s), t, void 0, r);
202
202
  }));
203
203
  }
204
- function wn(n, e, t) {
204
+ function Mn(n, e, t) {
205
205
  var i = m({}, n.attrs);
206
206
  t != null && t.colorChannel1 && i.fill === "colorChannel1" && (i.fill = t.colorChannel1), n.tag === "mask" && i.id && (i.id = i.id + e.idSuffix), Object.entries(i).forEach(function(o) {
207
207
  var s = o[0], c = o[1];
@@ -213,7 +213,7 @@ function wn(n, e, t) {
213
213
  typeof c == "string" && (i[s] = c.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")")));
214
214
  })), i;
215
215
  }
216
- function Mn(n, e) {
216
+ function wn(n, e) {
217
217
  var t, i = e.defIds;
218
218
  return !i || i.length === 0 ? n : n.tag === "defs" && (!((t = n.children) === null || t === void 0) && t.length) ? m(m({}, n), { children: n.children.map(function(r) {
219
219
  return typeof r.attrs.id == "string" && i && i.indexOf(r.attrs.id) > -1 ? m(m({}, r), { attrs: m(m({}, r.attrs), { id: r.attrs.id + e.idSuffix }) }) : r;
@@ -239,22 +239,22 @@ var Nn = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em"
239
239
  }));
240
240
  });
241
241
  ie.displayName = "LinkSingle";
242
- var Un = { 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" } }] }, we = N(function(n, e) {
242
+ var Un = { 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" } }] }, Me = N(function(n, e) {
243
243
  return U($, Object.assign({}, n, {
244
244
  id: "unlink-single",
245
245
  ref: e,
246
246
  icon: Un
247
247
  }));
248
248
  });
249
- we.displayName = "UnlinkSingle";
250
- var $n = { 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" } }] }, Me = N(function(n, e) {
249
+ Me.displayName = "UnlinkSingle";
250
+ var $n = { 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" } }] }, we = N(function(n, e) {
251
251
  return U($, Object.assign({}, n, {
252
252
  id: "write-single",
253
253
  ref: e,
254
254
  icon: $n
255
255
  }));
256
256
  });
257
- Me.displayName = "WriteSingle";
257
+ we.displayName = "WriteSingle";
258
258
  const De = {
259
259
  type: R.COMMAND,
260
260
  id: "docs.command.delete-hyper-link",
@@ -265,7 +265,7 @@ const De = {
265
265
  return s ? await o.syncExecuteCommand(s.id, s.params) : !1;
266
266
  }
267
267
  }, Ee = (n) => {
268
- const e = n.get(w), t = n.get(L), i = e.getTextRanges();
268
+ const e = n.get(M), t = n.get(L), i = e.getTextRanges();
269
269
  if (!(i != null && i.length))
270
270
  return !0;
271
271
  const r = i[0];
@@ -292,10 +292,10 @@ const De = {
292
292
  type: R.OPERATION,
293
293
  id: "doc.operation.click-hyper-link",
294
294
  handler(n, e) {
295
- var u, h, v;
295
+ var u, f, v;
296
296
  if (!e)
297
297
  return !1;
298
- const { unitId: t, linkId: i, segmentId: r } = e, s = n.get(L).getUnit(t, _.UNIVER_DOC), c = s == null ? void 0 : s.getSelfOrHeaderFooterModel(r).getBody(), l = (v = (h = (u = c == null ? void 0 : c.customRanges) == null ? void 0 : u.find((g) => g.rangeId === i && g.rangeType === D.HYPERLINK)) == null ? void 0 : h.properties) == null ? void 0 : v.url;
298
+ const { unitId: t, linkId: i, segmentId: r } = e, s = n.get(L).getUnit(t, _.UNIVER_DOC), c = s == null ? void 0 : s.getSelfOrHeaderFooterModel(r).getBody(), l = (v = (f = (u = c == null ? void 0 : c.customRanges) == null ? void 0 : u.find((g) => g.rangeId === i && g.rangeType === D.HYPERLINK)) == null ? void 0 : f.properties) == null ? void 0 : v.url;
299
299
  return l && window.open(l, "_blank", "noopener noreferrer"), !0;
300
300
  }
301
301
  }, B = () => {
@@ -303,7 +303,7 @@ const De = {
303
303
  const n = S(y), e = S(k), t = S(gn), i = S(ye), r = Le(n.showingLink$), o = S(L);
304
304
  if (!r)
305
305
  return null;
306
- const { unitId: s, linkId: c, segmentId: l, startIndex: u, endIndex: h } = r, v = o.getUnit(s, _.UNIVER_DOC), g = v == null ? void 0 : v.getSelfOrHeaderFooterModel(l).getBody(), d = (C = g == null ? void 0 : g.customRanges) == null ? void 0 : C.find((x) => x.rangeId === c && x.rangeType === D.HYPERLINK && x.startIndex === u && x.endIndex === h);
306
+ const { unitId: s, linkId: c, segmentId: l, startIndex: u, endIndex: f } = r, v = o.getUnit(s, _.UNIVER_DOC), g = v == null ? void 0 : v.getSelfOrHeaderFooterModel(l).getBody(), d = (C = g == null ? void 0 : g.customRanges) == null ? void 0 : C.find((x) => x.rangeId === c && x.rangeType === D.HYPERLINK && x.startIndex === u && x.endIndex === f);
307
307
  if (!d)
308
308
  return null;
309
309
  const p = (a = d.properties) == null ? void 0 : a.url;
@@ -321,19 +321,19 @@ const De = {
321
321
  className: "univer-flex univer-h-6 univer-flex-1 univer-cursor-pointer univer-items-center univer-truncate univer-text-sm univer-leading-5 univer-text-primary-500",
322
322
  onClick: () => window.open(p, void 0, "noopener noreferrer"),
323
323
  children: [
324
- /* @__PURE__ */ f(
324
+ /* @__PURE__ */ h(
325
325
  "div",
326
326
  {
327
327
  className: "univer-mr-2 univer-flex univer-size-5 univer-flex-[0_0_auto] univer-items-center univer-justify-center univer-text-base univer-text-gray-900 dark:!univer-text-white",
328
- children: /* @__PURE__ */ f(ie, {})
328
+ children: /* @__PURE__ */ h(ie, {})
329
329
  }
330
330
  ),
331
- /* @__PURE__ */ f(A, { showIfEllipsis: !0, title: p, children: /* @__PURE__ */ f("span", { className: "univer-flex-1 univer-truncate", children: p }) })
331
+ /* @__PURE__ */ h(A, { showIfEllipsis: !0, title: p, children: /* @__PURE__ */ h("span", { className: "univer-flex-1 univer-truncate", children: p }) })
332
332
  ]
333
333
  }
334
334
  ),
335
335
  /* @__PURE__ */ P("div", { className: "univer-flex univer-h-6 univer-flex-[0_0_auto] univer-items-center univer-justify-center", children: [
336
- /* @__PURE__ */ f(
336
+ /* @__PURE__ */ h(
337
337
  "div",
338
338
  {
339
339
  className: "univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",
@@ -343,10 +343,10 @@ const De = {
343
343
  type: pn.Info
344
344
  });
345
345
  },
346
- children: /* @__PURE__ */ f(A, { placement: "bottom", title: i.t("docLink.info.copy"), children: /* @__PURE__ */ f(Re, {}) })
346
+ children: /* @__PURE__ */ h(A, { placement: "bottom", title: i.t("docLink.info.copy"), children: /* @__PURE__ */ h(Re, {}) })
347
347
  }
348
348
  ),
349
- /* @__PURE__ */ f(
349
+ /* @__PURE__ */ h(
350
350
  "div",
351
351
  {
352
352
  className: "univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",
@@ -355,10 +355,10 @@ const De = {
355
355
  link: r
356
356
  });
357
357
  },
358
- children: /* @__PURE__ */ f(A, { placement: "bottom", title: i.t("docLink.info.edit"), children: /* @__PURE__ */ f(Me, {}) })
358
+ children: /* @__PURE__ */ h(A, { placement: "bottom", title: i.t("docLink.info.edit"), children: /* @__PURE__ */ h(we, {}) })
359
359
  }
360
360
  ),
361
- /* @__PURE__ */ f(
361
+ /* @__PURE__ */ h(
362
362
  "div",
363
363
  {
364
364
  className: "univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",
@@ -369,7 +369,7 @@ const De = {
369
369
  segmentId: l
370
370
  });
371
371
  },
372
- children: /* @__PURE__ */ f(A, { placement: "bottom", title: i.t("docLink.info.cancel"), children: /* @__PURE__ */ f(we, {}) })
372
+ children: /* @__PURE__ */ h(A, { placement: "bottom", title: i.t("docLink.info.cancel"), children: /* @__PURE__ */ h(Me, {}) })
373
373
  }
374
374
  )
375
375
  ] })
@@ -386,8 +386,8 @@ var Tn = Object.getOwnPropertyDescriptor, Hn = (n, e, t, i) => {
386
386
  let y = class extends E {
387
387
  constructor(e, t, i) {
388
388
  super();
389
- O(this, "_editingLink$", new he(null));
390
- O(this, "_showingLink$", new he(null));
389
+ O(this, "_editingLink$", new fe(null));
390
+ O(this, "_showingLink$", new fe(null));
391
391
  O(this, "editingLink$", this._editingLink$.asObservable());
392
392
  O(this, "showingLink$", this._showingLink$.asObservable());
393
393
  O(this, "_editPopup", null);
@@ -433,9 +433,9 @@ let y = class extends E {
433
433
  this._editingLink$.next(null), (e = this._editPopup) == null || e.dispose();
434
434
  }
435
435
  showInfoPopup(e) {
436
- var u, h, v, g, d, p;
436
+ var u, f, v, g, d, p;
437
437
  const { linkId: t, unitId: i, segmentId: r, segmentPage: o, startIndex: s, endIndex: c } = e;
438
- if (!(((u = this.showing) == null ? void 0 : u.linkId) === t && ((h = this.showing) == null ? void 0 : h.unitId) === i && ((v = this.showing) == null ? void 0 : v.segmentId) === r && ((g = this.showing) == null ? void 0 : g.segmentPage) === o && ((d = this.showing) == null ? void 0 : d.startIndex) === s && ((p = this.showing) == null ? void 0 : p.endIndex) === c || (this._infoPopup && this._infoPopup.dispose(), !this._univerInstanceService.getUnit(i, _.UNIVER_DOC))))
438
+ if (!(((u = this.showing) == null ? void 0 : u.linkId) === t && ((f = this.showing) == null ? void 0 : f.unitId) === i && ((v = this.showing) == null ? void 0 : v.segmentId) === r && ((g = this.showing) == null ? void 0 : g.segmentPage) === o && ((d = this.showing) == null ? void 0 : d.startIndex) === s && ((p = this.showing) == null ? void 0 : p.endIndex) === c || (this._infoPopup && this._infoPopup.dispose(), !this._univerInstanceService.getUnit(i, _.UNIVER_DOC))))
439
439
  return this._showingLink$.next({ unitId: i, linkId: t, segmentId: r, segmentPage: o, startIndex: s, endIndex: c }), this._infoPopup = this._docCanvasPopupManagerService.attachPopupToRange(
440
440
  {
441
441
  collapsed: !1,
@@ -462,7 +462,7 @@ let y = class extends E {
462
462
  };
463
463
  y = Hn([
464
464
  G(0, I(rn)),
465
- G(1, I(w)),
465
+ G(1, I(M)),
466
466
  G(2, L)
467
467
  ], y);
468
468
  var jn = Object.getOwnPropertyDescriptor, An = (n, e, t, i) => {
@@ -481,15 +481,15 @@ let V = class extends E {
481
481
  if (n.id === Xe.id) {
482
482
  const r = n.params, { unitId: o, ranges: s, segmentId: c } = r, l = this._univerInstanceService.getUnit(o, _.UNIVER_DOC), u = s[0];
483
483
  if (u && l) {
484
- const { startOffset: h, endOffset: v, collapsed: g, segmentPage: d } = u, p = (t = (e = l.getSelfOrHeaderFooterModel(c)) == null ? void 0 : e.getBody()) == null ? void 0 : t.customRanges;
484
+ const { startOffset: f, endOffset: v, collapsed: g, segmentPage: d } = u, p = (t = (e = l.getSelfOrHeaderFooterModel(c)) == null ? void 0 : e.getBody()) == null ? void 0 : t.customRanges;
485
485
  if (g) {
486
- const C = (i = p == null ? void 0 : p.findIndex((a) => a.startIndex < h && a.endIndex > v - 1)) != null ? i : -1;
486
+ const C = (i = p == null ? void 0 : p.findIndex((a) => a.startIndex < f && a.endIndex > v - 1)) != null ? i : -1;
487
487
  if (C > -1) {
488
488
  const a = p[C];
489
489
  this._docHyperLinkService.showInfoPopup({ unitId: o, linkId: a.rangeId, segmentId: c, segmentPage: d, startIndex: a.startIndex, endIndex: a.endIndex });
490
490
  return;
491
491
  }
492
- } else if (p == null ? void 0 : p.find((a) => a.startIndex <= h && a.endIndex >= v - 1))
492
+ } else if (p == null ? void 0 : p.find((a) => a.startIndex <= f && a.endIndex >= v - 1))
493
493
  return;
494
494
  }
495
495
  this._docHyperLinkService.hideInfoPopup(), this._docHyperLinkService.hideEditPopup();
@@ -507,7 +507,7 @@ var Kn = Object.getOwnPropertyDescriptor, Fn = (n, e, t, i) => {
507
507
  for (var r = i > 1 ? void 0 : i ? Kn(e, t) : e, o = n.length - 1, s; o >= 0; o--)
508
508
  (s = n[o]) && (r = s(r) || r);
509
509
  return r;
510
- }, M = (n, e) => (t, i) => e(t, i, n);
510
+ }, w = (n, e) => (t, i) => e(t, i, n);
511
511
  let ne = class extends E {
512
512
  constructor(n, e, t, i, r, o) {
513
513
  super(), this._context = n, this._docEventManagerService = e, this._commandService = t, this._hyperLinkPopupService = i, this._docSkeletonManagerService = r, this._docSelectionManagerService = o, !(this._context.unitId === Ke || this._context.unitId === Fe) && (this._initHover(), this._initClick());
@@ -561,11 +561,11 @@ let ne = class extends E {
561
561
  }
562
562
  };
563
563
  ne = Fn([
564
- M(1, I(on)),
565
- M(2, k),
566
- M(3, I(y)),
567
- M(4, I(en)),
568
- M(5, I(w))
564
+ w(1, I(on)),
565
+ w(2, k),
566
+ w(3, I(y)),
567
+ w(4, I(en)),
568
+ w(5, I(M))
569
569
  ], ne);
570
570
  var Bn = Object.getOwnPropertyDescriptor, Vn = (n, e, t, i) => {
571
571
  for (var r = i > 1 ? void 0 : i ? Bn(e, t) : e, o = n.length - 1, s; o >= 0; o--)
@@ -587,10 +587,10 @@ let te = class extends E {
587
587
  ...n,
588
588
  active: !1
589
589
  });
590
- const { linkId: s, unitId: c, startIndex: l, endIndex: u } = o, h = c === i && n.rangeId === s && r >= l && r <= u;
590
+ const { linkId: s, unitId: c, startIndex: l, endIndex: u } = o, f = c === i && n.rangeId === s && r >= l && r <= u;
591
591
  return t({
592
592
  ...n,
593
- active: h
593
+ active: f
594
594
  });
595
595
  }
596
596
  });
@@ -617,9 +617,9 @@ function Ce(n) {
617
617
  icon: Ue,
618
618
  title: "docLink.menu.tooltip",
619
619
  tooltip: "docLink.menu.tooltip",
620
- hidden$: hn(n, _.UNIVER_DOC),
620
+ hidden$: fn(n, _.UNIVER_DOC),
621
621
  disabled$: new ln(function(e) {
622
- const i = n.get(w).textSelection$.pipe(un(16)).subscribe(() => {
622
+ const i = n.get(M).textSelection$.pipe(un(16)).subscribe(() => {
623
623
  e.next(Ee(n));
624
624
  });
625
625
  return () => {
@@ -630,7 +630,7 @@ function Ce(n) {
630
630
  }
631
631
  const Yn = {
632
632
  id: b.id,
633
- binding: fn.CTRL_COMMAND | X.K,
633
+ binding: hn.CTRL_COMMAND | X.K,
634
634
  description: "docLink.menu.tooltip",
635
635
  preconditions: cn
636
636
  }, Zn = {
@@ -649,8 +649,8 @@ const Yn = {
649
649
  }
650
650
  }
651
651
  };
652
- var zn = Object.getOwnPropertyDescriptor, Wn = (n, e, t, i) => {
653
- for (var r = i > 1 ? void 0 : i ? zn(e, t) : e, o = n.length - 1, s; o >= 0; o--)
652
+ var Wn = Object.getOwnPropertyDescriptor, zn = (n, e, t, i) => {
653
+ for (var r = i > 1 ? void 0 : i ? Wn(e, t) : e, o = n.length - 1, s; o >= 0; o--)
654
654
  (s = n[o]) && (r = s(r) || r);
655
655
  return r;
656
656
  }, K = (n, e) => (t, i) => e(t, i, n);
@@ -664,7 +664,9 @@ let Y = class extends E {
664
664
  [B, B.componentKey],
665
665
  [ie, Ue]
666
666
  ].forEach(([n, e]) => {
667
- this._componentManager.register(e, n);
667
+ this.disposeWithMe(
668
+ this._componentManager.register(e, n)
669
+ );
668
670
  });
669
671
  }
670
672
  _initCommands() {
@@ -688,7 +690,7 @@ let Y = class extends E {
688
690
  this._menuManagerService.mergeMenu(Zn);
689
691
  }
690
692
  };
691
- Y = Wn([
693
+ Y = zn([
692
694
  K(0, I(Cn)),
693
695
  K(1, k),
694
696
  K(2, Sn),
@@ -703,7 +705,7 @@ var qn = Object.defineProperty, Jn = Object.getOwnPropertyDescriptor, Qn = (n, e
703
705
  let Z = class extends Ze {
704
706
  constructor(n = _e, e, t, i) {
705
707
  super(), this._config = n, this._injector = e, this._renderManagerSrv = t, this._configService = i;
706
- const { menu: r, ...o } = ze(
708
+ const { menu: r, ...o } = We(
707
709
  {},
708
710
  _e,
709
711
  this._config
@@ -737,7 +739,7 @@ let Z = class extends Ze {
737
739
  $e(Z, "pluginName", Gn);
738
740
  $e(Z, "type", _.UNIVER_DOC);
739
741
  Z = Xn([
740
- Be(We),
742
+ Be(ze),
741
743
  Q(1, I(Ve)),
742
744
  Q(2, Ge),
743
745
  Q(3, Ye)
package/lib/index.js CHANGED
@@ -1,16 +1,16 @@
1
1
  var Te = Object.defineProperty;
2
2
  var He = (n, e, t) => e in n ? Te(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
3
  var O = (n, e, t) => He(n, typeof e != "symbol" ? e + "" : e, t);
4
- import { CommandType as R, ICommandService as k, generateRandomId as je, CustomRangeType as D, IUniverInstanceService as L, UniverInstanceType as _, getBodySlice as Se, LocaleService as ye, Tools as Ae, BuildTextUtils as fe, Inject as I, Disposable as E, DOCS_ZEN_EDITOR_UNIT_ID_KEY as Ke, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as Fe, DependentOn as Be, Injector as Ve, IConfigService as Ye, Plugin as Ze, merge as ze } from "@univerjs/core";
5
- import { UniverDocsHyperLinkPlugin as We } from "@univerjs/docs-hyper-link";
4
+ import { CommandType as R, ICommandService as k, generateRandomId as je, CustomRangeType as D, IUniverInstanceService as L, UniverInstanceType as _, getBodySlice as Se, LocaleService as ye, Tools as Ae, BuildTextUtils as he, Inject as I, Disposable as E, DOCS_ZEN_EDITOR_UNIT_ID_KEY as Ke, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as Fe, DependentOn as Be, Injector as Ve, IConfigService as Ye, Plugin as Ze, merge as We } from "@univerjs/core";
5
+ import { UniverDocsHyperLinkPlugin as ze } from "@univerjs/docs-hyper-link";
6
6
  import { IRenderManagerService as Ge } from "@univerjs/engine-render";
7
- import { addCustomRangeBySelectionFactory as qe, DocSelectionManagerService as w, replaceSelectionFactory as Je, deleteCustomRangeFactory as Qe, SetTextSelectionsOperation as Xe, DocSkeletonManagerService as en, DocInterceptorService as nn, DOC_INTERCEPTOR_POINT as tn } from "@univerjs/docs";
7
+ import { addCustomRangeBySelectionFactory as qe, DocSelectionManagerService as M, replaceSelectionFactory as Je, deleteCustomRangeFactory as Qe, SetTextSelectionsOperation as Xe, DocSkeletonManagerService as en, DocInterceptorService as nn, DOC_INTERCEPTOR_POINT as tn } from "@univerjs/docs";
8
8
  import { DocCanvasPopManagerService as rn, DocEventManagerService as on, DocRenderController as sn, whenDocAndEditorFocused as cn } from "@univerjs/docs-ui";
9
- import { BehaviorSubject as he, distinctUntilChanged as dn, pairwise as an, Observable as ln, debounceTime as un } from "rxjs";
10
- import { jsxs as P, jsx as f } from "react/jsx-runtime";
9
+ import { BehaviorSubject as fe, distinctUntilChanged as dn, pairwise as an, Observable as ln, debounceTime as un } from "rxjs";
10
+ import { jsxs as P, jsx as h } from "react/jsx-runtime";
11
11
  import { clsx as xe, FormLayout as ve, Input as me, Button as Ie, borderClassName as ke, Tooltip as A, MessageType as pn } from "@univerjs/design";
12
- import { useDependency as S, useObservable as Le, KeyCode as X, IMessageService as gn, MetaKeys as fn, getMenuHiddenObservable as hn, MenuItemType as vn, ContextMenuPosition as mn, ContextMenuGroup as In, RibbonInsertGroup as _n, ComponentManager as Cn, IMenuManagerService as Sn, IShortcutService as yn } from "@univerjs/ui";
13
- import { useState as W, useEffect as xn, forwardRef as N, useRef as kn, createElement as U } from "react";
12
+ import { useDependency as S, useObservable as Le, KeyCode as X, IMessageService as gn, MetaKeys as hn, getMenuHiddenObservable as fn, MenuItemType as vn, ContextMenuPosition as mn, ContextMenuGroup as In, RibbonInsertGroup as _n, ComponentManager as Cn, IMenuManagerService as Sn, IShortcutService as yn } from "@univerjs/ui";
13
+ import { useState as z, useEffect as xn, forwardRef as N, useRef as kn, createElement as U } from "react";
14
14
  const Ln = "docs-hyper-link-ui.config", _e = {}, Oe = {
15
15
  type: R.COMMAND,
16
16
  id: "docs.command.add-hyper-link",
@@ -38,10 +38,10 @@ const Ln = "docs-hyper-link-ui.config", _e = {}, Oe = {
38
38
  var p;
39
39
  if (!e)
40
40
  return !1;
41
- const { unitId: t, payload: i, segmentId: r, linkId: o } = e, s = n.get(k), c = n.get(L), u = n.get(w).getActiveTextRange(), h = c.getUnit(t, _.UNIVER_DOC);
42
- if (!u || !h)
41
+ const { unitId: t, payload: i, segmentId: r, linkId: o } = e, s = n.get(k), c = n.get(L), u = n.get(M).getActiveTextRange(), f = c.getUnit(t, _.UNIVER_DOC);
42
+ if (!u || !f)
43
43
  return !1;
44
- const g = (p = Se(h.getSelfOrHeaderFooterModel(r).getBody(), u.startOffset, u.endOffset).textRuns) == null ? void 0 : p[0];
44
+ const g = (p = Se(f.getSelfOrHeaderFooterModel(r).getBody(), u.startOffset, u.endOffset).textRuns) == null ? void 0 : p[0];
45
45
  g && (g.ed = e.label.length + 1);
46
46
  const d = Je(n, {
47
47
  unitId: t,
@@ -78,18 +78,18 @@ function bn(n) {
78
78
  return On(n) ? n : Pn(n) ? `mailto://${n}` : `https://${n}`;
79
79
  }
80
80
  const F = () => {
81
- const n = S(y), e = S(ye), t = Le(n.editingLink$), i = S(k), r = S(L), o = S(w), [s, c] = W(""), [l, u] = W(""), [h, v] = W(!1), g = Ae.isLegalUrl(s), d = t ? r.getUnit(t.unitId, _.UNIVER_DOC) : r.getCurrentUnitForType(_.UNIVER_DOC);
81
+ const n = S(y), e = S(ye), t = Le(n.editingLink$), i = S(k), r = S(L), o = S(M), [s, c] = z(""), [l, u] = z(""), [f, v] = z(!1), g = Ae.isLegalUrl(s), d = t ? r.getUnit(t.unitId, _.UNIVER_DOC) : r.getCurrentUnitForType(_.UNIVER_DOC);
82
82
  xn(() => {
83
83
  var oe, se, ce, de, ae, le, ue, pe, ge;
84
84
  const a = o.getActiveTextRange();
85
85
  if (!a)
86
86
  return;
87
87
  if (t) {
88
- const H = (oe = d == null ? void 0 : d.getSelfOrHeaderFooterModel(t.segmentId)) == null ? void 0 : oe.getBody(), j = (se = H == null ? void 0 : H.customRanges) == null ? void 0 : se.find((z) => (t == null ? void 0 : t.linkId) === z.rangeId && z.startIndex === t.startIndex && z.endIndex === t.endIndex);
89
- d && j && (c((de = (ce = j.properties) == null ? void 0 : ce.url) != null ? de : ""), u(fe.transform.getPlainText(Se(H, j.startIndex, j.endIndex + 1).dataStream)));
88
+ const H = (oe = d == null ? void 0 : d.getSelfOrHeaderFooterModel(t.segmentId)) == null ? void 0 : oe.getBody(), j = (se = H == null ? void 0 : H.customRanges) == null ? void 0 : se.find((W) => (t == null ? void 0 : t.linkId) === W.rangeId && W.startIndex === t.startIndex && W.endIndex === t.endIndex);
89
+ d && j && (c((de = (ce = j.properties) == null ? void 0 : ce.url) != null ? de : ""), u(he.transform.getPlainText(Se(H, j.startIndex, j.endIndex + 1).dataStream)));
90
90
  return;
91
91
  }
92
- const x = (ae = d == null ? void 0 : d.getSelfOrHeaderFooterModel(a.segmentId)) == null ? void 0 : ae.getBody(), re = x ? a : null, T = re && ((ue = fe.customRange.getCustomRangesInterestsWithSelection(re, (le = x == null ? void 0 : x.customRanges) != null ? le : [])) == null ? void 0 : ue[0]);
92
+ const x = (ae = d == null ? void 0 : d.getSelfOrHeaderFooterModel(a.segmentId)) == null ? void 0 : ae.getBody(), re = x ? a : null, T = re && ((ue = he.customRange.getCustomRangesInterestsWithSelection(re, (le = x == null ? void 0 : x.customRanges) != null ? le : [])) == null ? void 0 : ue[0]);
93
93
  d && T && c((ge = (pe = T == null ? void 0 : T.properties) == null ? void 0 : pe.url) != null ? ge : "");
94
94
  }, [d, t, o, r]);
95
95
  const p = () => {
@@ -123,12 +123,12 @@ const F = () => {
123
123
  className: xe("univer-box-border univer-w-[328px] univer-rounded-xl univer-bg-white univer-px-6 univer-py-5 univer-shadow dark:!univer-bg-gray-900", ke),
124
124
  children: [
125
125
  /* @__PURE__ */ P("div", { children: [
126
- t ? /* @__PURE__ */ f(
126
+ t ? /* @__PURE__ */ h(
127
127
  ve,
128
128
  {
129
129
  label: e.t("docLink.edit.label"),
130
- error: h && !l ? e.t("docLink.edit.labelError") : "",
131
- children: /* @__PURE__ */ f(
130
+ error: f && !l ? e.t("docLink.edit.labelError") : "",
131
+ children: /* @__PURE__ */ h(
132
132
  me,
133
133
  {
134
134
  value: l,
@@ -141,12 +141,12 @@ const F = () => {
141
141
  )
142
142
  }
143
143
  ) : null,
144
- /* @__PURE__ */ f(
144
+ /* @__PURE__ */ h(
145
145
  ve,
146
146
  {
147
147
  label: e.t("docLink.edit.address"),
148
- error: h && !g ? e.t("docLink.edit.addressError") : "",
149
- children: /* @__PURE__ */ f(
148
+ error: f && !g ? e.t("docLink.edit.addressError") : "",
149
+ children: /* @__PURE__ */ h(
150
150
  me,
151
151
  {
152
152
  value: s,
@@ -161,8 +161,8 @@ const F = () => {
161
161
  )
162
162
  ] }),
163
163
  /* @__PURE__ */ P("div", { className: "univer-flex univer-justify-end univer-gap-3", children: [
164
- /* @__PURE__ */ f(Ie, { onClick: p, children: e.t("docLink.edit.cancel") }),
165
- /* @__PURE__ */ f(
164
+ /* @__PURE__ */ h(Ie, { onClick: p, children: e.t("docLink.edit.cancel") }),
165
+ /* @__PURE__ */ h(
166
166
  Ie,
167
167
  {
168
168
  variant: "primary",
@@ -197,11 +197,11 @@ var m = function() {
197
197
  return be(t, "".concat(i), { defIds: t.defIds, idSuffix: l.current }, m({ ref: e, className: c }, s), o);
198
198
  });
199
199
  function be(n, e, t, i, r) {
200
- return U(n.tag, m(m({ key: e }, wn(n, t, r)), i), (Mn(n, t).children || []).map(function(o, s) {
200
+ return U(n.tag, m(m({ key: e }, Mn(n, t, r)), i), (wn(n, t).children || []).map(function(o, s) {
201
201
  return be(o, "".concat(e, "-").concat(n.tag, "-").concat(s), t, void 0, r);
202
202
  }));
203
203
  }
204
- function wn(n, e, t) {
204
+ function Mn(n, e, t) {
205
205
  var i = m({}, n.attrs);
206
206
  t != null && t.colorChannel1 && i.fill === "colorChannel1" && (i.fill = t.colorChannel1), n.tag === "mask" && i.id && (i.id = i.id + e.idSuffix), Object.entries(i).forEach(function(o) {
207
207
  var s = o[0], c = o[1];
@@ -213,7 +213,7 @@ function wn(n, e, t) {
213
213
  typeof c == "string" && (i[s] = c.replace(/url\(#(.*)\)/, "url(#$1".concat(e.idSuffix, ")")));
214
214
  })), i;
215
215
  }
216
- function Mn(n, e) {
216
+ function wn(n, e) {
217
217
  var t, i = e.defIds;
218
218
  return !i || i.length === 0 ? n : n.tag === "defs" && (!((t = n.children) === null || t === void 0) && t.length) ? m(m({}, n), { children: n.children.map(function(r) {
219
219
  return typeof r.attrs.id == "string" && i && i.indexOf(r.attrs.id) > -1 ? m(m({}, r), { attrs: m(m({}, r.attrs), { id: r.attrs.id + e.idSuffix }) }) : r;
@@ -239,22 +239,22 @@ var Nn = { tag: "svg", attrs: { fill: "none", viewBox: "0 0 16 16", width: "1em"
239
239
  }));
240
240
  });
241
241
  ie.displayName = "LinkSingle";
242
- var Un = { 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" } }] }, we = N(function(n, e) {
242
+ var Un = { 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" } }] }, Me = N(function(n, e) {
243
243
  return U($, Object.assign({}, n, {
244
244
  id: "unlink-single",
245
245
  ref: e,
246
246
  icon: Un
247
247
  }));
248
248
  });
249
- we.displayName = "UnlinkSingle";
250
- var $n = { 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" } }] }, Me = N(function(n, e) {
249
+ Me.displayName = "UnlinkSingle";
250
+ var $n = { 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" } }] }, we = N(function(n, e) {
251
251
  return U($, Object.assign({}, n, {
252
252
  id: "write-single",
253
253
  ref: e,
254
254
  icon: $n
255
255
  }));
256
256
  });
257
- Me.displayName = "WriteSingle";
257
+ we.displayName = "WriteSingle";
258
258
  const De = {
259
259
  type: R.COMMAND,
260
260
  id: "docs.command.delete-hyper-link",
@@ -265,7 +265,7 @@ const De = {
265
265
  return s ? await o.syncExecuteCommand(s.id, s.params) : !1;
266
266
  }
267
267
  }, Ee = (n) => {
268
- const e = n.get(w), t = n.get(L), i = e.getTextRanges();
268
+ const e = n.get(M), t = n.get(L), i = e.getTextRanges();
269
269
  if (!(i != null && i.length))
270
270
  return !0;
271
271
  const r = i[0];
@@ -292,10 +292,10 @@ const De = {
292
292
  type: R.OPERATION,
293
293
  id: "doc.operation.click-hyper-link",
294
294
  handler(n, e) {
295
- var u, h, v;
295
+ var u, f, v;
296
296
  if (!e)
297
297
  return !1;
298
- const { unitId: t, linkId: i, segmentId: r } = e, s = n.get(L).getUnit(t, _.UNIVER_DOC), c = s == null ? void 0 : s.getSelfOrHeaderFooterModel(r).getBody(), l = (v = (h = (u = c == null ? void 0 : c.customRanges) == null ? void 0 : u.find((g) => g.rangeId === i && g.rangeType === D.HYPERLINK)) == null ? void 0 : h.properties) == null ? void 0 : v.url;
298
+ const { unitId: t, linkId: i, segmentId: r } = e, s = n.get(L).getUnit(t, _.UNIVER_DOC), c = s == null ? void 0 : s.getSelfOrHeaderFooterModel(r).getBody(), l = (v = (f = (u = c == null ? void 0 : c.customRanges) == null ? void 0 : u.find((g) => g.rangeId === i && g.rangeType === D.HYPERLINK)) == null ? void 0 : f.properties) == null ? void 0 : v.url;
299
299
  return l && window.open(l, "_blank", "noopener noreferrer"), !0;
300
300
  }
301
301
  }, B = () => {
@@ -303,7 +303,7 @@ const De = {
303
303
  const n = S(y), e = S(k), t = S(gn), i = S(ye), r = Le(n.showingLink$), o = S(L);
304
304
  if (!r)
305
305
  return null;
306
- const { unitId: s, linkId: c, segmentId: l, startIndex: u, endIndex: h } = r, v = o.getUnit(s, _.UNIVER_DOC), g = v == null ? void 0 : v.getSelfOrHeaderFooterModel(l).getBody(), d = (C = g == null ? void 0 : g.customRanges) == null ? void 0 : C.find((x) => x.rangeId === c && x.rangeType === D.HYPERLINK && x.startIndex === u && x.endIndex === h);
306
+ const { unitId: s, linkId: c, segmentId: l, startIndex: u, endIndex: f } = r, v = o.getUnit(s, _.UNIVER_DOC), g = v == null ? void 0 : v.getSelfOrHeaderFooterModel(l).getBody(), d = (C = g == null ? void 0 : g.customRanges) == null ? void 0 : C.find((x) => x.rangeId === c && x.rangeType === D.HYPERLINK && x.startIndex === u && x.endIndex === f);
307
307
  if (!d)
308
308
  return null;
309
309
  const p = (a = d.properties) == null ? void 0 : a.url;
@@ -321,19 +321,19 @@ const De = {
321
321
  className: "univer-flex univer-h-6 univer-flex-1 univer-cursor-pointer univer-items-center univer-truncate univer-text-sm univer-leading-5 univer-text-primary-500",
322
322
  onClick: () => window.open(p, void 0, "noopener noreferrer"),
323
323
  children: [
324
- /* @__PURE__ */ f(
324
+ /* @__PURE__ */ h(
325
325
  "div",
326
326
  {
327
327
  className: "univer-mr-2 univer-flex univer-size-5 univer-flex-[0_0_auto] univer-items-center univer-justify-center univer-text-base univer-text-gray-900 dark:!univer-text-white",
328
- children: /* @__PURE__ */ f(ie, {})
328
+ children: /* @__PURE__ */ h(ie, {})
329
329
  }
330
330
  ),
331
- /* @__PURE__ */ f(A, { showIfEllipsis: !0, title: p, children: /* @__PURE__ */ f("span", { className: "univer-flex-1 univer-truncate", children: p }) })
331
+ /* @__PURE__ */ h(A, { showIfEllipsis: !0, title: p, children: /* @__PURE__ */ h("span", { className: "univer-flex-1 univer-truncate", children: p }) })
332
332
  ]
333
333
  }
334
334
  ),
335
335
  /* @__PURE__ */ P("div", { className: "univer-flex univer-h-6 univer-flex-[0_0_auto] univer-items-center univer-justify-center", children: [
336
- /* @__PURE__ */ f(
336
+ /* @__PURE__ */ h(
337
337
  "div",
338
338
  {
339
339
  className: "univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",
@@ -343,10 +343,10 @@ const De = {
343
343
  type: pn.Info
344
344
  });
345
345
  },
346
- children: /* @__PURE__ */ f(A, { placement: "bottom", title: i.t("docLink.info.copy"), children: /* @__PURE__ */ f(Re, {}) })
346
+ children: /* @__PURE__ */ h(A, { placement: "bottom", title: i.t("docLink.info.copy"), children: /* @__PURE__ */ h(Re, {}) })
347
347
  }
348
348
  ),
349
- /* @__PURE__ */ f(
349
+ /* @__PURE__ */ h(
350
350
  "div",
351
351
  {
352
352
  className: "univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",
@@ -355,10 +355,10 @@ const De = {
355
355
  link: r
356
356
  });
357
357
  },
358
- children: /* @__PURE__ */ f(A, { placement: "bottom", title: i.t("docLink.info.edit"), children: /* @__PURE__ */ f(Me, {}) })
358
+ children: /* @__PURE__ */ h(A, { placement: "bottom", title: i.t("docLink.info.edit"), children: /* @__PURE__ */ h(we, {}) })
359
359
  }
360
360
  ),
361
- /* @__PURE__ */ f(
361
+ /* @__PURE__ */ h(
362
362
  "div",
363
363
  {
364
364
  className: "univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",
@@ -369,7 +369,7 @@ const De = {
369
369
  segmentId: l
370
370
  });
371
371
  },
372
- children: /* @__PURE__ */ f(A, { placement: "bottom", title: i.t("docLink.info.cancel"), children: /* @__PURE__ */ f(we, {}) })
372
+ children: /* @__PURE__ */ h(A, { placement: "bottom", title: i.t("docLink.info.cancel"), children: /* @__PURE__ */ h(Me, {}) })
373
373
  }
374
374
  )
375
375
  ] })
@@ -386,8 +386,8 @@ var Tn = Object.getOwnPropertyDescriptor, Hn = (n, e, t, i) => {
386
386
  let y = class extends E {
387
387
  constructor(e, t, i) {
388
388
  super();
389
- O(this, "_editingLink$", new he(null));
390
- O(this, "_showingLink$", new he(null));
389
+ O(this, "_editingLink$", new fe(null));
390
+ O(this, "_showingLink$", new fe(null));
391
391
  O(this, "editingLink$", this._editingLink$.asObservable());
392
392
  O(this, "showingLink$", this._showingLink$.asObservable());
393
393
  O(this, "_editPopup", null);
@@ -433,9 +433,9 @@ let y = class extends E {
433
433
  this._editingLink$.next(null), (e = this._editPopup) == null || e.dispose();
434
434
  }
435
435
  showInfoPopup(e) {
436
- var u, h, v, g, d, p;
436
+ var u, f, v, g, d, p;
437
437
  const { linkId: t, unitId: i, segmentId: r, segmentPage: o, startIndex: s, endIndex: c } = e;
438
- if (!(((u = this.showing) == null ? void 0 : u.linkId) === t && ((h = this.showing) == null ? void 0 : h.unitId) === i && ((v = this.showing) == null ? void 0 : v.segmentId) === r && ((g = this.showing) == null ? void 0 : g.segmentPage) === o && ((d = this.showing) == null ? void 0 : d.startIndex) === s && ((p = this.showing) == null ? void 0 : p.endIndex) === c || (this._infoPopup && this._infoPopup.dispose(), !this._univerInstanceService.getUnit(i, _.UNIVER_DOC))))
438
+ if (!(((u = this.showing) == null ? void 0 : u.linkId) === t && ((f = this.showing) == null ? void 0 : f.unitId) === i && ((v = this.showing) == null ? void 0 : v.segmentId) === r && ((g = this.showing) == null ? void 0 : g.segmentPage) === o && ((d = this.showing) == null ? void 0 : d.startIndex) === s && ((p = this.showing) == null ? void 0 : p.endIndex) === c || (this._infoPopup && this._infoPopup.dispose(), !this._univerInstanceService.getUnit(i, _.UNIVER_DOC))))
439
439
  return this._showingLink$.next({ unitId: i, linkId: t, segmentId: r, segmentPage: o, startIndex: s, endIndex: c }), this._infoPopup = this._docCanvasPopupManagerService.attachPopupToRange(
440
440
  {
441
441
  collapsed: !1,
@@ -462,7 +462,7 @@ let y = class extends E {
462
462
  };
463
463
  y = Hn([
464
464
  G(0, I(rn)),
465
- G(1, I(w)),
465
+ G(1, I(M)),
466
466
  G(2, L)
467
467
  ], y);
468
468
  var jn = Object.getOwnPropertyDescriptor, An = (n, e, t, i) => {
@@ -481,15 +481,15 @@ let V = class extends E {
481
481
  if (n.id === Xe.id) {
482
482
  const r = n.params, { unitId: o, ranges: s, segmentId: c } = r, l = this._univerInstanceService.getUnit(o, _.UNIVER_DOC), u = s[0];
483
483
  if (u && l) {
484
- const { startOffset: h, endOffset: v, collapsed: g, segmentPage: d } = u, p = (t = (e = l.getSelfOrHeaderFooterModel(c)) == null ? void 0 : e.getBody()) == null ? void 0 : t.customRanges;
484
+ const { startOffset: f, endOffset: v, collapsed: g, segmentPage: d } = u, p = (t = (e = l.getSelfOrHeaderFooterModel(c)) == null ? void 0 : e.getBody()) == null ? void 0 : t.customRanges;
485
485
  if (g) {
486
- const C = (i = p == null ? void 0 : p.findIndex((a) => a.startIndex < h && a.endIndex > v - 1)) != null ? i : -1;
486
+ const C = (i = p == null ? void 0 : p.findIndex((a) => a.startIndex < f && a.endIndex > v - 1)) != null ? i : -1;
487
487
  if (C > -1) {
488
488
  const a = p[C];
489
489
  this._docHyperLinkService.showInfoPopup({ unitId: o, linkId: a.rangeId, segmentId: c, segmentPage: d, startIndex: a.startIndex, endIndex: a.endIndex });
490
490
  return;
491
491
  }
492
- } else if (p == null ? void 0 : p.find((a) => a.startIndex <= h && a.endIndex >= v - 1))
492
+ } else if (p == null ? void 0 : p.find((a) => a.startIndex <= f && a.endIndex >= v - 1))
493
493
  return;
494
494
  }
495
495
  this._docHyperLinkService.hideInfoPopup(), this._docHyperLinkService.hideEditPopup();
@@ -507,7 +507,7 @@ var Kn = Object.getOwnPropertyDescriptor, Fn = (n, e, t, i) => {
507
507
  for (var r = i > 1 ? void 0 : i ? Kn(e, t) : e, o = n.length - 1, s; o >= 0; o--)
508
508
  (s = n[o]) && (r = s(r) || r);
509
509
  return r;
510
- }, M = (n, e) => (t, i) => e(t, i, n);
510
+ }, w = (n, e) => (t, i) => e(t, i, n);
511
511
  let ne = class extends E {
512
512
  constructor(n, e, t, i, r, o) {
513
513
  super(), this._context = n, this._docEventManagerService = e, this._commandService = t, this._hyperLinkPopupService = i, this._docSkeletonManagerService = r, this._docSelectionManagerService = o, !(this._context.unitId === Ke || this._context.unitId === Fe) && (this._initHover(), this._initClick());
@@ -561,11 +561,11 @@ let ne = class extends E {
561
561
  }
562
562
  };
563
563
  ne = Fn([
564
- M(1, I(on)),
565
- M(2, k),
566
- M(3, I(y)),
567
- M(4, I(en)),
568
- M(5, I(w))
564
+ w(1, I(on)),
565
+ w(2, k),
566
+ w(3, I(y)),
567
+ w(4, I(en)),
568
+ w(5, I(M))
569
569
  ], ne);
570
570
  var Bn = Object.getOwnPropertyDescriptor, Vn = (n, e, t, i) => {
571
571
  for (var r = i > 1 ? void 0 : i ? Bn(e, t) : e, o = n.length - 1, s; o >= 0; o--)
@@ -587,10 +587,10 @@ let te = class extends E {
587
587
  ...n,
588
588
  active: !1
589
589
  });
590
- const { linkId: s, unitId: c, startIndex: l, endIndex: u } = o, h = c === i && n.rangeId === s && r >= l && r <= u;
590
+ const { linkId: s, unitId: c, startIndex: l, endIndex: u } = o, f = c === i && n.rangeId === s && r >= l && r <= u;
591
591
  return t({
592
592
  ...n,
593
- active: h
593
+ active: f
594
594
  });
595
595
  }
596
596
  });
@@ -617,9 +617,9 @@ function Ce(n) {
617
617
  icon: Ue,
618
618
  title: "docLink.menu.tooltip",
619
619
  tooltip: "docLink.menu.tooltip",
620
- hidden$: hn(n, _.UNIVER_DOC),
620
+ hidden$: fn(n, _.UNIVER_DOC),
621
621
  disabled$: new ln(function(e) {
622
- const i = n.get(w).textSelection$.pipe(un(16)).subscribe(() => {
622
+ const i = n.get(M).textSelection$.pipe(un(16)).subscribe(() => {
623
623
  e.next(Ee(n));
624
624
  });
625
625
  return () => {
@@ -630,7 +630,7 @@ function Ce(n) {
630
630
  }
631
631
  const Yn = {
632
632
  id: b.id,
633
- binding: fn.CTRL_COMMAND | X.K,
633
+ binding: hn.CTRL_COMMAND | X.K,
634
634
  description: "docLink.menu.tooltip",
635
635
  preconditions: cn
636
636
  }, Zn = {
@@ -649,8 +649,8 @@ const Yn = {
649
649
  }
650
650
  }
651
651
  };
652
- var zn = Object.getOwnPropertyDescriptor, Wn = (n, e, t, i) => {
653
- for (var r = i > 1 ? void 0 : i ? zn(e, t) : e, o = n.length - 1, s; o >= 0; o--)
652
+ var Wn = Object.getOwnPropertyDescriptor, zn = (n, e, t, i) => {
653
+ for (var r = i > 1 ? void 0 : i ? Wn(e, t) : e, o = n.length - 1, s; o >= 0; o--)
654
654
  (s = n[o]) && (r = s(r) || r);
655
655
  return r;
656
656
  }, K = (n, e) => (t, i) => e(t, i, n);
@@ -664,7 +664,9 @@ let Y = class extends E {
664
664
  [B, B.componentKey],
665
665
  [ie, Ue]
666
666
  ].forEach(([n, e]) => {
667
- this._componentManager.register(e, n);
667
+ this.disposeWithMe(
668
+ this._componentManager.register(e, n)
669
+ );
668
670
  });
669
671
  }
670
672
  _initCommands() {
@@ -688,7 +690,7 @@ let Y = class extends E {
688
690
  this._menuManagerService.mergeMenu(Zn);
689
691
  }
690
692
  };
691
- Y = Wn([
693
+ Y = zn([
692
694
  K(0, I(Cn)),
693
695
  K(1, k),
694
696
  K(2, Sn),
@@ -703,7 +705,7 @@ var qn = Object.defineProperty, Jn = Object.getOwnPropertyDescriptor, Qn = (n, e
703
705
  let Z = class extends Ze {
704
706
  constructor(n = _e, e, t, i) {
705
707
  super(), this._config = n, this._injector = e, this._renderManagerSrv = t, this._configService = i;
706
- const { menu: r, ...o } = ze(
708
+ const { menu: r, ...o } = We(
707
709
  {},
708
710
  _e,
709
711
  this._config
@@ -737,7 +739,7 @@ let Z = class extends Ze {
737
739
  $e(Z, "pluginName", Gn);
738
740
  $e(Z, "type", _.UNIVER_DOC);
739
741
  Z = Xn([
740
- Be(We),
742
+ Be(ze),
741
743
  Q(1, I(Ve)),
742
744
  Q(2, Ge),
743
745
  Q(3, Ye)
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(a,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/docs-hyper-link"),require("@univerjs/engine-render"),require("@univerjs/docs"),require("@univerjs/docs-ui"),require("rxjs"),require("react/jsx-runtime"),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","react/jsx-runtime","@univerjs/design","@univerjs/ui","react"],o):(a=typeof globalThis<"u"?globalThis:a||self,o(a.UniverDocsHyperLinkUi={},a.UniverCore,a.UniverDocsHyperLink,a.UniverEngineRender,a.UniverDocs,a.UniverDocsUi,a.rxjs,a.React,a.UniverDesign,a.UniverUi,a.React))})(this,function(a,o,P,Ce,S,E,U,u,_,v,C){"use strict";var Ge=Object.defineProperty;var Je=(a,o,P)=>o in a?Ge(a,o,{enumerable:!0,configurable:!0,writable:!0,value:P}):a[o]=P;var D=(a,o,P)=>Je(a,typeof o!="symbol"?o+"":o,P);const ye="docs-hyper-link-ui.config",J={},Q={type:o.CommandType.COMMAND,id:"docs.command.add-hyper-link",async handler(n,e){if(!e)return!1;const{payload:t,unitId:i,selections:r}=e,s=n.get(o.ICommandService),c=o.generateRandomId(),d=S.addCustomRangeBySelectionFactory(n,{rangeId:c,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:t},unitId:i,selections:r});return d?s.syncExecuteCommand(d.id,d.params):!1}},X={id:"docs.command.update-hyper-link",type:o.CommandType.COMMAND,handler(n,e){var h;if(!e)return!1;const{unitId:t,payload:i,segmentId:r,linkId:s}=e,c=n.get(o.ICommandService),d=n.get(o.IUniverInstanceService),f=n.get(S.DocSelectionManagerService).getActiveTextRange(),m=d.getUnit(t,o.UniverInstanceType.UNIVER_DOC);if(!f||!m)return!1;const I=(h=o.getBodySlice(m.getSelfOrHeaderFooterModel(r).getBody(),f.startOffset,f.endOffset).textRuns)==null?void 0:h[0];I&&(I.ed=e.label.length+1);const l=S.replaceSelectionFactory(n,{unitId:t,body:{dataStream:`${e.label}`,customRanges:[{rangeId:s,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:e.label.length+1,properties:{url:i}}],textRuns:I?[I]:void 0},selection:{startOffset:f.startOffset,endOffset:f.endOffset,collapsed:!1,segmentId:r}});return l?c.syncExecuteCommand(l.id,l.params):!1}};function Se(n){return/^[a-zA-Z]+:\/\//.test(n)}function xe(n){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(n)}function ke(n){return Se(n)?n:xe(n)?`mailto://${n}`:`https://${n}`}const T=()=>{const n=v.useDependency(k),e=v.useDependency(o.LocaleService),t=v.useObservable(n.editingLink$),i=v.useDependency(o.ICommandService),r=v.useDependency(o.IUniverInstanceService),s=v.useDependency(S.DocSelectionManagerService),[c,d]=C.useState(""),[g,f]=C.useState(""),[m,y]=C.useState(!1),I=o.Tools.isLegalUrl(c),l=t?r.getUnit(t.unitId,o.UniverInstanceType.UNIVER_DOC):r.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC);C.useEffect(()=>{var ue,ve,pe,ge,fe,he,Ie,me,_e;const p=s.getActiveTextRange();if(!p)return;if(t){const K=(ue=l==null?void 0:l.getSelfOrHeaderFooterModel(t.segmentId))==null?void 0:ue.getBody(),A=(ve=K==null?void 0:K.customRanges)==null?void 0:ve.find(G=>(t==null?void 0:t.linkId)===G.rangeId&&G.startIndex===t.startIndex&&G.endIndex===t.endIndex);l&&A&&(d((ge=(pe=A.properties)==null?void 0:pe.url)!=null?ge:""),f(o.BuildTextUtils.transform.getPlainText(o.getBodySlice(K,A.startIndex,A.endIndex+1).dataStream)));return}const O=(fe=l==null?void 0:l.getSelfOrHeaderFooterModel(p.segmentId))==null?void 0:fe.getBody(),le=O?p:null,$=le&&((Ie=o.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(le,(he=O==null?void 0:O.customRanges)!=null?he:[]))==null?void 0:Ie[0]);l&&$&&d((_e=(me=$==null?void 0:$.properties)==null?void 0:me.url)!=null?_e:"")},[l,t,s,r]);const h=()=>{n.hideEditPopup()},L=()=>{if(y(!0),!I||!l)return;const p=ke(c);if(!t)i.executeCommand(Q.id,{unitId:l.getUnitId(),payload:p});else{if(!g)return;i.executeCommand(X.id,{unitId:l.getUnitId(),payload:p,linkId:t.linkId,label:g,segmentId:t.segmentId})}n.hideEditPopup()};if(l)return u.jsxs("div",{className:_.clsx("univer-box-border univer-w-[328px] univer-rounded-xl univer-bg-white univer-px-6 univer-py-5 univer-shadow dark:!univer-bg-gray-900",_.borderClassName),children:[u.jsxs("div",{children:[t?u.jsx(_.FormLayout,{label:e.t("docLink.edit.label"),error:m&&!g?e.t("docLink.edit.labelError"):"",children:u.jsx(_.Input,{value:g,onChange:f,autoFocus:!0,onKeyDown:p=>{p.keyCode===v.KeyCode.ENTER&&L()}})}):null,u.jsx(_.FormLayout,{label:e.t("docLink.edit.address"),error:m&&!I?e.t("docLink.edit.addressError"):"",children:u.jsx(_.Input,{value:c,onChange:d,autoFocus:!0,onKeyDown:p=>{p.keyCode===v.KeyCode.ENTER&&L()}})})]}),u.jsxs("div",{className:"univer-flex univer-justify-end univer-gap-3",children:[u.jsx(_.Button,{onClick:h,children:e.t("docLink.edit.cancel")}),u.jsx(_.Button,{variant:"primary",disabled:!c,onClick:L,children:e.t("docLink.edit.confirm")})]})]})};T.componentKey="docs-hyper-link-edit";var x=function(){return x=Object.assign||function(n){for(var e,t=1,i=arguments.length;t<i;t++){e=arguments[t];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r])}return n},x.apply(this,arguments)},Le=function(n,e){var t={};for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&e.indexOf(i)<0&&(t[i]=n[i]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,i=Object.getOwnPropertySymbols(n);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(n,i[r])&&(t[i[r]]=n[i[r]]);return t},w=C.forwardRef(function(n,e){var t=n.icon,i=n.id,r=n.className,s=n.extend,c=Le(n,["icon","id","className","extend"]),d="univerjs-icon univerjs-icon-".concat(i," ").concat(r||"").trim(),g=C.useRef("_".concat(Pe()));return ee(t,"".concat(i),{defIds:t.defIds,idSuffix:g.current},x({ref:e,className:d},c),s)});function ee(n,e,t,i,r){return C.createElement(n.tag,x(x({key:e},Oe(n,t,r)),i),(De(n,t).children||[]).map(function(s,c){return ee(s,"".concat(e,"-").concat(n.tag,"-").concat(c),t,void 0,r)}))}function Oe(n,e,t){var i=x({},n.attrs);t!=null&&t.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=t.colorChannel1),n.tag==="mask"&&i.id&&(i.id=i.id+e.idSuffix),Object.entries(i).forEach(function(s){var c=s[0],d=s[1];c==="mask"&&typeof d=="string"&&(i[c]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))});var r=e.defIds;return!r||r.length===0||(n.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+e.idSuffix),Object.entries(i).forEach(function(s){var c=s[0],d=s[1];typeof d=="string"&&(i[c]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),i}function De(n,e){var t,i=e.defIds;return!i||i.length===0?n:n.tag==="defs"&&(!((t=n.children)===null||t===void 0)&&t.length)?x(x({},n),{children:n.children.map(function(r){return typeof r.attrs.id=="string"&&i&&i.indexOf(r.attrs.id)>-1?x(x({},r),{attrs:x(x({},r.attrs),{id:r.attrs.id+e.idSuffix})}):r})}):n}function Pe(){return Math.random().toString(36).substring(2,8)}w.displayName="UniverIcon";var Ue={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"}}]},ne=C.forwardRef(function(n,e){return C.createElement(w,Object.assign({},n,{id:"copy-single",ref:e,icon:Ue}))});ne.displayName="CopySingle";var Me={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M9.8816 1.97978C11.0177 0.843607 12.862 0.884962 14.0004 2.02342C15.1389 3.16188 15.1803 5.00612 14.0441 6.14228L11.399 8.78737C11.1608 9.02559 10.7746 9.02559 10.5363 8.78737C10.2981 8.54915 10.2981 8.16292 10.5363 7.9247L13.1814 5.2796C13.8195 4.64155 13.8217 3.57006 13.1378 2.8861C12.4538 2.20211 11.3823 2.20438 10.7443 2.84245L7.6976 5.88911L7.69317 5.89349C7.05959 6.53211 7.05894 7.60014 7.74132 8.28252C7.97954 8.52074 7.97954 8.90697 7.74132 9.14519C7.5031 9.38341 7.11687 9.38341 6.87865 9.14519C5.74016 8.00671 5.69884 6.16251 6.83497 5.02633L6.84021 5.02116L9.8816 1.97978Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.61426 7.2364C4.85248 6.99818 5.23871 6.99818 5.47693 7.2364C5.71515 7.47462 5.71515 7.86085 5.47693 8.09907L2.83183 10.7442C2.19375 11.3823 2.1915 12.4537 2.87547 13.1377C3.55945 13.8217 4.6309 13.8194 5.26899 13.1813L8.31566 10.1347C8.32262 10.1277 8.32971 10.121 8.33691 10.1144C8.34408 10.1064 8.3515 10.0986 8.35916 10.091C8.99721 9.45291 8.99949 8.38145 8.3155 7.69746C8.07728 7.45924 8.07728 7.07301 8.3155 6.83479C8.55372 6.59657 8.93995 6.59657 9.17817 6.83479C10.3166 7.97327 10.358 9.81748 9.22183 10.9536C9.21487 10.9606 9.20779 10.9673 9.20058 10.9739C9.19341 10.9819 9.18599 10.9897 9.17833 10.9973L6.13166 14.044C4.99548 15.1802 3.15127 15.1389 2.01279 14.0004C0.874362 12.8619 0.83297 11.0177 1.96916 9.8815L4.61426 7.2364Z"}}]},B=C.forwardRef(function(n,e){return C.createElement(w,Object.assign({},n,{id:"link-single",ref:e,icon:Me}))});B.displayName="LinkSingle";var we={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"}}]},te=C.forwardRef(function(n,e){return C.createElement(w,Object.assign({},n,{id:"unlink-single",ref:e,icon:we}))});te.displayName="UnlinkSingle";var be={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"}}]},ie=C.forwardRef(function(n,e){return C.createElement(w,Object.assign({},n,{id:"write-single",ref:e,icon:be}))});ie.displayName="WriteSingle";const re={type:o.CommandType.COMMAND,id:"docs.command.delete-hyper-link",async handler(n,e){if(!e)return!1;const{unitId:t,linkId:i,segmentId:r}=e,s=n.get(o.ICommandService),c=S.deleteCustomRangeFactory(n,{unitId:t,rangeId:i,segmentId:r});return c?await s.syncExecuteCommand(c.id,c.params):!1}},oe=n=>{const e=n.get(S.DocSelectionManagerService),t=n.get(o.IUniverInstanceService),i=e.getTextRanges();if(!(i!=null&&i.length))return!0;const r=i[0];return!!(!t.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC)||!r||r.collapsed)},M={type:o.CommandType.OPERATION,id:"doc.operation.show-hyper-link-edit-popup",handler(n,e){var c;const t=e==null?void 0:e.link,i=n.get(o.IUniverInstanceService);if(oe(n)&&!t)return!1;const r=n.get(k),s=(t==null?void 0:t.unitId)||((c=i.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC))==null?void 0:c.getUnitId());return s?(r.showEditPopup(s,t),!0):!1}},F={type:o.CommandType.OPERATION,id:"doc.operation.toggle-hyper-link-info-popup",handler(n,e){const t=n.get(k);return e?(t.showInfoPopup(e),!0):(t.hideInfoPopup(),!0)}},se={type:o.CommandType.OPERATION,id:"doc.operation.click-hyper-link",handler(n,e){var f,m,y;if(!e)return!1;const{unitId:t,linkId:i,segmentId:r}=e,c=n.get(o.IUniverInstanceService).getUnit(t,o.UniverInstanceType.UNIVER_DOC),d=c==null?void 0:c.getSelfOrHeaderFooterModel(r).getBody(),g=(y=(m=(f=d==null?void 0:d.customRanges)==null?void 0:f.find(I=>I.rangeId===i&&I.rangeType===o.CustomRangeType.HYPERLINK))==null?void 0:m.properties)==null?void 0:y.url;return g&&window.open(g,"_blank","noopener noreferrer"),!0}},R=()=>{var L,p;const n=v.useDependency(k),e=v.useDependency(o.ICommandService),t=v.useDependency(v.IMessageService),i=v.useDependency(o.LocaleService),r=v.useObservable(n.showingLink$),s=v.useDependency(o.IUniverInstanceService);if(!r)return null;const{unitId:c,linkId:d,segmentId:g,startIndex:f,endIndex:m}=r,y=s.getUnit(c,o.UniverInstanceType.UNIVER_DOC),I=y==null?void 0:y.getSelfOrHeaderFooterModel(g).getBody(),l=(L=I==null?void 0:I.customRanges)==null?void 0:L.find(O=>O.rangeId===d&&O.rangeType===o.CustomRangeType.HYPERLINK&&O.startIndex===f&&O.endIndex===m);if(!l)return null;const h=(p=l.properties)==null?void 0:p.url;return u.jsxs("div",{className:_.clsx("univer-box-border univer-flex univer-max-w-80 univer-items-center univer-justify-between univer-overflow-hidden univer-rounded-lg univer-bg-white univer-p-3 univer-shadow dark:!univer-bg-gray-900",_.borderClassName),onClick:()=>{n.hideInfoPopup()},children:[u.jsxs("div",{className:"univer-flex univer-h-6 univer-flex-1 univer-cursor-pointer univer-items-center univer-truncate univer-text-sm univer-leading-5 univer-text-primary-500",onClick:()=>window.open(h,void 0,"noopener noreferrer"),children:[u.jsx("div",{className:"univer-mr-2 univer-flex univer-size-5 univer-flex-[0_0_auto] univer-items-center univer-justify-center univer-text-base univer-text-gray-900 dark:!univer-text-white",children:u.jsx(B,{})}),u.jsx(_.Tooltip,{showIfEllipsis:!0,title:h,children:u.jsx("span",{className:"univer-flex-1 univer-truncate",children:h})})]}),u.jsxs("div",{className:"univer-flex univer-h-6 univer-flex-[0_0_auto] univer-items-center univer-justify-center",children:[u.jsx("div",{className:"univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",onClick:()=>{navigator.clipboard.writeText(h),t.show({content:i.t("docLink.info.coped"),type:_.MessageType.Info})},children:u.jsx(_.Tooltip,{placement:"bottom",title:i.t("docLink.info.copy"),children:u.jsx(ne,{})})}),u.jsx("div",{className:"univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",onClick:()=>{e.executeCommand(M.id,{link:r})},children:u.jsx(_.Tooltip,{placement:"bottom",title:i.t("docLink.info.edit"),children:u.jsx(ie,{})})}),u.jsx("div",{className:"univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",onClick:()=>{e.executeCommand(re.id,{unitId:c,linkId:l.rangeId,segmentId:g})},children:u.jsx(_.Tooltip,{placement:"bottom",title:i.t("docLink.info.cancel"),children:u.jsx(te,{})})})]})]})};R.componentKey="univer.doc.link-info-popup";var Ee=Object.getOwnPropertyDescriptor,Te=(n,e,t,i)=>{for(var r=i>1?void 0:i?Ee(e,t):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(r=c(r)||r);return r},V=(n,e)=>(t,i)=>e(t,i,n);let k=class extends o.Disposable{constructor(e,t,i){super();D(this,"_editingLink$",new U.BehaviorSubject(null));D(this,"_showingLink$",new U.BehaviorSubject(null));D(this,"editingLink$",this._editingLink$.asObservable());D(this,"showingLink$",this._showingLink$.asObservable());D(this,"_editPopup",null);D(this,"_infoPopup",null);this._docCanvasPopupManagerService=e,this._textSelectionManagerService=t,this._univerInstanceService=i,this.disposeWithMe(()=>{this._editingLink$.complete(),this._showingLink$.complete()})}get editing(){return this._editingLink$.value}get showing(){return this._showingLink$.value}showEditPopup(e,t){this._editPopup&&this._editPopup.dispose(),this._editingLink$.next(t);const i=this._textSelectionManagerService.getTextRanges({unitId:e,subUnitId:e});let r=i==null?void 0:i[i.length-1];if(t){const{segmentId:s,segmentPage:c,startIndex:d,endIndex:g}=t;r={collapsed:!1,startOffset:d,endOffset:g+1,segmentId:s,segmentPage:c},this._textSelectionManagerService.replaceDocRanges([{startOffset:d,endOffset:g+1}])}return r?(this._editPopup=this._docCanvasPopupManagerService.attachPopupToRange(r,{componentKey:T.componentKey,direction:"bottom"},e),this._editPopup):null}hideEditPopup(){var e;this._editingLink$.next(null),(e=this._editPopup)==null||e.dispose()}showInfoPopup(e){var f,m,y,I,l,h;const{linkId:t,unitId:i,segmentId:r,segmentPage:s,startIndex:c,endIndex:d}=e;if(!(((f=this.showing)==null?void 0:f.linkId)===t&&((m=this.showing)==null?void 0:m.unitId)===i&&((y=this.showing)==null?void 0:y.segmentId)===r&&((I=this.showing)==null?void 0:I.segmentPage)===s&&((l=this.showing)==null?void 0:l.startIndex)===c&&((h=this.showing)==null?void 0:h.endIndex)===d||(this._infoPopup&&this._infoPopup.dispose(),!this._univerInstanceService.getUnit(i,o.UniverInstanceType.UNIVER_DOC))))return this._showingLink$.next({unitId:i,linkId:t,segmentId:r,segmentPage:s,startIndex:c,endIndex:d}),this._infoPopup=this._docCanvasPopupManagerService.attachPopupToRange({collapsed:!1,startOffset:c,endOffset:d+1,segmentId:r,segmentPage:s},{componentKey:R.componentKey,direction:"top-center",multipleDirection:"top",onClickOutside:()=>{this.hideInfoPopup()}},i),this._infoPopup}hideInfoPopup(){var e;this._showingLink$.next(null),(e=this._infoPopup)==null||e.dispose()}};k=Te([V(0,o.Inject(E.DocCanvasPopManagerService)),V(1,o.Inject(S.DocSelectionManagerService)),V(2,o.IUniverInstanceService)],k);var Re=Object.getOwnPropertyDescriptor,Ne=(n,e,t,i)=>{for(var r=i>1?void 0:i?Re(e,t):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(r=c(r)||r);return r},Y=(n,e)=>(t,i)=>e(t,i,n);let N=class extends o.Disposable{constructor(n,e,t){super(),this._commandService=n,this._univerInstanceService=e,this._docHyperLinkService=t,this._initSelectionChange()}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(n=>{var e,t,i;if(n.id===S.SetTextSelectionsOperation.id){const r=n.params,{unitId:s,ranges:c,segmentId:d}=r,g=this._univerInstanceService.getUnit(s,o.UniverInstanceType.UNIVER_DOC),f=c[0];if(f&&g){const{startOffset:m,endOffset:y,collapsed:I,segmentPage:l}=f,h=(t=(e=g.getSelfOrHeaderFooterModel(d))==null?void 0:e.getBody())==null?void 0:t.customRanges;if(I){const L=(i=h==null?void 0:h.findIndex(p=>p.startIndex<m&&p.endIndex>y-1))!=null?i:-1;if(L>-1){const p=h[L];this._docHyperLinkService.showInfoPopup({unitId:s,linkId:p.rangeId,segmentId:d,segmentPage:l,startIndex:p.startIndex,endIndex:p.endIndex});return}}else if(h==null?void 0:h.find(p=>p.startIndex<=m&&p.endIndex>=y-1))return}this._docHyperLinkService.hideInfoPopup(),this._docHyperLinkService.hideEditPopup()}}))}};N=Ne([Y(0,o.ICommandService),Y(1,o.IUniverInstanceService),Y(2,o.Inject(k))],N);var je=Object.getOwnPropertyDescriptor,He=(n,e,t,i)=>{for(var r=i>1?void 0:i?je(e,t):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(r=c(r)||r);return r},b=(n,e)=>(t,i)=>e(t,i,n);let q=class extends o.Disposable{constructor(n,e,t,i,r,s){super(),this._context=n,this._docEventManagerService=e,this._commandService=t,this._hyperLinkPopupService=i,this._docSkeletonManagerService=r,this._docSelectionManagerService=s,!(this._context.unitId===o.DOCS_ZEN_EDITOR_UNIT_ID_KEY||this._context.unitId===o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)&&(this._initHover(),this._initClick())}get _skeleton(){return this._docSkeletonManagerService.getSkeleton()}_hideInfoPopup(){this._hyperLinkPopupService.showing&&this._commandService.executeCommand(F.id)}_initHover(){this.disposeWithMe(this._docEventManagerService.hoverCustomRanges$.subscribe(n=>{var r;const e=n.find(s=>s.range.rangeType===o.CustomRangeType.HYPERLINK),t=this._docSelectionManagerService.getTextRanges(),i=t==null?void 0:t[0].segmentId;if(((r=e==null?void 0:e.segmentId)!=null?r:"")!==i){this._hideInfoPopup();return}e?this._commandService.executeCommand(F.id,{unitId:this._context.unitId,linkId:e.range.rangeId,segmentId:e.segmentId,segmentPage:e.segmentPageIndex,rangeId:e.range.rangeId,startIndex:e.range.startIndex,endIndex:e.range.endIndex}):this._hideInfoPopup()}))}_initClick(){this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe(n=>{const e=n.range;e&&this._commandService.executeCommand(se.id,{unitId:this._context.unitId,linkId:e.rangeId,segmentId:n.segmentId})}))}};q=He([b(1,o.Inject(E.DocEventManagerService)),b(2,o.ICommandService),b(3,o.Inject(k)),b(4,o.Inject(S.DocSkeletonManagerService)),b(5,o.Inject(S.DocSelectionManagerService))],q);var $e=Object.getOwnPropertyDescriptor,Ke=(n,e,t,i)=>{for(var r=i>1?void 0:i?$e(e,t):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(r=c(r)||r);return r},Z=(n,e)=>(t,i)=>e(t,i,n);let z=class extends o.Disposable{constructor(n,e,t,i){super(),this._context=n,this._docInterceptorService=e,this._hyperLinkService=t,this._docRenderController=i,this._init(),this._initReRender()}_init(){this._docInterceptorService.intercept(S.DOC_INTERCEPTOR_POINT.CUSTOM_RANGE,{handler:(n,e,t)=>{if(!n)return t(n);const{unitId:i,index:r}=e,s=this._hyperLinkService.showing;if(!s)return t({...n,active:!1});const{linkId:c,unitId:d,startIndex:g,endIndex:f}=s,m=d===i&&n.rangeId===c&&r>=g&&r<=f;return t({...n,active:m})}})}_initReRender(){this.disposeWithMe(this._hyperLinkService.showingLink$.pipe(U.distinctUntilChanged((n,e)=>(n==null?void 0:n.linkId)===(e==null?void 0:e.linkId)&&(n==null?void 0:n.unitId)===(e==null?void 0:e.unitId)&&(n==null?void 0:n.startIndex)===(e==null?void 0:e.startIndex)),U.pairwise()).subscribe(([n,e])=>{e?e.unitId===this._context.unitId&&this._docRenderController.reRender(e.unitId):n&&n.unitId===this._context.unitId&&this._docRenderController.reRender(n.unitId)}))}};z=Ke([Z(1,o.Inject(S.DocInterceptorService)),Z(2,o.Inject(k)),Z(3,o.Inject(E.DocRenderController))],z);const ce="doc-hyper-link-icon";function de(n){return{id:M.id,type:v.MenuItemType.BUTTON,icon:ce,title:"docLink.menu.tooltip",tooltip:"docLink.menu.tooltip",hidden$:v.getMenuHiddenObservable(n,o.UniverInstanceType.UNIVER_DOC),disabled$:new U.Observable(function(e){const i=n.get(S.DocSelectionManagerService).textSelection$.pipe(U.debounceTime(16)).subscribe(()=>{e.next(oe(n))});return()=>{i.unsubscribe()}})}}const Ae={id:M.id,binding:v.MetaKeys.CTRL_COMMAND|v.KeyCode.K,description:"docLink.menu.tooltip",preconditions:E.whenDocAndEditorFocused},Be={[v.RibbonInsertGroup.MEDIA]:{[M.id]:{order:1,menuItemFactory:de}},[v.ContextMenuPosition.MAIN_AREA]:{[v.ContextMenuGroup.DATA]:{[M.id]:{order:0,menuItemFactory:de}}}};var Fe=Object.getOwnPropertyDescriptor,Ve=(n,e,t,i)=>{for(var r=i>1?void 0:i?Fe(e,t):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(r=c(r)||r);return r},j=(n,e)=>(t,i)=>e(t,i,n);let H=class extends o.Disposable{constructor(n,e,t,i){super(),this._componentManager=n,this._commandService=e,this._menuManagerService=t,this._shortcutService=i,this._initComponents(),this._initCommands(),this._initMenus(),this._initShortcut()}_initComponents(){[[T,T.componentKey],[R,R.componentKey],[B,ce]].forEach(([n,e])=>{this._componentManager.register(e,n)})}_initCommands(){[Q,X,re,M,F,se].forEach(n=>{this._commandService.registerCommand(n)})}_initShortcut(){[Ae].forEach(n=>{this._shortcutService.registerShortcut(n)})}_initMenus(){this._menuManagerService.mergeMenu(Be)}};H=Ve([j(0,o.Inject(v.ComponentManager)),j(1,o.ICommandService),j(2,v.IMenuManagerService),j(3,v.IShortcutService)],H);const Ye="DOC_HYPER_LINK_UI_PLUGIN";var qe=Object.defineProperty,Ze=Object.getOwnPropertyDescriptor,ze=(n,e,t)=>e in n?qe(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,We=(n,e,t,i)=>{for(var r=i>1?void 0:i?Ze(e,t):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(r=c(r)||r);return r},W=(n,e)=>(t,i)=>e(t,i,n),ae=(n,e,t)=>ze(n,typeof e!="symbol"?e+"":e,t);a.UniverDocsHyperLinkUIPlugin=class extends o.Plugin{constructor(e=J,t,i,r){super(),this._config=e,this._injector=t,this._renderManagerSrv=i,this._configService=r;const{menu:s,...c}=o.merge({},J,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig(ye,c)}onStarting(){[[k],[H],[N]].forEach(t=>{this._injector.add(t)}),this._injector.get(H)}onReady(){this._injector.get(N)}onRendered(){this._initRenderModule()}_initRenderModule(){[[z],[q]].forEach(e=>{this._renderManagerSrv.registerRenderModule(o.UniverInstanceType.UNIVER_DOC,e)})}},ae(a.UniverDocsHyperLinkUIPlugin,"pluginName",Ye),ae(a.UniverDocsHyperLinkUIPlugin,"type",o.UniverInstanceType.UNIVER_DOC),a.UniverDocsHyperLinkUIPlugin=We([o.DependentOn(P.UniverDocsHyperLinkPlugin),W(1,o.Inject(o.Injector)),W(2,Ce.IRenderManagerService),W(3,o.IConfigService)],a.UniverDocsHyperLinkUIPlugin),Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
1
+ (function(a,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/docs-hyper-link"),require("@univerjs/engine-render"),require("@univerjs/docs"),require("@univerjs/docs-ui"),require("rxjs"),require("react/jsx-runtime"),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","react/jsx-runtime","@univerjs/design","@univerjs/ui","react"],o):(a=typeof globalThis<"u"?globalThis:a||self,o(a.UniverDocsHyperLinkUi={},a.UniverCore,a.UniverDocsHyperLink,a.UniverEngineRender,a.UniverDocs,a.UniverDocsUi,a.rxjs,a.React,a.UniverDesign,a.UniverUi,a.React))})(this,function(a,o,P,Ce,S,E,M,u,_,v,C){"use strict";var Ge=Object.defineProperty;var Je=(a,o,P)=>o in a?Ge(a,o,{enumerable:!0,configurable:!0,writable:!0,value:P}):a[o]=P;var D=(a,o,P)=>Je(a,typeof o!="symbol"?o+"":o,P);const ye="docs-hyper-link-ui.config",J={},Q={type:o.CommandType.COMMAND,id:"docs.command.add-hyper-link",async handler(n,e){if(!e)return!1;const{payload:t,unitId:i,selections:r}=e,s=n.get(o.ICommandService),c=o.generateRandomId(),d=S.addCustomRangeBySelectionFactory(n,{rangeId:c,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:t},unitId:i,selections:r});return d?s.syncExecuteCommand(d.id,d.params):!1}},X={id:"docs.command.update-hyper-link",type:o.CommandType.COMMAND,handler(n,e){var h;if(!e)return!1;const{unitId:t,payload:i,segmentId:r,linkId:s}=e,c=n.get(o.ICommandService),d=n.get(o.IUniverInstanceService),f=n.get(S.DocSelectionManagerService).getActiveTextRange(),m=d.getUnit(t,o.UniverInstanceType.UNIVER_DOC);if(!f||!m)return!1;const I=(h=o.getBodySlice(m.getSelfOrHeaderFooterModel(r).getBody(),f.startOffset,f.endOffset).textRuns)==null?void 0:h[0];I&&(I.ed=e.label.length+1);const l=S.replaceSelectionFactory(n,{unitId:t,body:{dataStream:`${e.label}`,customRanges:[{rangeId:s,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:e.label.length+1,properties:{url:i}}],textRuns:I?[I]:void 0},selection:{startOffset:f.startOffset,endOffset:f.endOffset,collapsed:!1,segmentId:r}});return l?c.syncExecuteCommand(l.id,l.params):!1}};function Se(n){return/^[a-zA-Z]+:\/\//.test(n)}function xe(n){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(n)}function ke(n){return Se(n)?n:xe(n)?`mailto://${n}`:`https://${n}`}const T=()=>{const n=v.useDependency(k),e=v.useDependency(o.LocaleService),t=v.useObservable(n.editingLink$),i=v.useDependency(o.ICommandService),r=v.useDependency(o.IUniverInstanceService),s=v.useDependency(S.DocSelectionManagerService),[c,d]=C.useState(""),[g,f]=C.useState(""),[m,y]=C.useState(!1),I=o.Tools.isLegalUrl(c),l=t?r.getUnit(t.unitId,o.UniverInstanceType.UNIVER_DOC):r.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC);C.useEffect(()=>{var ue,ve,pe,ge,fe,he,Ie,me,_e;const p=s.getActiveTextRange();if(!p)return;if(t){const K=(ue=l==null?void 0:l.getSelfOrHeaderFooterModel(t.segmentId))==null?void 0:ue.getBody(),A=(ve=K==null?void 0:K.customRanges)==null?void 0:ve.find(G=>(t==null?void 0:t.linkId)===G.rangeId&&G.startIndex===t.startIndex&&G.endIndex===t.endIndex);l&&A&&(d((ge=(pe=A.properties)==null?void 0:pe.url)!=null?ge:""),f(o.BuildTextUtils.transform.getPlainText(o.getBodySlice(K,A.startIndex,A.endIndex+1).dataStream)));return}const O=(fe=l==null?void 0:l.getSelfOrHeaderFooterModel(p.segmentId))==null?void 0:fe.getBody(),le=O?p:null,$=le&&((Ie=o.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(le,(he=O==null?void 0:O.customRanges)!=null?he:[]))==null?void 0:Ie[0]);l&&$&&d((_e=(me=$==null?void 0:$.properties)==null?void 0:me.url)!=null?_e:"")},[l,t,s,r]);const h=()=>{n.hideEditPopup()},L=()=>{if(y(!0),!I||!l)return;const p=ke(c);if(!t)i.executeCommand(Q.id,{unitId:l.getUnitId(),payload:p});else{if(!g)return;i.executeCommand(X.id,{unitId:l.getUnitId(),payload:p,linkId:t.linkId,label:g,segmentId:t.segmentId})}n.hideEditPopup()};if(l)return u.jsxs("div",{className:_.clsx("univer-box-border univer-w-[328px] univer-rounded-xl univer-bg-white univer-px-6 univer-py-5 univer-shadow dark:!univer-bg-gray-900",_.borderClassName),children:[u.jsxs("div",{children:[t?u.jsx(_.FormLayout,{label:e.t("docLink.edit.label"),error:m&&!g?e.t("docLink.edit.labelError"):"",children:u.jsx(_.Input,{value:g,onChange:f,autoFocus:!0,onKeyDown:p=>{p.keyCode===v.KeyCode.ENTER&&L()}})}):null,u.jsx(_.FormLayout,{label:e.t("docLink.edit.address"),error:m&&!I?e.t("docLink.edit.addressError"):"",children:u.jsx(_.Input,{value:c,onChange:d,autoFocus:!0,onKeyDown:p=>{p.keyCode===v.KeyCode.ENTER&&L()}})})]}),u.jsxs("div",{className:"univer-flex univer-justify-end univer-gap-3",children:[u.jsx(_.Button,{onClick:h,children:e.t("docLink.edit.cancel")}),u.jsx(_.Button,{variant:"primary",disabled:!c,onClick:L,children:e.t("docLink.edit.confirm")})]})]})};T.componentKey="docs-hyper-link-edit";var x=function(){return x=Object.assign||function(n){for(var e,t=1,i=arguments.length;t<i;t++){e=arguments[t];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r])}return n},x.apply(this,arguments)},Le=function(n,e){var t={};for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&e.indexOf(i)<0&&(t[i]=n[i]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,i=Object.getOwnPropertySymbols(n);r<i.length;r++)e.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(n,i[r])&&(t[i[r]]=n[i[r]]);return t},w=C.forwardRef(function(n,e){var t=n.icon,i=n.id,r=n.className,s=n.extend,c=Le(n,["icon","id","className","extend"]),d="univerjs-icon univerjs-icon-".concat(i," ").concat(r||"").trim(),g=C.useRef("_".concat(Pe()));return ee(t,"".concat(i),{defIds:t.defIds,idSuffix:g.current},x({ref:e,className:d},c),s)});function ee(n,e,t,i,r){return C.createElement(n.tag,x(x({key:e},Oe(n,t,r)),i),(De(n,t).children||[]).map(function(s,c){return ee(s,"".concat(e,"-").concat(n.tag,"-").concat(c),t,void 0,r)}))}function Oe(n,e,t){var i=x({},n.attrs);t!=null&&t.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=t.colorChannel1),n.tag==="mask"&&i.id&&(i.id=i.id+e.idSuffix),Object.entries(i).forEach(function(s){var c=s[0],d=s[1];c==="mask"&&typeof d=="string"&&(i[c]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))});var r=e.defIds;return!r||r.length===0||(n.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+e.idSuffix),Object.entries(i).forEach(function(s){var c=s[0],d=s[1];typeof d=="string"&&(i[c]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(e.idSuffix,")")))})),i}function De(n,e){var t,i=e.defIds;return!i||i.length===0?n:n.tag==="defs"&&(!((t=n.children)===null||t===void 0)&&t.length)?x(x({},n),{children:n.children.map(function(r){return typeof r.attrs.id=="string"&&i&&i.indexOf(r.attrs.id)>-1?x(x({},r),{attrs:x(x({},r.attrs),{id:r.attrs.id+e.idSuffix})}):r})}):n}function Pe(){return Math.random().toString(36).substring(2,8)}w.displayName="UniverIcon";var Me={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"}}]},ne=C.forwardRef(function(n,e){return C.createElement(w,Object.assign({},n,{id:"copy-single",ref:e,icon:Me}))});ne.displayName="CopySingle";var Ue={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M9.8816 1.97978C11.0177 0.843607 12.862 0.884962 14.0004 2.02342C15.1389 3.16188 15.1803 5.00612 14.0441 6.14228L11.399 8.78737C11.1608 9.02559 10.7746 9.02559 10.5363 8.78737C10.2981 8.54915 10.2981 8.16292 10.5363 7.9247L13.1814 5.2796C13.8195 4.64155 13.8217 3.57006 13.1378 2.8861C12.4538 2.20211 11.3823 2.20438 10.7443 2.84245L7.6976 5.88911L7.69317 5.89349C7.05959 6.53211 7.05894 7.60014 7.74132 8.28252C7.97954 8.52074 7.97954 8.90697 7.74132 9.14519C7.5031 9.38341 7.11687 9.38341 6.87865 9.14519C5.74016 8.00671 5.69884 6.16251 6.83497 5.02633L6.84021 5.02116L9.8816 1.97978Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.61426 7.2364C4.85248 6.99818 5.23871 6.99818 5.47693 7.2364C5.71515 7.47462 5.71515 7.86085 5.47693 8.09907L2.83183 10.7442C2.19375 11.3823 2.1915 12.4537 2.87547 13.1377C3.55945 13.8217 4.6309 13.8194 5.26899 13.1813L8.31566 10.1347C8.32262 10.1277 8.32971 10.121 8.33691 10.1144C8.34408 10.1064 8.3515 10.0986 8.35916 10.091C8.99721 9.45291 8.99949 8.38145 8.3155 7.69746C8.07728 7.45924 8.07728 7.07301 8.3155 6.83479C8.55372 6.59657 8.93995 6.59657 9.17817 6.83479C10.3166 7.97327 10.358 9.81748 9.22183 10.9536C9.21487 10.9606 9.20779 10.9673 9.20058 10.9739C9.19341 10.9819 9.18599 10.9897 9.17833 10.9973L6.13166 14.044C4.99548 15.1802 3.15127 15.1389 2.01279 14.0004C0.874362 12.8619 0.83297 11.0177 1.96916 9.8815L4.61426 7.2364Z"}}]},B=C.forwardRef(function(n,e){return C.createElement(w,Object.assign({},n,{id:"link-single",ref:e,icon:Ue}))});B.displayName="LinkSingle";var we={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"}}]},te=C.forwardRef(function(n,e){return C.createElement(w,Object.assign({},n,{id:"unlink-single",ref:e,icon:we}))});te.displayName="UnlinkSingle";var be={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"}}]},ie=C.forwardRef(function(n,e){return C.createElement(w,Object.assign({},n,{id:"write-single",ref:e,icon:be}))});ie.displayName="WriteSingle";const re={type:o.CommandType.COMMAND,id:"docs.command.delete-hyper-link",async handler(n,e){if(!e)return!1;const{unitId:t,linkId:i,segmentId:r}=e,s=n.get(o.ICommandService),c=S.deleteCustomRangeFactory(n,{unitId:t,rangeId:i,segmentId:r});return c?await s.syncExecuteCommand(c.id,c.params):!1}},oe=n=>{const e=n.get(S.DocSelectionManagerService),t=n.get(o.IUniverInstanceService),i=e.getTextRanges();if(!(i!=null&&i.length))return!0;const r=i[0];return!!(!t.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC)||!r||r.collapsed)},U={type:o.CommandType.OPERATION,id:"doc.operation.show-hyper-link-edit-popup",handler(n,e){var c;const t=e==null?void 0:e.link,i=n.get(o.IUniverInstanceService);if(oe(n)&&!t)return!1;const r=n.get(k),s=(t==null?void 0:t.unitId)||((c=i.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC))==null?void 0:c.getUnitId());return s?(r.showEditPopup(s,t),!0):!1}},F={type:o.CommandType.OPERATION,id:"doc.operation.toggle-hyper-link-info-popup",handler(n,e){const t=n.get(k);return e?(t.showInfoPopup(e),!0):(t.hideInfoPopup(),!0)}},se={type:o.CommandType.OPERATION,id:"doc.operation.click-hyper-link",handler(n,e){var f,m,y;if(!e)return!1;const{unitId:t,linkId:i,segmentId:r}=e,c=n.get(o.IUniverInstanceService).getUnit(t,o.UniverInstanceType.UNIVER_DOC),d=c==null?void 0:c.getSelfOrHeaderFooterModel(r).getBody(),g=(y=(m=(f=d==null?void 0:d.customRanges)==null?void 0:f.find(I=>I.rangeId===i&&I.rangeType===o.CustomRangeType.HYPERLINK))==null?void 0:m.properties)==null?void 0:y.url;return g&&window.open(g,"_blank","noopener noreferrer"),!0}},R=()=>{var L,p;const n=v.useDependency(k),e=v.useDependency(o.ICommandService),t=v.useDependency(v.IMessageService),i=v.useDependency(o.LocaleService),r=v.useObservable(n.showingLink$),s=v.useDependency(o.IUniverInstanceService);if(!r)return null;const{unitId:c,linkId:d,segmentId:g,startIndex:f,endIndex:m}=r,y=s.getUnit(c,o.UniverInstanceType.UNIVER_DOC),I=y==null?void 0:y.getSelfOrHeaderFooterModel(g).getBody(),l=(L=I==null?void 0:I.customRanges)==null?void 0:L.find(O=>O.rangeId===d&&O.rangeType===o.CustomRangeType.HYPERLINK&&O.startIndex===f&&O.endIndex===m);if(!l)return null;const h=(p=l.properties)==null?void 0:p.url;return u.jsxs("div",{className:_.clsx("univer-box-border univer-flex univer-max-w-80 univer-items-center univer-justify-between univer-overflow-hidden univer-rounded-lg univer-bg-white univer-p-3 univer-shadow dark:!univer-bg-gray-900",_.borderClassName),onClick:()=>{n.hideInfoPopup()},children:[u.jsxs("div",{className:"univer-flex univer-h-6 univer-flex-1 univer-cursor-pointer univer-items-center univer-truncate univer-text-sm univer-leading-5 univer-text-primary-500",onClick:()=>window.open(h,void 0,"noopener noreferrer"),children:[u.jsx("div",{className:"univer-mr-2 univer-flex univer-size-5 univer-flex-[0_0_auto] univer-items-center univer-justify-center univer-text-base univer-text-gray-900 dark:!univer-text-white",children:u.jsx(B,{})}),u.jsx(_.Tooltip,{showIfEllipsis:!0,title:h,children:u.jsx("span",{className:"univer-flex-1 univer-truncate",children:h})})]}),u.jsxs("div",{className:"univer-flex univer-h-6 univer-flex-[0_0_auto] univer-items-center univer-justify-center",children:[u.jsx("div",{className:"univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",onClick:()=>{navigator.clipboard.writeText(h),t.show({content:i.t("docLink.info.coped"),type:_.MessageType.Info})},children:u.jsx(_.Tooltip,{placement:"bottom",title:i.t("docLink.info.copy"),children:u.jsx(ne,{})})}),u.jsx("div",{className:"univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",onClick:()=>{e.executeCommand(U.id,{link:r})},children:u.jsx(_.Tooltip,{placement:"bottom",title:i.t("docLink.info.edit"),children:u.jsx(ie,{})})}),u.jsx("div",{className:"univer-ml-2 univer-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded univer-text-base",onClick:()=>{e.executeCommand(re.id,{unitId:c,linkId:l.rangeId,segmentId:g})},children:u.jsx(_.Tooltip,{placement:"bottom",title:i.t("docLink.info.cancel"),children:u.jsx(te,{})})})]})]})};R.componentKey="univer.doc.link-info-popup";var Ee=Object.getOwnPropertyDescriptor,Te=(n,e,t,i)=>{for(var r=i>1?void 0:i?Ee(e,t):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(r=c(r)||r);return r},V=(n,e)=>(t,i)=>e(t,i,n);let k=class extends o.Disposable{constructor(e,t,i){super();D(this,"_editingLink$",new M.BehaviorSubject(null));D(this,"_showingLink$",new M.BehaviorSubject(null));D(this,"editingLink$",this._editingLink$.asObservable());D(this,"showingLink$",this._showingLink$.asObservable());D(this,"_editPopup",null);D(this,"_infoPopup",null);this._docCanvasPopupManagerService=e,this._textSelectionManagerService=t,this._univerInstanceService=i,this.disposeWithMe(()=>{this._editingLink$.complete(),this._showingLink$.complete()})}get editing(){return this._editingLink$.value}get showing(){return this._showingLink$.value}showEditPopup(e,t){this._editPopup&&this._editPopup.dispose(),this._editingLink$.next(t);const i=this._textSelectionManagerService.getTextRanges({unitId:e,subUnitId:e});let r=i==null?void 0:i[i.length-1];if(t){const{segmentId:s,segmentPage:c,startIndex:d,endIndex:g}=t;r={collapsed:!1,startOffset:d,endOffset:g+1,segmentId:s,segmentPage:c},this._textSelectionManagerService.replaceDocRanges([{startOffset:d,endOffset:g+1}])}return r?(this._editPopup=this._docCanvasPopupManagerService.attachPopupToRange(r,{componentKey:T.componentKey,direction:"bottom"},e),this._editPopup):null}hideEditPopup(){var e;this._editingLink$.next(null),(e=this._editPopup)==null||e.dispose()}showInfoPopup(e){var f,m,y,I,l,h;const{linkId:t,unitId:i,segmentId:r,segmentPage:s,startIndex:c,endIndex:d}=e;if(!(((f=this.showing)==null?void 0:f.linkId)===t&&((m=this.showing)==null?void 0:m.unitId)===i&&((y=this.showing)==null?void 0:y.segmentId)===r&&((I=this.showing)==null?void 0:I.segmentPage)===s&&((l=this.showing)==null?void 0:l.startIndex)===c&&((h=this.showing)==null?void 0:h.endIndex)===d||(this._infoPopup&&this._infoPopup.dispose(),!this._univerInstanceService.getUnit(i,o.UniverInstanceType.UNIVER_DOC))))return this._showingLink$.next({unitId:i,linkId:t,segmentId:r,segmentPage:s,startIndex:c,endIndex:d}),this._infoPopup=this._docCanvasPopupManagerService.attachPopupToRange({collapsed:!1,startOffset:c,endOffset:d+1,segmentId:r,segmentPage:s},{componentKey:R.componentKey,direction:"top-center",multipleDirection:"top",onClickOutside:()=>{this.hideInfoPopup()}},i),this._infoPopup}hideInfoPopup(){var e;this._showingLink$.next(null),(e=this._infoPopup)==null||e.dispose()}};k=Te([V(0,o.Inject(E.DocCanvasPopManagerService)),V(1,o.Inject(S.DocSelectionManagerService)),V(2,o.IUniverInstanceService)],k);var Re=Object.getOwnPropertyDescriptor,Ne=(n,e,t,i)=>{for(var r=i>1?void 0:i?Re(e,t):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(r=c(r)||r);return r},Y=(n,e)=>(t,i)=>e(t,i,n);let N=class extends o.Disposable{constructor(n,e,t){super(),this._commandService=n,this._univerInstanceService=e,this._docHyperLinkService=t,this._initSelectionChange()}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(n=>{var e,t,i;if(n.id===S.SetTextSelectionsOperation.id){const r=n.params,{unitId:s,ranges:c,segmentId:d}=r,g=this._univerInstanceService.getUnit(s,o.UniverInstanceType.UNIVER_DOC),f=c[0];if(f&&g){const{startOffset:m,endOffset:y,collapsed:I,segmentPage:l}=f,h=(t=(e=g.getSelfOrHeaderFooterModel(d))==null?void 0:e.getBody())==null?void 0:t.customRanges;if(I){const L=(i=h==null?void 0:h.findIndex(p=>p.startIndex<m&&p.endIndex>y-1))!=null?i:-1;if(L>-1){const p=h[L];this._docHyperLinkService.showInfoPopup({unitId:s,linkId:p.rangeId,segmentId:d,segmentPage:l,startIndex:p.startIndex,endIndex:p.endIndex});return}}else if(h==null?void 0:h.find(p=>p.startIndex<=m&&p.endIndex>=y-1))return}this._docHyperLinkService.hideInfoPopup(),this._docHyperLinkService.hideEditPopup()}}))}};N=Ne([Y(0,o.ICommandService),Y(1,o.IUniverInstanceService),Y(2,o.Inject(k))],N);var je=Object.getOwnPropertyDescriptor,He=(n,e,t,i)=>{for(var r=i>1?void 0:i?je(e,t):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(r=c(r)||r);return r},b=(n,e)=>(t,i)=>e(t,i,n);let q=class extends o.Disposable{constructor(n,e,t,i,r,s){super(),this._context=n,this._docEventManagerService=e,this._commandService=t,this._hyperLinkPopupService=i,this._docSkeletonManagerService=r,this._docSelectionManagerService=s,!(this._context.unitId===o.DOCS_ZEN_EDITOR_UNIT_ID_KEY||this._context.unitId===o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)&&(this._initHover(),this._initClick())}get _skeleton(){return this._docSkeletonManagerService.getSkeleton()}_hideInfoPopup(){this._hyperLinkPopupService.showing&&this._commandService.executeCommand(F.id)}_initHover(){this.disposeWithMe(this._docEventManagerService.hoverCustomRanges$.subscribe(n=>{var r;const e=n.find(s=>s.range.rangeType===o.CustomRangeType.HYPERLINK),t=this._docSelectionManagerService.getTextRanges(),i=t==null?void 0:t[0].segmentId;if(((r=e==null?void 0:e.segmentId)!=null?r:"")!==i){this._hideInfoPopup();return}e?this._commandService.executeCommand(F.id,{unitId:this._context.unitId,linkId:e.range.rangeId,segmentId:e.segmentId,segmentPage:e.segmentPageIndex,rangeId:e.range.rangeId,startIndex:e.range.startIndex,endIndex:e.range.endIndex}):this._hideInfoPopup()}))}_initClick(){this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe(n=>{const e=n.range;e&&this._commandService.executeCommand(se.id,{unitId:this._context.unitId,linkId:e.rangeId,segmentId:n.segmentId})}))}};q=He([b(1,o.Inject(E.DocEventManagerService)),b(2,o.ICommandService),b(3,o.Inject(k)),b(4,o.Inject(S.DocSkeletonManagerService)),b(5,o.Inject(S.DocSelectionManagerService))],q);var $e=Object.getOwnPropertyDescriptor,Ke=(n,e,t,i)=>{for(var r=i>1?void 0:i?$e(e,t):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(r=c(r)||r);return r},Z=(n,e)=>(t,i)=>e(t,i,n);let W=class extends o.Disposable{constructor(n,e,t,i){super(),this._context=n,this._docInterceptorService=e,this._hyperLinkService=t,this._docRenderController=i,this._init(),this._initReRender()}_init(){this._docInterceptorService.intercept(S.DOC_INTERCEPTOR_POINT.CUSTOM_RANGE,{handler:(n,e,t)=>{if(!n)return t(n);const{unitId:i,index:r}=e,s=this._hyperLinkService.showing;if(!s)return t({...n,active:!1});const{linkId:c,unitId:d,startIndex:g,endIndex:f}=s,m=d===i&&n.rangeId===c&&r>=g&&r<=f;return t({...n,active:m})}})}_initReRender(){this.disposeWithMe(this._hyperLinkService.showingLink$.pipe(M.distinctUntilChanged((n,e)=>(n==null?void 0:n.linkId)===(e==null?void 0:e.linkId)&&(n==null?void 0:n.unitId)===(e==null?void 0:e.unitId)&&(n==null?void 0:n.startIndex)===(e==null?void 0:e.startIndex)),M.pairwise()).subscribe(([n,e])=>{e?e.unitId===this._context.unitId&&this._docRenderController.reRender(e.unitId):n&&n.unitId===this._context.unitId&&this._docRenderController.reRender(n.unitId)}))}};W=Ke([Z(1,o.Inject(S.DocInterceptorService)),Z(2,o.Inject(k)),Z(3,o.Inject(E.DocRenderController))],W);const ce="doc-hyper-link-icon";function de(n){return{id:U.id,type:v.MenuItemType.BUTTON,icon:ce,title:"docLink.menu.tooltip",tooltip:"docLink.menu.tooltip",hidden$:v.getMenuHiddenObservable(n,o.UniverInstanceType.UNIVER_DOC),disabled$:new M.Observable(function(e){const i=n.get(S.DocSelectionManagerService).textSelection$.pipe(M.debounceTime(16)).subscribe(()=>{e.next(oe(n))});return()=>{i.unsubscribe()}})}}const Ae={id:U.id,binding:v.MetaKeys.CTRL_COMMAND|v.KeyCode.K,description:"docLink.menu.tooltip",preconditions:E.whenDocAndEditorFocused},Be={[v.RibbonInsertGroup.MEDIA]:{[U.id]:{order:1,menuItemFactory:de}},[v.ContextMenuPosition.MAIN_AREA]:{[v.ContextMenuGroup.DATA]:{[U.id]:{order:0,menuItemFactory:de}}}};var Fe=Object.getOwnPropertyDescriptor,Ve=(n,e,t,i)=>{for(var r=i>1?void 0:i?Fe(e,t):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(r=c(r)||r);return r},j=(n,e)=>(t,i)=>e(t,i,n);let H=class extends o.Disposable{constructor(n,e,t,i){super(),this._componentManager=n,this._commandService=e,this._menuManagerService=t,this._shortcutService=i,this._initComponents(),this._initCommands(),this._initMenus(),this._initShortcut()}_initComponents(){[[T,T.componentKey],[R,R.componentKey],[B,ce]].forEach(([n,e])=>{this.disposeWithMe(this._componentManager.register(e,n))})}_initCommands(){[Q,X,re,U,F,se].forEach(n=>{this._commandService.registerCommand(n)})}_initShortcut(){[Ae].forEach(n=>{this._shortcutService.registerShortcut(n)})}_initMenus(){this._menuManagerService.mergeMenu(Be)}};H=Ve([j(0,o.Inject(v.ComponentManager)),j(1,o.ICommandService),j(2,v.IMenuManagerService),j(3,v.IShortcutService)],H);const Ye="DOC_HYPER_LINK_UI_PLUGIN";var qe=Object.defineProperty,Ze=Object.getOwnPropertyDescriptor,We=(n,e,t)=>e in n?qe(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,ze=(n,e,t,i)=>{for(var r=i>1?void 0:i?Ze(e,t):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(r=c(r)||r);return r},z=(n,e)=>(t,i)=>e(t,i,n),ae=(n,e,t)=>We(n,typeof e!="symbol"?e+"":e,t);a.UniverDocsHyperLinkUIPlugin=class extends o.Plugin{constructor(e=J,t,i,r){super(),this._config=e,this._injector=t,this._renderManagerSrv=i,this._configService=r;const{menu:s,...c}=o.merge({},J,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig(ye,c)}onStarting(){[[k],[H],[N]].forEach(t=>{this._injector.add(t)}),this._injector.get(H)}onReady(){this._injector.get(N)}onRendered(){this._initRenderModule()}_initRenderModule(){[[W],[q]].forEach(e=>{this._renderManagerSrv.registerRenderModule(o.UniverInstanceType.UNIVER_DOC,e)})}},ae(a.UniverDocsHyperLinkUIPlugin,"pluginName",Ye),ae(a.UniverDocsHyperLinkUIPlugin,"type",o.UniverInstanceType.UNIVER_DOC),a.UniverDocsHyperLinkUIPlugin=ze([o.DependentOn(P.UniverDocsHyperLinkPlugin),z(1,o.Inject(o.Injector)),z(2,Ce.IRenderManagerService),z(3,o.IConfigService)],a.UniverDocsHyperLinkUIPlugin),Object.defineProperty(a,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.7.0-nightly.202505201607",
3
+ "version": "0.7.0-nightly.202505221607",
4
4
  "private": false,
5
5
  "description": "Univer thread comment plugin",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -53,13 +53,13 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "@univerjs/icons": "^0.3.24",
56
- "@univerjs/core": "0.7.0-nightly.202505201607",
57
- "@univerjs/docs": "0.7.0-nightly.202505201607",
58
- "@univerjs/docs-ui": "0.7.0-nightly.202505201607",
59
- "@univerjs/docs-hyper-link": "0.7.0-nightly.202505201607",
60
- "@univerjs/design": "0.7.0-nightly.202505201607",
61
- "@univerjs/engine-render": "0.7.0-nightly.202505201607",
62
- "@univerjs/ui": "0.7.0-nightly.202505201607"
56
+ "@univerjs/core": "0.7.0-nightly.202505221607",
57
+ "@univerjs/design": "0.7.0-nightly.202505221607",
58
+ "@univerjs/docs-ui": "0.7.0-nightly.202505221607",
59
+ "@univerjs/docs-hyper-link": "0.7.0-nightly.202505221607",
60
+ "@univerjs/docs": "0.7.0-nightly.202505221607",
61
+ "@univerjs/engine-render": "0.7.0-nightly.202505221607",
62
+ "@univerjs/ui": "0.7.0-nightly.202505221607"
63
63
  },
64
64
  "devDependencies": {
65
65
  "postcss": "^8.5.3",
@@ -68,7 +68,7 @@
68
68
  "tailwindcss": "^3.4.17",
69
69
  "typescript": "^5.8.3",
70
70
  "vite": "^6.3.5",
71
- "vitest": "^3.1.3",
71
+ "vitest": "^3.1.4",
72
72
  "@univerjs-infra/shared": "0.7.0"
73
73
  },
74
74
  "scripts": {