@univerjs/docs 0.5.4 → 0.5.5-experimental.20250122-3362a4a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +435 -427
- package/lib/umd/index.js +1 -1
- package/package.json +4 -4
- package/LICENSE +0 -176
package/lib/es/index.js
CHANGED
|
@@ -1,95 +1,96 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
5
|
+
import { CommandType, RxDisposable, UniverInstanceType, ICommandService, IUniverInstanceService, Inject, LocaleService, isInternalEditorID, JSONX, Disposable, BuildTextUtils, Injector, Plugin, merge, IConfigService, createInterceptorKey, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DisposableCollection, toDisposable, remove, composeInterceptors } from "@univerjs/core";
|
|
6
|
+
import { NORMAL_TEXT_SELECTION_PLUGIN_STYLE, DocumentSkeleton, DocumentViewModel, IRenderManagerService } from "@univerjs/engine-render";
|
|
7
|
+
import { Subject, BehaviorSubject, takeUntil } from "rxjs";
|
|
8
|
+
const SetTextSelectionsOperation = {
|
|
8
9
|
id: "doc.operation.set-selections",
|
|
9
|
-
type:
|
|
10
|
-
handler: () => !0
|
|
10
|
+
type: CommandType.OPERATION,
|
|
11
|
+
handler: /* @__PURE__ */ __name(() => !0, "handler")
|
|
11
12
|
};
|
|
12
|
-
var
|
|
13
|
-
for (var
|
|
14
|
-
(
|
|
15
|
-
return
|
|
16
|
-
},
|
|
17
|
-
let
|
|
18
|
-
constructor(
|
|
13
|
+
var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
14
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
15
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
16
|
+
return kind && result && __defProp$4(target, key, result), result;
|
|
17
|
+
}, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a;
|
|
18
|
+
let DocSelectionManagerService = (_a = class extends RxDisposable {
|
|
19
|
+
constructor(_commandService, _univerInstanceService) {
|
|
19
20
|
super();
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
this._commandService =
|
|
21
|
+
__publicField(this, "_currentSelection", null);
|
|
22
|
+
__publicField(this, "_textSelectionInfo", /* @__PURE__ */ new Map());
|
|
23
|
+
__publicField(this, "_textSelection$", new Subject());
|
|
24
|
+
__publicField(this, "textSelection$", this._textSelection$.asObservable());
|
|
25
|
+
__publicField(this, "_refreshSelection$", new BehaviorSubject(null));
|
|
26
|
+
__publicField(this, "refreshSelection$", this._refreshSelection$.asObservable());
|
|
27
|
+
this._commandService = _commandService, this._univerInstanceService = _univerInstanceService, this._listenCurrentUnit();
|
|
27
28
|
}
|
|
28
29
|
_listenCurrentUnit() {
|
|
29
|
-
this._univerInstanceService.getCurrentTypeOfUnit$(
|
|
30
|
-
if (
|
|
30
|
+
this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC).pipe(takeUntil(this.dispose$)).subscribe((documentModel) => {
|
|
31
|
+
if (documentModel == null)
|
|
31
32
|
return;
|
|
32
|
-
const
|
|
33
|
+
const unitId = documentModel.getUnitId();
|
|
33
34
|
this._setCurrentSelectionNotRefresh({
|
|
34
|
-
unitId
|
|
35
|
-
subUnitId:
|
|
35
|
+
unitId,
|
|
36
|
+
subUnitId: unitId
|
|
36
37
|
});
|
|
37
38
|
});
|
|
38
39
|
}
|
|
39
40
|
__getCurrentSelection() {
|
|
40
41
|
return this._currentSelection;
|
|
41
42
|
}
|
|
42
|
-
getSelectionInfo(
|
|
43
|
-
return this._getTextRanges(
|
|
43
|
+
getSelectionInfo(params = this._currentSelection) {
|
|
44
|
+
return this._getTextRanges(params);
|
|
44
45
|
}
|
|
45
|
-
refreshSelection(
|
|
46
|
-
|
|
46
|
+
refreshSelection(params = this._currentSelection) {
|
|
47
|
+
params != null && this._refresh(params);
|
|
47
48
|
}
|
|
48
49
|
// **Only used in test case** because this does not go through the render layer.
|
|
49
|
-
__TEST_ONLY_setCurrentSelection(
|
|
50
|
-
this._currentSelection =
|
|
50
|
+
__TEST_ONLY_setCurrentSelection(param) {
|
|
51
|
+
this._currentSelection = param, this._refresh(param);
|
|
51
52
|
}
|
|
52
|
-
getTextRanges(
|
|
53
|
-
var
|
|
54
|
-
return (
|
|
53
|
+
getTextRanges(params = this._currentSelection) {
|
|
54
|
+
var _a6;
|
|
55
|
+
return (_a6 = this._getTextRanges(params)) == null ? void 0 : _a6.textRanges;
|
|
55
56
|
}
|
|
56
|
-
getRectRanges(
|
|
57
|
-
var
|
|
58
|
-
return (
|
|
57
|
+
getRectRanges(params = this._currentSelection) {
|
|
58
|
+
var _a6;
|
|
59
|
+
return (_a6 = this._getTextRanges(params)) == null ? void 0 : _a6.rectRanges;
|
|
59
60
|
}
|
|
60
|
-
getDocRanges(
|
|
61
|
-
var
|
|
62
|
-
const
|
|
63
|
-
return [...
|
|
61
|
+
getDocRanges(params = this._currentSelection) {
|
|
62
|
+
var _a6, _b;
|
|
63
|
+
const textRanges = (_a6 = this.getTextRanges(params)) != null ? _a6 : [], rectRanges = (_b = this.getRectRanges(params)) != null ? _b : [];
|
|
64
|
+
return [...textRanges, ...rectRanges].filter((range) => range.startOffset != null && range.endOffset != null).sort((a, b) => a.startOffset > b.startOffset ? 1 : a.startOffset < b.startOffset ? -1 : 0);
|
|
64
65
|
}
|
|
65
66
|
getActiveTextRange() {
|
|
66
|
-
const
|
|
67
|
-
if (
|
|
67
|
+
const selectionInfo = this._getTextRanges(this._currentSelection);
|
|
68
|
+
if (selectionInfo == null)
|
|
68
69
|
return;
|
|
69
|
-
const { textRanges
|
|
70
|
-
return
|
|
70
|
+
const { textRanges } = selectionInfo;
|
|
71
|
+
return textRanges.find((textRange) => textRange.isActive);
|
|
71
72
|
}
|
|
72
73
|
/**
|
|
73
74
|
*
|
|
74
75
|
* @deprecated
|
|
75
76
|
*/
|
|
76
77
|
getActiveRectRange() {
|
|
77
|
-
const
|
|
78
|
-
if (
|
|
78
|
+
const selectionInfo = this._getTextRanges(this._currentSelection);
|
|
79
|
+
if (selectionInfo == null)
|
|
79
80
|
return;
|
|
80
|
-
const { rectRanges
|
|
81
|
-
return
|
|
81
|
+
const { rectRanges } = selectionInfo;
|
|
82
|
+
return rectRanges.find((rectRange) => rectRange.isActive);
|
|
82
83
|
}
|
|
83
84
|
// **Only used in test case** because this does not go through the render layer.
|
|
84
|
-
__TEST_ONLY_add(
|
|
85
|
+
__TEST_ONLY_add(textRanges, isEditing = !0) {
|
|
85
86
|
this._currentSelection != null && this._addByParam({
|
|
86
87
|
...this._currentSelection,
|
|
87
|
-
textRanges
|
|
88
|
+
textRanges,
|
|
88
89
|
rectRanges: [],
|
|
89
90
|
segmentId: "",
|
|
90
91
|
segmentPage: -1,
|
|
91
|
-
isEditing
|
|
92
|
-
style:
|
|
92
|
+
isEditing,
|
|
93
|
+
style: NORMAL_TEXT_SELECTION_PLUGIN_STYLE
|
|
93
94
|
// mock style.
|
|
94
95
|
});
|
|
95
96
|
}
|
|
@@ -97,104 +98,104 @@ let m = class extends V {
|
|
|
97
98
|
/**
|
|
98
99
|
* @deprecated pls use replaceDocRanges.
|
|
99
100
|
*/
|
|
100
|
-
replaceTextRanges(
|
|
101
|
+
replaceTextRanges(docRanges, isEditing = !0, options) {
|
|
101
102
|
return this.replaceDocRanges(
|
|
102
|
-
|
|
103
|
+
docRanges,
|
|
103
104
|
this._currentSelection,
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
isEditing,
|
|
106
|
+
options
|
|
106
107
|
);
|
|
107
108
|
}
|
|
108
|
-
replaceDocRanges(
|
|
109
|
-
if (
|
|
109
|
+
replaceDocRanges(docRanges, params = this._currentSelection, isEditing = !0, options) {
|
|
110
|
+
if (params == null)
|
|
110
111
|
return;
|
|
111
|
-
const { unitId
|
|
112
|
+
const { unitId, subUnitId } = params;
|
|
112
113
|
this._refreshSelection$.next({
|
|
113
|
-
unitId
|
|
114
|
-
subUnitId
|
|
115
|
-
docRanges
|
|
116
|
-
isEditing
|
|
117
|
-
options
|
|
114
|
+
unitId,
|
|
115
|
+
subUnitId,
|
|
116
|
+
docRanges,
|
|
117
|
+
isEditing,
|
|
118
|
+
options
|
|
118
119
|
});
|
|
119
120
|
}
|
|
120
121
|
// Only use in doc-selection-render.controller.ts
|
|
121
|
-
__replaceTextRangesWithNoRefresh(
|
|
122
|
+
__replaceTextRangesWithNoRefresh(textSelectionInfo, search) {
|
|
122
123
|
if (this._currentSelection == null)
|
|
123
124
|
return;
|
|
124
|
-
const
|
|
125
|
-
...
|
|
126
|
-
...
|
|
125
|
+
const params = {
|
|
126
|
+
...textSelectionInfo,
|
|
127
|
+
...search
|
|
127
128
|
};
|
|
128
|
-
this._replaceByParam(
|
|
129
|
-
const { unitId
|
|
130
|
-
this._commandService.executeCommand(
|
|
131
|
-
unitId
|
|
132
|
-
subUnitId
|
|
133
|
-
segmentId
|
|
134
|
-
style
|
|
135
|
-
isEditing
|
|
136
|
-
ranges
|
|
129
|
+
this._replaceByParam(params), this._textSelection$.next(params);
|
|
130
|
+
const { unitId, subUnitId, segmentId, style, textRanges, rectRanges, isEditing } = params, ranges = [...textRanges, ...rectRanges].filter((range) => range.startOffset != null && range.endOffset != null).sort((a, b) => a.startOffset > b.startOffset ? 1 : a.startOffset < b.startOffset ? -1 : 0);
|
|
131
|
+
this._commandService.executeCommand(SetTextSelectionsOperation.id, {
|
|
132
|
+
unitId,
|
|
133
|
+
subUnitId,
|
|
134
|
+
segmentId,
|
|
135
|
+
style,
|
|
136
|
+
isEditing,
|
|
137
|
+
ranges
|
|
137
138
|
});
|
|
138
139
|
}
|
|
139
140
|
dispose() {
|
|
140
141
|
this._textSelection$.complete();
|
|
141
142
|
}
|
|
142
|
-
_setCurrentSelectionNotRefresh(
|
|
143
|
-
this._currentSelection =
|
|
143
|
+
_setCurrentSelectionNotRefresh(param) {
|
|
144
|
+
this._currentSelection = param;
|
|
144
145
|
}
|
|
145
|
-
_getTextRanges(
|
|
146
|
-
var
|
|
147
|
-
if (
|
|
146
|
+
_getTextRanges(param) {
|
|
147
|
+
var _a6;
|
|
148
|
+
if (param == null)
|
|
148
149
|
return;
|
|
149
|
-
const { unitId
|
|
150
|
-
return (
|
|
150
|
+
const { unitId, subUnitId = "" } = param;
|
|
151
|
+
return (_a6 = this._textSelectionInfo.get(unitId)) == null ? void 0 : _a6.get(subUnitId);
|
|
151
152
|
}
|
|
152
|
-
_refresh(
|
|
153
|
-
const
|
|
154
|
-
if (
|
|
153
|
+
_refresh(param) {
|
|
154
|
+
const allTextSelectionInfo = this._getTextRanges(param);
|
|
155
|
+
if (allTextSelectionInfo == null)
|
|
155
156
|
return;
|
|
156
|
-
const { textRanges
|
|
157
|
+
const { textRanges, rectRanges } = allTextSelectionInfo, docRanges = [...textRanges, ...rectRanges], { unitId, subUnitId } = param;
|
|
157
158
|
this._refreshSelection$.next({
|
|
158
|
-
unitId
|
|
159
|
-
subUnitId
|
|
160
|
-
docRanges
|
|
159
|
+
unitId,
|
|
160
|
+
subUnitId,
|
|
161
|
+
docRanges,
|
|
161
162
|
isEditing: !1
|
|
162
163
|
});
|
|
163
164
|
}
|
|
164
|
-
_replaceByParam(
|
|
165
|
-
const { unitId
|
|
166
|
-
this._textSelectionInfo.has(
|
|
167
|
-
}
|
|
168
|
-
_addByParam(
|
|
169
|
-
const { unitId
|
|
170
|
-
this._textSelectionInfo.has(
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
],
|
|
179
|
-
var
|
|
180
|
-
for (var
|
|
181
|
-
(
|
|
182
|
-
return
|
|
183
|
-
},
|
|
184
|
-
let
|
|
185
|
-
constructor(
|
|
165
|
+
_replaceByParam(insertParam) {
|
|
166
|
+
const { unitId, subUnitId, ...selectionInsertParam } = insertParam;
|
|
167
|
+
this._textSelectionInfo.has(unitId) || this._textSelectionInfo.set(unitId, /* @__PURE__ */ new Map()), this._textSelectionInfo.get(unitId).set(subUnitId, { ...selectionInsertParam });
|
|
168
|
+
}
|
|
169
|
+
_addByParam(insertParam) {
|
|
170
|
+
const { unitId, subUnitId, ...selectionInsertParam } = insertParam;
|
|
171
|
+
this._textSelectionInfo.has(unitId) || this._textSelectionInfo.set(unitId, /* @__PURE__ */ new Map());
|
|
172
|
+
const unitTextRange = this._textSelectionInfo.get(unitId);
|
|
173
|
+
unitTextRange.has(subUnitId) ? unitTextRange.get(subUnitId).textRanges.push(...insertParam.textRanges) : unitTextRange.set(subUnitId, { ...selectionInsertParam });
|
|
174
|
+
}
|
|
175
|
+
}, __name(_a, "DocSelectionManagerService"), _a);
|
|
176
|
+
DocSelectionManagerService = __decorateClass$4([
|
|
177
|
+
__decorateParam$4(0, ICommandService),
|
|
178
|
+
__decorateParam$4(1, IUniverInstanceService)
|
|
179
|
+
], DocSelectionManagerService);
|
|
180
|
+
var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
181
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
182
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
183
|
+
return kind && result && __defProp$3(target, key, result), result;
|
|
184
|
+
}, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a2;
|
|
185
|
+
let DocSkeletonManagerService = (_a2 = class extends RxDisposable {
|
|
186
|
+
constructor(_context, _localeService, _univerInstanceService) {
|
|
186
187
|
super();
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
188
|
+
__publicField(this, "_skeleton");
|
|
189
|
+
__publicField(this, "_docViewModel");
|
|
190
|
+
__publicField(this, "_currentSkeleton$", new BehaviorSubject(null));
|
|
191
|
+
__publicField(this, "currentSkeleton$", this._currentSkeleton$.asObservable());
|
|
191
192
|
// CurrentSkeletonBefore for pre-triggered logic during registration
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
this._context =
|
|
197
|
-
|
|
193
|
+
__publicField(this, "_currentSkeletonBefore$", new BehaviorSubject(null));
|
|
194
|
+
__publicField(this, "currentSkeletonBefore$", this._currentSkeletonBefore$.asObservable());
|
|
195
|
+
__publicField(this, "_currentViewModel$", new BehaviorSubject(null));
|
|
196
|
+
__publicField(this, "currentViewModel$", this._currentViewModel$.asObservable());
|
|
197
|
+
this._context = _context, this._localeService = _localeService, this._univerInstanceService = _univerInstanceService, this._init(), this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_DOC).pipe(takeUntil(this.dispose$)).subscribe((documentModel) => {
|
|
198
|
+
documentModel && documentModel.getUnitId() === this._context.unitId && this._update(documentModel);
|
|
198
199
|
});
|
|
199
200
|
}
|
|
200
201
|
dispose() {
|
|
@@ -207,403 +208,410 @@ let D = class extends V {
|
|
|
207
208
|
return this._docViewModel;
|
|
208
209
|
}
|
|
209
210
|
_init() {
|
|
210
|
-
const
|
|
211
|
-
this._update(
|
|
211
|
+
const documentDataModel = this._context.unit;
|
|
212
|
+
this._update(documentDataModel);
|
|
212
213
|
}
|
|
213
|
-
_update(
|
|
214
|
-
const
|
|
215
|
-
if (
|
|
214
|
+
_update(documentDataModel) {
|
|
215
|
+
const unitId = this._context.unitId;
|
|
216
|
+
if (documentDataModel.getBody() == null)
|
|
216
217
|
return;
|
|
217
|
-
this._docViewModel &&
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
}
|
|
221
|
-
_buildSkeleton(
|
|
222
|
-
return
|
|
223
|
-
}
|
|
224
|
-
_buildDocViewModel(
|
|
225
|
-
return new
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
],
|
|
232
|
-
class
|
|
218
|
+
this._docViewModel && isInternalEditorID(unitId) ? (this._docViewModel.reset(documentDataModel), this._context.unit = documentDataModel) : this._docViewModel || (this._docViewModel = this._buildDocViewModel(documentDataModel)), this._skeleton || (this._skeleton = this._buildSkeleton(this._docViewModel));
|
|
219
|
+
const skeleton = this._skeleton;
|
|
220
|
+
skeleton.calculate(), this._currentSkeletonBefore$.next(skeleton), this._currentSkeleton$.next(skeleton), this._currentViewModel$.next(this._docViewModel);
|
|
221
|
+
}
|
|
222
|
+
_buildSkeleton(documentViewModel) {
|
|
223
|
+
return DocumentSkeleton.create(documentViewModel, this._localeService);
|
|
224
|
+
}
|
|
225
|
+
_buildDocViewModel(documentDataModel) {
|
|
226
|
+
return new DocumentViewModel(documentDataModel);
|
|
227
|
+
}
|
|
228
|
+
}, __name(_a2, "DocSkeletonManagerService"), _a2);
|
|
229
|
+
DocSkeletonManagerService = __decorateClass$3([
|
|
230
|
+
__decorateParam$3(1, Inject(LocaleService)),
|
|
231
|
+
__decorateParam$3(2, IUniverInstanceService)
|
|
232
|
+
], DocSkeletonManagerService);
|
|
233
|
+
const _DocStateEmitService = class _DocStateEmitService extends RxDisposable {
|
|
233
234
|
constructor() {
|
|
234
235
|
super();
|
|
235
|
-
|
|
236
|
-
|
|
236
|
+
__publicField(this, "_docStateChangeParams$", new BehaviorSubject(null));
|
|
237
|
+
__publicField(this, "docStateChangeParams$", this._docStateChangeParams$.asObservable());
|
|
237
238
|
}
|
|
238
|
-
emitStateChangeInfo(
|
|
239
|
-
this._docStateChangeParams$.next(
|
|
239
|
+
emitStateChangeInfo(params) {
|
|
240
|
+
this._docStateChangeParams$.next(params);
|
|
240
241
|
}
|
|
241
242
|
dispose() {
|
|
242
243
|
super.dispose(), this._docStateChangeParams$.complete();
|
|
243
244
|
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
245
|
+
};
|
|
246
|
+
__name(_DocStateEmitService, "DocStateEmitService");
|
|
247
|
+
let DocStateEmitService = _DocStateEmitService;
|
|
248
|
+
const RichTextEditingMutationId = "doc.mutation.rich-text-editing", RichTextEditingMutation = {
|
|
249
|
+
id: RichTextEditingMutationId,
|
|
250
|
+
type: CommandType.MUTATION,
|
|
248
251
|
// eslint-disable-next-line max-lines-per-function
|
|
249
|
-
handler: (
|
|
250
|
-
var
|
|
252
|
+
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
253
|
+
var _a6, _b;
|
|
251
254
|
const {
|
|
252
|
-
unitId
|
|
253
|
-
segmentId
|
|
254
|
-
actions
|
|
255
|
-
textRanges
|
|
256
|
-
prevTextRanges
|
|
257
|
-
trigger
|
|
258
|
-
noHistory
|
|
259
|
-
isCompositionEnd
|
|
260
|
-
noNeedSetTextRange
|
|
261
|
-
debounce
|
|
262
|
-
isEditing
|
|
263
|
-
isSync
|
|
264
|
-
syncer
|
|
265
|
-
} =
|
|
266
|
-
if (
|
|
267
|
-
throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${
|
|
268
|
-
const
|
|
269
|
-
if (
|
|
255
|
+
unitId,
|
|
256
|
+
segmentId = "",
|
|
257
|
+
actions,
|
|
258
|
+
textRanges,
|
|
259
|
+
prevTextRanges,
|
|
260
|
+
trigger,
|
|
261
|
+
noHistory,
|
|
262
|
+
isCompositionEnd,
|
|
263
|
+
noNeedSetTextRange,
|
|
264
|
+
debounce,
|
|
265
|
+
isEditing = !0,
|
|
266
|
+
isSync,
|
|
267
|
+
syncer
|
|
268
|
+
} = params, univerInstanceService = accessor.get(IUniverInstanceService), renderManagerService = accessor.get(IRenderManagerService), docStateEmitService = accessor.get(DocStateEmitService), documentDataModel = univerInstanceService.getUniverDocInstance(unitId), documentViewModel = (_a6 = renderManagerService.getRenderById(unitId)) == null ? void 0 : _a6.with(DocSkeletonManagerService).getViewModel();
|
|
269
|
+
if (documentDataModel == null || documentViewModel == null)
|
|
270
|
+
throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${unitId}`);
|
|
271
|
+
const docSelectionManagerService = accessor.get(DocSelectionManagerService), docRanges = (_b = docSelectionManagerService.getDocRanges()) != null ? _b : [], disabled = !!documentDataModel.getSnapshot().disabled;
|
|
272
|
+
if (JSONX.isNoop(actions) || actions && actions.length === 0 || disabled)
|
|
270
273
|
return {
|
|
271
|
-
unitId
|
|
274
|
+
unitId,
|
|
272
275
|
actions: [],
|
|
273
|
-
textRanges:
|
|
276
|
+
textRanges: docRanges
|
|
274
277
|
};
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
+
const undoActions = JSONX.invertWithDoc(actions, documentDataModel.getSnapshot());
|
|
279
|
+
documentDataModel.apply(actions), documentViewModel.reset(documentDataModel), !noNeedSetTextRange && textRanges && trigger != null && !isSync && queueMicrotask(() => {
|
|
280
|
+
docSelectionManagerService.replaceDocRanges(textRanges, { unitId, subUnitId: unitId }, isEditing, params.options);
|
|
278
281
|
});
|
|
279
|
-
const
|
|
280
|
-
commandId:
|
|
281
|
-
unitId
|
|
282
|
-
segmentId
|
|
283
|
-
trigger
|
|
284
|
-
noHistory
|
|
285
|
-
debounce
|
|
282
|
+
const changeState = {
|
|
283
|
+
commandId: RichTextEditingMutationId,
|
|
284
|
+
unitId,
|
|
285
|
+
segmentId,
|
|
286
|
+
trigger,
|
|
287
|
+
noHistory,
|
|
288
|
+
debounce,
|
|
286
289
|
redoState: {
|
|
287
|
-
actions
|
|
288
|
-
textRanges
|
|
290
|
+
actions,
|
|
291
|
+
textRanges
|
|
289
292
|
},
|
|
290
293
|
undoState: {
|
|
291
|
-
actions:
|
|
292
|
-
textRanges:
|
|
294
|
+
actions: undoActions,
|
|
295
|
+
textRanges: prevTextRanges != null ? prevTextRanges : docRanges
|
|
293
296
|
},
|
|
294
|
-
isCompositionEnd
|
|
295
|
-
isSync
|
|
296
|
-
syncer
|
|
297
|
+
isCompositionEnd,
|
|
298
|
+
isSync,
|
|
299
|
+
syncer
|
|
297
300
|
};
|
|
298
|
-
return
|
|
299
|
-
unitId
|
|
300
|
-
actions:
|
|
301
|
-
textRanges:
|
|
301
|
+
return docStateEmitService.emitStateChangeInfo(changeState), {
|
|
302
|
+
unitId,
|
|
303
|
+
actions: undoActions,
|
|
304
|
+
textRanges: docRanges
|
|
302
305
|
};
|
|
303
|
-
}
|
|
304
|
-
},
|
|
306
|
+
}, "handler")
|
|
307
|
+
}, DocsRenameMutation = {
|
|
305
308
|
id: "doc.mutation.rename-doc",
|
|
306
|
-
type:
|
|
307
|
-
handler: (
|
|
308
|
-
const
|
|
309
|
-
return
|
|
310
|
-
}
|
|
311
|
-
},
|
|
312
|
-
var
|
|
313
|
-
for (var
|
|
314
|
-
(
|
|
315
|
-
return
|
|
316
|
-
},
|
|
317
|
-
let
|
|
318
|
-
constructor(
|
|
319
|
-
super(), this._commandService =
|
|
320
|
-
}
|
|
321
|
-
_transformCustomRange(
|
|
322
|
-
var
|
|
323
|
-
const { startOffset
|
|
324
|
-
if (
|
|
325
|
-
let
|
|
326
|
-
return
|
|
327
|
-
|
|
309
|
+
type: CommandType.MUTATION,
|
|
310
|
+
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
311
|
+
const doc = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
|
|
312
|
+
return doc ? (doc.setName(params.name), !0) : !1;
|
|
313
|
+
}, "handler")
|
|
314
|
+
}, DOCS_PLUGIN_CONFIG_KEY = "docs.config", defaultPluginConfig = {};
|
|
315
|
+
var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
316
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
317
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
318
|
+
return kind && result && __defProp$2(target, key, result), result;
|
|
319
|
+
}, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a3;
|
|
320
|
+
let DocCustomRangeController = (_a3 = class extends Disposable {
|
|
321
|
+
constructor(_commandService, _textSelectionManagerService, _univerInstanceService) {
|
|
322
|
+
super(), this._commandService = _commandService, this._textSelectionManagerService = _textSelectionManagerService, this._univerInstanceService = _univerInstanceService, this._initSelectionChange();
|
|
323
|
+
}
|
|
324
|
+
_transformCustomRange(doc, selection) {
|
|
325
|
+
var _a6;
|
|
326
|
+
const { startOffset, endOffset, collapsed } = selection, customRanges = (_a6 = doc.getCustomRanges()) == null ? void 0 : _a6.filter((range) => !range.wholeEntity || startOffset <= range.startIndex && endOffset > range.endIndex ? !1 : collapsed ? range.startIndex < startOffset && range.endIndex >= endOffset : BuildTextUtils.range.isIntersects(startOffset, endOffset - 1, range.startIndex, range.endIndex));
|
|
327
|
+
if (customRanges != null && customRanges.length) {
|
|
328
|
+
let start = startOffset, end = endOffset;
|
|
329
|
+
return customRanges.forEach((range) => {
|
|
330
|
+
start = Math.min(range.startIndex, start), end = Math.max(range.endIndex + 1, end);
|
|
328
331
|
}), {
|
|
329
|
-
...
|
|
330
|
-
startOffset:
|
|
331
|
-
endOffset:
|
|
332
|
-
collapsed:
|
|
332
|
+
...selection,
|
|
333
|
+
startOffset: start,
|
|
334
|
+
endOffset: end,
|
|
335
|
+
collapsed: start === end
|
|
333
336
|
};
|
|
334
337
|
}
|
|
335
|
-
return
|
|
338
|
+
return selection;
|
|
336
339
|
}
|
|
337
340
|
_initSelectionChange() {
|
|
338
|
-
this.disposeWithMe(this._commandService.onCommandExecuted((
|
|
339
|
-
if (
|
|
340
|
-
const
|
|
341
|
-
if (!
|
|
341
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
|
|
342
|
+
if (commandInfo.id === SetTextSelectionsOperation.id) {
|
|
343
|
+
const params = commandInfo.params, { unitId, ranges, isEditing } = params, doc = this._univerInstanceService.getUnit(unitId);
|
|
344
|
+
if (!doc)
|
|
342
345
|
return;
|
|
343
|
-
const
|
|
344
|
-
|
|
346
|
+
const transformedRanges = ranges.map((range) => this._transformCustomRange(doc, range));
|
|
347
|
+
transformedRanges.some((range, i) => ranges[i] !== range) && this._textSelectionManagerService.replaceTextRanges(transformedRanges, isEditing);
|
|
345
348
|
}
|
|
346
349
|
}));
|
|
347
350
|
}
|
|
348
|
-
};
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
],
|
|
354
|
-
var
|
|
355
|
-
for (var
|
|
356
|
-
(
|
|
357
|
-
return
|
|
358
|
-
},
|
|
359
|
-
const
|
|
360
|
-
var
|
|
361
|
-
let
|
|
351
|
+
}, __name(_a3, "DocCustomRangeController"), _a3);
|
|
352
|
+
DocCustomRangeController = __decorateClass$2([
|
|
353
|
+
__decorateParam$2(0, ICommandService),
|
|
354
|
+
__decorateParam$2(1, Inject(DocSelectionManagerService)),
|
|
355
|
+
__decorateParam$2(2, IUniverInstanceService)
|
|
356
|
+
], DocCustomRangeController);
|
|
357
|
+
var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
358
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
359
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
360
|
+
return kind && result && __defProp$1(target, key, result), result;
|
|
361
|
+
}, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1");
|
|
362
|
+
const PLUGIN_NAME = "DOCS_PLUGIN";
|
|
363
|
+
var _a4;
|
|
364
|
+
let UniverDocsPlugin = (_a4 = class extends Plugin {
|
|
362
365
|
// static override type = UniverInstanceType.UNIVER_DOC;
|
|
363
|
-
constructor(
|
|
364
|
-
super(), this._config =
|
|
365
|
-
const { ...
|
|
366
|
+
constructor(_config = defaultPluginConfig, _injector, _configService) {
|
|
367
|
+
super(), this._config = _config, this._injector = _injector, this._configService = _configService;
|
|
368
|
+
const { ...rest } = merge(
|
|
366
369
|
{},
|
|
367
|
-
|
|
370
|
+
defaultPluginConfig,
|
|
368
371
|
this._config
|
|
369
372
|
);
|
|
370
|
-
this._configService.setConfig(
|
|
373
|
+
this._configService.setConfig(DOCS_PLUGIN_CONFIG_KEY, rest);
|
|
371
374
|
}
|
|
372
375
|
onStarting() {
|
|
373
376
|
this._initializeDependencies(), this._initializeCommands();
|
|
374
377
|
}
|
|
375
378
|
_initializeCommands() {
|
|
376
379
|
[
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
].forEach((
|
|
381
|
-
this._injector.get(
|
|
380
|
+
RichTextEditingMutation,
|
|
381
|
+
DocsRenameMutation,
|
|
382
|
+
SetTextSelectionsOperation
|
|
383
|
+
].forEach((command) => {
|
|
384
|
+
this._injector.get(ICommandService).registerCommand(command);
|
|
382
385
|
});
|
|
383
386
|
}
|
|
384
387
|
_initializeDependencies() {
|
|
385
388
|
[
|
|
386
|
-
[
|
|
387
|
-
[
|
|
388
|
-
[
|
|
389
|
-
].forEach((
|
|
389
|
+
[DocSelectionManagerService],
|
|
390
|
+
[DocStateEmitService],
|
|
391
|
+
[DocCustomRangeController]
|
|
392
|
+
].forEach((d) => this._injector.add(d));
|
|
390
393
|
}
|
|
391
394
|
onReady() {
|
|
392
|
-
this._injector.get(
|
|
393
|
-
}
|
|
394
|
-
},
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
],
|
|
399
|
-
const
|
|
400
|
-
CUSTOM_RANGE
|
|
401
|
-
CUSTOM_DECORATION
|
|
395
|
+
this._injector.get(DocCustomRangeController);
|
|
396
|
+
}
|
|
397
|
+
}, __name(_a4, "UniverDocsPlugin"), __publicField(_a4, "pluginName", PLUGIN_NAME), _a4);
|
|
398
|
+
UniverDocsPlugin = __decorateClass$1([
|
|
399
|
+
__decorateParam$1(1, Inject(Injector)),
|
|
400
|
+
__decorateParam$1(2, IConfigService)
|
|
401
|
+
], UniverDocsPlugin);
|
|
402
|
+
const CUSTOM_RANGE = createInterceptorKey("CUSTOM_RANGE"), CUSTOM_DECORATION = createInterceptorKey("CUSTOM_DECORATION"), DOC_INTERCEPTOR_POINT = {
|
|
403
|
+
CUSTOM_RANGE,
|
|
404
|
+
CUSTOM_DECORATION
|
|
402
405
|
};
|
|
403
|
-
var
|
|
404
|
-
for (var
|
|
405
|
-
(
|
|
406
|
-
return
|
|
407
|
-
},
|
|
408
|
-
let
|
|
409
|
-
constructor(
|
|
406
|
+
var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
407
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
408
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
409
|
+
return kind && result && __defProp2(target, key, result), result;
|
|
410
|
+
}, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), _a5;
|
|
411
|
+
let DocInterceptorService = (_a5 = class extends Disposable {
|
|
412
|
+
constructor(_context, _docSkeletonManagerService) {
|
|
410
413
|
super();
|
|
411
|
-
|
|
412
|
-
this._context =
|
|
413
|
-
const
|
|
414
|
-
if (
|
|
414
|
+
__publicField(this, "_interceptorsByName", /* @__PURE__ */ new Map());
|
|
415
|
+
this._context = _context, this._docSkeletonManagerService = _docSkeletonManagerService;
|
|
416
|
+
const viewModel = this._docSkeletonManagerService.getViewModel(), unitId = viewModel.getDataModel().getUnitId();
|
|
417
|
+
if (unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY || unitId === DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)
|
|
415
418
|
return;
|
|
416
|
-
this.disposeWithMe(this.interceptDocumentViewModel(
|
|
419
|
+
this.disposeWithMe(this.interceptDocumentViewModel(viewModel)), this.disposeWithMe(this.intercept(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE, {
|
|
417
420
|
priority: -1,
|
|
418
|
-
handler: (
|
|
421
|
+
handler: /* @__PURE__ */ __name((data, pos, next) => next(data), "handler")
|
|
419
422
|
}));
|
|
420
|
-
let
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
423
|
+
let disposableCollection = new DisposableCollection();
|
|
424
|
+
viewModel.segmentViewModels$.subscribe((segmentViewModels) => {
|
|
425
|
+
disposableCollection.dispose(), disposableCollection = new DisposableCollection(), segmentViewModels.forEach((segmentViewModel) => {
|
|
426
|
+
disposableCollection.add(this.interceptDocumentViewModel(segmentViewModel));
|
|
424
427
|
});
|
|
425
|
-
}), this.disposeWithMe(
|
|
426
|
-
}
|
|
427
|
-
intercept(
|
|
428
|
-
const
|
|
429
|
-
this._interceptorsByName.has(
|
|
430
|
-
const
|
|
431
|
-
return
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
var
|
|
435
|
-
return ((
|
|
428
|
+
}), this.disposeWithMe(disposableCollection);
|
|
429
|
+
}
|
|
430
|
+
intercept(name, interceptor) {
|
|
431
|
+
const key = name;
|
|
432
|
+
this._interceptorsByName.has(key) || this._interceptorsByName.set(key, []);
|
|
433
|
+
const interceptors = this._interceptorsByName.get(key);
|
|
434
|
+
return interceptors.push(interceptor), this._interceptorsByName.set(
|
|
435
|
+
key,
|
|
436
|
+
interceptors.sort((a, b) => {
|
|
437
|
+
var _a6, _b;
|
|
438
|
+
return ((_a6 = b.priority) != null ? _a6 : 0) - ((_b = a.priority) != null ? _b : 0);
|
|
436
439
|
})
|
|
437
|
-
), this.disposeWithMe(
|
|
438
|
-
}
|
|
439
|
-
fetchThroughInterceptors(
|
|
440
|
-
const
|
|
441
|
-
return
|
|
442
|
-
}
|
|
443
|
-
interceptDocumentViewModel(
|
|
444
|
-
const
|
|
445
|
-
return
|
|
446
|
-
getCustomRange: (
|
|
447
|
-
var
|
|
448
|
-
return this.fetchThroughInterceptors(
|
|
449
|
-
|
|
440
|
+
), this.disposeWithMe(toDisposable(() => remove(this._interceptorsByName.get(key), interceptor)));
|
|
441
|
+
}
|
|
442
|
+
fetchThroughInterceptors(name) {
|
|
443
|
+
const key = name, interceptors = this._interceptorsByName.get(key);
|
|
444
|
+
return composeInterceptors(interceptors || []);
|
|
445
|
+
}
|
|
446
|
+
interceptDocumentViewModel(viewModel) {
|
|
447
|
+
const disposableCollection = new DisposableCollection();
|
|
448
|
+
return disposableCollection.add(viewModel.registerCustomRangeInterceptor({
|
|
449
|
+
getCustomRange: /* @__PURE__ */ __name((index) => {
|
|
450
|
+
var _a6;
|
|
451
|
+
return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE)(
|
|
452
|
+
viewModel.getCustomRangeRaw(index),
|
|
450
453
|
{
|
|
451
|
-
index
|
|
452
|
-
unitId:
|
|
453
|
-
customRanges: (
|
|
454
|
+
index,
|
|
455
|
+
unitId: viewModel.getDataModel().getUnitId(),
|
|
456
|
+
customRanges: (_a6 = viewModel.getDataModel().getCustomRanges()) != null ? _a6 : []
|
|
454
457
|
}
|
|
455
458
|
);
|
|
456
|
-
},
|
|
457
|
-
getCustomDecoration: (
|
|
458
|
-
var
|
|
459
|
-
return this.fetchThroughInterceptors(
|
|
460
|
-
|
|
459
|
+
}, "getCustomRange"),
|
|
460
|
+
getCustomDecoration: /* @__PURE__ */ __name((index) => {
|
|
461
|
+
var _a6;
|
|
462
|
+
return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION)(
|
|
463
|
+
viewModel.getCustomDecorationRaw(index),
|
|
461
464
|
{
|
|
462
|
-
index
|
|
463
|
-
unitId:
|
|
464
|
-
customDecorations: (
|
|
465
|
+
index,
|
|
466
|
+
unitId: viewModel.getDataModel().getUnitId(),
|
|
467
|
+
customDecorations: (_a6 = viewModel.getDataModel().getCustomDecorations()) != null ? _a6 : []
|
|
465
468
|
}
|
|
466
469
|
);
|
|
467
|
-
}
|
|
468
|
-
})),
|
|
469
|
-
}
|
|
470
|
-
};
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
],
|
|
474
|
-
function
|
|
475
|
-
if (!
|
|
470
|
+
}, "getCustomDecoration")
|
|
471
|
+
})), disposableCollection;
|
|
472
|
+
}
|
|
473
|
+
}, __name(_a5, "DocInterceptorService"), _a5);
|
|
474
|
+
DocInterceptorService = __decorateClass([
|
|
475
|
+
__decorateParam(1, Inject(DocSkeletonManagerService))
|
|
476
|
+
], DocInterceptorService);
|
|
477
|
+
function getRichTextEditPath(docDataModel, segmentId = "") {
|
|
478
|
+
if (!segmentId)
|
|
476
479
|
return ["body"];
|
|
477
|
-
const { headers
|
|
478
|
-
if (
|
|
480
|
+
const { headers, footers } = docDataModel.getSnapshot();
|
|
481
|
+
if (headers == null && footers == null)
|
|
479
482
|
throw new Error("Document data model must have headers or footers when update by segment id");
|
|
480
|
-
if ((
|
|
481
|
-
return ["headers",
|
|
482
|
-
if ((
|
|
483
|
-
return ["footers",
|
|
483
|
+
if ((headers == null ? void 0 : headers[segmentId]) != null)
|
|
484
|
+
return ["headers", segmentId, "body"];
|
|
485
|
+
if ((footers == null ? void 0 : footers[segmentId]) != null)
|
|
486
|
+
return ["footers", segmentId, "body"];
|
|
484
487
|
throw new Error("Segment id not found in headers or footers");
|
|
485
488
|
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
+
__name(getRichTextEditPath, "getRichTextEditPath");
|
|
490
|
+
function addCustomRangeFactory(accessor, param, body) {
|
|
491
|
+
const { unitId, segmentId } = param, documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId);
|
|
492
|
+
if (!documentDataModel)
|
|
489
493
|
return !1;
|
|
490
|
-
const
|
|
491
|
-
id:
|
|
494
|
+
const doMutation = {
|
|
495
|
+
id: RichTextEditingMutation.id,
|
|
492
496
|
params: {
|
|
493
|
-
unitId:
|
|
497
|
+
unitId: param.unitId,
|
|
494
498
|
actions: [],
|
|
495
499
|
textRanges: void 0
|
|
496
500
|
}
|
|
497
|
-
},
|
|
498
|
-
if (!
|
|
501
|
+
}, jsonX = JSONX.getInstance(), textX = BuildTextUtils.customRange.add({ ...param, body });
|
|
502
|
+
if (!textX)
|
|
499
503
|
return !1;
|
|
500
|
-
const
|
|
501
|
-
return
|
|
504
|
+
const path = getRichTextEditPath(documentDataModel, segmentId);
|
|
505
|
+
return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), doMutation;
|
|
502
506
|
}
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
+
__name(addCustomRangeFactory, "addCustomRangeFactory");
|
|
508
|
+
function addCustomRangeBySelectionFactory(accessor, param) {
|
|
509
|
+
var _a6;
|
|
510
|
+
const { rangeId, rangeType, wholeEntity, properties, unitId, selections: propSelection } = param, docSelectionManagerService = accessor.get(DocSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), selections = propSelection != null ? propSelection : docSelectionManagerService.getTextRanges({ unitId, subUnitId: unitId }), segmentId = (_a6 = selections == null ? void 0 : selections[0]) == null ? void 0 : _a6.segmentId;
|
|
511
|
+
if (!(selections != null && selections.length))
|
|
507
512
|
return !1;
|
|
508
|
-
const
|
|
509
|
-
if (!
|
|
513
|
+
const documentDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
514
|
+
if (!documentDataModel)
|
|
510
515
|
return !1;
|
|
511
|
-
const
|
|
512
|
-
if (!
|
|
516
|
+
const body = documentDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
517
|
+
if (!body)
|
|
513
518
|
return !1;
|
|
514
|
-
const
|
|
515
|
-
ranges:
|
|
516
|
-
rangeId
|
|
517
|
-
rangeType
|
|
518
|
-
segmentId
|
|
519
|
-
wholeEntity
|
|
520
|
-
properties
|
|
521
|
-
body
|
|
519
|
+
const textX = BuildTextUtils.customRange.add({
|
|
520
|
+
ranges: selections,
|
|
521
|
+
rangeId,
|
|
522
|
+
rangeType,
|
|
523
|
+
segmentId,
|
|
524
|
+
wholeEntity,
|
|
525
|
+
properties,
|
|
526
|
+
body
|
|
522
527
|
});
|
|
523
|
-
if (!
|
|
528
|
+
if (!textX)
|
|
524
529
|
return !1;
|
|
525
|
-
const
|
|
526
|
-
id:
|
|
530
|
+
const jsonX = JSONX.getInstance(), doMutation = {
|
|
531
|
+
id: RichTextEditingMutation.id,
|
|
527
532
|
params: {
|
|
528
|
-
unitId
|
|
533
|
+
unitId,
|
|
529
534
|
actions: [],
|
|
530
|
-
textRanges:
|
|
531
|
-
segmentId
|
|
535
|
+
textRanges: textX.selections,
|
|
536
|
+
segmentId
|
|
532
537
|
},
|
|
533
|
-
textX
|
|
534
|
-
},
|
|
535
|
-
return
|
|
538
|
+
textX
|
|
539
|
+
}, path = getRichTextEditPath(documentDataModel, segmentId);
|
|
540
|
+
return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), doMutation;
|
|
536
541
|
}
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
542
|
+
__name(addCustomRangeBySelectionFactory, "addCustomRangeBySelectionFactory");
|
|
543
|
+
function deleteCustomRangeFactory(accessor, params) {
|
|
544
|
+
const { unitId, segmentId, insert } = params, documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId);
|
|
545
|
+
if (!documentDataModel)
|
|
540
546
|
return !1;
|
|
541
|
-
const
|
|
542
|
-
id:
|
|
547
|
+
const doMutation = {
|
|
548
|
+
id: RichTextEditingMutation.id,
|
|
543
549
|
params: {
|
|
544
|
-
unitId:
|
|
550
|
+
unitId: params.unitId,
|
|
545
551
|
actions: [],
|
|
546
552
|
textRanges: void 0,
|
|
547
|
-
segmentId
|
|
553
|
+
segmentId
|
|
548
554
|
}
|
|
549
|
-
},
|
|
550
|
-
documentDataModel
|
|
551
|
-
rangeId:
|
|
552
|
-
insert
|
|
553
|
-
segmentId
|
|
555
|
+
}, jsonX = JSONX.getInstance(), textX = BuildTextUtils.customRange.delete({
|
|
556
|
+
documentDataModel,
|
|
557
|
+
rangeId: params.rangeId,
|
|
558
|
+
insert,
|
|
559
|
+
segmentId
|
|
554
560
|
});
|
|
555
|
-
if (!
|
|
561
|
+
if (!textX)
|
|
556
562
|
return !1;
|
|
557
|
-
const
|
|
558
|
-
return
|
|
563
|
+
const path = getRichTextEditPath(documentDataModel, segmentId);
|
|
564
|
+
return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), doMutation.params.textRanges = textX.selections, doMutation;
|
|
559
565
|
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
566
|
+
__name(deleteCustomRangeFactory, "deleteCustomRangeFactory");
|
|
567
|
+
function replaceSelectionFactory(accessor, params) {
|
|
568
|
+
var _a6, _b, _c, _d;
|
|
569
|
+
const { unitId, body: insertBody, doc } = params;
|
|
570
|
+
let docDataModel = doc;
|
|
571
|
+
if (docDataModel || (docDataModel = accessor.get(IUniverInstanceService).getUnit(unitId)), !docDataModel)
|
|
565
572
|
return !1;
|
|
566
|
-
const
|
|
567
|
-
if (!
|
|
568
|
-
const
|
|
569
|
-
if (!
|
|
573
|
+
const segmentId = (_a6 = params.selection) == null ? void 0 : _a6.segmentId, body = (_b = docDataModel.getSelfOrHeaderFooterModel(segmentId)) == null ? void 0 : _b.getBody();
|
|
574
|
+
if (!body) return !1;
|
|
575
|
+
const docSelectionManagerService = accessor.get(DocSelectionManagerService), selection = (_c = params.selection) != null ? _c : docSelectionManagerService.getActiveTextRange();
|
|
576
|
+
if (!selection || !body)
|
|
570
577
|
return !1;
|
|
571
|
-
const
|
|
572
|
-
startOffset:
|
|
573
|
-
endOffset:
|
|
578
|
+
const textRanges = (_d = params.textRanges) != null ? _d : [{
|
|
579
|
+
startOffset: selection.startOffset + insertBody.dataStream.length,
|
|
580
|
+
endOffset: selection.startOffset + insertBody.dataStream.length,
|
|
574
581
|
collapsed: !0,
|
|
575
|
-
segmentId
|
|
576
|
-
}],
|
|
577
|
-
selection
|
|
578
|
-
body:
|
|
579
|
-
doc:
|
|
582
|
+
segmentId
|
|
583
|
+
}], textX = BuildTextUtils.selection.replace({
|
|
584
|
+
selection,
|
|
585
|
+
body: insertBody,
|
|
586
|
+
doc: docDataModel
|
|
580
587
|
});
|
|
581
|
-
if (!
|
|
588
|
+
if (!textX)
|
|
582
589
|
return !1;
|
|
583
|
-
const
|
|
584
|
-
id:
|
|
590
|
+
const doMutation = {
|
|
591
|
+
id: RichTextEditingMutation.id,
|
|
585
592
|
params: {
|
|
586
|
-
unitId
|
|
593
|
+
unitId,
|
|
587
594
|
actions: [],
|
|
588
|
-
textRanges
|
|
595
|
+
textRanges,
|
|
589
596
|
debounce: !0,
|
|
590
|
-
segmentId
|
|
597
|
+
segmentId
|
|
591
598
|
},
|
|
592
|
-
textX
|
|
593
|
-
},
|
|
594
|
-
return
|
|
599
|
+
textX
|
|
600
|
+
}, jsonX = JSONX.getInstance();
|
|
601
|
+
return doMutation.params.actions = jsonX.editOp(textX.serialize()), doMutation;
|
|
595
602
|
}
|
|
603
|
+
__name(replaceSelectionFactory, "replaceSelectionFactory");
|
|
596
604
|
export {
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
605
|
+
DOC_INTERCEPTOR_POINT,
|
|
606
|
+
DocInterceptorService,
|
|
607
|
+
DocSelectionManagerService,
|
|
608
|
+
DocSkeletonManagerService,
|
|
609
|
+
DocStateEmitService,
|
|
610
|
+
RichTextEditingMutation,
|
|
611
|
+
SetTextSelectionsOperation,
|
|
612
|
+
UniverDocsPlugin,
|
|
613
|
+
addCustomRangeBySelectionFactory,
|
|
614
|
+
addCustomRangeFactory,
|
|
615
|
+
deleteCustomRangeFactory,
|
|
616
|
+
replaceSelectionFactory
|
|
609
617
|
};
|