@univerjs/docs 0.1.17 → 0.2.1
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 +1769 -1088
- package/lib/types/basics/custom-decoration-factory.d.ts +25 -0
- package/lib/types/basics/custom-range-factory.d.ts +25 -0
- package/lib/types/basics/custom-range.d.ts +5 -0
- package/lib/types/basics/retain-delete-params.d.ts +6 -2
- package/lib/types/basics/selection.d.ts +28 -0
- package/lib/types/commands/commands/__tests__/create-command-test-bed.d.ts +6 -6
- package/lib/types/commands/commands/core-editing.command.d.ts +2 -2
- package/lib/types/commands/commands/delete.command.d.ts +2 -2
- package/lib/types/commands/util.d.ts +2 -0
- package/lib/types/controllers/move-cursor.controller.d.ts +1 -1
- package/lib/types/index.d.ts +19 -13
- package/lib/types/services/doc-custom-range.service.d.ts +18 -0
- package/lib/types/services/doc-interceptor/doc-interceptor.service.d.ts +13 -0
- package/lib/types/services/doc-interceptor/interceptor-const.d.ts +14 -0
- package/lib/types/services/doc-skeleton-manager.service.d.ts +4 -2
- package/lib/types/services/doc-view-model-manager.service.d.ts +2 -0
- package/lib/types/services/text-selection-manager.service.d.ts +1 -0
- package/lib/umd/index.js +1 -1
- package/package.json +10 -10
package/lib/es/index.js
CHANGED
|
@@ -1,59 +1,213 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { UniverInstanceType as
|
|
5
|
-
import { NORMAL_TEXT_SELECTION_PLUGIN_STYLE as
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
var Vt = Object.defineProperty;
|
|
2
|
+
var kt = (s, e, t) => e in s ? Vt(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
3
|
+
var A = (s, e, t) => kt(s, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { DataStreamTreeTokenType as N, UniverInstanceType as Z, CommandType as T, RxDisposable as Le, ICommandService as E, TextXActionType as C, IUndoRedoService as Fe, UndoCommandId as rt, RedoCommandId as at, JSONX as w, IUniverInstanceService as P, LocaleService as Wt, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as Tt, TextX as G, normalizeBody as Yt, getBodySlice as Et, updateAttributeByInsert as Kt, Tools as J, MemoryCursor as oe, getDocsUpdateBody as Zt, UpdateDocsAttributeType as _e, getCustomRangeSlice as it, getCustomDecorationSlice as ct, BooleanNumber as k, BaselineOffset as W, PRESET_LIST_TYPE as Jt, PresetListType as At, OnLifecycle as Re, LifecycleStages as ve, Disposable as xe, Direction as L, HorizontalAlign as re, toDisposable as Nt, Plugin as qt, createInterceptorKey as Dt, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY as Qt, remove as en, composeInterceptors as tn, DisposableCollection as nn } from "@univerjs/core";
|
|
5
|
+
import { NORMAL_TEXT_SELECTION_PLUGIN_STYLE as sn, ITextSelectionRenderManager as Ce, DocumentSkeleton as on, DocumentViewModel as rn, IRenderManagerService as ae, hasListGlyph as an, isIndentByGlyph as cn, isFirstGlyph as ln, getParagraphByGlyph as dn, getCharSpaceApply as un, getNumberUnitValue as Ne, RANGE_DIRECTION as De, NodePositionConvertToCursor as lt, TextSelectionRenderManager as gn } from "@univerjs/engine-render";
|
|
6
|
+
import { Inject as Q, Injector as fn } from "@wendellhu/redi";
|
|
7
|
+
import { BehaviorSubject as ne, takeUntil as Pt } from "rxjs";
|
|
8
|
+
function pe(s) {
|
|
9
|
+
return s === N.CUSTOM_RANGE_END || s === N.CUSTOM_RANGE_START;
|
|
10
|
+
}
|
|
11
|
+
function $e(s, e, t, n) {
|
|
12
|
+
return s <= t && e >= t || s >= t && s <= n;
|
|
13
|
+
}
|
|
14
|
+
function Ge(s, e, t, n) {
|
|
15
|
+
const o = n.slice(t.startIndex + 1, t.endIndex), r = Math.max(s - (t.startIndex + 1), 0), a = s + e - 1 - (t.startIndex + 1);
|
|
16
|
+
if (a < 0)
|
|
17
|
+
return !1;
|
|
18
|
+
if (r === 0 && a >= o.length)
|
|
19
|
+
return !0;
|
|
20
|
+
const i = o.slice(0, r) + o.slice(r + e);
|
|
21
|
+
for (let c = 0, l = i.length; c < l; c++) {
|
|
22
|
+
const d = i[c];
|
|
23
|
+
if (!pe(d))
|
|
24
|
+
return !1;
|
|
25
|
+
}
|
|
26
|
+
return !0;
|
|
27
|
+
}
|
|
28
|
+
function ie(s) {
|
|
29
|
+
const { startOffset: e, endOffset: t, collapsed: n } = s, o = Math.min(e, t), r = Math.max(e, t);
|
|
30
|
+
return {
|
|
31
|
+
startOffset: o,
|
|
32
|
+
endOffset: r,
|
|
33
|
+
collapsed: n
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function ze(s, e) {
|
|
37
|
+
let { startOffset: t, endOffset: n } = ie(s);
|
|
38
|
+
for (; e.dataStream[t - 1] === N.CUSTOM_RANGE_START; )
|
|
39
|
+
t -= 1;
|
|
40
|
+
for (; e.dataStream[n] === N.CUSTOM_RANGE_END; )
|
|
41
|
+
n += 1;
|
|
42
|
+
return {
|
|
43
|
+
startOffset: t,
|
|
44
|
+
endOffset: n
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
function je(s, e) {
|
|
48
|
+
let { startOffset: t, endOffset: n, collapsed: o } = ie(s);
|
|
49
|
+
if (o) {
|
|
50
|
+
for (; pe(e.dataStream[t - 1]); )
|
|
51
|
+
n -= 1, t -= 1;
|
|
52
|
+
return {
|
|
53
|
+
startOffset: t,
|
|
54
|
+
endOffset: n,
|
|
55
|
+
collapsed: o
|
|
56
|
+
};
|
|
57
|
+
} else
|
|
58
|
+
return {
|
|
59
|
+
...ze(s, e),
|
|
60
|
+
collapsed: !1
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function Oe(s, e) {
|
|
64
|
+
let { startOffset: t, endOffset: n, collapsed: o } = ie(s);
|
|
65
|
+
if (o) {
|
|
66
|
+
for (; e.dataStream[n] === N.CUSTOM_RANGE_END; )
|
|
67
|
+
n += 1, t += 1;
|
|
68
|
+
for (; e.dataStream[n - 1] === N.CUSTOM_RANGE_START; )
|
|
69
|
+
n -= 1, t -= 1;
|
|
70
|
+
return {
|
|
71
|
+
startOffset: t,
|
|
72
|
+
endOffset: n,
|
|
73
|
+
collapsed: o
|
|
74
|
+
};
|
|
75
|
+
} else
|
|
76
|
+
return {
|
|
77
|
+
...ze(s, e),
|
|
78
|
+
collapsed: !1
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function mn(s, e) {
|
|
82
|
+
if (s.startOffset === s.endOffset)
|
|
83
|
+
return null;
|
|
84
|
+
const t = e.customRanges;
|
|
85
|
+
if (!t)
|
|
86
|
+
return ie(s);
|
|
87
|
+
let { startOffset: n, endOffset: o } = ze(s, e);
|
|
88
|
+
for (; pe(e.dataStream[n]); ) {
|
|
89
|
+
if (e.dataStream[n] === N.CUSTOM_RANGE_START) {
|
|
90
|
+
const r = t.find((a) => a.startIndex === n);
|
|
91
|
+
if (!r)
|
|
92
|
+
throw new Error("No custom-range matched");
|
|
93
|
+
if (r.endIndex === o - 1)
|
|
94
|
+
return {
|
|
95
|
+
startOffset: n,
|
|
96
|
+
endOffset: o,
|
|
97
|
+
collapsed: !1
|
|
98
|
+
};
|
|
99
|
+
if (r.endIndex < o - 1)
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
n += 1;
|
|
103
|
+
}
|
|
104
|
+
for (; pe(e.dataStream[o - 1]); ) {
|
|
105
|
+
if (e.dataStream[n] === N.CUSTOM_RANGE_END) {
|
|
106
|
+
const r = t.find((a) => a.endIndex === o - 1);
|
|
107
|
+
if (!r)
|
|
108
|
+
throw new Error("No custom-range matched");
|
|
109
|
+
if (r.startIndex === n)
|
|
110
|
+
return {
|
|
111
|
+
startOffset: n,
|
|
112
|
+
endOffset: o,
|
|
113
|
+
collapsed: !1
|
|
114
|
+
};
|
|
115
|
+
if (r.startIndex > n)
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
o -= 1;
|
|
119
|
+
}
|
|
120
|
+
return o <= n ? null : {
|
|
121
|
+
startOffset: n,
|
|
122
|
+
endOffset: o,
|
|
123
|
+
collapsed: !1
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
const hn = [
|
|
127
|
+
N.PARAGRAPH,
|
|
128
|
+
// 段落
|
|
129
|
+
N.SECTION_BREAK,
|
|
130
|
+
// 章节
|
|
131
|
+
N.TABLE_START,
|
|
132
|
+
// 表格开始
|
|
133
|
+
N.TABLE_ROW_START,
|
|
134
|
+
// 表格开始
|
|
135
|
+
N.TABLE_CELL_START,
|
|
136
|
+
// 表格开始
|
|
137
|
+
N.TABLE_CELL_END,
|
|
138
|
+
// 表格开始
|
|
139
|
+
N.TABLE_ROW_END,
|
|
140
|
+
// 表格开始
|
|
141
|
+
N.TABLE_END,
|
|
142
|
+
// 表格结束
|
|
143
|
+
N.CUSTOM_RANGE_START,
|
|
144
|
+
// 自定义范围开始
|
|
145
|
+
N.CUSTOM_RANGE_END,
|
|
146
|
+
// 自定义范围结束
|
|
147
|
+
N.COLUMN_BREAK,
|
|
148
|
+
// 换列
|
|
149
|
+
N.PAGE_BREAK,
|
|
150
|
+
// 换页
|
|
151
|
+
N.DOCS_END,
|
|
152
|
+
// 文档结尾
|
|
153
|
+
N.TAB,
|
|
154
|
+
// 制表符
|
|
155
|
+
N.CUSTOM_BLOCK
|
|
156
|
+
// 图片 mention 等不参与文档流的场景
|
|
157
|
+
];
|
|
158
|
+
function vs(s, e, t) {
|
|
159
|
+
const n = s.slice(e, t);
|
|
160
|
+
return hn.reduce((o, r) => o.replaceAll(r, ""), n);
|
|
161
|
+
}
|
|
162
|
+
var Me = /* @__PURE__ */ ((s) => (s.MAIN = "__Document_Render_Main__", s.BACKGROUND = "__Document_Render_Background__", s))(Me || {}), pn = /* @__PURE__ */ ((s) => (s.VIEW_MAIN = "viewMain", s.VIEW_TOP = "viewTop", s.VIEW_LEFT = "viewLeft", s.VIEW_LEFT_TOP = "viewLeftTop", s))(pn || {});
|
|
163
|
+
const xs = 0, Cs = 2, Os = 4, Ms = 10, ys = "normalTextSelectionPluginName";
|
|
164
|
+
function Ts(s) {
|
|
165
|
+
const { mainComponent: e, scene: t, engine: n, components: o } = s, r = e, a = o.get(Me.BACKGROUND);
|
|
12
166
|
return {
|
|
13
167
|
document: r,
|
|
14
|
-
docBackground:
|
|
168
|
+
docBackground: a,
|
|
15
169
|
scene: t,
|
|
16
170
|
engine: n
|
|
17
171
|
};
|
|
18
172
|
}
|
|
19
|
-
function
|
|
20
|
-
const t = s.getCurrentUnitForType(
|
|
173
|
+
function Sn(s, e) {
|
|
174
|
+
const t = s.getCurrentUnitForType(Z.UNIVER_DOC);
|
|
21
175
|
if (!t)
|
|
22
176
|
return null;
|
|
23
177
|
const n = t.getUnitId(), o = e.getRenderById(n);
|
|
24
178
|
if (o == null)
|
|
25
179
|
return;
|
|
26
|
-
const { mainComponent: r, scene:
|
|
180
|
+
const { mainComponent: r, scene: a, engine: i, components: c } = o, l = r, d = c.get(Me.BACKGROUND);
|
|
27
181
|
return {
|
|
28
182
|
document: l,
|
|
29
183
|
docBackground: d,
|
|
30
|
-
scene:
|
|
31
|
-
engine:
|
|
184
|
+
scene: a,
|
|
185
|
+
engine: i
|
|
32
186
|
};
|
|
33
187
|
}
|
|
34
|
-
function
|
|
188
|
+
function Es(s, e) {
|
|
35
189
|
const t = e.getRenderById(s);
|
|
36
190
|
if (t == null)
|
|
37
191
|
return;
|
|
38
|
-
const { mainComponent: n, scene: o, engine: r, components:
|
|
192
|
+
const { mainComponent: n, scene: o, engine: r, components: a } = t, i = n, c = a.get(Me.BACKGROUND);
|
|
39
193
|
return {
|
|
40
|
-
document:
|
|
194
|
+
document: i,
|
|
41
195
|
docBackground: c,
|
|
42
196
|
scene: o,
|
|
43
197
|
engine: r
|
|
44
198
|
};
|
|
45
199
|
}
|
|
46
|
-
const
|
|
200
|
+
const bt = {
|
|
47
201
|
id: "doc.operation.set-selections",
|
|
48
|
-
type:
|
|
202
|
+
type: T.OPERATION,
|
|
49
203
|
handler: (s, e) => !0
|
|
50
204
|
};
|
|
51
|
-
var
|
|
52
|
-
for (var o = n > 1 ? void 0 : n ?
|
|
53
|
-
(
|
|
54
|
-
return n && o &&
|
|
55
|
-
},
|
|
56
|
-
function
|
|
205
|
+
var In = Object.defineProperty, _n = Object.getOwnPropertyDescriptor, Rn = (s, e, t, n) => {
|
|
206
|
+
for (var o = n > 1 ? void 0 : n ? _n(e, t) : e, r = s.length - 1, a; r >= 0; r--)
|
|
207
|
+
(a = s[r]) && (o = (n ? a(e, t, o) : a(o)) || o);
|
|
208
|
+
return n && o && In(e, t, o), o;
|
|
209
|
+
}, dt = (s, e) => (t, n) => e(t, n, s);
|
|
210
|
+
function q(s) {
|
|
57
211
|
const { startOffset: e, endOffset: t, collapsed: n } = s, o = {
|
|
58
212
|
startOffset: e,
|
|
59
213
|
endOffset: t,
|
|
@@ -61,13 +215,13 @@ function W(s) {
|
|
|
61
215
|
};
|
|
62
216
|
return typeof s.isActive == "function" && (o.isActive = s.isActive()), o;
|
|
63
217
|
}
|
|
64
|
-
let
|
|
218
|
+
let D = class extends Le {
|
|
65
219
|
constructor(e, t) {
|
|
66
220
|
super();
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
221
|
+
A(this, "_currentSelection", null);
|
|
222
|
+
A(this, "_textSelectionInfo", /* @__PURE__ */ new Map());
|
|
223
|
+
A(this, "_textSelection$", new ne(null));
|
|
224
|
+
A(this, "textSelection$", this._textSelection$.asObservable());
|
|
71
225
|
this._textSelectionRenderManager = e, this._commandService = t, this._syncSelectionFromRenderService();
|
|
72
226
|
}
|
|
73
227
|
getCurrentSelection() {
|
|
@@ -105,18 +259,19 @@ let T = class extends ye {
|
|
|
105
259
|
const e = this._getTextRanges(this._currentSelection);
|
|
106
260
|
if (e == null)
|
|
107
261
|
return;
|
|
108
|
-
const { textRanges: t, segmentId: n, style: o } = e,
|
|
109
|
-
if (
|
|
262
|
+
const { textRanges: t, segmentId: n, style: o, segmentPage: r } = e, a = t.find((I) => I.isActive());
|
|
263
|
+
if (a == null)
|
|
110
264
|
return null;
|
|
111
|
-
const { startOffset: i, endOffset:
|
|
112
|
-
return i == null ||
|
|
265
|
+
const { startOffset: i, endOffset: c, collapsed: l, startNodePosition: d, endNodePosition: g, direction: u } = a;
|
|
266
|
+
return i == null || c == null ? null : {
|
|
113
267
|
startOffset: i,
|
|
114
|
-
endOffset:
|
|
115
|
-
collapsed:
|
|
116
|
-
startNodePosition:
|
|
117
|
-
endNodePosition:
|
|
268
|
+
endOffset: c,
|
|
269
|
+
collapsed: l,
|
|
270
|
+
startNodePosition: d,
|
|
271
|
+
endNodePosition: g,
|
|
118
272
|
direction: u,
|
|
119
273
|
segmentId: n,
|
|
274
|
+
segmentPage: r,
|
|
120
275
|
style: o
|
|
121
276
|
};
|
|
122
277
|
}
|
|
@@ -126,8 +281,9 @@ let T = class extends ye {
|
|
|
126
281
|
...this._currentSelection,
|
|
127
282
|
textRanges: e,
|
|
128
283
|
segmentId: "",
|
|
284
|
+
segmentPage: -1,
|
|
129
285
|
isEditing: t,
|
|
130
|
-
style:
|
|
286
|
+
style: sn
|
|
131
287
|
// mock style.
|
|
132
288
|
});
|
|
133
289
|
}
|
|
@@ -136,7 +292,7 @@ let T = class extends ye {
|
|
|
136
292
|
}
|
|
137
293
|
// All textRanges should be synchronized from the render layer.
|
|
138
294
|
_syncSelectionFromRenderService() {
|
|
139
|
-
this._textSelectionRenderManager.textSelectionInner$.pipe(
|
|
295
|
+
this._textSelectionRenderManager.textSelectionInner$.pipe(Pt(this.dispose$)).subscribe((e) => {
|
|
140
296
|
e != null && this._replaceTextRangesWithNoRefresh(e);
|
|
141
297
|
});
|
|
142
298
|
}
|
|
@@ -148,14 +304,14 @@ let T = class extends ye {
|
|
|
148
304
|
...e
|
|
149
305
|
};
|
|
150
306
|
this._replaceByParam(t), this._textSelection$.next(t);
|
|
151
|
-
const { unitId: n, subUnitId: o, segmentId: r, style:
|
|
152
|
-
this._commandService.executeCommand(
|
|
307
|
+
const { unitId: n, subUnitId: o, segmentId: r, style: a, textRanges: i, isEditing: c } = t;
|
|
308
|
+
this._commandService.executeCommand(bt.id, {
|
|
153
309
|
unitId: n,
|
|
154
310
|
subUnitId: o,
|
|
155
311
|
segmentId: r,
|
|
156
|
-
style:
|
|
312
|
+
style: a,
|
|
157
313
|
isEditing: c,
|
|
158
|
-
ranges:
|
|
314
|
+
ranges: i.map(q)
|
|
159
315
|
});
|
|
160
316
|
}
|
|
161
317
|
_getTextRanges(e) {
|
|
@@ -167,53 +323,75 @@ let T = class extends ye {
|
|
|
167
323
|
}
|
|
168
324
|
_refresh(e) {
|
|
169
325
|
const t = this._getTextRanges(e);
|
|
170
|
-
this._textSelectionRenderManager.removeAllTextRanges(), t && Array.isArray(t.textRanges) && t.textRanges.length && this._textSelectionRenderManager.addTextRanges(t.textRanges.map(
|
|
326
|
+
this._textSelectionRenderManager.removeAllTextRanges(), t && Array.isArray(t.textRanges) && t.textRanges.length && this._textSelectionRenderManager.addTextRanges(t.textRanges.map(q));
|
|
171
327
|
}
|
|
172
328
|
_replaceByParam(e) {
|
|
173
|
-
const { unitId: t, subUnitId: n, style: o, segmentId: r, textRanges:
|
|
174
|
-
this._textSelectionInfo.has(t) || this._textSelectionInfo.set(t, /* @__PURE__ */ new Map()), this._textSelectionInfo.get(t).set(n, { textRanges:
|
|
329
|
+
const { unitId: t, subUnitId: n, style: o, segmentId: r, textRanges: a, isEditing: i, segmentPage: c } = e;
|
|
330
|
+
this._textSelectionInfo.has(t) || this._textSelectionInfo.set(t, /* @__PURE__ */ new Map()), this._textSelectionInfo.get(t).set(n, { textRanges: a, style: o, segmentId: r, isEditing: i, segmentPage: c });
|
|
175
331
|
}
|
|
176
332
|
_addByParam(e) {
|
|
177
|
-
const { unitId: t, subUnitId: n, textRanges: o, style: r, segmentId:
|
|
333
|
+
const { unitId: t, subUnitId: n, textRanges: o, style: r, segmentId: a, isEditing: i, segmentPage: c } = e;
|
|
178
334
|
this._textSelectionInfo.has(t) || this._textSelectionInfo.set(t, /* @__PURE__ */ new Map());
|
|
179
|
-
const
|
|
180
|
-
|
|
335
|
+
const l = this._textSelectionInfo.get(t);
|
|
336
|
+
l.has(n) ? l.get(n).textRanges.push(...o) : l.set(n, { textRanges: o, style: r, segmentId: a, isEditing: i, segmentPage: c });
|
|
181
337
|
}
|
|
182
338
|
};
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
],
|
|
187
|
-
function
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
339
|
+
D = Rn([
|
|
340
|
+
dt(0, Ce),
|
|
341
|
+
dt(1, E)
|
|
342
|
+
], D);
|
|
343
|
+
function He(s, e = "", t, n) {
|
|
344
|
+
var S;
|
|
345
|
+
const { startOffset: o, endOffset: r } = s, a = [], i = o - t, c = r - t, l = n.dataStream, d = (S = n.customRanges) == null ? void 0 : S.filter((m) => $e(m.startIndex, m.endIndex, o, r)), g = new Set(d == null ? void 0 : d.filter((m) => Ge(o, r - o, m, l))), u = /* @__PURE__ */ new Set();
|
|
346
|
+
d == null || d.forEach((m) => {
|
|
347
|
+
g.has(m) || (m.startIndex - t >= i && m.startIndex - t <= c && m.endIndex - t > c && u.add(m.startIndex), m.endIndex - t >= i && m.endIndex - t <= c && m.startIndex < i && u.add(m.endIndex));
|
|
348
|
+
}), i > 0 && a.push({
|
|
349
|
+
t: C.RETAIN,
|
|
191
350
|
len: i,
|
|
192
351
|
segmentId: e
|
|
193
|
-
})
|
|
194
|
-
|
|
195
|
-
|
|
352
|
+
});
|
|
353
|
+
const I = [...u].sort((m, h) => m - h);
|
|
354
|
+
let f = i;
|
|
355
|
+
return I.forEach((m) => {
|
|
356
|
+
const h = m - f;
|
|
357
|
+
h > 0 && a.push({
|
|
358
|
+
t: C.DELETE,
|
|
359
|
+
len: h,
|
|
360
|
+
line: 0,
|
|
361
|
+
segmentId: e
|
|
362
|
+
}), a.push({
|
|
363
|
+
t: C.RETAIN,
|
|
364
|
+
len: 1,
|
|
365
|
+
segmentId: e
|
|
366
|
+
}), f = m + 1;
|
|
367
|
+
}), f < c && (a.push({
|
|
368
|
+
t: C.DELETE,
|
|
369
|
+
len: c - f,
|
|
196
370
|
line: 0,
|
|
197
371
|
segmentId: e
|
|
198
|
-
}),
|
|
372
|
+
}), f = c + 1), {
|
|
373
|
+
dos: a,
|
|
374
|
+
cursor: f,
|
|
375
|
+
retain: u.size
|
|
376
|
+
};
|
|
199
377
|
}
|
|
200
|
-
var
|
|
201
|
-
for (var o = n > 1 ? void 0 : n ?
|
|
202
|
-
(
|
|
203
|
-
return n && o &&
|
|
204
|
-
},
|
|
205
|
-
const
|
|
206
|
-
let
|
|
378
|
+
var vn = Object.defineProperty, xn = Object.getOwnPropertyDescriptor, Cn = (s, e, t, n) => {
|
|
379
|
+
for (var o = n > 1 ? void 0 : n ? xn(e, t) : e, r = s.length - 1, a; r >= 0; r--)
|
|
380
|
+
(a = s[r]) && (o = (n ? a(e, t, o) : a(o)) || o);
|
|
381
|
+
return n && o && vn(e, t, o), o;
|
|
382
|
+
}, Pe = (s, e) => (t, n) => e(t, n, s);
|
|
383
|
+
const ut = 300;
|
|
384
|
+
let Se = class extends Le {
|
|
207
385
|
constructor(e, t, n) {
|
|
208
386
|
super();
|
|
209
|
-
|
|
210
|
-
|
|
387
|
+
A(this, "_docStateChange$", new ne(null));
|
|
388
|
+
A(this, "docStateChange$", this._docStateChange$.asObservable());
|
|
211
389
|
// This cache used for history compose.
|
|
212
|
-
|
|
390
|
+
A(this, "_historyStateCache", /* @__PURE__ */ new Map());
|
|
213
391
|
// This cache used for collaboration state compose.
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
392
|
+
A(this, "_changeStateCache", /* @__PURE__ */ new Map());
|
|
393
|
+
A(this, "_historyTimer", null);
|
|
394
|
+
A(this, "_changeStateCacheTimer", null);
|
|
217
395
|
this._undoRedoService = e, this._commandService = t, this._univerInstanceService = n, this._initialize();
|
|
218
396
|
}
|
|
219
397
|
setChangeState(e) {
|
|
@@ -222,7 +400,7 @@ let ge = class extends ye {
|
|
|
222
400
|
_initialize() {
|
|
223
401
|
this.disposeWithMe(
|
|
224
402
|
this._commandService.beforeCommandExecuted((e) => {
|
|
225
|
-
if (e.id ===
|
|
403
|
+
if (e.id === rt || e.id === at) {
|
|
226
404
|
const t = this._univerInstanceService.getCurrentUniverDocInstance();
|
|
227
405
|
if (t == null)
|
|
228
406
|
return;
|
|
@@ -233,34 +411,34 @@ let ge = class extends ye {
|
|
|
233
411
|
);
|
|
234
412
|
}
|
|
235
413
|
_cacheChangeState(e, t = "history") {
|
|
236
|
-
const { trigger: n, unitId: o, noHistory: r, debounce:
|
|
237
|
-
if (r || t === "history" && (n ===
|
|
414
|
+
const { trigger: n, unitId: o, noHistory: r, debounce: a = !1 } = e;
|
|
415
|
+
if (r || t === "history" && (n === at || n === rt))
|
|
238
416
|
return;
|
|
239
|
-
const
|
|
240
|
-
if (
|
|
241
|
-
const l =
|
|
417
|
+
const i = t === "history" ? this._historyStateCache : this._changeStateCache, c = t === "history" ? this._pushHistory.bind(this) : this._emitChangeState.bind(this);
|
|
418
|
+
if (i.has(o)) {
|
|
419
|
+
const l = i.get(o);
|
|
242
420
|
l == null || l.push(e);
|
|
243
421
|
} else
|
|
244
|
-
|
|
245
|
-
|
|
422
|
+
i.set(o, [e]);
|
|
423
|
+
a ? t === "history" ? (this._historyTimer && clearTimeout(this._historyTimer), this._historyTimer = setTimeout(() => {
|
|
246
424
|
c(o);
|
|
247
|
-
},
|
|
425
|
+
}, ut)) : (this._changeStateCacheTimer && clearTimeout(this._changeStateCacheTimer), this._changeStateCacheTimer = setTimeout(() => {
|
|
248
426
|
c(o);
|
|
249
|
-
},
|
|
427
|
+
}, ut)) : c(o);
|
|
250
428
|
}
|
|
251
429
|
_pushHistory(e) {
|
|
252
430
|
const t = this._undoRedoService, n = this._historyStateCache.get(e);
|
|
253
431
|
if (!Array.isArray(n) || n.length === 0)
|
|
254
432
|
return;
|
|
255
|
-
const o = n.length, r = n[0].commandId,
|
|
433
|
+
const o = n.length, r = n[0].commandId, a = n[0], i = n[o - 1], c = {
|
|
256
434
|
unitId: e,
|
|
257
|
-
actions: n.reduce((d,
|
|
258
|
-
textRanges:
|
|
435
|
+
actions: n.reduce((d, g) => w.compose(d, g.redoState.actions), null),
|
|
436
|
+
textRanges: i.redoState.textRanges
|
|
259
437
|
}, l = {
|
|
260
438
|
unitId: e,
|
|
261
439
|
// Always need to put undoParams after redoParams, because `reverse` will change the `cacheStates` order.
|
|
262
|
-
actions: n.reverse().reduce((d,
|
|
263
|
-
textRanges:
|
|
440
|
+
actions: n.reverse().reduce((d, g) => w.compose(d, g.undoState.actions), null),
|
|
441
|
+
textRanges: a.undoState.textRanges
|
|
264
442
|
};
|
|
265
443
|
t.pushUndoRedo({
|
|
266
444
|
unitID: e,
|
|
@@ -272,38 +450,38 @@ let ge = class extends ye {
|
|
|
272
450
|
const t = this._changeStateCache.get(e);
|
|
273
451
|
if (!Array.isArray(t) || t.length === 0)
|
|
274
452
|
return;
|
|
275
|
-
const n = t.length, { commandId: o, trigger: r, segmentId:
|
|
453
|
+
const n = t.length, { commandId: o, trigger: r, segmentId: a, noHistory: i, debounce: c } = t[0], l = t[0], d = t[n - 1], g = {
|
|
276
454
|
unitId: e,
|
|
277
|
-
actions: t.reduce((
|
|
455
|
+
actions: t.reduce((f, S) => w.compose(f, S.redoState.actions), null),
|
|
278
456
|
textRanges: d.redoState.textRanges
|
|
279
|
-
},
|
|
457
|
+
}, u = {
|
|
280
458
|
unitId: e,
|
|
281
459
|
// Always need to put undoParams after redoParams, because `reverse` will change the `cacheStates` order.
|
|
282
|
-
actions: t.reverse().reduce((
|
|
460
|
+
actions: t.reverse().reduce((f, S) => w.compose(f, S.undoState.actions), null),
|
|
283
461
|
textRanges: l.undoState.textRanges
|
|
284
|
-
},
|
|
462
|
+
}, I = {
|
|
285
463
|
commandId: o,
|
|
286
464
|
unitId: e,
|
|
287
465
|
trigger: r,
|
|
288
|
-
redoState:
|
|
289
|
-
undoState:
|
|
290
|
-
segmentId:
|
|
291
|
-
noHistory:
|
|
466
|
+
redoState: g,
|
|
467
|
+
undoState: u,
|
|
468
|
+
segmentId: a,
|
|
469
|
+
noHistory: i,
|
|
292
470
|
debounce: c
|
|
293
471
|
};
|
|
294
|
-
t.length = 0, this._docStateChange$.next(
|
|
472
|
+
t.length = 0, this._docStateChange$.next(I);
|
|
295
473
|
}
|
|
296
474
|
};
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
],
|
|
302
|
-
class
|
|
475
|
+
Se = Cn([
|
|
476
|
+
Pe(0, Q(Fe)),
|
|
477
|
+
Pe(1, E),
|
|
478
|
+
Pe(2, P)
|
|
479
|
+
], Se);
|
|
480
|
+
class ye {
|
|
303
481
|
constructor() {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
482
|
+
A(this, "_previousActiveRange", null);
|
|
483
|
+
A(this, "_undoMutationParamsCache", []);
|
|
484
|
+
A(this, "_redoMutationParamsCache", []);
|
|
307
485
|
}
|
|
308
486
|
clearUndoRedoMutationParamsCache() {
|
|
309
487
|
this._undoMutationParamsCache = [], this._redoMutationParamsCache = [];
|
|
@@ -331,13 +509,13 @@ class he {
|
|
|
331
509
|
return null;
|
|
332
510
|
const { unitId: e } = this._undoMutationParamsCache[0], t = {
|
|
333
511
|
unitId: e,
|
|
334
|
-
actions: this._undoMutationParamsCache.reverse().reduce((o, r) =>
|
|
512
|
+
actions: this._undoMutationParamsCache.reverse().reduce((o, r) => w.compose(o, r.actions), null),
|
|
335
513
|
textRanges: []
|
|
336
514
|
// Add empty array, will never use, just fix type error
|
|
337
515
|
};
|
|
338
516
|
return { redoMutationParams: {
|
|
339
517
|
unitId: e,
|
|
340
|
-
actions: this._redoMutationParamsCache.reduce((o, r) =>
|
|
518
|
+
actions: this._redoMutationParamsCache.reduce((o, r) => w.compose(o, r.actions), null),
|
|
341
519
|
textRanges: []
|
|
342
520
|
// Add empty array, will never use, just fix type error
|
|
343
521
|
}, undoMutationParams: t, previousActiveRange: this._previousActiveRange };
|
|
@@ -346,28 +524,36 @@ class he {
|
|
|
346
524
|
this._undoMutationParamsCache = [], this._redoMutationParamsCache = [], this._previousActiveRange = null;
|
|
347
525
|
}
|
|
348
526
|
}
|
|
349
|
-
var
|
|
350
|
-
for (var o = n > 1 ? void 0 : n ?
|
|
351
|
-
(
|
|
352
|
-
return n && o &&
|
|
353
|
-
},
|
|
354
|
-
let
|
|
527
|
+
var On = Object.defineProperty, Mn = Object.getOwnPropertyDescriptor, yn = (s, e, t, n) => {
|
|
528
|
+
for (var o = n > 1 ? void 0 : n ? Mn(e, t) : e, r = s.length - 1, a; r >= 0; r--)
|
|
529
|
+
(a = s[r]) && (o = (n ? a(e, t, o) : a(o)) || o);
|
|
530
|
+
return n && o && On(e, t, o), o;
|
|
531
|
+
}, gt = (s, e) => (t, n) => e(t, n, s);
|
|
532
|
+
let X = class extends Le {
|
|
355
533
|
constructor(e, t, n) {
|
|
356
534
|
super();
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
535
|
+
A(this, "_skeleton");
|
|
536
|
+
A(this, "_docViewModel");
|
|
537
|
+
A(this, "_currentSkeleton$", new ne(null));
|
|
538
|
+
A(this, "currentSkeleton$", this._currentSkeleton$.asObservable());
|
|
361
539
|
// CurrentSkeletonBefore for pre-triggered logic during registration
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
this
|
|
540
|
+
A(this, "_currentSkeletonBefore$", new ne(null));
|
|
541
|
+
A(this, "currentSkeletonBefore$", this._currentSkeletonBefore$.asObservable());
|
|
542
|
+
A(this, "_currentViewModel$", new ne(null));
|
|
543
|
+
A(this, "currentViewModel$", this._currentViewModel$.asObservable());
|
|
544
|
+
this._context = e, this._localeService = t, this._univerInstanceService = n, this._init(), this._univerInstanceService.getCurrentTypeOfUnit$(Z.UNIVER_DOC).pipe(Pt(this.dispose$)).subscribe((o) => {
|
|
365
545
|
(o == null ? void 0 : o.getUnitId()) === this._context.unitId && this._update(o);
|
|
366
546
|
});
|
|
367
547
|
}
|
|
368
548
|
dispose() {
|
|
369
549
|
super.dispose(), this._currentSkeletonBefore$.complete(), this._currentSkeleton$.complete();
|
|
370
550
|
}
|
|
551
|
+
getSkeleton() {
|
|
552
|
+
return this._skeleton;
|
|
553
|
+
}
|
|
554
|
+
getViewModel() {
|
|
555
|
+
return this._docViewModel;
|
|
556
|
+
}
|
|
371
557
|
_init() {
|
|
372
558
|
const e = this._context.unit;
|
|
373
559
|
this._update(e);
|
|
@@ -376,30 +562,24 @@ let H = class extends ye {
|
|
|
376
562
|
const t = this._context.unitId;
|
|
377
563
|
if (e.getBody() == null)
|
|
378
564
|
return;
|
|
379
|
-
this._docViewModel && t ===
|
|
565
|
+
this._docViewModel && t === Tt ? (this._docViewModel.reset(e), this._context.unit = e) : this._docViewModel || (this._docViewModel = this._buildDocViewModel(e)), this._skeleton || (this._skeleton = this._buildSkeleton(this._docViewModel));
|
|
380
566
|
const n = this._skeleton;
|
|
381
|
-
n.calculate(), this._currentSkeletonBefore$.next(n), this._currentSkeleton$.next(n);
|
|
382
|
-
}
|
|
383
|
-
getSkeleton() {
|
|
384
|
-
return this._skeleton;
|
|
385
|
-
}
|
|
386
|
-
getViewModel() {
|
|
387
|
-
return this._docViewModel;
|
|
567
|
+
n.calculate(), this._currentSkeletonBefore$.next(n), this._currentSkeleton$.next(n), this._currentViewModel$.next(this._docViewModel);
|
|
388
568
|
}
|
|
389
569
|
_buildSkeleton(e) {
|
|
390
|
-
return
|
|
570
|
+
return on.create(e, this._localeService);
|
|
391
571
|
}
|
|
392
572
|
_buildDocViewModel(e) {
|
|
393
|
-
return new
|
|
573
|
+
return new rn(e);
|
|
394
574
|
}
|
|
395
575
|
};
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
],
|
|
400
|
-
const
|
|
401
|
-
id:
|
|
402
|
-
type:
|
|
576
|
+
X = yn([
|
|
577
|
+
gt(1, Q(Wt)),
|
|
578
|
+
gt(2, P)
|
|
579
|
+
], X);
|
|
580
|
+
const ft = "doc.mutation.rich-text-editing", F = {
|
|
581
|
+
id: ft,
|
|
582
|
+
type: T.MUTATION,
|
|
403
583
|
// eslint-disable-next-line max-lines-per-function
|
|
404
584
|
handler: (s, e) => {
|
|
405
585
|
var O, b;
|
|
@@ -408,137 +588,204 @@ const et = "doc.mutation.rich-text-editing", B = {
|
|
|
408
588
|
segmentId: n = "",
|
|
409
589
|
actions: o,
|
|
410
590
|
textRanges: r,
|
|
411
|
-
prevTextRanges:
|
|
412
|
-
trigger:
|
|
591
|
+
prevTextRanges: a,
|
|
592
|
+
trigger: i,
|
|
413
593
|
noHistory: c,
|
|
414
594
|
isCompositionEnd: l,
|
|
415
595
|
noNeedSetTextRange: d,
|
|
416
|
-
debounce:
|
|
417
|
-
} = e,
|
|
418
|
-
if (
|
|
596
|
+
debounce: g
|
|
597
|
+
} = e, u = s.get(P), I = s.get(ae), f = u.getUniverDocInstance(t), S = (O = I.getRenderById(t)) == null ? void 0 : O.with(X).getViewModel();
|
|
598
|
+
if (f == null || S == null)
|
|
419
599
|
throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${t}`);
|
|
420
|
-
const
|
|
421
|
-
if (
|
|
600
|
+
const m = s.get(D), p = ((b = m.getSelections()) != null ? b : []).map(q), R = s.get(Se), v = s.get(ye), y = !!f.getSnapshot().disabled;
|
|
601
|
+
if (w.isNoop(o) || o && o.length === 0 || y)
|
|
422
602
|
return {
|
|
423
603
|
unitId: t,
|
|
424
604
|
actions: [],
|
|
425
605
|
textRanges: p
|
|
426
606
|
};
|
|
427
|
-
const
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
f.getSelfOrHeaderFooterViewModel(n).reset(E), !d && r && a != null && queueMicrotask(() => {
|
|
431
|
-
S.replaceTextRanges(r);
|
|
607
|
+
const _ = w.invertWithDoc(o, f.getSnapshot());
|
|
608
|
+
f.apply(o), S.reset(f), !d && r && i != null && queueMicrotask(() => {
|
|
609
|
+
m.replaceTextRanges(r);
|
|
432
610
|
});
|
|
433
|
-
const
|
|
434
|
-
commandId:
|
|
611
|
+
const M = {
|
|
612
|
+
commandId: ft,
|
|
435
613
|
unitId: t,
|
|
436
614
|
segmentId: n,
|
|
437
|
-
trigger:
|
|
615
|
+
trigger: i,
|
|
438
616
|
noHistory: c,
|
|
439
|
-
debounce:
|
|
617
|
+
debounce: g,
|
|
440
618
|
redoState: {
|
|
441
619
|
actions: o,
|
|
442
620
|
textRanges: r
|
|
443
621
|
},
|
|
444
622
|
undoState: {
|
|
445
|
-
actions:
|
|
446
|
-
textRanges:
|
|
623
|
+
actions: _,
|
|
624
|
+
textRanges: a != null ? a : p
|
|
447
625
|
}
|
|
448
626
|
};
|
|
449
627
|
if (l) {
|
|
450
|
-
const
|
|
451
|
-
if (
|
|
628
|
+
const x = v.fetchComposedUndoRedoMutationParams();
|
|
629
|
+
if (x == null)
|
|
452
630
|
throw new Error("historyParams is null in RichTextEditingMutation");
|
|
453
|
-
const { undoMutationParams:
|
|
454
|
-
|
|
631
|
+
const { undoMutationParams: U, redoMutationParams: B, previousActiveRange: $ } = x;
|
|
632
|
+
M.redoState.actions = B.actions, M.undoState.actions = U.actions, M.undoState.textRanges = [$];
|
|
455
633
|
}
|
|
456
|
-
return
|
|
634
|
+
return R.setChangeState(M), {
|
|
457
635
|
unitId: t,
|
|
458
|
-
actions:
|
|
636
|
+
actions: _,
|
|
459
637
|
textRanges: p
|
|
460
638
|
};
|
|
461
639
|
}
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
|
|
640
|
+
};
|
|
641
|
+
function Ut(s, e) {
|
|
642
|
+
var n;
|
|
643
|
+
return (n = s.get(ae).getRenderById(e)) == null ? void 0 : n.with(X);
|
|
644
|
+
}
|
|
645
|
+
function z(s, e = "") {
|
|
646
|
+
if (!e)
|
|
647
|
+
return ["body"];
|
|
648
|
+
const { headers: t, footers: n } = s.getSnapshot();
|
|
649
|
+
if (t == null && n == null)
|
|
650
|
+
throw new Error("Document data model must have headers or footers when update by segment id");
|
|
651
|
+
if ((t == null ? void 0 : t[e]) != null)
|
|
652
|
+
return ["headers", e, "body"];
|
|
653
|
+
if ((n == null ? void 0 : n[e]) != null)
|
|
654
|
+
return ["footers", e, "body"];
|
|
655
|
+
throw new Error("Segment id not found in headers or footers");
|
|
656
|
+
}
|
|
657
|
+
const Tn = "doc.command.insert-text", Ie = {
|
|
658
|
+
id: Tn,
|
|
659
|
+
type: T.COMMAND,
|
|
660
|
+
// eslint-disable-next-line max-lines-per-function
|
|
465
661
|
handler: async (s, e) => {
|
|
466
|
-
|
|
467
|
-
|
|
662
|
+
var O;
|
|
663
|
+
const t = s.get(E), { range: n, segmentId: o, body: r, unitId: a, textRanges: i, cursorOffset: c } = e, l = s.get(D), g = s.get(P).getUnit(a, Z.UNIVER_DOC);
|
|
664
|
+
if (g == null)
|
|
665
|
+
return !1;
|
|
666
|
+
const u = l.getActiveRange(), I = g.getSelfOrHeaderFooterModel((O = u == null ? void 0 : u.segmentId) != null ? O : "").getBody();
|
|
667
|
+
if (!I)
|
|
668
|
+
return !1;
|
|
669
|
+
const f = Oe(n, I), { startOffset: S, collapsed: m } = f, h = c != null ? c : r.dataStream.length, p = [
|
|
670
|
+
{
|
|
671
|
+
startOffset: S + h,
|
|
672
|
+
endOffset: S + h,
|
|
673
|
+
style: u == null ? void 0 : u.style,
|
|
674
|
+
collapsed: m
|
|
675
|
+
}
|
|
676
|
+
], R = {
|
|
677
|
+
id: F.id,
|
|
468
678
|
params: {
|
|
469
|
-
unitId:
|
|
679
|
+
unitId: a,
|
|
470
680
|
actions: [],
|
|
471
|
-
textRanges:
|
|
681
|
+
textRanges: i != null ? i : p,
|
|
472
682
|
debounce: !0
|
|
473
683
|
}
|
|
474
|
-
},
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
684
|
+
}, v = new G(), y = w.getInstance();
|
|
685
|
+
if (m)
|
|
686
|
+
S > 0 && v.push({
|
|
687
|
+
t: C.RETAIN,
|
|
688
|
+
len: S,
|
|
689
|
+
segmentId: o
|
|
690
|
+
});
|
|
691
|
+
else {
|
|
692
|
+
const { dos: b, retain: x } = He(f, o, 0, I);
|
|
693
|
+
v.push(...b), i || (R.params.textRanges = [{
|
|
694
|
+
startOffset: S + h + x,
|
|
695
|
+
endOffset: S + h + x,
|
|
696
|
+
collapsed: m
|
|
697
|
+
}]);
|
|
698
|
+
}
|
|
699
|
+
v.push({
|
|
700
|
+
t: C.INSERT,
|
|
481
701
|
body: r,
|
|
482
702
|
len: r.dataStream.length,
|
|
483
703
|
line: 0,
|
|
484
704
|
segmentId: o
|
|
485
|
-
})
|
|
705
|
+
});
|
|
706
|
+
const _ = z(g, o);
|
|
707
|
+
return R.params.actions = y.editOp(v.serialize(), _), !!t.syncExecuteCommand(R.id, R.params);
|
|
486
708
|
}
|
|
487
709
|
};
|
|
488
|
-
var
|
|
489
|
-
const
|
|
710
|
+
var Y = /* @__PURE__ */ ((s) => (s[s.LEFT = 0] = "LEFT", s[s.RIGHT = 1] = "RIGHT", s))(Y || {});
|
|
711
|
+
const Xe = {
|
|
490
712
|
id: "doc.command.delete-text",
|
|
491
|
-
type:
|
|
713
|
+
type: T.COMMAND,
|
|
492
714
|
handler: async (s, e) => {
|
|
493
|
-
|
|
494
|
-
|
|
715
|
+
var b;
|
|
716
|
+
const t = s.get(E), n = s.get(P), { range: o, segmentId: r, unitId: a, direction: i, len: c = 1 } = e, l = n.getUnit(a, Z.UNIVER_DOC), d = l == null ? void 0 : l.getSelfOrHeaderFooterModel(r).getBody();
|
|
717
|
+
if (l == null || d == null)
|
|
718
|
+
return !1;
|
|
719
|
+
const { startOffset: g } = o, u = d.dataStream, I = i === 0 ? g - c : g, f = I + c - 1, S = (b = d.customRanges) == null ? void 0 : b.filter((x) => $e(x.startIndex, x.endIndex, I, f)), m = S == null ? void 0 : S.filter((x) => Ge(I, c, x, u)), h = [];
|
|
720
|
+
for (let x = 0; x < c; x++)
|
|
721
|
+
h.push(I + x);
|
|
722
|
+
m == null || m.forEach((x) => {
|
|
723
|
+
h.push(x.startIndex, x.endIndex);
|
|
724
|
+
}), h.sort((x, U) => x - U);
|
|
725
|
+
const p = h[0], R = {
|
|
726
|
+
id: F.id,
|
|
495
727
|
params: {
|
|
496
|
-
unitId:
|
|
728
|
+
unitId: a,
|
|
497
729
|
actions: [],
|
|
498
|
-
textRanges:
|
|
730
|
+
textRanges: [{
|
|
731
|
+
startOffset: p,
|
|
732
|
+
endOffset: p,
|
|
733
|
+
collapsed: !0
|
|
734
|
+
}],
|
|
499
735
|
debounce: !0
|
|
500
736
|
}
|
|
501
|
-
},
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
737
|
+
}, v = new G(), y = w.getInstance();
|
|
738
|
+
let _ = 0;
|
|
739
|
+
for (let x = 0; x < h.length; x++) {
|
|
740
|
+
const U = h[x];
|
|
741
|
+
U - _ > 0 && v.push({
|
|
742
|
+
t: C.RETAIN,
|
|
743
|
+
len: U - _,
|
|
744
|
+
segmentId: r
|
|
745
|
+
}), v.push({
|
|
746
|
+
t: C.DELETE,
|
|
747
|
+
len: 1,
|
|
748
|
+
segmentId: r,
|
|
749
|
+
line: 0
|
|
750
|
+
}), _ = U + 1;
|
|
751
|
+
}
|
|
752
|
+
const M = z(l, r);
|
|
753
|
+
return R.params.actions = y.editOp(v.serialize(), M), !!t.syncExecuteCommand(R.id, R.params);
|
|
512
754
|
}
|
|
513
|
-
},
|
|
755
|
+
}, wt = {
|
|
514
756
|
id: "doc.command.update-text",
|
|
515
|
-
type:
|
|
757
|
+
type: T.COMMAND,
|
|
516
758
|
handler: async (s, e) => {
|
|
517
|
-
const { range: t, segmentId: n, updateBody: o, coverType: r, unitId:
|
|
518
|
-
|
|
759
|
+
const { range: t, segmentId: n, updateBody: o, coverType: r, unitId: a, textRanges: i } = e, c = s.get(E), d = s.get(P).getCurrentUniverDocInstance();
|
|
760
|
+
if (d == null)
|
|
761
|
+
return !1;
|
|
762
|
+
const g = {
|
|
763
|
+
id: F.id,
|
|
519
764
|
params: {
|
|
520
|
-
unitId:
|
|
765
|
+
unitId: a,
|
|
521
766
|
actions: [],
|
|
522
|
-
textRanges:
|
|
767
|
+
textRanges: i
|
|
523
768
|
}
|
|
524
|
-
},
|
|
525
|
-
|
|
526
|
-
t:
|
|
527
|
-
len:
|
|
769
|
+
}, u = new G(), I = w.getInstance(), { startOffset: f, endOffset: S } = t;
|
|
770
|
+
u.push({
|
|
771
|
+
t: C.RETAIN,
|
|
772
|
+
len: f,
|
|
528
773
|
segmentId: n
|
|
529
|
-
}),
|
|
530
|
-
t:
|
|
774
|
+
}), u.push({
|
|
775
|
+
t: C.RETAIN,
|
|
531
776
|
body: o,
|
|
532
|
-
len:
|
|
777
|
+
len: S - f,
|
|
533
778
|
segmentId: n,
|
|
534
779
|
coverType: r
|
|
535
|
-
})
|
|
780
|
+
});
|
|
781
|
+
const m = z(d, n);
|
|
782
|
+
return g.params.actions = I.editOp(u.serialize(), m), !!c.syncExecuteCommand(g.id, g.params);
|
|
536
783
|
}
|
|
537
784
|
};
|
|
538
|
-
function
|
|
785
|
+
function mt(s, e) {
|
|
539
786
|
const t = [];
|
|
540
787
|
for (let n = 0, o = s.length; n < o; n++)
|
|
541
|
-
s[n] ===
|
|
788
|
+
s[n] === N.PARAGRAPH && t.push({
|
|
542
789
|
startIndex: n
|
|
543
790
|
});
|
|
544
791
|
if (e)
|
|
@@ -546,365 +793,394 @@ function nn(s, e) {
|
|
|
546
793
|
e.bullet && (n.bullet = J.deepClone(e.bullet)), e.paragraphStyle && (n.paragraphStyle = J.deepClone(e.paragraphStyle));
|
|
547
794
|
return t;
|
|
548
795
|
}
|
|
549
|
-
const
|
|
796
|
+
const En = {
|
|
550
797
|
id: "doc.command.break-line",
|
|
551
|
-
type:
|
|
798
|
+
type: T.COMMAND,
|
|
552
799
|
handler: async (s) => {
|
|
553
|
-
var
|
|
554
|
-
const e = s.get(
|
|
800
|
+
var I, f;
|
|
801
|
+
const e = s.get(D), t = s.get(P), n = s.get(E), o = e.getActiveRange();
|
|
555
802
|
if (o == null)
|
|
556
803
|
return !1;
|
|
557
|
-
const r = t.getCurrentUniverDocInstance();
|
|
558
|
-
if (!r)
|
|
804
|
+
const r = t.getCurrentUniverDocInstance(), a = r == null ? void 0 : r.getBody();
|
|
805
|
+
if (!r || !a)
|
|
559
806
|
return !1;
|
|
560
|
-
const i = r.getUnitId(), { startOffset:
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
807
|
+
const i = r.getUnitId(), { startOffset: c, endOffset: l } = Oe(o, a), { segmentId: d } = o, u = ((f = (I = r.getSelfOrHeaderFooterModel(d).getBody()) == null ? void 0 : I.paragraphs) != null ? f : []).find((S) => S.startIndex >= c);
|
|
808
|
+
if (u && u.startIndex > l) {
|
|
809
|
+
const S = Yt(Et(a, l, u.startIndex)), m = {
|
|
810
|
+
startOffset: c,
|
|
811
|
+
endOffset: u.startIndex,
|
|
812
|
+
collapsed: !1
|
|
813
|
+
};
|
|
814
|
+
return Kt(
|
|
815
|
+
S,
|
|
816
|
+
{
|
|
817
|
+
dataStream: N.PARAGRAPH,
|
|
818
|
+
paragraphs: mt(N.PARAGRAPH, u)
|
|
819
|
+
},
|
|
820
|
+
1,
|
|
821
|
+
0
|
|
822
|
+
), await n.executeCommand(Ie.id, {
|
|
823
|
+
unitId: i,
|
|
824
|
+
body: S,
|
|
825
|
+
range: m,
|
|
826
|
+
segmentId: d,
|
|
827
|
+
cursorOffset: 1
|
|
828
|
+
});
|
|
829
|
+
} else
|
|
830
|
+
return await n.executeCommand(Ie.id, {
|
|
831
|
+
unitId: i,
|
|
832
|
+
body: {
|
|
833
|
+
dataStream: N.PARAGRAPH,
|
|
834
|
+
paragraphs: mt(N.PARAGRAPH, u)
|
|
835
|
+
},
|
|
836
|
+
range: o,
|
|
837
|
+
segmentId: d
|
|
838
|
+
});
|
|
577
839
|
}
|
|
578
|
-
}
|
|
579
|
-
function St(s, e) {
|
|
580
|
-
var n;
|
|
581
|
-
return (n = s.get(ee).getRenderById(e)) == null ? void 0 : n.with(H);
|
|
582
|
-
}
|
|
583
|
-
const Wn = {
|
|
840
|
+
}, As = {
|
|
584
841
|
id: "doc.command.inner-paste",
|
|
585
|
-
type:
|
|
842
|
+
type: T.COMMAND,
|
|
586
843
|
handler: async (s, e) => {
|
|
587
|
-
const { segmentId: t,
|
|
844
|
+
const { segmentId: t, textRanges: n } = e, o = e.body, r = s.get(E), a = s.get(D), i = s.get(P), c = a.getSelections();
|
|
588
845
|
if (!Array.isArray(c) || c.length === 0)
|
|
589
846
|
return !1;
|
|
590
|
-
const l =
|
|
591
|
-
if (
|
|
847
|
+
const l = i.getCurrentUniverDocInstance(), d = l == null ? void 0 : l.getSelfOrHeaderFooterModel(t).getBody();
|
|
848
|
+
if (l == null || d == null)
|
|
592
849
|
return !1;
|
|
593
|
-
const
|
|
594
|
-
id:
|
|
850
|
+
const g = l.getUnitId(), u = {
|
|
851
|
+
id: F.id,
|
|
595
852
|
params: {
|
|
596
|
-
unitId:
|
|
853
|
+
unitId: g,
|
|
597
854
|
actions: [],
|
|
598
|
-
textRanges:
|
|
855
|
+
textRanges: n
|
|
599
856
|
}
|
|
600
|
-
},
|
|
601
|
-
|
|
602
|
-
const
|
|
603
|
-
for (const
|
|
604
|
-
const { startOffset:
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
857
|
+
}, I = new oe();
|
|
858
|
+
I.reset();
|
|
859
|
+
const f = new G(), S = w.getInstance();
|
|
860
|
+
for (const p of c) {
|
|
861
|
+
const { startOffset: R, endOffset: v, collapsed: y } = p, _ = R - I.cursor;
|
|
862
|
+
if (y)
|
|
863
|
+
f.push({
|
|
864
|
+
t: C.RETAIN,
|
|
865
|
+
len: _,
|
|
866
|
+
segmentId: t
|
|
867
|
+
});
|
|
868
|
+
else {
|
|
869
|
+
const { dos: M } = He(p, t, I.cursor, d);
|
|
870
|
+
f.push(...M);
|
|
871
|
+
}
|
|
872
|
+
f.push({
|
|
873
|
+
t: C.INSERT,
|
|
874
|
+
body: o,
|
|
875
|
+
len: o.dataStream.length,
|
|
613
876
|
line: 0,
|
|
614
877
|
segmentId: t
|
|
615
|
-
}),
|
|
878
|
+
}), I.reset(), I.moveCursor(v);
|
|
616
879
|
}
|
|
617
|
-
|
|
880
|
+
const m = z(l, t);
|
|
881
|
+
return u.params.actions = S.editOp(f.serialize(), m), !!r.syncExecuteCommand(u.id, u.params);
|
|
618
882
|
}
|
|
619
|
-
},
|
|
883
|
+
}, Bt = {
|
|
620
884
|
id: "doc.command.inner-cut",
|
|
621
|
-
type:
|
|
885
|
+
type: T.COMMAND,
|
|
622
886
|
handler: async (s, e) => {
|
|
623
|
-
var
|
|
624
|
-
const { segmentId: t, textRanges: n } = e, o = s.get(
|
|
625
|
-
if (!Array.isArray(
|
|
887
|
+
var h;
|
|
888
|
+
const { segmentId: t, textRanges: n } = e, o = s.get(E), r = s.get(D), a = s.get(P), i = r.getSelections();
|
|
889
|
+
if (!Array.isArray(i) || i.length === 0)
|
|
626
890
|
return !1;
|
|
627
|
-
const c = (
|
|
891
|
+
const c = (h = a.getCurrentUniverDocInstance()) == null ? void 0 : h.getUnitId();
|
|
628
892
|
if (!c)
|
|
629
893
|
return !1;
|
|
630
|
-
const l =
|
|
631
|
-
if (d == null)
|
|
894
|
+
const l = a.getUniverDocInstance(c), d = Zt(l.getSnapshot(), t);
|
|
895
|
+
if (l == null || d == null)
|
|
632
896
|
return !1;
|
|
633
|
-
const
|
|
634
|
-
id:
|
|
897
|
+
const g = {
|
|
898
|
+
id: F.id,
|
|
635
899
|
params: {
|
|
636
900
|
unitId: c,
|
|
637
901
|
actions: [],
|
|
638
902
|
textRanges: n
|
|
639
903
|
}
|
|
640
|
-
},
|
|
641
|
-
|
|
642
|
-
const
|
|
643
|
-
for (const
|
|
644
|
-
const { startOffset:
|
|
645
|
-
|
|
646
|
-
t:
|
|
647
|
-
len:
|
|
904
|
+
}, u = new oe();
|
|
905
|
+
u.reset();
|
|
906
|
+
const I = new G(), f = w.getInstance();
|
|
907
|
+
for (const p of i) {
|
|
908
|
+
const { startOffset: R, endOffset: v, collapsed: y } = p, _ = R - u.cursor;
|
|
909
|
+
y ? I.push({
|
|
910
|
+
t: C.RETAIN,
|
|
911
|
+
len: _,
|
|
648
912
|
segmentId: t
|
|
649
|
-
}) :
|
|
913
|
+
}) : I.push(...An(p, d, t, u.cursor)), u.reset(), u.moveCursor(v);
|
|
650
914
|
}
|
|
651
|
-
|
|
915
|
+
const S = z(l, t);
|
|
916
|
+
return g.params.actions = f.editOp(I.serialize(), S), !!o.syncExecuteCommand(g.id, g.params);
|
|
652
917
|
}
|
|
653
918
|
};
|
|
654
|
-
function
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
919
|
+
function An(s, e, t = "", n = 0) {
|
|
920
|
+
var h;
|
|
921
|
+
const { startOffset: o, endOffset: r } = je(s, e), a = [], { paragraphs: i = [], dataStream: c } = e, l = o - n, d = r - n, g = i == null ? void 0 : i.find(
|
|
922
|
+
(p) => p.startIndex - n >= l && p.startIndex - n <= d
|
|
923
|
+
), u = (h = e.customRanges) == null ? void 0 : h.filter((p) => $e(p.startIndex, p.endIndex, o, r)), I = new Set(u == null ? void 0 : u.filter((p) => Ge(o, r - o, p, c))), f = /* @__PURE__ */ new Set();
|
|
924
|
+
if (u == null || u.forEach((p) => {
|
|
925
|
+
I.has(p) || (p.startIndex - n >= l && p.startIndex - n <= d && p.endIndex - n > d && f.add(p.startIndex), p.endIndex - n >= l && p.endIndex - n <= d && p.startIndex < l && f.add(p.endIndex));
|
|
926
|
+
}), l > 0 && a.push({
|
|
927
|
+
t: C.RETAIN,
|
|
928
|
+
len: l,
|
|
661
929
|
segmentId: t
|
|
662
|
-
}),
|
|
663
|
-
const
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
930
|
+
}), g && g.startIndex - n > l) {
|
|
931
|
+
const p = g.startIndex - n;
|
|
932
|
+
f.add(p);
|
|
933
|
+
}
|
|
934
|
+
const S = [...f].sort((p, R) => p - R);
|
|
935
|
+
let m = l;
|
|
936
|
+
return S.forEach((p) => {
|
|
937
|
+
const R = p - m;
|
|
938
|
+
R > 0 && a.push({
|
|
939
|
+
t: C.DELETE,
|
|
940
|
+
len: R,
|
|
667
941
|
line: 0,
|
|
668
942
|
segmentId: t
|
|
669
|
-
}),
|
|
670
|
-
t:
|
|
943
|
+
}), a.push({
|
|
944
|
+
t: C.RETAIN,
|
|
671
945
|
len: 1,
|
|
672
946
|
segmentId: t
|
|
673
|
-
}),
|
|
674
|
-
|
|
675
|
-
|
|
947
|
+
}), m = p + 1;
|
|
948
|
+
}), m < d && a.push({
|
|
949
|
+
t: C.DELETE,
|
|
950
|
+
len: d - m,
|
|
951
|
+
line: 0,
|
|
952
|
+
segmentId: t
|
|
953
|
+
}), a;
|
|
954
|
+
}
|
|
955
|
+
const Ve = {
|
|
956
|
+
id: "doc.command.merge-two-paragraph",
|
|
957
|
+
type: T.COMMAND,
|
|
958
|
+
// eslint-disable-next-line max-lines-per-function
|
|
959
|
+
handler: async (s, e) => {
|
|
960
|
+
var U, B;
|
|
961
|
+
const t = s.get(D), n = s.get(P), o = s.get(E), { direction: r, range: a } = e, i = t.getActiveRange(), c = t.getSelections();
|
|
962
|
+
if (i == null || c == null)
|
|
963
|
+
return !1;
|
|
964
|
+
const { segmentId: l, style: d } = i, g = n.getCurrentUniverDocInstance(), u = g == null ? void 0 : g.getSelfOrHeaderFooterModel(l).getBody();
|
|
965
|
+
if (!g || !u)
|
|
966
|
+
return !1;
|
|
967
|
+
const I = je(i, u), { startOffset: f, collapsed: S } = I;
|
|
968
|
+
if (!S)
|
|
969
|
+
return !1;
|
|
970
|
+
const m = r === Y.LEFT ? f : f + 1, h = (B = (U = u.paragraphs) == null ? void 0 : U.find(($) => $.startIndex >= m)) == null ? void 0 : B.startIndex, p = Pn(u, m, h), R = r === Y.LEFT ? f - 1 : f, v = g.getUnitId(), y = [
|
|
971
|
+
{
|
|
972
|
+
startOffset: R,
|
|
973
|
+
endOffset: R,
|
|
974
|
+
style: d
|
|
975
|
+
}
|
|
976
|
+
], _ = {
|
|
977
|
+
id: F.id,
|
|
978
|
+
params: {
|
|
979
|
+
unitId: v,
|
|
980
|
+
actions: [],
|
|
981
|
+
textRanges: y,
|
|
982
|
+
prevTextRanges: [a]
|
|
983
|
+
}
|
|
984
|
+
}, M = new G(), O = w.getInstance();
|
|
985
|
+
M.push({
|
|
986
|
+
t: C.RETAIN,
|
|
987
|
+
len: r === Y.LEFT ? f - 1 : f,
|
|
988
|
+
segmentId: l
|
|
989
|
+
}), p.dataStream.length && M.push({
|
|
990
|
+
t: C.INSERT,
|
|
991
|
+
body: p,
|
|
992
|
+
len: p.dataStream.length,
|
|
676
993
|
line: 0,
|
|
677
|
-
segmentId:
|
|
678
|
-
})
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
994
|
+
segmentId: l
|
|
995
|
+
}), M.push({
|
|
996
|
+
t: C.RETAIN,
|
|
997
|
+
len: 1,
|
|
998
|
+
segmentId: l
|
|
999
|
+
}), M.push({
|
|
1000
|
+
t: C.DELETE,
|
|
1001
|
+
len: h + 1 - m,
|
|
683
1002
|
line: 0,
|
|
684
|
-
segmentId:
|
|
1003
|
+
segmentId: l
|
|
685
1004
|
});
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
1005
|
+
const b = z(g, l);
|
|
1006
|
+
return _.params.actions = O.editOp(M.serialize(), b), !!o.syncExecuteCommand(_.id, _.params);
|
|
1007
|
+
}
|
|
1008
|
+
}, Nn = {
|
|
689
1009
|
id: "doc.command.delete-left",
|
|
690
|
-
type:
|
|
691
|
-
// eslint-disable-next-line max-lines-per-function
|
|
1010
|
+
type: T.COMMAND,
|
|
1011
|
+
// eslint-disable-next-line max-lines-per-function, complexity
|
|
692
1012
|
handler: async (s) => {
|
|
693
|
-
const e = s.get(
|
|
1013
|
+
const e = s.get(D), t = s.get(P), n = s.get(E);
|
|
694
1014
|
let o = !0;
|
|
695
1015
|
const r = t.getCurrentUniverDocInstance();
|
|
696
1016
|
if (!r)
|
|
697
1017
|
return !1;
|
|
698
|
-
const
|
|
1018
|
+
const a = r.getUnitId(), i = Ut(s, a), c = e.getActiveRange(), l = e.getSelections(), d = i == null ? void 0 : i.getSkeleton();
|
|
699
1019
|
if (c == null || d == null || l == null)
|
|
700
1020
|
return !1;
|
|
701
|
-
const {
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
1021
|
+
const { segmentId: g, style: u, segmentPage: I } = c, f = r.getSelfOrHeaderFooterModel(g).getBody();
|
|
1022
|
+
if (f == null)
|
|
1023
|
+
return !1;
|
|
1024
|
+
const S = je(c, f), { startOffset: m, collapsed: h } = S, p = d.findNodeByCharIndex(m, g, I), R = an(p), v = cn(p, f);
|
|
1025
|
+
let y = m;
|
|
1026
|
+
const _ = d.findNodeByCharIndex(m - 1, g, I);
|
|
1027
|
+
if (ln(p) && _ !== p && (R === !0 || v === !0) && h) {
|
|
1028
|
+
const O = dn(p, f);
|
|
1029
|
+
if (O == null)
|
|
707
1030
|
return !1;
|
|
708
|
-
const
|
|
709
|
-
if (
|
|
710
|
-
const
|
|
711
|
-
if (
|
|
712
|
-
|
|
713
|
-
const { hanging:
|
|
714
|
-
|
|
1031
|
+
const b = O == null ? void 0 : O.startIndex, x = { startIndex: 0 }, U = O.paragraphStyle;
|
|
1032
|
+
if (R === !0) {
|
|
1033
|
+
const $ = O.paragraphStyle;
|
|
1034
|
+
if ($) {
|
|
1035
|
+
x.paragraphStyle = $;
|
|
1036
|
+
const { hanging: ee } = $;
|
|
1037
|
+
ee && (x.paragraphStyle.indentStart = ee, x.paragraphStyle.hanging = void 0);
|
|
715
1038
|
}
|
|
716
1039
|
} else if (v === !0) {
|
|
717
|
-
const
|
|
718
|
-
|
|
1040
|
+
const $ = O.bullet;
|
|
1041
|
+
$ && (x.bullet = $), U != null && (x.paragraphStyle = { ...U }, delete x.paragraphStyle.hanging, delete x.paragraphStyle.indentStart);
|
|
719
1042
|
}
|
|
720
|
-
const
|
|
1043
|
+
const B = [
|
|
721
1044
|
{
|
|
722
|
-
startOffset:
|
|
723
|
-
endOffset:
|
|
724
|
-
style:
|
|
1045
|
+
startOffset: y,
|
|
1046
|
+
endOffset: y,
|
|
1047
|
+
style: u
|
|
725
1048
|
}
|
|
726
1049
|
];
|
|
727
|
-
o = await n.executeCommand(
|
|
1050
|
+
o = await n.executeCommand(wt.id, {
|
|
728
1051
|
unitId: r.getUnitId(),
|
|
729
1052
|
updateBody: {
|
|
730
1053
|
dataStream: "",
|
|
731
|
-
paragraphs: [{ ...
|
|
1054
|
+
paragraphs: [{ ...x }]
|
|
732
1055
|
},
|
|
733
1056
|
range: {
|
|
734
|
-
startOffset:
|
|
735
|
-
endOffset:
|
|
1057
|
+
startOffset: b,
|
|
1058
|
+
endOffset: b + 1
|
|
736
1059
|
},
|
|
737
|
-
textRanges:
|
|
738
|
-
coverType:
|
|
739
|
-
segmentId:
|
|
1060
|
+
textRanges: B,
|
|
1061
|
+
coverType: _e.REPLACE,
|
|
1062
|
+
segmentId: g
|
|
740
1063
|
});
|
|
741
|
-
} else if (
|
|
742
|
-
if (
|
|
1064
|
+
} else if (h === !0) {
|
|
1065
|
+
if (_ == null)
|
|
743
1066
|
return !0;
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
];
|
|
758
|
-
o = await n.executeCommand(Pe.id, {
|
|
759
|
-
unitId: r.getUnitId(),
|
|
760
|
-
range: c,
|
|
761
|
-
segmentId: m,
|
|
762
|
-
direction: k.LEFT,
|
|
763
|
-
len: C.count,
|
|
764
|
-
textRanges: R
|
|
765
|
-
});
|
|
766
|
-
}
|
|
1067
|
+
_.content === "\r" ? o = await n.executeCommand(
|
|
1068
|
+
Ve.id,
|
|
1069
|
+
{
|
|
1070
|
+
direction: Y.LEFT,
|
|
1071
|
+
range: S
|
|
1072
|
+
}
|
|
1073
|
+
) : (y -= _.count, o = await n.executeCommand(Xe.id, {
|
|
1074
|
+
unitId: r.getUnitId(),
|
|
1075
|
+
range: S,
|
|
1076
|
+
segmentId: g,
|
|
1077
|
+
direction: Y.LEFT,
|
|
1078
|
+
len: _.count
|
|
1079
|
+
}));
|
|
767
1080
|
} else {
|
|
768
|
-
const
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
1081
|
+
const O = Lt({
|
|
1082
|
+
...c,
|
|
1083
|
+
...S
|
|
1084
|
+
}, l);
|
|
1085
|
+
o = await n.executeCommand(Bt.id, {
|
|
1086
|
+
segmentId: g,
|
|
1087
|
+
textRanges: O
|
|
772
1088
|
});
|
|
773
1089
|
}
|
|
774
1090
|
return o;
|
|
775
1091
|
}
|
|
776
|
-
},
|
|
1092
|
+
}, Dn = {
|
|
777
1093
|
id: "doc.command.delete-right",
|
|
778
|
-
type:
|
|
1094
|
+
type: T.COMMAND,
|
|
779
1095
|
handler: async (s) => {
|
|
780
|
-
const e = s.get(
|
|
1096
|
+
const e = s.get(D), n = s.get(P).getCurrentUniverDocInstance();
|
|
781
1097
|
if (!n)
|
|
782
1098
|
return !1;
|
|
783
|
-
const o =
|
|
784
|
-
if (
|
|
1099
|
+
const o = Ut(s, n.getUnitId()), r = s.get(E), a = e.getActiveRange(), i = e.getSelections(), c = o == null ? void 0 : o.getSkeleton();
|
|
1100
|
+
if (a == null || c == null || i == null)
|
|
1101
|
+
return !1;
|
|
1102
|
+
const { segmentId: l, style: d, segmentPage: g } = a, u = n == null ? void 0 : n.getSelfOrHeaderFooterModel(l).getBody();
|
|
1103
|
+
if (!n || !u)
|
|
785
1104
|
return !1;
|
|
786
|
-
const
|
|
787
|
-
if (
|
|
1105
|
+
const I = Oe(a, u), { startOffset: f, collapsed: S } = I;
|
|
1106
|
+
if (f === u.dataStream.length - 2 && S)
|
|
788
1107
|
return !0;
|
|
789
1108
|
let m = !1;
|
|
790
|
-
if (
|
|
791
|
-
const h = c.findNodeByCharIndex(l);
|
|
1109
|
+
if (S === !0) {
|
|
1110
|
+
const h = c.findNodeByCharIndex(f, l, g);
|
|
792
1111
|
if (h.content === "\r")
|
|
793
|
-
m = await r.executeCommand(
|
|
794
|
-
direction:
|
|
795
|
-
range:
|
|
1112
|
+
m = await r.executeCommand(Ve.id, {
|
|
1113
|
+
direction: Y.RIGHT,
|
|
1114
|
+
range: a
|
|
796
1115
|
});
|
|
797
1116
|
else {
|
|
798
|
-
const
|
|
1117
|
+
const p = [
|
|
799
1118
|
{
|
|
800
|
-
startOffset:
|
|
801
|
-
endOffset:
|
|
802
|
-
style:
|
|
1119
|
+
startOffset: f,
|
|
1120
|
+
endOffset: f,
|
|
1121
|
+
style: d
|
|
803
1122
|
}
|
|
804
1123
|
];
|
|
805
|
-
m = await r.executeCommand(
|
|
1124
|
+
m = await r.executeCommand(Xe.id, {
|
|
806
1125
|
unitId: n.getUnitId(),
|
|
807
|
-
range:
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
1126
|
+
range: {
|
|
1127
|
+
startOffset: f,
|
|
1128
|
+
endOffset: f,
|
|
1129
|
+
collapsed: S
|
|
1130
|
+
},
|
|
1131
|
+
segmentId: l,
|
|
1132
|
+
direction: Y.RIGHT,
|
|
1133
|
+
textRanges: p,
|
|
811
1134
|
len: h.count
|
|
812
1135
|
});
|
|
813
1136
|
}
|
|
814
1137
|
} else {
|
|
815
|
-
const h =
|
|
816
|
-
m = await r.executeCommand(
|
|
817
|
-
segmentId:
|
|
1138
|
+
const h = Lt(a, i);
|
|
1139
|
+
m = await r.executeCommand(Bt.id, {
|
|
1140
|
+
segmentId: l,
|
|
818
1141
|
textRanges: h
|
|
819
1142
|
});
|
|
820
1143
|
}
|
|
821
1144
|
return m;
|
|
822
1145
|
}
|
|
823
|
-
}, Ue = {
|
|
824
|
-
id: "doc.command.merge-two-paragraph",
|
|
825
|
-
type: I.COMMAND,
|
|
826
|
-
// eslint-disable-next-line max-lines-per-function
|
|
827
|
-
handler: async (s, e) => {
|
|
828
|
-
var L, U, O;
|
|
829
|
-
const t = s.get(T), n = s.get(N), o = s.get(_), { direction: r, range: i } = e, a = t.getActiveRange(), c = t.getSelections();
|
|
830
|
-
if (a == null || c == null)
|
|
831
|
-
return !1;
|
|
832
|
-
const l = n.getCurrentUniverDocInstance();
|
|
833
|
-
if (!l)
|
|
834
|
-
return !1;
|
|
835
|
-
const { startOffset: d, collapsed: u, segmentId: g, style: m } = a;
|
|
836
|
-
if (!u)
|
|
837
|
-
return !1;
|
|
838
|
-
const h = r === k.LEFT ? d : d + 1, f = (O = (U = (L = l.getBody()) == null ? void 0 : L.paragraphs) == null ? void 0 : U.find((b) => b.startIndex >= h)) == null ? void 0 : O.startIndex, S = cn(l.getBody(), h, f), v = r === k.LEFT ? d - 1 : d, p = l.getUnitId(), C = [
|
|
839
|
-
{
|
|
840
|
-
startOffset: v,
|
|
841
|
-
endOffset: v,
|
|
842
|
-
style: m
|
|
843
|
-
}
|
|
844
|
-
], x = {
|
|
845
|
-
id: B.id,
|
|
846
|
-
params: {
|
|
847
|
-
unitId: p,
|
|
848
|
-
actions: [],
|
|
849
|
-
textRanges: C,
|
|
850
|
-
prevTextRanges: [i]
|
|
851
|
-
}
|
|
852
|
-
}, R = new F(), A = D.getInstance();
|
|
853
|
-
return R.push({
|
|
854
|
-
t: M.RETAIN,
|
|
855
|
-
len: r === k.LEFT ? d - 1 : d,
|
|
856
|
-
segmentId: g
|
|
857
|
-
}), S.dataStream.length && R.push({
|
|
858
|
-
t: M.INSERT,
|
|
859
|
-
body: S,
|
|
860
|
-
len: S.dataStream.length,
|
|
861
|
-
line: 0,
|
|
862
|
-
segmentId: g
|
|
863
|
-
}), R.push({
|
|
864
|
-
t: M.RETAIN,
|
|
865
|
-
len: 1,
|
|
866
|
-
segmentId: g
|
|
867
|
-
}), R.push({
|
|
868
|
-
t: M.DELETE,
|
|
869
|
-
len: f + 1 - h,
|
|
870
|
-
line: 0,
|
|
871
|
-
segmentId: g
|
|
872
|
-
}), x.params.actions = A.editOp(R.serialize()), !!o.syncExecuteCommand(x.id, x.params);
|
|
873
|
-
}
|
|
874
1146
|
};
|
|
875
|
-
function
|
|
1147
|
+
function Pn(s, e, t) {
|
|
876
1148
|
const { textRuns: n } = s, o = s.dataStream.substring(e, t);
|
|
877
1149
|
if (n == null)
|
|
878
1150
|
return {
|
|
879
|
-
dataStream: o
|
|
1151
|
+
dataStream: o,
|
|
1152
|
+
customRanges: it(s, e, t).customRanges,
|
|
1153
|
+
customDecorations: ct(s, e, t)
|
|
880
1154
|
};
|
|
881
1155
|
const r = [];
|
|
882
|
-
for (const
|
|
883
|
-
const { st:
|
|
884
|
-
c <= e ||
|
|
885
|
-
...
|
|
1156
|
+
for (const a of n) {
|
|
1157
|
+
const { st: i, ed: c } = a;
|
|
1158
|
+
c <= e || i >= t || (i < e ? r.push({
|
|
1159
|
+
...a,
|
|
886
1160
|
st: 0,
|
|
887
1161
|
ed: c - e
|
|
888
1162
|
}) : c > t ? r.push({
|
|
889
|
-
...
|
|
890
|
-
st:
|
|
1163
|
+
...a,
|
|
1164
|
+
st: i - e,
|
|
891
1165
|
ed: t - e
|
|
892
1166
|
}) : r.push({
|
|
893
|
-
...
|
|
894
|
-
st:
|
|
1167
|
+
...a,
|
|
1168
|
+
st: i - e,
|
|
895
1169
|
ed: c - e
|
|
896
1170
|
}));
|
|
897
1171
|
}
|
|
898
1172
|
return {
|
|
899
1173
|
dataStream: o,
|
|
900
|
-
textRuns: r
|
|
1174
|
+
textRuns: r,
|
|
1175
|
+
customRanges: it(s, e, t).customRanges,
|
|
1176
|
+
customDecorations: ct(s, e, t)
|
|
901
1177
|
};
|
|
902
1178
|
}
|
|
903
|
-
function
|
|
1179
|
+
function Lt(s, e) {
|
|
904
1180
|
let t = s.endOffset;
|
|
905
1181
|
for (const o of e) {
|
|
906
|
-
const { startOffset: r, endOffset:
|
|
907
|
-
r == null ||
|
|
1182
|
+
const { startOffset: r, endOffset: a } = o;
|
|
1183
|
+
r == null || a == null || a <= s.endOffset && (t -= a - r);
|
|
908
1184
|
}
|
|
909
1185
|
return [
|
|
910
1186
|
{
|
|
@@ -914,244 +1190,264 @@ function _t(s, e) {
|
|
|
914
1190
|
}
|
|
915
1191
|
];
|
|
916
1192
|
}
|
|
917
|
-
const
|
|
1193
|
+
const Ft = {
|
|
918
1194
|
id: "doc.command.ime-input",
|
|
919
|
-
type:
|
|
1195
|
+
type: T.COMMAND,
|
|
1196
|
+
// eslint-disable-next-line max-lines-per-function
|
|
920
1197
|
handler: async (s, e) => {
|
|
921
|
-
const { unitId: t, newText: n, oldTextLen: o, isCompositionEnd: r, isCompositionStart:
|
|
922
|
-
if (
|
|
1198
|
+
const { unitId: t, newText: n, oldTextLen: o, isCompositionEnd: r, isCompositionStart: a } = e, i = s.get(E), c = s.get(ye), d = s.get(P).getCurrentUniverDocInstance();
|
|
1199
|
+
if (d == null)
|
|
1200
|
+
return !1;
|
|
1201
|
+
const g = c.getActiveRange();
|
|
1202
|
+
if (!g)
|
|
1203
|
+
return !1;
|
|
1204
|
+
const { startOffset: u, style: I, segmentId: f } = g, S = d.getSelfOrHeaderFooterModel(f).getBody();
|
|
1205
|
+
if (S == null)
|
|
923
1206
|
return !1;
|
|
924
|
-
const
|
|
1207
|
+
const m = Oe(g, S);
|
|
1208
|
+
Object.assign(g, m);
|
|
1209
|
+
const h = n.length, p = [
|
|
925
1210
|
{
|
|
926
|
-
startOffset:
|
|
927
|
-
endOffset:
|
|
1211
|
+
startOffset: u + h,
|
|
1212
|
+
endOffset: u + h,
|
|
928
1213
|
collapsed: !0,
|
|
929
|
-
style:
|
|
1214
|
+
style: I
|
|
930
1215
|
}
|
|
931
|
-
],
|
|
932
|
-
id:
|
|
1216
|
+
], R = {
|
|
1217
|
+
id: F.id,
|
|
933
1218
|
params: {
|
|
934
1219
|
unitId: t,
|
|
935
1220
|
actions: [],
|
|
936
|
-
textRanges:
|
|
1221
|
+
textRanges: p
|
|
937
1222
|
}
|
|
938
|
-
},
|
|
939
|
-
!
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
1223
|
+
}, v = new G(), y = w.getInstance();
|
|
1224
|
+
if (!g.collapsed && a) {
|
|
1225
|
+
const { dos: O, retain: b, cursor: x } = He(g, f, 0, S);
|
|
1226
|
+
v.push(...O), R.params.textRanges = [{
|
|
1227
|
+
startOffset: u + h + b,
|
|
1228
|
+
endOffset: u + h + b,
|
|
1229
|
+
collapsed: !0
|
|
1230
|
+
}];
|
|
1231
|
+
} else
|
|
1232
|
+
v.push({
|
|
1233
|
+
t: C.RETAIN,
|
|
1234
|
+
len: u,
|
|
1235
|
+
segmentId: f
|
|
1236
|
+
});
|
|
1237
|
+
o > 0 && v.push({
|
|
1238
|
+
t: C.DELETE,
|
|
945
1239
|
len: o,
|
|
946
1240
|
line: 0,
|
|
947
|
-
segmentId:
|
|
948
|
-
}),
|
|
949
|
-
t:
|
|
1241
|
+
segmentId: f
|
|
1242
|
+
}), v.push({
|
|
1243
|
+
t: C.INSERT,
|
|
950
1244
|
body: {
|
|
951
1245
|
dataStream: n
|
|
952
1246
|
},
|
|
953
1247
|
len: n.length,
|
|
954
1248
|
line: 0,
|
|
955
|
-
segmentId:
|
|
956
|
-
})
|
|
957
|
-
const
|
|
958
|
-
|
|
1249
|
+
segmentId: f
|
|
1250
|
+
});
|
|
1251
|
+
const _ = z(d, f);
|
|
1252
|
+
R.params.actions = y.editOp(v.serialize(), _), R.params.noHistory = !r, R.params.isCompositionEnd = r;
|
|
1253
|
+
const M = i.syncExecuteCommand(R.id, R.params);
|
|
1254
|
+
return c.pushUndoRedoMutationParams(M, R.params), !!M;
|
|
959
1255
|
}
|
|
960
1256
|
};
|
|
961
|
-
function
|
|
1257
|
+
function j(s, e, t, n) {
|
|
962
1258
|
var r;
|
|
963
1259
|
const { segmentId: o } = (r = t.getActiveRange()) != null ? r : {};
|
|
964
|
-
return o == null ? !1 : n.executeCommand(
|
|
1260
|
+
return o == null ? !1 : n.executeCommand(Gt.id, {
|
|
965
1261
|
segmentId: o,
|
|
966
1262
|
preCommandId: s,
|
|
967
1263
|
...e != null ? e : {}
|
|
968
1264
|
});
|
|
969
1265
|
}
|
|
970
|
-
const
|
|
971
|
-
id:
|
|
972
|
-
type:
|
|
1266
|
+
const ht = "doc.command.set-inline-format-bold", ke = {
|
|
1267
|
+
id: ht,
|
|
1268
|
+
type: T.COMMAND,
|
|
973
1269
|
handler: async (s, e) => {
|
|
974
|
-
const t = s.get(
|
|
975
|
-
return
|
|
976
|
-
|
|
1270
|
+
const t = s.get(E), n = s.get(D);
|
|
1271
|
+
return j(
|
|
1272
|
+
ht,
|
|
977
1273
|
e,
|
|
978
1274
|
n,
|
|
979
1275
|
t
|
|
980
1276
|
);
|
|
981
1277
|
}
|
|
982
|
-
},
|
|
983
|
-
id:
|
|
984
|
-
type:
|
|
1278
|
+
}, pt = "doc.command.set-inline-format-italic", We = {
|
|
1279
|
+
id: pt,
|
|
1280
|
+
type: T.COMMAND,
|
|
985
1281
|
handler: async (s, e) => {
|
|
986
|
-
const t = s.get(
|
|
987
|
-
return
|
|
988
|
-
|
|
1282
|
+
const t = s.get(E), n = s.get(D);
|
|
1283
|
+
return j(
|
|
1284
|
+
pt,
|
|
989
1285
|
e,
|
|
990
1286
|
n,
|
|
991
1287
|
t
|
|
992
1288
|
);
|
|
993
1289
|
}
|
|
994
|
-
},
|
|
995
|
-
id:
|
|
996
|
-
type:
|
|
1290
|
+
}, St = "doc.command.set-inline-format-underline", Ye = {
|
|
1291
|
+
id: St,
|
|
1292
|
+
type: T.COMMAND,
|
|
997
1293
|
handler: async (s, e) => {
|
|
998
|
-
const t = s.get(
|
|
999
|
-
return
|
|
1000
|
-
|
|
1294
|
+
const t = s.get(E), n = s.get(D);
|
|
1295
|
+
return j(
|
|
1296
|
+
St,
|
|
1001
1297
|
e,
|
|
1002
1298
|
n,
|
|
1003
1299
|
t
|
|
1004
1300
|
);
|
|
1005
1301
|
}
|
|
1006
|
-
},
|
|
1007
|
-
id:
|
|
1008
|
-
type:
|
|
1302
|
+
}, It = "doc.command.set-inline-format-strikethrough", Ke = {
|
|
1303
|
+
id: It,
|
|
1304
|
+
type: T.COMMAND,
|
|
1009
1305
|
handler: async (s, e) => {
|
|
1010
|
-
const t = s.get(
|
|
1011
|
-
return
|
|
1012
|
-
|
|
1306
|
+
const t = s.get(E), n = s.get(D);
|
|
1307
|
+
return j(
|
|
1308
|
+
It,
|
|
1013
1309
|
e,
|
|
1014
1310
|
n,
|
|
1015
1311
|
t
|
|
1016
1312
|
);
|
|
1017
1313
|
}
|
|
1018
|
-
},
|
|
1019
|
-
id:
|
|
1020
|
-
type:
|
|
1314
|
+
}, _t = "doc.command.set-inline-format-subscript", se = {
|
|
1315
|
+
id: _t,
|
|
1316
|
+
type: T.COMMAND,
|
|
1021
1317
|
handler: async (s, e) => {
|
|
1022
|
-
const t = s.get(
|
|
1023
|
-
return
|
|
1024
|
-
|
|
1318
|
+
const t = s.get(E), n = s.get(D);
|
|
1319
|
+
return j(
|
|
1320
|
+
_t,
|
|
1025
1321
|
e,
|
|
1026
1322
|
n,
|
|
1027
1323
|
t
|
|
1028
1324
|
);
|
|
1029
1325
|
}
|
|
1030
|
-
},
|
|
1031
|
-
id:
|
|
1032
|
-
type:
|
|
1326
|
+
}, Rt = "doc.command.set-inline-format-superscript", Ze = {
|
|
1327
|
+
id: Rt,
|
|
1328
|
+
type: T.COMMAND,
|
|
1033
1329
|
handler: async (s, e) => {
|
|
1034
|
-
const t = s.get(
|
|
1035
|
-
return
|
|
1036
|
-
|
|
1330
|
+
const t = s.get(E), n = s.get(D);
|
|
1331
|
+
return j(
|
|
1332
|
+
Rt,
|
|
1037
1333
|
e,
|
|
1038
1334
|
n,
|
|
1039
1335
|
t
|
|
1040
1336
|
);
|
|
1041
1337
|
}
|
|
1042
|
-
},
|
|
1043
|
-
id:
|
|
1044
|
-
type:
|
|
1338
|
+
}, vt = "doc.command.set-inline-format-fontsize", Je = {
|
|
1339
|
+
id: vt,
|
|
1340
|
+
type: T.COMMAND,
|
|
1045
1341
|
handler: async (s, e) => {
|
|
1046
|
-
const t = s.get(
|
|
1047
|
-
return
|
|
1048
|
-
|
|
1342
|
+
const t = s.get(E), n = s.get(D);
|
|
1343
|
+
return j(
|
|
1344
|
+
vt,
|
|
1049
1345
|
e,
|
|
1050
1346
|
n,
|
|
1051
1347
|
t
|
|
1052
1348
|
);
|
|
1053
1349
|
}
|
|
1054
|
-
},
|
|
1055
|
-
id:
|
|
1056
|
-
type:
|
|
1350
|
+
}, xt = "doc.command.set-inline-format-font-family", qe = {
|
|
1351
|
+
id: xt,
|
|
1352
|
+
type: T.COMMAND,
|
|
1057
1353
|
handler: async (s, e) => {
|
|
1058
|
-
const t = s.get(
|
|
1059
|
-
return
|
|
1060
|
-
|
|
1354
|
+
const t = s.get(E), n = s.get(D);
|
|
1355
|
+
return j(
|
|
1356
|
+
xt,
|
|
1061
1357
|
e,
|
|
1062
1358
|
n,
|
|
1063
1359
|
t
|
|
1064
1360
|
);
|
|
1065
1361
|
}
|
|
1066
|
-
},
|
|
1067
|
-
id:
|
|
1068
|
-
type:
|
|
1362
|
+
}, Ct = "doc.command.set-inline-format-text-color", Qe = {
|
|
1363
|
+
id: Ct,
|
|
1364
|
+
type: T.COMMAND,
|
|
1069
1365
|
handler: async (s, e) => {
|
|
1070
|
-
const t = s.get(
|
|
1071
|
-
return
|
|
1072
|
-
|
|
1366
|
+
const t = s.get(E), n = s.get(D);
|
|
1367
|
+
return j(
|
|
1368
|
+
Ct,
|
|
1073
1369
|
e,
|
|
1074
1370
|
n,
|
|
1075
1371
|
t
|
|
1076
1372
|
);
|
|
1077
1373
|
}
|
|
1078
|
-
},
|
|
1079
|
-
id:
|
|
1080
|
-
type:
|
|
1374
|
+
}, Ot = "doc.command.set-inline-format-text-background-color", et = {
|
|
1375
|
+
id: Ot,
|
|
1376
|
+
type: T.COMMAND,
|
|
1081
1377
|
handler: async (s, e) => {
|
|
1082
|
-
const t = s.get(
|
|
1083
|
-
return
|
|
1084
|
-
|
|
1378
|
+
const t = s.get(E), n = s.get(D);
|
|
1379
|
+
return j(
|
|
1380
|
+
Ot,
|
|
1085
1381
|
e,
|
|
1086
1382
|
n,
|
|
1087
1383
|
t
|
|
1088
1384
|
);
|
|
1089
1385
|
}
|
|
1090
|
-
},
|
|
1091
|
-
id:
|
|
1092
|
-
type:
|
|
1386
|
+
}, Mt = "doc.command.reset-inline-format-text-background-color", tt = {
|
|
1387
|
+
id: Mt,
|
|
1388
|
+
type: T.COMMAND,
|
|
1093
1389
|
handler: async (s, e) => {
|
|
1094
|
-
const t = s.get(
|
|
1095
|
-
return
|
|
1096
|
-
|
|
1390
|
+
const t = s.get(E), n = s.get(D);
|
|
1391
|
+
return j(
|
|
1392
|
+
Mt,
|
|
1097
1393
|
e,
|
|
1098
1394
|
n,
|
|
1099
1395
|
t
|
|
1100
1396
|
);
|
|
1101
1397
|
}
|
|
1102
|
-
},
|
|
1103
|
-
[
|
|
1104
|
-
[
|
|
1105
|
-
[
|
|
1106
|
-
[
|
|
1107
|
-
[
|
|
1108
|
-
[
|
|
1109
|
-
[
|
|
1110
|
-
[
|
|
1111
|
-
[
|
|
1112
|
-
[
|
|
1113
|
-
[
|
|
1114
|
-
},
|
|
1398
|
+
}, $t = {
|
|
1399
|
+
[ke.id]: "bl",
|
|
1400
|
+
[We.id]: "it",
|
|
1401
|
+
[Ye.id]: "ul",
|
|
1402
|
+
[Ke.id]: "st",
|
|
1403
|
+
[Je.id]: "fs",
|
|
1404
|
+
[qe.id]: "ff",
|
|
1405
|
+
[Qe.id]: "cl",
|
|
1406
|
+
[et.id]: "bg",
|
|
1407
|
+
[tt.id]: "bg",
|
|
1408
|
+
[se.id]: "va",
|
|
1409
|
+
[Ze.id]: "va"
|
|
1410
|
+
}, Gt = {
|
|
1115
1411
|
id: "doc.command.set-inline-format",
|
|
1116
|
-
type:
|
|
1412
|
+
type: T.COMMAND,
|
|
1117
1413
|
// eslint-disable-next-line max-lines-per-function
|
|
1118
1414
|
handler: async (s, e) => {
|
|
1119
|
-
const { segmentId: t, value: n, preCommandId: o } = e, r = s.get(
|
|
1415
|
+
const { segmentId: t, value: n, preCommandId: o } = e, r = s.get(E), a = s.get(D), i = s.get(P), c = a.getSelections();
|
|
1120
1416
|
if (!Array.isArray(c) || c.length === 0)
|
|
1121
1417
|
return !1;
|
|
1122
|
-
const l =
|
|
1123
|
-
if (
|
|
1418
|
+
const l = i.getCurrentUniverDocInstance();
|
|
1419
|
+
if (l == null)
|
|
1124
1420
|
return !1;
|
|
1125
1421
|
const d = l.getUnitId();
|
|
1126
|
-
let
|
|
1422
|
+
let g;
|
|
1127
1423
|
switch (o) {
|
|
1128
|
-
case
|
|
1129
|
-
case
|
|
1130
|
-
case
|
|
1131
|
-
case
|
|
1132
|
-
case
|
|
1133
|
-
case
|
|
1134
|
-
|
|
1135
|
-
l.getBody().textRuns,
|
|
1424
|
+
case ke.id:
|
|
1425
|
+
case We.id:
|
|
1426
|
+
case Ye.id:
|
|
1427
|
+
case Ke.id:
|
|
1428
|
+
case se.id:
|
|
1429
|
+
case Ze.id: {
|
|
1430
|
+
g = Un(
|
|
1431
|
+
l.getSelfOrHeaderFooterModel(t).getBody().textRuns,
|
|
1136
1432
|
o,
|
|
1137
1433
|
c
|
|
1138
1434
|
);
|
|
1139
1435
|
break;
|
|
1140
1436
|
}
|
|
1141
|
-
case
|
|
1142
|
-
case
|
|
1143
|
-
|
|
1437
|
+
case Je.id:
|
|
1438
|
+
case qe.id: {
|
|
1439
|
+
g = n;
|
|
1144
1440
|
break;
|
|
1145
1441
|
}
|
|
1146
|
-
case
|
|
1147
|
-
case
|
|
1148
|
-
|
|
1442
|
+
case Qe.id:
|
|
1443
|
+
case et.id: {
|
|
1444
|
+
g = {
|
|
1149
1445
|
rgb: n
|
|
1150
1446
|
};
|
|
1151
1447
|
break;
|
|
1152
1448
|
}
|
|
1153
|
-
case
|
|
1154
|
-
|
|
1449
|
+
case tt.id: {
|
|
1450
|
+
g = {
|
|
1155
1451
|
rgb: null
|
|
1156
1452
|
};
|
|
1157
1453
|
break;
|
|
@@ -1159,318 +1455,235 @@ const tt = "doc.command.set-inline-format-bold", we = {
|
|
|
1159
1455
|
default:
|
|
1160
1456
|
throw new Error(`Unknown command: ${o} in handleInlineFormat`);
|
|
1161
1457
|
}
|
|
1162
|
-
const
|
|
1163
|
-
id:
|
|
1458
|
+
const u = {
|
|
1459
|
+
id: F.id,
|
|
1164
1460
|
params: {
|
|
1165
1461
|
unitId: d,
|
|
1166
1462
|
actions: [],
|
|
1167
|
-
textRanges: c.map(
|
|
1463
|
+
textRanges: c.map(q)
|
|
1168
1464
|
}
|
|
1169
|
-
},
|
|
1170
|
-
|
|
1171
|
-
for (const
|
|
1172
|
-
const { startOffset:
|
|
1465
|
+
}, I = new G(), f = w.getInstance(), S = new oe();
|
|
1466
|
+
S.reset();
|
|
1467
|
+
for (const p of c) {
|
|
1468
|
+
const { startOffset: R, endOffset: v } = p, y = {
|
|
1173
1469
|
dataStream: "",
|
|
1174
1470
|
textRuns: [
|
|
1175
1471
|
{
|
|
1176
1472
|
st: 0,
|
|
1177
|
-
ed:
|
|
1473
|
+
ed: v - R,
|
|
1178
1474
|
ts: {
|
|
1179
|
-
[
|
|
1475
|
+
[$t[o]]: g
|
|
1180
1476
|
}
|
|
1181
1477
|
}
|
|
1182
1478
|
]
|
|
1183
|
-
},
|
|
1184
|
-
|
|
1185
|
-
t:
|
|
1186
|
-
len:
|
|
1479
|
+
}, _ = R - S.cursor;
|
|
1480
|
+
_ !== 0 && I.push({
|
|
1481
|
+
t: C.RETAIN,
|
|
1482
|
+
len: _,
|
|
1187
1483
|
segmentId: t
|
|
1188
|
-
}),
|
|
1189
|
-
t:
|
|
1190
|
-
body:
|
|
1191
|
-
len:
|
|
1484
|
+
}), I.push({
|
|
1485
|
+
t: C.RETAIN,
|
|
1486
|
+
body: y,
|
|
1487
|
+
len: v - R,
|
|
1192
1488
|
segmentId: t
|
|
1193
|
-
}),
|
|
1489
|
+
}), S.reset(), S.moveCursor(v);
|
|
1194
1490
|
}
|
|
1195
|
-
|
|
1491
|
+
const m = z(l, t);
|
|
1492
|
+
return u.params.actions = f.editOp(I.serialize(), m), !!r.syncExecuteCommand(u.id, u.params);
|
|
1196
1493
|
}
|
|
1197
1494
|
};
|
|
1198
|
-
function
|
|
1495
|
+
function bn(s) {
|
|
1199
1496
|
return s !== null && typeof s == "object";
|
|
1200
1497
|
}
|
|
1201
|
-
function
|
|
1498
|
+
function Un(s, e, t) {
|
|
1202
1499
|
let n = 0, o = 0;
|
|
1203
|
-
const r =
|
|
1500
|
+
const r = $t[e];
|
|
1204
1501
|
for (; n !== s.length && o !== t.length; ) {
|
|
1205
|
-
const { startOffset:
|
|
1206
|
-
if (
|
|
1502
|
+
const { startOffset: a, endOffset: i } = t[o], { st: c, ed: l, ts: d } = s[n];
|
|
1503
|
+
if (i <= c)
|
|
1207
1504
|
o++;
|
|
1208
|
-
else if (l <=
|
|
1505
|
+
else if (l <= a)
|
|
1209
1506
|
n++;
|
|
1210
1507
|
else {
|
|
1211
1508
|
if (/bl|it/.test(r))
|
|
1212
|
-
return (d == null ? void 0 : d[r]) ===
|
|
1509
|
+
return (d == null ? void 0 : d[r]) === k.TRUE ? k.FALSE : k.TRUE;
|
|
1213
1510
|
if (/ul|st/.test(r))
|
|
1214
|
-
return
|
|
1215
|
-
s:
|
|
1511
|
+
return bn(d == null ? void 0 : d[r]) && (d == null ? void 0 : d[r]).s === k.TRUE ? {
|
|
1512
|
+
s: k.FALSE
|
|
1216
1513
|
} : {
|
|
1217
|
-
s:
|
|
1514
|
+
s: k.TRUE
|
|
1218
1515
|
};
|
|
1219
1516
|
if (/va/.test(r))
|
|
1220
|
-
return e ===
|
|
1517
|
+
return e === se.id ? (d == null ? void 0 : d[r]) === W.SUBSCRIPT ? W.NORMAL : W.SUBSCRIPT : (d == null ? void 0 : d[r]) === W.SUPERSCRIPT ? W.NORMAL : W.SUPERSCRIPT;
|
|
1221
1518
|
n++;
|
|
1222
1519
|
}
|
|
1223
1520
|
}
|
|
1224
|
-
return /bl|it/.test(r) ?
|
|
1225
|
-
s:
|
|
1226
|
-
} : e ===
|
|
1521
|
+
return /bl|it/.test(r) ? k.TRUE : /ul|st/.test(r) ? {
|
|
1522
|
+
s: k.TRUE
|
|
1523
|
+
} : e === se.id ? W.SUBSCRIPT : W.SUPERSCRIPT;
|
|
1227
1524
|
}
|
|
1228
|
-
const
|
|
1525
|
+
const nt = {
|
|
1229
1526
|
id: "doc.command.list-operation",
|
|
1230
|
-
type:
|
|
1527
|
+
type: T.COMMAND,
|
|
1231
1528
|
// eslint-disable-next-line max-lines-per-function
|
|
1232
1529
|
handler: (s, e) => {
|
|
1233
|
-
var
|
|
1234
|
-
const t = s.get(
|
|
1235
|
-
if (
|
|
1530
|
+
var B, $, ee, st;
|
|
1531
|
+
const t = s.get(D), n = s.get(P), o = s.get(E), { listType: r } = e, a = n.getCurrentUniverDocInstance(), i = t.getActiveRange();
|
|
1532
|
+
if (a == null || i == null)
|
|
1236
1533
|
return !1;
|
|
1237
|
-
const
|
|
1238
|
-
if (
|
|
1534
|
+
const { segmentId: c } = i, l = (B = t.getSelections()) != null ? B : [], d = ($ = a.getSelfOrHeaderFooterModel(c).getBody()) == null ? void 0 : $.paragraphs, g = l.map(q);
|
|
1535
|
+
if (d == null)
|
|
1239
1536
|
return !1;
|
|
1240
|
-
const u =
|
|
1241
|
-
var
|
|
1242
|
-
return ((
|
|
1537
|
+
const u = zt(i, d), I = a.getUnitId(), f = u.every((K) => {
|
|
1538
|
+
var H;
|
|
1539
|
+
return ((H = K.bullet) == null ? void 0 : H.listType) === r;
|
|
1243
1540
|
});
|
|
1244
|
-
let
|
|
1541
|
+
let m = J.generateRandomId(6);
|
|
1245
1542
|
if (u.length === 1) {
|
|
1246
|
-
const
|
|
1247
|
-
|
|
1543
|
+
const K = d.indexOf(u[0]), H = d[K - 1], V = d[K + 1];
|
|
1544
|
+
H && H.bullet && H.bullet.listType === r ? m = H.bullet.listId : V && V.bullet && V.bullet.listType === r && (m = V.bullet.listId);
|
|
1248
1545
|
}
|
|
1249
|
-
const
|
|
1250
|
-
id:
|
|
1546
|
+
const h = {
|
|
1547
|
+
id: F.id,
|
|
1251
1548
|
params: {
|
|
1252
|
-
unitId:
|
|
1549
|
+
unitId: I,
|
|
1253
1550
|
actions: [],
|
|
1254
|
-
textRanges:
|
|
1551
|
+
textRanges: g
|
|
1255
1552
|
}
|
|
1256
|
-
}, p = new
|
|
1553
|
+
}, p = new oe();
|
|
1257
1554
|
p.reset();
|
|
1258
|
-
const
|
|
1259
|
-
...
|
|
1260
|
-
...
|
|
1261
|
-
}, { charSpace:
|
|
1262
|
-
for (const
|
|
1263
|
-
const { startIndex:
|
|
1264
|
-
|
|
1265
|
-
t:
|
|
1266
|
-
len:
|
|
1267
|
-
segmentId:
|
|
1268
|
-
}),
|
|
1269
|
-
t:
|
|
1555
|
+
const R = new G(), v = w.getInstance(), y = (ee = a.getSnapshot().lists) != null ? ee : {}, _ = {
|
|
1556
|
+
...Jt,
|
|
1557
|
+
...y
|
|
1558
|
+
}, { charSpace: M, defaultTabStop: O = 36, gridType: b } = a.getSnapshot().documentStyle;
|
|
1559
|
+
for (const K of u) {
|
|
1560
|
+
const { startIndex: H, paragraphStyle: V = {} } = K, { indentFirstLine: Ht = 0, snapToGrid: Xt, indentStart: Te = 0 } = V, { hanging: Ee, indentStart: ot } = _[r].nestingLevel[0], Ae = un(M, O, b, Xt);
|
|
1561
|
+
R.push({
|
|
1562
|
+
t: C.RETAIN,
|
|
1563
|
+
len: H - p.cursor,
|
|
1564
|
+
segmentId: c
|
|
1565
|
+
}), R.push({
|
|
1566
|
+
t: C.RETAIN,
|
|
1270
1567
|
len: 1,
|
|
1271
1568
|
body: {
|
|
1272
1569
|
dataStream: "",
|
|
1273
1570
|
paragraphs: [
|
|
1274
|
-
|
|
1571
|
+
f ? {
|
|
1275
1572
|
paragraphStyle: {
|
|
1276
|
-
...
|
|
1573
|
+
...V,
|
|
1277
1574
|
hanging: void 0,
|
|
1278
|
-
indentStart:
|
|
1575
|
+
indentStart: Te ? Math.max(0, Ne(Te, Ae) + Ee - ot) : void 0
|
|
1279
1576
|
},
|
|
1280
1577
|
startIndex: 0
|
|
1281
1578
|
} : {
|
|
1282
1579
|
startIndex: 0,
|
|
1283
1580
|
paragraphStyle: {
|
|
1284
|
-
...
|
|
1581
|
+
...V,
|
|
1285
1582
|
indentFirstLine: void 0,
|
|
1286
|
-
hanging:
|
|
1287
|
-
indentStart:
|
|
1583
|
+
hanging: Ee,
|
|
1584
|
+
indentStart: ot - Ee + Ne(Ht, Ae) + Ne(Te, Ae)
|
|
1288
1585
|
},
|
|
1289
1586
|
bullet: {
|
|
1290
|
-
...(
|
|
1587
|
+
...(st = K.bullet) != null ? st : {
|
|
1291
1588
|
nestingLevel: 0,
|
|
1292
1589
|
textStyle: {
|
|
1293
1590
|
fs: 20
|
|
1294
1591
|
}
|
|
1295
1592
|
},
|
|
1296
1593
|
listType: r,
|
|
1297
|
-
listId:
|
|
1594
|
+
listId: m
|
|
1298
1595
|
}
|
|
1299
1596
|
}
|
|
1300
1597
|
]
|
|
1301
1598
|
},
|
|
1302
|
-
segmentId:
|
|
1303
|
-
coverType:
|
|
1304
|
-
}), p.moveCursorTo(
|
|
1599
|
+
segmentId: c,
|
|
1600
|
+
coverType: _e.REPLACE
|
|
1601
|
+
}), p.moveCursorTo(H + 1);
|
|
1305
1602
|
}
|
|
1306
|
-
|
|
1603
|
+
const x = z(a, c);
|
|
1604
|
+
return h.params.actions = v.editOp(R.serialize(), x), !!o.syncExecuteCommand(h.id, h.params);
|
|
1307
1605
|
}
|
|
1308
|
-
},
|
|
1606
|
+
}, wn = {
|
|
1309
1607
|
id: "doc.command.bullet-list",
|
|
1310
|
-
type:
|
|
1311
|
-
handler: (s) => s.get(
|
|
1312
|
-
listType:
|
|
1608
|
+
type: T.COMMAND,
|
|
1609
|
+
handler: (s) => s.get(E).syncExecuteCommand(nt.id, {
|
|
1610
|
+
listType: At.BULLET_LIST
|
|
1313
1611
|
})
|
|
1314
|
-
},
|
|
1612
|
+
}, Bn = {
|
|
1315
1613
|
id: "doc.command.order-list",
|
|
1316
|
-
type:
|
|
1317
|
-
handler: (s) => s.get(
|
|
1318
|
-
listType:
|
|
1614
|
+
type: T.COMMAND,
|
|
1615
|
+
handler: (s) => s.get(E).syncExecuteCommand(nt.id, {
|
|
1616
|
+
listType: At.ORDER_LIST
|
|
1319
1617
|
})
|
|
1320
1618
|
};
|
|
1321
|
-
function
|
|
1619
|
+
function zt(s, e) {
|
|
1322
1620
|
const { startOffset: t, endOffset: n } = s, o = [];
|
|
1323
1621
|
let r = -1;
|
|
1324
|
-
for (const
|
|
1325
|
-
const { startIndex:
|
|
1326
|
-
(t > r && t <=
|
|
1622
|
+
for (const a of e) {
|
|
1623
|
+
const { startIndex: i } = a;
|
|
1624
|
+
(t > r && t <= i || n > r && n <= i || i >= t && i <= n) && o.push(a), r = i;
|
|
1327
1625
|
}
|
|
1328
1626
|
return o;
|
|
1329
1627
|
}
|
|
1330
|
-
const
|
|
1331
|
-
id: "doc.command.align-operation",
|
|
1332
|
-
type: I.COMMAND,
|
|
1333
|
-
// eslint-disable-next-line max-lines-per-function
|
|
1334
|
-
handler: (s, e) => {
|
|
1335
|
-
var x, R;
|
|
1336
|
-
const t = s.get(T), n = s.get(N), o = s.get(_), { alignType: r } = e, i = n.getCurrentUniverDocInstance();
|
|
1337
|
-
if (!i) return !1;
|
|
1338
|
-
const a = t.getActiveRange(), c = (x = t.getSelections()) != null ? x : [], l = (R = i.getBody()) == null ? void 0 : R.paragraphs, d = c.map(W);
|
|
1339
|
-
if (a == null || l == null) return !1;
|
|
1340
|
-
const u = xt(a, l), { segmentId: g } = a, m = i.getUnitId(), h = u.every((A) => {
|
|
1341
|
-
var E;
|
|
1342
|
-
return ((E = A.paragraphStyle) == null ? void 0 : E.horizontalAlign) === r;
|
|
1343
|
-
}), f = {
|
|
1344
|
-
id: B.id,
|
|
1345
|
-
params: {
|
|
1346
|
-
unitId: m,
|
|
1347
|
-
actions: [],
|
|
1348
|
-
textRanges: d
|
|
1349
|
-
}
|
|
1350
|
-
}, S = new q();
|
|
1351
|
-
S.reset();
|
|
1352
|
-
const v = new F(), p = D.getInstance();
|
|
1353
|
-
for (const A of u) {
|
|
1354
|
-
const { startIndex: E } = A;
|
|
1355
|
-
v.push({
|
|
1356
|
-
t: M.RETAIN,
|
|
1357
|
-
len: E - S.cursor,
|
|
1358
|
-
segmentId: g
|
|
1359
|
-
});
|
|
1360
|
-
const L = {
|
|
1361
|
-
...A.paragraphStyle,
|
|
1362
|
-
horizontalAlign: h ? Q.UNSPECIFIED : r
|
|
1363
|
-
};
|
|
1364
|
-
v.push({
|
|
1365
|
-
t: M.RETAIN,
|
|
1366
|
-
len: 1,
|
|
1367
|
-
body: {
|
|
1368
|
-
dataStream: "",
|
|
1369
|
-
paragraphs: [
|
|
1370
|
-
{
|
|
1371
|
-
...A,
|
|
1372
|
-
paragraphStyle: L,
|
|
1373
|
-
startIndex: 0
|
|
1374
|
-
}
|
|
1375
|
-
]
|
|
1376
|
-
},
|
|
1377
|
-
segmentId: g,
|
|
1378
|
-
coverType: Te.REPLACE
|
|
1379
|
-
}), S.moveCursorTo(E + 1);
|
|
1380
|
-
}
|
|
1381
|
-
return f.params.actions = p.editOp(v.serialize()), !!o.syncExecuteCommand(f.id, f.params);
|
|
1382
|
-
}
|
|
1383
|
-
}, mn = {
|
|
1384
|
-
id: "doc.command.align-left",
|
|
1385
|
-
type: I.COMMAND,
|
|
1386
|
-
handler: (s) => s.get(_).syncExecuteCommand(ne.id, {
|
|
1387
|
-
alignType: Q.LEFT
|
|
1388
|
-
})
|
|
1389
|
-
}, fn = {
|
|
1390
|
-
id: "doc.command.align-center",
|
|
1391
|
-
type: I.COMMAND,
|
|
1392
|
-
handler: (s) => s.get(_).syncExecuteCommand(ne.id, {
|
|
1393
|
-
alignType: Q.CENTER
|
|
1394
|
-
})
|
|
1395
|
-
}, hn = {
|
|
1396
|
-
id: "doc.command.align-right",
|
|
1397
|
-
type: I.COMMAND,
|
|
1398
|
-
handler: (s) => s.get(_).syncExecuteCommand(ne.id, {
|
|
1399
|
-
alignType: Q.RIGHT
|
|
1400
|
-
})
|
|
1401
|
-
}, pn = {
|
|
1402
|
-
id: "doc.command.align-justify",
|
|
1403
|
-
type: I.COMMAND,
|
|
1404
|
-
handler: (s) => s.get(_).syncExecuteCommand(ne.id, {
|
|
1405
|
-
alignType: Q.JUSTIFIED
|
|
1406
|
-
})
|
|
1407
|
-
}, Sn = {
|
|
1628
|
+
const Ln = {
|
|
1408
1629
|
id: "doc.command-replace-content",
|
|
1409
|
-
type:
|
|
1630
|
+
type: T.COMMAND,
|
|
1410
1631
|
handler: async (s, e) => {
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
if (l == null || !Array.isArray(d) || d.length === 0)
|
|
1632
|
+
const { unitId: t, body: n, textRanges: o, segmentId: r = "" } = e, a = s.get(P), i = s.get(E), c = s.get(D), l = a.getUniverDocInstance(t), d = l == null ? void 0 : l.getSnapshot().body, g = c.getSelections();
|
|
1633
|
+
if (l == null || d == null || !Array.isArray(g) || g.length === 0)
|
|
1414
1634
|
return !1;
|
|
1415
|
-
const u =
|
|
1416
|
-
return u.params.textRanges = o, !!
|
|
1635
|
+
const u = jt(t, r, l, d, n);
|
|
1636
|
+
return u.params.textRanges = o, !!i.syncExecuteCommand(u.id, u.params);
|
|
1417
1637
|
}
|
|
1418
|
-
},
|
|
1638
|
+
}, Fn = {
|
|
1419
1639
|
id: "doc.command-cover-content",
|
|
1420
|
-
type:
|
|
1640
|
+
type: T.COMMAND,
|
|
1421
1641
|
handler: async (s, e) => {
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
if (c == null)
|
|
1642
|
+
const { unitId: t, body: n, segmentId: o = "" } = e, r = s.get(P), a = s.get(E), i = s.get(Fe), c = r.getUniverDocInstance(t), l = c == null ? void 0 : c.getSnapshot().body;
|
|
1643
|
+
if (c == null || l == null)
|
|
1425
1644
|
return !1;
|
|
1426
|
-
const
|
|
1427
|
-
return
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
),
|
|
1645
|
+
const d = jt(t, o, c, l, n);
|
|
1646
|
+
return d.params.noNeedSetTextRange = !0, d.params.noHistory = !0, a.syncExecuteCommand(
|
|
1647
|
+
d.id,
|
|
1648
|
+
d.params
|
|
1649
|
+
), i.clearUndoRedo(t), !0;
|
|
1431
1650
|
}
|
|
1432
1651
|
};
|
|
1433
|
-
function
|
|
1434
|
-
const
|
|
1435
|
-
id:
|
|
1652
|
+
function jt(s, e, t, n, o) {
|
|
1653
|
+
const r = {
|
|
1654
|
+
id: F.id,
|
|
1436
1655
|
params: {
|
|
1437
1656
|
unitId: s,
|
|
1438
1657
|
actions: [],
|
|
1439
1658
|
textRanges: []
|
|
1440
1659
|
}
|
|
1441
|
-
},
|
|
1442
|
-
|
|
1443
|
-
t:
|
|
1444
|
-
len:
|
|
1660
|
+
}, a = new G(), i = w.getInstance(), c = (n == null ? void 0 : n.dataStream.length) - 2;
|
|
1661
|
+
c > 0 && a.push({
|
|
1662
|
+
t: C.DELETE,
|
|
1663
|
+
len: c,
|
|
1445
1664
|
line: 0,
|
|
1446
1665
|
segmentId: e
|
|
1447
|
-
}),
|
|
1448
|
-
t:
|
|
1449
|
-
body:
|
|
1450
|
-
len:
|
|
1666
|
+
}), o.dataStream.length > 0 && a.push({
|
|
1667
|
+
t: C.INSERT,
|
|
1668
|
+
body: o,
|
|
1669
|
+
len: o.dataStream.length,
|
|
1451
1670
|
line: 0,
|
|
1452
1671
|
segmentId: e
|
|
1453
|
-
})
|
|
1672
|
+
});
|
|
1673
|
+
const l = z(t, e);
|
|
1674
|
+
return r.params.actions = i.editOp(a.serialize(), l), r;
|
|
1454
1675
|
}
|
|
1455
|
-
const
|
|
1456
|
-
|
|
1457
|
-
type: I.OPERATION,
|
|
1458
|
-
handler: (s, e) => !!e
|
|
1459
|
-
}, xe = {
|
|
1460
|
-
id: "doc.operation.move-selection",
|
|
1461
|
-
type: I.OPERATION,
|
|
1462
|
-
handler: (s, e) => !!e
|
|
1463
|
-
}, _n = (s, e) => {
|
|
1464
|
-
const t = s.get(N).getUniverDocInstance(e.unitId), n = (t == null ? void 0 : t.zoomRatio) || 1;
|
|
1676
|
+
const $n = (s, e) => {
|
|
1677
|
+
const t = s.get(P).getUniverDocInstance(e.unitId), n = (t == null ? void 0 : t.zoomRatio) || 1;
|
|
1465
1678
|
return {
|
|
1466
1679
|
...J.deepClone(e),
|
|
1467
1680
|
zoomRatio: n
|
|
1468
1681
|
};
|
|
1469
|
-
},
|
|
1682
|
+
}, ge = {
|
|
1470
1683
|
id: "doc.operation.set-zoom-ratio",
|
|
1471
|
-
type:
|
|
1684
|
+
type: T.OPERATION,
|
|
1472
1685
|
handler: (s, e) => {
|
|
1473
|
-
const t = s.get(
|
|
1686
|
+
const t = s.get(P).getUniverDocInstance(e.unitId);
|
|
1474
1687
|
if (!t)
|
|
1475
1688
|
return !1;
|
|
1476
1689
|
const n = t.getSnapshot();
|
|
@@ -1478,56 +1691,66 @@ const Re = {
|
|
|
1478
1691
|
zoomRatio: e.zoomRatio
|
|
1479
1692
|
} : n.settings.zoomRatio = e.zoomRatio, !0;
|
|
1480
1693
|
}
|
|
1481
|
-
},
|
|
1482
|
-
type:
|
|
1694
|
+
}, Gn = {
|
|
1695
|
+
type: T.COMMAND,
|
|
1483
1696
|
id: "doc.command.set-zoom-ratio",
|
|
1484
1697
|
handler: async (s, e) => {
|
|
1485
|
-
var
|
|
1486
|
-
const t = s.get(
|
|
1487
|
-
let r = (
|
|
1698
|
+
var g, u, I;
|
|
1699
|
+
const t = s.get(E), n = s.get(Fe), o = s.get(P);
|
|
1700
|
+
let r = (g = o.getCurrentUniverDocInstance()) == null ? void 0 : g.getUnitId();
|
|
1488
1701
|
if (!r) return !1;
|
|
1489
|
-
let
|
|
1490
|
-
if (e && (r = (
|
|
1702
|
+
let a = 1;
|
|
1703
|
+
if (e && (r = (u = e.documentId) != null ? u : r, a = (I = e.zoomRatio) != null ? I : a), !o.getUniverDocInstance(r)) return !1;
|
|
1491
1704
|
const c = {
|
|
1492
|
-
zoomRatio:
|
|
1705
|
+
zoomRatio: a,
|
|
1493
1706
|
unitId: r
|
|
1494
|
-
}, l =
|
|
1495
|
-
return t.syncExecuteCommand(
|
|
1707
|
+
}, l = $n(s, c);
|
|
1708
|
+
return t.syncExecuteCommand(ge.id, c) ? (n.pushUndoRedo({
|
|
1496
1709
|
unitID: r,
|
|
1497
|
-
undoMutations: [{ id:
|
|
1498
|
-
redoMutations: [{ id:
|
|
1710
|
+
undoMutations: [{ id: ge.id, params: l }],
|
|
1711
|
+
redoMutations: [{ id: ge.id, params: c }]
|
|
1499
1712
|
}), !0) : !1;
|
|
1500
1713
|
}
|
|
1501
|
-
},
|
|
1714
|
+
}, we = {
|
|
1715
|
+
id: "doc.operation.move-cursor",
|
|
1716
|
+
type: T.OPERATION,
|
|
1717
|
+
handler: (s, e) => !!e
|
|
1718
|
+
}, Be = {
|
|
1719
|
+
id: "doc.operation.move-selection",
|
|
1720
|
+
type: T.OPERATION,
|
|
1721
|
+
handler: (s, e) => !!e
|
|
1722
|
+
}, zn = {
|
|
1502
1723
|
id: "doc.operation.select-all",
|
|
1503
|
-
type:
|
|
1724
|
+
type: T.COMMAND,
|
|
1504
1725
|
handler: async (s) => {
|
|
1505
|
-
const e = s.get(
|
|
1506
|
-
if (
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1726
|
+
const e = s.get(P), t = s.get(D), n = e.getCurrentUniverDocInstance(), o = t.getActiveRange();
|
|
1727
|
+
if (n == null || o == null)
|
|
1728
|
+
return !1;
|
|
1729
|
+
const { segmentId: r } = o, a = n.getSelfOrHeaderFooterModel(r).getSnapshot().body;
|
|
1730
|
+
if (a == null)
|
|
1731
|
+
return !1;
|
|
1732
|
+
const i = [
|
|
1510
1733
|
{
|
|
1511
1734
|
startOffset: 0,
|
|
1512
|
-
endOffset:
|
|
1735
|
+
endOffset: a.dataStream.length - 2
|
|
1513
1736
|
}
|
|
1514
1737
|
];
|
|
1515
|
-
return t.replaceTextRanges(
|
|
1738
|
+
return t.replaceTextRanges(i, !1), !0;
|
|
1516
1739
|
}
|
|
1517
1740
|
};
|
|
1518
|
-
var
|
|
1519
|
-
for (var o = n > 1 ? void 0 : n ?
|
|
1520
|
-
(
|
|
1521
|
-
return n && o &&
|
|
1522
|
-
},
|
|
1523
|
-
let
|
|
1741
|
+
var jn = Object.defineProperty, Hn = Object.getOwnPropertyDescriptor, Xn = (s, e, t, n) => {
|
|
1742
|
+
for (var o = n > 1 ? void 0 : n ? Hn(e, t) : e, r = s.length - 1, a; r >= 0; r--)
|
|
1743
|
+
(a = s[r]) && (o = (n ? a(e, t, o) : a(o)) || o);
|
|
1744
|
+
return n && o && jn(e, t, o), o;
|
|
1745
|
+
}, te = (s, e) => (t, n) => e(t, n, s);
|
|
1746
|
+
let fe = class extends xe {
|
|
1524
1747
|
constructor(e, t, n, o, r) {
|
|
1525
1748
|
super();
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1749
|
+
A(this, "_previousIMEContent", "");
|
|
1750
|
+
A(this, "_isCompositionStart", !0);
|
|
1751
|
+
A(this, "_onStartSubscription");
|
|
1752
|
+
A(this, "_onUpdateSubscription");
|
|
1753
|
+
A(this, "_onEndSubscription");
|
|
1531
1754
|
this._univerInstanceService = e, this._renderManagerSrv = t, this._textSelectionRenderManager = n, this._imeInputManagerService = o, this._commandService = r, this._initialize();
|
|
1532
1755
|
}
|
|
1533
1756
|
dispose() {
|
|
@@ -1563,11 +1786,11 @@ let ce = class extends Ne {
|
|
|
1563
1786
|
const n = this._univerInstanceService.getCurrentUniverDocInstance();
|
|
1564
1787
|
if (!n)
|
|
1565
1788
|
return;
|
|
1566
|
-
const o = (l = this._renderManagerSrv.getRenderById(n.getUnitId())) == null ? void 0 : l.with(
|
|
1567
|
-
if (o == null ||
|
|
1789
|
+
const o = (l = this._renderManagerSrv.getRenderById(n.getUnitId())) == null ? void 0 : l.with(X).getSkeleton(), { event: r, activeRange: a } = e;
|
|
1790
|
+
if (o == null || a == null)
|
|
1568
1791
|
return;
|
|
1569
1792
|
const c = r.data;
|
|
1570
|
-
c === this._previousIMEContent && t || (await this._commandService.executeCommand(
|
|
1793
|
+
c === this._previousIMEContent && t || (await this._commandService.executeCommand(Ft.id, {
|
|
1571
1794
|
unitId: n.getUnitId(),
|
|
1572
1795
|
newText: c,
|
|
1573
1796
|
oldTextLen: this._previousIMEContent.length,
|
|
@@ -1579,23 +1802,23 @@ let ce = class extends Ne {
|
|
|
1579
1802
|
this._previousIMEContent = "", this._isCompositionStart = !0, this._imeInputManagerService.clearUndoRedoMutationParamsCache(), this._imeInputManagerService.setActiveRange(null);
|
|
1580
1803
|
}
|
|
1581
1804
|
};
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
],
|
|
1590
|
-
var
|
|
1591
|
-
for (var o = n > 1 ? void 0 : n ?
|
|
1592
|
-
(
|
|
1593
|
-
return n && o &&
|
|
1594
|
-
},
|
|
1595
|
-
let
|
|
1805
|
+
fe = Xn([
|
|
1806
|
+
Re(ve.Rendered, fe),
|
|
1807
|
+
te(0, P),
|
|
1808
|
+
te(1, ae),
|
|
1809
|
+
te(2, Ce),
|
|
1810
|
+
te(3, Q(ye)),
|
|
1811
|
+
te(4, E)
|
|
1812
|
+
], fe);
|
|
1813
|
+
var Vn = Object.defineProperty, kn = Object.getOwnPropertyDescriptor, Wn = (s, e, t, n) => {
|
|
1814
|
+
for (var o = n > 1 ? void 0 : n ? kn(e, t) : e, r = s.length - 1, a; r >= 0; r--)
|
|
1815
|
+
(a = s[r]) && (o = (n ? a(e, t, o) : a(o)) || o);
|
|
1816
|
+
return n && o && Vn(e, t, o), o;
|
|
1817
|
+
}, le = (s, e) => (t, n) => e(t, n, s);
|
|
1818
|
+
let me = class extends xe {
|
|
1596
1819
|
constructor(e, t, n, o) {
|
|
1597
1820
|
super();
|
|
1598
|
-
|
|
1821
|
+
A(this, "_onInputSubscription");
|
|
1599
1822
|
this._univerInstanceService = e, this._renderManagerService = t, this._textSelectionManagerService = n, this._commandService = o, this._commandExecutedListener();
|
|
1600
1823
|
}
|
|
1601
1824
|
dispose() {
|
|
@@ -1603,16 +1826,16 @@ let le = class extends Ne {
|
|
|
1603
1826
|
super.dispose(), (e = this._onInputSubscription) == null || e.unsubscribe();
|
|
1604
1827
|
}
|
|
1605
1828
|
_commandExecutedListener() {
|
|
1606
|
-
const e = [
|
|
1829
|
+
const e = [we.id, Be.id];
|
|
1607
1830
|
this.disposeWithMe(
|
|
1608
1831
|
this._commandService.onCommandExecuted((t) => {
|
|
1609
1832
|
if (!e.includes(t.id))
|
|
1610
1833
|
return;
|
|
1611
1834
|
const n = t.params;
|
|
1612
1835
|
switch (t.id) {
|
|
1613
|
-
case
|
|
1836
|
+
case we.id:
|
|
1614
1837
|
return this._handleMoveCursor(n.direction);
|
|
1615
|
-
case
|
|
1838
|
+
case Be.id:
|
|
1616
1839
|
return this._handleShiftMoveSelection(n.direction);
|
|
1617
1840
|
default:
|
|
1618
1841
|
throw new Error("Unknown command");
|
|
@@ -1622,156 +1845,171 @@ let le = class extends Ne {
|
|
|
1622
1845
|
}
|
|
1623
1846
|
// eslint-disable-next-line max-lines-per-function, complexity
|
|
1624
1847
|
_handleShiftMoveSelection(e) {
|
|
1625
|
-
var
|
|
1848
|
+
var R, v, y;
|
|
1626
1849
|
const t = this._textSelectionManagerService.getActiveRange(), n = this._textSelectionManagerService.getSelections(), o = this._univerInstanceService.getCurrentUniverDocInstance();
|
|
1627
1850
|
if (!o)
|
|
1628
1851
|
return;
|
|
1629
|
-
const r = (
|
|
1630
|
-
if (t == null || r == null ||
|
|
1852
|
+
const r = (R = this._renderManagerService.getRenderById(o.getUnitId())) == null ? void 0 : R.with(X).getSkeleton(), a = this._getDocObject();
|
|
1853
|
+
if (t == null || r == null || a == null)
|
|
1631
1854
|
return;
|
|
1632
|
-
const {
|
|
1855
|
+
const {
|
|
1856
|
+
startOffset: i,
|
|
1857
|
+
endOffset: c,
|
|
1858
|
+
style: l,
|
|
1859
|
+
collapsed: d,
|
|
1860
|
+
direction: g,
|
|
1861
|
+
segmentId: u,
|
|
1862
|
+
startNodePosition: I,
|
|
1863
|
+
endNodePosition: f,
|
|
1864
|
+
segmentPage: S
|
|
1865
|
+
} = t;
|
|
1633
1866
|
if (n.length > 1) {
|
|
1634
|
-
let
|
|
1635
|
-
for (const
|
|
1636
|
-
|
|
1867
|
+
let _ = Number.POSITIVE_INFINITY, M = Number.NEGATIVE_INFINITY;
|
|
1868
|
+
for (const O of n)
|
|
1869
|
+
_ = Math.min(_, O.startOffset), M = Math.max(M, O.endOffset);
|
|
1637
1870
|
this._textSelectionManagerService.replaceTextRanges([
|
|
1638
1871
|
{
|
|
1639
|
-
startOffset: e ===
|
|
1640
|
-
endOffset: e ===
|
|
1872
|
+
startOffset: e === L.LEFT || e === L.UP ? M : _,
|
|
1873
|
+
endOffset: e === L.LEFT || e === L.UP ? _ : M,
|
|
1641
1874
|
style: l
|
|
1642
1875
|
}
|
|
1643
1876
|
], !1);
|
|
1644
1877
|
return;
|
|
1645
1878
|
}
|
|
1646
|
-
const
|
|
1647
|
-
let
|
|
1648
|
-
const
|
|
1649
|
-
if (e ===
|
|
1650
|
-
const
|
|
1651
|
-
|
|
1879
|
+
const m = d || g === De.FORWARD ? i : c;
|
|
1880
|
+
let h = d || g === De.FORWARD ? c : i;
|
|
1881
|
+
const p = (v = o.getSelfOrHeaderFooterModel(u).getBody().dataStream.length) != null ? v : Number.POSITIVE_INFINITY;
|
|
1882
|
+
if (e === L.LEFT || e === L.RIGHT) {
|
|
1883
|
+
const _ = r.findNodeByCharIndex(h - 1, u, S), M = r.findNodeByCharIndex(h, u, S);
|
|
1884
|
+
h = e === L.RIGHT ? h + M.count : h - ((y = _ == null ? void 0 : _.count) != null ? y : 0), h = Math.min(p - 2, Math.max(0, h)), this._textSelectionManagerService.replaceTextRanges([
|
|
1652
1885
|
{
|
|
1653
|
-
startOffset:
|
|
1654
|
-
endOffset:
|
|
1886
|
+
startOffset: m,
|
|
1887
|
+
endOffset: h,
|
|
1655
1888
|
style: l
|
|
1656
1889
|
}
|
|
1657
1890
|
], !1);
|
|
1658
1891
|
} else {
|
|
1659
|
-
const
|
|
1660
|
-
if (
|
|
1661
|
-
const
|
|
1662
|
-
if (
|
|
1892
|
+
const _ = r.findNodeByCharIndex(h, u, S), M = a.document.getOffsetConfig(), O = d ? I : g === De.FORWARD ? f : I, b = this._getTopOrBottomPosition(r, _, O, e === L.DOWN);
|
|
1893
|
+
if (b == null) {
|
|
1894
|
+
const U = e === L.UP ? 0 : p - 2;
|
|
1895
|
+
if (U === h)
|
|
1663
1896
|
return;
|
|
1664
1897
|
this._textSelectionManagerService.replaceTextRanges([
|
|
1665
1898
|
{
|
|
1666
|
-
startOffset:
|
|
1667
|
-
endOffset:
|
|
1899
|
+
startOffset: m,
|
|
1900
|
+
endOffset: U,
|
|
1668
1901
|
style: l
|
|
1669
1902
|
}
|
|
1670
1903
|
], !1);
|
|
1671
1904
|
return;
|
|
1672
1905
|
}
|
|
1673
|
-
const
|
|
1674
|
-
|
|
1675
|
-
|
|
1906
|
+
const x = new lt(M, r).getRangePointData(
|
|
1907
|
+
b,
|
|
1908
|
+
b
|
|
1676
1909
|
).cursorList[0];
|
|
1677
1910
|
this._textSelectionManagerService.replaceTextRanges([
|
|
1678
1911
|
{
|
|
1679
|
-
startOffset:
|
|
1680
|
-
endOffset:
|
|
1912
|
+
startOffset: m,
|
|
1913
|
+
endOffset: x.endOffset,
|
|
1681
1914
|
style: l
|
|
1682
1915
|
}
|
|
1683
1916
|
], !1);
|
|
1684
1917
|
}
|
|
1685
1918
|
}
|
|
1919
|
+
// eslint-disable-next-line max-lines-per-function, complexity
|
|
1686
1920
|
_handleMoveCursor(e) {
|
|
1687
|
-
var
|
|
1921
|
+
var m, h, p;
|
|
1688
1922
|
const t = this._textSelectionManagerService.getActiveRange(), n = this._textSelectionManagerService.getSelections(), o = this._univerInstanceService.getCurrentUniverDocInstance();
|
|
1689
1923
|
if (!o)
|
|
1690
1924
|
return !1;
|
|
1691
|
-
const r = (
|
|
1692
|
-
if (t == null || r == null ||
|
|
1925
|
+
const r = (m = this._renderManagerService.getRenderById(o.getUnitId())) == null ? void 0 : m.with(X).getSkeleton(), a = this._getDocObject();
|
|
1926
|
+
if (t == null || r == null || a == null || n == null)
|
|
1693
1927
|
return;
|
|
1694
|
-
const { startOffset:
|
|
1695
|
-
if (e ===
|
|
1696
|
-
let
|
|
1928
|
+
const { startOffset: i, endOffset: c, style: l, collapsed: d, segmentId: g, startNodePosition: u, endNodePosition: I, segmentPage: f } = t, S = (h = o.getSelfOrHeaderFooterModel(g).getBody().dataStream.length) != null ? h : Number.POSITIVE_INFINITY;
|
|
1929
|
+
if (e === L.LEFT || e === L.RIGHT) {
|
|
1930
|
+
let R;
|
|
1697
1931
|
if (!t.collapsed || n.length > 1) {
|
|
1698
|
-
let
|
|
1699
|
-
for (const
|
|
1700
|
-
|
|
1701
|
-
|
|
1932
|
+
let v = Number.POSITIVE_INFINITY, y = Number.NEGATIVE_INFINITY;
|
|
1933
|
+
for (const _ of n)
|
|
1934
|
+
v = Math.min(v, _.startOffset), y = Math.max(y, _.endOffset);
|
|
1935
|
+
R = e === L.LEFT ? v : y;
|
|
1702
1936
|
} else {
|
|
1703
|
-
const
|
|
1704
|
-
e ===
|
|
1937
|
+
const v = r.findNodeByCharIndex(i - 1, g, f), y = r.findNodeByCharIndex(i, g, f);
|
|
1938
|
+
e === L.LEFT ? R = Math.max(0, i - ((p = v == null ? void 0 : v.count) != null ? p : 0)) : R = Math.min(S - 2, c + y.count);
|
|
1705
1939
|
}
|
|
1706
1940
|
this._textSelectionManagerService.replaceTextRanges([
|
|
1707
1941
|
{
|
|
1708
|
-
startOffset:
|
|
1709
|
-
endOffset:
|
|
1942
|
+
startOffset: R,
|
|
1943
|
+
endOffset: R,
|
|
1710
1944
|
style: l
|
|
1711
1945
|
}
|
|
1712
1946
|
], !1);
|
|
1713
1947
|
} else {
|
|
1714
|
-
const
|
|
1948
|
+
const R = r.findNodeByCharIndex(i, g, f), v = r.findNodeByCharIndex(c, g, f), y = a.document.getOffsetConfig(), _ = this._getTopOrBottomPosition(
|
|
1715
1949
|
r,
|
|
1716
|
-
e ===
|
|
1717
|
-
e ===
|
|
1950
|
+
e === L.UP ? R : v,
|
|
1951
|
+
e === L.UP ? u : I,
|
|
1952
|
+
e === L.DOWN
|
|
1718
1953
|
);
|
|
1719
|
-
if (
|
|
1720
|
-
let
|
|
1721
|
-
d ?
|
|
1954
|
+
if (_ == null) {
|
|
1955
|
+
let O;
|
|
1956
|
+
d ? O = e === L.UP ? 0 : S - 2 : O = e === L.UP ? i : c, this._textSelectionManagerService.replaceTextRanges([
|
|
1722
1957
|
{
|
|
1723
|
-
startOffset:
|
|
1724
|
-
endOffset:
|
|
1958
|
+
startOffset: O,
|
|
1959
|
+
endOffset: O,
|
|
1725
1960
|
style: l
|
|
1726
1961
|
}
|
|
1727
1962
|
], !1);
|
|
1728
1963
|
return;
|
|
1729
1964
|
}
|
|
1730
|
-
const
|
|
1731
|
-
|
|
1732
|
-
|
|
1965
|
+
const M = new lt(y, r).getRangePointData(
|
|
1966
|
+
_,
|
|
1967
|
+
_
|
|
1733
1968
|
).cursorList[0];
|
|
1734
1969
|
this._textSelectionManagerService.replaceTextRanges([
|
|
1735
1970
|
{
|
|
1736
|
-
...
|
|
1971
|
+
...M,
|
|
1737
1972
|
style: l
|
|
1738
1973
|
}
|
|
1739
1974
|
], !1);
|
|
1740
1975
|
}
|
|
1741
1976
|
}
|
|
1742
|
-
_getTopOrBottomPosition(e, t, n) {
|
|
1743
|
-
if (t == null)
|
|
1977
|
+
_getTopOrBottomPosition(e, t, n, o) {
|
|
1978
|
+
if (t == null || n == null)
|
|
1744
1979
|
return;
|
|
1745
|
-
const
|
|
1746
|
-
if (
|
|
1980
|
+
const r = this._getGlyphLeftOffsetInLine(t), a = this._getNextOrPrevLine(t, o);
|
|
1981
|
+
if (a == null)
|
|
1747
1982
|
return;
|
|
1748
|
-
const i = this._matchPositionByLeftOffset(e, r,
|
|
1983
|
+
const i = this._matchPositionByLeftOffset(e, a, r, n);
|
|
1749
1984
|
if (i != null)
|
|
1750
1985
|
return { ...i, isBack: !0 };
|
|
1751
1986
|
}
|
|
1752
|
-
|
|
1987
|
+
_getGlyphLeftOffsetInLine(e) {
|
|
1753
1988
|
const t = e.parent;
|
|
1754
1989
|
if (t == null)
|
|
1755
1990
|
return Number.NEGATIVE_INFINITY;
|
|
1756
1991
|
const n = t.left, { left: o } = e;
|
|
1757
1992
|
return n + o;
|
|
1758
1993
|
}
|
|
1759
|
-
_matchPositionByLeftOffset(e, t, n) {
|
|
1760
|
-
const
|
|
1994
|
+
_matchPositionByLeftOffset(e, t, n, o) {
|
|
1995
|
+
const r = {
|
|
1761
1996
|
distance: Number.POSITIVE_INFINITY
|
|
1762
1997
|
};
|
|
1763
|
-
for (const
|
|
1764
|
-
const
|
|
1765
|
-
for (const
|
|
1766
|
-
const { left:
|
|
1767
|
-
|
|
1998
|
+
for (const i of t.divides) {
|
|
1999
|
+
const c = i.left;
|
|
2000
|
+
for (const l of i.glyphGroup) {
|
|
2001
|
+
const { left: d } = l, g = c + d, u = Math.abs(n - g);
|
|
2002
|
+
u < r.distance && (r.glyph = l, r.distance = u);
|
|
1768
2003
|
}
|
|
1769
2004
|
}
|
|
1770
|
-
if (
|
|
1771
|
-
return
|
|
2005
|
+
if (r.glyph == null)
|
|
2006
|
+
return;
|
|
2007
|
+
const { segmentPage: a } = o;
|
|
2008
|
+
return e.findPositionByGlyph(r.glyph, a);
|
|
1772
2009
|
}
|
|
2010
|
+
// eslint-disable-next-line max-lines-per-function
|
|
1773
2011
|
_getNextOrPrevLine(e, t) {
|
|
1774
|
-
var
|
|
2012
|
+
var f, S, m, h, p, R, v, y, _, M, O, b;
|
|
1775
2013
|
const n = e.parent;
|
|
1776
2014
|
if (n == null)
|
|
1777
2015
|
return;
|
|
@@ -1781,12 +2019,12 @@ let le = class extends Ne {
|
|
|
1781
2019
|
const r = o.parent;
|
|
1782
2020
|
if (r == null)
|
|
1783
2021
|
return;
|
|
1784
|
-
const
|
|
1785
|
-
if (
|
|
2022
|
+
const a = r.lines.indexOf(o);
|
|
2023
|
+
if (a === -1)
|
|
1786
2024
|
return;
|
|
1787
|
-
let
|
|
1788
|
-
if (t === !0 ?
|
|
1789
|
-
return
|
|
2025
|
+
let i;
|
|
2026
|
+
if (t === !0 ? i = r.lines[a + 1] : i = r.lines[a - 1], i != null)
|
|
2027
|
+
return i;
|
|
1790
2028
|
const c = r.parent;
|
|
1791
2029
|
if (c == null)
|
|
1792
2030
|
return;
|
|
@@ -1794,65 +2032,65 @@ let le = class extends Ne {
|
|
|
1794
2032
|
if (l === -1)
|
|
1795
2033
|
return;
|
|
1796
2034
|
if (t === !0)
|
|
1797
|
-
|
|
2035
|
+
i = (f = c.columns[l + 1]) == null ? void 0 : f.lines[0];
|
|
1798
2036
|
else {
|
|
1799
|
-
const
|
|
1800
|
-
|
|
2037
|
+
const x = (m = (S = c.columns) == null ? void 0 : S[l - 1]) == null ? void 0 : m.lines;
|
|
2038
|
+
i = x == null ? void 0 : x[x.length - 1];
|
|
1801
2039
|
}
|
|
1802
|
-
if (
|
|
1803
|
-
return
|
|
2040
|
+
if (i != null)
|
|
2041
|
+
return i;
|
|
1804
2042
|
const d = c.parent;
|
|
1805
2043
|
if (d == null)
|
|
1806
2044
|
return;
|
|
1807
|
-
const
|
|
1808
|
-
if (
|
|
2045
|
+
const g = d.sections.indexOf(c);
|
|
2046
|
+
if (g === -1)
|
|
1809
2047
|
return;
|
|
1810
2048
|
if (t === !0)
|
|
1811
|
-
|
|
2049
|
+
i = (p = (h = d.sections[g - 1]) == null ? void 0 : h.columns[0]) == null ? void 0 : p.lines[0];
|
|
1812
2050
|
else {
|
|
1813
|
-
const
|
|
1814
|
-
|
|
2051
|
+
const x = (v = (R = d.sections) == null ? void 0 : R[g - 1]) == null ? void 0 : v.columns, U = x == null ? void 0 : x[x.length - 1], B = U == null ? void 0 : U.lines;
|
|
2052
|
+
i = B == null ? void 0 : B[B.length - 1];
|
|
1815
2053
|
}
|
|
1816
|
-
if (
|
|
1817
|
-
return
|
|
1818
|
-
const
|
|
1819
|
-
if (
|
|
2054
|
+
if (i != null)
|
|
2055
|
+
return i;
|
|
2056
|
+
const u = d.parent;
|
|
2057
|
+
if (u == null)
|
|
1820
2058
|
return;
|
|
1821
|
-
const
|
|
1822
|
-
if (
|
|
2059
|
+
const I = u.pages.indexOf(d);
|
|
2060
|
+
if (I !== -1) {
|
|
1823
2061
|
if (t === !0)
|
|
1824
|
-
|
|
2062
|
+
i = (M = (_ = (y = u.pages[I + 1]) == null ? void 0 : y.sections[0]) == null ? void 0 : _.columns[0]) == null ? void 0 : M.lines[0];
|
|
1825
2063
|
else {
|
|
1826
|
-
const
|
|
1827
|
-
if (
|
|
2064
|
+
const x = (O = u.pages[I - 1]) == null ? void 0 : O.sections;
|
|
2065
|
+
if (x == null)
|
|
1828
2066
|
return;
|
|
1829
|
-
const
|
|
1830
|
-
|
|
2067
|
+
const U = (b = x[x.length - 1]) == null ? void 0 : b.columns, B = U[U.length - 1], $ = B == null ? void 0 : B.lines;
|
|
2068
|
+
i = $[$.length - 1];
|
|
1831
2069
|
}
|
|
1832
|
-
if (
|
|
1833
|
-
return
|
|
2070
|
+
if (i != null)
|
|
2071
|
+
return i;
|
|
1834
2072
|
}
|
|
1835
2073
|
}
|
|
1836
2074
|
_getDocObject() {
|
|
1837
|
-
return
|
|
2075
|
+
return Sn(this._univerInstanceService, this._renderManagerService);
|
|
1838
2076
|
}
|
|
1839
2077
|
};
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
],
|
|
1847
|
-
var
|
|
1848
|
-
for (var o = n > 1 ? void 0 : n ?
|
|
1849
|
-
(
|
|
1850
|
-
return n && o &&
|
|
1851
|
-
},
|
|
1852
|
-
let
|
|
2078
|
+
me = Wn([
|
|
2079
|
+
Re(ve.Rendered, me),
|
|
2080
|
+
le(0, P),
|
|
2081
|
+
le(1, ae),
|
|
2082
|
+
le(2, Q(D)),
|
|
2083
|
+
le(3, E)
|
|
2084
|
+
], me);
|
|
2085
|
+
var Yn = Object.defineProperty, Kn = Object.getOwnPropertyDescriptor, Zn = (s, e, t, n) => {
|
|
2086
|
+
for (var o = n > 1 ? void 0 : n ? Kn(e, t) : e, r = s.length - 1, a; r >= 0; r--)
|
|
2087
|
+
(a = s[r]) && (o = (n ? a(e, t, o) : a(o)) || o);
|
|
2088
|
+
return n && o && Yn(e, t, o), o;
|
|
2089
|
+
}, de = (s, e) => (t, n) => e(t, n, s);
|
|
2090
|
+
let he = class extends xe {
|
|
1853
2091
|
constructor(e, t, n, o) {
|
|
1854
2092
|
super();
|
|
1855
|
-
|
|
2093
|
+
A(this, "_onInputSubscription");
|
|
1856
2094
|
this._univerInstanceService = e, this._renderManagerService = t, this._textSelectionRenderManager = n, this._commandService = o, this._init();
|
|
1857
2095
|
}
|
|
1858
2096
|
dispose() {
|
|
@@ -1864,170 +2102,613 @@ let de = class extends Ne {
|
|
|
1864
2102
|
}
|
|
1865
2103
|
_initialNormalInput() {
|
|
1866
2104
|
this._onInputSubscription = this._textSelectionRenderManager.onInput$.subscribe(async (e) => {
|
|
1867
|
-
var
|
|
2105
|
+
var S;
|
|
1868
2106
|
if (e == null)
|
|
1869
2107
|
return;
|
|
1870
2108
|
const t = this._univerInstanceService.getCurrentUniverDocInstance();
|
|
1871
2109
|
if (!t)
|
|
1872
2110
|
return;
|
|
1873
|
-
const n = t.getUnitId(), { event: o, content: r = "", activeRange:
|
|
1874
|
-
if (
|
|
2111
|
+
const n = t.getUnitId(), { event: o, content: r = "", activeRange: a } = e, i = o, c = (S = this._renderManagerService.getRenderById(t.getUnitId())) == null ? void 0 : S.with(X).getSkeleton();
|
|
2112
|
+
if (i.data == null || c == null || !c || !a)
|
|
1875
2113
|
return;
|
|
1876
|
-
const { startOffset: l, segmentId: d, style: u } =
|
|
2114
|
+
const { startOffset: l, segmentId: d, style: g, segmentPage: u } = a, I = r.length, f = [
|
|
1877
2115
|
{
|
|
1878
|
-
startOffset: l +
|
|
1879
|
-
endOffset: l +
|
|
1880
|
-
|
|
2116
|
+
startOffset: l + I,
|
|
2117
|
+
endOffset: l + I,
|
|
2118
|
+
segmentId: d,
|
|
2119
|
+
segmentPage: u,
|
|
2120
|
+
style: g
|
|
1881
2121
|
}
|
|
1882
2122
|
];
|
|
1883
|
-
await this._commandService.executeCommand(
|
|
2123
|
+
await this._commandService.executeCommand(Ie.id, {
|
|
1884
2124
|
unitId: n,
|
|
1885
2125
|
body: {
|
|
1886
2126
|
dataStream: r
|
|
1887
2127
|
},
|
|
1888
|
-
|
|
1889
|
-
|
|
2128
|
+
textRanges: f,
|
|
2129
|
+
range: a,
|
|
1890
2130
|
segmentId: d
|
|
1891
2131
|
});
|
|
1892
2132
|
});
|
|
1893
2133
|
}
|
|
1894
2134
|
};
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
],
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
2135
|
+
he = Zn([
|
|
2136
|
+
Re(ve.Rendered, he),
|
|
2137
|
+
de(0, P),
|
|
2138
|
+
de(1, ae),
|
|
2139
|
+
de(2, Ce),
|
|
2140
|
+
de(3, E)
|
|
2141
|
+
], he);
|
|
2142
|
+
const ce = {
|
|
2143
|
+
id: "doc.command.align-operation",
|
|
2144
|
+
type: T.COMMAND,
|
|
2145
|
+
// eslint-disable-next-line max-lines-per-function
|
|
2146
|
+
handler: (s, e) => {
|
|
2147
|
+
var y, _;
|
|
2148
|
+
const t = s.get(D), n = s.get(P), o = s.get(E), { alignType: r } = e, a = n.getCurrentUniverDocInstance(), i = t.getActiveRange();
|
|
2149
|
+
if (a == null || i == null)
|
|
2150
|
+
return !1;
|
|
2151
|
+
const { segmentId: c } = i, l = (y = t.getSelections()) != null ? y : [], d = (_ = a.getSelfOrHeaderFooterModel(c).getBody()) == null ? void 0 : _.paragraphs, g = l.map(q);
|
|
2152
|
+
if (d == null)
|
|
2153
|
+
return !1;
|
|
2154
|
+
const u = zt(i, d), I = a.getUnitId(), f = u.every((M) => {
|
|
2155
|
+
var O;
|
|
2156
|
+
return ((O = M.paragraphStyle) == null ? void 0 : O.horizontalAlign) === r;
|
|
2157
|
+
}), S = {
|
|
2158
|
+
id: F.id,
|
|
2159
|
+
params: {
|
|
2160
|
+
unitId: I,
|
|
2161
|
+
actions: [],
|
|
2162
|
+
textRanges: g
|
|
2163
|
+
}
|
|
2164
|
+
}, m = new oe();
|
|
2165
|
+
m.reset();
|
|
2166
|
+
const h = new G(), p = w.getInstance();
|
|
2167
|
+
for (const M of u) {
|
|
2168
|
+
const { startIndex: O } = M;
|
|
2169
|
+
h.push({
|
|
2170
|
+
t: C.RETAIN,
|
|
2171
|
+
len: O - m.cursor,
|
|
2172
|
+
segmentId: c
|
|
2173
|
+
});
|
|
2174
|
+
const b = {
|
|
2175
|
+
...M.paragraphStyle,
|
|
2176
|
+
horizontalAlign: f ? re.UNSPECIFIED : r
|
|
2177
|
+
};
|
|
2178
|
+
h.push({
|
|
2179
|
+
t: C.RETAIN,
|
|
2180
|
+
len: 1,
|
|
2181
|
+
body: {
|
|
2182
|
+
dataStream: "",
|
|
2183
|
+
paragraphs: [
|
|
2184
|
+
{
|
|
2185
|
+
...M,
|
|
2186
|
+
paragraphStyle: b,
|
|
2187
|
+
startIndex: 0
|
|
2188
|
+
}
|
|
2189
|
+
]
|
|
2190
|
+
},
|
|
2191
|
+
segmentId: c,
|
|
2192
|
+
coverType: _e.REPLACE
|
|
2193
|
+
}), m.moveCursorTo(O + 1);
|
|
2194
|
+
}
|
|
2195
|
+
const R = z(a, c);
|
|
2196
|
+
return S.params.actions = p.editOp(h.serialize(), R), !!o.syncExecuteCommand(S.id, S.params);
|
|
2197
|
+
}
|
|
2198
|
+
}, Jn = {
|
|
2199
|
+
id: "doc.command.align-left",
|
|
2200
|
+
type: T.COMMAND,
|
|
2201
|
+
handler: (s) => s.get(E).syncExecuteCommand(ce.id, {
|
|
2202
|
+
alignType: re.LEFT
|
|
2203
|
+
})
|
|
2204
|
+
}, qn = {
|
|
2205
|
+
id: "doc.command.align-center",
|
|
2206
|
+
type: T.COMMAND,
|
|
2207
|
+
handler: (s) => s.get(E).syncExecuteCommand(ce.id, {
|
|
2208
|
+
alignType: re.CENTER
|
|
2209
|
+
})
|
|
2210
|
+
}, Qn = {
|
|
2211
|
+
id: "doc.command.align-right",
|
|
2212
|
+
type: T.COMMAND,
|
|
2213
|
+
handler: (s) => s.get(E).syncExecuteCommand(ce.id, {
|
|
2214
|
+
alignType: re.RIGHT
|
|
2215
|
+
})
|
|
2216
|
+
}, es = {
|
|
2217
|
+
id: "doc.command.align-justify",
|
|
2218
|
+
type: T.COMMAND,
|
|
2219
|
+
handler: (s) => s.get(E).syncExecuteCommand(ce.id, {
|
|
2220
|
+
alignType: re.JUSTIFIED
|
|
2221
|
+
})
|
|
2222
|
+
};
|
|
2223
|
+
class ts {
|
|
2224
|
+
constructor() {
|
|
2225
|
+
A(this, "_customRangeHooks", []);
|
|
2226
|
+
}
|
|
2227
|
+
addClipboardHook(e) {
|
|
2228
|
+
return this._customRangeHooks.push(e), Nt(() => {
|
|
2229
|
+
const t = this._customRangeHooks.indexOf(e);
|
|
2230
|
+
t > -1 && this._customRangeHooks.splice(t, 1);
|
|
2231
|
+
});
|
|
2232
|
+
}
|
|
2233
|
+
copyCustomRange(e) {
|
|
2234
|
+
let t = { ...e };
|
|
2235
|
+
return this._customRangeHooks.forEach((n) => {
|
|
2236
|
+
n.onCopyCustomRange && (t = n.onCopyCustomRange(t));
|
|
2237
|
+
}), t;
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
var ns = Object.defineProperty, ss = Object.getOwnPropertyDescriptor, os = (s, e, t, n) => {
|
|
2241
|
+
for (var o = n > 1 ? void 0 : n ? ss(e, t) : e, r = s.length - 1, a; r >= 0; r--)
|
|
2242
|
+
(a = s[r]) && (o = (n ? a(e, t, o) : a(o)) || o);
|
|
2243
|
+
return n && o && ns(e, t, o), o;
|
|
2244
|
+
}, rs = (s, e) => (t, n) => e(t, n, s);
|
|
2245
|
+
const as = "docs";
|
|
2246
|
+
var ue;
|
|
2247
|
+
let yt = (ue = class extends qt {
|
|
1910
2248
|
constructor(s = {}, e) {
|
|
1911
2249
|
super(), this._injector = e, this._initializeDependencies(e), this._initializeCommands();
|
|
1912
2250
|
}
|
|
1913
2251
|
_initializeCommands() {
|
|
1914
2252
|
[
|
|
1915
|
-
Re,
|
|
1916
|
-
xe,
|
|
1917
|
-
rn,
|
|
1918
|
-
an,
|
|
1919
2253
|
we,
|
|
1920
|
-
Le,
|
|
1921
2254
|
Be,
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
2255
|
+
Nn,
|
|
2256
|
+
Dn,
|
|
2257
|
+
ke,
|
|
2258
|
+
We,
|
|
2259
|
+
Ye,
|
|
2260
|
+
Ke,
|
|
2261
|
+
se,
|
|
2262
|
+
Ze,
|
|
2263
|
+
Je,
|
|
2264
|
+
qe,
|
|
2265
|
+
Qe,
|
|
2266
|
+
tt,
|
|
2267
|
+
et,
|
|
2268
|
+
Gt,
|
|
2269
|
+
En,
|
|
2270
|
+
Ie,
|
|
1928
2271
|
Xe,
|
|
2272
|
+
wt,
|
|
2273
|
+
Ft,
|
|
1929
2274
|
Ve,
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
un,
|
|
1946
|
-
ke,
|
|
1947
|
-
mn,
|
|
1948
|
-
fn,
|
|
1949
|
-
hn,
|
|
1950
|
-
ne,
|
|
1951
|
-
pn
|
|
2275
|
+
F,
|
|
2276
|
+
Ln,
|
|
2277
|
+
Fn,
|
|
2278
|
+
Gn,
|
|
2279
|
+
ge,
|
|
2280
|
+
bt,
|
|
2281
|
+
zn,
|
|
2282
|
+
Bn,
|
|
2283
|
+
wn,
|
|
2284
|
+
nt,
|
|
2285
|
+
Jn,
|
|
2286
|
+
qn,
|
|
2287
|
+
Qn,
|
|
2288
|
+
ce,
|
|
2289
|
+
es
|
|
1952
2290
|
].forEach((s) => {
|
|
1953
|
-
this._injector.get(
|
|
2291
|
+
this._injector.get(E).registerCommand(s);
|
|
1954
2292
|
});
|
|
1955
2293
|
}
|
|
1956
2294
|
_initializeDependencies(s) {
|
|
1957
2295
|
[
|
|
1958
2296
|
// services
|
|
1959
|
-
[
|
|
1960
|
-
[
|
|
2297
|
+
[Se],
|
|
2298
|
+
[ye],
|
|
1961
2299
|
[
|
|
1962
|
-
|
|
2300
|
+
Ce,
|
|
1963
2301
|
{
|
|
1964
|
-
useClass:
|
|
2302
|
+
useClass: gn
|
|
1965
2303
|
}
|
|
1966
2304
|
],
|
|
1967
|
-
[
|
|
2305
|
+
[D],
|
|
2306
|
+
[ts],
|
|
1968
2307
|
// controllers
|
|
1969
|
-
[
|
|
1970
|
-
[
|
|
1971
|
-
[
|
|
2308
|
+
[he],
|
|
2309
|
+
[fe],
|
|
2310
|
+
[me]
|
|
1972
2311
|
].forEach((e) => s.add(e));
|
|
1973
2312
|
}
|
|
1974
|
-
},
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
],
|
|
2313
|
+
}, A(ue, "pluginName", as), A(ue, "type", Z.UNIVER_DOC), ue);
|
|
2314
|
+
yt = os([
|
|
2315
|
+
rs(1, Q(fn))
|
|
2316
|
+
], yt);
|
|
2317
|
+
function is(s, e) {
|
|
2318
|
+
const { range: t, rangeId: n, rangeType: o, segmentId: r } = s, a = mn(t, e);
|
|
2319
|
+
if (!a)
|
|
2320
|
+
return null;
|
|
2321
|
+
const { startOffset: i, endOffset: c } = a, l = new G();
|
|
2322
|
+
return i > 0 && l.push({
|
|
2323
|
+
t: C.RETAIN,
|
|
2324
|
+
len: i,
|
|
2325
|
+
segmentId: r
|
|
2326
|
+
}), l.push({
|
|
2327
|
+
t: C.INSERT,
|
|
2328
|
+
body: {
|
|
2329
|
+
dataStream: N.CUSTOM_RANGE_START
|
|
2330
|
+
},
|
|
2331
|
+
len: 1,
|
|
2332
|
+
line: 0
|
|
2333
|
+
}), l.push({
|
|
2334
|
+
t: C.RETAIN,
|
|
2335
|
+
body: {
|
|
2336
|
+
dataStream: ""
|
|
2337
|
+
},
|
|
2338
|
+
len: c - i,
|
|
2339
|
+
segmentId: r
|
|
2340
|
+
}), l.push({
|
|
2341
|
+
t: C.INSERT,
|
|
2342
|
+
body: {
|
|
2343
|
+
dataStream: N.CUSTOM_RANGE_END,
|
|
2344
|
+
customRanges: [
|
|
2345
|
+
{
|
|
2346
|
+
rangeId: n,
|
|
2347
|
+
rangeType: o,
|
|
2348
|
+
startIndex: -(c - i) - 1,
|
|
2349
|
+
endIndex: 0
|
|
2350
|
+
}
|
|
2351
|
+
]
|
|
2352
|
+
},
|
|
2353
|
+
len: 1,
|
|
2354
|
+
line: 0
|
|
2355
|
+
}), l;
|
|
2356
|
+
}
|
|
2357
|
+
function Ns(s, e) {
|
|
2358
|
+
const t = {
|
|
2359
|
+
id: F.id,
|
|
2360
|
+
params: {
|
|
2361
|
+
unitId: s.unitId,
|
|
2362
|
+
actions: [],
|
|
2363
|
+
textRanges: void 0
|
|
2364
|
+
}
|
|
2365
|
+
}, n = w.getInstance(), o = is(s, e);
|
|
2366
|
+
return o ? (t.params.actions = n.editOp(o.serialize()), t) : !1;
|
|
2367
|
+
}
|
|
2368
|
+
function Ds(s, e) {
|
|
2369
|
+
var y;
|
|
2370
|
+
const { segmentId: t, rangeId: n, rangeType: o } = e, r = s.get(D), a = s.get(P), i = r.getActiveRange();
|
|
2371
|
+
if (!i)
|
|
2372
|
+
return !1;
|
|
2373
|
+
const c = a.getCurrentUnitForType(Z.UNIVER_DOC);
|
|
2374
|
+
if (!c)
|
|
2375
|
+
return !1;
|
|
2376
|
+
const l = c.getBody(), d = c.getUnitId();
|
|
2377
|
+
if (!l)
|
|
2378
|
+
return !1;
|
|
2379
|
+
const { startOffset: g, endOffset: u } = ie(i), I = (y = l.customRanges) != null ? y : [], f = [];
|
|
2380
|
+
for (let _ = 0, M = I.length; _ < M; _++) {
|
|
2381
|
+
const O = I[_];
|
|
2382
|
+
if (O.rangeType === o && Math.max(O.startIndex, g) <= Math.min(O.endIndex, u - 1) && f.push({ ...O }), O.startIndex >= u)
|
|
2383
|
+
break;
|
|
2384
|
+
}
|
|
2385
|
+
const S = f.map((_) => [_.startIndex, _.endIndex]).flat().sort((_, M) => _ - M);
|
|
2386
|
+
let m = 0;
|
|
2387
|
+
const h = new G(), p = S.length ? {
|
|
2388
|
+
startOffset: Math.min(S[0], g),
|
|
2389
|
+
endOffset: Math.max(S[S.length - 1] + 1, u)
|
|
2390
|
+
} : i;
|
|
2391
|
+
p.startOffset !== m && (h.push({
|
|
2392
|
+
t: C.RETAIN,
|
|
2393
|
+
len: p.startOffset - m,
|
|
2394
|
+
segmentId: t
|
|
2395
|
+
}), m = p.startOffset), h.push({
|
|
2396
|
+
t: C.INSERT,
|
|
2397
|
+
body: {
|
|
2398
|
+
dataStream: N.CUSTOM_RANGE_START
|
|
2399
|
+
},
|
|
2400
|
+
len: 1,
|
|
2401
|
+
line: 0,
|
|
2402
|
+
segmentId: t
|
|
2403
|
+
}), S.forEach((_, M) => {
|
|
2404
|
+
_ !== m && (h.push({
|
|
2405
|
+
t: C.RETAIN,
|
|
2406
|
+
len: _ - m,
|
|
2407
|
+
segmentId: t
|
|
2408
|
+
}), m = _), h.push({
|
|
2409
|
+
t: C.DELETE,
|
|
2410
|
+
len: 1,
|
|
2411
|
+
line: 0,
|
|
2412
|
+
segmentId: t
|
|
2413
|
+
}), m++;
|
|
2414
|
+
}), m !== p.endOffset && (h.push({
|
|
2415
|
+
t: C.RETAIN,
|
|
2416
|
+
len: p.endOffset - m,
|
|
2417
|
+
segmentId: t
|
|
2418
|
+
}), m = p.endOffset), h.push({
|
|
2419
|
+
t: C.INSERT,
|
|
2420
|
+
body: {
|
|
2421
|
+
dataStream: N.CUSTOM_RANGE_END,
|
|
2422
|
+
customRanges: [
|
|
2423
|
+
{
|
|
2424
|
+
rangeId: n,
|
|
2425
|
+
rangeType: o,
|
|
2426
|
+
startIndex: -(p.endOffset - p.startOffset - S.length + 1),
|
|
2427
|
+
endIndex: 0
|
|
2428
|
+
}
|
|
2429
|
+
]
|
|
2430
|
+
},
|
|
2431
|
+
len: 1,
|
|
2432
|
+
line: 0,
|
|
2433
|
+
segmentId: t
|
|
2434
|
+
});
|
|
2435
|
+
const R = w.getInstance(), v = {
|
|
2436
|
+
id: F.id,
|
|
2437
|
+
params: {
|
|
2438
|
+
unitId: d,
|
|
2439
|
+
actions: [],
|
|
2440
|
+
textRanges: void 0
|
|
2441
|
+
}
|
|
2442
|
+
};
|
|
2443
|
+
return v.params.actions = R.editOp(h.serialize()), v;
|
|
2444
|
+
}
|
|
2445
|
+
function cs(s, e) {
|
|
2446
|
+
var u, I;
|
|
2447
|
+
const { unitId: t, rangeId: n, segmentId: o } = e, a = s.get(P).getUnit(t);
|
|
2448
|
+
if (!a)
|
|
2449
|
+
return !1;
|
|
2450
|
+
const i = (I = (u = a.getBody()) == null ? void 0 : u.customRanges) == null ? void 0 : I.find((f) => f.rangeId === n);
|
|
2451
|
+
if (!i)
|
|
2452
|
+
return !1;
|
|
2453
|
+
const { startIndex: c, endIndex: l } = i, d = new G(), g = l - c + 1;
|
|
2454
|
+
return c > 0 && d.push({
|
|
2455
|
+
t: C.RETAIN,
|
|
2456
|
+
len: c,
|
|
2457
|
+
segmentId: o
|
|
2458
|
+
}), d.push({
|
|
2459
|
+
t: C.DELETE,
|
|
2460
|
+
len: 1,
|
|
2461
|
+
segmentId: o,
|
|
2462
|
+
line: 0
|
|
2463
|
+
}), g - 2 > 0 && d.push({
|
|
2464
|
+
t: C.RETAIN,
|
|
2465
|
+
len: g - 2,
|
|
2466
|
+
segmentId: o
|
|
2467
|
+
}), d.push({
|
|
2468
|
+
t: C.DELETE,
|
|
2469
|
+
len: 1,
|
|
2470
|
+
segmentId: o,
|
|
2471
|
+
line: 0
|
|
2472
|
+
}), d;
|
|
2473
|
+
}
|
|
2474
|
+
function Ps(s, e) {
|
|
2475
|
+
const t = {
|
|
2476
|
+
id: F.id,
|
|
2477
|
+
params: {
|
|
2478
|
+
unitId: e.unitId,
|
|
2479
|
+
actions: [],
|
|
2480
|
+
textRanges: void 0
|
|
2481
|
+
}
|
|
2482
|
+
}, n = w.getInstance(), o = cs(s, e);
|
|
2483
|
+
return o ? (t.params.actions = n.editOp(o.serialize()), t) : !1;
|
|
2484
|
+
}
|
|
2485
|
+
function ls(s) {
|
|
2486
|
+
const { unitId: e, range: t, id: n, type: o, segmentId: r } = s, { startOffset: a, endOffset: i } = t, c = {
|
|
2487
|
+
id: F.id,
|
|
2488
|
+
params: {
|
|
2489
|
+
unitId: e,
|
|
2490
|
+
actions: [],
|
|
2491
|
+
textRanges: void 0
|
|
2492
|
+
}
|
|
2493
|
+
}, l = new G(), d = w.getInstance();
|
|
2494
|
+
return a > 0 && l.push({
|
|
2495
|
+
t: C.RETAIN,
|
|
2496
|
+
len: a,
|
|
2497
|
+
segmentId: r
|
|
2498
|
+
}), l.push({
|
|
2499
|
+
t: C.RETAIN,
|
|
2500
|
+
body: {
|
|
2501
|
+
dataStream: "",
|
|
2502
|
+
customDecorations: [{
|
|
2503
|
+
id: n,
|
|
2504
|
+
type: o,
|
|
2505
|
+
startIndex: 0,
|
|
2506
|
+
endIndex: i - a - 1
|
|
2507
|
+
}]
|
|
2508
|
+
},
|
|
2509
|
+
len: i - a,
|
|
2510
|
+
segmentId: r
|
|
2511
|
+
}), c.params.actions = d.editOp(l.serialize()), c;
|
|
2512
|
+
}
|
|
2513
|
+
function bs(s, e) {
|
|
2514
|
+
const { segmentId: t, id: n, type: o } = e, r = s.get(D), a = s.get(P), i = r.getActiveRange();
|
|
2515
|
+
if (!i)
|
|
2516
|
+
return !1;
|
|
2517
|
+
const c = a.getCurrentUnitForType(Z.UNIVER_DOC);
|
|
2518
|
+
if (!c)
|
|
2519
|
+
return !1;
|
|
2520
|
+
const l = c.getBody(), d = c.getUnitId();
|
|
2521
|
+
return l ? ls(
|
|
2522
|
+
{
|
|
2523
|
+
unitId: d,
|
|
2524
|
+
range: {
|
|
2525
|
+
startOffset: i.startOffset,
|
|
2526
|
+
endOffset: i.endOffset,
|
|
2527
|
+
collapsed: !0
|
|
2528
|
+
},
|
|
2529
|
+
id: n,
|
|
2530
|
+
type: o,
|
|
2531
|
+
segmentId: t
|
|
2532
|
+
}
|
|
2533
|
+
) : !1;
|
|
2534
|
+
}
|
|
2535
|
+
function Us(s, e) {
|
|
2536
|
+
var S, m;
|
|
2537
|
+
const { unitId: t, id: n, segmentId: o } = e, a = s.get(P).getUnit(t), i = a == null ? void 0 : a.getBody();
|
|
2538
|
+
if (!a || !i)
|
|
2539
|
+
return !1;
|
|
2540
|
+
const c = (m = (S = a.getBody()) == null ? void 0 : S.customDecorations) == null ? void 0 : m.filter((h) => h.id === n);
|
|
2541
|
+
if (!(c != null && c.length))
|
|
2542
|
+
return !1;
|
|
2543
|
+
const l = c.map((h) => Et(i, h.startIndex, h.endIndex + 1)), d = l.map((h) => {
|
|
2544
|
+
var R;
|
|
2545
|
+
const p = J.deepClone(h);
|
|
2546
|
+
return p.customDecorations = (R = p.customDecorations) == null ? void 0 : R.filter((v) => v.id !== n), p;
|
|
2547
|
+
}), g = {
|
|
2548
|
+
id: F.id,
|
|
2549
|
+
params: {
|
|
2550
|
+
unitId: t,
|
|
2551
|
+
actions: [],
|
|
2552
|
+
textRanges: void 0
|
|
2553
|
+
}
|
|
2554
|
+
}, u = new G(), I = w.getInstance();
|
|
2555
|
+
let f = 0;
|
|
2556
|
+
return c.forEach((h, p) => {
|
|
2557
|
+
const R = d[p], v = l[p];
|
|
2558
|
+
h.startIndex !== f && u.push({
|
|
2559
|
+
t: C.RETAIN,
|
|
2560
|
+
len: h.startIndex - f,
|
|
2561
|
+
segmentId: o
|
|
2562
|
+
}), f = h.startIndex, u.push({
|
|
2563
|
+
t: C.RETAIN,
|
|
2564
|
+
len: h.endIndex - h.startIndex + 1,
|
|
2565
|
+
segmentId: o,
|
|
2566
|
+
body: R,
|
|
2567
|
+
oldBody: v,
|
|
2568
|
+
coverType: _e.REPLACE
|
|
2569
|
+
}), f = f + (h.endIndex - h.startIndex + 1);
|
|
2570
|
+
}), g.params.actions = I.editOp(u.serialize()), g;
|
|
2571
|
+
}
|
|
2572
|
+
const ds = Dt("CUSTOM_RANGE"), us = Dt("CUSTOM_DECORATION"), be = {
|
|
2573
|
+
CUSTOM_RANGE: ds,
|
|
2574
|
+
CUSTOM_DECORATION: us
|
|
2575
|
+
};
|
|
2576
|
+
var gs = Object.defineProperty, fs = Object.getOwnPropertyDescriptor, ms = (s, e, t, n) => {
|
|
2577
|
+
for (var o = n > 1 ? void 0 : n ? fs(e, t) : e, r = s.length - 1, a; r >= 0; r--)
|
|
2578
|
+
(a = s[r]) && (o = (n ? a(e, t, o) : a(o)) || o);
|
|
2579
|
+
return n && o && gs(e, t, o), o;
|
|
2580
|
+
}, hs = (s, e) => (t, n) => e(t, n, s);
|
|
2581
|
+
let Ue = class extends xe {
|
|
2582
|
+
constructor(e, t) {
|
|
2583
|
+
super();
|
|
2584
|
+
A(this, "_interceptorsByName", /* @__PURE__ */ new Map());
|
|
2585
|
+
this._context = e, this._docSkeletonManagerService = t, this.disposeWithMe(this._docSkeletonManagerService.currentViewModel$.subscribe((n) => {
|
|
2586
|
+
if (n) {
|
|
2587
|
+
const o = n.getDataModel().getUnitId();
|
|
2588
|
+
if (o === Tt || o === Qt)
|
|
2589
|
+
return;
|
|
2590
|
+
this.interceptDocumentViewModel(n);
|
|
2591
|
+
}
|
|
2592
|
+
})), this.disposeWithMe(this.intercept(be.CUSTOM_RANGE, {
|
|
2593
|
+
priority: -1,
|
|
2594
|
+
handler: (n, o, r) => r(n)
|
|
2595
|
+
}));
|
|
2596
|
+
}
|
|
2597
|
+
intercept(e, t) {
|
|
2598
|
+
const n = e;
|
|
2599
|
+
this._interceptorsByName.has(n) || this._interceptorsByName.set(n, []);
|
|
2600
|
+
const o = this._interceptorsByName.get(n);
|
|
2601
|
+
return o.push(t), this._interceptorsByName.set(
|
|
2602
|
+
n,
|
|
2603
|
+
o.sort((r, a) => {
|
|
2604
|
+
var i, c;
|
|
2605
|
+
return ((i = a.priority) != null ? i : 0) - ((c = r.priority) != null ? c : 0);
|
|
2606
|
+
})
|
|
2607
|
+
), this.disposeWithMe(Nt(() => en(this._interceptorsByName.get(n), t)));
|
|
2608
|
+
}
|
|
2609
|
+
fetchThroughInterceptors(e) {
|
|
2610
|
+
const t = e, n = this._interceptorsByName.get(t);
|
|
2611
|
+
return tn(n || []);
|
|
2612
|
+
}
|
|
2613
|
+
interceptDocumentViewModel(e) {
|
|
2614
|
+
const t = new nn();
|
|
2615
|
+
return t.add(e.registerCustomRangeInterceptor({
|
|
2616
|
+
getCustomRange: (n) => {
|
|
2617
|
+
var o;
|
|
2618
|
+
return this.fetchThroughInterceptors(be.CUSTOM_RANGE)(
|
|
2619
|
+
e.getCustomRangeRaw(n),
|
|
2620
|
+
{
|
|
2621
|
+
index: n,
|
|
2622
|
+
unitId: e.getDataModel().getUnitId(),
|
|
2623
|
+
customRanges: (o = e.getDataModel().getCustomRanges()) != null ? o : []
|
|
2624
|
+
}
|
|
2625
|
+
);
|
|
2626
|
+
},
|
|
2627
|
+
getCustomDecoration: (n) => {
|
|
2628
|
+
var o;
|
|
2629
|
+
return this.fetchThroughInterceptors(be.CUSTOM_DECORATION)(
|
|
2630
|
+
e.getCustomDecorationRaw(n),
|
|
2631
|
+
{
|
|
2632
|
+
index: n,
|
|
2633
|
+
unitId: e.getDataModel().getUnitId(),
|
|
2634
|
+
customDecorations: (o = e.getDataModel().getCustomDecorations()) != null ? o : []
|
|
2635
|
+
}
|
|
2636
|
+
);
|
|
2637
|
+
}
|
|
2638
|
+
})), t;
|
|
2639
|
+
}
|
|
2640
|
+
};
|
|
2641
|
+
Ue = ms([
|
|
2642
|
+
Re(ve.Starting, Ue),
|
|
2643
|
+
hs(1, Q(X))
|
|
2644
|
+
], Ue);
|
|
1978
2645
|
export {
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2646
|
+
qn as AlignCenterCommand,
|
|
2647
|
+
es as AlignJustifyCommand,
|
|
2648
|
+
Jn as AlignLeftCommand,
|
|
2649
|
+
ce as AlignOperationCommand,
|
|
2650
|
+
Qn as AlignRightCommand,
|
|
2651
|
+
En as BreakLineCommand,
|
|
2652
|
+
wn as BulletListCommand,
|
|
2653
|
+
Fn as CoverContentCommand,
|
|
2654
|
+
Bt as CutContentCommand,
|
|
2655
|
+
xs as DOCS_COMPONENT_BACKGROUND_LAYER_INDEX,
|
|
2656
|
+
Ms as DOCS_COMPONENT_DEFAULT_Z_INDEX,
|
|
2657
|
+
Os as DOCS_COMPONENT_HEADER_LAYER_INDEX,
|
|
2658
|
+
Cs as DOCS_COMPONENT_MAIN_LAYER_INDEX,
|
|
2659
|
+
Me as DOCS_VIEW_KEY,
|
|
2660
|
+
be as DOC_INTERCEPTOR_POINT,
|
|
2661
|
+
Xe as DeleteCommand,
|
|
2662
|
+
Nn as DeleteLeftCommand,
|
|
2663
|
+
Dn as DeleteRightCommand,
|
|
2664
|
+
ts as DocCustomRangeService,
|
|
2665
|
+
Ue as DocInterceptorService,
|
|
2666
|
+
X as DocSkeletonManagerService,
|
|
2667
|
+
Se as DocStateChangeManagerService,
|
|
2668
|
+
Tn as EditorInsertTextCommandId,
|
|
2669
|
+
Ft as IMEInputCommand,
|
|
2670
|
+
ye as IMEInputManagerService,
|
|
2671
|
+
As as InnerPasteCommand,
|
|
2672
|
+
Ie as InsertCommand,
|
|
2673
|
+
nt as ListOperationCommand,
|
|
2674
|
+
Ve as MergeTwoParagraphCommand,
|
|
2675
|
+
we as MoveCursorOperation,
|
|
2676
|
+
Be as MoveSelectionOperation,
|
|
2677
|
+
ys as NORMAL_TEXT_SELECTION_PLUGIN_NAME,
|
|
2678
|
+
Bn as OrderListCommand,
|
|
2679
|
+
Ln as ReplaceContentCommand,
|
|
2680
|
+
tt as ResetInlineFormatTextBackgroundColorCommand,
|
|
2681
|
+
F as RichTextEditingMutation,
|
|
2682
|
+
zn as SelectAllOperation,
|
|
2683
|
+
Gn as SetDocZoomRatioCommand,
|
|
2684
|
+
ge as SetDocZoomRatioOperation,
|
|
2685
|
+
ke as SetInlineFormatBoldCommand,
|
|
2686
|
+
Gt as SetInlineFormatCommand,
|
|
2687
|
+
qe as SetInlineFormatFontFamilyCommand,
|
|
2688
|
+
Je as SetInlineFormatFontSizeCommand,
|
|
2689
|
+
We as SetInlineFormatItalicCommand,
|
|
2690
|
+
Ke as SetInlineFormatStrikethroughCommand,
|
|
2691
|
+
se as SetInlineFormatSubscriptCommand,
|
|
2692
|
+
Ze as SetInlineFormatSuperscriptCommand,
|
|
2693
|
+
et as SetInlineFormatTextBackgroundColorCommand,
|
|
2694
|
+
Qe as SetInlineFormatTextColorCommand,
|
|
2695
|
+
Ye as SetInlineFormatUnderlineCommand,
|
|
2696
|
+
bt as SetTextSelectionsOperation,
|
|
2697
|
+
D as TextSelectionManagerService,
|
|
2698
|
+
yt as UniverDocsPlugin,
|
|
2699
|
+
wt as UpdateCommand,
|
|
2700
|
+
pn as VIEWPORT_KEY,
|
|
2701
|
+
bs as addCustomDecorationBySelectionFactory,
|
|
2702
|
+
ls as addCustomDecorationFactory,
|
|
2703
|
+
Ds as addCustomRangeBySelectionFactory,
|
|
2704
|
+
Ns as addCustomRangeFactory,
|
|
2705
|
+
Us as deleteCustomDecorationFactory,
|
|
2706
|
+
Ps as deleteCustomRangeFactory,
|
|
2707
|
+
je as getDeleteSelection,
|
|
2708
|
+
Sn as getDocObject,
|
|
2709
|
+
Es as getDocObjectById,
|
|
2710
|
+
Oe as getInsertSelection,
|
|
2711
|
+
vs as getSelectionText,
|
|
2712
|
+
Ts as neoGetDocObject,
|
|
2713
|
+
q as serializeTextRange
|
|
2033
2714
|
};
|