@univerjs/sheets-hyper-link 0.20.1 → 0.21.0
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 +208 -1
- package/lib/cjs/index.js +1600 -1
- package/lib/es/facade.js +207 -1
- package/lib/es/index.js +1570 -1
- package/lib/facade.js +207 -1
- package/lib/index.js +1570 -1
- package/lib/umd/index.js +1 -1
- package/package.json +7 -7
package/lib/index.js
CHANGED
|
@@ -1 +1,1570 @@
|
|
|
1
|
-
import{BuildTextUtils as e,CellValueType as t,CommandType as n,CustomRangeType as r,DOCS_NORMAL_EDITOR_UNIT_ID_KEY as i,DependentOn as a,Disposable as o,DisposableCollection as s,ICommandService as c,IConfigService as l,IUndoRedoService as u,IUniverInstanceService as d,Inject as f,Injector as p,LocaleService as m,ObjectMatrix as h,Plugin as g,Range as _,Rectangle as v,TextX as y,Tools as b,UniverInstanceType as x,generateRandomId as S,getBodySlice as C,isValidRange as w,merge as T,registerDependencies as E,sequenceExecute as D,sequenceExecuteAsync as O,toDisposable as k,touchDependencies as A}from"@univerjs/core";import{addCustomRangeBySelectionFactory as j,deleteCustomRangeFactory as M,replaceSelectionFactory as ee}from"@univerjs/docs";import{AFTER_CELL_EDIT as N,ClearSelectionAllCommand as P,ClearSelectionContentCommand as F,ClearSelectionFormatCommand as te,RefRangeService as ne,RemoveSheetCommand as I,SetRangeValuesCommand as L,SetRangeValuesMutation as R,SetRangeValuesUndoMutationFactory as re,SheetInterceptorService as ie,SheetsSelectionsService as z,UniverSheetsPlugin as ae,getSheetCommandTarget as B,handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests as oe,handleDefaultRangeChangeWithEffectRefCommands as V,handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests as H}from"@univerjs/sheets";import{Subject as U}from"rxjs";import{IDefinedNamesService as se,deserializeRangeWithSheet as ce,serializeRange as W,serializeRangeWithSheet as le}from"@univerjs/engine-formula";function G(e){"@babel/helpers - typeof";return G=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},G(e)}function ue(e,t){if(G(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(G(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function de(e){var t=ue(e,`string`);return G(t)==`symbol`?t:t+``}function K(e,t,n){return(t=de(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function q(e,t){return function(n,r){t(n,r,e)}}function J(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let Y=class extends o{constructor(e){super(),this._univerInstanceService=e,K(this,`_linkUpdate$`,new U),K(this,`linkUpdate$`,this._linkUpdate$.asObservable()),K(this,`_linkMap`,new Map),K(this,`_linkPositionMap`,new Map),this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,t){let n=this._linkMap.get(e);n||(n=new Map,this._linkMap.set(e,n));let r=n.get(t);r||(r=new h,n.set(t,r));let i=this._linkPositionMap.get(e);i||(i=new Map,this._linkPositionMap.set(e,i));let a=i.get(t);return a||(a=new Map,i.set(t,a)),{matrix:r,positionMap:a}}addHyperLink(e,t,n){let{matrix:r,positionMap:i}=this._ensureMap(e,t);return r.setValue(n.row,n.column,n),i.set(n.id,{row:n.row,column:n.column,link:n}),this._linkUpdate$.next({unitId:e,subUnitId:t,payload:n,type:`add`}),!0}updateHyperLink(e,t,n,r,i=!1){let{matrix:a,positionMap:o}=this._ensureMap(e,t),s=o.get(n);if(!s)return!0;let c=a.getValue(s.row,s.column);return c?(Object.assign(c,r),this._linkUpdate$.next({unitId:e,subUnitId:t,payload:{display:c.display,payload:c.payload},id:n,type:`update`,silent:i}),!0):!0}updateHyperLinkRef(e,t,n,r,i=!1){let{matrix:a,positionMap:o}=this._ensureMap(e,t),s=o.get(n);if(!s)return!0;let c=a.getValue(s.row,s.column);return!c||c.id!==n?c=s.link:a.realDeleteValue(s.row,s.column),Object.assign(c,r),o.set(n,{...r,link:c}),a.setValue(r.row,r.column,c),this._linkUpdate$.next({unitId:e,subUnitId:t,payload:r,id:n,type:`updateRef`,silent:i}),!0}removeHyperLink(e,t,n){let{matrix:r,positionMap:i}=this._ensureMap(e,t),a=i.get(n);if(!a)return!1;i.delete(n);let o=r.getValue(a.row,a.column);return o&&o.id===n&&r.realDeleteValue(a.row,a.column),this._linkUpdate$.next({unitId:e,subUnitId:t,payload:a.link,type:`remove`}),!0}getHyperLink(e,t,n){let{matrix:r,positionMap:i}=this._ensureMap(e,t),a=i.get(n);if(a)return r.getValue(a.row,a.column)}getHyperLinkByLocation(e,t,n,r){let{matrix:i}=this._ensureMap(e,t);return i.getValue(n,r)}getHyperLinkByLocationSync(e,t,n,r){var i,a,o,s;let{matrix:c}=this._ensureMap(e,t),l=this._univerInstanceService.getUnit(e,x.UNIVER_SHEET),u=l==null||(i=l.getSheetBySheetId(t))==null?void 0:i.getCellRaw(n,r),d=((a=(o=u==null?void 0:u.v)==null?u==null||(s=u.p)==null||(s=s.body)==null?void 0:s.dataStream.slice(0,-2):o)==null?``:a).toString(),f=c.getValue(n,r);if(f)return{...f,display:d}}getSubUnit(e,t){let{matrix:n}=this._ensureMap(e,t),r=[];return n.forValue((e,t,n)=>{n&&r.push(n)}),r}getUnit(e){let t=this._linkMap.get(e);return t?Array.from(t.keys()).map(t=>({unitId:e,subUnitId:t,links:this.getSubUnit(e,t)})):[]}deleteUnit(e){let t=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:`unload`,unitId:e,unitLinks:t})}getAll(){return Array.from(this._linkMap.keys()).map(e=>this.getUnit(e))}};Y=J([q(0,d)],Y);const X={type:n.MUTATION,id:`sheets.mutation.add-hyper-link`,handler(e,t){if(!t)return!1;let n=e.get(Y),{unitId:r,subUnitId:i,link:a}=t;return n.addHyperLink(r,i,a)}},Z={type:n.MUTATION,id:`sheets.mutation.remove-hyper-link`,handler(e,t){if(!t)return!1;let n=e.get(Y),{unitId:r,subUnitId:i,id:a}=t;return n.removeHyperLink(r,i,a)}},fe={type:n.COMMAND,id:`sheets.command.add-hyper-link`,async handler(n,i){if(!i)return!1;let a=n.get(c),o=n.get(u),s=n.get(d),l=n.get(Y),f=n.get(ie),p=B(s,i);if(!p)return!1;let{unitId:m,subUnitId:h,workbook:g,worksheet:_}=p,{link:v}=i,{payload:x,display:S,row:C,column:w,id:T}=v,E=_.getCell(C,w),O=_.getBlankCellDocumentModel(E,C,w),k=O.documentModel.getSnapshot(),A=b.deepClone(k.body);if(!A)return!1;let j;if(j=S?e.selection.replace({selection:{startOffset:0,endOffset:A.dataStream.length-2,collapsed:A.dataStream.length-2==0},body:{dataStream:`${S}`,customRanges:[{startIndex:0,endIndex:S.length-1,rangeType:r.HYPERLINK,rangeId:T,properties:{url:x}}]},doc:O.documentModel}):e.customRange.add({body:A,ranges:[{startOffset:0,endOffset:A.dataStream.length-2,collapsed:!1}],rangeId:T,rangeType:r.HYPERLINK,properties:{url:x,refId:T}}),!j)return!1;let M=y.apply(A,j.serialize()),ee={p:{...k,body:M},t:t.STRING},N=f.onWriteCell(g,_,C,w,ee),P={unitId:m,subUnitId:h,cellValue:{[v.row]:{[v.column]:N}}},F={id:R.id,params:P},te=re(n,P),ne={id:R.id,params:te},I=[F],L=[ne],z=l.getHyperLinkByLocation(m,h,C,w);return z&&(I.push({id:Z.id,params:{unitId:m,subUnitId:h,id:z.id}}),L.push({id:X.id,params:{unitId:m,subUnitId:h,link:z}})),await D(I,a)?await f.onValidateCell(g,_,C,w)===!1?(D(L,a),!1):(o.pushUndoRedo({redoMutations:I,undoMutations:L,unitID:m}),!0):!1}},pe={id:`sheets.command.add-rich-hyper-link`,type:n.COMMAND,handler:async(e,t)=>{if(!t)return!1;let{documentId:n,link:i}=t,a=e.get(c),o=S(),{payload:s}=i,l=j(e,{unitId:n,rangeId:o,rangeType:r.HYPERLINK,properties:{url:s,refId:o}});return l?a.syncExecuteCommand(l.id,l.params):!1}},me={type:n.COMMAND,id:`sheets.command.cancel-hyper-link`,handler(n,r){var i;if(!r)return!1;let a=n.get(c),o=n.get(u),s=n.get(d),l=n.get(Y),f=B(s,r);if(!f)return!1;let{row:p,column:m,id:h}=r,{unitId:g,subUnitId:_,worksheet:v}=f,x=v.getCell(p,m);if(!x)return!1;let S=v.getCellDocumentModelWithFormula(x,p,m);if(!(S!=null&&S.documentModel))return!1;let C=b.deepClone(S.documentModel.getSnapshot()),w=(i=C.body)==null||(i=i.customRanges)==null?void 0:i.find(e=>`${e.rangeId}`===h);if(!w)return!1;let T=e.customRange.delete({documentDataModel:S.documentModel,rangeId:w.rangeId});if(!T)return!1;let E=y.apply(C.body,T.serialize()),O=[],k=[],A={unitId:g,subUnitId:_,cellValue:{[p]:{[m]:{p:{...C,body:E},t:t.STRING}}}};O.push({id:R.id,params:A});let j=re(n,A);k.push({id:R.id,params:j});let M=l.getHyperLinkByLocation(g,_,p,m);return M&&(O.push({id:Z.id,params:{unitId:g,subUnitId:_,id:M.id}}),k.push({id:X.id,params:{unitId:g,subUnitId:_,link:{...M}}})),D(O,a).result?(o.pushUndoRedo({redoMutations:O,undoMutations:k,unitID:g}),!0):!1}},he={type:n.COMMAND,id:`sheets.command.cancel-rich-hyper-link`,handler(e,t){var n;if(!t)return!1;let{id:r,documentId:i}=t,a=e.get(c),o=e.get(d).getUnit(i,x.UNIVER_DOC),s=o==null||(n=o.getBody())==null||(n=n.customRanges)==null?void 0:n.find(e=>e.rangeId===r),l=null;s&&s.endIndex===o.getBody().dataStream.length-3&&(l={dataStream:` `});let u=M(e,{unitId:i,rangeId:r,insert:l});return u?a.syncExecuteCommand(u.id,u.params):!1}},ge={type:n.COMMAND,id:`sheets.command.update-hyper-link`,async handler(e,n){var i,a;if(!n)return!1;let o=e.get(c),s=e.get(u),l=e.get(d),f=e.get(Y),p=e.get(ie),m=B(l,{unitId:n.unitId,subUnitId:n.subUnitId});if(!m)return!1;let{payload:h,row:g,column:_,id:v}=n,{workbook:x,worksheet:w,unitId:T,subUnitId:E}=m,{payload:O,display:k=``}=h,A=w.getCell(g,_);if(!A)return!1;let j=w.getCellDocumentModelWithFormula(A,g,_);if(!(j!=null&&j.documentModel))return!1;let M=j.documentModel.getSnapshot(),N=(i=M.body)==null||(i=i.customRanges)==null?void 0:i.find(e=>`${e.rangeId}`===v);if(!N)return!1;let P=S(),F=(a=C(j.documentModel.getBody(),N.startIndex,N.endIndex+1).textRuns)==null?void 0:a[0];F&&(F.ed=k.length+1);let te=ee(e,{unitId:T,body:{dataStream:`${k}`,customRanges:[{rangeId:P,rangeType:r.HYPERLINK,startIndex:0,endIndex:k.length-1,properties:{url:O}}],textRuns:F?[F]:void 0},selection:{startOffset:N.startIndex,endOffset:N.endIndex+1,collapsed:!1},doc:j.documentModel});if(!te)return!1;let ne=y.apply(b.deepClone(M.body),te.textX.serialize()),I={p:{...M,body:ne},t:t.STRING},L=p.onWriteCell(x,w,g,_,I),z={id:R.id,params:{unitId:T,subUnitId:E,cellValue:{[g]:{[_]:L}}}},ae=re(e,z.params),oe={id:R.id,params:ae},V=[z],H=[oe],U=f.getHyperLinkByLocation(T,E,g,_);return U&&(V.push({id:Z.id,params:{unitId:T,subUnitId:E,id:U.id}}),H.push({id:X.id,params:{unitId:T,subUnitId:E,link:U}})),D(V,o)?await p.onValidateCell(x,w,g,_)===!1?(D(H,o),!1):(s.pushUndoRedo({redoMutations:V,undoMutations:H,unitID:T}),!0):!1}},_e={type:n.COMMAND,id:`sheets.command.update-rich-hyper-link`,handler:(e,t)=>{var n,i,a;if(!t)return!1;let{documentId:o,payload:s,id:l}=t,u=e.get(d),f=e.get(c),p=u.getUnit(o,x.UNIVER_DOC);if(!p)return!1;let m=(n=p.getBody())==null||(n=n.customRanges)==null?void 0:n.find(e=>e.rangeId===l);if(!m)return!1;let h=(i=t.payload.display)==null?``:i,g=S(),_=(a=C(p.getBody(),m.startIndex,m.endIndex+1).textRuns)==null?void 0:a[0];_&&(_.ed=h.length+1);let v=ee(e,{unitId:o,body:{dataStream:`${h}`,customRanges:[{rangeId:g,rangeType:r.HYPERLINK,startIndex:0,endIndex:h.length-1,properties:{url:s.payload}}],textRuns:_?[_]:void 0},selection:{startOffset:m.startIndex,endOffset:m.endIndex+1,collapsed:!1},doc:p});return v?f.syncExecuteCommand(v.id,v.params):!1}},ve={type:n.MUTATION,id:`sheets.mutation.update-hyper-link`,handler(e,t){if(!t)return!1;let n=e.get(Y),{unitId:r,subUnitId:i,payload:a,id:o}=t;return n.updateHyperLink(r,i,o,a,!1)}},ye={type:n.MUTATION,id:`sheets.mutation.update-hyper-link-ref`,handler(e,t){if(!t)return!1;let n=e.get(Y),{unitId:r,subUnitId:i,id:a,row:o,column:s,silent:c}=t;return n.updateHyperLinkRef(r,i,a,{row:o,column:s},c)}},be={type:n.MUTATION,id:`sheets.mutation.update-rich-hyper-link`,handler(e,t){var n;if(!t)return!1;let{unitId:i,subUnitId:a,row:o,col:s,id:c,url:l}=t,u=B(e.get(d),{unitId:i,subUnitId:a});if(!u)return!1;let{worksheet:f}=u,p=f.getCellRaw(o,s),m=p==null||(n=p.p)==null||(n=n.body)==null||(n=n.customRanges)==null?void 0:n.find(e=>e.rangeType===r.HYPERLINK&&e.rangeId===c);return m&&(m.properties.url=l),!0}};var xe=`@univerjs/sheets-hyper-link`,Se=`0.20.1`;const Ce=`sheets-hyper-link.config`;Symbol(Ce);const we={},Te=`err`;let Ee=class extends o{constructor(e,t,n,r){super(),this._refRangeService=e,this._hyperLinkModel=t,this._selectionManagerService=n,this._commandService=r,K(this,`_disposableMap`,new Map),K(this,`_watchDisposableMap`,new Map),K(this,`_rangeDisableMap`,new Map),K(this,`_rangeWatcherMap`,new Map),K(this,`_handlePositionChange`,(e,t,n,r,i)=>{let a={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};return r?{redos:[{id:ye.id,params:{unitId:e,subUnitId:t,id:n.id,row:r.startRow,column:r.startColumn,silent:i}}],undos:[{id:ye.id,params:{unitId:e,subUnitId:t,id:n.id,row:a.startRow,column:a.startColumn,silent:i}}]}:{redos:[{id:Z.id,params:{unitId:e,subUnitId:t,id:n.id}}],undos:[{id:X.id,params:{unitId:e,subUnitId:t,link:n}}]}}),this._initData(),this._initRefRange()}_registerPosition(e,t,n){let r=n.id,i={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._disposableMap.set(r,this._refRangeService.registerRefRange(i,r=>{let a=oe(i,r,{selectionManagerService:this._selectionManagerService}),o=Array.isArray(a)?a[0]:a;return o&&o.startColumn===i.startColumn&&o.startRow===i.startRow?{undos:[],redos:[]}:this._handlePositionChange(e,t,n,o,!1)},e,t))}_watchPosition(e,t,n){let r=n.id,i={startColumn:n.column,endColumn:n.column,startRow:n.row,endRow:n.row};this._watchDisposableMap.set(r,this._refRangeService.watchRange(e,t,i,(r,i)=>{let{redos:a}=this._handlePositionChange(e,t,n,i,!0);O(a,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(e){let t=this._disposableMap.get(e);t==null||t.dispose(),this._disposableMap.delete(e)}_unwatchPosition(e){let t=this._watchDisposableMap.get(e);t==null||t.dispose(),this._watchDisposableMap.delete(e)}_registerRange(e,t,n,r=!1){if(n.startsWith(`#`)){var i,a,o;let s=new URLSearchParams(n.slice(1)),c={gid:(i=s.get(`gid`))==null?``:i,range:(a=s.get(`range`))==null?``:a,rangeid:(o=s.get(`rangeid`))==null?``:o};if(c.range&&c.gid){let i=c.gid,a=ce(c.range).range;w(a)&&c.range!==`err`&&(this._rangeDisableMap.set(t,this._refRangeService.registerRefRange(a,r=>{let o=H(a,r,{selectionManagerService:this._selectionManagerService});return o&&W(o)===W(a)?{redos:[],undos:[]}:{redos:[{id:ve.id,params:{unitId:e,subUnitId:i,id:t,payload:{payload:`#gid=${i}&range=${o?W(o):`err`}`}}}],undos:[{id:ve.id,params:{unitId:e,subUnitId:i,id:t,payload:{payload:n}}}]}},e,i)),r||this._rangeWatcherMap.set(t,this._refRangeService.watchRange(e,i,a,(n,r)=>{this._hyperLinkModel.updateHyperLink(e,i,t,{payload:`#gid=${i}&range=${r?W(r):`err`}`},!0)},!0)))}}}_unregisterRange(e){let t=this._rangeDisableMap.get(e);t==null||t.dispose(),this._rangeDisableMap.delete(e)}_unwatchRange(e){let t=this._rangeWatcherMap.get(e);t==null||t.dispose(),this._rangeWatcherMap.delete(e)}_initData(){this._hyperLinkModel.getAll().forEach(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,links:r}=e;r.forEach(e=>{this._registerPosition(t,n,e),this._watchPosition(t,n,e),this._registerRange(t,e.id,e.payload)})})})}_initRefRange(){this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe(e=>{switch(e.type){case`add`:this._registerPosition(e.unitId,e.subUnitId,e.payload),this._watchPosition(e.unitId,e.subUnitId,e.payload),this._registerRange(e.unitId,e.payload.id,e.payload.payload);break;case`remove`:this._unregisterPosition(e.payload.id),this._unwatchPosition(e.payload.id),this._unregisterRange(e.payload.id),this._unwatchRange(e.payload.id);break;case`updateRef`:{let{unitId:t,subUnitId:n,id:r,silent:i}=e,a=this._hyperLinkModel.getHyperLink(t,n,r);if(!a)return;this._unregisterPosition(r),this._registerPosition(t,n,a),i||(this._unwatchPosition(r),this._watchPosition(t,n,a));break}case`unload`:{let{unitLinks:t}=e;t.forEach(e=>{let{links:t}=e;t.forEach(e=>{this._unregisterPosition(e.id),this._unwatchPosition(e.id),this._unregisterRange(e.id),this._unwatchRange(e.id)})});break}case`update`:e.silent||this._unwatchRange(e.id),this._unregisterRange(e.id),this._registerRange(e.unitId,e.id,e.payload.payload,e.silent);break}})),this.disposeWithMe(k(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};Ee=J([q(0,f(ne)),q(1,f(Y)),q(2,f(z)),q(3,c)],Ee);let De=class extends o{constructor(e,t,n){super(),this._sheetInterceptorService=e,this._univerInstanceService=t,this._hyperLinkModel=n,this._initSheetChange()}_initSheetChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===I.id){var t;let n=e.params,r=n.unitId?this._univerInstanceService.getUnit(n.unitId):this._univerInstanceService.getCurrentUnitForType(x.UNIVER_SHEET);if(!r)return{redos:[],undos:[]};let i=r.getUnitId(),a=n.subUnitId||((t=r.getActiveSheet())==null?void 0:t.getSheetId());if(!a)return{redos:[],undos:[]};let o=this._hyperLinkModel.getSubUnit(i,a);return{redos:o.map(e=>({id:Z.id,params:{unitId:i,subUnitId:a,id:e.id}})),undos:o.map(e=>({id:X.id,params:{unitId:i,subUnitId:a,link:e}}))}}return{redos:[],undos:[]}}}))}};De=J([q(0,f(ie)),q(1,d),q(2,f(Y))],De);let Oe=class extends o{constructor(e,t,n){super(),this._commandService=e,this._univerInstanceService=t,this._refRangeService=n,K(this,`_refRangeMap`,new Map),this._initWorkbookLoad(),this._initWorkbookUnload(),this._initSetRangesListener()}_enusreMap(e,t){let n=this._refRangeMap.get(e);n||(n=new Map,this._refRangeMap.set(e,n));let r=n.get(t);return r||(r=new h,n.set(t,r)),r}_isLegalRangeUrl(e,t){let n=this._univerInstanceService.getUnit(e,x.UNIVER_SHEET);if(!n)return null;if(t&&t.startsWith(`#`)){var r,i,a;let e=new URLSearchParams(t.slice(1)),o={gid:(r=e.get(`gid`))==null?``:r,range:(i=e.get(`range`))==null?``:i,rangeid:(a=e.get(`rangeid`))==null?``:a};if(o.range&&o.gid){let e=o.gid,t=n.getSheetBySheetId(e);if(!t)return null;let r=ce(o.range).range;if(w(r,t)&&o.range!==`err`)return{range:r,worksheet:t}}}return null}_registerRange(e,t,n,i,a){var o;let c=this._enusreMap(e,t);if(!((o=a.body)==null||(o=o.customRanges)==null)&&o.some(t=>{var n;return t.rangeType===r.HYPERLINK&&this._isLegalRangeUrl(e,(n=t.properties)==null?void 0:n.url)})){var l;let o=new s,u=!1;(l=a.body)==null||(l=l.customRanges)==null||l.forEach(a=>{if(a.rangeType===r.HYPERLINK){var s;let r=(s=a.properties)==null?void 0:s.url,c=this._isLegalRangeUrl(e,r);if(c){let{range:s,worksheet:l}=c;u=!0,o.add(this._refRangeService.registerRefRange(s,o=>{let c=V(s,o);return c&&v.equals(c,s)?{preRedos:[],preUndos:[],redos:[],undos:[]}:{preRedos:[{id:be.id,params:{unitId:e,subUnitId:t,row:n,col:i,id:a.rangeId,url:`#gid=${t}&range=${c?W(c):`err`}`}}],undos:[{id:be.id,params:{unitId:e,subUnitId:t,row:n,col:i,id:a.rangeId,url:r}}],redos:[]}},l.getUnitId(),l.getSheetId()))}}}),u&&c.setValue(n,i,o)}}_initWorkbookLoad(){let e=e=>{let t=e.getUnitId();e.getSheets().forEach(e=>{let n=e.getSheetId(),r=this._enusreMap(t,n);e.getCellMatrix().forValue((e,i,a)=>{let o=r.getValue(e,i);o&&o.dispose(),a&&a.p&&this._registerRange(t,n,e,i,a.p)})})};this._univerInstanceService.getAllUnitsForType(x.UNIVER_SHEET).forEach(t=>{e(t)}),this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe(t=>{t.type===x.UNIVER_SHEET&&e(t)}))}_initWorkbookUnload(){this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(e=>{if(e.type===x.UNIVER_SHEET){let t=e,n=t.getUnitId();t.getSheets().forEach(e=>{let t=e.getSheetId();this._enusreMap(n,t).forValue((e,t,n)=>{n&&n.dispose()})}),this._refRangeMap.delete(n)}}))}_initSetRangesListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===R.id){let{unitId:t,subUnitId:n,cellValue:r}=e.params,i=this._enusreMap(t,n);r&&new h(r).forValue((e,r,a)=>{let o=i.getValue(e,r);o&&o.dispose(),a&&a.p&&this._registerRange(t,n,e,r,a.p)})}})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===be.id){let{unitId:t,subUnitId:n,row:r,col:i}=e.params,a=B(this._univerInstanceService,{unitId:t,subUnitId:n}),o=this._enusreMap(t,n).getValue(r,i);if(o&&o.dispose(),a){let{worksheet:e}=a,o=e.getCellRaw(r,i);o&&o.p&&this._registerRange(t,n,r,i,o.p)}}}))}};Oe=J([q(0,c),q(1,d),q(2,f(ne))],Oe);let ke=class extends o{constructor(e,t,n,r){super(),this._sheetInterceptorService=e,this._hyperLinkModel=t,this._selectionManagerService=n,this._univerInstanceService=r,this._initCommandInterceptor(),this._initAfterEditor()}_initCommandInterceptor(){this._initSetRangeValuesCommandInterceptor(),this._initClearSelectionCommandInterceptor()}_initSetRangeValuesCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===L.id){let t=e.params,{unitId:n,subUnitId:r}=t,i=[],a=[];return t.cellValue&&new h(t.cellValue).forValue((e,t)=>{let o=this._hyperLinkModel.getHyperLinkByLocation(n,r,e,t);o&&(i.push({id:Z.id,params:{unitId:n,subUnitId:r,id:o.id}}),a.push({id:X.id,params:{unitId:n,subUnitId:r,link:o}}))}),{undos:a,redos:i}}return{redos:[],undos:[]}}}))}_initClearSelectionCommandInterceptor(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{if(e.id===F.id||e.id===P.id||e.id===te.id){let t=[],n=[],r=this._selectionManagerService.getCurrentLastSelection(),i=B(this._univerInstanceService,e.params);if(r&&i){let{unitId:e,subUnitId:a}=i;_.foreach(r.range,(r,i)=>{let o=this._hyperLinkModel.getHyperLinkByLocation(e,a,r,i);o&&(t.push({id:Z.id,params:{unitId:e,subUnitId:a,id:o.id}}),n.push({id:X.id,params:{unitId:e,subUnitId:a,link:o}}))})}return{redos:t,undos:n}}return{redos:[],undos:[]}}}))}_initAfterEditor(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(N,{handler:(t,n,a)=>{if(!t||t.p)return a(t);if(typeof t.v==`string`&&b.isLegalUrl(t.v)&&t.v[t.v.length-1]!==` `){let{unitId:o,subUnitId:s,row:c,col:l}=n,u=b.normalizeUrl(t.v),d=this._univerInstanceService.getUnit(o,x.UNIVER_SHEET),f=d==null?void 0:d.getSheetBySheetId(s);if(!f)return a(t);let p=f.getBlankCellDocumentModel(t,c,l);if(!p.documentModel)return a(t);let m=e.selection.replace({selection:{startOffset:0,endOffset:t.v.length,collapsed:!1},body:{dataStream:`${t.v}`,customRanges:[{startIndex:0,endIndex:t.v.length-1,rangeId:S(),rangeType:r.HYPERLINK,properties:{url:u}}]},doc:p.documentModel});if(!m)return a(t);let h=p.documentModel.getBody();return y.apply(h,m.serialize()),a({...t,p:{id:i,body:h,documentStyle:{pageSize:{width:1/0,height:1/0}}}})}return a(t)}}))}};ke=J([q(0,f(ie)),q(1,f(Y)),q(2,f(z)),q(3,d)],ke);let Ae=class extends o{constructor(e){super(),this._commandService=e,this._registerCommands()}_registerCommands(){[fe,ge,me,_e,he,pe,X,ve,Z,ye,be].forEach(e=>{this._commandService.registerCommand(e)})}};Ae=J([q(0,c)],Ae);let Q=function(e){return e.SHEET=`gid`,e.RANGE=`range`,e.DEFINE_NAME=`rangeid`,e.INVALID=`invalid`,e.URL=`url`,e}({}),je=class{constructor(e,t,n){this._univerInstanceService=e,this._localeService=t,this._definedNamesService=n}buildHyperLink(e,t,n){return`#${Q.SHEET}=${t}${n?`&${typeof n==`string`?Q.DEFINE_NAME:Q.RANGE}=${typeof n==`string`?n:W(n)}`:``}`}parseHyperLink(e){if(e.startsWith(`#`)){var t,n,r,i;let a=new URLSearchParams(e.slice(1)),o={gid:(t=a.get(`gid`))==null?``:t,range:(n=a.get(`range`))==null?``:n,rangeid:(r=a.get(`rangeid`))==null?``:r,unitid:(i=a.get(`unitid`))==null?``:i},s=this._getURLName(o);return{type:s.type,name:s.name,url:e,searchObj:o}}else return{type:Q.URL,name:e,url:e,searchObj:null}}_getURLName(e){var t;let{gid:n,range:r,rangeid:i,unitid:a}=e,o=a?this._univerInstanceService.getUnit(a,x.UNIVER_SHEET):this._univerInstanceService.getCurrentUnitForType(x.UNIVER_SHEET),s={type:Q.INVALID,name:this._localeService.t(`hyperLink.message.refError`)};if(!o)return s;let c=n?o.getSheetBySheetId(n):o.getActiveSheet(),l=(t=c==null?void 0:c.getName())==null?``:t;if(r){if(!c)return s;let e=ce(r).range;return w(e,c)&&r!==`err`?{type:Q.RANGE,name:le(l,e)}:s}if(i){let e=this._definedNamesService.getValueById(o.getUnitId(),i);return e?{type:Q.DEFINE_NAME,name:e.formulaOrRefString}:s}if(n){let e=o.getSheetBySheetId(n);return e?{type:Q.SHEET,name:e.getName()}:s}return s}};je=J([q(0,d),q(1,f(m)),q(2,se)],je);let $=class extends g{constructor(e=we,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{...r}=T({},we,this._config);this._configService.setConfig(Ce,r)}onStarting(){E(this._injector,[[Y],[je],[Ae],[Ee],[ke],[De],[Oe]]),A(this._injector,[[Ee],[Ae],[ke],[De],[Oe]])}};K($,`pluginName`,`SHEET_HYPER_LINK_PLUGIN`),K($,`packageName`,xe),K($,`version`,Se),K($,`type`,x.UNIVER_SHEET),$=J([a(ae),q(1,f(p)),q(2,l)],$);export{fe as AddHyperLinkCommand,X as AddHyperLinkMutation,pe as AddRichHyperLinkCommand,me as CancelHyperLinkCommand,he as CancelRichHyperLinkCommand,Te as ERROR_RANGE,Y as HyperLinkModel,Z as RemoveHyperLinkMutation,Q as SheetHyperLinkType,je as SheetsHyperLinkParserService,$ as UniverSheetsHyperLinkPlugin,ge as UpdateHyperLinkCommand,ve as UpdateHyperLinkMutation,ye as UpdateHyperLinkRefMutation,_e as UpdateRichHyperLinkCommand};
|
|
1
|
+
import { BuildTextUtils, CellValueType, CommandType, CustomRangeType, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DependentOn, Disposable, DisposableCollection, ICommandService, IConfigService, IUndoRedoService, IUniverInstanceService, Inject, Injector, LocaleService, ObjectMatrix, Plugin, Range, Rectangle, TextX, Tools, UniverInstanceType, generateRandomId, getBodySlice, isValidRange, merge, registerDependencies, sequenceExecute, sequenceExecuteAsync, toDisposable, touchDependencies } from "@univerjs/core";
|
|
2
|
+
import { addCustomRangeBySelectionFactory, deleteCustomRangeFactory, replaceSelectionFactory } from "@univerjs/docs";
|
|
3
|
+
import { AFTER_CELL_EDIT, ClearSelectionAllCommand, ClearSelectionContentCommand, ClearSelectionFormatCommand, RefRangeService, RemoveSheetCommand, SetRangeValuesCommand, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory, SheetInterceptorService, SheetsSelectionsService, UniverSheetsPlugin, getSheetCommandTarget, handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests, handleDefaultRangeChangeWithEffectRefCommands, handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests } from "@univerjs/sheets";
|
|
4
|
+
import { Subject } from "rxjs";
|
|
5
|
+
import { IDefinedNamesService, deserializeRangeWithSheet, serializeRange, serializeRangeWithSheet } from "@univerjs/engine-formula";
|
|
6
|
+
|
|
7
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
|
|
8
|
+
function _typeof(o) {
|
|
9
|
+
"@babel/helpers - typeof";
|
|
10
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
11
|
+
return typeof o;
|
|
12
|
+
} : function(o) {
|
|
13
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
14
|
+
}, _typeof(o);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
|
|
19
|
+
function toPrimitive(t, r) {
|
|
20
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
21
|
+
var e = t[Symbol.toPrimitive];
|
|
22
|
+
if (void 0 !== e) {
|
|
23
|
+
var i = e.call(t, r || "default");
|
|
24
|
+
if ("object" != _typeof(i)) return i;
|
|
25
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
26
|
+
}
|
|
27
|
+
return ("string" === r ? String : Number)(t);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
|
|
32
|
+
function toPropertyKey(t) {
|
|
33
|
+
var i = toPrimitive(t, "string");
|
|
34
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
|
|
39
|
+
function _defineProperty(e, r, t) {
|
|
40
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
41
|
+
value: t,
|
|
42
|
+
enumerable: !0,
|
|
43
|
+
configurable: !0,
|
|
44
|
+
writable: !0
|
|
45
|
+
}) : e[r] = t, e;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
|
|
50
|
+
function __decorateParam(paramIndex, decorator) {
|
|
51
|
+
return function(target, key) {
|
|
52
|
+
decorator(target, key, paramIndex);
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
|
|
58
|
+
function __decorate(decorators, target, key, desc) {
|
|
59
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
60
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
61
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
62
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/models/hyper-link.model.ts
|
|
67
|
+
let HyperLinkModel = class HyperLinkModel extends Disposable {
|
|
68
|
+
constructor(_univerInstanceService) {
|
|
69
|
+
super();
|
|
70
|
+
this._univerInstanceService = _univerInstanceService;
|
|
71
|
+
_defineProperty(this, "_linkUpdate$", new Subject());
|
|
72
|
+
_defineProperty(this, "linkUpdate$", this._linkUpdate$.asObservable());
|
|
73
|
+
_defineProperty(this, "_linkMap", /* @__PURE__ */ new Map());
|
|
74
|
+
_defineProperty(this, "_linkPositionMap", /* @__PURE__ */ new Map());
|
|
75
|
+
this.disposeWithMe({ dispose: () => {
|
|
76
|
+
this._linkUpdate$.complete();
|
|
77
|
+
} });
|
|
78
|
+
}
|
|
79
|
+
_ensureMap(unitId, subUnitId) {
|
|
80
|
+
let unitMap = this._linkMap.get(unitId);
|
|
81
|
+
if (!unitMap) {
|
|
82
|
+
unitMap = /* @__PURE__ */ new Map();
|
|
83
|
+
this._linkMap.set(unitId, unitMap);
|
|
84
|
+
}
|
|
85
|
+
let matrix = unitMap.get(subUnitId);
|
|
86
|
+
if (!matrix) {
|
|
87
|
+
matrix = new ObjectMatrix();
|
|
88
|
+
unitMap.set(subUnitId, matrix);
|
|
89
|
+
}
|
|
90
|
+
let positionUnitMap = this._linkPositionMap.get(unitId);
|
|
91
|
+
if (!positionUnitMap) {
|
|
92
|
+
positionUnitMap = /* @__PURE__ */ new Map();
|
|
93
|
+
this._linkPositionMap.set(unitId, positionUnitMap);
|
|
94
|
+
}
|
|
95
|
+
let positionSubUnitMap = positionUnitMap.get(subUnitId);
|
|
96
|
+
if (!positionSubUnitMap) {
|
|
97
|
+
positionSubUnitMap = /* @__PURE__ */ new Map();
|
|
98
|
+
positionUnitMap.set(subUnitId, positionSubUnitMap);
|
|
99
|
+
}
|
|
100
|
+
return {
|
|
101
|
+
matrix,
|
|
102
|
+
positionMap: positionSubUnitMap
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
addHyperLink(unitId, subUnitId, link) {
|
|
106
|
+
const { matrix, positionMap } = this._ensureMap(unitId, subUnitId);
|
|
107
|
+
matrix.setValue(link.row, link.column, link);
|
|
108
|
+
positionMap.set(link.id, {
|
|
109
|
+
row: link.row,
|
|
110
|
+
column: link.column,
|
|
111
|
+
link
|
|
112
|
+
});
|
|
113
|
+
this._linkUpdate$.next({
|
|
114
|
+
unitId,
|
|
115
|
+
subUnitId,
|
|
116
|
+
payload: link,
|
|
117
|
+
type: "add"
|
|
118
|
+
});
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
updateHyperLink(unitId, subUnitId, id, payload, silent = false) {
|
|
122
|
+
const { matrix, positionMap } = this._ensureMap(unitId, subUnitId);
|
|
123
|
+
const position = positionMap.get(id);
|
|
124
|
+
if (!position) return true;
|
|
125
|
+
const link = matrix.getValue(position.row, position.column);
|
|
126
|
+
if (!link) return true;
|
|
127
|
+
Object.assign(link, payload);
|
|
128
|
+
this._linkUpdate$.next({
|
|
129
|
+
unitId,
|
|
130
|
+
subUnitId,
|
|
131
|
+
payload: {
|
|
132
|
+
display: link.display,
|
|
133
|
+
payload: link.payload
|
|
134
|
+
},
|
|
135
|
+
id,
|
|
136
|
+
type: "update",
|
|
137
|
+
silent
|
|
138
|
+
});
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
updateHyperLinkRef(unitId, subUnitId, id, payload, silent = false) {
|
|
142
|
+
const { matrix, positionMap } = this._ensureMap(unitId, subUnitId);
|
|
143
|
+
const position = positionMap.get(id);
|
|
144
|
+
if (!position) return true;
|
|
145
|
+
let link = matrix.getValue(position.row, position.column);
|
|
146
|
+
if (!link || link.id !== id) link = position.link;
|
|
147
|
+
else matrix.realDeleteValue(position.row, position.column);
|
|
148
|
+
Object.assign(link, payload);
|
|
149
|
+
positionMap.set(id, {
|
|
150
|
+
...payload,
|
|
151
|
+
link
|
|
152
|
+
});
|
|
153
|
+
matrix.setValue(payload.row, payload.column, link);
|
|
154
|
+
this._linkUpdate$.next({
|
|
155
|
+
unitId,
|
|
156
|
+
subUnitId,
|
|
157
|
+
payload,
|
|
158
|
+
id,
|
|
159
|
+
type: "updateRef",
|
|
160
|
+
silent
|
|
161
|
+
});
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
removeHyperLink(unitId, subUnitId, id) {
|
|
165
|
+
const { matrix, positionMap } = this._ensureMap(unitId, subUnitId);
|
|
166
|
+
const position = positionMap.get(id);
|
|
167
|
+
if (!position) return false;
|
|
168
|
+
positionMap.delete(id);
|
|
169
|
+
const link = matrix.getValue(position.row, position.column);
|
|
170
|
+
if (link && link.id === id) matrix.realDeleteValue(position.row, position.column);
|
|
171
|
+
this._linkUpdate$.next({
|
|
172
|
+
unitId,
|
|
173
|
+
subUnitId,
|
|
174
|
+
payload: position.link,
|
|
175
|
+
type: "remove"
|
|
176
|
+
});
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
getHyperLink(unitId, subUnitId, id) {
|
|
180
|
+
const { matrix, positionMap } = this._ensureMap(unitId, subUnitId);
|
|
181
|
+
const position = positionMap.get(id);
|
|
182
|
+
if (!position) return;
|
|
183
|
+
return matrix.getValue(position.row, position.column);
|
|
184
|
+
}
|
|
185
|
+
getHyperLinkByLocation(unitId, subUnitId, row, column) {
|
|
186
|
+
const { matrix } = this._ensureMap(unitId, subUnitId);
|
|
187
|
+
return matrix.getValue(row, column);
|
|
188
|
+
}
|
|
189
|
+
getHyperLinkByLocationSync(unitId, subUnitId, row, column) {
|
|
190
|
+
var _workbook$getSheetByS, _ref, _cell$v, _cell$p;
|
|
191
|
+
const { matrix } = this._ensureMap(unitId, subUnitId);
|
|
192
|
+
const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
|
|
193
|
+
const cell = workbook === null || workbook === void 0 || (_workbook$getSheetByS = workbook.getSheetBySheetId(subUnitId)) === null || _workbook$getSheetByS === void 0 ? void 0 : _workbook$getSheetByS.getCellRaw(row, column);
|
|
194
|
+
const cellValueStr = ((_ref = (_cell$v = cell === null || cell === void 0 ? void 0 : cell.v) !== null && _cell$v !== void 0 ? _cell$v : cell === null || cell === void 0 || (_cell$p = cell.p) === null || _cell$p === void 0 || (_cell$p = _cell$p.body) === null || _cell$p === void 0 ? void 0 : _cell$p.dataStream.slice(0, -2)) !== null && _ref !== void 0 ? _ref : "").toString();
|
|
195
|
+
const link = matrix.getValue(row, column);
|
|
196
|
+
if (!link) return;
|
|
197
|
+
return {
|
|
198
|
+
...link,
|
|
199
|
+
display: cellValueStr
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
getSubUnit(unitId, subUnitId) {
|
|
203
|
+
const { matrix } = this._ensureMap(unitId, subUnitId);
|
|
204
|
+
const links = [];
|
|
205
|
+
matrix.forValue((row, col, value) => {
|
|
206
|
+
if (value) links.push(value);
|
|
207
|
+
});
|
|
208
|
+
return links;
|
|
209
|
+
}
|
|
210
|
+
getUnit(unitId) {
|
|
211
|
+
const unitMap = this._linkMap.get(unitId);
|
|
212
|
+
if (!unitMap) return [];
|
|
213
|
+
return Array.from(unitMap.keys()).map((subUnitId) => {
|
|
214
|
+
return {
|
|
215
|
+
unitId,
|
|
216
|
+
subUnitId,
|
|
217
|
+
links: this.getSubUnit(unitId, subUnitId)
|
|
218
|
+
};
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
deleteUnit(unitId) {
|
|
222
|
+
const links = this.getUnit(unitId);
|
|
223
|
+
this._linkMap.delete(unitId);
|
|
224
|
+
this._linkPositionMap.delete(unitId);
|
|
225
|
+
this._linkUpdate$.next({
|
|
226
|
+
type: "unload",
|
|
227
|
+
unitId,
|
|
228
|
+
unitLinks: links
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
getAll() {
|
|
232
|
+
return Array.from(this._linkMap.keys()).map((unitId) => this.getUnit(unitId));
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
HyperLinkModel = __decorate([__decorateParam(0, IUniverInstanceService)], HyperLinkModel);
|
|
236
|
+
|
|
237
|
+
//#endregion
|
|
238
|
+
//#region src/commands/mutations/add-hyper-link.mutation.ts
|
|
239
|
+
const AddHyperLinkMutation = {
|
|
240
|
+
type: CommandType.MUTATION,
|
|
241
|
+
id: "sheets.mutation.add-hyper-link",
|
|
242
|
+
handler(accessor, params) {
|
|
243
|
+
if (!params) return false;
|
|
244
|
+
const model = accessor.get(HyperLinkModel);
|
|
245
|
+
const { unitId, subUnitId, link } = params;
|
|
246
|
+
return model.addHyperLink(unitId, subUnitId, link);
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
//#endregion
|
|
251
|
+
//#region src/commands/mutations/remove-hyper-link.mutation.ts
|
|
252
|
+
const RemoveHyperLinkMutation = {
|
|
253
|
+
type: CommandType.MUTATION,
|
|
254
|
+
id: "sheets.mutation.remove-hyper-link",
|
|
255
|
+
handler(accessor, params) {
|
|
256
|
+
if (!params) return false;
|
|
257
|
+
const model = accessor.get(HyperLinkModel);
|
|
258
|
+
const { unitId, subUnitId, id } = params;
|
|
259
|
+
return model.removeHyperLink(unitId, subUnitId, id);
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
//#endregion
|
|
264
|
+
//#region src/commands/commands/add-hyper-link.command.ts
|
|
265
|
+
/**
|
|
266
|
+
* Command for add hyperlink
|
|
267
|
+
*/
|
|
268
|
+
const AddHyperLinkCommand = {
|
|
269
|
+
type: CommandType.COMMAND,
|
|
270
|
+
id: "sheets.command.add-hyper-link",
|
|
271
|
+
async handler(accessor, params) {
|
|
272
|
+
if (!params) return false;
|
|
273
|
+
const commandService = accessor.get(ICommandService);
|
|
274
|
+
const undoRedoService = accessor.get(IUndoRedoService);
|
|
275
|
+
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
276
|
+
const hyperLinkModel = accessor.get(HyperLinkModel);
|
|
277
|
+
const sheetInterceptorService = accessor.get(SheetInterceptorService);
|
|
278
|
+
const target = getSheetCommandTarget(univerInstanceService, params);
|
|
279
|
+
if (!target) return false;
|
|
280
|
+
const { unitId, subUnitId, workbook, worksheet } = target;
|
|
281
|
+
const { link } = params;
|
|
282
|
+
const { payload, display, row, column, id } = link;
|
|
283
|
+
const cellData = worksheet.getCell(row, column);
|
|
284
|
+
const doc = worksheet.getBlankCellDocumentModel(cellData, row, column);
|
|
285
|
+
const snapshot = doc.documentModel.getSnapshot();
|
|
286
|
+
const body = Tools.deepClone(snapshot.body);
|
|
287
|
+
if (!body) return false;
|
|
288
|
+
let textX;
|
|
289
|
+
if (display) textX = BuildTextUtils.selection.replace({
|
|
290
|
+
selection: {
|
|
291
|
+
startOffset: 0,
|
|
292
|
+
endOffset: body.dataStream.length - 2,
|
|
293
|
+
collapsed: body.dataStream.length - 2 === 0
|
|
294
|
+
},
|
|
295
|
+
body: {
|
|
296
|
+
dataStream: `${display}`,
|
|
297
|
+
customRanges: [{
|
|
298
|
+
startIndex: 0,
|
|
299
|
+
endIndex: display.length - 1,
|
|
300
|
+
rangeType: CustomRangeType.HYPERLINK,
|
|
301
|
+
rangeId: id,
|
|
302
|
+
properties: { url: payload }
|
|
303
|
+
}]
|
|
304
|
+
},
|
|
305
|
+
doc: doc.documentModel
|
|
306
|
+
});
|
|
307
|
+
else textX = BuildTextUtils.customRange.add({
|
|
308
|
+
body,
|
|
309
|
+
ranges: [{
|
|
310
|
+
startOffset: 0,
|
|
311
|
+
endOffset: body.dataStream.length - 2,
|
|
312
|
+
collapsed: false
|
|
313
|
+
}],
|
|
314
|
+
rangeId: id,
|
|
315
|
+
rangeType: CustomRangeType.HYPERLINK,
|
|
316
|
+
properties: {
|
|
317
|
+
url: payload,
|
|
318
|
+
refId: id
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
if (!textX) return false;
|
|
322
|
+
const newBody = TextX.apply(body, textX.serialize());
|
|
323
|
+
const newCellData = {
|
|
324
|
+
p: {
|
|
325
|
+
...snapshot,
|
|
326
|
+
body: newBody
|
|
327
|
+
},
|
|
328
|
+
t: CellValueType.STRING
|
|
329
|
+
};
|
|
330
|
+
const finalCellData = sheetInterceptorService.onWriteCell(workbook, worksheet, row, column, newCellData);
|
|
331
|
+
const redoParams = {
|
|
332
|
+
unitId,
|
|
333
|
+
subUnitId,
|
|
334
|
+
cellValue: { [link.row]: { [link.column]: finalCellData } }
|
|
335
|
+
};
|
|
336
|
+
const redo = {
|
|
337
|
+
id: SetRangeValuesMutation.id,
|
|
338
|
+
params: redoParams
|
|
339
|
+
};
|
|
340
|
+
const undoParams = SetRangeValuesUndoMutationFactory(accessor, redoParams);
|
|
341
|
+
const undo = {
|
|
342
|
+
id: SetRangeValuesMutation.id,
|
|
343
|
+
params: undoParams
|
|
344
|
+
};
|
|
345
|
+
const redos = [redo];
|
|
346
|
+
const undos = [undo];
|
|
347
|
+
const modelLink = hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
|
|
348
|
+
if (modelLink) {
|
|
349
|
+
redos.push({
|
|
350
|
+
id: RemoveHyperLinkMutation.id,
|
|
351
|
+
params: {
|
|
352
|
+
unitId,
|
|
353
|
+
subUnitId,
|
|
354
|
+
id: modelLink.id
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
undos.push({
|
|
358
|
+
id: AddHyperLinkMutation.id,
|
|
359
|
+
params: {
|
|
360
|
+
unitId,
|
|
361
|
+
subUnitId,
|
|
362
|
+
link: modelLink
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
if (await sequenceExecute(redos, commandService)) {
|
|
367
|
+
if (await sheetInterceptorService.onValidateCell(workbook, worksheet, row, column) === false) {
|
|
368
|
+
sequenceExecute(undos, commandService);
|
|
369
|
+
return false;
|
|
370
|
+
}
|
|
371
|
+
undoRedoService.pushUndoRedo({
|
|
372
|
+
redoMutations: redos,
|
|
373
|
+
undoMutations: undos,
|
|
374
|
+
unitID: unitId
|
|
375
|
+
});
|
|
376
|
+
return true;
|
|
377
|
+
}
|
|
378
|
+
return false;
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
const AddRichHyperLinkCommand = {
|
|
382
|
+
id: "sheets.command.add-rich-hyper-link",
|
|
383
|
+
type: CommandType.COMMAND,
|
|
384
|
+
handler: async (accessor, params) => {
|
|
385
|
+
if (!params) return false;
|
|
386
|
+
const { documentId, link } = params;
|
|
387
|
+
const commandService = accessor.get(ICommandService);
|
|
388
|
+
const newId = generateRandomId();
|
|
389
|
+
const { payload } = link;
|
|
390
|
+
const replaceSelection = addCustomRangeBySelectionFactory(accessor, {
|
|
391
|
+
unitId: documentId,
|
|
392
|
+
rangeId: newId,
|
|
393
|
+
rangeType: CustomRangeType.HYPERLINK,
|
|
394
|
+
properties: {
|
|
395
|
+
url: payload,
|
|
396
|
+
refId: newId
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
if (replaceSelection) return commandService.syncExecuteCommand(replaceSelection.id, replaceSelection.params);
|
|
400
|
+
return false;
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
//#endregion
|
|
405
|
+
//#region src/commands/commands/remove-hyper-link.command.ts
|
|
406
|
+
const CancelHyperLinkCommand = {
|
|
407
|
+
type: CommandType.COMMAND,
|
|
408
|
+
id: "sheets.command.cancel-hyper-link",
|
|
409
|
+
handler(accessor, params) {
|
|
410
|
+
var _snapshot$body;
|
|
411
|
+
if (!params) return false;
|
|
412
|
+
const commandService = accessor.get(ICommandService);
|
|
413
|
+
const undoRedoService = accessor.get(IUndoRedoService);
|
|
414
|
+
const instanceSrv = accessor.get(IUniverInstanceService);
|
|
415
|
+
const hyperLinkModel = accessor.get(HyperLinkModel);
|
|
416
|
+
const target = getSheetCommandTarget(instanceSrv, params);
|
|
417
|
+
if (!target) return false;
|
|
418
|
+
const { row, column, id } = params;
|
|
419
|
+
const { unitId, subUnitId, worksheet } = target;
|
|
420
|
+
const cellData = worksheet.getCell(row, column);
|
|
421
|
+
if (!cellData) return false;
|
|
422
|
+
const doc = worksheet.getCellDocumentModelWithFormula(cellData, row, column);
|
|
423
|
+
if (!(doc === null || doc === void 0 ? void 0 : doc.documentModel)) return false;
|
|
424
|
+
const snapshot = Tools.deepClone(doc.documentModel.getSnapshot());
|
|
425
|
+
const range = (_snapshot$body = snapshot.body) === null || _snapshot$body === void 0 || (_snapshot$body = _snapshot$body.customRanges) === null || _snapshot$body === void 0 ? void 0 : _snapshot$body.find((range) => `${range.rangeId}` === id);
|
|
426
|
+
if (!range) return false;
|
|
427
|
+
const textX = BuildTextUtils.customRange.delete({
|
|
428
|
+
documentDataModel: doc.documentModel,
|
|
429
|
+
rangeId: range.rangeId
|
|
430
|
+
});
|
|
431
|
+
if (!textX) return false;
|
|
432
|
+
const newBody = TextX.apply(snapshot.body, textX.serialize());
|
|
433
|
+
const redos = [];
|
|
434
|
+
const undos = [];
|
|
435
|
+
const setRangeParams = {
|
|
436
|
+
unitId,
|
|
437
|
+
subUnitId,
|
|
438
|
+
cellValue: { [row]: { [column]: {
|
|
439
|
+
p: {
|
|
440
|
+
...snapshot,
|
|
441
|
+
body: newBody
|
|
442
|
+
},
|
|
443
|
+
t: CellValueType.STRING
|
|
444
|
+
} } }
|
|
445
|
+
};
|
|
446
|
+
redos.push({
|
|
447
|
+
id: SetRangeValuesMutation.id,
|
|
448
|
+
params: setRangeParams
|
|
449
|
+
});
|
|
450
|
+
const undoParams = SetRangeValuesUndoMutationFactory(accessor, setRangeParams);
|
|
451
|
+
undos.push({
|
|
452
|
+
id: SetRangeValuesMutation.id,
|
|
453
|
+
params: undoParams
|
|
454
|
+
});
|
|
455
|
+
const link = hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
|
|
456
|
+
if (link) {
|
|
457
|
+
redos.push({
|
|
458
|
+
id: RemoveHyperLinkMutation.id,
|
|
459
|
+
params: {
|
|
460
|
+
unitId,
|
|
461
|
+
subUnitId,
|
|
462
|
+
id: link.id
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
undos.push({
|
|
466
|
+
id: AddHyperLinkMutation.id,
|
|
467
|
+
params: {
|
|
468
|
+
unitId,
|
|
469
|
+
subUnitId,
|
|
470
|
+
link: { ...link }
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
if (sequenceExecute(redos, commandService).result) {
|
|
475
|
+
undoRedoService.pushUndoRedo({
|
|
476
|
+
redoMutations: redos,
|
|
477
|
+
undoMutations: undos,
|
|
478
|
+
unitID: unitId
|
|
479
|
+
});
|
|
480
|
+
return true;
|
|
481
|
+
}
|
|
482
|
+
return false;
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
const CancelRichHyperLinkCommand = {
|
|
486
|
+
type: CommandType.COMMAND,
|
|
487
|
+
id: "sheets.command.cancel-rich-hyper-link",
|
|
488
|
+
handler(accessor, params) {
|
|
489
|
+
var _doc$getBody;
|
|
490
|
+
if (!params) return false;
|
|
491
|
+
const { id: linkId, documentId } = params;
|
|
492
|
+
const commandService = accessor.get(ICommandService);
|
|
493
|
+
const doc = accessor.get(IUniverInstanceService).getUnit(documentId, UniverInstanceType.UNIVER_DOC);
|
|
494
|
+
const link = doc === null || doc === void 0 || (_doc$getBody = doc.getBody()) === null || _doc$getBody === void 0 || (_doc$getBody = _doc$getBody.customRanges) === null || _doc$getBody === void 0 ? void 0 : _doc$getBody.find((i) => i.rangeId === linkId);
|
|
495
|
+
let insert = null;
|
|
496
|
+
if (link && link.endIndex === doc.getBody().dataStream.length - 3) insert = { dataStream: " " };
|
|
497
|
+
const doMutation = deleteCustomRangeFactory(accessor, {
|
|
498
|
+
unitId: documentId,
|
|
499
|
+
rangeId: linkId,
|
|
500
|
+
insert
|
|
501
|
+
});
|
|
502
|
+
if (!doMutation) return false;
|
|
503
|
+
return commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
//#endregion
|
|
508
|
+
//#region src/commands/commands/update-hyper-link.command.ts
|
|
509
|
+
const UpdateHyperLinkCommand = {
|
|
510
|
+
type: CommandType.COMMAND,
|
|
511
|
+
id: "sheets.command.update-hyper-link",
|
|
512
|
+
async handler(accessor, params) {
|
|
513
|
+
var _snapshot$body, _oldBody$textRuns;
|
|
514
|
+
if (!params) return false;
|
|
515
|
+
const commandService = accessor.get(ICommandService);
|
|
516
|
+
const undoRedoService = accessor.get(IUndoRedoService);
|
|
517
|
+
const instanceSrv = accessor.get(IUniverInstanceService);
|
|
518
|
+
const hyperLinkModel = accessor.get(HyperLinkModel);
|
|
519
|
+
const interceptorService = accessor.get(SheetInterceptorService);
|
|
520
|
+
const target = getSheetCommandTarget(instanceSrv, {
|
|
521
|
+
unitId: params.unitId,
|
|
522
|
+
subUnitId: params.subUnitId
|
|
523
|
+
});
|
|
524
|
+
if (!target) return false;
|
|
525
|
+
const { payload: link, row, column, id } = params;
|
|
526
|
+
const { workbook, worksheet, unitId, subUnitId } = target;
|
|
527
|
+
const { payload, display = "" } = link;
|
|
528
|
+
const cellData = worksheet.getCell(row, column);
|
|
529
|
+
if (!cellData) return false;
|
|
530
|
+
const doc = worksheet.getCellDocumentModelWithFormula(cellData, row, column);
|
|
531
|
+
if (!(doc === null || doc === void 0 ? void 0 : doc.documentModel)) return false;
|
|
532
|
+
const snapshot = doc.documentModel.getSnapshot();
|
|
533
|
+
const range = (_snapshot$body = snapshot.body) === null || _snapshot$body === void 0 || (_snapshot$body = _snapshot$body.customRanges) === null || _snapshot$body === void 0 ? void 0 : _snapshot$body.find((range) => `${range.rangeId}` === id);
|
|
534
|
+
if (!range) return false;
|
|
535
|
+
const newId = generateRandomId();
|
|
536
|
+
const textRun = (_oldBody$textRuns = getBodySlice(doc.documentModel.getBody(), range.startIndex, range.endIndex + 1).textRuns) === null || _oldBody$textRuns === void 0 ? void 0 : _oldBody$textRuns[0];
|
|
537
|
+
if (textRun) textRun.ed = display.length + 1;
|
|
538
|
+
const replaceSelection = replaceSelectionFactory(accessor, {
|
|
539
|
+
unitId,
|
|
540
|
+
body: {
|
|
541
|
+
dataStream: `${display}`,
|
|
542
|
+
customRanges: [{
|
|
543
|
+
rangeId: newId,
|
|
544
|
+
rangeType: CustomRangeType.HYPERLINK,
|
|
545
|
+
startIndex: 0,
|
|
546
|
+
endIndex: display.length - 1,
|
|
547
|
+
properties: { url: payload }
|
|
548
|
+
}],
|
|
549
|
+
textRuns: textRun ? [textRun] : void 0
|
|
550
|
+
},
|
|
551
|
+
selection: {
|
|
552
|
+
startOffset: range.startIndex,
|
|
553
|
+
endOffset: range.endIndex + 1,
|
|
554
|
+
collapsed: false
|
|
555
|
+
},
|
|
556
|
+
doc: doc.documentModel
|
|
557
|
+
});
|
|
558
|
+
if (!replaceSelection) return false;
|
|
559
|
+
const newBody = TextX.apply(Tools.deepClone(snapshot.body), replaceSelection.textX.serialize());
|
|
560
|
+
const newCellData = {
|
|
561
|
+
p: {
|
|
562
|
+
...snapshot,
|
|
563
|
+
body: newBody
|
|
564
|
+
},
|
|
565
|
+
t: CellValueType.STRING
|
|
566
|
+
};
|
|
567
|
+
const finalCellData = interceptorService.onWriteCell(workbook, worksheet, row, column, newCellData);
|
|
568
|
+
const redo = {
|
|
569
|
+
id: SetRangeValuesMutation.id,
|
|
570
|
+
params: {
|
|
571
|
+
unitId,
|
|
572
|
+
subUnitId,
|
|
573
|
+
cellValue: { [row]: { [column]: finalCellData } }
|
|
574
|
+
}
|
|
575
|
+
};
|
|
576
|
+
const undoParams = SetRangeValuesUndoMutationFactory(accessor, redo.params);
|
|
577
|
+
const undo = {
|
|
578
|
+
id: SetRangeValuesMutation.id,
|
|
579
|
+
params: undoParams
|
|
580
|
+
};
|
|
581
|
+
const redos = [redo];
|
|
582
|
+
const undos = [undo];
|
|
583
|
+
const modelLink = hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, column);
|
|
584
|
+
if (modelLink) {
|
|
585
|
+
redos.push({
|
|
586
|
+
id: RemoveHyperLinkMutation.id,
|
|
587
|
+
params: {
|
|
588
|
+
unitId,
|
|
589
|
+
subUnitId,
|
|
590
|
+
id: modelLink.id
|
|
591
|
+
}
|
|
592
|
+
});
|
|
593
|
+
undos.push({
|
|
594
|
+
id: AddHyperLinkMutation.id,
|
|
595
|
+
params: {
|
|
596
|
+
unitId,
|
|
597
|
+
subUnitId,
|
|
598
|
+
link: modelLink
|
|
599
|
+
}
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
if (sequenceExecute(redos, commandService)) {
|
|
603
|
+
if (await interceptorService.onValidateCell(workbook, worksheet, row, column) === false) {
|
|
604
|
+
sequenceExecute(undos, commandService);
|
|
605
|
+
return false;
|
|
606
|
+
}
|
|
607
|
+
undoRedoService.pushUndoRedo({
|
|
608
|
+
redoMutations: redos,
|
|
609
|
+
undoMutations: undos,
|
|
610
|
+
unitID: unitId
|
|
611
|
+
});
|
|
612
|
+
return true;
|
|
613
|
+
}
|
|
614
|
+
return false;
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
const UpdateRichHyperLinkCommand = {
|
|
618
|
+
type: CommandType.COMMAND,
|
|
619
|
+
id: "sheets.command.update-rich-hyper-link",
|
|
620
|
+
handler: (accessor, params) => {
|
|
621
|
+
var _doc$getBody, _params$payload$displ, _oldBody$textRuns2;
|
|
622
|
+
if (!params) return false;
|
|
623
|
+
const { documentId: unitId, payload, id: rangeId } = params;
|
|
624
|
+
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
625
|
+
const commandService = accessor.get(ICommandService);
|
|
626
|
+
const doc = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
627
|
+
if (!doc) return false;
|
|
628
|
+
const range = (_doc$getBody = doc.getBody()) === null || _doc$getBody === void 0 || (_doc$getBody = _doc$getBody.customRanges) === null || _doc$getBody === void 0 ? void 0 : _doc$getBody.find((range) => range.rangeId === rangeId);
|
|
629
|
+
if (!range) return false;
|
|
630
|
+
const display = (_params$payload$displ = params.payload.display) !== null && _params$payload$displ !== void 0 ? _params$payload$displ : "";
|
|
631
|
+
const newId = generateRandomId();
|
|
632
|
+
const textRun = (_oldBody$textRuns2 = getBodySlice(doc.getBody(), range.startIndex, range.endIndex + 1).textRuns) === null || _oldBody$textRuns2 === void 0 ? void 0 : _oldBody$textRuns2[0];
|
|
633
|
+
if (textRun) textRun.ed = display.length + 1;
|
|
634
|
+
const replaceSelection = replaceSelectionFactory(accessor, {
|
|
635
|
+
unitId,
|
|
636
|
+
body: {
|
|
637
|
+
dataStream: `${display}`,
|
|
638
|
+
customRanges: [{
|
|
639
|
+
rangeId: newId,
|
|
640
|
+
rangeType: CustomRangeType.HYPERLINK,
|
|
641
|
+
startIndex: 0,
|
|
642
|
+
endIndex: display.length - 1,
|
|
643
|
+
properties: { url: payload.payload }
|
|
644
|
+
}],
|
|
645
|
+
textRuns: textRun ? [textRun] : void 0
|
|
646
|
+
},
|
|
647
|
+
selection: {
|
|
648
|
+
startOffset: range.startIndex,
|
|
649
|
+
endOffset: range.endIndex + 1,
|
|
650
|
+
collapsed: false
|
|
651
|
+
},
|
|
652
|
+
doc
|
|
653
|
+
});
|
|
654
|
+
if (!replaceSelection) return false;
|
|
655
|
+
return commandService.syncExecuteCommand(replaceSelection.id, replaceSelection.params);
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
|
|
659
|
+
//#endregion
|
|
660
|
+
//#region src/commands/mutations/update-hyper-link.mutation.ts
|
|
661
|
+
const UpdateHyperLinkMutation = {
|
|
662
|
+
type: CommandType.MUTATION,
|
|
663
|
+
id: "sheets.mutation.update-hyper-link",
|
|
664
|
+
handler(accessor, params) {
|
|
665
|
+
if (!params) return false;
|
|
666
|
+
const model = accessor.get(HyperLinkModel);
|
|
667
|
+
const { unitId, subUnitId, payload, id } = params;
|
|
668
|
+
return model.updateHyperLink(unitId, subUnitId, id, payload, false);
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
const UpdateHyperLinkRefMutation = {
|
|
672
|
+
type: CommandType.MUTATION,
|
|
673
|
+
id: "sheets.mutation.update-hyper-link-ref",
|
|
674
|
+
handler(accessor, params) {
|
|
675
|
+
if (!params) return false;
|
|
676
|
+
const model = accessor.get(HyperLinkModel);
|
|
677
|
+
const { unitId, subUnitId, id, row, column, silent } = params;
|
|
678
|
+
return model.updateHyperLinkRef(unitId, subUnitId, id, {
|
|
679
|
+
row,
|
|
680
|
+
column
|
|
681
|
+
}, silent);
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
const UpdateRichHyperLinkMutation = {
|
|
685
|
+
type: CommandType.MUTATION,
|
|
686
|
+
id: "sheets.mutation.update-rich-hyper-link",
|
|
687
|
+
handler(accessor, params) {
|
|
688
|
+
var _cell$p;
|
|
689
|
+
if (!params) return false;
|
|
690
|
+
const { unitId, subUnitId, row, col, id, url } = params;
|
|
691
|
+
const sheetTarget = getSheetCommandTarget(accessor.get(IUniverInstanceService), {
|
|
692
|
+
unitId,
|
|
693
|
+
subUnitId
|
|
694
|
+
});
|
|
695
|
+
if (!sheetTarget) return false;
|
|
696
|
+
const { worksheet } = sheetTarget;
|
|
697
|
+
const cell = worksheet.getCellRaw(row, col);
|
|
698
|
+
const link = cell === null || cell === void 0 || (_cell$p = cell.p) === null || _cell$p === void 0 || (_cell$p = _cell$p.body) === null || _cell$p === void 0 || (_cell$p = _cell$p.customRanges) === null || _cell$p === void 0 ? void 0 : _cell$p.find((range) => range.rangeType === CustomRangeType.HYPERLINK && range.rangeId === id);
|
|
699
|
+
if (!link) return true;
|
|
700
|
+
link.properties.url = url;
|
|
701
|
+
return true;
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
|
|
705
|
+
//#endregion
|
|
706
|
+
//#region package.json
|
|
707
|
+
var name = "@univerjs/sheets-hyper-link";
|
|
708
|
+
var version = "0.21.0";
|
|
709
|
+
|
|
710
|
+
//#endregion
|
|
711
|
+
//#region src/config/config.ts
|
|
712
|
+
/**
|
|
713
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
714
|
+
*
|
|
715
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
716
|
+
* you may not use this file except in compliance with the License.
|
|
717
|
+
* You may obtain a copy of the License at
|
|
718
|
+
*
|
|
719
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
720
|
+
*
|
|
721
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
722
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
723
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
724
|
+
* See the License for the specific language governing permissions and
|
|
725
|
+
* limitations under the License.
|
|
726
|
+
*/
|
|
727
|
+
const SHEETS_HYPER_LINK_PLUGIN_CONFIG_KEY = "sheets-hyper-link.config";
|
|
728
|
+
const configSymbol = Symbol(SHEETS_HYPER_LINK_PLUGIN_CONFIG_KEY);
|
|
729
|
+
const defaultPluginConfig = {};
|
|
730
|
+
|
|
731
|
+
//#endregion
|
|
732
|
+
//#region src/types/const.ts
|
|
733
|
+
/**
|
|
734
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
735
|
+
*
|
|
736
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
737
|
+
* you may not use this file except in compliance with the License.
|
|
738
|
+
* You may obtain a copy of the License at
|
|
739
|
+
*
|
|
740
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
741
|
+
*
|
|
742
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
743
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
744
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
745
|
+
* See the License for the specific language governing permissions and
|
|
746
|
+
* limitations under the License.
|
|
747
|
+
*/
|
|
748
|
+
const SHEET_HYPER_LINK_PLUGIN = "SHEET_HYPER_LINK_PLUGIN";
|
|
749
|
+
const ERROR_RANGE = "err";
|
|
750
|
+
|
|
751
|
+
//#endregion
|
|
752
|
+
//#region src/controllers/ref-range.controller.ts
|
|
753
|
+
let SheetsHyperLinkRefRangeController = class SheetsHyperLinkRefRangeController extends Disposable {
|
|
754
|
+
constructor(_refRangeService, _hyperLinkModel, _selectionManagerService, _commandService) {
|
|
755
|
+
super();
|
|
756
|
+
this._refRangeService = _refRangeService;
|
|
757
|
+
this._hyperLinkModel = _hyperLinkModel;
|
|
758
|
+
this._selectionManagerService = _selectionManagerService;
|
|
759
|
+
this._commandService = _commandService;
|
|
760
|
+
_defineProperty(this, "_disposableMap", /* @__PURE__ */ new Map());
|
|
761
|
+
_defineProperty(this, "_watchDisposableMap", /* @__PURE__ */ new Map());
|
|
762
|
+
_defineProperty(this, "_rangeDisableMap", /* @__PURE__ */ new Map());
|
|
763
|
+
_defineProperty(this, "_rangeWatcherMap", /* @__PURE__ */ new Map());
|
|
764
|
+
_defineProperty(this, "_handlePositionChange", (unitId, subUnitId, link, resultRange, silent) => {
|
|
765
|
+
const oldRange = {
|
|
766
|
+
startColumn: link.column,
|
|
767
|
+
endColumn: link.column,
|
|
768
|
+
startRow: link.row,
|
|
769
|
+
endRow: link.row
|
|
770
|
+
};
|
|
771
|
+
if (!resultRange) return {
|
|
772
|
+
redos: [{
|
|
773
|
+
id: RemoveHyperLinkMutation.id,
|
|
774
|
+
params: {
|
|
775
|
+
unitId,
|
|
776
|
+
subUnitId,
|
|
777
|
+
id: link.id
|
|
778
|
+
}
|
|
779
|
+
}],
|
|
780
|
+
undos: [{
|
|
781
|
+
id: AddHyperLinkMutation.id,
|
|
782
|
+
params: {
|
|
783
|
+
unitId,
|
|
784
|
+
subUnitId,
|
|
785
|
+
link
|
|
786
|
+
}
|
|
787
|
+
}]
|
|
788
|
+
};
|
|
789
|
+
return {
|
|
790
|
+
redos: [{
|
|
791
|
+
id: UpdateHyperLinkRefMutation.id,
|
|
792
|
+
params: {
|
|
793
|
+
unitId,
|
|
794
|
+
subUnitId,
|
|
795
|
+
id: link.id,
|
|
796
|
+
row: resultRange.startRow,
|
|
797
|
+
column: resultRange.startColumn,
|
|
798
|
+
silent
|
|
799
|
+
}
|
|
800
|
+
}],
|
|
801
|
+
undos: [{
|
|
802
|
+
id: UpdateHyperLinkRefMutation.id,
|
|
803
|
+
params: {
|
|
804
|
+
unitId,
|
|
805
|
+
subUnitId,
|
|
806
|
+
id: link.id,
|
|
807
|
+
row: oldRange.startRow,
|
|
808
|
+
column: oldRange.startColumn,
|
|
809
|
+
silent
|
|
810
|
+
}
|
|
811
|
+
}]
|
|
812
|
+
};
|
|
813
|
+
});
|
|
814
|
+
this._initData();
|
|
815
|
+
this._initRefRange();
|
|
816
|
+
}
|
|
817
|
+
_registerPosition(unitId, subUnitId, link) {
|
|
818
|
+
const id = link.id;
|
|
819
|
+
const oldRange = {
|
|
820
|
+
startColumn: link.column,
|
|
821
|
+
endColumn: link.column,
|
|
822
|
+
startRow: link.row,
|
|
823
|
+
endRow: link.row
|
|
824
|
+
};
|
|
825
|
+
const handleRefRangeChange = (commandInfo) => {
|
|
826
|
+
const resultRanges = handleCommonRangeChangeWithEffectRefCommandsSkipNoInterests(oldRange, commandInfo, { selectionManagerService: this._selectionManagerService });
|
|
827
|
+
const resultRange = Array.isArray(resultRanges) ? resultRanges[0] : resultRanges;
|
|
828
|
+
if (resultRange && resultRange.startColumn === oldRange.startColumn && resultRange.startRow === oldRange.startRow) return {
|
|
829
|
+
undos: [],
|
|
830
|
+
redos: []
|
|
831
|
+
};
|
|
832
|
+
return this._handlePositionChange(unitId, subUnitId, link, resultRange, false);
|
|
833
|
+
};
|
|
834
|
+
this._disposableMap.set(id, this._refRangeService.registerRefRange(oldRange, handleRefRangeChange, unitId, subUnitId));
|
|
835
|
+
}
|
|
836
|
+
_watchPosition(unitId, subUnitId, link) {
|
|
837
|
+
const id = link.id;
|
|
838
|
+
const oldRange = {
|
|
839
|
+
startColumn: link.column,
|
|
840
|
+
endColumn: link.column,
|
|
841
|
+
startRow: link.row,
|
|
842
|
+
endRow: link.row
|
|
843
|
+
};
|
|
844
|
+
this._watchDisposableMap.set(id, this._refRangeService.watchRange(unitId, subUnitId, oldRange, (before, after) => {
|
|
845
|
+
const { redos } = this._handlePositionChange(unitId, subUnitId, link, after, true);
|
|
846
|
+
sequenceExecuteAsync(redos, this._commandService, { onlyLocal: true });
|
|
847
|
+
}, true));
|
|
848
|
+
}
|
|
849
|
+
_unregisterPosition(id) {
|
|
850
|
+
const disposable = this._disposableMap.get(id);
|
|
851
|
+
disposable === null || disposable === void 0 || disposable.dispose();
|
|
852
|
+
this._disposableMap.delete(id);
|
|
853
|
+
}
|
|
854
|
+
_unwatchPosition(id) {
|
|
855
|
+
const disposable = this._watchDisposableMap.get(id);
|
|
856
|
+
disposable === null || disposable === void 0 || disposable.dispose();
|
|
857
|
+
this._watchDisposableMap.delete(id);
|
|
858
|
+
}
|
|
859
|
+
_registerRange(unitId, id, payload, silent = false) {
|
|
860
|
+
if (payload.startsWith("#")) {
|
|
861
|
+
var _search$get, _search$get2, _search$get3;
|
|
862
|
+
const search = new URLSearchParams(payload.slice(1));
|
|
863
|
+
const searchObj = {
|
|
864
|
+
gid: (_search$get = search.get("gid")) !== null && _search$get !== void 0 ? _search$get : "",
|
|
865
|
+
range: (_search$get2 = search.get("range")) !== null && _search$get2 !== void 0 ? _search$get2 : "",
|
|
866
|
+
rangeid: (_search$get3 = search.get("rangeid")) !== null && _search$get3 !== void 0 ? _search$get3 : ""
|
|
867
|
+
};
|
|
868
|
+
if (searchObj.range && searchObj.gid) {
|
|
869
|
+
const subUnitId = searchObj.gid;
|
|
870
|
+
const range = deserializeRangeWithSheet(searchObj.range).range;
|
|
871
|
+
if (isValidRange(range) && searchObj.range !== "err") {
|
|
872
|
+
const handleRangeChange = (commandInfo) => {
|
|
873
|
+
const resultRange = handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(range, commandInfo, { selectionManagerService: this._selectionManagerService });
|
|
874
|
+
if (resultRange && serializeRange(resultRange) === serializeRange(range)) return {
|
|
875
|
+
redos: [],
|
|
876
|
+
undos: []
|
|
877
|
+
};
|
|
878
|
+
return {
|
|
879
|
+
redos: [{
|
|
880
|
+
id: UpdateHyperLinkMutation.id,
|
|
881
|
+
params: {
|
|
882
|
+
unitId,
|
|
883
|
+
subUnitId,
|
|
884
|
+
id,
|
|
885
|
+
payload: { payload: `#gid=${subUnitId}&range=${resultRange ? serializeRange(resultRange) : "err"}` }
|
|
886
|
+
}
|
|
887
|
+
}],
|
|
888
|
+
undos: [{
|
|
889
|
+
id: UpdateHyperLinkMutation.id,
|
|
890
|
+
params: {
|
|
891
|
+
unitId,
|
|
892
|
+
subUnitId,
|
|
893
|
+
id,
|
|
894
|
+
payload: { payload }
|
|
895
|
+
}
|
|
896
|
+
}]
|
|
897
|
+
};
|
|
898
|
+
};
|
|
899
|
+
this._rangeDisableMap.set(id, this._refRangeService.registerRefRange(range, handleRangeChange, unitId, subUnitId));
|
|
900
|
+
if (!silent) this._rangeWatcherMap.set(id, this._refRangeService.watchRange(unitId, subUnitId, range, (before, after) => {
|
|
901
|
+
this._hyperLinkModel.updateHyperLink(unitId, subUnitId, id, { payload: `#gid=${subUnitId}&range=${after ? serializeRange(after) : "err"}` }, true);
|
|
902
|
+
}, true));
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
_unregisterRange(id) {
|
|
908
|
+
const disposable = this._rangeDisableMap.get(id);
|
|
909
|
+
disposable === null || disposable === void 0 || disposable.dispose();
|
|
910
|
+
this._rangeDisableMap.delete(id);
|
|
911
|
+
}
|
|
912
|
+
_unwatchRange(id) {
|
|
913
|
+
const disposable = this._rangeWatcherMap.get(id);
|
|
914
|
+
disposable === null || disposable === void 0 || disposable.dispose();
|
|
915
|
+
this._rangeWatcherMap.delete(id);
|
|
916
|
+
}
|
|
917
|
+
_initData() {
|
|
918
|
+
this._hyperLinkModel.getAll().forEach((unitData) => {
|
|
919
|
+
unitData.forEach((subUnitData) => {
|
|
920
|
+
const { unitId, subUnitId, links } = subUnitData;
|
|
921
|
+
links.forEach((link) => {
|
|
922
|
+
this._registerPosition(unitId, subUnitId, link);
|
|
923
|
+
this._watchPosition(unitId, subUnitId, link);
|
|
924
|
+
this._registerRange(unitId, link.id, link.payload);
|
|
925
|
+
});
|
|
926
|
+
});
|
|
927
|
+
});
|
|
928
|
+
}
|
|
929
|
+
_initRefRange() {
|
|
930
|
+
this.disposeWithMe(this._hyperLinkModel.linkUpdate$.subscribe((option) => {
|
|
931
|
+
switch (option.type) {
|
|
932
|
+
case "add":
|
|
933
|
+
this._registerPosition(option.unitId, option.subUnitId, option.payload);
|
|
934
|
+
this._watchPosition(option.unitId, option.subUnitId, option.payload);
|
|
935
|
+
this._registerRange(option.unitId, option.payload.id, option.payload.payload);
|
|
936
|
+
break;
|
|
937
|
+
case "remove":
|
|
938
|
+
this._unregisterPosition(option.payload.id);
|
|
939
|
+
this._unwatchPosition(option.payload.id);
|
|
940
|
+
this._unregisterRange(option.payload.id);
|
|
941
|
+
this._unwatchRange(option.payload.id);
|
|
942
|
+
break;
|
|
943
|
+
case "updateRef": {
|
|
944
|
+
const { unitId, subUnitId, id, silent } = option;
|
|
945
|
+
const link = this._hyperLinkModel.getHyperLink(unitId, subUnitId, id);
|
|
946
|
+
if (!link) return;
|
|
947
|
+
this._unregisterPosition(id);
|
|
948
|
+
this._registerPosition(unitId, subUnitId, link);
|
|
949
|
+
if (!silent) {
|
|
950
|
+
this._unwatchPosition(id);
|
|
951
|
+
this._watchPosition(unitId, subUnitId, link);
|
|
952
|
+
}
|
|
953
|
+
break;
|
|
954
|
+
}
|
|
955
|
+
case "unload": {
|
|
956
|
+
const { unitLinks } = option;
|
|
957
|
+
unitLinks.forEach((subUnitData) => {
|
|
958
|
+
const { links } = subUnitData;
|
|
959
|
+
links.forEach((link) => {
|
|
960
|
+
this._unregisterPosition(link.id);
|
|
961
|
+
this._unwatchPosition(link.id);
|
|
962
|
+
this._unregisterRange(link.id);
|
|
963
|
+
this._unwatchRange(link.id);
|
|
964
|
+
});
|
|
965
|
+
});
|
|
966
|
+
break;
|
|
967
|
+
}
|
|
968
|
+
case "update":
|
|
969
|
+
if (!option.silent) this._unwatchRange(option.id);
|
|
970
|
+
this._unregisterRange(option.id);
|
|
971
|
+
this._registerRange(option.unitId, option.id, option.payload.payload, option.silent);
|
|
972
|
+
break;
|
|
973
|
+
}
|
|
974
|
+
}));
|
|
975
|
+
this.disposeWithMe(toDisposable(() => {
|
|
976
|
+
this._disposableMap.forEach((item) => {
|
|
977
|
+
item.dispose();
|
|
978
|
+
});
|
|
979
|
+
this._disposableMap.clear();
|
|
980
|
+
}));
|
|
981
|
+
}
|
|
982
|
+
};
|
|
983
|
+
SheetsHyperLinkRefRangeController = __decorate([
|
|
984
|
+
__decorateParam(0, Inject(RefRangeService)),
|
|
985
|
+
__decorateParam(1, Inject(HyperLinkModel)),
|
|
986
|
+
__decorateParam(2, Inject(SheetsSelectionsService)),
|
|
987
|
+
__decorateParam(3, ICommandService)
|
|
988
|
+
], SheetsHyperLinkRefRangeController);
|
|
989
|
+
|
|
990
|
+
//#endregion
|
|
991
|
+
//#region src/controllers/remove-sheet.controller.ts
|
|
992
|
+
let SheetsHyperLinkRemoveSheetController = class SheetsHyperLinkRemoveSheetController extends Disposable {
|
|
993
|
+
constructor(_sheetInterceptorService, _univerInstanceService, _hyperLinkModel) {
|
|
994
|
+
super();
|
|
995
|
+
this._sheetInterceptorService = _sheetInterceptorService;
|
|
996
|
+
this._univerInstanceService = _univerInstanceService;
|
|
997
|
+
this._hyperLinkModel = _hyperLinkModel;
|
|
998
|
+
this._initSheetChange();
|
|
999
|
+
}
|
|
1000
|
+
_initSheetChange() {
|
|
1001
|
+
this.disposeWithMe(this._sheetInterceptorService.interceptCommand({ getMutations: (commandInfo) => {
|
|
1002
|
+
if (commandInfo.id === RemoveSheetCommand.id) {
|
|
1003
|
+
var _workbook$getActiveSh;
|
|
1004
|
+
const params = commandInfo.params;
|
|
1005
|
+
const workbook = params.unitId ? this._univerInstanceService.getUnit(params.unitId) : this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
|
|
1006
|
+
if (!workbook) return {
|
|
1007
|
+
redos: [],
|
|
1008
|
+
undos: []
|
|
1009
|
+
};
|
|
1010
|
+
const unitId = workbook.getUnitId();
|
|
1011
|
+
const subUnitId = params.subUnitId || ((_workbook$getActiveSh = workbook.getActiveSheet()) === null || _workbook$getActiveSh === void 0 ? void 0 : _workbook$getActiveSh.getSheetId());
|
|
1012
|
+
if (!subUnitId) return {
|
|
1013
|
+
redos: [],
|
|
1014
|
+
undos: []
|
|
1015
|
+
};
|
|
1016
|
+
const links = this._hyperLinkModel.getSubUnit(unitId, subUnitId);
|
|
1017
|
+
return {
|
|
1018
|
+
redos: links.map((link) => ({
|
|
1019
|
+
id: RemoveHyperLinkMutation.id,
|
|
1020
|
+
params: {
|
|
1021
|
+
unitId,
|
|
1022
|
+
subUnitId,
|
|
1023
|
+
id: link.id
|
|
1024
|
+
}
|
|
1025
|
+
})),
|
|
1026
|
+
undos: links.map((link) => ({
|
|
1027
|
+
id: AddHyperLinkMutation.id,
|
|
1028
|
+
params: {
|
|
1029
|
+
unitId,
|
|
1030
|
+
subUnitId,
|
|
1031
|
+
link
|
|
1032
|
+
}
|
|
1033
|
+
}))
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
return {
|
|
1037
|
+
redos: [],
|
|
1038
|
+
undos: []
|
|
1039
|
+
};
|
|
1040
|
+
} }));
|
|
1041
|
+
}
|
|
1042
|
+
};
|
|
1043
|
+
SheetsHyperLinkRemoveSheetController = __decorate([
|
|
1044
|
+
__decorateParam(0, Inject(SheetInterceptorService)),
|
|
1045
|
+
__decorateParam(1, IUniverInstanceService),
|
|
1046
|
+
__decorateParam(2, Inject(HyperLinkModel))
|
|
1047
|
+
], SheetsHyperLinkRemoveSheetController);
|
|
1048
|
+
|
|
1049
|
+
//#endregion
|
|
1050
|
+
//#region src/controllers/rich-text-ref-range.controller.ts
|
|
1051
|
+
let SheetsHyperLinkRichTextRefRangeController = class SheetsHyperLinkRichTextRefRangeController extends Disposable {
|
|
1052
|
+
constructor(_commandService, _univerInstanceService, _refRangeService) {
|
|
1053
|
+
super();
|
|
1054
|
+
this._commandService = _commandService;
|
|
1055
|
+
this._univerInstanceService = _univerInstanceService;
|
|
1056
|
+
this._refRangeService = _refRangeService;
|
|
1057
|
+
_defineProperty(this, "_refRangeMap", /* @__PURE__ */ new Map());
|
|
1058
|
+
this._initWorkbookLoad();
|
|
1059
|
+
this._initWorkbookUnload();
|
|
1060
|
+
this._initSetRangesListener();
|
|
1061
|
+
}
|
|
1062
|
+
_enusreMap(unitId, subUnitId) {
|
|
1063
|
+
let unitMap = this._refRangeMap.get(unitId);
|
|
1064
|
+
if (!unitMap) {
|
|
1065
|
+
unitMap = /* @__PURE__ */ new Map();
|
|
1066
|
+
this._refRangeMap.set(unitId, unitMap);
|
|
1067
|
+
}
|
|
1068
|
+
let subUnitMap = unitMap.get(subUnitId);
|
|
1069
|
+
if (!subUnitMap) {
|
|
1070
|
+
subUnitMap = new ObjectMatrix();
|
|
1071
|
+
unitMap.set(subUnitId, subUnitMap);
|
|
1072
|
+
}
|
|
1073
|
+
return subUnitMap;
|
|
1074
|
+
}
|
|
1075
|
+
_isLegalRangeUrl(unitId, payload) {
|
|
1076
|
+
const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
|
|
1077
|
+
if (!workbook) return null;
|
|
1078
|
+
if (payload && payload.startsWith("#")) {
|
|
1079
|
+
var _search$get, _search$get2, _search$get3;
|
|
1080
|
+
const search = new URLSearchParams(payload.slice(1));
|
|
1081
|
+
const searchObj = {
|
|
1082
|
+
gid: (_search$get = search.get("gid")) !== null && _search$get !== void 0 ? _search$get : "",
|
|
1083
|
+
range: (_search$get2 = search.get("range")) !== null && _search$get2 !== void 0 ? _search$get2 : "",
|
|
1084
|
+
rangeid: (_search$get3 = search.get("rangeid")) !== null && _search$get3 !== void 0 ? _search$get3 : ""
|
|
1085
|
+
};
|
|
1086
|
+
if (searchObj.range && searchObj.gid) {
|
|
1087
|
+
const subUnitId = searchObj.gid;
|
|
1088
|
+
const worksheet = workbook.getSheetBySheetId(subUnitId);
|
|
1089
|
+
if (!worksheet) return null;
|
|
1090
|
+
const range = deserializeRangeWithSheet(searchObj.range).range;
|
|
1091
|
+
if (isValidRange(range, worksheet) && searchObj.range !== "err") return {
|
|
1092
|
+
range,
|
|
1093
|
+
worksheet
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
return null;
|
|
1098
|
+
}
|
|
1099
|
+
_registerRange(unitId, subUnitId, row, col, p) {
|
|
1100
|
+
var _p$body;
|
|
1101
|
+
const map = this._enusreMap(unitId, subUnitId);
|
|
1102
|
+
if ((_p$body = p.body) === null || _p$body === void 0 || (_p$body = _p$body.customRanges) === null || _p$body === void 0 ? void 0 : _p$body.some((customRange) => {
|
|
1103
|
+
var _customRange$properti;
|
|
1104
|
+
return customRange.rangeType === CustomRangeType.HYPERLINK && this._isLegalRangeUrl(unitId, (_customRange$properti = customRange.properties) === null || _customRange$properti === void 0 ? void 0 : _customRange$properti.url);
|
|
1105
|
+
})) {
|
|
1106
|
+
var _p$body2;
|
|
1107
|
+
const disposableCollection = new DisposableCollection();
|
|
1108
|
+
let hasWatch = false;
|
|
1109
|
+
(_p$body2 = p.body) === null || _p$body2 === void 0 || (_p$body2 = _p$body2.customRanges) === null || _p$body2 === void 0 || _p$body2.forEach((customRange) => {
|
|
1110
|
+
if (customRange.rangeType === CustomRangeType.HYPERLINK) {
|
|
1111
|
+
var _customRange$properti2;
|
|
1112
|
+
const payload = (_customRange$properti2 = customRange.properties) === null || _customRange$properti2 === void 0 ? void 0 : _customRange$properti2.url;
|
|
1113
|
+
const rangeInfo = this._isLegalRangeUrl(unitId, payload);
|
|
1114
|
+
if (rangeInfo) {
|
|
1115
|
+
const { range, worksheet } = rangeInfo;
|
|
1116
|
+
hasWatch = true;
|
|
1117
|
+
disposableCollection.add(this._refRangeService.registerRefRange(range, (commandInfo) => {
|
|
1118
|
+
const newRange = handleDefaultRangeChangeWithEffectRefCommands(range, commandInfo);
|
|
1119
|
+
if (newRange && Rectangle.equals(newRange, range)) return {
|
|
1120
|
+
preRedos: [],
|
|
1121
|
+
preUndos: [],
|
|
1122
|
+
redos: [],
|
|
1123
|
+
undos: []
|
|
1124
|
+
};
|
|
1125
|
+
return {
|
|
1126
|
+
preRedos: [{
|
|
1127
|
+
id: UpdateRichHyperLinkMutation.id,
|
|
1128
|
+
params: {
|
|
1129
|
+
unitId,
|
|
1130
|
+
subUnitId,
|
|
1131
|
+
row,
|
|
1132
|
+
col,
|
|
1133
|
+
id: customRange.rangeId,
|
|
1134
|
+
url: `#gid=${subUnitId}&range=${newRange ? serializeRange(newRange) : "err"}`
|
|
1135
|
+
}
|
|
1136
|
+
}],
|
|
1137
|
+
undos: [{
|
|
1138
|
+
id: UpdateRichHyperLinkMutation.id,
|
|
1139
|
+
params: {
|
|
1140
|
+
unitId,
|
|
1141
|
+
subUnitId,
|
|
1142
|
+
row,
|
|
1143
|
+
col,
|
|
1144
|
+
id: customRange.rangeId,
|
|
1145
|
+
url: payload
|
|
1146
|
+
}
|
|
1147
|
+
}],
|
|
1148
|
+
redos: []
|
|
1149
|
+
};
|
|
1150
|
+
}, worksheet.getUnitId(), worksheet.getSheetId()));
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
});
|
|
1154
|
+
if (hasWatch) map.setValue(row, col, disposableCollection);
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
_initWorkbookLoad() {
|
|
1158
|
+
const handleWorkbook = (workbook) => {
|
|
1159
|
+
const unitId = workbook.getUnitId();
|
|
1160
|
+
workbook.getSheets().forEach((sheet) => {
|
|
1161
|
+
const subUnitId = sheet.getSheetId();
|
|
1162
|
+
const map = this._enusreMap(unitId, subUnitId);
|
|
1163
|
+
sheet.getCellMatrix().forValue((row, col, cell) => {
|
|
1164
|
+
const dispose = map.getValue(row, col);
|
|
1165
|
+
if (dispose) dispose.dispose();
|
|
1166
|
+
if (cell && cell.p) this._registerRange(unitId, subUnitId, row, col, cell.p);
|
|
1167
|
+
});
|
|
1168
|
+
});
|
|
1169
|
+
};
|
|
1170
|
+
this._univerInstanceService.getAllUnitsForType(UniverInstanceType.UNIVER_SHEET).forEach((workbook) => {
|
|
1171
|
+
handleWorkbook(workbook);
|
|
1172
|
+
});
|
|
1173
|
+
this.disposeWithMe(this._univerInstanceService.unitAdded$.subscribe((unit) => {
|
|
1174
|
+
if (unit.type === UniverInstanceType.UNIVER_SHEET) handleWorkbook(unit);
|
|
1175
|
+
}));
|
|
1176
|
+
}
|
|
1177
|
+
_initWorkbookUnload() {
|
|
1178
|
+
this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe((unit) => {
|
|
1179
|
+
if (unit.type === UniverInstanceType.UNIVER_SHEET) {
|
|
1180
|
+
const workbook = unit;
|
|
1181
|
+
const unitId = workbook.getUnitId();
|
|
1182
|
+
workbook.getSheets().forEach((sheet) => {
|
|
1183
|
+
const subUnitId = sheet.getSheetId();
|
|
1184
|
+
this._enusreMap(unitId, subUnitId).forValue((row, col, dispose) => {
|
|
1185
|
+
if (dispose) dispose.dispose();
|
|
1186
|
+
});
|
|
1187
|
+
});
|
|
1188
|
+
this._refRangeMap.delete(unitId);
|
|
1189
|
+
}
|
|
1190
|
+
}));
|
|
1191
|
+
}
|
|
1192
|
+
_initSetRangesListener() {
|
|
1193
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
|
|
1194
|
+
if (commandInfo.id === SetRangeValuesMutation.id) {
|
|
1195
|
+
const { unitId, subUnitId, cellValue } = commandInfo.params;
|
|
1196
|
+
const map = this._enusreMap(unitId, subUnitId);
|
|
1197
|
+
if (cellValue) new ObjectMatrix(cellValue).forValue((row, col, cell) => {
|
|
1198
|
+
const dispose = map.getValue(row, col);
|
|
1199
|
+
if (dispose) dispose.dispose();
|
|
1200
|
+
if (cell && cell.p) this._registerRange(unitId, subUnitId, row, col, cell.p);
|
|
1201
|
+
});
|
|
1202
|
+
}
|
|
1203
|
+
}));
|
|
1204
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
|
|
1205
|
+
if (commandInfo.id === UpdateRichHyperLinkMutation.id) {
|
|
1206
|
+
const { unitId, subUnitId, row, col } = commandInfo.params;
|
|
1207
|
+
const sheetTarget = getSheetCommandTarget(this._univerInstanceService, {
|
|
1208
|
+
unitId,
|
|
1209
|
+
subUnitId
|
|
1210
|
+
});
|
|
1211
|
+
const dispose = this._enusreMap(unitId, subUnitId).getValue(row, col);
|
|
1212
|
+
if (dispose) dispose.dispose();
|
|
1213
|
+
if (sheetTarget) {
|
|
1214
|
+
const { worksheet } = sheetTarget;
|
|
1215
|
+
const cell = worksheet.getCellRaw(row, col);
|
|
1216
|
+
if (cell && cell.p) this._registerRange(unitId, subUnitId, row, col, cell.p);
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
}));
|
|
1220
|
+
}
|
|
1221
|
+
};
|
|
1222
|
+
SheetsHyperLinkRichTextRefRangeController = __decorate([
|
|
1223
|
+
__decorateParam(0, ICommandService),
|
|
1224
|
+
__decorateParam(1, IUniverInstanceService),
|
|
1225
|
+
__decorateParam(2, Inject(RefRangeService))
|
|
1226
|
+
], SheetsHyperLinkRichTextRefRangeController);
|
|
1227
|
+
|
|
1228
|
+
//#endregion
|
|
1229
|
+
//#region src/controllers/set-range.controller.ts
|
|
1230
|
+
let SheetHyperLinkSetRangeController = class SheetHyperLinkSetRangeController extends Disposable {
|
|
1231
|
+
constructor(_sheetInterceptorService, _hyperLinkModel, _selectionManagerService, _univerInstanceService) {
|
|
1232
|
+
super();
|
|
1233
|
+
this._sheetInterceptorService = _sheetInterceptorService;
|
|
1234
|
+
this._hyperLinkModel = _hyperLinkModel;
|
|
1235
|
+
this._selectionManagerService = _selectionManagerService;
|
|
1236
|
+
this._univerInstanceService = _univerInstanceService;
|
|
1237
|
+
this._initCommandInterceptor();
|
|
1238
|
+
this._initAfterEditor();
|
|
1239
|
+
}
|
|
1240
|
+
_initCommandInterceptor() {
|
|
1241
|
+
this._initSetRangeValuesCommandInterceptor();
|
|
1242
|
+
this._initClearSelectionCommandInterceptor();
|
|
1243
|
+
}
|
|
1244
|
+
_initSetRangeValuesCommandInterceptor() {
|
|
1245
|
+
this.disposeWithMe(this._sheetInterceptorService.interceptCommand({ getMutations: (command) => {
|
|
1246
|
+
if (command.id === SetRangeValuesCommand.id) {
|
|
1247
|
+
const params = command.params;
|
|
1248
|
+
const { unitId, subUnitId } = params;
|
|
1249
|
+
const redos = [];
|
|
1250
|
+
const undos = [];
|
|
1251
|
+
if (params.cellValue) new ObjectMatrix(params.cellValue).forValue((row, col) => {
|
|
1252
|
+
const link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, col);
|
|
1253
|
+
if (link) {
|
|
1254
|
+
redos.push({
|
|
1255
|
+
id: RemoveHyperLinkMutation.id,
|
|
1256
|
+
params: {
|
|
1257
|
+
unitId,
|
|
1258
|
+
subUnitId,
|
|
1259
|
+
id: link.id
|
|
1260
|
+
}
|
|
1261
|
+
});
|
|
1262
|
+
undos.push({
|
|
1263
|
+
id: AddHyperLinkMutation.id,
|
|
1264
|
+
params: {
|
|
1265
|
+
unitId,
|
|
1266
|
+
subUnitId,
|
|
1267
|
+
link
|
|
1268
|
+
}
|
|
1269
|
+
});
|
|
1270
|
+
}
|
|
1271
|
+
});
|
|
1272
|
+
return {
|
|
1273
|
+
undos,
|
|
1274
|
+
redos
|
|
1275
|
+
};
|
|
1276
|
+
}
|
|
1277
|
+
return {
|
|
1278
|
+
redos: [],
|
|
1279
|
+
undos: []
|
|
1280
|
+
};
|
|
1281
|
+
} }));
|
|
1282
|
+
}
|
|
1283
|
+
_initClearSelectionCommandInterceptor() {
|
|
1284
|
+
this.disposeWithMe(this._sheetInterceptorService.interceptCommand({ getMutations: (command) => {
|
|
1285
|
+
if (command.id === ClearSelectionContentCommand.id || command.id === ClearSelectionAllCommand.id || command.id === ClearSelectionFormatCommand.id) {
|
|
1286
|
+
const redos = [];
|
|
1287
|
+
const undos = [];
|
|
1288
|
+
const selection = this._selectionManagerService.getCurrentLastSelection();
|
|
1289
|
+
const target = getSheetCommandTarget(this._univerInstanceService, command.params);
|
|
1290
|
+
if (selection && target) {
|
|
1291
|
+
const { unitId, subUnitId } = target;
|
|
1292
|
+
Range.foreach(selection.range, (row, col) => {
|
|
1293
|
+
const link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, col);
|
|
1294
|
+
if (link) {
|
|
1295
|
+
redos.push({
|
|
1296
|
+
id: RemoveHyperLinkMutation.id,
|
|
1297
|
+
params: {
|
|
1298
|
+
unitId,
|
|
1299
|
+
subUnitId,
|
|
1300
|
+
id: link.id
|
|
1301
|
+
}
|
|
1302
|
+
});
|
|
1303
|
+
undos.push({
|
|
1304
|
+
id: AddHyperLinkMutation.id,
|
|
1305
|
+
params: {
|
|
1306
|
+
unitId,
|
|
1307
|
+
subUnitId,
|
|
1308
|
+
link
|
|
1309
|
+
}
|
|
1310
|
+
});
|
|
1311
|
+
}
|
|
1312
|
+
});
|
|
1313
|
+
}
|
|
1314
|
+
return {
|
|
1315
|
+
redos,
|
|
1316
|
+
undos
|
|
1317
|
+
};
|
|
1318
|
+
}
|
|
1319
|
+
return {
|
|
1320
|
+
redos: [],
|
|
1321
|
+
undos: []
|
|
1322
|
+
};
|
|
1323
|
+
} }));
|
|
1324
|
+
}
|
|
1325
|
+
_initAfterEditor() {
|
|
1326
|
+
this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(AFTER_CELL_EDIT, { handler: (cell, context, next) => {
|
|
1327
|
+
if (!cell || cell.p) return next(cell);
|
|
1328
|
+
if (typeof cell.v === "string" && Tools.isLegalUrl(cell.v) && cell.v[cell.v.length - 1] !== " ") {
|
|
1329
|
+
const { unitId, subUnitId, row, col } = context;
|
|
1330
|
+
const link = Tools.normalizeUrl(cell.v);
|
|
1331
|
+
const workbook = this._univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_SHEET);
|
|
1332
|
+
const worksheet = workbook === null || workbook === void 0 ? void 0 : workbook.getSheetBySheetId(subUnitId);
|
|
1333
|
+
if (!worksheet) return next(cell);
|
|
1334
|
+
const doc = worksheet.getBlankCellDocumentModel(cell, row, col);
|
|
1335
|
+
if (!doc.documentModel) return next(cell);
|
|
1336
|
+
const textX = BuildTextUtils.selection.replace({
|
|
1337
|
+
selection: {
|
|
1338
|
+
startOffset: 0,
|
|
1339
|
+
endOffset: cell.v.length,
|
|
1340
|
+
collapsed: false
|
|
1341
|
+
},
|
|
1342
|
+
body: {
|
|
1343
|
+
dataStream: `${cell.v}`,
|
|
1344
|
+
customRanges: [{
|
|
1345
|
+
startIndex: 0,
|
|
1346
|
+
endIndex: cell.v.length - 1,
|
|
1347
|
+
rangeId: generateRandomId(),
|
|
1348
|
+
rangeType: CustomRangeType.HYPERLINK,
|
|
1349
|
+
properties: { url: link }
|
|
1350
|
+
}]
|
|
1351
|
+
},
|
|
1352
|
+
doc: doc.documentModel
|
|
1353
|
+
});
|
|
1354
|
+
if (!textX) return next(cell);
|
|
1355
|
+
const body = doc.documentModel.getBody();
|
|
1356
|
+
TextX.apply(body, textX.serialize());
|
|
1357
|
+
return next({
|
|
1358
|
+
...cell,
|
|
1359
|
+
p: {
|
|
1360
|
+
id: DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
|
|
1361
|
+
body,
|
|
1362
|
+
documentStyle: { pageSize: {
|
|
1363
|
+
width: Infinity,
|
|
1364
|
+
height: Infinity
|
|
1365
|
+
} }
|
|
1366
|
+
}
|
|
1367
|
+
});
|
|
1368
|
+
}
|
|
1369
|
+
return next(cell);
|
|
1370
|
+
} }));
|
|
1371
|
+
}
|
|
1372
|
+
};
|
|
1373
|
+
SheetHyperLinkSetRangeController = __decorate([
|
|
1374
|
+
__decorateParam(0, Inject(SheetInterceptorService)),
|
|
1375
|
+
__decorateParam(1, Inject(HyperLinkModel)),
|
|
1376
|
+
__decorateParam(2, Inject(SheetsSelectionsService)),
|
|
1377
|
+
__decorateParam(3, IUniverInstanceService)
|
|
1378
|
+
], SheetHyperLinkSetRangeController);
|
|
1379
|
+
|
|
1380
|
+
//#endregion
|
|
1381
|
+
//#region src/controllers/sheet-hyper-link.controller.ts
|
|
1382
|
+
/**
|
|
1383
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1384
|
+
*
|
|
1385
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1386
|
+
* you may not use this file except in compliance with the License.
|
|
1387
|
+
* You may obtain a copy of the License at
|
|
1388
|
+
*
|
|
1389
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1390
|
+
*
|
|
1391
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1392
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1393
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1394
|
+
* See the License for the specific language governing permissions and
|
|
1395
|
+
* limitations under the License.
|
|
1396
|
+
*/
|
|
1397
|
+
let SheetsHyperLinkController = class SheetsHyperLinkController extends Disposable {
|
|
1398
|
+
constructor(_commandService) {
|
|
1399
|
+
super();
|
|
1400
|
+
this._commandService = _commandService;
|
|
1401
|
+
this._registerCommands();
|
|
1402
|
+
}
|
|
1403
|
+
_registerCommands() {
|
|
1404
|
+
[
|
|
1405
|
+
AddHyperLinkCommand,
|
|
1406
|
+
UpdateHyperLinkCommand,
|
|
1407
|
+
CancelHyperLinkCommand,
|
|
1408
|
+
UpdateRichHyperLinkCommand,
|
|
1409
|
+
CancelRichHyperLinkCommand,
|
|
1410
|
+
AddRichHyperLinkCommand,
|
|
1411
|
+
AddHyperLinkMutation,
|
|
1412
|
+
UpdateHyperLinkMutation,
|
|
1413
|
+
RemoveHyperLinkMutation,
|
|
1414
|
+
UpdateHyperLinkRefMutation,
|
|
1415
|
+
UpdateRichHyperLinkMutation
|
|
1416
|
+
].forEach((command) => {
|
|
1417
|
+
this._commandService.registerCommand(command);
|
|
1418
|
+
});
|
|
1419
|
+
}
|
|
1420
|
+
};
|
|
1421
|
+
SheetsHyperLinkController = __decorate([__decorateParam(0, ICommandService)], SheetsHyperLinkController);
|
|
1422
|
+
|
|
1423
|
+
//#endregion
|
|
1424
|
+
//#region src/types/enums/hyper-link-type.ts
|
|
1425
|
+
/**
|
|
1426
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1427
|
+
*
|
|
1428
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1429
|
+
* you may not use this file except in compliance with the License.
|
|
1430
|
+
* You may obtain a copy of the License at
|
|
1431
|
+
*
|
|
1432
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1433
|
+
*
|
|
1434
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1435
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1436
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1437
|
+
* See the License for the specific language governing permissions and
|
|
1438
|
+
* limitations under the License.
|
|
1439
|
+
*/
|
|
1440
|
+
let SheetHyperLinkType = /* @__PURE__ */ function(SheetHyperLinkType) {
|
|
1441
|
+
SheetHyperLinkType["SHEET"] = "gid";
|
|
1442
|
+
SheetHyperLinkType["RANGE"] = "range";
|
|
1443
|
+
SheetHyperLinkType["DEFINE_NAME"] = "rangeid";
|
|
1444
|
+
SheetHyperLinkType["INVALID"] = "invalid";
|
|
1445
|
+
SheetHyperLinkType["URL"] = "url";
|
|
1446
|
+
return SheetHyperLinkType;
|
|
1447
|
+
}({});
|
|
1448
|
+
|
|
1449
|
+
//#endregion
|
|
1450
|
+
//#region src/services/parser.service.ts
|
|
1451
|
+
let SheetsHyperLinkParserService = class SheetsHyperLinkParserService {
|
|
1452
|
+
constructor(_univerInstanceService, _localeService, _definedNamesService) {
|
|
1453
|
+
this._univerInstanceService = _univerInstanceService;
|
|
1454
|
+
this._localeService = _localeService;
|
|
1455
|
+
this._definedNamesService = _definedNamesService;
|
|
1456
|
+
}
|
|
1457
|
+
buildHyperLink(unitId, sheetId, range) {
|
|
1458
|
+
return `#${SheetHyperLinkType.SHEET}=${sheetId}${range ? `&${typeof range === "string" ? SheetHyperLinkType.DEFINE_NAME : SheetHyperLinkType.RANGE}=${typeof range === "string" ? range : serializeRange(range)}` : ""}`;
|
|
1459
|
+
}
|
|
1460
|
+
parseHyperLink(urlStr) {
|
|
1461
|
+
if (urlStr.startsWith("#")) {
|
|
1462
|
+
var _search$get, _search$get2, _search$get3, _search$get4;
|
|
1463
|
+
const search = new URLSearchParams(urlStr.slice(1));
|
|
1464
|
+
const searchObj = {
|
|
1465
|
+
gid: (_search$get = search.get("gid")) !== null && _search$get !== void 0 ? _search$get : "",
|
|
1466
|
+
range: (_search$get2 = search.get("range")) !== null && _search$get2 !== void 0 ? _search$get2 : "",
|
|
1467
|
+
rangeid: (_search$get3 = search.get("rangeid")) !== null && _search$get3 !== void 0 ? _search$get3 : "",
|
|
1468
|
+
unitid: (_search$get4 = search.get("unitid")) !== null && _search$get4 !== void 0 ? _search$get4 : ""
|
|
1469
|
+
};
|
|
1470
|
+
const urlInfo = this._getURLName(searchObj);
|
|
1471
|
+
return {
|
|
1472
|
+
type: urlInfo.type,
|
|
1473
|
+
name: urlInfo.name,
|
|
1474
|
+
url: urlStr,
|
|
1475
|
+
searchObj
|
|
1476
|
+
};
|
|
1477
|
+
} else return {
|
|
1478
|
+
type: SheetHyperLinkType.URL,
|
|
1479
|
+
name: urlStr,
|
|
1480
|
+
url: urlStr,
|
|
1481
|
+
searchObj: null
|
|
1482
|
+
};
|
|
1483
|
+
}
|
|
1484
|
+
_getURLName(params) {
|
|
1485
|
+
var _sheet$getName;
|
|
1486
|
+
const { gid, range, rangeid, unitid } = params;
|
|
1487
|
+
const workbook = unitid ? this._univerInstanceService.getUnit(unitid, UniverInstanceType.UNIVER_SHEET) : this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET);
|
|
1488
|
+
const invalidLink = {
|
|
1489
|
+
type: SheetHyperLinkType.INVALID,
|
|
1490
|
+
name: this._localeService.t("hyperLink.message.refError")
|
|
1491
|
+
};
|
|
1492
|
+
if (!workbook) return invalidLink;
|
|
1493
|
+
const sheet = gid ? workbook.getSheetBySheetId(gid) : workbook.getActiveSheet();
|
|
1494
|
+
const sheetName = (_sheet$getName = sheet === null || sheet === void 0 ? void 0 : sheet.getName()) !== null && _sheet$getName !== void 0 ? _sheet$getName : "";
|
|
1495
|
+
if (range) {
|
|
1496
|
+
if (!sheet) return invalidLink;
|
|
1497
|
+
const rangeObj = deserializeRangeWithSheet(range).range;
|
|
1498
|
+
if (isValidRange(rangeObj, sheet) && range !== "err") return {
|
|
1499
|
+
type: SheetHyperLinkType.RANGE,
|
|
1500
|
+
name: serializeRangeWithSheet(sheetName, rangeObj)
|
|
1501
|
+
};
|
|
1502
|
+
return invalidLink;
|
|
1503
|
+
}
|
|
1504
|
+
if (rangeid) {
|
|
1505
|
+
const range = this._definedNamesService.getValueById(workbook.getUnitId(), rangeid);
|
|
1506
|
+
if (range) return {
|
|
1507
|
+
type: SheetHyperLinkType.DEFINE_NAME,
|
|
1508
|
+
name: range.formulaOrRefString
|
|
1509
|
+
};
|
|
1510
|
+
return invalidLink;
|
|
1511
|
+
}
|
|
1512
|
+
if (gid) {
|
|
1513
|
+
const worksheet = workbook.getSheetBySheetId(gid);
|
|
1514
|
+
if (worksheet) return {
|
|
1515
|
+
type: SheetHyperLinkType.SHEET,
|
|
1516
|
+
name: worksheet.getName()
|
|
1517
|
+
};
|
|
1518
|
+
return invalidLink;
|
|
1519
|
+
}
|
|
1520
|
+
return invalidLink;
|
|
1521
|
+
}
|
|
1522
|
+
};
|
|
1523
|
+
SheetsHyperLinkParserService = __decorate([
|
|
1524
|
+
__decorateParam(0, IUniverInstanceService),
|
|
1525
|
+
__decorateParam(1, Inject(LocaleService)),
|
|
1526
|
+
__decorateParam(2, IDefinedNamesService)
|
|
1527
|
+
], SheetsHyperLinkParserService);
|
|
1528
|
+
|
|
1529
|
+
//#endregion
|
|
1530
|
+
//#region src/plugin.ts
|
|
1531
|
+
let UniverSheetsHyperLinkPlugin = class UniverSheetsHyperLinkPlugin extends Plugin {
|
|
1532
|
+
constructor(_config = defaultPluginConfig, _injector, _configService) {
|
|
1533
|
+
super();
|
|
1534
|
+
this._config = _config;
|
|
1535
|
+
this._injector = _injector;
|
|
1536
|
+
this._configService = _configService;
|
|
1537
|
+
const { ...rest } = merge({}, defaultPluginConfig, this._config);
|
|
1538
|
+
this._configService.setConfig(SHEETS_HYPER_LINK_PLUGIN_CONFIG_KEY, rest);
|
|
1539
|
+
}
|
|
1540
|
+
onStarting() {
|
|
1541
|
+
registerDependencies(this._injector, [
|
|
1542
|
+
[HyperLinkModel],
|
|
1543
|
+
[SheetsHyperLinkParserService],
|
|
1544
|
+
[SheetsHyperLinkController],
|
|
1545
|
+
[SheetsHyperLinkRefRangeController],
|
|
1546
|
+
[SheetHyperLinkSetRangeController],
|
|
1547
|
+
[SheetsHyperLinkRemoveSheetController],
|
|
1548
|
+
[SheetsHyperLinkRichTextRefRangeController]
|
|
1549
|
+
]);
|
|
1550
|
+
touchDependencies(this._injector, [
|
|
1551
|
+
[SheetsHyperLinkRefRangeController],
|
|
1552
|
+
[SheetsHyperLinkController],
|
|
1553
|
+
[SheetHyperLinkSetRangeController],
|
|
1554
|
+
[SheetsHyperLinkRemoveSheetController],
|
|
1555
|
+
[SheetsHyperLinkRichTextRefRangeController]
|
|
1556
|
+
]);
|
|
1557
|
+
}
|
|
1558
|
+
};
|
|
1559
|
+
_defineProperty(UniverSheetsHyperLinkPlugin, "pluginName", SHEET_HYPER_LINK_PLUGIN);
|
|
1560
|
+
_defineProperty(UniverSheetsHyperLinkPlugin, "packageName", name);
|
|
1561
|
+
_defineProperty(UniverSheetsHyperLinkPlugin, "version", version);
|
|
1562
|
+
_defineProperty(UniverSheetsHyperLinkPlugin, "type", UniverInstanceType.UNIVER_SHEET);
|
|
1563
|
+
UniverSheetsHyperLinkPlugin = __decorate([
|
|
1564
|
+
DependentOn(UniverSheetsPlugin),
|
|
1565
|
+
__decorateParam(1, Inject(Injector)),
|
|
1566
|
+
__decorateParam(2, IConfigService)
|
|
1567
|
+
], UniverSheetsHyperLinkPlugin);
|
|
1568
|
+
|
|
1569
|
+
//#endregion
|
|
1570
|
+
export { AddHyperLinkCommand, AddHyperLinkMutation, AddRichHyperLinkCommand, CancelHyperLinkCommand, CancelRichHyperLinkCommand, ERROR_RANGE, HyperLinkModel, RemoveHyperLinkMutation, SheetHyperLinkType, SheetsHyperLinkParserService, UniverSheetsHyperLinkPlugin, UpdateHyperLinkCommand, UpdateHyperLinkMutation, UpdateHyperLinkRefMutation, UpdateRichHyperLinkCommand };
|