@univerjs/sheets-hyper-link 0.5.0-alpha.0 → 0.5.0-beta.0

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 Se=(i,t,e)=>t in i?ve(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var I=(i,t,e)=>Se(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),Ie=require("rxjs"),g=require("@univerjs/sheets"),R=require("@univerjs/engine-formula"),X=require("@univerjs/docs");var Re=Object.defineProperty,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=(n?a(t,e,r):a(r))||r);return n&&r&&Re(t,e,r),r},Le=(i,t)=>(e,n)=>t(e,n,i);exports.HyperLinkModel=class extends o.Disposable{constructor(e){super();I(this,"_linkUpdate$",new Ie.Subject);I(this,"linkUpdate$",this._linkUpdate$.asObservable());I(this,"_linkMap",new Map);I(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 p=d.getValue(l.row,l.column);return p&&(Object.assign(p,s),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:p.display,payload:p.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 p=d.getValue(l.row,l.column);return!p||p.id!==r?p=l.link:d.realDeleteValue(l.row,l.column),Object.assign(p,s),c.set(r,{...s,link:p}),d.setValue(s.row,s.column,p),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 u,m,_,h,f;const{matrix:a}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,o.UniverInstanceType.UNIVER_SHEET),c=(u=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:u.getCellRaw(r,s),l=((f=(h=c==null?void 0:c.v)!=null?h:(_=(m=c==null?void 0:c.p)==null?void 0:m.body)==null?void 0:_.dataStream.slice(0,-2))!=null?f:"").toString(),p=a.getValue(r,s);if(p)return{...p,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([Le(0,o.IUniverInstanceService)],exports.HyperLinkModel);var L=(i=>(i.SHEET="gid",i.RANGE="range",i.DEFINE_NAME="rangeid",i.INVALID="invalid",i.URL="url",i))(L||{});const Ue="sheets-hyper-link.config",we={},U={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)}},W={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)}},F={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)}},de="SHEET_HYPER_LINK_PLUGIN",x="err";var Ee=Object.defineProperty,ke=Object.getOwnPropertyDescriptor,be=(i,t,e,n)=>{for(var r=n>1?void 0:n?ke(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Ee(t,e,r),r},A=(i,t)=>(e,n)=>t(e,n,i);let z=class extends o.Disposable{constructor(t,e,n,r){super();I(this,"_disposableMap",new Map);I(this,"_watchDisposableMap",new Map);I(this,"_rangeDisableMap",new Map);I(this,"_rangeWatcherMap",new Map);I(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:F.id,params:{unitId:t,subUnitId:e,id:n.id,row:r.startRow,column:r.startColumn,silent:s}}],undos:[{id:F.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:U.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=g.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 p=l.gid,u=R.deserializeRangeWithSheet(l.range).range;if(o.isValidRange(u)&&l.range!==x){const m=_=>{const h=g.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(u,_,{selectionManagerService:this._selectionManagerService});return h&&R.serializeRange(h)===R.serializeRange(u)?{redos:[],undos:[]}:{redos:[{id:W.id,params:{unitId:t,subUnitId:p,id:e,payload:{payload:`#gid=${p}&range=${h?R.serializeRange(h):"err"}`}}}],undos:[{id:W.id,params:{unitId:t,subUnitId:p,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(u,m,t,p)),r||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,p,u,(_,h)=>{this._hyperLinkModel.updateHyperLink(t,p,e,{payload:`#gid=${p}&range=${h?R.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: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=be([A(0,o.Inject(g.RefRangeService)),A(1,o.Inject(exports.HyperLinkModel)),A(2,o.Inject(g.SheetsSelectionsService)),A(3,o.ICommandService)],z);var Pe=Object.defineProperty,He=Object.getOwnPropertyDescriptor,Te=(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=(n?a(t,e,r):a(r))||r);return n&&r&&Pe(t,e,r),r},ee=(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===g.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:U.id,params:{unitId:r,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};G=Te([ee(0,o.Inject(g.SheetInterceptorService)),ee(1,o.IUniverInstanceService),ee(2,o.Inject(exports.HyperLinkModel))],G);var Ne=Object.defineProperty,Oe=Object.getOwnPropertyDescriptor,De=(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=(n?a(t,e,r):a(r))||r);return n&&r&&Ne(t,e,r),r},te=(i,t)=>(e,n)=>t(e,n,i);let K=class extends o.Disposable{constructor(t,e,n){super();I(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,p=n.getSheetBySheetId(l);if(!p)return null;const u=R.deserializeRangeWithSheet(c.range).range;if(o.isValidRange(u,p)&&c.range!==x)return u}}return null}_registerRange(t,e,n,r,s){var d,c,l,p;const a=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(u=>{var m;return u.rangeType===o.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(m=u.properties)==null?void 0:m.url)})){const u=new o.DisposableCollection;(p=(l=s.body)==null?void 0:l.customRanges)==null||p.forEach(m=>{var _;if(m.rangeType===o.CustomRangeType.HYPERLINK){const h=(_=m.properties)==null?void 0:_.url,f=this._isLegalRangeUrl(t,h);f&&u.add(this._refRangeService.watchRange(t,e,f,(M,y)=>{m.properties.url=`#gid=${e}&range=${y?R.serializeRange(y):x}`}))}}),a.setValue(n,r,u)}}_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 p=a.getValue(d,c);p&&p.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===g.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 p=a.getValue(d,c);p&&p.dispose(),l&&l.p&&this._registerRange(n,r,d,c,l.p)})}}))}};K=De([te(0,o.ICommandService),te(1,o.IUniverInstanceService),te(2,o.Inject(g.RefRangeService))],K);var Ve=Object.defineProperty,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=(n?a(t,e,r):a(r))||r);return n&&r&&Ve(t,e,r),r},B=(i,t)=>(e,n)=>t(e,n,i);let Y=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===g.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:U.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===g.ClearSelectionContentCommand.id||i.id===g.ClearSelectionAllCommand.id||i.id===g.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),r=g.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:U.id,params:{unitId:s,subUnitId:a,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(g.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)}}))}};Y=$e([B(0,o.Inject(g.SheetInterceptorService)),B(1,o.Inject(exports.HyperLinkModel)),B(2,o.Inject(g.SheetsSelectionsService)),B(3,o.IUniverInstanceService)],Y);const ce={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(g.SheetInterceptorService),d=g.getSheetCommandTarget(r,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:p,worksheet:u}=d,{link:m}=t,{payload:_,display:h,row:f,column:M,id:y}=m,E=u.getCell(f,M),v=u.getBlankCellDocumentModel(E),C=v.documentModel.getSnapshot(),S=o.Tools.deepClone(C.body);if(!S)return!1;let k;if(h?k=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:S.dataStream.length-2,collapsed:!0},body:{dataStream:`${h}`,customRanges:[{startIndex:0,endIndex:h.length-1,rangeType:o.CustomRangeType.HYPERLINK,rangeId:y,properties:{url:_}}]},doc:v.documentModel}):k=o.BuildTextUtils.customRange.add({body:S,range:{startOffset:0,endOffset:S.dataStream.length-2,collapsed:!1},rangeId:y,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:_,refId:y}}),!k)return!1;const D=o.TextX.apply(S,k.serialize()),b={p:{...C,body:D},t:o.CellValueType.STRING},H=await a.onWriteCell(p,u,f,M,b),T={unitId:c,subUnitId:l,cellValue:{[m.row]:{[m.column]:H}}},Z={id:g.SetRangeValuesMutation.id,params:T},$=g.SetRangeValuesUndoMutationFactory(i,T),Q={id:g.SetRangeValuesMutation.id,params:$},V=[Z],N=[Q],O=s.getHyperLinkByLocation(c,l,f,M);return O&&(V.push({id:w.id,params:{unitId:c,subUnitId:l,id:O.id}}),N.push({id:U.id,params:{unitId:c,subUnitId:l,link:O}})),await o.sequenceExecuteAsync(V,e)?(n.pushUndoRedo({redoMutations:V,undoMutations:N,unitID:c}),!0):!1}},le={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=X.addCustomRangeBySelectionFactory(i,{unitId:e,rangeId:s,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:a,refId:s}});return d?r.syncExecuteCommand(d.id,d.params):!1}},pe={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=g.getSheetCommandTarget(r,t);if(!a)return!1;const{row:d,column:c,id:l}=t,{unitId:p,subUnitId:u,worksheet:m}=a,_=m.getCell(d,c);if(!_)return!1;const h=m.getCellDocumentModelWithFormula(_);if(!(h!=null&&h.documentModel))return!1;const f=o.Tools.deepClone(h.documentModel.getSnapshot());if(!((H=(b=f.body)==null?void 0:b.customRanges)==null?void 0:H.find(T=>T.rangeId===l)))return!1;const y=o.BuildTextUtils.customRange.delete(i,{documentDataModel:h.documentModel,rangeId:l});if(!y)return!1;const E=o.TextX.apply(f.body,y.serialize()),v=[],C=[],S={unitId:p,subUnitId:u,cellValue:{[d]:{[c]:{p:{...f,body:E},t:o.CellValueType.STRING}}}};v.push({id:g.SetRangeValuesMutation.id,params:S});const k=g.SetRangeValuesUndoMutationFactory(i,S);C.push({id:g.SetRangeValuesMutation.id,params:k});const D=s.getHyperLinkByLocation(p,u,d,c);return D&&(v.push({id:w.id,params:{unitId:p,subUnitId:u,id:l}}),C.push({id:U.id,params:{unitId:p,subUnitId:u,link:{...D}}})),o.sequenceExecute(v,e).result?(n.pushUndoRedo({redoMutations:v,undoMutations:C,unitID:p}),!0):!1}},ue={type:o.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(i,t){var p,u;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=(u=(p=a==null?void 0:a.getBody())==null?void 0:p.customRanges)==null?void 0:u.find(m=>m.rangeId===e);let c=null;d&&d.endIndex===a.getBody().dataStream.length-3&&(c={dataStream:" "});const l=X.deleteCustomRangeFactory(i,{unitId:n,rangeId:e,insert:c});return l?r.syncExecuteCommand(l.id,l.params):!1}},he={type:o.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(i,t){var re,ie,se;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(g.SheetInterceptorService),d=g.getSheetCommandTarget(r);if(!d)return!1;const{payload:c,row:l,column:p,id:u}=t,{workbook:m,worksheet:_,unitId:h,subUnitId:f}=d,{payload:M,display:y=""}=c,E=_.getCell(l,p);if(!E)return!1;const v=_.getCellDocumentModelWithFormula(E);if(!(v!=null&&v.documentModel))return!1;const C=v.documentModel.getSnapshot(),S=(ie=(re=C.body)==null?void 0:re.customRanges)==null?void 0:ie.find(ye=>ye.rangeId===u);if(!S)return!1;const k=o.generateRandomId(),P=(se=o.getBodySlice(v.documentModel.getBody(),S.startIndex,S.endIndex+1).textRuns)==null?void 0:se[0];P&&(P.ed=y.length+1);const b=X.replaceSelectionFactory(i,{unitId:h,body:{dataStream:`${y}`,customRanges:[{rangeId:k,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:y.length-1,properties:{url:M}}],textRuns:P?[P]:void 0},selection:{startOffset:S.startIndex,endOffset:S.endIndex+1,collapsed:!1},doc:v.documentModel});if(!b)return!1;const H=o.TextX.apply(o.Tools.deepClone(C.body),b.textX.serialize()),T={p:{...C,body:H},t:o.CellValueType.STRING},Z=await a.onWriteCell(m,_,l,p,T),$={id:g.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:f,cellValue:{[l]:{[p]:Z}}}},Q=g.SetRangeValuesUndoMutationFactory(i,$.params),V={id:g.SetRangeValuesMutation.id,params:Q},N=[$],O=[V],j=s.getHyperLinkByLocation(h,f,l,p);return j&&(N.push({id:w.id,params:{unitId:h,subUnitId:f,id:j.id}}),O.push({id:U.id,params:{unitId:h,subUnitId:f,link:j}})),await o.sequenceExecuteAsync(N,e)?(n.pushUndoRedo({redoMutations:N,undoMutations:O,unitID:h}),!0):!1}},ge={type:o.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(i,t)=>{var h,f,M,y;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=(h=d.getBody())==null?void 0:h.customRanges)==null?void 0:f.find(E=>E.rangeId===r);if(!c)return!1;const l=(M=t.payload.display)!=null?M:"",p=o.generateRandomId(),m=(y=o.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:y[0];m&&(m.ed=l.length+1);const _=X.replaceSelectionFactory(i,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:p,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 _?a.syncExecuteCommand(_.id,_.params):!1}};var je=Object.defineProperty,Ae=Object.getOwnPropertyDescriptor,Be=(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=(n?a(t,e,r):a(r))||r);return n&&r&&je(t,e,r),r},We=(i,t)=>(e,n)=>t(e,n,i);let q=class extends o.Disposable{constructor(i){super(),this._commandService=i,this._registerCommands()}_registerCommands(){[ce,he,pe,ge,ue,le,U,W,w,F].forEach(i=>{this._commandService.registerCommand(i)})}};q=Be([We(0,o.ICommandService)],q);var me=(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))(me||{}),Fe=Object.defineProperty,ze=Object.getOwnPropertyDescriptor,Ge=(i,t,e,n)=>{for(var r=n>1?void 0:n?ze(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Fe(t,e,r),r},ae=(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:de,businesses:[me.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=Ge([ae(0,o.IResourceManagerService),ae(1,o.Inject(exports.HyperLinkModel))],J);var Ke=Object.defineProperty,Ye=Object.getOwnPropertyDescriptor,qe=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ye(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Ke(t,e,r),r},ne=(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`#${L.SHEET}=${e}${n?`&${typeof n=="string"?L.DEFINE_NAME:L.RANGE}=${typeof n=="string"?n:R.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:L.URL,name:t,url:t,searchObj:null}}_getURLName(t){var p;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:L.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!a)return d;const c=e?a.getSheetBySheetId(e):a.getActiveSheet(),l=(p=c==null?void 0:c.getName())!=null?p:"";if(n){if(!c)return d;const u=R.deserializeRangeWithSheet(n).range;return o.isValidRange(u,c)&&n!==x?{type:L.RANGE,name:R.serializeRangeWithSheet(l,u)}:d}if(r){const u=this._definedNamesService.getValueById(a.getUnitId(),r);return u?{type:L.DEFINE_NAME,name:u.formulaOrRefString}:d}if(e){const u=a.getSheetBySheetId(e);return u?{type:L.SHEET,name:u.getName()}:d}return d}};exports.SheetsHyperLinkParserService=qe([ne(0,o.IUniverInstanceService),ne(1,o.Inject(o.LocaleService)),ne(2,R.IDefinedNamesService)],exports.SheetsHyperLinkParserService);var _e=Object.defineProperty,Je=Object.getOwnPropertyDescriptor,Xe=(i,t,e)=>t in i?_e(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?Je(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&_e(t,e,r),r},oe=(i,t)=>(e,n)=>t(e,n,i),fe=(i,t,e)=>Xe(i,typeof t!="symbol"?t+"":t,e);exports.UniverSheetsHyperLinkPlugin=class extends o.Plugin{constructor(t=we,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...r}=this._config;this._configService.setConfig(Ue,r)}onStarting(){o.registerDependencies(this._injector,[[exports.HyperLinkModel],[exports.SheetsHyperLinkParserService],[J],[q],[z],[Y],[G],[K]]),o.touchDependencies(this._injector,[[z],[J],[q],[Y],[G],[K]])}};fe(exports.UniverSheetsHyperLinkPlugin,"pluginName",de);fe(exports.UniverSheetsHyperLinkPlugin,"type",o.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsHyperLinkPlugin=Ze([o.DependentOn(g.UniverSheetsPlugin),oe(1,o.Inject(o.Injector)),oe(2,o.IConfigService)],exports.UniverSheetsHyperLinkPlugin);exports.AddHyperLinkCommand=ce;exports.AddHyperLinkMutation=U;exports.AddRichHyperLinkCommand=le;exports.CancelHyperLinkCommand=pe;exports.CancelRichHyperLinkCommand=ue;exports.ERROR_RANGE=x;exports.RemoveHyperLinkMutation=w;exports.SheetHyperLinkType=L;exports.UpdateHyperLinkCommand=he;exports.UpdateHyperLinkMutation=W;exports.UpdateHyperLinkRefMutation=F;exports.UpdateRichHyperLinkCommand=ge;
1
+ "use strict";var ve=Object.defineProperty;var Se=(i,t,e)=>t in i?ve(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var M=(i,t,e)=>Se(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),Ie=require("rxjs"),g=require("@univerjs/sheets"),C=require("@univerjs/engine-formula"),X=require("@univerjs/docs");var Re=Object.defineProperty,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=(n?a(t,e,r):a(r))||r);return n&&r&&Re(t,e,r),r},Le=(i,t)=>(e,n)=>t(e,n,i);exports.HyperLinkModel=class extends o.Disposable{constructor(e){super();M(this,"_linkUpdate$",new Ie.Subject);M(this,"linkUpdate$",this._linkUpdate$.asObservable());M(this,"_linkMap",new Map);M(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 p=d.getValue(l.row,l.column);return p&&(Object.assign(p,s),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:p.display,payload:p.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 p=d.getValue(l.row,l.column);return!p||p.id!==r?p=l.link:d.realDeleteValue(l.row,l.column),Object.assign(p,s),c.set(r,{...s,link:p}),d.setValue(s.row,s.column,p),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 u,m,f,h,_;const{matrix:a}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,o.UniverInstanceType.UNIVER_SHEET),c=(u=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:u.getCellRaw(r,s),l=((_=(h=c==null?void 0:c.v)!=null?h:(f=(m=c==null?void 0:c.p)==null?void 0:m.body)==null?void 0:f.dataStream.slice(0,-2))!=null?_:"").toString(),p=a.getValue(r,s);if(p)return{...p,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([Le(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",we={},w={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)}},W={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)}},F={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)}},de="SHEET_HYPER_LINK_PLUGIN",x="err";var Ee=Object.defineProperty,be=Object.getOwnPropertyDescriptor,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=(n?a(t,e,r):a(r))||r);return n&&r&&Ee(t,e,r),r},A=(i,t)=>(e,n)=>t(e,n,i);let z=class extends o.Disposable{constructor(t,e,n,r){super();M(this,"_disposableMap",new Map);M(this,"_watchDisposableMap",new Map);M(this,"_rangeDisableMap",new Map);M(this,"_rangeWatcherMap",new Map);M(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:F.id,params:{unitId:t,subUnitId:e,id:n.id,row:r.startRow,column:r.startColumn,silent:s}}],undos:[{id:F.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:w.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=g.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 p=l.gid,u=C.deserializeRangeWithSheet(l.range).range;if(o.isValidRange(u)&&l.range!==x){const m=f=>{const h=g.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(u,f,{selectionManagerService:this._selectionManagerService});return h&&C.serializeRange(h)===C.serializeRange(u)?{redos:[],undos:[]}:{redos:[{id:W.id,params:{unitId:t,subUnitId:p,id:e,payload:{payload:`#gid=${p}&range=${h?C.serializeRange(h):"err"}`}}}],undos:[{id:W.id,params:{unitId:t,subUnitId:p,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(u,m,t,p)),r||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,p,u,(f,h)=>{this._hyperLinkModel.updateHyperLink(t,p,e,{payload:`#gid=${p}&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: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=ke([A(0,o.Inject(g.RefRangeService)),A(1,o.Inject(exports.HyperLinkModel)),A(2,o.Inject(g.SheetsSelectionsService)),A(3,o.ICommandService)],z);var Pe=Object.defineProperty,He=Object.getOwnPropertyDescriptor,Te=(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=(n?a(t,e,r):a(r))||r);return n&&r&&Pe(t,e,r),r},ee=(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===g.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:w.id,params:{unitId:r,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};G=Te([ee(0,o.Inject(g.SheetInterceptorService)),ee(1,o.IUniverInstanceService),ee(2,o.Inject(exports.HyperLinkModel))],G);var Ne=Object.defineProperty,Oe=Object.getOwnPropertyDescriptor,De=(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=(n?a(t,e,r):a(r))||r);return n&&r&&Ne(t,e,r),r},te=(i,t)=>(e,n)=>t(e,n,i);let K=class extends o.Disposable{constructor(t,e,n){super();M(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,p=n.getSheetBySheetId(l);if(!p)return null;const u=C.deserializeRangeWithSheet(c.range).range;if(o.isValidRange(u,p)&&c.range!==x)return u}}return null}_registerRange(t,e,n,r,s){var d,c,l,p;const a=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(u=>{var m;return u.rangeType===o.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(m=u.properties)==null?void 0:m.url)})){const u=new o.DisposableCollection;let m=!1;(p=(l=s.body)==null?void 0:l.customRanges)==null||p.forEach(f=>{var h;if(f.rangeType===o.CustomRangeType.HYPERLINK){const _=(h=f.properties)==null?void 0:h.url,I=this._isLegalRangeUrl(t,_);I&&(m=!0,u.add(this._refRangeService.watchRange(t,e,I,(y,R)=>{f.properties.url=`#gid=${e}&range=${R?C.serializeRange(R):x}`})))}}),m&&a.setValue(n,r,u)}}_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 p=a.getValue(d,c);p&&p.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===g.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 p=a.getValue(d,c);p&&p.dispose(),l&&l.p&&this._registerRange(n,r,d,c,l.p)})}}))}};K=De([te(0,o.ICommandService),te(1,o.IUniverInstanceService),te(2,o.Inject(g.RefRangeService))],K);var Ve=Object.defineProperty,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=(n?a(t,e,r):a(r))||r);return n&&r&&Ve(t,e,r),r},B=(i,t)=>(e,n)=>t(e,n,i);let Y=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===g.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:w.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===g.ClearSelectionContentCommand.id||i.id===g.ClearSelectionAllCommand.id||i.id===g.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),r=g.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:w.id,params:{unitId:s,subUnitId:a,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(g.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)}}))}};Y=$e([B(0,o.Inject(g.SheetInterceptorService)),B(1,o.Inject(exports.HyperLinkModel)),B(2,o.Inject(g.SheetsSelectionsService)),B(3,o.IUniverInstanceService)],Y);const ce={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(g.SheetInterceptorService),d=g.getSheetCommandTarget(r,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:p,worksheet:u}=d,{link:m}=t,{payload:f,display:h,row:_,column:I,id:y}=m,R=u.getCell(_,I),v=u.getBlankCellDocumentModel(R),L=v.documentModel.getSnapshot(),S=o.Tools.deepClone(L.body);if(!S)return!1;let b;if(h?b=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:S.dataStream.length-2,collapsed:!0},body:{dataStream:`${h}`,customRanges:[{startIndex:0,endIndex:h.length-1,rangeType:o.CustomRangeType.HYPERLINK,rangeId:y,properties:{url:f}}]},doc:v.documentModel}):b=o.BuildTextUtils.customRange.add({body:S,range:{startOffset:0,endOffset:S.dataStream.length-2,collapsed:!1},rangeId:y,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:f,refId:y}}),!b)return!1;const D=o.TextX.apply(S,b.serialize()),k={p:{...L,body:D},t:o.CellValueType.STRING},H=await a.onWriteCell(p,u,_,I,k),T={unitId:c,subUnitId:l,cellValue:{[m.row]:{[m.column]:H}}},Z={id:g.SetRangeValuesMutation.id,params:T},$=g.SetRangeValuesUndoMutationFactory(i,T),Q={id:g.SetRangeValuesMutation.id,params:$},V=[Z],N=[Q],O=s.getHyperLinkByLocation(c,l,_,I);return O&&(V.push({id:E.id,params:{unitId:c,subUnitId:l,id:O.id}}),N.push({id:w.id,params:{unitId:c,subUnitId:l,link:O}})),await o.sequenceExecuteAsync(V,e)?(n.pushUndoRedo({redoMutations:V,undoMutations:N,unitID:c}),!0):!1}},le={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=X.addCustomRangeBySelectionFactory(i,{unitId:e,rangeId:s,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:a,refId:s}});return d?r.syncExecuteCommand(d.id,d.params):!1}},pe={type:o.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(i,t){var k,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=g.getSheetCommandTarget(r,t);if(!a)return!1;const{row:d,column:c,id:l}=t,{unitId:p,subUnitId:u,worksheet:m}=a,f=m.getCell(d,c);if(!f)return!1;const h=m.getCellDocumentModelWithFormula(f);if(!(h!=null&&h.documentModel))return!1;const _=o.Tools.deepClone(h.documentModel.getSnapshot());if(!((H=(k=_.body)==null?void 0:k.customRanges)==null?void 0:H.find(T=>T.rangeId===l)))return!1;const y=o.BuildTextUtils.customRange.delete(i,{documentDataModel:h.documentModel,rangeId:l});if(!y)return!1;const R=o.TextX.apply(_.body,y.serialize()),v=[],L=[],S={unitId:p,subUnitId:u,cellValue:{[d]:{[c]:{p:{..._,body:R},t:o.CellValueType.STRING}}}};v.push({id:g.SetRangeValuesMutation.id,params:S});const b=g.SetRangeValuesUndoMutationFactory(i,S);L.push({id:g.SetRangeValuesMutation.id,params:b});const D=s.getHyperLinkByLocation(p,u,d,c);return D&&(v.push({id:E.id,params:{unitId:p,subUnitId:u,id:l}}),L.push({id:w.id,params:{unitId:p,subUnitId:u,link:{...D}}})),o.sequenceExecute(v,e).result?(n.pushUndoRedo({redoMutations:v,undoMutations:L,unitID:p}),!0):!1}},ue={type:o.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(i,t){var p,u;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=(u=(p=a==null?void 0:a.getBody())==null?void 0:p.customRanges)==null?void 0:u.find(m=>m.rangeId===e);let c=null;d&&d.endIndex===a.getBody().dataStream.length-3&&(c={dataStream:" "});const l=X.deleteCustomRangeFactory(i,{unitId:n,rangeId:e,insert:c});return l?r.syncExecuteCommand(l.id,l.params):!1}},he={type:o.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(i,t){var re,ie,se;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(g.SheetInterceptorService),d=g.getSheetCommandTarget(r,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:p,id:u}=t,{workbook:m,worksheet:f,unitId:h,subUnitId:_}=d,{payload:I,display:y=""}=c,R=f.getCell(l,p);if(!R)return!1;const v=f.getCellDocumentModelWithFormula(R);if(!(v!=null&&v.documentModel))return!1;const L=v.documentModel.getSnapshot(),S=(ie=(re=L.body)==null?void 0:re.customRanges)==null?void 0:ie.find(ye=>ye.rangeId===u);if(!S)return!1;const b=o.generateRandomId(),P=(se=o.getBodySlice(v.documentModel.getBody(),S.startIndex,S.endIndex+1).textRuns)==null?void 0:se[0];P&&(P.ed=y.length+1);const k=X.replaceSelectionFactory(i,{unitId:h,body:{dataStream:`${y}`,customRanges:[{rangeId:b,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:y.length-1,properties:{url:I}}],textRuns:P?[P]:void 0},selection:{startOffset:S.startIndex,endOffset:S.endIndex+1,collapsed:!1},doc:v.documentModel});if(!k)return!1;const H=o.TextX.apply(o.Tools.deepClone(L.body),k.textX.serialize()),T={p:{...L,body:H},t:o.CellValueType.STRING},Z=await a.onWriteCell(m,f,l,p,T),$={id:g.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:_,cellValue:{[l]:{[p]:Z}}}},Q=g.SetRangeValuesUndoMutationFactory(i,$.params),V={id:g.SetRangeValuesMutation.id,params:Q},N=[$],O=[V],j=s.getHyperLinkByLocation(h,_,l,p);return j&&(N.push({id:E.id,params:{unitId:h,subUnitId:_,id:j.id}}),O.push({id:w.id,params:{unitId:h,subUnitId:_,link:j}})),await o.sequenceExecuteAsync(N,e)?(n.pushUndoRedo({redoMutations:N,undoMutations:O,unitID:h}),!0):!1}},ge={type:o.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(i,t)=>{var h,_,I,y;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=(_=(h=d.getBody())==null?void 0:h.customRanges)==null?void 0:_.find(R=>R.rangeId===r);if(!c)return!1;const l=(I=t.payload.display)!=null?I:"",p=o.generateRandomId(),m=(y=o.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:y[0];m&&(m.ed=l.length+1);const f=X.replaceSelectionFactory(i,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:p,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 je=Object.defineProperty,Ae=Object.getOwnPropertyDescriptor,Be=(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=(n?a(t,e,r):a(r))||r);return n&&r&&je(t,e,r),r},We=(i,t)=>(e,n)=>t(e,n,i);let q=class extends o.Disposable{constructor(i){super(),this._commandService=i,this._registerCommands()}_registerCommands(){[ce,he,pe,ge,ue,le,w,W,E,F].forEach(i=>{this._commandService.registerCommand(i)})}};q=Be([We(0,o.ICommandService)],q);var me=(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))(me||{}),Fe=Object.defineProperty,ze=Object.getOwnPropertyDescriptor,Ge=(i,t,e,n)=>{for(var r=n>1?void 0:n?ze(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Fe(t,e,r),r},ae=(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:de,businesses:[me.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=Ge([ae(0,o.IResourceManagerService),ae(1,o.Inject(exports.HyperLinkModel))],J);var Ke=Object.defineProperty,Ye=Object.getOwnPropertyDescriptor,qe=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ye(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Ke(t,e,r),r},ne=(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:C.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 p;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=(p=c==null?void 0:c.getName())!=null?p:"";if(n){if(!c)return d;const u=C.deserializeRangeWithSheet(n).range;return o.isValidRange(u,c)&&n!==x?{type:U.RANGE,name:C.serializeRangeWithSheet(l,u)}:d}if(r){const u=this._definedNamesService.getValueById(a.getUnitId(),r);return u?{type:U.DEFINE_NAME,name:u.formulaOrRefString}:d}if(e){const u=a.getSheetBySheetId(e);return u?{type:U.SHEET,name:u.getName()}:d}return d}};exports.SheetsHyperLinkParserService=qe([ne(0,o.IUniverInstanceService),ne(1,o.Inject(o.LocaleService)),ne(2,C.IDefinedNamesService)],exports.SheetsHyperLinkParserService);var fe=Object.defineProperty,Je=Object.getOwnPropertyDescriptor,Xe=(i,t,e)=>t in i?fe(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?Je(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&fe(t,e,r),r},oe=(i,t)=>(e,n)=>t(e,n,i),_e=(i,t,e)=>Xe(i,typeof t!="symbol"?t+"":t,e);exports.UniverSheetsHyperLinkPlugin=class extends o.Plugin{constructor(t=we,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...r}=this._config;this._configService.setConfig(Ue,r)}onStarting(){o.registerDependencies(this._injector,[[exports.HyperLinkModel],[exports.SheetsHyperLinkParserService],[J],[q],[z],[Y],[G],[K]]),o.touchDependencies(this._injector,[[z],[J],[q],[Y],[G],[K]])}};_e(exports.UniverSheetsHyperLinkPlugin,"pluginName",de);_e(exports.UniverSheetsHyperLinkPlugin,"type",o.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsHyperLinkPlugin=Ze([o.DependentOn(g.UniverSheetsPlugin),oe(1,o.Inject(o.Injector)),oe(2,o.IConfigService)],exports.UniverSheetsHyperLinkPlugin);exports.AddHyperLinkCommand=ce;exports.AddHyperLinkMutation=w;exports.AddRichHyperLinkCommand=le;exports.CancelHyperLinkCommand=pe;exports.CancelRichHyperLinkCommand=ue;exports.ERROR_RANGE=x;exports.RemoveHyperLinkMutation=E;exports.SheetHyperLinkType=U;exports.UpdateHyperLinkCommand=he;exports.UpdateHyperLinkMutation=W;exports.UpdateHyperLinkRefMutation=F;exports.UpdateRichHyperLinkCommand=ge;
package/lib/es/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var xe = Object.defineProperty;
2
2
  var Te = (s, e, t) => e in s ? xe(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
- var I = (s, e, t) => Te(s, typeof e != "symbol" ? e + "" : e, t);
4
- import { Disposable as V, ObjectMatrix as J, UniverInstanceType as S, IUniverInstanceService as w, CommandType as E, Inject as R, ICommandService as U, sequenceExecuteAsync as ye, isValidRange as ve, toDisposable as Ae, CustomRangeType as N, DisposableCollection as We, Range as Be, Tools as ie, BuildTextUtils as X, generateRandomId as ae, TextX as oe, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as je, IUndoRedoService as Se, CellValueType as Re, sequenceExecute as Fe, getBodySlice as be, IResourceManagerService as Ke, LocaleService as Ge, DependentOn as Ye, Injector as ze, Plugin as Je, registerDependencies as Xe, touchDependencies as qe, IConfigService as Ze } from "@univerjs/core";
3
+ var C = (s, e, t) => Te(s, typeof e != "symbol" ? e + "" : e, t);
4
+ import { Disposable as V, ObjectMatrix as J, UniverInstanceType as R, IUniverInstanceService as E, CommandType as L, Inject as I, ICommandService as b, sequenceExecuteAsync as ye, isValidRange as ve, toDisposable as Ae, CustomRangeType as N, DisposableCollection as We, Range as Be, Tools as ie, BuildTextUtils as X, generateRandomId as ae, TextX as oe, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as je, IUndoRedoService as Se, CellValueType as Re, sequenceExecute as Fe, getBodySlice as be, IResourceManagerService as Ke, LocaleService as Ge, DependentOn as Ye, Injector as ze, Plugin as Je, registerDependencies as Xe, touchDependencies as qe, IConfigService as Ze } from "@univerjs/core";
5
5
  import { Subject as Qe } from "rxjs";
6
6
  import { RefRangeService as Pe, SheetsSelectionsService as Ne, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as et, handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests as tt, SheetInterceptorService as de, RemoveSheetCommand as nt, SetRangeValuesMutation as H, SetRangeValuesCommand as rt, ClearSelectionContentCommand as st, ClearSelectionAllCommand as it, ClearSelectionFormatCommand as at, getSheetCommandTarget as ce, AFTER_CELL_EDIT as ot, SetRangeValuesUndoMutationFactory as Ie, UniverSheetsPlugin as dt } from "@univerjs/sheets";
7
7
  import { deserializeRangeWithSheet as Me, serializeRange as B, serializeRangeWithSheet as ct, IDefinedNamesService as lt } from "@univerjs/engine-formula";
@@ -14,10 +14,10 @@ var ht = Object.defineProperty, gt = Object.getOwnPropertyDescriptor, ft = (s, e
14
14
  let v = class extends V {
15
15
  constructor(e) {
16
16
  super();
17
- I(this, "_linkUpdate$", new Qe());
18
- I(this, "linkUpdate$", this._linkUpdate$.asObservable());
19
- I(this, "_linkMap", /* @__PURE__ */ new Map());
20
- I(this, "_linkPositionMap", /* @__PURE__ */ new Map());
17
+ C(this, "_linkUpdate$", new Qe());
18
+ C(this, "linkUpdate$", this._linkUpdate$.asObservable());
19
+ C(this, "_linkMap", /* @__PURE__ */ new Map());
20
+ C(this, "_linkPositionMap", /* @__PURE__ */ new Map());
21
21
  this._univerInstanceService = e, this.disposeWithMe({
22
22
  dispose: () => {
23
23
  this._linkUpdate$.complete();
@@ -100,8 +100,8 @@ let v = class extends V {
100
100
  return i.getValue(n, r);
101
101
  }
102
102
  getHyperLinkByLocationSync(e, t, n, r) {
103
- var l, u, h, g, p;
104
- const { matrix: i } = this._ensureMap(e, t), a = this._univerInstanceService.getUnit(e, S.UNIVER_SHEET), o = (l = a == null ? void 0 : a.getSheetBySheetId(t)) == null ? void 0 : l.getCellRaw(n, r), c = ((p = (g = o == null ? void 0 : o.v) != null ? g : (h = (u = o == null ? void 0 : o.p) == null ? void 0 : u.body) == null ? void 0 : h.dataStream.slice(0, -2)) != null ? p : "").toString(), d = i.getValue(n, r);
103
+ var l, p, h, g, u;
104
+ const { matrix: i } = this._ensureMap(e, t), a = this._univerInstanceService.getUnit(e, R.UNIVER_SHEET), o = (l = a == null ? void 0 : a.getSheetBySheetId(t)) == null ? void 0 : l.getCellRaw(n, r), c = ((u = (g = o == null ? void 0 : o.v) != null ? g : (h = (p = o == null ? void 0 : o.p) == null ? void 0 : p.body) == null ? void 0 : h.dataStream.slice(0, -2)) != null ? u : "").toString(), d = i.getValue(n, r);
105
105
  if (d)
106
106
  return {
107
107
  ...d,
@@ -138,11 +138,11 @@ let v = class extends V {
138
138
  }
139
139
  };
140
140
  v = ft([
141
- _t(0, w)
141
+ _t(0, E)
142
142
  ], v);
143
- var L = /* @__PURE__ */ ((s) => (s.SHEET = "gid", s.RANGE = "range", s.DEFINE_NAME = "rangeid", s.INVALID = "invalid", s.URL = "url", s))(L || {});
143
+ var U = /* @__PURE__ */ ((s) => (s.SHEET = "gid", s.RANGE = "range", s.DEFINE_NAME = "rangeid", s.INVALID = "invalid", s.URL = "url", s))(U || {});
144
144
  const mt = "sheets-hyper-link.config", yt = {}, O = {
145
- type: E.MUTATION,
145
+ type: L.MUTATION,
146
146
  id: "sheets.mutation.add-hyper-link",
147
147
  handler(s, e) {
148
148
  if (!e)
@@ -151,7 +151,7 @@ const mt = "sheets-hyper-link.config", yt = {}, O = {
151
151
  return t.addHyperLink(n, r, i);
152
152
  }
153
153
  }, k = {
154
- type: E.MUTATION,
154
+ type: L.MUTATION,
155
155
  id: "sheets.mutation.remove-hyper-link",
156
156
  handler(s, e) {
157
157
  if (!e)
@@ -160,7 +160,7 @@ const mt = "sheets-hyper-link.config", yt = {}, O = {
160
160
  return t.removeHyperLink(n, r, i);
161
161
  }
162
162
  }, fe = {
163
- type: E.MUTATION,
163
+ type: L.MUTATION,
164
164
  id: "sheets.mutation.update-hyper-link",
165
165
  handler(s, e) {
166
166
  if (!e)
@@ -169,7 +169,7 @@ const mt = "sheets-hyper-link.config", yt = {}, O = {
169
169
  return t.updateHyperLink(n, r, a, i, !1);
170
170
  }
171
171
  }, _e = {
172
- type: E.MUTATION,
172
+ type: L.MUTATION,
173
173
  id: "sheets.mutation.update-hyper-link-ref",
174
174
  handler(s, e) {
175
175
  if (!e)
@@ -186,11 +186,11 @@ var vt = Object.defineProperty, St = Object.getOwnPropertyDescriptor, Rt = (s, e
186
186
  let Z = class extends V {
187
187
  constructor(e, t, n, r) {
188
188
  super();
189
- I(this, "_disposableMap", /* @__PURE__ */ new Map());
190
- I(this, "_watchDisposableMap", /* @__PURE__ */ new Map());
191
- I(this, "_rangeDisableMap", /* @__PURE__ */ new Map());
192
- I(this, "_rangeWatcherMap", /* @__PURE__ */ new Map());
193
- I(this, "_handlePositionChange", (e, t, n, r, i) => {
189
+ C(this, "_disposableMap", /* @__PURE__ */ new Map());
190
+ C(this, "_watchDisposableMap", /* @__PURE__ */ new Map());
191
+ C(this, "_rangeDisableMap", /* @__PURE__ */ new Map());
192
+ C(this, "_rangeWatcherMap", /* @__PURE__ */ new Map());
193
+ C(this, "_handlePositionChange", (e, t, n, r, i) => {
194
194
  const a = {
195
195
  startColumn: n.column,
196
196
  endColumn: n.column,
@@ -288,11 +288,11 @@ let Z = class extends V {
288
288
  rangeid: (o = c.get("rangeid")) != null ? o : ""
289
289
  };
290
290
  if (d.range && d.gid) {
291
- const l = d.gid, u = Me(d.range).range;
292
- if (ve(u) && d.range !== q) {
291
+ const l = d.gid, p = Me(d.range).range;
292
+ if (ve(p) && d.range !== q) {
293
293
  const h = (g) => {
294
- const p = tt(u, g, { selectionManagerService: this._selectionManagerService });
295
- return p && B(p) === B(u) ? {
294
+ const u = tt(p, g, { selectionManagerService: this._selectionManagerService });
295
+ return u && B(u) === B(p) ? {
296
296
  redos: [],
297
297
  undos: []
298
298
  } : {
@@ -303,7 +303,7 @@ let Z = class extends V {
303
303
  subUnitId: l,
304
304
  id: t,
305
305
  payload: {
306
- payload: `#gid=${l}&range=${p ? B(p) : "err"}`
306
+ payload: `#gid=${l}&range=${u ? B(u) : "err"}`
307
307
  }
308
308
  }
309
309
  }],
@@ -320,9 +320,9 @@ let Z = class extends V {
320
320
  }]
321
321
  };
322
322
  };
323
- this._rangeDisableMap.set(t, this._refRangeService.registerRefRange(u, h, e, l)), r || this._rangeWatcherMap.set(t, this._refRangeService.watchRange(e, l, u, (g, p) => {
323
+ this._rangeDisableMap.set(t, this._refRangeService.registerRefRange(p, h, e, l)), r || this._rangeWatcherMap.set(t, this._refRangeService.watchRange(e, l, p, (g, u) => {
324
324
  this._hyperLinkModel.updateHyperLink(e, l, t, {
325
- payload: `#gid=${l}&range=${p ? B(p) : "err"}`
325
+ payload: `#gid=${l}&range=${u ? B(u) : "err"}`
326
326
  }, !0);
327
327
  }, !0));
328
328
  }
@@ -390,10 +390,10 @@ let Z = class extends V {
390
390
  }
391
391
  };
392
392
  Z = Rt([
393
- Y(0, R(Pe)),
394
- Y(1, R(v)),
395
- Y(2, R(Ne)),
396
- Y(3, U)
393
+ Y(0, I(Pe)),
394
+ Y(1, I(v)),
395
+ Y(2, I(Ne)),
396
+ Y(3, b)
397
397
  ], Z);
398
398
  var It = Object.defineProperty, Mt = Object.getOwnPropertyDescriptor, Ct = (s, e, t, n) => {
399
399
  for (var r = n > 1 ? void 0 : n ? Mt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
@@ -410,7 +410,7 @@ let Q = class extends V {
410
410
  getMutations: (s) => {
411
411
  var e;
412
412
  if (s.id === nt.id) {
413
- const t = s.params, n = t.unitId ? this._univerInstanceService.getUnit(t.unitId) : this._univerInstanceService.getCurrentUnitForType(S.UNIVER_SHEET);
413
+ const t = s.params, n = t.unitId ? this._univerInstanceService.getUnit(t.unitId) : this._univerInstanceService.getCurrentUnitForType(R.UNIVER_SHEET);
414
414
  if (!n)
415
415
  return { redos: [], undos: [] };
416
416
  const r = n.getUnitId(), i = t.subUnitId || ((e = n.getActiveSheet()) == null ? void 0 : e.getSheetId());
@@ -440,9 +440,9 @@ let Q = class extends V {
440
440
  }
441
441
  };
442
442
  Q = Ct([
443
- pe(0, R(de)),
444
- pe(1, w),
445
- pe(2, R(v))
443
+ pe(0, I(de)),
444
+ pe(1, E),
445
+ pe(2, I(v))
446
446
  ], Q);
447
447
  var wt = Object.defineProperty, Et = Object.getOwnPropertyDescriptor, Lt = (s, e, t, n) => {
448
448
  for (var r = n > 1 ? void 0 : n ? Et(e, t) : e, i = s.length - 1, a; i >= 0; i--)
@@ -452,7 +452,7 @@ var wt = Object.defineProperty, Et = Object.getOwnPropertyDescriptor, Lt = (s, e
452
452
  let ee = class extends V {
453
453
  constructor(e, t, n) {
454
454
  super();
455
- I(this, "_refRangeMap", /* @__PURE__ */ new Map());
455
+ C(this, "_refRangeMap", /* @__PURE__ */ new Map());
456
456
  this._commandService = e, this._univerInstanceService = t, this._refRangeService = n, this._initWorkbookLoad(), this._initWorkbookUnload(), this._initSetRangesListener();
457
457
  }
458
458
  _enusreMap(e, t) {
@@ -463,7 +463,7 @@ let ee = class extends V {
463
463
  }
464
464
  _isLegalRangeUrl(e, t) {
465
465
  var r, i, a;
466
- const n = this._univerInstanceService.getUnit(e, S.UNIVER_SHEET);
466
+ const n = this._univerInstanceService.getUnit(e, R.UNIVER_SHEET);
467
467
  if (!n)
468
468
  return null;
469
469
  if (t && t.startsWith("#")) {
@@ -476,9 +476,9 @@ let ee = class extends V {
476
476
  const d = c.gid, l = n.getSheetBySheetId(d);
477
477
  if (!l)
478
478
  return null;
479
- const u = Me(c.range).range;
480
- if (ve(u, l) && c.range !== q)
481
- return u;
479
+ const p = Me(c.range).range;
480
+ if (ve(p, l) && c.range !== q)
481
+ return p;
482
482
  }
483
483
  }
484
484
  return null;
@@ -486,20 +486,21 @@ let ee = class extends V {
486
486
  _registerRange(e, t, n, r, i) {
487
487
  var o, c, d, l;
488
488
  const a = this._enusreMap(e, t);
489
- if ((c = (o = i.body) == null ? void 0 : o.customRanges) != null && c.some((u) => {
489
+ if ((c = (o = i.body) == null ? void 0 : o.customRanges) != null && c.some((p) => {
490
490
  var h;
491
- return u.rangeType === N.HYPERLINK && this._isLegalRangeUrl(e, (h = u.properties) == null ? void 0 : h.url);
491
+ return p.rangeType === N.HYPERLINK && this._isLegalRangeUrl(e, (h = p.properties) == null ? void 0 : h.url);
492
492
  })) {
493
- const u = new We();
494
- (l = (d = i.body) == null ? void 0 : d.customRanges) == null || l.forEach((h) => {
495
- var g;
496
- if (h.rangeType === N.HYPERLINK) {
497
- const p = (g = h.properties) == null ? void 0 : g.url, f = this._isLegalRangeUrl(e, p);
498
- f && u.add(this._refRangeService.watchRange(e, t, f, (M, _) => {
499
- h.properties.url = `#gid=${t}&range=${_ ? B(_) : q}`;
500
- }));
493
+ const p = new We();
494
+ let h = !1;
495
+ (l = (d = i.body) == null ? void 0 : d.customRanges) == null || l.forEach((g) => {
496
+ var u;
497
+ if (g.rangeType === N.HYPERLINK) {
498
+ const f = (u = g.properties) == null ? void 0 : u.url, S = this._isLegalRangeUrl(e, f);
499
+ S && (h = !0, p.add(this._refRangeService.watchRange(e, t, S, (_, M) => {
500
+ g.properties.url = `#gid=${t}&range=${M ? B(M) : q}`;
501
+ })));
501
502
  }
502
- }), a.setValue(n, r, u);
503
+ }), h && a.setValue(n, r, p);
503
504
  }
504
505
  }
505
506
  _initWorkbookLoad() {
@@ -513,17 +514,17 @@ let ee = class extends V {
513
514
  });
514
515
  });
515
516
  };
516
- this._univerInstanceService.getAllUnitsForType(S.UNIVER_SHEET).forEach((t) => {
517
+ this._univerInstanceService.getAllUnitsForType(R.UNIVER_SHEET).forEach((t) => {
517
518
  e(t);
518
519
  }), this.disposeWithMe(
519
520
  this._univerInstanceService.unitAdded$.subscribe((t) => {
520
- t.type === S.UNIVER_SHEET && e(t);
521
+ t.type === R.UNIVER_SHEET && e(t);
521
522
  })
522
523
  );
523
524
  }
524
525
  _initWorkbookUnload() {
525
526
  this._univerInstanceService.unitDisposed$.subscribe((e) => {
526
- if (e.type === S.UNIVER_SHEET) {
527
+ if (e.type === R.UNIVER_SHEET) {
527
528
  const t = e, n = t.getUnitId();
528
529
  t.getSheets().forEach((r) => {
529
530
  const i = r.getSheetId();
@@ -549,9 +550,9 @@ let ee = class extends V {
549
550
  }
550
551
  };
551
552
  ee = Lt([
552
- he(0, U),
553
- he(1, w),
554
- he(2, R(Pe))
553
+ he(0, b),
554
+ he(1, E),
555
+ he(2, I(Pe))
555
556
  ], ee);
556
557
  var Ut = Object.defineProperty, bt = Object.getOwnPropertyDescriptor, Pt = (s, e, t, n) => {
557
558
  for (var r = n > 1 ? void 0 : n ? bt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
@@ -643,7 +644,7 @@ let te = class extends V {
643
644
  if (!s || s.p)
644
645
  return t(s);
645
646
  if (typeof s.v == "string" && ie.isLegalUrl(s.v) && s.v[s.v.length - 1] !== " ") {
646
- const { unitId: n, subUnitId: r } = e, i = this._univerInstanceService.getUnit(n, S.UNIVER_SHEET), a = i == null ? void 0 : i.getSheetBySheetId(r);
647
+ const { unitId: n, subUnitId: r } = e, i = this._univerInstanceService.getUnit(n, R.UNIVER_SHEET), a = i == null ? void 0 : i.getSheetBySheetId(r);
647
648
  if (!a)
648
649
  return t(s);
649
650
  const o = a.getBlankCellDocumentModel(s);
@@ -692,33 +693,33 @@ let te = class extends V {
692
693
  }
693
694
  };
694
695
  te = Pt([
695
- z(0, R(de)),
696
- z(1, R(v)),
697
- z(2, R(Ne)),
698
- z(3, w)
696
+ z(0, I(de)),
697
+ z(1, I(v)),
698
+ z(2, I(Ne)),
699
+ z(3, E)
699
700
  ], te);
700
701
  const Nt = {
701
- type: E.COMMAND,
702
+ type: L.COMMAND,
702
703
  id: "sheets.command.add-hyper-link",
703
704
  // eslint-disable-next-line max-lines-per-function
704
705
  async handler(s, e) {
705
706
  if (!e) return !1;
706
- const t = s.get(U), n = s.get(Se), r = s.get(w), i = s.get(v), a = s.get(de), o = ce(r, e);
707
+ const t = s.get(b), n = s.get(Se), r = s.get(E), i = s.get(v), a = s.get(de), o = ce(r, e);
707
708
  if (!o) return !1;
708
- const { unitId: c, subUnitId: d, workbook: l, worksheet: u } = o, { link: h } = e, { payload: g, display: p, row: f, column: M, id: _ } = h, b = u.getCell(f, M), m = u.getBlankCellDocumentModel(b), C = m.documentModel.getSnapshot(), y = ie.deepClone(C.body);
709
+ const { unitId: c, subUnitId: d, workbook: l, worksheet: p } = o, { link: h } = e, { payload: g, display: u, row: f, column: S, id: _ } = h, M = p.getCell(f, S), m = p.getBlankCellDocumentModel(M), w = m.documentModel.getSnapshot(), y = ie.deepClone(w.body);
709
710
  if (!y) return !1;
710
711
  let P;
711
- if (p ? P = X.selection.replace({
712
+ if (u ? P = X.selection.replace({
712
713
  selection: {
713
714
  startOffset: 0,
714
715
  endOffset: y.dataStream.length - 2,
715
716
  collapsed: !0
716
717
  },
717
718
  body: {
718
- dataStream: `${p}`,
719
+ dataStream: `${u}`,
719
720
  customRanges: [{
720
721
  startIndex: 0,
721
- endIndex: p.length - 1,
722
+ endIndex: u.length - 1,
722
723
  rangeType: N.HYPERLINK,
723
724
  rangeId: _,
724
725
  properties: {
@@ -740,11 +741,11 @@ const Nt = {
740
741
  }), !P) return !1;
741
742
  const j = oe.apply(y, P.serialize()), D = {
742
743
  p: {
743
- ...C,
744
+ ...w,
744
745
  body: j
745
746
  },
746
747
  t: Re.STRING
747
- }, x = await a.onWriteCell(l, u, f, M, D), T = {
748
+ }, x = await a.onWriteCell(l, p, f, S, D), T = {
748
749
  unitId: c,
749
750
  subUnitId: d,
750
751
  cellValue: {
@@ -758,7 +759,7 @@ const Nt = {
758
759
  }, K = Ie(s, T), ue = {
759
760
  id: H.id,
760
761
  params: K
761
- }, F = [le], A = [ue], W = i.getHyperLinkByLocation(c, d, f, M);
762
+ }, F = [le], A = [ue], W = i.getHyperLinkByLocation(c, d, f, S);
762
763
  return W && (F.push({
763
764
  id: k.id,
764
765
  params: {
@@ -781,11 +782,11 @@ const Nt = {
781
782
  }
782
783
  }, Ot = {
783
784
  id: "sheets.command.add-rich-hyper-link",
784
- type: E.COMMAND,
785
+ type: L.COMMAND,
785
786
  handler: async (s, e) => {
786
787
  if (!e)
787
788
  return !1;
788
- const { documentId: t, link: n } = e, r = s.get(U), i = ae(), { payload: a } = n, o = ut(s, {
789
+ const { documentId: t, link: n } = e, r = s.get(b), i = ae(), { payload: a } = n, o = ut(s, {
789
790
  unitId: t,
790
791
  rangeId: i,
791
792
  rangeType: N.HYPERLINK,
@@ -797,31 +798,31 @@ const Nt = {
797
798
  return o ? r.syncExecuteCommand(o.id, o.params) : !1;
798
799
  }
799
800
  }, kt = {
800
- type: E.COMMAND,
801
+ type: L.COMMAND,
801
802
  id: "sheets.command.cancel-hyper-link",
802
803
  // eslint-disable-next-line max-lines-per-function
803
804
  handler(s, e) {
804
805
  var D, x;
805
806
  if (!e) return !1;
806
- const t = s.get(U), n = s.get(Se), r = s.get(w), i = s.get(v), a = ce(r, e);
807
+ const t = s.get(b), n = s.get(Se), r = s.get(E), i = s.get(v), a = ce(r, e);
807
808
  if (!a) return !1;
808
- const { row: o, column: c, id: d } = e, { unitId: l, subUnitId: u, worksheet: h } = a, g = h.getCell(o, c);
809
+ const { row: o, column: c, id: d } = e, { unitId: l, subUnitId: p, worksheet: h } = a, g = h.getCell(o, c);
809
810
  if (!g) return !1;
810
- const p = h.getCellDocumentModelWithFormula(g);
811
- if (!(p != null && p.documentModel)) return !1;
812
- const f = ie.deepClone(p.documentModel.getSnapshot());
811
+ const u = h.getCellDocumentModelWithFormula(g);
812
+ if (!(u != null && u.documentModel)) return !1;
813
+ const f = ie.deepClone(u.documentModel.getSnapshot());
813
814
  if (!((x = (D = f.body) == null ? void 0 : D.customRanges) == null ? void 0 : x.find((T) => T.rangeId === d))) return !1;
814
- const _ = X.customRange.delete(s, { documentDataModel: p.documentModel, rangeId: d });
815
+ const _ = X.customRange.delete(s, { documentDataModel: u.documentModel, rangeId: d });
815
816
  if (!_) return !1;
816
- const b = oe.apply(f.body, _.serialize()), m = [], C = [], y = {
817
+ const M = oe.apply(f.body, _.serialize()), m = [], w = [], y = {
817
818
  unitId: l,
818
- subUnitId: u,
819
+ subUnitId: p,
819
820
  cellValue: {
820
821
  [o]: {
821
822
  [c]: {
822
823
  p: {
823
824
  ...f,
824
- body: b
825
+ body: M
825
826
  },
826
827
  t: Re.STRING
827
828
  }
@@ -833,41 +834,41 @@ const Nt = {
833
834
  params: y
834
835
  });
835
836
  const P = Ie(s, y);
836
- C.push({
837
+ w.push({
837
838
  id: H.id,
838
839
  params: P
839
840
  });
840
- const j = i.getHyperLinkByLocation(l, u, o, c);
841
+ const j = i.getHyperLinkByLocation(l, p, o, c);
841
842
  return j && (m.push({
842
843
  id: k.id,
843
844
  params: {
844
845
  unitId: l,
845
- subUnitId: u,
846
+ subUnitId: p,
846
847
  id: d
847
848
  }
848
- }), C.push({
849
+ }), w.push({
849
850
  id: O.id,
850
851
  params: {
851
852
  unitId: l,
852
- subUnitId: u,
853
+ subUnitId: p,
853
854
  link: {
854
855
  ...j
855
856
  }
856
857
  }
857
858
  })), Fe(m, t).result ? (n.pushUndoRedo({
858
859
  redoMutations: m,
859
- undoMutations: C,
860
+ undoMutations: w,
860
861
  unitID: l
861
862
  }), !0) : !1;
862
863
  }
863
864
  }, Dt = {
864
- type: E.COMMAND,
865
+ type: L.COMMAND,
865
866
  id: "sheets.command.cancel-rich-hyper-link",
866
867
  handler(s, e) {
867
- var l, u;
868
+ var l, p;
868
869
  if (!e)
869
870
  return !1;
870
- const { id: t, documentId: n } = e, r = s.get(U), a = s.get(w).getUnit(n, S.UNIVER_DOC), o = (u = (l = a == null ? void 0 : a.getBody()) == null ? void 0 : l.customRanges) == null ? void 0 : u.find((h) => h.rangeId === t);
871
+ const { id: t, documentId: n } = e, r = s.get(b), a = s.get(E).getUnit(n, R.UNIVER_DOC), o = (p = (l = a == null ? void 0 : a.getBody()) == null ? void 0 : l.customRanges) == null ? void 0 : p.find((h) => h.rangeId === t);
871
872
  let c = null;
872
873
  o && o.endIndex === a.getBody().dataStream.length - 3 && (c = {
873
874
  dataStream: " "
@@ -876,24 +877,27 @@ const Nt = {
876
877
  return d ? r.syncExecuteCommand(d.id, d.params) : !1;
877
878
  }
878
879
  }, Ht = {
879
- type: E.COMMAND,
880
+ type: L.COMMAND,
880
881
  id: "sheets.command.update-hyper-link",
881
882
  // eslint-disable-next-line max-lines-per-function
882
883
  async handler(s, e) {
883
884
  var Ce, we, Ee;
884
885
  if (!e) return !1;
885
- const t = s.get(U), n = s.get(Se), r = s.get(w), i = s.get(v), a = s.get(de), o = ce(r);
886
+ const t = s.get(b), n = s.get(Se), r = s.get(E), i = s.get(v), a = s.get(de), o = ce(r, {
887
+ unitId: e.unitId,
888
+ subUnitId: e.subUnitId
889
+ });
886
890
  if (!o) return !1;
887
- const { payload: c, row: d, column: l, id: u } = e, { workbook: h, worksheet: g, unitId: p, subUnitId: f } = o, { payload: M, display: _ = "" } = c, b = g.getCell(d, l);
888
- if (!b) return !1;
889
- const m = g.getCellDocumentModelWithFormula(b);
891
+ const { payload: c, row: d, column: l, id: p } = e, { workbook: h, worksheet: g, unitId: u, subUnitId: f } = o, { payload: S, display: _ = "" } = c, M = g.getCell(d, l);
892
+ if (!M) return !1;
893
+ const m = g.getCellDocumentModelWithFormula(M);
890
894
  if (!(m != null && m.documentModel)) return !1;
891
- const C = m.documentModel.getSnapshot(), y = (we = (Ce = C.body) == null ? void 0 : Ce.customRanges) == null ? void 0 : we.find(($e) => $e.rangeId === u);
895
+ const w = m.documentModel.getSnapshot(), y = (we = (Ce = w.body) == null ? void 0 : Ce.customRanges) == null ? void 0 : we.find(($e) => $e.rangeId === p);
892
896
  if (!y) return !1;
893
897
  const P = ae(), $ = (Ee = be(m.documentModel.getBody(), y.startIndex, y.endIndex + 1).textRuns) == null ? void 0 : Ee[0];
894
898
  $ && ($.ed = _.length + 1);
895
899
  const D = Oe(s, {
896
- unitId: p,
900
+ unitId: u,
897
901
  body: {
898
902
  dataStream: `${_}`,
899
903
  customRanges: [{
@@ -902,7 +906,7 @@ const Nt = {
902
906
  startIndex: 0,
903
907
  endIndex: _.length - 1,
904
908
  properties: {
905
- url: M
909
+ url: S
906
910
  }
907
911
  }],
908
912
  textRuns: $ ? [$] : void 0
@@ -916,16 +920,16 @@ const Nt = {
916
920
  });
917
921
  if (!D)
918
922
  return !1;
919
- const x = oe.apply(ie.deepClone(C.body), D.textX.serialize()), T = {
923
+ const x = oe.apply(ie.deepClone(w.body), D.textX.serialize()), T = {
920
924
  p: {
921
- ...C,
925
+ ...w,
922
926
  body: x
923
927
  },
924
928
  t: Re.STRING
925
929
  }, le = await a.onWriteCell(h, g, d, l, T), K = {
926
930
  id: H.id,
927
931
  params: {
928
- unitId: p,
932
+ unitId: u,
929
933
  subUnitId: f,
930
934
  cellValue: {
931
935
  [d]: {
@@ -936,41 +940,41 @@ const Nt = {
936
940
  }, ue = Ie(s, K.params), F = {
937
941
  id: H.id,
938
942
  params: ue
939
- }, A = [K], W = [F], G = i.getHyperLinkByLocation(p, f, d, l);
943
+ }, A = [K], W = [F], G = i.getHyperLinkByLocation(u, f, d, l);
940
944
  return G && (A.push({
941
945
  id: k.id,
942
946
  params: {
943
- unitId: p,
947
+ unitId: u,
944
948
  subUnitId: f,
945
949
  id: G.id
946
950
  }
947
951
  }), W.push({
948
952
  id: O.id,
949
953
  params: {
950
- unitId: p,
954
+ unitId: u,
951
955
  subUnitId: f,
952
956
  link: G
953
957
  }
954
958
  })), await ye(A, t) ? (n.pushUndoRedo({
955
959
  redoMutations: A,
956
960
  undoMutations: W,
957
- unitID: p
961
+ unitID: u
958
962
  }), !0) : !1;
959
963
  }
960
964
  }, Vt = {
961
- type: E.COMMAND,
965
+ type: L.COMMAND,
962
966
  id: "sheets.command.update-rich-hyper-link",
963
967
  handler: (s, e) => {
964
- var p, f, M, _;
968
+ var u, f, S, _;
965
969
  if (!e)
966
970
  return !1;
967
- const { documentId: t, payload: n, id: r } = e, i = s.get(w), a = s.get(U), o = i.getUnit(t, S.UNIVER_DOC);
971
+ const { documentId: t, payload: n, id: r } = e, i = s.get(E), a = s.get(b), o = i.getUnit(t, R.UNIVER_DOC);
968
972
  if (!o)
969
973
  return !1;
970
- const c = (f = (p = o.getBody()) == null ? void 0 : p.customRanges) == null ? void 0 : f.find((b) => b.rangeId === r);
974
+ const c = (f = (u = o.getBody()) == null ? void 0 : u.customRanges) == null ? void 0 : f.find((M) => M.rangeId === r);
971
975
  if (!c)
972
976
  return !1;
973
- const d = (M = e.payload.display) != null ? M : "", l = ae(), h = (_ = be(o.getBody(), c.startIndex, c.endIndex + 1).textRuns) == null ? void 0 : _[0];
977
+ const d = (S = e.payload.display) != null ? S : "", l = ae(), h = (_ = be(o.getBody(), c.startIndex, c.endIndex + 1).textRuns) == null ? void 0 : _[0];
974
978
  h && (h.ed = d.length + 1);
975
979
  const g = Oe(s, {
976
980
  unitId: t,
@@ -1024,7 +1028,7 @@ let ne = class extends V {
1024
1028
  }
1025
1029
  };
1026
1030
  ne = Tt([
1027
- At(0, U)
1031
+ At(0, b)
1028
1032
  ], ne);
1029
1033
  var De = /* @__PURE__ */ ((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 || {}), Wt = Object.defineProperty, Bt = Object.getOwnPropertyDescriptor, jt = (s, e, t, n) => {
1030
1034
  for (var r = n > 1 ? void 0 : n ? Bt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
@@ -1072,7 +1076,7 @@ let re = class extends V {
1072
1076
  };
1073
1077
  re = jt([
1074
1078
  Le(0, Ke),
1075
- Le(1, R(v))
1079
+ Le(1, I(v))
1076
1080
  ], re);
1077
1081
  var Ft = Object.defineProperty, Kt = Object.getOwnPropertyDescriptor, Gt = (s, e, t, n) => {
1078
1082
  for (var r = n > 1 ? void 0 : n ? Kt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
@@ -1084,7 +1088,7 @@ let me = class {
1084
1088
  this._univerInstanceService = s, this._localeService = e, this._definedNamesService = t;
1085
1089
  }
1086
1090
  buildHyperLink(s, e, t) {
1087
- return `#${L.SHEET}=${e}${t ? `&${typeof t == "string" ? L.DEFINE_NAME : L.RANGE}=${typeof t == "string" ? t : B(t)}` : ""}`;
1091
+ return `#${U.SHEET}=${e}${t ? `&${typeof t == "string" ? U.DEFINE_NAME : U.RANGE}=${typeof t == "string" ? t : B(t)}` : ""}`;
1088
1092
  }
1089
1093
  parseHyperLink(s) {
1090
1094
  var e, t, n, r;
@@ -1103,7 +1107,7 @@ let me = class {
1103
1107
  };
1104
1108
  } else
1105
1109
  return {
1106
- type: L.URL,
1110
+ type: U.URL,
1107
1111
  name: s,
1108
1112
  url: s,
1109
1113
  searchObj: null
@@ -1111,8 +1115,8 @@ let me = class {
1111
1115
  }
1112
1116
  _getURLName(s) {
1113
1117
  var d;
1114
- const { gid: e, range: t, rangeid: n, unitid: r } = s, i = r ? this._univerInstanceService.getUnit(r, S.UNIVER_SHEET) : this._univerInstanceService.getCurrentUnitForType(S.UNIVER_SHEET), a = {
1115
- type: L.INVALID,
1118
+ const { gid: e, range: t, rangeid: n, unitid: r } = s, i = r ? this._univerInstanceService.getUnit(r, R.UNIVER_SHEET) : this._univerInstanceService.getCurrentUnitForType(R.UNIVER_SHEET), a = {
1119
+ type: U.INVALID,
1116
1120
  name: this._localeService.t("hyperLink.message.refError")
1117
1121
  };
1118
1122
  if (!i)
@@ -1122,21 +1126,21 @@ let me = class {
1122
1126
  if (!o) return a;
1123
1127
  const l = Me(t).range;
1124
1128
  return ve(l, o) && t !== q ? {
1125
- type: L.RANGE,
1129
+ type: U.RANGE,
1126
1130
  name: ct(c, l)
1127
1131
  } : a;
1128
1132
  }
1129
1133
  if (n) {
1130
1134
  const l = this._definedNamesService.getValueById(i.getUnitId(), n);
1131
1135
  return l ? {
1132
- type: L.DEFINE_NAME,
1136
+ type: U.DEFINE_NAME,
1133
1137
  name: l.formulaOrRefString
1134
1138
  } : a;
1135
1139
  }
1136
1140
  if (e) {
1137
1141
  const l = i.getSheetBySheetId(e);
1138
1142
  return l ? {
1139
- type: L.SHEET,
1143
+ type: U.SHEET,
1140
1144
  name: l.getName()
1141
1145
  } : a;
1142
1146
  }
@@ -1144,8 +1148,8 @@ let me = class {
1144
1148
  }
1145
1149
  };
1146
1150
  me = Gt([
1147
- ge(0, w),
1148
- ge(1, R(Ge)),
1151
+ ge(0, E),
1152
+ ge(1, I(Ge)),
1149
1153
  ge(2, lt)
1150
1154
  ], me);
1151
1155
  var He = Object.defineProperty, Yt = Object.getOwnPropertyDescriptor, zt = (s, e, t) => e in s ? He(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, Jt = (s, e, t, n) => {
@@ -1180,10 +1184,10 @@ let se = class extends Je {
1180
1184
  }
1181
1185
  };
1182
1186
  Ve(se, "pluginName", ke);
1183
- Ve(se, "type", S.UNIVER_SHEET);
1187
+ Ve(se, "type", R.UNIVER_SHEET);
1184
1188
  se = Jt([
1185
1189
  Ye(dt),
1186
- Ue(1, R(ze)),
1190
+ Ue(1, I(ze)),
1187
1191
  Ue(2, Ze)
1188
1192
  ], se);
1189
1193
  export {
@@ -1195,7 +1199,7 @@ export {
1195
1199
  q as ERROR_RANGE,
1196
1200
  v as HyperLinkModel,
1197
1201
  k as RemoveHyperLinkMutation,
1198
- L as SheetHyperLinkType,
1202
+ U as SheetHyperLinkType,
1199
1203
  me as SheetsHyperLinkParserService,
1200
1204
  se as UniverSheetsHyperLinkPlugin,
1201
1205
  Ht as UpdateHyperLinkCommand,
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(p,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("rxjs"),require("@univerjs/sheets"),require("@univerjs/engine-formula"),require("@univerjs/docs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","@univerjs/sheets","@univerjs/engine-formula","@univerjs/docs"],o):(p=typeof globalThis<"u"?globalThis:p||self,o(p.UniverSheetsHyperLink={},p.UniverCore,p.rxjs,p.UniverSheets,p.UniverEngineFormula,p.UniverDocs))})(this,function(p,o,H,m,R,x){"use strict";var Ze=Object.defineProperty;var Qe=(p,o,H)=>o in p?Ze(p,o,{enumerable:!0,configurable:!0,writable:!0,value:H}):p[o]=H;var M=(p,o,H)=>Qe(p,typeof o!="symbol"?o+"":o,H);var Se=Object.defineProperty,Ie=Object.getOwnPropertyDescriptor,Re=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ie(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Se(t,e,i),i},Me=(r,t)=>(e,n)=>t(e,n,r);p.HyperLinkModel=class extends o.Disposable{constructor(e){super();M(this,"_linkUpdate$",new H.Subject);M(this,"linkUpdate$",this._linkUpdate$.asObservable());M(this,"_linkMap",new Map);M(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let i=this._linkMap.get(e);i||(i=new Map,this._linkMap.set(e,i));let s=i.get(n);s||(s=new o.ObjectMatrix,i.set(n,s));let a=this._linkPositionMap.get(e);a||(a=new Map,this._linkPositionMap.set(e,a));let d=a.get(n);return d||(d=new Map,a.set(n,d)),{matrix:s,positionMap:d}}addHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n);return s.setValue(i.row,i.column,i),a.set(i.id,{row:i.row,column:i.column,link:i}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:i,type:"add"}),!0}updateHyperLink(e,n,i,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;const u=d.getValue(l.row,l.column);return u&&(Object.assign(u,s),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:u.display,payload:u.payload},id:i,type:"update",silent:a})),!0}updateHyperLinkRef(e,n,i,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;let u=d.getValue(l.row,l.column);return!u||u.id!==i?u=l.link:d.realDeleteValue(l.row,l.column),Object.assign(u,s),c.set(i,{...s,link:u}),d.setValue(s.row,s.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:i,type:"updateRef",silent:a}),!0}removeHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(i);if(!d)return!1;a.delete(i);const c=s.getValue(d.row,d.column);return c&&c.id===i&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(i);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,i,s){const{matrix:a}=this._ensureMap(e,n);return a.getValue(i,s)}getHyperLinkByLocationSync(e,n,i,s){var g,f,_,h,y;const{matrix:a}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,o.UniverInstanceType.UNIVER_SHEET),c=(g=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:g.getCellRaw(i,s),l=((y=(h=c==null?void 0:c.v)!=null?h:(_=(f=c==null?void 0:c.p)==null?void 0:f.body)==null?void 0:_.dataStream.slice(0,-2))!=null?y:"").toString(),u=a.getValue(i,s);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:i}=this._ensureMap(e,n),s=[];return i.forValue((a,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(i=>{const s=this.getSubUnit(e,i);return{unitId:e,subUnitId:i,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}},p.HyperLinkModel=Re([Me(0,o.IUniverInstanceService)],p.HyperLinkModel);var C=(r=>(r.SHEET="gid",r.RANGE="range",r.DEFINE_NAME="rangeid",r.INVALID="invalid",r.URL="url",r))(C||{});const Ce="sheets-hyper-link.config",Ue={},w={type:o.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,link:s}=t;return e.addHyperLink(n,i,s)}},E={type:o.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:s}=t;return e.removeHyperLink(n,i,s)}},B={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,payload:s,id:a}=t;return e.updateHyperLink(n,i,a,s,!1)}},W={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:s,row:a,column:d,silent:c}=t;return e.updateHyperLinkRef(n,i,s,{row:a,column:d},c)}},se="SHEET_HYPER_LINK_PLUGIN",$="err";var Le=Object.defineProperty,we=Object.getOwnPropertyDescriptor,Ee=(r,t,e,n)=>{for(var i=n>1?void 0:n?we(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Le(t,e,i),i},z=(r,t)=>(e,n)=>t(e,n,r);let G=class extends o.Disposable{constructor(t,e,n,i){super();M(this,"_disposableMap",new Map);M(this,"_watchDisposableMap",new Map);M(this,"_rangeDisableMap",new Map);M(this,"_rangeWatcherMap",new Map);M(this,"_handlePositionChange",(t,e,n,i,s)=>{const a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return i?{redos:[{id:W.id,params:{unitId:t,subUnitId:e,id:n.id,row:i.startRow,column:i.startColumn,silent:s}}],undos:[{id:W.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: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},a=d=>{const c=m.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===s.startColumn&&l.startRow===s.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(i,this._refRangeService.registerRefRange(s,a,t,e))}_watchPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(t,e,s,(a,d)=>{const{redos:c}=this._handlePositionChange(t,e,n,d,!0);o.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(t){const e=this._disposableMap.get(t);e==null||e.dispose(),this._disposableMap.delete(t)}_unwatchPosition(t){const e=this._watchDisposableMap.get(t);e==null||e.dispose(),this._watchDisposableMap.delete(t)}_registerRange(t,e,n,i=!1){var s,a,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(s=c.get("gid"))!=null?s:"",range:(a=c.get("range"))!=null?a:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const u=l.gid,g=R.deserializeRangeWithSheet(l.range).range;if(o.isValidRange(g)&&l.range!==$){const f=_=>{const h=m.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(g,_,{selectionManagerService:this._selectionManagerService});return h&&R.serializeRange(h)===R.serializeRange(g)?{redos:[],undos:[]}:{redos:[{id:B.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:`#gid=${u}&range=${h?R.serializeRange(h):"err"}`}}}],undos:[{id:B.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(g,f,t,u)),i||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,u,g,(_,h)=>{this._hyperLinkModel.updateHyperLink(t,u,e,{payload:`#gid=${u}&range=${h?R.serializeRange(h):"err"}`},!0)},!0))}}}}_unregisterRange(t){const e=this._rangeDisableMap.get(t);e==null||e.dispose(),this._rangeDisableMap.delete(t)}_unwatchRange(t){const e=this._rangeWatcherMap.get(t);e==null||e.dispose(),this._rangeWatcherMap.delete(t)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(n=>{const{unitId:i,subUnitId:s,links:a}=n;a.forEach(d=>{this._registerPosition(i,s,d),this._watchPosition(i,s,d),this._registerRange(i,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:i,silent:s}=t,a=this._hyperLinkModel.getHyperLink(e,n,i);if(!a)return;this._unregisterPosition(i),this._registerPosition(e,n,a),s||(this._unwatchPosition(i),this._watchPosition(e,n,a));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:i}=n;i.forEach(s=>{this._unregisterPosition(s.id),this._unwatchPosition(s.id),this._unregisterRange(s.id),this._unwatchRange(s.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(o.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};G=Ee([z(0,o.Inject(m.RefRangeService)),z(1,o.Inject(p.HyperLinkModel)),z(2,o.Inject(m.SheetsSelectionsService)),z(3,o.ICommandService)],G);var ke=Object.defineProperty,Pe=Object.getOwnPropertyDescriptor,be=(r,t,e,n)=>{for(var i=n>1?void 0:n?Pe(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&ke(t,e,i),i},ee=(r,t)=>(e,n)=>t(e,n,r);let K=class extends o.Disposable{constructor(r,t,e){super(),this._sheetInterceptorService=r,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{var t;if(r.id===m.RemoveSheetCommand.id){const e=r.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const i=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const a=this._hyperLinkModel.getSubUnit(i,s),d=a.map(l=>({id:E.id,params:{unitId:i,subUnitId:s,id:l.id}})),c=a.map(l=>({id:w.id,params:{unitId:i,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};K=be([ee(0,o.Inject(m.SheetInterceptorService)),ee(1,o.IUniverInstanceService),ee(2,o.Inject(p.HyperLinkModel))],K);var He=Object.defineProperty,Te=Object.getOwnPropertyDescriptor,Ne=(r,t,e,n)=>{for(var i=n>1?void 0:n?Te(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&He(t,e,i),i},te=(r,t)=>(e,n)=>t(e,n,r);let Y=class extends o.Disposable{constructor(t,e,n){super();M(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let i=n.get(e);return i||(i=new o.ObjectMatrix,n.set(e,i)),i}_isLegalRangeUrl(t,e){var i,s,a;const n=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(i=d.get("gid"))!=null?i:"",range:(s=d.get("range"))!=null?s:"",rangeid:(a=d.get("rangeid"))!=null?a:""};if(c.range&&c.gid){const l=c.gid,u=n.getSheetBySheetId(l);if(!u)return null;const g=R.deserializeRangeWithSheet(c.range).range;if(o.isValidRange(g,u)&&c.range!==$)return g}}return null}_registerRange(t,e,n,i,s){var d,c,l,u;const a=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(g=>{var f;return g.rangeType===o.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(f=g.properties)==null?void 0:f.url)})){const g=new o.DisposableCollection;(u=(l=s.body)==null?void 0:l.customRanges)==null||u.forEach(f=>{var _;if(f.rangeType===o.CustomRangeType.HYPERLINK){const h=(_=f.properties)==null?void 0:_.url,y=this._isLegalRangeUrl(t,h);y&&g.add(this._refRangeService.watchRange(t,e,y,(U,v)=>{f.properties.url=`#gid=${e}&range=${v?R.serializeRange(v):$}`}))}}),a.setValue(n,i,g)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId(),a=this._enusreMap(n,s);i.getCellMatrix().forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,s,d,c,l.p)})})};this._univerInstanceService.getAllUnitsForType(o.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(e=>{e.type===o.UniverInstanceType.UNIVER_SHEET&&t(e)}))}_initWorkbookUnload(){this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===o.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId();this._enusreMap(n,s).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}})}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===m.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:i,cellValue:s}=e,a=this._enusreMap(n,i);s&&new o.ObjectMatrix(s).forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,i,d,c,l.p)})}}))}};Y=Ne([te(0,o.ICommandService),te(1,o.IUniverInstanceService),te(2,o.Inject(m.RefRangeService))],Y);var Oe=Object.defineProperty,De=Object.getOwnPropertyDescriptor,Ve=(r,t,e,n)=>{for(var i=n>1?void 0:n?De(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Oe(t,e,i),i},F=(r,t)=>(e,n)=>t(e,n,r);let q=class extends o.Disposable{constructor(r,t,e,n){super(),this._sheetInterceptorService=r,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.SetRangeValuesCommand.id){const t=r.params,{unitId:e,subUnitId:n}=t,i=[],s=[];return t.cellValue&&new o.ObjectMatrix(t.cellValue).forValue((a,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,a,d);c&&(i.push({id: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:a}=i;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:w.id,params:{unitId:s,subUnitId:a,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(m.AFTER_CELL_EDIT,{handler:(r,t,e)=>{if(!r||r.p)return e(r);if(typeof r.v=="string"&&o.Tools.isLegalUrl(r.v)&&r.v[r.v.length-1]!==" "){const{unitId:n,subUnitId:i}=t,s=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET),a=s==null?void 0:s.getSheetBySheetId(i);if(!a)return e(r);const d=a.getBlankCellDocumentModel(r);if(!d.documentModel)return e(r);const c=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:r.v.length,collapsed:!1},body:{dataStream:`${r.v}`,customRanges:[{startIndex:0,endIndex:r.v.length-1,rangeId:o.generateRandomId(),rangeType:o.CustomRangeType.HYPERLINK,properties:{url:r.v}}]},doc:d.documentModel});if(!c)return e(r);const l=d.documentModel.getBody();return o.TextX.apply(l,c.serialize()),e({...r,p:{id:o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:l,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(r)}}))}};q=Ve([F(0,o.Inject(m.SheetInterceptorService)),F(1,o.Inject(p.HyperLinkModel)),F(2,o.Inject(m.SheetsSelectionsService)),F(3,o.IUniverInstanceService)],q);const ae={type:o.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(r,t){if(!t)return!1;const e=r.get(o.ICommandService),n=r.get(o.IUndoRedoService),i=r.get(o.IUniverInstanceService),s=r.get(p.HyperLinkModel),a=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:u,worksheet:g}=d,{link:f}=t,{payload:_,display:h,row:y,column:U,id:v}=f,k=g.getCell(y,U),S=g.getBlankCellDocumentModel(k),L=S.documentModel.getSnapshot(),I=o.Tools.deepClone(L.body);if(!I)return!1;let P;if(h?P=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:I.dataStream.length-2,collapsed:!0},body:{dataStream:`${h}`,customRanges:[{startIndex:0,endIndex:h.length-1,rangeType:o.CustomRangeType.HYPERLINK,rangeId:v,properties:{url:_}}]},doc:S.documentModel}):P=o.BuildTextUtils.customRange.add({body:I,range:{startOffset:0,endOffset:I.dataStream.length-2,collapsed:!1},rangeId:v,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:_,refId:v}}),!P)return!1;const j=o.TextX.apply(I,P.serialize()),b={p:{...L,body:j},t:o.CellValueType.STRING},N=await a.onWriteCell(u,g,y,U,b),O={unitId:c,subUnitId:l,cellValue:{[f.row]:{[f.column]:N}}},ie={id:m.SetRangeValuesMutation.id,params:O},Z=m.SetRangeValuesUndoMutationFactory(r,O),re={id:m.SetRangeValuesMutation.id,params:Z},A=[ie],D=[re],V=s.getHyperLinkByLocation(c,l,y,U);return V&&(A.push({id:E.id,params:{unitId:c,subUnitId:l,id:V.id}}),D.push({id:w.id,params:{unitId:c,subUnitId:l,link:V}})),await o.sequenceExecuteAsync(A,e)?(n.pushUndoRedo({redoMutations:A,undoMutations:D,unitID:c}),!0):!1}},oe={id:"sheets.command.add-rich-hyper-link",type:o.CommandType.COMMAND,handler:async(r,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,i=r.get(o.ICommandService),s=o.generateRandomId(),{payload:a}=n,d=x.addCustomRangeBySelectionFactory(r,{unitId:e,rangeId:s,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:a,refId:s}});return d?i.syncExecuteCommand(d.id,d.params):!1}},de={type:o.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(r,t){var b,N;if(!t)return!1;const e=r.get(o.ICommandService),n=r.get(o.IUndoRedoService),i=r.get(o.IUniverInstanceService),s=r.get(p.HyperLinkModel),a=m.getSheetCommandTarget(i,t);if(!a)return!1;const{row:d,column:c,id:l}=t,{unitId:u,subUnitId:g,worksheet:f}=a,_=f.getCell(d,c);if(!_)return!1;const h=f.getCellDocumentModelWithFormula(_);if(!(h!=null&&h.documentModel))return!1;const y=o.Tools.deepClone(h.documentModel.getSnapshot());if(!((N=(b=y.body)==null?void 0:b.customRanges)==null?void 0:N.find(O=>O.rangeId===l)))return!1;const v=o.BuildTextUtils.customRange.delete(r,{documentDataModel:h.documentModel,rangeId:l});if(!v)return!1;const k=o.TextX.apply(y.body,v.serialize()),S=[],L=[],I={unitId:u,subUnitId:g,cellValue:{[d]:{[c]:{p:{...y,body:k},t:o.CellValueType.STRING}}}};S.push({id:m.SetRangeValuesMutation.id,params:I});const P=m.SetRangeValuesUndoMutationFactory(r,I);L.push({id:m.SetRangeValuesMutation.id,params:P});const j=s.getHyperLinkByLocation(u,g,d,c);return j&&(S.push({id:E.id,params:{unitId:u,subUnitId:g,id:l}}),L.push({id:w.id,params:{unitId:u,subUnitId:g,link:{...j}}})),o.sequenceExecute(S,e).result?(n.pushUndoRedo({redoMutations:S,undoMutations:L,unitID:u}),!0):!1}},ce={type:o.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(r,t){var u,g;if(!t)return!1;const{id:e,documentId:n}=t,i=r.get(o.ICommandService),a=r.get(o.IUniverInstanceService).getUnit(n,o.UniverInstanceType.UNIVER_DOC),d=(g=(u=a==null?void 0:a.getBody())==null?void 0:u.customRanges)==null?void 0:g.find(f=>f.rangeId===e);let c=null;d&&d.endIndex===a.getBody().dataStream.length-3&&(c={dataStream:" "});const l=x.deleteCustomRangeFactory(r,{unitId:n,rangeId:e,insert:c});return l?i.syncExecuteCommand(l.id,l.params):!1}},le={type:o.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(r,t){var _e,ye,ve;if(!t)return!1;const e=r.get(o.ICommandService),n=r.get(o.IUndoRedoService),i=r.get(o.IUniverInstanceService),s=r.get(p.HyperLinkModel),a=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i);if(!d)return!1;const{payload:c,row:l,column:u,id:g}=t,{workbook:f,worksheet:_,unitId:h,subUnitId:y}=d,{payload:U,display:v=""}=c,k=_.getCell(l,u);if(!k)return!1;const S=_.getCellDocumentModelWithFormula(k);if(!(S!=null&&S.documentModel))return!1;const L=S.documentModel.getSnapshot(),I=(ye=(_e=L.body)==null?void 0:_e.customRanges)==null?void 0:ye.find(Xe=>Xe.rangeId===g);if(!I)return!1;const P=o.generateRandomId(),T=(ve=o.getBodySlice(S.documentModel.getBody(),I.startIndex,I.endIndex+1).textRuns)==null?void 0:ve[0];T&&(T.ed=v.length+1);const b=x.replaceSelectionFactory(r,{unitId:h,body:{dataStream:`${v}`,customRanges:[{rangeId:P,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:v.length-1,properties:{url:U}}],textRuns:T?[T]:void 0},selection:{startOffset:I.startIndex,endOffset:I.endIndex+1,collapsed:!1},doc:S.documentModel});if(!b)return!1;const N=o.TextX.apply(o.Tools.deepClone(L.body),b.textX.serialize()),O={p:{...L,body:N},t:o.CellValueType.STRING},ie=await a.onWriteCell(f,_,l,u,O),Z={id:m.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:y,cellValue:{[l]:{[u]:ie}}}},re=m.SetRangeValuesUndoMutationFactory(r,Z.params),A={id:m.SetRangeValuesMutation.id,params:re},D=[Z],V=[A],Q=s.getHyperLinkByLocation(h,y,l,u);return Q&&(D.push({id:E.id,params:{unitId:h,subUnitId:y,id:Q.id}}),V.push({id:w.id,params:{unitId:h,subUnitId:y,link:Q}})),await o.sequenceExecuteAsync(D,e)?(n.pushUndoRedo({redoMutations:D,undoMutations:V,unitID:h}),!0):!1}},ue={type:o.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(r,t)=>{var h,y,U,v;if(!t)return!1;const{documentId:e,payload:n,id:i}=t,s=r.get(o.IUniverInstanceService),a=r.get(o.ICommandService),d=s.getUnit(e,o.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(y=(h=d.getBody())==null?void 0:h.customRanges)==null?void 0:y.find(k=>k.rangeId===i);if(!c)return!1;const l=(U=t.payload.display)!=null?U:"",u=o.generateRandomId(),f=(v=o.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:v[0];f&&(f.ed=l.length+1);const _=x.replaceSelectionFactory(r,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:u,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:f?[f]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return _?a.syncExecuteCommand(_.id,_.params):!1}};var $e=Object.defineProperty,je=Object.getOwnPropertyDescriptor,Ae=(r,t,e,n)=>{for(var i=n>1?void 0:n?je(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&$e(t,e,i),i},xe=(r,t)=>(e,n)=>t(e,n,r);let J=class extends o.Disposable{constructor(r){super(),this._commandService=r,this._registerCommands()}_registerCommands(){[ae,le,de,ue,ce,oe,w,B,E,W].forEach(r=>{this._commandService.registerCommand(r)})}};J=Ae([xe(0,o.ICommandService)],J);var pe=(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))(pe||{}),Be=Object.defineProperty,We=Object.getOwnPropertyDescriptor,ze=(r,t,e,n)=>{for(var i=n>1?void 0:n?We(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Be(t,e,i),i},ge=(r,t)=>(e,n)=>t(e,n,r);let X=class extends o.Disposable{constructor(r,t){super(),this._resourceManagerService=r,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const r=e=>{const n=this._hyperLinkModel.getUnit(e),i={};return n?(n.forEach(s=>{i[s.subUnitId]=s.links.map(({display:a,...d})=>d)}),JSON.stringify(i)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:se,businesses:[pe.UNIVER_SHEET],toJson:e=>r(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(i=>{n[i].forEach(a=>{this._hyperLinkModel.addHyperLink(e,i,a)})})}}))}};X=ze([ge(0,o.IResourceManagerService),ge(1,o.Inject(p.HyperLinkModel))],X);var Ge=Object.defineProperty,Ke=Object.getOwnPropertyDescriptor,Ye=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ke(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Ge(t,e,i),i},ne=(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`#${C.SHEET}=${e}${n?`&${typeof n=="string"?C.DEFINE_NAME:C.RANGE}=${typeof n=="string"?n:R.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,i,s;if(t.startsWith("#")){const a=new URLSearchParams(t.slice(1)),d={gid:(e=a.get("gid"))!=null?e:"",range:(n=a.get("range"))!=null?n:"",rangeid:(i=a.get("rangeid"))!=null?i:"",unitid:(s=a.get("unitid"))!=null?s:""},c=this._getURLName(d);return{type:c.type,name:c.name,url:t,searchObj:d}}else return{type:C.URL,name:t,url:t,searchObj:null}}_getURLName(t){var u;const{gid:e,range:n,rangeid:i,unitid:s}=t,a=s?this._univerInstanceService.getUnit(s,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),d={type:C.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!a)return d;const c=e?a.getSheetBySheetId(e):a.getActiveSheet(),l=(u=c==null?void 0:c.getName())!=null?u:"";if(n){if(!c)return d;const g=R.deserializeRangeWithSheet(n).range;return o.isValidRange(g,c)&&n!==$?{type:C.RANGE,name:R.serializeRangeWithSheet(l,g)}:d}if(i){const g=this._definedNamesService.getValueById(a.getUnitId(),i);return g?{type:C.DEFINE_NAME,name:g.formulaOrRefString}:d}if(e){const g=a.getSheetBySheetId(e);return g?{type:C.SHEET,name:g.getName()}:d}return d}},p.SheetsHyperLinkParserService=Ye([ne(0,o.IUniverInstanceService),ne(1,o.Inject(o.LocaleService)),ne(2,R.IDefinedNamesService)],p.SheetsHyperLinkParserService);var he=Object.defineProperty,Fe=Object.getOwnPropertyDescriptor,qe=(r,t,e)=>t in r?he(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Je=(r,t,e,n)=>{for(var i=n>1?void 0:n?Fe(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&he(t,e,i),i},me=(r,t)=>(e,n)=>t(e,n,r),fe=(r,t,e)=>qe(r,typeof t!="symbol"?t+"":t,e);p.UniverSheetsHyperLinkPlugin=class extends o.Plugin{constructor(t=Ue,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...i}=this._config;this._configService.setConfig(Ce,i)}onStarting(){o.registerDependencies(this._injector,[[p.HyperLinkModel],[p.SheetsHyperLinkParserService],[X],[J],[G],[q],[K],[Y]]),o.touchDependencies(this._injector,[[G],[X],[J],[q],[K],[Y]])}},fe(p.UniverSheetsHyperLinkPlugin,"pluginName",se),fe(p.UniverSheetsHyperLinkPlugin,"type",o.UniverInstanceType.UNIVER_SHEET),p.UniverSheetsHyperLinkPlugin=Je([o.DependentOn(m.UniverSheetsPlugin),me(1,o.Inject(o.Injector)),me(2,o.IConfigService)],p.UniverSheetsHyperLinkPlugin),p.AddHyperLinkCommand=ae,p.AddHyperLinkMutation=w,p.AddRichHyperLinkCommand=oe,p.CancelHyperLinkCommand=de,p.CancelRichHyperLinkCommand=ce,p.ERROR_RANGE=$,p.RemoveHyperLinkMutation=E,p.SheetHyperLinkType=C,p.UpdateHyperLinkCommand=le,p.UpdateHyperLinkMutation=B,p.UpdateHyperLinkRefMutation=W,p.UpdateRichHyperLinkCommand=ue,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
1
+ (function(p,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("rxjs"),require("@univerjs/sheets"),require("@univerjs/engine-formula"),require("@univerjs/docs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","@univerjs/sheets","@univerjs/engine-formula","@univerjs/docs"],o):(p=typeof globalThis<"u"?globalThis:p||self,o(p.UniverSheetsHyperLink={},p.UniverCore,p.rxjs,p.UniverSheets,p.UniverEngineFormula,p.UniverDocs))})(this,function(p,o,H,m,M,x){"use strict";var Ze=Object.defineProperty;var Qe=(p,o,H)=>o in p?Ze(p,o,{enumerable:!0,configurable:!0,writable:!0,value:H}):p[o]=H;var U=(p,o,H)=>Qe(p,typeof o!="symbol"?o+"":o,H);var Se=Object.defineProperty,Ie=Object.getOwnPropertyDescriptor,Re=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ie(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Se(t,e,i),i},Me=(r,t)=>(e,n)=>t(e,n,r);p.HyperLinkModel=class extends o.Disposable{constructor(e){super();U(this,"_linkUpdate$",new H.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 o.ObjectMatrix,i.set(n,s));let a=this._linkPositionMap.get(e);a||(a=new Map,this._linkPositionMap.set(e,a));let d=a.get(n);return d||(d=new Map,a.set(n,d)),{matrix:s,positionMap:d}}addHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n);return s.setValue(i.row,i.column,i),a.set(i.id,{row:i.row,column:i.column,link:i}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:i,type:"add"}),!0}updateHyperLink(e,n,i,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;const u=d.getValue(l.row,l.column);return u&&(Object.assign(u,s),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:u.display,payload:u.payload},id:i,type:"update",silent:a})),!0}updateHyperLinkRef(e,n,i,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;let u=d.getValue(l.row,l.column);return!u||u.id!==i?u=l.link:d.realDeleteValue(l.row,l.column),Object.assign(u,s),c.set(i,{...s,link:u}),d.setValue(s.row,s.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:i,type:"updateRef",silent:a}),!0}removeHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(i);if(!d)return!1;a.delete(i);const c=s.getValue(d.row,d.column);return c&&c.id===i&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(i);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,i,s){const{matrix:a}=this._ensureMap(e,n);return a.getValue(i,s)}getHyperLinkByLocationSync(e,n,i,s){var g,f,_,h,y;const{matrix:a}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,o.UniverInstanceType.UNIVER_SHEET),c=(g=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:g.getCellRaw(i,s),l=((y=(h=c==null?void 0:c.v)!=null?h:(_=(f=c==null?void 0:c.p)==null?void 0:f.body)==null?void 0:_.dataStream.slice(0,-2))!=null?y:"").toString(),u=a.getValue(i,s);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:i}=this._ensureMap(e,n),s=[];return i.forValue((a,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(i=>{const s=this.getSubUnit(e,i);return{unitId:e,subUnitId:i,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}},p.HyperLinkModel=Re([Me(0,o.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",Ue={},E={type:o.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,link:s}=t;return e.addHyperLink(n,i,s)}},k={type:o.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:s}=t;return e.removeHyperLink(n,i,s)}},B={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,payload:s,id:a}=t;return e.updateHyperLink(n,i,a,s,!1)}},W={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:s,row:a,column:d,silent:c}=t;return e.updateHyperLinkRef(n,i,s,{row:a,column:d},c)}},se="SHEET_HYPER_LINK_PLUGIN",$="err";var Le=Object.defineProperty,we=Object.getOwnPropertyDescriptor,Ee=(r,t,e,n)=>{for(var i=n>1?void 0:n?we(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Le(t,e,i),i},z=(r,t)=>(e,n)=>t(e,n,r);let G=class extends o.Disposable{constructor(t,e,n,i){super();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 a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return i?{redos:[{id:W.id,params:{unitId:t,subUnitId:e,id:n.id,row:i.startRow,column:i.startColumn,silent:s}}],undos:[{id:W.id,params:{unitId:t,subUnitId:e,id:n.id,row:a.startRow,column:a.startColumn,silent:s}}]}:{redos:[{id:k.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:E.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=i,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},a=d=>{const c=m.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===s.startColumn&&l.startRow===s.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(i,this._refRangeService.registerRefRange(s,a,t,e))}_watchPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(t,e,s,(a,d)=>{const{redos:c}=this._handlePositionChange(t,e,n,d,!0);o.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(t){const e=this._disposableMap.get(t);e==null||e.dispose(),this._disposableMap.delete(t)}_unwatchPosition(t){const e=this._watchDisposableMap.get(t);e==null||e.dispose(),this._watchDisposableMap.delete(t)}_registerRange(t,e,n,i=!1){var s,a,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(s=c.get("gid"))!=null?s:"",range:(a=c.get("range"))!=null?a:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const u=l.gid,g=M.deserializeRangeWithSheet(l.range).range;if(o.isValidRange(g)&&l.range!==$){const f=_=>{const h=m.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(g,_,{selectionManagerService:this._selectionManagerService});return h&&M.serializeRange(h)===M.serializeRange(g)?{redos:[],undos:[]}:{redos:[{id:B.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:`#gid=${u}&range=${h?M.serializeRange(h):"err"}`}}}],undos:[{id:B.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(g,f,t,u)),i||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,u,g,(_,h)=>{this._hyperLinkModel.updateHyperLink(t,u,e,{payload:`#gid=${u}&range=${h?M.serializeRange(h):"err"}`},!0)},!0))}}}}_unregisterRange(t){const e=this._rangeDisableMap.get(t);e==null||e.dispose(),this._rangeDisableMap.delete(t)}_unwatchRange(t){const e=this._rangeWatcherMap.get(t);e==null||e.dispose(),this._rangeWatcherMap.delete(t)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(n=>{const{unitId:i,subUnitId:s,links:a}=n;a.forEach(d=>{this._registerPosition(i,s,d),this._watchPosition(i,s,d),this._registerRange(i,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:i,silent:s}=t,a=this._hyperLinkModel.getHyperLink(e,n,i);if(!a)return;this._unregisterPosition(i),this._registerPosition(e,n,a),s||(this._unwatchPosition(i),this._watchPosition(e,n,a));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:i}=n;i.forEach(s=>{this._unregisterPosition(s.id),this._unwatchPosition(s.id),this._unregisterRange(s.id),this._unwatchRange(s.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(o.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};G=Ee([z(0,o.Inject(m.RefRangeService)),z(1,o.Inject(p.HyperLinkModel)),z(2,o.Inject(m.SheetsSelectionsService)),z(3,o.ICommandService)],G);var ke=Object.defineProperty,be=Object.getOwnPropertyDescriptor,Pe=(r,t,e,n)=>{for(var i=n>1?void 0:n?be(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&ke(t,e,i),i},ee=(r,t)=>(e,n)=>t(e,n,r);let K=class extends o.Disposable{constructor(r,t,e){super(),this._sheetInterceptorService=r,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{var t;if(r.id===m.RemoveSheetCommand.id){const e=r.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const i=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const a=this._hyperLinkModel.getSubUnit(i,s),d=a.map(l=>({id:k.id,params:{unitId:i,subUnitId:s,id:l.id}})),c=a.map(l=>({id:E.id,params:{unitId:i,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};K=Pe([ee(0,o.Inject(m.SheetInterceptorService)),ee(1,o.IUniverInstanceService),ee(2,o.Inject(p.HyperLinkModel))],K);var He=Object.defineProperty,Te=Object.getOwnPropertyDescriptor,Ne=(r,t,e,n)=>{for(var i=n>1?void 0:n?Te(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&He(t,e,i),i},te=(r,t)=>(e,n)=>t(e,n,r);let Y=class extends o.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 o.ObjectMatrix,n.set(e,i)),i}_isLegalRangeUrl(t,e){var i,s,a;const n=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(i=d.get("gid"))!=null?i:"",range:(s=d.get("range"))!=null?s:"",rangeid:(a=d.get("rangeid"))!=null?a:""};if(c.range&&c.gid){const l=c.gid,u=n.getSheetBySheetId(l);if(!u)return null;const g=M.deserializeRangeWithSheet(c.range).range;if(o.isValidRange(g,u)&&c.range!==$)return g}}return null}_registerRange(t,e,n,i,s){var d,c,l,u;const a=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(g=>{var f;return g.rangeType===o.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(f=g.properties)==null?void 0:f.url)})){const g=new o.DisposableCollection;let f=!1;(u=(l=s.body)==null?void 0:l.customRanges)==null||u.forEach(_=>{var h;if(_.rangeType===o.CustomRangeType.HYPERLINK){const y=(h=_.properties)==null?void 0:h.url,R=this._isLegalRangeUrl(t,y);R&&(f=!0,g.add(this._refRangeService.watchRange(t,e,R,(v,C)=>{_.properties.url=`#gid=${e}&range=${C?M.serializeRange(C):$}`})))}}),f&&a.setValue(n,i,g)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId(),a=this._enusreMap(n,s);i.getCellMatrix().forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,s,d,c,l.p)})})};this._univerInstanceService.getAllUnitsForType(o.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(e=>{e.type===o.UniverInstanceType.UNIVER_SHEET&&t(e)}))}_initWorkbookUnload(){this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===o.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId();this._enusreMap(n,s).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}})}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===m.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:i,cellValue:s}=e,a=this._enusreMap(n,i);s&&new o.ObjectMatrix(s).forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,i,d,c,l.p)})}}))}};Y=Ne([te(0,o.ICommandService),te(1,o.IUniverInstanceService),te(2,o.Inject(m.RefRangeService))],Y);var Oe=Object.defineProperty,De=Object.getOwnPropertyDescriptor,Ve=(r,t,e,n)=>{for(var i=n>1?void 0:n?De(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Oe(t,e,i),i},F=(r,t)=>(e,n)=>t(e,n,r);let q=class extends o.Disposable{constructor(r,t,e,n){super(),this._sheetInterceptorService=r,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.SetRangeValuesCommand.id){const t=r.params,{unitId:e,subUnitId:n}=t,i=[],s=[];return t.cellValue&&new o.ObjectMatrix(t.cellValue).forValue((a,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,a,d);c&&(i.push({id:k.id,params:{unitId:e,subUnitId:n,id:c.id}}),s.push({id:E.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:s,redos:i}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.ClearSelectionContentCommand.id||r.id===m.ClearSelectionAllCommand.id||r.id===m.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),i=m.getSheetCommandTarget(this._univerInstanceService);if(n&&i){const{unitId:s,subUnitId:a}=i;o.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(s,a,d,c);l&&(t.push({id:k.id,params:{unitId:s,subUnitId:a,id:l.id}}),e.push({id:E.id,params:{unitId:s,subUnitId:a,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(m.AFTER_CELL_EDIT,{handler:(r,t,e)=>{if(!r||r.p)return e(r);if(typeof r.v=="string"&&o.Tools.isLegalUrl(r.v)&&r.v[r.v.length-1]!==" "){const{unitId:n,subUnitId:i}=t,s=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET),a=s==null?void 0:s.getSheetBySheetId(i);if(!a)return e(r);const d=a.getBlankCellDocumentModel(r);if(!d.documentModel)return e(r);const c=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:r.v.length,collapsed:!1},body:{dataStream:`${r.v}`,customRanges:[{startIndex:0,endIndex:r.v.length-1,rangeId:o.generateRandomId(),rangeType:o.CustomRangeType.HYPERLINK,properties:{url:r.v}}]},doc:d.documentModel});if(!c)return e(r);const l=d.documentModel.getBody();return o.TextX.apply(l,c.serialize()),e({...r,p:{id:o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:l,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(r)}}))}};q=Ve([F(0,o.Inject(m.SheetInterceptorService)),F(1,o.Inject(p.HyperLinkModel)),F(2,o.Inject(m.SheetsSelectionsService)),F(3,o.IUniverInstanceService)],q);const ae={type:o.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(r,t){if(!t)return!1;const e=r.get(o.ICommandService),n=r.get(o.IUndoRedoService),i=r.get(o.IUniverInstanceService),s=r.get(p.HyperLinkModel),a=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:u,worksheet:g}=d,{link:f}=t,{payload:_,display:h,row:y,column:R,id:v}=f,C=g.getCell(y,R),S=g.getBlankCellDocumentModel(C),w=S.documentModel.getSnapshot(),I=o.Tools.deepClone(w.body);if(!I)return!1;let b;if(h?b=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:I.dataStream.length-2,collapsed:!0},body:{dataStream:`${h}`,customRanges:[{startIndex:0,endIndex:h.length-1,rangeType:o.CustomRangeType.HYPERLINK,rangeId:v,properties:{url:_}}]},doc:S.documentModel}):b=o.BuildTextUtils.customRange.add({body:I,range:{startOffset:0,endOffset:I.dataStream.length-2,collapsed:!1},rangeId:v,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:_,refId:v}}),!b)return!1;const j=o.TextX.apply(I,b.serialize()),P={p:{...w,body:j},t:o.CellValueType.STRING},N=await a.onWriteCell(u,g,y,R,P),O={unitId:c,subUnitId:l,cellValue:{[f.row]:{[f.column]:N}}},ie={id:m.SetRangeValuesMutation.id,params:O},Z=m.SetRangeValuesUndoMutationFactory(r,O),re={id:m.SetRangeValuesMutation.id,params:Z},A=[ie],D=[re],V=s.getHyperLinkByLocation(c,l,y,R);return V&&(A.push({id:k.id,params:{unitId:c,subUnitId:l,id:V.id}}),D.push({id:E.id,params:{unitId:c,subUnitId:l,link:V}})),await o.sequenceExecuteAsync(A,e)?(n.pushUndoRedo({redoMutations:A,undoMutations:D,unitID:c}),!0):!1}},oe={id:"sheets.command.add-rich-hyper-link",type:o.CommandType.COMMAND,handler:async(r,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,i=r.get(o.ICommandService),s=o.generateRandomId(),{payload:a}=n,d=x.addCustomRangeBySelectionFactory(r,{unitId:e,rangeId:s,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:a,refId:s}});return d?i.syncExecuteCommand(d.id,d.params):!1}},de={type:o.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(r,t){var P,N;if(!t)return!1;const e=r.get(o.ICommandService),n=r.get(o.IUndoRedoService),i=r.get(o.IUniverInstanceService),s=r.get(p.HyperLinkModel),a=m.getSheetCommandTarget(i,t);if(!a)return!1;const{row:d,column:c,id:l}=t,{unitId:u,subUnitId:g,worksheet:f}=a,_=f.getCell(d,c);if(!_)return!1;const h=f.getCellDocumentModelWithFormula(_);if(!(h!=null&&h.documentModel))return!1;const y=o.Tools.deepClone(h.documentModel.getSnapshot());if(!((N=(P=y.body)==null?void 0:P.customRanges)==null?void 0:N.find(O=>O.rangeId===l)))return!1;const v=o.BuildTextUtils.customRange.delete(r,{documentDataModel:h.documentModel,rangeId:l});if(!v)return!1;const C=o.TextX.apply(y.body,v.serialize()),S=[],w=[],I={unitId:u,subUnitId:g,cellValue:{[d]:{[c]:{p:{...y,body:C},t:o.CellValueType.STRING}}}};S.push({id:m.SetRangeValuesMutation.id,params:I});const b=m.SetRangeValuesUndoMutationFactory(r,I);w.push({id:m.SetRangeValuesMutation.id,params:b});const j=s.getHyperLinkByLocation(u,g,d,c);return j&&(S.push({id:k.id,params:{unitId:u,subUnitId:g,id:l}}),w.push({id:E.id,params:{unitId:u,subUnitId:g,link:{...j}}})),o.sequenceExecute(S,e).result?(n.pushUndoRedo({redoMutations:S,undoMutations:w,unitID:u}),!0):!1}},ce={type:o.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(r,t){var u,g;if(!t)return!1;const{id:e,documentId:n}=t,i=r.get(o.ICommandService),a=r.get(o.IUniverInstanceService).getUnit(n,o.UniverInstanceType.UNIVER_DOC),d=(g=(u=a==null?void 0:a.getBody())==null?void 0:u.customRanges)==null?void 0:g.find(f=>f.rangeId===e);let c=null;d&&d.endIndex===a.getBody().dataStream.length-3&&(c={dataStream:" "});const l=x.deleteCustomRangeFactory(r,{unitId:n,rangeId:e,insert:c});return l?i.syncExecuteCommand(l.id,l.params):!1}},le={type:o.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(r,t){var _e,ye,ve;if(!t)return!1;const e=r.get(o.ICommandService),n=r.get(o.IUndoRedoService),i=r.get(o.IUniverInstanceService),s=r.get(p.HyperLinkModel),a=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:u,id:g}=t,{workbook:f,worksheet:_,unitId:h,subUnitId:y}=d,{payload:R,display:v=""}=c,C=_.getCell(l,u);if(!C)return!1;const S=_.getCellDocumentModelWithFormula(C);if(!(S!=null&&S.documentModel))return!1;const w=S.documentModel.getSnapshot(),I=(ye=(_e=w.body)==null?void 0:_e.customRanges)==null?void 0:ye.find(Xe=>Xe.rangeId===g);if(!I)return!1;const b=o.generateRandomId(),T=(ve=o.getBodySlice(S.documentModel.getBody(),I.startIndex,I.endIndex+1).textRuns)==null?void 0:ve[0];T&&(T.ed=v.length+1);const P=x.replaceSelectionFactory(r,{unitId:h,body:{dataStream:`${v}`,customRanges:[{rangeId:b,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:v.length-1,properties:{url:R}}],textRuns:T?[T]:void 0},selection:{startOffset:I.startIndex,endOffset:I.endIndex+1,collapsed:!1},doc:S.documentModel});if(!P)return!1;const N=o.TextX.apply(o.Tools.deepClone(w.body),P.textX.serialize()),O={p:{...w,body:N},t:o.CellValueType.STRING},ie=await a.onWriteCell(f,_,l,u,O),Z={id:m.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:y,cellValue:{[l]:{[u]:ie}}}},re=m.SetRangeValuesUndoMutationFactory(r,Z.params),A={id:m.SetRangeValuesMutation.id,params:re},D=[Z],V=[A],Q=s.getHyperLinkByLocation(h,y,l,u);return Q&&(D.push({id:k.id,params:{unitId:h,subUnitId:y,id:Q.id}}),V.push({id:E.id,params:{unitId:h,subUnitId:y,link:Q}})),await o.sequenceExecuteAsync(D,e)?(n.pushUndoRedo({redoMutations:D,undoMutations:V,unitID:h}),!0):!1}},ue={type:o.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(r,t)=>{var h,y,R,v;if(!t)return!1;const{documentId:e,payload:n,id:i}=t,s=r.get(o.IUniverInstanceService),a=r.get(o.ICommandService),d=s.getUnit(e,o.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(y=(h=d.getBody())==null?void 0:h.customRanges)==null?void 0:y.find(C=>C.rangeId===i);if(!c)return!1;const l=(R=t.payload.display)!=null?R:"",u=o.generateRandomId(),f=(v=o.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:v[0];f&&(f.ed=l.length+1);const _=x.replaceSelectionFactory(r,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:u,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:f?[f]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return _?a.syncExecuteCommand(_.id,_.params):!1}};var $e=Object.defineProperty,je=Object.getOwnPropertyDescriptor,Ae=(r,t,e,n)=>{for(var i=n>1?void 0:n?je(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&$e(t,e,i),i},xe=(r,t)=>(e,n)=>t(e,n,r);let J=class extends o.Disposable{constructor(r){super(),this._commandService=r,this._registerCommands()}_registerCommands(){[ae,le,de,ue,ce,oe,E,B,k,W].forEach(r=>{this._commandService.registerCommand(r)})}};J=Ae([xe(0,o.ICommandService)],J);var pe=(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))(pe||{}),Be=Object.defineProperty,We=Object.getOwnPropertyDescriptor,ze=(r,t,e,n)=>{for(var i=n>1?void 0:n?We(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Be(t,e,i),i},ge=(r,t)=>(e,n)=>t(e,n,r);let X=class extends o.Disposable{constructor(r,t){super(),this._resourceManagerService=r,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const r=e=>{const n=this._hyperLinkModel.getUnit(e),i={};return n?(n.forEach(s=>{i[s.subUnitId]=s.links.map(({display:a,...d})=>d)}),JSON.stringify(i)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:se,businesses:[pe.UNIVER_SHEET],toJson:e=>r(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(i=>{n[i].forEach(a=>{this._hyperLinkModel.addHyperLink(e,i,a)})})}}))}};X=ze([ge(0,o.IResourceManagerService),ge(1,o.Inject(p.HyperLinkModel))],X);var Ge=Object.defineProperty,Ke=Object.getOwnPropertyDescriptor,Ye=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ke(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Ge(t,e,i),i},ne=(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:M.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,i,s;if(t.startsWith("#")){const a=new URLSearchParams(t.slice(1)),d={gid:(e=a.get("gid"))!=null?e:"",range:(n=a.get("range"))!=null?n:"",rangeid:(i=a.get("rangeid"))!=null?i:"",unitid:(s=a.get("unitid"))!=null?s:""},c=this._getURLName(d);return{type:c.type,name:c.name,url:t,searchObj:d}}else return{type:L.URL,name:t,url:t,searchObj:null}}_getURLName(t){var u;const{gid:e,range:n,rangeid:i,unitid:s}=t,a=s?this._univerInstanceService.getUnit(s,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),d={type:L.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!a)return d;const c=e?a.getSheetBySheetId(e):a.getActiveSheet(),l=(u=c==null?void 0:c.getName())!=null?u:"";if(n){if(!c)return d;const g=M.deserializeRangeWithSheet(n).range;return o.isValidRange(g,c)&&n!==$?{type:L.RANGE,name:M.serializeRangeWithSheet(l,g)}:d}if(i){const g=this._definedNamesService.getValueById(a.getUnitId(),i);return g?{type:L.DEFINE_NAME,name:g.formulaOrRefString}:d}if(e){const g=a.getSheetBySheetId(e);return g?{type:L.SHEET,name:g.getName()}:d}return d}},p.SheetsHyperLinkParserService=Ye([ne(0,o.IUniverInstanceService),ne(1,o.Inject(o.LocaleService)),ne(2,M.IDefinedNamesService)],p.SheetsHyperLinkParserService);var he=Object.defineProperty,Fe=Object.getOwnPropertyDescriptor,qe=(r,t,e)=>t in r?he(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Je=(r,t,e,n)=>{for(var i=n>1?void 0:n?Fe(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&he(t,e,i),i},me=(r,t)=>(e,n)=>t(e,n,r),fe=(r,t,e)=>qe(r,typeof t!="symbol"?t+"":t,e);p.UniverSheetsHyperLinkPlugin=class extends o.Plugin{constructor(t=Ue,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...i}=this._config;this._configService.setConfig(Ce,i)}onStarting(){o.registerDependencies(this._injector,[[p.HyperLinkModel],[p.SheetsHyperLinkParserService],[X],[J],[G],[q],[K],[Y]]),o.touchDependencies(this._injector,[[G],[X],[J],[q],[K],[Y]])}},fe(p.UniverSheetsHyperLinkPlugin,"pluginName",se),fe(p.UniverSheetsHyperLinkPlugin,"type",o.UniverInstanceType.UNIVER_SHEET),p.UniverSheetsHyperLinkPlugin=Je([o.DependentOn(m.UniverSheetsPlugin),me(1,o.Inject(o.Injector)),me(2,o.IConfigService)],p.UniverSheetsHyperLinkPlugin),p.AddHyperLinkCommand=ae,p.AddHyperLinkMutation=E,p.AddRichHyperLinkCommand=oe,p.CancelHyperLinkCommand=de,p.CancelRichHyperLinkCommand=ce,p.ERROR_RANGE=$,p.RemoveHyperLinkMutation=k,p.SheetHyperLinkType=L,p.UpdateHyperLinkCommand=le,p.UpdateHyperLinkMutation=B,p.UpdateHyperLinkRefMutation=W,p.UpdateRichHyperLinkCommand=ue,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.5.0-alpha.0",
3
+ "version": "0.5.0-beta.0",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -51,19 +51,18 @@
51
51
  "rxjs": ">=7.0.0"
52
52
  },
53
53
  "dependencies": {
54
- "@univerjs/protocol": "0.1.39-alpha.38",
55
- "@vitejs/plugin-react": "4.3.3",
56
- "@univerjs/core": "0.5.0-alpha.0",
57
- "@univerjs/docs": "0.5.0-alpha.0",
58
- "@univerjs/engine-formula": "0.5.0-alpha.0",
59
- "@univerjs/sheets": "0.5.0-alpha.0"
54
+ "@univerjs/protocol": "0.1.39-alpha.45",
55
+ "@univerjs/docs": "0.5.0-beta.0",
56
+ "@univerjs/core": "0.5.0-beta.0",
57
+ "@univerjs/sheets": "0.5.0-beta.0",
58
+ "@univerjs/engine-formula": "0.5.0-beta.0"
60
59
  },
61
60
  "devDependencies": {
62
61
  "rxjs": "^7.8.1",
63
62
  "typescript": "^5.6.3",
64
- "vite": "^5.4.10",
65
- "vitest": "^2.1.4",
66
- "@univerjs-infra/shared": "0.5.0-alpha.0"
63
+ "vite": "^5.4.11",
64
+ "vitest": "^2.1.5",
65
+ "@univerjs-infra/shared": "0.5.0-beta.0"
67
66
  },
68
67
  "space": {
69
68
  ".": {
@@ -88,7 +87,7 @@
88
87
  "test:watch": "vitest",
89
88
  "coverage": "vitest run --coverage",
90
89
  "lint:types": "tsc --noEmit",
91
- "build": "tsx build.ts"
90
+ "build": "univer-cli build"
92
91
  },
93
92
  "module": "./lib/es/index.js"
94
93
  }