@univerjs/docs 0.1.16 → 0.2.0

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