@univerjs/docs 0.1.11 → 0.1.13-nightly.202406041140

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/es/index.js CHANGED
@@ -1,63 +1,63 @@
1
- var yt = Object.defineProperty;
2
- var Ot = (o, e, t) => e in o ? yt(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
- var y = (o, e, t) => (Ot(o, typeof e != "symbol" ? e + "" : e, t), t);
4
- import { UniverInstanceType as W, CommandType as v, RxDisposable as ge, ICommandService as I, TextXActionType as x, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as ut, IUniverInstanceService as E, IUndoRedoService as Te, UndoCommandId as Ye, RedoCommandId as We, TextX as b, DataStreamTreeTokenType as xe, Tools as Q, LocaleService as Tt, MemoryCursor as se, getDocsUpdateBody as Et, UpdateDocsAttributeType as Ee, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY as Dt, BooleanNumber as z, BaselineOffset as G, PRESET_LIST_TYPE as At, PresetListType as mt, HorizontalAlign as re, OnLifecycle as De, LifecycleStages as Ae, Disposable as Ne, Direction as N, Plugin as Nt } from "@univerjs/core";
5
- import { NORMAL_TEXT_SELECTION_PLUGIN_STYLE as Pt, ITextSelectionRenderManager as fe, DocumentViewModel as bt, DocumentSkeleton as Ut, hasListGlyph as wt, isIndentByGlyph as Lt, isFirstGlyph as Bt, getParagraphByGlyph as Ft, getCharSpaceApply as $t, getNumberUnitValue as Me, RANGE_DIRECTION as Ze, NodePositionConvertToCursor as Ke, IRenderManagerService as gt, TextSelectionRenderManager as Vt } from "@univerjs/engine-render";
6
- import { BehaviorSubject as ee, takeUntil as te } from "rxjs";
7
- import { Inject as V, Injector as kt } from "@wendellhu/redi";
8
- var Pe = /* @__PURE__ */ ((o) => (o.MAIN = "__Document_Render_Main__", o.BACKGROUND = "__Document_Render_Background__", o))(Pe || {}), zt = /* @__PURE__ */ ((o) => (o.VIEW_MAIN = "viewMain", o.VIEW_TOP = "viewTop", o.VIEW_LEFT = "viewLeft", o.VIEW_LEFT_TOP = "viewLeftTop", o))(zt || {});
9
- const Gn = 0, jn = 2, Hn = 4, Xn = 10, Yn = "normalTextSelectionPluginName";
10
- function Gt(o, e) {
11
- const t = o.getCurrentUnitForType(W.UNIVER_DOC);
1
+ var Ot = Object.defineProperty;
2
+ var Tt = (n, e, t) => e in n ? Ot(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var y = (n, e, t) => (Tt(n, typeof e != "symbol" ? e + "" : e, t), t);
4
+ import { UniverInstanceType as Z, CommandType as _, RxDisposable as he, ICommandService as v, TextXActionType as x, DOCS_NORMAL_EDITOR_UNIT_ID_KEY as Et, IUniverInstanceService as E, IUndoRedoService as Ee, UndoCommandId as Ze, RedoCommandId as Je, JSONX as U, TextX as B, DataStreamTreeTokenType as ye, Tools as ee, LocaleService as At, MemoryCursor as ie, getDocsUpdateBody as Nt, UpdateDocsAttributeType as Ae, BooleanNumber as G, BaselineOffset as X, PRESET_LIST_TYPE as Dt, PresetListType as mt, HorizontalAlign as re, OnLifecycle as Ne, LifecycleStages as De, Disposable as be, Direction as b, Plugin as bt } from "@univerjs/core";
5
+ import { NORMAL_TEXT_SELECTION_PLUGIN_STYLE as Ut, ITextSelectionRenderManager as fe, DocumentViewModel as Pt, DocumentSkeleton as wt, hasListGlyph as kt, isIndentByGlyph as Lt, isFirstGlyph as Bt, getParagraphByGlyph as Ft, getCharSpaceApply as $t, getNumberUnitValue as Ce, RANGE_DIRECTION as Ke, NodePositionConvertToCursor as qe, IRenderManagerService as ht, TextSelectionRenderManager as Vt } from "@univerjs/engine-render";
6
+ import { BehaviorSubject as te, takeUntil as ne } from "rxjs";
7
+ import { Inject as V, Injector as zt } from "@wendellhu/redi";
8
+ var Ue = /* @__PURE__ */ ((n) => (n.MAIN = "__Document_Render_Main__", n.BACKGROUND = "__Document_Render_Background__", n))(Ue || {}), Gt = /* @__PURE__ */ ((n) => (n.VIEW_MAIN = "viewMain", n.VIEW_TOP = "viewTop", n.VIEW_LEFT = "viewLeft", n.VIEW_LEFT_TOP = "viewLeftTop", n))(Gt || {});
9
+ const An = 0, Nn = 2, Dn = 4, bn = 10, Un = "normalTextSelectionPluginName";
10
+ function Xt(n, e) {
11
+ const t = n.getCurrentUnitForType(Z.UNIVER_DOC);
12
12
  if (!t)
13
13
  return null;
14
- const n = t.getUnitId(), s = e.getRenderById(n);
15
- if (s == null)
14
+ const s = t.getUnitId(), i = e.getRenderById(s);
15
+ if (i == null)
16
16
  return;
17
- const { mainComponent: r, scene: i, engine: a, components: c } = s, d = r, l = c.get(Pe.BACKGROUND);
17
+ const { mainComponent: o, scene: r, engine: a, components: c } = i, d = o, l = c.get(Ue.BACKGROUND);
18
18
  return {
19
19
  document: d,
20
20
  docBackground: l,
21
- scene: i,
21
+ scene: r,
22
22
  engine: a
23
23
  };
24
24
  }
25
- function Wn(o, e) {
26
- const t = e.getRenderById(o);
25
+ function Pn(n, e) {
26
+ const t = e.getRenderById(n);
27
27
  if (t == null)
28
28
  return;
29
- const { mainComponent: n, scene: s, engine: r, components: i } = t, a = n, c = i.get(Pe.BACKGROUND);
29
+ const { mainComponent: s, scene: i, engine: o, components: r } = t, a = s, c = r.get(Ue.BACKGROUND);
30
30
  return {
31
31
  document: a,
32
32
  docBackground: c,
33
- scene: s,
34
- engine: r
33
+ scene: i,
34
+ engine: o
35
35
  };
36
36
  }
37
37
  const ft = {
38
38
  id: "doc.operation.set-selections",
39
- type: v.OPERATION,
40
- handler: (o, e) => !0
39
+ type: _.OPERATION,
40
+ handler: (n, e) => !0
41
41
  };
42
- var jt = Object.defineProperty, Ht = Object.getOwnPropertyDescriptor, Xt = (o, e, t, n) => {
43
- for (var s = n > 1 ? void 0 : n ? Ht(e, t) : e, r = o.length - 1, i; r >= 0; r--)
44
- (i = o[r]) && (s = (n ? i(e, t, s) : i(s)) || s);
45
- return n && s && jt(e, t, s), s;
46
- }, Je = (o, e) => (t, n) => e(t, n, o);
47
- function Z(o) {
48
- const { startOffset: e, endOffset: t, collapsed: n } = o, s = {
42
+ var Ht = (n, e, t, s) => {
43
+ for (var i = e, o = n.length - 1, r; o >= 0; o--)
44
+ (r = n[o]) && (i = r(i) || i);
45
+ return i;
46
+ }, Qe = (n, e) => (t, s) => e(t, s, n);
47
+ function J(n) {
48
+ const { startOffset: e, endOffset: t, collapsed: s } = n, i = {
49
49
  startOffset: e,
50
50
  endOffset: t,
51
- collapsed: n
51
+ collapsed: s
52
52
  };
53
- return typeof o.isActive == "function" && (s.isActive = o.isActive()), s;
53
+ return typeof n.isActive == "function" && (i.isActive = n.isActive()), i;
54
54
  }
55
- let T = class extends ge {
55
+ let T = class extends he {
56
56
  constructor(e, t) {
57
57
  super();
58
58
  y(this, "_currentSelection", null);
59
59
  y(this, "_textSelectionInfo", /* @__PURE__ */ new Map());
60
- y(this, "_textSelection$", new ee(null));
60
+ y(this, "_textSelection$", new te(null));
61
61
  y(this, "textSelection$", this._textSelection$.asObservable());
62
62
  this._textSelectionRenderManager = e, this._commandService = t, this._syncSelectionFromRenderService();
63
63
  }
@@ -85,23 +85,30 @@ let T = class extends ge {
85
85
  var e;
86
86
  return (e = this._getTextRanges(this._currentSelection)) == null ? void 0 : e.textRanges;
87
87
  }
88
+ getActiveTextRange() {
89
+ const e = this._getTextRanges(this._currentSelection);
90
+ if (e == null)
91
+ return;
92
+ const { textRanges: t } = e;
93
+ return t.find((s) => s.isActive());
94
+ }
88
95
  getActiveRange() {
89
96
  const e = this._getTextRanges(this._currentSelection);
90
97
  if (e == null)
91
98
  return;
92
- const { textRanges: t, segmentId: n, style: s } = e, r = t.find((m) => m.isActive());
93
- if (r == null)
99
+ const { textRanges: t, segmentId: s, style: i } = e, o = t.find((g) => g.isActive());
100
+ if (o == null)
94
101
  return null;
95
- const { startOffset: i, endOffset: a, collapsed: c, startNodePosition: d, endNodePosition: l, direction: u } = r;
96
- return i == null || a == null ? null : {
97
- startOffset: i,
102
+ const { startOffset: r, endOffset: a, collapsed: c, startNodePosition: d, endNodePosition: l, direction: u } = o;
103
+ return r == null || a == null ? null : {
104
+ startOffset: r,
98
105
  endOffset: a,
99
106
  collapsed: c,
100
107
  startNodePosition: d,
101
108
  endNodePosition: l,
102
109
  direction: u,
103
- segmentId: n,
104
- style: s
110
+ segmentId: s,
111
+ style: i
105
112
  };
106
113
  }
107
114
  // **Only used in test case** because this does not go through the render layer.
@@ -111,7 +118,7 @@ let T = class extends ge {
111
118
  textRanges: e,
112
119
  segmentId: "",
113
120
  isEditing: t,
114
- style: Pt
121
+ style: Ut
115
122
  // mock style.
116
123
  });
117
124
  }
@@ -120,7 +127,7 @@ let T = class extends ge {
120
127
  }
121
128
  // All textRanges should be synchronized from the render layer.
122
129
  _syncSelectionFromRenderService() {
123
- this._textSelectionRenderManager.textSelectionInner$.pipe(te(this.dispose$)).subscribe((e) => {
130
+ this._textSelectionRenderManager.textSelectionInner$.pipe(ne(this.dispose$)).subscribe((e) => {
124
131
  e != null && this._replaceTextRangesWithNoRefresh(e);
125
132
  });
126
133
  }
@@ -132,65 +139,65 @@ let T = class extends ge {
132
139
  ...e
133
140
  };
134
141
  this._replaceByParam(t), this._textSelection$.next(t);
135
- const { unitId: n, subUnitId: s, segmentId: r, style: i, textRanges: a, isEditing: c } = t;
142
+ const { unitId: s, subUnitId: i, segmentId: o, style: r, textRanges: a, isEditing: c } = t;
136
143
  this._commandService.executeCommand(ft.id, {
137
- unitId: n,
138
- subUnitId: s,
139
- segmentId: r,
140
- style: i,
144
+ unitId: s,
145
+ subUnitId: i,
146
+ segmentId: o,
147
+ style: r,
141
148
  isEditing: c,
142
- ranges: a.map(Z)
149
+ ranges: a.map(J)
143
150
  });
144
151
  }
145
152
  _getTextRanges(e) {
146
- var s;
153
+ var i;
147
154
  if (e == null)
148
155
  return;
149
- const { unitId: t, subUnitId: n = "" } = e;
150
- return (s = this._textSelectionInfo.get(t)) == null ? void 0 : s.get(n);
156
+ const { unitId: t, subUnitId: s = "" } = e;
157
+ return (i = this._textSelectionInfo.get(t)) == null ? void 0 : i.get(s);
151
158
  }
152
159
  _refresh(e) {
153
160
  const t = this._getTextRanges(e);
154
- this._textSelectionRenderManager.removeAllTextRanges(), t && Array.isArray(t.textRanges) && t.textRanges.length && this._textSelectionRenderManager.addTextRanges(t.textRanges.map(Z));
161
+ this._textSelectionRenderManager.removeAllTextRanges(), t && Array.isArray(t.textRanges) && t.textRanges.length && this._textSelectionRenderManager.addTextRanges(t.textRanges.map(J));
155
162
  }
156
163
  _replaceByParam(e) {
157
- const { unitId: t, subUnitId: n, style: s, segmentId: r, textRanges: i, isEditing: a } = e;
158
- this._textSelectionInfo.has(t) || this._textSelectionInfo.set(t, /* @__PURE__ */ new Map()), this._textSelectionInfo.get(t).set(n, { textRanges: i, style: s, segmentId: r, isEditing: a });
164
+ const { unitId: t, subUnitId: s, style: i, segmentId: o, textRanges: r, isEditing: a } = e;
165
+ this._textSelectionInfo.has(t) || this._textSelectionInfo.set(t, /* @__PURE__ */ new Map()), this._textSelectionInfo.get(t).set(s, { textRanges: r, style: i, segmentId: o, isEditing: a });
159
166
  }
160
167
  _addByParam(e) {
161
- const { unitId: t, subUnitId: n, textRanges: s, style: r, segmentId: i, isEditing: a } = e;
168
+ const { unitId: t, subUnitId: s, textRanges: i, style: o, segmentId: r, isEditing: a } = e;
162
169
  this._textSelectionInfo.has(t) || this._textSelectionInfo.set(t, /* @__PURE__ */ new Map());
163
170
  const c = this._textSelectionInfo.get(t);
164
- c.has(n) ? c.get(n).textRanges.push(...s) : c.set(n, { textRanges: s, style: r, segmentId: i, isEditing: a });
171
+ c.has(s) ? c.get(s).textRanges.push(...i) : c.set(s, { textRanges: i, style: o, segmentId: r, isEditing: a });
165
172
  }
166
173
  };
167
- T = Xt([
168
- Je(0, fe),
169
- Je(1, I)
174
+ T = Ht([
175
+ Qe(0, fe),
176
+ Qe(1, v)
170
177
  ], T);
171
- function be(o, e = "", t = 0) {
172
- const { startOffset: n, endOffset: s } = o, r = [], i = n - t, a = s - t;
173
- return i > 0 && r.push({
178
+ function Pe(n, e = "", t = 0) {
179
+ const { startOffset: s, endOffset: i } = n, o = [], r = s - t, a = i - t;
180
+ return r > 0 && o.push({
174
181
  t: x.RETAIN,
175
- len: i,
182
+ len: r,
176
183
  segmentId: e
177
- }), r.push({
184
+ }), o.push({
178
185
  t: x.DELETE,
179
- len: a - i,
186
+ len: a - r,
180
187
  line: 0,
181
188
  segmentId: e
182
- }), r;
189
+ }), o;
183
190
  }
184
- var Yt = Object.defineProperty, Wt = Object.getOwnPropertyDescriptor, Zt = (o, e, t, n) => {
185
- for (var s = n > 1 ? void 0 : n ? Wt(e, t) : e, r = o.length - 1, i; r >= 0; r--)
186
- (i = o[r]) && (s = (n ? i(e, t, s) : i(s)) || s);
187
- return n && s && Yt(e, t, s), s;
188
- }, Kt = (o, e) => (t, n) => e(t, n, o);
189
- let ne = class extends ge {
191
+ var jt = (n, e, t, s) => {
192
+ for (var i = e, o = n.length - 1, r; o >= 0; o--)
193
+ (r = n[o]) && (i = r(i) || i);
194
+ return i;
195
+ }, Yt = (n, e) => (t, s) => e(t, s, n);
196
+ let se = class extends he {
190
197
  constructor(e) {
191
198
  super();
192
199
  y(this, "_docViewModelMap", /* @__PURE__ */ new Map());
193
- y(this, "_currentDocViewModel$", new ee(null));
200
+ y(this, "_currentDocViewModel$", new te(null));
194
201
  y(this, "currentDocViewModel$", this._currentDocViewModel$.asObservable());
195
202
  this._univerInstanceService = e, this._initialize();
196
203
  }
@@ -201,11 +208,11 @@ let ne = class extends ge {
201
208
  this._currentDocViewModel$.complete(), this._docViewModelMap.clear();
202
209
  }
203
210
  _init() {
204
- this._univerInstanceService.getCurrentTypeOfUnit$(W.UNIVER_DOC).pipe(te(this.dispose$)).subscribe((e) => {
211
+ this._univerInstanceService.getCurrentTypeOfUnit$(Z.UNIVER_DOC).pipe(ne(this.dispose$)).subscribe((e) => {
205
212
  this._create(e);
206
- }), this._univerInstanceService.getAllUnitsForType(W.UNIVER_DOC).forEach((e) => {
213
+ }), this._univerInstanceService.getAllUnitsForType(Z.UNIVER_DOC).forEach((e) => {
207
214
  this._create(e);
208
- }), this._univerInstanceService.getTypeOfUnitDisposed$(W.UNIVER_DOC).pipe(te(this.dispose$)).subscribe((e) => {
215
+ }), this._univerInstanceService.getTypeOfUnitDisposed$(Z.UNIVER_DOC).pipe(ne(this.dispose$)).subscribe((e) => {
209
216
  this._docViewModelMap.delete(e.getUnitId());
210
217
  });
211
218
  }
@@ -223,106 +230,106 @@ let ne = class extends ge {
223
230
  return (t = this._docViewModelMap.get(e)) == null ? void 0 : t.docViewModel;
224
231
  }
225
232
  _setCurrent(e) {
226
- var n;
233
+ var s;
227
234
  const t = this._univerInstanceService.getUniverDocInstance(e);
228
235
  if (t == null)
229
236
  throw new Error(`Document data model with id ${e} not found when build view model.`);
230
237
  if (t.getBody() != null) {
231
238
  if (!this._docViewModelMap.has(e)) {
232
- const s = this._buildDocViewModel(t);
239
+ const i = this._buildDocViewModel(t);
233
240
  this._docViewModelMap.set(e, {
234
241
  unitId: e,
235
- docViewModel: s
242
+ docViewModel: i
236
243
  });
237
244
  }
238
- if (e === ut) {
239
- const s = (n = this._docViewModelMap.get(e)) == null ? void 0 : n.docViewModel;
240
- if (s == null)
245
+ if (e === Et) {
246
+ const i = (s = this._docViewModelMap.get(e)) == null ? void 0 : s.docViewModel;
247
+ if (i == null)
241
248
  return;
242
- s.reset(t);
249
+ i.reset(t);
243
250
  }
244
251
  this._currentDocViewModel$.next(this._docViewModelMap.get(e));
245
252
  }
246
253
  }
247
254
  _buildDocViewModel(e) {
248
- return new bt(e);
255
+ return new Pt(e);
249
256
  }
250
257
  };
251
- ne = Zt([
252
- Kt(0, E)
253
- ], ne);
254
- var Jt = Object.defineProperty, qt = Object.getOwnPropertyDescriptor, Qt = (o, e, t, n) => {
255
- for (var s = n > 1 ? void 0 : n ? qt(e, t) : e, r = o.length - 1, i; r >= 0; r--)
256
- (i = o[r]) && (s = (n ? i(e, t, s) : i(s)) || s);
257
- return n && s && Jt(e, t, s), s;
258
- }, Ce = (o, e) => (t, n) => e(t, n, o);
259
- const en = 300;
260
- let me = class extends ge {
261
- constructor(e, t, n) {
258
+ se = jt([
259
+ Yt(0, E)
260
+ ], se);
261
+ var Wt = (n, e, t, s) => {
262
+ for (var i = e, o = n.length - 1, r; o >= 0; o--)
263
+ (r = n[o]) && (i = r(i) || i);
264
+ return i;
265
+ }, Re = (n, e) => (t, s) => e(t, s, n);
266
+ const Zt = 300;
267
+ let me = class extends he {
268
+ constructor(e, t, s) {
262
269
  super();
263
- y(this, "_docStateChange$", new ee(null));
270
+ y(this, "_docStateChange$", new te(null));
264
271
  y(this, "docStateChange$", this._docStateChange$.asObservable());
265
272
  y(this, "_stateCache", /* @__PURE__ */ new Map());
266
273
  y(this, "_timer", null);
267
- this._undoRedoService = e, this._commandService = t, this._univerInstanceService = n, this._initialize();
274
+ this._undoRedoService = e, this._commandService = t, this._univerInstanceService = s, this._initialize();
268
275
  }
269
276
  setChangeState(e) {
270
- const { trigger: t, noHistory: n } = e;
271
- t != null && (this._cacheChangeState(e), n || this._docStateChange$.next(e));
277
+ const { trigger: t, noHistory: s } = e;
278
+ t != null && (this._cacheChangeState(e), s || this._docStateChange$.next(e));
272
279
  }
273
280
  _initialize() {
274
281
  this.disposeWithMe(
275
282
  this._commandService.beforeCommandExecuted((e) => {
276
- if (e.id === Ye || e.id === We) {
283
+ if (e.id === Ze || e.id === Je) {
277
284
  const t = this._univerInstanceService.getCurrentUniverDocInstance();
278
285
  if (t == null)
279
286
  return;
280
- const n = t.getUnitId();
281
- this._pushHistory(n);
287
+ const s = t.getUnitId();
288
+ this._pushHistory(s);
282
289
  }
283
290
  })
284
291
  );
285
292
  }
286
293
  _cacheChangeState(e) {
287
- const { trigger: t, unitId: n, noHistory: s } = e;
288
- if (!(t === We || t === Ye || s)) {
289
- if (this._stateCache.has(n)) {
290
- const r = this._stateCache.get(n);
291
- r == null || r.push(e);
294
+ const { trigger: t, unitId: s, noHistory: i } = e;
295
+ if (!(t === Je || t === Ze || i)) {
296
+ if (this._stateCache.has(s)) {
297
+ const o = this._stateCache.get(s);
298
+ o == null || o.push(e);
292
299
  } else
293
- this._stateCache.set(n, [e]);
294
- t === pe.id || t === Se.id ? (this._timer && clearTimeout(this._timer), this._timer = setTimeout(() => {
295
- this._pushHistory(n);
296
- }, en)) : this._pushHistory(n);
300
+ this._stateCache.set(s, [e]);
301
+ t === Se.id || t === Ie.id ? (this._timer && clearTimeout(this._timer), this._timer = setTimeout(() => {
302
+ this._pushHistory(s);
303
+ }, Zt)) : this._pushHistory(s);
297
304
  }
298
305
  }
299
306
  _pushHistory(e) {
300
- const t = this._undoRedoService, n = this._stateCache.get(e);
301
- if (!Array.isArray(n) || n.length === 0)
307
+ const t = this._undoRedoService, s = this._stateCache.get(e);
308
+ if (!Array.isArray(s) || s.length === 0)
302
309
  return;
303
- const s = n.length, r = n[0].commandId, i = n[0], a = n[s - 1], c = {
310
+ const i = s.length, o = s[0].commandId, r = s[0], a = s[i - 1], c = {
304
311
  unitId: e,
305
- actions: n.reduce((l, u) => b.compose(l, u.redoState.actions), []),
312
+ actions: s.reduce((l, u) => U.compose(l, u.redoState.actions), null),
306
313
  textRanges: a.redoState.textRanges
307
314
  }, d = {
308
315
  unitId: e,
309
316
  // Always need to put undoParams after redoParams, because `reverse` will change the `cacheStates` order.
310
- actions: n.reverse().reduce((l, u) => b.compose(l, u.undoState.actions), []),
311
- textRanges: i.undoState.textRanges
317
+ actions: s.reverse().reduce((l, u) => U.compose(l, u.undoState.actions), null),
318
+ textRanges: r.undoState.textRanges
312
319
  };
313
320
  t.pushUndoRedo({
314
321
  unitID: e,
315
- undoMutations: [{ id: r, params: d }],
316
- redoMutations: [{ id: r, params: c }]
317
- }), n.length = 0;
322
+ undoMutations: [{ id: o, params: d }],
323
+ redoMutations: [{ id: o, params: c }]
324
+ }), s.length = 0;
318
325
  }
319
326
  };
320
- me = Qt([
321
- Ce(0, V(Te)),
322
- Ce(1, I),
323
- Ce(2, E)
327
+ me = Wt([
328
+ Re(0, V(Ee)),
329
+ Re(1, v),
330
+ Re(2, E)
324
331
  ], me);
325
- class he {
332
+ class pe {
326
333
  constructor() {
327
334
  y(this, "_previousActiveRange", null);
328
335
  y(this, "_undoMutationParamsCache", []);
@@ -354,13 +361,13 @@ class he {
354
361
  return null;
355
362
  const { unitId: e } = this._undoMutationParamsCache[0], t = {
356
363
  unitId: e,
357
- actions: this._undoMutationParamsCache.reverse().reduce((s, r) => b.compose(s, r.actions), []),
364
+ actions: this._undoMutationParamsCache.reverse().reduce((i, o) => U.compose(i, o.actions), null),
358
365
  textRanges: []
359
366
  // Add empty array, will never use, just fix type error
360
367
  };
361
368
  return { redoMutationParams: {
362
369
  unitId: e,
363
- actions: this._redoMutationParamsCache.reduce((s, r) => b.compose(s, r.actions), []),
370
+ actions: this._redoMutationParamsCache.reduce((i, o) => U.compose(i, o.actions), null),
364
371
  textRanges: []
365
372
  // Add empty array, will never use, just fix type error
366
373
  }, undoMutationParams: t, previousActiveRange: this._previousActiveRange };
@@ -369,193 +376,197 @@ class he {
369
376
  this._undoMutationParamsCache = [], this._redoMutationParamsCache = [], this._previousActiveRange = null;
370
377
  }
371
378
  }
372
- const qe = "doc.mutation.rich-text-editing", L = {
373
- id: qe,
374
- type: v.MUTATION,
379
+ const et = "doc.mutation.rich-text-editing", L = {
380
+ id: et,
381
+ type: _.MUTATION,
375
382
  // eslint-disable-next-line max-lines-per-function
376
- handler: (o, e) => {
377
- var B;
383
+ handler: (n, e) => {
384
+ var k;
378
385
  const {
379
386
  unitId: t,
380
- actions: n,
381
- textRanges: s,
387
+ segmentId: s = "",
388
+ actions: i,
389
+ textRanges: o,
382
390
  prevTextRanges: r,
383
- trigger: i,
384
- noHistory: a,
385
- isCompositionEnd: c,
386
- noNeedSetTextRange: d
387
- } = e, u = o.get(E).getUniverDocInstance(t), g = o.get(ne).getViewModel(t), p = o.get(T), f = ((B = p.getSelections()) != null ? B : []).map(Z), S = o.get(me), _ = o.get(he);
388
- if (u == null || g == null)
391
+ trigger: a,
392
+ noHistory: c,
393
+ isCompositionEnd: d,
394
+ noNeedSetTextRange: l
395
+ } = e, g = n.get(E).getUniverDocInstance(t), S = n.get(se).getViewModel(t), h = n.get(T), I = ((k = h.getSelections()) != null ? k : []).map(J), p = n.get(me), R = n.get(pe);
396
+ if (g == null || S == null)
389
397
  throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${t}`);
390
- const R = !!u.getSnapshot().disabled;
391
- if (n.length === 0 || R)
398
+ const C = !!g.getSnapshot().disabled;
399
+ if (U.isNoop(i) || i && i.length === 0 || C)
392
400
  return {
393
401
  unitId: t,
394
402
  actions: [],
395
- textRanges: f
403
+ textRanges: I
396
404
  };
397
- const M = u.apply(n), { segmentId: C } = n[0], D = u.getSelfOrHeaderFooterModel(C);
398
- g.getSelfOrHeaderFooterViewModel(C).reset(D), !d && s && i != null && queueMicrotask(() => {
399
- p.replaceTextRanges(s);
405
+ const M = U.invertWithDoc(i, g.getSnapshot());
406
+ g.apply(i);
407
+ const N = g.getSelfOrHeaderFooterModel(s);
408
+ S.getSelfOrHeaderFooterViewModel(s).reset(N), !l && o && a != null && queueMicrotask(() => {
409
+ h.replaceTextRanges(o);
400
410
  });
401
- const P = {
402
- commandId: qe,
411
+ const D = {
412
+ commandId: et,
403
413
  unitId: t,
404
- trigger: i,
405
- noHistory: a,
414
+ segmentId: s,
415
+ trigger: a,
416
+ noHistory: c,
406
417
  redoState: {
407
- actions: n,
408
- textRanges: s
418
+ actions: i,
419
+ textRanges: o
409
420
  },
410
421
  undoState: {
411
422
  actions: M,
412
- textRanges: r != null ? r : f
423
+ textRanges: r != null ? r : I
413
424
  }
414
425
  };
415
- if (c) {
416
- const O = _.fetchComposedUndoRedoMutationParams();
426
+ if (d) {
427
+ const O = R.fetchComposedUndoRedoMutationParams();
417
428
  if (O == null)
418
429
  throw new Error("historyParams is null in RichTextEditingMutation");
419
- const { undoMutationParams: U, redoMutationParams: w, previousActiveRange: X } = O;
420
- P.redoState.actions = w.actions, P.undoState.actions = U.actions, P.undoState.textRanges = [X];
430
+ const { undoMutationParams: P, redoMutationParams: w, previousActiveRange: Y } = O;
431
+ D.redoState.actions = w.actions, D.undoState.actions = P.actions, D.undoState.textRanges = [Y];
421
432
  }
422
- return S.setChangeState(P), {
433
+ return p.setChangeState(D), {
423
434
  unitId: t,
424
435
  actions: M,
425
- textRanges: f
436
+ textRanges: I
426
437
  };
427
438
  }
428
- }, pe = {
429
- id: "doc.command.insert-text",
430
- type: v.COMMAND,
431
- handler: async (o, e) => {
432
- const t = o.get(I), { range: n, segmentId: s, body: r, unitId: i, textRanges: a } = e, { startOffset: c, collapsed: d } = n, l = {
439
+ }, Jt = "doc.command.insert-text", Se = {
440
+ id: Jt,
441
+ type: _.COMMAND,
442
+ handler: async (n, e) => {
443
+ const t = n.get(v), { range: s, segmentId: i, body: o, unitId: r, textRanges: a } = e, { startOffset: c, collapsed: d } = s, l = {
433
444
  id: L.id,
434
445
  params: {
435
- unitId: i,
446
+ unitId: r,
436
447
  actions: [],
437
448
  textRanges: a
438
449
  }
439
- }, u = new b();
450
+ }, u = new B(), g = U.getInstance();
440
451
  return d ? c > 0 && u.push({
441
452
  t: x.RETAIN,
442
453
  len: c,
443
- segmentId: s
444
- }) : u.push(...be(n, s)), u.push({
454
+ segmentId: i
455
+ }) : u.push(...Pe(s, i)), u.push({
445
456
  t: x.INSERT,
446
- body: r,
447
- len: r.dataStream.length,
457
+ body: o,
458
+ len: o.dataStream.length,
448
459
  line: 0,
449
- segmentId: s
450
- }), l.params.actions = u.serialize(), !!t.syncExecuteCommand(l.id, l.params);
460
+ segmentId: i
461
+ }), l.params.actions = g.editOp(u.serialize()), !!t.syncExecuteCommand(l.id, l.params);
451
462
  }
452
463
  };
453
- var j = /* @__PURE__ */ ((o) => (o[o.LEFT = 0] = "LEFT", o[o.RIGHT = 1] = "RIGHT", o))(j || {});
454
- const Se = {
464
+ var H = /* @__PURE__ */ ((n) => (n[n.LEFT = 0] = "LEFT", n[n.RIGHT = 1] = "RIGHT", n))(H || {});
465
+ const Ie = {
455
466
  id: "doc.command.delete-text",
456
- type: v.COMMAND,
457
- handler: async (o, e) => {
458
- const t = o.get(I), { range: n, segmentId: s, unitId: r, direction: i, textRanges: a, len: c = 1 } = e, { startOffset: d } = n, l = {
467
+ type: _.COMMAND,
468
+ handler: async (n, e) => {
469
+ const t = n.get(v), { range: s, segmentId: i, unitId: o, direction: r, textRanges: a, len: c = 1 } = e, { startOffset: d } = s, l = {
459
470
  id: L.id,
460
471
  params: {
461
- unitId: r,
472
+ unitId: o,
462
473
  actions: [],
463
474
  textRanges: a
464
475
  }
465
- }, u = new b();
476
+ }, u = new B(), g = U.getInstance();
466
477
  return d > 0 && u.push({
467
478
  t: x.RETAIN,
468
- len: i === 0 ? d - c : d,
469
- segmentId: s
479
+ len: r === 0 ? d - c : d,
480
+ segmentId: i
470
481
  }), u.push({
471
482
  t: x.DELETE,
472
483
  len: c,
473
484
  line: 0,
474
- segmentId: s
475
- }), l.params.actions = u.serialize(), !!t.syncExecuteCommand(l.id, l.params);
485
+ segmentId: i
486
+ }), l.params.actions = g.editOp(u.serialize()), !!t.syncExecuteCommand(l.id, l.params);
476
487
  }
477
- }, ht = {
488
+ }, pt = {
478
489
  id: "doc.command.update-text",
479
- type: v.COMMAND,
480
- handler: async (o, e) => {
481
- const { range: t, segmentId: n, updateBody: s, coverType: r, unitId: i, textRanges: a } = e, c = o.get(I), d = {
490
+ type: _.COMMAND,
491
+ handler: async (n, e) => {
492
+ const { range: t, segmentId: s, updateBody: i, coverType: o, unitId: r, textRanges: a } = e, c = n.get(v), d = {
482
493
  id: L.id,
483
494
  params: {
484
- unitId: i,
495
+ unitId: r,
485
496
  actions: [],
486
497
  textRanges: a
487
498
  }
488
- }, l = new b(), { startOffset: u, endOffset: m } = t;
499
+ }, l = new B(), u = U.getInstance(), { startOffset: g, endOffset: m } = t;
489
500
  return l.push({
490
501
  t: x.RETAIN,
491
- len: u,
492
- segmentId: n
502
+ len: g,
503
+ segmentId: s
493
504
  }), l.push({
494
505
  t: x.RETAIN,
495
- body: s,
496
- len: m - u,
497
- segmentId: n,
498
- coverType: r
499
- }), d.params.actions = l.serialize(), !!c.syncExecuteCommand(d.id, d.params);
506
+ body: i,
507
+ len: m - g,
508
+ segmentId: s,
509
+ coverType: o
510
+ }), d.params.actions = u.editOp(l.serialize()), !!c.syncExecuteCommand(d.id, d.params);
500
511
  }
501
512
  };
502
- function tn(o, e) {
513
+ function Kt(n, e) {
503
514
  const t = [];
504
- for (let n = 0, s = o.length; n < s; n++)
505
- o[n] === xe.PARAGRAPH && t.push({
506
- startIndex: n
515
+ for (let s = 0, i = n.length; s < i; s++)
516
+ n[s] === ye.PARAGRAPH && t.push({
517
+ startIndex: s
507
518
  });
508
519
  if (e)
509
- for (const n of t)
510
- e.bullet && (n.bullet = Q.deepClone(e.bullet)), e.paragraphStyle && (n.paragraphStyle = Q.deepClone(e.paragraphStyle));
520
+ for (const s of t)
521
+ e.bullet && (s.bullet = ee.deepClone(e.bullet)), e.paragraphStyle && (s.paragraphStyle = ee.deepClone(e.paragraphStyle));
511
522
  return t;
512
523
  }
513
- const nn = {
524
+ const qt = {
514
525
  id: "doc.command.break-line",
515
- type: v.COMMAND,
516
- handler: async (o) => {
517
- var p, h;
518
- const e = o.get(T), t = o.get(E), n = o.get(I), s = e.getActiveRange();
519
- if (s == null)
526
+ type: _.COMMAND,
527
+ handler: async (n) => {
528
+ var S, h;
529
+ const e = n.get(T), t = n.get(E), s = n.get(v), i = e.getActiveRange();
530
+ if (i == null)
520
531
  return !1;
521
- const r = t.getCurrentUniverDocInstance();
522
- if (!r)
532
+ const o = t.getCurrentUniverDocInstance();
533
+ if (!o)
523
534
  return !1;
524
- const i = r.getUnitId(), { startOffset: a, segmentId: c, style: d } = s, l = [
535
+ const r = o.getUnitId(), { startOffset: a, segmentId: c, style: d } = i, l = [
525
536
  {
526
537
  startOffset: a + 1,
527
538
  endOffset: a + 1,
528
539
  style: d
529
540
  }
530
- ], m = ((h = (p = r.getBody()) == null ? void 0 : p.paragraphs) != null ? h : []).find((f) => f.startIndex >= a);
531
- return await n.executeCommand(pe.id, {
532
- unitId: i,
541
+ ], g = ((h = (S = o.getBody()) == null ? void 0 : S.paragraphs) != null ? h : []).find((f) => f.startIndex >= a);
542
+ return await s.executeCommand(Se.id, {
543
+ unitId: r,
533
544
  body: {
534
- dataStream: xe.PARAGRAPH,
535
- paragraphs: tn(xe.PARAGRAPH, m)
545
+ dataStream: ye.PARAGRAPH,
546
+ paragraphs: Kt(ye.PARAGRAPH, g)
536
547
  },
537
- range: s,
548
+ range: i,
538
549
  textRanges: l,
539
550
  segmentId: c
540
551
  });
541
552
  }
542
553
  };
543
- var on = Object.defineProperty, sn = Object.getOwnPropertyDescriptor, rn = (o, e, t, n) => {
544
- for (var s = n > 1 ? void 0 : n ? sn(e, t) : e, r = o.length - 1, i; r >= 0; r--)
545
- (i = o[r]) && (s = (n ? i(e, t, s) : i(s)) || s);
546
- return n && s && on(e, t, s), s;
547
- }, Re = (o, e) => (t, n) => e(t, n, o);
548
- let H = class extends ge {
549
- constructor(e, t, n) {
554
+ var Qt = (n, e, t, s) => {
555
+ for (var i = e, o = n.length - 1, r; o >= 0; o--)
556
+ (r = n[o]) && (i = r(i) || i);
557
+ return i;
558
+ }, xe = (n, e) => (t, s) => e(t, s, n);
559
+ let j = class extends he {
560
+ constructor(e, t, s) {
550
561
  super();
551
562
  y(this, "_currentSkeletonUnitId", "");
552
563
  y(this, "_docSkeletonMap", /* @__PURE__ */ new Map());
553
- y(this, "_currentSkeleton$", new ee(null));
564
+ y(this, "_currentSkeleton$", new te(null));
554
565
  y(this, "currentSkeleton$", this._currentSkeleton$.asObservable());
555
566
  // CurrentSkeletonBefore for pre-triggered logic during registration
556
- y(this, "_currentSkeletonBefore$", new ee(null));
567
+ y(this, "_currentSkeletonBefore$", new te(null));
557
568
  y(this, "currentSkeletonBefore$", this._currentSkeletonBefore$.asObservable());
558
- this._localeService = e, this._docViewModelManagerService = t, this._univerInstanceService = n, this._initialize();
569
+ this._localeService = e, this._docViewModelManagerService = t, this._univerInstanceService = s, this._initialize();
559
570
  }
560
571
  _initialize() {
561
572
  this._init();
@@ -564,13 +575,13 @@ let H = class extends ge {
564
575
  this._currentSkeletonBefore$.complete(), this._currentSkeleton$.complete(), this._docSkeletonMap.clear();
565
576
  }
566
577
  _init() {
567
- this._docViewModelManagerService.currentDocViewModel$.pipe(te(this.dispose$)).subscribe((e) => {
578
+ this._docViewModelManagerService.currentDocViewModel$.pipe(ne(this.dispose$)).subscribe((e) => {
568
579
  e != null && this._setCurrent(e);
569
580
  }), this._docViewModelManagerService.getAllModel().forEach((e) => {
570
581
  e != null && this._setCurrent(e);
571
- }), this._univerInstanceService.getTypeOfUnitDisposed$(W.UNIVER_DOC).pipe(te(this.dispose$)).subscribe((e) => {
572
- var t, n;
573
- this._docSkeletonMap.delete(e.getUnitId()), this._currentSkeletonUnitId = (n = (t = this._univerInstanceService.getCurrentUnitForType(W.UNIVER_DOC)) == null ? void 0 : t.getUnitId()) != null ? n : "";
582
+ }), this._univerInstanceService.getTypeOfUnitDisposed$(Z.UNIVER_DOC).pipe(ne(this.dispose$)).subscribe((e) => {
583
+ var t, s;
584
+ this._docSkeletonMap.delete(e.getUnitId()), this._currentSkeletonUnitId = (s = (t = this._univerInstanceService.getCurrentUnitForType(Z.UNIVER_DOC)) == null ? void 0 : t.getUnitId()) != null ? s : "";
574
585
  });
575
586
  }
576
587
  getCurrent() {
@@ -583,8 +594,8 @@ let H = class extends ge {
583
594
  this.makeDirty(this._currentSkeletonUnitId, e);
584
595
  }
585
596
  makeDirty(e, t = !0) {
586
- const n = this.getSkeletonByUnitId(e);
587
- n != null && (n.dirty = t);
597
+ const s = this.getSkeletonByUnitId(e);
598
+ s != null && (s.dirty = t);
588
599
  }
589
600
  getSkeletonByUnitId(e) {
590
601
  return this._docSkeletonMap.get(e);
@@ -592,32 +603,32 @@ let H = class extends ge {
592
603
  _setCurrent(e) {
593
604
  const { unitId: t } = e;
594
605
  if (this._docSkeletonMap.has(t)) {
595
- const n = this.getSkeletonByUnitId(t);
596
- n.skeleton.calculate(), n.dirty = !0;
606
+ const s = this.getSkeletonByUnitId(t);
607
+ s.skeleton.calculate(), s.dirty = !0;
597
608
  } else {
598
- const n = this._buildSkeleton(e.docViewModel);
599
- n.calculate(), this._docSkeletonMap.set(t, {
609
+ const s = this._buildSkeleton(e.docViewModel);
610
+ s.calculate(), this._docSkeletonMap.set(t, {
600
611
  unitId: t,
601
- skeleton: n,
612
+ skeleton: s,
602
613
  dirty: !1
603
614
  });
604
615
  }
605
616
  return this._currentSkeletonUnitId = t, this._currentSkeletonBefore$.next(this.getCurrent()), this._currentSkeleton$.next(this.getCurrent()), this.getCurrent();
606
617
  }
607
618
  _buildSkeleton(e) {
608
- return Ut.create(e, this._localeService);
619
+ return wt.create(e, this._localeService);
609
620
  }
610
621
  };
611
- H = rn([
612
- Re(0, V(Tt)),
613
- Re(1, V(ne)),
614
- Re(2, E)
615
- ], H);
616
- const Zn = {
622
+ j = Qt([
623
+ xe(0, V(At)),
624
+ xe(1, V(se)),
625
+ xe(2, E)
626
+ ], j);
627
+ const wn = {
617
628
  id: "doc.command.inner-paste",
618
- type: v.COMMAND,
619
- handler: async (o, e) => {
620
- const { segmentId: t, body: n, textRanges: s } = e, r = o.get(I), i = o.get(T), a = o.get(E), c = i.getSelections();
629
+ type: _.COMMAND,
630
+ handler: async (n, e) => {
631
+ const { segmentId: t, body: s, textRanges: i } = e, o = n.get(v), r = n.get(T), a = n.get(E), c = r.getSelections();
621
632
  if (!Array.isArray(c) || c.length === 0)
622
633
  return !1;
623
634
  const d = a.getCurrentUniverDocInstance();
@@ -628,39 +639,39 @@ const Zn = {
628
639
  params: {
629
640
  unitId: l,
630
641
  actions: [],
631
- textRanges: s
642
+ textRanges: i
632
643
  }
633
- }, m = new se();
634
- m.reset();
635
- const g = new b();
636
- for (const h of c) {
637
- const { startOffset: f, endOffset: S, collapsed: _ } = h, R = f - m.cursor;
638
- _ ? g.push({
644
+ }, g = new ie();
645
+ g.reset();
646
+ const m = new B(), S = U.getInstance();
647
+ for (const f of c) {
648
+ const { startOffset: I, endOffset: p, collapsed: R } = f, C = I - g.cursor;
649
+ R ? m.push({
639
650
  t: x.RETAIN,
640
- len: R,
651
+ len: C,
641
652
  segmentId: t
642
- }) : g.push(...be(h, t, m.cursor)), g.push({
653
+ }) : m.push(...Pe(f, t, g.cursor)), m.push({
643
654
  t: x.INSERT,
644
- body: n,
645
- len: n.dataStream.length,
655
+ body: s,
656
+ len: s.dataStream.length,
646
657
  line: 0,
647
658
  segmentId: t
648
- }), m.reset(), m.moveCursor(S);
659
+ }), g.reset(), g.moveCursor(p);
649
660
  }
650
- return u.params.actions = g.serialize(), !!r.syncExecuteCommand(u.id, u.params);
661
+ return u.params.actions = S.editOp(m.serialize()), !!o.syncExecuteCommand(u.id, u.params);
651
662
  }
652
- }, pt = {
663
+ }, St = {
653
664
  id: "doc.command.inner-cut",
654
- type: v.COMMAND,
655
- handler: async (o, e) => {
656
- var h;
657
- const { segmentId: t, textRanges: n } = e, s = o.get(I), r = o.get(T), i = o.get(E), a = r.getSelections();
665
+ type: _.COMMAND,
666
+ handler: async (n, e) => {
667
+ var f;
668
+ const { segmentId: t, textRanges: s } = e, i = n.get(v), o = n.get(T), r = n.get(E), a = o.getSelections();
658
669
  if (!Array.isArray(a) || a.length === 0)
659
670
  return !1;
660
- const c = (h = i.getCurrentUniverDocInstance()) == null ? void 0 : h.getUnitId();
671
+ const c = (f = r.getCurrentUniverDocInstance()) == null ? void 0 : f.getUnitId();
661
672
  if (!c)
662
673
  return !1;
663
- const d = i.getUniverDocInstance(c), l = Et(d.snapshot, t);
674
+ const d = r.getUniverDocInstance(c), l = Nt(d.getSnapshot(), t);
664
675
  if (l == null)
665
676
  return !1;
666
677
  const u = {
@@ -668,297 +679,297 @@ const Zn = {
668
679
  params: {
669
680
  unitId: c,
670
681
  actions: [],
671
- textRanges: n
682
+ textRanges: s
672
683
  }
673
- }, m = new se();
674
- m.reset();
675
- const g = new b();
676
- for (const f of a) {
677
- const { startOffset: S, endOffset: _, collapsed: R } = f, M = S - m.cursor;
678
- R ? g.push({
684
+ }, g = new ie();
685
+ g.reset();
686
+ const m = new B(), S = U.getInstance();
687
+ for (const I of a) {
688
+ const { startOffset: p, endOffset: R, collapsed: C } = I, M = p - g.cursor;
689
+ C ? m.push({
679
690
  t: x.RETAIN,
680
691
  len: M,
681
692
  segmentId: t
682
- }) : g.push(...an(f, l, t, m.cursor)), m.reset(), m.moveCursor(_);
693
+ }) : m.push(...en(I, l, t, g.cursor)), g.reset(), g.moveCursor(R);
683
694
  }
684
- return u.params.actions = g.serialize(), !!s.syncExecuteCommand(u.id, u.params);
695
+ return u.params.actions = S.editOp(m.serialize()), !!i.syncExecuteCommand(u.id, u.params);
685
696
  }
686
697
  };
687
- function an(o, e, t = "", n = 0) {
688
- const { startOffset: s, endOffset: r } = o, i = [], { paragraphs: a = [] } = e, c = s - n, d = r - n, l = a == null ? void 0 : a.find(
689
- (u) => u.startIndex - n >= c && u.startIndex - n <= d
698
+ function en(n, e, t = "", s = 0) {
699
+ const { startOffset: i, endOffset: o } = n, r = [], { paragraphs: a = [] } = e, c = i - s, d = o - s, l = a == null ? void 0 : a.find(
700
+ (u) => u.startIndex - s >= c && u.startIndex - s <= d
690
701
  );
691
- if (c > 0 && i.push({
702
+ if (c > 0 && r.push({
692
703
  t: x.RETAIN,
693
704
  len: c,
694
705
  segmentId: t
695
- }), l && l.startIndex - n > c) {
696
- const u = l.startIndex - n;
697
- i.push({
706
+ }), l && l.startIndex - s > c) {
707
+ const u = l.startIndex - s;
708
+ r.push({
698
709
  t: x.DELETE,
699
710
  len: u - c,
700
711
  line: 0,
701
712
  segmentId: t
702
- }), i.push({
713
+ }), r.push({
703
714
  t: x.RETAIN,
704
715
  len: 1,
705
716
  segmentId: t
706
- }), d > u + 1 && i.push({
717
+ }), d > u + 1 && r.push({
707
718
  t: x.DELETE,
708
719
  len: d - u - 1,
709
720
  line: 0,
710
721
  segmentId: t
711
722
  });
712
723
  } else
713
- i.push({
724
+ r.push({
714
725
  t: x.DELETE,
715
726
  len: d - c,
716
727
  line: 0,
717
728
  segmentId: t
718
729
  });
719
- return i;
730
+ return r;
720
731
  }
721
- const cn = {
732
+ const tn = {
722
733
  id: "doc.command.delete-left",
723
- type: v.COMMAND,
734
+ type: _.COMMAND,
724
735
  // eslint-disable-next-line max-lines-per-function
725
- handler: async (o) => {
726
- var M;
727
- const e = o.get(T), t = o.get(H), n = o.get(E), s = o.get(I), r = e.getActiveRange(), i = e.getSelections(), a = (M = t.getCurrent()) == null ? void 0 : M.skeleton;
736
+ handler: async (n) => {
737
+ var C;
738
+ const e = n.get(T), t = n.get(j), s = n.get(E), i = n.get(v), o = e.getActiveRange(), r = e.getSelections(), a = (C = t.getCurrent()) == null ? void 0 : C.skeleton;
728
739
  let c = !0;
729
- if (r == null || a == null || i == null)
740
+ if (o == null || a == null || r == null)
730
741
  return !1;
731
- const d = n.getCurrentUniverDocInstance();
742
+ const d = s.getCurrentUniverDocInstance();
732
743
  if (!d)
733
744
  return !1;
734
- const { startOffset: l, collapsed: u, segmentId: m, style: g } = r, p = a.findNodeByCharIndex(l), h = wt(p), f = Lt(p, d.getBody());
735
- let S = l;
736
- const _ = a.findNodeByCharIndex(l - 1);
737
- if (Bt(p) && _ !== p && (h === !0 || f === !0) && u) {
738
- const C = Ft(p, d.getBody());
739
- if (C == null)
745
+ const { startOffset: l, collapsed: u, segmentId: g, style: m } = o, S = a.findNodeByCharIndex(l), h = kt(S), f = Lt(S, d.getBody());
746
+ let I = l;
747
+ const p = a.findNodeByCharIndex(l - 1);
748
+ if (Bt(S) && p !== S && (h === !0 || f === !0) && u) {
749
+ const M = Ft(S, d.getBody());
750
+ if (M == null)
740
751
  return !1;
741
- const D = C == null ? void 0 : C.startIndex, A = { startIndex: 0 }, P = C.paragraphStyle;
752
+ const N = M == null ? void 0 : M.startIndex, A = { startIndex: 0 }, D = M.paragraphStyle;
742
753
  if (h === !0) {
743
- const O = C.paragraphStyle;
754
+ const O = M.paragraphStyle;
744
755
  if (O) {
745
756
  A.paragraphStyle = O;
746
- const { hanging: U } = O;
747
- U && (A.paragraphStyle.indentStart = U, A.paragraphStyle.hanging = void 0);
757
+ const { hanging: P } = O;
758
+ P && (A.paragraphStyle.indentStart = P, A.paragraphStyle.hanging = void 0);
748
759
  }
749
760
  } else if (f === !0) {
750
- const O = C.bullet;
751
- O && (A.bullet = O), P != null && (A.paragraphStyle = { ...P }, delete A.paragraphStyle.hanging, delete A.paragraphStyle.indentStart);
761
+ const O = M.bullet;
762
+ O && (A.bullet = O), D != null && (A.paragraphStyle = { ...D }, delete A.paragraphStyle.hanging, delete A.paragraphStyle.indentStart);
752
763
  }
753
- const B = [
764
+ const k = [
754
765
  {
755
- startOffset: S,
756
- endOffset: S,
757
- style: g
766
+ startOffset: I,
767
+ endOffset: I,
768
+ style: m
758
769
  }
759
770
  ];
760
- c = await s.executeCommand(ht.id, {
771
+ c = await i.executeCommand(pt.id, {
761
772
  unitId: d.getUnitId(),
762
773
  updateBody: {
763
774
  dataStream: "",
764
775
  paragraphs: [{ ...A }]
765
776
  },
766
777
  range: {
767
- startOffset: D,
768
- endOffset: D + 1
778
+ startOffset: N,
779
+ endOffset: N + 1
769
780
  },
770
- textRanges: B,
771
- coverType: Ee.REPLACE,
772
- segmentId: m
781
+ textRanges: k,
782
+ coverType: Ae.REPLACE,
783
+ segmentId: g
773
784
  });
774
785
  } else if (u === !0) {
775
- if (_ == null)
786
+ if (p == null)
776
787
  return !0;
777
- if (_.content === "\r")
778
- c = await s.executeCommand(Ue.id, {
779
- direction: j.LEFT,
780
- range: r
788
+ if (p.content === "\r")
789
+ c = await i.executeCommand(we.id, {
790
+ direction: H.LEFT,
791
+ range: o
781
792
  });
782
793
  else {
783
- S -= _.count;
784
- const C = [
794
+ I -= p.count;
795
+ const M = [
785
796
  {
786
- startOffset: S,
787
- endOffset: S,
788
- style: g
797
+ startOffset: I,
798
+ endOffset: I,
799
+ style: m
789
800
  }
790
801
  ];
791
- c = await s.executeCommand(Se.id, {
802
+ c = await i.executeCommand(Ie.id, {
792
803
  unitId: d.getUnitId(),
793
- range: r,
794
- segmentId: m,
795
- direction: j.LEFT,
796
- len: _.count,
797
- textRanges: C
804
+ range: o,
805
+ segmentId: g,
806
+ direction: H.LEFT,
807
+ len: p.count,
808
+ textRanges: M
798
809
  });
799
810
  }
800
811
  } else {
801
- const C = St(r, i);
802
- c = await s.executeCommand(pt.id, {
803
- segmentId: m,
804
- textRanges: C
812
+ const M = It(o, r);
813
+ c = await i.executeCommand(St.id, {
814
+ segmentId: g,
815
+ textRanges: M
805
816
  });
806
817
  }
807
818
  return c;
808
819
  }
809
- }, ln = {
820
+ }, nn = {
810
821
  id: "doc.command.delete-right",
811
- type: v.COMMAND,
812
- handler: async (o) => {
813
- var p;
814
- const e = o.get(T), t = o.get(H), n = o.get(E), s = o.get(I), r = e.getActiveRange(), i = e.getSelections(), a = (p = t.getCurrent()) == null ? void 0 : p.skeleton;
822
+ type: _.COMMAND,
823
+ handler: async (n) => {
824
+ var S;
825
+ const e = n.get(T), t = n.get(j), s = n.get(E), i = n.get(v), o = e.getActiveRange(), r = e.getSelections(), a = (S = t.getCurrent()) == null ? void 0 : S.skeleton;
815
826
  let c;
816
- if (r == null || a == null || i == null)
827
+ if (o == null || a == null || r == null)
817
828
  return !1;
818
- const d = n.getCurrentUniverDocInstance();
829
+ const d = s.getCurrentUniverDocInstance();
819
830
  if (!d)
820
831
  return !1;
821
- const { startOffset: l, collapsed: u, segmentId: m, style: g } = r;
832
+ const { startOffset: l, collapsed: u, segmentId: g, style: m } = o;
822
833
  if (l === d.getBody().dataStream.length - 2 && u)
823
834
  return !0;
824
835
  if (u === !0) {
825
836
  const h = a.findNodeByCharIndex(l);
826
837
  if (h.content === "\r")
827
- c = await s.executeCommand(Ue.id, {
828
- direction: j.RIGHT,
829
- range: r
838
+ c = await i.executeCommand(we.id, {
839
+ direction: H.RIGHT,
840
+ range: o
830
841
  });
831
842
  else {
832
843
  const f = [
833
844
  {
834
845
  startOffset: l,
835
846
  endOffset: l,
836
- style: g
847
+ style: m
837
848
  }
838
849
  ];
839
- c = await s.executeCommand(Se.id, {
850
+ c = await i.executeCommand(Ie.id, {
840
851
  unitId: d.getUnitId(),
841
- range: r,
842
- segmentId: m,
843
- direction: j.RIGHT,
852
+ range: o,
853
+ segmentId: g,
854
+ direction: H.RIGHT,
844
855
  textRanges: f,
845
856
  len: h.count
846
857
  });
847
858
  }
848
859
  } else {
849
- const h = St(r, i);
850
- c = await s.executeCommand(pt.id, {
851
- segmentId: m,
860
+ const h = It(o, r);
861
+ c = await i.executeCommand(St.id, {
862
+ segmentId: g,
852
863
  textRanges: h
853
864
  });
854
865
  }
855
866
  return c;
856
867
  }
857
- }, Ue = {
868
+ }, we = {
858
869
  id: "doc.command.merge-two-paragraph",
859
- type: v.COMMAND,
870
+ type: _.COMMAND,
860
871
  // eslint-disable-next-line max-lines-per-function
861
- handler: async (o, e) => {
862
- var A, P, B;
863
- const t = o.get(T), n = o.get(E), s = o.get(I), { direction: r, range: i } = e, a = t.getActiveRange(), c = t.getSelections();
872
+ handler: async (n, e) => {
873
+ var D, k, O;
874
+ const t = n.get(T), s = n.get(E), i = n.get(v), { direction: o, range: r } = e, a = t.getActiveRange(), c = t.getSelections();
864
875
  if (a == null || c == null)
865
876
  return !1;
866
- const d = n.getCurrentUniverDocInstance();
877
+ const d = s.getCurrentUniverDocInstance();
867
878
  if (!d)
868
879
  return !1;
869
- const { startOffset: l, collapsed: u, segmentId: m, style: g } = a;
880
+ const { startOffset: l, collapsed: u, segmentId: g, style: m } = a;
870
881
  if (!u)
871
882
  return !1;
872
- const p = r === j.LEFT ? l : l + 1, h = (B = (P = (A = d.getBody()) == null ? void 0 : A.paragraphs) == null ? void 0 : P.find((O) => O.startIndex >= p)) == null ? void 0 : B.startIndex, f = dn(d.getBody(), p, h), S = r === j.LEFT ? l - 1 : l, _ = d.getUnitId(), R = [
883
+ const S = o === H.LEFT ? l : l + 1, h = (O = (k = (D = d.getBody()) == null ? void 0 : D.paragraphs) == null ? void 0 : k.find((P) => P.startIndex >= S)) == null ? void 0 : O.startIndex, f = sn(d.getBody(), S, h), I = o === H.LEFT ? l - 1 : l, p = d.getUnitId(), R = [
873
884
  {
874
- startOffset: S,
875
- endOffset: S,
876
- style: g
885
+ startOffset: I,
886
+ endOffset: I,
887
+ style: m
877
888
  }
878
- ], M = {
889
+ ], C = {
879
890
  id: L.id,
880
891
  params: {
881
- unitId: _,
892
+ unitId: p,
882
893
  actions: [],
883
894
  textRanges: R,
884
- prevTextRanges: [i]
895
+ prevTextRanges: [r]
885
896
  }
886
- }, C = new b();
887
- return C.push({
897
+ }, M = new B(), N = U.getInstance();
898
+ return M.push({
888
899
  t: x.RETAIN,
889
- len: r === j.LEFT ? l - 1 : l,
890
- segmentId: m
891
- }), f.dataStream.length && C.push({
900
+ len: o === H.LEFT ? l - 1 : l,
901
+ segmentId: g
902
+ }), f.dataStream.length && M.push({
892
903
  t: x.INSERT,
893
904
  body: f,
894
905
  len: f.dataStream.length,
895
906
  line: 0,
896
- segmentId: m
897
- }), C.push({
907
+ segmentId: g
908
+ }), M.push({
898
909
  t: x.RETAIN,
899
910
  len: 1,
900
- segmentId: m
901
- }), C.push({
911
+ segmentId: g
912
+ }), M.push({
902
913
  t: x.DELETE,
903
- len: h + 1 - p,
914
+ len: h + 1 - S,
904
915
  line: 0,
905
- segmentId: m
906
- }), M.params.actions = C.serialize(), !!s.syncExecuteCommand(M.id, M.params);
916
+ segmentId: g
917
+ }), C.params.actions = N.editOp(M.serialize()), !!i.syncExecuteCommand(C.id, C.params);
907
918
  }
908
919
  };
909
- function dn(o, e, t) {
910
- const { textRuns: n } = o, s = o.dataStream.substring(e, t);
911
- if (n == null)
920
+ function sn(n, e, t) {
921
+ const { textRuns: s } = n, i = n.dataStream.substring(e, t);
922
+ if (s == null)
912
923
  return {
913
- dataStream: s
924
+ dataStream: i
914
925
  };
915
- const r = [];
916
- for (const i of n) {
917
- const { st: a, ed: c } = i;
918
- c <= e || a >= t || (a < e ? r.push({
919
- ...i,
926
+ const o = [];
927
+ for (const r of s) {
928
+ const { st: a, ed: c } = r;
929
+ c <= e || a >= t || (a < e ? o.push({
930
+ ...r,
920
931
  st: 0,
921
932
  ed: c - e
922
- }) : c > t ? r.push({
923
- ...i,
933
+ }) : c > t ? o.push({
934
+ ...r,
924
935
  st: a - e,
925
936
  ed: t - e
926
- }) : r.push({
927
- ...i,
937
+ }) : o.push({
938
+ ...r,
928
939
  st: a - e,
929
940
  ed: c - e
930
941
  }));
931
942
  }
932
943
  return {
933
- dataStream: s,
934
- textRuns: r
944
+ dataStream: i,
945
+ textRuns: o
935
946
  };
936
947
  }
937
- function St(o, e) {
938
- let t = o.endOffset;
939
- for (const s of e) {
940
- const { startOffset: r, endOffset: i } = s;
941
- r == null || i == null || i <= o.endOffset && (t -= i - r);
948
+ function It(n, e) {
949
+ let t = n.endOffset;
950
+ for (const i of e) {
951
+ const { startOffset: o, endOffset: r } = i;
952
+ o == null || r == null || r <= n.endOffset && (t -= r - o);
942
953
  }
943
954
  return [
944
955
  {
945
956
  startOffset: t,
946
957
  endOffset: t,
947
- style: o.style
958
+ style: n.style
948
959
  }
949
960
  ];
950
961
  }
951
962
  const _t = {
952
963
  id: "doc.command.ime-input",
953
- type: v.COMMAND,
954
- handler: async (o, e) => {
955
- const { unitId: t, newText: n, oldTextLen: s, isCompositionEnd: r, isCompositionStart: i } = e, a = o.get(I), c = o.get(he), d = c.getActiveRange();
964
+ type: _.COMMAND,
965
+ handler: async (n, e) => {
966
+ const { unitId: t, newText: s, oldTextLen: i, isCompositionEnd: o, isCompositionStart: r } = e, a = n.get(v), c = n.get(pe), d = c.getActiveRange();
956
967
  if (d == null)
957
968
  return !1;
958
- const { startOffset: l, style: u, segmentId: m } = d, g = n.length, p = [
969
+ const { startOffset: l, style: u, segmentId: g } = d, m = s.length, S = [
959
970
  {
960
- startOffset: l + g,
961
- endOffset: l + g,
971
+ startOffset: l + m,
972
+ endOffset: l + m,
962
973
  collapsed: !0,
963
974
  style: u
964
975
  }
@@ -967,610 +978,612 @@ const _t = {
967
978
  params: {
968
979
  unitId: t,
969
980
  actions: [],
970
- textRanges: p
981
+ textRanges: S
971
982
  }
972
- }, f = new b();
973
- !d.collapsed && i ? f.push(...be(d, m)) : f.push({
983
+ }, f = new B(), I = U.getInstance();
984
+ !d.collapsed && r ? f.push(...Pe(d, g)) : f.push({
974
985
  t: x.RETAIN,
975
986
  len: l,
976
- segmentId: m
977
- }), s > 0 && f.push({
987
+ segmentId: g
988
+ }), i > 0 && f.push({
978
989
  t: x.DELETE,
979
- len: s,
990
+ len: i,
980
991
  line: 0,
981
- segmentId: m
992
+ segmentId: g
982
993
  }), f.push({
983
994
  t: x.INSERT,
984
995
  body: {
985
- dataStream: n
996
+ dataStream: s
986
997
  },
987
- len: n.length,
998
+ len: s.length,
988
999
  line: 0,
989
- segmentId: m
990
- }), h.params.actions = f.serialize(), h.params.noHistory = !r, h.params.isCompositionEnd = r;
991
- const S = a.syncExecuteCommand(h.id, h.params);
992
- return c.pushUndoRedoMutationParams(S, h.params), !!S;
1000
+ segmentId: g
1001
+ }), h.params.actions = I.editOp(f.serialize()), h.params.noHistory = !o, h.params.isCompositionEnd = o;
1002
+ const p = a.syncExecuteCommand(h.id, h.params);
1003
+ return c.pushUndoRedoMutationParams(p, h.params), !!p;
993
1004
  }
994
1005
  };
995
- function F(o, e, t, n) {
996
- var r;
997
- const { segmentId: s } = (r = t.getActiveRange()) != null ? r : {};
998
- return s == null ? !1 : n.executeCommand(It.id, {
999
- segmentId: s,
1000
- preCommandId: o,
1006
+ function F(n, e, t, s) {
1007
+ var o;
1008
+ const { segmentId: i } = (o = t.getActiveRange()) != null ? o : {};
1009
+ return i == null ? !1 : s.executeCommand(Mt.id, {
1010
+ segmentId: i,
1011
+ preCommandId: n,
1001
1012
  ...e != null ? e : {}
1002
1013
  });
1003
1014
  }
1004
- const Qe = "doc.command.set-inline-format-bold", we = {
1005
- id: Qe,
1006
- type: v.COMMAND,
1007
- handler: async (o, e) => {
1008
- const t = o.get(I), n = o.get(T);
1009
- return F(
1010
- Qe,
1011
- e,
1012
- n,
1013
- t
1014
- );
1015
- }
1016
- }, et = "doc.command.set-inline-format-italic", Le = {
1017
- id: et,
1018
- type: v.COMMAND,
1019
- handler: async (o, e) => {
1020
- const t = o.get(I), n = o.get(T);
1021
- return F(
1022
- et,
1023
- e,
1024
- n,
1025
- t
1026
- );
1027
- }
1028
- }, tt = "doc.command.set-inline-format-underline", Be = {
1015
+ const tt = "doc.command.set-inline-format-bold", ke = {
1029
1016
  id: tt,
1030
- type: v.COMMAND,
1031
- handler: async (o, e) => {
1032
- const t = o.get(I), n = o.get(T);
1017
+ type: _.COMMAND,
1018
+ handler: async (n, e) => {
1019
+ const t = n.get(v), s = n.get(T);
1033
1020
  return F(
1034
1021
  tt,
1035
1022
  e,
1036
- n,
1023
+ s,
1037
1024
  t
1038
1025
  );
1039
1026
  }
1040
- }, nt = "doc.command.set-inline-format-strikethrough", Fe = {
1027
+ }, nt = "doc.command.set-inline-format-italic", Le = {
1041
1028
  id: nt,
1042
- type: v.COMMAND,
1043
- handler: async (o, e) => {
1044
- const t = o.get(I), n = o.get(T);
1029
+ type: _.COMMAND,
1030
+ handler: async (n, e) => {
1031
+ const t = n.get(v), s = n.get(T);
1045
1032
  return F(
1046
1033
  nt,
1047
1034
  e,
1048
- n,
1035
+ s,
1049
1036
  t
1050
1037
  );
1051
1038
  }
1052
- }, ot = "doc.command.set-inline-format-subscript", oe = {
1053
- id: ot,
1054
- type: v.COMMAND,
1055
- handler: async (o, e) => {
1056
- const t = o.get(I), n = o.get(T);
1039
+ }, st = "doc.command.set-inline-format-underline", Be = {
1040
+ id: st,
1041
+ type: _.COMMAND,
1042
+ handler: async (n, e) => {
1043
+ const t = n.get(v), s = n.get(T);
1057
1044
  return F(
1058
- ot,
1045
+ st,
1059
1046
  e,
1060
- n,
1047
+ s,
1061
1048
  t
1062
1049
  );
1063
1050
  }
1064
- }, st = "doc.command.set-inline-format-superscript", $e = {
1065
- id: st,
1066
- type: v.COMMAND,
1067
- handler: async (o, e) => {
1068
- const t = o.get(I), n = o.get(T);
1051
+ }, ot = "doc.command.set-inline-format-strikethrough", Fe = {
1052
+ id: ot,
1053
+ type: _.COMMAND,
1054
+ handler: async (n, e) => {
1055
+ const t = n.get(v), s = n.get(T);
1069
1056
  return F(
1070
- st,
1057
+ ot,
1071
1058
  e,
1072
- n,
1059
+ s,
1073
1060
  t
1074
1061
  );
1075
1062
  }
1076
- }, rt = "doc.command.set-inline-format-fontsize", Ve = {
1077
- id: rt,
1078
- type: v.COMMAND,
1079
- handler: async (o, e) => {
1080
- const t = o.get(I), n = o.get(T);
1063
+ }, it = "doc.command.set-inline-format-subscript", oe = {
1064
+ id: it,
1065
+ type: _.COMMAND,
1066
+ handler: async (n, e) => {
1067
+ const t = n.get(v), s = n.get(T);
1081
1068
  return F(
1082
- rt,
1069
+ it,
1083
1070
  e,
1084
- n,
1071
+ s,
1085
1072
  t
1086
1073
  );
1087
1074
  }
1088
- }, it = "doc.command.set-inline-format-font-family", ke = {
1089
- id: it,
1090
- type: v.COMMAND,
1091
- handler: async (o, e) => {
1092
- const t = o.get(I), n = o.get(T);
1075
+ }, rt = "doc.command.set-inline-format-superscript", $e = {
1076
+ id: rt,
1077
+ type: _.COMMAND,
1078
+ handler: async (n, e) => {
1079
+ const t = n.get(v), s = n.get(T);
1093
1080
  return F(
1094
- it,
1081
+ rt,
1095
1082
  e,
1096
- n,
1083
+ s,
1097
1084
  t
1098
1085
  );
1099
1086
  }
1100
- }, at = "doc.command.set-inline-format-text-color", ze = {
1087
+ }, at = "doc.command.set-inline-format-fontsize", Ve = {
1101
1088
  id: at,
1102
- type: v.COMMAND,
1103
- handler: async (o, e) => {
1104
- const t = o.get(I), n = o.get(T);
1089
+ type: _.COMMAND,
1090
+ handler: async (n, e) => {
1091
+ const t = n.get(v), s = n.get(T);
1105
1092
  return F(
1106
1093
  at,
1107
1094
  e,
1108
- n,
1095
+ s,
1109
1096
  t
1110
1097
  );
1111
1098
  }
1112
- }, ct = "doc.command.set-inline-format-text-background-color", Ge = {
1099
+ }, ct = "doc.command.set-inline-format-font-family", ze = {
1113
1100
  id: ct,
1114
- type: v.COMMAND,
1115
- handler: async (o, e) => {
1116
- const t = o.get(I), n = o.get(T);
1101
+ type: _.COMMAND,
1102
+ handler: async (n, e) => {
1103
+ const t = n.get(v), s = n.get(T);
1117
1104
  return F(
1118
1105
  ct,
1119
1106
  e,
1120
- n,
1107
+ s,
1121
1108
  t
1122
1109
  );
1123
1110
  }
1124
- }, lt = "doc.command.reset-inline-format-text-background-color", je = {
1111
+ }, lt = "doc.command.set-inline-format-text-color", Ge = {
1125
1112
  id: lt,
1126
- type: v.COMMAND,
1127
- handler: async (o, e) => {
1128
- const t = o.get(I), n = o.get(T);
1113
+ type: _.COMMAND,
1114
+ handler: async (n, e) => {
1115
+ const t = n.get(v), s = n.get(T);
1129
1116
  return F(
1130
1117
  lt,
1131
1118
  e,
1132
- n,
1119
+ s,
1120
+ t
1121
+ );
1122
+ }
1123
+ }, dt = "doc.command.set-inline-format-text-background-color", Xe = {
1124
+ id: dt,
1125
+ type: _.COMMAND,
1126
+ handler: async (n, e) => {
1127
+ const t = n.get(v), s = n.get(T);
1128
+ return F(
1129
+ dt,
1130
+ e,
1131
+ s,
1132
+ t
1133
+ );
1134
+ }
1135
+ }, ut = "doc.command.reset-inline-format-text-background-color", He = {
1136
+ id: ut,
1137
+ type: _.COMMAND,
1138
+ handler: async (n, e) => {
1139
+ const t = n.get(v), s = n.get(T);
1140
+ return F(
1141
+ ut,
1142
+ e,
1143
+ s,
1133
1144
  t
1134
1145
  );
1135
1146
  }
1136
1147
  }, vt = {
1137
- [we.id]: "bl",
1148
+ [ke.id]: "bl",
1138
1149
  [Le.id]: "it",
1139
1150
  [Be.id]: "ul",
1140
1151
  [Fe.id]: "st",
1141
1152
  [Ve.id]: "fs",
1142
- [ke.id]: "ff",
1143
- [ze.id]: "cl",
1144
- [Ge.id]: "bg",
1145
- [je.id]: "bg",
1153
+ [ze.id]: "ff",
1154
+ [Ge.id]: "cl",
1155
+ [Xe.id]: "bg",
1156
+ [He.id]: "bg",
1146
1157
  [oe.id]: "va",
1147
1158
  [$e.id]: "va"
1148
- }, It = {
1159
+ }, Mt = {
1149
1160
  id: "doc.command.set-inline-format",
1150
- type: v.COMMAND,
1151
- handler: async (o, e) => {
1152
- const { segmentId: t, value: n, preCommandId: s } = e, r = o.get(I), i = o.get(T), a = o.get(E), c = i.getSelections();
1161
+ type: _.COMMAND,
1162
+ // eslint-disable-next-line max-lines-per-function
1163
+ handler: async (n, e) => {
1164
+ const { segmentId: t, value: s, preCommandId: i } = e, o = n.get(v), r = n.get(T), a = n.get(E), c = r.getSelections();
1153
1165
  if (!Array.isArray(c) || c.length === 0)
1154
1166
  return !1;
1155
- let d = a.getCurrentUniverDocInstance();
1167
+ const d = a.getCurrentUniverDocInstance();
1156
1168
  if (!d)
1157
1169
  return !1;
1158
- let l = d.getUnitId();
1159
- l === Dt && (d = a.getUniverDocInstance(ut), l = d.getUnitId());
1170
+ const l = d.getUnitId();
1160
1171
  let u;
1161
- switch (s) {
1162
- case we.id:
1172
+ switch (i) {
1173
+ case ke.id:
1163
1174
  case Le.id:
1164
1175
  case Be.id:
1165
1176
  case Fe.id:
1166
1177
  case oe.id:
1167
1178
  case $e.id: {
1168
- u = mn(
1179
+ u = rn(
1169
1180
  d.getBody().textRuns,
1170
- s,
1181
+ i,
1171
1182
  c
1172
1183
  );
1173
1184
  break;
1174
1185
  }
1175
1186
  case Ve.id:
1176
- case ke.id: {
1177
- u = n;
1187
+ case ze.id: {
1188
+ u = s;
1178
1189
  break;
1179
1190
  }
1180
- case ze.id:
1181
- case Ge.id: {
1191
+ case Ge.id:
1192
+ case Xe.id: {
1182
1193
  u = {
1183
- rgb: n
1194
+ rgb: s
1184
1195
  };
1185
1196
  break;
1186
1197
  }
1187
- case je.id: {
1198
+ case He.id: {
1188
1199
  u = {
1189
1200
  rgb: null
1190
1201
  };
1191
1202
  break;
1192
1203
  }
1193
1204
  default:
1194
- throw new Error(`Unknown command: ${s} in handleInlineFormat`);
1205
+ throw new Error(`Unknown command: ${i} in handleInlineFormat`);
1195
1206
  }
1196
- const m = {
1207
+ const g = {
1197
1208
  id: L.id,
1198
1209
  params: {
1199
1210
  unitId: l,
1200
1211
  actions: [],
1201
- textRanges: c.map(Z)
1212
+ textRanges: c.map(J)
1202
1213
  }
1203
- }, g = new b(), p = new se();
1204
- p.reset();
1205
- for (const f of c) {
1206
- const { startOffset: S, endOffset: _ } = f, R = {
1214
+ }, m = new B(), S = U.getInstance(), h = new ie();
1215
+ h.reset();
1216
+ for (const I of c) {
1217
+ const { startOffset: p, endOffset: R } = I, C = {
1207
1218
  dataStream: "",
1208
1219
  textRuns: [
1209
1220
  {
1210
1221
  st: 0,
1211
- ed: _ - S,
1222
+ ed: R - p,
1212
1223
  ts: {
1213
- [vt[s]]: u
1224
+ [vt[i]]: u
1214
1225
  }
1215
1226
  }
1216
1227
  ]
1217
- }, M = S - p.cursor;
1218
- M !== 0 && g.push({
1228
+ }, M = p - h.cursor;
1229
+ M !== 0 && m.push({
1219
1230
  t: x.RETAIN,
1220
1231
  len: M,
1221
1232
  segmentId: t
1222
- }), g.push({
1233
+ }), m.push({
1223
1234
  t: x.RETAIN,
1224
- body: R,
1225
- len: _ - S,
1235
+ body: C,
1236
+ len: R - p,
1226
1237
  segmentId: t
1227
- }), p.reset(), p.moveCursor(_);
1238
+ }), h.reset(), h.moveCursor(R);
1228
1239
  }
1229
- return m.params.actions = g.serialize(), !!r.syncExecuteCommand(m.id, m.params);
1240
+ return g.params.actions = S.editOp(m.serialize()), !!o.syncExecuteCommand(g.id, g.params);
1230
1241
  }
1231
1242
  };
1232
- function un(o) {
1233
- return o !== null && typeof o == "object";
1243
+ function on(n) {
1244
+ return n !== null && typeof n == "object";
1234
1245
  }
1235
- function mn(o, e, t) {
1236
- let n = 0, s = 0;
1237
- const r = vt[e];
1238
- for (; n !== o.length && s !== t.length; ) {
1239
- const { startOffset: i, endOffset: a } = t[s], { st: c, ed: d, ts: l } = o[n];
1246
+ function rn(n, e, t) {
1247
+ let s = 0, i = 0;
1248
+ const o = vt[e];
1249
+ for (; s !== n.length && i !== t.length; ) {
1250
+ const { startOffset: r, endOffset: a } = t[i], { st: c, ed: d, ts: l } = n[s];
1240
1251
  if (a <= c)
1252
+ i++;
1253
+ else if (d <= r)
1241
1254
  s++;
1242
- else if (d <= i)
1243
- n++;
1244
1255
  else {
1245
- if (/bl|it/.test(r))
1246
- return (l == null ? void 0 : l[r]) === z.TRUE ? z.FALSE : z.TRUE;
1247
- if (/ul|st/.test(r))
1248
- return un(l == null ? void 0 : l[r]) && (l == null ? void 0 : l[r]).s === z.TRUE ? {
1249
- s: z.FALSE
1256
+ if (/bl|it/.test(o))
1257
+ return (l == null ? void 0 : l[o]) === G.TRUE ? G.FALSE : G.TRUE;
1258
+ if (/ul|st/.test(o))
1259
+ return on(l == null ? void 0 : l[o]) && (l == null ? void 0 : l[o]).s === G.TRUE ? {
1260
+ s: G.FALSE
1250
1261
  } : {
1251
- s: z.TRUE
1262
+ s: G.TRUE
1252
1263
  };
1253
- if (/va/.test(r))
1254
- return e === oe.id ? (l == null ? void 0 : l[r]) === G.SUBSCRIPT ? G.NORMAL : G.SUBSCRIPT : (l == null ? void 0 : l[r]) === G.SUPERSCRIPT ? G.NORMAL : G.SUPERSCRIPT;
1255
- n++;
1264
+ if (/va/.test(o))
1265
+ return e === oe.id ? (l == null ? void 0 : l[o]) === X.SUBSCRIPT ? X.NORMAL : X.SUBSCRIPT : (l == null ? void 0 : l[o]) === X.SUPERSCRIPT ? X.NORMAL : X.SUPERSCRIPT;
1266
+ s++;
1256
1267
  }
1257
1268
  }
1258
- return /bl|it/.test(r) ? z.TRUE : /ul|st/.test(r) ? {
1259
- s: z.TRUE
1260
- } : e === oe.id ? G.SUBSCRIPT : G.SUPERSCRIPT;
1269
+ return /bl|it/.test(o) ? G.TRUE : /ul|st/.test(o) ? {
1270
+ s: G.TRUE
1271
+ } : e === oe.id ? X.SUBSCRIPT : X.SUPERSCRIPT;
1261
1272
  }
1262
- const He = {
1273
+ const je = {
1263
1274
  id: "doc.command.list-operation",
1264
- type: v.COMMAND,
1265
- handler: (o, e) => {
1266
- var O, U, w, X;
1267
- const t = o.get(T), n = o.get(E), s = o.get(I), { listType: r } = e, i = n.getCurrentUniverDocInstance();
1268
- if (!i)
1275
+ type: _.COMMAND,
1276
+ // eslint-disable-next-line max-lines-per-function
1277
+ handler: (n, e) => {
1278
+ var P, w, Y, Ye;
1279
+ const t = n.get(T), s = n.get(E), i = n.get(v), { listType: o } = e, r = s.getCurrentUniverDocInstance();
1280
+ if (!r)
1269
1281
  return !1;
1270
- const a = t.getActiveRange(), c = (O = t.getSelections()) != null ? O : [], d = (U = i.getBody()) == null ? void 0 : U.paragraphs, l = c.map(Z);
1282
+ const a = t.getActiveRange(), c = (P = t.getSelections()) != null ? P : [], d = (w = r.getBody()) == null ? void 0 : w.paragraphs, l = c.map(J);
1271
1283
  if (a == null || d == null)
1272
1284
  return !1;
1273
- const u = Mt(a, d), { segmentId: m } = a, g = i.getUnitId(), p = u.every((Y) => {
1285
+ const u = Ct(a, d), { segmentId: g } = a, m = r.getUnitId(), S = u.every((W) => {
1274
1286
  var $;
1275
- return (($ = Y.bullet) == null ? void 0 : $.listType) === r;
1287
+ return (($ = W.bullet) == null ? void 0 : $.listType) === o;
1276
1288
  });
1277
- let f = Q.generateRandomId(6);
1289
+ let f = ee.generateRandomId(6);
1278
1290
  if (u.length === 1) {
1279
- const Y = d.indexOf(u[0]), $ = d[Y - 1], k = d[Y + 1];
1280
- $ && $.bullet && $.bullet.listType === r ? f = $.bullet.listId : k && k.bullet && k.bullet.listType === r && (f = k.bullet.listId);
1291
+ const W = d.indexOf(u[0]), $ = d[W - 1], z = d[W + 1];
1292
+ $ && $.bullet && $.bullet.listType === o ? f = $.bullet.listId : z && z.bullet && z.bullet.listType === o && (f = z.bullet.listId);
1281
1293
  }
1282
- const S = {
1294
+ const I = {
1283
1295
  id: L.id,
1284
1296
  params: {
1285
- unitId: g,
1297
+ unitId: m,
1286
1298
  actions: [],
1287
1299
  textRanges: l
1288
1300
  }
1289
- }, _ = new se();
1290
- _.reset();
1291
- const R = new b(), M = (w = i.getSnapshot().lists) != null ? w : {}, C = {
1292
- ...At,
1301
+ }, p = new ie();
1302
+ p.reset();
1303
+ const R = new B(), C = U.getInstance(), M = (Y = r.getSnapshot().lists) != null ? Y : {}, N = {
1304
+ ...Dt,
1293
1305
  ...M
1294
- }, { charSpace: D, defaultTabStop: A = 36, gridType: P } = i.getSnapshot().documentStyle;
1295
- for (const Y of u) {
1296
- const { startIndex: $, paragraphStyle: k = {} } = Y, { indentFirstLine: Rt = 0, snapToGrid: xt, indentStart: _e = 0 } = k, { hanging: ve, indentStart: Xe } = C[r].nestingLevel[0], Ie = $t(D, A, P, xt);
1306
+ }, { charSpace: A, defaultTabStop: D = 36, gridType: k } = r.getSnapshot().documentStyle;
1307
+ for (const W of u) {
1308
+ const { startIndex: $, paragraphStyle: z = {} } = W, { indentFirstLine: xt = 0, snapToGrid: yt, indentStart: _e = 0 } = z, { hanging: ve, indentStart: We } = N[o].nestingLevel[0], Me = $t(A, D, k, yt);
1297
1309
  R.push({
1298
1310
  t: x.RETAIN,
1299
- len: $ - _.cursor,
1300
- segmentId: m
1311
+ len: $ - p.cursor,
1312
+ segmentId: g
1301
1313
  }), R.push({
1302
1314
  t: x.RETAIN,
1303
1315
  len: 1,
1304
1316
  body: {
1305
1317
  dataStream: "",
1306
1318
  paragraphs: [
1307
- p ? {
1319
+ S ? {
1308
1320
  paragraphStyle: {
1309
- ...k,
1321
+ ...z,
1310
1322
  hanging: void 0,
1311
- indentStart: _e ? Math.max(0, Me(_e, Ie) + ve - Xe) : void 0
1323
+ indentStart: _e ? Math.max(0, Ce(_e, Me) + ve - We) : void 0
1312
1324
  },
1313
1325
  startIndex: 0
1314
1326
  } : {
1315
1327
  startIndex: 0,
1316
1328
  paragraphStyle: {
1317
- ...k,
1329
+ ...z,
1318
1330
  indentFirstLine: void 0,
1319
1331
  hanging: ve,
1320
- indentStart: Xe - ve + Me(Rt, Ie) + Me(_e, Ie)
1332
+ indentStart: We - ve + Ce(xt, Me) + Ce(_e, Me)
1321
1333
  },
1322
1334
  bullet: {
1323
- ...(X = Y.bullet) != null ? X : {
1335
+ ...(Ye = W.bullet) != null ? Ye : {
1324
1336
  nestingLevel: 0,
1325
1337
  textStyle: {
1326
1338
  fs: 20
1327
1339
  }
1328
1340
  },
1329
- listType: r,
1341
+ listType: o,
1330
1342
  listId: f
1331
1343
  }
1332
1344
  }
1333
1345
  ]
1334
1346
  },
1335
- segmentId: m,
1336
- coverType: Ee.REPLACE
1337
- }), _.moveCursorTo($ + 1);
1347
+ segmentId: g,
1348
+ coverType: Ae.REPLACE
1349
+ }), p.moveCursorTo($ + 1);
1338
1350
  }
1339
- return S.params.actions = R.serialize(), !!s.syncExecuteCommand(S.id, S.params);
1351
+ return I.params.actions = C.editOp(R.serialize()), !!i.syncExecuteCommand(I.id, I.params);
1340
1352
  }
1341
- }, gn = {
1353
+ }, an = {
1342
1354
  id: "doc.command.bullet-list",
1343
- type: v.COMMAND,
1344
- handler: (o) => o.get(I).syncExecuteCommand(He.id, {
1355
+ type: _.COMMAND,
1356
+ handler: (n) => n.get(v).syncExecuteCommand(je.id, {
1345
1357
  listType: mt.BULLET_LIST
1346
1358
  })
1347
- }, fn = {
1359
+ }, cn = {
1348
1360
  id: "doc.command.order-list",
1349
- type: v.COMMAND,
1350
- handler: (o) => o.get(I).syncExecuteCommand(He.id, {
1361
+ type: _.COMMAND,
1362
+ handler: (n) => n.get(v).syncExecuteCommand(je.id, {
1351
1363
  listType: mt.ORDER_LIST
1352
1364
  })
1353
1365
  };
1354
- function Mt(o, e) {
1355
- const { startOffset: t, endOffset: n } = o, s = [];
1356
- let r = -1;
1357
- for (const i of e) {
1358
- const { startIndex: a } = i;
1359
- (t > r && t <= a || n > r && n <= a || a >= t && a <= n) && s.push(i), r = a;
1366
+ function Ct(n, e) {
1367
+ const { startOffset: t, endOffset: s } = n, i = [];
1368
+ let o = -1;
1369
+ for (const r of e) {
1370
+ const { startIndex: a } = r;
1371
+ (t > o && t <= a || s > o && s <= a || a >= t && a <= s) && i.push(r), o = a;
1360
1372
  }
1361
- return s;
1373
+ return i;
1362
1374
  }
1363
- const ie = {
1375
+ const ae = {
1364
1376
  id: "doc.command.align-operation",
1365
- type: v.COMMAND,
1366
- handler: (o, e) => {
1367
- var R, M;
1368
- const t = o.get(T), n = o.get(E), s = o.get(I), { alignType: r } = e, i = n.getCurrentUniverDocInstance();
1369
- if (!i)
1377
+ type: _.COMMAND,
1378
+ // eslint-disable-next-line max-lines-per-function
1379
+ handler: (n, e) => {
1380
+ var C, M;
1381
+ const t = n.get(T), s = n.get(E), i = n.get(v), { alignType: o } = e, r = s.getCurrentUniverDocInstance();
1382
+ if (!r)
1370
1383
  return !1;
1371
- const a = t.getActiveRange(), c = (R = t.getSelections()) != null ? R : [], d = (M = i.getBody()) == null ? void 0 : M.paragraphs, l = c.map(Z);
1384
+ const a = t.getActiveRange(), c = (C = t.getSelections()) != null ? C : [], d = (M = r.getBody()) == null ? void 0 : M.paragraphs, l = c.map(J);
1372
1385
  if (a == null || d == null)
1373
1386
  return !1;
1374
- const u = Mt(a, d), { segmentId: m } = a, g = i.getUnitId(), p = u.every((C) => {
1375
- var D;
1376
- return ((D = C.paragraphStyle) == null ? void 0 : D.horizontalAlign) === r;
1387
+ const u = Ct(a, d), { segmentId: g } = a, m = r.getUnitId(), S = u.every((N) => {
1388
+ var A;
1389
+ return ((A = N.paragraphStyle) == null ? void 0 : A.horizontalAlign) === o;
1377
1390
  }), h = {
1378
1391
  id: L.id,
1379
1392
  params: {
1380
- unitId: g,
1393
+ unitId: m,
1381
1394
  actions: [],
1382
1395
  textRanges: l
1383
1396
  }
1384
- }, f = new se();
1397
+ }, f = new ie();
1385
1398
  f.reset();
1386
- const S = new b();
1387
- for (const C of u) {
1388
- const { startIndex: D } = C;
1389
- S.push({
1399
+ const I = new B(), p = U.getInstance();
1400
+ for (const N of u) {
1401
+ const { startIndex: A } = N;
1402
+ I.push({
1390
1403
  t: x.RETAIN,
1391
- len: D - f.cursor,
1392
- segmentId: m
1404
+ len: A - f.cursor,
1405
+ segmentId: g
1393
1406
  });
1394
- const A = {
1395
- ...C.paragraphStyle,
1396
- horizontalAlign: p ? re.UNSPECIFIED : r
1407
+ const D = {
1408
+ ...N.paragraphStyle,
1409
+ horizontalAlign: S ? re.UNSPECIFIED : o
1397
1410
  };
1398
- S.push({
1411
+ I.push({
1399
1412
  t: x.RETAIN,
1400
1413
  len: 1,
1401
1414
  body: {
1402
1415
  dataStream: "",
1403
1416
  paragraphs: [
1404
1417
  {
1405
- ...C,
1406
- paragraphStyle: A,
1418
+ ...N,
1419
+ paragraphStyle: D,
1407
1420
  startIndex: 0
1408
1421
  }
1409
1422
  ]
1410
1423
  },
1411
- segmentId: m,
1412
- coverType: Ee.REPLACE
1413
- }), f.moveCursorTo(D + 1);
1424
+ segmentId: g,
1425
+ coverType: Ae.REPLACE
1426
+ }), f.moveCursorTo(A + 1);
1414
1427
  }
1415
- return h.params.actions = S.serialize(), !!s.syncExecuteCommand(h.id, h.params);
1428
+ return h.params.actions = p.editOp(I.serialize()), !!i.syncExecuteCommand(h.id, h.params);
1416
1429
  }
1417
- }, hn = {
1430
+ }, ln = {
1418
1431
  id: "doc.command.align-left",
1419
- type: v.COMMAND,
1420
- handler: (o) => o.get(I).syncExecuteCommand(ie.id, {
1432
+ type: _.COMMAND,
1433
+ handler: (n) => n.get(v).syncExecuteCommand(ae.id, {
1421
1434
  alignType: re.LEFT
1422
1435
  })
1423
- }, pn = {
1436
+ }, dn = {
1424
1437
  id: "doc.command.align-center",
1425
- type: v.COMMAND,
1426
- handler: (o) => o.get(I).syncExecuteCommand(ie.id, {
1438
+ type: _.COMMAND,
1439
+ handler: (n) => n.get(v).syncExecuteCommand(ae.id, {
1427
1440
  alignType: re.CENTER
1428
1441
  })
1429
- }, Sn = {
1442
+ }, un = {
1430
1443
  id: "doc.command.align-right",
1431
- type: v.COMMAND,
1432
- handler: (o) => o.get(I).syncExecuteCommand(ie.id, {
1444
+ type: _.COMMAND,
1445
+ handler: (n) => n.get(v).syncExecuteCommand(ae.id, {
1433
1446
  alignType: re.RIGHT
1434
1447
  })
1435
- }, _n = {
1448
+ }, gn = {
1436
1449
  id: "doc.command.align-justify",
1437
- type: v.COMMAND,
1438
- handler: (o) => o.get(I).syncExecuteCommand(ie.id, {
1450
+ type: _.COMMAND,
1451
+ handler: (n) => n.get(v).syncExecuteCommand(ae.id, {
1439
1452
  alignType: re.JUSTIFIED
1440
1453
  })
1441
- }, vn = {
1454
+ }, mn = {
1442
1455
  id: "doc.command-replace-content",
1443
- type: v.COMMAND,
1444
- handler: async (o, e) => {
1445
- var g;
1446
- const { unitId: t, body: n, textRanges: s, segmentId: r = "" } = e, i = o.get(E), a = o.get(I), c = o.get(T), d = (g = i.getUniverDocInstance(t)) == null ? void 0 : g.getSnapshot().body, l = c.getSelections();
1456
+ type: _.COMMAND,
1457
+ handler: async (n, e) => {
1458
+ var m;
1459
+ const { unitId: t, body: s, textRanges: i, segmentId: o = "" } = e, r = n.get(E), a = n.get(v), c = n.get(T), d = (m = r.getUniverDocInstance(t)) == null ? void 0 : m.getSnapshot().body, l = c.getSelections();
1447
1460
  if (d == null || !Array.isArray(l) || l.length === 0)
1448
1461
  return !1;
1449
- const u = Ct(t, r, d, n);
1450
- return u.params.textRanges = s, !!a.syncExecuteCommand(u.id, u.params);
1462
+ const u = Rt(t, o, d, s);
1463
+ return u.params.textRanges = i, !!a.syncExecuteCommand(u.id, u.params);
1451
1464
  }
1452
- }, In = {
1465
+ }, hn = {
1453
1466
  id: "doc.command-cover-content",
1454
- type: v.COMMAND,
1455
- handler: async (o, e) => {
1467
+ type: _.COMMAND,
1468
+ handler: async (n, e) => {
1456
1469
  var l;
1457
- const { unitId: t, body: n, segmentId: s = "" } = e, r = o.get(E), i = o.get(I), a = o.get(Te), c = (l = r.getUniverDocInstance(t)) == null ? void 0 : l.getSnapshot().body;
1470
+ const { unitId: t, body: s, segmentId: i = "" } = e, o = n.get(E), r = n.get(v), a = n.get(Ee), c = (l = o.getUniverDocInstance(t)) == null ? void 0 : l.getSnapshot().body;
1458
1471
  if (c == null)
1459
1472
  return !1;
1460
- const d = Ct(t, s, c, n);
1461
- return d.params.noNeedSetTextRange = !0, d.params.noHistory = !0, i.syncExecuteCommand(
1473
+ const d = Rt(t, i, c, s);
1474
+ return d.params.noNeedSetTextRange = !0, d.params.noHistory = !0, r.syncExecuteCommand(
1462
1475
  d.id,
1463
1476
  d.params
1464
1477
  ), a.clearUndoRedo(t), !0;
1465
1478
  }
1466
1479
  };
1467
- function Ct(o, e, t, n) {
1468
- const s = {
1480
+ function Rt(n, e, t, s) {
1481
+ const i = {
1469
1482
  id: L.id,
1470
1483
  params: {
1471
- unitId: o,
1484
+ unitId: n,
1472
1485
  actions: [],
1473
1486
  textRanges: []
1474
1487
  }
1475
- }, r = new b(), i = (t == null ? void 0 : t.dataStream.length) - 2;
1476
- return i > 0 && r.push({
1488
+ }, o = new B(), r = U.getInstance(), a = (t == null ? void 0 : t.dataStream.length) - 2;
1489
+ return a > 0 && o.push({
1477
1490
  t: x.DELETE,
1478
- len: i,
1491
+ len: a,
1479
1492
  line: 0,
1480
1493
  segmentId: e
1481
- }), n.dataStream.length > 0 && r.push({
1494
+ }), s.dataStream.length > 0 && o.push({
1482
1495
  t: x.INSERT,
1483
- body: n,
1484
- len: n.dataStream.length,
1496
+ body: s,
1497
+ len: s.dataStream.length,
1485
1498
  line: 0,
1486
1499
  segmentId: e
1487
- }), s.params.actions = r.serialize(), s;
1500
+ }), i.params.actions = r.editOp(o.serialize()), i;
1488
1501
  }
1489
- const ye = {
1502
+ const Oe = {
1490
1503
  id: "doc.operation.move-cursor",
1491
- type: v.OPERATION,
1492
- handler: (o, e) => !!e
1493
- }, Oe = {
1504
+ type: _.OPERATION,
1505
+ handler: (n, e) => !!e
1506
+ }, Te = {
1494
1507
  id: "doc.operation.move-selection",
1495
- type: v.OPERATION,
1496
- handler: (o, e) => !!e
1497
- }, Mn = (o, e) => {
1498
- const t = o.get(E).getUniverDocInstance(e.unitId), n = (t == null ? void 0 : t.zoomRatio) || 1;
1508
+ type: _.OPERATION,
1509
+ handler: (n, e) => !!e
1510
+ }, fn = (n, e) => {
1511
+ const t = n.get(E).getUniverDocInstance(e.unitId), s = (t == null ? void 0 : t.zoomRatio) || 1;
1499
1512
  return {
1500
- ...Q.deepClone(e),
1501
- zoomRatio: n
1513
+ ...ee.deepClone(e),
1514
+ zoomRatio: s
1502
1515
  };
1503
- }, ce = {
1516
+ }, le = {
1504
1517
  id: "doc.operation.set-zoom-ratio",
1505
- type: v.OPERATION,
1506
- handler: (o, e) => {
1507
- const t = o.get(E).getUniverDocInstance(e.unitId);
1518
+ type: _.OPERATION,
1519
+ handler: (n, e) => {
1520
+ const t = n.get(E).getUniverDocInstance(e.unitId);
1508
1521
  if (!t)
1509
1522
  return !1;
1510
- const n = t.getSnapshot();
1511
- return n.settings == null ? n.settings = {
1523
+ const s = t.getSnapshot();
1524
+ return s.settings == null ? s.settings = {
1512
1525
  zoomRatio: e.zoomRatio
1513
- } : n.settings.zoomRatio = e.zoomRatio, !0;
1526
+ } : s.settings.zoomRatio = e.zoomRatio, !0;
1514
1527
  }
1515
- }, Cn = {
1516
- type: v.COMMAND,
1528
+ }, pn = {
1529
+ type: _.COMMAND,
1517
1530
  id: "doc.command.set-zoom-ratio",
1518
- handler: async (o, e) => {
1519
- var u, m, g;
1520
- const t = o.get(I), n = o.get(Te), s = o.get(E);
1521
- let r = (u = s.getCurrentUniverDocInstance()) == null ? void 0 : u.getUnitId();
1522
- if (!r)
1531
+ handler: async (n, e) => {
1532
+ var u, g, m;
1533
+ const t = n.get(v), s = n.get(Ee), i = n.get(E);
1534
+ let o = (u = i.getCurrentUniverDocInstance()) == null ? void 0 : u.getUnitId();
1535
+ if (!o)
1523
1536
  return !1;
1524
- let i = 1;
1525
- if (e && (r = (m = e.documentId) != null ? m : r, i = (g = e.zoomRatio) != null ? g : i), !s.getUniverDocInstance(r))
1537
+ let r = 1;
1538
+ if (e && (o = (g = e.documentId) != null ? g : o, r = (m = e.zoomRatio) != null ? m : r), !i.getUniverDocInstance(o))
1526
1539
  return !1;
1527
1540
  const c = {
1528
- zoomRatio: i,
1529
- unitId: r
1530
- }, d = Mn(o, c);
1531
- return t.syncExecuteCommand(ce.id, c) ? (n.pushUndoRedo({
1532
- unitID: r,
1533
- undoMutations: [{ id: ce.id, params: d }],
1534
- redoMutations: [{ id: ce.id, params: c }]
1541
+ zoomRatio: r,
1542
+ unitId: o
1543
+ }, d = fn(n, c);
1544
+ return t.syncExecuteCommand(le.id, c) ? (s.pushUndoRedo({
1545
+ unitID: o,
1546
+ undoMutations: [{ id: le.id, params: d }],
1547
+ redoMutations: [{ id: le.id, params: c }]
1535
1548
  }), !0) : !1;
1536
1549
  }
1537
- }, Rn = {
1550
+ }, Sn = {
1538
1551
  id: "doc.operation.select-all",
1539
- type: v.COMMAND,
1540
- handler: async (o) => {
1541
- const e = o.get(E), t = o.get(T), n = e.getCurrentUniverDocInstance();
1542
- if (!n)
1552
+ type: _.COMMAND,
1553
+ handler: async (n) => {
1554
+ const e = n.get(E), t = n.get(T), s = e.getCurrentUniverDocInstance();
1555
+ if (!s)
1543
1556
  return !1;
1544
- const s = n.getSnapshot().body;
1545
- if (s == null)
1557
+ const i = s.getSnapshot().body;
1558
+ if (i == null)
1546
1559
  return !1;
1547
- const r = [
1560
+ const o = [
1548
1561
  {
1549
1562
  startOffset: 0,
1550
- endOffset: s.dataStream.length - 2
1563
+ endOffset: i.dataStream.length - 2
1551
1564
  }
1552
1565
  ];
1553
- return t.replaceTextRanges(r, !1), !0;
1566
+ return t.replaceTextRanges(o, !1), !0;
1554
1567
  }
1555
1568
  };
1556
- var xn = Object.defineProperty, yn = Object.getOwnPropertyDescriptor, On = (o, e, t, n) => {
1557
- for (var s = n > 1 ? void 0 : n ? yn(e, t) : e, r = o.length - 1, i; r >= 0; r--)
1558
- (i = o[r]) && (s = (n ? i(e, t, s) : i(s)) || s);
1559
- return n && s && xn(e, t, s), s;
1560
- }, K = (o, e) => (t, n) => e(t, n, o);
1561
- let le = class extends Ne {
1562
- constructor(e, t, n, s, r) {
1569
+ var In = (n, e, t, s) => {
1570
+ for (var i = e, o = n.length - 1, r; o >= 0; o--)
1571
+ (r = n[o]) && (i = r(i) || i);
1572
+ return i;
1573
+ }, K = (n, e) => (t, s) => e(t, s, n);
1574
+ let de = class extends be {
1575
+ constructor(e, t, s, i, o) {
1563
1576
  super();
1564
1577
  y(this, "_previousIMEContent", "");
1565
1578
  y(this, "_isCompositionStart", !0);
1566
1579
  y(this, "_onStartSubscription");
1567
1580
  y(this, "_onUpdateSubscription");
1568
1581
  y(this, "_onEndSubscription");
1569
- this._docSkeletonManagerService = e, this._univerInstanceService = t, this._textSelectionRenderManager = n, this._imeInputManagerService = s, this._commandService = r, this._initialize();
1582
+ this._docSkeletonManagerService = e, this._univerInstanceService = t, this._textSelectionRenderManager = s, this._imeInputManagerService = i, this._commandService = o, this._initialize();
1570
1583
  }
1571
1584
  dispose() {
1572
- var e, t, n;
1573
- (e = this._onStartSubscription) == null || e.unsubscribe(), (t = this._onUpdateSubscription) == null || t.unsubscribe(), (n = this._onEndSubscription) == null || n.unsubscribe();
1585
+ var e, t, s;
1586
+ (e = this._onStartSubscription) == null || e.unsubscribe(), (t = this._onUpdateSubscription) == null || t.unsubscribe(), (s = this._onEndSubscription) == null || s.unsubscribe();
1574
1587
  }
1575
1588
  _initialize() {
1576
1589
  this._initialOnCompositionstart(), this._initialOnCompositionUpdate(), this._initialOnCompositionend();
@@ -1581,7 +1594,7 @@ let le = class extends Ne {
1581
1594
  return;
1582
1595
  this._resetIME();
1583
1596
  const { activeRange: t } = e;
1584
- t != null && this._imeInputManagerService.setActiveRange(Q.deepClone(t));
1597
+ t != null && this._imeInputManagerService.setActiveRange(ee.deepClone(t));
1585
1598
  });
1586
1599
  }
1587
1600
  _initialOnCompositionUpdate() {
@@ -1596,18 +1609,18 @@ let le = class extends Ne {
1596
1609
  }
1597
1610
  async _updateContent(e, t) {
1598
1611
  var d;
1599
- const n = (d = this._docSkeletonManagerService.getCurrent()) == null ? void 0 : d.skeleton;
1600
- if (e == null || n == null)
1612
+ const s = (d = this._docSkeletonManagerService.getCurrent()) == null ? void 0 : d.skeleton;
1613
+ if (e == null || s == null)
1601
1614
  return;
1602
- const s = this._univerInstanceService.getCurrentUniverDocInstance();
1603
- if (!s)
1615
+ const i = this._univerInstanceService.getCurrentUniverDocInstance();
1616
+ if (!i)
1604
1617
  return;
1605
- const { event: r, activeRange: i } = e;
1606
- if (n == null || i == null)
1618
+ const { event: o, activeRange: r } = e;
1619
+ if (s == null || r == null)
1607
1620
  return;
1608
- const c = r.data;
1621
+ const c = o.data;
1609
1622
  c === this._previousIMEContent && t || (await this._commandService.executeCommand(_t.id, {
1610
- unitId: s.getUnitId(),
1623
+ unitId: i.getUnitId(),
1611
1624
  newText: c,
1612
1625
  oldTextLen: this._previousIMEContent.length,
1613
1626
  isCompositionStart: this._isCompositionStart,
@@ -1618,41 +1631,41 @@ let le = class extends Ne {
1618
1631
  this._previousIMEContent = "", this._isCompositionStart = !0, this._imeInputManagerService.clearUndoRedoMutationParamsCache(), this._imeInputManagerService.setActiveRange(null);
1619
1632
  }
1620
1633
  };
1621
- le = On([
1622
- De(Ae.Rendered, le),
1623
- K(0, V(H)),
1634
+ de = In([
1635
+ Ne(De.Rendered, de),
1636
+ K(0, V(j)),
1624
1637
  K(1, E),
1625
1638
  K(2, fe),
1626
- K(3, V(he)),
1627
- K(4, I)
1628
- ], le);
1629
- var Tn = Object.defineProperty, En = Object.getOwnPropertyDescriptor, Dn = (o, e, t, n) => {
1630
- for (var s = n > 1 ? void 0 : n ? En(e, t) : e, r = o.length - 1, i; r >= 0; r--)
1631
- (i = o[r]) && (s = (n ? i(e, t, s) : i(s)) || s);
1632
- return n && s && Tn(e, t, s), s;
1633
- }, J = (o, e) => (t, n) => e(t, n, o);
1634
- let de = class extends Ne {
1635
- constructor(e, t, n, s, r) {
1639
+ K(3, V(pe)),
1640
+ K(4, v)
1641
+ ], de);
1642
+ var _n = (n, e, t, s) => {
1643
+ for (var i = e, o = n.length - 1, r; o >= 0; o--)
1644
+ (r = n[o]) && (i = r(i) || i);
1645
+ return i;
1646
+ }, q = (n, e) => (t, s) => e(t, s, n);
1647
+ let ue = class extends be {
1648
+ constructor(e, t, s, i, o) {
1636
1649
  super();
1637
1650
  y(this, "_onInputSubscription");
1638
- this._docSkeletonManagerService = e, this._univerInstanceService = t, this._renderManagerService = n, this._textSelectionManagerService = s, this._commandService = r, this._commandExecutedListener();
1651
+ this._docSkeletonManagerService = e, this._univerInstanceService = t, this._renderManagerService = s, this._textSelectionManagerService = i, this._commandService = o, this._commandExecutedListener();
1639
1652
  }
1640
1653
  dispose() {
1641
1654
  var e;
1642
1655
  super.dispose(), (e = this._onInputSubscription) == null || e.unsubscribe();
1643
1656
  }
1644
1657
  _commandExecutedListener() {
1645
- const e = [ye.id, Oe.id];
1658
+ const e = [Oe.id, Te.id];
1646
1659
  this.disposeWithMe(
1647
1660
  this._commandService.onCommandExecuted((t) => {
1648
1661
  if (!e.includes(t.id))
1649
1662
  return;
1650
- const n = t.params;
1663
+ const s = t.params;
1651
1664
  switch (t.id) {
1652
- case ye.id:
1653
- return this._handleMoveCursor(n.direction);
1654
1665
  case Oe.id:
1655
- return this._handleShiftMoveSelection(n.direction);
1666
+ return this._handleMoveCursor(s.direction);
1667
+ case Te.id:
1668
+ return this._handleShiftMoveSelection(s.direction);
1656
1669
  default:
1657
1670
  throw new Error("Unknown command");
1658
1671
  }
@@ -1660,86 +1673,86 @@ let de = class extends Ne {
1660
1673
  );
1661
1674
  }
1662
1675
  _handleShiftMoveSelection(e) {
1663
- var h, f, S;
1664
- const t = this._textSelectionManagerService.getActiveRange(), n = this._textSelectionManagerService.getSelections(), s = this._univerInstanceService.getCurrentUniverDocInstance();
1665
- if (!s)
1676
+ var h, f, I;
1677
+ const t = this._textSelectionManagerService.getActiveRange(), s = this._textSelectionManagerService.getSelections(), i = this._univerInstanceService.getCurrentUniverDocInstance();
1678
+ if (!i)
1666
1679
  return;
1667
- const r = (h = this._docSkeletonManagerService.getCurrent()) == null ? void 0 : h.skeleton, i = this._getDocObject();
1668
- if (t == null || r == null || i == null)
1680
+ const o = (h = this._docSkeletonManagerService.getCurrent()) == null ? void 0 : h.skeleton, r = this._getDocObject();
1681
+ if (t == null || o == null || r == null)
1669
1682
  return;
1670
1683
  const { startOffset: a, endOffset: c, style: d, collapsed: l, direction: u } = t;
1671
- if (n.length > 1) {
1672
- let _ = Number.POSITIVE_INFINITY, R = Number.NEGATIVE_INFINITY;
1673
- for (const M of n)
1674
- _ = Math.min(_, M.startOffset), R = Math.max(R, M.endOffset);
1684
+ if (s.length > 1) {
1685
+ let p = Number.POSITIVE_INFINITY, R = Number.NEGATIVE_INFINITY;
1686
+ for (const C of s)
1687
+ p = Math.min(p, C.startOffset), R = Math.max(R, C.endOffset);
1675
1688
  this._textSelectionManagerService.replaceTextRanges([
1676
1689
  {
1677
- startOffset: e === N.LEFT || e === N.UP ? R : _,
1678
- endOffset: e === N.LEFT || e === N.UP ? _ : R,
1690
+ startOffset: e === b.LEFT || e === b.UP ? R : p,
1691
+ endOffset: e === b.LEFT || e === b.UP ? p : R,
1679
1692
  style: d
1680
1693
  }
1681
1694
  ], !1);
1682
1695
  return;
1683
1696
  }
1684
- const m = l || u === Ze.FORWARD ? a : c;
1685
- let g = l || u === Ze.FORWARD ? c : a;
1686
- const p = (f = s.getBody().dataStream.length) != null ? f : Number.POSITIVE_INFINITY;
1687
- if (e === N.LEFT || e === N.RIGHT) {
1688
- const _ = r.findNodeByCharIndex(g - 1), R = r.findNodeByCharIndex(g);
1689
- g = e === N.RIGHT ? g + R.count : g - ((S = _ == null ? void 0 : _.count) != null ? S : 0), g = Math.min(p - 2, Math.max(0, g)), this._textSelectionManagerService.replaceTextRanges([
1697
+ const g = l || u === Ke.FORWARD ? a : c;
1698
+ let m = l || u === Ke.FORWARD ? c : a;
1699
+ const S = (f = i.getBody().dataStream.length) != null ? f : Number.POSITIVE_INFINITY;
1700
+ if (e === b.LEFT || e === b.RIGHT) {
1701
+ const p = o.findNodeByCharIndex(m - 1), R = o.findNodeByCharIndex(m);
1702
+ m = e === b.RIGHT ? m + R.count : m - ((I = p == null ? void 0 : p.count) != null ? I : 0), m = Math.min(S - 2, Math.max(0, m)), this._textSelectionManagerService.replaceTextRanges([
1690
1703
  {
1691
- startOffset: m,
1692
- endOffset: g,
1704
+ startOffset: g,
1705
+ endOffset: m,
1693
1706
  style: d
1694
1707
  }
1695
1708
  ], !1);
1696
1709
  } else {
1697
- const _ = r.findNodeByCharIndex(g), R = i.document.getOffsetConfig(), M = this._getTopOrBottomPosition(r, _, e === N.DOWN);
1698
- if (M == null) {
1699
- const D = e === N.UP ? 0 : p - 2;
1700
- if (D === g)
1710
+ const p = o.findNodeByCharIndex(m), R = r.document.getOffsetConfig(), C = this._getTopOrBottomPosition(o, p, e === b.DOWN);
1711
+ if (C == null) {
1712
+ const N = e === b.UP ? 0 : S - 2;
1713
+ if (N === m)
1701
1714
  return;
1702
1715
  this._textSelectionManagerService.replaceTextRanges([
1703
1716
  {
1704
- startOffset: m,
1705
- endOffset: D,
1717
+ startOffset: g,
1718
+ endOffset: N,
1706
1719
  style: d
1707
1720
  }
1708
1721
  ], !1);
1709
1722
  return;
1710
1723
  }
1711
- const C = new Ke(R, r).getRangePointData(
1712
- M,
1713
- M
1724
+ const M = new qe(R, o).getRangePointData(
1725
+ C,
1726
+ C
1714
1727
  ).cursorList[0];
1715
1728
  this._textSelectionManagerService.replaceTextRanges([
1716
1729
  {
1717
- startOffset: m,
1718
- endOffset: C.endOffset,
1730
+ startOffset: g,
1731
+ endOffset: M.endOffset,
1719
1732
  style: d
1720
1733
  }
1721
1734
  ], !1);
1722
1735
  }
1723
1736
  }
1724
1737
  _handleMoveCursor(e) {
1725
- var m, g, p;
1726
- const t = this._textSelectionManagerService.getActiveRange(), n = this._textSelectionManagerService.getSelections(), s = this._univerInstanceService.getCurrentUniverDocInstance();
1727
- if (!s)
1738
+ var g, m, S;
1739
+ const t = this._textSelectionManagerService.getActiveRange(), s = this._textSelectionManagerService.getSelections(), i = this._univerInstanceService.getCurrentUniverDocInstance();
1740
+ if (!i)
1728
1741
  return !1;
1729
- const r = (m = this._docSkeletonManagerService.getCurrent()) == null ? void 0 : m.skeleton, i = this._getDocObject();
1730
- if (t == null || r == null || i == null || n == null)
1742
+ const o = (g = this._docSkeletonManagerService.getCurrent()) == null ? void 0 : g.skeleton, r = this._getDocObject();
1743
+ if (t == null || o == null || r == null || s == null)
1731
1744
  return;
1732
- const { startOffset: a, endOffset: c, style: d, collapsed: l } = t, u = (g = s.getBody().dataStream.length) != null ? g : Number.POSITIVE_INFINITY;
1733
- if (e === N.LEFT || e === N.RIGHT) {
1745
+ const { startOffset: a, endOffset: c, style: d, collapsed: l } = t, u = (m = i.getBody().dataStream.length) != null ? m : Number.POSITIVE_INFINITY;
1746
+ if (e === b.LEFT || e === b.RIGHT) {
1734
1747
  let h;
1735
- if (!t.collapsed || n.length > 1) {
1736
- let f = Number.POSITIVE_INFINITY, S = Number.NEGATIVE_INFINITY;
1737
- for (const _ of n)
1738
- f = Math.min(f, _.startOffset), S = Math.max(S, _.endOffset);
1739
- h = e === N.LEFT ? f : S;
1748
+ if (!t.collapsed || s.length > 1) {
1749
+ let f = Number.POSITIVE_INFINITY, I = Number.NEGATIVE_INFINITY;
1750
+ for (const p of s)
1751
+ f = Math.min(f, p.startOffset), I = Math.max(I, p.endOffset);
1752
+ h = e === b.LEFT ? f : I;
1740
1753
  } else {
1741
- const f = r.findNodeByCharIndex(a - 1), S = r.findNodeByCharIndex(a);
1742
- e === N.LEFT ? h = Math.max(0, a - ((p = f == null ? void 0 : f.count) != null ? p : 0)) : h = Math.min(u - 2, c + S.count);
1754
+ const f = o.findNodeByCharIndex(a - 1), I = o.findNodeByCharIndex(a);
1755
+ e === b.LEFT ? h = Math.max(0, a - ((S = f == null ? void 0 : f.count) != null ? S : 0)) : h = Math.min(u - 2, c + I.count);
1743
1756
  }
1744
1757
  this._textSelectionManagerService.replaceTextRanges([
1745
1758
  {
@@ -1749,25 +1762,25 @@ let de = class extends Ne {
1749
1762
  }
1750
1763
  ], !1);
1751
1764
  } else {
1752
- const h = r.findNodeByCharIndex(a), f = r.findNodeByCharIndex(c), S = i.document.getOffsetConfig(), _ = this._getTopOrBottomPosition(
1753
- r,
1754
- e === N.UP ? h : f,
1755
- e === N.DOWN
1765
+ const h = o.findNodeByCharIndex(a), f = o.findNodeByCharIndex(c), I = r.document.getOffsetConfig(), p = this._getTopOrBottomPosition(
1766
+ o,
1767
+ e === b.UP ? h : f,
1768
+ e === b.DOWN
1756
1769
  );
1757
- if (_ == null) {
1758
- let M;
1759
- l ? M = e === N.UP ? 0 : u - 2 : M = e === N.UP ? a : c, this._textSelectionManagerService.replaceTextRanges([
1770
+ if (p == null) {
1771
+ let C;
1772
+ l ? C = e === b.UP ? 0 : u - 2 : C = e === b.UP ? a : c, this._textSelectionManagerService.replaceTextRanges([
1760
1773
  {
1761
- startOffset: M,
1762
- endOffset: M,
1774
+ startOffset: C,
1775
+ endOffset: C,
1763
1776
  style: d
1764
1777
  }
1765
1778
  ], !1);
1766
1779
  return;
1767
1780
  }
1768
- const R = new Ke(S, r).getRangePointData(
1769
- _,
1770
- _
1781
+ const R = new qe(I, o).getRangePointData(
1782
+ p,
1783
+ p
1771
1784
  ).cursorList[0];
1772
1785
  this._textSelectionManagerService.replaceTextRanges([
1773
1786
  {
@@ -1777,62 +1790,62 @@ let de = class extends Ne {
1777
1790
  ], !1);
1778
1791
  }
1779
1792
  }
1780
- _getTopOrBottomPosition(e, t, n) {
1793
+ _getTopOrBottomPosition(e, t, s) {
1781
1794
  if (t == null)
1782
1795
  return;
1783
- const s = this._getSpanLeftOffsetInLine(t), r = this._getNextOrPrevLine(t, n);
1784
- if (r == null)
1796
+ const i = this._getSpanLeftOffsetInLine(t), o = this._getNextOrPrevLine(t, s);
1797
+ if (o == null)
1785
1798
  return;
1786
- const i = this._matchPositionByLeftOffset(e, r, s);
1787
- if (i != null)
1788
- return { ...i, isBack: !0 };
1799
+ const r = this._matchPositionByLeftOffset(e, o, i);
1800
+ if (r != null)
1801
+ return { ...r, isBack: !0 };
1789
1802
  }
1790
1803
  _getSpanLeftOffsetInLine(e) {
1791
1804
  const t = e.parent;
1792
1805
  if (t == null)
1793
1806
  return Number.NEGATIVE_INFINITY;
1794
- const n = t.left, { left: s } = e;
1795
- return n + s;
1807
+ const s = t.left, { left: i } = e;
1808
+ return s + i;
1796
1809
  }
1797
- _matchPositionByLeftOffset(e, t, n) {
1798
- const s = {
1810
+ _matchPositionByLeftOffset(e, t, s) {
1811
+ const i = {
1799
1812
  distance: Number.POSITIVE_INFINITY
1800
1813
  };
1801
- for (const r of t.divides) {
1802
- const i = r.left;
1803
- for (const a of r.glyphGroup) {
1804
- const { left: c } = a, d = i + c, l = Math.abs(n - d);
1805
- l < s.distance && (s.glyph = a, s.distance = l);
1814
+ for (const o of t.divides) {
1815
+ const r = o.left;
1816
+ for (const a of o.glyphGroup) {
1817
+ const { left: c } = a, d = r + c, l = Math.abs(s - d);
1818
+ l < i.distance && (i.glyph = a, i.distance = l);
1806
1819
  }
1807
1820
  }
1808
- if (s.glyph != null)
1809
- return e.findPositionByGlyph(s.glyph);
1821
+ if (i.glyph != null)
1822
+ return e.findPositionByGlyph(i.glyph);
1810
1823
  }
1811
1824
  _getNextOrPrevLine(e, t) {
1812
- var p, h, f, S, _, R, M, C, D, A, P, B;
1813
- const n = e.parent;
1814
- if (n == null)
1815
- return;
1816
- const s = n.parent;
1825
+ var S, h, f, I, p, R, C, M, N, A, D, k;
1826
+ const s = e.parent;
1817
1827
  if (s == null)
1818
1828
  return;
1819
- const r = s.parent;
1820
- if (r == null)
1829
+ const i = s.parent;
1830
+ if (i == null)
1821
1831
  return;
1822
- const i = r.lines.indexOf(s);
1823
- if (i === -1)
1832
+ const o = i.parent;
1833
+ if (o == null)
1834
+ return;
1835
+ const r = o.lines.indexOf(i);
1836
+ if (r === -1)
1824
1837
  return;
1825
1838
  let a;
1826
- if (t === !0 ? a = r.lines[i + 1] : a = r.lines[i - 1], a != null)
1839
+ if (t === !0 ? a = o.lines[r + 1] : a = o.lines[r - 1], a != null)
1827
1840
  return a;
1828
- const c = r.parent;
1841
+ const c = o.parent;
1829
1842
  if (c == null)
1830
1843
  return;
1831
- const d = c.columns.indexOf(r);
1844
+ const d = c.columns.indexOf(o);
1832
1845
  if (d === -1)
1833
1846
  return;
1834
1847
  if (t === !0)
1835
- a = (p = c.columns[d + 1]) == null ? void 0 : p.lines[0];
1848
+ a = (S = c.columns[d + 1]) == null ? void 0 : S.lines[0];
1836
1849
  else {
1837
1850
  const O = (f = (h = c.columns) == null ? void 0 : h[d - 1]) == null ? void 0 : f.lines;
1838
1851
  a = O == null ? void 0 : O[O.length - 1];
@@ -1846,53 +1859,53 @@ let de = class extends Ne {
1846
1859
  if (u === -1)
1847
1860
  return;
1848
1861
  if (t === !0)
1849
- a = (_ = (S = l.sections[u - 1]) == null ? void 0 : S.columns[0]) == null ? void 0 : _.lines[0];
1862
+ a = (p = (I = l.sections[u - 1]) == null ? void 0 : I.columns[0]) == null ? void 0 : p.lines[0];
1850
1863
  else {
1851
- const O = (M = (R = l.sections) == null ? void 0 : R[u - 1]) == null ? void 0 : M.columns, U = O == null ? void 0 : O[O.length - 1], w = U == null ? void 0 : U.lines;
1864
+ const O = (C = (R = l.sections) == null ? void 0 : R[u - 1]) == null ? void 0 : C.columns, P = O == null ? void 0 : O[O.length - 1], w = P == null ? void 0 : P.lines;
1852
1865
  a = w == null ? void 0 : w[w.length - 1];
1853
1866
  }
1854
1867
  if (a != null)
1855
1868
  return a;
1856
- const m = l.parent;
1857
- if (m == null)
1869
+ const g = l.parent;
1870
+ if (g == null)
1858
1871
  return;
1859
- const g = m.pages.indexOf(l);
1860
- if (g !== -1) {
1872
+ const m = g.pages.indexOf(l);
1873
+ if (m !== -1) {
1861
1874
  if (t === !0)
1862
- a = (A = (D = (C = m.pages[g + 1]) == null ? void 0 : C.sections[0]) == null ? void 0 : D.columns[0]) == null ? void 0 : A.lines[0];
1875
+ a = (A = (N = (M = g.pages[m + 1]) == null ? void 0 : M.sections[0]) == null ? void 0 : N.columns[0]) == null ? void 0 : A.lines[0];
1863
1876
  else {
1864
- const O = (P = m.pages[g - 1]) == null ? void 0 : P.sections;
1877
+ const O = (D = g.pages[m - 1]) == null ? void 0 : D.sections;
1865
1878
  if (O == null)
1866
1879
  return;
1867
- const U = (B = O[O.length - 1]) == null ? void 0 : B.columns, w = U[U.length - 1], X = w == null ? void 0 : w.lines;
1868
- a = X[X.length - 1];
1880
+ const P = (k = O[O.length - 1]) == null ? void 0 : k.columns, w = P[P.length - 1], Y = w == null ? void 0 : w.lines;
1881
+ a = Y[Y.length - 1];
1869
1882
  }
1870
1883
  if (a != null)
1871
1884
  return a;
1872
1885
  }
1873
1886
  }
1874
1887
  _getDocObject() {
1875
- return Gt(this._univerInstanceService, this._renderManagerService);
1888
+ return Xt(this._univerInstanceService, this._renderManagerService);
1876
1889
  }
1877
1890
  };
1878
- de = Dn([
1879
- De(Ae.Rendered, de),
1880
- J(0, V(H)),
1881
- J(1, E),
1882
- J(2, gt),
1883
- J(3, V(T)),
1884
- J(4, I)
1885
- ], de);
1886
- var An = Object.defineProperty, Nn = Object.getOwnPropertyDescriptor, Pn = (o, e, t, n) => {
1887
- for (var s = n > 1 ? void 0 : n ? Nn(e, t) : e, r = o.length - 1, i; r >= 0; r--)
1888
- (i = o[r]) && (s = (n ? i(e, t, s) : i(s)) || s);
1889
- return n && s && An(e, t, s), s;
1890
- }, q = (o, e) => (t, n) => e(t, n, o);
1891
- let ue = class extends Ne {
1892
- constructor(e, t, n, s, r) {
1891
+ ue = _n([
1892
+ Ne(De.Rendered, ue),
1893
+ q(0, V(j)),
1894
+ q(1, E),
1895
+ q(2, ht),
1896
+ q(3, V(T)),
1897
+ q(4, v)
1898
+ ], ue);
1899
+ var vn = (n, e, t, s) => {
1900
+ for (var i = e, o = n.length - 1, r; o >= 0; o--)
1901
+ (r = n[o]) && (i = r(i) || i);
1902
+ return i;
1903
+ }, Q = (n, e) => (t, s) => e(t, s, n);
1904
+ let ge = class extends be {
1905
+ constructor(e, t, s, i, o) {
1893
1906
  super();
1894
1907
  y(this, "_onInputSubscription");
1895
- this._docSkeletonManagerService = e, this._univerInstanceService = t, this._renderManagerService = n, this._textSelectionRenderManager = s, this._commandService = r, this._init();
1908
+ this._docSkeletonManagerService = e, this._univerInstanceService = t, this._renderManagerService = s, this._textSelectionRenderManager = i, this._commandService = o, this._init();
1896
1909
  }
1897
1910
  dispose() {
1898
1911
  var e;
@@ -1903,103 +1916,103 @@ let ue = class extends Ne {
1903
1916
  }
1904
1917
  _initialNormalInput() {
1905
1918
  this._onInputSubscription = this._textSelectionRenderManager.onInput$.subscribe(async (e) => {
1906
- var p;
1919
+ var S;
1907
1920
  if (e == null)
1908
1921
  return;
1909
1922
  const t = this._univerInstanceService.getCurrentUniverDocInstance();
1910
1923
  if (!t)
1911
1924
  return;
1912
- const n = t.getUnitId(), { event: s, content: r = "", activeRange: i } = e, a = s, c = (p = this._docSkeletonManagerService.getCurrent()) == null ? void 0 : p.skeleton;
1913
- if (a.data == null || c == null || !c || !i)
1925
+ const s = t.getUnitId(), { event: i, content: o = "", activeRange: r } = e, a = i, c = (S = this._docSkeletonManagerService.getCurrent()) == null ? void 0 : S.skeleton;
1926
+ if (a.data == null || c == null || !c || !r)
1914
1927
  return;
1915
- const { startOffset: d, segmentId: l, style: u } = i, m = r.length, g = [
1928
+ const { startOffset: d, segmentId: l, style: u } = r, g = o.length, m = [
1916
1929
  {
1917
- startOffset: d + m,
1918
- endOffset: d + m,
1930
+ startOffset: d + g,
1931
+ endOffset: d + g,
1919
1932
  style: u
1920
1933
  }
1921
1934
  ];
1922
- await this._commandService.executeCommand(pe.id, {
1923
- unitId: n,
1935
+ await this._commandService.executeCommand(Se.id, {
1936
+ unitId: s,
1924
1937
  body: {
1925
- dataStream: r
1938
+ dataStream: o
1926
1939
  },
1927
- range: i,
1928
- textRanges: g,
1940
+ range: r,
1941
+ textRanges: m,
1929
1942
  segmentId: l
1930
1943
  });
1931
1944
  });
1932
1945
  }
1933
1946
  };
1934
- ue = Pn([
1935
- De(Ae.Rendered, ue),
1936
- q(0, V(H)),
1937
- q(1, E),
1938
- q(2, gt),
1939
- q(3, fe),
1940
- q(4, I)
1941
- ], ue);
1942
- var bn = Object.defineProperty, Un = Object.getOwnPropertyDescriptor, wn = (o, e, t, n) => {
1943
- for (var s = n > 1 ? void 0 : n ? Un(e, t) : e, r = o.length - 1, i; r >= 0; r--)
1944
- (i = o[r]) && (s = (n ? i(e, t, s) : i(s)) || s);
1945
- return n && s && bn(e, t, s), s;
1946
- }, Ln = (o, e) => (t, n) => e(t, n, o);
1947
- const Bn = "docs";
1948
- var ae;
1949
- let dt = (ae = class extends Nt {
1950
- constructor(o = {}, e) {
1947
+ ge = vn([
1948
+ Ne(De.Rendered, ge),
1949
+ Q(0, V(j)),
1950
+ Q(1, E),
1951
+ Q(2, ht),
1952
+ Q(3, fe),
1953
+ Q(4, v)
1954
+ ], ge);
1955
+ var Mn = (n, e, t, s) => {
1956
+ for (var i = e, o = n.length - 1, r; o >= 0; o--)
1957
+ (r = n[o]) && (i = r(i) || i);
1958
+ return i;
1959
+ }, Cn = (n, e) => (t, s) => e(t, s, n);
1960
+ const Rn = "docs";
1961
+ var ce;
1962
+ let gt = (ce = class extends bt {
1963
+ constructor(n = {}, e) {
1951
1964
  super(), this._injector = e, this._initializeDependencies(e), this._initializeCommands();
1952
1965
  }
1953
1966
  _initializeCommands() {
1954
1967
  [
1955
- ye,
1956
1968
  Oe,
1957
- cn,
1958
- ln,
1959
- we,
1969
+ Te,
1970
+ tn,
1971
+ nn,
1972
+ ke,
1960
1973
  Le,
1961
1974
  Be,
1962
1975
  Fe,
1963
1976
  oe,
1964
1977
  $e,
1965
1978
  Ve,
1966
- ke,
1967
1979
  ze,
1968
- je,
1969
1980
  Ge,
1970
- It,
1971
- nn,
1972
- pe,
1981
+ He,
1982
+ Xe,
1983
+ Mt,
1984
+ qt,
1973
1985
  Se,
1974
- ht,
1986
+ Ie,
1987
+ pt,
1975
1988
  _t,
1976
- Ue,
1989
+ we,
1977
1990
  L,
1978
- vn,
1979
- In,
1980
- Cn,
1981
- ce,
1982
- ft,
1983
- Rn,
1984
- fn,
1985
- gn,
1986
- He,
1991
+ mn,
1987
1992
  hn,
1988
1993
  pn,
1994
+ le,
1995
+ ft,
1989
1996
  Sn,
1990
- ie,
1991
- _n
1992
- ].forEach((o) => {
1993
- this._injector.get(I).registerCommand(o);
1997
+ cn,
1998
+ an,
1999
+ je,
2000
+ ln,
2001
+ dn,
2002
+ un,
2003
+ ae,
2004
+ gn
2005
+ ].forEach((n) => {
2006
+ this._injector.get(v).registerCommand(n);
1994
2007
  });
1995
2008
  }
1996
- _initializeDependencies(o) {
2009
+ _initializeDependencies(n) {
1997
2010
  [
1998
2011
  // services
1999
- [H],
2000
- [ne],
2012
+ [j],
2013
+ [se],
2001
2014
  [me],
2002
- [he],
2015
+ [pe],
2003
2016
  [
2004
2017
  fe,
2005
2018
  {
@@ -2008,67 +2021,68 @@ let dt = (ae = class extends Nt {
2008
2021
  ],
2009
2022
  [T],
2010
2023
  // controllers
2011
- [ue],
2012
- [le],
2013
- [de]
2014
- ].forEach((e) => o.add(e));
2015
- }
2016
- }, y(ae, "pluginName", Bn), y(ae, "type", W.UNIVER_DOC), ae);
2017
- dt = wn([
2018
- Ln(1, V(kt))
2019
- ], dt);
2024
+ [ge],
2025
+ [de],
2026
+ [ue]
2027
+ ].forEach((e) => n.add(e));
2028
+ }
2029
+ }, y(ce, "pluginName", Rn), y(ce, "type", Z.UNIVER_DOC), ce);
2030
+ gt = Mn([
2031
+ Cn(1, V(zt))
2032
+ ], gt);
2020
2033
  export {
2021
- pn as AlignCenterCommand,
2022
- _n as AlignJustifyCommand,
2023
- hn as AlignLeftCommand,
2024
- ie as AlignOperationCommand,
2025
- Sn as AlignRightCommand,
2026
- nn as BreakLineCommand,
2027
- gn as BulletListCommand,
2028
- In as CoverContentCommand,
2029
- pt as CutContentCommand,
2030
- Gn as DOCS_COMPONENT_BACKGROUND_LAYER_INDEX,
2031
- Xn as DOCS_COMPONENT_DEFAULT_Z_INDEX,
2032
- Hn as DOCS_COMPONENT_HEADER_LAYER_INDEX,
2033
- jn as DOCS_COMPONENT_MAIN_LAYER_INDEX,
2034
- Pe as DOCS_VIEW_KEY,
2035
- Se as DeleteCommand,
2036
- cn as DeleteLeftCommand,
2037
- ln as DeleteRightCommand,
2038
- H as DocSkeletonManagerService,
2034
+ dn as AlignCenterCommand,
2035
+ gn as AlignJustifyCommand,
2036
+ ln as AlignLeftCommand,
2037
+ ae as AlignOperationCommand,
2038
+ un as AlignRightCommand,
2039
+ qt as BreakLineCommand,
2040
+ an as BulletListCommand,
2041
+ hn as CoverContentCommand,
2042
+ St as CutContentCommand,
2043
+ An as DOCS_COMPONENT_BACKGROUND_LAYER_INDEX,
2044
+ bn as DOCS_COMPONENT_DEFAULT_Z_INDEX,
2045
+ Dn as DOCS_COMPONENT_HEADER_LAYER_INDEX,
2046
+ Nn as DOCS_COMPONENT_MAIN_LAYER_INDEX,
2047
+ Ue as DOCS_VIEW_KEY,
2048
+ Ie as DeleteCommand,
2049
+ tn as DeleteLeftCommand,
2050
+ nn as DeleteRightCommand,
2051
+ j as DocSkeletonManagerService,
2039
2052
  me as DocStateChangeManagerService,
2040
- ne as DocViewModelManagerService,
2053
+ se as DocViewModelManagerService,
2054
+ Jt as EditorInsertTextCommandId,
2041
2055
  _t as IMEInputCommand,
2042
- he as IMEInputManagerService,
2043
- Zn as InnerPasteCommand,
2044
- pe as InsertCommand,
2045
- ye as MoveCursorOperation,
2046
- Oe as MoveSelectionOperation,
2047
- Yn as NORMAL_TEXT_SELECTION_PLUGIN_NAME,
2048
- fn as OrderListCommand,
2049
- vn as ReplaceContentCommand,
2050
- je as ResetInlineFormatTextBackgroundColorCommand,
2056
+ pe as IMEInputManagerService,
2057
+ wn as InnerPasteCommand,
2058
+ Se as InsertCommand,
2059
+ Oe as MoveCursorOperation,
2060
+ Te as MoveSelectionOperation,
2061
+ Un as NORMAL_TEXT_SELECTION_PLUGIN_NAME,
2062
+ cn as OrderListCommand,
2063
+ mn as ReplaceContentCommand,
2064
+ He as ResetInlineFormatTextBackgroundColorCommand,
2051
2065
  L as RichTextEditingMutation,
2052
- Rn as SelectAllOperation,
2053
- Cn as SetDocZoomRatioCommand,
2054
- ce as SetDocZoomRatioOperation,
2055
- we as SetInlineFormatBoldCommand,
2056
- It as SetInlineFormatCommand,
2057
- ke as SetInlineFormatFontFamilyCommand,
2066
+ Sn as SelectAllOperation,
2067
+ pn as SetDocZoomRatioCommand,
2068
+ le as SetDocZoomRatioOperation,
2069
+ ke as SetInlineFormatBoldCommand,
2070
+ Mt as SetInlineFormatCommand,
2071
+ ze as SetInlineFormatFontFamilyCommand,
2058
2072
  Ve as SetInlineFormatFontSizeCommand,
2059
2073
  Le as SetInlineFormatItalicCommand,
2060
2074
  Fe as SetInlineFormatStrikethroughCommand,
2061
2075
  oe as SetInlineFormatSubscriptCommand,
2062
2076
  $e as SetInlineFormatSuperscriptCommand,
2063
- Ge as SetInlineFormatTextBackgroundColorCommand,
2064
- ze as SetInlineFormatTextColorCommand,
2077
+ Xe as SetInlineFormatTextBackgroundColorCommand,
2078
+ Ge as SetInlineFormatTextColorCommand,
2065
2079
  Be as SetInlineFormatUnderlineCommand,
2066
2080
  ft as SetTextSelectionsOperation,
2067
2081
  T as TextSelectionManagerService,
2068
- dt as UniverDocsPlugin,
2069
- ht as UpdateCommand,
2070
- zt as VIEWPORT_KEY,
2071
- Gt as getDocObject,
2072
- Wn as getDocObjectById,
2073
- Z as serializeTextRange
2082
+ gt as UniverDocsPlugin,
2083
+ pt as UpdateCommand,
2084
+ Gt as VIEWPORT_KEY,
2085
+ Xt as getDocObject,
2086
+ Pn as getDocObjectById,
2087
+ J as serializeTextRange
2074
2088
  };