@univerjs/sheets-hyper-link 0.20.1 → 0.21.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,1600 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/docs`),n=require(`@univerjs/sheets`),r=require(`rxjs`),i=require(`@univerjs/engine-formula`);function a(e){"@babel/helpers - typeof";return a=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},a(e)}function o(e,t){if(a(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(a(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function s(e){var t=o(e,`string`);return a(t)==`symbol`?t:t+``}function c(e,t,n){return(t=s(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function l(e,t){return function(n,r){t(n,r,e)}}function u(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let d=class extends e.Disposable{constructor(e){super(),this._univerInstanceService=e,c(this,`_linkUpdate$`,new r.Subject),c(this,`linkUpdate$`,this._linkUpdate$.asObservable()),c(this,`_linkMap`,new Map),c(this,`_linkPositionMap`,new Map),this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(t,n){let r=this._linkMap.get(t);r||(r=new Map,this._linkMap.set(t,r));let i=r.get(n);i||(i=new e.ObjectMatrix,r.set(n,i));let a=this._linkPositionMap.get(t);a||(a=new Map,this._linkPositionMap.set(t,a));let o=a.get(n);return o||(o=new Map,a.set(n,o)),{matrix:i,positionMap:o}}addHyperLink(e,t,n){let{matrix:r,positionMap:i}=this._ensureMap(e,t);return r.setValue(n.row,n.column,n),i.set(n.id,{row:n.row,column:n.column,link:n}),this._linkUpdate$.next({unitId:e,subUnitId:t,payload:n,type:`add`}),!0}updateHyperLink(e,t,n,r,i=!1){let{matrix:a,positionMap:o}=this._ensureMap(e,t),s=o.get(n);if(!s)return!0;let c=a.getValue(s.row,s.column);return c?(Object.assign(c,r),this._linkUpdate$.next({unitId:e,subUnitId:t,payload:{display:c.display,payload:c.payload},id:n,type:`update`,silent:i}),!0):!0}updateHyperLinkRef(e,t,n,r,i=!1){let{matrix:a,positionMap:o}=this._ensureMap(e,t),s=o.get(n);if(!s)return!0;let c=a.getValue(s.row,s.column);return!c||c.id!==n?c=s.link:a.realDeleteValue(s.row,s.column),Object.assign(c,r),o.set(n,{...r,link:c}),a.setValue(r.row,r.column,c),this._linkUpdate$.next({unitId:e,subUnitId:t,payload:r,id:n,type:`updateRef`,silent:i}),!0}removeHyperLink(e,t,n){let{matrix:r,positionMap:i}=this._ensureMap(e,t),a=i.get(n);if(!a)return!1;i.delete(n);let o=r.getValue(a.row,a.column);return o&&o.id===n&&r.realDeleteValue(a.row,a.column),this._linkUpdate$.next({unitId:e,subUnitId:t,payload:a.link,type:`remove`}),!0}getHyperLink(e,t,n){let{matrix:r,positionMap:i}=this._ensureMap(e,t),a=i.get(n);if(a)return r.getValue(a.row,a.column)}getHyperLinkByLocation(e,t,n,r){let{matrix:i}=this._ensureMap(e,t);return i.getValue(n,r)}getHyperLinkByLocationSync(t,n,r,i){var a,o,s,c;let{matrix:l}=this._ensureMap(t,n),u=this._univerInstanceService.getUnit(t,e.UniverInstanceType.UNIVER_SHEET),d=u==null||(a=u.getSheetBySheetId(n))==null?void 0:a.getCellRaw(r,i),f=((o=(s=d==null?void 0:d.v)==null?d==null||(c=d.p)==null||(c=c.body)==null?void 0:c.dataStream.slice(0,-2):s)==null?``:o).toString(),p=l.getValue(r,i);if(p)return{...p,display:f}}getSubUnit(e,t){let{matrix:n}=this._ensureMap(e,t),r=[];return n.forValue((e,t,n)=>{n&&r.push(n)}),r}getUnit(e){let t=this._linkMap.get(e);return t?Array.from(t.keys()).map(t=>({unitId:e,subUnitId:t,links:this.getSubUnit(e,t)})):[]}deleteUnit(e){let t=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:`unload`,unitId:e,unitLinks:t})}getAll(){return Array.from(this._linkMap.keys()).map(e=>this.getUnit(e))}};d=u([l(0,e.IUniverInstanceService)],d);const f={type:e.CommandType.MUTATION,id:`sheets.mutation.add-hyper-link`,handler(e,t){if(!t)return!1;let n=e.get(d),{unitId:r,subUnitId:i,link:a}=t;return n.addHyperLink(r,i,a)}},p={type:e.CommandType.MUTATION,id:`sheets.mutation.remove-hyper-link`,handler(e,t){if(!t)return!1;let n=e.get(d),{unitId:r,subUnitId:i,id:a}=t;return n.removeHyperLink(r,i,a)}},m={type:e.CommandType.COMMAND,id:`sheets.command.add-hyper-link`,async handler(t,r){if(!r)return!1;let i=t.get(e.ICommandService),a=t.get(e.IUndoRedoService),o=t.get(e.IUniverInstanceService),s=t.get(d),c=t.get(n.SheetInterceptorService),l=(0,n.getSheetCommandTarget)(o,r);if(!l)return!1;let{unitId:u,subUnitId:m,workbook:h,worksheet:g}=l,{link:_}=r,{payload:v,display:y,row:b,column:x,id:S}=_,C=g.getCell(b,x),w=g.getBlankCellDocumentModel(C,b,x),T=w.documentModel.getSnapshot(),E=e.Tools.deepClone(T.body);if(!E)return!1;let D;if(D=y?e.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:E.dataStream.length-2,collapsed:E.dataStream.length-2==0},body:{dataStream:`${y}`,customRanges:[{startIndex:0,endIndex:y.length-1,rangeType:e.CustomRangeType.HYPERLINK,rangeId:S,properties:{url:v}}]},doc:w.documentModel}):e.BuildTextUtils.customRange.add({body:E,ranges:[{startOffset:0,endOffset:E.dataStream.length-2,collapsed:!1}],rangeId:S,rangeType:e.CustomRangeType.HYPERLINK,properties:{url:v,refId:S}}),!D)return!1;let O=e.TextX.apply(E,D.serialize()),k={p:{...T,body:O},t:e.CellValueType.STRING},A=c.onWriteCell(h,g,b,x,k),j={unitId:u,subUnitId:m,cellValue:{[_.row]:{[_.column]:A}}},M={id:n.SetRangeValuesMutation.id,params:j},N=(0,n.SetRangeValuesUndoMutationFactory)(t,j),P={id:n.SetRangeValuesMutation.id,params:N},F=[M],I=[P],L=s.getHyperLinkByLocation(u,m,b,x);return L&&(F.push({id:p.id,params:{unitId:u,subUnitId:m,id:L.id}}),I.push({id:f.id,params:{unitId:u,subUnitId:m,link:L}})),await(0,e.sequenceExecute)(F,i)?await c.onValidateCell(h,g,b,x)===!1?((0,e.sequenceExecute)(I,i),!1):(a.pushUndoRedo({redoMutations:F,undoMutations:I,unitID:u}),!0):!1}},h={id:`sheets.command.add-rich-hyper-link`,type:e.CommandType.COMMAND,handler:async(n,r)=>{if(!r)return!1;let{documentId:i,link:a}=r,o=n.get(e.ICommandService),s=(0,e.generateRandomId)(),{payload:c}=a,l=(0,t.addCustomRangeBySelectionFactory)(n,{unitId:i,rangeId:s,rangeType:e.CustomRangeType.HYPERLINK,properties:{url:c,refId:s}});return l?o.syncExecuteCommand(l.id,l.params):!1}},g={type:e.CommandType.COMMAND,id:`sheets.command.cancel-hyper-link`,handler(t,r){var i;if(!r)return!1;let a=t.get(e.ICommandService),o=t.get(e.IUndoRedoService),s=t.get(e.IUniverInstanceService),c=t.get(d),l=(0,n.getSheetCommandTarget)(s,r);if(!l)return!1;let{row:u,column:m,id:h}=r,{unitId:g,subUnitId:_,worksheet:v}=l,y=v.getCell(u,m);if(!y)return!1;let b=v.getCellDocumentModelWithFormula(y,u,m);if(!(b!=null&&b.documentModel))return!1;let x=e.Tools.deepClone(b.documentModel.getSnapshot()),S=(i=x.body)==null||(i=i.customRanges)==null?void 0:i.find(e=>`${e.rangeId}`===h);if(!S)return!1;let C=e.BuildTextUtils.customRange.delete({documentDataModel:b.documentModel,rangeId:S.rangeId});if(!C)return!1;let w=e.TextX.apply(x.body,C.serialize()),T=[],E=[],D={unitId:g,subUnitId:_,cellValue:{[u]:{[m]:{p:{...x,body:w},t:e.CellValueType.STRING}}}};T.push({id:n.SetRangeValuesMutation.id,params:D});let O=(0,n.SetRangeValuesUndoMutationFactory)(t,D);E.push({id:n.SetRangeValuesMutation.id,params:O});let k=c.getHyperLinkByLocation(g,_,u,m);return k&&(T.push({id:p.id,params:{unitId:g,subUnitId:_,id:k.id}}),E.push({id:f.id,params:{unitId:g,subUnitId:_,link:{...k}}})),(0,e.sequenceExecute)(T,a).result?(o.pushUndoRedo({redoMutations:T,undoMutations:E,unitID:g}),!0):!1}},_={type:e.CommandType.COMMAND,id:`sheets.command.cancel-rich-hyper-link`,handler(n,r){var i;if(!r)return!1;let{id:a,documentId:o}=r,s=n.get(e.ICommandService),c=n.get(e.IUniverInstanceService).getUnit(o,e.UniverInstanceType.UNIVER_DOC),l=c==null||(i=c.getBody())==null||(i=i.customRanges)==null?void 0:i.find(e=>e.rangeId===a),u=null;l&&l.endIndex===c.getBody().dataStream.length-3&&(u={dataStream:` `});let d=(0,t.deleteCustomRangeFactory)(n,{unitId:o,rangeId:a,insert:u});return d?s.syncExecuteCommand(d.id,d.params):!1}},v={type:e.CommandType.COMMAND,id:`sheets.command.update-hyper-link`,async handler(r,i){var a,o;if(!i)return!1;let s=r.get(e.ICommandService),c=r.get(e.IUndoRedoService),l=r.get(e.IUniverInstanceService),u=r.get(d),m=r.get(n.SheetInterceptorService),h=(0,n.getSheetCommandTarget)(l,{unitId:i.unitId,subUnitId:i.subUnitId});if(!h)return!1;let{payload:g,row:_,column:v,id:y}=i,{workbook:b,worksheet:x,unitId:S,subUnitId:C}=h,{payload:w,display:T=``}=g,E=x.getCell(_,v);if(!E)return!1;let D=x.getCellDocumentModelWithFormula(E,_,v);if(!(D!=null&&D.documentModel))return!1;let O=D.documentModel.getSnapshot(),k=(a=O.body)==null||(a=a.customRanges)==null?void 0:a.find(e=>`${e.rangeId}`===y);if(!k)return!1;let A=(0,e.generateRandomId)(),j=(o=(0,e.getBodySlice)(D.documentModel.getBody(),k.startIndex,k.endIndex+1).textRuns)==null?void 0:o[0];j&&(j.ed=T.length+1);let M=(0,t.replaceSelectionFactory)(r,{unitId:S,body:{dataStream:`${T}`,customRanges:[{rangeId:A,rangeType:e.CustomRangeType.HYPERLINK,startIndex:0,endIndex:T.length-1,properties:{url:w}}],textRuns:j?[j]:void 0},selection:{startOffset:k.startIndex,endOffset:k.endIndex+1,collapsed:!1},doc:D.documentModel});if(!M)return!1;let N=e.TextX.apply(e.Tools.deepClone(O.body),M.textX.serialize()),P={p:{...O,body:N},t:e.CellValueType.STRING},F=m.onWriteCell(b,x,_,v,P),I={id:n.SetRangeValuesMutation.id,params:{unitId:S,subUnitId:C,cellValue:{[_]:{[v]:F}}}},L=(0,n.SetRangeValuesUndoMutationFactory)(r,I.params),R={id:n.SetRangeValuesMutation.id,params:L},z=[I],B=[R],V=u.getHyperLinkByLocation(S,C,_,v);return V&&(z.push({id:p.id,params:{unitId:S,subUnitId:C,id:V.id}}),B.push({id:f.id,params:{unitId:S,subUnitId:C,link:V}})),(0,e.sequenceExecute)(z,s)?await m.onValidateCell(b,x,_,v)===!1?((0,e.sequenceExecute)(B,s),!1):(c.pushUndoRedo({redoMutations:z,undoMutations:B,unitID:S}),!0):!1}},y={type:e.CommandType.COMMAND,id:`sheets.command.update-rich-hyper-link`,handler:(n,r)=>{var i,a,o;if(!r)return!1;let{documentId:s,payload:c,id:l}=r,u=n.get(e.IUniverInstanceService),d=n.get(e.ICommandService),f=u.getUnit(s,e.UniverInstanceType.UNIVER_DOC);if(!f)return!1;let p=(i=f.getBody())==null||(i=i.customRanges)==null?void 0:i.find(e=>e.rangeId===l);if(!p)return!1;let m=(a=r.payload.display)==null?``:a,h=(0,e.generateRandomId)(),g=(o=(0,e.getBodySlice)(f.getBody(),p.startIndex,p.endIndex+1).textRuns)==null?void 0:o[0];g&&(g.ed=m.length+1);let _=(0,t.replaceSelectionFactory)(n,{unitId:s,body:{dataStream:`${m}`,customRanges:[{rangeId:h,rangeType:e.CustomRangeType.HYPERLINK,startIndex:0,endIndex:m.length-1,properties:{url:c.payload}}],textRuns:g?[g]:void 0},selection:{startOffset:p.startIndex,endOffset:p.endIndex+1,collapsed:!1},doc:f});return _?d.syncExecuteCommand(_.id,_.params):!1}},b={type:e.CommandType.MUTATION,id:`sheets.mutation.update-hyper-link`,handler(e,t){if(!t)return!1;let n=e.get(d),{unitId:r,subUnitId:i,payload:a,id:o}=t;return n.updateHyperLink(r,i,o,a,!1)}},x={type:e.CommandType.MUTATION,id:`sheets.mutation.update-hyper-link-ref`,handler(e,t){if(!t)return!1;let n=e.get(d),{unitId:r,subUnitId:i,id:a,row:o,column:s,silent:c}=t;return n.updateHyperLinkRef(r,i,a,{row:o,column:s},c)}},S={type:e.CommandType.MUTATION,id:`sheets.mutation.update-rich-hyper-link`,handler(t,r){var i;if(!r)return!1;let{unitId:a,subUnitId:o,row:s,col:c,id:l,url:u}=r,d=(0,n.getSheetCommandTarget)(t.get(e.IUniverInstanceService),{unitId:a,subUnitId:o});if(!d)return!1;let{worksheet:f}=d,p=f.getCellRaw(s,c),m=p==null||(i=p.p)==null||(i=i.body)==null||(i=i.customRanges)==null?void 0:i.find(t=>t.rangeType===e.CustomRangeType.HYPERLINK&&t.rangeId===l);return m&&(m.properties.url=u),!0}};var C=`@univerjs/sheets-hyper-link`,w=`0.20.1`;const T=`sheets-hyper-link.config`;Symbol(T);const E={};let D=class extends e.Disposable{constructor(e,t,n,r){super(),this._refRangeService=e,this._hyperLinkModel=t,this._selectionManagerService=n,this._commandService=r,c(this,`_disposableMap`,new Map),c(this,`_watchDisposableMap`,new Map),c(this,`_rangeDisableMap`,new Map),c(this,`_rangeWatcherMap`,new Map),c(this,`_handlePositionChange`,(e,t,n,r,i)=>{let a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return r?{redos:[{id:x.id,params:{unitId:e,subUnitId:t,id:n.id,row:r.startRow,column:r.startColumn,silent:i}}],undos:[{id:x.id,params:{unitId:e,subUnitId:t,id:n.id,row:a.startRow,column:a.startColumn,silent:i}}]}:{redos:[{id:p.id,params:{unitId:e,subUnitId:t,id:n.id}}],undos:[{id:f.id,params:{unitId:e,subUnitId:t,link:n}}]}}),this._initData(),this._initRefRange()}_registerPosition(e,t,r){let i=r.id,a={startColumn:r.column,endColumn:r.column,startRow:r.row,endRow:r.row};this._disposableMap.set(i,this._refRangeService.registerRefRange(a,i=>{let o=(0,n.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests)(a,i,{selectionManagerService:this._selectionManagerService}),s=Array.isArray(o)?o[0]:o;return s&&s.startColumn===a.startColumn&&s.startRow===a.startRow?{undos:[],redos:[]}:this._handlePositionChange(e,t,r,s,!1)},e,t))}_watchPosition(t,n,r){let i=r.id,a={startColumn:r.column,endColumn:r.column,startRow:r.row,endRow:r.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(t,n,a,(i,a)=>{let{redos:o}=this._handlePositionChange(t,n,r,a,!0);(0,e.sequenceExecuteAsync)(o,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(e){let t=this._disposableMap.get(e);t==null||t.dispose(),this._disposableMap.delete(e)}_unwatchPosition(e){let t=this._watchDisposableMap.get(e);t==null||t.dispose(),this._watchDisposableMap.delete(e)}_registerRange(t,r,a,o=!1){if(a.startsWith(`#`)){var s,c,l;let u=new URLSearchParams(a.slice(1)),d={gid:(s=u.get(`gid`))==null?``:s,range:(c=u.get(`range`))==null?``:c,rangeid:(l=u.get(`rangeid`))==null?``:l};if(d.range&&d.gid){let s=d.gid,c=(0,i.deserializeRangeWithSheet)(d.range).range;(0,e.isValidRange)(c)&&d.range!==`err`&&(this._rangeDisableMap.set(r,this._refRangeService.registerRefRange(c,e=>{let o=(0,n.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests)(c,e,{selectionManagerService:this._selectionManagerService});return o&&(0,i.serializeRange)(o)===(0,i.serializeRange)(c)?{redos:[],undos:[]}:{redos:[{id:b.id,params:{unitId:t,subUnitId:s,id:r,payload:{payload:`#gid=${s}&range=${o?(0,i.serializeRange)(o):`err`}`}}}],undos:[{id:b.id,params:{unitId:t,subUnitId:s,id:r,payload:{payload:a}}}]}},t,s)),o||this._rangeWatcherMap.set(r,this._refRangeService.watchRange(t,s,c,(e,n)=>{this._hyperLinkModel.updateHyperLink(t,s,r,{payload:`#gid=${s}&range=${n?(0,i.serializeRange)(n):`err`}`},!0)},!0)))}}}_unregisterRange(e){let t=this._rangeDisableMap.get(e);t==null||t.dispose(),this._rangeDisableMap.delete(e)}_unwatchRange(e){let t=this._rangeWatcherMap.get(e);t==null||t.dispose(),this._rangeWatcherMap.delete(e)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,links:r}=e;r.forEach(e=>{this._registerPosition(t,n,e),this._watchPosition(t,n,e),this._registerRange(t,e.id,e.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(e=>{switch(e.type){case`add`:this._registerPosition(e.unitId,e.subUnitId,e.payload),this._watchPosition(e.unitId,e.subUnitId,e.payload),this._registerRange(e.unitId,e.payload.id,e.payload.payload);break;case`remove`:this._unregisterPosition(e.payload.id),this._unwatchPosition(e.payload.id),this._unregisterRange(e.payload.id),this._unwatchRange(e.payload.id);break;case`updateRef`:{let{unitId:t,subUnitId:n,id:r,silent:i}=e,a=this._hyperLinkModel.getHyperLink(t,n,r);if(!a)return;this._unregisterPosition(r),this._registerPosition(t,n,a),i||(this._unwatchPosition(r),this._watchPosition(t,n,a));break}case`unload`:{let{unitLinks:t}=e;t.forEach(e=>{let{links:t}=e;t.forEach(e=>{this._unregisterPosition(e.id),this._unwatchPosition(e.id),this._unregisterRange(e.id),this._unwatchRange(e.id)})});break}case`update`:e.silent||this._unwatchRange(e.id),this._unregisterRange(e.id),this._registerRange(e.unitId,e.id,e.payload.payload,e.silent);break}})),this.disposeWithMe((0,e.toDisposable)(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};D=u([l(0,(0,e.Inject)(n.RefRangeService)),l(1,(0,e.Inject)(d)),l(2,(0,e.Inject)(n.SheetsSelectionsService)),l(3,e.ICommandService)],D);let O=class extends e.Disposable{constructor(e,t,n){super(),this._sheetInterceptorService=e,this._univerInstanceService=t,this._hyperLinkModel=n,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:t=>{if(t.id===n.RemoveSheetCommand.id){var r;let n=t.params,i=n.unitId?this._univerInstanceService.getUnit(n.unitId):this._univerInstanceService.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SHEET);if(!i)return{redos:[],undos:[]};let a=i.getUnitId(),o=n.subUnitId||((r=i.getActiveSheet())==null?void 0:r.getSheetId());if(!o)return{redos:[],undos:[]};let s=this._hyperLinkModel.getSubUnit(a,o);return{redos:s.map(e=>({id:p.id,params:{unitId:a,subUnitId:o,id:e.id}})),undos:s.map(e=>({id:f.id,params:{unitId:a,subUnitId:o,link:e}}))}}return{redos:[],undos:[]}}}))}};O=u([l(0,(0,e.Inject)(n.SheetInterceptorService)),l(1,e.IUniverInstanceService),l(2,(0,e.Inject)(d))],O);let k=class extends e.Disposable{constructor(e,t,n){super(),this._commandService=e,this._univerInstanceService=t,this._refRangeService=n,c(this,`_refRangeMap`,new Map),this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,n){let r=this._refRangeMap.get(t);r||(r=new Map,this._refRangeMap.set(t,r));let i=r.get(n);return i||(i=new e.ObjectMatrix,r.set(n,i)),i}_isLegalRangeUrl(t,n){let r=this._univerInstanceService.getUnit(t,e.UniverInstanceType.UNIVER_SHEET);if(!r)return null;if(n&&n.startsWith(`#`)){var a,o,s;let t=new URLSearchParams(n.slice(1)),c={gid:(a=t.get(`gid`))==null?``:a,range:(o=t.get(`range`))==null?``:o,rangeid:(s=t.get(`rangeid`))==null?``:s};if(c.range&&c.gid){let t=c.gid,n=r.getSheetBySheetId(t);if(!n)return null;let a=(0,i.deserializeRangeWithSheet)(c.range).range;if((0,e.isValidRange)(a,n)&&c.range!==`err`)return{range:a,worksheet:n}}}return null}_registerRange(t,r,a,o,s){var c;let l=this._enusreMap(t,r);if(!((c=s.body)==null||(c=c.customRanges)==null)&&c.some(n=>{var r;return n.rangeType===e.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(r=n.properties)==null?void 0:r.url)})){var u;let c=new e.DisposableCollection,d=!1;(u=s.body)==null||(u=u.customRanges)==null||u.forEach(s=>{if(s.rangeType===e.CustomRangeType.HYPERLINK){var l;let u=(l=s.properties)==null?void 0:l.url,f=this._isLegalRangeUrl(t,u);if(f){let{range:l,worksheet:p}=f;d=!0,c.add(this._refRangeService.registerRefRange(l,c=>{let d=(0,n.handleDefaultRangeChangeWithEffectRefCommands)(l,c);return d&&e.Rectangle.equals(d,l)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:S.id,params:{unitId:t,subUnitId:r,row:a,col:o,id:s.rangeId,url:`#gid=${r}&range=${d?(0,i.serializeRange)(d):`err`}`}}],undos:[{id:S.id,params:{unitId:t,subUnitId:r,row:a,col:o,id:s.rangeId,url:u}}],redos:[]}},p.getUnitId(),p.getSheetId()))}}}),d&&l.setValue(a,o,c)}}_initWorkbookLoad(){let t=e=>{let t=e.getUnitId();e.getSheets().forEach(e=>{let n=e.getSheetId(),r=this._enusreMap(t,n);e.getCellMatrix().forValue((e,i,a)=>{let o=r.getValue(e,i);o&&o.dispose(),a&&a.p&&this._registerRange(t,n,e,i,a.p)})})};this._univerInstanceService.getAllUnitsForType(e.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(n=>{n.type===e.UniverInstanceType.UNIVER_SHEET&&t(n)}))}_initWorkbookUnload(){this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===e.UniverInstanceType.UNIVER_SHEET){let e=t,n=e.getUnitId();e.getSheets().forEach(e=>{let t=e.getSheetId();this._enusreMap(n,t).forValue((e,t,n)=>{n&&n.dispose()})}),this._refRangeMap.delete(n)}}))}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===n.SetRangeValuesMutation.id){let{unitId:n,subUnitId:r,cellValue:i}=t.params,a=this._enusreMap(n,r);i&&new e.ObjectMatrix(i).forValue((e,t,i)=>{let o=a.getValue(e,t);o&&o.dispose(),i&&i.p&&this._registerRange(n,r,e,t,i.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===S.id){let{unitId:t,subUnitId:r,row:i,col:a}=e.params,o=(0,n.getSheetCommandTarget)(this._univerInstanceService,{unitId:t,subUnitId:r}),s=this._enusreMap(t,r).getValue(i,a);if(s&&s.dispose(),o){let{worksheet:e}=o,n=e.getCellRaw(i,a);n&&n.p&&this._registerRange(t,r,i,a,n.p)}}}))}};k=u([l(0,e.ICommandService),l(1,e.IUniverInstanceService),l(2,(0,e.Inject)(n.RefRangeService))],k);let A=class extends e.Disposable{constructor(e,t,n,r){super(),this._sheetInterceptorService=e,this._hyperLinkModel=t,this._selectionManagerService=n,this._univerInstanceService=r,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:t=>{if(t.id===n.SetRangeValuesCommand.id){let n=t.params,{unitId:r,subUnitId:i}=n,a=[],o=[];return n.cellValue&&new e.ObjectMatrix(n.cellValue).forValue((e,t)=>{let n=this._hyperLinkModel.getHyperLinkByLocation(r,i,e,t);n&&(a.push({id:p.id,params:{unitId:r,subUnitId:i,id:n.id}}),o.push({id:f.id,params:{unitId:r,subUnitId:i,link:n}}))}),{undos:o,redos:a}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:t=>{if(t.id===n.ClearSelectionContentCommand.id||t.id===n.ClearSelectionAllCommand.id||t.id===n.ClearSelectionFormatCommand.id){let r=[],i=[],a=this._selectionManagerService.getCurrentLastSelection(),o=(0,n.getSheetCommandTarget)(this._univerInstanceService,t.params);if(a&&o){let{unitId:t,subUnitId:n}=o;e.Range.foreach(a.range,(e,a)=>{let o=this._hyperLinkModel.getHyperLinkByLocation(t,n,e,a);o&&(r.push({id:p.id,params:{unitId:t,subUnitId:n,id:o.id}}),i.push({id:f.id,params:{unitId:t,subUnitId:n,link:o}}))})}return{redos:r,undos:i}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(n.AFTER_CELL_EDIT,{handler:(t,n,r)=>{if(!t||t.p)return r(t);if(typeof t.v==`string`&&e.Tools.isLegalUrl(t.v)&&t.v[t.v.length-1]!==` `){let{unitId:i,subUnitId:a,row:o,col:s}=n,c=e.Tools.normalizeUrl(t.v),l=this._univerInstanceService.getUnit(i,e.UniverInstanceType.UNIVER_SHEET),u=l==null?void 0:l.getSheetBySheetId(a);if(!u)return r(t);let d=u.getBlankCellDocumentModel(t,o,s);if(!d.documentModel)return r(t);let f=e.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:t.v.length,collapsed:!1},body:{dataStream:`${t.v}`,customRanges:[{startIndex:0,endIndex:t.v.length-1,rangeId:(0,e.generateRandomId)(),rangeType:e.CustomRangeType.HYPERLINK,properties:{url:c}}]},doc:d.documentModel});if(!f)return r(t);let p=d.documentModel.getBody();return e.TextX.apply(p,f.serialize()),r({...t,p:{id:e.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:p,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return r(t)}}))}};A=u([l(0,(0,e.Inject)(n.SheetInterceptorService)),l(1,(0,e.Inject)(d)),l(2,(0,e.Inject)(n.SheetsSelectionsService)),l(3,e.IUniverInstanceService)],A);let j=class extends e.Disposable{constructor(e){super(),this._commandService=e,this._registerCommands()}_registerCommands(){[m,v,g,y,_,h,f,b,p,x,S].forEach(e=>{this._commandService.registerCommand(e)})}};j=u([l(0,e.ICommandService)],j);let M=function(e){return e.SHEET=`gid`,e.RANGE=`range`,e.DEFINE_NAME=`rangeid`,e.INVALID=`invalid`,e.URL=`url`,e}({}),N=class{constructor(e,t,n){this._univerInstanceService=e,this._localeService=t,this._definedNamesService=n}buildHyperLink(e,t,n){return`#${M.SHEET}=${t}${n?`&${typeof n==`string`?M.DEFINE_NAME:M.RANGE}=${typeof n==`string`?n:(0,i.serializeRange)(n)}`:``}`}parseHyperLink(e){if(e.startsWith(`#`)){var t,n,r,i;let a=new URLSearchParams(e.slice(1)),o={gid:(t=a.get(`gid`))==null?``:t,range:(n=a.get(`range`))==null?``:n,rangeid:(r=a.get(`rangeid`))==null?``:r,unitid:(i=a.get(`unitid`))==null?``:i},s=this._getURLName(o);return{type:s.type,name:s.name,url:e,searchObj:o}}else return{type:M.URL,name:e,url:e,searchObj:null}}_getURLName(t){var n;let{gid:r,range:a,rangeid:o,unitid:s}=t,c=s?this._univerInstanceService.getUnit(s,e.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(e.UniverInstanceType.UNIVER_SHEET),l={type:M.INVALID,name:this._localeService.t(`hyperLink.message.refError`)};if(!c)return l;let u=r?c.getSheetBySheetId(r):c.getActiveSheet(),d=(n=u==null?void 0:u.getName())==null?``:n;if(a){if(!u)return l;let t=(0,i.deserializeRangeWithSheet)(a).range;return(0,e.isValidRange)(t,u)&&a!==`err`?{type:M.RANGE,name:(0,i.serializeRangeWithSheet)(d,t)}:l}if(o){let e=this._definedNamesService.getValueById(c.getUnitId(),o);return e?{type:M.DEFINE_NAME,name:e.formulaOrRefString}:l}if(r){let e=c.getSheetBySheetId(r);return e?{type:M.SHEET,name:e.getName()}:l}return l}};N=u([l(0,e.IUniverInstanceService),l(1,(0,e.Inject)(e.LocaleService)),l(2,i.IDefinedNamesService)],N);let P=class extends e.Plugin{constructor(t=E,n,r){super(),this._config=t,this._injector=n,this._configService=r;let{...i}=(0,e.merge)({},E,this._config);this._configService.setConfig(T,i)}onStarting(){(0,e.registerDependencies)(this._injector,[[d],[N],[j],[D],[A],[O],[k]]),(0,e.touchDependencies)(this._injector,[[D],[j],[A],[O],[k]])}};c(P,`pluginName`,`SHEET_HYPER_LINK_PLUGIN`),c(P,`packageName`,C),c(P,`version`,w),c(P,`type`,e.UniverInstanceType.UNIVER_SHEET),P=u([(0,e.DependentOn)(n.UniverSheetsPlugin),l(1,(0,e.Inject)(e.Injector)),l(2,e.IConfigService)],P),exports.AddHyperLinkCommand=m,exports.AddHyperLinkMutation=f,exports.AddRichHyperLinkCommand=h,exports.CancelHyperLinkCommand=g,exports.CancelRichHyperLinkCommand=_,exports.ERROR_RANGE=`err`,Object.defineProperty(exports,`HyperLinkModel`,{enumerable:!0,get:function(){return d}}),exports.RemoveHyperLinkMutation=p,exports.SheetHyperLinkType=M,Object.defineProperty(exports,`SheetsHyperLinkParserService`,{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,`UniverSheetsHyperLinkPlugin`,{enumerable:!0,get:function(){return P}}),exports.UpdateHyperLinkCommand=v,exports.UpdateHyperLinkMutation=b,exports.UpdateHyperLinkRefMutation=x,exports.UpdateRichHyperLinkCommand=y;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ let _univerjs_core = require("@univerjs/core");
3
+ let _univerjs_docs = require("@univerjs/docs");
4
+ let _univerjs_sheets = require("@univerjs/sheets");
5
+ let rxjs = require("rxjs");
6
+ let _univerjs_engine_formula = require("@univerjs/engine-formula");
7
+
8
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
9
+ function _typeof(o) {
10
+ "@babel/helpers - typeof";
11
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
12
+ return typeof o;
13
+ } : function(o) {
14
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
15
+ }, _typeof(o);
16
+ }
17
+
18
+ //#endregion
19
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
20
+ function toPrimitive(t, r) {
21
+ if ("object" != _typeof(t) || !t) return t;
22
+ var e = t[Symbol.toPrimitive];
23
+ if (void 0 !== e) {
24
+ var i = e.call(t, r || "default");
25
+ if ("object" != _typeof(i)) return i;
26
+ throw new TypeError("@@toPrimitive must return a primitive value.");
27
+ }
28
+ return ("string" === r ? String : Number)(t);
29
+ }
30
+
31
+ //#endregion
32
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
33
+ function toPropertyKey(t) {
34
+ var i = toPrimitive(t, "string");
35
+ return "symbol" == _typeof(i) ? i : i + "";
36
+ }
37
+
38
+ //#endregion
39
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
40
+ function _defineProperty(e, r, t) {
41
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
42
+ value: t,
43
+ enumerable: !0,
44
+ configurable: !0,
45
+ writable: !0
46
+ }) : e[r] = t, e;
47
+ }
48
+
49
+ //#endregion
50
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
51
+ function __decorateParam(paramIndex, decorator) {
52
+ return function(target, key) {
53
+ decorator(target, key, paramIndex);
54
+ };
55
+ }
56
+
57
+ //#endregion
58
+ //#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
59
+ function __decorate(decorators, target, key, desc) {
60
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
61
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
62
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
63
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
64
+ }
65
+
66
+ //#endregion
67
+ //#region src/models/hyper-link.model.ts
68
+ let HyperLinkModel = class HyperLinkModel extends _univerjs_core.Disposable {
69
+ constructor(_univerInstanceService) {
70
+ super();
71
+ this._univerInstanceService = _univerInstanceService;
72
+ _defineProperty(this, "_linkUpdate$", new rxjs.Subject());
73
+ _defineProperty(this, "linkUpdate$", this._linkUpdate$.asObservable());
74
+ _defineProperty(this, "_linkMap", /* @__PURE__ */ new Map());
75
+ _defineProperty(this, "_linkPositionMap", /* @__PURE__ */ new Map());
76
+ this.disposeWithMe({ dispose: () => {
77
+ this._linkUpdate$.complete();
78
+ } });
79
+ }
80
+ _ensureMap(unitId, subUnitId) {
81
+ let unitMap = this._linkMap.get(unitId);
82
+ if (!unitMap) {
83
+ unitMap = /* @__PURE__ */ new Map();
84
+ this._linkMap.set(unitId, unitMap);
85
+ }
86
+ let matrix = unitMap.get(subUnitId);
87
+ if (!matrix) {
88
+ matrix = new _univerjs_core.ObjectMatrix();
89
+ unitMap.set(subUnitId, matrix);
90
+ }
91
+ let positionUnitMap = this._linkPositionMap.get(unitId);
92
+ if (!positionUnitMap) {
93
+ positionUnitMap = /* @__PURE__ */ new Map();
94
+ this._linkPositionMap.set(unitId, positionUnitMap);
95
+ }
96
+ let positionSubUnitMap = positionUnitMap.get(subUnitId);
97
+ if (!positionSubUnitMap) {
98
+ positionSubUnitMap = /* @__PURE__ */ new Map();
99
+ positionUnitMap.set(subUnitId, positionSubUnitMap);
100
+ }
101
+ return {
102
+ matrix,
103
+ positionMap: positionSubUnitMap
104
+ };
105
+ }
106
+ addHyperLink(unitId, subUnitId, link) {
107
+ const { matrix, positionMap } = this._ensureMap(unitId, subUnitId);
108
+ matrix.setValue(link.row, link.column, link);
109
+ positionMap.set(link.id, {
110
+ row: link.row,
111
+ column: link.column,
112
+ link
113
+ });
114
+ this._linkUpdate$.next({
115
+ unitId,
116
+ subUnitId,
117
+ payload: link,
118
+ type: "add"
119
+ });
120
+ return true;
121
+ }
122
+ updateHyperLink(unitId, subUnitId, id, payload, silent = false) {
123
+ const { matrix, positionMap } = this._ensureMap(unitId, subUnitId);
124
+ const position = positionMap.get(id);
125
+ if (!position) return true;
126
+ const link = matrix.getValue(position.row, position.column);
127
+ if (!link) return true;
128
+ Object.assign(link, payload);
129
+ this._linkUpdate$.next({
130
+ unitId,
131
+ subUnitId,
132
+ payload: {
133
+ display: link.display,
134
+ payload: link.payload
135
+ },
136
+ id,
137
+ type: "update",
138
+ silent
139
+ });
140
+ return true;
141
+ }
142
+ updateHyperLinkRef(unitId, subUnitId, id, payload, silent = false) {
143
+ const { matrix, positionMap } = this._ensureMap(unitId, subUnitId);
144
+ const position = positionMap.get(id);
145
+ if (!position) return true;
146
+ let link = matrix.getValue(position.row, position.column);
147
+ if (!link || link.id !== id) link = position.link;
148
+ else matrix.realDeleteValue(position.row, position.column);
149
+ Object.assign(link, payload);
150
+ positionMap.set(id, {
151
+ ...payload,
152
+ link
153
+ });
154
+ matrix.setValue(payload.row, payload.column, link);
155
+ this._linkUpdate$.next({
156
+ unitId,
157
+ subUnitId,
158
+ payload,
159
+ id,
160
+ type: "updateRef",
161
+ silent
162
+ });
163
+ return true;
164
+ }
165
+ removeHyperLink(unitId, subUnitId, id) {
166
+ const { matrix, positionMap } = this._ensureMap(unitId, subUnitId);
167
+ const position = positionMap.get(id);
168
+ if (!position) return false;
169
+ positionMap.delete(id);
170
+ const link = matrix.getValue(position.row, position.column);
171
+ if (link && link.id === id) matrix.realDeleteValue(position.row, position.column);
172
+ this._linkUpdate$.next({
173
+ unitId,
174
+ subUnitId,
175
+ payload: position.link,
176
+ type: "remove"
177
+ });
178
+ return true;
179
+ }
180
+ getHyperLink(unitId, subUnitId, id) {
181
+ const { matrix, positionMap } = this._ensureMap(unitId, subUnitId);
182
+ const position = positionMap.get(id);
183
+ if (!position) return;
184
+ return matrix.getValue(position.row, position.column);
185
+ }
186
+ getHyperLinkByLocation(unitId, subUnitId, row, column) {
187
+ const { matrix } = this._ensureMap(unitId, subUnitId);
188
+ return matrix.getValue(row, column);
189
+ }
190
+ getHyperLinkByLocationSync(unitId, subUnitId, row, column) {
191
+ var _workbook$getSheetByS, _ref, _cell$v, _cell$p;
192
+ const { matrix } = this._ensureMap(unitId, subUnitId);
193
+ const workbook = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
194
+ const cell = workbook === null || workbook === void 0 || (_workbook$getSheetByS = workbook.getSheetBySheetId(subUnitId)) === null || _workbook$getSheetByS === void 0 ? void 0 : _workbook$getSheetByS.getCellRaw(row, column);
195
+ const cellValueStr = ((_ref = (_cell$v = cell === null || cell === void 0 ? void 0 : cell.v) !== null && _cell$v !== void 0 ? _cell$v : cell === null || cell === void 0 || (_cell$p = cell.p) === null || _cell$p === void 0 || (_cell$p = _cell$p.body) === null || _cell$p === void 0 ? void 0 : _cell$p.dataStream.slice(0, -2)) !== null && _ref !== void 0 ? _ref : "").toString();
196
+ const link = matrix.getValue(row, column);
197
+ if (!link) return;
198
+ return {
199
+ ...link,
200
+ display: cellValueStr
201
+ };
202
+ }
203
+ getSubUnit(unitId, subUnitId) {
204
+ const { matrix } = this._ensureMap(unitId, subUnitId);
205
+ const links = [];
206
+ matrix.forValue((row, col, value) => {
207
+ if (value) links.push(value);
208
+ });
209
+ return links;
210
+ }
211
+ getUnit(unitId) {
212
+ const unitMap = this._linkMap.get(unitId);
213
+ if (!unitMap) return [];
214
+ return Array.from(unitMap.keys()).map((subUnitId) => {
215
+ return {
216
+ unitId,
217
+ subUnitId,
218
+ links: this.getSubUnit(unitId, subUnitId)
219
+ };
220
+ });
221
+ }
222
+ deleteUnit(unitId) {
223
+ const links = this.getUnit(unitId);
224
+ this._linkMap.delete(unitId);
225
+ this._linkPositionMap.delete(unitId);
226
+ this._linkUpdate$.next({
227
+ type: "unload",
228
+ unitId,
229
+ unitLinks: links
230
+ });
231
+ }
232
+ getAll() {
233
+ return Array.from(this._linkMap.keys()).map((unitId) => this.getUnit(unitId));
234
+ }
235
+ };
236
+ HyperLinkModel = __decorate([__decorateParam(0, _univerjs_core.IUniverInstanceService)], HyperLinkModel);
237
+
238
+ //#endregion
239
+ //#region src/commands/mutations/add-hyper-link.mutation.ts
240
+ const AddHyperLinkMutation = {
241
+ type: _univerjs_core.CommandType.MUTATION,
242
+ id: "sheets.mutation.add-hyper-link",
243
+ handler(accessor, params) {
244
+ if (!params) return false;
245
+ const model = accessor.get(HyperLinkModel);
246
+ const { unitId, subUnitId, link } = params;
247
+ return model.addHyperLink(unitId, subUnitId, link);
248
+ }
249
+ };
250
+
251
+ //#endregion
252
+ //#region src/commands/mutations/remove-hyper-link.mutation.ts
253
+ const RemoveHyperLinkMutation = {
254
+ type: _univerjs_core.CommandType.MUTATION,
255
+ id: "sheets.mutation.remove-hyper-link",
256
+ handler(accessor, params) {
257
+ if (!params) return false;
258
+ const model = accessor.get(HyperLinkModel);
259
+ const { unitId, subUnitId, id } = params;
260
+ return model.removeHyperLink(unitId, subUnitId, id);
261
+ }
262
+ };
263
+
264
+ //#endregion
265
+ //#region src/commands/commands/add-hyper-link.command.ts
266
+ /**
267
+ * Command for add hyperlink
268
+ */
269
+ const AddHyperLinkCommand = {
270
+ type: _univerjs_core.CommandType.COMMAND,
271
+ id: "sheets.command.add-hyper-link",
272
+ async handler(accessor, params) {
273
+ if (!params) return false;
274
+ const commandService = accessor.get(_univerjs_core.ICommandService);
275
+ const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
276
+ const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
277
+ const hyperLinkModel = accessor.get(HyperLinkModel);
278
+ const sheetInterceptorService = accessor.get(_univerjs_sheets.SheetInterceptorService);
279
+ const target = (0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService, params);
280
+ if (!target) return false;
281
+ const { unitId, subUnitId, workbook, worksheet } = target;
282
+ const { link } = params;
283
+ const { payload, display, row, column, id } = link;
284
+ const cellData = worksheet.getCell(row, column);
285
+ const doc = worksheet.getBlankCellDocumentModel(cellData, row, column);
286
+ const snapshot = doc.documentModel.getSnapshot();
287
+ const body = _univerjs_core.Tools.deepClone(snapshot.body);
288
+ if (!body) return false;
289
+ let textX;
290
+ if (display) textX = _univerjs_core.BuildTextUtils.selection.replace({
291
+ selection: {
292
+ startOffset: 0,
293
+ endOffset: body.dataStream.length - 2,
294
+ collapsed: body.dataStream.length - 2 === 0
295
+ },
296
+ body: {
297
+ dataStream: `${display}`,
298
+ customRanges: [{
299
+ startIndex: 0,
300
+ endIndex: display.length - 1,
301
+ rangeType: _univerjs_core.CustomRangeType.HYPERLINK,
302
+ rangeId: id,
303
+ properties: { url: payload }
304
+ }]
305
+ },
306
+ doc: doc.documentModel
307
+ });
308
+ else textX = _univerjs_core.BuildTextUtils.customRange.add({
309
+ body,
310
+ ranges: [{
311
+ startOffset: 0,
312
+ endOffset: body.dataStream.length - 2,
313
+ collapsed: false
314
+ }],
315
+ rangeId: id,
316
+ rangeType: _univerjs_core.CustomRangeType.HYPERLINK,
317
+ properties: {
318
+ url: payload,
319
+ refId: id
320
+ }
321
+ });
322
+ if (!textX) return false;
323
+ const newBody = _univerjs_core.TextX.apply(body, textX.serialize());
324
+ const newCellData = {
325
+ p: {
326
+ ...snapshot,
327
+ body: newBody
328
+ },
329
+ t: _univerjs_core.CellValueType.STRING
330
+ };
331
+ const finalCellData = sheetInterceptorService.onWriteCell(workbook, worksheet, row, column, newCellData);
332
+ const redoParams = {
333
+ unitId,
334
+ subUnitId,
335
+ cellValue: { [link.row]: { [link.column]: finalCellData } }
336
+ };
337
+ const redo = {
338
+ id: _univerjs_sheets.SetRangeValuesMutation.id,
339
+ params: redoParams
340
+ };
341
+ const undoParams = (0, _univerjs_sheets.SetRangeValuesUndoMutationFactory)(accessor, redoParams);
342
+ const undo = {
343
+ id: _univerjs_sheets.SetRangeValuesMutation.id,
344
+ params: undoParams
345
+ };
346
+ const redos = [redo];
347
+ const undos = [undo];
348
+ const modelLink = hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
349
+ if (modelLink) {
350
+ redos.push({
351
+ id: RemoveHyperLinkMutation.id,
352
+ params: {
353
+ unitId,
354
+ subUnitId,
355
+ id: modelLink.id
356
+ }
357
+ });
358
+ undos.push({
359
+ id: AddHyperLinkMutation.id,
360
+ params: {
361
+ unitId,
362
+ subUnitId,
363
+ link: modelLink
364
+ }
365
+ });
366
+ }
367
+ if (await (0, _univerjs_core.sequenceExecute)(redos, commandService)) {
368
+ if (await sheetInterceptorService.onValidateCell(workbook, worksheet, row, column) === false) {
369
+ (0, _univerjs_core.sequenceExecute)(undos, commandService);
370
+ return false;
371
+ }
372
+ undoRedoService.pushUndoRedo({
373
+ redoMutations: redos,
374
+ undoMutations: undos,
375
+ unitID: unitId
376
+ });
377
+ return true;
378
+ }
379
+ return false;
380
+ }
381
+ };
382
+ const AddRichHyperLinkCommand = {
383
+ id: "sheets.command.add-rich-hyper-link",
384
+ type: _univerjs_core.CommandType.COMMAND,
385
+ handler: async (accessor, params) => {
386
+ if (!params) return false;
387
+ const { documentId, link } = params;
388
+ const commandService = accessor.get(_univerjs_core.ICommandService);
389
+ const newId = (0, _univerjs_core.generateRandomId)();
390
+ const { payload } = link;
391
+ const replaceSelection = (0, _univerjs_docs.addCustomRangeBySelectionFactory)(accessor, {
392
+ unitId: documentId,
393
+ rangeId: newId,
394
+ rangeType: _univerjs_core.CustomRangeType.HYPERLINK,
395
+ properties: {
396
+ url: payload,
397
+ refId: newId
398
+ }
399
+ });
400
+ if (replaceSelection) return commandService.syncExecuteCommand(replaceSelection.id, replaceSelection.params);
401
+ return false;
402
+ }
403
+ };
404
+
405
+ //#endregion
406
+ //#region src/commands/commands/remove-hyper-link.command.ts
407
+ const CancelHyperLinkCommand = {
408
+ type: _univerjs_core.CommandType.COMMAND,
409
+ id: "sheets.command.cancel-hyper-link",
410
+ handler(accessor, params) {
411
+ var _snapshot$body;
412
+ if (!params) return false;
413
+ const commandService = accessor.get(_univerjs_core.ICommandService);
414
+ const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
415
+ const instanceSrv = accessor.get(_univerjs_core.IUniverInstanceService);
416
+ const hyperLinkModel = accessor.get(HyperLinkModel);
417
+ const target = (0, _univerjs_sheets.getSheetCommandTarget)(instanceSrv, params);
418
+ if (!target) return false;
419
+ const { row, column, id } = params;
420
+ const { unitId, subUnitId, worksheet } = target;
421
+ const cellData = worksheet.getCell(row, column);
422
+ if (!cellData) return false;
423
+ const doc = worksheet.getCellDocumentModelWithFormula(cellData, row, column);
424
+ if (!(doc === null || doc === void 0 ? void 0 : doc.documentModel)) return false;
425
+ const snapshot = _univerjs_core.Tools.deepClone(doc.documentModel.getSnapshot());
426
+ const range = (_snapshot$body = snapshot.body) === null || _snapshot$body === void 0 || (_snapshot$body = _snapshot$body.customRanges) === null || _snapshot$body === void 0 ? void 0 : _snapshot$body.find((range) => `${range.rangeId}` === id);
427
+ if (!range) return false;
428
+ const textX = _univerjs_core.BuildTextUtils.customRange.delete({
429
+ documentDataModel: doc.documentModel,
430
+ rangeId: range.rangeId
431
+ });
432
+ if (!textX) return false;
433
+ const newBody = _univerjs_core.TextX.apply(snapshot.body, textX.serialize());
434
+ const redos = [];
435
+ const undos = [];
436
+ const setRangeParams = {
437
+ unitId,
438
+ subUnitId,
439
+ cellValue: { [row]: { [column]: {
440
+ p: {
441
+ ...snapshot,
442
+ body: newBody
443
+ },
444
+ t: _univerjs_core.CellValueType.STRING
445
+ } } }
446
+ };
447
+ redos.push({
448
+ id: _univerjs_sheets.SetRangeValuesMutation.id,
449
+ params: setRangeParams
450
+ });
451
+ const undoParams = (0, _univerjs_sheets.SetRangeValuesUndoMutationFactory)(accessor, setRangeParams);
452
+ undos.push({
453
+ id: _univerjs_sheets.SetRangeValuesMutation.id,
454
+ params: undoParams
455
+ });
456
+ const link = hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
457
+ if (link) {
458
+ redos.push({
459
+ id: RemoveHyperLinkMutation.id,
460
+ params: {
461
+ unitId,
462
+ subUnitId,
463
+ id: link.id
464
+ }
465
+ });
466
+ undos.push({
467
+ id: AddHyperLinkMutation.id,
468
+ params: {
469
+ unitId,
470
+ subUnitId,
471
+ link: { ...link }
472
+ }
473
+ });
474
+ }
475
+ if ((0, _univerjs_core.sequenceExecute)(redos, commandService).result) {
476
+ undoRedoService.pushUndoRedo({
477
+ redoMutations: redos,
478
+ undoMutations: undos,
479
+ unitID: unitId
480
+ });
481
+ return true;
482
+ }
483
+ return false;
484
+ }
485
+ };
486
+ const CancelRichHyperLinkCommand = {
487
+ type: _univerjs_core.CommandType.COMMAND,
488
+ id: "sheets.command.cancel-rich-hyper-link",
489
+ handler(accessor, params) {
490
+ var _doc$getBody;
491
+ if (!params) return false;
492
+ const { id: linkId, documentId } = params;
493
+ const commandService = accessor.get(_univerjs_core.ICommandService);
494
+ const doc = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(documentId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
495
+ const link = doc === null || doc === void 0 || (_doc$getBody = doc.getBody()) === null || _doc$getBody === void 0 || (_doc$getBody = _doc$getBody.customRanges) === null || _doc$getBody === void 0 ? void 0 : _doc$getBody.find((i) => i.rangeId === linkId);
496
+ let insert = null;
497
+ if (link && link.endIndex === doc.getBody().dataStream.length - 3) insert = { dataStream: " " };
498
+ const doMutation = (0, _univerjs_docs.deleteCustomRangeFactory)(accessor, {
499
+ unitId: documentId,
500
+ rangeId: linkId,
501
+ insert
502
+ });
503
+ if (!doMutation) return false;
504
+ return commandService.syncExecuteCommand(doMutation.id, doMutation.params);
505
+ }
506
+ };
507
+
508
+ //#endregion
509
+ //#region src/commands/commands/update-hyper-link.command.ts
510
+ const UpdateHyperLinkCommand = {
511
+ type: _univerjs_core.CommandType.COMMAND,
512
+ id: "sheets.command.update-hyper-link",
513
+ async handler(accessor, params) {
514
+ var _snapshot$body, _oldBody$textRuns;
515
+ if (!params) return false;
516
+ const commandService = accessor.get(_univerjs_core.ICommandService);
517
+ const undoRedoService = accessor.get(_univerjs_core.IUndoRedoService);
518
+ const instanceSrv = accessor.get(_univerjs_core.IUniverInstanceService);
519
+ const hyperLinkModel = accessor.get(HyperLinkModel);
520
+ const interceptorService = accessor.get(_univerjs_sheets.SheetInterceptorService);
521
+ const target = (0, _univerjs_sheets.getSheetCommandTarget)(instanceSrv, {
522
+ unitId: params.unitId,
523
+ subUnitId: params.subUnitId
524
+ });
525
+ if (!target) return false;
526
+ const { payload: link, row, column, id } = params;
527
+ const { workbook, worksheet, unitId, subUnitId } = target;
528
+ const { payload, display = "" } = link;
529
+ const cellData = worksheet.getCell(row, column);
530
+ if (!cellData) return false;
531
+ const doc = worksheet.getCellDocumentModelWithFormula(cellData, row, column);
532
+ if (!(doc === null || doc === void 0 ? void 0 : doc.documentModel)) return false;
533
+ const snapshot = doc.documentModel.getSnapshot();
534
+ const range = (_snapshot$body = snapshot.body) === null || _snapshot$body === void 0 || (_snapshot$body = _snapshot$body.customRanges) === null || _snapshot$body === void 0 ? void 0 : _snapshot$body.find((range) => `${range.rangeId}` === id);
535
+ if (!range) return false;
536
+ const newId = (0, _univerjs_core.generateRandomId)();
537
+ const textRun = (_oldBody$textRuns = (0, _univerjs_core.getBodySlice)(doc.documentModel.getBody(), range.startIndex, range.endIndex + 1).textRuns) === null || _oldBody$textRuns === void 0 ? void 0 : _oldBody$textRuns[0];
538
+ if (textRun) textRun.ed = display.length + 1;
539
+ const replaceSelection = (0, _univerjs_docs.replaceSelectionFactory)(accessor, {
540
+ unitId,
541
+ body: {
542
+ dataStream: `${display}`,
543
+ customRanges: [{
544
+ rangeId: newId,
545
+ rangeType: _univerjs_core.CustomRangeType.HYPERLINK,
546
+ startIndex: 0,
547
+ endIndex: display.length - 1,
548
+ properties: { url: payload }
549
+ }],
550
+ textRuns: textRun ? [textRun] : void 0
551
+ },
552
+ selection: {
553
+ startOffset: range.startIndex,
554
+ endOffset: range.endIndex + 1,
555
+ collapsed: false
556
+ },
557
+ doc: doc.documentModel
558
+ });
559
+ if (!replaceSelection) return false;
560
+ const newBody = _univerjs_core.TextX.apply(_univerjs_core.Tools.deepClone(snapshot.body), replaceSelection.textX.serialize());
561
+ const newCellData = {
562
+ p: {
563
+ ...snapshot,
564
+ body: newBody
565
+ },
566
+ t: _univerjs_core.CellValueType.STRING
567
+ };
568
+ const finalCellData = interceptorService.onWriteCell(workbook, worksheet, row, column, newCellData);
569
+ const redo = {
570
+ id: _univerjs_sheets.SetRangeValuesMutation.id,
571
+ params: {
572
+ unitId,
573
+ subUnitId,
574
+ cellValue: { [row]: { [column]: finalCellData } }
575
+ }
576
+ };
577
+ const undoParams = (0, _univerjs_sheets.SetRangeValuesUndoMutationFactory)(accessor, redo.params);
578
+ const undo = {
579
+ id: _univerjs_sheets.SetRangeValuesMutation.id,
580
+ params: undoParams
581
+ };
582
+ const redos = [redo];
583
+ const undos = [undo];
584
+ const modelLink = hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
585
+ if (modelLink) {
586
+ redos.push({
587
+ id: RemoveHyperLinkMutation.id,
588
+ params: {
589
+ unitId,
590
+ subUnitId,
591
+ id: modelLink.id
592
+ }
593
+ });
594
+ undos.push({
595
+ id: AddHyperLinkMutation.id,
596
+ params: {
597
+ unitId,
598
+ subUnitId,
599
+ link: modelLink
600
+ }
601
+ });
602
+ }
603
+ if ((0, _univerjs_core.sequenceExecute)(redos, commandService)) {
604
+ if (await interceptorService.onValidateCell(workbook, worksheet, row, column) === false) {
605
+ (0, _univerjs_core.sequenceExecute)(undos, commandService);
606
+ return false;
607
+ }
608
+ undoRedoService.pushUndoRedo({
609
+ redoMutations: redos,
610
+ undoMutations: undos,
611
+ unitID: unitId
612
+ });
613
+ return true;
614
+ }
615
+ return false;
616
+ }
617
+ };
618
+ const UpdateRichHyperLinkCommand = {
619
+ type: _univerjs_core.CommandType.COMMAND,
620
+ id: "sheets.command.update-rich-hyper-link",
621
+ handler: (accessor, params) => {
622
+ var _doc$getBody, _params$payload$displ, _oldBody$textRuns2;
623
+ if (!params) return false;
624
+ const { documentId: unitId, payload, id: rangeId } = params;
625
+ const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
626
+ const commandService = accessor.get(_univerjs_core.ICommandService);
627
+ const doc = univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
628
+ if (!doc) return false;
629
+ const range = (_doc$getBody = doc.getBody()) === null || _doc$getBody === void 0 || (_doc$getBody = _doc$getBody.customRanges) === null || _doc$getBody === void 0 ? void 0 : _doc$getBody.find((range) => range.rangeId === rangeId);
630
+ if (!range) return false;
631
+ const display = (_params$payload$displ = params.payload.display) !== null && _params$payload$displ !== void 0 ? _params$payload$displ : "";
632
+ const newId = (0, _univerjs_core.generateRandomId)();
633
+ const textRun = (_oldBody$textRuns2 = (0, _univerjs_core.getBodySlice)(doc.getBody(), range.startIndex, range.endIndex + 1).textRuns) === null || _oldBody$textRuns2 === void 0 ? void 0 : _oldBody$textRuns2[0];
634
+ if (textRun) textRun.ed = display.length + 1;
635
+ const replaceSelection = (0, _univerjs_docs.replaceSelectionFactory)(accessor, {
636
+ unitId,
637
+ body: {
638
+ dataStream: `${display}`,
639
+ customRanges: [{
640
+ rangeId: newId,
641
+ rangeType: _univerjs_core.CustomRangeType.HYPERLINK,
642
+ startIndex: 0,
643
+ endIndex: display.length - 1,
644
+ properties: { url: payload.payload }
645
+ }],
646
+ textRuns: textRun ? [textRun] : void 0
647
+ },
648
+ selection: {
649
+ startOffset: range.startIndex,
650
+ endOffset: range.endIndex + 1,
651
+ collapsed: false
652
+ },
653
+ doc
654
+ });
655
+ if (!replaceSelection) return false;
656
+ return commandService.syncExecuteCommand(replaceSelection.id, replaceSelection.params);
657
+ }
658
+ };
659
+
660
+ //#endregion
661
+ //#region src/commands/mutations/update-hyper-link.mutation.ts
662
+ const UpdateHyperLinkMutation = {
663
+ type: _univerjs_core.CommandType.MUTATION,
664
+ id: "sheets.mutation.update-hyper-link",
665
+ handler(accessor, params) {
666
+ if (!params) return false;
667
+ const model = accessor.get(HyperLinkModel);
668
+ const { unitId, subUnitId, payload, id } = params;
669
+ return model.updateHyperLink(unitId, subUnitId, id, payload, false);
670
+ }
671
+ };
672
+ const UpdateHyperLinkRefMutation = {
673
+ type: _univerjs_core.CommandType.MUTATION,
674
+ id: "sheets.mutation.update-hyper-link-ref",
675
+ handler(accessor, params) {
676
+ if (!params) return false;
677
+ const model = accessor.get(HyperLinkModel);
678
+ const { unitId, subUnitId, id, row, column, silent } = params;
679
+ return model.updateHyperLinkRef(unitId, subUnitId, id, {
680
+ row,
681
+ column
682
+ }, silent);
683
+ }
684
+ };
685
+ const UpdateRichHyperLinkMutation = {
686
+ type: _univerjs_core.CommandType.MUTATION,
687
+ id: "sheets.mutation.update-rich-hyper-link",
688
+ handler(accessor, params) {
689
+ var _cell$p;
690
+ if (!params) return false;
691
+ const { unitId, subUnitId, row, col, id, url } = params;
692
+ const sheetTarget = (0, _univerjs_sheets.getSheetCommandTarget)(accessor.get(_univerjs_core.IUniverInstanceService), {
693
+ unitId,
694
+ subUnitId
695
+ });
696
+ if (!sheetTarget) return false;
697
+ const { worksheet } = sheetTarget;
698
+ const cell = worksheet.getCellRaw(row, col);
699
+ const link = cell === null || cell === void 0 || (_cell$p = cell.p) === null || _cell$p === void 0 || (_cell$p = _cell$p.body) === null || _cell$p === void 0 || (_cell$p = _cell$p.customRanges) === null || _cell$p === void 0 ? void 0 : _cell$p.find((range) => range.rangeType === _univerjs_core.CustomRangeType.HYPERLINK && range.rangeId === id);
700
+ if (!link) return true;
701
+ link.properties.url = url;
702
+ return true;
703
+ }
704
+ };
705
+
706
+ //#endregion
707
+ //#region package.json
708
+ var name = "@univerjs/sheets-hyper-link";
709
+ var version = "0.21.0";
710
+
711
+ //#endregion
712
+ //#region src/config/config.ts
713
+ /**
714
+ * Copyright 2023-present DreamNum Co., Ltd.
715
+ *
716
+ * Licensed under the Apache License, Version 2.0 (the "License");
717
+ * you may not use this file except in compliance with the License.
718
+ * You may obtain a copy of the License at
719
+ *
720
+ * http://www.apache.org/licenses/LICENSE-2.0
721
+ *
722
+ * Unless required by applicable law or agreed to in writing, software
723
+ * distributed under the License is distributed on an "AS IS" BASIS,
724
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
725
+ * See the License for the specific language governing permissions and
726
+ * limitations under the License.
727
+ */
728
+ const SHEETS_HYPER_LINK_PLUGIN_CONFIG_KEY = "sheets-hyper-link.config";
729
+ const configSymbol = Symbol(SHEETS_HYPER_LINK_PLUGIN_CONFIG_KEY);
730
+ const defaultPluginConfig = {};
731
+
732
+ //#endregion
733
+ //#region src/types/const.ts
734
+ /**
735
+ * Copyright 2023-present DreamNum Co., Ltd.
736
+ *
737
+ * Licensed under the Apache License, Version 2.0 (the "License");
738
+ * you may not use this file except in compliance with the License.
739
+ * You may obtain a copy of the License at
740
+ *
741
+ * http://www.apache.org/licenses/LICENSE-2.0
742
+ *
743
+ * Unless required by applicable law or agreed to in writing, software
744
+ * distributed under the License is distributed on an "AS IS" BASIS,
745
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
746
+ * See the License for the specific language governing permissions and
747
+ * limitations under the License.
748
+ */
749
+ const SHEET_HYPER_LINK_PLUGIN = "SHEET_HYPER_LINK_PLUGIN";
750
+ const ERROR_RANGE = "err";
751
+
752
+ //#endregion
753
+ //#region src/controllers/ref-range.controller.ts
754
+ let SheetsHyperLinkRefRangeController = class SheetsHyperLinkRefRangeController extends _univerjs_core.Disposable {
755
+ constructor(_refRangeService, _hyperLinkModel, _selectionManagerService, _commandService) {
756
+ super();
757
+ this._refRangeService = _refRangeService;
758
+ this._hyperLinkModel = _hyperLinkModel;
759
+ this._selectionManagerService = _selectionManagerService;
760
+ this._commandService = _commandService;
761
+ _defineProperty(this, "_disposableMap", /* @__PURE__ */ new Map());
762
+ _defineProperty(this, "_watchDisposableMap", /* @__PURE__ */ new Map());
763
+ _defineProperty(this, "_rangeDisableMap", /* @__PURE__ */ new Map());
764
+ _defineProperty(this, "_rangeWatcherMap", /* @__PURE__ */ new Map());
765
+ _defineProperty(this, "_handlePositionChange", (unitId, subUnitId, link, resultRange, silent) => {
766
+ const oldRange = {
767
+ startColumn: link.column,
768
+ endColumn: link.column,
769
+ startRow: link.row,
770
+ endRow: link.row
771
+ };
772
+ if (!resultRange) return {
773
+ redos: [{
774
+ id: RemoveHyperLinkMutation.id,
775
+ params: {
776
+ unitId,
777
+ subUnitId,
778
+ id: link.id
779
+ }
780
+ }],
781
+ undos: [{
782
+ id: AddHyperLinkMutation.id,
783
+ params: {
784
+ unitId,
785
+ subUnitId,
786
+ link
787
+ }
788
+ }]
789
+ };
790
+ return {
791
+ redos: [{
792
+ id: UpdateHyperLinkRefMutation.id,
793
+ params: {
794
+ unitId,
795
+ subUnitId,
796
+ id: link.id,
797
+ row: resultRange.startRow,
798
+ column: resultRange.startColumn,
799
+ silent
800
+ }
801
+ }],
802
+ undos: [{
803
+ id: UpdateHyperLinkRefMutation.id,
804
+ params: {
805
+ unitId,
806
+ subUnitId,
807
+ id: link.id,
808
+ row: oldRange.startRow,
809
+ column: oldRange.startColumn,
810
+ silent
811
+ }
812
+ }]
813
+ };
814
+ });
815
+ this._initData();
816
+ this._initRefRange();
817
+ }
818
+ _registerPosition(unitId, subUnitId, link) {
819
+ const id = link.id;
820
+ const oldRange = {
821
+ startColumn: link.column,
822
+ endColumn: link.column,
823
+ startRow: link.row,
824
+ endRow: link.row
825
+ };
826
+ const handleRefRangeChange = (commandInfo) => {
827
+ const resultRanges = (0, _univerjs_sheets.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests)(oldRange, commandInfo, { selectionManagerService: this._selectionManagerService });
828
+ const resultRange = Array.isArray(resultRanges) ? resultRanges[0] : resultRanges;
829
+ if (resultRange && resultRange.startColumn === oldRange.startColumn && resultRange.startRow === oldRange.startRow) return {
830
+ undos: [],
831
+ redos: []
832
+ };
833
+ return this._handlePositionChange(unitId, subUnitId, link, resultRange, false);
834
+ };
835
+ this._disposableMap.set(id, this._refRangeService.registerRefRange(oldRange, handleRefRangeChange, unitId, subUnitId));
836
+ }
837
+ _watchPosition(unitId, subUnitId, link) {
838
+ const id = link.id;
839
+ const oldRange = {
840
+ startColumn: link.column,
841
+ endColumn: link.column,
842
+ startRow: link.row,
843
+ endRow: link.row
844
+ };
845
+ this._watchDisposableMap.set(id, this._refRangeService.watchRange(unitId, subUnitId, oldRange, (before, after) => {
846
+ const { redos } = this._handlePositionChange(unitId, subUnitId, link, after, true);
847
+ (0, _univerjs_core.sequenceExecuteAsync)(redos, this._commandService, { onlyLocal: true });
848
+ }, true));
849
+ }
850
+ _unregisterPosition(id) {
851
+ const disposable = this._disposableMap.get(id);
852
+ disposable === null || disposable === void 0 || disposable.dispose();
853
+ this._disposableMap.delete(id);
854
+ }
855
+ _unwatchPosition(id) {
856
+ const disposable = this._watchDisposableMap.get(id);
857
+ disposable === null || disposable === void 0 || disposable.dispose();
858
+ this._watchDisposableMap.delete(id);
859
+ }
860
+ _registerRange(unitId, id, payload, silent = false) {
861
+ if (payload.startsWith("#")) {
862
+ var _search$get, _search$get2, _search$get3;
863
+ const search = new URLSearchParams(payload.slice(1));
864
+ const searchObj = {
865
+ gid: (_search$get = search.get("gid")) !== null && _search$get !== void 0 ? _search$get : "",
866
+ range: (_search$get2 = search.get("range")) !== null && _search$get2 !== void 0 ? _search$get2 : "",
867
+ rangeid: (_search$get3 = search.get("rangeid")) !== null && _search$get3 !== void 0 ? _search$get3 : ""
868
+ };
869
+ if (searchObj.range && searchObj.gid) {
870
+ const subUnitId = searchObj.gid;
871
+ const range = (0, _univerjs_engine_formula.deserializeRangeWithSheet)(searchObj.range).range;
872
+ if ((0, _univerjs_core.isValidRange)(range) && searchObj.range !== "err") {
873
+ const handleRangeChange = (commandInfo) => {
874
+ const resultRange = (0, _univerjs_sheets.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests)(range, commandInfo, { selectionManagerService: this._selectionManagerService });
875
+ if (resultRange && (0, _univerjs_engine_formula.serializeRange)(resultRange) === (0, _univerjs_engine_formula.serializeRange)(range)) return {
876
+ redos: [],
877
+ undos: []
878
+ };
879
+ return {
880
+ redos: [{
881
+ id: UpdateHyperLinkMutation.id,
882
+ params: {
883
+ unitId,
884
+ subUnitId,
885
+ id,
886
+ payload: { payload: `#gid=${subUnitId}&range=${resultRange ? (0, _univerjs_engine_formula.serializeRange)(resultRange) : "err"}` }
887
+ }
888
+ }],
889
+ undos: [{
890
+ id: UpdateHyperLinkMutation.id,
891
+ params: {
892
+ unitId,
893
+ subUnitId,
894
+ id,
895
+ payload: { payload }
896
+ }
897
+ }]
898
+ };
899
+ };
900
+ this._rangeDisableMap.set(id, this._refRangeService.registerRefRange(range, handleRangeChange, unitId, subUnitId));
901
+ if (!silent) this._rangeWatcherMap.set(id, this._refRangeService.watchRange(unitId, subUnitId, range, (before, after) => {
902
+ this._hyperLinkModel.updateHyperLink(unitId, subUnitId, id, { payload: `#gid=${subUnitId}&range=${after ? (0, _univerjs_engine_formula.serializeRange)(after) : "err"}` }, true);
903
+ }, true));
904
+ }
905
+ }
906
+ }
907
+ }
908
+ _unregisterRange(id) {
909
+ const disposable = this._rangeDisableMap.get(id);
910
+ disposable === null || disposable === void 0 || disposable.dispose();
911
+ this._rangeDisableMap.delete(id);
912
+ }
913
+ _unwatchRange(id) {
914
+ const disposable = this._rangeWatcherMap.get(id);
915
+ disposable === null || disposable === void 0 || disposable.dispose();
916
+ this._rangeWatcherMap.delete(id);
917
+ }
918
+ _initData() {
919
+ this._hyperLinkModel.getAll().forEach((unitData) => {
920
+ unitData.forEach((subUnitData) => {
921
+ const { unitId, subUnitId, links } = subUnitData;
922
+ links.forEach((link) => {
923
+ this._registerPosition(unitId, subUnitId, link);
924
+ this._watchPosition(unitId, subUnitId, link);
925
+ this._registerRange(unitId, link.id, link.payload);
926
+ });
927
+ });
928
+ });
929
+ }
930
+ _initRefRange() {
931
+ this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe((option) => {
932
+ switch (option.type) {
933
+ case "add":
934
+ this._registerPosition(option.unitId, option.subUnitId, option.payload);
935
+ this._watchPosition(option.unitId, option.subUnitId, option.payload);
936
+ this._registerRange(option.unitId, option.payload.id, option.payload.payload);
937
+ break;
938
+ case "remove":
939
+ this._unregisterPosition(option.payload.id);
940
+ this._unwatchPosition(option.payload.id);
941
+ this._unregisterRange(option.payload.id);
942
+ this._unwatchRange(option.payload.id);
943
+ break;
944
+ case "updateRef": {
945
+ const { unitId, subUnitId, id, silent } = option;
946
+ const link = this._hyperLinkModel.getHyperLink(unitId, subUnitId, id);
947
+ if (!link) return;
948
+ this._unregisterPosition(id);
949
+ this._registerPosition(unitId, subUnitId, link);
950
+ if (!silent) {
951
+ this._unwatchPosition(id);
952
+ this._watchPosition(unitId, subUnitId, link);
953
+ }
954
+ break;
955
+ }
956
+ case "unload": {
957
+ const { unitLinks } = option;
958
+ unitLinks.forEach((subUnitData) => {
959
+ const { links } = subUnitData;
960
+ links.forEach((link) => {
961
+ this._unregisterPosition(link.id);
962
+ this._unwatchPosition(link.id);
963
+ this._unregisterRange(link.id);
964
+ this._unwatchRange(link.id);
965
+ });
966
+ });
967
+ break;
968
+ }
969
+ case "update":
970
+ if (!option.silent) this._unwatchRange(option.id);
971
+ this._unregisterRange(option.id);
972
+ this._registerRange(option.unitId, option.id, option.payload.payload, option.silent);
973
+ break;
974
+ }
975
+ }));
976
+ this.disposeWithMe((0, _univerjs_core.toDisposable)(() => {
977
+ this._disposableMap.forEach((item) => {
978
+ item.dispose();
979
+ });
980
+ this._disposableMap.clear();
981
+ }));
982
+ }
983
+ };
984
+ SheetsHyperLinkRefRangeController = __decorate([
985
+ __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_sheets.RefRangeService)),
986
+ __decorateParam(1, (0, _univerjs_core.Inject)(HyperLinkModel)),
987
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetsSelectionsService)),
988
+ __decorateParam(3, _univerjs_core.ICommandService)
989
+ ], SheetsHyperLinkRefRangeController);
990
+
991
+ //#endregion
992
+ //#region src/controllers/remove-sheet.controller.ts
993
+ let SheetsHyperLinkRemoveSheetController = class SheetsHyperLinkRemoveSheetController extends _univerjs_core.Disposable {
994
+ constructor(_sheetInterceptorService, _univerInstanceService, _hyperLinkModel) {
995
+ super();
996
+ this._sheetInterceptorService = _sheetInterceptorService;
997
+ this._univerInstanceService = _univerInstanceService;
998
+ this._hyperLinkModel = _hyperLinkModel;
999
+ this._initSheetChange();
1000
+ }
1001
+ _initSheetChange() {
1002
+ this.disposeWithMe(this._sheetInterceptorService.interceptCommand({ getMutations: (commandInfo) => {
1003
+ if (commandInfo.id === _univerjs_sheets.RemoveSheetCommand.id) {
1004
+ var _workbook$getActiveSh;
1005
+ const params = commandInfo.params;
1006
+ const workbook = params.unitId ? this._univerInstanceService.getUnit(params.unitId) : this._univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
1007
+ if (!workbook) return {
1008
+ redos: [],
1009
+ undos: []
1010
+ };
1011
+ const unitId = workbook.getUnitId();
1012
+ const subUnitId = params.subUnitId || ((_workbook$getActiveSh = workbook.getActiveSheet()) === null || _workbook$getActiveSh === void 0 ? void 0 : _workbook$getActiveSh.getSheetId());
1013
+ if (!subUnitId) return {
1014
+ redos: [],
1015
+ undos: []
1016
+ };
1017
+ const links = this._hyperLinkModel.getSubUnit(unitId, subUnitId);
1018
+ return {
1019
+ redos: links.map((link) => ({
1020
+ id: RemoveHyperLinkMutation.id,
1021
+ params: {
1022
+ unitId,
1023
+ subUnitId,
1024
+ id: link.id
1025
+ }
1026
+ })),
1027
+ undos: links.map((link) => ({
1028
+ id: AddHyperLinkMutation.id,
1029
+ params: {
1030
+ unitId,
1031
+ subUnitId,
1032
+ link
1033
+ }
1034
+ }))
1035
+ };
1036
+ }
1037
+ return {
1038
+ redos: [],
1039
+ undos: []
1040
+ };
1041
+ } }));
1042
+ }
1043
+ };
1044
+ SheetsHyperLinkRemoveSheetController = __decorate([
1045
+ __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
1046
+ __decorateParam(1, _univerjs_core.IUniverInstanceService),
1047
+ __decorateParam(2, (0, _univerjs_core.Inject)(HyperLinkModel))
1048
+ ], SheetsHyperLinkRemoveSheetController);
1049
+
1050
+ //#endregion
1051
+ //#region src/controllers/rich-text-ref-range.controller.ts
1052
+ let SheetsHyperLinkRichTextRefRangeController = class SheetsHyperLinkRichTextRefRangeController extends _univerjs_core.Disposable {
1053
+ constructor(_commandService, _univerInstanceService, _refRangeService) {
1054
+ super();
1055
+ this._commandService = _commandService;
1056
+ this._univerInstanceService = _univerInstanceService;
1057
+ this._refRangeService = _refRangeService;
1058
+ _defineProperty(this, "_refRangeMap", /* @__PURE__ */ new Map());
1059
+ this._initWorkbookLoad();
1060
+ this._initWorkbookUnload();
1061
+ this._initSetRangesListener();
1062
+ }
1063
+ _enusreMap(unitId, subUnitId) {
1064
+ let unitMap = this._refRangeMap.get(unitId);
1065
+ if (!unitMap) {
1066
+ unitMap = /* @__PURE__ */ new Map();
1067
+ this._refRangeMap.set(unitId, unitMap);
1068
+ }
1069
+ let subUnitMap = unitMap.get(subUnitId);
1070
+ if (!subUnitMap) {
1071
+ subUnitMap = new _univerjs_core.ObjectMatrix();
1072
+ unitMap.set(subUnitId, subUnitMap);
1073
+ }
1074
+ return subUnitMap;
1075
+ }
1076
+ _isLegalRangeUrl(unitId, payload) {
1077
+ const workbook = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
1078
+ if (!workbook) return null;
1079
+ if (payload && payload.startsWith("#")) {
1080
+ var _search$get, _search$get2, _search$get3;
1081
+ const search = new URLSearchParams(payload.slice(1));
1082
+ const searchObj = {
1083
+ gid: (_search$get = search.get("gid")) !== null && _search$get !== void 0 ? _search$get : "",
1084
+ range: (_search$get2 = search.get("range")) !== null && _search$get2 !== void 0 ? _search$get2 : "",
1085
+ rangeid: (_search$get3 = search.get("rangeid")) !== null && _search$get3 !== void 0 ? _search$get3 : ""
1086
+ };
1087
+ if (searchObj.range && searchObj.gid) {
1088
+ const subUnitId = searchObj.gid;
1089
+ const worksheet = workbook.getSheetBySheetId(subUnitId);
1090
+ if (!worksheet) return null;
1091
+ const range = (0, _univerjs_engine_formula.deserializeRangeWithSheet)(searchObj.range).range;
1092
+ if ((0, _univerjs_core.isValidRange)(range, worksheet) && searchObj.range !== "err") return {
1093
+ range,
1094
+ worksheet
1095
+ };
1096
+ }
1097
+ }
1098
+ return null;
1099
+ }
1100
+ _registerRange(unitId, subUnitId, row, col, p) {
1101
+ var _p$body;
1102
+ const map = this._enusreMap(unitId, subUnitId);
1103
+ if ((_p$body = p.body) === null || _p$body === void 0 || (_p$body = _p$body.customRanges) === null || _p$body === void 0 ? void 0 : _p$body.some((customRange) => {
1104
+ var _customRange$properti;
1105
+ return customRange.rangeType === _univerjs_core.CustomRangeType.HYPERLINK && this._isLegalRangeUrl(unitId, (_customRange$properti = customRange.properties) === null || _customRange$properti === void 0 ? void 0 : _customRange$properti.url);
1106
+ })) {
1107
+ var _p$body2;
1108
+ const disposableCollection = new _univerjs_core.DisposableCollection();
1109
+ let hasWatch = false;
1110
+ (_p$body2 = p.body) === null || _p$body2 === void 0 || (_p$body2 = _p$body2.customRanges) === null || _p$body2 === void 0 || _p$body2.forEach((customRange) => {
1111
+ if (customRange.rangeType === _univerjs_core.CustomRangeType.HYPERLINK) {
1112
+ var _customRange$properti2;
1113
+ const payload = (_customRange$properti2 = customRange.properties) === null || _customRange$properti2 === void 0 ? void 0 : _customRange$properti2.url;
1114
+ const rangeInfo = this._isLegalRangeUrl(unitId, payload);
1115
+ if (rangeInfo) {
1116
+ const { range, worksheet } = rangeInfo;
1117
+ hasWatch = true;
1118
+ disposableCollection.add(this._refRangeService.registerRefRange(range, (commandInfo) => {
1119
+ const newRange = (0, _univerjs_sheets.handleDefaultRangeChangeWithEffectRefCommands)(range, commandInfo);
1120
+ if (newRange && _univerjs_core.Rectangle.equals(newRange, range)) return {
1121
+ preRedos: [],
1122
+ preUndos: [],
1123
+ redos: [],
1124
+ undos: []
1125
+ };
1126
+ return {
1127
+ preRedos: [{
1128
+ id: UpdateRichHyperLinkMutation.id,
1129
+ params: {
1130
+ unitId,
1131
+ subUnitId,
1132
+ row,
1133
+ col,
1134
+ id: customRange.rangeId,
1135
+ url: `#gid=${subUnitId}&range=${newRange ? (0, _univerjs_engine_formula.serializeRange)(newRange) : "err"}`
1136
+ }
1137
+ }],
1138
+ undos: [{
1139
+ id: UpdateRichHyperLinkMutation.id,
1140
+ params: {
1141
+ unitId,
1142
+ subUnitId,
1143
+ row,
1144
+ col,
1145
+ id: customRange.rangeId,
1146
+ url: payload
1147
+ }
1148
+ }],
1149
+ redos: []
1150
+ };
1151
+ }, worksheet.getUnitId(), worksheet.getSheetId()));
1152
+ }
1153
+ }
1154
+ });
1155
+ if (hasWatch) map.setValue(row, col, disposableCollection);
1156
+ }
1157
+ }
1158
+ _initWorkbookLoad() {
1159
+ const handleWorkbook = (workbook) => {
1160
+ const unitId = workbook.getUnitId();
1161
+ workbook.getSheets().forEach((sheet) => {
1162
+ const subUnitId = sheet.getSheetId();
1163
+ const map = this._enusreMap(unitId, subUnitId);
1164
+ sheet.getCellMatrix().forValue((row, col, cell) => {
1165
+ const dispose = map.getValue(row, col);
1166
+ if (dispose) dispose.dispose();
1167
+ if (cell && cell.p) this._registerRange(unitId, subUnitId, row, col, cell.p);
1168
+ });
1169
+ });
1170
+ };
1171
+ this._univerInstanceService.getAllUnitsForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET).forEach((workbook) => {
1172
+ handleWorkbook(workbook);
1173
+ });
1174
+ this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe((unit) => {
1175
+ if (unit.type === _univerjs_core.UniverInstanceType.UNIVER_SHEET) handleWorkbook(unit);
1176
+ }));
1177
+ }
1178
+ _initWorkbookUnload() {
1179
+ this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe((unit) => {
1180
+ if (unit.type === _univerjs_core.UniverInstanceType.UNIVER_SHEET) {
1181
+ const workbook = unit;
1182
+ const unitId = workbook.getUnitId();
1183
+ workbook.getSheets().forEach((sheet) => {
1184
+ const subUnitId = sheet.getSheetId();
1185
+ this._enusreMap(unitId, subUnitId).forValue((row, col, dispose) => {
1186
+ if (dispose) dispose.dispose();
1187
+ });
1188
+ });
1189
+ this._refRangeMap.delete(unitId);
1190
+ }
1191
+ }));
1192
+ }
1193
+ _initSetRangesListener() {
1194
+ this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
1195
+ if (commandInfo.id === _univerjs_sheets.SetRangeValuesMutation.id) {
1196
+ const { unitId, subUnitId, cellValue } = commandInfo.params;
1197
+ const map = this._enusreMap(unitId, subUnitId);
1198
+ if (cellValue) new _univerjs_core.ObjectMatrix(cellValue).forValue((row, col, cell) => {
1199
+ const dispose = map.getValue(row, col);
1200
+ if (dispose) dispose.dispose();
1201
+ if (cell && cell.p) this._registerRange(unitId, subUnitId, row, col, cell.p);
1202
+ });
1203
+ }
1204
+ }));
1205
+ this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
1206
+ if (commandInfo.id === UpdateRichHyperLinkMutation.id) {
1207
+ const { unitId, subUnitId, row, col } = commandInfo.params;
1208
+ const sheetTarget = (0, _univerjs_sheets.getSheetCommandTarget)(this._univerInstanceService, {
1209
+ unitId,
1210
+ subUnitId
1211
+ });
1212
+ const dispose = this._enusreMap(unitId, subUnitId).getValue(row, col);
1213
+ if (dispose) dispose.dispose();
1214
+ if (sheetTarget) {
1215
+ const { worksheet } = sheetTarget;
1216
+ const cell = worksheet.getCellRaw(row, col);
1217
+ if (cell && cell.p) this._registerRange(unitId, subUnitId, row, col, cell.p);
1218
+ }
1219
+ }
1220
+ }));
1221
+ }
1222
+ };
1223
+ SheetsHyperLinkRichTextRefRangeController = __decorate([
1224
+ __decorateParam(0, _univerjs_core.ICommandService),
1225
+ __decorateParam(1, _univerjs_core.IUniverInstanceService),
1226
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets.RefRangeService))
1227
+ ], SheetsHyperLinkRichTextRefRangeController);
1228
+
1229
+ //#endregion
1230
+ //#region src/controllers/set-range.controller.ts
1231
+ let SheetHyperLinkSetRangeController = class SheetHyperLinkSetRangeController extends _univerjs_core.Disposable {
1232
+ constructor(_sheetInterceptorService, _hyperLinkModel, _selectionManagerService, _univerInstanceService) {
1233
+ super();
1234
+ this._sheetInterceptorService = _sheetInterceptorService;
1235
+ this._hyperLinkModel = _hyperLinkModel;
1236
+ this._selectionManagerService = _selectionManagerService;
1237
+ this._univerInstanceService = _univerInstanceService;
1238
+ this._initCommandInterceptor();
1239
+ this._initAfterEditor();
1240
+ }
1241
+ _initCommandInterceptor() {
1242
+ this._initSetRangeValuesCommandInterceptor();
1243
+ this._initClearSelectionCommandInterceptor();
1244
+ }
1245
+ _initSetRangeValuesCommandInterceptor() {
1246
+ this.disposeWithMe(this._sheetInterceptorService.interceptCommand({ getMutations: (command) => {
1247
+ if (command.id === _univerjs_sheets.SetRangeValuesCommand.id) {
1248
+ const params = command.params;
1249
+ const { unitId, subUnitId } = params;
1250
+ const redos = [];
1251
+ const undos = [];
1252
+ if (params.cellValue) new _univerjs_core.ObjectMatrix(params.cellValue).forValue((row, col) => {
1253
+ const link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, col);
1254
+ if (link) {
1255
+ redos.push({
1256
+ id: RemoveHyperLinkMutation.id,
1257
+ params: {
1258
+ unitId,
1259
+ subUnitId,
1260
+ id: link.id
1261
+ }
1262
+ });
1263
+ undos.push({
1264
+ id: AddHyperLinkMutation.id,
1265
+ params: {
1266
+ unitId,
1267
+ subUnitId,
1268
+ link
1269
+ }
1270
+ });
1271
+ }
1272
+ });
1273
+ return {
1274
+ undos,
1275
+ redos
1276
+ };
1277
+ }
1278
+ return {
1279
+ redos: [],
1280
+ undos: []
1281
+ };
1282
+ } }));
1283
+ }
1284
+ _initClearSelectionCommandInterceptor() {
1285
+ this.disposeWithMe(this._sheetInterceptorService.interceptCommand({ getMutations: (command) => {
1286
+ if (command.id === _univerjs_sheets.ClearSelectionContentCommand.id || command.id === _univerjs_sheets.ClearSelectionAllCommand.id || command.id === _univerjs_sheets.ClearSelectionFormatCommand.id) {
1287
+ const redos = [];
1288
+ const undos = [];
1289
+ const selection = this._selectionManagerService.getCurrentLastSelection();
1290
+ const target = (0, _univerjs_sheets.getSheetCommandTarget)(this._univerInstanceService, command.params);
1291
+ if (selection && target) {
1292
+ const { unitId, subUnitId } = target;
1293
+ _univerjs_core.Range.foreach(selection.range, (row, col) => {
1294
+ const link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, col);
1295
+ if (link) {
1296
+ redos.push({
1297
+ id: RemoveHyperLinkMutation.id,
1298
+ params: {
1299
+ unitId,
1300
+ subUnitId,
1301
+ id: link.id
1302
+ }
1303
+ });
1304
+ undos.push({
1305
+ id: AddHyperLinkMutation.id,
1306
+ params: {
1307
+ unitId,
1308
+ subUnitId,
1309
+ link
1310
+ }
1311
+ });
1312
+ }
1313
+ });
1314
+ }
1315
+ return {
1316
+ redos,
1317
+ undos
1318
+ };
1319
+ }
1320
+ return {
1321
+ redos: [],
1322
+ undos: []
1323
+ };
1324
+ } }));
1325
+ }
1326
+ _initAfterEditor() {
1327
+ this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(_univerjs_sheets.AFTER_CELL_EDIT, { handler: (cell, context, next) => {
1328
+ if (!cell || cell.p) return next(cell);
1329
+ if (typeof cell.v === "string" && _univerjs_core.Tools.isLegalUrl(cell.v) && cell.v[cell.v.length - 1] !== " ") {
1330
+ const { unitId, subUnitId, row, col } = context;
1331
+ const link = _univerjs_core.Tools.normalizeUrl(cell.v);
1332
+ const workbook = this._univerInstanceService.getUnit(unitId, _univerjs_core.UniverInstanceType.UNIVER_SHEET);
1333
+ const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
1334
+ if (!worksheet) return next(cell);
1335
+ const doc = worksheet.getBlankCellDocumentModel(cell, row, col);
1336
+ if (!doc.documentModel) return next(cell);
1337
+ const textX = _univerjs_core.BuildTextUtils.selection.replace({
1338
+ selection: {
1339
+ startOffset: 0,
1340
+ endOffset: cell.v.length,
1341
+ collapsed: false
1342
+ },
1343
+ body: {
1344
+ dataStream: `${cell.v}`,
1345
+ customRanges: [{
1346
+ startIndex: 0,
1347
+ endIndex: cell.v.length - 1,
1348
+ rangeId: (0, _univerjs_core.generateRandomId)(),
1349
+ rangeType: _univerjs_core.CustomRangeType.HYPERLINK,
1350
+ properties: { url: link }
1351
+ }]
1352
+ },
1353
+ doc: doc.documentModel
1354
+ });
1355
+ if (!textX) return next(cell);
1356
+ const body = doc.documentModel.getBody();
1357
+ _univerjs_core.TextX.apply(body, textX.serialize());
1358
+ return next({
1359
+ ...cell,
1360
+ p: {
1361
+ id: _univerjs_core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
1362
+ body,
1363
+ documentStyle: { pageSize: {
1364
+ width: Infinity,
1365
+ height: Infinity
1366
+ } }
1367
+ }
1368
+ });
1369
+ }
1370
+ return next(cell);
1371
+ } }));
1372
+ }
1373
+ };
1374
+ SheetHyperLinkSetRangeController = __decorate([
1375
+ __decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
1376
+ __decorateParam(1, (0, _univerjs_core.Inject)(HyperLinkModel)),
1377
+ __decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetsSelectionsService)),
1378
+ __decorateParam(3, _univerjs_core.IUniverInstanceService)
1379
+ ], SheetHyperLinkSetRangeController);
1380
+
1381
+ //#endregion
1382
+ //#region src/controllers/sheet-hyper-link.controller.ts
1383
+ /**
1384
+ * Copyright 2023-present DreamNum Co., Ltd.
1385
+ *
1386
+ * Licensed under the Apache License, Version 2.0 (the "License");
1387
+ * you may not use this file except in compliance with the License.
1388
+ * You may obtain a copy of the License at
1389
+ *
1390
+ * http://www.apache.org/licenses/LICENSE-2.0
1391
+ *
1392
+ * Unless required by applicable law or agreed to in writing, software
1393
+ * distributed under the License is distributed on an "AS IS" BASIS,
1394
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1395
+ * See the License for the specific language governing permissions and
1396
+ * limitations under the License.
1397
+ */
1398
+ let SheetsHyperLinkController = class SheetsHyperLinkController extends _univerjs_core.Disposable {
1399
+ constructor(_commandService) {
1400
+ super();
1401
+ this._commandService = _commandService;
1402
+ this._registerCommands();
1403
+ }
1404
+ _registerCommands() {
1405
+ [
1406
+ AddHyperLinkCommand,
1407
+ UpdateHyperLinkCommand,
1408
+ CancelHyperLinkCommand,
1409
+ UpdateRichHyperLinkCommand,
1410
+ CancelRichHyperLinkCommand,
1411
+ AddRichHyperLinkCommand,
1412
+ AddHyperLinkMutation,
1413
+ UpdateHyperLinkMutation,
1414
+ RemoveHyperLinkMutation,
1415
+ UpdateHyperLinkRefMutation,
1416
+ UpdateRichHyperLinkMutation
1417
+ ].forEach((command) => {
1418
+ this._commandService.registerCommand(command);
1419
+ });
1420
+ }
1421
+ };
1422
+ SheetsHyperLinkController = __decorate([__decorateParam(0, _univerjs_core.ICommandService)], SheetsHyperLinkController);
1423
+
1424
+ //#endregion
1425
+ //#region src/types/enums/hyper-link-type.ts
1426
+ /**
1427
+ * Copyright 2023-present DreamNum Co., Ltd.
1428
+ *
1429
+ * Licensed under the Apache License, Version 2.0 (the "License");
1430
+ * you may not use this file except in compliance with the License.
1431
+ * You may obtain a copy of the License at
1432
+ *
1433
+ * http://www.apache.org/licenses/LICENSE-2.0
1434
+ *
1435
+ * Unless required by applicable law or agreed to in writing, software
1436
+ * distributed under the License is distributed on an "AS IS" BASIS,
1437
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1438
+ * See the License for the specific language governing permissions and
1439
+ * limitations under the License.
1440
+ */
1441
+ let SheetHyperLinkType = /* @__PURE__ */ function(SheetHyperLinkType) {
1442
+ SheetHyperLinkType["SHEET"] = "gid";
1443
+ SheetHyperLinkType["RANGE"] = "range";
1444
+ SheetHyperLinkType["DEFINE_NAME"] = "rangeid";
1445
+ SheetHyperLinkType["INVALID"] = "invalid";
1446
+ SheetHyperLinkType["URL"] = "url";
1447
+ return SheetHyperLinkType;
1448
+ }({});
1449
+
1450
+ //#endregion
1451
+ //#region src/services/parser.service.ts
1452
+ let SheetsHyperLinkParserService = class SheetsHyperLinkParserService {
1453
+ constructor(_univerInstanceService, _localeService, _definedNamesService) {
1454
+ this._univerInstanceService = _univerInstanceService;
1455
+ this._localeService = _localeService;
1456
+ this._definedNamesService = _definedNamesService;
1457
+ }
1458
+ buildHyperLink(unitId, sheetId, range) {
1459
+ return `#${SheetHyperLinkType.SHEET}=${sheetId}${range ? `&${typeof range === "string" ? SheetHyperLinkType.DEFINE_NAME : SheetHyperLinkType.RANGE}=${typeof range === "string" ? range : (0, _univerjs_engine_formula.serializeRange)(range)}` : ""}`;
1460
+ }
1461
+ parseHyperLink(urlStr) {
1462
+ if (urlStr.startsWith("#")) {
1463
+ var _search$get, _search$get2, _search$get3, _search$get4;
1464
+ const search = new URLSearchParams(urlStr.slice(1));
1465
+ const searchObj = {
1466
+ gid: (_search$get = search.get("gid")) !== null && _search$get !== void 0 ? _search$get : "",
1467
+ range: (_search$get2 = search.get("range")) !== null && _search$get2 !== void 0 ? _search$get2 : "",
1468
+ rangeid: (_search$get3 = search.get("rangeid")) !== null && _search$get3 !== void 0 ? _search$get3 : "",
1469
+ unitid: (_search$get4 = search.get("unitid")) !== null && _search$get4 !== void 0 ? _search$get4 : ""
1470
+ };
1471
+ const urlInfo = this._getURLName(searchObj);
1472
+ return {
1473
+ type: urlInfo.type,
1474
+ name: urlInfo.name,
1475
+ url: urlStr,
1476
+ searchObj
1477
+ };
1478
+ } else return {
1479
+ type: SheetHyperLinkType.URL,
1480
+ name: urlStr,
1481
+ url: urlStr,
1482
+ searchObj: null
1483
+ };
1484
+ }
1485
+ _getURLName(params) {
1486
+ var _sheet$getName;
1487
+ const { gid, range, rangeid, unitid } = params;
1488
+ const workbook = unitid ? this._univerInstanceService.getUnit(unitid, _univerjs_core.UniverInstanceType.UNIVER_SHEET) : this._univerInstanceService.getCurrentUnitForType(_univerjs_core.UniverInstanceType.UNIVER_SHEET);
1489
+ const invalidLink = {
1490
+ type: SheetHyperLinkType.INVALID,
1491
+ name: this._localeService.t("hyperLink.message.refError")
1492
+ };
1493
+ if (!workbook) return invalidLink;
1494
+ const sheet = gid ? workbook.getSheetBySheetId(gid) : workbook.getActiveSheet();
1495
+ const sheetName = (_sheet$getName = sheet === null || sheet === void 0 ? void 0 : sheet.getName()) !== null && _sheet$getName !== void 0 ? _sheet$getName : "";
1496
+ if (range) {
1497
+ if (!sheet) return invalidLink;
1498
+ const rangeObj = (0, _univerjs_engine_formula.deserializeRangeWithSheet)(range).range;
1499
+ if ((0, _univerjs_core.isValidRange)(rangeObj, sheet) && range !== "err") return {
1500
+ type: SheetHyperLinkType.RANGE,
1501
+ name: (0, _univerjs_engine_formula.serializeRangeWithSheet)(sheetName, rangeObj)
1502
+ };
1503
+ return invalidLink;
1504
+ }
1505
+ if (rangeid) {
1506
+ const range = this._definedNamesService.getValueById(workbook.getUnitId(), rangeid);
1507
+ if (range) return {
1508
+ type: SheetHyperLinkType.DEFINE_NAME,
1509
+ name: range.formulaOrRefString
1510
+ };
1511
+ return invalidLink;
1512
+ }
1513
+ if (gid) {
1514
+ const worksheet = workbook.getSheetBySheetId(gid);
1515
+ if (worksheet) return {
1516
+ type: SheetHyperLinkType.SHEET,
1517
+ name: worksheet.getName()
1518
+ };
1519
+ return invalidLink;
1520
+ }
1521
+ return invalidLink;
1522
+ }
1523
+ };
1524
+ SheetsHyperLinkParserService = __decorate([
1525
+ __decorateParam(0, _univerjs_core.IUniverInstanceService),
1526
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService)),
1527
+ __decorateParam(2, _univerjs_engine_formula.IDefinedNamesService)
1528
+ ], SheetsHyperLinkParserService);
1529
+
1530
+ //#endregion
1531
+ //#region src/plugin.ts
1532
+ let UniverSheetsHyperLinkPlugin = class UniverSheetsHyperLinkPlugin extends _univerjs_core.Plugin {
1533
+ constructor(_config = defaultPluginConfig, _injector, _configService) {
1534
+ super();
1535
+ this._config = _config;
1536
+ this._injector = _injector;
1537
+ this._configService = _configService;
1538
+ const { ...rest } = (0, _univerjs_core.merge)({}, defaultPluginConfig, this._config);
1539
+ this._configService.setConfig(SHEETS_HYPER_LINK_PLUGIN_CONFIG_KEY, rest);
1540
+ }
1541
+ onStarting() {
1542
+ (0, _univerjs_core.registerDependencies)(this._injector, [
1543
+ [HyperLinkModel],
1544
+ [SheetsHyperLinkParserService],
1545
+ [SheetsHyperLinkController],
1546
+ [SheetsHyperLinkRefRangeController],
1547
+ [SheetHyperLinkSetRangeController],
1548
+ [SheetsHyperLinkRemoveSheetController],
1549
+ [SheetsHyperLinkRichTextRefRangeController]
1550
+ ]);
1551
+ (0, _univerjs_core.touchDependencies)(this._injector, [
1552
+ [SheetsHyperLinkRefRangeController],
1553
+ [SheetsHyperLinkController],
1554
+ [SheetHyperLinkSetRangeController],
1555
+ [SheetsHyperLinkRemoveSheetController],
1556
+ [SheetsHyperLinkRichTextRefRangeController]
1557
+ ]);
1558
+ }
1559
+ };
1560
+ _defineProperty(UniverSheetsHyperLinkPlugin, "pluginName", SHEET_HYPER_LINK_PLUGIN);
1561
+ _defineProperty(UniverSheetsHyperLinkPlugin, "packageName", name);
1562
+ _defineProperty(UniverSheetsHyperLinkPlugin, "version", version);
1563
+ _defineProperty(UniverSheetsHyperLinkPlugin, "type", _univerjs_core.UniverInstanceType.UNIVER_SHEET);
1564
+ UniverSheetsHyperLinkPlugin = __decorate([
1565
+ (0, _univerjs_core.DependentOn)(_univerjs_sheets.UniverSheetsPlugin),
1566
+ __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
1567
+ __decorateParam(2, _univerjs_core.IConfigService)
1568
+ ], UniverSheetsHyperLinkPlugin);
1569
+
1570
+ //#endregion
1571
+ exports.AddHyperLinkCommand = AddHyperLinkCommand;
1572
+ exports.AddHyperLinkMutation = AddHyperLinkMutation;
1573
+ exports.AddRichHyperLinkCommand = AddRichHyperLinkCommand;
1574
+ exports.CancelHyperLinkCommand = CancelHyperLinkCommand;
1575
+ exports.CancelRichHyperLinkCommand = CancelRichHyperLinkCommand;
1576
+ exports.ERROR_RANGE = ERROR_RANGE;
1577
+ Object.defineProperty(exports, 'HyperLinkModel', {
1578
+ enumerable: true,
1579
+ get: function () {
1580
+ return HyperLinkModel;
1581
+ }
1582
+ });
1583
+ exports.RemoveHyperLinkMutation = RemoveHyperLinkMutation;
1584
+ exports.SheetHyperLinkType = SheetHyperLinkType;
1585
+ Object.defineProperty(exports, 'SheetsHyperLinkParserService', {
1586
+ enumerable: true,
1587
+ get: function () {
1588
+ return SheetsHyperLinkParserService;
1589
+ }
1590
+ });
1591
+ Object.defineProperty(exports, 'UniverSheetsHyperLinkPlugin', {
1592
+ enumerable: true,
1593
+ get: function () {
1594
+ return UniverSheetsHyperLinkPlugin;
1595
+ }
1596
+ });
1597
+ exports.UpdateHyperLinkCommand = UpdateHyperLinkCommand;
1598
+ exports.UpdateHyperLinkMutation = UpdateHyperLinkMutation;
1599
+ exports.UpdateHyperLinkRefMutation = UpdateHyperLinkRefMutation;
1600
+ exports.UpdateRichHyperLinkCommand = UpdateRichHyperLinkCommand;