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