@univerjs/sheets-hyper-link 0.10.10 → 0.10.11-nightly.202510220308
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 +13 -11
- package/lib/index.js +13 -11
- package/lib/umd/index.js +1 -1
- package/package.json +8 -8
- package/LICENSE +0 -176
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var ve=Object.defineProperty;var Ie=(s,t,e)=>t in s?ve(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var C=(s,t,e)=>Ie(s,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),Q=require("@univerjs/docs"),h=require("@univerjs/sheets"),Re=require("rxjs"),k=require("@univerjs/engine-formula");var Me=Object.getOwnPropertyDescriptor,Ce=(s,t,e,n)=>{for(var r=n>1?void 0:n?Me(t,e):t,i=s.length-1,a;i>=0;i--)(a=s[i])&&(r=a(r)||r);return r},ke=(s,t)=>(e,n)=>t(e,n,s);exports.HyperLinkModel=class extends o.Disposable{constructor(e){super();C(this,"_linkUpdate$",new Re.Subject);C(this,"linkUpdate$",this._linkUpdate$.asObservable());C(this,"_linkMap",new Map);C(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let r=this._linkMap.get(e);r||(r=new Map,this._linkMap.set(e,r));let i=r.get(n);i||(i=new o.ObjectMatrix,r.set(n,i));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:i,positionMap:d}}addHyperLink(e,n,r){const{matrix:i,positionMap:a}=this._ensureMap(e,n);return i.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,i,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,i),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,i,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,i),c.set(r,{...i,link:u}),d.setValue(i.row,i.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:i,id:r,type:"updateRef",silent:a}),!0}removeHyperLink(e,n,r){const{matrix:i,positionMap:a}=this._ensureMap(e,n),d=a.get(r);if(!d)return!1;a.delete(r);const c=i.getValue(d.row,d.column);return c&&c.id===r&&i.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,r){const{matrix:i,positionMap:a}=this._ensureMap(e,n),d=a.get(r);if(d)return i.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,r,i){const{matrix:a}=this._ensureMap(e,n);return a.getValue(r,i)}getHyperLinkByLocationSync(e,n,r,i){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,i),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,i);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:r}=this._ensureMap(e,n),i=[];return r.forValue((a,d,c)=>{c&&i.push(c)}),i}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(r=>{const i=this.getSubUnit(e,r);return{unitId:e,subUnitId:r,links:i}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}};exports.HyperLinkModel=Ce([ke(0,o.IUniverInstanceService)],exports.HyperLinkModel);const U={type:o.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(s,t){if(!t)return!1;const e=s.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,link:i}=t;return e.addHyperLink(n,r,i)}},w={type:o.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(s,t){if(!t)return!1;const e=s.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,id:i}=t;return e.removeHyperLink(n,r,i)}},ue={type:o.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(s,t){if(!t)return!1;const e=s.get(o.ICommandService),n=s.get(o.IUndoRedoService),r=s.get(o.IUniverInstanceService),i=s.get(exports.HyperLinkModel),a=s.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,y,_),I=v.documentModel.getSnapshot(),R=o.Tools.deepClone(I.body);if(!R)return!1;let E;if(g?E=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}):E=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}}),!E)return!1;const N=o.TextX.apply(R,E.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}}},Z={id:h.SetRangeValuesMutation.id,params:O},$=h.SetRangeValuesUndoMutationFactory(s,O),ee={id:h.SetRangeValuesMutation.id,params:$},x=[Z],H=[ee],T=i.getHyperLinkByLocation(c,l,y,_);return T&&(x.push({id:w.id,params:{unitId:c,subUnitId:l,id:T.id}}),H.push({id:U.id,params:{unitId:c,subUnitId:l,link:T}})),await o.sequenceExecute(x,e)?await a.onValidateCell(u,p,y,_)===!1?(o.sequenceExecute(H,e),!1):(n.pushUndoRedo({redoMutations:x,undoMutations:H,unitID:c}),!0):!1}},pe={id:"sheets.command.add-rich-hyper-link",type:o.CommandType.COMMAND,handler:async(s,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,r=s.get(o.ICommandService),i=o.generateRandomId(),{payload:a}=n,d=Q.addCustomRangeBySelectionFactory(s,{unitId:e,rangeId:i,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:a,refId:i}});return d?r.syncExecuteCommand(d.id,d.params):!1}},ge={type:o.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(s,t){var b,D;if(!t)return!1;const e=s.get(o.ICommandService),n=s.get(o.IUndoRedoService),r=s.get(o.IUniverInstanceService),i=s.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,d,c);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 E=h.SetRangeValuesUndoMutationFactory(s,R);I.push({id:h.SetRangeValuesMutation.id,params:E});const N=i.getHyperLinkByLocation(u,p,d,c);return N&&(v.push({id:w.id,params:{unitId:u,subUnitId:p,id:l}}),I.push({id:U.id,params:{unitId:u,subUnitId:p,link:{...N}}})),o.sequenceExecute(v,e).result?(n.pushUndoRedo({redoMutations:v,undoMutations:I,unitID:u}),!0):!1}},he={type:o.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(s,t){var u,p;if(!t)return!1;const{id:e,documentId:n}=t,r=s.get(o.ICommandService),a=s.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=Q.deleteCustomRangeFactory(s,{unitId:n,rangeId:e,insert:c});return l?r.syncExecuteCommand(l.id,l.params):!1}},me={type:o.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(s,t){var ie,se,ae;if(!t)return!1;const e=s.get(o.ICommandService),n=s.get(o.IUndoRedoService),r=s.get(o.IUniverInstanceService),i=s.get(exports.HyperLinkModel),a=s.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,l,u);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 E=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=Q.replaceSelectionFactory(s,{unitId:g,body:{dataStream:`${S}`,customRanges:[{rangeId:E,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},Z=a.onWriteCell(m,f,l,u,O),$={id:h.SetRangeValuesMutation.id,params:{unitId:g,subUnitId:y,cellValue:{[l]:{[u]:Z}}}},ee=h.SetRangeValuesUndoMutationFactory(s,$.params),x={id:h.SetRangeValuesMutation.id,params:ee},H=[$],T=[x],A=i.getHyperLinkByLocation(g,y,l,u);return A&&(H.push({id:w.id,params:{unitId:g,subUnitId:y,id:A.id}}),T.push({id:U.id,params:{unitId:g,subUnitId:y,link:A}})),o.sequenceExecute(H,e)?await a.onValidateCell(m,f,l,u)===!1?(o.sequenceExecute(T,e),!1):(n.pushUndoRedo({redoMutations:H,undoMutations:T,unitID:g}),!0):!1}},fe={type:o.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(s,t)=>{var g,y,_,S;if(!t)return!1;const{documentId:e,payload:n,id:r}=t,i=s.get(o.IUniverInstanceService),a=s.get(o.ICommandService),d=i.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=Q.replaceSelectionFactory(s,{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}},F={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(s,t){if(!t)return!1;const e=s.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,payload:i,id:a}=t;return e.updateHyperLink(n,r,a,i,!1)}},z={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(s,t){if(!t)return!1;const e=s.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,id:i,row:a,column:d,silent:c}=t;return e.updateHyperLinkRef(n,r,i,{row:a,column:d},c)}},W={type:o.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(s,t){var f,g,y;if(!t)return!1;const{unitId:e,subUnitId:n,row:r,col:i,id:a,url:d}=t,c=s.get(o.IUniverInstanceService),l=h.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:u}=l,p=u.getCellRaw(r,i),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}},Le="sheets-hyper-link.config",de={},ye="SHEET_HYPER_LINK_PLUGIN",V="err";var Ue=Object.getOwnPropertyDescriptor,we=(s,t,e,n)=>{for(var r=n>1?void 0:n?Ue(t,e):t,i=s.length-1,a;i>=0;i--)(a=s[i])&&(r=a(r)||r);return r},j=(s,t)=>(e,n)=>t(e,n,s);let K=class extends o.Disposable{constructor(t,e,n,r){super();C(this,"_disposableMap",new Map);C(this,"_watchDisposableMap",new Map);C(this,"_rangeDisableMap",new Map);C(this,"_rangeWatcherMap",new Map);C(this,"_handlePositionChange",(t,e,n,r,i)=>{const a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return r?{redos:[{id:z.id,params:{unitId:t,subUnitId:e,id:n.id,row:r.startRow,column:r.startColumn,silent:i}}],undos:[{id:z.id,params:{unitId:t,subUnitId:e,id:n.id,row:a.startRow,column:a.startColumn,silent:i}}]}:{redos:[{id:w.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:U.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=r,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const r=n.id,i={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},a=d=>{const c=h.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(i,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===i.startColumn&&l.startRow===i.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(r,this._refRangeService.registerRefRange(i,a,t,e))}_watchPosition(t,e,n){const r=n.id,i={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(r,this._refRangeService.watchRange(t,e,i,(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 i,a,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(i=c.get("gid"))!=null?i:"",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!==V){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:i,links:a}=n;a.forEach(d=>{this._registerPosition(r,i,d),this._watchPosition(r,i,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:i}=t,a=this._hyperLinkModel.getHyperLink(e,n,r);if(!a)return;this._unregisterPosition(r),this._registerPosition(e,n,a),i||(this._unwatchPosition(r),this._watchPosition(e,n,a));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:r}=n;r.forEach(i=>{this._unregisterPosition(i.id),this._unwatchPosition(i.id),this._unregisterRange(i.id),this._unwatchRange(i.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(o.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};K=we([j(0,o.Inject(h.RefRangeService)),j(1,o.Inject(exports.HyperLinkModel)),j(2,o.Inject(h.SheetsSelectionsService)),j(3,o.ICommandService)],K);var Ee=Object.getOwnPropertyDescriptor,be=(s,t,e,n)=>{for(var r=n>1?void 0:n?Ee(t,e):t,i=s.length-1,a;i>=0;i--)(a=s[i])&&(r=a(r)||r);return r},te=(s,t)=>(e,n)=>t(e,n,s);let Y=class extends o.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===h.RemoveSheetCommand.id){const e=s.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(),i=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!i)return{redos:[],undos:[]};const a=this._hyperLinkModel.getSubUnit(r,i),d=a.map(l=>({id:w.id,params:{unitId:r,subUnitId:i,id:l.id}})),c=a.map(l=>({id:U.id,params:{unitId:r,subUnitId:i,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};Y=be([te(0,o.Inject(h.SheetInterceptorService)),te(1,o.IUniverInstanceService),te(2,o.Inject(exports.HyperLinkModel))],Y);var He=Object.getOwnPropertyDescriptor,Te=(s,t,e,n)=>{for(var r=n>1?void 0:n?He(t,e):t,i=s.length-1,a;i>=0;i--)(a=s[i])&&(r=a(r)||r);return r},ne=(s,t)=>(e,n)=>t(e,n,s);let q=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,i,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:(i=d.get("range"))!=null?i:"",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!==V)return{range:p,worksheet:u}}}return null}_registerRange(t,e,n,r,i){var d,c,l,u;const a=this._enusreMap(t,e);if((c=(d=i.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=i.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:W.id,params:{unitId:t,subUnitId:e,row:n,col:r,id:f.rangeId,url:`#gid=${e}&range=${I?k.serializeRange(I):V}`}}],undos:[{id:W.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 i=r.getSheetId(),a=this._enusreMap(n,i);r.getCellMatrix().forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,i,d,c,l.p)})})};this._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 i=r.getSheetId();this._enusreMap(n,i).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:i}=e,a=this._enusreMap(n,r);i&&new o.ObjectMatrix(i).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===W.id){const e=t.params,{unitId:n,subUnitId:r,row:i,col:a}=e,d=h.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:r}),l=this._enusreMap(n,r).getValue(i,a);if(l&&l.dispose(),d){const{worksheet:u}=d,p=u.getCellRaw(i,a);p&&p.p&&this._registerRange(n,r,i,a,p.p)}}}))}};q=Te([ne(0,o.ICommandService),ne(1,o.IUniverInstanceService),ne(2,o.Inject(h.RefRangeService))],q);var Pe=Object.getOwnPropertyDescriptor,De=(s,t,e,n)=>{for(var r=n>1?void 0:n?Pe(t,e):t,i=s.length-1,a;i>=0;i--)(a=s[i])&&(r=a(r)||r);return r},B=(s,t)=>(e,n)=>t(e,n,s);let G=class extends o.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===h.SetRangeValuesCommand.id){const t=s.params,{unitId:e,subUnitId:n}=t,r=[],i=[];return t.cellValue&&new o.ObjectMatrix(t.cellValue).forValue((a,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,a,d);c&&(r.push({id:w.id,params:{unitId:e,subUnitId:n,id:c.id}}),i.push({id:U.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:i,redos:r}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:s=>{if(s.id===h.ClearSelectionContentCommand.id||s.id===h.ClearSelectionAllCommand.id||s.id===h.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),r=h.getSheetCommandTarget(this._univerInstanceService);if(n&&r){const{unitId:i,subUnitId:a}=r;o.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(i,a,d,c);l&&(t.push({id:w.id,params:{unitId:i,subUnitId:a,id:l.id}}),e.push({id:U.id,params:{unitId:i,subUnitId:a,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(h.AFTER_CELL_EDIT,{handler:(s,t,e)=>{if(!s||s.p)return e(s);if(typeof s.v=="string"&&o.Tools.isLegalUrl(s.v)&&s.v[s.v.length-1]!==" "){const{unitId:n,subUnitId:r,row:i,col:a}=t,d=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET),c=d==null?void 0:d.getSheetBySheetId(r);if(!c)return e(s);const l=c.getBlankCellDocumentModel(s,i,a);if(!l.documentModel)return e(s);const u=o.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:o.generateRandomId(),rangeType:o.CustomRangeType.HYPERLINK,properties:{url:s.v}}]},doc:l.documentModel});if(!u)return e(s);const p=l.documentModel.getBody();return o.TextX.apply(p,u.serialize()),e({...s,p:{id:o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:p,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(s)}}))}};G=De([B(0,o.Inject(h.SheetInterceptorService)),B(1,o.Inject(exports.HyperLinkModel)),B(2,o.Inject(h.SheetsSelectionsService)),B(3,o.IUniverInstanceService)],G);var Oe=Object.getOwnPropertyDescriptor,Ne=(s,t,e,n)=>{for(var r=n>1?void 0:n?Oe(t,e):t,i=s.length-1,a;i>=0;i--)(a=s[i])&&(r=a(r)||r);return r},ce=(s,t)=>(e,n)=>t(e,n,s);let X=class extends o.Disposable{constructor(s,t){super(),this._resourceManagerService=s,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const s=e=>{const n=this._hyperLinkModel.getUnit(e),r={};return n?(n.forEach(i=>{r[i.subUnitId]=i.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:ye,businesses:[o.UniverInstanceType.UNIVER_SHEET],toJson:e=>s(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(r=>{n[r].forEach(a=>{this._hyperLinkModel.addHyperLink(e,r,a)})})}}))}};X=Ne([ce(0,o.IResourceManagerService),ce(1,o.Inject(exports.HyperLinkModel))],X);var xe=Object.getOwnPropertyDescriptor,Ve=(s,t,e,n)=>{for(var r=n>1?void 0:n?xe(t,e):t,i=s.length-1,a;i>=0;i--)(a=s[i])&&(r=a(r)||r);return r},$e=(s,t)=>(e,n)=>t(e,n,s);let J=class extends o.Disposable{constructor(s){super(),this._commandService=s,this._registerCommands()}_registerCommands(){[ue,me,ge,fe,he,pe,U,F,w,z,W].forEach(s=>{this._commandService.registerCommand(s)})}};J=Ve([$e(0,o.ICommandService)],J);var L=(s=>(s.SHEET="gid",s.RANGE="range",s.DEFINE_NAME="rangeid",s.INVALID="invalid",s.URL="url",s))(L||{}),Ae=Object.getOwnPropertyDescriptor,je=(s,t,e,n)=>{for(var r=n>1?void 0:n?Ae(t,e):t,i=s.length-1,a;i>=0;i--)(a=s[i])&&(r=a(r)||r);return r},re=(s,t)=>(e,n)=>t(e,n,s);exports.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${L.SHEET}=${e}${n?`&${typeof n=="string"?L.DEFINE_NAME:L.RANGE}=${typeof n=="string"?n:k.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,r,i;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:(i=a.get("unitid"))!=null?i:""},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:r,unitid:i}=t,a=i?this._univerInstanceService.getUnit(i,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),d={type:L.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!a)return d;const c=e?a.getSheetBySheetId(e):a.getActiveSheet(),l=(u=c==null?void 0:c.getName())!=null?u:"";if(n){if(!c)return d;const p=k.deserializeRangeWithSheet(n).range;return o.isValidRange(p,c)&&n!==V?{type:L.RANGE,name:k.serializeRangeWithSheet(l,p)}:d}if(r){const p=this._definedNamesService.getValueById(a.getUnitId(),r);return p?{type:L.DEFINE_NAME,name:p.formulaOrRefString}:d}if(e){const p=a.getSheetBySheetId(e);return p?{type:L.SHEET,name:p.getName()}:d}return d}};exports.SheetsHyperLinkParserService=je([re(0,o.IUniverInstanceService),re(1,o.Inject(o.LocaleService)),re(2,k.IDefinedNamesService)],exports.SheetsHyperLinkParserService);var Be=Object.defineProperty,We=Object.getOwnPropertyDescriptor,Fe=(s,t,e)=>t in s?Be(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,ze=(s,t,e,n)=>{for(var r=n>1?void 0:n?We(t,e):t,i=s.length-1,a;i>=0;i--)(a=s[i])&&(r=a(r)||r);return r},le=(s,t)=>(e,n)=>t(e,n,s),_e=(s,t,e)=>Fe(s,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],[X],[J],[K],[G],[Y],[q]]),o.touchDependencies(this._injector,[[K],[X],[J],[G],[Y],[q]])}};_e(exports.UniverSheetsHyperLinkPlugin,"pluginName",ye);_e(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=ue;exports.AddHyperLinkMutation=U;exports.AddRichHyperLinkCommand=pe;exports.CancelHyperLinkCommand=ge;exports.CancelRichHyperLinkCommand=he;exports.ERROR_RANGE=V;exports.RemoveHyperLinkMutation=w;exports.SheetHyperLinkType=L;exports.UpdateHyperLinkCommand=me;exports.UpdateHyperLinkMutation=F;exports.UpdateHyperLinkRefMutation=z;exports.UpdateRichHyperLinkCommand=fe;
|
|
1
|
+
"use strict";var ve=Object.defineProperty;var Ie=(s,t,e)=>t in s?ve(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var C=(s,t,e)=>Ie(s,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),Q=require("@univerjs/docs"),h=require("@univerjs/sheets"),Re=require("rxjs"),k=require("@univerjs/engine-formula");var Me=Object.getOwnPropertyDescriptor,Ce=(s,t,e,n)=>{for(var r=n>1?void 0:n?Me(t,e):t,i=s.length-1,a;i>=0;i--)(a=s[i])&&(r=a(r)||r);return r},ke=(s,t)=>(e,n)=>t(e,n,s);exports.HyperLinkModel=class extends o.Disposable{constructor(e){super();C(this,"_linkUpdate$",new Re.Subject);C(this,"linkUpdate$",this._linkUpdate$.asObservable());C(this,"_linkMap",new Map);C(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let r=this._linkMap.get(e);r||(r=new Map,this._linkMap.set(e,r));let i=r.get(n);i||(i=new o.ObjectMatrix,r.set(n,i));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:i,positionMap:d}}addHyperLink(e,n,r){const{matrix:i,positionMap:a}=this._ensureMap(e,n);return i.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,i,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,i),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,i,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,i),c.set(r,{...i,link:u}),d.setValue(i.row,i.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:i,id:r,type:"updateRef",silent:a}),!0}removeHyperLink(e,n,r){const{matrix:i,positionMap:a}=this._ensureMap(e,n),d=a.get(r);if(!d)return!1;a.delete(r);const c=i.getValue(d.row,d.column);return c&&c.id===r&&i.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,r){const{matrix:i,positionMap:a}=this._ensureMap(e,n),d=a.get(r);if(d)return i.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,r,i){const{matrix:a}=this._ensureMap(e,n);return a.getValue(r,i)}getHyperLinkByLocationSync(e,n,r,i){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,i),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,i);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:r}=this._ensureMap(e,n),i=[];return r.forValue((a,d,c)=>{c&&i.push(c)}),i}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(r=>{const i=this.getSubUnit(e,r);return{unitId:e,subUnitId:r,links:i}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}};exports.HyperLinkModel=Ce([ke(0,o.IUniverInstanceService)],exports.HyperLinkModel);const U={type:o.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(s,t){if(!t)return!1;const e=s.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,link:i}=t;return e.addHyperLink(n,r,i)}},w={type:o.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(s,t){if(!t)return!1;const e=s.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,id:i}=t;return e.removeHyperLink(n,r,i)}},ue={type:o.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(s,t){if(!t)return!1;const e=s.get(o.ICommandService),n=s.get(o.IUndoRedoService),r=s.get(o.IUniverInstanceService),i=s.get(exports.HyperLinkModel),a=s.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,y,_),I=v.documentModel.getSnapshot(),R=o.Tools.deepClone(I.body);if(!R)return!1;let E;if(g?E=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}):E=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}}),!E)return!1;const N=o.TextX.apply(R,E.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}}},Z={id:h.SetRangeValuesMutation.id,params:O},$=h.SetRangeValuesUndoMutationFactory(s,O),ee={id:h.SetRangeValuesMutation.id,params:$},x=[Z],H=[ee],T=i.getHyperLinkByLocation(c,l,y,_);return T&&(x.push({id:w.id,params:{unitId:c,subUnitId:l,id:T.id}}),H.push({id:U.id,params:{unitId:c,subUnitId:l,link:T}})),await o.sequenceExecute(x,e)?await a.onValidateCell(u,p,y,_)===!1?(o.sequenceExecute(H,e),!1):(n.pushUndoRedo({redoMutations:x,undoMutations:H,unitID:c}),!0):!1}},pe={id:"sheets.command.add-rich-hyper-link",type:o.CommandType.COMMAND,handler:async(s,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,r=s.get(o.ICommandService),i=o.generateRandomId(),{payload:a}=n,d=Q.addCustomRangeBySelectionFactory(s,{unitId:e,rangeId:i,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:a,refId:i}});return d?r.syncExecuteCommand(d.id,d.params):!1}},ge={type:o.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(s,t){var b,D;if(!t)return!1;const e=s.get(o.ICommandService),n=s.get(o.IUndoRedoService),r=s.get(o.IUniverInstanceService),i=s.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,d,c);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 E=h.SetRangeValuesUndoMutationFactory(s,R);I.push({id:h.SetRangeValuesMutation.id,params:E});const N=i.getHyperLinkByLocation(u,p,d,c);return N&&(v.push({id:w.id,params:{unitId:u,subUnitId:p,id:l}}),I.push({id:U.id,params:{unitId:u,subUnitId:p,link:{...N}}})),o.sequenceExecute(v,e).result?(n.pushUndoRedo({redoMutations:v,undoMutations:I,unitID:u}),!0):!1}},he={type:o.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(s,t){var u,p;if(!t)return!1;const{id:e,documentId:n}=t,r=s.get(o.ICommandService),a=s.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=Q.deleteCustomRangeFactory(s,{unitId:n,rangeId:e,insert:c});return l?r.syncExecuteCommand(l.id,l.params):!1}},me={type:o.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(s,t){var ie,se,ae;if(!t)return!1;const e=s.get(o.ICommandService),n=s.get(o.IUndoRedoService),r=s.get(o.IUniverInstanceService),i=s.get(exports.HyperLinkModel),a=s.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,l,u);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 E=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=Q.replaceSelectionFactory(s,{unitId:g,body:{dataStream:`${S}`,customRanges:[{rangeId:E,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},Z=a.onWriteCell(m,f,l,u,O),$={id:h.SetRangeValuesMutation.id,params:{unitId:g,subUnitId:y,cellValue:{[l]:{[u]:Z}}}},ee=h.SetRangeValuesUndoMutationFactory(s,$.params),x={id:h.SetRangeValuesMutation.id,params:ee},H=[$],T=[x],A=i.getHyperLinkByLocation(g,y,l,u);return A&&(H.push({id:w.id,params:{unitId:g,subUnitId:y,id:A.id}}),T.push({id:U.id,params:{unitId:g,subUnitId:y,link:A}})),o.sequenceExecute(H,e)?await a.onValidateCell(m,f,l,u)===!1?(o.sequenceExecute(T,e),!1):(n.pushUndoRedo({redoMutations:H,undoMutations:T,unitID:g}),!0):!1}},fe={type:o.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(s,t)=>{var g,y,_,S;if(!t)return!1;const{documentId:e,payload:n,id:r}=t,i=s.get(o.IUniverInstanceService),a=s.get(o.ICommandService),d=i.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=Q.replaceSelectionFactory(s,{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}},F={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(s,t){if(!t)return!1;const e=s.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,payload:i,id:a}=t;return e.updateHyperLink(n,r,a,i,!1)}},z={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(s,t){if(!t)return!1;const e=s.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,id:i,row:a,column:d,silent:c}=t;return e.updateHyperLinkRef(n,r,i,{row:a,column:d},c)}},B={type:o.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(s,t){var f,g,y;if(!t)return!1;const{unitId:e,subUnitId:n,row:r,col:i,id:a,url:d}=t,c=s.get(o.IUniverInstanceService),l=h.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:u}=l,p=u.getCellRaw(r,i),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}},Le="sheets-hyper-link.config",de={},ye="SHEET_HYPER_LINK_PLUGIN",V="err";var Ue=Object.getOwnPropertyDescriptor,we=(s,t,e,n)=>{for(var r=n>1?void 0:n?Ue(t,e):t,i=s.length-1,a;i>=0;i--)(a=s[i])&&(r=a(r)||r);return r},j=(s,t)=>(e,n)=>t(e,n,s);let K=class extends o.Disposable{constructor(t,e,n,r){super();C(this,"_disposableMap",new Map);C(this,"_watchDisposableMap",new Map);C(this,"_rangeDisableMap",new Map);C(this,"_rangeWatcherMap",new Map);C(this,"_handlePositionChange",(t,e,n,r,i)=>{const a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return r?{redos:[{id:z.id,params:{unitId:t,subUnitId:e,id:n.id,row:r.startRow,column:r.startColumn,silent:i}}],undos:[{id:z.id,params:{unitId:t,subUnitId:e,id:n.id,row:a.startRow,column:a.startColumn,silent:i}}]}:{redos:[{id:w.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:U.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=r,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const r=n.id,i={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},a=d=>{const c=h.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(i,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===i.startColumn&&l.startRow===i.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(r,this._refRangeService.registerRefRange(i,a,t,e))}_watchPosition(t,e,n){const r=n.id,i={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(r,this._refRangeService.watchRange(t,e,i,(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 i,a,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(i=c.get("gid"))!=null?i:"",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!==V){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:i,links:a}=n;a.forEach(d=>{this._registerPosition(r,i,d),this._watchPosition(r,i,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:i}=t,a=this._hyperLinkModel.getHyperLink(e,n,r);if(!a)return;this._unregisterPosition(r),this._registerPosition(e,n,a),i||(this._unwatchPosition(r),this._watchPosition(e,n,a));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:r}=n;r.forEach(i=>{this._unregisterPosition(i.id),this._unwatchPosition(i.id),this._unregisterRange(i.id),this._unwatchRange(i.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(o.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};K=we([j(0,o.Inject(h.RefRangeService)),j(1,o.Inject(exports.HyperLinkModel)),j(2,o.Inject(h.SheetsSelectionsService)),j(3,o.ICommandService)],K);var Ee=Object.getOwnPropertyDescriptor,be=(s,t,e,n)=>{for(var r=n>1?void 0:n?Ee(t,e):t,i=s.length-1,a;i>=0;i--)(a=s[i])&&(r=a(r)||r);return r},te=(s,t)=>(e,n)=>t(e,n,s);let Y=class extends o.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===h.RemoveSheetCommand.id){const e=s.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(),i=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!i)return{redos:[],undos:[]};const a=this._hyperLinkModel.getSubUnit(r,i),d=a.map(l=>({id:w.id,params:{unitId:r,subUnitId:i,id:l.id}})),c=a.map(l=>({id:U.id,params:{unitId:r,subUnitId:i,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};Y=be([te(0,o.Inject(h.SheetInterceptorService)),te(1,o.IUniverInstanceService),te(2,o.Inject(exports.HyperLinkModel))],Y);var He=Object.getOwnPropertyDescriptor,Te=(s,t,e,n)=>{for(var r=n>1?void 0:n?He(t,e):t,i=s.length-1,a;i>=0;i--)(a=s[i])&&(r=a(r)||r);return r},ne=(s,t)=>(e,n)=>t(e,n,s);let q=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,i,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:(i=d.get("range"))!=null?i:"",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!==V)return{range:p,worksheet:u}}}return null}_registerRange(t,e,n,r,i){var d,c,l,u;const a=this._enusreMap(t,e);if((c=(d=i.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=i.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):V}`}}],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 i=r.getSheetId(),a=this._enusreMap(n,i);r.getCellMatrix().forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,i,d,c,l.p)})})};this._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.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===o.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(r=>{const i=r.getSheetId();this._enusreMap(n,i).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:i}=e,a=this._enusreMap(n,r);i&&new o.ObjectMatrix(i).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:i,col:a}=e,d=h.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:r}),l=this._enusreMap(n,r).getValue(i,a);if(l&&l.dispose(),d){const{worksheet:u}=d,p=u.getCellRaw(i,a);p&&p.p&&this._registerRange(n,r,i,a,p.p)}}}))}};q=Te([ne(0,o.ICommandService),ne(1,o.IUniverInstanceService),ne(2,o.Inject(h.RefRangeService))],q);var Pe=Object.getOwnPropertyDescriptor,De=(s,t,e,n)=>{for(var r=n>1?void 0:n?Pe(t,e):t,i=s.length-1,a;i>=0;i--)(a=s[i])&&(r=a(r)||r);return r},W=(s,t)=>(e,n)=>t(e,n,s);let G=class extends o.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===h.SetRangeValuesCommand.id){const t=s.params,{unitId:e,subUnitId:n}=t,r=[],i=[];return t.cellValue&&new o.ObjectMatrix(t.cellValue).forValue((a,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,a,d);c&&(r.push({id:w.id,params:{unitId:e,subUnitId:n,id:c.id}}),i.push({id:U.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:i,redos:r}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:s=>{if(s.id===h.ClearSelectionContentCommand.id||s.id===h.ClearSelectionAllCommand.id||s.id===h.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),r=h.getSheetCommandTarget(this._univerInstanceService);if(n&&r){const{unitId:i,subUnitId:a}=r;o.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(i,a,d,c);l&&(t.push({id:w.id,params:{unitId:i,subUnitId:a,id:l.id}}),e.push({id:U.id,params:{unitId:i,subUnitId:a,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(h.AFTER_CELL_EDIT,{handler:(s,t,e)=>{if(!s||s.p)return e(s);if(typeof s.v=="string"&&o.Tools.isLegalUrl(s.v)&&s.v[s.v.length-1]!==" "){const{unitId:n,subUnitId:r,row:i,col:a}=t,d=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET),c=d==null?void 0:d.getSheetBySheetId(r);if(!c)return e(s);const l=c.getBlankCellDocumentModel(s,i,a);if(!l.documentModel)return e(s);const u=o.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:o.generateRandomId(),rangeType:o.CustomRangeType.HYPERLINK,properties:{url:s.v}}]},doc:l.documentModel});if(!u)return e(s);const p=l.documentModel.getBody();return o.TextX.apply(p,u.serialize()),e({...s,p:{id:o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:p,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(s)}}))}};G=De([W(0,o.Inject(h.SheetInterceptorService)),W(1,o.Inject(exports.HyperLinkModel)),W(2,o.Inject(h.SheetsSelectionsService)),W(3,o.IUniverInstanceService)],G);var Oe=Object.getOwnPropertyDescriptor,Ne=(s,t,e,n)=>{for(var r=n>1?void 0:n?Oe(t,e):t,i=s.length-1,a;i>=0;i--)(a=s[i])&&(r=a(r)||r);return r},ce=(s,t)=>(e,n)=>t(e,n,s);let X=class extends o.Disposable{constructor(s,t){super(),this._resourceManagerService=s,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const s=e=>{const n=this._hyperLinkModel.getUnit(e),r={};return n?(n.forEach(i=>{r[i.subUnitId]=i.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:ye,businesses:[o.UniverInstanceType.UNIVER_SHEET],toJson:e=>s(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(r=>{n[r].forEach(a=>{this._hyperLinkModel.addHyperLink(e,r,a)})})}}))}};X=Ne([ce(0,o.IResourceManagerService),ce(1,o.Inject(exports.HyperLinkModel))],X);var xe=Object.getOwnPropertyDescriptor,Ve=(s,t,e,n)=>{for(var r=n>1?void 0:n?xe(t,e):t,i=s.length-1,a;i>=0;i--)(a=s[i])&&(r=a(r)||r);return r},$e=(s,t)=>(e,n)=>t(e,n,s);let J=class extends o.Disposable{constructor(s){super(),this._commandService=s,this._registerCommands()}_registerCommands(){[ue,me,ge,fe,he,pe,U,F,w,z,B].forEach(s=>{this._commandService.registerCommand(s)})}};J=Ve([$e(0,o.ICommandService)],J);var L=(s=>(s.SHEET="gid",s.RANGE="range",s.DEFINE_NAME="rangeid",s.INVALID="invalid",s.URL="url",s))(L||{}),Ae=Object.getOwnPropertyDescriptor,je=(s,t,e,n)=>{for(var r=n>1?void 0:n?Ae(t,e):t,i=s.length-1,a;i>=0;i--)(a=s[i])&&(r=a(r)||r);return r},re=(s,t)=>(e,n)=>t(e,n,s);exports.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${L.SHEET}=${e}${n?`&${typeof n=="string"?L.DEFINE_NAME:L.RANGE}=${typeof n=="string"?n:k.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,r,i;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:(i=a.get("unitid"))!=null?i:""},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:r,unitid:i}=t,a=i?this._univerInstanceService.getUnit(i,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),d={type:L.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!a)return d;const c=e?a.getSheetBySheetId(e):a.getActiveSheet(),l=(u=c==null?void 0:c.getName())!=null?u:"";if(n){if(!c)return d;const p=k.deserializeRangeWithSheet(n).range;return o.isValidRange(p,c)&&n!==V?{type:L.RANGE,name:k.serializeRangeWithSheet(l,p)}:d}if(r){const p=this._definedNamesService.getValueById(a.getUnitId(),r);return p?{type:L.DEFINE_NAME,name:p.formulaOrRefString}:d}if(e){const p=a.getSheetBySheetId(e);return p?{type:L.SHEET,name:p.getName()}:d}return d}};exports.SheetsHyperLinkParserService=je([re(0,o.IUniverInstanceService),re(1,o.Inject(o.LocaleService)),re(2,k.IDefinedNamesService)],exports.SheetsHyperLinkParserService);var We=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,Fe=(s,t,e)=>t in s?We(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e,ze=(s,t,e,n)=>{for(var r=n>1?void 0:n?Be(t,e):t,i=s.length-1,a;i>=0;i--)(a=s[i])&&(r=a(r)||r);return r},le=(s,t)=>(e,n)=>t(e,n,s),_e=(s,t,e)=>Fe(s,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],[X],[J],[K],[G],[Y],[q]]),o.touchDependencies(this._injector,[[K],[X],[J],[G],[Y],[q]])}};_e(exports.UniverSheetsHyperLinkPlugin,"pluginName",ye);_e(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=ue;exports.AddHyperLinkMutation=U;exports.AddRichHyperLinkCommand=pe;exports.CancelHyperLinkCommand=ge;exports.CancelRichHyperLinkCommand=he;exports.ERROR_RANGE=V;exports.RemoveHyperLinkMutation=w;exports.SheetHyperLinkType=L;exports.UpdateHyperLinkCommand=me;exports.UpdateHyperLinkMutation=F;exports.UpdateHyperLinkRefMutation=z;exports.UpdateRichHyperLinkCommand=fe;
|
package/lib/es/index.js
CHANGED
|
@@ -877,17 +877,19 @@ let re = class extends T {
|
|
|
877
877
|
);
|
|
878
878
|
}
|
|
879
879
|
_initWorkbookUnload() {
|
|
880
|
-
this.
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
880
|
+
this.disposeWithMe(
|
|
881
|
+
this._univerInstanceService.unitDisposed$.subscribe((e) => {
|
|
882
|
+
if (e.type === I.UNIVER_SHEET) {
|
|
883
|
+
const t = e, n = t.getUnitId();
|
|
884
|
+
t.getSheets().forEach((r) => {
|
|
885
|
+
const i = r.getSheetId();
|
|
886
|
+
this._enusreMap(n, i).forValue((o, c, d) => {
|
|
887
|
+
d && d.dispose();
|
|
888
|
+
});
|
|
889
|
+
}), this._refRangeMap.delete(n);
|
|
890
|
+
}
|
|
891
|
+
})
|
|
892
|
+
);
|
|
891
893
|
}
|
|
892
894
|
_initSetRangesListener() {
|
|
893
895
|
this.disposeWithMe(
|
package/lib/index.js
CHANGED
|
@@ -877,17 +877,19 @@ let re = class extends T {
|
|
|
877
877
|
);
|
|
878
878
|
}
|
|
879
879
|
_initWorkbookUnload() {
|
|
880
|
-
this.
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
880
|
+
this.disposeWithMe(
|
|
881
|
+
this._univerInstanceService.unitDisposed$.subscribe((e) => {
|
|
882
|
+
if (e.type === I.UNIVER_SHEET) {
|
|
883
|
+
const t = e, n = t.getUnitId();
|
|
884
|
+
t.getSheets().forEach((r) => {
|
|
885
|
+
const i = r.getSheetId();
|
|
886
|
+
this._enusreMap(n, i).forValue((o, c, d) => {
|
|
887
|
+
d && d.dispose();
|
|
888
|
+
});
|
|
889
|
+
}), this._refRangeMap.delete(n);
|
|
890
|
+
}
|
|
891
|
+
})
|
|
892
|
+
);
|
|
891
893
|
}
|
|
892
894
|
_initSetRangesListener() {
|
|
893
895
|
this.disposeWithMe(
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(g,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/docs"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs","@univerjs/sheets","rxjs","@univerjs/engine-formula"],a):(g=typeof globalThis<"u"?globalThis:g||self,a(g.UniverSheetsHyperLink={},g.UniverCore,g.UniverDocs,g.UniverSheets,g.rxjs,g.UniverEngineFormula))})(this,(function(g,a,w,m,Se,C){"use strict";var Ke=Object.defineProperty;var Ye=(g,a,w)=>a in g?Ke(g,a,{enumerable:!0,configurable:!0,writable:!0,value:w}):g[a]=w;var L=(g,a,w)=>Ye(g,typeof a!="symbol"?a+"":a,w);var Ie=Object.getOwnPropertyDescriptor,Re=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ie(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},Me=(r,t)=>(e,n)=>t(e,n,r);g.HyperLinkModel=class extends a.Disposable{constructor(e){super();L(this,"_linkUpdate$",new Se.Subject);L(this,"linkUpdate$",this._linkUpdate$.asObservable());L(this,"_linkMap",new Map);L(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let i=this._linkMap.get(e);i||(i=new Map,this._linkMap.set(e,i));let s=i.get(n);s||(s=new a.ObjectMatrix,i.set(n,s));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:s,positionMap:d}}addHyperLink(e,n,i){const{matrix:s,positionMap:o}=this._ensureMap(e,n);return s.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,s,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,s),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,s,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,s),c.set(i,{...s,link:u}),d.setValue(s.row,s.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:i,type:"updateRef",silent:o}),!0}removeHyperLink(e,n,i){const{matrix:s,positionMap:o}=this._ensureMap(e,n),d=o.get(i);if(!d)return!1;o.delete(i);const c=s.getValue(d.row,d.column);return c&&c.id===i&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,i){const{matrix:s,positionMap:o}=this._ensureMap(e,n),d=o.get(i);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,i,s){const{matrix:o}=this._ensureMap(e,n);return o.getValue(i,s)}getHyperLinkByLocationSync(e,n,i,s){var p,f,y,h,_;const{matrix:o}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,a.UniverInstanceType.UNIVER_SHEET),c=(p=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:p.getCellRaw(i,s),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,s);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:i}=this._ensureMap(e,n),s=[];return i.forValue((o,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(i=>{const s=this.getSubUnit(e,i);return{unitId:e,subUnitId:i,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}},g.HyperLinkModel=Re([Me(0,a.IUniverInstanceService)],g.HyperLinkModel);const E={type:a.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(g.HyperLinkModel),{unitId:n,subUnitId:i,link:s}=t;return e.addHyperLink(n,i,s)}},T={type:a.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(g.HyperLinkModel),{unitId:n,subUnitId:i,id:s}=t;return e.removeHyperLink(n,i,s)}},re={type:a.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(r,t){if(!t)return!1;const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService),s=r.get(g.HyperLinkModel),o=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:u,worksheet:p}=d,{link:f}=t,{payload:y,display:h,row:_,column:v,id:S}=f,k=p.getCell(_,v),I=p.getBlankCellDocumentModel(k,_,v),R=I.documentModel.getSnapshot(),M=a.Tools.deepClone(R.body);if(!M)return!1;let H;if(h?H=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}):H=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}}),!H)return!1;const j=a.TextX.apply(M,H.serialize()),b={p:{...R,body:j},t:a.CellValueType.STRING},N=o.onWriteCell(u,p,_,v,b),V={unitId:c,subUnitId:l,cellValue:{[f.row]:{[f.column]:N}}},ie={id:m.SetRangeValuesMutation.id,params:V},Q=m.SetRangeValuesUndoMutationFactory(r,V),se={id:m.SetRangeValuesMutation.id,params:Q},A=[ie],P=[se],D=s.getHyperLinkByLocation(c,l,_,v);return D&&(A.push({id:T.id,params:{unitId:c,subUnitId:l,id:D.id}}),P.push({id:E.id,params:{unitId:c,subUnitId:l,link:D}})),await a.sequenceExecute(A,e)?await o.onValidateCell(u,p,_,v)===!1?(a.sequenceExecute(P,e),!1):(n.pushUndoRedo({redoMutations:A,undoMutations:P,unitID:c}),!0):!1}},ae={id:"sheets.command.add-rich-hyper-link",type:a.CommandType.COMMAND,handler:async(r,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,i=r.get(a.ICommandService),s=a.generateRandomId(),{payload:o}=n,d=w.addCustomRangeBySelectionFactory(r,{unitId:e,rangeId:s,rangeType:a.CustomRangeType.HYPERLINK,properties:{url:o,refId:s}});return d?i.syncExecuteCommand(d.id,d.params):!1}},oe={type:a.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(r,t){var b,N;if(!t)return!1;const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService),s=r.get(g.HyperLinkModel),o=m.getSheetCommandTarget(i,t);if(!o)return!1;const{row:d,column:c,id:l}=t,{unitId:u,subUnitId:p,worksheet:f}=o,y=f.getCell(d,c);if(!y)return!1;const h=f.getCellDocumentModelWithFormula(y,d,c);if(!(h!=null&&h.documentModel))return!1;const _=a.Tools.deepClone(h.documentModel.getSnapshot()),v=(N=(b=_.body)==null?void 0:b.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:p,cellValue:{[d]:{[c]:{p:{..._,body:k},t:a.CellValueType.STRING}}}};I.push({id:m.SetRangeValuesMutation.id,params:M});const H=m.SetRangeValuesUndoMutationFactory(r,M);R.push({id:m.SetRangeValuesMutation.id,params:H});const j=s.getHyperLinkByLocation(u,p,d,c);return j&&(I.push({id:T.id,params:{unitId:u,subUnitId:p,id:l}}),R.push({id:E.id,params:{unitId:u,subUnitId:p,link:{...j}}})),a.sequenceExecute(I,e).result?(n.pushUndoRedo({redoMutations:I,undoMutations:R,unitID:u}),!0):!1}},de={type:a.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(r,t){var u,p;if(!t)return!1;const{id:e,documentId:n}=t,i=r.get(a.ICommandService),o=r.get(a.IUniverInstanceService).getUnit(n,a.UniverInstanceType.UNIVER_DOC),d=(p=(u=o==null?void 0:o.getBody())==null?void 0:u.customRanges)==null?void 0:p.find(f=>f.rangeId===e);let c=null;d&&d.endIndex===o.getBody().dataStream.length-3&&(c={dataStream:" "});const l=w.deleteCustomRangeFactory(r,{unitId:n,rangeId:e,insert:c});return l?i.syncExecuteCommand(l.id,l.params):!1}},ce={type:a.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(r,t){var fe,ye,_e;if(!t)return!1;const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService),s=r.get(g.HyperLinkModel),o=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:u,id:p}=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,l,u);if(!(I!=null&&I.documentModel))return!1;const R=I.documentModel.getSnapshot(),M=(ye=(fe=R.body)==null?void 0:fe.customRanges)==null?void 0:ye.find(ve=>`${ve.rangeId}`===p);if(!M)return!1;const H=a.generateRandomId(),O=(_e=a.getBodySlice(I.documentModel.getBody(),M.startIndex,M.endIndex+1).textRuns)==null?void 0:_e[0];O&&(O.ed=S.length+1);const b=w.replaceSelectionFactory(r,{unitId:h,body:{dataStream:`${S}`,customRanges:[{rangeId:H,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(!b)return!1;const N=a.TextX.apply(a.Tools.deepClone(R.body),b.textX.serialize()),V={p:{...R,body:N},t:a.CellValueType.STRING},ie=o.onWriteCell(f,y,l,u,V),Q={id:m.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:_,cellValue:{[l]:{[u]:ie}}}},se=m.SetRangeValuesUndoMutationFactory(r,Q.params),A={id:m.SetRangeValuesMutation.id,params:se},P=[Q],D=[A],Z=s.getHyperLinkByLocation(h,_,l,u);return Z&&(P.push({id:T.id,params:{unitId:h,subUnitId:_,id:Z.id}}),D.push({id:E.id,params:{unitId:h,subUnitId:_,link:Z}})),a.sequenceExecute(P,e)?await o.onValidateCell(f,y,l,u)===!1?(a.sequenceExecute(D,e),!1):(n.pushUndoRedo({redoMutations:P,undoMutations:D,unitID:h}),!0):!1}},le={type:a.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(r,t)=>{var h,_,v,S;if(!t)return!1;const{documentId:e,payload:n,id:i}=t,s=r.get(a.IUniverInstanceService),o=r.get(a.ICommandService),d=s.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=w.replaceSelectionFactory(r,{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}},x={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(g.HyperLinkModel),{unitId:n,subUnitId:i,payload:s,id:o}=t;return e.updateHyperLink(n,i,o,s,!1)}},B={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(r,t){if(!t)return!1;const e=r.get(g.HyperLinkModel),{unitId:n,subUnitId:i,id:s,row:o,column:d,silent:c}=t;return e.updateHyperLinkRef(n,i,s,{row:o,column:d},c)}},W={type:a.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(r,t){var y,h,_;if(!t)return!1;const{unitId:e,subUnitId:n,row:i,col:s,id:o,url:d}=t,c=r.get(a.IUniverInstanceService),l=m.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:u}=l,p=u.getCellRaw(i,s),f=(_=(h=(y=p==null?void 0:p.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}},Ce="sheets-hyper-link.config",ue={},pe="SHEET_HYPER_LINK_PLUGIN",$="err";var ke=Object.getOwnPropertyDescriptor,Le=(r,t,e,n)=>{for(var i=n>1?void 0:n?ke(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},z=(r,t)=>(e,n)=>t(e,n,r);let K=class extends a.Disposable{constructor(t,e,n,i){super();L(this,"_disposableMap",new Map);L(this,"_watchDisposableMap",new Map);L(this,"_rangeDisableMap",new Map);L(this,"_rangeWatcherMap",new Map);L(this,"_handlePositionChange",(t,e,n,i,s)=>{const 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:s}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,id:n.id,row:o.startRow,column:o.startColumn,silent:s}}]}:{redos:[{id:T.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:E.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=i,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},o=d=>{const c=m.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===s.startColumn&&l.startRow===s.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(i,this._refRangeService.registerRefRange(s,o,t,e))}_watchPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(t,e,s,(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 s,o,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(s=c.get("gid"))!=null?s:"",range:(o=c.get("range"))!=null?o:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const u=l.gid,p=C.deserializeRangeWithSheet(l.range).range;if(a.isValidRange(p)&&l.range!==$){const f=y=>{const h=m.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(p,y,{selectionManagerService:this._selectionManagerService});return h&&C.serializeRange(h)===C.serializeRange(p)?{redos:[],undos:[]}:{redos:[{id:x.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`}}}],undos:[{id:x.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(p,f,t,u)),i||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,u,p,(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:s,links:o}=n;o.forEach(d=>{this._registerPosition(i,s,d),this._watchPosition(i,s,d),this._registerRange(i,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:i,silent:s}=t,o=this._hyperLinkModel.getHyperLink(e,n,i);if(!o)return;this._unregisterPosition(i),this._registerPosition(e,n,o),s||(this._unwatchPosition(i),this._watchPosition(e,n,o));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:i}=n;i.forEach(s=>{this._unregisterPosition(s.id),this._unwatchPosition(s.id),this._unregisterRange(s.id),this._unwatchRange(s.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(a.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};K=Le([z(0,a.Inject(m.RefRangeService)),z(1,a.Inject(g.HyperLinkModel)),z(2,a.Inject(m.SheetsSelectionsService)),z(3,a.ICommandService)],K);var Ue=Object.getOwnPropertyDescriptor,we=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ue(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},ee=(r,t)=>(e,n)=>t(e,n,r);let Y=class extends a.Disposable{constructor(r,t,e){super(),this._sheetInterceptorService=r,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{var t;if(r.id===m.RemoveSheetCommand.id){const e=r.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const i=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const o=this._hyperLinkModel.getSubUnit(i,s),d=o.map(l=>({id:T.id,params:{unitId:i,subUnitId:s,id:l.id}})),c=o.map(l=>({id:E.id,params:{unitId:i,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};Y=we([ee(0,a.Inject(m.SheetInterceptorService)),ee(1,a.IUniverInstanceService),ee(2,a.Inject(g.HyperLinkModel))],Y);var Ee=Object.getOwnPropertyDescriptor,Te=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ee(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},te=(r,t)=>(e,n)=>t(e,n,r);let q=class extends a.Disposable{constructor(t,e,n){super();L(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let i=n.get(e);return i||(i=new a.ObjectMatrix,n.set(e,i)),i}_isLegalRangeUrl(t,e){var i,s,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:(s=d.get("range"))!=null?s:"",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 p=C.deserializeRangeWithSheet(c.range).range;if(a.isValidRange(p,u)&&c.range!==$)return{range:p,worksheet:u}}}return null}_registerRange(t,e,n,i,s){var d,c,l,u;const o=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(p=>{var f;return p.rangeType===a.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(f=p.properties)==null?void 0:f.url)})){const p=new a.DisposableCollection;let f=!1;(u=(l=s.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,p.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:W.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:y.rangeId,url:`#gid=${e}&range=${R?C.serializeRange(R):$}`}}],undos:[{id:W.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:y.rangeId,url:_}}],redos:[]}},k.getUnitId(),k.getSheetId()))}}}),f&&o.setValue(n,i,p)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId(),o=this._enusreMap(n,s);i.getCellMatrix().forValue((d,c,l)=>{const u=o.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,s,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 s=i.getSheetId();this._enusreMap(n,s).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}})}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===m.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:i,cellValue:s}=e,o=this._enusreMap(n,i);s&&new a.ObjectMatrix(s).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===W.id){const e=t.params,{unitId:n,subUnitId:i,row:s,col:o}=e,d=m.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:i}),l=this._enusreMap(n,i).getValue(s,o);if(l&&l.dispose(),d){const{worksheet:u}=d,p=u.getCellRaw(s,o);p&&p.p&&this._registerRange(n,i,s,o,p.p)}}}))}};q=Te([te(0,a.ICommandService),te(1,a.IUniverInstanceService),te(2,a.Inject(m.RefRangeService))],q);var He=Object.getOwnPropertyDescriptor,be=(r,t,e,n)=>{for(var i=n>1?void 0:n?He(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},G=(r,t)=>(e,n)=>t(e,n,r);let F=class extends a.Disposable{constructor(r,t,e,n){super(),this._sheetInterceptorService=r,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.SetRangeValuesCommand.id){const t=r.params,{unitId:e,subUnitId:n}=t,i=[],s=[];return t.cellValue&&new a.ObjectMatrix(t.cellValue).forValue((o,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,o,d);c&&(i.push({id:T.id,params:{unitId:e,subUnitId:n,id:c.id}}),s.push({id:E.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:s,redos:i}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.ClearSelectionContentCommand.id||r.id===m.ClearSelectionAllCommand.id||r.id===m.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),i=m.getSheetCommandTarget(this._univerInstanceService);if(n&&i){const{unitId:s,subUnitId:o}=i;a.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(s,o,d,c);l&&(t.push({id:T.id,params:{unitId:s,subUnitId:o,id:l.id}}),e.push({id:E.id,params:{unitId:s,subUnitId:o,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(m.AFTER_CELL_EDIT,{handler:(r,t,e)=>{if(!r||r.p)return e(r);if(typeof r.v=="string"&&a.Tools.isLegalUrl(r.v)&&r.v[r.v.length-1]!==" "){const{unitId:n,subUnitId:i,row:s,col:o}=t,d=this._univerInstanceService.getUnit(n,a.UniverInstanceType.UNIVER_SHEET),c=d==null?void 0:d.getSheetBySheetId(i);if(!c)return e(r);const l=c.getBlankCellDocumentModel(r,s,o);if(!l.documentModel)return e(r);const u=a.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:r.v.length,collapsed:!1},body:{dataStream:`${r.v}`,customRanges:[{startIndex:0,endIndex:r.v.length-1,rangeId:a.generateRandomId(),rangeType:a.CustomRangeType.HYPERLINK,properties:{url:r.v}}]},doc:l.documentModel});if(!u)return e(r);const p=l.documentModel.getBody();return a.TextX.apply(p,u.serialize()),e({...r,p:{id:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:p,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(r)}}))}};F=be([G(0,a.Inject(m.SheetInterceptorService)),G(1,a.Inject(g.HyperLinkModel)),G(2,a.Inject(m.SheetsSelectionsService)),G(3,a.IUniverInstanceService)],F);var Pe=Object.getOwnPropertyDescriptor,De=(r,t,e,n)=>{for(var i=n>1?void 0:n?Pe(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},ge=(r,t)=>(e,n)=>t(e,n,r);let X=class extends a.Disposable{constructor(r,t){super(),this._resourceManagerService=r,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const r=e=>{const n=this._hyperLinkModel.getUnit(e),i={};return n?(n.forEach(s=>{i[s.subUnitId]=s.links.map(({display:o,...d})=>d)}),JSON.stringify(i)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:pe,businesses:[a.UniverInstanceType.UNIVER_SHEET],toJson:e=>r(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(i=>{n[i].forEach(o=>{this._hyperLinkModel.addHyperLink(e,i,o)})})}}))}};X=De([ge(0,a.IResourceManagerService),ge(1,a.Inject(g.HyperLinkModel))],X);var Oe=Object.getOwnPropertyDescriptor,Ne=(r,t,e,n)=>{for(var i=n>1?void 0:n?Oe(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},Ve=(r,t)=>(e,n)=>t(e,n,r);let J=class extends a.Disposable{constructor(r){super(),this._commandService=r,this._registerCommands()}_registerCommands(){[re,ce,oe,le,de,ae,E,x,T,B,W].forEach(r=>{this._commandService.registerCommand(r)})}};J=Ne([Ve(0,a.ICommandService)],J);var U=(r=>(r.SHEET="gid",r.RANGE="range",r.DEFINE_NAME="rangeid",r.INVALID="invalid",r.URL="url",r))(U||{}),$e=Object.getOwnPropertyDescriptor,je=(r,t,e,n)=>{for(var i=n>1?void 0:n?$e(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},ne=(r,t)=>(e,n)=>t(e,n,r);g.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${U.SHEET}=${e}${n?`&${typeof n=="string"?U.DEFINE_NAME:U.RANGE}=${typeof n=="string"?n:C.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,i,s;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:(s=o.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:i,unitid:s}=t,o=s?this._univerInstanceService.getUnit(s,a.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),d={type:U.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 p=C.deserializeRangeWithSheet(n).range;return a.isValidRange(p,c)&&n!==$?{type:U.RANGE,name:C.serializeRangeWithSheet(l,p)}:d}if(i){const p=this._definedNamesService.getValueById(o.getUnitId(),i);return p?{type:U.DEFINE_NAME,name:p.formulaOrRefString}:d}if(e){const p=o.getSheetBySheetId(e);return p?{type:U.SHEET,name:p.getName()}:d}return d}},g.SheetsHyperLinkParserService=je([ne(0,a.IUniverInstanceService),ne(1,a.Inject(a.LocaleService)),ne(2,C.IDefinedNamesService)],g.SheetsHyperLinkParserService);var Ae=Object.defineProperty,xe=Object.getOwnPropertyDescriptor,Be=(r,t,e)=>t in r?Ae(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,We=(r,t,e,n)=>{for(var i=n>1?void 0:n?xe(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},he=(r,t)=>(e,n)=>t(e,n,r),me=(r,t,e)=>Be(r,typeof t!="symbol"?t+"":t,e);g.UniverSheetsHyperLinkPlugin=class extends a.Plugin{constructor(t=ue,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...i}=a.merge({},ue,this._config);this._configService.setConfig(Ce,i)}onStarting(){a.registerDependencies(this._injector,[[g.HyperLinkModel],[g.SheetsHyperLinkParserService],[X],[J],[K],[F],[Y],[q]]),a.touchDependencies(this._injector,[[K],[X],[J],[F],[Y],[q]])}},me(g.UniverSheetsHyperLinkPlugin,"pluginName",pe),me(g.UniverSheetsHyperLinkPlugin,"type",a.UniverInstanceType.UNIVER_SHEET),g.UniverSheetsHyperLinkPlugin=We([a.DependentOn(m.UniverSheetsPlugin),he(1,a.Inject(a.Injector)),he(2,a.IConfigService)],g.UniverSheetsHyperLinkPlugin),g.AddHyperLinkCommand=re,g.AddHyperLinkMutation=E,g.AddRichHyperLinkCommand=ae,g.CancelHyperLinkCommand=oe,g.CancelRichHyperLinkCommand=de,g.ERROR_RANGE=$,g.RemoveHyperLinkMutation=T,g.SheetHyperLinkType=U,g.UpdateHyperLinkCommand=ce,g.UpdateHyperLinkMutation=x,g.UpdateHyperLinkRefMutation=B,g.UpdateRichHyperLinkCommand=le,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(g,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/docs"),require("@univerjs/sheets"),require("rxjs"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs","@univerjs/sheets","rxjs","@univerjs/engine-formula"],a):(g=typeof globalThis<"u"?globalThis:g||self,a(g.UniverSheetsHyperLink={},g.UniverCore,g.UniverDocs,g.UniverSheets,g.rxjs,g.UniverEngineFormula))})(this,(function(g,a,w,m,Se,C){"use strict";var Ke=Object.defineProperty;var Ye=(g,a,w)=>a in g?Ke(g,a,{enumerable:!0,configurable:!0,writable:!0,value:w}):g[a]=w;var L=(g,a,w)=>Ye(g,typeof a!="symbol"?a+"":a,w);var Ie=Object.getOwnPropertyDescriptor,Re=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ie(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},Me=(r,t)=>(e,n)=>t(e,n,r);g.HyperLinkModel=class extends a.Disposable{constructor(e){super();L(this,"_linkUpdate$",new Se.Subject);L(this,"linkUpdate$",this._linkUpdate$.asObservable());L(this,"_linkMap",new Map);L(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let i=this._linkMap.get(e);i||(i=new Map,this._linkMap.set(e,i));let s=i.get(n);s||(s=new a.ObjectMatrix,i.set(n,s));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:s,positionMap:d}}addHyperLink(e,n,i){const{matrix:s,positionMap:o}=this._ensureMap(e,n);return s.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,s,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,s),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,s,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,s),c.set(i,{...s,link:u}),d.setValue(s.row,s.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:i,type:"updateRef",silent:o}),!0}removeHyperLink(e,n,i){const{matrix:s,positionMap:o}=this._ensureMap(e,n),d=o.get(i);if(!d)return!1;o.delete(i);const c=s.getValue(d.row,d.column);return c&&c.id===i&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,i){const{matrix:s,positionMap:o}=this._ensureMap(e,n),d=o.get(i);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,i,s){const{matrix:o}=this._ensureMap(e,n);return o.getValue(i,s)}getHyperLinkByLocationSync(e,n,i,s){var p,f,y,h,_;const{matrix:o}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,a.UniverInstanceType.UNIVER_SHEET),c=(p=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:p.getCellRaw(i,s),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,s);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:i}=this._ensureMap(e,n),s=[];return i.forValue((o,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(i=>{const s=this.getSubUnit(e,i);return{unitId:e,subUnitId:i,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}},g.HyperLinkModel=Re([Me(0,a.IUniverInstanceService)],g.HyperLinkModel);const E={type:a.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(g.HyperLinkModel),{unitId:n,subUnitId:i,link:s}=t;return e.addHyperLink(n,i,s)}},T={type:a.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(g.HyperLinkModel),{unitId:n,subUnitId:i,id:s}=t;return e.removeHyperLink(n,i,s)}},re={type:a.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(r,t){if(!t)return!1;const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService),s=r.get(g.HyperLinkModel),o=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:u,worksheet:p}=d,{link:f}=t,{payload:y,display:h,row:_,column:v,id:S}=f,k=p.getCell(_,v),I=p.getBlankCellDocumentModel(k,_,v),R=I.documentModel.getSnapshot(),M=a.Tools.deepClone(R.body);if(!M)return!1;let H;if(h?H=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}):H=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}}),!H)return!1;const j=a.TextX.apply(M,H.serialize()),b={p:{...R,body:j},t:a.CellValueType.STRING},N=o.onWriteCell(u,p,_,v,b),V={unitId:c,subUnitId:l,cellValue:{[f.row]:{[f.column]:N}}},ie={id:m.SetRangeValuesMutation.id,params:V},Q=m.SetRangeValuesUndoMutationFactory(r,V),se={id:m.SetRangeValuesMutation.id,params:Q},A=[ie],P=[se],D=s.getHyperLinkByLocation(c,l,_,v);return D&&(A.push({id:T.id,params:{unitId:c,subUnitId:l,id:D.id}}),P.push({id:E.id,params:{unitId:c,subUnitId:l,link:D}})),await a.sequenceExecute(A,e)?await o.onValidateCell(u,p,_,v)===!1?(a.sequenceExecute(P,e),!1):(n.pushUndoRedo({redoMutations:A,undoMutations:P,unitID:c}),!0):!1}},ae={id:"sheets.command.add-rich-hyper-link",type:a.CommandType.COMMAND,handler:async(r,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,i=r.get(a.ICommandService),s=a.generateRandomId(),{payload:o}=n,d=w.addCustomRangeBySelectionFactory(r,{unitId:e,rangeId:s,rangeType:a.CustomRangeType.HYPERLINK,properties:{url:o,refId:s}});return d?i.syncExecuteCommand(d.id,d.params):!1}},oe={type:a.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(r,t){var b,N;if(!t)return!1;const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService),s=r.get(g.HyperLinkModel),o=m.getSheetCommandTarget(i,t);if(!o)return!1;const{row:d,column:c,id:l}=t,{unitId:u,subUnitId:p,worksheet:f}=o,y=f.getCell(d,c);if(!y)return!1;const h=f.getCellDocumentModelWithFormula(y,d,c);if(!(h!=null&&h.documentModel))return!1;const _=a.Tools.deepClone(h.documentModel.getSnapshot()),v=(N=(b=_.body)==null?void 0:b.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:p,cellValue:{[d]:{[c]:{p:{..._,body:k},t:a.CellValueType.STRING}}}};I.push({id:m.SetRangeValuesMutation.id,params:M});const H=m.SetRangeValuesUndoMutationFactory(r,M);R.push({id:m.SetRangeValuesMutation.id,params:H});const j=s.getHyperLinkByLocation(u,p,d,c);return j&&(I.push({id:T.id,params:{unitId:u,subUnitId:p,id:l}}),R.push({id:E.id,params:{unitId:u,subUnitId:p,link:{...j}}})),a.sequenceExecute(I,e).result?(n.pushUndoRedo({redoMutations:I,undoMutations:R,unitID:u}),!0):!1}},de={type:a.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(r,t){var u,p;if(!t)return!1;const{id:e,documentId:n}=t,i=r.get(a.ICommandService),o=r.get(a.IUniverInstanceService).getUnit(n,a.UniverInstanceType.UNIVER_DOC),d=(p=(u=o==null?void 0:o.getBody())==null?void 0:u.customRanges)==null?void 0:p.find(f=>f.rangeId===e);let c=null;d&&d.endIndex===o.getBody().dataStream.length-3&&(c={dataStream:" "});const l=w.deleteCustomRangeFactory(r,{unitId:n,rangeId:e,insert:c});return l?i.syncExecuteCommand(l.id,l.params):!1}},ce={type:a.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(r,t){var fe,ye,_e;if(!t)return!1;const e=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService),s=r.get(g.HyperLinkModel),o=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:u,id:p}=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,l,u);if(!(I!=null&&I.documentModel))return!1;const R=I.documentModel.getSnapshot(),M=(ye=(fe=R.body)==null?void 0:fe.customRanges)==null?void 0:ye.find(ve=>`${ve.rangeId}`===p);if(!M)return!1;const H=a.generateRandomId(),O=(_e=a.getBodySlice(I.documentModel.getBody(),M.startIndex,M.endIndex+1).textRuns)==null?void 0:_e[0];O&&(O.ed=S.length+1);const b=w.replaceSelectionFactory(r,{unitId:h,body:{dataStream:`${S}`,customRanges:[{rangeId:H,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(!b)return!1;const N=a.TextX.apply(a.Tools.deepClone(R.body),b.textX.serialize()),V={p:{...R,body:N},t:a.CellValueType.STRING},ie=o.onWriteCell(f,y,l,u,V),Q={id:m.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:_,cellValue:{[l]:{[u]:ie}}}},se=m.SetRangeValuesUndoMutationFactory(r,Q.params),A={id:m.SetRangeValuesMutation.id,params:se},P=[Q],D=[A],Z=s.getHyperLinkByLocation(h,_,l,u);return Z&&(P.push({id:T.id,params:{unitId:h,subUnitId:_,id:Z.id}}),D.push({id:E.id,params:{unitId:h,subUnitId:_,link:Z}})),a.sequenceExecute(P,e)?await o.onValidateCell(f,y,l,u)===!1?(a.sequenceExecute(D,e),!1):(n.pushUndoRedo({redoMutations:P,undoMutations:D,unitID:h}),!0):!1}},le={type:a.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(r,t)=>{var h,_,v,S;if(!t)return!1;const{documentId:e,payload:n,id:i}=t,s=r.get(a.IUniverInstanceService),o=r.get(a.ICommandService),d=s.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=w.replaceSelectionFactory(r,{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}},x={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(g.HyperLinkModel),{unitId:n,subUnitId:i,payload:s,id:o}=t;return e.updateHyperLink(n,i,o,s,!1)}},W={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(r,t){if(!t)return!1;const e=r.get(g.HyperLinkModel),{unitId:n,subUnitId:i,id:s,row:o,column:d,silent:c}=t;return e.updateHyperLinkRef(n,i,s,{row:o,column:d},c)}},B={type:a.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(r,t){var y,h,_;if(!t)return!1;const{unitId:e,subUnitId:n,row:i,col:s,id:o,url:d}=t,c=r.get(a.IUniverInstanceService),l=m.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:u}=l,p=u.getCellRaw(i,s),f=(_=(h=(y=p==null?void 0:p.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}},Ce="sheets-hyper-link.config",ue={},pe="SHEET_HYPER_LINK_PLUGIN",$="err";var ke=Object.getOwnPropertyDescriptor,Le=(r,t,e,n)=>{for(var i=n>1?void 0:n?ke(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},z=(r,t)=>(e,n)=>t(e,n,r);let K=class extends a.Disposable{constructor(t,e,n,i){super();L(this,"_disposableMap",new Map);L(this,"_watchDisposableMap",new Map);L(this,"_rangeDisableMap",new Map);L(this,"_rangeWatcherMap",new Map);L(this,"_handlePositionChange",(t,e,n,i,s)=>{const o={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return i?{redos:[{id:W.id,params:{unitId:t,subUnitId:e,id:n.id,row:i.startRow,column:i.startColumn,silent:s}}],undos:[{id:W.id,params:{unitId:t,subUnitId:e,id:n.id,row:o.startRow,column:o.startColumn,silent:s}}]}:{redos:[{id:T.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:E.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=i,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},o=d=>{const c=m.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===s.startColumn&&l.startRow===s.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(i,this._refRangeService.registerRefRange(s,o,t,e))}_watchPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(t,e,s,(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 s,o,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(s=c.get("gid"))!=null?s:"",range:(o=c.get("range"))!=null?o:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const u=l.gid,p=C.deserializeRangeWithSheet(l.range).range;if(a.isValidRange(p)&&l.range!==$){const f=y=>{const h=m.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(p,y,{selectionManagerService:this._selectionManagerService});return h&&C.serializeRange(h)===C.serializeRange(p)?{redos:[],undos:[]}:{redos:[{id:x.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`}}}],undos:[{id:x.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(p,f,t,u)),i||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,u,p,(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:s,links:o}=n;o.forEach(d=>{this._registerPosition(i,s,d),this._watchPosition(i,s,d),this._registerRange(i,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:i,silent:s}=t,o=this._hyperLinkModel.getHyperLink(e,n,i);if(!o)return;this._unregisterPosition(i),this._registerPosition(e,n,o),s||(this._unwatchPosition(i),this._watchPosition(e,n,o));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:i}=n;i.forEach(s=>{this._unregisterPosition(s.id),this._unwatchPosition(s.id),this._unregisterRange(s.id),this._unwatchRange(s.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(a.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};K=Le([z(0,a.Inject(m.RefRangeService)),z(1,a.Inject(g.HyperLinkModel)),z(2,a.Inject(m.SheetsSelectionsService)),z(3,a.ICommandService)],K);var Ue=Object.getOwnPropertyDescriptor,we=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ue(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},ee=(r,t)=>(e,n)=>t(e,n,r);let Y=class extends a.Disposable{constructor(r,t,e){super(),this._sheetInterceptorService=r,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{var t;if(r.id===m.RemoveSheetCommand.id){const e=r.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const i=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const o=this._hyperLinkModel.getSubUnit(i,s),d=o.map(l=>({id:T.id,params:{unitId:i,subUnitId:s,id:l.id}})),c=o.map(l=>({id:E.id,params:{unitId:i,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};Y=we([ee(0,a.Inject(m.SheetInterceptorService)),ee(1,a.IUniverInstanceService),ee(2,a.Inject(g.HyperLinkModel))],Y);var Ee=Object.getOwnPropertyDescriptor,Te=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ee(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},te=(r,t)=>(e,n)=>t(e,n,r);let q=class extends a.Disposable{constructor(t,e,n){super();L(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let i=n.get(e);return i||(i=new a.ObjectMatrix,n.set(e,i)),i}_isLegalRangeUrl(t,e){var i,s,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:(s=d.get("range"))!=null?s:"",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 p=C.deserializeRangeWithSheet(c.range).range;if(a.isValidRange(p,u)&&c.range!==$)return{range:p,worksheet:u}}}return null}_registerRange(t,e,n,i,s){var d,c,l,u;const o=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(p=>{var f;return p.rangeType===a.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(f=p.properties)==null?void 0:f.url)})){const p=new a.DisposableCollection;let f=!1;(u=(l=s.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,p.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:B.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:y.rangeId,url:`#gid=${e}&range=${R?C.serializeRange(R):$}`}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:y.rangeId,url:_}}],redos:[]}},k.getUnitId(),k.getSheetId()))}}}),f&&o.setValue(n,i,p)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId(),o=this._enusreMap(n,s);i.getCellMatrix().forValue((d,c,l)=>{const u=o.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,s,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.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===a.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId();this._enusreMap(n,s).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}}))}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===m.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:i,cellValue:s}=e,o=this._enusreMap(n,i);s&&new a.ObjectMatrix(s).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===B.id){const e=t.params,{unitId:n,subUnitId:i,row:s,col:o}=e,d=m.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:i}),l=this._enusreMap(n,i).getValue(s,o);if(l&&l.dispose(),d){const{worksheet:u}=d,p=u.getCellRaw(s,o);p&&p.p&&this._registerRange(n,i,s,o,p.p)}}}))}};q=Te([te(0,a.ICommandService),te(1,a.IUniverInstanceService),te(2,a.Inject(m.RefRangeService))],q);var He=Object.getOwnPropertyDescriptor,be=(r,t,e,n)=>{for(var i=n>1?void 0:n?He(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},G=(r,t)=>(e,n)=>t(e,n,r);let F=class extends a.Disposable{constructor(r,t,e,n){super(),this._sheetInterceptorService=r,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.SetRangeValuesCommand.id){const t=r.params,{unitId:e,subUnitId:n}=t,i=[],s=[];return t.cellValue&&new a.ObjectMatrix(t.cellValue).forValue((o,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,o,d);c&&(i.push({id:T.id,params:{unitId:e,subUnitId:n,id:c.id}}),s.push({id:E.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:s,redos:i}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.ClearSelectionContentCommand.id||r.id===m.ClearSelectionAllCommand.id||r.id===m.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),i=m.getSheetCommandTarget(this._univerInstanceService);if(n&&i){const{unitId:s,subUnitId:o}=i;a.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(s,o,d,c);l&&(t.push({id:T.id,params:{unitId:s,subUnitId:o,id:l.id}}),e.push({id:E.id,params:{unitId:s,subUnitId:o,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(m.AFTER_CELL_EDIT,{handler:(r,t,e)=>{if(!r||r.p)return e(r);if(typeof r.v=="string"&&a.Tools.isLegalUrl(r.v)&&r.v[r.v.length-1]!==" "){const{unitId:n,subUnitId:i,row:s,col:o}=t,d=this._univerInstanceService.getUnit(n,a.UniverInstanceType.UNIVER_SHEET),c=d==null?void 0:d.getSheetBySheetId(i);if(!c)return e(r);const l=c.getBlankCellDocumentModel(r,s,o);if(!l.documentModel)return e(r);const u=a.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:r.v.length,collapsed:!1},body:{dataStream:`${r.v}`,customRanges:[{startIndex:0,endIndex:r.v.length-1,rangeId:a.generateRandomId(),rangeType:a.CustomRangeType.HYPERLINK,properties:{url:r.v}}]},doc:l.documentModel});if(!u)return e(r);const p=l.documentModel.getBody();return a.TextX.apply(p,u.serialize()),e({...r,p:{id:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:p,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(r)}}))}};F=be([G(0,a.Inject(m.SheetInterceptorService)),G(1,a.Inject(g.HyperLinkModel)),G(2,a.Inject(m.SheetsSelectionsService)),G(3,a.IUniverInstanceService)],F);var Pe=Object.getOwnPropertyDescriptor,De=(r,t,e,n)=>{for(var i=n>1?void 0:n?Pe(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},ge=(r,t)=>(e,n)=>t(e,n,r);let X=class extends a.Disposable{constructor(r,t){super(),this._resourceManagerService=r,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const r=e=>{const n=this._hyperLinkModel.getUnit(e),i={};return n?(n.forEach(s=>{i[s.subUnitId]=s.links.map(({display:o,...d})=>d)}),JSON.stringify(i)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:pe,businesses:[a.UniverInstanceType.UNIVER_SHEET],toJson:e=>r(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(i=>{n[i].forEach(o=>{this._hyperLinkModel.addHyperLink(e,i,o)})})}}))}};X=De([ge(0,a.IResourceManagerService),ge(1,a.Inject(g.HyperLinkModel))],X);var Oe=Object.getOwnPropertyDescriptor,Ne=(r,t,e,n)=>{for(var i=n>1?void 0:n?Oe(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},Ve=(r,t)=>(e,n)=>t(e,n,r);let J=class extends a.Disposable{constructor(r){super(),this._commandService=r,this._registerCommands()}_registerCommands(){[re,ce,oe,le,de,ae,E,x,T,W,B].forEach(r=>{this._commandService.registerCommand(r)})}};J=Ne([Ve(0,a.ICommandService)],J);var U=(r=>(r.SHEET="gid",r.RANGE="range",r.DEFINE_NAME="rangeid",r.INVALID="invalid",r.URL="url",r))(U||{}),$e=Object.getOwnPropertyDescriptor,je=(r,t,e,n)=>{for(var i=n>1?void 0:n?$e(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},ne=(r,t)=>(e,n)=>t(e,n,r);g.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${U.SHEET}=${e}${n?`&${typeof n=="string"?U.DEFINE_NAME:U.RANGE}=${typeof n=="string"?n:C.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,i,s;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:(s=o.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:i,unitid:s}=t,o=s?this._univerInstanceService.getUnit(s,a.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),d={type:U.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 p=C.deserializeRangeWithSheet(n).range;return a.isValidRange(p,c)&&n!==$?{type:U.RANGE,name:C.serializeRangeWithSheet(l,p)}:d}if(i){const p=this._definedNamesService.getValueById(o.getUnitId(),i);return p?{type:U.DEFINE_NAME,name:p.formulaOrRefString}:d}if(e){const p=o.getSheetBySheetId(e);return p?{type:U.SHEET,name:p.getName()}:d}return d}},g.SheetsHyperLinkParserService=je([ne(0,a.IUniverInstanceService),ne(1,a.Inject(a.LocaleService)),ne(2,C.IDefinedNamesService)],g.SheetsHyperLinkParserService);var Ae=Object.defineProperty,xe=Object.getOwnPropertyDescriptor,We=(r,t,e)=>t in r?Ae(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Be=(r,t,e,n)=>{for(var i=n>1?void 0:n?xe(t,e):t,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=o(i)||i);return i},he=(r,t)=>(e,n)=>t(e,n,r),me=(r,t,e)=>We(r,typeof t!="symbol"?t+"":t,e);g.UniverSheetsHyperLinkPlugin=class extends a.Plugin{constructor(t=ue,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...i}=a.merge({},ue,this._config);this._configService.setConfig(Ce,i)}onStarting(){a.registerDependencies(this._injector,[[g.HyperLinkModel],[g.SheetsHyperLinkParserService],[X],[J],[K],[F],[Y],[q]]),a.touchDependencies(this._injector,[[K],[X],[J],[F],[Y],[q]])}},me(g.UniverSheetsHyperLinkPlugin,"pluginName",pe),me(g.UniverSheetsHyperLinkPlugin,"type",a.UniverInstanceType.UNIVER_SHEET),g.UniverSheetsHyperLinkPlugin=Be([a.DependentOn(m.UniverSheetsPlugin),he(1,a.Inject(a.Injector)),he(2,a.IConfigService)],g.UniverSheetsHyperLinkPlugin),g.AddHyperLinkCommand=re,g.AddHyperLinkMutation=E,g.AddRichHyperLinkCommand=ae,g.CancelHyperLinkCommand=oe,g.CancelRichHyperLinkCommand=de,g.ERROR_RANGE=$,g.RemoveHyperLinkMutation=T,g.SheetHyperLinkType=U,g.UpdateHyperLinkCommand=ce,g.UpdateHyperLinkMutation=x,g.UpdateHyperLinkRefMutation=W,g.UpdateRichHyperLinkCommand=le,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-hyper-link",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.11-nightly.202510220308",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -56,17 +56,17 @@
|
|
|
56
56
|
"rxjs": ">=7.0.0"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@univerjs/core": "0.10.
|
|
60
|
-
"@univerjs/
|
|
61
|
-
"@univerjs/
|
|
62
|
-
"@univerjs/sheets": "0.10.
|
|
59
|
+
"@univerjs/core": "0.10.11-nightly.202510220308",
|
|
60
|
+
"@univerjs/docs": "0.10.11-nightly.202510220308",
|
|
61
|
+
"@univerjs/engine-formula": "0.10.11-nightly.202510220308",
|
|
62
|
+
"@univerjs/sheets": "0.10.11-nightly.202510220308"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"rxjs": "^7.8.2",
|
|
66
|
-
"typescript": "^5.9.
|
|
67
|
-
"vite": "^7.1.
|
|
66
|
+
"typescript": "^5.9.3",
|
|
67
|
+
"vite": "^7.1.10",
|
|
68
68
|
"vitest": "^3.2.4",
|
|
69
|
-
"@univerjs-infra/shared": "0.10.
|
|
69
|
+
"@univerjs-infra/shared": "0.10.11"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"test": "vitest run",
|
package/LICENSE
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|