@univerjs/docs-hyper-link-ui 0.6.1 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +277 -290
- package/lib/umd/index.js +1 -1
- package/package.json +11 -12
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,U,Le,y,b,E,u,k,p,_){"use strict";var en=Object.defineProperty;var nn=(a,o,U)=>o in a?en(a,o,{enumerable:!0,configurable:!0,writable:!0,value:U}):a[o]=U;var P=(a,o,U)=>nn(a,typeof o!="symbol"?o+"":o,U);const Oe="docs-hyper-link-ui.config",X={},ee={type:o.CommandType.COMMAND,id:"docs.command.add-hyper-link",async handler(e,n){if(!n)return!1;const{payload:i,unitId:t,selections:r}=n,s=e.get(o.ICommandService),c=o.generateRandomId(),d=y.addCustomRangeBySelectionFactory(e,{rangeId:c,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:i},unitId:t,selections:r});return d?s.syncExecuteCommand(d.id,d.params):!1}},ne={id:"docs.command.update-hyper-link",type:o.CommandType.COMMAND,handler(e,n){var f;if(!n)return!1;const{unitId:i,payload:t,segmentId:r,linkId:s}=n,c=e.get(o.ICommandService),d=e.get(o.IUniverInstanceService),h=e.get(y.DocSelectionManagerService).getActiveTextRange(),m=d.getUnit(i,o.UniverInstanceType.UNIVER_DOC);if(!h||!m)return!1;const I=(f=o.getBodySlice(m.getSelfOrHeaderFooterModel(r).getBody(),h.startOffset,h.endOffset).textRuns)==null?void 0:f[0];I&&(I.ed=n.label.length+1);const l=y.replaceSelectionFactory(e,{unitId:i,body:{dataStream:`${n.label}`,customRanges:[{rangeId:s,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:n.label.length+1,properties:{url:t}}],textRuns:I?[I]:void 0},selection:{startOffset:h.startOffset,endOffset:h.endOffset,collapsed:!1,segmentId:r}});return l?c.syncExecuteCommand(l.id,l.params):!1}},R={docsLinkEdit:"univer-docs-link-edit",docsLinkEditButtons:"univer-docs-link-edit-buttons",docsLinkEditButton:"univer-docs-link-edit-button"};function xe(e){return/^[a-zA-Z]+:\/\//.test(e)}function De(e){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(e)}function Pe(e){return xe(e)?e:De(e)?`mailto://${e}`:`https://${e}`}const N=()=>{const e=p.useDependency(L),n=p.useDependency(o.LocaleService),i=p.useObservable(e.editingLink$),t=p.useDependency(o.ICommandService),r=p.useDependency(o.IUniverInstanceService),s=p.useDependency(y.DocSelectionManagerService),[c,d]=_.useState(""),[v,h]=_.useState(""),[m,C]=_.useState(!1),I=o.Tools.isLegalUrl(c),l=i?r.getUnit(i.unitId,o.UniverInstanceType.UNIVER_DOC):r.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC);_.useEffect(()=>{var he,fe,Ie,me,_e,Ce,ye,Se,ke;const g=s.getActiveTextRange();if(!g)return;if(i){const A=(he=l==null?void 0:l.getSelfOrHeaderFooterModel(i.segmentId))==null?void 0:he.getBody(),F=(fe=A==null?void 0:A.customRanges)==null?void 0:fe.find(Q=>(i==null?void 0:i.linkId)===Q.rangeId&&Q.startIndex===i.startIndex&&Q.endIndex===i.endIndex);l&&F&&(d((me=(Ie=F.properties)==null?void 0:Ie.url)!=null?me:""),h(o.BuildTextUtils.transform.getPlainText(o.getBodySlice(A,F.startIndex,F.endIndex+1).dataStream)));return}const x=(_e=l==null?void 0:l.getSelfOrHeaderFooterModel(g.segmentId))==null?void 0:_e.getBody(),ve=x?g:null,K=ve&&((ye=o.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(ve,(Ce=x==null?void 0:x.customRanges)!=null?Ce:[]))==null?void 0:ye[0]);l&&K&&d((ke=(Se=K==null?void 0:K.properties)==null?void 0:Se.url)!=null?ke:"")},[l,i,s,r]);const f=()=>{e.hideEditPopup()},O=()=>{if(C(!0),!I||!l)return;const g=Pe(c);if(!i)t.executeCommand(ee.id,{unitId:l.getUnitId(),payload:g});else{if(!v)return;t.executeCommand(ne.id,{unitId:l.getUnitId(),payload:g,linkId:i.linkId,label:v,segmentId:i.segmentId})}e.hideEditPopup()};if(l)return u.jsxs("div",{className:R.docsLinkEdit,children:[u.jsxs("div",{children:[i?u.jsx(k.FormLayout,{label:n.t("docLink.edit.label"),error:m&&!v?n.t("docLink.edit.labelError"):"",children:u.jsx(k.Input,{value:v,onChange:h,autoFocus:!0,onKeyDown:g=>{g.keyCode===p.KeyCode.ENTER&&O()}})}):null,u.jsx(k.FormLayout,{label:n.t("docLink.edit.address"),error:m&&!I?n.t("docLink.edit.addressError"):"",children:u.jsx(k.Input,{value:c,onChange:d,autoFocus:!0,onKeyDown:g=>{g.keyCode===p.KeyCode.ENTER&&O()}})})]}),u.jsxs("div",{className:R.docsLinkEditButtons,children:[u.jsx(k.Button,{className:R.docsLinkEditButton,onClick:f,children:n.t("docLink.edit.cancel")}),u.jsx(k.Button,{disabled:!c,className:R.docsLinkEditButton,type:"primary",onClick:O,children:n.t("docLink.edit.confirm")})]})]})};N.componentKey="docs-hyper-link-edit";var S=function(){return S=Object.assign||function(e){for(var n,i=1,t=arguments.length;i<t;i++){n=arguments[i];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},S.apply(this,arguments)},Ue=function(e,n){var i={};for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&n.indexOf(t)<0&&(i[t]=e[t]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,t=Object.getOwnPropertySymbols(e);r<t.length;r++)n.indexOf(t[r])<0&&Object.prototype.propertyIsEnumerable.call(e,t[r])&&(i[t[r]]=e[t[r]]);return i},T=_.forwardRef(function(e,n){var i=e.icon,t=e.id,r=e.className,s=e.extend,c=Ue(e,["icon","id","className","extend"]),d="univerjs-icon univerjs-icon-".concat(t," ").concat(r||"").trim(),v=_.useRef("_".concat(Te()));return te(i,"".concat(t),{defIds:i.defIds,idSuffix:v.current},S({ref:n,className:d},c),s)});function te(e,n,i,t,r){return _.createElement(e.tag,S(S({key:n},Ee(e,i,r)),t),(Me(e,i).children||[]).map(function(s,c){return te(s,"".concat(n,"-").concat(e.tag,"-").concat(c),i,void 0,r)}))}function Ee(e,n,i){var t=S({},e.attrs);i!=null&&i.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=i.colorChannel1),e.tag==="mask"&&t.id&&(t.id=t.id+n.idSuffix),Object.entries(t).forEach(function(s){var c=s[0],d=s[1];c==="mask"&&typeof d=="string"&&(t[c]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))});var r=n.defIds;return!r||r.length===0||(e.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+n.idSuffix),Object.entries(t).forEach(function(s){var c=s[0],d=s[1];typeof d=="string"&&(t[c]=d.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),t}function Me(e,n){var i,t=n.defIds;return!t||t.length===0?e:e.tag==="defs"&&(!((i=e.children)===null||i===void 0)&&i.length)?S(S({},e),{children:e.children.map(function(r){return typeof r.attrs.id=="string"&&t&&t.indexOf(r.attrs.id)>-1?S(S({},r),{attrs:S(S({},r.attrs),{id:r.attrs.id+n.idSuffix})}):r})}):e}function Te(){return Math.random().toString(36).substring(2,8)}T.displayName="UniverIcon";var we={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"}}]},ie=_.forwardRef(function(e,n){return _.createElement(T,Object.assign({},e,{id:"copy-single",ref:n,icon:we}))});ie.displayName="CopySingle";var be={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"}}]},V=_.forwardRef(function(e,n){return _.createElement(T,Object.assign({},e,{id:"link-single",ref:n,icon:be}))});V.displayName="LinkSingle";var Re={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"}}]},re=_.forwardRef(function(e,n){return _.createElement(T,Object.assign({},e,{id:"unlink-single",ref:n,icon:Re}))});re.displayName="UnlinkSingle";var Ne={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"}}]},oe=_.forwardRef(function(e,n){return _.createElement(T,Object.assign({},e,{id:"write-single",ref:n,icon:Ne}))});oe.displayName="WriteSingle";function se(e){var n,i,t="";if(typeof e=="string"||typeof e=="number")t+=e;else if(typeof e=="object")if(Array.isArray(e)){var r=e.length;for(n=0;n<r;n++)e[n]&&(i=se(e[n]))&&(t&&(t+=" "),t+=i)}else for(i in e)e[i]&&(t&&(t+=" "),t+=i);return t}function ce(){for(var e,n,i=0,t="",r=arguments.length;i<r;i++)(e=arguments[i])&&(n=se(e))&&(t&&(t+=" "),t+=n);return t}const de={type:o.CommandType.COMMAND,id:"docs.command.delete-hyper-link",async handler(e,n){if(!n)return!1;const{unitId:i,linkId:t,segmentId:r}=n,s=e.get(o.ICommandService),c=y.deleteCustomRangeFactory(e,{unitId:i,rangeId:t,segmentId:r});return c?await s.syncExecuteCommand(c.id,c.params):!1}},ae=e=>{const n=e.get(y.DocSelectionManagerService),i=e.get(o.IUniverInstanceService),t=n.getTextRanges();if(!(t!=null&&t.length))return!0;const r=t[0];return!!(!i.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC)||!r||r.collapsed)},M={type:o.CommandType.OPERATION,id:"doc.operation.show-hyper-link-edit-popup",handler(e,n){var c;const i=n==null?void 0:n.link,t=e.get(o.IUniverInstanceService);if(ae(e)&&!i)return!1;const r=e.get(L),s=(i==null?void 0:i.unitId)||((c=t.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC))==null?void 0:c.getUnitId());return s?(r.showEditPopup(s,i),!0):!1}},Y={type:o.CommandType.OPERATION,id:"doc.operation.toggle-hyper-link-info-popup",handler(e,n){const i=e.get(L);return n?(i.showInfoPopup(n),!0):(i.hideInfoPopup(),!0)}},le={type:o.CommandType.OPERATION,id:"doc.operation.click-hyper-link",handler(e,n){var h,m,C;if(!n)return!1;const{unitId:i,linkId:t,segmentId:r}=n,c=e.get(o.IUniverInstanceService).getUnit(i,o.UniverInstanceType.UNIVER_DOC),d=c==null?void 0:c.getSelfOrHeaderFooterModel(r).getBody(),v=(C=(m=(h=d==null?void 0:d.customRanges)==null?void 0:h.find(I=>I.rangeId===t&&I.rangeType===o.CustomRangeType.HYPERLINK))==null?void 0:m.properties)==null?void 0:C.url;return v&&window.open(v,"_blank","noopener noreferrer"),!0}},D={docLink:"univer-doc-link",docLinkType:"univer-doc-link-type",docLinkContent:"univer-doc-link-content",docLinkUrl:"univer-doc-link-url",docLinkOperations:"univer-doc-link-operations",docLinkOperation:"univer-doc-link-operation"},j=()=>{var O,g;const e=p.useDependency(L),n=p.useDependency(o.ICommandService),i=p.useDependency(p.IMessageService),t=p.useDependency(o.LocaleService),r=p.useObservable(e.showingLink$),s=p.useDependency(o.IUniverInstanceService);if(!r)return null;const{unitId:c,linkId:d,segmentId:v,startIndex:h,endIndex:m}=r,C=s.getUnit(c,o.UniverInstanceType.UNIVER_DOC),I=C==null?void 0:C.getSelfOrHeaderFooterModel(v).getBody(),l=(O=I==null?void 0:I.customRanges)==null?void 0:O.find(x=>x.rangeId===d&&x.rangeType===o.CustomRangeType.HYPERLINK&&x.startIndex===h&&x.endIndex===m);if(!l)return null;const f=(g=l.properties)==null?void 0:g.url;return u.jsxs("div",{className:D.docLink,onClick:()=>{e.hideInfoPopup()},children:[u.jsxs("div",{className:ce(D.docLinkContent),onClick:()=>window.open(f),children:[u.jsx("div",{className:D.docLinkType,children:u.jsx(V,{})}),u.jsx(k.Tooltip,{showIfEllipsis:!0,title:f,children:u.jsx("span",{className:D.docLinkUrl,children:f})})]}),u.jsxs("div",{className:D.docLinkOperations,children:[u.jsx("div",{className:ce(D.docLinkOperation),onClick:()=>{navigator.clipboard.writeText(f),i.show({content:t.t("docLink.info.coped"),type:k.MessageType.Info})},children:u.jsx(k.Tooltip,{placement:"bottom",title:t.t("docLink.info.copy"),children:u.jsx(ie,{})})}),u.jsx("div",{className:D.docLinkOperation,onClick:()=>{n.executeCommand(M.id,{link:r})},children:u.jsx(k.Tooltip,{placement:"bottom",title:t.t("docLink.info.edit"),children:u.jsx(oe,{})})}),u.jsx("div",{className:D.docLinkOperation,onClick:()=>{n.executeCommand(de.id,{unitId:c,linkId:l.rangeId,segmentId:v})},children:u.jsx(k.Tooltip,{placement:"bottom",title:t.t("docLink.info.cancel"),children:u.jsx(re,{})})})]})]})};j.componentKey="univer.doc.link-info-popup";var je=Object.getOwnPropertyDescriptor,He=(e,n,i,t)=>{for(var r=t>1?void 0:t?je(n,i):n,s=e.length-1,c;s>=0;s--)(c=e[s])&&(r=c(r)||r);return r},q=(e,n)=>(i,t)=>n(i,t,e);let L=class extends o.Disposable{constructor(n,i,t){super();P(this,"_editingLink$",new E.BehaviorSubject(null));P(this,"_showingLink$",new E.BehaviorSubject(null));P(this,"editingLink$",this._editingLink$.asObservable());P(this,"showingLink$",this._showingLink$.asObservable());P(this,"_editPopup",null);P(this,"_infoPopup",null);this._docCanvasPopupManagerService=n,this._textSelectionManagerService=i,this._univerInstanceService=t,this.disposeWithMe(()=>{this._editingLink$.complete(),this._showingLink$.complete()})}get editing(){return this._editingLink$.value}get showing(){return this._showingLink$.value}showEditPopup(n,i){this._editPopup&&this._editPopup.dispose(),this._editingLink$.next(i);const t=this._textSelectionManagerService.getTextRanges({unitId:n,subUnitId:n});let r=t==null?void 0:t[t.length-1];if(i){const{segmentId:s,segmentPage:c,startIndex:d,endIndex:v}=i;r={collapsed:!1,startOffset:d,endOffset:v+1,segmentId:s,segmentPage:c},this._textSelectionManagerService.replaceDocRanges([{startOffset:d,endOffset:v+1}])}return r?(this._editPopup=this._docCanvasPopupManagerService.attachPopupToRange(r,{componentKey:N.componentKey,direction:"bottom"},n),this._editPopup):null}hideEditPopup(){var n;this._editingLink$.next(null),(n=this._editPopup)==null||n.dispose()}showInfoPopup(n){var h,m,C,I,l,f;const{linkId:i,unitId:t,segmentId:r,segmentPage:s,startIndex:c,endIndex:d}=n;if(!(((h=this.showing)==null?void 0:h.linkId)===i&&((m=this.showing)==null?void 0:m.unitId)===t&&((C=this.showing)==null?void 0:C.segmentId)===r&&((I=this.showing)==null?void 0:I.segmentPage)===s&&((l=this.showing)==null?void 0:l.startIndex)===c&&((f=this.showing)==null?void 0:f.endIndex)===d||(this._infoPopup&&this._infoPopup.dispose(),!this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_DOC))))return this._showingLink$.next({unitId:t,linkId:i,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:j.componentKey,direction:"top-center",multipleDirection:"top",onClickOutside:()=>{this.hideInfoPopup()}},t),this._infoPopup}hideInfoPopup(){var n;this._showingLink$.next(null),(n=this._infoPopup)==null||n.dispose()}};L=He([q(0,o.Inject(b.DocCanvasPopManagerService)),q(1,o.Inject(y.DocSelectionManagerService)),q(2,o.IUniverInstanceService)],L);var $e=Object.getOwnPropertyDescriptor,Be=(e,n,i,t)=>{for(var r=t>1?void 0:t?$e(n,i):n,s=e.length-1,c;s>=0;s--)(c=e[s])&&(r=c(r)||r);return r},Z=(e,n)=>(i,t)=>n(i,t,e);let H=class extends o.Disposable{constructor(e,n,i){super(),this._commandService=e,this._univerInstanceService=n,this._docHyperLinkService=i,this._initSelectionChange()}_initSelectionChange(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var n,i,t;if(e.id===y.SetTextSelectionsOperation.id){const r=e.params,{unitId:s,ranges:c,segmentId:d}=r,v=this._univerInstanceService.getUnit(s,o.UniverInstanceType.UNIVER_DOC),h=c[0];if(h&&v){const{startOffset:m,endOffset:C,collapsed:I,segmentPage:l}=h,f=(i=(n=v.getSelfOrHeaderFooterModel(d))==null?void 0:n.getBody())==null?void 0:i.customRanges;if(I){const O=(t=f==null?void 0:f.findIndex(g=>g.startIndex<m&&g.endIndex>C-1))!=null?t:-1;if(O>-1){const g=f[O];this._docHyperLinkService.showInfoPopup({unitId:s,linkId:g.rangeId,segmentId:d,segmentPage:l,startIndex:g.startIndex,endIndex:g.endIndex});return}}else if(f==null?void 0:f.find(g=>g.startIndex<=m&&g.endIndex>=C-1))return}this._docHyperLinkService.hideInfoPopup(),this._docHyperLinkService.hideEditPopup()}}))}};H=Be([Z(0,o.ICommandService),Z(1,o.IUniverInstanceService),Z(2,o.Inject(L))],H);var Ke=Object.getOwnPropertyDescriptor,Ae=(e,n,i,t)=>{for(var r=t>1?void 0:t?Ke(n,i):n,s=e.length-1,c;s>=0;s--)(c=e[s])&&(r=c(r)||r);return r},w=(e,n)=>(i,t)=>n(i,t,e);let W=class extends o.Disposable{constructor(e,n,i,t,r,s){super(),this._context=e,this._docEventManagerService=n,this._commandService=i,this._hyperLinkPopupService=t,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(e=>{var r;const n=e.find(s=>s.range.rangeType===o.CustomRangeType.HYPERLINK),i=this._docSelectionManagerService.getTextRanges(),t=i==null?void 0:i[0].segmentId;if(((r=n==null?void 0:n.segmentId)!=null?r:"")!==t){this._hideInfoPopup();return}n?this._commandService.executeCommand(Y.id,{unitId:this._context.unitId,linkId:n.range.rangeId,segmentId:n.segmentId,segmentPage:n.segmentPageIndex,rangeId:n.range.rangeId,startIndex:n.range.startIndex,endIndex:n.range.endIndex}):this._hideInfoPopup()}))}_initClick(){this.disposeWithMe(this._docEventManagerService.clickCustomRanges$.subscribe(e=>{const n=e.range;n&&this._commandService.executeCommand(le.id,{unitId:this._context.unitId,linkId:n.rangeId,segmentId:e.segmentId})}))}};W=Ae([w(1,o.Inject(b.DocEventManagerService)),w(2,o.ICommandService),w(3,o.Inject(L)),w(4,o.Inject(y.DocSkeletonManagerService)),w(5,o.Inject(y.DocSelectionManagerService))],W);var Fe=Object.getOwnPropertyDescriptor,Ve=(e,n,i,t)=>{for(var r=t>1?void 0:t?Fe(n,i):n,s=e.length-1,c;s>=0;s--)(c=e[s])&&(r=c(r)||r);return r},G=(e,n)=>(i,t)=>n(i,t,e);let z=class extends o.Disposable{constructor(e,n,i,t){super(),this._context=e,this._docInterceptorService=n,this._hyperLinkService=i,this._docRenderController=t,this._init(),this._initReRender()}_init(){this._docInterceptorService.intercept(y.DOC_INTERCEPTOR_POINT.CUSTOM_RANGE,{handler:(e,n,i)=>{if(!e)return i(e);const{unitId:t,index:r}=n,s=this._hyperLinkService.showing;if(!s)return i({...e,active:!1});const{linkId:c,unitId:d,startIndex:v,endIndex:h}=s,m=d===t&&e.rangeId===c&&r>=v&&r<=h;return i({...e,active:m})}})}_initReRender(){this.disposeWithMe(this._hyperLinkService.showingLink$.pipe(E.distinctUntilChanged((e,n)=>(e==null?void 0:e.linkId)===(n==null?void 0:n.linkId)&&(e==null?void 0:e.unitId)===(n==null?void 0:n.unitId)&&(e==null?void 0:e.startIndex)===(n==null?void 0:n.startIndex)),E.pairwise()).subscribe(([e,n])=>{n?n.unitId===this._context.unitId&&this._docRenderController.reRender(n.unitId):e&&e.unitId===this._context.unitId&&this._docRenderController.reRender(e.unitId)}))}};z=Ve([G(1,o.Inject(y.DocInterceptorService)),G(2,o.Inject(L)),G(3,o.Inject(b.DocRenderController))],z);const ue="doc-hyper-link-icon";function pe(e){return{id:M.id,type:p.MenuItemType.BUTTON,icon:ue,title:"docLink.menu.tooltip",tooltip:"docLink.menu.tooltip",hidden$:p.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_DOC),disabled$:new E.Observable(function(n){const t=e.get(y.DocSelectionManagerService).textSelection$.pipe(E.debounceTime(16)).subscribe(()=>{n.next(ae(e))});return()=>{t.unsubscribe()}})}}const Ye={id:M.id,binding:p.MetaKeys.CTRL_COMMAND|p.KeyCode.K,description:"docLink.menu.tooltip",preconditions:b.whenDocAndEditorFocused},qe={[p.RibbonStartGroup.OTHERS]:{[M.id]:{order:0,menuItemFactory:pe}},[p.ContextMenuPosition.MAIN_AREA]:{[p.ContextMenuGroup.DATA]:{[M.id]:{order:0,menuItemFactory:pe}}}};var Ze=Object.getOwnPropertyDescriptor,We=(e,n,i,t)=>{for(var r=t>1?void 0:t?Ze(n,i):n,s=e.length-1,c;s>=0;s--)(c=e[s])&&(r=c(r)||r);return r},$=(e,n)=>(i,t)=>n(i,t,e);let B=class extends o.Disposable{constructor(e,n,i,t){super(),this._componentManager=e,this._commandService=n,this._menuManagerService=i,this._shortcutService=t,this._initComponents(),this._initCommands(),this._initMenus(),this._initShortcut()}_initComponents(){[[N,N.componentKey],[j,j.componentKey],[V,ue]].forEach(([e,n])=>{this._componentManager.register(n,e)})}_initCommands(){[ee,ne,de,M,Y,le].forEach(e=>{this._commandService.registerCommand(e)})}_initShortcut(){[Ye].forEach(e=>{this._shortcutService.registerShortcut(e)})}_initMenus(){this._menuManagerService.mergeMenu(qe)}};B=We([$(0,o.Inject(p.ComponentManager)),$(1,o.ICommandService),$(2,p.IMenuManagerService),$(3,p.IShortcutService)],B);const Ge="DOC_HYPER_LINK_UI_PLUGIN";var ze=Object.defineProperty,Je=Object.getOwnPropertyDescriptor,Qe=(e,n,i)=>n in e?ze(e,n,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[n]=i,Xe=(e,n,i,t)=>{for(var r=t>1?void 0:t?Je(n,i):n,s=e.length-1,c;s>=0;s--)(c=e[s])&&(r=c(r)||r);return r},J=(e,n)=>(i,t)=>n(i,t,e),ge=(e,n,i)=>Qe(e,typeof n!="symbol"?n+"":n,i);a.UniverDocsHyperLinkUIPlugin=class extends o.Plugin{constructor(n=X,i,t,r){super(),this._config=n,this._injector=i,this._renderManagerSrv=t,this._configService=r;const{menu:s,...c}=o.merge({},X,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig(Oe,c)}onStarting(){[[L],[B],[H]].forEach(i=>{this._injector.add(i)}),this._injector.get(B)}onReady(){this._injector.get(H)}onRendered(){this._initRenderModule()}_initRenderModule(){[[z],[W]].forEach(n=>{this._renderManagerSrv.registerRenderModule(o.UniverInstanceType.UNIVER_DOC,n)})}},ge(a.UniverDocsHyperLinkUIPlugin,"pluginName",Ge),ge(a.UniverDocsHyperLinkUIPlugin,"type",o.UniverInstanceType.UNIVER_DOC),a.UniverDocsHyperLinkUIPlugin=Xe([o.DependentOn(U.UniverDocsHyperLinkPlugin),J(1,o.Inject(o.Injector)),J(2,Le.IRenderManagerService),J(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,U,Se,y,b,E,u,S,p,_){"use strict";var Qe=Object.defineProperty;var Xe=(a,o,U)=>o in a?Qe(a,o,{enumerable:!0,configurable:!0,writable:!0,value:U}):a[o]=U;var P=(a,o,U)=>Xe(a,typeof o!="symbol"?o+"":o,U);const ke="docs-hyper-link-ui.config",X={},ee={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=y.addCustomRangeBySelectionFactory(n,{rangeId:c,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:t},unitId:i,selections:r});return d?s.syncExecuteCommand(d.id,d.params):!1}},ne={id:"docs.command.update-hyper-link",type:o.CommandType.COMMAND,handler(n,e){var f;if(!e)return!1;const{unitId:t,payload:i,segmentId:r,linkId:s}=e,c=n.get(o.ICommandService),d=n.get(o.IUniverInstanceService),h=n.get(y.DocSelectionManagerService).getActiveTextRange(),m=d.getUnit(t,o.UniverInstanceType.UNIVER_DOC);if(!h||!m)return!1;const I=(f=o.getBodySlice(m.getSelfOrHeaderFooterModel(r).getBody(),h.startOffset,h.endOffset).textRuns)==null?void 0:f[0];I&&(I.ed=e.label.length+1);const l=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:I?[I]:void 0},selection:{startOffset:h.startOffset,endOffset:h.endOffset,collapsed:!1,segmentId:r}});return l?c.syncExecuteCommand(l.id,l.params):!1}},R={docsLinkEdit:"univer-docs-link-edit",docsLinkEditButtons:"univer-docs-link-edit-buttons",docsLinkEditButton:"univer-docs-link-edit-button"};function Le(n){return/^[a-zA-Z]+:\/\//.test(n)}function Oe(n){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(n)}function xe(n){return Le(n)?n:Oe(n)?`mailto://${n}`:`https://${n}`}const N=()=>{const n=p.useDependency(L),e=p.useDependency(o.LocaleService),t=p.useObservable(n.editingLink$),i=p.useDependency(o.ICommandService),r=p.useDependency(o.IUniverInstanceService),s=p.useDependency(y.DocSelectionManagerService),[c,d]=_.useState(""),[v,h]=_.useState(""),[m,C]=_.useState(!1),I=o.Tools.isLegalUrl(c),l=t?r.getUnit(t.unitId,o.UniverInstanceType.UNIVER_DOC):r.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC);_.useEffect(()=>{var ge,ve,he,fe,Ie,me,_e,Ce,ye;const g=s.getActiveTextRange();if(!g)return;if(t){const A=(ge=l==null?void 0:l.getSelfOrHeaderFooterModel(t.segmentId))==null?void 0:ge.getBody(),F=(ve=A==null?void 0:A.customRanges)==null?void 0:ve.find(Q=>(t==null?void 0:t.linkId)===Q.rangeId&&Q.startIndex===t.startIndex&&Q.endIndex===t.endIndex);l&&F&&(d((fe=(he=F.properties)==null?void 0:he.url)!=null?fe:""),h(o.BuildTextUtils.transform.getPlainText(o.getBodySlice(A,F.startIndex,F.endIndex+1).dataStream)));return}const x=(Ie=l==null?void 0:l.getSelfOrHeaderFooterModel(g.segmentId))==null?void 0:Ie.getBody(),pe=x?g:null,K=pe&&((_e=o.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(pe,(me=x==null?void 0:x.customRanges)!=null?me:[]))==null?void 0:_e[0]);l&&K&&d((ye=(Ce=K==null?void 0:K.properties)==null?void 0:Ce.url)!=null?ye:"")},[l,t,s,r]);const f=()=>{n.hideEditPopup()},O=()=>{if(C(!0),!I||!l)return;const g=xe(c);if(!t)i.executeCommand(ee.id,{unitId:l.getUnitId(),payload:g});else{if(!v)return;i.executeCommand(ne.id,{unitId:l.getUnitId(),payload:g,linkId:t.linkId,label:v,segmentId:t.segmentId})}n.hideEditPopup()};if(l)return u.jsxs("div",{className:R.docsLinkEdit,children:[u.jsxs("div",{children:[t?u.jsx(S.FormLayout,{label:e.t("docLink.edit.label"),error:m&&!v?e.t("docLink.edit.labelError"):"",children:u.jsx(S.Input,{value:v,onChange:h,autoFocus:!0,onKeyDown:g=>{g.keyCode===p.KeyCode.ENTER&&O()}})}):null,u.jsx(S.FormLayout,{label:e.t("docLink.edit.address"),error:m&&!I?e.t("docLink.edit.addressError"):"",children:u.jsx(S.Input,{value:c,onChange:d,autoFocus:!0,onKeyDown:g=>{g.keyCode===p.KeyCode.ENTER&&O()}})})]}),u.jsxs("div",{className:R.docsLinkEditButtons,children:[u.jsx(S.Button,{className:R.docsLinkEditButton,onClick:f,children:e.t("docLink.edit.cancel")}),u.jsx(S.Button,{disabled:!c,className:R.docsLinkEditButton,type:"primary",onClick:O,children:e.t("docLink.edit.confirm")})]})]})};N.componentKey="docs-hyper-link-edit";var k=function(){return k=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},k.apply(this,arguments)},De=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},T=_.forwardRef(function(n,e){var t=n.icon,i=n.id,r=n.className,s=n.extend,c=De(n,["icon","id","className","extend"]),d="univerjs-icon univerjs-icon-".concat(i," ").concat(r||"").trim(),v=_.useRef("_".concat(Ee()));return te(t,"".concat(i),{defIds:t.defIds,idSuffix:v.current},k({ref:e,className:d},c),s)});function te(n,e,t,i,r){return _.createElement(n.tag,k(k({key:e},Pe(n,t,r)),i),(Ue(n,t).children||[]).map(function(s,c){return te(s,"".concat(e,"-").concat(n.tag,"-").concat(c),t,void 0,r)}))}function Pe(n,e,t){var i=k({},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 Ue(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)?k(k({},n),{children:n.children.map(function(r){return typeof r.attrs.id=="string"&&i&&i.indexOf(r.attrs.id)>-1?k(k({},r),{attrs:k(k({},r.attrs),{id:r.attrs.id+e.idSuffix})}):r})}):n}function Ee(){return Math.random().toString(36).substring(2,8)}T.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"}}]},ie=_.forwardRef(function(n,e){return _.createElement(T,Object.assign({},n,{id:"copy-single",ref:e,icon:Me}))});ie.displayName="CopySingle";var Te={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"}}]},V=_.forwardRef(function(n,e){return _.createElement(T,Object.assign({},n,{id:"link-single",ref:e,icon:Te}))});V.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"}}]},re=_.forwardRef(function(n,e){return _.createElement(T,Object.assign({},n,{id:"unlink-single",ref:e,icon:we}))});re.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"}}]},oe=_.forwardRef(function(n,e){return _.createElement(T,Object.assign({},n,{id:"write-single",ref:e,icon:be}))});oe.displayName="WriteSingle";const se={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}},ce=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)},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(ce(n)&&!t)return!1;const r=n.get(L),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(L);return e?(t.showInfoPopup(e),!0):(t.hideInfoPopup(),!0)}},de={type:o.CommandType.OPERATION,id:"doc.operation.click-hyper-link",handler(n,e){var h,m,C;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(),v=(C=(m=(h=d==null?void 0:d.customRanges)==null?void 0:h.find(I=>I.rangeId===i&&I.rangeType===o.CustomRangeType.HYPERLINK))==null?void 0:m.properties)==null?void 0:C.url;return v&&window.open(v,"_blank","noopener noreferrer"),!0}},D={docLink:"univer-doc-link",docLinkType:"univer-doc-link-type",docLinkContent:"univer-doc-link-content",docLinkUrl:"univer-doc-link-url",docLinkOperations:"univer-doc-link-operations",docLinkOperation:"univer-doc-link-operation"},j=()=>{var O,g;const n=p.useDependency(L),e=p.useDependency(o.ICommandService),t=p.useDependency(p.IMessageService),i=p.useDependency(o.LocaleService),r=p.useObservable(n.showingLink$),s=p.useDependency(o.IUniverInstanceService);if(!r)return null;const{unitId:c,linkId:d,segmentId:v,startIndex:h,endIndex:m}=r,C=s.getUnit(c,o.UniverInstanceType.UNIVER_DOC),I=C==null?void 0:C.getSelfOrHeaderFooterModel(v).getBody(),l=(O=I==null?void 0:I.customRanges)==null?void 0:O.find(x=>x.rangeId===d&&x.rangeType===o.CustomRangeType.HYPERLINK&&x.startIndex===h&&x.endIndex===m);if(!l)return null;const f=(g=l.properties)==null?void 0:g.url;return u.jsxs("div",{className:D.docLink,onClick:()=>{n.hideInfoPopup()},children:[u.jsxs("div",{className:S.clsx(D.docLinkContent),onClick:()=>window.open(f),children:[u.jsx("div",{className:D.docLinkType,children:u.jsx(V,{})}),u.jsx(S.Tooltip,{showIfEllipsis:!0,title:f,children:u.jsx("span",{className:D.docLinkUrl,children:f})})]}),u.jsxs("div",{className:D.docLinkOperations,children:[u.jsx("div",{className:S.clsx(D.docLinkOperation),onClick:()=>{navigator.clipboard.writeText(f),t.show({content:i.t("docLink.info.coped"),type:S.MessageType.Info})},children:u.jsx(S.Tooltip,{placement:"bottom",title:i.t("docLink.info.copy"),children:u.jsx(ie,{})})}),u.jsx("div",{className:D.docLinkOperation,onClick:()=>{e.executeCommand(M.id,{link:r})},children:u.jsx(S.Tooltip,{placement:"bottom",title:i.t("docLink.info.edit"),children:u.jsx(oe,{})})}),u.jsx("div",{className:D.docLinkOperation,onClick:()=>{e.executeCommand(se.id,{unitId:c,linkId:l.rangeId,segmentId:v})},children:u.jsx(S.Tooltip,{placement:"bottom",title:i.t("docLink.info.cancel"),children:u.jsx(re,{})})})]})]})};j.componentKey="univer.doc.link-info-popup";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},q=(n,e)=>(t,i)=>e(t,i,n);let L=class extends o.Disposable{constructor(e,t,i){super();P(this,"_editingLink$",new E.BehaviorSubject(null));P(this,"_showingLink$",new E.BehaviorSubject(null));P(this,"editingLink$",this._editingLink$.asObservable());P(this,"showingLink$",this._showingLink$.asObservable());P(this,"_editPopup",null);P(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:v}=t;r={collapsed:!1,startOffset:d,endOffset:v+1,segmentId:s,segmentPage:c},this._textSelectionManagerService.replaceDocRanges([{startOffset:d,endOffset:v+1}])}return r?(this._editPopup=this._docCanvasPopupManagerService.attachPopupToRange(r,{componentKey:N.componentKey,direction:"bottom"},e),this._editPopup):null}hideEditPopup(){var e;this._editingLink$.next(null),(e=this._editPopup)==null||e.dispose()}showInfoPopup(e){var h,m,C,I,l,f;const{linkId:t,unitId:i,segmentId:r,segmentPage:s,startIndex:c,endIndex:d}=e;if(!(((h=this.showing)==null?void 0:h.linkId)===t&&((m=this.showing)==null?void 0:m.unitId)===i&&((C=this.showing)==null?void 0:C.segmentId)===r&&((I=this.showing)==null?void 0:I.segmentPage)===s&&((l=this.showing)==null?void 0:l.startIndex)===c&&((f=this.showing)==null?void 0:f.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:j.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()}};L=Ne([q(0,o.Inject(b.DocCanvasPopManagerService)),q(1,o.Inject(y.DocSelectionManagerService)),q(2,o.IUniverInstanceService)],L);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},Z=(n,e)=>(t,i)=>e(t,i,n);let H=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:d}=r,v=this._univerInstanceService.getUnit(s,o.UniverInstanceType.UNIVER_DOC),h=c[0];if(h&&v){const{startOffset:m,endOffset:C,collapsed:I,segmentPage:l}=h,f=(t=(e=v.getSelfOrHeaderFooterModel(d))==null?void 0:e.getBody())==null?void 0:t.customRanges;if(I){const O=(i=f==null?void 0:f.findIndex(g=>g.startIndex<m&&g.endIndex>C-1))!=null?i:-1;if(O>-1){const g=f[O];this._docHyperLinkService.showInfoPopup({unitId:s,linkId:g.rangeId,segmentId:d,segmentPage:l,startIndex:g.startIndex,endIndex:g.endIndex});return}}else if(f==null?void 0:f.find(g=>g.startIndex<=m&&g.endIndex>=C-1))return}this._docHyperLinkService.hideInfoPopup(),this._docHyperLinkService.hideEditPopup()}}))}};H=He([Z(0,o.ICommandService),Z(1,o.IUniverInstanceService),Z(2,o.Inject(L))],H);var $e=Object.getOwnPropertyDescriptor,Be=(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},w=(n,e)=>(t,i)=>e(t,i,n);let W=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(de.id,{unitId:this._context.unitId,linkId:e.rangeId,segmentId:n.segmentId})}))}};W=Be([w(1,o.Inject(b.DocEventManagerService)),w(2,o.ICommandService),w(3,o.Inject(L)),w(4,o.Inject(y.DocSkeletonManagerService)),w(5,o.Inject(y.DocSelectionManagerService))],W);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},G=(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:d,startIndex:v,endIndex:h}=s,m=d===i&&n.rangeId===c&&r>=v&&r<=h;return t({...n,active:m})}})}_initReRender(){this.disposeWithMe(this._hyperLinkService.showingLink$.pipe(E.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)),E.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([G(1,o.Inject(y.DocInterceptorService)),G(2,o.Inject(L)),G(3,o.Inject(b.DocRenderController))],z);const ae="doc-hyper-link-icon";function le(n){return{id:M.id,type:p.MenuItemType.BUTTON,icon:ae,title:"docLink.menu.tooltip",tooltip:"docLink.menu.tooltip",hidden$:p.getMenuHiddenObservable(n,o.UniverInstanceType.UNIVER_DOC),disabled$:new E.Observable(function(e){const i=n.get(y.DocSelectionManagerService).textSelection$.pipe(E.debounceTime(16)).subscribe(()=>{e.next(ce(n))});return()=>{i.unsubscribe()}})}}const Fe={id:M.id,binding:p.MetaKeys.CTRL_COMMAND|p.KeyCode.K,description:"docLink.menu.tooltip",preconditions:b.whenDocAndEditorFocused},Ve={[p.RibbonStartGroup.OTHERS]:{[M.id]:{order:0,menuItemFactory:le}},[p.ContextMenuPosition.MAIN_AREA]:{[p.ContextMenuGroup.DATA]:{[M.id]:{order:0,menuItemFactory:le}}}};var Ye=Object.getOwnPropertyDescriptor,qe=(n,e,t,i)=>{for(var r=i>1?void 0:i?Ye(e,t):e,s=n.length-1,c;s>=0;s--)(c=n[s])&&(r=c(r)||r);return r},$=(n,e)=>(t,i)=>e(t,i,n);let B=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(){[[N,N.componentKey],[j,j.componentKey],[V,ae]].forEach(([n,e])=>{this._componentManager.register(e,n)})}_initCommands(){[ee,ne,se,M,Y,de].forEach(n=>{this._commandService.registerCommand(n)})}_initShortcut(){[Fe].forEach(n=>{this._shortcutService.registerShortcut(n)})}_initMenus(){this._menuManagerService.mergeMenu(Ve)}};B=qe([$(0,o.Inject(p.ComponentManager)),$(1,o.ICommandService),$(2,p.IMenuManagerService),$(3,p.IShortcutService)],B);const Ze="DOC_HYPER_LINK_UI_PLUGIN";var We=Object.defineProperty,Ge=Object.getOwnPropertyDescriptor,ze=(n,e,t)=>e in n?We(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,Je=(n,e,t,i)=>{for(var r=i>1?void 0:i?Ge(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),ue=(n,e,t)=>ze(n,typeof e!="symbol"?e+"":e,t);a.UniverDocsHyperLinkUIPlugin=class extends o.Plugin{constructor(e=X,t,i,r){super(),this._config=e,this._injector=t,this._renderManagerSrv=i,this._configService=r;const{menu:s,...c}=o.merge({},X,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig(ke,c)}onStarting(){[[L],[B],[H]].forEach(t=>{this._injector.add(t)}),this._injector.get(B)}onReady(){this._injector.get(H)}onRendered(){this._initRenderModule()}_initRenderModule(){[[z],[W]].forEach(e=>{this._renderManagerSrv.registerRenderModule(o.UniverInstanceType.UNIVER_DOC,e)})}},ue(a.UniverDocsHyperLinkUIPlugin,"pluginName",Ze),ue(a.UniverDocsHyperLinkUIPlugin,"type",o.UniverInstanceType.UNIVER_DOC),a.UniverDocsHyperLinkUIPlugin=Je([o.DependentOn(U.UniverDocsHyperLinkPlugin),J(1,o.Inject(o.Injector)),J(2,Se.IRenderManagerService),J(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.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Univer thread comment plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -53,14 +53,13 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@univerjs/icons": "^0.2.20",
|
|
56
|
-
"
|
|
57
|
-
"@univerjs/
|
|
58
|
-
"@univerjs/
|
|
59
|
-
"@univerjs/
|
|
60
|
-
"@univerjs/docs-
|
|
61
|
-
"@univerjs/
|
|
62
|
-
"@univerjs/
|
|
63
|
-
"@univerjs/ui": "0.6.1"
|
|
56
|
+
"@univerjs/core": "0.6.2",
|
|
57
|
+
"@univerjs/design": "0.6.2",
|
|
58
|
+
"@univerjs/docs": "0.6.2",
|
|
59
|
+
"@univerjs/docs-hyper-link": "0.6.2",
|
|
60
|
+
"@univerjs/docs-ui": "0.6.2",
|
|
61
|
+
"@univerjs/engine-render": "0.6.2",
|
|
62
|
+
"@univerjs/ui": "0.6.2"
|
|
64
63
|
},
|
|
65
64
|
"devDependencies": {
|
|
66
65
|
"postcss": "^8.5.3",
|
|
@@ -68,9 +67,9 @@
|
|
|
68
67
|
"rxjs": "^7.8.1",
|
|
69
68
|
"tailwindcss": "^3.4.17",
|
|
70
69
|
"typescript": "^5.7.3",
|
|
71
|
-
"vite": "^6.
|
|
72
|
-
"vitest": "^3.0.
|
|
73
|
-
"@univerjs-infra/shared": "0.6.
|
|
70
|
+
"vite": "^6.2.0",
|
|
71
|
+
"vitest": "^3.0.7",
|
|
72
|
+
"@univerjs-infra/shared": "0.6.2"
|
|
74
73
|
},
|
|
75
74
|
"scripts": {
|
|
76
75
|
"test": "vitest run",
|