@univerjs/docs-hyper-link 0.2.3 → 0.2.4
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 +0 -6
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +164 -109
- package/lib/types/commands/mutations/add-link.mutation.d.ts +2 -2
- package/lib/types/controllers/doc-hyper-link-custom-range.controller.d.ts +10 -0
- package/lib/types/plugin.d.ts +2 -1
- package/lib/umd/index.js +1 -1
- package/package.json +11 -9
package/README.md
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
# @univerjs/docs-hyper-link
|
|
2
2
|
|
|
3
|
-
## Package Overview
|
|
4
|
-
|
|
5
|
-
| Package Name | UMD Namespace | Version | License | Downloads | Contains CSS | Contains i18n locales |
|
|
6
|
-
| --- | --- | --- | --- | --- | :---: | :---: |
|
|
7
|
-
| `@univerjs/docs-hyper-link` | `UniverDocsHyperLink` | [![][npm-version-shield]][npm-version-link] | ![][npm-license-shield] | ![][npm-downloads-shield] | ❌ | ❌ |
|
|
8
|
-
|
|
9
3
|
## Introduction
|
|
10
4
|
|
|
11
5
|
`@univerjs/docs-hyper-link` provides the base link function of Univer Docs.
|
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var U=Object.defineProperty;var I=(t,e,n)=>e in t?U(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var p=(t,e,n)=>I(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@univerjs/core"),O=require("rxjs"),d=require("@wendellhu/redi"),f=require("@univerjs/docs"),v="DOC_HYPER_LINK_PLUGIN";class c extends s.Disposable{constructor(){super();p(this,"_links",new Map);p(this,"_linkUpdate$",new O.Subject);p(this,"linkUpdate$",this._linkUpdate$.asObservable());this.disposeWithMe(()=>{this._linkUpdate$.complete()})}_ensureMap(n){let r=this._links.get(n);return r||(r=new Map,this._links.set(n,r)),r}addLink(n,r){const i=this._ensureMap(n);return r.payload=s.Tools.normalizeUrl(r.payload),i.set(r.id,r),this._linkUpdate$.next({type:"add",link:r,unitId:n}),!0}updateLink(n,r,i){const o=this._ensureMap(n).get(r);if(!o)return!1;const l=o.payload;return o.payload=i,this._linkUpdate$.next({type:"update",link:o,oldPayload:l,unitId:n}),!0}deleteLink(n,r){const i=this._ensureMap(n),a=i.get(r);return a?(i.delete(r),this._linkUpdate$.next({type:"delete",link:a,unitId:n}),!1):!0}getLink(n,r){return this._ensureMap(n).get(r)}getUnit(n){const r=this._ensureMap(n);return Array.from(r.values())}deleteUnit(n){this._links.delete(n),this._linkUpdate$.next({unitId:n,type:"delete-unit"})}}var m=(t=>(t[t.URL=0]="URL",t))(m||{});const k={type:s.CommandType.MUTATION,id:"docs.mutation.add-hyper-link",handler(t,e){return e?t.get(c).addLink(e.unitId,e.link):!1}},M={type:s.CommandType.MUTATION,id:"docs.mutation.update-hyper-link",handler(t,e){return e?t.get(c).updateLink(e.unitId,e.linkId,e.payload):!1}},P={type:s.CommandType.MUTATION,id:"docs.mutation.delete-hyper-link",handler(t,e){return e?t.get(c).deleteLink(e.unitId,e.linkId):!1}};var C=Object.defineProperty,R=Object.getOwnPropertyDescriptor,S=(t,e,n,r)=>{for(var i=r>1?void 0:r?R(e,n):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(r?o(e,n,i):o(i))||i);return r&&i&&C(e,n,i),i},b=(t,e)=>(n,r)=>e(n,r,t);let u=class extends s.Disposable{constructor(t){super(),this._commandService=t,this._initCommands()}_initCommands(){[k,M,P].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}};u=S([s.OnLifecycle(s.LifecycleStages.Starting,u),b(0,s.ICommandService)],u);var T=Object.defineProperty,$=Object.getOwnPropertyDescriptor,N=(t,e,n,r)=>{for(var i=r>1?void 0:r?$(e,n):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(r?o(e,n,i):o(i))||i);return r&&i&&T(e,n,i),i},L=(t,e)=>(n,r)=>e(n,r,t);let _=class extends s.Disposable{constructor(t,e,n){super(),this._resourceManagerService=t,this._docHyperLinkModel=e,this._univerInstanceService=n,this._init()}_init(){this._resourceManagerService.registerPluginResource({pluginName:v,businesses:[s.UniverInstanceType.UNIVER_DOC],onLoad:(t,e)=>{e.links.forEach(n=>{this._docHyperLinkModel.addLink(t,n)})},onUnLoad:t=>{this._docHyperLinkModel.deleteUnit(t)},toJson:t=>{var a;const e=this._docHyperLinkModel.getUnit(t),n=this._univerInstanceService.getUnit(t,s.UniverInstanceType.UNIVER_DOC),r=(a=n==null?void 0:n.getBody())==null?void 0:a.customRanges,i=new Set(r==null?void 0:r.filter(o=>o.rangeType===s.CustomRangeType.HYPERLINK).map(o=>o.rangeId));return JSON.stringify({links:e.filter(o=>i.has(o.id))})},parseJson(t){return JSON.parse(t)}})}};_=N([s.OnLifecycle(s.LifecycleStages.Starting,_),L(0,d.Inject(s.IResourceManagerService)),L(1,d.Inject(c)),L(2,s.IUniverInstanceService)],_);var j=Object.defineProperty,w=Object.getOwnPropertyDescriptor,x=(t,e,n,r)=>{for(var i=r>1?void 0:r?w(e,n):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(r?o(e,n,i):o(i))||i);return r&&i&&j(e,n,i),i},g=(t,e)=>(n,r)=>e(n,r,t);let y=class extends s.Disposable{constructor(t,e){super(),this._docCustomRangeService=t,this._docHyperLinkModel=e,this._initCustomRangeHooks()}_initCustomRangeHooks(){this.disposeWithMe(this._docCustomRangeService.addClipboardHook({onCopyCustomRange:(t,e)=>{const{rangeId:n,rangeType:r,data:i,...a}=e;if(r===s.CustomRangeType.HYPERLINK){if(i){const h=s.Tools.generateRandomId();return this._docHyperLinkModel.addLink(t,{id:h,payload:i}),{...e,rangeId:h}}const o=this._docHyperLinkModel.getLink(t,n);if(!o)return e;const l=s.Tools.generateRandomId();return this._docHyperLinkModel.addLink(t,{id:l,payload:o.payload}),{...a,rangeId:l,rangeType:r}}return e}}))}};y=x([s.OnLifecycle(s.LifecycleStages.Ready,y),g(0,d.Inject(f.DocCustomRangeService)),g(1,d.Inject(c))],y);var D=Object.defineProperty,E=Object.getOwnPropertyDescriptor,A=(t,e,n)=>e in t?D(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,K=(t,e,n,r)=>{for(var i=r>1?void 0:r?E(e,n):e,a=t.length-1,o;a>=0;a--)(o=t[a])&&(i=(r?o(e,n,i):o(i))||i);return r&&i&&D(e,n,i),i},Y=(t,e)=>(n,r)=>e(n,r,t),H=(t,e,n)=>A(t,typeof e!="symbol"?e+"":e,n);exports.UniverDocsHyperLinkPlugin=class extends s.Plugin{constructor(e,n){super(),this._config=e,this._injector=n}onStarting(e){[[c],[u],[_],[y]].forEach(r=>{e.add(r)})}};H(exports.UniverDocsHyperLinkPlugin,"pluginName",v);H(exports.UniverDocsHyperLinkPlugin,"type",s.UniverInstanceType.UNIVER_DOC);exports.UniverDocsHyperLinkPlugin=K([s.DependentOn(f.UniverDocsPlugin),Y(1,d.Inject(d.Injector))],exports.UniverDocsHyperLinkPlugin);exports.AddDocHyperLinkMutation=k;exports.DOC_HYPER_LINK_PLUGIN=v;exports.DeleteDocHyperLinkMutation=P;exports.DocHyperLinkModel=c;exports.DocHyperLinkType=m;exports.UpdateDocHyperLinkMutation=M;
|
package/lib/es/index.js
CHANGED
|
@@ -1,134 +1,136 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { Disposable as y, CommandType as
|
|
5
|
-
import { Subject as
|
|
6
|
-
import { Inject as
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
var I = Object.defineProperty;
|
|
2
|
+
var D = (t, e, n) => e in t ? I(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
3
|
+
var l = (t, e, n) => D(t, typeof e != "symbol" ? e + "" : e, n);
|
|
4
|
+
import { Disposable as f, Tools as y, CommandType as g, OnLifecycle as L, LifecycleStages as M, ICommandService as R, IResourceManagerService as S, UniverInstanceType as m, CustomRangeType as U, IUniverInstanceService as $, DependentOn as b, Plugin as N } from "@univerjs/core";
|
|
5
|
+
import { Subject as w } from "rxjs";
|
|
6
|
+
import { Inject as d, Injector as x } from "@wendellhu/redi";
|
|
7
|
+
import { DocCustomRangeService as T, UniverDocsPlugin as j } from "@univerjs/docs";
|
|
8
|
+
const O = "DOC_HYPER_LINK_PLUGIN";
|
|
9
|
+
class a extends f {
|
|
9
10
|
constructor() {
|
|
10
11
|
super();
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
l(this, "_links", /* @__PURE__ */ new Map());
|
|
13
|
+
l(this, "_linkUpdate$", new w());
|
|
14
|
+
l(this, "linkUpdate$", this._linkUpdate$.asObservable());
|
|
14
15
|
this.disposeWithMe(() => {
|
|
15
16
|
this._linkUpdate$.complete();
|
|
16
17
|
});
|
|
17
18
|
}
|
|
18
|
-
_ensureMap(
|
|
19
|
-
let r = this._links.get(
|
|
20
|
-
return r || (r = /* @__PURE__ */ new Map(), this._links.set(
|
|
19
|
+
_ensureMap(n) {
|
|
20
|
+
let r = this._links.get(n);
|
|
21
|
+
return r || (r = /* @__PURE__ */ new Map(), this._links.set(n, r)), r;
|
|
21
22
|
}
|
|
22
|
-
addLink(
|
|
23
|
-
|
|
23
|
+
addLink(n, r) {
|
|
24
|
+
const i = this._ensureMap(n);
|
|
25
|
+
return r.payload = y.normalizeUrl(r.payload), i.set(r.id, r), this._linkUpdate$.next({
|
|
24
26
|
type: "add",
|
|
25
27
|
link: r,
|
|
26
|
-
unitId:
|
|
28
|
+
unitId: n
|
|
27
29
|
}), !0;
|
|
28
30
|
}
|
|
29
|
-
updateLink(
|
|
30
|
-
const
|
|
31
|
-
if (!
|
|
31
|
+
updateLink(n, r, i) {
|
|
32
|
+
const o = this._ensureMap(n).get(r);
|
|
33
|
+
if (!o)
|
|
32
34
|
return !1;
|
|
33
|
-
const
|
|
34
|
-
return
|
|
35
|
+
const c = o.payload;
|
|
36
|
+
return o.payload = i, this._linkUpdate$.next({
|
|
35
37
|
type: "update",
|
|
36
|
-
link:
|
|
37
|
-
oldPayload:
|
|
38
|
-
unitId:
|
|
38
|
+
link: o,
|
|
39
|
+
oldPayload: c,
|
|
40
|
+
unitId: n
|
|
39
41
|
}), !0;
|
|
40
42
|
}
|
|
41
|
-
deleteLink(
|
|
42
|
-
const i = this._ensureMap(
|
|
43
|
-
return
|
|
43
|
+
deleteLink(n, r) {
|
|
44
|
+
const i = this._ensureMap(n), s = i.get(r);
|
|
45
|
+
return s ? (i.delete(r), this._linkUpdate$.next({
|
|
44
46
|
type: "delete",
|
|
45
|
-
link:
|
|
46
|
-
unitId:
|
|
47
|
+
link: s,
|
|
48
|
+
unitId: n
|
|
47
49
|
}), !1) : !0;
|
|
48
50
|
}
|
|
49
|
-
getLink(
|
|
50
|
-
return this._ensureMap(
|
|
51
|
+
getLink(n, r) {
|
|
52
|
+
return this._ensureMap(n).get(r);
|
|
51
53
|
}
|
|
52
|
-
getUnit(
|
|
53
|
-
const r = this._ensureMap(
|
|
54
|
+
getUnit(n) {
|
|
55
|
+
const r = this._ensureMap(n);
|
|
54
56
|
return Array.from(r.values());
|
|
55
57
|
}
|
|
56
|
-
deleteUnit(
|
|
57
|
-
this._links.delete(
|
|
58
|
-
unitId:
|
|
58
|
+
deleteUnit(n) {
|
|
59
|
+
this._links.delete(n), this._linkUpdate$.next({
|
|
60
|
+
unitId: n,
|
|
59
61
|
type: "delete-unit"
|
|
60
62
|
});
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
|
-
var
|
|
64
|
-
const
|
|
65
|
-
type:
|
|
65
|
+
var E = /* @__PURE__ */ ((t) => (t[t.URL = 0] = "URL", t))(E || {});
|
|
66
|
+
const A = {
|
|
67
|
+
type: g.MUTATION,
|
|
66
68
|
id: "docs.mutation.add-hyper-link",
|
|
67
|
-
handler(t,
|
|
68
|
-
return
|
|
69
|
+
handler(t, e) {
|
|
70
|
+
return e ? t.get(a).addLink(e.unitId, e.link) : !1;
|
|
69
71
|
}
|
|
70
|
-
},
|
|
71
|
-
type:
|
|
72
|
+
}, J = {
|
|
73
|
+
type: g.MUTATION,
|
|
72
74
|
id: "docs.mutation.update-hyper-link",
|
|
73
|
-
handler(t,
|
|
74
|
-
return
|
|
75
|
+
handler(t, e) {
|
|
76
|
+
return e ? t.get(a).updateLink(e.unitId, e.linkId, e.payload) : !1;
|
|
75
77
|
}
|
|
76
|
-
},
|
|
77
|
-
type:
|
|
78
|
+
}, K = {
|
|
79
|
+
type: g.MUTATION,
|
|
78
80
|
id: "docs.mutation.delete-hyper-link",
|
|
79
|
-
handler(t,
|
|
80
|
-
return
|
|
81
|
+
handler(t, e) {
|
|
82
|
+
return e ? t.get(a).deleteLink(e.unitId, e.linkId) : !1;
|
|
81
83
|
}
|
|
82
84
|
};
|
|
83
|
-
var
|
|
84
|
-
for (var i = r > 1 ? void 0 : r ?
|
|
85
|
-
(
|
|
86
|
-
return r && i &&
|
|
87
|
-
},
|
|
88
|
-
let
|
|
85
|
+
var Y = Object.defineProperty, V = Object.getOwnPropertyDescriptor, W = (t, e, n, r) => {
|
|
86
|
+
for (var i = r > 1 ? void 0 : r ? V(e, n) : e, s = t.length - 1, o; s >= 0; s--)
|
|
87
|
+
(o = t[s]) && (i = (r ? o(e, n, i) : o(i)) || i);
|
|
88
|
+
return r && i && Y(e, n, i), i;
|
|
89
|
+
}, G = (t, e) => (n, r) => e(n, r, t);
|
|
90
|
+
let p = class extends f {
|
|
89
91
|
constructor(t) {
|
|
90
92
|
super(), this._commandService = t, this._initCommands();
|
|
91
93
|
}
|
|
92
94
|
_initCommands() {
|
|
93
95
|
[
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
96
|
+
A,
|
|
97
|
+
J,
|
|
98
|
+
K
|
|
97
99
|
].forEach((t) => {
|
|
98
100
|
this.disposeWithMe(this._commandService.registerCommand(t));
|
|
99
101
|
});
|
|
100
102
|
}
|
|
101
103
|
};
|
|
102
|
-
|
|
103
|
-
L(
|
|
104
|
-
|
|
105
|
-
],
|
|
106
|
-
var
|
|
107
|
-
for (var i = r > 1 ? void 0 : r ?
|
|
108
|
-
(
|
|
109
|
-
return r && i &&
|
|
110
|
-
},
|
|
111
|
-
let
|
|
112
|
-
constructor(t,
|
|
113
|
-
super(), this._resourceManagerService = t, this._docHyperLinkModel =
|
|
104
|
+
p = W([
|
|
105
|
+
L(M.Starting, p),
|
|
106
|
+
G(0, R)
|
|
107
|
+
], p);
|
|
108
|
+
var z = Object.defineProperty, B = Object.getOwnPropertyDescriptor, F = (t, e, n, r) => {
|
|
109
|
+
for (var i = r > 1 ? void 0 : r ? B(e, n) : e, s = t.length - 1, o; s >= 0; s--)
|
|
110
|
+
(o = t[s]) && (i = (r ? o(e, n, i) : o(i)) || i);
|
|
111
|
+
return r && i && z(e, n, i), i;
|
|
112
|
+
}, v = (t, e) => (n, r) => e(n, r, t);
|
|
113
|
+
let _ = class extends f {
|
|
114
|
+
constructor(t, e, n) {
|
|
115
|
+
super(), this._resourceManagerService = t, this._docHyperLinkModel = e, this._univerInstanceService = n, this._init();
|
|
114
116
|
}
|
|
115
117
|
_init() {
|
|
116
118
|
this._resourceManagerService.registerPluginResource({
|
|
117
|
-
pluginName:
|
|
118
|
-
businesses: [
|
|
119
|
-
onLoad: (t,
|
|
120
|
-
|
|
121
|
-
this._docHyperLinkModel.addLink(t,
|
|
119
|
+
pluginName: O,
|
|
120
|
+
businesses: [m.UNIVER_DOC],
|
|
121
|
+
onLoad: (t, e) => {
|
|
122
|
+
e.links.forEach((n) => {
|
|
123
|
+
this._docHyperLinkModel.addLink(t, n);
|
|
122
124
|
});
|
|
123
125
|
},
|
|
124
126
|
onUnLoad: (t) => {
|
|
125
127
|
this._docHyperLinkModel.deleteUnit(t);
|
|
126
128
|
},
|
|
127
129
|
toJson: (t) => {
|
|
128
|
-
var
|
|
129
|
-
const
|
|
130
|
+
var s;
|
|
131
|
+
const e = this._docHyperLinkModel.getUnit(t), n = this._univerInstanceService.getUnit(t, m.UNIVER_DOC), r = (s = n == null ? void 0 : n.getBody()) == null ? void 0 : s.customRanges, i = new Set(r == null ? void 0 : r.filter((o) => o.rangeType === U.HYPERLINK).map((o) => o.rangeId));
|
|
130
132
|
return JSON.stringify({
|
|
131
|
-
links:
|
|
133
|
+
links: e.filter((o) => i.has(o.id))
|
|
132
134
|
});
|
|
133
135
|
},
|
|
134
136
|
parseJson(t) {
|
|
@@ -137,40 +139,93 @@ let d = class extends y {
|
|
|
137
139
|
});
|
|
138
140
|
}
|
|
139
141
|
};
|
|
140
|
-
|
|
141
|
-
L(
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
],
|
|
146
|
-
var
|
|
147
|
-
for (var i = r > 1 ? void 0 : r ?
|
|
148
|
-
(
|
|
149
|
-
return r && i &&
|
|
150
|
-
},
|
|
151
|
-
let
|
|
152
|
-
constructor(t) {
|
|
153
|
-
super(), this.
|
|
142
|
+
_ = F([
|
|
143
|
+
L(M.Starting, _),
|
|
144
|
+
v(0, d(S)),
|
|
145
|
+
v(1, d(a)),
|
|
146
|
+
v(2, $)
|
|
147
|
+
], _);
|
|
148
|
+
var q = Object.defineProperty, Q = Object.getOwnPropertyDescriptor, X = (t, e, n, r) => {
|
|
149
|
+
for (var i = r > 1 ? void 0 : r ? Q(e, n) : e, s = t.length - 1, o; s >= 0; s--)
|
|
150
|
+
(o = t[s]) && (i = (r ? o(e, n, i) : o(i)) || i);
|
|
151
|
+
return r && i && q(e, n, i), i;
|
|
152
|
+
}, k = (t, e) => (n, r) => e(n, r, t);
|
|
153
|
+
let u = class extends f {
|
|
154
|
+
constructor(t, e) {
|
|
155
|
+
super(), this._docCustomRangeService = t, this._docHyperLinkModel = e, this._initCustomRangeHooks();
|
|
156
|
+
}
|
|
157
|
+
_initCustomRangeHooks() {
|
|
158
|
+
this.disposeWithMe(
|
|
159
|
+
this._docCustomRangeService.addClipboardHook({
|
|
160
|
+
onCopyCustomRange: (t, e) => {
|
|
161
|
+
const { rangeId: n, rangeType: r, data: i, ...s } = e;
|
|
162
|
+
if (r === U.HYPERLINK) {
|
|
163
|
+
if (i) {
|
|
164
|
+
const P = y.generateRandomId();
|
|
165
|
+
return this._docHyperLinkModel.addLink(t, {
|
|
166
|
+
id: P,
|
|
167
|
+
payload: i
|
|
168
|
+
}), {
|
|
169
|
+
...e,
|
|
170
|
+
rangeId: P
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
const o = this._docHyperLinkModel.getLink(t, n);
|
|
174
|
+
if (!o)
|
|
175
|
+
return e;
|
|
176
|
+
const c = y.generateRandomId();
|
|
177
|
+
return this._docHyperLinkModel.addLink(t, {
|
|
178
|
+
id: c,
|
|
179
|
+
payload: o.payload
|
|
180
|
+
}), {
|
|
181
|
+
...s,
|
|
182
|
+
rangeId: c,
|
|
183
|
+
rangeType: r
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
return e;
|
|
187
|
+
}
|
|
188
|
+
})
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
u = X([
|
|
193
|
+
L(M.Ready, u),
|
|
194
|
+
k(0, d(T)),
|
|
195
|
+
k(1, d(a))
|
|
196
|
+
], u);
|
|
197
|
+
var H = Object.defineProperty, Z = Object.getOwnPropertyDescriptor, ee = (t, e, n) => e in t ? H(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n, te = (t, e, n, r) => {
|
|
198
|
+
for (var i = r > 1 ? void 0 : r ? Z(e, n) : e, s = t.length - 1, o; s >= 0; s--)
|
|
199
|
+
(o = t[s]) && (i = (r ? o(e, n, i) : o(i)) || i);
|
|
200
|
+
return r && i && H(e, n, i), i;
|
|
201
|
+
}, ne = (t, e) => (n, r) => e(n, r, t), C = (t, e, n) => ee(t, typeof e != "symbol" ? e + "" : e, n);
|
|
202
|
+
let h = class extends N {
|
|
203
|
+
constructor(t, e) {
|
|
204
|
+
super(), this._config = t, this._injector = e;
|
|
154
205
|
}
|
|
155
206
|
onStarting(t) {
|
|
156
207
|
[
|
|
157
|
-
[
|
|
158
|
-
[
|
|
159
|
-
[
|
|
160
|
-
|
|
161
|
-
|
|
208
|
+
[a],
|
|
209
|
+
[p],
|
|
210
|
+
[_],
|
|
211
|
+
[u]
|
|
212
|
+
].forEach((n) => {
|
|
213
|
+
t.add(n);
|
|
162
214
|
});
|
|
163
215
|
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
216
|
+
};
|
|
217
|
+
C(h, "pluginName", O);
|
|
218
|
+
C(h, "type", m.UNIVER_DOC);
|
|
219
|
+
h = te([
|
|
220
|
+
b(j),
|
|
221
|
+
ne(1, d(x))
|
|
222
|
+
], h);
|
|
168
223
|
export {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
224
|
+
A as AddDocHyperLinkMutation,
|
|
225
|
+
O as DOC_HYPER_LINK_PLUGIN,
|
|
226
|
+
K as DeleteDocHyperLinkMutation,
|
|
227
|
+
a as DocHyperLinkModel,
|
|
228
|
+
E as DocHyperLinkType,
|
|
229
|
+
h as UniverDocsHyperLinkPlugin,
|
|
230
|
+
J as UpdateDocHyperLinkMutation
|
|
176
231
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { IMutation } from '@univerjs/core';
|
|
2
2
|
import { IDocHyperLink } from '../../types/interfaces/i-doc-hyper-link';
|
|
3
3
|
|
|
4
4
|
export interface IAddDocHyperLinkMutationParams {
|
|
5
5
|
unitId: string;
|
|
6
6
|
link: IDocHyperLink;
|
|
7
7
|
}
|
|
8
|
-
export declare const AddDocHyperLinkMutation:
|
|
8
|
+
export declare const AddDocHyperLinkMutation: IMutation<IAddDocHyperLinkMutationParams>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Disposable } from '@univerjs/core';
|
|
2
|
+
import { DocCustomRangeService } from '@univerjs/docs';
|
|
3
|
+
import { DocHyperLinkModel } from '../models/hyper-link.model';
|
|
4
|
+
|
|
5
|
+
export declare class DocHyperLinkCustomRangeController extends Disposable {
|
|
6
|
+
private readonly _docCustomRangeService;
|
|
7
|
+
private readonly _docHyperLinkModel;
|
|
8
|
+
constructor(_docCustomRangeService: DocCustomRangeService, _docHyperLinkModel: DocHyperLinkModel);
|
|
9
|
+
private _initCustomRangeHooks;
|
|
10
|
+
}
|
package/lib/types/plugin.d.ts
CHANGED
|
@@ -2,9 +2,10 @@ import { Plugin, UniverInstanceType } from '@univerjs/core';
|
|
|
2
2
|
import { Injector } from '@wendellhu/redi';
|
|
3
3
|
|
|
4
4
|
export declare class UniverDocsHyperLinkPlugin extends Plugin {
|
|
5
|
+
private _config;
|
|
5
6
|
protected _injector: Injector;
|
|
6
7
|
static pluginName: string;
|
|
7
8
|
static type: UniverInstanceType;
|
|
8
|
-
constructor(_injector: Injector);
|
|
9
|
+
constructor(_config: unknown, _injector: Injector);
|
|
9
10
|
onStarting(injector: Injector): void;
|
|
10
11
|
}
|
package/lib/umd/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(a,s){typeof exports=="object"&&typeof module<"u"?s(exports,require("@univerjs/core"),require("rxjs"),require("@wendellhu/redi"),require("@univerjs/docs")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","rxjs","@wendellhu/redi","@univerjs/docs"],s):(a=typeof globalThis<"u"?globalThis:a||self,s(a.UniverDocsHyperLink={},a.UniverCore,a.rxjs,a["@wendellhu/redi"],a.UniverDocs))})(this,function(a,s,p,c,g){"use strict";var Y=Object.defineProperty;var q=(a,s,p)=>s in a?Y(a,s,{enumerable:!0,configurable:!0,writable:!0,value:p}):a[s]=p;var f=(a,s,p)=>q(a,typeof s!="symbol"?s+"":s,p);const h="DOC_HYPER_LINK_PLUGIN";class l extends s.Disposable{constructor(){super();f(this,"_links",new Map);f(this,"_linkUpdate$",new p.Subject);f(this,"linkUpdate$",this._linkUpdate$.asObservable());this.disposeWithMe(()=>{this._linkUpdate$.complete()})}_ensureMap(n){let i=this._links.get(n);return i||(i=new Map,this._links.set(n,i)),i}addLink(n,i){const r=this._ensureMap(n);return i.payload=s.Tools.normalizeUrl(i.payload),r.set(i.id,i),this._linkUpdate$.next({type:"add",link:i,unitId:n}),!0}updateLink(n,i,r){const o=this._ensureMap(n).get(i);if(!o)return!1;const v=o.payload;return o.payload=r,this._linkUpdate$.next({type:"update",link:o,oldPayload:v,unitId:n}),!0}deleteLink(n,i){const r=this._ensureMap(n),d=r.get(i);return d?(r.delete(i),this._linkUpdate$.next({type:"delete",link:d,unitId:n}),!1):!0}getLink(n,i){return this._ensureMap(n).get(i)}getUnit(n){const i=this._ensureMap(n);return Array.from(i.values())}deleteUnit(n){this._links.delete(n),this._linkUpdate$.next({unitId:n,type:"delete-unit"})}}var m=(t=>(t[t.URL=0]="URL",t))(m||{});const k={type:s.CommandType.MUTATION,id:"docs.mutation.add-hyper-link",handler(t,e){return e?t.get(l).addLink(e.unitId,e.link):!1}},U={type:s.CommandType.MUTATION,id:"docs.mutation.update-hyper-link",handler(t,e){return e?t.get(l).updateLink(e.unitId,e.linkId,e.payload):!1}},D={type:s.CommandType.MUTATION,id:"docs.mutation.delete-hyper-link",handler(t,e){return e?t.get(l).deleteLink(e.unitId,e.linkId):!1}};var O=Object.defineProperty,C=Object.getOwnPropertyDescriptor,R=(t,e,n,i)=>{for(var r=i>1?void 0:i?C(e,n):e,d=t.length-1,o;d>=0;d--)(o=t[d])&&(r=(i?o(e,n,r):o(r))||r);return i&&r&&O(e,n,r),r},S=(t,e)=>(n,i)=>e(n,i,t);let u=class extends s.Disposable{constructor(t){super(),this._commandService=t,this._initCommands()}_initCommands(){[k,U,D].forEach(t=>{this.disposeWithMe(this._commandService.registerCommand(t))})}};u=R([s.OnLifecycle(s.LifecycleStages.Starting,u),S(0,s.ICommandService)],u);var j=Object.defineProperty,T=Object.getOwnPropertyDescriptor,$=(t,e,n,i)=>{for(var r=i>1?void 0:i?T(e,n):e,d=t.length-1,o;d>=0;d--)(o=t[d])&&(r=(i?o(e,n,r):o(r))||r);return i&&r&&j(e,n,r),r},L=(t,e)=>(n,i)=>e(n,i,t);let _=class extends s.Disposable{constructor(t,e,n){super(),this._resourceManagerService=t,this._docHyperLinkModel=e,this._univerInstanceService=n,this._init()}_init(){this._resourceManagerService.registerPluginResource({pluginName:h,businesses:[s.UniverInstanceType.UNIVER_DOC],onLoad:(t,e)=>{e.links.forEach(n=>{this._docHyperLinkModel.addLink(t,n)})},onUnLoad:t=>{this._docHyperLinkModel.deleteUnit(t)},toJson:t=>{var d;const e=this._docHyperLinkModel.getUnit(t),n=this._univerInstanceService.getUnit(t,s.UniverInstanceType.UNIVER_DOC),i=(d=n==null?void 0:n.getBody())==null?void 0:d.customRanges,r=new Set(i==null?void 0:i.filter(o=>o.rangeType===s.CustomRangeType.HYPERLINK).map(o=>o.rangeId));return JSON.stringify({links:e.filter(o=>r.has(o.id))})},parseJson(t){return JSON.parse(t)}})}};_=$([s.OnLifecycle(s.LifecycleStages.Starting,_),L(0,c.Inject(s.IResourceManagerService)),L(1,c.Inject(l)),L(2,s.IUniverInstanceService)],_);var b=Object.defineProperty,N=Object.getOwnPropertyDescriptor,w=(t,e,n,i)=>{for(var r=i>1?void 0:i?N(e,n):e,d=t.length-1,o;d>=0;d--)(o=t[d])&&(r=(i?o(e,n,r):o(r))||r);return i&&r&&b(e,n,r),r},H=(t,e)=>(n,i)=>e(n,i,t);let y=class extends s.Disposable{constructor(t,e){super(),this._docCustomRangeService=t,this._docHyperLinkModel=e,this._initCustomRangeHooks()}_initCustomRangeHooks(){this.disposeWithMe(this._docCustomRangeService.addClipboardHook({onCopyCustomRange:(t,e)=>{const{rangeId:n,rangeType:i,data:r,...d}=e;if(i===s.CustomRangeType.HYPERLINK){if(r){const I=s.Tools.generateRandomId();return this._docHyperLinkModel.addLink(t,{id:I,payload:r}),{...e,rangeId:I}}const o=this._docHyperLinkModel.getLink(t,n);if(!o)return e;const v=s.Tools.generateRandomId();return this._docHyperLinkModel.addLink(t,{id:v,payload:o.payload}),{...d,rangeId:v,rangeType:i}}return e}}))}};y=w([s.OnLifecycle(s.LifecycleStages.Ready,y),H(0,c.Inject(g.DocCustomRangeService)),H(1,c.Inject(l))],y);var M=Object.defineProperty,E=Object.getOwnPropertyDescriptor,A=(t,e,n)=>e in t?M(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,x=(t,e,n,i)=>{for(var r=i>1?void 0:i?E(e,n):e,d=t.length-1,o;d>=0;d--)(o=t[d])&&(r=(i?o(e,n,r):o(r))||r);return i&&r&&M(e,n,r),r},K=(t,e)=>(n,i)=>e(n,i,t),P=(t,e,n)=>A(t,typeof e!="symbol"?e+"":e,n);a.UniverDocsHyperLinkPlugin=class extends s.Plugin{constructor(e,n){super(),this._config=e,this._injector=n}onStarting(e){[[l],[u],[_],[y]].forEach(i=>{e.add(i)})}},P(a.UniverDocsHyperLinkPlugin,"pluginName",h),P(a.UniverDocsHyperLinkPlugin,"type",s.UniverInstanceType.UNIVER_DOC),a.UniverDocsHyperLinkPlugin=x([s.DependentOn(g.UniverDocsPlugin),K(1,c.Inject(c.Injector))],a.UniverDocsHyperLinkPlugin),a.AddDocHyperLinkMutation=k,a.DOC_HYPER_LINK_PLUGIN=h,a.DeleteDocHyperLinkMutation=D,a.DocHyperLinkModel=l,a.DocHyperLinkType=m,a.UpdateDocHyperLinkMutation=U,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/docs-hyper-link",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Univer thread comment plugin",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -44,19 +44,21 @@
|
|
|
44
44
|
"lib"
|
|
45
45
|
],
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@wendellhu/redi": "0.
|
|
47
|
+
"@wendellhu/redi": "0.16.0",
|
|
48
48
|
"rxjs": ">=7.0.0",
|
|
49
|
-
"@univerjs/core": "0.2.
|
|
49
|
+
"@univerjs/core": "0.2.4",
|
|
50
|
+
"@univerjs/docs": "0.2.4"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
|
-
"@wendellhu/redi": "0.
|
|
53
|
+
"@wendellhu/redi": "0.16.0",
|
|
53
54
|
"rxjs": "^7.8.1",
|
|
54
55
|
"typescript": "^5.5.3",
|
|
55
|
-
"vite": "^5.3.
|
|
56
|
-
"vitest": "^
|
|
57
|
-
"@univerjs/
|
|
58
|
-
"@univerjs/shared": "0.2.
|
|
59
|
-
"@univerjs/design": "0.2.
|
|
56
|
+
"vite": "^5.3.4",
|
|
57
|
+
"vitest": "^2.0.3",
|
|
58
|
+
"@univerjs/docs": "0.2.4",
|
|
59
|
+
"@univerjs/shared": "0.2.4",
|
|
60
|
+
"@univerjs/design": "0.2.4",
|
|
61
|
+
"@univerjs/core": "0.2.4"
|
|
60
62
|
},
|
|
61
63
|
"univerSpace": {
|
|
62
64
|
".": {
|