@univerjs/preset-sheets-hyper-link 0.6.0-alpha.0 → 0.6.0-nightly.202502131606
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/umd/index.js +3 -3
- package/package.json +4 -4
package/lib/umd/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
// @univerjs/sheets-hyper-link/index
|
|
2
|
-
(function(p,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("rxjs"),require("@univerjs/sheets"),require("@univerjs/engine-formula"),require("@univerjs/docs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","@univerjs/sheets","@univerjs/engine-formula","@univerjs/docs"],o):(p=typeof globalThis<"u"?globalThis:p||self,o(p.UniverSheetsHyperLink={},p.UniverCore,p.rxjs,p.UniverSheets,p.UniverEngineFormula,p.UniverDocs))})(this,function(p,o,T,m,C,x){"use strict";var Qe=Object.defineProperty;var et=(p,o,T)=>o in p?Qe(p,o,{enumerable:!0,configurable:!0,writable:!0,value:T}):p[o]=T;var L=(p,o,T)=>et(p,typeof o!="symbol"?o+"":o,T);var Re=Object.defineProperty,Me=Object.getOwnPropertyDescriptor,Ce=(r,t,e,n)=>{for(var i=n>1?void 0:n?Me(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Re(t,e,i),i},Ue=(r,t)=>(e,n)=>t(e,n,r);p.HyperLinkModel=class extends o.Disposable{constructor(e){super();L(this,"_linkUpdate$",new T.Subject);L(this,"linkUpdate$",this._linkUpdate$.asObservable());L(this,"_linkMap",new Map);L(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let i=this._linkMap.get(e);i||(i=new Map,this._linkMap.set(e,i));let s=i.get(n);s||(s=new o.ObjectMatrix,i.set(n,s));let a=this._linkPositionMap.get(e);a||(a=new Map,this._linkPositionMap.set(e,a));let d=a.get(n);return d||(d=new Map,a.set(n,d)),{matrix:s,positionMap:d}}addHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n);return s.setValue(i.row,i.column,i),a.set(i.id,{row:i.row,column:i.column,link:i}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:i,type:"add"}),!0}updateHyperLink(e,n,i,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;const u=d.getValue(l.row,l.column);return u&&(Object.assign(u,s),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:u.display,payload:u.payload},id:i,type:"update",silent:a})),!0}updateHyperLinkRef(e,n,i,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;let u=d.getValue(l.row,l.column);return!u||u.id!==i?u=l.link:d.realDeleteValue(l.row,l.column),Object.assign(u,s),c.set(i,{...s,link:u}),d.setValue(s.row,s.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:i,type:"updateRef",silent:a}),!0}removeHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(i);if(!d)return!1;a.delete(i);const c=s.getValue(d.row,d.column);return c&&c.id===i&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(i);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,i,s){const{matrix:a}=this._ensureMap(e,n);return a.getValue(i,s)}getHyperLinkByLocationSync(e,n,i,s){var g,f,_,h,y;const{matrix:a}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,o.UniverInstanceType.UNIVER_SHEET),c=(g=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:g.getCellRaw(i,s),l=((y=(h=c==null?void 0:c.v)!=null?h:(_=(f=c==null?void 0:c.p)==null?void 0:f.body)==null?void 0:_.dataStream.slice(0,-2))!=null?y:"").toString(),u=a.getValue(i,s);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:i}=this._ensureMap(e,n),s=[];return i.forValue((a,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(i=>{const s=this.getSubUnit(e,i);return{unitId:e,subUnitId:i,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}},p.HyperLinkModel=Ce([Ue(0,o.IUniverInstanceService)],p.HyperLinkModel);var w=(r=>(r.SHEET="gid",r.RANGE="range",r.DEFINE_NAME="rangeid",r.INVALID="invalid",r.URL="url",r))(w||{});const Le="sheets-hyper-link.config",ae={},E={type:o.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,link:s}=t;return e.addHyperLink(n,i,s)}},k={type:o.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:s}=t;return e.removeHyperLink(n,i,s)}},W={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,payload:s,id:a}=t;return e.updateHyperLink(n,i,a,s,!1)}},B={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:s,row:a,column:d,silent:c}=t;return e.updateHyperLinkRef(n,i,s,{row:a,column:d},c)}},K={type:o.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(r,t){var _,h,y;if(!t)return!1;const{unitId:e,subUnitId:n,row:i,col:s,id:a,url:d}=t,c=r.get(o.IUniverInstanceService),l=m.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:u}=l,g=u.getCellRaw(i,s),f=(y=(h=(_=g==null?void 0:g.p)==null?void 0:_.body)==null?void 0:h.customRanges)==null?void 0:y.find(S=>S.rangeType===o.CustomRangeType.HYPERLINK&&S.rangeId===a);return f&&(f.properties.url=d),!0}},oe="SHEET_HYPER_LINK_PLUGIN",$="err";var we=Object.defineProperty,Ee=Object.getOwnPropertyDescriptor,ke=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ee(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&we(t,e,i),i},z=(r,t)=>(e,n)=>t(e,n,r);let G=class extends o.Disposable{constructor(t,e,n,i){super();L(this,"_disposableMap",new Map);L(this,"_watchDisposableMap",new Map);L(this,"_rangeDisableMap",new Map);L(this,"_rangeWatcherMap",new Map);L(this,"_handlePositionChange",(t,e,n,i,s)=>{const a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return i?{redos:[{id:B.id,params:{unitId:t,subUnitId:e,id:n.id,row:i.startRow,column:i.startColumn,silent:s}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,id:n.id,row:a.startRow,column:a.startColumn,silent:s}}]}:{redos:[{id:k.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:E.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=i,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},a=d=>{const c=m.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===s.startColumn&&l.startRow===s.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(i,this._refRangeService.registerRefRange(s,a,t,e))}_watchPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(t,e,s,(a,d)=>{const{redos:c}=this._handlePositionChange(t,e,n,d,!0);o.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(t){const e=this._disposableMap.get(t);e==null||e.dispose(),this._disposableMap.delete(t)}_unwatchPosition(t){const e=this._watchDisposableMap.get(t);e==null||e.dispose(),this._watchDisposableMap.delete(t)}_registerRange(t,e,n,i=!1){var s,a,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(s=c.get("gid"))!=null?s:"",range:(a=c.get("range"))!=null?a:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const u=l.gid,g=C.deserializeRangeWithSheet(l.range).range;if(o.isValidRange(g)&&l.range!==$){const f=_=>{const h=m.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(g,_,{selectionManagerService:this._selectionManagerService});return h&&C.serializeRange(h)===C.serializeRange(g)?{redos:[],undos:[]}:{redos:[{id:W.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`}}}],undos:[{id:W.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(g,f,t,u)),i||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,u,g,(_,h)=>{this._hyperLinkModel.updateHyperLink(t,u,e,{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`},!0)},!0))}}}}_unregisterRange(t){const e=this._rangeDisableMap.get(t);e==null||e.dispose(),this._rangeDisableMap.delete(t)}_unwatchRange(t){const e=this._rangeWatcherMap.get(t);e==null||e.dispose(),this._rangeWatcherMap.delete(t)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(n=>{const{unitId:i,subUnitId:s,links:a}=n;a.forEach(d=>{this._registerPosition(i,s,d),this._watchPosition(i,s,d),this._registerRange(i,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:i,silent:s}=t,a=this._hyperLinkModel.getHyperLink(e,n,i);if(!a)return;this._unregisterPosition(i),this._registerPosition(e,n,a),s||(this._unwatchPosition(i),this._watchPosition(e,n,a));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:i}=n;i.forEach(s=>{this._unregisterPosition(s.id),this._unwatchPosition(s.id),this._unregisterRange(s.id),this._unwatchRange(s.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(o.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};G=ke([z(0,o.Inject(m.RefRangeService)),z(1,o.Inject(p.HyperLinkModel)),z(2,o.Inject(m.SheetsSelectionsService)),z(3,o.ICommandService)],G);var Pe=Object.defineProperty,be=Object.getOwnPropertyDescriptor,Te=(r,t,e,n)=>{for(var i=n>1?void 0:n?be(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Pe(t,e,i),i},te=(r,t)=>(e,n)=>t(e,n,r);let Y=class extends o.Disposable{constructor(r,t,e){super(),this._sheetInterceptorService=r,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{var t;if(r.id===m.RemoveSheetCommand.id){const e=r.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const i=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const a=this._hyperLinkModel.getSubUnit(i,s),d=a.map(l=>({id:k.id,params:{unitId:i,subUnitId:s,id:l.id}})),c=a.map(l=>({id:E.id,params:{unitId:i,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};Y=Te([te(0,o.Inject(m.SheetInterceptorService)),te(1,o.IUniverInstanceService),te(2,o.Inject(p.HyperLinkModel))],Y);var He=Object.defineProperty,Ne=Object.getOwnPropertyDescriptor,Oe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ne(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&He(t,e,i),i},ne=(r,t)=>(e,n)=>t(e,n,r);let q=class extends o.Disposable{constructor(t,e,n){super();L(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let i=n.get(e);return i||(i=new o.ObjectMatrix,n.set(e,i)),i}_isLegalRangeUrl(t,e){var i,s,a;const n=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(i=d.get("gid"))!=null?i:"",range:(s=d.get("range"))!=null?s:"",rangeid:(a=d.get("rangeid"))!=null?a:""};if(c.range&&c.gid){const l=c.gid,u=n.getSheetBySheetId(l);if(!u)return null;const g=C.deserializeRangeWithSheet(c.range).range;if(o.isValidRange(g,u)&&c.range!==$)return{range:g,worksheet:u}}}return null}_registerRange(t,e,n,i,s){var d,c,l,u;const a=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(g=>{var f;return g.rangeType===o.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(f=g.properties)==null?void 0:f.url)})){const g=new o.DisposableCollection;let f=!1;(u=(l=s.body)==null?void 0:l.customRanges)==null||u.forEach(_=>{var h;if(_.rangeType===o.CustomRangeType.HYPERLINK){const y=(h=_.properties)==null?void 0:h.url,S=this._isLegalRangeUrl(t,y);if(S){const{range:v,worksheet:U}=S;f=!0,g.add(this._refRangeService.registerRefRange(v,I=>{const R=m.handleDefaultRangeChangeWithEffectRefCommands(v,I);return R&&o.Rectangle.equals(R,v)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:K.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:_.rangeId,url:`#gid=${e}&range=${R?C.serializeRange(R):$}`}}],undos:[{id:K.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:_.rangeId,url:y}}],redos:[]}},U.getUnitId(),U.getSheetId()))}}}),f&&a.setValue(n,i,g)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId(),a=this._enusreMap(n,s);i.getCellMatrix().forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,s,d,c,l.p)})})};this._univerInstanceService.getAllUnitsForType(o.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(e=>{e.type===o.UniverInstanceType.UNIVER_SHEET&&t(e)}))}_initWorkbookUnload(){this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===o.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId();this._enusreMap(n,s).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}})}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===m.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:i,cellValue:s}=e,a=this._enusreMap(n,i);s&&new o.ObjectMatrix(s).forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,i,d,c,l.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===K.id){const e=t.params,{unitId:n,subUnitId:i,row:s,col:a}=e,d=m.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:i}),l=this._enusreMap(n,i).getValue(s,a);if(l&&l.dispose(),d){const{worksheet:u}=d,g=u.getCellRaw(s,a);g&&g.p&&this._registerRange(n,i,s,a,g.p)}}}))}};q=Oe([ne(0,o.ICommandService),ne(1,o.IUniverInstanceService),ne(2,o.Inject(m.RefRangeService))],q);var De=Object.defineProperty,Ve=Object.getOwnPropertyDescriptor,$e=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ve(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&De(t,e,i),i},F=(r,t)=>(e,n)=>t(e,n,r);let J=class extends o.Disposable{constructor(r,t,e,n){super(),this._sheetInterceptorService=r,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.SetRangeValuesCommand.id){const t=r.params,{unitId:e,subUnitId:n}=t,i=[],s=[];return t.cellValue&&new o.ObjectMatrix(t.cellValue).forValue((a,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,a,d);c&&(i.push({id:k.id,params:{unitId:e,subUnitId:n,id:c.id}}),s.push({id:E.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:s,redos:i}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.ClearSelectionContentCommand.id||r.id===m.ClearSelectionAllCommand.id||r.id===m.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),i=m.getSheetCommandTarget(this._univerInstanceService);if(n&&i){const{unitId:s,subUnitId:a}=i;o.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(s,a,d,c);l&&(t.push({id:k.id,params:{unitId:s,subUnitId:a,id:l.id}}),e.push({id:E.id,params:{unitId:s,subUnitId:a,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(m.AFTER_CELL_EDIT,{handler:(r,t,e)=>{if(!r||r.p)return e(r);if(typeof r.v=="string"&&o.Tools.isLegalUrl(r.v)&&r.v[r.v.length-1]!==" "){const{unitId:n,subUnitId:i}=t,s=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET),a=s==null?void 0:s.getSheetBySheetId(i);if(!a)return e(r);const d=a.getBlankCellDocumentModel(r);if(!d.documentModel)return e(r);const c=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:r.v.length,collapsed:!1},body:{dataStream:`${r.v}`,customRanges:[{startIndex:0,endIndex:r.v.length-1,rangeId:o.generateRandomId(),rangeType:o.CustomRangeType.HYPERLINK,properties:{url:r.v}}]},doc:d.documentModel});if(!c)return e(r);const l=d.documentModel.getBody();return o.TextX.apply(l,c.serialize()),e({...r,p:{id:o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:l,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(r)}}))}};J=$e([F(0,o.Inject(m.SheetInterceptorService)),F(1,o.Inject(p.HyperLinkModel)),F(2,o.Inject(m.SheetsSelectionsService)),F(3,o.IUniverInstanceService)],J);var de=(r=>(r[r.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",r[r.UNIVER_DOC=1]="UNIVER_DOC",r[r.UNIVER_SHEET=2]="UNIVER_SHEET",r[r.UNIVER_SLIDE=3]="UNIVER_SLIDE",r[r.UNIVER_PROJECT=4]="UNIVER_PROJECT",r[r.UNRECOGNIZED=-1]="UNRECOGNIZED",r))(de||{}),je=Object.defineProperty,Ae=Object.getOwnPropertyDescriptor,xe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ae(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&je(t,e,i),i},ce=(r,t)=>(e,n)=>t(e,n,r);let X=class extends o.Disposable{constructor(r,t){super(),this._resourceManagerService=r,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const r=e=>{const n=this._hyperLinkModel.getUnit(e),i={};return n?(n.forEach(s=>{i[s.subUnitId]=s.links.map(({display:a,...d})=>d)}),JSON.stringify(i)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:oe,businesses:[de.UNIVER_SHEET],toJson:e=>r(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(i=>{n[i].forEach(a=>{this._hyperLinkModel.addHyperLink(e,i,a)})})}}))}};X=xe([ce(0,o.IResourceManagerService),ce(1,o.Inject(p.HyperLinkModel))],X);const le={type:o.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(r,t){if(!t)return!1;const e=r.get(o.ICommandService),n=r.get(o.IUndoRedoService),i=r.get(o.IUniverInstanceService),s=r.get(p.HyperLinkModel),a=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:u,worksheet:g}=d,{link:f}=t,{payload:_,display:h,row:y,column:S,id:v}=f,U=g.getCell(y,S),I=g.getBlankCellDocumentModel(U),R=I.documentModel.getSnapshot(),M=o.Tools.deepClone(R.body);if(!M)return!1;let P;if(h?P=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:M.dataStream.length-2,collapsed:M.dataStream.length-2===0},body:{dataStream:`${h}`,customRanges:[{startIndex:0,endIndex:h.length-1,rangeType:o.CustomRangeType.HYPERLINK,rangeId:v,properties:{url:_}}]},doc:I.documentModel}):P=o.BuildTextUtils.customRange.add({body:M,ranges:[{startOffset:0,endOffset:M.dataStream.length-2,collapsed:!1}],rangeId:v,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:_,refId:v}}),!P)return!1;const j=o.TextX.apply(M,P.serialize()),b={p:{...R,body:j},t:o.CellValueType.STRING},N=await a.onWriteCell(u,g,y,S,b),O={unitId:c,subUnitId:l,cellValue:{[f.row]:{[f.column]:N}}},re={id:m.SetRangeValuesMutation.id,params:O},Q=m.SetRangeValuesUndoMutationFactory(r,O),se={id:m.SetRangeValuesMutation.id,params:Q},A=[re],D=[se],V=s.getHyperLinkByLocation(c,l,y,S);return V&&(A.push({id:k.id,params:{unitId:c,subUnitId:l,id:V.id}}),D.push({id:E.id,params:{unitId:c,subUnitId:l,link:V}})),await o.sequenceExecuteAsync(A,e)?(n.pushUndoRedo({redoMutations:A,undoMutations:D,unitID:c}),!0):!1}},ue={id:"sheets.command.add-rich-hyper-link",type:o.CommandType.COMMAND,handler:async(r,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,i=r.get(o.ICommandService),s=o.generateRandomId(),{payload:a}=n,d=x.addCustomRangeBySelectionFactory(r,{unitId:e,rangeId:s,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:a,refId:s}});return d?i.syncExecuteCommand(d.id,d.params):!1}},pe={type:o.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(r,t){var b,N;if(!t)return!1;const e=r.get(o.ICommandService),n=r.get(o.IUndoRedoService),i=r.get(o.IUniverInstanceService),s=r.get(p.HyperLinkModel),a=m.getSheetCommandTarget(i,t);if(!a)return!1;const{row:d,column:c,id:l}=t,{unitId:u,subUnitId:g,worksheet:f}=a,_=f.getCell(d,c);if(!_)return!1;const h=f.getCellDocumentModelWithFormula(_);if(!(h!=null&&h.documentModel))return!1;const y=o.Tools.deepClone(h.documentModel.getSnapshot()),S=(N=(b=y.body)==null?void 0:b.customRanges)==null?void 0:N.find(O=>`${O.rangeId}`===l);if(!S)return!1;const v=o.BuildTextUtils.customRange.delete({documentDataModel:h.documentModel,rangeId:S.rangeId});if(!v)return!1;const U=o.TextX.apply(y.body,v.serialize()),I=[],R=[],M={unitId:u,subUnitId:g,cellValue:{[d]:{[c]:{p:{...y,body:U},t:o.CellValueType.STRING}}}};I.push({id:m.SetRangeValuesMutation.id,params:M});const P=m.SetRangeValuesUndoMutationFactory(r,M);R.push({id:m.SetRangeValuesMutation.id,params:P});const j=s.getHyperLinkByLocation(u,g,d,c);return j&&(I.push({id:k.id,params:{unitId:u,subUnitId:g,id:l}}),R.push({id:E.id,params:{unitId:u,subUnitId:g,link:{...j}}})),o.sequenceExecute(I,e).result?(n.pushUndoRedo({redoMutations:I,undoMutations:R,unitID:u}),!0):!1}},ge={type:o.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(r,t){var u,g;if(!t)return!1;const{id:e,documentId:n}=t,i=r.get(o.ICommandService),a=r.get(o.IUniverInstanceService).getUnit(n,o.UniverInstanceType.UNIVER_DOC),d=(g=(u=a==null?void 0:a.getBody())==null?void 0:u.customRanges)==null?void 0:g.find(f=>f.rangeId===e);let c=null;d&&d.endIndex===a.getBody().dataStream.length-3&&(c={dataStream:" "});const l=x.deleteCustomRangeFactory(r,{unitId:n,rangeId:e,insert:c});return l?i.syncExecuteCommand(l.id,l.params):!1}},he={type:o.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(r,t){var Se,ve,Ie;if(!t)return!1;const e=r.get(o.ICommandService),n=r.get(o.IUndoRedoService),i=r.get(o.IUniverInstanceService),s=r.get(p.HyperLinkModel),a=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:u,id:g}=t,{workbook:f,worksheet:_,unitId:h,subUnitId:y}=d,{payload:S,display:v=""}=c,U=_.getCell(l,u);if(!U)return!1;const I=_.getCellDocumentModelWithFormula(U);if(!(I!=null&&I.documentModel))return!1;const R=I.documentModel.getSnapshot(),M=(ve=(Se=R.body)==null?void 0:Se.customRanges)==null?void 0:ve.find(Ze=>`${Ze.rangeId}`===g);if(!M)return!1;const P=o.generateRandomId(),H=(Ie=o.getBodySlice(I.documentModel.getBody(),M.startIndex,M.endIndex+1).textRuns)==null?void 0:Ie[0];H&&(H.ed=v.length+1);const b=x.replaceSelectionFactory(r,{unitId:h,body:{dataStream:`${v}`,customRanges:[{rangeId:P,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:v.length-1,properties:{url:S}}],textRuns:H?[H]:void 0},selection:{startOffset:M.startIndex,endOffset:M.endIndex+1,collapsed:!1},doc:I.documentModel});if(!b)return!1;const N=o.TextX.apply(o.Tools.deepClone(R.body),b.textX.serialize()),O={p:{...R,body:N},t:o.CellValueType.STRING},re=await a.onWriteCell(f,_,l,u,O),Q={id:m.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:y,cellValue:{[l]:{[u]:re}}}},se=m.SetRangeValuesUndoMutationFactory(r,Q.params),A={id:m.SetRangeValuesMutation.id,params:se},D=[Q],V=[A],ee=s.getHyperLinkByLocation(h,y,l,u);return ee&&(D.push({id:k.id,params:{unitId:h,subUnitId:y,id:ee.id}}),V.push({id:E.id,params:{unitId:h,subUnitId:y,link:ee}})),await o.sequenceExecuteAsync(D,e)?(n.pushUndoRedo({redoMutations:D,undoMutations:V,unitID:h}),!0):!1}},me={type:o.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(r,t)=>{var h,y,S,v;if(!t)return!1;const{documentId:e,payload:n,id:i}=t,s=r.get(o.IUniverInstanceService),a=r.get(o.ICommandService),d=s.getUnit(e,o.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(y=(h=d.getBody())==null?void 0:h.customRanges)==null?void 0:y.find(U=>U.rangeId===i);if(!c)return!1;const l=(S=t.payload.display)!=null?S:"",u=o.generateRandomId(),f=(v=o.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:v[0];f&&(f.ed=l.length+1);const _=x.replaceSelectionFactory(r,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:u,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:f?[f]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return _?a.syncExecuteCommand(_.id,_.params):!1}};var We=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,Ke=(r,t,e,n)=>{for(var i=n>1?void 0:n?Be(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&We(t,e,i),i},ze=(r,t)=>(e,n)=>t(e,n,r);let Z=class extends o.Disposable{constructor(r){super(),this._commandService=r,this._registerCommands()}_registerCommands(){[le,he,pe,me,ge,ue,E,W,k,B,K].forEach(r=>{this._commandService.registerCommand(r)})}};Z=Ke([ze(0,o.ICommandService)],Z);var Ge=Object.defineProperty,Ye=Object.getOwnPropertyDescriptor,qe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ye(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Ge(t,e,i),i},ie=(r,t)=>(e,n)=>t(e,n,r);p.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${w.SHEET}=${e}${n?`&${typeof n=="string"?w.DEFINE_NAME:w.RANGE}=${typeof n=="string"?n:C.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,i,s;if(t.startsWith("#")){const a=new URLSearchParams(t.slice(1)),d={gid:(e=a.get("gid"))!=null?e:"",range:(n=a.get("range"))!=null?n:"",rangeid:(i=a.get("rangeid"))!=null?i:"",unitid:(s=a.get("unitid"))!=null?s:""},c=this._getURLName(d);return{type:c.type,name:c.name,url:t,searchObj:d}}else return{type:w.URL,name:t,url:t,searchObj:null}}_getURLName(t){var u;const{gid:e,range:n,rangeid:i,unitid:s}=t,a=s?this._univerInstanceService.getUnit(s,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),d={type:w.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!a)return d;const c=e?a.getSheetBySheetId(e):a.getActiveSheet(),l=(u=c==null?void 0:c.getName())!=null?u:"";if(n){if(!c)return d;const g=C.deserializeRangeWithSheet(n).range;return o.isValidRange(g,c)&&n!==$?{type:w.RANGE,name:C.serializeRangeWithSheet(l,g)}:d}if(i){const g=this._definedNamesService.getValueById(a.getUnitId(),i);return g?{type:w.DEFINE_NAME,name:g.formulaOrRefString}:d}if(e){const g=a.getSheetBySheetId(e);return g?{type:w.SHEET,name:g.getName()}:d}return d}},p.SheetsHyperLinkParserService=qe([ie(0,o.IUniverInstanceService),ie(1,o.Inject(o.LocaleService)),ie(2,C.IDefinedNamesService)],p.SheetsHyperLinkParserService);var fe=Object.defineProperty,Fe=Object.getOwnPropertyDescriptor,Je=(r,t,e)=>t in r?fe(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Xe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Fe(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&fe(t,e,i),i},_e=(r,t)=>(e,n)=>t(e,n,r),ye=(r,t,e)=>Je(r,typeof t!="symbol"?t+"":t,e);p.UniverSheetsHyperLinkPlugin=class extends o.Plugin{constructor(t=ae,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...i}=o.merge({},ae,this._config);this._configService.setConfig(Le,i)}onStarting(){o.registerDependencies(this._injector,[[p.HyperLinkModel],[p.SheetsHyperLinkParserService],[X],[Z],[G],[J],[Y],[q]]),o.touchDependencies(this._injector,[[G],[X],[Z],[J],[Y],[q]])}},ye(p.UniverSheetsHyperLinkPlugin,"pluginName",oe),ye(p.UniverSheetsHyperLinkPlugin,"type",o.UniverInstanceType.UNIVER_SHEET),p.UniverSheetsHyperLinkPlugin=Xe([o.DependentOn(m.UniverSheetsPlugin),_e(1,o.Inject(o.Injector)),_e(2,o.IConfigService)],p.UniverSheetsHyperLinkPlugin),p.AddHyperLinkCommand=le,p.AddHyperLinkMutation=E,p.AddRichHyperLinkCommand=ue,p.CancelHyperLinkCommand=pe,p.CancelRichHyperLinkCommand=ge,p.ERROR_RANGE=$,p.RemoveHyperLinkMutation=k,p.SheetHyperLinkType=w,p.UpdateHyperLinkCommand=he,p.UpdateHyperLinkMutation=W,p.UpdateHyperLinkRefMutation=B,p.UpdateRichHyperLinkCommand=me,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
|
|
2
|
+
(function(p,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("rxjs"),require("@univerjs/sheets"),require("@univerjs/engine-formula"),require("@univerjs/docs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","@univerjs/sheets","@univerjs/engine-formula","@univerjs/docs"],a):(p=typeof globalThis<"u"?globalThis:p||self,a(p.UniverSheetsHyperLink={},p.UniverCore,p.rxjs,p.UniverSheets,p.UniverEngineFormula,p.UniverDocs))})(this,function(p,a,b,m,C,x){"use strict";var ze=Object.defineProperty;var Ge=(p,a,b)=>a in p?ze(p,a,{enumerable:!0,configurable:!0,writable:!0,value:b}):p[a]=b;var U=(p,a,b)=>Ge(p,typeof a!="symbol"?a+"":a,b);var Ie=Object.getOwnPropertyDescriptor,Re=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ie(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},Me=(r,t)=>(e,n)=>t(e,n,r);p.HyperLinkModel=class extends a.Disposable{constructor(e){super();U(this,"_linkUpdate$",new b.Subject);U(this,"linkUpdate$",this._linkUpdate$.asObservable());U(this,"_linkMap",new Map);U(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let i=this._linkMap.get(e);i||(i=new Map,this._linkMap.set(e,i));let s=i.get(n);s||(s=new a.ObjectMatrix,i.set(n,s));let o=this._linkPositionMap.get(e);o||(o=new Map,this._linkPositionMap.set(e,o));let d=o.get(n);return d||(d=new Map,o.set(n,d)),{matrix:s,positionMap:d}}addHyperLink(e,n,i){const{matrix:s,positionMap:o}=this._ensureMap(e,n);return s.setValue(i.row,i.column,i),o.set(i.id,{row:i.row,column:i.column,link:i}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:i,type:"add"}),!0}updateHyperLink(e,n,i,s,o=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;const u=d.getValue(l.row,l.column);return u&&(Object.assign(u,s),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:u.display,payload:u.payload},id:i,type:"update",silent:o})),!0}updateHyperLinkRef(e,n,i,s,o=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;let u=d.getValue(l.row,l.column);return!u||u.id!==i?u=l.link:d.realDeleteValue(l.row,l.column),Object.assign(u,s),c.set(i,{...s,link:u}),d.setValue(s.row,s.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:i,type:"updateRef",silent:o}),!0}removeHyperLink(e,n,i){const{matrix:s,positionMap:o}=this._ensureMap(e,n),d=o.get(i);if(!d)return!1;o.delete(i);const c=s.getValue(d.row,d.column);return c&&c.id===i&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,i){const{matrix:s,positionMap:o}=this._ensureMap(e,n),d=o.get(i);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,i,s){const{matrix:o}=this._ensureMap(e,n);return o.getValue(i,s)}getHyperLinkByLocationSync(e,n,i,s){var g,f,y,h,_;const{matrix:o}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,a.UniverInstanceType.UNIVER_SHEET),c=(g=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:g.getCellRaw(i,s),l=((_=(h=c==null?void 0:c.v)!=null?h:(y=(f=c==null?void 0:c.p)==null?void 0:f.body)==null?void 0:y.dataStream.slice(0,-2))!=null?_:"").toString(),u=o.getValue(i,s);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:i}=this._ensureMap(e,n),s=[];return i.forValue((o,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(i=>{const s=this.getSubUnit(e,i);return{unitId:e,subUnitId:i,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}},p.HyperLinkModel=Re([Me(0,a.IUniverInstanceService)],p.HyperLinkModel);var L=(r=>(r.SHEET="gid",r.RANGE="range",r.DEFINE_NAME="rangeid",r.INVALID="invalid",r.URL="url",r))(L||{});const Ce="sheets-hyper-link.config",ae={},w={type:a.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,link:s}=t;return e.addHyperLink(n,i,s)}},E={type:a.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:s}=t;return e.removeHyperLink(n,i,s)}},W={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,payload:s,id:o}=t;return e.updateHyperLink(n,i,o,s,!1)}},B={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:s,row:o,column:d,silent:c}=t;return e.updateHyperLinkRef(n,i,s,{row:o,column:d},c)}},K={type:a.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(r,t){var y,h,_;if(!t)return!1;const{unitId:e,subUnitId:n,row:i,col:s,id:o,url:d}=t,c=r.get(a.IUniverInstanceService),l=m.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:u}=l,g=u.getCellRaw(i,s),f=(_=(h=(y=g==null?void 0:g.p)==null?void 0:y.body)==null?void 0:h.customRanges)==null?void 0:_.find(v=>v.rangeType===a.CustomRangeType.HYPERLINK&&v.rangeId===o);return f&&(f.properties.url=d),!0}},oe="SHEET_HYPER_LINK_PLUGIN",$="err";var ke=Object.getOwnPropertyDescriptor,Ue=(r,t,e,n)=>{for(var i=n>1?void 0:n?ke(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},z=(r,t)=>(e,n)=>t(e,n,r);let G=class extends a.Disposable{constructor(t,e,n,i){super();U(this,"_disposableMap",new Map);U(this,"_watchDisposableMap",new Map);U(this,"_rangeDisableMap",new Map);U(this,"_rangeWatcherMap",new Map);U(this,"_handlePositionChange",(t,e,n,i,s)=>{const o={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return i?{redos:[{id:B.id,params:{unitId:t,subUnitId:e,id:n.id,row:i.startRow,column:i.startColumn,silent:s}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,id:n.id,row:o.startRow,column:o.startColumn,silent:s}}]}:{redos:[{id:E.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:w.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=i,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},o=d=>{const c=m.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===s.startColumn&&l.startRow===s.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(i,this._refRangeService.registerRefRange(s,o,t,e))}_watchPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(t,e,s,(o,d)=>{const{redos:c}=this._handlePositionChange(t,e,n,d,!0);a.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(t){const e=this._disposableMap.get(t);e==null||e.dispose(),this._disposableMap.delete(t)}_unwatchPosition(t){const e=this._watchDisposableMap.get(t);e==null||e.dispose(),this._watchDisposableMap.delete(t)}_registerRange(t,e,n,i=!1){var s,o,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(s=c.get("gid"))!=null?s:"",range:(o=c.get("range"))!=null?o:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const u=l.gid,g=C.deserializeRangeWithSheet(l.range).range;if(a.isValidRange(g)&&l.range!==$){const f=y=>{const h=m.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(g,y,{selectionManagerService:this._selectionManagerService});return h&&C.serializeRange(h)===C.serializeRange(g)?{redos:[],undos:[]}:{redos:[{id:W.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`}}}],undos:[{id:W.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(g,f,t,u)),i||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,u,g,(y,h)=>{this._hyperLinkModel.updateHyperLink(t,u,e,{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`},!0)},!0))}}}}_unregisterRange(t){const e=this._rangeDisableMap.get(t);e==null||e.dispose(),this._rangeDisableMap.delete(t)}_unwatchRange(t){const e=this._rangeWatcherMap.get(t);e==null||e.dispose(),this._rangeWatcherMap.delete(t)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(n=>{const{unitId:i,subUnitId:s,links:o}=n;o.forEach(d=>{this._registerPosition(i,s,d),this._watchPosition(i,s,d),this._registerRange(i,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:i,silent:s}=t,o=this._hyperLinkModel.getHyperLink(e,n,i);if(!o)return;this._unregisterPosition(i),this._registerPosition(e,n,o),s||(this._unwatchPosition(i),this._watchPosition(e,n,o));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:i}=n;i.forEach(s=>{this._unregisterPosition(s.id),this._unwatchPosition(s.id),this._unregisterRange(s.id),this._unwatchRange(s.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(a.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};G=Ue([z(0,a.Inject(m.RefRangeService)),z(1,a.Inject(p.HyperLinkModel)),z(2,a.Inject(m.SheetsSelectionsService)),z(3,a.ICommandService)],G);var Le=Object.getOwnPropertyDescriptor,we=(r,t,e,n)=>{for(var i=n>1?void 0:n?Le(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},te=(r,t)=>(e,n)=>t(e,n,r);let Y=class extends a.Disposable{constructor(r,t,e){super(),this._sheetInterceptorService=r,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{var t;if(r.id===m.RemoveSheetCommand.id){const e=r.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const i=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const o=this._hyperLinkModel.getSubUnit(i,s),d=o.map(l=>({id:E.id,params:{unitId:i,subUnitId:s,id:l.id}})),c=o.map(l=>({id:w.id,params:{unitId:i,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};Y=we([te(0,a.Inject(m.SheetInterceptorService)),te(1,a.IUniverInstanceService),te(2,a.Inject(p.HyperLinkModel))],Y);var Ee=Object.getOwnPropertyDescriptor,Te=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ee(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},ne=(r,t)=>(e,n)=>t(e,n,r);let q=class extends a.Disposable{constructor(t,e,n){super();U(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let i=n.get(e);return i||(i=new a.ObjectMatrix,n.set(e,i)),i}_isLegalRangeUrl(t,e){var i,s,o;const n=this._univerInstanceService.getUnit(t,a.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(i=d.get("gid"))!=null?i:"",range:(s=d.get("range"))!=null?s:"",rangeid:(o=d.get("rangeid"))!=null?o:""};if(c.range&&c.gid){const l=c.gid,u=n.getSheetBySheetId(l);if(!u)return null;const g=C.deserializeRangeWithSheet(c.range).range;if(a.isValidRange(g,u)&&c.range!==$)return{range:g,worksheet:u}}}return null}_registerRange(t,e,n,i,s){var d,c,l,u;const o=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(g=>{var f;return g.rangeType===a.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(f=g.properties)==null?void 0:f.url)})){const g=new a.DisposableCollection;let f=!1;(u=(l=s.body)==null?void 0:l.customRanges)==null||u.forEach(y=>{var h;if(y.rangeType===a.CustomRangeType.HYPERLINK){const _=(h=y.properties)==null?void 0:h.url,v=this._isLegalRangeUrl(t,_);if(v){const{range:S,worksheet:k}=v;f=!0,g.add(this._refRangeService.registerRefRange(S,I=>{const R=m.handleDefaultRangeChangeWithEffectRefCommands(S,I);return R&&a.Rectangle.equals(R,S)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:K.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:y.rangeId,url:`#gid=${e}&range=${R?C.serializeRange(R):$}`}}],undos:[{id:K.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:y.rangeId,url:_}}],redos:[]}},k.getUnitId(),k.getSheetId()))}}}),f&&o.setValue(n,i,g)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId(),o=this._enusreMap(n,s);i.getCellMatrix().forValue((d,c,l)=>{const u=o.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,s,d,c,l.p)})})};this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(e=>{e.type===a.UniverInstanceType.UNIVER_SHEET&&t(e)}))}_initWorkbookUnload(){this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===a.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId();this._enusreMap(n,s).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}})}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===m.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:i,cellValue:s}=e,o=this._enusreMap(n,i);s&&new a.ObjectMatrix(s).forValue((d,c,l)=>{const u=o.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,i,d,c,l.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===K.id){const e=t.params,{unitId:n,subUnitId:i,row:s,col:o}=e,d=m.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:i}),l=this._enusreMap(n,i).getValue(s,o);if(l&&l.dispose(),d){const{worksheet:u}=d,g=u.getCellRaw(s,o);g&&g.p&&this._registerRange(n,i,s,o,g.p)}}}))}};q=Te([ne(0,a.ICommandService),ne(1,a.IUniverInstanceService),ne(2,a.Inject(m.RefRangeService))],q);var He=Object.getOwnPropertyDescriptor,be=(r,t,e,n)=>{for(var i=n>1?void 0:n?He(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},F=(r,t)=>(e,n)=>t(e,n,r);let J=class extends a.Disposable{constructor(r,t,e,n){super(),this._sheetInterceptorService=r,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.SetRangeValuesCommand.id){const t=r.params,{unitId:e,subUnitId:n}=t,i=[],s=[];return t.cellValue&&new a.ObjectMatrix(t.cellValue).forValue((o,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,o,d);c&&(i.push({id:E.id,params:{unitId:e,subUnitId:n,id:c.id}}),s.push({id:w.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:s,redos:i}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.ClearSelectionContentCommand.id||r.id===m.ClearSelectionAllCommand.id||r.id===m.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),i=m.getSheetCommandTarget(this._univerInstanceService);if(n&&i){const{unitId:s,subUnitId:o}=i;a.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(s,o,d,c);l&&(t.push({id:E.id,params:{unitId:s,subUnitId:o,id:l.id}}),e.push({id:w.id,params:{unitId:s,subUnitId:o,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(m.AFTER_CELL_EDIT,{handler:(r,t,e)=>{if(!r||r.p)return e(r);if(typeof r.v=="string"&&a.Tools.isLegalUrl(r.v)&&r.v[r.v.length-1]!==" "){const{unitId:n,subUnitId:i}=t,s=this._univerInstanceService.getUnit(n,a.UniverInstanceType.UNIVER_SHEET),o=s==null?void 0:s.getSheetBySheetId(i);if(!o)return e(r);const d=o.getBlankCellDocumentModel(r);if(!d.documentModel)return e(r);const c=a.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:r.v.length,collapsed:!1},body:{dataStream:`${r.v}`,customRanges:[{startIndex:0,endIndex:r.v.length-1,rangeId:a.generateRandomId(),rangeType:a.CustomRangeType.HYPERLINK,properties:{url:r.v}}]},doc:d.documentModel});if(!c)return e(r);const l=d.documentModel.getBody();return a.TextX.apply(l,c.serialize()),e({...r,p:{id:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:l,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(r)}}))}};J=be([F(0,a.Inject(m.SheetInterceptorService)),F(1,a.Inject(p.HyperLinkModel)),F(2,a.Inject(m.SheetsSelectionsService)),F(3,a.IUniverInstanceService)],J);var de=(r=>(r[r.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",r[r.UNIVER_DOC=1]="UNIVER_DOC",r[r.UNIVER_SHEET=2]="UNIVER_SHEET",r[r.UNIVER_SLIDE=3]="UNIVER_SLIDE",r[r.UNIVER_PROJECT=4]="UNIVER_PROJECT",r[r.UNRECOGNIZED=-1]="UNRECOGNIZED",r))(de||{}),Pe=Object.getOwnPropertyDescriptor,Ne=(r,t,e,n)=>{for(var i=n>1?void 0:n?Pe(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},ce=(r,t)=>(e,n)=>t(e,n,r);let X=class extends a.Disposable{constructor(r,t){super(),this._resourceManagerService=r,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const r=e=>{const n=this._hyperLinkModel.getUnit(e),i={};return n?(n.forEach(s=>{i[s.subUnitId]=s.links.map(({display:o,...d})=>d)}),JSON.stringify(i)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:oe,businesses:[de.UNIVER_SHEET],toJson:e=>r(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(i=>{n[i].forEach(o=>{this._hyperLinkModel.addHyperLink(e,i,o)})})}}))}};X=Ne([ce(0,a.IResourceManagerService),ce(1,a.Inject(p.HyperLinkModel))],X);const le={type:a.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(r,t){if(!t)return!1;const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService),s=r.get(p.HyperLinkModel),o=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:u,worksheet:g}=d,{link:f}=t,{payload:y,display:h,row:_,column:v,id:S}=f,k=g.getCell(_,v),I=g.getBlankCellDocumentModel(k),R=I.documentModel.getSnapshot(),M=a.Tools.deepClone(R.body);if(!M)return!1;let T;if(h?T=a.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:M.dataStream.length-2,collapsed:M.dataStream.length-2===0},body:{dataStream:`${h}`,customRanges:[{startIndex:0,endIndex:h.length-1,rangeType:a.CustomRangeType.HYPERLINK,rangeId:S,properties:{url:y}}]},doc:I.documentModel}):T=a.BuildTextUtils.customRange.add({body:M,ranges:[{startOffset:0,endOffset:M.dataStream.length-2,collapsed:!1}],rangeId:S,rangeType:a.CustomRangeType.HYPERLINK,properties:{url:y,refId:S}}),!T)return!1;const j=a.TextX.apply(M,T.serialize()),H={p:{...R,body:j},t:a.CellValueType.STRING},N=await o.onWriteCell(u,g,_,v,H),D={unitId:c,subUnitId:l,cellValue:{[f.row]:{[f.column]:N}}},re={id:m.SetRangeValuesMutation.id,params:D},Q=m.SetRangeValuesUndoMutationFactory(r,D),se={id:m.SetRangeValuesMutation.id,params:Q},A=[re],O=[se],V=s.getHyperLinkByLocation(c,l,_,v);return V&&(A.push({id:E.id,params:{unitId:c,subUnitId:l,id:V.id}}),O.push({id:w.id,params:{unitId:c,subUnitId:l,link:V}})),await a.sequenceExecuteAsync(A,e)?(n.pushUndoRedo({redoMutations:A,undoMutations:O,unitID:c}),!0):!1}},ue={id:"sheets.command.add-rich-hyper-link",type:a.CommandType.COMMAND,handler:async(r,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,i=r.get(a.ICommandService),s=a.generateRandomId(),{payload:o}=n,d=x.addCustomRangeBySelectionFactory(r,{unitId:e,rangeId:s,rangeType:a.CustomRangeType.HYPERLINK,properties:{url:o,refId:s}});return d?i.syncExecuteCommand(d.id,d.params):!1}},pe={type:a.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(r,t){var H,N;if(!t)return!1;const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService),s=r.get(p.HyperLinkModel),o=m.getSheetCommandTarget(i,t);if(!o)return!1;const{row:d,column:c,id:l}=t,{unitId:u,subUnitId:g,worksheet:f}=o,y=f.getCell(d,c);if(!y)return!1;const h=f.getCellDocumentModelWithFormula(y);if(!(h!=null&&h.documentModel))return!1;const _=a.Tools.deepClone(h.documentModel.getSnapshot()),v=(N=(H=_.body)==null?void 0:H.customRanges)==null?void 0:N.find(D=>`${D.rangeId}`===l);if(!v)return!1;const S=a.BuildTextUtils.customRange.delete({documentDataModel:h.documentModel,rangeId:v.rangeId});if(!S)return!1;const k=a.TextX.apply(_.body,S.serialize()),I=[],R=[],M={unitId:u,subUnitId:g,cellValue:{[d]:{[c]:{p:{..._,body:k},t:a.CellValueType.STRING}}}};I.push({id:m.SetRangeValuesMutation.id,params:M});const T=m.SetRangeValuesUndoMutationFactory(r,M);R.push({id:m.SetRangeValuesMutation.id,params:T});const j=s.getHyperLinkByLocation(u,g,d,c);return j&&(I.push({id:E.id,params:{unitId:u,subUnitId:g,id:l}}),R.push({id:w.id,params:{unitId:u,subUnitId:g,link:{...j}}})),a.sequenceExecute(I,e).result?(n.pushUndoRedo({redoMutations:I,undoMutations:R,unitID:u}),!0):!1}},ge={type:a.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(r,t){var u,g;if(!t)return!1;const{id:e,documentId:n}=t,i=r.get(a.ICommandService),o=r.get(a.IUniverInstanceService).getUnit(n,a.UniverInstanceType.UNIVER_DOC),d=(g=(u=o==null?void 0:o.getBody())==null?void 0:u.customRanges)==null?void 0:g.find(f=>f.rangeId===e);let c=null;d&&d.endIndex===o.getBody().dataStream.length-3&&(c={dataStream:" "});const l=x.deleteCustomRangeFactory(r,{unitId:n,rangeId:e,insert:c});return l?i.syncExecuteCommand(l.id,l.params):!1}},he={type:a.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(r,t){var _e,ve,Se;if(!t)return!1;const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService),s=r.get(p.HyperLinkModel),o=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:u,id:g}=t,{workbook:f,worksheet:y,unitId:h,subUnitId:_}=d,{payload:v,display:S=""}=c,k=y.getCell(l,u);if(!k)return!1;const I=y.getCellDocumentModelWithFormula(k);if(!(I!=null&&I.documentModel))return!1;const R=I.documentModel.getSnapshot(),M=(ve=(_e=R.body)==null?void 0:_e.customRanges)==null?void 0:ve.find(Ke=>`${Ke.rangeId}`===g);if(!M)return!1;const T=a.generateRandomId(),P=(Se=a.getBodySlice(I.documentModel.getBody(),M.startIndex,M.endIndex+1).textRuns)==null?void 0:Se[0];P&&(P.ed=S.length+1);const H=x.replaceSelectionFactory(r,{unitId:h,body:{dataStream:`${S}`,customRanges:[{rangeId:T,rangeType:a.CustomRangeType.HYPERLINK,startIndex:0,endIndex:S.length-1,properties:{url:v}}],textRuns:P?[P]:void 0},selection:{startOffset:M.startIndex,endOffset:M.endIndex+1,collapsed:!1},doc:I.documentModel});if(!H)return!1;const N=a.TextX.apply(a.Tools.deepClone(R.body),H.textX.serialize()),D={p:{...R,body:N},t:a.CellValueType.STRING},re=await o.onWriteCell(f,y,l,u,D),Q={id:m.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:_,cellValue:{[l]:{[u]:re}}}},se=m.SetRangeValuesUndoMutationFactory(r,Q.params),A={id:m.SetRangeValuesMutation.id,params:se},O=[Q],V=[A],ee=s.getHyperLinkByLocation(h,_,l,u);return ee&&(O.push({id:E.id,params:{unitId:h,subUnitId:_,id:ee.id}}),V.push({id:w.id,params:{unitId:h,subUnitId:_,link:ee}})),await a.sequenceExecuteAsync(O,e)?(n.pushUndoRedo({redoMutations:O,undoMutations:V,unitID:h}),!0):!1}},me={type:a.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(r,t)=>{var h,_,v,S;if(!t)return!1;const{documentId:e,payload:n,id:i}=t,s=r.get(a.IUniverInstanceService),o=r.get(a.ICommandService),d=s.getUnit(e,a.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(_=(h=d.getBody())==null?void 0:h.customRanges)==null?void 0:_.find(k=>k.rangeId===i);if(!c)return!1;const l=(v=t.payload.display)!=null?v:"",u=a.generateRandomId(),f=(S=a.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:S[0];f&&(f.ed=l.length+1);const y=x.replaceSelectionFactory(r,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:u,rangeType:a.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:f?[f]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return y?o.syncExecuteCommand(y.id,y.params):!1}};var De=Object.getOwnPropertyDescriptor,Oe=(r,t,e,n)=>{for(var i=n>1?void 0:n?De(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},Ve=(r,t)=>(e,n)=>t(e,n,r);let Z=class extends a.Disposable{constructor(r){super(),this._commandService=r,this._registerCommands()}_registerCommands(){[le,he,pe,me,ge,ue,w,W,E,B,K].forEach(r=>{this._commandService.registerCommand(r)})}};Z=Oe([Ve(0,a.ICommandService)],Z);var $e=Object.getOwnPropertyDescriptor,je=(r,t,e,n)=>{for(var i=n>1?void 0:n?$e(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},ie=(r,t)=>(e,n)=>t(e,n,r);p.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${L.SHEET}=${e}${n?`&${typeof n=="string"?L.DEFINE_NAME:L.RANGE}=${typeof n=="string"?n:C.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,i,s;if(t.startsWith("#")){const o=new URLSearchParams(t.slice(1)),d={gid:(e=o.get("gid"))!=null?e:"",range:(n=o.get("range"))!=null?n:"",rangeid:(i=o.get("rangeid"))!=null?i:"",unitid:(s=o.get("unitid"))!=null?s:""},c=this._getURLName(d);return{type:c.type,name:c.name,url:t,searchObj:d}}else return{type:L.URL,name:t,url:t,searchObj:null}}_getURLName(t){var u;const{gid:e,range:n,rangeid:i,unitid:s}=t,o=s?this._univerInstanceService.getUnit(s,a.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),d={type:L.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!o)return d;const c=e?o.getSheetBySheetId(e):o.getActiveSheet(),l=(u=c==null?void 0:c.getName())!=null?u:"";if(n){if(!c)return d;const g=C.deserializeRangeWithSheet(n).range;return a.isValidRange(g,c)&&n!==$?{type:L.RANGE,name:C.serializeRangeWithSheet(l,g)}:d}if(i){const g=this._definedNamesService.getValueById(o.getUnitId(),i);return g?{type:L.DEFINE_NAME,name:g.formulaOrRefString}:d}if(e){const g=o.getSheetBySheetId(e);return g?{type:L.SHEET,name:g.getName()}:d}return d}},p.SheetsHyperLinkParserService=je([ie(0,a.IUniverInstanceService),ie(1,a.Inject(a.LocaleService)),ie(2,C.IDefinedNamesService)],p.SheetsHyperLinkParserService);var Ae=Object.defineProperty,xe=Object.getOwnPropertyDescriptor,We=(r,t,e)=>t in r?Ae(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Be=(r,t,e,n)=>{for(var i=n>1?void 0:n?xe(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},fe=(r,t)=>(e,n)=>t(e,n,r),ye=(r,t,e)=>We(r,typeof t!="symbol"?t+"":t,e);p.UniverSheetsHyperLinkPlugin=class extends a.Plugin{constructor(t=ae,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...i}=a.merge({},ae,this._config);this._configService.setConfig(Ce,i)}onStarting(){a.registerDependencies(this._injector,[[p.HyperLinkModel],[p.SheetsHyperLinkParserService],[X],[Z],[G],[J],[Y],[q]]),a.touchDependencies(this._injector,[[G],[X],[Z],[J],[Y],[q]])}},ye(p.UniverSheetsHyperLinkPlugin,"pluginName",oe),ye(p.UniverSheetsHyperLinkPlugin,"type",a.UniverInstanceType.UNIVER_SHEET),p.UniverSheetsHyperLinkPlugin=Be([a.DependentOn(m.UniverSheetsPlugin),fe(1,a.Inject(a.Injector)),fe(2,a.IConfigService)],p.UniverSheetsHyperLinkPlugin),p.AddHyperLinkCommand=le,p.AddHyperLinkMutation=w,p.AddRichHyperLinkCommand=ue,p.CancelHyperLinkCommand=pe,p.CancelRichHyperLinkCommand=ge,p.ERROR_RANGE=$,p.RemoveHyperLinkMutation=E,p.SheetHyperLinkType=L,p.UpdateHyperLinkCommand=he,p.UpdateHyperLinkMutation=W,p.UpdateHyperLinkRefMutation=B,p.UpdateRichHyperLinkCommand=me,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
// @univerjs/sheets-hyper-link/facade
|
|
6
|
-
(function(h,
|
|
6
|
+
(function(h,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/sheets-hyper-link"),require("@univerjs/sheets/facade"),require("@univerjs/core/facade")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-hyper-link","@univerjs/sheets/facade","@univerjs/core/facade"],a):(h=typeof globalThis<"u"?globalThis:h||self,a(h.UniverSheetsHyperLinkFacade={},h.UniverCore,h.UniverSheetsHyperLink,h.UniverSheetsFacade,h.UniverCoreFacade))})(this,function(h,a,d,c,k){"use strict";var g=Object.getOwnPropertyDescriptor,w=(s,e,i,r)=>{for(var n=r>1?void 0:r?g(e,i):e,t=s.length-1,o;t>=0;t--)(o=s[t])&&(n=o(n)||n);return n},y=(s,e)=>(i,r)=>e(i,r,s);let l=class{constructor(s,e){this._workbook=s,this._parserService=e}getRangeUrl(s){return this._parserService.buildHyperLink(this._workbook.getId(),s.getSheetId(),s.getRange()),this}};l=w([y(1,a.Inject(d.SheetsHyperLinkParserService))],l);class p extends c.FWorkbook{createSheetHyperlink(e,i){return this._injector.get(d.SheetsHyperLinkParserService).buildHyperLink(this.getId(),e,i)}parseSheetHyperlink(e){return this._injector.get(d.SheetsHyperLinkParserService).parseHyperLink(e)}}c.FWorkbook.extend(p);class C extends c.FWorksheet{getUrl(){return this._injector.get(d.SheetsHyperLinkParserService).buildHyperLink(this._workbook.getUnitId(),this._worksheet.getSheetId())}}c.FWorksheet.extend(C);class _ extends c.FRange{setHyperLink(e,i){const r={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),link:{row:this._range.startRow,column:this._range.startColumn,payload:e,display:i,id:a.generateRandomId()}};return this._commandService.executeCommand(d.AddHyperLinkCommand.id,r)}getHyperLinks(){var i,r,n;const e=this._worksheet.getCellRaw(this._range.startRow,this._range.startColumn);return e!=null&&e.p?(n=(r=(i=e.p.body)==null?void 0:i.customRanges)==null?void 0:r.filter(t=>t.rangeType===a.CustomRangeType.HYPERLINK).map(t=>{var o,u,v,m,S;return{id:`${t.rangeId}`,startIndex:t.startIndex,endIndex:t.endIndex,url:(u=(o=t.properties)==null?void 0:o.url)!=null?u:"",label:(S=(m=(v=e.p)==null?void 0:v.body)==null?void 0:m.dataStream.slice(t.startIndex,t.endIndex+1).replaceAll(a.DataStreamTreeTokenType.CUSTOM_RANGE_START,"").replaceAll(a.DataStreamTreeTokenType.CUSTOM_RANGE_END,""))!=null?S:""}}))!=null?n:[]:[]}updateHyperLink(e,i,r){const n={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id:e,payload:{payload:i,display:r}};return this._commandService.executeCommand(d.UpdateHyperLinkCommand.id,n)}cancelHyperLink(e){const i={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id:e};return this._commandService.syncExecuteCommand(d.CancelHyperLinkCommand.id,i)}getUrl(){return this._injector.get(d.SheetsHyperLinkParserService).buildHyperLink(this.getUnitId(),this.getSheetId(),this.getRange())}}c.FRange.extend(_);class f{get BeforeSheetLinkAdd(){return"BeforeSheetLinkAdd"}get BeforeSheetLinkCancel(){return"BeforeSheetLinkCancel"}get BeforeSheetLinkUpdate(){return"BeforeSheetLinkUpdate"}}k.FEventName.extend(f);class L extends k.FUniver{_initialize(e){const i=e.get(a.ICommandService);this.registerEventHandler(this.Event.BeforeSheetLinkAdd,()=>i.beforeCommandExecuted(r=>{if(r.id!==d.AddHyperLinkCommand.id)return;const n=this.getCommandSheetTarget(r);if(!n)return;const t=r.params,o={workbook:n.workbook,worksheet:n.worksheet,row:t.link.row,col:t.link.column,link:t.link};if(this.fireEvent(this.Event.BeforeSheetLinkAdd,o),o.cancel)throw new a.CanceledError})),this.registerEventHandler(this.Event.BeforeSheetLinkUpdate,()=>i.beforeCommandExecuted(r=>{if(r.id!==d.UpdateHyperLinkCommand.id)return;const n=this.getCommandSheetTarget(r);if(!n)return;const t=r.params,o={workbook:n.workbook,worksheet:n.worksheet,row:t.row,column:t.column,id:t.id,payload:t.payload};if(this.fireEvent(this.Event.BeforeSheetLinkUpdate,o),o.cancel)throw new a.CanceledError})),this.registerEventHandler(this.Event.BeforeSheetLinkCancel,()=>i.beforeCommandExecuted(r=>{if(r.id!==d.CancelHyperLinkCommand.id)return;const n=this.getCommandSheetTarget(r);if(!n)return;const t=r.params,o={workbook:n.workbook,worksheet:n.worksheet,row:t.row,column:t.column,id:t.id};if(this.fireEvent(this.Event.BeforeSheetLinkCancel,o),o.cancel)throw new a.CanceledError}))}}k.FUniver.extend(L),h.FWorkbookHyperLinkMixin=p,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
// @univerjs/sheets-hyper-link-ui/index
|
|
10
|
-
(function(g,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/sheets-hyper-link"),require("@univerjs/sheets-ui"),require("@univerjs/design"),require("@univerjs/engine-formula"),require("@univerjs/sheets"),require("@univerjs/ui"),require("@univerjs/docs-ui"),require("@univerjs/engine-render"),require("rxjs"),require("@univerjs/docs"),require("react/jsx-runtime"),require("@univerjs/sheets-formula-ui"),require("react"),require("@univerjs/sheets-data-validation")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-hyper-link","@univerjs/sheets-ui","@univerjs/design","@univerjs/engine-formula","@univerjs/sheets","@univerjs/ui","@univerjs/docs-ui","@univerjs/engine-render","rxjs","@univerjs/docs","react/jsx-runtime","@univerjs/sheets-formula-ui","react","@univerjs/sheets-data-validation"],o):(g=typeof globalThis<"u"?globalThis:g||self,o(g.UniverSheetsHyperLinkUi={},g.UniverCore,g.UniverSheetsHyperLink,g.UniverSheetsUi,g.UniverDesign,g.UniverEngineFormula,g.UniverSheets,g.UniverUi,g.UniverDocsUi,g.UniverEngineRender,g.rxjs,g.UniverDocs,g.React,g.UniverSheetsFormulaUi,g.React,g.UniverSheetsDataValidation))})(this,function(g,o,v,y,w,X,E,b,ee,pe,L,he,f,At,C,tt){"use strict";var Fn=Object.defineProperty;var Zn=(g,o,v)=>o in g?Fn(g,o,{enumerable:!0,configurable:!0,writable:!0,value:v}):g[o]=v;var W=(g,o,v)=>Zn(g,typeof o!="symbol"?o+"":o,v);function Ee(e){return o.Tools.isLegalUrl(e)}function Bt(e){return/^[a-zA-Z]+:\/\//.test(e)}function $t(e){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(e)}function Vt(e){if(Ee(e)){const n=Bt(e)?e:$t(e)?`mailto://${e}`:`http://${e}`;let t;try{t=new URL(n)}catch{return e}return t.hostname===location.hostname&&t.port===location.port&&t.protocol===location.protocol&&t.pathname===location.pathname&&t.hash&&!t.search?t.hash:n}return e}const nt="sheets-hyper-link-ui.config",it={};var jt=Object.defineProperty,xt=Object.getOwnPropertyDescriptor,Ft=(e,n,t,i)=>{for(var r=i>1?void 0:i?xt(n,t):n,a=e.length-1,s;a>=0;a--)(s=e[a])&&(r=(i?s(n,t,r):s(r))||r);return i&&r&&jt(n,t,r),r},ue=(e,n)=>(t,i)=>n(t,i,e);function Zt(e,n){const t=n.getMergeData(),i=n.getMaxColumns()-1,r=n.getMaxRows()-1;if(i<e.endColumn&&(e.endColumn=i),r<e.endRow&&(e.endRow=r),e.rangeType===o.RANGE_TYPE.COLUMN||o.RANGE_TYPE.ROW)return e;const a=[];return t.forEach(s=>{o.Rectangle.intersects(e,s)&&a.push(s)}),o.Rectangle.realUnion(e,...a)}g.SheetsHyperLinkResolverService=class{constructor(n,t,i,r,a,s){this._univerInstanceService=n,this._commandService=t,this._definedNamesService=i,this._messageService=r,this._localeService=a,this._configService=s}navigate(n){switch(n.type){case v.SheetHyperLinkType.URL:this.navigateToOtherWebsite(n.url);break;default:this._navigateToUniver(n.searchObj)}}_navigateToUniver(n){const{gid:t,range:i,rangeid:r}=n,a=this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!a)return;const s=a.getUnitId();if(r){const l=this._definedNamesService.getValueById(s,r);if(!l)return;const{formulaOrRefString:u}=l,p=this._definedNamesService.getWorksheetByRef(s,u);if(!p){this._messageService.show({content:this._localeService.t("hyperLink.message.refError"),type:w.MessageType.Error});return}if(p.isSheetHidden()){this._messageService.show({content:this._localeService.t("hyperLink.message.hiddenSheet"),type:w.MessageType.Error});return}this.navigateToDefineName(s,r)}if(t){if(i){const l=X.deserializeRangeWithSheet(i);o.isValidRange(l.range)&&i!==v.ERROR_RANGE&&this.navigateToRange(s,t,l.range);return}this.navigateToSheetById(s,t)}}async navigateToRange(n,t,i,r){const a=await this.navigateToSheetById(n,t);if(a){const s=Zt(i,a);await this._commandService.executeCommand(E.SetSelectionsOperation.id,{unitId:n,subUnitId:t,selections:[{range:s,primary:null}]}),await this._commandService.executeCommand(y.ScrollToRangeOperation.id,{range:s,forceTop:r})}}async navigateToSheetById(n,t){const i=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET);if(!i)return!1;const r=i.getActiveSheet();if(!r)return!1;if(r.getSheetId()===t)return r;const a=i.getSheetBySheetId(t);return a?i.getHiddenWorksheets().indexOf(t)>-1?(this._messageService.show({content:this._localeService.t("hyperLink.message.hiddenSheet"),type:w.MessageType.Error}),!1):await this._commandService.executeCommand(E.SetWorksheetActiveOperation.id,{unitId:n,subUnitId:t})?a:!1:(this._messageService.show({content:this._localeService.t("hyperLink.message.noSheet"),type:w.MessageType.Error}),!1)}async navigateToDefineName(n,t){return this._definedNamesService.focusRange(n,t),!0}async navigateToOtherWebsite(n){var i;const t=this._configService.getConfig(nt);if((i=t==null?void 0:t.urlHandler)!=null&&i.navigateToOtherWebsite)return t.urlHandler.navigateToOtherWebsite(n);window.open(n,"_blank","noopener noreferrer")}},g.SheetsHyperLinkResolverService=Ft([ue(0,o.IUniverInstanceService),ue(1,o.ICommandService),ue(2,X.IDefinedNamesService),ue(3,b.IMessageService),ue(4,o.Inject(o.LocaleService)),ue(5,o.IConfigService)],g.SheetsHyperLinkResolverService);const Ve="SHEET_HYPER_LINK_UI_PLUGIN";var Wt=Object.defineProperty,Kt=Object.getOwnPropertyDescriptor,Yt=(e,n,t,i)=>{for(var r=i>1?void 0:i?Kt(n,t):n,a=e.length-1,s;a>=0;a--)(s=e[a])&&(r=(i?s(n,t,r):s(r))||r);return i&&r&&Wt(n,t,r),r},Pe=(e,n)=>(t,i)=>n(t,i,e);g.SheetsHyperLinkCopyPasteController=class extends o.Disposable{constructor(t,i,r,a){super();W(this,"_plainTextFilter",new Set);W(this,"_copyInfo");this._sheetClipboardService=t,this._hyperLinkModel=i,this._injector=r,this._resolverService=a,this._initCopyPaste(),this.disposeWithMe(()=>{this._plainTextFilter.clear()})}registerPlainTextFilter(t){this._plainTextFilter.add(t)}removePlainTextFilter(t){this._plainTextFilter.delete(t)}_filterPlainText(t){return Array.from(this._plainTextFilter).every(i=>i(t))}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:Ve,onBeforeCopy:(t,i,r)=>this._collect(t,i,r),onPasteCells:(t,i,r,a)=>{const{copyType:s=y.COPY_TYPE.COPY,pasteType:l}=a,{range:u}=t||{},{range:p,unitId:d,subUnitId:h}=i;return this._generateMutations(p,{copyType:s,pasteType:l,copyRange:u,unitId:d,subUnitId:h})},onPastePlainText:(t,i)=>{const r=this._filterPlainText(i);if(Ee(i)&&r){const{range:a,unitId:s,subUnitId:l}=t,{ranges:[u],mapFunc:p}=y.virtualizeDiscreteRanges([a]),d=[],h=[];return o.Range.foreach(u,(I,S)=>{const{row:P,col:R}=p(I,S),T=this._hyperLinkModel.getHyperLinkByLocation(s,l,P,R);T&&d.push({id:v.RemoveHyperLinkMutation.id,params:{unitId:s,subUnitId:l,id:T.id}}),T&&h.push({id:v.AddHyperLinkMutation.id,params:{unitId:s,subUnitId:l,link:T}})}),{redos:d,undos:h}}return{undos:[],redos:[]}},priority:99})}_collect(t,i,r){const a=new o.ObjectMatrix;this._copyInfo={unitId:t,subUnitId:i,matrix:a};const s=this._injector.invoke(p=>y.rangeToDiscreteRange(r,p,t,i));if(!s)return;const{rows:l,cols:u}=s;l.forEach((p,d)=>{u.forEach((h,I)=>{var P;const S=this._hyperLinkModel.getHyperLinkByLocation(t,i,p,h);a.setValue(d,I,(P=S==null?void 0:S.id)!=null?P:"")})})}_generateMutations(t,i){if(!this._copyInfo)return{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!i.copyRange)return{redos:[],undos:[]};if([y.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,y.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,y.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,y.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(i.pasteType))return{redos:[],undos:[]};const{unitId:a,subUnitId:s}=this._copyInfo,l=[],u=[],{ranges:[p,d],mapFunc:h}=y.virtualizeDiscreteRanges([i.copyRange,t]);return y.getRepeatRange(p,d,!0).forEach(({startRange:S})=>{var P;(P=this._copyInfo)==null||P.matrix.forValue((R,T,c)=>{const D=o.Rectangle.getPositionRange({startRow:R,endRow:R,startColumn:T,endColumn:T},S),B=this._hyperLinkModel.getHyperLink(a,s,c),{row:M,col:U}=h(D.startRow,D.startColumn),j=this._hyperLinkModel.getHyperLinkByLocation(i.unitId,i.subUnitId,M,U),V=o.Tools.generateRandomId();j&&l.push({id:v.RemoveHyperLinkMutation.id,params:{unitId:i.unitId,subUnitId:i.subUnitId,id:j.id}}),B&&(l.push({id:v.AddHyperLinkMutation.id,params:{unitId:i.unitId,subUnitId:i.subUnitId,link:{...B,id:V,row:M,column:U}}}),u.push({id:v.RemoveHyperLinkMutation.id,params:{unitId:i.unitId,subUnitId:i.subUnitId,id:V}})),j&&u.push({id:v.AddHyperLinkMutation.id,params:{unitId:i.unitId,subUnitId:i.subUnitId,link:j}})})}),{redos:l,undos:u}}},g.SheetsHyperLinkCopyPasteController=Yt([Pe(0,y.ISheetClipboardService),Pe(1,o.Inject(v.HyperLinkModel)),Pe(2,o.Inject(o.Injector)),Pe(3,o.Inject(g.SheetsHyperLinkResolverService))],g.SheetsHyperLinkCopyPasteController);var m=(e=>(e.EDITING="editing",e.VIEWING="viewing",e.ZEN_EDITOR="zen_mode",e))(m||{});class je extends o.Disposable{constructor(){super(...arguments);W(this,"_customHyperLinks",new Map)}isBuiltInLinkType(t){return t!==v.SheetHyperLinkType.URL}getOptions(){return Array.from(this._customHyperLinks.values()).map(({option:t})=>t)}findCustomHyperLink(t){return Array.from(this._customHyperLinks.values()).find(r=>r.match(t))}registerCustomHyperLink(t){this._customHyperLinks.set(t.type,t)}getCustomHyperLink(t){return this._customHyperLinks.get(t)}removeCustomHyperLink(t){const{_customHyperLinks:i}=this;i.delete(t)}dispose(){super.dispose(),this._customHyperLinks.clear()}}const rt={cellLinkEdit:"univer-cell-link-edit",cellLinkEditButtons:"univer-cell-link-edit-buttons"},Le=()=>{var Ct;const[e,n]=C.useState(""),[t,i]=C.useState(!1),[r,a]=C.useState(""),[s,l]=C.useState(!0),[u,p]=C.useState(v.SheetHyperLinkType.URL),[d,h]=C.useState(""),I=o.useDependency(o.LocaleService),S=o.useDependency(X.IDefinedNamesService),P=o.useDependency(y.IEditorBridgeService),R=o.useDependency(o.IUniverInstanceService),T=o.useDependency(g.SheetsHyperLinkPopupService),c=b.useObservable(T.currentEditing$),D=o.useDependency(v.SheetsHyperLinkParserService),B=o.useDependency(g.SheetsHyperLinkResolverService),M=o.useDependency(o.ICommandService),U=o.useDependency(je),j=C.useMemo(()=>U.getOptions(),[U]),V=o.useDependency(b.IZenZoneService),J=o.useDependency(pe.IRenderManagerService),_e=o.useDependency(y.IMarkSelectionService),$e=o.useDependency(he.DocSelectionManagerService),ae=o.useDependency(o.IContextService),Ie=o.useDependency(o.ThemeService),fe=o.useDependency(he.DocSelectionManagerService),me=C.useRef({}),ce=C.useMemo(()=>{if(!U.isBuiltInLinkType(u))return U.getCustomHyperLink(u)},[U,u]),[Z,An]=C.useState(!1),[ye,ze]=C.useState(!1),x=C.useRef(!1),G=R.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),Bn=(G==null?void 0:G.getActiveSheet().getSheetId())||"",te=C.useCallback(_=>{a(_.replaceAll(o.DataStreamTreeTokenType.CUSTOM_RANGE_START,"").replaceAll(o.DataStreamTreeTokenType.CUSTOM_RANGE_END,""))},[a]);C.useEffect(()=>{var _,k,O,N,A,z,Et,Pt,Lt,Rt,Tt,Ot,Dt,kt,bt,wt,Nt;if((c==null?void 0:c.row)!==void 0&&c.col!==void 0){const{customRange:le,row:Qe,col:et}=c;let{label:Q}=c;typeof Q=="number"&&(Q=`${Q}`);let q;if(le)q={id:(_=le==null?void 0:le.rangeId)!=null?_:"",display:Q!=null?Q:"",payload:(O=(k=le==null?void 0:le.properties)==null?void 0:k.url)!=null?O:"",row:Qe,column:et};else if(c.type===m.VIEWING){const H=R.getUnit(c.unitId),ie=H==null?void 0:H.getSheetBySheetId(c.subUnitId),$=ie==null?void 0:ie.getCellRaw(c.row,c.col),de=(z=(A=(N=$==null?void 0:$.p)==null?void 0:N.body)==null?void 0:A.customRanges)==null?void 0:z.find(Ut=>{var Ht;return Ut.rangeType===o.CustomRangeType.HYPERLINK&&((Ht=Ut.properties)==null?void 0:Ht.url)}),Ce=$==null?void 0:$.v;$&&(!o.BuildTextUtils.transform.isEmptyDocument((Pt=(Et=$.p)==null?void 0:Et.body)==null?void 0:Pt.dataStream)||o.Tools.isDefine(Ce))&&l(!1),q={id:"",display:"",payload:(Rt=(Lt=de==null?void 0:de.properties)==null?void 0:Lt.url)!=null?Rt:"",row:Qe,column:et}}else{const H=R.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC),ie=$e.getActiveTextRange(),$=H==null?void 0:H.getBody(),de=ie&&$?ie:null,Ce=de&&((Ot=o.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(de,(Tt=$==null?void 0:$.customRanges)!=null?Tt:[]))==null?void 0:Ot[0]);l(!1),q={id:"",display:Q!=null?Q:"",payload:(kt=(Dt=Ce==null?void 0:Ce.properties)==null?void 0:Dt.url)!=null?kt:"",row:Qe,column:et}}n(q.id);const Mt=U.findCustomHyperLink(q);if(Mt){const H=Mt.convert(q);p(H.type),h(H.payload),te(H.display);return}te(q.display);const ne=D.parseHyperLink(q.payload);switch(p(ne.type===v.SheetHyperLinkType.INVALID?v.SheetHyperLinkType.RANGE:ne.type),ne.type){case v.SheetHyperLinkType.URL:{h(ne.url),ne.url===q.display&&(x.current=!0);break}case v.SheetHyperLinkType.RANGE:{const H=ne.searchObj,ie=H.gid&&(Nt=(wt=(bt=R.getUnit(c.unitId))==null?void 0:bt.getSheetBySheetId(H.gid))==null?void 0:wt.getName())!=null?Nt:"",$=X.serializeRangeWithSheet(ie,X.deserializeRangeWithSheet(H.range).range);h($),$===q.display&&(x.current=!0);break}case v.SheetHyperLinkType.SHEET:{const H=ne.searchObj;h(H.gid);break}case v.SheetHyperLinkType.DEFINE_NAME:{const H=ne.searchObj;h(H.rangeid);break}default:h("");break}}},[c,B,U,$e,R]),C.useEffect(()=>{let _=null;if(c&&!c.customRangeId&&c.type===m.VIEWING&&o.Tools.isDefine(c.row)&&o.Tools.isDefine(c.col)){const k=R.getUnit(c.unitId,o.UniverInstanceType.UNIVER_SHEET),O=k==null?void 0:k.getSheetBySheetId(c.subUnitId),N=O==null?void 0:O.getMergedCell(c.row,c.col),A=new o.ColorKit(Ie.getCurrentTheme().hyacinth500).toRgb();_=_e.addShape({range:N!=null?N:{startColumn:c.col,endColumn:c.col,startRow:c.row,endRow:c.row},style:{fill:`rgb(${A.r}, ${A.g}, ${A.b}, 0.12)`,strokeWidth:1,stroke:"#FFBD37",widgets:{}},primary:null},[],-1)}return()=>{_&&_e.removeShape(_)}},[c,_e,Ie,R]),C.useEffect(()=>{ze(u===v.SheetHyperLinkType.RANGE)},[u]),C.useEffect(()=>{const _=(c==null?void 0:c.type)===m.ZEN_EDITOR?J.getRenderById(o.DOCS_ZEN_EDITOR_UNIT_ID_KEY):J.getRenderById(P.getCurrentEditorId()),k=new o.DisposableCollection;if(_){const O=_.with(ee.DocSelectionRenderService);O.setReserveRangesStatus(!0),k.add(()=>{O.setReserveRangesStatus(!1)})}return()=>{P.disableForceKeepVisible(),k.dispose()}},[c==null?void 0:c.type,P,J]),C.useEffect(()=>(T.setIsKeepVisible(ye),()=>{T.setIsKeepVisible(!1)}),[ye,T]),C.useEffect(()=>()=>{V.temporaryHidden&&(V.show(),ae.setContextValue(o.FOCUSING_SHEET,!1))},[ae,V]),C.useEffect(()=>{if(ye)return P.enableForceKeepVisible(),()=>{P.disableForceKeepVisible()}},[ye,P]);const $n=[{label:I.t("hyperLink.form.link"),value:v.SheetHyperLinkType.URL},{label:I.t("hyperLink.form.range"),value:v.SheetHyperLinkType.RANGE},{label:I.t("hyperLink.form.worksheet"),value:v.SheetHyperLinkType.SHEET},{label:I.t("hyperLink.form.definedName"),value:v.SheetHyperLinkType.DEFINE_NAME},...j];if(!G)return;const Vn=G.getHiddenWorksheets(),qe=G.getSheets().map(_=>({label:_.getName(),value:_.getSheetId()})).filter(_=>Vn.indexOf(_.value)===-1),Xe=Object.values((Ct=S.getDefinedNameMap(G.getUnitId()))!=null?Ct:{}).map(_=>({label:_.name,value:_.id})),yt=(_,k)=>{if(_===v.SheetHyperLinkType.URL)return Vt(k);if(_===v.SheetHyperLinkType.RANGE){const O=X.deserializeRangeWithSheet(k),N=G.getSheetBySheetName(O.sheetName);if(N)return`#gid=${N.getSheetId()}&range=${X.serializeRange(O.range)}`}return`#${_}=${k}`},jn=b.useEvent(_=>{var A;const O=_.split(",").map(X.deserializeRangeWithSheet)[0];if(!O||!o.isValidRange(O.range))return;O.sheetName||(O.sheetName=((A=G.getActiveSheet())==null?void 0:A.getName())||"");const N=X.serializeRangeToRefString(O);h(N),N&&(x.current||!r)&&(te(N),x.current=!0)}),Je=async()=>{if(s&&!r||!d||u===v.SheetHyperLinkType.URL&&!Ee(d)){An(!0);return}if(c)if(e){const _=c.type===m.ZEN_EDITOR||c.type===m.EDITING?v.UpdateRichHyperLinkCommand.id:v.UpdateHyperLinkCommand.id;await M.executeCommand(_,{id:e,unitId:c.unitId,subUnitId:c.subUnitId,payload:{display:s?r:"",payload:yt(u,d)},row:c.row,column:c.col,documentId:c.type===m.ZEN_EDITOR?o.DOCS_ZEN_EDITOR_UNIT_ID_KEY:P.getCurrentEditorId()})}else{const _=c.type===m.ZEN_EDITOR||c.type===m.EDITING?v.AddRichHyperLinkCommand.id:v.AddHyperLinkCommand.id;await M.executeCommand(_,{unitId:c.unitId,subUnitId:c.subUnitId,link:{id:o.generateRandomId(),row:c.row,column:c.col,payload:yt(u,d),display:s?r:""},documentId:c.type===m.ZEN_EDITOR?o.DOCS_ZEN_EDITOR_UNIT_ID_KEY:P.getCurrentEditorId()})}if((c==null?void 0:c.type)===m.VIEWING){await M.executeCommand(E.SetWorksheetActiveOperation.id,{unitId:c.unitId,subUnitId:c.subUnitId});const _=1;await M.executeCommand(y.ScrollToRangeOperation.id,{range:{startRow:Math.max(c.row-_,0),endRow:c.row+_,startColumn:Math.max(c.col-_,0),endColumn:c.col+_}})}M.executeCommand(ve.id)},xn=_=>{var O;if(u!==v.SheetHyperLinkType.RANGE)return;const k=(O=me.current)==null?void 0:O.handleOutClick;k&&k(_,()=>ze(!1))};return c?f.jsxs("div",{className:rt.cellLinkEdit,style:{display:t?"none":"block"},onClick:xn,children:[s?f.jsx(w.FormLayout,{label:I.t("hyperLink.form.label"),error:Z&&!r?I.t("hyperLink.form.inputError"):"",children:f.jsx(w.Input,{value:r,onChange:_=>{te(_),x.current=!1},placeholder:I.t("hyperLink.form.labelPlaceholder"),autoFocus:!0,onKeyDown:_=>{_.keyCode===b.KeyCode.ENTER&&Je()}})}):null,f.jsx(w.FormLayout,{label:I.t("hyperLink.form.type"),children:f.jsx(w.Select,{options:$n,value:u,onChange:_=>{p(_),h("")}})}),u===v.SheetHyperLinkType.URL&&f.jsx(w.FormLayout,{error:Z?d?Ee(d)?"":I.t("hyperLink.form.linkError"):I.t("hyperLink.form.inputError"):"",children:f.jsx(w.Input,{value:d,onChange:_=>{h(_),_&&(x.current||!r||r===d)&&(te(_),x.current=!0)},placeholder:I.t("hyperLink.form.linkPlaceholder"),autoFocus:!0,onKeyDown:_=>{_.keyCode===b.KeyCode.ENTER&&Je()}})}),u===v.SheetHyperLinkType.RANGE&&f.jsx(w.FormLayout,{error:Z&&!d?I.t("hyperLink.form.inputError"):"",children:f.jsx(At.RangeSelector,{unitId:G.getUnitId(),subUnitId:Bn,isOnlyOneRange:!0,isSupportAcrossSheet:!0,initValue:d,onChange:jn,isFocus:ye,onFocus:()=>ze(!0),actions:me.current,onRangeSelectorDialogVisibleChange:async _=>{var k,O;if(_)c.type===m.ZEN_EDITOR&&(V.hide(),ae.setContextValue(o.FOCUSING_SHEET,!0)),c.type!==m.VIEWING&&P.enableForceKeepVisible(),i(!0);else{if(await B.navigateToRange(c.unitId,c.subUnitId,{startRow:c.row,endRow:c.row,startColumn:c.col,endColumn:c.col},!0),c.type===m.ZEN_EDITOR){await M.executeCommand(E.SetSelectionsOperation.id,{unitId:c.unitId,subUnitId:c.subUnitId,selections:[{range:{startRow:c.row,endRow:c.row,startColumn:c.col,endColumn:c.col}}]}),V.show(),ae.setContextValue(o.FOCUSING_SHEET,!1);const N=(k=J.getRenderById(o.DOCS_ZEN_EDITOR_UNIT_ID_KEY))==null?void 0:k.with(ee.DocBackScrollRenderController),A=(O=fe.getTextRanges({unitId:o.DOCS_ZEN_EDITOR_UNIT_ID_KEY,subUnitId:o.DOCS_ZEN_EDITOR_UNIT_ID_KEY}))==null?void 0:O[0];N&&A&&(N.scrollToRange(A),fe.refreshSelection({unitId:o.DOCS_ZEN_EDITOR_UNIT_ID_KEY,subUnitId:o.DOCS_ZEN_EDITOR_UNIT_ID_KEY}))}P.disableForceKeepVisible(),i(!1)}}})}),u===v.SheetHyperLinkType.SHEET&&f.jsx(w.FormLayout,{error:Z&&!d?I.t("hyperLink.form.selectError"):"",children:f.jsx(w.Select,{options:qe,value:d,onChange:_=>{var N,A;h(_);const k=(N=qe.find(z=>z.value===_))==null?void 0:N.label,O=(A=qe.find(z=>z.value===d))==null?void 0:A.label;k&&(x.current||!r||r===O)&&(te(k),x.current=!0)}})}),u===v.SheetHyperLinkType.DEFINE_NAME&&f.jsx(w.FormLayout,{error:Z&&!d?I.t("hyperLink.form.selectError"):"",children:f.jsx(w.Select,{options:Xe,value:d,onChange:_=>{var N,A;h(_);const k=(N=Xe.find(z=>z.value===_))==null?void 0:N.label,O=(A=Xe.find(z=>z.value===d))==null?void 0:A.label;k&&(x.current||!r||r===O)&&(te(k),x.current=!0)}})}),(ce==null?void 0:ce.Form)&&f.jsx(ce.Form,{linkId:e,payload:d,display:r,showError:Z,setByPayload:x,setDisplay:_=>{te(_),x.current=!0},setPayload:h}),f.jsxs("div",{className:rt.cellLinkEditButtons,children:[f.jsx(w.Button,{onClick:()=>{c&&B.navigateToRange(c.unitId,c.subUnitId,{startRow:c.row,endRow:c.row,startColumn:c.col,endColumn:c.col},!0),M.executeCommand(ve.id)},children:I.t("hyperLink.form.cancel")}),f.jsx(w.Button,{type:"primary",style:{marginLeft:8},onClick:async()=>{Je()},children:I.t("hyperLink.form.ok")})]})]}):null};Le.componentKey="univer.sheet.cell-link-edit";var F=function(){return F=Object.assign||function(e){for(var n,t=1,i=arguments.length;t<i;t++){n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},F.apply(this,arguments)},Gt=function(e,n){var t={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&n.indexOf(i)<0&&(t[i]=e[i]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,i=Object.getOwnPropertySymbols(e);r<i.length;r++)n.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(t[i[r]]=e[i[r]]);return t},re=C.forwardRef(function(e,n){var t=e.icon,i=e.id,r=e.className,a=e.extend,s=Gt(e,["icon","id","className","extend"]),l="univerjs-icon univerjs-icon-".concat(i," ").concat(r||"").trim(),u=C.useRef("_".concat(Xt()));return ot(t,"".concat(i),{defIds:t.defIds,idSuffix:u.current},F({ref:n,className:l},s),a)});function ot(e,n,t,i,r){return C.createElement(e.tag,F(F({key:n},zt(e,t,r)),i),(qt(e,t).children||[]).map(function(a,s){return ot(a,"".concat(n,"-").concat(e.tag,"-").concat(s),t,void 0,r)}))}function zt(e,n,t){var i=F({},e.attrs);t!=null&&t.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=t.colorChannel1);var r=n.defIds;return!r||r.length===0||(e.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+n.idSuffix),Object.entries(i).forEach(function(a){var s=a[0],l=a[1];typeof l=="string"&&(i[s]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),i}function qt(e,n){var t,i=n.defIds;return!i||i.length===0?e:e.tag==="defs"&&(!((t=e.children)===null||t===void 0)&&t.length)?F(F({},e),{children:e.children.map(function(r){return typeof r.attrs.id=="string"&&i&&i.indexOf(r.attrs.id)>-1?F(F({},r),{attrs:F(F({},r.attrs),{id:r.attrs.id+n.idSuffix})}):r})}):e}function Xt(){return Math.random().toString(36).substring(2,8)}re.displayName="UniverIcon";var Jt={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M7.9999 1.12915C8.03875 1.12915 8.07673 1.13284 8.11352 1.13989H12.2599C13.6958 1.13989 14.8599 2.30395 14.8599 3.73989V7.88619C14.867 7.92301 14.8707 7.96102 14.8707 7.9999C14.8707 8.03878 14.867 8.0768 14.8599 8.11362V12.2599C14.8599 13.6958 13.6958 14.8599 12.2599 14.8599H8.11362C8.0768 14.867 8.03878 14.8707 7.9999 14.8707C7.96102 14.8707 7.92301 14.867 7.88619 14.8599H3.73989C2.30396 14.8599 1.13989 13.6958 1.13989 12.2599V8.11352C1.13284 8.07673 1.12915 8.03875 1.12915 7.9999C1.12915 7.96106 1.13284 7.92308 1.13989 7.88629V3.73989C1.13989 2.30396 2.30395 1.13989 3.73989 1.13989H7.88629C7.92308 1.13284 7.96106 1.12915 7.9999 1.12915ZM2.33989 8.5999V12.2599C2.33989 13.0331 2.9667 13.6599 3.73989 13.6599H7.3999V8.5999H2.33989ZM7.3999 7.3999H2.33989V3.73989C2.33989 2.9667 2.96669 2.33989 3.73989 2.33989H7.3999V7.3999ZM8.5999 8.5999V13.6599H12.2599C13.0331 13.6599 13.6599 13.0331 13.6599 12.2599V8.5999H8.5999ZM13.6599 7.3999H8.5999V2.33989H12.2599C13.0331 2.33989 13.6599 2.96669 13.6599 3.73989V7.3999Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Re=C.forwardRef(function(e,n){return C.createElement(re,Object.assign({},e,{id:"all-border-single",ref:n,icon:Jt}))});Re.displayName="AllBorderSingle";var Qt={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"}}]},st=C.forwardRef(function(e,n){return C.createElement(re,Object.assign({},e,{id:"copy-single",ref:n,icon:Qt}))});st.displayName="CopySingle";var en={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"}}]},xe=C.forwardRef(function(e,n){return C.createElement(re,Object.assign({},e,{id:"link-single",ref:n,icon:en}))});xe.displayName="LinkSingle";var tn={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"}}]},at=C.forwardRef(function(e,n){return C.createElement(re,Object.assign({},e,{id:"unlink-single",ref:n,icon:tn}))});at.displayName="UnlinkSingle";var nn={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"}}]},ct=C.forwardRef(function(e,n){return C.createElement(re,Object.assign({},e,{id:"write-single",ref:n,icon:nn}))});ct.displayName="WriteSingle";var rn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"#35BD4B",d:"M3.4535 1.12549C2.7002 1.12549 2.08954 1.73615 2.08954 2.48945V13.5104C2.08954 14.2637 2.7002 14.8744 3.4535 14.8744H12.5465C13.2998 14.8744 13.9105 14.2637 13.9105 13.5104V5.0992L10.0091 1.12549H3.4535Z"}},{tag:"path",attrs:{fill:"#32A846",d:"M10.0075 1.12549L13.9104 5.09842H10.6742C10.306 5.09842 10.0075 4.79994 10.0075 4.43175V1.12549Z"}},{tag:"path",attrs:{fill:"#fff",d:"M7.8088 10.2949L6.3764 12.403C6.26259 12.5705 6.03455 12.614 5.86705 12.5002C5.69955 12.3864 5.65603 12.1584 5.76984 11.9909L7.3655 9.64252L5.94042 7.54519C5.82661 7.37769 5.87013 7.14964 6.03763 7.03583C6.20512 6.92202 6.43317 6.96555 6.54698 7.13304L7.8088 8.9901L9.07062 7.13304C9.18443 6.96555 9.41248 6.92202 9.57997 7.03583C9.74747 7.14964 9.79099 7.37769 9.67718 7.54519L8.2521 9.64252L9.84776 11.9909C9.96157 12.1584 9.91805 12.3864 9.75055 12.5002C9.58305 12.614 9.35501 12.5705 9.2412 12.403L7.8088 10.2949Z",fillRule:"evenodd",clipRule:"evenodd"}}]},lt=C.forwardRef(function(e,n){return C.createElement(re,Object.assign({},e,{id:"xlsx",ref:n,icon:rn}))});lt.displayName="Xlsx";function ut(e){var n,t,i="";if(typeof e=="string"||typeof e=="number")i+=e;else if(typeof e=="object")if(Array.isArray(e)){var r=e.length;for(n=0;n<r;n++)e[n]&&(t=ut(e[n]))&&(i&&(i+=" "),i+=t)}else for(t in e)e[t]&&(i&&(i+=" "),i+=t);return i}function dt(){for(var e,n,t=0,i="",r=arguments.length;t<r;t++)(e=arguments[t])&&(n=ut(e))&&(i&&(i+=" "),i+=n);return i}const K={cellLink:"univer-cell-link",cellLinkType:"univer-cell-link-type",cellLinkContent:"univer-cell-link-content",cellLinkContentError:"univer-cell-link-content-error",cellLinkUrl:"univer-cell-link-url",cellLinkOperations:"univer-cell-link-operations",cellLinkOperation:"univer-cell-link-operation",cellLinkOperationError:"univer-cell-link-operation-error"},on={[v.SheetHyperLinkType.URL]:f.jsx(xe,{}),[v.SheetHyperLinkType.SHEET]:f.jsx(lt,{}),[v.SheetHyperLinkType.RANGE]:f.jsx(Re,{}),[v.SheetHyperLinkType.DEFINE_NAME]:f.jsx(Re,{}),[v.SheetHyperLinkType.INVALID]:f.jsx(Re,{})},pt=e=>{var B,M;const n=o.useDependency(g.SheetsHyperLinkPopupService),t=o.useDependency(o.ICommandService),i=o.useDependency(b.IMessageService),r=o.useDependency(o.LocaleService),a=o.useDependency(g.SheetsHyperLinkResolverService),s=o.useDependency(y.IEditorBridgeService),l=o.useDependency(v.SheetsHyperLinkParserService),u=o.useDependency(b.IZenZoneService),{customRange:p,row:d,col:h,unitId:I,subUnitId:S,editPermission:P,copyPermission:R,type:T}=e;if(!((B=p==null?void 0:p.properties)!=null&&B.url))return null;const c=l.parseHyperLink((M=p.properties.url)!=null?M:""),D=c.type===v.SheetHyperLinkType.INVALID;return f.jsxs("div",{className:K.cellLink,onClick:()=>n.hideCurrentPopup(),children:[f.jsxs("div",{className:dt(K.cellLinkContent,{[K.cellLinkContentError]:D}),onClick:()=>{u.visible||D||a.navigate(c)},children:[f.jsx("div",{className:K.cellLinkType,children:on[c.type]}),f.jsx(w.Tooltip,{showIfEllipsis:!0,title:c.name,asChild:!0,children:f.jsx("span",{className:K.cellLinkUrl,children:c.name})})]}),f.jsxs("div",{className:K.cellLinkOperations,children:[R&&f.jsx("div",{className:dt(K.cellLinkOperation,{[K.cellLinkOperationError]:D}),onClick:()=>{if(!D){if(c.type!==v.SheetHyperLinkType.URL){const U=new URL(window.location.href);U.hash=c.url.slice(1),navigator.clipboard.writeText(U.href)}else navigator.clipboard.writeText(c.url);i.show({content:r.t("hyperLink.message.coped"),type:w.MessageType.Info})}},children:f.jsx(w.Tooltip,{placement:"bottom",title:r.t("hyperLink.popup.copy"),children:f.jsx(st,{})})}),P&&f.jsxs(f.Fragment,{children:[f.jsx("div",{className:K.cellLinkOperation,onClick:()=>{t.executeCommand(Oe.id,{unitId:I,subUnitId:S,row:d,col:h,customRangeId:p.rangeId,type:T})},children:f.jsx(w.Tooltip,{placement:"bottom",title:r.t("hyperLink.popup.edit"),children:f.jsx(ct,{})})}),f.jsx("div",{className:K.cellLinkOperation,onClick:()=>{const U=T===m.EDITING||T===m.ZEN_EDITOR?v.CancelRichHyperLinkCommand.id:v.CancelHyperLinkCommand.id;t.syncExecuteCommand(U,{unitId:I,subUnitId:S,id:p.rangeId,row:d,column:h,documentId:T===m.ZEN_EDITOR?o.DOCS_ZEN_EDITOR_UNIT_ID_KEY:s.getCurrentEditorId()})&&n.hideCurrentPopup(void 0,!0)},children:f.jsx(w.Tooltip,{placement:"bottom",title:r.t("hyperLink.popup.cancel"),children:f.jsx(at,{})})})]})]})]})},Te=()=>{var r,a;const e=o.useDependency(g.SheetsHyperLinkPopupService),[n,t]=C.useState(null),i=o.useDependency(o.IUniverInstanceService);if(C.useEffect(()=>{t(e.currentPopup);const s=e.currentPopup$.subscribe(l=>{t(l)});return()=>{s.unsubscribe()}},[e.currentPopup,e.currentPopup$]),!n)return null;if(n.showAll){const s=i.getUnit(n.unitId,o.UniverInstanceType.UNIVER_SHEET),l=s==null?void 0:s.getSheetBySheetId(n.subUnitId),u=l==null?void 0:l.getCell(n.row,n.col),p=(a=(r=u==null?void 0:u.p)==null?void 0:r.body)==null?void 0:a.customRanges;return p!=null&&p.length?f.jsx("div",{children:p.map(d=>f.jsx(pt,{...n,customRange:d},d.rangeId))}):null}return f.jsx(pt,{...n})};Te.componentKey="univer.sheet.cell-link-popup";var sn=Object.defineProperty,an=Object.getOwnPropertyDescriptor,cn=(e,n,t,i)=>{for(var r=i>1?void 0:i?an(n,t):n,a=e.length-1,s;a>=0;a--)(s=e[a])&&(r=(i?s(n,t,r):s(r))||r);return i&&r&&sn(n,t,r),r},oe=(e,n)=>(t,i)=>n(t,i,e);const ht=(e,n)=>{var t,i;return e.unitId===n.unitId&&e.subUnitId===n.subUnitId&&e.row===n.row&&e.col===n.col&&((t=e.customRange)==null?void 0:t.rangeId)===((i=n.customRange)==null?void 0:i.rangeId)&&e.type===n.type};g.SheetsHyperLinkPopupService=class extends o.Disposable{constructor(t,i,r,a,s,l,u){super();W(this,"_currentPopup",null);W(this,"_currentPopup$",new L.Subject);W(this,"currentPopup$",this._currentPopup$.asObservable());W(this,"_currentEditingPopup",null);W(this,"_currentEditing$",new L.BehaviorSubject(null));W(this,"currentEditing$",this._currentEditing$.asObservable());W(this,"_isKeepVisible",!1);this._sheetCanvasPopManagerService=t,this._injector=i,this._univerInstanceService=r,this._editorBridgeService=a,this._textSelectionManagerService=s,this._docCanvasPopManagerService=l,this._zenZoneService=u,this.disposeWithMe(()=>{this.hideCurrentPopup(),this.endEditing(),this._currentEditing$.complete(),this._currentPopup$.complete()})}get currentPopup(){return this._currentPopup}get currentEditing(){return this._currentEditing$.getValue()}setIsKeepVisible(t){this._isKeepVisible=t}getIsKeepVisible(){return this._isKeepVisible}showPopup(t){if(this._currentPopup&&ht(t,this._currentPopup)||(this.hideCurrentPopup(void 0,!0),t.type!==m.ZEN_EDITOR&&this._zenZoneService.visible))return;const i=this._currentEditing$.getValue();if(i&&ht(t,i))return;const{unitId:r,subUnitId:a,row:s,col:l,customRangeRect:u,customRange:p}=t;let d;const h={componentKey:Te.componentKey,direction:"bottom",onClickOutside:()=>{this.hideCurrentPopup()},onClick:()=>{this.hideCurrentPopup(t.type,!0)}};if(t.type===m.EDITING){if(!p)return;d=u&&this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(u,h)}else if(t.type===m.ZEN_EDITOR){if(!p)return;d=this._docCanvasPopManagerService.attachPopupToRange({startOffset:p.startIndex,endOffset:p.endIndex+1,collapsed:!1},h,o.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}else if(t.showAll)d=this._sheetCanvasPopManagerService.attachPopupToCell(t.row,t.col,h,r,a);else{if(!p)return;d=u&&this._sheetCanvasPopManagerService.attachPopupByPosition(u,h,t)}d&&(this._currentPopup={unitId:r,subUnitId:a,disposable:d,row:s,col:l,editPermission:!!t.editPermission,copyPermission:!!t.copyPermission,customRange:p,type:t.type,showAll:t.showAll},this._currentPopup$.next(this._currentPopup))}hideCurrentPopup(t,i){var r,a;this._currentPopup&&((!t||t===this._currentPopup.type)&&this._currentPopup.disposable.canDispose()||i)&&((a=(r=this._currentPopup)==null?void 0:r.disposable)==null||a.dispose(),this._currentPopup=null,this._currentPopup$.next(null))}_getEditingRange(){var r,a,s;const t=this._editorBridgeService.isVisible().visible,i=this._editorBridgeService.getEditCellState();if(t&&i){const l=this._textSelectionManagerService.getActiveTextRange(),u=(r=i.documentLayoutObject.documentModel)==null?void 0:r.getBody();if(!u)return null;if(!l||l.collapsed)return{startOffset:0,endOffset:u.dataStream.length-2,collapsed:u.dataStream.length-2===0,label:o.BuildTextUtils.transform.getPlainText(u.dataStream)};const p=o.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(l,(s=(a=u.customRanges)==null?void 0:a.filter(I=>I.rangeType===o.CustomRangeType.HYPERLINK))!=null?s:[]);let d=l.startOffset,h=l.endOffset;return p.forEach(I=>{d=Math.min(d,I.startIndex),h=Math.max(h,I.endIndex+1)}),{startOffset:d,endOffset:h,collapsed:d===h,label:o.BuildTextUtils.transform.getPlainText(u.dataStream.slice(d,h))}}return null}get _editPopup(){return{componentKey:Le.componentKey,direction:"vertical",onClickOutside:()=>{this.getIsKeepVisible()||this.endEditing()},onContextMenu:()=>{this.getIsKeepVisible()||this.endEditing()},hiddenType:"hide"}}startAddEditing(t){var s,l,u,p,d;const{unitId:i,subUnitId:r,type:a}=t;if(a===m.ZEN_EDITOR){const h=this._univerInstanceService.getUnit(o.DOCS_ZEN_EDITOR_UNIT_ID_KEY,o.UniverInstanceType.UNIVER_DOC);if(!h)return;const I=this._textSelectionManagerService.getActiveTextRange();if(!I)return;this._currentEditingPopup=this._docCanvasPopManagerService.attachPopupToRange(I,this._editPopup,o.DOCS_ZEN_EDITOR_UNIT_ID_KEY);const S=(s=h.getBody())==null?void 0:s.dataStream.slice(I.startOffset,I.endOffset);this._currentEditing$.next({...t,label:S})}else if(a===m.EDITING){const h=this._getEditingRange();if(!h)return;this._textSelectionManagerService.replaceDocRanges([{...h}],{unitId:o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY});const I=this._injector.get(pe.IRenderManagerService).getRenderById(o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(!I)return;const S=ee.calcDocRangePositions(h,I);if(!(S!=null&&S.length))return;this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(S.pop(),this._editPopup,i,r),this._currentEditing$.next({...t,label:(l=h==null?void 0:h.label)!=null?l:""})}else{this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToCell(t.row,t.col,this._editPopup,i,r);const h=this._univerInstanceService.getUnit(i,o.UniverInstanceType.UNIVER_SHEET),I=h==null?void 0:h.getSheetBySheetId(r),S=I==null?void 0:I.getCellRaw(t.row,t.col);this._currentEditing$.next({...t,label:S!=null&&S.p?o.BuildTextUtils.transform.getPlainText((p=(u=S.p.body)==null?void 0:u.dataStream)!=null?p:""):((d=S==null?void 0:S.v)!=null?d:"").toString()})}}startEditing(t){var l,u,p,d,h,I;(l=this._currentEditingPopup)==null||l.dispose(),this.hideCurrentPopup(void 0,!0);const{unitId:i,subUnitId:r}=t;let a,s;if(t.type===m.ZEN_EDITOR){const S=this._univerInstanceService.getUnit(o.DOCS_ZEN_EDITOR_UNIT_ID_KEY,o.UniverInstanceType.UNIVER_DOC);if(a=(p=(u=S==null?void 0:S.getBody())==null?void 0:u.customRanges)==null?void 0:p.find(P=>P.rangeId===t.customRangeId),s=a?(d=S==null?void 0:S.getBody())==null?void 0:d.dataStream.slice(a.startIndex,a.endIndex+1):"",!a||!s)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:a.startIndex,endOffset:a.endIndex+1}]),this._currentEditingPopup=this._docCanvasPopManagerService.attachPopupToRange({startOffset:a.startIndex,endOffset:a.endIndex,collapsed:!1},this._editPopup,o.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}else if(t.type===m.EDITING){const S=y.getEditingCustomRangePosition(this._injector,t.unitId,t.subUnitId,t.row,t.col,t.customRangeId);if(!S||!((h=S.rects)!=null&&h.length))return;a=S.customRange,s=S.label,this._textSelectionManagerService.replaceTextRanges([{startOffset:a.startIndex,endOffset:a.endIndex+1}]),this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(S.rects.pop(),this._editPopup,i,r)}else{const S=this._univerInstanceService.getUnit(i,o.UniverInstanceType.UNIVER_SHEET),P=S==null?void 0:S.getSheetBySheetId(r),R=P==null?void 0:P.getCellRaw(t.row,t.col),T=S==null?void 0:S.getStyles().getStyleByCell(R),c=T==null?void 0:T.tr,D=y.getCustomRangePosition(this._injector,t.unitId,t.subUnitId,t.row,t.col,t.customRangeId);if(!D||!((I=D.rects)!=null&&I.length))return;a=D.customRange,s=D.label,c?this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToCell(t.row,t.col,this._editPopup,i,r):this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupByPosition(D.rects.pop(),this._editPopup,{unitId:i,subUnitId:r,row:t.row,col:t.col})}this._currentEditing$.next({...t,customRange:a,label:s})}endEditing(t){var r;const i=this._currentEditing$.getValue();i&&(!t||t===i.type)&&((r=this._currentEditingPopup)==null||r.dispose(),this._currentEditing$.next(null))}},g.SheetsHyperLinkPopupService=cn([oe(0,o.Inject(y.SheetCanvasPopManagerService)),oe(1,o.Inject(o.Injector)),oe(2,o.IUniverInstanceService),oe(3,y.IEditorBridgeService),oe(4,o.Inject(he.DocSelectionManagerService)),oe(5,o.Inject(ee.DocCanvasPopManagerService)),oe(6,b.IZenZoneService)],g.SheetsHyperLinkPopupService);var ge=(e=>(e[e.ALLOWED=0]="ALLOWED",e[e.DISABLED_BY_CELL=1]="DISABLED_BY_CELL",e[e.ALLOW_ON_EDITING=2]="ALLOW_ON_EDITING",e))(ge||{});const ln=new Set([o.DataValidationType.CHECKBOX,o.DataValidationType.LIST,o.DataValidationType.LIST_MULTIPLE]),Fe=(e,n,t,i)=>{var l,u;const r=n.getCell(t,i);if(r!=null&&r.f||r!=null&&r.si)return 1;const a=e.has(tt.SheetDataValidationModel)?e.get(tt.SheetDataValidationModel):null,s=a==null?void 0:a.getRuleByLocation(n.getUnitId(),n.getSheetId(),t,i);return s&&ln.has(s.type)?!0:(u=(l=r==null?void 0:r.p)==null?void 0:l.drawingsOrder)!=null&&u.length?2:0},un=e=>{const n=e.get(o.IUniverInstanceService).getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!n)return!0;const t=n.getActiveSheet(),i=e.get(E.SheetsSelectionsService).getCurrentSelections();if(!i.length)return!0;const r=i[0].range.startRow,a=i[0].range.startColumn;return Fe(e,t,r,a)===1},dn=e=>{const n=e.get(he.DocSelectionManagerService),t=e.get(o.IUniverInstanceService),i=n.getTextRanges();if(!(i!=null&&i.length))return!0;const r=t.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC);return!!(!r||i.every(s=>s.collapsed)||!r.getSelfOrHeaderFooterModel(i[0].segmentId).getBody())},Oe={type:o.CommandType.OPERATION,id:"sheet.operation.open-hyper-link-edit-panel",handler(e,n){if(!n)return!1;const t=e.get(g.SheetsHyperLinkPopupService);return n.customRangeId?t.startEditing(n):t.startAddEditing(n),!0}},ve={type:o.CommandType.OPERATION,id:"sheet.operation.close-hyper-link-popup",handler(e){return e.get(g.SheetsHyperLinkPopupService).endEditing(),!0}},De={type:o.CommandType.OPERATION,id:"sheet.operation.insert-hyper-link",handler(e){var h;const n=e.get(o.IUniverInstanceService),t=E.getSheetCommandTarget(n),i=e.get(y.IEditorBridgeService);if(!t)return!1;const r=e.get(o.ICommandService),s=e.get(E.SheetsSelectionsService).getCurrentLastSelection();if(!s)return!1;const l=s.range.startRow,u=s.range.startColumn,p=i.isVisible(),d=((h=n.getFocusedUnit())==null?void 0:h.getUnitId())===o.DOCS_ZEN_EDITOR_UNIT_ID_KEY;return r.executeCommand(Oe.id,{unitId:t.unitId,subUnitId:t.subUnitId,row:l,col:u,type:d?m.ZEN_EDITOR:p.visible?m.EDITING:m.VIEWING})}},se={type:o.CommandType.OPERATION,id:"sheet.operation.insert-hyper-link-toolbar",handler(e){if(un(e))return!1;const n=e.get(o.ICommandService);return e.get(g.SheetsHyperLinkPopupService).currentEditing?n.executeCommand(ve.id):n.executeCommand(De.id)}},Ze=(e,n=o.DOCS_ZEN_EDITOR_UNIT_ID_KEY)=>{var r;const t=e.get(o.IUniverInstanceService),i=(r=e.get(pe.IRenderManagerService).getRenderById(n))==null?void 0:r.with(ee.DocSelectionRenderService);return i?i.textSelectionInner$.pipe(L.map(()=>{const s=e.get(y.IEditorBridgeService).getEditCellState();if(!s)return!0;const l=E.getSheetCommandTarget(t,{unitId:s.unitId,subUnitId:s.sheetId});return!(l!=null&&l.worksheet)||Fe(e,l.worksheet,s.row,s.column)===1?!0:dn(e)})):L.of(!0)},gt=e=>{const n=y.getCurrentRangeDisable$(e,{workbookTypes:[E.WorkbookEditablePermission],worksheetTypes:[E.WorksheetEditPermission,E.WorksheetSetCellValuePermission,E.WorksheetInsertHyperlinkPermission],rangeTypes:[E.RangeProtectionPermissionEditPoint]},!0),t=e.get(o.IUniverInstanceService),i=e.get(E.SheetsSelectionsService),r=e.has(y.IEditorBridgeService)?e.get(y.IEditorBridgeService):null,a=t.focused$.pipe(L.filter(s=>!!s),L.map(s=>t.getUnit(s,o.UniverInstanceType.UNIVER_SHEET)),L.filter(s=>!!s),L.switchMap(s=>s.activeSheet$),L.switchMap(s=>i.selectionMoveEnd$.pipe(L.map(l=>s&&{selections:l,sheet:s}))),L.map(s=>{if(!s)return ge.DISABLED_BY_CELL;const{selections:l,sheet:u}=s;if(!l.length)return ge.DISABLED_BY_CELL;const p=l[0].range.startRow,d=l[0].range.startColumn;return Fe(e,u,p,d)}),L.switchMap(s=>{if(s===ge.DISABLED_BY_CELL)return L.of(!0);const l=(r?r.visible$:L.of(null)).pipe(L.map(p=>p!=null&&p.visible?o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY:void 0)),u=e.get(o.IContextService).subscribeContextValue$(o.FOCUSING_FX_BAR_EDITOR);return L.combineLatest([l,u]).pipe(L.switchMap(([p,d])=>p?d?L.of(!0):Ze(e,p):L.of(s===ge.ALLOW_ON_EDITING)))}));return n.pipe(L.distinctUntilChanged(),L.switchMap(s=>a.pipe(L.map(l=>s||l))))},ke={commandId:De.id,type:b.MenuItemType.BUTTON,title:"hyperLink.menu.add",icon:"LinkSingle"},be=e=>`${e}-zen-editor`,pn=e=>({...ke,id:ke.commandId,hidden$:b.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:gt(e)}),hn=e=>({...ke,id:be(ke.commandId),hidden$:b.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_DOC,o.DOCS_ZEN_EDITOR_UNIT_ID_KEY),disabled$:Ze(e)}),we={tooltip:"hyperLink.form.addTitle",commandId:se.id,type:b.MenuItemType.BUTTON,icon:"LinkSingle"},gn=e=>({...we,id:we.commandId,hidden$:b.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:gt(e)}),vn=e=>({...we,id:be(we.commandId),hidden$:b.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_DOC,o.DOCS_ZEN_EDITOR_UNIT_ID_KEY),disabled$:Ze(e)}),We={id:se.id,binding:b.KeyCode.K|b.MetaKeys.CTRL_COMMAND,preconditions:y.whenSheetEditorFocused};var Sn=Object.defineProperty,_n=Object.getOwnPropertyDescriptor,In=(e,n,t,i)=>{for(var r=i>1?void 0:i?_n(n,t):n,a=e.length-1,s;a>=0;a--)(s=e[a])&&(r=(i?s(n,t,r):s(r))||r);return i&&r&&Sn(n,t,r),r},vt=(e,n)=>(t,i)=>n(t,i,e);let Ne=class extends o.Disposable{constructor(e,n){super(),this._autoFillService=e,this._hyperLinkModel=n,this._initAutoFill()}_initAutoFill(){const e=()=>({redos:[],undos:[]}),n=(i,r)=>{const{source:a,target:s,unitId:l,subUnitId:u}=i,p=y.virtualizeDiscreteRanges([a,s]),[d,h]=p.ranges,{mapFunc:I}=p,S={row:d.startRow,col:d.startColumn},P=y.getAutoFillRepeatRange(d,h),R=[],T=[];return P.forEach(c=>{const D=c.repeatStartCell,B=c.relativeRange,M={startRow:S.row,startColumn:S.col,endColumn:S.col,endRow:S.row},U={startRow:D.row,startColumn:D.col,endColumn:D.col,endRow:D.row};o.Range.foreach(B,(j,V)=>{const J=o.Rectangle.getPositionRange({startRow:j,startColumn:V,endColumn:V,endRow:j},M),{row:_e,col:$e}=I(J.startRow,J.startColumn),ae=this._hyperLinkModel.getHyperLinkByLocation(l,u,_e,$e),Ie=o.Rectangle.getPositionRange({startRow:j,startColumn:V,endColumn:V,endRow:j},U),{row:fe,col:me}=I(Ie.startRow,Ie.startColumn),ce=o.Tools.generateRandomId(),Z=this._hyperLinkModel.getHyperLinkByLocation(l,u,fe,me);Z&&R.push({id:v.RemoveHyperLinkMutation.id,params:{unitId:l,subUnitId:u,id:Z.id}}),(y.APPLY_TYPE.COPY===r||y.APPLY_TYPE.SERIES===r)&&ae&&(R.push({id:v.AddHyperLinkMutation.id,params:{unitId:l,subUnitId:u,link:{...ae,id:ce,row:fe,column:me}}}),T.push({id:v.RemoveHyperLinkMutation.id,params:{unitId:l,subUnitId:u,id:ce}})),Z&&T.push({id:v.AddHyperLinkMutation.id,params:{unitId:l,subUnitId:u,link:Z}})})}),{undos:T,redos:R}},t={id:Ve,onFillData:(i,r,a)=>a===y.APPLY_TYPE.COPY||a===y.APPLY_TYPE.ONLY_FORMAT||a===y.APPLY_TYPE.SERIES?n(i,a):e()};this.disposeWithMe(this._autoFillService.addHook(t))}};Ne=In([vt(0,y.IAutoFillService),vt(1,o.Inject(v.HyperLinkModel))],Ne);var fn=Object.defineProperty,mn=Object.getOwnPropertyDescriptor,yn=(e,n,t,i)=>{for(var r=i>1?void 0:i?mn(n,t):n,a=e.length-1,s;a>=0;a--)(s=e[a])&&(r=(i?s(n,t,r):s(r))||r);return i&&r&&fn(n,t,r),r},Ke=(e,n)=>(t,i)=>n(t,i,e);let Me=class extends o.Disposable{constructor(e,n,t){super(),this._localeService=e,this._commandService=n,this._sheetPermissionCheckController=t,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{e.id===We.id&&(this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[E.WorkbookEditablePermission],rangeTypes:[E.RangeProtectionPermissionEditPoint],worksheetTypes:[E.WorksheetEditPermission,E.WorksheetSetCellValuePermission,E.WorksheetInsertHyperlinkPermission]})||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.hyperLinkErr")))}))}};Me=yn([Ke(0,o.Inject(o.LocaleService)),Ke(1,o.ICommandService),Ke(2,o.Inject(E.SheetPermissionCheckController))],Me);var Cn=Object.defineProperty,En=Object.getOwnPropertyDescriptor,Pn=(e,n,t,i)=>{for(var r=i>1?void 0:i?En(n,t):n,a=e.length-1,s;a>=0;a--)(s=e[a])&&(r=(i?s(n,t,r):s(r))||r);return i&&r&&Cn(n,t,r),r},Y=(e,n)=>(t,i)=>n(t,i,e);let Ue=class extends o.Disposable{constructor(e,n,t,i,r,a,s,l,u,p){super(),this._hoverManagerService=e,this._sheetsHyperLinkPopupService=n,this._renderManagerService=t,this._permissionService=i,this._sheetPermissionCheckController=r,this._commandService=a,this._editorBridgeService=s,this._textSelectionManagerService=l,this._univerInstanceService=u,this._zenZoneService=p,this._initHoverListener(),this._initCommandListener(),this._initHoverEditingListener(),this._initTextSelectionListener(),this._initZenEditor()}_getLinkPermission(e){const{unitId:n,subUnitId:t,row:i,col:r}=e,a=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET);if(!(a==null?void 0:a.getSheetBySheetId(t)))return{viewPermission:!1,editPermission:!1,copyPermission:!1};const l=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[E.WorkbookViewPermission],worksheetTypes:[E.WorksheetViewPermission],rangeTypes:[E.RangeProtectionPermissionViewPoint]},[{startRow:i,startColumn:r,endRow:i,endColumn:r}]),u=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[E.WorkbookEditablePermission],worksheetTypes:[E.WorksheetEditPermission,E.WorksheetInsertHyperlinkPermission],rangeTypes:[E.RangeProtectionPermissionEditPoint]},[{startRow:i,startColumn:r,endRow:i,endColumn:r}]),p=this._permissionService.composePermission([new E.WorkbookCopyPermission(n).id,new E.WorksheetCopyPermission(n,t).id]).every(d=>d.value);return{viewPermission:l,editPermission:u,copyPermission:p}}_initHoverListener(){this.disposeWithMe(this._hoverManagerService.currentRichText$.pipe(L.debounceTime(200)).subscribe(e=>{var M,U;if(!e){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const{unitId:n,subUnitId:t,row:i,col:r}=e,a=this._renderManagerService.getRenderById(n);if(!a)return;const s=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET),l=s==null?void 0:s.getSheetBySheetId(t);if(!l)return;if(!a.with(y.HoverRenderController).active){this._sheetsHyperLinkPopupService.hideCurrentPopup(m.VIEWING);return}const p=(M=a==null?void 0:a.with(y.SheetSkeletonManagerService).getWorksheetSkeleton(t))==null?void 0:M.skeleton,d=r,h=i;let I=h,S=d;p&&p.overflowCache.forValue((j,V,J)=>{o.Rectangle.contains(J,{startColumn:d,endColumn:d,startRow:h,endRow:h})&&(I=j,S=V)});const{viewPermission:P,editPermission:R,copyPermission:T}=this._getLinkPermission(e);if(!P){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const c=l.getCellStyleOnly(I,S),D=s.getStyles().getStyleByCell(c),B=(U=D==null?void 0:D.tr)==null?void 0:U.a;if(!B&&!e.customRange){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}this._sheetsHyperLinkPopupService.showPopup({row:I,col:S,editPermission:R,copyPermission:T,customRange:e.customRange,customRangeRect:e.rect,type:m.VIEWING,unitId:n,subUnitId:t,showAll:!!B})}))}_initHoverEditingListener(){let e=null;this.disposeWithMe(this._editorBridgeService.currentEditCellState$.pipe(L.switchMap(n=>this._editorBridgeService.visible$.pipe(L.map(t=>({visible:t,state:n}))))).subscribe(({visible:n,state:t})=>{if(!t||t.editorUnitId!==o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)return;if(!n.visible){e==null||e.unsubscribe(),this._sheetsHyperLinkPopupService.hideCurrentPopup(m.EDITING),this._sheetsHyperLinkPopupService.endEditing(m.EDITING);return}const{editorUnitId:i,unitId:r,sheetId:a,row:s,column:l}=t,u=this._renderManagerService.getRenderById(i);if(!u)return;const{editPermission:p,viewPermission:d,copyPermission:h}=this._getLinkPermission({unitId:r,subUnitId:a,row:s,col:l}),I=u.with(ee.DocEventManagerService);d&&(e==null||e.unsubscribe(),e=I.hoverCustomRanges$.pipe(L.debounceTime(200)).subscribe(S=>{var D,B;const P=S.find(M=>M.range.rangeType===o.CustomRangeType.HYPERLINK);if(!P){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const R=P.rects[P.rects.length-1];if(!((B=(D=this._renderManagerService.getRenderById(r))==null?void 0:D.with(y.SheetSkeletonManagerService).getWorksheetSkeleton(a))==null?void 0:B.skeleton)||!R)return;const c=u.engine.getCanvasElement().getBoundingClientRect();this._sheetsHyperLinkPopupService.showPopup({unitId:r,subUnitId:a,row:s,col:l,customRange:P.range,customRangeRect:{left:R.left+c.left,top:R.top+c.top,bottom:R.bottom+c.top,right:R.right+c.left},editPermission:p,copyPermission:h,type:m.EDITING})}))})),this.disposeWithMe(()=>{e==null||e.unsubscribe()})}_initZenEditor(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e?(this._sheetsHyperLinkPopupService.hideCurrentPopup(m.VIEWING),this._sheetsHyperLinkPopupService.hideCurrentPopup(m.EDITING),this._sheetsHyperLinkPopupService.endEditing(m.EDITING),this._sheetsHyperLinkPopupService.hideCurrentPopup(m.VIEWING)):(this._sheetsHyperLinkPopupService.hideCurrentPopup(m.ZEN_EDITOR),this._sheetsHyperLinkPopupService.endEditing(m.ZEN_EDITOR))})),this.disposeWithMe(this._univerInstanceService.focused$.pipe(L.switchMap(e=>{const n=e===o.DOCS_ZEN_EDITOR_UNIT_ID_KEY?this._renderManagerService.getRenderById(e):null;return n?n.with(ee.DocEventManagerService).hoverCustomRanges$.pipe(L.debounceTime(200)):new L.Observable(t=>{t.next(null)})})).subscribe(e=>{const n=e==null?void 0:e.find(i=>i.range.rangeType===o.CustomRangeType.HYPERLINK),t=this._editorBridgeService.getEditCellState();if(n&&t){const{unitId:i,sheetId:r,row:a,column:s}=t,{editPermission:l,viewPermission:u,copyPermission:p}=this._getLinkPermission({unitId:i,subUnitId:r,row:a,col:s});u&&this._sheetsHyperLinkPopupService.showPopup({type:m.ZEN_EDITOR,unitId:i,subUnitId:r,row:a,col:s,customRange:n.range,editPermission:l,copyPermission:p})}else this._sheetsHyperLinkPopupService.hideCurrentPopup(m.ZEN_EDITOR)}))}_initTextSelectionListener(){this.disposeWithMe(this._textSelectionManagerService.textSelection$.subscribe(e=>{e&&e.unitId===o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._sheetsHyperLinkPopupService.endEditing(m.EDITING)}))}_initCommandListener(){const e=[E.ClearSelectionContentCommand.id,E.ClearSelectionAllCommand.id,E.ClearSelectionFormatCommand.id];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{e.includes(n.id)&&this._sheetsHyperLinkPopupService.hideCurrentPopup()}))}};Ue=Pn([Y(0,o.Inject(y.HoverManagerService)),Y(1,o.Inject(g.SheetsHyperLinkPopupService)),Y(2,o.Inject(pe.IRenderManagerService)),Y(3,o.Inject(o.IPermissionService)),Y(4,o.Inject(E.SheetPermissionCheckController)),Y(5,o.ICommandService),Y(6,y.IEditorBridgeService),Y(7,o.Inject(he.DocSelectionManagerService)),Y(8,o.IUniverInstanceService),Y(9,b.IZenZoneService)],Ue);var Ln=Object.defineProperty,Rn=Object.getOwnPropertyDescriptor,St=(e,n,t,i)=>{for(var r=i>1?void 0:i?Rn(n,t):n,a=e.length-1,s;a>=0;a--)(s=e[a])&&(r=(i?s(n,t,r):s(r))||r);return i&&r&&Ln(n,t,r),r},Ye=(e,n)=>(t,i)=>n(t,i,e);let Ge=class extends o.Disposable{constructor(e,n){super(),this._context=e,this._hyperLinkModel=n,this._initSkeletonChange()}_initSkeletonChange(){const e=()=>{var n;(n=this._context.mainComponent)==null||n.makeForceDirty()};this.disposeWithMe(this._hyperLinkModel.linkUpdate$.pipe(L.debounceTime(16)).subscribe(()=>{e()}))}};Ge=St([Ye(1,o.Inject(v.HyperLinkModel))],Ge);let He=class extends o.Disposable{constructor(e,n){super(),this._sheetInterceptorService=e,this._hyperLinkModel=n,this._initViewModelIntercept()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(E.INTERCEPTOR_POINT.CELL_CONTENT,{effect:o.InterceptorEffectEnum.Value,priority:100,handler:(e,n,t)=>{const{row:i,col:r,unitId:a,subUnitId:s}=n,l=this._hyperLinkModel.getHyperLinkByLocation(a,s,i,r);return t(l?{...e,linkUrl:l.payload,linkId:l.id}:e)}}))}};He=St([Ye(0,o.Inject(E.SheetInterceptorService)),Ye(1,o.Inject(v.HyperLinkModel))],He);const Tn={[b.RibbonStartGroup.OTHERS]:{[se.id]:{order:2,menuItemFactory:gn},[be(se.id)]:{order:2,menuItemFactory:vn}},[b.ContextMenuPosition.MAIN_AREA]:{[b.ContextMenuGroup.OTHERS]:{order:1,[se.id]:{order:0,menuItemFactory:pn},[be(se.id)]:{order:0,menuItemFactory:hn}}}};var On=Object.defineProperty,Dn=Object.getOwnPropertyDescriptor,kn=(e,n,t,i)=>{for(var r=i>1?void 0:i?Dn(n,t):n,a=e.length-1,s;a>=0;a--)(s=e[a])&&(r=(i?s(n,t,r):s(r))||r);return i&&r&&On(n,t,r),r},Se=(e,n)=>(t,i)=>n(t,i,e);let Ae=class extends o.Disposable{constructor(e,n,t,i,r){super(),this._componentManager=e,this._commandService=n,this._menuManagerService=t,this._injector=i,this._shortcutService=r,this._initComponents(),this._initCommands(),this._initMenus(),this._initShortCut()}_initComponents(){[[Te,Te.componentKey],[Le,Le.componentKey],[xe,"LinkSingle"]].forEach(([e,n])=>{this._componentManager.register(n,e)})}_initCommands(){[Oe,ve,De,se].forEach(e=>{this._commandService.registerCommand(e)})}_initMenus(){this._menuManagerService.mergeMenu(Tn)}_initShortCut(){this._shortcutService.registerShortcut(We)}};Ae=kn([Se(0,o.Inject(b.ComponentManager)),Se(1,o.ICommandService),Se(2,b.IMenuManagerService),Se(3,o.Inject(o.Injector)),Se(4,o.Inject(b.IShortcutService))],Ae);var bn=Object.defineProperty,wn=Object.getOwnPropertyDescriptor,Nn=(e,n,t,i)=>{for(var r=i>1?void 0:i?wn(n,t):n,a=e.length-1,s;a>=0;a--)(s=e[a])&&(r=(i?s(n,t,r):s(r))||r);return i&&r&&bn(n,t,r),r},_t=(e,n)=>(t,i)=>n(t,i,e);let Be=class extends o.Disposable{constructor(e,n){super(),this._parserService=e,this._resolverService=n,this._handleInitUrl()}_handleInitUrl(){const e=location.hash;if(e){const n=this._parserService.parseHyperLink(e);this._resolverService.navigate(n)}}};Be=Nn([_t(0,o.Inject(v.SheetsHyperLinkParserService)),_t(1,o.Inject(g.SheetsHyperLinkResolverService))],Be);var It=Object.defineProperty,Mn=Object.getOwnPropertyDescriptor,Un=(e,n,t)=>n in e?It(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,Hn=(e,n,t,i)=>{for(var r=i>1?void 0:i?Mn(n,t):n,a=e.length-1,s;a>=0;a--)(s=e[a])&&(r=(i?s(n,t,r):s(r))||r);return i&&r&&It(n,t,r),r},ft=(e,n)=>(t,i)=>n(t,i,e),mt=(e,n,t)=>Un(e,typeof n!="symbol"?n+"":n,t);g.UniverSheetsHyperLinkUIPlugin=class extends o.Plugin{constructor(n=it,t,i){super(),this._config=n,this._injector=t,this._configService=i;const{menu:r,...a}=o.merge({},it,this._config);r&&this._configService.setConfig("menu",r,{merge:!0}),this._configService.setConfig(nt,a)}onStarting(){[[g.SheetsHyperLinkResolverService],[g.SheetsHyperLinkPopupService],[je],[He],[Ue],[Ae],[Ne],[g.SheetsHyperLinkCopyPasteController],[Me],[Be]].forEach(t=>this._injector.add(t)),this._injector.get(He)}onReady(){this._injector.get(pe.IRenderManagerService).registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[Ge]),this._injector.get(Ne),this._injector.get(g.SheetsHyperLinkCopyPasteController),this._injector.get(Ae)}onRendered(){this._injector.get(Me),this._injector.get(Be),this._injector.get(Ue)}},mt(g.UniverSheetsHyperLinkUIPlugin,"pluginName",Ve),mt(g.UniverSheetsHyperLinkUIPlugin,"type",o.UniverInstanceType.UNIVER_SHEET),g.UniverSheetsHyperLinkUIPlugin=Hn([o.DependentOn(v.UniverSheetsHyperLinkPlugin,ee.UniverDocsUIPlugin),ft(1,o.Inject(o.Injector)),ft(2,o.IConfigService)],g.UniverSheetsHyperLinkUIPlugin),g.CloseHyperLinkPopupOperation=ve,g.InsertHyperLinkOperation=De,g.InsertLinkShortcut=We,g.OpenHyperLinkEditPanelOperation=Oe,g.SheetsHyperLinkSidePanelService=je,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
|
|
10
|
+
(function(g,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/sheets-hyper-link"),require("@univerjs/sheets-ui"),require("@univerjs/design"),require("@univerjs/engine-formula"),require("@univerjs/sheets"),require("@univerjs/ui"),require("@univerjs/docs-ui"),require("@univerjs/engine-render"),require("rxjs"),require("@univerjs/docs"),require("react/jsx-runtime"),require("@univerjs/sheets-formula-ui"),require("react"),require("@univerjs/sheets-data-validation")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets-hyper-link","@univerjs/sheets-ui","@univerjs/design","@univerjs/engine-formula","@univerjs/sheets","@univerjs/ui","@univerjs/docs-ui","@univerjs/engine-render","rxjs","@univerjs/docs","react/jsx-runtime","@univerjs/sheets-formula-ui","react","@univerjs/sheets-data-validation"],o):(g=typeof globalThis<"u"?globalThis:g||self,o(g.UniverSheetsHyperLinkUi={},g.UniverCore,g.UniverSheetsHyperLink,g.UniverSheetsUi,g.UniverDesign,g.UniverEngineFormula,g.UniverSheets,g.UniverUi,g.UniverDocsUi,g.UniverEngineRender,g.rxjs,g.UniverDocs,g.React,g.UniverSheetsFormulaUi,g.React,g.UniverSheetsDataValidation))})(this,function(g,o,v,C,w,X,L,m,ee,pe,P,he,f,Ht,E,tt){"use strict";var Mn=Object.defineProperty;var Un=(g,o,v)=>o in g?Mn(g,o,{enumerable:!0,configurable:!0,writable:!0,value:v}):g[o]=v;var K=(g,o,v)=>Un(g,typeof o!="symbol"?o+"":o,v);function Ee(e){return o.Tools.isLegalUrl(e)}function At(e){return/^[a-zA-Z]+:\/\//.test(e)}function Bt(e){return/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/.test(e)}function Vt(e){if(Ee(e)){const n=At(e)?e:Bt(e)?`mailto://${e}`:`http://${e}`;let t;try{t=new URL(n)}catch{return e}return t.hostname===location.hostname&&t.port===location.port&&t.protocol===location.protocol&&t.pathname===location.pathname&&t.hash&&!t.search?t.hash:n}return e}const nt="sheets-hyper-link-ui.config",it={};var $t=Object.getOwnPropertyDescriptor,xt=(e,n,t,i)=>{for(var r=i>1?void 0:i?$t(n,t):n,s=e.length-1,a;s>=0;s--)(a=e[s])&&(r=a(r)||r);return r},de=(e,n)=>(t,i)=>n(t,i,e);function jt(e,n){const t=n.getMergeData(),i=n.getMaxColumns()-1,r=n.getMaxRows()-1;if(i<e.endColumn&&(e.endColumn=i),r<e.endRow&&(e.endRow=r),e.rangeType===o.RANGE_TYPE.COLUMN||o.RANGE_TYPE.ROW)return e;const s=[];return t.forEach(a=>{o.Rectangle.intersects(e,a)&&s.push(a)}),o.Rectangle.realUnion(e,...s)}g.SheetsHyperLinkResolverService=class{constructor(n,t,i,r,s,a){this._univerInstanceService=n,this._commandService=t,this._definedNamesService=i,this._messageService=r,this._localeService=s,this._configService=a}navigate(n){switch(n.type){case v.SheetHyperLinkType.URL:this.navigateToOtherWebsite(n.url);break;default:this._navigateToUniver(n.searchObj)}}_navigateToUniver(n){const{gid:t,range:i,rangeid:r}=n,s=this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!s)return;const a=s.getUnitId();if(r){const l=this._definedNamesService.getValueById(a,r);if(!l)return;const{formulaOrRefString:d}=l,p=this._definedNamesService.getWorksheetByRef(a,d);if(!p){this._messageService.show({content:this._localeService.t("hyperLink.message.refError"),type:w.MessageType.Error});return}if(p.isSheetHidden()){this._messageService.show({content:this._localeService.t("hyperLink.message.hiddenSheet"),type:w.MessageType.Error});return}this.navigateToDefineName(a,r)}if(t){if(i){const l=X.deserializeRangeWithSheet(i);o.isValidRange(l.range)&&i!==v.ERROR_RANGE&&this.navigateToRange(a,t,l.range);return}this.navigateToSheetById(a,t)}}async navigateToRange(n,t,i,r){const s=await this.navigateToSheetById(n,t);if(s){const a=jt(i,s);await this._commandService.executeCommand(L.SetSelectionsOperation.id,{unitId:n,subUnitId:t,selections:[{range:a,primary:null}]}),await this._commandService.executeCommand(C.ScrollToRangeOperation.id,{range:a,forceTop:r})}}async navigateToSheetById(n,t){const i=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET);if(!i)return!1;const r=i.getActiveSheet();if(!r)return!1;if(r.getSheetId()===t)return r;const s=i.getSheetBySheetId(t);return s?i.getHiddenWorksheets().indexOf(t)>-1?(this._messageService.show({content:this._localeService.t("hyperLink.message.hiddenSheet"),type:w.MessageType.Error}),!1):await this._commandService.executeCommand(L.SetWorksheetActiveOperation.id,{unitId:n,subUnitId:t})?s:!1:(this._messageService.show({content:this._localeService.t("hyperLink.message.noSheet"),type:w.MessageType.Error}),!1)}async navigateToDefineName(n,t){return this._definedNamesService.focusRange(n,t),!0}async navigateToOtherWebsite(n){var i;const t=this._configService.getConfig(nt);if((i=t==null?void 0:t.urlHandler)!=null&&i.navigateToOtherWebsite)return t.urlHandler.navigateToOtherWebsite(n);window.open(n,"_blank","noopener noreferrer")}},g.SheetsHyperLinkResolverService=xt([de(0,o.IUniverInstanceService),de(1,o.ICommandService),de(2,X.IDefinedNamesService),de(3,m.IMessageService),de(4,o.Inject(o.LocaleService)),de(5,o.IConfigService)],g.SheetsHyperLinkResolverService);const $e="SHEET_HYPER_LINK_UI_PLUGIN";var Ft=Object.getOwnPropertyDescriptor,Zt=(e,n,t,i)=>{for(var r=i>1?void 0:i?Ft(n,t):n,s=e.length-1,a;s>=0;s--)(a=e[s])&&(r=a(r)||r);return r},Le=(e,n)=>(t,i)=>n(t,i,e);g.SheetsHyperLinkCopyPasteController=class extends o.Disposable{constructor(t,i,r,s){super();K(this,"_plainTextFilter",new Set);K(this,"_copyInfo");this._sheetClipboardService=t,this._hyperLinkModel=i,this._injector=r,this._resolverService=s,this._initCopyPaste(),this.disposeWithMe(()=>{this._plainTextFilter.clear()})}registerPlainTextFilter(t){this._plainTextFilter.add(t)}removePlainTextFilter(t){this._plainTextFilter.delete(t)}_filterPlainText(t){return Array.from(this._plainTextFilter).every(i=>i(t))}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:$e,onBeforeCopy:(t,i,r)=>this._collect(t,i,r),onPasteCells:(t,i,r,s)=>{const{copyType:a=C.COPY_TYPE.COPY,pasteType:l}=s,{range:d}=t||{},{range:p,unitId:u,subUnitId:h}=i;return this._generateMutations(p,{copyType:a,pasteType:l,copyRange:d,unitId:u,subUnitId:h})},onPastePlainText:(t,i)=>{const r=this._filterPlainText(i);if(Ee(i)&&r){const{range:s,unitId:a,subUnitId:l}=t,{ranges:[d],mapFunc:p}=C.virtualizeDiscreteRanges([s]),u=[],h=[];return o.Range.foreach(d,(I,S)=>{const{row:R,col:T}=p(I,S),k=this._hyperLinkModel.getHyperLinkByLocation(a,l,R,T);k&&u.push({id:v.RemoveHyperLinkMutation.id,params:{unitId:a,subUnitId:l,id:k.id}}),k&&h.push({id:v.AddHyperLinkMutation.id,params:{unitId:a,subUnitId:l,link:k}})}),{redos:u,undos:h}}return{undos:[],redos:[]}},priority:99})}_collect(t,i,r){const s=new o.ObjectMatrix;this._copyInfo={unitId:t,subUnitId:i,matrix:s};const a=this._injector.invoke(p=>C.rangeToDiscreteRange(r,p,t,i));if(!a)return;const{rows:l,cols:d}=a;l.forEach((p,u)=>{d.forEach((h,I)=>{var R;const S=this._hyperLinkModel.getHyperLinkByLocation(t,i,p,h);s.setValue(u,I,(R=S==null?void 0:S.id)!=null?R:"")})})}_generateMutations(t,i){if(!this._copyInfo)return{redos:[],undos:[]};if(!this._copyInfo||!this._copyInfo.matrix.getSizeOf()||!i.copyRange)return{redos:[],undos:[]};if([C.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,C.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,C.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,C.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(i.pasteType))return{redos:[],undos:[]};const{unitId:s,subUnitId:a}=this._copyInfo,l=[],d=[],{ranges:[p,u],mapFunc:h}=C.virtualizeDiscreteRanges([i.copyRange,t]);return C.getRepeatRange(p,u,!0).forEach(({startRange:S})=>{var R;(R=this._copyInfo)==null||R.matrix.forValue((T,k,c)=>{const D=o.Rectangle.getPositionRange({startRow:T,endRow:T,startColumn:k,endColumn:k},S),B=this._hyperLinkModel.getHyperLink(s,a,c),{row:M,col:U}=h(D.startRow,D.startColumn),x=this._hyperLinkModel.getHyperLinkByLocation(i.unitId,i.subUnitId,M,U),$=o.Tools.generateRandomId();x&&l.push({id:v.RemoveHyperLinkMutation.id,params:{unitId:i.unitId,subUnitId:i.subUnitId,id:x.id}}),B&&(l.push({id:v.AddHyperLinkMutation.id,params:{unitId:i.unitId,subUnitId:i.subUnitId,link:{...B,id:$,row:M,column:U}}}),d.push({id:v.RemoveHyperLinkMutation.id,params:{unitId:i.unitId,subUnitId:i.subUnitId,id:$}})),x&&d.push({id:v.AddHyperLinkMutation.id,params:{unitId:i.unitId,subUnitId:i.subUnitId,link:x}})})}),{redos:l,undos:d}}},g.SheetsHyperLinkCopyPasteController=Zt([Le(0,C.ISheetClipboardService),Le(1,o.Inject(v.HyperLinkModel)),Le(2,o.Inject(o.Injector)),Le(3,o.Inject(g.SheetsHyperLinkResolverService))],g.SheetsHyperLinkCopyPasteController);var y=(e=>(e.EDITING="editing",e.VIEWING="viewing",e.ZEN_EDITOR="zen_mode",e))(y||{});class xe extends o.Disposable{constructor(){super(...arguments);K(this,"_customHyperLinks",new Map)}isBuiltInLinkType(t){return t!==v.SheetHyperLinkType.URL}getOptions(){return Array.from(this._customHyperLinks.values()).map(({option:t})=>t)}findCustomHyperLink(t){return Array.from(this._customHyperLinks.values()).find(r=>r.match(t))}registerCustomHyperLink(t){this._customHyperLinks.set(t.type,t)}getCustomHyperLink(t){return this._customHyperLinks.get(t)}removeCustomHyperLink(t){const{_customHyperLinks:i}=this;i.delete(t)}dispose(){super.dispose(),this._customHyperLinks.clear()}}const rt={cellLinkEdit:"univer-cell-link-edit",cellLinkEditButtons:"univer-cell-link-edit-buttons"},Re=()=>{var yt;const[e,n]=E.useState(""),[t,i]=E.useState(!1),[r,s]=E.useState(""),[a,l]=E.useState(!0),[d,p]=E.useState(v.SheetHyperLinkType.URL),[u,h]=E.useState(""),I=m.useDependency(o.LocaleService),S=m.useDependency(X.IDefinedNamesService),R=m.useDependency(C.IEditorBridgeService),T=m.useDependency(o.IUniverInstanceService),k=m.useDependency(g.SheetsHyperLinkPopupService),c=m.useObservable(k.currentEditing$),D=m.useDependency(v.SheetsHyperLinkParserService),B=m.useDependency(g.SheetsHyperLinkResolverService),M=m.useDependency(o.ICommandService),U=m.useDependency(xe),x=E.useMemo(()=>U.getOptions(),[U]),$=m.useDependency(m.IZenZoneService),J=m.useDependency(pe.IRenderManagerService),_e=m.useDependency(C.IMarkSelectionService),Ve=m.useDependency(he.DocSelectionManagerService),ae=m.useDependency(o.IContextService),Ie=m.useDependency(o.ThemeService),me=m.useDependency(he.DocSelectionManagerService),fe=E.useRef({}),ce=E.useMemo(()=>{if(!U.isBuiltInLinkType(d))return U.getCustomHyperLink(d)},[U,d]),[Z,kn]=E.useState(!1),[ye,ze]=E.useState(!1),j=E.useRef(!1),G=T.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),On=(G==null?void 0:G.getActiveSheet().getSheetId())||"",te=E.useCallback(_=>{s(_.replaceAll(o.DataStreamTreeTokenType.CUSTOM_RANGE_START,"").replaceAll(o.DataStreamTreeTokenType.CUSTOM_RANGE_END,""))},[s]);E.useEffect(()=>{var _,b,O,N,A,z,Ct,Et,Lt,Rt,Pt,Tt,kt,Ot,Dt,bt,wt;if((c==null?void 0:c.row)!==void 0&&c.col!==void 0){const{customRange:le,row:Qe,col:et}=c;let{label:Q}=c;typeof Q=="number"&&(Q=`${Q}`);let q;if(le)q={id:(_=le==null?void 0:le.rangeId)!=null?_:"",display:Q!=null?Q:"",payload:(O=(b=le==null?void 0:le.properties)==null?void 0:b.url)!=null?O:"",row:Qe,column:et};else if(c.type===y.VIEWING){const H=T.getUnit(c.unitId),ie=H==null?void 0:H.getSheetBySheetId(c.subUnitId),V=ie==null?void 0:ie.getCellRaw(c.row,c.col),ue=(z=(A=(N=V==null?void 0:V.p)==null?void 0:N.body)==null?void 0:A.customRanges)==null?void 0:z.find(Mt=>{var Ut;return Mt.rangeType===o.CustomRangeType.HYPERLINK&&((Ut=Mt.properties)==null?void 0:Ut.url)}),Ce=V==null?void 0:V.v;V&&(!o.BuildTextUtils.transform.isEmptyDocument((Et=(Ct=V.p)==null?void 0:Ct.body)==null?void 0:Et.dataStream)||o.Tools.isDefine(Ce))&&l(!1),q={id:"",display:"",payload:(Rt=(Lt=ue==null?void 0:ue.properties)==null?void 0:Lt.url)!=null?Rt:"",row:Qe,column:et}}else{const H=T.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC),ie=Ve.getActiveTextRange(),V=H==null?void 0:H.getBody(),ue=ie&&V?ie:null,Ce=ue&&((Tt=o.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(ue,(Pt=V==null?void 0:V.customRanges)!=null?Pt:[]))==null?void 0:Tt[0]);l(!1),q={id:"",display:Q!=null?Q:"",payload:(Ot=(kt=Ce==null?void 0:Ce.properties)==null?void 0:kt.url)!=null?Ot:"",row:Qe,column:et}}n(q.id);const Nt=U.findCustomHyperLink(q);if(Nt){const H=Nt.convert(q);p(H.type),h(H.payload),te(H.display);return}te(q.display);const ne=D.parseHyperLink(q.payload);switch(p(ne.type===v.SheetHyperLinkType.INVALID?v.SheetHyperLinkType.RANGE:ne.type),ne.type){case v.SheetHyperLinkType.URL:{h(ne.url),ne.url===q.display&&(j.current=!0);break}case v.SheetHyperLinkType.RANGE:{const H=ne.searchObj,ie=H.gid&&(wt=(bt=(Dt=T.getUnit(c.unitId))==null?void 0:Dt.getSheetBySheetId(H.gid))==null?void 0:bt.getName())!=null?wt:"",V=X.serializeRangeWithSheet(ie,X.deserializeRangeWithSheet(H.range).range);h(V),V===q.display&&(j.current=!0);break}case v.SheetHyperLinkType.SHEET:{const H=ne.searchObj;h(H.gid);break}case v.SheetHyperLinkType.DEFINE_NAME:{const H=ne.searchObj;h(H.rangeid);break}default:h("");break}}},[c,B,U,Ve,T]),E.useEffect(()=>{let _=null;if(c&&!c.customRangeId&&c.type===y.VIEWING&&o.Tools.isDefine(c.row)&&o.Tools.isDefine(c.col)){const b=T.getUnit(c.unitId,o.UniverInstanceType.UNIVER_SHEET),O=b==null?void 0:b.getSheetBySheetId(c.subUnitId),N=O==null?void 0:O.getMergedCell(c.row,c.col),A=new o.ColorKit(Ie.getCurrentTheme().hyacinth500).toRgb();_=_e.addShape({range:N!=null?N:{startColumn:c.col,endColumn:c.col,startRow:c.row,endRow:c.row},style:{fill:`rgb(${A.r}, ${A.g}, ${A.b}, 0.12)`,strokeWidth:1,stroke:"#FFBD37",widgets:{}},primary:null},[],-1)}return()=>{_&&_e.removeShape(_)}},[c,_e,Ie,T]),E.useEffect(()=>{ze(d===v.SheetHyperLinkType.RANGE)},[d]),E.useEffect(()=>{const _=(c==null?void 0:c.type)===y.ZEN_EDITOR?J.getRenderById(o.DOCS_ZEN_EDITOR_UNIT_ID_KEY):J.getRenderById(R.getCurrentEditorId()),b=new o.DisposableCollection;if(_){const O=_.with(ee.DocSelectionRenderService);O.setReserveRangesStatus(!0),b.add(()=>{O.setReserveRangesStatus(!1)})}return()=>{R.disableForceKeepVisible(),b.dispose()}},[c==null?void 0:c.type,R,J]),E.useEffect(()=>(k.setIsKeepVisible(ye),()=>{k.setIsKeepVisible(!1)}),[ye,k]),E.useEffect(()=>()=>{$.temporaryHidden&&($.show(),ae.setContextValue(o.FOCUSING_SHEET,!1))},[ae,$]),E.useEffect(()=>{if(ye)return R.enableForceKeepVisible(),()=>{R.disableForceKeepVisible()}},[ye,R]);const Dn=[{label:I.t("hyperLink.form.link"),value:v.SheetHyperLinkType.URL},{label:I.t("hyperLink.form.range"),value:v.SheetHyperLinkType.RANGE},{label:I.t("hyperLink.form.worksheet"),value:v.SheetHyperLinkType.SHEET},{label:I.t("hyperLink.form.definedName"),value:v.SheetHyperLinkType.DEFINE_NAME},...x];if(!G)return;const bn=G.getHiddenWorksheets(),qe=G.getSheets().map(_=>({label:_.getName(),value:_.getSheetId()})).filter(_=>bn.indexOf(_.value)===-1),Xe=Object.values((yt=S.getDefinedNameMap(G.getUnitId()))!=null?yt:{}).map(_=>({label:_.name,value:_.id})),ft=(_,b)=>{if(_===v.SheetHyperLinkType.URL)return Vt(b);if(_===v.SheetHyperLinkType.RANGE){const O=X.deserializeRangeWithSheet(b),N=G.getSheetBySheetName(O.sheetName);if(N)return`#gid=${N.getSheetId()}&range=${X.serializeRange(O.range)}`}return`#${_}=${b}`},wn=m.useEvent(_=>{var A;const O=_.split(",").map(X.deserializeRangeWithSheet)[0];if(!O||!o.isValidRange(O.range))return;O.sheetName||(O.sheetName=((A=G.getActiveSheet())==null?void 0:A.getName())||"");const N=X.serializeRangeToRefString(O);h(N),N&&(j.current||!r)&&(te(N),j.current=!0)}),Je=async()=>{if(a&&!r||!u||d===v.SheetHyperLinkType.URL&&!Ee(u)){kn(!0);return}if(c)if(e){const _=c.type===y.ZEN_EDITOR||c.type===y.EDITING?v.UpdateRichHyperLinkCommand.id:v.UpdateHyperLinkCommand.id;await M.executeCommand(_,{id:e,unitId:c.unitId,subUnitId:c.subUnitId,payload:{display:a?r:"",payload:ft(d,u)},row:c.row,column:c.col,documentId:c.type===y.ZEN_EDITOR?o.DOCS_ZEN_EDITOR_UNIT_ID_KEY:R.getCurrentEditorId()})}else{const _=c.type===y.ZEN_EDITOR||c.type===y.EDITING?v.AddRichHyperLinkCommand.id:v.AddHyperLinkCommand.id;await M.executeCommand(_,{unitId:c.unitId,subUnitId:c.subUnitId,link:{id:o.generateRandomId(),row:c.row,column:c.col,payload:ft(d,u),display:a?r:""},documentId:c.type===y.ZEN_EDITOR?o.DOCS_ZEN_EDITOR_UNIT_ID_KEY:R.getCurrentEditorId()})}if((c==null?void 0:c.type)===y.VIEWING){await M.executeCommand(L.SetWorksheetActiveOperation.id,{unitId:c.unitId,subUnitId:c.subUnitId});const _=1;await M.executeCommand(C.ScrollToRangeOperation.id,{range:{startRow:Math.max(c.row-_,0),endRow:c.row+_,startColumn:Math.max(c.col-_,0),endColumn:c.col+_}})}M.executeCommand(ve.id)},Nn=_=>{var O;if(d!==v.SheetHyperLinkType.RANGE)return;const b=(O=fe.current)==null?void 0:O.handleOutClick;b&&b(_,()=>ze(!1))};return c?f.jsxs("div",{className:rt.cellLinkEdit,style:{display:t?"none":"block"},onClick:Nn,children:[a?f.jsx(w.FormLayout,{label:I.t("hyperLink.form.label"),error:Z&&!r?I.t("hyperLink.form.inputError"):"",children:f.jsx(w.Input,{value:r,onChange:_=>{te(_),j.current=!1},placeholder:I.t("hyperLink.form.labelPlaceholder"),autoFocus:!0,onKeyDown:_=>{_.keyCode===m.KeyCode.ENTER&&Je()}})}):null,f.jsx(w.FormLayout,{label:I.t("hyperLink.form.type"),children:f.jsx(w.Select,{options:Dn,value:d,onChange:_=>{p(_),h("")}})}),d===v.SheetHyperLinkType.URL&&f.jsx(w.FormLayout,{error:Z?u?Ee(u)?"":I.t("hyperLink.form.linkError"):I.t("hyperLink.form.inputError"):"",children:f.jsx(w.Input,{value:u,onChange:_=>{h(_),_&&(j.current||!r||r===u)&&(te(_),j.current=!0)},placeholder:I.t("hyperLink.form.linkPlaceholder"),autoFocus:!0,onKeyDown:_=>{_.keyCode===m.KeyCode.ENTER&&Je()}})}),d===v.SheetHyperLinkType.RANGE&&f.jsx(w.FormLayout,{error:Z&&!u?I.t("hyperLink.form.inputError"):"",children:f.jsx(Ht.RangeSelector,{unitId:G.getUnitId(),subUnitId:On,isOnlyOneRange:!0,isSupportAcrossSheet:!0,initValue:u,onChange:wn,isFocus:ye,onFocus:()=>ze(!0),actions:fe.current,onRangeSelectorDialogVisibleChange:async _=>{var b,O;if(_)c.type===y.ZEN_EDITOR&&($.hide(),ae.setContextValue(o.FOCUSING_SHEET,!0)),c.type!==y.VIEWING&&R.enableForceKeepVisible(),i(!0);else{if(await B.navigateToRange(c.unitId,c.subUnitId,{startRow:c.row,endRow:c.row,startColumn:c.col,endColumn:c.col},!0),c.type===y.ZEN_EDITOR){await M.executeCommand(L.SetSelectionsOperation.id,{unitId:c.unitId,subUnitId:c.subUnitId,selections:[{range:{startRow:c.row,endRow:c.row,startColumn:c.col,endColumn:c.col}}]}),$.show(),ae.setContextValue(o.FOCUSING_SHEET,!1);const N=(b=J.getRenderById(o.DOCS_ZEN_EDITOR_UNIT_ID_KEY))==null?void 0:b.with(ee.DocBackScrollRenderController),A=(O=me.getTextRanges({unitId:o.DOCS_ZEN_EDITOR_UNIT_ID_KEY,subUnitId:o.DOCS_ZEN_EDITOR_UNIT_ID_KEY}))==null?void 0:O[0];N&&A&&(N.scrollToRange(A),me.refreshSelection({unitId:o.DOCS_ZEN_EDITOR_UNIT_ID_KEY,subUnitId:o.DOCS_ZEN_EDITOR_UNIT_ID_KEY}))}R.disableForceKeepVisible(),i(!1)}}})}),d===v.SheetHyperLinkType.SHEET&&f.jsx(w.FormLayout,{error:Z&&!u?I.t("hyperLink.form.selectError"):"",children:f.jsx(w.Select,{options:qe,value:u,onChange:_=>{var N,A;h(_);const b=(N=qe.find(z=>z.value===_))==null?void 0:N.label,O=(A=qe.find(z=>z.value===u))==null?void 0:A.label;b&&(j.current||!r||r===O)&&(te(b),j.current=!0)}})}),d===v.SheetHyperLinkType.DEFINE_NAME&&f.jsx(w.FormLayout,{error:Z&&!u?I.t("hyperLink.form.selectError"):"",children:f.jsx(w.Select,{options:Xe,value:u,onChange:_=>{var N,A;h(_);const b=(N=Xe.find(z=>z.value===_))==null?void 0:N.label,O=(A=Xe.find(z=>z.value===u))==null?void 0:A.label;b&&(j.current||!r||r===O)&&(te(b),j.current=!0)}})}),(ce==null?void 0:ce.Form)&&f.jsx(ce.Form,{linkId:e,payload:u,display:r,showError:Z,setByPayload:j,setDisplay:_=>{te(_),j.current=!0},setPayload:h}),f.jsxs("div",{className:rt.cellLinkEditButtons,children:[f.jsx(w.Button,{onClick:()=>{c&&B.navigateToRange(c.unitId,c.subUnitId,{startRow:c.row,endRow:c.row,startColumn:c.col,endColumn:c.col},!0),M.executeCommand(ve.id)},children:I.t("hyperLink.form.cancel")}),f.jsx(w.Button,{type:"primary",style:{marginLeft:8},onClick:async()=>{Je()},children:I.t("hyperLink.form.ok")})]})]}):null};Re.componentKey="univer.sheet.cell-link-edit";var F=function(){return F=Object.assign||function(e){for(var n,t=1,i=arguments.length;t<i;t++){n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},F.apply(this,arguments)},Kt=function(e,n){var t={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&n.indexOf(i)<0&&(t[i]=e[i]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var r=0,i=Object.getOwnPropertySymbols(e);r<i.length;r++)n.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(t[i[r]]=e[i[r]]);return t},re=E.forwardRef(function(e,n){var t=e.icon,i=e.id,r=e.className,s=e.extend,a=Kt(e,["icon","id","className","extend"]),l="univerjs-icon univerjs-icon-".concat(i," ").concat(r||"").trim(),d=E.useRef("_".concat(Gt()));return ot(t,"".concat(i),{defIds:t.defIds,idSuffix:d.current},F({ref:n,className:l},a),s)});function ot(e,n,t,i,r){return E.createElement(e.tag,F(F({key:n},Wt(e,t,r)),i),(Yt(e,t).children||[]).map(function(s,a){return ot(s,"".concat(n,"-").concat(e.tag,"-").concat(a),t,void 0,r)}))}function Wt(e,n,t){var i=F({},e.attrs);t!=null&&t.colorChannel1&&i.fill==="colorChannel1"&&(i.fill=t.colorChannel1);var r=n.defIds;return!r||r.length===0||(e.tag==="use"&&i["xlink:href"]&&(i["xlink:href"]=i["xlink:href"]+n.idSuffix),Object.entries(i).forEach(function(s){var a=s[0],l=s[1];typeof l=="string"&&(i[a]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),i}function Yt(e,n){var t,i=n.defIds;return!i||i.length===0?e:e.tag==="defs"&&(!((t=e.children)===null||t===void 0)&&t.length)?F(F({},e),{children:e.children.map(function(r){return typeof r.attrs.id=="string"&&i&&i.indexOf(r.attrs.id)>-1?F(F({},r),{attrs:F(F({},r.attrs),{id:r.attrs.id+n.idSuffix})}):r})}):e}function Gt(){return Math.random().toString(36).substring(2,8)}re.displayName="UniverIcon";var zt={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M7.9999 1.12915C8.03875 1.12915 8.07673 1.13284 8.11352 1.13989H12.2599C13.6958 1.13989 14.8599 2.30395 14.8599 3.73989V7.88619C14.867 7.92301 14.8707 7.96102 14.8707 7.9999C14.8707 8.03878 14.867 8.0768 14.8599 8.11362V12.2599C14.8599 13.6958 13.6958 14.8599 12.2599 14.8599H8.11362C8.0768 14.867 8.03878 14.8707 7.9999 14.8707C7.96102 14.8707 7.92301 14.867 7.88619 14.8599H3.73989C2.30396 14.8599 1.13989 13.6958 1.13989 12.2599V8.11352C1.13284 8.07673 1.12915 8.03875 1.12915 7.9999C1.12915 7.96106 1.13284 7.92308 1.13989 7.88629V3.73989C1.13989 2.30396 2.30395 1.13989 3.73989 1.13989H7.88629C7.92308 1.13284 7.96106 1.12915 7.9999 1.12915ZM2.33989 8.5999V12.2599C2.33989 13.0331 2.9667 13.6599 3.73989 13.6599H7.3999V8.5999H2.33989ZM7.3999 7.3999H2.33989V3.73989C2.33989 2.9667 2.96669 2.33989 3.73989 2.33989H7.3999V7.3999ZM8.5999 8.5999V13.6599H12.2599C13.0331 13.6599 13.6599 13.0331 13.6599 12.2599V8.5999H8.5999ZM13.6599 7.3999H8.5999V2.33989H12.2599C13.0331 2.33989 13.6599 2.96669 13.6599 3.73989V7.3999Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Pe=E.forwardRef(function(e,n){return E.createElement(re,Object.assign({},e,{id:"all-border-single",ref:n,icon:zt}))});Pe.displayName="AllBorderSingle";var qt={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"}}]},st=E.forwardRef(function(e,n){return E.createElement(re,Object.assign({},e,{id:"copy-single",ref:n,icon:qt}))});st.displayName="CopySingle";var Xt={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"}}]},je=E.forwardRef(function(e,n){return E.createElement(re,Object.assign({},e,{id:"link-single",ref:n,icon:Xt}))});je.displayName="LinkSingle";var Jt={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"}}]},at=E.forwardRef(function(e,n){return E.createElement(re,Object.assign({},e,{id:"unlink-single",ref:n,icon:Jt}))});at.displayName="UnlinkSingle";var Qt={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"}}]},ct=E.forwardRef(function(e,n){return E.createElement(re,Object.assign({},e,{id:"write-single",ref:n,icon:Qt}))});ct.displayName="WriteSingle";var en={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3.4538 1.12549C2.70051 1.12549 2.08984 1.73615 2.08984 2.48945V13.5104C2.08984 14.2637 2.70051 14.8744 3.4538 14.8744H12.5468C13.3001 14.8744 13.9108 14.2637 13.9108 13.5104V5.0992L10.0094 1.12549H3.4538Z"}},{tag:"path",attrs:{fill:"colorChannel1",d:"M10.0078 1.12549L13.9107 5.09842H10.6745C10.3063 5.09842 10.0078 4.79994 10.0078 4.43175V1.12549Z"}},{tag:"path",attrs:{fill:"#fff",d:"M7.80941 10.2949L6.37701 12.403C6.2632 12.5705 6.03516 12.614 5.86766 12.5002C5.70017 12.3864 5.65664 12.1584 5.77045 11.9909L7.36611 9.64252L5.94103 7.54519C5.82722 7.37769 5.87074 7.14964 6.03824 7.03583C6.20573 6.92202 6.43378 6.96555 6.54759 7.13304L7.80941 8.9901L9.07123 7.13304C9.18504 6.96555 9.41309 6.92202 9.58059 7.03583C9.74808 7.14964 9.7916 7.37769 9.67779 7.54519L8.25271 9.64252L9.84837 11.9909C9.96218 12.1584 9.91866 12.3864 9.75116 12.5002C9.58366 12.614 9.35562 12.5705 9.24181 12.403L7.80941 10.2949Z",fillRule:"evenodd",clipRule:"evenodd"}}]},lt=E.forwardRef(function(e,n){return E.createElement(re,Object.assign({},e,{id:"xlsx",ref:n,icon:en}))});lt.displayName="Xlsx";function dt(e){var n,t,i="";if(typeof e=="string"||typeof e=="number")i+=e;else if(typeof e=="object")if(Array.isArray(e)){var r=e.length;for(n=0;n<r;n++)e[n]&&(t=dt(e[n]))&&(i&&(i+=" "),i+=t)}else for(t in e)e[t]&&(i&&(i+=" "),i+=t);return i}function ut(){for(var e,n,t=0,i="",r=arguments.length;t<r;t++)(e=arguments[t])&&(n=dt(e))&&(i&&(i+=" "),i+=n);return i}const W={cellLink:"univer-cell-link",cellLinkType:"univer-cell-link-type",cellLinkContent:"univer-cell-link-content",cellLinkContentError:"univer-cell-link-content-error",cellLinkUrl:"univer-cell-link-url",cellLinkOperations:"univer-cell-link-operations",cellLinkOperation:"univer-cell-link-operation",cellLinkOperationError:"univer-cell-link-operation-error"},tn={[v.SheetHyperLinkType.URL]:f.jsx(je,{}),[v.SheetHyperLinkType.SHEET]:f.jsx(lt,{}),[v.SheetHyperLinkType.RANGE]:f.jsx(Pe,{}),[v.SheetHyperLinkType.DEFINE_NAME]:f.jsx(Pe,{}),[v.SheetHyperLinkType.INVALID]:f.jsx(Pe,{})},pt=e=>{var B,M;const n=m.useDependency(g.SheetsHyperLinkPopupService),t=m.useDependency(o.ICommandService),i=m.useDependency(m.IMessageService),r=m.useDependency(o.LocaleService),s=m.useDependency(g.SheetsHyperLinkResolverService),a=m.useDependency(C.IEditorBridgeService),l=m.useDependency(v.SheetsHyperLinkParserService),d=m.useDependency(m.IZenZoneService),{customRange:p,row:u,col:h,unitId:I,subUnitId:S,editPermission:R,copyPermission:T,type:k}=e;if(!((B=p==null?void 0:p.properties)!=null&&B.url))return null;const c=l.parseHyperLink((M=p.properties.url)!=null?M:""),D=c.type===v.SheetHyperLinkType.INVALID;return f.jsxs("div",{className:W.cellLink,onClick:()=>n.hideCurrentPopup(),children:[f.jsxs("div",{className:ut(W.cellLinkContent,{[W.cellLinkContentError]:D}),onClick:()=>{d.visible||D||s.navigate(c)},children:[f.jsx("div",{className:W.cellLinkType,children:tn[c.type]}),f.jsx(w.Tooltip,{showIfEllipsis:!0,title:c.name,asChild:!0,children:f.jsx("span",{className:W.cellLinkUrl,children:c.name})})]}),f.jsxs("div",{className:W.cellLinkOperations,children:[T&&f.jsx("div",{className:ut(W.cellLinkOperation,{[W.cellLinkOperationError]:D}),onClick:()=>{if(!D){if(c.type!==v.SheetHyperLinkType.URL){const U=new URL(window.location.href);U.hash=c.url.slice(1),navigator.clipboard.writeText(U.href)}else navigator.clipboard.writeText(c.url);i.show({content:r.t("hyperLink.message.coped"),type:w.MessageType.Info})}},children:f.jsx(w.Tooltip,{placement:"bottom",title:r.t("hyperLink.popup.copy"),children:f.jsx(st,{})})}),R&&f.jsxs(f.Fragment,{children:[f.jsx("div",{className:W.cellLinkOperation,onClick:()=>{t.executeCommand(ke.id,{unitId:I,subUnitId:S,row:u,col:h,customRangeId:p.rangeId,type:k})},children:f.jsx(w.Tooltip,{placement:"bottom",title:r.t("hyperLink.popup.edit"),children:f.jsx(ct,{})})}),f.jsx("div",{className:W.cellLinkOperation,onClick:()=>{const U=k===y.EDITING||k===y.ZEN_EDITOR?v.CancelRichHyperLinkCommand.id:v.CancelHyperLinkCommand.id;t.syncExecuteCommand(U,{unitId:I,subUnitId:S,id:p.rangeId,row:u,column:h,documentId:k===y.ZEN_EDITOR?o.DOCS_ZEN_EDITOR_UNIT_ID_KEY:a.getCurrentEditorId()})&&n.hideCurrentPopup(void 0,!0)},children:f.jsx(w.Tooltip,{placement:"bottom",title:r.t("hyperLink.popup.cancel"),children:f.jsx(at,{})})})]})]})]})},Te=()=>{var r,s;const e=m.useDependency(g.SheetsHyperLinkPopupService),[n,t]=E.useState(null),i=m.useDependency(o.IUniverInstanceService);if(E.useEffect(()=>{t(e.currentPopup);const a=e.currentPopup$.subscribe(l=>{t(l)});return()=>{a.unsubscribe()}},[e.currentPopup,e.currentPopup$]),!n)return null;if(n.showAll){const a=i.getUnit(n.unitId,o.UniverInstanceType.UNIVER_SHEET),l=a==null?void 0:a.getSheetBySheetId(n.subUnitId),d=l==null?void 0:l.getCell(n.row,n.col),p=(s=(r=d==null?void 0:d.p)==null?void 0:r.body)==null?void 0:s.customRanges;return p!=null&&p.length?f.jsx("div",{children:p.map(u=>f.jsx(pt,{...n,customRange:u},u.rangeId))}):null}return f.jsx(pt,{...n})};Te.componentKey="univer.sheet.cell-link-popup";var nn=Object.getOwnPropertyDescriptor,rn=(e,n,t,i)=>{for(var r=i>1?void 0:i?nn(n,t):n,s=e.length-1,a;s>=0;s--)(a=e[s])&&(r=a(r)||r);return r},oe=(e,n)=>(t,i)=>n(t,i,e);const ht=(e,n)=>{var t,i;return e.unitId===n.unitId&&e.subUnitId===n.subUnitId&&e.row===n.row&&e.col===n.col&&((t=e.customRange)==null?void 0:t.rangeId)===((i=n.customRange)==null?void 0:i.rangeId)&&e.type===n.type};g.SheetsHyperLinkPopupService=class extends o.Disposable{constructor(t,i,r,s,a,l,d){super();K(this,"_currentPopup",null);K(this,"_currentPopup$",new P.Subject);K(this,"currentPopup$",this._currentPopup$.asObservable());K(this,"_currentEditingPopup",null);K(this,"_currentEditing$",new P.BehaviorSubject(null));K(this,"currentEditing$",this._currentEditing$.asObservable());K(this,"_isKeepVisible",!1);this._sheetCanvasPopManagerService=t,this._injector=i,this._univerInstanceService=r,this._editorBridgeService=s,this._textSelectionManagerService=a,this._docCanvasPopManagerService=l,this._zenZoneService=d,this.disposeWithMe(()=>{this.hideCurrentPopup(),this.endEditing(),this._currentEditing$.complete(),this._currentPopup$.complete()})}get currentPopup(){return this._currentPopup}get currentEditing(){return this._currentEditing$.getValue()}setIsKeepVisible(t){this._isKeepVisible=t}getIsKeepVisible(){return this._isKeepVisible}showPopup(t){if(this._currentPopup&&ht(t,this._currentPopup)||(this.hideCurrentPopup(void 0,!0),t.type!==y.ZEN_EDITOR&&this._zenZoneService.visible))return;const i=this._currentEditing$.getValue();if(i&&ht(t,i))return;const{unitId:r,subUnitId:s,row:a,col:l,customRangeRect:d,customRange:p}=t;let u;const h={componentKey:Te.componentKey,direction:"bottom",onClickOutside:()=>{this.hideCurrentPopup()},onClick:()=>{this.hideCurrentPopup(t.type,!0)}};if(t.type===y.EDITING){if(!p)return;u=d&&this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(d,h)}else if(t.type===y.ZEN_EDITOR){if(!p)return;u=this._docCanvasPopManagerService.attachPopupToRange({startOffset:p.startIndex,endOffset:p.endIndex+1,collapsed:!1},h,o.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}else if(t.showAll)u=this._sheetCanvasPopManagerService.attachPopupToCell(t.row,t.col,h,r,s);else{if(!p)return;u=d&&this._sheetCanvasPopManagerService.attachPopupByPosition(d,h,t)}u&&(this._currentPopup={unitId:r,subUnitId:s,disposable:u,row:a,col:l,editPermission:!!t.editPermission,copyPermission:!!t.copyPermission,customRange:p,type:t.type,showAll:t.showAll},this._currentPopup$.next(this._currentPopup))}hideCurrentPopup(t,i){var r,s;this._currentPopup&&((!t||t===this._currentPopup.type)&&this._currentPopup.disposable.canDispose()||i)&&((s=(r=this._currentPopup)==null?void 0:r.disposable)==null||s.dispose(),this._currentPopup=null,this._currentPopup$.next(null))}_getEditingRange(){var r,s,a;const t=this._editorBridgeService.isVisible().visible,i=this._editorBridgeService.getEditCellState();if(t&&i){const l=this._textSelectionManagerService.getActiveTextRange(),d=(r=i.documentLayoutObject.documentModel)==null?void 0:r.getBody();if(!d)return null;if(!l||l.collapsed)return{startOffset:0,endOffset:d.dataStream.length-2,collapsed:d.dataStream.length-2===0,label:o.BuildTextUtils.transform.getPlainText(d.dataStream)};const p=o.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(l,(a=(s=d.customRanges)==null?void 0:s.filter(I=>I.rangeType===o.CustomRangeType.HYPERLINK))!=null?a:[]);let u=l.startOffset,h=l.endOffset;return p.forEach(I=>{u=Math.min(u,I.startIndex),h=Math.max(h,I.endIndex+1)}),{startOffset:u,endOffset:h,collapsed:u===h,label:o.BuildTextUtils.transform.getPlainText(d.dataStream.slice(u,h))}}return null}get _editPopup(){return{componentKey:Re.componentKey,direction:"vertical",onClickOutside:()=>{this.getIsKeepVisible()||this.endEditing()},onContextMenu:()=>{this.getIsKeepVisible()||this.endEditing()},hiddenType:"hide"}}startAddEditing(t){var a,l,d,p,u;const{unitId:i,subUnitId:r,type:s}=t;if(s===y.ZEN_EDITOR){const h=this._univerInstanceService.getUnit(o.DOCS_ZEN_EDITOR_UNIT_ID_KEY,o.UniverInstanceType.UNIVER_DOC);if(!h)return;const I=this._textSelectionManagerService.getActiveTextRange();if(!I)return;this._currentEditingPopup=this._docCanvasPopManagerService.attachPopupToRange(I,this._editPopup,o.DOCS_ZEN_EDITOR_UNIT_ID_KEY);const S=(a=h.getBody())==null?void 0:a.dataStream.slice(I.startOffset,I.endOffset);this._currentEditing$.next({...t,label:S})}else if(s===y.EDITING){const h=this._getEditingRange();if(!h)return;this._textSelectionManagerService.replaceDocRanges([{...h}],{unitId:o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY});const I=this._injector.get(pe.IRenderManagerService).getRenderById(o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(!I)return;const S=ee.calcDocRangePositions(h,I);if(!(S!=null&&S.length))return;this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(S.pop(),this._editPopup,i,r),this._currentEditing$.next({...t,label:(l=h==null?void 0:h.label)!=null?l:""})}else{this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToCell(t.row,t.col,this._editPopup,i,r);const h=this._univerInstanceService.getUnit(i,o.UniverInstanceType.UNIVER_SHEET),I=h==null?void 0:h.getSheetBySheetId(r),S=I==null?void 0:I.getCellRaw(t.row,t.col);this._currentEditing$.next({...t,label:S!=null&&S.p?o.BuildTextUtils.transform.getPlainText((p=(d=S.p.body)==null?void 0:d.dataStream)!=null?p:""):((u=S==null?void 0:S.v)!=null?u:"").toString()})}}startEditing(t){var l,d,p,u,h,I;(l=this._currentEditingPopup)==null||l.dispose(),this.hideCurrentPopup(void 0,!0);const{unitId:i,subUnitId:r}=t;let s,a;if(t.type===y.ZEN_EDITOR){const S=this._univerInstanceService.getUnit(o.DOCS_ZEN_EDITOR_UNIT_ID_KEY,o.UniverInstanceType.UNIVER_DOC);if(s=(p=(d=S==null?void 0:S.getBody())==null?void 0:d.customRanges)==null?void 0:p.find(R=>R.rangeId===t.customRangeId),a=s?(u=S==null?void 0:S.getBody())==null?void 0:u.dataStream.slice(s.startIndex,s.endIndex+1):"",!s||!a)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:s.startIndex,endOffset:s.endIndex+1}]),this._currentEditingPopup=this._docCanvasPopManagerService.attachPopupToRange({startOffset:s.startIndex,endOffset:s.endIndex,collapsed:!1},this._editPopup,o.DOCS_ZEN_EDITOR_UNIT_ID_KEY)}else if(t.type===y.EDITING){const S=C.getEditingCustomRangePosition(this._injector,t.unitId,t.subUnitId,t.row,t.col,t.customRangeId);if(!S||!((h=S.rects)!=null&&h.length))return;s=S.customRange,a=S.label,this._textSelectionManagerService.replaceTextRanges([{startOffset:s.startIndex,endOffset:s.endIndex+1}]),this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToAbsolutePosition(S.rects.pop(),this._editPopup,i,r)}else{const S=this._univerInstanceService.getUnit(i,o.UniverInstanceType.UNIVER_SHEET),R=S==null?void 0:S.getSheetBySheetId(r),T=R==null?void 0:R.getCellRaw(t.row,t.col),k=S==null?void 0:S.getStyles().getStyleByCell(T),c=k==null?void 0:k.tr,D=C.getCustomRangePosition(this._injector,t.unitId,t.subUnitId,t.row,t.col,t.customRangeId);if(!D||!((I=D.rects)!=null&&I.length))return;s=D.customRange,a=D.label,c?this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupToCell(t.row,t.col,this._editPopup,i,r):this._currentEditingPopup=this._sheetCanvasPopManagerService.attachPopupByPosition(D.rects.pop(),this._editPopup,{unitId:i,subUnitId:r,row:t.row,col:t.col})}this._currentEditing$.next({...t,customRange:s,label:a})}endEditing(t){var r;const i=this._currentEditing$.getValue();i&&(!t||t===i.type)&&((r=this._currentEditingPopup)==null||r.dispose(),this._currentEditing$.next(null))}},g.SheetsHyperLinkPopupService=rn([oe(0,o.Inject(C.SheetCanvasPopManagerService)),oe(1,o.Inject(o.Injector)),oe(2,o.IUniverInstanceService),oe(3,C.IEditorBridgeService),oe(4,o.Inject(he.DocSelectionManagerService)),oe(5,o.Inject(ee.DocCanvasPopManagerService)),oe(6,m.IZenZoneService)],g.SheetsHyperLinkPopupService);var ge=(e=>(e[e.ALLOWED=0]="ALLOWED",e[e.DISABLED_BY_CELL=1]="DISABLED_BY_CELL",e[e.ALLOW_ON_EDITING=2]="ALLOW_ON_EDITING",e))(ge||{});const on=new Set([o.DataValidationType.CHECKBOX,o.DataValidationType.LIST,o.DataValidationType.LIST_MULTIPLE]),Fe=(e,n,t,i)=>{var l,d;const r=n.getCell(t,i);if(r!=null&&r.f||r!=null&&r.si)return 1;const s=e.has(tt.SheetDataValidationModel)?e.get(tt.SheetDataValidationModel):null,a=s==null?void 0:s.getRuleByLocation(n.getUnitId(),n.getSheetId(),t,i);return a&&on.has(a.type)?!0:(d=(l=r==null?void 0:r.p)==null?void 0:l.drawingsOrder)!=null&&d.length?2:0},sn=e=>{const n=e.get(o.IUniverInstanceService).getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!n)return!0;const t=n.getActiveSheet(),i=e.get(L.SheetsSelectionsService).getCurrentSelections();if(!i.length)return!0;const r=i[0].range.startRow,s=i[0].range.startColumn;return Fe(e,t,r,s)===1},an=e=>{const n=e.get(he.DocSelectionManagerService),t=e.get(o.IUniverInstanceService),i=n.getTextRanges();if(!(i!=null&&i.length))return!0;const r=t.getCurrentUnitForType(o.UniverInstanceType.UNIVER_DOC);return!!(!r||i.every(a=>a.collapsed)||!r.getSelfOrHeaderFooterModel(i[0].segmentId).getBody())},ke={type:o.CommandType.OPERATION,id:"sheet.operation.open-hyper-link-edit-panel",handler(e,n){if(!n)return!1;const t=e.get(g.SheetsHyperLinkPopupService);return n.customRangeId?t.startEditing(n):t.startAddEditing(n),!0}},ve={type:o.CommandType.OPERATION,id:"sheet.operation.close-hyper-link-popup",handler(e){return e.get(g.SheetsHyperLinkPopupService).endEditing(),!0}},Oe={type:o.CommandType.OPERATION,id:"sheet.operation.insert-hyper-link",handler(e){var h;const n=e.get(o.IUniverInstanceService),t=L.getSheetCommandTarget(n),i=e.get(C.IEditorBridgeService);if(!t)return!1;const r=e.get(o.ICommandService),a=e.get(L.SheetsSelectionsService).getCurrentLastSelection();if(!a)return!1;const l=a.range.startRow,d=a.range.startColumn,p=i.isVisible(),u=((h=n.getFocusedUnit())==null?void 0:h.getUnitId())===o.DOCS_ZEN_EDITOR_UNIT_ID_KEY;return r.executeCommand(ke.id,{unitId:t.unitId,subUnitId:t.subUnitId,row:l,col:d,type:u?y.ZEN_EDITOR:p.visible?y.EDITING:y.VIEWING})}},se={type:o.CommandType.OPERATION,id:"sheet.operation.insert-hyper-link-toolbar",handler(e){if(sn(e))return!1;const n=e.get(o.ICommandService);return e.get(g.SheetsHyperLinkPopupService).currentEditing?n.executeCommand(ve.id):n.executeCommand(Oe.id)}},Ze=(e,n=o.DOCS_ZEN_EDITOR_UNIT_ID_KEY)=>{var r;const t=e.get(o.IUniverInstanceService),i=(r=e.get(pe.IRenderManagerService).getRenderById(n))==null?void 0:r.with(ee.DocSelectionRenderService);return i?i.textSelectionInner$.pipe(P.map(()=>{const a=e.get(C.IEditorBridgeService).getEditCellState();if(!a)return!0;const l=L.getSheetCommandTarget(t,{unitId:a.unitId,subUnitId:a.sheetId});return!(l!=null&&l.worksheet)||Fe(e,l.worksheet,a.row,a.column)===1?!0:an(e)})):P.of(!0)},gt=e=>{const n=C.getCurrentRangeDisable$(e,{workbookTypes:[L.WorkbookEditablePermission],worksheetTypes:[L.WorksheetEditPermission,L.WorksheetSetCellValuePermission,L.WorksheetInsertHyperlinkPermission],rangeTypes:[L.RangeProtectionPermissionEditPoint]},!0),t=e.get(o.IUniverInstanceService),i=e.get(L.SheetsSelectionsService),r=e.has(C.IEditorBridgeService)?e.get(C.IEditorBridgeService):null,s=t.focused$.pipe(P.filter(a=>!!a),P.map(a=>t.getUnit(a,o.UniverInstanceType.UNIVER_SHEET)),P.filter(a=>!!a),P.switchMap(a=>a.activeSheet$),P.switchMap(a=>i.selectionMoveEnd$.pipe(P.map(l=>a&&{selections:l,sheet:a}))),P.map(a=>{if(!a)return ge.DISABLED_BY_CELL;const{selections:l,sheet:d}=a;if(!l.length)return ge.DISABLED_BY_CELL;const p=l[0].range.startRow,u=l[0].range.startColumn;return Fe(e,d,p,u)}),P.switchMap(a=>{if(a===ge.DISABLED_BY_CELL)return P.of(!0);const l=(r?r.visible$:P.of(null)).pipe(P.map(p=>p!=null&&p.visible?o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY:void 0)),d=e.get(o.IContextService).subscribeContextValue$(o.FOCUSING_FX_BAR_EDITOR);return P.combineLatest([l,d]).pipe(P.switchMap(([p,u])=>p?u?P.of(!0):Ze(e,p):P.of(a===ge.ALLOW_ON_EDITING)))}));return n.pipe(P.distinctUntilChanged(),P.switchMap(a=>s.pipe(P.map(l=>a||l))))},De={commandId:Oe.id,type:m.MenuItemType.BUTTON,title:"hyperLink.menu.add",icon:"LinkSingle"},be=e=>`${e}-zen-editor`,cn=e=>({...De,id:De.commandId,hidden$:m.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:gt(e)}),ln=e=>({...De,id:be(De.commandId),hidden$:m.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_DOC,o.DOCS_ZEN_EDITOR_UNIT_ID_KEY),disabled$:Ze(e)}),we={tooltip:"hyperLink.form.addTitle",commandId:se.id,type:m.MenuItemType.BUTTON,icon:"LinkSingle"},dn=e=>({...we,id:we.commandId,hidden$:m.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_SHEET),disabled$:gt(e)}),un=e=>({...we,id:be(we.commandId),hidden$:m.getMenuHiddenObservable(e,o.UniverInstanceType.UNIVER_DOC,o.DOCS_ZEN_EDITOR_UNIT_ID_KEY),disabled$:Ze(e)}),Ke={id:se.id,binding:m.KeyCode.K|m.MetaKeys.CTRL_COMMAND,preconditions:C.whenSheetEditorFocused};var pn=Object.getOwnPropertyDescriptor,hn=(e,n,t,i)=>{for(var r=i>1?void 0:i?pn(n,t):n,s=e.length-1,a;s>=0;s--)(a=e[s])&&(r=a(r)||r);return r},vt=(e,n)=>(t,i)=>n(t,i,e);let Ne=class extends o.Disposable{constructor(e,n){super(),this._autoFillService=e,this._hyperLinkModel=n,this._initAutoFill()}_initAutoFill(){const e=()=>({redos:[],undos:[]}),n=(i,r)=>{const{source:s,target:a,unitId:l,subUnitId:d}=i,p=C.virtualizeDiscreteRanges([s,a]),[u,h]=p.ranges,{mapFunc:I}=p,S={row:u.startRow,col:u.startColumn},R=C.getAutoFillRepeatRange(u,h),T=[],k=[];return R.forEach(c=>{const D=c.repeatStartCell,B=c.relativeRange,M={startRow:S.row,startColumn:S.col,endColumn:S.col,endRow:S.row},U={startRow:D.row,startColumn:D.col,endColumn:D.col,endRow:D.row};o.Range.foreach(B,(x,$)=>{const J=o.Rectangle.getPositionRange({startRow:x,startColumn:$,endColumn:$,endRow:x},M),{row:_e,col:Ve}=I(J.startRow,J.startColumn),ae=this._hyperLinkModel.getHyperLinkByLocation(l,d,_e,Ve),Ie=o.Rectangle.getPositionRange({startRow:x,startColumn:$,endColumn:$,endRow:x},U),{row:me,col:fe}=I(Ie.startRow,Ie.startColumn),ce=o.Tools.generateRandomId(),Z=this._hyperLinkModel.getHyperLinkByLocation(l,d,me,fe);Z&&T.push({id:v.RemoveHyperLinkMutation.id,params:{unitId:l,subUnitId:d,id:Z.id}}),(C.APPLY_TYPE.COPY===r||C.APPLY_TYPE.SERIES===r)&&ae&&(T.push({id:v.AddHyperLinkMutation.id,params:{unitId:l,subUnitId:d,link:{...ae,id:ce,row:me,column:fe}}}),k.push({id:v.RemoveHyperLinkMutation.id,params:{unitId:l,subUnitId:d,id:ce}})),Z&&k.push({id:v.AddHyperLinkMutation.id,params:{unitId:l,subUnitId:d,link:Z}})})}),{undos:k,redos:T}},t={id:$e,onFillData:(i,r,s)=>s===C.APPLY_TYPE.COPY||s===C.APPLY_TYPE.ONLY_FORMAT||s===C.APPLY_TYPE.SERIES?n(i,s):e()};this.disposeWithMe(this._autoFillService.addHook(t))}};Ne=hn([vt(0,C.IAutoFillService),vt(1,o.Inject(v.HyperLinkModel))],Ne);var gn=Object.getOwnPropertyDescriptor,vn=(e,n,t,i)=>{for(var r=i>1?void 0:i?gn(n,t):n,s=e.length-1,a;s>=0;s--)(a=e[s])&&(r=a(r)||r);return r},We=(e,n)=>(t,i)=>n(t,i,e);let Me=class extends o.Disposable{constructor(e,n,t){super(),this._localeService=e,this._commandService=n,this._sheetPermissionCheckController=t,this._commandExecutedListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{e.id===Ke.id&&(this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[L.WorkbookEditablePermission],rangeTypes:[L.RangeProtectionPermissionEditPoint],worksheetTypes:[L.WorksheetEditPermission,L.WorksheetSetCellValuePermission,L.WorksheetInsertHyperlinkPermission]})||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t("permission.dialog.hyperLinkErr")))}))}};Me=vn([We(0,o.Inject(o.LocaleService)),We(1,o.ICommandService),We(2,o.Inject(L.SheetPermissionCheckController))],Me);var Sn=Object.getOwnPropertyDescriptor,_n=(e,n,t,i)=>{for(var r=i>1?void 0:i?Sn(n,t):n,s=e.length-1,a;s>=0;s--)(a=e[s])&&(r=a(r)||r);return r},Y=(e,n)=>(t,i)=>n(t,i,e);let Ue=class extends o.Disposable{constructor(e,n,t,i,r,s,a,l,d,p){super(),this._hoverManagerService=e,this._sheetsHyperLinkPopupService=n,this._renderManagerService=t,this._permissionService=i,this._sheetPermissionCheckController=r,this._commandService=s,this._editorBridgeService=a,this._textSelectionManagerService=l,this._univerInstanceService=d,this._zenZoneService=p,this._initHoverListener(),this._initCommandListener(),this._initHoverEditingListener(),this._initTextSelectionListener(),this._initZenEditor()}_getLinkPermission(e){const{unitId:n,subUnitId:t,row:i,col:r}=e,s=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET);if(!(s==null?void 0:s.getSheetBySheetId(t)))return{viewPermission:!1,editPermission:!1,copyPermission:!1};const l=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[L.WorkbookViewPermission],worksheetTypes:[L.WorksheetViewPermission],rangeTypes:[L.RangeProtectionPermissionViewPoint]},[{startRow:i,startColumn:r,endRow:i,endColumn:r}]),d=this._sheetPermissionCheckController.permissionCheckWithRanges({workbookTypes:[L.WorkbookEditablePermission],worksheetTypes:[L.WorksheetEditPermission,L.WorksheetInsertHyperlinkPermission],rangeTypes:[L.RangeProtectionPermissionEditPoint]},[{startRow:i,startColumn:r,endRow:i,endColumn:r}]),p=this._permissionService.composePermission([new L.WorkbookCopyPermission(n).id,new L.WorksheetCopyPermission(n,t).id]).every(u=>u.value);return{viewPermission:l,editPermission:d,copyPermission:p}}_initHoverListener(){this.disposeWithMe(this._hoverManagerService.currentRichText$.pipe(P.debounceTime(200)).subscribe(e=>{var M,U;if(!e){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const{unitId:n,subUnitId:t,row:i,col:r}=e,s=this._renderManagerService.getRenderById(n);if(!s)return;const a=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET),l=a==null?void 0:a.getSheetBySheetId(t);if(!l)return;if(!s.with(C.HoverRenderController).active){this._sheetsHyperLinkPopupService.hideCurrentPopup(y.VIEWING);return}const p=(M=s==null?void 0:s.with(C.SheetSkeletonManagerService).getSkeletonParam(t))==null?void 0:M.skeleton,u=r,h=i;let I=h,S=u;p&&p.overflowCache.forValue((x,$,J)=>{o.Rectangle.contains(J,{startColumn:u,endColumn:u,startRow:h,endRow:h})&&(I=x,S=$)});const{viewPermission:R,editPermission:T,copyPermission:k}=this._getLinkPermission(e);if(!R){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const c=l.getCellStyleOnly(I,S),D=a.getStyles().getStyleByCell(c),B=(U=D==null?void 0:D.tr)==null?void 0:U.a;if(!B&&!e.customRange){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}this._sheetsHyperLinkPopupService.showPopup({row:I,col:S,editPermission:T,copyPermission:k,customRange:e.customRange,customRangeRect:e.rect,type:y.VIEWING,unitId:n,subUnitId:t,showAll:!!B})}))}_initHoverEditingListener(){let e=null;this.disposeWithMe(this._editorBridgeService.currentEditCellState$.pipe(P.switchMap(n=>this._editorBridgeService.visible$.pipe(P.map(t=>({visible:t,state:n}))))).subscribe(({visible:n,state:t})=>{if(!t||t.editorUnitId!==o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)return;if(!n.visible){e==null||e.unsubscribe(),this._sheetsHyperLinkPopupService.hideCurrentPopup(y.EDITING),this._sheetsHyperLinkPopupService.endEditing(y.EDITING);return}const{editorUnitId:i,unitId:r,sheetId:s,row:a,column:l}=t,d=this._renderManagerService.getRenderById(i);if(!d)return;const{editPermission:p,viewPermission:u,copyPermission:h}=this._getLinkPermission({unitId:r,subUnitId:s,row:a,col:l}),I=d.with(ee.DocEventManagerService);u&&(e==null||e.unsubscribe(),e=I.hoverCustomRanges$.pipe(P.debounceTime(200)).subscribe(S=>{var D,B;const R=S.find(M=>M.range.rangeType===o.CustomRangeType.HYPERLINK);if(!R){this._sheetsHyperLinkPopupService.hideCurrentPopup();return}const T=R.rects[R.rects.length-1];if(!((B=(D=this._renderManagerService.getRenderById(r))==null?void 0:D.with(C.SheetSkeletonManagerService).getSkeletonParam(s))==null?void 0:B.skeleton)||!T)return;const c=d.engine.getCanvasElement().getBoundingClientRect();this._sheetsHyperLinkPopupService.showPopup({unitId:r,subUnitId:s,row:a,col:l,customRange:R.range,customRangeRect:{left:T.left+c.left,top:T.top+c.top,bottom:T.bottom+c.top,right:T.right+c.left},editPermission:p,copyPermission:h,type:y.EDITING})}))})),this.disposeWithMe(()=>{e==null||e.unsubscribe()})}_initZenEditor(){this.disposeWithMe(this._zenZoneService.visible$.subscribe(e=>{e?(this._sheetsHyperLinkPopupService.hideCurrentPopup(y.VIEWING),this._sheetsHyperLinkPopupService.hideCurrentPopup(y.EDITING),this._sheetsHyperLinkPopupService.endEditing(y.EDITING),this._sheetsHyperLinkPopupService.hideCurrentPopup(y.VIEWING)):(this._sheetsHyperLinkPopupService.hideCurrentPopup(y.ZEN_EDITOR),this._sheetsHyperLinkPopupService.endEditing(y.ZEN_EDITOR))})),this.disposeWithMe(this._univerInstanceService.focused$.pipe(P.switchMap(e=>{const n=e===o.DOCS_ZEN_EDITOR_UNIT_ID_KEY?this._renderManagerService.getRenderById(e):null;return n?n.with(ee.DocEventManagerService).hoverCustomRanges$.pipe(P.debounceTime(200)):new P.Observable(t=>{t.next(null)})})).subscribe(e=>{const n=e==null?void 0:e.find(i=>i.range.rangeType===o.CustomRangeType.HYPERLINK),t=this._editorBridgeService.getEditCellState();if(n&&t){const{unitId:i,sheetId:r,row:s,column:a}=t,{editPermission:l,viewPermission:d,copyPermission:p}=this._getLinkPermission({unitId:i,subUnitId:r,row:s,col:a});d&&this._sheetsHyperLinkPopupService.showPopup({type:y.ZEN_EDITOR,unitId:i,subUnitId:r,row:s,col:a,customRange:n.range,editPermission:l,copyPermission:p})}else this._sheetsHyperLinkPopupService.hideCurrentPopup(y.ZEN_EDITOR)}))}_initTextSelectionListener(){this.disposeWithMe(this._textSelectionManagerService.textSelection$.subscribe(e=>{e&&e.unitId===o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._sheetsHyperLinkPopupService.endEditing(y.EDITING)}))}_initCommandListener(){const e=[L.ClearSelectionContentCommand.id,L.ClearSelectionAllCommand.id,L.ClearSelectionFormatCommand.id];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{e.includes(n.id)&&this._sheetsHyperLinkPopupService.hideCurrentPopup()}))}};Ue=_n([Y(0,o.Inject(C.HoverManagerService)),Y(1,o.Inject(g.SheetsHyperLinkPopupService)),Y(2,o.Inject(pe.IRenderManagerService)),Y(3,o.Inject(o.IPermissionService)),Y(4,o.Inject(L.SheetPermissionCheckController)),Y(5,o.ICommandService),Y(6,C.IEditorBridgeService),Y(7,o.Inject(he.DocSelectionManagerService)),Y(8,o.IUniverInstanceService),Y(9,m.IZenZoneService)],Ue);var In=Object.getOwnPropertyDescriptor,St=(e,n,t,i)=>{for(var r=i>1?void 0:i?In(n,t):n,s=e.length-1,a;s>=0;s--)(a=e[s])&&(r=a(r)||r);return r},Ye=(e,n)=>(t,i)=>n(t,i,e);let Ge=class extends o.Disposable{constructor(e,n){super(),this._context=e,this._hyperLinkModel=n,this._initSkeletonChange()}_initSkeletonChange(){const e=()=>{var n;(n=this._context.mainComponent)==null||n.makeForceDirty()};this.disposeWithMe(this._hyperLinkModel.linkUpdate$.pipe(P.debounceTime(16)).subscribe(()=>{e()}))}};Ge=St([Ye(1,o.Inject(v.HyperLinkModel))],Ge);let He=class extends o.Disposable{constructor(e,n){super(),this._sheetInterceptorService=e,this._hyperLinkModel=n,this._initViewModelIntercept()}_initViewModelIntercept(){this.disposeWithMe(this._sheetInterceptorService.intercept(L.INTERCEPTOR_POINT.CELL_CONTENT,{effect:o.InterceptorEffectEnum.Value,priority:100,handler:(e,n,t)=>{const{row:i,col:r,unitId:s,subUnitId:a}=n,l=this._hyperLinkModel.getHyperLinkByLocation(s,a,i,r);return t(l?{...e,linkUrl:l.payload,linkId:l.id}:e)}}))}};He=St([Ye(0,o.Inject(L.SheetInterceptorService)),Ye(1,o.Inject(v.HyperLinkModel))],He);const mn={[m.RibbonStartGroup.OTHERS]:{[se.id]:{order:2,menuItemFactory:dn},[be(se.id)]:{order:2,menuItemFactory:un}},[m.ContextMenuPosition.MAIN_AREA]:{[m.ContextMenuGroup.OTHERS]:{order:1,[se.id]:{order:0,menuItemFactory:cn},[be(se.id)]:{order:0,menuItemFactory:ln}}}};var fn=Object.getOwnPropertyDescriptor,yn=(e,n,t,i)=>{for(var r=i>1?void 0:i?fn(n,t):n,s=e.length-1,a;s>=0;s--)(a=e[s])&&(r=a(r)||r);return r},Se=(e,n)=>(t,i)=>n(t,i,e);let Ae=class extends o.Disposable{constructor(e,n,t,i,r){super(),this._componentManager=e,this._commandService=n,this._menuManagerService=t,this._injector=i,this._shortcutService=r,this._initComponents(),this._initCommands(),this._initMenus(),this._initShortCut()}_initComponents(){[[Te,Te.componentKey],[Re,Re.componentKey],[je,"LinkSingle"]].forEach(([e,n])=>{this._componentManager.register(n,e)})}_initCommands(){[ke,ve,Oe,se].forEach(e=>{this._commandService.registerCommand(e)})}_initMenus(){this._menuManagerService.mergeMenu(mn)}_initShortCut(){this._shortcutService.registerShortcut(Ke)}};Ae=yn([Se(0,o.Inject(m.ComponentManager)),Se(1,o.ICommandService),Se(2,m.IMenuManagerService),Se(3,o.Inject(o.Injector)),Se(4,o.Inject(m.IShortcutService))],Ae);var Cn=Object.getOwnPropertyDescriptor,En=(e,n,t,i)=>{for(var r=i>1?void 0:i?Cn(n,t):n,s=e.length-1,a;s>=0;s--)(a=e[s])&&(r=a(r)||r);return r},_t=(e,n)=>(t,i)=>n(t,i,e);let Be=class extends o.Disposable{constructor(e,n){super(),this._parserService=e,this._resolverService=n,this._handleInitUrl()}_handleInitUrl(){const e=location.hash;if(e){const n=this._parserService.parseHyperLink(e);this._resolverService.navigate(n)}}};Be=En([_t(0,o.Inject(v.SheetsHyperLinkParserService)),_t(1,o.Inject(g.SheetsHyperLinkResolverService))],Be);var Ln=Object.defineProperty,Rn=Object.getOwnPropertyDescriptor,Pn=(e,n,t)=>n in e?Ln(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t,Tn=(e,n,t,i)=>{for(var r=i>1?void 0:i?Rn(n,t):n,s=e.length-1,a;s>=0;s--)(a=e[s])&&(r=a(r)||r);return r},It=(e,n)=>(t,i)=>n(t,i,e),mt=(e,n,t)=>Pn(e,typeof n!="symbol"?n+"":n,t);g.UniverSheetsHyperLinkUIPlugin=class extends o.Plugin{constructor(n=it,t,i){super(),this._config=n,this._injector=t,this._configService=i;const{menu:r,...s}=o.merge({},it,this._config);r&&this._configService.setConfig("menu",r,{merge:!0}),this._configService.setConfig(nt,s)}onStarting(){[[g.SheetsHyperLinkResolverService],[g.SheetsHyperLinkPopupService],[xe],[He],[Ue],[Ae],[Ne],[g.SheetsHyperLinkCopyPasteController],[Me],[Be]].forEach(t=>this._injector.add(t)),this._injector.get(He)}onReady(){this._injector.get(pe.IRenderManagerService).registerRenderModule(o.UniverInstanceType.UNIVER_SHEET,[Ge]),this._injector.get(Ne),this._injector.get(g.SheetsHyperLinkCopyPasteController),this._injector.get(Ae)}onRendered(){this._injector.get(Me),this._injector.get(Be),this._injector.get(Ue)}},mt(g.UniverSheetsHyperLinkUIPlugin,"pluginName",$e),mt(g.UniverSheetsHyperLinkUIPlugin,"type",o.UniverInstanceType.UNIVER_SHEET),g.UniverSheetsHyperLinkUIPlugin=Tn([o.DependentOn(v.UniverSheetsHyperLinkPlugin,ee.UniverDocsUIPlugin),It(1,o.Inject(o.Injector)),It(2,o.IConfigService)],g.UniverSheetsHyperLinkUIPlugin),g.CloseHyperLinkPopupOperation=ve,g.InsertHyperLinkOperation=Oe,g.InsertLinkShortcut=Ke,g.OpenHyperLinkEditPanelOperation=ke,g.SheetsHyperLinkSidePanelService=xe,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
// @univerjs/sheets-hyper-link-ui/facade
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/preset-sheets-hyper-link",
|
|
3
|
-
"version": "0.6.0-
|
|
3
|
+
"version": "0.6.0-nightly.202502131606",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -57,11 +57,11 @@
|
|
|
57
57
|
"rxjs": ">=7.0.0"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@univerjs/sheets-hyper-link": "0.6.0-
|
|
61
|
-
"@univerjs/sheets-hyper-link-ui": "0.6.0-
|
|
60
|
+
"@univerjs/sheets-hyper-link": "0.6.0-nightly.202502131606",
|
|
61
|
+
"@univerjs/sheets-hyper-link-ui": "0.6.0-nightly.202502131606"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@univerjs/core": "0.6.0-
|
|
64
|
+
"@univerjs/core": "0.6.0-nightly.202502131606",
|
|
65
65
|
"typescript": "^5.7.2",
|
|
66
66
|
"@univerjs-infra/shared": "0.6.0-alpha.0"
|
|
67
67
|
},
|