@univerjs/docs 0.6.7 → 0.6.8
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/index.js +609 -0
- package/package.json +4 -4
package/lib/index.js
ADDED
|
@@ -0,0 +1,609 @@
|
|
|
1
|
+
var ie = Object.defineProperty;
|
|
2
|
+
var re = (i, e, t) => e in i ? ie(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
3
|
+
var u = (i, e, t) => re(i, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { CommandType as P, RxDisposable as V, UniverInstanceType as y, ICommandService as B, IUniverInstanceService as I, Inject as w, LocaleService as oe, isInternalEditorID as ce, JSONX as x, Disposable as Q, BuildTextUtils as C, Injector as ae, IConfigService as le, Plugin as ue, merge as de, createInterceptorKey as Z, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as ge, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY as he, DisposableCollection as U, toDisposable as _e, remove as fe, composeInterceptors as Se } from "@univerjs/core";
|
|
5
|
+
import { NORMAL_TEXT_SELECTION_PLUGIN_STYLE as Ie, DocumentSkeleton as pe, DocumentViewModel as me, IRenderManagerService as Re } from "@univerjs/engine-render";
|
|
6
|
+
import { Subject as ve, BehaviorSubject as O, takeUntil as ee } from "rxjs";
|
|
7
|
+
const k = {
|
|
8
|
+
id: "doc.operation.set-selections",
|
|
9
|
+
type: P.OPERATION,
|
|
10
|
+
handler: () => !0
|
|
11
|
+
};
|
|
12
|
+
var xe = Object.getOwnPropertyDescriptor, Oe = (i, e, t, n) => {
|
|
13
|
+
for (var s = n > 1 ? void 0 : n ? xe(e, t) : e, r = i.length - 1, o; r >= 0; r--)
|
|
14
|
+
(o = i[r]) && (s = o(s) || s);
|
|
15
|
+
return s;
|
|
16
|
+
}, F = (i, e) => (t, n) => e(t, n, i);
|
|
17
|
+
let m = class extends V {
|
|
18
|
+
constructor(e, t) {
|
|
19
|
+
super();
|
|
20
|
+
u(this, "_currentSelection", null);
|
|
21
|
+
u(this, "_textSelectionInfo", /* @__PURE__ */ new Map());
|
|
22
|
+
u(this, "_textSelection$", new ve());
|
|
23
|
+
u(this, "textSelection$", this._textSelection$.asObservable());
|
|
24
|
+
u(this, "_refreshSelection$", new O(null));
|
|
25
|
+
u(this, "refreshSelection$", this._refreshSelection$.asObservable());
|
|
26
|
+
this._commandService = e, this._univerInstanceService = t, this._listenCurrentUnit();
|
|
27
|
+
}
|
|
28
|
+
_listenCurrentUnit() {
|
|
29
|
+
this._univerInstanceService.getCurrentTypeOfUnit$(y.UNIVER_DOC).pipe(ee(this.dispose$)).subscribe((e) => {
|
|
30
|
+
if (e == null)
|
|
31
|
+
return;
|
|
32
|
+
const t = e.getUnitId();
|
|
33
|
+
this._setCurrentSelectionNotRefresh({
|
|
34
|
+
unitId: t,
|
|
35
|
+
subUnitId: t
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
__getCurrentSelection() {
|
|
40
|
+
return this._currentSelection;
|
|
41
|
+
}
|
|
42
|
+
getSelectionInfo(e = this._currentSelection) {
|
|
43
|
+
return this._getTextRanges(e);
|
|
44
|
+
}
|
|
45
|
+
refreshSelection(e = this._currentSelection) {
|
|
46
|
+
e != null && this._refresh(e);
|
|
47
|
+
}
|
|
48
|
+
// **Only used in test case** because this does not go through the render layer.
|
|
49
|
+
__TEST_ONLY_setCurrentSelection(e) {
|
|
50
|
+
this._currentSelection = e, this._refresh(e);
|
|
51
|
+
}
|
|
52
|
+
getTextRanges(e = this._currentSelection) {
|
|
53
|
+
var t;
|
|
54
|
+
return (t = this._getTextRanges(e)) == null ? void 0 : t.textRanges;
|
|
55
|
+
}
|
|
56
|
+
getRectRanges(e = this._currentSelection) {
|
|
57
|
+
var t;
|
|
58
|
+
return (t = this._getTextRanges(e)) == null ? void 0 : t.rectRanges;
|
|
59
|
+
}
|
|
60
|
+
getDocRanges(e = this._currentSelection) {
|
|
61
|
+
var r, o;
|
|
62
|
+
const t = (r = this.getTextRanges(e)) != null ? r : [], n = (o = this.getRectRanges(e)) != null ? o : [];
|
|
63
|
+
return [...t, ...n].filter((c) => c.startOffset != null && c.endOffset != null).sort((c, a) => c.startOffset > a.startOffset ? 1 : c.startOffset < a.startOffset ? -1 : 0);
|
|
64
|
+
}
|
|
65
|
+
getActiveTextRange() {
|
|
66
|
+
const e = this._getTextRanges(this._currentSelection);
|
|
67
|
+
if (e == null)
|
|
68
|
+
return;
|
|
69
|
+
const { textRanges: t } = e;
|
|
70
|
+
return t.find((n) => n.isActive);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
*
|
|
74
|
+
* @deprecated
|
|
75
|
+
*/
|
|
76
|
+
getActiveRectRange() {
|
|
77
|
+
const e = this._getTextRanges(this._currentSelection);
|
|
78
|
+
if (e == null)
|
|
79
|
+
return;
|
|
80
|
+
const { rectRanges: t } = e;
|
|
81
|
+
return t.find((n) => n.isActive);
|
|
82
|
+
}
|
|
83
|
+
// **Only used in test case** because this does not go through the render layer.
|
|
84
|
+
__TEST_ONLY_add(e, t = !0) {
|
|
85
|
+
this._currentSelection != null && this._addByParam({
|
|
86
|
+
...this._currentSelection,
|
|
87
|
+
textRanges: e,
|
|
88
|
+
rectRanges: [],
|
|
89
|
+
segmentId: "",
|
|
90
|
+
segmentPage: -1,
|
|
91
|
+
isEditing: t,
|
|
92
|
+
style: Ie
|
|
93
|
+
// mock style.
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
// Use to replace the current editor selection.
|
|
97
|
+
/**
|
|
98
|
+
* @deprecated pls use replaceDocRanges.
|
|
99
|
+
*/
|
|
100
|
+
replaceTextRanges(e, t = !0, n) {
|
|
101
|
+
return this.replaceDocRanges(
|
|
102
|
+
e,
|
|
103
|
+
this._currentSelection,
|
|
104
|
+
t,
|
|
105
|
+
n
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
replaceDocRanges(e, t = this._currentSelection, n = !0, s) {
|
|
109
|
+
if (t == null)
|
|
110
|
+
return;
|
|
111
|
+
const { unitId: r, subUnitId: o } = t;
|
|
112
|
+
this._refreshSelection$.next({
|
|
113
|
+
unitId: r,
|
|
114
|
+
subUnitId: o,
|
|
115
|
+
docRanges: e,
|
|
116
|
+
isEditing: n,
|
|
117
|
+
options: s
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
// Only use in doc-selection-render.controller.ts
|
|
121
|
+
__replaceTextRangesWithNoRefresh(e, t) {
|
|
122
|
+
if (this._currentSelection == null)
|
|
123
|
+
return;
|
|
124
|
+
const n = {
|
|
125
|
+
...e,
|
|
126
|
+
...t
|
|
127
|
+
};
|
|
128
|
+
this._replaceByParam(n), this._textSelection$.next(n);
|
|
129
|
+
const { unitId: s, subUnitId: r, segmentId: o, style: c, textRanges: a, rectRanges: l, isEditing: d } = n, h = [...a, ...l].filter((g) => g.startOffset != null && g.endOffset != null).sort((g, _) => g.startOffset > _.startOffset ? 1 : g.startOffset < _.startOffset ? -1 : 0);
|
|
130
|
+
this._commandService.executeCommand(k.id, {
|
|
131
|
+
unitId: s,
|
|
132
|
+
subUnitId: r,
|
|
133
|
+
segmentId: o,
|
|
134
|
+
style: c,
|
|
135
|
+
isEditing: d,
|
|
136
|
+
ranges: h
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
dispose() {
|
|
140
|
+
this._textSelection$.complete();
|
|
141
|
+
}
|
|
142
|
+
_setCurrentSelectionNotRefresh(e) {
|
|
143
|
+
this._currentSelection = e;
|
|
144
|
+
}
|
|
145
|
+
_getTextRanges(e) {
|
|
146
|
+
var s;
|
|
147
|
+
if (e == null)
|
|
148
|
+
return;
|
|
149
|
+
const { unitId: t, subUnitId: n = "" } = e;
|
|
150
|
+
return (s = this._textSelectionInfo.get(t)) == null ? void 0 : s.get(n);
|
|
151
|
+
}
|
|
152
|
+
_refresh(e) {
|
|
153
|
+
const t = this._getTextRanges(e);
|
|
154
|
+
if (t == null)
|
|
155
|
+
return;
|
|
156
|
+
const { textRanges: n, rectRanges: s } = t, r = [...n, ...s], { unitId: o, subUnitId: c } = e;
|
|
157
|
+
this._refreshSelection$.next({
|
|
158
|
+
unitId: o,
|
|
159
|
+
subUnitId: c,
|
|
160
|
+
docRanges: r,
|
|
161
|
+
isEditing: !1
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
_replaceByParam(e) {
|
|
165
|
+
const { unitId: t, subUnitId: n, ...s } = e;
|
|
166
|
+
this._textSelectionInfo.has(t) || this._textSelectionInfo.set(t, /* @__PURE__ */ new Map()), this._textSelectionInfo.get(t).set(n, { ...s });
|
|
167
|
+
}
|
|
168
|
+
_addByParam(e) {
|
|
169
|
+
const { unitId: t, subUnitId: n, ...s } = e;
|
|
170
|
+
this._textSelectionInfo.has(t) || this._textSelectionInfo.set(t, /* @__PURE__ */ new Map());
|
|
171
|
+
const r = this._textSelectionInfo.get(t);
|
|
172
|
+
r.has(n) ? r.get(n).textRanges.push(...e.textRanges) : r.set(n, { ...s });
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
m = Oe([
|
|
176
|
+
F(0, B),
|
|
177
|
+
F(1, I)
|
|
178
|
+
], m);
|
|
179
|
+
var Ce = Object.getOwnPropertyDescriptor, Me = (i, e, t, n) => {
|
|
180
|
+
for (var s = n > 1 ? void 0 : n ? Ce(e, t) : e, r = i.length - 1, o; r >= 0; r--)
|
|
181
|
+
(o = i[r]) && (s = o(s) || s);
|
|
182
|
+
return s;
|
|
183
|
+
}, W = (i, e) => (t, n) => e(t, n, i);
|
|
184
|
+
let D = class extends V {
|
|
185
|
+
constructor(e, t, n) {
|
|
186
|
+
super();
|
|
187
|
+
u(this, "_skeleton");
|
|
188
|
+
u(this, "_docViewModel");
|
|
189
|
+
u(this, "_currentSkeleton$", new O(null));
|
|
190
|
+
u(this, "currentSkeleton$", this._currentSkeleton$.asObservable());
|
|
191
|
+
// CurrentSkeletonBefore for pre-triggered logic during registration
|
|
192
|
+
u(this, "_currentSkeletonBefore$", new O(null));
|
|
193
|
+
u(this, "currentSkeletonBefore$", this._currentSkeletonBefore$.asObservable());
|
|
194
|
+
u(this, "_currentViewModel$", new O(null));
|
|
195
|
+
u(this, "currentViewModel$", this._currentViewModel$.asObservable());
|
|
196
|
+
this._context = e, this._localeService = t, this._univerInstanceService = n, this._init(), this._univerInstanceService.getCurrentTypeOfUnit$(y.UNIVER_DOC).pipe(ee(this.dispose$)).subscribe((s) => {
|
|
197
|
+
s && s.getUnitId() === this._context.unitId && this._update(s);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
dispose() {
|
|
201
|
+
super.dispose(), this._currentSkeletonBefore$.complete(), this._currentSkeleton$.complete();
|
|
202
|
+
}
|
|
203
|
+
getSkeleton() {
|
|
204
|
+
return this._skeleton;
|
|
205
|
+
}
|
|
206
|
+
getViewModel() {
|
|
207
|
+
return this._docViewModel;
|
|
208
|
+
}
|
|
209
|
+
_init() {
|
|
210
|
+
const e = this._context.unit;
|
|
211
|
+
this._update(e);
|
|
212
|
+
}
|
|
213
|
+
_update(e) {
|
|
214
|
+
const t = this._context.unitId;
|
|
215
|
+
if (e.getBody() == null)
|
|
216
|
+
return;
|
|
217
|
+
this._docViewModel && ce(t) ? (this._docViewModel.reset(e), this._context.unit = e) : this._docViewModel || (this._docViewModel = this._buildDocViewModel(e)), this._skeleton || (this._skeleton = this._buildSkeleton(this._docViewModel));
|
|
218
|
+
const n = this._skeleton;
|
|
219
|
+
n.calculate(), this._currentSkeletonBefore$.next(n), this._currentSkeleton$.next(n), this._currentViewModel$.next(this._docViewModel);
|
|
220
|
+
}
|
|
221
|
+
_buildSkeleton(e) {
|
|
222
|
+
return pe.create(e, this._localeService);
|
|
223
|
+
}
|
|
224
|
+
_buildDocViewModel(e) {
|
|
225
|
+
return new me(e);
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
D = Me([
|
|
229
|
+
W(1, w(oe)),
|
|
230
|
+
W(2, I)
|
|
231
|
+
], D);
|
|
232
|
+
class te extends V {
|
|
233
|
+
constructor() {
|
|
234
|
+
super();
|
|
235
|
+
u(this, "_docStateChangeParams$", new O(null));
|
|
236
|
+
u(this, "docStateChangeParams$", this._docStateChangeParams$.asObservable());
|
|
237
|
+
}
|
|
238
|
+
emitStateChangeInfo(t) {
|
|
239
|
+
this._docStateChangeParams$.next(t);
|
|
240
|
+
}
|
|
241
|
+
dispose() {
|
|
242
|
+
super.dispose(), this._docStateChangeParams$.complete();
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const Y = "doc.mutation.rich-text-editing", M = {
|
|
246
|
+
id: Y,
|
|
247
|
+
type: P.MUTATION,
|
|
248
|
+
// eslint-disable-next-line max-lines-per-function
|
|
249
|
+
handler: (i, e) => {
|
|
250
|
+
var G, z;
|
|
251
|
+
const {
|
|
252
|
+
unitId: t,
|
|
253
|
+
segmentId: n = "",
|
|
254
|
+
actions: s,
|
|
255
|
+
textRanges: r,
|
|
256
|
+
prevTextRanges: o,
|
|
257
|
+
trigger: c,
|
|
258
|
+
noHistory: a,
|
|
259
|
+
isCompositionEnd: l,
|
|
260
|
+
noNeedSetTextRange: d,
|
|
261
|
+
debounce: h,
|
|
262
|
+
isEditing: g = !0,
|
|
263
|
+
isSync: _,
|
|
264
|
+
syncer: f
|
|
265
|
+
} = e, R = i.get(I), p = i.get(Re), v = i.get(te), S = R.getUniverDocInstance(t), j = (G = p.getRenderById(t)) == null ? void 0 : G.with(D).getViewModel();
|
|
266
|
+
if (S == null || j == null)
|
|
267
|
+
throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${t}`);
|
|
268
|
+
const L = i.get(m), b = (z = L.getDocRanges()) != null ? z : [], ne = !!S.getSnapshot().disabled;
|
|
269
|
+
if (x.isNoop(s) || s && s.length === 0 || ne)
|
|
270
|
+
return {
|
|
271
|
+
unitId: t,
|
|
272
|
+
actions: [],
|
|
273
|
+
textRanges: b
|
|
274
|
+
};
|
|
275
|
+
const X = x.invertWithDoc(s, S.getSnapshot());
|
|
276
|
+
S.apply(s), j.reset(S), !d && r && c != null && !_ && queueMicrotask(() => {
|
|
277
|
+
L.replaceDocRanges(r, { unitId: t, subUnitId: t }, g, e.options);
|
|
278
|
+
});
|
|
279
|
+
const se = {
|
|
280
|
+
commandId: Y,
|
|
281
|
+
unitId: t,
|
|
282
|
+
segmentId: n,
|
|
283
|
+
trigger: c,
|
|
284
|
+
noHistory: a,
|
|
285
|
+
debounce: h,
|
|
286
|
+
redoState: {
|
|
287
|
+
actions: s,
|
|
288
|
+
textRanges: r
|
|
289
|
+
},
|
|
290
|
+
undoState: {
|
|
291
|
+
actions: X,
|
|
292
|
+
textRanges: o != null ? o : b
|
|
293
|
+
},
|
|
294
|
+
isCompositionEnd: l,
|
|
295
|
+
isSync: _,
|
|
296
|
+
syncer: f
|
|
297
|
+
};
|
|
298
|
+
return v.emitStateChangeInfo(se), {
|
|
299
|
+
unitId: t,
|
|
300
|
+
actions: X,
|
|
301
|
+
textRanges: b
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
}, De = {
|
|
305
|
+
id: "doc.mutation.rename-doc",
|
|
306
|
+
type: P.MUTATION,
|
|
307
|
+
handler: (i, e) => {
|
|
308
|
+
const n = i.get(I).getUnit(e.unitId, y.UNIVER_DOC);
|
|
309
|
+
return n ? (n.setName(e.name), !0) : !1;
|
|
310
|
+
}
|
|
311
|
+
}, Te = "docs.config", K = {};
|
|
312
|
+
var ye = Object.getOwnPropertyDescriptor, we = (i, e, t, n) => {
|
|
313
|
+
for (var s = n > 1 ? void 0 : n ? ye(e, t) : e, r = i.length - 1, o; r >= 0; r--)
|
|
314
|
+
(o = i[r]) && (s = o(s) || s);
|
|
315
|
+
return s;
|
|
316
|
+
}, E = (i, e) => (t, n) => e(t, n, i);
|
|
317
|
+
let T = class extends Q {
|
|
318
|
+
constructor(i, e, t) {
|
|
319
|
+
super(), this._commandService = i, this._textSelectionManagerService = e, this._univerInstanceService = t, this._initSelectionChange();
|
|
320
|
+
}
|
|
321
|
+
_transformCustomRange(i, e) {
|
|
322
|
+
var o;
|
|
323
|
+
const { startOffset: t, endOffset: n, collapsed: s } = e, r = (o = i.getCustomRanges()) == null ? void 0 : o.filter((c) => !c.wholeEntity || t <= c.startIndex && n > c.endIndex ? !1 : s ? c.startIndex < t && c.endIndex >= n : C.range.isIntersects(t, n - 1, c.startIndex, c.endIndex));
|
|
324
|
+
if (r != null && r.length) {
|
|
325
|
+
let c = t, a = n;
|
|
326
|
+
return r.forEach((l) => {
|
|
327
|
+
c = Math.min(l.startIndex, c), a = Math.max(l.endIndex + 1, a);
|
|
328
|
+
}), {
|
|
329
|
+
...e,
|
|
330
|
+
startOffset: c,
|
|
331
|
+
endOffset: a,
|
|
332
|
+
collapsed: c === a
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
return e;
|
|
336
|
+
}
|
|
337
|
+
_initSelectionChange() {
|
|
338
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((i) => {
|
|
339
|
+
if (i.id === k.id) {
|
|
340
|
+
const e = i.params, { unitId: t, ranges: n, isEditing: s } = e, r = this._univerInstanceService.getUnit(t);
|
|
341
|
+
if (!r)
|
|
342
|
+
return;
|
|
343
|
+
const o = n.map((c) => this._transformCustomRange(r, c));
|
|
344
|
+
o.some((c, a) => n[a] !== c) && this._textSelectionManagerService.replaceTextRanges(o, s);
|
|
345
|
+
}
|
|
346
|
+
}));
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
T = we([
|
|
350
|
+
E(0, B),
|
|
351
|
+
E(1, w(m)),
|
|
352
|
+
E(2, I)
|
|
353
|
+
], T);
|
|
354
|
+
var be = Object.getOwnPropertyDescriptor, Ue = (i, e, t, n) => {
|
|
355
|
+
for (var s = n > 1 ? void 0 : n ? be(e, t) : e, r = i.length - 1, o; r >= 0; r--)
|
|
356
|
+
(o = i[r]) && (s = o(s) || s);
|
|
357
|
+
return s;
|
|
358
|
+
}, H = (i, e) => (t, n) => e(t, n, i);
|
|
359
|
+
const Ee = "DOCS_PLUGIN";
|
|
360
|
+
var N;
|
|
361
|
+
let q = (N = class extends ue {
|
|
362
|
+
// static override type = UniverInstanceType.UNIVER_DOC;
|
|
363
|
+
constructor(i = K, e, t) {
|
|
364
|
+
super(), this._config = i, this._injector = e, this._configService = t;
|
|
365
|
+
const { ...n } = de(
|
|
366
|
+
{},
|
|
367
|
+
K,
|
|
368
|
+
this._config
|
|
369
|
+
);
|
|
370
|
+
this._configService.setConfig(Te, n);
|
|
371
|
+
}
|
|
372
|
+
onStarting() {
|
|
373
|
+
this._initializeDependencies(), this._initializeCommands();
|
|
374
|
+
}
|
|
375
|
+
_initializeCommands() {
|
|
376
|
+
[
|
|
377
|
+
M,
|
|
378
|
+
De,
|
|
379
|
+
k
|
|
380
|
+
].forEach((i) => {
|
|
381
|
+
this._injector.get(B).registerCommand(i);
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
_initializeDependencies() {
|
|
385
|
+
[
|
|
386
|
+
[m],
|
|
387
|
+
[te],
|
|
388
|
+
[T]
|
|
389
|
+
].forEach((i) => this._injector.add(i));
|
|
390
|
+
}
|
|
391
|
+
onReady() {
|
|
392
|
+
this._injector.get(T);
|
|
393
|
+
}
|
|
394
|
+
}, u(N, "pluginName", Ee), N);
|
|
395
|
+
q = Ue([
|
|
396
|
+
H(1, w(ae)),
|
|
397
|
+
H(2, le)
|
|
398
|
+
], q);
|
|
399
|
+
const $e = Z("CUSTOM_RANGE"), Ne = Z("CUSTOM_DECORATION"), $ = {
|
|
400
|
+
CUSTOM_RANGE: $e,
|
|
401
|
+
CUSTOM_DECORATION: Ne
|
|
402
|
+
};
|
|
403
|
+
var Pe = Object.getOwnPropertyDescriptor, Ve = (i, e, t, n) => {
|
|
404
|
+
for (var s = n > 1 ? void 0 : n ? Pe(e, t) : e, r = i.length - 1, o; r >= 0; r--)
|
|
405
|
+
(o = i[r]) && (s = o(s) || s);
|
|
406
|
+
return s;
|
|
407
|
+
}, Be = (i, e) => (t, n) => e(t, n, i);
|
|
408
|
+
let J = class extends Q {
|
|
409
|
+
constructor(e, t) {
|
|
410
|
+
super();
|
|
411
|
+
u(this, "_interceptorsByName", /* @__PURE__ */ new Map());
|
|
412
|
+
this._context = e, this._docSkeletonManagerService = t;
|
|
413
|
+
const n = this._docSkeletonManagerService.getViewModel(), s = n.getDataModel().getUnitId();
|
|
414
|
+
if (s === ge || s === he)
|
|
415
|
+
return;
|
|
416
|
+
this.disposeWithMe(this.interceptDocumentViewModel(n)), this.disposeWithMe(this.intercept($.CUSTOM_RANGE, {
|
|
417
|
+
priority: -1,
|
|
418
|
+
handler: (o, c, a) => a(o)
|
|
419
|
+
}));
|
|
420
|
+
let r = new U();
|
|
421
|
+
n.segmentViewModels$.subscribe((o) => {
|
|
422
|
+
r.dispose(), r = new U(), o.forEach((c) => {
|
|
423
|
+
r.add(this.interceptDocumentViewModel(c));
|
|
424
|
+
});
|
|
425
|
+
}), this.disposeWithMe(r);
|
|
426
|
+
}
|
|
427
|
+
intercept(e, t) {
|
|
428
|
+
const n = e;
|
|
429
|
+
this._interceptorsByName.has(n) || this._interceptorsByName.set(n, []);
|
|
430
|
+
const s = this._interceptorsByName.get(n);
|
|
431
|
+
return s.push(t), this._interceptorsByName.set(
|
|
432
|
+
n,
|
|
433
|
+
s.sort((r, o) => {
|
|
434
|
+
var c, a;
|
|
435
|
+
return ((c = o.priority) != null ? c : 0) - ((a = r.priority) != null ? a : 0);
|
|
436
|
+
})
|
|
437
|
+
), this.disposeWithMe(_e(() => fe(this._interceptorsByName.get(n), t)));
|
|
438
|
+
}
|
|
439
|
+
fetchThroughInterceptors(e) {
|
|
440
|
+
const t = e, n = this._interceptorsByName.get(t);
|
|
441
|
+
return Se(n || []);
|
|
442
|
+
}
|
|
443
|
+
interceptDocumentViewModel(e) {
|
|
444
|
+
const t = new U();
|
|
445
|
+
return t.add(e.registerCustomRangeInterceptor({
|
|
446
|
+
getCustomRange: (n) => {
|
|
447
|
+
var s;
|
|
448
|
+
return this.fetchThroughInterceptors($.CUSTOM_RANGE)(
|
|
449
|
+
e.getCustomRangeRaw(n),
|
|
450
|
+
{
|
|
451
|
+
index: n,
|
|
452
|
+
unitId: e.getDataModel().getUnitId(),
|
|
453
|
+
customRanges: (s = e.getDataModel().getCustomRanges()) != null ? s : []
|
|
454
|
+
}
|
|
455
|
+
);
|
|
456
|
+
},
|
|
457
|
+
getCustomDecoration: (n) => {
|
|
458
|
+
var s;
|
|
459
|
+
return this.fetchThroughInterceptors($.CUSTOM_DECORATION)(
|
|
460
|
+
e.getCustomDecorationRaw(n),
|
|
461
|
+
{
|
|
462
|
+
index: n,
|
|
463
|
+
unitId: e.getDataModel().getUnitId(),
|
|
464
|
+
customDecorations: (s = e.getDataModel().getCustomDecorations()) != null ? s : []
|
|
465
|
+
}
|
|
466
|
+
);
|
|
467
|
+
}
|
|
468
|
+
})), t;
|
|
469
|
+
}
|
|
470
|
+
};
|
|
471
|
+
J = Ve([
|
|
472
|
+
Be(1, w(D))
|
|
473
|
+
], J);
|
|
474
|
+
function A(i, e = "") {
|
|
475
|
+
if (!e)
|
|
476
|
+
return ["body"];
|
|
477
|
+
const { headers: t, footers: n } = i.getSnapshot();
|
|
478
|
+
if (t == null && n == null)
|
|
479
|
+
throw new Error("Document data model must have headers or footers when update by segment id");
|
|
480
|
+
if ((t == null ? void 0 : t[e]) != null)
|
|
481
|
+
return ["headers", e, "body"];
|
|
482
|
+
if ((n == null ? void 0 : n[e]) != null)
|
|
483
|
+
return ["footers", e, "body"];
|
|
484
|
+
throw new Error("Segment id not found in headers or footers");
|
|
485
|
+
}
|
|
486
|
+
function Xe(i, e, t) {
|
|
487
|
+
const { unitId: n, segmentId: s } = e, o = i.get(I).getUnit(n);
|
|
488
|
+
if (!o)
|
|
489
|
+
return !1;
|
|
490
|
+
const c = {
|
|
491
|
+
id: M.id,
|
|
492
|
+
params: {
|
|
493
|
+
unitId: e.unitId,
|
|
494
|
+
actions: [],
|
|
495
|
+
textRanges: void 0
|
|
496
|
+
}
|
|
497
|
+
}, a = x.getInstance(), l = C.customRange.add({ ...e, body: t });
|
|
498
|
+
if (!l)
|
|
499
|
+
return !1;
|
|
500
|
+
const d = A(o, s);
|
|
501
|
+
return c.params.actions = a.editOp(l.serialize(), d), c;
|
|
502
|
+
}
|
|
503
|
+
function Ge(i, e) {
|
|
504
|
+
var S;
|
|
505
|
+
const { rangeId: t, rangeType: n, wholeEntity: s, properties: r, unitId: o, selections: c } = e, a = i.get(m), l = i.get(I), d = c != null ? c : a.getTextRanges({ unitId: o, subUnitId: o }), h = (S = d == null ? void 0 : d[0]) == null ? void 0 : S.segmentId;
|
|
506
|
+
if (!(d != null && d.length))
|
|
507
|
+
return !1;
|
|
508
|
+
const g = l.getUnit(o, y.UNIVER_DOC);
|
|
509
|
+
if (!g)
|
|
510
|
+
return !1;
|
|
511
|
+
const _ = g.getSelfOrHeaderFooterModel(h).getBody();
|
|
512
|
+
if (!_)
|
|
513
|
+
return !1;
|
|
514
|
+
const f = C.customRange.add({
|
|
515
|
+
ranges: d,
|
|
516
|
+
rangeId: t,
|
|
517
|
+
rangeType: n,
|
|
518
|
+
segmentId: h,
|
|
519
|
+
wholeEntity: s,
|
|
520
|
+
properties: r,
|
|
521
|
+
body: _
|
|
522
|
+
});
|
|
523
|
+
if (!f)
|
|
524
|
+
return !1;
|
|
525
|
+
const R = x.getInstance(), p = {
|
|
526
|
+
id: M.id,
|
|
527
|
+
params: {
|
|
528
|
+
unitId: o,
|
|
529
|
+
actions: [],
|
|
530
|
+
textRanges: f.selections,
|
|
531
|
+
segmentId: h
|
|
532
|
+
},
|
|
533
|
+
textX: f
|
|
534
|
+
}, v = A(g, h);
|
|
535
|
+
return p.params.actions = R.editOp(f.serialize(), v), p;
|
|
536
|
+
}
|
|
537
|
+
function ze(i, e) {
|
|
538
|
+
const { unitId: t, segmentId: n, insert: s } = e, o = i.get(I).getUnit(t);
|
|
539
|
+
if (!o)
|
|
540
|
+
return !1;
|
|
541
|
+
const c = {
|
|
542
|
+
id: M.id,
|
|
543
|
+
params: {
|
|
544
|
+
unitId: e.unitId,
|
|
545
|
+
actions: [],
|
|
546
|
+
textRanges: void 0,
|
|
547
|
+
segmentId: n
|
|
548
|
+
}
|
|
549
|
+
}, a = x.getInstance(), l = C.customRange.delete({
|
|
550
|
+
documentDataModel: o,
|
|
551
|
+
rangeId: e.rangeId,
|
|
552
|
+
insert: s,
|
|
553
|
+
segmentId: n
|
|
554
|
+
});
|
|
555
|
+
if (!l)
|
|
556
|
+
return !1;
|
|
557
|
+
const d = A(o, n);
|
|
558
|
+
return c.params.actions = a.editOp(l.serialize(), d), c.params.textRanges = l.selections, c;
|
|
559
|
+
}
|
|
560
|
+
function Fe(i, e) {
|
|
561
|
+
var f, R, p, v;
|
|
562
|
+
const { unitId: t, body: n, doc: s } = e;
|
|
563
|
+
let r = s;
|
|
564
|
+
if (r || (r = i.get(I).getUnit(t)), !r)
|
|
565
|
+
return !1;
|
|
566
|
+
const o = (f = e.selection) == null ? void 0 : f.segmentId, c = (R = r.getSelfOrHeaderFooterModel(o)) == null ? void 0 : R.getBody();
|
|
567
|
+
if (!c) return !1;
|
|
568
|
+
const a = i.get(m), l = (p = e.selection) != null ? p : a.getActiveTextRange();
|
|
569
|
+
if (!l || !c)
|
|
570
|
+
return !1;
|
|
571
|
+
const d = (v = e.textRanges) != null ? v : [{
|
|
572
|
+
startOffset: l.startOffset + n.dataStream.length,
|
|
573
|
+
endOffset: l.startOffset + n.dataStream.length,
|
|
574
|
+
collapsed: !0,
|
|
575
|
+
segmentId: o
|
|
576
|
+
}], h = C.selection.replace({
|
|
577
|
+
selection: l,
|
|
578
|
+
body: n,
|
|
579
|
+
doc: r
|
|
580
|
+
});
|
|
581
|
+
if (!h)
|
|
582
|
+
return !1;
|
|
583
|
+
const g = {
|
|
584
|
+
id: M.id,
|
|
585
|
+
params: {
|
|
586
|
+
unitId: t,
|
|
587
|
+
actions: [],
|
|
588
|
+
textRanges: d,
|
|
589
|
+
debounce: !0,
|
|
590
|
+
segmentId: o
|
|
591
|
+
},
|
|
592
|
+
textX: h
|
|
593
|
+
}, _ = x.getInstance();
|
|
594
|
+
return g.params.actions = _.editOp(h.serialize()), g;
|
|
595
|
+
}
|
|
596
|
+
export {
|
|
597
|
+
$ as DOC_INTERCEPTOR_POINT,
|
|
598
|
+
J as DocInterceptorService,
|
|
599
|
+
m as DocSelectionManagerService,
|
|
600
|
+
D as DocSkeletonManagerService,
|
|
601
|
+
te as DocStateEmitService,
|
|
602
|
+
M as RichTextEditingMutation,
|
|
603
|
+
k as SetTextSelectionsOperation,
|
|
604
|
+
q as UniverDocsPlugin,
|
|
605
|
+
Ge as addCustomRangeBySelectionFactory,
|
|
606
|
+
Xe as addCustomRangeFactory,
|
|
607
|
+
ze as deleteCustomRangeFactory,
|
|
608
|
+
Fe as replaceSelectionFactory
|
|
609
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/docs",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.8",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "UniverSheet normal base-docs",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -48,15 +48,15 @@
|
|
|
48
48
|
"rxjs": ">=7.0.0"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@univerjs/
|
|
52
|
-
"@univerjs/
|
|
51
|
+
"@univerjs/core": "0.6.8",
|
|
52
|
+
"@univerjs/engine-render": "0.6.8"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"rxjs": "^7.8.1",
|
|
56
56
|
"typescript": "^5.8.2",
|
|
57
57
|
"vite": "^6.2.3",
|
|
58
58
|
"vitest": "^3.0.9",
|
|
59
|
-
"@univerjs-infra/shared": "0.6.
|
|
59
|
+
"@univerjs-infra/shared": "0.6.8"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"test": "vitest run",
|