@univerjs/sheets-hyper-link 0.5.1 → 0.5.2-nightly.202412281605

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/facade.js CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/sheets/facade"),i=require("@univerjs/sheets-hyper-link"),a=require("@univerjs/core");class u extends o.FWorkbook{createSheetHyperlink(e,t){return this._injector.get(i.SheetsHyperLinkParserService).buildHyperLink(this.getId(),e,t)}parseSheetHyperlink(e){return this._injector.get(i.SheetsHyperLinkParserService).parseHyperLink(e)}}o.FWorkbook.extend(u);class k extends o.FRange{setHyperLink(e,t){const n={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),link:{row:this._range.startRow,column:this._range.startColumn,payload:e,display:t,id:a.generateRandomId()}};return this._commandService.executeCommand(i.AddHyperLinkCommand.id,n)}getHyperLinks(){var t,n,s;const e=this._worksheet.getCellRaw(this._range.startRow,this._range.startColumn);return e!=null&&e.p?(s=(n=(t=e.p.body)==null?void 0:t.customRanges)==null?void 0:n.filter(r=>r.rangeType===a.CustomRangeType.HYPERLINK).map(r=>{var d,p,c,l,m;return{id:`${r.rangeId}_${r.startIndex}_${r.endIndex}`,startIndex:r.startIndex,endIndex:r.endIndex,url:(p=(d=r.properties)==null?void 0:d.url)!=null?p:"",label:(m=(l=(c=e.p)==null?void 0:c.body)==null?void 0:l.dataStream.slice(r.startIndex,r.endIndex+1).replaceAll(a.DataStreamTreeTokenType.CUSTOM_RANGE_START,"").replaceAll(a.DataStreamTreeTokenType.CUSTOM_RANGE_END,""))!=null?m:""}}))!=null?s:[]:[]}updateHyperLink(e,t,n){const s={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id:e,payload:{payload:t,display:n}};return this._commandService.executeCommand(i.UpdateHyperLinkCommand.id,s)}cancelHyperLink(e){const t={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id:e};return this._commandService.executeCommand(i.CancelHyperLinkCommand.id,t)}}o.FRange.extend(k);exports.FWorkbookHyperLinkMixin=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/sheets/facade"),i=require("@univerjs/sheets-hyper-link"),a=require("@univerjs/core");class u extends o.FWorkbook{createSheetHyperlink(e,t){return this._injector.get(i.SheetsHyperLinkParserService).buildHyperLink(this.getId(),e,t)}parseSheetHyperlink(e){return this._injector.get(i.SheetsHyperLinkParserService).parseHyperLink(e)}}o.FWorkbook.extend(u);class k extends o.FRange{setHyperLink(e,t){const n={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),link:{row:this._range.startRow,column:this._range.startColumn,payload:e,display:t,id:a.generateRandomId()}};return this._commandService.executeCommand(i.AddHyperLinkCommand.id,n)}getHyperLinks(){var t,n,s;const e=this._worksheet.getCellRaw(this._range.startRow,this._range.startColumn);return e!=null&&e.p?(s=(n=(t=e.p.body)==null?void 0:t.customRanges)==null?void 0:n.filter(r=>r.rangeType===a.CustomRangeType.HYPERLINK).map(r=>{var d,p,c,l,m;return{id:`${r.rangeId}`,startIndex:r.startIndex,endIndex:r.endIndex,url:(p=(d=r.properties)==null?void 0:d.url)!=null?p:"",label:(m=(l=(c=e.p)==null?void 0:c.body)==null?void 0:l.dataStream.slice(r.startIndex,r.endIndex+1).replaceAll(a.DataStreamTreeTokenType.CUSTOM_RANGE_START,"").replaceAll(a.DataStreamTreeTokenType.CUSTOM_RANGE_END,""))!=null?m:""}}))!=null?s:[]:[]}updateHyperLink(e,t,n){const s={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id:e,payload:{payload:t,display:n}};return this._commandService.executeCommand(i.UpdateHyperLinkCommand.id,s)}cancelHyperLink(e){const t={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id:e};return this._commandService.executeCommand(i.CancelHyperLinkCommand.id,t)}}o.FRange.extend(k);exports.FWorkbookHyperLinkMixin=u;
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var Se=Object.defineProperty;var Ie=(i,t,e)=>t in i?Se(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var C=(i,t,e)=>Ie(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),Re=require("rxjs"),g=require("@univerjs/sheets"),U=require("@univerjs/engine-formula"),Z=require("@univerjs/docs");var Me=Object.defineProperty,Ce=Object.getOwnPropertyDescriptor,Ue=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ce(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Me(t,e,r),r},Le=(i,t)=>(e,n)=>t(e,n,i);exports.HyperLinkModel=class extends o.Disposable{constructor(e){super();C(this,"_linkUpdate$",new Re.Subject);C(this,"linkUpdate$",this._linkUpdate$.asObservable());C(this,"_linkMap",new Map);C(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let r=this._linkMap.get(e);r||(r=new Map,this._linkMap.set(e,r));let s=r.get(n);s||(s=new o.ObjectMatrix,r.set(n,s));let a=this._linkPositionMap.get(e);a||(a=new Map,this._linkPositionMap.set(e,a));let d=a.get(n);return d||(d=new Map,a.set(n,d)),{matrix:s,positionMap:d}}addHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n);return s.setValue(r.row,r.column,r),a.set(r.id,{row:r.row,column:r.column,link:r}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:r,type:"add"}),!0}updateHyperLink(e,n,r,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(r);if(!l)return!0;const p=d.getValue(l.row,l.column);return p&&(Object.assign(p,s),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:p.display,payload:p.payload},id:r,type:"update",silent:a})),!0}updateHyperLinkRef(e,n,r,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(r);if(!l)return!0;let p=d.getValue(l.row,l.column);return!p||p.id!==r?p=l.link:d.realDeleteValue(l.row,l.column),Object.assign(p,s),c.set(r,{...s,link:p}),d.setValue(s.row,s.column,p),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:r,type:"updateRef",silent:a}),!0}removeHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(r);if(!d)return!1;a.delete(r);const c=s.getValue(d.row,d.column);return c&&c.id===r&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(r);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,r,s){const{matrix:a}=this._ensureMap(e,n);return a.getValue(r,s)}getHyperLinkByLocationSync(e,n,r,s){var u,m,f,h,_;const{matrix:a}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,o.UniverInstanceType.UNIVER_SHEET),c=(u=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:u.getCellRaw(r,s),l=((_=(h=c==null?void 0:c.v)!=null?h:(f=(m=c==null?void 0:c.p)==null?void 0:m.body)==null?void 0:f.dataStream.slice(0,-2))!=null?_:"").toString(),p=a.getValue(r,s);if(p)return{...p,display:l}}getSubUnit(e,n){const{matrix:r}=this._ensureMap(e,n),s=[];return r.forValue((a,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(r=>{const s=this.getSubUnit(e,r);return{unitId:e,subUnitId:r,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}};exports.HyperLinkModel=Ue([Le(0,o.IUniverInstanceService)],exports.HyperLinkModel);var L=(i=>(i.SHEET="gid",i.RANGE="range",i.DEFINE_NAME="rangeid",i.INVALID="invalid",i.URL="url",i))(L||{});const we="sheets-hyper-link.config",Ee={},w={type:o.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,link:s}=t;return e.addHyperLink(n,r,s)}},E={type:o.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,id:s}=t;return e.removeHyperLink(n,r,s)}},F={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,payload:s,id:a}=t;return e.updateHyperLink(n,r,a,s,!1)}},K={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,id:s,row:a,column:d,silent:c}=t;return e.updateHyperLinkRef(n,r,s,{row:a,column:d},c)}},B={type:o.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(i,t){var f,h,_;if(!t)return!1;const{unitId:e,subUnitId:n,row:r,col:s,id:a,url:d}=t,c=i.get(o.IUniverInstanceService),l=g.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:p}=l,u=p.getCellRaw(r,s),m=(_=(h=(f=u==null?void 0:u.p)==null?void 0:f.body)==null?void 0:h.customRanges)==null?void 0:_.find(S=>S.rangeType===o.CustomRangeType.HYPERLINK&&S.rangeId===a);return m&&(m.properties.url=d),!0}},ce="SHEET_HYPER_LINK_PLUGIN",x="err";var ke=Object.defineProperty,be=Object.getOwnPropertyDescriptor,Pe=(i,t,e,n)=>{for(var r=n>1?void 0:n?be(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&ke(t,e,r),r},A=(i,t)=>(e,n)=>t(e,n,i);let z=class extends o.Disposable{constructor(t,e,n,r){super();C(this,"_disposableMap",new Map);C(this,"_watchDisposableMap",new Map);C(this,"_rangeDisableMap",new Map);C(this,"_rangeWatcherMap",new Map);C(this,"_handlePositionChange",(t,e,n,r,s)=>{const a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return r?{redos:[{id:K.id,params:{unitId:t,subUnitId:e,id:n.id,row:r.startRow,column:r.startColumn,silent:s}}],undos:[{id:K.id,params:{unitId:t,subUnitId:e,id:n.id,row:a.startRow,column:a.startColumn,silent:s}}]}:{redos:[{id:E.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:w.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=r,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const r=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},a=d=>{const c=g.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===s.startColumn&&l.startRow===s.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(r,this._refRangeService.registerRefRange(s,a,t,e))}_watchPosition(t,e,n){const r=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(r,this._refRangeService.watchRange(t,e,s,(a,d)=>{const{redos:c}=this._handlePositionChange(t,e,n,d,!0);o.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(t){const e=this._disposableMap.get(t);e==null||e.dispose(),this._disposableMap.delete(t)}_unwatchPosition(t){const e=this._watchDisposableMap.get(t);e==null||e.dispose(),this._watchDisposableMap.delete(t)}_registerRange(t,e,n,r=!1){var s,a,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(s=c.get("gid"))!=null?s:"",range:(a=c.get("range"))!=null?a:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const p=l.gid,u=U.deserializeRangeWithSheet(l.range).range;if(o.isValidRange(u)&&l.range!==x){const m=f=>{const h=g.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(u,f,{selectionManagerService:this._selectionManagerService});return h&&U.serializeRange(h)===U.serializeRange(u)?{redos:[],undos:[]}:{redos:[{id:F.id,params:{unitId:t,subUnitId:p,id:e,payload:{payload:`#gid=${p}&range=${h?U.serializeRange(h):"err"}`}}}],undos:[{id:F.id,params:{unitId:t,subUnitId:p,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(u,m,t,p)),r||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,p,u,(f,h)=>{this._hyperLinkModel.updateHyperLink(t,p,e,{payload:`#gid=${p}&range=${h?U.serializeRange(h):"err"}`},!0)},!0))}}}}_unregisterRange(t){const e=this._rangeDisableMap.get(t);e==null||e.dispose(),this._rangeDisableMap.delete(t)}_unwatchRange(t){const e=this._rangeWatcherMap.get(t);e==null||e.dispose(),this._rangeWatcherMap.delete(t)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(n=>{const{unitId:r,subUnitId:s,links:a}=n;a.forEach(d=>{this._registerPosition(r,s,d),this._watchPosition(r,s,d),this._registerRange(r,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:r,silent:s}=t,a=this._hyperLinkModel.getHyperLink(e,n,r);if(!a)return;this._unregisterPosition(r),this._registerPosition(e,n,a),s||(this._unwatchPosition(r),this._watchPosition(e,n,a));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:r}=n;r.forEach(s=>{this._unregisterPosition(s.id),this._unwatchPosition(s.id),this._unregisterRange(s.id),this._unwatchRange(s.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(o.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};z=Pe([A(0,o.Inject(g.RefRangeService)),A(1,o.Inject(exports.HyperLinkModel)),A(2,o.Inject(g.SheetsSelectionsService)),A(3,o.ICommandService)],z);var Te=Object.defineProperty,He=Object.getOwnPropertyDescriptor,Ne=(i,t,e,n)=>{for(var r=n>1?void 0:n?He(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Te(t,e,r),r},te=(i,t)=>(e,n)=>t(e,n,i);let G=class extends o.Disposable{constructor(i,t,e){super(),this._sheetInterceptorService=i,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{var t;if(i.id===g.RemoveSheetCommand.id){const e=i.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const r=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const a=this._hyperLinkModel.getSubUnit(r,s),d=a.map(l=>({id:E.id,params:{unitId:r,subUnitId:s,id:l.id}})),c=a.map(l=>({id:w.id,params:{unitId:r,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};G=Ne([te(0,o.Inject(g.SheetInterceptorService)),te(1,o.IUniverInstanceService),te(2,o.Inject(exports.HyperLinkModel))],G);var Oe=Object.defineProperty,De=Object.getOwnPropertyDescriptor,Ve=(i,t,e,n)=>{for(var r=n>1?void 0:n?De(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Oe(t,e,r),r},ne=(i,t)=>(e,n)=>t(e,n,i);let Y=class extends o.Disposable{constructor(t,e,n){super();C(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let r=n.get(e);return r||(r=new o.ObjectMatrix,n.set(e,r)),r}_isLegalRangeUrl(t,e){var r,s,a;const n=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(r=d.get("gid"))!=null?r:"",range:(s=d.get("range"))!=null?s:"",rangeid:(a=d.get("rangeid"))!=null?a:""};if(c.range&&c.gid){const l=c.gid,p=n.getSheetBySheetId(l);if(!p)return null;const u=U.deserializeRangeWithSheet(c.range).range;if(o.isValidRange(u,p)&&c.range!==x)return{range:u,worksheet:p}}}return null}_registerRange(t,e,n,r,s){var d,c,l,p;const a=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(u=>{var m;return u.rangeType===o.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(m=u.properties)==null?void 0:m.url)})){const u=new o.DisposableCollection;let m=!1;(p=(l=s.body)==null?void 0:l.customRanges)==null||p.forEach(f=>{var h;if(f.rangeType===o.CustomRangeType.HYPERLINK){const _=(h=f.properties)==null?void 0:h.url,S=this._isLegalRangeUrl(t,_);if(S){const{range:y,worksheet:M}=S;m=!0,u.add(this._refRangeService.registerRefRange(y,v=>{const I=g.handleDefaultRangeChangeWithEffectRefCommands(y,v);return I&&o.Rectangle.equals(I,y)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:r,id:f.rangeId,url:`#gid=${e}&range=${I?U.serializeRange(I):x}`}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:r,id:f.rangeId,url:_}}],redos:[]}},M.getUnitId(),M.getSheetId()))}}}),m&&a.setValue(n,r,u)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(r=>{const s=r.getSheetId(),a=this._enusreMap(n,s);r.getCellMatrix().forValue((d,c,l)=>{const p=a.getValue(d,c);p&&p.dispose(),l&&l.p&&this._registerRange(n,s,d,c,l.p)})})};this._univerInstanceService.getAllUnitsForType(o.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(e=>{e.type===o.UniverInstanceType.UNIVER_SHEET&&t(e)}))}_initWorkbookUnload(){this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===o.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(r=>{const s=r.getSheetId();this._enusreMap(n,s).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}})}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===g.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:r,cellValue:s}=e,a=this._enusreMap(n,r);s&&new o.ObjectMatrix(s).forValue((d,c,l)=>{const p=a.getValue(d,c);p&&p.dispose(),l&&l.p&&this._registerRange(n,r,d,c,l.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===B.id){const e=t.params,{unitId:n,subUnitId:r,row:s,col:a}=e,d=g.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:r}),l=this._enusreMap(n,r).getValue(s,a);if(l&&l.dispose(),d){const{worksheet:p}=d,u=p.getCellRaw(s,a);u&&u.p&&this._registerRange(n,r,s,a,u.p)}}}))}};Y=Ve([ne(0,o.ICommandService),ne(1,o.IUniverInstanceService),ne(2,o.Inject(g.RefRangeService))],Y);var xe=Object.defineProperty,$e=Object.getOwnPropertyDescriptor,je=(i,t,e,n)=>{for(var r=n>1?void 0:n?$e(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&xe(t,e,r),r},W=(i,t)=>(e,n)=>t(e,n,i);let q=class extends o.Disposable{constructor(i,t,e,n){super(),this._sheetInterceptorService=i,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(i.id===g.SetRangeValuesCommand.id){const t=i.params,{unitId:e,subUnitId:n}=t,r=[],s=[];return t.cellValue&&new o.ObjectMatrix(t.cellValue).forValue((a,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,a,d);c&&(r.push({id:E.id,params:{unitId:e,subUnitId:n,id:c.id}}),s.push({id:w.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:s,redos:r}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(i.id===g.ClearSelectionContentCommand.id||i.id===g.ClearSelectionAllCommand.id||i.id===g.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),r=g.getSheetCommandTarget(this._univerInstanceService);if(n&&r){const{unitId:s,subUnitId:a}=r;o.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(s,a,d,c);l&&(t.push({id:E.id,params:{unitId:s,subUnitId:a,id:l.id}}),e.push({id:w.id,params:{unitId:s,subUnitId:a,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(g.AFTER_CELL_EDIT,{handler:(i,t,e)=>{if(!i||i.p)return e(i);if(typeof i.v=="string"&&o.Tools.isLegalUrl(i.v)&&i.v[i.v.length-1]!==" "){const{unitId:n,subUnitId:r}=t,s=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET),a=s==null?void 0:s.getSheetBySheetId(r);if(!a)return e(i);const d=a.getBlankCellDocumentModel(i);if(!d.documentModel)return e(i);const c=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:i.v.length,collapsed:!1},body:{dataStream:`${i.v}`,customRanges:[{startIndex:0,endIndex:i.v.length-1,rangeId:o.generateRandomId(),rangeType:o.CustomRangeType.HYPERLINK,properties:{url:i.v}}]},doc:d.documentModel});if(!c)return e(i);const l=d.documentModel.getBody();return o.TextX.apply(l,c.serialize()),e({...i,p:{id:o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:l,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(i)}}))}};q=je([W(0,o.Inject(g.SheetInterceptorService)),W(1,o.Inject(exports.HyperLinkModel)),W(2,o.Inject(g.SheetsSelectionsService)),W(3,o.IUniverInstanceService)],q);var le=(i=>(i[i.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",i[i.UNIVER_DOC=1]="UNIVER_DOC",i[i.UNIVER_SHEET=2]="UNIVER_SHEET",i[i.UNIVER_SLIDE=3]="UNIVER_SLIDE",i[i.UNIVER_PROJECT=4]="UNIVER_PROJECT",i[i.UNRECOGNIZED=-1]="UNRECOGNIZED",i))(le||{}),Ae=Object.defineProperty,We=Object.getOwnPropertyDescriptor,Be=(i,t,e,n)=>{for(var r=n>1?void 0:n?We(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Ae(t,e,r),r},oe=(i,t)=>(e,n)=>t(e,n,i);let J=class extends o.Disposable{constructor(i,t){super(),this._resourceManagerService=i,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const i=e=>{const n=this._hyperLinkModel.getUnit(e),r={};return n?(n.forEach(s=>{r[s.subUnitId]=s.links.map(({display:a,...d})=>d)}),JSON.stringify(r)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:ce,businesses:[le.UNIVER_SHEET],toJson:e=>i(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(r=>{n[r].forEach(a=>{this._hyperLinkModel.addHyperLink(e,r,a)})})}}))}};J=Be([oe(0,o.IResourceManagerService),oe(1,o.Inject(exports.HyperLinkModel))],J);const pe={type:o.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(i,t){if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=i.get(g.SheetInterceptorService),d=g.getSheetCommandTarget(r,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:p,worksheet:u}=d,{link:m}=t,{payload:f,display:h,row:_,column:S,id:y}=m,M=u.getCell(_,S),v=u.getBlankCellDocumentModel(M),I=v.documentModel.getSnapshot(),R=o.Tools.deepClone(I.body);if(!R)return!1;let k;if(h?k=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:R.dataStream.length-2,collapsed:!0},body:{dataStream:`${h}`,customRanges:[{startIndex:0,endIndex:h.length-1,rangeType:o.CustomRangeType.HYPERLINK,rangeId:y,properties:{url:f}}]},doc:v.documentModel}):k=o.BuildTextUtils.customRange.add({body:R,ranges:[{startOffset:0,endOffset:R.dataStream.length-2,collapsed:!1}],rangeId:y,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:f,refId:y}}),!k)return!1;const D=o.TextX.apply(R,k.serialize()),b={p:{...I,body:D},t:o.CellValueType.STRING},T=await a.onWriteCell(p,u,_,S,b),H={unitId:c,subUnitId:l,cellValue:{[m.row]:{[m.column]:T}}},Q={id:g.SetRangeValuesMutation.id,params:H},$=g.SetRangeValuesUndoMutationFactory(i,H),ee={id:g.SetRangeValuesMutation.id,params:$},V=[Q],N=[ee],O=s.getHyperLinkByLocation(c,l,_,S);return O&&(V.push({id:E.id,params:{unitId:c,subUnitId:l,id:O.id}}),N.push({id:w.id,params:{unitId:c,subUnitId:l,link:O}})),await o.sequenceExecuteAsync(V,e)?(n.pushUndoRedo({redoMutations:V,undoMutations:N,unitID:c}),!0):!1}},ue={id:"sheets.command.add-rich-hyper-link",type:o.CommandType.COMMAND,handler:async(i,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,r=i.get(o.ICommandService),s=o.generateRandomId(),{payload:a}=n,d=Z.addCustomRangeBySelectionFactory(i,{unitId:e,rangeId:s,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:a,refId:s}});return d?r.syncExecuteCommand(d.id,d.params):!1}},he={type:o.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(i,t){var b,T;if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=g.getSheetCommandTarget(r,t);if(!a)return!1;const{row:d,column:c,id:l}=t,{unitId:p,subUnitId:u,worksheet:m}=a,f=m.getCell(d,c);if(!f)return!1;const h=m.getCellDocumentModelWithFormula(f);if(!(h!=null&&h.documentModel))return!1;const _=o.Tools.deepClone(h.documentModel.getSnapshot());if(!((T=(b=_.body)==null?void 0:b.customRanges)==null?void 0:T.find(H=>H.rangeId===l)))return!1;const y=o.BuildTextUtils.customRange.delete(i,{documentDataModel:h.documentModel,rangeId:l});if(!y)return!1;const M=o.TextX.apply(_.body,y.serialize()),v=[],I=[],R={unitId:p,subUnitId:u,cellValue:{[d]:{[c]:{p:{..._,body:M},t:o.CellValueType.STRING}}}};v.push({id:g.SetRangeValuesMutation.id,params:R});const k=g.SetRangeValuesUndoMutationFactory(i,R);I.push({id:g.SetRangeValuesMutation.id,params:k});const D=s.getHyperLinkByLocation(p,u,d,c);return D&&(v.push({id:E.id,params:{unitId:p,subUnitId:u,id:l}}),I.push({id:w.id,params:{unitId:p,subUnitId:u,link:{...D}}})),o.sequenceExecute(v,e).result?(n.pushUndoRedo({redoMutations:v,undoMutations:I,unitID:p}),!0):!1}},ge={type:o.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(i,t){var p,u;if(!t)return!1;const{id:e,documentId:n}=t,r=i.get(o.ICommandService),a=i.get(o.IUniverInstanceService).getUnit(n,o.UniverInstanceType.UNIVER_DOC),d=(u=(p=a==null?void 0:a.getBody())==null?void 0:p.customRanges)==null?void 0:u.find(m=>m.rangeId===e);let c=null;d&&d.endIndex===a.getBody().dataStream.length-3&&(c={dataStream:" "});const l=Z.deleteCustomRangeFactory(i,{unitId:n,rangeId:e,insert:c});return l?r.syncExecuteCommand(l.id,l.params):!1}},me={type:o.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(i,t){var ie,se,ae;if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=i.get(g.SheetInterceptorService),d=g.getSheetCommandTarget(r,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:p,id:u}=t,{workbook:m,worksheet:f,unitId:h,subUnitId:_}=d,{payload:S,display:y=""}=c,M=f.getCell(l,p);if(!M)return!1;const v=f.getCellDocumentModelWithFormula(M);if(!(v!=null&&v.documentModel))return!1;const I=v.documentModel.getSnapshot(),R=(se=(ie=I.body)==null?void 0:ie.customRanges)==null?void 0:se.find(ve=>ve.rangeId===u);if(!R)return!1;const k=o.generateRandomId(),P=(ae=o.getBodySlice(v.documentModel.getBody(),R.startIndex,R.endIndex+1).textRuns)==null?void 0:ae[0];P&&(P.ed=y.length+1);const b=Z.replaceSelectionFactory(i,{unitId:h,body:{dataStream:`${y}`,customRanges:[{rangeId:k,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:y.length-1,properties:{url:S}}],textRuns:P?[P]:void 0},selection:{startOffset:R.startIndex,endOffset:R.endIndex+1,collapsed:!1},doc:v.documentModel});if(!b)return!1;const T=o.TextX.apply(o.Tools.deepClone(I.body),b.textX.serialize()),H={p:{...I,body:T},t:o.CellValueType.STRING},Q=await a.onWriteCell(m,f,l,p,H),$={id:g.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:_,cellValue:{[l]:{[p]:Q}}}},ee=g.SetRangeValuesUndoMutationFactory(i,$.params),V={id:g.SetRangeValuesMutation.id,params:ee},N=[$],O=[V],j=s.getHyperLinkByLocation(h,_,l,p);return j&&(N.push({id:E.id,params:{unitId:h,subUnitId:_,id:j.id}}),O.push({id:w.id,params:{unitId:h,subUnitId:_,link:j}})),await o.sequenceExecuteAsync(N,e)?(n.pushUndoRedo({redoMutations:N,undoMutations:O,unitID:h}),!0):!1}},fe={type:o.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(i,t)=>{var h,_,S,y;if(!t)return!1;const{documentId:e,payload:n,id:r}=t,s=i.get(o.IUniverInstanceService),a=i.get(o.ICommandService),d=s.getUnit(e,o.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(_=(h=d.getBody())==null?void 0:h.customRanges)==null?void 0:_.find(M=>M.rangeId===r);if(!c)return!1;const l=(S=t.payload.display)!=null?S:"",p=o.generateRandomId(),m=(y=o.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:y[0];m&&(m.ed=l.length+1);const f=Z.replaceSelectionFactory(i,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:p,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:m?[m]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return f?a.syncExecuteCommand(f.id,f.params):!1}};var Fe=Object.defineProperty,Ke=Object.getOwnPropertyDescriptor,ze=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ke(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Fe(t,e,r),r},Ge=(i,t)=>(e,n)=>t(e,n,i);let X=class extends o.Disposable{constructor(i){super(),this._commandService=i,this._registerCommands()}_registerCommands(){[pe,me,he,fe,ge,ue,w,F,E,K,B].forEach(i=>{this._commandService.registerCommand(i)})}};X=ze([Ge(0,o.ICommandService)],X);var Ye=Object.defineProperty,qe=Object.getOwnPropertyDescriptor,Je=(i,t,e,n)=>{for(var r=n>1?void 0:n?qe(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Ye(t,e,r),r},re=(i,t)=>(e,n)=>t(e,n,i);exports.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${L.SHEET}=${e}${n?`&${typeof n=="string"?L.DEFINE_NAME:L.RANGE}=${typeof n=="string"?n:U.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,r,s;if(t.startsWith("#")){const a=new URLSearchParams(t.slice(1)),d={gid:(e=a.get("gid"))!=null?e:"",range:(n=a.get("range"))!=null?n:"",rangeid:(r=a.get("rangeid"))!=null?r:"",unitid:(s=a.get("unitid"))!=null?s:""},c=this._getURLName(d);return{type:c.type,name:c.name,url:t,searchObj:d}}else return{type:L.URL,name:t,url:t,searchObj:null}}_getURLName(t){var p;const{gid:e,range:n,rangeid:r,unitid:s}=t,a=s?this._univerInstanceService.getUnit(s,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),d={type:L.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!a)return d;const c=e?a.getSheetBySheetId(e):a.getActiveSheet(),l=(p=c==null?void 0:c.getName())!=null?p:"";if(n){if(!c)return d;const u=U.deserializeRangeWithSheet(n).range;return o.isValidRange(u,c)&&n!==x?{type:L.RANGE,name:U.serializeRangeWithSheet(l,u)}:d}if(r){const u=this._definedNamesService.getValueById(a.getUnitId(),r);return u?{type:L.DEFINE_NAME,name:u.formulaOrRefString}:d}if(e){const u=a.getSheetBySheetId(e);return u?{type:L.SHEET,name:u.getName()}:d}return d}};exports.SheetsHyperLinkParserService=Je([re(0,o.IUniverInstanceService),re(1,o.Inject(o.LocaleService)),re(2,U.IDefinedNamesService)],exports.SheetsHyperLinkParserService);var _e=Object.defineProperty,Xe=Object.getOwnPropertyDescriptor,Ze=(i,t,e)=>t in i?_e(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,Qe=(i,t,e,n)=>{for(var r=n>1?void 0:n?Xe(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&_e(t,e,r),r},de=(i,t)=>(e,n)=>t(e,n,i),ye=(i,t,e)=>Ze(i,typeof t!="symbol"?t+"":t,e);exports.UniverSheetsHyperLinkPlugin=class extends o.Plugin{constructor(t=Ee,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...r}=this._config;this._configService.setConfig(we,r)}onStarting(){o.registerDependencies(this._injector,[[exports.HyperLinkModel],[exports.SheetsHyperLinkParserService],[J],[X],[z],[q],[G],[Y]]),o.touchDependencies(this._injector,[[z],[J],[X],[q],[G],[Y]])}};ye(exports.UniverSheetsHyperLinkPlugin,"pluginName",ce);ye(exports.UniverSheetsHyperLinkPlugin,"type",o.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsHyperLinkPlugin=Qe([o.DependentOn(g.UniverSheetsPlugin),de(1,o.Inject(o.Injector)),de(2,o.IConfigService)],exports.UniverSheetsHyperLinkPlugin);exports.AddHyperLinkCommand=pe;exports.AddHyperLinkMutation=w;exports.AddRichHyperLinkCommand=ue;exports.CancelHyperLinkCommand=he;exports.CancelRichHyperLinkCommand=ge;exports.ERROR_RANGE=x;exports.RemoveHyperLinkMutation=E;exports.SheetHyperLinkType=L;exports.UpdateHyperLinkCommand=me;exports.UpdateHyperLinkMutation=F;exports.UpdateHyperLinkRefMutation=K;exports.UpdateRichHyperLinkCommand=fe;
1
+ "use strict";var Ie=Object.defineProperty;var Re=(i,t,e)=>t in i?Ie(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var C=(i,t,e)=>Re(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),Me=require("rxjs"),g=require("@univerjs/sheets"),U=require("@univerjs/engine-formula"),Z=require("@univerjs/docs");var Ce=Object.defineProperty,Ue=Object.getOwnPropertyDescriptor,Le=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ue(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Ce(t,e,r),r},we=(i,t)=>(e,n)=>t(e,n,i);exports.HyperLinkModel=class extends o.Disposable{constructor(e){super();C(this,"_linkUpdate$",new Me.Subject);C(this,"linkUpdate$",this._linkUpdate$.asObservable());C(this,"_linkMap",new Map);C(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let r=this._linkMap.get(e);r||(r=new Map,this._linkMap.set(e,r));let s=r.get(n);s||(s=new o.ObjectMatrix,r.set(n,s));let a=this._linkPositionMap.get(e);a||(a=new Map,this._linkPositionMap.set(e,a));let d=a.get(n);return d||(d=new Map,a.set(n,d)),{matrix:s,positionMap:d}}addHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n);return s.setValue(r.row,r.column,r),a.set(r.id,{row:r.row,column:r.column,link:r}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:r,type:"add"}),!0}updateHyperLink(e,n,r,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(r);if(!l)return!0;const p=d.getValue(l.row,l.column);return p&&(Object.assign(p,s),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:p.display,payload:p.payload},id:r,type:"update",silent:a})),!0}updateHyperLinkRef(e,n,r,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(r);if(!l)return!0;let p=d.getValue(l.row,l.column);return!p||p.id!==r?p=l.link:d.realDeleteValue(l.row,l.column),Object.assign(p,s),c.set(r,{...s,link:p}),d.setValue(s.row,s.column,p),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:r,type:"updateRef",silent:a}),!0}removeHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(r);if(!d)return!1;a.delete(r);const c=s.getValue(d.row,d.column);return c&&c.id===r&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(r);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,r,s){const{matrix:a}=this._ensureMap(e,n);return a.getValue(r,s)}getHyperLinkByLocationSync(e,n,r,s){var u,m,f,h,_;const{matrix:a}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,o.UniverInstanceType.UNIVER_SHEET),c=(u=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:u.getCellRaw(r,s),l=((_=(h=c==null?void 0:c.v)!=null?h:(f=(m=c==null?void 0:c.p)==null?void 0:m.body)==null?void 0:f.dataStream.slice(0,-2))!=null?_:"").toString(),p=a.getValue(r,s);if(p)return{...p,display:l}}getSubUnit(e,n){const{matrix:r}=this._ensureMap(e,n),s=[];return r.forValue((a,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(r=>{const s=this.getSubUnit(e,r);return{unitId:e,subUnitId:r,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}};exports.HyperLinkModel=Le([we(0,o.IUniverInstanceService)],exports.HyperLinkModel);var L=(i=>(i.SHEET="gid",i.RANGE="range",i.DEFINE_NAME="rangeid",i.INVALID="invalid",i.URL="url",i))(L||{});const Ee="sheets-hyper-link.config",oe={},w={type:o.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,link:s}=t;return e.addHyperLink(n,r,s)}},E={type:o.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,id:s}=t;return e.removeHyperLink(n,r,s)}},F={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,payload:s,id:a}=t;return e.updateHyperLink(n,r,a,s,!1)}},K={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,id:s,row:a,column:d,silent:c}=t;return e.updateHyperLinkRef(n,r,s,{row:a,column:d},c)}},B={type:o.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(i,t){var f,h,_;if(!t)return!1;const{unitId:e,subUnitId:n,row:r,col:s,id:a,url:d}=t,c=i.get(o.IUniverInstanceService),l=g.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:p}=l,u=p.getCellRaw(r,s),m=(_=(h=(f=u==null?void 0:u.p)==null?void 0:f.body)==null?void 0:h.customRanges)==null?void 0:_.find(y=>y.rangeType===o.CustomRangeType.HYPERLINK&&y.rangeId===a);return m&&(m.properties.url=d),!0}},le="SHEET_HYPER_LINK_PLUGIN",x="err";var ke=Object.defineProperty,be=Object.getOwnPropertyDescriptor,Pe=(i,t,e,n)=>{for(var r=n>1?void 0:n?be(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&ke(t,e,r),r},A=(i,t)=>(e,n)=>t(e,n,i);let z=class extends o.Disposable{constructor(t,e,n,r){super();C(this,"_disposableMap",new Map);C(this,"_watchDisposableMap",new Map);C(this,"_rangeDisableMap",new Map);C(this,"_rangeWatcherMap",new Map);C(this,"_handlePositionChange",(t,e,n,r,s)=>{const a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return r?{redos:[{id:K.id,params:{unitId:t,subUnitId:e,id:n.id,row:r.startRow,column:r.startColumn,silent:s}}],undos:[{id:K.id,params:{unitId:t,subUnitId:e,id:n.id,row:a.startRow,column:a.startColumn,silent:s}}]}:{redos:[{id:E.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:w.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=r,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const r=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},a=d=>{const c=g.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===s.startColumn&&l.startRow===s.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(r,this._refRangeService.registerRefRange(s,a,t,e))}_watchPosition(t,e,n){const r=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(r,this._refRangeService.watchRange(t,e,s,(a,d)=>{const{redos:c}=this._handlePositionChange(t,e,n,d,!0);o.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(t){const e=this._disposableMap.get(t);e==null||e.dispose(),this._disposableMap.delete(t)}_unwatchPosition(t){const e=this._watchDisposableMap.get(t);e==null||e.dispose(),this._watchDisposableMap.delete(t)}_registerRange(t,e,n,r=!1){var s,a,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(s=c.get("gid"))!=null?s:"",range:(a=c.get("range"))!=null?a:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const p=l.gid,u=U.deserializeRangeWithSheet(l.range).range;if(o.isValidRange(u)&&l.range!==x){const m=f=>{const h=g.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(u,f,{selectionManagerService:this._selectionManagerService});return h&&U.serializeRange(h)===U.serializeRange(u)?{redos:[],undos:[]}:{redos:[{id:F.id,params:{unitId:t,subUnitId:p,id:e,payload:{payload:`#gid=${p}&range=${h?U.serializeRange(h):"err"}`}}}],undos:[{id:F.id,params:{unitId:t,subUnitId:p,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(u,m,t,p)),r||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,p,u,(f,h)=>{this._hyperLinkModel.updateHyperLink(t,p,e,{payload:`#gid=${p}&range=${h?U.serializeRange(h):"err"}`},!0)},!0))}}}}_unregisterRange(t){const e=this._rangeDisableMap.get(t);e==null||e.dispose(),this._rangeDisableMap.delete(t)}_unwatchRange(t){const e=this._rangeWatcherMap.get(t);e==null||e.dispose(),this._rangeWatcherMap.delete(t)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(n=>{const{unitId:r,subUnitId:s,links:a}=n;a.forEach(d=>{this._registerPosition(r,s,d),this._watchPosition(r,s,d),this._registerRange(r,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:r,silent:s}=t,a=this._hyperLinkModel.getHyperLink(e,n,r);if(!a)return;this._unregisterPosition(r),this._registerPosition(e,n,a),s||(this._unwatchPosition(r),this._watchPosition(e,n,a));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:r}=n;r.forEach(s=>{this._unregisterPosition(s.id),this._unwatchPosition(s.id),this._unregisterRange(s.id),this._unwatchRange(s.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(o.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};z=Pe([A(0,o.Inject(g.RefRangeService)),A(1,o.Inject(exports.HyperLinkModel)),A(2,o.Inject(g.SheetsSelectionsService)),A(3,o.ICommandService)],z);var Te=Object.defineProperty,He=Object.getOwnPropertyDescriptor,Ne=(i,t,e,n)=>{for(var r=n>1?void 0:n?He(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Te(t,e,r),r},te=(i,t)=>(e,n)=>t(e,n,i);let G=class extends o.Disposable{constructor(i,t,e){super(),this._sheetInterceptorService=i,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{var t;if(i.id===g.RemoveSheetCommand.id){const e=i.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const r=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const a=this._hyperLinkModel.getSubUnit(r,s),d=a.map(l=>({id:E.id,params:{unitId:r,subUnitId:s,id:l.id}})),c=a.map(l=>({id:w.id,params:{unitId:r,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};G=Ne([te(0,o.Inject(g.SheetInterceptorService)),te(1,o.IUniverInstanceService),te(2,o.Inject(exports.HyperLinkModel))],G);var Oe=Object.defineProperty,De=Object.getOwnPropertyDescriptor,Ve=(i,t,e,n)=>{for(var r=n>1?void 0:n?De(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Oe(t,e,r),r},ne=(i,t)=>(e,n)=>t(e,n,i);let Y=class extends o.Disposable{constructor(t,e,n){super();C(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let r=n.get(e);return r||(r=new o.ObjectMatrix,n.set(e,r)),r}_isLegalRangeUrl(t,e){var r,s,a;const n=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(r=d.get("gid"))!=null?r:"",range:(s=d.get("range"))!=null?s:"",rangeid:(a=d.get("rangeid"))!=null?a:""};if(c.range&&c.gid){const l=c.gid,p=n.getSheetBySheetId(l);if(!p)return null;const u=U.deserializeRangeWithSheet(c.range).range;if(o.isValidRange(u,p)&&c.range!==x)return{range:u,worksheet:p}}}return null}_registerRange(t,e,n,r,s){var d,c,l,p;const a=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(u=>{var m;return u.rangeType===o.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(m=u.properties)==null?void 0:m.url)})){const u=new o.DisposableCollection;let m=!1;(p=(l=s.body)==null?void 0:l.customRanges)==null||p.forEach(f=>{var h;if(f.rangeType===o.CustomRangeType.HYPERLINK){const _=(h=f.properties)==null?void 0:h.url,y=this._isLegalRangeUrl(t,_);if(y){const{range:v,worksheet:M}=y;m=!0,u.add(this._refRangeService.registerRefRange(v,S=>{const I=g.handleDefaultRangeChangeWithEffectRefCommands(v,S);return I&&o.Rectangle.equals(I,v)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:r,id:f.rangeId,url:`#gid=${e}&range=${I?U.serializeRange(I):x}`}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:r,id:f.rangeId,url:_}}],redos:[]}},M.getUnitId(),M.getSheetId()))}}}),m&&a.setValue(n,r,u)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(r=>{const s=r.getSheetId(),a=this._enusreMap(n,s);r.getCellMatrix().forValue((d,c,l)=>{const p=a.getValue(d,c);p&&p.dispose(),l&&l.p&&this._registerRange(n,s,d,c,l.p)})})};this._univerInstanceService.getAllUnitsForType(o.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(e=>{e.type===o.UniverInstanceType.UNIVER_SHEET&&t(e)}))}_initWorkbookUnload(){this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===o.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(r=>{const s=r.getSheetId();this._enusreMap(n,s).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}})}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===g.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:r,cellValue:s}=e,a=this._enusreMap(n,r);s&&new o.ObjectMatrix(s).forValue((d,c,l)=>{const p=a.getValue(d,c);p&&p.dispose(),l&&l.p&&this._registerRange(n,r,d,c,l.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===B.id){const e=t.params,{unitId:n,subUnitId:r,row:s,col:a}=e,d=g.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:r}),l=this._enusreMap(n,r).getValue(s,a);if(l&&l.dispose(),d){const{worksheet:p}=d,u=p.getCellRaw(s,a);u&&u.p&&this._registerRange(n,r,s,a,u.p)}}}))}};Y=Ve([ne(0,o.ICommandService),ne(1,o.IUniverInstanceService),ne(2,o.Inject(g.RefRangeService))],Y);var xe=Object.defineProperty,$e=Object.getOwnPropertyDescriptor,je=(i,t,e,n)=>{for(var r=n>1?void 0:n?$e(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&xe(t,e,r),r},W=(i,t)=>(e,n)=>t(e,n,i);let q=class extends o.Disposable{constructor(i,t,e,n){super(),this._sheetInterceptorService=i,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(i.id===g.SetRangeValuesCommand.id){const t=i.params,{unitId:e,subUnitId:n}=t,r=[],s=[];return t.cellValue&&new o.ObjectMatrix(t.cellValue).forValue((a,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,a,d);c&&(r.push({id:E.id,params:{unitId:e,subUnitId:n,id:c.id}}),s.push({id:w.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:s,redos:r}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(i.id===g.ClearSelectionContentCommand.id||i.id===g.ClearSelectionAllCommand.id||i.id===g.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),r=g.getSheetCommandTarget(this._univerInstanceService);if(n&&r){const{unitId:s,subUnitId:a}=r;o.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(s,a,d,c);l&&(t.push({id:E.id,params:{unitId:s,subUnitId:a,id:l.id}}),e.push({id:w.id,params:{unitId:s,subUnitId:a,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(g.AFTER_CELL_EDIT,{handler:(i,t,e)=>{if(!i||i.p)return e(i);if(typeof i.v=="string"&&o.Tools.isLegalUrl(i.v)&&i.v[i.v.length-1]!==" "){const{unitId:n,subUnitId:r}=t,s=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET),a=s==null?void 0:s.getSheetBySheetId(r);if(!a)return e(i);const d=a.getBlankCellDocumentModel(i);if(!d.documentModel)return e(i);const c=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:i.v.length,collapsed:!1},body:{dataStream:`${i.v}`,customRanges:[{startIndex:0,endIndex:i.v.length-1,rangeId:o.generateRandomId(),rangeType:o.CustomRangeType.HYPERLINK,properties:{url:i.v}}]},doc:d.documentModel});if(!c)return e(i);const l=d.documentModel.getBody();return o.TextX.apply(l,c.serialize()),e({...i,p:{id:o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:l,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(i)}}))}};q=je([W(0,o.Inject(g.SheetInterceptorService)),W(1,o.Inject(exports.HyperLinkModel)),W(2,o.Inject(g.SheetsSelectionsService)),W(3,o.IUniverInstanceService)],q);var pe=(i=>(i[i.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",i[i.UNIVER_DOC=1]="UNIVER_DOC",i[i.UNIVER_SHEET=2]="UNIVER_SHEET",i[i.UNIVER_SLIDE=3]="UNIVER_SLIDE",i[i.UNIVER_PROJECT=4]="UNIVER_PROJECT",i[i.UNRECOGNIZED=-1]="UNRECOGNIZED",i))(pe||{}),Ae=Object.defineProperty,We=Object.getOwnPropertyDescriptor,Be=(i,t,e,n)=>{for(var r=n>1?void 0:n?We(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Ae(t,e,r),r},de=(i,t)=>(e,n)=>t(e,n,i);let J=class extends o.Disposable{constructor(i,t){super(),this._resourceManagerService=i,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const i=e=>{const n=this._hyperLinkModel.getUnit(e),r={};return n?(n.forEach(s=>{r[s.subUnitId]=s.links.map(({display:a,...d})=>d)}),JSON.stringify(r)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:le,businesses:[pe.UNIVER_SHEET],toJson:e=>i(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(r=>{n[r].forEach(a=>{this._hyperLinkModel.addHyperLink(e,r,a)})})}}))}};J=Be([de(0,o.IResourceManagerService),de(1,o.Inject(exports.HyperLinkModel))],J);const ue={type:o.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(i,t){if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=i.get(g.SheetInterceptorService),d=g.getSheetCommandTarget(r,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:p,worksheet:u}=d,{link:m}=t,{payload:f,display:h,row:_,column:y,id:v}=m,M=u.getCell(_,y),S=u.getBlankCellDocumentModel(M),I=S.documentModel.getSnapshot(),R=o.Tools.deepClone(I.body);if(!R)return!1;let k;if(h?k=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:R.dataStream.length-2,collapsed:R.dataStream.length-2===0},body:{dataStream:`${h}`,customRanges:[{startIndex:0,endIndex:h.length-1,rangeType:o.CustomRangeType.HYPERLINK,rangeId:v,properties:{url:f}}]},doc:S.documentModel}):k=o.BuildTextUtils.customRange.add({body:R,ranges:[{startOffset:0,endOffset:R.dataStream.length-2,collapsed:!1}],rangeId:v,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:f,refId:v}}),!k)return!1;const D=o.TextX.apply(R,k.serialize()),b={p:{...I,body:D},t:o.CellValueType.STRING},T=await a.onWriteCell(p,u,_,y,b),H={unitId:c,subUnitId:l,cellValue:{[m.row]:{[m.column]:T}}},Q={id:g.SetRangeValuesMutation.id,params:H},$=g.SetRangeValuesUndoMutationFactory(i,H),ee={id:g.SetRangeValuesMutation.id,params:$},V=[Q],N=[ee],O=s.getHyperLinkByLocation(c,l,_,y);return O&&(V.push({id:E.id,params:{unitId:c,subUnitId:l,id:O.id}}),N.push({id:w.id,params:{unitId:c,subUnitId:l,link:O}})),await o.sequenceExecuteAsync(V,e)?(n.pushUndoRedo({redoMutations:V,undoMutations:N,unitID:c}),!0):!1}},he={id:"sheets.command.add-rich-hyper-link",type:o.CommandType.COMMAND,handler:async(i,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,r=i.get(o.ICommandService),s=o.generateRandomId(),{payload:a}=n,d=Z.addCustomRangeBySelectionFactory(i,{unitId:e,rangeId:s,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:a,refId:s}});return d?r.syncExecuteCommand(d.id,d.params):!1}},ge={type:o.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(i,t){var b,T;if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=g.getSheetCommandTarget(r,t);if(!a)return!1;const{row:d,column:c,id:l}=t,{unitId:p,subUnitId:u,worksheet:m}=a,f=m.getCell(d,c);if(!f)return!1;const h=m.getCellDocumentModelWithFormula(f);if(!(h!=null&&h.documentModel))return!1;const _=o.Tools.deepClone(h.documentModel.getSnapshot()),y=(T=(b=_.body)==null?void 0:b.customRanges)==null?void 0:T.find(H=>`${H.rangeId}`===l);if(!y)return!1;const v=o.BuildTextUtils.customRange.delete(i,{documentDataModel:h.documentModel,rangeId:y.rangeId});if(!v)return!1;const M=o.TextX.apply(_.body,v.serialize()),S=[],I=[],R={unitId:p,subUnitId:u,cellValue:{[d]:{[c]:{p:{..._,body:M},t:o.CellValueType.STRING}}}};S.push({id:g.SetRangeValuesMutation.id,params:R});const k=g.SetRangeValuesUndoMutationFactory(i,R);I.push({id:g.SetRangeValuesMutation.id,params:k});const D=s.getHyperLinkByLocation(p,u,d,c);return D&&(S.push({id:E.id,params:{unitId:p,subUnitId:u,id:l}}),I.push({id:w.id,params:{unitId:p,subUnitId:u,link:{...D}}})),o.sequenceExecute(S,e).result?(n.pushUndoRedo({redoMutations:S,undoMutations:I,unitID:p}),!0):!1}},me={type:o.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(i,t){var p,u;if(!t)return!1;const{id:e,documentId:n}=t,r=i.get(o.ICommandService),a=i.get(o.IUniverInstanceService).getUnit(n,o.UniverInstanceType.UNIVER_DOC),d=(u=(p=a==null?void 0:a.getBody())==null?void 0:p.customRanges)==null?void 0:u.find(m=>m.rangeId===e);let c=null;d&&d.endIndex===a.getBody().dataStream.length-3&&(c={dataStream:" "});const l=Z.deleteCustomRangeFactory(i,{unitId:n,rangeId:e,insert:c});return l?r.syncExecuteCommand(l.id,l.params):!1}},fe={type:o.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(i,t){var ie,se,ae;if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=i.get(g.SheetInterceptorService),d=g.getSheetCommandTarget(r,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:p,id:u}=t,{workbook:m,worksheet:f,unitId:h,subUnitId:_}=d,{payload:y,display:v=""}=c,M=f.getCell(l,p);if(!M)return!1;const S=f.getCellDocumentModelWithFormula(M);if(!(S!=null&&S.documentModel))return!1;const I=S.documentModel.getSnapshot(),R=(se=(ie=I.body)==null?void 0:ie.customRanges)==null?void 0:se.find(Se=>`${Se.rangeId}`===u);if(!R)return!1;const k=o.generateRandomId(),P=(ae=o.getBodySlice(S.documentModel.getBody(),R.startIndex,R.endIndex+1).textRuns)==null?void 0:ae[0];P&&(P.ed=v.length+1);const b=Z.replaceSelectionFactory(i,{unitId:h,body:{dataStream:`${v}`,customRanges:[{rangeId:k,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:v.length-1,properties:{url:y}}],textRuns:P?[P]:void 0},selection:{startOffset:R.startIndex,endOffset:R.endIndex+1,collapsed:!1},doc:S.documentModel});if(!b)return!1;const T=o.TextX.apply(o.Tools.deepClone(I.body),b.textX.serialize()),H={p:{...I,body:T},t:o.CellValueType.STRING},Q=await a.onWriteCell(m,f,l,p,H),$={id:g.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:_,cellValue:{[l]:{[p]:Q}}}},ee=g.SetRangeValuesUndoMutationFactory(i,$.params),V={id:g.SetRangeValuesMutation.id,params:ee},N=[$],O=[V],j=s.getHyperLinkByLocation(h,_,l,p);return j&&(N.push({id:E.id,params:{unitId:h,subUnitId:_,id:j.id}}),O.push({id:w.id,params:{unitId:h,subUnitId:_,link:j}})),await o.sequenceExecuteAsync(N,e)?(n.pushUndoRedo({redoMutations:N,undoMutations:O,unitID:h}),!0):!1}},_e={type:o.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(i,t)=>{var h,_,y,v;if(!t)return!1;const{documentId:e,payload:n,id:r}=t,s=i.get(o.IUniverInstanceService),a=i.get(o.ICommandService),d=s.getUnit(e,o.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(_=(h=d.getBody())==null?void 0:h.customRanges)==null?void 0:_.find(M=>M.rangeId===r);if(!c)return!1;const l=(y=t.payload.display)!=null?y:"",p=o.generateRandomId(),m=(v=o.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:v[0];m&&(m.ed=l.length+1);const f=Z.replaceSelectionFactory(i,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:p,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:m?[m]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return f?a.syncExecuteCommand(f.id,f.params):!1}};var Fe=Object.defineProperty,Ke=Object.getOwnPropertyDescriptor,ze=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ke(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Fe(t,e,r),r},Ge=(i,t)=>(e,n)=>t(e,n,i);let X=class extends o.Disposable{constructor(i){super(),this._commandService=i,this._registerCommands()}_registerCommands(){[ue,fe,ge,_e,me,he,w,F,E,K,B].forEach(i=>{this._commandService.registerCommand(i)})}};X=ze([Ge(0,o.ICommandService)],X);var Ye=Object.defineProperty,qe=Object.getOwnPropertyDescriptor,Je=(i,t,e,n)=>{for(var r=n>1?void 0:n?qe(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Ye(t,e,r),r},re=(i,t)=>(e,n)=>t(e,n,i);exports.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${L.SHEET}=${e}${n?`&${typeof n=="string"?L.DEFINE_NAME:L.RANGE}=${typeof n=="string"?n:U.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,r,s;if(t.startsWith("#")){const a=new URLSearchParams(t.slice(1)),d={gid:(e=a.get("gid"))!=null?e:"",range:(n=a.get("range"))!=null?n:"",rangeid:(r=a.get("rangeid"))!=null?r:"",unitid:(s=a.get("unitid"))!=null?s:""},c=this._getURLName(d);return{type:c.type,name:c.name,url:t,searchObj:d}}else return{type:L.URL,name:t,url:t,searchObj:null}}_getURLName(t){var p;const{gid:e,range:n,rangeid:r,unitid:s}=t,a=s?this._univerInstanceService.getUnit(s,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),d={type:L.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!a)return d;const c=e?a.getSheetBySheetId(e):a.getActiveSheet(),l=(p=c==null?void 0:c.getName())!=null?p:"";if(n){if(!c)return d;const u=U.deserializeRangeWithSheet(n).range;return o.isValidRange(u,c)&&n!==x?{type:L.RANGE,name:U.serializeRangeWithSheet(l,u)}:d}if(r){const u=this._definedNamesService.getValueById(a.getUnitId(),r);return u?{type:L.DEFINE_NAME,name:u.formulaOrRefString}:d}if(e){const u=a.getSheetBySheetId(e);return u?{type:L.SHEET,name:u.getName()}:d}return d}};exports.SheetsHyperLinkParserService=Je([re(0,o.IUniverInstanceService),re(1,o.Inject(o.LocaleService)),re(2,U.IDefinedNamesService)],exports.SheetsHyperLinkParserService);var ye=Object.defineProperty,Xe=Object.getOwnPropertyDescriptor,Ze=(i,t,e)=>t in i?ye(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,Qe=(i,t,e,n)=>{for(var r=n>1?void 0:n?Xe(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&ye(t,e,r),r},ce=(i,t)=>(e,n)=>t(e,n,i),ve=(i,t,e)=>Ze(i,typeof t!="symbol"?t+"":t,e);exports.UniverSheetsHyperLinkPlugin=class extends o.Plugin{constructor(t=oe,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...r}=o.merge({},oe,this._config);this._configService.setConfig(Ee,r)}onStarting(){o.registerDependencies(this._injector,[[exports.HyperLinkModel],[exports.SheetsHyperLinkParserService],[J],[X],[z],[q],[G],[Y]]),o.touchDependencies(this._injector,[[z],[J],[X],[q],[G],[Y]])}};ve(exports.UniverSheetsHyperLinkPlugin,"pluginName",le);ve(exports.UniverSheetsHyperLinkPlugin,"type",o.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsHyperLinkPlugin=Qe([o.DependentOn(g.UniverSheetsPlugin),ce(1,o.Inject(o.Injector)),ce(2,o.IConfigService)],exports.UniverSheetsHyperLinkPlugin);exports.AddHyperLinkCommand=ue;exports.AddHyperLinkMutation=w;exports.AddRichHyperLinkCommand=he;exports.CancelHyperLinkCommand=ge;exports.CancelRichHyperLinkCommand=me;exports.ERROR_RANGE=x;exports.RemoveHyperLinkMutation=E;exports.SheetHyperLinkType=L;exports.UpdateHyperLinkCommand=fe;exports.UpdateHyperLinkMutation=F;exports.UpdateHyperLinkRefMutation=K;exports.UpdateRichHyperLinkCommand=_e;
package/lib/es/facade.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { FWorkbook as l, FRange as h } from "@univerjs/sheets/facade";
2
2
  import { SheetsHyperLinkParserService as m, AddHyperLinkCommand as k, UpdateHyperLinkCommand as y, CancelHyperLinkCommand as I } from "@univerjs/sheets-hyper-link";
3
- import { generateRandomId as _, CustomRangeType as g, DataStreamTreeTokenType as c } from "@univerjs/core";
3
+ import { generateRandomId as g, CustomRangeType as _, DataStreamTreeTokenType as c } from "@univerjs/core";
4
4
  class S extends l {
5
5
  createSheetHyperlink(e, t) {
6
6
  return this._injector.get(m).buildHyperLink(this.getId(), e, t);
@@ -17,13 +17,6 @@ class S extends l {
17
17
  l.extend(S);
18
18
  class x extends h {
19
19
  // #region hyperlink
20
- /**
21
- * Set hyperlink in the cell in the range.
22
- * [!important] This method is async.
23
- * @param url url
24
- * @param label optional, label of the url
25
- * @returns success or not
26
- */
27
20
  setHyperLink(e, t) {
28
21
  const n = {
29
22
  unitId: this.getUnitId(),
@@ -33,7 +26,7 @@ class x extends h {
33
26
  column: this._range.startColumn,
34
27
  payload: e,
35
28
  display: t,
36
- id: _()
29
+ id: g()
37
30
  }
38
31
  };
39
32
  return this._commandService.executeCommand(k.id, n);
@@ -45,10 +38,10 @@ class x extends h {
45
38
  getHyperLinks() {
46
39
  var t, n, i;
47
40
  const e = this._worksheet.getCellRaw(this._range.startRow, this._range.startColumn);
48
- return e != null && e.p ? (i = (n = (t = e.p.body) == null ? void 0 : t.customRanges) == null ? void 0 : n.filter((r) => r.rangeType === g.HYPERLINK).map((r) => {
41
+ return e != null && e.p ? (i = (n = (t = e.p.body) == null ? void 0 : t.customRanges) == null ? void 0 : n.filter((r) => r.rangeType === _.HYPERLINK).map((r) => {
49
42
  var s, a, o, d, p;
50
43
  return {
51
- id: `${r.rangeId}_${r.startIndex}_${r.endIndex}`,
44
+ id: `${r.rangeId}`,
52
45
  startIndex: r.startIndex,
53
46
  endIndex: r.endIndex,
54
47
  url: (a = (s = r.properties) == null ? void 0 : s.url) != null ? a : "",
package/lib/es/index.js CHANGED
@@ -1,20 +1,20 @@
1
- var Te = Object.defineProperty;
2
- var Ae = (s, e, t) => e in s ? Te(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
- var w = (s, e, t) => Ae(s, typeof e != "symbol" ? e + "" : e, t);
4
- import { Disposable as V, ObjectMatrix as q, UniverInstanceType as I, IUniverInstanceService as E, CommandType as L, CustomRangeType as b, Inject as M, ICommandService as P, sequenceExecuteAsync as ve, isValidRange as Re, toDisposable as We, DisposableCollection as Be, Rectangle as je, Range as Fe, Tools as oe, BuildTextUtils as Z, generateRandomId as de, TextX as ce, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as Ke, IResourceManagerService as Ye, IUndoRedoService as Se, CellValueType as Ie, sequenceExecute as Ge, getBodySlice as Pe, LocaleService as ze, DependentOn as Je, Injector as Xe, Plugin as qe, registerDependencies as Ze, touchDependencies as Qe, IConfigService as et } from "@univerjs/core";
5
- import { Subject as tt } from "rxjs";
6
- import { getSheetCommandTarget as j, RefRangeService as Ne, SheetsSelectionsService as Oe, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as nt, handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests as rt, SheetInterceptorService as le, RemoveSheetCommand as st, handleDefaultRangeChangeWithEffectRefCommands as it, SetRangeValuesMutation as H, SetRangeValuesCommand as at, ClearSelectionContentCommand as ot, ClearSelectionAllCommand as dt, ClearSelectionFormatCommand as ct, AFTER_CELL_EDIT as lt, SetRangeValuesUndoMutationFactory as Me, UniverSheetsPlugin as ut } from "@univerjs/sheets";
7
- import { deserializeRangeWithSheet as Ce, serializeRange as B, serializeRangeWithSheet as pt, IDefinedNamesService as ht } from "@univerjs/engine-formula";
8
- import { addCustomRangeBySelectionFactory as gt, deleteCustomRangeFactory as ft, replaceSelectionFactory as ke } from "@univerjs/docs";
9
- var _t = Object.defineProperty, mt = Object.getOwnPropertyDescriptor, yt = (s, e, t, n) => {
10
- for (var r = n > 1 ? void 0 : n ? mt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
1
+ var Ae = Object.defineProperty;
2
+ var We = (s, e, t) => e in s ? Ae(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
+ var w = (s, e, t) => We(s, typeof e != "symbol" ? e + "" : e, t);
4
+ import { Disposable as V, ObjectMatrix as q, UniverInstanceType as I, IUniverInstanceService as E, CommandType as L, CustomRangeType as b, Inject as M, ICommandService as P, sequenceExecuteAsync as ve, isValidRange as Re, toDisposable as Be, DisposableCollection as je, Rectangle as Fe, Range as Ke, Tools as oe, BuildTextUtils as Z, generateRandomId as de, TextX as ce, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as Ye, IResourceManagerService as Ge, IUndoRedoService as Se, CellValueType as Ie, sequenceExecute as ze, getBodySlice as Ne, LocaleService as Je, DependentOn as Xe, Injector as qe, Plugin as Ze, merge as Qe, registerDependencies as et, touchDependencies as tt, IConfigService as nt } from "@univerjs/core";
5
+ import { Subject as rt } from "rxjs";
6
+ import { getSheetCommandTarget as j, RefRangeService as Oe, SheetsSelectionsService as ke, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as st, handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests as it, SheetInterceptorService as le, RemoveSheetCommand as at, handleDefaultRangeChangeWithEffectRefCommands as ot, SetRangeValuesMutation as H, SetRangeValuesCommand as dt, ClearSelectionContentCommand as ct, ClearSelectionAllCommand as lt, ClearSelectionFormatCommand as ut, AFTER_CELL_EDIT as pt, SetRangeValuesUndoMutationFactory as Me, UniverSheetsPlugin as ht } from "@univerjs/sheets";
7
+ import { deserializeRangeWithSheet as Ce, serializeRange as B, serializeRangeWithSheet as gt, IDefinedNamesService as ft } from "@univerjs/engine-formula";
8
+ import { addCustomRangeBySelectionFactory as _t, deleteCustomRangeFactory as mt, replaceSelectionFactory as De } from "@univerjs/docs";
9
+ var yt = Object.defineProperty, vt = Object.getOwnPropertyDescriptor, Rt = (s, e, t, n) => {
10
+ for (var r = n > 1 ? void 0 : n ? vt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
11
11
  (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
12
- return n && r && _t(e, t, r), r;
13
- }, vt = (s, e) => (t, n) => e(t, n, s);
12
+ return n && r && yt(e, t, r), r;
13
+ }, St = (s, e) => (t, n) => e(t, n, s);
14
14
  let S = class extends V {
15
15
  constructor(e) {
16
16
  super();
17
- w(this, "_linkUpdate$", new tt());
17
+ w(this, "_linkUpdate$", new rt());
18
18
  w(this, "linkUpdate$", this._linkUpdate$.asObservable());
19
19
  w(this, "_linkMap", /* @__PURE__ */ new Map());
20
20
  w(this, "_linkPositionMap", /* @__PURE__ */ new Map());
@@ -137,11 +137,11 @@ let S = class extends V {
137
137
  return Array.from(this._linkMap.keys()).map((t) => this.getUnit(t));
138
138
  }
139
139
  };
140
- S = yt([
141
- vt(0, E)
140
+ S = Rt([
141
+ St(0, E)
142
142
  ], S);
143
143
  var U = /* @__PURE__ */ ((s) => (s.SHEET = "gid", s.RANGE = "range", s.DEFINE_NAME = "rangeid", s.INVALID = "invalid", s.URL = "url", s))(U || {});
144
- const Rt = "sheets-hyper-link.config", St = {}, O = {
144
+ const It = "sheets-hyper-link.config", Ue = {}, O = {
145
145
  type: L.MUTATION,
146
146
  id: "sheets.mutation.add-hyper-link",
147
147
  handler(s, e) {
@@ -187,14 +187,14 @@ const Rt = "sheets-hyper-link.config", St = {}, O = {
187
187
  const { unitId: t, subUnitId: n, row: r, col: i, id: a, url: o } = e, c = s.get(E), d = j(c, { unitId: t, subUnitId: n });
188
188
  if (!d)
189
189
  return !1;
190
- const { worksheet: l } = d, u = l.getCellRaw(r, i), h = (f = (p = (g = u == null ? void 0 : u.p) == null ? void 0 : g.body) == null ? void 0 : p.customRanges) == null ? void 0 : f.find((y) => y.rangeType === b.HYPERLINK && y.rangeId === a);
190
+ const { worksheet: l } = d, u = l.getCellRaw(r, i), h = (f = (p = (g = u == null ? void 0 : u.p) == null ? void 0 : g.body) == null ? void 0 : p.customRanges) == null ? void 0 : f.find((_) => _.rangeType === b.HYPERLINK && _.rangeId === a);
191
191
  return h && (h.properties.url = o), !0;
192
192
  }
193
- }, De = "SHEET_HYPER_LINK_PLUGIN", Q = "err";
194
- var It = Object.defineProperty, Mt = Object.getOwnPropertyDescriptor, Ct = (s, e, t, n) => {
195
- for (var r = n > 1 ? void 0 : n ? Mt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
193
+ }, He = "SHEET_HYPER_LINK_PLUGIN", Q = "err";
194
+ var Mt = Object.defineProperty, Ct = Object.getOwnPropertyDescriptor, wt = (s, e, t, n) => {
195
+ for (var r = n > 1 ? void 0 : n ? Ct(e, t) : e, i = s.length - 1, a; i >= 0; i--)
196
196
  (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
197
- return n && r && It(e, t, r), r;
197
+ return n && r && Mt(e, t, r), r;
198
198
  }, z = (s, e) => (t, n) => e(t, n, s);
199
199
  let ee = class extends V {
200
200
  constructor(e, t, n, r) {
@@ -261,7 +261,7 @@ let ee = class extends V {
261
261
  startRow: n.row,
262
262
  endRow: n.row
263
263
  }, a = (o) => {
264
- const c = nt(i, o, { selectionManagerService: this._selectionManagerService }), d = Array.isArray(c) ? c[0] : c;
264
+ const c = st(i, o, { selectionManagerService: this._selectionManagerService }), d = Array.isArray(c) ? c[0] : c;
265
265
  return d && d.startColumn === i.startColumn && d.startRow === i.startRow ? {
266
266
  undos: [],
267
267
  redos: []
@@ -304,7 +304,7 @@ let ee = class extends V {
304
304
  const l = d.gid, u = Ce(d.range).range;
305
305
  if (Re(u) && d.range !== Q) {
306
306
  const h = (g) => {
307
- const p = rt(u, g, { selectionManagerService: this._selectionManagerService });
307
+ const p = it(u, g, { selectionManagerService: this._selectionManagerService });
308
308
  return p && B(p) === B(u) ? {
309
309
  redos: [],
310
310
  undos: []
@@ -395,23 +395,23 @@ let ee = class extends V {
395
395
  }
396
396
  }
397
397
  })
398
- ), this.disposeWithMe(We(() => {
398
+ ), this.disposeWithMe(Be(() => {
399
399
  this._disposableMap.forEach((e) => {
400
400
  e.dispose();
401
401
  }), this._disposableMap.clear();
402
402
  }));
403
403
  }
404
404
  };
405
- ee = Ct([
406
- z(0, M(Ne)),
405
+ ee = wt([
406
+ z(0, M(Oe)),
407
407
  z(1, M(S)),
408
- z(2, M(Oe)),
408
+ z(2, M(ke)),
409
409
  z(3, P)
410
410
  ], ee);
411
- var wt = Object.defineProperty, Et = Object.getOwnPropertyDescriptor, Lt = (s, e, t, n) => {
412
- for (var r = n > 1 ? void 0 : n ? Et(e, t) : e, i = s.length - 1, a; i >= 0; i--)
411
+ var Et = Object.defineProperty, Lt = Object.getOwnPropertyDescriptor, Ut = (s, e, t, n) => {
412
+ for (var r = n > 1 ? void 0 : n ? Lt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
413
413
  (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
414
- return n && r && wt(e, t, r), r;
414
+ return n && r && Et(e, t, r), r;
415
415
  }, he = (s, e) => (t, n) => e(t, n, s);
416
416
  let te = class extends V {
417
417
  constructor(s, e, t) {
@@ -422,7 +422,7 @@ let te = class extends V {
422
422
  this._sheetInterceptorService.interceptCommand({
423
423
  getMutations: (s) => {
424
424
  var e;
425
- if (s.id === st.id) {
425
+ if (s.id === at.id) {
426
426
  const t = s.params, n = t.unitId ? this._univerInstanceService.getUnit(t.unitId) : this._univerInstanceService.getCurrentUnitForType(I.UNIVER_SHEET);
427
427
  if (!n)
428
428
  return { redos: [], undos: [] };
@@ -452,15 +452,15 @@ let te = class extends V {
452
452
  );
453
453
  }
454
454
  };
455
- te = Lt([
455
+ te = Ut([
456
456
  he(0, M(le)),
457
457
  he(1, E),
458
458
  he(2, M(S))
459
459
  ], te);
460
- var Ut = Object.defineProperty, bt = Object.getOwnPropertyDescriptor, Pt = (s, e, t, n) => {
461
- for (var r = n > 1 ? void 0 : n ? bt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
460
+ var bt = Object.defineProperty, Pt = Object.getOwnPropertyDescriptor, Nt = (s, e, t, n) => {
461
+ for (var r = n > 1 ? void 0 : n ? Pt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
462
462
  (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
463
- return n && r && Ut(e, t, r), r;
463
+ return n && r && bt(e, t, r), r;
464
464
  }, ge = (s, e) => (t, n) => e(t, n, s);
465
465
  let ne = class extends V {
466
466
  constructor(e, t, n) {
@@ -506,20 +506,20 @@ let ne = class extends V {
506
506
  var h;
507
507
  return u.rangeType === b.HYPERLINK && this._isLegalRangeUrl(e, (h = u.properties) == null ? void 0 : h.url);
508
508
  })) {
509
- const u = new Be();
509
+ const u = new je();
510
510
  let h = !1;
511
511
  (l = (d = i.body) == null ? void 0 : d.customRanges) == null || l.forEach((g) => {
512
512
  var p;
513
513
  if (g.rangeType === b.HYPERLINK) {
514
- const f = (p = g.properties) == null ? void 0 : p.url, y = this._isLegalRangeUrl(e, f);
515
- if (y) {
516
- const { range: _, worksheet: C } = y;
514
+ const f = (p = g.properties) == null ? void 0 : p.url, _ = this._isLegalRangeUrl(e, f);
515
+ if (_) {
516
+ const { range: m, worksheet: C } = _;
517
517
  h = !0, u.add(
518
518
  this._refRangeService.registerRefRange(
519
- _,
520
- (m) => {
521
- const v = it(_, m);
522
- return v && je.equals(v, _) ? {
519
+ m,
520
+ (y) => {
521
+ const v = ot(m, y);
522
+ return v && Fe.equals(v, m) ? {
523
523
  preRedos: [],
524
524
  preUndos: [],
525
525
  redos: [],
@@ -615,15 +615,15 @@ let ne = class extends V {
615
615
  );
616
616
  }
617
617
  };
618
- ne = Pt([
618
+ ne = Nt([
619
619
  ge(0, P),
620
620
  ge(1, E),
621
- ge(2, M(Ne))
621
+ ge(2, M(Oe))
622
622
  ], ne);
623
- var Nt = Object.defineProperty, Ot = Object.getOwnPropertyDescriptor, kt = (s, e, t, n) => {
624
- for (var r = n > 1 ? void 0 : n ? Ot(e, t) : e, i = s.length - 1, a; i >= 0; i--)
623
+ var Ot = Object.defineProperty, kt = Object.getOwnPropertyDescriptor, Dt = (s, e, t, n) => {
624
+ for (var r = n > 1 ? void 0 : n ? kt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
625
625
  (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
626
- return n && r && Nt(e, t, r), r;
626
+ return n && r && Ot(e, t, r), r;
627
627
  }, J = (s, e) => (t, n) => e(t, n, s);
628
628
  let re = class extends V {
629
629
  constructor(s, e, t, n) {
@@ -635,7 +635,7 @@ let re = class extends V {
635
635
  _initSetRangeValuesCommandInterceptor() {
636
636
  this.disposeWithMe(this._sheetInterceptorService.interceptCommand({
637
637
  getMutations: (s) => {
638
- if (s.id === at.id) {
638
+ if (s.id === dt.id) {
639
639
  const e = s.params, { unitId: t, subUnitId: n } = e, r = [], i = [];
640
640
  return e.cellValue && new q(e.cellValue).forValue((a, o) => {
641
641
  const c = this._hyperLinkModel.getHyperLinkByLocation(t, n, a, o);
@@ -669,11 +669,11 @@ let re = class extends V {
669
669
  _initClearSelectionCommandInterceptor() {
670
670
  this.disposeWithMe(this._sheetInterceptorService.interceptCommand({
671
671
  getMutations: (s) => {
672
- if (s.id === ot.id || s.id === dt.id || s.id === ct.id) {
672
+ if (s.id === ct.id || s.id === lt.id || s.id === ut.id) {
673
673
  const e = [], t = [], n = this._selectionManagerService.getCurrentLastSelection(), r = j(this._univerInstanceService);
674
674
  if (n && r) {
675
675
  const { unitId: i, subUnitId: a } = r;
676
- Fe.foreach(n.range, (o, c) => {
676
+ Ke.foreach(n.range, (o, c) => {
677
677
  const d = this._hyperLinkModel.getHyperLinkByLocation(i, a, o, c);
678
678
  d && (e.push({
679
679
  id: k.id,
@@ -705,7 +705,7 @@ let re = class extends V {
705
705
  }));
706
706
  }
707
707
  _initAfterEditor() {
708
- this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(lt, {
708
+ this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(pt, {
709
709
  handler: (s, e, t) => {
710
710
  if (!s || s.p)
711
711
  return t(s);
@@ -742,7 +742,7 @@ let re = class extends V {
742
742
  return ce.apply(d, c.serialize()), t({
743
743
  ...s,
744
744
  p: {
745
- id: Ke,
745
+ id: Ye,
746
746
  body: d,
747
747
  documentStyle: {
748
748
  pageSize: {
@@ -758,17 +758,17 @@ let re = class extends V {
758
758
  }));
759
759
  }
760
760
  };
761
- re = kt([
761
+ re = Dt([
762
762
  J(0, M(le)),
763
763
  J(1, M(S)),
764
- J(2, M(Oe)),
764
+ J(2, M(ke)),
765
765
  J(3, E)
766
766
  ], re);
767
- var He = /* @__PURE__ */ ((s) => (s[s.UNIVER_UNKNOWN = 0] = "UNIVER_UNKNOWN", s[s.UNIVER_DOC = 1] = "UNIVER_DOC", s[s.UNIVER_SHEET = 2] = "UNIVER_SHEET", s[s.UNIVER_SLIDE = 3] = "UNIVER_SLIDE", s[s.UNIVER_PROJECT = 4] = "UNIVER_PROJECT", s[s.UNRECOGNIZED = -1] = "UNRECOGNIZED", s))(He || {}), Dt = Object.defineProperty, Ht = Object.getOwnPropertyDescriptor, Vt = (s, e, t, n) => {
768
- for (var r = n > 1 ? void 0 : n ? Ht(e, t) : e, i = s.length - 1, a; i >= 0; i--)
767
+ var Ve = /* @__PURE__ */ ((s) => (s[s.UNIVER_UNKNOWN = 0] = "UNIVER_UNKNOWN", s[s.UNIVER_DOC = 1] = "UNIVER_DOC", s[s.UNIVER_SHEET = 2] = "UNIVER_SHEET", s[s.UNIVER_SLIDE = 3] = "UNIVER_SLIDE", s[s.UNIVER_PROJECT = 4] = "UNIVER_PROJECT", s[s.UNRECOGNIZED = -1] = "UNRECOGNIZED", s))(Ve || {}), Ht = Object.defineProperty, Vt = Object.getOwnPropertyDescriptor, $t = (s, e, t, n) => {
768
+ for (var r = n > 1 ? void 0 : n ? Vt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
769
769
  (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
770
- return n && r && Dt(e, t, r), r;
771
- }, Ue = (s, e) => (t, n) => e(t, n, s);
770
+ return n && r && Ht(e, t, r), r;
771
+ }, be = (s, e) => (t, n) => e(t, n, s);
772
772
  let se = class extends V {
773
773
  constructor(s, e) {
774
774
  super(), this._resourceManagerService = s, this._hyperLinkModel = e, this._initSnapshot();
@@ -790,8 +790,8 @@ let se = class extends V {
790
790
  };
791
791
  this.disposeWithMe(
792
792
  this._resourceManagerService.registerPluginResource({
793
- pluginName: De,
794
- businesses: [He.UNIVER_SHEET],
793
+ pluginName: He,
794
+ businesses: [Ve.UNIVER_SHEET],
795
795
  toJson: (t) => s(t),
796
796
  parseJson: (t) => e(t),
797
797
  onUnLoad: (t) => {
@@ -808,11 +808,11 @@ let se = class extends V {
808
808
  );
809
809
  }
810
810
  };
811
- se = Vt([
812
- Ue(0, Ye),
813
- Ue(1, M(S))
811
+ se = $t([
812
+ be(0, Ge),
813
+ be(1, M(S))
814
814
  ], se);
815
- const $t = {
815
+ const xt = {
816
816
  type: L.COMMAND,
817
817
  id: "sheets.command.add-hyper-link",
818
818
  // eslint-disable-next-line max-lines-per-function
@@ -820,14 +820,14 @@ const $t = {
820
820
  if (!e) return !1;
821
821
  const t = s.get(P), n = s.get(Se), r = s.get(E), i = s.get(S), a = s.get(le), o = j(r, e);
822
822
  if (!o) return !1;
823
- const { unitId: c, subUnitId: d, workbook: l, worksheet: u } = o, { link: h } = e, { payload: g, display: p, row: f, column: y, id: _ } = h, C = u.getCell(f, y), m = u.getBlankCellDocumentModel(C), v = m.documentModel.getSnapshot(), R = oe.deepClone(v.body);
823
+ const { unitId: c, subUnitId: d, workbook: l, worksheet: u } = o, { link: h } = e, { payload: g, display: p, row: f, column: _, id: m } = h, C = u.getCell(f, _), y = u.getBlankCellDocumentModel(C), v = y.documentModel.getSnapshot(), R = oe.deepClone(v.body);
824
824
  if (!R) return !1;
825
825
  let N;
826
826
  if (p ? N = Z.selection.replace({
827
827
  selection: {
828
828
  startOffset: 0,
829
829
  endOffset: R.dataStream.length - 2,
830
- collapsed: !0
830
+ collapsed: R.dataStream.length - 2 === 0
831
831
  },
832
832
  body: {
833
833
  dataStream: `${p}`,
@@ -835,22 +835,22 @@ const $t = {
835
835
  startIndex: 0,
836
836
  endIndex: p.length - 1,
837
837
  rangeType: b.HYPERLINK,
838
- rangeId: _,
838
+ rangeId: m,
839
839
  properties: {
840
840
  url: g
841
841
  // refId: id,
842
842
  }
843
843
  }]
844
844
  },
845
- doc: m.documentModel
845
+ doc: y.documentModel
846
846
  }) : N = Z.customRange.add({
847
847
  body: R,
848
848
  ranges: [{ startOffset: 0, endOffset: R.dataStream.length - 2, collapsed: !1 }],
849
- rangeId: _,
849
+ rangeId: m,
850
850
  rangeType: b.HYPERLINK,
851
851
  properties: {
852
852
  url: g,
853
- refId: _
853
+ refId: m
854
854
  }
855
855
  }), !N) return !1;
856
856
  const F = ce.apply(R, N.serialize()), D = {
@@ -859,7 +859,7 @@ const $t = {
859
859
  body: F
860
860
  },
861
861
  t: Ie.STRING
862
- }, x = await a.onWriteCell(l, u, f, y, D), T = {
862
+ }, x = await a.onWriteCell(l, u, f, _, D), T = {
863
863
  unitId: c,
864
864
  subUnitId: d,
865
865
  cellValue: {
@@ -873,7 +873,7 @@ const $t = {
873
873
  }, Y = Me(s, T), pe = {
874
874
  id: H.id,
875
875
  params: Y
876
- }, K = [ue], A = [pe], W = i.getHyperLinkByLocation(c, d, f, y);
876
+ }, K = [ue], A = [pe], W = i.getHyperLinkByLocation(c, d, f, _);
877
877
  return W && (K.push({
878
878
  id: k.id,
879
879
  params: {
@@ -894,13 +894,13 @@ const $t = {
894
894
  unitID: c
895
895
  }), !0) : !1;
896
896
  }
897
- }, xt = {
897
+ }, Tt = {
898
898
  id: "sheets.command.add-rich-hyper-link",
899
899
  type: L.COMMAND,
900
900
  handler: async (s, e) => {
901
901
  if (!e)
902
902
  return !1;
903
- const { documentId: t, link: n } = e, r = s.get(P), i = de(), { payload: a } = n, o = gt(s, {
903
+ const { documentId: t, link: n } = e, r = s.get(P), i = de(), { payload: a } = n, o = _t(s, {
904
904
  unitId: t,
905
905
  rangeId: i,
906
906
  rangeType: b.HYPERLINK,
@@ -911,7 +911,7 @@ const $t = {
911
911
  });
912
912
  return o ? r.syncExecuteCommand(o.id, o.params) : !1;
913
913
  }
914
- }, Tt = {
914
+ }, At = {
915
915
  type: L.COMMAND,
916
916
  id: "sheets.command.cancel-hyper-link",
917
917
  // eslint-disable-next-line max-lines-per-function
@@ -924,11 +924,11 @@ const $t = {
924
924
  if (!g) return !1;
925
925
  const p = h.getCellDocumentModelWithFormula(g);
926
926
  if (!(p != null && p.documentModel)) return !1;
927
- const f = oe.deepClone(p.documentModel.getSnapshot());
928
- if (!((x = (D = f.body) == null ? void 0 : D.customRanges) == null ? void 0 : x.find((T) => T.rangeId === d))) return !1;
929
- const _ = Z.customRange.delete(s, { documentDataModel: p.documentModel, rangeId: d });
927
+ const f = oe.deepClone(p.documentModel.getSnapshot()), _ = (x = (D = f.body) == null ? void 0 : D.customRanges) == null ? void 0 : x.find((T) => `${T.rangeId}` === d);
930
928
  if (!_) return !1;
931
- const C = ce.apply(f.body, _.serialize()), m = [], v = [], R = {
929
+ const m = Z.customRange.delete(s, { documentDataModel: p.documentModel, rangeId: _.rangeId });
930
+ if (!m) return !1;
931
+ const C = ce.apply(f.body, m.serialize()), y = [], v = [], R = {
932
932
  unitId: l,
933
933
  subUnitId: u,
934
934
  cellValue: {
@@ -943,7 +943,7 @@ const $t = {
943
943
  }
944
944
  }
945
945
  };
946
- m.push({
946
+ y.push({
947
947
  id: H.id,
948
948
  params: R
949
949
  });
@@ -953,7 +953,7 @@ const $t = {
953
953
  params: N
954
954
  });
955
955
  const F = i.getHyperLinkByLocation(l, u, o, c);
956
- return F && (m.push({
956
+ return F && (y.push({
957
957
  id: k.id,
958
958
  params: {
959
959
  unitId: l,
@@ -969,13 +969,13 @@ const $t = {
969
969
  ...F
970
970
  }
971
971
  }
972
- })), Ge(m, t).result ? (n.pushUndoRedo({
973
- redoMutations: m,
972
+ })), ze(y, t).result ? (n.pushUndoRedo({
973
+ redoMutations: y,
974
974
  undoMutations: v,
975
975
  unitID: l
976
976
  }), !0) : !1;
977
977
  }
978
- }, At = {
978
+ }, Wt = {
979
979
  type: L.COMMAND,
980
980
  id: "sheets.command.cancel-rich-hyper-link",
981
981
  handler(s, e) {
@@ -987,10 +987,10 @@ const $t = {
987
987
  o && o.endIndex === a.getBody().dataStream.length - 3 && (c = {
988
988
  dataStream: " "
989
989
  });
990
- const d = ft(s, { unitId: n, rangeId: t, insert: c });
990
+ const d = mt(s, { unitId: n, rangeId: t, insert: c });
991
991
  return d ? r.syncExecuteCommand(d.id, d.params) : !1;
992
992
  }
993
- }, Wt = {
993
+ }, Bt = {
994
994
  type: L.COMMAND,
995
995
  id: "sheets.command.update-hyper-link",
996
996
  // eslint-disable-next-line max-lines-per-function
@@ -1002,25 +1002,25 @@ const $t = {
1002
1002
  subUnitId: e.subUnitId
1003
1003
  });
1004
1004
  if (!o) return !1;
1005
- const { payload: c, row: d, column: l, id: u } = e, { workbook: h, worksheet: g, unitId: p, subUnitId: f } = o, { payload: y, display: _ = "" } = c, C = g.getCell(d, l);
1005
+ const { payload: c, row: d, column: l, id: u } = e, { workbook: h, worksheet: g, unitId: p, subUnitId: f } = o, { payload: _, display: m = "" } = c, C = g.getCell(d, l);
1006
1006
  if (!C) return !1;
1007
- const m = g.getCellDocumentModelWithFormula(C);
1008
- if (!(m != null && m.documentModel)) return !1;
1009
- const v = m.documentModel.getSnapshot(), R = (Ee = (we = v.body) == null ? void 0 : we.customRanges) == null ? void 0 : Ee.find((xe) => xe.rangeId === u);
1007
+ const y = g.getCellDocumentModelWithFormula(C);
1008
+ if (!(y != null && y.documentModel)) return !1;
1009
+ const v = y.documentModel.getSnapshot(), R = (Ee = (we = v.body) == null ? void 0 : we.customRanges) == null ? void 0 : Ee.find((Te) => `${Te.rangeId}` === u);
1010
1010
  if (!R) return !1;
1011
- const N = de(), $ = (Le = Pe(m.documentModel.getBody(), R.startIndex, R.endIndex + 1).textRuns) == null ? void 0 : Le[0];
1012
- $ && ($.ed = _.length + 1);
1013
- const D = ke(s, {
1011
+ const N = de(), $ = (Le = Ne(y.documentModel.getBody(), R.startIndex, R.endIndex + 1).textRuns) == null ? void 0 : Le[0];
1012
+ $ && ($.ed = m.length + 1);
1013
+ const D = De(s, {
1014
1014
  unitId: p,
1015
1015
  body: {
1016
- dataStream: `${_}`,
1016
+ dataStream: `${m}`,
1017
1017
  customRanges: [{
1018
1018
  rangeId: N,
1019
1019
  rangeType: b.HYPERLINK,
1020
1020
  startIndex: 0,
1021
- endIndex: _.length - 1,
1021
+ endIndex: m.length - 1,
1022
1022
  properties: {
1023
- url: y
1023
+ url: _
1024
1024
  }
1025
1025
  }],
1026
1026
  textRuns: $ ? [$] : void 0
@@ -1030,7 +1030,7 @@ const $t = {
1030
1030
  endOffset: R.endIndex + 1,
1031
1031
  collapsed: !1
1032
1032
  },
1033
- doc: m.documentModel
1033
+ doc: y.documentModel
1034
1034
  });
1035
1035
  if (!D)
1036
1036
  return !1;
@@ -1075,11 +1075,11 @@ const $t = {
1075
1075
  unitID: p
1076
1076
  }), !0) : !1;
1077
1077
  }
1078
- }, Bt = {
1078
+ }, jt = {
1079
1079
  type: L.COMMAND,
1080
1080
  id: "sheets.command.update-rich-hyper-link",
1081
1081
  handler: (s, e) => {
1082
- var p, f, y, _;
1082
+ var p, f, _, m;
1083
1083
  if (!e)
1084
1084
  return !1;
1085
1085
  const { documentId: t, payload: n, id: r } = e, i = s.get(E), a = s.get(P), o = i.getUnit(t, I.UNIVER_DOC);
@@ -1088,9 +1088,9 @@ const $t = {
1088
1088
  const c = (f = (p = o.getBody()) == null ? void 0 : p.customRanges) == null ? void 0 : f.find((C) => C.rangeId === r);
1089
1089
  if (!c)
1090
1090
  return !1;
1091
- const d = (y = e.payload.display) != null ? y : "", l = de(), h = (_ = Pe(o.getBody(), c.startIndex, c.endIndex + 1).textRuns) == null ? void 0 : _[0];
1091
+ const d = (_ = e.payload.display) != null ? _ : "", l = de(), h = (m = Ne(o.getBody(), c.startIndex, c.endIndex + 1).textRuns) == null ? void 0 : m[0];
1092
1092
  h && (h.ed = d.length + 1);
1093
- const g = ke(s, {
1093
+ const g = De(s, {
1094
1094
  unitId: t,
1095
1095
  body: {
1096
1096
  dataStream: `${d}`,
@@ -1115,23 +1115,23 @@ const $t = {
1115
1115
  return g ? a.syncExecuteCommand(g.id, g.params) : !1;
1116
1116
  }
1117
1117
  };
1118
- var jt = Object.defineProperty, Ft = Object.getOwnPropertyDescriptor, Kt = (s, e, t, n) => {
1119
- for (var r = n > 1 ? void 0 : n ? Ft(e, t) : e, i = s.length - 1, a; i >= 0; i--)
1118
+ var Ft = Object.defineProperty, Kt = Object.getOwnPropertyDescriptor, Yt = (s, e, t, n) => {
1119
+ for (var r = n > 1 ? void 0 : n ? Kt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
1120
1120
  (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
1121
- return n && r && jt(e, t, r), r;
1122
- }, Yt = (s, e) => (t, n) => e(t, n, s);
1121
+ return n && r && Ft(e, t, r), r;
1122
+ }, Gt = (s, e) => (t, n) => e(t, n, s);
1123
1123
  let ie = class extends V {
1124
1124
  constructor(s) {
1125
1125
  super(), this._commandService = s, this._registerCommands();
1126
1126
  }
1127
1127
  _registerCommands() {
1128
1128
  [
1129
- $t,
1130
- Wt,
1131
- Tt,
1129
+ xt,
1132
1130
  Bt,
1133
1131
  At,
1134
- xt,
1132
+ jt,
1133
+ Wt,
1134
+ Tt,
1135
1135
  O,
1136
1136
  _e,
1137
1137
  k,
@@ -1142,13 +1142,13 @@ let ie = class extends V {
1142
1142
  });
1143
1143
  }
1144
1144
  };
1145
- ie = Kt([
1146
- Yt(0, P)
1145
+ ie = Yt([
1146
+ Gt(0, P)
1147
1147
  ], ie);
1148
- var Gt = Object.defineProperty, zt = Object.getOwnPropertyDescriptor, Jt = (s, e, t, n) => {
1149
- for (var r = n > 1 ? void 0 : n ? zt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
1148
+ var zt = Object.defineProperty, Jt = Object.getOwnPropertyDescriptor, Xt = (s, e, t, n) => {
1149
+ for (var r = n > 1 ? void 0 : n ? Jt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
1150
1150
  (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
1151
- return n && r && Gt(e, t, r), r;
1151
+ return n && r && zt(e, t, r), r;
1152
1152
  }, fe = (s, e) => (t, n) => e(t, n, s);
1153
1153
  let ye = class {
1154
1154
  constructor(s, e, t) {
@@ -1194,7 +1194,7 @@ let ye = class {
1194
1194
  const l = Ce(t).range;
1195
1195
  return Re(l, o) && t !== Q ? {
1196
1196
  type: U.RANGE,
1197
- name: pt(c, l)
1197
+ name: gt(c, l)
1198
1198
  } : a;
1199
1199
  }
1200
1200
  if (n) {
@@ -1214,24 +1214,28 @@ let ye = class {
1214
1214
  return a;
1215
1215
  }
1216
1216
  };
1217
- ye = Jt([
1217
+ ye = Xt([
1218
1218
  fe(0, E),
1219
- fe(1, M(ze)),
1220
- fe(2, ht)
1219
+ fe(1, M(Je)),
1220
+ fe(2, ft)
1221
1221
  ], ye);
1222
- var Ve = Object.defineProperty, Xt = Object.getOwnPropertyDescriptor, qt = (s, e, t) => e in s ? Ve(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, Zt = (s, e, t, n) => {
1223
- for (var r = n > 1 ? void 0 : n ? Xt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
1222
+ var $e = Object.defineProperty, qt = Object.getOwnPropertyDescriptor, Zt = (s, e, t) => e in s ? $e(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, Qt = (s, e, t, n) => {
1223
+ for (var r = n > 1 ? void 0 : n ? qt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
1224
1224
  (a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
1225
- return n && r && Ve(e, t, r), r;
1226
- }, be = (s, e) => (t, n) => e(t, n, s), $e = (s, e, t) => qt(s, typeof e != "symbol" ? e + "" : e, t);
1227
- let ae = class extends qe {
1228
- constructor(s = St, e, t) {
1225
+ return n && r && $e(e, t, r), r;
1226
+ }, Pe = (s, e) => (t, n) => e(t, n, s), xe = (s, e, t) => Zt(s, typeof e != "symbol" ? e + "" : e, t);
1227
+ let ae = class extends Ze {
1228
+ constructor(s = Ue, e, t) {
1229
1229
  super(), this._config = s, this._injector = e, this._configService = t;
1230
- const { ...n } = this._config;
1231
- this._configService.setConfig(Rt, n);
1230
+ const { ...n } = Qe(
1231
+ {},
1232
+ Ue,
1233
+ this._config
1234
+ );
1235
+ this._configService.setConfig(It, n);
1232
1236
  }
1233
1237
  onStarting() {
1234
- Ze(this._injector, [
1238
+ et(this._injector, [
1235
1239
  [S],
1236
1240
  [ye],
1237
1241
  [se],
@@ -1240,7 +1244,7 @@ let ae = class extends qe {
1240
1244
  [re],
1241
1245
  [te],
1242
1246
  [ne]
1243
- ]), Qe(this._injector, [
1247
+ ]), tt(this._injector, [
1244
1248
  [ee],
1245
1249
  [se],
1246
1250
  [ie],
@@ -1250,27 +1254,27 @@ let ae = class extends qe {
1250
1254
  ]);
1251
1255
  }
1252
1256
  };
1253
- $e(ae, "pluginName", De);
1254
- $e(ae, "type", I.UNIVER_SHEET);
1255
- ae = Zt([
1256
- Je(ut),
1257
- be(1, M(Xe)),
1258
- be(2, et)
1257
+ xe(ae, "pluginName", He);
1258
+ xe(ae, "type", I.UNIVER_SHEET);
1259
+ ae = Qt([
1260
+ Xe(ht),
1261
+ Pe(1, M(qe)),
1262
+ Pe(2, nt)
1259
1263
  ], ae);
1260
1264
  export {
1261
- $t as AddHyperLinkCommand,
1265
+ xt as AddHyperLinkCommand,
1262
1266
  O as AddHyperLinkMutation,
1263
- xt as AddRichHyperLinkCommand,
1264
- Tt as CancelHyperLinkCommand,
1265
- At as CancelRichHyperLinkCommand,
1267
+ Tt as AddRichHyperLinkCommand,
1268
+ At as CancelHyperLinkCommand,
1269
+ Wt as CancelRichHyperLinkCommand,
1266
1270
  Q as ERROR_RANGE,
1267
1271
  S as HyperLinkModel,
1268
1272
  k as RemoveHyperLinkMutation,
1269
1273
  U as SheetHyperLinkType,
1270
1274
  ye as SheetsHyperLinkParserService,
1271
1275
  ae as UniverSheetsHyperLinkPlugin,
1272
- Wt as UpdateHyperLinkCommand,
1276
+ Bt as UpdateHyperLinkCommand,
1273
1277
  _e as UpdateHyperLinkMutation,
1274
1278
  me as UpdateHyperLinkRefMutation,
1275
- Bt as UpdateRichHyperLinkCommand
1279
+ jt as UpdateRichHyperLinkCommand
1276
1280
  };
@@ -7,6 +7,14 @@ export interface ICellHyperLink {
7
7
  label: string;
8
8
  }
9
9
  export interface IFRangeHyperlinkMixin {
10
+ /**
11
+ * Set hyperlink in the cell in the range.
12
+ * [!important] This method is async.
13
+ * @param url url
14
+ * @param label optional, label of the url
15
+ * @returns success or not
16
+ */
17
+ setHyperLink(url: string, label?: string): Promise<boolean>;
10
18
  /**
11
19
  * Get all hyperlinks in the cell in the range.
12
20
  * @returns hyperlinks
@@ -30,13 +38,6 @@ export interface IFRangeHyperlinkMixin {
30
38
  cancelHyperLink(id: string): Promise<boolean>;
31
39
  }
32
40
  export declare class FRangeHyperlinkMixin extends FRange implements IFRangeHyperlinkMixin {
33
- /**
34
- * Set hyperlink in the cell in the range.
35
- * [!important] This method is async.
36
- * @param url url
37
- * @param label optional, label of the url
38
- * @returns success or not
39
- */
40
41
  setHyperLink(url: string, label?: string): Promise<boolean>;
41
42
  /**
42
43
  * Get all hyperlinks in the cell in the range.
package/lib/umd/facade.js CHANGED
@@ -1 +1 @@
1
- (function(n,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@univerjs/sheets/facade"),require("@univerjs/sheets-hyper-link"),require("@univerjs/core")):typeof define=="function"&&define.amd?define(["exports","@univerjs/sheets/facade","@univerjs/sheets-hyper-link","@univerjs/core"],i):(n=typeof globalThis<"u"?globalThis:n||self,i(n.UniverSheetsHyperLinkFacade={},n.UniverSheetsFacade,n.UniverSheetsHyperLink,n.UniverCore))})(this,function(n,i,a,d){"use strict";class p extends i.FWorkbook{createSheetHyperlink(e,t){return this._injector.get(a.SheetsHyperLinkParserService).buildHyperLink(this.getId(),e,t)}parseSheetHyperlink(e){return this._injector.get(a.SheetsHyperLinkParserService).parseHyperLink(e)}}i.FWorkbook.extend(p);class k extends i.FRange{setHyperLink(e,t){const s={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),link:{row:this._range.startRow,column:this._range.startColumn,payload:e,display:t,id:d.generateRandomId()}};return this._commandService.executeCommand(a.AddHyperLinkCommand.id,s)}getHyperLinks(){var t,s,o;const e=this._worksheet.getCellRaw(this._range.startRow,this._range.startColumn);return e!=null&&e.p?(o=(s=(t=e.p.body)==null?void 0:t.customRanges)==null?void 0:s.filter(r=>r.rangeType===d.CustomRangeType.HYPERLINK).map(r=>{var u,h,c,m,l;return{id:`${r.rangeId}_${r.startIndex}_${r.endIndex}`,startIndex:r.startIndex,endIndex:r.endIndex,url:(h=(u=r.properties)==null?void 0:u.url)!=null?h:"",label:(l=(m=(c=e.p)==null?void 0:c.body)==null?void 0:m.dataStream.slice(r.startIndex,r.endIndex+1).replaceAll(d.DataStreamTreeTokenType.CUSTOM_RANGE_START,"").replaceAll(d.DataStreamTreeTokenType.CUSTOM_RANGE_END,""))!=null?l:""}}))!=null?o:[]:[]}updateHyperLink(e,t,s){const o={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id:e,payload:{payload:t,display:s}};return this._commandService.executeCommand(a.UpdateHyperLinkCommand.id,o)}cancelHyperLink(e){const t={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id:e};return this._commandService.executeCommand(a.CancelHyperLinkCommand.id,t)}}i.FRange.extend(k),n.FWorkbookHyperLinkMixin=p,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})});
1
+ (function(r,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("@univerjs/sheets/facade"),require("@univerjs/sheets-hyper-link"),require("@univerjs/core")):typeof define=="function"&&define.amd?define(["exports","@univerjs/sheets/facade","@univerjs/sheets-hyper-link","@univerjs/core"],n):(r=typeof globalThis<"u"?globalThis:r||self,n(r.UniverSheetsHyperLinkFacade={},r.UniverSheetsFacade,r.UniverSheetsHyperLink,r.UniverCore))})(this,function(r,n,a,o){"use strict";class p extends n.FWorkbook{createSheetHyperlink(e,t){return this._injector.get(a.SheetsHyperLinkParserService).buildHyperLink(this.getId(),e,t)}parseSheetHyperlink(e){return this._injector.get(a.SheetsHyperLinkParserService).parseHyperLink(e)}}n.FWorkbook.extend(p);class k extends n.FRange{setHyperLink(e,t){const s={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),link:{row:this._range.startRow,column:this._range.startColumn,payload:e,display:t,id:o.generateRandomId()}};return this._commandService.executeCommand(a.AddHyperLinkCommand.id,s)}getHyperLinks(){var t,s,d;const e=this._worksheet.getCellRaw(this._range.startRow,this._range.startColumn);return e!=null&&e.p?(d=(s=(t=e.p.body)==null?void 0:t.customRanges)==null?void 0:s.filter(i=>i.rangeType===o.CustomRangeType.HYPERLINK).map(i=>{var u,h,c,m,l;return{id:`${i.rangeId}`,startIndex:i.startIndex,endIndex:i.endIndex,url:(h=(u=i.properties)==null?void 0:u.url)!=null?h:"",label:(l=(m=(c=e.p)==null?void 0:c.body)==null?void 0:m.dataStream.slice(i.startIndex,i.endIndex+1).replaceAll(o.DataStreamTreeTokenType.CUSTOM_RANGE_START,"").replaceAll(o.DataStreamTreeTokenType.CUSTOM_RANGE_END,""))!=null?l:""}}))!=null?d:[]:[]}updateHyperLink(e,t,s){const d={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id:e,payload:{payload:t,display:s}};return this._commandService.executeCommand(a.UpdateHyperLinkCommand.id,d)}cancelHyperLink(e){const t={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id:e};return this._commandService.executeCommand(a.CancelHyperLinkCommand.id,t)}}n.FRange.extend(k),r.FWorkbookHyperLinkMixin=p,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(p,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("rxjs"),require("@univerjs/sheets"),require("@univerjs/engine-formula"),require("@univerjs/docs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","@univerjs/sheets","@univerjs/engine-formula","@univerjs/docs"],o):(p=typeof globalThis<"u"?globalThis:p||self,o(p.UniverSheetsHyperLink={},p.UniverCore,p.rxjs,p.UniverSheets,p.UniverEngineFormula,p.UniverDocs))})(this,function(p,o,T,m,C,x){"use strict";var Qe=Object.defineProperty;var et=(p,o,T)=>o in p?Qe(p,o,{enumerable:!0,configurable:!0,writable:!0,value:T}):p[o]=T;var L=(p,o,T)=>et(p,typeof o!="symbol"?o+"":o,T);var Ie=Object.defineProperty,Re=Object.getOwnPropertyDescriptor,Me=(r,t,e,n)=>{for(var i=n>1?void 0:n?Re(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Ie(t,e,i),i},Ce=(r,t)=>(e,n)=>t(e,n,r);p.HyperLinkModel=class extends o.Disposable{constructor(e){super();L(this,"_linkUpdate$",new T.Subject);L(this,"linkUpdate$",this._linkUpdate$.asObservable());L(this,"_linkMap",new Map);L(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let i=this._linkMap.get(e);i||(i=new Map,this._linkMap.set(e,i));let s=i.get(n);s||(s=new o.ObjectMatrix,i.set(n,s));let a=this._linkPositionMap.get(e);a||(a=new Map,this._linkPositionMap.set(e,a));let d=a.get(n);return d||(d=new Map,a.set(n,d)),{matrix:s,positionMap:d}}addHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n);return s.setValue(i.row,i.column,i),a.set(i.id,{row:i.row,column:i.column,link:i}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:i,type:"add"}),!0}updateHyperLink(e,n,i,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;const u=d.getValue(l.row,l.column);return u&&(Object.assign(u,s),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:u.display,payload:u.payload},id:i,type:"update",silent:a})),!0}updateHyperLinkRef(e,n,i,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;let u=d.getValue(l.row,l.column);return!u||u.id!==i?u=l.link:d.realDeleteValue(l.row,l.column),Object.assign(u,s),c.set(i,{...s,link:u}),d.setValue(s.row,s.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:i,type:"updateRef",silent:a}),!0}removeHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(i);if(!d)return!1;a.delete(i);const c=s.getValue(d.row,d.column);return c&&c.id===i&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(i);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,i,s){const{matrix:a}=this._ensureMap(e,n);return a.getValue(i,s)}getHyperLinkByLocationSync(e,n,i,s){var g,f,_,h,y;const{matrix:a}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,o.UniverInstanceType.UNIVER_SHEET),c=(g=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:g.getCellRaw(i,s),l=((y=(h=c==null?void 0:c.v)!=null?h:(_=(f=c==null?void 0:c.p)==null?void 0:f.body)==null?void 0:_.dataStream.slice(0,-2))!=null?y:"").toString(),u=a.getValue(i,s);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:i}=this._ensureMap(e,n),s=[];return i.forValue((a,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(i=>{const s=this.getSubUnit(e,i);return{unitId:e,subUnitId:i,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}},p.HyperLinkModel=Me([Ce(0,o.IUniverInstanceService)],p.HyperLinkModel);var w=(r=>(r.SHEET="gid",r.RANGE="range",r.DEFINE_NAME="rangeid",r.INVALID="invalid",r.URL="url",r))(w||{});const Ue="sheets-hyper-link.config",Le={},E={type:o.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,link:s}=t;return e.addHyperLink(n,i,s)}},k={type:o.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:s}=t;return e.removeHyperLink(n,i,s)}},W={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,payload:s,id:a}=t;return e.updateHyperLink(n,i,a,s,!1)}},B={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:s,row:a,column:d,silent:c}=t;return e.updateHyperLinkRef(n,i,s,{row:a,column:d},c)}},K={type:o.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(r,t){var _,h,y;if(!t)return!1;const{unitId:e,subUnitId:n,row:i,col:s,id:a,url:d}=t,c=r.get(o.IUniverInstanceService),l=m.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:u}=l,g=u.getCellRaw(i,s),f=(y=(h=(_=g==null?void 0:g.p)==null?void 0:_.body)==null?void 0:h.customRanges)==null?void 0:y.find(I=>I.rangeType===o.CustomRangeType.HYPERLINK&&I.rangeId===a);return f&&(f.properties.url=d),!0}},ae="SHEET_HYPER_LINK_PLUGIN",$="err";var we=Object.defineProperty,Ee=Object.getOwnPropertyDescriptor,ke=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ee(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&we(t,e,i),i},z=(r,t)=>(e,n)=>t(e,n,r);let G=class extends o.Disposable{constructor(t,e,n,i){super();L(this,"_disposableMap",new Map);L(this,"_watchDisposableMap",new Map);L(this,"_rangeDisableMap",new Map);L(this,"_rangeWatcherMap",new Map);L(this,"_handlePositionChange",(t,e,n,i,s)=>{const a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return i?{redos:[{id:B.id,params:{unitId:t,subUnitId:e,id:n.id,row:i.startRow,column:i.startColumn,silent:s}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,id:n.id,row:a.startRow,column:a.startColumn,silent:s}}]}:{redos:[{id:k.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:E.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=i,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},a=d=>{const c=m.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===s.startColumn&&l.startRow===s.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(i,this._refRangeService.registerRefRange(s,a,t,e))}_watchPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(t,e,s,(a,d)=>{const{redos:c}=this._handlePositionChange(t,e,n,d,!0);o.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(t){const e=this._disposableMap.get(t);e==null||e.dispose(),this._disposableMap.delete(t)}_unwatchPosition(t){const e=this._watchDisposableMap.get(t);e==null||e.dispose(),this._watchDisposableMap.delete(t)}_registerRange(t,e,n,i=!1){var s,a,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(s=c.get("gid"))!=null?s:"",range:(a=c.get("range"))!=null?a:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const u=l.gid,g=C.deserializeRangeWithSheet(l.range).range;if(o.isValidRange(g)&&l.range!==$){const f=_=>{const h=m.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(g,_,{selectionManagerService:this._selectionManagerService});return h&&C.serializeRange(h)===C.serializeRange(g)?{redos:[],undos:[]}:{redos:[{id:W.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`}}}],undos:[{id:W.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(g,f,t,u)),i||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,u,g,(_,h)=>{this._hyperLinkModel.updateHyperLink(t,u,e,{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`},!0)},!0))}}}}_unregisterRange(t){const e=this._rangeDisableMap.get(t);e==null||e.dispose(),this._rangeDisableMap.delete(t)}_unwatchRange(t){const e=this._rangeWatcherMap.get(t);e==null||e.dispose(),this._rangeWatcherMap.delete(t)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(n=>{const{unitId:i,subUnitId:s,links:a}=n;a.forEach(d=>{this._registerPosition(i,s,d),this._watchPosition(i,s,d),this._registerRange(i,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:i,silent:s}=t,a=this._hyperLinkModel.getHyperLink(e,n,i);if(!a)return;this._unregisterPosition(i),this._registerPosition(e,n,a),s||(this._unwatchPosition(i),this._watchPosition(e,n,a));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:i}=n;i.forEach(s=>{this._unregisterPosition(s.id),this._unwatchPosition(s.id),this._unregisterRange(s.id),this._unwatchRange(s.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(o.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};G=ke([z(0,o.Inject(m.RefRangeService)),z(1,o.Inject(p.HyperLinkModel)),z(2,o.Inject(m.SheetsSelectionsService)),z(3,o.ICommandService)],G);var Pe=Object.defineProperty,be=Object.getOwnPropertyDescriptor,Te=(r,t,e,n)=>{for(var i=n>1?void 0:n?be(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Pe(t,e,i),i},te=(r,t)=>(e,n)=>t(e,n,r);let Y=class extends o.Disposable{constructor(r,t,e){super(),this._sheetInterceptorService=r,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{var t;if(r.id===m.RemoveSheetCommand.id){const e=r.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const i=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const a=this._hyperLinkModel.getSubUnit(i,s),d=a.map(l=>({id:k.id,params:{unitId:i,subUnitId:s,id:l.id}})),c=a.map(l=>({id:E.id,params:{unitId:i,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};Y=Te([te(0,o.Inject(m.SheetInterceptorService)),te(1,o.IUniverInstanceService),te(2,o.Inject(p.HyperLinkModel))],Y);var He=Object.defineProperty,Ne=Object.getOwnPropertyDescriptor,Oe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ne(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&He(t,e,i),i},ne=(r,t)=>(e,n)=>t(e,n,r);let q=class extends o.Disposable{constructor(t,e,n){super();L(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let i=n.get(e);return i||(i=new o.ObjectMatrix,n.set(e,i)),i}_isLegalRangeUrl(t,e){var i,s,a;const n=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(i=d.get("gid"))!=null?i:"",range:(s=d.get("range"))!=null?s:"",rangeid:(a=d.get("rangeid"))!=null?a:""};if(c.range&&c.gid){const l=c.gid,u=n.getSheetBySheetId(l);if(!u)return null;const g=C.deserializeRangeWithSheet(c.range).range;if(o.isValidRange(g,u)&&c.range!==$)return{range:g,worksheet:u}}}return null}_registerRange(t,e,n,i,s){var d,c,l,u;const a=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(g=>{var f;return g.rangeType===o.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(f=g.properties)==null?void 0:f.url)})){const g=new o.DisposableCollection;let f=!1;(u=(l=s.body)==null?void 0:l.customRanges)==null||u.forEach(_=>{var h;if(_.rangeType===o.CustomRangeType.HYPERLINK){const y=(h=_.properties)==null?void 0:h.url,I=this._isLegalRangeUrl(t,y);if(I){const{range:v,worksheet:U}=I;f=!0,g.add(this._refRangeService.registerRefRange(v,S=>{const R=m.handleDefaultRangeChangeWithEffectRefCommands(v,S);return R&&o.Rectangle.equals(R,v)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:K.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:_.rangeId,url:`#gid=${e}&range=${R?C.serializeRange(R):$}`}}],undos:[{id:K.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:_.rangeId,url:y}}],redos:[]}},U.getUnitId(),U.getSheetId()))}}}),f&&a.setValue(n,i,g)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId(),a=this._enusreMap(n,s);i.getCellMatrix().forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,s,d,c,l.p)})})};this._univerInstanceService.getAllUnitsForType(o.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(e=>{e.type===o.UniverInstanceType.UNIVER_SHEET&&t(e)}))}_initWorkbookUnload(){this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===o.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId();this._enusreMap(n,s).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}})}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===m.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:i,cellValue:s}=e,a=this._enusreMap(n,i);s&&new o.ObjectMatrix(s).forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,i,d,c,l.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===K.id){const e=t.params,{unitId:n,subUnitId:i,row:s,col:a}=e,d=m.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:i}),l=this._enusreMap(n,i).getValue(s,a);if(l&&l.dispose(),d){const{worksheet:u}=d,g=u.getCellRaw(s,a);g&&g.p&&this._registerRange(n,i,s,a,g.p)}}}))}};q=Oe([ne(0,o.ICommandService),ne(1,o.IUniverInstanceService),ne(2,o.Inject(m.RefRangeService))],q);var De=Object.defineProperty,Ve=Object.getOwnPropertyDescriptor,$e=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ve(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&De(t,e,i),i},F=(r,t)=>(e,n)=>t(e,n,r);let J=class extends o.Disposable{constructor(r,t,e,n){super(),this._sheetInterceptorService=r,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.SetRangeValuesCommand.id){const t=r.params,{unitId:e,subUnitId:n}=t,i=[],s=[];return t.cellValue&&new o.ObjectMatrix(t.cellValue).forValue((a,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,a,d);c&&(i.push({id:k.id,params:{unitId:e,subUnitId:n,id:c.id}}),s.push({id:E.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:s,redos:i}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.ClearSelectionContentCommand.id||r.id===m.ClearSelectionAllCommand.id||r.id===m.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),i=m.getSheetCommandTarget(this._univerInstanceService);if(n&&i){const{unitId:s,subUnitId:a}=i;o.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(s,a,d,c);l&&(t.push({id:k.id,params:{unitId:s,subUnitId:a,id:l.id}}),e.push({id:E.id,params:{unitId:s,subUnitId:a,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(m.AFTER_CELL_EDIT,{handler:(r,t,e)=>{if(!r||r.p)return e(r);if(typeof r.v=="string"&&o.Tools.isLegalUrl(r.v)&&r.v[r.v.length-1]!==" "){const{unitId:n,subUnitId:i}=t,s=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET),a=s==null?void 0:s.getSheetBySheetId(i);if(!a)return e(r);const d=a.getBlankCellDocumentModel(r);if(!d.documentModel)return e(r);const c=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:r.v.length,collapsed:!1},body:{dataStream:`${r.v}`,customRanges:[{startIndex:0,endIndex:r.v.length-1,rangeId:o.generateRandomId(),rangeType:o.CustomRangeType.HYPERLINK,properties:{url:r.v}}]},doc:d.documentModel});if(!c)return e(r);const l=d.documentModel.getBody();return o.TextX.apply(l,c.serialize()),e({...r,p:{id:o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:l,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(r)}}))}};J=$e([F(0,o.Inject(m.SheetInterceptorService)),F(1,o.Inject(p.HyperLinkModel)),F(2,o.Inject(m.SheetsSelectionsService)),F(3,o.IUniverInstanceService)],J);var oe=(r=>(r[r.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",r[r.UNIVER_DOC=1]="UNIVER_DOC",r[r.UNIVER_SHEET=2]="UNIVER_SHEET",r[r.UNIVER_SLIDE=3]="UNIVER_SLIDE",r[r.UNIVER_PROJECT=4]="UNIVER_PROJECT",r[r.UNRECOGNIZED=-1]="UNRECOGNIZED",r))(oe||{}),je=Object.defineProperty,Ae=Object.getOwnPropertyDescriptor,xe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ae(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&je(t,e,i),i},de=(r,t)=>(e,n)=>t(e,n,r);let X=class extends o.Disposable{constructor(r,t){super(),this._resourceManagerService=r,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const r=e=>{const n=this._hyperLinkModel.getUnit(e),i={};return n?(n.forEach(s=>{i[s.subUnitId]=s.links.map(({display:a,...d})=>d)}),JSON.stringify(i)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:ae,businesses:[oe.UNIVER_SHEET],toJson:e=>r(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(i=>{n[i].forEach(a=>{this._hyperLinkModel.addHyperLink(e,i,a)})})}}))}};X=xe([de(0,o.IResourceManagerService),de(1,o.Inject(p.HyperLinkModel))],X);const ce={type:o.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(r,t){if(!t)return!1;const e=r.get(o.ICommandService),n=r.get(o.IUndoRedoService),i=r.get(o.IUniverInstanceService),s=r.get(p.HyperLinkModel),a=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:u,worksheet:g}=d,{link:f}=t,{payload:_,display:h,row:y,column:I,id:v}=f,U=g.getCell(y,I),S=g.getBlankCellDocumentModel(U),R=S.documentModel.getSnapshot(),M=o.Tools.deepClone(R.body);if(!M)return!1;let P;if(h?P=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:M.dataStream.length-2,collapsed:!0},body:{dataStream:`${h}`,customRanges:[{startIndex:0,endIndex:h.length-1,rangeType:o.CustomRangeType.HYPERLINK,rangeId:v,properties:{url:_}}]},doc:S.documentModel}):P=o.BuildTextUtils.customRange.add({body:M,ranges:[{startOffset:0,endOffset:M.dataStream.length-2,collapsed:!1}],rangeId:v,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:_,refId:v}}),!P)return!1;const j=o.TextX.apply(M,P.serialize()),b={p:{...R,body:j},t:o.CellValueType.STRING},N=await a.onWriteCell(u,g,y,I,b),O={unitId:c,subUnitId:l,cellValue:{[f.row]:{[f.column]:N}}},re={id:m.SetRangeValuesMutation.id,params:O},Q=m.SetRangeValuesUndoMutationFactory(r,O),se={id:m.SetRangeValuesMutation.id,params:Q},A=[re],D=[se],V=s.getHyperLinkByLocation(c,l,y,I);return V&&(A.push({id:k.id,params:{unitId:c,subUnitId:l,id:V.id}}),D.push({id:E.id,params:{unitId:c,subUnitId:l,link:V}})),await o.sequenceExecuteAsync(A,e)?(n.pushUndoRedo({redoMutations:A,undoMutations:D,unitID:c}),!0):!1}},le={id:"sheets.command.add-rich-hyper-link",type:o.CommandType.COMMAND,handler:async(r,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,i=r.get(o.ICommandService),s=o.generateRandomId(),{payload:a}=n,d=x.addCustomRangeBySelectionFactory(r,{unitId:e,rangeId:s,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:a,refId:s}});return d?i.syncExecuteCommand(d.id,d.params):!1}},ue={type:o.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(r,t){var b,N;if(!t)return!1;const e=r.get(o.ICommandService),n=r.get(o.IUndoRedoService),i=r.get(o.IUniverInstanceService),s=r.get(p.HyperLinkModel),a=m.getSheetCommandTarget(i,t);if(!a)return!1;const{row:d,column:c,id:l}=t,{unitId:u,subUnitId:g,worksheet:f}=a,_=f.getCell(d,c);if(!_)return!1;const h=f.getCellDocumentModelWithFormula(_);if(!(h!=null&&h.documentModel))return!1;const y=o.Tools.deepClone(h.documentModel.getSnapshot());if(!((N=(b=y.body)==null?void 0:b.customRanges)==null?void 0:N.find(O=>O.rangeId===l)))return!1;const v=o.BuildTextUtils.customRange.delete(r,{documentDataModel:h.documentModel,rangeId:l});if(!v)return!1;const U=o.TextX.apply(y.body,v.serialize()),S=[],R=[],M={unitId:u,subUnitId:g,cellValue:{[d]:{[c]:{p:{...y,body:U},t:o.CellValueType.STRING}}}};S.push({id:m.SetRangeValuesMutation.id,params:M});const P=m.SetRangeValuesUndoMutationFactory(r,M);R.push({id:m.SetRangeValuesMutation.id,params:P});const j=s.getHyperLinkByLocation(u,g,d,c);return j&&(S.push({id:k.id,params:{unitId:u,subUnitId:g,id:l}}),R.push({id:E.id,params:{unitId:u,subUnitId:g,link:{...j}}})),o.sequenceExecute(S,e).result?(n.pushUndoRedo({redoMutations:S,undoMutations:R,unitID:u}),!0):!1}},pe={type:o.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(r,t){var u,g;if(!t)return!1;const{id:e,documentId:n}=t,i=r.get(o.ICommandService),a=r.get(o.IUniverInstanceService).getUnit(n,o.UniverInstanceType.UNIVER_DOC),d=(g=(u=a==null?void 0:a.getBody())==null?void 0:u.customRanges)==null?void 0:g.find(f=>f.rangeId===e);let c=null;d&&d.endIndex===a.getBody().dataStream.length-3&&(c={dataStream:" "});const l=x.deleteCustomRangeFactory(r,{unitId:n,rangeId:e,insert:c});return l?i.syncExecuteCommand(l.id,l.params):!1}},ge={type:o.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(r,t){var ye,ve,Se;if(!t)return!1;const e=r.get(o.ICommandService),n=r.get(o.IUndoRedoService),i=r.get(o.IUniverInstanceService),s=r.get(p.HyperLinkModel),a=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:u,id:g}=t,{workbook:f,worksheet:_,unitId:h,subUnitId:y}=d,{payload:I,display:v=""}=c,U=_.getCell(l,u);if(!U)return!1;const S=_.getCellDocumentModelWithFormula(U);if(!(S!=null&&S.documentModel))return!1;const R=S.documentModel.getSnapshot(),M=(ve=(ye=R.body)==null?void 0:ye.customRanges)==null?void 0:ve.find(Ze=>Ze.rangeId===g);if(!M)return!1;const P=o.generateRandomId(),H=(Se=o.getBodySlice(S.documentModel.getBody(),M.startIndex,M.endIndex+1).textRuns)==null?void 0:Se[0];H&&(H.ed=v.length+1);const b=x.replaceSelectionFactory(r,{unitId:h,body:{dataStream:`${v}`,customRanges:[{rangeId:P,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:v.length-1,properties:{url:I}}],textRuns:H?[H]:void 0},selection:{startOffset:M.startIndex,endOffset:M.endIndex+1,collapsed:!1},doc:S.documentModel});if(!b)return!1;const N=o.TextX.apply(o.Tools.deepClone(R.body),b.textX.serialize()),O={p:{...R,body:N},t:o.CellValueType.STRING},re=await a.onWriteCell(f,_,l,u,O),Q={id:m.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:y,cellValue:{[l]:{[u]:re}}}},se=m.SetRangeValuesUndoMutationFactory(r,Q.params),A={id:m.SetRangeValuesMutation.id,params:se},D=[Q],V=[A],ee=s.getHyperLinkByLocation(h,y,l,u);return ee&&(D.push({id:k.id,params:{unitId:h,subUnitId:y,id:ee.id}}),V.push({id:E.id,params:{unitId:h,subUnitId:y,link:ee}})),await o.sequenceExecuteAsync(D,e)?(n.pushUndoRedo({redoMutations:D,undoMutations:V,unitID:h}),!0):!1}},he={type:o.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(r,t)=>{var h,y,I,v;if(!t)return!1;const{documentId:e,payload:n,id:i}=t,s=r.get(o.IUniverInstanceService),a=r.get(o.ICommandService),d=s.getUnit(e,o.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(y=(h=d.getBody())==null?void 0:h.customRanges)==null?void 0:y.find(U=>U.rangeId===i);if(!c)return!1;const l=(I=t.payload.display)!=null?I:"",u=o.generateRandomId(),f=(v=o.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:v[0];f&&(f.ed=l.length+1);const _=x.replaceSelectionFactory(r,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:u,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:f?[f]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return _?a.syncExecuteCommand(_.id,_.params):!1}};var We=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,Ke=(r,t,e,n)=>{for(var i=n>1?void 0:n?Be(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&We(t,e,i),i},ze=(r,t)=>(e,n)=>t(e,n,r);let Z=class extends o.Disposable{constructor(r){super(),this._commandService=r,this._registerCommands()}_registerCommands(){[ce,ge,ue,he,pe,le,E,W,k,B,K].forEach(r=>{this._commandService.registerCommand(r)})}};Z=Ke([ze(0,o.ICommandService)],Z);var Ge=Object.defineProperty,Ye=Object.getOwnPropertyDescriptor,qe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ye(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Ge(t,e,i),i},ie=(r,t)=>(e,n)=>t(e,n,r);p.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${w.SHEET}=${e}${n?`&${typeof n=="string"?w.DEFINE_NAME:w.RANGE}=${typeof n=="string"?n:C.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,i,s;if(t.startsWith("#")){const a=new URLSearchParams(t.slice(1)),d={gid:(e=a.get("gid"))!=null?e:"",range:(n=a.get("range"))!=null?n:"",rangeid:(i=a.get("rangeid"))!=null?i:"",unitid:(s=a.get("unitid"))!=null?s:""},c=this._getURLName(d);return{type:c.type,name:c.name,url:t,searchObj:d}}else return{type:w.URL,name:t,url:t,searchObj:null}}_getURLName(t){var u;const{gid:e,range:n,rangeid:i,unitid:s}=t,a=s?this._univerInstanceService.getUnit(s,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),d={type:w.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!a)return d;const c=e?a.getSheetBySheetId(e):a.getActiveSheet(),l=(u=c==null?void 0:c.getName())!=null?u:"";if(n){if(!c)return d;const g=C.deserializeRangeWithSheet(n).range;return o.isValidRange(g,c)&&n!==$?{type:w.RANGE,name:C.serializeRangeWithSheet(l,g)}:d}if(i){const g=this._definedNamesService.getValueById(a.getUnitId(),i);return g?{type:w.DEFINE_NAME,name:g.formulaOrRefString}:d}if(e){const g=a.getSheetBySheetId(e);return g?{type:w.SHEET,name:g.getName()}:d}return d}},p.SheetsHyperLinkParserService=qe([ie(0,o.IUniverInstanceService),ie(1,o.Inject(o.LocaleService)),ie(2,C.IDefinedNamesService)],p.SheetsHyperLinkParserService);var me=Object.defineProperty,Fe=Object.getOwnPropertyDescriptor,Je=(r,t,e)=>t in r?me(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Xe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Fe(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&me(t,e,i),i},fe=(r,t)=>(e,n)=>t(e,n,r),_e=(r,t,e)=>Je(r,typeof t!="symbol"?t+"":t,e);p.UniverSheetsHyperLinkPlugin=class extends o.Plugin{constructor(t=Le,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...i}=this._config;this._configService.setConfig(Ue,i)}onStarting(){o.registerDependencies(this._injector,[[p.HyperLinkModel],[p.SheetsHyperLinkParserService],[X],[Z],[G],[J],[Y],[q]]),o.touchDependencies(this._injector,[[G],[X],[Z],[J],[Y],[q]])}},_e(p.UniverSheetsHyperLinkPlugin,"pluginName",ae),_e(p.UniverSheetsHyperLinkPlugin,"type",o.UniverInstanceType.UNIVER_SHEET),p.UniverSheetsHyperLinkPlugin=Xe([o.DependentOn(m.UniverSheetsPlugin),fe(1,o.Inject(o.Injector)),fe(2,o.IConfigService)],p.UniverSheetsHyperLinkPlugin),p.AddHyperLinkCommand=ce,p.AddHyperLinkMutation=E,p.AddRichHyperLinkCommand=le,p.CancelHyperLinkCommand=ue,p.CancelRichHyperLinkCommand=pe,p.ERROR_RANGE=$,p.RemoveHyperLinkMutation=k,p.SheetHyperLinkType=w,p.UpdateHyperLinkCommand=ge,p.UpdateHyperLinkMutation=W,p.UpdateHyperLinkRefMutation=B,p.UpdateRichHyperLinkCommand=he,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
1
+ (function(p,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("rxjs"),require("@univerjs/sheets"),require("@univerjs/engine-formula"),require("@univerjs/docs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","@univerjs/sheets","@univerjs/engine-formula","@univerjs/docs"],o):(p=typeof globalThis<"u"?globalThis:p||self,o(p.UniverSheetsHyperLink={},p.UniverCore,p.rxjs,p.UniverSheets,p.UniverEngineFormula,p.UniverDocs))})(this,function(p,o,T,m,C,x){"use strict";var Qe=Object.defineProperty;var et=(p,o,T)=>o in p?Qe(p,o,{enumerable:!0,configurable:!0,writable:!0,value:T}):p[o]=T;var L=(p,o,T)=>et(p,typeof o!="symbol"?o+"":o,T);var Re=Object.defineProperty,Me=Object.getOwnPropertyDescriptor,Ce=(r,t,e,n)=>{for(var i=n>1?void 0:n?Me(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Re(t,e,i),i},Ue=(r,t)=>(e,n)=>t(e,n,r);p.HyperLinkModel=class extends o.Disposable{constructor(e){super();L(this,"_linkUpdate$",new T.Subject);L(this,"linkUpdate$",this._linkUpdate$.asObservable());L(this,"_linkMap",new Map);L(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let i=this._linkMap.get(e);i||(i=new Map,this._linkMap.set(e,i));let s=i.get(n);s||(s=new o.ObjectMatrix,i.set(n,s));let a=this._linkPositionMap.get(e);a||(a=new Map,this._linkPositionMap.set(e,a));let d=a.get(n);return d||(d=new Map,a.set(n,d)),{matrix:s,positionMap:d}}addHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n);return s.setValue(i.row,i.column,i),a.set(i.id,{row:i.row,column:i.column,link:i}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:i,type:"add"}),!0}updateHyperLink(e,n,i,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;const u=d.getValue(l.row,l.column);return u&&(Object.assign(u,s),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:u.display,payload:u.payload},id:i,type:"update",silent:a})),!0}updateHyperLinkRef(e,n,i,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;let u=d.getValue(l.row,l.column);return!u||u.id!==i?u=l.link:d.realDeleteValue(l.row,l.column),Object.assign(u,s),c.set(i,{...s,link:u}),d.setValue(s.row,s.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:i,type:"updateRef",silent:a}),!0}removeHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(i);if(!d)return!1;a.delete(i);const c=s.getValue(d.row,d.column);return c&&c.id===i&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(i);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,i,s){const{matrix:a}=this._ensureMap(e,n);return a.getValue(i,s)}getHyperLinkByLocationSync(e,n,i,s){var g,f,_,h,y;const{matrix:a}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,o.UniverInstanceType.UNIVER_SHEET),c=(g=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:g.getCellRaw(i,s),l=((y=(h=c==null?void 0:c.v)!=null?h:(_=(f=c==null?void 0:c.p)==null?void 0:f.body)==null?void 0:_.dataStream.slice(0,-2))!=null?y:"").toString(),u=a.getValue(i,s);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:i}=this._ensureMap(e,n),s=[];return i.forValue((a,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(i=>{const s=this.getSubUnit(e,i);return{unitId:e,subUnitId:i,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}},p.HyperLinkModel=Ce([Ue(0,o.IUniverInstanceService)],p.HyperLinkModel);var w=(r=>(r.SHEET="gid",r.RANGE="range",r.DEFINE_NAME="rangeid",r.INVALID="invalid",r.URL="url",r))(w||{});const Le="sheets-hyper-link.config",ae={},E={type:o.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,link:s}=t;return e.addHyperLink(n,i,s)}},k={type:o.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:s}=t;return e.removeHyperLink(n,i,s)}},W={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,payload:s,id:a}=t;return e.updateHyperLink(n,i,a,s,!1)}},B={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:s,row:a,column:d,silent:c}=t;return e.updateHyperLinkRef(n,i,s,{row:a,column:d},c)}},K={type:o.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(r,t){var _,h,y;if(!t)return!1;const{unitId:e,subUnitId:n,row:i,col:s,id:a,url:d}=t,c=r.get(o.IUniverInstanceService),l=m.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:u}=l,g=u.getCellRaw(i,s),f=(y=(h=(_=g==null?void 0:g.p)==null?void 0:_.body)==null?void 0:h.customRanges)==null?void 0:y.find(v=>v.rangeType===o.CustomRangeType.HYPERLINK&&v.rangeId===a);return f&&(f.properties.url=d),!0}},oe="SHEET_HYPER_LINK_PLUGIN",$="err";var we=Object.defineProperty,Ee=Object.getOwnPropertyDescriptor,ke=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ee(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&we(t,e,i),i},z=(r,t)=>(e,n)=>t(e,n,r);let G=class extends o.Disposable{constructor(t,e,n,i){super();L(this,"_disposableMap",new Map);L(this,"_watchDisposableMap",new Map);L(this,"_rangeDisableMap",new Map);L(this,"_rangeWatcherMap",new Map);L(this,"_handlePositionChange",(t,e,n,i,s)=>{const a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return i?{redos:[{id:B.id,params:{unitId:t,subUnitId:e,id:n.id,row:i.startRow,column:i.startColumn,silent:s}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,id:n.id,row:a.startRow,column:a.startColumn,silent:s}}]}:{redos:[{id:k.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:E.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=i,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},a=d=>{const c=m.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===s.startColumn&&l.startRow===s.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(i,this._refRangeService.registerRefRange(s,a,t,e))}_watchPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(t,e,s,(a,d)=>{const{redos:c}=this._handlePositionChange(t,e,n,d,!0);o.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(t){const e=this._disposableMap.get(t);e==null||e.dispose(),this._disposableMap.delete(t)}_unwatchPosition(t){const e=this._watchDisposableMap.get(t);e==null||e.dispose(),this._watchDisposableMap.delete(t)}_registerRange(t,e,n,i=!1){var s,a,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(s=c.get("gid"))!=null?s:"",range:(a=c.get("range"))!=null?a:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const u=l.gid,g=C.deserializeRangeWithSheet(l.range).range;if(o.isValidRange(g)&&l.range!==$){const f=_=>{const h=m.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(g,_,{selectionManagerService:this._selectionManagerService});return h&&C.serializeRange(h)===C.serializeRange(g)?{redos:[],undos:[]}:{redos:[{id:W.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`}}}],undos:[{id:W.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(g,f,t,u)),i||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,u,g,(_,h)=>{this._hyperLinkModel.updateHyperLink(t,u,e,{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`},!0)},!0))}}}}_unregisterRange(t){const e=this._rangeDisableMap.get(t);e==null||e.dispose(),this._rangeDisableMap.delete(t)}_unwatchRange(t){const e=this._rangeWatcherMap.get(t);e==null||e.dispose(),this._rangeWatcherMap.delete(t)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(n=>{const{unitId:i,subUnitId:s,links:a}=n;a.forEach(d=>{this._registerPosition(i,s,d),this._watchPosition(i,s,d),this._registerRange(i,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:i,silent:s}=t,a=this._hyperLinkModel.getHyperLink(e,n,i);if(!a)return;this._unregisterPosition(i),this._registerPosition(e,n,a),s||(this._unwatchPosition(i),this._watchPosition(e,n,a));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:i}=n;i.forEach(s=>{this._unregisterPosition(s.id),this._unwatchPosition(s.id),this._unregisterRange(s.id),this._unwatchRange(s.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(o.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};G=ke([z(0,o.Inject(m.RefRangeService)),z(1,o.Inject(p.HyperLinkModel)),z(2,o.Inject(m.SheetsSelectionsService)),z(3,o.ICommandService)],G);var Pe=Object.defineProperty,be=Object.getOwnPropertyDescriptor,Te=(r,t,e,n)=>{for(var i=n>1?void 0:n?be(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Pe(t,e,i),i},te=(r,t)=>(e,n)=>t(e,n,r);let Y=class extends o.Disposable{constructor(r,t,e){super(),this._sheetInterceptorService=r,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{var t;if(r.id===m.RemoveSheetCommand.id){const e=r.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const i=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const a=this._hyperLinkModel.getSubUnit(i,s),d=a.map(l=>({id:k.id,params:{unitId:i,subUnitId:s,id:l.id}})),c=a.map(l=>({id:E.id,params:{unitId:i,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};Y=Te([te(0,o.Inject(m.SheetInterceptorService)),te(1,o.IUniverInstanceService),te(2,o.Inject(p.HyperLinkModel))],Y);var He=Object.defineProperty,Ne=Object.getOwnPropertyDescriptor,Oe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ne(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&He(t,e,i),i},ne=(r,t)=>(e,n)=>t(e,n,r);let q=class extends o.Disposable{constructor(t,e,n){super();L(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let i=n.get(e);return i||(i=new o.ObjectMatrix,n.set(e,i)),i}_isLegalRangeUrl(t,e){var i,s,a;const n=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(i=d.get("gid"))!=null?i:"",range:(s=d.get("range"))!=null?s:"",rangeid:(a=d.get("rangeid"))!=null?a:""};if(c.range&&c.gid){const l=c.gid,u=n.getSheetBySheetId(l);if(!u)return null;const g=C.deserializeRangeWithSheet(c.range).range;if(o.isValidRange(g,u)&&c.range!==$)return{range:g,worksheet:u}}}return null}_registerRange(t,e,n,i,s){var d,c,l,u;const a=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(g=>{var f;return g.rangeType===o.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(f=g.properties)==null?void 0:f.url)})){const g=new o.DisposableCollection;let f=!1;(u=(l=s.body)==null?void 0:l.customRanges)==null||u.forEach(_=>{var h;if(_.rangeType===o.CustomRangeType.HYPERLINK){const y=(h=_.properties)==null?void 0:h.url,v=this._isLegalRangeUrl(t,y);if(v){const{range:S,worksheet:U}=v;f=!0,g.add(this._refRangeService.registerRefRange(S,I=>{const R=m.handleDefaultRangeChangeWithEffectRefCommands(S,I);return R&&o.Rectangle.equals(R,S)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:K.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:_.rangeId,url:`#gid=${e}&range=${R?C.serializeRange(R):$}`}}],undos:[{id:K.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:_.rangeId,url:y}}],redos:[]}},U.getUnitId(),U.getSheetId()))}}}),f&&a.setValue(n,i,g)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId(),a=this._enusreMap(n,s);i.getCellMatrix().forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,s,d,c,l.p)})})};this._univerInstanceService.getAllUnitsForType(o.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(e=>{e.type===o.UniverInstanceType.UNIVER_SHEET&&t(e)}))}_initWorkbookUnload(){this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===o.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId();this._enusreMap(n,s).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}})}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===m.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:i,cellValue:s}=e,a=this._enusreMap(n,i);s&&new o.ObjectMatrix(s).forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,i,d,c,l.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===K.id){const e=t.params,{unitId:n,subUnitId:i,row:s,col:a}=e,d=m.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:i}),l=this._enusreMap(n,i).getValue(s,a);if(l&&l.dispose(),d){const{worksheet:u}=d,g=u.getCellRaw(s,a);g&&g.p&&this._registerRange(n,i,s,a,g.p)}}}))}};q=Oe([ne(0,o.ICommandService),ne(1,o.IUniverInstanceService),ne(2,o.Inject(m.RefRangeService))],q);var De=Object.defineProperty,Ve=Object.getOwnPropertyDescriptor,$e=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ve(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&De(t,e,i),i},F=(r,t)=>(e,n)=>t(e,n,r);let J=class extends o.Disposable{constructor(r,t,e,n){super(),this._sheetInterceptorService=r,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.SetRangeValuesCommand.id){const t=r.params,{unitId:e,subUnitId:n}=t,i=[],s=[];return t.cellValue&&new o.ObjectMatrix(t.cellValue).forValue((a,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,a,d);c&&(i.push({id:k.id,params:{unitId:e,subUnitId:n,id:c.id}}),s.push({id:E.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:s,redos:i}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.ClearSelectionContentCommand.id||r.id===m.ClearSelectionAllCommand.id||r.id===m.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),i=m.getSheetCommandTarget(this._univerInstanceService);if(n&&i){const{unitId:s,subUnitId:a}=i;o.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(s,a,d,c);l&&(t.push({id:k.id,params:{unitId:s,subUnitId:a,id:l.id}}),e.push({id:E.id,params:{unitId:s,subUnitId:a,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(m.AFTER_CELL_EDIT,{handler:(r,t,e)=>{if(!r||r.p)return e(r);if(typeof r.v=="string"&&o.Tools.isLegalUrl(r.v)&&r.v[r.v.length-1]!==" "){const{unitId:n,subUnitId:i}=t,s=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET),a=s==null?void 0:s.getSheetBySheetId(i);if(!a)return e(r);const d=a.getBlankCellDocumentModel(r);if(!d.documentModel)return e(r);const c=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:r.v.length,collapsed:!1},body:{dataStream:`${r.v}`,customRanges:[{startIndex:0,endIndex:r.v.length-1,rangeId:o.generateRandomId(),rangeType:o.CustomRangeType.HYPERLINK,properties:{url:r.v}}]},doc:d.documentModel});if(!c)return e(r);const l=d.documentModel.getBody();return o.TextX.apply(l,c.serialize()),e({...r,p:{id:o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:l,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(r)}}))}};J=$e([F(0,o.Inject(m.SheetInterceptorService)),F(1,o.Inject(p.HyperLinkModel)),F(2,o.Inject(m.SheetsSelectionsService)),F(3,o.IUniverInstanceService)],J);var de=(r=>(r[r.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",r[r.UNIVER_DOC=1]="UNIVER_DOC",r[r.UNIVER_SHEET=2]="UNIVER_SHEET",r[r.UNIVER_SLIDE=3]="UNIVER_SLIDE",r[r.UNIVER_PROJECT=4]="UNIVER_PROJECT",r[r.UNRECOGNIZED=-1]="UNRECOGNIZED",r))(de||{}),je=Object.defineProperty,Ae=Object.getOwnPropertyDescriptor,xe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ae(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&je(t,e,i),i},ce=(r,t)=>(e,n)=>t(e,n,r);let X=class extends o.Disposable{constructor(r,t){super(),this._resourceManagerService=r,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const r=e=>{const n=this._hyperLinkModel.getUnit(e),i={};return n?(n.forEach(s=>{i[s.subUnitId]=s.links.map(({display:a,...d})=>d)}),JSON.stringify(i)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:oe,businesses:[de.UNIVER_SHEET],toJson:e=>r(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(i=>{n[i].forEach(a=>{this._hyperLinkModel.addHyperLink(e,i,a)})})}}))}};X=xe([ce(0,o.IResourceManagerService),ce(1,o.Inject(p.HyperLinkModel))],X);const le={type:o.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(r,t){if(!t)return!1;const e=r.get(o.ICommandService),n=r.get(o.IUndoRedoService),i=r.get(o.IUniverInstanceService),s=r.get(p.HyperLinkModel),a=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:u,worksheet:g}=d,{link:f}=t,{payload:_,display:h,row:y,column:v,id:S}=f,U=g.getCell(y,v),I=g.getBlankCellDocumentModel(U),R=I.documentModel.getSnapshot(),M=o.Tools.deepClone(R.body);if(!M)return!1;let P;if(h?P=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:M.dataStream.length-2,collapsed:M.dataStream.length-2===0},body:{dataStream:`${h}`,customRanges:[{startIndex:0,endIndex:h.length-1,rangeType:o.CustomRangeType.HYPERLINK,rangeId:S,properties:{url:_}}]},doc:I.documentModel}):P=o.BuildTextUtils.customRange.add({body:M,ranges:[{startOffset:0,endOffset:M.dataStream.length-2,collapsed:!1}],rangeId:S,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:_,refId:S}}),!P)return!1;const j=o.TextX.apply(M,P.serialize()),b={p:{...R,body:j},t:o.CellValueType.STRING},N=await a.onWriteCell(u,g,y,v,b),O={unitId:c,subUnitId:l,cellValue:{[f.row]:{[f.column]:N}}},re={id:m.SetRangeValuesMutation.id,params:O},Q=m.SetRangeValuesUndoMutationFactory(r,O),se={id:m.SetRangeValuesMutation.id,params:Q},A=[re],D=[se],V=s.getHyperLinkByLocation(c,l,y,v);return V&&(A.push({id:k.id,params:{unitId:c,subUnitId:l,id:V.id}}),D.push({id:E.id,params:{unitId:c,subUnitId:l,link:V}})),await o.sequenceExecuteAsync(A,e)?(n.pushUndoRedo({redoMutations:A,undoMutations:D,unitID:c}),!0):!1}},ue={id:"sheets.command.add-rich-hyper-link",type:o.CommandType.COMMAND,handler:async(r,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,i=r.get(o.ICommandService),s=o.generateRandomId(),{payload:a}=n,d=x.addCustomRangeBySelectionFactory(r,{unitId:e,rangeId:s,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:a,refId:s}});return d?i.syncExecuteCommand(d.id,d.params):!1}},pe={type:o.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(r,t){var b,N;if(!t)return!1;const e=r.get(o.ICommandService),n=r.get(o.IUndoRedoService),i=r.get(o.IUniverInstanceService),s=r.get(p.HyperLinkModel),a=m.getSheetCommandTarget(i,t);if(!a)return!1;const{row:d,column:c,id:l}=t,{unitId:u,subUnitId:g,worksheet:f}=a,_=f.getCell(d,c);if(!_)return!1;const h=f.getCellDocumentModelWithFormula(_);if(!(h!=null&&h.documentModel))return!1;const y=o.Tools.deepClone(h.documentModel.getSnapshot()),v=(N=(b=y.body)==null?void 0:b.customRanges)==null?void 0:N.find(O=>`${O.rangeId}`===l);if(!v)return!1;const S=o.BuildTextUtils.customRange.delete(r,{documentDataModel:h.documentModel,rangeId:v.rangeId});if(!S)return!1;const U=o.TextX.apply(y.body,S.serialize()),I=[],R=[],M={unitId:u,subUnitId:g,cellValue:{[d]:{[c]:{p:{...y,body:U},t:o.CellValueType.STRING}}}};I.push({id:m.SetRangeValuesMutation.id,params:M});const P=m.SetRangeValuesUndoMutationFactory(r,M);R.push({id:m.SetRangeValuesMutation.id,params:P});const j=s.getHyperLinkByLocation(u,g,d,c);return j&&(I.push({id:k.id,params:{unitId:u,subUnitId:g,id:l}}),R.push({id:E.id,params:{unitId:u,subUnitId:g,link:{...j}}})),o.sequenceExecute(I,e).result?(n.pushUndoRedo({redoMutations:I,undoMutations:R,unitID:u}),!0):!1}},ge={type:o.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(r,t){var u,g;if(!t)return!1;const{id:e,documentId:n}=t,i=r.get(o.ICommandService),a=r.get(o.IUniverInstanceService).getUnit(n,o.UniverInstanceType.UNIVER_DOC),d=(g=(u=a==null?void 0:a.getBody())==null?void 0:u.customRanges)==null?void 0:g.find(f=>f.rangeId===e);let c=null;d&&d.endIndex===a.getBody().dataStream.length-3&&(c={dataStream:" "});const l=x.deleteCustomRangeFactory(r,{unitId:n,rangeId:e,insert:c});return l?i.syncExecuteCommand(l.id,l.params):!1}},he={type:o.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(r,t){var ve,Se,Ie;if(!t)return!1;const e=r.get(o.ICommandService),n=r.get(o.IUndoRedoService),i=r.get(o.IUniverInstanceService),s=r.get(p.HyperLinkModel),a=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:u,id:g}=t,{workbook:f,worksheet:_,unitId:h,subUnitId:y}=d,{payload:v,display:S=""}=c,U=_.getCell(l,u);if(!U)return!1;const I=_.getCellDocumentModelWithFormula(U);if(!(I!=null&&I.documentModel))return!1;const R=I.documentModel.getSnapshot(),M=(Se=(ve=R.body)==null?void 0:ve.customRanges)==null?void 0:Se.find(Ze=>`${Ze.rangeId}`===g);if(!M)return!1;const P=o.generateRandomId(),H=(Ie=o.getBodySlice(I.documentModel.getBody(),M.startIndex,M.endIndex+1).textRuns)==null?void 0:Ie[0];H&&(H.ed=S.length+1);const b=x.replaceSelectionFactory(r,{unitId:h,body:{dataStream:`${S}`,customRanges:[{rangeId:P,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:S.length-1,properties:{url:v}}],textRuns:H?[H]:void 0},selection:{startOffset:M.startIndex,endOffset:M.endIndex+1,collapsed:!1},doc:I.documentModel});if(!b)return!1;const N=o.TextX.apply(o.Tools.deepClone(R.body),b.textX.serialize()),O={p:{...R,body:N},t:o.CellValueType.STRING},re=await a.onWriteCell(f,_,l,u,O),Q={id:m.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:y,cellValue:{[l]:{[u]:re}}}},se=m.SetRangeValuesUndoMutationFactory(r,Q.params),A={id:m.SetRangeValuesMutation.id,params:se},D=[Q],V=[A],ee=s.getHyperLinkByLocation(h,y,l,u);return ee&&(D.push({id:k.id,params:{unitId:h,subUnitId:y,id:ee.id}}),V.push({id:E.id,params:{unitId:h,subUnitId:y,link:ee}})),await o.sequenceExecuteAsync(D,e)?(n.pushUndoRedo({redoMutations:D,undoMutations:V,unitID:h}),!0):!1}},me={type:o.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(r,t)=>{var h,y,v,S;if(!t)return!1;const{documentId:e,payload:n,id:i}=t,s=r.get(o.IUniverInstanceService),a=r.get(o.ICommandService),d=s.getUnit(e,o.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(y=(h=d.getBody())==null?void 0:h.customRanges)==null?void 0:y.find(U=>U.rangeId===i);if(!c)return!1;const l=(v=t.payload.display)!=null?v:"",u=o.generateRandomId(),f=(S=o.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:S[0];f&&(f.ed=l.length+1);const _=x.replaceSelectionFactory(r,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:u,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:f?[f]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return _?a.syncExecuteCommand(_.id,_.params):!1}};var We=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,Ke=(r,t,e,n)=>{for(var i=n>1?void 0:n?Be(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&We(t,e,i),i},ze=(r,t)=>(e,n)=>t(e,n,r);let Z=class extends o.Disposable{constructor(r){super(),this._commandService=r,this._registerCommands()}_registerCommands(){[le,he,pe,me,ge,ue,E,W,k,B,K].forEach(r=>{this._commandService.registerCommand(r)})}};Z=Ke([ze(0,o.ICommandService)],Z);var Ge=Object.defineProperty,Ye=Object.getOwnPropertyDescriptor,qe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ye(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Ge(t,e,i),i},ie=(r,t)=>(e,n)=>t(e,n,r);p.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${w.SHEET}=${e}${n?`&${typeof n=="string"?w.DEFINE_NAME:w.RANGE}=${typeof n=="string"?n:C.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,i,s;if(t.startsWith("#")){const a=new URLSearchParams(t.slice(1)),d={gid:(e=a.get("gid"))!=null?e:"",range:(n=a.get("range"))!=null?n:"",rangeid:(i=a.get("rangeid"))!=null?i:"",unitid:(s=a.get("unitid"))!=null?s:""},c=this._getURLName(d);return{type:c.type,name:c.name,url:t,searchObj:d}}else return{type:w.URL,name:t,url:t,searchObj:null}}_getURLName(t){var u;const{gid:e,range:n,rangeid:i,unitid:s}=t,a=s?this._univerInstanceService.getUnit(s,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),d={type:w.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!a)return d;const c=e?a.getSheetBySheetId(e):a.getActiveSheet(),l=(u=c==null?void 0:c.getName())!=null?u:"";if(n){if(!c)return d;const g=C.deserializeRangeWithSheet(n).range;return o.isValidRange(g,c)&&n!==$?{type:w.RANGE,name:C.serializeRangeWithSheet(l,g)}:d}if(i){const g=this._definedNamesService.getValueById(a.getUnitId(),i);return g?{type:w.DEFINE_NAME,name:g.formulaOrRefString}:d}if(e){const g=a.getSheetBySheetId(e);return g?{type:w.SHEET,name:g.getName()}:d}return d}},p.SheetsHyperLinkParserService=qe([ie(0,o.IUniverInstanceService),ie(1,o.Inject(o.LocaleService)),ie(2,C.IDefinedNamesService)],p.SheetsHyperLinkParserService);var fe=Object.defineProperty,Fe=Object.getOwnPropertyDescriptor,Je=(r,t,e)=>t in r?fe(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Xe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Fe(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&fe(t,e,i),i},_e=(r,t)=>(e,n)=>t(e,n,r),ye=(r,t,e)=>Je(r,typeof t!="symbol"?t+"":t,e);p.UniverSheetsHyperLinkPlugin=class extends o.Plugin{constructor(t=ae,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...i}=o.merge({},ae,this._config);this._configService.setConfig(Le,i)}onStarting(){o.registerDependencies(this._injector,[[p.HyperLinkModel],[p.SheetsHyperLinkParserService],[X],[Z],[G],[J],[Y],[q]]),o.touchDependencies(this._injector,[[G],[X],[Z],[J],[Y],[q]])}},ye(p.UniverSheetsHyperLinkPlugin,"pluginName",oe),ye(p.UniverSheetsHyperLinkPlugin,"type",o.UniverInstanceType.UNIVER_SHEET),p.UniverSheetsHyperLinkPlugin=Xe([o.DependentOn(m.UniverSheetsPlugin),_e(1,o.Inject(o.Injector)),_e(2,o.IConfigService)],p.UniverSheetsHyperLinkPlugin),p.AddHyperLinkCommand=le,p.AddHyperLinkMutation=E,p.AddRichHyperLinkCommand=ue,p.CancelHyperLinkCommand=pe,p.CancelRichHyperLinkCommand=ge,p.ERROR_RANGE=$,p.RemoveHyperLinkMutation=k,p.SheetHyperLinkType=w,p.UpdateHyperLinkCommand=he,p.UpdateHyperLinkMutation=W,p.UpdateHyperLinkRefMutation=B,p.UpdateRichHyperLinkCommand=me,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-hyper-link",
3
- "version": "0.5.1",
3
+ "version": "0.5.2-nightly.202412281605",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -52,17 +52,17 @@
52
52
  },
53
53
  "dependencies": {
54
54
  "@univerjs/protocol": "0.1.39",
55
- "@univerjs/core": "0.5.1",
56
- "@univerjs/docs": "0.5.1",
57
- "@univerjs/engine-formula": "0.5.1",
58
- "@univerjs/sheets": "0.5.1"
55
+ "@univerjs/core": "0.5.2-nightly.202412281605",
56
+ "@univerjs/engine-formula": "0.5.2-nightly.202412281605",
57
+ "@univerjs/docs": "0.5.2-nightly.202412281605",
58
+ "@univerjs/sheets": "0.5.2-nightly.202412281605"
59
59
  },
60
60
  "devDependencies": {
61
61
  "rxjs": "^7.8.1",
62
62
  "typescript": "^5.7.2",
63
- "vite": "^6.0.1",
64
- "vitest": "^2.1.6",
65
- "@univerjs-infra/shared": "0.5.1"
63
+ "vite": "^6.0.3",
64
+ "vitest": "^2.1.8",
65
+ "@univerjs-infra/shared": "0.5.2"
66
66
  },
67
67
  "space": {
68
68
  ".": {
package/LICENSE DELETED
@@ -1,176 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS