@univerjs/sheets-hyper-link 0.1.13 → 0.1.15
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/index.js +1 -1
- package/lib/es/index.js +501 -259
- package/lib/types/commands/mutations/update-hyper-link.mutation.d.ts +1 -0
- package/lib/types/controllers/ref-range.controller.d.ts +25 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/models/hyper-link.model.d.ts +16 -3
- package/lib/types/types/const.d.ts +1 -0
- package/lib/types/types/interfaces/i-hyper-link.d.ts +4 -1
- package/lib/umd/index.js +1 -1
- package/package.json +28 -12
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var x=Object.defineProperty;var D=(r,i,e)=>i in r?x(r,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[i]=e;var m=(r,i,e)=>(D(r,typeof i!="symbol"?i+"":i,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@univerjs/core"),L=require("@univerjs/sheets"),b=require("rxjs"),S=require("@wendellhu/redi");class l extends d.Disposable{constructor(){super();m(this,"_linkUpdate$",new b.Subject);m(this,"linkUpdate$",this._linkUpdate$.asObservable());m(this,"_linkMap",new Map);m(this,"_linkPositionMap",new Map);this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let t=this._linkMap.get(e);t||(t=new Map,this._linkMap.set(e,t));let o=t.get(n);o||(o=new d.ObjectMatrix,t.set(n,o));let s=this._linkPositionMap.get(e);s||(s=new Map,this._linkPositionMap.set(e,s));let a=s.get(n);return a||(a=new Map,s.set(n,a)),{matrix:o,positionMap:a}}addHyperLink(e,n,t){const{matrix:o,positionMap:s}=this._ensureMap(e,n);return o.setValue(t.row,t.column,t),s.set(t.id,{row:t.row,column:t.column,link:t}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:t,type:"add"}),!0}updateHyperLink(e,n,t,o,s){const{matrix:a,positionMap:c}=this._ensureMap(e,n),u=c.get(t);if(!u)return!1;const p=a.getValue(u.row,u.column);return p?(Object.assign(p,o),s||this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:p.display,payload:p.payload},id:t,type:"update"}),!0):!1}updateHyperLinkRef(e,n,t,o){const{matrix:s,positionMap:a}=this._ensureMap(e,n),c=a.get(t);if(!c)return!1;let u=s.getValue(c.row,c.column);return!u||u.id!==t?u=c.link:s.realDeleteValue(c.row,c.column),Object.assign(u,o),a.set(t,{...o,link:u}),s.setValue(o.row,o.column,u),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:o,id:t,type:"updateRef"}),!0}removeHyperLink(e,n,t){const{matrix:o,positionMap:s}=this._ensureMap(e,n),a=s.get(t);if(!a)return!1;s.delete(t);const c=o.getValue(a.row,a.column);return c&&c.id===t&&o.realDeleteValue(a.row,a.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:c,type:"remove"}),!0}getHyperLink(e,n,t){const{matrix:o,positionMap:s}=this._ensureMap(e,n),a=s.get(t);if(a)return o.getValue(a.row,a.column)}getHyperLinkByLocation(e,n,t,o){const{matrix:s}=this._ensureMap(e,n);return s.getValue(t,o)}getSubUnit(e,n){const{matrix:t}=this._ensureMap(e,n),o=[];return t.forValue((s,a,c)=>{c&&o.push(c)}),o}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(t=>{const o=this.getSubUnit(e,t);return{unitId:e,subUnitId:t,links:o}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}}const f={type:d.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(r,i){if(!i)return!1;const e=r.get(l),{unitId:n,subUnitId:t,link:o}=i;return e.addHyperLink(n,t,o)}},_={type:d.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(r,i){if(!i)return!1;const e=r.get(l),{unitId:n,subUnitId:t,id:o}=i;return e.removeHyperLink(n,t,o)}},U={type:d.CommandType.COMMAND,id:"sheets.command.remove-hyper-link",async handler(r,i){if(!i)return!1;const e=r.get(L.SheetInterceptorService),n=r.get(d.ICommandService),t=r.get(d.IUndoRedoService),o=r.get(l),{unitId:s,subUnitId:a,id:c}=i,u=o.getHyperLink(s,a,c),{redos:p,undos:y}=e.onCommandExecute({id:U.id,params:i}),h={id:_.id,params:i},v={id:f.id,params:{unitId:s,subUnitId:a,link:u}};return(await d.sequenceExecuteAsync([h,...p],n)).result?(t.pushUndoRedo({redoMutations:[h,...p],undoMutations:[v,...y],unitID:s}),!0):!1}},R={type:d.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",async handler(r,i){if(!i)return!1;const e=r.get(d.ICommandService),n=r.get(d.IUndoRedoService),t=r.get(l),{unitId:o,subUnitId:s,id:a}=i,c=t.getHyperLink(o,s,a),u={id:_.id,params:i},p={id:f.id,params:{unitId:o,subUnitId:s,link:c}};return(await d.sequenceExecuteAsync([u],e)).result?(n.pushUndoRedo({redoMutations:[u],undoMutations:[p],unitID:o}),!0):!1}},k={type:d.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(r,i){if(!i)return!1;const e=r.get(l),{unitId:n,subUnitId:t,payload:o,id:s}=i;return e.updateHyperLink(n,t,s,o)}},N={type:d.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(r,i){if(!i)return!1;const e=r.get(l),{unitId:n,subUnitId:t,id:o,row:s,column:a}=i;return e.updateHyperLinkRef(n,t,o,{row:s,column:a})}},H={type:d.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(r,i){if(!i)return!1;const e=r.get(L.SheetInterceptorService),n=r.get(d.ICommandService),t=r.get(d.IUndoRedoService),{unitId:o,subUnitId:s,link:a}=i,{redos:c,undos:u}=e.onCommandExecute({id:H.id,params:i}),p={id:f.id,params:i},y={id:_.id,params:{unitId:o,subUnitId:s,id:a.id}};return(await d.sequenceExecuteAsync([p,...c],n)).result?(t.pushUndoRedo({redoMutations:[p,...c],undoMutations:[y,...u],unitID:o}),!0):!1}};function T(r){const{row:i,column:e,id:n,...t}=r;return t}const C={type:d.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(r,i){if(!i)return!1;const e=r.get(L.SheetInterceptorService),n=r.get(d.ICommandService),t=r.get(d.IUndoRedoService),o=r.get(l),{unitId:s,subUnitId:a,id:c}=i,u=o.getHyperLink(s,a,c);if(!u)return!1;const{redos:p,undos:y}=e.onCommandExecute({id:C.id,params:i}),h={id:k.id,params:i},v={id:k.id,params:{unitId:s,subUnitId:a,id:c,payload:T(u)}};return(await d.sequenceExecuteAsync([h,...p],n)).result?(t.pushUndoRedo({redoMutations:[h,...p],undoMutations:[v,...y],unitID:s}),!0):!1}};var V=Object.defineProperty,A=Object.getOwnPropertyDescriptor,$=(r,i,e,n)=>{for(var t=n>1?void 0:n?A(i,e):i,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(n?s(i,e,t):s(t))||t);return n&&t&&V(i,e,t),t},j=(r,i)=>(e,n)=>i(e,n,r);exports.SheetsHyperLinkController=class extends d.Disposable{constructor(i){super(),this._commandService=i,this._registerCommands()}_registerCommands(){[f,k,_,N,H,C,U,R].forEach(i=>{this._commandService.registerCommand(i)})}};exports.SheetsHyperLinkController=$([d.OnLifecycle(d.LifecycleStages.Starting,exports.SheetsHyperLinkController),j(0,d.ICommandService)],exports.SheetsHyperLinkController);var O=(r=>(r[r.range=0]="range",r[r.link=1]="link",r))(O||{});const E="SHEET_HYPER_LINK_PLUGIN";var w=(r=>(r[r.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",r[r.UNIVER_DOC=1]="UNIVER_DOC",r[r.UNIVER_SHEET=2]="UNIVER_SHEET",r[r.UNIVER_SLIDE=3]="UNIVER_SLIDE",r[r.UNRECOGNIZED=-1]="UNRECOGNIZED",r))(w||{}),q=Object.defineProperty,J=Object.getOwnPropertyDescriptor,G=(r,i,e,n)=>{for(var t=n>1?void 0:n?J(i,e):i,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(n?s(i,e,t):s(t))||t);return n&&t&&q(i,e,t),t},I=(r,i)=>(e,n)=>i(e,n,r);let g=class extends d.Disposable{constructor(r,i){super(),this._resourceManagerService=r,this._hyperLinkModel=i,this._initSnapshot()}_initSnapshot(){const r=e=>{const n=this._hyperLinkModel.getUnit(e),t={};return n?(n.forEach(o=>{t[o.subUnitId]=o.links}),JSON.stringify(t)):""},i=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:E,businesses:[w.UNIVER_SHEET],toJson:e=>r(e),parseJson:e=>i(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(t=>{n[t].forEach(s=>{this._hyperLinkModel.addHyperLink(e,t,s)})})}}))}};g=G([d.OnLifecycle(d.LifecycleStages.Starting,g),I(0,d.IResourceManagerService),I(1,S.Inject(l))],g);var K=Object.defineProperty,W=Object.getOwnPropertyDescriptor,Y=(r,i,e,n)=>{for(var t=n>1?void 0:n?W(i,e):i,o=r.length-1,s;o>=0;o--)(s=r[o])&&(t=(n?s(i,e,t):s(t))||t);return n&&t&&K(i,e,t),t},Z=(r,i)=>(e,n)=>i(e,n,r),M;exports.UniverSheetsHyperLinkPlugin=(M=class extends d.Plugin{constructor(i,e){super(),this._injector=e}onStarting(i){[[g],[exports.SheetsHyperLinkController],[l]].forEach(e=>{i.add(e)})}},m(M,"pluginName",E),m(M,"type",d.UniverInstanceType.UNIVER_SHEET),M);exports.UniverSheetsHyperLinkPlugin=Y([Z(1,S.Inject(S.Injector))],exports.UniverSheetsHyperLinkPlugin);exports.AddHyperLinkCommand=H;exports.AddHyperLinkMutation=f;exports.CancelHyperLinkCommand=R;exports.HyperLinkModel=l;exports.HyperLinkType=O;exports.RemoveHyperLinkCommand=U;exports.RemoveHyperLinkMutation=_;exports.UpdateHyperLinkCommand=C;exports.UpdateHyperLinkMutation=k;exports.UpdateHyperLinkRefMutation=N;
|
|
1
|
+
"use strict";var j=Object.defineProperty;var A=(s,i,e)=>i in s?j(s,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[i]=e;var g=(s,i,e)=>(A(s,typeof i!="symbol"?i+"":i,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@univerjs/core"),M=require("@univerjs/sheets"),T=require("rxjs"),R=require("@wendellhu/redi"),f=require("@univerjs/sheets-hyper-link"),v=require("@univerjs/engine-formula");var V=Object.defineProperty,W=Object.getOwnPropertyDescriptor,q=(s,i,e,n)=>{for(var t=n>1?void 0:n?W(i,e):i,r=s.length-1,o;r>=0;r--)(o=s[r])&&(t=(n?o(i,e,t):o(t))||t);return n&&t&&V(i,e,t),t},G=(s,i)=>(e,n)=>i(e,n,s);exports.HyperLinkModel=class extends d.Disposable{constructor(e){super();g(this,"_linkUpdate$",new T.Subject);g(this,"linkUpdate$",this._linkUpdate$.asObservable());g(this,"_linkMap",new Map);g(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let t=this._linkMap.get(e);t||(t=new Map,this._linkMap.set(e,t));let r=t.get(n);r||(r=new d.ObjectMatrix,t.set(n,r));let o=this._linkPositionMap.get(e);o||(o=new Map,this._linkPositionMap.set(e,o));let a=o.get(n);return a||(a=new Map,o.set(n,a)),{matrix:r,positionMap:a}}addHyperLink(e,n,t){const{matrix:r,positionMap:o}=this._ensureMap(e,n);return r.setValue(t.row,t.column,t),o.set(t.id,{row:t.row,column:t.column,link:t}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:t,type:"add"}),!0}updateHyperLink(e,n,t,r,o=!1){const{matrix:a,positionMap:c}=this._ensureMap(e,n),l=c.get(t);if(!l)return!0;const p=a.getValue(l.row,l.column);return p&&(Object.assign(p,r),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:p.display,payload:p.payload},id:t,type:"update",silent:o})),!0}updateHyperLinkRef(e,n,t,r,o=!1){const{matrix:a,positionMap:c}=this._ensureMap(e,n),l=c.get(t);if(!l)return!0;let p=a.getValue(l.row,l.column);return!p||p.id!==t?p=l.link:a.realDeleteValue(l.row,l.column),Object.assign(p,r),c.set(t,{...r,link:p}),a.setValue(r.row,r.column,p),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:r,id:t,type:"updateRef",silent:o}),!0}removeHyperLink(e,n,t){const{matrix:r,positionMap:o}=this._ensureMap(e,n),a=o.get(t);if(!a)return!1;o.delete(t);const c=r.getValue(a.row,a.column);return c&&c.id===t&&r.realDeleteValue(a.row,a.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:a.link,type:"remove"}),!0}getHyperLink(e,n,t){const{matrix:r,positionMap:o}=this._ensureMap(e,n),a=o.get(t);if(a)return r.getValue(a.row,a.column)}getHyperLinkByLocation(e,n,t,r){const{matrix:o}=this._ensureMap(e,n);return o.getValue(t,r)}getHyperLinkByLocationSync(e,n,t,r){var u,h,y,m,_;const{matrix:o}=this._ensureMap(e,n),a=this._univerInstanceService.getUnit(e,d.UniverInstanceType.UNIVER_SHEET),c=(u=a==null?void 0:a.getSheetBySheetId(n))==null?void 0:u.getCellRaw(t,r),l=((_=(m=c==null?void 0:c.v)!=null?m:(y=(h=c==null?void 0:c.p)==null?void 0:h.body)==null?void 0:y.dataStream.slice(0,-2))!=null?_:"").toString(),p=o.getValue(t,r);if(p)return{...p,display:l}}getSubUnit(e,n){const{matrix:t}=this._ensureMap(e,n),r=[];return t.forValue((o,a,c)=>{c&&r.push(c)}),r}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(t=>{const r=this.getSubUnit(e,t);return{unitId:e,subUnitId:t,links:r}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}};exports.HyperLinkModel=q([G(0,d.IUniverInstanceService)],exports.HyperLinkModel);const S={type:d.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(s,i){if(!i)return!1;const e=s.get(exports.HyperLinkModel),{unitId:n,subUnitId:t,link:r}=i;return e.addHyperLink(n,t,r)}},L={type:d.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(s,i){if(!i)return!1;const e=s.get(exports.HyperLinkModel),{unitId:n,subUnitId:t,id:r}=i;return e.removeHyperLink(n,t,r)}},U={type:d.CommandType.COMMAND,id:"sheets.command.remove-hyper-link",async handler(s,i){if(!i)return!1;const e=s.get(M.SheetInterceptorService),n=s.get(d.ICommandService),t=s.get(d.IUndoRedoService),r=s.get(exports.HyperLinkModel),{unitId:o,subUnitId:a,id:c}=i,l=r.getHyperLink(o,a,c),{redos:p,undos:u}=e.onCommandExecute({id:U.id,params:i}),h={id:L.id,params:i},y={id:S.id,params:{unitId:o,subUnitId:a,link:l}};return(await d.sequenceExecuteAsync([h,...p],n)).result?(t.pushUndoRedo({redoMutations:[h,...p],undoMutations:[y,...u],unitID:o}),!0):!1}},O={type:d.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",async handler(s,i){if(!i)return!1;const e=s.get(d.ICommandService),n=s.get(d.IUndoRedoService),t=s.get(exports.HyperLinkModel),{unitId:r,subUnitId:o,id:a}=i,c=t.getHyperLink(r,o,a),l={id:L.id,params:i},p={id:S.id,params:{unitId:r,subUnitId:o,link:c}};return(await d.sequenceExecuteAsync([l],e)).result?(n.pushUndoRedo({redoMutations:[l],undoMutations:[p],unitID:r}),!0):!1}},w={type:d.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(s,i){if(!i)return!1;const e=s.get(exports.HyperLinkModel),{unitId:n,subUnitId:t,payload:r,id:o}=i;return e.updateHyperLink(n,t,o,r,!1)}},b={type:d.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(s,i){if(!i)return!1;const e=s.get(exports.HyperLinkModel),{unitId:n,subUnitId:t,id:r,row:o,column:a,silent:c}=i;return e.updateHyperLinkRef(n,t,r,{row:o,column:a},c)}},P={type:d.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(s,i){if(!i)return!1;const e=s.get(M.SheetInterceptorService),n=s.get(d.ICommandService),t=s.get(d.IUndoRedoService),{unitId:r,subUnitId:o,link:a}=i,{redos:c,undos:l}=e.onCommandExecute({id:P.id,params:i}),p={id:S.id,params:i},u={id:L.id,params:{unitId:r,subUnitId:o,id:a.id}};return(await d.sequenceExecuteAsync([p,...c],n)).result?(t.pushUndoRedo({redoMutations:[p,...c],undoMutations:[u,...l],unitID:r}),!0):!1}};function J(s){const{row:i,column:e,id:n,...t}=s;return t}const I={type:d.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(s,i){if(!i)return!1;const e=s.get(M.SheetInterceptorService),n=s.get(d.ICommandService),t=s.get(d.IUndoRedoService),r=s.get(exports.HyperLinkModel),{unitId:o,subUnitId:a,id:c}=i,l=r.getHyperLink(o,a,c);if(!l)return!1;const{redos:p,undos:u}=e.onCommandExecute({id:I.id,params:i}),h={id:w.id,params:i},y={id:w.id,params:{unitId:o,subUnitId:a,id:c,payload:J(l)}};return(await d.sequenceExecuteAsync([h,...p],n)).result?(t.pushUndoRedo({redoMutations:[h,...p],undoMutations:[y,...u],unitID:o}),!0):!1}};var z=Object.defineProperty,K=Object.getOwnPropertyDescriptor,B=(s,i,e,n)=>{for(var t=n>1?void 0:n?K(i,e):i,r=s.length-1,o;r>=0;r--)(o=s[r])&&(t=(n?o(i,e,t):o(t))||t);return n&&t&&z(i,e,t),t},Y=(s,i)=>(e,n)=>i(e,n,s);exports.SheetsHyperLinkController=class extends d.Disposable{constructor(i){super(),this._commandService=i,this._registerCommands()}_registerCommands(){[S,w,L,b,P,I,U,O].forEach(i=>{this._commandService.registerCommand(i)})}};exports.SheetsHyperLinkController=B([d.OnLifecycle(d.LifecycleStages.Starting,exports.SheetsHyperLinkController),Y(0,d.ICommandService)],exports.SheetsHyperLinkController);var D=(s=>(s[s.range=0]="range",s[s.link=1]="link",s))(D||{});const N="SHEET_HYPER_LINK_PLUGIN",$="err";var x=(s=>(s[s.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",s[s.UNIVER_DOC=1]="UNIVER_DOC",s[s.UNIVER_SHEET=2]="UNIVER_SHEET",s[s.UNIVER_SLIDE=3]="UNIVER_SLIDE",s[s.UNRECOGNIZED=-1]="UNRECOGNIZED",s))(x||{}),Z=Object.defineProperty,F=Object.getOwnPropertyDescriptor,Q=(s,i,e,n)=>{for(var t=n>1?void 0:n?F(i,e):i,r=s.length-1,o;r>=0;r--)(o=s[r])&&(t=(n?o(i,e,t):o(t))||t);return n&&t&&Z(i,e,t),t},E=(s,i)=>(e,n)=>i(e,n,s);let C=class extends d.Disposable{constructor(s,i){super(),this._resourceManagerService=s,this._hyperLinkModel=i,this._initSnapshot()}_initSnapshot(){const s=e=>{const n=this._hyperLinkModel.getUnit(e),t={};return n?(n.forEach(r=>{t[r.subUnitId]=r.links.map(({display:o,...a})=>a)}),JSON.stringify(t)):""},i=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:N,businesses:[x.UNIVER_SHEET],toJson:e=>s(e),parseJson:e=>i(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(t=>{n[t].forEach(o=>{this._hyperLinkModel.addHyperLink(e,t,o)})})}}))}};C=Q([d.OnLifecycle(d.LifecycleStages.Starting,C),E(0,d.IResourceManagerService),E(1,R.Inject(exports.HyperLinkModel))],C);var X=Object.defineProperty,ee=Object.getOwnPropertyDescriptor,te=(s,i,e,n)=>{for(var t=n>1?void 0:n?ee(i,e):i,r=s.length-1,o;r>=0;r--)(o=s[r])&&(t=(n?o(i,e,t):o(t))||t);return n&&t&&X(i,e,t),t},k=(s,i)=>(e,n)=>i(e,n,s);exports.SheetsHyperLinkRefRangeController=class extends d.Disposable{constructor(e,n,t,r){super();g(this,"_disposableMap",new Map);g(this,"_watchDisposableMap",new Map);g(this,"_rangeDisableMap",new Map);g(this,"_rangeWatcherMap",new Map);g(this,"_handlePositionChange",(e,n,t,r,o)=>{const a={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row};return r?{redos:[{id:f.UpdateHyperLinkRefMutation.id,params:{unitId:e,subUnitId:n,id:t.id,row:r.startRow,column:r.startColumn,silent:o}}],undos:[{id:f.UpdateHyperLinkRefMutation.id,params:{unitId:e,subUnitId:n,id:t.id,row:a.startRow,column:a.startColumn,silent:o}}]}:{redos:[{id:f.RemoveHyperLinkMutation.id,params:{unitId:e,subUnitId:n,id:t.id}}],undos:[{id:f.AddHyperLinkMutation.id,params:{unitId:e,subUnitId:n,link:t}}]}});this._refRangeService=e,this._hyperLinkModel=n,this._selectionManagerService=t,this._commandService=r,this._initData(),this._initRefRange()}_registerPosition(e,n,t){const r=t.id,o={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row},a=c=>{const l=M.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(o,c,{selectionManagerService:this._selectionManagerService});return l&&l.startColumn===o.startColumn&&l.startRow===o.startRow?{undos:[],redos:[]}:this._handlePositionChange(e,n,t,l,!1)};this._disposableMap.set(r,this._refRangeService.registerRefRange(o,a,e,n))}_watchPosition(e,n,t){const r=t.id,o={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row};this._watchDisposableMap.set(r,this._refRangeService.watchRange(e,n,o,(a,c)=>{const{redos:l}=this._handlePositionChange(e,n,t,c,!0);d.sequenceExecuteAsync(l,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(e){const n=this._disposableMap.get(e);n==null||n.dispose(),this._disposableMap.delete(e)}_unwatchPosition(e){const n=this._watchDisposableMap.get(e);n==null||n.dispose(),this._watchDisposableMap.delete(e)}_registerRange(e,n,t,r=!1){var o,a,c;if(t.startsWith("#")){const l=new URLSearchParams(t.slice(1)),p={gid:(o=l.get("gid"))!=null?o:"",range:(a=l.get("range"))!=null?a:"",rangeid:(c=l.get("rangeid"))!=null?c:""};if(p.range&&p.gid){const u=p.gid,h=v.deserializeRangeWithSheet(p.range).range;if(d.isValidRange(h)&&p.range!==$){const y=m=>{const _=M.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(h,m,{selectionManagerService:this._selectionManagerService});return _&&v.serializeRange(_)===v.serializeRange(h)?{redos:[],undos:[]}:{redos:[{id:f.UpdateHyperLinkMutation.id,params:{unitId:e,subUnitId:u,id:n,payload:{payload:`#gid=${u}&range=${_?v.serializeRange(_):"err"}`}}}],undos:[{id:f.UpdateHyperLinkMutation.id,params:{unitId:e,subUnitId:u,id:n,payload:{payload:t}}}]}};this._rangeDisableMap.set(n,this._refRangeService.registerRefRange(h,y,e,u)),r||this._rangeWatcherMap.set(n,this._refRangeService.watchRange(e,u,h,(m,_)=>{this._hyperLinkModel.updateHyperLink(e,u,n,{payload:`#gid=${u}&range=${_?v.serializeRange(_):"err"}`},!0)},!0))}}}}_unregisterRange(e){const n=this._rangeDisableMap.get(e);n==null||n.dispose(),this._rangeDisableMap.delete(e)}_unwatchRange(e){const n=this._rangeWatcherMap.get(e);n==null||n.dispose(),this._rangeWatcherMap.delete(e)}_initData(){this._hyperLinkModel.getAll().forEach(n=>{n.forEach(t=>{const{unitId:r,subUnitId:o,links:a}=t;a.forEach(c=>{this._registerPosition(r,o,c),this._watchPosition(r,o,c),this._registerRange(r,c.id,c.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":{const{unitId:n,subUnitId:t,id:r,silent:o}=e,a=this._hyperLinkModel.getHyperLink(n,t,r);if(!a)return;this._unregisterPosition(r),this._registerPosition(n,t,a),o||(this._unwatchPosition(r),this._watchPosition(n,t,a));break}case"unload":{const{unitLinks:n}=e;n.forEach(t=>{const{links:r}=t;r.forEach(o=>{this._unregisterPosition(o.id),this._unwatchPosition(o.id),this._unregisterRange(o.id),this._unwatchRange(o.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(d.toDisposable(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}};exports.SheetsHyperLinkRefRangeController=te([d.OnLifecycle(d.LifecycleStages.Starting,exports.SheetsHyperLinkRefRangeController),k(0,R.Inject(M.RefRangeService)),k(1,R.Inject(f.HyperLinkModel)),k(2,R.Inject(M.SelectionManagerService)),k(3,d.ICommandService)],exports.SheetsHyperLinkRefRangeController);var ne=Object.defineProperty,re=Object.getOwnPropertyDescriptor,ie=(s,i,e,n)=>{for(var t=n>1?void 0:n?re(i,e):i,r=s.length-1,o;r>=0;r--)(o=s[r])&&(t=(n?o(i,e,t):o(t))||t);return n&&t&&ne(i,e,t),t},se=(s,i)=>(e,n)=>i(e,n,s),H;exports.UniverSheetsHyperLinkPlugin=(H=class extends d.Plugin{constructor(i,e){super(),this._injector=e}onStarting(i){[[C],[exports.SheetsHyperLinkController],[exports.SheetsHyperLinkRefRangeController],[exports.HyperLinkModel]].forEach(e=>{i.add(e)})}},g(H,"pluginName",N),g(H,"type",d.UniverInstanceType.UNIVER_SHEET),H);exports.UniverSheetsHyperLinkPlugin=ie([se(1,R.Inject(R.Injector))],exports.UniverSheetsHyperLinkPlugin);exports.AddHyperLinkCommand=P;exports.AddHyperLinkMutation=S;exports.CancelHyperLinkCommand=O;exports.ERROR_RANGE=$;exports.HyperLinkType=D;exports.RemoveHyperLinkCommand=U;exports.RemoveHyperLinkMutation=L;exports.UpdateHyperLinkCommand=I;exports.UpdateHyperLinkMutation=w;exports.UpdateHyperLinkRefMutation=b;
|
package/lib/es/index.js
CHANGED
|
@@ -1,339 +1,360 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var h = (
|
|
4
|
-
import { Disposable as
|
|
5
|
-
import { SheetInterceptorService as
|
|
6
|
-
import { Subject as
|
|
7
|
-
import { Inject as
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
var B = Object.defineProperty;
|
|
2
|
+
var z = (s, e, t) => e in s ? B(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
3
|
+
var h = (s, e, t) => (z(s, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
import { Disposable as k, ObjectMatrix as Y, UniverInstanceType as A, IUniverInstanceService as Z, CommandType as m, ICommandService as M, IUndoRedoService as C, sequenceExecuteAsync as R, OnLifecycle as E, LifecycleStages as D, IResourceManagerService as q, isValidRange as F, toDisposable as Q, Plugin as X } from "@univerjs/core";
|
|
5
|
+
import { SheetInterceptorService as N, RefRangeService as ee, SelectionManagerService as te, handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests as I } from "@univerjs/sheets";
|
|
6
|
+
import { Subject as ne } from "rxjs";
|
|
7
|
+
import { Inject as y, Injector as re } from "@wendellhu/redi";
|
|
8
|
+
import { HyperLinkModel as se, RemoveHyperLinkMutation as ie, AddHyperLinkMutation as ae, UpdateHyperLinkRefMutation as $, UpdateHyperLinkMutation as x } from "@univerjs/sheets-hyper-link";
|
|
9
|
+
import { deserializeRangeWithSheet as oe, serializeRange as v } from "@univerjs/engine-formula";
|
|
10
|
+
var de = Object.defineProperty, ce = Object.getOwnPropertyDescriptor, ue = (s, e, t, n) => {
|
|
11
|
+
for (var r = n > 1 ? void 0 : n ? ce(e, t) : e, i = s.length - 1, a; i >= 0; i--)
|
|
12
|
+
(a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
|
|
13
|
+
return n && r && de(e, t, r), r;
|
|
14
|
+
}, pe = (s, e) => (t, n) => e(t, n, s);
|
|
15
|
+
let _ = class extends k {
|
|
16
|
+
constructor(e) {
|
|
10
17
|
super();
|
|
11
|
-
h(this, "_linkUpdate$", new
|
|
18
|
+
h(this, "_linkUpdate$", new ne());
|
|
12
19
|
h(this, "linkUpdate$", this._linkUpdate$.asObservable());
|
|
13
20
|
h(this, "_linkMap", /* @__PURE__ */ new Map());
|
|
14
21
|
h(this, "_linkPositionMap", /* @__PURE__ */ new Map());
|
|
15
|
-
this.disposeWithMe({
|
|
22
|
+
this._univerInstanceService = e, this.disposeWithMe({
|
|
16
23
|
dispose: () => {
|
|
17
24
|
this._linkUpdate$.complete();
|
|
18
25
|
}
|
|
19
26
|
});
|
|
20
27
|
}
|
|
21
|
-
_ensureMap(e,
|
|
22
|
-
let
|
|
23
|
-
|
|
24
|
-
let
|
|
25
|
-
|
|
26
|
-
let
|
|
27
|
-
|
|
28
|
-
let a =
|
|
29
|
-
return a || (a = /* @__PURE__ */ new Map(),
|
|
30
|
-
matrix:
|
|
28
|
+
_ensureMap(e, t) {
|
|
29
|
+
let n = this._linkMap.get(e);
|
|
30
|
+
n || (n = /* @__PURE__ */ new Map(), this._linkMap.set(e, n));
|
|
31
|
+
let r = n.get(t);
|
|
32
|
+
r || (r = new Y(), n.set(t, r));
|
|
33
|
+
let i = this._linkPositionMap.get(e);
|
|
34
|
+
i || (i = /* @__PURE__ */ new Map(), this._linkPositionMap.set(e, i));
|
|
35
|
+
let a = i.get(t);
|
|
36
|
+
return a || (a = /* @__PURE__ */ new Map(), i.set(t, a)), {
|
|
37
|
+
matrix: r,
|
|
31
38
|
positionMap: a
|
|
32
39
|
};
|
|
33
40
|
}
|
|
34
|
-
addHyperLink(e,
|
|
35
|
-
const { matrix:
|
|
36
|
-
return
|
|
41
|
+
addHyperLink(e, t, n) {
|
|
42
|
+
const { matrix: r, positionMap: i } = this._ensureMap(e, t);
|
|
43
|
+
return r.setValue(n.row, n.column, n), i.set(n.id, { row: n.row, column: n.column, link: n }), this._linkUpdate$.next({
|
|
37
44
|
unitId: e,
|
|
38
|
-
subUnitId:
|
|
39
|
-
payload:
|
|
45
|
+
subUnitId: t,
|
|
46
|
+
payload: n,
|
|
40
47
|
type: "add"
|
|
41
48
|
}), !0;
|
|
42
49
|
}
|
|
43
|
-
updateHyperLink(e,
|
|
44
|
-
const { matrix: a, positionMap:
|
|
45
|
-
if (!
|
|
46
|
-
return !
|
|
47
|
-
const c = a.getValue(
|
|
48
|
-
return c
|
|
50
|
+
updateHyperLink(e, t, n, r, i = !1) {
|
|
51
|
+
const { matrix: a, positionMap: o } = this._ensureMap(e, t), d = o.get(n);
|
|
52
|
+
if (!d)
|
|
53
|
+
return !0;
|
|
54
|
+
const c = a.getValue(d.row, d.column);
|
|
55
|
+
return c && (Object.assign(c, r), this._linkUpdate$.next({
|
|
49
56
|
unitId: e,
|
|
50
|
-
subUnitId:
|
|
57
|
+
subUnitId: t,
|
|
51
58
|
payload: {
|
|
52
59
|
display: c.display,
|
|
53
60
|
payload: c.payload
|
|
54
61
|
},
|
|
55
|
-
id:
|
|
56
|
-
type: "update"
|
|
57
|
-
|
|
62
|
+
id: n,
|
|
63
|
+
type: "update",
|
|
64
|
+
silent: i
|
|
65
|
+
})), !0;
|
|
58
66
|
}
|
|
59
|
-
updateHyperLinkRef(e,
|
|
60
|
-
const { matrix:
|
|
67
|
+
updateHyperLinkRef(e, t, n, r, i = !1) {
|
|
68
|
+
const { matrix: a, positionMap: o } = this._ensureMap(e, t), d = o.get(n);
|
|
61
69
|
if (!d)
|
|
62
|
-
return !
|
|
63
|
-
let
|
|
64
|
-
return !
|
|
70
|
+
return !0;
|
|
71
|
+
let c = a.getValue(d.row, d.column);
|
|
72
|
+
return !c || c.id !== n ? c = d.link : a.realDeleteValue(d.row, d.column), Object.assign(c, r), o.set(n, { ...r, link: c }), a.setValue(r.row, r.column, c), this._linkUpdate$.next({
|
|
65
73
|
unitId: e,
|
|
66
|
-
subUnitId:
|
|
67
|
-
payload:
|
|
68
|
-
id:
|
|
69
|
-
type: "updateRef"
|
|
74
|
+
subUnitId: t,
|
|
75
|
+
payload: r,
|
|
76
|
+
id: n,
|
|
77
|
+
type: "updateRef",
|
|
78
|
+
silent: i
|
|
70
79
|
}), !0;
|
|
71
80
|
}
|
|
72
|
-
removeHyperLink(e,
|
|
73
|
-
const { matrix:
|
|
81
|
+
removeHyperLink(e, t, n) {
|
|
82
|
+
const { matrix: r, positionMap: i } = this._ensureMap(e, t), a = i.get(n);
|
|
74
83
|
if (!a)
|
|
75
84
|
return !1;
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
return
|
|
85
|
+
i.delete(n);
|
|
86
|
+
const o = r.getValue(a.row, a.column);
|
|
87
|
+
return o && o.id === n && r.realDeleteValue(a.row, a.column), this._linkUpdate$.next({
|
|
79
88
|
unitId: e,
|
|
80
|
-
subUnitId:
|
|
81
|
-
payload:
|
|
89
|
+
subUnitId: t,
|
|
90
|
+
payload: a.link,
|
|
82
91
|
type: "remove"
|
|
83
92
|
}), !0;
|
|
84
93
|
}
|
|
85
|
-
getHyperLink(e,
|
|
86
|
-
const { matrix:
|
|
94
|
+
getHyperLink(e, t, n) {
|
|
95
|
+
const { matrix: r, positionMap: i } = this._ensureMap(e, t), a = i.get(n);
|
|
87
96
|
if (a)
|
|
88
|
-
return
|
|
97
|
+
return r.getValue(a.row, a.column);
|
|
98
|
+
}
|
|
99
|
+
getHyperLinkByLocation(e, t, n, r) {
|
|
100
|
+
const { matrix: i } = this._ensureMap(e, t);
|
|
101
|
+
return i.getValue(n, r);
|
|
89
102
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
103
|
+
getHyperLinkByLocationSync(e, t, n, r) {
|
|
104
|
+
var u, p, g, f, l;
|
|
105
|
+
const { matrix: i } = this._ensureMap(e, t), a = this._univerInstanceService.getUnit(e, A.UNIVER_SHEET), o = (u = a == null ? void 0 : a.getSheetBySheetId(t)) == null ? void 0 : u.getCellRaw(n, r), d = ((l = (f = o == null ? void 0 : o.v) != null ? f : (g = (p = o == null ? void 0 : o.p) == null ? void 0 : p.body) == null ? void 0 : g.dataStream.slice(0, -2)) != null ? l : "").toString(), c = i.getValue(n, r);
|
|
106
|
+
if (c)
|
|
107
|
+
return {
|
|
108
|
+
...c,
|
|
109
|
+
display: d
|
|
110
|
+
};
|
|
93
111
|
}
|
|
94
|
-
getSubUnit(e,
|
|
95
|
-
const { matrix:
|
|
96
|
-
return
|
|
97
|
-
|
|
98
|
-
}),
|
|
112
|
+
getSubUnit(e, t) {
|
|
113
|
+
const { matrix: n } = this._ensureMap(e, t), r = [];
|
|
114
|
+
return n.forValue((i, a, o) => {
|
|
115
|
+
o && r.push(o);
|
|
116
|
+
}), r;
|
|
99
117
|
}
|
|
100
118
|
getUnit(e) {
|
|
101
|
-
const
|
|
102
|
-
return
|
|
103
|
-
const
|
|
119
|
+
const t = this._linkMap.get(e);
|
|
120
|
+
return t ? Array.from(t.keys()).map((n) => {
|
|
121
|
+
const r = this.getSubUnit(e, n);
|
|
104
122
|
return {
|
|
105
123
|
unitId: e,
|
|
106
|
-
subUnitId:
|
|
107
|
-
links:
|
|
124
|
+
subUnitId: n,
|
|
125
|
+
links: r
|
|
108
126
|
};
|
|
109
127
|
}) : [];
|
|
110
128
|
}
|
|
111
129
|
deleteUnit(e) {
|
|
112
|
-
const
|
|
130
|
+
const t = this.getUnit(e);
|
|
113
131
|
this._linkMap.delete(e), this._linkPositionMap.delete(e), this._linkUpdate$.next({
|
|
114
132
|
type: "unload",
|
|
115
133
|
unitId: e,
|
|
116
|
-
unitLinks:
|
|
134
|
+
unitLinks: t
|
|
117
135
|
});
|
|
118
136
|
}
|
|
119
137
|
getAll() {
|
|
120
|
-
return Array.from(this._linkMap.keys()).map((
|
|
138
|
+
return Array.from(this._linkMap.keys()).map((t) => this.getUnit(t));
|
|
121
139
|
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
140
|
+
};
|
|
141
|
+
_ = ue([
|
|
142
|
+
pe(0, Z)
|
|
143
|
+
], _);
|
|
144
|
+
const H = {
|
|
145
|
+
type: m.MUTATION,
|
|
125
146
|
id: "sheets.mutation.add-hyper-link",
|
|
126
|
-
handler(
|
|
127
|
-
if (!
|
|
147
|
+
handler(s, e) {
|
|
148
|
+
if (!e)
|
|
128
149
|
return !1;
|
|
129
|
-
const
|
|
130
|
-
return
|
|
150
|
+
const t = s.get(_), { unitId: n, subUnitId: r, link: i } = e;
|
|
151
|
+
return t.addHyperLink(n, r, i);
|
|
131
152
|
}
|
|
132
|
-
},
|
|
133
|
-
type:
|
|
153
|
+
}, O = {
|
|
154
|
+
type: m.MUTATION,
|
|
134
155
|
id: "sheets.mutation.remove-hyper-link",
|
|
135
|
-
handler(
|
|
136
|
-
if (!
|
|
156
|
+
handler(s, e) {
|
|
157
|
+
if (!e)
|
|
137
158
|
return !1;
|
|
138
|
-
const
|
|
139
|
-
return
|
|
159
|
+
const t = s.get(_), { unitId: n, subUnitId: r, id: i } = e;
|
|
160
|
+
return t.removeHyperLink(n, r, i);
|
|
140
161
|
}
|
|
141
|
-
},
|
|
142
|
-
type:
|
|
162
|
+
}, T = {
|
|
163
|
+
type: m.COMMAND,
|
|
143
164
|
id: "sheets.command.remove-hyper-link",
|
|
144
|
-
async handler(
|
|
145
|
-
if (!
|
|
165
|
+
async handler(s, e) {
|
|
166
|
+
if (!e)
|
|
146
167
|
return !1;
|
|
147
|
-
const
|
|
148
|
-
id:
|
|
149
|
-
params:
|
|
150
|
-
}),
|
|
151
|
-
id:
|
|
152
|
-
params:
|
|
153
|
-
},
|
|
154
|
-
id:
|
|
168
|
+
const t = s.get(N), n = s.get(M), r = s.get(C), i = s.get(_), { unitId: a, subUnitId: o, id: d } = e, c = i.getHyperLink(a, o, d), { redos: u, undos: p } = t.onCommandExecute({
|
|
169
|
+
id: T.id,
|
|
170
|
+
params: e
|
|
171
|
+
}), g = {
|
|
172
|
+
id: O.id,
|
|
173
|
+
params: e
|
|
174
|
+
}, f = {
|
|
175
|
+
id: H.id,
|
|
155
176
|
params: {
|
|
156
|
-
unitId:
|
|
157
|
-
subUnitId:
|
|
158
|
-
link:
|
|
177
|
+
unitId: a,
|
|
178
|
+
subUnitId: o,
|
|
179
|
+
link: c
|
|
159
180
|
}
|
|
160
181
|
};
|
|
161
|
-
return (await
|
|
162
|
-
redoMutations: [
|
|
163
|
-
undoMutations: [
|
|
164
|
-
unitID:
|
|
182
|
+
return (await R([g, ...u], n)).result ? (r.pushUndoRedo({
|
|
183
|
+
redoMutations: [g, ...u],
|
|
184
|
+
undoMutations: [f, ...p],
|
|
185
|
+
unitID: a
|
|
165
186
|
}), !0) : !1;
|
|
166
187
|
}
|
|
167
|
-
},
|
|
168
|
-
type:
|
|
188
|
+
}, le = {
|
|
189
|
+
type: m.COMMAND,
|
|
169
190
|
id: "sheets.command.cancel-hyper-link",
|
|
170
|
-
async handler(
|
|
171
|
-
if (!
|
|
191
|
+
async handler(s, e) {
|
|
192
|
+
if (!e)
|
|
172
193
|
return !1;
|
|
173
|
-
const
|
|
174
|
-
id:
|
|
175
|
-
params:
|
|
176
|
-
},
|
|
177
|
-
id:
|
|
194
|
+
const t = s.get(M), n = s.get(C), r = s.get(_), { unitId: i, subUnitId: a, id: o } = e, d = r.getHyperLink(i, a, o), c = {
|
|
195
|
+
id: O.id,
|
|
196
|
+
params: e
|
|
197
|
+
}, u = {
|
|
198
|
+
id: H.id,
|
|
178
199
|
params: {
|
|
179
|
-
unitId:
|
|
180
|
-
subUnitId:
|
|
200
|
+
unitId: i,
|
|
201
|
+
subUnitId: a,
|
|
181
202
|
link: d
|
|
182
203
|
}
|
|
183
204
|
};
|
|
184
|
-
return (await
|
|
185
|
-
redoMutations: [
|
|
186
|
-
undoMutations: [
|
|
187
|
-
unitID:
|
|
205
|
+
return (await R([c], t)).result ? (n.pushUndoRedo({
|
|
206
|
+
redoMutations: [c],
|
|
207
|
+
undoMutations: [u],
|
|
208
|
+
unitID: i
|
|
188
209
|
}), !0) : !1;
|
|
189
210
|
}
|
|
190
|
-
},
|
|
191
|
-
type:
|
|
211
|
+
}, b = {
|
|
212
|
+
type: m.MUTATION,
|
|
192
213
|
id: "sheets.mutation.update-hyper-link",
|
|
193
|
-
handler(
|
|
194
|
-
if (!
|
|
214
|
+
handler(s, e) {
|
|
215
|
+
if (!e)
|
|
195
216
|
return !1;
|
|
196
|
-
const
|
|
197
|
-
return
|
|
217
|
+
const t = s.get(_), { unitId: n, subUnitId: r, payload: i, id: a } = e;
|
|
218
|
+
return t.updateHyperLink(n, r, a, i, !1);
|
|
198
219
|
}
|
|
199
|
-
},
|
|
200
|
-
type:
|
|
220
|
+
}, he = {
|
|
221
|
+
type: m.MUTATION,
|
|
201
222
|
id: "sheets.mutation.update-hyper-link-ref",
|
|
202
|
-
handler(
|
|
203
|
-
if (!
|
|
223
|
+
handler(s, e) {
|
|
224
|
+
if (!e)
|
|
204
225
|
return !1;
|
|
205
|
-
const
|
|
206
|
-
return
|
|
226
|
+
const t = s.get(_), { unitId: n, subUnitId: r, id: i, row: a, column: o, silent: d } = e;
|
|
227
|
+
return t.updateHyperLinkRef(n, r, i, { row: a, column: o }, d);
|
|
207
228
|
}
|
|
208
|
-
},
|
|
209
|
-
type:
|
|
229
|
+
}, W = {
|
|
230
|
+
type: m.COMMAND,
|
|
210
231
|
id: "sheets.command.add-hyper-link",
|
|
211
|
-
async handler(
|
|
212
|
-
if (!
|
|
232
|
+
async handler(s, e) {
|
|
233
|
+
if (!e)
|
|
213
234
|
return !1;
|
|
214
|
-
const
|
|
215
|
-
id:
|
|
216
|
-
params:
|
|
217
|
-
}),
|
|
218
|
-
id:
|
|
219
|
-
params:
|
|
220
|
-
},
|
|
221
|
-
id:
|
|
235
|
+
const t = s.get(N), n = s.get(M), r = s.get(C), { unitId: i, subUnitId: a, link: o } = e, { redos: d, undos: c } = t.onCommandExecute({
|
|
236
|
+
id: W.id,
|
|
237
|
+
params: e
|
|
238
|
+
}), u = {
|
|
239
|
+
id: H.id,
|
|
240
|
+
params: e
|
|
241
|
+
}, p = {
|
|
242
|
+
id: O.id,
|
|
222
243
|
params: {
|
|
223
|
-
unitId:
|
|
224
|
-
subUnitId:
|
|
225
|
-
id:
|
|
244
|
+
unitId: i,
|
|
245
|
+
subUnitId: a,
|
|
246
|
+
id: o.id
|
|
226
247
|
}
|
|
227
248
|
};
|
|
228
|
-
return (await
|
|
229
|
-
redoMutations: [
|
|
230
|
-
undoMutations: [
|
|
231
|
-
unitID:
|
|
249
|
+
return (await R([u, ...d], n)).result ? (r.pushUndoRedo({
|
|
250
|
+
redoMutations: [u, ...d],
|
|
251
|
+
undoMutations: [p, ...c],
|
|
252
|
+
unitID: i
|
|
232
253
|
}), !0) : !1;
|
|
233
254
|
}
|
|
234
255
|
};
|
|
235
|
-
function
|
|
236
|
-
const { row:
|
|
237
|
-
return
|
|
256
|
+
function ge(s) {
|
|
257
|
+
const { row: e, column: t, id: n, ...r } = s;
|
|
258
|
+
return r;
|
|
238
259
|
}
|
|
239
|
-
const
|
|
240
|
-
type:
|
|
260
|
+
const J = {
|
|
261
|
+
type: m.COMMAND,
|
|
241
262
|
id: "sheets.command.update-hyper-link",
|
|
242
|
-
async handler(
|
|
243
|
-
if (!
|
|
263
|
+
async handler(s, e) {
|
|
264
|
+
if (!e)
|
|
244
265
|
return !1;
|
|
245
|
-
const
|
|
246
|
-
if (!
|
|
266
|
+
const t = s.get(N), n = s.get(M), r = s.get(C), i = s.get(_), { unitId: a, subUnitId: o, id: d } = e, c = i.getHyperLink(a, o, d);
|
|
267
|
+
if (!c)
|
|
247
268
|
return !1;
|
|
248
|
-
const { redos:
|
|
249
|
-
id:
|
|
250
|
-
params:
|
|
251
|
-
}),
|
|
252
|
-
id:
|
|
253
|
-
params:
|
|
254
|
-
},
|
|
255
|
-
id:
|
|
269
|
+
const { redos: u, undos: p } = t.onCommandExecute({
|
|
270
|
+
id: J.id,
|
|
271
|
+
params: e
|
|
272
|
+
}), g = {
|
|
273
|
+
id: b.id,
|
|
274
|
+
params: e
|
|
275
|
+
}, f = {
|
|
276
|
+
id: b.id,
|
|
256
277
|
params: {
|
|
257
|
-
unitId:
|
|
258
|
-
subUnitId:
|
|
278
|
+
unitId: a,
|
|
279
|
+
subUnitId: o,
|
|
259
280
|
id: d,
|
|
260
|
-
payload:
|
|
281
|
+
payload: ge(c)
|
|
261
282
|
}
|
|
262
283
|
};
|
|
263
|
-
return (await
|
|
264
|
-
redoMutations: [
|
|
265
|
-
undoMutations: [
|
|
266
|
-
unitID:
|
|
284
|
+
return (await R([g, ...u], n)).result ? (r.pushUndoRedo({
|
|
285
|
+
redoMutations: [g, ...u],
|
|
286
|
+
undoMutations: [f, ...p],
|
|
287
|
+
unitID: a
|
|
267
288
|
}), !0) : !1;
|
|
268
289
|
}
|
|
269
290
|
};
|
|
270
|
-
var
|
|
271
|
-
for (var
|
|
272
|
-
(
|
|
273
|
-
return
|
|
274
|
-
},
|
|
275
|
-
let
|
|
276
|
-
constructor(
|
|
277
|
-
super(), this._commandService =
|
|
291
|
+
var _e = Object.defineProperty, fe = Object.getOwnPropertyDescriptor, me = (s, e, t, n) => {
|
|
292
|
+
for (var r = n > 1 ? void 0 : n ? fe(e, t) : e, i = s.length - 1, a; i >= 0; i--)
|
|
293
|
+
(a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
|
|
294
|
+
return n && r && _e(e, t, r), r;
|
|
295
|
+
}, Me = (s, e) => (t, n) => e(t, n, s);
|
|
296
|
+
let L = class extends k {
|
|
297
|
+
constructor(s) {
|
|
298
|
+
super(), this._commandService = s, this._registerCommands();
|
|
278
299
|
}
|
|
279
300
|
_registerCommands() {
|
|
280
301
|
[
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
].forEach((
|
|
290
|
-
this._commandService.registerCommand(
|
|
302
|
+
H,
|
|
303
|
+
b,
|
|
304
|
+
O,
|
|
305
|
+
he,
|
|
306
|
+
W,
|
|
307
|
+
J,
|
|
308
|
+
T,
|
|
309
|
+
le
|
|
310
|
+
].forEach((s) => {
|
|
311
|
+
this._commandService.registerCommand(s);
|
|
291
312
|
});
|
|
292
313
|
}
|
|
293
314
|
};
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
],
|
|
298
|
-
var
|
|
299
|
-
const
|
|
300
|
-
var
|
|
301
|
-
for (var
|
|
302
|
-
(
|
|
303
|
-
return
|
|
304
|
-
},
|
|
305
|
-
let
|
|
306
|
-
constructor(
|
|
307
|
-
super(), this._resourceManagerService =
|
|
315
|
+
L = me([
|
|
316
|
+
E(D.Starting, L),
|
|
317
|
+
Me(0, M)
|
|
318
|
+
], L);
|
|
319
|
+
var ye = /* @__PURE__ */ ((s) => (s[s.range = 0] = "range", s[s.link = 1] = "link", s))(ye || {});
|
|
320
|
+
const G = "SHEET_HYPER_LINK_PLUGIN", Re = "err";
|
|
321
|
+
var K = /* @__PURE__ */ ((s) => (s[s.UNIVER_UNKNOWN = 0] = "UNIVER_UNKNOWN", s[s.UNIVER_DOC = 1] = "UNIVER_DOC", s[s.UNIVER_SHEET = 2] = "UNIVER_SHEET", s[s.UNIVER_SLIDE = 3] = "UNIVER_SLIDE", s[s.UNRECOGNIZED = -1] = "UNRECOGNIZED", s))(K || {}), ve = Object.defineProperty, we = Object.getOwnPropertyDescriptor, Se = (s, e, t, n) => {
|
|
322
|
+
for (var r = n > 1 ? void 0 : n ? we(e, t) : e, i = s.length - 1, a; i >= 0; i--)
|
|
323
|
+
(a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
|
|
324
|
+
return n && r && ve(e, t, r), r;
|
|
325
|
+
}, V = (s, e) => (t, n) => e(t, n, s);
|
|
326
|
+
let U = class extends k {
|
|
327
|
+
constructor(s, e) {
|
|
328
|
+
super(), this._resourceManagerService = s, this._hyperLinkModel = e, this._initSnapshot();
|
|
308
329
|
}
|
|
309
330
|
_initSnapshot() {
|
|
310
|
-
const
|
|
311
|
-
const
|
|
312
|
-
return
|
|
313
|
-
|
|
314
|
-
}), JSON.stringify(
|
|
315
|
-
},
|
|
316
|
-
if (!
|
|
331
|
+
const s = (t) => {
|
|
332
|
+
const n = this._hyperLinkModel.getUnit(t), r = {};
|
|
333
|
+
return n ? (n.forEach((i) => {
|
|
334
|
+
r[i.subUnitId] = i.links.map(({ display: a, ...o }) => o);
|
|
335
|
+
}), JSON.stringify(r)) : "";
|
|
336
|
+
}, e = (t) => {
|
|
337
|
+
if (!t)
|
|
317
338
|
return {};
|
|
318
339
|
try {
|
|
319
|
-
return JSON.parse(
|
|
340
|
+
return JSON.parse(t);
|
|
320
341
|
} catch {
|
|
321
342
|
return {};
|
|
322
343
|
}
|
|
323
344
|
};
|
|
324
345
|
this.disposeWithMe(
|
|
325
346
|
this._resourceManagerService.registerPluginResource({
|
|
326
|
-
pluginName:
|
|
327
|
-
businesses: [
|
|
328
|
-
toJson: (
|
|
329
|
-
parseJson: (
|
|
330
|
-
onUnLoad: (
|
|
331
|
-
this._hyperLinkModel.deleteUnit(
|
|
347
|
+
pluginName: G,
|
|
348
|
+
businesses: [K.UNIVER_SHEET],
|
|
349
|
+
toJson: (t) => s(t),
|
|
350
|
+
parseJson: (t) => e(t),
|
|
351
|
+
onUnLoad: (t) => {
|
|
352
|
+
this._hyperLinkModel.deleteUnit(t);
|
|
332
353
|
},
|
|
333
|
-
onLoad: async (
|
|
334
|
-
Object.keys(
|
|
335
|
-
r
|
|
336
|
-
this._hyperLinkModel.addHyperLink(
|
|
354
|
+
onLoad: async (t, n) => {
|
|
355
|
+
Object.keys(n).forEach((r) => {
|
|
356
|
+
n[r].forEach((a) => {
|
|
357
|
+
this._hyperLinkModel.addHyperLink(t, r, a);
|
|
337
358
|
});
|
|
338
359
|
});
|
|
339
360
|
}
|
|
@@ -341,44 +362,265 @@ let g = class extends I {
|
|
|
341
362
|
);
|
|
342
363
|
}
|
|
343
364
|
};
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
],
|
|
349
|
-
var
|
|
350
|
-
for (var
|
|
351
|
-
(
|
|
352
|
-
return
|
|
353
|
-
},
|
|
354
|
-
let
|
|
355
|
-
constructor(n,
|
|
356
|
-
super()
|
|
357
|
-
|
|
358
|
-
|
|
365
|
+
U = Se([
|
|
366
|
+
E(D.Starting, U),
|
|
367
|
+
V(0, q),
|
|
368
|
+
V(1, y(_))
|
|
369
|
+
], U);
|
|
370
|
+
var Le = Object.defineProperty, Ue = Object.getOwnPropertyDescriptor, Pe = (s, e, t, n) => {
|
|
371
|
+
for (var r = n > 1 ? void 0 : n ? Ue(e, t) : e, i = s.length - 1, a; i >= 0; i--)
|
|
372
|
+
(a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
|
|
373
|
+
return n && r && Le(e, t, r), r;
|
|
374
|
+
}, w = (s, e) => (t, n) => e(t, n, s);
|
|
375
|
+
let P = class extends k {
|
|
376
|
+
constructor(e, t, n, r) {
|
|
377
|
+
super();
|
|
378
|
+
h(this, "_disposableMap", /* @__PURE__ */ new Map());
|
|
379
|
+
h(this, "_watchDisposableMap", /* @__PURE__ */ new Map());
|
|
380
|
+
h(this, "_rangeDisableMap", /* @__PURE__ */ new Map());
|
|
381
|
+
h(this, "_rangeWatcherMap", /* @__PURE__ */ new Map());
|
|
382
|
+
h(this, "_handlePositionChange", (e, t, n, r, i) => {
|
|
383
|
+
const a = {
|
|
384
|
+
startColumn: n.column,
|
|
385
|
+
endColumn: n.column,
|
|
386
|
+
startRow: n.row,
|
|
387
|
+
endRow: n.row
|
|
388
|
+
};
|
|
389
|
+
return r ? {
|
|
390
|
+
redos: [{
|
|
391
|
+
id: $.id,
|
|
392
|
+
params: {
|
|
393
|
+
unitId: e,
|
|
394
|
+
subUnitId: t,
|
|
395
|
+
id: n.id,
|
|
396
|
+
row: r.startRow,
|
|
397
|
+
column: r.startColumn,
|
|
398
|
+
silent: i
|
|
399
|
+
}
|
|
400
|
+
}],
|
|
401
|
+
undos: [{
|
|
402
|
+
id: $.id,
|
|
403
|
+
params: {
|
|
404
|
+
unitId: e,
|
|
405
|
+
subUnitId: t,
|
|
406
|
+
id: n.id,
|
|
407
|
+
row: a.startRow,
|
|
408
|
+
column: a.startColumn,
|
|
409
|
+
silent: i
|
|
410
|
+
}
|
|
411
|
+
}]
|
|
412
|
+
} : {
|
|
413
|
+
redos: [{
|
|
414
|
+
id: ie.id,
|
|
415
|
+
params: {
|
|
416
|
+
unitId: e,
|
|
417
|
+
subUnitId: t,
|
|
418
|
+
id: n.id
|
|
419
|
+
}
|
|
420
|
+
}],
|
|
421
|
+
undos: [{
|
|
422
|
+
id: ae.id,
|
|
423
|
+
params: {
|
|
424
|
+
unitId: e,
|
|
425
|
+
subUnitId: t,
|
|
426
|
+
link: n
|
|
427
|
+
}
|
|
428
|
+
}]
|
|
429
|
+
};
|
|
430
|
+
});
|
|
431
|
+
this._refRangeService = e, this._hyperLinkModel = t, this._selectionManagerService = n, this._commandService = r, this._initData(), this._initRefRange();
|
|
432
|
+
}
|
|
433
|
+
_registerPosition(e, t, n) {
|
|
434
|
+
const r = n.id, i = {
|
|
435
|
+
startColumn: n.column,
|
|
436
|
+
endColumn: n.column,
|
|
437
|
+
startRow: n.row,
|
|
438
|
+
endRow: n.row
|
|
439
|
+
}, a = (o) => {
|
|
440
|
+
const d = I(i, o, { selectionManagerService: this._selectionManagerService });
|
|
441
|
+
return d && d.startColumn === i.startColumn && d.startRow === i.startRow ? {
|
|
442
|
+
undos: [],
|
|
443
|
+
redos: []
|
|
444
|
+
} : this._handlePositionChange(e, t, n, d, !1);
|
|
445
|
+
};
|
|
446
|
+
this._disposableMap.set(r, this._refRangeService.registerRefRange(i, a, e, t));
|
|
447
|
+
}
|
|
448
|
+
_watchPosition(e, t, n) {
|
|
449
|
+
const r = n.id, i = {
|
|
450
|
+
startColumn: n.column,
|
|
451
|
+
endColumn: n.column,
|
|
452
|
+
startRow: n.row,
|
|
453
|
+
endRow: n.row
|
|
454
|
+
};
|
|
455
|
+
this._watchDisposableMap.set(
|
|
456
|
+
r,
|
|
457
|
+
this._refRangeService.watchRange(e, t, i, (a, o) => {
|
|
458
|
+
const { redos: d } = this._handlePositionChange(e, t, n, o, !0);
|
|
459
|
+
R(d, this._commandService, { onlyLocal: !0 });
|
|
460
|
+
}, !0)
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
_unregisterPosition(e) {
|
|
464
|
+
const t = this._disposableMap.get(e);
|
|
465
|
+
t == null || t.dispose(), this._disposableMap.delete(e);
|
|
466
|
+
}
|
|
467
|
+
_unwatchPosition(e) {
|
|
468
|
+
const t = this._watchDisposableMap.get(e);
|
|
469
|
+
t == null || t.dispose(), this._watchDisposableMap.delete(e);
|
|
470
|
+
}
|
|
471
|
+
_registerRange(e, t, n, r = !1) {
|
|
472
|
+
var i, a, o;
|
|
473
|
+
if (n.startsWith("#")) {
|
|
474
|
+
const d = new URLSearchParams(n.slice(1)), c = {
|
|
475
|
+
gid: (i = d.get("gid")) != null ? i : "",
|
|
476
|
+
range: (a = d.get("range")) != null ? a : "",
|
|
477
|
+
rangeid: (o = d.get("rangeid")) != null ? o : ""
|
|
478
|
+
};
|
|
479
|
+
if (c.range && c.gid) {
|
|
480
|
+
const u = c.gid, p = oe(c.range).range;
|
|
481
|
+
if (F(p) && c.range !== Re) {
|
|
482
|
+
const g = (f) => {
|
|
483
|
+
const l = I(p, f, { selectionManagerService: this._selectionManagerService });
|
|
484
|
+
return l && v(l) === v(p) ? {
|
|
485
|
+
redos: [],
|
|
486
|
+
undos: []
|
|
487
|
+
} : {
|
|
488
|
+
redos: [{
|
|
489
|
+
id: x.id,
|
|
490
|
+
params: {
|
|
491
|
+
unitId: e,
|
|
492
|
+
subUnitId: u,
|
|
493
|
+
id: t,
|
|
494
|
+
payload: {
|
|
495
|
+
payload: `#gid=${u}&range=${l ? v(l) : "err"}`
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}],
|
|
499
|
+
undos: [{
|
|
500
|
+
id: x.id,
|
|
501
|
+
params: {
|
|
502
|
+
unitId: e,
|
|
503
|
+
subUnitId: u,
|
|
504
|
+
id: t,
|
|
505
|
+
payload: {
|
|
506
|
+
payload: n
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}]
|
|
510
|
+
};
|
|
511
|
+
};
|
|
512
|
+
this._rangeDisableMap.set(t, this._refRangeService.registerRefRange(p, g, e, u)), r || this._rangeWatcherMap.set(t, this._refRangeService.watchRange(e, u, p, (f, l) => {
|
|
513
|
+
this._hyperLinkModel.updateHyperLink(e, u, t, {
|
|
514
|
+
payload: `#gid=${u}&range=${l ? v(l) : "err"}`
|
|
515
|
+
}, !0);
|
|
516
|
+
}, !0));
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
_unregisterRange(e) {
|
|
522
|
+
const t = this._rangeDisableMap.get(e);
|
|
523
|
+
t == null || t.dispose(), this._rangeDisableMap.delete(e);
|
|
524
|
+
}
|
|
525
|
+
_unwatchRange(e) {
|
|
526
|
+
const t = this._rangeWatcherMap.get(e);
|
|
527
|
+
t == null || t.dispose(), this._rangeWatcherMap.delete(e);
|
|
528
|
+
}
|
|
529
|
+
_initData() {
|
|
530
|
+
this._hyperLinkModel.getAll().forEach((t) => {
|
|
531
|
+
t.forEach((n) => {
|
|
532
|
+
const { unitId: r, subUnitId: i, links: a } = n;
|
|
533
|
+
a.forEach((o) => {
|
|
534
|
+
this._registerPosition(r, i, o), this._watchPosition(r, i, o), this._registerRange(r, o.id, o.payload);
|
|
535
|
+
});
|
|
536
|
+
});
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
_initRefRange() {
|
|
540
|
+
this.disposeWithMe(
|
|
541
|
+
this._hyperLinkModel.linkUpdate$.subscribe((e) => {
|
|
542
|
+
switch (e.type) {
|
|
543
|
+
case "add": {
|
|
544
|
+
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);
|
|
545
|
+
break;
|
|
546
|
+
}
|
|
547
|
+
case "remove": {
|
|
548
|
+
this._unregisterPosition(e.payload.id), this._unwatchPosition(e.payload.id), this._unregisterRange(e.payload.id), this._unwatchRange(e.payload.id);
|
|
549
|
+
break;
|
|
550
|
+
}
|
|
551
|
+
case "updateRef": {
|
|
552
|
+
const { unitId: t, subUnitId: n, id: r, silent: i } = e, a = this._hyperLinkModel.getHyperLink(t, n, r);
|
|
553
|
+
if (!a)
|
|
554
|
+
return;
|
|
555
|
+
this._unregisterPosition(r), this._registerPosition(t, n, a), i || (this._unwatchPosition(r), this._watchPosition(t, n, a));
|
|
556
|
+
break;
|
|
557
|
+
}
|
|
558
|
+
case "unload": {
|
|
559
|
+
const { unitLinks: t } = e;
|
|
560
|
+
t.forEach((n) => {
|
|
561
|
+
const { links: r } = n;
|
|
562
|
+
r.forEach((i) => {
|
|
563
|
+
this._unregisterPosition(i.id), this._unwatchPosition(i.id), this._unregisterRange(i.id), this._unwatchRange(i.id);
|
|
564
|
+
});
|
|
565
|
+
});
|
|
566
|
+
break;
|
|
567
|
+
}
|
|
568
|
+
case "update": {
|
|
569
|
+
e.silent || this._unwatchRange(e.id), this._unregisterRange(e.id), this._registerRange(e.unitId, e.id, e.payload.payload, e.silent);
|
|
570
|
+
break;
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
})
|
|
574
|
+
), this.disposeWithMe(Q(() => {
|
|
575
|
+
this._disposableMap.forEach((e) => {
|
|
576
|
+
e.dispose();
|
|
577
|
+
}), this._disposableMap.clear();
|
|
578
|
+
}));
|
|
579
|
+
}
|
|
580
|
+
};
|
|
581
|
+
P = Pe([
|
|
582
|
+
E(D.Starting, P),
|
|
583
|
+
w(0, y(ee)),
|
|
584
|
+
w(1, y(se)),
|
|
585
|
+
w(2, y(te)),
|
|
586
|
+
w(3, M)
|
|
587
|
+
], P);
|
|
588
|
+
var ke = Object.defineProperty, Ce = Object.getOwnPropertyDescriptor, He = (s, e, t, n) => {
|
|
589
|
+
for (var r = n > 1 ? void 0 : n ? Ce(e, t) : e, i = s.length - 1, a; i >= 0; i--)
|
|
590
|
+
(a = s[i]) && (r = (n ? a(e, t, r) : a(r)) || r);
|
|
591
|
+
return n && r && ke(e, t, r), r;
|
|
592
|
+
}, Oe = (s, e) => (t, n) => e(t, n, s), S;
|
|
593
|
+
let j = (S = class extends X {
|
|
594
|
+
constructor(s, e) {
|
|
595
|
+
super(), this._injector = e;
|
|
596
|
+
}
|
|
597
|
+
onStarting(s) {
|
|
359
598
|
[
|
|
360
|
-
[
|
|
361
|
-
[
|
|
362
|
-
[
|
|
363
|
-
|
|
364
|
-
|
|
599
|
+
[U],
|
|
600
|
+
[L],
|
|
601
|
+
[P],
|
|
602
|
+
[_]
|
|
603
|
+
].forEach((e) => {
|
|
604
|
+
s.add(e);
|
|
365
605
|
});
|
|
366
606
|
}
|
|
367
|
-
}, h(
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
],
|
|
607
|
+
}, h(S, "pluginName", G), h(S, "type", A.UNIVER_SHEET), S);
|
|
608
|
+
j = He([
|
|
609
|
+
Oe(1, y(re))
|
|
610
|
+
], j);
|
|
371
611
|
export {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
612
|
+
W as AddHyperLinkCommand,
|
|
613
|
+
H as AddHyperLinkMutation,
|
|
614
|
+
le as CancelHyperLinkCommand,
|
|
615
|
+
Re as ERROR_RANGE,
|
|
616
|
+
_ as HyperLinkModel,
|
|
617
|
+
ye as HyperLinkType,
|
|
618
|
+
T as RemoveHyperLinkCommand,
|
|
619
|
+
O as RemoveHyperLinkMutation,
|
|
620
|
+
L as SheetsHyperLinkController,
|
|
621
|
+
P as SheetsHyperLinkRefRangeController,
|
|
622
|
+
j as UniverSheetsHyperLinkPlugin,
|
|
623
|
+
J as UpdateHyperLinkCommand,
|
|
624
|
+
b as UpdateHyperLinkMutation,
|
|
625
|
+
he as UpdateHyperLinkRefMutation
|
|
384
626
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Disposable, ICommandService } from '@univerjs/core';
|
|
2
|
+
import { RefRangeService, SelectionManagerService } from '@univerjs/sheets';
|
|
3
|
+
import { HyperLinkModel } from '@univerjs/sheets-hyper-link';
|
|
4
|
+
|
|
5
|
+
export declare class SheetsHyperLinkRefRangeController extends Disposable {
|
|
6
|
+
private readonly _refRangeService;
|
|
7
|
+
private readonly _hyperLinkModel;
|
|
8
|
+
private readonly _selectionManagerService;
|
|
9
|
+
private readonly _commandService;
|
|
10
|
+
private _disposableMap;
|
|
11
|
+
private _watchDisposableMap;
|
|
12
|
+
private _rangeDisableMap;
|
|
13
|
+
private _rangeWatcherMap;
|
|
14
|
+
constructor(_refRangeService: RefRangeService, _hyperLinkModel: HyperLinkModel, _selectionManagerService: SelectionManagerService, _commandService: ICommandService);
|
|
15
|
+
private _handlePositionChange;
|
|
16
|
+
private _registerPosition;
|
|
17
|
+
private _watchPosition;
|
|
18
|
+
private _unregisterPosition;
|
|
19
|
+
private _unwatchPosition;
|
|
20
|
+
private _registerRange;
|
|
21
|
+
private _unregisterRange;
|
|
22
|
+
private _unwatchRange;
|
|
23
|
+
private _initData;
|
|
24
|
+
private _initRefRange;
|
|
25
|
+
}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -24,4 +24,6 @@ export { HyperLinkModel } from './models/hyper-link.model';
|
|
|
24
24
|
export { SheetsHyperLinkController } from './controllers/sheet-hyper-link.controller';
|
|
25
25
|
export { HyperLinkType } from './types/enums/hyper-link-type';
|
|
26
26
|
export { UniverSheetsHyperLinkPlugin } from './plugin';
|
|
27
|
+
export { SheetsHyperLinkRefRangeController } from './controllers/ref-range.controller';
|
|
27
28
|
export type { ICellHyperLink, ICellLinkContent } from './types/interfaces/i-hyper-link';
|
|
29
|
+
export { ERROR_RANGE } from './types/const';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Disposable } from '@univerjs/core';
|
|
1
|
+
import { Disposable, IUniverInstanceService } from '@univerjs/core';
|
|
2
2
|
import { ICellHyperLink, ICellLinkContent } from '../types/interfaces/i-hyper-link';
|
|
3
3
|
|
|
4
4
|
type LinkUpdate = {
|
|
@@ -6,17 +6,20 @@ type LinkUpdate = {
|
|
|
6
6
|
payload: ICellHyperLink;
|
|
7
7
|
unitId: string;
|
|
8
8
|
subUnitId: string;
|
|
9
|
+
silent?: boolean;
|
|
9
10
|
} | {
|
|
10
11
|
type: 'remove';
|
|
11
12
|
payload: ICellHyperLink;
|
|
12
13
|
unitId: string;
|
|
13
14
|
subUnitId: string;
|
|
15
|
+
silent?: boolean;
|
|
14
16
|
} | {
|
|
15
17
|
type: 'update';
|
|
16
18
|
unitId: string;
|
|
17
19
|
subUnitId: string;
|
|
18
20
|
payload: ICellLinkContent;
|
|
19
21
|
id: string;
|
|
22
|
+
silent?: boolean;
|
|
20
23
|
} | {
|
|
21
24
|
type: 'updateRef';
|
|
22
25
|
unitId: string;
|
|
@@ -26,6 +29,7 @@ type LinkUpdate = {
|
|
|
26
29
|
row: number;
|
|
27
30
|
column: number;
|
|
28
31
|
};
|
|
32
|
+
silent?: boolean;
|
|
29
33
|
} | {
|
|
30
34
|
type: 'unload';
|
|
31
35
|
unitId: string;
|
|
@@ -34,23 +38,32 @@ type LinkUpdate = {
|
|
|
34
38
|
subUnitId: string;
|
|
35
39
|
links: ICellHyperLink[];
|
|
36
40
|
}[];
|
|
41
|
+
silent?: boolean;
|
|
37
42
|
};
|
|
38
43
|
export declare class HyperLinkModel extends Disposable {
|
|
44
|
+
private readonly _univerInstanceService;
|
|
39
45
|
private _linkUpdate$;
|
|
40
46
|
linkUpdate$: import('rxjs').Observable<LinkUpdate>;
|
|
41
47
|
private _linkMap;
|
|
42
48
|
private _linkPositionMap;
|
|
43
|
-
constructor();
|
|
49
|
+
constructor(_univerInstanceService: IUniverInstanceService);
|
|
44
50
|
private _ensureMap;
|
|
45
51
|
addHyperLink(unitId: string, subUnitId: string, link: ICellHyperLink): boolean;
|
|
46
52
|
updateHyperLink(unitId: string, subUnitId: string, id: string, payload: Partial<ICellLinkContent>, silent?: boolean): boolean;
|
|
47
53
|
updateHyperLinkRef(unitId: string, subUnitId: string, id: string, payload: {
|
|
48
54
|
row: number;
|
|
49
55
|
column: number;
|
|
50
|
-
}): boolean;
|
|
56
|
+
}, silent?: boolean): boolean;
|
|
51
57
|
removeHyperLink(unitId: string, subUnitId: string, id: string): boolean;
|
|
52
58
|
getHyperLink(unitId: string, subUnitId: string, id: string): ICellHyperLink | undefined;
|
|
53
59
|
getHyperLinkByLocation(unitId: string, subUnitId: string, row: number, column: number): ICellHyperLink | undefined;
|
|
60
|
+
getHyperLinkByLocationSync(unitId: string, subUnitId: string, row: number, column: number): {
|
|
61
|
+
display: string;
|
|
62
|
+
id: string;
|
|
63
|
+
row: number;
|
|
64
|
+
column: number;
|
|
65
|
+
payload: string;
|
|
66
|
+
} | undefined;
|
|
54
67
|
getSubUnit(unitId: string, subUnitId: string): ICellHyperLink[];
|
|
55
68
|
getUnit(unitId: string): {
|
|
56
69
|
unitId: string;
|
|
@@ -22,7 +22,10 @@ export interface ICellLinkContent {
|
|
|
22
22
|
* file: file://a.xlsx
|
|
23
23
|
*/
|
|
24
24
|
payload: string;
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* only for notify, if you wan't to read the display of text, use cell-value of cell-matrix instead
|
|
27
|
+
*/
|
|
28
|
+
display?: string;
|
|
26
29
|
}
|
|
27
30
|
export interface ICellHyperLink extends ICellLinkContent {
|
|
28
31
|
id: string;
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(d,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs"),require("@wendellhu/redi")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs","@wendellhu/redi"],a):(d=typeof globalThis<"u"?globalThis:d||self,a(d.UniverSheetsHyperLink={},d.UniverCore,d.UniverSheets,d.rxjs,d["@wendellhu/redi"]))})(this,function(d,a,h,D,L){"use strict";var Z=Object.defineProperty;var B=(d,a,h)=>a in d?Z(d,a,{enumerable:!0,configurable:!0,writable:!0,value:h}):d[a]=h;var y=(d,a,h)=>(B(d,typeof a!="symbol"?a+"":a,h),h);var S;class m extends a.Disposable{constructor(){super();y(this,"_linkUpdate$",new D.Subject);y(this,"linkUpdate$",this._linkUpdate$.asObservable());y(this,"_linkMap",new Map);y(this,"_linkPositionMap",new Map);this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let t=this._linkMap.get(e);t||(t=new Map,this._linkMap.set(e,t));let s=t.get(n);s||(s=new a.ObjectMatrix,t.set(n,s));let o=this._linkPositionMap.get(e);o||(o=new Map,this._linkPositionMap.set(e,o));let u=o.get(n);return u||(u=new Map,o.set(n,u)),{matrix:s,positionMap:u}}addHyperLink(e,n,t){const{matrix:s,positionMap:o}=this._ensureMap(e,n);return s.setValue(t.row,t.column,t),o.set(t.id,{row:t.row,column:t.column,link:t}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:t,type:"add"}),!0}updateHyperLink(e,n,t,s,o){const{matrix:u,positionMap:p}=this._ensureMap(e,n),l=p.get(t);if(!l)return!1;const c=u.getValue(l.row,l.column);return c?(Object.assign(c,s),o||this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:c.display,payload:c.payload},id:t,type:"update"}),!0):!1}updateHyperLinkRef(e,n,t,s){const{matrix:o,positionMap:u}=this._ensureMap(e,n),p=u.get(t);if(!p)return!1;let l=o.getValue(p.row,p.column);return!l||l.id!==t?l=p.link:o.realDeleteValue(p.row,p.column),Object.assign(l,s),u.set(t,{...s,link:l}),o.setValue(s.row,s.column,l),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:s,id:t,type:"updateRef"}),!0}removeHyperLink(e,n,t){const{matrix:s,positionMap:o}=this._ensureMap(e,n),u=o.get(t);if(!u)return!1;o.delete(t);const p=s.getValue(u.row,u.column);return p&&p.id===t&&s.realDeleteValue(u.row,u.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:p,type:"remove"}),!0}getHyperLink(e,n,t){const{matrix:s,positionMap:o}=this._ensureMap(e,n),u=o.get(t);if(u)return s.getValue(u.row,u.column)}getHyperLinkByLocation(e,n,t,s){const{matrix:o}=this._ensureMap(e,n);return o.getValue(t,s)}getSubUnit(e,n){const{matrix:t}=this._ensureMap(e,n),s=[];return t.forValue((o,u,p)=>{p&&s.push(p)}),s}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(t=>{const s=this.getSubUnit(e,t);return{unitId:e,subUnitId:t,links:s}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}}const M={type:a.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(i,r){if(!r)return!1;const e=i.get(m),{unitId:n,subUnitId:t,link:s}=r;return e.addHyperLink(n,t,s)}},k={type:a.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(i,r){if(!r)return!1;const e=i.get(m),{unitId:n,subUnitId:t,id:s}=r;return e.removeHyperLink(n,t,s)}},U={type:a.CommandType.COMMAND,id:"sheets.command.remove-hyper-link",async handler(i,r){if(!r)return!1;const e=i.get(h.SheetInterceptorService),n=i.get(a.ICommandService),t=i.get(a.IUndoRedoService),s=i.get(m),{unitId:o,subUnitId:u,id:p}=r,l=s.getHyperLink(o,u,p),{redos:c,undos:f}=e.onCommandExecute({id:U.id,params:r}),_={id:k.id,params:r},I={id:M.id,params:{unitId:o,subUnitId:u,link:l}};return(await a.sequenceExecuteAsync([_,...c],n)).result?(t.pushUndoRedo({redoMutations:[_,...c],undoMutations:[I,...f],unitID:o}),!0):!1}},R={type:a.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",async handler(i,r){if(!r)return!1;const e=i.get(a.ICommandService),n=i.get(a.IUndoRedoService),t=i.get(m),{unitId:s,subUnitId:o,id:u}=r,p=t.getHyperLink(s,o,u),l={id:k.id,params:r},c={id:M.id,params:{unitId:s,subUnitId:o,link:p}};return(await a.sequenceExecuteAsync([l],e)).result?(n.pushUndoRedo({redoMutations:[l],undoMutations:[c],unitID:s}),!0):!1}},v={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(i,r){if(!r)return!1;const e=i.get(m),{unitId:n,subUnitId:t,payload:s,id:o}=r;return e.updateHyperLink(n,t,o,s)}},N={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(i,r){if(!r)return!1;const e=i.get(m),{unitId:n,subUnitId:t,id:s,row:o,column:u}=r;return e.updateHyperLinkRef(n,t,s,{row:o,column:u})}},H={type:a.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(i,r){if(!r)return!1;const e=i.get(h.SheetInterceptorService),n=i.get(a.ICommandService),t=i.get(a.IUndoRedoService),{unitId:s,subUnitId:o,link:u}=r,{redos:p,undos:l}=e.onCommandExecute({id:H.id,params:r}),c={id:M.id,params:r},f={id:k.id,params:{unitId:s,subUnitId:o,id:u.id}};return(await a.sequenceExecuteAsync([c,...p],n)).result?(t.pushUndoRedo({redoMutations:[c,...p],undoMutations:[f,...l],unitID:s}),!0):!1}};function T(i){const{row:r,column:e,id:n,...t}=i;return t}const C={type:a.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(i,r){if(!r)return!1;const e=i.get(h.SheetInterceptorService),n=i.get(a.ICommandService),t=i.get(a.IUndoRedoService),s=i.get(m),{unitId:o,subUnitId:u,id:p}=r,l=s.getHyperLink(o,u,p);if(!l)return!1;const{redos:c,undos:f}=e.onCommandExecute({id:C.id,params:r}),_={id:v.id,params:r},I={id:v.id,params:{unitId:o,subUnitId:u,id:p,payload:T(l)}};return(await a.sequenceExecuteAsync([_,...c],n)).result?(t.pushUndoRedo({redoMutations:[_,...c],undoMutations:[I,...f],unitID:o}),!0):!1}};var j=Object.defineProperty,V=Object.getOwnPropertyDescriptor,b=(i,r,e,n)=>{for(var t=n>1?void 0:n?V(r,e):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(t=(n?o(r,e,t):o(t))||t);return n&&t&&j(r,e,t),t},A=(i,r)=>(e,n)=>r(e,n,i);d.SheetsHyperLinkController=class extends a.Disposable{constructor(r){super(),this._commandService=r,this._registerCommands()}_registerCommands(){[M,v,k,N,H,C,U,R].forEach(r=>{this._commandService.registerCommand(r)})}},d.SheetsHyperLinkController=b([a.OnLifecycle(a.LifecycleStages.Starting,d.SheetsHyperLinkController),A(0,a.ICommandService)],d.SheetsHyperLinkController);var O=(i=>(i[i.range=0]="range",i[i.link=1]="link",i))(O||{});const w="SHEET_HYPER_LINK_PLUGIN";var E=(i=>(i[i.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",i[i.UNIVER_DOC=1]="UNIVER_DOC",i[i.UNIVER_SHEET=2]="UNIVER_SHEET",i[i.UNIVER_SLIDE=3]="UNIVER_SLIDE",i[i.UNRECOGNIZED=-1]="UNRECOGNIZED",i))(E||{}),$=Object.defineProperty,x=Object.getOwnPropertyDescriptor,q=(i,r,e,n)=>{for(var t=n>1?void 0:n?x(r,e):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(t=(n?o(r,e,t):o(t))||t);return n&&t&&$(r,e,t),t},P=(i,r)=>(e,n)=>r(e,n,i);let g=class extends a.Disposable{constructor(i,r){super(),this._resourceManagerService=i,this._hyperLinkModel=r,this._initSnapshot()}_initSnapshot(){const i=e=>{const n=this._hyperLinkModel.getUnit(e),t={};return n?(n.forEach(s=>{t[s.subUnitId]=s.links}),JSON.stringify(t)):""},r=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:w,businesses:[E.UNIVER_SHEET],toJson:e=>i(e),parseJson:e=>r(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(t=>{n[t].forEach(o=>{this._hyperLinkModel.addHyperLink(e,t,o)})})}}))}};g=q([a.OnLifecycle(a.LifecycleStages.Starting,g),P(0,a.IResourceManagerService),P(1,L.Inject(m))],g);var J=Object.defineProperty,G=Object.getOwnPropertyDescriptor,K=(i,r,e,n)=>{for(var t=n>1?void 0:n?G(r,e):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(t=(n?o(r,e,t):o(t))||t);return n&&t&&J(r,e,t),t},W=(i,r)=>(e,n)=>r(e,n,i);d.UniverSheetsHyperLinkPlugin=(S=class extends a.Plugin{constructor(r,e){super(),this._injector=e}onStarting(r){[[g],[d.SheetsHyperLinkController],[m]].forEach(e=>{r.add(e)})}},y(S,"pluginName",w),y(S,"type",a.UniverInstanceType.UNIVER_SHEET),S),d.UniverSheetsHyperLinkPlugin=K([W(1,L.Inject(L.Injector))],d.UniverSheetsHyperLinkPlugin),d.AddHyperLinkCommand=H,d.AddHyperLinkMutation=M,d.CancelHyperLinkCommand=R,d.HyperLinkModel=m,d.HyperLinkType=O,d.RemoveHyperLinkCommand=U,d.RemoveHyperLinkMutation=k,d.UpdateHyperLinkCommand=C,d.UpdateHyperLinkMutation=v,d.UpdateHyperLinkRefMutation=N,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(c,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("@univerjs/core"),require("@univerjs/sheets"),require("rxjs"),require("@wendellhu/redi"),require("@univerjs/sheets-hyper-link"),require("@univerjs/engine-formula")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/sheets","rxjs","@wendellhu/redi","@univerjs/sheets-hyper-link","@univerjs/engine-formula"],d):(c=typeof globalThis<"u"?globalThis:c||self,d(c.UniverSheetsHyperLink={},c.UniverCore,c.UniverSheets,c.rxjs,c["@wendellhu/redi"],c.UniverSheetsHyperLink,c.UniverEngineFormula))})(this,function(c,d,_,A,v,M,S){"use strict";var se=Object.defineProperty;var ae=(c,d,_)=>d in c?se(c,d,{enumerable:!0,configurable:!0,writable:!0,value:_}):c[d]=_;var y=(c,d,_)=>(ae(c,typeof d!="symbol"?d+"":d,_),_);var U;var V=Object.defineProperty,W=Object.getOwnPropertyDescriptor,q=(a,s,e,n)=>{for(var t=n>1?void 0:n?W(s,e):s,i=a.length-1,r;i>=0;i--)(r=a[i])&&(t=(n?r(s,e,t):r(t))||t);return n&&t&&V(s,e,t),t},G=(a,s)=>(e,n)=>s(e,n,a);c.HyperLinkModel=class extends d.Disposable{constructor(e){super();y(this,"_linkUpdate$",new A.Subject);y(this,"linkUpdate$",this._linkUpdate$.asObservable());y(this,"_linkMap",new Map);y(this,"_linkPositionMap",new Map);this._univerInstanceService=e,this.disposeWithMe({dispose:()=>{this._linkUpdate$.complete()}})}_ensureMap(e,n){let t=this._linkMap.get(e);t||(t=new Map,this._linkMap.set(e,t));let i=t.get(n);i||(i=new d.ObjectMatrix,t.set(n,i));let r=this._linkPositionMap.get(e);r||(r=new Map,this._linkPositionMap.set(e,r));let o=r.get(n);return o||(o=new Map,r.set(n,o)),{matrix:i,positionMap:o}}addHyperLink(e,n,t){const{matrix:i,positionMap:r}=this._ensureMap(e,n);return i.setValue(t.row,t.column,t),r.set(t.id,{row:t.row,column:t.column,link:t}),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:t,type:"add"}),!0}updateHyperLink(e,n,t,i,r=!1){const{matrix:o,positionMap:u}=this._ensureMap(e,n),l=u.get(t);if(!l)return!0;const p=o.getValue(l.row,l.column);return p&&(Object.assign(p,i),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:{display:p.display,payload:p.payload},id:t,type:"update",silent:r})),!0}updateHyperLinkRef(e,n,t,i,r=!1){const{matrix:o,positionMap:u}=this._ensureMap(e,n),l=u.get(t);if(!l)return!0;let p=o.getValue(l.row,l.column);return!p||p.id!==t?p=l.link:o.realDeleteValue(l.row,l.column),Object.assign(p,i),u.set(t,{...i,link:p}),o.setValue(i.row,i.column,p),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:i,id:t,type:"updateRef",silent:r}),!0}removeHyperLink(e,n,t){const{matrix:i,positionMap:r}=this._ensureMap(e,n),o=r.get(t);if(!o)return!1;r.delete(t);const u=i.getValue(o.row,o.column);return u&&u.id===t&&i.realDeleteValue(o.row,o.column),this._linkUpdate$.next({unitId:e,subUnitId:n,payload:o.link,type:"remove"}),!0}getHyperLink(e,n,t){const{matrix:i,positionMap:r}=this._ensureMap(e,n),o=r.get(t);if(o)return i.getValue(o.row,o.column)}getHyperLinkByLocation(e,n,t,i){const{matrix:r}=this._ensureMap(e,n);return r.getValue(t,i)}getHyperLinkByLocationSync(e,n,t,i){var h,g,f,R,m;const{matrix:r}=this._ensureMap(e,n),o=this._univerInstanceService.getUnit(e,d.UniverInstanceType.UNIVER_SHEET),u=(h=o==null?void 0:o.getSheetBySheetId(n))==null?void 0:h.getCellRaw(t,i),l=((m=(R=u==null?void 0:u.v)!=null?R:(f=(g=u==null?void 0:u.p)==null?void 0:g.body)==null?void 0:f.dataStream.slice(0,-2))!=null?m:"").toString(),p=r.getValue(t,i);if(p)return{...p,display:l}}getSubUnit(e,n){const{matrix:t}=this._ensureMap(e,n),i=[];return t.forValue((r,o,u)=>{u&&i.push(u)}),i}getUnit(e){const n=this._linkMap.get(e);return n?Array.from(n.keys()).map(t=>{const i=this.getSubUnit(e,t);return{unitId:e,subUnitId:t,links:i}}):[]}deleteUnit(e){const n=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:n})}getAll(){return Array.from(this._linkMap.keys()).map(n=>this.getUnit(n))}},c.HyperLinkModel=q([G(0,d.IUniverInstanceService)],c.HyperLinkModel);const L={type:d.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(a,s){if(!s)return!1;const e=a.get(c.HyperLinkModel),{unitId:n,subUnitId:t,link:i}=s;return e.addHyperLink(n,t,i)}},k={type:d.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(a,s){if(!s)return!1;const e=a.get(c.HyperLinkModel),{unitId:n,subUnitId:t,id:i}=s;return e.removeHyperLink(n,t,i)}},P={type:d.CommandType.COMMAND,id:"sheets.command.remove-hyper-link",async handler(a,s){if(!s)return!1;const e=a.get(_.SheetInterceptorService),n=a.get(d.ICommandService),t=a.get(d.IUndoRedoService),i=a.get(c.HyperLinkModel),{unitId:r,subUnitId:o,id:u}=s,l=i.getHyperLink(r,o,u),{redos:p,undos:h}=e.onCommandExecute({id:P.id,params:s}),g={id:k.id,params:s},f={id:L.id,params:{unitId:r,subUnitId:o,link:l}};return(await d.sequenceExecuteAsync([g,...p],n)).result?(t.pushUndoRedo({redoMutations:[g,...p],undoMutations:[f,...h],unitID:r}),!0):!1}},O={type:d.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",async handler(a,s){if(!s)return!1;const e=a.get(d.ICommandService),n=a.get(d.IUndoRedoService),t=a.get(c.HyperLinkModel),{unitId:i,subUnitId:r,id:o}=s,u=t.getHyperLink(i,r,o),l={id:k.id,params:s},p={id:L.id,params:{unitId:i,subUnitId:r,link:u}};return(await d.sequenceExecuteAsync([l],e)).result?(n.pushUndoRedo({redoMutations:[l],undoMutations:[p],unitID:i}),!0):!1}},w={type:d.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(a,s){if(!s)return!1;const e=a.get(c.HyperLinkModel),{unitId:n,subUnitId:t,payload:i,id:r}=s;return e.updateHyperLink(n,t,r,i,!1)}},D={type:d.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(a,s){if(!s)return!1;const e=a.get(c.HyperLinkModel),{unitId:n,subUnitId:t,id:i,row:r,column:o,silent:u}=s;return e.updateHyperLinkRef(n,t,i,{row:r,column:o},u)}},I={type:d.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(a,s){if(!s)return!1;const e=a.get(_.SheetInterceptorService),n=a.get(d.ICommandService),t=a.get(d.IUndoRedoService),{unitId:i,subUnitId:r,link:o}=s,{redos:u,undos:l}=e.onCommandExecute({id:I.id,params:s}),p={id:L.id,params:s},h={id:k.id,params:{unitId:i,subUnitId:r,id:o.id}};return(await d.sequenceExecuteAsync([p,...u],n)).result?(t.pushUndoRedo({redoMutations:[p,...u],undoMutations:[h,...l],unitID:i}),!0):!1}};function J(a){const{row:s,column:e,id:n,...t}=a;return t}const E={type:d.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(a,s){if(!s)return!1;const e=a.get(_.SheetInterceptorService),n=a.get(d.ICommandService),t=a.get(d.IUndoRedoService),i=a.get(c.HyperLinkModel),{unitId:r,subUnitId:o,id:u}=s,l=i.getHyperLink(r,o,u);if(!l)return!1;const{redos:p,undos:h}=e.onCommandExecute({id:E.id,params:s}),g={id:w.id,params:s},f={id:w.id,params:{unitId:r,subUnitId:o,id:u,payload:J(l)}};return(await d.sequenceExecuteAsync([g,...p],n)).result?(t.pushUndoRedo({redoMutations:[g,...p],undoMutations:[f,...h],unitID:r}),!0):!1}};var z=Object.defineProperty,K=Object.getOwnPropertyDescriptor,B=(a,s,e,n)=>{for(var t=n>1?void 0:n?K(s,e):s,i=a.length-1,r;i>=0;i--)(r=a[i])&&(t=(n?r(s,e,t):r(t))||t);return n&&t&&z(s,e,t),t},Y=(a,s)=>(e,n)=>s(e,n,a);c.SheetsHyperLinkController=class extends d.Disposable{constructor(s){super(),this._commandService=s,this._registerCommands()}_registerCommands(){[L,w,k,D,I,E,P,O].forEach(s=>{this._commandService.registerCommand(s)})}},c.SheetsHyperLinkController=B([d.OnLifecycle(d.LifecycleStages.Starting,c.SheetsHyperLinkController),Y(0,d.ICommandService)],c.SheetsHyperLinkController);var b=(a=>(a[a.range=0]="range",a[a.link=1]="link",a))(b||{});const N="SHEET_HYPER_LINK_PLUGIN",j="err";var $=(a=>(a[a.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",a[a.UNIVER_DOC=1]="UNIVER_DOC",a[a.UNIVER_SHEET=2]="UNIVER_SHEET",a[a.UNIVER_SLIDE=3]="UNIVER_SLIDE",a[a.UNRECOGNIZED=-1]="UNRECOGNIZED",a))($||{}),Z=Object.defineProperty,Q=Object.getOwnPropertyDescriptor,X=(a,s,e,n)=>{for(var t=n>1?void 0:n?Q(s,e):s,i=a.length-1,r;i>=0;i--)(r=a[i])&&(t=(n?r(s,e,t):r(t))||t);return n&&t&&Z(s,e,t),t},T=(a,s)=>(e,n)=>s(e,n,a);let C=class extends d.Disposable{constructor(a,s){super(),this._resourceManagerService=a,this._hyperLinkModel=s,this._initSnapshot()}_initSnapshot(){const a=e=>{const n=this._hyperLinkModel.getUnit(e),t={};return n?(n.forEach(i=>{t[i.subUnitId]=i.links.map(({display:r,...o})=>o)}),JSON.stringify(t)):""},s=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:N,businesses:[$.UNIVER_SHEET],toJson:e=>a(e),parseJson:e=>s(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,n)=>{Object.keys(n).forEach(t=>{n[t].forEach(r=>{this._hyperLinkModel.addHyperLink(e,t,r)})})}}))}};C=X([d.OnLifecycle(d.LifecycleStages.Starting,C),T(0,d.IResourceManagerService),T(1,v.Inject(c.HyperLinkModel))],C);var x=Object.defineProperty,F=Object.getOwnPropertyDescriptor,ee=(a,s,e,n)=>{for(var t=n>1?void 0:n?F(s,e):s,i=a.length-1,r;i>=0;i--)(r=a[i])&&(t=(n?r(s,e,t):r(t))||t);return n&&t&&x(s,e,t),t},H=(a,s)=>(e,n)=>s(e,n,a);c.SheetsHyperLinkRefRangeController=class extends d.Disposable{constructor(e,n,t,i){super();y(this,"_disposableMap",new Map);y(this,"_watchDisposableMap",new Map);y(this,"_rangeDisableMap",new Map);y(this,"_rangeWatcherMap",new Map);y(this,"_handlePositionChange",(e,n,t,i,r)=>{const o={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row};return i?{redos:[{id:M.UpdateHyperLinkRefMutation.id,params:{unitId:e,subUnitId:n,id:t.id,row:i.startRow,column:i.startColumn,silent:r}}],undos:[{id:M.UpdateHyperLinkRefMutation.id,params:{unitId:e,subUnitId:n,id:t.id,row:o.startRow,column:o.startColumn,silent:r}}]}:{redos:[{id:M.RemoveHyperLinkMutation.id,params:{unitId:e,subUnitId:n,id:t.id}}],undos:[{id:M.AddHyperLinkMutation.id,params:{unitId:e,subUnitId:n,link:t}}]}});this._refRangeService=e,this._hyperLinkModel=n,this._selectionManagerService=t,this._commandService=i,this._initData(),this._initRefRange()}_registerPosition(e,n,t){const i=t.id,r={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row},o=u=>{const l=_.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(r,u,{selectionManagerService:this._selectionManagerService});return l&&l.startColumn===r.startColumn&&l.startRow===r.startRow?{undos:[],redos:[]}:this._handlePositionChange(e,n,t,l,!1)};this._disposableMap.set(i,this._refRangeService.registerRefRange(r,o,e,n))}_watchPosition(e,n,t){const i=t.id,r={startColumn:t.column,endColumn:t.column,startRow:t.row,endRow:t.row};this._watchDisposableMap.set(i,this._refRangeService.watchRange(e,n,r,(o,u)=>{const{redos:l}=this._handlePositionChange(e,n,t,u,!0);d.sequenceExecuteAsync(l,this._commandService,{onlyLocal:!0})},!0))}_unregisterPosition(e){const n=this._disposableMap.get(e);n==null||n.dispose(),this._disposableMap.delete(e)}_unwatchPosition(e){const n=this._watchDisposableMap.get(e);n==null||n.dispose(),this._watchDisposableMap.delete(e)}_registerRange(e,n,t,i=!1){var r,o,u;if(t.startsWith("#")){const l=new URLSearchParams(t.slice(1)),p={gid:(r=l.get("gid"))!=null?r:"",range:(o=l.get("range"))!=null?o:"",rangeid:(u=l.get("rangeid"))!=null?u:""};if(p.range&&p.gid){const h=p.gid,g=S.deserializeRangeWithSheet(p.range).range;if(d.isValidRange(g)&&p.range!==j){const f=R=>{const m=_.handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(g,R,{selectionManagerService:this._selectionManagerService});return m&&S.serializeRange(m)===S.serializeRange(g)?{redos:[],undos:[]}:{redos:[{id:M.UpdateHyperLinkMutation.id,params:{unitId:e,subUnitId:h,id:n,payload:{payload:`#gid=${h}&range=${m?S.serializeRange(m):"err"}`}}}],undos:[{id:M.UpdateHyperLinkMutation.id,params:{unitId:e,subUnitId:h,id:n,payload:{payload:t}}}]}};this._rangeDisableMap.set(n,this._refRangeService.registerRefRange(g,f,e,h)),i||this._rangeWatcherMap.set(n,this._refRangeService.watchRange(e,h,g,(R,m)=>{this._hyperLinkModel.updateHyperLink(e,h,n,{payload:`#gid=${h}&range=${m?S.serializeRange(m):"err"}`},!0)},!0))}}}}_unregisterRange(e){const n=this._rangeDisableMap.get(e);n==null||n.dispose(),this._rangeDisableMap.delete(e)}_unwatchRange(e){const n=this._rangeWatcherMap.get(e);n==null||n.dispose(),this._rangeWatcherMap.delete(e)}_initData(){this._hyperLinkModel.getAll().forEach(n=>{n.forEach(t=>{const{unitId:i,subUnitId:r,links:o}=t;o.forEach(u=>{this._registerPosition(i,r,u),this._watchPosition(i,r,u),this._registerRange(i,u.id,u.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":{const{unitId:n,subUnitId:t,id:i,silent:r}=e,o=this._hyperLinkModel.getHyperLink(n,t,i);if(!o)return;this._unregisterPosition(i),this._registerPosition(n,t,o),r||(this._unwatchPosition(i),this._watchPosition(n,t,o));break}case"unload":{const{unitLinks:n}=e;n.forEach(t=>{const{links:i}=t;i.forEach(r=>{this._unregisterPosition(r.id),this._unwatchPosition(r.id),this._unregisterRange(r.id),this._unwatchRange(r.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(d.toDisposable(()=>{this._disposableMap.forEach(e=>{e.dispose()}),this._disposableMap.clear()}))}},c.SheetsHyperLinkRefRangeController=ee([d.OnLifecycle(d.LifecycleStages.Starting,c.SheetsHyperLinkRefRangeController),H(0,v.Inject(_.RefRangeService)),H(1,v.Inject(M.HyperLinkModel)),H(2,v.Inject(_.SelectionManagerService)),H(3,d.ICommandService)],c.SheetsHyperLinkRefRangeController);var te=Object.defineProperty,ne=Object.getOwnPropertyDescriptor,ie=(a,s,e,n)=>{for(var t=n>1?void 0:n?ne(s,e):s,i=a.length-1,r;i>=0;i--)(r=a[i])&&(t=(n?r(s,e,t):r(t))||t);return n&&t&&te(s,e,t),t},re=(a,s)=>(e,n)=>s(e,n,a);c.UniverSheetsHyperLinkPlugin=(U=class extends d.Plugin{constructor(s,e){super(),this._injector=e}onStarting(s){[[C],[c.SheetsHyperLinkController],[c.SheetsHyperLinkRefRangeController],[c.HyperLinkModel]].forEach(e=>{s.add(e)})}},y(U,"pluginName",N),y(U,"type",d.UniverInstanceType.UNIVER_SHEET),U),c.UniverSheetsHyperLinkPlugin=ie([re(1,v.Inject(v.Injector))],c.UniverSheetsHyperLinkPlugin),c.AddHyperLinkCommand=I,c.AddHyperLinkMutation=L,c.CancelHyperLinkCommand=O,c.ERROR_RANGE=j,c.HyperLinkType=b,c.RemoveHyperLinkCommand=P,c.RemoveHyperLinkMutation=k,c.UpdateHyperLinkCommand=E,c.UpdateHyperLinkMutation=w,c.UpdateHyperLinkRefMutation=D,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-hyper-link",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -44,28 +44,44 @@
|
|
|
44
44
|
"lib"
|
|
45
45
|
],
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@wendellhu/redi": "0.15.
|
|
47
|
+
"@wendellhu/redi": "0.15.4",
|
|
48
48
|
"rxjs": ">=7.0.0",
|
|
49
|
-
"@univerjs/core": "0.1.
|
|
50
|
-
"@univerjs/sheets": "0.1.
|
|
49
|
+
"@univerjs/core": "0.1.15",
|
|
50
|
+
"@univerjs/sheets": "0.1.15",
|
|
51
|
+
"@univerjs/engine-formula": "0.1.15",
|
|
52
|
+
"@univerjs/sheets-hyper-link": "0.1.15"
|
|
51
53
|
},
|
|
52
|
-
"dependencies": {},
|
|
53
54
|
"devDependencies": {
|
|
54
|
-
"@univerjs/protocol": "
|
|
55
|
-
"@wendellhu/redi": "^0.15.
|
|
55
|
+
"@univerjs/protocol": "0.1.38-alpha.3",
|
|
56
|
+
"@wendellhu/redi": "^0.15.4",
|
|
56
57
|
"rxjs": "^7.8.1",
|
|
57
58
|
"typescript": "^5.4.5",
|
|
58
|
-
"vite": "^5.2.
|
|
59
|
+
"vite": "^5.2.13",
|
|
59
60
|
"vitest": "^1.6.0",
|
|
60
|
-
"@univerjs/
|
|
61
|
-
"@univerjs/
|
|
62
|
-
"@univerjs/
|
|
61
|
+
"@univerjs/core": "0.1.15",
|
|
62
|
+
"@univerjs/shared": "0.1.15",
|
|
63
|
+
"@univerjs/engine-formula": "0.1.15",
|
|
64
|
+
"@univerjs/sheets": "0.1.15"
|
|
65
|
+
},
|
|
66
|
+
"univerSpace": {
|
|
67
|
+
".": {
|
|
68
|
+
"import": "./lib/es/index.js",
|
|
69
|
+
"require": "./lib/cjs/index.js",
|
|
70
|
+
"types": "./lib/types/index.d.ts"
|
|
71
|
+
},
|
|
72
|
+
"./*": {
|
|
73
|
+
"import": "./lib/es/*",
|
|
74
|
+
"require": "./lib/cjs/*",
|
|
75
|
+
"types": "./lib/types/index.d.ts"
|
|
76
|
+
},
|
|
77
|
+
"./lib/*": "./lib/*"
|
|
63
78
|
},
|
|
64
79
|
"scripts": {
|
|
65
80
|
"test": "vitest run",
|
|
66
81
|
"test:watch": "vitest",
|
|
67
82
|
"coverage": "vitest run --coverage",
|
|
68
83
|
"lint:types": "tsc --noEmit",
|
|
69
|
-
"build": "tsc && vite build"
|
|
84
|
+
"build": "tsc && vite build",
|
|
85
|
+
"sync:cnpm": "cnpm sync"
|
|
70
86
|
}
|
|
71
87
|
}
|