@univerjs/sheets-hyper-link 0.5.3 → 0.5.4-nightly.202501131606
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 +65 -39
- package/lib/es/index.js +68 -68
- package/lib/types/commands/commands/add-hyper-link.command.d.ts +3 -3
- package/lib/types/commands/mutations/add-hyper-link.mutation.d.ts +2 -2
- package/lib/types/facade/f-range.d.ts +21 -28
- package/lib/types/facade/f-workbook.d.ts +17 -10
- package/lib/types/facade/f-worksheet.d.ts +14 -0
- package/lib/types/facade/index.d.ts +2 -0
- package/lib/types/index.d.ts +1 -1
- package/lib/types/models/hyper-link.model.d.ts +10 -10
- package/lib/types/types/interfaces/i-hyper-link.d.ts +1 -1
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +1 -1
- package/package.json +7 -7
- package/LICENSE +0 -176
package/lib/cjs/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@univerjs/core"),a=require("@univerjs/sheets-hyper-link"),d=require("@univerjs/sheets/facade");var g=Object.defineProperty,y=Object.getOwnPropertyDescriptor,m=(n,e,r,t)=>{for(var i=t>1?void 0:t?y(e,r):e,s=n.length-1,o;s>=0;s--)(o=n[s])&&(i=(t?o(e,r,i):o(i))||i);return t&&i&&g(e,r,i),i},_=(n,e)=>(r,t)=>e(r,t,n);let u=class{constructor(n,e){this._workbook=n,this._parserService=e}getRangeUrl(n){return this._parserService.buildHyperLink(this._workbook.getId(),n.getSheetId(),n.getRange()),this}};u=m([_(1,c.Inject(a.SheetsHyperLinkParserService))],u);class S extends d.FWorkbook{createSheetHyperlink(e,r){return this._injector.get(a.SheetsHyperLinkParserService).buildHyperLink(this.getId(),e,r)}parseSheetHyperlink(e){return this._injector.get(a.SheetsHyperLinkParserService).parseHyperLink(e)}}d.FWorkbook.extend(S);class I extends d.FWorksheet{getUrl(){return this._injector.get(a.SheetsHyperLinkParserService).buildHyperLink(this._workbook.getUnitId(),this._worksheet.getSheetId())}}d.FWorksheet.extend(I);class v extends d.FRange{setHyperLink(e,r){const t={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),link:{row:this._range.startRow,column:this._range.startColumn,payload:e,display:r,id:c.generateRandomId()}};return this._commandService.executeCommand(a.AddHyperLinkCommand.id,t)}getHyperLinks(){var r,t,i;const e=this._worksheet.getCellRaw(this._range.startRow,this._range.startColumn);return e!=null&&e.p?(i=(t=(r=e.p.body)==null?void 0:r.customRanges)==null?void 0:t.filter(s=>s.rangeType===c.CustomRangeType.HYPERLINK).map(s=>{var o,p,h,l,k;return{id:`${s.rangeId}`,startIndex:s.startIndex,endIndex:s.endIndex,url:(p=(o=s.properties)==null?void 0:o.url)!=null?p:"",label:(k=(l=(h=e.p)==null?void 0:h.body)==null?void 0:l.dataStream.slice(s.startIndex,s.endIndex+1).replaceAll(c.DataStreamTreeTokenType.CUSTOM_RANGE_START,"").replaceAll(c.DataStreamTreeTokenType.CUSTOM_RANGE_END,""))!=null?k:""}}))!=null?i:[]:[]}updateHyperLink(e,r,t){const i={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id:e,payload:{payload:r,display:t}};return this._commandService.executeCommand(a.UpdateHyperLinkCommand.id,i)}cancelHyperLink(e){const r={unitId:this.getUnitId(),subUnitId:this._worksheet.getSheetId(),row:this._range.startRow,column:this._range.startColumn,id:e};return this._commandService.syncExecuteCommand(a.CancelHyperLinkCommand.id,r)}getUrl(){return this._injector.get(a.SheetsHyperLinkParserService).buildHyperLink(this.getUnitId(),this.getSheetId(),this.getRange())}}d.FRange.extend(v);exports.FWorkbookHyperLinkMixin=S;
|
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var Ie=Object.defineProperty;var Re=(i,t,e)=>t in i?Ie(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var C=(i,t,e)=>Re(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),Me=require("rxjs"),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;
|
|
1
|
+
"use strict";var ve=Object.defineProperty;var Re=(i,t,e)=>t in i?ve(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var C=(i,t,e)=>Re(i,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@univerjs/core"),Me=require("rxjs"),g=require("@univerjs/sheets"),U=require("@univerjs/engine-formula"),Z=require("@univerjs/docs");var Ce=Object.defineProperty,Ue=Object.getOwnPropertyDescriptor,Le=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ue(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Ce(t,e,r),r},we=(i,t)=>(e,n)=>t(e,n,i);exports.HyperLinkModel=class extends o.Disposable{constructor(e){super();C(this,"_linkUpdate$",new Me.Subject);C(this,"linkUpdate$",this._linkUpdate$.asObservable());C(this,"_linkMap",new Map);C(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let r=this._linkMap.get(e);r||(r=new Map,this._linkMap.set(e,r));let s=r.get(n);s||(s=new o.ObjectMatrix,r.set(n,s));let a=this._linkPositionMap.get(e);a||(a=new Map,this._linkPositionMap.set(e,a));let d=a.get(n);return d||(d=new Map,a.set(n,d)),{matrix:s,positionMap:d}}addHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n);return s.setValue(r.row,r.column,r),a.set(r.id,{row:r.row,column:r.column,link:r}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:r,type:"add"}),!0}updateHyperLink(e,n,r,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(r);if(!l)return!0;const u=d.getValue(l.row,l.column);return u&&(Object.assign(u,s),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:u.display,payload:u.payload},id:r,type:"update",silent:a})),!0}updateHyperLinkRef(e,n,r,s,a=!1){const{matrix:d,positionMap:c}=this._ensureMap(e,n),l=c.get(r);if(!l)return!0;let u=d.getValue(l.row,l.column);return!u||u.id!==r?u=l.link:d.realDeleteValue(l.row,l.column),Object.assign(u,s),c.set(r,{...s,link:u}),d.setValue(s.row,s.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:r,type:"updateRef",silent:a}),!0}removeHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(r);if(!d)return!1;a.delete(r);const c=s.getValue(d.row,d.column);return c&&c.id===r&&s.realDeleteValue(d.row,d.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:d.link,type:"remove"}),!0}getHyperLink(e,n,r){const{matrix:s,positionMap:a}=this._ensureMap(e,n),d=a.get(r);if(d)return s.getValue(d.row,d.column)}getHyperLinkByLocation(e,n,r,s){const{matrix:a}=this._ensureMap(e,n);return a.getValue(r,s)}getHyperLinkByLocationSync(e,n,r,s){var p,m,f,h,_;const{matrix:a}=this._ensureMap(e,n),d=this._univerInstanceService.getUnit(e,o.UniverInstanceType.UNIVER_SHEET),c=(p=d==null?void 0:d.getSheetBySheetId(n))==null?void 0:p.getCellRaw(r,s),l=((_=(h=c==null?void 0:c.v)!=null?h:(f=(m=c==null?void 0:c.p)==null?void 0:m.body)==null?void 0:f.dataStream.slice(0,-2))!=null?_:"").toString(),u=a.getValue(r,s);if(u)return{...u,display:l}}getSubUnit(e,n){const{matrix:r}=this._ensureMap(e,n),s=[];return r.forValue((a,d,c)=>{c&&s.push(c)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(r=>{const s=this.getSubUnit(e,r);return{unitId:e,subUnitId:r,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}};exports.HyperLinkModel=Le([we(0,o.IUniverInstanceService)],exports.HyperLinkModel);var L=(i=>(i.SHEET="gid",i.RANGE="range",i.DEFINE_NAME="rangeid",i.INVALID="invalid",i.URL="url",i))(L||{});const Ee="sheets-hyper-link.config",oe={},w={type:o.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,link:s}=t;return e.addHyperLink(n,r,s)}},E={type:o.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,id:s}=t;return e.removeHyperLink(n,r,s)}},F={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,payload:s,id:a}=t;return e.updateHyperLink(n,r,a,s,!1)}},K={type:o.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(i,t){if(!t)return!1;const e=i.get(exports.HyperLinkModel),{unitId:n,subUnitId:r,id:s,row:a,column:d,silent:c}=t;return e.updateHyperLinkRef(n,r,s,{row:a,column:d},c)}},B={type:o.CommandType.MUTATION,id:"sheets.mutation.update-rich-hyper-link",handler(i,t){var f,h,_;if(!t)return!1;const{unitId:e,subUnitId:n,row:r,col:s,id:a,url:d}=t,c=i.get(o.IUniverInstanceService),l=g.getSheetCommandTarget(c,{unitId:e,subUnitId:n});if(!l)return!1;const{worksheet:u}=l,p=u.getCellRaw(r,s),m=(_=(h=(f=p==null?void 0:p.p)==null?void 0:f.body)==null?void 0:h.customRanges)==null?void 0:_.find(y=>y.rangeType===o.CustomRangeType.HYPERLINK&&y.rangeId===a);return m&&(m.properties.url=d),!0}},le="SHEET_HYPER_LINK_PLUGIN",x="err";var ke=Object.defineProperty,be=Object.getOwnPropertyDescriptor,Pe=(i,t,e,n)=>{for(var r=n>1?void 0:n?be(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&ke(t,e,r),r},A=(i,t)=>(e,n)=>t(e,n,i);let z=class extends o.Disposable{constructor(t,e,n,r){super();C(this,"_disposableMap",new Map);C(this,"_watchDisposableMap",new Map);C(this,"_rangeDisableMap",new Map);C(this,"_rangeWatcherMap",new Map);C(this,"_handlePositionChange",(t,e,n,r,s)=>{const a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return r?{redos:[{id:K.id,params:{unitId:t,subUnitId:e,id:n.id,row:r.startRow,column:r.startColumn,silent:s}}],undos:[{id:K.id,params:{unitId:t,subUnitId:e,id:n.id,row:a.startRow,column:a.startColumn,silent:s}}]}:{redos:[{id:E.id,params:{unitId:t,subUnitId:e,id:n.id}}],undos:[{id:w.id,params:{unitId:t,subUnitId:e,link:n}}]}});this._refRangeService=t,this._hyperLinkModel=e,this._selectionManagerService=n,this._commandService=r,this._initData(),this._initRefRange()}_registerPosition(t,e,n){const r=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row},a=d=>{const c=g.handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(s,d,{selectionManagerService:this._selectionManagerService}),l=Array.isArray(c)?c[0]:c;return l&&l.startColumn===s.startColumn&&l.startRow===s.startRow?{undos:[],redos:[]}:this._handlePositionChange(t,e,n,l,!1)};this._disposableMap.set(r,this._refRangeService.registerRefRange(s,a,t,e))}_watchPosition(t,e,n){const r=n.id,s={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(r,this._refRangeService.watchRange(t,e,s,(a,d)=>{const{redos:c}=this._handlePositionChange(t,e,n,d,!0);o.sequenceExecuteAsync(c,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(t){const e=this._disposableMap.get(t);e==null||e.dispose(),this._disposableMap.delete(t)}_unwatchPosition(t){const e=this._watchDisposableMap.get(t);e==null||e.dispose(),this._watchDisposableMap.delete(t)}_registerRange(t,e,n,r=!1){var s,a,d;if(n.startsWith("#")){const c=new URLSearchParams(n.slice(1)),l={gid:(s=c.get("gid"))!=null?s:"",range:(a=c.get("range"))!=null?a:"",rangeid:(d=c.get("rangeid"))!=null?d:""};if(l.range&&l.gid){const u=l.gid,p=U.deserializeRangeWithSheet(l.range).range;if(o.isValidRange(p)&&l.range!==x){const m=f=>{const h=g.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(p,f,{selectionManagerService:this._selectionManagerService});return h&&U.serializeRange(h)===U.serializeRange(p)?{redos:[],undos:[]}:{redos:[{id:F.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:`#gid=${u}&range=${h?U.serializeRange(h):"err"}`}}}],undos:[{id:F.id,params:{unitId:t,subUnitId:u,id:e,payload:{payload:n}}}]}};this._rangeDisableMap.set(e,this._refRangeService.registerRefRange(p,m,t,u)),r||this._rangeWatcherMap.set(e,this._refRangeService.watchRange(t,u,p,(f,h)=>{this._hyperLinkModel.updateHyperLink(t,u,e,{payload:`#gid=${u}&range=${h?U.serializeRange(h):"err"}`},!0)},!0))}}}}_unregisterRange(t){const e=this._rangeDisableMap.get(t);e==null||e.dispose(),this._rangeDisableMap.delete(t)}_unwatchRange(t){const e=this._rangeWatcherMap.get(t);e==null||e.dispose(),this._rangeWatcherMap.delete(t)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(n=>{const{unitId:r,subUnitId:s,links:a}=n;a.forEach(d=>{this._registerPosition(r,s,d),this._watchPosition(r,s,d),this._registerRange(r,d.id,d.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(t=>{switch(t.type){case"add":{this._registerPosition(t.unitId,t.subUnitId,t.payload),this._watchPosition(t.unitId,t.subUnitId,t.payload),this._registerRange(t.unitId,t.payload.id,t.payload.payload);break}case"remove":{this._unregisterPosition(t.payload.id),this._unwatchPosition(t.payload.id),this._unregisterRange(t.payload.id),this._unwatchRange(t.payload.id);break}case"updateRef":{const{unitId:e,subUnitId:n,id:r,silent:s}=t,a=this._hyperLinkModel.getHyperLink(e,n,r);if(!a)return;this._unregisterPosition(r),this._registerPosition(e,n,a),s||(this._unwatchPosition(r),this._watchPosition(e,n,a));break}case"unload":{const{unitLinks:e}=t;e.forEach(n=>{const{links:r}=n;r.forEach(s=>{this._unregisterPosition(s.id),this._unwatchPosition(s.id),this._unregisterRange(s.id),this._unwatchRange(s.id)})});break}case"update":{t.silent||this._unwatchRange(t.id),this._unregisterRange(t.id),this._registerRange(t.unitId,t.id,t.payload.payload,t.silent);break}}})),this.disposeWithMe(o.toDisposable(()=>{this._disposableMap.forEach(t=>{t.dispose()}),this._disposableMap.clear()}))}};z=Pe([A(0,o.Inject(g.RefRangeService)),A(1,o.Inject(exports.HyperLinkModel)),A(2,o.Inject(g.SheetsSelectionsService)),A(3,o.ICommandService)],z);var Te=Object.defineProperty,He=Object.getOwnPropertyDescriptor,Ne=(i,t,e,n)=>{for(var r=n>1?void 0:n?He(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Te(t,e,r),r},te=(i,t)=>(e,n)=>t(e,n,i);let G=class extends o.Disposable{constructor(i,t,e){super(),this._sheetInterceptorService=i,this._univerInstanceService=t,this._hyperLinkModel=e,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{var t;if(i.id===g.RemoveSheetCommand.id){const e=i.params,n=e.unitId?this._univerInstanceService.getUnit(e.unitId):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET);if(!n)return{redos:[],undos:[]};const r=n.getUnitId(),s=e.subUnitId||((t=n.getActiveSheet())==null?void 0:t.getSheetId());if(!s)return{redos:[],undos:[]};const a=this._hyperLinkModel.getSubUnit(r,s),d=a.map(l=>({id:E.id,params:{unitId:r,subUnitId:s,id:l.id}})),c=a.map(l=>({id:w.id,params:{unitId:r,subUnitId:s,link:l}}));return{redos:d,undos:c}}return{redos:[],undos:[]}}}))}};G=Ne([te(0,o.Inject(g.SheetInterceptorService)),te(1,o.IUniverInstanceService),te(2,o.Inject(exports.HyperLinkModel))],G);var Oe=Object.defineProperty,De=Object.getOwnPropertyDescriptor,Ve=(i,t,e,n)=>{for(var r=n>1?void 0:n?De(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Oe(t,e,r),r},ne=(i,t)=>(e,n)=>t(e,n,i);let Y=class extends o.Disposable{constructor(t,e,n){super();C(this,"_refRangeMap",new Map);this._commandService=t,this._univerInstanceService=e,this._refRangeService=n,this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(t,e){let n=this._refRangeMap.get(t);n||(n=new Map,this._refRangeMap.set(t,n));let r=n.get(e);return r||(r=new o.ObjectMatrix,n.set(e,r)),r}_isLegalRangeUrl(t,e){var r,s,a;const n=this._univerInstanceService.getUnit(t,o.UniverInstanceType.UNIVER_SHEET);if(!n)return null;if(e&&e.startsWith("#")){const d=new URLSearchParams(e.slice(1)),c={gid:(r=d.get("gid"))!=null?r:"",range:(s=d.get("range"))!=null?s:"",rangeid:(a=d.get("rangeid"))!=null?a:""};if(c.range&&c.gid){const l=c.gid,u=n.getSheetBySheetId(l);if(!u)return null;const p=U.deserializeRangeWithSheet(c.range).range;if(o.isValidRange(p,u)&&c.range!==x)return{range:p,worksheet:u}}}return null}_registerRange(t,e,n,r,s){var d,c,l,u;const a=this._enusreMap(t,e);if((c=(d=s.body)==null?void 0:d.customRanges)!=null&&c.some(p=>{var m;return p.rangeType===o.CustomRangeType.HYPERLINK&&this._isLegalRangeUrl(t,(m=p.properties)==null?void 0:m.url)})){const p=new o.DisposableCollection;let m=!1;(u=(l=s.body)==null?void 0:l.customRanges)==null||u.forEach(f=>{var h;if(f.rangeType===o.CustomRangeType.HYPERLINK){const _=(h=f.properties)==null?void 0:h.url,y=this._isLegalRangeUrl(t,_);if(y){const{range:S,worksheet:M}=y;m=!0,p.add(this._refRangeService.registerRefRange(S,I=>{const v=g.handleDefaultRangeChangeWithEffectRefCommands(S,I);return v&&o.Rectangle.equals(v,S)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:r,id:f.rangeId,url:`#gid=${e}&range=${v?U.serializeRange(v):x}`}}],undos:[{id:B.id,params:{unitId:t,subUnitId:e,row:n,col:r,id:f.rangeId,url:_}}],redos:[]}},M.getUnitId(),M.getSheetId()))}}}),m&&a.setValue(n,r,p)}}_initWorkbookLoad(){const t=e=>{const n=e.getUnitId();e.getSheets().forEach(r=>{const s=r.getSheetId(),a=this._enusreMap(n,s);r.getCellMatrix().forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,s,d,c,l.p)})})};this._univerInstanceService.getAllUnitsForType(o.UniverInstanceType.UNIVER_SHEET).forEach(e=>{t(e)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(e=>{e.type===o.UniverInstanceType.UNIVER_SHEET&&t(e)}))}_initWorkbookUnload(){this._univerInstanceService.unitDisposed$.subscribe(t=>{if(t.type===o.UniverInstanceType.UNIVER_SHEET){const e=t,n=e.getUnitId();e.getSheets().forEach(r=>{const s=r.getSheetId();this._enusreMap(n,s).forValue((d,c,l)=>{l&&l.dispose()})}),this._refRangeMap.delete(n)}})}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===g.SetRangeValuesMutation.id){const e=t.params,{unitId:n,subUnitId:r,cellValue:s}=e,a=this._enusreMap(n,r);s&&new o.ObjectMatrix(s).forValue((d,c,l)=>{const u=a.getValue(d,c);u&&u.dispose(),l&&l.p&&this._registerRange(n,r,d,c,l.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===B.id){const e=t.params,{unitId:n,subUnitId:r,row:s,col:a}=e,d=g.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:r}),l=this._enusreMap(n,r).getValue(s,a);if(l&&l.dispose(),d){const{worksheet:u}=d,p=u.getCellRaw(s,a);p&&p.p&&this._registerRange(n,r,s,a,p.p)}}}))}};Y=Ve([ne(0,o.ICommandService),ne(1,o.IUniverInstanceService),ne(2,o.Inject(g.RefRangeService))],Y);var xe=Object.defineProperty,$e=Object.getOwnPropertyDescriptor,je=(i,t,e,n)=>{for(var r=n>1?void 0:n?$e(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&xe(t,e,r),r},W=(i,t)=>(e,n)=>t(e,n,i);let q=class extends o.Disposable{constructor(i,t,e,n){super(),this._sheetInterceptorService=i,this._hyperLinkModel=t,this._selectionManagerService=e,this._univerInstanceService=n,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(i.id===g.SetRangeValuesCommand.id){const t=i.params,{unitId:e,subUnitId:n}=t,r=[],s=[];return t.cellValue&&new o.ObjectMatrix(t.cellValue).forValue((a,d)=>{const c=this._hyperLinkModel.getHyperLinkByLocation(e,n,a,d);c&&(r.push({id:E.id,params:{unitId:e,subUnitId:n,id:c.id}}),s.push({id:w.id,params:{unitId:e,subUnitId:n,link:c}}))}),{undos:s,redos:r}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(i.id===g.ClearSelectionContentCommand.id||i.id===g.ClearSelectionAllCommand.id||i.id===g.ClearSelectionFormatCommand.id){const t=[],e=[],n=this._selectionManagerService.getCurrentLastSelection(),r=g.getSheetCommandTarget(this._univerInstanceService);if(n&&r){const{unitId:s,subUnitId:a}=r;o.Range.foreach(n.range,(d,c)=>{const l=this._hyperLinkModel.getHyperLinkByLocation(s,a,d,c);l&&(t.push({id:E.id,params:{unitId:s,subUnitId:a,id:l.id}}),e.push({id:w.id,params:{unitId:s,subUnitId:a,link:l}}))})}return{redos:t,undos:e}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(g.AFTER_CELL_EDIT,{handler:(i,t,e)=>{if(!i||i.p)return e(i);if(typeof i.v=="string"&&o.Tools.isLegalUrl(i.v)&&i.v[i.v.length-1]!==" "){const{unitId:n,subUnitId:r}=t,s=this._univerInstanceService.getUnit(n,o.UniverInstanceType.UNIVER_SHEET),a=s==null?void 0:s.getSheetBySheetId(r);if(!a)return e(i);const d=a.getBlankCellDocumentModel(i);if(!d.documentModel)return e(i);const c=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:i.v.length,collapsed:!1},body:{dataStream:`${i.v}`,customRanges:[{startIndex:0,endIndex:i.v.length-1,rangeId:o.generateRandomId(),rangeType:o.CustomRangeType.HYPERLINK,properties:{url:i.v}}]},doc:d.documentModel});if(!c)return e(i);const l=d.documentModel.getBody();return o.TextX.apply(l,c.serialize()),e({...i,p:{id:o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,body:l,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return e(i)}}))}};q=je([W(0,o.Inject(g.SheetInterceptorService)),W(1,o.Inject(exports.HyperLinkModel)),W(2,o.Inject(g.SheetsSelectionsService)),W(3,o.IUniverInstanceService)],q);var ue=(i=>(i[i.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",i[i.UNIVER_DOC=1]="UNIVER_DOC",i[i.UNIVER_SHEET=2]="UNIVER_SHEET",i[i.UNIVER_SLIDE=3]="UNIVER_SLIDE",i[i.UNIVER_PROJECT=4]="UNIVER_PROJECT",i[i.UNRECOGNIZED=-1]="UNRECOGNIZED",i))(ue||{}),Ae=Object.defineProperty,We=Object.getOwnPropertyDescriptor,Be=(i,t,e,n)=>{for(var r=n>1?void 0:n?We(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Ae(t,e,r),r},de=(i,t)=>(e,n)=>t(e,n,i);let J=class extends o.Disposable{constructor(i,t){super(),this._resourceManagerService=i,this._hyperLinkModel=t,this._initSnapshot()}_initSnapshot(){const i=e=>{const n=this._hyperLinkModel.getUnit(e),r={};return n?(n.forEach(s=>{r[s.subUnitId]=s.links.map(({display:a,...d})=>d)}),JSON.stringify(r)):""},t=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:le,businesses:[ue.UNIVER_SHEET],toJson:e=>i(e),parseJson:e=>t(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(r=>{n[r].forEach(a=>{this._hyperLinkModel.addHyperLink(e,r,a)})})}}))}};J=Be([de(0,o.IResourceManagerService),de(1,o.Inject(exports.HyperLinkModel))],J);const pe={type:o.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(i,t){if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=i.get(g.SheetInterceptorService),d=g.getSheetCommandTarget(r,t);if(!d)return!1;const{unitId:c,subUnitId:l,workbook:u,worksheet:p}=d,{link:m}=t,{payload:f,display:h,row:_,column:y,id:S}=m,M=p.getCell(_,y),I=p.getBlankCellDocumentModel(M),v=I.documentModel.getSnapshot(),R=o.Tools.deepClone(v.body);if(!R)return!1;let k;if(h?k=o.BuildTextUtils.selection.replace({selection:{startOffset:0,endOffset:R.dataStream.length-2,collapsed:R.dataStream.length-2===0},body:{dataStream:`${h}`,customRanges:[{startIndex:0,endIndex:h.length-1,rangeType:o.CustomRangeType.HYPERLINK,rangeId:S,properties:{url:f}}]},doc:I.documentModel}):k=o.BuildTextUtils.customRange.add({body:R,ranges:[{startOffset:0,endOffset:R.dataStream.length-2,collapsed:!1}],rangeId:S,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:f,refId:S}}),!k)return!1;const D=o.TextX.apply(R,k.serialize()),b={p:{...v,body:D},t:o.CellValueType.STRING},T=await a.onWriteCell(u,p,_,y,b),H={unitId:c,subUnitId:l,cellValue:{[m.row]:{[m.column]:T}}},Q={id:g.SetRangeValuesMutation.id,params:H},$=g.SetRangeValuesUndoMutationFactory(i,H),ee={id:g.SetRangeValuesMutation.id,params:$},V=[Q],N=[ee],O=s.getHyperLinkByLocation(c,l,_,y);return O&&(V.push({id:E.id,params:{unitId:c,subUnitId:l,id:O.id}}),N.push({id:w.id,params:{unitId:c,subUnitId:l,link:O}})),await o.sequenceExecuteAsync(V,e)?(n.pushUndoRedo({redoMutations:V,undoMutations:N,unitID:c}),!0):!1}},he={id:"sheets.command.add-rich-hyper-link",type:o.CommandType.COMMAND,handler:async(i,t)=>{if(!t)return!1;const{documentId:e,link:n}=t,r=i.get(o.ICommandService),s=o.generateRandomId(),{payload:a}=n,d=Z.addCustomRangeBySelectionFactory(i,{unitId:e,rangeId:s,rangeType:o.CustomRangeType.HYPERLINK,properties:{url:a,refId:s}});return d?r.syncExecuteCommand(d.id,d.params):!1}},ge={type:o.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",handler(i,t){var b,T;if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=g.getSheetCommandTarget(r,t);if(!a)return!1;const{row:d,column:c,id:l}=t,{unitId:u,subUnitId:p,worksheet:m}=a,f=m.getCell(d,c);if(!f)return!1;const h=m.getCellDocumentModelWithFormula(f);if(!(h!=null&&h.documentModel))return!1;const _=o.Tools.deepClone(h.documentModel.getSnapshot()),y=(T=(b=_.body)==null?void 0:b.customRanges)==null?void 0:T.find(H=>`${H.rangeId}`===l);if(!y)return!1;const S=o.BuildTextUtils.customRange.delete({documentDataModel:h.documentModel,rangeId:y.rangeId});if(!S)return!1;const M=o.TextX.apply(_.body,S.serialize()),I=[],v=[],R={unitId:u,subUnitId:p,cellValue:{[d]:{[c]:{p:{..._,body:M},t:o.CellValueType.STRING}}}};I.push({id:g.SetRangeValuesMutation.id,params:R});const k=g.SetRangeValuesUndoMutationFactory(i,R);v.push({id:g.SetRangeValuesMutation.id,params:k});const D=s.getHyperLinkByLocation(u,p,d,c);return D&&(I.push({id:E.id,params:{unitId:u,subUnitId:p,id:l}}),v.push({id:w.id,params:{unitId:u,subUnitId:p,link:{...D}}})),o.sequenceExecute(I,e).result?(n.pushUndoRedo({redoMutations:I,undoMutations:v,unitID:u}),!0):!1}},me={type:o.CommandType.COMMAND,id:"sheets.command.cancel-rich-hyper-link",handler(i,t){var u,p;if(!t)return!1;const{id:e,documentId:n}=t,r=i.get(o.ICommandService),a=i.get(o.IUniverInstanceService).getUnit(n,o.UniverInstanceType.UNIVER_DOC),d=(p=(u=a==null?void 0:a.getBody())==null?void 0:u.customRanges)==null?void 0:p.find(m=>m.rangeId===e);let c=null;d&&d.endIndex===a.getBody().dataStream.length-3&&(c={dataStream:" "});const l=Z.deleteCustomRangeFactory(i,{unitId:n,rangeId:e,insert:c});return l?r.syncExecuteCommand(l.id,l.params):!1}},fe={type:o.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(i,t){var ie,se,ae;if(!t)return!1;const e=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService),s=i.get(exports.HyperLinkModel),a=i.get(g.SheetInterceptorService),d=g.getSheetCommandTarget(r,{unitId:t.unitId,subUnitId:t.subUnitId});if(!d)return!1;const{payload:c,row:l,column:u,id:p}=t,{workbook:m,worksheet:f,unitId:h,subUnitId:_}=d,{payload:y,display:S=""}=c,M=f.getCell(l,u);if(!M)return!1;const I=f.getCellDocumentModelWithFormula(M);if(!(I!=null&&I.documentModel))return!1;const v=I.documentModel.getSnapshot(),R=(se=(ie=v.body)==null?void 0:ie.customRanges)==null?void 0:se.find(Ie=>`${Ie.rangeId}`===p);if(!R)return!1;const k=o.generateRandomId(),P=(ae=o.getBodySlice(I.documentModel.getBody(),R.startIndex,R.endIndex+1).textRuns)==null?void 0:ae[0];P&&(P.ed=S.length+1);const b=Z.replaceSelectionFactory(i,{unitId:h,body:{dataStream:`${S}`,customRanges:[{rangeId:k,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:S.length-1,properties:{url:y}}],textRuns:P?[P]:void 0},selection:{startOffset:R.startIndex,endOffset:R.endIndex+1,collapsed:!1},doc:I.documentModel});if(!b)return!1;const T=o.TextX.apply(o.Tools.deepClone(v.body),b.textX.serialize()),H={p:{...v,body:T},t:o.CellValueType.STRING},Q=await a.onWriteCell(m,f,l,u,H),$={id:g.SetRangeValuesMutation.id,params:{unitId:h,subUnitId:_,cellValue:{[l]:{[u]:Q}}}},ee=g.SetRangeValuesUndoMutationFactory(i,$.params),V={id:g.SetRangeValuesMutation.id,params:ee},N=[$],O=[V],j=s.getHyperLinkByLocation(h,_,l,u);return j&&(N.push({id:E.id,params:{unitId:h,subUnitId:_,id:j.id}}),O.push({id:w.id,params:{unitId:h,subUnitId:_,link:j}})),await o.sequenceExecuteAsync(N,e)?(n.pushUndoRedo({redoMutations:N,undoMutations:O,unitID:h}),!0):!1}},_e={type:o.CommandType.COMMAND,id:"sheets.command.update-rich-hyper-link",handler:(i,t)=>{var h,_,y,S;if(!t)return!1;const{documentId:e,payload:n,id:r}=t,s=i.get(o.IUniverInstanceService),a=i.get(o.ICommandService),d=s.getUnit(e,o.UniverInstanceType.UNIVER_DOC);if(!d)return!1;const c=(_=(h=d.getBody())==null?void 0:h.customRanges)==null?void 0:_.find(M=>M.rangeId===r);if(!c)return!1;const l=(y=t.payload.display)!=null?y:"",u=o.generateRandomId(),m=(S=o.getBodySlice(d.getBody(),c.startIndex,c.endIndex+1).textRuns)==null?void 0:S[0];m&&(m.ed=l.length+1);const f=Z.replaceSelectionFactory(i,{unitId:e,body:{dataStream:`${l}`,customRanges:[{rangeId:u,rangeType:o.CustomRangeType.HYPERLINK,startIndex:0,endIndex:l.length-1,properties:{url:n.payload}}],textRuns:m?[m]:void 0},selection:{startOffset:c.startIndex,endOffset:c.endIndex+1,collapsed:!1},doc:d});return f?a.syncExecuteCommand(f.id,f.params):!1}};var Fe=Object.defineProperty,Ke=Object.getOwnPropertyDescriptor,ze=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ke(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Fe(t,e,r),r},Ge=(i,t)=>(e,n)=>t(e,n,i);let X=class extends o.Disposable{constructor(i){super(),this._commandService=i,this._registerCommands()}_registerCommands(){[pe,fe,ge,_e,me,he,w,F,E,K,B].forEach(i=>{this._commandService.registerCommand(i)})}};X=ze([Ge(0,o.ICommandService)],X);var Ye=Object.defineProperty,qe=Object.getOwnPropertyDescriptor,Je=(i,t,e,n)=>{for(var r=n>1?void 0:n?qe(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Ye(t,e,r),r},re=(i,t)=>(e,n)=>t(e,n,i);exports.SheetsHyperLinkParserService=class{constructor(t,e,n){this._univerInstanceService=t,this._localeService=e,this._definedNamesService=n}buildHyperLink(t,e,n){return`#${L.SHEET}=${e}${n?`&${typeof n=="string"?L.DEFINE_NAME:L.RANGE}=${typeof n=="string"?n:U.serializeRange(n)}`:""}`}parseHyperLink(t){var e,n,r,s;if(t.startsWith("#")){const a=new URLSearchParams(t.slice(1)),d={gid:(e=a.get("gid"))!=null?e:"",range:(n=a.get("range"))!=null?n:"",rangeid:(r=a.get("rangeid"))!=null?r:"",unitid:(s=a.get("unitid"))!=null?s:""},c=this._getURLName(d);return{type:c.type,name:c.name,url:t,searchObj:d}}else return{type:L.URL,name:t,url:t,searchObj:null}}_getURLName(t){var u;const{gid:e,range:n,rangeid:r,unitid:s}=t,a=s?this._univerInstanceService.getUnit(s,o.UniverInstanceType.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(o.UniverInstanceType.UNIVER_SHEET),d={type:L.INVALID,name:this._localeService.t("hyperLink.message.refError")};if(!a)return d;const c=e?a.getSheetBySheetId(e):a.getActiveSheet(),l=(u=c==null?void 0:c.getName())!=null?u:"";if(n){if(!c)return d;const p=U.deserializeRangeWithSheet(n).range;return o.isValidRange(p,c)&&n!==x?{type:L.RANGE,name:U.serializeRangeWithSheet(l,p)}:d}if(r){const p=this._definedNamesService.getValueById(a.getUnitId(),r);return p?{type:L.DEFINE_NAME,name:p.formulaOrRefString}:d}if(e){const p=a.getSheetBySheetId(e);return p?{type:L.SHEET,name:p.getName()}:d}return d}};exports.SheetsHyperLinkParserService=Je([re(0,o.IUniverInstanceService),re(1,o.Inject(o.LocaleService)),re(2,U.IDefinedNamesService)],exports.SheetsHyperLinkParserService);var ye=Object.defineProperty,Xe=Object.getOwnPropertyDescriptor,Ze=(i,t,e)=>t in i?ye(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,Qe=(i,t,e,n)=>{for(var r=n>1?void 0:n?Xe(t,e):t,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&ye(t,e,r),r},ce=(i,t)=>(e,n)=>t(e,n,i),Se=(i,t,e)=>Ze(i,typeof t!="symbol"?t+"":t,e);exports.UniverSheetsHyperLinkPlugin=class extends o.Plugin{constructor(t=oe,e,n){super(),this._config=t,this._injector=e,this._configService=n;const{...r}=o.merge({},oe,this._config);this._configService.setConfig(Ee,r)}onStarting(){o.registerDependencies(this._injector,[[exports.HyperLinkModel],[exports.SheetsHyperLinkParserService],[J],[X],[z],[q],[G],[Y]]),o.touchDependencies(this._injector,[[z],[J],[X],[q],[G],[Y]])}};Se(exports.UniverSheetsHyperLinkPlugin,"pluginName",le);Se(exports.UniverSheetsHyperLinkPlugin,"type",o.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsHyperLinkPlugin=Qe([o.DependentOn(g.UniverSheetsPlugin),ce(1,o.Inject(o.Injector)),ce(2,o.IConfigService)],exports.UniverSheetsHyperLinkPlugin);exports.AddHyperLinkCommand=pe;exports.AddHyperLinkMutation=w;exports.AddRichHyperLinkCommand=he;exports.CancelHyperLinkCommand=ge;exports.CancelRichHyperLinkCommand=me;exports.ERROR_RANGE=x;exports.RemoveHyperLinkMutation=E;exports.SheetHyperLinkType=L;exports.UpdateHyperLinkCommand=fe;exports.UpdateHyperLinkMutation=F;exports.UpdateHyperLinkRefMutation=K;exports.UpdateRichHyperLinkCommand=_e;
|
package/lib/es/facade.js
CHANGED
|
@@ -1,24 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
1
|
+
import { Inject as k, generateRandomId as y, CustomRangeType as I, DataStreamTreeTokenType as l } from "@univerjs/core";
|
|
2
|
+
import { SheetsHyperLinkParserService as o, AddHyperLinkCommand as S, UpdateHyperLinkCommand as v, CancelHyperLinkCommand as H } from "@univerjs/sheets-hyper-link";
|
|
3
|
+
import { FWorkbook as u, FWorksheet as _, FRange as g } from "@univerjs/sheets/facade";
|
|
4
|
+
var x = Object.defineProperty, w = Object.getOwnPropertyDescriptor, b = (n, e, t, r) => {
|
|
5
|
+
for (var i = r > 1 ? void 0 : r ? w(e, t) : e, s = n.length - 1, a; s >= 0; s--)
|
|
6
|
+
(a = n[s]) && (i = (r ? a(e, t, i) : a(i)) || i);
|
|
7
|
+
return r && i && x(e, t, i), i;
|
|
8
|
+
}, R = (n, e) => (t, r) => e(t, r, n);
|
|
9
|
+
let m = class {
|
|
10
|
+
constructor(n, e) {
|
|
11
|
+
this._workbook = n, this._parserService = e;
|
|
12
|
+
}
|
|
13
|
+
getRangeUrl(n) {
|
|
14
|
+
return this._parserService.buildHyperLink(this._workbook.getId(), n.getSheetId(), n.getRange()), this;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
m = b([
|
|
18
|
+
R(1, k(o))
|
|
19
|
+
], m);
|
|
20
|
+
class C extends u {
|
|
5
21
|
createSheetHyperlink(e, t) {
|
|
6
|
-
return this._injector.get(
|
|
22
|
+
return this._injector.get(o).buildHyperLink(this.getId(), e, t);
|
|
7
23
|
}
|
|
8
24
|
/**
|
|
9
|
-
*
|
|
10
|
-
* @param hyperlink the hyperlink string
|
|
11
|
-
* @returns the hyperlink info
|
|
25
|
+
* Parse the hyperlink string to get the hyperlink info.
|
|
26
|
+
* @param {string} hyperlink the hyperlink string
|
|
27
|
+
* @returns {ISheetHyperLinkInfo} the hyperlink info
|
|
12
28
|
*/
|
|
13
29
|
parseSheetHyperlink(e) {
|
|
14
|
-
return this._injector.get(
|
|
30
|
+
return this._injector.get(o).parseHyperLink(e);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
u.extend(C);
|
|
34
|
+
class L extends _ {
|
|
35
|
+
getUrl() {
|
|
36
|
+
return this._injector.get(o).buildHyperLink(this._workbook.getUnitId(), this._worksheet.getSheetId());
|
|
15
37
|
}
|
|
16
38
|
}
|
|
17
|
-
|
|
18
|
-
class
|
|
39
|
+
_.extend(L);
|
|
40
|
+
class U extends g {
|
|
19
41
|
// #region hyperlink
|
|
42
|
+
/**
|
|
43
|
+
* @param url
|
|
44
|
+
* @param label
|
|
45
|
+
* @deprecated
|
|
46
|
+
*/
|
|
20
47
|
setHyperLink(e, t) {
|
|
21
|
-
const
|
|
48
|
+
const r = {
|
|
22
49
|
unitId: this.getUnitId(),
|
|
23
50
|
subUnitId: this._worksheet.getSheetId(),
|
|
24
51
|
link: {
|
|
@@ -26,38 +53,35 @@ class x extends h {
|
|
|
26
53
|
column: this._range.startColumn,
|
|
27
54
|
payload: e,
|
|
28
55
|
display: t,
|
|
29
|
-
id:
|
|
56
|
+
id: y()
|
|
30
57
|
}
|
|
31
58
|
};
|
|
32
|
-
return this._commandService.executeCommand(
|
|
59
|
+
return this._commandService.executeCommand(S.id, r);
|
|
33
60
|
}
|
|
34
61
|
/**
|
|
35
|
-
*
|
|
36
|
-
* @returns hyperlinks
|
|
62
|
+
* @deprecated
|
|
37
63
|
*/
|
|
38
64
|
getHyperLinks() {
|
|
39
|
-
var t,
|
|
65
|
+
var t, r, i;
|
|
40
66
|
const e = this._worksheet.getCellRaw(this._range.startRow, this._range.startColumn);
|
|
41
|
-
return e != null && e.p ? (i = (
|
|
42
|
-
var
|
|
67
|
+
return e != null && e.p ? (i = (r = (t = e.p.body) == null ? void 0 : t.customRanges) == null ? void 0 : r.filter((s) => s.rangeType === I.HYPERLINK).map((s) => {
|
|
68
|
+
var a, d, p, c, h;
|
|
43
69
|
return {
|
|
44
|
-
id: `${
|
|
45
|
-
startIndex:
|
|
46
|
-
endIndex:
|
|
47
|
-
url: (
|
|
48
|
-
label: (
|
|
70
|
+
id: `${s.rangeId}`,
|
|
71
|
+
startIndex: s.startIndex,
|
|
72
|
+
endIndex: s.endIndex,
|
|
73
|
+
url: (d = (a = s.properties) == null ? void 0 : a.url) != null ? d : "",
|
|
74
|
+
label: (h = (c = (p = e.p) == null ? void 0 : p.body) == null ? void 0 : c.dataStream.slice(s.startIndex, s.endIndex + 1).replaceAll(l.CUSTOM_RANGE_START, "").replaceAll(l.CUSTOM_RANGE_END, "")) != null ? h : ""
|
|
49
75
|
};
|
|
50
76
|
})) != null ? i : [] : [];
|
|
51
77
|
}
|
|
52
78
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* @param
|
|
56
|
-
* @
|
|
57
|
-
* @param label optional, label of the url
|
|
58
|
-
* @returns success or not
|
|
79
|
+
* @param id
|
|
80
|
+
* @param url
|
|
81
|
+
* @param label
|
|
82
|
+
* @deprecated
|
|
59
83
|
*/
|
|
60
|
-
updateHyperLink(e, t,
|
|
84
|
+
updateHyperLink(e, t, r) {
|
|
61
85
|
const i = {
|
|
62
86
|
unitId: this.getUnitId(),
|
|
63
87
|
subUnitId: this._worksheet.getSheetId(),
|
|
@@ -66,15 +90,14 @@ class x extends h {
|
|
|
66
90
|
id: e,
|
|
67
91
|
payload: {
|
|
68
92
|
payload: t,
|
|
69
|
-
display:
|
|
93
|
+
display: r
|
|
70
94
|
}
|
|
71
95
|
};
|
|
72
|
-
return this._commandService.executeCommand(
|
|
96
|
+
return this._commandService.executeCommand(v.id, i);
|
|
73
97
|
}
|
|
74
98
|
/**
|
|
75
|
-
*
|
|
76
|
-
* @
|
|
77
|
-
* @returns success or not
|
|
99
|
+
* @param id
|
|
100
|
+
* @deprecated
|
|
78
101
|
*/
|
|
79
102
|
cancelHyperLink(e) {
|
|
80
103
|
const t = {
|
|
@@ -84,11 +107,14 @@ class x extends h {
|
|
|
84
107
|
column: this._range.startColumn,
|
|
85
108
|
id: e
|
|
86
109
|
};
|
|
87
|
-
return this._commandService.syncExecuteCommand(
|
|
110
|
+
return this._commandService.syncExecuteCommand(H.id, t);
|
|
111
|
+
}
|
|
112
|
+
getUrl() {
|
|
113
|
+
return this._injector.get(o).buildHyperLink(this.getUnitId(), this.getSheetId(), this.getRange());
|
|
88
114
|
}
|
|
89
115
|
// #endregion
|
|
90
116
|
}
|
|
91
|
-
|
|
117
|
+
g.extend(U);
|
|
92
118
|
export {
|
|
93
|
-
|
|
119
|
+
C as FWorkbookHyperLinkMixin
|
|
94
120
|
};
|