@univerjs/docs 0.1.17 → 0.2.1

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