@univerjs/sheets-hyper-link 0.6.6 → 0.6.7
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 +1 -1
- package/lib/es/index.js +69 -69
- package/lib/umd/index.js +1 -1
- package/package.json +9 -9
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var Ie=Object.defineProperty;var Re=(i,t,e)=>t in i?Ie(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var C=(i,t,e)=>Re(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),Me=require("rxjs"),h=require("@univerjs/sheets"),k=require("@univerjs/engine-formula"),Z=require("@univerjs/docs");var Ce=Object.getOwnPropertyDescriptor,ke=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ce(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},Ue=(i,t)=>(e,n)=>t(e,n,i);exports.HyperLinkModel=class extends o.Disposable{constructor(e){super();C(this,"_linkUpdate$",new Me.Subject);C(this,"linkUpdate$",this._linkUpdate$.asObservable());C(this,"_linkMap",new Map);C(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let r=this._linkMap.get(e);r||(r=new Map,this._linkMap.set(e,r));let s=r.get(n);s||(s=new o.ObjectMatrix,r.set(n,s));let a=this._linkPositionMap.get(e);a||(a=new Map,this._linkPositionMap.set(e,a));let d=a.get(n);return d||(d=new Map,a.set(n,d)),{matrix:s,positionMap:d}}addHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n);return s.setValue(r.row,r.column,r),a.set(r.id,{row:r.row,column:r.column,link:r}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:r,type:"add"}),!0}updateHyperLink(e,n,r,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(r);if(!l)return!0;const u=d.getValue(l.row,l.column);return u&&(Object.assign(u,s),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:u.display,payload:u.payload},id:r,type:"update",silent:a})),!0}updateHyperLinkRef(e,n,r,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(r);if(!l)return!0;let u=d.getValue(l.row,l.column);return!u||u.id!==r?u=l.link:d.realDeleteValue(l.row,l.column),Object.assign(u,s),c.set(r,{...s,link:u}),d.setValue(s.row,s.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:r,type:"updateRef",silent:a}),!0}removeHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(r);if(!d)return!1;a.delete(r);const c=s.getValue(d.row,d.column);return c&&c.id===r&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(r);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,r,s){const{matrix:a}=this._ensureMap(e,n);return a.getValue(r,s)}getHyperLinkByLocationSync(e,n,r,s){var p,m,f,g,y;const{matrix:a}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,o.UniverInstanceType.UNIVER_SHEET),c=(p=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:p.getCellRaw(r,s),l=((y=(g=c==null?void 0:c.v)!=null?g:(f=(m=c==null?void 0:c.p)==null?void 0:m.body)==null?void 0:f.dataStream.slice(0,-2))!=null?y:"").toString(),u=a.getValue(r,s);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:r}=this._ensureMap(e,n),s=[];return r.forValue((a,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(r=>{const s=this.getSubUnit(e,r);return{unitId:e,subUnitId:r,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}};exports.HyperLinkModel=ke([Ue(0,o.IUniverInstanceService)],exports.HyperLinkModel);var U=(i=>(i.SHEET="gid",i.RANGE="range",i.DEFINE_NAME="rangeid",i.INVALID="invalid",i.URL="url",i))(U||{});const Le="sheets-hyper-link.config",de={},L={type:o.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,link:s}=t;return e.addHyperLink(n,r,s)}},E={type:o.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,id:s}=t;return e.removeHyperLink(n,r,s)}},F={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,payload:s,id:a}=t;return e.updateHyperLink(n,r,a,s,!1)}},K={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,id:s,row:a,column:d,silent:c}=t;return e.updateHyperLinkRef(n,r,s,{row:a,column:d},c)}},B={type:o.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(i,t){var f,g,y;if(!t)return!1;const{unitId:e,subUnitId:n,row:r,col:s,id:a,url:d}=t,c=i.get(o.IUniverInstanceService),l=h.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:u}=l,p=u.getCellRaw(r,s),m=(y=(g=(f=p==null?void 0:p.p)==null?void 0:f.body)==null?void 0:g.customRanges)==null?void 0:y.find(_=>_.rangeType===o.CustomRangeType.HYPERLINK&&_.rangeId===a);return m&&(m.properties.url=d),!0}},ue="SHEET_HYPER_LINK_PLUGIN",x="err";var Ee=Object.getOwnPropertyDescriptor,we=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ee(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},j=(i,t)=>(e,n)=>t(e,n,i);let z=class extends o.Disposable{constructor(t,e,n,r){super();C(this,"_disposableMap",new Map);C(this,"_watchDisposableMap",new Map);C(this,"_rangeDisableMap",new Map);C(this,"_rangeWatcherMap",new Map);C(this,"_handlePositionChange",(t,e,n,r,s)=>{const a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return r?{redos:[{id:K.id,params:{unitId:t,subUnitId:e,id:n.id,row:r.startRow,column:r.startColumn,silent:s}}],undos:[{id:K.id,params:{unitId:t,subUnitId:e,id:n.id,row:a.startRow,column:a.startColumn,silent:s}}]}:{redos:[{id:E.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:L.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=r,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const r=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},a=d=>{const c=h.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===s.startColumn&&l.startRow===s.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(r,this._refRangeService.registerRefRange(s,a,t,e))}_watchPosition(t,e,n){const r=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(r,this._refRangeService.watchRange(t,e,s,(a,d)=>{const{redos:c}=this._handlePositionChange(t,e,n,d,!0);o.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(t){const e=this._disposableMap.get(t);e==null||e.dispose(),this._disposableMap.delete(t)}_unwatchPosition(t){const e=this._watchDisposableMap.get(t);e==null||e.dispose(),this._watchDisposableMap.delete(t)}_registerRange(t,e,n,r=!1){var s,a,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(s=c.get("gid"))!=null?s:"",range:(a=c.get("range"))!=null?a:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const u=l.gid,p=k.deserializeRangeWithSheet(l.range).range;if(o.isValidRange(p)&&l.range!==x){const m=f=>{const g=h.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(p,f,{selectionManagerService:this._selectionManagerService});return g&&k.serializeRange(g)===k.serializeRange(p)?{redos:[],undos:[]}:{redos:[{id:F.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:`#gid=${u}&range=${g?k.serializeRange(g):"err"}`}}}],undos:[{id:F.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(p,m,t,u)),r||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,u,p,(f,g)=>{this._hyperLinkModel.updateHyperLink(t,u,e,{payload:`#gid=${u}&range=${g?k.serializeRange(g):"err"}`},!0)},!0))}}}}_unregisterRange(t){const e=this._rangeDisableMap.get(t);e==null||e.dispose(),this._rangeDisableMap.delete(t)}_unwatchRange(t){const e=this._rangeWatcherMap.get(t);e==null||e.dispose(),this._rangeWatcherMap.delete(t)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(n=>{const{unitId:r,subUnitId:s,links:a}=n;a.forEach(d=>{this._registerPosition(r,s,d),this._watchPosition(r,s,d),this._registerRange(r,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:r,silent:s}=t,a=this._hyperLinkModel.getHyperLink(e,n,r);if(!a)return;this._unregisterPosition(r),this._registerPosition(e,n,a),s||(this._unwatchPosition(r),this._watchPosition(e,n,a));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:r}=n;r.forEach(s=>{this._unregisterPosition(s.id),this._unwatchPosition(s.id),this._unregisterRange(s.id),this._unwatchRange(s.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(o.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};z=we([j(0,o.Inject(h.RefRangeService)),j(1,o.Inject(exports.HyperLinkModel)),j(2,o.Inject(h.SheetsSelectionsService)),j(3,o.ICommandService)],z);var be=Object.getOwnPropertyDescriptor,Te=(i,t,e,n)=>{for(var r=n>1?void 0:n?be(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},te=(i,t)=>(e,n)=>t(e,n,i);let G=class extends o.Disposable{constructor(i,t,e){super(),this._sheetInterceptorService=i,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{var t;if(i.id===h.RemoveSheetCommand.id){const e=i.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const r=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const a=this._hyperLinkModel.getSubUnit(r,s),d=a.map(l=>({id:E.id,params:{unitId:r,subUnitId:s,id:l.id}})),c=a.map(l=>({id:L.id,params:{unitId:r,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};G=Te([te(0,o.Inject(h.SheetInterceptorService)),te(1,o.IUniverInstanceService),te(2,o.Inject(exports.HyperLinkModel))],G);var He=Object.getOwnPropertyDescriptor,Pe=(i,t,e,n)=>{for(var r=n>1?void 0:n?He(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},ne=(i,t)=>(e,n)=>t(e,n,i);let Y=class extends o.Disposable{constructor(t,e,n){super();C(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let r=n.get(e);return r||(r=new o.ObjectMatrix,n.set(e,r)),r}_isLegalRangeUrl(t,e){var r,s,a;const n=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(r=d.get("gid"))!=null?r:"",range:(s=d.get("range"))!=null?s:"",rangeid:(a=d.get("rangeid"))!=null?a:""};if(c.range&&c.gid){const l=c.gid,u=n.getSheetBySheetId(l);if(!u)return null;const p=k.deserializeRangeWithSheet(c.range).range;if(o.isValidRange(p,u)&&c.range!==x)return{range:p,worksheet:u}}}return null}_registerRange(t,e,n,r,s){var d,c,l,u;const a=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(p=>{var m;return p.rangeType===o.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(m=p.properties)==null?void 0:m.url)})){const p=new o.DisposableCollection;let m=!1;(u=(l=s.body)==null?void 0:l.customRanges)==null||u.forEach(f=>{var g;if(f.rangeType===o.CustomRangeType.HYPERLINK){const y=(g=f.properties)==null?void 0:g.url,_=this._isLegalRangeUrl(t,y);if(_){const{range:S,worksheet:M}=_;m=!0,p.add(this._refRangeService.registerRefRange(S,v=>{const I=h.handleDefaultRangeChangeWithEffectRefCommands(S,v);return I&&o.Rectangle.equals(I,S)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:r,id:f.rangeId,url:`#gid=${e}&range=${I?k.serializeRange(I):x}`}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:r,id:f.rangeId,url:y}}],redos:[]}},M.getUnitId(),M.getSheetId()))}}}),m&&a.setValue(n,r,p)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(r=>{const s=r.getSheetId(),a=this._enusreMap(n,s);r.getCellMatrix().forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,s,d,c,l.p)})})};this._univerInstanceService.getAllUnitsForType(o.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(e=>{e.type===o.UniverInstanceType.UNIVER_SHEET&&t(e)}))}_initWorkbookUnload(){this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===o.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(r=>{const s=r.getSheetId();this._enusreMap(n,s).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}})}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===h.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:r,cellValue:s}=e,a=this._enusreMap(n,r);s&&new o.ObjectMatrix(s).forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,r,d,c,l.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===B.id){const e=t.params,{unitId:n,subUnitId:r,row:s,col:a}=e,d=h.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:r}),l=this._enusreMap(n,r).getValue(s,a);if(l&&l.dispose(),d){const{worksheet:u}=d,p=u.getCellRaw(s,a);p&&p.p&&this._registerRange(n,r,s,a,p.p)}}}))}};Y=Pe([ne(0,o.ICommandService),ne(1,o.IUniverInstanceService),ne(2,o.Inject(h.RefRangeService))],Y);var De=Object.getOwnPropertyDescriptor,Oe=(i,t,e,n)=>{for(var r=n>1?void 0:n?De(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},W=(i,t)=>(e,n)=>t(e,n,i);let q=class extends o.Disposable{constructor(i,t,e,n){super(),this._sheetInterceptorService=i,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(i.id===h.SetRangeValuesCommand.id){const t=i.params,{unitId:e,subUnitId:n}=t,r=[],s=[];return t.cellValue&&new o.ObjectMatrix(t.cellValue).forValue((a,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,a,d);c&&(r.push({id:E.id,params:{unitId:e,subUnitId:n,id:c.id}}),s.push({id:L.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:s,redos:r}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(i.id===h.ClearSelectionContentCommand.id||i.id===h.ClearSelectionAllCommand.id||i.id===h.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),r=h.getSheetCommandTarget(this._univerInstanceService);if(n&&r){const{unitId:s,subUnitId:a}=r;o.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(s,a,d,c);l&&(t.push({id:E.id,params:{unitId:s,subUnitId:a,id:l.id}}),e.push({id:L.id,params:{unitId:s,subUnitId:a,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(h.AFTER_CELL_EDIT,{handler:(i,t,e)=>{if(!i||i.p)return e(i);if(typeof i.v=="string"&&o.Tools.isLegalUrl(i.v)&&i.v[i.v.length-1]!==" "){const{unitId:n,subUnitId:r}=t,s=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET),a=s==null?void 0:s.getSheetBySheetId(r);if(!a)return e(i);const d=a.getBlankCellDocumentModel(i);if(!d.documentModel)return e(i);const c=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:i.v.length,collapsed:!1},body:{dataStream:`${i.v}`,customRanges:[{startIndex:0,endIndex:i.v.length-1,rangeId:o.generateRandomId(),rangeType:o.CustomRangeType.HYPERLINK,properties:{url:i.v}}]},doc:d.documentModel});if(!c)return e(i);const l=d.documentModel.getBody();return o.TextX.apply(l,c.serialize()),e({...i,p:{id:o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:l,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(i)}}))}};q=Oe([W(0,o.Inject(h.SheetInterceptorService)),W(1,o.Inject(exports.HyperLinkModel)),W(2,o.Inject(h.SheetsSelectionsService)),W(3,o.IUniverInstanceService)],q);var pe=(i=>(i[i.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",i[i.UNIVER_DOC=1]="UNIVER_DOC",i[i.UNIVER_SHEET=2]="UNIVER_SHEET",i[i.UNIVER_SLIDE=3]="UNIVER_SLIDE",i[i.UNIVER_PROJECT=4]="UNIVER_PROJECT",i[i.UNRECOGNIZED=-1]="UNRECOGNIZED",i))(pe||{}),Ne=Object.getOwnPropertyDescriptor,Ve=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ne(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},ce=(i,t)=>(e,n)=>t(e,n,i);let J=class extends o.Disposable{constructor(i,t){super(),this._resourceManagerService=i,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const i=e=>{const n=this._hyperLinkModel.getUnit(e),r={};return n?(n.forEach(s=>{r[s.subUnitId]=s.links.map(({display:a,...d})=>d)}),JSON.stringify(r)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:ue,businesses:[pe.UNIVER_SHEET],toJson:e=>i(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(r=>{n[r].forEach(a=>{this._hyperLinkModel.addHyperLink(e,r,a)})})}}))}};J=Ve([ce(0,o.IResourceManagerService),ce(1,o.Inject(exports.HyperLinkModel))],J);const ge={type:o.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(i,t){if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=i.get(h.SheetInterceptorService),d=h.getSheetCommandTarget(r,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:u,worksheet:p}=d,{link:m}=t,{payload:f,display:g,row:y,column:_,id:S}=m,M=p.getCell(y,_),v=p.getBlankCellDocumentModel(M),I=v.documentModel.getSnapshot(),R=o.Tools.deepClone(I.body);if(!R)return!1;let w;if(g?w=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:R.dataStream.length-2,collapsed:R.dataStream.length-2===0},body:{dataStream:`${g}`,customRanges:[{startIndex:0,endIndex:g.length-1,rangeType:o.CustomRangeType.HYPERLINK,rangeId:S,properties:{url:f}}]},doc:v.documentModel}):w=o.BuildTextUtils.customRange.add({body:R,ranges:[{startOffset:0,endOffset:R.dataStream.length-2,collapsed:!1}],rangeId:S,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:f,refId:S}}),!w)return!1;const N=o.TextX.apply(R,w.serialize()),b={p:{...I,body:N},t:o.CellValueType.STRING},D=a.onWriteCell(u,p,y,_,b),O={unitId:c,subUnitId:l,cellValue:{[m.row]:{[m.column]:D}}},Q={id:h.SetRangeValuesMutation.id,params:O},$=h.SetRangeValuesUndoMutationFactory(i,O),ee={id:h.SetRangeValuesMutation.id,params:$},V=[Q],T=[ee],H=s.getHyperLinkByLocation(c,l,y,_);return H&&(V.push({id:E.id,params:{unitId:c,subUnitId:l,id:H.id}}),T.push({id:L.id,params:{unitId:c,subUnitId:l,link:H}})),await o.sequenceExecute(V,e)?await a.onValidateCell(u,p,y,_)===!1?(o.sequenceExecute(T,e),!1):(n.pushUndoRedo({redoMutations:V,undoMutations:T,unitID:c}),!0):!1}},he={id:"sheets.command.add-rich-hyper-link",type:o.CommandType.COMMAND,handler:async(i,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,r=i.get(o.ICommandService),s=o.generateRandomId(),{payload:a}=n,d=Z.addCustomRangeBySelectionFactory(i,{unitId:e,rangeId:s,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:a,refId:s}});return d?r.syncExecuteCommand(d.id,d.params):!1}},me={type:o.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(i,t){var b,D;if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=h.getSheetCommandTarget(r,t);if(!a)return!1;const{row:d,column:c,id:l}=t,{unitId:u,subUnitId:p,worksheet:m}=a,f=m.getCell(d,c);if(!f)return!1;const g=m.getCellDocumentModelWithFormula(f);if(!(g!=null&&g.documentModel))return!1;const y=o.Tools.deepClone(g.documentModel.getSnapshot()),_=(D=(b=y.body)==null?void 0:b.customRanges)==null?void 0:D.find(O=>`${O.rangeId}`===l);if(!_)return!1;const S=o.BuildTextUtils.customRange.delete({documentDataModel:g.documentModel,rangeId:_.rangeId});if(!S)return!1;const M=o.TextX.apply(y.body,S.serialize()),v=[],I=[],R={unitId:u,subUnitId:p,cellValue:{[d]:{[c]:{p:{...y,body:M},t:o.CellValueType.STRING}}}};v.push({id:h.SetRangeValuesMutation.id,params:R});const w=h.SetRangeValuesUndoMutationFactory(i,R);I.push({id:h.SetRangeValuesMutation.id,params:w});const N=s.getHyperLinkByLocation(u,p,d,c);return N&&(v.push({id:E.id,params:{unitId:u,subUnitId:p,id:l}}),I.push({id:L.id,params:{unitId:u,subUnitId:p,link:{...N}}})),o.sequenceExecute(v,e).result?(n.pushUndoRedo({redoMutations:v,undoMutations:I,unitID:u}),!0):!1}},fe={type:o.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(i,t){var u,p;if(!t)return!1;const{id:e,documentId:n}=t,r=i.get(o.ICommandService),a=i.get(o.IUniverInstanceService).getUnit(n,o.UniverInstanceType.UNIVER_DOC),d=(p=(u=a==null?void 0:a.getBody())==null?void 0:u.customRanges)==null?void 0:p.find(m=>m.rangeId===e);let c=null;d&&d.endIndex===a.getBody().dataStream.length-3&&(c={dataStream:" "});const l=Z.deleteCustomRangeFactory(i,{unitId:n,rangeId:e,insert:c});return l?r.syncExecuteCommand(l.id,l.params):!1}},ye={type:o.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(i,t){var ie,se,ae;if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=i.get(h.SheetInterceptorService),d=h.getSheetCommandTarget(r,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:u,id:p}=t,{workbook:m,worksheet:f,unitId:g,subUnitId:y}=d,{payload:_,display:S=""}=c,M=f.getCell(l,u);if(!M)return!1;const v=f.getCellDocumentModelWithFormula(M);if(!(v!=null&&v.documentModel))return!1;const I=v.documentModel.getSnapshot(),R=(se=(ie=I.body)==null?void 0:ie.customRanges)==null?void 0:se.find(oe=>`${oe.rangeId}`===p);if(!R)return!1;const w=o.generateRandomId(),P=(ae=o.getBodySlice(v.documentModel.getBody(),R.startIndex,R.endIndex+1).textRuns)==null?void 0:ae[0];P&&(P.ed=S.length+1);const b=Z.replaceSelectionFactory(i,{unitId:g,body:{dataStream:`${S}`,customRanges:[{rangeId:w,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:S.length-1,properties:{url:_}}],textRuns:P?[P]:void 0},selection:{startOffset:R.startIndex,endOffset:R.endIndex+1,collapsed:!1},doc:v.documentModel});if(!b)return!1;const D=o.TextX.apply(o.Tools.deepClone(I.body),b.textX.serialize()),O={p:{...I,body:D},t:o.CellValueType.STRING},Q=a.onWriteCell(m,f,l,u,O),$={id:h.SetRangeValuesMutation.id,params:{unitId:g,subUnitId:y,cellValue:{[l]:{[u]:Q}}}},ee=h.SetRangeValuesUndoMutationFactory(i,$.params),V={id:h.SetRangeValuesMutation.id,params:ee},T=[$],H=[V],A=s.getHyperLinkByLocation(g,y,l,u);return A&&(T.push({id:E.id,params:{unitId:g,subUnitId:y,id:A.id}}),H.push({id:L.id,params:{unitId:g,subUnitId:y,link:A}})),o.sequenceExecute(T,e)?await a.onValidateCell(m,f,l,u)===!1?(o.sequenceExecute(H,e),!1):(n.pushUndoRedo({redoMutations:T,undoMutations:H,unitID:g}),!0):!1}},_e={type:o.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(i,t)=>{var g,y,_,S;if(!t)return!1;const{documentId:e,payload:n,id:r}=t,s=i.get(o.IUniverInstanceService),a=i.get(o.ICommandService),d=s.getUnit(e,o.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(y=(g=d.getBody())==null?void 0:g.customRanges)==null?void 0:y.find(M=>M.rangeId===r);if(!c)return!1;const l=(_=t.payload.display)!=null?_:"",u=o.generateRandomId(),m=(S=o.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:S[0];m&&(m.ed=l.length+1);const f=Z.replaceSelectionFactory(i,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:u,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:m?[m]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return f?a.syncExecuteCommand(f.id,f.params):!1}};var xe=Object.getOwnPropertyDescriptor,$e=(i,t,e,n)=>{for(var r=n>1?void 0:n?xe(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},Ae=(i,t)=>(e,n)=>t(e,n,i);let X=class extends o.Disposable{constructor(i){super(),this._commandService=i,this._registerCommands()}_registerCommands(){[ge,ye,me,_e,fe,he,L,F,E,K,B].forEach(i=>{this._commandService.registerCommand(i)})}};X=$e([Ae(0,o.ICommandService)],X);var je=Object.getOwnPropertyDescriptor,We=(i,t,e,n)=>{for(var r=n>1?void 0:n?je(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},re=(i,t)=>(e,n)=>t(e,n,i);exports.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${U.SHEET}=${e}${n?`&${typeof n=="string"?U.DEFINE_NAME:U.RANGE}=${typeof n=="string"?n:k.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,r,s;if(t.startsWith("#")){const a=new URLSearchParams(t.slice(1)),d={gid:(e=a.get("gid"))!=null?e:"",range:(n=a.get("range"))!=null?n:"",rangeid:(r=a.get("rangeid"))!=null?r:"",unitid:(s=a.get("unitid"))!=null?s:""},c=this._getURLName(d);return{type:c.type,name:c.name,url:t,searchObj:d}}else return{type:U.URL,name:t,url:t,searchObj:null}}_getURLName(t){var u;const{gid:e,range:n,rangeid:r,unitid:s}=t,a=s?this._univerInstanceService.getUnit(s,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),d={type:U.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!a)return d;const c=e?a.getSheetBySheetId(e):a.getActiveSheet(),l=(u=c==null?void 0:c.getName())!=null?u:"";if(n){if(!c)return d;const p=k.deserializeRangeWithSheet(n).range;return o.isValidRange(p,c)&&n!==x?{type:U.RANGE,name:k.serializeRangeWithSheet(l,p)}:d}if(r){const p=this._definedNamesService.getValueById(a.getUnitId(),r);return p?{type:U.DEFINE_NAME,name:p.formulaOrRefString}:d}if(e){const p=a.getSheetBySheetId(e);return p?{type:U.SHEET,name:p.getName()}:d}return d}};exports.SheetsHyperLinkParserService=We([re(0,o.IUniverInstanceService),re(1,o.Inject(o.LocaleService)),re(2,k.IDefinedNamesService)],exports.SheetsHyperLinkParserService);var Be=Object.defineProperty,Fe=Object.getOwnPropertyDescriptor,Ke=(i,t,e)=>t in i?Be(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,ze=(i,t,e,n)=>{for(var r=n>1?void 0:n?Fe(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},le=(i,t)=>(e,n)=>t(e,n,i),Se=(i,t,e)=>Ke(i,typeof t!="symbol"?t+"":t,e);exports.UniverSheetsHyperLinkPlugin=class extends o.Plugin{constructor(t=de,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...r}=o.merge({},de,this._config);this._configService.setConfig(Le,r)}onStarting(){o.registerDependencies(this._injector,[[exports.HyperLinkModel],[exports.SheetsHyperLinkParserService],[J],[X],[z],[q],[G],[Y]]),o.touchDependencies(this._injector,[[z],[J],[X],[q],[G],[Y]])}};Se(exports.UniverSheetsHyperLinkPlugin,"pluginName",ue);Se(exports.UniverSheetsHyperLinkPlugin,"type",o.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsHyperLinkPlugin=ze([o.DependentOn(h.UniverSheetsPlugin),le(1,o.Inject(o.Injector)),le(2,o.IConfigService)],exports.UniverSheetsHyperLinkPlugin);exports.AddHyperLinkCommand=ge;exports.AddHyperLinkMutation=L;exports.AddRichHyperLinkCommand=he;exports.CancelHyperLinkCommand=me;exports.CancelRichHyperLinkCommand=fe;exports.ERROR_RANGE=x;exports.RemoveHyperLinkMutation=E;exports.SheetHyperLinkType=U;exports.UpdateHyperLinkCommand=ye;exports.UpdateHyperLinkMutation=F;exports.UpdateHyperLinkRefMutation=K;exports.UpdateRichHyperLinkCommand=_e;
|
|
1
|
+
"use strict";var Ie=Object.defineProperty;var Re=(i,t,e)=>t in i?Ie(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var C=(i,t,e)=>Re(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),Me=require("rxjs"),h=require("@univerjs/sheets"),k=require("@univerjs/engine-formula"),Z=require("@univerjs/docs");var Ce=Object.getOwnPropertyDescriptor,ke=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ce(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},Ue=(i,t)=>(e,n)=>t(e,n,i);exports.HyperLinkModel=class extends o.Disposable{constructor(e){super();C(this,"_linkUpdate$",new Me.Subject);C(this,"linkUpdate$",this._linkUpdate$.asObservable());C(this,"_linkMap",new Map);C(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let r=this._linkMap.get(e);r||(r=new Map,this._linkMap.set(e,r));let s=r.get(n);s||(s=new o.ObjectMatrix,r.set(n,s));let a=this._linkPositionMap.get(e);a||(a=new Map,this._linkPositionMap.set(e,a));let d=a.get(n);return d||(d=new Map,a.set(n,d)),{matrix:s,positionMap:d}}addHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n);return s.setValue(r.row,r.column,r),a.set(r.id,{row:r.row,column:r.column,link:r}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:r,type:"add"}),!0}updateHyperLink(e,n,r,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(r);if(!l)return!0;const u=d.getValue(l.row,l.column);return u&&(Object.assign(u,s),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:u.display,payload:u.payload},id:r,type:"update",silent:a})),!0}updateHyperLinkRef(e,n,r,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(r);if(!l)return!0;let u=d.getValue(l.row,l.column);return!u||u.id!==r?u=l.link:d.realDeleteValue(l.row,l.column),Object.assign(u,s),c.set(r,{...s,link:u}),d.setValue(s.row,s.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:r,type:"updateRef",silent:a}),!0}removeHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(r);if(!d)return!1;a.delete(r);const c=s.getValue(d.row,d.column);return c&&c.id===r&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(r);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,r,s){const{matrix:a}=this._ensureMap(e,n);return a.getValue(r,s)}getHyperLinkByLocationSync(e,n,r,s){var p,m,f,g,y;const{matrix:a}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,o.UniverInstanceType.UNIVER_SHEET),c=(p=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:p.getCellRaw(r,s),l=((y=(g=c==null?void 0:c.v)!=null?g:(f=(m=c==null?void 0:c.p)==null?void 0:m.body)==null?void 0:f.dataStream.slice(0,-2))!=null?y:"").toString(),u=a.getValue(r,s);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:r}=this._ensureMap(e,n),s=[];return r.forValue((a,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(r=>{const s=this.getSubUnit(e,r);return{unitId:e,subUnitId:r,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}};exports.HyperLinkModel=ke([Ue(0,o.IUniverInstanceService)],exports.HyperLinkModel);var U=(i=>(i.SHEET="gid",i.RANGE="range",i.DEFINE_NAME="rangeid",i.INVALID="invalid",i.URL="url",i))(U||{});const Le="sheets-hyper-link.config",de={},L={type:o.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,link:s}=t;return e.addHyperLink(n,r,s)}},E={type:o.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,id:s}=t;return e.removeHyperLink(n,r,s)}},F={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,payload:s,id:a}=t;return e.updateHyperLink(n,r,a,s,!1)}},K={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,id:s,row:a,column:d,silent:c}=t;return e.updateHyperLinkRef(n,r,s,{row:a,column:d},c)}},B={type:o.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(i,t){var f,g,y;if(!t)return!1;const{unitId:e,subUnitId:n,row:r,col:s,id:a,url:d}=t,c=i.get(o.IUniverInstanceService),l=h.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:u}=l,p=u.getCellRaw(r,s),m=(y=(g=(f=p==null?void 0:p.p)==null?void 0:f.body)==null?void 0:g.customRanges)==null?void 0:y.find(_=>_.rangeType===o.CustomRangeType.HYPERLINK&&_.rangeId===a);return m&&(m.properties.url=d),!0}},ue="SHEET_HYPER_LINK_PLUGIN",x="err";var Ee=Object.getOwnPropertyDescriptor,we=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ee(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},j=(i,t)=>(e,n)=>t(e,n,i);let z=class extends o.Disposable{constructor(t,e,n,r){super();C(this,"_disposableMap",new Map);C(this,"_watchDisposableMap",new Map);C(this,"_rangeDisableMap",new Map);C(this,"_rangeWatcherMap",new Map);C(this,"_handlePositionChange",(t,e,n,r,s)=>{const a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return r?{redos:[{id:K.id,params:{unitId:t,subUnitId:e,id:n.id,row:r.startRow,column:r.startColumn,silent:s}}],undos:[{id:K.id,params:{unitId:t,subUnitId:e,id:n.id,row:a.startRow,column:a.startColumn,silent:s}}]}:{redos:[{id:E.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:L.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=r,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const r=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},a=d=>{const c=h.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===s.startColumn&&l.startRow===s.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(r,this._refRangeService.registerRefRange(s,a,t,e))}_watchPosition(t,e,n){const r=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(r,this._refRangeService.watchRange(t,e,s,(a,d)=>{const{redos:c}=this._handlePositionChange(t,e,n,d,!0);o.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(t){const e=this._disposableMap.get(t);e==null||e.dispose(),this._disposableMap.delete(t)}_unwatchPosition(t){const e=this._watchDisposableMap.get(t);e==null||e.dispose(),this._watchDisposableMap.delete(t)}_registerRange(t,e,n,r=!1){var s,a,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(s=c.get("gid"))!=null?s:"",range:(a=c.get("range"))!=null?a:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const u=l.gid,p=k.deserializeRangeWithSheet(l.range).range;if(o.isValidRange(p)&&l.range!==x){const m=f=>{const g=h.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(p,f,{selectionManagerService:this._selectionManagerService});return g&&k.serializeRange(g)===k.serializeRange(p)?{redos:[],undos:[]}:{redos:[{id:F.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:`#gid=${u}&range=${g?k.serializeRange(g):"err"}`}}}],undos:[{id:F.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(p,m,t,u)),r||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,u,p,(f,g)=>{this._hyperLinkModel.updateHyperLink(t,u,e,{payload:`#gid=${u}&range=${g?k.serializeRange(g):"err"}`},!0)},!0))}}}}_unregisterRange(t){const e=this._rangeDisableMap.get(t);e==null||e.dispose(),this._rangeDisableMap.delete(t)}_unwatchRange(t){const e=this._rangeWatcherMap.get(t);e==null||e.dispose(),this._rangeWatcherMap.delete(t)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(n=>{const{unitId:r,subUnitId:s,links:a}=n;a.forEach(d=>{this._registerPosition(r,s,d),this._watchPosition(r,s,d),this._registerRange(r,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:r,silent:s}=t,a=this._hyperLinkModel.getHyperLink(e,n,r);if(!a)return;this._unregisterPosition(r),this._registerPosition(e,n,a),s||(this._unwatchPosition(r),this._watchPosition(e,n,a));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:r}=n;r.forEach(s=>{this._unregisterPosition(s.id),this._unwatchPosition(s.id),this._unregisterRange(s.id),this._unwatchRange(s.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(o.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};z=we([j(0,o.Inject(h.RefRangeService)),j(1,o.Inject(exports.HyperLinkModel)),j(2,o.Inject(h.SheetsSelectionsService)),j(3,o.ICommandService)],z);var be=Object.getOwnPropertyDescriptor,Te=(i,t,e,n)=>{for(var r=n>1?void 0:n?be(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},te=(i,t)=>(e,n)=>t(e,n,i);let G=class extends o.Disposable{constructor(i,t,e){super(),this._sheetInterceptorService=i,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{var t;if(i.id===h.RemoveSheetCommand.id){const e=i.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const r=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const a=this._hyperLinkModel.getSubUnit(r,s),d=a.map(l=>({id:E.id,params:{unitId:r,subUnitId:s,id:l.id}})),c=a.map(l=>({id:L.id,params:{unitId:r,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};G=Te([te(0,o.Inject(h.SheetInterceptorService)),te(1,o.IUniverInstanceService),te(2,o.Inject(exports.HyperLinkModel))],G);var He=Object.getOwnPropertyDescriptor,Pe=(i,t,e,n)=>{for(var r=n>1?void 0:n?He(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},ne=(i,t)=>(e,n)=>t(e,n,i);let Y=class extends o.Disposable{constructor(t,e,n){super();C(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let r=n.get(e);return r||(r=new o.ObjectMatrix,n.set(e,r)),r}_isLegalRangeUrl(t,e){var r,s,a;const n=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(r=d.get("gid"))!=null?r:"",range:(s=d.get("range"))!=null?s:"",rangeid:(a=d.get("rangeid"))!=null?a:""};if(c.range&&c.gid){const l=c.gid,u=n.getSheetBySheetId(l);if(!u)return null;const p=k.deserializeRangeWithSheet(c.range).range;if(o.isValidRange(p,u)&&c.range!==x)return{range:p,worksheet:u}}}return null}_registerRange(t,e,n,r,s){var d,c,l,u;const a=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(p=>{var m;return p.rangeType===o.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(m=p.properties)==null?void 0:m.url)})){const p=new o.DisposableCollection;let m=!1;(u=(l=s.body)==null?void 0:l.customRanges)==null||u.forEach(f=>{var g;if(f.rangeType===o.CustomRangeType.HYPERLINK){const y=(g=f.properties)==null?void 0:g.url,_=this._isLegalRangeUrl(t,y);if(_){const{range:S,worksheet:M}=_;m=!0,p.add(this._refRangeService.registerRefRange(S,v=>{const I=h.handleDefaultRangeChangeWithEffectRefCommands(S,v);return I&&o.Rectangle.equals(I,S)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:r,id:f.rangeId,url:`#gid=${e}&range=${I?k.serializeRange(I):x}`}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:r,id:f.rangeId,url:y}}],redos:[]}},M.getUnitId(),M.getSheetId()))}}}),m&&a.setValue(n,r,p)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(r=>{const s=r.getSheetId(),a=this._enusreMap(n,s);r.getCellMatrix().forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,s,d,c,l.p)})})};this._univerInstanceService.getAllUnitsForType(o.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(e=>{e.type===o.UniverInstanceType.UNIVER_SHEET&&t(e)}))}_initWorkbookUnload(){this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===o.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(r=>{const s=r.getSheetId();this._enusreMap(n,s).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}})}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===h.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:r,cellValue:s}=e,a=this._enusreMap(n,r);s&&new o.ObjectMatrix(s).forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,r,d,c,l.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===B.id){const e=t.params,{unitId:n,subUnitId:r,row:s,col:a}=e,d=h.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:r}),l=this._enusreMap(n,r).getValue(s,a);if(l&&l.dispose(),d){const{worksheet:u}=d,p=u.getCellRaw(s,a);p&&p.p&&this._registerRange(n,r,s,a,p.p)}}}))}};Y=Pe([ne(0,o.ICommandService),ne(1,o.IUniverInstanceService),ne(2,o.Inject(h.RefRangeService))],Y);var Ne=Object.getOwnPropertyDescriptor,De=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ne(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},W=(i,t)=>(e,n)=>t(e,n,i);let q=class extends o.Disposable{constructor(i,t,e,n){super(),this._sheetInterceptorService=i,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(i.id===h.SetRangeValuesCommand.id){const t=i.params,{unitId:e,subUnitId:n}=t,r=[],s=[];return t.cellValue&&new o.ObjectMatrix(t.cellValue).forValue((a,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,a,d);c&&(r.push({id:E.id,params:{unitId:e,subUnitId:n,id:c.id}}),s.push({id:L.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:s,redos:r}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(i.id===h.ClearSelectionContentCommand.id||i.id===h.ClearSelectionAllCommand.id||i.id===h.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),r=h.getSheetCommandTarget(this._univerInstanceService);if(n&&r){const{unitId:s,subUnitId:a}=r;o.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(s,a,d,c);l&&(t.push({id:E.id,params:{unitId:s,subUnitId:a,id:l.id}}),e.push({id:L.id,params:{unitId:s,subUnitId:a,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(h.AFTER_CELL_EDIT,{handler:(i,t,e)=>{if(!i||i.p)return e(i);if(typeof i.v=="string"&&o.Tools.isLegalUrl(i.v)&&i.v[i.v.length-1]!==" "){const{unitId:n,subUnitId:r}=t,s=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET),a=s==null?void 0:s.getSheetBySheetId(r);if(!a)return e(i);const d=a.getBlankCellDocumentModel(i);if(!d.documentModel)return e(i);const c=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:i.v.length,collapsed:!1},body:{dataStream:`${i.v}`,customRanges:[{startIndex:0,endIndex:i.v.length-1,rangeId:o.generateRandomId(),rangeType:o.CustomRangeType.HYPERLINK,properties:{url:i.v}}]},doc:d.documentModel});if(!c)return e(i);const l=d.documentModel.getBody();return o.TextX.apply(l,c.serialize()),e({...i,p:{id:o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:l,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(i)}}))}};q=De([W(0,o.Inject(h.SheetInterceptorService)),W(1,o.Inject(exports.HyperLinkModel)),W(2,o.Inject(h.SheetsSelectionsService)),W(3,o.IUniverInstanceService)],q);var pe=(i=>(i[i.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",i[i.UNIVER_DOC=1]="UNIVER_DOC",i[i.UNIVER_SHEET=2]="UNIVER_SHEET",i[i.UNIVER_SLIDE=3]="UNIVER_SLIDE",i[i.UNIVER_PROJECT=4]="UNIVER_PROJECT",i[i.UNRECOGNIZED=-1]="UNRECOGNIZED",i))(pe||{}),Oe=Object.getOwnPropertyDescriptor,Ve=(i,t,e,n)=>{for(var r=n>1?void 0:n?Oe(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},ce=(i,t)=>(e,n)=>t(e,n,i);let J=class extends o.Disposable{constructor(i,t){super(),this._resourceManagerService=i,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const i=e=>{const n=this._hyperLinkModel.getUnit(e),r={};return n?(n.forEach(s=>{r[s.subUnitId]=s.links.map(({display:a,...d})=>d)}),JSON.stringify(r)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:ue,businesses:[pe.UNIVER_SHEET],toJson:e=>i(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(r=>{n[r].forEach(a=>{this._hyperLinkModel.addHyperLink(e,r,a)})})}}))}};J=Ve([ce(0,o.IResourceManagerService),ce(1,o.Inject(exports.HyperLinkModel))],J);const ge={type:o.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(i,t){if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=i.get(h.SheetInterceptorService),d=h.getSheetCommandTarget(r,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:u,worksheet:p}=d,{link:m}=t,{payload:f,display:g,row:y,column:_,id:S}=m,M=p.getCell(y,_),v=p.getBlankCellDocumentModel(M),I=v.documentModel.getSnapshot(),R=o.Tools.deepClone(I.body);if(!R)return!1;let w;if(g?w=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:R.dataStream.length-2,collapsed:R.dataStream.length-2===0},body:{dataStream:`${g}`,customRanges:[{startIndex:0,endIndex:g.length-1,rangeType:o.CustomRangeType.HYPERLINK,rangeId:S,properties:{url:f}}]},doc:v.documentModel}):w=o.BuildTextUtils.customRange.add({body:R,ranges:[{startOffset:0,endOffset:R.dataStream.length-2,collapsed:!1}],rangeId:S,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:f,refId:S}}),!w)return!1;const O=o.TextX.apply(R,w.serialize()),b={p:{...I,body:O},t:o.CellValueType.STRING},N=a.onWriteCell(u,p,y,_,b),D={unitId:c,subUnitId:l,cellValue:{[m.row]:{[m.column]:N}}},Q={id:h.SetRangeValuesMutation.id,params:D},$=h.SetRangeValuesUndoMutationFactory(i,D),ee={id:h.SetRangeValuesMutation.id,params:$},V=[Q],T=[ee],H=s.getHyperLinkByLocation(c,l,y,_);return H&&(V.push({id:E.id,params:{unitId:c,subUnitId:l,id:H.id}}),T.push({id:L.id,params:{unitId:c,subUnitId:l,link:H}})),await o.sequenceExecute(V,e)?await a.onValidateCell(u,p,y,_)===!1?(o.sequenceExecute(T,e),!1):(n.pushUndoRedo({redoMutations:V,undoMutations:T,unitID:c}),!0):!1}},he={id:"sheets.command.add-rich-hyper-link",type:o.CommandType.COMMAND,handler:async(i,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,r=i.get(o.ICommandService),s=o.generateRandomId(),{payload:a}=n,d=Z.addCustomRangeBySelectionFactory(i,{unitId:e,rangeId:s,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:a,refId:s}});return d?r.syncExecuteCommand(d.id,d.params):!1}},me={type:o.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(i,t){var b,N;if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=h.getSheetCommandTarget(r,t);if(!a)return!1;const{row:d,column:c,id:l}=t,{unitId:u,subUnitId:p,worksheet:m}=a,f=m.getCell(d,c);if(!f)return!1;const g=m.getCellDocumentModelWithFormula(f);if(!(g!=null&&g.documentModel))return!1;const y=o.Tools.deepClone(g.documentModel.getSnapshot()),_=(N=(b=y.body)==null?void 0:b.customRanges)==null?void 0:N.find(D=>`${D.rangeId}`===l);if(!_)return!1;const S=o.BuildTextUtils.customRange.delete({documentDataModel:g.documentModel,rangeId:_.rangeId});if(!S)return!1;const M=o.TextX.apply(y.body,S.serialize()),v=[],I=[],R={unitId:u,subUnitId:p,cellValue:{[d]:{[c]:{p:{...y,body:M},t:o.CellValueType.STRING}}}};v.push({id:h.SetRangeValuesMutation.id,params:R});const w=h.SetRangeValuesUndoMutationFactory(i,R);I.push({id:h.SetRangeValuesMutation.id,params:w});const O=s.getHyperLinkByLocation(u,p,d,c);return O&&(v.push({id:E.id,params:{unitId:u,subUnitId:p,id:l}}),I.push({id:L.id,params:{unitId:u,subUnitId:p,link:{...O}}})),o.sequenceExecute(v,e).result?(n.pushUndoRedo({redoMutations:v,undoMutations:I,unitID:u}),!0):!1}},fe={type:o.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(i,t){var u,p;if(!t)return!1;const{id:e,documentId:n}=t,r=i.get(o.ICommandService),a=i.get(o.IUniverInstanceService).getUnit(n,o.UniverInstanceType.UNIVER_DOC),d=(p=(u=a==null?void 0:a.getBody())==null?void 0:u.customRanges)==null?void 0:p.find(m=>m.rangeId===e);let c=null;d&&d.endIndex===a.getBody().dataStream.length-3&&(c={dataStream:" "});const l=Z.deleteCustomRangeFactory(i,{unitId:n,rangeId:e,insert:c});return l?r.syncExecuteCommand(l.id,l.params):!1}},ye={type:o.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(i,t){var ie,se,ae;if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=i.get(h.SheetInterceptorService),d=h.getSheetCommandTarget(r,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:u,id:p}=t,{workbook:m,worksheet:f,unitId:g,subUnitId:y}=d,{payload:_,display:S=""}=c,M=f.getCell(l,u);if(!M)return!1;const v=f.getCellDocumentModelWithFormula(M);if(!(v!=null&&v.documentModel))return!1;const I=v.documentModel.getSnapshot(),R=(se=(ie=I.body)==null?void 0:ie.customRanges)==null?void 0:se.find(oe=>`${oe.rangeId}`===p);if(!R)return!1;const w=o.generateRandomId(),P=(ae=o.getBodySlice(v.documentModel.getBody(),R.startIndex,R.endIndex+1).textRuns)==null?void 0:ae[0];P&&(P.ed=S.length+1);const b=Z.replaceSelectionFactory(i,{unitId:g,body:{dataStream:`${S}`,customRanges:[{rangeId:w,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:S.length-1,properties:{url:_}}],textRuns:P?[P]:void 0},selection:{startOffset:R.startIndex,endOffset:R.endIndex+1,collapsed:!1},doc:v.documentModel});if(!b)return!1;const N=o.TextX.apply(o.Tools.deepClone(I.body),b.textX.serialize()),D={p:{...I,body:N},t:o.CellValueType.STRING},Q=a.onWriteCell(m,f,l,u,D),$={id:h.SetRangeValuesMutation.id,params:{unitId:g,subUnitId:y,cellValue:{[l]:{[u]:Q}}}},ee=h.SetRangeValuesUndoMutationFactory(i,$.params),V={id:h.SetRangeValuesMutation.id,params:ee},T=[$],H=[V],A=s.getHyperLinkByLocation(g,y,l,u);return A&&(T.push({id:E.id,params:{unitId:g,subUnitId:y,id:A.id}}),H.push({id:L.id,params:{unitId:g,subUnitId:y,link:A}})),o.sequenceExecute(T,e)?await a.onValidateCell(m,f,l,u)===!1?(o.sequenceExecute(H,e),!1):(n.pushUndoRedo({redoMutations:T,undoMutations:H,unitID:g}),!0):!1}},_e={type:o.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(i,t)=>{var g,y,_,S;if(!t)return!1;const{documentId:e,payload:n,id:r}=t,s=i.get(o.IUniverInstanceService),a=i.get(o.ICommandService),d=s.getUnit(e,o.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(y=(g=d.getBody())==null?void 0:g.customRanges)==null?void 0:y.find(M=>M.rangeId===r);if(!c)return!1;const l=(_=t.payload.display)!=null?_:"",u=o.generateRandomId(),m=(S=o.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:S[0];m&&(m.ed=l.length+1);const f=Z.replaceSelectionFactory(i,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:u,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:m?[m]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return f?a.syncExecuteCommand(f.id,f.params):!1}};var xe=Object.getOwnPropertyDescriptor,$e=(i,t,e,n)=>{for(var r=n>1?void 0:n?xe(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},Ae=(i,t)=>(e,n)=>t(e,n,i);let X=class extends o.Disposable{constructor(i){super(),this._commandService=i,this._registerCommands()}_registerCommands(){[ge,ye,me,_e,fe,he,L,F,E,K,B].forEach(i=>{this._commandService.registerCommand(i)})}};X=$e([Ae(0,o.ICommandService)],X);var je=Object.getOwnPropertyDescriptor,We=(i,t,e,n)=>{for(var r=n>1?void 0:n?je(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},re=(i,t)=>(e,n)=>t(e,n,i);exports.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${U.SHEET}=${e}${n?`&${typeof n=="string"?U.DEFINE_NAME:U.RANGE}=${typeof n=="string"?n:k.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,r,s;if(t.startsWith("#")){const a=new URLSearchParams(t.slice(1)),d={gid:(e=a.get("gid"))!=null?e:"",range:(n=a.get("range"))!=null?n:"",rangeid:(r=a.get("rangeid"))!=null?r:"",unitid:(s=a.get("unitid"))!=null?s:""},c=this._getURLName(d);return{type:c.type,name:c.name,url:t,searchObj:d}}else return{type:U.URL,name:t,url:t,searchObj:null}}_getURLName(t){var u;const{gid:e,range:n,rangeid:r,unitid:s}=t,a=s?this._univerInstanceService.getUnit(s,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),d={type:U.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!a)return d;const c=e?a.getSheetBySheetId(e):a.getActiveSheet(),l=(u=c==null?void 0:c.getName())!=null?u:"";if(n){if(!c)return d;const p=k.deserializeRangeWithSheet(n).range;return o.isValidRange(p,c)&&n!==x?{type:U.RANGE,name:k.serializeRangeWithSheet(l,p)}:d}if(r){const p=this._definedNamesService.getValueById(a.getUnitId(),r);return p?{type:U.DEFINE_NAME,name:p.formulaOrRefString}:d}if(e){const p=a.getSheetBySheetId(e);return p?{type:U.SHEET,name:p.getName()}:d}return d}};exports.SheetsHyperLinkParserService=We([re(0,o.IUniverInstanceService),re(1,o.Inject(o.LocaleService)),re(2,k.IDefinedNamesService)],exports.SheetsHyperLinkParserService);var Be=Object.defineProperty,Fe=Object.getOwnPropertyDescriptor,Ke=(i,t,e)=>t in i?Be(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,ze=(i,t,e,n)=>{for(var r=n>1?void 0:n?Fe(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=a(r)||r);return r},le=(i,t)=>(e,n)=>t(e,n,i),Se=(i,t,e)=>Ke(i,typeof t!="symbol"?t+"":t,e);exports.UniverSheetsHyperLinkPlugin=class extends o.Plugin{constructor(t=de,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...r}=o.merge({},de,this._config);this._configService.setConfig(Le,r)}onStarting(){o.registerDependencies(this._injector,[[exports.HyperLinkModel],[exports.SheetsHyperLinkParserService],[J],[X],[z],[q],[G],[Y]]),o.touchDependencies(this._injector,[[z],[J],[X],[q],[G],[Y]])}};Se(exports.UniverSheetsHyperLinkPlugin,"pluginName",ue);Se(exports.UniverSheetsHyperLinkPlugin,"type",o.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsHyperLinkPlugin=ze([o.DependentOn(h.UniverSheetsPlugin),le(1,o.Inject(o.Injector)),le(2,o.IConfigService)],exports.UniverSheetsHyperLinkPlugin);exports.AddHyperLinkCommand=ge;exports.AddHyperLinkMutation=L;exports.AddRichHyperLinkCommand=he;exports.CancelHyperLinkCommand=me;exports.CancelRichHyperLinkCommand=fe;exports.ERROR_RANGE=x;exports.RemoveHyperLinkMutation=E;exports.SheetHyperLinkType=U;exports.UpdateHyperLinkCommand=ye;exports.UpdateHyperLinkMutation=F;exports.UpdateHyperLinkRefMutation=K;exports.UpdateRichHyperLinkCommand=_e;
|
package/lib/es/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var Ae = Object.defineProperty;
|
|
2
2
|
var We = (r, e, t) => e in r ? Ae(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
-
var
|
|
4
|
-
import { Disposable as T, ObjectMatrix as Z, UniverInstanceType as I, IUniverInstanceService as
|
|
3
|
+
var w = (r, e, t) => We(r, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { Disposable as T, ObjectMatrix as Z, UniverInstanceType as I, IUniverInstanceService as k, CommandType as E, CustomRangeType as U, Inject as M, ICommandService as b, sequenceExecuteAsync as Be, isValidRange as Se, toDisposable as je, DisposableCollection as Fe, Rectangle as Ke, Range as Ye, Tools as de, BuildTextUtils as Q, generateRandomId as ce, TextX as le, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as Ge, IResourceManagerService as ze, IUndoRedoService as ve, CellValueType as Ie, sequenceExecute as Y, getBodySlice as Pe, LocaleService as Je, DependentOn as Xe, Injector as qe, IConfigService as Ze, Plugin as Qe, merge as et, registerDependencies as tt, touchDependencies as nt } from "@univerjs/core";
|
|
5
5
|
import { Subject as rt } from "rxjs";
|
|
6
6
|
import { getSheetCommandTarget as j, RefRangeService as Oe, SheetsSelectionsService as De, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as st, handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests as it, SheetInterceptorService as ue, RemoveSheetCommand as at, handleDefaultRangeChangeWithEffectRefCommands as ot, SetRangeValuesMutation as x, SetRangeValuesCommand as dt, ClearSelectionContentCommand as ct, ClearSelectionAllCommand as lt, ClearSelectionFormatCommand as ut, AFTER_CELL_EDIT as pt, SetRangeValuesUndoMutationFactory as Me, UniverSheetsPlugin as ht } from "@univerjs/sheets";
|
|
7
7
|
import { deserializeRangeWithSheet as Ce, serializeRange as B, IDefinedNamesService as gt, serializeRangeWithSheet as ft } from "@univerjs/engine-formula";
|
|
@@ -14,10 +14,10 @@ var yt = Object.getOwnPropertyDescriptor, Rt = (r, e, t, n) => {
|
|
|
14
14
|
let v = class extends T {
|
|
15
15
|
constructor(e) {
|
|
16
16
|
super();
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
w(this, "_linkUpdate$", new rt());
|
|
18
|
+
w(this, "linkUpdate$", this._linkUpdate$.asObservable());
|
|
19
|
+
w(this, "_linkMap", /* @__PURE__ */ new Map());
|
|
20
|
+
w(this, "_linkPositionMap", /* @__PURE__ */ new Map());
|
|
21
21
|
this._univerInstanceService = e, this.disposeWithMe({
|
|
22
22
|
dispose: () => {
|
|
23
23
|
this._linkUpdate$.complete();
|
|
@@ -138,11 +138,11 @@ let v = class extends T {
|
|
|
138
138
|
}
|
|
139
139
|
};
|
|
140
140
|
v = Rt([
|
|
141
|
-
St(0,
|
|
141
|
+
St(0, k)
|
|
142
142
|
], v);
|
|
143
143
|
var L = /* @__PURE__ */ ((r) => (r.SHEET = "gid", r.RANGE = "range", r.DEFINE_NAME = "rangeid", r.INVALID = "invalid", r.URL = "url", r))(L || {});
|
|
144
|
-
const vt = "sheets-hyper-link.config", Ue = {},
|
|
145
|
-
type:
|
|
144
|
+
const vt = "sheets-hyper-link.config", Ue = {}, P = {
|
|
145
|
+
type: E.MUTATION,
|
|
146
146
|
id: "sheets.mutation.add-hyper-link",
|
|
147
147
|
handler(r, e) {
|
|
148
148
|
if (!e)
|
|
@@ -151,7 +151,7 @@ const vt = "sheets-hyper-link.config", Ue = {}, N = {
|
|
|
151
151
|
return t.addHyperLink(n, s, i);
|
|
152
152
|
}
|
|
153
153
|
}, O = {
|
|
154
|
-
type:
|
|
154
|
+
type: E.MUTATION,
|
|
155
155
|
id: "sheets.mutation.remove-hyper-link",
|
|
156
156
|
handler(r, e) {
|
|
157
157
|
if (!e)
|
|
@@ -160,7 +160,7 @@ const vt = "sheets-hyper-link.config", Ue = {}, N = {
|
|
|
160
160
|
return t.removeHyperLink(n, s, i);
|
|
161
161
|
}
|
|
162
162
|
}, me = {
|
|
163
|
-
type:
|
|
163
|
+
type: E.MUTATION,
|
|
164
164
|
id: "sheets.mutation.update-hyper-link",
|
|
165
165
|
handler(r, e) {
|
|
166
166
|
if (!e)
|
|
@@ -169,7 +169,7 @@ const vt = "sheets-hyper-link.config", Ue = {}, N = {
|
|
|
169
169
|
return t.updateHyperLink(n, s, a, i, !1);
|
|
170
170
|
}
|
|
171
171
|
}, ye = {
|
|
172
|
-
type:
|
|
172
|
+
type: E.MUTATION,
|
|
173
173
|
id: "sheets.mutation.update-hyper-link-ref",
|
|
174
174
|
handler(r, e) {
|
|
175
175
|
if (!e)
|
|
@@ -178,13 +178,13 @@ const vt = "sheets-hyper-link.config", Ue = {}, N = {
|
|
|
178
178
|
return t.updateHyperLinkRef(n, s, i, { row: a, column: o }, c);
|
|
179
179
|
}
|
|
180
180
|
}, q = {
|
|
181
|
-
type:
|
|
181
|
+
type: E.MUTATION,
|
|
182
182
|
id: "sheets.mutation.update-rich-hyper-link",
|
|
183
183
|
handler(r, e) {
|
|
184
184
|
var g, p, f;
|
|
185
185
|
if (!e)
|
|
186
186
|
return !1;
|
|
187
|
-
const { unitId: t, subUnitId: n, row: s, col: i, id: a, url: o } = e, c = r.get(
|
|
187
|
+
const { unitId: t, subUnitId: n, row: s, col: i, id: a, url: o } = e, c = r.get(k), d = j(c, { unitId: t, subUnitId: n });
|
|
188
188
|
if (!d)
|
|
189
189
|
return !1;
|
|
190
190
|
const { worksheet: l } = d, u = l.getCellRaw(s, i), h = (f = (p = (g = u == null ? void 0 : u.p) == null ? void 0 : g.body) == null ? void 0 : p.customRanges) == null ? void 0 : f.find((_) => _.rangeType === U.HYPERLINK && _.rangeId === a);
|
|
@@ -199,11 +199,11 @@ var It = Object.getOwnPropertyDescriptor, Mt = (r, e, t, n) => {
|
|
|
199
199
|
let te = class extends T {
|
|
200
200
|
constructor(e, t, n, s) {
|
|
201
201
|
super();
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
202
|
+
w(this, "_disposableMap", /* @__PURE__ */ new Map());
|
|
203
|
+
w(this, "_watchDisposableMap", /* @__PURE__ */ new Map());
|
|
204
|
+
w(this, "_rangeDisableMap", /* @__PURE__ */ new Map());
|
|
205
|
+
w(this, "_rangeWatcherMap", /* @__PURE__ */ new Map());
|
|
206
|
+
w(this, "_handlePositionChange", (e, t, n, s, i) => {
|
|
207
207
|
const a = {
|
|
208
208
|
startColumn: n.column,
|
|
209
209
|
endColumn: n.column,
|
|
@@ -243,7 +243,7 @@ let te = class extends T {
|
|
|
243
243
|
}
|
|
244
244
|
}],
|
|
245
245
|
undos: [{
|
|
246
|
-
id:
|
|
246
|
+
id: P.id,
|
|
247
247
|
params: {
|
|
248
248
|
unitId: e,
|
|
249
249
|
subUnitId: t,
|
|
@@ -405,7 +405,7 @@ te = Mt([
|
|
|
405
405
|
J(2, M(De)),
|
|
406
406
|
J(3, b)
|
|
407
407
|
], te);
|
|
408
|
-
var Ct = Object.getOwnPropertyDescriptor,
|
|
408
|
+
var Ct = Object.getOwnPropertyDescriptor, wt = (r, e, t, n) => {
|
|
409
409
|
for (var s = n > 1 ? void 0 : n ? Ct(e, t) : e, i = r.length - 1, a; i >= 0; i--)
|
|
410
410
|
(a = r[i]) && (s = a(s) || s);
|
|
411
411
|
return s;
|
|
@@ -434,7 +434,7 @@ let ne = class extends T {
|
|
|
434
434
|
id: d.id
|
|
435
435
|
}
|
|
436
436
|
})), c = a.map((d) => ({
|
|
437
|
-
id:
|
|
437
|
+
id: P.id,
|
|
438
438
|
params: {
|
|
439
439
|
unitId: s,
|
|
440
440
|
subUnitId: i,
|
|
@@ -449,20 +449,20 @@ let ne = class extends T {
|
|
|
449
449
|
);
|
|
450
450
|
}
|
|
451
451
|
};
|
|
452
|
-
ne =
|
|
452
|
+
ne = wt([
|
|
453
453
|
ge(0, M(ue)),
|
|
454
|
-
ge(1,
|
|
454
|
+
ge(1, k),
|
|
455
455
|
ge(2, M(v))
|
|
456
456
|
], ne);
|
|
457
|
-
var
|
|
458
|
-
for (var s = n > 1 ? void 0 : n ?
|
|
457
|
+
var kt = Object.getOwnPropertyDescriptor, Et = (r, e, t, n) => {
|
|
458
|
+
for (var s = n > 1 ? void 0 : n ? kt(e, t) : e, i = r.length - 1, a; i >= 0; i--)
|
|
459
459
|
(a = r[i]) && (s = a(s) || s);
|
|
460
460
|
return s;
|
|
461
461
|
}, fe = (r, e) => (t, n) => e(t, n, r);
|
|
462
462
|
let re = class extends T {
|
|
463
463
|
constructor(e, t, n) {
|
|
464
464
|
super();
|
|
465
|
-
|
|
465
|
+
w(this, "_refRangeMap", /* @__PURE__ */ new Map());
|
|
466
466
|
this._commandService = e, this._univerInstanceService = t, this._refRangeService = n, this._initWorkbookLoad(), this._initWorkbookUnload(), this._initSetRangesListener();
|
|
467
467
|
}
|
|
468
468
|
_enusreMap(e, t) {
|
|
@@ -612,9 +612,9 @@ let re = class extends T {
|
|
|
612
612
|
);
|
|
613
613
|
}
|
|
614
614
|
};
|
|
615
|
-
re =
|
|
615
|
+
re = Et([
|
|
616
616
|
fe(0, b),
|
|
617
|
-
fe(1,
|
|
617
|
+
fe(1, k),
|
|
618
618
|
fe(2, M(Oe))
|
|
619
619
|
], re);
|
|
620
620
|
var Lt = Object.getOwnPropertyDescriptor, Ut = (r, e, t, n) => {
|
|
@@ -644,7 +644,7 @@ let se = class extends T {
|
|
|
644
644
|
id: c.id
|
|
645
645
|
}
|
|
646
646
|
}), i.push({
|
|
647
|
-
id:
|
|
647
|
+
id: P.id,
|
|
648
648
|
params: {
|
|
649
649
|
unitId: t,
|
|
650
650
|
subUnitId: n,
|
|
@@ -680,7 +680,7 @@ let se = class extends T {
|
|
|
680
680
|
id: d.id
|
|
681
681
|
}
|
|
682
682
|
}), t.push({
|
|
683
|
-
id:
|
|
683
|
+
id: P.id,
|
|
684
684
|
params: {
|
|
685
685
|
unitId: i,
|
|
686
686
|
subUnitId: a,
|
|
@@ -759,9 +759,9 @@ se = Ut([
|
|
|
759
759
|
X(0, M(ue)),
|
|
760
760
|
X(1, M(v)),
|
|
761
761
|
X(2, M(De)),
|
|
762
|
-
X(3,
|
|
762
|
+
X(3, k)
|
|
763
763
|
], se);
|
|
764
|
-
var xe = /* @__PURE__ */ ((r) => (r[r.UNIVER_UNKNOWN = 0] = "UNIVER_UNKNOWN", r[r.UNIVER_DOC = 1] = "UNIVER_DOC", r[r.UNIVER_SHEET = 2] = "UNIVER_SHEET", r[r.UNIVER_SLIDE = 3] = "UNIVER_SLIDE", r[r.UNIVER_PROJECT = 4] = "UNIVER_PROJECT", r[r.UNRECOGNIZED = -1] = "UNRECOGNIZED", r))(xe || {}), bt = Object.getOwnPropertyDescriptor,
|
|
764
|
+
var xe = /* @__PURE__ */ ((r) => (r[r.UNIVER_UNKNOWN = 0] = "UNIVER_UNKNOWN", r[r.UNIVER_DOC = 1] = "UNIVER_DOC", r[r.UNIVER_SHEET = 2] = "UNIVER_SHEET", r[r.UNIVER_SLIDE = 3] = "UNIVER_SLIDE", r[r.UNIVER_PROJECT = 4] = "UNIVER_PROJECT", r[r.UNRECOGNIZED = -1] = "UNRECOGNIZED", r))(xe || {}), bt = Object.getOwnPropertyDescriptor, Nt = (r, e, t, n) => {
|
|
765
765
|
for (var s = n > 1 ? void 0 : n ? bt(e, t) : e, i = r.length - 1, a; i >= 0; i--)
|
|
766
766
|
(a = r[i]) && (s = a(s) || s);
|
|
767
767
|
return s;
|
|
@@ -805,22 +805,22 @@ let ie = class extends T {
|
|
|
805
805
|
);
|
|
806
806
|
}
|
|
807
807
|
};
|
|
808
|
-
ie =
|
|
808
|
+
ie = Nt([
|
|
809
809
|
be(0, ze),
|
|
810
810
|
be(1, M(v))
|
|
811
811
|
], ie);
|
|
812
|
-
const
|
|
813
|
-
type:
|
|
812
|
+
const Pt = {
|
|
813
|
+
type: E.COMMAND,
|
|
814
814
|
id: "sheets.command.add-hyper-link",
|
|
815
815
|
// eslint-disable-next-line max-lines-per-function
|
|
816
816
|
async handler(r, e) {
|
|
817
817
|
if (!e) return !1;
|
|
818
|
-
const t = r.get(b), n = r.get(ve), s = r.get(
|
|
818
|
+
const t = r.get(b), n = r.get(ve), s = r.get(k), i = r.get(v), a = r.get(ue), o = j(s, e);
|
|
819
819
|
if (!o) return !1;
|
|
820
820
|
const { unitId: c, subUnitId: d, workbook: l, worksheet: u } = o, { link: h } = e, { payload: g, display: p, row: f, column: _, id: m } = h, C = u.getCell(f, _), y = u.getBlankCellDocumentModel(C), R = y.documentModel.getSnapshot(), S = de.deepClone(R.body);
|
|
821
821
|
if (!S) return !1;
|
|
822
|
-
let
|
|
823
|
-
if (p ?
|
|
822
|
+
let N;
|
|
823
|
+
if (p ? N = Q.selection.replace({
|
|
824
824
|
selection: {
|
|
825
825
|
startOffset: 0,
|
|
826
826
|
endOffset: S.dataStream.length - 2,
|
|
@@ -840,7 +840,7 @@ const Nt = {
|
|
|
840
840
|
}]
|
|
841
841
|
},
|
|
842
842
|
doc: y.documentModel
|
|
843
|
-
}) :
|
|
843
|
+
}) : N = Q.customRange.add({
|
|
844
844
|
body: S,
|
|
845
845
|
ranges: [{ startOffset: 0, endOffset: S.dataStream.length - 2, collapsed: !1 }],
|
|
846
846
|
rangeId: m,
|
|
@@ -849,8 +849,8 @@ const Nt = {
|
|
|
849
849
|
url: g,
|
|
850
850
|
refId: m
|
|
851
851
|
}
|
|
852
|
-
}), !
|
|
853
|
-
const F = le.apply(S,
|
|
852
|
+
}), !N) return !1;
|
|
853
|
+
const F = le.apply(S, N.serialize()), D = {
|
|
854
854
|
p: {
|
|
855
855
|
...R,
|
|
856
856
|
body: F
|
|
@@ -879,7 +879,7 @@ const Nt = {
|
|
|
879
879
|
id: V.id
|
|
880
880
|
}
|
|
881
881
|
}), H.push({
|
|
882
|
-
id:
|
|
882
|
+
id: P.id,
|
|
883
883
|
params: {
|
|
884
884
|
unitId: c,
|
|
885
885
|
subUnitId: d,
|
|
@@ -893,7 +893,7 @@ const Nt = {
|
|
|
893
893
|
}
|
|
894
894
|
}, Ot = {
|
|
895
895
|
id: "sheets.command.add-rich-hyper-link",
|
|
896
|
-
type:
|
|
896
|
+
type: E.COMMAND,
|
|
897
897
|
handler: async (r, e) => {
|
|
898
898
|
if (!e)
|
|
899
899
|
return !1;
|
|
@@ -909,13 +909,13 @@ const Nt = {
|
|
|
909
909
|
return o ? s.syncExecuteCommand(o.id, o.params) : !1;
|
|
910
910
|
}
|
|
911
911
|
}, Dt = {
|
|
912
|
-
type:
|
|
912
|
+
type: E.COMMAND,
|
|
913
913
|
id: "sheets.command.cancel-hyper-link",
|
|
914
914
|
// eslint-disable-next-line max-lines-per-function
|
|
915
915
|
handler(r, e) {
|
|
916
916
|
var D, A;
|
|
917
917
|
if (!e) return !1;
|
|
918
|
-
const t = r.get(b), n = r.get(ve), s = r.get(
|
|
918
|
+
const t = r.get(b), n = r.get(ve), s = r.get(k), i = r.get(v), a = j(s, e);
|
|
919
919
|
if (!a) return !1;
|
|
920
920
|
const { row: o, column: c, id: d } = e, { unitId: l, subUnitId: u, worksheet: h } = a, g = h.getCell(o, c);
|
|
921
921
|
if (!g) return !1;
|
|
@@ -944,10 +944,10 @@ const Nt = {
|
|
|
944
944
|
id: x.id,
|
|
945
945
|
params: S
|
|
946
946
|
});
|
|
947
|
-
const
|
|
947
|
+
const N = Me(r, S);
|
|
948
948
|
R.push({
|
|
949
949
|
id: x.id,
|
|
950
|
-
params:
|
|
950
|
+
params: N
|
|
951
951
|
});
|
|
952
952
|
const F = i.getHyperLinkByLocation(l, u, o, c);
|
|
953
953
|
return F && (y.push({
|
|
@@ -958,7 +958,7 @@ const Nt = {
|
|
|
958
958
|
id: d
|
|
959
959
|
}
|
|
960
960
|
}), R.push({
|
|
961
|
-
id:
|
|
961
|
+
id: P.id,
|
|
962
962
|
params: {
|
|
963
963
|
unitId: l,
|
|
964
964
|
subUnitId: u,
|
|
@@ -973,13 +973,13 @@ const Nt = {
|
|
|
973
973
|
}), !0) : !1;
|
|
974
974
|
}
|
|
975
975
|
}, Ht = {
|
|
976
|
-
type:
|
|
976
|
+
type: E.COMMAND,
|
|
977
977
|
id: "sheets.command.cancel-rich-hyper-link",
|
|
978
978
|
handler(r, e) {
|
|
979
979
|
var l, u;
|
|
980
980
|
if (!e)
|
|
981
981
|
return !1;
|
|
982
|
-
const { id: t, documentId: n } = e, s = r.get(b), a = r.get(
|
|
982
|
+
const { id: t, documentId: n } = e, s = r.get(b), a = r.get(k).getUnit(n, I.UNIVER_DOC), o = (u = (l = a == null ? void 0 : a.getBody()) == null ? void 0 : l.customRanges) == null ? void 0 : u.find((h) => h.rangeId === t);
|
|
983
983
|
let c = null;
|
|
984
984
|
o && o.endIndex === a.getBody().dataStream.length - 3 && (c = {
|
|
985
985
|
dataStream: " "
|
|
@@ -988,13 +988,13 @@ const Nt = {
|
|
|
988
988
|
return d ? s.syncExecuteCommand(d.id, d.params) : !1;
|
|
989
989
|
}
|
|
990
990
|
}, Vt = {
|
|
991
|
-
type:
|
|
991
|
+
type: E.COMMAND,
|
|
992
992
|
id: "sheets.command.update-hyper-link",
|
|
993
993
|
// eslint-disable-next-line max-lines-per-function
|
|
994
994
|
async handler(r, e) {
|
|
995
|
-
var
|
|
995
|
+
var we, ke, Ee;
|
|
996
996
|
if (!e) return !1;
|
|
997
|
-
const t = r.get(b), n = r.get(ve), s = r.get(
|
|
997
|
+
const t = r.get(b), n = r.get(ve), s = r.get(k), i = r.get(v), a = r.get(ue), o = j(s, {
|
|
998
998
|
unitId: e.unitId,
|
|
999
999
|
subUnitId: e.subUnitId
|
|
1000
1000
|
});
|
|
@@ -1003,16 +1003,16 @@ const Nt = {
|
|
|
1003
1003
|
if (!C) return !1;
|
|
1004
1004
|
const y = g.getCellDocumentModelWithFormula(C);
|
|
1005
1005
|
if (!(y != null && y.documentModel)) return !1;
|
|
1006
|
-
const R = y.documentModel.getSnapshot(), S = (
|
|
1006
|
+
const R = y.documentModel.getSnapshot(), S = (ke = (we = R.body) == null ? void 0 : we.customRanges) == null ? void 0 : ke.find((Le) => `${Le.rangeId}` === u);
|
|
1007
1007
|
if (!S) return !1;
|
|
1008
|
-
const
|
|
1008
|
+
const N = ce(), $ = (Ee = Pe(y.documentModel.getBody(), S.startIndex, S.endIndex + 1).textRuns) == null ? void 0 : Ee[0];
|
|
1009
1009
|
$ && ($.ed = m.length + 1);
|
|
1010
1010
|
const D = He(r, {
|
|
1011
1011
|
unitId: p,
|
|
1012
1012
|
body: {
|
|
1013
1013
|
dataStream: `${m}`,
|
|
1014
1014
|
customRanges: [{
|
|
1015
|
-
rangeId:
|
|
1015
|
+
rangeId: N,
|
|
1016
1016
|
rangeType: U.HYPERLINK,
|
|
1017
1017
|
startIndex: 0,
|
|
1018
1018
|
endIndex: m.length - 1,
|
|
@@ -1060,7 +1060,7 @@ const Nt = {
|
|
|
1060
1060
|
id: z.id
|
|
1061
1061
|
}
|
|
1062
1062
|
}), V.push({
|
|
1063
|
-
id:
|
|
1063
|
+
id: P.id,
|
|
1064
1064
|
params: {
|
|
1065
1065
|
unitId: p,
|
|
1066
1066
|
subUnitId: f,
|
|
@@ -1073,19 +1073,19 @@ const Nt = {
|
|
|
1073
1073
|
}), !0) : !1;
|
|
1074
1074
|
}
|
|
1075
1075
|
}, xt = {
|
|
1076
|
-
type:
|
|
1076
|
+
type: E.COMMAND,
|
|
1077
1077
|
id: "sheets.command.update-rich-hyper-link",
|
|
1078
1078
|
handler: (r, e) => {
|
|
1079
1079
|
var p, f, _, m;
|
|
1080
1080
|
if (!e)
|
|
1081
1081
|
return !1;
|
|
1082
|
-
const { documentId: t, payload: n, id: s } = e, i = r.get(
|
|
1082
|
+
const { documentId: t, payload: n, id: s } = e, i = r.get(k), a = r.get(b), o = i.getUnit(t, I.UNIVER_DOC);
|
|
1083
1083
|
if (!o)
|
|
1084
1084
|
return !1;
|
|
1085
1085
|
const c = (f = (p = o.getBody()) == null ? void 0 : p.customRanges) == null ? void 0 : f.find((C) => C.rangeId === s);
|
|
1086
1086
|
if (!c)
|
|
1087
1087
|
return !1;
|
|
1088
|
-
const d = (_ = e.payload.display) != null ? _ : "", l = ce(), h = (m =
|
|
1088
|
+
const d = (_ = e.payload.display) != null ? _ : "", l = ce(), h = (m = Pe(o.getBody(), c.startIndex, c.endIndex + 1).textRuns) == null ? void 0 : m[0];
|
|
1089
1089
|
h && (h.ed = d.length + 1);
|
|
1090
1090
|
const g = He(r, {
|
|
1091
1091
|
unitId: t,
|
|
@@ -1123,13 +1123,13 @@ let ae = class extends T {
|
|
|
1123
1123
|
}
|
|
1124
1124
|
_registerCommands() {
|
|
1125
1125
|
[
|
|
1126
|
-
|
|
1126
|
+
Pt,
|
|
1127
1127
|
Vt,
|
|
1128
1128
|
Dt,
|
|
1129
1129
|
xt,
|
|
1130
1130
|
Ht,
|
|
1131
1131
|
Ot,
|
|
1132
|
-
|
|
1132
|
+
P,
|
|
1133
1133
|
me,
|
|
1134
1134
|
O,
|
|
1135
1135
|
ye,
|
|
@@ -1212,7 +1212,7 @@ let Re = class {
|
|
|
1212
1212
|
}
|
|
1213
1213
|
};
|
|
1214
1214
|
Re = Bt([
|
|
1215
|
-
_e(0,
|
|
1215
|
+
_e(0, k),
|
|
1216
1216
|
_e(1, M(Je)),
|
|
1217
1217
|
_e(2, gt)
|
|
1218
1218
|
], Re);
|
|
@@ -1220,7 +1220,7 @@ var jt = Object.defineProperty, Ft = Object.getOwnPropertyDescriptor, Kt = (r, e
|
|
|
1220
1220
|
for (var s = n > 1 ? void 0 : n ? Ft(e, t) : e, i = r.length - 1, a; i >= 0; i--)
|
|
1221
1221
|
(a = r[i]) && (s = a(s) || s);
|
|
1222
1222
|
return s;
|
|
1223
|
-
},
|
|
1223
|
+
}, Ne = (r, e) => (t, n) => e(t, n, r), Te = (r, e, t) => Kt(r, typeof e != "symbol" ? e + "" : e, t);
|
|
1224
1224
|
let oe = class extends Qe {
|
|
1225
1225
|
constructor(r = Ue, e, t) {
|
|
1226
1226
|
super(), this._config = r, this._injector = e, this._configService = t;
|
|
@@ -1255,12 +1255,12 @@ Te(oe, "pluginName", Ve);
|
|
|
1255
1255
|
Te(oe, "type", I.UNIVER_SHEET);
|
|
1256
1256
|
oe = Yt([
|
|
1257
1257
|
Xe(ht),
|
|
1258
|
-
|
|
1259
|
-
|
|
1258
|
+
Ne(1, M(qe)),
|
|
1259
|
+
Ne(2, Ze)
|
|
1260
1260
|
], oe);
|
|
1261
1261
|
export {
|
|
1262
|
-
|
|
1263
|
-
|
|
1262
|
+
Pt as AddHyperLinkCommand,
|
|
1263
|
+
P as AddHyperLinkMutation,
|
|
1264
1264
|
Ot as AddRichHyperLinkCommand,
|
|
1265
1265
|
Dt as CancelHyperLinkCommand,
|
|
1266
1266
|
Ht as CancelRichHyperLinkCommand,
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(p,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("rxjs"),require("@univerjs/sheets"),require("@univerjs/engine-formula"),require("@univerjs/docs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","@univerjs/sheets","@univerjs/engine-formula","@univerjs/docs"],a):(p=typeof globalThis<"u"?globalThis:p||self,a(p.UniverSheetsHyperLink={},p.UniverCore,p.rxjs,p.UniverSheets,p.UniverEngineFormula,p.UniverDocs))})(this,function(p,a,D,m,C,x){"use strict";var Ge=Object.defineProperty;var Ye=(p,a,D)=>a in p?Ge(p,a,{enumerable:!0,configurable:!0,writable:!0,value:D}):p[a]=D;var U=(p,a,D)=>Ye(p,typeof a!="symbol"?a+"":a,D);var Re=Object.getOwnPropertyDescriptor,Me=(s,t,e,n)=>{for(var i=n>1?void 0:n?Re(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},Ce=(s,t)=>(e,n)=>t(e,n,s);p.HyperLinkModel=class extends a.Disposable{constructor(e){super();U(this,"_linkUpdate$",new D.Subject);U(this,"linkUpdate$",this._linkUpdate$.asObservable());U(this,"_linkMap",new Map);U(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let i=this._linkMap.get(e);i||(i=new Map,this._linkMap.set(e,i));let r=i.get(n);r||(r=new a.ObjectMatrix,i.set(n,r));let o=this._linkPositionMap.get(e);o||(o=new Map,this._linkPositionMap.set(e,o));let d=o.get(n);return d||(d=new Map,o.set(n,d)),{matrix:r,positionMap:d}}addHyperLink(e,n,i){const{matrix:r,positionMap:o}=this._ensureMap(e,n);return r.setValue(i.row,i.column,i),o.set(i.id,{row:i.row,column:i.column,link:i}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:i,type:"add"}),!0}updateHyperLink(e,n,i,r,o=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;const u=d.getValue(l.row,l.column);return u&&(Object.assign(u,r),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:u.display,payload:u.payload},id:i,type:"update",silent:o})),!0}updateHyperLinkRef(e,n,i,r,o=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;let u=d.getValue(l.row,l.column);return!u||u.id!==i?u=l.link:d.realDeleteValue(l.row,l.column),Object.assign(u,r),c.set(i,{...r,link:u}),d.setValue(r.row,r.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:r,id:i,type:"updateRef",silent:o}),!0}removeHyperLink(e,n,i){const{matrix:r,positionMap:o}=this._ensureMap(e,n),d=o.get(i);if(!d)return!1;o.delete(i);const c=r.getValue(d.row,d.column);return c&&c.id===i&&r.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,i){const{matrix:r,positionMap:o}=this._ensureMap(e,n),d=o.get(i);if(d)return r.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,i,r){const{matrix:o}=this._ensureMap(e,n);return o.getValue(i,r)}getHyperLinkByLocationSync(e,n,i,r){var g,f,y,h,_;const{matrix:o}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,a.UniverInstanceType.UNIVER_SHEET),c=(g=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:g.getCellRaw(i,r),l=((_=(h=c==null?void 0:c.v)!=null?h:(y=(f=c==null?void 0:c.p)==null?void 0:f.body)==null?void 0:y.dataStream.slice(0,-2))!=null?_:"").toString(),u=o.getValue(i,r);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:i}=this._ensureMap(e,n),r=[];return i.forValue((o,d,c)=>{c&&r.push(c)}),r}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(i=>{const r=this.getSubUnit(e,i);return{unitId:e,subUnitId:i,links:r}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}},p.HyperLinkModel=Me([Ce(0,a.IUniverInstanceService)],p.HyperLinkModel);var L=(s=>(s.SHEET="gid",s.RANGE="range",s.DEFINE_NAME="rangeid",s.INVALID="invalid",s.URL="url",s))(L||{});const ke="sheets-hyper-link.config",ae={},E={type:a.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(s,t){if(!t)return!1;const e=s.get(p.HyperLinkModel),{unitId:n,subUnitId:i,link:r}=t;return e.addHyperLink(n,i,r)}},w={type:a.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(s,t){if(!t)return!1;const e=s.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:r}=t;return e.removeHyperLink(n,i,r)}},W={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(s,t){if(!t)return!1;const e=s.get(p.HyperLinkModel),{unitId:n,subUnitId:i,payload:r,id:o}=t;return e.updateHyperLink(n,i,o,r,!1)}},B={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(s,t){if(!t)return!1;const e=s.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:r,row:o,column:d,silent:c}=t;return e.updateHyperLinkRef(n,i,r,{row:o,column:d},c)}},K={type:a.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(s,t){var y,h,_;if(!t)return!1;const{unitId:e,subUnitId:n,row:i,col:r,id:o,url:d}=t,c=s.get(a.IUniverInstanceService),l=m.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:u}=l,g=u.getCellRaw(i,r),f=(_=(h=(y=g==null?void 0:g.p)==null?void 0:y.body)==null?void 0:h.customRanges)==null?void 0:_.find(v=>v.rangeType===a.CustomRangeType.HYPERLINK&&v.rangeId===o);return f&&(f.properties.url=d),!0}},oe="SHEET_HYPER_LINK_PLUGIN",$="err";var Ue=Object.getOwnPropertyDescriptor,Le=(s,t,e,n)=>{for(var i=n>1?void 0:n?Ue(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},z=(s,t)=>(e,n)=>t(e,n,s);let G=class extends a.Disposable{constructor(t,e,n,i){super();U(this,"_disposableMap",new Map);U(this,"_watchDisposableMap",new Map);U(this,"_rangeDisableMap",new Map);U(this,"_rangeWatcherMap",new Map);U(this,"_handlePositionChange",(t,e,n,i,r)=>{const o={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return i?{redos:[{id:B.id,params:{unitId:t,subUnitId:e,id:n.id,row:i.startRow,column:i.startColumn,silent:r}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,id:n.id,row:o.startRow,column:o.startColumn,silent:r}}]}:{redos:[{id:w.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:E.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=i,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const i=n.id,r={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},o=d=>{const c=m.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(r,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===r.startColumn&&l.startRow===r.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(i,this._refRangeService.registerRefRange(r,o,t,e))}_watchPosition(t,e,n){const i=n.id,r={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(t,e,r,(o,d)=>{const{redos:c}=this._handlePositionChange(t,e,n,d,!0);a.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(t){const e=this._disposableMap.get(t);e==null||e.dispose(),this._disposableMap.delete(t)}_unwatchPosition(t){const e=this._watchDisposableMap.get(t);e==null||e.dispose(),this._watchDisposableMap.delete(t)}_registerRange(t,e,n,i=!1){var r,o,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(r=c.get("gid"))!=null?r:"",range:(o=c.get("range"))!=null?o:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const u=l.gid,g=C.deserializeRangeWithSheet(l.range).range;if(a.isValidRange(g)&&l.range!==$){const f=y=>{const h=m.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(g,y,{selectionManagerService:this._selectionManagerService});return h&&C.serializeRange(h)===C.serializeRange(g)?{redos:[],undos:[]}:{redos:[{id:W.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`}}}],undos:[{id:W.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(g,f,t,u)),i||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,u,g,(y,h)=>{this._hyperLinkModel.updateHyperLink(t,u,e,{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`},!0)},!0))}}}}_unregisterRange(t){const e=this._rangeDisableMap.get(t);e==null||e.dispose(),this._rangeDisableMap.delete(t)}_unwatchRange(t){const e=this._rangeWatcherMap.get(t);e==null||e.dispose(),this._rangeWatcherMap.delete(t)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(n=>{const{unitId:i,subUnitId:r,links:o}=n;o.forEach(d=>{this._registerPosition(i,r,d),this._watchPosition(i,r,d),this._registerRange(i,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:i,silent:r}=t,o=this._hyperLinkModel.getHyperLink(e,n,i);if(!o)return;this._unregisterPosition(i),this._registerPosition(e,n,o),r||(this._unwatchPosition(i),this._watchPosition(e,n,o));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:i}=n;i.forEach(r=>{this._unregisterPosition(r.id),this._unwatchPosition(r.id),this._unregisterRange(r.id),this._unwatchRange(r.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(a.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};G=Le([z(0,a.Inject(m.RefRangeService)),z(1,a.Inject(p.HyperLinkModel)),z(2,a.Inject(m.SheetsSelectionsService)),z(3,a.ICommandService)],G);var Ee=Object.getOwnPropertyDescriptor,we=(s,t,e,n)=>{for(var i=n>1?void 0:n?Ee(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},te=(s,t)=>(e,n)=>t(e,n,s);let Y=class extends a.Disposable{constructor(s,t,e){super(),this._sheetInterceptorService=s,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:s=>{var t;if(s.id===m.RemoveSheetCommand.id){const e=s.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const i=n.getUnitId(),r=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!r)return{redos:[],undos:[]};const o=this._hyperLinkModel.getSubUnit(i,r),d=o.map(l=>({id:w.id,params:{unitId:i,subUnitId:r,id:l.id}})),c=o.map(l=>({id:E.id,params:{unitId:i,subUnitId:r,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};Y=we([te(0,a.Inject(m.SheetInterceptorService)),te(1,a.IUniverInstanceService),te(2,a.Inject(p.HyperLinkModel))],Y);var Te=Object.getOwnPropertyDescriptor,He=(s,t,e,n)=>{for(var i=n>1?void 0:n?Te(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},ne=(s,t)=>(e,n)=>t(e,n,s);let q=class extends a.Disposable{constructor(t,e,n){super();U(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let i=n.get(e);return i||(i=new a.ObjectMatrix,n.set(e,i)),i}_isLegalRangeUrl(t,e){var i,r,o;const n=this._univerInstanceService.getUnit(t,a.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(i=d.get("gid"))!=null?i:"",range:(r=d.get("range"))!=null?r:"",rangeid:(o=d.get("rangeid"))!=null?o:""};if(c.range&&c.gid){const l=c.gid,u=n.getSheetBySheetId(l);if(!u)return null;const g=C.deserializeRangeWithSheet(c.range).range;if(a.isValidRange(g,u)&&c.range!==$)return{range:g,worksheet:u}}}return null}_registerRange(t,e,n,i,r){var d,c,l,u;const o=this._enusreMap(t,e);if((c=(d=r.body)==null?void 0:d.customRanges)!=null&&c.some(g=>{var f;return g.rangeType===a.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(f=g.properties)==null?void 0:f.url)})){const g=new a.DisposableCollection;let f=!1;(u=(l=r.body)==null?void 0:l.customRanges)==null||u.forEach(y=>{var h;if(y.rangeType===a.CustomRangeType.HYPERLINK){const _=(h=y.properties)==null?void 0:h.url,v=this._isLegalRangeUrl(t,_);if(v){const{range:S,worksheet:k}=v;f=!0,g.add(this._refRangeService.registerRefRange(S,I=>{const R=m.handleDefaultRangeChangeWithEffectRefCommands(S,I);return R&&a.Rectangle.equals(R,S)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:K.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:y.rangeId,url:`#gid=${e}&range=${R?C.serializeRange(R):$}`}}],undos:[{id:K.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:y.rangeId,url:_}}],redos:[]}},k.getUnitId(),k.getSheetId()))}}}),f&&o.setValue(n,i,g)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(i=>{const r=i.getSheetId(),o=this._enusreMap(n,r);i.getCellMatrix().forValue((d,c,l)=>{const u=o.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,r,d,c,l.p)})})};this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(e=>{e.type===a.UniverInstanceType.UNIVER_SHEET&&t(e)}))}_initWorkbookUnload(){this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===a.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(i=>{const r=i.getSheetId();this._enusreMap(n,r).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}})}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===m.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:i,cellValue:r}=e,o=this._enusreMap(n,i);r&&new a.ObjectMatrix(r).forValue((d,c,l)=>{const u=o.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,i,d,c,l.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===K.id){const e=t.params,{unitId:n,subUnitId:i,row:r,col:o}=e,d=m.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:i}),l=this._enusreMap(n,i).getValue(r,o);if(l&&l.dispose(),d){const{worksheet:u}=d,g=u.getCellRaw(r,o);g&&g.p&&this._registerRange(n,i,r,o,g.p)}}}))}};q=He([ne(0,a.ICommandService),ne(1,a.IUniverInstanceService),ne(2,a.Inject(m.RefRangeService))],q);var be=Object.getOwnPropertyDescriptor,Pe=(s,t,e,n)=>{for(var i=n>1?void 0:n?be(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},F=(s,t)=>(e,n)=>t(e,n,s);let J=class extends a.Disposable{constructor(s,t,e,n){super(),this._sheetInterceptorService=s,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:s=>{if(s.id===m.SetRangeValuesCommand.id){const t=s.params,{unitId:e,subUnitId:n}=t,i=[],r=[];return t.cellValue&&new a.ObjectMatrix(t.cellValue).forValue((o,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,o,d);c&&(i.push({id:w.id,params:{unitId:e,subUnitId:n,id:c.id}}),r.push({id:E.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:r,redos:i}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:s=>{if(s.id===m.ClearSelectionContentCommand.id||s.id===m.ClearSelectionAllCommand.id||s.id===m.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),i=m.getSheetCommandTarget(this._univerInstanceService);if(n&&i){const{unitId:r,subUnitId:o}=i;a.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(r,o,d,c);l&&(t.push({id:w.id,params:{unitId:r,subUnitId:o,id:l.id}}),e.push({id:E.id,params:{unitId:r,subUnitId:o,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(m.AFTER_CELL_EDIT,{handler:(s,t,e)=>{if(!s||s.p)return e(s);if(typeof s.v=="string"&&a.Tools.isLegalUrl(s.v)&&s.v[s.v.length-1]!==" "){const{unitId:n,subUnitId:i}=t,r=this._univerInstanceService.getUnit(n,a.UniverInstanceType.UNIVER_SHEET),o=r==null?void 0:r.getSheetBySheetId(i);if(!o)return e(s);const d=o.getBlankCellDocumentModel(s);if(!d.documentModel)return e(s);const c=a.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:s.v.length,collapsed:!1},body:{dataStream:`${s.v}`,customRanges:[{startIndex:0,endIndex:s.v.length-1,rangeId:a.generateRandomId(),rangeType:a.CustomRangeType.HYPERLINK,properties:{url:s.v}}]},doc:d.documentModel});if(!c)return e(s);const l=d.documentModel.getBody();return a.TextX.apply(l,c.serialize()),e({...s,p:{id:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:l,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(s)}}))}};J=Pe([F(0,a.Inject(m.SheetInterceptorService)),F(1,a.Inject(p.HyperLinkModel)),F(2,a.Inject(m.SheetsSelectionsService)),F(3,a.IUniverInstanceService)],J);var de=(s=>(s[s.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",s[s.UNIVER_DOC=1]="UNIVER_DOC",s[s.UNIVER_SHEET=2]="UNIVER_SHEET",s[s.UNIVER_SLIDE=3]="UNIVER_SLIDE",s[s.UNIVER_PROJECT=4]="UNIVER_PROJECT",s[s.UNRECOGNIZED=-1]="UNRECOGNIZED",s))(de||{}),De=Object.getOwnPropertyDescriptor,Oe=(s,t,e,n)=>{for(var i=n>1?void 0:n?De(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},ce=(s,t)=>(e,n)=>t(e,n,s);let X=class extends a.Disposable{constructor(s,t){super(),this._resourceManagerService=s,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const s=e=>{const n=this._hyperLinkModel.getUnit(e),i={};return n?(n.forEach(r=>{i[r.subUnitId]=r.links.map(({display:o,...d})=>d)}),JSON.stringify(i)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:oe,businesses:[de.UNIVER_SHEET],toJson:e=>s(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(i=>{n[i].forEach(o=>{this._hyperLinkModel.addHyperLink(e,i,o)})})}}))}};X=Oe([ce(0,a.IResourceManagerService),ce(1,a.Inject(p.HyperLinkModel))],X);const le={type:a.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(s,t){if(!t)return!1;const e=s.get(a.ICommandService),n=s.get(a.IUndoRedoService),i=s.get(a.IUniverInstanceService),r=s.get(p.HyperLinkModel),o=s.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:u,worksheet:g}=d,{link:f}=t,{payload:y,display:h,row:_,column:v,id:S}=f,k=g.getCell(_,v),I=g.getBlankCellDocumentModel(k),R=I.documentModel.getSnapshot(),M=a.Tools.deepClone(R.body);if(!M)return!1;let T;if(h?T=a.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:M.dataStream.length-2,collapsed:M.dataStream.length-2===0},body:{dataStream:`${h}`,customRanges:[{startIndex:0,endIndex:h.length-1,rangeType:a.CustomRangeType.HYPERLINK,rangeId:S,properties:{url:y}}]},doc:I.documentModel}):T=a.BuildTextUtils.customRange.add({body:M,ranges:[{startOffset:0,endOffset:M.dataStream.length-2,collapsed:!1}],rangeId:S,rangeType:a.CustomRangeType.HYPERLINK,properties:{url:y,refId:S}}),!T)return!1;const j=a.TextX.apply(M,T.serialize()),H={p:{...R,body:j},t:a.CellValueType.STRING},N=o.onWriteCell(u,g,_,v,H),V={unitId:c,subUnitId:l,cellValue:{[f.row]:{[f.column]:N}}},se={id:m.SetRangeValuesMutation.id,params:V},Q=m.SetRangeValuesUndoMutationFactory(s,V),re={id:m.SetRangeValuesMutation.id,params:Q},A=[se],b=[re],P=r.getHyperLinkByLocation(c,l,_,v);return P&&(A.push({id:w.id,params:{unitId:c,subUnitId:l,id:P.id}}),b.push({id:E.id,params:{unitId:c,subUnitId:l,link:P}})),await a.sequenceExecute(A,e)?await o.onValidateCell(u,g,_,v)===!1?(a.sequenceExecute(b,e),!1):(n.pushUndoRedo({redoMutations:A,undoMutations:b,unitID:c}),!0):!1}},ue={id:"sheets.command.add-rich-hyper-link",type:a.CommandType.COMMAND,handler:async(s,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,i=s.get(a.ICommandService),r=a.generateRandomId(),{payload:o}=n,d=x.addCustomRangeBySelectionFactory(s,{unitId:e,rangeId:r,rangeType:a.CustomRangeType.HYPERLINK,properties:{url:o,refId:r}});return d?i.syncExecuteCommand(d.id,d.params):!1}},pe={type:a.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(s,t){var H,N;if(!t)return!1;const e=s.get(a.ICommandService),n=s.get(a.IUndoRedoService),i=s.get(a.IUniverInstanceService),r=s.get(p.HyperLinkModel),o=m.getSheetCommandTarget(i,t);if(!o)return!1;const{row:d,column:c,id:l}=t,{unitId:u,subUnitId:g,worksheet:f}=o,y=f.getCell(d,c);if(!y)return!1;const h=f.getCellDocumentModelWithFormula(y);if(!(h!=null&&h.documentModel))return!1;const _=a.Tools.deepClone(h.documentModel.getSnapshot()),v=(N=(H=_.body)==null?void 0:H.customRanges)==null?void 0:N.find(V=>`${V.rangeId}`===l);if(!v)return!1;const S=a.BuildTextUtils.customRange.delete({documentDataModel:h.documentModel,rangeId:v.rangeId});if(!S)return!1;const k=a.TextX.apply(_.body,S.serialize()),I=[],R=[],M={unitId:u,subUnitId:g,cellValue:{[d]:{[c]:{p:{..._,body:k},t:a.CellValueType.STRING}}}};I.push({id:m.SetRangeValuesMutation.id,params:M});const T=m.SetRangeValuesUndoMutationFactory(s,M);R.push({id:m.SetRangeValuesMutation.id,params:T});const j=r.getHyperLinkByLocation(u,g,d,c);return j&&(I.push({id:w.id,params:{unitId:u,subUnitId:g,id:l}}),R.push({id:E.id,params:{unitId:u,subUnitId:g,link:{...j}}})),a.sequenceExecute(I,e).result?(n.pushUndoRedo({redoMutations:I,undoMutations:R,unitID:u}),!0):!1}},ge={type:a.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(s,t){var u,g;if(!t)return!1;const{id:e,documentId:n}=t,i=s.get(a.ICommandService),o=s.get(a.IUniverInstanceService).getUnit(n,a.UniverInstanceType.UNIVER_DOC),d=(g=(u=o==null?void 0:o.getBody())==null?void 0:u.customRanges)==null?void 0:g.find(f=>f.rangeId===e);let c=null;d&&d.endIndex===o.getBody().dataStream.length-3&&(c={dataStream:" "});const l=x.deleteCustomRangeFactory(s,{unitId:n,rangeId:e,insert:c});return l?i.syncExecuteCommand(l.id,l.params):!1}},he={type:a.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(s,t){var _e,ve,Se;if(!t)return!1;const e=s.get(a.ICommandService),n=s.get(a.IUndoRedoService),i=s.get(a.IUniverInstanceService),r=s.get(p.HyperLinkModel),o=s.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:u,id:g}=t,{workbook:f,worksheet:y,unitId:h,subUnitId:_}=d,{payload:v,display:S=""}=c,k=y.getCell(l,u);if(!k)return!1;const I=y.getCellDocumentModelWithFormula(k);if(!(I!=null&&I.documentModel))return!1;const R=I.documentModel.getSnapshot(),M=(ve=(_e=R.body)==null?void 0:_e.customRanges)==null?void 0:ve.find(Ie=>`${Ie.rangeId}`===g);if(!M)return!1;const T=a.generateRandomId(),O=(Se=a.getBodySlice(I.documentModel.getBody(),M.startIndex,M.endIndex+1).textRuns)==null?void 0:Se[0];O&&(O.ed=S.length+1);const H=x.replaceSelectionFactory(s,{unitId:h,body:{dataStream:`${S}`,customRanges:[{rangeId:T,rangeType:a.CustomRangeType.HYPERLINK,startIndex:0,endIndex:S.length-1,properties:{url:v}}],textRuns:O?[O]:void 0},selection:{startOffset:M.startIndex,endOffset:M.endIndex+1,collapsed:!1},doc:I.documentModel});if(!H)return!1;const N=a.TextX.apply(a.Tools.deepClone(R.body),H.textX.serialize()),V={p:{...R,body:N},t:a.CellValueType.STRING},se=o.onWriteCell(f,y,l,u,V),Q={id:m.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:_,cellValue:{[l]:{[u]:se}}}},re=m.SetRangeValuesUndoMutationFactory(s,Q.params),A={id:m.SetRangeValuesMutation.id,params:re},b=[Q],P=[A],ee=r.getHyperLinkByLocation(h,_,l,u);return ee&&(b.push({id:w.id,params:{unitId:h,subUnitId:_,id:ee.id}}),P.push({id:E.id,params:{unitId:h,subUnitId:_,link:ee}})),a.sequenceExecute(b,e)?await o.onValidateCell(f,y,l,u)===!1?(a.sequenceExecute(P,e),!1):(n.pushUndoRedo({redoMutations:b,undoMutations:P,unitID:h}),!0):!1}},me={type:a.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(s,t)=>{var h,_,v,S;if(!t)return!1;const{documentId:e,payload:n,id:i}=t,r=s.get(a.IUniverInstanceService),o=s.get(a.ICommandService),d=r.getUnit(e,a.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(_=(h=d.getBody())==null?void 0:h.customRanges)==null?void 0:_.find(k=>k.rangeId===i);if(!c)return!1;const l=(v=t.payload.display)!=null?v:"",u=a.generateRandomId(),f=(S=a.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:S[0];f&&(f.ed=l.length+1);const y=x.replaceSelectionFactory(s,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:u,rangeType:a.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:f?[f]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return y?o.syncExecuteCommand(y.id,y.params):!1}};var Ne=Object.getOwnPropertyDescriptor,Ve=(s,t,e,n)=>{for(var i=n>1?void 0:n?Ne(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},$e=(s,t)=>(e,n)=>t(e,n,s);let Z=class extends a.Disposable{constructor(s){super(),this._commandService=s,this._registerCommands()}_registerCommands(){[le,he,pe,me,ge,ue,E,W,w,B,K].forEach(s=>{this._commandService.registerCommand(s)})}};Z=Ve([$e(0,a.ICommandService)],Z);var je=Object.getOwnPropertyDescriptor,Ae=(s,t,e,n)=>{for(var i=n>1?void 0:n?je(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},ie=(s,t)=>(e,n)=>t(e,n,s);p.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${L.SHEET}=${e}${n?`&${typeof n=="string"?L.DEFINE_NAME:L.RANGE}=${typeof n=="string"?n:C.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,i,r;if(t.startsWith("#")){const o=new URLSearchParams(t.slice(1)),d={gid:(e=o.get("gid"))!=null?e:"",range:(n=o.get("range"))!=null?n:"",rangeid:(i=o.get("rangeid"))!=null?i:"",unitid:(r=o.get("unitid"))!=null?r:""},c=this._getURLName(d);return{type:c.type,name:c.name,url:t,searchObj:d}}else return{type:L.URL,name:t,url:t,searchObj:null}}_getURLName(t){var u;const{gid:e,range:n,rangeid:i,unitid:r}=t,o=r?this._univerInstanceService.getUnit(r,a.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),d={type:L.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!o)return d;const c=e?o.getSheetBySheetId(e):o.getActiveSheet(),l=(u=c==null?void 0:c.getName())!=null?u:"";if(n){if(!c)return d;const g=C.deserializeRangeWithSheet(n).range;return a.isValidRange(g,c)&&n!==$?{type:L.RANGE,name:C.serializeRangeWithSheet(l,g)}:d}if(i){const g=this._definedNamesService.getValueById(o.getUnitId(),i);return g?{type:L.DEFINE_NAME,name:g.formulaOrRefString}:d}if(e){const g=o.getSheetBySheetId(e);return g?{type:L.SHEET,name:g.getName()}:d}return d}},p.SheetsHyperLinkParserService=Ae([ie(0,a.IUniverInstanceService),ie(1,a.Inject(a.LocaleService)),ie(2,C.IDefinedNamesService)],p.SheetsHyperLinkParserService);var xe=Object.defineProperty,We=Object.getOwnPropertyDescriptor,Be=(s,t,e)=>t in s?xe(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Ke=(s,t,e,n)=>{for(var i=n>1?void 0:n?We(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},fe=(s,t)=>(e,n)=>t(e,n,s),ye=(s,t,e)=>Be(s,typeof t!="symbol"?t+"":t,e);p.UniverSheetsHyperLinkPlugin=class extends a.Plugin{constructor(t=ae,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...i}=a.merge({},ae,this._config);this._configService.setConfig(ke,i)}onStarting(){a.registerDependencies(this._injector,[[p.HyperLinkModel],[p.SheetsHyperLinkParserService],[X],[Z],[G],[J],[Y],[q]]),a.touchDependencies(this._injector,[[G],[X],[Z],[J],[Y],[q]])}},ye(p.UniverSheetsHyperLinkPlugin,"pluginName",oe),ye(p.UniverSheetsHyperLinkPlugin,"type",a.UniverInstanceType.UNIVER_SHEET),p.UniverSheetsHyperLinkPlugin=Ke([a.DependentOn(m.UniverSheetsPlugin),fe(1,a.Inject(a.Injector)),fe(2,a.IConfigService)],p.UniverSheetsHyperLinkPlugin),p.AddHyperLinkCommand=le,p.AddHyperLinkMutation=E,p.AddRichHyperLinkCommand=ue,p.CancelHyperLinkCommand=pe,p.CancelRichHyperLinkCommand=ge,p.ERROR_RANGE=$,p.RemoveHyperLinkMutation=w,p.SheetHyperLinkType=L,p.UpdateHyperLinkCommand=he,p.UpdateHyperLinkMutation=W,p.UpdateHyperLinkRefMutation=B,p.UpdateRichHyperLinkCommand=me,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(p,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("rxjs"),require("@univerjs/sheets"),require("@univerjs/engine-formula"),require("@univerjs/docs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","@univerjs/sheets","@univerjs/engine-formula","@univerjs/docs"],a):(p=typeof globalThis<"u"?globalThis:p||self,a(p.UniverSheetsHyperLink={},p.UniverCore,p.rxjs,p.UniverSheets,p.UniverEngineFormula,p.UniverDocs))})(this,function(p,a,N,m,C,x){"use strict";var Ge=Object.defineProperty;var Ye=(p,a,N)=>a in p?Ge(p,a,{enumerable:!0,configurable:!0,writable:!0,value:N}):p[a]=N;var U=(p,a,N)=>Ye(p,typeof a!="symbol"?a+"":a,N);var Re=Object.getOwnPropertyDescriptor,Me=(s,t,e,n)=>{for(var i=n>1?void 0:n?Re(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},Ce=(s,t)=>(e,n)=>t(e,n,s);p.HyperLinkModel=class extends a.Disposable{constructor(e){super();U(this,"_linkUpdate$",new N.Subject);U(this,"linkUpdate$",this._linkUpdate$.asObservable());U(this,"_linkMap",new Map);U(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let i=this._linkMap.get(e);i||(i=new Map,this._linkMap.set(e,i));let r=i.get(n);r||(r=new a.ObjectMatrix,i.set(n,r));let o=this._linkPositionMap.get(e);o||(o=new Map,this._linkPositionMap.set(e,o));let d=o.get(n);return d||(d=new Map,o.set(n,d)),{matrix:r,positionMap:d}}addHyperLink(e,n,i){const{matrix:r,positionMap:o}=this._ensureMap(e,n);return r.setValue(i.row,i.column,i),o.set(i.id,{row:i.row,column:i.column,link:i}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:i,type:"add"}),!0}updateHyperLink(e,n,i,r,o=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;const u=d.getValue(l.row,l.column);return u&&(Object.assign(u,r),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:u.display,payload:u.payload},id:i,type:"update",silent:o})),!0}updateHyperLinkRef(e,n,i,r,o=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;let u=d.getValue(l.row,l.column);return!u||u.id!==i?u=l.link:d.realDeleteValue(l.row,l.column),Object.assign(u,r),c.set(i,{...r,link:u}),d.setValue(r.row,r.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:r,id:i,type:"updateRef",silent:o}),!0}removeHyperLink(e,n,i){const{matrix:r,positionMap:o}=this._ensureMap(e,n),d=o.get(i);if(!d)return!1;o.delete(i);const c=r.getValue(d.row,d.column);return c&&c.id===i&&r.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,i){const{matrix:r,positionMap:o}=this._ensureMap(e,n),d=o.get(i);if(d)return r.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,i,r){const{matrix:o}=this._ensureMap(e,n);return o.getValue(i,r)}getHyperLinkByLocationSync(e,n,i,r){var g,f,y,h,_;const{matrix:o}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,a.UniverInstanceType.UNIVER_SHEET),c=(g=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:g.getCellRaw(i,r),l=((_=(h=c==null?void 0:c.v)!=null?h:(y=(f=c==null?void 0:c.p)==null?void 0:f.body)==null?void 0:y.dataStream.slice(0,-2))!=null?_:"").toString(),u=o.getValue(i,r);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:i}=this._ensureMap(e,n),r=[];return i.forValue((o,d,c)=>{c&&r.push(c)}),r}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(i=>{const r=this.getSubUnit(e,i);return{unitId:e,subUnitId:i,links:r}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}},p.HyperLinkModel=Me([Ce(0,a.IUniverInstanceService)],p.HyperLinkModel);var L=(s=>(s.SHEET="gid",s.RANGE="range",s.DEFINE_NAME="rangeid",s.INVALID="invalid",s.URL="url",s))(L||{});const ke="sheets-hyper-link.config",ae={},E={type:a.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(s,t){if(!t)return!1;const e=s.get(p.HyperLinkModel),{unitId:n,subUnitId:i,link:r}=t;return e.addHyperLink(n,i,r)}},w={type:a.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(s,t){if(!t)return!1;const e=s.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:r}=t;return e.removeHyperLink(n,i,r)}},W={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(s,t){if(!t)return!1;const e=s.get(p.HyperLinkModel),{unitId:n,subUnitId:i,payload:r,id:o}=t;return e.updateHyperLink(n,i,o,r,!1)}},B={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(s,t){if(!t)return!1;const e=s.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:r,row:o,column:d,silent:c}=t;return e.updateHyperLinkRef(n,i,r,{row:o,column:d},c)}},K={type:a.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(s,t){var y,h,_;if(!t)return!1;const{unitId:e,subUnitId:n,row:i,col:r,id:o,url:d}=t,c=s.get(a.IUniverInstanceService),l=m.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:u}=l,g=u.getCellRaw(i,r),f=(_=(h=(y=g==null?void 0:g.p)==null?void 0:y.body)==null?void 0:h.customRanges)==null?void 0:_.find(v=>v.rangeType===a.CustomRangeType.HYPERLINK&&v.rangeId===o);return f&&(f.properties.url=d),!0}},oe="SHEET_HYPER_LINK_PLUGIN",$="err";var Ue=Object.getOwnPropertyDescriptor,Le=(s,t,e,n)=>{for(var i=n>1?void 0:n?Ue(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},z=(s,t)=>(e,n)=>t(e,n,s);let G=class extends a.Disposable{constructor(t,e,n,i){super();U(this,"_disposableMap",new Map);U(this,"_watchDisposableMap",new Map);U(this,"_rangeDisableMap",new Map);U(this,"_rangeWatcherMap",new Map);U(this,"_handlePositionChange",(t,e,n,i,r)=>{const o={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return i?{redos:[{id:B.id,params:{unitId:t,subUnitId:e,id:n.id,row:i.startRow,column:i.startColumn,silent:r}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,id:n.id,row:o.startRow,column:o.startColumn,silent:r}}]}:{redos:[{id:w.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:E.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=i,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const i=n.id,r={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},o=d=>{const c=m.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(r,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===r.startColumn&&l.startRow===r.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(i,this._refRangeService.registerRefRange(r,o,t,e))}_watchPosition(t,e,n){const i=n.id,r={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(t,e,r,(o,d)=>{const{redos:c}=this._handlePositionChange(t,e,n,d,!0);a.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(t){const e=this._disposableMap.get(t);e==null||e.dispose(),this._disposableMap.delete(t)}_unwatchPosition(t){const e=this._watchDisposableMap.get(t);e==null||e.dispose(),this._watchDisposableMap.delete(t)}_registerRange(t,e,n,i=!1){var r,o,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(r=c.get("gid"))!=null?r:"",range:(o=c.get("range"))!=null?o:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const u=l.gid,g=C.deserializeRangeWithSheet(l.range).range;if(a.isValidRange(g)&&l.range!==$){const f=y=>{const h=m.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(g,y,{selectionManagerService:this._selectionManagerService});return h&&C.serializeRange(h)===C.serializeRange(g)?{redos:[],undos:[]}:{redos:[{id:W.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`}}}],undos:[{id:W.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(g,f,t,u)),i||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,u,g,(y,h)=>{this._hyperLinkModel.updateHyperLink(t,u,e,{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`},!0)},!0))}}}}_unregisterRange(t){const e=this._rangeDisableMap.get(t);e==null||e.dispose(),this._rangeDisableMap.delete(t)}_unwatchRange(t){const e=this._rangeWatcherMap.get(t);e==null||e.dispose(),this._rangeWatcherMap.delete(t)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(n=>{const{unitId:i,subUnitId:r,links:o}=n;o.forEach(d=>{this._registerPosition(i,r,d),this._watchPosition(i,r,d),this._registerRange(i,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:i,silent:r}=t,o=this._hyperLinkModel.getHyperLink(e,n,i);if(!o)return;this._unregisterPosition(i),this._registerPosition(e,n,o),r||(this._unwatchPosition(i),this._watchPosition(e,n,o));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:i}=n;i.forEach(r=>{this._unregisterPosition(r.id),this._unwatchPosition(r.id),this._unregisterRange(r.id),this._unwatchRange(r.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(a.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};G=Le([z(0,a.Inject(m.RefRangeService)),z(1,a.Inject(p.HyperLinkModel)),z(2,a.Inject(m.SheetsSelectionsService)),z(3,a.ICommandService)],G);var Ee=Object.getOwnPropertyDescriptor,we=(s,t,e,n)=>{for(var i=n>1?void 0:n?Ee(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},te=(s,t)=>(e,n)=>t(e,n,s);let Y=class extends a.Disposable{constructor(s,t,e){super(),this._sheetInterceptorService=s,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:s=>{var t;if(s.id===m.RemoveSheetCommand.id){const e=s.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const i=n.getUnitId(),r=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!r)return{redos:[],undos:[]};const o=this._hyperLinkModel.getSubUnit(i,r),d=o.map(l=>({id:w.id,params:{unitId:i,subUnitId:r,id:l.id}})),c=o.map(l=>({id:E.id,params:{unitId:i,subUnitId:r,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};Y=we([te(0,a.Inject(m.SheetInterceptorService)),te(1,a.IUniverInstanceService),te(2,a.Inject(p.HyperLinkModel))],Y);var Te=Object.getOwnPropertyDescriptor,He=(s,t,e,n)=>{for(var i=n>1?void 0:n?Te(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},ne=(s,t)=>(e,n)=>t(e,n,s);let q=class extends a.Disposable{constructor(t,e,n){super();U(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let i=n.get(e);return i||(i=new a.ObjectMatrix,n.set(e,i)),i}_isLegalRangeUrl(t,e){var i,r,o;const n=this._univerInstanceService.getUnit(t,a.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(i=d.get("gid"))!=null?i:"",range:(r=d.get("range"))!=null?r:"",rangeid:(o=d.get("rangeid"))!=null?o:""};if(c.range&&c.gid){const l=c.gid,u=n.getSheetBySheetId(l);if(!u)return null;const g=C.deserializeRangeWithSheet(c.range).range;if(a.isValidRange(g,u)&&c.range!==$)return{range:g,worksheet:u}}}return null}_registerRange(t,e,n,i,r){var d,c,l,u;const o=this._enusreMap(t,e);if((c=(d=r.body)==null?void 0:d.customRanges)!=null&&c.some(g=>{var f;return g.rangeType===a.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(f=g.properties)==null?void 0:f.url)})){const g=new a.DisposableCollection;let f=!1;(u=(l=r.body)==null?void 0:l.customRanges)==null||u.forEach(y=>{var h;if(y.rangeType===a.CustomRangeType.HYPERLINK){const _=(h=y.properties)==null?void 0:h.url,v=this._isLegalRangeUrl(t,_);if(v){const{range:S,worksheet:k}=v;f=!0,g.add(this._refRangeService.registerRefRange(S,I=>{const R=m.handleDefaultRangeChangeWithEffectRefCommands(S,I);return R&&a.Rectangle.equals(R,S)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:K.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:y.rangeId,url:`#gid=${e}&range=${R?C.serializeRange(R):$}`}}],undos:[{id:K.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:y.rangeId,url:_}}],redos:[]}},k.getUnitId(),k.getSheetId()))}}}),f&&o.setValue(n,i,g)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(i=>{const r=i.getSheetId(),o=this._enusreMap(n,r);i.getCellMatrix().forValue((d,c,l)=>{const u=o.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,r,d,c,l.p)})})};this._univerInstanceService.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(e=>{e.type===a.UniverInstanceType.UNIVER_SHEET&&t(e)}))}_initWorkbookUnload(){this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===a.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(i=>{const r=i.getSheetId();this._enusreMap(n,r).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}})}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===m.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:i,cellValue:r}=e,o=this._enusreMap(n,i);r&&new a.ObjectMatrix(r).forValue((d,c,l)=>{const u=o.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,i,d,c,l.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===K.id){const e=t.params,{unitId:n,subUnitId:i,row:r,col:o}=e,d=m.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:i}),l=this._enusreMap(n,i).getValue(r,o);if(l&&l.dispose(),d){const{worksheet:u}=d,g=u.getCellRaw(r,o);g&&g.p&&this._registerRange(n,i,r,o,g.p)}}}))}};q=He([ne(0,a.ICommandService),ne(1,a.IUniverInstanceService),ne(2,a.Inject(m.RefRangeService))],q);var be=Object.getOwnPropertyDescriptor,Pe=(s,t,e,n)=>{for(var i=n>1?void 0:n?be(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},F=(s,t)=>(e,n)=>t(e,n,s);let J=class extends a.Disposable{constructor(s,t,e,n){super(),this._sheetInterceptorService=s,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:s=>{if(s.id===m.SetRangeValuesCommand.id){const t=s.params,{unitId:e,subUnitId:n}=t,i=[],r=[];return t.cellValue&&new a.ObjectMatrix(t.cellValue).forValue((o,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,o,d);c&&(i.push({id:w.id,params:{unitId:e,subUnitId:n,id:c.id}}),r.push({id:E.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:r,redos:i}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:s=>{if(s.id===m.ClearSelectionContentCommand.id||s.id===m.ClearSelectionAllCommand.id||s.id===m.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),i=m.getSheetCommandTarget(this._univerInstanceService);if(n&&i){const{unitId:r,subUnitId:o}=i;a.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(r,o,d,c);l&&(t.push({id:w.id,params:{unitId:r,subUnitId:o,id:l.id}}),e.push({id:E.id,params:{unitId:r,subUnitId:o,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(m.AFTER_CELL_EDIT,{handler:(s,t,e)=>{if(!s||s.p)return e(s);if(typeof s.v=="string"&&a.Tools.isLegalUrl(s.v)&&s.v[s.v.length-1]!==" "){const{unitId:n,subUnitId:i}=t,r=this._univerInstanceService.getUnit(n,a.UniverInstanceType.UNIVER_SHEET),o=r==null?void 0:r.getSheetBySheetId(i);if(!o)return e(s);const d=o.getBlankCellDocumentModel(s);if(!d.documentModel)return e(s);const c=a.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:s.v.length,collapsed:!1},body:{dataStream:`${s.v}`,customRanges:[{startIndex:0,endIndex:s.v.length-1,rangeId:a.generateRandomId(),rangeType:a.CustomRangeType.HYPERLINK,properties:{url:s.v}}]},doc:d.documentModel});if(!c)return e(s);const l=d.documentModel.getBody();return a.TextX.apply(l,c.serialize()),e({...s,p:{id:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:l,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(s)}}))}};J=Pe([F(0,a.Inject(m.SheetInterceptorService)),F(1,a.Inject(p.HyperLinkModel)),F(2,a.Inject(m.SheetsSelectionsService)),F(3,a.IUniverInstanceService)],J);var de=(s=>(s[s.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",s[s.UNIVER_DOC=1]="UNIVER_DOC",s[s.UNIVER_SHEET=2]="UNIVER_SHEET",s[s.UNIVER_SLIDE=3]="UNIVER_SLIDE",s[s.UNIVER_PROJECT=4]="UNIVER_PROJECT",s[s.UNRECOGNIZED=-1]="UNRECOGNIZED",s))(de||{}),Ne=Object.getOwnPropertyDescriptor,De=(s,t,e,n)=>{for(var i=n>1?void 0:n?Ne(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},ce=(s,t)=>(e,n)=>t(e,n,s);let X=class extends a.Disposable{constructor(s,t){super(),this._resourceManagerService=s,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const s=e=>{const n=this._hyperLinkModel.getUnit(e),i={};return n?(n.forEach(r=>{i[r.subUnitId]=r.links.map(({display:o,...d})=>d)}),JSON.stringify(i)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:oe,businesses:[de.UNIVER_SHEET],toJson:e=>s(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(i=>{n[i].forEach(o=>{this._hyperLinkModel.addHyperLink(e,i,o)})})}}))}};X=De([ce(0,a.IResourceManagerService),ce(1,a.Inject(p.HyperLinkModel))],X);const le={type:a.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(s,t){if(!t)return!1;const e=s.get(a.ICommandService),n=s.get(a.IUndoRedoService),i=s.get(a.IUniverInstanceService),r=s.get(p.HyperLinkModel),o=s.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:u,worksheet:g}=d,{link:f}=t,{payload:y,display:h,row:_,column:v,id:S}=f,k=g.getCell(_,v),I=g.getBlankCellDocumentModel(k),R=I.documentModel.getSnapshot(),M=a.Tools.deepClone(R.body);if(!M)return!1;let T;if(h?T=a.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:M.dataStream.length-2,collapsed:M.dataStream.length-2===0},body:{dataStream:`${h}`,customRanges:[{startIndex:0,endIndex:h.length-1,rangeType:a.CustomRangeType.HYPERLINK,rangeId:S,properties:{url:y}}]},doc:I.documentModel}):T=a.BuildTextUtils.customRange.add({body:M,ranges:[{startOffset:0,endOffset:M.dataStream.length-2,collapsed:!1}],rangeId:S,rangeType:a.CustomRangeType.HYPERLINK,properties:{url:y,refId:S}}),!T)return!1;const j=a.TextX.apply(M,T.serialize()),H={p:{...R,body:j},t:a.CellValueType.STRING},O=o.onWriteCell(u,g,_,v,H),V={unitId:c,subUnitId:l,cellValue:{[f.row]:{[f.column]:O}}},se={id:m.SetRangeValuesMutation.id,params:V},Q=m.SetRangeValuesUndoMutationFactory(s,V),re={id:m.SetRangeValuesMutation.id,params:Q},A=[se],b=[re],P=r.getHyperLinkByLocation(c,l,_,v);return P&&(A.push({id:w.id,params:{unitId:c,subUnitId:l,id:P.id}}),b.push({id:E.id,params:{unitId:c,subUnitId:l,link:P}})),await a.sequenceExecute(A,e)?await o.onValidateCell(u,g,_,v)===!1?(a.sequenceExecute(b,e),!1):(n.pushUndoRedo({redoMutations:A,undoMutations:b,unitID:c}),!0):!1}},ue={id:"sheets.command.add-rich-hyper-link",type:a.CommandType.COMMAND,handler:async(s,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,i=s.get(a.ICommandService),r=a.generateRandomId(),{payload:o}=n,d=x.addCustomRangeBySelectionFactory(s,{unitId:e,rangeId:r,rangeType:a.CustomRangeType.HYPERLINK,properties:{url:o,refId:r}});return d?i.syncExecuteCommand(d.id,d.params):!1}},pe={type:a.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(s,t){var H,O;if(!t)return!1;const e=s.get(a.ICommandService),n=s.get(a.IUndoRedoService),i=s.get(a.IUniverInstanceService),r=s.get(p.HyperLinkModel),o=m.getSheetCommandTarget(i,t);if(!o)return!1;const{row:d,column:c,id:l}=t,{unitId:u,subUnitId:g,worksheet:f}=o,y=f.getCell(d,c);if(!y)return!1;const h=f.getCellDocumentModelWithFormula(y);if(!(h!=null&&h.documentModel))return!1;const _=a.Tools.deepClone(h.documentModel.getSnapshot()),v=(O=(H=_.body)==null?void 0:H.customRanges)==null?void 0:O.find(V=>`${V.rangeId}`===l);if(!v)return!1;const S=a.BuildTextUtils.customRange.delete({documentDataModel:h.documentModel,rangeId:v.rangeId});if(!S)return!1;const k=a.TextX.apply(_.body,S.serialize()),I=[],R=[],M={unitId:u,subUnitId:g,cellValue:{[d]:{[c]:{p:{..._,body:k},t:a.CellValueType.STRING}}}};I.push({id:m.SetRangeValuesMutation.id,params:M});const T=m.SetRangeValuesUndoMutationFactory(s,M);R.push({id:m.SetRangeValuesMutation.id,params:T});const j=r.getHyperLinkByLocation(u,g,d,c);return j&&(I.push({id:w.id,params:{unitId:u,subUnitId:g,id:l}}),R.push({id:E.id,params:{unitId:u,subUnitId:g,link:{...j}}})),a.sequenceExecute(I,e).result?(n.pushUndoRedo({redoMutations:I,undoMutations:R,unitID:u}),!0):!1}},ge={type:a.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(s,t){var u,g;if(!t)return!1;const{id:e,documentId:n}=t,i=s.get(a.ICommandService),o=s.get(a.IUniverInstanceService).getUnit(n,a.UniverInstanceType.UNIVER_DOC),d=(g=(u=o==null?void 0:o.getBody())==null?void 0:u.customRanges)==null?void 0:g.find(f=>f.rangeId===e);let c=null;d&&d.endIndex===o.getBody().dataStream.length-3&&(c={dataStream:" "});const l=x.deleteCustomRangeFactory(s,{unitId:n,rangeId:e,insert:c});return l?i.syncExecuteCommand(l.id,l.params):!1}},he={type:a.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(s,t){var _e,ve,Se;if(!t)return!1;const e=s.get(a.ICommandService),n=s.get(a.IUndoRedoService),i=s.get(a.IUniverInstanceService),r=s.get(p.HyperLinkModel),o=s.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:u,id:g}=t,{workbook:f,worksheet:y,unitId:h,subUnitId:_}=d,{payload:v,display:S=""}=c,k=y.getCell(l,u);if(!k)return!1;const I=y.getCellDocumentModelWithFormula(k);if(!(I!=null&&I.documentModel))return!1;const R=I.documentModel.getSnapshot(),M=(ve=(_e=R.body)==null?void 0:_e.customRanges)==null?void 0:ve.find(Ie=>`${Ie.rangeId}`===g);if(!M)return!1;const T=a.generateRandomId(),D=(Se=a.getBodySlice(I.documentModel.getBody(),M.startIndex,M.endIndex+1).textRuns)==null?void 0:Se[0];D&&(D.ed=S.length+1);const H=x.replaceSelectionFactory(s,{unitId:h,body:{dataStream:`${S}`,customRanges:[{rangeId:T,rangeType:a.CustomRangeType.HYPERLINK,startIndex:0,endIndex:S.length-1,properties:{url:v}}],textRuns:D?[D]:void 0},selection:{startOffset:M.startIndex,endOffset:M.endIndex+1,collapsed:!1},doc:I.documentModel});if(!H)return!1;const O=a.TextX.apply(a.Tools.deepClone(R.body),H.textX.serialize()),V={p:{...R,body:O},t:a.CellValueType.STRING},se=o.onWriteCell(f,y,l,u,V),Q={id:m.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:_,cellValue:{[l]:{[u]:se}}}},re=m.SetRangeValuesUndoMutationFactory(s,Q.params),A={id:m.SetRangeValuesMutation.id,params:re},b=[Q],P=[A],ee=r.getHyperLinkByLocation(h,_,l,u);return ee&&(b.push({id:w.id,params:{unitId:h,subUnitId:_,id:ee.id}}),P.push({id:E.id,params:{unitId:h,subUnitId:_,link:ee}})),a.sequenceExecute(b,e)?await o.onValidateCell(f,y,l,u)===!1?(a.sequenceExecute(P,e),!1):(n.pushUndoRedo({redoMutations:b,undoMutations:P,unitID:h}),!0):!1}},me={type:a.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(s,t)=>{var h,_,v,S;if(!t)return!1;const{documentId:e,payload:n,id:i}=t,r=s.get(a.IUniverInstanceService),o=s.get(a.ICommandService),d=r.getUnit(e,a.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(_=(h=d.getBody())==null?void 0:h.customRanges)==null?void 0:_.find(k=>k.rangeId===i);if(!c)return!1;const l=(v=t.payload.display)!=null?v:"",u=a.generateRandomId(),f=(S=a.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:S[0];f&&(f.ed=l.length+1);const y=x.replaceSelectionFactory(s,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:u,rangeType:a.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:f?[f]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return y?o.syncExecuteCommand(y.id,y.params):!1}};var Oe=Object.getOwnPropertyDescriptor,Ve=(s,t,e,n)=>{for(var i=n>1?void 0:n?Oe(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},$e=(s,t)=>(e,n)=>t(e,n,s);let Z=class extends a.Disposable{constructor(s){super(),this._commandService=s,this._registerCommands()}_registerCommands(){[le,he,pe,me,ge,ue,E,W,w,B,K].forEach(s=>{this._commandService.registerCommand(s)})}};Z=Ve([$e(0,a.ICommandService)],Z);var je=Object.getOwnPropertyDescriptor,Ae=(s,t,e,n)=>{for(var i=n>1?void 0:n?je(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},ie=(s,t)=>(e,n)=>t(e,n,s);p.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${L.SHEET}=${e}${n?`&${typeof n=="string"?L.DEFINE_NAME:L.RANGE}=${typeof n=="string"?n:C.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,i,r;if(t.startsWith("#")){const o=new URLSearchParams(t.slice(1)),d={gid:(e=o.get("gid"))!=null?e:"",range:(n=o.get("range"))!=null?n:"",rangeid:(i=o.get("rangeid"))!=null?i:"",unitid:(r=o.get("unitid"))!=null?r:""},c=this._getURLName(d);return{type:c.type,name:c.name,url:t,searchObj:d}}else return{type:L.URL,name:t,url:t,searchObj:null}}_getURLName(t){var u;const{gid:e,range:n,rangeid:i,unitid:r}=t,o=r?this._univerInstanceService.getUnit(r,a.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),d={type:L.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!o)return d;const c=e?o.getSheetBySheetId(e):o.getActiveSheet(),l=(u=c==null?void 0:c.getName())!=null?u:"";if(n){if(!c)return d;const g=C.deserializeRangeWithSheet(n).range;return a.isValidRange(g,c)&&n!==$?{type:L.RANGE,name:C.serializeRangeWithSheet(l,g)}:d}if(i){const g=this._definedNamesService.getValueById(o.getUnitId(),i);return g?{type:L.DEFINE_NAME,name:g.formulaOrRefString}:d}if(e){const g=o.getSheetBySheetId(e);return g?{type:L.SHEET,name:g.getName()}:d}return d}},p.SheetsHyperLinkParserService=Ae([ie(0,a.IUniverInstanceService),ie(1,a.Inject(a.LocaleService)),ie(2,C.IDefinedNamesService)],p.SheetsHyperLinkParserService);var xe=Object.defineProperty,We=Object.getOwnPropertyDescriptor,Be=(s,t,e)=>t in s?xe(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,Ke=(s,t,e,n)=>{for(var i=n>1?void 0:n?We(t,e):t,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=o(i)||i);return i},fe=(s,t)=>(e,n)=>t(e,n,s),ye=(s,t,e)=>Be(s,typeof t!="symbol"?t+"":t,e);p.UniverSheetsHyperLinkPlugin=class extends a.Plugin{constructor(t=ae,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...i}=a.merge({},ae,this._config);this._configService.setConfig(ke,i)}onStarting(){a.registerDependencies(this._injector,[[p.HyperLinkModel],[p.SheetsHyperLinkParserService],[X],[Z],[G],[J],[Y],[q]]),a.touchDependencies(this._injector,[[G],[X],[Z],[J],[Y],[q]])}},ye(p.UniverSheetsHyperLinkPlugin,"pluginName",oe),ye(p.UniverSheetsHyperLinkPlugin,"type",a.UniverInstanceType.UNIVER_SHEET),p.UniverSheetsHyperLinkPlugin=Ke([a.DependentOn(m.UniverSheetsPlugin),fe(1,a.Inject(a.Injector)),fe(2,a.IConfigService)],p.UniverSheetsHyperLinkPlugin),p.AddHyperLinkCommand=le,p.AddHyperLinkMutation=E,p.AddRichHyperLinkCommand=ue,p.CancelHyperLinkCommand=pe,p.CancelRichHyperLinkCommand=ge,p.ERROR_RANGE=$,p.RemoveHyperLinkMutation=w,p.SheetHyperLinkType=L,p.UpdateHyperLinkCommand=he,p.UpdateHyperLinkMutation=W,p.UpdateHyperLinkRefMutation=B,p.UpdateRichHyperLinkCommand=me,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-hyper-link",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
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.
|
|
55
|
-
"@univerjs/
|
|
56
|
-
"@univerjs/
|
|
57
|
-
"@univerjs/sheets": "0.6.
|
|
58
|
-
"@univerjs/
|
|
54
|
+
"@univerjs/protocol": "0.1.45",
|
|
55
|
+
"@univerjs/docs": "0.6.7",
|
|
56
|
+
"@univerjs/engine-formula": "0.6.7",
|
|
57
|
+
"@univerjs/sheets": "0.6.7",
|
|
58
|
+
"@univerjs/core": "0.6.7"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"rxjs": "^7.8.1",
|
|
62
62
|
"typescript": "^5.8.2",
|
|
63
|
-
"vite": "^6.2.
|
|
64
|
-
"vitest": "^3.0.
|
|
65
|
-
"@univerjs-infra/shared": "0.6.
|
|
63
|
+
"vite": "^6.2.3",
|
|
64
|
+
"vitest": "^3.0.9",
|
|
65
|
+
"@univerjs-infra/shared": "0.6.7"
|
|
66
66
|
},
|
|
67
67
|
"scripts": {
|
|
68
68
|
"test": "vitest run",
|