@univerjs/docs 0.2.6 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +4 -1
- package/lib/es/index.js +2016 -439
- package/lib/types/basics/component-tools.d.ts +0 -1
- package/lib/types/basics/custom-decoration-factory.d.ts +1 -2
- package/lib/types/basics/custom-range-factory.d.ts +0 -1
- package/lib/types/basics/custom-range.d.ts +2 -2
- package/lib/types/basics/plain-text.d.ts +0 -1
- package/lib/types/basics/replace.d.ts +3 -2
- package/lib/types/basics/retain-delete-params.d.ts +0 -1
- package/lib/types/basics/selection.d.ts +2 -6
- package/lib/types/basics/table.d.ts +18 -0
- package/lib/types/commands/commands/__tests__/create-command-test-bed.d.ts +0 -1
- package/lib/types/commands/commands/__tests__/mock-text-selection-render-manager.d.ts +2 -3
- package/lib/types/commands/commands/auto-format.command.d.ts +7 -0
- package/lib/types/commands/commands/break-line.command.d.ts +2 -2
- package/lib/types/commands/commands/clipboard.inner.command.d.ts +2 -3
- package/lib/types/commands/commands/core-editing.command.d.ts +0 -1
- package/lib/types/commands/commands/delete.command.d.ts +3 -3
- package/lib/types/commands/commands/ime-input.command.d.ts +0 -1
- package/lib/types/commands/commands/inline-format.command.d.ts +0 -2
- package/lib/types/commands/commands/list.command.d.ts +28 -3
- package/lib/types/commands/commands/paragraph-align.command.d.ts +0 -1
- package/lib/types/commands/commands/replace-content.command.d.ts +0 -1
- package/lib/types/commands/commands/set-doc-zoom-ratio.command.d.ts +0 -1
- package/lib/types/commands/commands/table/doc-table-create.command.d.ts +10 -0
- package/lib/types/commands/commands/table/doc-table-delete.command.d.ts +10 -0
- package/lib/types/commands/commands/table/doc-table-insert.command.d.ts +34 -0
- package/lib/types/commands/commands/table/doc-table-tab.command.d.ts +7 -0
- package/lib/types/commands/commands/table/table.d.ts +84 -0
- package/lib/types/commands/mutations/core-editing.mutation.d.ts +0 -1
- package/lib/types/commands/mutations/docs-rename.mutation.d.ts +0 -1
- package/lib/types/commands/operations/cursor.operation.d.ts +0 -1
- package/lib/types/commands/operations/select-all.operation.d.ts +0 -1
- package/lib/types/commands/operations/set-doc-zoom-ratio.operation.d.ts +0 -1
- package/lib/types/commands/operations/text-selection.operation.d.ts +0 -1
- package/lib/types/commands/util.d.ts +0 -1
- package/lib/types/controllers/custom-range.controller.d.ts +0 -1
- package/lib/types/controllers/ime-input.controller.d.ts +3 -2
- package/lib/types/controllers/move-cursor.controller.d.ts +0 -1
- package/lib/types/controllers/normal-input.controller.d.ts +0 -1
- package/lib/types/doc-plugin.d.ts +0 -1
- package/lib/types/index.d.ts +23 -7
- package/lib/types/services/doc-auto-format.service.d.ts +37 -0
- package/lib/types/services/doc-custom-range.service.d.ts +0 -1
- package/lib/types/services/doc-interceptor/doc-interceptor.service.d.ts +0 -1
- package/lib/types/services/doc-interceptor/interceptor-const.d.ts +0 -1
- package/lib/types/services/doc-skeleton-manager.service.d.ts +0 -1
- package/lib/types/services/doc-state-change-manager.service.d.ts +0 -1
- package/lib/types/services/doc-view-model-manager.service.d.ts +0 -1
- package/lib/types/services/ime-input-manager.service.d.ts +0 -1
- package/lib/types/services/text-selection-manager.service.d.ts +14 -12
- package/lib/umd/index.js +4 -1
- package/package.json +9 -8
package/lib/es/index.js
CHANGED
|
@@ -2,28 +2,30 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key] = value;
|
|
3
3
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
|
4
4
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key != "symbol" ? key + "" : key, value);
|
|
5
|
-
import { CommandType, RxDisposable, ICommandService, Inject, IUndoRedoService, UndoCommandId, RedoCommandId, JSONX, IUniverInstanceService, LocaleService, UniverInstanceType,
|
|
6
|
-
import { NORMAL_TEXT_SELECTION_PLUGIN_STYLE, ITextSelectionRenderManager, DocumentSkeleton, DocumentViewModel, IRenderManagerService, hasListGlyph, isIndentByGlyph, isFirstGlyph, getParagraphByGlyph,
|
|
5
|
+
import { CommandType, RxDisposable, ICommandService, Inject, IUndoRedoService, UndoCommandId, RedoCommandId, JSONX, IUniverInstanceService, LocaleService, UniverInstanceType, isInternalEditorID, Tools, PresetListType, MemoryCursor, TextX, PRESET_LIST_TYPE, GridType, TextXActionType, BooleanNumber, UpdateDocsAttributeType, sortRulesFactory, DataStreamTreeTokenType, toDisposable, normalizeBody, getBodySlice, updateAttributeByInsert, 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, remove, composeInterceptors, DisposableCollection } 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";
|
|
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";
|
|
8
9
|
const SetTextSelectionsOperation = {
|
|
9
10
|
id: "doc.operation.set-selections",
|
|
10
11
|
type: CommandType.OPERATION,
|
|
11
12
|
handler: /* @__PURE__ */ __name((_, __) => !0, "handler")
|
|
12
13
|
};
|
|
13
|
-
var __defProp$
|
|
14
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$
|
|
14
|
+
var __defProp$9 = Object.defineProperty, __getOwnPropDesc$9 = Object.getOwnPropertyDescriptor, __decorateClass$9 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
15
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$9(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
15
16
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
16
|
-
return kind && result && __defProp$
|
|
17
|
-
}, "__decorateClass$
|
|
18
|
-
function
|
|
19
|
-
const { startOffset, endOffset, collapsed } = textRange, serializedTextRange = {
|
|
17
|
+
return kind && result && __defProp$9(target, key, result), result;
|
|
18
|
+
}, "__decorateClass$9"), __decorateParam$9 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$9");
|
|
19
|
+
function serializeDocRange(textRange) {
|
|
20
|
+
const { startOffset, endOffset, collapsed, rangeType } = textRange, serializedTextRange = {
|
|
20
21
|
startOffset,
|
|
21
22
|
endOffset,
|
|
22
|
-
collapsed
|
|
23
|
+
collapsed,
|
|
24
|
+
rangeType
|
|
23
25
|
};
|
|
24
26
|
return typeof textRange.isActive == "function" && (serializedTextRange.isActive = textRange.isActive()), serializedTextRange;
|
|
25
27
|
}
|
|
26
|
-
__name(
|
|
28
|
+
__name(serializeDocRange, "serializeDocRange");
|
|
27
29
|
var _a;
|
|
28
30
|
let TextSelectionManagerService = (_a = class extends RxDisposable {
|
|
29
31
|
constructor(_textSelectionRenderManager, _commandService) {
|
|
@@ -54,9 +56,18 @@ let TextSelectionManagerService = (_a = class extends RxDisposable {
|
|
|
54
56
|
setCurrentSelectionNotRefresh(param) {
|
|
55
57
|
this._currentSelection = param;
|
|
56
58
|
}
|
|
57
|
-
|
|
58
|
-
var
|
|
59
|
-
return (
|
|
59
|
+
getCurrentTextRanges() {
|
|
60
|
+
var _a11;
|
|
61
|
+
return (_a11 = this._getTextRanges(this._currentSelection)) == null ? void 0 : _a11.textRanges;
|
|
62
|
+
}
|
|
63
|
+
getCurrentRectRanges() {
|
|
64
|
+
var _a11;
|
|
65
|
+
return (_a11 = this._getTextRanges(this._currentSelection)) == null ? void 0 : _a11.rectRanges;
|
|
66
|
+
}
|
|
67
|
+
getDocRanges() {
|
|
68
|
+
var _a11, _b;
|
|
69
|
+
const textRanges = (_a11 = this.getCurrentTextRanges()) != null ? _a11 : [], rectRanges = (_b = this.getCurrentRectRanges()) != null ? _b : [];
|
|
70
|
+
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);
|
|
60
71
|
}
|
|
61
72
|
getActiveTextRange() {
|
|
62
73
|
const selectionInfo = this._getTextRanges(this._currentSelection);
|
|
@@ -65,7 +76,14 @@ let TextSelectionManagerService = (_a = class extends RxDisposable {
|
|
|
65
76
|
const { textRanges } = selectionInfo;
|
|
66
77
|
return textRanges.find((textRange) => textRange.isActive());
|
|
67
78
|
}
|
|
68
|
-
|
|
79
|
+
getActiveRectRange() {
|
|
80
|
+
const selectionInfo = this._getTextRanges(this._currentSelection);
|
|
81
|
+
if (selectionInfo == null)
|
|
82
|
+
return;
|
|
83
|
+
const { rectRanges } = selectionInfo;
|
|
84
|
+
return rectRanges.find((rectRange) => rectRange.isActive());
|
|
85
|
+
}
|
|
86
|
+
getActiveTextRangeWithStyle() {
|
|
69
87
|
const selectionInfo = this._getTextRanges(this._currentSelection);
|
|
70
88
|
if (selectionInfo == null)
|
|
71
89
|
return;
|
|
@@ -90,6 +108,7 @@ let TextSelectionManagerService = (_a = class extends RxDisposable {
|
|
|
90
108
|
this._currentSelection != null && this._addByParam({
|
|
91
109
|
...this._currentSelection,
|
|
92
110
|
textRanges,
|
|
111
|
+
rectRanges: [],
|
|
93
112
|
segmentId: "",
|
|
94
113
|
segmentPage: -1,
|
|
95
114
|
isEditing,
|
|
@@ -97,8 +116,8 @@ let TextSelectionManagerService = (_a = class extends RxDisposable {
|
|
|
97
116
|
// mock style.
|
|
98
117
|
});
|
|
99
118
|
}
|
|
100
|
-
replaceTextRanges(
|
|
101
|
-
this._currentSelection != null && (this._textSelectionRenderManager.
|
|
119
|
+
replaceTextRanges(docRanges, isEditing = !0, options) {
|
|
120
|
+
this._currentSelection != null && (this._textSelectionRenderManager.removeAllRanges(), this._textSelectionRenderManager.addDocRanges(docRanges, isEditing, options));
|
|
102
121
|
}
|
|
103
122
|
// All textRanges should be synchronized from the render layer.
|
|
104
123
|
_syncSelectionFromRenderService() {
|
|
@@ -114,47 +133,50 @@ let TextSelectionManagerService = (_a = class extends RxDisposable {
|
|
|
114
133
|
...textSelectionInfo
|
|
115
134
|
};
|
|
116
135
|
this._replaceByParam(params), this._textSelection$.next(params);
|
|
117
|
-
const { unitId, subUnitId, segmentId, style, textRanges, isEditing } = params;
|
|
136
|
+
const { unitId, subUnitId, segmentId, style, textRanges, rectRanges, isEditing } = params, ranges = [...textRanges, ...rectRanges].filter((range) => range.startOffset != null && range.endOffset != null).sort((a, b) => a.startOffset > b.startOffset ? 1 : a.startOffset < b.startOffset ? -1 : 0).map(serializeDocRange);
|
|
118
137
|
this._commandService.executeCommand(SetTextSelectionsOperation.id, {
|
|
119
138
|
unitId,
|
|
120
139
|
subUnitId,
|
|
121
140
|
segmentId,
|
|
122
141
|
style,
|
|
123
142
|
isEditing,
|
|
124
|
-
ranges
|
|
143
|
+
ranges
|
|
125
144
|
});
|
|
126
145
|
}
|
|
127
146
|
_getTextRanges(param) {
|
|
128
|
-
var
|
|
147
|
+
var _a11;
|
|
129
148
|
if (param == null)
|
|
130
149
|
return;
|
|
131
150
|
const { unitId, subUnitId = "" } = param;
|
|
132
|
-
return (
|
|
151
|
+
return (_a11 = this._textSelectionInfo.get(unitId)) == null ? void 0 : _a11.get(subUnitId);
|
|
133
152
|
}
|
|
134
153
|
_refresh(param) {
|
|
135
154
|
const allTextSelectionInfo = this._getTextRanges(param);
|
|
136
|
-
this._textSelectionRenderManager.
|
|
155
|
+
if (this._textSelectionRenderManager.removeAllRanges(), allTextSelectionInfo == null)
|
|
156
|
+
return;
|
|
157
|
+
const { textRanges, rectRanges } = allTextSelectionInfo, docRanges = [...textRanges, ...rectRanges];
|
|
158
|
+
docRanges.length > 0 && this._textSelectionRenderManager.addDocRanges(docRanges.map(serializeDocRange));
|
|
137
159
|
}
|
|
138
160
|
_replaceByParam(insertParam) {
|
|
139
|
-
const { unitId, subUnitId, style, segmentId, textRanges, isEditing, segmentPage } = insertParam;
|
|
140
|
-
this._textSelectionInfo.has(unitId) || this._textSelectionInfo.set(unitId, /* @__PURE__ */ new Map()), this._textSelectionInfo.get(unitId).set(subUnitId, { textRanges, style, segmentId, isEditing, segmentPage });
|
|
161
|
+
const { unitId, subUnitId, style, segmentId, textRanges, rectRanges, isEditing, segmentPage } = insertParam;
|
|
162
|
+
this._textSelectionInfo.has(unitId) || this._textSelectionInfo.set(unitId, /* @__PURE__ */ new Map()), this._textSelectionInfo.get(unitId).set(subUnitId, { textRanges, rectRanges, style, segmentId, isEditing, segmentPage });
|
|
141
163
|
}
|
|
142
164
|
_addByParam(insertParam) {
|
|
143
|
-
const { unitId, subUnitId, textRanges, style, segmentId, isEditing, segmentPage } = insertParam;
|
|
165
|
+
const { unitId, subUnitId, textRanges, rectRanges, style, segmentId, isEditing, segmentPage } = insertParam;
|
|
144
166
|
this._textSelectionInfo.has(unitId) || this._textSelectionInfo.set(unitId, /* @__PURE__ */ new Map());
|
|
145
167
|
const unitTextRange = this._textSelectionInfo.get(unitId);
|
|
146
|
-
unitTextRange.has(subUnitId) ? unitTextRange.get(subUnitId).textRanges.push(...textRanges) : unitTextRange.set(subUnitId, { textRanges, style, segmentId, isEditing, segmentPage });
|
|
168
|
+
unitTextRange.has(subUnitId) ? unitTextRange.get(subUnitId).textRanges.push(...textRanges) : unitTextRange.set(subUnitId, { textRanges, rectRanges, style, segmentId, isEditing, segmentPage });
|
|
147
169
|
}
|
|
148
170
|
}, __name(_a, "TextSelectionManagerService"), _a);
|
|
149
|
-
TextSelectionManagerService = __decorateClass$
|
|
150
|
-
__decorateParam$
|
|
151
|
-
__decorateParam$
|
|
171
|
+
TextSelectionManagerService = __decorateClass$9([
|
|
172
|
+
__decorateParam$9(0, ITextSelectionRenderManager),
|
|
173
|
+
__decorateParam$9(1, ICommandService)
|
|
152
174
|
], TextSelectionManagerService);
|
|
153
|
-
var __defProp$
|
|
154
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$
|
|
175
|
+
var __defProp$8 = Object.defineProperty, __getOwnPropDesc$8 = Object.getOwnPropertyDescriptor, __decorateClass$8 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
176
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$8(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
155
177
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
156
|
-
return kind && result && __defProp$
|
|
157
|
-
}, "__decorateClass$
|
|
178
|
+
return kind && result && __defProp$8(target, key, result), result;
|
|
179
|
+
}, "__decorateClass$8"), __decorateParam$8 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$8");
|
|
158
180
|
const DEBOUNCE_DELAY = 300;
|
|
159
181
|
var _a2;
|
|
160
182
|
let DocStateChangeManagerService = (_a2 = class extends RxDisposable {
|
|
@@ -248,10 +270,10 @@ let DocStateChangeManagerService = (_a2 = class extends RxDisposable {
|
|
|
248
270
|
cacheStates.length = 0, this._docStateChange$.next(changeState);
|
|
249
271
|
}
|
|
250
272
|
}, __name(_a2, "DocStateChangeManagerService"), _a2);
|
|
251
|
-
DocStateChangeManagerService = __decorateClass$
|
|
252
|
-
__decorateParam$
|
|
253
|
-
__decorateParam$
|
|
254
|
-
__decorateParam$
|
|
273
|
+
DocStateChangeManagerService = __decorateClass$8([
|
|
274
|
+
__decorateParam$8(0, Inject(IUndoRedoService)),
|
|
275
|
+
__decorateParam$8(1, ICommandService),
|
|
276
|
+
__decorateParam$8(2, IUniverInstanceService)
|
|
255
277
|
], DocStateChangeManagerService);
|
|
256
278
|
const _IMEInputManagerService = class _IMEInputManagerService {
|
|
257
279
|
constructor() {
|
|
@@ -302,11 +324,11 @@ const _IMEInputManagerService = class _IMEInputManagerService {
|
|
|
302
324
|
};
|
|
303
325
|
__name(_IMEInputManagerService, "IMEInputManagerService");
|
|
304
326
|
let IMEInputManagerService = _IMEInputManagerService;
|
|
305
|
-
var __defProp$
|
|
306
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$
|
|
327
|
+
var __defProp$7 = Object.defineProperty, __getOwnPropDesc$7 = Object.getOwnPropertyDescriptor, __decorateClass$7 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
328
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$7(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
307
329
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
308
|
-
return kind && result && __defProp$
|
|
309
|
-
}, "__decorateClass$
|
|
330
|
+
return kind && result && __defProp$7(target, key, result), result;
|
|
331
|
+
}, "__decorateClass$7"), __decorateParam$7 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$7"), _a3;
|
|
310
332
|
let DocSkeletonManagerService = (_a3 = class extends RxDisposable {
|
|
311
333
|
constructor(_context, _localeService, _univerInstanceService) {
|
|
312
334
|
super();
|
|
@@ -340,7 +362,7 @@ let DocSkeletonManagerService = (_a3 = class extends RxDisposable {
|
|
|
340
362
|
const unitId = this._context.unitId;
|
|
341
363
|
if (documentDataModel.getBody() == null)
|
|
342
364
|
return;
|
|
343
|
-
this._docViewModel && unitId
|
|
365
|
+
this._docViewModel && isInternalEditorID(unitId) ? (this._docViewModel.reset(documentDataModel), this._context.unit = documentDataModel) : this._docViewModel || (this._docViewModel = this._buildDocViewModel(documentDataModel)), this._skeleton || (this._skeleton = this._buildSkeleton(this._docViewModel));
|
|
344
366
|
const skeleton = this._skeleton;
|
|
345
367
|
skeleton.calculate(), this._currentSkeletonBefore$.next(skeleton), this._currentSkeleton$.next(skeleton), this._currentViewModel$.next(this._docViewModel);
|
|
346
368
|
}
|
|
@@ -351,16 +373,16 @@ let DocSkeletonManagerService = (_a3 = class extends RxDisposable {
|
|
|
351
373
|
return new DocumentViewModel(documentDataModel);
|
|
352
374
|
}
|
|
353
375
|
}, __name(_a3, "DocSkeletonManagerService"), _a3);
|
|
354
|
-
DocSkeletonManagerService = __decorateClass$
|
|
355
|
-
__decorateParam$
|
|
356
|
-
__decorateParam$
|
|
376
|
+
DocSkeletonManagerService = __decorateClass$7([
|
|
377
|
+
__decorateParam$7(1, Inject(LocaleService)),
|
|
378
|
+
__decorateParam$7(2, IUniverInstanceService)
|
|
357
379
|
], DocSkeletonManagerService);
|
|
358
380
|
const RichTextEditingMutationId = "doc.mutation.rich-text-editing", RichTextEditingMutation = {
|
|
359
381
|
id: RichTextEditingMutationId,
|
|
360
382
|
type: CommandType.MUTATION,
|
|
361
383
|
// eslint-disable-next-line max-lines-per-function
|
|
362
384
|
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
363
|
-
var
|
|
385
|
+
var _a11, _b;
|
|
364
386
|
const {
|
|
365
387
|
unitId,
|
|
366
388
|
segmentId = "",
|
|
@@ -372,10 +394,10 @@ const RichTextEditingMutationId = "doc.mutation.rich-text-editing", RichTextEdit
|
|
|
372
394
|
isCompositionEnd,
|
|
373
395
|
noNeedSetTextRange,
|
|
374
396
|
debounce
|
|
375
|
-
} = params, univerInstanceService = accessor.get(IUniverInstanceService), renderManagerService = accessor.get(IRenderManagerService), documentDataModel = univerInstanceService.getUniverDocInstance(unitId), documentViewModel = (
|
|
397
|
+
} = params, univerInstanceService = accessor.get(IUniverInstanceService), renderManagerService = accessor.get(IRenderManagerService), documentDataModel = univerInstanceService.getUniverDocInstance(unitId), documentViewModel = (_a11 = renderManagerService.getRenderById(unitId)) == null ? void 0 : _a11.with(DocSkeletonManagerService).getViewModel();
|
|
376
398
|
if (documentDataModel == null || documentViewModel == null)
|
|
377
399
|
throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${unitId}`);
|
|
378
|
-
const textSelectionManagerService = accessor.get(TextSelectionManagerService), serializedSelections = ((_b = textSelectionManagerService.
|
|
400
|
+
const textSelectionManagerService = accessor.get(TextSelectionManagerService), serializedSelections = ((_b = textSelectionManagerService.getDocRanges()) != null ? _b : []).map(serializeDocRange), docStateChangeManagerService = accessor.get(DocStateChangeManagerService), imeInputManagerService = accessor.get(IMEInputManagerService), disabled = !!documentDataModel.getSnapshot().disabled;
|
|
379
401
|
if (JSONX.isNoop(actions) || actions && actions.length === 0 || disabled)
|
|
380
402
|
return {
|
|
381
403
|
unitId,
|
|
@@ -416,6 +438,466 @@ const RichTextEditingMutationId = "doc.mutation.rich-text-editing", RichTextEdit
|
|
|
416
438
|
};
|
|
417
439
|
}, "handler")
|
|
418
440
|
};
|
|
441
|
+
function getCommandSkeleton(accessor, unitId) {
|
|
442
|
+
var _a11;
|
|
443
|
+
return (_a11 = accessor.get(IRenderManagerService).getRenderById(unitId)) == null ? void 0 : _a11.with(DocSkeletonManagerService);
|
|
444
|
+
}
|
|
445
|
+
__name(getCommandSkeleton, "getCommandSkeleton");
|
|
446
|
+
function getRichTextEditPath(docDataModel, segmentId = "") {
|
|
447
|
+
if (!segmentId)
|
|
448
|
+
return ["body"];
|
|
449
|
+
const { headers, footers } = docDataModel.getSnapshot();
|
|
450
|
+
if (headers == null && footers == null)
|
|
451
|
+
throw new Error("Document data model must have headers or footers when update by segment id");
|
|
452
|
+
if ((headers == null ? void 0 : headers[segmentId]) != null)
|
|
453
|
+
return ["headers", segmentId, "body"];
|
|
454
|
+
if ((footers == null ? void 0 : footers[segmentId]) != null)
|
|
455
|
+
return ["footers", segmentId, "body"];
|
|
456
|
+
throw new Error("Segment id not found in headers or footers");
|
|
457
|
+
}
|
|
458
|
+
__name(getRichTextEditPath, "getRichTextEditPath");
|
|
459
|
+
const ListOperationCommand = {
|
|
460
|
+
id: "doc.command.list-operation",
|
|
461
|
+
type: CommandType.COMMAND,
|
|
462
|
+
// eslint-disable-next-line max-lines-per-function, complexity
|
|
463
|
+
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
464
|
+
var _a11, _b, _c, _d, _e, _f;
|
|
465
|
+
const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService);
|
|
466
|
+
let listType = params.listType;
|
|
467
|
+
const docDataModel = univerInstanceService.getCurrentUniverDocInstance(), docRanges = (_a11 = textSelectionManagerService.getDocRanges()) != null ? _a11 : [];
|
|
468
|
+
if (docDataModel == null || docRanges.length === 0)
|
|
469
|
+
return !1;
|
|
470
|
+
const segmentId = docRanges[0].segmentId, paragraphs = (_b = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _b.paragraphs, serializedSelections = docRanges.map(serializeDocRange);
|
|
471
|
+
if (paragraphs == null)
|
|
472
|
+
return !1;
|
|
473
|
+
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) => {
|
|
474
|
+
var _a12;
|
|
475
|
+
return ((_a12 = paragraph.bullet) == null ? void 0 : _a12.listType.indexOf(listType)) === 0;
|
|
476
|
+
});
|
|
477
|
+
let listId = Tools.generateRandomId(6);
|
|
478
|
+
if (currentParagraphs.length === 1) {
|
|
479
|
+
const curIndex = paragraphs.indexOf(currentParagraphs[0]), prevParagraph = paragraphs[curIndex - 1], nextParagraph = paragraphs[curIndex + 1];
|
|
480
|
+
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));
|
|
481
|
+
}
|
|
482
|
+
const doMutation = {
|
|
483
|
+
id: RichTextEditingMutation.id,
|
|
484
|
+
params: {
|
|
485
|
+
unitId,
|
|
486
|
+
actions: [],
|
|
487
|
+
textRanges: serializedSelections
|
|
488
|
+
}
|
|
489
|
+
}, memoryCursor = new MemoryCursor();
|
|
490
|
+
memoryCursor.reset();
|
|
491
|
+
const textX = new TextX(), jsonX = JSONX.getInstance(), customLists = (_e = docDataModel.getSnapshot().lists) != null ? _e : {}, lists = {
|
|
492
|
+
...PRESET_LIST_TYPE,
|
|
493
|
+
...customLists
|
|
494
|
+
}, { defaultTabStop = 36 } = docDataModel.getSnapshot().documentStyle;
|
|
495
|
+
for (const paragraph of currentParagraphs) {
|
|
496
|
+
const { startIndex, paragraphStyle = {}, bullet } = paragraph, { indentFirstLine, snapToGrid, indentStart } = paragraphStyle, paragraphProperties = lists[listType].nestingLevel[0].paragraphProperties || {}, { hanging: listHanging, indentStart: listIndentStart } = paragraphProperties, bulletParagraphTextStyle = paragraphProperties.textStyle, { charSpace, gridType } = findNearestSectionBreak(startIndex, sectionBreaks) || { charSpace: 0, gridType: GridType.LINES }, bulletParagraphTextStyleEmpty = Object.keys(bulletParagraphTextStyle != null ? bulletParagraphTextStyle : {}).reduce((acc, key) => (acc[key] = void 0, acc), {}), charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);
|
|
497
|
+
textX.push({
|
|
498
|
+
t: TextXActionType.RETAIN,
|
|
499
|
+
len: startIndex - memoryCursor.cursor,
|
|
500
|
+
segmentId
|
|
501
|
+
}), textX.push({
|
|
502
|
+
t: TextXActionType.RETAIN,
|
|
503
|
+
len: 1,
|
|
504
|
+
body: {
|
|
505
|
+
dataStream: "",
|
|
506
|
+
paragraphs: [
|
|
507
|
+
isAlreadyList ? {
|
|
508
|
+
paragraphStyle: {
|
|
509
|
+
...paragraphStyle,
|
|
510
|
+
hanging: void 0,
|
|
511
|
+
indentStart: indentStart ? { v: Math.max(0, getNumberUnitValue(indentStart, charSpaceApply) + getNumberUnitValue(listHanging, charSpaceApply) - getNumberUnitValue(listIndentStart, charSpaceApply)) } : void 0,
|
|
512
|
+
textStyle: {
|
|
513
|
+
...paragraphStyle.textStyle,
|
|
514
|
+
...bulletParagraphTextStyleEmpty
|
|
515
|
+
}
|
|
516
|
+
},
|
|
517
|
+
startIndex: 0
|
|
518
|
+
} : {
|
|
519
|
+
startIndex: 0,
|
|
520
|
+
paragraphStyle: {
|
|
521
|
+
...paragraphStyle,
|
|
522
|
+
textStyle: {
|
|
523
|
+
...paragraphStyle.textStyle,
|
|
524
|
+
...bulletParagraphTextStyle,
|
|
525
|
+
...(bullet == null ? void 0 : bullet.listType) === PresetListType.CHECK_LIST_CHECKED ? {
|
|
526
|
+
st: {
|
|
527
|
+
s: BooleanNumber.FALSE
|
|
528
|
+
}
|
|
529
|
+
} : null
|
|
530
|
+
},
|
|
531
|
+
indentFirstLine: void 0,
|
|
532
|
+
hanging: listHanging,
|
|
533
|
+
indentStart: { v: getNumberUnitValue(listIndentStart, charSpaceApply) - getNumberUnitValue(listHanging, charSpaceApply) + getNumberUnitValue(indentFirstLine, charSpaceApply) + getNumberUnitValue(indentStart, charSpaceApply) }
|
|
534
|
+
},
|
|
535
|
+
bullet: {
|
|
536
|
+
nestingLevel: (_f = bullet == null ? void 0 : bullet.nestingLevel) != null ? _f : 0,
|
|
537
|
+
textStyle: {
|
|
538
|
+
fs: 20
|
|
539
|
+
},
|
|
540
|
+
listType,
|
|
541
|
+
listId
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
]
|
|
545
|
+
},
|
|
546
|
+
segmentId,
|
|
547
|
+
coverType: UpdateDocsAttributeType.REPLACE
|
|
548
|
+
}), memoryCursor.moveCursorTo(startIndex + 1);
|
|
549
|
+
}
|
|
550
|
+
const path = getRichTextEditPath(docDataModel, segmentId);
|
|
551
|
+
return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
552
|
+
}, "handler")
|
|
553
|
+
}, ChangeListTypeCommand = {
|
|
554
|
+
id: "doc.command.change-list-type",
|
|
555
|
+
type: CommandType.COMMAND,
|
|
556
|
+
// eslint-disable-next-line max-lines-per-function, complexity
|
|
557
|
+
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
558
|
+
var _a11, _b, _c, _d, _e, _f;
|
|
559
|
+
const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), { listType } = params, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), activeRanges = textSelectionManagerService.getDocRanges();
|
|
560
|
+
if (docDataModel == null || activeRanges == null || !activeRanges.length)
|
|
561
|
+
return !1;
|
|
562
|
+
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);
|
|
563
|
+
if (paragraphs == null)
|
|
564
|
+
return !1;
|
|
565
|
+
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 = {
|
|
566
|
+
id: RichTextEditingMutation.id,
|
|
567
|
+
params: {
|
|
568
|
+
unitId,
|
|
569
|
+
actions: [],
|
|
570
|
+
textRanges: serializedSelections
|
|
571
|
+
}
|
|
572
|
+
}, memoryCursor = new MemoryCursor();
|
|
573
|
+
memoryCursor.reset();
|
|
574
|
+
const textX = new TextX(), jsonX = JSONX.getInstance(), customLists = (_e = docDataModel.getSnapshot().lists) != null ? _e : {}, lists = {
|
|
575
|
+
...PRESET_LIST_TYPE,
|
|
576
|
+
...customLists
|
|
577
|
+
}, { defaultTabStop = 36 } = docDataModel.getSnapshot().documentStyle;
|
|
578
|
+
for (const paragraph of currentParagraphs) {
|
|
579
|
+
const { startIndex, paragraphStyle = {}, bullet } = paragraph, { indentFirstLine, snapToGrid, indentStart } = paragraphStyle, paragraphProperties = lists[listType].nestingLevel[0].paragraphProperties || {}, bulletParagraphTextStyle = paragraphProperties.textStyle, { hanging: listHanging, indentStart: listIndentStart } = paragraphProperties, { charSpace, gridType } = findNearestSectionBreak(startIndex, sectionBreaks) || { charSpace: 0, gridType: GridType.LINES }, charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);
|
|
580
|
+
textX.push({
|
|
581
|
+
t: TextXActionType.RETAIN,
|
|
582
|
+
len: startIndex - memoryCursor.cursor,
|
|
583
|
+
segmentId
|
|
584
|
+
}), textX.push({
|
|
585
|
+
t: TextXActionType.RETAIN,
|
|
586
|
+
len: 1,
|
|
587
|
+
body: {
|
|
588
|
+
dataStream: "",
|
|
589
|
+
paragraphs: [
|
|
590
|
+
{
|
|
591
|
+
startIndex: 0,
|
|
592
|
+
paragraphStyle: {
|
|
593
|
+
...paragraphStyle,
|
|
594
|
+
textStyle: {
|
|
595
|
+
...paragraphStyle.textStyle,
|
|
596
|
+
...bulletParagraphTextStyle,
|
|
597
|
+
...(bullet == null ? void 0 : bullet.listType) === PresetListType.CHECK_LIST_CHECKED ? {
|
|
598
|
+
st: {
|
|
599
|
+
s: BooleanNumber.FALSE
|
|
600
|
+
}
|
|
601
|
+
} : null
|
|
602
|
+
},
|
|
603
|
+
indentFirstLine: void 0,
|
|
604
|
+
hanging: listHanging,
|
|
605
|
+
indentStart: { v: getNumberUnitValue(listIndentStart, charSpaceApply) - getNumberUnitValue(listHanging, charSpaceApply) + getNumberUnitValue(indentFirstLine, charSpaceApply) + getNumberUnitValue(indentStart, charSpaceApply) }
|
|
606
|
+
},
|
|
607
|
+
bullet: {
|
|
608
|
+
nestingLevel: (_f = bullet == null ? void 0 : bullet.nestingLevel) != null ? _f : 0,
|
|
609
|
+
textStyle: (bullet == null ? void 0 : bullet.listType) === listType ? bullet.textStyle : {
|
|
610
|
+
fs: 20
|
|
611
|
+
},
|
|
612
|
+
listType,
|
|
613
|
+
listId
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
]
|
|
617
|
+
},
|
|
618
|
+
segmentId,
|
|
619
|
+
coverType: UpdateDocsAttributeType.REPLACE
|
|
620
|
+
}), memoryCursor.moveCursorTo(startIndex + 1);
|
|
621
|
+
}
|
|
622
|
+
const path = getRichTextEditPath(docDataModel, segmentId);
|
|
623
|
+
return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
624
|
+
}, "handler")
|
|
625
|
+
};
|
|
626
|
+
var ChangeListNestingLevelType = /* @__PURE__ */ ((ChangeListNestingLevelType2) => (ChangeListNestingLevelType2[ChangeListNestingLevelType2.increase = 1] = "increase", ChangeListNestingLevelType2[ChangeListNestingLevelType2.decrease = -1] = "decrease", ChangeListNestingLevelType2))(ChangeListNestingLevelType || {});
|
|
627
|
+
const ChangeListNestingLevelCommand = {
|
|
628
|
+
id: "doc.command.change-list-nesting-level",
|
|
629
|
+
type: CommandType.COMMAND,
|
|
630
|
+
// eslint-disable-next-line max-lines-per-function
|
|
631
|
+
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
632
|
+
var _a11, _b, _c;
|
|
633
|
+
if (!params)
|
|
634
|
+
return !1;
|
|
635
|
+
const { type } = params, textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), docDataModel = univerInstanceService.getCurrentUniverDocInstance(), activeRange = textSelectionManagerService.getActiveTextRangeWithStyle();
|
|
636
|
+
if (docDataModel == null || activeRange == null)
|
|
637
|
+
return !1;
|
|
638
|
+
const { segmentId } = activeRange, selections = (_a11 = textSelectionManagerService.getDocRanges()) != null ? _a11 : [], paragraphs = (_b = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _b.paragraphs, serializedSelections = selections.map(serializeDocRange);
|
|
639
|
+
if (paragraphs == null)
|
|
640
|
+
return !1;
|
|
641
|
+
const currentParagraphs = getParagraphsInRange$1(activeRange, paragraphs), unitId = docDataModel.getUnitId(), doMutation = {
|
|
642
|
+
id: RichTextEditingMutation.id,
|
|
643
|
+
params: {
|
|
644
|
+
unitId,
|
|
645
|
+
actions: [],
|
|
646
|
+
textRanges: serializedSelections
|
|
647
|
+
}
|
|
648
|
+
}, memoryCursor = new MemoryCursor();
|
|
649
|
+
memoryCursor.reset();
|
|
650
|
+
const textX = new TextX(), jsonX = JSONX.getInstance(), customLists = (_c = docDataModel.getSnapshot().lists) != null ? _c : {}, lists = {
|
|
651
|
+
...PRESET_LIST_TYPE,
|
|
652
|
+
...customLists
|
|
653
|
+
};
|
|
654
|
+
for (const paragraph of currentParagraphs) {
|
|
655
|
+
const { startIndex, paragraphStyle = {}, bullet } = paragraph;
|
|
656
|
+
if (textX.push({
|
|
657
|
+
t: TextXActionType.RETAIN,
|
|
658
|
+
len: startIndex - memoryCursor.cursor,
|
|
659
|
+
segmentId
|
|
660
|
+
}), bullet) {
|
|
661
|
+
const listType = bullet.listType, maxLevel = lists[listType].nestingLevel.length - 1;
|
|
662
|
+
textX.push({
|
|
663
|
+
t: TextXActionType.RETAIN,
|
|
664
|
+
len: 1,
|
|
665
|
+
body: {
|
|
666
|
+
dataStream: "",
|
|
667
|
+
paragraphs: [
|
|
668
|
+
{
|
|
669
|
+
startIndex: 0,
|
|
670
|
+
paragraphStyle: {
|
|
671
|
+
...paragraphStyle
|
|
672
|
+
},
|
|
673
|
+
bullet: {
|
|
674
|
+
...bullet,
|
|
675
|
+
nestingLevel: Math.max(Math.min(bullet.nestingLevel + type, maxLevel), 0)
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
]
|
|
679
|
+
},
|
|
680
|
+
segmentId,
|
|
681
|
+
coverType: UpdateDocsAttributeType.REPLACE
|
|
682
|
+
});
|
|
683
|
+
} else
|
|
684
|
+
textX.push({
|
|
685
|
+
t: TextXActionType.RETAIN,
|
|
686
|
+
len: 1
|
|
687
|
+
});
|
|
688
|
+
memoryCursor.moveCursorTo(startIndex + 1);
|
|
689
|
+
}
|
|
690
|
+
const path = getRichTextEditPath(docDataModel, segmentId);
|
|
691
|
+
return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
692
|
+
}, "handler")
|
|
693
|
+
}, BulletListCommand = {
|
|
694
|
+
id: "doc.command.bullet-list",
|
|
695
|
+
type: CommandType.COMMAND,
|
|
696
|
+
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
697
|
+
const commandService = accessor.get(ICommandService);
|
|
698
|
+
return params != null && params.value ? commandService.syncExecuteCommand(ChangeListTypeCommand.id, {
|
|
699
|
+
listType: params.value
|
|
700
|
+
}) : commandService.syncExecuteCommand(ListOperationCommand.id, {
|
|
701
|
+
listType: PresetListType.BULLET_LIST
|
|
702
|
+
});
|
|
703
|
+
}, "handler")
|
|
704
|
+
}, CheckListCommand = {
|
|
705
|
+
id: "doc.command.check-list",
|
|
706
|
+
type: CommandType.COMMAND,
|
|
707
|
+
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
708
|
+
const commandService = accessor.get(ICommandService);
|
|
709
|
+
return params != null && params.value ? commandService.syncExecuteCommand(ChangeListTypeCommand.id, {
|
|
710
|
+
listType: params.value
|
|
711
|
+
}) : commandService.syncExecuteCommand(ListOperationCommand.id, {
|
|
712
|
+
listType: PresetListType.CHECK_LIST
|
|
713
|
+
});
|
|
714
|
+
}, "handler")
|
|
715
|
+
}, ToggleCheckListCommand = {
|
|
716
|
+
id: "doc.command.toggle-check-list",
|
|
717
|
+
type: CommandType.COMMAND,
|
|
718
|
+
// eslint-disable-next-line max-lines-per-function
|
|
719
|
+
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
720
|
+
var _a11, _b;
|
|
721
|
+
if (!params)
|
|
722
|
+
return !1;
|
|
723
|
+
const univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), { index } = params, docDataModel = univerInstanceService.getCurrentUniverDocInstance();
|
|
724
|
+
if (docDataModel == null)
|
|
725
|
+
return !1;
|
|
726
|
+
const paragraphs = (_a11 = docDataModel.getBody()) == null ? void 0 : _a11.paragraphs;
|
|
727
|
+
if (paragraphs == null)
|
|
728
|
+
return !1;
|
|
729
|
+
const currentParagraph = paragraphs.find((p) => p.startIndex === index), unitId = docDataModel.getUnitId();
|
|
730
|
+
if (!(currentParagraph != null && currentParagraph.bullet) || currentParagraph.bullet.listType.indexOf(PresetListType.CHECK_LIST) === -1)
|
|
731
|
+
return !1;
|
|
732
|
+
const doMutation = {
|
|
733
|
+
id: RichTextEditingMutation.id,
|
|
734
|
+
params: {
|
|
735
|
+
unitId,
|
|
736
|
+
actions: [],
|
|
737
|
+
textRanges: []
|
|
738
|
+
}
|
|
739
|
+
}, memoryCursor = new MemoryCursor();
|
|
740
|
+
memoryCursor.reset();
|
|
741
|
+
const textX = new TextX(), jsonX = JSONX.getInstance(), customLists = (_b = docDataModel.getSnapshot().lists) != null ? _b : {}, lists = {
|
|
742
|
+
...PRESET_LIST_TYPE,
|
|
743
|
+
...customLists
|
|
744
|
+
}, { startIndex, paragraphStyle = {} } = currentParagraph, listType = currentParagraph.bullet.listType === PresetListType.CHECK_LIST ? PresetListType.CHECK_LIST_CHECKED : PresetListType.CHECK_LIST, bulletParagraphTextStyle = (lists[listType].nestingLevel[0].paragraphProperties || {}).textStyle;
|
|
745
|
+
textX.push({
|
|
746
|
+
t: TextXActionType.RETAIN,
|
|
747
|
+
len: startIndex - memoryCursor.cursor
|
|
748
|
+
}), textX.push({
|
|
749
|
+
t: TextXActionType.RETAIN,
|
|
750
|
+
len: 1,
|
|
751
|
+
body: {
|
|
752
|
+
dataStream: "",
|
|
753
|
+
paragraphs: [
|
|
754
|
+
{
|
|
755
|
+
...currentParagraph,
|
|
756
|
+
paragraphStyle: {
|
|
757
|
+
...paragraphStyle,
|
|
758
|
+
textStyle: {
|
|
759
|
+
...paragraphStyle.textStyle,
|
|
760
|
+
...bulletParagraphTextStyle
|
|
761
|
+
}
|
|
762
|
+
},
|
|
763
|
+
startIndex: 0,
|
|
764
|
+
bullet: {
|
|
765
|
+
...currentParagraph.bullet,
|
|
766
|
+
listType
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
]
|
|
770
|
+
},
|
|
771
|
+
coverType: UpdateDocsAttributeType.REPLACE
|
|
772
|
+
}), memoryCursor.moveCursorTo(startIndex + 1);
|
|
773
|
+
const path = getRichTextEditPath(docDataModel);
|
|
774
|
+
return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
775
|
+
}, "handler")
|
|
776
|
+
}, OrderListCommand = {
|
|
777
|
+
id: "doc.command.order-list",
|
|
778
|
+
type: CommandType.COMMAND,
|
|
779
|
+
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
780
|
+
const commandService = accessor.get(ICommandService);
|
|
781
|
+
return params != null && params.value ? commandService.syncExecuteCommand(ChangeListTypeCommand.id, {
|
|
782
|
+
listType: params.value
|
|
783
|
+
}) : commandService.syncExecuteCommand(ListOperationCommand.id, {
|
|
784
|
+
listType: PresetListType.ORDER_LIST
|
|
785
|
+
});
|
|
786
|
+
}, "handler")
|
|
787
|
+
}, QuickListCommand = {
|
|
788
|
+
id: "doc.command.quick-list",
|
|
789
|
+
type: CommandType.COMMAND,
|
|
790
|
+
// eslint-disable-next-line max-lines-per-function
|
|
791
|
+
handler(accessor, params) {
|
|
792
|
+
var _a11, _b, _c, _d, _e;
|
|
793
|
+
if (!params)
|
|
794
|
+
return !1;
|
|
795
|
+
const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), docDataModel = univerInstanceService.getCurrentUniverDocInstance(), activeRange = textSelectionManagerService.getActiveTextRange();
|
|
796
|
+
if (docDataModel == null || activeRange == null)
|
|
797
|
+
return !1;
|
|
798
|
+
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);
|
|
799
|
+
let listId = Tools.generateRandomId(6);
|
|
800
|
+
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];
|
|
801
|
+
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);
|
|
802
|
+
const doMutation = {
|
|
803
|
+
id: RichTextEditingMutation.id,
|
|
804
|
+
params: {
|
|
805
|
+
unitId: docDataModel.getUnitId(),
|
|
806
|
+
actions: [],
|
|
807
|
+
textRanges: [{
|
|
808
|
+
startOffset: paragraphStart,
|
|
809
|
+
endOffset: paragraphStart,
|
|
810
|
+
collapsed: !0
|
|
811
|
+
}]
|
|
812
|
+
}
|
|
813
|
+
};
|
|
814
|
+
textX.push({
|
|
815
|
+
t: TextXActionType.RETAIN,
|
|
816
|
+
len: paragraphStart
|
|
817
|
+
}), textX.push({
|
|
818
|
+
t: TextXActionType.DELETE,
|
|
819
|
+
len: paragraphEnd - paragraphStart,
|
|
820
|
+
line: 1
|
|
821
|
+
}), textX.push({
|
|
822
|
+
t: TextXActionType.RETAIN,
|
|
823
|
+
len: 1,
|
|
824
|
+
body: {
|
|
825
|
+
dataStream: "",
|
|
826
|
+
paragraphs: [
|
|
827
|
+
{
|
|
828
|
+
startIndex: 0,
|
|
829
|
+
paragraphStyle: {
|
|
830
|
+
...paragraphStyle,
|
|
831
|
+
textStyle: {
|
|
832
|
+
...paragraphStyle.textStyle,
|
|
833
|
+
...bulletParagraphTextStyle
|
|
834
|
+
},
|
|
835
|
+
indentFirstLine: void 0,
|
|
836
|
+
hanging: listHanging,
|
|
837
|
+
indentStart: { v: getNumberUnitValue(listIndentStart, charSpaceApply) - getNumberUnitValue(listHanging, charSpaceApply) + getNumberUnitValue(indentFirstLine, charSpaceApply) + getNumberUnitValue(indentStart, charSpaceApply) }
|
|
838
|
+
},
|
|
839
|
+
bullet: {
|
|
840
|
+
...(_e = paragraph.bullet) != null ? _e : {
|
|
841
|
+
nestingLevel: 0,
|
|
842
|
+
textStyle: {
|
|
843
|
+
fs: 20
|
|
844
|
+
}
|
|
845
|
+
},
|
|
846
|
+
listType,
|
|
847
|
+
listId
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
]
|
|
851
|
+
}
|
|
852
|
+
});
|
|
853
|
+
const path = getRichTextEditPath(docDataModel, segmentId);
|
|
854
|
+
return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
function getParagraphsInRange$1(activeRange, paragraphs) {
|
|
858
|
+
const { startOffset, endOffset } = activeRange, results = [];
|
|
859
|
+
let start = -1;
|
|
860
|
+
for (const paragraph of paragraphs) {
|
|
861
|
+
const { startIndex } = paragraph;
|
|
862
|
+
(startOffset > start && startOffset <= startIndex || endOffset > start && endOffset <= startIndex || startIndex >= startOffset && startIndex <= endOffset) && results.push(paragraph), start = startIndex;
|
|
863
|
+
}
|
|
864
|
+
return results;
|
|
865
|
+
}
|
|
866
|
+
__name(getParagraphsInRange$1, "getParagraphsInRange$1");
|
|
867
|
+
function getParagraphsRelative(ranges, paragraphs) {
|
|
868
|
+
const selectionParagraphs = getParagraphsInRanges(ranges, paragraphs), startIndex = paragraphs.indexOf(selectionParagraphs[0]), endIndex = paragraphs.indexOf(selectionParagraphs[selectionParagraphs.length - 1]);
|
|
869
|
+
if (selectionParagraphs[0].bullet)
|
|
870
|
+
for (let i = startIndex - 1; i >= 0; i--) {
|
|
871
|
+
const prevParagraph = paragraphs[i];
|
|
872
|
+
prevParagraph.bullet && prevParagraph.bullet.listId === selectionParagraphs[0].bullet.listId && selectionParagraphs.unshift(prevParagraph);
|
|
873
|
+
}
|
|
874
|
+
const lastParagraph = selectionParagraphs[selectionParagraphs.length - 1];
|
|
875
|
+
if (lastParagraph.bullet)
|
|
876
|
+
for (let i = endIndex + 1; i < paragraphs.length; i++) {
|
|
877
|
+
const nextParagraph = paragraphs[i];
|
|
878
|
+
nextParagraph.bullet && nextParagraph.bullet.listId === lastParagraph.bullet.listId && selectionParagraphs.push(nextParagraph);
|
|
879
|
+
}
|
|
880
|
+
return selectionParagraphs;
|
|
881
|
+
}
|
|
882
|
+
__name(getParagraphsRelative, "getParagraphsRelative");
|
|
883
|
+
function getParagraphsInRanges(ranges, paragraphs) {
|
|
884
|
+
const results = [];
|
|
885
|
+
for (const range of ranges) {
|
|
886
|
+
const ps = getParagraphsInRange$1(range, paragraphs);
|
|
887
|
+
results.push(...ps);
|
|
888
|
+
}
|
|
889
|
+
return results;
|
|
890
|
+
}
|
|
891
|
+
__name(getParagraphsInRanges, "getParagraphsInRanges");
|
|
892
|
+
function findNearestSectionBreak(currentIndex, sectionBreaks) {
|
|
893
|
+
const sortedSectionBreaks = sectionBreaks.sort(sortRulesFactory("startIndex"));
|
|
894
|
+
for (let i = 0; i < sortedSectionBreaks.length; i++) {
|
|
895
|
+
const sectionBreak = sectionBreaks[i];
|
|
896
|
+
if (sectionBreak.startIndex >= currentIndex)
|
|
897
|
+
return sectionBreak;
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
__name(findNearestSectionBreak, "findNearestSectionBreak");
|
|
419
901
|
function isCustomRangeSplitSymbol(text) {
|
|
420
902
|
return text === DataStreamTreeTokenType.CUSTOM_RANGE_END || text === DataStreamTreeTokenType.CUSTOM_RANGE_START;
|
|
421
903
|
}
|
|
@@ -439,7 +921,24 @@ function shouldDeleteCustomRange(deleteStart, deleteLen, customRange, dataStream
|
|
|
439
921
|
return !0;
|
|
440
922
|
}
|
|
441
923
|
__name(shouldDeleteCustomRange, "shouldDeleteCustomRange");
|
|
924
|
+
function getCustomRangesIntesetsWithRange(range, customRanges) {
|
|
925
|
+
const result = [];
|
|
926
|
+
for (let i = 0, len = customRanges.length; i < len; i++) {
|
|
927
|
+
const customRange = customRanges[i];
|
|
928
|
+
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);
|
|
929
|
+
}
|
|
930
|
+
return result;
|
|
931
|
+
}
|
|
932
|
+
__name(getCustomRangesIntesetsWithRange, "getCustomRangesIntesetsWithRange");
|
|
442
933
|
var DeleteDirection = /* @__PURE__ */ ((DeleteDirection2) => (DeleteDirection2[DeleteDirection2.LEFT = 0] = "LEFT", DeleteDirection2[DeleteDirection2.RIGHT = 1] = "RIGHT", DeleteDirection2))(DeleteDirection || {});
|
|
934
|
+
function makeSelection(startOffset, endOffset) {
|
|
935
|
+
if (typeof endOffset > "u")
|
|
936
|
+
return { startOffset, endOffset: startOffset, collapsed: !0 };
|
|
937
|
+
if (endOffset < startOffset)
|
|
938
|
+
throw new Error(`Cannot make a doc selection when endOffset ${endOffset} is less than startOffset ${startOffset}.`);
|
|
939
|
+
return { startOffset, endOffset, collapsed: startOffset === endOffset };
|
|
940
|
+
}
|
|
941
|
+
__name(makeSelection, "makeSelection");
|
|
443
942
|
function normalizeSelection(selection) {
|
|
444
943
|
const { startOffset, endOffset, collapsed } = selection, start = Math.min(startOffset, endOffset), end = Math.max(startOffset, endOffset);
|
|
445
944
|
return {
|
|
@@ -462,7 +961,7 @@ function getSelectionWithSymbolMax(selection, body) {
|
|
|
462
961
|
}
|
|
463
962
|
__name(getSelectionWithSymbolMax, "getSelectionWithSymbolMax");
|
|
464
963
|
function getDeleteSelection(selection, body, direction = DeleteDirection.LEFT) {
|
|
465
|
-
var
|
|
964
|
+
var _a11;
|
|
466
965
|
let { startOffset, endOffset, collapsed } = normalizeSelection(selection);
|
|
467
966
|
if (collapsed)
|
|
468
967
|
if (direction === DeleteDirection.LEFT)
|
|
@@ -476,7 +975,7 @@ function getDeleteSelection(selection, body, direction = DeleteDirection.LEFT) {
|
|
|
476
975
|
startOffset = selectionWithSymbolMax.startOffset, endOffset = selectionWithSymbolMax.endOffset;
|
|
477
976
|
}
|
|
478
977
|
collapsed = startOffset === endOffset;
|
|
479
|
-
const customRanges = (
|
|
978
|
+
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));
|
|
480
979
|
return customRanges != null && customRanges.length && customRanges.forEach((range) => {
|
|
481
980
|
startOffset = Math.min(range.startIndex, startOffset), endOffset = Math.max(range.endIndex + 1, endOffset);
|
|
482
981
|
}), {
|
|
@@ -593,18 +1092,18 @@ function isSegmentIntersects(start, end, start2, end2) {
|
|
|
593
1092
|
return Math.max(start, start2) <= Math.min(end, end2);
|
|
594
1093
|
}
|
|
595
1094
|
__name(isSegmentIntersects, "isSegmentIntersects");
|
|
596
|
-
function getRetainAndDeleteAndExcludeLineBreak(selection, body, segmentId = "", memoryCursor = 0) {
|
|
597
|
-
var
|
|
1095
|
+
function getRetainAndDeleteAndExcludeLineBreak(selection, body, segmentId = "", memoryCursor = 0, preserveLineBreak = !0) {
|
|
1096
|
+
var _a11;
|
|
598
1097
|
const { startOffset, endOffset } = getDeleteSelection(selection, body), dos = [], { paragraphs = [], dataStream } = body, textStart = startOffset - memoryCursor, textEnd = endOffset - memoryCursor, paragraphInRange = paragraphs == null ? void 0 : paragraphs.find(
|
|
599
1098
|
(p) => p.startIndex - memoryCursor >= textStart && p.startIndex - memoryCursor < textEnd
|
|
600
|
-
), relativeCustomRanges = (
|
|
1099
|
+
), 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();
|
|
601
1100
|
if (relativeCustomRanges == null || relativeCustomRanges.forEach((range) => {
|
|
602
1101
|
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));
|
|
603
1102
|
}), textStart > 0 && dos.push({
|
|
604
1103
|
t: TextXActionType.RETAIN,
|
|
605
1104
|
len: textStart,
|
|
606
1105
|
segmentId
|
|
607
|
-
}), paragraphInRange && paragraphInRange.startIndex - memoryCursor > textStart) {
|
|
1106
|
+
}), preserveLineBreak && paragraphInRange && paragraphInRange.startIndex - memoryCursor > textStart) {
|
|
608
1107
|
const paragraphIndex = paragraphInRange.startIndex - memoryCursor;
|
|
609
1108
|
retainPoints.add(paragraphIndex);
|
|
610
1109
|
}
|
|
@@ -631,11 +1130,17 @@ function getRetainAndDeleteAndExcludeLineBreak(selection, body, segmentId = "",
|
|
|
631
1130
|
}
|
|
632
1131
|
__name(getRetainAndDeleteAndExcludeLineBreak, "getRetainAndDeleteAndExcludeLineBreak");
|
|
633
1132
|
function replaceSelectionFactory(accessor, params) {
|
|
634
|
-
var
|
|
635
|
-
const { unitId, body: insertBody } = params,
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
1133
|
+
var _a11, _b;
|
|
1134
|
+
const { unitId, originBody, body: insertBody } = params, univerInstanceService = accessor.get(IUniverInstanceService);
|
|
1135
|
+
let body;
|
|
1136
|
+
if (params.originBody)
|
|
1137
|
+
body = originBody;
|
|
1138
|
+
else {
|
|
1139
|
+
const docDataModel = univerInstanceService.getUnit(unitId);
|
|
1140
|
+
body = docDataModel == null ? void 0 : docDataModel.getBody();
|
|
1141
|
+
}
|
|
1142
|
+
if (!body) return !1;
|
|
1143
|
+
const textSelectionManagerService = accessor.get(TextSelectionManagerService), selection = (_a11 = params.selection) != null ? _a11 : textSelectionManagerService.getActiveTextRangeWithStyle();
|
|
639
1144
|
if (!selection || !body)
|
|
640
1145
|
return !1;
|
|
641
1146
|
const textRanges = (_b = params.textRanges) != null ? _b : [{
|
|
@@ -720,8 +1225,8 @@ const _DocCustomRangeService = class _DocCustomRangeService {
|
|
|
720
1225
|
__name(_DocCustomRangeService, "DocCustomRangeService");
|
|
721
1226
|
let DocCustomRangeService = _DocCustomRangeService;
|
|
722
1227
|
function getRetainAndDeleteFromReplace(range, segmentId = "", memoryCursor, body) {
|
|
723
|
-
var
|
|
724
|
-
const { startOffset, endOffset } = range, dos = [], textStart = startOffset - memoryCursor, textEnd = endOffset - memoryCursor, dataStream = body.dataStream, relativeCustomRanges = (
|
|
1228
|
+
var _a11;
|
|
1229
|
+
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();
|
|
725
1230
|
relativeCustomRanges == null || relativeCustomRanges.forEach((range2) => {
|
|
726
1231
|
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));
|
|
727
1232
|
}), textStart > 0 && dos.push({
|
|
@@ -755,34 +1260,16 @@ function getRetainAndDeleteFromReplace(range, segmentId = "", memoryCursor, body
|
|
|
755
1260
|
};
|
|
756
1261
|
}
|
|
757
1262
|
__name(getRetainAndDeleteFromReplace, "getRetainAndDeleteFromReplace");
|
|
758
|
-
function getCommandSkeleton(accessor, unitId) {
|
|
759
|
-
var _a10;
|
|
760
|
-
return (_a10 = accessor.get(IRenderManagerService).getRenderById(unitId)) == null ? void 0 : _a10.with(DocSkeletonManagerService);
|
|
761
|
-
}
|
|
762
|
-
__name(getCommandSkeleton, "getCommandSkeleton");
|
|
763
|
-
function getRichTextEditPath(docDataModel, segmentId = "") {
|
|
764
|
-
if (!segmentId)
|
|
765
|
-
return ["body"];
|
|
766
|
-
const { headers, footers } = docDataModel.getSnapshot();
|
|
767
|
-
if (headers == null && footers == null)
|
|
768
|
-
throw new Error("Document data model must have headers or footers when update by segment id");
|
|
769
|
-
if ((headers == null ? void 0 : headers[segmentId]) != null)
|
|
770
|
-
return ["headers", segmentId, "body"];
|
|
771
|
-
if ((footers == null ? void 0 : footers[segmentId]) != null)
|
|
772
|
-
return ["footers", segmentId, "body"];
|
|
773
|
-
throw new Error("Segment id not found in headers or footers");
|
|
774
|
-
}
|
|
775
|
-
__name(getRichTextEditPath, "getRichTextEditPath");
|
|
776
1263
|
const EditorInsertTextCommandId = "doc.command.insert-text", InsertCommand = {
|
|
777
1264
|
id: EditorInsertTextCommandId,
|
|
778
1265
|
type: CommandType.COMMAND,
|
|
779
1266
|
// eslint-disable-next-line max-lines-per-function
|
|
780
1267
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
781
|
-
var
|
|
1268
|
+
var _a11;
|
|
782
1269
|
const commandService = accessor.get(ICommandService), { range, segmentId, body, unitId, textRanges: propTextRanges, cursorOffset } = params, textSelectionManagerService = accessor.get(TextSelectionManagerService), docDataModel = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
783
1270
|
if (docDataModel == null)
|
|
784
1271
|
return !1;
|
|
785
|
-
const activeRange = textSelectionManagerService.
|
|
1272
|
+
const activeRange = textSelectionManagerService.getActiveTextRangeWithStyle(), originBody = docDataModel.getSelfOrHeaderFooterModel((_a11 = activeRange == null ? void 0 : activeRange.segmentId) != null ? _a11 : "").getBody();
|
|
786
1273
|
if (!originBody)
|
|
787
1274
|
return !1;
|
|
788
1275
|
const actualRange = getInsertSelection(range, originBody), { startOffset, collapsed } = actualRange, cursorMove = cursorOffset != null ? cursorOffset : body.dataStream.length, textRanges = [
|
|
@@ -829,11 +1316,11 @@ const EditorInsertTextCommandId = "doc.command.insert-text", InsertCommand = {
|
|
|
829
1316
|
id: "doc.command.delete-text",
|
|
830
1317
|
type: CommandType.COMMAND,
|
|
831
1318
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
832
|
-
var
|
|
1319
|
+
var _a11;
|
|
833
1320
|
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();
|
|
834
1321
|
if (docDataModel == null || body == null)
|
|
835
1322
|
return !1;
|
|
836
|
-
const { startOffset } = range, dataStream = body.dataStream, start = direction === DeleteDirection.LEFT ? startOffset - len : startOffset, end = start + len - 1, relativeCustomRanges = (
|
|
1323
|
+
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 = [];
|
|
837
1324
|
for (let i = 0; i < len; i++)
|
|
838
1325
|
deleteIndexes.push(start + i);
|
|
839
1326
|
toDeleteRanges == null || toDeleteRanges.forEach((range2) => {
|
|
@@ -900,6 +1387,7 @@ const EditorInsertTextCommandId = "doc.command.insert-text", InsertCommand = {
|
|
|
900
1387
|
}, "handler")
|
|
901
1388
|
};
|
|
902
1389
|
function generateParagraphs(dataStream, prevParagraph) {
|
|
1390
|
+
var _a11, _b;
|
|
903
1391
|
const paragraphs = [];
|
|
904
1392
|
for (let i = 0, len = dataStream.length; i < len; i++)
|
|
905
1393
|
dataStream[i] === DataStreamTreeTokenType.PARAGRAPH && paragraphs.push({
|
|
@@ -907,7 +1395,9 @@ function generateParagraphs(dataStream, prevParagraph) {
|
|
|
907
1395
|
});
|
|
908
1396
|
if (prevParagraph)
|
|
909
1397
|
for (const paragraph of paragraphs)
|
|
910
|
-
prevParagraph.bullet && (paragraph.bullet = Tools.deepClone(prevParagraph.bullet)), prevParagraph.paragraphStyle && (paragraph.paragraphStyle = Tools.deepClone(prevParagraph.paragraphStyle))
|
|
1398
|
+
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 = {
|
|
1399
|
+
s: BooleanNumber.FALSE
|
|
1400
|
+
}));
|
|
911
1401
|
return paragraphs;
|
|
912
1402
|
}
|
|
913
1403
|
__name(generateParagraphs, "generateParagraphs");
|
|
@@ -915,20 +1405,27 @@ const BreakLineCommand = {
|
|
|
915
1405
|
id: "doc.command.break-line",
|
|
916
1406
|
type: CommandType.COMMAND,
|
|
917
1407
|
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
918
|
-
var
|
|
919
|
-
const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), customRangeService = accessor.get(DocCustomRangeService),
|
|
920
|
-
if (
|
|
1408
|
+
var _a11, _b;
|
|
1409
|
+
const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), customRangeService = accessor.get(DocCustomRangeService), activeTextRange = textSelectionManagerService.getActiveTextRangeWithStyle(), rectRanges = textSelectionManagerService.getCurrentRectRanges();
|
|
1410
|
+
if (activeTextRange == null)
|
|
921
1411
|
return !1;
|
|
922
|
-
|
|
1412
|
+
if (rectRanges && rectRanges.length) {
|
|
1413
|
+
const { startOffset: startOffset2 } = activeTextRange;
|
|
1414
|
+
return textSelectionManagerService.replaceTextRanges([{
|
|
1415
|
+
startOffset: startOffset2,
|
|
1416
|
+
endOffset: startOffset2
|
|
1417
|
+
}]), !0;
|
|
1418
|
+
}
|
|
1419
|
+
const { segmentId } = activeTextRange, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), body = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
923
1420
|
if (!docDataModel || !body)
|
|
924
1421
|
return !1;
|
|
925
|
-
const unitId = docDataModel.getUnitId(), { startOffset, endOffset } = getInsertSelection(
|
|
1422
|
+
const unitId = docDataModel.getUnitId(), { startOffset, endOffset } = getInsertSelection(activeTextRange, body), prevParagraph = ((_a11 = body.paragraphs) != null ? _a11 : []).find((p) => p.startIndex >= startOffset);
|
|
926
1423
|
if (prevParagraph && prevParagraph.startIndex > endOffset) {
|
|
927
|
-
const bodyAfter = normalizeBody(getBodySlice(body, endOffset, prevParagraph.startIndex));
|
|
1424
|
+
const bodyAfter = normalizeBody(getBodySlice(body, endOffset, prevParagraph.startIndex + 1));
|
|
928
1425
|
bodyAfter.customRanges = (_b = bodyAfter.customRanges) == null ? void 0 : _b.map((range) => customRangeService.copyCustomRange(unitId, range));
|
|
929
1426
|
const deleteRange = {
|
|
930
1427
|
startOffset,
|
|
931
|
-
endOffset: prevParagraph.startIndex,
|
|
1428
|
+
endOffset: prevParagraph.startIndex + 1,
|
|
932
1429
|
collapsed: !1
|
|
933
1430
|
};
|
|
934
1431
|
return updateAttributeByInsert(
|
|
@@ -953,16 +1450,447 @@ const BreakLineCommand = {
|
|
|
953
1450
|
dataStream: DataStreamTreeTokenType.PARAGRAPH,
|
|
954
1451
|
paragraphs: generateParagraphs(DataStreamTreeTokenType.PARAGRAPH, prevParagraph)
|
|
955
1452
|
},
|
|
956
|
-
range:
|
|
1453
|
+
range: activeTextRange,
|
|
957
1454
|
segmentId
|
|
958
1455
|
});
|
|
959
1456
|
}, "handler")
|
|
960
|
-
}
|
|
1457
|
+
};
|
|
1458
|
+
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 || {});
|
|
1459
|
+
function genEmptyTable(rowCount, colCount) {
|
|
1460
|
+
let dataStream = DataStreamTreeTokenType.TABLE_START;
|
|
1461
|
+
const paragraphs = [], sectionBreaks = [];
|
|
1462
|
+
for (let i = 0; i < rowCount; i++) {
|
|
1463
|
+
dataStream += DataStreamTreeTokenType.TABLE_ROW_START;
|
|
1464
|
+
for (let j = 0; j < colCount; j++)
|
|
1465
|
+
dataStream += `${DataStreamTreeTokenType.TABLE_CELL_START}\r
|
|
1466
|
+
${DataStreamTreeTokenType.TABLE_CELL_END}`, paragraphs.push({
|
|
1467
|
+
startIndex: dataStream.length - 3,
|
|
1468
|
+
paragraphStyle: {
|
|
1469
|
+
spaceAbove: { v: 3 },
|
|
1470
|
+
lineSpacing: 2,
|
|
1471
|
+
spaceBelow: { v: 0 }
|
|
1472
|
+
}
|
|
1473
|
+
}), sectionBreaks.push({
|
|
1474
|
+
startIndex: dataStream.length - 2
|
|
1475
|
+
});
|
|
1476
|
+
dataStream += DataStreamTreeTokenType.TABLE_ROW_END;
|
|
1477
|
+
}
|
|
1478
|
+
return dataStream += DataStreamTreeTokenType.TABLE_END, {
|
|
1479
|
+
dataStream,
|
|
1480
|
+
paragraphs,
|
|
1481
|
+
sectionBreaks
|
|
1482
|
+
};
|
|
1483
|
+
}
|
|
1484
|
+
__name(genEmptyTable, "genEmptyTable");
|
|
1485
|
+
function getEmptyTableCell() {
|
|
1486
|
+
return {
|
|
1487
|
+
margin: {
|
|
1488
|
+
start: {
|
|
1489
|
+
v: 10
|
|
1490
|
+
},
|
|
1491
|
+
end: {
|
|
1492
|
+
v: 10
|
|
1493
|
+
},
|
|
1494
|
+
top: {
|
|
1495
|
+
v: 5
|
|
1496
|
+
},
|
|
1497
|
+
bottom: {
|
|
1498
|
+
v: 5
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
};
|
|
1502
|
+
}
|
|
1503
|
+
__name(getEmptyTableCell, "getEmptyTableCell");
|
|
1504
|
+
function getEmptyTableRow(col) {
|
|
1505
|
+
const tableCell = getEmptyTableCell();
|
|
1506
|
+
return {
|
|
1507
|
+
tableCells: [...new Array(col).fill(null).map(() => Tools.deepClone(tableCell))],
|
|
1508
|
+
trHeight: {
|
|
1509
|
+
val: { v: 30 },
|
|
1510
|
+
hRule: TableCellHeightRule.AUTO
|
|
1511
|
+
}
|
|
1512
|
+
};
|
|
1513
|
+
}
|
|
1514
|
+
__name(getEmptyTableRow, "getEmptyTableRow");
|
|
1515
|
+
function getTableColumn(width) {
|
|
1516
|
+
return {
|
|
1517
|
+
size: {
|
|
1518
|
+
type: TableSizeType.SPECIFIED,
|
|
1519
|
+
width: {
|
|
1520
|
+
v: width
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
};
|
|
1524
|
+
}
|
|
1525
|
+
__name(getTableColumn, "getTableColumn");
|
|
1526
|
+
function genTableSource(rowCount, colCount, pageContentWidth) {
|
|
1527
|
+
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);
|
|
1528
|
+
return {
|
|
1529
|
+
tableRows,
|
|
1530
|
+
tableColumns,
|
|
1531
|
+
tableId,
|
|
1532
|
+
align: TableAlignmentType.START,
|
|
1533
|
+
indent: {
|
|
1534
|
+
v: 0
|
|
1535
|
+
},
|
|
1536
|
+
textWrap: TableTextWrapType.NONE,
|
|
1537
|
+
position: {
|
|
1538
|
+
positionH: {
|
|
1539
|
+
relativeFrom: ObjectRelativeFromH.PAGE,
|
|
1540
|
+
posOffset: 0
|
|
1541
|
+
},
|
|
1542
|
+
positionV: {
|
|
1543
|
+
relativeFrom: ObjectRelativeFromV.PAGE,
|
|
1544
|
+
posOffset: 0
|
|
1545
|
+
}
|
|
1546
|
+
},
|
|
1547
|
+
dist: {
|
|
1548
|
+
distB: 0,
|
|
1549
|
+
distL: 0,
|
|
1550
|
+
distR: 0,
|
|
1551
|
+
distT: 0
|
|
1552
|
+
},
|
|
1553
|
+
cellMargin: {
|
|
1554
|
+
start: {
|
|
1555
|
+
v: 10
|
|
1556
|
+
},
|
|
1557
|
+
end: {
|
|
1558
|
+
v: 10
|
|
1559
|
+
},
|
|
1560
|
+
top: {
|
|
1561
|
+
v: 5
|
|
1562
|
+
},
|
|
1563
|
+
bottom: {
|
|
1564
|
+
v: 5
|
|
1565
|
+
}
|
|
1566
|
+
},
|
|
1567
|
+
size: {
|
|
1568
|
+
type: TableSizeType.UNSPECIFIED,
|
|
1569
|
+
width: {
|
|
1570
|
+
v: pageContentWidth
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
};
|
|
1574
|
+
}
|
|
1575
|
+
__name(genTableSource, "genTableSource");
|
|
1576
|
+
function getRangeInfoFromRanges(textRange, rectRanges) {
|
|
1577
|
+
if (!textRange && !rectRanges)
|
|
1578
|
+
return null;
|
|
1579
|
+
if (rectRanges && rectRanges.length > 0) {
|
|
1580
|
+
let startOffset = Number.POSITIVE_INFINITY, endOffset = Number.NEGATIVE_INFINITY;
|
|
1581
|
+
const segmentId = "";
|
|
1582
|
+
for (const rectRange of rectRanges) {
|
|
1583
|
+
const { startOffset: st, endOffset: ed, segmentId: sid } = rectRange;
|
|
1584
|
+
st == null || ed == null || sid == null || (startOffset = Math.min(startOffset, st), endOffset = Math.max(endOffset, ed));
|
|
1585
|
+
}
|
|
1586
|
+
if (Number.isFinite(startOffset) && Number.isFinite(endOffset))
|
|
1587
|
+
return {
|
|
1588
|
+
startOffset,
|
|
1589
|
+
endOffset,
|
|
1590
|
+
segmentId
|
|
1591
|
+
};
|
|
1592
|
+
} else if (textRange) {
|
|
1593
|
+
const { startOffset, endOffset, segmentId } = textRange;
|
|
1594
|
+
return startOffset == null || endOffset == null || segmentId == null ? null : {
|
|
1595
|
+
startOffset,
|
|
1596
|
+
endOffset,
|
|
1597
|
+
segmentId
|
|
1598
|
+
};
|
|
1599
|
+
}
|
|
1600
|
+
}
|
|
1601
|
+
__name(getRangeInfoFromRanges, "getRangeInfoFromRanges");
|
|
1602
|
+
function getInsertRowBody(col) {
|
|
1603
|
+
let dataStream = DataStreamTreeTokenType.TABLE_ROW_START;
|
|
1604
|
+
const paragraphs = [], sectionBreaks = [];
|
|
1605
|
+
for (let i = 0; i < col; i++)
|
|
1606
|
+
dataStream += `${DataStreamTreeTokenType.TABLE_CELL_START}\r
|
|
1607
|
+
${DataStreamTreeTokenType.TABLE_CELL_END}`, paragraphs.push({
|
|
1608
|
+
startIndex: dataStream.length - 3,
|
|
1609
|
+
paragraphStyle: {
|
|
1610
|
+
spaceAbove: { v: 3 },
|
|
1611
|
+
lineSpacing: 2,
|
|
1612
|
+
spaceBelow: { v: 0 }
|
|
1613
|
+
}
|
|
1614
|
+
}), sectionBreaks.push({
|
|
1615
|
+
startIndex: dataStream.length - 2
|
|
1616
|
+
});
|
|
1617
|
+
return dataStream += DataStreamTreeTokenType.TABLE_ROW_END, {
|
|
1618
|
+
dataStream,
|
|
1619
|
+
paragraphs,
|
|
1620
|
+
sectionBreaks
|
|
1621
|
+
};
|
|
1622
|
+
}
|
|
1623
|
+
__name(getInsertRowBody, "getInsertRowBody");
|
|
1624
|
+
function getInsertColumnBody() {
|
|
1625
|
+
const dataStream = `${DataStreamTreeTokenType.TABLE_CELL_START}\r
|
|
1626
|
+
${DataStreamTreeTokenType.TABLE_CELL_END}`, paragraphs = [], sectionBreaks = [];
|
|
1627
|
+
return paragraphs.push({
|
|
1628
|
+
startIndex: 1,
|
|
1629
|
+
paragraphStyle: {
|
|
1630
|
+
spaceAbove: { v: 3 },
|
|
1631
|
+
lineSpacing: 2,
|
|
1632
|
+
spaceBelow: { v: 0 }
|
|
1633
|
+
}
|
|
1634
|
+
}), sectionBreaks.push({
|
|
1635
|
+
startIndex: 2
|
|
1636
|
+
}), {
|
|
1637
|
+
dataStream,
|
|
1638
|
+
paragraphs,
|
|
1639
|
+
sectionBreaks
|
|
1640
|
+
};
|
|
1641
|
+
}
|
|
1642
|
+
__name(getInsertColumnBody, "getInsertColumnBody");
|
|
1643
|
+
function getInsertRowActionsParams(rangeInfo, position, viewModel) {
|
|
1644
|
+
var _a11, _b, _c;
|
|
1645
|
+
const { startOffset, endOffset, segmentId } = rangeInfo, vm = viewModel.getSelfOrHeaderFooterViewModel(segmentId), index = position === 0 ? startOffset : endOffset;
|
|
1646
|
+
let tableRow = null;
|
|
1647
|
+
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;
|
|
1648
|
+
let rowIndex = 0;
|
|
1649
|
+
for (const section of vm.children) {
|
|
1650
|
+
for (const paragraph of section.children) {
|
|
1651
|
+
const { children } = paragraph, table = children[0];
|
|
1652
|
+
if (table) {
|
|
1653
|
+
for (const row of table.children)
|
|
1654
|
+
if (row.startIndex <= index && index <= row.endIndex) {
|
|
1655
|
+
rowIndex = table.children.indexOf(row), tableRow = row;
|
|
1656
|
+
break;
|
|
1657
|
+
}
|
|
1658
|
+
}
|
|
1659
|
+
if (tableRow)
|
|
1660
|
+
break;
|
|
1661
|
+
}
|
|
1662
|
+
if (tableRow)
|
|
1663
|
+
break;
|
|
1664
|
+
}
|
|
1665
|
+
return tableRow == null || tableId == null ? null : {
|
|
1666
|
+
offset: position === 0 ? tableRow.startIndex : tableRow.endIndex + 1,
|
|
1667
|
+
colCount: tableRow.children.length,
|
|
1668
|
+
tableId,
|
|
1669
|
+
insertRowIndex: position === 0 ? rowIndex : rowIndex + 1
|
|
1670
|
+
};
|
|
1671
|
+
}
|
|
1672
|
+
__name(getInsertRowActionsParams, "getInsertRowActionsParams");
|
|
1673
|
+
function getInsertColumnActionsParams(rangeInfo, position, viewModel) {
|
|
1674
|
+
var _a11, _b, _c;
|
|
1675
|
+
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 = [];
|
|
1676
|
+
let table = null, columnIndex = -1;
|
|
1677
|
+
for (const section of vm.children) {
|
|
1678
|
+
for (const paragraph of section.children) {
|
|
1679
|
+
const { children } = paragraph, tableNode = children[0];
|
|
1680
|
+
if (tableNode) {
|
|
1681
|
+
if (index < tableNode.startIndex || index > tableNode.endIndex)
|
|
1682
|
+
continue;
|
|
1683
|
+
table = tableNode;
|
|
1684
|
+
for (const row of tableNode.children) {
|
|
1685
|
+
for (const cell of row.children) {
|
|
1686
|
+
const cellIndex = row.children.indexOf(cell);
|
|
1687
|
+
if (index >= cell.startIndex && index <= cell.endIndex) {
|
|
1688
|
+
columnIndex = cellIndex;
|
|
1689
|
+
break;
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
if (columnIndex !== -1)
|
|
1693
|
+
break;
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
if (table)
|
|
1697
|
+
break;
|
|
1698
|
+
}
|
|
1699
|
+
if (table)
|
|
1700
|
+
break;
|
|
1701
|
+
}
|
|
1702
|
+
if (table == null || tableId == null || columnIndex === -1)
|
|
1703
|
+
return null;
|
|
1704
|
+
let cursor = 0;
|
|
1705
|
+
for (const row of table.children) {
|
|
1706
|
+
const cell = row.children[columnIndex], insertIndex = position === 0 ? cell.startIndex : cell.endIndex + 1;
|
|
1707
|
+
offsets.push(insertIndex - cursor), cursor = insertIndex;
|
|
1708
|
+
}
|
|
1709
|
+
return {
|
|
1710
|
+
offsets,
|
|
1711
|
+
tableId,
|
|
1712
|
+
columnIndex,
|
|
1713
|
+
rowCount: table.children.length
|
|
1714
|
+
};
|
|
1715
|
+
}
|
|
1716
|
+
__name(getInsertColumnActionsParams, "getInsertColumnActionsParams");
|
|
1717
|
+
function getColumnWidths(pageWidth, tableColumns, insertColumnIndex) {
|
|
1718
|
+
const widths = [];
|
|
1719
|
+
let newColWidth = tableColumns[insertColumnIndex].size.width.v, totalWidth = 0;
|
|
1720
|
+
for (let i = 0; i < tableColumns.length; i++)
|
|
1721
|
+
totalWidth += tableColumns[i].size.width.v;
|
|
1722
|
+
totalWidth += newColWidth;
|
|
1723
|
+
for (let i = 0; i < tableColumns.length; i++)
|
|
1724
|
+
widths.push(tableColumns[i].size.width.v / totalWidth * pageWidth);
|
|
1725
|
+
return newColWidth = newColWidth / totalWidth * pageWidth, {
|
|
1726
|
+
widths,
|
|
1727
|
+
newColWidth
|
|
1728
|
+
};
|
|
1729
|
+
}
|
|
1730
|
+
__name(getColumnWidths, "getColumnWidths");
|
|
1731
|
+
function getDeleteRowsActionsParams(rangeInfo, viewModel) {
|
|
1732
|
+
var _a11, _b, _c;
|
|
1733
|
+
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 = [];
|
|
1734
|
+
let offset = -1, len = 0, cursor = -1, selectWholeTable = !1;
|
|
1735
|
+
for (const section of vm.children) {
|
|
1736
|
+
for (const paragraph of section.children) {
|
|
1737
|
+
const { children } = paragraph, table = children[0];
|
|
1738
|
+
if (table) {
|
|
1739
|
+
if (startOffset < table.startIndex || endOffset > table.endIndex)
|
|
1740
|
+
continue;
|
|
1741
|
+
cursor = table.startIndex + 3;
|
|
1742
|
+
for (const row of table.children) {
|
|
1743
|
+
const rowIndex = table.children.indexOf(row), { startIndex, endIndex } = row;
|
|
1744
|
+
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);
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
if (rowIndexes.length)
|
|
1748
|
+
break;
|
|
1749
|
+
}
|
|
1750
|
+
if (rowIndexes.length)
|
|
1751
|
+
break;
|
|
1752
|
+
}
|
|
1753
|
+
return tableId == null || rowIndexes.length === 0 ? null : {
|
|
1754
|
+
tableId,
|
|
1755
|
+
rowIndexes,
|
|
1756
|
+
offset,
|
|
1757
|
+
len,
|
|
1758
|
+
cursor,
|
|
1759
|
+
selectWholeTable
|
|
1760
|
+
};
|
|
1761
|
+
}
|
|
1762
|
+
__name(getDeleteRowsActionsParams, "getDeleteRowsActionsParams");
|
|
1763
|
+
function getDeleteColumnsActionParams(rangeInfo, viewModel) {
|
|
1764
|
+
var _a11, _b, _c;
|
|
1765
|
+
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 = [];
|
|
1766
|
+
let table = null;
|
|
1767
|
+
const columnIndexes = [];
|
|
1768
|
+
let cursor = -1, startColumnIndex = -1, endColumnIndex = -1;
|
|
1769
|
+
for (const section of vm.children) {
|
|
1770
|
+
for (const paragraph of section.children) {
|
|
1771
|
+
const { children } = paragraph, tableNode = children[0];
|
|
1772
|
+
if (tableNode) {
|
|
1773
|
+
if (startOffset < tableNode.startIndex || endOffset > tableNode.endIndex)
|
|
1774
|
+
continue;
|
|
1775
|
+
table = tableNode;
|
|
1776
|
+
for (const row of tableNode.children)
|
|
1777
|
+
for (const cell of row.children) {
|
|
1778
|
+
const cellIndex = row.children.indexOf(cell);
|
|
1779
|
+
startOffset >= cell.startIndex && startOffset <= cell.endIndex && (startColumnIndex = cellIndex), endOffset >= cell.startIndex && endOffset <= cell.endIndex && (endColumnIndex = cellIndex);
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
if (table)
|
|
1783
|
+
break;
|
|
1784
|
+
}
|
|
1785
|
+
if (table)
|
|
1786
|
+
break;
|
|
1787
|
+
}
|
|
1788
|
+
if (table == null || tableId == null)
|
|
1789
|
+
return null;
|
|
1790
|
+
for (let i = startColumnIndex; i <= endColumnIndex; i++)
|
|
1791
|
+
columnIndexes.push(i);
|
|
1792
|
+
let delta = 0;
|
|
1793
|
+
for (const row of table.children) {
|
|
1794
|
+
const startCell = row.children[startColumnIndex], endCell = row.children[endColumnIndex];
|
|
1795
|
+
offsets.push({
|
|
1796
|
+
retain: startCell.startIndex - delta,
|
|
1797
|
+
delete: endCell.endIndex - startCell.startIndex + 1
|
|
1798
|
+
}), delta = endCell.endIndex + 1;
|
|
1799
|
+
}
|
|
1800
|
+
return cursor = table.startIndex + 3, {
|
|
1801
|
+
offsets,
|
|
1802
|
+
tableId,
|
|
1803
|
+
columnIndexes,
|
|
1804
|
+
cursor,
|
|
1805
|
+
selectWholeTable: columnIndexes.length === table.children[0].children.length,
|
|
1806
|
+
rowCount: table.children.length
|
|
1807
|
+
};
|
|
1808
|
+
}
|
|
1809
|
+
__name(getDeleteColumnsActionParams, "getDeleteColumnsActionParams");
|
|
1810
|
+
function getDeleteTableActionParams(rangeInfo, viewModel) {
|
|
1811
|
+
var _a11, _b, _c;
|
|
1812
|
+
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;
|
|
1813
|
+
let offset = -1, len = 0, cursor = -1;
|
|
1814
|
+
for (const section of vm.children) {
|
|
1815
|
+
for (const paragraph of section.children) {
|
|
1816
|
+
const { children } = paragraph, table = children[0];
|
|
1817
|
+
if (table) {
|
|
1818
|
+
if (startOffset < table.startIndex || endOffset > table.endIndex)
|
|
1819
|
+
continue;
|
|
1820
|
+
offset = table.startIndex, len = table.endIndex - table.startIndex + 1, cursor = table.startIndex;
|
|
1821
|
+
}
|
|
1822
|
+
if (table)
|
|
1823
|
+
break;
|
|
1824
|
+
}
|
|
1825
|
+
if (len > 0)
|
|
1826
|
+
break;
|
|
1827
|
+
}
|
|
1828
|
+
return tableId == null ? null : {
|
|
1829
|
+
tableId,
|
|
1830
|
+
offset,
|
|
1831
|
+
len,
|
|
1832
|
+
cursor
|
|
1833
|
+
};
|
|
1834
|
+
}
|
|
1835
|
+
__name(getDeleteTableActionParams, "getDeleteTableActionParams");
|
|
1836
|
+
function getDeleteRowContentActionParams(rangeInfo, viewModel) {
|
|
1837
|
+
var _a11, _b, _c;
|
|
1838
|
+
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 = [];
|
|
1839
|
+
let table = null, cursor = -1, rowIndex = -1, startColumnIndex = -1, endColumnIndex = -1;
|
|
1840
|
+
for (const section of vm.children) {
|
|
1841
|
+
for (const paragraph of section.children) {
|
|
1842
|
+
const { children } = paragraph, tableNode = children[0];
|
|
1843
|
+
if (tableNode) {
|
|
1844
|
+
if (startOffset < tableNode.startIndex || endOffset > tableNode.endIndex)
|
|
1845
|
+
continue;
|
|
1846
|
+
table = tableNode;
|
|
1847
|
+
for (const row2 of tableNode.children) {
|
|
1848
|
+
const rIndex = tableNode.children.indexOf(row2);
|
|
1849
|
+
for (const cell of row2.children) {
|
|
1850
|
+
const cellIndex = row2.children.indexOf(cell);
|
|
1851
|
+
startOffset >= cell.startIndex && startOffset <= cell.endIndex && (rowIndex = rIndex, startColumnIndex = cellIndex), endOffset >= cell.startIndex && endOffset <= cell.endIndex && (endColumnIndex = cellIndex);
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1855
|
+
if (table)
|
|
1856
|
+
break;
|
|
1857
|
+
}
|
|
1858
|
+
if (table)
|
|
1859
|
+
break;
|
|
1860
|
+
}
|
|
1861
|
+
if (table == null || tableId == null || rowIndex === -1)
|
|
1862
|
+
return null;
|
|
1863
|
+
const row = table.children[rowIndex];
|
|
1864
|
+
for (let i = startColumnIndex; i <= endColumnIndex; i++) {
|
|
1865
|
+
const cell = row.children[i];
|
|
1866
|
+
offsets.push({
|
|
1867
|
+
retain: cell.startIndex + 1,
|
|
1868
|
+
delete: cell.endIndex - cell.startIndex - 3
|
|
1869
|
+
});
|
|
1870
|
+
}
|
|
1871
|
+
return cursor = table.startIndex + 3, {
|
|
1872
|
+
offsets,
|
|
1873
|
+
tableId,
|
|
1874
|
+
cursor,
|
|
1875
|
+
rowCount: table.children.length
|
|
1876
|
+
};
|
|
1877
|
+
}
|
|
1878
|
+
__name(getDeleteRowContentActionParams, "getDeleteRowContentActionParams");
|
|
1879
|
+
function hasRangeInTable(ranges) {
|
|
1880
|
+
return ranges.some((range) => {
|
|
1881
|
+
const { anchorNodePosition } = range;
|
|
1882
|
+
return anchorNodePosition ? (anchorNodePosition == null ? void 0 : anchorNodePosition.path.indexOf("cells")) > -1 : !1;
|
|
1883
|
+
});
|
|
1884
|
+
}
|
|
1885
|
+
__name(hasRangeInTable, "hasRangeInTable");
|
|
1886
|
+
const InnerPasteCommand = {
|
|
961
1887
|
id: "doc.command.inner-paste",
|
|
962
1888
|
type: CommandType.COMMAND,
|
|
1889
|
+
// eslint-disable-next-line max-lines-per-function
|
|
963
1890
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
964
|
-
|
|
965
|
-
|
|
1891
|
+
var _a11;
|
|
1892
|
+
const { segmentId, textRanges, doc } = params, commandService = accessor.get(ICommandService), textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), selections = textSelectionManagerService.getCurrentTextRanges(), { body, tableSource } = doc;
|
|
1893
|
+
if (!Array.isArray(selections) || selections.length === 0 || body == null)
|
|
966
1894
|
return !1;
|
|
967
1895
|
const docDataModel = univerInstanceService.getCurrentUniverDocInstance(), originBody = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
968
1896
|
if (docDataModel == null || originBody == null)
|
|
@@ -976,9 +1904,20 @@ const BreakLineCommand = {
|
|
|
976
1904
|
}
|
|
977
1905
|
}, memoryCursor = new MemoryCursor();
|
|
978
1906
|
memoryCursor.reset();
|
|
979
|
-
const textX = new TextX(), jsonX = JSONX.getInstance();
|
|
1907
|
+
const textX = new TextX(), jsonX = JSONX.getInstance(), rawActions = [], hasTable = !!((_a11 = body.tables) != null && _a11.length);
|
|
1908
|
+
if (hasTable && segmentId || hasTable && hasRangeInTable(selections))
|
|
1909
|
+
return !1;
|
|
980
1910
|
for (const selection of selections) {
|
|
981
|
-
const { startOffset, endOffset, collapsed } = selection, len = startOffset - memoryCursor.cursor;
|
|
1911
|
+
const { startOffset, endOffset, collapsed } = selection, len = startOffset - memoryCursor.cursor, cloneBody = Tools.deepClone(body);
|
|
1912
|
+
if (hasTable)
|
|
1913
|
+
for (const t of cloneBody.tables) {
|
|
1914
|
+
const { tableId: oldTableId } = t, tableId = Tools.generateRandomId(6);
|
|
1915
|
+
t.tableId = tableId;
|
|
1916
|
+
const table = Tools.deepClone(tableSource[oldTableId]);
|
|
1917
|
+
table.tableId = tableId;
|
|
1918
|
+
const action = jsonX.insertOp(["tableSource", tableId], table);
|
|
1919
|
+
rawActions.push(action);
|
|
1920
|
+
}
|
|
982
1921
|
if (collapsed)
|
|
983
1922
|
textX.push({
|
|
984
1923
|
t: TextXActionType.RETAIN,
|
|
@@ -991,63 +1930,151 @@ const BreakLineCommand = {
|
|
|
991
1930
|
}
|
|
992
1931
|
textX.push({
|
|
993
1932
|
t: TextXActionType.INSERT,
|
|
994
|
-
body,
|
|
1933
|
+
body: cloneBody,
|
|
995
1934
|
len: body.dataStream.length,
|
|
996
1935
|
line: 0,
|
|
997
1936
|
segmentId
|
|
998
1937
|
}), memoryCursor.reset(), memoryCursor.moveCursor(endOffset);
|
|
999
1938
|
}
|
|
1000
1939
|
const path = getRichTextEditPath(docDataModel, segmentId);
|
|
1001
|
-
return doMutation.params.actions =
|
|
1940
|
+
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);
|
|
1002
1941
|
}, "handler")
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1942
|
+
};
|
|
1943
|
+
function getCutActionsFromTextRanges(selections, docDataModel, segmentId) {
|
|
1944
|
+
var _a11, _b;
|
|
1945
|
+
const originBody = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody(), textX = new TextX(), jsonX = JSONX.getInstance(), rawActions = [];
|
|
1946
|
+
if (originBody == null)
|
|
1947
|
+
return rawActions;
|
|
1948
|
+
const memoryCursor = new MemoryCursor();
|
|
1949
|
+
memoryCursor.reset();
|
|
1950
|
+
for (const selection of selections) {
|
|
1951
|
+
const { startOffset, endOffset, collapsed } = selection;
|
|
1952
|
+
if (startOffset == null || endOffset == null)
|
|
1953
|
+
continue;
|
|
1954
|
+
const len = startOffset - memoryCursor.cursor;
|
|
1955
|
+
collapsed ? textX.push({
|
|
1956
|
+
t: TextXActionType.RETAIN,
|
|
1957
|
+
len,
|
|
1958
|
+
segmentId
|
|
1959
|
+
}) : textX.push(...getRetainAndDeleteAndExcludeLineBreak(selection, originBody, segmentId, memoryCursor.cursor, !1)), memoryCursor.reset(), memoryCursor.moveCursor(endOffset);
|
|
1960
|
+
}
|
|
1961
|
+
const path = getRichTextEditPath(docDataModel, segmentId);
|
|
1962
|
+
rawActions.push(jsonX.editOp(textX.serialize(), path));
|
|
1963
|
+
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);
|
|
1964
|
+
if (sortedRemovedCustomBlockIds.length > 0)
|
|
1965
|
+
for (const blockId of sortedRemovedCustomBlockIds) {
|
|
1966
|
+
const drawing = drawings[blockId], drawingIndex = drawingOrder.indexOf(blockId);
|
|
1967
|
+
if (drawing == null || drawingIndex < 0)
|
|
1968
|
+
continue;
|
|
1969
|
+
const removeDrawingAction = jsonX.removeOp(["drawings", blockId], drawing), removeDrawingOrderAction = jsonX.removeOp(["drawingsOrder", drawingIndex], blockId);
|
|
1970
|
+
rawActions.push(removeDrawingAction), rawActions.push(removeDrawingOrderAction);
|
|
1971
|
+
}
|
|
1972
|
+
return rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null);
|
|
1973
|
+
}
|
|
1974
|
+
__name(getCutActionsFromTextRanges, "getCutActionsFromTextRanges");
|
|
1975
|
+
function getCutActionsFromRectRanges(ranges, docDataModel, viewModel, segmentId) {
|
|
1976
|
+
const rawActions = [];
|
|
1977
|
+
if (docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody() == null)
|
|
1978
|
+
return rawActions;
|
|
1979
|
+
const textX = new TextX(), jsonX = JSONX.getInstance(), memoryCursor = new MemoryCursor();
|
|
1980
|
+
memoryCursor.reset();
|
|
1981
|
+
for (const range of ranges) {
|
|
1982
|
+
const { startOffset, endOffset, spanEntireRow, spanEntireTable } = range;
|
|
1983
|
+
if (!(startOffset == null || endOffset == null))
|
|
1984
|
+
if (spanEntireTable) {
|
|
1985
|
+
const actionParams = getDeleteTableActionParams({ startOffset, endOffset, segmentId }, viewModel);
|
|
1986
|
+
if (actionParams == null)
|
|
1987
|
+
continue;
|
|
1988
|
+
const { offset, len, tableId } = actionParams;
|
|
1989
|
+
offset - memoryCursor.cursor > 0 && textX.push({
|
|
1990
|
+
t: TextXActionType.RETAIN,
|
|
1991
|
+
len: offset - memoryCursor.cursor,
|
|
1992
|
+
segmentId
|
|
1993
|
+
}), textX.push({
|
|
1994
|
+
t: TextXActionType.DELETE,
|
|
1995
|
+
len,
|
|
1996
|
+
line: 0,
|
|
1997
|
+
segmentId
|
|
1998
|
+
});
|
|
1999
|
+
const action = jsonX.removeOp(["tableSource", tableId]);
|
|
2000
|
+
rawActions.push(action), memoryCursor.moveCursorTo(offset + len);
|
|
2001
|
+
} else if (spanEntireRow) {
|
|
2002
|
+
const actionParams = getDeleteRowsActionsParams({ startOffset, endOffset, segmentId }, viewModel);
|
|
2003
|
+
if (actionParams == null)
|
|
2004
|
+
continue;
|
|
2005
|
+
const { offset, rowIndexes, len, tableId } = actionParams;
|
|
2006
|
+
offset - memoryCursor.cursor > 0 && textX.push({
|
|
2007
|
+
t: TextXActionType.RETAIN,
|
|
2008
|
+
len: offset - memoryCursor.cursor,
|
|
2009
|
+
segmentId
|
|
2010
|
+
}), textX.push({
|
|
2011
|
+
t: TextXActionType.DELETE,
|
|
2012
|
+
len,
|
|
2013
|
+
line: 0,
|
|
2014
|
+
segmentId
|
|
2015
|
+
});
|
|
2016
|
+
for (const index of rowIndexes.reverse()) {
|
|
2017
|
+
const action = jsonX.removeOp(["tableSource", tableId, "tableRows", index]);
|
|
2018
|
+
rawActions.push(action);
|
|
2019
|
+
}
|
|
2020
|
+
memoryCursor.moveCursorTo(offset + len);
|
|
2021
|
+
} else {
|
|
2022
|
+
const actionParams = getDeleteRowContentActionParams({ startOffset, endOffset, segmentId }, viewModel);
|
|
2023
|
+
if (actionParams == null)
|
|
2024
|
+
continue;
|
|
2025
|
+
const { offsets } = actionParams;
|
|
2026
|
+
for (const offset of offsets) {
|
|
2027
|
+
const { retain, delete: delLen } = offset;
|
|
2028
|
+
retain - memoryCursor.cursor > 0 && textX.push({
|
|
2029
|
+
t: TextXActionType.RETAIN,
|
|
2030
|
+
len: retain - memoryCursor.cursor,
|
|
2031
|
+
segmentId
|
|
2032
|
+
}), textX.push({
|
|
2033
|
+
t: TextXActionType.DELETE,
|
|
2034
|
+
len: delLen,
|
|
2035
|
+
line: 0,
|
|
2036
|
+
segmentId
|
|
2037
|
+
}), memoryCursor.moveCursorTo(retain + delLen);
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
const path = getRichTextEditPath(docDataModel, segmentId);
|
|
2042
|
+
return rawActions.push(jsonX.editOp(textX.serialize(), path)), rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null);
|
|
2043
|
+
}
|
|
2044
|
+
__name(getCutActionsFromRectRanges, "getCutActionsFromRectRanges");
|
|
2045
|
+
const INNER_CUT_COMMAND_ID = "doc.command.inner-cut", CutContentCommand = {
|
|
2046
|
+
id: INNER_CUT_COMMAND_ID,
|
|
1005
2047
|
type: CommandType.COMMAND,
|
|
1006
|
-
// eslint-disable-next-line max-lines-per-function
|
|
1007
2048
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1008
|
-
var
|
|
1009
|
-
const { segmentId, textRanges } = params, commandService = accessor.get(ICommandService), textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), selections = (
|
|
1010
|
-
if (!Array.isArray(selections) || selections.length === 0)
|
|
2049
|
+
var _a11, _b, _c;
|
|
2050
|
+
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();
|
|
2051
|
+
if ((!Array.isArray(selections) || selections.length === 0) && (!Array.isArray(rectRanges) || rectRanges.length === 0))
|
|
1011
2052
|
return !1;
|
|
1012
2053
|
const unitId = (_b = univerInstanceService.getCurrentUniverDocInstance()) == null ? void 0 : _b.getUnitId();
|
|
1013
2054
|
if (!unitId)
|
|
1014
2055
|
return !1;
|
|
1015
|
-
const docDataModel = univerInstanceService.getUniverDocInstance(unitId)
|
|
1016
|
-
if (docDataModel == null
|
|
2056
|
+
const docDataModel = univerInstanceService.getUniverDocInstance(unitId);
|
|
2057
|
+
if (docDataModel == null)
|
|
1017
2058
|
return !1;
|
|
1018
|
-
const
|
|
2059
|
+
const docSkeletonManagerService = getCommandSkeleton(accessor, unitId);
|
|
2060
|
+
if (docSkeletonManagerService == null)
|
|
2061
|
+
return !1;
|
|
2062
|
+
const viewModel = docSkeletonManagerService.getViewModel(), doMutation = {
|
|
1019
2063
|
id: RichTextEditingMutation.id,
|
|
1020
2064
|
params: {
|
|
1021
2065
|
unitId,
|
|
1022
2066
|
actions: [],
|
|
1023
2067
|
textRanges
|
|
1024
2068
|
}
|
|
1025
|
-
}
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
const len = startOffset - memoryCursor.cursor;
|
|
1033
|
-
collapsed ? textX.push({
|
|
1034
|
-
t: TextXActionType.RETAIN,
|
|
1035
|
-
len,
|
|
1036
|
-
segmentId
|
|
1037
|
-
}) : textX.push(...getRetainAndDeleteAndExcludeLineBreak(selection, originBody, segmentId, memoryCursor.cursor)), memoryCursor.reset(), memoryCursor.moveCursor(endOffset);
|
|
2069
|
+
};
|
|
2070
|
+
if (Array.isArray(selections) && (selections == null ? void 0 : selections.length) !== 0 && (doMutation.params.actions = getCutActionsFromTextRanges(selections, docDataModel, segmentId)), Array.isArray(rectRanges) && (rectRanges == null ? void 0 : rectRanges.length) !== 0) {
|
|
2071
|
+
const actions = getCutActionsFromRectRanges(rectRanges, docDataModel, viewModel, segmentId);
|
|
2072
|
+
((_c = doMutation.params.actions) == null ? void 0 : _c.length) === 0 || doMutation.params.actions == null ? doMutation.params.actions = actions : doMutation.params.actions = JSONX.compose(
|
|
2073
|
+
doMutation.params.actions,
|
|
2074
|
+
JSONX.transform(actions, doMutation.params.actions, "right")
|
|
2075
|
+
);
|
|
1038
2076
|
}
|
|
1039
|
-
|
|
1040
|
-
rawActions.push(jsonX.editOp(textX.serialize(), path));
|
|
1041
|
-
const removedCustomBlockIds = getCustomBlockIdsInSelections(originBody, selections), drawings = (_c = docDataModel.getDrawings()) != null ? _c : {}, drawingOrder = (_d = docDataModel.getDrawingsOrder()) != null ? _d : [], sortedRemovedCustomBlockIds = removedCustomBlockIds.sort((a, b) => drawingOrder.indexOf(a) > drawingOrder.indexOf(b) ? -1 : drawingOrder.indexOf(a) < drawingOrder.indexOf(b) ? 1 : 0);
|
|
1042
|
-
if (sortedRemovedCustomBlockIds.length > 0)
|
|
1043
|
-
for (const blockId of sortedRemovedCustomBlockIds) {
|
|
1044
|
-
const drawing = drawings[blockId], drawingIndex = drawingOrder.indexOf(blockId);
|
|
1045
|
-
if (drawing == null || drawingIndex < 0)
|
|
1046
|
-
continue;
|
|
1047
|
-
const removeDrawingAction = jsonX.removeOp(["drawings", blockId], drawing), removeDrawingOrderAction = jsonX.removeOp(["drawingsOrder", drawingIndex], blockId);
|
|
1048
|
-
rawActions.push(removeDrawingAction), rawActions.push(removeDrawingOrderAction);
|
|
1049
|
-
}
|
|
1050
|
-
return doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
2077
|
+
return !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
1051
2078
|
}, "handler")
|
|
1052
2079
|
};
|
|
1053
2080
|
function getCustomBlockIdsInSelections(body, selections) {
|
|
@@ -1067,8 +2094,8 @@ const DeleteCustomBlockCommand = {
|
|
|
1067
2094
|
id: "doc.command.delete-custom-block",
|
|
1068
2095
|
type: CommandType.COMMAND,
|
|
1069
2096
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1070
|
-
var
|
|
1071
|
-
const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), activeRange = textSelectionManagerService.
|
|
2097
|
+
var _a11;
|
|
2098
|
+
const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), activeRange = textSelectionManagerService.getActiveTextRangeWithStyle(), documentDataModel = univerInstanceService.getCurrentUniverDocInstance();
|
|
1072
2099
|
if (activeRange == null || documentDataModel == null)
|
|
1073
2100
|
return !1;
|
|
1074
2101
|
const { direction, range, unitId, drawingId } = params, { startOffset, segmentId, style } = activeRange, cursor = direction === DeleteDirection.LEFT ? startOffset - 1 : startOffset, textRanges = [
|
|
@@ -1098,7 +2125,7 @@ const DeleteCustomBlockCommand = {
|
|
|
1098
2125
|
});
|
|
1099
2126
|
const path = getRichTextEditPath(documentDataModel, segmentId);
|
|
1100
2127
|
rawActions.push(jsonX.editOp(textX.serialize(), path));
|
|
1101
|
-
const drawing = ((
|
|
2128
|
+
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);
|
|
1102
2129
|
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);
|
|
1103
2130
|
}, "handler")
|
|
1104
2131
|
}, MergeTwoParagraphCommand = {
|
|
@@ -1106,8 +2133,7 @@ const DeleteCustomBlockCommand = {
|
|
|
1106
2133
|
type: CommandType.COMMAND,
|
|
1107
2134
|
// eslint-disable-next-line max-lines-per-function
|
|
1108
2135
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1109
|
-
|
|
1110
|
-
const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), { direction, range } = params, activeRange = textSelectionManagerService.getActiveRange(), ranges = textSelectionManagerService.getCurrentSelections();
|
|
2136
|
+
const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), { direction, range } = params, activeRange = textSelectionManagerService.getActiveTextRangeWithStyle(), ranges = textSelectionManagerService.getCurrentTextRanges();
|
|
1111
2137
|
if (activeRange == null || ranges == null)
|
|
1112
2138
|
return !1;
|
|
1113
2139
|
const { segmentId, style } = activeRange, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), originBody = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
@@ -1116,7 +2142,7 @@ const DeleteCustomBlockCommand = {
|
|
|
1116
2142
|
const actualRange = getDeleteSelection(activeRange, originBody), unitId = docDataModel.getUnitId(), { startOffset, collapsed } = actualRange;
|
|
1117
2143
|
if (!collapsed)
|
|
1118
2144
|
return !1;
|
|
1119
|
-
const startIndex = direction === DeleteDirection.LEFT ? startOffset : startOffset + 1, endIndex =
|
|
2145
|
+
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 = [
|
|
1120
2146
|
{
|
|
1121
2147
|
startOffset: cursor,
|
|
1122
2148
|
endOffset: cursor,
|
|
@@ -1154,19 +2180,55 @@ const DeleteCustomBlockCommand = {
|
|
|
1154
2180
|
const path = getRichTextEditPath(docDataModel, segmentId);
|
|
1155
2181
|
return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
1156
2182
|
}, "handler")
|
|
1157
|
-
}
|
|
2183
|
+
};
|
|
2184
|
+
function getCursorWhenDelete(textRanges, rectRanges) {
|
|
2185
|
+
let cursor = 0;
|
|
2186
|
+
if (textRanges == null || textRanges.length === 0) {
|
|
2187
|
+
if (typeof rectRanges[0].startOffset == "number") {
|
|
2188
|
+
const rectRange = rectRanges[0], { spanEntireRow, spanEntireTable } = rectRange;
|
|
2189
|
+
spanEntireTable ? cursor = rectRange.startOffset - 3 : spanEntireRow ? rectRange.startRow > 0 ? cursor = rectRange.startOffset - 6 : cursor = rectRange.startOffset : cursor = rectRanges[0].startOffset;
|
|
2190
|
+
}
|
|
2191
|
+
} else if (textRanges.length > 0 && rectRanges.length > 0) {
|
|
2192
|
+
const textRange = textRanges[0], rectRange = rectRanges[0];
|
|
2193
|
+
if (textRange.startOffset != null && rectRange.startOffset != null) {
|
|
2194
|
+
if (textRange.startOffset < rectRange.startOffset)
|
|
2195
|
+
cursor = textRange.startOffset;
|
|
2196
|
+
else if (textRange.startOffset >= rectRange.startOffset) {
|
|
2197
|
+
const { spanEntireRow, spanEntireTable } = rectRange;
|
|
2198
|
+
spanEntireTable ? cursor = rectRange.startOffset - 3 : spanEntireRow && (cursor = rectRange.startOffset - 6);
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
}
|
|
2202
|
+
return cursor;
|
|
2203
|
+
}
|
|
2204
|
+
__name(getCursorWhenDelete, "getCursorWhenDelete");
|
|
2205
|
+
const DeleteLeftCommand = {
|
|
1158
2206
|
id: "doc.command.delete-left",
|
|
1159
2207
|
type: CommandType.COMMAND,
|
|
1160
2208
|
// eslint-disable-next-line max-lines-per-function, complexity
|
|
1161
2209
|
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
1162
|
-
var
|
|
2210
|
+
var _a11, _b;
|
|
1163
2211
|
const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService);
|
|
1164
2212
|
let result = !0;
|
|
1165
2213
|
const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
|
|
1166
2214
|
if (!docDataModel)
|
|
1167
2215
|
return !1;
|
|
1168
|
-
const unitId = docDataModel.getUnitId(), docSkeletonManagerService = getCommandSkeleton(accessor, unitId), activeRange = textSelectionManagerService.
|
|
1169
|
-
if (
|
|
2216
|
+
const unitId = docDataModel.getUnitId(), docSkeletonManagerService = getCommandSkeleton(accessor, unitId), activeRange = textSelectionManagerService.getActiveTextRangeWithStyle(), rectRanges = textSelectionManagerService.getCurrentRectRanges(), ranges = textSelectionManagerService.getCurrentTextRanges(), skeleton = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getSkeleton();
|
|
2217
|
+
if (skeleton == null)
|
|
2218
|
+
return !1;
|
|
2219
|
+
if (rectRanges != null && rectRanges.length) {
|
|
2220
|
+
const cursor2 = getCursorWhenDelete(ranges, rectRanges), segmentId2 = rectRanges[0].segmentId, textRanges = [
|
|
2221
|
+
{
|
|
2222
|
+
startOffset: cursor2,
|
|
2223
|
+
endOffset: cursor2
|
|
2224
|
+
}
|
|
2225
|
+
];
|
|
2226
|
+
return commandService.executeCommand(CutContentCommand.id, {
|
|
2227
|
+
segmentId: segmentId2,
|
|
2228
|
+
textRanges
|
|
2229
|
+
});
|
|
2230
|
+
}
|
|
2231
|
+
if (activeRange == null || ranges == null)
|
|
1170
2232
|
return !1;
|
|
1171
2233
|
const { segmentId, style, segmentPage } = activeRange, body = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
1172
2234
|
if (body == null)
|
|
@@ -1220,7 +2282,7 @@ const DeleteCustomBlockCommand = {
|
|
|
1220
2282
|
range: actualRange
|
|
1221
2283
|
});
|
|
1222
2284
|
else if (preGlyph.streamType === "\b") {
|
|
1223
|
-
const drawing = (_b = docDataModel.getSnapshot().drawings) == null ? void 0 : _b[(
|
|
2285
|
+
const drawing = (_b = docDataModel.getSnapshot().drawings) == null ? void 0 : _b[(_a11 = preGlyph.drawingId) != null ? _a11 : ""];
|
|
1224
2286
|
if (drawing == null)
|
|
1225
2287
|
return !0;
|
|
1226
2288
|
if (drawing.layoutType === PositionedObjectLayoutType.INLINE) {
|
|
@@ -1277,13 +2339,25 @@ const DeleteCustomBlockCommand = {
|
|
|
1277
2339
|
}, DeleteRightCommand = {
|
|
1278
2340
|
id: "doc.command.delete-right",
|
|
1279
2341
|
type: CommandType.COMMAND,
|
|
1280
|
-
// eslint-disable-next-line max-lines-per-function
|
|
2342
|
+
// eslint-disable-next-line max-lines-per-function, complexity
|
|
1281
2343
|
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
1282
|
-
var
|
|
2344
|
+
var _a11, _b;
|
|
1283
2345
|
const textSelectionManagerService = accessor.get(TextSelectionManagerService), docDataModel = accessor.get(IUniverInstanceService).getCurrentUniverDocInstance();
|
|
1284
2346
|
if (!docDataModel)
|
|
1285
2347
|
return !1;
|
|
1286
|
-
const docSkeletonManagerService = getCommandSkeleton(accessor, docDataModel.getUnitId()), commandService = accessor.get(ICommandService), activeRange = textSelectionManagerService.
|
|
2348
|
+
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();
|
|
2349
|
+
if (rectRanges != null && rectRanges.length) {
|
|
2350
|
+
const cursor = getCursorWhenDelete(ranges, rectRanges), segmentId2 = rectRanges[0].segmentId, textRanges = [
|
|
2351
|
+
{
|
|
2352
|
+
startOffset: cursor,
|
|
2353
|
+
endOffset: cursor
|
|
2354
|
+
}
|
|
2355
|
+
];
|
|
2356
|
+
return commandService.executeCommand(CutContentCommand.id, {
|
|
2357
|
+
segmentId: segmentId2,
|
|
2358
|
+
textRanges
|
|
2359
|
+
});
|
|
2360
|
+
}
|
|
1287
2361
|
if (activeRange == null || skeleton == null || ranges == null)
|
|
1288
2362
|
return !1;
|
|
1289
2363
|
const { segmentId, style, segmentPage } = activeRange, body = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
@@ -1295,13 +2369,15 @@ const DeleteCustomBlockCommand = {
|
|
|
1295
2369
|
let result = !1;
|
|
1296
2370
|
if (collapsed === !0) {
|
|
1297
2371
|
const needDeleteGlyph = skeleton.findNodeByCharIndex(startOffset, segmentId, segmentPage), nextGlyph = skeleton.findNodeByCharIndex(startOffset + 1);
|
|
2372
|
+
if (needDeleteGlyph.streamType === DataStreamTreeTokenType.PARAGRAPH && (nextGlyph == null ? void 0 : nextGlyph.streamType) === DataStreamTreeTokenType.SECTION_BREAK)
|
|
2373
|
+
return !1;
|
|
1298
2374
|
if (needDeleteGlyph.content === "\r")
|
|
1299
2375
|
result = await commandService.executeCommand(MergeTwoParagraphCommand.id, {
|
|
1300
2376
|
direction: DeleteDirection.RIGHT,
|
|
1301
2377
|
range: activeRange
|
|
1302
2378
|
});
|
|
1303
2379
|
else if (needDeleteGlyph.streamType === "\b") {
|
|
1304
|
-
const drawing = (_b = docDataModel.getSnapshot().drawings) == null ? void 0 : _b[(
|
|
2380
|
+
const drawing = (_b = docDataModel.getSnapshot().drawings) == null ? void 0 : _b[(_a11 = needDeleteGlyph.drawingId) != null ? _a11 : ""];
|
|
1305
2381
|
if (drawing == null)
|
|
1306
2382
|
return !0;
|
|
1307
2383
|
if (drawing.layoutType === PositionedObjectLayoutType.INLINE) {
|
|
@@ -1476,11 +2552,8 @@ const IMEInputCommand = {
|
|
|
1476
2552
|
return imeInputManagerService.pushUndoRedoMutationParams(result, doMutation.params), !!result;
|
|
1477
2553
|
}, "handler")
|
|
1478
2554
|
};
|
|
1479
|
-
function handleInlineFormat(preCommandId, params,
|
|
1480
|
-
|
|
1481
|
-
const { segmentId } = (_a10 = textSelectionManagerService.getActiveRange()) != null ? _a10 : {};
|
|
1482
|
-
return segmentId == null ? !1 : commandService.executeCommand(SetInlineFormatCommand.id, {
|
|
1483
|
-
segmentId,
|
|
2555
|
+
function handleInlineFormat(preCommandId, params, commandService) {
|
|
2556
|
+
return commandService.executeCommand(SetInlineFormatCommand.id, {
|
|
1484
2557
|
preCommandId,
|
|
1485
2558
|
...params != null ? params : {}
|
|
1486
2559
|
});
|
|
@@ -1490,11 +2563,10 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1490
2563
|
id: SetInlineFormatBoldCommandId,
|
|
1491
2564
|
type: CommandType.COMMAND,
|
|
1492
2565
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1493
|
-
const commandService = accessor.get(ICommandService)
|
|
2566
|
+
const commandService = accessor.get(ICommandService);
|
|
1494
2567
|
return handleInlineFormat(
|
|
1495
2568
|
SetInlineFormatBoldCommandId,
|
|
1496
2569
|
params,
|
|
1497
|
-
textSelectionManagerService,
|
|
1498
2570
|
commandService
|
|
1499
2571
|
);
|
|
1500
2572
|
}, "handler")
|
|
@@ -1502,11 +2574,10 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1502
2574
|
id: SetInlineFormatItalicCommandId,
|
|
1503
2575
|
type: CommandType.COMMAND,
|
|
1504
2576
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1505
|
-
const commandService = accessor.get(ICommandService)
|
|
2577
|
+
const commandService = accessor.get(ICommandService);
|
|
1506
2578
|
return handleInlineFormat(
|
|
1507
2579
|
SetInlineFormatItalicCommandId,
|
|
1508
2580
|
params,
|
|
1509
|
-
textSelectionManagerService,
|
|
1510
2581
|
commandService
|
|
1511
2582
|
);
|
|
1512
2583
|
}, "handler")
|
|
@@ -1514,11 +2585,10 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1514
2585
|
id: SetInlineFormatUnderlineCommandId,
|
|
1515
2586
|
type: CommandType.COMMAND,
|
|
1516
2587
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1517
|
-
const commandService = accessor.get(ICommandService)
|
|
2588
|
+
const commandService = accessor.get(ICommandService);
|
|
1518
2589
|
return handleInlineFormat(
|
|
1519
2590
|
SetInlineFormatUnderlineCommandId,
|
|
1520
2591
|
params,
|
|
1521
|
-
textSelectionManagerService,
|
|
1522
2592
|
commandService
|
|
1523
2593
|
);
|
|
1524
2594
|
}, "handler")
|
|
@@ -1526,11 +2596,10 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1526
2596
|
id: SetInlineFormatStrikethroughCommandId,
|
|
1527
2597
|
type: CommandType.COMMAND,
|
|
1528
2598
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1529
|
-
const commandService = accessor.get(ICommandService)
|
|
2599
|
+
const commandService = accessor.get(ICommandService);
|
|
1530
2600
|
return handleInlineFormat(
|
|
1531
2601
|
SetInlineFormatStrikethroughCommandId,
|
|
1532
2602
|
params,
|
|
1533
|
-
textSelectionManagerService,
|
|
1534
2603
|
commandService
|
|
1535
2604
|
);
|
|
1536
2605
|
}, "handler")
|
|
@@ -1538,11 +2607,10 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1538
2607
|
id: SetInlineFormatSubscriptCommandId,
|
|
1539
2608
|
type: CommandType.COMMAND,
|
|
1540
2609
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1541
|
-
const commandService = accessor.get(ICommandService)
|
|
2610
|
+
const commandService = accessor.get(ICommandService);
|
|
1542
2611
|
return handleInlineFormat(
|
|
1543
2612
|
SetInlineFormatSubscriptCommandId,
|
|
1544
2613
|
params,
|
|
1545
|
-
textSelectionManagerService,
|
|
1546
2614
|
commandService
|
|
1547
2615
|
);
|
|
1548
2616
|
}, "handler")
|
|
@@ -1550,11 +2618,10 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1550
2618
|
id: SetInlineFormatSuperscriptCommandId,
|
|
1551
2619
|
type: CommandType.COMMAND,
|
|
1552
2620
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1553
|
-
const commandService = accessor.get(ICommandService)
|
|
2621
|
+
const commandService = accessor.get(ICommandService);
|
|
1554
2622
|
return handleInlineFormat(
|
|
1555
2623
|
SetInlineFormatSuperscriptCommandId,
|
|
1556
2624
|
params,
|
|
1557
|
-
textSelectionManagerService,
|
|
1558
2625
|
commandService
|
|
1559
2626
|
);
|
|
1560
2627
|
}, "handler")
|
|
@@ -1562,11 +2629,10 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1562
2629
|
id: SetInlineFormatFontSizeCommandId,
|
|
1563
2630
|
type: CommandType.COMMAND,
|
|
1564
2631
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1565
|
-
const commandService = accessor.get(ICommandService)
|
|
2632
|
+
const commandService = accessor.get(ICommandService);
|
|
1566
2633
|
return handleInlineFormat(
|
|
1567
2634
|
SetInlineFormatFontSizeCommandId,
|
|
1568
2635
|
params,
|
|
1569
|
-
textSelectionManagerService,
|
|
1570
2636
|
commandService
|
|
1571
2637
|
);
|
|
1572
2638
|
}, "handler")
|
|
@@ -1574,11 +2640,10 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1574
2640
|
id: SetInlineFormatFontFamilyCommandId,
|
|
1575
2641
|
type: CommandType.COMMAND,
|
|
1576
2642
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1577
|
-
const commandService = accessor.get(ICommandService)
|
|
2643
|
+
const commandService = accessor.get(ICommandService);
|
|
1578
2644
|
return handleInlineFormat(
|
|
1579
2645
|
SetInlineFormatFontFamilyCommandId,
|
|
1580
2646
|
params,
|
|
1581
|
-
textSelectionManagerService,
|
|
1582
2647
|
commandService
|
|
1583
2648
|
);
|
|
1584
2649
|
}, "handler")
|
|
@@ -1586,11 +2651,10 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1586
2651
|
id: SetInlineFormatTextColorCommandId,
|
|
1587
2652
|
type: CommandType.COMMAND,
|
|
1588
2653
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1589
|
-
const commandService = accessor.get(ICommandService)
|
|
2654
|
+
const commandService = accessor.get(ICommandService);
|
|
1590
2655
|
return handleInlineFormat(
|
|
1591
2656
|
SetInlineFormatTextColorCommandId,
|
|
1592
2657
|
params,
|
|
1593
|
-
textSelectionManagerService,
|
|
1594
2658
|
commandService
|
|
1595
2659
|
);
|
|
1596
2660
|
}, "handler")
|
|
@@ -1598,11 +2662,10 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1598
2662
|
id: SetInlineFormatTextBackgroundColorCommandId,
|
|
1599
2663
|
type: CommandType.COMMAND,
|
|
1600
2664
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1601
|
-
const commandService = accessor.get(ICommandService)
|
|
2665
|
+
const commandService = accessor.get(ICommandService);
|
|
1602
2666
|
return handleInlineFormat(
|
|
1603
2667
|
SetInlineFormatTextBackgroundColorCommandId,
|
|
1604
2668
|
params,
|
|
1605
|
-
textSelectionManagerService,
|
|
1606
2669
|
commandService
|
|
1607
2670
|
);
|
|
1608
2671
|
}, "handler")
|
|
@@ -1610,11 +2673,10 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1610
2673
|
id: ResetInlineFormatTextBackgroundColorCommandId,
|
|
1611
2674
|
type: CommandType.COMMAND,
|
|
1612
2675
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1613
|
-
const commandService = accessor.get(ICommandService)
|
|
2676
|
+
const commandService = accessor.get(ICommandService);
|
|
1614
2677
|
return handleInlineFormat(
|
|
1615
2678
|
ResetInlineFormatTextBackgroundColorCommandId,
|
|
1616
2679
|
params,
|
|
1617
|
-
textSelectionManagerService,
|
|
1618
2680
|
commandService
|
|
1619
2681
|
);
|
|
1620
2682
|
}, "handler")
|
|
@@ -1635,10 +2697,10 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1635
2697
|
type: CommandType.COMMAND,
|
|
1636
2698
|
// eslint-disable-next-line max-lines-per-function
|
|
1637
2699
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1638
|
-
const {
|
|
1639
|
-
if (
|
|
2700
|
+
const { value, preCommandId } = params, commandService = accessor.get(ICommandService), textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), docRanges = textSelectionManagerService.getDocRanges();
|
|
2701
|
+
if (docRanges.length === 0)
|
|
1640
2702
|
return !1;
|
|
1641
|
-
const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
|
|
2703
|
+
const segmentId = docRanges[0].segmentId, docDataModel = univerInstanceService.getCurrentUniverDocInstance();
|
|
1642
2704
|
if (docDataModel == null)
|
|
1643
2705
|
return !1;
|
|
1644
2706
|
const unitId = docDataModel.getUnitId();
|
|
@@ -1653,7 +2715,7 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1653
2715
|
formatValue = getReverseFormatValueInSelection(
|
|
1654
2716
|
docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody().textRuns,
|
|
1655
2717
|
preCommandId,
|
|
1656
|
-
|
|
2718
|
+
docRanges
|
|
1657
2719
|
);
|
|
1658
2720
|
break;
|
|
1659
2721
|
}
|
|
@@ -1683,12 +2745,15 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1683
2745
|
params: {
|
|
1684
2746
|
unitId,
|
|
1685
2747
|
actions: [],
|
|
1686
|
-
textRanges:
|
|
2748
|
+
textRanges: docRanges.map(serializeDocRange)
|
|
1687
2749
|
}
|
|
1688
2750
|
}, textX = new TextX(), jsonX = JSONX.getInstance(), memoryCursor = new MemoryCursor();
|
|
1689
2751
|
memoryCursor.reset();
|
|
1690
|
-
for (const
|
|
1691
|
-
const { startOffset, endOffset } =
|
|
2752
|
+
for (const range of docRanges) {
|
|
2753
|
+
const { startOffset, endOffset } = range;
|
|
2754
|
+
if (startOffset == null || endOffset == null)
|
|
2755
|
+
continue;
|
|
2756
|
+
const body = {
|
|
1692
2757
|
dataStream: "",
|
|
1693
2758
|
textRuns: [
|
|
1694
2759
|
{
|
|
@@ -1719,11 +2784,11 @@ function isTextDecoration(value) {
|
|
|
1719
2784
|
return value !== null && typeof value == "object";
|
|
1720
2785
|
}
|
|
1721
2786
|
__name(isTextDecoration, "isTextDecoration");
|
|
1722
|
-
function getReverseFormatValueInSelection(textRuns, preCommandId,
|
|
2787
|
+
function getReverseFormatValueInSelection(textRuns, preCommandId, docRanges) {
|
|
1723
2788
|
let ti = 0, si = 0;
|
|
1724
2789
|
const key = COMMAND_ID_TO_FORMAT_KEY_MAP[preCommandId];
|
|
1725
|
-
for (; ti !== textRuns.length && si !==
|
|
1726
|
-
const { startOffset, endOffset } =
|
|
2790
|
+
for (; ti !== textRuns.length && si !== docRanges.length; ) {
|
|
2791
|
+
const { startOffset, endOffset } = docRanges[si], { st, ed, ts } = textRuns[ti];
|
|
1727
2792
|
if (endOffset <= st)
|
|
1728
2793
|
si++;
|
|
1729
2794
|
else if (ed <= startOffset)
|
|
@@ -1747,124 +2812,11 @@ function getReverseFormatValueInSelection(textRuns, preCommandId, selections) {
|
|
|
1747
2812
|
} : preCommandId === SetInlineFormatSubscriptCommand.id ? BaselineOffset.SUBSCRIPT : BaselineOffset.SUPERSCRIPT;
|
|
1748
2813
|
}
|
|
1749
2814
|
__name(getReverseFormatValueInSelection, "getReverseFormatValueInSelection");
|
|
1750
|
-
const ListOperationCommand = {
|
|
1751
|
-
id: "doc.command.list-operation",
|
|
1752
|
-
type: CommandType.COMMAND,
|
|
1753
|
-
// eslint-disable-next-line max-lines-per-function
|
|
1754
|
-
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
1755
|
-
var _a10, _b, _c, _d, _e, _f;
|
|
1756
|
-
const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), { listType } = params, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), activeRange = textSelectionManagerService.getActiveRange();
|
|
1757
|
-
if (docDataModel == null || activeRange == null)
|
|
1758
|
-
return !1;
|
|
1759
|
-
const { segmentId } = activeRange, selections = (_a10 = textSelectionManagerService.getCurrentSelections()) != null ? _a10 : [], paragraphs = (_b = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _b.paragraphs, serializedSelections = selections.map(serializeTextRange);
|
|
1760
|
-
if (paragraphs == null)
|
|
1761
|
-
return !1;
|
|
1762
|
-
const sectionBreaks = (_d = (_c = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _c.sectionBreaks) != null ? _d : [], currentParagraphs = getParagraphsInRange(activeRange, paragraphs), unitId = docDataModel.getUnitId(), isAlreadyList = currentParagraphs.every((paragraph) => {
|
|
1763
|
-
var _a11;
|
|
1764
|
-
return ((_a11 = paragraph.bullet) == null ? void 0 : _a11.listType) === listType;
|
|
1765
|
-
});
|
|
1766
|
-
let listId = Tools.generateRandomId(6);
|
|
1767
|
-
if (currentParagraphs.length === 1) {
|
|
1768
|
-
const curIndex = paragraphs.indexOf(currentParagraphs[0]), prevParagraph = paragraphs[curIndex - 1], nextParagraph = paragraphs[curIndex + 1];
|
|
1769
|
-
prevParagraph && prevParagraph.bullet && prevParagraph.bullet.listType === listType ? listId = prevParagraph.bullet.listId : nextParagraph && nextParagraph.bullet && nextParagraph.bullet.listType === listType && (listId = nextParagraph.bullet.listId);
|
|
1770
|
-
}
|
|
1771
|
-
const doMutation = {
|
|
1772
|
-
id: RichTextEditingMutation.id,
|
|
1773
|
-
params: {
|
|
1774
|
-
unitId,
|
|
1775
|
-
actions: [],
|
|
1776
|
-
textRanges: serializedSelections
|
|
1777
|
-
}
|
|
1778
|
-
}, memoryCursor = new MemoryCursor();
|
|
1779
|
-
memoryCursor.reset();
|
|
1780
|
-
const textX = new TextX(), jsonX = JSONX.getInstance(), customLists = (_e = docDataModel.getSnapshot().lists) != null ? _e : {}, lists = {
|
|
1781
|
-
...PRESET_LIST_TYPE,
|
|
1782
|
-
...customLists
|
|
1783
|
-
}, { defaultTabStop = 36 } = docDataModel.getSnapshot().documentStyle;
|
|
1784
|
-
for (const paragraph of currentParagraphs) {
|
|
1785
|
-
const { startIndex, paragraphStyle = {} } = 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);
|
|
1786
|
-
textX.push({
|
|
1787
|
-
t: TextXActionType.RETAIN,
|
|
1788
|
-
len: startIndex - memoryCursor.cursor,
|
|
1789
|
-
segmentId
|
|
1790
|
-
}), textX.push({
|
|
1791
|
-
t: TextXActionType.RETAIN,
|
|
1792
|
-
len: 1,
|
|
1793
|
-
body: {
|
|
1794
|
-
dataStream: "",
|
|
1795
|
-
paragraphs: [
|
|
1796
|
-
isAlreadyList ? {
|
|
1797
|
-
paragraphStyle: {
|
|
1798
|
-
...paragraphStyle,
|
|
1799
|
-
hanging: void 0,
|
|
1800
|
-
indentStart: indentStart ? { v: Math.max(0, getNumberUnitValue(indentStart, charSpaceApply) + getNumberUnitValue(listHanging, charSpaceApply) - getNumberUnitValue(listIndentStart, charSpaceApply)) } : void 0
|
|
1801
|
-
},
|
|
1802
|
-
startIndex: 0
|
|
1803
|
-
} : {
|
|
1804
|
-
startIndex: 0,
|
|
1805
|
-
paragraphStyle: {
|
|
1806
|
-
...paragraphStyle,
|
|
1807
|
-
indentFirstLine: void 0,
|
|
1808
|
-
hanging: listHanging,
|
|
1809
|
-
indentStart: { v: getNumberUnitValue(listIndentStart, charSpaceApply) - getNumberUnitValue(listHanging, charSpaceApply) + getNumberUnitValue(indentFirstLine, charSpaceApply) + getNumberUnitValue(indentStart, charSpaceApply) }
|
|
1810
|
-
},
|
|
1811
|
-
bullet: {
|
|
1812
|
-
...(_f = paragraph.bullet) != null ? _f : {
|
|
1813
|
-
nestingLevel: 0,
|
|
1814
|
-
textStyle: {
|
|
1815
|
-
fs: 20
|
|
1816
|
-
}
|
|
1817
|
-
},
|
|
1818
|
-
listType,
|
|
1819
|
-
listId
|
|
1820
|
-
}
|
|
1821
|
-
}
|
|
1822
|
-
]
|
|
1823
|
-
},
|
|
1824
|
-
segmentId,
|
|
1825
|
-
coverType: UpdateDocsAttributeType.REPLACE
|
|
1826
|
-
}), memoryCursor.moveCursorTo(startIndex + 1);
|
|
1827
|
-
}
|
|
1828
|
-
const path = getRichTextEditPath(docDataModel, segmentId);
|
|
1829
|
-
return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
1830
|
-
}, "handler")
|
|
1831
|
-
}, BulletListCommand = {
|
|
1832
|
-
id: "doc.command.bullet-list",
|
|
1833
|
-
type: CommandType.COMMAND,
|
|
1834
|
-
handler: /* @__PURE__ */ __name((accessor) => accessor.get(ICommandService).syncExecuteCommand(ListOperationCommand.id, {
|
|
1835
|
-
listType: PresetListType.BULLET_LIST
|
|
1836
|
-
}), "handler")
|
|
1837
|
-
}, OrderListCommand = {
|
|
1838
|
-
id: "doc.command.order-list",
|
|
1839
|
-
type: CommandType.COMMAND,
|
|
1840
|
-
handler: /* @__PURE__ */ __name((accessor) => accessor.get(ICommandService).syncExecuteCommand(ListOperationCommand.id, {
|
|
1841
|
-
listType: PresetListType.ORDER_LIST
|
|
1842
|
-
}), "handler")
|
|
1843
|
-
};
|
|
1844
|
-
function getParagraphsInRange(activeRange, paragraphs) {
|
|
1845
|
-
const { startOffset, endOffset } = activeRange, results = [];
|
|
1846
|
-
let start = -1;
|
|
1847
|
-
for (const paragraph of paragraphs) {
|
|
1848
|
-
const { startIndex } = paragraph;
|
|
1849
|
-
(startOffset > start && startOffset <= startIndex || endOffset > start && endOffset <= startIndex || startIndex >= startOffset && startIndex <= endOffset) && results.push(paragraph), start = startIndex;
|
|
1850
|
-
}
|
|
1851
|
-
return results;
|
|
1852
|
-
}
|
|
1853
|
-
__name(getParagraphsInRange, "getParagraphsInRange");
|
|
1854
|
-
function findNearestSectionBreak(currentIndex, sectionBreaks) {
|
|
1855
|
-
const sortedSectionBreaks = sectionBreaks.sort(sortRulesFactory("startIndex"));
|
|
1856
|
-
for (let i = 0; i < sortedSectionBreaks.length; i++) {
|
|
1857
|
-
const sectionBreak = sectionBreaks[i];
|
|
1858
|
-
if (sectionBreak.startIndex >= currentIndex)
|
|
1859
|
-
return sectionBreak;
|
|
1860
|
-
}
|
|
1861
|
-
}
|
|
1862
|
-
__name(findNearestSectionBreak, "findNearestSectionBreak");
|
|
1863
2815
|
const ReplaceContentCommand = {
|
|
1864
2816
|
id: "doc.command-replace-content",
|
|
1865
2817
|
type: CommandType.COMMAND,
|
|
1866
2818
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1867
|
-
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.
|
|
2819
|
+
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();
|
|
1868
2820
|
if (docDataModel == null || prevBody == null || !Array.isArray(selections) || selections.length === 0)
|
|
1869
2821
|
return !1;
|
|
1870
2822
|
const doMutation = getMutationParams(unitId, segmentId, docDataModel, prevBody, body);
|
|
@@ -1932,9 +2884,9 @@ const SetDocZoomRatioUndoMutationFactory = /* @__PURE__ */ __name((accessor, par
|
|
|
1932
2884
|
type: CommandType.COMMAND,
|
|
1933
2885
|
id: "doc.command.set-zoom-ratio",
|
|
1934
2886
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1935
|
-
var
|
|
2887
|
+
var _a11, _b, _c;
|
|
1936
2888
|
const commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), univerInstanceService = accessor.get(IUniverInstanceService);
|
|
1937
|
-
let documentId = (
|
|
2889
|
+
let documentId = (_a11 = univerInstanceService.getCurrentUniverDocInstance()) == null ? void 0 : _a11.getUnitId();
|
|
1938
2890
|
if (!documentId) return !1;
|
|
1939
2891
|
let zoomRatio = 1;
|
|
1940
2892
|
if (params && (documentId = (_b = params.documentId) != null ? _b : documentId, zoomRatio = (_c = params.zoomRatio) != null ? _c : zoomRatio), !univerInstanceService.getUniverDocInstance(documentId)) return !1;
|
|
@@ -1960,7 +2912,7 @@ const SetDocZoomRatioUndoMutationFactory = /* @__PURE__ */ __name((accessor, par
|
|
|
1960
2912
|
id: "doc.operation.select-all",
|
|
1961
2913
|
type: CommandType.COMMAND,
|
|
1962
2914
|
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
1963
|
-
const univerInstanceService = accessor.get(IUniverInstanceService), textSelectionManagerService = accessor.get(TextSelectionManagerService), docDataModel = univerInstanceService.getCurrentUniverDocInstance(), activeTextRange = textSelectionManagerService.
|
|
2915
|
+
const univerInstanceService = accessor.get(IUniverInstanceService), textSelectionManagerService = accessor.get(TextSelectionManagerService), docDataModel = univerInstanceService.getCurrentUniverDocInstance(), activeTextRange = textSelectionManagerService.getActiveTextRangeWithStyle();
|
|
1964
2916
|
if (docDataModel == null || activeTextRange == null)
|
|
1965
2917
|
return !1;
|
|
1966
2918
|
const { segmentId } = activeTextRange, prevBody = docDataModel.getSelfOrHeaderFooterModel(segmentId).getSnapshot().body;
|
|
@@ -1975,24 +2927,24 @@ const SetDocZoomRatioUndoMutationFactory = /* @__PURE__ */ __name((accessor, par
|
|
|
1975
2927
|
return textSelectionManagerService.replaceTextRanges(textRanges, !1), !0;
|
|
1976
2928
|
}, "handler")
|
|
1977
2929
|
};
|
|
1978
|
-
var __defProp$
|
|
1979
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$
|
|
2930
|
+
var __defProp$6 = Object.defineProperty, __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor, __decorateClass$6 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
2931
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1980
2932
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
1981
|
-
return kind && result && __defProp$
|
|
1982
|
-
}, "__decorateClass$
|
|
2933
|
+
return kind && result && __defProp$6(target, key, result), result;
|
|
2934
|
+
}, "__decorateClass$6"), __decorateParam$6 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$6"), _a4;
|
|
1983
2935
|
let IMEInputController = (_a4 = class extends Disposable {
|
|
1984
|
-
constructor(_univerInstanceService, _renderManagerSrv, _textSelectionRenderManager, _imeInputManagerService, _commandService) {
|
|
2936
|
+
constructor(_univerInstanceService, _renderManagerSrv, _textSelectionRenderManager, _textSelectionManagerService, _imeInputManagerService, _commandService) {
|
|
1985
2937
|
super();
|
|
1986
2938
|
__publicField(this, "_previousIMEContent", "");
|
|
1987
2939
|
__publicField(this, "_isCompositionStart", !0);
|
|
1988
2940
|
__publicField(this, "_onStartSubscription");
|
|
1989
2941
|
__publicField(this, "_onUpdateSubscription");
|
|
1990
2942
|
__publicField(this, "_onEndSubscription");
|
|
1991
|
-
this._univerInstanceService = _univerInstanceService, this._renderManagerSrv = _renderManagerSrv, this._textSelectionRenderManager = _textSelectionRenderManager, this._imeInputManagerService = _imeInputManagerService, this._commandService = _commandService, this._initialize();
|
|
2943
|
+
this._univerInstanceService = _univerInstanceService, this._renderManagerSrv = _renderManagerSrv, this._textSelectionRenderManager = _textSelectionRenderManager, this._textSelectionManagerService = _textSelectionManagerService, this._imeInputManagerService = _imeInputManagerService, this._commandService = _commandService, this._initialize();
|
|
1992
2944
|
}
|
|
1993
2945
|
dispose() {
|
|
1994
|
-
var
|
|
1995
|
-
(
|
|
2946
|
+
var _a11, _b, _c;
|
|
2947
|
+
(_a11 = this._onStartSubscription) == null || _a11.unsubscribe(), (_b = this._onUpdateSubscription) == null || _b.unsubscribe(), (_c = this._onEndSubscription) == null || _c.unsubscribe();
|
|
1996
2948
|
}
|
|
1997
2949
|
_initialize() {
|
|
1998
2950
|
this._initialOnCompositionstart(), this._initialOnCompositionUpdate(), this._initialOnCompositionend();
|
|
@@ -2017,13 +2969,13 @@ let IMEInputController = (_a4 = class extends Disposable {
|
|
|
2017
2969
|
});
|
|
2018
2970
|
}
|
|
2019
2971
|
async _updateContent(config, isUpdate) {
|
|
2020
|
-
var
|
|
2972
|
+
var _a11;
|
|
2021
2973
|
if (config == null)
|
|
2022
2974
|
return;
|
|
2023
2975
|
const documentModel = this._univerInstanceService.getCurrentUniverDocInstance();
|
|
2024
2976
|
if (!documentModel)
|
|
2025
2977
|
return;
|
|
2026
|
-
const skeleton = (
|
|
2978
|
+
const skeleton = (_a11 = this._renderManagerSrv.getRenderById(documentModel.getUnitId())) == null ? void 0 : _a11.with(DocSkeletonManagerService).getSkeleton(), { event, activeRange } = config;
|
|
2027
2979
|
if (skeleton == null || activeRange == null)
|
|
2028
2980
|
return;
|
|
2029
2981
|
const content = event.data;
|
|
@@ -2039,19 +2991,98 @@ let IMEInputController = (_a4 = class extends Disposable {
|
|
|
2039
2991
|
this._previousIMEContent = "", this._isCompositionStart = !0, this._imeInputManagerService.clearUndoRedoMutationParamsCache(), this._imeInputManagerService.setActiveRange(null);
|
|
2040
2992
|
}
|
|
2041
2993
|
}, __name(_a4, "IMEInputController"), _a4);
|
|
2042
|
-
IMEInputController = __decorateClass$
|
|
2994
|
+
IMEInputController = __decorateClass$6([
|
|
2043
2995
|
OnLifecycle(LifecycleStages.Rendered, IMEInputController),
|
|
2044
|
-
__decorateParam$
|
|
2045
|
-
__decorateParam$
|
|
2046
|
-
__decorateParam$
|
|
2047
|
-
__decorateParam$
|
|
2048
|
-
__decorateParam$
|
|
2996
|
+
__decorateParam$6(0, IUniverInstanceService),
|
|
2997
|
+
__decorateParam$6(1, IRenderManagerService),
|
|
2998
|
+
__decorateParam$6(2, ITextSelectionRenderManager),
|
|
2999
|
+
__decorateParam$6(3, Inject(TextSelectionManagerService)),
|
|
3000
|
+
__decorateParam$6(4, Inject(IMEInputManagerService)),
|
|
3001
|
+
__decorateParam$6(5, ICommandService)
|
|
2049
3002
|
], IMEInputController);
|
|
2050
|
-
|
|
2051
|
-
|
|
3003
|
+
function firstLineInTable(table) {
|
|
3004
|
+
return table.rows[0].cells[0].sections[0].columns[0].lines[0];
|
|
3005
|
+
}
|
|
3006
|
+
__name(firstLineInTable, "firstLineInTable");
|
|
3007
|
+
function lastLineInTable(table) {
|
|
3008
|
+
const lastRow = table.rows[table.rows.length - 1], lastCell = lastRow.cells[lastRow.cells.length - 1];
|
|
3009
|
+
return getLastLine(lastCell);
|
|
3010
|
+
}
|
|
3011
|
+
__name(lastLineInTable, "lastLineInTable");
|
|
3012
|
+
function findTableAfterLine(line, page) {
|
|
3013
|
+
const { ed } = line, { skeTables } = page;
|
|
3014
|
+
let table = null;
|
|
3015
|
+
for (const t of skeTables.values())
|
|
3016
|
+
if (t.st === ed + 1) {
|
|
3017
|
+
table = t;
|
|
3018
|
+
break;
|
|
3019
|
+
}
|
|
3020
|
+
return table;
|
|
3021
|
+
}
|
|
3022
|
+
__name(findTableAfterLine, "findTableAfterLine");
|
|
3023
|
+
function findLineBeforeAndAfterTable(table) {
|
|
3024
|
+
const tablePage = table == null ? void 0 : table.parent;
|
|
3025
|
+
let lineBeforeTable = null, lineAfterTable = null;
|
|
3026
|
+
if (table == null || tablePage == null)
|
|
3027
|
+
return {
|
|
3028
|
+
lineBeforeTable,
|
|
3029
|
+
lineAfterTable
|
|
3030
|
+
};
|
|
3031
|
+
const { st, ed } = table, pages = tablePage.type === DocumentSkeletonPageType.CELL ? [tablePage] : tablePage.parent.pages;
|
|
3032
|
+
return lineIterator(pages, (l) => {
|
|
3033
|
+
l.st === ed + 1 ? lineAfterTable = l : l.ed === st - 1 && (lineBeforeTable = l);
|
|
3034
|
+
}), {
|
|
3035
|
+
lineBeforeTable,
|
|
3036
|
+
lineAfterTable
|
|
3037
|
+
};
|
|
3038
|
+
}
|
|
3039
|
+
__name(findLineBeforeAndAfterTable, "findLineBeforeAndAfterTable");
|
|
3040
|
+
function findBellowCell(cell) {
|
|
3041
|
+
const row = cell.parent, table = row == null ? void 0 : row.parent;
|
|
3042
|
+
if (row == null || table == null)
|
|
3043
|
+
return;
|
|
3044
|
+
const bellowRow = table.rows[table.rows.indexOf(row) + 1];
|
|
3045
|
+
if (bellowRow == null)
|
|
3046
|
+
return;
|
|
3047
|
+
const col = row.cells.indexOf(cell);
|
|
3048
|
+
return bellowRow.cells[col];
|
|
3049
|
+
}
|
|
3050
|
+
__name(findBellowCell, "findBellowCell");
|
|
3051
|
+
function findAboveCell(cell) {
|
|
3052
|
+
const row = cell.parent, table = row == null ? void 0 : row.parent;
|
|
3053
|
+
if (row == null || table == null)
|
|
3054
|
+
return;
|
|
3055
|
+
const aboveRow = table.rows[table.rows.indexOf(row) - 1];
|
|
3056
|
+
if (aboveRow == null)
|
|
3057
|
+
return;
|
|
3058
|
+
const col = row.cells.indexOf(cell);
|
|
3059
|
+
return aboveRow.cells[col];
|
|
3060
|
+
}
|
|
3061
|
+
__name(findAboveCell, "findAboveCell");
|
|
3062
|
+
function findTableBeforeLine(line, page) {
|
|
3063
|
+
const { st } = line, { skeTables } = page;
|
|
3064
|
+
let table = null;
|
|
3065
|
+
for (const t of skeTables.values())
|
|
3066
|
+
if (t.ed === st - 1) {
|
|
3067
|
+
table = t;
|
|
3068
|
+
break;
|
|
3069
|
+
}
|
|
3070
|
+
return table;
|
|
3071
|
+
}
|
|
3072
|
+
__name(findTableBeforeLine, "findTableBeforeLine");
|
|
3073
|
+
function firstLineInCell(cell) {
|
|
3074
|
+
return cell.sections[0].columns[0].lines[0];
|
|
3075
|
+
}
|
|
3076
|
+
__name(firstLineInCell, "firstLineInCell");
|
|
3077
|
+
function lastLineInCell(cell) {
|
|
3078
|
+
return getLastLine(cell);
|
|
3079
|
+
}
|
|
3080
|
+
__name(lastLineInCell, "lastLineInCell");
|
|
3081
|
+
var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
3082
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
2052
3083
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
2053
|
-
return kind && result && __defProp$
|
|
2054
|
-
}, "__decorateClass$
|
|
3084
|
+
return kind && result && __defProp$5(target, key, result), result;
|
|
3085
|
+
}, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$5"), _a5;
|
|
2055
3086
|
let MoveCursorController = (_a5 = class extends Disposable {
|
|
2056
3087
|
constructor(_univerInstanceService, _renderManagerService, _textSelectionManagerService, _commandService) {
|
|
2057
3088
|
super();
|
|
@@ -2059,8 +3090,8 @@ let MoveCursorController = (_a5 = class extends Disposable {
|
|
|
2059
3090
|
this._univerInstanceService = _univerInstanceService, this._renderManagerService = _renderManagerService, this._textSelectionManagerService = _textSelectionManagerService, this._commandService = _commandService, this._commandExecutedListener();
|
|
2060
3091
|
}
|
|
2061
3092
|
dispose() {
|
|
2062
|
-
var
|
|
2063
|
-
super.dispose(), (
|
|
3093
|
+
var _a11;
|
|
3094
|
+
super.dispose(), (_a11 = this._onInputSubscription) == null || _a11.unsubscribe();
|
|
2064
3095
|
}
|
|
2065
3096
|
_commandExecutedListener() {
|
|
2066
3097
|
const updateCommandList = [MoveCursorOperation.id, MoveSelectionOperation.id];
|
|
@@ -2082,11 +3113,11 @@ let MoveCursorController = (_a5 = class extends Disposable {
|
|
|
2082
3113
|
}
|
|
2083
3114
|
// eslint-disable-next-line max-lines-per-function, complexity
|
|
2084
3115
|
_handleShiftMoveSelection(direction) {
|
|
2085
|
-
var
|
|
2086
|
-
const activeRange = this._textSelectionManagerService.
|
|
2087
|
-
if (
|
|
3116
|
+
var _a11, _b, _c;
|
|
3117
|
+
const activeRange = this._textSelectionManagerService.getActiveTextRangeWithStyle(), allRanges = this._textSelectionManagerService.getCurrentTextRanges(), docDataModel = this._univerInstanceService.getCurrentUniverDocInstance();
|
|
3118
|
+
if (docDataModel == null)
|
|
2088
3119
|
return;
|
|
2089
|
-
const skeleton = (
|
|
3120
|
+
const skeleton = (_a11 = this._renderManagerService.getRenderById(docDataModel.getUnitId())) == null ? void 0 : _a11.with(DocSkeletonManagerService).getSkeleton(), docObject = this._getDocObject();
|
|
2090
3121
|
if (activeRange == null || skeleton == null || docObject == null)
|
|
2091
3122
|
return;
|
|
2092
3123
|
const {
|
|
@@ -2126,7 +3157,7 @@ let MoveCursorController = (_a5 = class extends Disposable {
|
|
|
2126
3157
|
}
|
|
2127
3158
|
], !1);
|
|
2128
3159
|
} else {
|
|
2129
|
-
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);
|
|
3160
|
+
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);
|
|
2130
3161
|
if (newPos == null) {
|
|
2131
3162
|
const newFocusOffset = direction === Direction.UP ? 0 : dataStreamLength - 2;
|
|
2132
3163
|
if (newFocusOffset === focusOffset)
|
|
@@ -2155,14 +3186,17 @@ let MoveCursorController = (_a5 = class extends Disposable {
|
|
|
2155
3186
|
}
|
|
2156
3187
|
// eslint-disable-next-line max-lines-per-function, complexity
|
|
2157
3188
|
_handleMoveCursor(direction) {
|
|
2158
|
-
var
|
|
2159
|
-
const activeRange = this._textSelectionManagerService.
|
|
2160
|
-
if (
|
|
3189
|
+
var _a11, _b, _c, _d;
|
|
3190
|
+
const activeRange = this._textSelectionManagerService.getActiveTextRangeWithStyle(), allRanges = this._textSelectionManagerService.getCurrentTextRanges(), docDataModel = this._univerInstanceService.getCurrentUniverDocInstance();
|
|
3191
|
+
if (docDataModel == null)
|
|
2161
3192
|
return !1;
|
|
2162
|
-
const skeleton = (
|
|
2163
|
-
if (activeRange == null || skeleton == null || docObject == null || allRanges == null
|
|
3193
|
+
const skeleton = (_a11 = this._renderManagerService.getRenderById(docDataModel.getUnitId())) == null ? void 0 : _a11.with(DocSkeletonManagerService).getSkeleton(), docObject = this._getDocObject();
|
|
3194
|
+
if (activeRange == null || skeleton == null || docObject == null || allRanges == null)
|
|
2164
3195
|
return;
|
|
2165
|
-
const { startOffset, endOffset, style, collapsed, segmentId, startNodePosition, endNodePosition, segmentPage } = activeRange,
|
|
3196
|
+
const { startOffset, endOffset, style, collapsed, segmentId, startNodePosition, endNodePosition, segmentPage } = activeRange, body = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
3197
|
+
if (body == null)
|
|
3198
|
+
return;
|
|
3199
|
+
const dataStreamLength = (_b = body.dataStream.length) != null ? _b : Number.POSITIVE_INFINITY, customRanges = (_c = docDataModel.getCustomRanges()) != null ? _c : [];
|
|
2166
3200
|
if (direction === Direction.LEFT || direction === Direction.RIGHT) {
|
|
2167
3201
|
let cursor;
|
|
2168
3202
|
if (!activeRange.collapsed || allRanges.length > 1) {
|
|
@@ -2171,15 +3205,25 @@ let MoveCursorController = (_a5 = class extends Disposable {
|
|
|
2171
3205
|
min = Math.min(min, range.startOffset), max = Math.max(max, range.endOffset);
|
|
2172
3206
|
cursor = direction === Direction.LEFT ? min : max;
|
|
2173
3207
|
} else {
|
|
2174
|
-
const preSpan = skeleton.findNodeByCharIndex(startOffset - 1, segmentId, segmentPage), curSpan = skeleton.findNodeByCharIndex(startOffset, segmentId, segmentPage);
|
|
2175
|
-
direction === Direction.LEFT ? cursor = Math.max(0, startOffset - ((_d = preSpan == null ? void 0 : preSpan.count) != null ? _d :
|
|
3208
|
+
const preSpan = skeleton.findNodeByCharIndex(startOffset - 1, segmentId, segmentPage), curSpan = skeleton.findNodeByCharIndex(startOffset, segmentId, segmentPage), nextGlyph = skeleton.findNodeByCharIndex(startOffset + 1, segmentId, segmentPage);
|
|
3209
|
+
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));
|
|
2176
3210
|
}
|
|
2177
|
-
const skipTokens = [
|
|
3211
|
+
const skipTokens = [
|
|
3212
|
+
DataStreamTreeTokenType.CUSTOM_RANGE_START,
|
|
3213
|
+
DataStreamTreeTokenType.CUSTOM_RANGE_END,
|
|
3214
|
+
DataStreamTreeTokenType.TABLE_START,
|
|
3215
|
+
DataStreamTreeTokenType.TABLE_END,
|
|
3216
|
+
DataStreamTreeTokenType.TABLE_ROW_START,
|
|
3217
|
+
DataStreamTreeTokenType.TABLE_ROW_END,
|
|
3218
|
+
DataStreamTreeTokenType.TABLE_CELL_START,
|
|
3219
|
+
DataStreamTreeTokenType.TABLE_CELL_END,
|
|
3220
|
+
DataStreamTreeTokenType.SECTION_BREAK
|
|
3221
|
+
];
|
|
2178
3222
|
if (direction === Direction.LEFT)
|
|
2179
3223
|
for (; skipTokens.includes(body.dataStream[cursor]); )
|
|
2180
3224
|
cursor--;
|
|
2181
3225
|
else
|
|
2182
|
-
for (; skipTokens.includes(body.dataStream[cursor
|
|
3226
|
+
for (; skipTokens.includes(body.dataStream[cursor]); )
|
|
2183
3227
|
cursor++;
|
|
2184
3228
|
customRanges.filter((range) => range.wholeEntity && range.startIndex < cursor && range.endIndex >= cursor).forEach((range) => {
|
|
2185
3229
|
direction === Direction.LEFT ? cursor = Math.min(range.startIndex, cursor) : cursor = Math.max(range.endIndex + 1, cursor);
|
|
@@ -2220,10 +3264,10 @@ let MoveCursorController = (_a5 = class extends Disposable {
|
|
|
2220
3264
|
], !1);
|
|
2221
3265
|
}
|
|
2222
3266
|
}
|
|
2223
|
-
_getTopOrBottomPosition(docSkeleton, glyph, nodePosition, direction) {
|
|
3267
|
+
_getTopOrBottomPosition(docSkeleton, glyph, nodePosition, direction, skipCellContent = !1) {
|
|
2224
3268
|
if (glyph == null || nodePosition == null)
|
|
2225
3269
|
return;
|
|
2226
|
-
const offsetLeft = this._getGlyphLeftOffsetInLine(glyph), line = this._getNextOrPrevLine(glyph, direction);
|
|
3270
|
+
const offsetLeft = this._getGlyphLeftOffsetInLine(glyph), line = this._getNextOrPrevLine(glyph, direction, skipCellContent);
|
|
2227
3271
|
if (line == null)
|
|
2228
3272
|
return;
|
|
2229
3273
|
const position = this._matchPositionByLeftOffset(docSkeleton, line, offsetLeft, nodePosition);
|
|
@@ -2244,6 +3288,8 @@ let MoveCursorController = (_a5 = class extends Disposable {
|
|
|
2244
3288
|
for (const divide of line.divides) {
|
|
2245
3289
|
const divideLeft = divide.left;
|
|
2246
3290
|
for (const glyph of divide.glyphGroup) {
|
|
3291
|
+
if (glyph.streamType === DataStreamTreeTokenType.SECTION_BREAK)
|
|
3292
|
+
continue;
|
|
2247
3293
|
const { left } = glyph, leftSide = divideLeft + left, distance = Math.abs(offsetLeft - leftSide);
|
|
2248
3294
|
distance < nearestNode.distance && (nearestNode.glyph = glyph, nearestNode.distance = distance);
|
|
2249
3295
|
}
|
|
@@ -2253,41 +3299,49 @@ let MoveCursorController = (_a5 = class extends Disposable {
|
|
|
2253
3299
|
const { segmentPage } = nodePosition;
|
|
2254
3300
|
return docSkeleton.findPositionByGlyph(nearestNode.glyph, segmentPage);
|
|
2255
3301
|
}
|
|
2256
|
-
// eslint-disable-next-line max-lines-per-function
|
|
2257
|
-
_getNextOrPrevLine(glyph, direction) {
|
|
2258
|
-
var
|
|
2259
|
-
const divide = glyph.parent;
|
|
2260
|
-
if (divide == null)
|
|
2261
|
-
return;
|
|
2262
|
-
const line = divide.parent;
|
|
2263
|
-
if (line == null)
|
|
2264
|
-
return;
|
|
2265
|
-
const column = line.parent;
|
|
2266
|
-
if (column == null)
|
|
3302
|
+
// eslint-disable-next-line max-lines-per-function, complexity
|
|
3303
|
+
_getNextOrPrevLine(glyph, direction, skipCellContent = !1) {
|
|
3304
|
+
var _a11, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
3305
|
+
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;
|
|
3306
|
+
if (divide == null || line == null || column == null || section == null || page == null)
|
|
2267
3307
|
return;
|
|
2268
3308
|
const currentLineIndex = column.lines.indexOf(line);
|
|
2269
3309
|
if (currentLineIndex === -1)
|
|
2270
3310
|
return;
|
|
2271
3311
|
let newLine;
|
|
2272
|
-
if (
|
|
3312
|
+
if (page.type === DocumentSkeletonPageType.CELL && skipCellContent) {
|
|
3313
|
+
const nLine = findAboveOrBellowCellLine(page, direction);
|
|
3314
|
+
if (nLine)
|
|
3315
|
+
return nLine;
|
|
3316
|
+
}
|
|
3317
|
+
if (direction === !0) {
|
|
3318
|
+
newLine = column.lines[currentLineIndex + 1];
|
|
3319
|
+
const tableAfterLine = findTableAfterLine(line, page);
|
|
3320
|
+
if (tableAfterLine) {
|
|
3321
|
+
const firstLine = firstLineInTable(tableAfterLine);
|
|
3322
|
+
firstLine && (newLine = firstLine);
|
|
3323
|
+
}
|
|
3324
|
+
} else {
|
|
3325
|
+
newLine = column.lines[currentLineIndex - 1];
|
|
3326
|
+
const tableBeforeLine = findTableBeforeLine(line, page);
|
|
3327
|
+
if (tableBeforeLine) {
|
|
3328
|
+
const lastLine = lastLineInTable(tableBeforeLine);
|
|
3329
|
+
lastLine && (newLine = lastLine);
|
|
3330
|
+
}
|
|
3331
|
+
}
|
|
3332
|
+
if (newLine != null)
|
|
2273
3333
|
return newLine;
|
|
2274
|
-
const section = column.parent;
|
|
2275
|
-
if (section == null)
|
|
2276
|
-
return;
|
|
2277
3334
|
const currentColumnIndex = section.columns.indexOf(column);
|
|
2278
3335
|
if (currentColumnIndex === -1)
|
|
2279
3336
|
return;
|
|
2280
3337
|
if (direction === !0)
|
|
2281
|
-
newLine = (
|
|
3338
|
+
newLine = (_a11 = section.columns[currentColumnIndex + 1]) == null ? void 0 : _a11.lines[0];
|
|
2282
3339
|
else {
|
|
2283
3340
|
const prevColumnLines = (_c = (_b = section.columns) == null ? void 0 : _b[currentColumnIndex - 1]) == null ? void 0 : _c.lines;
|
|
2284
3341
|
newLine = prevColumnLines == null ? void 0 : prevColumnLines[prevColumnLines.length - 1];
|
|
2285
3342
|
}
|
|
2286
3343
|
if (newLine != null)
|
|
2287
3344
|
return newLine;
|
|
2288
|
-
const page = section.parent;
|
|
2289
|
-
if (page == null)
|
|
2290
|
-
return;
|
|
2291
3345
|
const currentSectionIndex = page.sections.indexOf(section);
|
|
2292
3346
|
if (currentSectionIndex === -1)
|
|
2293
3347
|
return;
|
|
@@ -2299,6 +3353,8 @@ let MoveCursorController = (_a5 = class extends Disposable {
|
|
|
2299
3353
|
}
|
|
2300
3354
|
if (newLine != null)
|
|
2301
3355
|
return newLine;
|
|
3356
|
+
if (page.type === DocumentSkeletonPageType.CELL)
|
|
3357
|
+
return findAboveOrBellowCellLine(page, direction);
|
|
2302
3358
|
const skeleton = page.parent;
|
|
2303
3359
|
if (skeleton == null)
|
|
2304
3360
|
return;
|
|
@@ -2317,44 +3373,155 @@ let MoveCursorController = (_a5 = class extends Disposable {
|
|
|
2317
3373
|
return newLine;
|
|
2318
3374
|
}
|
|
2319
3375
|
}
|
|
2320
|
-
_getDocObject() {
|
|
2321
|
-
return getDocObject(this._univerInstanceService, this._renderManagerService);
|
|
3376
|
+
_getDocObject() {
|
|
3377
|
+
return getDocObject(this._univerInstanceService, this._renderManagerService);
|
|
3378
|
+
}
|
|
3379
|
+
}, __name(_a5, "MoveCursorController"), _a5);
|
|
3380
|
+
MoveCursorController = __decorateClass$5([
|
|
3381
|
+
OnLifecycle(LifecycleStages.Rendered, MoveCursorController),
|
|
3382
|
+
__decorateParam$5(0, IUniverInstanceService),
|
|
3383
|
+
__decorateParam$5(1, IRenderManagerService),
|
|
3384
|
+
__decorateParam$5(2, Inject(TextSelectionManagerService)),
|
|
3385
|
+
__decorateParam$5(3, ICommandService)
|
|
3386
|
+
], MoveCursorController);
|
|
3387
|
+
function findAboveOrBellowCellLine(page, direction) {
|
|
3388
|
+
var _a11, _b;
|
|
3389
|
+
let newLine = null;
|
|
3390
|
+
if (direction === !0) {
|
|
3391
|
+
const bellowCell = findBellowCell(page);
|
|
3392
|
+
if (bellowCell)
|
|
3393
|
+
newLine = firstLineInCell(bellowCell);
|
|
3394
|
+
else {
|
|
3395
|
+
const table = (_a11 = page.parent) == null ? void 0 : _a11.parent, { lineAfterTable } = findLineBeforeAndAfterTable(table);
|
|
3396
|
+
lineAfterTable && (newLine = lineAfterTable);
|
|
3397
|
+
}
|
|
3398
|
+
} else {
|
|
3399
|
+
const aboveCell = findAboveCell(page);
|
|
3400
|
+
if (aboveCell)
|
|
3401
|
+
newLine = lastLineInCell(aboveCell);
|
|
3402
|
+
else {
|
|
3403
|
+
const table = (_b = page.parent) == null ? void 0 : _b.parent, { lineBeforeTable } = findLineBeforeAndAfterTable(table);
|
|
3404
|
+
lineBeforeTable && (newLine = lineBeforeTable);
|
|
3405
|
+
}
|
|
3406
|
+
}
|
|
3407
|
+
return newLine != null, newLine;
|
|
3408
|
+
}
|
|
3409
|
+
__name(findAboveOrBellowCellLine, "findAboveOrBellowCellLine");
|
|
3410
|
+
var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
3411
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
3412
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
3413
|
+
return kind && result && __defProp$4(target, key, result), result;
|
|
3414
|
+
}, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4");
|
|
3415
|
+
function getParagraphsInRange(activeRange, paragraphs) {
|
|
3416
|
+
var _a11, _b;
|
|
3417
|
+
const { startOffset, endOffset } = activeRange, results = [];
|
|
3418
|
+
let start = -1;
|
|
3419
|
+
for (let i = 0; i < paragraphs.length; i++) {
|
|
3420
|
+
const paragraph = paragraphs[i], prevParagraph = paragraphs[i - 1], { startIndex } = paragraph;
|
|
3421
|
+
startOffset > start && startOffset <= startIndex || endOffset > start && endOffset <= startIndex ? results.push({
|
|
3422
|
+
...paragraph,
|
|
3423
|
+
paragraphStart: ((_a11 = prevParagraph == null ? void 0 : prevParagraph.startIndex) != null ? _a11 : -1) + 1,
|
|
3424
|
+
paragraphEnd: paragraph.startIndex
|
|
3425
|
+
}) : startIndex >= startOffset && startIndex <= endOffset && results.push({
|
|
3426
|
+
...paragraph,
|
|
3427
|
+
paragraphStart: ((_b = prevParagraph == null ? void 0 : prevParagraph.startIndex) != null ? _b : -1) + 1,
|
|
3428
|
+
paragraphEnd: paragraph.startIndex
|
|
3429
|
+
}), start = startIndex;
|
|
2322
3430
|
}
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
3431
|
+
return results;
|
|
3432
|
+
}
|
|
3433
|
+
__name(getParagraphsInRange, "getParagraphsInRange");
|
|
3434
|
+
var _a6;
|
|
3435
|
+
let DocAutoFormatService = (_a6 = class extends Disposable {
|
|
3436
|
+
constructor(_univerInstanceService, _textSelectionManagerService) {
|
|
3437
|
+
super();
|
|
3438
|
+
__publicField(this, "_matches", /* @__PURE__ */ new Map());
|
|
3439
|
+
this._univerInstanceService = _univerInstanceService, this._textSelectionManagerService = _textSelectionManagerService;
|
|
3440
|
+
}
|
|
3441
|
+
registerAutoFormat(match) {
|
|
3442
|
+
const matchList = this._matches.get(match.id);
|
|
3443
|
+
return matchList ? (matchList.push(match), matchList.sort((a, b) => {
|
|
3444
|
+
var _a11, _b;
|
|
3445
|
+
return ((_a11 = b.priority) != null ? _a11 : 0) - ((_b = a.priority) != null ? _b : 0);
|
|
3446
|
+
})) : this._matches.set(match.id, [match]), toDisposable(() => {
|
|
3447
|
+
const matchList2 = this._matches.get(match.id);
|
|
3448
|
+
if (matchList2) {
|
|
3449
|
+
const index = matchList2.findIndex((i) => i === match);
|
|
3450
|
+
index >= 0 && matchList2.splice(index, 1);
|
|
3451
|
+
}
|
|
3452
|
+
});
|
|
3453
|
+
}
|
|
3454
|
+
onAutoFormat(id, params) {
|
|
3455
|
+
var _a11, _b, _c, _d, _e, _f;
|
|
3456
|
+
const autoForamts = (_a11 = this._matches.get(id)) != null ? _a11 : [], unit = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC), selection = this._textSelectionManagerService.getActiveTextRangeWithStyle();
|
|
3457
|
+
if (unit && selection) {
|
|
3458
|
+
const doc = unit.getSelfOrHeaderFooterModel(selection.segmentId), context = {
|
|
3459
|
+
unit: doc,
|
|
3460
|
+
selection,
|
|
3461
|
+
isBody: !selection.segmentId,
|
|
3462
|
+
paragraphs: getParagraphsInRange(selection, (_c = (_b = doc.getBody()) == null ? void 0 : _b.paragraphs) != null ? _c : []),
|
|
3463
|
+
customRanges: getCustomRangesIntesetsWithRange(selection, (_e = (_d = doc.getBody()) == null ? void 0 : _d.customRanges) != null ? _e : []),
|
|
3464
|
+
commandId: id,
|
|
3465
|
+
commandParams: params
|
|
3466
|
+
}, matched = autoForamts.find((i) => i.match(context));
|
|
3467
|
+
return (_f = matched == null ? void 0 : matched.getMutations(context)) != null ? _f : [];
|
|
3468
|
+
}
|
|
3469
|
+
return [];
|
|
3470
|
+
}
|
|
3471
|
+
}, __name(_a6, "DocAutoFormatService"), _a6);
|
|
3472
|
+
DocAutoFormatService = __decorateClass$4([
|
|
2326
3473
|
__decorateParam$4(0, IUniverInstanceService),
|
|
2327
|
-
__decorateParam$4(1,
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
3474
|
+
__decorateParam$4(1, Inject(TextSelectionManagerService))
|
|
3475
|
+
], DocAutoFormatService);
|
|
3476
|
+
const TabCommandId = "doc.command.tab", TabCommand = {
|
|
3477
|
+
id: TabCommandId,
|
|
3478
|
+
type: CommandType.COMMAND,
|
|
3479
|
+
async handler(accessor, params) {
|
|
3480
|
+
const mutations = accessor.get(DocAutoFormatService).onAutoFormat(TabCommand.id, params);
|
|
3481
|
+
return (await sequenceExecuteAsync(mutations, accessor.get(ICommandService))).result;
|
|
3482
|
+
}
|
|
3483
|
+
}, AfterSpaceCommandId = "doc.command.after-space", AfterSpaceCommand = {
|
|
3484
|
+
id: AfterSpaceCommandId,
|
|
3485
|
+
type: CommandType.COMMAND,
|
|
3486
|
+
async handler(accessor) {
|
|
3487
|
+
const mutations = accessor.get(DocAutoFormatService).onAutoFormat(AfterSpaceCommand.id);
|
|
3488
|
+
return (await sequenceExecuteAsync(mutations, accessor.get(ICommandService))).result;
|
|
3489
|
+
}
|
|
3490
|
+
}, EnterCommand = {
|
|
3491
|
+
id: "doc.command.enter",
|
|
3492
|
+
type: CommandType.COMMAND,
|
|
3493
|
+
async handler(accessor) {
|
|
3494
|
+
const mutations = accessor.get(DocAutoFormatService).onAutoFormat(EnterCommand.id);
|
|
3495
|
+
return (await sequenceExecuteAsync(mutations, accessor.get(ICommandService))).result;
|
|
3496
|
+
}
|
|
3497
|
+
};
|
|
2331
3498
|
var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
2332
3499
|
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
2333
3500
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
2334
3501
|
return kind && result && __defProp$3(target, key, result), result;
|
|
2335
|
-
}, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"),
|
|
2336
|
-
let NormalInputController = (
|
|
3502
|
+
}, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a7;
|
|
3503
|
+
let NormalInputController = (_a7 = class extends Disposable {
|
|
2337
3504
|
constructor(_univerInstanceService, _renderManagerService, _textSelectionRenderManager, _commandService) {
|
|
2338
3505
|
super();
|
|
2339
3506
|
__publicField(this, "_onInputSubscription");
|
|
2340
3507
|
this._univerInstanceService = _univerInstanceService, this._renderManagerService = _renderManagerService, this._textSelectionRenderManager = _textSelectionRenderManager, this._commandService = _commandService, this._init();
|
|
2341
3508
|
}
|
|
2342
3509
|
dispose() {
|
|
2343
|
-
var
|
|
2344
|
-
super.dispose(), (
|
|
3510
|
+
var _a11;
|
|
3511
|
+
super.dispose(), (_a11 = this._onInputSubscription) == null || _a11.unsubscribe();
|
|
2345
3512
|
}
|
|
2346
3513
|
_init() {
|
|
2347
3514
|
this._initialNormalInput();
|
|
2348
3515
|
}
|
|
2349
3516
|
_initialNormalInput() {
|
|
2350
3517
|
this._onInputSubscription = this._textSelectionRenderManager.onInput$.subscribe(async (config) => {
|
|
2351
|
-
var
|
|
3518
|
+
var _a11;
|
|
2352
3519
|
if (config == null)
|
|
2353
3520
|
return;
|
|
2354
3521
|
const documentModel = this._univerInstanceService.getCurrentUniverDocInstance();
|
|
2355
3522
|
if (!documentModel)
|
|
2356
3523
|
return;
|
|
2357
|
-
const unitId = documentModel.getUnitId(), { event, content = "", activeRange } = config, e = event, skeleton = (
|
|
3524
|
+
const unitId = documentModel.getUnitId(), { event, content = "", activeRange } = config, e = event, skeleton = (_a11 = this._renderManagerService.getRenderById(documentModel.getUnitId())) == null ? void 0 : _a11.with(DocSkeletonManagerService).getSkeleton();
|
|
2358
3525
|
if (e.data == null || skeleton == null || !skeleton || !activeRange)
|
|
2359
3526
|
return;
|
|
2360
3527
|
const { startOffset, segmentId, style, segmentPage } = activeRange, len = content.length, textRanges = [
|
|
@@ -2374,10 +3541,10 @@ let NormalInputController = (_a6 = class extends Disposable {
|
|
|
2374
3541
|
textRanges,
|
|
2375
3542
|
range: activeRange,
|
|
2376
3543
|
segmentId
|
|
2377
|
-
});
|
|
3544
|
+
}), content === " " && await this._commandService.executeCommand(AfterSpaceCommand.id);
|
|
2378
3545
|
});
|
|
2379
3546
|
}
|
|
2380
|
-
}, __name(
|
|
3547
|
+
}, __name(_a7, "NormalInputController"), _a7);
|
|
2381
3548
|
NormalInputController = __decorateClass$3([
|
|
2382
3549
|
OnLifecycle(LifecycleStages.Rendered, NormalInputController),
|
|
2383
3550
|
__decorateParam$3(0, IUniverInstanceService),
|
|
@@ -2386,20 +3553,23 @@ NormalInputController = __decorateClass$3([
|
|
|
2386
3553
|
__decorateParam$3(3, ICommandService)
|
|
2387
3554
|
], NormalInputController);
|
|
2388
3555
|
const AlignOperationCommand = {
|
|
2389
|
-
id: "doc.command.align-
|
|
3556
|
+
id: "doc.command.align-action",
|
|
2390
3557
|
type: CommandType.COMMAND,
|
|
2391
3558
|
// eslint-disable-next-line max-lines-per-function
|
|
2392
3559
|
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
2393
|
-
var
|
|
2394
|
-
const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), { alignType } = params, docDataModel = univerInstanceService.getCurrentUniverDocInstance()
|
|
2395
|
-
if (docDataModel == null
|
|
3560
|
+
var _a11;
|
|
3561
|
+
const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), { alignType } = params, docDataModel = univerInstanceService.getCurrentUniverDocInstance();
|
|
3562
|
+
if (docDataModel == null)
|
|
2396
3563
|
return !1;
|
|
2397
|
-
const
|
|
3564
|
+
const allRanges = textSelectionManagerService.getDocRanges();
|
|
3565
|
+
if (allRanges.length === 0)
|
|
3566
|
+
return !1;
|
|
3567
|
+
const segmentId = allRanges[0].segmentId, paragraphs = (_a11 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a11.paragraphs, serializedSelections = allRanges.map(serializeDocRange);
|
|
2398
3568
|
if (paragraphs == null)
|
|
2399
3569
|
return !1;
|
|
2400
|
-
const currentParagraphs =
|
|
2401
|
-
var
|
|
2402
|
-
return ((
|
|
3570
|
+
const currentParagraphs = getParagraphsInRanges(allRanges, paragraphs), unitId = docDataModel.getUnitId(), isAlreadyAligned = currentParagraphs.every((paragraph) => {
|
|
3571
|
+
var _a12;
|
|
3572
|
+
return ((_a12 = paragraph.paragraphStyle) == null ? void 0 : _a12.horizontalAlign) === alignType;
|
|
2403
3573
|
}), doMutation = {
|
|
2404
3574
|
id: RichTextEditingMutation.id,
|
|
2405
3575
|
params: {
|
|
@@ -2470,14 +3640,14 @@ var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPrope
|
|
|
2470
3640
|
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
2471
3641
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
2472
3642
|
return kind && result && __defProp$2(target, key, result), result;
|
|
2473
|
-
}, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"),
|
|
2474
|
-
let DocCustomRangeController = (
|
|
3643
|
+
}, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a8;
|
|
3644
|
+
let DocCustomRangeController = (_a8 = class extends Disposable {
|
|
2475
3645
|
constructor(_commandService, _textSelectionManagerService, _univerInstanceService) {
|
|
2476
3646
|
super(), this._commandService = _commandService, this._textSelectionManagerService = _textSelectionManagerService, this._univerInstanceService = _univerInstanceService, this._initSelectionChange();
|
|
2477
3647
|
}
|
|
2478
3648
|
_transformCustomRange(doc, selection) {
|
|
2479
|
-
var
|
|
2480
|
-
const { startOffset, endOffset, collapsed } = selection, customRanges = (
|
|
3649
|
+
var _a11;
|
|
3650
|
+
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));
|
|
2481
3651
|
if (customRanges != null && customRanges.length) {
|
|
2482
3652
|
let start = startOffset, end = endOffset;
|
|
2483
3653
|
return customRanges.forEach((range) => {
|
|
@@ -2502,7 +3672,7 @@ let DocCustomRangeController = (_a7 = class extends Disposable {
|
|
|
2502
3672
|
}
|
|
2503
3673
|
}));
|
|
2504
3674
|
}
|
|
2505
|
-
}, __name(
|
|
3675
|
+
}, __name(_a8, "DocCustomRangeController"), _a8);
|
|
2506
3676
|
DocCustomRangeController = __decorateClass$2([
|
|
2507
3677
|
OnLifecycle(LifecycleStages.Ready, DocCustomRangeController),
|
|
2508
3678
|
__decorateParam$2(0, ICommandService),
|
|
@@ -2516,6 +3686,359 @@ const DocsRenameMutation = {
|
|
|
2516
3686
|
const doc = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
|
|
2517
3687
|
return doc ? (doc.setName(params.name), !0) : !1;
|
|
2518
3688
|
}, "handler")
|
|
3689
|
+
}, CreateDocTableCommandId = "doc.command.create-table", CreateDocTableCommand = {
|
|
3690
|
+
id: CreateDocTableCommandId,
|
|
3691
|
+
type: CommandType.COMMAND,
|
|
3692
|
+
// eslint-disable-next-line max-lines-per-function
|
|
3693
|
+
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
3694
|
+
var _a11, _b, _c, _d, _e, _f;
|
|
3695
|
+
const { rowCount, colCount } = params, textSelectionManagerService = accessor.get(TextSelectionManagerService$1), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), activeRange = textSelectionManagerService.getActiveTextRangeWithStyle();
|
|
3696
|
+
if (activeRange == null)
|
|
3697
|
+
return !1;
|
|
3698
|
+
const { segmentId, segmentPage } = activeRange, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), body = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
3699
|
+
if (docDataModel == null || body == null)
|
|
3700
|
+
return !1;
|
|
3701
|
+
const unitId = docDataModel.getUnitId(), docSkeletonManagerService = getCommandSkeleton$1(accessor, unitId), skeleton = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getSkeleton();
|
|
3702
|
+
if (skeleton == null)
|
|
3703
|
+
return !1;
|
|
3704
|
+
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";
|
|
3705
|
+
if (curGlyph == null || line == null)
|
|
3706
|
+
return !1;
|
|
3707
|
+
const needCreateParagraph = isInParagraph || line.isBehindTable, textX = new TextX(), jsonX = JSONX.getInstance(), rawActions = [], cursor = startOffset + (needCreateParagraph ? 4 : 3), textRanges = [{
|
|
3708
|
+
startOffset: cursor,
|
|
3709
|
+
endOffset: cursor,
|
|
3710
|
+
collapsed: !0
|
|
3711
|
+
}], doMutation = {
|
|
3712
|
+
id: RichTextEditingMutation$1.id,
|
|
3713
|
+
params: {
|
|
3714
|
+
unitId,
|
|
3715
|
+
actions: [],
|
|
3716
|
+
textRanges
|
|
3717
|
+
}
|
|
3718
|
+
};
|
|
3719
|
+
startOffset > 0 && textX.push({
|
|
3720
|
+
t: TextXActionType.RETAIN,
|
|
3721
|
+
len: startOffset,
|
|
3722
|
+
segmentId
|
|
3723
|
+
}), needCreateParagraph && textX.push({
|
|
3724
|
+
t: TextXActionType.INSERT,
|
|
3725
|
+
body: {
|
|
3726
|
+
dataStream: DataStreamTreeTokenType.PARAGRAPH,
|
|
3727
|
+
paragraphs: generateParagraphs$1(DataStreamTreeTokenType.PARAGRAPH, prevParagraph)
|
|
3728
|
+
},
|
|
3729
|
+
len: 1,
|
|
3730
|
+
line: 0,
|
|
3731
|
+
segmentId
|
|
3732
|
+
});
|
|
3733
|
+
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;
|
|
3734
|
+
if (page == null)
|
|
3735
|
+
return !1;
|
|
3736
|
+
const { pageWidth, marginLeft, marginRight } = page, tableSource = genTableSource(rowCount, colCount, pageWidth - marginLeft - marginRight);
|
|
3737
|
+
textX.push({
|
|
3738
|
+
t: TextXActionType.INSERT,
|
|
3739
|
+
body: {
|
|
3740
|
+
dataStream: tableDataStream,
|
|
3741
|
+
paragraphs: tableParagraphs,
|
|
3742
|
+
sectionBreaks,
|
|
3743
|
+
tables: [
|
|
3744
|
+
{
|
|
3745
|
+
startIndex: 0,
|
|
3746
|
+
endIndex: tableDataStream.length,
|
|
3747
|
+
tableId: tableSource.tableId
|
|
3748
|
+
}
|
|
3749
|
+
]
|
|
3750
|
+
},
|
|
3751
|
+
len: tableDataStream.length,
|
|
3752
|
+
line: 0,
|
|
3753
|
+
segmentId
|
|
3754
|
+
});
|
|
3755
|
+
const path = getRichTextEditPath$1(docDataModel, segmentId);
|
|
3756
|
+
rawActions.push(jsonX.editOp(textX.serialize(), path));
|
|
3757
|
+
const insertTableSource = jsonX.insertOp(["tableSource", tableSource.tableId], tableSource);
|
|
3758
|
+
return rawActions.push(insertTableSource), doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
3759
|
+
}, "handler")
|
|
3760
|
+
}, DocTableDeleteRowsCommand = {
|
|
3761
|
+
id: "doc.table.delete-rows",
|
|
3762
|
+
type: CommandType.COMMAND,
|
|
3763
|
+
// eslint-disable-next-line max-lines-per-function
|
|
3764
|
+
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
3765
|
+
const textSelectionManagerService = accessor.get(TextSelectionManagerService$1), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), activeRectRanges = textSelectionManagerService.getCurrentRectRanges(), activeTextRange = textSelectionManagerService.getActiveTextRange(), rangeInfo = getRangeInfoFromRanges(activeTextRange, activeRectRanges);
|
|
3766
|
+
if (rangeInfo == null)
|
|
3767
|
+
return !1;
|
|
3768
|
+
const { segmentId } = rangeInfo, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), body = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
3769
|
+
if (docDataModel == null || body == null)
|
|
3770
|
+
return !1;
|
|
3771
|
+
const docSkeletonManagerService = getCommandSkeleton$1(accessor, docDataModel.getUnitId());
|
|
3772
|
+
if (docSkeletonManagerService == null)
|
|
3773
|
+
return !1;
|
|
3774
|
+
const viewModel = docSkeletonManagerService.getViewModel(), unitId = docDataModel == null ? void 0 : docDataModel.getUnitId(), textX = new TextX(), jsonX = JSONX.getInstance(), actionParams = getDeleteRowsActionsParams(rangeInfo, viewModel);
|
|
3775
|
+
if (actionParams == null)
|
|
3776
|
+
return !1;
|
|
3777
|
+
const { offset, rowIndexes, len, tableId, cursor, selectWholeTable } = actionParams;
|
|
3778
|
+
if (selectWholeTable)
|
|
3779
|
+
return commandService.executeCommand(DocTableDeleteTableCommand.id);
|
|
3780
|
+
const rawActions = [], textRanges = [{
|
|
3781
|
+
startOffset: cursor,
|
|
3782
|
+
endOffset: cursor,
|
|
3783
|
+
collapsed: !0
|
|
3784
|
+
}], doMutation = {
|
|
3785
|
+
id: RichTextEditingMutation$1.id,
|
|
3786
|
+
params: {
|
|
3787
|
+
unitId,
|
|
3788
|
+
actions: [],
|
|
3789
|
+
textRanges
|
|
3790
|
+
}
|
|
3791
|
+
};
|
|
3792
|
+
offset > 0 && textX.push({
|
|
3793
|
+
t: TextXActionType.RETAIN,
|
|
3794
|
+
len: offset,
|
|
3795
|
+
segmentId
|
|
3796
|
+
}), textX.push({
|
|
3797
|
+
t: TextXActionType.DELETE,
|
|
3798
|
+
len,
|
|
3799
|
+
line: 0,
|
|
3800
|
+
segmentId
|
|
3801
|
+
});
|
|
3802
|
+
const path = getRichTextEditPath$1(docDataModel, segmentId);
|
|
3803
|
+
rawActions.push(jsonX.editOp(textX.serialize(), path));
|
|
3804
|
+
for (const index of rowIndexes.reverse()) {
|
|
3805
|
+
const action = jsonX.removeOp(["tableSource", tableId, "tableRows", index]);
|
|
3806
|
+
rawActions.push(action);
|
|
3807
|
+
}
|
|
3808
|
+
return doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
3809
|
+
}, "handler")
|
|
3810
|
+
}, DocTableDeleteColumnsCommand = {
|
|
3811
|
+
id: "doc.table.delete-columns",
|
|
3812
|
+
type: CommandType.COMMAND,
|
|
3813
|
+
// eslint-disable-next-line max-lines-per-function
|
|
3814
|
+
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
3815
|
+
const textSelectionManagerService = accessor.get(TextSelectionManagerService$1), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), activeRectRanges = textSelectionManagerService.getCurrentRectRanges(), activeTextRange = textSelectionManagerService.getActiveTextRange(), rangeInfo = getRangeInfoFromRanges(activeTextRange, activeRectRanges);
|
|
3816
|
+
if (rangeInfo == null)
|
|
3817
|
+
return !1;
|
|
3818
|
+
const { segmentId } = rangeInfo, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), body = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
3819
|
+
if (docDataModel == null || body == null)
|
|
3820
|
+
return !1;
|
|
3821
|
+
const docSkeletonManagerService = getCommandSkeleton$1(accessor, docDataModel.getUnitId());
|
|
3822
|
+
if (docSkeletonManagerService == null)
|
|
3823
|
+
return !1;
|
|
3824
|
+
const viewModel = docSkeletonManagerService.getViewModel(), unitId = docDataModel == null ? void 0 : docDataModel.getUnitId(), textX = new TextX(), jsonX = JSONX.getInstance(), actionParams = getDeleteColumnsActionParams(rangeInfo, viewModel);
|
|
3825
|
+
if (actionParams == null)
|
|
3826
|
+
return !1;
|
|
3827
|
+
const { offsets, columnIndexes, tableId, cursor, rowCount, selectWholeTable } = actionParams;
|
|
3828
|
+
if (selectWholeTable)
|
|
3829
|
+
return commandService.executeCommand(DocTableDeleteTableCommand.id);
|
|
3830
|
+
const rawActions = [], textRanges = [{
|
|
3831
|
+
startOffset: cursor,
|
|
3832
|
+
endOffset: cursor,
|
|
3833
|
+
collapsed: !0
|
|
3834
|
+
}], doMutation = {
|
|
3835
|
+
id: RichTextEditingMutation$1.id,
|
|
3836
|
+
params: {
|
|
3837
|
+
unitId,
|
|
3838
|
+
actions: [],
|
|
3839
|
+
textRanges
|
|
3840
|
+
}
|
|
3841
|
+
};
|
|
3842
|
+
for (const offset of offsets) {
|
|
3843
|
+
const { retain, delete: deleteLen } = offset;
|
|
3844
|
+
retain > 0 && textX.push({
|
|
3845
|
+
t: TextXActionType.RETAIN,
|
|
3846
|
+
len: retain,
|
|
3847
|
+
segmentId
|
|
3848
|
+
}), textX.push({
|
|
3849
|
+
t: TextXActionType.DELETE,
|
|
3850
|
+
len: deleteLen,
|
|
3851
|
+
line: 0,
|
|
3852
|
+
segmentId
|
|
3853
|
+
});
|
|
3854
|
+
}
|
|
3855
|
+
const path = getRichTextEditPath$1(docDataModel, segmentId);
|
|
3856
|
+
rawActions.push(jsonX.editOp(textX.serialize(), path)), columnIndexes.reverse();
|
|
3857
|
+
for (let i = 0; i < rowCount; i++)
|
|
3858
|
+
for (const index of columnIndexes) {
|
|
3859
|
+
const action = jsonX.removeOp(["tableSource", tableId, "tableRows", i, "tableCells", index]);
|
|
3860
|
+
rawActions.push(action);
|
|
3861
|
+
}
|
|
3862
|
+
for (const index of columnIndexes) {
|
|
3863
|
+
const action = jsonX.removeOp(["tableSource", tableId, "tableColumns", index]);
|
|
3864
|
+
rawActions.push(action);
|
|
3865
|
+
}
|
|
3866
|
+
return doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
3867
|
+
}, "handler")
|
|
3868
|
+
}, DocTableDeleteTableCommand = {
|
|
3869
|
+
id: "doc.table.delete-table",
|
|
3870
|
+
type: CommandType.COMMAND,
|
|
3871
|
+
// eslint-disable-next-line max-lines-per-function
|
|
3872
|
+
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
3873
|
+
const textSelectionManagerService = accessor.get(TextSelectionManagerService$1), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), activeRectRanges = textSelectionManagerService.getCurrentRectRanges(), activeTextRange = textSelectionManagerService.getActiveTextRange(), rangeInfo = getRangeInfoFromRanges(activeTextRange, activeRectRanges);
|
|
3874
|
+
if (rangeInfo == null)
|
|
3875
|
+
return !1;
|
|
3876
|
+
const { segmentId } = rangeInfo, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), body = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
3877
|
+
if (docDataModel == null || body == null)
|
|
3878
|
+
return !1;
|
|
3879
|
+
const docSkeletonManagerService = getCommandSkeleton$1(accessor, docDataModel.getUnitId());
|
|
3880
|
+
if (docSkeletonManagerService == null)
|
|
3881
|
+
return !1;
|
|
3882
|
+
const viewModel = docSkeletonManagerService.getViewModel(), unitId = docDataModel == null ? void 0 : docDataModel.getUnitId(), textX = new TextX(), jsonX = JSONX.getInstance(), actionParams = getDeleteTableActionParams(rangeInfo, viewModel);
|
|
3883
|
+
if (actionParams == null)
|
|
3884
|
+
return !1;
|
|
3885
|
+
const { offset, len, tableId, cursor } = actionParams, rawActions = [], textRanges = [{
|
|
3886
|
+
startOffset: cursor,
|
|
3887
|
+
endOffset: cursor,
|
|
3888
|
+
collapsed: !0
|
|
3889
|
+
}], doMutation = {
|
|
3890
|
+
id: RichTextEditingMutation$1.id,
|
|
3891
|
+
params: {
|
|
3892
|
+
unitId,
|
|
3893
|
+
actions: [],
|
|
3894
|
+
textRanges
|
|
3895
|
+
}
|
|
3896
|
+
};
|
|
3897
|
+
offset > 0 && textX.push({
|
|
3898
|
+
t: TextXActionType.RETAIN,
|
|
3899
|
+
len: offset,
|
|
3900
|
+
segmentId
|
|
3901
|
+
}), textX.push({
|
|
3902
|
+
t: TextXActionType.DELETE,
|
|
3903
|
+
len,
|
|
3904
|
+
line: 0,
|
|
3905
|
+
segmentId
|
|
3906
|
+
});
|
|
3907
|
+
const path = getRichTextEditPath$1(docDataModel, segmentId);
|
|
3908
|
+
rawActions.push(jsonX.editOp(textX.serialize(), path));
|
|
3909
|
+
const action = jsonX.removeOp(["tableSource", tableId]);
|
|
3910
|
+
return rawActions.push(action), doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
3911
|
+
}, "handler")
|
|
3912
|
+
}, 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 = {
|
|
3913
|
+
id: DocTableInsertRowAboveCommandId,
|
|
3914
|
+
type: CommandType.COMMAND,
|
|
3915
|
+
handler: /* @__PURE__ */ __name(async (accessor) => accessor.get(ICommandService).executeCommand(DocTableInsertRowCommandId, { position: INSERT_ROW_POSITION.ABOVE }), "handler")
|
|
3916
|
+
}, DocTableInsertRowBellowCommand = {
|
|
3917
|
+
id: DocTableInsertRowBellowCommandId,
|
|
3918
|
+
type: CommandType.COMMAND,
|
|
3919
|
+
handler: /* @__PURE__ */ __name(async (accessor) => accessor.get(ICommandService).executeCommand(DocTableInsertRowCommandId, { position: INSERT_ROW_POSITION.BELLOW }), "handler")
|
|
3920
|
+
}, DocTableInsertColumnLeftCommand = {
|
|
3921
|
+
id: DocTableInsertColumnLeftCommandId,
|
|
3922
|
+
type: CommandType.COMMAND,
|
|
3923
|
+
handler: /* @__PURE__ */ __name(async (accessor) => accessor.get(ICommandService).executeCommand(DocTableInsertColumnCommandId, { position: INSERT_COLUMN_POSITION.LEFT }), "handler")
|
|
3924
|
+
}, DocTableInsertColumnRightCommand = {
|
|
3925
|
+
id: DocTableInsertColumnRightCommandId,
|
|
3926
|
+
type: CommandType.COMMAND,
|
|
3927
|
+
handler: /* @__PURE__ */ __name(async (accessor) => accessor.get(ICommandService).executeCommand(DocTableInsertColumnCommandId, { position: INSERT_COLUMN_POSITION.RIGHT }), "handler")
|
|
3928
|
+
}, DocTableInsertRowCommand = {
|
|
3929
|
+
id: DocTableInsertRowCommandId,
|
|
3930
|
+
type: CommandType.COMMAND,
|
|
3931
|
+
// eslint-disable-next-line max-lines-per-function
|
|
3932
|
+
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
3933
|
+
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);
|
|
3934
|
+
if (rangeInfo == null)
|
|
3935
|
+
return !1;
|
|
3936
|
+
const { segmentId } = rangeInfo, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), body = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
3937
|
+
if (docDataModel == null || body == null)
|
|
3938
|
+
return !1;
|
|
3939
|
+
const docSkeletonManagerService = getCommandSkeleton$1(accessor, docDataModel.getUnitId());
|
|
3940
|
+
if (docSkeletonManagerService == null)
|
|
3941
|
+
return !1;
|
|
3942
|
+
const viewModel = docSkeletonManagerService.getViewModel(), unitId = docDataModel == null ? void 0 : docDataModel.getUnitId(), textX = new TextX(), jsonX = JSONX.getInstance(), actionParams = getInsertRowActionsParams(rangeInfo, position, viewModel);
|
|
3943
|
+
if (actionParams == null)
|
|
3944
|
+
return !1;
|
|
3945
|
+
const { offset, colCount, tableId, insertRowIndex } = actionParams, rawActions = [], cursor = offset + 2, textRanges = [{
|
|
3946
|
+
startOffset: cursor,
|
|
3947
|
+
endOffset: cursor,
|
|
3948
|
+
collapsed: !0
|
|
3949
|
+
}], doMutation = {
|
|
3950
|
+
id: RichTextEditingMutation$1.id,
|
|
3951
|
+
params: {
|
|
3952
|
+
unitId,
|
|
3953
|
+
actions: [],
|
|
3954
|
+
textRanges
|
|
3955
|
+
}
|
|
3956
|
+
};
|
|
3957
|
+
offset > 0 && textX.push({
|
|
3958
|
+
t: TextXActionType.RETAIN,
|
|
3959
|
+
len: offset,
|
|
3960
|
+
segmentId
|
|
3961
|
+
});
|
|
3962
|
+
const insertBody = getInsertRowBody(colCount);
|
|
3963
|
+
textX.push({
|
|
3964
|
+
t: TextXActionType.INSERT,
|
|
3965
|
+
body: insertBody,
|
|
3966
|
+
len: insertBody.dataStream.length,
|
|
3967
|
+
line: 0,
|
|
3968
|
+
segmentId
|
|
3969
|
+
});
|
|
3970
|
+
const path = getRichTextEditPath$1(docDataModel, segmentId);
|
|
3971
|
+
rawActions.push(jsonX.editOp(textX.serialize(), path));
|
|
3972
|
+
const insertRow = getEmptyTableRow(colCount), insertTableSource = jsonX.insertOp(["tableSource", tableId, "tableRows", insertRowIndex], insertRow);
|
|
3973
|
+
return rawActions.push(insertTableSource), doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
3974
|
+
}, "handler")
|
|
3975
|
+
}, DocTableInsertColumnCommand = {
|
|
3976
|
+
id: DocTableInsertColumnCommandId,
|
|
3977
|
+
type: CommandType.COMMAND,
|
|
3978
|
+
// eslint-disable-next-line max-lines-per-function
|
|
3979
|
+
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
3980
|
+
var _a11, _b, _c;
|
|
3981
|
+
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);
|
|
3982
|
+
if (rangeInfo == null)
|
|
3983
|
+
return !1;
|
|
3984
|
+
const { segmentId } = rangeInfo, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), body = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
3985
|
+
if (docDataModel == null || body == null)
|
|
3986
|
+
return !1;
|
|
3987
|
+
const docSkeletonManagerService = getCommandSkeleton$1(accessor, docDataModel.getUnitId());
|
|
3988
|
+
if (docSkeletonManagerService == null)
|
|
3989
|
+
return !1;
|
|
3990
|
+
const viewModel = docSkeletonManagerService.getViewModel(), unitId = docDataModel == null ? void 0 : docDataModel.getUnitId(), textX = new TextX(), jsonX = JSONX.getInstance(), actionParams = getInsertColumnActionsParams(rangeInfo, position, viewModel);
|
|
3991
|
+
if (actionParams == null)
|
|
3992
|
+
return !1;
|
|
3993
|
+
const { offsets, columnIndex, tableId, rowCount } = actionParams, rawActions = [], cursor = offsets[0] + 1, textRanges = [{
|
|
3994
|
+
startOffset: cursor,
|
|
3995
|
+
endOffset: cursor,
|
|
3996
|
+
collapsed: !0
|
|
3997
|
+
}], doMutation = {
|
|
3998
|
+
id: RichTextEditingMutation$1.id,
|
|
3999
|
+
params: {
|
|
4000
|
+
unitId,
|
|
4001
|
+
actions: [],
|
|
4002
|
+
textRanges
|
|
4003
|
+
}
|
|
4004
|
+
};
|
|
4005
|
+
for (const offset of offsets) {
|
|
4006
|
+
textX.push({
|
|
4007
|
+
t: TextXActionType.RETAIN,
|
|
4008
|
+
len: offset,
|
|
4009
|
+
segmentId
|
|
4010
|
+
});
|
|
4011
|
+
const insertBody = getInsertColumnBody();
|
|
4012
|
+
textX.push({
|
|
4013
|
+
t: TextXActionType.INSERT,
|
|
4014
|
+
body: insertBody,
|
|
4015
|
+
len: insertBody.dataStream.length,
|
|
4016
|
+
line: 0,
|
|
4017
|
+
segmentId
|
|
4018
|
+
});
|
|
4019
|
+
}
|
|
4020
|
+
const path = getRichTextEditPath$1(docDataModel, segmentId);
|
|
4021
|
+
rawActions.push(jsonX.editOp(textX.serialize(), path));
|
|
4022
|
+
for (let i = 0; i < rowCount; i++) {
|
|
4023
|
+
const insertCell = getEmptyTableCell(), insertTableSource = jsonX.insertOp(["tableSource", tableId, "tableRows", i, "tableCells", columnIndex], insertCell);
|
|
4024
|
+
rawActions.push(insertTableSource);
|
|
4025
|
+
}
|
|
4026
|
+
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);
|
|
4027
|
+
for (let i = 0; i < widths.length; i++) {
|
|
4028
|
+
const action = jsonX.replaceOp(["tableSource", tableId, "tableColumns", i, "size", "width", "v"], tableColumns[i].size.width.v, widths[i]);
|
|
4029
|
+
rawActions.push(action);
|
|
4030
|
+
}
|
|
4031
|
+
const insertCol = getTableColumn(newColWidth), insertTableColumn = jsonX.insertOp(["tableSource", tableId, "tableColumns", columnIndex], insertCol);
|
|
4032
|
+
return rawActions.push(insertTableColumn), doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
4033
|
+
}, "handler")
|
|
4034
|
+
}, DocTableTabCommand = {
|
|
4035
|
+
id: "doc.table.tab-in-table",
|
|
4036
|
+
type: CommandType.COMMAND,
|
|
4037
|
+
handler: /* @__PURE__ */ __name(async () => !0, "handler")
|
|
4038
|
+
}, DocTableShiftTabCommand = {
|
|
4039
|
+
id: "doc.table.shift-tab-in-table",
|
|
4040
|
+
type: CommandType.COMMAND,
|
|
4041
|
+
handler: /* @__PURE__ */ __name(async () => !0, "handler")
|
|
2519
4042
|
};
|
|
2520
4043
|
var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
2521
4044
|
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
@@ -2523,8 +4046,8 @@ var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPrope
|
|
|
2523
4046
|
return kind && result && __defProp$1(target, key, result), result;
|
|
2524
4047
|
}, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1");
|
|
2525
4048
|
const PLUGIN_NAME = "DOCS_PLUGIN";
|
|
2526
|
-
var
|
|
2527
|
-
let UniverDocsPlugin = (
|
|
4049
|
+
var _a9;
|
|
4050
|
+
let UniverDocsPlugin = (_a9 = class extends Plugin {
|
|
2528
4051
|
constructor(_config = {}, _injector) {
|
|
2529
4052
|
super(), this._injector = _injector, this._initializeDependencies(_injector), this._initializeCommands();
|
|
2530
4053
|
}
|
|
@@ -2568,7 +4091,27 @@ let UniverDocsPlugin = (_a8 = class extends Plugin {
|
|
|
2568
4091
|
AlignRightCommand,
|
|
2569
4092
|
AlignOperationCommand,
|
|
2570
4093
|
AlignJustifyCommand,
|
|
2571
|
-
|
|
4094
|
+
CreateDocTableCommand,
|
|
4095
|
+
DocTableInsertRowCommand,
|
|
4096
|
+
DocTableInsertRowAboveCommand,
|
|
4097
|
+
DocTableInsertRowBellowCommand,
|
|
4098
|
+
DocTableInsertColumnCommand,
|
|
4099
|
+
DocTableInsertColumnLeftCommand,
|
|
4100
|
+
DocTableInsertColumnRightCommand,
|
|
4101
|
+
DocTableDeleteRowsCommand,
|
|
4102
|
+
DocTableDeleteColumnsCommand,
|
|
4103
|
+
DocTableDeleteTableCommand,
|
|
4104
|
+
DocTableTabCommand,
|
|
4105
|
+
DocTableShiftTabCommand,
|
|
4106
|
+
DocsRenameMutation,
|
|
4107
|
+
TabCommand,
|
|
4108
|
+
AfterSpaceCommand,
|
|
4109
|
+
EnterCommand,
|
|
4110
|
+
ChangeListNestingLevelCommand,
|
|
4111
|
+
ChangeListTypeCommand,
|
|
4112
|
+
CheckListCommand,
|
|
4113
|
+
ToggleCheckListCommand,
|
|
4114
|
+
QuickListCommand
|
|
2572
4115
|
].forEach((command) => {
|
|
2573
4116
|
this._injector.get(ICommandService).registerCommand(command);
|
|
2574
4117
|
});
|
|
@@ -2586,6 +4129,7 @@ let UniverDocsPlugin = (_a8 = class extends Plugin {
|
|
|
2586
4129
|
],
|
|
2587
4130
|
[TextSelectionManagerService],
|
|
2588
4131
|
[DocCustomRangeService],
|
|
4132
|
+
[DocAutoFormatService],
|
|
2589
4133
|
// controllers
|
|
2590
4134
|
[NormalInputController],
|
|
2591
4135
|
[IMEInputController],
|
|
@@ -2593,10 +4137,11 @@ let UniverDocsPlugin = (_a8 = class extends Plugin {
|
|
|
2593
4137
|
[DocCustomRangeController]
|
|
2594
4138
|
].forEach((d) => docInjector.add(d));
|
|
2595
4139
|
}
|
|
2596
|
-
}, __name(
|
|
4140
|
+
}, __name(_a9, "UniverDocsPlugin"), __publicField(_a9, "pluginName", PLUGIN_NAME), __publicField(_a9, "type", UniverInstanceType.UNIVER_DOC), _a9);
|
|
2597
4141
|
UniverDocsPlugin = __decorateClass$1([
|
|
2598
4142
|
__decorateParam$1(1, Inject(Injector))
|
|
2599
4143
|
], UniverDocsPlugin);
|
|
4144
|
+
const getPlainTextFormDocument = /* @__PURE__ */ __name((data) => data.body ? data.body.dataStream.slice(0, -2).replaceAll(DataStreamTreeTokenType.CUSTOM_RANGE_START, "").replaceAll(DataStreamTreeTokenType.CUSTOM_RANGE_END, "") : "", "getPlainTextFormDocument");
|
|
2600
4145
|
function addCustomRangeTextX(param, body) {
|
|
2601
4146
|
const { range, rangeId, rangeType, segmentId } = param, actualRange = getSelectionForAddCustomRange(range, body);
|
|
2602
4147
|
if (!actualRange)
|
|
@@ -2651,8 +4196,8 @@ function addCustomRangeFactory(param, body) {
|
|
|
2651
4196
|
}
|
|
2652
4197
|
__name(addCustomRangeFactory, "addCustomRangeFactory");
|
|
2653
4198
|
function addCustomRangeBySelectionFactory(accessor, param) {
|
|
2654
|
-
var
|
|
2655
|
-
const { segmentId, rangeId, rangeType, wholeEntity } = param, textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), selection = textSelectionManagerService.
|
|
4199
|
+
var _a11;
|
|
4200
|
+
const { segmentId, rangeId, rangeType, wholeEntity } = param, textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), selection = textSelectionManagerService.getActiveTextRangeWithStyle();
|
|
2656
4201
|
if (!selection)
|
|
2657
4202
|
return !1;
|
|
2658
4203
|
const documentDataModel = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
|
|
@@ -2661,7 +4206,7 @@ function addCustomRangeBySelectionFactory(accessor, param) {
|
|
|
2661
4206
|
const body = documentDataModel.getBody(), unitId = documentDataModel.getUnitId();
|
|
2662
4207
|
if (!body)
|
|
2663
4208
|
return !1;
|
|
2664
|
-
const { startOffset, endOffset } = normalizeSelection(selection), customRanges = (
|
|
4209
|
+
const { startOffset, endOffset } = normalizeSelection(selection), customRanges = (_a11 = body.customRanges) != null ? _a11 : [], relativeCustomRanges = [];
|
|
2665
4210
|
for (let i = 0, len = customRanges.length; i < len; i++) {
|
|
2666
4211
|
const customRange = customRanges[i];
|
|
2667
4212
|
if (customRange.rangeType === rangeType && Math.max(customRange.startIndex, startOffset) <= Math.min(customRange.endIndex, endOffset - 1) && relativeCustomRanges.push({ ...customRange }), customRange.startIndex >= endOffset)
|
|
@@ -2730,11 +4275,11 @@ function addCustomRangeBySelectionFactory(accessor, param) {
|
|
|
2730
4275
|
}
|
|
2731
4276
|
__name(addCustomRangeBySelectionFactory, "addCustomRangeBySelectionFactory");
|
|
2732
4277
|
function deleteCustomRangeTextX(accessor, params) {
|
|
2733
|
-
var
|
|
4278
|
+
var _a11, _b;
|
|
2734
4279
|
const { unitId, rangeId, segmentId } = params, documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId);
|
|
2735
4280
|
if (!documentDataModel)
|
|
2736
4281
|
return !1;
|
|
2737
|
-
const range = (_b = (
|
|
4282
|
+
const range = (_b = (_a11 = documentDataModel.getBody()) == null ? void 0 : _a11.customRanges) == null ? void 0 : _b.find((r) => r.rangeId === rangeId);
|
|
2738
4283
|
if (!range)
|
|
2739
4284
|
return !1;
|
|
2740
4285
|
const { startIndex, endIndex } = range, textX = new TextX(), len = endIndex - startIndex + 1;
|
|
@@ -2772,7 +4317,7 @@ function deleteCustomRangeFactory(accessor, params) {
|
|
|
2772
4317
|
}
|
|
2773
4318
|
__name(deleteCustomRangeFactory, "deleteCustomRangeFactory");
|
|
2774
4319
|
function addCustomDecorationFactory(param) {
|
|
2775
|
-
const { unitId,
|
|
4320
|
+
const { unitId, ranges, id, type, segmentId } = param, doMutation = {
|
|
2776
4321
|
id: RichTextEditingMutation.id,
|
|
2777
4322
|
params: {
|
|
2778
4323
|
unitId,
|
|
@@ -2780,29 +4325,34 @@ function addCustomDecorationFactory(param) {
|
|
|
2780
4325
|
textRanges: void 0
|
|
2781
4326
|
}
|
|
2782
4327
|
}, textX = new TextX(), jsonX = JSONX.getInstance();
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
4328
|
+
let cursor = 0;
|
|
4329
|
+
for (let i = 0; i < ranges.length; i++) {
|
|
4330
|
+
const range = ranges[i], { startOffset: start, endOffset: end } = range;
|
|
4331
|
+
start > 0 && textX.push({
|
|
4332
|
+
t: TextXActionType.RETAIN,
|
|
4333
|
+
len: start - cursor,
|
|
4334
|
+
segmentId
|
|
4335
|
+
}), textX.push({
|
|
4336
|
+
t: TextXActionType.RETAIN,
|
|
4337
|
+
body: {
|
|
4338
|
+
dataStream: "",
|
|
4339
|
+
customDecorations: [{
|
|
4340
|
+
id,
|
|
4341
|
+
type,
|
|
4342
|
+
startIndex: 0,
|
|
4343
|
+
endIndex: end - start - 1
|
|
4344
|
+
}]
|
|
4345
|
+
},
|
|
4346
|
+
len: end - start,
|
|
4347
|
+
segmentId
|
|
4348
|
+
}), cursor = end;
|
|
4349
|
+
}
|
|
4350
|
+
return doMutation.params.actions = jsonX.editOp(textX.serialize()), doMutation;
|
|
2801
4351
|
}
|
|
2802
4352
|
__name(addCustomDecorationFactory, "addCustomDecorationFactory");
|
|
2803
4353
|
function addCustomDecorationBySelectionFactory(accessor, param) {
|
|
2804
|
-
const { segmentId, id, type } = param, textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService),
|
|
2805
|
-
if (!
|
|
4354
|
+
const { segmentId, id, type } = param, textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), selections = textSelectionManagerService.getCurrentTextRanges();
|
|
4355
|
+
if (!selections)
|
|
2806
4356
|
return !1;
|
|
2807
4357
|
const documentDataModel = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
|
|
2808
4358
|
if (!documentDataModel)
|
|
@@ -2811,11 +4361,7 @@ function addCustomDecorationBySelectionFactory(accessor, param) {
|
|
|
2811
4361
|
return body ? addCustomDecorationFactory(
|
|
2812
4362
|
{
|
|
2813
4363
|
unitId,
|
|
2814
|
-
|
|
2815
|
-
startOffset: selection.startOffset,
|
|
2816
|
-
endOffset: selection.endOffset,
|
|
2817
|
-
collapsed: !0
|
|
2818
|
-
},
|
|
4364
|
+
ranges: selections.map(serializeDocRange),
|
|
2819
4365
|
id,
|
|
2820
4366
|
type,
|
|
2821
4367
|
segmentId
|
|
@@ -2824,17 +4370,17 @@ function addCustomDecorationBySelectionFactory(accessor, param) {
|
|
|
2824
4370
|
}
|
|
2825
4371
|
__name(addCustomDecorationBySelectionFactory, "addCustomDecorationBySelectionFactory");
|
|
2826
4372
|
function deleteCustomDecorationFactory(accessor, params) {
|
|
2827
|
-
var
|
|
4373
|
+
var _a11, _b;
|
|
2828
4374
|
const { unitId, id, segmentId } = params, documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId), body = documentDataModel == null ? void 0 : documentDataModel.getBody();
|
|
2829
4375
|
if (!documentDataModel || !body)
|
|
2830
4376
|
return !1;
|
|
2831
|
-
const decorations = (_b = (
|
|
4377
|
+
const decorations = (_b = (_a11 = documentDataModel.getBody()) == null ? void 0 : _a11.customDecorations) == null ? void 0 : _b.filter((d) => d.id === id);
|
|
2832
4378
|
if (!(decorations != null && decorations.length))
|
|
2833
4379
|
return !1;
|
|
2834
4380
|
const oldBodySlices = decorations.map((i) => getBodySlice(body, i.startIndex, i.endIndex + 1)), bodySlices = oldBodySlices.map((bodySlice) => {
|
|
2835
|
-
var
|
|
4381
|
+
var _a12;
|
|
2836
4382
|
const copy = Tools.deepClone(bodySlice);
|
|
2837
|
-
return copy.customDecorations = (
|
|
4383
|
+
return copy.customDecorations = (_a12 = copy.customDecorations) == null ? void 0 : _a12.filter((decoration) => decoration.id !== id), copy;
|
|
2838
4384
|
}), doMutation = {
|
|
2839
4385
|
id: RichTextEditingMutation.id,
|
|
2840
4386
|
params: {
|
|
@@ -2869,8 +4415,8 @@ var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnProperty
|
|
|
2869
4415
|
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
2870
4416
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
2871
4417
|
return kind && result && __defProp2(target, key, result), result;
|
|
2872
|
-
}, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"),
|
|
2873
|
-
let DocInterceptorService = (
|
|
4418
|
+
}, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), _a10;
|
|
4419
|
+
let DocInterceptorService = (_a10 = class extends Disposable {
|
|
2874
4420
|
constructor(_context, _docSkeletonManagerService) {
|
|
2875
4421
|
super();
|
|
2876
4422
|
__publicField(this, "_interceptorsByName", /* @__PURE__ */ new Map());
|
|
@@ -2893,8 +4439,8 @@ let DocInterceptorService = (_a9 = class extends Disposable {
|
|
|
2893
4439
|
return interceptors.push(interceptor), this._interceptorsByName.set(
|
|
2894
4440
|
key,
|
|
2895
4441
|
interceptors.sort((a, b) => {
|
|
2896
|
-
var
|
|
2897
|
-
return ((
|
|
4442
|
+
var _a11, _b;
|
|
4443
|
+
return ((_a11 = b.priority) != null ? _a11 : 0) - ((_b = a.priority) != null ? _b : 0);
|
|
2898
4444
|
})
|
|
2899
4445
|
), this.disposeWithMe(toDisposable(() => remove(this._interceptorsByName.get(key), interceptor)));
|
|
2900
4446
|
}
|
|
@@ -2906,36 +4452,36 @@ let DocInterceptorService = (_a9 = class extends Disposable {
|
|
|
2906
4452
|
const disposableCollection = new DisposableCollection();
|
|
2907
4453
|
return disposableCollection.add(viewModel.registerCustomRangeInterceptor({
|
|
2908
4454
|
getCustomRange: /* @__PURE__ */ __name((index) => {
|
|
2909
|
-
var
|
|
4455
|
+
var _a11;
|
|
2910
4456
|
return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE)(
|
|
2911
4457
|
viewModel.getCustomRangeRaw(index),
|
|
2912
4458
|
{
|
|
2913
4459
|
index,
|
|
2914
4460
|
unitId: viewModel.getDataModel().getUnitId(),
|
|
2915
|
-
customRanges: (
|
|
4461
|
+
customRanges: (_a11 = viewModel.getDataModel().getCustomRanges()) != null ? _a11 : []
|
|
2916
4462
|
}
|
|
2917
4463
|
);
|
|
2918
4464
|
}, "getCustomRange"),
|
|
2919
4465
|
getCustomDecoration: /* @__PURE__ */ __name((index) => {
|
|
2920
|
-
var
|
|
4466
|
+
var _a11;
|
|
2921
4467
|
return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION)(
|
|
2922
4468
|
viewModel.getCustomDecorationRaw(index),
|
|
2923
4469
|
{
|
|
2924
4470
|
index,
|
|
2925
4471
|
unitId: viewModel.getDataModel().getUnitId(),
|
|
2926
|
-
customDecorations: (
|
|
4472
|
+
customDecorations: (_a11 = viewModel.getDataModel().getCustomDecorations()) != null ? _a11 : []
|
|
2927
4473
|
}
|
|
2928
4474
|
);
|
|
2929
4475
|
}, "getCustomDecoration")
|
|
2930
4476
|
})), disposableCollection;
|
|
2931
4477
|
}
|
|
2932
|
-
}, __name(
|
|
4478
|
+
}, __name(_a10, "DocInterceptorService"), _a10);
|
|
2933
4479
|
DocInterceptorService = __decorateClass([
|
|
2934
4480
|
OnLifecycle(LifecycleStages.Starting, DocInterceptorService),
|
|
2935
4481
|
__decorateParam(1, Inject(DocSkeletonManagerService))
|
|
2936
4482
|
], DocInterceptorService);
|
|
2937
|
-
const getPlainTextFormDocument = /* @__PURE__ */ __name((data) => data.body ? data.body.dataStream.slice(0, -2).replaceAll(DataStreamTreeTokenType.CUSTOM_RANGE_START, "").replaceAll(DataStreamTreeTokenType.CUSTOM_RANGE_END, "") : "", "getPlainTextFormDocument");
|
|
2938
4483
|
export {
|
|
4484
|
+
AfterSpaceCommand,
|
|
2939
4485
|
AlignCenterCommand,
|
|
2940
4486
|
AlignJustifyCommand,
|
|
2941
4487
|
AlignLeftCommand,
|
|
@@ -2943,7 +4489,12 @@ export {
|
|
|
2943
4489
|
AlignRightCommand,
|
|
2944
4490
|
BreakLineCommand,
|
|
2945
4491
|
BulletListCommand,
|
|
4492
|
+
ChangeListNestingLevelCommand,
|
|
4493
|
+
ChangeListNestingLevelType,
|
|
4494
|
+
ChangeListTypeCommand,
|
|
4495
|
+
CheckListCommand,
|
|
2946
4496
|
CoverContentCommand,
|
|
4497
|
+
CreateDocTableCommand,
|
|
2947
4498
|
CutContentCommand,
|
|
2948
4499
|
DOCS_COMPONENT_BACKGROUND_LAYER_INDEX,
|
|
2949
4500
|
DOCS_COMPONENT_DEFAULT_Z_INDEX,
|
|
@@ -2955,11 +4506,24 @@ export {
|
|
|
2955
4506
|
DeleteCustomBlockCommand,
|
|
2956
4507
|
DeleteLeftCommand,
|
|
2957
4508
|
DeleteRightCommand,
|
|
4509
|
+
DocAutoFormatService,
|
|
2958
4510
|
DocCustomRangeService,
|
|
2959
4511
|
DocInterceptorService,
|
|
2960
4512
|
DocSkeletonManagerService,
|
|
2961
4513
|
DocStateChangeManagerService,
|
|
4514
|
+
DocTableDeleteColumnsCommand,
|
|
4515
|
+
DocTableDeleteRowsCommand,
|
|
4516
|
+
DocTableDeleteTableCommand,
|
|
4517
|
+
DocTableInsertColumnCommand,
|
|
4518
|
+
DocTableInsertColumnLeftCommand,
|
|
4519
|
+
DocTableInsertColumnRightCommand,
|
|
4520
|
+
DocTableInsertRowAboveCommand,
|
|
4521
|
+
DocTableInsertRowBellowCommand,
|
|
4522
|
+
DocTableInsertRowCommand,
|
|
4523
|
+
DocTableShiftTabCommand,
|
|
4524
|
+
DocTableTabCommand,
|
|
2962
4525
|
EditorInsertTextCommandId,
|
|
4526
|
+
EnterCommand,
|
|
2963
4527
|
IMEInputCommand,
|
|
2964
4528
|
IMEInputManagerService,
|
|
2965
4529
|
InnerPasteCommand,
|
|
@@ -2970,6 +4534,7 @@ export {
|
|
|
2970
4534
|
MoveSelectionOperation,
|
|
2971
4535
|
NORMAL_TEXT_SELECTION_PLUGIN_NAME,
|
|
2972
4536
|
OrderListCommand,
|
|
4537
|
+
QuickListCommand,
|
|
2973
4538
|
ReplaceContentCommand,
|
|
2974
4539
|
ResetInlineFormatTextBackgroundColorCommand,
|
|
2975
4540
|
RichTextEditingMutation,
|
|
@@ -2988,7 +4553,9 @@ export {
|
|
|
2988
4553
|
SetInlineFormatTextColorCommand,
|
|
2989
4554
|
SetInlineFormatUnderlineCommand,
|
|
2990
4555
|
SetTextSelectionsOperation,
|
|
4556
|
+
TabCommand,
|
|
2991
4557
|
TextSelectionManagerService,
|
|
4558
|
+
ToggleCheckListCommand,
|
|
2992
4559
|
UniverDocsPlugin,
|
|
2993
4560
|
UpdateCommand,
|
|
2994
4561
|
VIEWPORT_KEY,
|
|
@@ -2998,16 +4565,26 @@ export {
|
|
|
2998
4565
|
addCustomRangeFactory,
|
|
2999
4566
|
deleteCustomDecorationFactory,
|
|
3000
4567
|
deleteCustomRangeFactory,
|
|
4568
|
+
genTableSource,
|
|
4569
|
+
generateParagraphs,
|
|
4570
|
+
getCommandSkeleton,
|
|
4571
|
+
getCursorWhenDelete,
|
|
3001
4572
|
getDeleteSelection,
|
|
3002
4573
|
getDocObject,
|
|
3003
4574
|
getDocObjectById,
|
|
4575
|
+
getEmptyTableCell,
|
|
4576
|
+
getEmptyTableRow,
|
|
3004
4577
|
getInsertSelection,
|
|
4578
|
+
getParagraphsInRange$1 as getParagraphsInRange,
|
|
4579
|
+
getParagraphsInRanges,
|
|
3005
4580
|
getPlainTextFormDocument,
|
|
3006
4581
|
getRetainAndDeleteFromReplace,
|
|
3007
4582
|
getRichTextEditPath,
|
|
3008
4583
|
getSelectionText,
|
|
4584
|
+
getTableColumn,
|
|
3009
4585
|
isSegmentIntersects,
|
|
4586
|
+
makeSelection,
|
|
3010
4587
|
neoGetDocObject,
|
|
3011
4588
|
replaceSelectionFactory,
|
|
3012
|
-
|
|
4589
|
+
serializeDocRange
|
|
3013
4590
|
};
|