@univerjs/sheets-hyper-link 0.1.13-nightly.202406041140
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/README.md +19 -0
- package/lib/cjs/index.js +1 -0
- package/lib/es/index.js +384 -0
- package/lib/types/commands/commands/add-hyper-link.command.d.ts +9 -0
- package/lib/types/commands/commands/remove-hyper-link.command.d.ts +9 -0
- package/lib/types/commands/commands/update-hyper-link.command.d.ts +10 -0
- package/lib/types/commands/mutations/add-hyper-link.mutation.d.ts +9 -0
- package/lib/types/commands/mutations/remove-hyper-link.mutation.d.ts +8 -0
- package/lib/types/commands/mutations/update-hyper-link.mutation.d.ts +18 -0
- package/lib/types/controllers/sheet-hyper-link-resource.controller.d.ts +9 -0
- package/lib/types/controllers/sheet-hyper-link.controller.d.ts +7 -0
- package/lib/types/index.d.ts +27 -0
- package/lib/types/models/hyper-link.model.d.ts +67 -0
- package/lib/types/plugin.d.ts +10 -0
- package/lib/types/types/const.d.ts +16 -0
- package/lib/types/types/enums/hyper-link-type.d.ts +19 -0
- package/lib/types/types/interfaces/i-hyper-link.d.ts +31 -0
- package/lib/umd/index.js +1 -0
- package/package.json +70 -0
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @univerjs/sheets-hyper-link
|
|
2
|
+
|
|
3
|
+
[](https://npmjs.org/packages/@univerjs/hyper-link)
|
|
4
|
+
[](https://img.shields.io/npm/l/@univerjs/hyper-link)
|
|
5
|
+
|
|
6
|
+
## Introduction
|
|
7
|
+
|
|
8
|
+
A internal package for `@univerjs/sheets-hyper-link-ui`, for using hyper-link feature please refer to [`@univerjs/sheets-hyper-link-ui`](../sheets-hyper-link-ui//README.md).
|
|
9
|
+
|
|
10
|
+
为 `@univerjs/sheets-hyper-link-ui` 准备的内部包, 如需使用链接功能请查看
|
|
11
|
+
[`@univerjs/sheets-hyper-link-ui`](../sheets-hyper-link-ui//README-zh.md)。
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### Installation
|
|
16
|
+
|
|
17
|
+
```shell
|
|
18
|
+
npm i @univerjs/sheets-hyper-link
|
|
19
|
+
```
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var T=Object.defineProperty;var V=(n,r,e)=>r in n?T(n,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[r]=e;var m=(n,r,e)=>(V(n,typeof r!="symbol"?r+"":r,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@univerjs/core"),U=require("@univerjs/sheets"),A=require("rxjs"),L=require("@wendellhu/redi");class p extends d.Disposable{constructor(){super();m(this,"_linkUpdate$",new A.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,i){let t=this._linkMap.get(e);t||(t=new Map,this._linkMap.set(e,t));let o=t.get(i);o||(o=new d.ObjectMatrix,t.set(i,o));let s=this._linkPositionMap.get(e);s||(s=new Map,this._linkPositionMap.set(e,s));let a=s.get(i);return a||(a=new Map,s.set(i,a)),{matrix:o,positionMap:a}}addHyperLink(e,i,t){const{matrix:o,positionMap:s}=this._ensureMap(e,i);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:i,payload:t,type:"add"}),!0}updateHyperLink(e,i,t,o,s){const{matrix:a,positionMap:c}=this._ensureMap(e,i),u=c.get(t);if(!u)return!1;const l=a.getValue(u.row,u.column);return l?(Object.assign(l,o),s||this._linkUpdate$.next({unitId:e,subUnitId:i,payload:{display:l.display,payload:l.payload},id:t,type:"update"}),!0):!1}updateHyperLinkRef(e,i,t,o){const{matrix:s,positionMap:a}=this._ensureMap(e,i),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:i,payload:o,id:t,type:"updateRef"}),!0}removeHyperLink(e,i,t){const{matrix:o,positionMap:s}=this._ensureMap(e,i),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:i,payload:c,type:"remove"}),!0}getHyperLink(e,i,t){const{matrix:o,positionMap:s}=this._ensureMap(e,i),a=s.get(t);if(a)return o.getValue(a.row,a.column)}getHyperLinkByLocation(e,i,t,o){const{matrix:s}=this._ensureMap(e,i);return s.getValue(t,o)}getSubUnit(e,i){const{matrix:t}=this._ensureMap(e,i),o=[];return t.forValue((s,a,c)=>{c&&o.push(c)}),o}getUnit(e){const i=this._linkMap.get(e);return i?Array.from(i.keys()).map(t=>{const o=this.getSubUnit(e,t);return{unitId:e,subUnitId:t,links:o}}):[]}deleteUnit(e){const i=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:i})}getAll(){return Array.from(this._linkMap.keys()).map(i=>this.getUnit(i))}}const k={type:d.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(n,r){if(!r)return!1;const e=n.get(p),{unitId:i,subUnitId:t,link:o}=r;return e.addHyperLink(i,t,o)}},g={type:d.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(n,r){if(!r)return!1;const e=n.get(p),{unitId:i,subUnitId:t,id:o}=r;return e.removeHyperLink(i,t,o)}},v={type:d.CommandType.COMMAND,id:"sheets.command.remove-hyper-link",async handler(n,r){if(!r)return!1;const e=n.get(U.SheetInterceptorService),i=n.get(d.ICommandService),t=n.get(d.IUndoRedoService),o=n.get(p),{unitId:s,subUnitId:a,id:c}=r,u=o.getHyperLink(s,a,c),{redos:l,undos:y}=e.onCommandExecute({id:v.id,params:r}),h={id:g.id,params:r},S={id:k.id,params:{unitId:s,subUnitId:a,link:u}};return(await d.sequenceExecuteAsync([h,...l],i)).result?(t.pushUndoRedo({redoMutations:[h,...l],undoMutations:[S,...y],unitID:s}),!0):!1}},R={type:d.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",async handler(n,r){if(!r)return!1;const e=n.get(d.ICommandService),i=n.get(d.IUndoRedoService),t=n.get(p),{unitId:o,subUnitId:s,id:a}=r,c=t.getHyperLink(o,s,a),u={id:g.id,params:r},l={id:k.id,params:{unitId:o,subUnitId:s,link:c}};return(await d.sequenceExecuteAsync([u],e)).result?(i.pushUndoRedo({redoMutations:[u],undoMutations:[l],unitID:o}),!0):!1}},_={type:d.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(n,r){if(!r)return!1;const e=n.get(p),{unitId:i,subUnitId:t,payload:o,id:s}=r;return e.updateHyperLink(i,t,s,o)}},N={type:d.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(n,r){if(!r)return!1;const e=n.get(p),{unitId:i,subUnitId:t,id:o,row:s,column:a}=r;return e.updateHyperLinkRef(i,t,o,{row:s,column:a})}},H={type:d.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(n,r){if(!r)return!1;const e=n.get(U.SheetInterceptorService),i=n.get(d.ICommandService),t=n.get(d.IUndoRedoService),{unitId:o,subUnitId:s,link:a}=r,{redos:c,undos:u}=e.onCommandExecute({id:H.id,params:r}),l={id:k.id,params:r},y={id:g.id,params:{unitId:o,subUnitId:s,id:a.id}};return(await d.sequenceExecuteAsync([l,...c],i)).result?(t.pushUndoRedo({redoMutations:[l,...c],undoMutations:[y,...u],unitID:o}),!0):!1}};function D(n){const{row:r,column:e,id:i,...t}=n;return t}const C={type:d.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(n,r){if(!r)return!1;const e=n.get(U.SheetInterceptorService),i=n.get(d.ICommandService),t=n.get(d.IUndoRedoService),o=n.get(p),{unitId:s,subUnitId:a,id:c}=r,u=o.getHyperLink(s,a,c);if(!u)return!1;const{redos:l,undos:y}=e.onCommandExecute({id:C.id,params:r}),h={id:_.id,params:r},S={id:_.id,params:{unitId:s,subUnitId:a,id:c,payload:D(u)}};return(await d.sequenceExecuteAsync([h,...l],i)).result?(t.pushUndoRedo({redoMutations:[h,...l],undoMutations:[S,...y],unitID:s}),!0):!1}};var P=(n,r,e,i)=>{for(var t=r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(t=s(t)||t);return t},b=(n,r)=>(e,i)=>r(e,i,n);exports.SheetsHyperLinkController=class extends d.Disposable{constructor(r){super(),this._commandService=r,this._registerCommands()}_registerCommands(){[k,_,g,N,H,C,v,R].forEach(r=>{this._commandService.registerCommand(r)})}};exports.SheetsHyperLinkController=P([d.OnLifecycle(d.LifecycleStages.Starting,exports.SheetsHyperLinkController),b(0,d.ICommandService)],exports.SheetsHyperLinkController);var E=(n=>(n[n.range=0]="range",n[n.link=1]="link",n))(E||{});const x="SHEET_HYPER_LINK_PLUGIN";var w=(n=>(n[n.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",n[n.UNIVER_DOC=1]="UNIVER_DOC",n[n.UNIVER_SHEET=2]="UNIVER_SHEET",n[n.UNIVER_SLIDE=3]="UNIVER_SLIDE",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(w||{}),$=(n,r,e,i)=>{for(var t=r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(t=s(t)||t);return t},I=(n,r)=>(e,i)=>r(e,i,n);let f=class extends d.Disposable{constructor(n,r){super(),this._resourceManagerService=n,this._hyperLinkModel=r,this._initSnapshot()}_initSnapshot(){const n=e=>{const i=this._hyperLinkModel.getUnit(e),t={};return i?(i.forEach(o=>{t[o.subUnitId]=o.links}),JSON.stringify(t)):""},r=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:x,businesses:[w.UNIVER_SHEET],toJson:e=>n(e),parseJson:e=>r(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,i)=>{Object.keys(i).forEach(t=>{i[t].forEach(s=>{this._hyperLinkModel.addHyperLink(e,t,s)})})}}))}};f=$([d.OnLifecycle(d.LifecycleStages.Starting,f),I(0,d.IResourceManagerService),I(1,L.Inject(p))],f);var j=(n,r,e,i)=>{for(var t=r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(t=s(t)||t);return t},q=(n,r)=>(e,i)=>r(e,i,n),M;exports.UniverSheetsHyperLinkPlugin=(M=class extends d.Plugin{constructor(r,e){super(),this._injector=e}onStarting(r){[[f],[exports.SheetsHyperLinkController],[p]].forEach(e=>{r.add(e)})}},m(M,"pluginName",x),m(M,"type",d.UniverInstanceType.UNIVER_SHEET),M);exports.UniverSheetsHyperLinkPlugin=j([q(1,L.Inject(L.Injector))],exports.UniverSheetsHyperLinkPlugin);exports.AddHyperLinkCommand=H;exports.AddHyperLinkMutation=k;exports.CancelHyperLinkCommand=R;exports.HyperLinkModel=p;exports.HyperLinkType=E;exports.RemoveHyperLinkCommand=v;exports.RemoveHyperLinkMutation=g;exports.UpdateHyperLinkCommand=C;exports.UpdateHyperLinkMutation=_;exports.UpdateHyperLinkRefMutation=N;
|
package/lib/es/index.js
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
var $ = Object.defineProperty;
|
|
2
|
+
var b = (e, o, t) => o in e ? $(e, o, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[o] = t;
|
|
3
|
+
var h = (e, o, t) => (b(e, typeof o != "symbol" ? o + "" : o, t), t);
|
|
4
|
+
import { Disposable as I, ObjectMatrix as j, CommandType as p, ICommandService as f, IUndoRedoService as _, sequenceExecuteAsync as U, OnLifecycle as C, LifecycleStages as w, IResourceManagerService as J, Plugin as G, UniverInstanceType as K } from "@univerjs/core";
|
|
5
|
+
import { SheetInterceptorService as H } from "@univerjs/sheets";
|
|
6
|
+
import { Subject as W } from "rxjs";
|
|
7
|
+
import { Inject as x, Injector as Y } from "@wendellhu/redi";
|
|
8
|
+
class l extends I {
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
h(this, "_linkUpdate$", new W());
|
|
12
|
+
h(this, "linkUpdate$", this._linkUpdate$.asObservable());
|
|
13
|
+
h(this, "_linkMap", /* @__PURE__ */ new Map());
|
|
14
|
+
h(this, "_linkPositionMap", /* @__PURE__ */ new Map());
|
|
15
|
+
this.disposeWithMe({
|
|
16
|
+
dispose: () => {
|
|
17
|
+
this._linkUpdate$.complete();
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
_ensureMap(t, i) {
|
|
22
|
+
let n = this._linkMap.get(t);
|
|
23
|
+
n || (n = /* @__PURE__ */ new Map(), this._linkMap.set(t, n));
|
|
24
|
+
let r = n.get(i);
|
|
25
|
+
r || (r = new j(), n.set(i, r));
|
|
26
|
+
let s = this._linkPositionMap.get(t);
|
|
27
|
+
s || (s = /* @__PURE__ */ new Map(), this._linkPositionMap.set(t, s));
|
|
28
|
+
let a = s.get(i);
|
|
29
|
+
return a || (a = /* @__PURE__ */ new Map(), s.set(i, a)), {
|
|
30
|
+
matrix: r,
|
|
31
|
+
positionMap: a
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
addHyperLink(t, i, n) {
|
|
35
|
+
const { matrix: r, positionMap: s } = this._ensureMap(t, i);
|
|
36
|
+
return r.setValue(n.row, n.column, n), s.set(n.id, { row: n.row, column: n.column, link: n }), this._linkUpdate$.next({
|
|
37
|
+
unitId: t,
|
|
38
|
+
subUnitId: i,
|
|
39
|
+
payload: n,
|
|
40
|
+
type: "add"
|
|
41
|
+
}), !0;
|
|
42
|
+
}
|
|
43
|
+
updateHyperLink(t, i, n, r, s) {
|
|
44
|
+
const { matrix: a, positionMap: d } = this._ensureMap(t, i), u = d.get(n);
|
|
45
|
+
if (!u)
|
|
46
|
+
return !1;
|
|
47
|
+
const c = a.getValue(u.row, u.column);
|
|
48
|
+
return c ? (Object.assign(c, r), s || this._linkUpdate$.next({
|
|
49
|
+
unitId: t,
|
|
50
|
+
subUnitId: i,
|
|
51
|
+
payload: {
|
|
52
|
+
display: c.display,
|
|
53
|
+
payload: c.payload
|
|
54
|
+
},
|
|
55
|
+
id: n,
|
|
56
|
+
type: "update"
|
|
57
|
+
}), !0) : !1;
|
|
58
|
+
}
|
|
59
|
+
updateHyperLinkRef(t, i, n, r) {
|
|
60
|
+
const { matrix: s, positionMap: a } = this._ensureMap(t, i), d = a.get(n);
|
|
61
|
+
if (!d)
|
|
62
|
+
return !1;
|
|
63
|
+
let u = s.getValue(d.row, d.column);
|
|
64
|
+
return !u || u.id !== n ? u = d.link : s.realDeleteValue(d.row, d.column), Object.assign(u, r), a.set(n, { ...r, link: u }), s.setValue(r.row, r.column, u), this._linkUpdate$.next({
|
|
65
|
+
unitId: t,
|
|
66
|
+
subUnitId: i,
|
|
67
|
+
payload: r,
|
|
68
|
+
id: n,
|
|
69
|
+
type: "updateRef"
|
|
70
|
+
}), !0;
|
|
71
|
+
}
|
|
72
|
+
removeHyperLink(t, i, n) {
|
|
73
|
+
const { matrix: r, positionMap: s } = this._ensureMap(t, i), a = s.get(n);
|
|
74
|
+
if (!a)
|
|
75
|
+
return !1;
|
|
76
|
+
s.delete(n);
|
|
77
|
+
const d = r.getValue(a.row, a.column);
|
|
78
|
+
return d && d.id === n && r.realDeleteValue(a.row, a.column), this._linkUpdate$.next({
|
|
79
|
+
unitId: t,
|
|
80
|
+
subUnitId: i,
|
|
81
|
+
payload: d,
|
|
82
|
+
type: "remove"
|
|
83
|
+
}), !0;
|
|
84
|
+
}
|
|
85
|
+
getHyperLink(t, i, n) {
|
|
86
|
+
const { matrix: r, positionMap: s } = this._ensureMap(t, i), a = s.get(n);
|
|
87
|
+
if (a)
|
|
88
|
+
return r.getValue(a.row, a.column);
|
|
89
|
+
}
|
|
90
|
+
getHyperLinkByLocation(t, i, n, r) {
|
|
91
|
+
const { matrix: s } = this._ensureMap(t, i);
|
|
92
|
+
return s.getValue(n, r);
|
|
93
|
+
}
|
|
94
|
+
getSubUnit(t, i) {
|
|
95
|
+
const { matrix: n } = this._ensureMap(t, i), r = [];
|
|
96
|
+
return n.forValue((s, a, d) => {
|
|
97
|
+
d && r.push(d);
|
|
98
|
+
}), r;
|
|
99
|
+
}
|
|
100
|
+
getUnit(t) {
|
|
101
|
+
const i = this._linkMap.get(t);
|
|
102
|
+
return i ? Array.from(i.keys()).map((n) => {
|
|
103
|
+
const r = this.getSubUnit(t, n);
|
|
104
|
+
return {
|
|
105
|
+
unitId: t,
|
|
106
|
+
subUnitId: n,
|
|
107
|
+
links: r
|
|
108
|
+
};
|
|
109
|
+
}) : [];
|
|
110
|
+
}
|
|
111
|
+
deleteUnit(t) {
|
|
112
|
+
const i = this.getUnit(t);
|
|
113
|
+
this._linkMap.delete(t), this._linkPositionMap.delete(t), this._linkUpdate$.next({
|
|
114
|
+
type: "unload",
|
|
115
|
+
unitId: t,
|
|
116
|
+
unitLinks: i
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
getAll() {
|
|
120
|
+
return Array.from(this._linkMap.keys()).map((i) => this.getUnit(i));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const S = {
|
|
124
|
+
type: p.MUTATION,
|
|
125
|
+
id: "sheets.mutation.add-hyper-link",
|
|
126
|
+
handler(e, o) {
|
|
127
|
+
if (!o)
|
|
128
|
+
return !1;
|
|
129
|
+
const t = e.get(l), { unitId: i, subUnitId: n, link: r } = o;
|
|
130
|
+
return t.addHyperLink(i, n, r);
|
|
131
|
+
}
|
|
132
|
+
}, v = {
|
|
133
|
+
type: p.MUTATION,
|
|
134
|
+
id: "sheets.mutation.remove-hyper-link",
|
|
135
|
+
handler(e, o) {
|
|
136
|
+
if (!o)
|
|
137
|
+
return !1;
|
|
138
|
+
const t = e.get(l), { unitId: i, subUnitId: n, id: r } = o;
|
|
139
|
+
return t.removeHyperLink(i, n, r);
|
|
140
|
+
}
|
|
141
|
+
}, O = {
|
|
142
|
+
type: p.COMMAND,
|
|
143
|
+
id: "sheets.command.remove-hyper-link",
|
|
144
|
+
async handler(e, o) {
|
|
145
|
+
if (!o)
|
|
146
|
+
return !1;
|
|
147
|
+
const t = e.get(H), i = e.get(f), n = e.get(_), r = e.get(l), { unitId: s, subUnitId: a, id: d } = o, u = r.getHyperLink(s, a, d), { redos: c, undos: m } = t.onCommandExecute({
|
|
148
|
+
id: O.id,
|
|
149
|
+
params: o
|
|
150
|
+
}), k = {
|
|
151
|
+
id: v.id,
|
|
152
|
+
params: o
|
|
153
|
+
}, L = {
|
|
154
|
+
id: S.id,
|
|
155
|
+
params: {
|
|
156
|
+
unitId: s,
|
|
157
|
+
subUnitId: a,
|
|
158
|
+
link: u
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
return (await U([k, ...c], i)).result ? (n.pushUndoRedo({
|
|
162
|
+
redoMutations: [k, ...c],
|
|
163
|
+
undoMutations: [L, ...m],
|
|
164
|
+
unitID: s
|
|
165
|
+
}), !0) : !1;
|
|
166
|
+
}
|
|
167
|
+
}, Z = {
|
|
168
|
+
type: p.COMMAND,
|
|
169
|
+
id: "sheets.command.cancel-hyper-link",
|
|
170
|
+
async handler(e, o) {
|
|
171
|
+
if (!o)
|
|
172
|
+
return !1;
|
|
173
|
+
const t = e.get(f), i = e.get(_), n = e.get(l), { unitId: r, subUnitId: s, id: a } = o, d = n.getHyperLink(r, s, a), u = {
|
|
174
|
+
id: v.id,
|
|
175
|
+
params: o
|
|
176
|
+
}, c = {
|
|
177
|
+
id: S.id,
|
|
178
|
+
params: {
|
|
179
|
+
unitId: r,
|
|
180
|
+
subUnitId: s,
|
|
181
|
+
link: d
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
return (await U([u], t)).result ? (i.pushUndoRedo({
|
|
185
|
+
redoMutations: [u],
|
|
186
|
+
undoMutations: [c],
|
|
187
|
+
unitID: r
|
|
188
|
+
}), !0) : !1;
|
|
189
|
+
}
|
|
190
|
+
}, N = {
|
|
191
|
+
type: p.MUTATION,
|
|
192
|
+
id: "sheets.mutation.update-hyper-link",
|
|
193
|
+
handler(e, o) {
|
|
194
|
+
if (!o)
|
|
195
|
+
return !1;
|
|
196
|
+
const t = e.get(l), { unitId: i, subUnitId: n, payload: r, id: s } = o;
|
|
197
|
+
return t.updateHyperLink(i, n, s, r);
|
|
198
|
+
}
|
|
199
|
+
}, q = {
|
|
200
|
+
type: p.MUTATION,
|
|
201
|
+
id: "sheets.mutation.update-hyper-link-ref",
|
|
202
|
+
handler(e, o) {
|
|
203
|
+
if (!o)
|
|
204
|
+
return !1;
|
|
205
|
+
const t = e.get(l), { unitId: i, subUnitId: n, id: r, row: s, column: a } = o;
|
|
206
|
+
return t.updateHyperLinkRef(i, n, r, { row: s, column: a });
|
|
207
|
+
}
|
|
208
|
+
}, V = {
|
|
209
|
+
type: p.COMMAND,
|
|
210
|
+
id: "sheets.command.add-hyper-link",
|
|
211
|
+
async handler(e, o) {
|
|
212
|
+
if (!o)
|
|
213
|
+
return !1;
|
|
214
|
+
const t = e.get(H), i = e.get(f), n = e.get(_), { unitId: r, subUnitId: s, link: a } = o, { redos: d, undos: u } = t.onCommandExecute({
|
|
215
|
+
id: V.id,
|
|
216
|
+
params: o
|
|
217
|
+
}), c = {
|
|
218
|
+
id: S.id,
|
|
219
|
+
params: o
|
|
220
|
+
}, m = {
|
|
221
|
+
id: v.id,
|
|
222
|
+
params: {
|
|
223
|
+
unitId: r,
|
|
224
|
+
subUnitId: s,
|
|
225
|
+
id: a.id
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
return (await U([c, ...d], i)).result ? (n.pushUndoRedo({
|
|
229
|
+
redoMutations: [c, ...d],
|
|
230
|
+
undoMutations: [m, ...u],
|
|
231
|
+
unitID: r
|
|
232
|
+
}), !0) : !1;
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
function B(e) {
|
|
236
|
+
const { row: o, column: t, id: i, ...n } = e;
|
|
237
|
+
return n;
|
|
238
|
+
}
|
|
239
|
+
const D = {
|
|
240
|
+
type: p.COMMAND,
|
|
241
|
+
id: "sheets.command.update-hyper-link",
|
|
242
|
+
async handler(e, o) {
|
|
243
|
+
if (!o)
|
|
244
|
+
return !1;
|
|
245
|
+
const t = e.get(H), i = e.get(f), n = e.get(_), r = e.get(l), { unitId: s, subUnitId: a, id: d } = o, u = r.getHyperLink(s, a, d);
|
|
246
|
+
if (!u)
|
|
247
|
+
return !1;
|
|
248
|
+
const { redos: c, undos: m } = t.onCommandExecute({
|
|
249
|
+
id: D.id,
|
|
250
|
+
params: o
|
|
251
|
+
}), k = {
|
|
252
|
+
id: N.id,
|
|
253
|
+
params: o
|
|
254
|
+
}, L = {
|
|
255
|
+
id: N.id,
|
|
256
|
+
params: {
|
|
257
|
+
unitId: s,
|
|
258
|
+
subUnitId: a,
|
|
259
|
+
id: d,
|
|
260
|
+
payload: B(u)
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
return (await U([k, ...c], i)).result ? (n.pushUndoRedo({
|
|
264
|
+
redoMutations: [k, ...c],
|
|
265
|
+
undoMutations: [L, ...m],
|
|
266
|
+
unitID: s
|
|
267
|
+
}), !0) : !1;
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
var z = (e, o, t, i) => {
|
|
271
|
+
for (var n = o, r = e.length - 1, s; r >= 0; r--)
|
|
272
|
+
(s = e[r]) && (n = s(n) || n);
|
|
273
|
+
return n;
|
|
274
|
+
}, F = (e, o) => (t, i) => o(t, i, e);
|
|
275
|
+
let g = class extends I {
|
|
276
|
+
constructor(e) {
|
|
277
|
+
super(), this._commandService = e, this._registerCommands();
|
|
278
|
+
}
|
|
279
|
+
_registerCommands() {
|
|
280
|
+
[
|
|
281
|
+
S,
|
|
282
|
+
N,
|
|
283
|
+
v,
|
|
284
|
+
q,
|
|
285
|
+
V,
|
|
286
|
+
D,
|
|
287
|
+
O,
|
|
288
|
+
Z
|
|
289
|
+
].forEach((e) => {
|
|
290
|
+
this._commandService.registerCommand(e);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
g = z([
|
|
295
|
+
C(w.Starting, g),
|
|
296
|
+
F(0, f)
|
|
297
|
+
], g);
|
|
298
|
+
var Q = /* @__PURE__ */ ((e) => (e[e.range = 0] = "range", e[e.link = 1] = "link", e))(Q || {});
|
|
299
|
+
const A = "SHEET_HYPER_LINK_PLUGIN";
|
|
300
|
+
var P = /* @__PURE__ */ ((e) => (e[e.UNIVER_UNKNOWN = 0] = "UNIVER_UNKNOWN", e[e.UNIVER_DOC = 1] = "UNIVER_DOC", e[e.UNIVER_SHEET = 2] = "UNIVER_SHEET", e[e.UNIVER_SLIDE = 3] = "UNIVER_SLIDE", e[e.UNRECOGNIZED = -1] = "UNRECOGNIZED", e))(P || {}), X = (e, o, t, i) => {
|
|
301
|
+
for (var n = o, r = e.length - 1, s; r >= 0; r--)
|
|
302
|
+
(s = e[r]) && (n = s(n) || n);
|
|
303
|
+
return n;
|
|
304
|
+
}, R = (e, o) => (t, i) => o(t, i, e);
|
|
305
|
+
let M = class extends I {
|
|
306
|
+
constructor(e, o) {
|
|
307
|
+
super(), this._resourceManagerService = e, this._hyperLinkModel = o, this._initSnapshot();
|
|
308
|
+
}
|
|
309
|
+
_initSnapshot() {
|
|
310
|
+
const e = (t) => {
|
|
311
|
+
const i = this._hyperLinkModel.getUnit(t), n = {};
|
|
312
|
+
return i ? (i.forEach((r) => {
|
|
313
|
+
n[r.subUnitId] = r.links;
|
|
314
|
+
}), JSON.stringify(n)) : "";
|
|
315
|
+
}, o = (t) => {
|
|
316
|
+
if (!t)
|
|
317
|
+
return {};
|
|
318
|
+
try {
|
|
319
|
+
return JSON.parse(t);
|
|
320
|
+
} catch {
|
|
321
|
+
return {};
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
this.disposeWithMe(
|
|
325
|
+
this._resourceManagerService.registerPluginResource({
|
|
326
|
+
pluginName: A,
|
|
327
|
+
businesses: [P.UNIVER_SHEET],
|
|
328
|
+
toJson: (t) => e(t),
|
|
329
|
+
parseJson: (t) => o(t),
|
|
330
|
+
onUnLoad: (t) => {
|
|
331
|
+
this._hyperLinkModel.deleteUnit(t);
|
|
332
|
+
},
|
|
333
|
+
onLoad: async (t, i) => {
|
|
334
|
+
Object.keys(i).forEach((n) => {
|
|
335
|
+
i[n].forEach((s) => {
|
|
336
|
+
this._hyperLinkModel.addHyperLink(t, n, s);
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
})
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
M = X([
|
|
345
|
+
C(w.Starting, M),
|
|
346
|
+
R(0, J),
|
|
347
|
+
R(1, x(l))
|
|
348
|
+
], M);
|
|
349
|
+
var ee = (e, o, t, i) => {
|
|
350
|
+
for (var n = o, r = e.length - 1, s; r >= 0; r--)
|
|
351
|
+
(s = e[r]) && (n = s(n) || n);
|
|
352
|
+
return n;
|
|
353
|
+
}, te = (e, o) => (t, i) => o(t, i, e), y;
|
|
354
|
+
let E = (y = class extends G {
|
|
355
|
+
constructor(e, o) {
|
|
356
|
+
super(), this._injector = o;
|
|
357
|
+
}
|
|
358
|
+
onStarting(e) {
|
|
359
|
+
[
|
|
360
|
+
[M],
|
|
361
|
+
[g],
|
|
362
|
+
[l]
|
|
363
|
+
].forEach((o) => {
|
|
364
|
+
e.add(o);
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
}, h(y, "pluginName", A), h(y, "type", K.UNIVER_SHEET), y);
|
|
368
|
+
E = ee([
|
|
369
|
+
te(1, x(Y))
|
|
370
|
+
], E);
|
|
371
|
+
export {
|
|
372
|
+
V as AddHyperLinkCommand,
|
|
373
|
+
S as AddHyperLinkMutation,
|
|
374
|
+
Z as CancelHyperLinkCommand,
|
|
375
|
+
l as HyperLinkModel,
|
|
376
|
+
Q as HyperLinkType,
|
|
377
|
+
O as RemoveHyperLinkCommand,
|
|
378
|
+
v as RemoveHyperLinkMutation,
|
|
379
|
+
g as SheetsHyperLinkController,
|
|
380
|
+
E as UniverSheetsHyperLinkPlugin,
|
|
381
|
+
D as UpdateHyperLinkCommand,
|
|
382
|
+
N as UpdateHyperLinkMutation,
|
|
383
|
+
q as UpdateHyperLinkRefMutation
|
|
384
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ICommand } from '@univerjs/core';
|
|
2
|
+
import { ICellHyperLink } from '../../types/interfaces/i-hyper-link';
|
|
3
|
+
|
|
4
|
+
export interface IAddHyperLinkCommandParams {
|
|
5
|
+
unitId: string;
|
|
6
|
+
subUnitId: string;
|
|
7
|
+
link: ICellHyperLink;
|
|
8
|
+
}
|
|
9
|
+
export declare const AddHyperLinkCommand: ICommand<IAddHyperLinkCommandParams>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ICommand } from '@univerjs/core';
|
|
2
|
+
|
|
3
|
+
export interface IRemoveHyperLinkCommandParams {
|
|
4
|
+
unitId: string;
|
|
5
|
+
subUnitId: string;
|
|
6
|
+
id: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const RemoveHyperLinkCommand: ICommand<IRemoveHyperLinkCommandParams>;
|
|
9
|
+
export declare const CancelHyperLinkCommand: ICommand<IRemoveHyperLinkCommandParams>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ICommand } from '@univerjs/core';
|
|
2
|
+
import { ICellLinkContent } from '../../types/interfaces/i-hyper-link';
|
|
3
|
+
|
|
4
|
+
export interface IUpdateHyperLinkCommandParams {
|
|
5
|
+
unitId: string;
|
|
6
|
+
subUnitId: string;
|
|
7
|
+
id: string;
|
|
8
|
+
payload: ICellLinkContent;
|
|
9
|
+
}
|
|
10
|
+
export declare const UpdateHyperLinkCommand: ICommand<IUpdateHyperLinkCommandParams>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ICommand } from '@univerjs/core';
|
|
2
|
+
import { ICellHyperLink } from '../../types/interfaces/i-hyper-link';
|
|
3
|
+
|
|
4
|
+
export interface IAddHyperLinkMutationParams {
|
|
5
|
+
unitId: string;
|
|
6
|
+
subUnitId: string;
|
|
7
|
+
link: ICellHyperLink;
|
|
8
|
+
}
|
|
9
|
+
export declare const AddHyperLinkMutation: ICommand<IAddHyperLinkMutationParams>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ICommand } from '@univerjs/core';
|
|
2
|
+
import { ICellLinkContent } from '../../types/interfaces/i-hyper-link';
|
|
3
|
+
|
|
4
|
+
export interface IUpdateHyperLinkMutationParams {
|
|
5
|
+
unitId: string;
|
|
6
|
+
subUnitId: string;
|
|
7
|
+
id: string;
|
|
8
|
+
payload: ICellLinkContent;
|
|
9
|
+
}
|
|
10
|
+
export declare const UpdateHyperLinkMutation: ICommand<IUpdateHyperLinkMutationParams>;
|
|
11
|
+
export interface IUpdateHyperLinkRefMutationParams {
|
|
12
|
+
unitId: string;
|
|
13
|
+
subUnitId: string;
|
|
14
|
+
id: string;
|
|
15
|
+
row: number;
|
|
16
|
+
column: number;
|
|
17
|
+
}
|
|
18
|
+
export declare const UpdateHyperLinkRefMutation: ICommand<IUpdateHyperLinkRefMutationParams>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Disposable, IResourceManagerService } from '@univerjs/core';
|
|
2
|
+
import { HyperLinkModel } from '../models/hyper-link.model';
|
|
3
|
+
|
|
4
|
+
export declare class SheetsHyperLinkResourceController extends Disposable {
|
|
5
|
+
private readonly _resourceManagerService;
|
|
6
|
+
private readonly _hyperLinkModel;
|
|
7
|
+
constructor(_resourceManagerService: IResourceManagerService, _hyperLinkModel: HyperLinkModel);
|
|
8
|
+
private _initSnapshot;
|
|
9
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export { CancelHyperLinkCommand } from './commands/commands/remove-hyper-link.command';
|
|
17
|
+
export { AddHyperLinkMutation, type IAddHyperLinkMutationParams } from './commands/mutations/add-hyper-link.mutation';
|
|
18
|
+
export { UpdateHyperLinkMutation, UpdateHyperLinkRefMutation, type IUpdateHyperLinkMutationParams, type IUpdateHyperLinkRefMutationParams } from './commands/mutations/update-hyper-link.mutation';
|
|
19
|
+
export { RemoveHyperLinkMutation, type IRemoveHyperLinkMutationParams } from './commands/mutations/remove-hyper-link.mutation';
|
|
20
|
+
export { AddHyperLinkCommand, type IAddHyperLinkCommandParams } from './commands/commands/add-hyper-link.command';
|
|
21
|
+
export { UpdateHyperLinkCommand, type IUpdateHyperLinkCommandParams } from './commands/commands/update-hyper-link.command';
|
|
22
|
+
export { RemoveHyperLinkCommand, type IRemoveHyperLinkCommandParams } from './commands/commands/remove-hyper-link.command';
|
|
23
|
+
export { HyperLinkModel } from './models/hyper-link.model';
|
|
24
|
+
export { SheetsHyperLinkController } from './controllers/sheet-hyper-link.controller';
|
|
25
|
+
export { HyperLinkType } from './types/enums/hyper-link-type';
|
|
26
|
+
export { UniverSheetsHyperLinkPlugin } from './plugin';
|
|
27
|
+
export type { ICellHyperLink, ICellLinkContent } from './types/interfaces/i-hyper-link';
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Disposable } from '@univerjs/core';
|
|
2
|
+
import { ICellHyperLink, ICellLinkContent } from '../types/interfaces/i-hyper-link';
|
|
3
|
+
|
|
4
|
+
type LinkUpdate = {
|
|
5
|
+
type: 'add';
|
|
6
|
+
payload: ICellHyperLink;
|
|
7
|
+
unitId: string;
|
|
8
|
+
subUnitId: string;
|
|
9
|
+
} | {
|
|
10
|
+
type: 'remove';
|
|
11
|
+
payload: ICellHyperLink;
|
|
12
|
+
unitId: string;
|
|
13
|
+
subUnitId: string;
|
|
14
|
+
} | {
|
|
15
|
+
type: 'update';
|
|
16
|
+
unitId: string;
|
|
17
|
+
subUnitId: string;
|
|
18
|
+
payload: ICellLinkContent;
|
|
19
|
+
id: string;
|
|
20
|
+
} | {
|
|
21
|
+
type: 'updateRef';
|
|
22
|
+
unitId: string;
|
|
23
|
+
subUnitId: string;
|
|
24
|
+
id: string;
|
|
25
|
+
payload: {
|
|
26
|
+
row: number;
|
|
27
|
+
column: number;
|
|
28
|
+
};
|
|
29
|
+
} | {
|
|
30
|
+
type: 'unload';
|
|
31
|
+
unitId: string;
|
|
32
|
+
unitLinks: {
|
|
33
|
+
unitId: string;
|
|
34
|
+
subUnitId: string;
|
|
35
|
+
links: ICellHyperLink[];
|
|
36
|
+
}[];
|
|
37
|
+
};
|
|
38
|
+
export declare class HyperLinkModel extends Disposable {
|
|
39
|
+
private _linkUpdate$;
|
|
40
|
+
linkUpdate$: import('rxjs').Observable<LinkUpdate>;
|
|
41
|
+
private _linkMap;
|
|
42
|
+
private _linkPositionMap;
|
|
43
|
+
constructor();
|
|
44
|
+
private _ensureMap;
|
|
45
|
+
addHyperLink(unitId: string, subUnitId: string, link: ICellHyperLink): boolean;
|
|
46
|
+
updateHyperLink(unitId: string, subUnitId: string, id: string, payload: Partial<ICellLinkContent>, silent?: boolean): boolean;
|
|
47
|
+
updateHyperLinkRef(unitId: string, subUnitId: string, id: string, payload: {
|
|
48
|
+
row: number;
|
|
49
|
+
column: number;
|
|
50
|
+
}): boolean;
|
|
51
|
+
removeHyperLink(unitId: string, subUnitId: string, id: string): boolean;
|
|
52
|
+
getHyperLink(unitId: string, subUnitId: string, id: string): ICellHyperLink | undefined;
|
|
53
|
+
getHyperLinkByLocation(unitId: string, subUnitId: string, row: number, column: number): ICellHyperLink | undefined;
|
|
54
|
+
getSubUnit(unitId: string, subUnitId: string): ICellHyperLink[];
|
|
55
|
+
getUnit(unitId: string): {
|
|
56
|
+
unitId: string;
|
|
57
|
+
subUnitId: string;
|
|
58
|
+
links: ICellHyperLink[];
|
|
59
|
+
}[];
|
|
60
|
+
deleteUnit(unitId: string): void;
|
|
61
|
+
getAll(): {
|
|
62
|
+
unitId: string;
|
|
63
|
+
subUnitId: string;
|
|
64
|
+
links: ICellHyperLink[];
|
|
65
|
+
}[][];
|
|
66
|
+
}
|
|
67
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Plugin, UniverInstanceType } from '@univerjs/core';
|
|
2
|
+
import { Injector } from '@wendellhu/redi';
|
|
3
|
+
|
|
4
|
+
export declare class UniverSheetsHyperLinkPlugin extends Plugin {
|
|
5
|
+
protected _injector: Injector;
|
|
6
|
+
static pluginName: string;
|
|
7
|
+
static type: UniverInstanceType;
|
|
8
|
+
constructor(config: unknown, _injector: Injector);
|
|
9
|
+
onStarting(_injector: Injector): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export declare const SHEET_HYPER_LINK_PLUGIN = "SHEET_HYPER_LINK_PLUGIN";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export declare enum HyperLinkType {
|
|
17
|
+
range = 0,
|
|
18
|
+
link = 1
|
|
19
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Inc.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export interface ICellLinkContent {
|
|
17
|
+
/**
|
|
18
|
+
* #gid=sheet1&range=A1
|
|
19
|
+
* sub sheet: #gid=sheet1
|
|
20
|
+
* namedRange: #rangeid=123
|
|
21
|
+
* http: https://baidu.com
|
|
22
|
+
* file: file://a.xlsx
|
|
23
|
+
*/
|
|
24
|
+
payload: string;
|
|
25
|
+
display: string;
|
|
26
|
+
}
|
|
27
|
+
export interface ICellHyperLink extends ICellLinkContent {
|
|
28
|
+
id: string;
|
|
29
|
+
row: number;
|
|
30
|
+
column: number;
|
|
31
|
+
}
|
package/lib/umd/index.js
ADDED
|
@@ -0,0 +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,V,L){"use strict";var q=Object.defineProperty;var J=(d,a,h)=>a in d?q(d,a,{enumerable:!0,configurable:!0,writable:!0,value:h}):d[a]=h;var y=(d,a,h)=>(J(d,typeof a!="symbol"?a+"":a,h),h);var v;class m extends a.Disposable{constructor(){super();y(this,"_linkUpdate$",new V.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,i){let n=this._linkMap.get(e);n||(n=new Map,this._linkMap.set(e,n));let r=n.get(i);r||(r=new a.ObjectMatrix,n.set(i,r));let o=this._linkPositionMap.get(e);o||(o=new Map,this._linkPositionMap.set(e,o));let u=o.get(i);return u||(u=new Map,o.set(i,u)),{matrix:r,positionMap:u}}addHyperLink(e,i,n){const{matrix:r,positionMap:o}=this._ensureMap(e,i);return r.setValue(n.row,n.column,n),o.set(n.id,{row:n.row,column:n.column,link:n}),this._linkUpdate$.next({unitId:e,subUnitId:i,payload:n,type:"add"}),!0}updateHyperLink(e,i,n,r,o){const{matrix:u,positionMap:l}=this._ensureMap(e,i),c=l.get(n);if(!c)return!1;const p=u.getValue(c.row,c.column);return p?(Object.assign(p,r),o||this._linkUpdate$.next({unitId:e,subUnitId:i,payload:{display:p.display,payload:p.payload},id:n,type:"update"}),!0):!1}updateHyperLinkRef(e,i,n,r){const{matrix:o,positionMap:u}=this._ensureMap(e,i),l=u.get(n);if(!l)return!1;let c=o.getValue(l.row,l.column);return!c||c.id!==n?c=l.link:o.realDeleteValue(l.row,l.column),Object.assign(c,r),u.set(n,{...r,link:c}),o.setValue(r.row,r.column,c),this._linkUpdate$.next({unitId:e,subUnitId:i,payload:r,id:n,type:"updateRef"}),!0}removeHyperLink(e,i,n){const{matrix:r,positionMap:o}=this._ensureMap(e,i),u=o.get(n);if(!u)return!1;o.delete(n);const l=r.getValue(u.row,u.column);return l&&l.id===n&&r.realDeleteValue(u.row,u.column),this._linkUpdate$.next({unitId:e,subUnitId:i,payload:l,type:"remove"}),!0}getHyperLink(e,i,n){const{matrix:r,positionMap:o}=this._ensureMap(e,i),u=o.get(n);if(u)return r.getValue(u.row,u.column)}getHyperLinkByLocation(e,i,n,r){const{matrix:o}=this._ensureMap(e,i);return o.getValue(n,r)}getSubUnit(e,i){const{matrix:n}=this._ensureMap(e,i),r=[];return n.forValue((o,u,l)=>{l&&r.push(l)}),r}getUnit(e){const i=this._linkMap.get(e);return i?Array.from(i.keys()).map(n=>{const r=this.getSubUnit(e,n);return{unitId:e,subUnitId:n,links:r}}):[]}deleteUnit(e){const i=this.getUnit(e);this._linkMap.delete(e),this._linkPositionMap.delete(e),this._linkUpdate$.next({type:"unload",unitId:e,unitLinks:i})}getAll(){return Array.from(this._linkMap.keys()).map(i=>this.getUnit(i))}}const M={type:a.CommandType.MUTATION,id:"sheets.mutation.add-hyper-link",handler(t,s){if(!s)return!1;const e=t.get(m),{unitId:i,subUnitId:n,link:r}=s;return e.addHyperLink(i,n,r)}},g={type:a.CommandType.MUTATION,id:"sheets.mutation.remove-hyper-link",handler(t,s){if(!s)return!1;const e=t.get(m),{unitId:i,subUnitId:n,id:r}=s;return e.removeHyperLink(i,n,r)}},U={type:a.CommandType.COMMAND,id:"sheets.command.remove-hyper-link",async handler(t,s){if(!s)return!1;const e=t.get(h.SheetInterceptorService),i=t.get(a.ICommandService),n=t.get(a.IUndoRedoService),r=t.get(m),{unitId:o,subUnitId:u,id:l}=s,c=r.getHyperLink(o,u,l),{redos:p,undos:k}=e.onCommandExecute({id:U.id,params:s}),f={id:g.id,params:s},I={id:M.id,params:{unitId:o,subUnitId:u,link:c}};return(await a.sequenceExecuteAsync([f,...p],i)).result?(n.pushUndoRedo({redoMutations:[f,...p],undoMutations:[I,...k],unitID:o}),!0):!1}},R={type:a.CommandType.COMMAND,id:"sheets.command.cancel-hyper-link",async handler(t,s){if(!s)return!1;const e=t.get(a.ICommandService),i=t.get(a.IUndoRedoService),n=t.get(m),{unitId:r,subUnitId:o,id:u}=s,l=n.getHyperLink(r,o,u),c={id:g.id,params:s},p={id:M.id,params:{unitId:r,subUnitId:o,link:l}};return(await a.sequenceExecuteAsync([c],e)).result?(i.pushUndoRedo({redoMutations:[c],undoMutations:[p],unitID:r}),!0):!1}},S={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link",handler(t,s){if(!s)return!1;const e=t.get(m),{unitId:i,subUnitId:n,payload:r,id:o}=s;return e.updateHyperLink(i,n,o,r)}},N={type:a.CommandType.MUTATION,id:"sheets.mutation.update-hyper-link-ref",handler(t,s){if(!s)return!1;const e=t.get(m),{unitId:i,subUnitId:n,id:r,row:o,column:u}=s;return e.updateHyperLinkRef(i,n,r,{row:o,column:u})}},H={type:a.CommandType.COMMAND,id:"sheets.command.add-hyper-link",async handler(t,s){if(!s)return!1;const e=t.get(h.SheetInterceptorService),i=t.get(a.ICommandService),n=t.get(a.IUndoRedoService),{unitId:r,subUnitId:o,link:u}=s,{redos:l,undos:c}=e.onCommandExecute({id:H.id,params:s}),p={id:M.id,params:s},k={id:g.id,params:{unitId:r,subUnitId:o,id:u.id}};return(await a.sequenceExecuteAsync([p,...l],i)).result?(n.pushUndoRedo({redoMutations:[p,...l],undoMutations:[k,...c],unitID:r}),!0):!1}};function A(t){const{row:s,column:e,id:i,...n}=t;return n}const C={type:a.CommandType.COMMAND,id:"sheets.command.update-hyper-link",async handler(t,s){if(!s)return!1;const e=t.get(h.SheetInterceptorService),i=t.get(a.ICommandService),n=t.get(a.IUndoRedoService),r=t.get(m),{unitId:o,subUnitId:u,id:l}=s,c=r.getHyperLink(o,u,l);if(!c)return!1;const{redos:p,undos:k}=e.onCommandExecute({id:C.id,params:s}),f={id:S.id,params:s},I={id:S.id,params:{unitId:o,subUnitId:u,id:l,payload:A(c)}};return(await a.sequenceExecuteAsync([f,...p],i)).result?(n.pushUndoRedo({redoMutations:[f,...p],undoMutations:[I,...k],unitID:o}),!0):!1}};var D=(t,s,e,i)=>{for(var n=s,r=t.length-1,o;r>=0;r--)(o=t[r])&&(n=o(n)||n);return n},P=(t,s)=>(e,i)=>s(e,i,t);d.SheetsHyperLinkController=class extends a.Disposable{constructor(s){super(),this._commandService=s,this._registerCommands()}_registerCommands(){[M,S,g,N,H,C,U,R].forEach(s=>{this._commandService.registerCommand(s)})}},d.SheetsHyperLinkController=D([a.OnLifecycle(a.LifecycleStages.Starting,d.SheetsHyperLinkController),P(0,a.ICommandService)],d.SheetsHyperLinkController);var E=(t=>(t[t.range=0]="range",t[t.link=1]="link",t))(E||{});const w="SHEET_HYPER_LINK_PLUGIN";var O=(t=>(t[t.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",t[t.UNIVER_DOC=1]="UNIVER_DOC",t[t.UNIVER_SHEET=2]="UNIVER_SHEET",t[t.UNIVER_SLIDE=3]="UNIVER_SLIDE",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED",t))(O||{}),j=(t,s,e,i)=>{for(var n=s,r=t.length-1,o;r>=0;r--)(o=t[r])&&(n=o(n)||n);return n},T=(t,s)=>(e,i)=>s(e,i,t);let _=class extends a.Disposable{constructor(t,s){super(),this._resourceManagerService=t,this._hyperLinkModel=s,this._initSnapshot()}_initSnapshot(){const t=e=>{const i=this._hyperLinkModel.getUnit(e),n={};return i?(i.forEach(r=>{n[r.subUnitId]=r.links}),JSON.stringify(n)):""},s=e=>{if(!e)return{};try{return JSON.parse(e)}catch{return{}}};this.disposeWithMe(this._resourceManagerService.registerPluginResource({pluginName:w,businesses:[O.UNIVER_SHEET],toJson:e=>t(e),parseJson:e=>s(e),onUnLoad:e=>{this._hyperLinkModel.deleteUnit(e)},onLoad:async(e,i)=>{Object.keys(i).forEach(n=>{i[n].forEach(o=>{this._hyperLinkModel.addHyperLink(e,n,o)})})}}))}};_=j([a.OnLifecycle(a.LifecycleStages.Starting,_),T(0,a.IResourceManagerService),T(1,L.Inject(m))],_);var b=(t,s,e,i)=>{for(var n=s,r=t.length-1,o;r>=0;r--)(o=t[r])&&(n=o(n)||n);return n},x=(t,s)=>(e,i)=>s(e,i,t);d.UniverSheetsHyperLinkPlugin=(v=class extends a.Plugin{constructor(s,e){super(),this._injector=e}onStarting(s){[[_],[d.SheetsHyperLinkController],[m]].forEach(e=>{s.add(e)})}},y(v,"pluginName",w),y(v,"type",a.UniverInstanceType.UNIVER_SHEET),v),d.UniverSheetsHyperLinkPlugin=b([x(1,L.Inject(L.Injector))],d.UniverSheetsHyperLinkPlugin),d.AddHyperLinkCommand=H,d.AddHyperLinkMutation=M,d.CancelHyperLinkCommand=R,d.HyperLinkModel=m,d.HyperLinkType=E,d.RemoveHyperLinkCommand=U,d.RemoveHyperLinkMutation=g,d.UpdateHyperLinkCommand=C,d.UpdateHyperLinkMutation=S,d.UpdateHyperLinkRefMutation=N,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@univerjs/sheets-hyper-link",
|
|
3
|
+
"version": "0.1.13-nightly.202406041140",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "",
|
|
6
|
+
"author": "DreamNum <developer@univer.ai>",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"funding": {
|
|
9
|
+
"type": "opencollective",
|
|
10
|
+
"url": "https://opencollective.com/univer"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://univer.ai",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/dream-num/univer"
|
|
16
|
+
},
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/dream-num/univer/issues"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [],
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"import": "./lib/es/index.js",
|
|
24
|
+
"require": "./lib/cjs/index.js",
|
|
25
|
+
"types": "./lib/types/index.d.ts"
|
|
26
|
+
},
|
|
27
|
+
"./*": {
|
|
28
|
+
"import": "./lib/es/*",
|
|
29
|
+
"require": "./lib/cjs/*",
|
|
30
|
+
"types": "./lib/types/index.d.ts"
|
|
31
|
+
},
|
|
32
|
+
"./lib/*": "./lib/*"
|
|
33
|
+
},
|
|
34
|
+
"main": "./lib/cjs/index.js",
|
|
35
|
+
"module": "./lib/es/index.js",
|
|
36
|
+
"types": "./lib/types/index.d.ts",
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"directories": {
|
|
41
|
+
"lib": "lib"
|
|
42
|
+
},
|
|
43
|
+
"files": [
|
|
44
|
+
"lib"
|
|
45
|
+
],
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"@wendellhu/redi": "0.15.2",
|
|
48
|
+
"rxjs": ">=7.0.0",
|
|
49
|
+
"@univerjs/core": "0.1.13-nightly.202406041140",
|
|
50
|
+
"@univerjs/sheets": "0.1.13-nightly.202406041140"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@univerjs/protocol": "^0.1.36",
|
|
54
|
+
"@wendellhu/redi": "^0.15.2",
|
|
55
|
+
"rxjs": "^7.8.1",
|
|
56
|
+
"typescript": "^5.4.5",
|
|
57
|
+
"vite": "^5.2.12",
|
|
58
|
+
"vitest": "^1.6.0",
|
|
59
|
+
"@univerjs/core": "0.1.13-nightly.202406041140",
|
|
60
|
+
"@univerjs/sheets": "0.1.13-nightly.202406041140",
|
|
61
|
+
"@univerjs/shared": "0.1.13"
|
|
62
|
+
},
|
|
63
|
+
"scripts": {
|
|
64
|
+
"test": "vitest run",
|
|
65
|
+
"test:watch": "vitest",
|
|
66
|
+
"coverage": "vitest run --coverage",
|
|
67
|
+
"lint:types": "tsc --noEmit",
|
|
68
|
+
"build": "tsc && vite build"
|
|
69
|
+
}
|
|
70
|
+
}
|