@univerjs/sheets-hyper-link 0.5.0 → 0.5.1-nightly.202411301606

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 Se=Object.defineProperty;var Ie=(i,t,e)=>t in i?Se(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var C=(i,t,e)=>Ie(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),Re=require("rxjs"),g=require("@univerjs/sheets"),U=require("@univerjs/engine-formula"),Z=require("@univerjs/docs");var Me=Object.defineProperty,Ce=Object.getOwnPropertyDescriptor,Ue=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ce(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Me(t,e,r),r},Le=(i,t)=>(e,n)=>t(e,n,i);exports.HyperLinkModel=class extends o.Disposable{constructor(e){super();C(this,"_linkUpdate$",new Re.Subject);C(this,"linkUpdate$",this._linkUpdate$.asObservable());C(this,"_linkMap",new Map);C(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let r=this._linkMap.get(e);r||(r=new Map,this._linkMap.set(e,r));let s=r.get(n);s||(s=new o.ObjectMatrix,r.set(n,s));let a=this._linkPositionMap.get(e);a||(a=new Map,this._linkPositionMap.set(e,a));let d=a.get(n);return d||(d=new Map,a.set(n,d)),{matrix:s,positionMap:d}}addHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n);return s.setValue(r.row,r.column,r),a.set(r.id,{row:r.row,column:r.column,link:r}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:r,type:"add"}),!0}updateHyperLink(e,n,r,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(r);if(!l)return!0;const 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=Ue([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 we="sheets-hyper-link.config",ke={},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)}},k={type:o.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,id:s}=t;return e.removeHyperLink(n,r,s)}},F={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,payload:s,id:a}=t;return e.updateHyperLink(n,r,a,s,!1)}},z={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,id:s,row:a,column:d,silent:c}=t;return e.updateHyperLinkRef(n,r,s,{row:a,column:d},c)}},B={type:o.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(i,t){var f,h,_;if(!t)return!1;const{unitId:e,subUnitId:n,row:r,col:s,id:a,url:d}=t,c=i.get(o.IUniverInstanceService),l=g.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:p}=l,u=p.getCellRaw(r,s),m=(_=(h=(f=u==null?void 0:u.p)==null?void 0:f.body)==null?void 0:h.customRanges)==null?void 0:_.find(S=>S.rangeType===o.CustomRangeType.HYPERLINK&&S.rangeId===a);return m&&(m.properties.url=d),!0}},ce="SHEET_HYPER_LINK_PLUGIN",x="err";var Ee=Object.defineProperty,be=Object.getOwnPropertyDescriptor,Pe=(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 K=class extends o.Disposable{constructor(t,e,n,r){super();C(this,"_disposableMap",new Map);C(this,"_watchDisposableMap",new Map);C(this,"_rangeDisableMap",new Map);C(this,"_rangeWatcherMap",new Map);C(this,"_handlePositionChange",(t,e,n,r,s)=>{const a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return r?{redos:[{id:z.id,params:{unitId:t,subUnitId:e,id:n.id,row:r.startRow,column:r.startColumn,silent:s}}],undos:[{id:z.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: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=U.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&&U.serializeRange(h)===U.serializeRange(u)?{redos:[],undos:[]}:{redos:[{id:F.id,params:{unitId:t,subUnitId:p,id:e,payload:{payload:`#gid=${p}&range=${h?U.serializeRange(h):"err"}`}}}],undos:[{id:F.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?U.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()}))}};K=Pe([A(0,o.Inject(g.RefRangeService)),A(1,o.Inject(exports.HyperLinkModel)),A(2,o.Inject(g.SheetsSelectionsService)),A(3,o.ICommandService)],K);var Te=Object.defineProperty,He=Object.getOwnPropertyDescriptor,Ne=(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&&Te(t,e,r),r},te=(i,t)=>(e,n)=>t(e,n,i);let G=class extends o.Disposable{constructor(i,t,e){super(),this._sheetInterceptorService=i,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{var t;if(i.id===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:k.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=Ne([te(0,o.Inject(g.SheetInterceptorService)),te(1,o.IUniverInstanceService),te(2,o.Inject(exports.HyperLinkModel))],G);var Oe=Object.defineProperty,De=Object.getOwnPropertyDescriptor,Ve=(i,t,e,n)=>{for(var r=n>1?void 0:n?De(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Oe(t,e,r),r},ne=(i,t)=>(e,n)=>t(e,n,i);let Y=class extends o.Disposable{constructor(t,e,n){super();C(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let r=n.get(e);return r||(r=new o.ObjectMatrix,n.set(e,r)),r}_isLegalRangeUrl(t,e){var r,s,a;const n=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(r=d.get("gid"))!=null?r:"",range:(s=d.get("range"))!=null?s:"",rangeid:(a=d.get("rangeid"))!=null?a:""};if(c.range&&c.gid){const l=c.gid,p=n.getSheetBySheetId(l);if(!p)return null;const u=U.deserializeRangeWithSheet(c.range).range;if(o.isValidRange(u,p)&&c.range!==x)return{range:u,worksheet:p}}}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,S=this._isLegalRangeUrl(t,_);if(S){const{range:y,worksheet:M}=S;m=!0,u.add(this._refRangeService.registerRefRange(y,v=>{const I=g.handleDefaultRangeChangeWithEffectRefCommands(y,v);return I&&o.Rectangle.equals(I,y)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:r,id:f.rangeId,url:`#gid=${e}&range=${I?U.serializeRange(I):x}`}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:r,id:f.rangeId,url:_}}],redos:[]}},M.getUnitId(),M.getSheetId()))}}}),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)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===B.id){const e=t.params,{unitId:n,subUnitId:r,row:s,col:a}=e,d=g.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:r}),l=this._enusreMap(n,r).getValue(s,a);if(l&&l.dispose(),d){const{worksheet:p}=d,u=p.getCellRaw(s,a);u&&u.p&&this._registerRange(n,r,s,a,u.p)}}}))}};Y=Ve([ne(0,o.ICommandService),ne(1,o.IUniverInstanceService),ne(2,o.Inject(g.RefRangeService))],Y);var xe=Object.defineProperty,$e=Object.getOwnPropertyDescriptor,je=(i,t,e,n)=>{for(var r=n>1?void 0:n?$e(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&&xe(t,e,r),r},W=(i,t)=>(e,n)=>t(e,n,i);let q=class extends o.Disposable{constructor(i,t,e,n){super(),this._sheetInterceptorService=i,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(i.id===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:k.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:k.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)}}))}};q=je([W(0,o.Inject(g.SheetInterceptorService)),W(1,o.Inject(exports.HyperLinkModel)),W(2,o.Inject(g.SheetsSelectionsService)),W(3,o.IUniverInstanceService)],q);const le={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:S,id:y}=m,M=u.getCell(_,S),v=u.getBlankCellDocumentModel(M),I=v.documentModel.getSnapshot(),R=o.Tools.deepClone(I.body);if(!R)return!1;let E;if(h?E=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:R.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}):E=o.BuildTextUtils.customRange.add({body:R,ranges:[{startOffset:0,endOffset:R.dataStream.length-2,collapsed:!1}],rangeId:y,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:f,refId:y}}),!E)return!1;const D=o.TextX.apply(R,E.serialize()),b={p:{...I,body:D},t:o.CellValueType.STRING},T=await a.onWriteCell(p,u,_,S,b),H={unitId:c,subUnitId:l,cellValue:{[m.row]:{[m.column]:T}}},Q={id:g.SetRangeValuesMutation.id,params:H},$=g.SetRangeValuesUndoMutationFactory(i,H),ee={id:g.SetRangeValuesMutation.id,params:$},V=[Q],N=[ee],O=s.getHyperLinkByLocation(c,l,_,S);return O&&(V.push({id:k.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}},pe={id:"sheets.command.add-rich-hyper-link",type:o.CommandType.COMMAND,handler:async(i,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,r=i.get(o.ICommandService),s=o.generateRandomId(),{payload:a}=n,d=Z.addCustomRangeBySelectionFactory(i,{unitId:e,rangeId:s,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:a,refId:s}});return d?r.syncExecuteCommand(d.id,d.params):!1}},ue={type:o.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(i,t){var b,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=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(!((T=(b=_.body)==null?void 0:b.customRanges)==null?void 0:T.find(H=>H.rangeId===l)))return!1;const y=o.BuildTextUtils.customRange.delete(i,{documentDataModel:h.documentModel,rangeId:l});if(!y)return!1;const M=o.TextX.apply(_.body,y.serialize()),v=[],I=[],R={unitId:p,subUnitId:u,cellValue:{[d]:{[c]:{p:{..._,body:M},t:o.CellValueType.STRING}}}};v.push({id:g.SetRangeValuesMutation.id,params:R});const E=g.SetRangeValuesUndoMutationFactory(i,R);I.push({id:g.SetRangeValuesMutation.id,params:E});const D=s.getHyperLinkByLocation(p,u,d,c);return D&&(v.push({id:k.id,params:{unitId:p,subUnitId:u,id:l}}),I.push({id:w.id,params:{unitId:p,subUnitId:u,link:{...D}}})),o.sequenceExecute(v,e).result?(n.pushUndoRedo({redoMutations:v,undoMutations:I,unitID:p}),!0):!1}},he={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=Z.deleteCustomRangeFactory(i,{unitId:n,rangeId:e,insert:c});return l?r.syncExecuteCommand(l.id,l.params):!1}},ge={type:o.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(i,t){var ie,se,ae;if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=i.get(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:S,display:y=""}=c,M=f.getCell(l,p);if(!M)return!1;const v=f.getCellDocumentModelWithFormula(M);if(!(v!=null&&v.documentModel))return!1;const I=v.documentModel.getSnapshot(),R=(se=(ie=I.body)==null?void 0:ie.customRanges)==null?void 0:se.find(ve=>ve.rangeId===u);if(!R)return!1;const E=o.generateRandomId(),P=(ae=o.getBodySlice(v.documentModel.getBody(),R.startIndex,R.endIndex+1).textRuns)==null?void 0:ae[0];P&&(P.ed=y.length+1);const b=Z.replaceSelectionFactory(i,{unitId:h,body:{dataStream:`${y}`,customRanges:[{rangeId:E,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:y.length-1,properties:{url:S}}],textRuns:P?[P]:void 0},selection:{startOffset:R.startIndex,endOffset:R.endIndex+1,collapsed:!1},doc:v.documentModel});if(!b)return!1;const T=o.TextX.apply(o.Tools.deepClone(I.body),b.textX.serialize()),H={p:{...I,body:T},t:o.CellValueType.STRING},Q=await a.onWriteCell(m,f,l,p,H),$={id:g.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:_,cellValue:{[l]:{[p]:Q}}}},ee=g.SetRangeValuesUndoMutationFactory(i,$.params),V={id:g.SetRangeValuesMutation.id,params:ee},N=[$],O=[V],j=s.getHyperLinkByLocation(h,_,l,p);return j&&(N.push({id:k.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}},me={type:o.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(i,t)=>{var h,_,S,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(M=>M.rangeId===r);if(!c)return!1;const l=(S=t.payload.display)!=null?S:"",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=Z.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 Ae=Object.defineProperty,We=Object.getOwnPropertyDescriptor,Be=(i,t,e,n)=>{for(var r=n>1?void 0:n?We(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&&Ae(t,e,r),r},Fe=(i,t)=>(e,n)=>t(e,n,i);let J=class extends o.Disposable{constructor(i){super(),this._commandService=i,this._registerCommands()}_registerCommands(){[le,ge,ue,me,he,pe,w,F,k,z,B].forEach(i=>{this._commandService.registerCommand(i)})}};J=Be([Fe(0,o.ICommandService)],J);var fe=(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))(fe||{}),ze=Object.defineProperty,Ke=Object.getOwnPropertyDescriptor,Ge=(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&&ze(t,e,r),r},oe=(i,t)=>(e,n)=>t(e,n,i);let X=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:ce,businesses:[fe.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)})})}}))}};X=Ge([oe(0,o.IResourceManagerService),oe(1,o.Inject(exports.HyperLinkModel))],X);var Ye=Object.defineProperty,qe=Object.getOwnPropertyDescriptor,Je=(i,t,e,n)=>{for(var r=n>1?void 0:n?qe(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&&Ye(t,e,r),r},re=(i,t)=>(e,n)=>t(e,n,i);exports.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${L.SHEET}=${e}${n?`&${typeof n=="string"?L.DEFINE_NAME:L.RANGE}=${typeof n=="string"?n:U.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=U.deserializeRangeWithSheet(n).range;return o.isValidRange(u,c)&&n!==x?{type:L.RANGE,name:U.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=Je([re(0,o.IUniverInstanceService),re(1,o.Inject(o.LocaleService)),re(2,U.IDefinedNamesService)],exports.SheetsHyperLinkParserService);var _e=Object.defineProperty,Xe=Object.getOwnPropertyDescriptor,Ze=(i,t,e)=>t in i?_e(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,Qe=(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&&_e(t,e,r),r},de=(i,t)=>(e,n)=>t(e,n,i),ye=(i,t,e)=>Ze(i,typeof t!="symbol"?t+"":t,e);exports.UniverSheetsHyperLinkPlugin=class extends o.Plugin{constructor(t=ke,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...r}=this._config;this._configService.setConfig(we,r)}onStarting(){o.registerDependencies(this._injector,[[exports.HyperLinkModel],[exports.SheetsHyperLinkParserService],[X],[J],[K],[q],[G],[Y]]),o.touchDependencies(this._injector,[[K],[X],[J],[q],[G],[Y]])}};ye(exports.UniverSheetsHyperLinkPlugin,"pluginName",ce);ye(exports.UniverSheetsHyperLinkPlugin,"type",o.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsHyperLinkPlugin=Qe([o.DependentOn(g.UniverSheetsPlugin),de(1,o.Inject(o.Injector)),de(2,o.IConfigService)],exports.UniverSheetsHyperLinkPlugin);exports.AddHyperLinkCommand=le;exports.AddHyperLinkMutation=w;exports.AddRichHyperLinkCommand=pe;exports.CancelHyperLinkCommand=ue;exports.CancelRichHyperLinkCommand=he;exports.ERROR_RANGE=x;exports.RemoveHyperLinkMutation=k;exports.SheetHyperLinkType=L;exports.UpdateHyperLinkCommand=ge;exports.UpdateHyperLinkMutation=F;exports.UpdateHyperLinkRefMutation=z;exports.UpdateRichHyperLinkCommand=me;
1
+ "use strict";var Se=Object.defineProperty;var Ie=(i,t,e)=>t in i?Se(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var C=(i,t,e)=>Ie(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),Re=require("rxjs"),g=require("@univerjs/sheets"),U=require("@univerjs/engine-formula"),Z=require("@univerjs/docs");var Me=Object.defineProperty,Ce=Object.getOwnPropertyDescriptor,Ue=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ce(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Me(t,e,r),r},Le=(i,t)=>(e,n)=>t(e,n,i);exports.HyperLinkModel=class extends o.Disposable{constructor(e){super();C(this,"_linkUpdate$",new Re.Subject);C(this,"linkUpdate$",this._linkUpdate$.asObservable());C(this,"_linkMap",new Map);C(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let r=this._linkMap.get(e);r||(r=new Map,this._linkMap.set(e,r));let s=r.get(n);s||(s=new o.ObjectMatrix,r.set(n,s));let a=this._linkPositionMap.get(e);a||(a=new Map,this._linkPositionMap.set(e,a));let d=a.get(n);return d||(d=new Map,a.set(n,d)),{matrix:s,positionMap:d}}addHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n);return s.setValue(r.row,r.column,r),a.set(r.id,{row:r.row,column:r.column,link:r}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:r,type:"add"}),!0}updateHyperLink(e,n,r,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(r);if(!l)return!0;const 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=Ue([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 we="sheets-hyper-link.config",Ee={},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)}},F={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,payload:s,id:a}=t;return e.updateHyperLink(n,r,a,s,!1)}},K={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,id:s,row:a,column:d,silent:c}=t;return e.updateHyperLinkRef(n,r,s,{row:a,column:d},c)}},B={type:o.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(i,t){var f,h,_;if(!t)return!1;const{unitId:e,subUnitId:n,row:r,col:s,id:a,url:d}=t,c=i.get(o.IUniverInstanceService),l=g.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:p}=l,u=p.getCellRaw(r,s),m=(_=(h=(f=u==null?void 0:u.p)==null?void 0:f.body)==null?void 0:h.customRanges)==null?void 0:_.find(S=>S.rangeType===o.CustomRangeType.HYPERLINK&&S.rangeId===a);return m&&(m.properties.url=d),!0}},ce="SHEET_HYPER_LINK_PLUGIN",x="err";var ke=Object.defineProperty,be=Object.getOwnPropertyDescriptor,Pe=(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&&ke(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();C(this,"_disposableMap",new Map);C(this,"_watchDisposableMap",new Map);C(this,"_rangeDisableMap",new Map);C(this,"_rangeWatcherMap",new Map);C(this,"_handlePositionChange",(t,e,n,r,s)=>{const a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return r?{redos:[{id:K.id,params:{unitId:t,subUnitId:e,id:n.id,row:r.startRow,column:r.startColumn,silent:s}}],undos:[{id:K.id,params:{unitId:t,subUnitId:e,id:n.id,row:a.startRow,column:a.startColumn,silent:s}}]}:{redos:[{id:E.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id: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=U.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&&U.serializeRange(h)===U.serializeRange(u)?{redos:[],undos:[]}:{redos:[{id:F.id,params:{unitId:t,subUnitId:p,id:e,payload:{payload:`#gid=${p}&range=${h?U.serializeRange(h):"err"}`}}}],undos:[{id:F.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?U.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=Pe([A(0,o.Inject(g.RefRangeService)),A(1,o.Inject(exports.HyperLinkModel)),A(2,o.Inject(g.SheetsSelectionsService)),A(3,o.ICommandService)],z);var Te=Object.defineProperty,He=Object.getOwnPropertyDescriptor,Ne=(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&&Te(t,e,r),r},te=(i,t)=>(e,n)=>t(e,n,i);let G=class extends o.Disposable{constructor(i,t,e){super(),this._sheetInterceptorService=i,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{var t;if(i.id===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=Ne([te(0,o.Inject(g.SheetInterceptorService)),te(1,o.IUniverInstanceService),te(2,o.Inject(exports.HyperLinkModel))],G);var Oe=Object.defineProperty,De=Object.getOwnPropertyDescriptor,Ve=(i,t,e,n)=>{for(var r=n>1?void 0:n?De(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Oe(t,e,r),r},ne=(i,t)=>(e,n)=>t(e,n,i);let Y=class extends o.Disposable{constructor(t,e,n){super();C(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let r=n.get(e);return r||(r=new o.ObjectMatrix,n.set(e,r)),r}_isLegalRangeUrl(t,e){var r,s,a;const n=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(r=d.get("gid"))!=null?r:"",range:(s=d.get("range"))!=null?s:"",rangeid:(a=d.get("rangeid"))!=null?a:""};if(c.range&&c.gid){const l=c.gid,p=n.getSheetBySheetId(l);if(!p)return null;const u=U.deserializeRangeWithSheet(c.range).range;if(o.isValidRange(u,p)&&c.range!==x)return{range:u,worksheet:p}}}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,S=this._isLegalRangeUrl(t,_);if(S){const{range:y,worksheet:M}=S;m=!0,u.add(this._refRangeService.registerRefRange(y,v=>{const I=g.handleDefaultRangeChangeWithEffectRefCommands(y,v);return I&&o.Rectangle.equals(I,y)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:r,id:f.rangeId,url:`#gid=${e}&range=${I?U.serializeRange(I):x}`}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:r,id:f.rangeId,url:_}}],redos:[]}},M.getUnitId(),M.getSheetId()))}}}),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)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===B.id){const e=t.params,{unitId:n,subUnitId:r,row:s,col:a}=e,d=g.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:r}),l=this._enusreMap(n,r).getValue(s,a);if(l&&l.dispose(),d){const{worksheet:p}=d,u=p.getCellRaw(s,a);u&&u.p&&this._registerRange(n,r,s,a,u.p)}}}))}};Y=Ve([ne(0,o.ICommandService),ne(1,o.IUniverInstanceService),ne(2,o.Inject(g.RefRangeService))],Y);var xe=Object.defineProperty,$e=Object.getOwnPropertyDescriptor,je=(i,t,e,n)=>{for(var r=n>1?void 0:n?$e(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&&xe(t,e,r),r},W=(i,t)=>(e,n)=>t(e,n,i);let q=class extends o.Disposable{constructor(i,t,e,n){super(),this._sheetInterceptorService=i,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(i.id===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)}}))}};q=je([W(0,o.Inject(g.SheetInterceptorService)),W(1,o.Inject(exports.HyperLinkModel)),W(2,o.Inject(g.SheetsSelectionsService)),W(3,o.IUniverInstanceService)],q);var le=(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))(le||{}),Ae=Object.defineProperty,We=Object.getOwnPropertyDescriptor,Be=(i,t,e,n)=>{for(var r=n>1?void 0:n?We(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&&Ae(t,e,r),r},oe=(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:ce,businesses:[le.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=Be([oe(0,o.IResourceManagerService),oe(1,o.Inject(exports.HyperLinkModel))],J);const pe={type:o.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(i,t){if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=i.get(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:S,id:y}=m,M=u.getCell(_,S),v=u.getBlankCellDocumentModel(M),I=v.documentModel.getSnapshot(),R=o.Tools.deepClone(I.body);if(!R)return!1;let k;if(h?k=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:R.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}):k=o.BuildTextUtils.customRange.add({body:R,ranges:[{startOffset:0,endOffset:R.dataStream.length-2,collapsed:!1}],rangeId:y,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:f,refId:y}}),!k)return!1;const D=o.TextX.apply(R,k.serialize()),b={p:{...I,body:D},t:o.CellValueType.STRING},T=await a.onWriteCell(p,u,_,S,b),H={unitId:c,subUnitId:l,cellValue:{[m.row]:{[m.column]:T}}},Q={id:g.SetRangeValuesMutation.id,params:H},$=g.SetRangeValuesUndoMutationFactory(i,H),ee={id:g.SetRangeValuesMutation.id,params:$},V=[Q],N=[ee],O=s.getHyperLinkByLocation(c,l,_,S);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}},ue={id:"sheets.command.add-rich-hyper-link",type:o.CommandType.COMMAND,handler:async(i,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,r=i.get(o.ICommandService),s=o.generateRandomId(),{payload:a}=n,d=Z.addCustomRangeBySelectionFactory(i,{unitId:e,rangeId:s,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:a,refId:s}});return d?r.syncExecuteCommand(d.id,d.params):!1}},he={type:o.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(i,t){var b,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=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(!((T=(b=_.body)==null?void 0:b.customRanges)==null?void 0:T.find(H=>H.rangeId===l)))return!1;const y=o.BuildTextUtils.customRange.delete(i,{documentDataModel:h.documentModel,rangeId:l});if(!y)return!1;const M=o.TextX.apply(_.body,y.serialize()),v=[],I=[],R={unitId:p,subUnitId:u,cellValue:{[d]:{[c]:{p:{..._,body:M},t:o.CellValueType.STRING}}}};v.push({id:g.SetRangeValuesMutation.id,params:R});const k=g.SetRangeValuesUndoMutationFactory(i,R);I.push({id:g.SetRangeValuesMutation.id,params:k});const D=s.getHyperLinkByLocation(p,u,d,c);return D&&(v.push({id:E.id,params:{unitId:p,subUnitId:u,id:l}}),I.push({id:w.id,params:{unitId:p,subUnitId:u,link:{...D}}})),o.sequenceExecute(v,e).result?(n.pushUndoRedo({redoMutations:v,undoMutations:I,unitID:p}),!0):!1}},ge={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=Z.deleteCustomRangeFactory(i,{unitId:n,rangeId:e,insert:c});return l?r.syncExecuteCommand(l.id,l.params):!1}},me={type:o.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(i,t){var ie,se,ae;if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=i.get(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:S,display:y=""}=c,M=f.getCell(l,p);if(!M)return!1;const v=f.getCellDocumentModelWithFormula(M);if(!(v!=null&&v.documentModel))return!1;const I=v.documentModel.getSnapshot(),R=(se=(ie=I.body)==null?void 0:ie.customRanges)==null?void 0:se.find(ve=>ve.rangeId===u);if(!R)return!1;const k=o.generateRandomId(),P=(ae=o.getBodySlice(v.documentModel.getBody(),R.startIndex,R.endIndex+1).textRuns)==null?void 0:ae[0];P&&(P.ed=y.length+1);const b=Z.replaceSelectionFactory(i,{unitId:h,body:{dataStream:`${y}`,customRanges:[{rangeId:k,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:y.length-1,properties:{url:S}}],textRuns:P?[P]:void 0},selection:{startOffset:R.startIndex,endOffset:R.endIndex+1,collapsed:!1},doc:v.documentModel});if(!b)return!1;const T=o.TextX.apply(o.Tools.deepClone(I.body),b.textX.serialize()),H={p:{...I,body:T},t:o.CellValueType.STRING},Q=await a.onWriteCell(m,f,l,p,H),$={id:g.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:_,cellValue:{[l]:{[p]:Q}}}},ee=g.SetRangeValuesUndoMutationFactory(i,$.params),V={id:g.SetRangeValuesMutation.id,params:ee},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}},fe={type:o.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(i,t)=>{var h,_,S,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(M=>M.rangeId===r);if(!c)return!1;const l=(S=t.payload.display)!=null?S:"",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=Z.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 Fe=Object.defineProperty,Ke=Object.getOwnPropertyDescriptor,ze=(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&&Fe(t,e,r),r},Ge=(i,t)=>(e,n)=>t(e,n,i);let X=class extends o.Disposable{constructor(i){super(),this._commandService=i,this._registerCommands()}_registerCommands(){[pe,me,he,fe,ge,ue,w,F,E,K,B].forEach(i=>{this._commandService.registerCommand(i)})}};X=ze([Ge(0,o.ICommandService)],X);var Ye=Object.defineProperty,qe=Object.getOwnPropertyDescriptor,Je=(i,t,e,n)=>{for(var r=n>1?void 0:n?qe(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&&Ye(t,e,r),r},re=(i,t)=>(e,n)=>t(e,n,i);exports.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${L.SHEET}=${e}${n?`&${typeof n=="string"?L.DEFINE_NAME:L.RANGE}=${typeof n=="string"?n:U.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=U.deserializeRangeWithSheet(n).range;return o.isValidRange(u,c)&&n!==x?{type:L.RANGE,name:U.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=Je([re(0,o.IUniverInstanceService),re(1,o.Inject(o.LocaleService)),re(2,U.IDefinedNamesService)],exports.SheetsHyperLinkParserService);var _e=Object.defineProperty,Xe=Object.getOwnPropertyDescriptor,Ze=(i,t,e)=>t in i?_e(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,Qe=(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&&_e(t,e,r),r},de=(i,t)=>(e,n)=>t(e,n,i),ye=(i,t,e)=>Ze(i,typeof t!="symbol"?t+"":t,e);exports.UniverSheetsHyperLinkPlugin=class extends o.Plugin{constructor(t=Ee,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...r}=this._config;this._configService.setConfig(we,r)}onStarting(){o.registerDependencies(this._injector,[[exports.HyperLinkModel],[exports.SheetsHyperLinkParserService],[J],[X],[z],[q],[G],[Y]]),o.touchDependencies(this._injector,[[z],[J],[X],[q],[G],[Y]])}};ye(exports.UniverSheetsHyperLinkPlugin,"pluginName",ce);ye(exports.UniverSheetsHyperLinkPlugin,"type",o.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsHyperLinkPlugin=Qe([o.DependentOn(g.UniverSheetsPlugin),de(1,o.Inject(o.Injector)),de(2,o.IConfigService)],exports.UniverSheetsHyperLinkPlugin);exports.AddHyperLinkCommand=pe;exports.AddHyperLinkMutation=w;exports.AddRichHyperLinkCommand=ue;exports.CancelHyperLinkCommand=he;exports.CancelRichHyperLinkCommand=ge;exports.ERROR_RANGE=x;exports.RemoveHyperLinkMutation=E;exports.SheetHyperLinkType=L;exports.UpdateHyperLinkCommand=me;exports.UpdateHyperLinkMutation=F;exports.UpdateHyperLinkRefMutation=K;exports.UpdateRichHyperLinkCommand=fe;
package/lib/es/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var Te = Object.defineProperty;
2
2
  var Ae = (s, e, t) => e in s ? Te(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
3
  var w = (s, e, t) => Ae(s, typeof e != "symbol" ? e + "" : e, t);
4
- import { Disposable as V, ObjectMatrix as q, UniverInstanceType as I, IUniverInstanceService as E, CommandType as U, CustomRangeType as b, Inject as M, ICommandService as P, sequenceExecuteAsync as ve, isValidRange as Re, toDisposable as We, DisposableCollection as Be, Rectangle as je, Range as Fe, Tools as oe, BuildTextUtils as Z, generateRandomId as de, TextX as ce, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as Ke, IUndoRedoService as Se, CellValueType as Ie, sequenceExecute as Ge, getBodySlice as Pe, IResourceManagerService as Ye, LocaleService as ze, DependentOn as Je, Injector as Xe, Plugin as qe, registerDependencies as Ze, touchDependencies as Qe, IConfigService as et } from "@univerjs/core";
4
+ import { Disposable as V, ObjectMatrix as q, UniverInstanceType as I, IUniverInstanceService as E, CommandType as L, CustomRangeType as b, Inject as M, ICommandService as P, sequenceExecuteAsync as ve, isValidRange as Re, toDisposable as We, DisposableCollection as Be, Rectangle as je, Range as Fe, Tools as oe, BuildTextUtils as Z, generateRandomId as de, TextX as ce, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as Ke, IResourceManagerService as Ye, IUndoRedoService as Se, CellValueType as Ie, sequenceExecute as Ge, getBodySlice as Pe, LocaleService as ze, DependentOn as Je, Injector as Xe, Plugin as qe, registerDependencies as Ze, touchDependencies as Qe, IConfigService as et } from "@univerjs/core";
5
5
  import { Subject as tt } from "rxjs";
6
6
  import { getSheetCommandTarget as j, RefRangeService as Ne, SheetsSelectionsService as Oe, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as nt, handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests as rt, SheetInterceptorService as le, RemoveSheetCommand as st, handleDefaultRangeChangeWithEffectRefCommands as it, SetRangeValuesMutation as H, SetRangeValuesCommand as at, ClearSelectionContentCommand as ot, ClearSelectionAllCommand as dt, ClearSelectionFormatCommand as ct, AFTER_CELL_EDIT as lt, SetRangeValuesUndoMutationFactory as Me, UniverSheetsPlugin as ut } from "@univerjs/sheets";
7
7
  import { deserializeRangeWithSheet as Ce, serializeRange as B, serializeRangeWithSheet as pt, IDefinedNamesService as ht } from "@univerjs/engine-formula";
@@ -140,9 +140,9 @@ let S = class extends V {
140
140
  S = yt([
141
141
  vt(0, E)
142
142
  ], S);
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 Rt = "sheets-hyper-link.config", St = {}, O = {
145
- type: U.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 Rt = "sheets-hyper-link.config", St = {}, O = {
151
151
  return t.addHyperLink(n, r, i);
152
152
  }
153
153
  }, k = {
154
- type: U.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 Rt = "sheets-hyper-link.config", St = {}, O = {
160
160
  return t.removeHyperLink(n, r, i);
161
161
  }
162
162
  }, _e = {
163
- type: U.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 Rt = "sheets-hyper-link.config", St = {}, O = {
169
169
  return t.updateHyperLink(n, r, a, i, !1);
170
170
  }
171
171
  }, me = {
172
- type: U.MUTATION,
172
+ type: L.MUTATION,
173
173
  id: "sheets.mutation.update-hyper-link-ref",
174
174
  handler(s, e) {
175
175
  if (!e)
@@ -178,7 +178,7 @@ const Rt = "sheets-hyper-link.config", St = {}, O = {
178
178
  return t.updateHyperLinkRef(n, r, i, { row: a, column: o }, c);
179
179
  }
180
180
  }, X = {
181
- type: U.MUTATION,
181
+ type: L.MUTATION,
182
182
  id: "sheets.mutation.update-rich-hyper-link",
183
183
  handler(s, e) {
184
184
  var g, p, f;
@@ -408,7 +408,7 @@ ee = Ct([
408
408
  z(2, M(Oe)),
409
409
  z(3, P)
410
410
  ], ee);
411
- var wt = Object.defineProperty, Et = Object.getOwnPropertyDescriptor, Ut = (s, e, t, n) => {
411
+ var wt = Object.defineProperty, Et = Object.getOwnPropertyDescriptor, Lt = (s, e, t, n) => {
412
412
  for (var r = n > 1 ? void 0 : n ? Et(e, t) : e, i = s.length - 1, a; i >= 0; i--)
413
413
  (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
414
414
  return n && r && wt(e, t, r), r;
@@ -452,15 +452,15 @@ let te = class extends V {
452
452
  );
453
453
  }
454
454
  };
455
- te = Ut([
455
+ te = Lt([
456
456
  he(0, M(le)),
457
457
  he(1, E),
458
458
  he(2, M(S))
459
459
  ], te);
460
- var Lt = Object.defineProperty, bt = Object.getOwnPropertyDescriptor, Pt = (s, e, t, n) => {
460
+ var Ut = Object.defineProperty, bt = Object.getOwnPropertyDescriptor, Pt = (s, e, t, n) => {
461
461
  for (var r = n > 1 ? void 0 : n ? bt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
462
462
  (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
463
- return n && r && Lt(e, t, r), r;
463
+ return n && r && Ut(e, t, r), r;
464
464
  }, ge = (s, e) => (t, n) => e(t, n, s);
465
465
  let ne = class extends V {
466
466
  constructor(e, t, n) {
@@ -764,8 +764,56 @@ re = kt([
764
764
  J(2, M(Oe)),
765
765
  J(3, E)
766
766
  ], re);
767
- const Dt = {
768
- type: U.COMMAND,
767
+ var He = /* @__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))(He || {}), Dt = Object.defineProperty, Ht = Object.getOwnPropertyDescriptor, Vt = (s, e, t, n) => {
768
+ for (var r = n > 1 ? void 0 : n ? Ht(e, t) : e, i = s.length - 1, a; i >= 0; i--)
769
+ (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
770
+ return n && r && Dt(e, t, r), r;
771
+ }, Ue = (s, e) => (t, n) => e(t, n, s);
772
+ let se = class extends V {
773
+ constructor(s, e) {
774
+ super(), this._resourceManagerService = s, this._hyperLinkModel = e, this._initSnapshot();
775
+ }
776
+ _initSnapshot() {
777
+ const s = (t) => {
778
+ const n = this._hyperLinkModel.getUnit(t), r = {};
779
+ return n ? (n.forEach((i) => {
780
+ r[i.subUnitId] = i.links.map(({ display: a, ...o }) => o);
781
+ }), JSON.stringify(r)) : "";
782
+ }, e = (t) => {
783
+ if (!t)
784
+ return {};
785
+ try {
786
+ return JSON.parse(t);
787
+ } catch {
788
+ return {};
789
+ }
790
+ };
791
+ this.disposeWithMe(
792
+ this._resourceManagerService.registerPluginResource({
793
+ pluginName: De,
794
+ businesses: [He.UNIVER_SHEET],
795
+ toJson: (t) => s(t),
796
+ parseJson: (t) => e(t),
797
+ onUnLoad: (t) => {
798
+ this._hyperLinkModel.deleteUnit(t);
799
+ },
800
+ onLoad: async (t, n) => {
801
+ Object.keys(n).forEach((r) => {
802
+ n[r].forEach((a) => {
803
+ this._hyperLinkModel.addHyperLink(t, r, a);
804
+ });
805
+ });
806
+ }
807
+ })
808
+ );
809
+ }
810
+ };
811
+ se = Vt([
812
+ Ue(0, Ye),
813
+ Ue(1, M(S))
814
+ ], se);
815
+ const $t = {
816
+ type: L.COMMAND,
769
817
  id: "sheets.command.add-hyper-link",
770
818
  // eslint-disable-next-line max-lines-per-function
771
819
  async handler(s, e) {
@@ -822,9 +870,9 @@ const Dt = {
822
870
  }, ue = {
823
871
  id: H.id,
824
872
  params: T
825
- }, G = Me(s, T), pe = {
873
+ }, Y = Me(s, T), pe = {
826
874
  id: H.id,
827
- params: G
875
+ params: Y
828
876
  }, K = [ue], A = [pe], W = i.getHyperLinkByLocation(c, d, f, y);
829
877
  return W && (K.push({
830
878
  id: k.id,
@@ -846,9 +894,9 @@ const Dt = {
846
894
  unitID: c
847
895
  }), !0) : !1;
848
896
  }
849
- }, Ht = {
897
+ }, xt = {
850
898
  id: "sheets.command.add-rich-hyper-link",
851
- type: U.COMMAND,
899
+ type: L.COMMAND,
852
900
  handler: async (s, e) => {
853
901
  if (!e)
854
902
  return !1;
@@ -863,8 +911,8 @@ const Dt = {
863
911
  });
864
912
  return o ? r.syncExecuteCommand(o.id, o.params) : !1;
865
913
  }
866
- }, Vt = {
867
- type: U.COMMAND,
914
+ }, Tt = {
915
+ type: L.COMMAND,
868
916
  id: "sheets.command.cancel-hyper-link",
869
917
  // eslint-disable-next-line max-lines-per-function
870
918
  handler(s, e) {
@@ -927,8 +975,8 @@ const Dt = {
927
975
  unitID: l
928
976
  }), !0) : !1;
929
977
  }
930
- }, $t = {
931
- type: U.COMMAND,
978
+ }, At = {
979
+ type: L.COMMAND,
932
980
  id: "sheets.command.cancel-rich-hyper-link",
933
981
  handler(s, e) {
934
982
  var l, u;
@@ -942,12 +990,12 @@ const Dt = {
942
990
  const d = ft(s, { unitId: n, rangeId: t, insert: c });
943
991
  return d ? r.syncExecuteCommand(d.id, d.params) : !1;
944
992
  }
945
- }, xt = {
946
- type: U.COMMAND,
993
+ }, Wt = {
994
+ type: L.COMMAND,
947
995
  id: "sheets.command.update-hyper-link",
948
996
  // eslint-disable-next-line max-lines-per-function
949
997
  async handler(s, e) {
950
- var we, Ee, Ue;
998
+ var we, Ee, Le;
951
999
  if (!e) return !1;
952
1000
  const t = s.get(P), n = s.get(Se), r = s.get(E), i = s.get(S), a = s.get(le), o = j(r, {
953
1001
  unitId: e.unitId,
@@ -960,7 +1008,7 @@ const Dt = {
960
1008
  if (!(m != null && m.documentModel)) return !1;
961
1009
  const v = m.documentModel.getSnapshot(), R = (Ee = (we = v.body) == null ? void 0 : we.customRanges) == null ? void 0 : Ee.find((xe) => xe.rangeId === u);
962
1010
  if (!R) return !1;
963
- const N = de(), $ = (Ue = Pe(m.documentModel.getBody(), R.startIndex, R.endIndex + 1).textRuns) == null ? void 0 : Ue[0];
1011
+ const N = de(), $ = (Le = Pe(m.documentModel.getBody(), R.startIndex, R.endIndex + 1).textRuns) == null ? void 0 : Le[0];
964
1012
  $ && ($.ed = _.length + 1);
965
1013
  const D = ke(s, {
966
1014
  unitId: p,
@@ -992,7 +1040,7 @@ const Dt = {
992
1040
  body: x
993
1041
  },
994
1042
  t: Ie.STRING
995
- }, ue = await a.onWriteCell(h, g, d, l, T), G = {
1043
+ }, ue = await a.onWriteCell(h, g, d, l, T), Y = {
996
1044
  id: H.id,
997
1045
  params: {
998
1046
  unitId: p,
@@ -1003,23 +1051,23 @@ const Dt = {
1003
1051
  }
1004
1052
  }
1005
1053
  }
1006
- }, pe = Me(s, G.params), K = {
1054
+ }, pe = Me(s, Y.params), K = {
1007
1055
  id: H.id,
1008
1056
  params: pe
1009
- }, A = [G], W = [K], Y = i.getHyperLinkByLocation(p, f, d, l);
1010
- return Y && (A.push({
1057
+ }, A = [Y], W = [K], G = i.getHyperLinkByLocation(p, f, d, l);
1058
+ return G && (A.push({
1011
1059
  id: k.id,
1012
1060
  params: {
1013
1061
  unitId: p,
1014
1062
  subUnitId: f,
1015
- id: Y.id
1063
+ id: G.id
1016
1064
  }
1017
1065
  }), W.push({
1018
1066
  id: O.id,
1019
1067
  params: {
1020
1068
  unitId: p,
1021
1069
  subUnitId: f,
1022
- link: Y
1070
+ link: G
1023
1071
  }
1024
1072
  })), await ve(A, t) ? (n.pushUndoRedo({
1025
1073
  redoMutations: A,
@@ -1027,8 +1075,8 @@ const Dt = {
1027
1075
  unitID: p
1028
1076
  }), !0) : !1;
1029
1077
  }
1030
- }, Tt = {
1031
- type: U.COMMAND,
1078
+ }, Bt = {
1079
+ type: L.COMMAND,
1032
1080
  id: "sheets.command.update-rich-hyper-link",
1033
1081
  handler: (s, e) => {
1034
1082
  var p, f, y, _;
@@ -1067,23 +1115,23 @@ const Dt = {
1067
1115
  return g ? a.syncExecuteCommand(g.id, g.params) : !1;
1068
1116
  }
1069
1117
  };
1070
- var At = Object.defineProperty, Wt = Object.getOwnPropertyDescriptor, Bt = (s, e, t, n) => {
1071
- for (var r = n > 1 ? void 0 : n ? Wt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
1118
+ var jt = Object.defineProperty, Ft = Object.getOwnPropertyDescriptor, Kt = (s, e, t, n) => {
1119
+ for (var r = n > 1 ? void 0 : n ? Ft(e, t) : e, i = s.length - 1, a; i >= 0; i--)
1072
1120
  (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
1073
- return n && r && At(e, t, r), r;
1074
- }, jt = (s, e) => (t, n) => e(t, n, s);
1075
- let se = class extends V {
1121
+ return n && r && jt(e, t, r), r;
1122
+ }, Yt = (s, e) => (t, n) => e(t, n, s);
1123
+ let ie = class extends V {
1076
1124
  constructor(s) {
1077
1125
  super(), this._commandService = s, this._registerCommands();
1078
1126
  }
1079
1127
  _registerCommands() {
1080
1128
  [
1081
- Dt,
1082
- xt,
1083
- Vt,
1084
- Tt,
1085
1129
  $t,
1086
- Ht,
1130
+ Wt,
1131
+ Tt,
1132
+ Bt,
1133
+ At,
1134
+ xt,
1087
1135
  O,
1088
1136
  _e,
1089
1137
  k,
@@ -1094,68 +1142,20 @@ let se = class extends V {
1094
1142
  });
1095
1143
  }
1096
1144
  };
1097
- se = Bt([
1098
- jt(0, P)
1099
- ], se);
1100
- var He = /* @__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))(He || {}), Ft = Object.defineProperty, Kt = Object.getOwnPropertyDescriptor, Gt = (s, e, t, n) => {
1101
- for (var r = n > 1 ? void 0 : n ? Kt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
1102
- (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
1103
- return n && r && Ft(e, t, r), r;
1104
- }, Le = (s, e) => (t, n) => e(t, n, s);
1105
- let ie = class extends V {
1106
- constructor(s, e) {
1107
- super(), this._resourceManagerService = s, this._hyperLinkModel = e, this._initSnapshot();
1108
- }
1109
- _initSnapshot() {
1110
- const s = (t) => {
1111
- const n = this._hyperLinkModel.getUnit(t), r = {};
1112
- return n ? (n.forEach((i) => {
1113
- r[i.subUnitId] = i.links.map(({ display: a, ...o }) => o);
1114
- }), JSON.stringify(r)) : "";
1115
- }, e = (t) => {
1116
- if (!t)
1117
- return {};
1118
- try {
1119
- return JSON.parse(t);
1120
- } catch {
1121
- return {};
1122
- }
1123
- };
1124
- this.disposeWithMe(
1125
- this._resourceManagerService.registerPluginResource({
1126
- pluginName: De,
1127
- businesses: [He.UNIVER_SHEET],
1128
- toJson: (t) => s(t),
1129
- parseJson: (t) => e(t),
1130
- onUnLoad: (t) => {
1131
- this._hyperLinkModel.deleteUnit(t);
1132
- },
1133
- onLoad: async (t, n) => {
1134
- Object.keys(n).forEach((r) => {
1135
- n[r].forEach((a) => {
1136
- this._hyperLinkModel.addHyperLink(t, r, a);
1137
- });
1138
- });
1139
- }
1140
- })
1141
- );
1142
- }
1143
- };
1144
- ie = Gt([
1145
- Le(0, Ye),
1146
- Le(1, M(S))
1145
+ ie = Kt([
1146
+ Yt(0, P)
1147
1147
  ], ie);
1148
- var Yt = Object.defineProperty, zt = Object.getOwnPropertyDescriptor, Jt = (s, e, t, n) => {
1148
+ var Gt = Object.defineProperty, zt = Object.getOwnPropertyDescriptor, Jt = (s, e, t, n) => {
1149
1149
  for (var r = n > 1 ? void 0 : n ? zt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
1150
1150
  (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
1151
- return n && r && Yt(e, t, r), r;
1151
+ return n && r && Gt(e, t, r), r;
1152
1152
  }, fe = (s, e) => (t, n) => e(t, n, s);
1153
1153
  let ye = class {
1154
1154
  constructor(s, e, t) {
1155
1155
  this._univerInstanceService = s, this._localeService = e, this._definedNamesService = t;
1156
1156
  }
1157
1157
  buildHyperLink(s, e, t) {
1158
- return `#${L.SHEET}=${e}${t ? `&${typeof t == "string" ? L.DEFINE_NAME : L.RANGE}=${typeof t == "string" ? t : B(t)}` : ""}`;
1158
+ return `#${U.SHEET}=${e}${t ? `&${typeof t == "string" ? U.DEFINE_NAME : U.RANGE}=${typeof t == "string" ? t : B(t)}` : ""}`;
1159
1159
  }
1160
1160
  parseHyperLink(s) {
1161
1161
  var e, t, n, r;
@@ -1174,7 +1174,7 @@ let ye = class {
1174
1174
  };
1175
1175
  } else
1176
1176
  return {
1177
- type: L.URL,
1177
+ type: U.URL,
1178
1178
  name: s,
1179
1179
  url: s,
1180
1180
  searchObj: null
@@ -1183,7 +1183,7 @@ let ye = class {
1183
1183
  _getURLName(s) {
1184
1184
  var d;
1185
1185
  const { gid: e, range: t, rangeid: n, unitid: r } = s, i = r ? this._univerInstanceService.getUnit(r, I.UNIVER_SHEET) : this._univerInstanceService.getCurrentUnitForType(I.UNIVER_SHEET), a = {
1186
- type: L.INVALID,
1186
+ type: U.INVALID,
1187
1187
  name: this._localeService.t("hyperLink.message.refError")
1188
1188
  };
1189
1189
  if (!i)
@@ -1193,21 +1193,21 @@ let ye = class {
1193
1193
  if (!o) return a;
1194
1194
  const l = Ce(t).range;
1195
1195
  return Re(l, o) && t !== Q ? {
1196
- type: L.RANGE,
1196
+ type: U.RANGE,
1197
1197
  name: pt(c, l)
1198
1198
  } : a;
1199
1199
  }
1200
1200
  if (n) {
1201
1201
  const l = this._definedNamesService.getValueById(i.getUnitId(), n);
1202
1202
  return l ? {
1203
- type: L.DEFINE_NAME,
1203
+ type: U.DEFINE_NAME,
1204
1204
  name: l.formulaOrRefString
1205
1205
  } : a;
1206
1206
  }
1207
1207
  if (e) {
1208
1208
  const l = i.getSheetBySheetId(e);
1209
1209
  return l ? {
1210
- type: L.SHEET,
1210
+ type: U.SHEET,
1211
1211
  name: l.getName()
1212
1212
  } : a;
1213
1213
  }
@@ -1234,16 +1234,16 @@ let ae = class extends qe {
1234
1234
  Ze(this._injector, [
1235
1235
  [S],
1236
1236
  [ye],
1237
- [ie],
1238
1237
  [se],
1238
+ [ie],
1239
1239
  [ee],
1240
1240
  [re],
1241
1241
  [te],
1242
1242
  [ne]
1243
1243
  ]), Qe(this._injector, [
1244
1244
  [ee],
1245
- [ie],
1246
1245
  [se],
1246
+ [ie],
1247
1247
  [re],
1248
1248
  [te],
1249
1249
  [ne]
@@ -1258,19 +1258,19 @@ ae = Zt([
1258
1258
  be(2, et)
1259
1259
  ], ae);
1260
1260
  export {
1261
- Dt as AddHyperLinkCommand,
1261
+ $t as AddHyperLinkCommand,
1262
1262
  O as AddHyperLinkMutation,
1263
- Ht as AddRichHyperLinkCommand,
1264
- Vt as CancelHyperLinkCommand,
1265
- $t as CancelRichHyperLinkCommand,
1263
+ xt as AddRichHyperLinkCommand,
1264
+ Tt as CancelHyperLinkCommand,
1265
+ At as CancelRichHyperLinkCommand,
1266
1266
  Q as ERROR_RANGE,
1267
1267
  S as HyperLinkModel,
1268
1268
  k as RemoveHyperLinkMutation,
1269
- L as SheetHyperLinkType,
1269
+ U as SheetHyperLinkType,
1270
1270
  ye as SheetsHyperLinkParserService,
1271
1271
  ae as UniverSheetsHyperLinkPlugin,
1272
- xt as UpdateHyperLinkCommand,
1272
+ Wt as UpdateHyperLinkCommand,
1273
1273
  _e as UpdateHyperLinkMutation,
1274
1274
  me as UpdateHyperLinkRefMutation,
1275
- Tt as UpdateRichHyperLinkCommand
1275
+ Bt as UpdateRichHyperLinkCommand
1276
1276
  };
@@ -13,7 +13,7 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- export declare const PLUGIN_CONFIG_KEY = "sheets-hyper-link.config";
16
+ export declare const SHEETS_HYPER_LINK_PLUGIN_CONFIG_KEY = "sheets-hyper-link.config";
17
17
  export declare const configSymbol: unique symbol;
18
18
  export interface IUniverSheetsHyperLinkConfig {
19
19
  }
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,T,m,C,x){"use strict";var Qe=Object.defineProperty;var et=(p,o,T)=>o in p?Qe(p,o,{enumerable:!0,configurable:!0,writable:!0,value:T}):p[o]=T;var L=(p,o,T)=>et(p,typeof o!="symbol"?o+"":o,T);var Ie=Object.defineProperty,Re=Object.getOwnPropertyDescriptor,Me=(r,t,e,n)=>{for(var i=n>1?void 0:n?Re(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&&Ie(t,e,i),i},Ce=(r,t)=>(e,n)=>t(e,n,r);p.HyperLinkModel=class extends o.Disposable{constructor(e){super();L(this,"_linkUpdate$",new T.Subject);L(this,"linkUpdate$",this._linkUpdate$.asObservable());L(this,"_linkMap",new Map);L(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let i=this._linkMap.get(e);i||(i=new Map,this._linkMap.set(e,i));let s=i.get(n);s||(s=new o.ObjectMatrix,i.set(n,s));let a=this._linkPositionMap.get(e);a||(a=new Map,this._linkPositionMap.set(e,a));let d=a.get(n);return d||(d=new Map,a.set(n,d)),{matrix:s,positionMap:d}}addHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n);return s.setValue(i.row,i.column,i),a.set(i.id,{row:i.row,column:i.column,link:i}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:i,type:"add"}),!0}updateHyperLink(e,n,i,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;const u=d.getValue(l.row,l.column);return u&&(Object.assign(u,s),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:u.display,payload:u.payload},id:i,type:"update",silent:a})),!0}updateHyperLinkRef(e,n,i,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;let u=d.getValue(l.row,l.column);return!u||u.id!==i?u=l.link:d.realDeleteValue(l.row,l.column),Object.assign(u,s),c.set(i,{...s,link:u}),d.setValue(s.row,s.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:i,type:"updateRef",silent:a}),!0}removeHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(i);if(!d)return!1;a.delete(i);const c=s.getValue(d.row,d.column);return c&&c.id===i&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(i);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,i,s){const{matrix:a}=this._ensureMap(e,n);return a.getValue(i,s)}getHyperLinkByLocationSync(e,n,i,s){var g,f,_,h,y;const{matrix:a}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,o.UniverInstanceType.UNIVER_SHEET),c=(g=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:g.getCellRaw(i,s),l=((y=(h=c==null?void 0:c.v)!=null?h:(_=(f=c==null?void 0:c.p)==null?void 0:f.body)==null?void 0:_.dataStream.slice(0,-2))!=null?y:"").toString(),u=a.getValue(i,s);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:i}=this._ensureMap(e,n),s=[];return i.forValue((a,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(i=>{const s=this.getSubUnit(e,i);return{unitId:e,subUnitId:i,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}},p.HyperLinkModel=Me([Ce(0,o.IUniverInstanceService)],p.HyperLinkModel);var w=(r=>(r.SHEET="gid",r.RANGE="range",r.DEFINE_NAME="rangeid",r.INVALID="invalid",r.URL="url",r))(w||{});const Ue="sheets-hyper-link.config",Le={},k={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)}},W={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,payload:s,id:a}=t;return e.updateHyperLink(n,i,a,s,!1)}},B={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:s,row:a,column:d,silent:c}=t;return e.updateHyperLinkRef(n,i,s,{row:a,column:d},c)}},z={type:o.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(r,t){var _,h,y;if(!t)return!1;const{unitId:e,subUnitId:n,row:i,col:s,id:a,url:d}=t,c=r.get(o.IUniverInstanceService),l=m.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:u}=l,g=u.getCellRaw(i,s),f=(y=(h=(_=g==null?void 0:g.p)==null?void 0:_.body)==null?void 0:h.customRanges)==null?void 0:y.find(I=>I.rangeType===o.CustomRangeType.HYPERLINK&&I.rangeId===a);return f&&(f.properties.url=d),!0}},ae="SHEET_HYPER_LINK_PLUGIN",$="err";var we=Object.defineProperty,ke=Object.getOwnPropertyDescriptor,Ee=(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&&we(t,e,i),i},K=(r,t)=>(e,n)=>t(e,n,r);let G=class extends o.Disposable{constructor(t,e,n,i){super();L(this,"_disposableMap",new Map);L(this,"_watchDisposableMap",new Map);L(this,"_rangeDisableMap",new Map);L(this,"_rangeWatcherMap",new Map);L(this,"_handlePositionChange",(t,e,n,i,s)=>{const a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return i?{redos:[{id:B.id,params:{unitId:t,subUnitId:e,id:n.id,row:i.startRow,column:i.startColumn,silent:s}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,id:n.id,row:a.startRow,column:a.startColumn,silent:s}}]}:{redos:[{id:E.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:k.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=i,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},a=d=>{const c=m.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===s.startColumn&&l.startRow===s.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(i,this._refRangeService.registerRefRange(s,a,t,e))}_watchPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(t,e,s,(a,d)=>{const{redos:c}=this._handlePositionChange(t,e,n,d,!0);o.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(t){const e=this._disposableMap.get(t);e==null||e.dispose(),this._disposableMap.delete(t)}_unwatchPosition(t){const e=this._watchDisposableMap.get(t);e==null||e.dispose(),this._watchDisposableMap.delete(t)}_registerRange(t,e,n,i=!1){var s,a,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(s=c.get("gid"))!=null?s:"",range:(a=c.get("range"))!=null?a:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const u=l.gid,g=C.deserializeRangeWithSheet(l.range).range;if(o.isValidRange(g)&&l.range!==$){const f=_=>{const h=m.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(g,_,{selectionManagerService:this._selectionManagerService});return h&&C.serializeRange(h)===C.serializeRange(g)?{redos:[],undos:[]}:{redos:[{id:W.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`}}}],undos:[{id:W.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(g,f,t,u)),i||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,u,g,(_,h)=>{this._hyperLinkModel.updateHyperLink(t,u,e,{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`},!0)},!0))}}}}_unregisterRange(t){const e=this._rangeDisableMap.get(t);e==null||e.dispose(),this._rangeDisableMap.delete(t)}_unwatchRange(t){const e=this._rangeWatcherMap.get(t);e==null||e.dispose(),this._rangeWatcherMap.delete(t)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(n=>{const{unitId:i,subUnitId:s,links:a}=n;a.forEach(d=>{this._registerPosition(i,s,d),this._watchPosition(i,s,d),this._registerRange(i,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:i,silent:s}=t,a=this._hyperLinkModel.getHyperLink(e,n,i);if(!a)return;this._unregisterPosition(i),this._registerPosition(e,n,a),s||(this._unwatchPosition(i),this._watchPosition(e,n,a));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:i}=n;i.forEach(s=>{this._unregisterPosition(s.id),this._unwatchPosition(s.id),this._unregisterRange(s.id),this._unwatchRange(s.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(o.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};G=Ee([K(0,o.Inject(m.RefRangeService)),K(1,o.Inject(p.HyperLinkModel)),K(2,o.Inject(m.SheetsSelectionsService)),K(3,o.ICommandService)],G);var be=Object.defineProperty,Pe=Object.getOwnPropertyDescriptor,Te=(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&&be(t,e,i),i},te=(r,t)=>(e,n)=>t(e,n,r);let Y=class extends o.Disposable{constructor(r,t,e){super(),this._sheetInterceptorService=r,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{var t;if(r.id===m.RemoveSheetCommand.id){const e=r.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const i=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const a=this._hyperLinkModel.getSubUnit(i,s),d=a.map(l=>({id:E.id,params:{unitId:i,subUnitId:s,id:l.id}})),c=a.map(l=>({id:k.id,params:{unitId:i,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};Y=Te([te(0,o.Inject(m.SheetInterceptorService)),te(1,o.IUniverInstanceService),te(2,o.Inject(p.HyperLinkModel))],Y);var He=Object.defineProperty,Ne=Object.getOwnPropertyDescriptor,Oe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ne(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&He(t,e,i),i},ne=(r,t)=>(e,n)=>t(e,n,r);let q=class extends o.Disposable{constructor(t,e,n){super();L(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let i=n.get(e);return i||(i=new o.ObjectMatrix,n.set(e,i)),i}_isLegalRangeUrl(t,e){var i,s,a;const n=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(i=d.get("gid"))!=null?i:"",range:(s=d.get("range"))!=null?s:"",rangeid:(a=d.get("rangeid"))!=null?a:""};if(c.range&&c.gid){const l=c.gid,u=n.getSheetBySheetId(l);if(!u)return null;const g=C.deserializeRangeWithSheet(c.range).range;if(o.isValidRange(g,u)&&c.range!==$)return{range:g,worksheet:u}}}return null}_registerRange(t,e,n,i,s){var d,c,l,u;const a=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(g=>{var f;return g.rangeType===o.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(f=g.properties)==null?void 0:f.url)})){const g=new o.DisposableCollection;let f=!1;(u=(l=s.body)==null?void 0:l.customRanges)==null||u.forEach(_=>{var h;if(_.rangeType===o.CustomRangeType.HYPERLINK){const y=(h=_.properties)==null?void 0:h.url,I=this._isLegalRangeUrl(t,y);if(I){const{range:v,worksheet:U}=I;f=!0,g.add(this._refRangeService.registerRefRange(v,S=>{const R=m.handleDefaultRangeChangeWithEffectRefCommands(v,S);return R&&o.Rectangle.equals(R,v)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:z.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:_.rangeId,url:`#gid=${e}&range=${R?C.serializeRange(R):$}`}}],undos:[{id:z.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:_.rangeId,url:y}}],redos:[]}},U.getUnitId(),U.getSheetId()))}}}),f&&a.setValue(n,i,g)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId(),a=this._enusreMap(n,s);i.getCellMatrix().forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,s,d,c,l.p)})})};this._univerInstanceService.getAllUnitsForType(o.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(e=>{e.type===o.UniverInstanceType.UNIVER_SHEET&&t(e)}))}_initWorkbookUnload(){this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===o.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId();this._enusreMap(n,s).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}})}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===m.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:i,cellValue:s}=e,a=this._enusreMap(n,i);s&&new o.ObjectMatrix(s).forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,i,d,c,l.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===z.id){const e=t.params,{unitId:n,subUnitId:i,row:s,col:a}=e,d=m.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:i}),l=this._enusreMap(n,i).getValue(s,a);if(l&&l.dispose(),d){const{worksheet:u}=d,g=u.getCellRaw(s,a);g&&g.p&&this._registerRange(n,i,s,a,g.p)}}}))}};q=Oe([ne(0,o.ICommandService),ne(1,o.IUniverInstanceService),ne(2,o.Inject(m.RefRangeService))],q);var De=Object.defineProperty,Ve=Object.getOwnPropertyDescriptor,$e=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ve(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&De(t,e,i),i},F=(r,t)=>(e,n)=>t(e,n,r);let J=class extends o.Disposable{constructor(r,t,e,n){super(),this._sheetInterceptorService=r,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.SetRangeValuesCommand.id){const t=r.params,{unitId:e,subUnitId:n}=t,i=[],s=[];return t.cellValue&&new o.ObjectMatrix(t.cellValue).forValue((a,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,a,d);c&&(i.push({id:E.id,params:{unitId:e,subUnitId:n,id:c.id}}),s.push({id:k.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:k.id,params:{unitId:s,subUnitId:a,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(m.AFTER_CELL_EDIT,{handler:(r,t,e)=>{if(!r||r.p)return e(r);if(typeof r.v=="string"&&o.Tools.isLegalUrl(r.v)&&r.v[r.v.length-1]!==" "){const{unitId:n,subUnitId:i}=t,s=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET),a=s==null?void 0:s.getSheetBySheetId(i);if(!a)return e(r);const d=a.getBlankCellDocumentModel(r);if(!d.documentModel)return e(r);const c=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:r.v.length,collapsed:!1},body:{dataStream:`${r.v}`,customRanges:[{startIndex:0,endIndex:r.v.length-1,rangeId:o.generateRandomId(),rangeType:o.CustomRangeType.HYPERLINK,properties:{url:r.v}}]},doc:d.documentModel});if(!c)return e(r);const l=d.documentModel.getBody();return o.TextX.apply(l,c.serialize()),e({...r,p:{id:o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:l,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(r)}}))}};J=$e([F(0,o.Inject(m.SheetInterceptorService)),F(1,o.Inject(p.HyperLinkModel)),F(2,o.Inject(m.SheetsSelectionsService)),F(3,o.IUniverInstanceService)],J);const oe={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:I,id:v}=f,U=g.getCell(y,I),S=g.getBlankCellDocumentModel(U),R=S.documentModel.getSnapshot(),M=o.Tools.deepClone(R.body);if(!M)return!1;let b;if(h?b=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:M.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:M,ranges:[{startOffset:0,endOffset:M.dataStream.length-2,collapsed:!1}],rangeId:v,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:_,refId:v}}),!b)return!1;const j=o.TextX.apply(M,b.serialize()),P={p:{...R,body:j},t:o.CellValueType.STRING},N=await a.onWriteCell(u,g,y,I,P),O={unitId:c,subUnitId:l,cellValue:{[f.row]:{[f.column]:N}}},re={id:m.SetRangeValuesMutation.id,params:O},Q=m.SetRangeValuesUndoMutationFactory(r,O),se={id:m.SetRangeValuesMutation.id,params:Q},A=[re],D=[se],V=s.getHyperLinkByLocation(c,l,y,I);return V&&(A.push({id:E.id,params:{unitId:c,subUnitId:l,id:V.id}}),D.push({id:k.id,params:{unitId:c,subUnitId:l,link:V}})),await o.sequenceExecuteAsync(A,e)?(n.pushUndoRedo({redoMutations:A,undoMutations:D,unitID:c}),!0):!1}},de={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}},ce={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 U=o.TextX.apply(y.body,v.serialize()),S=[],R=[],M={unitId:u,subUnitId:g,cellValue:{[d]:{[c]:{p:{...y,body:U},t:o.CellValueType.STRING}}}};S.push({id:m.SetRangeValuesMutation.id,params:M});const b=m.SetRangeValuesUndoMutationFactory(r,M);R.push({id:m.SetRangeValuesMutation.id,params:b});const j=s.getHyperLinkByLocation(u,g,d,c);return j&&(S.push({id:E.id,params:{unitId:u,subUnitId:g,id:l}}),R.push({id:k.id,params:{unitId:u,subUnitId:g,link:{...j}}})),o.sequenceExecute(S,e).result?(n.pushUndoRedo({redoMutations:S,undoMutations:R,unitID:u}),!0):!1}},le={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}},ue={type:o.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(r,t){var ye,ve,Se;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:I,display:v=""}=c,U=_.getCell(l,u);if(!U)return!1;const S=_.getCellDocumentModelWithFormula(U);if(!(S!=null&&S.documentModel))return!1;const R=S.documentModel.getSnapshot(),M=(ve=(ye=R.body)==null?void 0:ye.customRanges)==null?void 0:ve.find(Ze=>Ze.rangeId===g);if(!M)return!1;const b=o.generateRandomId(),H=(Se=o.getBodySlice(S.documentModel.getBody(),M.startIndex,M.endIndex+1).textRuns)==null?void 0:Se[0];H&&(H.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:I}}],textRuns:H?[H]:void 0},selection:{startOffset:M.startIndex,endOffset:M.endIndex+1,collapsed:!1},doc:S.documentModel});if(!P)return!1;const N=o.TextX.apply(o.Tools.deepClone(R.body),P.textX.serialize()),O={p:{...R,body:N},t:o.CellValueType.STRING},re=await a.onWriteCell(f,_,l,u,O),Q={id:m.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:y,cellValue:{[l]:{[u]:re}}}},se=m.SetRangeValuesUndoMutationFactory(r,Q.params),A={id:m.SetRangeValuesMutation.id,params:se},D=[Q],V=[A],ee=s.getHyperLinkByLocation(h,y,l,u);return ee&&(D.push({id:E.id,params:{unitId:h,subUnitId:y,id:ee.id}}),V.push({id:k.id,params:{unitId:h,subUnitId:y,link:ee}})),await o.sequenceExecuteAsync(D,e)?(n.pushUndoRedo({redoMutations:D,undoMutations:V,unitID:h}),!0):!1}},pe={type:o.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(r,t)=>{var h,y,I,v;if(!t)return!1;const{documentId:e,payload:n,id:i}=t,s=r.get(o.IUniverInstanceService),a=r.get(o.ICommandService),d=s.getUnit(e,o.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(y=(h=d.getBody())==null?void 0:h.customRanges)==null?void 0:y.find(U=>U.rangeId===i);if(!c)return!1;const l=(I=t.payload.display)!=null?I:"",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 je=Object.defineProperty,Ae=Object.getOwnPropertyDescriptor,xe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ae(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&je(t,e,i),i},We=(r,t)=>(e,n)=>t(e,n,r);let X=class extends o.Disposable{constructor(r){super(),this._commandService=r,this._registerCommands()}_registerCommands(){[oe,ue,ce,pe,le,de,k,W,E,B,z].forEach(r=>{this._commandService.registerCommand(r)})}};X=xe([We(0,o.ICommandService)],X);var ge=(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))(ge||{}),Be=Object.defineProperty,ze=Object.getOwnPropertyDescriptor,Ke=(r,t,e,n)=>{for(var i=n>1?void 0:n?ze(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},he=(r,t)=>(e,n)=>t(e,n,r);let Z=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:ae,businesses:[ge.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)})})}}))}};Z=Ke([he(0,o.IResourceManagerService),he(1,o.Inject(p.HyperLinkModel))],Z);var Ge=Object.defineProperty,Ye=Object.getOwnPropertyDescriptor,qe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ye(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Ge(t,e,i),i},ie=(r,t)=>(e,n)=>t(e,n,r);p.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${w.SHEET}=${e}${n?`&${typeof n=="string"?w.DEFINE_NAME:w.RANGE}=${typeof n=="string"?n:C.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,i,s;if(t.startsWith("#")){const a=new URLSearchParams(t.slice(1)),d={gid:(e=a.get("gid"))!=null?e:"",range:(n=a.get("range"))!=null?n:"",rangeid:(i=a.get("rangeid"))!=null?i:"",unitid:(s=a.get("unitid"))!=null?s:""},c=this._getURLName(d);return{type:c.type,name:c.name,url:t,searchObj:d}}else return{type:w.URL,name:t,url:t,searchObj:null}}_getURLName(t){var u;const{gid:e,range:n,rangeid:i,unitid:s}=t,a=s?this._univerInstanceService.getUnit(s,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),d={type:w.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!a)return d;const c=e?a.getSheetBySheetId(e):a.getActiveSheet(),l=(u=c==null?void 0:c.getName())!=null?u:"";if(n){if(!c)return d;const g=C.deserializeRangeWithSheet(n).range;return o.isValidRange(g,c)&&n!==$?{type:w.RANGE,name:C.serializeRangeWithSheet(l,g)}:d}if(i){const g=this._definedNamesService.getValueById(a.getUnitId(),i);return g?{type:w.DEFINE_NAME,name:g.formulaOrRefString}:d}if(e){const g=a.getSheetBySheetId(e);return g?{type:w.SHEET,name:g.getName()}:d}return d}},p.SheetsHyperLinkParserService=qe([ie(0,o.IUniverInstanceService),ie(1,o.Inject(o.LocaleService)),ie(2,C.IDefinedNamesService)],p.SheetsHyperLinkParserService);var me=Object.defineProperty,Fe=Object.getOwnPropertyDescriptor,Je=(r,t,e)=>t in r?me(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Xe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Fe(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&me(t,e,i),i},fe=(r,t)=>(e,n)=>t(e,n,r),_e=(r,t,e)=>Je(r,typeof t!="symbol"?t+"":t,e);p.UniverSheetsHyperLinkPlugin=class extends o.Plugin{constructor(t=Le,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...i}=this._config;this._configService.setConfig(Ue,i)}onStarting(){o.registerDependencies(this._injector,[[p.HyperLinkModel],[p.SheetsHyperLinkParserService],[Z],[X],[G],[J],[Y],[q]]),o.touchDependencies(this._injector,[[G],[Z],[X],[J],[Y],[q]])}},_e(p.UniverSheetsHyperLinkPlugin,"pluginName",ae),_e(p.UniverSheetsHyperLinkPlugin,"type",o.UniverInstanceType.UNIVER_SHEET),p.UniverSheetsHyperLinkPlugin=Xe([o.DependentOn(m.UniverSheetsPlugin),fe(1,o.Inject(o.Injector)),fe(2,o.IConfigService)],p.UniverSheetsHyperLinkPlugin),p.AddHyperLinkCommand=oe,p.AddHyperLinkMutation=k,p.AddRichHyperLinkCommand=de,p.CancelHyperLinkCommand=ce,p.CancelRichHyperLinkCommand=le,p.ERROR_RANGE=$,p.RemoveHyperLinkMutation=E,p.SheetHyperLinkType=w,p.UpdateHyperLinkCommand=ue,p.UpdateHyperLinkMutation=W,p.UpdateHyperLinkRefMutation=B,p.UpdateRichHyperLinkCommand=pe,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,T,m,C,x){"use strict";var Qe=Object.defineProperty;var et=(p,o,T)=>o in p?Qe(p,o,{enumerable:!0,configurable:!0,writable:!0,value:T}):p[o]=T;var L=(p,o,T)=>et(p,typeof o!="symbol"?o+"":o,T);var Ie=Object.defineProperty,Re=Object.getOwnPropertyDescriptor,Me=(r,t,e,n)=>{for(var i=n>1?void 0:n?Re(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&&Ie(t,e,i),i},Ce=(r,t)=>(e,n)=>t(e,n,r);p.HyperLinkModel=class extends o.Disposable{constructor(e){super();L(this,"_linkUpdate$",new T.Subject);L(this,"linkUpdate$",this._linkUpdate$.asObservable());L(this,"_linkMap",new Map);L(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let i=this._linkMap.get(e);i||(i=new Map,this._linkMap.set(e,i));let s=i.get(n);s||(s=new o.ObjectMatrix,i.set(n,s));let a=this._linkPositionMap.get(e);a||(a=new Map,this._linkPositionMap.set(e,a));let d=a.get(n);return d||(d=new Map,a.set(n,d)),{matrix:s,positionMap:d}}addHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n);return s.setValue(i.row,i.column,i),a.set(i.id,{row:i.row,column:i.column,link:i}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:i,type:"add"}),!0}updateHyperLink(e,n,i,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;const u=d.getValue(l.row,l.column);return u&&(Object.assign(u,s),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:u.display,payload:u.payload},id:i,type:"update",silent:a})),!0}updateHyperLinkRef(e,n,i,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;let u=d.getValue(l.row,l.column);return!u||u.id!==i?u=l.link:d.realDeleteValue(l.row,l.column),Object.assign(u,s),c.set(i,{...s,link:u}),d.setValue(s.row,s.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:i,type:"updateRef",silent:a}),!0}removeHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(i);if(!d)return!1;a.delete(i);const c=s.getValue(d.row,d.column);return c&&c.id===i&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(i);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,i,s){const{matrix:a}=this._ensureMap(e,n);return a.getValue(i,s)}getHyperLinkByLocationSync(e,n,i,s){var g,f,_,h,y;const{matrix:a}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,o.UniverInstanceType.UNIVER_SHEET),c=(g=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:g.getCellRaw(i,s),l=((y=(h=c==null?void 0:c.v)!=null?h:(_=(f=c==null?void 0:c.p)==null?void 0:f.body)==null?void 0:_.dataStream.slice(0,-2))!=null?y:"").toString(),u=a.getValue(i,s);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:i}=this._ensureMap(e,n),s=[];return i.forValue((a,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(i=>{const s=this.getSubUnit(e,i);return{unitId:e,subUnitId:i,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}},p.HyperLinkModel=Me([Ce(0,o.IUniverInstanceService)],p.HyperLinkModel);var w=(r=>(r.SHEET="gid",r.RANGE="range",r.DEFINE_NAME="rangeid",r.INVALID="invalid",r.URL="url",r))(w||{});const Ue="sheets-hyper-link.config",Le={},E={type:o.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,link:s}=t;return e.addHyperLink(n,i,s)}},k={type:o.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:s}=t;return e.removeHyperLink(n,i,s)}},W={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,payload:s,id:a}=t;return e.updateHyperLink(n,i,a,s,!1)}},B={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:s,row:a,column:d,silent:c}=t;return e.updateHyperLinkRef(n,i,s,{row:a,column:d},c)}},K={type:o.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(r,t){var _,h,y;if(!t)return!1;const{unitId:e,subUnitId:n,row:i,col:s,id:a,url:d}=t,c=r.get(o.IUniverInstanceService),l=m.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:u}=l,g=u.getCellRaw(i,s),f=(y=(h=(_=g==null?void 0:g.p)==null?void 0:_.body)==null?void 0:h.customRanges)==null?void 0:y.find(I=>I.rangeType===o.CustomRangeType.HYPERLINK&&I.rangeId===a);return f&&(f.properties.url=d),!0}},ae="SHEET_HYPER_LINK_PLUGIN",$="err";var we=Object.defineProperty,Ee=Object.getOwnPropertyDescriptor,ke=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ee(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&we(t,e,i),i},z=(r,t)=>(e,n)=>t(e,n,r);let G=class extends o.Disposable{constructor(t,e,n,i){super();L(this,"_disposableMap",new Map);L(this,"_watchDisposableMap",new Map);L(this,"_rangeDisableMap",new Map);L(this,"_rangeWatcherMap",new Map);L(this,"_handlePositionChange",(t,e,n,i,s)=>{const a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return i?{redos:[{id:B.id,params:{unitId:t,subUnitId:e,id:n.id,row:i.startRow,column:i.startColumn,silent:s}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,id:n.id,row:a.startRow,column:a.startColumn,silent:s}}]}:{redos:[{id:k.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:E.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=i,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},a=d=>{const c=m.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===s.startColumn&&l.startRow===s.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(i,this._refRangeService.registerRefRange(s,a,t,e))}_watchPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(t,e,s,(a,d)=>{const{redos:c}=this._handlePositionChange(t,e,n,d,!0);o.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(t){const e=this._disposableMap.get(t);e==null||e.dispose(),this._disposableMap.delete(t)}_unwatchPosition(t){const e=this._watchDisposableMap.get(t);e==null||e.dispose(),this._watchDisposableMap.delete(t)}_registerRange(t,e,n,i=!1){var s,a,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(s=c.get("gid"))!=null?s:"",range:(a=c.get("range"))!=null?a:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const u=l.gid,g=C.deserializeRangeWithSheet(l.range).range;if(o.isValidRange(g)&&l.range!==$){const f=_=>{const h=m.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(g,_,{selectionManagerService:this._selectionManagerService});return h&&C.serializeRange(h)===C.serializeRange(g)?{redos:[],undos:[]}:{redos:[{id:W.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`}}}],undos:[{id:W.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(g,f,t,u)),i||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,u,g,(_,h)=>{this._hyperLinkModel.updateHyperLink(t,u,e,{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`},!0)},!0))}}}}_unregisterRange(t){const e=this._rangeDisableMap.get(t);e==null||e.dispose(),this._rangeDisableMap.delete(t)}_unwatchRange(t){const e=this._rangeWatcherMap.get(t);e==null||e.dispose(),this._rangeWatcherMap.delete(t)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(n=>{const{unitId:i,subUnitId:s,links:a}=n;a.forEach(d=>{this._registerPosition(i,s,d),this._watchPosition(i,s,d),this._registerRange(i,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:i,silent:s}=t,a=this._hyperLinkModel.getHyperLink(e,n,i);if(!a)return;this._unregisterPosition(i),this._registerPosition(e,n,a),s||(this._unwatchPosition(i),this._watchPosition(e,n,a));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:i}=n;i.forEach(s=>{this._unregisterPosition(s.id),this._unwatchPosition(s.id),this._unregisterRange(s.id),this._unwatchRange(s.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(o.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};G=ke([z(0,o.Inject(m.RefRangeService)),z(1,o.Inject(p.HyperLinkModel)),z(2,o.Inject(m.SheetsSelectionsService)),z(3,o.ICommandService)],G);var Pe=Object.defineProperty,be=Object.getOwnPropertyDescriptor,Te=(r,t,e,n)=>{for(var i=n>1?void 0:n?be(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Pe(t,e,i),i},te=(r,t)=>(e,n)=>t(e,n,r);let Y=class extends o.Disposable{constructor(r,t,e){super(),this._sheetInterceptorService=r,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{var t;if(r.id===m.RemoveSheetCommand.id){const e=r.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const i=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const a=this._hyperLinkModel.getSubUnit(i,s),d=a.map(l=>({id:k.id,params:{unitId:i,subUnitId:s,id:l.id}})),c=a.map(l=>({id:E.id,params:{unitId:i,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};Y=Te([te(0,o.Inject(m.SheetInterceptorService)),te(1,o.IUniverInstanceService),te(2,o.Inject(p.HyperLinkModel))],Y);var He=Object.defineProperty,Ne=Object.getOwnPropertyDescriptor,Oe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ne(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&He(t,e,i),i},ne=(r,t)=>(e,n)=>t(e,n,r);let q=class extends o.Disposable{constructor(t,e,n){super();L(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let i=n.get(e);return i||(i=new o.ObjectMatrix,n.set(e,i)),i}_isLegalRangeUrl(t,e){var i,s,a;const n=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(i=d.get("gid"))!=null?i:"",range:(s=d.get("range"))!=null?s:"",rangeid:(a=d.get("rangeid"))!=null?a:""};if(c.range&&c.gid){const l=c.gid,u=n.getSheetBySheetId(l);if(!u)return null;const g=C.deserializeRangeWithSheet(c.range).range;if(o.isValidRange(g,u)&&c.range!==$)return{range:g,worksheet:u}}}return null}_registerRange(t,e,n,i,s){var d,c,l,u;const a=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(g=>{var f;return g.rangeType===o.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(f=g.properties)==null?void 0:f.url)})){const g=new o.DisposableCollection;let f=!1;(u=(l=s.body)==null?void 0:l.customRanges)==null||u.forEach(_=>{var h;if(_.rangeType===o.CustomRangeType.HYPERLINK){const y=(h=_.properties)==null?void 0:h.url,I=this._isLegalRangeUrl(t,y);if(I){const{range:v,worksheet:U}=I;f=!0,g.add(this._refRangeService.registerRefRange(v,S=>{const R=m.handleDefaultRangeChangeWithEffectRefCommands(v,S);return R&&o.Rectangle.equals(R,v)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:K.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:_.rangeId,url:`#gid=${e}&range=${R?C.serializeRange(R):$}`}}],undos:[{id:K.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:_.rangeId,url:y}}],redos:[]}},U.getUnitId(),U.getSheetId()))}}}),f&&a.setValue(n,i,g)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId(),a=this._enusreMap(n,s);i.getCellMatrix().forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,s,d,c,l.p)})})};this._univerInstanceService.getAllUnitsForType(o.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(e=>{e.type===o.UniverInstanceType.UNIVER_SHEET&&t(e)}))}_initWorkbookUnload(){this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===o.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId();this._enusreMap(n,s).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}})}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===m.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:i,cellValue:s}=e,a=this._enusreMap(n,i);s&&new o.ObjectMatrix(s).forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,i,d,c,l.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===K.id){const e=t.params,{unitId:n,subUnitId:i,row:s,col:a}=e,d=m.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:i}),l=this._enusreMap(n,i).getValue(s,a);if(l&&l.dispose(),d){const{worksheet:u}=d,g=u.getCellRaw(s,a);g&&g.p&&this._registerRange(n,i,s,a,g.p)}}}))}};q=Oe([ne(0,o.ICommandService),ne(1,o.IUniverInstanceService),ne(2,o.Inject(m.RefRangeService))],q);var De=Object.defineProperty,Ve=Object.getOwnPropertyDescriptor,$e=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ve(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&De(t,e,i),i},F=(r,t)=>(e,n)=>t(e,n,r);let J=class extends o.Disposable{constructor(r,t,e,n){super(),this._sheetInterceptorService=r,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.SetRangeValuesCommand.id){const t=r.params,{unitId:e,subUnitId:n}=t,i=[],s=[];return t.cellValue&&new o.ObjectMatrix(t.cellValue).forValue((a,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,a,d);c&&(i.push({id:k.id,params:{unitId:e,subUnitId:n,id:c.id}}),s.push({id:E.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:s,redos:i}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.ClearSelectionContentCommand.id||r.id===m.ClearSelectionAllCommand.id||r.id===m.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),i=m.getSheetCommandTarget(this._univerInstanceService);if(n&&i){const{unitId:s,subUnitId:a}=i;o.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(s,a,d,c);l&&(t.push({id:k.id,params:{unitId:s,subUnitId:a,id:l.id}}),e.push({id:E.id,params:{unitId:s,subUnitId:a,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(m.AFTER_CELL_EDIT,{handler:(r,t,e)=>{if(!r||r.p)return e(r);if(typeof r.v=="string"&&o.Tools.isLegalUrl(r.v)&&r.v[r.v.length-1]!==" "){const{unitId:n,subUnitId:i}=t,s=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET),a=s==null?void 0:s.getSheetBySheetId(i);if(!a)return e(r);const d=a.getBlankCellDocumentModel(r);if(!d.documentModel)return e(r);const c=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:r.v.length,collapsed:!1},body:{dataStream:`${r.v}`,customRanges:[{startIndex:0,endIndex:r.v.length-1,rangeId:o.generateRandomId(),rangeType:o.CustomRangeType.HYPERLINK,properties:{url:r.v}}]},doc:d.documentModel});if(!c)return e(r);const l=d.documentModel.getBody();return o.TextX.apply(l,c.serialize()),e({...r,p:{id:o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:l,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(r)}}))}};J=$e([F(0,o.Inject(m.SheetInterceptorService)),F(1,o.Inject(p.HyperLinkModel)),F(2,o.Inject(m.SheetsSelectionsService)),F(3,o.IUniverInstanceService)],J);var oe=(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))(oe||{}),je=Object.defineProperty,Ae=Object.getOwnPropertyDescriptor,xe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ae(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&je(t,e,i),i},de=(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:ae,businesses:[oe.UNIVER_SHEET],toJson:e=>r(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(i=>{n[i].forEach(a=>{this._hyperLinkModel.addHyperLink(e,i,a)})})}}))}};X=xe([de(0,o.IResourceManagerService),de(1,o.Inject(p.HyperLinkModel))],X);const ce={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:I,id:v}=f,U=g.getCell(y,I),S=g.getBlankCellDocumentModel(U),R=S.documentModel.getSnapshot(),M=o.Tools.deepClone(R.body);if(!M)return!1;let P;if(h?P=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:M.dataStream.length-2,collapsed:!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:M,ranges:[{startOffset:0,endOffset:M.dataStream.length-2,collapsed:!1}],rangeId:v,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:_,refId:v}}),!P)return!1;const j=o.TextX.apply(M,P.serialize()),b={p:{...R,body:j},t:o.CellValueType.STRING},N=await a.onWriteCell(u,g,y,I,b),O={unitId:c,subUnitId:l,cellValue:{[f.row]:{[f.column]:N}}},re={id:m.SetRangeValuesMutation.id,params:O},Q=m.SetRangeValuesUndoMutationFactory(r,O),se={id:m.SetRangeValuesMutation.id,params:Q},A=[re],D=[se],V=s.getHyperLinkByLocation(c,l,y,I);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}},le={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}},ue={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 U=o.TextX.apply(y.body,v.serialize()),S=[],R=[],M={unitId:u,subUnitId:g,cellValue:{[d]:{[c]:{p:{...y,body:U},t:o.CellValueType.STRING}}}};S.push({id:m.SetRangeValuesMutation.id,params:M});const P=m.SetRangeValuesUndoMutationFactory(r,M);R.push({id:m.SetRangeValuesMutation.id,params:P});const j=s.getHyperLinkByLocation(u,g,d,c);return j&&(S.push({id:k.id,params:{unitId:u,subUnitId:g,id:l}}),R.push({id:E.id,params:{unitId:u,subUnitId:g,link:{...j}}})),o.sequenceExecute(S,e).result?(n.pushUndoRedo({redoMutations:S,undoMutations:R,unitID:u}),!0):!1}},pe={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}},ge={type:o.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(r,t){var ye,ve,Se;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:I,display:v=""}=c,U=_.getCell(l,u);if(!U)return!1;const S=_.getCellDocumentModelWithFormula(U);if(!(S!=null&&S.documentModel))return!1;const R=S.documentModel.getSnapshot(),M=(ve=(ye=R.body)==null?void 0:ye.customRanges)==null?void 0:ve.find(Ze=>Ze.rangeId===g);if(!M)return!1;const P=o.generateRandomId(),H=(Se=o.getBodySlice(S.documentModel.getBody(),M.startIndex,M.endIndex+1).textRuns)==null?void 0:Se[0];H&&(H.ed=v.length+1);const b=x.replaceSelectionFactory(r,{unitId:h,body:{dataStream:`${v}`,customRanges:[{rangeId:P,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:v.length-1,properties:{url:I}}],textRuns:H?[H]:void 0},selection:{startOffset:M.startIndex,endOffset:M.endIndex+1,collapsed:!1},doc:S.documentModel});if(!b)return!1;const N=o.TextX.apply(o.Tools.deepClone(R.body),b.textX.serialize()),O={p:{...R,body:N},t:o.CellValueType.STRING},re=await a.onWriteCell(f,_,l,u,O),Q={id:m.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:y,cellValue:{[l]:{[u]:re}}}},se=m.SetRangeValuesUndoMutationFactory(r,Q.params),A={id:m.SetRangeValuesMutation.id,params:se},D=[Q],V=[A],ee=s.getHyperLinkByLocation(h,y,l,u);return ee&&(D.push({id:k.id,params:{unitId:h,subUnitId:y,id:ee.id}}),V.push({id:E.id,params:{unitId:h,subUnitId:y,link:ee}})),await o.sequenceExecuteAsync(D,e)?(n.pushUndoRedo({redoMutations:D,undoMutations:V,unitID:h}),!0):!1}},he={type:o.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(r,t)=>{var h,y,I,v;if(!t)return!1;const{documentId:e,payload:n,id:i}=t,s=r.get(o.IUniverInstanceService),a=r.get(o.ICommandService),d=s.getUnit(e,o.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(y=(h=d.getBody())==null?void 0:h.customRanges)==null?void 0:y.find(U=>U.rangeId===i);if(!c)return!1;const l=(I=t.payload.display)!=null?I:"",u=o.generateRandomId(),f=(v=o.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:v[0];f&&(f.ed=l.length+1);const _=x.replaceSelectionFactory(r,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:u,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:f?[f]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return _?a.syncExecuteCommand(_.id,_.params):!1}};var We=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,Ke=(r,t,e,n)=>{for(var i=n>1?void 0:n?Be(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&We(t,e,i),i},ze=(r,t)=>(e,n)=>t(e,n,r);let Z=class extends o.Disposable{constructor(r){super(),this._commandService=r,this._registerCommands()}_registerCommands(){[ce,ge,ue,he,pe,le,E,W,k,B,K].forEach(r=>{this._commandService.registerCommand(r)})}};Z=Ke([ze(0,o.ICommandService)],Z);var Ge=Object.defineProperty,Ye=Object.getOwnPropertyDescriptor,qe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ye(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Ge(t,e,i),i},ie=(r,t)=>(e,n)=>t(e,n,r);p.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${w.SHEET}=${e}${n?`&${typeof n=="string"?w.DEFINE_NAME:w.RANGE}=${typeof n=="string"?n:C.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,i,s;if(t.startsWith("#")){const a=new URLSearchParams(t.slice(1)),d={gid:(e=a.get("gid"))!=null?e:"",range:(n=a.get("range"))!=null?n:"",rangeid:(i=a.get("rangeid"))!=null?i:"",unitid:(s=a.get("unitid"))!=null?s:""},c=this._getURLName(d);return{type:c.type,name:c.name,url:t,searchObj:d}}else return{type:w.URL,name:t,url:t,searchObj:null}}_getURLName(t){var u;const{gid:e,range:n,rangeid:i,unitid:s}=t,a=s?this._univerInstanceService.getUnit(s,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),d={type:w.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!a)return d;const c=e?a.getSheetBySheetId(e):a.getActiveSheet(),l=(u=c==null?void 0:c.getName())!=null?u:"";if(n){if(!c)return d;const g=C.deserializeRangeWithSheet(n).range;return o.isValidRange(g,c)&&n!==$?{type:w.RANGE,name:C.serializeRangeWithSheet(l,g)}:d}if(i){const g=this._definedNamesService.getValueById(a.getUnitId(),i);return g?{type:w.DEFINE_NAME,name:g.formulaOrRefString}:d}if(e){const g=a.getSheetBySheetId(e);return g?{type:w.SHEET,name:g.getName()}:d}return d}},p.SheetsHyperLinkParserService=qe([ie(0,o.IUniverInstanceService),ie(1,o.Inject(o.LocaleService)),ie(2,C.IDefinedNamesService)],p.SheetsHyperLinkParserService);var me=Object.defineProperty,Fe=Object.getOwnPropertyDescriptor,Je=(r,t,e)=>t in r?me(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Xe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Fe(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&me(t,e,i),i},fe=(r,t)=>(e,n)=>t(e,n,r),_e=(r,t,e)=>Je(r,typeof t!="symbol"?t+"":t,e);p.UniverSheetsHyperLinkPlugin=class extends o.Plugin{constructor(t=Le,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...i}=this._config;this._configService.setConfig(Ue,i)}onStarting(){o.registerDependencies(this._injector,[[p.HyperLinkModel],[p.SheetsHyperLinkParserService],[X],[Z],[G],[J],[Y],[q]]),o.touchDependencies(this._injector,[[G],[X],[Z],[J],[Y],[q]])}},_e(p.UniverSheetsHyperLinkPlugin,"pluginName",ae),_e(p.UniverSheetsHyperLinkPlugin,"type",o.UniverInstanceType.UNIVER_SHEET),p.UniverSheetsHyperLinkPlugin=Xe([o.DependentOn(m.UniverSheetsPlugin),fe(1,o.Inject(o.Injector)),fe(2,o.IConfigService)],p.UniverSheetsHyperLinkPlugin),p.AddHyperLinkCommand=ce,p.AddHyperLinkMutation=E,p.AddRichHyperLinkCommand=le,p.CancelHyperLinkCommand=ue,p.CancelRichHyperLinkCommand=pe,p.ERROR_RANGE=$,p.RemoveHyperLinkMutation=k,p.SheetHyperLinkType=w,p.UpdateHyperLinkCommand=ge,p.UpdateHyperLinkMutation=W,p.UpdateHyperLinkRefMutation=B,p.UpdateRichHyperLinkCommand=he,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",
3
+ "version": "0.5.1-nightly.202411301606",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -51,18 +51,18 @@
51
51
  "rxjs": ">=7.0.0"
52
52
  },
53
53
  "dependencies": {
54
- "@univerjs/protocol": "0.1.39-alpha.45",
55
- "@univerjs/engine-formula": "0.5.0",
56
- "@univerjs/sheets": "0.5.0",
57
- "@univerjs/docs": "0.5.0",
58
- "@univerjs/core": "0.5.0"
54
+ "@univerjs/protocol": "0.1.39",
55
+ "@univerjs/core": "0.5.1-nightly.202411301606",
56
+ "@univerjs/docs": "0.5.1-nightly.202411301606",
57
+ "@univerjs/engine-formula": "0.5.1-nightly.202411301606",
58
+ "@univerjs/sheets": "0.5.1-nightly.202411301606"
59
59
  },
60
60
  "devDependencies": {
61
61
  "rxjs": "^7.8.1",
62
- "typescript": "^5.6.3",
63
- "vite": "^5.4.11",
64
- "vitest": "^2.1.5",
65
- "@univerjs-infra/shared": "0.5.0"
62
+ "typescript": "^5.7.2",
63
+ "vite": "^6.0.1",
64
+ "vitest": "^2.1.6",
65
+ "@univerjs-infra/shared": "0.5.1"
66
66
  },
67
67
  "space": {
68
68
  ".": {
package/LICENSE DELETED
@@ -1,176 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS