@univerjs/sheets-hyper-link 0.5.1 → 0.5.2
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 +4 -11
- package/lib/es/index.js +145 -141
- package/lib/types/facade/f-range.d.ts +8 -7
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +8 -8
package/lib/cjs/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/sheets/facade"),i=require("@univerjs/sheets-hyper-link"),a=require("@univerjs/core");class u extends o.FWorkbook{createSheetHyperlink(e,t){return this._injector.get(i.SheetsHyperLinkParserService).buildHyperLink(this.getId(),e,t)}parseSheetHyperlink(e){return this._injector.get(i.SheetsHyperLinkParserService).parseHyperLink(e)}}o.FWorkbook.extend(u);class k extends o.FRange{setHyperLink(e,t){const n={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),link:{row:this._range.startRow,column:this._range.startColumn,payload:e,display:t,id:a.generateRandomId()}};return this._commandService.executeCommand(i.AddHyperLinkCommand.id,n)}getHyperLinks(){var t,n,s;const e=this._worksheet.getCellRaw(this._range.startRow,this._range.startColumn);return e!=null&&e.p?(s=(n=(t=e.p.body)==null?void 0:t.customRanges)==null?void 0:n.filter(r=>r.rangeType===a.CustomRangeType.HYPERLINK).map(r=>{var d,p,c,l,m;return{id:`${r.rangeId}
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/sheets/facade"),i=require("@univerjs/sheets-hyper-link"),a=require("@univerjs/core");class u extends o.FWorkbook{createSheetHyperlink(e,t){return this._injector.get(i.SheetsHyperLinkParserService).buildHyperLink(this.getId(),e,t)}parseSheetHyperlink(e){return this._injector.get(i.SheetsHyperLinkParserService).parseHyperLink(e)}}o.FWorkbook.extend(u);class k extends o.FRange{setHyperLink(e,t){const n={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),link:{row:this._range.startRow,column:this._range.startColumn,payload:e,display:t,id:a.generateRandomId()}};return this._commandService.executeCommand(i.AddHyperLinkCommand.id,n)}getHyperLinks(){var t,n,s;const e=this._worksheet.getCellRaw(this._range.startRow,this._range.startColumn);return e!=null&&e.p?(s=(n=(t=e.p.body)==null?void 0:t.customRanges)==null?void 0:n.filter(r=>r.rangeType===a.CustomRangeType.HYPERLINK).map(r=>{var d,p,c,l,m;return{id:`${r.rangeId}`,startIndex:r.startIndex,endIndex:r.endIndex,url:(p=(d=r.properties)==null?void 0:d.url)!=null?p:"",label:(m=(l=(c=e.p)==null?void 0:c.body)==null?void 0:l.dataStream.slice(r.startIndex,r.endIndex+1).replaceAll(a.DataStreamTreeTokenType.CUSTOM_RANGE_START,"").replaceAll(a.DataStreamTreeTokenType.CUSTOM_RANGE_END,""))!=null?m:""}}))!=null?s:[]:[]}updateHyperLink(e,t,n){const s={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id:e,payload:{payload:t,display:n}};return this._commandService.executeCommand(i.UpdateHyperLinkCommand.id,s)}cancelHyperLink(e){const t={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id:e};return this._commandService.executeCommand(i.CancelHyperLinkCommand.id,t)}}o.FRange.extend(k);exports.FWorkbookHyperLinkMixin=u;
|
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var Se=Object.defineProperty;var Ie=(i,t,e)=>t in i?Se(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var C=(i,t,e)=>Ie(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),Re=require("rxjs"),g=require("@univerjs/sheets"),U=require("@univerjs/engine-formula"),Z=require("@univerjs/docs");var Me=Object.defineProperty,Ce=Object.getOwnPropertyDescriptor,Ue=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ce(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Me(t,e,r),r},Le=(i,t)=>(e,n)=>t(e,n,i);exports.HyperLinkModel=class extends o.Disposable{constructor(e){super();C(this,"_linkUpdate$",new Re.Subject);C(this,"linkUpdate$",this._linkUpdate$.asObservable());C(this,"_linkMap",new Map);C(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let r=this._linkMap.get(e);r||(r=new Map,this._linkMap.set(e,r));let s=r.get(n);s||(s=new o.ObjectMatrix,r.set(n,s));let a=this._linkPositionMap.get(e);a||(a=new Map,this._linkPositionMap.set(e,a));let d=a.get(n);return d||(d=new Map,a.set(n,d)),{matrix:s,positionMap:d}}addHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n);return s.setValue(r.row,r.column,r),a.set(r.id,{row:r.row,column:r.column,link:r}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:r,type:"add"}),!0}updateHyperLink(e,n,r,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(r);if(!l)return!0;const p=d.getValue(l.row,l.column);return p&&(Object.assign(p,s),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:p.display,payload:p.payload},id:r,type:"update",silent:a})),!0}updateHyperLinkRef(e,n,r,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(r);if(!l)return!0;let p=d.getValue(l.row,l.column);return!p||p.id!==r?p=l.link:d.realDeleteValue(l.row,l.column),Object.assign(p,s),c.set(r,{...s,link:p}),d.setValue(s.row,s.column,p),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:r,type:"updateRef",silent:a}),!0}removeHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(r);if(!d)return!1;a.delete(r);const c=s.getValue(d.row,d.column);return c&&c.id===r&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(r);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,r,s){const{matrix:a}=this._ensureMap(e,n);return a.getValue(r,s)}getHyperLinkByLocationSync(e,n,r,s){var u,m,f,h,_;const{matrix:a}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,o.UniverInstanceType.UNIVER_SHEET),c=(u=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:u.getCellRaw(r,s),l=((_=(h=c==null?void 0:c.v)!=null?h:(f=(m=c==null?void 0:c.p)==null?void 0:m.body)==null?void 0:f.dataStream.slice(0,-2))!=null?_:"").toString(),p=a.getValue(r,s);if(p)return{...p,display:l}}getSubUnit(e,n){const{matrix:r}=this._ensureMap(e,n),s=[];return r.forValue((a,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(r=>{const s=this.getSubUnit(e,r);return{unitId:e,subUnitId:r,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}};exports.HyperLinkModel=Ue([Le(0,o.IUniverInstanceService)],exports.HyperLinkModel);var L=(i=>(i.SHEET="gid",i.RANGE="range",i.DEFINE_NAME="rangeid",i.INVALID="invalid",i.URL="url",i))(L||{});const we="sheets-hyper-link.config",Ee={},w={type:o.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,link:s}=t;return e.addHyperLink(n,r,s)}},E={type:o.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,id:s}=t;return e.removeHyperLink(n,r,s)}},F={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,payload:s,id:a}=t;return e.updateHyperLink(n,r,a,s,!1)}},K={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,id:s,row:a,column:d,silent:c}=t;return e.updateHyperLinkRef(n,r,s,{row:a,column:d},c)}},B={type:o.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(i,t){var f,h,_;if(!t)return!1;const{unitId:e,subUnitId:n,row:r,col:s,id:a,url:d}=t,c=i.get(o.IUniverInstanceService),l=g.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:p}=l,u=p.getCellRaw(r,s),m=(_=(h=(f=u==null?void 0:u.p)==null?void 0:f.body)==null?void 0:h.customRanges)==null?void 0:_.find(S=>S.rangeType===o.CustomRangeType.HYPERLINK&&S.rangeId===a);return m&&(m.properties.url=d),!0}},ce="SHEET_HYPER_LINK_PLUGIN",x="err";var ke=Object.defineProperty,be=Object.getOwnPropertyDescriptor,Pe=(i,t,e,n)=>{for(var r=n>1?void 0:n?be(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&ke(t,e,r),r},A=(i,t)=>(e,n)=>t(e,n,i);let z=class extends o.Disposable{constructor(t,e,n,r){super();C(this,"_disposableMap",new Map);C(this,"_watchDisposableMap",new Map);C(this,"_rangeDisableMap",new Map);C(this,"_rangeWatcherMap",new Map);C(this,"_handlePositionChange",(t,e,n,r,s)=>{const a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return r?{redos:[{id:K.id,params:{unitId:t,subUnitId:e,id:n.id,row:r.startRow,column:r.startColumn,silent:s}}],undos:[{id:K.id,params:{unitId:t,subUnitId:e,id:n.id,row:a.startRow,column:a.startColumn,silent:s}}]}:{redos:[{id:E.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:w.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=r,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const r=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},a=d=>{const c=g.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===s.startColumn&&l.startRow===s.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(r,this._refRangeService.registerRefRange(s,a,t,e))}_watchPosition(t,e,n){const r=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(r,this._refRangeService.watchRange(t,e,s,(a,d)=>{const{redos:c}=this._handlePositionChange(t,e,n,d,!0);o.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(t){const e=this._disposableMap.get(t);e==null||e.dispose(),this._disposableMap.delete(t)}_unwatchPosition(t){const e=this._watchDisposableMap.get(t);e==null||e.dispose(),this._watchDisposableMap.delete(t)}_registerRange(t,e,n,r=!1){var s,a,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(s=c.get("gid"))!=null?s:"",range:(a=c.get("range"))!=null?a:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const p=l.gid,u=U.deserializeRangeWithSheet(l.range).range;if(o.isValidRange(u)&&l.range!==x){const m=f=>{const h=g.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(u,f,{selectionManagerService:this._selectionManagerService});return h&&U.serializeRange(h)===U.serializeRange(u)?{redos:[],undos:[]}:{redos:[{id:F.id,params:{unitId:t,subUnitId:p,id:e,payload:{payload:`#gid=${p}&range=${h?U.serializeRange(h):"err"}`}}}],undos:[{id:F.id,params:{unitId:t,subUnitId:p,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(u,m,t,p)),r||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,p,u,(f,h)=>{this._hyperLinkModel.updateHyperLink(t,p,e,{payload:`#gid=${p}&range=${h?U.serializeRange(h):"err"}`},!0)},!0))}}}}_unregisterRange(t){const e=this._rangeDisableMap.get(t);e==null||e.dispose(),this._rangeDisableMap.delete(t)}_unwatchRange(t){const e=this._rangeWatcherMap.get(t);e==null||e.dispose(),this._rangeWatcherMap.delete(t)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(n=>{const{unitId:r,subUnitId:s,links:a}=n;a.forEach(d=>{this._registerPosition(r,s,d),this._watchPosition(r,s,d),this._registerRange(r,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:r,silent:s}=t,a=this._hyperLinkModel.getHyperLink(e,n,r);if(!a)return;this._unregisterPosition(r),this._registerPosition(e,n,a),s||(this._unwatchPosition(r),this._watchPosition(e,n,a));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:r}=n;r.forEach(s=>{this._unregisterPosition(s.id),this._unwatchPosition(s.id),this._unregisterRange(s.id),this._unwatchRange(s.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(o.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};z=Pe([A(0,o.Inject(g.RefRangeService)),A(1,o.Inject(exports.HyperLinkModel)),A(2,o.Inject(g.SheetsSelectionsService)),A(3,o.ICommandService)],z);var Te=Object.defineProperty,He=Object.getOwnPropertyDescriptor,Ne=(i,t,e,n)=>{for(var r=n>1?void 0:n?He(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Te(t,e,r),r},te=(i,t)=>(e,n)=>t(e,n,i);let G=class extends o.Disposable{constructor(i,t,e){super(),this._sheetInterceptorService=i,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{var t;if(i.id===g.RemoveSheetCommand.id){const e=i.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const r=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const a=this._hyperLinkModel.getSubUnit(r,s),d=a.map(l=>({id:E.id,params:{unitId:r,subUnitId:s,id:l.id}})),c=a.map(l=>({id:w.id,params:{unitId:r,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};G=Ne([te(0,o.Inject(g.SheetInterceptorService)),te(1,o.IUniverInstanceService),te(2,o.Inject(exports.HyperLinkModel))],G);var Oe=Object.defineProperty,De=Object.getOwnPropertyDescriptor,Ve=(i,t,e,n)=>{for(var r=n>1?void 0:n?De(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Oe(t,e,r),r},ne=(i,t)=>(e,n)=>t(e,n,i);let Y=class extends o.Disposable{constructor(t,e,n){super();C(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let r=n.get(e);return r||(r=new o.ObjectMatrix,n.set(e,r)),r}_isLegalRangeUrl(t,e){var r,s,a;const n=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(r=d.get("gid"))!=null?r:"",range:(s=d.get("range"))!=null?s:"",rangeid:(a=d.get("rangeid"))!=null?a:""};if(c.range&&c.gid){const l=c.gid,p=n.getSheetBySheetId(l);if(!p)return null;const u=U.deserializeRangeWithSheet(c.range).range;if(o.isValidRange(u,p)&&c.range!==x)return{range:u,worksheet:p}}}return null}_registerRange(t,e,n,r,s){var d,c,l,p;const a=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(u=>{var m;return u.rangeType===o.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(m=u.properties)==null?void 0:m.url)})){const u=new o.DisposableCollection;let m=!1;(p=(l=s.body)==null?void 0:l.customRanges)==null||p.forEach(f=>{var h;if(f.rangeType===o.CustomRangeType.HYPERLINK){const _=(h=f.properties)==null?void 0:h.url,S=this._isLegalRangeUrl(t,_);if(S){const{range:y,worksheet:M}=S;m=!0,u.add(this._refRangeService.registerRefRange(y,v=>{const I=g.handleDefaultRangeChangeWithEffectRefCommands(y,v);return I&&o.Rectangle.equals(I,y)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:r,id:f.rangeId,url:`#gid=${e}&range=${I?U.serializeRange(I):x}`}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:r,id:f.rangeId,url:_}}],redos:[]}},M.getUnitId(),M.getSheetId()))}}}),m&&a.setValue(n,r,u)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(r=>{const s=r.getSheetId(),a=this._enusreMap(n,s);r.getCellMatrix().forValue((d,c,l)=>{const p=a.getValue(d,c);p&&p.dispose(),l&&l.p&&this._registerRange(n,s,d,c,l.p)})})};this._univerInstanceService.getAllUnitsForType(o.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(e=>{e.type===o.UniverInstanceType.UNIVER_SHEET&&t(e)}))}_initWorkbookUnload(){this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===o.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(r=>{const s=r.getSheetId();this._enusreMap(n,s).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}})}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===g.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:r,cellValue:s}=e,a=this._enusreMap(n,r);s&&new o.ObjectMatrix(s).forValue((d,c,l)=>{const p=a.getValue(d,c);p&&p.dispose(),l&&l.p&&this._registerRange(n,r,d,c,l.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===B.id){const e=t.params,{unitId:n,subUnitId:r,row:s,col:a}=e,d=g.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:r}),l=this._enusreMap(n,r).getValue(s,a);if(l&&l.dispose(),d){const{worksheet:p}=d,u=p.getCellRaw(s,a);u&&u.p&&this._registerRange(n,r,s,a,u.p)}}}))}};Y=Ve([ne(0,o.ICommandService),ne(1,o.IUniverInstanceService),ne(2,o.Inject(g.RefRangeService))],Y);var xe=Object.defineProperty,$e=Object.getOwnPropertyDescriptor,je=(i,t,e,n)=>{for(var r=n>1?void 0:n?$e(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&xe(t,e,r),r},W=(i,t)=>(e,n)=>t(e,n,i);let q=class extends o.Disposable{constructor(i,t,e,n){super(),this._sheetInterceptorService=i,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(i.id===g.SetRangeValuesCommand.id){const t=i.params,{unitId:e,subUnitId:n}=t,r=[],s=[];return t.cellValue&&new o.ObjectMatrix(t.cellValue).forValue((a,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,a,d);c&&(r.push({id:E.id,params:{unitId:e,subUnitId:n,id:c.id}}),s.push({id:w.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:s,redos:r}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(i.id===g.ClearSelectionContentCommand.id||i.id===g.ClearSelectionAllCommand.id||i.id===g.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),r=g.getSheetCommandTarget(this._univerInstanceService);if(n&&r){const{unitId:s,subUnitId:a}=r;o.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(s,a,d,c);l&&(t.push({id:E.id,params:{unitId:s,subUnitId:a,id:l.id}}),e.push({id:w.id,params:{unitId:s,subUnitId:a,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(g.AFTER_CELL_EDIT,{handler:(i,t,e)=>{if(!i||i.p)return e(i);if(typeof i.v=="string"&&o.Tools.isLegalUrl(i.v)&&i.v[i.v.length-1]!==" "){const{unitId:n,subUnitId:r}=t,s=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET),a=s==null?void 0:s.getSheetBySheetId(r);if(!a)return e(i);const d=a.getBlankCellDocumentModel(i);if(!d.documentModel)return e(i);const c=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:i.v.length,collapsed:!1},body:{dataStream:`${i.v}`,customRanges:[{startIndex:0,endIndex:i.v.length-1,rangeId:o.generateRandomId(),rangeType:o.CustomRangeType.HYPERLINK,properties:{url:i.v}}]},doc:d.documentModel});if(!c)return e(i);const l=d.documentModel.getBody();return o.TextX.apply(l,c.serialize()),e({...i,p:{id:o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:l,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(i)}}))}};q=je([W(0,o.Inject(g.SheetInterceptorService)),W(1,o.Inject(exports.HyperLinkModel)),W(2,o.Inject(g.SheetsSelectionsService)),W(3,o.IUniverInstanceService)],q);var le=(i=>(i[i.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",i[i.UNIVER_DOC=1]="UNIVER_DOC",i[i.UNIVER_SHEET=2]="UNIVER_SHEET",i[i.UNIVER_SLIDE=3]="UNIVER_SLIDE",i[i.UNIVER_PROJECT=4]="UNIVER_PROJECT",i[i.UNRECOGNIZED=-1]="UNRECOGNIZED",i))(le||{}),Ae=Object.defineProperty,We=Object.getOwnPropertyDescriptor,Be=(i,t,e,n)=>{for(var r=n>1?void 0:n?We(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Ae(t,e,r),r},oe=(i,t)=>(e,n)=>t(e,n,i);let J=class extends o.Disposable{constructor(i,t){super(),this._resourceManagerService=i,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const i=e=>{const n=this._hyperLinkModel.getUnit(e),r={};return n?(n.forEach(s=>{r[s.subUnitId]=s.links.map(({display:a,...d})=>d)}),JSON.stringify(r)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:ce,businesses:[le.UNIVER_SHEET],toJson:e=>i(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(r=>{n[r].forEach(a=>{this._hyperLinkModel.addHyperLink(e,r,a)})})}}))}};J=Be([oe(0,o.IResourceManagerService),oe(1,o.Inject(exports.HyperLinkModel))],J);const pe={type:o.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(i,t){if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=i.get(g.SheetInterceptorService),d=g.getSheetCommandTarget(r,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:p,worksheet:u}=d,{link:m}=t,{payload:f,display:h,row:_,column:S,id:y}=m,M=u.getCell(_,S),v=u.getBlankCellDocumentModel(M),I=v.documentModel.getSnapshot(),R=o.Tools.deepClone(I.body);if(!R)return!1;let k;if(h?k=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:R.dataStream.length-2,collapsed:!0},body:{dataStream:`${h}`,customRanges:[{startIndex:0,endIndex:h.length-1,rangeType:o.CustomRangeType.HYPERLINK,rangeId:y,properties:{url:f}}]},doc:v.documentModel}):k=o.BuildTextUtils.customRange.add({body:R,ranges:[{startOffset:0,endOffset:R.dataStream.length-2,collapsed:!1}],rangeId:y,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:f,refId:y}}),!k)return!1;const D=o.TextX.apply(R,k.serialize()),b={p:{...I,body:D},t:o.CellValueType.STRING},T=await a.onWriteCell(p,u,_,S,b),H={unitId:c,subUnitId:l,cellValue:{[m.row]:{[m.column]:T}}},Q={id:g.SetRangeValuesMutation.id,params:H},$=g.SetRangeValuesUndoMutationFactory(i,H),ee={id:g.SetRangeValuesMutation.id,params:$},V=[Q],N=[ee],O=s.getHyperLinkByLocation(c,l,_,S);return O&&(V.push({id:E.id,params:{unitId:c,subUnitId:l,id:O.id}}),N.push({id:w.id,params:{unitId:c,subUnitId:l,link:O}})),await o.sequenceExecuteAsync(V,e)?(n.pushUndoRedo({redoMutations:V,undoMutations:N,unitID:c}),!0):!1}},ue={id:"sheets.command.add-rich-hyper-link",type:o.CommandType.COMMAND,handler:async(i,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,r=i.get(o.ICommandService),s=o.generateRandomId(),{payload:a}=n,d=Z.addCustomRangeBySelectionFactory(i,{unitId:e,rangeId:s,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:a,refId:s}});return d?r.syncExecuteCommand(d.id,d.params):!1}},he={type:o.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(i,t){var b,T;if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=g.getSheetCommandTarget(r,t);if(!a)return!1;const{row:d,column:c,id:l}=t,{unitId:p,subUnitId:u,worksheet:m}=a,f=m.getCell(d,c);if(!f)return!1;const h=m.getCellDocumentModelWithFormula(f);if(!(h!=null&&h.documentModel))return!1;const _=o.Tools.deepClone(h.documentModel.getSnapshot());if(!((T=(b=_.body)==null?void 0:b.customRanges)==null?void 0:T.find(H=>H.rangeId===l)))return!1;const y=o.BuildTextUtils.customRange.delete(i,{documentDataModel:h.documentModel,rangeId:l});if(!y)return!1;const M=o.TextX.apply(_.body,y.serialize()),v=[],I=[],R={unitId:p,subUnitId:u,cellValue:{[d]:{[c]:{p:{..._,body:M},t:o.CellValueType.STRING}}}};v.push({id:g.SetRangeValuesMutation.id,params:R});const k=g.SetRangeValuesUndoMutationFactory(i,R);I.push({id:g.SetRangeValuesMutation.id,params:k});const D=s.getHyperLinkByLocation(p,u,d,c);return D&&(v.push({id:E.id,params:{unitId:p,subUnitId:u,id:l}}),I.push({id:w.id,params:{unitId:p,subUnitId:u,link:{...D}}})),o.sequenceExecute(v,e).result?(n.pushUndoRedo({redoMutations:v,undoMutations:I,unitID:p}),!0):!1}},ge={type:o.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(i,t){var p,u;if(!t)return!1;const{id:e,documentId:n}=t,r=i.get(o.ICommandService),a=i.get(o.IUniverInstanceService).getUnit(n,o.UniverInstanceType.UNIVER_DOC),d=(u=(p=a==null?void 0:a.getBody())==null?void 0:p.customRanges)==null?void 0:u.find(m=>m.rangeId===e);let c=null;d&&d.endIndex===a.getBody().dataStream.length-3&&(c={dataStream:" "});const l=Z.deleteCustomRangeFactory(i,{unitId:n,rangeId:e,insert:c});return l?r.syncExecuteCommand(l.id,l.params):!1}},me={type:o.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(i,t){var ie,se,ae;if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=i.get(g.SheetInterceptorService),d=g.getSheetCommandTarget(r,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:p,id:u}=t,{workbook:m,worksheet:f,unitId:h,subUnitId:_}=d,{payload:S,display:y=""}=c,M=f.getCell(l,p);if(!M)return!1;const v=f.getCellDocumentModelWithFormula(M);if(!(v!=null&&v.documentModel))return!1;const I=v.documentModel.getSnapshot(),R=(se=(ie=I.body)==null?void 0:ie.customRanges)==null?void 0:se.find(ve=>ve.rangeId===u);if(!R)return!1;const k=o.generateRandomId(),P=(ae=o.getBodySlice(v.documentModel.getBody(),R.startIndex,R.endIndex+1).textRuns)==null?void 0:ae[0];P&&(P.ed=y.length+1);const b=Z.replaceSelectionFactory(i,{unitId:h,body:{dataStream:`${y}`,customRanges:[{rangeId:k,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:y.length-1,properties:{url:S}}],textRuns:P?[P]:void 0},selection:{startOffset:R.startIndex,endOffset:R.endIndex+1,collapsed:!1},doc:v.documentModel});if(!b)return!1;const T=o.TextX.apply(o.Tools.deepClone(I.body),b.textX.serialize()),H={p:{...I,body:T},t:o.CellValueType.STRING},Q=await a.onWriteCell(m,f,l,p,H),$={id:g.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:_,cellValue:{[l]:{[p]:Q}}}},ee=g.SetRangeValuesUndoMutationFactory(i,$.params),V={id:g.SetRangeValuesMutation.id,params:ee},N=[$],O=[V],j=s.getHyperLinkByLocation(h,_,l,p);return j&&(N.push({id:E.id,params:{unitId:h,subUnitId:_,id:j.id}}),O.push({id:w.id,params:{unitId:h,subUnitId:_,link:j}})),await o.sequenceExecuteAsync(N,e)?(n.pushUndoRedo({redoMutations:N,undoMutations:O,unitID:h}),!0):!1}},fe={type:o.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(i,t)=>{var h,_,S,y;if(!t)return!1;const{documentId:e,payload:n,id:r}=t,s=i.get(o.IUniverInstanceService),a=i.get(o.ICommandService),d=s.getUnit(e,o.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(_=(h=d.getBody())==null?void 0:h.customRanges)==null?void 0:_.find(M=>M.rangeId===r);if(!c)return!1;const l=(S=t.payload.display)!=null?S:"",p=o.generateRandomId(),m=(y=o.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:y[0];m&&(m.ed=l.length+1);const f=Z.replaceSelectionFactory(i,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:p,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:m?[m]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return f?a.syncExecuteCommand(f.id,f.params):!1}};var Fe=Object.defineProperty,Ke=Object.getOwnPropertyDescriptor,ze=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ke(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Fe(t,e,r),r},Ge=(i,t)=>(e,n)=>t(e,n,i);let X=class extends o.Disposable{constructor(i){super(),this._commandService=i,this._registerCommands()}_registerCommands(){[pe,me,he,fe,ge,ue,w,F,E,K,B].forEach(i=>{this._commandService.registerCommand(i)})}};X=ze([Ge(0,o.ICommandService)],X);var Ye=Object.defineProperty,qe=Object.getOwnPropertyDescriptor,Je=(i,t,e,n)=>{for(var r=n>1?void 0:n?qe(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Ye(t,e,r),r},re=(i,t)=>(e,n)=>t(e,n,i);exports.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${L.SHEET}=${e}${n?`&${typeof n=="string"?L.DEFINE_NAME:L.RANGE}=${typeof n=="string"?n:U.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,r,s;if(t.startsWith("#")){const a=new URLSearchParams(t.slice(1)),d={gid:(e=a.get("gid"))!=null?e:"",range:(n=a.get("range"))!=null?n:"",rangeid:(r=a.get("rangeid"))!=null?r:"",unitid:(s=a.get("unitid"))!=null?s:""},c=this._getURLName(d);return{type:c.type,name:c.name,url:t,searchObj:d}}else return{type:L.URL,name:t,url:t,searchObj:null}}_getURLName(t){var p;const{gid:e,range:n,rangeid:r,unitid:s}=t,a=s?this._univerInstanceService.getUnit(s,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),d={type:L.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!a)return d;const c=e?a.getSheetBySheetId(e):a.getActiveSheet(),l=(p=c==null?void 0:c.getName())!=null?p:"";if(n){if(!c)return d;const u=U.deserializeRangeWithSheet(n).range;return o.isValidRange(u,c)&&n!==x?{type:L.RANGE,name:U.serializeRangeWithSheet(l,u)}:d}if(r){const u=this._definedNamesService.getValueById(a.getUnitId(),r);return u?{type:L.DEFINE_NAME,name:u.formulaOrRefString}:d}if(e){const u=a.getSheetBySheetId(e);return u?{type:L.SHEET,name:u.getName()}:d}return d}};exports.SheetsHyperLinkParserService=Je([re(0,o.IUniverInstanceService),re(1,o.Inject(o.LocaleService)),re(2,U.IDefinedNamesService)],exports.SheetsHyperLinkParserService);var _e=Object.defineProperty,Xe=Object.getOwnPropertyDescriptor,Ze=(i,t,e)=>t in i?_e(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,Qe=(i,t,e,n)=>{for(var r=n>1?void 0:n?Xe(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&_e(t,e,r),r},de=(i,t)=>(e,n)=>t(e,n,i),ye=(i,t,e)=>Ze(i,typeof t!="symbol"?t+"":t,e);exports.UniverSheetsHyperLinkPlugin=class extends o.Plugin{constructor(t=Ee,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...r}=this._config;this._configService.setConfig(we,r)}onStarting(){o.registerDependencies(this._injector,[[exports.HyperLinkModel],[exports.SheetsHyperLinkParserService],[J],[X],[z],[q],[G],[Y]]),o.touchDependencies(this._injector,[[z],[J],[X],[q],[G],[Y]])}};ye(exports.UniverSheetsHyperLinkPlugin,"pluginName",ce);ye(exports.UniverSheetsHyperLinkPlugin,"type",o.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsHyperLinkPlugin=Qe([o.DependentOn(g.UniverSheetsPlugin),de(1,o.Inject(o.Injector)),de(2,o.IConfigService)],exports.UniverSheetsHyperLinkPlugin);exports.AddHyperLinkCommand=pe;exports.AddHyperLinkMutation=w;exports.AddRichHyperLinkCommand=ue;exports.CancelHyperLinkCommand=he;exports.CancelRichHyperLinkCommand=ge;exports.ERROR_RANGE=x;exports.RemoveHyperLinkMutation=E;exports.SheetHyperLinkType=L;exports.UpdateHyperLinkCommand=me;exports.UpdateHyperLinkMutation=F;exports.UpdateHyperLinkRefMutation=K;exports.UpdateRichHyperLinkCommand=fe;
|
|
1
|
+
"use strict";var Ie=Object.defineProperty;var Re=(i,t,e)=>t in i?Ie(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var C=(i,t,e)=>Re(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),Me=require("rxjs"),g=require("@univerjs/sheets"),U=require("@univerjs/engine-formula"),Z=require("@univerjs/docs");var Ce=Object.defineProperty,Ue=Object.getOwnPropertyDescriptor,Le=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ue(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Ce(t,e,r),r},we=(i,t)=>(e,n)=>t(e,n,i);exports.HyperLinkModel=class extends o.Disposable{constructor(e){super();C(this,"_linkUpdate$",new Me.Subject);C(this,"linkUpdate$",this._linkUpdate$.asObservable());C(this,"_linkMap",new Map);C(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let r=this._linkMap.get(e);r||(r=new Map,this._linkMap.set(e,r));let s=r.get(n);s||(s=new o.ObjectMatrix,r.set(n,s));let a=this._linkPositionMap.get(e);a||(a=new Map,this._linkPositionMap.set(e,a));let d=a.get(n);return d||(d=new Map,a.set(n,d)),{matrix:s,positionMap:d}}addHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n);return s.setValue(r.row,r.column,r),a.set(r.id,{row:r.row,column:r.column,link:r}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:r,type:"add"}),!0}updateHyperLink(e,n,r,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(r);if(!l)return!0;const p=d.getValue(l.row,l.column);return p&&(Object.assign(p,s),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:p.display,payload:p.payload},id:r,type:"update",silent:a})),!0}updateHyperLinkRef(e,n,r,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(r);if(!l)return!0;let p=d.getValue(l.row,l.column);return!p||p.id!==r?p=l.link:d.realDeleteValue(l.row,l.column),Object.assign(p,s),c.set(r,{...s,link:p}),d.setValue(s.row,s.column,p),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:r,type:"updateRef",silent:a}),!0}removeHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(r);if(!d)return!1;a.delete(r);const c=s.getValue(d.row,d.column);return c&&c.id===r&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(r);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,r,s){const{matrix:a}=this._ensureMap(e,n);return a.getValue(r,s)}getHyperLinkByLocationSync(e,n,r,s){var u,m,f,h,_;const{matrix:a}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,o.UniverInstanceType.UNIVER_SHEET),c=(u=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:u.getCellRaw(r,s),l=((_=(h=c==null?void 0:c.v)!=null?h:(f=(m=c==null?void 0:c.p)==null?void 0:m.body)==null?void 0:f.dataStream.slice(0,-2))!=null?_:"").toString(),p=a.getValue(r,s);if(p)return{...p,display:l}}getSubUnit(e,n){const{matrix:r}=this._ensureMap(e,n),s=[];return r.forValue((a,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(r=>{const s=this.getSubUnit(e,r);return{unitId:e,subUnitId:r,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}};exports.HyperLinkModel=Le([we(0,o.IUniverInstanceService)],exports.HyperLinkModel);var L=(i=>(i.SHEET="gid",i.RANGE="range",i.DEFINE_NAME="rangeid",i.INVALID="invalid",i.URL="url",i))(L||{});const Ee="sheets-hyper-link.config",oe={},w={type:o.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,link:s}=t;return e.addHyperLink(n,r,s)}},E={type:o.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,id:s}=t;return e.removeHyperLink(n,r,s)}},F={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,payload:s,id:a}=t;return e.updateHyperLink(n,r,a,s,!1)}},K={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,id:s,row:a,column:d,silent:c}=t;return e.updateHyperLinkRef(n,r,s,{row:a,column:d},c)}},B={type:o.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(i,t){var f,h,_;if(!t)return!1;const{unitId:e,subUnitId:n,row:r,col:s,id:a,url:d}=t,c=i.get(o.IUniverInstanceService),l=g.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:p}=l,u=p.getCellRaw(r,s),m=(_=(h=(f=u==null?void 0:u.p)==null?void 0:f.body)==null?void 0:h.customRanges)==null?void 0:_.find(y=>y.rangeType===o.CustomRangeType.HYPERLINK&&y.rangeId===a);return m&&(m.properties.url=d),!0}},le="SHEET_HYPER_LINK_PLUGIN",x="err";var ke=Object.defineProperty,be=Object.getOwnPropertyDescriptor,Pe=(i,t,e,n)=>{for(var r=n>1?void 0:n?be(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&ke(t,e,r),r},A=(i,t)=>(e,n)=>t(e,n,i);let z=class extends o.Disposable{constructor(t,e,n,r){super();C(this,"_disposableMap",new Map);C(this,"_watchDisposableMap",new Map);C(this,"_rangeDisableMap",new Map);C(this,"_rangeWatcherMap",new Map);C(this,"_handlePositionChange",(t,e,n,r,s)=>{const a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return r?{redos:[{id:K.id,params:{unitId:t,subUnitId:e,id:n.id,row:r.startRow,column:r.startColumn,silent:s}}],undos:[{id:K.id,params:{unitId:t,subUnitId:e,id:n.id,row:a.startRow,column:a.startColumn,silent:s}}]}:{redos:[{id:E.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:w.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=r,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const r=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},a=d=>{const c=g.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===s.startColumn&&l.startRow===s.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(r,this._refRangeService.registerRefRange(s,a,t,e))}_watchPosition(t,e,n){const r=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(r,this._refRangeService.watchRange(t,e,s,(a,d)=>{const{redos:c}=this._handlePositionChange(t,e,n,d,!0);o.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(t){const e=this._disposableMap.get(t);e==null||e.dispose(),this._disposableMap.delete(t)}_unwatchPosition(t){const e=this._watchDisposableMap.get(t);e==null||e.dispose(),this._watchDisposableMap.delete(t)}_registerRange(t,e,n,r=!1){var s,a,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(s=c.get("gid"))!=null?s:"",range:(a=c.get("range"))!=null?a:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const p=l.gid,u=U.deserializeRangeWithSheet(l.range).range;if(o.isValidRange(u)&&l.range!==x){const m=f=>{const h=g.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(u,f,{selectionManagerService:this._selectionManagerService});return h&&U.serializeRange(h)===U.serializeRange(u)?{redos:[],undos:[]}:{redos:[{id:F.id,params:{unitId:t,subUnitId:p,id:e,payload:{payload:`#gid=${p}&range=${h?U.serializeRange(h):"err"}`}}}],undos:[{id:F.id,params:{unitId:t,subUnitId:p,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(u,m,t,p)),r||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,p,u,(f,h)=>{this._hyperLinkModel.updateHyperLink(t,p,e,{payload:`#gid=${p}&range=${h?U.serializeRange(h):"err"}`},!0)},!0))}}}}_unregisterRange(t){const e=this._rangeDisableMap.get(t);e==null||e.dispose(),this._rangeDisableMap.delete(t)}_unwatchRange(t){const e=this._rangeWatcherMap.get(t);e==null||e.dispose(),this._rangeWatcherMap.delete(t)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(n=>{const{unitId:r,subUnitId:s,links:a}=n;a.forEach(d=>{this._registerPosition(r,s,d),this._watchPosition(r,s,d),this._registerRange(r,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:r,silent:s}=t,a=this._hyperLinkModel.getHyperLink(e,n,r);if(!a)return;this._unregisterPosition(r),this._registerPosition(e,n,a),s||(this._unwatchPosition(r),this._watchPosition(e,n,a));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:r}=n;r.forEach(s=>{this._unregisterPosition(s.id),this._unwatchPosition(s.id),this._unregisterRange(s.id),this._unwatchRange(s.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(o.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};z=Pe([A(0,o.Inject(g.RefRangeService)),A(1,o.Inject(exports.HyperLinkModel)),A(2,o.Inject(g.SheetsSelectionsService)),A(3,o.ICommandService)],z);var Te=Object.defineProperty,He=Object.getOwnPropertyDescriptor,Ne=(i,t,e,n)=>{for(var r=n>1?void 0:n?He(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Te(t,e,r),r},te=(i,t)=>(e,n)=>t(e,n,i);let G=class extends o.Disposable{constructor(i,t,e){super(),this._sheetInterceptorService=i,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{var t;if(i.id===g.RemoveSheetCommand.id){const e=i.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const r=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const a=this._hyperLinkModel.getSubUnit(r,s),d=a.map(l=>({id:E.id,params:{unitId:r,subUnitId:s,id:l.id}})),c=a.map(l=>({id:w.id,params:{unitId:r,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};G=Ne([te(0,o.Inject(g.SheetInterceptorService)),te(1,o.IUniverInstanceService),te(2,o.Inject(exports.HyperLinkModel))],G);var Oe=Object.defineProperty,De=Object.getOwnPropertyDescriptor,Ve=(i,t,e,n)=>{for(var r=n>1?void 0:n?De(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Oe(t,e,r),r},ne=(i,t)=>(e,n)=>t(e,n,i);let Y=class extends o.Disposable{constructor(t,e,n){super();C(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let r=n.get(e);return r||(r=new o.ObjectMatrix,n.set(e,r)),r}_isLegalRangeUrl(t,e){var r,s,a;const n=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(r=d.get("gid"))!=null?r:"",range:(s=d.get("range"))!=null?s:"",rangeid:(a=d.get("rangeid"))!=null?a:""};if(c.range&&c.gid){const l=c.gid,p=n.getSheetBySheetId(l);if(!p)return null;const u=U.deserializeRangeWithSheet(c.range).range;if(o.isValidRange(u,p)&&c.range!==x)return{range:u,worksheet:p}}}return null}_registerRange(t,e,n,r,s){var d,c,l,p;const a=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(u=>{var m;return u.rangeType===o.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(m=u.properties)==null?void 0:m.url)})){const u=new o.DisposableCollection;let m=!1;(p=(l=s.body)==null?void 0:l.customRanges)==null||p.forEach(f=>{var h;if(f.rangeType===o.CustomRangeType.HYPERLINK){const _=(h=f.properties)==null?void 0:h.url,y=this._isLegalRangeUrl(t,_);if(y){const{range:v,worksheet:M}=y;m=!0,u.add(this._refRangeService.registerRefRange(v,S=>{const I=g.handleDefaultRangeChangeWithEffectRefCommands(v,S);return I&&o.Rectangle.equals(I,v)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:r,id:f.rangeId,url:`#gid=${e}&range=${I?U.serializeRange(I):x}`}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:r,id:f.rangeId,url:_}}],redos:[]}},M.getUnitId(),M.getSheetId()))}}}),m&&a.setValue(n,r,u)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(r=>{const s=r.getSheetId(),a=this._enusreMap(n,s);r.getCellMatrix().forValue((d,c,l)=>{const p=a.getValue(d,c);p&&p.dispose(),l&&l.p&&this._registerRange(n,s,d,c,l.p)})})};this._univerInstanceService.getAllUnitsForType(o.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(e=>{e.type===o.UniverInstanceType.UNIVER_SHEET&&t(e)}))}_initWorkbookUnload(){this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===o.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(r=>{const s=r.getSheetId();this._enusreMap(n,s).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}})}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===g.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:r,cellValue:s}=e,a=this._enusreMap(n,r);s&&new o.ObjectMatrix(s).forValue((d,c,l)=>{const p=a.getValue(d,c);p&&p.dispose(),l&&l.p&&this._registerRange(n,r,d,c,l.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===B.id){const e=t.params,{unitId:n,subUnitId:r,row:s,col:a}=e,d=g.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:r}),l=this._enusreMap(n,r).getValue(s,a);if(l&&l.dispose(),d){const{worksheet:p}=d,u=p.getCellRaw(s,a);u&&u.p&&this._registerRange(n,r,s,a,u.p)}}}))}};Y=Ve([ne(0,o.ICommandService),ne(1,o.IUniverInstanceService),ne(2,o.Inject(g.RefRangeService))],Y);var xe=Object.defineProperty,$e=Object.getOwnPropertyDescriptor,je=(i,t,e,n)=>{for(var r=n>1?void 0:n?$e(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&xe(t,e,r),r},W=(i,t)=>(e,n)=>t(e,n,i);let q=class extends o.Disposable{constructor(i,t,e,n){super(),this._sheetInterceptorService=i,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(i.id===g.SetRangeValuesCommand.id){const t=i.params,{unitId:e,subUnitId:n}=t,r=[],s=[];return t.cellValue&&new o.ObjectMatrix(t.cellValue).forValue((a,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,a,d);c&&(r.push({id:E.id,params:{unitId:e,subUnitId:n,id:c.id}}),s.push({id:w.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:s,redos:r}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(i.id===g.ClearSelectionContentCommand.id||i.id===g.ClearSelectionAllCommand.id||i.id===g.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),r=g.getSheetCommandTarget(this._univerInstanceService);if(n&&r){const{unitId:s,subUnitId:a}=r;o.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(s,a,d,c);l&&(t.push({id:E.id,params:{unitId:s,subUnitId:a,id:l.id}}),e.push({id:w.id,params:{unitId:s,subUnitId:a,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(g.AFTER_CELL_EDIT,{handler:(i,t,e)=>{if(!i||i.p)return e(i);if(typeof i.v=="string"&&o.Tools.isLegalUrl(i.v)&&i.v[i.v.length-1]!==" "){const{unitId:n,subUnitId:r}=t,s=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET),a=s==null?void 0:s.getSheetBySheetId(r);if(!a)return e(i);const d=a.getBlankCellDocumentModel(i);if(!d.documentModel)return e(i);const c=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:i.v.length,collapsed:!1},body:{dataStream:`${i.v}`,customRanges:[{startIndex:0,endIndex:i.v.length-1,rangeId:o.generateRandomId(),rangeType:o.CustomRangeType.HYPERLINK,properties:{url:i.v}}]},doc:d.documentModel});if(!c)return e(i);const l=d.documentModel.getBody();return o.TextX.apply(l,c.serialize()),e({...i,p:{id:o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:l,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(i)}}))}};q=je([W(0,o.Inject(g.SheetInterceptorService)),W(1,o.Inject(exports.HyperLinkModel)),W(2,o.Inject(g.SheetsSelectionsService)),W(3,o.IUniverInstanceService)],q);var pe=(i=>(i[i.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",i[i.UNIVER_DOC=1]="UNIVER_DOC",i[i.UNIVER_SHEET=2]="UNIVER_SHEET",i[i.UNIVER_SLIDE=3]="UNIVER_SLIDE",i[i.UNIVER_PROJECT=4]="UNIVER_PROJECT",i[i.UNRECOGNIZED=-1]="UNRECOGNIZED",i))(pe||{}),Ae=Object.defineProperty,We=Object.getOwnPropertyDescriptor,Be=(i,t,e,n)=>{for(var r=n>1?void 0:n?We(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Ae(t,e,r),r},de=(i,t)=>(e,n)=>t(e,n,i);let J=class extends o.Disposable{constructor(i,t){super(),this._resourceManagerService=i,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const i=e=>{const n=this._hyperLinkModel.getUnit(e),r={};return n?(n.forEach(s=>{r[s.subUnitId]=s.links.map(({display:a,...d})=>d)}),JSON.stringify(r)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:le,businesses:[pe.UNIVER_SHEET],toJson:e=>i(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(r=>{n[r].forEach(a=>{this._hyperLinkModel.addHyperLink(e,r,a)})})}}))}};J=Be([de(0,o.IResourceManagerService),de(1,o.Inject(exports.HyperLinkModel))],J);const ue={type:o.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(i,t){if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=i.get(g.SheetInterceptorService),d=g.getSheetCommandTarget(r,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:p,worksheet:u}=d,{link:m}=t,{payload:f,display:h,row:_,column:y,id:v}=m,M=u.getCell(_,y),S=u.getBlankCellDocumentModel(M),I=S.documentModel.getSnapshot(),R=o.Tools.deepClone(I.body);if(!R)return!1;let k;if(h?k=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:R.dataStream.length-2,collapsed:R.dataStream.length-2===0},body:{dataStream:`${h}`,customRanges:[{startIndex:0,endIndex:h.length-1,rangeType:o.CustomRangeType.HYPERLINK,rangeId:v,properties:{url:f}}]},doc:S.documentModel}):k=o.BuildTextUtils.customRange.add({body:R,ranges:[{startOffset:0,endOffset:R.dataStream.length-2,collapsed:!1}],rangeId:v,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:f,refId:v}}),!k)return!1;const D=o.TextX.apply(R,k.serialize()),b={p:{...I,body:D},t:o.CellValueType.STRING},T=await a.onWriteCell(p,u,_,y,b),H={unitId:c,subUnitId:l,cellValue:{[m.row]:{[m.column]:T}}},Q={id:g.SetRangeValuesMutation.id,params:H},$=g.SetRangeValuesUndoMutationFactory(i,H),ee={id:g.SetRangeValuesMutation.id,params:$},V=[Q],N=[ee],O=s.getHyperLinkByLocation(c,l,_,y);return O&&(V.push({id:E.id,params:{unitId:c,subUnitId:l,id:O.id}}),N.push({id:w.id,params:{unitId:c,subUnitId:l,link:O}})),await o.sequenceExecuteAsync(V,e)?(n.pushUndoRedo({redoMutations:V,undoMutations:N,unitID:c}),!0):!1}},he={id:"sheets.command.add-rich-hyper-link",type:o.CommandType.COMMAND,handler:async(i,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,r=i.get(o.ICommandService),s=o.generateRandomId(),{payload:a}=n,d=Z.addCustomRangeBySelectionFactory(i,{unitId:e,rangeId:s,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:a,refId:s}});return d?r.syncExecuteCommand(d.id,d.params):!1}},ge={type:o.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(i,t){var b,T;if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=g.getSheetCommandTarget(r,t);if(!a)return!1;const{row:d,column:c,id:l}=t,{unitId:p,subUnitId:u,worksheet:m}=a,f=m.getCell(d,c);if(!f)return!1;const h=m.getCellDocumentModelWithFormula(f);if(!(h!=null&&h.documentModel))return!1;const _=o.Tools.deepClone(h.documentModel.getSnapshot()),y=(T=(b=_.body)==null?void 0:b.customRanges)==null?void 0:T.find(H=>`${H.rangeId}`===l);if(!y)return!1;const v=o.BuildTextUtils.customRange.delete(i,{documentDataModel:h.documentModel,rangeId:y.rangeId});if(!v)return!1;const M=o.TextX.apply(_.body,v.serialize()),S=[],I=[],R={unitId:p,subUnitId:u,cellValue:{[d]:{[c]:{p:{..._,body:M},t:o.CellValueType.STRING}}}};S.push({id:g.SetRangeValuesMutation.id,params:R});const k=g.SetRangeValuesUndoMutationFactory(i,R);I.push({id:g.SetRangeValuesMutation.id,params:k});const D=s.getHyperLinkByLocation(p,u,d,c);return D&&(S.push({id:E.id,params:{unitId:p,subUnitId:u,id:l}}),I.push({id:w.id,params:{unitId:p,subUnitId:u,link:{...D}}})),o.sequenceExecute(S,e).result?(n.pushUndoRedo({redoMutations:S,undoMutations:I,unitID:p}),!0):!1}},me={type:o.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(i,t){var p,u;if(!t)return!1;const{id:e,documentId:n}=t,r=i.get(o.ICommandService),a=i.get(o.IUniverInstanceService).getUnit(n,o.UniverInstanceType.UNIVER_DOC),d=(u=(p=a==null?void 0:a.getBody())==null?void 0:p.customRanges)==null?void 0:u.find(m=>m.rangeId===e);let c=null;d&&d.endIndex===a.getBody().dataStream.length-3&&(c={dataStream:" "});const l=Z.deleteCustomRangeFactory(i,{unitId:n,rangeId:e,insert:c});return l?r.syncExecuteCommand(l.id,l.params):!1}},fe={type:o.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(i,t){var ie,se,ae;if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=i.get(g.SheetInterceptorService),d=g.getSheetCommandTarget(r,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:p,id:u}=t,{workbook:m,worksheet:f,unitId:h,subUnitId:_}=d,{payload:y,display:v=""}=c,M=f.getCell(l,p);if(!M)return!1;const S=f.getCellDocumentModelWithFormula(M);if(!(S!=null&&S.documentModel))return!1;const I=S.documentModel.getSnapshot(),R=(se=(ie=I.body)==null?void 0:ie.customRanges)==null?void 0:se.find(Se=>`${Se.rangeId}`===u);if(!R)return!1;const k=o.generateRandomId(),P=(ae=o.getBodySlice(S.documentModel.getBody(),R.startIndex,R.endIndex+1).textRuns)==null?void 0:ae[0];P&&(P.ed=v.length+1);const b=Z.replaceSelectionFactory(i,{unitId:h,body:{dataStream:`${v}`,customRanges:[{rangeId:k,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:v.length-1,properties:{url:y}}],textRuns:P?[P]:void 0},selection:{startOffset:R.startIndex,endOffset:R.endIndex+1,collapsed:!1},doc:S.documentModel});if(!b)return!1;const T=o.TextX.apply(o.Tools.deepClone(I.body),b.textX.serialize()),H={p:{...I,body:T},t:o.CellValueType.STRING},Q=await a.onWriteCell(m,f,l,p,H),$={id:g.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:_,cellValue:{[l]:{[p]:Q}}}},ee=g.SetRangeValuesUndoMutationFactory(i,$.params),V={id:g.SetRangeValuesMutation.id,params:ee},N=[$],O=[V],j=s.getHyperLinkByLocation(h,_,l,p);return j&&(N.push({id:E.id,params:{unitId:h,subUnitId:_,id:j.id}}),O.push({id:w.id,params:{unitId:h,subUnitId:_,link:j}})),await o.sequenceExecuteAsync(N,e)?(n.pushUndoRedo({redoMutations:N,undoMutations:O,unitID:h}),!0):!1}},_e={type:o.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(i,t)=>{var h,_,y,v;if(!t)return!1;const{documentId:e,payload:n,id:r}=t,s=i.get(o.IUniverInstanceService),a=i.get(o.ICommandService),d=s.getUnit(e,o.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(_=(h=d.getBody())==null?void 0:h.customRanges)==null?void 0:_.find(M=>M.rangeId===r);if(!c)return!1;const l=(y=t.payload.display)!=null?y:"",p=o.generateRandomId(),m=(v=o.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:v[0];m&&(m.ed=l.length+1);const f=Z.replaceSelectionFactory(i,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:p,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:m?[m]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return f?a.syncExecuteCommand(f.id,f.params):!1}};var Fe=Object.defineProperty,Ke=Object.getOwnPropertyDescriptor,ze=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ke(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Fe(t,e,r),r},Ge=(i,t)=>(e,n)=>t(e,n,i);let X=class extends o.Disposable{constructor(i){super(),this._commandService=i,this._registerCommands()}_registerCommands(){[ue,fe,ge,_e,me,he,w,F,E,K,B].forEach(i=>{this._commandService.registerCommand(i)})}};X=ze([Ge(0,o.ICommandService)],X);var Ye=Object.defineProperty,qe=Object.getOwnPropertyDescriptor,Je=(i,t,e,n)=>{for(var r=n>1?void 0:n?qe(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Ye(t,e,r),r},re=(i,t)=>(e,n)=>t(e,n,i);exports.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${L.SHEET}=${e}${n?`&${typeof n=="string"?L.DEFINE_NAME:L.RANGE}=${typeof n=="string"?n:U.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,r,s;if(t.startsWith("#")){const a=new URLSearchParams(t.slice(1)),d={gid:(e=a.get("gid"))!=null?e:"",range:(n=a.get("range"))!=null?n:"",rangeid:(r=a.get("rangeid"))!=null?r:"",unitid:(s=a.get("unitid"))!=null?s:""},c=this._getURLName(d);return{type:c.type,name:c.name,url:t,searchObj:d}}else return{type:L.URL,name:t,url:t,searchObj:null}}_getURLName(t){var p;const{gid:e,range:n,rangeid:r,unitid:s}=t,a=s?this._univerInstanceService.getUnit(s,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),d={type:L.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!a)return d;const c=e?a.getSheetBySheetId(e):a.getActiveSheet(),l=(p=c==null?void 0:c.getName())!=null?p:"";if(n){if(!c)return d;const u=U.deserializeRangeWithSheet(n).range;return o.isValidRange(u,c)&&n!==x?{type:L.RANGE,name:U.serializeRangeWithSheet(l,u)}:d}if(r){const u=this._definedNamesService.getValueById(a.getUnitId(),r);return u?{type:L.DEFINE_NAME,name:u.formulaOrRefString}:d}if(e){const u=a.getSheetBySheetId(e);return u?{type:L.SHEET,name:u.getName()}:d}return d}};exports.SheetsHyperLinkParserService=Je([re(0,o.IUniverInstanceService),re(1,o.Inject(o.LocaleService)),re(2,U.IDefinedNamesService)],exports.SheetsHyperLinkParserService);var ye=Object.defineProperty,Xe=Object.getOwnPropertyDescriptor,Ze=(i,t,e)=>t in i?ye(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,Qe=(i,t,e,n)=>{for(var r=n>1?void 0:n?Xe(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&ye(t,e,r),r},ce=(i,t)=>(e,n)=>t(e,n,i),ve=(i,t,e)=>Ze(i,typeof t!="symbol"?t+"":t,e);exports.UniverSheetsHyperLinkPlugin=class extends o.Plugin{constructor(t=oe,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...r}=o.merge({},oe,this._config);this._configService.setConfig(Ee,r)}onStarting(){o.registerDependencies(this._injector,[[exports.HyperLinkModel],[exports.SheetsHyperLinkParserService],[J],[X],[z],[q],[G],[Y]]),o.touchDependencies(this._injector,[[z],[J],[X],[q],[G],[Y]])}};ve(exports.UniverSheetsHyperLinkPlugin,"pluginName",le);ve(exports.UniverSheetsHyperLinkPlugin,"type",o.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsHyperLinkPlugin=Qe([o.DependentOn(g.UniverSheetsPlugin),ce(1,o.Inject(o.Injector)),ce(2,o.IConfigService)],exports.UniverSheetsHyperLinkPlugin);exports.AddHyperLinkCommand=ue;exports.AddHyperLinkMutation=w;exports.AddRichHyperLinkCommand=he;exports.CancelHyperLinkCommand=ge;exports.CancelRichHyperLinkCommand=me;exports.ERROR_RANGE=x;exports.RemoveHyperLinkMutation=E;exports.SheetHyperLinkType=L;exports.UpdateHyperLinkCommand=fe;exports.UpdateHyperLinkMutation=F;exports.UpdateHyperLinkRefMutation=K;exports.UpdateRichHyperLinkCommand=_e;
|
package/lib/es/facade.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { FWorkbook as l, FRange as h } from "@univerjs/sheets/facade";
|
|
2
2
|
import { SheetsHyperLinkParserService as m, AddHyperLinkCommand as k, UpdateHyperLinkCommand as y, CancelHyperLinkCommand as I } from "@univerjs/sheets-hyper-link";
|
|
3
|
-
import { generateRandomId as
|
|
3
|
+
import { generateRandomId as g, CustomRangeType as _, DataStreamTreeTokenType as c } from "@univerjs/core";
|
|
4
4
|
class S extends l {
|
|
5
5
|
createSheetHyperlink(e, t) {
|
|
6
6
|
return this._injector.get(m).buildHyperLink(this.getId(), e, t);
|
|
@@ -17,13 +17,6 @@ class S extends l {
|
|
|
17
17
|
l.extend(S);
|
|
18
18
|
class x extends h {
|
|
19
19
|
// #region hyperlink
|
|
20
|
-
/**
|
|
21
|
-
* Set hyperlink in the cell in the range.
|
|
22
|
-
* [!important] This method is async.
|
|
23
|
-
* @param url url
|
|
24
|
-
* @param label optional, label of the url
|
|
25
|
-
* @returns success or not
|
|
26
|
-
*/
|
|
27
20
|
setHyperLink(e, t) {
|
|
28
21
|
const n = {
|
|
29
22
|
unitId: this.getUnitId(),
|
|
@@ -33,7 +26,7 @@ class x extends h {
|
|
|
33
26
|
column: this._range.startColumn,
|
|
34
27
|
payload: e,
|
|
35
28
|
display: t,
|
|
36
|
-
id:
|
|
29
|
+
id: g()
|
|
37
30
|
}
|
|
38
31
|
};
|
|
39
32
|
return this._commandService.executeCommand(k.id, n);
|
|
@@ -45,10 +38,10 @@ class x extends h {
|
|
|
45
38
|
getHyperLinks() {
|
|
46
39
|
var t, n, i;
|
|
47
40
|
const e = this._worksheet.getCellRaw(this._range.startRow, this._range.startColumn);
|
|
48
|
-
return e != null && e.p ? (i = (n = (t = e.p.body) == null ? void 0 : t.customRanges) == null ? void 0 : n.filter((r) => r.rangeType ===
|
|
41
|
+
return e != null && e.p ? (i = (n = (t = e.p.body) == null ? void 0 : t.customRanges) == null ? void 0 : n.filter((r) => r.rangeType === _.HYPERLINK).map((r) => {
|
|
49
42
|
var s, a, o, d, p;
|
|
50
43
|
return {
|
|
51
|
-
id: `${r.rangeId}
|
|
44
|
+
id: `${r.rangeId}`,
|
|
52
45
|
startIndex: r.startIndex,
|
|
53
46
|
endIndex: r.endIndex,
|
|
54
47
|
url: (a = (s = r.properties) == null ? void 0 : s.url) != null ? a : "",
|
package/lib/es/index.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var w = (s, e, t) =>
|
|
4
|
-
import { Disposable as V, ObjectMatrix as q, UniverInstanceType as I, IUniverInstanceService as E, CommandType as L, CustomRangeType as b, Inject as M, ICommandService as P, sequenceExecuteAsync as ve, isValidRange as Re, toDisposable as
|
|
5
|
-
import { Subject as
|
|
6
|
-
import { getSheetCommandTarget as j, RefRangeService as
|
|
7
|
-
import { deserializeRangeWithSheet as Ce, serializeRange as B, serializeRangeWithSheet as
|
|
8
|
-
import { addCustomRangeBySelectionFactory as
|
|
9
|
-
var
|
|
10
|
-
for (var r = n > 1 ? void 0 : n ?
|
|
1
|
+
var Ae = Object.defineProperty;
|
|
2
|
+
var We = (s, e, t) => e in s ? Ae(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
3
|
+
var w = (s, e, t) => We(s, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { Disposable as V, ObjectMatrix as q, UniverInstanceType as I, IUniverInstanceService as E, CommandType as L, CustomRangeType as b, Inject as M, ICommandService as P, sequenceExecuteAsync as ve, isValidRange as Re, toDisposable as Be, DisposableCollection as je, Rectangle as Fe, Range as Ke, Tools as oe, BuildTextUtils as Z, generateRandomId as de, TextX as ce, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as Ye, IResourceManagerService as Ge, IUndoRedoService as Se, CellValueType as Ie, sequenceExecute as ze, getBodySlice as Ne, LocaleService as Je, DependentOn as Xe, Injector as qe, Plugin as Ze, merge as Qe, registerDependencies as et, touchDependencies as tt, IConfigService as nt } from "@univerjs/core";
|
|
5
|
+
import { Subject as rt } from "rxjs";
|
|
6
|
+
import { getSheetCommandTarget as j, RefRangeService as Oe, SheetsSelectionsService as ke, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as st, handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests as it, SheetInterceptorService as le, RemoveSheetCommand as at, handleDefaultRangeChangeWithEffectRefCommands as ot, SetRangeValuesMutation as H, SetRangeValuesCommand as dt, ClearSelectionContentCommand as ct, ClearSelectionAllCommand as lt, ClearSelectionFormatCommand as ut, AFTER_CELL_EDIT as pt, SetRangeValuesUndoMutationFactory as Me, UniverSheetsPlugin as ht } from "@univerjs/sheets";
|
|
7
|
+
import { deserializeRangeWithSheet as Ce, serializeRange as B, serializeRangeWithSheet as gt, IDefinedNamesService as ft } from "@univerjs/engine-formula";
|
|
8
|
+
import { addCustomRangeBySelectionFactory as _t, deleteCustomRangeFactory as mt, replaceSelectionFactory as De } from "@univerjs/docs";
|
|
9
|
+
var yt = Object.defineProperty, vt = Object.getOwnPropertyDescriptor, Rt = (s, e, t, n) => {
|
|
10
|
+
for (var r = n > 1 ? void 0 : n ? vt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
|
|
11
11
|
(a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
|
|
12
|
-
return n && r &&
|
|
13
|
-
},
|
|
12
|
+
return n && r && yt(e, t, r), r;
|
|
13
|
+
}, St = (s, e) => (t, n) => e(t, n, s);
|
|
14
14
|
let S = class extends V {
|
|
15
15
|
constructor(e) {
|
|
16
16
|
super();
|
|
17
|
-
w(this, "_linkUpdate$", new
|
|
17
|
+
w(this, "_linkUpdate$", new rt());
|
|
18
18
|
w(this, "linkUpdate$", this._linkUpdate$.asObservable());
|
|
19
19
|
w(this, "_linkMap", /* @__PURE__ */ new Map());
|
|
20
20
|
w(this, "_linkPositionMap", /* @__PURE__ */ new Map());
|
|
@@ -137,11 +137,11 @@ let S = class extends V {
|
|
|
137
137
|
return Array.from(this._linkMap.keys()).map((t) => this.getUnit(t));
|
|
138
138
|
}
|
|
139
139
|
};
|
|
140
|
-
S =
|
|
141
|
-
|
|
140
|
+
S = Rt([
|
|
141
|
+
St(0, E)
|
|
142
142
|
], S);
|
|
143
143
|
var U = /* @__PURE__ */ ((s) => (s.SHEET = "gid", s.RANGE = "range", s.DEFINE_NAME = "rangeid", s.INVALID = "invalid", s.URL = "url", s))(U || {});
|
|
144
|
-
const
|
|
144
|
+
const It = "sheets-hyper-link.config", Ue = {}, O = {
|
|
145
145
|
type: L.MUTATION,
|
|
146
146
|
id: "sheets.mutation.add-hyper-link",
|
|
147
147
|
handler(s, e) {
|
|
@@ -187,14 +187,14 @@ const Rt = "sheets-hyper-link.config", St = {}, O = {
|
|
|
187
187
|
const { unitId: t, subUnitId: n, row: r, col: i, id: a, url: o } = e, c = s.get(E), d = j(c, { unitId: t, subUnitId: n });
|
|
188
188
|
if (!d)
|
|
189
189
|
return !1;
|
|
190
|
-
const { worksheet: l } = d, u = l.getCellRaw(r, i), h = (f = (p = (g = u == null ? void 0 : u.p) == null ? void 0 : g.body) == null ? void 0 : p.customRanges) == null ? void 0 : f.find((
|
|
190
|
+
const { worksheet: l } = d, u = l.getCellRaw(r, i), h = (f = (p = (g = u == null ? void 0 : u.p) == null ? void 0 : g.body) == null ? void 0 : p.customRanges) == null ? void 0 : f.find((_) => _.rangeType === b.HYPERLINK && _.rangeId === a);
|
|
191
191
|
return h && (h.properties.url = o), !0;
|
|
192
192
|
}
|
|
193
|
-
},
|
|
194
|
-
var
|
|
195
|
-
for (var r = n > 1 ? void 0 : n ?
|
|
193
|
+
}, He = "SHEET_HYPER_LINK_PLUGIN", Q = "err";
|
|
194
|
+
var Mt = Object.defineProperty, Ct = Object.getOwnPropertyDescriptor, wt = (s, e, t, n) => {
|
|
195
|
+
for (var r = n > 1 ? void 0 : n ? Ct(e, t) : e, i = s.length - 1, a; i >= 0; i--)
|
|
196
196
|
(a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
|
|
197
|
-
return n && r &&
|
|
197
|
+
return n && r && Mt(e, t, r), r;
|
|
198
198
|
}, z = (s, e) => (t, n) => e(t, n, s);
|
|
199
199
|
let ee = class extends V {
|
|
200
200
|
constructor(e, t, n, r) {
|
|
@@ -261,7 +261,7 @@ let ee = class extends V {
|
|
|
261
261
|
startRow: n.row,
|
|
262
262
|
endRow: n.row
|
|
263
263
|
}, a = (o) => {
|
|
264
|
-
const c =
|
|
264
|
+
const c = st(i, o, { selectionManagerService: this._selectionManagerService }), d = Array.isArray(c) ? c[0] : c;
|
|
265
265
|
return d && d.startColumn === i.startColumn && d.startRow === i.startRow ? {
|
|
266
266
|
undos: [],
|
|
267
267
|
redos: []
|
|
@@ -304,7 +304,7 @@ let ee = class extends V {
|
|
|
304
304
|
const l = d.gid, u = Ce(d.range).range;
|
|
305
305
|
if (Re(u) && d.range !== Q) {
|
|
306
306
|
const h = (g) => {
|
|
307
|
-
const p =
|
|
307
|
+
const p = it(u, g, { selectionManagerService: this._selectionManagerService });
|
|
308
308
|
return p && B(p) === B(u) ? {
|
|
309
309
|
redos: [],
|
|
310
310
|
undos: []
|
|
@@ -395,23 +395,23 @@ let ee = class extends V {
|
|
|
395
395
|
}
|
|
396
396
|
}
|
|
397
397
|
})
|
|
398
|
-
), this.disposeWithMe(
|
|
398
|
+
), this.disposeWithMe(Be(() => {
|
|
399
399
|
this._disposableMap.forEach((e) => {
|
|
400
400
|
e.dispose();
|
|
401
401
|
}), this._disposableMap.clear();
|
|
402
402
|
}));
|
|
403
403
|
}
|
|
404
404
|
};
|
|
405
|
-
ee =
|
|
406
|
-
z(0, M(
|
|
405
|
+
ee = wt([
|
|
406
|
+
z(0, M(Oe)),
|
|
407
407
|
z(1, M(S)),
|
|
408
|
-
z(2, M(
|
|
408
|
+
z(2, M(ke)),
|
|
409
409
|
z(3, P)
|
|
410
410
|
], ee);
|
|
411
|
-
var
|
|
412
|
-
for (var r = n > 1 ? void 0 : n ?
|
|
411
|
+
var Et = Object.defineProperty, Lt = Object.getOwnPropertyDescriptor, Ut = (s, e, t, n) => {
|
|
412
|
+
for (var r = n > 1 ? void 0 : n ? Lt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
|
|
413
413
|
(a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
|
|
414
|
-
return n && r &&
|
|
414
|
+
return n && r && Et(e, t, r), r;
|
|
415
415
|
}, he = (s, e) => (t, n) => e(t, n, s);
|
|
416
416
|
let te = class extends V {
|
|
417
417
|
constructor(s, e, t) {
|
|
@@ -422,7 +422,7 @@ let te = class extends V {
|
|
|
422
422
|
this._sheetInterceptorService.interceptCommand({
|
|
423
423
|
getMutations: (s) => {
|
|
424
424
|
var e;
|
|
425
|
-
if (s.id ===
|
|
425
|
+
if (s.id === at.id) {
|
|
426
426
|
const t = s.params, n = t.unitId ? this._univerInstanceService.getUnit(t.unitId) : this._univerInstanceService.getCurrentUnitForType(I.UNIVER_SHEET);
|
|
427
427
|
if (!n)
|
|
428
428
|
return { redos: [], undos: [] };
|
|
@@ -452,15 +452,15 @@ let te = class extends V {
|
|
|
452
452
|
);
|
|
453
453
|
}
|
|
454
454
|
};
|
|
455
|
-
te =
|
|
455
|
+
te = Ut([
|
|
456
456
|
he(0, M(le)),
|
|
457
457
|
he(1, E),
|
|
458
458
|
he(2, M(S))
|
|
459
459
|
], te);
|
|
460
|
-
var
|
|
461
|
-
for (var r = n > 1 ? void 0 : n ?
|
|
460
|
+
var bt = Object.defineProperty, Pt = Object.getOwnPropertyDescriptor, Nt = (s, e, t, n) => {
|
|
461
|
+
for (var r = n > 1 ? void 0 : n ? Pt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
|
|
462
462
|
(a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
|
|
463
|
-
return n && r &&
|
|
463
|
+
return n && r && bt(e, t, r), r;
|
|
464
464
|
}, ge = (s, e) => (t, n) => e(t, n, s);
|
|
465
465
|
let ne = class extends V {
|
|
466
466
|
constructor(e, t, n) {
|
|
@@ -506,20 +506,20 @@ let ne = class extends V {
|
|
|
506
506
|
var h;
|
|
507
507
|
return u.rangeType === b.HYPERLINK && this._isLegalRangeUrl(e, (h = u.properties) == null ? void 0 : h.url);
|
|
508
508
|
})) {
|
|
509
|
-
const u = new
|
|
509
|
+
const u = new je();
|
|
510
510
|
let h = !1;
|
|
511
511
|
(l = (d = i.body) == null ? void 0 : d.customRanges) == null || l.forEach((g) => {
|
|
512
512
|
var p;
|
|
513
513
|
if (g.rangeType === b.HYPERLINK) {
|
|
514
|
-
const f = (p = g.properties) == null ? void 0 : p.url,
|
|
515
|
-
if (
|
|
516
|
-
const { range:
|
|
514
|
+
const f = (p = g.properties) == null ? void 0 : p.url, _ = this._isLegalRangeUrl(e, f);
|
|
515
|
+
if (_) {
|
|
516
|
+
const { range: m, worksheet: C } = _;
|
|
517
517
|
h = !0, u.add(
|
|
518
518
|
this._refRangeService.registerRefRange(
|
|
519
|
-
|
|
520
|
-
(
|
|
521
|
-
const v =
|
|
522
|
-
return v &&
|
|
519
|
+
m,
|
|
520
|
+
(y) => {
|
|
521
|
+
const v = ot(m, y);
|
|
522
|
+
return v && Fe.equals(v, m) ? {
|
|
523
523
|
preRedos: [],
|
|
524
524
|
preUndos: [],
|
|
525
525
|
redos: [],
|
|
@@ -615,15 +615,15 @@ let ne = class extends V {
|
|
|
615
615
|
);
|
|
616
616
|
}
|
|
617
617
|
};
|
|
618
|
-
ne =
|
|
618
|
+
ne = Nt([
|
|
619
619
|
ge(0, P),
|
|
620
620
|
ge(1, E),
|
|
621
|
-
ge(2, M(
|
|
621
|
+
ge(2, M(Oe))
|
|
622
622
|
], ne);
|
|
623
|
-
var
|
|
624
|
-
for (var r = n > 1 ? void 0 : n ?
|
|
623
|
+
var Ot = Object.defineProperty, kt = Object.getOwnPropertyDescriptor, Dt = (s, e, t, n) => {
|
|
624
|
+
for (var r = n > 1 ? void 0 : n ? kt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
|
|
625
625
|
(a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
|
|
626
|
-
return n && r &&
|
|
626
|
+
return n && r && Ot(e, t, r), r;
|
|
627
627
|
}, J = (s, e) => (t, n) => e(t, n, s);
|
|
628
628
|
let re = class extends V {
|
|
629
629
|
constructor(s, e, t, n) {
|
|
@@ -635,7 +635,7 @@ let re = class extends V {
|
|
|
635
635
|
_initSetRangeValuesCommandInterceptor() {
|
|
636
636
|
this.disposeWithMe(this._sheetInterceptorService.interceptCommand({
|
|
637
637
|
getMutations: (s) => {
|
|
638
|
-
if (s.id ===
|
|
638
|
+
if (s.id === dt.id) {
|
|
639
639
|
const e = s.params, { unitId: t, subUnitId: n } = e, r = [], i = [];
|
|
640
640
|
return e.cellValue && new q(e.cellValue).forValue((a, o) => {
|
|
641
641
|
const c = this._hyperLinkModel.getHyperLinkByLocation(t, n, a, o);
|
|
@@ -669,11 +669,11 @@ let re = class extends V {
|
|
|
669
669
|
_initClearSelectionCommandInterceptor() {
|
|
670
670
|
this.disposeWithMe(this._sheetInterceptorService.interceptCommand({
|
|
671
671
|
getMutations: (s) => {
|
|
672
|
-
if (s.id ===
|
|
672
|
+
if (s.id === ct.id || s.id === lt.id || s.id === ut.id) {
|
|
673
673
|
const e = [], t = [], n = this._selectionManagerService.getCurrentLastSelection(), r = j(this._univerInstanceService);
|
|
674
674
|
if (n && r) {
|
|
675
675
|
const { unitId: i, subUnitId: a } = r;
|
|
676
|
-
|
|
676
|
+
Ke.foreach(n.range, (o, c) => {
|
|
677
677
|
const d = this._hyperLinkModel.getHyperLinkByLocation(i, a, o, c);
|
|
678
678
|
d && (e.push({
|
|
679
679
|
id: k.id,
|
|
@@ -705,7 +705,7 @@ let re = class extends V {
|
|
|
705
705
|
}));
|
|
706
706
|
}
|
|
707
707
|
_initAfterEditor() {
|
|
708
|
-
this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(
|
|
708
|
+
this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(pt, {
|
|
709
709
|
handler: (s, e, t) => {
|
|
710
710
|
if (!s || s.p)
|
|
711
711
|
return t(s);
|
|
@@ -742,7 +742,7 @@ let re = class extends V {
|
|
|
742
742
|
return ce.apply(d, c.serialize()), t({
|
|
743
743
|
...s,
|
|
744
744
|
p: {
|
|
745
|
-
id:
|
|
745
|
+
id: Ye,
|
|
746
746
|
body: d,
|
|
747
747
|
documentStyle: {
|
|
748
748
|
pageSize: {
|
|
@@ -758,17 +758,17 @@ let re = class extends V {
|
|
|
758
758
|
}));
|
|
759
759
|
}
|
|
760
760
|
};
|
|
761
|
-
re =
|
|
761
|
+
re = Dt([
|
|
762
762
|
J(0, M(le)),
|
|
763
763
|
J(1, M(S)),
|
|
764
|
-
J(2, M(
|
|
764
|
+
J(2, M(ke)),
|
|
765
765
|
J(3, E)
|
|
766
766
|
], re);
|
|
767
|
-
var
|
|
768
|
-
for (var r = n > 1 ? void 0 : n ?
|
|
767
|
+
var Ve = /* @__PURE__ */ ((s) => (s[s.UNIVER_UNKNOWN = 0] = "UNIVER_UNKNOWN", s[s.UNIVER_DOC = 1] = "UNIVER_DOC", s[s.UNIVER_SHEET = 2] = "UNIVER_SHEET", s[s.UNIVER_SLIDE = 3] = "UNIVER_SLIDE", s[s.UNIVER_PROJECT = 4] = "UNIVER_PROJECT", s[s.UNRECOGNIZED = -1] = "UNRECOGNIZED", s))(Ve || {}), Ht = Object.defineProperty, Vt = Object.getOwnPropertyDescriptor, $t = (s, e, t, n) => {
|
|
768
|
+
for (var r = n > 1 ? void 0 : n ? Vt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
|
|
769
769
|
(a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
|
|
770
|
-
return n && r &&
|
|
771
|
-
},
|
|
770
|
+
return n && r && Ht(e, t, r), r;
|
|
771
|
+
}, be = (s, e) => (t, n) => e(t, n, s);
|
|
772
772
|
let se = class extends V {
|
|
773
773
|
constructor(s, e) {
|
|
774
774
|
super(), this._resourceManagerService = s, this._hyperLinkModel = e, this._initSnapshot();
|
|
@@ -790,8 +790,8 @@ let se = class extends V {
|
|
|
790
790
|
};
|
|
791
791
|
this.disposeWithMe(
|
|
792
792
|
this._resourceManagerService.registerPluginResource({
|
|
793
|
-
pluginName:
|
|
794
|
-
businesses: [
|
|
793
|
+
pluginName: He,
|
|
794
|
+
businesses: [Ve.UNIVER_SHEET],
|
|
795
795
|
toJson: (t) => s(t),
|
|
796
796
|
parseJson: (t) => e(t),
|
|
797
797
|
onUnLoad: (t) => {
|
|
@@ -808,11 +808,11 @@ let se = class extends V {
|
|
|
808
808
|
);
|
|
809
809
|
}
|
|
810
810
|
};
|
|
811
|
-
se =
|
|
812
|
-
|
|
813
|
-
|
|
811
|
+
se = $t([
|
|
812
|
+
be(0, Ge),
|
|
813
|
+
be(1, M(S))
|
|
814
814
|
], se);
|
|
815
|
-
const
|
|
815
|
+
const xt = {
|
|
816
816
|
type: L.COMMAND,
|
|
817
817
|
id: "sheets.command.add-hyper-link",
|
|
818
818
|
// eslint-disable-next-line max-lines-per-function
|
|
@@ -820,14 +820,14 @@ const $t = {
|
|
|
820
820
|
if (!e) return !1;
|
|
821
821
|
const t = s.get(P), n = s.get(Se), r = s.get(E), i = s.get(S), a = s.get(le), o = j(r, e);
|
|
822
822
|
if (!o) return !1;
|
|
823
|
-
const { unitId: c, subUnitId: d, workbook: l, worksheet: u } = o, { link: h } = e, { payload: g, display: p, row: f, column:
|
|
823
|
+
const { unitId: c, subUnitId: d, workbook: l, worksheet: u } = o, { link: h } = e, { payload: g, display: p, row: f, column: _, id: m } = h, C = u.getCell(f, _), y = u.getBlankCellDocumentModel(C), v = y.documentModel.getSnapshot(), R = oe.deepClone(v.body);
|
|
824
824
|
if (!R) return !1;
|
|
825
825
|
let N;
|
|
826
826
|
if (p ? N = Z.selection.replace({
|
|
827
827
|
selection: {
|
|
828
828
|
startOffset: 0,
|
|
829
829
|
endOffset: R.dataStream.length - 2,
|
|
830
|
-
collapsed:
|
|
830
|
+
collapsed: R.dataStream.length - 2 === 0
|
|
831
831
|
},
|
|
832
832
|
body: {
|
|
833
833
|
dataStream: `${p}`,
|
|
@@ -835,22 +835,22 @@ const $t = {
|
|
|
835
835
|
startIndex: 0,
|
|
836
836
|
endIndex: p.length - 1,
|
|
837
837
|
rangeType: b.HYPERLINK,
|
|
838
|
-
rangeId:
|
|
838
|
+
rangeId: m,
|
|
839
839
|
properties: {
|
|
840
840
|
url: g
|
|
841
841
|
// refId: id,
|
|
842
842
|
}
|
|
843
843
|
}]
|
|
844
844
|
},
|
|
845
|
-
doc:
|
|
845
|
+
doc: y.documentModel
|
|
846
846
|
}) : N = Z.customRange.add({
|
|
847
847
|
body: R,
|
|
848
848
|
ranges: [{ startOffset: 0, endOffset: R.dataStream.length - 2, collapsed: !1 }],
|
|
849
|
-
rangeId:
|
|
849
|
+
rangeId: m,
|
|
850
850
|
rangeType: b.HYPERLINK,
|
|
851
851
|
properties: {
|
|
852
852
|
url: g,
|
|
853
|
-
refId:
|
|
853
|
+
refId: m
|
|
854
854
|
}
|
|
855
855
|
}), !N) return !1;
|
|
856
856
|
const F = ce.apply(R, N.serialize()), D = {
|
|
@@ -859,7 +859,7 @@ const $t = {
|
|
|
859
859
|
body: F
|
|
860
860
|
},
|
|
861
861
|
t: Ie.STRING
|
|
862
|
-
}, x = await a.onWriteCell(l, u, f,
|
|
862
|
+
}, x = await a.onWriteCell(l, u, f, _, D), T = {
|
|
863
863
|
unitId: c,
|
|
864
864
|
subUnitId: d,
|
|
865
865
|
cellValue: {
|
|
@@ -873,7 +873,7 @@ const $t = {
|
|
|
873
873
|
}, Y = Me(s, T), pe = {
|
|
874
874
|
id: H.id,
|
|
875
875
|
params: Y
|
|
876
|
-
}, K = [ue], A = [pe], W = i.getHyperLinkByLocation(c, d, f,
|
|
876
|
+
}, K = [ue], A = [pe], W = i.getHyperLinkByLocation(c, d, f, _);
|
|
877
877
|
return W && (K.push({
|
|
878
878
|
id: k.id,
|
|
879
879
|
params: {
|
|
@@ -894,13 +894,13 @@ const $t = {
|
|
|
894
894
|
unitID: c
|
|
895
895
|
}), !0) : !1;
|
|
896
896
|
}
|
|
897
|
-
},
|
|
897
|
+
}, Tt = {
|
|
898
898
|
id: "sheets.command.add-rich-hyper-link",
|
|
899
899
|
type: L.COMMAND,
|
|
900
900
|
handler: async (s, e) => {
|
|
901
901
|
if (!e)
|
|
902
902
|
return !1;
|
|
903
|
-
const { documentId: t, link: n } = e, r = s.get(P), i = de(), { payload: a } = n, o =
|
|
903
|
+
const { documentId: t, link: n } = e, r = s.get(P), i = de(), { payload: a } = n, o = _t(s, {
|
|
904
904
|
unitId: t,
|
|
905
905
|
rangeId: i,
|
|
906
906
|
rangeType: b.HYPERLINK,
|
|
@@ -911,7 +911,7 @@ const $t = {
|
|
|
911
911
|
});
|
|
912
912
|
return o ? r.syncExecuteCommand(o.id, o.params) : !1;
|
|
913
913
|
}
|
|
914
|
-
},
|
|
914
|
+
}, At = {
|
|
915
915
|
type: L.COMMAND,
|
|
916
916
|
id: "sheets.command.cancel-hyper-link",
|
|
917
917
|
// eslint-disable-next-line max-lines-per-function
|
|
@@ -924,11 +924,11 @@ const $t = {
|
|
|
924
924
|
if (!g) return !1;
|
|
925
925
|
const p = h.getCellDocumentModelWithFormula(g);
|
|
926
926
|
if (!(p != null && p.documentModel)) return !1;
|
|
927
|
-
const f = oe.deepClone(p.documentModel.getSnapshot());
|
|
928
|
-
if (!((x = (D = f.body) == null ? void 0 : D.customRanges) == null ? void 0 : x.find((T) => T.rangeId === d))) return !1;
|
|
929
|
-
const _ = Z.customRange.delete(s, { documentDataModel: p.documentModel, rangeId: d });
|
|
927
|
+
const f = oe.deepClone(p.documentModel.getSnapshot()), _ = (x = (D = f.body) == null ? void 0 : D.customRanges) == null ? void 0 : x.find((T) => `${T.rangeId}` === d);
|
|
930
928
|
if (!_) return !1;
|
|
931
|
-
const
|
|
929
|
+
const m = Z.customRange.delete(s, { documentDataModel: p.documentModel, rangeId: _.rangeId });
|
|
930
|
+
if (!m) return !1;
|
|
931
|
+
const C = ce.apply(f.body, m.serialize()), y = [], v = [], R = {
|
|
932
932
|
unitId: l,
|
|
933
933
|
subUnitId: u,
|
|
934
934
|
cellValue: {
|
|
@@ -943,7 +943,7 @@ const $t = {
|
|
|
943
943
|
}
|
|
944
944
|
}
|
|
945
945
|
};
|
|
946
|
-
|
|
946
|
+
y.push({
|
|
947
947
|
id: H.id,
|
|
948
948
|
params: R
|
|
949
949
|
});
|
|
@@ -953,7 +953,7 @@ const $t = {
|
|
|
953
953
|
params: N
|
|
954
954
|
});
|
|
955
955
|
const F = i.getHyperLinkByLocation(l, u, o, c);
|
|
956
|
-
return F && (
|
|
956
|
+
return F && (y.push({
|
|
957
957
|
id: k.id,
|
|
958
958
|
params: {
|
|
959
959
|
unitId: l,
|
|
@@ -969,13 +969,13 @@ const $t = {
|
|
|
969
969
|
...F
|
|
970
970
|
}
|
|
971
971
|
}
|
|
972
|
-
})),
|
|
973
|
-
redoMutations:
|
|
972
|
+
})), ze(y, t).result ? (n.pushUndoRedo({
|
|
973
|
+
redoMutations: y,
|
|
974
974
|
undoMutations: v,
|
|
975
975
|
unitID: l
|
|
976
976
|
}), !0) : !1;
|
|
977
977
|
}
|
|
978
|
-
},
|
|
978
|
+
}, Wt = {
|
|
979
979
|
type: L.COMMAND,
|
|
980
980
|
id: "sheets.command.cancel-rich-hyper-link",
|
|
981
981
|
handler(s, e) {
|
|
@@ -987,10 +987,10 @@ const $t = {
|
|
|
987
987
|
o && o.endIndex === a.getBody().dataStream.length - 3 && (c = {
|
|
988
988
|
dataStream: " "
|
|
989
989
|
});
|
|
990
|
-
const d =
|
|
990
|
+
const d = mt(s, { unitId: n, rangeId: t, insert: c });
|
|
991
991
|
return d ? r.syncExecuteCommand(d.id, d.params) : !1;
|
|
992
992
|
}
|
|
993
|
-
},
|
|
993
|
+
}, Bt = {
|
|
994
994
|
type: L.COMMAND,
|
|
995
995
|
id: "sheets.command.update-hyper-link",
|
|
996
996
|
// eslint-disable-next-line max-lines-per-function
|
|
@@ -1002,25 +1002,25 @@ const $t = {
|
|
|
1002
1002
|
subUnitId: e.subUnitId
|
|
1003
1003
|
});
|
|
1004
1004
|
if (!o) return !1;
|
|
1005
|
-
const { payload: c, row: d, column: l, id: u } = e, { workbook: h, worksheet: g, unitId: p, subUnitId: f } = o, { payload:
|
|
1005
|
+
const { payload: c, row: d, column: l, id: u } = e, { workbook: h, worksheet: g, unitId: p, subUnitId: f } = o, { payload: _, display: m = "" } = c, C = g.getCell(d, l);
|
|
1006
1006
|
if (!C) return !1;
|
|
1007
|
-
const
|
|
1008
|
-
if (!(
|
|
1009
|
-
const v =
|
|
1007
|
+
const y = g.getCellDocumentModelWithFormula(C);
|
|
1008
|
+
if (!(y != null && y.documentModel)) return !1;
|
|
1009
|
+
const v = y.documentModel.getSnapshot(), R = (Ee = (we = v.body) == null ? void 0 : we.customRanges) == null ? void 0 : Ee.find((Te) => `${Te.rangeId}` === u);
|
|
1010
1010
|
if (!R) return !1;
|
|
1011
|
-
const N = de(), $ = (Le =
|
|
1012
|
-
$ && ($.ed =
|
|
1013
|
-
const D =
|
|
1011
|
+
const N = de(), $ = (Le = Ne(y.documentModel.getBody(), R.startIndex, R.endIndex + 1).textRuns) == null ? void 0 : Le[0];
|
|
1012
|
+
$ && ($.ed = m.length + 1);
|
|
1013
|
+
const D = De(s, {
|
|
1014
1014
|
unitId: p,
|
|
1015
1015
|
body: {
|
|
1016
|
-
dataStream: `${
|
|
1016
|
+
dataStream: `${m}`,
|
|
1017
1017
|
customRanges: [{
|
|
1018
1018
|
rangeId: N,
|
|
1019
1019
|
rangeType: b.HYPERLINK,
|
|
1020
1020
|
startIndex: 0,
|
|
1021
|
-
endIndex:
|
|
1021
|
+
endIndex: m.length - 1,
|
|
1022
1022
|
properties: {
|
|
1023
|
-
url:
|
|
1023
|
+
url: _
|
|
1024
1024
|
}
|
|
1025
1025
|
}],
|
|
1026
1026
|
textRuns: $ ? [$] : void 0
|
|
@@ -1030,7 +1030,7 @@ const $t = {
|
|
|
1030
1030
|
endOffset: R.endIndex + 1,
|
|
1031
1031
|
collapsed: !1
|
|
1032
1032
|
},
|
|
1033
|
-
doc:
|
|
1033
|
+
doc: y.documentModel
|
|
1034
1034
|
});
|
|
1035
1035
|
if (!D)
|
|
1036
1036
|
return !1;
|
|
@@ -1075,11 +1075,11 @@ const $t = {
|
|
|
1075
1075
|
unitID: p
|
|
1076
1076
|
}), !0) : !1;
|
|
1077
1077
|
}
|
|
1078
|
-
},
|
|
1078
|
+
}, jt = {
|
|
1079
1079
|
type: L.COMMAND,
|
|
1080
1080
|
id: "sheets.command.update-rich-hyper-link",
|
|
1081
1081
|
handler: (s, e) => {
|
|
1082
|
-
var p, f,
|
|
1082
|
+
var p, f, _, m;
|
|
1083
1083
|
if (!e)
|
|
1084
1084
|
return !1;
|
|
1085
1085
|
const { documentId: t, payload: n, id: r } = e, i = s.get(E), a = s.get(P), o = i.getUnit(t, I.UNIVER_DOC);
|
|
@@ -1088,9 +1088,9 @@ const $t = {
|
|
|
1088
1088
|
const c = (f = (p = o.getBody()) == null ? void 0 : p.customRanges) == null ? void 0 : f.find((C) => C.rangeId === r);
|
|
1089
1089
|
if (!c)
|
|
1090
1090
|
return !1;
|
|
1091
|
-
const d = (
|
|
1091
|
+
const d = (_ = e.payload.display) != null ? _ : "", l = de(), h = (m = Ne(o.getBody(), c.startIndex, c.endIndex + 1).textRuns) == null ? void 0 : m[0];
|
|
1092
1092
|
h && (h.ed = d.length + 1);
|
|
1093
|
-
const g =
|
|
1093
|
+
const g = De(s, {
|
|
1094
1094
|
unitId: t,
|
|
1095
1095
|
body: {
|
|
1096
1096
|
dataStream: `${d}`,
|
|
@@ -1115,23 +1115,23 @@ const $t = {
|
|
|
1115
1115
|
return g ? a.syncExecuteCommand(g.id, g.params) : !1;
|
|
1116
1116
|
}
|
|
1117
1117
|
};
|
|
1118
|
-
var
|
|
1119
|
-
for (var r = n > 1 ? void 0 : n ?
|
|
1118
|
+
var Ft = Object.defineProperty, Kt = Object.getOwnPropertyDescriptor, Yt = (s, e, t, n) => {
|
|
1119
|
+
for (var r = n > 1 ? void 0 : n ? Kt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
|
|
1120
1120
|
(a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
|
|
1121
|
-
return n && r &&
|
|
1122
|
-
},
|
|
1121
|
+
return n && r && Ft(e, t, r), r;
|
|
1122
|
+
}, Gt = (s, e) => (t, n) => e(t, n, s);
|
|
1123
1123
|
let ie = class extends V {
|
|
1124
1124
|
constructor(s) {
|
|
1125
1125
|
super(), this._commandService = s, this._registerCommands();
|
|
1126
1126
|
}
|
|
1127
1127
|
_registerCommands() {
|
|
1128
1128
|
[
|
|
1129
|
-
|
|
1130
|
-
Wt,
|
|
1131
|
-
Tt,
|
|
1129
|
+
xt,
|
|
1132
1130
|
Bt,
|
|
1133
1131
|
At,
|
|
1134
|
-
|
|
1132
|
+
jt,
|
|
1133
|
+
Wt,
|
|
1134
|
+
Tt,
|
|
1135
1135
|
O,
|
|
1136
1136
|
_e,
|
|
1137
1137
|
k,
|
|
@@ -1142,13 +1142,13 @@ let ie = class extends V {
|
|
|
1142
1142
|
});
|
|
1143
1143
|
}
|
|
1144
1144
|
};
|
|
1145
|
-
ie =
|
|
1146
|
-
|
|
1145
|
+
ie = Yt([
|
|
1146
|
+
Gt(0, P)
|
|
1147
1147
|
], ie);
|
|
1148
|
-
var
|
|
1149
|
-
for (var r = n > 1 ? void 0 : n ?
|
|
1148
|
+
var zt = Object.defineProperty, Jt = Object.getOwnPropertyDescriptor, Xt = (s, e, t, n) => {
|
|
1149
|
+
for (var r = n > 1 ? void 0 : n ? Jt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
|
|
1150
1150
|
(a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
|
|
1151
|
-
return n && r &&
|
|
1151
|
+
return n && r && zt(e, t, r), r;
|
|
1152
1152
|
}, fe = (s, e) => (t, n) => e(t, n, s);
|
|
1153
1153
|
let ye = class {
|
|
1154
1154
|
constructor(s, e, t) {
|
|
@@ -1194,7 +1194,7 @@ let ye = class {
|
|
|
1194
1194
|
const l = Ce(t).range;
|
|
1195
1195
|
return Re(l, o) && t !== Q ? {
|
|
1196
1196
|
type: U.RANGE,
|
|
1197
|
-
name:
|
|
1197
|
+
name: gt(c, l)
|
|
1198
1198
|
} : a;
|
|
1199
1199
|
}
|
|
1200
1200
|
if (n) {
|
|
@@ -1214,24 +1214,28 @@ let ye = class {
|
|
|
1214
1214
|
return a;
|
|
1215
1215
|
}
|
|
1216
1216
|
};
|
|
1217
|
-
ye =
|
|
1217
|
+
ye = Xt([
|
|
1218
1218
|
fe(0, E),
|
|
1219
|
-
fe(1, M(
|
|
1220
|
-
fe(2,
|
|
1219
|
+
fe(1, M(Je)),
|
|
1220
|
+
fe(2, ft)
|
|
1221
1221
|
], ye);
|
|
1222
|
-
var
|
|
1223
|
-
for (var r = n > 1 ? void 0 : n ?
|
|
1222
|
+
var $e = Object.defineProperty, qt = Object.getOwnPropertyDescriptor, Zt = (s, e, t) => e in s ? $e(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t, Qt = (s, e, t, n) => {
|
|
1223
|
+
for (var r = n > 1 ? void 0 : n ? qt(e, t) : e, i = s.length - 1, a; i >= 0; i--)
|
|
1224
1224
|
(a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
|
|
1225
|
-
return n && r &&
|
|
1226
|
-
},
|
|
1227
|
-
let ae = class extends
|
|
1228
|
-
constructor(s =
|
|
1225
|
+
return n && r && $e(e, t, r), r;
|
|
1226
|
+
}, Pe = (s, e) => (t, n) => e(t, n, s), xe = (s, e, t) => Zt(s, typeof e != "symbol" ? e + "" : e, t);
|
|
1227
|
+
let ae = class extends Ze {
|
|
1228
|
+
constructor(s = Ue, e, t) {
|
|
1229
1229
|
super(), this._config = s, this._injector = e, this._configService = t;
|
|
1230
|
-
const { ...n } =
|
|
1231
|
-
|
|
1230
|
+
const { ...n } = Qe(
|
|
1231
|
+
{},
|
|
1232
|
+
Ue,
|
|
1233
|
+
this._config
|
|
1234
|
+
);
|
|
1235
|
+
this._configService.setConfig(It, n);
|
|
1232
1236
|
}
|
|
1233
1237
|
onStarting() {
|
|
1234
|
-
|
|
1238
|
+
et(this._injector, [
|
|
1235
1239
|
[S],
|
|
1236
1240
|
[ye],
|
|
1237
1241
|
[se],
|
|
@@ -1240,7 +1244,7 @@ let ae = class extends qe {
|
|
|
1240
1244
|
[re],
|
|
1241
1245
|
[te],
|
|
1242
1246
|
[ne]
|
|
1243
|
-
]),
|
|
1247
|
+
]), tt(this._injector, [
|
|
1244
1248
|
[ee],
|
|
1245
1249
|
[se],
|
|
1246
1250
|
[ie],
|
|
@@ -1250,27 +1254,27 @@ let ae = class extends qe {
|
|
|
1250
1254
|
]);
|
|
1251
1255
|
}
|
|
1252
1256
|
};
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
ae =
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1257
|
+
xe(ae, "pluginName", He);
|
|
1258
|
+
xe(ae, "type", I.UNIVER_SHEET);
|
|
1259
|
+
ae = Qt([
|
|
1260
|
+
Xe(ht),
|
|
1261
|
+
Pe(1, M(qe)),
|
|
1262
|
+
Pe(2, nt)
|
|
1259
1263
|
], ae);
|
|
1260
1264
|
export {
|
|
1261
|
-
|
|
1265
|
+
xt as AddHyperLinkCommand,
|
|
1262
1266
|
O as AddHyperLinkMutation,
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1267
|
+
Tt as AddRichHyperLinkCommand,
|
|
1268
|
+
At as CancelHyperLinkCommand,
|
|
1269
|
+
Wt as CancelRichHyperLinkCommand,
|
|
1266
1270
|
Q as ERROR_RANGE,
|
|
1267
1271
|
S as HyperLinkModel,
|
|
1268
1272
|
k as RemoveHyperLinkMutation,
|
|
1269
1273
|
U as SheetHyperLinkType,
|
|
1270
1274
|
ye as SheetsHyperLinkParserService,
|
|
1271
1275
|
ae as UniverSheetsHyperLinkPlugin,
|
|
1272
|
-
|
|
1276
|
+
Bt as UpdateHyperLinkCommand,
|
|
1273
1277
|
_e as UpdateHyperLinkMutation,
|
|
1274
1278
|
me as UpdateHyperLinkRefMutation,
|
|
1275
|
-
|
|
1279
|
+
jt as UpdateRichHyperLinkCommand
|
|
1276
1280
|
};
|
|
@@ -7,6 +7,14 @@ export interface ICellHyperLink {
|
|
|
7
7
|
label: string;
|
|
8
8
|
}
|
|
9
9
|
export interface IFRangeHyperlinkMixin {
|
|
10
|
+
/**
|
|
11
|
+
* Set hyperlink in the cell in the range.
|
|
12
|
+
* [!important] This method is async.
|
|
13
|
+
* @param url url
|
|
14
|
+
* @param label optional, label of the url
|
|
15
|
+
* @returns success or not
|
|
16
|
+
*/
|
|
17
|
+
setHyperLink(url: string, label?: string): Promise<boolean>;
|
|
10
18
|
/**
|
|
11
19
|
* Get all hyperlinks in the cell in the range.
|
|
12
20
|
* @returns hyperlinks
|
|
@@ -30,13 +38,6 @@ export interface IFRangeHyperlinkMixin {
|
|
|
30
38
|
cancelHyperLink(id: string): Promise<boolean>;
|
|
31
39
|
}
|
|
32
40
|
export declare class FRangeHyperlinkMixin extends FRange implements IFRangeHyperlinkMixin {
|
|
33
|
-
/**
|
|
34
|
-
* Set hyperlink in the cell in the range.
|
|
35
|
-
* [!important] This method is async.
|
|
36
|
-
* @param url url
|
|
37
|
-
* @param label optional, label of the url
|
|
38
|
-
* @returns success or not
|
|
39
|
-
*/
|
|
40
41
|
setHyperLink(url: string, label?: string): Promise<boolean>;
|
|
41
42
|
/**
|
|
42
43
|
* Get all hyperlinks in the cell in the range.
|
package/lib/umd/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(n
|
|
1
|
+
(function(r,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("@univerjs/sheets/facade"),require("@univerjs/sheets-hyper-link"),require("@univerjs/core")):typeof define=="function"&&define.amd?define(["exports","@univerjs/sheets/facade","@univerjs/sheets-hyper-link","@univerjs/core"],n):(r=typeof globalThis<"u"?globalThis:r||self,n(r.UniverSheetsHyperLinkFacade={},r.UniverSheetsFacade,r.UniverSheetsHyperLink,r.UniverCore))})(this,function(r,n,a,o){"use strict";class p extends n.FWorkbook{createSheetHyperlink(e,t){return this._injector.get(a.SheetsHyperLinkParserService).buildHyperLink(this.getId(),e,t)}parseSheetHyperlink(e){return this._injector.get(a.SheetsHyperLinkParserService).parseHyperLink(e)}}n.FWorkbook.extend(p);class k extends n.FRange{setHyperLink(e,t){const s={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),link:{row:this._range.startRow,column:this._range.startColumn,payload:e,display:t,id:o.generateRandomId()}};return this._commandService.executeCommand(a.AddHyperLinkCommand.id,s)}getHyperLinks(){var t,s,d;const e=this._worksheet.getCellRaw(this._range.startRow,this._range.startColumn);return e!=null&&e.p?(d=(s=(t=e.p.body)==null?void 0:t.customRanges)==null?void 0:s.filter(i=>i.rangeType===o.CustomRangeType.HYPERLINK).map(i=>{var u,h,c,m,l;return{id:`${i.rangeId}`,startIndex:i.startIndex,endIndex:i.endIndex,url:(h=(u=i.properties)==null?void 0:u.url)!=null?h:"",label:(l=(m=(c=e.p)==null?void 0:c.body)==null?void 0:m.dataStream.slice(i.startIndex,i.endIndex+1).replaceAll(o.DataStreamTreeTokenType.CUSTOM_RANGE_START,"").replaceAll(o.DataStreamTreeTokenType.CUSTOM_RANGE_END,""))!=null?l:""}}))!=null?d:[]:[]}updateHyperLink(e,t,s){const d={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id:e,payload:{payload:t,display:s}};return this._commandService.executeCommand(a.UpdateHyperLinkCommand.id,d)}cancelHyperLink(e){const t={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id:e};return this._commandService.executeCommand(a.CancelHyperLinkCommand.id,t)}}n.FRange.extend(k),r.FWorkbookHyperLinkMixin=p,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(p,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("rxjs"),require("@univerjs/sheets"),require("@univerjs/engine-formula"),require("@univerjs/docs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","@univerjs/sheets","@univerjs/engine-formula","@univerjs/docs"],o):(p=typeof globalThis<"u"?globalThis:p||self,o(p.UniverSheetsHyperLink={},p.UniverCore,p.rxjs,p.UniverSheets,p.UniverEngineFormula,p.UniverDocs))})(this,function(p,o,T,m,C,x){"use strict";var Qe=Object.defineProperty;var et=(p,o,T)=>o in p?Qe(p,o,{enumerable:!0,configurable:!0,writable:!0,value:T}):p[o]=T;var L=(p,o,T)=>et(p,typeof o!="symbol"?o+"":o,T);var Ie=Object.defineProperty,Re=Object.getOwnPropertyDescriptor,Me=(r,t,e,n)=>{for(var i=n>1?void 0:n?Re(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Ie(t,e,i),i},Ce=(r,t)=>(e,n)=>t(e,n,r);p.HyperLinkModel=class extends o.Disposable{constructor(e){super();L(this,"_linkUpdate$",new T.Subject);L(this,"linkUpdate$",this._linkUpdate$.asObservable());L(this,"_linkMap",new Map);L(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let i=this._linkMap.get(e);i||(i=new Map,this._linkMap.set(e,i));let s=i.get(n);s||(s=new o.ObjectMatrix,i.set(n,s));let a=this._linkPositionMap.get(e);a||(a=new Map,this._linkPositionMap.set(e,a));let d=a.get(n);return d||(d=new Map,a.set(n,d)),{matrix:s,positionMap:d}}addHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n);return s.setValue(i.row,i.column,i),a.set(i.id,{row:i.row,column:i.column,link:i}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:i,type:"add"}),!0}updateHyperLink(e,n,i,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;const u=d.getValue(l.row,l.column);return u&&(Object.assign(u,s),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:u.display,payload:u.payload},id:i,type:"update",silent:a})),!0}updateHyperLinkRef(e,n,i,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;let u=d.getValue(l.row,l.column);return!u||u.id!==i?u=l.link:d.realDeleteValue(l.row,l.column),Object.assign(u,s),c.set(i,{...s,link:u}),d.setValue(s.row,s.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:i,type:"updateRef",silent:a}),!0}removeHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(i);if(!d)return!1;a.delete(i);const c=s.getValue(d.row,d.column);return c&&c.id===i&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(i);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,i,s){const{matrix:a}=this._ensureMap(e,n);return a.getValue(i,s)}getHyperLinkByLocationSync(e,n,i,s){var g,f,_,h,y;const{matrix:a}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,o.UniverInstanceType.UNIVER_SHEET),c=(g=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:g.getCellRaw(i,s),l=((y=(h=c==null?void 0:c.v)!=null?h:(_=(f=c==null?void 0:c.p)==null?void 0:f.body)==null?void 0:_.dataStream.slice(0,-2))!=null?y:"").toString(),u=a.getValue(i,s);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:i}=this._ensureMap(e,n),s=[];return i.forValue((a,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(i=>{const s=this.getSubUnit(e,i);return{unitId:e,subUnitId:i,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}},p.HyperLinkModel=Me([Ce(0,o.IUniverInstanceService)],p.HyperLinkModel);var w=(r=>(r.SHEET="gid",r.RANGE="range",r.DEFINE_NAME="rangeid",r.INVALID="invalid",r.URL="url",r))(w||{});const Ue="sheets-hyper-link.config",Le={},E={type:o.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,link:s}=t;return e.addHyperLink(n,i,s)}},k={type:o.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:s}=t;return e.removeHyperLink(n,i,s)}},W={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,payload:s,id:a}=t;return e.updateHyperLink(n,i,a,s,!1)}},B={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:s,row:a,column:d,silent:c}=t;return e.updateHyperLinkRef(n,i,s,{row:a,column:d},c)}},K={type:o.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(r,t){var _,h,y;if(!t)return!1;const{unitId:e,subUnitId:n,row:i,col:s,id:a,url:d}=t,c=r.get(o.IUniverInstanceService),l=m.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:u}=l,g=u.getCellRaw(i,s),f=(y=(h=(_=g==null?void 0:g.p)==null?void 0:_.body)==null?void 0:h.customRanges)==null?void 0:y.find(I=>I.rangeType===o.CustomRangeType.HYPERLINK&&I.rangeId===a);return f&&(f.properties.url=d),!0}},ae="SHEET_HYPER_LINK_PLUGIN",$="err";var we=Object.defineProperty,Ee=Object.getOwnPropertyDescriptor,ke=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ee(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&we(t,e,i),i},z=(r,t)=>(e,n)=>t(e,n,r);let G=class extends o.Disposable{constructor(t,e,n,i){super();L(this,"_disposableMap",new Map);L(this,"_watchDisposableMap",new Map);L(this,"_rangeDisableMap",new Map);L(this,"_rangeWatcherMap",new Map);L(this,"_handlePositionChange",(t,e,n,i,s)=>{const a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return i?{redos:[{id:B.id,params:{unitId:t,subUnitId:e,id:n.id,row:i.startRow,column:i.startColumn,silent:s}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,id:n.id,row:a.startRow,column:a.startColumn,silent:s}}]}:{redos:[{id:k.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:E.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=i,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},a=d=>{const c=m.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===s.startColumn&&l.startRow===s.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(i,this._refRangeService.registerRefRange(s,a,t,e))}_watchPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(t,e,s,(a,d)=>{const{redos:c}=this._handlePositionChange(t,e,n,d,!0);o.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(t){const e=this._disposableMap.get(t);e==null||e.dispose(),this._disposableMap.delete(t)}_unwatchPosition(t){const e=this._watchDisposableMap.get(t);e==null||e.dispose(),this._watchDisposableMap.delete(t)}_registerRange(t,e,n,i=!1){var s,a,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(s=c.get("gid"))!=null?s:"",range:(a=c.get("range"))!=null?a:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const u=l.gid,g=C.deserializeRangeWithSheet(l.range).range;if(o.isValidRange(g)&&l.range!==$){const f=_=>{const h=m.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(g,_,{selectionManagerService:this._selectionManagerService});return h&&C.serializeRange(h)===C.serializeRange(g)?{redos:[],undos:[]}:{redos:[{id:W.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`}}}],undos:[{id:W.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(g,f,t,u)),i||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,u,g,(_,h)=>{this._hyperLinkModel.updateHyperLink(t,u,e,{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`},!0)},!0))}}}}_unregisterRange(t){const e=this._rangeDisableMap.get(t);e==null||e.dispose(),this._rangeDisableMap.delete(t)}_unwatchRange(t){const e=this._rangeWatcherMap.get(t);e==null||e.dispose(),this._rangeWatcherMap.delete(t)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(n=>{const{unitId:i,subUnitId:s,links:a}=n;a.forEach(d=>{this._registerPosition(i,s,d),this._watchPosition(i,s,d),this._registerRange(i,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:i,silent:s}=t,a=this._hyperLinkModel.getHyperLink(e,n,i);if(!a)return;this._unregisterPosition(i),this._registerPosition(e,n,a),s||(this._unwatchPosition(i),this._watchPosition(e,n,a));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:i}=n;i.forEach(s=>{this._unregisterPosition(s.id),this._unwatchPosition(s.id),this._unregisterRange(s.id),this._unwatchRange(s.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(o.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};G=ke([z(0,o.Inject(m.RefRangeService)),z(1,o.Inject(p.HyperLinkModel)),z(2,o.Inject(m.SheetsSelectionsService)),z(3,o.ICommandService)],G);var Pe=Object.defineProperty,be=Object.getOwnPropertyDescriptor,Te=(r,t,e,n)=>{for(var i=n>1?void 0:n?be(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Pe(t,e,i),i},te=(r,t)=>(e,n)=>t(e,n,r);let Y=class extends o.Disposable{constructor(r,t,e){super(),this._sheetInterceptorService=r,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{var t;if(r.id===m.RemoveSheetCommand.id){const e=r.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const i=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const a=this._hyperLinkModel.getSubUnit(i,s),d=a.map(l=>({id:k.id,params:{unitId:i,subUnitId:s,id:l.id}})),c=a.map(l=>({id:E.id,params:{unitId:i,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};Y=Te([te(0,o.Inject(m.SheetInterceptorService)),te(1,o.IUniverInstanceService),te(2,o.Inject(p.HyperLinkModel))],Y);var He=Object.defineProperty,Ne=Object.getOwnPropertyDescriptor,Oe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ne(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&He(t,e,i),i},ne=(r,t)=>(e,n)=>t(e,n,r);let q=class extends o.Disposable{constructor(t,e,n){super();L(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let i=n.get(e);return i||(i=new o.ObjectMatrix,n.set(e,i)),i}_isLegalRangeUrl(t,e){var i,s,a;const n=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(i=d.get("gid"))!=null?i:"",range:(s=d.get("range"))!=null?s:"",rangeid:(a=d.get("rangeid"))!=null?a:""};if(c.range&&c.gid){const l=c.gid,u=n.getSheetBySheetId(l);if(!u)return null;const g=C.deserializeRangeWithSheet(c.range).range;if(o.isValidRange(g,u)&&c.range!==$)return{range:g,worksheet:u}}}return null}_registerRange(t,e,n,i,s){var d,c,l,u;const a=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(g=>{var f;return g.rangeType===o.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(f=g.properties)==null?void 0:f.url)})){const g=new o.DisposableCollection;let f=!1;(u=(l=s.body)==null?void 0:l.customRanges)==null||u.forEach(_=>{var h;if(_.rangeType===o.CustomRangeType.HYPERLINK){const y=(h=_.properties)==null?void 0:h.url,I=this._isLegalRangeUrl(t,y);if(I){const{range:v,worksheet:U}=I;f=!0,g.add(this._refRangeService.registerRefRange(v,S=>{const R=m.handleDefaultRangeChangeWithEffectRefCommands(v,S);return R&&o.Rectangle.equals(R,v)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:K.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:_.rangeId,url:`#gid=${e}&range=${R?C.serializeRange(R):$}`}}],undos:[{id:K.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:_.rangeId,url:y}}],redos:[]}},U.getUnitId(),U.getSheetId()))}}}),f&&a.setValue(n,i,g)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId(),a=this._enusreMap(n,s);i.getCellMatrix().forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,s,d,c,l.p)})})};this._univerInstanceService.getAllUnitsForType(o.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(e=>{e.type===o.UniverInstanceType.UNIVER_SHEET&&t(e)}))}_initWorkbookUnload(){this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===o.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId();this._enusreMap(n,s).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}})}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===m.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:i,cellValue:s}=e,a=this._enusreMap(n,i);s&&new o.ObjectMatrix(s).forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,i,d,c,l.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===K.id){const e=t.params,{unitId:n,subUnitId:i,row:s,col:a}=e,d=m.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:i}),l=this._enusreMap(n,i).getValue(s,a);if(l&&l.dispose(),d){const{worksheet:u}=d,g=u.getCellRaw(s,a);g&&g.p&&this._registerRange(n,i,s,a,g.p)}}}))}};q=Oe([ne(0,o.ICommandService),ne(1,o.IUniverInstanceService),ne(2,o.Inject(m.RefRangeService))],q);var De=Object.defineProperty,Ve=Object.getOwnPropertyDescriptor,$e=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ve(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&De(t,e,i),i},F=(r,t)=>(e,n)=>t(e,n,r);let J=class extends o.Disposable{constructor(r,t,e,n){super(),this._sheetInterceptorService=r,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.SetRangeValuesCommand.id){const t=r.params,{unitId:e,subUnitId:n}=t,i=[],s=[];return t.cellValue&&new o.ObjectMatrix(t.cellValue).forValue((a,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,a,d);c&&(i.push({id:k.id,params:{unitId:e,subUnitId:n,id:c.id}}),s.push({id:E.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:s,redos:i}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.ClearSelectionContentCommand.id||r.id===m.ClearSelectionAllCommand.id||r.id===m.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),i=m.getSheetCommandTarget(this._univerInstanceService);if(n&&i){const{unitId:s,subUnitId:a}=i;o.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(s,a,d,c);l&&(t.push({id:k.id,params:{unitId:s,subUnitId:a,id:l.id}}),e.push({id:E.id,params:{unitId:s,subUnitId:a,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(m.AFTER_CELL_EDIT,{handler:(r,t,e)=>{if(!r||r.p)return e(r);if(typeof r.v=="string"&&o.Tools.isLegalUrl(r.v)&&r.v[r.v.length-1]!==" "){const{unitId:n,subUnitId:i}=t,s=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET),a=s==null?void 0:s.getSheetBySheetId(i);if(!a)return e(r);const d=a.getBlankCellDocumentModel(r);if(!d.documentModel)return e(r);const c=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:r.v.length,collapsed:!1},body:{dataStream:`${r.v}`,customRanges:[{startIndex:0,endIndex:r.v.length-1,rangeId:o.generateRandomId(),rangeType:o.CustomRangeType.HYPERLINK,properties:{url:r.v}}]},doc:d.documentModel});if(!c)return e(r);const l=d.documentModel.getBody();return o.TextX.apply(l,c.serialize()),e({...r,p:{id:o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:l,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(r)}}))}};J=$e([F(0,o.Inject(m.SheetInterceptorService)),F(1,o.Inject(p.HyperLinkModel)),F(2,o.Inject(m.SheetsSelectionsService)),F(3,o.IUniverInstanceService)],J);var oe=(r=>(r[r.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",r[r.UNIVER_DOC=1]="UNIVER_DOC",r[r.UNIVER_SHEET=2]="UNIVER_SHEET",r[r.UNIVER_SLIDE=3]="UNIVER_SLIDE",r[r.UNIVER_PROJECT=4]="UNIVER_PROJECT",r[r.UNRECOGNIZED=-1]="UNRECOGNIZED",r))(oe||{}),je=Object.defineProperty,Ae=Object.getOwnPropertyDescriptor,xe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ae(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&je(t,e,i),i},de=(r,t)=>(e,n)=>t(e,n,r);let X=class extends o.Disposable{constructor(r,t){super(),this._resourceManagerService=r,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const r=e=>{const n=this._hyperLinkModel.getUnit(e),i={};return n?(n.forEach(s=>{i[s.subUnitId]=s.links.map(({display:a,...d})=>d)}),JSON.stringify(i)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:ae,businesses:[oe.UNIVER_SHEET],toJson:e=>r(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(i=>{n[i].forEach(a=>{this._hyperLinkModel.addHyperLink(e,i,a)})})}}))}};X=xe([de(0,o.IResourceManagerService),de(1,o.Inject(p.HyperLinkModel))],X);const ce={type:o.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(r,t){if(!t)return!1;const e=r.get(o.ICommandService),n=r.get(o.IUndoRedoService),i=r.get(o.IUniverInstanceService),s=r.get(p.HyperLinkModel),a=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:u,worksheet:g}=d,{link:f}=t,{payload:_,display:h,row:y,column:I,id:v}=f,U=g.getCell(y,I),S=g.getBlankCellDocumentModel(U),R=S.documentModel.getSnapshot(),M=o.Tools.deepClone(R.body);if(!M)return!1;let P;if(h?P=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:M.dataStream.length-2,collapsed:!0},body:{dataStream:`${h}`,customRanges:[{startIndex:0,endIndex:h.length-1,rangeType:o.CustomRangeType.HYPERLINK,rangeId:v,properties:{url:_}}]},doc:S.documentModel}):P=o.BuildTextUtils.customRange.add({body:M,ranges:[{startOffset:0,endOffset:M.dataStream.length-2,collapsed:!1}],rangeId:v,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:_,refId:v}}),!P)return!1;const j=o.TextX.apply(M,P.serialize()),b={p:{...R,body:j},t:o.CellValueType.STRING},N=await a.onWriteCell(u,g,y,I,b),O={unitId:c,subUnitId:l,cellValue:{[f.row]:{[f.column]:N}}},re={id:m.SetRangeValuesMutation.id,params:O},Q=m.SetRangeValuesUndoMutationFactory(r,O),se={id:m.SetRangeValuesMutation.id,params:Q},A=[re],D=[se],V=s.getHyperLinkByLocation(c,l,y,I);return V&&(A.push({id:k.id,params:{unitId:c,subUnitId:l,id:V.id}}),D.push({id:E.id,params:{unitId:c,subUnitId:l,link:V}})),await o.sequenceExecuteAsync(A,e)?(n.pushUndoRedo({redoMutations:A,undoMutations:D,unitID:c}),!0):!1}},le={id:"sheets.command.add-rich-hyper-link",type:o.CommandType.COMMAND,handler:async(r,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,i=r.get(o.ICommandService),s=o.generateRandomId(),{payload:a}=n,d=x.addCustomRangeBySelectionFactory(r,{unitId:e,rangeId:s,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:a,refId:s}});return d?i.syncExecuteCommand(d.id,d.params):!1}},ue={type:o.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(r,t){var b,N;if(!t)return!1;const e=r.get(o.ICommandService),n=r.get(o.IUndoRedoService),i=r.get(o.IUniverInstanceService),s=r.get(p.HyperLinkModel),a=m.getSheetCommandTarget(i,t);if(!a)return!1;const{row:d,column:c,id:l}=t,{unitId:u,subUnitId:g,worksheet:f}=a,_=f.getCell(d,c);if(!_)return!1;const h=f.getCellDocumentModelWithFormula(_);if(!(h!=null&&h.documentModel))return!1;const y=o.Tools.deepClone(h.documentModel.getSnapshot());if(!((N=(b=y.body)==null?void 0:b.customRanges)==null?void 0:N.find(O=>O.rangeId===l)))return!1;const v=o.BuildTextUtils.customRange.delete(r,{documentDataModel:h.documentModel,rangeId:l});if(!v)return!1;const U=o.TextX.apply(y.body,v.serialize()),S=[],R=[],M={unitId:u,subUnitId:g,cellValue:{[d]:{[c]:{p:{...y,body:U},t:o.CellValueType.STRING}}}};S.push({id:m.SetRangeValuesMutation.id,params:M});const P=m.SetRangeValuesUndoMutationFactory(r,M);R.push({id:m.SetRangeValuesMutation.id,params:P});const j=s.getHyperLinkByLocation(u,g,d,c);return j&&(S.push({id:k.id,params:{unitId:u,subUnitId:g,id:l}}),R.push({id:E.id,params:{unitId:u,subUnitId:g,link:{...j}}})),o.sequenceExecute(S,e).result?(n.pushUndoRedo({redoMutations:S,undoMutations:R,unitID:u}),!0):!1}},pe={type:o.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(r,t){var u,g;if(!t)return!1;const{id:e,documentId:n}=t,i=r.get(o.ICommandService),a=r.get(o.IUniverInstanceService).getUnit(n,o.UniverInstanceType.UNIVER_DOC),d=(g=(u=a==null?void 0:a.getBody())==null?void 0:u.customRanges)==null?void 0:g.find(f=>f.rangeId===e);let c=null;d&&d.endIndex===a.getBody().dataStream.length-3&&(c={dataStream:" "});const l=x.deleteCustomRangeFactory(r,{unitId:n,rangeId:e,insert:c});return l?i.syncExecuteCommand(l.id,l.params):!1}},ge={type:o.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(r,t){var ye,ve,Se;if(!t)return!1;const e=r.get(o.ICommandService),n=r.get(o.IUndoRedoService),i=r.get(o.IUniverInstanceService),s=r.get(p.HyperLinkModel),a=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:u,id:g}=t,{workbook:f,worksheet:_,unitId:h,subUnitId:y}=d,{payload:I,display:v=""}=c,U=_.getCell(l,u);if(!U)return!1;const S=_.getCellDocumentModelWithFormula(U);if(!(S!=null&&S.documentModel))return!1;const R=S.documentModel.getSnapshot(),M=(ve=(ye=R.body)==null?void 0:ye.customRanges)==null?void 0:ve.find(Ze=>Ze.rangeId===g);if(!M)return!1;const P=o.generateRandomId(),H=(Se=o.getBodySlice(S.documentModel.getBody(),M.startIndex,M.endIndex+1).textRuns)==null?void 0:Se[0];H&&(H.ed=v.length+1);const b=x.replaceSelectionFactory(r,{unitId:h,body:{dataStream:`${v}`,customRanges:[{rangeId:P,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:v.length-1,properties:{url:I}}],textRuns:H?[H]:void 0},selection:{startOffset:M.startIndex,endOffset:M.endIndex+1,collapsed:!1},doc:S.documentModel});if(!b)return!1;const N=o.TextX.apply(o.Tools.deepClone(R.body),b.textX.serialize()),O={p:{...R,body:N},t:o.CellValueType.STRING},re=await a.onWriteCell(f,_,l,u,O),Q={id:m.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:y,cellValue:{[l]:{[u]:re}}}},se=m.SetRangeValuesUndoMutationFactory(r,Q.params),A={id:m.SetRangeValuesMutation.id,params:se},D=[Q],V=[A],ee=s.getHyperLinkByLocation(h,y,l,u);return ee&&(D.push({id:k.id,params:{unitId:h,subUnitId:y,id:ee.id}}),V.push({id:E.id,params:{unitId:h,subUnitId:y,link:ee}})),await o.sequenceExecuteAsync(D,e)?(n.pushUndoRedo({redoMutations:D,undoMutations:V,unitID:h}),!0):!1}},he={type:o.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(r,t)=>{var h,y,I,v;if(!t)return!1;const{documentId:e,payload:n,id:i}=t,s=r.get(o.IUniverInstanceService),a=r.get(o.ICommandService),d=s.getUnit(e,o.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(y=(h=d.getBody())==null?void 0:h.customRanges)==null?void 0:y.find(U=>U.rangeId===i);if(!c)return!1;const l=(I=t.payload.display)!=null?I:"",u=o.generateRandomId(),f=(v=o.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:v[0];f&&(f.ed=l.length+1);const _=x.replaceSelectionFactory(r,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:u,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:f?[f]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return _?a.syncExecuteCommand(_.id,_.params):!1}};var We=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,Ke=(r,t,e,n)=>{for(var i=n>1?void 0:n?Be(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&We(t,e,i),i},ze=(r,t)=>(e,n)=>t(e,n,r);let Z=class extends o.Disposable{constructor(r){super(),this._commandService=r,this._registerCommands()}_registerCommands(){[ce,ge,ue,he,pe,le,E,W,k,B,K].forEach(r=>{this._commandService.registerCommand(r)})}};Z=Ke([ze(0,o.ICommandService)],Z);var Ge=Object.defineProperty,Ye=Object.getOwnPropertyDescriptor,qe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ye(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Ge(t,e,i),i},ie=(r,t)=>(e,n)=>t(e,n,r);p.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${w.SHEET}=${e}${n?`&${typeof n=="string"?w.DEFINE_NAME:w.RANGE}=${typeof n=="string"?n:C.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,i,s;if(t.startsWith("#")){const a=new URLSearchParams(t.slice(1)),d={gid:(e=a.get("gid"))!=null?e:"",range:(n=a.get("range"))!=null?n:"",rangeid:(i=a.get("rangeid"))!=null?i:"",unitid:(s=a.get("unitid"))!=null?s:""},c=this._getURLName(d);return{type:c.type,name:c.name,url:t,searchObj:d}}else return{type:w.URL,name:t,url:t,searchObj:null}}_getURLName(t){var u;const{gid:e,range:n,rangeid:i,unitid:s}=t,a=s?this._univerInstanceService.getUnit(s,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),d={type:w.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!a)return d;const c=e?a.getSheetBySheetId(e):a.getActiveSheet(),l=(u=c==null?void 0:c.getName())!=null?u:"";if(n){if(!c)return d;const g=C.deserializeRangeWithSheet(n).range;return o.isValidRange(g,c)&&n!==$?{type:w.RANGE,name:C.serializeRangeWithSheet(l,g)}:d}if(i){const g=this._definedNamesService.getValueById(a.getUnitId(),i);return g?{type:w.DEFINE_NAME,name:g.formulaOrRefString}:d}if(e){const g=a.getSheetBySheetId(e);return g?{type:w.SHEET,name:g.getName()}:d}return d}},p.SheetsHyperLinkParserService=qe([ie(0,o.IUniverInstanceService),ie(1,o.Inject(o.LocaleService)),ie(2,C.IDefinedNamesService)],p.SheetsHyperLinkParserService);var me=Object.defineProperty,Fe=Object.getOwnPropertyDescriptor,Je=(r,t,e)=>t in r?me(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Xe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Fe(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&me(t,e,i),i},fe=(r,t)=>(e,n)=>t(e,n,r),_e=(r,t,e)=>Je(r,typeof t!="symbol"?t+"":t,e);p.UniverSheetsHyperLinkPlugin=class extends o.Plugin{constructor(t=Le,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...i}=this._config;this._configService.setConfig(Ue,i)}onStarting(){o.registerDependencies(this._injector,[[p.HyperLinkModel],[p.SheetsHyperLinkParserService],[X],[Z],[G],[J],[Y],[q]]),o.touchDependencies(this._injector,[[G],[X],[Z],[J],[Y],[q]])}},_e(p.UniverSheetsHyperLinkPlugin,"pluginName",ae),_e(p.UniverSheetsHyperLinkPlugin,"type",o.UniverInstanceType.UNIVER_SHEET),p.UniverSheetsHyperLinkPlugin=Xe([o.DependentOn(m.UniverSheetsPlugin),fe(1,o.Inject(o.Injector)),fe(2,o.IConfigService)],p.UniverSheetsHyperLinkPlugin),p.AddHyperLinkCommand=ce,p.AddHyperLinkMutation=E,p.AddRichHyperLinkCommand=le,p.CancelHyperLinkCommand=ue,p.CancelRichHyperLinkCommand=pe,p.ERROR_RANGE=$,p.RemoveHyperLinkMutation=k,p.SheetHyperLinkType=w,p.UpdateHyperLinkCommand=ge,p.UpdateHyperLinkMutation=W,p.UpdateHyperLinkRefMutation=B,p.UpdateRichHyperLinkCommand=he,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(p,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("rxjs"),require("@univerjs/sheets"),require("@univerjs/engine-formula"),require("@univerjs/docs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","@univerjs/sheets","@univerjs/engine-formula","@univerjs/docs"],o):(p=typeof globalThis<"u"?globalThis:p||self,o(p.UniverSheetsHyperLink={},p.UniverCore,p.rxjs,p.UniverSheets,p.UniverEngineFormula,p.UniverDocs))})(this,function(p,o,T,m,C,x){"use strict";var Qe=Object.defineProperty;var et=(p,o,T)=>o in p?Qe(p,o,{enumerable:!0,configurable:!0,writable:!0,value:T}):p[o]=T;var L=(p,o,T)=>et(p,typeof o!="symbol"?o+"":o,T);var Re=Object.defineProperty,Me=Object.getOwnPropertyDescriptor,Ce=(r,t,e,n)=>{for(var i=n>1?void 0:n?Me(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Re(t,e,i),i},Ue=(r,t)=>(e,n)=>t(e,n,r);p.HyperLinkModel=class extends o.Disposable{constructor(e){super();L(this,"_linkUpdate$",new T.Subject);L(this,"linkUpdate$",this._linkUpdate$.asObservable());L(this,"_linkMap",new Map);L(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let i=this._linkMap.get(e);i||(i=new Map,this._linkMap.set(e,i));let s=i.get(n);s||(s=new o.ObjectMatrix,i.set(n,s));let a=this._linkPositionMap.get(e);a||(a=new Map,this._linkPositionMap.set(e,a));let d=a.get(n);return d||(d=new Map,a.set(n,d)),{matrix:s,positionMap:d}}addHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n);return s.setValue(i.row,i.column,i),a.set(i.id,{row:i.row,column:i.column,link:i}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:i,type:"add"}),!0}updateHyperLink(e,n,i,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;const u=d.getValue(l.row,l.column);return u&&(Object.assign(u,s),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:u.display,payload:u.payload},id:i,type:"update",silent:a})),!0}updateHyperLinkRef(e,n,i,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(i);if(!l)return!0;let u=d.getValue(l.row,l.column);return!u||u.id!==i?u=l.link:d.realDeleteValue(l.row,l.column),Object.assign(u,s),c.set(i,{...s,link:u}),d.setValue(s.row,s.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:i,type:"updateRef",silent:a}),!0}removeHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(i);if(!d)return!1;a.delete(i);const c=s.getValue(d.row,d.column);return c&&c.id===i&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,i){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(i);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,i,s){const{matrix:a}=this._ensureMap(e,n);return a.getValue(i,s)}getHyperLinkByLocationSync(e,n,i,s){var g,f,_,h,y;const{matrix:a}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,o.UniverInstanceType.UNIVER_SHEET),c=(g=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:g.getCellRaw(i,s),l=((y=(h=c==null?void 0:c.v)!=null?h:(_=(f=c==null?void 0:c.p)==null?void 0:f.body)==null?void 0:_.dataStream.slice(0,-2))!=null?y:"").toString(),u=a.getValue(i,s);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:i}=this._ensureMap(e,n),s=[];return i.forValue((a,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(i=>{const s=this.getSubUnit(e,i);return{unitId:e,subUnitId:i,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}},p.HyperLinkModel=Ce([Ue(0,o.IUniverInstanceService)],p.HyperLinkModel);var w=(r=>(r.SHEET="gid",r.RANGE="range",r.DEFINE_NAME="rangeid",r.INVALID="invalid",r.URL="url",r))(w||{});const Le="sheets-hyper-link.config",ae={},E={type:o.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,link:s}=t;return e.addHyperLink(n,i,s)}},k={type:o.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:s}=t;return e.removeHyperLink(n,i,s)}},W={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,payload:s,id:a}=t;return e.updateHyperLink(n,i,a,s,!1)}},B={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(r,t){if(!t)return!1;const e=r.get(p.HyperLinkModel),{unitId:n,subUnitId:i,id:s,row:a,column:d,silent:c}=t;return e.updateHyperLinkRef(n,i,s,{row:a,column:d},c)}},K={type:o.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(r,t){var _,h,y;if(!t)return!1;const{unitId:e,subUnitId:n,row:i,col:s,id:a,url:d}=t,c=r.get(o.IUniverInstanceService),l=m.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:u}=l,g=u.getCellRaw(i,s),f=(y=(h=(_=g==null?void 0:g.p)==null?void 0:_.body)==null?void 0:h.customRanges)==null?void 0:y.find(v=>v.rangeType===o.CustomRangeType.HYPERLINK&&v.rangeId===a);return f&&(f.properties.url=d),!0}},oe="SHEET_HYPER_LINK_PLUGIN",$="err";var we=Object.defineProperty,Ee=Object.getOwnPropertyDescriptor,ke=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ee(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&we(t,e,i),i},z=(r,t)=>(e,n)=>t(e,n,r);let G=class extends o.Disposable{constructor(t,e,n,i){super();L(this,"_disposableMap",new Map);L(this,"_watchDisposableMap",new Map);L(this,"_rangeDisableMap",new Map);L(this,"_rangeWatcherMap",new Map);L(this,"_handlePositionChange",(t,e,n,i,s)=>{const a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return i?{redos:[{id:B.id,params:{unitId:t,subUnitId:e,id:n.id,row:i.startRow,column:i.startColumn,silent:s}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,id:n.id,row:a.startRow,column:a.startColumn,silent:s}}]}:{redos:[{id:k.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:E.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=i,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},a=d=>{const c=m.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===s.startColumn&&l.startRow===s.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(i,this._refRangeService.registerRefRange(s,a,t,e))}_watchPosition(t,e,n){const i=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(t,e,s,(a,d)=>{const{redos:c}=this._handlePositionChange(t,e,n,d,!0);o.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(t){const e=this._disposableMap.get(t);e==null||e.dispose(),this._disposableMap.delete(t)}_unwatchPosition(t){const e=this._watchDisposableMap.get(t);e==null||e.dispose(),this._watchDisposableMap.delete(t)}_registerRange(t,e,n,i=!1){var s,a,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(s=c.get("gid"))!=null?s:"",range:(a=c.get("range"))!=null?a:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const u=l.gid,g=C.deserializeRangeWithSheet(l.range).range;if(o.isValidRange(g)&&l.range!==$){const f=_=>{const h=m.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(g,_,{selectionManagerService:this._selectionManagerService});return h&&C.serializeRange(h)===C.serializeRange(g)?{redos:[],undos:[]}:{redos:[{id:W.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`}}}],undos:[{id:W.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(g,f,t,u)),i||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,u,g,(_,h)=>{this._hyperLinkModel.updateHyperLink(t,u,e,{payload:`#gid=${u}&range=${h?C.serializeRange(h):"err"}`},!0)},!0))}}}}_unregisterRange(t){const e=this._rangeDisableMap.get(t);e==null||e.dispose(),this._rangeDisableMap.delete(t)}_unwatchRange(t){const e=this._rangeWatcherMap.get(t);e==null||e.dispose(),this._rangeWatcherMap.delete(t)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(n=>{const{unitId:i,subUnitId:s,links:a}=n;a.forEach(d=>{this._registerPosition(i,s,d),this._watchPosition(i,s,d),this._registerRange(i,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:i,silent:s}=t,a=this._hyperLinkModel.getHyperLink(e,n,i);if(!a)return;this._unregisterPosition(i),this._registerPosition(e,n,a),s||(this._unwatchPosition(i),this._watchPosition(e,n,a));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:i}=n;i.forEach(s=>{this._unregisterPosition(s.id),this._unwatchPosition(s.id),this._unregisterRange(s.id),this._unwatchRange(s.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(o.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};G=ke([z(0,o.Inject(m.RefRangeService)),z(1,o.Inject(p.HyperLinkModel)),z(2,o.Inject(m.SheetsSelectionsService)),z(3,o.ICommandService)],G);var Pe=Object.defineProperty,be=Object.getOwnPropertyDescriptor,Te=(r,t,e,n)=>{for(var i=n>1?void 0:n?be(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Pe(t,e,i),i},te=(r,t)=>(e,n)=>t(e,n,r);let Y=class extends o.Disposable{constructor(r,t,e){super(),this._sheetInterceptorService=r,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{var t;if(r.id===m.RemoveSheetCommand.id){const e=r.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const i=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const a=this._hyperLinkModel.getSubUnit(i,s),d=a.map(l=>({id:k.id,params:{unitId:i,subUnitId:s,id:l.id}})),c=a.map(l=>({id:E.id,params:{unitId:i,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};Y=Te([te(0,o.Inject(m.SheetInterceptorService)),te(1,o.IUniverInstanceService),te(2,o.Inject(p.HyperLinkModel))],Y);var He=Object.defineProperty,Ne=Object.getOwnPropertyDescriptor,Oe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ne(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&He(t,e,i),i},ne=(r,t)=>(e,n)=>t(e,n,r);let q=class extends o.Disposable{constructor(t,e,n){super();L(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let i=n.get(e);return i||(i=new o.ObjectMatrix,n.set(e,i)),i}_isLegalRangeUrl(t,e){var i,s,a;const n=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(i=d.get("gid"))!=null?i:"",range:(s=d.get("range"))!=null?s:"",rangeid:(a=d.get("rangeid"))!=null?a:""};if(c.range&&c.gid){const l=c.gid,u=n.getSheetBySheetId(l);if(!u)return null;const g=C.deserializeRangeWithSheet(c.range).range;if(o.isValidRange(g,u)&&c.range!==$)return{range:g,worksheet:u}}}return null}_registerRange(t,e,n,i,s){var d,c,l,u;const a=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(g=>{var f;return g.rangeType===o.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(f=g.properties)==null?void 0:f.url)})){const g=new o.DisposableCollection;let f=!1;(u=(l=s.body)==null?void 0:l.customRanges)==null||u.forEach(_=>{var h;if(_.rangeType===o.CustomRangeType.HYPERLINK){const y=(h=_.properties)==null?void 0:h.url,v=this._isLegalRangeUrl(t,y);if(v){const{range:S,worksheet:U}=v;f=!0,g.add(this._refRangeService.registerRefRange(S,I=>{const R=m.handleDefaultRangeChangeWithEffectRefCommands(S,I);return R&&o.Rectangle.equals(R,S)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:K.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:_.rangeId,url:`#gid=${e}&range=${R?C.serializeRange(R):$}`}}],undos:[{id:K.id,params:{unitId:t,subUnitId:e,row:n,col:i,id:_.rangeId,url:y}}],redos:[]}},U.getUnitId(),U.getSheetId()))}}}),f&&a.setValue(n,i,g)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId(),a=this._enusreMap(n,s);i.getCellMatrix().forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,s,d,c,l.p)})})};this._univerInstanceService.getAllUnitsForType(o.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(e=>{e.type===o.UniverInstanceType.UNIVER_SHEET&&t(e)}))}_initWorkbookUnload(){this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===o.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(i=>{const s=i.getSheetId();this._enusreMap(n,s).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}})}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===m.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:i,cellValue:s}=e,a=this._enusreMap(n,i);s&&new o.ObjectMatrix(s).forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,i,d,c,l.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===K.id){const e=t.params,{unitId:n,subUnitId:i,row:s,col:a}=e,d=m.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:i}),l=this._enusreMap(n,i).getValue(s,a);if(l&&l.dispose(),d){const{worksheet:u}=d,g=u.getCellRaw(s,a);g&&g.p&&this._registerRange(n,i,s,a,g.p)}}}))}};q=Oe([ne(0,o.ICommandService),ne(1,o.IUniverInstanceService),ne(2,o.Inject(m.RefRangeService))],q);var De=Object.defineProperty,Ve=Object.getOwnPropertyDescriptor,$e=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ve(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&De(t,e,i),i},F=(r,t)=>(e,n)=>t(e,n,r);let J=class extends o.Disposable{constructor(r,t,e,n){super(),this._sheetInterceptorService=r,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.SetRangeValuesCommand.id){const t=r.params,{unitId:e,subUnitId:n}=t,i=[],s=[];return t.cellValue&&new o.ObjectMatrix(t.cellValue).forValue((a,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,a,d);c&&(i.push({id:k.id,params:{unitId:e,subUnitId:n,id:c.id}}),s.push({id:E.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:s,redos:i}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(r.id===m.ClearSelectionContentCommand.id||r.id===m.ClearSelectionAllCommand.id||r.id===m.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),i=m.getSheetCommandTarget(this._univerInstanceService);if(n&&i){const{unitId:s,subUnitId:a}=i;o.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(s,a,d,c);l&&(t.push({id:k.id,params:{unitId:s,subUnitId:a,id:l.id}}),e.push({id:E.id,params:{unitId:s,subUnitId:a,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(m.AFTER_CELL_EDIT,{handler:(r,t,e)=>{if(!r||r.p)return e(r);if(typeof r.v=="string"&&o.Tools.isLegalUrl(r.v)&&r.v[r.v.length-1]!==" "){const{unitId:n,subUnitId:i}=t,s=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET),a=s==null?void 0:s.getSheetBySheetId(i);if(!a)return e(r);const d=a.getBlankCellDocumentModel(r);if(!d.documentModel)return e(r);const c=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:r.v.length,collapsed:!1},body:{dataStream:`${r.v}`,customRanges:[{startIndex:0,endIndex:r.v.length-1,rangeId:o.generateRandomId(),rangeType:o.CustomRangeType.HYPERLINK,properties:{url:r.v}}]},doc:d.documentModel});if(!c)return e(r);const l=d.documentModel.getBody();return o.TextX.apply(l,c.serialize()),e({...r,p:{id:o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:l,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(r)}}))}};J=$e([F(0,o.Inject(m.SheetInterceptorService)),F(1,o.Inject(p.HyperLinkModel)),F(2,o.Inject(m.SheetsSelectionsService)),F(3,o.IUniverInstanceService)],J);var de=(r=>(r[r.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",r[r.UNIVER_DOC=1]="UNIVER_DOC",r[r.UNIVER_SHEET=2]="UNIVER_SHEET",r[r.UNIVER_SLIDE=3]="UNIVER_SLIDE",r[r.UNIVER_PROJECT=4]="UNIVER_PROJECT",r[r.UNRECOGNIZED=-1]="UNRECOGNIZED",r))(de||{}),je=Object.defineProperty,Ae=Object.getOwnPropertyDescriptor,xe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ae(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&je(t,e,i),i},ce=(r,t)=>(e,n)=>t(e,n,r);let X=class extends o.Disposable{constructor(r,t){super(),this._resourceManagerService=r,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const r=e=>{const n=this._hyperLinkModel.getUnit(e),i={};return n?(n.forEach(s=>{i[s.subUnitId]=s.links.map(({display:a,...d})=>d)}),JSON.stringify(i)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:oe,businesses:[de.UNIVER_SHEET],toJson:e=>r(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(i=>{n[i].forEach(a=>{this._hyperLinkModel.addHyperLink(e,i,a)})})}}))}};X=xe([ce(0,o.IResourceManagerService),ce(1,o.Inject(p.HyperLinkModel))],X);const le={type:o.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(r,t){if(!t)return!1;const e=r.get(o.ICommandService),n=r.get(o.IUndoRedoService),i=r.get(o.IUniverInstanceService),s=r.get(p.HyperLinkModel),a=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:u,worksheet:g}=d,{link:f}=t,{payload:_,display:h,row:y,column:v,id:S}=f,U=g.getCell(y,v),I=g.getBlankCellDocumentModel(U),R=I.documentModel.getSnapshot(),M=o.Tools.deepClone(R.body);if(!M)return!1;let P;if(h?P=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:M.dataStream.length-2,collapsed:M.dataStream.length-2===0},body:{dataStream:`${h}`,customRanges:[{startIndex:0,endIndex:h.length-1,rangeType:o.CustomRangeType.HYPERLINK,rangeId:S,properties:{url:_}}]},doc:I.documentModel}):P=o.BuildTextUtils.customRange.add({body:M,ranges:[{startOffset:0,endOffset:M.dataStream.length-2,collapsed:!1}],rangeId:S,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:_,refId:S}}),!P)return!1;const j=o.TextX.apply(M,P.serialize()),b={p:{...R,body:j},t:o.CellValueType.STRING},N=await a.onWriteCell(u,g,y,v,b),O={unitId:c,subUnitId:l,cellValue:{[f.row]:{[f.column]:N}}},re={id:m.SetRangeValuesMutation.id,params:O},Q=m.SetRangeValuesUndoMutationFactory(r,O),se={id:m.SetRangeValuesMutation.id,params:Q},A=[re],D=[se],V=s.getHyperLinkByLocation(c,l,y,v);return V&&(A.push({id:k.id,params:{unitId:c,subUnitId:l,id:V.id}}),D.push({id:E.id,params:{unitId:c,subUnitId:l,link:V}})),await o.sequenceExecuteAsync(A,e)?(n.pushUndoRedo({redoMutations:A,undoMutations:D,unitID:c}),!0):!1}},ue={id:"sheets.command.add-rich-hyper-link",type:o.CommandType.COMMAND,handler:async(r,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,i=r.get(o.ICommandService),s=o.generateRandomId(),{payload:a}=n,d=x.addCustomRangeBySelectionFactory(r,{unitId:e,rangeId:s,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:a,refId:s}});return d?i.syncExecuteCommand(d.id,d.params):!1}},pe={type:o.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(r,t){var b,N;if(!t)return!1;const e=r.get(o.ICommandService),n=r.get(o.IUndoRedoService),i=r.get(o.IUniverInstanceService),s=r.get(p.HyperLinkModel),a=m.getSheetCommandTarget(i,t);if(!a)return!1;const{row:d,column:c,id:l}=t,{unitId:u,subUnitId:g,worksheet:f}=a,_=f.getCell(d,c);if(!_)return!1;const h=f.getCellDocumentModelWithFormula(_);if(!(h!=null&&h.documentModel))return!1;const y=o.Tools.deepClone(h.documentModel.getSnapshot()),v=(N=(b=y.body)==null?void 0:b.customRanges)==null?void 0:N.find(O=>`${O.rangeId}`===l);if(!v)return!1;const S=o.BuildTextUtils.customRange.delete(r,{documentDataModel:h.documentModel,rangeId:v.rangeId});if(!S)return!1;const U=o.TextX.apply(y.body,S.serialize()),I=[],R=[],M={unitId:u,subUnitId:g,cellValue:{[d]:{[c]:{p:{...y,body:U},t:o.CellValueType.STRING}}}};I.push({id:m.SetRangeValuesMutation.id,params:M});const P=m.SetRangeValuesUndoMutationFactory(r,M);R.push({id:m.SetRangeValuesMutation.id,params:P});const j=s.getHyperLinkByLocation(u,g,d,c);return j&&(I.push({id:k.id,params:{unitId:u,subUnitId:g,id:l}}),R.push({id:E.id,params:{unitId:u,subUnitId:g,link:{...j}}})),o.sequenceExecute(I,e).result?(n.pushUndoRedo({redoMutations:I,undoMutations:R,unitID:u}),!0):!1}},ge={type:o.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(r,t){var u,g;if(!t)return!1;const{id:e,documentId:n}=t,i=r.get(o.ICommandService),a=r.get(o.IUniverInstanceService).getUnit(n,o.UniverInstanceType.UNIVER_DOC),d=(g=(u=a==null?void 0:a.getBody())==null?void 0:u.customRanges)==null?void 0:g.find(f=>f.rangeId===e);let c=null;d&&d.endIndex===a.getBody().dataStream.length-3&&(c={dataStream:" "});const l=x.deleteCustomRangeFactory(r,{unitId:n,rangeId:e,insert:c});return l?i.syncExecuteCommand(l.id,l.params):!1}},he={type:o.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(r,t){var ve,Se,Ie;if(!t)return!1;const e=r.get(o.ICommandService),n=r.get(o.IUndoRedoService),i=r.get(o.IUniverInstanceService),s=r.get(p.HyperLinkModel),a=r.get(m.SheetInterceptorService),d=m.getSheetCommandTarget(i,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:u,id:g}=t,{workbook:f,worksheet:_,unitId:h,subUnitId:y}=d,{payload:v,display:S=""}=c,U=_.getCell(l,u);if(!U)return!1;const I=_.getCellDocumentModelWithFormula(U);if(!(I!=null&&I.documentModel))return!1;const R=I.documentModel.getSnapshot(),M=(Se=(ve=R.body)==null?void 0:ve.customRanges)==null?void 0:Se.find(Ze=>`${Ze.rangeId}`===g);if(!M)return!1;const P=o.generateRandomId(),H=(Ie=o.getBodySlice(I.documentModel.getBody(),M.startIndex,M.endIndex+1).textRuns)==null?void 0:Ie[0];H&&(H.ed=S.length+1);const b=x.replaceSelectionFactory(r,{unitId:h,body:{dataStream:`${S}`,customRanges:[{rangeId:P,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:S.length-1,properties:{url:v}}],textRuns:H?[H]:void 0},selection:{startOffset:M.startIndex,endOffset:M.endIndex+1,collapsed:!1},doc:I.documentModel});if(!b)return!1;const N=o.TextX.apply(o.Tools.deepClone(R.body),b.textX.serialize()),O={p:{...R,body:N},t:o.CellValueType.STRING},re=await a.onWriteCell(f,_,l,u,O),Q={id:m.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:y,cellValue:{[l]:{[u]:re}}}},se=m.SetRangeValuesUndoMutationFactory(r,Q.params),A={id:m.SetRangeValuesMutation.id,params:se},D=[Q],V=[A],ee=s.getHyperLinkByLocation(h,y,l,u);return ee&&(D.push({id:k.id,params:{unitId:h,subUnitId:y,id:ee.id}}),V.push({id:E.id,params:{unitId:h,subUnitId:y,link:ee}})),await o.sequenceExecuteAsync(D,e)?(n.pushUndoRedo({redoMutations:D,undoMutations:V,unitID:h}),!0):!1}},me={type:o.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(r,t)=>{var h,y,v,S;if(!t)return!1;const{documentId:e,payload:n,id:i}=t,s=r.get(o.IUniverInstanceService),a=r.get(o.ICommandService),d=s.getUnit(e,o.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(y=(h=d.getBody())==null?void 0:h.customRanges)==null?void 0:y.find(U=>U.rangeId===i);if(!c)return!1;const l=(v=t.payload.display)!=null?v:"",u=o.generateRandomId(),f=(S=o.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:S[0];f&&(f.ed=l.length+1);const _=x.replaceSelectionFactory(r,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:u,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:f?[f]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return _?a.syncExecuteCommand(_.id,_.params):!1}};var We=Object.defineProperty,Be=Object.getOwnPropertyDescriptor,Ke=(r,t,e,n)=>{for(var i=n>1?void 0:n?Be(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&We(t,e,i),i},ze=(r,t)=>(e,n)=>t(e,n,r);let Z=class extends o.Disposable{constructor(r){super(),this._commandService=r,this._registerCommands()}_registerCommands(){[le,he,pe,me,ge,ue,E,W,k,B,K].forEach(r=>{this._commandService.registerCommand(r)})}};Z=Ke([ze(0,o.ICommandService)],Z);var Ge=Object.defineProperty,Ye=Object.getOwnPropertyDescriptor,qe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ye(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Ge(t,e,i),i},ie=(r,t)=>(e,n)=>t(e,n,r);p.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${w.SHEET}=${e}${n?`&${typeof n=="string"?w.DEFINE_NAME:w.RANGE}=${typeof n=="string"?n:C.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,i,s;if(t.startsWith("#")){const a=new URLSearchParams(t.slice(1)),d={gid:(e=a.get("gid"))!=null?e:"",range:(n=a.get("range"))!=null?n:"",rangeid:(i=a.get("rangeid"))!=null?i:"",unitid:(s=a.get("unitid"))!=null?s:""},c=this._getURLName(d);return{type:c.type,name:c.name,url:t,searchObj:d}}else return{type:w.URL,name:t,url:t,searchObj:null}}_getURLName(t){var u;const{gid:e,range:n,rangeid:i,unitid:s}=t,a=s?this._univerInstanceService.getUnit(s,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),d={type:w.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!a)return d;const c=e?a.getSheetBySheetId(e):a.getActiveSheet(),l=(u=c==null?void 0:c.getName())!=null?u:"";if(n){if(!c)return d;const g=C.deserializeRangeWithSheet(n).range;return o.isValidRange(g,c)&&n!==$?{type:w.RANGE,name:C.serializeRangeWithSheet(l,g)}:d}if(i){const g=this._definedNamesService.getValueById(a.getUnitId(),i);return g?{type:w.DEFINE_NAME,name:g.formulaOrRefString}:d}if(e){const g=a.getSheetBySheetId(e);return g?{type:w.SHEET,name:g.getName()}:d}return d}},p.SheetsHyperLinkParserService=qe([ie(0,o.IUniverInstanceService),ie(1,o.Inject(o.LocaleService)),ie(2,C.IDefinedNamesService)],p.SheetsHyperLinkParserService);var fe=Object.defineProperty,Fe=Object.getOwnPropertyDescriptor,Je=(r,t,e)=>t in r?fe(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Xe=(r,t,e,n)=>{for(var i=n>1?void 0:n?Fe(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&fe(t,e,i),i},_e=(r,t)=>(e,n)=>t(e,n,r),ye=(r,t,e)=>Je(r,typeof t!="symbol"?t+"":t,e);p.UniverSheetsHyperLinkPlugin=class extends o.Plugin{constructor(t=ae,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...i}=o.merge({},ae,this._config);this._configService.setConfig(Le,i)}onStarting(){o.registerDependencies(this._injector,[[p.HyperLinkModel],[p.SheetsHyperLinkParserService],[X],[Z],[G],[J],[Y],[q]]),o.touchDependencies(this._injector,[[G],[X],[Z],[J],[Y],[q]])}},ye(p.UniverSheetsHyperLinkPlugin,"pluginName",oe),ye(p.UniverSheetsHyperLinkPlugin,"type",o.UniverInstanceType.UNIVER_SHEET),p.UniverSheetsHyperLinkPlugin=Xe([o.DependentOn(m.UniverSheetsPlugin),_e(1,o.Inject(o.Injector)),_e(2,o.IConfigService)],p.UniverSheetsHyperLinkPlugin),p.AddHyperLinkCommand=le,p.AddHyperLinkMutation=E,p.AddRichHyperLinkCommand=ue,p.CancelHyperLinkCommand=pe,p.CancelRichHyperLinkCommand=ge,p.ERROR_RANGE=$,p.RemoveHyperLinkMutation=k,p.SheetHyperLinkType=w,p.UpdateHyperLinkCommand=he,p.UpdateHyperLinkMutation=W,p.UpdateHyperLinkRefMutation=B,p.UpdateRichHyperLinkCommand=me,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-hyper-link",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -52,17 +52,17 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@univerjs/protocol": "0.1.39",
|
|
55
|
-
"@univerjs/core": "0.5.
|
|
56
|
-
"@univerjs/docs": "0.5.
|
|
57
|
-
"@univerjs/engine-formula": "0.5.
|
|
58
|
-
"@univerjs/sheets": "0.5.
|
|
55
|
+
"@univerjs/core": "0.5.2",
|
|
56
|
+
"@univerjs/docs": "0.5.2",
|
|
57
|
+
"@univerjs/engine-formula": "0.5.2",
|
|
58
|
+
"@univerjs/sheets": "0.5.2"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"rxjs": "^7.8.1",
|
|
62
62
|
"typescript": "^5.7.2",
|
|
63
|
-
"vite": "^6.0.
|
|
64
|
-
"vitest": "^2.1.
|
|
65
|
-
"@univerjs-infra/shared": "0.5.
|
|
63
|
+
"vite": "^6.0.3",
|
|
64
|
+
"vitest": "^2.1.8",
|
|
65
|
+
"@univerjs-infra/shared": "0.5.2"
|
|
66
66
|
},
|
|
67
67
|
"space": {
|
|
68
68
|
".": {
|