@univerjs/sheets-hyper-link 0.6.6 → 0.6.7-experimental.20250328-3aaa828
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/facade.js +174 -0
- package/lib/index.js +1277 -0
- package/lib/umd/index.js +1 -1
- package/package.json +9 -9
- package/LICENSE +0 -176
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,
|