@univerjs/docs 0.2.6 → 0.2.7
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 +2004 -432
- package/lib/types/basics/custom-decoration-factory.d.ts +1 -1
- package/lib/types/basics/custom-range.d.ts +2 -1
- package/lib/types/basics/selection.d.ts +2 -5
- package/lib/types/basics/table.d.ts +19 -0
- package/lib/types/commands/commands/__tests__/mock-text-selection-render-manager.d.ts +2 -2
- package/lib/types/commands/commands/auto-format.command.d.ts +8 -0
- package/lib/types/commands/commands/break-line.command.d.ts +2 -1
- package/lib/types/commands/commands/clipboard.inner.command.d.ts +2 -2
- package/lib/types/commands/commands/delete.command.d.ts +3 -2
- package/lib/types/commands/commands/inline-format.command.d.ts +0 -1
- package/lib/types/commands/commands/list.command.d.ts +28 -2
- package/lib/types/commands/commands/table/doc-table-create.command.d.ts +11 -0
- package/lib/types/commands/commands/table/doc-table-delete.command.d.ts +11 -0
- package/lib/types/commands/commands/table/doc-table-insert.command.d.ts +35 -0
- package/lib/types/commands/commands/table/doc-table-tab.command.d.ts +8 -0
- package/lib/types/commands/commands/table/table.d.ts +85 -0
- package/lib/types/controllers/ime-input.controller.d.ts +3 -1
- package/lib/types/index.d.ts +23 -7
- package/lib/types/services/doc-auto-format.service.d.ts +38 -0
- package/lib/types/services/text-selection-manager.service.d.ts +14 -11
- package/lib/umd/index.js +4 -1
- package/package.json +8 -7
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, DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
|
|
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, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, 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_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();
|
|
@@ -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
|
}), {
|
|
@@ -594,10 +1093,10 @@ function isSegmentIntersects(start, end, start2, end2) {
|
|
|
594
1093
|
}
|
|
595
1094
|
__name(isSegmentIntersects, "isSegmentIntersects");
|
|
596
1095
|
function getRetainAndDeleteAndExcludeLineBreak(selection, body, segmentId = "", memoryCursor = 0) {
|
|
597
|
-
var
|
|
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({
|
|
@@ -631,11 +1130,11 @@ function getRetainAndDeleteAndExcludeLineBreak(selection, body, segmentId = "",
|
|
|
631
1130
|
}
|
|
632
1131
|
__name(getRetainAndDeleteAndExcludeLineBreak, "getRetainAndDeleteAndExcludeLineBreak");
|
|
633
1132
|
function replaceSelectionFactory(accessor, params) {
|
|
634
|
-
var
|
|
1133
|
+
var _a11, _b;
|
|
635
1134
|
const { unitId, body: insertBody } = params, docDataModel = accessor.get(IUniverInstanceService).getUnit(unitId), textSelectionManagerService = accessor.get(TextSelectionManagerService);
|
|
636
1135
|
if (!docDataModel)
|
|
637
1136
|
return !1;
|
|
638
|
-
const body = docDataModel.getBody(), selection = (
|
|
1137
|
+
const body = docDataModel.getBody(), selection = (_a11 = params.selection) != null ? _a11 : textSelectionManagerService.getActiveTextRangeWithStyle();
|
|
639
1138
|
if (!selection || !body)
|
|
640
1139
|
return !1;
|
|
641
1140
|
const textRanges = (_b = params.textRanges) != null ? _b : [{
|
|
@@ -720,8 +1219,8 @@ const _DocCustomRangeService = class _DocCustomRangeService {
|
|
|
720
1219
|
__name(_DocCustomRangeService, "DocCustomRangeService");
|
|
721
1220
|
let DocCustomRangeService = _DocCustomRangeService;
|
|
722
1221
|
function getRetainAndDeleteFromReplace(range, segmentId = "", memoryCursor, body) {
|
|
723
|
-
var
|
|
724
|
-
const { startOffset, endOffset } = range, dos = [], textStart = startOffset - memoryCursor, textEnd = endOffset - memoryCursor, dataStream = body.dataStream, relativeCustomRanges = (
|
|
1222
|
+
var _a11;
|
|
1223
|
+
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
1224
|
relativeCustomRanges == null || relativeCustomRanges.forEach((range2) => {
|
|
726
1225
|
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
1226
|
}), textStart > 0 && dos.push({
|
|
@@ -755,34 +1254,16 @@ function getRetainAndDeleteFromReplace(range, segmentId = "", memoryCursor, body
|
|
|
755
1254
|
};
|
|
756
1255
|
}
|
|
757
1256
|
__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
1257
|
const EditorInsertTextCommandId = "doc.command.insert-text", InsertCommand = {
|
|
777
1258
|
id: EditorInsertTextCommandId,
|
|
778
1259
|
type: CommandType.COMMAND,
|
|
779
1260
|
// eslint-disable-next-line max-lines-per-function
|
|
780
1261
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
781
|
-
var
|
|
1262
|
+
var _a11;
|
|
782
1263
|
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
1264
|
if (docDataModel == null)
|
|
784
1265
|
return !1;
|
|
785
|
-
const activeRange = textSelectionManagerService.
|
|
1266
|
+
const activeRange = textSelectionManagerService.getActiveTextRangeWithStyle(), originBody = docDataModel.getSelfOrHeaderFooterModel((_a11 = activeRange == null ? void 0 : activeRange.segmentId) != null ? _a11 : "").getBody();
|
|
786
1267
|
if (!originBody)
|
|
787
1268
|
return !1;
|
|
788
1269
|
const actualRange = getInsertSelection(range, originBody), { startOffset, collapsed } = actualRange, cursorMove = cursorOffset != null ? cursorOffset : body.dataStream.length, textRanges = [
|
|
@@ -829,11 +1310,11 @@ const EditorInsertTextCommandId = "doc.command.insert-text", InsertCommand = {
|
|
|
829
1310
|
id: "doc.command.delete-text",
|
|
830
1311
|
type: CommandType.COMMAND,
|
|
831
1312
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
832
|
-
var
|
|
1313
|
+
var _a11;
|
|
833
1314
|
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
1315
|
if (docDataModel == null || body == null)
|
|
835
1316
|
return !1;
|
|
836
|
-
const { startOffset } = range, dataStream = body.dataStream, start = direction === DeleteDirection.LEFT ? startOffset - len : startOffset, end = start + len - 1, relativeCustomRanges = (
|
|
1317
|
+
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
1318
|
for (let i = 0; i < len; i++)
|
|
838
1319
|
deleteIndexes.push(start + i);
|
|
839
1320
|
toDeleteRanges == null || toDeleteRanges.forEach((range2) => {
|
|
@@ -900,6 +1381,7 @@ const EditorInsertTextCommandId = "doc.command.insert-text", InsertCommand = {
|
|
|
900
1381
|
}, "handler")
|
|
901
1382
|
};
|
|
902
1383
|
function generateParagraphs(dataStream, prevParagraph) {
|
|
1384
|
+
var _a11, _b;
|
|
903
1385
|
const paragraphs = [];
|
|
904
1386
|
for (let i = 0, len = dataStream.length; i < len; i++)
|
|
905
1387
|
dataStream[i] === DataStreamTreeTokenType.PARAGRAPH && paragraphs.push({
|
|
@@ -907,7 +1389,9 @@ function generateParagraphs(dataStream, prevParagraph) {
|
|
|
907
1389
|
});
|
|
908
1390
|
if (prevParagraph)
|
|
909
1391
|
for (const paragraph of paragraphs)
|
|
910
|
-
prevParagraph.bullet && (paragraph.bullet = Tools.deepClone(prevParagraph.bullet)), prevParagraph.paragraphStyle && (paragraph.paragraphStyle = Tools.deepClone(prevParagraph.paragraphStyle))
|
|
1392
|
+
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 = {
|
|
1393
|
+
s: BooleanNumber.FALSE
|
|
1394
|
+
}));
|
|
911
1395
|
return paragraphs;
|
|
912
1396
|
}
|
|
913
1397
|
__name(generateParagraphs, "generateParagraphs");
|
|
@@ -915,20 +1399,27 @@ const BreakLineCommand = {
|
|
|
915
1399
|
id: "doc.command.break-line",
|
|
916
1400
|
type: CommandType.COMMAND,
|
|
917
1401
|
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 (
|
|
1402
|
+
var _a11, _b;
|
|
1403
|
+
const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), customRangeService = accessor.get(DocCustomRangeService), activeTextRange = textSelectionManagerService.getActiveTextRangeWithStyle(), rectRanges = textSelectionManagerService.getCurrentRectRanges();
|
|
1404
|
+
if (activeTextRange == null)
|
|
921
1405
|
return !1;
|
|
922
|
-
|
|
1406
|
+
if (rectRanges && rectRanges.length) {
|
|
1407
|
+
const { startOffset: startOffset2 } = activeTextRange;
|
|
1408
|
+
return textSelectionManagerService.replaceTextRanges([{
|
|
1409
|
+
startOffset: startOffset2,
|
|
1410
|
+
endOffset: startOffset2
|
|
1411
|
+
}]), !0;
|
|
1412
|
+
}
|
|
1413
|
+
const { segmentId } = activeTextRange, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), body = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
923
1414
|
if (!docDataModel || !body)
|
|
924
1415
|
return !1;
|
|
925
|
-
const unitId = docDataModel.getUnitId(), { startOffset, endOffset } = getInsertSelection(
|
|
1416
|
+
const unitId = docDataModel.getUnitId(), { startOffset, endOffset } = getInsertSelection(activeTextRange, body), prevParagraph = ((_a11 = body.paragraphs) != null ? _a11 : []).find((p) => p.startIndex >= startOffset);
|
|
926
1417
|
if (prevParagraph && prevParagraph.startIndex > endOffset) {
|
|
927
|
-
const bodyAfter = normalizeBody(getBodySlice(body, endOffset, prevParagraph.startIndex));
|
|
1418
|
+
const bodyAfter = normalizeBody(getBodySlice(body, endOffset, prevParagraph.startIndex + 1));
|
|
928
1419
|
bodyAfter.customRanges = (_b = bodyAfter.customRanges) == null ? void 0 : _b.map((range) => customRangeService.copyCustomRange(unitId, range));
|
|
929
1420
|
const deleteRange = {
|
|
930
1421
|
startOffset,
|
|
931
|
-
endOffset: prevParagraph.startIndex,
|
|
1422
|
+
endOffset: prevParagraph.startIndex + 1,
|
|
932
1423
|
collapsed: !1
|
|
933
1424
|
};
|
|
934
1425
|
return updateAttributeByInsert(
|
|
@@ -953,16 +1444,447 @@ const BreakLineCommand = {
|
|
|
953
1444
|
dataStream: DataStreamTreeTokenType.PARAGRAPH,
|
|
954
1445
|
paragraphs: generateParagraphs(DataStreamTreeTokenType.PARAGRAPH, prevParagraph)
|
|
955
1446
|
},
|
|
956
|
-
range:
|
|
1447
|
+
range: activeTextRange,
|
|
957
1448
|
segmentId
|
|
958
1449
|
});
|
|
959
1450
|
}, "handler")
|
|
960
|
-
}
|
|
1451
|
+
};
|
|
1452
|
+
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 || {});
|
|
1453
|
+
function genEmptyTable(rowCount, colCount) {
|
|
1454
|
+
let dataStream = DataStreamTreeTokenType.TABLE_START;
|
|
1455
|
+
const paragraphs = [], sectionBreaks = [];
|
|
1456
|
+
for (let i = 0; i < rowCount; i++) {
|
|
1457
|
+
dataStream += DataStreamTreeTokenType.TABLE_ROW_START;
|
|
1458
|
+
for (let j = 0; j < colCount; j++)
|
|
1459
|
+
dataStream += `${DataStreamTreeTokenType.TABLE_CELL_START}\r
|
|
1460
|
+
${DataStreamTreeTokenType.TABLE_CELL_END}`, paragraphs.push({
|
|
1461
|
+
startIndex: dataStream.length - 3,
|
|
1462
|
+
paragraphStyle: {
|
|
1463
|
+
spaceAbove: { v: 3 },
|
|
1464
|
+
lineSpacing: 2,
|
|
1465
|
+
spaceBelow: { v: 0 }
|
|
1466
|
+
}
|
|
1467
|
+
}), sectionBreaks.push({
|
|
1468
|
+
startIndex: dataStream.length - 2
|
|
1469
|
+
});
|
|
1470
|
+
dataStream += DataStreamTreeTokenType.TABLE_ROW_END;
|
|
1471
|
+
}
|
|
1472
|
+
return dataStream += DataStreamTreeTokenType.TABLE_END, {
|
|
1473
|
+
dataStream,
|
|
1474
|
+
paragraphs,
|
|
1475
|
+
sectionBreaks
|
|
1476
|
+
};
|
|
1477
|
+
}
|
|
1478
|
+
__name(genEmptyTable, "genEmptyTable");
|
|
1479
|
+
function getEmptyTableCell() {
|
|
1480
|
+
return {
|
|
1481
|
+
margin: {
|
|
1482
|
+
start: {
|
|
1483
|
+
v: 10
|
|
1484
|
+
},
|
|
1485
|
+
end: {
|
|
1486
|
+
v: 10
|
|
1487
|
+
},
|
|
1488
|
+
top: {
|
|
1489
|
+
v: 5
|
|
1490
|
+
},
|
|
1491
|
+
bottom: {
|
|
1492
|
+
v: 5
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
};
|
|
1496
|
+
}
|
|
1497
|
+
__name(getEmptyTableCell, "getEmptyTableCell");
|
|
1498
|
+
function getEmptyTableRow(col) {
|
|
1499
|
+
const tableCell = getEmptyTableCell();
|
|
1500
|
+
return {
|
|
1501
|
+
tableCells: [...new Array(col).fill(null).map(() => Tools.deepClone(tableCell))],
|
|
1502
|
+
trHeight: {
|
|
1503
|
+
val: { v: 30 },
|
|
1504
|
+
hRule: TableCellHeightRule.AUTO
|
|
1505
|
+
}
|
|
1506
|
+
};
|
|
1507
|
+
}
|
|
1508
|
+
__name(getEmptyTableRow, "getEmptyTableRow");
|
|
1509
|
+
function getTableColumn(width) {
|
|
1510
|
+
return {
|
|
1511
|
+
size: {
|
|
1512
|
+
type: TableSizeType.SPECIFIED,
|
|
1513
|
+
width: {
|
|
1514
|
+
v: width
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
};
|
|
1518
|
+
}
|
|
1519
|
+
__name(getTableColumn, "getTableColumn");
|
|
1520
|
+
function genTableSource(rowCount, colCount, pageContentWidth) {
|
|
1521
|
+
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);
|
|
1522
|
+
return {
|
|
1523
|
+
tableRows,
|
|
1524
|
+
tableColumns,
|
|
1525
|
+
tableId,
|
|
1526
|
+
align: TableAlignmentType.START,
|
|
1527
|
+
indent: {
|
|
1528
|
+
v: 0
|
|
1529
|
+
},
|
|
1530
|
+
textWrap: TableTextWrapType.NONE,
|
|
1531
|
+
position: {
|
|
1532
|
+
positionH: {
|
|
1533
|
+
relativeFrom: ObjectRelativeFromH.PAGE,
|
|
1534
|
+
posOffset: 0
|
|
1535
|
+
},
|
|
1536
|
+
positionV: {
|
|
1537
|
+
relativeFrom: ObjectRelativeFromV.PAGE,
|
|
1538
|
+
posOffset: 0
|
|
1539
|
+
}
|
|
1540
|
+
},
|
|
1541
|
+
dist: {
|
|
1542
|
+
distB: 0,
|
|
1543
|
+
distL: 0,
|
|
1544
|
+
distR: 0,
|
|
1545
|
+
distT: 0
|
|
1546
|
+
},
|
|
1547
|
+
cellMargin: {
|
|
1548
|
+
start: {
|
|
1549
|
+
v: 10
|
|
1550
|
+
},
|
|
1551
|
+
end: {
|
|
1552
|
+
v: 10
|
|
1553
|
+
},
|
|
1554
|
+
top: {
|
|
1555
|
+
v: 5
|
|
1556
|
+
},
|
|
1557
|
+
bottom: {
|
|
1558
|
+
v: 5
|
|
1559
|
+
}
|
|
1560
|
+
},
|
|
1561
|
+
size: {
|
|
1562
|
+
type: TableSizeType.UNSPECIFIED,
|
|
1563
|
+
width: {
|
|
1564
|
+
v: pageContentWidth
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
__name(genTableSource, "genTableSource");
|
|
1570
|
+
function getRangeInfoFromRanges(textRange, rectRanges) {
|
|
1571
|
+
if (!textRange && !rectRanges)
|
|
1572
|
+
return null;
|
|
1573
|
+
if (rectRanges && rectRanges.length > 0) {
|
|
1574
|
+
let startOffset = Number.POSITIVE_INFINITY, endOffset = Number.NEGATIVE_INFINITY;
|
|
1575
|
+
const segmentId = "";
|
|
1576
|
+
for (const rectRange of rectRanges) {
|
|
1577
|
+
const { startOffset: st, endOffset: ed, segmentId: sid } = rectRange;
|
|
1578
|
+
st == null || ed == null || sid == null || (startOffset = Math.min(startOffset, st), endOffset = Math.max(endOffset, ed));
|
|
1579
|
+
}
|
|
1580
|
+
if (Number.isFinite(startOffset) && Number.isFinite(endOffset))
|
|
1581
|
+
return {
|
|
1582
|
+
startOffset,
|
|
1583
|
+
endOffset,
|
|
1584
|
+
segmentId
|
|
1585
|
+
};
|
|
1586
|
+
} else if (textRange) {
|
|
1587
|
+
const { startOffset, endOffset, segmentId } = textRange;
|
|
1588
|
+
return startOffset == null || endOffset == null || segmentId == null ? null : {
|
|
1589
|
+
startOffset,
|
|
1590
|
+
endOffset,
|
|
1591
|
+
segmentId
|
|
1592
|
+
};
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
__name(getRangeInfoFromRanges, "getRangeInfoFromRanges");
|
|
1596
|
+
function getInsertRowBody(col) {
|
|
1597
|
+
let dataStream = DataStreamTreeTokenType.TABLE_ROW_START;
|
|
1598
|
+
const paragraphs = [], sectionBreaks = [];
|
|
1599
|
+
for (let i = 0; i < col; i++)
|
|
1600
|
+
dataStream += `${DataStreamTreeTokenType.TABLE_CELL_START}\r
|
|
1601
|
+
${DataStreamTreeTokenType.TABLE_CELL_END}`, paragraphs.push({
|
|
1602
|
+
startIndex: dataStream.length - 2,
|
|
1603
|
+
paragraphStyle: {
|
|
1604
|
+
spaceAbove: { v: 3 },
|
|
1605
|
+
lineSpacing: 2,
|
|
1606
|
+
spaceBelow: { v: 0 }
|
|
1607
|
+
}
|
|
1608
|
+
}), sectionBreaks.push({
|
|
1609
|
+
startIndex: dataStream.length - 1
|
|
1610
|
+
});
|
|
1611
|
+
return dataStream += DataStreamTreeTokenType.TABLE_ROW_END, {
|
|
1612
|
+
dataStream,
|
|
1613
|
+
paragraphs,
|
|
1614
|
+
sectionBreaks
|
|
1615
|
+
};
|
|
1616
|
+
}
|
|
1617
|
+
__name(getInsertRowBody, "getInsertRowBody");
|
|
1618
|
+
function getInsertColumnBody() {
|
|
1619
|
+
const dataStream = `${DataStreamTreeTokenType.TABLE_CELL_START}\r
|
|
1620
|
+
${DataStreamTreeTokenType.TABLE_CELL_END}`, paragraphs = [], sectionBreaks = [];
|
|
1621
|
+
return paragraphs.push({
|
|
1622
|
+
startIndex: 1,
|
|
1623
|
+
paragraphStyle: {
|
|
1624
|
+
spaceAbove: { v: 3 },
|
|
1625
|
+
lineSpacing: 2,
|
|
1626
|
+
spaceBelow: { v: 0 }
|
|
1627
|
+
}
|
|
1628
|
+
}), sectionBreaks.push({
|
|
1629
|
+
startIndex: 2
|
|
1630
|
+
}), {
|
|
1631
|
+
dataStream,
|
|
1632
|
+
paragraphs,
|
|
1633
|
+
sectionBreaks
|
|
1634
|
+
};
|
|
1635
|
+
}
|
|
1636
|
+
__name(getInsertColumnBody, "getInsertColumnBody");
|
|
1637
|
+
function getInsertRowActionsParams(rangeInfo, position, viewModel) {
|
|
1638
|
+
var _a11, _b, _c;
|
|
1639
|
+
const { startOffset, endOffset, segmentId } = rangeInfo, vm = viewModel.getSelfOrHeaderFooterViewModel(segmentId), index = position === 0 ? startOffset : endOffset;
|
|
1640
|
+
let tableRow = null;
|
|
1641
|
+
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;
|
|
1642
|
+
let rowIndex = 0;
|
|
1643
|
+
for (const section of vm.children) {
|
|
1644
|
+
for (const paragraph of section.children) {
|
|
1645
|
+
const { children } = paragraph, table = children[0];
|
|
1646
|
+
if (table) {
|
|
1647
|
+
for (const row of table.children)
|
|
1648
|
+
if (row.startIndex <= index && index <= row.endIndex) {
|
|
1649
|
+
rowIndex = table.children.indexOf(row), tableRow = row;
|
|
1650
|
+
break;
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
if (tableRow)
|
|
1654
|
+
break;
|
|
1655
|
+
}
|
|
1656
|
+
if (tableRow)
|
|
1657
|
+
break;
|
|
1658
|
+
}
|
|
1659
|
+
return tableRow == null || tableId == null ? null : {
|
|
1660
|
+
offset: position === 0 ? tableRow.startIndex : tableRow.endIndex + 1,
|
|
1661
|
+
colCount: tableRow.children.length,
|
|
1662
|
+
tableId,
|
|
1663
|
+
insertRowIndex: position === 0 ? rowIndex : rowIndex + 1
|
|
1664
|
+
};
|
|
1665
|
+
}
|
|
1666
|
+
__name(getInsertRowActionsParams, "getInsertRowActionsParams");
|
|
1667
|
+
function getInsertColumnActionsParams(rangeInfo, position, viewModel) {
|
|
1668
|
+
var _a11, _b, _c;
|
|
1669
|
+
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 = [];
|
|
1670
|
+
let table = null, columnIndex = -1;
|
|
1671
|
+
for (const section of vm.children) {
|
|
1672
|
+
for (const paragraph of section.children) {
|
|
1673
|
+
const { children } = paragraph, tableNode = children[0];
|
|
1674
|
+
if (tableNode) {
|
|
1675
|
+
if (index < tableNode.startIndex || index > tableNode.endIndex)
|
|
1676
|
+
continue;
|
|
1677
|
+
table = tableNode;
|
|
1678
|
+
for (const row of tableNode.children) {
|
|
1679
|
+
for (const cell of row.children) {
|
|
1680
|
+
const cellIndex = row.children.indexOf(cell);
|
|
1681
|
+
if (index >= cell.startIndex && index <= cell.endIndex) {
|
|
1682
|
+
columnIndex = cellIndex;
|
|
1683
|
+
break;
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
if (columnIndex !== -1)
|
|
1687
|
+
break;
|
|
1688
|
+
}
|
|
1689
|
+
}
|
|
1690
|
+
if (table)
|
|
1691
|
+
break;
|
|
1692
|
+
}
|
|
1693
|
+
if (table)
|
|
1694
|
+
break;
|
|
1695
|
+
}
|
|
1696
|
+
if (table == null || tableId == null || columnIndex === -1)
|
|
1697
|
+
return null;
|
|
1698
|
+
let cursor = 0;
|
|
1699
|
+
for (const row of table.children) {
|
|
1700
|
+
const cell = row.children[columnIndex], insertIndex = position === 0 ? cell.startIndex : cell.endIndex + 1;
|
|
1701
|
+
offsets.push(insertIndex - cursor), cursor = insertIndex;
|
|
1702
|
+
}
|
|
1703
|
+
return {
|
|
1704
|
+
offsets,
|
|
1705
|
+
tableId,
|
|
1706
|
+
columnIndex,
|
|
1707
|
+
rowCount: table.children.length
|
|
1708
|
+
};
|
|
1709
|
+
}
|
|
1710
|
+
__name(getInsertColumnActionsParams, "getInsertColumnActionsParams");
|
|
1711
|
+
function getColumnWidths(pageWidth, tableColumns, insertColumnIndex) {
|
|
1712
|
+
const widths = [];
|
|
1713
|
+
let newColWidth = tableColumns[insertColumnIndex].size.width.v, totalWidth = 0;
|
|
1714
|
+
for (let i = 0; i < tableColumns.length; i++)
|
|
1715
|
+
totalWidth += tableColumns[i].size.width.v;
|
|
1716
|
+
totalWidth += newColWidth;
|
|
1717
|
+
for (let i = 0; i < tableColumns.length; i++)
|
|
1718
|
+
widths.push(tableColumns[i].size.width.v / totalWidth * pageWidth);
|
|
1719
|
+
return newColWidth = newColWidth / totalWidth * pageWidth, {
|
|
1720
|
+
widths,
|
|
1721
|
+
newColWidth
|
|
1722
|
+
};
|
|
1723
|
+
}
|
|
1724
|
+
__name(getColumnWidths, "getColumnWidths");
|
|
1725
|
+
function getDeleteRowsActionsParams(rangeInfo, viewModel) {
|
|
1726
|
+
var _a11, _b, _c;
|
|
1727
|
+
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 = [];
|
|
1728
|
+
let offset = -1, len = 0, cursor = -1, selectWholeTable = !1;
|
|
1729
|
+
for (const section of vm.children) {
|
|
1730
|
+
for (const paragraph of section.children) {
|
|
1731
|
+
const { children } = paragraph, table = children[0];
|
|
1732
|
+
if (table) {
|
|
1733
|
+
if (startOffset < table.startIndex || endOffset > table.endIndex)
|
|
1734
|
+
continue;
|
|
1735
|
+
cursor = table.startIndex + 3;
|
|
1736
|
+
for (const row of table.children) {
|
|
1737
|
+
const rowIndex = table.children.indexOf(row), { startIndex, endIndex } = row;
|
|
1738
|
+
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);
|
|
1739
|
+
}
|
|
1740
|
+
}
|
|
1741
|
+
if (rowIndexes.length)
|
|
1742
|
+
break;
|
|
1743
|
+
}
|
|
1744
|
+
if (rowIndexes.length)
|
|
1745
|
+
break;
|
|
1746
|
+
}
|
|
1747
|
+
return tableId == null || rowIndexes.length === 0 ? null : {
|
|
1748
|
+
tableId,
|
|
1749
|
+
rowIndexes,
|
|
1750
|
+
offset,
|
|
1751
|
+
len,
|
|
1752
|
+
cursor,
|
|
1753
|
+
selectWholeTable
|
|
1754
|
+
};
|
|
1755
|
+
}
|
|
1756
|
+
__name(getDeleteRowsActionsParams, "getDeleteRowsActionsParams");
|
|
1757
|
+
function getDeleteColumnsActionParams(rangeInfo, viewModel) {
|
|
1758
|
+
var _a11, _b, _c;
|
|
1759
|
+
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 = [];
|
|
1760
|
+
let table = null;
|
|
1761
|
+
const columnIndexes = [];
|
|
1762
|
+
let cursor = -1, startColumnIndex = -1, endColumnIndex = -1;
|
|
1763
|
+
for (const section of vm.children) {
|
|
1764
|
+
for (const paragraph of section.children) {
|
|
1765
|
+
const { children } = paragraph, tableNode = children[0];
|
|
1766
|
+
if (tableNode) {
|
|
1767
|
+
if (startOffset < tableNode.startIndex || endOffset > tableNode.endIndex)
|
|
1768
|
+
continue;
|
|
1769
|
+
table = tableNode;
|
|
1770
|
+
for (const row of tableNode.children)
|
|
1771
|
+
for (const cell of row.children) {
|
|
1772
|
+
const cellIndex = row.children.indexOf(cell);
|
|
1773
|
+
startOffset >= cell.startIndex && startOffset <= cell.endIndex && (startColumnIndex = cellIndex), endOffset >= cell.startIndex && endOffset <= cell.endIndex && (endColumnIndex = cellIndex);
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
if (table)
|
|
1777
|
+
break;
|
|
1778
|
+
}
|
|
1779
|
+
if (table)
|
|
1780
|
+
break;
|
|
1781
|
+
}
|
|
1782
|
+
if (table == null || tableId == null)
|
|
1783
|
+
return null;
|
|
1784
|
+
for (let i = startColumnIndex; i <= endColumnIndex; i++)
|
|
1785
|
+
columnIndexes.push(i);
|
|
1786
|
+
let delta = 0;
|
|
1787
|
+
for (const row of table.children) {
|
|
1788
|
+
const startCell = row.children[startColumnIndex], endCell = row.children[endColumnIndex];
|
|
1789
|
+
offsets.push({
|
|
1790
|
+
retain: startCell.startIndex - delta,
|
|
1791
|
+
delete: endCell.endIndex - startCell.startIndex + 1
|
|
1792
|
+
}), delta = endCell.endIndex + 1;
|
|
1793
|
+
}
|
|
1794
|
+
return cursor = table.startIndex + 3, {
|
|
1795
|
+
offsets,
|
|
1796
|
+
tableId,
|
|
1797
|
+
columnIndexes,
|
|
1798
|
+
cursor,
|
|
1799
|
+
selectWholeTable: columnIndexes.length === table.children[0].children.length,
|
|
1800
|
+
rowCount: table.children.length
|
|
1801
|
+
};
|
|
1802
|
+
}
|
|
1803
|
+
__name(getDeleteColumnsActionParams, "getDeleteColumnsActionParams");
|
|
1804
|
+
function getDeleteTableActionParams(rangeInfo, viewModel) {
|
|
1805
|
+
var _a11, _b, _c;
|
|
1806
|
+
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;
|
|
1807
|
+
let offset = -1, len = 0, cursor = -1;
|
|
1808
|
+
for (const section of vm.children) {
|
|
1809
|
+
for (const paragraph of section.children) {
|
|
1810
|
+
const { children } = paragraph, table = children[0];
|
|
1811
|
+
if (table) {
|
|
1812
|
+
if (startOffset < table.startIndex || endOffset > table.endIndex)
|
|
1813
|
+
continue;
|
|
1814
|
+
offset = table.startIndex, len = table.endIndex - table.startIndex + 1, cursor = table.startIndex;
|
|
1815
|
+
}
|
|
1816
|
+
if (table)
|
|
1817
|
+
break;
|
|
1818
|
+
}
|
|
1819
|
+
if (len > 0)
|
|
1820
|
+
break;
|
|
1821
|
+
}
|
|
1822
|
+
return tableId == null ? null : {
|
|
1823
|
+
tableId,
|
|
1824
|
+
offset,
|
|
1825
|
+
len,
|
|
1826
|
+
cursor
|
|
1827
|
+
};
|
|
1828
|
+
}
|
|
1829
|
+
__name(getDeleteTableActionParams, "getDeleteTableActionParams");
|
|
1830
|
+
function getDeleteRowContentActionParams(rangeInfo, viewModel) {
|
|
1831
|
+
var _a11, _b, _c;
|
|
1832
|
+
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 = [];
|
|
1833
|
+
let table = null, cursor = -1, rowIndex = -1, startColumnIndex = -1, endColumnIndex = -1;
|
|
1834
|
+
for (const section of vm.children) {
|
|
1835
|
+
for (const paragraph of section.children) {
|
|
1836
|
+
const { children } = paragraph, tableNode = children[0];
|
|
1837
|
+
if (tableNode) {
|
|
1838
|
+
if (startOffset < tableNode.startIndex || endOffset > tableNode.endIndex)
|
|
1839
|
+
continue;
|
|
1840
|
+
table = tableNode;
|
|
1841
|
+
for (const row2 of tableNode.children) {
|
|
1842
|
+
const rIndex = tableNode.children.indexOf(row2);
|
|
1843
|
+
for (const cell of row2.children) {
|
|
1844
|
+
const cellIndex = row2.children.indexOf(cell);
|
|
1845
|
+
startOffset >= cell.startIndex && startOffset <= cell.endIndex && (rowIndex = rIndex, startColumnIndex = cellIndex), endOffset >= cell.startIndex && endOffset <= cell.endIndex && (endColumnIndex = cellIndex);
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
if (table)
|
|
1850
|
+
break;
|
|
1851
|
+
}
|
|
1852
|
+
if (table)
|
|
1853
|
+
break;
|
|
1854
|
+
}
|
|
1855
|
+
if (table == null || tableId == null || rowIndex === -1)
|
|
1856
|
+
return null;
|
|
1857
|
+
const row = table.children[rowIndex];
|
|
1858
|
+
for (let i = startColumnIndex; i <= endColumnIndex; i++) {
|
|
1859
|
+
const cell = row.children[i];
|
|
1860
|
+
offsets.push({
|
|
1861
|
+
retain: cell.startIndex + 1,
|
|
1862
|
+
delete: cell.endIndex - cell.startIndex - 3
|
|
1863
|
+
});
|
|
1864
|
+
}
|
|
1865
|
+
return cursor = table.startIndex + 3, {
|
|
1866
|
+
offsets,
|
|
1867
|
+
tableId,
|
|
1868
|
+
cursor,
|
|
1869
|
+
rowCount: table.children.length
|
|
1870
|
+
};
|
|
1871
|
+
}
|
|
1872
|
+
__name(getDeleteRowContentActionParams, "getDeleteRowContentActionParams");
|
|
1873
|
+
function hasRangeInTable(ranges) {
|
|
1874
|
+
return ranges.some((range) => {
|
|
1875
|
+
const { anchorNodePosition } = range;
|
|
1876
|
+
return anchorNodePosition ? (anchorNodePosition == null ? void 0 : anchorNodePosition.path.indexOf("cells")) > -1 : !1;
|
|
1877
|
+
});
|
|
1878
|
+
}
|
|
1879
|
+
__name(hasRangeInTable, "hasRangeInTable");
|
|
1880
|
+
const InnerPasteCommand = {
|
|
961
1881
|
id: "doc.command.inner-paste",
|
|
962
1882
|
type: CommandType.COMMAND,
|
|
1883
|
+
// eslint-disable-next-line max-lines-per-function
|
|
963
1884
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
964
|
-
|
|
965
|
-
|
|
1885
|
+
var _a11;
|
|
1886
|
+
const { segmentId, textRanges, doc } = params, commandService = accessor.get(ICommandService), textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), selections = textSelectionManagerService.getCurrentTextRanges(), { body, tableSource } = doc;
|
|
1887
|
+
if (!Array.isArray(selections) || selections.length === 0 || body == null)
|
|
966
1888
|
return !1;
|
|
967
1889
|
const docDataModel = univerInstanceService.getCurrentUniverDocInstance(), originBody = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
968
1890
|
if (docDataModel == null || originBody == null)
|
|
@@ -976,9 +1898,20 @@ const BreakLineCommand = {
|
|
|
976
1898
|
}
|
|
977
1899
|
}, memoryCursor = new MemoryCursor();
|
|
978
1900
|
memoryCursor.reset();
|
|
979
|
-
const textX = new TextX(), jsonX = JSONX.getInstance();
|
|
1901
|
+
const textX = new TextX(), jsonX = JSONX.getInstance(), rawActions = [], hasTable = !!((_a11 = body.tables) != null && _a11.length);
|
|
1902
|
+
if (hasTable && segmentId || hasTable && hasRangeInTable(selections))
|
|
1903
|
+
return !1;
|
|
980
1904
|
for (const selection of selections) {
|
|
981
|
-
const { startOffset, endOffset, collapsed } = selection, len = startOffset - memoryCursor.cursor;
|
|
1905
|
+
const { startOffset, endOffset, collapsed } = selection, len = startOffset - memoryCursor.cursor, cloneBody = Tools.deepClone(body);
|
|
1906
|
+
if (hasTable)
|
|
1907
|
+
for (const t of cloneBody.tables) {
|
|
1908
|
+
const { tableId: oldTableId } = t, tableId = Tools.generateRandomId(6);
|
|
1909
|
+
t.tableId = tableId;
|
|
1910
|
+
const table = Tools.deepClone(tableSource[oldTableId]);
|
|
1911
|
+
table.tableId = tableId;
|
|
1912
|
+
const action = jsonX.insertOp(["tableSource", tableId], table);
|
|
1913
|
+
rawActions.push(action);
|
|
1914
|
+
}
|
|
982
1915
|
if (collapsed)
|
|
983
1916
|
textX.push({
|
|
984
1917
|
t: TextXActionType.RETAIN,
|
|
@@ -991,63 +1924,151 @@ const BreakLineCommand = {
|
|
|
991
1924
|
}
|
|
992
1925
|
textX.push({
|
|
993
1926
|
t: TextXActionType.INSERT,
|
|
994
|
-
body,
|
|
1927
|
+
body: cloneBody,
|
|
995
1928
|
len: body.dataStream.length,
|
|
996
1929
|
line: 0,
|
|
997
1930
|
segmentId
|
|
998
1931
|
}), memoryCursor.reset(), memoryCursor.moveCursor(endOffset);
|
|
999
1932
|
}
|
|
1000
1933
|
const path = getRichTextEditPath(docDataModel, segmentId);
|
|
1001
|
-
return doMutation.params.actions =
|
|
1934
|
+
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
1935
|
}, "handler")
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1936
|
+
};
|
|
1937
|
+
function getCutActionsFromTextRanges(selections, docDataModel, segmentId) {
|
|
1938
|
+
var _a11, _b;
|
|
1939
|
+
const originBody = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody(), textX = new TextX(), jsonX = JSONX.getInstance(), rawActions = [];
|
|
1940
|
+
if (originBody == null)
|
|
1941
|
+
return rawActions;
|
|
1942
|
+
const memoryCursor = new MemoryCursor();
|
|
1943
|
+
memoryCursor.reset();
|
|
1944
|
+
for (const selection of selections) {
|
|
1945
|
+
const { startOffset, endOffset, collapsed } = selection;
|
|
1946
|
+
if (startOffset == null || endOffset == null)
|
|
1947
|
+
continue;
|
|
1948
|
+
const len = startOffset - memoryCursor.cursor;
|
|
1949
|
+
collapsed ? textX.push({
|
|
1950
|
+
t: TextXActionType.RETAIN,
|
|
1951
|
+
len,
|
|
1952
|
+
segmentId
|
|
1953
|
+
}) : textX.push(...getRetainAndDeleteAndExcludeLineBreak(selection, originBody, segmentId, memoryCursor.cursor)), memoryCursor.reset(), memoryCursor.moveCursor(endOffset);
|
|
1954
|
+
}
|
|
1955
|
+
const path = getRichTextEditPath(docDataModel, segmentId);
|
|
1956
|
+
rawActions.push(jsonX.editOp(textX.serialize(), path));
|
|
1957
|
+
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);
|
|
1958
|
+
if (sortedRemovedCustomBlockIds.length > 0)
|
|
1959
|
+
for (const blockId of sortedRemovedCustomBlockIds) {
|
|
1960
|
+
const drawing = drawings[blockId], drawingIndex = drawingOrder.indexOf(blockId);
|
|
1961
|
+
if (drawing == null || drawingIndex < 0)
|
|
1962
|
+
continue;
|
|
1963
|
+
const removeDrawingAction = jsonX.removeOp(["drawings", blockId], drawing), removeDrawingOrderAction = jsonX.removeOp(["drawingsOrder", drawingIndex], blockId);
|
|
1964
|
+
rawActions.push(removeDrawingAction), rawActions.push(removeDrawingOrderAction);
|
|
1965
|
+
}
|
|
1966
|
+
return rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null);
|
|
1967
|
+
}
|
|
1968
|
+
__name(getCutActionsFromTextRanges, "getCutActionsFromTextRanges");
|
|
1969
|
+
function getCutActionsFromRectRanges(ranges, docDataModel, viewModel, segmentId) {
|
|
1970
|
+
const rawActions = [];
|
|
1971
|
+
if (docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody() == null)
|
|
1972
|
+
return rawActions;
|
|
1973
|
+
const textX = new TextX(), jsonX = JSONX.getInstance(), memoryCursor = new MemoryCursor();
|
|
1974
|
+
memoryCursor.reset();
|
|
1975
|
+
for (const range of ranges) {
|
|
1976
|
+
const { startOffset, endOffset, spanEntireRow, spanEntireTable } = range;
|
|
1977
|
+
if (!(startOffset == null || endOffset == null))
|
|
1978
|
+
if (spanEntireTable) {
|
|
1979
|
+
const actionParams = getDeleteTableActionParams({ startOffset, endOffset, segmentId }, viewModel);
|
|
1980
|
+
if (actionParams == null)
|
|
1981
|
+
continue;
|
|
1982
|
+
const { offset, len, tableId } = actionParams;
|
|
1983
|
+
offset - memoryCursor.cursor > 0 && textX.push({
|
|
1984
|
+
t: TextXActionType.RETAIN,
|
|
1985
|
+
len: offset - memoryCursor.cursor,
|
|
1986
|
+
segmentId
|
|
1987
|
+
}), textX.push({
|
|
1988
|
+
t: TextXActionType.DELETE,
|
|
1989
|
+
len,
|
|
1990
|
+
line: 0,
|
|
1991
|
+
segmentId
|
|
1992
|
+
});
|
|
1993
|
+
const action = jsonX.removeOp(["tableSource", tableId]);
|
|
1994
|
+
rawActions.push(action), memoryCursor.moveCursorTo(offset + len);
|
|
1995
|
+
} else if (spanEntireRow) {
|
|
1996
|
+
const actionParams = getDeleteRowsActionsParams({ startOffset, endOffset, segmentId }, viewModel);
|
|
1997
|
+
if (actionParams == null)
|
|
1998
|
+
continue;
|
|
1999
|
+
const { offset, rowIndexes, len, tableId } = actionParams;
|
|
2000
|
+
offset - memoryCursor.cursor > 0 && textX.push({
|
|
2001
|
+
t: TextXActionType.RETAIN,
|
|
2002
|
+
len: offset - memoryCursor.cursor,
|
|
2003
|
+
segmentId
|
|
2004
|
+
}), textX.push({
|
|
2005
|
+
t: TextXActionType.DELETE,
|
|
2006
|
+
len,
|
|
2007
|
+
line: 0,
|
|
2008
|
+
segmentId
|
|
2009
|
+
});
|
|
2010
|
+
for (const index of rowIndexes.reverse()) {
|
|
2011
|
+
const action = jsonX.removeOp(["tableSource", tableId, "tableRows", index]);
|
|
2012
|
+
rawActions.push(action);
|
|
2013
|
+
}
|
|
2014
|
+
memoryCursor.moveCursorTo(offset + len);
|
|
2015
|
+
} else {
|
|
2016
|
+
const actionParams = getDeleteRowContentActionParams({ startOffset, endOffset, segmentId }, viewModel);
|
|
2017
|
+
if (actionParams == null)
|
|
2018
|
+
continue;
|
|
2019
|
+
const { offsets } = actionParams;
|
|
2020
|
+
for (const offset of offsets) {
|
|
2021
|
+
const { retain, delete: delLen } = offset;
|
|
2022
|
+
retain - memoryCursor.cursor > 0 && textX.push({
|
|
2023
|
+
t: TextXActionType.RETAIN,
|
|
2024
|
+
len: retain - memoryCursor.cursor,
|
|
2025
|
+
segmentId
|
|
2026
|
+
}), textX.push({
|
|
2027
|
+
t: TextXActionType.DELETE,
|
|
2028
|
+
len: delLen,
|
|
2029
|
+
line: 0,
|
|
2030
|
+
segmentId
|
|
2031
|
+
}), memoryCursor.moveCursorTo(retain + delLen);
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
const path = getRichTextEditPath(docDataModel, segmentId);
|
|
2036
|
+
return rawActions.push(jsonX.editOp(textX.serialize(), path)), rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null);
|
|
2037
|
+
}
|
|
2038
|
+
__name(getCutActionsFromRectRanges, "getCutActionsFromRectRanges");
|
|
2039
|
+
const INNER_CUT_COMMAND_ID = "doc.command.inner-cut", CutContentCommand = {
|
|
2040
|
+
id: INNER_CUT_COMMAND_ID,
|
|
1005
2041
|
type: CommandType.COMMAND,
|
|
1006
|
-
// eslint-disable-next-line max-lines-per-function
|
|
1007
2042
|
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)
|
|
2043
|
+
var _a11, _b, _c;
|
|
2044
|
+
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();
|
|
2045
|
+
if ((!Array.isArray(selections) || selections.length === 0) && (!Array.isArray(rectRanges) || rectRanges.length === 0))
|
|
1011
2046
|
return !1;
|
|
1012
2047
|
const unitId = (_b = univerInstanceService.getCurrentUniverDocInstance()) == null ? void 0 : _b.getUnitId();
|
|
1013
2048
|
if (!unitId)
|
|
1014
2049
|
return !1;
|
|
1015
|
-
const docDataModel = univerInstanceService.getUniverDocInstance(unitId)
|
|
1016
|
-
if (docDataModel == null
|
|
2050
|
+
const docDataModel = univerInstanceService.getUniverDocInstance(unitId);
|
|
2051
|
+
if (docDataModel == null)
|
|
1017
2052
|
return !1;
|
|
1018
|
-
const
|
|
2053
|
+
const docSkeletonManagerService = getCommandSkeleton(accessor, unitId);
|
|
2054
|
+
if (docSkeletonManagerService == null)
|
|
2055
|
+
return !1;
|
|
2056
|
+
const viewModel = docSkeletonManagerService.getViewModel(), doMutation = {
|
|
1019
2057
|
id: RichTextEditingMutation.id,
|
|
1020
2058
|
params: {
|
|
1021
2059
|
unitId,
|
|
1022
2060
|
actions: [],
|
|
1023
2061
|
textRanges
|
|
1024
2062
|
}
|
|
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);
|
|
2063
|
+
};
|
|
2064
|
+
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) {
|
|
2065
|
+
const actions = getCutActionsFromRectRanges(rectRanges, docDataModel, viewModel, segmentId);
|
|
2066
|
+
((_c = doMutation.params.actions) == null ? void 0 : _c.length) === 0 || doMutation.params.actions == null ? doMutation.params.actions = actions : doMutation.params.actions = JSONX.compose(
|
|
2067
|
+
doMutation.params.actions,
|
|
2068
|
+
JSONX.transform(actions, doMutation.params.actions, "right")
|
|
2069
|
+
);
|
|
1038
2070
|
}
|
|
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);
|
|
2071
|
+
return !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
1051
2072
|
}, "handler")
|
|
1052
2073
|
};
|
|
1053
2074
|
function getCustomBlockIdsInSelections(body, selections) {
|
|
@@ -1067,8 +2088,8 @@ const DeleteCustomBlockCommand = {
|
|
|
1067
2088
|
id: "doc.command.delete-custom-block",
|
|
1068
2089
|
type: CommandType.COMMAND,
|
|
1069
2090
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1070
|
-
var
|
|
1071
|
-
const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), activeRange = textSelectionManagerService.
|
|
2091
|
+
var _a11;
|
|
2092
|
+
const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), activeRange = textSelectionManagerService.getActiveTextRangeWithStyle(), documentDataModel = univerInstanceService.getCurrentUniverDocInstance();
|
|
1072
2093
|
if (activeRange == null || documentDataModel == null)
|
|
1073
2094
|
return !1;
|
|
1074
2095
|
const { direction, range, unitId, drawingId } = params, { startOffset, segmentId, style } = activeRange, cursor = direction === DeleteDirection.LEFT ? startOffset - 1 : startOffset, textRanges = [
|
|
@@ -1098,7 +2119,7 @@ const DeleteCustomBlockCommand = {
|
|
|
1098
2119
|
});
|
|
1099
2120
|
const path = getRichTextEditPath(documentDataModel, segmentId);
|
|
1100
2121
|
rawActions.push(jsonX.editOp(textX.serialize(), path));
|
|
1101
|
-
const drawing = ((
|
|
2122
|
+
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
2123
|
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
2124
|
}, "handler")
|
|
1104
2125
|
}, MergeTwoParagraphCommand = {
|
|
@@ -1106,8 +2127,8 @@ const DeleteCustomBlockCommand = {
|
|
|
1106
2127
|
type: CommandType.COMMAND,
|
|
1107
2128
|
// eslint-disable-next-line max-lines-per-function
|
|
1108
2129
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1109
|
-
var
|
|
1110
|
-
const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), { direction, range } = params, activeRange = textSelectionManagerService.
|
|
2130
|
+
var _a11, _b;
|
|
2131
|
+
const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), { direction, range } = params, activeRange = textSelectionManagerService.getActiveTextRangeWithStyle(), ranges = textSelectionManagerService.getCurrentTextRanges();
|
|
1111
2132
|
if (activeRange == null || ranges == null)
|
|
1112
2133
|
return !1;
|
|
1113
2134
|
const { segmentId, style } = activeRange, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), originBody = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
@@ -1116,7 +2137,7 @@ const DeleteCustomBlockCommand = {
|
|
|
1116
2137
|
const actualRange = getDeleteSelection(activeRange, originBody), unitId = docDataModel.getUnitId(), { startOffset, collapsed } = actualRange;
|
|
1117
2138
|
if (!collapsed)
|
|
1118
2139
|
return !1;
|
|
1119
|
-
const startIndex = direction === DeleteDirection.LEFT ? startOffset : startOffset + 1, endIndex = (_b = (
|
|
2140
|
+
const startIndex = direction === DeleteDirection.LEFT ? startOffset : startOffset + 1, endIndex = (_b = (_a11 = originBody.paragraphs) == null ? void 0 : _a11.find((p) => p.startIndex >= startIndex)) == null ? void 0 : _b.startIndex, body = getParagraphBody(accessor, unitId, originBody, startIndex, endIndex), cursor = direction === DeleteDirection.LEFT ? startOffset - 1 : startOffset, textRanges = [
|
|
1120
2141
|
{
|
|
1121
2142
|
startOffset: cursor,
|
|
1122
2143
|
endOffset: cursor,
|
|
@@ -1154,19 +2175,55 @@ const DeleteCustomBlockCommand = {
|
|
|
1154
2175
|
const path = getRichTextEditPath(docDataModel, segmentId);
|
|
1155
2176
|
return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
1156
2177
|
}, "handler")
|
|
1157
|
-
}
|
|
2178
|
+
};
|
|
2179
|
+
function getCursorWhenDelete(textRanges, rectRanges) {
|
|
2180
|
+
let cursor = 0;
|
|
2181
|
+
if (textRanges == null || textRanges.length === 0) {
|
|
2182
|
+
if (typeof rectRanges[0].startOffset == "number") {
|
|
2183
|
+
const rectRange = rectRanges[0], { spanEntireRow, spanEntireTable } = rectRange;
|
|
2184
|
+
spanEntireTable ? cursor = rectRange.startOffset - 3 : spanEntireRow ? rectRange.startRow > 0 ? cursor = rectRange.startOffset - 6 : cursor = rectRange.startOffset : cursor = rectRanges[0].startOffset;
|
|
2185
|
+
}
|
|
2186
|
+
} else if (textRanges.length > 0 && rectRanges.length > 0) {
|
|
2187
|
+
const textRange = textRanges[0], rectRange = rectRanges[0];
|
|
2188
|
+
if (textRange.startOffset != null && rectRange.startOffset != null) {
|
|
2189
|
+
if (textRange.startOffset < rectRange.startOffset)
|
|
2190
|
+
cursor = textRange.startOffset;
|
|
2191
|
+
else if (textRange.startOffset >= rectRange.startOffset) {
|
|
2192
|
+
const { spanEntireRow, spanEntireTable } = rectRange;
|
|
2193
|
+
spanEntireTable ? cursor = rectRange.startOffset - 3 : spanEntireRow && (cursor = rectRange.startOffset - 6);
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
}
|
|
2197
|
+
return cursor;
|
|
2198
|
+
}
|
|
2199
|
+
__name(getCursorWhenDelete, "getCursorWhenDelete");
|
|
2200
|
+
const DeleteLeftCommand = {
|
|
1158
2201
|
id: "doc.command.delete-left",
|
|
1159
2202
|
type: CommandType.COMMAND,
|
|
1160
2203
|
// eslint-disable-next-line max-lines-per-function, complexity
|
|
1161
2204
|
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
1162
|
-
var
|
|
2205
|
+
var _a11, _b;
|
|
1163
2206
|
const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService);
|
|
1164
2207
|
let result = !0;
|
|
1165
2208
|
const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
|
|
1166
2209
|
if (!docDataModel)
|
|
1167
2210
|
return !1;
|
|
1168
|
-
const unitId = docDataModel.getUnitId(), docSkeletonManagerService = getCommandSkeleton(accessor, unitId), activeRange = textSelectionManagerService.
|
|
1169
|
-
if (
|
|
2211
|
+
const unitId = docDataModel.getUnitId(), docSkeletonManagerService = getCommandSkeleton(accessor, unitId), activeRange = textSelectionManagerService.getActiveTextRangeWithStyle(), rectRanges = textSelectionManagerService.getCurrentRectRanges(), ranges = textSelectionManagerService.getCurrentTextRanges(), skeleton = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getSkeleton();
|
|
2212
|
+
if (skeleton == null)
|
|
2213
|
+
return !1;
|
|
2214
|
+
if (rectRanges != null && rectRanges.length) {
|
|
2215
|
+
const cursor2 = getCursorWhenDelete(ranges, rectRanges), segmentId2 = rectRanges[0].segmentId, textRanges = [
|
|
2216
|
+
{
|
|
2217
|
+
startOffset: cursor2,
|
|
2218
|
+
endOffset: cursor2
|
|
2219
|
+
}
|
|
2220
|
+
];
|
|
2221
|
+
return commandService.executeCommand(CutContentCommand.id, {
|
|
2222
|
+
segmentId: segmentId2,
|
|
2223
|
+
textRanges
|
|
2224
|
+
});
|
|
2225
|
+
}
|
|
2226
|
+
if (activeRange == null || ranges == null)
|
|
1170
2227
|
return !1;
|
|
1171
2228
|
const { segmentId, style, segmentPage } = activeRange, body = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
1172
2229
|
if (body == null)
|
|
@@ -1220,7 +2277,7 @@ const DeleteCustomBlockCommand = {
|
|
|
1220
2277
|
range: actualRange
|
|
1221
2278
|
});
|
|
1222
2279
|
else if (preGlyph.streamType === "\b") {
|
|
1223
|
-
const drawing = (_b = docDataModel.getSnapshot().drawings) == null ? void 0 : _b[(
|
|
2280
|
+
const drawing = (_b = docDataModel.getSnapshot().drawings) == null ? void 0 : _b[(_a11 = preGlyph.drawingId) != null ? _a11 : ""];
|
|
1224
2281
|
if (drawing == null)
|
|
1225
2282
|
return !0;
|
|
1226
2283
|
if (drawing.layoutType === PositionedObjectLayoutType.INLINE) {
|
|
@@ -1279,11 +2336,23 @@ const DeleteCustomBlockCommand = {
|
|
|
1279
2336
|
type: CommandType.COMMAND,
|
|
1280
2337
|
// eslint-disable-next-line max-lines-per-function
|
|
1281
2338
|
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
1282
|
-
var
|
|
2339
|
+
var _a11, _b;
|
|
1283
2340
|
const textSelectionManagerService = accessor.get(TextSelectionManagerService), docDataModel = accessor.get(IUniverInstanceService).getCurrentUniverDocInstance();
|
|
1284
2341
|
if (!docDataModel)
|
|
1285
2342
|
return !1;
|
|
1286
|
-
const docSkeletonManagerService = getCommandSkeleton(accessor, docDataModel.getUnitId()), commandService = accessor.get(ICommandService), activeRange = textSelectionManagerService.
|
|
2343
|
+
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();
|
|
2344
|
+
if (rectRanges != null && rectRanges.length) {
|
|
2345
|
+
const cursor = getCursorWhenDelete(ranges, rectRanges), segmentId2 = rectRanges[0].segmentId, textRanges = [
|
|
2346
|
+
{
|
|
2347
|
+
startOffset: cursor,
|
|
2348
|
+
endOffset: cursor
|
|
2349
|
+
}
|
|
2350
|
+
];
|
|
2351
|
+
return commandService.executeCommand(CutContentCommand.id, {
|
|
2352
|
+
segmentId: segmentId2,
|
|
2353
|
+
textRanges
|
|
2354
|
+
});
|
|
2355
|
+
}
|
|
1287
2356
|
if (activeRange == null || skeleton == null || ranges == null)
|
|
1288
2357
|
return !1;
|
|
1289
2358
|
const { segmentId, style, segmentPage } = activeRange, body = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
@@ -1295,13 +2364,15 @@ const DeleteCustomBlockCommand = {
|
|
|
1295
2364
|
let result = !1;
|
|
1296
2365
|
if (collapsed === !0) {
|
|
1297
2366
|
const needDeleteGlyph = skeleton.findNodeByCharIndex(startOffset, segmentId, segmentPage), nextGlyph = skeleton.findNodeByCharIndex(startOffset + 1);
|
|
2367
|
+
if (needDeleteGlyph.streamType === DataStreamTreeTokenType.PARAGRAPH && (nextGlyph == null ? void 0 : nextGlyph.streamType) === DataStreamTreeTokenType.SECTION_BREAK)
|
|
2368
|
+
return !1;
|
|
1298
2369
|
if (needDeleteGlyph.content === "\r")
|
|
1299
2370
|
result = await commandService.executeCommand(MergeTwoParagraphCommand.id, {
|
|
1300
2371
|
direction: DeleteDirection.RIGHT,
|
|
1301
2372
|
range: activeRange
|
|
1302
2373
|
});
|
|
1303
2374
|
else if (needDeleteGlyph.streamType === "\b") {
|
|
1304
|
-
const drawing = (_b = docDataModel.getSnapshot().drawings) == null ? void 0 : _b[(
|
|
2375
|
+
const drawing = (_b = docDataModel.getSnapshot().drawings) == null ? void 0 : _b[(_a11 = needDeleteGlyph.drawingId) != null ? _a11 : ""];
|
|
1305
2376
|
if (drawing == null)
|
|
1306
2377
|
return !0;
|
|
1307
2378
|
if (drawing.layoutType === PositionedObjectLayoutType.INLINE) {
|
|
@@ -1476,11 +2547,8 @@ const IMEInputCommand = {
|
|
|
1476
2547
|
return imeInputManagerService.pushUndoRedoMutationParams(result, doMutation.params), !!result;
|
|
1477
2548
|
}, "handler")
|
|
1478
2549
|
};
|
|
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,
|
|
2550
|
+
function handleInlineFormat(preCommandId, params, commandService) {
|
|
2551
|
+
return commandService.executeCommand(SetInlineFormatCommand.id, {
|
|
1484
2552
|
preCommandId,
|
|
1485
2553
|
...params != null ? params : {}
|
|
1486
2554
|
});
|
|
@@ -1490,11 +2558,10 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1490
2558
|
id: SetInlineFormatBoldCommandId,
|
|
1491
2559
|
type: CommandType.COMMAND,
|
|
1492
2560
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1493
|
-
const commandService = accessor.get(ICommandService)
|
|
2561
|
+
const commandService = accessor.get(ICommandService);
|
|
1494
2562
|
return handleInlineFormat(
|
|
1495
2563
|
SetInlineFormatBoldCommandId,
|
|
1496
2564
|
params,
|
|
1497
|
-
textSelectionManagerService,
|
|
1498
2565
|
commandService
|
|
1499
2566
|
);
|
|
1500
2567
|
}, "handler")
|
|
@@ -1502,11 +2569,10 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1502
2569
|
id: SetInlineFormatItalicCommandId,
|
|
1503
2570
|
type: CommandType.COMMAND,
|
|
1504
2571
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1505
|
-
const commandService = accessor.get(ICommandService)
|
|
2572
|
+
const commandService = accessor.get(ICommandService);
|
|
1506
2573
|
return handleInlineFormat(
|
|
1507
2574
|
SetInlineFormatItalicCommandId,
|
|
1508
2575
|
params,
|
|
1509
|
-
textSelectionManagerService,
|
|
1510
2576
|
commandService
|
|
1511
2577
|
);
|
|
1512
2578
|
}, "handler")
|
|
@@ -1514,11 +2580,10 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1514
2580
|
id: SetInlineFormatUnderlineCommandId,
|
|
1515
2581
|
type: CommandType.COMMAND,
|
|
1516
2582
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1517
|
-
const commandService = accessor.get(ICommandService)
|
|
2583
|
+
const commandService = accessor.get(ICommandService);
|
|
1518
2584
|
return handleInlineFormat(
|
|
1519
2585
|
SetInlineFormatUnderlineCommandId,
|
|
1520
2586
|
params,
|
|
1521
|
-
textSelectionManagerService,
|
|
1522
2587
|
commandService
|
|
1523
2588
|
);
|
|
1524
2589
|
}, "handler")
|
|
@@ -1526,11 +2591,10 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1526
2591
|
id: SetInlineFormatStrikethroughCommandId,
|
|
1527
2592
|
type: CommandType.COMMAND,
|
|
1528
2593
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1529
|
-
const commandService = accessor.get(ICommandService)
|
|
2594
|
+
const commandService = accessor.get(ICommandService);
|
|
1530
2595
|
return handleInlineFormat(
|
|
1531
2596
|
SetInlineFormatStrikethroughCommandId,
|
|
1532
2597
|
params,
|
|
1533
|
-
textSelectionManagerService,
|
|
1534
2598
|
commandService
|
|
1535
2599
|
);
|
|
1536
2600
|
}, "handler")
|
|
@@ -1538,11 +2602,10 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1538
2602
|
id: SetInlineFormatSubscriptCommandId,
|
|
1539
2603
|
type: CommandType.COMMAND,
|
|
1540
2604
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1541
|
-
const commandService = accessor.get(ICommandService)
|
|
2605
|
+
const commandService = accessor.get(ICommandService);
|
|
1542
2606
|
return handleInlineFormat(
|
|
1543
2607
|
SetInlineFormatSubscriptCommandId,
|
|
1544
2608
|
params,
|
|
1545
|
-
textSelectionManagerService,
|
|
1546
2609
|
commandService
|
|
1547
2610
|
);
|
|
1548
2611
|
}, "handler")
|
|
@@ -1550,11 +2613,10 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1550
2613
|
id: SetInlineFormatSuperscriptCommandId,
|
|
1551
2614
|
type: CommandType.COMMAND,
|
|
1552
2615
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1553
|
-
const commandService = accessor.get(ICommandService)
|
|
2616
|
+
const commandService = accessor.get(ICommandService);
|
|
1554
2617
|
return handleInlineFormat(
|
|
1555
2618
|
SetInlineFormatSuperscriptCommandId,
|
|
1556
2619
|
params,
|
|
1557
|
-
textSelectionManagerService,
|
|
1558
2620
|
commandService
|
|
1559
2621
|
);
|
|
1560
2622
|
}, "handler")
|
|
@@ -1562,11 +2624,10 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1562
2624
|
id: SetInlineFormatFontSizeCommandId,
|
|
1563
2625
|
type: CommandType.COMMAND,
|
|
1564
2626
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1565
|
-
const commandService = accessor.get(ICommandService)
|
|
2627
|
+
const commandService = accessor.get(ICommandService);
|
|
1566
2628
|
return handleInlineFormat(
|
|
1567
2629
|
SetInlineFormatFontSizeCommandId,
|
|
1568
2630
|
params,
|
|
1569
|
-
textSelectionManagerService,
|
|
1570
2631
|
commandService
|
|
1571
2632
|
);
|
|
1572
2633
|
}, "handler")
|
|
@@ -1574,11 +2635,10 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1574
2635
|
id: SetInlineFormatFontFamilyCommandId,
|
|
1575
2636
|
type: CommandType.COMMAND,
|
|
1576
2637
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1577
|
-
const commandService = accessor.get(ICommandService)
|
|
2638
|
+
const commandService = accessor.get(ICommandService);
|
|
1578
2639
|
return handleInlineFormat(
|
|
1579
2640
|
SetInlineFormatFontFamilyCommandId,
|
|
1580
2641
|
params,
|
|
1581
|
-
textSelectionManagerService,
|
|
1582
2642
|
commandService
|
|
1583
2643
|
);
|
|
1584
2644
|
}, "handler")
|
|
@@ -1586,11 +2646,10 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1586
2646
|
id: SetInlineFormatTextColorCommandId,
|
|
1587
2647
|
type: CommandType.COMMAND,
|
|
1588
2648
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1589
|
-
const commandService = accessor.get(ICommandService)
|
|
2649
|
+
const commandService = accessor.get(ICommandService);
|
|
1590
2650
|
return handleInlineFormat(
|
|
1591
2651
|
SetInlineFormatTextColorCommandId,
|
|
1592
2652
|
params,
|
|
1593
|
-
textSelectionManagerService,
|
|
1594
2653
|
commandService
|
|
1595
2654
|
);
|
|
1596
2655
|
}, "handler")
|
|
@@ -1598,11 +2657,10 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1598
2657
|
id: SetInlineFormatTextBackgroundColorCommandId,
|
|
1599
2658
|
type: CommandType.COMMAND,
|
|
1600
2659
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1601
|
-
const commandService = accessor.get(ICommandService)
|
|
2660
|
+
const commandService = accessor.get(ICommandService);
|
|
1602
2661
|
return handleInlineFormat(
|
|
1603
2662
|
SetInlineFormatTextBackgroundColorCommandId,
|
|
1604
2663
|
params,
|
|
1605
|
-
textSelectionManagerService,
|
|
1606
2664
|
commandService
|
|
1607
2665
|
);
|
|
1608
2666
|
}, "handler")
|
|
@@ -1610,11 +2668,10 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1610
2668
|
id: ResetInlineFormatTextBackgroundColorCommandId,
|
|
1611
2669
|
type: CommandType.COMMAND,
|
|
1612
2670
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1613
|
-
const commandService = accessor.get(ICommandService)
|
|
2671
|
+
const commandService = accessor.get(ICommandService);
|
|
1614
2672
|
return handleInlineFormat(
|
|
1615
2673
|
ResetInlineFormatTextBackgroundColorCommandId,
|
|
1616
2674
|
params,
|
|
1617
|
-
textSelectionManagerService,
|
|
1618
2675
|
commandService
|
|
1619
2676
|
);
|
|
1620
2677
|
}, "handler")
|
|
@@ -1635,10 +2692,10 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1635
2692
|
type: CommandType.COMMAND,
|
|
1636
2693
|
// eslint-disable-next-line max-lines-per-function
|
|
1637
2694
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1638
|
-
const {
|
|
1639
|
-
if (
|
|
2695
|
+
const { value, preCommandId } = params, commandService = accessor.get(ICommandService), textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), docRanges = textSelectionManagerService.getDocRanges();
|
|
2696
|
+
if (docRanges.length === 0)
|
|
1640
2697
|
return !1;
|
|
1641
|
-
const docDataModel = univerInstanceService.getCurrentUniverDocInstance();
|
|
2698
|
+
const segmentId = docRanges[0].segmentId, docDataModel = univerInstanceService.getCurrentUniverDocInstance();
|
|
1642
2699
|
if (docDataModel == null)
|
|
1643
2700
|
return !1;
|
|
1644
2701
|
const unitId = docDataModel.getUnitId();
|
|
@@ -1653,7 +2710,7 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1653
2710
|
formatValue = getReverseFormatValueInSelection(
|
|
1654
2711
|
docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody().textRuns,
|
|
1655
2712
|
preCommandId,
|
|
1656
|
-
|
|
2713
|
+
docRanges
|
|
1657
2714
|
);
|
|
1658
2715
|
break;
|
|
1659
2716
|
}
|
|
@@ -1683,12 +2740,15 @@ const SetInlineFormatBoldCommandId = "doc.command.set-inline-format-bold", SetIn
|
|
|
1683
2740
|
params: {
|
|
1684
2741
|
unitId,
|
|
1685
2742
|
actions: [],
|
|
1686
|
-
textRanges:
|
|
2743
|
+
textRanges: docRanges.map(serializeDocRange)
|
|
1687
2744
|
}
|
|
1688
2745
|
}, textX = new TextX(), jsonX = JSONX.getInstance(), memoryCursor = new MemoryCursor();
|
|
1689
2746
|
memoryCursor.reset();
|
|
1690
|
-
for (const
|
|
1691
|
-
const { startOffset, endOffset } =
|
|
2747
|
+
for (const range of docRanges) {
|
|
2748
|
+
const { startOffset, endOffset } = range;
|
|
2749
|
+
if (startOffset == null || endOffset == null)
|
|
2750
|
+
continue;
|
|
2751
|
+
const body = {
|
|
1692
2752
|
dataStream: "",
|
|
1693
2753
|
textRuns: [
|
|
1694
2754
|
{
|
|
@@ -1719,11 +2779,11 @@ function isTextDecoration(value) {
|
|
|
1719
2779
|
return value !== null && typeof value == "object";
|
|
1720
2780
|
}
|
|
1721
2781
|
__name(isTextDecoration, "isTextDecoration");
|
|
1722
|
-
function getReverseFormatValueInSelection(textRuns, preCommandId,
|
|
2782
|
+
function getReverseFormatValueInSelection(textRuns, preCommandId, docRanges) {
|
|
1723
2783
|
let ti = 0, si = 0;
|
|
1724
2784
|
const key = COMMAND_ID_TO_FORMAT_KEY_MAP[preCommandId];
|
|
1725
|
-
for (; ti !== textRuns.length && si !==
|
|
1726
|
-
const { startOffset, endOffset } =
|
|
2785
|
+
for (; ti !== textRuns.length && si !== docRanges.length; ) {
|
|
2786
|
+
const { startOffset, endOffset } = docRanges[si], { st, ed, ts } = textRuns[ti];
|
|
1727
2787
|
if (endOffset <= st)
|
|
1728
2788
|
si++;
|
|
1729
2789
|
else if (ed <= startOffset)
|
|
@@ -1747,124 +2807,11 @@ function getReverseFormatValueInSelection(textRuns, preCommandId, selections) {
|
|
|
1747
2807
|
} : preCommandId === SetInlineFormatSubscriptCommand.id ? BaselineOffset.SUBSCRIPT : BaselineOffset.SUPERSCRIPT;
|
|
1748
2808
|
}
|
|
1749
2809
|
__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
2810
|
const ReplaceContentCommand = {
|
|
1864
2811
|
id: "doc.command-replace-content",
|
|
1865
2812
|
type: CommandType.COMMAND,
|
|
1866
2813
|
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.
|
|
2814
|
+
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
2815
|
if (docDataModel == null || prevBody == null || !Array.isArray(selections) || selections.length === 0)
|
|
1869
2816
|
return !1;
|
|
1870
2817
|
const doMutation = getMutationParams(unitId, segmentId, docDataModel, prevBody, body);
|
|
@@ -1932,9 +2879,9 @@ const SetDocZoomRatioUndoMutationFactory = /* @__PURE__ */ __name((accessor, par
|
|
|
1932
2879
|
type: CommandType.COMMAND,
|
|
1933
2880
|
id: "doc.command.set-zoom-ratio",
|
|
1934
2881
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1935
|
-
var
|
|
2882
|
+
var _a11, _b, _c;
|
|
1936
2883
|
const commandService = accessor.get(ICommandService), undoRedoService = accessor.get(IUndoRedoService), univerInstanceService = accessor.get(IUniverInstanceService);
|
|
1937
|
-
let documentId = (
|
|
2884
|
+
let documentId = (_a11 = univerInstanceService.getCurrentUniverDocInstance()) == null ? void 0 : _a11.getUnitId();
|
|
1938
2885
|
if (!documentId) return !1;
|
|
1939
2886
|
let zoomRatio = 1;
|
|
1940
2887
|
if (params && (documentId = (_b = params.documentId) != null ? _b : documentId, zoomRatio = (_c = params.zoomRatio) != null ? _c : zoomRatio), !univerInstanceService.getUniverDocInstance(documentId)) return !1;
|
|
@@ -1960,7 +2907,7 @@ const SetDocZoomRatioUndoMutationFactory = /* @__PURE__ */ __name((accessor, par
|
|
|
1960
2907
|
id: "doc.operation.select-all",
|
|
1961
2908
|
type: CommandType.COMMAND,
|
|
1962
2909
|
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
1963
|
-
const univerInstanceService = accessor.get(IUniverInstanceService), textSelectionManagerService = accessor.get(TextSelectionManagerService), docDataModel = univerInstanceService.getCurrentUniverDocInstance(), activeTextRange = textSelectionManagerService.
|
|
2910
|
+
const univerInstanceService = accessor.get(IUniverInstanceService), textSelectionManagerService = accessor.get(TextSelectionManagerService), docDataModel = univerInstanceService.getCurrentUniverDocInstance(), activeTextRange = textSelectionManagerService.getActiveTextRangeWithStyle();
|
|
1964
2911
|
if (docDataModel == null || activeTextRange == null)
|
|
1965
2912
|
return !1;
|
|
1966
2913
|
const { segmentId } = activeTextRange, prevBody = docDataModel.getSelfOrHeaderFooterModel(segmentId).getSnapshot().body;
|
|
@@ -1975,24 +2922,24 @@ const SetDocZoomRatioUndoMutationFactory = /* @__PURE__ */ __name((accessor, par
|
|
|
1975
2922
|
return textSelectionManagerService.replaceTextRanges(textRanges, !1), !0;
|
|
1976
2923
|
}, "handler")
|
|
1977
2924
|
};
|
|
1978
|
-
var __defProp$
|
|
1979
|
-
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$
|
|
2925
|
+
var __defProp$6 = Object.defineProperty, __getOwnPropDesc$6 = Object.getOwnPropertyDescriptor, __decorateClass$6 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
2926
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$6(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1980
2927
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
1981
|
-
return kind && result && __defProp$
|
|
1982
|
-
}, "__decorateClass$
|
|
2928
|
+
return kind && result && __defProp$6(target, key, result), result;
|
|
2929
|
+
}, "__decorateClass$6"), __decorateParam$6 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$6"), _a4;
|
|
1983
2930
|
let IMEInputController = (_a4 = class extends Disposable {
|
|
1984
|
-
constructor(_univerInstanceService, _renderManagerSrv, _textSelectionRenderManager, _imeInputManagerService, _commandService) {
|
|
2931
|
+
constructor(_univerInstanceService, _renderManagerSrv, _textSelectionRenderManager, _textSelectionManagerService, _imeInputManagerService, _commandService) {
|
|
1985
2932
|
super();
|
|
1986
2933
|
__publicField(this, "_previousIMEContent", "");
|
|
1987
2934
|
__publicField(this, "_isCompositionStart", !0);
|
|
1988
2935
|
__publicField(this, "_onStartSubscription");
|
|
1989
2936
|
__publicField(this, "_onUpdateSubscription");
|
|
1990
2937
|
__publicField(this, "_onEndSubscription");
|
|
1991
|
-
this._univerInstanceService = _univerInstanceService, this._renderManagerSrv = _renderManagerSrv, this._textSelectionRenderManager = _textSelectionRenderManager, this._imeInputManagerService = _imeInputManagerService, this._commandService = _commandService, this._initialize();
|
|
2938
|
+
this._univerInstanceService = _univerInstanceService, this._renderManagerSrv = _renderManagerSrv, this._textSelectionRenderManager = _textSelectionRenderManager, this._textSelectionManagerService = _textSelectionManagerService, this._imeInputManagerService = _imeInputManagerService, this._commandService = _commandService, this._initialize();
|
|
1992
2939
|
}
|
|
1993
2940
|
dispose() {
|
|
1994
|
-
var
|
|
1995
|
-
(
|
|
2941
|
+
var _a11, _b, _c;
|
|
2942
|
+
(_a11 = this._onStartSubscription) == null || _a11.unsubscribe(), (_b = this._onUpdateSubscription) == null || _b.unsubscribe(), (_c = this._onEndSubscription) == null || _c.unsubscribe();
|
|
1996
2943
|
}
|
|
1997
2944
|
_initialize() {
|
|
1998
2945
|
this._initialOnCompositionstart(), this._initialOnCompositionUpdate(), this._initialOnCompositionend();
|
|
@@ -2017,13 +2964,13 @@ let IMEInputController = (_a4 = class extends Disposable {
|
|
|
2017
2964
|
});
|
|
2018
2965
|
}
|
|
2019
2966
|
async _updateContent(config, isUpdate) {
|
|
2020
|
-
var
|
|
2967
|
+
var _a11;
|
|
2021
2968
|
if (config == null)
|
|
2022
2969
|
return;
|
|
2023
2970
|
const documentModel = this._univerInstanceService.getCurrentUniverDocInstance();
|
|
2024
2971
|
if (!documentModel)
|
|
2025
2972
|
return;
|
|
2026
|
-
const skeleton = (
|
|
2973
|
+
const skeleton = (_a11 = this._renderManagerSrv.getRenderById(documentModel.getUnitId())) == null ? void 0 : _a11.with(DocSkeletonManagerService).getSkeleton(), { event, activeRange } = config;
|
|
2027
2974
|
if (skeleton == null || activeRange == null)
|
|
2028
2975
|
return;
|
|
2029
2976
|
const content = event.data;
|
|
@@ -2039,19 +2986,98 @@ let IMEInputController = (_a4 = class extends Disposable {
|
|
|
2039
2986
|
this._previousIMEContent = "", this._isCompositionStart = !0, this._imeInputManagerService.clearUndoRedoMutationParamsCache(), this._imeInputManagerService.setActiveRange(null);
|
|
2040
2987
|
}
|
|
2041
2988
|
}, __name(_a4, "IMEInputController"), _a4);
|
|
2042
|
-
IMEInputController = __decorateClass$
|
|
2989
|
+
IMEInputController = __decorateClass$6([
|
|
2043
2990
|
OnLifecycle(LifecycleStages.Rendered, IMEInputController),
|
|
2044
|
-
__decorateParam$
|
|
2045
|
-
__decorateParam$
|
|
2046
|
-
__decorateParam$
|
|
2047
|
-
__decorateParam$
|
|
2048
|
-
__decorateParam$
|
|
2991
|
+
__decorateParam$6(0, IUniverInstanceService),
|
|
2992
|
+
__decorateParam$6(1, IRenderManagerService),
|
|
2993
|
+
__decorateParam$6(2, ITextSelectionRenderManager),
|
|
2994
|
+
__decorateParam$6(3, Inject(TextSelectionManagerService)),
|
|
2995
|
+
__decorateParam$6(4, Inject(IMEInputManagerService)),
|
|
2996
|
+
__decorateParam$6(5, ICommandService)
|
|
2049
2997
|
], IMEInputController);
|
|
2050
|
-
|
|
2051
|
-
|
|
2998
|
+
function firstLineInTable(table) {
|
|
2999
|
+
return table.rows[0].cells[0].sections[0].columns[0].lines[0];
|
|
3000
|
+
}
|
|
3001
|
+
__name(firstLineInTable, "firstLineInTable");
|
|
3002
|
+
function lastLineInTable(table) {
|
|
3003
|
+
const lastRow = table.rows[table.rows.length - 1], lastCell = lastRow.cells[lastRow.cells.length - 1];
|
|
3004
|
+
return getLastLine(lastCell);
|
|
3005
|
+
}
|
|
3006
|
+
__name(lastLineInTable, "lastLineInTable");
|
|
3007
|
+
function findTableAfterLine(line, page) {
|
|
3008
|
+
const { ed } = line, { skeTables } = page;
|
|
3009
|
+
let table = null;
|
|
3010
|
+
for (const t of skeTables.values())
|
|
3011
|
+
if (t.st === ed + 1) {
|
|
3012
|
+
table = t;
|
|
3013
|
+
break;
|
|
3014
|
+
}
|
|
3015
|
+
return table;
|
|
3016
|
+
}
|
|
3017
|
+
__name(findTableAfterLine, "findTableAfterLine");
|
|
3018
|
+
function findLineBeforeAndAfterTable(table) {
|
|
3019
|
+
const tablePage = table == null ? void 0 : table.parent;
|
|
3020
|
+
let lineBeforeTable = null, lineAfterTable = null;
|
|
3021
|
+
if (table == null || tablePage == null)
|
|
3022
|
+
return {
|
|
3023
|
+
lineBeforeTable,
|
|
3024
|
+
lineAfterTable
|
|
3025
|
+
};
|
|
3026
|
+
const { st, ed } = table, pages = tablePage.type === DocumentSkeletonPageType.CELL ? [tablePage] : tablePage.parent.pages;
|
|
3027
|
+
return lineIterator(pages, (l) => {
|
|
3028
|
+
l.st === ed + 1 ? lineAfterTable = l : l.ed === st - 1 && (lineBeforeTable = l);
|
|
3029
|
+
}), {
|
|
3030
|
+
lineBeforeTable,
|
|
3031
|
+
lineAfterTable
|
|
3032
|
+
};
|
|
3033
|
+
}
|
|
3034
|
+
__name(findLineBeforeAndAfterTable, "findLineBeforeAndAfterTable");
|
|
3035
|
+
function findBellowCell(cell) {
|
|
3036
|
+
const row = cell.parent, table = row == null ? void 0 : row.parent;
|
|
3037
|
+
if (row == null || table == null)
|
|
3038
|
+
return;
|
|
3039
|
+
const bellowRow = table.rows[table.rows.indexOf(row) + 1];
|
|
3040
|
+
if (bellowRow == null)
|
|
3041
|
+
return;
|
|
3042
|
+
const col = row.cells.indexOf(cell);
|
|
3043
|
+
return bellowRow.cells[col];
|
|
3044
|
+
}
|
|
3045
|
+
__name(findBellowCell, "findBellowCell");
|
|
3046
|
+
function findAboveCell(cell) {
|
|
3047
|
+
const row = cell.parent, table = row == null ? void 0 : row.parent;
|
|
3048
|
+
if (row == null || table == null)
|
|
3049
|
+
return;
|
|
3050
|
+
const aboveRow = table.rows[table.rows.indexOf(row) - 1];
|
|
3051
|
+
if (aboveRow == null)
|
|
3052
|
+
return;
|
|
3053
|
+
const col = row.cells.indexOf(cell);
|
|
3054
|
+
return aboveRow.cells[col];
|
|
3055
|
+
}
|
|
3056
|
+
__name(findAboveCell, "findAboveCell");
|
|
3057
|
+
function findTableBeforeLine(line, page) {
|
|
3058
|
+
const { st } = line, { skeTables } = page;
|
|
3059
|
+
let table = null;
|
|
3060
|
+
for (const t of skeTables.values())
|
|
3061
|
+
if (t.ed === st - 1) {
|
|
3062
|
+
table = t;
|
|
3063
|
+
break;
|
|
3064
|
+
}
|
|
3065
|
+
return table;
|
|
3066
|
+
}
|
|
3067
|
+
__name(findTableBeforeLine, "findTableBeforeLine");
|
|
3068
|
+
function firstLineInCell(cell) {
|
|
3069
|
+
return cell.sections[0].columns[0].lines[0];
|
|
3070
|
+
}
|
|
3071
|
+
__name(firstLineInCell, "firstLineInCell");
|
|
3072
|
+
function lastLineInCell(cell) {
|
|
3073
|
+
return getLastLine(cell);
|
|
3074
|
+
}
|
|
3075
|
+
__name(lastLineInCell, "lastLineInCell");
|
|
3076
|
+
var __defProp$5 = Object.defineProperty, __getOwnPropDesc$5 = Object.getOwnPropertyDescriptor, __decorateClass$5 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
3077
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$5(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
2052
3078
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
2053
|
-
return kind && result && __defProp$
|
|
2054
|
-
}, "__decorateClass$
|
|
3079
|
+
return kind && result && __defProp$5(target, key, result), result;
|
|
3080
|
+
}, "__decorateClass$5"), __decorateParam$5 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$5"), _a5;
|
|
2055
3081
|
let MoveCursorController = (_a5 = class extends Disposable {
|
|
2056
3082
|
constructor(_univerInstanceService, _renderManagerService, _textSelectionManagerService, _commandService) {
|
|
2057
3083
|
super();
|
|
@@ -2059,8 +3085,8 @@ let MoveCursorController = (_a5 = class extends Disposable {
|
|
|
2059
3085
|
this._univerInstanceService = _univerInstanceService, this._renderManagerService = _renderManagerService, this._textSelectionManagerService = _textSelectionManagerService, this._commandService = _commandService, this._commandExecutedListener();
|
|
2060
3086
|
}
|
|
2061
3087
|
dispose() {
|
|
2062
|
-
var
|
|
2063
|
-
super.dispose(), (
|
|
3088
|
+
var _a11;
|
|
3089
|
+
super.dispose(), (_a11 = this._onInputSubscription) == null || _a11.unsubscribe();
|
|
2064
3090
|
}
|
|
2065
3091
|
_commandExecutedListener() {
|
|
2066
3092
|
const updateCommandList = [MoveCursorOperation.id, MoveSelectionOperation.id];
|
|
@@ -2082,11 +3108,11 @@ let MoveCursorController = (_a5 = class extends Disposable {
|
|
|
2082
3108
|
}
|
|
2083
3109
|
// eslint-disable-next-line max-lines-per-function, complexity
|
|
2084
3110
|
_handleShiftMoveSelection(direction) {
|
|
2085
|
-
var
|
|
2086
|
-
const activeRange = this._textSelectionManagerService.
|
|
2087
|
-
if (
|
|
3111
|
+
var _a11, _b, _c;
|
|
3112
|
+
const activeRange = this._textSelectionManagerService.getActiveTextRangeWithStyle(), allRanges = this._textSelectionManagerService.getCurrentTextRanges(), docDataModel = this._univerInstanceService.getCurrentUniverDocInstance();
|
|
3113
|
+
if (docDataModel == null)
|
|
2088
3114
|
return;
|
|
2089
|
-
const skeleton = (
|
|
3115
|
+
const skeleton = (_a11 = this._renderManagerService.getRenderById(docDataModel.getUnitId())) == null ? void 0 : _a11.with(DocSkeletonManagerService).getSkeleton(), docObject = this._getDocObject();
|
|
2090
3116
|
if (activeRange == null || skeleton == null || docObject == null)
|
|
2091
3117
|
return;
|
|
2092
3118
|
const {
|
|
@@ -2126,7 +3152,7 @@ let MoveCursorController = (_a5 = class extends Disposable {
|
|
|
2126
3152
|
}
|
|
2127
3153
|
], !1);
|
|
2128
3154
|
} 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);
|
|
3155
|
+
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
3156
|
if (newPos == null) {
|
|
2131
3157
|
const newFocusOffset = direction === Direction.UP ? 0 : dataStreamLength - 2;
|
|
2132
3158
|
if (newFocusOffset === focusOffset)
|
|
@@ -2155,14 +3181,17 @@ let MoveCursorController = (_a5 = class extends Disposable {
|
|
|
2155
3181
|
}
|
|
2156
3182
|
// eslint-disable-next-line max-lines-per-function, complexity
|
|
2157
3183
|
_handleMoveCursor(direction) {
|
|
2158
|
-
var
|
|
2159
|
-
const activeRange = this._textSelectionManagerService.
|
|
2160
|
-
if (
|
|
3184
|
+
var _a11, _b, _c, _d;
|
|
3185
|
+
const activeRange = this._textSelectionManagerService.getActiveTextRangeWithStyle(), allRanges = this._textSelectionManagerService.getCurrentTextRanges(), docDataModel = this._univerInstanceService.getCurrentUniverDocInstance();
|
|
3186
|
+
if (docDataModel == null)
|
|
2161
3187
|
return !1;
|
|
2162
|
-
const skeleton = (
|
|
2163
|
-
if (activeRange == null || skeleton == null || docObject == null || allRanges == null
|
|
3188
|
+
const skeleton = (_a11 = this._renderManagerService.getRenderById(docDataModel.getUnitId())) == null ? void 0 : _a11.with(DocSkeletonManagerService).getSkeleton(), docObject = this._getDocObject();
|
|
3189
|
+
if (activeRange == null || skeleton == null || docObject == null || allRanges == null)
|
|
2164
3190
|
return;
|
|
2165
|
-
const { startOffset, endOffset, style, collapsed, segmentId, startNodePosition, endNodePosition, segmentPage } = activeRange,
|
|
3191
|
+
const { startOffset, endOffset, style, collapsed, segmentId, startNodePosition, endNodePosition, segmentPage } = activeRange, body = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
3192
|
+
if (body == null)
|
|
3193
|
+
return;
|
|
3194
|
+
const dataStreamLength = (_b = body.dataStream.length) != null ? _b : Number.POSITIVE_INFINITY, customRanges = (_c = docDataModel.getCustomRanges()) != null ? _c : [];
|
|
2166
3195
|
if (direction === Direction.LEFT || direction === Direction.RIGHT) {
|
|
2167
3196
|
let cursor;
|
|
2168
3197
|
if (!activeRange.collapsed || allRanges.length > 1) {
|
|
@@ -2171,15 +3200,25 @@ let MoveCursorController = (_a5 = class extends Disposable {
|
|
|
2171
3200
|
min = Math.min(min, range.startOffset), max = Math.max(max, range.endOffset);
|
|
2172
3201
|
cursor = direction === Direction.LEFT ? min : max;
|
|
2173
3202
|
} 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 :
|
|
3203
|
+
const preSpan = skeleton.findNodeByCharIndex(startOffset - 1, segmentId, segmentPage), curSpan = skeleton.findNodeByCharIndex(startOffset, segmentId, segmentPage), nextGlyph = skeleton.findNodeByCharIndex(startOffset + 1, segmentId, segmentPage);
|
|
3204
|
+
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
3205
|
}
|
|
2177
|
-
const skipTokens = [
|
|
3206
|
+
const skipTokens = [
|
|
3207
|
+
DataStreamTreeTokenType.CUSTOM_RANGE_START,
|
|
3208
|
+
DataStreamTreeTokenType.CUSTOM_RANGE_END,
|
|
3209
|
+
DataStreamTreeTokenType.TABLE_START,
|
|
3210
|
+
DataStreamTreeTokenType.TABLE_END,
|
|
3211
|
+
DataStreamTreeTokenType.TABLE_ROW_START,
|
|
3212
|
+
DataStreamTreeTokenType.TABLE_ROW_END,
|
|
3213
|
+
DataStreamTreeTokenType.TABLE_CELL_START,
|
|
3214
|
+
DataStreamTreeTokenType.TABLE_CELL_END,
|
|
3215
|
+
DataStreamTreeTokenType.SECTION_BREAK
|
|
3216
|
+
];
|
|
2178
3217
|
if (direction === Direction.LEFT)
|
|
2179
3218
|
for (; skipTokens.includes(body.dataStream[cursor]); )
|
|
2180
3219
|
cursor--;
|
|
2181
3220
|
else
|
|
2182
|
-
for (; skipTokens.includes(body.dataStream[cursor
|
|
3221
|
+
for (; skipTokens.includes(body.dataStream[cursor]); )
|
|
2183
3222
|
cursor++;
|
|
2184
3223
|
customRanges.filter((range) => range.wholeEntity && range.startIndex < cursor && range.endIndex >= cursor).forEach((range) => {
|
|
2185
3224
|
direction === Direction.LEFT ? cursor = Math.min(range.startIndex, cursor) : cursor = Math.max(range.endIndex + 1, cursor);
|
|
@@ -2220,10 +3259,10 @@ let MoveCursorController = (_a5 = class extends Disposable {
|
|
|
2220
3259
|
], !1);
|
|
2221
3260
|
}
|
|
2222
3261
|
}
|
|
2223
|
-
_getTopOrBottomPosition(docSkeleton, glyph, nodePosition, direction) {
|
|
3262
|
+
_getTopOrBottomPosition(docSkeleton, glyph, nodePosition, direction, skipCellContent = !1) {
|
|
2224
3263
|
if (glyph == null || nodePosition == null)
|
|
2225
3264
|
return;
|
|
2226
|
-
const offsetLeft = this._getGlyphLeftOffsetInLine(glyph), line = this._getNextOrPrevLine(glyph, direction);
|
|
3265
|
+
const offsetLeft = this._getGlyphLeftOffsetInLine(glyph), line = this._getNextOrPrevLine(glyph, direction, skipCellContent);
|
|
2227
3266
|
if (line == null)
|
|
2228
3267
|
return;
|
|
2229
3268
|
const position = this._matchPositionByLeftOffset(docSkeleton, line, offsetLeft, nodePosition);
|
|
@@ -2244,6 +3283,8 @@ let MoveCursorController = (_a5 = class extends Disposable {
|
|
|
2244
3283
|
for (const divide of line.divides) {
|
|
2245
3284
|
const divideLeft = divide.left;
|
|
2246
3285
|
for (const glyph of divide.glyphGroup) {
|
|
3286
|
+
if (glyph.streamType === DataStreamTreeTokenType.SECTION_BREAK)
|
|
3287
|
+
continue;
|
|
2247
3288
|
const { left } = glyph, leftSide = divideLeft + left, distance = Math.abs(offsetLeft - leftSide);
|
|
2248
3289
|
distance < nearestNode.distance && (nearestNode.glyph = glyph, nearestNode.distance = distance);
|
|
2249
3290
|
}
|
|
@@ -2253,41 +3294,49 @@ let MoveCursorController = (_a5 = class extends Disposable {
|
|
|
2253
3294
|
const { segmentPage } = nodePosition;
|
|
2254
3295
|
return docSkeleton.findPositionByGlyph(nearestNode.glyph, segmentPage);
|
|
2255
3296
|
}
|
|
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)
|
|
3297
|
+
// eslint-disable-next-line max-lines-per-function, complexity
|
|
3298
|
+
_getNextOrPrevLine(glyph, direction, skipCellContent = !1) {
|
|
3299
|
+
var _a11, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
3300
|
+
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;
|
|
3301
|
+
if (divide == null || line == null || column == null || section == null || page == null)
|
|
2267
3302
|
return;
|
|
2268
3303
|
const currentLineIndex = column.lines.indexOf(line);
|
|
2269
3304
|
if (currentLineIndex === -1)
|
|
2270
3305
|
return;
|
|
2271
3306
|
let newLine;
|
|
2272
|
-
if (
|
|
3307
|
+
if (page.type === DocumentSkeletonPageType.CELL && skipCellContent) {
|
|
3308
|
+
const nLine = findAboveOrBellowCellLine(page, direction);
|
|
3309
|
+
if (nLine)
|
|
3310
|
+
return nLine;
|
|
3311
|
+
}
|
|
3312
|
+
if (direction === !0) {
|
|
3313
|
+
newLine = column.lines[currentLineIndex + 1];
|
|
3314
|
+
const tableAfterLine = findTableAfterLine(line, page);
|
|
3315
|
+
if (tableAfterLine) {
|
|
3316
|
+
const firstLine = firstLineInTable(tableAfterLine);
|
|
3317
|
+
firstLine && (newLine = firstLine);
|
|
3318
|
+
}
|
|
3319
|
+
} else {
|
|
3320
|
+
newLine = column.lines[currentLineIndex - 1];
|
|
3321
|
+
const tableBeforeLine = findTableBeforeLine(line, page);
|
|
3322
|
+
if (tableBeforeLine) {
|
|
3323
|
+
const lastLine = lastLineInTable(tableBeforeLine);
|
|
3324
|
+
lastLine && (newLine = lastLine);
|
|
3325
|
+
}
|
|
3326
|
+
}
|
|
3327
|
+
if (newLine != null)
|
|
2273
3328
|
return newLine;
|
|
2274
|
-
const section = column.parent;
|
|
2275
|
-
if (section == null)
|
|
2276
|
-
return;
|
|
2277
3329
|
const currentColumnIndex = section.columns.indexOf(column);
|
|
2278
3330
|
if (currentColumnIndex === -1)
|
|
2279
3331
|
return;
|
|
2280
3332
|
if (direction === !0)
|
|
2281
|
-
newLine = (
|
|
3333
|
+
newLine = (_a11 = section.columns[currentColumnIndex + 1]) == null ? void 0 : _a11.lines[0];
|
|
2282
3334
|
else {
|
|
2283
3335
|
const prevColumnLines = (_c = (_b = section.columns) == null ? void 0 : _b[currentColumnIndex - 1]) == null ? void 0 : _c.lines;
|
|
2284
3336
|
newLine = prevColumnLines == null ? void 0 : prevColumnLines[prevColumnLines.length - 1];
|
|
2285
3337
|
}
|
|
2286
3338
|
if (newLine != null)
|
|
2287
3339
|
return newLine;
|
|
2288
|
-
const page = section.parent;
|
|
2289
|
-
if (page == null)
|
|
2290
|
-
return;
|
|
2291
3340
|
const currentSectionIndex = page.sections.indexOf(section);
|
|
2292
3341
|
if (currentSectionIndex === -1)
|
|
2293
3342
|
return;
|
|
@@ -2299,6 +3348,8 @@ let MoveCursorController = (_a5 = class extends Disposable {
|
|
|
2299
3348
|
}
|
|
2300
3349
|
if (newLine != null)
|
|
2301
3350
|
return newLine;
|
|
3351
|
+
if (page.type === DocumentSkeletonPageType.CELL)
|
|
3352
|
+
return findAboveOrBellowCellLine(page, direction);
|
|
2302
3353
|
const skeleton = page.parent;
|
|
2303
3354
|
if (skeleton == null)
|
|
2304
3355
|
return;
|
|
@@ -2317,44 +3368,155 @@ let MoveCursorController = (_a5 = class extends Disposable {
|
|
|
2317
3368
|
return newLine;
|
|
2318
3369
|
}
|
|
2319
3370
|
}
|
|
2320
|
-
_getDocObject() {
|
|
2321
|
-
return getDocObject(this._univerInstanceService, this._renderManagerService);
|
|
3371
|
+
_getDocObject() {
|
|
3372
|
+
return getDocObject(this._univerInstanceService, this._renderManagerService);
|
|
3373
|
+
}
|
|
3374
|
+
}, __name(_a5, "MoveCursorController"), _a5);
|
|
3375
|
+
MoveCursorController = __decorateClass$5([
|
|
3376
|
+
OnLifecycle(LifecycleStages.Rendered, MoveCursorController),
|
|
3377
|
+
__decorateParam$5(0, IUniverInstanceService),
|
|
3378
|
+
__decorateParam$5(1, IRenderManagerService),
|
|
3379
|
+
__decorateParam$5(2, Inject(TextSelectionManagerService)),
|
|
3380
|
+
__decorateParam$5(3, ICommandService)
|
|
3381
|
+
], MoveCursorController);
|
|
3382
|
+
function findAboveOrBellowCellLine(page, direction) {
|
|
3383
|
+
var _a11, _b;
|
|
3384
|
+
let newLine = null;
|
|
3385
|
+
if (direction === !0) {
|
|
3386
|
+
const bellowCell = findBellowCell(page);
|
|
3387
|
+
if (bellowCell)
|
|
3388
|
+
newLine = firstLineInCell(bellowCell);
|
|
3389
|
+
else {
|
|
3390
|
+
const table = (_a11 = page.parent) == null ? void 0 : _a11.parent, { lineAfterTable } = findLineBeforeAndAfterTable(table);
|
|
3391
|
+
lineAfterTable && (newLine = lineAfterTable);
|
|
3392
|
+
}
|
|
3393
|
+
} else {
|
|
3394
|
+
const aboveCell = findAboveCell(page);
|
|
3395
|
+
if (aboveCell)
|
|
3396
|
+
newLine = lastLineInCell(aboveCell);
|
|
3397
|
+
else {
|
|
3398
|
+
const table = (_b = page.parent) == null ? void 0 : _b.parent, { lineBeforeTable } = findLineBeforeAndAfterTable(table);
|
|
3399
|
+
lineBeforeTable && (newLine = lineBeforeTable);
|
|
3400
|
+
}
|
|
3401
|
+
}
|
|
3402
|
+
return newLine != null, newLine;
|
|
3403
|
+
}
|
|
3404
|
+
__name(findAboveOrBellowCellLine, "findAboveOrBellowCellLine");
|
|
3405
|
+
var __defProp$4 = Object.defineProperty, __getOwnPropDesc$4 = Object.getOwnPropertyDescriptor, __decorateClass$4 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
3406
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$4(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
3407
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
3408
|
+
return kind && result && __defProp$4(target, key, result), result;
|
|
3409
|
+
}, "__decorateClass$4"), __decorateParam$4 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$4");
|
|
3410
|
+
function getParagraphsInRange(activeRange, paragraphs) {
|
|
3411
|
+
var _a11, _b;
|
|
3412
|
+
const { startOffset, endOffset } = activeRange, results = [];
|
|
3413
|
+
let start = -1;
|
|
3414
|
+
for (let i = 0; i < paragraphs.length; i++) {
|
|
3415
|
+
const paragraph = paragraphs[i], prevParagraph = paragraphs[i - 1], { startIndex } = paragraph;
|
|
3416
|
+
startOffset > start && startOffset <= startIndex || endOffset > start && endOffset <= startIndex ? results.push({
|
|
3417
|
+
...paragraph,
|
|
3418
|
+
paragraphStart: ((_a11 = prevParagraph == null ? void 0 : prevParagraph.startIndex) != null ? _a11 : -1) + 1,
|
|
3419
|
+
paragraphEnd: paragraph.startIndex
|
|
3420
|
+
}) : startIndex >= startOffset && startIndex <= endOffset && results.push({
|
|
3421
|
+
...paragraph,
|
|
3422
|
+
paragraphStart: ((_b = prevParagraph == null ? void 0 : prevParagraph.startIndex) != null ? _b : -1) + 1,
|
|
3423
|
+
paragraphEnd: paragraph.startIndex
|
|
3424
|
+
}), start = startIndex;
|
|
2322
3425
|
}
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
3426
|
+
return results;
|
|
3427
|
+
}
|
|
3428
|
+
__name(getParagraphsInRange, "getParagraphsInRange");
|
|
3429
|
+
var _a6;
|
|
3430
|
+
let DocAutoFormatService = (_a6 = class extends Disposable {
|
|
3431
|
+
constructor(_univerInstanceService, _textSelectionManagerService) {
|
|
3432
|
+
super();
|
|
3433
|
+
__publicField(this, "_matches", /* @__PURE__ */ new Map());
|
|
3434
|
+
this._univerInstanceService = _univerInstanceService, this._textSelectionManagerService = _textSelectionManagerService;
|
|
3435
|
+
}
|
|
3436
|
+
registerAutoFormat(match) {
|
|
3437
|
+
const matchList = this._matches.get(match.id);
|
|
3438
|
+
return matchList ? (matchList.push(match), matchList.sort((a, b) => {
|
|
3439
|
+
var _a11, _b;
|
|
3440
|
+
return ((_a11 = b.priority) != null ? _a11 : 0) - ((_b = a.priority) != null ? _b : 0);
|
|
3441
|
+
})) : this._matches.set(match.id, [match]), toDisposable(() => {
|
|
3442
|
+
const matchList2 = this._matches.get(match.id);
|
|
3443
|
+
if (matchList2) {
|
|
3444
|
+
const index = matchList2.findIndex((i) => i === match);
|
|
3445
|
+
index >= 0 && matchList2.splice(index, 1);
|
|
3446
|
+
}
|
|
3447
|
+
});
|
|
3448
|
+
}
|
|
3449
|
+
onAutoFormat(id, params) {
|
|
3450
|
+
var _a11, _b, _c, _d, _e, _f;
|
|
3451
|
+
const autoForamts = (_a11 = this._matches.get(id)) != null ? _a11 : [], unit = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC), selection = this._textSelectionManagerService.getActiveTextRangeWithStyle();
|
|
3452
|
+
if (unit && selection) {
|
|
3453
|
+
const doc = unit.getSelfOrHeaderFooterModel(selection.segmentId), context = {
|
|
3454
|
+
unit: doc,
|
|
3455
|
+
selection,
|
|
3456
|
+
isBody: !selection.segmentId,
|
|
3457
|
+
paragraphs: getParagraphsInRange(selection, (_c = (_b = doc.getBody()) == null ? void 0 : _b.paragraphs) != null ? _c : []),
|
|
3458
|
+
customRanges: getCustomRangesIntesetsWithRange(selection, (_e = (_d = doc.getBody()) == null ? void 0 : _d.customRanges) != null ? _e : []),
|
|
3459
|
+
commandId: id,
|
|
3460
|
+
commandParams: params
|
|
3461
|
+
}, matched = autoForamts.find((i) => i.match(context));
|
|
3462
|
+
return (_f = matched == null ? void 0 : matched.getMutations(context)) != null ? _f : [];
|
|
3463
|
+
}
|
|
3464
|
+
return [];
|
|
3465
|
+
}
|
|
3466
|
+
}, __name(_a6, "DocAutoFormatService"), _a6);
|
|
3467
|
+
DocAutoFormatService = __decorateClass$4([
|
|
2326
3468
|
__decorateParam$4(0, IUniverInstanceService),
|
|
2327
|
-
__decorateParam$4(1,
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
3469
|
+
__decorateParam$4(1, Inject(TextSelectionManagerService))
|
|
3470
|
+
], DocAutoFormatService);
|
|
3471
|
+
const TabCommandId = "doc.command.tab", TabCommand = {
|
|
3472
|
+
id: TabCommandId,
|
|
3473
|
+
type: CommandType.COMMAND,
|
|
3474
|
+
async handler(accessor, params) {
|
|
3475
|
+
const mutations = accessor.get(DocAutoFormatService).onAutoFormat(TabCommand.id, params);
|
|
3476
|
+
return (await sequenceExecuteAsync(mutations, accessor.get(ICommandService))).result;
|
|
3477
|
+
}
|
|
3478
|
+
}, AfterSpaceCommandId = "doc.command.after-space", AfterSpaceCommand = {
|
|
3479
|
+
id: AfterSpaceCommandId,
|
|
3480
|
+
type: CommandType.COMMAND,
|
|
3481
|
+
async handler(accessor) {
|
|
3482
|
+
const mutations = accessor.get(DocAutoFormatService).onAutoFormat(AfterSpaceCommand.id);
|
|
3483
|
+
return (await sequenceExecuteAsync(mutations, accessor.get(ICommandService))).result;
|
|
3484
|
+
}
|
|
3485
|
+
}, EnterCommand = {
|
|
3486
|
+
id: "doc.command.enter",
|
|
3487
|
+
type: CommandType.COMMAND,
|
|
3488
|
+
async handler(accessor) {
|
|
3489
|
+
const mutations = accessor.get(DocAutoFormatService).onAutoFormat(EnterCommand.id);
|
|
3490
|
+
return (await sequenceExecuteAsync(mutations, accessor.get(ICommandService))).result;
|
|
3491
|
+
}
|
|
3492
|
+
};
|
|
2331
3493
|
var __defProp$3 = Object.defineProperty, __getOwnPropDesc$3 = Object.getOwnPropertyDescriptor, __decorateClass$3 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
2332
3494
|
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$3(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
2333
3495
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
2334
3496
|
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 = (
|
|
3497
|
+
}, "__decorateClass$3"), __decorateParam$3 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$3"), _a7;
|
|
3498
|
+
let NormalInputController = (_a7 = class extends Disposable {
|
|
2337
3499
|
constructor(_univerInstanceService, _renderManagerService, _textSelectionRenderManager, _commandService) {
|
|
2338
3500
|
super();
|
|
2339
3501
|
__publicField(this, "_onInputSubscription");
|
|
2340
3502
|
this._univerInstanceService = _univerInstanceService, this._renderManagerService = _renderManagerService, this._textSelectionRenderManager = _textSelectionRenderManager, this._commandService = _commandService, this._init();
|
|
2341
3503
|
}
|
|
2342
3504
|
dispose() {
|
|
2343
|
-
var
|
|
2344
|
-
super.dispose(), (
|
|
3505
|
+
var _a11;
|
|
3506
|
+
super.dispose(), (_a11 = this._onInputSubscription) == null || _a11.unsubscribe();
|
|
2345
3507
|
}
|
|
2346
3508
|
_init() {
|
|
2347
3509
|
this._initialNormalInput();
|
|
2348
3510
|
}
|
|
2349
3511
|
_initialNormalInput() {
|
|
2350
3512
|
this._onInputSubscription = this._textSelectionRenderManager.onInput$.subscribe(async (config) => {
|
|
2351
|
-
var
|
|
3513
|
+
var _a11;
|
|
2352
3514
|
if (config == null)
|
|
2353
3515
|
return;
|
|
2354
3516
|
const documentModel = this._univerInstanceService.getCurrentUniverDocInstance();
|
|
2355
3517
|
if (!documentModel)
|
|
2356
3518
|
return;
|
|
2357
|
-
const unitId = documentModel.getUnitId(), { event, content = "", activeRange } = config, e = event, skeleton = (
|
|
3519
|
+
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
3520
|
if (e.data == null || skeleton == null || !skeleton || !activeRange)
|
|
2359
3521
|
return;
|
|
2360
3522
|
const { startOffset, segmentId, style, segmentPage } = activeRange, len = content.length, textRanges = [
|
|
@@ -2374,10 +3536,10 @@ let NormalInputController = (_a6 = class extends Disposable {
|
|
|
2374
3536
|
textRanges,
|
|
2375
3537
|
range: activeRange,
|
|
2376
3538
|
segmentId
|
|
2377
|
-
});
|
|
3539
|
+
}), content === " " && await this._commandService.executeCommand(AfterSpaceCommand.id);
|
|
2378
3540
|
});
|
|
2379
3541
|
}
|
|
2380
|
-
}, __name(
|
|
3542
|
+
}, __name(_a7, "NormalInputController"), _a7);
|
|
2381
3543
|
NormalInputController = __decorateClass$3([
|
|
2382
3544
|
OnLifecycle(LifecycleStages.Rendered, NormalInputController),
|
|
2383
3545
|
__decorateParam$3(0, IUniverInstanceService),
|
|
@@ -2386,20 +3548,23 @@ NormalInputController = __decorateClass$3([
|
|
|
2386
3548
|
__decorateParam$3(3, ICommandService)
|
|
2387
3549
|
], NormalInputController);
|
|
2388
3550
|
const AlignOperationCommand = {
|
|
2389
|
-
id: "doc.command.align-
|
|
3551
|
+
id: "doc.command.align-action",
|
|
2390
3552
|
type: CommandType.COMMAND,
|
|
2391
3553
|
// eslint-disable-next-line max-lines-per-function
|
|
2392
3554
|
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
|
|
3555
|
+
var _a11;
|
|
3556
|
+
const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), { alignType } = params, docDataModel = univerInstanceService.getCurrentUniverDocInstance();
|
|
3557
|
+
if (docDataModel == null)
|
|
2396
3558
|
return !1;
|
|
2397
|
-
const
|
|
3559
|
+
const allRanges = textSelectionManagerService.getDocRanges();
|
|
3560
|
+
if (allRanges.length === 0)
|
|
3561
|
+
return !1;
|
|
3562
|
+
const segmentId = allRanges[0].segmentId, paragraphs = (_a11 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a11.paragraphs, serializedSelections = allRanges.map(serializeDocRange);
|
|
2398
3563
|
if (paragraphs == null)
|
|
2399
3564
|
return !1;
|
|
2400
|
-
const currentParagraphs =
|
|
2401
|
-
var
|
|
2402
|
-
return ((
|
|
3565
|
+
const currentParagraphs = getParagraphsInRanges(allRanges, paragraphs), unitId = docDataModel.getUnitId(), isAlreadyAligned = currentParagraphs.every((paragraph) => {
|
|
3566
|
+
var _a12;
|
|
3567
|
+
return ((_a12 = paragraph.paragraphStyle) == null ? void 0 : _a12.horizontalAlign) === alignType;
|
|
2403
3568
|
}), doMutation = {
|
|
2404
3569
|
id: RichTextEditingMutation.id,
|
|
2405
3570
|
params: {
|
|
@@ -2470,14 +3635,14 @@ var __defProp$2 = Object.defineProperty, __getOwnPropDesc$2 = Object.getOwnPrope
|
|
|
2470
3635
|
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
2471
3636
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
2472
3637
|
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 = (
|
|
3638
|
+
}, "__decorateClass$2"), __decorateParam$2 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$2"), _a8;
|
|
3639
|
+
let DocCustomRangeController = (_a8 = class extends Disposable {
|
|
2475
3640
|
constructor(_commandService, _textSelectionManagerService, _univerInstanceService) {
|
|
2476
3641
|
super(), this._commandService = _commandService, this._textSelectionManagerService = _textSelectionManagerService, this._univerInstanceService = _univerInstanceService, this._initSelectionChange();
|
|
2477
3642
|
}
|
|
2478
3643
|
_transformCustomRange(doc, selection) {
|
|
2479
|
-
var
|
|
2480
|
-
const { startOffset, endOffset, collapsed } = selection, customRanges = (
|
|
3644
|
+
var _a11;
|
|
3645
|
+
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
3646
|
if (customRanges != null && customRanges.length) {
|
|
2482
3647
|
let start = startOffset, end = endOffset;
|
|
2483
3648
|
return customRanges.forEach((range) => {
|
|
@@ -2502,7 +3667,7 @@ let DocCustomRangeController = (_a7 = class extends Disposable {
|
|
|
2502
3667
|
}
|
|
2503
3668
|
}));
|
|
2504
3669
|
}
|
|
2505
|
-
}, __name(
|
|
3670
|
+
}, __name(_a8, "DocCustomRangeController"), _a8);
|
|
2506
3671
|
DocCustomRangeController = __decorateClass$2([
|
|
2507
3672
|
OnLifecycle(LifecycleStages.Ready, DocCustomRangeController),
|
|
2508
3673
|
__decorateParam$2(0, ICommandService),
|
|
@@ -2516,6 +3681,359 @@ const DocsRenameMutation = {
|
|
|
2516
3681
|
const doc = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
|
|
2517
3682
|
return doc ? (doc.setName(params.name), !0) : !1;
|
|
2518
3683
|
}, "handler")
|
|
3684
|
+
}, CreateDocTableCommandId = "doc.command.create-table", CreateDocTableCommand = {
|
|
3685
|
+
id: CreateDocTableCommandId,
|
|
3686
|
+
type: CommandType.COMMAND,
|
|
3687
|
+
// eslint-disable-next-line max-lines-per-function
|
|
3688
|
+
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
3689
|
+
var _a11, _b, _c, _d, _e, _f;
|
|
3690
|
+
const { rowCount, colCount } = params, textSelectionManagerService = accessor.get(TextSelectionManagerService$1), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), activeRange = textSelectionManagerService.getActiveTextRangeWithStyle();
|
|
3691
|
+
if (activeRange == null)
|
|
3692
|
+
return !1;
|
|
3693
|
+
const { segmentId, segmentPage } = activeRange, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), body = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
3694
|
+
if (docDataModel == null || body == null)
|
|
3695
|
+
return !1;
|
|
3696
|
+
const unitId = docDataModel.getUnitId(), docSkeletonManagerService = getCommandSkeleton$1(accessor, unitId), skeleton = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getSkeleton();
|
|
3697
|
+
if (skeleton == null)
|
|
3698
|
+
return !1;
|
|
3699
|
+
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";
|
|
3700
|
+
if (curGlyph == null || line == null)
|
|
3701
|
+
return !1;
|
|
3702
|
+
const needCreateParagraph = isInParagraph || line.isBehindTable, textX = new TextX(), jsonX = JSONX.getInstance(), rawActions = [], cursor = startOffset + (needCreateParagraph ? 4 : 3), textRanges = [{
|
|
3703
|
+
startOffset: cursor,
|
|
3704
|
+
endOffset: cursor,
|
|
3705
|
+
collapsed: !0
|
|
3706
|
+
}], doMutation = {
|
|
3707
|
+
id: RichTextEditingMutation$1.id,
|
|
3708
|
+
params: {
|
|
3709
|
+
unitId,
|
|
3710
|
+
actions: [],
|
|
3711
|
+
textRanges
|
|
3712
|
+
}
|
|
3713
|
+
};
|
|
3714
|
+
startOffset > 0 && textX.push({
|
|
3715
|
+
t: TextXActionType.RETAIN,
|
|
3716
|
+
len: startOffset,
|
|
3717
|
+
segmentId
|
|
3718
|
+
}), needCreateParagraph && textX.push({
|
|
3719
|
+
t: TextXActionType.INSERT,
|
|
3720
|
+
body: {
|
|
3721
|
+
dataStream: DataStreamTreeTokenType.PARAGRAPH,
|
|
3722
|
+
paragraphs: generateParagraphs$1(DataStreamTreeTokenType.PARAGRAPH, prevParagraph)
|
|
3723
|
+
},
|
|
3724
|
+
len: 1,
|
|
3725
|
+
line: 0,
|
|
3726
|
+
segmentId
|
|
3727
|
+
});
|
|
3728
|
+
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;
|
|
3729
|
+
if (page == null)
|
|
3730
|
+
return !1;
|
|
3731
|
+
const { pageWidth, marginLeft, marginRight } = page, tableSource = genTableSource(rowCount, colCount, pageWidth - marginLeft - marginRight);
|
|
3732
|
+
textX.push({
|
|
3733
|
+
t: TextXActionType.INSERT,
|
|
3734
|
+
body: {
|
|
3735
|
+
dataStream: tableDataStream,
|
|
3736
|
+
paragraphs: tableParagraphs,
|
|
3737
|
+
sectionBreaks,
|
|
3738
|
+
tables: [
|
|
3739
|
+
{
|
|
3740
|
+
startIndex: 0,
|
|
3741
|
+
endIndex: tableDataStream.length,
|
|
3742
|
+
tableId: tableSource.tableId
|
|
3743
|
+
}
|
|
3744
|
+
]
|
|
3745
|
+
},
|
|
3746
|
+
len: tableDataStream.length,
|
|
3747
|
+
line: 0,
|
|
3748
|
+
segmentId
|
|
3749
|
+
});
|
|
3750
|
+
const path = getRichTextEditPath$1(docDataModel, segmentId);
|
|
3751
|
+
rawActions.push(jsonX.editOp(textX.serialize(), path));
|
|
3752
|
+
const insertTableSource = jsonX.insertOp(["tableSource", tableSource.tableId], tableSource);
|
|
3753
|
+
return rawActions.push(insertTableSource), doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
3754
|
+
}, "handler")
|
|
3755
|
+
}, DocTableDeleteRowsCommand = {
|
|
3756
|
+
id: "doc.table.delete-rows",
|
|
3757
|
+
type: CommandType.COMMAND,
|
|
3758
|
+
// eslint-disable-next-line max-lines-per-function
|
|
3759
|
+
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
3760
|
+
const textSelectionManagerService = accessor.get(TextSelectionManagerService$1), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), activeRectRanges = textSelectionManagerService.getCurrentRectRanges(), activeTextRange = textSelectionManagerService.getActiveTextRange(), rangeInfo = getRangeInfoFromRanges(activeTextRange, activeRectRanges);
|
|
3761
|
+
if (rangeInfo == null)
|
|
3762
|
+
return !1;
|
|
3763
|
+
const { segmentId } = rangeInfo, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), body = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
3764
|
+
if (docDataModel == null || body == null)
|
|
3765
|
+
return !1;
|
|
3766
|
+
const docSkeletonManagerService = getCommandSkeleton$1(accessor, docDataModel.getUnitId());
|
|
3767
|
+
if (docSkeletonManagerService == null)
|
|
3768
|
+
return !1;
|
|
3769
|
+
const viewModel = docSkeletonManagerService.getViewModel(), unitId = docDataModel == null ? void 0 : docDataModel.getUnitId(), textX = new TextX(), jsonX = JSONX.getInstance(), actionParams = getDeleteRowsActionsParams(rangeInfo, viewModel);
|
|
3770
|
+
if (actionParams == null)
|
|
3771
|
+
return !1;
|
|
3772
|
+
const { offset, rowIndexes, len, tableId, cursor, selectWholeTable } = actionParams;
|
|
3773
|
+
if (selectWholeTable)
|
|
3774
|
+
return commandService.executeCommand(DocTableDeleteTableCommand.id);
|
|
3775
|
+
const rawActions = [], textRanges = [{
|
|
3776
|
+
startOffset: cursor,
|
|
3777
|
+
endOffset: cursor,
|
|
3778
|
+
collapsed: !0
|
|
3779
|
+
}], doMutation = {
|
|
3780
|
+
id: RichTextEditingMutation$1.id,
|
|
3781
|
+
params: {
|
|
3782
|
+
unitId,
|
|
3783
|
+
actions: [],
|
|
3784
|
+
textRanges
|
|
3785
|
+
}
|
|
3786
|
+
};
|
|
3787
|
+
offset > 0 && textX.push({
|
|
3788
|
+
t: TextXActionType.RETAIN,
|
|
3789
|
+
len: offset,
|
|
3790
|
+
segmentId
|
|
3791
|
+
}), textX.push({
|
|
3792
|
+
t: TextXActionType.DELETE,
|
|
3793
|
+
len,
|
|
3794
|
+
line: 0,
|
|
3795
|
+
segmentId
|
|
3796
|
+
});
|
|
3797
|
+
const path = getRichTextEditPath$1(docDataModel, segmentId);
|
|
3798
|
+
rawActions.push(jsonX.editOp(textX.serialize(), path));
|
|
3799
|
+
for (const index of rowIndexes.reverse()) {
|
|
3800
|
+
const action = jsonX.removeOp(["tableSource", tableId, "tableRows", index]);
|
|
3801
|
+
rawActions.push(action);
|
|
3802
|
+
}
|
|
3803
|
+
return doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
3804
|
+
}, "handler")
|
|
3805
|
+
}, DocTableDeleteColumnsCommand = {
|
|
3806
|
+
id: "doc.table.delete-columns",
|
|
3807
|
+
type: CommandType.COMMAND,
|
|
3808
|
+
// eslint-disable-next-line max-lines-per-function
|
|
3809
|
+
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
3810
|
+
const textSelectionManagerService = accessor.get(TextSelectionManagerService$1), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), activeRectRanges = textSelectionManagerService.getCurrentRectRanges(), activeTextRange = textSelectionManagerService.getActiveTextRange(), rangeInfo = getRangeInfoFromRanges(activeTextRange, activeRectRanges);
|
|
3811
|
+
if (rangeInfo == null)
|
|
3812
|
+
return !1;
|
|
3813
|
+
const { segmentId } = rangeInfo, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), body = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
3814
|
+
if (docDataModel == null || body == null)
|
|
3815
|
+
return !1;
|
|
3816
|
+
const docSkeletonManagerService = getCommandSkeleton$1(accessor, docDataModel.getUnitId());
|
|
3817
|
+
if (docSkeletonManagerService == null)
|
|
3818
|
+
return !1;
|
|
3819
|
+
const viewModel = docSkeletonManagerService.getViewModel(), unitId = docDataModel == null ? void 0 : docDataModel.getUnitId(), textX = new TextX(), jsonX = JSONX.getInstance(), actionParams = getDeleteColumnsActionParams(rangeInfo, viewModel);
|
|
3820
|
+
if (actionParams == null)
|
|
3821
|
+
return !1;
|
|
3822
|
+
const { offsets, columnIndexes, tableId, cursor, rowCount, selectWholeTable } = actionParams;
|
|
3823
|
+
if (selectWholeTable)
|
|
3824
|
+
return commandService.executeCommand(DocTableDeleteTableCommand.id);
|
|
3825
|
+
const rawActions = [], textRanges = [{
|
|
3826
|
+
startOffset: cursor,
|
|
3827
|
+
endOffset: cursor,
|
|
3828
|
+
collapsed: !0
|
|
3829
|
+
}], doMutation = {
|
|
3830
|
+
id: RichTextEditingMutation$1.id,
|
|
3831
|
+
params: {
|
|
3832
|
+
unitId,
|
|
3833
|
+
actions: [],
|
|
3834
|
+
textRanges
|
|
3835
|
+
}
|
|
3836
|
+
};
|
|
3837
|
+
for (const offset of offsets) {
|
|
3838
|
+
const { retain, delete: deleteLen } = offset;
|
|
3839
|
+
retain > 0 && textX.push({
|
|
3840
|
+
t: TextXActionType.RETAIN,
|
|
3841
|
+
len: retain,
|
|
3842
|
+
segmentId
|
|
3843
|
+
}), textX.push({
|
|
3844
|
+
t: TextXActionType.DELETE,
|
|
3845
|
+
len: deleteLen,
|
|
3846
|
+
line: 0,
|
|
3847
|
+
segmentId
|
|
3848
|
+
});
|
|
3849
|
+
}
|
|
3850
|
+
const path = getRichTextEditPath$1(docDataModel, segmentId);
|
|
3851
|
+
rawActions.push(jsonX.editOp(textX.serialize(), path)), columnIndexes.reverse();
|
|
3852
|
+
for (let i = 0; i < rowCount; i++)
|
|
3853
|
+
for (const index of columnIndexes) {
|
|
3854
|
+
const action = jsonX.removeOp(["tableSource", tableId, "tableRows", i, "tableCells", index]);
|
|
3855
|
+
rawActions.push(action);
|
|
3856
|
+
}
|
|
3857
|
+
for (const index of columnIndexes) {
|
|
3858
|
+
const action = jsonX.removeOp(["tableSource", tableId, "tableColumns", index]);
|
|
3859
|
+
rawActions.push(action);
|
|
3860
|
+
}
|
|
3861
|
+
return doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
3862
|
+
}, "handler")
|
|
3863
|
+
}, DocTableDeleteTableCommand = {
|
|
3864
|
+
id: "doc.table.delete-table",
|
|
3865
|
+
type: CommandType.COMMAND,
|
|
3866
|
+
// eslint-disable-next-line max-lines-per-function
|
|
3867
|
+
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
3868
|
+
const textSelectionManagerService = accessor.get(TextSelectionManagerService$1), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), activeRectRanges = textSelectionManagerService.getCurrentRectRanges(), activeTextRange = textSelectionManagerService.getActiveTextRange(), rangeInfo = getRangeInfoFromRanges(activeTextRange, activeRectRanges);
|
|
3869
|
+
if (rangeInfo == null)
|
|
3870
|
+
return !1;
|
|
3871
|
+
const { segmentId } = rangeInfo, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), body = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
3872
|
+
if (docDataModel == null || body == null)
|
|
3873
|
+
return !1;
|
|
3874
|
+
const docSkeletonManagerService = getCommandSkeleton$1(accessor, docDataModel.getUnitId());
|
|
3875
|
+
if (docSkeletonManagerService == null)
|
|
3876
|
+
return !1;
|
|
3877
|
+
const viewModel = docSkeletonManagerService.getViewModel(), unitId = docDataModel == null ? void 0 : docDataModel.getUnitId(), textX = new TextX(), jsonX = JSONX.getInstance(), actionParams = getDeleteTableActionParams(rangeInfo, viewModel);
|
|
3878
|
+
if (actionParams == null)
|
|
3879
|
+
return !1;
|
|
3880
|
+
const { offset, len, tableId, cursor } = actionParams, rawActions = [], textRanges = [{
|
|
3881
|
+
startOffset: cursor,
|
|
3882
|
+
endOffset: cursor,
|
|
3883
|
+
collapsed: !0
|
|
3884
|
+
}], doMutation = {
|
|
3885
|
+
id: RichTextEditingMutation$1.id,
|
|
3886
|
+
params: {
|
|
3887
|
+
unitId,
|
|
3888
|
+
actions: [],
|
|
3889
|
+
textRanges
|
|
3890
|
+
}
|
|
3891
|
+
};
|
|
3892
|
+
offset > 0 && textX.push({
|
|
3893
|
+
t: TextXActionType.RETAIN,
|
|
3894
|
+
len: offset,
|
|
3895
|
+
segmentId
|
|
3896
|
+
}), textX.push({
|
|
3897
|
+
t: TextXActionType.DELETE,
|
|
3898
|
+
len,
|
|
3899
|
+
line: 0,
|
|
3900
|
+
segmentId
|
|
3901
|
+
});
|
|
3902
|
+
const path = getRichTextEditPath$1(docDataModel, segmentId);
|
|
3903
|
+
rawActions.push(jsonX.editOp(textX.serialize(), path));
|
|
3904
|
+
const action = jsonX.removeOp(["tableSource", tableId]);
|
|
3905
|
+
return rawActions.push(action), doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
3906
|
+
}, "handler")
|
|
3907
|
+
}, 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 = {
|
|
3908
|
+
id: DocTableInsertRowAboveCommandId,
|
|
3909
|
+
type: CommandType.COMMAND,
|
|
3910
|
+
handler: /* @__PURE__ */ __name(async (accessor) => accessor.get(ICommandService).executeCommand(DocTableInsertRowCommandId, { position: INSERT_ROW_POSITION.ABOVE }), "handler")
|
|
3911
|
+
}, DocTableInsertRowBellowCommand = {
|
|
3912
|
+
id: DocTableInsertRowBellowCommandId,
|
|
3913
|
+
type: CommandType.COMMAND,
|
|
3914
|
+
handler: /* @__PURE__ */ __name(async (accessor) => accessor.get(ICommandService).executeCommand(DocTableInsertRowCommandId, { position: INSERT_ROW_POSITION.BELLOW }), "handler")
|
|
3915
|
+
}, DocTableInsertColumnLeftCommand = {
|
|
3916
|
+
id: DocTableInsertColumnLeftCommandId,
|
|
3917
|
+
type: CommandType.COMMAND,
|
|
3918
|
+
handler: /* @__PURE__ */ __name(async (accessor) => accessor.get(ICommandService).executeCommand(DocTableInsertColumnCommandId, { position: INSERT_COLUMN_POSITION.LEFT }), "handler")
|
|
3919
|
+
}, DocTableInsertColumnRightCommand = {
|
|
3920
|
+
id: DocTableInsertColumnRightCommandId,
|
|
3921
|
+
type: CommandType.COMMAND,
|
|
3922
|
+
handler: /* @__PURE__ */ __name(async (accessor) => accessor.get(ICommandService).executeCommand(DocTableInsertColumnCommandId, { position: INSERT_COLUMN_POSITION.RIGHT }), "handler")
|
|
3923
|
+
}, DocTableInsertRowCommand = {
|
|
3924
|
+
id: DocTableInsertRowCommandId,
|
|
3925
|
+
type: CommandType.COMMAND,
|
|
3926
|
+
// eslint-disable-next-line max-lines-per-function
|
|
3927
|
+
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
3928
|
+
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);
|
|
3929
|
+
if (rangeInfo == null)
|
|
3930
|
+
return !1;
|
|
3931
|
+
const { segmentId } = rangeInfo, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), body = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
3932
|
+
if (docDataModel == null || body == null)
|
|
3933
|
+
return !1;
|
|
3934
|
+
const docSkeletonManagerService = getCommandSkeleton$1(accessor, docDataModel.getUnitId());
|
|
3935
|
+
if (docSkeletonManagerService == null)
|
|
3936
|
+
return !1;
|
|
3937
|
+
const viewModel = docSkeletonManagerService.getViewModel(), unitId = docDataModel == null ? void 0 : docDataModel.getUnitId(), textX = new TextX(), jsonX = JSONX.getInstance(), actionParams = getInsertRowActionsParams(rangeInfo, position, viewModel);
|
|
3938
|
+
if (actionParams == null)
|
|
3939
|
+
return !1;
|
|
3940
|
+
const { offset, colCount, tableId, insertRowIndex } = actionParams, rawActions = [], cursor = offset + 2, textRanges = [{
|
|
3941
|
+
startOffset: cursor,
|
|
3942
|
+
endOffset: cursor,
|
|
3943
|
+
collapsed: !0
|
|
3944
|
+
}], doMutation = {
|
|
3945
|
+
id: RichTextEditingMutation$1.id,
|
|
3946
|
+
params: {
|
|
3947
|
+
unitId,
|
|
3948
|
+
actions: [],
|
|
3949
|
+
textRanges
|
|
3950
|
+
}
|
|
3951
|
+
};
|
|
3952
|
+
offset > 0 && textX.push({
|
|
3953
|
+
t: TextXActionType.RETAIN,
|
|
3954
|
+
len: offset,
|
|
3955
|
+
segmentId
|
|
3956
|
+
});
|
|
3957
|
+
const insertBody = getInsertRowBody(colCount);
|
|
3958
|
+
textX.push({
|
|
3959
|
+
t: TextXActionType.INSERT,
|
|
3960
|
+
body: insertBody,
|
|
3961
|
+
len: insertBody.dataStream.length,
|
|
3962
|
+
line: 0,
|
|
3963
|
+
segmentId
|
|
3964
|
+
});
|
|
3965
|
+
const path = getRichTextEditPath$1(docDataModel, segmentId);
|
|
3966
|
+
rawActions.push(jsonX.editOp(textX.serialize(), path));
|
|
3967
|
+
const insertRow = getEmptyTableRow(colCount), insertTableSource = jsonX.insertOp(["tableSource", tableId, "tableRows", insertRowIndex], insertRow);
|
|
3968
|
+
return rawActions.push(insertTableSource), doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
3969
|
+
}, "handler")
|
|
3970
|
+
}, DocTableInsertColumnCommand = {
|
|
3971
|
+
id: DocTableInsertColumnCommandId,
|
|
3972
|
+
type: CommandType.COMMAND,
|
|
3973
|
+
// eslint-disable-next-line max-lines-per-function
|
|
3974
|
+
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
3975
|
+
var _a11, _b, _c;
|
|
3976
|
+
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);
|
|
3977
|
+
if (rangeInfo == null)
|
|
3978
|
+
return !1;
|
|
3979
|
+
const { segmentId } = rangeInfo, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), body = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
3980
|
+
if (docDataModel == null || body == null)
|
|
3981
|
+
return !1;
|
|
3982
|
+
const docSkeletonManagerService = getCommandSkeleton$1(accessor, docDataModel.getUnitId());
|
|
3983
|
+
if (docSkeletonManagerService == null)
|
|
3984
|
+
return !1;
|
|
3985
|
+
const viewModel = docSkeletonManagerService.getViewModel(), unitId = docDataModel == null ? void 0 : docDataModel.getUnitId(), textX = new TextX(), jsonX = JSONX.getInstance(), actionParams = getInsertColumnActionsParams(rangeInfo, position, viewModel);
|
|
3986
|
+
if (actionParams == null)
|
|
3987
|
+
return !1;
|
|
3988
|
+
const { offsets, columnIndex, tableId, rowCount } = actionParams, rawActions = [], cursor = offsets[0] + 1, textRanges = [{
|
|
3989
|
+
startOffset: cursor,
|
|
3990
|
+
endOffset: cursor,
|
|
3991
|
+
collapsed: !0
|
|
3992
|
+
}], doMutation = {
|
|
3993
|
+
id: RichTextEditingMutation$1.id,
|
|
3994
|
+
params: {
|
|
3995
|
+
unitId,
|
|
3996
|
+
actions: [],
|
|
3997
|
+
textRanges
|
|
3998
|
+
}
|
|
3999
|
+
};
|
|
4000
|
+
for (const offset of offsets) {
|
|
4001
|
+
textX.push({
|
|
4002
|
+
t: TextXActionType.RETAIN,
|
|
4003
|
+
len: offset,
|
|
4004
|
+
segmentId
|
|
4005
|
+
});
|
|
4006
|
+
const insertBody = getInsertColumnBody();
|
|
4007
|
+
textX.push({
|
|
4008
|
+
t: TextXActionType.INSERT,
|
|
4009
|
+
body: insertBody,
|
|
4010
|
+
len: insertBody.dataStream.length,
|
|
4011
|
+
line: 0,
|
|
4012
|
+
segmentId
|
|
4013
|
+
});
|
|
4014
|
+
}
|
|
4015
|
+
const path = getRichTextEditPath$1(docDataModel, segmentId);
|
|
4016
|
+
rawActions.push(jsonX.editOp(textX.serialize(), path));
|
|
4017
|
+
for (let i = 0; i < rowCount; i++) {
|
|
4018
|
+
const insertCell = getEmptyTableCell(), insertTableSource = jsonX.insertOp(["tableSource", tableId, "tableRows", i, "tableCells", columnIndex], insertCell);
|
|
4019
|
+
rawActions.push(insertTableSource);
|
|
4020
|
+
}
|
|
4021
|
+
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);
|
|
4022
|
+
for (let i = 0; i < widths.length; i++) {
|
|
4023
|
+
const action = jsonX.replaceOp(["tableSource", tableId, "tableColumns", i, "size", "width", "v"], tableColumns[i].size.width.v, widths[i]);
|
|
4024
|
+
rawActions.push(action);
|
|
4025
|
+
}
|
|
4026
|
+
const insertCol = getTableColumn(newColWidth), insertTableColumn = jsonX.insertOp(["tableSource", tableId, "tableColumns", columnIndex], insertCol);
|
|
4027
|
+
return rawActions.push(insertTableColumn), doMutation.params.actions = rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
4028
|
+
}, "handler")
|
|
4029
|
+
}, DocTableTabCommand = {
|
|
4030
|
+
id: "doc.table.tab-in-table",
|
|
4031
|
+
type: CommandType.COMMAND,
|
|
4032
|
+
handler: /* @__PURE__ */ __name(async () => !0, "handler")
|
|
4033
|
+
}, DocTableShiftTabCommand = {
|
|
4034
|
+
id: "doc.table.shift-tab-in-table",
|
|
4035
|
+
type: CommandType.COMMAND,
|
|
4036
|
+
handler: /* @__PURE__ */ __name(async () => !0, "handler")
|
|
2519
4037
|
};
|
|
2520
4038
|
var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
2521
4039
|
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
@@ -2523,8 +4041,8 @@ var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPrope
|
|
|
2523
4041
|
return kind && result && __defProp$1(target, key, result), result;
|
|
2524
4042
|
}, "__decorateClass$1"), __decorateParam$1 = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam$1");
|
|
2525
4043
|
const PLUGIN_NAME = "DOCS_PLUGIN";
|
|
2526
|
-
var
|
|
2527
|
-
let UniverDocsPlugin = (
|
|
4044
|
+
var _a9;
|
|
4045
|
+
let UniverDocsPlugin = (_a9 = class extends Plugin {
|
|
2528
4046
|
constructor(_config = {}, _injector) {
|
|
2529
4047
|
super(), this._injector = _injector, this._initializeDependencies(_injector), this._initializeCommands();
|
|
2530
4048
|
}
|
|
@@ -2568,7 +4086,27 @@ let UniverDocsPlugin = (_a8 = class extends Plugin {
|
|
|
2568
4086
|
AlignRightCommand,
|
|
2569
4087
|
AlignOperationCommand,
|
|
2570
4088
|
AlignJustifyCommand,
|
|
2571
|
-
|
|
4089
|
+
CreateDocTableCommand,
|
|
4090
|
+
DocTableInsertRowCommand,
|
|
4091
|
+
DocTableInsertRowAboveCommand,
|
|
4092
|
+
DocTableInsertRowBellowCommand,
|
|
4093
|
+
DocTableInsertColumnCommand,
|
|
4094
|
+
DocTableInsertColumnLeftCommand,
|
|
4095
|
+
DocTableInsertColumnRightCommand,
|
|
4096
|
+
DocTableDeleteRowsCommand,
|
|
4097
|
+
DocTableDeleteColumnsCommand,
|
|
4098
|
+
DocTableDeleteTableCommand,
|
|
4099
|
+
DocTableTabCommand,
|
|
4100
|
+
DocTableShiftTabCommand,
|
|
4101
|
+
DocsRenameMutation,
|
|
4102
|
+
TabCommand,
|
|
4103
|
+
AfterSpaceCommand,
|
|
4104
|
+
EnterCommand,
|
|
4105
|
+
ChangeListNestingLevelCommand,
|
|
4106
|
+
ChangeListTypeCommand,
|
|
4107
|
+
CheckListCommand,
|
|
4108
|
+
ToggleCheckListCommand,
|
|
4109
|
+
QuickListCommand
|
|
2572
4110
|
].forEach((command) => {
|
|
2573
4111
|
this._injector.get(ICommandService).registerCommand(command);
|
|
2574
4112
|
});
|
|
@@ -2586,6 +4124,7 @@ let UniverDocsPlugin = (_a8 = class extends Plugin {
|
|
|
2586
4124
|
],
|
|
2587
4125
|
[TextSelectionManagerService],
|
|
2588
4126
|
[DocCustomRangeService],
|
|
4127
|
+
[DocAutoFormatService],
|
|
2589
4128
|
// controllers
|
|
2590
4129
|
[NormalInputController],
|
|
2591
4130
|
[IMEInputController],
|
|
@@ -2593,10 +4132,11 @@ let UniverDocsPlugin = (_a8 = class extends Plugin {
|
|
|
2593
4132
|
[DocCustomRangeController]
|
|
2594
4133
|
].forEach((d) => docInjector.add(d));
|
|
2595
4134
|
}
|
|
2596
|
-
}, __name(
|
|
4135
|
+
}, __name(_a9, "UniverDocsPlugin"), __publicField(_a9, "pluginName", PLUGIN_NAME), __publicField(_a9, "type", UniverInstanceType.UNIVER_DOC), _a9);
|
|
2597
4136
|
UniverDocsPlugin = __decorateClass$1([
|
|
2598
4137
|
__decorateParam$1(1, Inject(Injector))
|
|
2599
4138
|
], UniverDocsPlugin);
|
|
4139
|
+
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
4140
|
function addCustomRangeTextX(param, body) {
|
|
2601
4141
|
const { range, rangeId, rangeType, segmentId } = param, actualRange = getSelectionForAddCustomRange(range, body);
|
|
2602
4142
|
if (!actualRange)
|
|
@@ -2651,8 +4191,8 @@ function addCustomRangeFactory(param, body) {
|
|
|
2651
4191
|
}
|
|
2652
4192
|
__name(addCustomRangeFactory, "addCustomRangeFactory");
|
|
2653
4193
|
function addCustomRangeBySelectionFactory(accessor, param) {
|
|
2654
|
-
var
|
|
2655
|
-
const { segmentId, rangeId, rangeType, wholeEntity } = param, textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), selection = textSelectionManagerService.
|
|
4194
|
+
var _a11;
|
|
4195
|
+
const { segmentId, rangeId, rangeType, wholeEntity } = param, textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), selection = textSelectionManagerService.getActiveTextRangeWithStyle();
|
|
2656
4196
|
if (!selection)
|
|
2657
4197
|
return !1;
|
|
2658
4198
|
const documentDataModel = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
|
|
@@ -2661,7 +4201,7 @@ function addCustomRangeBySelectionFactory(accessor, param) {
|
|
|
2661
4201
|
const body = documentDataModel.getBody(), unitId = documentDataModel.getUnitId();
|
|
2662
4202
|
if (!body)
|
|
2663
4203
|
return !1;
|
|
2664
|
-
const { startOffset, endOffset } = normalizeSelection(selection), customRanges = (
|
|
4204
|
+
const { startOffset, endOffset } = normalizeSelection(selection), customRanges = (_a11 = body.customRanges) != null ? _a11 : [], relativeCustomRanges = [];
|
|
2665
4205
|
for (let i = 0, len = customRanges.length; i < len; i++) {
|
|
2666
4206
|
const customRange = customRanges[i];
|
|
2667
4207
|
if (customRange.rangeType === rangeType && Math.max(customRange.startIndex, startOffset) <= Math.min(customRange.endIndex, endOffset - 1) && relativeCustomRanges.push({ ...customRange }), customRange.startIndex >= endOffset)
|
|
@@ -2730,11 +4270,11 @@ function addCustomRangeBySelectionFactory(accessor, param) {
|
|
|
2730
4270
|
}
|
|
2731
4271
|
__name(addCustomRangeBySelectionFactory, "addCustomRangeBySelectionFactory");
|
|
2732
4272
|
function deleteCustomRangeTextX(accessor, params) {
|
|
2733
|
-
var
|
|
4273
|
+
var _a11, _b;
|
|
2734
4274
|
const { unitId, rangeId, segmentId } = params, documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId);
|
|
2735
4275
|
if (!documentDataModel)
|
|
2736
4276
|
return !1;
|
|
2737
|
-
const range = (_b = (
|
|
4277
|
+
const range = (_b = (_a11 = documentDataModel.getBody()) == null ? void 0 : _a11.customRanges) == null ? void 0 : _b.find((r) => r.rangeId === rangeId);
|
|
2738
4278
|
if (!range)
|
|
2739
4279
|
return !1;
|
|
2740
4280
|
const { startIndex, endIndex } = range, textX = new TextX(), len = endIndex - startIndex + 1;
|
|
@@ -2772,7 +4312,7 @@ function deleteCustomRangeFactory(accessor, params) {
|
|
|
2772
4312
|
}
|
|
2773
4313
|
__name(deleteCustomRangeFactory, "deleteCustomRangeFactory");
|
|
2774
4314
|
function addCustomDecorationFactory(param) {
|
|
2775
|
-
const { unitId,
|
|
4315
|
+
const { unitId, ranges, id, type, segmentId } = param, doMutation = {
|
|
2776
4316
|
id: RichTextEditingMutation.id,
|
|
2777
4317
|
params: {
|
|
2778
4318
|
unitId,
|
|
@@ -2780,29 +4320,34 @@ function addCustomDecorationFactory(param) {
|
|
|
2780
4320
|
textRanges: void 0
|
|
2781
4321
|
}
|
|
2782
4322
|
}, textX = new TextX(), jsonX = JSONX.getInstance();
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
4323
|
+
let cursor = 0;
|
|
4324
|
+
for (let i = 0; i < ranges.length; i++) {
|
|
4325
|
+
const range = ranges[i], { startOffset: start, endOffset: end } = range;
|
|
4326
|
+
start > 0 && textX.push({
|
|
4327
|
+
t: TextXActionType.RETAIN,
|
|
4328
|
+
len: start - cursor,
|
|
4329
|
+
segmentId
|
|
4330
|
+
}), textX.push({
|
|
4331
|
+
t: TextXActionType.RETAIN,
|
|
4332
|
+
body: {
|
|
4333
|
+
dataStream: "",
|
|
4334
|
+
customDecorations: [{
|
|
4335
|
+
id,
|
|
4336
|
+
type,
|
|
4337
|
+
startIndex: 0,
|
|
4338
|
+
endIndex: end - start - 1
|
|
4339
|
+
}]
|
|
4340
|
+
},
|
|
4341
|
+
len: end - start,
|
|
4342
|
+
segmentId
|
|
4343
|
+
}), cursor = end;
|
|
4344
|
+
}
|
|
4345
|
+
return doMutation.params.actions = jsonX.editOp(textX.serialize()), doMutation;
|
|
2801
4346
|
}
|
|
2802
4347
|
__name(addCustomDecorationFactory, "addCustomDecorationFactory");
|
|
2803
4348
|
function addCustomDecorationBySelectionFactory(accessor, param) {
|
|
2804
|
-
const { segmentId, id, type } = param, textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService),
|
|
2805
|
-
if (!
|
|
4349
|
+
const { segmentId, id, type } = param, textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), selections = textSelectionManagerService.getCurrentTextRanges();
|
|
4350
|
+
if (!selections)
|
|
2806
4351
|
return !1;
|
|
2807
4352
|
const documentDataModel = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
|
|
2808
4353
|
if (!documentDataModel)
|
|
@@ -2811,11 +4356,7 @@ function addCustomDecorationBySelectionFactory(accessor, param) {
|
|
|
2811
4356
|
return body ? addCustomDecorationFactory(
|
|
2812
4357
|
{
|
|
2813
4358
|
unitId,
|
|
2814
|
-
|
|
2815
|
-
startOffset: selection.startOffset,
|
|
2816
|
-
endOffset: selection.endOffset,
|
|
2817
|
-
collapsed: !0
|
|
2818
|
-
},
|
|
4359
|
+
ranges: selections.map(serializeDocRange),
|
|
2819
4360
|
id,
|
|
2820
4361
|
type,
|
|
2821
4362
|
segmentId
|
|
@@ -2824,17 +4365,17 @@ function addCustomDecorationBySelectionFactory(accessor, param) {
|
|
|
2824
4365
|
}
|
|
2825
4366
|
__name(addCustomDecorationBySelectionFactory, "addCustomDecorationBySelectionFactory");
|
|
2826
4367
|
function deleteCustomDecorationFactory(accessor, params) {
|
|
2827
|
-
var
|
|
4368
|
+
var _a11, _b;
|
|
2828
4369
|
const { unitId, id, segmentId } = params, documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId), body = documentDataModel == null ? void 0 : documentDataModel.getBody();
|
|
2829
4370
|
if (!documentDataModel || !body)
|
|
2830
4371
|
return !1;
|
|
2831
|
-
const decorations = (_b = (
|
|
4372
|
+
const decorations = (_b = (_a11 = documentDataModel.getBody()) == null ? void 0 : _a11.customDecorations) == null ? void 0 : _b.filter((d) => d.id === id);
|
|
2832
4373
|
if (!(decorations != null && decorations.length))
|
|
2833
4374
|
return !1;
|
|
2834
4375
|
const oldBodySlices = decorations.map((i) => getBodySlice(body, i.startIndex, i.endIndex + 1)), bodySlices = oldBodySlices.map((bodySlice) => {
|
|
2835
|
-
var
|
|
4376
|
+
var _a12;
|
|
2836
4377
|
const copy = Tools.deepClone(bodySlice);
|
|
2837
|
-
return copy.customDecorations = (
|
|
4378
|
+
return copy.customDecorations = (_a12 = copy.customDecorations) == null ? void 0 : _a12.filter((decoration) => decoration.id !== id), copy;
|
|
2838
4379
|
}), doMutation = {
|
|
2839
4380
|
id: RichTextEditingMutation.id,
|
|
2840
4381
|
params: {
|
|
@@ -2869,8 +4410,8 @@ var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnProperty
|
|
|
2869
4410
|
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
2870
4411
|
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
2871
4412
|
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 = (
|
|
4413
|
+
}, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), _a10;
|
|
4414
|
+
let DocInterceptorService = (_a10 = class extends Disposable {
|
|
2874
4415
|
constructor(_context, _docSkeletonManagerService) {
|
|
2875
4416
|
super();
|
|
2876
4417
|
__publicField(this, "_interceptorsByName", /* @__PURE__ */ new Map());
|
|
@@ -2893,8 +4434,8 @@ let DocInterceptorService = (_a9 = class extends Disposable {
|
|
|
2893
4434
|
return interceptors.push(interceptor), this._interceptorsByName.set(
|
|
2894
4435
|
key,
|
|
2895
4436
|
interceptors.sort((a, b) => {
|
|
2896
|
-
var
|
|
2897
|
-
return ((
|
|
4437
|
+
var _a11, _b;
|
|
4438
|
+
return ((_a11 = b.priority) != null ? _a11 : 0) - ((_b = a.priority) != null ? _b : 0);
|
|
2898
4439
|
})
|
|
2899
4440
|
), this.disposeWithMe(toDisposable(() => remove(this._interceptorsByName.get(key), interceptor)));
|
|
2900
4441
|
}
|
|
@@ -2906,36 +4447,36 @@ let DocInterceptorService = (_a9 = class extends Disposable {
|
|
|
2906
4447
|
const disposableCollection = new DisposableCollection();
|
|
2907
4448
|
return disposableCollection.add(viewModel.registerCustomRangeInterceptor({
|
|
2908
4449
|
getCustomRange: /* @__PURE__ */ __name((index) => {
|
|
2909
|
-
var
|
|
4450
|
+
var _a11;
|
|
2910
4451
|
return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE)(
|
|
2911
4452
|
viewModel.getCustomRangeRaw(index),
|
|
2912
4453
|
{
|
|
2913
4454
|
index,
|
|
2914
4455
|
unitId: viewModel.getDataModel().getUnitId(),
|
|
2915
|
-
customRanges: (
|
|
4456
|
+
customRanges: (_a11 = viewModel.getDataModel().getCustomRanges()) != null ? _a11 : []
|
|
2916
4457
|
}
|
|
2917
4458
|
);
|
|
2918
4459
|
}, "getCustomRange"),
|
|
2919
4460
|
getCustomDecoration: /* @__PURE__ */ __name((index) => {
|
|
2920
|
-
var
|
|
4461
|
+
var _a11;
|
|
2921
4462
|
return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION)(
|
|
2922
4463
|
viewModel.getCustomDecorationRaw(index),
|
|
2923
4464
|
{
|
|
2924
4465
|
index,
|
|
2925
4466
|
unitId: viewModel.getDataModel().getUnitId(),
|
|
2926
|
-
customDecorations: (
|
|
4467
|
+
customDecorations: (_a11 = viewModel.getDataModel().getCustomDecorations()) != null ? _a11 : []
|
|
2927
4468
|
}
|
|
2928
4469
|
);
|
|
2929
4470
|
}, "getCustomDecoration")
|
|
2930
4471
|
})), disposableCollection;
|
|
2931
4472
|
}
|
|
2932
|
-
}, __name(
|
|
4473
|
+
}, __name(_a10, "DocInterceptorService"), _a10);
|
|
2933
4474
|
DocInterceptorService = __decorateClass([
|
|
2934
4475
|
OnLifecycle(LifecycleStages.Starting, DocInterceptorService),
|
|
2935
4476
|
__decorateParam(1, Inject(DocSkeletonManagerService))
|
|
2936
4477
|
], 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
4478
|
export {
|
|
4479
|
+
AfterSpaceCommand,
|
|
2939
4480
|
AlignCenterCommand,
|
|
2940
4481
|
AlignJustifyCommand,
|
|
2941
4482
|
AlignLeftCommand,
|
|
@@ -2943,7 +4484,12 @@ export {
|
|
|
2943
4484
|
AlignRightCommand,
|
|
2944
4485
|
BreakLineCommand,
|
|
2945
4486
|
BulletListCommand,
|
|
4487
|
+
ChangeListNestingLevelCommand,
|
|
4488
|
+
ChangeListNestingLevelType,
|
|
4489
|
+
ChangeListTypeCommand,
|
|
4490
|
+
CheckListCommand,
|
|
2946
4491
|
CoverContentCommand,
|
|
4492
|
+
CreateDocTableCommand,
|
|
2947
4493
|
CutContentCommand,
|
|
2948
4494
|
DOCS_COMPONENT_BACKGROUND_LAYER_INDEX,
|
|
2949
4495
|
DOCS_COMPONENT_DEFAULT_Z_INDEX,
|
|
@@ -2955,11 +4501,24 @@ export {
|
|
|
2955
4501
|
DeleteCustomBlockCommand,
|
|
2956
4502
|
DeleteLeftCommand,
|
|
2957
4503
|
DeleteRightCommand,
|
|
4504
|
+
DocAutoFormatService,
|
|
2958
4505
|
DocCustomRangeService,
|
|
2959
4506
|
DocInterceptorService,
|
|
2960
4507
|
DocSkeletonManagerService,
|
|
2961
4508
|
DocStateChangeManagerService,
|
|
4509
|
+
DocTableDeleteColumnsCommand,
|
|
4510
|
+
DocTableDeleteRowsCommand,
|
|
4511
|
+
DocTableDeleteTableCommand,
|
|
4512
|
+
DocTableInsertColumnCommand,
|
|
4513
|
+
DocTableInsertColumnLeftCommand,
|
|
4514
|
+
DocTableInsertColumnRightCommand,
|
|
4515
|
+
DocTableInsertRowAboveCommand,
|
|
4516
|
+
DocTableInsertRowBellowCommand,
|
|
4517
|
+
DocTableInsertRowCommand,
|
|
4518
|
+
DocTableShiftTabCommand,
|
|
4519
|
+
DocTableTabCommand,
|
|
2962
4520
|
EditorInsertTextCommandId,
|
|
4521
|
+
EnterCommand,
|
|
2963
4522
|
IMEInputCommand,
|
|
2964
4523
|
IMEInputManagerService,
|
|
2965
4524
|
InnerPasteCommand,
|
|
@@ -2970,6 +4529,7 @@ export {
|
|
|
2970
4529
|
MoveSelectionOperation,
|
|
2971
4530
|
NORMAL_TEXT_SELECTION_PLUGIN_NAME,
|
|
2972
4531
|
OrderListCommand,
|
|
4532
|
+
QuickListCommand,
|
|
2973
4533
|
ReplaceContentCommand,
|
|
2974
4534
|
ResetInlineFormatTextBackgroundColorCommand,
|
|
2975
4535
|
RichTextEditingMutation,
|
|
@@ -2988,7 +4548,9 @@ export {
|
|
|
2988
4548
|
SetInlineFormatTextColorCommand,
|
|
2989
4549
|
SetInlineFormatUnderlineCommand,
|
|
2990
4550
|
SetTextSelectionsOperation,
|
|
4551
|
+
TabCommand,
|
|
2991
4552
|
TextSelectionManagerService,
|
|
4553
|
+
ToggleCheckListCommand,
|
|
2992
4554
|
UniverDocsPlugin,
|
|
2993
4555
|
UpdateCommand,
|
|
2994
4556
|
VIEWPORT_KEY,
|
|
@@ -2998,16 +4560,26 @@ export {
|
|
|
2998
4560
|
addCustomRangeFactory,
|
|
2999
4561
|
deleteCustomDecorationFactory,
|
|
3000
4562
|
deleteCustomRangeFactory,
|
|
4563
|
+
genTableSource,
|
|
4564
|
+
generateParagraphs,
|
|
4565
|
+
getCommandSkeleton,
|
|
4566
|
+
getCursorWhenDelete,
|
|
3001
4567
|
getDeleteSelection,
|
|
3002
4568
|
getDocObject,
|
|
3003
4569
|
getDocObjectById,
|
|
4570
|
+
getEmptyTableCell,
|
|
4571
|
+
getEmptyTableRow,
|
|
3004
4572
|
getInsertSelection,
|
|
4573
|
+
getParagraphsInRange$1 as getParagraphsInRange,
|
|
4574
|
+
getParagraphsInRanges,
|
|
3005
4575
|
getPlainTextFormDocument,
|
|
3006
4576
|
getRetainAndDeleteFromReplace,
|
|
3007
4577
|
getRichTextEditPath,
|
|
3008
4578
|
getSelectionText,
|
|
4579
|
+
getTableColumn,
|
|
3009
4580
|
isSegmentIntersects,
|
|
4581
|
+
makeSelection,
|
|
3010
4582
|
neoGetDocObject,
|
|
3011
4583
|
replaceSelectionFactory,
|
|
3012
|
-
|
|
4584
|
+
serializeDocRange
|
|
3013
4585
|
};
|