@univerjs/sheets-hyper-link 0.6.3 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var ve=Object.defineProperty;var Ie=(i,t,e)=>t in i?ve(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var C=(i,t,e)=>Ie(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),Re=require("rxjs"),h=require("@univerjs/sheets"),k=require("@univerjs/engine-formula"),Z=require("@univerjs/docs");var Me=Object.getOwnPropertyDescriptor,Ce=(i,t,e,n)=>{for(var r=n>1?void 0:n?Me(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},ke=(i,t)=>(e,n)=>t(e,n,i);exports.HyperLinkModel=class extends o.Disposable{constructor(e){super();C(this,"_linkUpdate$",new Re.Subject);C(this,"linkUpdate$",this._linkUpdate$.asObservable());C(this,"_linkMap",new Map);C(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let r=this._linkMap.get(e);r||(r=new Map,this._linkMap.set(e,r));let s=r.get(n);s||(s=new o.ObjectMatrix,r.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,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n);return s.setValue(r.row,r.column,r),a.set(r.id,{row:r.row,column:r.column,link:r}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:r,type:"add"}),!0}updateHyperLink(e,n,r,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(r);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:r,type:"update",silent:a})),!0}updateHyperLinkRef(e,n,r,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(r);if(!l)return!0;let u=d.getValue(l.row,l.column);return!u||u.id!==r?u=l.link:d.realDeleteValue(l.row,l.column),Object.assign(u,s),c.set(r,{...s,link:u}),d.setValue(s.row,s.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:r,type:"updateRef",silent:a}),!0}removeHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(r);if(!d)return!1;a.delete(r);const c=s.getValue(d.row,d.column);return c&&c.id===r&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(r);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,r,s){const{matrix:a}=this._ensureMap(e,n);return a.getValue(r,s)}getHyperLinkByLocationSync(e,n,r,s){var p,m,y,g,f;const{matrix:a}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,o.UniverInstanceType.UNIVER_SHEET),c=(p=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:p.getCellRaw(r,s),l=((f=(g=c==null?void 0:c.v)!=null?g:(y=(m=c==null?void 0:c.p)==null?void 0:m.body)==null?void 0:y.dataStream.slice(0,-2))!=null?f:"").toString(),u=a.getValue(r,s);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:r}=this._ensureMap(e,n),s=[];return r.forValue((a,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(r=>{const s=this.getSubUnit(e,r);return{unitId:e,subUnitId:r,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))}};exports.HyperLinkModel=Ce([ke(0,o.IUniverInstanceService)],exports.HyperLinkModel);var U=(i=>(i.SHEET="gid",i.RANGE="range",i.DEFINE_NAME="rangeid",i.INVALID="invalid",i.URL="url",i))(U||{});const Ue="sheets-hyper-link.config",oe={},L={type:o.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,link:s}=t;return e.addHyperLink(n,r,s)}},w={type:o.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,id:s}=t;return e.removeHyperLink(n,r,s)}},F={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,payload:s,id:a}=t;return e.updateHyperLink(n,r,a,s,!1)}},K={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,id:s,row:a,column:d,silent:c}=t;return e.updateHyperLinkRef(n,r,s,{row:a,column:d},c)}},B={type:o.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(i,t){var y,g,f;if(!t)return!1;const{unitId:e,subUnitId:n,row:r,col:s,id:a,url:d}=t,c=i.get(o.IUniverInstanceService),l=h.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:u}=l,p=u.getCellRaw(r,s),m=(f=(g=(y=p==null?void 0:p.p)==null?void 0:y.body)==null?void 0:g.customRanges)==null?void 0:f.find(_=>_.rangeType===o.CustomRangeType.HYPERLINK&&_.rangeId===a);return m&&(m.properties.url=d),!0}},le="SHEET_HYPER_LINK_PLUGIN",x="err";var Le=Object.getOwnPropertyDescriptor,we=(i,t,e,n)=>{for(var r=n>1?void 0:n?Le(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},j=(i,t)=>(e,n)=>t(e,n,i);let z=class extends o.Disposable{constructor(t,e,n,r){super();C(this,"_disposableMap",new Map);C(this,"_watchDisposableMap",new Map);C(this,"_rangeDisableMap",new Map);C(this,"_rangeWatcherMap",new Map);C(this,"_handlePositionChange",(t,e,n,r,s)=>{const a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return r?{redos:[{id:K.id,params:{unitId:t,subUnitId:e,id:n.id,row:r.startRow,column:r.startColumn,silent:s}}],undos:[{id:K.id,params:{unitId:t,subUnitId:e,id:n.id,row:a.startRow,column:a.startColumn,silent:s}}]}:{redos:[{id:w.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:L.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=r,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const r=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},a=d=>{const c=h.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(r,this._refRangeService.registerRefRange(s,a,t,e))}_watchPosition(t,e,n){const r=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(r,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,r=!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,p=k.deserializeRangeWithSheet(l.range).range;if(o.isValidRange(p)&&l.range!==x){const m=y=>{const g=h.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(p,y,{selectionManagerService:this._selectionManagerService});return g&&k.serializeRange(g)===k.serializeRange(p)?{redos:[],undos:[]}:{redos:[{id:F.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:`#gid=${u}&range=${g?k.serializeRange(g):"err"}`}}}],undos:[{id:F.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(p,m,t,u)),r||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,u,p,(y,g)=>{this._hyperLinkModel.updateHyperLink(t,u,e,{payload:`#gid=${u}&range=${g?k.serializeRange(g):"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:r,subUnitId:s,links:a}=n;a.forEach(d=>{this._registerPosition(r,s,d),this._watchPosition(r,s,d),this._registerRange(r,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:r,silent:s}=t,a=this._hyperLinkModel.getHyperLink(e,n,r);if(!a)return;this._unregisterPosition(r),this._registerPosition(e,n,a),s||(this._unwatchPosition(r),this._watchPosition(e,n,a));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:r}=n;r.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()}))}};z=we([j(0,o.Inject(h.RefRangeService)),j(1,o.Inject(exports.HyperLinkModel)),j(2,o.Inject(h.SheetsSelectionsService)),j(3,o.ICommandService)],z);var Ee=Object.getOwnPropertyDescriptor,be=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ee(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},te=(i,t)=>(e,n)=>t(e,n,i);let G=class extends o.Disposable{constructor(i,t,e){super(),this._sheetInterceptorService=i,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{var t;if(i.id===h.RemoveSheetCommand.id){const e=i.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const r=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const a=this._hyperLinkModel.getSubUnit(r,s),d=a.map(l=>({id:w.id,params:{unitId:r,subUnitId:s,id:l.id}})),c=a.map(l=>({id:L.id,params:{unitId:r,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};G=be([te(0,o.Inject(h.SheetInterceptorService)),te(1,o.IUniverInstanceService),te(2,o.Inject(exports.HyperLinkModel))],G);var Te=Object.getOwnPropertyDescriptor,He=(i,t,e,n)=>{for(var r=n>1?void 0:n?Te(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},ne=(i,t)=>(e,n)=>t(e,n,i);let Y=class extends o.Disposable{constructor(t,e,n){super();C(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 r=n.get(e);return r||(r=new o.ObjectMatrix,n.set(e,r)),r}_isLegalRangeUrl(t,e){var r,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:(r=d.get("gid"))!=null?r:"",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 p=k.deserializeRangeWithSheet(c.range).range;if(o.isValidRange(p,u)&&c.range!==x)return{range:p,worksheet:u}}}return null}_registerRange(t,e,n,r,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(p=>{var m;return p.rangeType===o.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(m=p.properties)==null?void 0:m.url)})){const p=new o.DisposableCollection;let m=!1;(u=(l=s.body)==null?void 0:l.customRanges)==null||u.forEach(y=>{var g;if(y.rangeType===o.CustomRangeType.HYPERLINK){const f=(g=y.properties)==null?void 0:g.url,_=this._isLegalRangeUrl(t,f);if(_){const{range:S,worksheet:M}=_;m=!0,p.add(this._refRangeService.registerRefRange(S,v=>{const I=h.handleDefaultRangeChangeWithEffectRefCommands(S,v);return I&&o.Rectangle.equals(I,S)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:r,id:y.rangeId,url:`#gid=${e}&range=${I?k.serializeRange(I):x}`}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:r,id:y.rangeId,url:f}}],redos:[]}},M.getUnitId(),M.getSheetId()))}}}),m&&a.setValue(n,r,p)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(r=>{const s=r.getSheetId(),a=this._enusreMap(n,s);r.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(r=>{const s=r.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===h.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:r,cellValue:s}=e,a=this._enusreMap(n,r);s&&new o.ObjectMatrix(s).forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,r,d,c,l.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===B.id){const e=t.params,{unitId:n,subUnitId:r,row:s,col:a}=e,d=h.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:r}),l=this._enusreMap(n,r).getValue(s,a);if(l&&l.dispose(),d){const{worksheet:u}=d,p=u.getCellRaw(s,a);p&&p.p&&this._registerRange(n,r,s,a,p.p)}}}))}};Y=He([ne(0,o.ICommandService),ne(1,o.IUniverInstanceService),ne(2,o.Inject(h.RefRangeService))],Y);var Pe=Object.getOwnPropertyDescriptor,Ne=(i,t,e,n)=>{for(var r=n>1?void 0:n?Pe(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},W=(i,t)=>(e,n)=>t(e,n,i);let q=class extends o.Disposable{constructor(i,t,e,n){super(),this._sheetInterceptorService=i,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:i=>{if(i.id===h.SetRangeValuesCommand.id){const t=i.params,{unitId:e,subUnitId:n}=t,r=[],s=[];return t.cellValue&&new o.ObjectMatrix(t.cellValue).forValue((a,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,a,d);c&&(r.push({id:w.id,params:{unitId:e,subUnitId:n,id:c.id}}),s.push({id:L.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:s,redos:r}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(i.id===h.ClearSelectionContentCommand.id||i.id===h.ClearSelectionAllCommand.id||i.id===h.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),r=h.getSheetCommandTarget(this._univerInstanceService);if(n&&r){const{unitId:s,subUnitId:a}=r;o.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(s,a,d,c);l&&(t.push({id:w.id,params:{unitId:s,subUnitId:a,id:l.id}}),e.push({id:L.id,params:{unitId:s,subUnitId:a,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(h.AFTER_CELL_EDIT,{handler:(i,t,e)=>{if(!i||i.p)return e(i);if(typeof i.v=="string"&&o.Tools.isLegalUrl(i.v)&&i.v[i.v.length-1]!==" "){const{unitId:n,subUnitId:r}=t,s=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET),a=s==null?void 0:s.getSheetBySheetId(r);if(!a)return e(i);const d=a.getBlankCellDocumentModel(i);if(!d.documentModel)return e(i);const c=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:i.v.length,collapsed:!1},body:{dataStream:`${i.v}`,customRanges:[{startIndex:0,endIndex:i.v.length-1,rangeId:o.generateRandomId(),rangeType:o.CustomRangeType.HYPERLINK,properties:{url:i.v}}]},doc:d.documentModel});if(!c)return e(i);const l=d.documentModel.getBody();return o.TextX.apply(l,c.serialize()),e({...i,p:{id:o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:l,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(i)}}))}};q=Ne([W(0,o.Inject(h.SheetInterceptorService)),W(1,o.Inject(exports.HyperLinkModel)),W(2,o.Inject(h.SheetsSelectionsService)),W(3,o.IUniverInstanceService)],q);var ue=(i=>(i[i.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",i[i.UNIVER_DOC=1]="UNIVER_DOC",i[i.UNIVER_SHEET=2]="UNIVER_SHEET",i[i.UNIVER_SLIDE=3]="UNIVER_SLIDE",i[i.UNIVER_PROJECT=4]="UNIVER_PROJECT",i[i.UNRECOGNIZED=-1]="UNRECOGNIZED",i))(ue||{}),De=Object.getOwnPropertyDescriptor,Oe=(i,t,e,n)=>{for(var r=n>1?void 0:n?De(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},de=(i,t)=>(e,n)=>t(e,n,i);let J=class extends o.Disposable{constructor(i,t){super(),this._resourceManagerService=i,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const i=e=>{const n=this._hyperLinkModel.getUnit(e),r={};return n?(n.forEach(s=>{r[s.subUnitId]=s.links.map(({display:a,...d})=>d)}),JSON.stringify(r)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:le,businesses:[ue.UNIVER_SHEET],toJson:e=>i(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(r=>{n[r].forEach(a=>{this._hyperLinkModel.addHyperLink(e,r,a)})})}}))}};J=Oe([de(0,o.IResourceManagerService),de(1,o.Inject(exports.HyperLinkModel))],J);const pe={type:o.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(i,t){if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=i.get(h.SheetInterceptorService),d=h.getSheetCommandTarget(r,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:u,worksheet:p}=d,{link:m}=t,{payload:y,display:g,row:f,column:_,id:S}=m,M=p.getCell(f,_),v=p.getBlankCellDocumentModel(M),I=v.documentModel.getSnapshot(),R=o.Tools.deepClone(I.body);if(!R)return!1;let E;if(g?E=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:R.dataStream.length-2,collapsed:R.dataStream.length-2===0},body:{dataStream:`${g}`,customRanges:[{startIndex:0,endIndex:g.length-1,rangeType:o.CustomRangeType.HYPERLINK,rangeId:S,properties:{url:y}}]},doc:v.documentModel}):E=o.BuildTextUtils.customRange.add({body:R,ranges:[{startOffset:0,endOffset:R.dataStream.length-2,collapsed:!1}],rangeId:S,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:y,refId:S}}),!E)return!1;const O=o.TextX.apply(R,E.serialize()),b={p:{...I,body:O},t:o.CellValueType.STRING},H=await a.onWriteCell(u,p,f,_,b),P={unitId:c,subUnitId:l,cellValue:{[m.row]:{[m.column]:H}}},Q={id:h.SetRangeValuesMutation.id,params:P},$=h.SetRangeValuesUndoMutationFactory(i,P),ee={id:h.SetRangeValuesMutation.id,params:$},V=[Q],N=[ee],D=s.getHyperLinkByLocation(c,l,f,_);return D&&(V.push({id:w.id,params:{unitId:c,subUnitId:l,id:D.id}}),N.push({id:L.id,params:{unitId:c,subUnitId:l,link:D}})),await o.sequenceExecuteAsync(V,e)?(n.pushUndoRedo({redoMutations:V,undoMutations:N,unitID:c}),!0):!1}},ge={id:"sheets.command.add-rich-hyper-link",type:o.CommandType.COMMAND,handler:async(i,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,r=i.get(o.ICommandService),s=o.generateRandomId(),{payload:a}=n,d=Z.addCustomRangeBySelectionFactory(i,{unitId:e,rangeId:s,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:a,refId:s}});return d?r.syncExecuteCommand(d.id,d.params):!1}},he={type:o.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(i,t){var b,H;if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=h.getSheetCommandTarget(r,t);if(!a)return!1;const{row:d,column:c,id:l}=t,{unitId:u,subUnitId:p,worksheet:m}=a,y=m.getCell(d,c);if(!y)return!1;const g=m.getCellDocumentModelWithFormula(y);if(!(g!=null&&g.documentModel))return!1;const f=o.Tools.deepClone(g.documentModel.getSnapshot()),_=(H=(b=f.body)==null?void 0:b.customRanges)==null?void 0:H.find(P=>`${P.rangeId}`===l);if(!_)return!1;const S=o.BuildTextUtils.customRange.delete({documentDataModel:g.documentModel,rangeId:_.rangeId});if(!S)return!1;const M=o.TextX.apply(f.body,S.serialize()),v=[],I=[],R={unitId:u,subUnitId:p,cellValue:{[d]:{[c]:{p:{...f,body:M},t:o.CellValueType.STRING}}}};v.push({id:h.SetRangeValuesMutation.id,params:R});const E=h.SetRangeValuesUndoMutationFactory(i,R);I.push({id:h.SetRangeValuesMutation.id,params:E});const O=s.getHyperLinkByLocation(u,p,d,c);return O&&(v.push({id:w.id,params:{unitId:u,subUnitId:p,id:l}}),I.push({id:L.id,params:{unitId:u,subUnitId:p,link:{...O}}})),o.sequenceExecute(v,e).result?(n.pushUndoRedo({redoMutations:v,undoMutations:I,unitID:u}),!0):!1}},me={type:o.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(i,t){var u,p;if(!t)return!1;const{id:e,documentId:n}=t,r=i.get(o.ICommandService),a=i.get(o.IUniverInstanceService).getUnit(n,o.UniverInstanceType.UNIVER_DOC),d=(p=(u=a==null?void 0:a.getBody())==null?void 0:u.customRanges)==null?void 0:p.find(m=>m.rangeId===e);let c=null;d&&d.endIndex===a.getBody().dataStream.length-3&&(c={dataStream:" "});const l=Z.deleteCustomRangeFactory(i,{unitId:n,rangeId:e,insert:c});return l?r.syncExecuteCommand(l.id,l.params):!1}},ye={type:o.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(i,t){var ie,se,ae;if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=i.get(h.SheetInterceptorService),d=h.getSheetCommandTarget(r,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:u,id:p}=t,{workbook:m,worksheet:y,unitId:g,subUnitId:f}=d,{payload:_,display:S=""}=c,M=y.getCell(l,u);if(!M)return!1;const v=y.getCellDocumentModelWithFormula(M);if(!(v!=null&&v.documentModel))return!1;const I=v.documentModel.getSnapshot(),R=(se=(ie=I.body)==null?void 0:ie.customRanges)==null?void 0:se.find(Se=>`${Se.rangeId}`===p);if(!R)return!1;const E=o.generateRandomId(),T=(ae=o.getBodySlice(v.documentModel.getBody(),R.startIndex,R.endIndex+1).textRuns)==null?void 0:ae[0];T&&(T.ed=S.length+1);const b=Z.replaceSelectionFactory(i,{unitId:g,body:{dataStream:`${S}`,customRanges:[{rangeId:E,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:S.length-1,properties:{url:_}}],textRuns:T?[T]:void 0},selection:{startOffset:R.startIndex,endOffset:R.endIndex+1,collapsed:!1},doc:v.documentModel});if(!b)return!1;const H=o.TextX.apply(o.Tools.deepClone(I.body),b.textX.serialize()),P={p:{...I,body:H},t:o.CellValueType.STRING},Q=await a.onWriteCell(m,y,l,u,P),$={id:h.SetRangeValuesMutation.id,params:{unitId:g,subUnitId:f,cellValue:{[l]:{[u]:Q}}}},ee=h.SetRangeValuesUndoMutationFactory(i,$.params),V={id:h.SetRangeValuesMutation.id,params:ee},N=[$],D=[V],A=s.getHyperLinkByLocation(g,f,l,u);return A&&(N.push({id:w.id,params:{unitId:g,subUnitId:f,id:A.id}}),D.push({id:L.id,params:{unitId:g,subUnitId:f,link:A}})),await o.sequenceExecuteAsync(N,e)?(n.pushUndoRedo({redoMutations:N,undoMutations:D,unitID:g}),!0):!1}},fe={type:o.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(i,t)=>{var g,f,_,S;if(!t)return!1;const{documentId:e,payload:n,id:r}=t,s=i.get(o.IUniverInstanceService),a=i.get(o.ICommandService),d=s.getUnit(e,o.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(f=(g=d.getBody())==null?void 0:g.customRanges)==null?void 0:f.find(M=>M.rangeId===r);if(!c)return!1;const l=(_=t.payload.display)!=null?_:"",u=o.generateRandomId(),m=(S=o.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:S[0];m&&(m.ed=l.length+1);const y=Z.replaceSelectionFactory(i,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:u,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:m?[m]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return y?a.syncExecuteCommand(y.id,y.params):!1}};var Ve=Object.getOwnPropertyDescriptor,xe=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ve(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},$e=(i,t)=>(e,n)=>t(e,n,i);let X=class extends o.Disposable{constructor(i){super(),this._commandService=i,this._registerCommands()}_registerCommands(){[pe,ye,he,fe,me,ge,L,F,w,K,B].forEach(i=>{this._commandService.registerCommand(i)})}};X=xe([$e(0,o.ICommandService)],X);var Ae=Object.getOwnPropertyDescriptor,je=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ae(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},re=(i,t)=>(e,n)=>t(e,n,i);exports.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${U.SHEET}=${e}${n?`&${typeof n=="string"?U.DEFINE_NAME:U.RANGE}=${typeof n=="string"?n:k.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,r,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:(r=a.get("rangeid"))!=null?r:"",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:U.URL,name:t,url:t,searchObj:null}}_getURLName(t){var u;const{gid:e,range:n,rangeid:r,unitid:s}=t,a=s?this._univerInstanceService.getUnit(s,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),d={type:U.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 p=k.deserializeRangeWithSheet(n).range;return o.isValidRange(p,c)&&n!==x?{type:U.RANGE,name:k.serializeRangeWithSheet(l,p)}:d}if(r){const p=this._definedNamesService.getValueById(a.getUnitId(),r);return p?{type:U.DEFINE_NAME,name:p.formulaOrRefString}:d}if(e){const p=a.getSheetBySheetId(e);return p?{type:U.SHEET,name:p.getName()}:d}return d}};exports.SheetsHyperLinkParserService=je([re(0,o.IUniverInstanceService),re(1,o.Inject(o.LocaleService)),re(2,k.IDefinedNamesService)],exports.SheetsHyperLinkParserService);var We=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,Fe=(i,t,e)=>t in i?We(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,Ke=(i,t,e,n)=>{for(var r=n>1?void 0:n?Be(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},ce=(i,t)=>(e,n)=>t(e,n,i),_e=(i,t,e)=>Fe(i,typeof t!="symbol"?t+"":t,e);exports.UniverSheetsHyperLinkPlugin=class extends o.Plugin{constructor(t=oe,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...r}=o.merge({},oe,this._config);this._configService.setConfig(Ue,r)}onStarting(){o.registerDependencies(this._injector,[[exports.HyperLinkModel],[exports.SheetsHyperLinkParserService],[J],[X],[z],[q],[G],[Y]]),o.touchDependencies(this._injector,[[z],[J],[X],[q],[G],[Y]])}};_e(exports.UniverSheetsHyperLinkPlugin,"pluginName",le);_e(exports.UniverSheetsHyperLinkPlugin,"type",o.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsHyperLinkPlugin=Ke([o.DependentOn(h.UniverSheetsPlugin),ce(1,o.Inject(o.Injector)),ce(2,o.IConfigService)],exports.UniverSheetsHyperLinkPlugin);exports.AddHyperLinkCommand=pe;exports.AddHyperLinkMutation=L;exports.AddRichHyperLinkCommand=ge;exports.CancelHyperLinkCommand=he;exports.CancelRichHyperLinkCommand=me;exports.ERROR_RANGE=x;exports.RemoveHyperLinkMutation=w;exports.SheetHyperLinkType=U;exports.UpdateHyperLinkCommand=ye;exports.UpdateHyperLinkMutation=F;exports.UpdateHyperLinkRefMutation=K;exports.UpdateRichHyperLinkCommand=fe;
1
+ "use strict";var Ie=Object.defineProperty;var Re=(i,t,e)=>t in i?Ie(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var C=(i,t,e)=>Re(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),Me=require("rxjs"),h=require("@univerjs/sheets"),k=require("@univerjs/engine-formula"),Z=require("@univerjs/docs");var Ce=Object.getOwnPropertyDescriptor,ke=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ce(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},Ue=(i,t)=>(e,n)=>t(e,n,i);exports.HyperLinkModel=class extends o.Disposable{constructor(e){super();C(this,"_linkUpdate$",new Me.Subject);C(this,"linkUpdate$",this._linkUpdate$.asObservable());C(this,"_linkMap",new Map);C(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let r=this._linkMap.get(e);r||(r=new Map,this._linkMap.set(e,r));let s=r.get(n);s||(s=new o.ObjectMatrix,r.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,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n);return s.setValue(r.row,r.column,r),a.set(r.id,{row:r.row,column:r.column,link:r}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:r,type:"add"}),!0}updateHyperLink(e,n,r,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(r);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:r,type:"update",silent:a})),!0}updateHyperLinkRef(e,n,r,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(r);if(!l)return!0;let u=d.getValue(l.row,l.column);return!u||u.id!==r?u=l.link:d.realDeleteValue(l.row,l.column),Object.assign(u,s),c.set(r,{...s,link:u}),d.setValue(s.row,s.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:r,type:"updateRef",silent:a}),!0}removeHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(r);if(!d)return!1;a.delete(r);const c=s.getValue(d.row,d.column);return c&&c.id===r&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(r);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,r,s){const{matrix:a}=this._ensureMap(e,n);return a.getValue(r,s)}getHyperLinkByLocationSync(e,n,r,s){var p,m,f,g,y;const{matrix:a}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,o.UniverInstanceType.UNIVER_SHEET),c=(p=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:p.getCellRaw(r,s),l=((y=(g=c==null?void 0:c.v)!=null?g:(f=(m=c==null?void 0:c.p)==null?void 0:m.body)==null?void 0:f.dataStream.slice(0,-2))!=null?y:"").toString(),u=a.getValue(r,s);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:r}=this._ensureMap(e,n),s=[];return r.forValue((a,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(r=>{const s=this.getSubUnit(e,r);return{unitId:e,subUnitId:r,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))}};exports.HyperLinkModel=ke([Ue(0,o.IUniverInstanceService)],exports.HyperLinkModel);var U=(i=>(i.SHEET="gid",i.RANGE="range",i.DEFINE_NAME="rangeid",i.INVALID="invalid",i.URL="url",i))(U||{});const Le="sheets-hyper-link.config",de={},L={type:o.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,link:s}=t;return e.addHyperLink(n,r,s)}},E={type:o.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,id:s}=t;return e.removeHyperLink(n,r,s)}},F={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,payload:s,id:a}=t;return e.updateHyperLink(n,r,a,s,!1)}},K={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,id:s,row:a,column:d,silent:c}=t;return e.updateHyperLinkRef(n,r,s,{row:a,column:d},c)}},B={type:o.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(i,t){var f,g,y;if(!t)return!1;const{unitId:e,subUnitId:n,row:r,col:s,id:a,url:d}=t,c=i.get(o.IUniverInstanceService),l=h.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:u}=l,p=u.getCellRaw(r,s),m=(y=(g=(f=p==null?void 0:p.p)==null?void 0:f.body)==null?void 0:g.customRanges)==null?void 0:y.find(_=>_.rangeType===o.CustomRangeType.HYPERLINK&&_.rangeId===a);return m&&(m.properties.url=d),!0}},ue="SHEET_HYPER_LINK_PLUGIN",x="err";var Ee=Object.getOwnPropertyDescriptor,we=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ee(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},j=(i,t)=>(e,n)=>t(e,n,i);let z=class extends o.Disposable{constructor(t,e,n,r){super();C(this,"_disposableMap",new Map);C(this,"_watchDisposableMap",new Map);C(this,"_rangeDisableMap",new Map);C(this,"_rangeWatcherMap",new Map);C(this,"_handlePositionChange",(t,e,n,r,s)=>{const a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return r?{redos:[{id:K.id,params:{unitId:t,subUnitId:e,id:n.id,row:r.startRow,column:r.startColumn,silent:s}}],undos:[{id:K.id,params:{unitId:t,subUnitId:e,id:n.id,row:a.startRow,column:a.startColumn,silent:s}}]}:{redos:[{id:E.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:L.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=r,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const r=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},a=d=>{const c=h.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(r,this._refRangeService.registerRefRange(s,a,t,e))}_watchPosition(t,e,n){const r=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(r,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,r=!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,p=k.deserializeRangeWithSheet(l.range).range;if(o.isValidRange(p)&&l.range!==x){const m=f=>{const g=h.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(p,f,{selectionManagerService:this._selectionManagerService});return g&&k.serializeRange(g)===k.serializeRange(p)?{redos:[],undos:[]}:{redos:[{id:F.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:`#gid=${u}&range=${g?k.serializeRange(g):"err"}`}}}],undos:[{id:F.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(p,m,t,u)),r||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,u,p,(f,g)=>{this._hyperLinkModel.updateHyperLink(t,u,e,{payload:`#gid=${u}&range=${g?k.serializeRange(g):"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:r,subUnitId:s,links:a}=n;a.forEach(d=>{this._registerPosition(r,s,d),this._watchPosition(r,s,d),this._registerRange(r,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:r,silent:s}=t,a=this._hyperLinkModel.getHyperLink(e,n,r);if(!a)return;this._unregisterPosition(r),this._registerPosition(e,n,a),s||(this._unwatchPosition(r),this._watchPosition(e,n,a));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:r}=n;r.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()}))}};z=we([j(0,o.Inject(h.RefRangeService)),j(1,o.Inject(exports.HyperLinkModel)),j(2,o.Inject(h.SheetsSelectionsService)),j(3,o.ICommandService)],z);var be=Object.getOwnPropertyDescriptor,Te=(i,t,e,n)=>{for(var r=n>1?void 0:n?be(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},te=(i,t)=>(e,n)=>t(e,n,i);let G=class extends o.Disposable{constructor(i,t,e){super(),this._sheetInterceptorService=i,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{var t;if(i.id===h.RemoveSheetCommand.id){const e=i.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const r=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const a=this._hyperLinkModel.getSubUnit(r,s),d=a.map(l=>({id:E.id,params:{unitId:r,subUnitId:s,id:l.id}})),c=a.map(l=>({id:L.id,params:{unitId:r,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};G=Te([te(0,o.Inject(h.SheetInterceptorService)),te(1,o.IUniverInstanceService),te(2,o.Inject(exports.HyperLinkModel))],G);var He=Object.getOwnPropertyDescriptor,Pe=(i,t,e,n)=>{for(var r=n>1?void 0:n?He(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},ne=(i,t)=>(e,n)=>t(e,n,i);let Y=class extends o.Disposable{constructor(t,e,n){super();C(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 r=n.get(e);return r||(r=new o.ObjectMatrix,n.set(e,r)),r}_isLegalRangeUrl(t,e){var r,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:(r=d.get("gid"))!=null?r:"",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 p=k.deserializeRangeWithSheet(c.range).range;if(o.isValidRange(p,u)&&c.range!==x)return{range:p,worksheet:u}}}return null}_registerRange(t,e,n,r,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(p=>{var m;return p.rangeType===o.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(m=p.properties)==null?void 0:m.url)})){const p=new o.DisposableCollection;let m=!1;(u=(l=s.body)==null?void 0:l.customRanges)==null||u.forEach(f=>{var g;if(f.rangeType===o.CustomRangeType.HYPERLINK){const y=(g=f.properties)==null?void 0:g.url,_=this._isLegalRangeUrl(t,y);if(_){const{range:S,worksheet:M}=_;m=!0,p.add(this._refRangeService.registerRefRange(S,v=>{const I=h.handleDefaultRangeChangeWithEffectRefCommands(S,v);return I&&o.Rectangle.equals(I,S)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:r,id:f.rangeId,url:`#gid=${e}&range=${I?k.serializeRange(I):x}`}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:r,id:f.rangeId,url:y}}],redos:[]}},M.getUnitId(),M.getSheetId()))}}}),m&&a.setValue(n,r,p)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(r=>{const s=r.getSheetId(),a=this._enusreMap(n,s);r.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(r=>{const s=r.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===h.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:r,cellValue:s}=e,a=this._enusreMap(n,r);s&&new o.ObjectMatrix(s).forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,r,d,c,l.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===B.id){const e=t.params,{unitId:n,subUnitId:r,row:s,col:a}=e,d=h.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:r}),l=this._enusreMap(n,r).getValue(s,a);if(l&&l.dispose(),d){const{worksheet:u}=d,p=u.getCellRaw(s,a);p&&p.p&&this._registerRange(n,r,s,a,p.p)}}}))}};Y=Pe([ne(0,o.ICommandService),ne(1,o.IUniverInstanceService),ne(2,o.Inject(h.RefRangeService))],Y);var Ne=Object.getOwnPropertyDescriptor,De=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ne(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},W=(i,t)=>(e,n)=>t(e,n,i);let q=class extends o.Disposable{constructor(i,t,e,n){super(),this._sheetInterceptorService=i,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:i=>{if(i.id===h.SetRangeValuesCommand.id){const t=i.params,{unitId:e,subUnitId:n}=t,r=[],s=[];return t.cellValue&&new o.ObjectMatrix(t.cellValue).forValue((a,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,a,d);c&&(r.push({id:E.id,params:{unitId:e,subUnitId:n,id:c.id}}),s.push({id:L.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:s,redos:r}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(i.id===h.ClearSelectionContentCommand.id||i.id===h.ClearSelectionAllCommand.id||i.id===h.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),r=h.getSheetCommandTarget(this._univerInstanceService);if(n&&r){const{unitId:s,subUnitId:a}=r;o.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(s,a,d,c);l&&(t.push({id:E.id,params:{unitId:s,subUnitId:a,id:l.id}}),e.push({id:L.id,params:{unitId:s,subUnitId:a,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(h.AFTER_CELL_EDIT,{handler:(i,t,e)=>{if(!i||i.p)return e(i);if(typeof i.v=="string"&&o.Tools.isLegalUrl(i.v)&&i.v[i.v.length-1]!==" "){const{unitId:n,subUnitId:r}=t,s=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET),a=s==null?void 0:s.getSheetBySheetId(r);if(!a)return e(i);const d=a.getBlankCellDocumentModel(i);if(!d.documentModel)return e(i);const c=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:i.v.length,collapsed:!1},body:{dataStream:`${i.v}`,customRanges:[{startIndex:0,endIndex:i.v.length-1,rangeId:o.generateRandomId(),rangeType:o.CustomRangeType.HYPERLINK,properties:{url:i.v}}]},doc:d.documentModel});if(!c)return e(i);const l=d.documentModel.getBody();return o.TextX.apply(l,c.serialize()),e({...i,p:{id:o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:l,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(i)}}))}};q=De([W(0,o.Inject(h.SheetInterceptorService)),W(1,o.Inject(exports.HyperLinkModel)),W(2,o.Inject(h.SheetsSelectionsService)),W(3,o.IUniverInstanceService)],q);var pe=(i=>(i[i.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",i[i.UNIVER_DOC=1]="UNIVER_DOC",i[i.UNIVER_SHEET=2]="UNIVER_SHEET",i[i.UNIVER_SLIDE=3]="UNIVER_SLIDE",i[i.UNIVER_PROJECT=4]="UNIVER_PROJECT",i[i.UNRECOGNIZED=-1]="UNRECOGNIZED",i))(pe||{}),Oe=Object.getOwnPropertyDescriptor,Ve=(i,t,e,n)=>{for(var r=n>1?void 0:n?Oe(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},ce=(i,t)=>(e,n)=>t(e,n,i);let J=class extends o.Disposable{constructor(i,t){super(),this._resourceManagerService=i,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const i=e=>{const n=this._hyperLinkModel.getUnit(e),r={};return n?(n.forEach(s=>{r[s.subUnitId]=s.links.map(({display:a,...d})=>d)}),JSON.stringify(r)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:ue,businesses:[pe.UNIVER_SHEET],toJson:e=>i(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(r=>{n[r].forEach(a=>{this._hyperLinkModel.addHyperLink(e,r,a)})})}}))}};J=Ve([ce(0,o.IResourceManagerService),ce(1,o.Inject(exports.HyperLinkModel))],J);const ge={type:o.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(i,t){if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=i.get(h.SheetInterceptorService),d=h.getSheetCommandTarget(r,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:u,worksheet:p}=d,{link:m}=t,{payload:f,display:g,row:y,column:_,id:S}=m,M=p.getCell(y,_),v=p.getBlankCellDocumentModel(M),I=v.documentModel.getSnapshot(),R=o.Tools.deepClone(I.body);if(!R)return!1;let w;if(g?w=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:R.dataStream.length-2,collapsed:R.dataStream.length-2===0},body:{dataStream:`${g}`,customRanges:[{startIndex:0,endIndex:g.length-1,rangeType:o.CustomRangeType.HYPERLINK,rangeId:S,properties:{url:f}}]},doc:v.documentModel}):w=o.BuildTextUtils.customRange.add({body:R,ranges:[{startOffset:0,endOffset:R.dataStream.length-2,collapsed:!1}],rangeId:S,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:f,refId:S}}),!w)return!1;const O=o.TextX.apply(R,w.serialize()),b={p:{...I,body:O},t:o.CellValueType.STRING},N=a.onWriteCell(u,p,y,_,b),D={unitId:c,subUnitId:l,cellValue:{[m.row]:{[m.column]:N}}},Q={id:h.SetRangeValuesMutation.id,params:D},$=h.SetRangeValuesUndoMutationFactory(i,D),ee={id:h.SetRangeValuesMutation.id,params:$},V=[Q],T=[ee],H=s.getHyperLinkByLocation(c,l,y,_);return H&&(V.push({id:E.id,params:{unitId:c,subUnitId:l,id:H.id}}),T.push({id:L.id,params:{unitId:c,subUnitId:l,link:H}})),await o.sequenceExecute(V,e)?await a.onValidateCell(u,p,y,_)===!1?(o.sequenceExecute(T,e),!1):(n.pushUndoRedo({redoMutations:V,undoMutations:T,unitID:c}),!0):!1}},he={id:"sheets.command.add-rich-hyper-link",type:o.CommandType.COMMAND,handler:async(i,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,r=i.get(o.ICommandService),s=o.generateRandomId(),{payload:a}=n,d=Z.addCustomRangeBySelectionFactory(i,{unitId:e,rangeId:s,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:a,refId:s}});return d?r.syncExecuteCommand(d.id,d.params):!1}},me={type:o.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(i,t){var b,N;if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=h.getSheetCommandTarget(r,t);if(!a)return!1;const{row:d,column:c,id:l}=t,{unitId:u,subUnitId:p,worksheet:m}=a,f=m.getCell(d,c);if(!f)return!1;const g=m.getCellDocumentModelWithFormula(f);if(!(g!=null&&g.documentModel))return!1;const y=o.Tools.deepClone(g.documentModel.getSnapshot()),_=(N=(b=y.body)==null?void 0:b.customRanges)==null?void 0:N.find(D=>`${D.rangeId}`===l);if(!_)return!1;const S=o.BuildTextUtils.customRange.delete({documentDataModel:g.documentModel,rangeId:_.rangeId});if(!S)return!1;const M=o.TextX.apply(y.body,S.serialize()),v=[],I=[],R={unitId:u,subUnitId:p,cellValue:{[d]:{[c]:{p:{...y,body:M},t:o.CellValueType.STRING}}}};v.push({id:h.SetRangeValuesMutation.id,params:R});const w=h.SetRangeValuesUndoMutationFactory(i,R);I.push({id:h.SetRangeValuesMutation.id,params:w});const O=s.getHyperLinkByLocation(u,p,d,c);return O&&(v.push({id:E.id,params:{unitId:u,subUnitId:p,id:l}}),I.push({id:L.id,params:{unitId:u,subUnitId:p,link:{...O}}})),o.sequenceExecute(v,e).result?(n.pushUndoRedo({redoMutations:v,undoMutations:I,unitID:u}),!0):!1}},fe={type:o.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(i,t){var u,p;if(!t)return!1;const{id:e,documentId:n}=t,r=i.get(o.ICommandService),a=i.get(o.IUniverInstanceService).getUnit(n,o.UniverInstanceType.UNIVER_DOC),d=(p=(u=a==null?void 0:a.getBody())==null?void 0:u.customRanges)==null?void 0:p.find(m=>m.rangeId===e);let c=null;d&&d.endIndex===a.getBody().dataStream.length-3&&(c={dataStream:" "});const l=Z.deleteCustomRangeFactory(i,{unitId:n,rangeId:e,insert:c});return l?r.syncExecuteCommand(l.id,l.params):!1}},ye={type:o.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(i,t){var ie,se,ae;if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=i.get(h.SheetInterceptorService),d=h.getSheetCommandTarget(r,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:u,id:p}=t,{workbook:m,worksheet:f,unitId:g,subUnitId:y}=d,{payload:_,display:S=""}=c,M=f.getCell(l,u);if(!M)return!1;const v=f.getCellDocumentModelWithFormula(M);if(!(v!=null&&v.documentModel))return!1;const I=v.documentModel.getSnapshot(),R=(se=(ie=I.body)==null?void 0:ie.customRanges)==null?void 0:se.find(oe=>`${oe.rangeId}`===p);if(!R)return!1;const w=o.generateRandomId(),P=(ae=o.getBodySlice(v.documentModel.getBody(),R.startIndex,R.endIndex+1).textRuns)==null?void 0:ae[0];P&&(P.ed=S.length+1);const b=Z.replaceSelectionFactory(i,{unitId:g,body:{dataStream:`${S}`,customRanges:[{rangeId:w,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:S.length-1,properties:{url:_}}],textRuns:P?[P]:void 0},selection:{startOffset:R.startIndex,endOffset:R.endIndex+1,collapsed:!1},doc:v.documentModel});if(!b)return!1;const N=o.TextX.apply(o.Tools.deepClone(I.body),b.textX.serialize()),D={p:{...I,body:N},t:o.CellValueType.STRING},Q=a.onWriteCell(m,f,l,u,D),$={id:h.SetRangeValuesMutation.id,params:{unitId:g,subUnitId:y,cellValue:{[l]:{[u]:Q}}}},ee=h.SetRangeValuesUndoMutationFactory(i,$.params),V={id:h.SetRangeValuesMutation.id,params:ee},T=[$],H=[V],A=s.getHyperLinkByLocation(g,y,l,u);return A&&(T.push({id:E.id,params:{unitId:g,subUnitId:y,id:A.id}}),H.push({id:L.id,params:{unitId:g,subUnitId:y,link:A}})),o.sequenceExecute(T,e)?await a.onValidateCell(m,f,l,u)===!1?(o.sequenceExecute(H,e),!1):(n.pushUndoRedo({redoMutations:T,undoMutations:H,unitID:g}),!0):!1}},_e={type:o.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(i,t)=>{var g,y,_,S;if(!t)return!1;const{documentId:e,payload:n,id:r}=t,s=i.get(o.IUniverInstanceService),a=i.get(o.ICommandService),d=s.getUnit(e,o.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(y=(g=d.getBody())==null?void 0:g.customRanges)==null?void 0:y.find(M=>M.rangeId===r);if(!c)return!1;const l=(_=t.payload.display)!=null?_:"",u=o.generateRandomId(),m=(S=o.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:S[0];m&&(m.ed=l.length+1);const f=Z.replaceSelectionFactory(i,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:u,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:m?[m]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return f?a.syncExecuteCommand(f.id,f.params):!1}};var xe=Object.getOwnPropertyDescriptor,$e=(i,t,e,n)=>{for(var r=n>1?void 0:n?xe(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},Ae=(i,t)=>(e,n)=>t(e,n,i);let X=class extends o.Disposable{constructor(i){super(),this._commandService=i,this._registerCommands()}_registerCommands(){[ge,ye,me,_e,fe,he,L,F,E,K,B].forEach(i=>{this._commandService.registerCommand(i)})}};X=$e([Ae(0,o.ICommandService)],X);var je=Object.getOwnPropertyDescriptor,We=(i,t,e,n)=>{for(var r=n>1?void 0:n?je(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},re=(i,t)=>(e,n)=>t(e,n,i);exports.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${U.SHEET}=${e}${n?`&${typeof n=="string"?U.DEFINE_NAME:U.RANGE}=${typeof n=="string"?n:k.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,r,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:(r=a.get("rangeid"))!=null?r:"",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:U.URL,name:t,url:t,searchObj:null}}_getURLName(t){var u;const{gid:e,range:n,rangeid:r,unitid:s}=t,a=s?this._univerInstanceService.getUnit(s,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),d={type:U.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 p=k.deserializeRangeWithSheet(n).range;return o.isValidRange(p,c)&&n!==x?{type:U.RANGE,name:k.serializeRangeWithSheet(l,p)}:d}if(r){const p=this._definedNamesService.getValueById(a.getUnitId(),r);return p?{type:U.DEFINE_NAME,name:p.formulaOrRefString}:d}if(e){const p=a.getSheetBySheetId(e);return p?{type:U.SHEET,name:p.getName()}:d}return d}};exports.SheetsHyperLinkParserService=We([re(0,o.IUniverInstanceService),re(1,o.Inject(o.LocaleService)),re(2,k.IDefinedNamesService)],exports.SheetsHyperLinkParserService);var Be=Object.defineProperty,Fe=Object.getOwnPropertyDescriptor,Ke=(i,t,e)=>t in i?Be(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,ze=(i,t,e,n)=>{for(var r=n>1?void 0:n?Fe(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},le=(i,t)=>(e,n)=>t(e,n,i),Se=(i,t,e)=>Ke(i,typeof t!="symbol"?t+"":t,e);exports.UniverSheetsHyperLinkPlugin=class extends o.Plugin{constructor(t=de,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...r}=o.merge({},de,this._config);this._configService.setConfig(Le,r)}onStarting(){o.registerDependencies(this._injector,[[exports.HyperLinkModel],[exports.SheetsHyperLinkParserService],[J],[X],[z],[q],[G],[Y]]),o.touchDependencies(this._injector,[[z],[J],[X],[q],[G],[Y]])}};Se(exports.UniverSheetsHyperLinkPlugin,"pluginName",ue);Se(exports.UniverSheetsHyperLinkPlugin,"type",o.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsHyperLinkPlugin=ze([o.DependentOn(h.UniverSheetsPlugin),le(1,o.Inject(o.Injector)),le(2,o.IConfigService)],exports.UniverSheetsHyperLinkPlugin);exports.AddHyperLinkCommand=ge;exports.AddHyperLinkMutation=L;exports.AddRichHyperLinkCommand=he;exports.CancelHyperLinkCommand=me;exports.CancelRichHyperLinkCommand=fe;exports.ERROR_RANGE=x;exports.RemoveHyperLinkMutation=E;exports.SheetHyperLinkType=U;exports.UpdateHyperLinkCommand=ye;exports.UpdateHyperLinkMutation=F;exports.UpdateHyperLinkRefMutation=K;exports.UpdateRichHyperLinkCommand=_e;
package/lib/es/index.js CHANGED
@@ -1,20 +1,20 @@
1
- var $e = Object.defineProperty;
2
- var Ae = (r, e, t) => e in r ? $e(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
- var w = (r, e, t) => Ae(r, typeof e != "symbol" ? e + "" : e, t);
4
- import { Disposable as V, ObjectMatrix as q, UniverInstanceType as I, IUniverInstanceService as k, CommandType as E, CustomRangeType as U, Inject as M, ICommandService as b, sequenceExecuteAsync as Re, isValidRange as Se, toDisposable as We, DisposableCollection as Be, Rectangle as je, Range as Fe, Tools as oe, BuildTextUtils as Z, generateRandomId as de, TextX as ce, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as Ke, IResourceManagerService as Ye, IUndoRedoService as ve, CellValueType as Ie, sequenceExecute as Ge, getBodySlice as Ne, LocaleService as ze, DependentOn as Je, Injector as Xe, IConfigService as qe, Plugin as Ze, merge as Qe, registerDependencies as et, touchDependencies as tt } from "@univerjs/core";
5
- import { Subject as nt } from "rxjs";
6
- import { getSheetCommandTarget as j, RefRangeService as Pe, SheetsSelectionsService as De, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as rt, handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests as st, SheetInterceptorService as le, RemoveSheetCommand as it, handleDefaultRangeChangeWithEffectRefCommands as at, SetRangeValuesMutation as H, SetRangeValuesCommand as ot, ClearSelectionContentCommand as dt, ClearSelectionAllCommand as ct, ClearSelectionFormatCommand as lt, AFTER_CELL_EDIT as ut, SetRangeValuesUndoMutationFactory as Me, UniverSheetsPlugin as pt } from "@univerjs/sheets";
7
- import { deserializeRangeWithSheet as Ce, serializeRange as B, IDefinedNamesService as ht, serializeRangeWithSheet as gt } from "@univerjs/engine-formula";
8
- import { addCustomRangeBySelectionFactory as ft, deleteCustomRangeFactory as _t, replaceSelectionFactory as Oe } from "@univerjs/docs";
9
- var mt = Object.getOwnPropertyDescriptor, yt = (r, e, t, n) => {
10
- for (var s = n > 1 ? void 0 : n ? mt(e, t) : e, i = r.length - 1, a; i >= 0; i--)
1
+ var Ae = Object.defineProperty;
2
+ var We = (r, e, t) => e in r ? Ae(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
+ var w = (r, e, t) => We(r, typeof e != "symbol" ? e + "" : e, t);
4
+ import { Disposable as T, ObjectMatrix as Z, UniverInstanceType as I, IUniverInstanceService as k, CommandType as E, CustomRangeType as U, Inject as M, ICommandService as b, sequenceExecuteAsync as Be, isValidRange as Se, toDisposable as je, DisposableCollection as Fe, Rectangle as Ke, Range as Ye, Tools as de, BuildTextUtils as Q, generateRandomId as ce, TextX as le, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as Ge, IResourceManagerService as ze, IUndoRedoService as ve, CellValueType as Ie, sequenceExecute as Y, getBodySlice as Pe, LocaleService as Je, DependentOn as Xe, Injector as qe, IConfigService as Ze, Plugin as Qe, merge as et, registerDependencies as tt, touchDependencies as nt } from "@univerjs/core";
5
+ import { Subject as rt } from "rxjs";
6
+ import { getSheetCommandTarget as j, RefRangeService as De, SheetsSelectionsService as Oe, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as st, handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests as it, SheetInterceptorService as ue, RemoveSheetCommand as at, handleDefaultRangeChangeWithEffectRefCommands as ot, SetRangeValuesMutation as x, SetRangeValuesCommand as dt, ClearSelectionContentCommand as ct, ClearSelectionAllCommand as lt, ClearSelectionFormatCommand as ut, AFTER_CELL_EDIT as pt, SetRangeValuesUndoMutationFactory as Me, UniverSheetsPlugin as ht } from "@univerjs/sheets";
7
+ import { deserializeRangeWithSheet as Ce, serializeRange as B, IDefinedNamesService as gt, serializeRangeWithSheet as ft } from "@univerjs/engine-formula";
8
+ import { addCustomRangeBySelectionFactory as _t, deleteCustomRangeFactory as mt, replaceSelectionFactory as He } from "@univerjs/docs";
9
+ var yt = Object.getOwnPropertyDescriptor, Rt = (r, e, t, n) => {
10
+ for (var s = n > 1 ? void 0 : n ? yt(e, t) : e, i = r.length - 1, a; i >= 0; i--)
11
11
  (a = r[i]) && (s = a(s) || s);
12
12
  return s;
13
- }, Rt = (r, e) => (t, n) => e(t, n, r);
14
- let v = class extends V {
13
+ }, St = (r, e) => (t, n) => e(t, n, r);
14
+ let v = class extends T {
15
15
  constructor(e) {
16
16
  super();
17
- w(this, "_linkUpdate$", new nt());
17
+ w(this, "_linkUpdate$", new rt());
18
18
  w(this, "linkUpdate$", this._linkUpdate$.asObservable());
19
19
  w(this, "_linkMap", /* @__PURE__ */ new Map());
20
20
  w(this, "_linkPositionMap", /* @__PURE__ */ new Map());
@@ -28,7 +28,7 @@ let v = class extends V {
28
28
  let n = this._linkMap.get(e);
29
29
  n || (n = /* @__PURE__ */ new Map(), this._linkMap.set(e, n));
30
30
  let s = n.get(t);
31
- s || (s = new q(), n.set(t, s));
31
+ s || (s = new Z(), n.set(t, s));
32
32
  let i = this._linkPositionMap.get(e);
33
33
  i || (i = /* @__PURE__ */ new Map(), this._linkPositionMap.set(e, i));
34
34
  let a = i.get(t);
@@ -137,11 +137,11 @@ let v = class extends V {
137
137
  return Array.from(this._linkMap.keys()).map((t) => this.getUnit(t));
138
138
  }
139
139
  };
140
- v = yt([
141
- Rt(0, k)
140
+ v = Rt([
141
+ St(0, k)
142
142
  ], v);
143
143
  var L = /* @__PURE__ */ ((r) => (r.SHEET = "gid", r.RANGE = "range", r.DEFINE_NAME = "rangeid", r.INVALID = "invalid", r.URL = "url", r))(L || {});
144
- const St = "sheets-hyper-link.config", Le = {}, P = {
144
+ const vt = "sheets-hyper-link.config", Ue = {}, P = {
145
145
  type: E.MUTATION,
146
146
  id: "sheets.mutation.add-hyper-link",
147
147
  handler(r, e) {
@@ -159,7 +159,7 @@ const St = "sheets-hyper-link.config", Le = {}, P = {
159
159
  const t = r.get(v), { unitId: n, subUnitId: s, id: i } = e;
160
160
  return t.removeHyperLink(n, s, i);
161
161
  }
162
- }, _e = {
162
+ }, me = {
163
163
  type: E.MUTATION,
164
164
  id: "sheets.mutation.update-hyper-link",
165
165
  handler(r, e) {
@@ -168,7 +168,7 @@ const St = "sheets-hyper-link.config", Le = {}, P = {
168
168
  const t = r.get(v), { unitId: n, subUnitId: s, payload: i, id: a } = e;
169
169
  return t.updateHyperLink(n, s, a, i, !1);
170
170
  }
171
- }, me = {
171
+ }, ye = {
172
172
  type: E.MUTATION,
173
173
  id: "sheets.mutation.update-hyper-link-ref",
174
174
  handler(r, e) {
@@ -177,7 +177,7 @@ const St = "sheets-hyper-link.config", Le = {}, P = {
177
177
  const t = r.get(v), { unitId: n, subUnitId: s, id: i, row: a, column: o, silent: c } = e;
178
178
  return t.updateHyperLinkRef(n, s, i, { row: a, column: o }, c);
179
179
  }
180
- }, X = {
180
+ }, q = {
181
181
  type: E.MUTATION,
182
182
  id: "sheets.mutation.update-rich-hyper-link",
183
183
  handler(r, e) {
@@ -190,13 +190,13 @@ const St = "sheets-hyper-link.config", Le = {}, P = {
190
190
  const { worksheet: l } = d, u = l.getCellRaw(s, i), h = (f = (p = (g = u == null ? void 0 : u.p) == null ? void 0 : g.body) == null ? void 0 : p.customRanges) == null ? void 0 : f.find((_) => _.rangeType === U.HYPERLINK && _.rangeId === a);
191
191
  return h && (h.properties.url = o), !0;
192
192
  }
193
- }, He = "SHEET_HYPER_LINK_PLUGIN", Q = "err";
194
- var vt = Object.getOwnPropertyDescriptor, It = (r, e, t, n) => {
195
- for (var s = n > 1 ? void 0 : n ? vt(e, t) : e, i = r.length - 1, a; i >= 0; i--)
193
+ }, Ve = "SHEET_HYPER_LINK_PLUGIN", ee = "err";
194
+ var It = Object.getOwnPropertyDescriptor, Mt = (r, e, t, n) => {
195
+ for (var s = n > 1 ? void 0 : n ? It(e, t) : e, i = r.length - 1, a; i >= 0; i--)
196
196
  (a = r[i]) && (s = a(s) || s);
197
197
  return s;
198
- }, z = (r, e) => (t, n) => e(t, n, r);
199
- let ee = class extends V {
198
+ }, J = (r, e) => (t, n) => e(t, n, r);
199
+ let te = class extends T {
200
200
  constructor(e, t, n, s) {
201
201
  super();
202
202
  w(this, "_disposableMap", /* @__PURE__ */ new Map());
@@ -212,7 +212,7 @@ let ee = class extends V {
212
212
  };
213
213
  return s ? {
214
214
  redos: [{
215
- id: me.id,
215
+ id: ye.id,
216
216
  params: {
217
217
  unitId: e,
218
218
  subUnitId: t,
@@ -223,7 +223,7 @@ let ee = class extends V {
223
223
  }
224
224
  }],
225
225
  undos: [{
226
- id: me.id,
226
+ id: ye.id,
227
227
  params: {
228
228
  unitId: e,
229
229
  subUnitId: t,
@@ -261,7 +261,7 @@ let ee = class extends V {
261
261
  startRow: n.row,
262
262
  endRow: n.row
263
263
  }, a = (o) => {
264
- const c = rt(i, o, { selectionManagerService: this._selectionManagerService }), d = Array.isArray(c) ? c[0] : c;
264
+ const c = st(i, o, { selectionManagerService: this._selectionManagerService }), d = Array.isArray(c) ? c[0] : c;
265
265
  return d && d.startColumn === i.startColumn && d.startRow === i.startRow ? {
266
266
  undos: [],
267
267
  redos: []
@@ -278,7 +278,7 @@ let ee = class extends V {
278
278
  };
279
279
  this._watchDisposableMap.set(s, this._refRangeService.watchRange(e, t, i, (a, o) => {
280
280
  const { redos: c } = this._handlePositionChange(e, t, n, o, !0);
281
- Re(c, this._commandService, { onlyLocal: !0 });
281
+ Be(c, this._commandService, { onlyLocal: !0 });
282
282
  }, !0));
283
283
  }
284
284
  _unregisterPosition(e) {
@@ -299,15 +299,15 @@ let ee = class extends V {
299
299
  };
300
300
  if (d.range && d.gid) {
301
301
  const l = d.gid, u = Ce(d.range).range;
302
- if (Se(u) && d.range !== Q) {
302
+ if (Se(u) && d.range !== ee) {
303
303
  const h = (g) => {
304
- const p = st(u, g, { selectionManagerService: this._selectionManagerService });
304
+ const p = it(u, g, { selectionManagerService: this._selectionManagerService });
305
305
  return p && B(p) === B(u) ? {
306
306
  redos: [],
307
307
  undos: []
308
308
  } : {
309
309
  redos: [{
310
- id: _e.id,
310
+ id: me.id,
311
311
  params: {
312
312
  unitId: e,
313
313
  subUnitId: l,
@@ -318,7 +318,7 @@ let ee = class extends V {
318
318
  }
319
319
  }],
320
320
  undos: [{
321
- id: _e.id,
321
+ id: me.id,
322
322
  params: {
323
323
  unitId: e,
324
324
  subUnitId: l,
@@ -392,25 +392,25 @@ let ee = class extends V {
392
392
  }
393
393
  }
394
394
  })
395
- ), this.disposeWithMe(We(() => {
395
+ ), this.disposeWithMe(je(() => {
396
396
  this._disposableMap.forEach((e) => {
397
397
  e.dispose();
398
398
  }), this._disposableMap.clear();
399
399
  }));
400
400
  }
401
401
  };
402
- ee = It([
403
- z(0, M(Pe)),
404
- z(1, M(v)),
405
- z(2, M(De)),
406
- z(3, b)
407
- ], ee);
408
- var Mt = Object.getOwnPropertyDescriptor, Ct = (r, e, t, n) => {
409
- for (var s = n > 1 ? void 0 : n ? Mt(e, t) : e, i = r.length - 1, a; i >= 0; i--)
402
+ te = Mt([
403
+ J(0, M(De)),
404
+ J(1, M(v)),
405
+ J(2, M(Oe)),
406
+ J(3, b)
407
+ ], te);
408
+ var Ct = Object.getOwnPropertyDescriptor, wt = (r, e, t, n) => {
409
+ for (var s = n > 1 ? void 0 : n ? Ct(e, t) : e, i = r.length - 1, a; i >= 0; i--)
410
410
  (a = r[i]) && (s = a(s) || s);
411
411
  return s;
412
- }, he = (r, e) => (t, n) => e(t, n, r);
413
- let te = class extends V {
412
+ }, ge = (r, e) => (t, n) => e(t, n, r);
413
+ let ne = class extends T {
414
414
  constructor(r, e, t) {
415
415
  super(), this._sheetInterceptorService = r, this._univerInstanceService = e, this._hyperLinkModel = t, this._initSheetChange();
416
416
  }
@@ -419,7 +419,7 @@ let te = class extends V {
419
419
  this._sheetInterceptorService.interceptCommand({
420
420
  getMutations: (r) => {
421
421
  var e;
422
- if (r.id === it.id) {
422
+ if (r.id === at.id) {
423
423
  const t = r.params, n = t.unitId ? this._univerInstanceService.getUnit(t.unitId) : this._univerInstanceService.getCurrentUnitForType(I.UNIVER_SHEET);
424
424
  if (!n)
425
425
  return { redos: [], undos: [] };
@@ -449,17 +449,17 @@ let te = class extends V {
449
449
  );
450
450
  }
451
451
  };
452
- te = Ct([
453
- he(0, M(le)),
454
- he(1, k),
455
- he(2, M(v))
456
- ], te);
457
- var wt = Object.getOwnPropertyDescriptor, kt = (r, e, t, n) => {
458
- for (var s = n > 1 ? void 0 : n ? wt(e, t) : e, i = r.length - 1, a; i >= 0; i--)
452
+ ne = wt([
453
+ ge(0, M(ue)),
454
+ ge(1, k),
455
+ ge(2, M(v))
456
+ ], ne);
457
+ var kt = Object.getOwnPropertyDescriptor, Et = (r, e, t, n) => {
458
+ for (var s = n > 1 ? void 0 : n ? kt(e, t) : e, i = r.length - 1, a; i >= 0; i--)
459
459
  (a = r[i]) && (s = a(s) || s);
460
460
  return s;
461
- }, ge = (r, e) => (t, n) => e(t, n, r);
462
- let ne = class extends V {
461
+ }, fe = (r, e) => (t, n) => e(t, n, r);
462
+ let re = class extends T {
463
463
  constructor(e, t, n) {
464
464
  super();
465
465
  w(this, "_refRangeMap", /* @__PURE__ */ new Map());
@@ -469,7 +469,7 @@ let ne = class extends V {
469
469
  let n = this._refRangeMap.get(e);
470
470
  n || (n = /* @__PURE__ */ new Map(), this._refRangeMap.set(e, n));
471
471
  let s = n.get(t);
472
- return s || (s = new q(), n.set(t, s)), s;
472
+ return s || (s = new Z(), n.set(t, s)), s;
473
473
  }
474
474
  _isLegalRangeUrl(e, t) {
475
475
  var s, i, a;
@@ -487,7 +487,7 @@ let ne = class extends V {
487
487
  if (!l)
488
488
  return null;
489
489
  const u = Ce(c.range).range;
490
- if (Se(u, l) && c.range !== Q)
490
+ if (Se(u, l) && c.range !== ee)
491
491
  return {
492
492
  range: u,
493
493
  worksheet: l
@@ -503,7 +503,7 @@ let ne = class extends V {
503
503
  var h;
504
504
  return u.rangeType === U.HYPERLINK && this._isLegalRangeUrl(e, (h = u.properties) == null ? void 0 : h.url);
505
505
  })) {
506
- const u = new Be();
506
+ const u = new Fe();
507
507
  let h = !1;
508
508
  (l = (d = i.body) == null ? void 0 : d.customRanges) == null || l.forEach((g) => {
509
509
  var p;
@@ -515,26 +515,26 @@ let ne = class extends V {
515
515
  this._refRangeService.registerRefRange(
516
516
  m,
517
517
  (y) => {
518
- const R = at(m, y);
519
- return R && je.equals(R, m) ? {
518
+ const R = ot(m, y);
519
+ return R && Ke.equals(R, m) ? {
520
520
  preRedos: [],
521
521
  preUndos: [],
522
522
  redos: [],
523
523
  undos: []
524
524
  } : {
525
525
  preRedos: [{
526
- id: X.id,
526
+ id: q.id,
527
527
  params: {
528
528
  unitId: e,
529
529
  subUnitId: t,
530
530
  row: n,
531
531
  col: s,
532
532
  id: g.rangeId,
533
- url: `#gid=${t}&range=${R ? B(R) : Q}`
533
+ url: `#gid=${t}&range=${R ? B(R) : ee}`
534
534
  }
535
535
  }],
536
536
  undos: [{
537
- id: X.id,
537
+ id: q.id,
538
538
  params: {
539
539
  unitId: e,
540
540
  subUnitId: t,
@@ -591,9 +591,9 @@ let ne = class extends V {
591
591
  _initSetRangesListener() {
592
592
  this.disposeWithMe(
593
593
  this._commandService.onCommandExecuted((e) => {
594
- if (e.id === H.id) {
594
+ if (e.id === x.id) {
595
595
  const t = e.params, { unitId: n, subUnitId: s, cellValue: i } = t, a = this._enusreMap(n, s);
596
- i && new q(i).forValue((o, c, d) => {
596
+ i && new Z(i).forValue((o, c, d) => {
597
597
  const l = a.getValue(o, c);
598
598
  l && l.dispose(), d && d.p && this._registerRange(n, s, o, c, d.p);
599
599
  });
@@ -601,7 +601,7 @@ let ne = class extends V {
601
601
  })
602
602
  ), this.disposeWithMe(
603
603
  this._commandService.onCommandExecuted((e) => {
604
- if (e.id === X.id) {
604
+ if (e.id === q.id) {
605
605
  const t = e.params, { unitId: n, subUnitId: s, row: i, col: a } = t, o = j(this._univerInstanceService, { unitId: n, subUnitId: s }), d = this._enusreMap(n, s).getValue(i, a);
606
606
  if (d && d.dispose(), o) {
607
607
  const { worksheet: l } = o, u = l.getCellRaw(i, a);
@@ -612,17 +612,17 @@ let ne = class extends V {
612
612
  );
613
613
  }
614
614
  };
615
- ne = kt([
616
- ge(0, b),
617
- ge(1, k),
618
- ge(2, M(Pe))
619
- ], ne);
620
- var Et = Object.getOwnPropertyDescriptor, Lt = (r, e, t, n) => {
621
- for (var s = n > 1 ? void 0 : n ? Et(e, t) : e, i = r.length - 1, a; i >= 0; i--)
615
+ re = Et([
616
+ fe(0, b),
617
+ fe(1, k),
618
+ fe(2, M(De))
619
+ ], re);
620
+ var Lt = Object.getOwnPropertyDescriptor, Ut = (r, e, t, n) => {
621
+ for (var s = n > 1 ? void 0 : n ? Lt(e, t) : e, i = r.length - 1, a; i >= 0; i--)
622
622
  (a = r[i]) && (s = a(s) || s);
623
623
  return s;
624
- }, J = (r, e) => (t, n) => e(t, n, r);
625
- let re = class extends V {
624
+ }, X = (r, e) => (t, n) => e(t, n, r);
625
+ let se = class extends T {
626
626
  constructor(r, e, t, n) {
627
627
  super(), this._sheetInterceptorService = r, this._hyperLinkModel = e, this._selectionManagerService = t, this._univerInstanceService = n, this._initCommandInterceptor(), this._initAfterEditor();
628
628
  }
@@ -632,9 +632,9 @@ let re = class extends V {
632
632
  _initSetRangeValuesCommandInterceptor() {
633
633
  this.disposeWithMe(this._sheetInterceptorService.interceptCommand({
634
634
  getMutations: (r) => {
635
- if (r.id === ot.id) {
635
+ if (r.id === dt.id) {
636
636
  const e = r.params, { unitId: t, subUnitId: n } = e, s = [], i = [];
637
- return e.cellValue && new q(e.cellValue).forValue((a, o) => {
637
+ return e.cellValue && new Z(e.cellValue).forValue((a, o) => {
638
638
  const c = this._hyperLinkModel.getHyperLinkByLocation(t, n, a, o);
639
639
  c && (s.push({
640
640
  id: D.id,
@@ -666,11 +666,11 @@ let re = class extends V {
666
666
  _initClearSelectionCommandInterceptor() {
667
667
  this.disposeWithMe(this._sheetInterceptorService.interceptCommand({
668
668
  getMutations: (r) => {
669
- if (r.id === dt.id || r.id === ct.id || r.id === lt.id) {
669
+ if (r.id === ct.id || r.id === lt.id || r.id === ut.id) {
670
670
  const e = [], t = [], n = this._selectionManagerService.getCurrentLastSelection(), s = j(this._univerInstanceService);
671
671
  if (n && s) {
672
672
  const { unitId: i, subUnitId: a } = s;
673
- Fe.foreach(n.range, (o, c) => {
673
+ Ye.foreach(n.range, (o, c) => {
674
674
  const d = this._hyperLinkModel.getHyperLinkByLocation(i, a, o, c);
675
675
  d && (e.push({
676
676
  id: D.id,
@@ -702,18 +702,18 @@ let re = class extends V {
702
702
  }));
703
703
  }
704
704
  _initAfterEditor() {
705
- this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(ut, {
705
+ this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(pt, {
706
706
  handler: (r, e, t) => {
707
707
  if (!r || r.p)
708
708
  return t(r);
709
- if (typeof r.v == "string" && oe.isLegalUrl(r.v) && r.v[r.v.length - 1] !== " ") {
709
+ if (typeof r.v == "string" && de.isLegalUrl(r.v) && r.v[r.v.length - 1] !== " ") {
710
710
  const { unitId: n, subUnitId: s } = e, i = this._univerInstanceService.getUnit(n, I.UNIVER_SHEET), a = i == null ? void 0 : i.getSheetBySheetId(s);
711
711
  if (!a)
712
712
  return t(r);
713
713
  const o = a.getBlankCellDocumentModel(r);
714
714
  if (!o.documentModel)
715
715
  return t(r);
716
- const c = Z.selection.replace({
716
+ const c = Q.selection.replace({
717
717
  selection: {
718
718
  startOffset: 0,
719
719
  endOffset: r.v.length,
@@ -724,7 +724,7 @@ let re = class extends V {
724
724
  customRanges: [{
725
725
  startIndex: 0,
726
726
  endIndex: r.v.length - 1,
727
- rangeId: de(),
727
+ rangeId: ce(),
728
728
  rangeType: U.HYPERLINK,
729
729
  properties: {
730
730
  url: r.v
@@ -736,10 +736,10 @@ let re = class extends V {
736
736
  if (!c)
737
737
  return t(r);
738
738
  const d = o.documentModel.getBody();
739
- return ce.apply(d, c.serialize()), t({
739
+ return le.apply(d, c.serialize()), t({
740
740
  ...r,
741
741
  p: {
742
- id: Ke,
742
+ id: Ge,
743
743
  body: d,
744
744
  documentStyle: {
745
745
  pageSize: {
@@ -755,18 +755,18 @@ let re = class extends V {
755
755
  }));
756
756
  }
757
757
  };
758
- re = Lt([
759
- J(0, M(le)),
760
- J(1, M(v)),
761
- J(2, M(De)),
762
- J(3, k)
763
- ], re);
764
- var Ve = /* @__PURE__ */ ((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))(Ve || {}), Ut = Object.getOwnPropertyDescriptor, bt = (r, e, t, n) => {
765
- for (var s = n > 1 ? void 0 : n ? Ut(e, t) : e, i = r.length - 1, a; i >= 0; i--)
758
+ se = Ut([
759
+ X(0, M(ue)),
760
+ X(1, M(v)),
761
+ X(2, M(Oe)),
762
+ X(3, k)
763
+ ], se);
764
+ var xe = /* @__PURE__ */ ((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))(xe || {}), bt = Object.getOwnPropertyDescriptor, Nt = (r, e, t, n) => {
765
+ for (var s = n > 1 ? void 0 : n ? bt(e, t) : e, i = r.length - 1, a; i >= 0; i--)
766
766
  (a = r[i]) && (s = a(s) || s);
767
767
  return s;
768
- }, Ue = (r, e) => (t, n) => e(t, n, r);
769
- let se = class extends V {
768
+ }, be = (r, e) => (t, n) => e(t, n, r);
769
+ let ie = class extends T {
770
770
  constructor(r, e) {
771
771
  super(), this._resourceManagerService = r, this._hyperLinkModel = e, this._initSnapshot();
772
772
  }
@@ -787,8 +787,8 @@ let se = class extends V {
787
787
  };
788
788
  this.disposeWithMe(
789
789
  this._resourceManagerService.registerPluginResource({
790
- pluginName: He,
791
- businesses: [Ve.UNIVER_SHEET],
790
+ pluginName: Ve,
791
+ businesses: [xe.UNIVER_SHEET],
792
792
  toJson: (t) => r(t),
793
793
  parseJson: (t) => e(t),
794
794
  onUnLoad: (t) => {
@@ -805,22 +805,22 @@ let se = class extends V {
805
805
  );
806
806
  }
807
807
  };
808
- se = bt([
809
- Ue(0, Ye),
810
- Ue(1, M(v))
811
- ], se);
812
- const Nt = {
808
+ ie = Nt([
809
+ be(0, ze),
810
+ be(1, M(v))
811
+ ], ie);
812
+ const Pt = {
813
813
  type: E.COMMAND,
814
814
  id: "sheets.command.add-hyper-link",
815
815
  // eslint-disable-next-line max-lines-per-function
816
816
  async handler(r, e) {
817
817
  if (!e) return !1;
818
- const t = r.get(b), n = r.get(ve), s = r.get(k), i = r.get(v), a = r.get(le), o = j(s, e);
818
+ const t = r.get(b), n = r.get(ve), s = r.get(k), i = r.get(v), a = r.get(ue), o = j(s, e);
819
819
  if (!o) return !1;
820
- const { unitId: c, subUnitId: d, workbook: l, worksheet: u } = o, { link: h } = e, { payload: g, display: p, row: f, column: _, id: m } = h, C = u.getCell(f, _), y = u.getBlankCellDocumentModel(C), R = y.documentModel.getSnapshot(), S = oe.deepClone(R.body);
820
+ const { unitId: c, subUnitId: d, workbook: l, worksheet: u } = o, { link: h } = e, { payload: g, display: p, row: f, column: _, id: m } = h, C = u.getCell(f, _), y = u.getBlankCellDocumentModel(C), R = y.documentModel.getSnapshot(), S = de.deepClone(R.body);
821
821
  if (!S) return !1;
822
822
  let N;
823
- if (p ? N = Z.selection.replace({
823
+ if (p ? N = Q.selection.replace({
824
824
  selection: {
825
825
  startOffset: 0,
826
826
  endOffset: S.dataStream.length - 2,
@@ -840,7 +840,7 @@ const Nt = {
840
840
  }]
841
841
  },
842
842
  doc: y.documentModel
843
- }) : N = Z.customRange.add({
843
+ }) : N = Q.customRange.add({
844
844
  body: S,
845
845
  ranges: [{ startOffset: 0, endOffset: S.dataStream.length - 2, collapsed: !1 }],
846
846
  rangeId: m,
@@ -850,54 +850,54 @@ const Nt = {
850
850
  refId: m
851
851
  }
852
852
  }), !N) return !1;
853
- const F = ce.apply(S, N.serialize()), O = {
853
+ const F = le.apply(S, N.serialize()), O = {
854
854
  p: {
855
855
  ...R,
856
856
  body: F
857
857
  },
858
858
  t: Ie.STRING
859
- }, T = await a.onWriteCell(l, u, f, _, O), $ = {
859
+ }, A = a.onWriteCell(l, u, f, _, O), W = {
860
860
  unitId: c,
861
861
  subUnitId: d,
862
862
  cellValue: {
863
863
  [h.row]: {
864
- [h.column]: T
864
+ [h.column]: A
865
865
  }
866
866
  }
867
- }, ue = {
868
- id: H.id,
869
- params: $
870
- }, Y = Me(r, $), pe = {
871
- id: H.id,
872
- params: Y
873
- }, K = [ue], A = [pe], W = i.getHyperLinkByLocation(c, d, f, _);
874
- return W && (K.push({
867
+ }, pe = {
868
+ id: x.id,
869
+ params: W
870
+ }, G = Me(r, W), he = {
871
+ id: x.id,
872
+ params: G
873
+ }, K = [pe], H = [he], V = i.getHyperLinkByLocation(c, d, f, _);
874
+ return V && (K.push({
875
875
  id: D.id,
876
876
  params: {
877
877
  unitId: c,
878
878
  subUnitId: d,
879
- id: W.id
879
+ id: V.id
880
880
  }
881
- }), A.push({
881
+ }), H.push({
882
882
  id: P.id,
883
883
  params: {
884
884
  unitId: c,
885
885
  subUnitId: d,
886
- link: W
886
+ link: V
887
887
  }
888
- })), await Re(K, t) ? (n.pushUndoRedo({
888
+ })), await Y(K, t) ? await a.onValidateCell(l, u, f, _) === !1 ? (Y(H, t), !1) : (n.pushUndoRedo({
889
889
  redoMutations: K,
890
- undoMutations: A,
890
+ undoMutations: H,
891
891
  unitID: c
892
892
  }), !0) : !1;
893
893
  }
894
- }, Pt = {
894
+ }, Dt = {
895
895
  id: "sheets.command.add-rich-hyper-link",
896
896
  type: E.COMMAND,
897
897
  handler: async (r, e) => {
898
898
  if (!e)
899
899
  return !1;
900
- const { documentId: t, link: n } = e, s = r.get(b), i = de(), { payload: a } = n, o = ft(r, {
900
+ const { documentId: t, link: n } = e, s = r.get(b), i = ce(), { payload: a } = n, o = _t(r, {
901
901
  unitId: t,
902
902
  rangeId: i,
903
903
  rangeType: U.HYPERLINK,
@@ -908,12 +908,12 @@ const Nt = {
908
908
  });
909
909
  return o ? s.syncExecuteCommand(o.id, o.params) : !1;
910
910
  }
911
- }, Dt = {
911
+ }, Ot = {
912
912
  type: E.COMMAND,
913
913
  id: "sheets.command.cancel-hyper-link",
914
914
  // eslint-disable-next-line max-lines-per-function
915
915
  handler(r, e) {
916
- var O, T;
916
+ var O, A;
917
917
  if (!e) return !1;
918
918
  const t = r.get(b), n = r.get(ve), s = r.get(k), i = r.get(v), a = j(s, e);
919
919
  if (!a) return !1;
@@ -921,11 +921,11 @@ const Nt = {
921
921
  if (!g) return !1;
922
922
  const p = h.getCellDocumentModelWithFormula(g);
923
923
  if (!(p != null && p.documentModel)) return !1;
924
- const f = oe.deepClone(p.documentModel.getSnapshot()), _ = (T = (O = f.body) == null ? void 0 : O.customRanges) == null ? void 0 : T.find(($) => `${$.rangeId}` === d);
924
+ const f = de.deepClone(p.documentModel.getSnapshot()), _ = (A = (O = f.body) == null ? void 0 : O.customRanges) == null ? void 0 : A.find((W) => `${W.rangeId}` === d);
925
925
  if (!_) return !1;
926
- const m = Z.customRange.delete({ documentDataModel: p.documentModel, rangeId: _.rangeId });
926
+ const m = Q.customRange.delete({ documentDataModel: p.documentModel, rangeId: _.rangeId });
927
927
  if (!m) return !1;
928
- const C = ce.apply(f.body, m.serialize()), y = [], R = [], S = {
928
+ const C = le.apply(f.body, m.serialize()), y = [], R = [], S = {
929
929
  unitId: l,
930
930
  subUnitId: u,
931
931
  cellValue: {
@@ -941,12 +941,12 @@ const Nt = {
941
941
  }
942
942
  };
943
943
  y.push({
944
- id: H.id,
944
+ id: x.id,
945
945
  params: S
946
946
  });
947
947
  const N = Me(r, S);
948
948
  R.push({
949
- id: H.id,
949
+ id: x.id,
950
950
  params: N
951
951
  });
952
952
  const F = i.getHyperLinkByLocation(l, u, o, c);
@@ -966,13 +966,13 @@ const Nt = {
966
966
  ...F
967
967
  }
968
968
  }
969
- })), Ge(y, t).result ? (n.pushUndoRedo({
969
+ })), Y(y, t).result ? (n.pushUndoRedo({
970
970
  redoMutations: y,
971
971
  undoMutations: R,
972
972
  unitID: l
973
973
  }), !0) : !1;
974
974
  }
975
- }, Ot = {
975
+ }, Ht = {
976
976
  type: E.COMMAND,
977
977
  id: "sheets.command.cancel-rich-hyper-link",
978
978
  handler(r, e) {
@@ -984,17 +984,17 @@ const Nt = {
984
984
  o && o.endIndex === a.getBody().dataStream.length - 3 && (c = {
985
985
  dataStream: " "
986
986
  });
987
- const d = _t(r, { unitId: n, rangeId: t, insert: c });
987
+ const d = mt(r, { unitId: n, rangeId: t, insert: c });
988
988
  return d ? s.syncExecuteCommand(d.id, d.params) : !1;
989
989
  }
990
- }, Ht = {
990
+ }, Vt = {
991
991
  type: E.COMMAND,
992
992
  id: "sheets.command.update-hyper-link",
993
993
  // eslint-disable-next-line max-lines-per-function
994
994
  async handler(r, e) {
995
995
  var we, ke, Ee;
996
996
  if (!e) return !1;
997
- const t = r.get(b), n = r.get(ve), s = r.get(k), i = r.get(v), a = r.get(le), o = j(s, {
997
+ const t = r.get(b), n = r.get(ve), s = r.get(k), i = r.get(v), a = r.get(ue), o = j(s, {
998
998
  unitId: e.unitId,
999
999
  subUnitId: e.subUnitId
1000
1000
  });
@@ -1003,11 +1003,11 @@ const Nt = {
1003
1003
  if (!C) return !1;
1004
1004
  const y = g.getCellDocumentModelWithFormula(C);
1005
1005
  if (!(y != null && y.documentModel)) return !1;
1006
- const R = y.documentModel.getSnapshot(), S = (ke = (we = R.body) == null ? void 0 : we.customRanges) == null ? void 0 : ke.find((Te) => `${Te.rangeId}` === u);
1006
+ const R = y.documentModel.getSnapshot(), S = (ke = (we = R.body) == null ? void 0 : we.customRanges) == null ? void 0 : ke.find((Le) => `${Le.rangeId}` === u);
1007
1007
  if (!S) return !1;
1008
- const N = de(), x = (Ee = Ne(y.documentModel.getBody(), S.startIndex, S.endIndex + 1).textRuns) == null ? void 0 : Ee[0];
1009
- x && (x.ed = m.length + 1);
1010
- const O = Oe(r, {
1008
+ const N = ce(), $ = (Ee = Pe(y.documentModel.getBody(), S.startIndex, S.endIndex + 1).textRuns) == null ? void 0 : Ee[0];
1009
+ $ && ($.ed = m.length + 1);
1010
+ const O = He(r, {
1011
1011
  unitId: p,
1012
1012
  body: {
1013
1013
  dataStream: `${m}`,
@@ -1020,7 +1020,7 @@ const Nt = {
1020
1020
  url: _
1021
1021
  }
1022
1022
  }],
1023
- textRuns: x ? [x] : void 0
1023
+ textRuns: $ ? [$] : void 0
1024
1024
  },
1025
1025
  selection: {
1026
1026
  startOffset: S.startIndex,
@@ -1031,48 +1031,48 @@ const Nt = {
1031
1031
  });
1032
1032
  if (!O)
1033
1033
  return !1;
1034
- const T = ce.apply(oe.deepClone(R.body), O.textX.serialize()), $ = {
1034
+ const A = le.apply(de.deepClone(R.body), O.textX.serialize()), W = {
1035
1035
  p: {
1036
1036
  ...R,
1037
- body: T
1037
+ body: A
1038
1038
  },
1039
1039
  t: Ie.STRING
1040
- }, ue = await a.onWriteCell(h, g, d, l, $), Y = {
1041
- id: H.id,
1040
+ }, pe = a.onWriteCell(h, g, d, l, W), G = {
1041
+ id: x.id,
1042
1042
  params: {
1043
1043
  unitId: p,
1044
1044
  subUnitId: f,
1045
1045
  cellValue: {
1046
1046
  [d]: {
1047
- [l]: ue
1047
+ [l]: pe
1048
1048
  }
1049
1049
  }
1050
1050
  }
1051
- }, pe = Me(r, Y.params), K = {
1052
- id: H.id,
1053
- params: pe
1054
- }, A = [Y], W = [K], G = i.getHyperLinkByLocation(p, f, d, l);
1055
- return G && (A.push({
1051
+ }, he = Me(r, G.params), K = {
1052
+ id: x.id,
1053
+ params: he
1054
+ }, H = [G], V = [K], z = i.getHyperLinkByLocation(p, f, d, l);
1055
+ return z && (H.push({
1056
1056
  id: D.id,
1057
1057
  params: {
1058
1058
  unitId: p,
1059
1059
  subUnitId: f,
1060
- id: G.id
1060
+ id: z.id
1061
1061
  }
1062
- }), W.push({
1062
+ }), V.push({
1063
1063
  id: P.id,
1064
1064
  params: {
1065
1065
  unitId: p,
1066
1066
  subUnitId: f,
1067
- link: G
1067
+ link: z
1068
1068
  }
1069
- })), await Re(A, t) ? (n.pushUndoRedo({
1070
- redoMutations: A,
1071
- undoMutations: W,
1069
+ })), Y(H, t) ? await a.onValidateCell(h, g, d, l) === !1 ? (Y(V, t), !1) : (n.pushUndoRedo({
1070
+ redoMutations: H,
1071
+ undoMutations: V,
1072
1072
  unitID: p
1073
1073
  }), !0) : !1;
1074
1074
  }
1075
- }, Vt = {
1075
+ }, xt = {
1076
1076
  type: E.COMMAND,
1077
1077
  id: "sheets.command.update-rich-hyper-link",
1078
1078
  handler: (r, e) => {
@@ -1085,9 +1085,9 @@ const Nt = {
1085
1085
  const c = (f = (p = o.getBody()) == null ? void 0 : p.customRanges) == null ? void 0 : f.find((C) => C.rangeId === s);
1086
1086
  if (!c)
1087
1087
  return !1;
1088
- const d = (_ = e.payload.display) != null ? _ : "", l = de(), h = (m = Ne(o.getBody(), c.startIndex, c.endIndex + 1).textRuns) == null ? void 0 : m[0];
1088
+ const d = (_ = e.payload.display) != null ? _ : "", l = ce(), h = (m = Pe(o.getBody(), c.startIndex, c.endIndex + 1).textRuns) == null ? void 0 : m[0];
1089
1089
  h && (h.ed = d.length + 1);
1090
- const g = Oe(r, {
1090
+ const g = He(r, {
1091
1091
  unitId: t,
1092
1092
  body: {
1093
1093
  dataStream: `${d}`,
@@ -1112,42 +1112,42 @@ const Nt = {
1112
1112
  return g ? a.syncExecuteCommand(g.id, g.params) : !1;
1113
1113
  }
1114
1114
  };
1115
- var xt = Object.getOwnPropertyDescriptor, Tt = (r, e, t, n) => {
1116
- for (var s = n > 1 ? void 0 : n ? xt(e, t) : e, i = r.length - 1, a; i >= 0; i--)
1115
+ var Tt = Object.getOwnPropertyDescriptor, $t = (r, e, t, n) => {
1116
+ for (var s = n > 1 ? void 0 : n ? Tt(e, t) : e, i = r.length - 1, a; i >= 0; i--)
1117
1117
  (a = r[i]) && (s = a(s) || s);
1118
1118
  return s;
1119
- }, $t = (r, e) => (t, n) => e(t, n, r);
1120
- let ie = class extends V {
1119
+ }, At = (r, e) => (t, n) => e(t, n, r);
1120
+ let ae = class extends T {
1121
1121
  constructor(r) {
1122
1122
  super(), this._commandService = r, this._registerCommands();
1123
1123
  }
1124
1124
  _registerCommands() {
1125
1125
  [
1126
- Nt,
1127
- Ht,
1128
- Dt,
1126
+ Pt,
1129
1127
  Vt,
1130
1128
  Ot,
1131
- Pt,
1129
+ xt,
1130
+ Ht,
1131
+ Dt,
1132
1132
  P,
1133
- _e,
1134
- D,
1135
1133
  me,
1136
- X
1134
+ D,
1135
+ ye,
1136
+ q
1137
1137
  ].forEach((r) => {
1138
1138
  this._commandService.registerCommand(r);
1139
1139
  });
1140
1140
  }
1141
1141
  };
1142
- ie = Tt([
1143
- $t(0, b)
1144
- ], ie);
1145
- var At = Object.getOwnPropertyDescriptor, Wt = (r, e, t, n) => {
1146
- for (var s = n > 1 ? void 0 : n ? At(e, t) : e, i = r.length - 1, a; i >= 0; i--)
1142
+ ae = $t([
1143
+ At(0, b)
1144
+ ], ae);
1145
+ var Wt = Object.getOwnPropertyDescriptor, Bt = (r, e, t, n) => {
1146
+ for (var s = n > 1 ? void 0 : n ? Wt(e, t) : e, i = r.length - 1, a; i >= 0; i--)
1147
1147
  (a = r[i]) && (s = a(s) || s);
1148
1148
  return s;
1149
- }, fe = (r, e) => (t, n) => e(t, n, r);
1150
- let ye = class {
1149
+ }, _e = (r, e) => (t, n) => e(t, n, r);
1150
+ let Re = class {
1151
1151
  constructor(r, e, t) {
1152
1152
  this._univerInstanceService = r, this._localeService = e, this._definedNamesService = t;
1153
1153
  }
@@ -1189,9 +1189,9 @@ let ye = class {
1189
1189
  if (t) {
1190
1190
  if (!o) return a;
1191
1191
  const l = Ce(t).range;
1192
- return Se(l, o) && t !== Q ? {
1192
+ return Se(l, o) && t !== ee ? {
1193
1193
  type: L.RANGE,
1194
- name: gt(c, l)
1194
+ name: ft(c, l)
1195
1195
  } : a;
1196
1196
  }
1197
1197
  if (n) {
@@ -1211,67 +1211,67 @@ let ye = class {
1211
1211
  return a;
1212
1212
  }
1213
1213
  };
1214
- ye = Wt([
1215
- fe(0, k),
1216
- fe(1, M(ze)),
1217
- fe(2, ht)
1218
- ], ye);
1219
- var Bt = Object.defineProperty, jt = Object.getOwnPropertyDescriptor, Ft = (r, e, t) => e in r ? Bt(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, Kt = (r, e, t, n) => {
1220
- for (var s = n > 1 ? void 0 : n ? jt(e, t) : e, i = r.length - 1, a; i >= 0; i--)
1214
+ Re = Bt([
1215
+ _e(0, k),
1216
+ _e(1, M(Je)),
1217
+ _e(2, gt)
1218
+ ], Re);
1219
+ var jt = Object.defineProperty, Ft = Object.getOwnPropertyDescriptor, Kt = (r, e, t) => e in r ? jt(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, Yt = (r, e, t, n) => {
1220
+ for (var s = n > 1 ? void 0 : n ? Ft(e, t) : e, i = r.length - 1, a; i >= 0; i--)
1221
1221
  (a = r[i]) && (s = a(s) || s);
1222
1222
  return s;
1223
- }, be = (r, e) => (t, n) => e(t, n, r), xe = (r, e, t) => Ft(r, typeof e != "symbol" ? e + "" : e, t);
1224
- let ae = class extends Ze {
1225
- constructor(r = Le, e, t) {
1223
+ }, Ne = (r, e) => (t, n) => e(t, n, r), Te = (r, e, t) => Kt(r, typeof e != "symbol" ? e + "" : e, t);
1224
+ let oe = class extends Qe {
1225
+ constructor(r = Ue, e, t) {
1226
1226
  super(), this._config = r, this._injector = e, this._configService = t;
1227
- const { ...n } = Qe(
1227
+ const { ...n } = et(
1228
1228
  {},
1229
- Le,
1229
+ Ue,
1230
1230
  this._config
1231
1231
  );
1232
- this._configService.setConfig(St, n);
1232
+ this._configService.setConfig(vt, n);
1233
1233
  }
1234
1234
  onStarting() {
1235
- et(this._injector, [
1235
+ tt(this._injector, [
1236
1236
  [v],
1237
- [ye],
1238
- [se],
1237
+ [Re],
1239
1238
  [ie],
1240
- [ee],
1241
- [re],
1239
+ [ae],
1242
1240
  [te],
1243
- [ne]
1244
- ]), tt(this._injector, [
1245
- [ee],
1246
1241
  [se],
1247
- [ie],
1248
- [re],
1242
+ [ne],
1243
+ [re]
1244
+ ]), nt(this._injector, [
1249
1245
  [te],
1250
- [ne]
1246
+ [ie],
1247
+ [ae],
1248
+ [se],
1249
+ [ne],
1250
+ [re]
1251
1251
  ]);
1252
1252
  }
1253
1253
  };
1254
- xe(ae, "pluginName", He);
1255
- xe(ae, "type", I.UNIVER_SHEET);
1256
- ae = Kt([
1257
- Je(pt),
1258
- be(1, M(Xe)),
1259
- be(2, qe)
1260
- ], ae);
1254
+ Te(oe, "pluginName", Ve);
1255
+ Te(oe, "type", I.UNIVER_SHEET);
1256
+ oe = Yt([
1257
+ Xe(ht),
1258
+ Ne(1, M(qe)),
1259
+ Ne(2, Ze)
1260
+ ], oe);
1261
1261
  export {
1262
- Nt as AddHyperLinkCommand,
1262
+ Pt as AddHyperLinkCommand,
1263
1263
  P as AddHyperLinkMutation,
1264
- Pt as AddRichHyperLinkCommand,
1265
- Dt as CancelHyperLinkCommand,
1266
- Ot as CancelRichHyperLinkCommand,
1267
- Q as ERROR_RANGE,
1264
+ Dt as AddRichHyperLinkCommand,
1265
+ Ot as CancelHyperLinkCommand,
1266
+ Ht as CancelRichHyperLinkCommand,
1267
+ ee as ERROR_RANGE,
1268
1268
  v as HyperLinkModel,
1269
1269
  D as RemoveHyperLinkMutation,
1270
1270
  L as SheetHyperLinkType,
1271
- ye as SheetsHyperLinkParserService,
1272
- ae as UniverSheetsHyperLinkPlugin,
1273
- Ht as UpdateHyperLinkCommand,
1274
- _e as UpdateHyperLinkMutation,
1275
- me as UpdateHyperLinkRefMutation,
1276
- Vt as UpdateRichHyperLinkCommand
1271
+ Re as SheetsHyperLinkParserService,
1272
+ oe as UniverSheetsHyperLinkPlugin,
1273
+ Vt as UpdateHyperLinkCommand,
1274
+ me as UpdateHyperLinkMutation,
1275
+ ye as UpdateHyperLinkRefMutation,
1276
+ xt as UpdateRichHyperLinkCommand
1277
1277
  };
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (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"})});
1
+ (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,N,m,C,x){"use strict";var Ge=Object.defineProperty;var Ye=(p,a,N)=>a in p?Ge(p,a,{enumerable:!0,configurable:!0,writable:!0,value:N}):p[a]=N;var U=(p,a,N)=>Ye(p,typeof a!="symbol"?a+"":a,N);var Re=Object.getOwnPropertyDescriptor,Me=(s,t,e,n)=>{for(var i=n>1?void 0:n?Re(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},Ce=(s,t)=>(e,n)=>t(e,n,s);p.HyperLinkModel=class extends a.Disposable{constructor(e){super();U(this,"_linkUpdate$",new N.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 r=i.get(n);r||(r=new a.ObjectMatrix,i.set(n,r));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:r,positionMap:d}}addHyperLink(e,n,i){const{matrix:r,positionMap:o}=this._ensureMap(e,n);return r.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,r,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,r),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,r,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,r),c.set(i,{...r,link:u}),d.setValue(r.row,r.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:r,id:i,type:"updateRef",silent:o}),!0}removeHyperLink(e,n,i){const{matrix:r,positionMap:o}=this._ensureMap(e,n),d=o.get(i);if(!d)return!1;o.delete(i);const c=r.getValue(d.row,d.column);return c&&c.id===i&&r.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,i){const{matrix:r,positionMap:o}=this._ensureMap(e,n),d=o.get(i);if(d)return r.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,i,r){const{matrix:o}=this._ensureMap(e,n);return o.getValue(i,r)}getHyperLinkByLocationSync(e,n,i,r){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,r),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,r);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:i}=this._ensureMap(e,n),r=[];return i.forValue((o,d,c)=>{c&&r.push(c)}),r}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(i=>{const r=this.getSubUnit(e,i);return{unitId:e,subUnitId:i,links:r}}):[]}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=Me([Ce(0,a.IUniverInstanceService)],p.HyperLinkModel);var L=(s=>(s.SHEET="gid",s.RANGE="range",s.DEFINE_NAME="rangeid",s.INVALID="invalid",s.URL="url",s))(L||{});const ke="sheets-hyper-link.config",ae={},E={type:a.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(s,t){if(!t)return!1;const e=s.get(p.HyperLinkModel),{unitId:n,subUnitId:i,link:r}=t;return e.addHyperLink(n,i,r)}},w={type:a.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(s,t){if(!t)return!1;const e=s.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:r}=t;return e.removeHyperLink(n,i,r)}},W={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(s,t){if(!t)return!1;const e=s.get(p.HyperLinkModel),{unitId:n,subUnitId:i,payload:r,id:o}=t;return e.updateHyperLink(n,i,o,r,!1)}},B={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(s,t){if(!t)return!1;const e=s.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:r,row:o,column:d,silent:c}=t;return e.updateHyperLinkRef(n,i,r,{row:o,column:d},c)}},K={type:a.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(s,t){var y,h,_;if(!t)return!1;const{unitId:e,subUnitId:n,row:i,col:r,id:o,url:d}=t,c=s.get(a.IUniverInstanceService),l=m.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:u}=l,g=u.getCellRaw(i,r),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 Ue=Object.getOwnPropertyDescriptor,Le=(s,t,e,n)=>{for(var i=n>1?void 0:n?Ue(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},z=(s,t)=>(e,n)=>t(e,n,s);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,r)=>{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:r}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,id:n.id,row:o.startRow,column:o.startColumn,silent:r}}]}:{redos:[{id:w.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,r={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},o=d=>{const c=m.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(r,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===r.startColumn&&l.startRow===r.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(i,this._refRangeService.registerRefRange(r,o,t,e))}_watchPosition(t,e,n){const i=n.id,r={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(t,e,r,(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 r,o,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(r=c.get("gid"))!=null?r:"",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:r,links:o}=n;o.forEach(d=>{this._registerPosition(i,r,d),this._watchPosition(i,r,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:r}=t,o=this._hyperLinkModel.getHyperLink(e,n,i);if(!o)return;this._unregisterPosition(i),this._registerPosition(e,n,o),r||(this._unwatchPosition(i),this._watchPosition(e,n,o));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:i}=n;i.forEach(r=>{this._unregisterPosition(r.id),this._unwatchPosition(r.id),this._unregisterRange(r.id),this._unwatchRange(r.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=Le([z(0,a.Inject(m.RefRangeService)),z(1,a.Inject(p.HyperLinkModel)),z(2,a.Inject(m.SheetsSelectionsService)),z(3,a.ICommandService)],G);var Ee=Object.getOwnPropertyDescriptor,we=(s,t,e,n)=>{for(var i=n>1?void 0:n?Ee(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},te=(s,t)=>(e,n)=>t(e,n,s);let Y=class extends a.Disposable{constructor(s,t,e){super(),this._sheetInterceptorService=s,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:s=>{var t;if(s.id===m.RemoveSheetCommand.id){const e=s.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(),r=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!r)return{redos:[],undos:[]};const o=this._hyperLinkModel.getSubUnit(i,r),d=o.map(l=>({id:w.id,params:{unitId:i,subUnitId:r,id:l.id}})),c=o.map(l=>({id:E.id,params:{unitId:i,subUnitId:r,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 Te=Object.getOwnPropertyDescriptor,He=(s,t,e,n)=>{for(var i=n>1?void 0:n?Te(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},ne=(s,t)=>(e,n)=>t(e,n,s);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,r,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:(r=d.get("range"))!=null?r:"",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,r){var d,c,l,u;const o=this._enusreMap(t,e);if((c=(d=r.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=r.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 r=i.getSheetId(),o=this._enusreMap(n,r);i.getCellMatrix().forValue((d,c,l)=>{const u=o.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,r,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 r=i.getSheetId();this._enusreMap(n,r).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:r}=e,o=this._enusreMap(n,i);r&&new a.ObjectMatrix(r).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:r,col:o}=e,d=m.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:i}),l=this._enusreMap(n,i).getValue(r,o);if(l&&l.dispose(),d){const{worksheet:u}=d,g=u.getCellRaw(r,o);g&&g.p&&this._registerRange(n,i,r,o,g.p)}}}))}};q=He([ne(0,a.ICommandService),ne(1,a.IUniverInstanceService),ne(2,a.Inject(m.RefRangeService))],q);var be=Object.getOwnPropertyDescriptor,Pe=(s,t,e,n)=>{for(var i=n>1?void 0:n?be(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},F=(s,t)=>(e,n)=>t(e,n,s);let J=class extends a.Disposable{constructor(s,t,e,n){super(),this._sheetInterceptorService=s,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:s=>{if(s.id===m.SetRangeValuesCommand.id){const t=s.params,{unitId:e,subUnitId:n}=t,i=[],r=[];return t.cellValue&&new a.ObjectMatrix(t.cellValue).forValue((o,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,o,d);c&&(i.push({id:w.id,params:{unitId:e,subUnitId:n,id:c.id}}),r.push({id:E.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:r,redos:i}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:s=>{if(s.id===m.ClearSelectionContentCommand.id||s.id===m.ClearSelectionAllCommand.id||s.id===m.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),i=m.getSheetCommandTarget(this._univerInstanceService);if(n&&i){const{unitId:r,subUnitId:o}=i;a.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(r,o,d,c);l&&(t.push({id:w.id,params:{unitId:r,subUnitId:o,id:l.id}}),e.push({id:E.id,params:{unitId:r,subUnitId:o,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(m.AFTER_CELL_EDIT,{handler:(s,t,e)=>{if(!s||s.p)return e(s);if(typeof s.v=="string"&&a.Tools.isLegalUrl(s.v)&&s.v[s.v.length-1]!==" "){const{unitId:n,subUnitId:i}=t,r=this._univerInstanceService.getUnit(n,a.UniverInstanceType.UNIVER_SHEET),o=r==null?void 0:r.getSheetBySheetId(i);if(!o)return e(s);const d=o.getBlankCellDocumentModel(s);if(!d.documentModel)return e(s);const c=a.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:s.v.length,collapsed:!1},body:{dataStream:`${s.v}`,customRanges:[{startIndex:0,endIndex:s.v.length-1,rangeId:a.generateRandomId(),rangeType:a.CustomRangeType.HYPERLINK,properties:{url:s.v}}]},doc:d.documentModel});if(!c)return e(s);const l=d.documentModel.getBody();return a.TextX.apply(l,c.serialize()),e({...s,p:{id:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:l,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(s)}}))}};J=Pe([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=(s=>(s[s.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",s[s.UNIVER_DOC=1]="UNIVER_DOC",s[s.UNIVER_SHEET=2]="UNIVER_SHEET",s[s.UNIVER_SLIDE=3]="UNIVER_SLIDE",s[s.UNIVER_PROJECT=4]="UNIVER_PROJECT",s[s.UNRECOGNIZED=-1]="UNRECOGNIZED",s))(de||{}),Ne=Object.getOwnPropertyDescriptor,De=(s,t,e,n)=>{for(var i=n>1?void 0:n?Ne(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},ce=(s,t)=>(e,n)=>t(e,n,s);let X=class extends a.Disposable{constructor(s,t){super(),this._resourceManagerService=s,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const s=e=>{const n=this._hyperLinkModel.getUnit(e),i={};return n?(n.forEach(r=>{i[r.subUnitId]=r.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=>s(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=De([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(s,t){if(!t)return!1;const e=s.get(a.ICommandService),n=s.get(a.IUndoRedoService),i=s.get(a.IUniverInstanceService),r=s.get(p.HyperLinkModel),o=s.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},O=o.onWriteCell(u,g,_,v,H),V={unitId:c,subUnitId:l,cellValue:{[f.row]:{[f.column]:O}}},se={id:m.SetRangeValuesMutation.id,params:V},Q=m.SetRangeValuesUndoMutationFactory(s,V),re={id:m.SetRangeValuesMutation.id,params:Q},A=[se],b=[re],P=r.getHyperLinkByLocation(c,l,_,v);return P&&(A.push({id:w.id,params:{unitId:c,subUnitId:l,id:P.id}}),b.push({id:E.id,params:{unitId:c,subUnitId:l,link:P}})),await a.sequenceExecute(A,e)?await o.onValidateCell(u,g,_,v)===!1?(a.sequenceExecute(b,e),!1):(n.pushUndoRedo({redoMutations:A,undoMutations:b,unitID:c}),!0):!1}},ue={id:"sheets.command.add-rich-hyper-link",type:a.CommandType.COMMAND,handler:async(s,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,i=s.get(a.ICommandService),r=a.generateRandomId(),{payload:o}=n,d=x.addCustomRangeBySelectionFactory(s,{unitId:e,rangeId:r,rangeType:a.CustomRangeType.HYPERLINK,properties:{url:o,refId:r}});return d?i.syncExecuteCommand(d.id,d.params):!1}},pe={type:a.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(s,t){var H,O;if(!t)return!1;const e=s.get(a.ICommandService),n=s.get(a.IUndoRedoService),i=s.get(a.IUniverInstanceService),r=s.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=(O=(H=_.body)==null?void 0:H.customRanges)==null?void 0:O.find(V=>`${V.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(s,M);R.push({id:m.SetRangeValuesMutation.id,params:T});const j=r.getHyperLinkByLocation(u,g,d,c);return j&&(I.push({id:w.id,params:{unitId:u,subUnitId:g,id:l}}),R.push({id:E.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(s,t){var u,g;if(!t)return!1;const{id:e,documentId:n}=t,i=s.get(a.ICommandService),o=s.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(s,{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(s,t){var _e,ve,Se;if(!t)return!1;const e=s.get(a.ICommandService),n=s.get(a.IUndoRedoService),i=s.get(a.IUniverInstanceService),r=s.get(p.HyperLinkModel),o=s.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(Ie=>`${Ie.rangeId}`===g);if(!M)return!1;const T=a.generateRandomId(),D=(Se=a.getBodySlice(I.documentModel.getBody(),M.startIndex,M.endIndex+1).textRuns)==null?void 0:Se[0];D&&(D.ed=S.length+1);const H=x.replaceSelectionFactory(s,{unitId:h,body:{dataStream:`${S}`,customRanges:[{rangeId:T,rangeType:a.CustomRangeType.HYPERLINK,startIndex:0,endIndex:S.length-1,properties:{url:v}}],textRuns:D?[D]:void 0},selection:{startOffset:M.startIndex,endOffset:M.endIndex+1,collapsed:!1},doc:I.documentModel});if(!H)return!1;const O=a.TextX.apply(a.Tools.deepClone(R.body),H.textX.serialize()),V={p:{...R,body:O},t:a.CellValueType.STRING},se=o.onWriteCell(f,y,l,u,V),Q={id:m.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:_,cellValue:{[l]:{[u]:se}}}},re=m.SetRangeValuesUndoMutationFactory(s,Q.params),A={id:m.SetRangeValuesMutation.id,params:re},b=[Q],P=[A],ee=r.getHyperLinkByLocation(h,_,l,u);return ee&&(b.push({id:w.id,params:{unitId:h,subUnitId:_,id:ee.id}}),P.push({id:E.id,params:{unitId:h,subUnitId:_,link:ee}})),a.sequenceExecute(b,e)?await o.onValidateCell(f,y,l,u)===!1?(a.sequenceExecute(P,e),!1):(n.pushUndoRedo({redoMutations:b,undoMutations:P,unitID:h}),!0):!1}},me={type:a.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(s,t)=>{var h,_,v,S;if(!t)return!1;const{documentId:e,payload:n,id:i}=t,r=s.get(a.IUniverInstanceService),o=s.get(a.ICommandService),d=r.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(s,{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 Oe=Object.getOwnPropertyDescriptor,Ve=(s,t,e,n)=>{for(var i=n>1?void 0:n?Oe(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},$e=(s,t)=>(e,n)=>t(e,n,s);let Z=class extends a.Disposable{constructor(s){super(),this._commandService=s,this._registerCommands()}_registerCommands(){[le,he,pe,me,ge,ue,E,W,w,B,K].forEach(s=>{this._commandService.registerCommand(s)})}};Z=Ve([$e(0,a.ICommandService)],Z);var je=Object.getOwnPropertyDescriptor,Ae=(s,t,e,n)=>{for(var i=n>1?void 0:n?je(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},ie=(s,t)=>(e,n)=>t(e,n,s);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,r;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:(r=o.get("unitid"))!=null?r:""},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:r}=t,o=r?this._univerInstanceService.getUnit(r,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=Ae([ie(0,a.IUniverInstanceService),ie(1,a.Inject(a.LocaleService)),ie(2,C.IDefinedNamesService)],p.SheetsHyperLinkParserService);var xe=Object.defineProperty,We=Object.getOwnPropertyDescriptor,Be=(s,t,e)=>t in s?xe(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Ke=(s,t,e,n)=>{for(var i=n>1?void 0:n?We(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},fe=(s,t)=>(e,n)=>t(e,n,s),ye=(s,t,e)=>Be(s,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(ke,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=Ke([a.DependentOn(m.UniverSheetsPlugin),fe(1,a.Inject(a.Injector)),fe(2,a.IConfigService)],p.UniverSheetsHyperLinkPlugin),p.AddHyperLinkCommand=le,p.AddHyperLinkMutation=E,p.AddRichHyperLinkCommand=ue,p.CancelHyperLinkCommand=pe,p.CancelRichHyperLinkCommand=ge,p.ERROR_RANGE=$,p.RemoveHyperLinkMutation=w,p.SheetHyperLinkType=L,p.UpdateHyperLinkCommand=he,p.UpdateHyperLinkMutation=W,p.UpdateHyperLinkRefMutation=B,p.UpdateRichHyperLinkCommand=me,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-hyper-link",
3
- "version": "0.6.3",
3
+ "version": "0.6.4",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -52,17 +52,17 @@
52
52
  },
53
53
  "dependencies": {
54
54
  "@univerjs/protocol": "0.1.43",
55
- "@univerjs/core": "0.6.3",
56
- "@univerjs/sheets": "0.6.3",
57
- "@univerjs/engine-formula": "0.6.3",
58
- "@univerjs/docs": "0.6.3"
55
+ "@univerjs/core": "0.6.4",
56
+ "@univerjs/engine-formula": "0.6.4",
57
+ "@univerjs/docs": "0.6.4",
58
+ "@univerjs/sheets": "0.6.4"
59
59
  },
60
60
  "devDependencies": {
61
61
  "rxjs": "^7.8.1",
62
62
  "typescript": "^5.8.2",
63
63
  "vite": "^6.2.0",
64
64
  "vitest": "^3.0.7",
65
- "@univerjs-infra/shared": "0.6.3"
65
+ "@univerjs-infra/shared": "0.6.4"
66
66
  },
67
67
  "scripts": {
68
68
  "test": "vitest run",