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