@univerjs/docs 0.1.0-beta.4 → 0.1.1

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