@univerjs/docs 0.2.12 → 0.2.13

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 (58) hide show
  1. package/lib/cjs/index.js +1 -5
  2. package/lib/es/index.js +178 -4375
  3. package/lib/types/commands/mutations/core-editing.mutation.d.ts +1 -1
  4. package/lib/types/controllers/config.schema.d.ts +1 -0
  5. package/lib/types/controllers/custom-range.controller.d.ts +2 -2
  6. package/lib/types/doc-plugin.d.ts +1 -1
  7. package/lib/types/index.d.ts +7 -48
  8. package/lib/types/services/doc-interceptor/doc-interceptor.service.d.ts +1 -1
  9. package/lib/types/services/doc-selection-manager.service.d.ts +56 -0
  10. package/lib/types/services/doc-state-emit.service.d.ts +27 -0
  11. package/lib/umd/index.js +1 -5
  12. package/package.json +10 -9
  13. package/lib/types/basics/__tests__/plain-text.spec.d.ts +0 -16
  14. package/lib/types/basics/component-tools.d.ts +0 -17
  15. package/lib/types/basics/custom-decoration-factory.d.ts +0 -23
  16. package/lib/types/basics/custom-range-factory.d.ts +0 -24
  17. package/lib/types/basics/custom-range.d.ts +0 -13
  18. package/lib/types/basics/docs-view-key.d.ts +0 -30
  19. package/lib/types/basics/paragraph.d.ts +0 -2
  20. package/lib/types/basics/plain-text.d.ts +0 -9
  21. package/lib/types/basics/replace.d.ts +0 -13
  22. package/lib/types/basics/retain-delete-params.d.ts +0 -6
  23. package/lib/types/basics/selection.d.ts +0 -22
  24. package/lib/types/basics/table.d.ts +0 -16
  25. package/lib/types/commands/commands/__tests__/clipboard.command.spec.d.ts +0 -16
  26. package/lib/types/commands/commands/__tests__/core-editing.command.spec.d.ts +0 -16
  27. package/lib/types/commands/commands/__tests__/create-command-test-bed.d.ts +0 -34
  28. package/lib/types/commands/commands/__tests__/inline-format.command.spec.d.ts +0 -16
  29. package/lib/types/commands/commands/__tests__/mock-text-selection-render-manager.d.ts +0 -9
  30. package/lib/types/commands/commands/__tests__/replace-content.command.spec.d.ts +0 -16
  31. package/lib/types/commands/commands/auto-format.command.d.ts +0 -7
  32. package/lib/types/commands/commands/break-line.command.d.ts +0 -3
  33. package/lib/types/commands/commands/clipboard.inner.command.d.ts +0 -16
  34. package/lib/types/commands/commands/core-editing.command.d.ts +0 -43
  35. package/lib/types/commands/commands/delete.command.d.ts +0 -19
  36. package/lib/types/commands/commands/ime-input.command.d.ts +0 -9
  37. package/lib/types/commands/commands/inline-format.command.d.ts +0 -17
  38. package/lib/types/commands/commands/list.command.d.ts +0 -42
  39. package/lib/types/commands/commands/paragraph-align.command.d.ts +0 -18
  40. package/lib/types/commands/commands/replace-content.command.d.ts +0 -26
  41. package/lib/types/commands/commands/set-doc-zoom-ratio.command.d.ts +0 -6
  42. package/lib/types/commands/commands/table/doc-table-create.command.d.ts +0 -10
  43. package/lib/types/commands/commands/table/doc-table-delete.command.d.ts +0 -10
  44. package/lib/types/commands/commands/table/doc-table-insert.command.d.ts +0 -34
  45. package/lib/types/commands/commands/table/doc-table-tab.command.d.ts +0 -5
  46. package/lib/types/commands/commands/table/table.d.ts +0 -94
  47. package/lib/types/commands/operations/cursor.operation.d.ts +0 -12
  48. package/lib/types/commands/operations/select-all.operation.d.ts +0 -5
  49. package/lib/types/commands/operations/set-doc-zoom-ratio.operation.d.ts +0 -7
  50. package/lib/types/commands/util.d.ts +0 -9
  51. package/lib/types/controllers/ime-input.controller.d.ts +0 -25
  52. package/lib/types/controllers/move-cursor.controller.d.ts +0 -20
  53. package/lib/types/controllers/normal-input.controller.d.ts +0 -13
  54. package/lib/types/services/doc-auto-format.service.d.ts +0 -37
  55. package/lib/types/services/doc-state-change-manager.service.d.ts +0 -34
  56. package/lib/types/services/ime-input-manager.service.d.ts +0 -28
  57. package/lib/types/services/text-selection-manager.service.d.ts +0 -55
  58. package/lib/types/types/enums/delete-direction.d.ts +0 -19
package/lib/es/index.js CHANGED
@@ -2,50 +2,40 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
3
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
4
4
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
5
- import { CommandType, RxDisposable, ICommandService, Inject, IUndoRedoService, UndoCommandId, RedoCommandId, JSONX, IUniverInstanceService, LocaleService, UniverInstanceType, isInternalEditorID, Tools, PresetListType, MemoryCursor, TextX, PRESET_LIST_TYPE, GridType, TextXActionType, UpdateDocsAttributeType, sortRulesFactory, generateRandomId, DataStreamTreeTokenType, normalizeBody, getBodySlice, updateAttributeByInsert, BooleanNumber, TableCellHeightRule, TableSizeType, TableAlignmentType, TableTextWrapType, ObjectRelativeFromH, ObjectRelativeFromV, PositionedObjectLayoutType, getCustomRangeSlice, getCustomDecorationSlice, BaselineOffset, OnLifecycle, LifecycleStages, Disposable, Direction, toDisposable, sequenceExecuteAsync, HorizontalAlign, Plugin, Injector, IConfigService, createInterceptorKey, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DisposableCollection, remove, composeInterceptors } from "@univerjs/core";
6
- import { NORMAL_TEXT_SELECTION_PLUGIN_STYLE, ITextSelectionRenderManager, DocumentSkeleton, DocumentViewModel, IRenderManagerService, getCharSpaceApply, getNumberUnitValue, hasListGlyph, isIndentByGlyph, isFirstGlyph, getParagraphByGlyph, DocumentSkeletonPageType, lineIterator, getLastLine, RANGE_DIRECTION, NodePositionConvertToCursor, TextSelectionRenderManager } from "@univerjs/engine-render";
5
+ import { CommandType, RxDisposable, ICommandService, Inject, LocaleService, UniverInstanceType, isInternalEditorID, IUniverInstanceService, JSONX, OnLifecycle, LifecycleStages, Disposable, BuildTextUtils, Plugin, Injector, IConfigService, createInterceptorKey, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DisposableCollection, toDisposable, remove, composeInterceptors } from "@univerjs/core";
6
+ import { NORMAL_TEXT_SELECTION_PLUGIN_STYLE, DocumentSkeleton, DocumentViewModel, IRenderManagerService } from "@univerjs/engine-render";
7
7
  import { BehaviorSubject, takeUntil } from "rxjs";
8
- import { TextSelectionManagerService as TextSelectionManagerService$1, getCommandSkeleton as getCommandSkeleton$1, getInsertSelection as getInsertSelection$1, RichTextEditingMutation as RichTextEditingMutation$1, generateParagraphs as generateParagraphs$1, getRichTextEditPath as getRichTextEditPath$1 } from "@univerjs/docs";
9
8
  const SetTextSelectionsOperation = {
10
9
  id: "doc.operation.set-selections",
11
10
  type: CommandType.OPERATION,
12
11
  handler: /* @__PURE__ */ __name((_, __) => !0, "handler")
13
12
  };
14
- var __defProp$9 = Object.defineProperty, __getOwnPropDesc$9 = Object.getOwnPropertyDescriptor, __decorateClass$9 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
15
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$9(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
13
+ var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
14
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
16
15
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
17
- return kind && result && __defProp$9(target, key, result), result;
18
- }, "__decorateClass$9"), __decorateParam$9 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$9");
19
- function serializeDocRange(textRange) {
20
- const { startOffset, endOffset, collapsed, rangeType } = textRange, serializedTextRange = {
21
- startOffset,
22
- endOffset,
23
- collapsed,
24
- rangeType
25
- };
26
- return typeof textRange.isActive == "function" && (serializedTextRange.isActive = textRange.isActive()), serializedTextRange;
27
- }
28
- __name(serializeDocRange, "serializeDocRange");
29
- var _a;
30
- let TextSelectionManagerService = (_a = class extends RxDisposable {
31
- constructor(_textSelectionRenderManager, _commandService) {
16
+ return kind && result && __defProp$4(target, key, result), result;
17
+ }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4"), _a;
18
+ let DocSelectionManagerService = (_a = class extends RxDisposable {
19
+ constructor(_commandService) {
32
20
  super();
33
21
  __publicField(this, "_currentSelection", null);
34
22
  __publicField(this, "_textSelectionInfo", /* @__PURE__ */ new Map());
35
23
  __publicField(this, "_textSelection$", new BehaviorSubject(null));
36
24
  __publicField(this, "textSelection$", this._textSelection$.asObservable());
37
- this._textSelectionRenderManager = _textSelectionRenderManager, this._commandService = _commandService, this._syncSelectionFromRenderService();
25
+ __publicField(this, "_refreshSelection$", new BehaviorSubject(null));
26
+ __publicField(this, "refreshSelection$", this._refreshSelection$.asObservable());
27
+ this._commandService = _commandService;
38
28
  }
39
29
  getCurrentSelection() {
40
30
  return this._currentSelection;
41
31
  }
42
32
  // Get textRanges, style, segmentId
33
+ /**
34
+ * @deprecated
35
+ */
43
36
  getCurrentSelectionInfo() {
44
37
  return this._getTextRanges(this._currentSelection);
45
38
  }
46
- dispose() {
47
- this._textSelection$.complete();
48
- }
49
39
  refreshSelection() {
50
40
  this._currentSelection != null && this._refresh(this._currentSelection);
51
41
  }
@@ -54,19 +44,26 @@ let TextSelectionManagerService = (_a = class extends RxDisposable {
54
44
  this._currentSelection = param, this._refresh(param);
55
45
  }
56
46
  setCurrentSelectionNotRefresh(param) {
57
- this._currentSelection = param;
47
+ var _a6;
48
+ const { unitId, subUnitId } = (_a6 = this._currentSelection) != null ? _a6 : {}, { unitId: newUnitId, subUnitId: newSubUnitId } = param;
49
+ (unitId !== newUnitId || subUnitId !== newSubUnitId) && (unitId && subUnitId && this._refreshSelection$.next({
50
+ unitId,
51
+ subUnitId,
52
+ docRanges: [],
53
+ isEditing: !1
54
+ }), this._currentSelection = param);
58
55
  }
59
56
  getCurrentTextRanges() {
60
- var _a11;
61
- return (_a11 = this._getTextRanges(this._currentSelection)) == null ? void 0 : _a11.textRanges;
57
+ var _a6;
58
+ return (_a6 = this._getTextRanges(this._currentSelection)) == null ? void 0 : _a6.textRanges;
62
59
  }
63
60
  getCurrentRectRanges() {
64
- var _a11;
65
- return (_a11 = this._getTextRanges(this._currentSelection)) == null ? void 0 : _a11.rectRanges;
61
+ var _a6;
62
+ return (_a6 = this._getTextRanges(this._currentSelection)) == null ? void 0 : _a6.rectRanges;
66
63
  }
67
64
  getDocRanges() {
68
- var _a11, _b;
69
- const textRanges = (_a11 = this.getCurrentTextRanges()) != null ? _a11 : [], rectRanges = (_b = this.getCurrentRectRanges()) != null ? _b : [];
65
+ var _a6, _b;
66
+ const textRanges = (_a6 = this.getCurrentTextRanges()) != null ? _a6 : [], rectRanges = (_b = this.getCurrentRectRanges()) != null ? _b : [];
70
67
  return [...textRanges, ...rectRanges].filter((range) => range.startOffset != null && range.endOffset != null).sort((a, b) => a.startOffset > b.startOffset ? 1 : a.startOffset < b.startOffset ? -1 : 0);
71
68
  }
72
69
  getActiveTextRange() {
@@ -74,34 +71,18 @@ let TextSelectionManagerService = (_a = class extends RxDisposable {
74
71
  if (selectionInfo == null)
75
72
  return;
76
73
  const { textRanges } = selectionInfo;
77
- return textRanges.find((textRange) => textRange.isActive());
74
+ return textRanges.find((textRange) => textRange.isActive);
78
75
  }
76
+ /**
77
+ *
78
+ * @deprecated
79
+ */
79
80
  getActiveRectRange() {
80
81
  const selectionInfo = this._getTextRanges(this._currentSelection);
81
82
  if (selectionInfo == null)
82
83
  return;
83
84
  const { rectRanges } = selectionInfo;
84
- return rectRanges.find((rectRange) => rectRange.isActive());
85
- }
86
- getActiveTextRangeWithStyle() {
87
- const selectionInfo = this._getTextRanges(this._currentSelection);
88
- if (selectionInfo == null)
89
- return;
90
- const { textRanges, segmentId, style, segmentPage } = selectionInfo, activeTextRange = textRanges.find((textRange) => textRange.isActive());
91
- if (activeTextRange == null)
92
- return null;
93
- const { startOffset, endOffset, collapsed, startNodePosition, endNodePosition, direction } = activeTextRange;
94
- return startOffset == null || endOffset == null ? null : {
95
- startOffset,
96
- endOffset,
97
- collapsed,
98
- startNodePosition,
99
- endNodePosition,
100
- direction,
101
- segmentId,
102
- segmentPage,
103
- style
104
- };
85
+ return rectRanges.find((rectRange) => rectRange.isActive);
105
86
  }
106
87
  // **Only used in test case** because this does not go through the render layer.
107
88
  add(textRanges, isEditing = !0) {
@@ -117,15 +98,18 @@ let TextSelectionManagerService = (_a = class extends RxDisposable {
117
98
  });
118
99
  }
119
100
  replaceTextRanges(docRanges, isEditing = !0, options) {
120
- this._currentSelection != null && (this._textSelectionRenderManager.removeAllRanges(), this._textSelectionRenderManager.addDocRanges(docRanges, isEditing, options));
121
- }
122
- // All textRanges should be synchronized from the render layer.
123
- _syncSelectionFromRenderService() {
124
- this._textSelectionRenderManager.textSelectionInner$.pipe(takeUntil(this.dispose$)).subscribe((params) => {
125
- params != null && this._replaceTextRangesWithNoRefresh(params);
101
+ if (this._currentSelection == null)
102
+ return;
103
+ const { unitId, subUnitId } = this._currentSelection;
104
+ this._refreshSelection$.next({
105
+ unitId,
106
+ subUnitId,
107
+ docRanges,
108
+ isEditing,
109
+ options
126
110
  });
127
111
  }
128
- _replaceTextRangesWithNoRefresh(textSelectionInfo) {
112
+ replaceTextRangesWithNoRefresh(textSelectionInfo) {
129
113
  if (this._currentSelection == null)
130
114
  return;
131
115
  const params = {
@@ -133,7 +117,7 @@ let TextSelectionManagerService = (_a = class extends RxDisposable {
133
117
  ...textSelectionInfo
134
118
  };
135
119
  this._replaceByParam(params), this._textSelection$.next(params);
136
- const { unitId, subUnitId, segmentId, style, textRanges, rectRanges, isEditing } = params, ranges = [...textRanges, ...rectRanges].filter((range) => range.startOffset != null && range.endOffset != null).sort((a, b) => a.startOffset > b.startOffset ? 1 : a.startOffset < b.startOffset ? -1 : 0).map(serializeDocRange);
120
+ const { unitId, subUnitId, segmentId, style, textRanges, rectRanges, isEditing } = params, ranges = [...textRanges, ...rectRanges].filter((range) => range.startOffset != null && range.endOffset != null).sort((a, b) => a.startOffset > b.startOffset ? 1 : a.startOffset < b.startOffset ? -1 : 0);
137
121
  this._commandService.executeCommand(SetTextSelectionsOperation.id, {
138
122
  unitId,
139
123
  subUnitId,
@@ -143,193 +127,48 @@ let TextSelectionManagerService = (_a = class extends RxDisposable {
143
127
  ranges
144
128
  });
145
129
  }
130
+ dispose() {
131
+ this._textSelection$.complete();
132
+ }
146
133
  _getTextRanges(param) {
147
- var _a11;
134
+ var _a6;
148
135
  if (param == null)
149
136
  return;
150
137
  const { unitId, subUnitId = "" } = param;
151
- return (_a11 = this._textSelectionInfo.get(unitId)) == null ? void 0 : _a11.get(subUnitId);
138
+ return (_a6 = this._textSelectionInfo.get(unitId)) == null ? void 0 : _a6.get(subUnitId);
152
139
  }
153
140
  _refresh(param) {
154
141
  const allTextSelectionInfo = this._getTextRanges(param);
155
- if (this._textSelectionRenderManager.removeAllRanges(), allTextSelectionInfo == null)
142
+ if (allTextSelectionInfo == null)
156
143
  return;
157
- const { textRanges, rectRanges } = allTextSelectionInfo, docRanges = [...textRanges, ...rectRanges];
158
- docRanges.length > 0 && this._textSelectionRenderManager.addDocRanges(docRanges.map(serializeDocRange), !1);
144
+ const { textRanges, rectRanges } = allTextSelectionInfo, docRanges = [...textRanges, ...rectRanges], { unitId, subUnitId } = param;
145
+ this._refreshSelection$.next({
146
+ unitId,
147
+ subUnitId,
148
+ docRanges,
149
+ isEditing: !1
150
+ });
159
151
  }
160
152
  _replaceByParam(insertParam) {
161
- const { unitId, subUnitId, style, segmentId, textRanges, rectRanges, isEditing, segmentPage } = insertParam;
162
- this._textSelectionInfo.has(unitId) || this._textSelectionInfo.set(unitId, /* @__PURE__ */ new Map()), this._textSelectionInfo.get(unitId).set(subUnitId, { textRanges, rectRanges, style, segmentId, isEditing, segmentPage });
153
+ const { unitId, subUnitId, ...selectionInsertParam } = insertParam;
154
+ this._textSelectionInfo.has(unitId) || this._textSelectionInfo.set(unitId, /* @__PURE__ */ new Map()), this._textSelectionInfo.get(unitId).set(subUnitId, { ...selectionInsertParam });
163
155
  }
164
156
  _addByParam(insertParam) {
165
- const { unitId, subUnitId, textRanges, rectRanges, style, segmentId, isEditing, segmentPage } = insertParam;
157
+ const { unitId, subUnitId, ...selectionInsertParam } = insertParam;
166
158
  this._textSelectionInfo.has(unitId) || this._textSelectionInfo.set(unitId, /* @__PURE__ */ new Map());
167
159
  const unitTextRange = this._textSelectionInfo.get(unitId);
168
- unitTextRange.has(subUnitId) ? unitTextRange.get(subUnitId).textRanges.push(...textRanges) : unitTextRange.set(subUnitId, { textRanges, rectRanges, style, segmentId, isEditing, segmentPage });
169
- }
170
- }, __name(_a, "TextSelectionManagerService"), _a);
171
- TextSelectionManagerService = __decorateClass$9([
172
- __decorateParam$9(0, ITextSelectionRenderManager),
173
- __decorateParam$9(1, ICommandService)
174
- ], TextSelectionManagerService);
175
- var __defProp$8 = Object.defineProperty, __getOwnPropDesc$8 = Object.getOwnPropertyDescriptor, __decorateClass$8 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
176
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$8(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
177
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
178
- return kind && result && __defProp$8(target, key, result), result;
179
- }, "__decorateClass$8"), __decorateParam$8 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$8");
180
- const DEBOUNCE_DELAY = 300;
181
- var _a2;
182
- let DocStateChangeManagerService = (_a2 = class extends RxDisposable {
183
- constructor(_undoRedoService, _commandService, _univerInstanceService) {
184
- super();
185
- __publicField(this, "_docStateChange$", new BehaviorSubject(null));
186
- __publicField(this, "docStateChange$", this._docStateChange$.asObservable());
187
- // This cache used for history compose.
188
- __publicField(this, "_historyStateCache", /* @__PURE__ */ new Map());
189
- // This cache used for collaboration state compose.
190
- __publicField(this, "_changeStateCache", /* @__PURE__ */ new Map());
191
- __publicField(this, "_historyTimer", null);
192
- __publicField(this, "_changeStateCacheTimer", null);
193
- this._undoRedoService = _undoRedoService, this._commandService = _commandService, this._univerInstanceService = _univerInstanceService, this._initialize();
194
- }
195
- setChangeState(changeState) {
196
- this._cacheChangeState(changeState, "history"), this._cacheChangeState(changeState, "collaboration");
197
- }
198
- _initialize() {
199
- this.disposeWithMe(
200
- this._commandService.beforeCommandExecuted((command) => {
201
- if (command.id === UndoCommandId || command.id === RedoCommandId) {
202
- const univerDoc = this._univerInstanceService.getCurrentUniverDocInstance();
203
- if (univerDoc == null)
204
- return;
205
- const unitId = univerDoc.getUnitId();
206
- this._pushHistory(unitId), this._emitChangeState(unitId);
207
- }
208
- })
209
- );
210
- }
211
- _cacheChangeState(changeState, type = "history") {
212
- const { trigger, unitId, noHistory, debounce = !1 } = changeState;
213
- if (noHistory || trigger == null || type === "history" && (trigger === RedoCommandId || trigger === UndoCommandId))
214
- return;
215
- const stateCache = type === "history" ? this._historyStateCache : this._changeStateCache, cb = type === "history" ? this._pushHistory.bind(this) : this._emitChangeState.bind(this);
216
- if (stateCache.has(unitId)) {
217
- const cacheStates = stateCache.get(unitId);
218
- cacheStates == null || cacheStates.push(changeState);
219
- } else
220
- stateCache.set(unitId, [changeState]);
221
- debounce ? type === "history" ? (this._historyTimer && clearTimeout(this._historyTimer), this._historyTimer = setTimeout(() => {
222
- cb(unitId);
223
- }, DEBOUNCE_DELAY)) : (this._changeStateCacheTimer && clearTimeout(this._changeStateCacheTimer), this._changeStateCacheTimer = setTimeout(() => {
224
- cb(unitId);
225
- }, DEBOUNCE_DELAY)) : cb(unitId);
226
- }
227
- _pushHistory(unitId) {
228
- const undoRedoService = this._undoRedoService, cacheStates = this._historyStateCache.get(unitId);
229
- if (!Array.isArray(cacheStates) || cacheStates.length === 0)
230
- return;
231
- const len = cacheStates.length, commandId = cacheStates[0].commandId, firstState = cacheStates[0], lastState = cacheStates[len - 1], redoParams = {
232
- unitId,
233
- actions: cacheStates.reduce((acc, cur) => JSONX.compose(acc, cur.redoState.actions), null),
234
- textRanges: lastState.redoState.textRanges
235
- }, undoParams = {
236
- unitId,
237
- // Always need to put undoParams after redoParams, because `reverse` will change the `cacheStates` order.
238
- actions: cacheStates.reverse().reduce((acc, cur) => JSONX.compose(acc, cur.undoState.actions), null),
239
- textRanges: firstState.undoState.textRanges
240
- };
241
- undoRedoService.pushUndoRedo({
242
- unitID: unitId,
243
- undoMutations: [{ id: commandId, params: undoParams }],
244
- redoMutations: [{ id: commandId, params: redoParams }]
245
- }), cacheStates.length = 0;
246
- }
247
- _emitChangeState(unitId) {
248
- const cacheStates = this._changeStateCache.get(unitId);
249
- if (!Array.isArray(cacheStates) || cacheStates.length === 0)
250
- return;
251
- const len = cacheStates.length, { commandId, trigger, segmentId, noHistory, debounce } = cacheStates[0], firstState = cacheStates[0], lastState = cacheStates[len - 1], redoState = {
252
- unitId,
253
- actions: cacheStates.reduce((acc, cur) => JSONX.compose(acc, cur.redoState.actions), null),
254
- textRanges: lastState.redoState.textRanges
255
- }, undoState = {
256
- unitId,
257
- // Always need to put undoParams after redoParams, because `reverse` will change the `cacheStates` order.
258
- actions: cacheStates.reverse().reduce((acc, cur) => JSONX.compose(acc, cur.undoState.actions), null),
259
- textRanges: firstState.undoState.textRanges
260
- }, changeState = {
261
- commandId,
262
- unitId,
263
- trigger,
264
- redoState,
265
- undoState,
266
- segmentId,
267
- noHistory,
268
- debounce
269
- };
270
- cacheStates.length = 0, this._docStateChange$.next(changeState);
271
- }
272
- }, __name(_a2, "DocStateChangeManagerService"), _a2);
273
- DocStateChangeManagerService = __decorateClass$8([
274
- __decorateParam$8(0, Inject(IUndoRedoService)),
275
- __decorateParam$8(1, ICommandService),
276
- __decorateParam$8(2, IUniverInstanceService)
277
- ], DocStateChangeManagerService);
278
- const _IMEInputManagerService = class _IMEInputManagerService {
279
- constructor() {
280
- __publicField(this, "_previousActiveRange", null);
281
- __publicField(this, "_undoMutationParamsCache", []);
282
- __publicField(this, "_redoMutationParamsCache", []);
283
- }
284
- clearUndoRedoMutationParamsCache() {
285
- this._undoMutationParamsCache = [], this._redoMutationParamsCache = [];
286
- }
287
- getUndoRedoMutationParamsCache() {
288
- return {
289
- undoCache: this._undoMutationParamsCache,
290
- redoCache: this._redoMutationParamsCache
291
- };
292
- }
293
- setUndoRedoMutationParamsCache({ undoCache = [], redoCache = [] }) {
294
- this._undoMutationParamsCache = undoCache, this._redoMutationParamsCache = redoCache;
295
- }
296
- getActiveRange() {
297
- return this._previousActiveRange;
298
- }
299
- setActiveRange(range) {
300
- this._previousActiveRange = range;
301
- }
302
- pushUndoRedoMutationParams(undoParams, redoParams) {
303
- this._undoMutationParamsCache.push(undoParams), this._redoMutationParamsCache.push(redoParams);
304
- }
305
- fetchComposedUndoRedoMutationParams() {
306
- if (this._undoMutationParamsCache.length === 0 || this._previousActiveRange == null || this._redoMutationParamsCache.length === 0)
307
- return null;
308
- const { unitId } = this._undoMutationParamsCache[0], undoMutationParams = {
309
- unitId,
310
- actions: this._undoMutationParamsCache.reverse().reduce((acc, cur) => JSONX.compose(acc, cur.actions), null),
311
- textRanges: []
312
- // Add empty array, will never use, just fix type error
313
- };
314
- return { redoMutationParams: {
315
- unitId,
316
- actions: this._redoMutationParamsCache.reduce((acc, cur) => JSONX.compose(acc, cur.actions), null),
317
- textRanges: []
318
- // Add empty array, will never use, just fix type error
319
- }, undoMutationParams, previousActiveRange: this._previousActiveRange };
320
- }
321
- dispose() {
322
- this._undoMutationParamsCache = [], this._redoMutationParamsCache = [], this._previousActiveRange = null;
160
+ unitTextRange.has(subUnitId) ? unitTextRange.get(subUnitId).textRanges.push(...insertParam.textRanges) : unitTextRange.set(subUnitId, { ...selectionInsertParam });
323
161
  }
324
- };
325
- __name(_IMEInputManagerService, "IMEInputManagerService");
326
- let IMEInputManagerService = _IMEInputManagerService;
327
- var __defProp$7 = Object.defineProperty, __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor, __decorateClass$7 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
328
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
162
+ }, __name(_a, "DocSelectionManagerService"), _a);
163
+ DocSelectionManagerService = __decorateClass$4([
164
+ __decorateParam$4(0, ICommandService)
165
+ ], DocSelectionManagerService);
166
+ var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
167
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
329
168
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
330
- return kind && result && __defProp$7(target, key, result), result;
331
- }, "__decorateClass$7"), __decorateParam$7 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$7"), _a3;
332
- let DocSkeletonManagerService = (_a3 = class extends RxDisposable {
169
+ return kind && result && __defProp$3(target, key, result), result;
170
+ }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a2;
171
+ let DocSkeletonManagerService = (_a2 = class extends RxDisposable {
333
172
  constructor(_context, _localeService, _univerInstanceService) {
334
173
  super();
335
174
  __publicField(this, "_skeleton");
@@ -372,17 +211,31 @@ let DocSkeletonManagerService = (_a3 = class extends RxDisposable {
372
211
  _buildDocViewModel(documentDataModel) {
373
212
  return new DocumentViewModel(documentDataModel);
374
213
  }
375
- }, __name(_a3, "DocSkeletonManagerService"), _a3);
376
- DocSkeletonManagerService = __decorateClass$7([
377
- __decorateParam$7(1, Inject(LocaleService)),
378
- __decorateParam$7(2, IUniverInstanceService)
214
+ }, __name(_a2, "DocSkeletonManagerService"), _a2);
215
+ DocSkeletonManagerService = __decorateClass$3([
216
+ __decorateParam$3(1, Inject(LocaleService)),
217
+ __decorateParam$3(2, IUniverInstanceService)
379
218
  ], DocSkeletonManagerService);
219
+ const _DocStateEmitService = class _DocStateEmitService extends RxDisposable {
220
+ constructor() {
221
+ super();
222
+ __publicField(this, "_docStateChangeParams$", new BehaviorSubject(null));
223
+ __publicField(this, "docStateChangeParams$", this._docStateChangeParams$.asObservable());
224
+ }
225
+ emitStateChangeInfo(params) {
226
+ this._docStateChangeParams$.next(params);
227
+ }
228
+ dispose() {
229
+ super.dispose(), this._docStateChangeParams$.complete();
230
+ }
231
+ };
232
+ __name(_DocStateEmitService, "DocStateEmitService");
233
+ let DocStateEmitService = _DocStateEmitService;
380
234
  const RichTextEditingMutationId = "doc.mutation.rich-text-editing", RichTextEditingMutation = {
381
235
  id: RichTextEditingMutationId,
382
236
  type: CommandType.MUTATION,
383
- // eslint-disable-next-line max-lines-per-function
384
237
  handler: /* @__PURE__ */ __name((accessor, params) => {
385
- var _a11, _b;
238
+ var _a6, _b;
386
239
  const {
387
240
  unitId,
388
241
  segmentId = "",
@@ -394,19 +247,19 @@ const RichTextEditingMutationId = "doc.mutation.rich-text-editing", RichTextEdit
394
247
  isCompositionEnd,
395
248
  noNeedSetTextRange,
396
249
  debounce
397
- } = params, univerInstanceService = accessor.get(IUniverInstanceService), renderManagerService = accessor.get(IRenderManagerService), documentDataModel = univerInstanceService.getUniverDocInstance(unitId), documentViewModel = (_a11 = renderManagerService.getRenderById(unitId)) == null ? void 0 : _a11.with(DocSkeletonManagerService).getViewModel();
250
+ } = params, univerInstanceService = accessor.get(IUniverInstanceService), renderManagerService = accessor.get(IRenderManagerService), docStateEmitService = accessor.get(DocStateEmitService), documentDataModel = univerInstanceService.getUniverDocInstance(unitId), documentViewModel = (_a6 = renderManagerService.getRenderById(unitId)) == null ? void 0 : _a6.with(DocSkeletonManagerService).getViewModel();
398
251
  if (documentDataModel == null || documentViewModel == null)
399
252
  throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${unitId}`);
400
- const textSelectionManagerService = accessor.get(TextSelectionManagerService), serializedSelections = ((_b = textSelectionManagerService.getDocRanges()) != null ? _b : []).map(serializeDocRange), docStateChangeManagerService = accessor.get(DocStateChangeManagerService), imeInputManagerService = accessor.get(IMEInputManagerService), disabled = !!documentDataModel.getSnapshot().disabled;
253
+ const docSelectionManagerService = accessor.get(DocSelectionManagerService), docRanges = (_b = docSelectionManagerService.getDocRanges()) != null ? _b : [], disabled = !!documentDataModel.getSnapshot().disabled;
401
254
  if (JSONX.isNoop(actions) || actions && actions.length === 0 || disabled)
402
255
  return {
403
256
  unitId,
404
257
  actions: [],
405
- textRanges: serializedSelections
258
+ textRanges: docRanges
406
259
  };
407
260
  const undoActions = JSONX.invertWithDoc(actions, documentDataModel.getSnapshot());
408
261
  documentDataModel.apply(actions), documentViewModel.reset(documentDataModel), !noNeedSetTextRange && textRanges && trigger != null && queueMicrotask(() => {
409
- textSelectionManagerService.replaceTextRanges(textRanges, !0, params.options);
262
+ docSelectionManagerService.replaceTextRanges(textRanges, !0, params.options);
410
263
  });
411
264
  const changeState = {
412
265
  commandId: RichTextEditingMutationId,
@@ -421,4050 +274,103 @@ const RichTextEditingMutationId = "doc.mutation.rich-text-editing", RichTextEdit
421
274
  },
422
275
  undoState: {
423
276
  actions: undoActions,
424
- textRanges: prevTextRanges != null ? prevTextRanges : serializedSelections
425
- }
277
+ textRanges: prevTextRanges != null ? prevTextRanges : docRanges
278
+ },
279
+ isCompositionEnd
426
280
  };
427
- if (isCompositionEnd) {
428
- const historyParams = imeInputManagerService.fetchComposedUndoRedoMutationParams();
429
- if (historyParams == null)
430
- throw new Error("historyParams is null in RichTextEditingMutation");
431
- const { undoMutationParams, redoMutationParams, previousActiveRange } = historyParams;
432
- changeState.redoState.actions = redoMutationParams.actions, changeState.undoState.actions = undoMutationParams.actions, changeState.undoState.textRanges = [previousActiveRange];
433
- }
434
- return docStateChangeManagerService.setChangeState(changeState), {
281
+ return docStateEmitService.emitStateChangeInfo(changeState), {
435
282
  unitId,
436
283
  actions: undoActions,
437
- textRanges: serializedSelections
438
- };
439
- }, "handler")
440
- };
441
- function getCommandSkeleton(accessor, unitId) {
442
- var _a11;
443
- return (_a11 = accessor.get(IRenderManagerService).getRenderById(unitId)) == null ? void 0 : _a11.with(DocSkeletonManagerService);
444
- }
445
- __name(getCommandSkeleton, "getCommandSkeleton");
446
- function getRichTextEditPath(docDataModel, segmentId = "") {
447
- if (!segmentId)
448
- return ["body"];
449
- const { headers, footers } = docDataModel.getSnapshot();
450
- if (headers == null && footers == null)
451
- throw new Error("Document data model must have headers or footers when update by segment id");
452
- if ((headers == null ? void 0 : headers[segmentId]) != null)
453
- return ["headers", segmentId, "body"];
454
- if ((footers == null ? void 0 : footers[segmentId]) != null)
455
- return ["footers", segmentId, "body"];
456
- throw new Error("Segment id not found in headers or footers");
457
- }
458
- __name(getRichTextEditPath, "getRichTextEditPath");
459
- function hasParagraphInTable(paragraph, tables) {
460
- return tables.some((table) => paragraph.startIndex > table.startIndex && paragraph.startIndex < table.endIndex);
461
- }
462
- __name(hasParagraphInTable, "hasParagraphInTable");
463
- const ListOperationCommand = {
464
- id: "doc.command.list-operation",
465
- type: CommandType.COMMAND,
466
- // eslint-disable-next-line max-lines-per-function, complexity
467
- handler: /* @__PURE__ */ __name((accessor, params) => {
468
- var _a11, _b, _c, _d, _e, _f;
469
- const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService);
470
- let listType = params.listType;
471
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance(), docRanges = (_a11 = textSelectionManagerService.getDocRanges()) != null ? _a11 : [];
472
- if (docDataModel == null || docRanges.length === 0)
473
- return !1;
474
- const segmentId = docRanges[0].segmentId, paragraphs = (_b = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _b.paragraphs, serializedSelections = docRanges.map(serializeDocRange);
475
- if (paragraphs == null)
476
- return !1;
477
- const sectionBreaks = (_d = (_c = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _c.sectionBreaks) != null ? _d : [], currentParagraphs = getParagraphsInRanges(docRanges, paragraphs), unitId = docDataModel.getUnitId(), isAlreadyList = currentParagraphs.every((paragraph) => {
478
- var _a12;
479
- return ((_a12 = paragraph.bullet) == null ? void 0 : _a12.listType.indexOf(listType)) === 0;
480
- });
481
- let listId = Tools.generateRandomId(6);
482
- if (currentParagraphs.length === 1) {
483
- const curIndex = paragraphs.indexOf(currentParagraphs[0]), prevParagraph = paragraphs[curIndex - 1], nextParagraph = paragraphs[curIndex + 1];
484
- prevParagraph && prevParagraph.bullet && prevParagraph.bullet.listType.indexOf(listType) === 0 ? (listId = prevParagraph.bullet.listId, listType !== PresetListType.CHECK_LIST && (listType = prevParagraph.bullet.listType)) : nextParagraph && nextParagraph.bullet && nextParagraph.bullet.listType.indexOf(listType) === 0 && (listId = nextParagraph.bullet.listId, listType !== PresetListType.CHECK_LIST && (listType = nextParagraph.bullet.listType));
485
- }
486
- const doMutation = {
487
- id: RichTextEditingMutation.id,
488
- params: {
489
- unitId,
490
- actions: [],
491
- textRanges: serializedSelections
492
- }
493
- }, memoryCursor = new MemoryCursor();
494
- memoryCursor.reset();
495
- const textX = new TextX(), jsonX = JSONX.getInstance(), customLists = (_e = docDataModel.getSnapshot().lists) != null ? _e : {}, lists = {
496
- ...PRESET_LIST_TYPE,
497
- ...customLists
498
- }, { defaultTabStop = 36 } = docDataModel.getSnapshot().documentStyle;
499
- for (const paragraph of currentParagraphs) {
500
- const { startIndex, paragraphStyle = {}, bullet } = paragraph, { indentFirstLine, snapToGrid, indentStart } = paragraphStyle, paragraphProperties = lists[listType].nestingLevel[0].paragraphProperties || {}, { hanging: listHanging, indentStart: listIndentStart } = paragraphProperties, { charSpace, gridType } = findNearestSectionBreak(startIndex, sectionBreaks) || { charSpace: 0, gridType: GridType.LINES }, charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);
501
- textX.push({
502
- t: TextXActionType.RETAIN,
503
- len: startIndex - memoryCursor.cursor,
504
- segmentId
505
- }), textX.push({
506
- t: TextXActionType.RETAIN,
507
- len: 1,
508
- body: {
509
- dataStream: "",
510
- paragraphs: [
511
- isAlreadyList ? {
512
- paragraphStyle: {
513
- ...paragraphStyle,
514
- hanging: void 0,
515
- indentStart: indentStart ? { v: Math.max(0, getNumberUnitValue(indentStart, charSpaceApply) + getNumberUnitValue(listHanging, charSpaceApply) - getNumberUnitValue(listIndentStart, charSpaceApply)) } : void 0
516
- },
517
- startIndex: 0
518
- } : {
519
- startIndex: 0,
520
- paragraphStyle: {
521
- ...paragraphStyle,
522
- indentFirstLine: void 0,
523
- hanging: listHanging,
524
- indentStart: { v: getNumberUnitValue(listIndentStart, charSpaceApply) - getNumberUnitValue(listHanging, charSpaceApply) + getNumberUnitValue(indentFirstLine, charSpaceApply) + getNumberUnitValue(indentStart, charSpaceApply) }
525
- },
526
- bullet: {
527
- nestingLevel: (_f = bullet == null ? void 0 : bullet.nestingLevel) != null ? _f : 0,
528
- textStyle: {
529
- fs: 20
530
- },
531
- listType,
532
- listId
533
- }
534
- }
535
- ]
536
- },
537
- segmentId,
538
- coverType: UpdateDocsAttributeType.REPLACE
539
- }), memoryCursor.moveCursorTo(startIndex + 1);
540
- }
541
- const path = getRichTextEditPath(docDataModel, segmentId);
542
- return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
543
- }, "handler")
544
- }, ChangeListTypeCommand = {
545
- id: "doc.command.change-list-type",
546
- type: CommandType.COMMAND,
547
- // eslint-disable-next-line max-lines-per-function
548
- handler: /* @__PURE__ */ __name((accessor, params) => {
549
- var _a11, _b, _c, _d, _e, _f;
550
- const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), { listType } = params, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), activeRanges = textSelectionManagerService.getDocRanges();
551
- if (docDataModel == null || activeRanges == null || !activeRanges.length)
552
- return !1;
553
- const { segmentId } = activeRanges[0], selections = (_a11 = textSelectionManagerService.getDocRanges()) != null ? _a11 : [], paragraphs = (_b = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _b.paragraphs, serializedSelections = selections.map(serializeDocRange);
554
- if (paragraphs == null)
555
- return !1;
556
- const sectionBreaks = (_d = (_c = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _c.sectionBreaks) != null ? _d : [], currentParagraphs = getParagraphsRelative(activeRanges, paragraphs), unitId = docDataModel.getUnitId(), listId = Tools.generateRandomId(6), doMutation = {
557
- id: RichTextEditingMutation.id,
558
- params: {
559
- unitId,
560
- actions: [],
561
- textRanges: serializedSelections
562
- }
563
- }, memoryCursor = new MemoryCursor();
564
- memoryCursor.reset();
565
- const textX = new TextX(), jsonX = JSONX.getInstance(), customLists = (_e = docDataModel.getSnapshot().lists) != null ? _e : {}, lists = {
566
- ...PRESET_LIST_TYPE,
567
- ...customLists
568
- }, { defaultTabStop = 36 } = docDataModel.getSnapshot().documentStyle;
569
- for (const paragraph of currentParagraphs) {
570
- const { startIndex, paragraphStyle = {}, bullet } = paragraph, { indentFirstLine, snapToGrid, indentStart } = paragraphStyle, paragraphProperties = lists[listType].nestingLevel[0].paragraphProperties || {}, { hanging: listHanging, indentStart: listIndentStart } = paragraphProperties, { charSpace, gridType } = findNearestSectionBreak(startIndex, sectionBreaks) || { charSpace: 0, gridType: GridType.LINES }, charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);
571
- textX.push({
572
- t: TextXActionType.RETAIN,
573
- len: startIndex - memoryCursor.cursor,
574
- segmentId
575
- }), textX.push({
576
- t: TextXActionType.RETAIN,
577
- len: 1,
578
- body: {
579
- dataStream: "",
580
- paragraphs: [
581
- {
582
- startIndex: 0,
583
- paragraphStyle: {
584
- ...paragraphStyle,
585
- indentFirstLine: void 0,
586
- hanging: listHanging,
587
- indentStart: { v: getNumberUnitValue(listIndentStart, charSpaceApply) - getNumberUnitValue(listHanging, charSpaceApply) + getNumberUnitValue(indentFirstLine, charSpaceApply) + getNumberUnitValue(indentStart, charSpaceApply) }
588
- },
589
- bullet: {
590
- nestingLevel: (_f = bullet == null ? void 0 : bullet.nestingLevel) != null ? _f : 0,
591
- textStyle: (bullet == null ? void 0 : bullet.listType) === listType ? bullet.textStyle : {
592
- fs: 20
593
- },
594
- listType,
595
- listId
596
- }
597
- }
598
- ]
599
- },
600
- segmentId,
601
- coverType: UpdateDocsAttributeType.REPLACE
602
- }), memoryCursor.moveCursorTo(startIndex + 1);
603
- }
604
- const path = getRichTextEditPath(docDataModel, segmentId);
605
- return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
606
- }, "handler")
607
- };
608
- var ChangeListNestingLevelType = /* @__PURE__ */ ((ChangeListNestingLevelType2) => (ChangeListNestingLevelType2[ChangeListNestingLevelType2.increase = 1] = "increase", ChangeListNestingLevelType2[ChangeListNestingLevelType2.decrease = -1] = "decrease", ChangeListNestingLevelType2))(ChangeListNestingLevelType || {});
609
- const ChangeListNestingLevelCommand = {
610
- id: "doc.command.change-list-nesting-level",
611
- type: CommandType.COMMAND,
612
- // eslint-disable-next-line max-lines-per-function
613
- handler: /* @__PURE__ */ __name((accessor, params) => {
614
- var _a11, _b, _c, _d, _e;
615
- if (!params)
616
- return !1;
617
- const { type } = params, textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), docDataModel = univerInstanceService.getCurrentUniverDocInstance(), activeRange = textSelectionManagerService.getActiveTextRangeWithStyle();
618
- if (docDataModel == null || activeRange == null)
619
- return !1;
620
- const { segmentId } = activeRange, tables = (_b = (_a11 = docDataModel.getBody()) == null ? void 0 : _a11.tables) != null ? _b : [], selections = (_c = textSelectionManagerService.getDocRanges()) != null ? _c : [], paragraphs = (_d = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _d.paragraphs, serializedSelections = selections.map(serializeDocRange);
621
- if (paragraphs == null)
622
- return !1;
623
- const currentParagraphs = getParagraphsInRange$1(activeRange, paragraphs), unitId = docDataModel.getUnitId(), doMutation = {
624
- id: RichTextEditingMutation.id,
625
- params: {
626
- unitId,
627
- actions: [],
628
- textRanges: serializedSelections
629
- }
630
- }, memoryCursor = new MemoryCursor();
631
- memoryCursor.reset();
632
- const textX = new TextX(), jsonX = JSONX.getInstance(), customLists = (_e = docDataModel.getSnapshot().lists) != null ? _e : {}, lists = {
633
- ...PRESET_LIST_TYPE,
634
- ...customLists
284
+ textRanges: docRanges
635
285
  };
636
- for (const paragraph of currentParagraphs) {
637
- const { startIndex, paragraphStyle = {}, bullet } = paragraph, isInTable = hasParagraphInTable(paragraph, tables);
638
- if (textX.push({
639
- t: TextXActionType.RETAIN,
640
- len: startIndex - memoryCursor.cursor,
641
- segmentId
642
- }), bullet) {
643
- const listType = bullet.listType;
644
- let maxLevel = lists[listType].nestingLevel.length - 1;
645
- isInTable && (maxLevel = Math.min(maxLevel, 2)), textX.push({
646
- t: TextXActionType.RETAIN,
647
- len: 1,
648
- body: {
649
- dataStream: "",
650
- paragraphs: [
651
- {
652
- startIndex: 0,
653
- paragraphStyle: {
654
- ...paragraphStyle
655
- },
656
- bullet: {
657
- ...bullet,
658
- nestingLevel: Math.max(Math.min(bullet.nestingLevel + type, maxLevel), 0)
659
- }
660
- }
661
- ]
662
- },
663
- segmentId,
664
- coverType: UpdateDocsAttributeType.REPLACE
665
- });
666
- } else
667
- textX.push({
668
- t: TextXActionType.RETAIN,
669
- len: 1
670
- });
671
- memoryCursor.moveCursorTo(startIndex + 1);
672
- }
673
- const path = getRichTextEditPath(docDataModel, segmentId);
674
- return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
675
- }, "handler")
676
- }, BulletListCommand = {
677
- id: "doc.command.bullet-list",
678
- type: CommandType.COMMAND,
679
- handler: /* @__PURE__ */ __name((accessor, params) => {
680
- const commandService = accessor.get(ICommandService);
681
- return params != null && params.value ? commandService.syncExecuteCommand(ChangeListTypeCommand.id, {
682
- listType: params.value
683
- }) : commandService.syncExecuteCommand(ListOperationCommand.id, {
684
- listType: PresetListType.BULLET_LIST
685
- });
686
- }, "handler")
687
- }, CheckListCommand = {
688
- id: "doc.command.check-list",
689
- type: CommandType.COMMAND,
690
- handler: /* @__PURE__ */ __name((accessor, params) => {
691
- const commandService = accessor.get(ICommandService);
692
- return params != null && params.value ? commandService.syncExecuteCommand(ChangeListTypeCommand.id, {
693
- listType: params.value
694
- }) : commandService.syncExecuteCommand(ListOperationCommand.id, {
695
- listType: PresetListType.CHECK_LIST
696
- });
697
- }, "handler")
698
- }, ToggleCheckListCommand = {
699
- id: "doc.command.toggle-check-list",
700
- type: CommandType.COMMAND,
701
- handler: /* @__PURE__ */ __name((accessor, params) => {
702
- var _a11;
703
- if (!params)
704
- return !1;
705
- const univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), { index, segmentId } = params, docDataModel = univerInstanceService.getCurrentUniverDocInstance();
706
- if (docDataModel == null)
707
- return !1;
708
- const paragraphs = (_a11 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a11.paragraphs;
709
- if (paragraphs == null)
710
- return !1;
711
- const currentParagraph = paragraphs.find((p) => p.startIndex === index), unitId = docDataModel.getUnitId();
712
- if (!(currentParagraph != null && currentParagraph.bullet) || currentParagraph.bullet.listType.indexOf(PresetListType.CHECK_LIST) === -1)
713
- return !1;
714
- const doMutation = {
715
- id: RichTextEditingMutation.id,
716
- params: {
717
- unitId,
718
- actions: [],
719
- textRanges: [],
720
- segmentId
721
- }
722
- }, memoryCursor = new MemoryCursor();
723
- memoryCursor.reset();
724
- const textX = new TextX(), jsonX = JSONX.getInstance(), { startIndex, paragraphStyle = {} } = currentParagraph, listType = currentParagraph.bullet.listType === PresetListType.CHECK_LIST ? PresetListType.CHECK_LIST_CHECKED : PresetListType.CHECK_LIST;
725
- textX.push({
726
- t: TextXActionType.RETAIN,
727
- len: startIndex - memoryCursor.cursor,
728
- segmentId
729
- }), textX.push({
730
- t: TextXActionType.RETAIN,
731
- len: 1,
732
- body: {
733
- dataStream: "",
734
- paragraphs: [
735
- {
736
- ...currentParagraph,
737
- paragraphStyle,
738
- startIndex: 0,
739
- bullet: {
740
- ...currentParagraph.bullet,
741
- listType
742
- }
743
- }
744
- ]
745
- },
746
- coverType: UpdateDocsAttributeType.REPLACE,
747
- segmentId
748
- }), memoryCursor.moveCursorTo(startIndex + 1);
749
- const path = getRichTextEditPath(docDataModel, segmentId);
750
- return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
751
286
  }, "handler")
752
- }, OrderListCommand = {
753
- id: "doc.command.order-list",
754
- type: CommandType.COMMAND,
287
+ }, DocsRenameMutation = {
288
+ id: "doc.mutation.rename-doc",
289
+ type: CommandType.MUTATION,
755
290
  handler: /* @__PURE__ */ __name((accessor, params) => {
756
- const commandService = accessor.get(ICommandService);
757
- return params != null && params.value ? commandService.syncExecuteCommand(ChangeListTypeCommand.id, {
758
- listType: params.value
759
- }) : commandService.syncExecuteCommand(ListOperationCommand.id, {
760
- listType: PresetListType.ORDER_LIST
761
- });
762
- }, "handler")
763
- }, QuickListCommand = {
764
- id: "doc.command.quick-list",
765
- type: CommandType.COMMAND,
766
- // eslint-disable-next-line max-lines-per-function
767
- handler(accessor, params) {
768
- var _a11, _b, _c, _d, _e;
769
- if (!params)
770
- return !1;
771
- const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), docDataModel = univerInstanceService.getCurrentUniverDocInstance(), activeRange = textSelectionManagerService.getActiveTextRange();
772
- if (docDataModel == null || activeRange == null)
773
- return !1;
774
- const { segmentId } = activeRange, { listType, paragraph } = params, { paragraphStart, paragraphEnd } = paragraph, textX = new TextX(), jsonX = JSONX.getInstance(), { defaultTabStop = 36 } = docDataModel.getSnapshot().documentStyle, sectionBreaks = (_b = (_a11 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a11.sectionBreaks) != null ? _b : [], { startIndex, paragraphStyle = {} } = paragraph, { indentFirstLine, snapToGrid, indentStart } = paragraphStyle, paragraphProperties = PRESET_LIST_TYPE[listType].nestingLevel[0].paragraphProperties || {}, { hanging: listHanging, indentStart: listIndentStart } = paragraphProperties, bulletParagraphTextStyle = paragraphProperties.textStyle, { charSpace, gridType } = findNearestSectionBreak(startIndex, sectionBreaks) || { charSpace: 0, gridType: GridType.LINES }, charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);
775
- let listId = Tools.generateRandomId(6);
776
- const paragraphs = (_d = (_c = docDataModel.getBody()) == null ? void 0 : _c.paragraphs) != null ? _d : [], curIndex = paragraphs.findIndex((i) => i.startIndex === paragraph.startIndex), prevParagraph = paragraphs[curIndex - 1], nextParagraph = paragraphs[curIndex + 1];
777
- prevParagraph && prevParagraph.bullet && prevParagraph.bullet.listType.indexOf(listType) === 0 ? listId = prevParagraph.bullet.listId : nextParagraph && nextParagraph.bullet && nextParagraph.bullet.listType.indexOf(listType) === 0 && (listId = nextParagraph.bullet.listId);
778
- const doMutation = {
779
- id: RichTextEditingMutation.id,
780
- params: {
781
- unitId: docDataModel.getUnitId(),
782
- actions: [],
783
- textRanges: [{
784
- startOffset: paragraphStart,
785
- endOffset: paragraphStart,
786
- collapsed: !0
787
- }]
788
- }
789
- };
790
- textX.push({
791
- t: TextXActionType.RETAIN,
792
- len: paragraphStart
793
- }), textX.push({
794
- t: TextXActionType.DELETE,
795
- len: paragraphEnd - paragraphStart,
796
- line: 1
797
- }), textX.push({
798
- t: TextXActionType.RETAIN,
799
- len: 1,
800
- body: {
801
- dataStream: "",
802
- paragraphs: [
803
- {
804
- startIndex: 0,
805
- paragraphStyle: {
806
- ...paragraphStyle,
807
- textStyle: {
808
- ...paragraphStyle.textStyle,
809
- ...bulletParagraphTextStyle
810
- },
811
- indentFirstLine: void 0,
812
- hanging: listHanging,
813
- indentStart: { v: getNumberUnitValue(listIndentStart, charSpaceApply) - getNumberUnitValue(listHanging, charSpaceApply) + getNumberUnitValue(indentFirstLine, charSpaceApply) + getNumberUnitValue(indentStart, charSpaceApply) }
814
- },
815
- bullet: {
816
- ...(_e = paragraph.bullet) != null ? _e : {
817
- nestingLevel: 0,
818
- textStyle: {
819
- fs: 20
820
- }
821
- },
822
- listType,
823
- listId
824
- }
825
- }
826
- ]
827
- }
828
- });
829
- const path = getRichTextEditPath(docDataModel, segmentId);
830
- return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
831
- }
832
- };
833
- function getParagraphsInRange$1(activeRange, paragraphs) {
834
- const { startOffset, endOffset } = activeRange, results = [];
835
- let start = -1;
836
- for (const paragraph of paragraphs) {
837
- const { startIndex } = paragraph;
838
- (startOffset > start && startOffset <= startIndex || endOffset > start && endOffset <= startIndex || startIndex >= startOffset && startIndex <= endOffset) && results.push(paragraph), start = startIndex;
839
- }
840
- return results;
841
- }
842
- __name(getParagraphsInRange$1, "getParagraphsInRange$1");
843
- function getParagraphsRelative(ranges, paragraphs) {
844
- const selectionParagraphs = getParagraphsInRanges(ranges, paragraphs), startIndex = paragraphs.indexOf(selectionParagraphs[0]), endIndex = paragraphs.indexOf(selectionParagraphs[selectionParagraphs.length - 1]);
845
- if (selectionParagraphs[0].bullet)
846
- for (let i = startIndex - 1; i >= 0; i--) {
847
- const prevParagraph = paragraphs[i];
848
- prevParagraph.bullet && prevParagraph.bullet.listId === selectionParagraphs[0].bullet.listId && selectionParagraphs.unshift(prevParagraph);
849
- }
850
- const lastParagraph = selectionParagraphs[selectionParagraphs.length - 1];
851
- if (lastParagraph.bullet)
852
- for (let i = endIndex + 1; i < paragraphs.length; i++) {
853
- const nextParagraph = paragraphs[i];
854
- nextParagraph.bullet && nextParagraph.bullet.listId === lastParagraph.bullet.listId && selectionParagraphs.push(nextParagraph);
855
- }
856
- return selectionParagraphs;
857
- }
858
- __name(getParagraphsRelative, "getParagraphsRelative");
859
- function getParagraphsInRanges(ranges, paragraphs) {
860
- const results = [];
861
- for (const range of ranges) {
862
- const ps = getParagraphsInRange$1(range, paragraphs);
863
- results.push(...ps);
864
- }
865
- return results;
866
- }
867
- __name(getParagraphsInRanges, "getParagraphsInRanges");
868
- function findNearestSectionBreak(currentIndex, sectionBreaks) {
869
- const sortedSectionBreaks = sectionBreaks.sort(sortRulesFactory("startIndex"));
870
- for (let i = 0; i < sortedSectionBreaks.length; i++) {
871
- const sectionBreak = sectionBreaks[i];
872
- if (sectionBreak.startIndex >= currentIndex)
873
- return sectionBreak;
874
- }
875
- }
876
- __name(findNearestSectionBreak, "findNearestSectionBreak");
877
- function isCustomRangeSplitSymbol(text) {
878
- return text === DataStreamTreeTokenType.CUSTOM_RANGE_END || text === DataStreamTreeTokenType.CUSTOM_RANGE_START;
879
- }
880
- __name(isCustomRangeSplitSymbol, "isCustomRangeSplitSymbol");
881
- function isIntersecting(line1Start, line1End, line2Start, line2End) {
882
- return line1Start <= line2Start && line1End >= line2Start || line1Start >= line2Start && line1Start <= line2End;
883
- }
884
- __name(isIntersecting, "isIntersecting");
885
- function shouldDeleteCustomRange(deleteStart, deleteLen, customRange, dataStream) {
886
- const dataStreamSlice = dataStream.slice(customRange.startIndex + 1, customRange.endIndex), start = Math.max(deleteStart - (customRange.startIndex + 1), 0), end = deleteStart + deleteLen - 1 - (customRange.startIndex + 1);
887
- if (end < 0)
888
- return !1;
889
- if (start === 0 && end >= dataStreamSlice.length)
890
- return !0;
891
- const result = dataStreamSlice.slice(0, start) + dataStreamSlice.slice(start + deleteLen);
892
- for (let i = 0, len = result.length; i < len; i++) {
893
- const letter = result[i];
894
- if (!isCustomRangeSplitSymbol(letter))
895
- return !1;
896
- }
897
- return !0;
898
- }
899
- __name(shouldDeleteCustomRange, "shouldDeleteCustomRange");
900
- function getCustomRangesInterestsWithRange(range, customRanges) {
901
- const result = [];
902
- for (let i = 0, len = customRanges.length; i < len; i++) {
903
- const customRange = customRanges[i];
904
- range.collapsed ? customRange.startIndex < range.startOffset && range.startOffset <= customRange.endIndex && result.push(customRange) : isIntersecting(range.startOffset, range.endOffset, customRange.startIndex, customRange.endIndex) && result.push(customRange);
905
- }
906
- return result;
907
- }
908
- __name(getCustomRangesInterestsWithRange, "getCustomRangesInterestsWithRange");
909
- function copyCustomRange(range) {
910
- return {
911
- ...Tools.deepClone(range),
912
- rangeId: generateRandomId()
913
- };
914
- }
915
- __name(copyCustomRange, "copyCustomRange");
916
- var DeleteDirection = /* @__PURE__ */ ((DeleteDirection2) => (DeleteDirection2[DeleteDirection2.LEFT = 0] = "LEFT", DeleteDirection2[DeleteDirection2.RIGHT = 1] = "RIGHT", DeleteDirection2))(DeleteDirection || {});
917
- function makeSelection(startOffset, endOffset) {
918
- if (typeof endOffset > "u")
919
- return { startOffset, endOffset: startOffset, collapsed: !0 };
920
- if (endOffset < startOffset)
921
- throw new Error(`Cannot make a doc selection when endOffset ${endOffset} is less than startOffset ${startOffset}.`);
922
- return { startOffset, endOffset, collapsed: startOffset === endOffset };
923
- }
924
- __name(makeSelection, "makeSelection");
925
- function normalizeSelection(selection) {
926
- const { startOffset, endOffset, collapsed } = selection, start = Math.min(startOffset, endOffset), end = Math.max(startOffset, endOffset);
927
- return {
928
- startOffset: start,
929
- endOffset: end,
930
- collapsed
931
- };
932
- }
933
- __name(normalizeSelection, "normalizeSelection");
934
- function getSelectionWithSymbolMax(selection, body) {
935
- let { startOffset, endOffset } = normalizeSelection(selection);
936
- for (; body.dataStream[startOffset - 1] === DataStreamTreeTokenType.CUSTOM_RANGE_START; )
937
- startOffset -= 1;
938
- for (; body.dataStream[endOffset] === DataStreamTreeTokenType.CUSTOM_RANGE_END; )
939
- endOffset += 1;
940
- return {
941
- startOffset,
942
- endOffset
943
- };
944
- }
945
- __name(getSelectionWithSymbolMax, "getSelectionWithSymbolMax");
946
- function getDeleteSelection(selection, body, direction = DeleteDirection.LEFT) {
947
- var _a11;
948
- let { startOffset, endOffset, collapsed } = normalizeSelection(selection);
949
- if (collapsed)
950
- if (direction === DeleteDirection.LEFT)
951
- for (; isCustomRangeSplitSymbol(body.dataStream[startOffset - 1]); )
952
- endOffset -= 1, startOffset -= 1;
953
- else
954
- for (; isCustomRangeSplitSymbol(body.dataStream[startOffset]); )
955
- endOffset += 1, startOffset += 1;
956
- else {
957
- const selectionWithSymbolMax = getSelectionWithSymbolMax(selection, body);
958
- startOffset = selectionWithSymbolMax.startOffset, endOffset = selectionWithSymbolMax.endOffset;
959
- }
960
- collapsed = startOffset === endOffset;
961
- const customRanges = (_a11 = body.customRanges) == null ? void 0 : _a11.filter((range) => !range.wholeEntity || startOffset <= range.startIndex && endOffset > range.endIndex ? !1 : isSegmentIntersects(startOffset, collapsed ? endOffset : endOffset - 1, range.startIndex, range.endIndex));
962
- return customRanges != null && customRanges.length && customRanges.forEach((range) => {
963
- startOffset = Math.min(range.startIndex, startOffset), endOffset = Math.max(range.endIndex + 1, endOffset);
964
- }), {
965
- ...selection,
966
- startOffset,
967
- endOffset,
968
- collapsed: startOffset === endOffset
969
- };
970
- }
971
- __name(getDeleteSelection, "getDeleteSelection");
972
- function getInsertSelection(selection, body) {
973
- let { startOffset, endOffset, collapsed } = normalizeSelection(selection);
974
- if (collapsed) {
975
- for (; body.dataStream[endOffset] === DataStreamTreeTokenType.CUSTOM_RANGE_END; )
976
- endOffset += 1, startOffset += 1;
977
- for (; body.dataStream[endOffset - 1] === DataStreamTreeTokenType.CUSTOM_RANGE_START; )
978
- endOffset -= 1, startOffset -= 1;
979
- return {
980
- ...selection,
981
- startOffset,
982
- endOffset,
983
- collapsed
984
- };
985
- } else
986
- return {
987
- ...selection,
988
- ...getSelectionWithSymbolMax(selection, body),
989
- collapsed: !1
990
- };
991
- }
992
- __name(getInsertSelection, "getInsertSelection");
993
- function getSelectionForAddCustomRange(selection, body) {
994
- if (selection.startOffset === selection.endOffset)
995
- return null;
996
- const customRanges = body.customRanges;
997
- if (!customRanges)
998
- return normalizeSelection(selection);
999
- let { startOffset, endOffset } = getSelectionWithSymbolMax(selection, body);
1000
- for (; isCustomRangeSplitSymbol(body.dataStream[startOffset]); ) {
1001
- if (body.dataStream[startOffset] === DataStreamTreeTokenType.CUSTOM_RANGE_START) {
1002
- const customRange = customRanges.find((range) => range.startIndex === startOffset);
1003
- if (!customRange)
1004
- throw new Error("No custom-range matched");
1005
- if (customRange.endIndex === endOffset - 1)
1006
- return {
1007
- startOffset,
1008
- endOffset,
1009
- collapsed: !1
1010
- };
1011
- if (customRange.endIndex < endOffset - 1)
1012
- break;
1013
- }
1014
- startOffset += 1;
1015
- }
1016
- for (; isCustomRangeSplitSymbol(body.dataStream[endOffset - 1]); ) {
1017
- if (body.dataStream[startOffset] === DataStreamTreeTokenType.CUSTOM_RANGE_END) {
1018
- const customRange = customRanges.find((range) => range.endIndex === endOffset - 1);
1019
- if (!customRange)
1020
- throw new Error("No custom-range matched");
1021
- if (customRange.startIndex === startOffset)
1022
- return {
1023
- startOffset,
1024
- endOffset,
1025
- collapsed: !1
1026
- };
1027
- if (customRange.startIndex > startOffset)
1028
- break;
1029
- }
1030
- endOffset -= 1;
1031
- }
1032
- return endOffset <= startOffset ? null : {
1033
- startOffset,
1034
- endOffset,
1035
- collapsed: !1
1036
- };
1037
- }
1038
- __name(getSelectionForAddCustomRange, "getSelectionForAddCustomRange");
1039
- const tags = [
1040
- DataStreamTreeTokenType.PARAGRAPH,
1041
- // 段落
1042
- DataStreamTreeTokenType.SECTION_BREAK,
1043
- // 章节
1044
- DataStreamTreeTokenType.TABLE_START,
1045
- // 表格开始
1046
- DataStreamTreeTokenType.TABLE_ROW_START,
1047
- // 表格开始
1048
- DataStreamTreeTokenType.TABLE_CELL_START,
1049
- // 表格开始
1050
- DataStreamTreeTokenType.TABLE_CELL_END,
1051
- // 表格开始
1052
- DataStreamTreeTokenType.TABLE_ROW_END,
1053
- // 表格开始
1054
- DataStreamTreeTokenType.TABLE_END,
1055
- // 表格结束
1056
- DataStreamTreeTokenType.CUSTOM_RANGE_START,
1057
- // 自定义范围开始
1058
- DataStreamTreeTokenType.CUSTOM_RANGE_END,
1059
- // 自定义范围结束
1060
- DataStreamTreeTokenType.COLUMN_BREAK,
1061
- // 换列
1062
- DataStreamTreeTokenType.PAGE_BREAK,
1063
- // 换页
1064
- DataStreamTreeTokenType.DOCS_END,
1065
- // 文档结尾
1066
- DataStreamTreeTokenType.TAB,
1067
- // 制表符
1068
- DataStreamTreeTokenType.CUSTOM_BLOCK
1069
- // 图片 mention 等不参与文档流的场景
1070
- ];
1071
- function getSelectionText(dataStream, start, end) {
1072
- const text = dataStream.slice(start, end);
1073
- return tags.reduce((res, curr) => res.replaceAll(curr, ""), text);
1074
- }
1075
- __name(getSelectionText, "getSelectionText");
1076
- function isSegmentIntersects(start, end, start2, end2) {
1077
- return Math.max(start, start2) <= Math.min(end, end2);
1078
- }
1079
- __name(isSegmentIntersects, "isSegmentIntersects");
1080
- function getRetainAndDeleteAndExcludeLineBreak(selection, body, segmentId = "", memoryCursor = 0, preserveLineBreak = !0) {
1081
- var _a11;
1082
- const { startOffset, endOffset } = getDeleteSelection(selection, body), dos = [], { paragraphs = [], dataStream } = body, textStart = startOffset - memoryCursor, textEnd = endOffset - memoryCursor, paragraphInRange = paragraphs == null ? void 0 : paragraphs.find(
1083
- (p) => p.startIndex - memoryCursor >= textStart && p.startIndex - memoryCursor < textEnd
1084
- ), relativeCustomRanges = (_a11 = body.customRanges) == null ? void 0 : _a11.filter((customRange) => isIntersecting(customRange.startIndex, customRange.endIndex, startOffset, endOffset)), toDeleteRanges = new Set(relativeCustomRanges == null ? void 0 : relativeCustomRanges.filter((customRange) => shouldDeleteCustomRange(startOffset, endOffset - startOffset, customRange, dataStream))), retainPoints = /* @__PURE__ */ new Set();
1085
- if (relativeCustomRanges == null || relativeCustomRanges.forEach((range) => {
1086
- toDeleteRanges.has(range) || (range.startIndex - memoryCursor >= textStart && range.startIndex - memoryCursor <= textEnd && range.endIndex - memoryCursor > textEnd && retainPoints.add(range.startIndex), range.endIndex - memoryCursor >= textStart && range.endIndex - memoryCursor <= textEnd && range.startIndex < textStart && retainPoints.add(range.endIndex));
1087
- }), textStart > 0 && dos.push({
1088
- t: TextXActionType.RETAIN,
1089
- len: textStart,
1090
- segmentId
1091
- }), preserveLineBreak && paragraphInRange && paragraphInRange.startIndex - memoryCursor > textStart) {
1092
- const paragraphIndex = paragraphInRange.startIndex - memoryCursor;
1093
- retainPoints.add(paragraphIndex);
1094
- }
1095
- const sortedRetains = [...retainPoints].sort((pre, aft) => pre - aft);
1096
- let cursor = textStart;
1097
- return sortedRetains.forEach((pos) => {
1098
- const len = pos - cursor;
1099
- len > 0 && dos.push({
1100
- t: TextXActionType.DELETE,
1101
- len,
1102
- line: 0,
1103
- segmentId
1104
- }), dos.push({
1105
- t: TextXActionType.RETAIN,
1106
- len: 1,
1107
- segmentId
1108
- }), cursor = pos + 1;
1109
- }), cursor < textEnd && dos.push({
1110
- t: TextXActionType.DELETE,
1111
- len: textEnd - cursor,
1112
- line: 0,
1113
- segmentId
1114
- }), dos;
1115
- }
1116
- __name(getRetainAndDeleteAndExcludeLineBreak, "getRetainAndDeleteAndExcludeLineBreak");
1117
- function replaceSelectionFactory(accessor, params) {
1118
- var _a11, _b, _c, _d;
1119
- const { unitId, originBody, body: insertBody } = params, docDataModel = accessor.get(IUniverInstanceService).getUnit(unitId);
1120
- if (!docDataModel)
1121
- return !1;
1122
- const segmentId = (_a11 = params.selection) == null ? void 0 : _a11.segmentId;
1123
- let body;
1124
- if (params.originBody ? body = originBody : body = (_b = docDataModel.getSelfOrHeaderFooterModel(segmentId)) == null ? void 0 : _b.getBody(), !body) return !1;
1125
- const textSelectionManagerService = accessor.get(TextSelectionManagerService), selection = (_c = params.selection) != null ? _c : textSelectionManagerService.getActiveTextRangeWithStyle();
1126
- if (!selection || !body)
1127
- return !1;
1128
- const textRanges = (_d = params.textRanges) != null ? _d : [{
1129
- startOffset: selection.startOffset + insertBody.dataStream.length,
1130
- endOffset: selection.startOffset + insertBody.dataStream.length,
1131
- collapsed: !0,
1132
- segmentId
1133
- }], doMutation = {
1134
- id: RichTextEditingMutation.id,
1135
- params: {
1136
- unitId,
1137
- actions: [],
1138
- textRanges,
1139
- debounce: !0,
1140
- segmentId
1141
- }
1142
- }, textX = new TextX(), jsonX = JSONX.getInstance();
1143
- textX.push(...getRetainAndDeleteAndExcludeLineBreak(selection, body, segmentId)), textX.push({
1144
- t: TextXActionType.INSERT,
1145
- body: insertBody,
1146
- len: insertBody.dataStream.length,
1147
- line: 0,
1148
- segmentId
1149
- });
1150
- const path = getRichTextEditPath(docDataModel, segmentId);
1151
- return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), doMutation;
1152
- }
1153
- __name(replaceSelectionFactory, "replaceSelectionFactory");
1154
- var DOCS_VIEW_KEY = /* @__PURE__ */ ((DOCS_VIEW_KEY2) => (DOCS_VIEW_KEY2.MAIN = "__Document_Render_Main__", DOCS_VIEW_KEY2.BACKGROUND = "__Document_Render_Background__", DOCS_VIEW_KEY2))(DOCS_VIEW_KEY || {}), VIEWPORT_KEY = /* @__PURE__ */ ((VIEWPORT_KEY2) => (VIEWPORT_KEY2.VIEW_MAIN = "viewMain", VIEWPORT_KEY2.VIEW_TOP = "viewTop", VIEWPORT_KEY2.VIEW_LEFT = "viewLeft", VIEWPORT_KEY2.VIEW_LEFT_TOP = "viewLeftTop", VIEWPORT_KEY2))(VIEWPORT_KEY || {});
1155
- const DOCS_COMPONENT_BACKGROUND_LAYER_INDEX = 0, DOCS_COMPONENT_MAIN_LAYER_INDEX = 2, DOCS_COMPONENT_HEADER_LAYER_INDEX = 4, DOCS_COMPONENT_DEFAULT_Z_INDEX = 10, NORMAL_TEXT_SELECTION_PLUGIN_NAME = "normalTextSelectionPluginName";
1156
- function neoGetDocObject(renderContext) {
1157
- const { mainComponent, scene, engine, components } = renderContext, document = mainComponent, docBackground = components.get(DOCS_VIEW_KEY.BACKGROUND);
1158
- return {
1159
- document,
1160
- docBackground,
1161
- scene,
1162
- engine
1163
- };
1164
- }
1165
- __name(neoGetDocObject, "neoGetDocObject");
1166
- function getDocObject(univerInstanceService, renderManagerService) {
1167
- const documentModel = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
1168
- if (!documentModel)
1169
- return null;
1170
- const unitId = documentModel.getUnitId(), currentRender = renderManagerService.getRenderById(unitId);
1171
- if (currentRender == null)
1172
- return;
1173
- const { mainComponent, scene, engine, components } = currentRender, document = mainComponent, docBackground = components.get(DOCS_VIEW_KEY.BACKGROUND);
1174
- return {
1175
- document,
1176
- docBackground,
1177
- scene,
1178
- engine
1179
- };
1180
- }
1181
- __name(getDocObject, "getDocObject");
1182
- function getDocObjectById(unitId, renderManagerService) {
1183
- const currentRender = renderManagerService.getRenderById(unitId);
1184
- if (currentRender == null)
1185
- return;
1186
- const { mainComponent, scene, engine, components } = currentRender, document = mainComponent, docBackground = components.get(DOCS_VIEW_KEY.BACKGROUND);
1187
- return {
1188
- document,
1189
- docBackground,
1190
- scene,
1191
- engine
1192
- };
1193
- }
1194
- __name(getDocObjectById, "getDocObjectById");
1195
- function getRetainAndDeleteFromReplace(range, segmentId = "", memoryCursor, body) {
1196
- var _a11;
1197
- const { startOffset, endOffset } = range, dos = [], textStart = startOffset - memoryCursor, textEnd = endOffset - memoryCursor, dataStream = body.dataStream, relativeCustomRanges = (_a11 = body.customRanges) == null ? void 0 : _a11.filter((customRange) => isIntersecting(customRange.startIndex, customRange.endIndex, startOffset, endOffset)), toDeleteRanges = new Set(relativeCustomRanges == null ? void 0 : relativeCustomRanges.filter((customRange) => shouldDeleteCustomRange(startOffset, endOffset - startOffset, customRange, dataStream))), retainPoints = /* @__PURE__ */ new Set();
1198
- relativeCustomRanges == null || relativeCustomRanges.forEach((range2) => {
1199
- toDeleteRanges.has(range2) || (range2.startIndex - memoryCursor >= textStart && range2.startIndex - memoryCursor <= textEnd && range2.endIndex - memoryCursor > textEnd && retainPoints.add(range2.startIndex), range2.endIndex - memoryCursor >= textStart && range2.endIndex - memoryCursor <= textEnd && range2.startIndex < textStart && retainPoints.add(range2.endIndex));
1200
- }), textStart > 0 && dos.push({
1201
- t: TextXActionType.RETAIN,
1202
- len: textStart,
1203
- segmentId
1204
- });
1205
- const sortedRetains = [...retainPoints].sort((pre, aft) => pre - aft);
1206
- let cursor = textStart;
1207
- return sortedRetains.forEach((pos) => {
1208
- const len = pos - cursor;
1209
- len > 0 && dos.push({
1210
- t: TextXActionType.DELETE,
1211
- len,
1212
- line: 0,
1213
- segmentId
1214
- }), dos.push({
1215
- t: TextXActionType.RETAIN,
1216
- len: 1,
1217
- segmentId
1218
- }), cursor = pos + 1;
1219
- }), cursor < textEnd && (dos.push({
1220
- t: TextXActionType.DELETE,
1221
- len: textEnd - cursor,
1222
- line: 0,
1223
- segmentId
1224
- }), cursor = textEnd + 1), {
1225
- dos,
1226
- cursor,
1227
- retain: retainPoints.size
1228
- };
1229
- }
1230
- __name(getRetainAndDeleteFromReplace, "getRetainAndDeleteFromReplace");
1231
- const EditorInsertTextCommandId = "doc.command.insert-text", InsertCommand = {
1232
- id: EditorInsertTextCommandId,
1233
- type: CommandType.COMMAND,
1234
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
1235
- var _a11;
1236
- const commandService = accessor.get(ICommandService), { range, segmentId, body, unitId, cursorOffset } = params, textSelectionManagerService = accessor.get(TextSelectionManagerService), docDataModel = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
1237
- if (docDataModel == null)
1238
- return !1;
1239
- const activeRange = textSelectionManagerService.getActiveTextRangeWithStyle(), originBody = docDataModel.getSelfOrHeaderFooterModel((_a11 = activeRange == null ? void 0 : activeRange.segmentId) != null ? _a11 : "").getBody();
1240
- if (!originBody)
1241
- return !1;
1242
- const actualRange = getInsertSelection(range, originBody), { startOffset, collapsed } = actualRange, cursorMove = cursorOffset != null ? cursorOffset : body.dataStream.length, textRanges = [
1243
- {
1244
- startOffset: startOffset + cursorMove,
1245
- endOffset: startOffset + cursorMove,
1246
- style: activeRange == null ? void 0 : activeRange.style,
1247
- collapsed
1248
- }
1249
- ], doMutation = {
1250
- id: RichTextEditingMutation.id,
1251
- params: {
1252
- unitId,
1253
- actions: [],
1254
- textRanges,
1255
- debounce: !0
1256
- }
1257
- }, textX = new TextX(), jsonX = JSONX.getInstance();
1258
- if (collapsed)
1259
- startOffset > 0 && textX.push({
1260
- t: TextXActionType.RETAIN,
1261
- len: startOffset,
1262
- segmentId
1263
- });
1264
- else {
1265
- const { dos, retain } = getRetainAndDeleteFromReplace(actualRange, segmentId, 0, originBody);
1266
- textX.push(...dos), doMutation.params.textRanges = [{
1267
- startOffset: startOffset + cursorMove + retain,
1268
- endOffset: startOffset + cursorMove + retain,
1269
- collapsed
1270
- }];
1271
- }
1272
- textX.push({
1273
- t: TextXActionType.INSERT,
1274
- body,
1275
- len: body.dataStream.length,
1276
- line: 0,
1277
- segmentId
1278
- });
1279
- const path = getRichTextEditPath(docDataModel, segmentId);
1280
- return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
1281
- }, "handler")
1282
- }, DeleteCommand = {
1283
- id: "doc.command.delete-text",
1284
- type: CommandType.COMMAND,
1285
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
1286
- var _a11;
1287
- const commandService = accessor.get(ICommandService), univerInstanceService = accessor.get(IUniverInstanceService), { range, segmentId, unitId, direction, len = 1 } = params, docDataModel = univerInstanceService.getUnit(unitId, UniverInstanceType.UNIVER_DOC), body = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
1288
- if (docDataModel == null || body == null)
1289
- return !1;
1290
- const { startOffset } = range, dataStream = body.dataStream, start = direction === DeleteDirection.LEFT ? startOffset - len : startOffset, end = start + len - 1, relativeCustomRanges = (_a11 = body.customRanges) == null ? void 0 : _a11.filter((customRange) => isIntersecting(customRange.startIndex, customRange.endIndex, start, end)), toDeleteRanges = relativeCustomRanges == null ? void 0 : relativeCustomRanges.filter((customRange) => shouldDeleteCustomRange(start, len, customRange, dataStream)), deleteIndexes = [];
1291
- for (let i = 0; i < len; i++)
1292
- deleteIndexes.push(start + i);
1293
- toDeleteRanges == null || toDeleteRanges.forEach((range2) => {
1294
- deleteIndexes.push(range2.startIndex, range2.endIndex);
1295
- }), deleteIndexes.sort((pre, aft) => pre - aft);
1296
- const deleteStart = deleteIndexes[0], doMutation = {
1297
- id: RichTextEditingMutation.id,
1298
- params: {
1299
- unitId,
1300
- actions: [],
1301
- textRanges: [{
1302
- startOffset: deleteStart,
1303
- endOffset: deleteStart,
1304
- collapsed: !0
1305
- }],
1306
- debounce: !0
1307
- }
1308
- }, textX = new TextX(), jsonX = JSONX.getInstance();
1309
- let cursor = 0;
1310
- for (let i = 0; i < deleteIndexes.length; i++) {
1311
- const deleteIndex = deleteIndexes[i];
1312
- deleteIndex - cursor > 0 && textX.push({
1313
- t: TextXActionType.RETAIN,
1314
- len: deleteIndex - cursor,
1315
- segmentId
1316
- }), textX.push({
1317
- t: TextXActionType.DELETE,
1318
- len: 1,
1319
- segmentId,
1320
- line: 0
1321
- }), cursor = deleteIndex + 1;
1322
- }
1323
- const path = getRichTextEditPath(docDataModel, segmentId);
1324
- return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
1325
- }, "handler")
1326
- }, UpdateCommand = {
1327
- id: "doc.command.update-text",
1328
- type: CommandType.COMMAND,
1329
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
1330
- const { range, segmentId, updateBody, coverType, unitId, textRanges } = params, commandService = accessor.get(ICommandService), docDataModel = accessor.get(IUniverInstanceService).getCurrentUniverDocInstance();
1331
- if (docDataModel == null)
1332
- return !1;
1333
- const doMutation = {
1334
- id: RichTextEditingMutation.id,
1335
- params: {
1336
- unitId,
1337
- actions: [],
1338
- textRanges
1339
- }
1340
- }, textX = new TextX(), jsonX = JSONX.getInstance(), { startOffset, endOffset } = range;
1341
- textX.push({
1342
- t: TextXActionType.RETAIN,
1343
- len: startOffset,
1344
- segmentId
1345
- }), textX.push({
1346
- t: TextXActionType.RETAIN,
1347
- body: updateBody,
1348
- len: endOffset - startOffset,
1349
- segmentId,
1350
- coverType
1351
- });
1352
- const path = getRichTextEditPath(docDataModel, segmentId);
1353
- return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
1354
- }, "handler")
1355
- };
1356
- function generateParagraphs(dataStream, prevParagraph) {
1357
- var _a11, _b;
1358
- const paragraphs = [];
1359
- for (let i = 0, len = dataStream.length; i < len; i++)
1360
- dataStream[i] === DataStreamTreeTokenType.PARAGRAPH && paragraphs.push({
1361
- startIndex: i
1362
- });
1363
- if (prevParagraph)
1364
- for (const paragraph of paragraphs)
1365
- prevParagraph.bullet && (paragraph.bullet = Tools.deepClone(prevParagraph.bullet), paragraph.bullet.listType === PresetListType.CHECK_LIST_CHECKED && (paragraph.bullet.listType = PresetListType.CHECK_LIST)), prevParagraph.paragraphStyle && (paragraph.paragraphStyle = Tools.deepClone(prevParagraph.paragraphStyle), ((_a11 = prevParagraph.bullet) == null ? void 0 : _a11.listType) === PresetListType.CHECK_LIST_CHECKED && (_b = paragraph.paragraphStyle) != null && _b.textStyle && (paragraph.paragraphStyle.textStyle.st = {
1366
- s: BooleanNumber.FALSE
1367
- }));
1368
- return paragraphs;
1369
- }
1370
- __name(generateParagraphs, "generateParagraphs");
1371
- const BreakLineCommand = {
1372
- id: "doc.command.break-line",
1373
- type: CommandType.COMMAND,
1374
- handler: /* @__PURE__ */ __name(async (accessor) => {
1375
- var _a11, _b;
1376
- const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), activeTextRange = textSelectionManagerService.getActiveTextRangeWithStyle(), rectRanges = textSelectionManagerService.getCurrentRectRanges();
1377
- if (activeTextRange == null)
1378
- return !1;
1379
- if (rectRanges && rectRanges.length) {
1380
- const { startOffset: startOffset2 } = activeTextRange;
1381
- return textSelectionManagerService.replaceTextRanges([{
1382
- startOffset: startOffset2,
1383
- endOffset: startOffset2
1384
- }]), !0;
1385
- }
1386
- const { segmentId } = activeTextRange, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), body = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
1387
- if (!docDataModel || !body)
1388
- return !1;
1389
- const unitId = docDataModel.getUnitId(), { startOffset, endOffset } = getInsertSelection(activeTextRange, body), prevParagraph = ((_a11 = body.paragraphs) != null ? _a11 : []).find((p) => p.startIndex >= startOffset);
1390
- if (prevParagraph && prevParagraph.startIndex > endOffset) {
1391
- const bodyAfter = normalizeBody(getBodySlice(body, endOffset, prevParagraph.startIndex + 1));
1392
- bodyAfter.customRanges = (_b = bodyAfter.customRanges) == null ? void 0 : _b.map(copyCustomRange);
1393
- const deleteRange = {
1394
- startOffset,
1395
- endOffset: prevParagraph.startIndex + 1,
1396
- collapsed: !1
1397
- };
1398
- return updateAttributeByInsert(
1399
- bodyAfter,
1400
- {
1401
- dataStream: DataStreamTreeTokenType.PARAGRAPH,
1402
- paragraphs: generateParagraphs(DataStreamTreeTokenType.PARAGRAPH, prevParagraph)
1403
- },
1404
- 1,
1405
- 0
1406
- ), await commandService.executeCommand(InsertCommand.id, {
1407
- unitId,
1408
- body: bodyAfter,
1409
- range: deleteRange,
1410
- segmentId,
1411
- cursorOffset: 1
1412
- });
1413
- } else
1414
- return await commandService.executeCommand(InsertCommand.id, {
1415
- unitId,
1416
- body: {
1417
- dataStream: DataStreamTreeTokenType.PARAGRAPH,
1418
- paragraphs: generateParagraphs(DataStreamTreeTokenType.PARAGRAPH, prevParagraph)
1419
- },
1420
- range: activeTextRange,
1421
- segmentId
1422
- });
291
+ const doc = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
292
+ return doc ? (doc.setName(params.name), !0) : !1;
1423
293
  }, "handler")
1424
- };
1425
- var INSERT_ROW_POSITION = /* @__PURE__ */ ((INSERT_ROW_POSITION2) => (INSERT_ROW_POSITION2[INSERT_ROW_POSITION2.ABOVE = 0] = "ABOVE", INSERT_ROW_POSITION2[INSERT_ROW_POSITION2.BELLOW = 1] = "BELLOW", INSERT_ROW_POSITION2))(INSERT_ROW_POSITION || {}), INSERT_COLUMN_POSITION = /* @__PURE__ */ ((INSERT_COLUMN_POSITION2) => (INSERT_COLUMN_POSITION2[INSERT_COLUMN_POSITION2.LEFT = 0] = "LEFT", INSERT_COLUMN_POSITION2[INSERT_COLUMN_POSITION2.RIGHT = 1] = "RIGHT", INSERT_COLUMN_POSITION2))(INSERT_COLUMN_POSITION || {});
1426
- function genEmptyTable(rowCount, colCount) {
1427
- let dataStream = DataStreamTreeTokenType.TABLE_START;
1428
- const paragraphs = [], sectionBreaks = [];
1429
- for (let i = 0; i < rowCount; i++) {
1430
- dataStream += DataStreamTreeTokenType.TABLE_ROW_START;
1431
- for (let j = 0; j < colCount; j++)
1432
- dataStream += `${DataStreamTreeTokenType.TABLE_CELL_START}\r
1433
- ${DataStreamTreeTokenType.TABLE_CELL_END}`, paragraphs.push({
1434
- startIndex: dataStream.length - 3,
1435
- paragraphStyle: {
1436
- spaceAbove: { v: 3 },
1437
- lineSpacing: 2,
1438
- spaceBelow: { v: 0 }
1439
- }
1440
- }), sectionBreaks.push({
1441
- startIndex: dataStream.length - 2
1442
- });
1443
- dataStream += DataStreamTreeTokenType.TABLE_ROW_END;
294
+ }, PLUGIN_CONFIG_KEY = "docs.config", defaultPluginConfig = {};
295
+ var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
296
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
297
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
298
+ return kind && result && __defProp$2(target, key, result), result;
299
+ }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a3;
300
+ let DocCustomRangeController = (_a3 = class extends Disposable {
301
+ constructor(_commandService, _textSelectionManagerService, _univerInstanceService) {
302
+ super(), this._commandService = _commandService, this._textSelectionManagerService = _textSelectionManagerService, this._univerInstanceService = _univerInstanceService, this._initSelectionChange();
1444
303
  }
1445
- return dataStream += DataStreamTreeTokenType.TABLE_END, {
1446
- dataStream,
1447
- paragraphs,
1448
- sectionBreaks
1449
- };
1450
- }
1451
- __name(genEmptyTable, "genEmptyTable");
1452
- function getEmptyTableCell() {
1453
- return {
1454
- margin: {
1455
- start: {
1456
- v: 10
1457
- },
1458
- end: {
1459
- v: 10
1460
- },
1461
- top: {
1462
- v: 5
1463
- },
1464
- bottom: {
1465
- v: 5
1466
- }
1467
- }
1468
- };
1469
- }
1470
- __name(getEmptyTableCell, "getEmptyTableCell");
1471
- function getEmptyTableRow(col) {
1472
- const tableCell = getEmptyTableCell();
1473
- return {
1474
- tableCells: [...new Array(col).fill(null).map(() => Tools.deepClone(tableCell))],
1475
- trHeight: {
1476
- val: { v: 30 },
1477
- hRule: TableCellHeightRule.AUTO
1478
- }
1479
- };
1480
- }
1481
- __name(getEmptyTableRow, "getEmptyTableRow");
1482
- function getTableColumn(width) {
1483
- return {
1484
- size: {
1485
- type: TableSizeType.SPECIFIED,
1486
- width: {
1487
- v: width
1488
- }
1489
- }
1490
- };
1491
- }
1492
- __name(getTableColumn, "getTableColumn");
1493
- function genTableSource(rowCount, colCount, pageContentWidth) {
1494
- const tableColumn = getTableColumn(pageContentWidth / colCount), tableRow = getEmptyTableRow(colCount), tableRows = [...new Array(rowCount).fill(null).map(() => Tools.deepClone(tableRow))], tableColumns = [...new Array(colCount).fill(null).map(() => Tools.deepClone(tableColumn))], tableId = generateRandomId(6);
1495
- return {
1496
- tableRows,
1497
- tableColumns,
1498
- tableId,
1499
- align: TableAlignmentType.START,
1500
- indent: {
1501
- v: 0
1502
- },
1503
- textWrap: TableTextWrapType.NONE,
1504
- position: {
1505
- positionH: {
1506
- relativeFrom: ObjectRelativeFromH.PAGE,
1507
- posOffset: 0
1508
- },
1509
- positionV: {
1510
- relativeFrom: ObjectRelativeFromV.PAGE,
1511
- posOffset: 0
1512
- }
1513
- },
1514
- dist: {
1515
- distB: 0,
1516
- distL: 0,
1517
- distR: 0,
1518
- distT: 0
1519
- },
1520
- cellMargin: {
1521
- start: {
1522
- v: 10
1523
- },
1524
- end: {
1525
- v: 10
1526
- },
1527
- top: {
1528
- v: 5
1529
- },
1530
- bottom: {
1531
- v: 5
1532
- }
1533
- },
1534
- size: {
1535
- type: TableSizeType.UNSPECIFIED,
1536
- width: {
1537
- v: pageContentWidth
1538
- }
1539
- }
1540
- };
1541
- }
1542
- __name(genTableSource, "genTableSource");
1543
- function getRangeInfoFromRanges(textRange, rectRanges) {
1544
- if (!textRange && !rectRanges)
1545
- return null;
1546
- if (rectRanges && rectRanges.length > 0) {
1547
- let startOffset = Number.POSITIVE_INFINITY, endOffset = Number.NEGATIVE_INFINITY;
1548
- const segmentId = "";
1549
- for (const rectRange of rectRanges) {
1550
- const { startOffset: st, endOffset: ed, segmentId: sid } = rectRange;
1551
- st == null || ed == null || sid == null || (startOffset = Math.min(startOffset, st), endOffset = Math.max(endOffset, ed));
1552
- }
1553
- if (Number.isFinite(startOffset) && Number.isFinite(endOffset))
1554
- return {
1555
- startOffset,
1556
- endOffset,
1557
- segmentId
304
+ _transformCustomRange(doc, selection) {
305
+ var _a6;
306
+ const { startOffset, endOffset, collapsed } = selection, customRanges = (_a6 = doc.getCustomRanges()) == null ? void 0 : _a6.filter((range) => !range.wholeEntity || startOffset <= range.startIndex && endOffset > range.endIndex ? !1 : collapsed ? range.startIndex < startOffset && range.endIndex >= endOffset : BuildTextUtils.range.isIntersects(startOffset, endOffset - 1, range.startIndex, range.endIndex));
307
+ if (customRanges != null && customRanges.length) {
308
+ let start = startOffset, end = endOffset;
309
+ return customRanges.forEach((range) => {
310
+ start = Math.min(range.startIndex, start), end = Math.max(range.endIndex + 1, end);
311
+ }), {
312
+ ...selection,
313
+ startOffset: start,
314
+ endOffset: end,
315
+ collapsed: start === end
1558
316
  };
1559
- } else if (textRange) {
1560
- const { startOffset, endOffset, segmentId } = textRange;
1561
- return startOffset == null || endOffset == null || segmentId == null ? null : {
1562
- startOffset,
1563
- endOffset,
1564
- segmentId
1565
- };
1566
- }
1567
- }
1568
- __name(getRangeInfoFromRanges, "getRangeInfoFromRanges");
1569
- function getInsertRowBody(col) {
1570
- let dataStream = DataStreamTreeTokenType.TABLE_ROW_START;
1571
- const paragraphs = [], sectionBreaks = [];
1572
- for (let i = 0; i < col; i++)
1573
- dataStream += `${DataStreamTreeTokenType.TABLE_CELL_START}\r
1574
- ${DataStreamTreeTokenType.TABLE_CELL_END}`, paragraphs.push({
1575
- startIndex: dataStream.length - 3,
1576
- paragraphStyle: {
1577
- spaceAbove: { v: 3 },
1578
- lineSpacing: 2,
1579
- spaceBelow: { v: 0 }
1580
- }
1581
- }), sectionBreaks.push({
1582
- startIndex: dataStream.length - 2
1583
- });
1584
- return dataStream += DataStreamTreeTokenType.TABLE_ROW_END, {
1585
- dataStream,
1586
- paragraphs,
1587
- sectionBreaks
1588
- };
1589
- }
1590
- __name(getInsertRowBody, "getInsertRowBody");
1591
- function getInsertColumnBody() {
1592
- const dataStream = `${DataStreamTreeTokenType.TABLE_CELL_START}\r
1593
- ${DataStreamTreeTokenType.TABLE_CELL_END}`, paragraphs = [], sectionBreaks = [];
1594
- return paragraphs.push({
1595
- startIndex: 1,
1596
- paragraphStyle: {
1597
- spaceAbove: { v: 3 },
1598
- lineSpacing: 2,
1599
- spaceBelow: { v: 0 }
1600
- }
1601
- }), sectionBreaks.push({
1602
- startIndex: 2
1603
- }), {
1604
- dataStream,
1605
- paragraphs,
1606
- sectionBreaks
1607
- };
1608
- }
1609
- __name(getInsertColumnBody, "getInsertColumnBody");
1610
- function getInsertRowActionsParams(rangeInfo, position, viewModel) {
1611
- var _a11, _b, _c;
1612
- const { startOffset, endOffset, segmentId } = rangeInfo, vm = viewModel.getSelfOrHeaderFooterViewModel(segmentId), index = position === 0 ? startOffset : endOffset;
1613
- let tableRow = null;
1614
- const tableId = (_c = (_b = (_a11 = viewModel.getBody()) == null ? void 0 : _a11.tables) == null ? void 0 : _b.find((t) => index >= t.startIndex && index <= t.endIndex)) == null ? void 0 : _c.tableId;
1615
- let rowIndex = 0;
1616
- for (const section of vm.children) {
1617
- for (const paragraph of section.children) {
1618
- const { children } = paragraph, table = children[0];
1619
- if (table) {
1620
- for (const row of table.children)
1621
- if (row.startIndex <= index && index <= row.endIndex) {
1622
- rowIndex = table.children.indexOf(row), tableRow = row;
1623
- break;
1624
- }
1625
- }
1626
- if (tableRow)
1627
- break;
1628
317
  }
1629
- if (tableRow)
1630
- break;
318
+ return selection;
1631
319
  }
1632
- return tableRow == null || tableId == null ? null : {
1633
- offset: position === 0 ? tableRow.startIndex : tableRow.endIndex + 1,
1634
- colCount: tableRow.children.length,
1635
- tableId,
1636
- insertRowIndex: position === 0 ? rowIndex : rowIndex + 1
1637
- };
1638
- }
1639
- __name(getInsertRowActionsParams, "getInsertRowActionsParams");
1640
- function getInsertColumnActionsParams(rangeInfo, position, viewModel) {
1641
- var _a11, _b, _c;
1642
- const { startOffset, endOffset, segmentId } = rangeInfo, vm = viewModel.getSelfOrHeaderFooterViewModel(segmentId), index = position === 0 ? startOffset : endOffset, tableId = (_c = (_b = (_a11 = viewModel.getBody()) == null ? void 0 : _a11.tables) == null ? void 0 : _b.find((t) => index >= t.startIndex && index <= t.endIndex)) == null ? void 0 : _c.tableId, offsets = [];
1643
- let table = null, columnIndex = -1;
1644
- for (const section of vm.children) {
1645
- for (const paragraph of section.children) {
1646
- const { children } = paragraph, tableNode = children[0];
1647
- if (tableNode) {
1648
- if (index < tableNode.startIndex || index > tableNode.endIndex)
1649
- continue;
1650
- table = tableNode;
1651
- for (const row of tableNode.children) {
1652
- for (const cell of row.children) {
1653
- const cellIndex = row.children.indexOf(cell);
1654
- if (index >= cell.startIndex && index <= cell.endIndex) {
1655
- columnIndex = cellIndex;
1656
- break;
1657
- }
1658
- }
1659
- if (columnIndex !== -1)
1660
- break;
1661
- }
320
+ _initSelectionChange() {
321
+ this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
322
+ if (commandInfo.id === SetTextSelectionsOperation.id) {
323
+ const params = commandInfo.params, { unitId, ranges, isEditing } = params, doc = this._univerInstanceService.getUnit(unitId);
324
+ if (!doc)
325
+ return;
326
+ const transformedRanges = ranges.map((range) => this._transformCustomRange(doc, range));
327
+ transformedRanges.some((range, i) => ranges[i] !== range) && this._textSelectionManagerService.replaceTextRanges(transformedRanges, isEditing);
1662
328
  }
1663
- if (table)
1664
- break;
1665
- }
1666
- if (table)
1667
- break;
329
+ }));
1668
330
  }
1669
- if (table == null || tableId == null || columnIndex === -1)
1670
- return null;
1671
- let cursor = 0;
1672
- for (const row of table.children) {
1673
- const cell = row.children[columnIndex], insertIndex = position === 0 ? cell.startIndex : cell.endIndex + 1;
1674
- offsets.push(insertIndex - cursor), cursor = insertIndex;
331
+ }, __name(_a3, "DocCustomRangeController"), _a3);
332
+ DocCustomRangeController = __decorateClass$2([
333
+ OnLifecycle(LifecycleStages.Ready, DocCustomRangeController),
334
+ __decorateParam$2(0, ICommandService),
335
+ __decorateParam$2(1, Inject(DocSelectionManagerService)),
336
+ __decorateParam$2(2, IUniverInstanceService)
337
+ ], DocCustomRangeController);
338
+ var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
339
+ for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
340
+ (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
341
+ return kind && result && __defProp$1(target, key, result), result;
342
+ }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1");
343
+ const PLUGIN_NAME = "DOCS_PLUGIN";
344
+ var _a4;
345
+ let UniverDocsPlugin = (_a4 = class extends Plugin {
346
+ constructor(_config = defaultPluginConfig, _injector, _configService) {
347
+ super(), this._config = _config, this._injector = _injector, this._configService = _configService;
348
+ const { ...rest } = this._config;
349
+ this._configService.setConfig(PLUGIN_CONFIG_KEY, rest), this._initializeDependencies(_injector), this._initializeCommands();
1675
350
  }
1676
- return {
1677
- offsets,
1678
- tableId,
1679
- columnIndex,
1680
- rowCount: table.children.length
1681
- };
1682
- }
1683
- __name(getInsertColumnActionsParams, "getInsertColumnActionsParams");
1684
- function getColumnWidths(pageWidth, tableColumns, insertColumnIndex) {
1685
- const widths = [];
1686
- let newColWidth = tableColumns[insertColumnIndex].size.width.v, totalWidth = 0;
1687
- for (let i = 0; i < tableColumns.length; i++)
1688
- totalWidth += tableColumns[i].size.width.v;
1689
- totalWidth += newColWidth;
1690
- for (let i = 0; i < tableColumns.length; i++)
1691
- widths.push(tableColumns[i].size.width.v / totalWidth * pageWidth);
1692
- return newColWidth = newColWidth / totalWidth * pageWidth, {
1693
- widths,
1694
- newColWidth
1695
- };
1696
- }
1697
- __name(getColumnWidths, "getColumnWidths");
1698
- function getDeleteRowsActionsParams(rangeInfo, viewModel) {
1699
- var _a11, _b, _c;
1700
- const { startOffset, endOffset, segmentId } = rangeInfo, vm = viewModel.getSelfOrHeaderFooterViewModel(segmentId), tableId = (_c = (_b = (_a11 = viewModel.getBody()) == null ? void 0 : _a11.tables) == null ? void 0 : _b.find((t) => startOffset >= t.startIndex && endOffset <= t.endIndex)) == null ? void 0 : _c.tableId, rowIndexes = [];
1701
- let offset = -1, len = 0, cursor = -1, selectWholeTable = !1;
1702
- for (const section of vm.children) {
1703
- for (const paragraph of section.children) {
1704
- const { children } = paragraph, table = children[0];
1705
- if (table) {
1706
- if (startOffset < table.startIndex || endOffset > table.endIndex)
1707
- continue;
1708
- cursor = table.startIndex + 3;
1709
- for (const row of table.children) {
1710
- const rowIndex = table.children.indexOf(row), { startIndex, endIndex } = row;
1711
- startOffset >= startIndex && startOffset <= endIndex ? (offset = startIndex, rowIndexes.push(rowIndex), len += endIndex - startIndex + 1) : (startIndex > startOffset && endIndex < endOffset || endOffset >= startIndex && endOffset <= endIndex) && (rowIndexes.push(rowIndex), len += endIndex - startIndex + 1), rowIndexes.length === table.children.length && (selectWholeTable = !0);
1712
- }
1713
- }
1714
- if (rowIndexes.length)
1715
- break;
1716
- }
1717
- if (rowIndexes.length)
1718
- break;
1719
- }
1720
- return tableId == null || rowIndexes.length === 0 ? null : {
1721
- tableId,
1722
- rowIndexes,
1723
- offset,
1724
- len,
1725
- cursor,
1726
- selectWholeTable
1727
- };
1728
- }
1729
- __name(getDeleteRowsActionsParams, "getDeleteRowsActionsParams");
1730
- function getDeleteColumnsActionParams(rangeInfo, viewModel) {
1731
- var _a11, _b, _c;
1732
- const { startOffset, endOffset, segmentId } = rangeInfo, vm = viewModel.getSelfOrHeaderFooterViewModel(segmentId), tableId = (_c = (_b = (_a11 = viewModel.getBody()) == null ? void 0 : _a11.tables) == null ? void 0 : _b.find((t) => startOffset >= t.startIndex && endOffset <= t.endIndex)) == null ? void 0 : _c.tableId, offsets = [];
1733
- let table = null;
1734
- const columnIndexes = [];
1735
- let cursor = -1, startColumnIndex = -1, endColumnIndex = -1;
1736
- for (const section of vm.children) {
1737
- for (const paragraph of section.children) {
1738
- const { children } = paragraph, tableNode = children[0];
1739
- if (tableNode) {
1740
- if (startOffset < tableNode.startIndex || endOffset > tableNode.endIndex)
1741
- continue;
1742
- table = tableNode;
1743
- for (const row of tableNode.children)
1744
- for (const cell of row.children) {
1745
- const cellIndex = row.children.indexOf(cell);
1746
- startOffset >= cell.startIndex && startOffset <= cell.endIndex && (startColumnIndex = cellIndex), endOffset >= cell.startIndex && endOffset <= cell.endIndex && (endColumnIndex = cellIndex);
1747
- }
1748
- }
1749
- if (table)
1750
- break;
1751
- }
1752
- if (table)
1753
- break;
1754
- }
1755
- if (table == null || tableId == null)
1756
- return null;
1757
- for (let i = startColumnIndex; i <= endColumnIndex; i++)
1758
- columnIndexes.push(i);
1759
- let delta = 0;
1760
- for (const row of table.children) {
1761
- const startCell = row.children[startColumnIndex], endCell = row.children[endColumnIndex];
1762
- offsets.push({
1763
- retain: startCell.startIndex - delta,
1764
- delete: endCell.endIndex - startCell.startIndex + 1
1765
- }), delta = endCell.endIndex + 1;
1766
- }
1767
- return cursor = table.startIndex + 3, {
1768
- offsets,
1769
- tableId,
1770
- columnIndexes,
1771
- cursor,
1772
- selectWholeTable: columnIndexes.length === table.children[0].children.length,
1773
- rowCount: table.children.length
1774
- };
1775
- }
1776
- __name(getDeleteColumnsActionParams, "getDeleteColumnsActionParams");
1777
- function getDeleteTableActionParams(rangeInfo, viewModel) {
1778
- var _a11, _b, _c;
1779
- const { startOffset, endOffset, segmentId } = rangeInfo, vm = viewModel.getSelfOrHeaderFooterViewModel(segmentId), tableId = (_c = (_b = (_a11 = viewModel.getBody()) == null ? void 0 : _a11.tables) == null ? void 0 : _b.find((t) => startOffset >= t.startIndex && endOffset <= t.endIndex)) == null ? void 0 : _c.tableId;
1780
- let offset = -1, len = 0, cursor = -1;
1781
- for (const section of vm.children) {
1782
- for (const paragraph of section.children) {
1783
- const { children } = paragraph, table = children[0];
1784
- if (table) {
1785
- if (startOffset < table.startIndex || endOffset > table.endIndex)
1786
- continue;
1787
- offset = table.startIndex, len = table.endIndex - table.startIndex + 1, cursor = table.startIndex;
1788
- }
1789
- if (table)
1790
- break;
1791
- }
1792
- if (len > 0)
1793
- break;
1794
- }
1795
- return tableId == null ? null : {
1796
- tableId,
1797
- offset,
1798
- len,
1799
- cursor
1800
- };
1801
- }
1802
- __name(getDeleteTableActionParams, "getDeleteTableActionParams");
1803
- function getDeleteRowContentActionParams(rangeInfo, viewModel) {
1804
- var _a11, _b, _c;
1805
- const { startOffset, endOffset, segmentId } = rangeInfo, vm = viewModel.getSelfOrHeaderFooterViewModel(segmentId), tableId = (_c = (_b = (_a11 = viewModel.getBody()) == null ? void 0 : _a11.tables) == null ? void 0 : _b.find((t) => startOffset >= t.startIndex && endOffset <= t.endIndex)) == null ? void 0 : _c.tableId, offsets = [];
1806
- let table = null, cursor = -1, rowIndex = -1, startColumnIndex = -1, endColumnIndex = -1;
1807
- for (const section of vm.children) {
1808
- for (const paragraph of section.children) {
1809
- const { children } = paragraph, tableNode = children[0];
1810
- if (tableNode) {
1811
- if (startOffset < tableNode.startIndex || endOffset > tableNode.endIndex)
1812
- continue;
1813
- table = tableNode;
1814
- for (const row2 of tableNode.children) {
1815
- const rIndex = tableNode.children.indexOf(row2);
1816
- for (const cell of row2.children) {
1817
- const cellIndex = row2.children.indexOf(cell);
1818
- startOffset >= cell.startIndex && startOffset <= cell.endIndex && (rowIndex = rIndex, startColumnIndex = cellIndex), endOffset >= cell.startIndex && endOffset <= cell.endIndex && (endColumnIndex = cellIndex);
1819
- }
1820
- }
1821
- }
1822
- if (table)
1823
- break;
1824
- }
1825
- if (table)
1826
- break;
1827
- }
1828
- if (table == null || tableId == null || rowIndex === -1)
1829
- return null;
1830
- const row = table.children[rowIndex];
1831
- for (let i = startColumnIndex; i <= endColumnIndex; i++) {
1832
- const cell = row.children[i];
1833
- offsets.push({
1834
- retain: cell.startIndex + 1,
1835
- delete: cell.endIndex - cell.startIndex - 3
1836
- });
1837
- }
1838
- return cursor = table.startIndex + 3, {
1839
- offsets,
1840
- tableId,
1841
- cursor,
1842
- rowCount: table.children.length
1843
- };
1844
- }
1845
- __name(getDeleteRowContentActionParams, "getDeleteRowContentActionParams");
1846
- var CellPosition = /* @__PURE__ */ ((CellPosition2) => (CellPosition2[CellPosition2.NEXT = 0] = "NEXT", CellPosition2[CellPosition2.PREV = 1] = "PREV", CellPosition2))(CellPosition || {});
1847
- function getCellOffsets(viewModel, range, position) {
1848
- const { startOffset } = range;
1849
- let targetTable = null;
1850
- for (const section of viewModel.children) {
1851
- for (const paragraph of section.children) {
1852
- const table = paragraph.children[0];
1853
- if (table && startOffset > table.startIndex && startOffset < table.endIndex) {
1854
- targetTable = table;
1855
- break;
1856
- }
1857
- }
1858
- if (targetTable)
1859
- break;
1860
- }
1861
- if (targetTable == null)
1862
- return null;
1863
- let cellIndex = -1, rowIndex = -1, targetRow = null;
1864
- for (const row of targetTable.children) {
1865
- for (const cell of row.children)
1866
- if (startOffset > cell.startIndex && startOffset < cell.endIndex) {
1867
- cellIndex = row.children.indexOf(cell), rowIndex = targetTable.children.indexOf(row), targetRow = row;
1868
- break;
1869
- }
1870
- if (cellIndex > -1)
1871
- break;
1872
- }
1873
- if (cellIndex === -1 || rowIndex === -1 || targetRow == null)
1874
- return null;
1875
- let newCell = null;
1876
- if (position === 0) {
1877
- if (newCell = targetRow.children[cellIndex + 1], !newCell) {
1878
- const nextRow = targetTable.children[rowIndex + 1];
1879
- nextRow && (newCell = nextRow.children[0]);
1880
- }
1881
- } else if (newCell = targetRow.children[cellIndex - 1], !newCell) {
1882
- const prevRow = targetTable.children[rowIndex - 1];
1883
- prevRow && (newCell = prevRow.children[prevRow.children.length - 1]);
1884
- }
1885
- if (newCell) {
1886
- const { startIndex, endIndex } = newCell;
1887
- return {
1888
- startOffset: startIndex + 1,
1889
- endOffset: endIndex - 2
1890
- };
1891
- }
1892
- }
1893
- __name(getCellOffsets, "getCellOffsets");
1894
- function getCustomBlockIdsInSelections(body, selections) {
1895
- const customBlockIds = [], { customBlocks = [] } = body;
1896
- for (const selection of selections) {
1897
- const { startOffset, endOffset } = selection;
1898
- if (!(startOffset == null || endOffset == null))
1899
- for (const customBlock of customBlocks) {
1900
- const { startIndex } = customBlock;
1901
- startIndex >= startOffset && startIndex < endOffset && customBlockIds.push(customBlock.blockId);
1902
- }
1903
- }
1904
- return customBlockIds;
1905
- }
1906
- __name(getCustomBlockIdsInSelections, "getCustomBlockIdsInSelections");
1907
- function hasRangeInTable(ranges) {
1908
- return ranges.some((range) => {
1909
- const { anchorNodePosition } = range;
1910
- return anchorNodePosition ? (anchorNodePosition == null ? void 0 : anchorNodePosition.path.indexOf("cells")) > -1 : !1;
1911
- });
1912
- }
1913
- __name(hasRangeInTable, "hasRangeInTable");
1914
- const InnerPasteCommand = {
1915
- id: "doc.command.inner-paste",
1916
- type: CommandType.COMMAND,
1917
- // eslint-disable-next-line max-lines-per-function, complexity
1918
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
1919
- var _a11, _b, _c, _d;
1920
- const { segmentId, textRanges, doc } = params, commandService = accessor.get(ICommandService), textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), selections = textSelectionManagerService.getCurrentTextRanges(), { body, tableSource, drawings } = doc;
1921
- if (!Array.isArray(selections) || selections.length === 0 || body == null)
1922
- return !1;
1923
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance(), originBody = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
1924
- if (docDataModel == null || originBody == null)
1925
- return !1;
1926
- const unitId = docDataModel.getUnitId(), doMutation = {
1927
- id: RichTextEditingMutation.id,
1928
- params: {
1929
- unitId,
1930
- actions: [],
1931
- textRanges,
1932
- segmentId
1933
- }
1934
- }, memoryCursor = new MemoryCursor();
1935
- memoryCursor.reset();
1936
- const textX = new TextX(), jsonX = JSONX.getInstance(), rawActions = [], hasTable = !!((_a11 = body.tables) != null && _a11.length), hasCustomBlock = !!((_b = body.customBlocks) != null && _b.length);
1937
- if (hasTable && segmentId || hasTable && hasRangeInTable(selections))
1938
- return !1;
1939
- for (const selection of selections) {
1940
- const { startOffset, endOffset, collapsed } = selection, len = startOffset - memoryCursor.cursor, cloneBody = Tools.deepClone(body);
1941
- if (hasTable)
1942
- for (const t of cloneBody.tables) {
1943
- const { tableId: oldTableId } = t, tableId = Tools.generateRandomId(6);
1944
- t.tableId = tableId;
1945
- const table = Tools.deepClone(tableSource[oldTableId]);
1946
- table.tableId = tableId;
1947
- const action = jsonX.insertOp(["tableSource", tableId], table);
1948
- rawActions.push(action);
1949
- }
1950
- if (hasCustomBlock && drawings) {
1951
- const drawingLen = (_d = (_c = docDataModel.getSnapshot().drawingsOrder) == null ? void 0 : _c.length) != null ? _d : 0;
1952
- for (const block of cloneBody.customBlocks) {
1953
- const { blockId } = block, drawingId = Tools.generateRandomId(6);
1954
- block.blockId = drawingId;
1955
- const drawing = Tools.deepClone(drawings[blockId]);
1956
- drawing.drawingId = drawingId;
1957
- const action = jsonX.insertOp(["drawings", drawingId], drawing), orderAction = jsonX.insertOp(["drawingsOrder", drawingLen], drawingId);
1958
- rawActions.push(action), rawActions.push(orderAction);
1959
- }
1960
- }
1961
- if (collapsed)
1962
- textX.push({
1963
- t: TextXActionType.RETAIN,
1964
- len,
1965
- segmentId
1966
- });
1967
- else {
1968
- const { dos } = getRetainAndDeleteFromReplace(selection, segmentId, memoryCursor.cursor, originBody);
1969
- textX.push(...dos);
1970
- }
1971
- textX.push({
1972
- t: TextXActionType.INSERT,
1973
- body: cloneBody,
1974
- len: body.dataStream.length,
1975
- line: 0,
1976
- segmentId
1977
- }), memoryCursor.reset(), memoryCursor.moveCursor(endOffset);
1978
- }
1979
- const path = getRichTextEditPath(docDataModel, segmentId);
1980
- return rawActions.push(jsonX.editOp(textX.serialize(), path)), doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
1981
- }, "handler")
1982
- };
1983
- function getCutActionsFromTextRanges(selections, docDataModel, segmentId) {
1984
- var _a11, _b;
1985
- const originBody = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody(), textX = new TextX(), jsonX = JSONX.getInstance(), rawActions = [];
1986
- if (originBody == null)
1987
- return rawActions;
1988
- const memoryCursor = new MemoryCursor();
1989
- memoryCursor.reset();
1990
- for (const selection of selections) {
1991
- const { startOffset, endOffset, collapsed } = selection;
1992
- if (startOffset == null || endOffset == null)
1993
- continue;
1994
- const len = startOffset - memoryCursor.cursor;
1995
- collapsed ? textX.push({
1996
- t: TextXActionType.RETAIN,
1997
- len,
1998
- segmentId
1999
- }) : textX.push(...getRetainAndDeleteAndExcludeLineBreak(selection, originBody, segmentId, memoryCursor.cursor, !1)), memoryCursor.reset(), memoryCursor.moveCursor(endOffset);
2000
- }
2001
- const path = getRichTextEditPath(docDataModel, segmentId);
2002
- rawActions.push(jsonX.editOp(textX.serialize(), path));
2003
- const removedCustomBlockIds = getCustomBlockIdsInSelections(originBody, selections), drawings = (_a11 = docDataModel.getDrawings()) != null ? _a11 : {}, drawingOrder = (_b = docDataModel.getDrawingsOrder()) != null ? _b : [], sortedRemovedCustomBlockIds = removedCustomBlockIds.sort((a, b) => drawingOrder.indexOf(a) > drawingOrder.indexOf(b) ? -1 : drawingOrder.indexOf(a) < drawingOrder.indexOf(b) ? 1 : 0);
2004
- if (sortedRemovedCustomBlockIds.length > 0)
2005
- for (const blockId of sortedRemovedCustomBlockIds) {
2006
- const drawing = drawings[blockId], drawingIndex = drawingOrder.indexOf(blockId);
2007
- if (drawing == null || drawingIndex < 0)
2008
- continue;
2009
- const removeDrawingAction = jsonX.removeOp(["drawings", blockId], drawing), removeDrawingOrderAction = jsonX.removeOp(["drawingsOrder", drawingIndex], blockId);
2010
- rawActions.push(removeDrawingAction), rawActions.push(removeDrawingOrderAction);
2011
- }
2012
- return rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null);
2013
- }
2014
- __name(getCutActionsFromTextRanges, "getCutActionsFromTextRanges");
2015
- function getCutActionsFromRectRanges(ranges, docDataModel, viewModel, segmentId) {
2016
- const rawActions = [];
2017
- if (docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody() == null)
2018
- return rawActions;
2019
- const textX = new TextX(), jsonX = JSONX.getInstance(), memoryCursor = new MemoryCursor();
2020
- memoryCursor.reset();
2021
- for (const range of ranges) {
2022
- const { startOffset, endOffset, spanEntireRow, spanEntireTable } = range;
2023
- if (!(startOffset == null || endOffset == null))
2024
- if (spanEntireTable) {
2025
- const actionParams = getDeleteTableActionParams({ startOffset, endOffset, segmentId }, viewModel);
2026
- if (actionParams == null)
2027
- continue;
2028
- const { offset, len, tableId } = actionParams;
2029
- offset - memoryCursor.cursor > 0 && textX.push({
2030
- t: TextXActionType.RETAIN,
2031
- len: offset - memoryCursor.cursor,
2032
- segmentId
2033
- }), textX.push({
2034
- t: TextXActionType.DELETE,
2035
- len,
2036
- line: 0,
2037
- segmentId
2038
- });
2039
- const action = jsonX.removeOp(["tableSource", tableId]);
2040
- rawActions.push(action), memoryCursor.moveCursorTo(offset + len);
2041
- } else if (spanEntireRow) {
2042
- const actionParams = getDeleteRowsActionsParams({ startOffset, endOffset, segmentId }, viewModel);
2043
- if (actionParams == null)
2044
- continue;
2045
- const { offset, rowIndexes, len, tableId } = actionParams;
2046
- offset - memoryCursor.cursor > 0 && textX.push({
2047
- t: TextXActionType.RETAIN,
2048
- len: offset - memoryCursor.cursor,
2049
- segmentId
2050
- }), textX.push({
2051
- t: TextXActionType.DELETE,
2052
- len,
2053
- line: 0,
2054
- segmentId
2055
- });
2056
- for (const index of rowIndexes.reverse()) {
2057
- const action = jsonX.removeOp(["tableSource", tableId, "tableRows", index]);
2058
- rawActions.push(action);
2059
- }
2060
- memoryCursor.moveCursorTo(offset + len);
2061
- } else {
2062
- const actionParams = getDeleteRowContentActionParams({ startOffset, endOffset, segmentId }, viewModel);
2063
- if (actionParams == null)
2064
- continue;
2065
- const { offsets } = actionParams;
2066
- for (const offset of offsets) {
2067
- const { retain, delete: delLen } = offset;
2068
- retain - memoryCursor.cursor > 0 && textX.push({
2069
- t: TextXActionType.RETAIN,
2070
- len: retain - memoryCursor.cursor,
2071
- segmentId
2072
- }), textX.push({
2073
- t: TextXActionType.DELETE,
2074
- len: delLen,
2075
- line: 0,
2076
- segmentId
2077
- }), memoryCursor.moveCursorTo(retain + delLen);
2078
- }
2079
- }
2080
- }
2081
- const path = getRichTextEditPath(docDataModel, segmentId);
2082
- return rawActions.push(jsonX.editOp(textX.serialize(), path)), rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null);
2083
- }
2084
- __name(getCutActionsFromRectRanges, "getCutActionsFromRectRanges");
2085
- function getCutActionsFromDocRanges(textRanges, rectRanges, docDataModel, viewModel, segmentId) {
2086
- let rawActions = [];
2087
- if (Array.isArray(textRanges) && (textRanges == null ? void 0 : textRanges.length) !== 0 && (rawActions = getCutActionsFromTextRanges(textRanges, docDataModel, segmentId)), Array.isArray(rectRanges) && (rectRanges == null ? void 0 : rectRanges.length) !== 0) {
2088
- const actions = getCutActionsFromRectRanges(rectRanges, docDataModel, viewModel, segmentId);
2089
- rawActions == null || rawActions.length === 0 ? rawActions = actions : rawActions = JSONX.compose(
2090
- rawActions,
2091
- JSONX.transform(actions, rawActions, "right")
2092
- );
2093
- }
2094
- return rawActions;
2095
- }
2096
- __name(getCutActionsFromDocRanges, "getCutActionsFromDocRanges");
2097
- const INNER_CUT_COMMAND_ID = "doc.command.inner-cut", CutContentCommand = {
2098
- id: INNER_CUT_COMMAND_ID,
2099
- type: CommandType.COMMAND,
2100
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
2101
- var _a11, _b;
2102
- const { segmentId, textRanges } = params, commandService = accessor.get(ICommandService), textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), selections = (_a11 = params.selections) != null ? _a11 : textSelectionManagerService.getCurrentTextRanges(), rectRanges = textSelectionManagerService.getCurrentRectRanges();
2103
- if ((!Array.isArray(selections) || selections.length === 0) && (!Array.isArray(rectRanges) || rectRanges.length === 0))
2104
- return !1;
2105
- const unitId = (_b = univerInstanceService.getCurrentUniverDocInstance()) == null ? void 0 : _b.getUnitId();
2106
- if (!unitId)
2107
- return !1;
2108
- const docDataModel = univerInstanceService.getUniverDocInstance(unitId);
2109
- if (docDataModel == null)
2110
- return !1;
2111
- const docSkeletonManagerService = getCommandSkeleton(accessor, unitId);
2112
- if (docSkeletonManagerService == null)
2113
- return !1;
2114
- const viewModel = docSkeletonManagerService.getViewModel(), doMutation = {
2115
- id: RichTextEditingMutation.id,
2116
- params: {
2117
- unitId,
2118
- actions: [],
2119
- textRanges
2120
- }
2121
- };
2122
- return doMutation.params.actions = getCutActionsFromDocRanges(selections, rectRanges, docDataModel, viewModel, segmentId), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
2123
- }, "handler")
2124
- }, DeleteCustomBlockCommand = {
2125
- id: "doc.command.delete-custom-block",
2126
- type: CommandType.COMMAND,
2127
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
2128
- var _a11;
2129
- const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), activeRange = textSelectionManagerService.getActiveTextRangeWithStyle(), documentDataModel = univerInstanceService.getCurrentUniverDocInstance();
2130
- if (activeRange == null || documentDataModel == null)
2131
- return !1;
2132
- const { direction, range, unitId, drawingId } = params, { startOffset, segmentId, style } = activeRange, cursor = direction === DeleteDirection.LEFT ? startOffset - 1 : startOffset, textRanges = [
2133
- {
2134
- startOffset: cursor,
2135
- endOffset: cursor,
2136
- style
2137
- }
2138
- ], doMutation = {
2139
- id: RichTextEditingMutation.id,
2140
- params: {
2141
- unitId,
2142
- actions: [],
2143
- textRanges,
2144
- prevTextRanges: [range]
2145
- }
2146
- }, textX = new TextX(), jsonX = JSONX.getInstance(), rawActions = [];
2147
- startOffset > 0 && textX.push({
2148
- t: TextXActionType.RETAIN,
2149
- len: direction === DeleteDirection.LEFT ? startOffset - 1 : startOffset,
2150
- segmentId
2151
- }), textX.push({
2152
- t: TextXActionType.DELETE,
2153
- len: 1,
2154
- line: 0,
2155
- segmentId
2156
- });
2157
- const path = getRichTextEditPath(documentDataModel, segmentId);
2158
- rawActions.push(jsonX.editOp(textX.serialize(), path));
2159
- const drawing = ((_a11 = documentDataModel.getDrawings()) != null ? _a11 : {})[drawingId], drawingIndex = documentDataModel.getDrawingsOrder().indexOf(drawingId), removeDrawingAction = jsonX.removeOp(["drawings", drawingId], drawing), removeDrawingOrderAction = jsonX.removeOp(["drawingsOrder", drawingIndex], drawingId);
2160
- return rawActions.push(removeDrawingAction), rawActions.push(removeDrawingOrderAction), doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
2161
- }, "handler")
2162
- }, MergeTwoParagraphCommand = {
2163
- id: "doc.command.merge-two-paragraph",
2164
- type: CommandType.COMMAND,
2165
- // eslint-disable-next-line max-lines-per-function
2166
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
2167
- const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), { direction, range } = params, activeRange = textSelectionManagerService.getActiveTextRangeWithStyle(), ranges = textSelectionManagerService.getCurrentTextRanges();
2168
- if (activeRange == null || ranges == null)
2169
- return !1;
2170
- const { segmentId, style } = activeRange, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), originBody = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
2171
- if (!docDataModel || !originBody)
2172
- return !1;
2173
- const actualRange = getDeleteSelection(activeRange, originBody), unitId = docDataModel.getUnitId(), { startOffset, collapsed } = actualRange;
2174
- if (!collapsed)
2175
- return !1;
2176
- const startIndex = direction === DeleteDirection.LEFT ? startOffset : startOffset + 1, endIndex = originBody.paragraphs.find((p) => p.startIndex >= startIndex).startIndex, body = getParagraphBody(accessor, unitId, originBody, startIndex, endIndex), cursor = direction === DeleteDirection.LEFT ? startOffset - 1 : startOffset, textRanges = [
2177
- {
2178
- startOffset: cursor,
2179
- endOffset: cursor,
2180
- style
2181
- }
2182
- ], doMutation = {
2183
- id: RichTextEditingMutation.id,
2184
- params: {
2185
- unitId,
2186
- actions: [],
2187
- textRanges,
2188
- prevTextRanges: [range]
2189
- }
2190
- }, textX = new TextX(), jsonX = JSONX.getInstance();
2191
- textX.push({
2192
- t: TextXActionType.RETAIN,
2193
- len: direction === DeleteDirection.LEFT ? startOffset - 1 : startOffset,
2194
- segmentId
2195
- }), body.dataStream.length && textX.push({
2196
- t: TextXActionType.INSERT,
2197
- body,
2198
- len: body.dataStream.length,
2199
- line: 0,
2200
- segmentId
2201
- }), textX.push({
2202
- t: TextXActionType.RETAIN,
2203
- len: 1,
2204
- segmentId
2205
- }), textX.push({
2206
- t: TextXActionType.DELETE,
2207
- len: endIndex + 1 - startIndex,
2208
- line: 0,
2209
- segmentId
2210
- });
2211
- const path = getRichTextEditPath(docDataModel, segmentId);
2212
- return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
2213
- }, "handler")
2214
- };
2215
- function getCursorWhenDelete(textRanges, rectRanges) {
2216
- let cursor = 0;
2217
- if (textRanges == null || textRanges.length === 0) {
2218
- if (typeof rectRanges[0].startOffset == "number") {
2219
- const rectRange = rectRanges[0], { spanEntireRow, spanEntireTable } = rectRange;
2220
- spanEntireTable ? cursor = rectRange.startOffset - 3 : spanEntireRow ? rectRange.startRow > 0 ? cursor = rectRange.startOffset - 6 : cursor = rectRange.startOffset : cursor = rectRanges[0].startOffset;
2221
- }
2222
- } else if (textRanges.length > 0 && rectRanges.length > 0) {
2223
- const textRange = textRanges[0], rectRange = rectRanges[0];
2224
- if (textRange.startOffset != null && rectRange.startOffset != null) {
2225
- if (textRange.startOffset < rectRange.startOffset)
2226
- cursor = textRange.startOffset;
2227
- else if (textRange.startOffset >= rectRange.startOffset) {
2228
- const { spanEntireRow, spanEntireTable } = rectRange;
2229
- spanEntireTable ? cursor = rectRange.startOffset - 3 : spanEntireRow && (cursor = rectRange.startOffset - 6);
2230
- }
2231
- }
2232
- }
2233
- return cursor;
2234
- }
2235
- __name(getCursorWhenDelete, "getCursorWhenDelete");
2236
- const DeleteLeftCommand = {
2237
- id: "doc.command.delete-left",
2238
- type: CommandType.COMMAND,
2239
- // eslint-disable-next-line max-lines-per-function, complexity
2240
- handler: /* @__PURE__ */ __name(async (accessor) => {
2241
- var _a11, _b;
2242
- const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService);
2243
- let result = !0;
2244
- const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
2245
- if (!docDataModel)
2246
- return !1;
2247
- const unitId = docDataModel.getUnitId(), docSkeletonManagerService = getCommandSkeleton(accessor, unitId), activeRange = textSelectionManagerService.getActiveTextRangeWithStyle(), rectRanges = textSelectionManagerService.getCurrentRectRanges(), ranges = textSelectionManagerService.getCurrentTextRanges(), skeleton = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getSkeleton();
2248
- if (skeleton == null)
2249
- return !1;
2250
- if (rectRanges != null && rectRanges.length) {
2251
- const cursor2 = getCursorWhenDelete(ranges, rectRanges), segmentId2 = rectRanges[0].segmentId, textRanges = [
2252
- {
2253
- startOffset: cursor2,
2254
- endOffset: cursor2
2255
- }
2256
- ];
2257
- return commandService.executeCommand(CutContentCommand.id, {
2258
- segmentId: segmentId2,
2259
- textRanges
2260
- });
2261
- }
2262
- if (activeRange == null || ranges == null)
2263
- return !1;
2264
- const { segmentId, style, segmentPage } = activeRange, body = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
2265
- if (body == null)
2266
- return !1;
2267
- const actualRange = getDeleteSelection(activeRange, body), { startOffset, collapsed } = actualRange, curGlyph = skeleton.findNodeByCharIndex(startOffset, segmentId, segmentPage), isBullet = hasListGlyph(curGlyph), isIndent = isIndentByGlyph(curGlyph, body);
2268
- let cursor = startOffset;
2269
- const preGlyph = skeleton.findNodeByCharIndex(startOffset - 1, segmentId, segmentPage);
2270
- if (isFirstGlyph(curGlyph) && preGlyph !== curGlyph && (isBullet === !0 || isIndent === !0) && collapsed) {
2271
- const paragraph = getParagraphByGlyph(curGlyph, body);
2272
- if (paragraph == null)
2273
- return !1;
2274
- const paragraphIndex = paragraph == null ? void 0 : paragraph.startIndex, updateParagraph = { startIndex: 0 }, paragraphStyle = paragraph.paragraphStyle;
2275
- if (isBullet === !0) {
2276
- const paragraphStyle2 = paragraph.paragraphStyle;
2277
- if (paragraphStyle2) {
2278
- updateParagraph.paragraphStyle = paragraphStyle2;
2279
- const { hanging } = paragraphStyle2;
2280
- hanging && (updateParagraph.paragraphStyle.indentStart = hanging, updateParagraph.paragraphStyle.hanging = void 0);
2281
- }
2282
- } else if (isIndent === !0) {
2283
- const bullet = paragraph.bullet;
2284
- bullet && (updateParagraph.bullet = bullet), paragraphStyle != null && (updateParagraph.paragraphStyle = { ...paragraphStyle }, delete updateParagraph.paragraphStyle.hanging, delete updateParagraph.paragraphStyle.indentStart);
2285
- }
2286
- const textRanges = [
2287
- {
2288
- startOffset: cursor,
2289
- endOffset: cursor,
2290
- style
2291
- }
2292
- ];
2293
- result = await commandService.executeCommand(UpdateCommand.id, {
2294
- unitId: docDataModel.getUnitId(),
2295
- updateBody: {
2296
- dataStream: "",
2297
- paragraphs: [{ ...updateParagraph }]
2298
- },
2299
- range: {
2300
- startOffset: paragraphIndex,
2301
- endOffset: paragraphIndex + 1
2302
- },
2303
- textRanges,
2304
- coverType: UpdateDocsAttributeType.REPLACE,
2305
- segmentId
2306
- });
2307
- } else if (collapsed === !0) {
2308
- if (preGlyph == null)
2309
- return !0;
2310
- if (preGlyph.content === "\r")
2311
- result = await commandService.executeCommand(MergeTwoParagraphCommand.id, {
2312
- direction: DeleteDirection.LEFT,
2313
- range: actualRange
2314
- });
2315
- else if (preGlyph.streamType === "\b") {
2316
- const drawing = (_b = docDataModel.getSnapshot().drawings) == null ? void 0 : _b[(_a11 = preGlyph.drawingId) != null ? _a11 : ""];
2317
- if (drawing == null)
2318
- return !0;
2319
- if (drawing.layoutType === PositionedObjectLayoutType.INLINE) {
2320
- const unitId2 = docDataModel.getUnitId();
2321
- result = await commandService.executeCommand(DeleteCustomBlockCommand.id, {
2322
- direction: DeleteDirection.LEFT,
2323
- range: activeRange,
2324
- unitId: unitId2,
2325
- drawingId: preGlyph.drawingId
2326
- });
2327
- } else {
2328
- const prePreGlyph = skeleton.findNodeByCharIndex(startOffset - 2);
2329
- if (prePreGlyph == null)
2330
- return !0;
2331
- cursor -= preGlyph.count, cursor -= prePreGlyph.count;
2332
- const textRanges = [
2333
- {
2334
- startOffset: cursor,
2335
- endOffset: cursor,
2336
- style
2337
- }
2338
- ];
2339
- result = await commandService.executeCommand(DeleteCommand.id, {
2340
- unitId: docDataModel.getUnitId(),
2341
- range: {
2342
- ...activeRange,
2343
- startOffset: activeRange.startOffset - 1,
2344
- endOffset: activeRange.endOffset - 1
2345
- },
2346
- segmentId,
2347
- direction: DeleteDirection.LEFT,
2348
- len: prePreGlyph.count,
2349
- textRanges
2350
- });
2351
- }
2352
- } else
2353
- cursor -= preGlyph.count, result = await commandService.executeCommand(DeleteCommand.id, {
2354
- unitId: docDataModel.getUnitId(),
2355
- range: actualRange,
2356
- segmentId,
2357
- direction: DeleteDirection.LEFT,
2358
- len: preGlyph.count
2359
- });
2360
- } else {
2361
- const textRanges = getTextRangesWhenDelete(actualRange, [actualRange]);
2362
- result = await commandService.executeCommand(CutContentCommand.id, {
2363
- segmentId,
2364
- textRanges,
2365
- selections: [actualRange]
2366
- });
2367
- }
2368
- return result;
2369
- }, "handler")
2370
- }, DeleteRightCommand = {
2371
- id: "doc.command.delete-right",
2372
- type: CommandType.COMMAND,
2373
- // eslint-disable-next-line max-lines-per-function, complexity
2374
- handler: /* @__PURE__ */ __name(async (accessor) => {
2375
- var _a11, _b;
2376
- const textSelectionManagerService = accessor.get(TextSelectionManagerService), docDataModel = accessor.get(IUniverInstanceService).getCurrentUniverDocInstance();
2377
- if (!docDataModel)
2378
- return !1;
2379
- const docSkeletonManagerService = getCommandSkeleton(accessor, docDataModel.getUnitId()), commandService = accessor.get(ICommandService), activeRange = textSelectionManagerService.getActiveTextRangeWithStyle(), rectRanges = textSelectionManagerService.getCurrentRectRanges(), ranges = textSelectionManagerService.getCurrentTextRanges(), skeleton = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getSkeleton();
2380
- if (rectRanges != null && rectRanges.length) {
2381
- const cursor = getCursorWhenDelete(ranges, rectRanges), segmentId2 = rectRanges[0].segmentId, textRanges = [
2382
- {
2383
- startOffset: cursor,
2384
- endOffset: cursor
2385
- }
2386
- ];
2387
- return commandService.executeCommand(CutContentCommand.id, {
2388
- segmentId: segmentId2,
2389
- textRanges
2390
- });
2391
- }
2392
- if (activeRange == null || skeleton == null || ranges == null)
2393
- return !1;
2394
- const { segmentId, style, segmentPage } = activeRange, body = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
2395
- if (!docDataModel || !body)
2396
- return !1;
2397
- const actualRange = getDeleteSelection(activeRange, body, DeleteDirection.RIGHT), { startOffset, endOffset, collapsed } = actualRange;
2398
- if (startOffset === body.dataStream.length - 2 && collapsed)
2399
- return !0;
2400
- let result = !1;
2401
- if (collapsed === !0) {
2402
- const needDeleteGlyph = skeleton.findNodeByCharIndex(startOffset, segmentId, segmentPage), nextGlyph = skeleton.findNodeByCharIndex(startOffset + 1);
2403
- if (needDeleteGlyph.streamType === DataStreamTreeTokenType.PARAGRAPH && (nextGlyph == null ? void 0 : nextGlyph.streamType) === DataStreamTreeTokenType.SECTION_BREAK)
2404
- return !1;
2405
- if (needDeleteGlyph.content === "\r")
2406
- result = await commandService.executeCommand(MergeTwoParagraphCommand.id, {
2407
- direction: DeleteDirection.RIGHT,
2408
- range: activeRange
2409
- });
2410
- else if (needDeleteGlyph.streamType === "\b") {
2411
- const drawing = (_b = docDataModel.getSnapshot().drawings) == null ? void 0 : _b[(_a11 = needDeleteGlyph.drawingId) != null ? _a11 : ""];
2412
- if (drawing == null)
2413
- return !0;
2414
- if (drawing.layoutType === PositionedObjectLayoutType.INLINE) {
2415
- const unitId = docDataModel.getUnitId();
2416
- result = await commandService.executeCommand(DeleteCustomBlockCommand.id, {
2417
- direction: DeleteDirection.RIGHT,
2418
- range: activeRange,
2419
- unitId,
2420
- drawingId: needDeleteGlyph.drawingId
2421
- });
2422
- } else {
2423
- if (nextGlyph == null)
2424
- return !0;
2425
- const textRanges = [
2426
- {
2427
- startOffset: startOffset + 1,
2428
- endOffset: startOffset + 1,
2429
- style
2430
- }
2431
- ];
2432
- result = await commandService.executeCommand(DeleteCommand.id, {
2433
- unitId: docDataModel.getUnitId(),
2434
- range: {
2435
- ...activeRange,
2436
- startOffset: startOffset + 1,
2437
- endOffset: endOffset + 1
2438
- },
2439
- segmentId,
2440
- direction: DeleteDirection.RIGHT,
2441
- textRanges,
2442
- len: nextGlyph.count
2443
- });
2444
- }
2445
- } else {
2446
- const textRanges = [
2447
- {
2448
- startOffset,
2449
- endOffset: startOffset,
2450
- style
2451
- }
2452
- ];
2453
- result = await commandService.executeCommand(DeleteCommand.id, {
2454
- unitId: docDataModel.getUnitId(),
2455
- range: actualRange,
2456
- segmentId,
2457
- direction: DeleteDirection.RIGHT,
2458
- textRanges,
2459
- len: needDeleteGlyph.count
2460
- });
2461
- }
2462
- } else {
2463
- const textRanges = getTextRangesWhenDelete(actualRange, [actualRange]);
2464
- result = await commandService.executeCommand(CutContentCommand.id, {
2465
- segmentId,
2466
- textRanges,
2467
- selections: [actualRange]
2468
- });
2469
- }
2470
- return result;
2471
- }, "handler")
2472
- };
2473
- function getParagraphBody(accessor, unitId, body, start, end) {
2474
- const { textRuns: originTextRuns = [], customBlocks: originCustomBlocks = [] } = body, bodySlice = {
2475
- dataStream: body.dataStream.substring(start, end),
2476
- customRanges: getCustomRangeSlice(body, start, end).customRanges.map((range) => ({
2477
- ...Tools.deepClone(range),
2478
- rangeId: generateRandomId()
2479
- })),
2480
- customDecorations: getCustomDecorationSlice(body, start, end)
2481
- }, textRuns = [];
2482
- for (const textRun of originTextRuns) {
2483
- const { st, ed } = textRun;
2484
- ed <= start || st >= end || (st < start ? textRuns.push({
2485
- ...textRun,
2486
- st: 0,
2487
- ed: ed - start
2488
- }) : ed > end ? textRuns.push({
2489
- ...textRun,
2490
- st: st - start,
2491
- ed: end - start
2492
- }) : textRuns.push({
2493
- ...textRun,
2494
- st: st - start,
2495
- ed: ed - start
2496
- }));
2497
- }
2498
- textRuns.length > 0 && (bodySlice.textRuns = textRuns);
2499
- const customBlocks = [];
2500
- for (const block of originCustomBlocks) {
2501
- const { startIndex } = block;
2502
- startIndex >= start && startIndex <= end && customBlocks.push({
2503
- ...block,
2504
- startIndex: startIndex - start
2505
- });
2506
- }
2507
- return customBlocks.length > 0 && (bodySlice.customBlocks = customBlocks), bodySlice;
2508
- }
2509
- __name(getParagraphBody, "getParagraphBody");
2510
- function getTextRangesWhenDelete(activeRange, ranges) {
2511
- let cursor = activeRange.endOffset;
2512
- for (const range of ranges) {
2513
- const { startOffset, endOffset } = range;
2514
- startOffset == null || endOffset == null || endOffset <= activeRange.endOffset && (cursor -= endOffset - startOffset);
2515
- }
2516
- return [
2517
- {
2518
- startOffset: cursor,
2519
- endOffset: cursor,
2520
- style: activeRange.style
2521
- }
2522
- ];
2523
- }
2524
- __name(getTextRangesWhenDelete, "getTextRangesWhenDelete");
2525
- const IMEInputCommand = {
2526
- id: "doc.command.ime-input",
2527
- type: CommandType.COMMAND,
2528
- // eslint-disable-next-line max-lines-per-function
2529
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
2530
- const { unitId, newText, oldTextLen, isCompositionEnd, isCompositionStart } = params, commandService = accessor.get(ICommandService), imeInputManagerService = accessor.get(IMEInputManagerService), docDataModel = accessor.get(IUniverInstanceService).getCurrentUniverDocInstance();
2531
- if (docDataModel == null)
2532
- return !1;
2533
- const previousActiveRange = imeInputManagerService.getActiveRange();
2534
- if (!previousActiveRange)
2535
- return !1;
2536
- const { style, segmentId } = previousActiveRange, body = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
2537
- if (body == null)
2538
- return !1;
2539
- const insertRange = getInsertSelection(previousActiveRange, body);
2540
- Object.assign(previousActiveRange, insertRange);
2541
- const { startOffset } = previousActiveRange, len = newText.length, textRanges = [
2542
- {
2543
- startOffset: startOffset + len,
2544
- endOffset: startOffset + len,
2545
- collapsed: !0,
2546
- style
2547
- }
2548
- ], doMutation = {
2549
- id: RichTextEditingMutation.id,
2550
- params: {
2551
- unitId,
2552
- actions: [],
2553
- textRanges
2554
- }
2555
- }, textX = new TextX(), jsonX = JSONX.getInstance();
2556
- if (!previousActiveRange.collapsed && isCompositionStart) {
2557
- const { dos, retain, cursor } = getRetainAndDeleteFromReplace(previousActiveRange, segmentId, 0, body);
2558
- textX.push(...dos), doMutation.params.textRanges = [{
2559
- startOffset: startOffset + len + retain,
2560
- endOffset: startOffset + len + retain,
2561
- collapsed: !0
2562
- }];
2563
- } else
2564
- textX.push({
2565
- t: TextXActionType.RETAIN,
2566
- len: startOffset,
2567
- segmentId
2568
- });
2569
- oldTextLen > 0 && textX.push({
2570
- t: TextXActionType.DELETE,
2571
- len: oldTextLen,
2572
- line: 0,
2573
- segmentId
2574
- }), textX.push({
2575
- t: TextXActionType.INSERT,
2576
- body: {
2577
- dataStream: newText
2578
- },
2579
- len: newText.length,
2580
- line: 0,
2581
- segmentId
2582
- });
2583
- const path = getRichTextEditPath(docDataModel, segmentId);
2584
- doMutation.params.actions = jsonX.editOp(textX.serialize(), path), doMutation.params.noHistory = !isCompositionEnd, doMutation.params.isCompositionEnd = isCompositionEnd;
2585
- const result = commandService.syncExecuteCommand(doMutation.id, doMutation.params);
2586
- return imeInputManagerService.pushUndoRedoMutationParams(result, doMutation.params), !!result;
2587
- }, "handler")
2588
- };
2589
- function handleInlineFormat(preCommandId, params, commandService) {
2590
- return commandService.executeCommand(SetInlineFormatCommand.id, {
2591
- preCommandId,
2592
- ...params != null ? params : {}
2593
- });
2594
- }
2595
- __name(handleInlineFormat, "handleInlineFormat");
2596
- const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetInlineFormatBoldCommand = {
2597
- id: SetInlineFormatBoldCommandId,
2598
- type: CommandType.COMMAND,
2599
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
2600
- const commandService = accessor.get(ICommandService);
2601
- return handleInlineFormat(
2602
- SetInlineFormatBoldCommandId,
2603
- params,
2604
- commandService
2605
- );
2606
- }, "handler")
2607
- }, SetInlineFormatItalicCommandId = "doc.command.set-inline-format-italic", SetInlineFormatItalicCommand = {
2608
- id: SetInlineFormatItalicCommandId,
2609
- type: CommandType.COMMAND,
2610
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
2611
- const commandService = accessor.get(ICommandService);
2612
- return handleInlineFormat(
2613
- SetInlineFormatItalicCommandId,
2614
- params,
2615
- commandService
2616
- );
2617
- }, "handler")
2618
- }, SetInlineFormatUnderlineCommandId = "doc.command.set-inline-format-underline", SetInlineFormatUnderlineCommand = {
2619
- id: SetInlineFormatUnderlineCommandId,
2620
- type: CommandType.COMMAND,
2621
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
2622
- const commandService = accessor.get(ICommandService);
2623
- return handleInlineFormat(
2624
- SetInlineFormatUnderlineCommandId,
2625
- params,
2626
- commandService
2627
- );
2628
- }, "handler")
2629
- }, SetInlineFormatStrikethroughCommandId = "doc.command.set-inline-format-strikethrough", SetInlineFormatStrikethroughCommand = {
2630
- id: SetInlineFormatStrikethroughCommandId,
2631
- type: CommandType.COMMAND,
2632
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
2633
- const commandService = accessor.get(ICommandService);
2634
- return handleInlineFormat(
2635
- SetInlineFormatStrikethroughCommandId,
2636
- params,
2637
- commandService
2638
- );
2639
- }, "handler")
2640
- }, SetInlineFormatSubscriptCommandId = "doc.command.set-inline-format-subscript", SetInlineFormatSubscriptCommand = {
2641
- id: SetInlineFormatSubscriptCommandId,
2642
- type: CommandType.COMMAND,
2643
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
2644
- const commandService = accessor.get(ICommandService);
2645
- return handleInlineFormat(
2646
- SetInlineFormatSubscriptCommandId,
2647
- params,
2648
- commandService
2649
- );
2650
- }, "handler")
2651
- }, SetInlineFormatSuperscriptCommandId = "doc.command.set-inline-format-superscript", SetInlineFormatSuperscriptCommand = {
2652
- id: SetInlineFormatSuperscriptCommandId,
2653
- type: CommandType.COMMAND,
2654
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
2655
- const commandService = accessor.get(ICommandService);
2656
- return handleInlineFormat(
2657
- SetInlineFormatSuperscriptCommandId,
2658
- params,
2659
- commandService
2660
- );
2661
- }, "handler")
2662
- }, SetInlineFormatFontSizeCommandId = "doc.command.set-inline-format-fontsize", SetInlineFormatFontSizeCommand = {
2663
- id: SetInlineFormatFontSizeCommandId,
2664
- type: CommandType.COMMAND,
2665
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
2666
- const commandService = accessor.get(ICommandService);
2667
- return handleInlineFormat(
2668
- SetInlineFormatFontSizeCommandId,
2669
- params,
2670
- commandService
2671
- );
2672
- }, "handler")
2673
- }, SetInlineFormatFontFamilyCommandId = "doc.command.set-inline-format-font-family", SetInlineFormatFontFamilyCommand = {
2674
- id: SetInlineFormatFontFamilyCommandId,
2675
- type: CommandType.COMMAND,
2676
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
2677
- const commandService = accessor.get(ICommandService);
2678
- return handleInlineFormat(
2679
- SetInlineFormatFontFamilyCommandId,
2680
- params,
2681
- commandService
2682
- );
2683
- }, "handler")
2684
- }, SetInlineFormatTextColorCommandId = "doc.command.set-inline-format-text-color", SetInlineFormatTextColorCommand = {
2685
- id: SetInlineFormatTextColorCommandId,
2686
- type: CommandType.COMMAND,
2687
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
2688
- const commandService = accessor.get(ICommandService);
2689
- return handleInlineFormat(
2690
- SetInlineFormatTextColorCommandId,
2691
- params,
2692
- commandService
2693
- );
2694
- }, "handler")
2695
- }, SetInlineFormatTextBackgroundColorCommandId = "doc.command.set-inline-format-text-background-color", SetInlineFormatTextBackgroundColorCommand = {
2696
- id: SetInlineFormatTextBackgroundColorCommandId,
2697
- type: CommandType.COMMAND,
2698
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
2699
- const commandService = accessor.get(ICommandService);
2700
- return handleInlineFormat(
2701
- SetInlineFormatTextBackgroundColorCommandId,
2702
- params,
2703
- commandService
2704
- );
2705
- }, "handler")
2706
- }, ResetInlineFormatTextBackgroundColorCommandId = "doc.command.reset-inline-format-text-background-color", ResetInlineFormatTextBackgroundColorCommand = {
2707
- id: ResetInlineFormatTextBackgroundColorCommandId,
2708
- type: CommandType.COMMAND,
2709
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
2710
- const commandService = accessor.get(ICommandService);
2711
- return handleInlineFormat(
2712
- ResetInlineFormatTextBackgroundColorCommandId,
2713
- params,
2714
- commandService
2715
- );
2716
- }, "handler")
2717
- }, COMMAND_ID_TO_FORMAT_KEY_MAP = {
2718
- [SetInlineFormatBoldCommand.id]: "bl",
2719
- [SetInlineFormatItalicCommand.id]: "it",
2720
- [SetInlineFormatUnderlineCommand.id]: "ul",
2721
- [SetInlineFormatStrikethroughCommand.id]: "st",
2722
- [SetInlineFormatFontSizeCommand.id]: "fs",
2723
- [SetInlineFormatFontFamilyCommand.id]: "ff",
2724
- [SetInlineFormatTextColorCommand.id]: "cl",
2725
- [SetInlineFormatTextBackgroundColorCommand.id]: "bg",
2726
- [ResetInlineFormatTextBackgroundColorCommand.id]: "bg",
2727
- [SetInlineFormatSubscriptCommand.id]: "va",
2728
- [SetInlineFormatSuperscriptCommand.id]: "va"
2729
- }, SetInlineFormatCommand = {
2730
- id: "doc.command.set-inline-format",
2731
- type: CommandType.COMMAND,
2732
- // eslint-disable-next-line max-lines-per-function
2733
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
2734
- const { value, preCommandId } = params, commandService = accessor.get(ICommandService), textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), docRanges = textSelectionManagerService.getDocRanges();
2735
- if (docRanges.length === 0)
2736
- return !1;
2737
- const segmentId = docRanges[0].segmentId, docDataModel = univerInstanceService.getCurrentUniverDocInstance();
2738
- if (docDataModel == null)
2739
- return !1;
2740
- const unitId = docDataModel.getUnitId();
2741
- let formatValue;
2742
- switch (preCommandId) {
2743
- case SetInlineFormatBoldCommand.id:
2744
- case SetInlineFormatItalicCommand.id:
2745
- case SetInlineFormatUnderlineCommand.id:
2746
- case SetInlineFormatStrikethroughCommand.id:
2747
- case SetInlineFormatSubscriptCommand.id:
2748
- case SetInlineFormatSuperscriptCommand.id: {
2749
- formatValue = getReverseFormatValueInSelection(
2750
- docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody().textRuns,
2751
- preCommandId,
2752
- docRanges
2753
- );
2754
- break;
2755
- }
2756
- case SetInlineFormatFontSizeCommand.id:
2757
- case SetInlineFormatFontFamilyCommand.id: {
2758
- formatValue = value;
2759
- break;
2760
- }
2761
- case SetInlineFormatTextColorCommand.id:
2762
- case SetInlineFormatTextBackgroundColorCommand.id: {
2763
- formatValue = {
2764
- rgb: value
2765
- };
2766
- break;
2767
- }
2768
- case ResetInlineFormatTextBackgroundColorCommand.id: {
2769
- formatValue = {
2770
- rgb: null
2771
- };
2772
- break;
2773
- }
2774
- default:
2775
- throw new Error(`Unknown command: ${preCommandId} in handleInlineFormat`);
2776
- }
2777
- const doMutation = {
2778
- id: RichTextEditingMutation.id,
2779
- params: {
2780
- unitId,
2781
- actions: [],
2782
- textRanges: docRanges.map(serializeDocRange)
2783
- }
2784
- }, textX = new TextX(), jsonX = JSONX.getInstance(), memoryCursor = new MemoryCursor();
2785
- memoryCursor.reset();
2786
- for (const range of docRanges) {
2787
- const { startOffset, endOffset } = range;
2788
- if (startOffset == null || endOffset == null)
2789
- continue;
2790
- const body = {
2791
- dataStream: "",
2792
- textRuns: [
2793
- {
2794
- st: 0,
2795
- ed: endOffset - startOffset,
2796
- ts: {
2797
- [COMMAND_ID_TO_FORMAT_KEY_MAP[preCommandId]]: formatValue
2798
- }
2799
- }
2800
- ]
2801
- }, len = startOffset - memoryCursor.cursor;
2802
- len !== 0 && textX.push({
2803
- t: TextXActionType.RETAIN,
2804
- len,
2805
- segmentId
2806
- }), textX.push({
2807
- t: TextXActionType.RETAIN,
2808
- body,
2809
- len: endOffset - startOffset,
2810
- segmentId
2811
- }), memoryCursor.reset(), memoryCursor.moveCursor(endOffset);
2812
- }
2813
- const path = getRichTextEditPath(docDataModel, segmentId);
2814
- return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
2815
- }, "handler")
2816
- };
2817
- function isTextDecoration(value) {
2818
- return value !== null && typeof value == "object";
2819
- }
2820
- __name(isTextDecoration, "isTextDecoration");
2821
- function getReverseFormatValueInSelection(textRuns, preCommandId, docRanges) {
2822
- let ti = 0, si = 0;
2823
- const key = COMMAND_ID_TO_FORMAT_KEY_MAP[preCommandId];
2824
- for (; ti !== textRuns.length && si !== docRanges.length; ) {
2825
- const { startOffset, endOffset } = docRanges[si], { st, ed, ts } = textRuns[ti];
2826
- if (endOffset <= st)
2827
- si++;
2828
- else if (ed <= startOffset)
2829
- ti++;
2830
- else {
2831
- if (/bl|it/.test(key))
2832
- return (ts == null ? void 0 : ts[key]) === BooleanNumber.TRUE ? BooleanNumber.FALSE : BooleanNumber.TRUE;
2833
- if (/ul|st/.test(key))
2834
- return isTextDecoration(ts == null ? void 0 : ts[key]) && (ts == null ? void 0 : ts[key]).s === BooleanNumber.TRUE ? {
2835
- s: BooleanNumber.FALSE
2836
- } : {
2837
- s: BooleanNumber.TRUE
2838
- };
2839
- if (/va/.test(key))
2840
- return preCommandId === SetInlineFormatSubscriptCommand.id ? (ts == null ? void 0 : ts[key]) === BaselineOffset.SUBSCRIPT ? BaselineOffset.NORMAL : BaselineOffset.SUBSCRIPT : (ts == null ? void 0 : ts[key]) === BaselineOffset.SUPERSCRIPT ? BaselineOffset.NORMAL : BaselineOffset.SUPERSCRIPT;
2841
- ti++;
2842
- }
2843
- }
2844
- return /bl|it/.test(key) ? BooleanNumber.TRUE : /ul|st/.test(key) ? {
2845
- s: BooleanNumber.TRUE
2846
- } : preCommandId === SetInlineFormatSubscriptCommand.id ? BaselineOffset.SUBSCRIPT : BaselineOffset.SUPERSCRIPT;
2847
- }
2848
- __name(getReverseFormatValueInSelection, "getReverseFormatValueInSelection");
2849
- const ReplaceContentCommand = {
2850
- id: "doc.command-replace-content",
2851
- type: CommandType.COMMAND,
2852
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
2853
- const { unitId, body, textRanges, segmentId = "", options } = params, univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), textSelectionManagerService = accessor.get(TextSelectionManagerService), docDataModel = univerInstanceService.getUniverDocInstance(unitId), prevBody = docDataModel == null ? void 0 : docDataModel.getSnapshot().body, selections = textSelectionManagerService.getCurrentTextRanges();
2854
- if (docDataModel == null || prevBody == null || !Array.isArray(selections) || selections.length === 0)
2855
- return !1;
2856
- const doMutation = getMutationParams(unitId, segmentId, docDataModel, prevBody, body);
2857
- return doMutation.params.textRanges = textRanges, options && (doMutation.params.options = options), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
2858
- }, "handler")
2859
- }, CoverContentCommand = {
2860
- id: "doc.command-cover-content",
2861
- type: CommandType.COMMAND,
2862
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
2863
- const { unitId, body, segmentId = "" } = params, univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), docDatModel = univerInstanceService.getUniverDocInstance(unitId), prevBody = docDatModel == null ? void 0 : docDatModel.getSnapshot().body;
2864
- if (docDatModel == null || prevBody == null)
2865
- return !1;
2866
- const doMutation = getMutationParams(unitId, segmentId, docDatModel, prevBody, body);
2867
- return doMutation.params.noNeedSetTextRange = !0, doMutation.params.noHistory = !0, commandService.syncExecuteCommand(
2868
- doMutation.id,
2869
- doMutation.params
2870
- ), undoRedoService.clearUndoRedo(unitId), !0;
2871
- }, "handler")
2872
- };
2873
- function getMutationParams(unitId, segmentId, docDatModel, prevBody, body) {
2874
- const doMutation = {
2875
- id: RichTextEditingMutation.id,
2876
- params: {
2877
- unitId,
2878
- actions: [],
2879
- textRanges: []
2880
- }
2881
- }, textX = new TextX(), jsonX = JSONX.getInstance(), deleteLen = (prevBody == null ? void 0 : prevBody.dataStream.length) - 2;
2882
- deleteLen > 0 && textX.push({
2883
- t: TextXActionType.DELETE,
2884
- len: deleteLen,
2885
- line: 0,
2886
- segmentId
2887
- }), body.dataStream.length > 0 && textX.push({
2888
- t: TextXActionType.INSERT,
2889
- body,
2890
- len: body.dataStream.length,
2891
- line: 0,
2892
- segmentId
2893
- });
2894
- const path = getRichTextEditPath(docDatModel, segmentId);
2895
- return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), doMutation;
2896
- }
2897
- __name(getMutationParams, "getMutationParams");
2898
- CommandType.COMMAND;
2899
- const SetDocZoomRatioUndoMutationFactory = /* @__PURE__ */ __name((accessor, params) => {
2900
- const documentModel = accessor.get(IUniverInstanceService).getUniverDocInstance(params.unitId), old = (documentModel == null ? void 0 : documentModel.zoomRatio) || 1;
2901
- return {
2902
- ...Tools.deepClone(params),
2903
- zoomRatio: old
2904
- };
2905
- }, "SetDocZoomRatioUndoMutationFactory"), SetDocZoomRatioOperation = {
2906
- id: "doc.operation.set-zoom-ratio",
2907
- type: CommandType.OPERATION,
2908
- handler: /* @__PURE__ */ __name((accessor, params) => {
2909
- const documentModel = accessor.get(IUniverInstanceService).getUniverDocInstance(params.unitId);
2910
- if (!documentModel)
2911
- return !1;
2912
- const documentData = documentModel.getSnapshot();
2913
- return documentData.settings == null ? documentData.settings = {
2914
- zoomRatio: params.zoomRatio
2915
- } : documentData.settings.zoomRatio = params.zoomRatio, !0;
2916
- }, "handler")
2917
- }, SetDocZoomRatioCommand = {
2918
- type: CommandType.COMMAND,
2919
- id: "doc.command.set-zoom-ratio",
2920
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
2921
- var _a11, _b, _c;
2922
- const commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), univerInstanceService = accessor.get(IUniverInstanceService);
2923
- let documentId = (_a11 = univerInstanceService.getCurrentUniverDocInstance()) == null ? void 0 : _a11.getUnitId();
2924
- if (!documentId) return !1;
2925
- let zoomRatio = 1;
2926
- if (params && (documentId = (_b = params.documentId) != null ? _b : documentId, zoomRatio = (_c = params.zoomRatio) != null ? _c : zoomRatio), !univerInstanceService.getUniverDocInstance(documentId)) return !1;
2927
- const setZoomRatioMutationParams = {
2928
- zoomRatio,
2929
- unitId: documentId
2930
- }, undoMutationParams = SetDocZoomRatioUndoMutationFactory(accessor, setZoomRatioMutationParams);
2931
- return commandService.syncExecuteCommand(SetDocZoomRatioOperation.id, setZoomRatioMutationParams) ? (undoRedoService.pushUndoRedo({
2932
- unitID: documentId,
2933
- undoMutations: [{ id: SetDocZoomRatioOperation.id, params: undoMutationParams }],
2934
- redoMutations: [{ id: SetDocZoomRatioOperation.id, params: setZoomRatioMutationParams }]
2935
- }), !0) : !1;
2936
- }, "handler")
2937
- }, MoveCursorOperation = {
2938
- id: "doc.operation.move-cursor",
2939
- type: CommandType.OPERATION,
2940
- handler: /* @__PURE__ */ __name((accessor, params) => !!params, "handler")
2941
- }, MoveSelectionOperation = {
2942
- id: "doc.operation.move-selection",
2943
- type: CommandType.OPERATION,
2944
- handler: /* @__PURE__ */ __name((accessor, params) => !!params, "handler")
2945
- }, SelectAllOperation = {
2946
- id: "doc.operation.select-all",
2947
- type: CommandType.COMMAND,
2948
- handler: /* @__PURE__ */ __name(async (accessor) => {
2949
- const univerInstanceService = accessor.get(IUniverInstanceService), textSelectionManagerService = accessor.get(TextSelectionManagerService), docDataModel = univerInstanceService.getCurrentUniverDocInstance(), activeTextRange = textSelectionManagerService.getActiveTextRangeWithStyle();
2950
- if (docDataModel == null || activeTextRange == null)
2951
- return !1;
2952
- const { segmentId } = activeTextRange, prevBody = docDataModel.getSelfOrHeaderFooterModel(segmentId).getSnapshot().body;
2953
- if (prevBody == null)
2954
- return !1;
2955
- const textRanges = [
2956
- {
2957
- startOffset: 0,
2958
- endOffset: prevBody.dataStream.length - 2
2959
- }
2960
- ];
2961
- return textSelectionManagerService.replaceTextRanges(textRanges, !1), !0;
2962
- }, "handler")
2963
- };
2964
- var __defProp$6 = Object.defineProperty, __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor, __decorateClass$6 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
2965
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
2966
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
2967
- return kind && result && __defProp$6(target, key, result), result;
2968
- }, "__decorateClass$6"), __decorateParam$6 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$6"), _a4;
2969
- let IMEInputController = (_a4 = class extends Disposable {
2970
- constructor(_univerInstanceService, _renderManagerSrv, _textSelectionRenderManager, _textSelectionManagerService, _imeInputManagerService, _commandService) {
2971
- super();
2972
- __publicField(this, "_previousIMEContent", "");
2973
- __publicField(this, "_isCompositionStart", !0);
2974
- __publicField(this, "_onStartSubscription");
2975
- __publicField(this, "_onUpdateSubscription");
2976
- __publicField(this, "_onEndSubscription");
2977
- this._univerInstanceService = _univerInstanceService, this._renderManagerSrv = _renderManagerSrv, this._textSelectionRenderManager = _textSelectionRenderManager, this._textSelectionManagerService = _textSelectionManagerService, this._imeInputManagerService = _imeInputManagerService, this._commandService = _commandService, this._initialize();
2978
- }
2979
- dispose() {
2980
- var _a11, _b, _c;
2981
- (_a11 = this._onStartSubscription) == null || _a11.unsubscribe(), (_b = this._onUpdateSubscription) == null || _b.unsubscribe(), (_c = this._onEndSubscription) == null || _c.unsubscribe();
2982
- }
2983
- _initialize() {
2984
- this._initialOnCompositionstart(), this._initialOnCompositionUpdate(), this._initialOnCompositionend();
2985
- }
2986
- _initialOnCompositionstart() {
2987
- this._onStartSubscription = this._textSelectionRenderManager.onCompositionstart$.subscribe((config) => {
2988
- if (config == null)
2989
- return;
2990
- this._resetIME();
2991
- const { activeRange } = config;
2992
- activeRange != null && this._imeInputManagerService.setActiveRange(Tools.deepClone(activeRange));
2993
- });
2994
- }
2995
- _initialOnCompositionUpdate() {
2996
- this._onUpdateSubscription = this._textSelectionRenderManager.onCompositionupdate$.subscribe(async (config) => {
2997
- this._updateContent(config, !0);
2998
- });
2999
- }
3000
- _initialOnCompositionend() {
3001
- this._onEndSubscription = this._textSelectionRenderManager.onCompositionend$.subscribe((config) => {
3002
- this._updateContent(config, !1);
3003
- });
3004
- }
3005
- async _updateContent(config, isUpdate) {
3006
- var _a11;
3007
- if (config == null)
3008
- return;
3009
- const documentModel = this._univerInstanceService.getCurrentUniverDocInstance();
3010
- if (!documentModel)
3011
- return;
3012
- const skeleton = (_a11 = this._renderManagerSrv.getRenderById(documentModel.getUnitId())) == null ? void 0 : _a11.with(DocSkeletonManagerService).getSkeleton(), { event, activeRange } = config;
3013
- if (skeleton == null || activeRange == null)
3014
- return;
3015
- const content = event.data;
3016
- content === this._previousIMEContent && isUpdate || (await this._commandService.executeCommand(IMEInputCommand.id, {
3017
- unitId: documentModel.getUnitId(),
3018
- newText: content,
3019
- oldTextLen: this._previousIMEContent.length,
3020
- isCompositionStart: this._isCompositionStart,
3021
- isCompositionEnd: !isUpdate
3022
- }), isUpdate ? (this._isCompositionStart && (this._isCompositionStart = !1), this._previousIMEContent = content) : this._resetIME());
3023
- }
3024
- _resetIME() {
3025
- this._previousIMEContent = "", this._isCompositionStart = !0, this._imeInputManagerService.clearUndoRedoMutationParamsCache(), this._imeInputManagerService.setActiveRange(null);
3026
- }
3027
- }, __name(_a4, "IMEInputController"), _a4);
3028
- IMEInputController = __decorateClass$6([
3029
- OnLifecycle(LifecycleStages.Rendered, IMEInputController),
3030
- __decorateParam$6(0, IUniverInstanceService),
3031
- __decorateParam$6(1, IRenderManagerService),
3032
- __decorateParam$6(2, ITextSelectionRenderManager),
3033
- __decorateParam$6(3, Inject(TextSelectionManagerService)),
3034
- __decorateParam$6(4, Inject(IMEInputManagerService)),
3035
- __decorateParam$6(5, ICommandService)
3036
- ], IMEInputController);
3037
- function firstLineInTable(table) {
3038
- return table.rows[0].cells[0].sections[0].columns[0].lines[0];
3039
- }
3040
- __name(firstLineInTable, "firstLineInTable");
3041
- function lastLineInTable(table) {
3042
- const lastRow = table.rows[table.rows.length - 1], lastCell = lastRow.cells[lastRow.cells.length - 1];
3043
- return getLastLine(lastCell);
3044
- }
3045
- __name(lastLineInTable, "lastLineInTable");
3046
- function findTableAfterLine(line, page) {
3047
- const { ed } = line, { skeTables } = page;
3048
- let table = null;
3049
- for (const t of skeTables.values())
3050
- if (t.st === ed + 1) {
3051
- table = t;
3052
- break;
3053
- }
3054
- return table;
3055
- }
3056
- __name(findTableAfterLine, "findTableAfterLine");
3057
- function findLineBeforeAndAfterTable(table) {
3058
- const tablePage = table == null ? void 0 : table.parent;
3059
- let lineBeforeTable = null, lineAfterTable = null;
3060
- if (table == null || tablePage == null)
3061
- return {
3062
- lineBeforeTable,
3063
- lineAfterTable
3064
- };
3065
- const { st, ed } = table, pages = tablePage.type === DocumentSkeletonPageType.CELL ? [tablePage] : tablePage.parent.pages;
3066
- return lineIterator(pages, (l) => {
3067
- l.st === ed + 1 ? lineAfterTable = l : l.ed === st - 1 && (lineBeforeTable = l);
3068
- }), {
3069
- lineBeforeTable,
3070
- lineAfterTable
3071
- };
3072
- }
3073
- __name(findLineBeforeAndAfterTable, "findLineBeforeAndAfterTable");
3074
- function findBellowCell(cell) {
3075
- const row = cell.parent, table = row == null ? void 0 : row.parent;
3076
- if (row == null || table == null)
3077
- return;
3078
- const bellowRow = table.rows[table.rows.indexOf(row) + 1];
3079
- if (bellowRow == null)
3080
- return;
3081
- const col = row.cells.indexOf(cell);
3082
- return bellowRow.cells[col];
3083
- }
3084
- __name(findBellowCell, "findBellowCell");
3085
- function findAboveCell(cell) {
3086
- const row = cell.parent, table = row == null ? void 0 : row.parent;
3087
- if (row == null || table == null)
3088
- return;
3089
- const aboveRow = table.rows[table.rows.indexOf(row) - 1];
3090
- if (aboveRow == null)
3091
- return;
3092
- const col = row.cells.indexOf(cell);
3093
- return aboveRow.cells[col];
3094
- }
3095
- __name(findAboveCell, "findAboveCell");
3096
- function findTableBeforeLine(line, page) {
3097
- const { st } = line, { skeTables } = page;
3098
- let table = null;
3099
- for (const t of skeTables.values())
3100
- if (t.ed === st - 1) {
3101
- table = t;
3102
- break;
3103
- }
3104
- return table;
3105
- }
3106
- __name(findTableBeforeLine, "findTableBeforeLine");
3107
- function firstLineInCell(cell) {
3108
- return cell.sections[0].columns[0].lines[0];
3109
- }
3110
- __name(firstLineInCell, "firstLineInCell");
3111
- function lastLineInCell(cell) {
3112
- return getLastLine(cell);
3113
- }
3114
- __name(lastLineInCell, "lastLineInCell");
3115
- var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3116
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3117
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
3118
- return kind && result && __defProp$5(target, key, result), result;
3119
- }, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$5"), _a5;
3120
- let MoveCursorController = (_a5 = class extends Disposable {
3121
- constructor(_univerInstanceService, _renderManagerService, _textSelectionManagerService, _commandService) {
3122
- super();
3123
- __publicField(this, "_onInputSubscription");
3124
- this._univerInstanceService = _univerInstanceService, this._renderManagerService = _renderManagerService, this._textSelectionManagerService = _textSelectionManagerService, this._commandService = _commandService, this._commandExecutedListener();
3125
- }
3126
- dispose() {
3127
- var _a11;
3128
- super.dispose(), (_a11 = this._onInputSubscription) == null || _a11.unsubscribe();
3129
- }
3130
- _commandExecutedListener() {
3131
- const updateCommandList = [MoveCursorOperation.id, MoveSelectionOperation.id];
3132
- this.disposeWithMe(
3133
- this._commandService.onCommandExecuted((command) => {
3134
- if (!updateCommandList.includes(command.id))
3135
- return;
3136
- const param = command.params;
3137
- switch (command.id) {
3138
- case MoveCursorOperation.id:
3139
- return this._handleMoveCursor(param.direction);
3140
- case MoveSelectionOperation.id:
3141
- return this._handleShiftMoveSelection(param.direction);
3142
- default:
3143
- throw new Error("Unknown command");
3144
- }
3145
- })
3146
- );
3147
- }
3148
- // eslint-disable-next-line max-lines-per-function, complexity
3149
- _handleShiftMoveSelection(direction) {
3150
- var _a11, _b, _c;
3151
- const activeRange = this._textSelectionManagerService.getActiveTextRangeWithStyle(), allRanges = this._textSelectionManagerService.getCurrentTextRanges(), docDataModel = this._univerInstanceService.getCurrentUniverDocInstance();
3152
- if (docDataModel == null)
3153
- return;
3154
- const skeleton = (_a11 = this._renderManagerService.getRenderById(docDataModel.getUnitId())) == null ? void 0 : _a11.with(DocSkeletonManagerService).getSkeleton(), docObject = this._getDocObject();
3155
- if (activeRange == null || skeleton == null || docObject == null)
3156
- return;
3157
- const {
3158
- startOffset,
3159
- endOffset,
3160
- style,
3161
- collapsed,
3162
- direction: rangeDirection,
3163
- segmentId,
3164
- startNodePosition,
3165
- endNodePosition,
3166
- segmentPage
3167
- } = activeRange;
3168
- if (allRanges.length > 1) {
3169
- let min = Number.POSITIVE_INFINITY, max = Number.NEGATIVE_INFINITY;
3170
- for (const range of allRanges)
3171
- min = Math.min(min, range.startOffset), max = Math.max(max, range.endOffset);
3172
- this._textSelectionManagerService.replaceTextRanges([
3173
- {
3174
- startOffset: direction === Direction.LEFT || direction === Direction.UP ? max : min,
3175
- endOffset: direction === Direction.LEFT || direction === Direction.UP ? min : max,
3176
- style
3177
- }
3178
- ], !1);
3179
- return;
3180
- }
3181
- const anchorOffset = collapsed || rangeDirection === RANGE_DIRECTION.FORWARD ? startOffset : endOffset;
3182
- let focusOffset = collapsed || rangeDirection === RANGE_DIRECTION.FORWARD ? endOffset : startOffset;
3183
- const dataStreamLength = (_b = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody().dataStream.length) != null ? _b : Number.POSITIVE_INFINITY;
3184
- if (direction === Direction.LEFT || direction === Direction.RIGHT) {
3185
- const preGlyph = skeleton.findNodeByCharIndex(focusOffset - 1, segmentId, segmentPage), curGlyph = skeleton.findNodeByCharIndex(focusOffset, segmentId, segmentPage);
3186
- focusOffset = direction === Direction.RIGHT ? focusOffset + curGlyph.count : focusOffset - ((_c = preGlyph == null ? void 0 : preGlyph.count) != null ? _c : 0), focusOffset = Math.min(dataStreamLength - 2, Math.max(0, focusOffset)), this._textSelectionManagerService.replaceTextRanges([
3187
- {
3188
- startOffset: anchorOffset,
3189
- endOffset: focusOffset,
3190
- style
3191
- }
3192
- ], !1);
3193
- } else {
3194
- const focusGlyph = skeleton.findNodeByCharIndex(focusOffset, segmentId, segmentPage), documentOffsetConfig = docObject.document.getOffsetConfig(), focusNodePosition = collapsed ? startNodePosition : rangeDirection === RANGE_DIRECTION.FORWARD ? endNodePosition : startNodePosition, newPos = this._getTopOrBottomPosition(skeleton, focusGlyph, focusNodePosition, direction === Direction.DOWN, !0);
3195
- if (newPos == null) {
3196
- const newFocusOffset = direction === Direction.UP ? 0 : dataStreamLength - 2;
3197
- if (newFocusOffset === focusOffset)
3198
- return;
3199
- this._textSelectionManagerService.replaceTextRanges([
3200
- {
3201
- startOffset: anchorOffset,
3202
- endOffset: newFocusOffset,
3203
- style
3204
- }
3205
- ], !1);
3206
- return;
3207
- }
3208
- const newActiveRange = new NodePositionConvertToCursor(documentOffsetConfig, skeleton).getRangePointData(
3209
- newPos,
3210
- newPos
3211
- ).cursorList[0];
3212
- this._textSelectionManagerService.replaceTextRanges([
3213
- {
3214
- startOffset: anchorOffset,
3215
- endOffset: newActiveRange.endOffset,
3216
- style
3217
- }
3218
- ], !1);
3219
- }
3220
- }
3221
- // eslint-disable-next-line max-lines-per-function, complexity
3222
- _handleMoveCursor(direction) {
3223
- var _a11, _b, _c, _d;
3224
- const activeRange = this._textSelectionManagerService.getActiveTextRangeWithStyle(), allRanges = this._textSelectionManagerService.getCurrentTextRanges(), docDataModel = this._univerInstanceService.getCurrentUniverDocInstance();
3225
- if (docDataModel == null)
3226
- return !1;
3227
- const skeleton = (_a11 = this._renderManagerService.getRenderById(docDataModel.getUnitId())) == null ? void 0 : _a11.with(DocSkeletonManagerService).getSkeleton(), docObject = this._getDocObject();
3228
- if (activeRange == null || skeleton == null || docObject == null || allRanges == null)
3229
- return;
3230
- const { startOffset, endOffset, style, collapsed, segmentId, startNodePosition, endNodePosition, segmentPage } = activeRange, body = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
3231
- if (body == null)
3232
- return;
3233
- const dataStreamLength = (_b = body.dataStream.length) != null ? _b : Number.POSITIVE_INFINITY, customRanges = (_c = docDataModel.getCustomRanges()) != null ? _c : [];
3234
- if (direction === Direction.LEFT || direction === Direction.RIGHT) {
3235
- let cursor;
3236
- if (!activeRange.collapsed || allRanges.length > 1) {
3237
- let min = Number.POSITIVE_INFINITY, max = Number.NEGATIVE_INFINITY;
3238
- for (const range of allRanges)
3239
- min = Math.min(min, range.startOffset), max = Math.max(max, range.endOffset);
3240
- cursor = direction === Direction.LEFT ? min : max;
3241
- } else {
3242
- const preSpan = skeleton.findNodeByCharIndex(startOffset - 1, segmentId, segmentPage), curSpan = skeleton.findNodeByCharIndex(startOffset, segmentId, segmentPage), nextGlyph = skeleton.findNodeByCharIndex(startOffset + 1, segmentId, segmentPage);
3243
- direction === Direction.LEFT ? cursor = Math.max(0, startOffset - ((_d = preSpan == null ? void 0 : preSpan.count) != null ? _d : 1)) : cursor = Math.min(dataStreamLength - 2, endOffset + curSpan.count + ((nextGlyph == null ? void 0 : nextGlyph.streamType) === DataStreamTreeTokenType.SECTION_BREAK ? 1 : 0));
3244
- }
3245
- const skipTokens = [
3246
- DataStreamTreeTokenType.CUSTOM_RANGE_START,
3247
- DataStreamTreeTokenType.CUSTOM_RANGE_END,
3248
- DataStreamTreeTokenType.TABLE_START,
3249
- DataStreamTreeTokenType.TABLE_END,
3250
- DataStreamTreeTokenType.TABLE_ROW_START,
3251
- DataStreamTreeTokenType.TABLE_ROW_END,
3252
- DataStreamTreeTokenType.TABLE_CELL_START,
3253
- DataStreamTreeTokenType.TABLE_CELL_END,
3254
- DataStreamTreeTokenType.SECTION_BREAK
3255
- ];
3256
- if (direction === Direction.LEFT)
3257
- for (; skipTokens.includes(body.dataStream[cursor]); )
3258
- cursor--;
3259
- else
3260
- for (; skipTokens.includes(body.dataStream[cursor]); )
3261
- cursor++;
3262
- customRanges.filter((range) => range.wholeEntity && range.startIndex < cursor && range.endIndex >= cursor).forEach((range) => {
3263
- direction === Direction.LEFT ? cursor = Math.min(range.startIndex, cursor) : cursor = Math.max(range.endIndex + 1, cursor);
3264
- }), this._textSelectionManagerService.replaceTextRanges([
3265
- {
3266
- startOffset: cursor,
3267
- endOffset: cursor,
3268
- style
3269
- }
3270
- ], !1);
3271
- } else {
3272
- const startNode = skeleton.findNodeByCharIndex(startOffset, segmentId, segmentPage), endNode = skeleton.findNodeByCharIndex(endOffset, segmentId, segmentPage), documentOffsetConfig = docObject.document.getOffsetConfig(), newPos = this._getTopOrBottomPosition(
3273
- skeleton,
3274
- direction === Direction.UP || collapsed ? startNode : endNode,
3275
- direction === Direction.UP || collapsed ? startNodePosition : endNodePosition,
3276
- direction === Direction.DOWN
3277
- );
3278
- if (newPos == null) {
3279
- let cursor;
3280
- collapsed ? cursor = direction === Direction.UP ? 0 : dataStreamLength - 2 : cursor = direction === Direction.UP ? startOffset : endOffset, this._textSelectionManagerService.replaceTextRanges([
3281
- {
3282
- startOffset: cursor,
3283
- endOffset: cursor,
3284
- style
3285
- }
3286
- ], !1);
3287
- return;
3288
- }
3289
- const newActiveRange = new NodePositionConvertToCursor(documentOffsetConfig, skeleton).getRangePointData(
3290
- newPos,
3291
- newPos
3292
- ).cursorList[0];
3293
- this._textSelectionManagerService.replaceTextRanges([
3294
- {
3295
- ...newActiveRange,
3296
- style
3297
- }
3298
- ], !1);
3299
- }
3300
- }
3301
- _getTopOrBottomPosition(docSkeleton, glyph, nodePosition, direction, skipCellContent = !1) {
3302
- if (glyph == null || nodePosition == null)
3303
- return;
3304
- const offsetLeft = this._getGlyphLeftOffsetInLine(glyph), line = this._getNextOrPrevLine(glyph, direction, skipCellContent);
3305
- if (line == null)
3306
- return;
3307
- const position = this._matchPositionByLeftOffset(docSkeleton, line, offsetLeft, nodePosition);
3308
- if (position != null)
3309
- return { ...position, isBack: !0 };
3310
- }
3311
- _getGlyphLeftOffsetInLine(glyph) {
3312
- const divide = glyph.parent;
3313
- if (divide == null)
3314
- return Number.NEGATIVE_INFINITY;
3315
- const divideLeft = divide.left, { left } = glyph;
3316
- return divideLeft + left;
3317
- }
3318
- _matchPositionByLeftOffset(docSkeleton, line, offsetLeft, nodePosition) {
3319
- const nearestNode = {
3320
- distance: Number.POSITIVE_INFINITY
3321
- };
3322
- for (const divide of line.divides) {
3323
- const divideLeft = divide.left;
3324
- for (const glyph of divide.glyphGroup) {
3325
- if (glyph.streamType === DataStreamTreeTokenType.SECTION_BREAK)
3326
- continue;
3327
- const { left } = glyph, leftSide = divideLeft + left, distance = Math.abs(offsetLeft - leftSide);
3328
- distance < nearestNode.distance && (nearestNode.glyph = glyph, nearestNode.distance = distance);
3329
- }
3330
- }
3331
- if (nearestNode.glyph == null)
3332
- return;
3333
- const { segmentPage } = nodePosition;
3334
- return docSkeleton.findPositionByGlyph(nearestNode.glyph, segmentPage);
3335
- }
3336
- // eslint-disable-next-line max-lines-per-function, complexity
3337
- _getNextOrPrevLine(glyph, direction, skipCellContent = !1) {
3338
- var _a11, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
3339
- const divide = glyph.parent, line = divide == null ? void 0 : divide.parent, column = line == null ? void 0 : line.parent, section = column == null ? void 0 : column.parent, page = section == null ? void 0 : section.parent;
3340
- if (divide == null || line == null || column == null || section == null || page == null)
3341
- return;
3342
- const currentLineIndex = column.lines.indexOf(line);
3343
- if (currentLineIndex === -1)
3344
- return;
3345
- let newLine;
3346
- if (page.type === DocumentSkeletonPageType.CELL && skipCellContent) {
3347
- const nLine = findAboveOrBellowCellLine(page, direction);
3348
- if (nLine)
3349
- return nLine;
3350
- }
3351
- if (direction === !0) {
3352
- newLine = column.lines[currentLineIndex + 1];
3353
- const tableAfterLine = findTableAfterLine(line, page);
3354
- if (tableAfterLine) {
3355
- const firstLine = firstLineInTable(tableAfterLine);
3356
- firstLine && (newLine = firstLine);
3357
- }
3358
- } else {
3359
- newLine = column.lines[currentLineIndex - 1];
3360
- const tableBeforeLine = findTableBeforeLine(line, page);
3361
- if (tableBeforeLine) {
3362
- const lastLine = lastLineInTable(tableBeforeLine);
3363
- lastLine && (newLine = lastLine);
3364
- }
3365
- }
3366
- if (newLine != null)
3367
- return newLine;
3368
- const currentColumnIndex = section.columns.indexOf(column);
3369
- if (currentColumnIndex === -1)
3370
- return;
3371
- if (direction === !0)
3372
- newLine = (_a11 = section.columns[currentColumnIndex + 1]) == null ? void 0 : _a11.lines[0];
3373
- else {
3374
- const prevColumnLines = (_c = (_b = section.columns) == null ? void 0 : _b[currentColumnIndex - 1]) == null ? void 0 : _c.lines;
3375
- newLine = prevColumnLines == null ? void 0 : prevColumnLines[prevColumnLines.length - 1];
3376
- }
3377
- if (newLine != null)
3378
- return newLine;
3379
- const currentSectionIndex = page.sections.indexOf(section);
3380
- if (currentSectionIndex === -1)
3381
- return;
3382
- if (direction === !0)
3383
- newLine = (_e = (_d = page.sections[currentSectionIndex - 1]) == null ? void 0 : _d.columns[0]) == null ? void 0 : _e.lines[0];
3384
- else {
3385
- const prevColumns = (_g = (_f = page.sections) == null ? void 0 : _f[currentSectionIndex - 1]) == null ? void 0 : _g.columns, column2 = prevColumns == null ? void 0 : prevColumns[prevColumns.length - 1], prevColumnLines = column2 == null ? void 0 : column2.lines;
3386
- newLine = prevColumnLines == null ? void 0 : prevColumnLines[prevColumnLines.length - 1];
3387
- }
3388
- if (newLine != null)
3389
- return newLine;
3390
- if (page.type === DocumentSkeletonPageType.CELL)
3391
- return findAboveOrBellowCellLine(page, direction);
3392
- const skeleton = page.parent;
3393
- if (skeleton == null)
3394
- return;
3395
- const currentPageIndex = skeleton.pages.indexOf(page);
3396
- if (currentPageIndex !== -1) {
3397
- if (direction === !0)
3398
- newLine = (_j = (_i = (_h = skeleton.pages[currentPageIndex + 1]) == null ? void 0 : _h.sections[0]) == null ? void 0 : _i.columns[0]) == null ? void 0 : _j.lines[0];
3399
- else {
3400
- const prevSections = (_k = skeleton.pages[currentPageIndex - 1]) == null ? void 0 : _k.sections;
3401
- if (prevSections == null)
3402
- return;
3403
- const prevColumns = (_l = prevSections[prevSections.length - 1]) == null ? void 0 : _l.columns, column2 = prevColumns[prevColumns.length - 1], prevColumnLines = column2 == null ? void 0 : column2.lines;
3404
- newLine = prevColumnLines[prevColumnLines.length - 1];
3405
- }
3406
- if (newLine != null)
3407
- return newLine;
3408
- }
3409
- }
3410
- _getDocObject() {
3411
- return getDocObject(this._univerInstanceService, this._renderManagerService);
3412
- }
3413
- }, __name(_a5, "MoveCursorController"), _a5);
3414
- MoveCursorController = __decorateClass$5([
3415
- OnLifecycle(LifecycleStages.Rendered, MoveCursorController),
3416
- __decorateParam$5(0, IUniverInstanceService),
3417
- __decorateParam$5(1, IRenderManagerService),
3418
- __decorateParam$5(2, Inject(TextSelectionManagerService)),
3419
- __decorateParam$5(3, ICommandService)
3420
- ], MoveCursorController);
3421
- function findAboveOrBellowCellLine(page, direction) {
3422
- var _a11, _b;
3423
- let newLine = null;
3424
- if (direction === !0) {
3425
- const bellowCell = findBellowCell(page);
3426
- if (bellowCell)
3427
- newLine = firstLineInCell(bellowCell);
3428
- else {
3429
- const table = (_a11 = page.parent) == null ? void 0 : _a11.parent, { lineAfterTable } = findLineBeforeAndAfterTable(table);
3430
- lineAfterTable && (newLine = lineAfterTable);
3431
- }
3432
- } else {
3433
- const aboveCell = findAboveCell(page);
3434
- if (aboveCell)
3435
- newLine = lastLineInCell(aboveCell);
3436
- else {
3437
- const table = (_b = page.parent) == null ? void 0 : _b.parent, { lineBeforeTable } = findLineBeforeAndAfterTable(table);
3438
- lineBeforeTable && (newLine = lineBeforeTable);
3439
- }
3440
- }
3441
- return newLine != null, newLine;
3442
- }
3443
- __name(findAboveOrBellowCellLine, "findAboveOrBellowCellLine");
3444
- var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3445
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3446
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
3447
- return kind && result && __defProp$4(target, key, result), result;
3448
- }, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4");
3449
- function getParagraphsInRange(activeRange, paragraphs) {
3450
- var _a11, _b;
3451
- const { startOffset, endOffset } = activeRange, results = [];
3452
- let start = -1;
3453
- for (let i = 0; i < paragraphs.length; i++) {
3454
- const paragraph = paragraphs[i], prevParagraph = paragraphs[i - 1], { startIndex } = paragraph;
3455
- startOffset > start && startOffset <= startIndex || endOffset > start && endOffset <= startIndex ? results.push({
3456
- ...paragraph,
3457
- paragraphStart: ((_a11 = prevParagraph == null ? void 0 : prevParagraph.startIndex) != null ? _a11 : -1) + 1,
3458
- paragraphEnd: paragraph.startIndex
3459
- }) : startIndex >= startOffset && startIndex <= endOffset && results.push({
3460
- ...paragraph,
3461
- paragraphStart: ((_b = prevParagraph == null ? void 0 : prevParagraph.startIndex) != null ? _b : -1) + 1,
3462
- paragraphEnd: paragraph.startIndex
3463
- }), start = startIndex;
3464
- }
3465
- return results;
3466
- }
3467
- __name(getParagraphsInRange, "getParagraphsInRange");
3468
- var _a6;
3469
- let DocAutoFormatService = (_a6 = class extends Disposable {
3470
- constructor(_univerInstanceService, _textSelectionManagerService) {
3471
- super();
3472
- __publicField(this, "_matches", /* @__PURE__ */ new Map());
3473
- this._univerInstanceService = _univerInstanceService, this._textSelectionManagerService = _textSelectionManagerService;
3474
- }
3475
- registerAutoFormat(match) {
3476
- const matchList = this._matches.get(match.id);
3477
- return matchList ? (matchList.push(match), matchList.sort((a, b) => {
3478
- var _a11, _b;
3479
- return ((_a11 = b.priority) != null ? _a11 : 0) - ((_b = a.priority) != null ? _b : 0);
3480
- })) : this._matches.set(match.id, [match]), toDisposable(() => {
3481
- const matchList2 = this._matches.get(match.id);
3482
- if (matchList2) {
3483
- const index = matchList2.findIndex((i) => i === match);
3484
- index >= 0 && matchList2.splice(index, 1);
3485
- }
3486
- });
3487
- }
3488
- onAutoFormat(id, params) {
3489
- var _a11, _b, _c, _d, _e, _f;
3490
- const autoFormats = (_a11 = this._matches.get(id)) != null ? _a11 : [], unit = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC), selection = this._textSelectionManagerService.getActiveTextRangeWithStyle();
3491
- if (unit && selection) {
3492
- const doc = unit.getSelfOrHeaderFooterModel(selection.segmentId), context = {
3493
- unit: doc,
3494
- selection,
3495
- isBody: !selection.segmentId,
3496
- paragraphs: getParagraphsInRange(selection, (_c = (_b = doc.getBody()) == null ? void 0 : _b.paragraphs) != null ? _c : []),
3497
- customRanges: getCustomRangesInterestsWithRange(selection, (_e = (_d = doc.getBody()) == null ? void 0 : _d.customRanges) != null ? _e : []),
3498
- commandId: id,
3499
- commandParams: params
3500
- }, matched = autoFormats.find((i) => i.match(context));
3501
- return (_f = matched == null ? void 0 : matched.getMutations(context)) != null ? _f : [];
3502
- }
3503
- return [];
3504
- }
3505
- }, __name(_a6, "DocAutoFormatService"), _a6);
3506
- DocAutoFormatService = __decorateClass$4([
3507
- __decorateParam$4(0, IUniverInstanceService),
3508
- __decorateParam$4(1, Inject(TextSelectionManagerService))
3509
- ], DocAutoFormatService);
3510
- const TabCommandId = "doc.command.tab", TabCommand = {
3511
- id: TabCommandId,
3512
- type: CommandType.COMMAND,
3513
- async handler(accessor, params) {
3514
- const mutations = accessor.get(DocAutoFormatService).onAutoFormat(TabCommand.id, params);
3515
- return (await sequenceExecuteAsync(mutations, accessor.get(ICommandService))).result;
3516
- }
3517
- }, AfterSpaceCommandId = "doc.command.after-space", AfterSpaceCommand = {
3518
- id: AfterSpaceCommandId,
3519
- type: CommandType.COMMAND,
3520
- async handler(accessor) {
3521
- const mutations = accessor.get(DocAutoFormatService).onAutoFormat(AfterSpaceCommand.id);
3522
- return (await sequenceExecuteAsync(mutations, accessor.get(ICommandService))).result;
3523
- }
3524
- }, EnterCommand = {
3525
- id: "doc.command.enter",
3526
- type: CommandType.COMMAND,
3527
- async handler(accessor) {
3528
- const mutations = accessor.get(DocAutoFormatService).onAutoFormat(EnterCommand.id);
3529
- return (await sequenceExecuteAsync(mutations, accessor.get(ICommandService))).result;
3530
- }
3531
- };
3532
- var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3533
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3534
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
3535
- return kind && result && __defProp$3(target, key, result), result;
3536
- }, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a7;
3537
- let NormalInputController = (_a7 = class extends Disposable {
3538
- constructor(_univerInstanceService, _renderManagerService, _textSelectionRenderManager, _commandService) {
3539
- super();
3540
- __publicField(this, "_onInputSubscription");
3541
- this._univerInstanceService = _univerInstanceService, this._renderManagerService = _renderManagerService, this._textSelectionRenderManager = _textSelectionRenderManager, this._commandService = _commandService, this._init();
3542
- }
3543
- dispose() {
3544
- var _a11;
3545
- super.dispose(), (_a11 = this._onInputSubscription) == null || _a11.unsubscribe();
3546
- }
3547
- _init() {
3548
- this._initialNormalInput();
3549
- }
3550
- _initialNormalInput() {
3551
- this._onInputSubscription = this._textSelectionRenderManager.onInput$.subscribe(async (config) => {
3552
- var _a11;
3553
- if (config == null)
3554
- return;
3555
- const documentModel = this._univerInstanceService.getCurrentUniverDocInstance();
3556
- if (!documentModel)
3557
- return;
3558
- const unitId = documentModel.getUnitId(), { event, content = "", activeRange } = config, e = event, skeleton = (_a11 = this._renderManagerService.getRenderById(documentModel.getUnitId())) == null ? void 0 : _a11.with(DocSkeletonManagerService).getSkeleton();
3559
- if (e.data == null || skeleton == null || !skeleton || !activeRange)
3560
- return;
3561
- const { segmentId } = activeRange;
3562
- await this._commandService.executeCommand(InsertCommand.id, {
3563
- unitId,
3564
- body: {
3565
- dataStream: content
3566
- },
3567
- range: activeRange,
3568
- segmentId
3569
- }), content === " " && await this._commandService.executeCommand(AfterSpaceCommand.id);
3570
- });
3571
- }
3572
- }, __name(_a7, "NormalInputController"), _a7);
3573
- NormalInputController = __decorateClass$3([
3574
- OnLifecycle(LifecycleStages.Rendered, NormalInputController),
3575
- __decorateParam$3(0, IUniverInstanceService),
3576
- __decorateParam$3(1, IRenderManagerService),
3577
- __decorateParam$3(2, ITextSelectionRenderManager),
3578
- __decorateParam$3(3, ICommandService)
3579
- ], NormalInputController);
3580
- const AlignOperationCommand = {
3581
- id: "doc.command.align-action",
3582
- type: CommandType.COMMAND,
3583
- // eslint-disable-next-line max-lines-per-function
3584
- handler: /* @__PURE__ */ __name((accessor, params) => {
3585
- var _a11;
3586
- const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), { alignType } = params, docDataModel = univerInstanceService.getCurrentUniverDocInstance();
3587
- if (docDataModel == null)
3588
- return !1;
3589
- const allRanges = textSelectionManagerService.getDocRanges();
3590
- if (allRanges.length === 0)
3591
- return !1;
3592
- const segmentId = allRanges[0].segmentId, paragraphs = (_a11 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a11.paragraphs, serializedSelections = allRanges.map(serializeDocRange);
3593
- if (paragraphs == null)
3594
- return !1;
3595
- const currentParagraphs = getParagraphsInRanges(allRanges, paragraphs), unitId = docDataModel.getUnitId(), isAlreadyAligned = currentParagraphs.every((paragraph) => {
3596
- var _a12;
3597
- return ((_a12 = paragraph.paragraphStyle) == null ? void 0 : _a12.horizontalAlign) === alignType;
3598
- }), doMutation = {
3599
- id: RichTextEditingMutation.id,
3600
- params: {
3601
- unitId,
3602
- actions: [],
3603
- textRanges: serializedSelections
3604
- }
3605
- }, memoryCursor = new MemoryCursor();
3606
- memoryCursor.reset();
3607
- const textX = new TextX(), jsonX = JSONX.getInstance();
3608
- for (const paragraph of currentParagraphs) {
3609
- const { startIndex } = paragraph;
3610
- textX.push({
3611
- t: TextXActionType.RETAIN,
3612
- len: startIndex - memoryCursor.cursor,
3613
- segmentId
3614
- });
3615
- const paragraphStyle = {
3616
- ...paragraph.paragraphStyle,
3617
- horizontalAlign: isAlreadyAligned ? HorizontalAlign.UNSPECIFIED : alignType
3618
- };
3619
- textX.push({
3620
- t: TextXActionType.RETAIN,
3621
- len: 1,
3622
- body: {
3623
- dataStream: "",
3624
- paragraphs: [
3625
- {
3626
- ...paragraph,
3627
- paragraphStyle,
3628
- startIndex: 0
3629
- }
3630
- ]
3631
- },
3632
- segmentId,
3633
- coverType: UpdateDocsAttributeType.REPLACE
3634
- }), memoryCursor.moveCursorTo(startIndex + 1);
3635
- }
3636
- const path = getRichTextEditPath(docDataModel, segmentId);
3637
- return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
3638
- }, "handler")
3639
- }, AlignLeftCommand = {
3640
- id: "doc.command.align-left",
3641
- type: CommandType.COMMAND,
3642
- handler: /* @__PURE__ */ __name((accessor) => accessor.get(ICommandService).syncExecuteCommand(AlignOperationCommand.id, {
3643
- alignType: HorizontalAlign.LEFT
3644
- }), "handler")
3645
- }, AlignCenterCommand = {
3646
- id: "doc.command.align-center",
3647
- type: CommandType.COMMAND,
3648
- handler: /* @__PURE__ */ __name((accessor) => accessor.get(ICommandService).syncExecuteCommand(AlignOperationCommand.id, {
3649
- alignType: HorizontalAlign.CENTER
3650
- }), "handler")
3651
- }, AlignRightCommand = {
3652
- id: "doc.command.align-right",
3653
- type: CommandType.COMMAND,
3654
- handler: /* @__PURE__ */ __name((accessor) => accessor.get(ICommandService).syncExecuteCommand(AlignOperationCommand.id, {
3655
- alignType: HorizontalAlign.RIGHT
3656
- }), "handler")
3657
- }, AlignJustifyCommand = {
3658
- id: "doc.command.align-justify",
3659
- type: CommandType.COMMAND,
3660
- handler: /* @__PURE__ */ __name((accessor) => accessor.get(ICommandService).syncExecuteCommand(AlignOperationCommand.id, {
3661
- alignType: HorizontalAlign.JUSTIFIED
3662
- }), "handler")
3663
- };
3664
- var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor, __decorateClass$2 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
3665
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
3666
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
3667
- return kind && result && __defProp$2(target, key, result), result;
3668
- }, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a8;
3669
- let DocCustomRangeController = (_a8 = class extends Disposable {
3670
- constructor(_commandService, _textSelectionManagerService, _univerInstanceService) {
3671
- super(), this._commandService = _commandService, this._textSelectionManagerService = _textSelectionManagerService, this._univerInstanceService = _univerInstanceService, this._initSelectionChange();
3672
- }
3673
- _transformCustomRange(doc, selection) {
3674
- var _a11;
3675
- const { startOffset, endOffset, collapsed } = selection, customRanges = (_a11 = doc.getCustomRanges()) == null ? void 0 : _a11.filter((range) => !range.wholeEntity || startOffset <= range.startIndex && endOffset > range.endIndex ? !1 : collapsed ? range.startIndex < startOffset && range.endIndex >= endOffset : isSegmentIntersects(startOffset, endOffset - 1, range.startIndex, range.endIndex));
3676
- if (customRanges != null && customRanges.length) {
3677
- let start = startOffset, end = endOffset;
3678
- return customRanges.forEach((range) => {
3679
- start = Math.min(range.startIndex, start), end = Math.max(range.endIndex + 1, end);
3680
- }), {
3681
- ...selection,
3682
- startOffset: start,
3683
- endOffset: end,
3684
- collapsed: start === end
3685
- };
3686
- }
3687
- return selection;
3688
- }
3689
- _initSelectionChange() {
3690
- this.disposeWithMe(this._commandService.onCommandExecuted((commandInfo) => {
3691
- if (commandInfo.id === SetTextSelectionsOperation.id) {
3692
- const params = commandInfo.params, { unitId, ranges, isEditing } = params, doc = this._univerInstanceService.getUnit(unitId);
3693
- if (!doc)
3694
- return;
3695
- const transformedRanges = ranges.map((range) => this._transformCustomRange(doc, range));
3696
- transformedRanges.some((range, i) => ranges[i] !== range) && this._textSelectionManagerService.replaceTextRanges(transformedRanges, isEditing);
3697
- }
3698
- }));
3699
- }
3700
- }, __name(_a8, "DocCustomRangeController"), _a8);
3701
- DocCustomRangeController = __decorateClass$2([
3702
- OnLifecycle(LifecycleStages.Ready, DocCustomRangeController),
3703
- __decorateParam$2(0, ICommandService),
3704
- __decorateParam$2(1, Inject(TextSelectionManagerService)),
3705
- __decorateParam$2(2, IUniverInstanceService)
3706
- ], DocCustomRangeController);
3707
- const DocsRenameMutation = {
3708
- id: "doc.mutation.rename-doc",
3709
- type: CommandType.MUTATION,
3710
- handler: /* @__PURE__ */ __name((accessor, params) => {
3711
- const doc = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
3712
- return doc ? (doc.setName(params.name), !0) : !1;
3713
- }, "handler")
3714
- }, CreateDocTableCommandId = "doc.command.create-table", CreateDocTableCommand = {
3715
- id: CreateDocTableCommandId,
3716
- type: CommandType.COMMAND,
3717
- // eslint-disable-next-line max-lines-per-function
3718
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
3719
- var _a11, _b, _c, _d, _e, _f;
3720
- const { rowCount, colCount } = params, textSelectionManagerService = accessor.get(TextSelectionManagerService$1), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), activeRange = textSelectionManagerService.getActiveTextRangeWithStyle();
3721
- if (activeRange == null)
3722
- return !1;
3723
- const { segmentId, segmentPage } = activeRange, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), body = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
3724
- if (docDataModel == null || body == null)
3725
- return !1;
3726
- const unitId = docDataModel.getUnitId(), docSkeletonManagerService = getCommandSkeleton$1(accessor, unitId), skeleton = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getSkeleton();
3727
- if (skeleton == null)
3728
- return !1;
3729
- const { startOffset } = getInsertSelection$1(activeRange, body), prevParagraph = ((_a11 = body.paragraphs) != null ? _a11 : []).find((p) => p.startIndex >= startOffset), curGlyph = skeleton.findNodeByCharIndex(startOffset, segmentId, segmentPage), line = (_b = curGlyph == null ? void 0 : curGlyph.parent) == null ? void 0 : _b.parent, preGlyph = skeleton.findNodeByCharIndex(startOffset - 1, segmentId, segmentPage), isInParagraph = preGlyph && preGlyph.content !== "\r";
3730
- if (curGlyph == null || line == null)
3731
- return !1;
3732
- const needCreateParagraph = isInParagraph || line.isBehindTable, textX = new TextX(), jsonX = JSONX.getInstance(), rawActions = [], cursor = startOffset + (needCreateParagraph ? 4 : 3), textRanges = [{
3733
- startOffset: cursor,
3734
- endOffset: cursor,
3735
- collapsed: !0
3736
- }], doMutation = {
3737
- id: RichTextEditingMutation$1.id,
3738
- params: {
3739
- unitId,
3740
- actions: [],
3741
- textRanges
3742
- }
3743
- };
3744
- startOffset > 0 && textX.push({
3745
- t: TextXActionType.RETAIN,
3746
- len: startOffset,
3747
- segmentId
3748
- }), needCreateParagraph && textX.push({
3749
- t: TextXActionType.INSERT,
3750
- body: {
3751
- dataStream: DataStreamTreeTokenType.PARAGRAPH,
3752
- paragraphs: generateParagraphs$1(DataStreamTreeTokenType.PARAGRAPH, prevParagraph)
3753
- },
3754
- len: 1,
3755
- line: 0,
3756
- segmentId
3757
- });
3758
- const { dataStream: tableDataStream, paragraphs: tableParagraphs, sectionBreaks } = genEmptyTable(rowCount, colCount), page = (_f = (_e = (_d = (_c = curGlyph.parent) == null ? void 0 : _c.parent) == null ? void 0 : _d.parent) == null ? void 0 : _e.parent) == null ? void 0 : _f.parent;
3759
- if (page == null)
3760
- return !1;
3761
- const { pageWidth, marginLeft, marginRight } = page, tableSource = genTableSource(rowCount, colCount, pageWidth - marginLeft - marginRight);
3762
- textX.push({
3763
- t: TextXActionType.INSERT,
3764
- body: {
3765
- dataStream: tableDataStream,
3766
- paragraphs: tableParagraphs,
3767
- sectionBreaks,
3768
- tables: [
3769
- {
3770
- startIndex: 0,
3771
- endIndex: tableDataStream.length,
3772
- tableId: tableSource.tableId
3773
- }
3774
- ]
3775
- },
3776
- len: tableDataStream.length,
3777
- line: 0,
3778
- segmentId
3779
- });
3780
- const path = getRichTextEditPath$1(docDataModel, segmentId);
3781
- rawActions.push(jsonX.editOp(textX.serialize(), path));
3782
- const insertTableSource = jsonX.insertOp(["tableSource", tableSource.tableId], tableSource);
3783
- return rawActions.push(insertTableSource), doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
3784
- }, "handler")
3785
- }, DocTableDeleteRowsCommand = {
3786
- id: "doc.table.delete-rows",
3787
- type: CommandType.COMMAND,
3788
- // eslint-disable-next-line max-lines-per-function
3789
- handler: /* @__PURE__ */ __name(async (accessor) => {
3790
- const textSelectionManagerService = accessor.get(TextSelectionManagerService$1), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), activeRectRanges = textSelectionManagerService.getCurrentRectRanges(), activeTextRange = textSelectionManagerService.getActiveTextRange(), rangeInfo = getRangeInfoFromRanges(activeTextRange, activeRectRanges);
3791
- if (rangeInfo == null)
3792
- return !1;
3793
- const { segmentId } = rangeInfo, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), body = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
3794
- if (docDataModel == null || body == null)
3795
- return !1;
3796
- const docSkeletonManagerService = getCommandSkeleton$1(accessor, docDataModel.getUnitId());
3797
- if (docSkeletonManagerService == null)
3798
- return !1;
3799
- const viewModel = docSkeletonManagerService.getViewModel(), unitId = docDataModel == null ? void 0 : docDataModel.getUnitId(), textX = new TextX(), jsonX = JSONX.getInstance(), actionParams = getDeleteRowsActionsParams(rangeInfo, viewModel);
3800
- if (actionParams == null)
3801
- return !1;
3802
- const { offset, rowIndexes, len, tableId, cursor, selectWholeTable } = actionParams;
3803
- if (selectWholeTable)
3804
- return commandService.executeCommand(DocTableDeleteTableCommand.id);
3805
- const rawActions = [], textRanges = [{
3806
- startOffset: cursor,
3807
- endOffset: cursor,
3808
- collapsed: !0
3809
- }], doMutation = {
3810
- id: RichTextEditingMutation$1.id,
3811
- params: {
3812
- unitId,
3813
- actions: [],
3814
- textRanges
3815
- }
3816
- };
3817
- offset > 0 && textX.push({
3818
- t: TextXActionType.RETAIN,
3819
- len: offset,
3820
- segmentId
3821
- }), textX.push({
3822
- t: TextXActionType.DELETE,
3823
- len,
3824
- line: 0,
3825
- segmentId
3826
- });
3827
- const path = getRichTextEditPath$1(docDataModel, segmentId);
3828
- rawActions.push(jsonX.editOp(textX.serialize(), path));
3829
- for (const index of rowIndexes.reverse()) {
3830
- const action = jsonX.removeOp(["tableSource", tableId, "tableRows", index]);
3831
- rawActions.push(action);
3832
- }
3833
- return doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
3834
- }, "handler")
3835
- }, DocTableDeleteColumnsCommand = {
3836
- id: "doc.table.delete-columns",
3837
- type: CommandType.COMMAND,
3838
- // eslint-disable-next-line max-lines-per-function
3839
- handler: /* @__PURE__ */ __name(async (accessor) => {
3840
- const textSelectionManagerService = accessor.get(TextSelectionManagerService$1), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), activeRectRanges = textSelectionManagerService.getCurrentRectRanges(), activeTextRange = textSelectionManagerService.getActiveTextRange(), rangeInfo = getRangeInfoFromRanges(activeTextRange, activeRectRanges);
3841
- if (rangeInfo == null)
3842
- return !1;
3843
- const { segmentId } = rangeInfo, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), body = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
3844
- if (docDataModel == null || body == null)
3845
- return !1;
3846
- const docSkeletonManagerService = getCommandSkeleton$1(accessor, docDataModel.getUnitId());
3847
- if (docSkeletonManagerService == null)
3848
- return !1;
3849
- const viewModel = docSkeletonManagerService.getViewModel(), unitId = docDataModel == null ? void 0 : docDataModel.getUnitId(), textX = new TextX(), jsonX = JSONX.getInstance(), actionParams = getDeleteColumnsActionParams(rangeInfo, viewModel);
3850
- if (actionParams == null)
3851
- return !1;
3852
- const { offsets, columnIndexes, tableId, cursor, rowCount, selectWholeTable } = actionParams;
3853
- if (selectWholeTable)
3854
- return commandService.executeCommand(DocTableDeleteTableCommand.id);
3855
- const rawActions = [], textRanges = [{
3856
- startOffset: cursor,
3857
- endOffset: cursor,
3858
- collapsed: !0
3859
- }], doMutation = {
3860
- id: RichTextEditingMutation$1.id,
3861
- params: {
3862
- unitId,
3863
- actions: [],
3864
- textRanges
3865
- }
3866
- };
3867
- for (const offset of offsets) {
3868
- const { retain, delete: deleteLen } = offset;
3869
- retain > 0 && textX.push({
3870
- t: TextXActionType.RETAIN,
3871
- len: retain,
3872
- segmentId
3873
- }), textX.push({
3874
- t: TextXActionType.DELETE,
3875
- len: deleteLen,
3876
- line: 0,
3877
- segmentId
3878
- });
3879
- }
3880
- const path = getRichTextEditPath$1(docDataModel, segmentId);
3881
- rawActions.push(jsonX.editOp(textX.serialize(), path)), columnIndexes.reverse();
3882
- for (let i = 0; i < rowCount; i++)
3883
- for (const index of columnIndexes) {
3884
- const action = jsonX.removeOp(["tableSource", tableId, "tableRows", i, "tableCells", index]);
3885
- rawActions.push(action);
3886
- }
3887
- for (const index of columnIndexes) {
3888
- const action = jsonX.removeOp(["tableSource", tableId, "tableColumns", index]);
3889
- rawActions.push(action);
3890
- }
3891
- return doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
3892
- }, "handler")
3893
- }, DocTableDeleteTableCommand = {
3894
- id: "doc.table.delete-table",
3895
- type: CommandType.COMMAND,
3896
- // eslint-disable-next-line max-lines-per-function
3897
- handler: /* @__PURE__ */ __name(async (accessor) => {
3898
- const textSelectionManagerService = accessor.get(TextSelectionManagerService$1), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), activeRectRanges = textSelectionManagerService.getCurrentRectRanges(), activeTextRange = textSelectionManagerService.getActiveTextRange(), rangeInfo = getRangeInfoFromRanges(activeTextRange, activeRectRanges);
3899
- if (rangeInfo == null)
3900
- return !1;
3901
- const { segmentId } = rangeInfo, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), body = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
3902
- if (docDataModel == null || body == null)
3903
- return !1;
3904
- const docSkeletonManagerService = getCommandSkeleton$1(accessor, docDataModel.getUnitId());
3905
- if (docSkeletonManagerService == null)
3906
- return !1;
3907
- const viewModel = docSkeletonManagerService.getViewModel(), unitId = docDataModel == null ? void 0 : docDataModel.getUnitId(), textX = new TextX(), jsonX = JSONX.getInstance(), actionParams = getDeleteTableActionParams(rangeInfo, viewModel);
3908
- if (actionParams == null)
3909
- return !1;
3910
- const { offset, len, tableId, cursor } = actionParams, rawActions = [], textRanges = [{
3911
- startOffset: cursor,
3912
- endOffset: cursor,
3913
- collapsed: !0
3914
- }], doMutation = {
3915
- id: RichTextEditingMutation$1.id,
3916
- params: {
3917
- unitId,
3918
- actions: [],
3919
- textRanges
3920
- }
3921
- };
3922
- offset > 0 && textX.push({
3923
- t: TextXActionType.RETAIN,
3924
- len: offset,
3925
- segmentId
3926
- }), textX.push({
3927
- t: TextXActionType.DELETE,
3928
- len,
3929
- line: 0,
3930
- segmentId
3931
- });
3932
- const path = getRichTextEditPath$1(docDataModel, segmentId);
3933
- rawActions.push(jsonX.editOp(textX.serialize(), path));
3934
- const action = jsonX.removeOp(["tableSource", tableId]);
3935
- return rawActions.push(action), doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
3936
- }, "handler")
3937
- }, DocTableInsertRowCommandId = "doc.command.table-insert-row", DocTableInsertColumnCommandId = "doc.command.table-insert-column", DocTableInsertRowAboveCommandId = "doc.command.table-insert-row-above", DocTableInsertRowBellowCommandId = "doc.command.table-insert-row-bellow", DocTableInsertColumnLeftCommandId = "doc.command.table-insert-column-left", DocTableInsertColumnRightCommandId = "doc.command.table-insert-column-right", DocTableInsertRowAboveCommand = {
3938
- id: DocTableInsertRowAboveCommandId,
3939
- type: CommandType.COMMAND,
3940
- handler: /* @__PURE__ */ __name(async (accessor) => accessor.get(ICommandService).executeCommand(DocTableInsertRowCommandId, { position: INSERT_ROW_POSITION.ABOVE }), "handler")
3941
- }, DocTableInsertRowBellowCommand = {
3942
- id: DocTableInsertRowBellowCommandId,
3943
- type: CommandType.COMMAND,
3944
- handler: /* @__PURE__ */ __name(async (accessor) => accessor.get(ICommandService).executeCommand(DocTableInsertRowCommandId, { position: INSERT_ROW_POSITION.BELLOW }), "handler")
3945
- }, DocTableInsertColumnLeftCommand = {
3946
- id: DocTableInsertColumnLeftCommandId,
3947
- type: CommandType.COMMAND,
3948
- handler: /* @__PURE__ */ __name(async (accessor) => accessor.get(ICommandService).executeCommand(DocTableInsertColumnCommandId, { position: INSERT_COLUMN_POSITION.LEFT }), "handler")
3949
- }, DocTableInsertColumnRightCommand = {
3950
- id: DocTableInsertColumnRightCommandId,
3951
- type: CommandType.COMMAND,
3952
- handler: /* @__PURE__ */ __name(async (accessor) => accessor.get(ICommandService).executeCommand(DocTableInsertColumnCommandId, { position: INSERT_COLUMN_POSITION.RIGHT }), "handler")
3953
- }, DocTableInsertRowCommand = {
3954
- id: DocTableInsertRowCommandId,
3955
- type: CommandType.COMMAND,
3956
- // eslint-disable-next-line max-lines-per-function
3957
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
3958
- const { position } = params, textSelectionManagerService = accessor.get(TextSelectionManagerService$1), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), activeRectRanges = textSelectionManagerService.getCurrentRectRanges(), activeTextRange = textSelectionManagerService.getActiveTextRange(), rangeInfo = getRangeInfoFromRanges(activeTextRange, activeRectRanges);
3959
- if (rangeInfo == null)
3960
- return !1;
3961
- const { segmentId } = rangeInfo, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), body = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
3962
- if (docDataModel == null || body == null)
3963
- return !1;
3964
- const docSkeletonManagerService = getCommandSkeleton$1(accessor, docDataModel.getUnitId());
3965
- if (docSkeletonManagerService == null)
3966
- return !1;
3967
- const viewModel = docSkeletonManagerService.getViewModel(), unitId = docDataModel == null ? void 0 : docDataModel.getUnitId(), textX = new TextX(), jsonX = JSONX.getInstance(), actionParams = getInsertRowActionsParams(rangeInfo, position, viewModel);
3968
- if (actionParams == null)
3969
- return !1;
3970
- const { offset, colCount, tableId, insertRowIndex } = actionParams, rawActions = [], cursor = offset + 2, textRanges = [{
3971
- startOffset: cursor,
3972
- endOffset: cursor,
3973
- collapsed: !0
3974
- }], doMutation = {
3975
- id: RichTextEditingMutation$1.id,
3976
- params: {
3977
- unitId,
3978
- actions: [],
3979
- textRanges
3980
- }
3981
- };
3982
- offset > 0 && textX.push({
3983
- t: TextXActionType.RETAIN,
3984
- len: offset,
3985
- segmentId
3986
- });
3987
- const insertBody = getInsertRowBody(colCount);
3988
- textX.push({
3989
- t: TextXActionType.INSERT,
3990
- body: insertBody,
3991
- len: insertBody.dataStream.length,
3992
- line: 0,
3993
- segmentId
3994
- });
3995
- const path = getRichTextEditPath$1(docDataModel, segmentId);
3996
- rawActions.push(jsonX.editOp(textX.serialize(), path));
3997
- const insertRow = getEmptyTableRow(colCount), insertTableSource = jsonX.insertOp(["tableSource", tableId, "tableRows", insertRowIndex], insertRow);
3998
- return rawActions.push(insertTableSource), doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
3999
- }, "handler")
4000
- }, DocTableInsertColumnCommand = {
4001
- id: DocTableInsertColumnCommandId,
4002
- type: CommandType.COMMAND,
4003
- // eslint-disable-next-line max-lines-per-function
4004
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
4005
- var _a11, _b, _c;
4006
- const { position } = params, textSelectionManagerService = accessor.get(TextSelectionManagerService$1), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), activeRectRanges = textSelectionManagerService.getCurrentRectRanges(), activeTextRange = textSelectionManagerService.getActiveTextRange(), rangeInfo = getRangeInfoFromRanges(activeTextRange, activeRectRanges);
4007
- if (rangeInfo == null)
4008
- return !1;
4009
- const { segmentId } = rangeInfo, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), body = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
4010
- if (docDataModel == null || body == null)
4011
- return !1;
4012
- const docSkeletonManagerService = getCommandSkeleton$1(accessor, docDataModel.getUnitId());
4013
- if (docSkeletonManagerService == null)
4014
- return !1;
4015
- const viewModel = docSkeletonManagerService.getViewModel(), unitId = docDataModel == null ? void 0 : docDataModel.getUnitId(), textX = new TextX(), jsonX = JSONX.getInstance(), actionParams = getInsertColumnActionsParams(rangeInfo, position, viewModel);
4016
- if (actionParams == null)
4017
- return !1;
4018
- const { offsets, columnIndex, tableId, rowCount } = actionParams, rawActions = [], cursor = offsets[0] + 1, textRanges = [{
4019
- startOffset: cursor,
4020
- endOffset: cursor,
4021
- collapsed: !0
4022
- }], doMutation = {
4023
- id: RichTextEditingMutation$1.id,
4024
- params: {
4025
- unitId,
4026
- actions: [],
4027
- textRanges
4028
- }
4029
- };
4030
- for (const offset of offsets) {
4031
- textX.push({
4032
- t: TextXActionType.RETAIN,
4033
- len: offset,
4034
- segmentId
4035
- });
4036
- const insertBody = getInsertColumnBody();
4037
- textX.push({
4038
- t: TextXActionType.INSERT,
4039
- body: insertBody,
4040
- len: insertBody.dataStream.length,
4041
- line: 0,
4042
- segmentId
4043
- });
4044
- }
4045
- const path = getRichTextEditPath$1(docDataModel, segmentId);
4046
- rawActions.push(jsonX.editOp(textX.serialize(), path));
4047
- for (let i = 0; i < rowCount; i++) {
4048
- const insertCell = getEmptyTableCell(), insertTableSource = jsonX.insertOp(["tableSource", tableId, "tableRows", i, "tableCells", columnIndex], insertCell);
4049
- rawActions.push(insertTableSource);
4050
- }
4051
- const snapshot = docDataModel.getSnapshot(), documentStyle = snapshot.documentStyle, { marginLeft = 0, marginRight = 0 } = documentStyle, pageWidth = ((_b = (_a11 = documentStyle.pageSize) == null ? void 0 : _a11.width) != null ? _b : 800) - marginLeft - marginRight, tableColumns = (_c = snapshot == null ? void 0 : snapshot.tableSource) == null ? void 0 : _c[tableId].tableColumns, { newColWidth, widths } = getColumnWidths(pageWidth, tableColumns, columnIndex);
4052
- for (let i = 0; i < widths.length; i++) {
4053
- const action = jsonX.replaceOp(["tableSource", tableId, "tableColumns", i, "size", "width", "v"], tableColumns[i].size.width.v, widths[i]);
4054
- rawActions.push(action);
4055
- }
4056
- const insertCol = getTableColumn(newColWidth), insertTableColumn = jsonX.insertOp(["tableSource", tableId, "tableColumns", columnIndex], insertCol);
4057
- return rawActions.push(insertTableColumn), doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
4058
- }, "handler")
4059
- }, DocTableTabCommand = {
4060
- id: "doc.table.tab-in-table",
4061
- type: CommandType.COMMAND,
4062
- handler: /* @__PURE__ */ __name(async (accessor, params) => {
4063
- const { shift } = params, textSelectionManager = accessor.get(TextSelectionManagerService), activeTextRange = textSelectionManager.getActiveTextRangeWithStyle(), commandService = accessor.get(ICommandService), docDataModel = accessor.get(IUniverInstanceService).getCurrentUniverDocInstance();
4064
- if (!docDataModel)
4065
- return !1;
4066
- const unitId = docDataModel.getUnitId(), docSkeletonManagerService = getCommandSkeleton(accessor, unitId), skeleton = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getSkeleton(), viewModel = skeleton == null ? void 0 : skeleton.getViewModel().getSelfOrHeaderFooterViewModel(activeTextRange == null ? void 0 : activeTextRange.segmentId);
4067
- if (viewModel == null || activeTextRange == null)
4068
- return !1;
4069
- let offsets = null;
4070
- if (shift ? offsets = getCellOffsets(viewModel, activeTextRange, CellPosition.PREV) : offsets = getCellOffsets(viewModel, activeTextRange, CellPosition.NEXT), offsets) {
4071
- const { startOffset, endOffset } = offsets, textRanges = [{
4072
- startOffset,
4073
- endOffset
4074
- }];
4075
- return textSelectionManager.replaceTextRanges(textRanges), !0;
4076
- }
4077
- return shift === !1 ? await commandService.executeCommand(DocTableInsertRowCommand.id, {
4078
- position: INSERT_ROW_POSITION.BELLOW
4079
- }) : !0;
4080
- }, "handler")
4081
- }, PLUGIN_CONFIG_KEY = "docs.config", defaultPluginConfig = {};
4082
- var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
4083
- for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
4084
- (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
4085
- return kind && result && __defProp$1(target, key, result), result;
4086
- }, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1");
4087
- const PLUGIN_NAME = "DOCS_PLUGIN";
4088
- var _a9;
4089
- let UniverDocsPlugin = (_a9 = class extends Plugin {
4090
- constructor(_config = defaultPluginConfig, _injector, _configService) {
4091
- super(), this._config = _config, this._injector = _injector, this._configService = _configService;
4092
- const { ...rest } = this._config;
4093
- this._configService.setConfig(PLUGIN_CONFIG_KEY, rest), this._initializeDependencies(_injector), this._initializeCommands();
4094
- }
4095
- _initializeCommands() {
4096
- [
4097
- MoveCursorOperation,
4098
- MoveSelectionOperation,
4099
- DeleteLeftCommand,
4100
- DeleteRightCommand,
4101
- SetInlineFormatBoldCommand,
4102
- SetInlineFormatItalicCommand,
4103
- SetInlineFormatUnderlineCommand,
4104
- SetInlineFormatStrikethroughCommand,
4105
- SetInlineFormatSubscriptCommand,
4106
- SetInlineFormatSuperscriptCommand,
4107
- SetInlineFormatFontSizeCommand,
4108
- SetInlineFormatFontFamilyCommand,
4109
- SetInlineFormatTextColorCommand,
4110
- ResetInlineFormatTextBackgroundColorCommand,
4111
- SetInlineFormatTextBackgroundColorCommand,
4112
- SetInlineFormatCommand,
4113
- BreakLineCommand,
4114
- InsertCommand,
4115
- DeleteCommand,
4116
- DeleteCustomBlockCommand,
4117
- UpdateCommand,
4118
- IMEInputCommand,
4119
- MergeTwoParagraphCommand,
4120
- RichTextEditingMutation,
4121
- ReplaceContentCommand,
4122
- CoverContentCommand,
4123
- SetDocZoomRatioCommand,
4124
- SetDocZoomRatioOperation,
4125
- SetTextSelectionsOperation,
4126
- SelectAllOperation,
4127
- OrderListCommand,
4128
- BulletListCommand,
4129
- ListOperationCommand,
4130
- AlignLeftCommand,
4131
- AlignCenterCommand,
4132
- AlignRightCommand,
4133
- AlignOperationCommand,
4134
- AlignJustifyCommand,
4135
- CreateDocTableCommand,
4136
- DocTableInsertRowCommand,
4137
- DocTableInsertRowAboveCommand,
4138
- DocTableInsertRowBellowCommand,
4139
- DocTableInsertColumnCommand,
4140
- DocTableInsertColumnLeftCommand,
4141
- DocTableInsertColumnRightCommand,
4142
- DocTableDeleteRowsCommand,
4143
- DocTableDeleteColumnsCommand,
4144
- DocTableDeleteTableCommand,
4145
- DocTableTabCommand,
4146
- DocsRenameMutation,
4147
- TabCommand,
4148
- AfterSpaceCommand,
4149
- EnterCommand,
4150
- ChangeListNestingLevelCommand,
4151
- ChangeListTypeCommand,
4152
- CheckListCommand,
4153
- ToggleCheckListCommand,
4154
- QuickListCommand
4155
- ].forEach((command) => {
4156
- this._injector.get(ICommandService).registerCommand(command);
4157
- });
351
+ _initializeCommands() {
352
+ [
353
+ RichTextEditingMutation,
354
+ DocsRenameMutation,
355
+ SetTextSelectionsOperation
356
+ ].forEach((command) => {
357
+ this._injector.get(ICommandService).registerCommand(command);
358
+ });
4158
359
  }
4159
360
  _initializeDependencies(docInjector) {
4160
361
  [
4161
362
  // services
4162
- [DocStateChangeManagerService],
4163
- [IMEInputManagerService],
4164
- [
4165
- ITextSelectionRenderManager,
4166
- {
4167
- useClass: TextSelectionRenderManager
4168
- }
4169
- ],
4170
- [TextSelectionManagerService],
4171
- [DocAutoFormatService],
363
+ [DocSelectionManagerService],
364
+ [DocStateEmitService],
4172
365
  // controllers
4173
- [NormalInputController],
4174
- [IMEInputController],
4175
- [MoveCursorController],
4176
366
  [DocCustomRangeController]
4177
367
  ].forEach((d) => docInjector.add(d));
4178
368
  }
4179
- }, __name(_a9, "UniverDocsPlugin"), __publicField(_a9, "pluginName", PLUGIN_NAME), __publicField(_a9, "type", UniverInstanceType.UNIVER_DOC), _a9);
369
+ }, __name(_a4, "UniverDocsPlugin"), __publicField(_a4, "pluginName", PLUGIN_NAME), __publicField(_a4, "type", UniverInstanceType.UNIVER_DOC), _a4);
4180
370
  UniverDocsPlugin = __decorateClass$1([
4181
371
  __decorateParam$1(1, Inject(Injector)),
4182
372
  __decorateParam$1(2, IConfigService)
4183
373
  ], UniverDocsPlugin);
4184
- const getPlainTextFormBody = /* @__PURE__ */ __name((body) => {
4185
- let str = body.dataStream;
4186
- return body.dataStream.endsWith(`\r
4187
- `) && (str = body.dataStream.slice(0, -2)), str.replaceAll(DataStreamTreeTokenType.CUSTOM_RANGE_START, "").replaceAll(DataStreamTreeTokenType.CUSTOM_RANGE_END, "");
4188
- }, "getPlainTextFormBody"), getPlainTextFormDocument = /* @__PURE__ */ __name((data) => data.body ? getPlainTextFormBody(data.body) : "", "getPlainTextFormDocument");
4189
- function addCustomRangeTextX(param, body) {
4190
- const { range, rangeId, rangeType, segmentId } = param, actualRange = getSelectionForAddCustomRange(range, body);
4191
- if (!actualRange)
4192
- return null;
4193
- const { startOffset: start, endOffset: end } = actualRange, textX = new TextX();
4194
- return start > 0 && textX.push({
4195
- t: TextXActionType.RETAIN,
4196
- len: start,
4197
- segmentId
4198
- }), textX.push({
4199
- t: TextXActionType.INSERT,
4200
- body: {
4201
- dataStream: DataStreamTreeTokenType.CUSTOM_RANGE_START
4202
- },
4203
- len: 1,
4204
- line: 0
4205
- }), textX.push({
4206
- t: TextXActionType.RETAIN,
4207
- body: {
4208
- dataStream: ""
4209
- },
4210
- len: end - start,
4211
- segmentId
4212
- }), textX.push({
4213
- t: TextXActionType.INSERT,
4214
- body: {
4215
- dataStream: DataStreamTreeTokenType.CUSTOM_RANGE_END,
4216
- customRanges: [
4217
- {
4218
- rangeId,
4219
- rangeType,
4220
- startIndex: -(end - start) - 1,
4221
- endIndex: 0
4222
- }
4223
- ]
4224
- },
4225
- len: 1,
4226
- line: 0
4227
- }), textX;
4228
- }
4229
- __name(addCustomRangeTextX, "addCustomRangeTextX");
4230
- function addCustomRangeFactory(accessor, param, body) {
4231
- const { unitId, segmentId } = param, documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId);
4232
- if (!documentDataModel)
4233
- return !1;
4234
- const doMutation = {
4235
- id: RichTextEditingMutation.id,
4236
- params: {
4237
- unitId: param.unitId,
4238
- actions: [],
4239
- textRanges: void 0
4240
- }
4241
- }, jsonX = JSONX.getInstance(), textX = addCustomRangeTextX(param, body);
4242
- if (!textX)
4243
- return !1;
4244
- const path = getRichTextEditPath(documentDataModel, segmentId);
4245
- return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), doMutation;
4246
- }
4247
- __name(addCustomRangeFactory, "addCustomRangeFactory");
4248
- function addCustomRangeBySelectionFactory(accessor, param) {
4249
- var _a11;
4250
- const { rangeId, rangeType, wholeEntity, properties } = param, textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), selection = textSelectionManagerService.getActiveTextRangeWithStyle(), segmentId = selection == null ? void 0 : selection.segmentId;
4251
- if (!selection)
4252
- return !1;
4253
- const documentDataModel = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
4254
- if (!documentDataModel)
4255
- return !1;
4256
- const body = documentDataModel.getSelfOrHeaderFooterModel(selection.segmentId).getBody(), unitId = documentDataModel.getUnitId();
4257
- if (!body)
4258
- return !1;
4259
- const { startOffset, endOffset } = normalizeSelection(selection), customRanges = (_a11 = body.customRanges) != null ? _a11 : [], relativeCustomRanges = [];
4260
- for (let i = 0, len = customRanges.length; i < len; i++) {
4261
- const customRange = customRanges[i];
4262
- if (customRange.rangeType === rangeType && Math.max(customRange.startIndex, startOffset) <= Math.min(customRange.endIndex, endOffset - 1) && relativeCustomRanges.push({ ...customRange }), customRange.startIndex >= endOffset)
4263
- break;
4264
- }
4265
- const deletes = relativeCustomRanges.map((i) => [i.startIndex, i.endIndex]).flat().sort((pre, aft) => pre - aft);
4266
- let cursor = 0;
4267
- const textX = new TextX(), range = deletes.length ? {
4268
- startOffset: Math.min(deletes[0], startOffset),
4269
- endOffset: Math.max(deletes[deletes.length - 1] + 1, endOffset)
4270
- } : selection;
4271
- range.startOffset !== cursor && (textX.push({
4272
- t: TextXActionType.RETAIN,
4273
- len: range.startOffset - cursor,
4274
- segmentId
4275
- }), cursor = range.startOffset), textX.push({
4276
- t: TextXActionType.INSERT,
4277
- body: {
4278
- dataStream: DataStreamTreeTokenType.CUSTOM_RANGE_START
4279
- },
4280
- len: 1,
4281
- line: 0,
4282
- segmentId
4283
- }), deletes.forEach((index, i) => {
4284
- index !== cursor && (textX.push({
4285
- t: TextXActionType.RETAIN,
4286
- len: index - cursor,
4287
- segmentId
4288
- }), cursor = index), textX.push({
4289
- t: TextXActionType.DELETE,
4290
- len: 1,
4291
- line: 0,
4292
- segmentId
4293
- }), cursor++;
4294
- }), cursor !== range.endOffset && (textX.push({
4295
- t: TextXActionType.RETAIN,
4296
- len: range.endOffset - cursor,
4297
- segmentId
4298
- }), cursor = range.endOffset), textX.push({
4299
- t: TextXActionType.INSERT,
4300
- body: {
4301
- dataStream: DataStreamTreeTokenType.CUSTOM_RANGE_END,
4302
- customRanges: [
4303
- {
4304
- rangeId,
4305
- rangeType,
4306
- startIndex: -(range.endOffset - range.startOffset - deletes.length + 1),
4307
- endIndex: 0,
4308
- wholeEntity,
4309
- properties
4310
- }
4311
- ]
4312
- },
4313
- len: 1,
4314
- line: 0,
4315
- segmentId
4316
- });
4317
- const jsonX = JSONX.getInstance(), doMutation = {
4318
- id: RichTextEditingMutation.id,
4319
- params: {
4320
- unitId,
4321
- actions: [],
4322
- textRanges: void 0
4323
- }
4324
- }, path = getRichTextEditPath(documentDataModel, segmentId);
4325
- return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), doMutation;
4326
- }
4327
- __name(addCustomRangeBySelectionFactory, "addCustomRangeBySelectionFactory");
4328
- function deleteCustomRangeTextX(accessor, params) {
4329
- var _a11, _b;
4330
- const { unitId, rangeId, segmentId } = params, documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId);
4331
- if (!documentDataModel)
4332
- return !1;
4333
- const range = (_b = (_a11 = documentDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a11.customRanges) == null ? void 0 : _b.find((r) => r.rangeId === rangeId);
4334
- if (!range)
4335
- return !1;
4336
- const { startIndex, endIndex } = range, textX = new TextX(), len = endIndex - startIndex + 1;
4337
- return startIndex > 0 && textX.push({
4338
- t: TextXActionType.RETAIN,
4339
- len: startIndex,
4340
- segmentId
4341
- }), textX.push({
4342
- t: TextXActionType.DELETE,
4343
- len: 1,
4344
- segmentId,
4345
- line: 0
4346
- }), len - 2 > 0 && textX.push({
4347
- t: TextXActionType.RETAIN,
4348
- len: len - 2,
4349
- segmentId
4350
- }), textX.push({
4351
- t: TextXActionType.DELETE,
4352
- len: 1,
4353
- segmentId,
4354
- line: 0
4355
- }), textX;
4356
- }
4357
- __name(deleteCustomRangeTextX, "deleteCustomRangeTextX");
4358
- function deleteCustomRangeFactory(accessor, params) {
4359
- const { unitId, segmentId } = params, documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId);
4360
- if (!documentDataModel)
4361
- return !1;
4362
- const doMutation = {
4363
- id: RichTextEditingMutation.id,
4364
- params: {
4365
- unitId: params.unitId,
4366
- actions: [],
4367
- textRanges: void 0,
4368
- segmentId
4369
- }
4370
- }, jsonX = JSONX.getInstance(), textX = deleteCustomRangeTextX(accessor, params);
4371
- if (!textX)
4372
- return !1;
4373
- const path = getRichTextEditPath(documentDataModel, segmentId);
4374
- return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), doMutation;
4375
- }
4376
- __name(deleteCustomRangeFactory, "deleteCustomRangeFactory");
4377
- function addCustomDecorationFactory(param) {
4378
- const { unitId, ranges, id, type, segmentId } = param, doMutation = {
4379
- id: RichTextEditingMutation.id,
4380
- params: {
4381
- unitId,
4382
- actions: [],
4383
- textRanges: void 0
4384
- }
4385
- }, textX = new TextX(), jsonX = JSONX.getInstance();
4386
- let cursor = 0;
4387
- for (let i = 0; i < ranges.length; i++) {
4388
- const range = ranges[i], { startOffset: start, endOffset: end } = range;
4389
- start > 0 && textX.push({
4390
- t: TextXActionType.RETAIN,
4391
- len: start - cursor,
4392
- segmentId
4393
- }), textX.push({
4394
- t: TextXActionType.RETAIN,
4395
- body: {
4396
- dataStream: "",
4397
- customDecorations: [{
4398
- id,
4399
- type,
4400
- startIndex: 0,
4401
- endIndex: end - start - 1
4402
- }]
4403
- },
4404
- len: end - start,
4405
- segmentId
4406
- }), cursor = end;
4407
- }
4408
- return doMutation.params.actions = jsonX.editOp(textX.serialize()), doMutation;
4409
- }
4410
- __name(addCustomDecorationFactory, "addCustomDecorationFactory");
4411
- function addCustomDecorationBySelectionFactory(accessor, param) {
4412
- const { segmentId, id, type } = param, textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), selections = textSelectionManagerService.getCurrentTextRanges();
4413
- if (!selections)
4414
- return !1;
4415
- const documentDataModel = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
4416
- if (!documentDataModel)
4417
- return !1;
4418
- const body = documentDataModel.getBody(), unitId = documentDataModel.getUnitId();
4419
- return body ? addCustomDecorationFactory(
4420
- {
4421
- unitId,
4422
- ranges: selections.map(serializeDocRange),
4423
- id,
4424
- type,
4425
- segmentId
4426
- }
4427
- ) : !1;
4428
- }
4429
- __name(addCustomDecorationBySelectionFactory, "addCustomDecorationBySelectionFactory");
4430
- function deleteCustomDecorationFactory(accessor, params) {
4431
- var _a11, _b;
4432
- const { unitId, id, segmentId } = params, documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId), body = documentDataModel == null ? void 0 : documentDataModel.getBody();
4433
- if (!documentDataModel || !body)
4434
- return !1;
4435
- const decorations = (_b = (_a11 = documentDataModel.getBody()) == null ? void 0 : _a11.customDecorations) == null ? void 0 : _b.filter((d) => d.id === id);
4436
- if (!(decorations != null && decorations.length))
4437
- return !1;
4438
- const oldBodySlices = decorations.map((i) => getBodySlice(body, i.startIndex, i.endIndex + 1)), bodySlices = oldBodySlices.map((bodySlice) => {
4439
- var _a12;
4440
- const copy = Tools.deepClone(bodySlice);
4441
- return copy.customDecorations = (_a12 = copy.customDecorations) == null ? void 0 : _a12.filter((decoration) => decoration.id !== id), copy;
4442
- }), doMutation = {
4443
- id: RichTextEditingMutation.id,
4444
- params: {
4445
- unitId,
4446
- actions: [],
4447
- textRanges: void 0
4448
- }
4449
- }, textX = new TextX(), jsonX = JSONX.getInstance();
4450
- let cursor = 0;
4451
- return decorations.forEach((decoration, i) => {
4452
- const bodySlice = bodySlices[i], oldBody = oldBodySlices[i];
4453
- decoration.startIndex !== cursor && textX.push({
4454
- t: TextXActionType.RETAIN,
4455
- len: decoration.startIndex - cursor,
4456
- segmentId
4457
- }), cursor = decoration.startIndex, textX.push({
4458
- t: TextXActionType.RETAIN,
4459
- len: decoration.endIndex - decoration.startIndex + 1,
4460
- segmentId,
4461
- body: bodySlice,
4462
- oldBody,
4463
- coverType: UpdateDocsAttributeType.REPLACE
4464
- }), cursor = cursor + (decoration.endIndex - decoration.startIndex + 1);
4465
- }), doMutation.params.actions = jsonX.editOp(textX.serialize()), doMutation;
4466
- }
4467
- __name(deleteCustomDecorationFactory, "deleteCustomDecorationFactory");
4468
374
  const CUSTOM_RANGE = createInterceptorKey("CUSTOM_RANGE"), CUSTOM_DECORATION = createInterceptorKey("CUSTOM_DECORATION"), DOC_INTERCEPTOR_POINT = {
4469
375
  CUSTOM_RANGE,
4470
376
  CUSTOM_DECORATION
@@ -4473,8 +379,8 @@ var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnProperty
4473
379
  for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
4474
380
  (decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
4475
381
  return kind && result && __defProp2(target, key, result), result;
4476
- }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), _a10;
4477
- let DocInterceptorService = (_a10 = class extends Disposable {
382
+ }, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), _a5;
383
+ let DocInterceptorService = (_a5 = class extends Disposable {
4478
384
  constructor(_context, _docSkeletonManagerService) {
4479
385
  super();
4480
386
  __publicField(this, "_interceptorsByName", /* @__PURE__ */ new Map());
@@ -4500,8 +406,8 @@ let DocInterceptorService = (_a10 = class extends Disposable {
4500
406
  return interceptors.push(interceptor), this._interceptorsByName.set(
4501
407
  key,
4502
408
  interceptors.sort((a, b) => {
4503
- var _a11, _b;
4504
- return ((_a11 = b.priority) != null ? _a11 : 0) - ((_b = a.priority) != null ? _b : 0);
409
+ var _a6, _b;
410
+ return ((_a6 = b.priority) != null ? _a6 : 0) - ((_b = a.priority) != null ? _b : 0);
4505
411
  })
4506
412
  ), this.disposeWithMe(toDisposable(() => remove(this._interceptorsByName.get(key), interceptor)));
4507
413
  }
@@ -4513,144 +419,41 @@ let DocInterceptorService = (_a10 = class extends Disposable {
4513
419
  const disposableCollection = new DisposableCollection();
4514
420
  return disposableCollection.add(viewModel.registerCustomRangeInterceptor({
4515
421
  getCustomRange: /* @__PURE__ */ __name((index) => {
4516
- var _a11;
422
+ var _a6;
4517
423
  return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE)(
4518
424
  viewModel.getCustomRangeRaw(index),
4519
425
  {
4520
426
  index,
4521
427
  unitId: viewModel.getDataModel().getUnitId(),
4522
- customRanges: (_a11 = viewModel.getDataModel().getCustomRanges()) != null ? _a11 : []
428
+ customRanges: (_a6 = viewModel.getDataModel().getCustomRanges()) != null ? _a6 : []
4523
429
  }
4524
430
  );
4525
431
  }, "getCustomRange"),
4526
432
  getCustomDecoration: /* @__PURE__ */ __name((index) => {
4527
- var _a11;
433
+ var _a6;
4528
434
  return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION)(
4529
435
  viewModel.getCustomDecorationRaw(index),
4530
436
  {
4531
437
  index,
4532
438
  unitId: viewModel.getDataModel().getUnitId(),
4533
- customDecorations: (_a11 = viewModel.getDataModel().getCustomDecorations()) != null ? _a11 : []
439
+ customDecorations: (_a6 = viewModel.getDataModel().getCustomDecorations()) != null ? _a6 : []
4534
440
  }
4535
441
  );
4536
442
  }, "getCustomDecoration")
4537
443
  })), disposableCollection;
4538
444
  }
4539
- }, __name(_a10, "DocInterceptorService"), _a10);
445
+ }, __name(_a5, "DocInterceptorService"), _a5);
4540
446
  DocInterceptorService = __decorateClass([
4541
447
  OnLifecycle(LifecycleStages.Starting, DocInterceptorService),
4542
448
  __decorateParam(1, Inject(DocSkeletonManagerService))
4543
449
  ], DocInterceptorService);
4544
450
  export {
4545
- AfterSpaceCommand,
4546
- AlignCenterCommand,
4547
- AlignJustifyCommand,
4548
- AlignLeftCommand,
4549
- AlignOperationCommand,
4550
- AlignRightCommand,
4551
- BreakLineCommand,
4552
- BulletListCommand,
4553
- ChangeListNestingLevelCommand,
4554
- ChangeListNestingLevelType,
4555
- ChangeListTypeCommand,
4556
- CheckListCommand,
4557
- CoverContentCommand,
4558
- CreateDocTableCommand,
4559
- CutContentCommand,
4560
- DOCS_COMPONENT_BACKGROUND_LAYER_INDEX,
4561
- DOCS_COMPONENT_DEFAULT_Z_INDEX,
4562
- DOCS_COMPONENT_HEADER_LAYER_INDEX,
4563
- DOCS_COMPONENT_MAIN_LAYER_INDEX,
4564
- DOCS_VIEW_KEY,
4565
451
  DOC_INTERCEPTOR_POINT,
4566
- DeleteCommand,
4567
- DeleteCustomBlockCommand,
4568
- DeleteLeftCommand,
4569
- DeleteRightCommand,
4570
- DocAutoFormatService,
4571
452
  DocInterceptorService,
453
+ DocSelectionManagerService,
4572
454
  DocSkeletonManagerService,
4573
- DocStateChangeManagerService,
4574
- DocTableDeleteColumnsCommand,
4575
- DocTableDeleteRowsCommand,
4576
- DocTableDeleteTableCommand,
4577
- DocTableInsertColumnCommand,
4578
- DocTableInsertColumnLeftCommand,
4579
- DocTableInsertColumnRightCommand,
4580
- DocTableInsertRowAboveCommand,
4581
- DocTableInsertRowBellowCommand,
4582
- DocTableInsertRowCommand,
4583
- DocTableTabCommand,
4584
- EditorInsertTextCommandId,
4585
- EnterCommand,
4586
- IMEInputCommand,
4587
- IMEInputManagerService,
4588
- InnerPasteCommand,
4589
- InsertCommand,
4590
- ListOperationCommand,
4591
- MergeTwoParagraphCommand,
4592
- MoveCursorOperation,
4593
- MoveSelectionOperation,
4594
- NORMAL_TEXT_SELECTION_PLUGIN_NAME,
4595
- OrderListCommand,
4596
- QuickListCommand,
4597
- ReplaceContentCommand,
4598
- ResetInlineFormatTextBackgroundColorCommand,
455
+ DocStateEmitService,
4599
456
  RichTextEditingMutation,
4600
- SelectAllOperation,
4601
- SetDocZoomRatioCommand,
4602
- SetDocZoomRatioOperation,
4603
- SetInlineFormatBoldCommand,
4604
- SetInlineFormatCommand,
4605
- SetInlineFormatFontFamilyCommand,
4606
- SetInlineFormatFontSizeCommand,
4607
- SetInlineFormatItalicCommand,
4608
- SetInlineFormatStrikethroughCommand,
4609
- SetInlineFormatSubscriptCommand,
4610
- SetInlineFormatSuperscriptCommand,
4611
- SetInlineFormatTextBackgroundColorCommand,
4612
- SetInlineFormatTextColorCommand,
4613
- SetInlineFormatUnderlineCommand,
4614
457
  SetTextSelectionsOperation,
4615
- TabCommand,
4616
- TextSelectionManagerService,
4617
- ToggleCheckListCommand,
4618
- UniverDocsPlugin,
4619
- UpdateCommand,
4620
- VIEWPORT_KEY,
4621
- addCustomDecorationBySelectionFactory,
4622
- addCustomDecorationFactory,
4623
- addCustomRangeBySelectionFactory,
4624
- addCustomRangeFactory,
4625
- copyCustomRange,
4626
- deleteCustomDecorationFactory,
4627
- deleteCustomRangeFactory,
4628
- findNearestSectionBreak,
4629
- genTableSource,
4630
- generateParagraphs,
4631
- getCommandSkeleton,
4632
- getCursorWhenDelete,
4633
- getCustomBlockIdsInSelections,
4634
- getCustomRangesInterestsWithRange,
4635
- getCutActionsFromDocRanges,
4636
- getDeleteSelection,
4637
- getDocObject,
4638
- getDocObjectById,
4639
- getEmptyTableCell,
4640
- getEmptyTableRow,
4641
- getInsertSelection,
4642
- getParagraphsInRange$1 as getParagraphsInRange,
4643
- getParagraphsInRanges,
4644
- getPlainTextFormBody,
4645
- getPlainTextFormDocument,
4646
- getRetainAndDeleteFromReplace,
4647
- getRichTextEditPath,
4648
- getSelectionText,
4649
- getTableColumn,
4650
- hasParagraphInTable,
4651
- isSegmentIntersects,
4652
- makeSelection,
4653
- neoGetDocObject,
4654
- replaceSelectionFactory,
4655
- serializeDocRange
458
+ UniverDocsPlugin
4656
459
  };