@univerjs/sheets-hyper-link 0.5.4 → 0.5.5-experimental.20250123-34738ff
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 +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/es/facade.js +137 -71
- package/lib/es/index.js +861 -860
- package/lib/types/facade/f-event.d.ts +99 -0
- package/lib/types/facade/f-range.d.ts +6 -15
- package/lib/types/facade/f-univer.d.ts +7 -0
- package/lib/types/facade/f-workbook.d.ts +6 -0
- package/lib/types/facade/f-worksheet.d.ts +3 -0
- package/lib/types/facade/index.d.ts +5 -1
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +8 -8
- package/LICENSE +0 -176
package/lib/cjs/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";var __defProp=Object.defineProperty;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const core=require("@univerjs/core"),sheetsHyperLink=require("@univerjs/sheets-hyper-link"),facade=require("@univerjs/sheets/facade");var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),_a;let SheetHyperLinkBuilder=(_a=class{constructor(_workbook,_parserService){this._workbook=_workbook,this._parserService=_parserService}getRangeUrl(range){return this._parserService.buildHyperLink(this._workbook.getId(),range.getSheetId(),range.getRange()),this}},__name(_a,"SheetHyperLinkBuilder"),_a);SheetHyperLinkBuilder=__decorateClass([__decorateParam(1,core.Inject(sheetsHyperLink.SheetsHyperLinkParserService))],SheetHyperLinkBuilder);const _FWorkbookHyperLinkMixin=class _FWorkbookHyperLinkMixin extends facade.FWorkbook{createSheetHyperlink(sheetId,range){return this._injector.get(sheetsHyperLink.SheetsHyperLinkParserService).buildHyperLink(this.getId(),sheetId,range)}parseSheetHyperlink(hyperlink){return this._injector.get(sheetsHyperLink.SheetsHyperLinkParserService).parseHyperLink(hyperlink)}};__name(_FWorkbookHyperLinkMixin,"FWorkbookHyperLinkMixin");let FWorkbookHyperLinkMixin=_FWorkbookHyperLinkMixin;facade.FWorkbook.extend(FWorkbookHyperLinkMixin);const _FWorksheetHyperlinkMixin=class _FWorksheetHyperlinkMixin extends facade.FWorksheet{getUrl(){return this._injector.get(sheetsHyperLink.SheetsHyperLinkParserService).buildHyperLink(this._workbook.getUnitId(),this._worksheet.getSheetId())}};__name(_FWorksheetHyperlinkMixin,"FWorksheetHyperlinkMixin");let FWorksheetHyperlinkMixin=_FWorksheetHyperlinkMixin;facade.FWorksheet.extend(FWorksheetHyperlinkMixin);const _FRangeHyperlinkMixin=class _FRangeHyperlinkMixin extends facade.FRange{setHyperLink(url,label){const params={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),link:{row:this._range.startRow,column:this._range.startColumn,payload:url,display:label,id:core.generateRandomId()}};return this._commandService.executeCommand(sheetsHyperLink.AddHyperLinkCommand.id,params)}getHyperLinks(){var _a2,_b,_c;const cellValue=this._worksheet.getCellRaw(this._range.startRow,this._range.startColumn);return cellValue!=null&&cellValue.p?(_c=(_b=(_a2=cellValue.p.body)==null?void 0:_a2.customRanges)==null?void 0:_b.filter(range=>range.rangeType===core.CustomRangeType.HYPERLINK).map(range=>{var _a3,_b2,_c2,_d,_e;return{id:`${range.rangeId}`,startIndex:range.startIndex,endIndex:range.endIndex,url:(_b2=(_a3=range.properties)==null?void 0:_a3.url)!=null?_b2:"",label:(_e=(_d=(_c2=cellValue.p)==null?void 0:_c2.body)==null?void 0:_d.dataStream.slice(range.startIndex,range.endIndex+1).replaceAll(core.DataStreamTreeTokenType.CUSTOM_RANGE_START,"").replaceAll(core.DataStreamTreeTokenType.CUSTOM_RANGE_END,""))!=null?_e:""}}))!=null?_c:[]:[]}updateHyperLink(id,url,label){const params={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id,payload:{payload:url,display:label}};return this._commandService.executeCommand(sheetsHyperLink.UpdateHyperLinkCommand.id,params)}cancelHyperLink(id){const params={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id};return this._commandService.syncExecuteCommand(sheetsHyperLink.CancelHyperLinkCommand.id,params)}getUrl(){return this._injector.get(sheetsHyperLink.SheetsHyperLinkParserService).buildHyperLink(this.getUnitId(),this.getSheetId(),this.getRange())}};__name(_FRangeHyperlinkMixin,"FRangeHyperlinkMixin");let FRangeHyperlinkMixin=_FRangeHyperlinkMixin;facade.FRange.extend(FRangeHyperlinkMixin);const _FSheetLinkEvent=class _FSheetLinkEvent{get BeforeSheetLinkAdd(){return"BeforeSheetLinkAdd"}get BeforeSheetLinkCancel(){return"BeforeSheetLinkCancel"}get BeforeSheetLinkUpdate(){return"BeforeSheetLinkUpdate"}};__name(_FSheetLinkEvent,"FSheetLinkEvent");let FSheetLinkEvent=_FSheetLinkEvent;core.FEventName.extend(FSheetLinkEvent);const _FSheetLinkUniver=class _FSheetLinkUniver extends core.FUniver{_initialize(injector){const commandService=injector.get(core.ICommandService);this.disposeWithMe(commandService.beforeCommandExecuted(commandInfo=>{if(commandInfo.id===sheetsHyperLink.AddHyperLinkCommand.id){if(!this._eventListend(this.Event.BeforeSheetLinkAdd))return;const eventTarget=this.getCommandSheetTarget(commandInfo);if(!eventTarget)return;const params=commandInfo.params,eventParams={workbook:eventTarget.workbook,worksheet:eventTarget.worksheet,row:params.link.row,col:params.link.column,link:params.link};if(this.fireEvent(this.Event.BeforeSheetLinkAdd,eventParams),eventParams.cancel)throw new core.CanceledError}if(commandInfo.id===sheetsHyperLink.UpdateHyperLinkCommand.id){const eventTarget=this.getCommandSheetTarget(commandInfo);if(!eventTarget)return;const params=commandInfo.params,eventParams={workbook:eventTarget.workbook,worksheet:eventTarget.worksheet,row:params.row,column:params.column,id:params.id,payload:params.payload};if(this.fireEvent(this.Event.BeforeSheetLinkUpdate,eventParams),eventParams.cancel)throw new core.CanceledError}if(commandInfo.id===sheetsHyperLink.CancelHyperLinkCommand.id){const eventTarget=this.getCommandSheetTarget(commandInfo);if(!eventTarget)return;const params=commandInfo.params,eventParams={workbook:eventTarget.workbook,worksheet:eventTarget.worksheet,row:params.row,column:params.column,id:params.id};if(this.fireEvent(this.Event.BeforeSheetLinkCancel,eventParams),eventParams.cancel)throw new core.CanceledError}}))}};__name(_FSheetLinkUniver,"FSheetLinkUniver");let FSheetLinkUniver=_FSheetLinkUniver;core.FUniver.extend(FSheetLinkUniver);exports.FWorkbookHyperLinkMixin=FWorkbookHyperLinkMixin;
|
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var ve=Object.defineProperty;var Re=(i,t,e)=>t in i?ve(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 u=d.getValue(l.row,l.column);return u&&(Object.assign(u,s),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:u.display,payload:u.payload},id:r,type:"update",silent:a})),!0}updateHyperLinkRef(e,n,r,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(r);if(!l)return!0;let u=d.getValue(l.row,l.column);return!u||u.id!==r?u=l.link:d.realDeleteValue(l.row,l.column),Object.assign(u,s),c.set(r,{...s,link:u}),d.setValue(s.row,s.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:r,type:"updateRef",silent:a}),!0}removeHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(r);if(!d)return!1;a.delete(r);const c=s.getValue(d.row,d.column);return c&&c.id===r&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(r);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,r,s){const{matrix:a}=this._ensureMap(e,n);return a.getValue(r,s)}getHyperLinkByLocationSync(e,n,r,s){var p,m,f,h,_;const{matrix:a}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,o.UniverInstanceType.UNIVER_SHEET),c=(p=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:p.getCellRaw(r,s),l=((_=(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(),u=a.getValue(r,s);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:r}=this._ensureMap(e,n),s=[];return r.forValue((a,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(r=>{const s=this.getSubUnit(e,r);return{unitId:e,subUnitId:r,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}};exports.HyperLinkModel=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:u}=l,p=u.getCellRaw(r,s),m=(_=(h=(f=p==null?void 0:p.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 u=l.gid,p=U.deserializeRangeWithSheet(l.range).range;if(o.isValidRange(p)&&l.range!==x){const m=f=>{const h=g.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(p,f,{selectionManagerService:this._selectionManagerService});return h&&U.serializeRange(h)===U.serializeRange(p)?{redos:[],undos:[]}:{redos:[{id:F.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:`#gid=${u}&range=${h?U.serializeRange(h):"err"}`}}}],undos:[{id:F.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(p,m,t,u)),r||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,u,p,(f,h)=>{this._hyperLinkModel.updateHyperLink(t,u,e,{payload:`#gid=${u}&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,u=n.getSheetBySheetId(l);if(!u)return null;const p=U.deserializeRangeWithSheet(c.range).range;if(o.isValidRange(p,u)&&c.range!==x)return{range:p,worksheet:u}}}return null}_registerRange(t,e,n,r,s){var d,c,l,u;const a=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(p=>{var m;return p.rangeType===o.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(m=p.properties)==null?void 0:m.url)})){const p=new o.DisposableCollection;let m=!1;(u=(l=s.body)==null?void 0:l.customRanges)==null||u.forEach(f=>{var h;if(f.rangeType===o.CustomRangeType.HYPERLINK){const _=(h=f.properties)==null?void 0:h.url,y=this._isLegalRangeUrl(t,_);if(y){const{range:S,worksheet:M}=y;m=!0,p.add(this._refRangeService.registerRefRange(S,I=>{const v=g.handleDefaultRangeChangeWithEffectRefCommands(S,I);return v&&o.Rectangle.equals(v,S)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:r,id:f.rangeId,url:`#gid=${e}&range=${v?U.serializeRange(v):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,p)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(r=>{const s=r.getSheetId(),a=this._enusreMap(n,s);r.getCellMatrix().forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,s,d,c,l.p)})})};this._univerInstanceService.getAllUnitsForType(o.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(e=>{e.type===o.UniverInstanceType.UNIVER_SHEET&&t(e)}))}_initWorkbookUnload(){this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===o.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(r=>{const s=r.getSheetId();this._enusreMap(n,s).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}})}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===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 u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,r,d,c,l.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===B.id){const e=t.params,{unitId:n,subUnitId:r,row:s,col:a}=e,d=g.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:r}),l=this._enusreMap(n,r).getValue(s,a);if(l&&l.dispose(),d){const{worksheet:u}=d,p=u.getCellRaw(s,a);p&&p.p&&this._registerRange(n,r,s,a,p.p)}}}))}};Y=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 ue=(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))(ue||{}),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:[ue.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 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:u,worksheet:p}=d,{link:m}=t,{payload:f,display:h,row:_,column:y,id:S}=m,M=p.getCell(_,y),I=p.getBlankCellDocumentModel(M),v=I.documentModel.getSnapshot(),R=o.Tools.deepClone(v.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:S,properties:{url:f}}]},doc:I.documentModel}):k=o.BuildTextUtils.customRange.add({body:R,ranges:[{startOffset:0,endOffset:R.dataStream.length-2,collapsed:!1}],rangeId:S,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:f,refId:S}}),!k)return!1;const D=o.TextX.apply(R,k.serialize()),b={p:{...v,body:D},t:o.CellValueType.STRING},T=await a.onWriteCell(u,p,_,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:u,subUnitId:p,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 S=o.BuildTextUtils.customRange.delete({documentDataModel:h.documentModel,rangeId:y.rangeId});if(!S)return!1;const M=o.TextX.apply(_.body,S.serialize()),I=[],v=[],R={unitId:u,subUnitId:p,cellValue:{[d]:{[c]:{p:{..._,body:M},t:o.CellValueType.STRING}}}};I.push({id:g.SetRangeValuesMutation.id,params:R});const k=g.SetRangeValuesUndoMutationFactory(i,R);v.push({id:g.SetRangeValuesMutation.id,params:k});const D=s.getHyperLinkByLocation(u,p,d,c);return D&&(I.push({id:E.id,params:{unitId:u,subUnitId:p,id:l}}),v.push({id:w.id,params:{unitId:u,subUnitId:p,link:{...D}}})),o.sequenceExecute(I,e).result?(n.pushUndoRedo({redoMutations:I,undoMutations:v,unitID:u}),!0):!1}},me={type:o.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(i,t){var u,p;if(!t)return!1;const{id:e,documentId:n}=t,r=i.get(o.ICommandService),a=i.get(o.IUniverInstanceService).getUnit(n,o.UniverInstanceType.UNIVER_DOC),d=(p=(u=a==null?void 0:a.getBody())==null?void 0:u.customRanges)==null?void 0:p.find(m=>m.rangeId===e);let c=null;d&&d.endIndex===a.getBody().dataStream.length-3&&(c={dataStream:" "});const l=Z.deleteCustomRangeFactory(i,{unitId:n,rangeId:e,insert:c});return l?r.syncExecuteCommand(l.id,l.params):!1}},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:u,id:p}=t,{workbook:m,worksheet:f,unitId:h,subUnitId:_}=d,{payload:y,display:S=""}=c,M=f.getCell(l,u);if(!M)return!1;const I=f.getCellDocumentModelWithFormula(M);if(!(I!=null&&I.documentModel))return!1;const v=I.documentModel.getSnapshot(),R=(se=(ie=v.body)==null?void 0:ie.customRanges)==null?void 0:se.find(Ie=>`${Ie.rangeId}`===p);if(!R)return!1;const k=o.generateRandomId(),P=(ae=o.getBodySlice(I.documentModel.getBody(),R.startIndex,R.endIndex+1).textRuns)==null?void 0:ae[0];P&&(P.ed=S.length+1);const b=Z.replaceSelectionFactory(i,{unitId:h,body:{dataStream:`${S}`,customRanges:[{rangeId:k,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:S.length-1,properties:{url:y}}],textRuns:P?[P]:void 0},selection:{startOffset:R.startIndex,endOffset:R.endIndex+1,collapsed:!1},doc:I.documentModel});if(!b)return!1;const T=o.TextX.apply(o.Tools.deepClone(v.body),b.textX.serialize()),H={p:{...v,body:T},t:o.CellValueType.STRING},Q=await a.onWriteCell(m,f,l,u,H),$={id:g.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:_,cellValue:{[l]:{[u]:Q}}}},ee=g.SetRangeValuesUndoMutationFactory(i,$.params),V={id:g.SetRangeValuesMutation.id,params:ee},N=[$],O=[V],j=s.getHyperLinkByLocation(h,_,l,u);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,S;if(!t)return!1;const{documentId:e,payload:n,id:r}=t,s=i.get(o.IUniverInstanceService),a=i.get(o.ICommandService),d=s.getUnit(e,o.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(_=(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:"",u=o.generateRandomId(),m=(S=o.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:S[0];m&&(m.ed=l.length+1);const f=Z.replaceSelectionFactory(i,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:u,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:m?[m]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return f?a.syncExecuteCommand(f.id,f.params):!1}};var 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,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 u;const{gid:e,range:n,rangeid:r,unitid:s}=t,a=s?this._univerInstanceService.getUnit(s,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),d={type:L.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!a)return d;const c=e?a.getSheetBySheetId(e):a.getActiveSheet(),l=(u=c==null?void 0:c.getName())!=null?u:"";if(n){if(!c)return d;const p=U.deserializeRangeWithSheet(n).range;return o.isValidRange(p,c)&&n!==x?{type:L.RANGE,name:U.serializeRangeWithSheet(l,p)}:d}if(r){const p=this._definedNamesService.getValueById(a.getUnitId(),r);return p?{type:L.DEFINE_NAME,name:p.formulaOrRefString}:d}if(e){const p=a.getSheetBySheetId(e);return p?{type:L.SHEET,name:p.getName()}:d}return d}};exports.SheetsHyperLinkParserService=Je([re(0,o.IUniverInstanceService),re(1,o.Inject(o.LocaleService)),re(2,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),Se=(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]])}};Se(exports.UniverSheetsHyperLinkPlugin,"pluginName",le);Se(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=pe;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;
|
|
1
|
+
"use strict";var __defProp=Object.defineProperty;var __defNormalProp=(obj,key,value)=>key in obj?__defProp(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value;var __name=(target,value)=>__defProp(target,"name",{value,configurable:!0});var __publicField=(obj,key,value)=>__defNormalProp(obj,typeof key!="symbol"?key+"":key,value);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const core=require("@univerjs/core"),rxjs=require("rxjs"),sheets=require("@univerjs/sheets"),engineFormula=require("@univerjs/engine-formula"),docs=require("@univerjs/docs");var __defProp$8=Object.defineProperty,__getOwnPropDesc$8=Object.getOwnPropertyDescriptor,__decorateClass$8=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$8(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$8(target,key,result),result},"__decorateClass$8"),__decorateParam$8=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$8"),_a;exports.HyperLinkModel=(_a=class extends core.Disposable{constructor(_univerInstanceService){super();__publicField(this,"_linkUpdate$",new rxjs.Subject);__publicField(this,"linkUpdate$",this._linkUpdate$.asObservable());__publicField(this,"_linkMap",new Map);__publicField(this,"_linkPositionMap",new Map);this._univerInstanceService=_univerInstanceService,this.disposeWithMe({dispose:__name(()=>{this._linkUpdate$.complete()},"dispose")})}_ensureMap(unitId,subUnitId){let unitMap=this._linkMap.get(unitId);unitMap||(unitMap=new Map,this._linkMap.set(unitId,unitMap));let matrix=unitMap.get(subUnitId);matrix||(matrix=new core.ObjectMatrix,unitMap.set(subUnitId,matrix));let positionUnitMap=this._linkPositionMap.get(unitId);positionUnitMap||(positionUnitMap=new Map,this._linkPositionMap.set(unitId,positionUnitMap));let positionSubUnitMap=positionUnitMap.get(subUnitId);return positionSubUnitMap||(positionSubUnitMap=new Map,positionUnitMap.set(subUnitId,positionSubUnitMap)),{matrix,positionMap:positionSubUnitMap}}addHyperLink(unitId,subUnitId,link){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId);return matrix.setValue(link.row,link.column,link),positionMap.set(link.id,{row:link.row,column:link.column,link}),this._linkUpdate$.next({unitId,subUnitId,payload:link,type:"add"}),!0}updateHyperLink(unitId,subUnitId,id,payload,silent=!1){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(!position)return!0;const link=matrix.getValue(position.row,position.column);return link&&(Object.assign(link,payload),this._linkUpdate$.next({unitId,subUnitId,payload:{display:link.display,payload:link.payload},id,type:"update",silent})),!0}updateHyperLinkRef(unitId,subUnitId,id,payload,silent=!1){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(!position)return!0;let link=matrix.getValue(position.row,position.column);return!link||link.id!==id?link=position.link:matrix.realDeleteValue(position.row,position.column),Object.assign(link,payload),positionMap.set(id,{...payload,link}),matrix.setValue(payload.row,payload.column,link),this._linkUpdate$.next({unitId,subUnitId,payload,id,type:"updateRef",silent}),!0}removeHyperLink(unitId,subUnitId,id){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(!position)return!1;positionMap.delete(id);const link=matrix.getValue(position.row,position.column);return link&&link.id===id&&matrix.realDeleteValue(position.row,position.column),this._linkUpdate$.next({unitId,subUnitId,payload:position.link,type:"remove"}),!0}getHyperLink(unitId,subUnitId,id){const{matrix,positionMap}=this._ensureMap(unitId,subUnitId),position=positionMap.get(id);if(position)return matrix.getValue(position.row,position.column)}getHyperLinkByLocation(unitId,subUnitId,row,column){const{matrix}=this._ensureMap(unitId,subUnitId);return matrix.getValue(row,column)}getHyperLinkByLocationSync(unitId,subUnitId,row,column){var _a10,_b,_c,_d,_e;const{matrix}=this._ensureMap(unitId,subUnitId),workbook=this._univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_SHEET),cell=(_a10=workbook==null?void 0:workbook.getSheetBySheetId(subUnitId))==null?void 0:_a10.getCellRaw(row,column),cellValueStr=((_e=(_d=cell==null?void 0:cell.v)!=null?_d:(_c=(_b=cell==null?void 0:cell.p)==null?void 0:_b.body)==null?void 0:_c.dataStream.slice(0,-2))!=null?_e:"").toString(),link=matrix.getValue(row,column);if(link)return{...link,display:cellValueStr}}getSubUnit(unitId,subUnitId){const{matrix}=this._ensureMap(unitId,subUnitId),links=[];return matrix.forValue((row,col,value)=>{value&&links.push(value)}),links}getUnit(unitId){const unitMap=this._linkMap.get(unitId);return unitMap?Array.from(unitMap.keys()).map(subUnitId=>{const links=this.getSubUnit(unitId,subUnitId);return{unitId,subUnitId,links}}):[]}deleteUnit(unitId){const links=this.getUnit(unitId);this._linkMap.delete(unitId),this._linkPositionMap.delete(unitId),this._linkUpdate$.next({type:"unload",unitId,unitLinks:links})}getAll(){return Array.from(this._linkMap.keys()).map(unitId=>this.getUnit(unitId))}},__name(_a,"HyperLinkModel"),_a);exports.HyperLinkModel=__decorateClass$8([__decorateParam$8(0,core.IUniverInstanceService)],exports.HyperLinkModel);var SheetHyperLinkType=(SheetHyperLinkType2=>(SheetHyperLinkType2.SHEET="gid",SheetHyperLinkType2.RANGE="range",SheetHyperLinkType2.DEFINE_NAME="rangeid",SheetHyperLinkType2.INVALID="invalid",SheetHyperLinkType2.URL="url",SheetHyperLinkType2))(SheetHyperLinkType||{});const SHEETS_HYPER_LINK_PLUGIN_CONFIG_KEY="sheets-hyper-link.config",defaultPluginConfig={},AddHyperLinkMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports.HyperLinkModel),{unitId,subUnitId,link}=params;return model.addHyperLink(unitId,subUnitId,link)}},RemoveHyperLinkMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports.HyperLinkModel),{unitId,subUnitId,id}=params;return model.removeHyperLink(unitId,subUnitId,id)}},UpdateHyperLinkMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports.HyperLinkModel),{unitId,subUnitId,payload,id}=params;return model.updateHyperLink(unitId,subUnitId,id,payload,!1)}},UpdateHyperLinkRefMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(accessor,params){if(!params)return!1;const model=accessor.get(exports.HyperLinkModel),{unitId,subUnitId,id,row,column,silent}=params;return model.updateHyperLinkRef(unitId,subUnitId,id,{row,column},silent)}},UpdateRichHyperLinkMutation={type:core.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(accessor,params){var _a10,_b,_c;if(!params)return!1;const{unitId,subUnitId,row,col,id,url}=params,univerInstanceService=accessor.get(core.IUniverInstanceService),sheetTarget=sheets.getSheetCommandTarget(univerInstanceService,{unitId,subUnitId});if(!sheetTarget)return!1;const{worksheet}=sheetTarget,cell=worksheet.getCellRaw(row,col),link=(_c=(_b=(_a10=cell==null?void 0:cell.p)==null?void 0:_a10.body)==null?void 0:_b.customRanges)==null?void 0:_c.find(range=>range.rangeType===core.CustomRangeType.HYPERLINK&&range.rangeId===id);return link&&(link.properties.url=url),!0}},SHEET_HYPER_LINK_PLUGIN="SHEET_HYPER_LINK_PLUGIN",ERROR_RANGE="err";var __defProp$7=Object.defineProperty,__getOwnPropDesc$7=Object.getOwnPropertyDescriptor,__decorateClass$7=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$7(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$7(target,key,result),result},"__decorateClass$7"),__decorateParam$7=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$7"),_a2;let SheetsHyperLinkRefRangeController=(_a2=class extends core.Disposable{constructor(_refRangeService,_hyperLinkModel,_selectionManagerService,_commandService){super();__publicField(this,"_disposableMap",new Map);__publicField(this,"_watchDisposableMap",new Map);__publicField(this,"_rangeDisableMap",new Map);__publicField(this,"_rangeWatcherMap",new Map);__publicField(this,"_handlePositionChange",__name((unitId,subUnitId,link,resultRange,silent)=>{const oldRange={startColumn:link.column,endColumn:link.column,startRow:link.row,endRow:link.row};return resultRange?{redos:[{id:UpdateHyperLinkRefMutation.id,params:{unitId,subUnitId,id:link.id,row:resultRange.startRow,column:resultRange.startColumn,silent}}],undos:[{id:UpdateHyperLinkRefMutation.id,params:{unitId,subUnitId,id:link.id,row:oldRange.startRow,column:oldRange.startColumn,silent}}]}:{redos:[{id:RemoveHyperLinkMutation.id,params:{unitId,subUnitId,id:link.id}}],undos:[{id:AddHyperLinkMutation.id,params:{unitId,subUnitId,link}}]}},"_handlePositionChange"));this._refRangeService=_refRangeService,this._hyperLinkModel=_hyperLinkModel,this._selectionManagerService=_selectionManagerService,this._commandService=_commandService,this._initData(),this._initRefRange()}_registerPosition(unitId,subUnitId,link){const id=link.id,oldRange={startColumn:link.column,endColumn:link.column,startRow:link.row,endRow:link.row},handleRefRangeChange=__name(commandInfo=>{const resultRanges=sheets.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(oldRange,commandInfo,{selectionManagerService:this._selectionManagerService}),resultRange=Array.isArray(resultRanges)?resultRanges[0]:resultRanges;return resultRange&&resultRange.startColumn===oldRange.startColumn&&resultRange.startRow===oldRange.startRow?{undos:[],redos:[]}:this._handlePositionChange(unitId,subUnitId,link,resultRange,!1)},"handleRefRangeChange");this._disposableMap.set(id,this._refRangeService.registerRefRange(oldRange,handleRefRangeChange,unitId,subUnitId))}_watchPosition(unitId,subUnitId,link){const id=link.id,oldRange={startColumn:link.column,endColumn:link.column,startRow:link.row,endRow:link.row};this._watchDisposableMap.set(id,this._refRangeService.watchRange(unitId,subUnitId,oldRange,(before,after)=>{const{redos}=this._handlePositionChange(unitId,subUnitId,link,after,!0);core.sequenceExecuteAsync(redos,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(id){const disposable=this._disposableMap.get(id);disposable==null||disposable.dispose(),this._disposableMap.delete(id)}_unwatchPosition(id){const disposable=this._watchDisposableMap.get(id);disposable==null||disposable.dispose(),this._watchDisposableMap.delete(id)}_registerRange(unitId,id,payload,silent=!1){var _a10,_b,_c;if(payload.startsWith("#")){const search=new URLSearchParams(payload.slice(1)),searchObj={gid:(_a10=search.get("gid"))!=null?_a10:"",range:(_b=search.get("range"))!=null?_b:"",rangeid:(_c=search.get("rangeid"))!=null?_c:""};if(searchObj.range&&searchObj.gid){const subUnitId=searchObj.gid,range=engineFormula.deserializeRangeWithSheet(searchObj.range).range;if(core.isValidRange(range)&&searchObj.range!==ERROR_RANGE){const handleRangeChange=__name(commandInfo=>{const resultRange=sheets.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(range,commandInfo,{selectionManagerService:this._selectionManagerService});return resultRange&&engineFormula.serializeRange(resultRange)===engineFormula.serializeRange(range)?{redos:[],undos:[]}:{redos:[{id:UpdateHyperLinkMutation.id,params:{unitId,subUnitId,id,payload:{payload:`#gid=${subUnitId}&range=${resultRange?engineFormula.serializeRange(resultRange):"err"}`}}}],undos:[{id:UpdateHyperLinkMutation.id,params:{unitId,subUnitId,id,payload:{payload}}}]}},"handleRangeChange");this._rangeDisableMap.set(id,this._refRangeService.registerRefRange(range,handleRangeChange,unitId,subUnitId)),silent||this._rangeWatcherMap.set(id,this._refRangeService.watchRange(unitId,subUnitId,range,(before,after)=>{this._hyperLinkModel.updateHyperLink(unitId,subUnitId,id,{payload:`#gid=${subUnitId}&range=${after?engineFormula.serializeRange(after):"err"}`},!0)},!0))}}}}_unregisterRange(id){const disposable=this._rangeDisableMap.get(id);disposable==null||disposable.dispose(),this._rangeDisableMap.delete(id)}_unwatchRange(id){const disposable=this._rangeWatcherMap.get(id);disposable==null||disposable.dispose(),this._rangeWatcherMap.delete(id)}_initData(){this._hyperLinkModel.getAll().forEach(unitData=>{unitData.forEach(subUnitData=>{const{unitId,subUnitId,links}=subUnitData;links.forEach(link=>{this._registerPosition(unitId,subUnitId,link),this._watchPosition(unitId,subUnitId,link),this._registerRange(unitId,link.id,link.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(option=>{switch(option.type){case"add":{this._registerPosition(option.unitId,option.subUnitId,option.payload),this._watchPosition(option.unitId,option.subUnitId,option.payload),this._registerRange(option.unitId,option.payload.id,option.payload.payload);break}case"remove":{this._unregisterPosition(option.payload.id),this._unwatchPosition(option.payload.id),this._unregisterRange(option.payload.id),this._unwatchRange(option.payload.id);break}case"updateRef":{const{unitId,subUnitId,id,silent}=option,link=this._hyperLinkModel.getHyperLink(unitId,subUnitId,id);if(!link)return;this._unregisterPosition(id),this._registerPosition(unitId,subUnitId,link),silent||(this._unwatchPosition(id),this._watchPosition(unitId,subUnitId,link));break}case"unload":{const{unitLinks}=option;unitLinks.forEach(subUnitData=>{const{links}=subUnitData;links.forEach(link=>{this._unregisterPosition(link.id),this._unwatchPosition(link.id),this._unregisterRange(link.id),this._unwatchRange(link.id)})});break}case"update":{option.silent||this._unwatchRange(option.id),this._unregisterRange(option.id),this._registerRange(option.unitId,option.id,option.payload.payload,option.silent);break}}})),this.disposeWithMe(core.toDisposable(()=>{this._disposableMap.forEach(item=>{item.dispose()}),this._disposableMap.clear()}))}},__name(_a2,"SheetsHyperLinkRefRangeController"),_a2);SheetsHyperLinkRefRangeController=__decorateClass$7([__decorateParam$7(0,core.Inject(sheets.RefRangeService)),__decorateParam$7(1,core.Inject(exports.HyperLinkModel)),__decorateParam$7(2,core.Inject(sheets.SheetsSelectionsService)),__decorateParam$7(3,core.ICommandService)],SheetsHyperLinkRefRangeController);var __defProp$6=Object.defineProperty,__getOwnPropDesc$6=Object.getOwnPropertyDescriptor,__decorateClass$6=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$6(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$6(target,key,result),result},"__decorateClass$6"),__decorateParam$6=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$6"),_a3;let SheetsHyperLinkRemoveSheetController=(_a3=class extends core.Disposable{constructor(_sheetInterceptorService,_univerInstanceService,_hyperLinkModel){super(),this._sheetInterceptorService=_sheetInterceptorService,this._univerInstanceService=_univerInstanceService,this._hyperLinkModel=_hyperLinkModel,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:__name(commandInfo=>{var _a10;if(commandInfo.id===sheets.RemoveSheetCommand.id){const params=commandInfo.params,workbook=params.unitId?this._univerInstanceService.getUnit(params.unitId):this._univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_SHEET);if(!workbook)return{redos:[],undos:[]};const unitId=workbook.getUnitId(),subUnitId=params.subUnitId||((_a10=workbook.getActiveSheet())==null?void 0:_a10.getSheetId());if(!subUnitId)return{redos:[],undos:[]};const links=this._hyperLinkModel.getSubUnit(unitId,subUnitId),redos=links.map(link=>({id:RemoveHyperLinkMutation.id,params:{unitId,subUnitId,id:link.id}})),undos=links.map(link=>({id:AddHyperLinkMutation.id,params:{unitId,subUnitId,link}}));return{redos,undos}}return{redos:[],undos:[]}},"getMutations")}))}},__name(_a3,"SheetsHyperLinkRemoveSheetController"),_a3);SheetsHyperLinkRemoveSheetController=__decorateClass$6([__decorateParam$6(0,core.Inject(sheets.SheetInterceptorService)),__decorateParam$6(1,core.IUniverInstanceService),__decorateParam$6(2,core.Inject(exports.HyperLinkModel))],SheetsHyperLinkRemoveSheetController);var __defProp$5=Object.defineProperty,__getOwnPropDesc$5=Object.getOwnPropertyDescriptor,__decorateClass$5=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$5(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$5(target,key,result),result},"__decorateClass$5"),__decorateParam$5=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$5"),_a4;let SheetsHyperLinkRichTextRefRangeController=(_a4=class extends core.Disposable{constructor(_commandService,_univerInstanceService,_refRangeService){super();__publicField(this,"_refRangeMap",new Map);this._commandService=_commandService,this._univerInstanceService=_univerInstanceService,this._refRangeService=_refRangeService,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(unitId,subUnitId){let unitMap=this._refRangeMap.get(unitId);unitMap||(unitMap=new Map,this._refRangeMap.set(unitId,unitMap));let subUnitMap=unitMap.get(subUnitId);return subUnitMap||(subUnitMap=new core.ObjectMatrix,unitMap.set(subUnitId,subUnitMap)),subUnitMap}_isLegalRangeUrl(unitId,payload){var _a10,_b,_c;const workbook=this._univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_SHEET);if(!workbook)return null;if(payload&&payload.startsWith("#")){const search=new URLSearchParams(payload.slice(1)),searchObj={gid:(_a10=search.get("gid"))!=null?_a10:"",range:(_b=search.get("range"))!=null?_b:"",rangeid:(_c=search.get("rangeid"))!=null?_c:""};if(searchObj.range&&searchObj.gid){const subUnitId=searchObj.gid,worksheet=workbook.getSheetBySheetId(subUnitId);if(!worksheet)return null;const range=engineFormula.deserializeRangeWithSheet(searchObj.range).range;if(core.isValidRange(range,worksheet)&&searchObj.range!==ERROR_RANGE)return{range,worksheet}}}return null}_registerRange(unitId,subUnitId,row,col,p){var _a10,_b,_c,_d;const map=this._enusreMap(unitId,subUnitId);if((_b=(_a10=p.body)==null?void 0:_a10.customRanges)!=null&&_b.some(customRange=>{var _a11;return customRange.rangeType===core.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(unitId,(_a11=customRange.properties)==null?void 0:_a11.url)})){const disposableCollection=new core.DisposableCollection;let hasWatch=!1;(_d=(_c=p.body)==null?void 0:_c.customRanges)==null||_d.forEach(customRange=>{var _a11;if(customRange.rangeType===core.CustomRangeType.HYPERLINK){const payload=(_a11=customRange.properties)==null?void 0:_a11.url,rangeInfo=this._isLegalRangeUrl(unitId,payload);if(rangeInfo){const{range,worksheet}=rangeInfo;hasWatch=!0,disposableCollection.add(this._refRangeService.registerRefRange(range,commandInfo=>{const newRange=sheets.handleDefaultRangeChangeWithEffectRefCommands(range,commandInfo);return newRange&&core.Rectangle.equals(newRange,range)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:UpdateRichHyperLinkMutation.id,params:{unitId,subUnitId,row,col,id:customRange.rangeId,url:`#gid=${subUnitId}&range=${newRange?engineFormula.serializeRange(newRange):ERROR_RANGE}`}}],undos:[{id:UpdateRichHyperLinkMutation.id,params:{unitId,subUnitId,row,col,id:customRange.rangeId,url:payload}}],redos:[]}},worksheet.getUnitId(),worksheet.getSheetId()))}}}),hasWatch&&map.setValue(row,col,disposableCollection)}}_initWorkbookLoad(){const handleWorkbook=__name(workbook=>{const unitId=workbook.getUnitId();workbook.getSheets().forEach(sheet=>{const subUnitId=sheet.getSheetId(),map=this._enusreMap(unitId,subUnitId);sheet.getCellMatrix().forValue((row,col,cell)=>{const dispose=map.getValue(row,col);dispose&&dispose.dispose(),cell&&cell.p&&this._registerRange(unitId,subUnitId,row,col,cell.p)})})},"handleWorkbook");this._univerInstanceService.getAllUnitsForType(core.UniverInstanceType.UNIVER_SHEET).forEach(workbook=>{handleWorkbook(workbook)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(unit=>{unit.type===core.UniverInstanceType.UNIVER_SHEET&&handleWorkbook(unit)}))}_initWorkbookUnload(){this._univerInstanceService.unitDisposed$.subscribe(unit=>{if(unit.type===core.UniverInstanceType.UNIVER_SHEET){const workbook=unit,unitId=workbook.getUnitId();workbook.getSheets().forEach(sheet=>{const subUnitId=sheet.getSheetId();this._enusreMap(unitId,subUnitId).forValue((row,col,dispose)=>{dispose&&dispose.dispose()})}),this._refRangeMap.delete(unitId)}})}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(commandInfo=>{if(commandInfo.id===sheets.SetRangeValuesMutation.id){const params=commandInfo.params,{unitId,subUnitId,cellValue}=params,map=this._enusreMap(unitId,subUnitId);cellValue&&new core.ObjectMatrix(cellValue).forValue((row,col,cell)=>{const dispose=map.getValue(row,col);dispose&&dispose.dispose(),cell&&cell.p&&this._registerRange(unitId,subUnitId,row,col,cell.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(commandInfo=>{if(commandInfo.id===UpdateRichHyperLinkMutation.id){const params=commandInfo.params,{unitId,subUnitId,row,col}=params,sheetTarget=sheets.getSheetCommandTarget(this._univerInstanceService,{unitId,subUnitId}),dispose=this._enusreMap(unitId,subUnitId).getValue(row,col);if(dispose&&dispose.dispose(),sheetTarget){const{worksheet}=sheetTarget,cell=worksheet.getCellRaw(row,col);cell&&cell.p&&this._registerRange(unitId,subUnitId,row,col,cell.p)}}}))}},__name(_a4,"SheetsHyperLinkRichTextRefRangeController"),_a4);SheetsHyperLinkRichTextRefRangeController=__decorateClass$5([__decorateParam$5(0,core.ICommandService),__decorateParam$5(1,core.IUniverInstanceService),__decorateParam$5(2,core.Inject(sheets.RefRangeService))],SheetsHyperLinkRichTextRefRangeController);var __defProp$4=Object.defineProperty,__getOwnPropDesc$4=Object.getOwnPropertyDescriptor,__decorateClass$4=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$4(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$4(target,key,result),result},"__decorateClass$4"),__decorateParam$4=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$4"),_a5;let SheetHyperLinkSetRangeController=(_a5=class extends core.Disposable{constructor(_sheetInterceptorService,_hyperLinkModel,_selectionManagerService,_univerInstanceService){super(),this._sheetInterceptorService=_sheetInterceptorService,this._hyperLinkModel=_hyperLinkModel,this._selectionManagerService=_selectionManagerService,this._univerInstanceService=_univerInstanceService,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:__name(command=>{if(command.id===sheets.SetRangeValuesCommand.id){const params=command.params,{unitId,subUnitId}=params,redos=[],undos=[];return params.cellValue&&new core.ObjectMatrix(params.cellValue).forValue((row,col)=>{const link=this._hyperLinkModel.getHyperLinkByLocation(unitId,subUnitId,row,col);link&&(redos.push({id:RemoveHyperLinkMutation.id,params:{unitId,subUnitId,id:link.id}}),undos.push({id:AddHyperLinkMutation.id,params:{unitId,subUnitId,link}}))}),{undos,redos}}return{redos:[],undos:[]}},"getMutations")}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:__name(command=>{if(command.id===sheets.ClearSelectionContentCommand.id||command.id===sheets.ClearSelectionAllCommand.id||command.id===sheets.ClearSelectionFormatCommand.id){const redos=[],undos=[],selection=this._selectionManagerService.getCurrentLastSelection(),target=sheets.getSheetCommandTarget(this._univerInstanceService);if(selection&&target){const{unitId,subUnitId}=target;core.Range.foreach(selection.range,(row,col)=>{const link=this._hyperLinkModel.getHyperLinkByLocation(unitId,subUnitId,row,col);link&&(redos.push({id:RemoveHyperLinkMutation.id,params:{unitId,subUnitId,id:link.id}}),undos.push({id:AddHyperLinkMutation.id,params:{unitId,subUnitId,link}}))})}return{redos,undos}}return{redos:[],undos:[]}},"getMutations")}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(sheets.AFTER_CELL_EDIT,{handler:__name((cell,context,next)=>{if(!cell||cell.p)return next(cell);if(typeof cell.v=="string"&&core.Tools.isLegalUrl(cell.v)&&cell.v[cell.v.length-1]!==" "){const{unitId,subUnitId}=context,workbook=this._univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_SHEET),worksheet=workbook==null?void 0:workbook.getSheetBySheetId(subUnitId);if(!worksheet)return next(cell);const doc=worksheet.getBlankCellDocumentModel(cell);if(!doc.documentModel)return next(cell);const textX=core.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:cell.v.length,collapsed:!1},body:{dataStream:`${cell.v}`,customRanges:[{startIndex:0,endIndex:cell.v.length-1,rangeId:core.generateRandomId(),rangeType:core.CustomRangeType.HYPERLINK,properties:{url:cell.v}}]},doc:doc.documentModel});if(!textX)return next(cell);const body=doc.documentModel.getBody();return core.TextX.apply(body,textX.serialize()),next({...cell,p:{id:core.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return next(cell)},"handler")}))}},__name(_a5,"SheetHyperLinkSetRangeController"),_a5);SheetHyperLinkSetRangeController=__decorateClass$4([__decorateParam$4(0,core.Inject(sheets.SheetInterceptorService)),__decorateParam$4(1,core.Inject(exports.HyperLinkModel)),__decorateParam$4(2,core.Inject(sheets.SheetsSelectionsService)),__decorateParam$4(3,core.IUniverInstanceService)],SheetHyperLinkSetRangeController);var _=(E=>(E[E.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",E[E.UNIVER_DOC=1]="UNIVER_DOC",E[E.UNIVER_SHEET=2]="UNIVER_SHEET",E[E.UNIVER_SLIDE=3]="UNIVER_SLIDE",E[E.UNIVER_PROJECT=4]="UNIVER_PROJECT",E[E.UNRECOGNIZED=-1]="UNRECOGNIZED",E))(_||{}),__defProp$3=Object.defineProperty,__getOwnPropDesc$3=Object.getOwnPropertyDescriptor,__decorateClass$3=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$3(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$3(target,key,result),result},"__decorateClass$3"),__decorateParam$3=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$3"),_a6;let SheetsHyperLinkResourceController=(_a6=class extends core.Disposable{constructor(_resourceManagerService,_hyperLinkModel){super(),this._resourceManagerService=_resourceManagerService,this._hyperLinkModel=_hyperLinkModel,this._initSnapshot()}_initSnapshot(){const toJson=__name(unitID=>{const map=this._hyperLinkModel.getUnit(unitID),resultMap={};return map?(map.forEach(info=>{resultMap[info.subUnitId]=info.links.map(({display,...link})=>link)}),JSON.stringify(resultMap)):""},"toJson"),parseJson=__name(json=>{if(!json)return{};try{return JSON.parse(json)}catch{return{}}},"parseJson");this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:SHEET_HYPER_LINK_PLUGIN,businesses:[_.UNIVER_SHEET],toJson:__name(unitID=>toJson(unitID),"toJson"),parseJson:__name(json=>parseJson(json),"parseJson"),onUnLoad:__name(unitID=>{this._hyperLinkModel.deleteUnit(unitID)},"onUnLoad"),onLoad:__name(async(unitID,value)=>{Object.keys(value).forEach(subunitId=>{value[subunitId].forEach(link=>{this._hyperLinkModel.addHyperLink(unitID,subunitId,link)})})},"onLoad")}))}},__name(_a6,"SheetsHyperLinkResourceController"),_a6);SheetsHyperLinkResourceController=__decorateClass$3([__decorateParam$3(0,core.IResourceManagerService),__decorateParam$3(1,core.Inject(exports.HyperLinkModel))],SheetsHyperLinkResourceController);const AddHyperLinkCommand={type:core.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(accessor,params){if(!params)return!1;const commandService=accessor.get(core.ICommandService),undoRedoService=accessor.get(core.IUndoRedoService),univerInstanceService=accessor.get(core.IUniverInstanceService),hyperLinkModel=accessor.get(exports.HyperLinkModel),sheetInterceptorService=accessor.get(sheets.SheetInterceptorService),target=sheets.getSheetCommandTarget(univerInstanceService,params);if(!target)return!1;const{unitId,subUnitId,workbook,worksheet}=target,{link}=params,{payload,display,row,column,id}=link,cellData=worksheet.getCell(row,column),doc=worksheet.getBlankCellDocumentModel(cellData),snapshot=doc.documentModel.getSnapshot(),body=core.Tools.deepClone(snapshot.body);if(!body)return!1;let textX;if(display?textX=core.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:body.dataStream.length-2,collapsed:body.dataStream.length-2===0},body:{dataStream:`${display}`,customRanges:[{startIndex:0,endIndex:display.length-1,rangeType:core.CustomRangeType.HYPERLINK,rangeId:id,properties:{url:payload}}]},doc:doc.documentModel}):textX=core.BuildTextUtils.customRange.add({body,ranges:[{startOffset:0,endOffset:body.dataStream.length-2,collapsed:!1}],rangeId:id,rangeType:core.CustomRangeType.HYPERLINK,properties:{url:payload,refId:id}}),!textX)return!1;const newBody=core.TextX.apply(body,textX.serialize()),newCellData={p:{...snapshot,body:newBody},t:core.CellValueType.STRING},finalCellData=await sheetInterceptorService.onWriteCell(workbook,worksheet,row,column,newCellData),redoParams={unitId,subUnitId,cellValue:{[link.row]:{[link.column]:finalCellData}}},redo={id:sheets.SetRangeValuesMutation.id,params:redoParams},undoParams=sheets.SetRangeValuesUndoMutationFactory(accessor,redoParams),undo={id:sheets.SetRangeValuesMutation.id,params:undoParams},redos=[redo],undos=[undo],modelLink=hyperLinkModel.getHyperLinkByLocation(unitId,subUnitId,row,column);return modelLink&&(redos.push({id:RemoveHyperLinkMutation.id,params:{unitId,subUnitId,id:modelLink.id}}),undos.push({id:AddHyperLinkMutation.id,params:{unitId,subUnitId,link:modelLink}})),await core.sequenceExecuteAsync(redos,commandService)?(undoRedoService.pushUndoRedo({redoMutations:redos,undoMutations:undos,unitID:unitId}),!0):!1}},AddRichHyperLinkCommand={id:"sheets.command.add-rich-hyper-link",type:core.CommandType.COMMAND,handler:__name(async(accessor,params)=>{if(!params)return!1;const{documentId,link}=params,commandService=accessor.get(core.ICommandService),newId=core.generateRandomId(),{payload}=link,replaceSelection=docs.addCustomRangeBySelectionFactory(accessor,{unitId:documentId,rangeId:newId,rangeType:core.CustomRangeType.HYPERLINK,properties:{url:payload,refId:newId}});return replaceSelection?commandService.syncExecuteCommand(replaceSelection.id,replaceSelection.params):!1},"handler")},CancelHyperLinkCommand={type:core.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(accessor,params){var _a10,_b;if(!params)return!1;const commandService=accessor.get(core.ICommandService),undoRedoService=accessor.get(core.IUndoRedoService),instanceSrv=accessor.get(core.IUniverInstanceService),hyperLinkModel=accessor.get(exports.HyperLinkModel),target=sheets.getSheetCommandTarget(instanceSrv,params);if(!target)return!1;const{row,column,id}=params,{unitId,subUnitId,worksheet}=target,cellData=worksheet.getCell(row,column);if(!cellData)return!1;const doc=worksheet.getCellDocumentModelWithFormula(cellData);if(!(doc!=null&&doc.documentModel))return!1;const snapshot=core.Tools.deepClone(doc.documentModel.getSnapshot()),range=(_b=(_a10=snapshot.body)==null?void 0:_a10.customRanges)==null?void 0:_b.find(range2=>`${range2.rangeId}`===id);if(!range)return!1;const textX=core.BuildTextUtils.customRange.delete({documentDataModel:doc.documentModel,rangeId:range.rangeId});if(!textX)return!1;const newBody=core.TextX.apply(snapshot.body,textX.serialize()),redos=[],undos=[],setRangeParams={unitId,subUnitId,cellValue:{[row]:{[column]:{p:{...snapshot,body:newBody},t:core.CellValueType.STRING}}}};redos.push({id:sheets.SetRangeValuesMutation.id,params:setRangeParams});const undoParams=sheets.SetRangeValuesUndoMutationFactory(accessor,setRangeParams);undos.push({id:sheets.SetRangeValuesMutation.id,params:undoParams});const link=hyperLinkModel.getHyperLinkByLocation(unitId,subUnitId,row,column);return link&&(redos.push({id:RemoveHyperLinkMutation.id,params:{unitId,subUnitId,id}}),undos.push({id:AddHyperLinkMutation.id,params:{unitId,subUnitId,link:{...link}}})),core.sequenceExecute(redos,commandService).result?(undoRedoService.pushUndoRedo({redoMutations:redos,undoMutations:undos,unitID:unitId}),!0):!1}},CancelRichHyperLinkCommand={type:core.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(accessor,params){var _a10,_b;if(!params)return!1;const{id:linkId,documentId}=params,commandService=accessor.get(core.ICommandService),doc=accessor.get(core.IUniverInstanceService).getUnit(documentId,core.UniverInstanceType.UNIVER_DOC),link=(_b=(_a10=doc==null?void 0:doc.getBody())==null?void 0:_a10.customRanges)==null?void 0:_b.find(i=>i.rangeId===linkId);let insert=null;link&&link.endIndex===doc.getBody().dataStream.length-3&&(insert={dataStream:" "});const doMutation=docs.deleteCustomRangeFactory(accessor,{unitId:documentId,rangeId:linkId,insert});return doMutation?commandService.syncExecuteCommand(doMutation.id,doMutation.params):!1}},UpdateHyperLinkCommand={type:core.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(accessor,params){var _a10,_b,_c;if(!params)return!1;const commandService=accessor.get(core.ICommandService),undoRedoService=accessor.get(core.IUndoRedoService),instanceSrv=accessor.get(core.IUniverInstanceService),hyperLinkModel=accessor.get(exports.HyperLinkModel),interceptorService=accessor.get(sheets.SheetInterceptorService),target=sheets.getSheetCommandTarget(instanceSrv,{unitId:params.unitId,subUnitId:params.subUnitId});if(!target)return!1;const{payload:link,row,column,id}=params,{workbook,worksheet,unitId,subUnitId}=target,{payload,display=""}=link,cellData=worksheet.getCell(row,column);if(!cellData)return!1;const doc=worksheet.getCellDocumentModelWithFormula(cellData);if(!(doc!=null&&doc.documentModel))return!1;const snapshot=doc.documentModel.getSnapshot(),range=(_b=(_a10=snapshot.body)==null?void 0:_a10.customRanges)==null?void 0:_b.find(range2=>`${range2.rangeId}`===id);if(!range)return!1;const newId=core.generateRandomId(),textRun=(_c=core.getBodySlice(doc.documentModel.getBody(),range.startIndex,range.endIndex+1).textRuns)==null?void 0:_c[0];textRun&&(textRun.ed=display.length+1);const replaceSelection=docs.replaceSelectionFactory(accessor,{unitId,body:{dataStream:`${display}`,customRanges:[{rangeId:newId,rangeType:core.CustomRangeType.HYPERLINK,startIndex:0,endIndex:display.length-1,properties:{url:payload}}],textRuns:textRun?[textRun]:void 0},selection:{startOffset:range.startIndex,endOffset:range.endIndex+1,collapsed:!1},doc:doc.documentModel});if(!replaceSelection)return!1;const newBody=core.TextX.apply(core.Tools.deepClone(snapshot.body),replaceSelection.textX.serialize()),newCellData={p:{...snapshot,body:newBody},t:core.CellValueType.STRING},finalCellData=await interceptorService.onWriteCell(workbook,worksheet,row,column,newCellData),redo={id:sheets.SetRangeValuesMutation.id,params:{unitId,subUnitId,cellValue:{[row]:{[column]:finalCellData}}}},undoParams=sheets.SetRangeValuesUndoMutationFactory(accessor,redo.params),undo={id:sheets.SetRangeValuesMutation.id,params:undoParams},redos=[redo],undos=[undo],modelLink=hyperLinkModel.getHyperLinkByLocation(unitId,subUnitId,row,column);return modelLink&&(redos.push({id:RemoveHyperLinkMutation.id,params:{unitId,subUnitId,id:modelLink.id}}),undos.push({id:AddHyperLinkMutation.id,params:{unitId,subUnitId,link:modelLink}})),await core.sequenceExecuteAsync(redos,commandService)?(undoRedoService.pushUndoRedo({redoMutations:redos,undoMutations:undos,unitID:unitId}),!0):!1}},UpdateRichHyperLinkCommand={type:core.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:__name((accessor,params)=>{var _a10,_b,_c,_d;if(!params)return!1;const{documentId:unitId,payload,id:rangeId}=params,univerInstanceService=accessor.get(core.IUniverInstanceService),commandService=accessor.get(core.ICommandService),doc=univerInstanceService.getUnit(unitId,core.UniverInstanceType.UNIVER_DOC);if(!doc)return!1;const range=(_b=(_a10=doc.getBody())==null?void 0:_a10.customRanges)==null?void 0:_b.find(range2=>range2.rangeId===rangeId);if(!range)return!1;const display=(_c=params.payload.display)!=null?_c:"",newId=core.generateRandomId(),textRun=(_d=core.getBodySlice(doc.getBody(),range.startIndex,range.endIndex+1).textRuns)==null?void 0:_d[0];textRun&&(textRun.ed=display.length+1);const replaceSelection=docs.replaceSelectionFactory(accessor,{unitId,body:{dataStream:`${display}`,customRanges:[{rangeId:newId,rangeType:core.CustomRangeType.HYPERLINK,startIndex:0,endIndex:display.length-1,properties:{url:payload.payload}}],textRuns:textRun?[textRun]:void 0},selection:{startOffset:range.startIndex,endOffset:range.endIndex+1,collapsed:!1},doc});return replaceSelection?commandService.syncExecuteCommand(replaceSelection.id,replaceSelection.params):!1},"handler")};var __defProp$2=Object.defineProperty,__getOwnPropDesc$2=Object.getOwnPropertyDescriptor,__decorateClass$2=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$2(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$2(target,key,result),result},"__decorateClass$2"),__decorateParam$2=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$2"),_a7;let SheetsHyperLinkController=(_a7=class extends core.Disposable{constructor(_commandService){super(),this._commandService=_commandService,this._registerCommands()}_registerCommands(){[AddHyperLinkCommand,UpdateHyperLinkCommand,CancelHyperLinkCommand,UpdateRichHyperLinkCommand,CancelRichHyperLinkCommand,AddRichHyperLinkCommand,AddHyperLinkMutation,UpdateHyperLinkMutation,RemoveHyperLinkMutation,UpdateHyperLinkRefMutation,UpdateRichHyperLinkMutation].forEach(command=>{this._commandService.registerCommand(command)})}},__name(_a7,"SheetsHyperLinkController"),_a7);SheetsHyperLinkController=__decorateClass$2([__decorateParam$2(0,core.ICommandService)],SheetsHyperLinkController);var __defProp$1=Object.defineProperty,__getOwnPropDesc$1=Object.getOwnPropertyDescriptor,__decorateClass$1=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc$1(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp$1(target,key,result),result},"__decorateClass$1"),__decorateParam$1=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam$1"),_a8;exports.SheetsHyperLinkParserService=(_a8=class{constructor(_univerInstanceService,_localeService,_definedNamesService){this._univerInstanceService=_univerInstanceService,this._localeService=_localeService,this._definedNamesService=_definedNamesService}buildHyperLink(unitId,sheetId,range){return`#${SheetHyperLinkType.SHEET}=${sheetId}${range?`&${typeof range=="string"?SheetHyperLinkType.DEFINE_NAME:SheetHyperLinkType.RANGE}=${typeof range=="string"?range:engineFormula.serializeRange(range)}`:""}`}parseHyperLink(urlStr){var _a10,_b,_c,_d;if(urlStr.startsWith("#")){const search=new URLSearchParams(urlStr.slice(1)),searchObj={gid:(_a10=search.get("gid"))!=null?_a10:"",range:(_b=search.get("range"))!=null?_b:"",rangeid:(_c=search.get("rangeid"))!=null?_c:"",unitid:(_d=search.get("unitid"))!=null?_d:""},urlInfo=this._getURLName(searchObj);return{type:urlInfo.type,name:urlInfo.name,url:urlStr,searchObj}}else return{type:SheetHyperLinkType.URL,name:urlStr,url:urlStr,searchObj:null}}_getURLName(params){var _a10;const{gid,range,rangeid,unitid}=params,workbook=unitid?this._univerInstanceService.getUnit(unitid,core.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(core.UniverInstanceType.UNIVER_SHEET),invalidLink={type:SheetHyperLinkType.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!workbook)return invalidLink;const sheet=gid?workbook.getSheetBySheetId(gid):workbook.getActiveSheet(),sheetName=(_a10=sheet==null?void 0:sheet.getName())!=null?_a10:"";if(range){if(!sheet)return invalidLink;const rangeObj=engineFormula.deserializeRangeWithSheet(range).range;return core.isValidRange(rangeObj,sheet)&&range!==ERROR_RANGE?{type:SheetHyperLinkType.RANGE,name:engineFormula.serializeRangeWithSheet(sheetName,rangeObj)}:invalidLink}if(rangeid){const range2=this._definedNamesService.getValueById(workbook.getUnitId(),rangeid);return range2?{type:SheetHyperLinkType.DEFINE_NAME,name:range2.formulaOrRefString}:invalidLink}if(gid){const worksheet=workbook.getSheetBySheetId(gid);return worksheet?{type:SheetHyperLinkType.SHEET,name:worksheet.getName()}:invalidLink}return invalidLink}},__name(_a8,"SheetsHyperLinkParserService"),_a8);exports.SheetsHyperLinkParserService=__decorateClass$1([__decorateParam$1(0,core.IUniverInstanceService),__decorateParam$1(1,core.Inject(core.LocaleService)),__decorateParam$1(2,engineFormula.IDefinedNamesService)],exports.SheetsHyperLinkParserService);var __defProp2=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__defNormalProp2=__name((obj,key,value)=>key in obj?__defProp2(obj,key,{enumerable:!0,configurable:!0,writable:!0,value}):obj[key]=value,"__defNormalProp"),__decorateClass=__name((decorators,target,key,kind)=>{for(var result=kind>1?void 0:kind?__getOwnPropDesc(target,key):target,i=decorators.length-1,decorator;i>=0;i--)(decorator=decorators[i])&&(result=(kind?decorator(target,key,result):decorator(result))||result);return kind&&result&&__defProp2(target,key,result),result},"__decorateClass"),__decorateParam=__name((index,decorator)=>(target,key)=>decorator(target,key,index),"__decorateParam"),__publicField2=__name((obj,key,value)=>__defNormalProp2(obj,typeof key!="symbol"?key+"":key,value),"__publicField"),_a9;exports.UniverSheetsHyperLinkPlugin=(_a9=class extends core.Plugin{constructor(_config=defaultPluginConfig,_injector,_configService){super(),this._config=_config,this._injector=_injector,this._configService=_configService;const{...rest}=core.merge({},defaultPluginConfig,this._config);this._configService.setConfig(SHEETS_HYPER_LINK_PLUGIN_CONFIG_KEY,rest)}onStarting(){core.registerDependencies(this._injector,[[exports.HyperLinkModel],[exports.SheetsHyperLinkParserService],[SheetsHyperLinkResourceController],[SheetsHyperLinkController],[SheetsHyperLinkRefRangeController],[SheetHyperLinkSetRangeController],[SheetsHyperLinkRemoveSheetController],[SheetsHyperLinkRichTextRefRangeController]]),core.touchDependencies(this._injector,[[SheetsHyperLinkRefRangeController],[SheetsHyperLinkResourceController],[SheetsHyperLinkController],[SheetHyperLinkSetRangeController],[SheetsHyperLinkRemoveSheetController],[SheetsHyperLinkRichTextRefRangeController]])}},__name(_a9,"UniverSheetsHyperLinkPlugin"),_a9);__publicField2(exports.UniverSheetsHyperLinkPlugin,"pluginName",SHEET_HYPER_LINK_PLUGIN);__publicField2(exports.UniverSheetsHyperLinkPlugin,"type",core.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsHyperLinkPlugin=__decorateClass([core.DependentOn(sheets.UniverSheetsPlugin),__decorateParam(1,core.Inject(core.Injector)),__decorateParam(2,core.IConfigService)],exports.UniverSheetsHyperLinkPlugin);exports.AddHyperLinkCommand=AddHyperLinkCommand;exports.AddHyperLinkMutation=AddHyperLinkMutation;exports.AddRichHyperLinkCommand=AddRichHyperLinkCommand;exports.CancelHyperLinkCommand=CancelHyperLinkCommand;exports.CancelRichHyperLinkCommand=CancelRichHyperLinkCommand;exports.ERROR_RANGE=ERROR_RANGE;exports.RemoveHyperLinkMutation=RemoveHyperLinkMutation;exports.SheetHyperLinkType=SheetHyperLinkType;exports.UpdateHyperLinkCommand=UpdateHyperLinkCommand;exports.UpdateHyperLinkMutation=UpdateHyperLinkMutation;exports.UpdateHyperLinkRefMutation=UpdateHyperLinkRefMutation;exports.UpdateRichHyperLinkCommand=UpdateRichHyperLinkCommand;
|
package/lib/es/facade.js
CHANGED
|
@@ -1,114 +1,180 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
|
3
|
+
import { Inject, generateRandomId, CustomRangeType, DataStreamTreeTokenType, FEventName, FUniver, ICommandService, CanceledError } from "@univerjs/core";
|
|
4
|
+
import { SheetsHyperLinkParserService, AddHyperLinkCommand, UpdateHyperLinkCommand, CancelHyperLinkCommand } from "@univerjs/sheets-hyper-link";
|
|
5
|
+
import { FWorkbook, FWorksheet, FRange } from "@univerjs/sheets/facade";
|
|
6
|
+
var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
7
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
8
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
9
|
+
return kind && result && __defProp2(target, key, result), result;
|
|
10
|
+
}, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), _a;
|
|
11
|
+
let SheetHyperLinkBuilder = (_a = class {
|
|
12
|
+
constructor(_workbook, _parserService) {
|
|
13
|
+
this._workbook = _workbook, this._parserService = _parserService;
|
|
12
14
|
}
|
|
13
|
-
getRangeUrl(
|
|
14
|
-
return this._parserService.buildHyperLink(this._workbook.getId(),
|
|
15
|
+
getRangeUrl(range) {
|
|
16
|
+
return this._parserService.buildHyperLink(this._workbook.getId(), range.getSheetId(), range.getRange()), this;
|
|
15
17
|
}
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
],
|
|
20
|
-
class
|
|
21
|
-
createSheetHyperlink(
|
|
22
|
-
return this._injector.get(
|
|
18
|
+
}, __name(_a, "SheetHyperLinkBuilder"), _a);
|
|
19
|
+
SheetHyperLinkBuilder = __decorateClass([
|
|
20
|
+
__decorateParam(1, Inject(SheetsHyperLinkParserService))
|
|
21
|
+
], SheetHyperLinkBuilder);
|
|
22
|
+
const _FWorkbookHyperLinkMixin = class _FWorkbookHyperLinkMixin extends FWorkbook {
|
|
23
|
+
createSheetHyperlink(sheetId, range) {
|
|
24
|
+
return this._injector.get(SheetsHyperLinkParserService).buildHyperLink(this.getId(), sheetId, range);
|
|
23
25
|
}
|
|
24
26
|
/**
|
|
25
27
|
* Parse the hyperlink string to get the hyperlink info.
|
|
26
28
|
* @param {string} hyperlink the hyperlink string
|
|
27
29
|
* @returns {ISheetHyperLinkInfo} the hyperlink info
|
|
28
30
|
*/
|
|
29
|
-
parseSheetHyperlink(
|
|
30
|
-
return this._injector.get(
|
|
31
|
+
parseSheetHyperlink(hyperlink) {
|
|
32
|
+
return this._injector.get(SheetsHyperLinkParserService).parseHyperLink(hyperlink);
|
|
31
33
|
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
};
|
|
35
|
+
__name(_FWorkbookHyperLinkMixin, "FWorkbookHyperLinkMixin");
|
|
36
|
+
let FWorkbookHyperLinkMixin = _FWorkbookHyperLinkMixin;
|
|
37
|
+
FWorkbook.extend(FWorkbookHyperLinkMixin);
|
|
38
|
+
const _FWorksheetHyperlinkMixin = class _FWorksheetHyperlinkMixin extends FWorksheet {
|
|
35
39
|
getUrl() {
|
|
36
|
-
return this._injector.get(
|
|
40
|
+
return this._injector.get(SheetsHyperLinkParserService).buildHyperLink(this._workbook.getUnitId(), this._worksheet.getSheetId());
|
|
37
41
|
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
};
|
|
43
|
+
__name(_FWorksheetHyperlinkMixin, "FWorksheetHyperlinkMixin");
|
|
44
|
+
let FWorksheetHyperlinkMixin = _FWorksheetHyperlinkMixin;
|
|
45
|
+
FWorksheet.extend(FWorksheetHyperlinkMixin);
|
|
46
|
+
const _FRangeHyperlinkMixin = class _FRangeHyperlinkMixin extends FRange {
|
|
41
47
|
// #region hyperlink
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
*/
|
|
45
|
-
setHyperLink(e, t) {
|
|
46
|
-
const r = {
|
|
48
|
+
setHyperLink(url, label) {
|
|
49
|
+
const params = {
|
|
47
50
|
unitId: this.getUnitId(),
|
|
48
51
|
subUnitId: this._worksheet.getSheetId(),
|
|
49
52
|
link: {
|
|
50
53
|
row: this._range.startRow,
|
|
51
54
|
column: this._range.startColumn,
|
|
52
|
-
payload:
|
|
53
|
-
display:
|
|
54
|
-
id:
|
|
55
|
+
payload: url,
|
|
56
|
+
display: label,
|
|
57
|
+
id: generateRandomId()
|
|
55
58
|
}
|
|
56
59
|
};
|
|
57
|
-
return this._commandService.executeCommand(
|
|
60
|
+
return this._commandService.executeCommand(AddHyperLinkCommand.id, params);
|
|
58
61
|
}
|
|
59
|
-
/**
|
|
60
|
-
* @deprecated
|
|
61
|
-
*/
|
|
62
62
|
getHyperLinks() {
|
|
63
|
-
var
|
|
64
|
-
const
|
|
65
|
-
return
|
|
66
|
-
var
|
|
63
|
+
var _a2, _b, _c;
|
|
64
|
+
const cellValue = this._worksheet.getCellRaw(this._range.startRow, this._range.startColumn);
|
|
65
|
+
return cellValue != null && cellValue.p ? (_c = (_b = (_a2 = cellValue.p.body) == null ? void 0 : _a2.customRanges) == null ? void 0 : _b.filter((range) => range.rangeType === CustomRangeType.HYPERLINK).map((range) => {
|
|
66
|
+
var _a3, _b2, _c2, _d, _e;
|
|
67
67
|
return {
|
|
68
|
-
id: `${
|
|
69
|
-
startIndex:
|
|
70
|
-
endIndex:
|
|
71
|
-
url: (
|
|
72
|
-
label: (
|
|
68
|
+
id: `${range.rangeId}`,
|
|
69
|
+
startIndex: range.startIndex,
|
|
70
|
+
endIndex: range.endIndex,
|
|
71
|
+
url: (_b2 = (_a3 = range.properties) == null ? void 0 : _a3.url) != null ? _b2 : "",
|
|
72
|
+
label: (_e = (_d = (_c2 = cellValue.p) == null ? void 0 : _c2.body) == null ? void 0 : _d.dataStream.slice(range.startIndex, range.endIndex + 1).replaceAll(DataStreamTreeTokenType.CUSTOM_RANGE_START, "").replaceAll(DataStreamTreeTokenType.CUSTOM_RANGE_END, "")) != null ? _e : ""
|
|
73
73
|
};
|
|
74
|
-
})) != null ?
|
|
74
|
+
})) != null ? _c : [] : [];
|
|
75
75
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
*/
|
|
79
|
-
updateHyperLink(e, t, r) {
|
|
80
|
-
const i = {
|
|
76
|
+
updateHyperLink(id, url, label) {
|
|
77
|
+
const params = {
|
|
81
78
|
unitId: this.getUnitId(),
|
|
82
79
|
subUnitId: this._worksheet.getSheetId(),
|
|
83
80
|
row: this._range.startRow,
|
|
84
81
|
column: this._range.startColumn,
|
|
85
|
-
id
|
|
82
|
+
id,
|
|
86
83
|
payload: {
|
|
87
|
-
payload:
|
|
88
|
-
display:
|
|
84
|
+
payload: url,
|
|
85
|
+
display: label
|
|
89
86
|
}
|
|
90
87
|
};
|
|
91
|
-
return this._commandService.executeCommand(
|
|
88
|
+
return this._commandService.executeCommand(UpdateHyperLinkCommand.id, params);
|
|
92
89
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
*/
|
|
96
|
-
cancelHyperLink(e) {
|
|
97
|
-
const t = {
|
|
90
|
+
cancelHyperLink(id) {
|
|
91
|
+
const params = {
|
|
98
92
|
unitId: this.getUnitId(),
|
|
99
93
|
subUnitId: this._worksheet.getSheetId(),
|
|
100
94
|
row: this._range.startRow,
|
|
101
95
|
column: this._range.startColumn,
|
|
102
|
-
id
|
|
96
|
+
id
|
|
103
97
|
};
|
|
104
|
-
return this._commandService.syncExecuteCommand(
|
|
98
|
+
return this._commandService.syncExecuteCommand(CancelHyperLinkCommand.id, params);
|
|
105
99
|
}
|
|
106
100
|
getUrl() {
|
|
107
|
-
return this._injector.get(
|
|
101
|
+
return this._injector.get(SheetsHyperLinkParserService).buildHyperLink(this.getUnitId(), this.getSheetId(), this.getRange());
|
|
108
102
|
}
|
|
109
103
|
// #endregion
|
|
110
|
-
}
|
|
111
|
-
|
|
104
|
+
};
|
|
105
|
+
__name(_FRangeHyperlinkMixin, "FRangeHyperlinkMixin");
|
|
106
|
+
let FRangeHyperlinkMixin = _FRangeHyperlinkMixin;
|
|
107
|
+
FRange.extend(FRangeHyperlinkMixin);
|
|
108
|
+
const _FSheetLinkEvent = class _FSheetLinkEvent {
|
|
109
|
+
get BeforeSheetLinkAdd() {
|
|
110
|
+
return "BeforeSheetLinkAdd";
|
|
111
|
+
}
|
|
112
|
+
get BeforeSheetLinkCancel() {
|
|
113
|
+
return "BeforeSheetLinkCancel";
|
|
114
|
+
}
|
|
115
|
+
get BeforeSheetLinkUpdate() {
|
|
116
|
+
return "BeforeSheetLinkUpdate";
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
__name(_FSheetLinkEvent, "FSheetLinkEvent");
|
|
120
|
+
let FSheetLinkEvent = _FSheetLinkEvent;
|
|
121
|
+
FEventName.extend(FSheetLinkEvent);
|
|
122
|
+
const _FSheetLinkUniver = class _FSheetLinkUniver extends FUniver {
|
|
123
|
+
/**
|
|
124
|
+
* @ignore
|
|
125
|
+
*/
|
|
126
|
+
_initialize(injector) {
|
|
127
|
+
const commandService = injector.get(ICommandService);
|
|
128
|
+
this.disposeWithMe(
|
|
129
|
+
commandService.beforeCommandExecuted((commandInfo) => {
|
|
130
|
+
if (commandInfo.id === AddHyperLinkCommand.id) {
|
|
131
|
+
if (!this._eventListend(this.Event.BeforeSheetLinkAdd)) return;
|
|
132
|
+
const eventTarget = this.getCommandSheetTarget(commandInfo);
|
|
133
|
+
if (!eventTarget) return;
|
|
134
|
+
const params = commandInfo.params, eventParams = {
|
|
135
|
+
workbook: eventTarget.workbook,
|
|
136
|
+
worksheet: eventTarget.worksheet,
|
|
137
|
+
row: params.link.row,
|
|
138
|
+
col: params.link.column,
|
|
139
|
+
link: params.link
|
|
140
|
+
};
|
|
141
|
+
if (this.fireEvent(this.Event.BeforeSheetLinkAdd, eventParams), eventParams.cancel)
|
|
142
|
+
throw new CanceledError();
|
|
143
|
+
}
|
|
144
|
+
if (commandInfo.id === UpdateHyperLinkCommand.id) {
|
|
145
|
+
const eventTarget = this.getCommandSheetTarget(commandInfo);
|
|
146
|
+
if (!eventTarget) return;
|
|
147
|
+
const params = commandInfo.params, eventParams = {
|
|
148
|
+
workbook: eventTarget.workbook,
|
|
149
|
+
worksheet: eventTarget.worksheet,
|
|
150
|
+
row: params.row,
|
|
151
|
+
column: params.column,
|
|
152
|
+
id: params.id,
|
|
153
|
+
payload: params.payload
|
|
154
|
+
};
|
|
155
|
+
if (this.fireEvent(this.Event.BeforeSheetLinkUpdate, eventParams), eventParams.cancel)
|
|
156
|
+
throw new CanceledError();
|
|
157
|
+
}
|
|
158
|
+
if (commandInfo.id === CancelHyperLinkCommand.id) {
|
|
159
|
+
const eventTarget = this.getCommandSheetTarget(commandInfo);
|
|
160
|
+
if (!eventTarget) return;
|
|
161
|
+
const params = commandInfo.params, eventParams = {
|
|
162
|
+
workbook: eventTarget.workbook,
|
|
163
|
+
worksheet: eventTarget.worksheet,
|
|
164
|
+
row: params.row,
|
|
165
|
+
column: params.column,
|
|
166
|
+
id: params.id
|
|
167
|
+
};
|
|
168
|
+
if (this.fireEvent(this.Event.BeforeSheetLinkCancel, eventParams), eventParams.cancel)
|
|
169
|
+
throw new CanceledError();
|
|
170
|
+
}
|
|
171
|
+
})
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
__name(_FSheetLinkUniver, "FSheetLinkUniver");
|
|
176
|
+
let FSheetLinkUniver = _FSheetLinkUniver;
|
|
177
|
+
FUniver.extend(FSheetLinkUniver);
|
|
112
178
|
export {
|
|
113
|
-
|
|
179
|
+
FWorkbookHyperLinkMixin
|
|
114
180
|
};
|