@univerjs/docs 0.2.7 → 0.2.9
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 -3
- package/lib/es/index.js +200 -147
- package/lib/types/basics/component-tools.d.ts +0 -1
- package/lib/types/basics/custom-decoration-factory.d.ts +0 -1
- package/lib/types/basics/custom-range-factory.d.ts +0 -2
- package/lib/types/basics/custom-range.d.ts +1 -2
- package/lib/types/basics/paragraph.d.ts +2 -0
- package/lib/types/basics/plain-text.d.ts +5 -2
- package/lib/types/basics/replace.d.ts +5 -4
- package/lib/types/basics/retain-delete-params.d.ts +0 -1
- package/lib/types/basics/selection.d.ts +1 -2
- package/lib/types/basics/table.d.ts +0 -3
- package/lib/types/commands/commands/__tests__/create-command-test-bed.d.ts +0 -1
- package/lib/types/commands/commands/__tests__/mock-text-selection-render-manager.d.ts +0 -1
- package/lib/types/commands/commands/auto-format.command.d.ts +0 -1
- package/lib/types/commands/commands/break-line.command.d.ts +0 -1
- package/lib/types/commands/commands/clipboard.inner.command.d.ts +0 -1
- package/lib/types/commands/commands/core-editing.command.d.ts +0 -2
- package/lib/types/commands/commands/delete.command.d.ts +0 -1
- package/lib/types/commands/commands/ime-input.command.d.ts +0 -1
- package/lib/types/commands/commands/inline-format.command.d.ts +0 -1
- package/lib/types/commands/commands/list.command.d.ts +1 -1
- package/lib/types/commands/commands/paragraph-align.command.d.ts +0 -1
- package/lib/types/commands/commands/replace-content.command.d.ts +0 -1
- package/lib/types/commands/commands/set-doc-zoom-ratio.command.d.ts +0 -1
- package/lib/types/commands/commands/table/doc-table-create.command.d.ts +0 -1
- package/lib/types/commands/commands/table/doc-table-delete.command.d.ts +0 -1
- package/lib/types/commands/commands/table/doc-table-insert.command.d.ts +0 -1
- package/lib/types/commands/commands/table/doc-table-tab.command.d.ts +1 -4
- package/lib/types/commands/commands/table/table.d.ts +10 -1
- package/lib/types/commands/mutations/core-editing.mutation.d.ts +0 -1
- package/lib/types/commands/mutations/docs-rename.mutation.d.ts +0 -1
- package/lib/types/commands/operations/cursor.operation.d.ts +0 -1
- package/lib/types/commands/operations/select-all.operation.d.ts +0 -1
- package/lib/types/commands/operations/set-doc-zoom-ratio.operation.d.ts +0 -1
- package/lib/types/commands/operations/text-selection.operation.d.ts +0 -1
- package/lib/types/commands/util.d.ts +0 -1
- package/lib/types/controllers/custom-range.controller.d.ts +0 -1
- package/lib/types/controllers/ime-input.controller.d.ts +0 -1
- package/lib/types/controllers/move-cursor.controller.d.ts +0 -1
- package/lib/types/controllers/normal-input.controller.d.ts +0 -1
- package/lib/types/doc-plugin.d.ts +0 -1
- package/lib/types/index.d.ts +5 -3
- package/lib/types/services/doc-auto-format.service.d.ts +4 -5
- package/lib/types/services/doc-custom-range.service.d.ts +0 -1
- package/lib/types/services/doc-interceptor/doc-interceptor.service.d.ts +2 -3
- package/lib/types/services/doc-interceptor/interceptor-const.d.ts +0 -1
- package/lib/types/services/doc-skeleton-manager.service.d.ts +0 -1
- package/lib/types/services/doc-state-change-manager.service.d.ts +0 -1
- package/lib/types/services/doc-view-model-manager.service.d.ts +0 -1
- package/lib/types/services/ime-input-manager.service.d.ts +0 -1
- package/lib/types/services/text-selection-manager.service.d.ts +0 -1
- package/lib/umd/index.js +4 -3
- package/package.json +8 -8
package/lib/es/index.js
CHANGED
|
@@ -2,10 +2,42 @@ 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,
|
|
5
|
+
import { DataStreamTreeTokenType, CommandType, RxDisposable, ICommandService, Inject, IUndoRedoService, UndoCommandId, RedoCommandId, JSONX, IUniverInstanceService, LocaleService, UniverInstanceType, isInternalEditorID, Tools, PresetListType, MemoryCursor, TextX, PRESET_LIST_TYPE, GridType, TextXActionType, UpdateDocsAttributeType, sortRulesFactory, toDisposable, normalizeBody, getBodySlice, updateAttributeByInsert, BooleanNumber, TableCellHeightRule, TableSizeType, generateRandomId, TableAlignmentType, TableTextWrapType, ObjectRelativeFromH, ObjectRelativeFromV, PositionedObjectLayoutType, getCustomRangeSlice, getCustomDecorationSlice, BaselineOffset, OnLifecycle, LifecycleStages, Disposable, Direction, sequenceExecuteAsync, HorizontalAlign, Plugin, Injector, createInterceptorKey, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DisposableCollection, remove, composeInterceptors } from "@univerjs/core";
|
|
6
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
8
|
import { TextSelectionManagerService as TextSelectionManagerService$1, getCommandSkeleton as getCommandSkeleton$1, getInsertSelection as getInsertSelection$1, RichTextEditingMutation as RichTextEditingMutation$1, generateParagraphs as generateParagraphs$1, getRichTextEditPath as getRichTextEditPath$1 } from "@univerjs/docs";
|
|
9
|
+
function isCustomRangeSplitSymbol(text) {
|
|
10
|
+
return text === DataStreamTreeTokenType.CUSTOM_RANGE_END || text === DataStreamTreeTokenType.CUSTOM_RANGE_START;
|
|
11
|
+
}
|
|
12
|
+
__name(isCustomRangeSplitSymbol, "isCustomRangeSplitSymbol");
|
|
13
|
+
function isIntersecting(line1Start, line1End, line2Start, line2End) {
|
|
14
|
+
return line1Start <= line2Start && line1End >= line2Start || line1Start >= line2Start && line1Start <= line2End;
|
|
15
|
+
}
|
|
16
|
+
__name(isIntersecting, "isIntersecting");
|
|
17
|
+
function shouldDeleteCustomRange(deleteStart, deleteLen, customRange, dataStream) {
|
|
18
|
+
const dataStreamSlice = dataStream.slice(customRange.startIndex + 1, customRange.endIndex), start = Math.max(deleteStart - (customRange.startIndex + 1), 0), end = deleteStart + deleteLen - 1 - (customRange.startIndex + 1);
|
|
19
|
+
if (end < 0)
|
|
20
|
+
return !1;
|
|
21
|
+
if (start === 0 && end >= dataStreamSlice.length)
|
|
22
|
+
return !0;
|
|
23
|
+
const result = dataStreamSlice.slice(0, start) + dataStreamSlice.slice(start + deleteLen);
|
|
24
|
+
for (let i = 0, len = result.length; i < len; i++) {
|
|
25
|
+
const letter = result[i];
|
|
26
|
+
if (!isCustomRangeSplitSymbol(letter))
|
|
27
|
+
return !1;
|
|
28
|
+
}
|
|
29
|
+
return !0;
|
|
30
|
+
}
|
|
31
|
+
__name(shouldDeleteCustomRange, "shouldDeleteCustomRange");
|
|
32
|
+
function getCustomRangesInterestsWithRange(range, customRanges) {
|
|
33
|
+
const result = [];
|
|
34
|
+
for (let i = 0, len = customRanges.length; i < len; i++) {
|
|
35
|
+
const customRange = customRanges[i];
|
|
36
|
+
range.collapsed ? customRange.startIndex < range.startOffset && range.startOffset <= customRange.endIndex && result.push(customRange) : isIntersecting(range.startOffset, range.endOffset, customRange.startIndex, customRange.endIndex) && result.push(customRange);
|
|
37
|
+
}
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
__name(getCustomRangesInterestsWithRange, "getCustomRangesInterestsWithRange");
|
|
9
41
|
const SetTextSelectionsOperation = {
|
|
10
42
|
id: "doc.operation.set-selections",
|
|
11
43
|
type: CommandType.OPERATION,
|
|
@@ -155,7 +187,7 @@ let TextSelectionManagerService = (_a = class extends RxDisposable {
|
|
|
155
187
|
if (this._textSelectionRenderManager.removeAllRanges(), allTextSelectionInfo == null)
|
|
156
188
|
return;
|
|
157
189
|
const { textRanges, rectRanges } = allTextSelectionInfo, docRanges = [...textRanges, ...rectRanges];
|
|
158
|
-
docRanges.length > 0 && this._textSelectionRenderManager.addDocRanges(docRanges.map(serializeDocRange));
|
|
190
|
+
docRanges.length > 0 && this._textSelectionRenderManager.addDocRanges(docRanges.map(serializeDocRange), !1);
|
|
159
191
|
}
|
|
160
192
|
_replaceByParam(insertParam) {
|
|
161
193
|
const { unitId, subUnitId, style, segmentId, textRanges, rectRanges, isEditing, segmentPage } = insertParam;
|
|
@@ -362,7 +394,7 @@ let DocSkeletonManagerService = (_a3 = class extends RxDisposable {
|
|
|
362
394
|
const unitId = this._context.unitId;
|
|
363
395
|
if (documentDataModel.getBody() == null)
|
|
364
396
|
return;
|
|
365
|
-
this._docViewModel && unitId
|
|
397
|
+
this._docViewModel && isInternalEditorID(unitId) ? (this._docViewModel.reset(documentDataModel), this._context.unit = documentDataModel) : this._docViewModel || (this._docViewModel = this._buildDocViewModel(documentDataModel)), this._skeleton || (this._skeleton = this._buildSkeleton(this._docViewModel));
|
|
366
398
|
const skeleton = this._skeleton;
|
|
367
399
|
skeleton.calculate(), this._currentSkeletonBefore$.next(skeleton), this._currentSkeleton$.next(skeleton), this._currentViewModel$.next(this._docViewModel);
|
|
368
400
|
}
|
|
@@ -456,6 +488,10 @@ function getRichTextEditPath(docDataModel, segmentId = "") {
|
|
|
456
488
|
throw new Error("Segment id not found in headers or footers");
|
|
457
489
|
}
|
|
458
490
|
__name(getRichTextEditPath, "getRichTextEditPath");
|
|
491
|
+
function hasParagraphInTable(paragraph, tables) {
|
|
492
|
+
return tables.some((table) => paragraph.startIndex > table.startIndex && paragraph.startIndex < table.endIndex);
|
|
493
|
+
}
|
|
494
|
+
__name(hasParagraphInTable, "hasParagraphInTable");
|
|
459
495
|
const ListOperationCommand = {
|
|
460
496
|
id: "doc.command.list-operation",
|
|
461
497
|
type: CommandType.COMMAND,
|
|
@@ -493,7 +529,7 @@ const ListOperationCommand = {
|
|
|
493
529
|
...customLists
|
|
494
530
|
}, { defaultTabStop = 36 } = docDataModel.getSnapshot().documentStyle;
|
|
495
531
|
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,
|
|
532
|
+
const { startIndex, paragraphStyle = {}, bullet } = paragraph, { indentFirstLine, snapToGrid, indentStart } = paragraphStyle, paragraphProperties = lists[listType].nestingLevel[0].paragraphProperties || {}, { hanging: listHanging, indentStart: listIndentStart } = paragraphProperties, { charSpace, gridType } = findNearestSectionBreak(startIndex, sectionBreaks) || { charSpace: 0, gridType: GridType.LINES }, charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);
|
|
497
533
|
textX.push({
|
|
498
534
|
t: TextXActionType.RETAIN,
|
|
499
535
|
len: startIndex - memoryCursor.cursor,
|
|
@@ -508,26 +544,13 @@ const ListOperationCommand = {
|
|
|
508
544
|
paragraphStyle: {
|
|
509
545
|
...paragraphStyle,
|
|
510
546
|
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
|
-
}
|
|
547
|
+
indentStart: indentStart ? { v: Math.max(0, getNumberUnitValue(indentStart, charSpaceApply) + getNumberUnitValue(listHanging, charSpaceApply) - getNumberUnitValue(listIndentStart, charSpaceApply)) } : void 0
|
|
516
548
|
},
|
|
517
549
|
startIndex: 0
|
|
518
550
|
} : {
|
|
519
551
|
startIndex: 0,
|
|
520
552
|
paragraphStyle: {
|
|
521
553
|
...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
554
|
indentFirstLine: void 0,
|
|
532
555
|
hanging: listHanging,
|
|
533
556
|
indentStart: { v: getNumberUnitValue(listIndentStart, charSpaceApply) - getNumberUnitValue(listHanging, charSpaceApply) + getNumberUnitValue(indentFirstLine, charSpaceApply) + getNumberUnitValue(indentStart, charSpaceApply) }
|
|
@@ -553,7 +576,7 @@ const ListOperationCommand = {
|
|
|
553
576
|
}, ChangeListTypeCommand = {
|
|
554
577
|
id: "doc.command.change-list-type",
|
|
555
578
|
type: CommandType.COMMAND,
|
|
556
|
-
// eslint-disable-next-line max-lines-per-function
|
|
579
|
+
// eslint-disable-next-line max-lines-per-function
|
|
557
580
|
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
558
581
|
var _a11, _b, _c, _d, _e, _f;
|
|
559
582
|
const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), { listType } = params, docDataModel = univerInstanceService.getCurrentUniverDocInstance(), activeRanges = textSelectionManagerService.getDocRanges();
|
|
@@ -576,7 +599,7 @@ const ListOperationCommand = {
|
|
|
576
599
|
...customLists
|
|
577
600
|
}, { defaultTabStop = 36 } = docDataModel.getSnapshot().documentStyle;
|
|
578
601
|
for (const paragraph of currentParagraphs) {
|
|
579
|
-
const { startIndex, paragraphStyle = {}, bullet } = paragraph, { indentFirstLine, snapToGrid, indentStart } = paragraphStyle, paragraphProperties = lists[listType].nestingLevel[0].paragraphProperties || {},
|
|
602
|
+
const { startIndex, paragraphStyle = {}, bullet } = paragraph, { indentFirstLine, snapToGrid, indentStart } = paragraphStyle, paragraphProperties = lists[listType].nestingLevel[0].paragraphProperties || {}, { hanging: listHanging, indentStart: listIndentStart } = paragraphProperties, { charSpace, gridType } = findNearestSectionBreak(startIndex, sectionBreaks) || { charSpace: 0, gridType: GridType.LINES }, charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);
|
|
580
603
|
textX.push({
|
|
581
604
|
t: TextXActionType.RETAIN,
|
|
582
605
|
len: startIndex - memoryCursor.cursor,
|
|
@@ -591,15 +614,6 @@ const ListOperationCommand = {
|
|
|
591
614
|
startIndex: 0,
|
|
592
615
|
paragraphStyle: {
|
|
593
616
|
...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
617
|
indentFirstLine: void 0,
|
|
604
618
|
hanging: listHanging,
|
|
605
619
|
indentStart: { v: getNumberUnitValue(listIndentStart, charSpaceApply) - getNumberUnitValue(listHanging, charSpaceApply) + getNumberUnitValue(indentFirstLine, charSpaceApply) + getNumberUnitValue(indentStart, charSpaceApply) }
|
|
@@ -629,13 +643,13 @@ const ChangeListNestingLevelCommand = {
|
|
|
629
643
|
type: CommandType.COMMAND,
|
|
630
644
|
// eslint-disable-next-line max-lines-per-function
|
|
631
645
|
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
632
|
-
var _a11, _b, _c;
|
|
646
|
+
var _a11, _b, _c, _d, _e;
|
|
633
647
|
if (!params)
|
|
634
648
|
return !1;
|
|
635
649
|
const { type } = params, textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), docDataModel = univerInstanceService.getCurrentUniverDocInstance(), activeRange = textSelectionManagerService.getActiveTextRangeWithStyle();
|
|
636
650
|
if (docDataModel == null || activeRange == null)
|
|
637
651
|
return !1;
|
|
638
|
-
const { segmentId } = activeRange,
|
|
652
|
+
const { segmentId } = activeRange, tables = (_b = (_a11 = docDataModel.getBody()) == null ? void 0 : _a11.tables) != null ? _b : [], selections = (_c = textSelectionManagerService.getDocRanges()) != null ? _c : [], paragraphs = (_d = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _d.paragraphs, serializedSelections = selections.map(serializeDocRange);
|
|
639
653
|
if (paragraphs == null)
|
|
640
654
|
return !1;
|
|
641
655
|
const currentParagraphs = getParagraphsInRange$1(activeRange, paragraphs), unitId = docDataModel.getUnitId(), doMutation = {
|
|
@@ -647,19 +661,20 @@ const ChangeListNestingLevelCommand = {
|
|
|
647
661
|
}
|
|
648
662
|
}, memoryCursor = new MemoryCursor();
|
|
649
663
|
memoryCursor.reset();
|
|
650
|
-
const textX = new TextX(), jsonX = JSONX.getInstance(), customLists = (
|
|
664
|
+
const textX = new TextX(), jsonX = JSONX.getInstance(), customLists = (_e = docDataModel.getSnapshot().lists) != null ? _e : {}, lists = {
|
|
651
665
|
...PRESET_LIST_TYPE,
|
|
652
666
|
...customLists
|
|
653
667
|
};
|
|
654
668
|
for (const paragraph of currentParagraphs) {
|
|
655
|
-
const { startIndex, paragraphStyle = {}, bullet } = paragraph;
|
|
669
|
+
const { startIndex, paragraphStyle = {}, bullet } = paragraph, isInTable = hasParagraphInTable(paragraph, tables);
|
|
656
670
|
if (textX.push({
|
|
657
671
|
t: TextXActionType.RETAIN,
|
|
658
672
|
len: startIndex - memoryCursor.cursor,
|
|
659
673
|
segmentId
|
|
660
674
|
}), bullet) {
|
|
661
|
-
const listType = bullet.listType
|
|
662
|
-
|
|
675
|
+
const listType = bullet.listType;
|
|
676
|
+
let maxLevel = lists[listType].nestingLevel.length - 1;
|
|
677
|
+
isInTable && (maxLevel = Math.min(maxLevel, 2)), textX.push({
|
|
663
678
|
t: TextXActionType.RETAIN,
|
|
664
679
|
len: 1,
|
|
665
680
|
body: {
|
|
@@ -715,15 +730,14 @@ const ChangeListNestingLevelCommand = {
|
|
|
715
730
|
}, ToggleCheckListCommand = {
|
|
716
731
|
id: "doc.command.toggle-check-list",
|
|
717
732
|
type: CommandType.COMMAND,
|
|
718
|
-
// eslint-disable-next-line max-lines-per-function
|
|
719
733
|
handler: /* @__PURE__ */ __name((accessor, params) => {
|
|
720
|
-
var _a11
|
|
734
|
+
var _a11;
|
|
721
735
|
if (!params)
|
|
722
736
|
return !1;
|
|
723
|
-
const univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), { index } = params, docDataModel = univerInstanceService.getCurrentUniverDocInstance();
|
|
737
|
+
const univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), { index, segmentId } = params, docDataModel = univerInstanceService.getCurrentUniverDocInstance();
|
|
724
738
|
if (docDataModel == null)
|
|
725
739
|
return !1;
|
|
726
|
-
const paragraphs = (_a11 = docDataModel.getBody()) == null ? void 0 : _a11.paragraphs;
|
|
740
|
+
const paragraphs = (_a11 = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a11.paragraphs;
|
|
727
741
|
if (paragraphs == null)
|
|
728
742
|
return !1;
|
|
729
743
|
const currentParagraph = paragraphs.find((p) => p.startIndex === index), unitId = docDataModel.getUnitId();
|
|
@@ -734,17 +748,16 @@ const ChangeListNestingLevelCommand = {
|
|
|
734
748
|
params: {
|
|
735
749
|
unitId,
|
|
736
750
|
actions: [],
|
|
737
|
-
textRanges: []
|
|
751
|
+
textRanges: [],
|
|
752
|
+
segmentId
|
|
738
753
|
}
|
|
739
754
|
}, memoryCursor = new MemoryCursor();
|
|
740
755
|
memoryCursor.reset();
|
|
741
|
-
const textX = new TextX(), jsonX = JSONX.getInstance(),
|
|
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;
|
|
756
|
+
const textX = new TextX(), jsonX = JSONX.getInstance(), { startIndex, paragraphStyle = {} } = currentParagraph, listType = currentParagraph.bullet.listType === PresetListType.CHECK_LIST ? PresetListType.CHECK_LIST_CHECKED : PresetListType.CHECK_LIST;
|
|
745
757
|
textX.push({
|
|
746
758
|
t: TextXActionType.RETAIN,
|
|
747
|
-
len: startIndex - memoryCursor.cursor
|
|
759
|
+
len: startIndex - memoryCursor.cursor,
|
|
760
|
+
segmentId
|
|
748
761
|
}), textX.push({
|
|
749
762
|
t: TextXActionType.RETAIN,
|
|
750
763
|
len: 1,
|
|
@@ -753,13 +766,7 @@ const ChangeListNestingLevelCommand = {
|
|
|
753
766
|
paragraphs: [
|
|
754
767
|
{
|
|
755
768
|
...currentParagraph,
|
|
756
|
-
paragraphStyle
|
|
757
|
-
...paragraphStyle,
|
|
758
|
-
textStyle: {
|
|
759
|
-
...paragraphStyle.textStyle,
|
|
760
|
-
...bulletParagraphTextStyle
|
|
761
|
-
}
|
|
762
|
-
},
|
|
769
|
+
paragraphStyle,
|
|
763
770
|
startIndex: 0,
|
|
764
771
|
bullet: {
|
|
765
772
|
...currentParagraph.bullet,
|
|
@@ -768,9 +775,10 @@ const ChangeListNestingLevelCommand = {
|
|
|
768
775
|
}
|
|
769
776
|
]
|
|
770
777
|
},
|
|
771
|
-
coverType: UpdateDocsAttributeType.REPLACE
|
|
778
|
+
coverType: UpdateDocsAttributeType.REPLACE,
|
|
779
|
+
segmentId
|
|
772
780
|
}), memoryCursor.moveCursorTo(startIndex + 1);
|
|
773
|
-
const path = getRichTextEditPath(docDataModel);
|
|
781
|
+
const path = getRichTextEditPath(docDataModel, segmentId);
|
|
774
782
|
return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
775
783
|
}, "handler")
|
|
776
784
|
}, OrderListCommand = {
|
|
@@ -898,38 +906,6 @@ function findNearestSectionBreak(currentIndex, sectionBreaks) {
|
|
|
898
906
|
}
|
|
899
907
|
}
|
|
900
908
|
__name(findNearestSectionBreak, "findNearestSectionBreak");
|
|
901
|
-
function isCustomRangeSplitSymbol(text) {
|
|
902
|
-
return text === DataStreamTreeTokenType.CUSTOM_RANGE_END || text === DataStreamTreeTokenType.CUSTOM_RANGE_START;
|
|
903
|
-
}
|
|
904
|
-
__name(isCustomRangeSplitSymbol, "isCustomRangeSplitSymbol");
|
|
905
|
-
function isIntersecting(line1Start, line1End, line2Start, line2End) {
|
|
906
|
-
return line1Start <= line2Start && line1End >= line2Start || line1Start >= line2Start && line1Start <= line2End;
|
|
907
|
-
}
|
|
908
|
-
__name(isIntersecting, "isIntersecting");
|
|
909
|
-
function shouldDeleteCustomRange(deleteStart, deleteLen, customRange, dataStream) {
|
|
910
|
-
const dataStreamSlice = dataStream.slice(customRange.startIndex + 1, customRange.endIndex), start = Math.max(deleteStart - (customRange.startIndex + 1), 0), end = deleteStart + deleteLen - 1 - (customRange.startIndex + 1);
|
|
911
|
-
if (end < 0)
|
|
912
|
-
return !1;
|
|
913
|
-
if (start === 0 && end >= dataStreamSlice.length)
|
|
914
|
-
return !0;
|
|
915
|
-
const result = dataStreamSlice.slice(0, start) + dataStreamSlice.slice(start + deleteLen);
|
|
916
|
-
for (let i = 0, len = result.length; i < len; i++) {
|
|
917
|
-
const letter = result[i];
|
|
918
|
-
if (!isCustomRangeSplitSymbol(letter))
|
|
919
|
-
return !1;
|
|
920
|
-
}
|
|
921
|
-
return !0;
|
|
922
|
-
}
|
|
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");
|
|
933
909
|
var DeleteDirection = /* @__PURE__ */ ((DeleteDirection2) => (DeleteDirection2[DeleteDirection2.LEFT = 0] = "LEFT", DeleteDirection2[DeleteDirection2.RIGHT = 1] = "RIGHT", DeleteDirection2))(DeleteDirection || {});
|
|
934
910
|
function makeSelection(startOffset, endOffset) {
|
|
935
911
|
if (typeof endOffset > "u")
|
|
@@ -994,12 +970,14 @@ function getInsertSelection(selection, body) {
|
|
|
994
970
|
for (; body.dataStream[endOffset - 1] === DataStreamTreeTokenType.CUSTOM_RANGE_START; )
|
|
995
971
|
endOffset -= 1, startOffset -= 1;
|
|
996
972
|
return {
|
|
973
|
+
...selection,
|
|
997
974
|
startOffset,
|
|
998
975
|
endOffset,
|
|
999
976
|
collapsed
|
|
1000
977
|
};
|
|
1001
978
|
} else
|
|
1002
979
|
return {
|
|
980
|
+
...selection,
|
|
1003
981
|
...getSelectionWithSymbolMax(selection, body),
|
|
1004
982
|
collapsed: !1
|
|
1005
983
|
};
|
|
@@ -1092,7 +1070,7 @@ function isSegmentIntersects(start, end, start2, end2) {
|
|
|
1092
1070
|
return Math.max(start, start2) <= Math.min(end, end2);
|
|
1093
1071
|
}
|
|
1094
1072
|
__name(isSegmentIntersects, "isSegmentIntersects");
|
|
1095
|
-
function getRetainAndDeleteAndExcludeLineBreak(selection, body, segmentId = "", memoryCursor = 0) {
|
|
1073
|
+
function getRetainAndDeleteAndExcludeLineBreak(selection, body, segmentId = "", memoryCursor = 0, preserveLineBreak = !0) {
|
|
1096
1074
|
var _a11;
|
|
1097
1075
|
const { startOffset, endOffset } = getDeleteSelection(selection, body), dos = [], { paragraphs = [], dataStream } = body, textStart = startOffset - memoryCursor, textEnd = endOffset - memoryCursor, paragraphInRange = paragraphs == null ? void 0 : paragraphs.find(
|
|
1098
1076
|
(p) => p.startIndex - memoryCursor >= textStart && p.startIndex - memoryCursor < textEnd
|
|
@@ -1103,7 +1081,7 @@ function getRetainAndDeleteAndExcludeLineBreak(selection, body, segmentId = "",
|
|
|
1103
1081
|
t: TextXActionType.RETAIN,
|
|
1104
1082
|
len: textStart,
|
|
1105
1083
|
segmentId
|
|
1106
|
-
}), paragraphInRange && paragraphInRange.startIndex - memoryCursor > textStart) {
|
|
1084
|
+
}), preserveLineBreak && paragraphInRange && paragraphInRange.startIndex - memoryCursor > textStart) {
|
|
1107
1085
|
const paragraphIndex = paragraphInRange.startIndex - memoryCursor;
|
|
1108
1086
|
retainPoints.add(paragraphIndex);
|
|
1109
1087
|
}
|
|
@@ -1130,32 +1108,40 @@ function getRetainAndDeleteAndExcludeLineBreak(selection, body, segmentId = "",
|
|
|
1130
1108
|
}
|
|
1131
1109
|
__name(getRetainAndDeleteAndExcludeLineBreak, "getRetainAndDeleteAndExcludeLineBreak");
|
|
1132
1110
|
function replaceSelectionFactory(accessor, params) {
|
|
1133
|
-
var _a11, _b;
|
|
1134
|
-
const { unitId, body: insertBody } = params, docDataModel = accessor.get(IUniverInstanceService).getUnit(unitId)
|
|
1111
|
+
var _a11, _b, _c, _d;
|
|
1112
|
+
const { unitId, originBody, body: insertBody } = params, docDataModel = accessor.get(IUniverInstanceService).getUnit(unitId);
|
|
1135
1113
|
if (!docDataModel)
|
|
1136
1114
|
return !1;
|
|
1137
|
-
const
|
|
1115
|
+
const segmentId = (_a11 = params.selection) == null ? void 0 : _a11.segmentId;
|
|
1116
|
+
let body;
|
|
1117
|
+
if (params.originBody ? body = originBody : body = (_b = docDataModel.getSelfOrHeaderFooterModel(segmentId)) == null ? void 0 : _b.getBody(), !body) return !1;
|
|
1118
|
+
const textSelectionManagerService = accessor.get(TextSelectionManagerService), selection = (_c = params.selection) != null ? _c : textSelectionManagerService.getActiveTextRangeWithStyle();
|
|
1138
1119
|
if (!selection || !body)
|
|
1139
1120
|
return !1;
|
|
1140
|
-
const textRanges = (
|
|
1121
|
+
const textRanges = (_d = params.textRanges) != null ? _d : [{
|
|
1141
1122
|
startOffset: selection.startOffset + insertBody.dataStream.length,
|
|
1142
1123
|
endOffset: selection.startOffset + insertBody.dataStream.length,
|
|
1143
|
-
collapsed: !0
|
|
1124
|
+
collapsed: !0,
|
|
1125
|
+
segmentId
|
|
1144
1126
|
}], doMutation = {
|
|
1145
1127
|
id: RichTextEditingMutation.id,
|
|
1146
1128
|
params: {
|
|
1147
1129
|
unitId,
|
|
1148
1130
|
actions: [],
|
|
1149
1131
|
textRanges,
|
|
1150
|
-
debounce: !0
|
|
1132
|
+
debounce: !0,
|
|
1133
|
+
segmentId
|
|
1151
1134
|
}
|
|
1152
1135
|
}, textX = new TextX(), jsonX = JSONX.getInstance();
|
|
1153
|
-
|
|
1136
|
+
textX.push(...getRetainAndDeleteAndExcludeLineBreak(selection, body, segmentId)), textX.push({
|
|
1154
1137
|
t: TextXActionType.INSERT,
|
|
1155
1138
|
body: insertBody,
|
|
1156
1139
|
len: insertBody.dataStream.length,
|
|
1157
|
-
line: 0
|
|
1158
|
-
|
|
1140
|
+
line: 0,
|
|
1141
|
+
segmentId
|
|
1142
|
+
});
|
|
1143
|
+
const path = getRichTextEditPath(docDataModel, segmentId);
|
|
1144
|
+
return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), doMutation;
|
|
1159
1145
|
}
|
|
1160
1146
|
__name(replaceSelectionFactory, "replaceSelectionFactory");
|
|
1161
1147
|
var DOCS_VIEW_KEY = /* @__PURE__ */ ((DOCS_VIEW_KEY2) => (DOCS_VIEW_KEY2.MAIN = "__Document_Render_Main__", DOCS_VIEW_KEY2.BACKGROUND = "__Document_Render_Background__", DOCS_VIEW_KEY2))(DOCS_VIEW_KEY || {}), VIEWPORT_KEY = /* @__PURE__ */ ((VIEWPORT_KEY2) => (VIEWPORT_KEY2.VIEW_MAIN = "viewMain", VIEWPORT_KEY2.VIEW_TOP = "viewTop", VIEWPORT_KEY2.VIEW_LEFT = "viewLeft", VIEWPORT_KEY2.VIEW_LEFT_TOP = "viewLeftTop", VIEWPORT_KEY2))(VIEWPORT_KEY || {});
|
|
@@ -1257,10 +1243,9 @@ __name(getRetainAndDeleteFromReplace, "getRetainAndDeleteFromReplace");
|
|
|
1257
1243
|
const EditorInsertTextCommandId = "doc.command.insert-text", InsertCommand = {
|
|
1258
1244
|
id: EditorInsertTextCommandId,
|
|
1259
1245
|
type: CommandType.COMMAND,
|
|
1260
|
-
// eslint-disable-next-line max-lines-per-function
|
|
1261
1246
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1262
1247
|
var _a11;
|
|
1263
|
-
const commandService = accessor.get(ICommandService), { range, segmentId, body, unitId,
|
|
1248
|
+
const commandService = accessor.get(ICommandService), { range, segmentId, body, unitId, cursorOffset } = params, textSelectionManagerService = accessor.get(TextSelectionManagerService), docDataModel = accessor.get(IUniverInstanceService).getUnit(unitId, UniverInstanceType.UNIVER_DOC);
|
|
1264
1249
|
if (docDataModel == null)
|
|
1265
1250
|
return !1;
|
|
1266
1251
|
const activeRange = textSelectionManagerService.getActiveTextRangeWithStyle(), originBody = docDataModel.getSelfOrHeaderFooterModel((_a11 = activeRange == null ? void 0 : activeRange.segmentId) != null ? _a11 : "").getBody();
|
|
@@ -1278,7 +1263,7 @@ const EditorInsertTextCommandId = "doc.command.insert-text", InsertCommand = {
|
|
|
1278
1263
|
params: {
|
|
1279
1264
|
unitId,
|
|
1280
1265
|
actions: [],
|
|
1281
|
-
textRanges
|
|
1266
|
+
textRanges,
|
|
1282
1267
|
debounce: !0
|
|
1283
1268
|
}
|
|
1284
1269
|
}, textX = new TextX(), jsonX = JSONX.getInstance();
|
|
@@ -1290,11 +1275,11 @@ const EditorInsertTextCommandId = "doc.command.insert-text", InsertCommand = {
|
|
|
1290
1275
|
});
|
|
1291
1276
|
else {
|
|
1292
1277
|
const { dos, retain } = getRetainAndDeleteFromReplace(actualRange, segmentId, 0, originBody);
|
|
1293
|
-
textX.push(...dos),
|
|
1278
|
+
textX.push(...dos), doMutation.params.textRanges = [{
|
|
1294
1279
|
startOffset: startOffset + cursorMove + retain,
|
|
1295
1280
|
endOffset: startOffset + cursorMove + retain,
|
|
1296
1281
|
collapsed
|
|
1297
|
-
}]
|
|
1282
|
+
}];
|
|
1298
1283
|
}
|
|
1299
1284
|
textX.push({
|
|
1300
1285
|
t: TextXActionType.INSERT,
|
|
@@ -1599,14 +1584,14 @@ function getInsertRowBody(col) {
|
|
|
1599
1584
|
for (let i = 0; i < col; i++)
|
|
1600
1585
|
dataStream += `${DataStreamTreeTokenType.TABLE_CELL_START}\r
|
|
1601
1586
|
${DataStreamTreeTokenType.TABLE_CELL_END}`, paragraphs.push({
|
|
1602
|
-
startIndex: dataStream.length -
|
|
1587
|
+
startIndex: dataStream.length - 3,
|
|
1603
1588
|
paragraphStyle: {
|
|
1604
1589
|
spaceAbove: { v: 3 },
|
|
1605
1590
|
lineSpacing: 2,
|
|
1606
1591
|
spaceBelow: { v: 0 }
|
|
1607
1592
|
}
|
|
1608
1593
|
}), sectionBreaks.push({
|
|
1609
|
-
startIndex: dataStream.length -
|
|
1594
|
+
startIndex: dataStream.length - 2
|
|
1610
1595
|
});
|
|
1611
1596
|
return dataStream += DataStreamTreeTokenType.TABLE_ROW_END, {
|
|
1612
1597
|
dataStream,
|
|
@@ -1870,6 +1855,54 @@ function getDeleteRowContentActionParams(rangeInfo, viewModel) {
|
|
|
1870
1855
|
};
|
|
1871
1856
|
}
|
|
1872
1857
|
__name(getDeleteRowContentActionParams, "getDeleteRowContentActionParams");
|
|
1858
|
+
var CellPosition = /* @__PURE__ */ ((CellPosition2) => (CellPosition2[CellPosition2.NEXT = 0] = "NEXT", CellPosition2[CellPosition2.PREV = 1] = "PREV", CellPosition2))(CellPosition || {});
|
|
1859
|
+
function getCellOffsets(viewModel, range, position) {
|
|
1860
|
+
const { startOffset } = range;
|
|
1861
|
+
let targetTable = null;
|
|
1862
|
+
for (const section of viewModel.children) {
|
|
1863
|
+
for (const paragraph of section.children) {
|
|
1864
|
+
const table = paragraph.children[0];
|
|
1865
|
+
if (table && startOffset > table.startIndex && startOffset < table.endIndex) {
|
|
1866
|
+
targetTable = table;
|
|
1867
|
+
break;
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
if (targetTable)
|
|
1871
|
+
break;
|
|
1872
|
+
}
|
|
1873
|
+
if (targetTable == null)
|
|
1874
|
+
return null;
|
|
1875
|
+
let cellIndex = -1, rowIndex = -1, targetRow = null;
|
|
1876
|
+
for (const row of targetTable.children) {
|
|
1877
|
+
for (const cell of row.children)
|
|
1878
|
+
if (startOffset > cell.startIndex && startOffset < cell.endIndex) {
|
|
1879
|
+
cellIndex = row.children.indexOf(cell), rowIndex = targetTable.children.indexOf(row), targetRow = row;
|
|
1880
|
+
break;
|
|
1881
|
+
}
|
|
1882
|
+
if (cellIndex > -1)
|
|
1883
|
+
break;
|
|
1884
|
+
}
|
|
1885
|
+
if (cellIndex === -1 || rowIndex === -1 || targetRow == null)
|
|
1886
|
+
return null;
|
|
1887
|
+
let newCell = null;
|
|
1888
|
+
if (position === 0) {
|
|
1889
|
+
if (newCell = targetRow.children[cellIndex + 1], !newCell) {
|
|
1890
|
+
const nextRow = targetTable.children[rowIndex + 1];
|
|
1891
|
+
nextRow && (newCell = nextRow.children[0]);
|
|
1892
|
+
}
|
|
1893
|
+
} else if (newCell = targetRow.children[cellIndex - 1], !newCell) {
|
|
1894
|
+
const prevRow = targetTable.children[rowIndex - 1];
|
|
1895
|
+
prevRow && (newCell = prevRow.children[prevRow.children.length - 1]);
|
|
1896
|
+
}
|
|
1897
|
+
if (newCell) {
|
|
1898
|
+
const { startIndex, endIndex } = newCell;
|
|
1899
|
+
return {
|
|
1900
|
+
startOffset: startIndex + 1,
|
|
1901
|
+
endOffset: endIndex - 2
|
|
1902
|
+
};
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
__name(getCellOffsets, "getCellOffsets");
|
|
1873
1906
|
function hasRangeInTable(ranges) {
|
|
1874
1907
|
return ranges.some((range) => {
|
|
1875
1908
|
const { anchorNodePosition } = range;
|
|
@@ -1894,7 +1927,8 @@ const InnerPasteCommand = {
|
|
|
1894
1927
|
params: {
|
|
1895
1928
|
unitId,
|
|
1896
1929
|
actions: [],
|
|
1897
|
-
textRanges
|
|
1930
|
+
textRanges,
|
|
1931
|
+
segmentId
|
|
1898
1932
|
}
|
|
1899
1933
|
}, memoryCursor = new MemoryCursor();
|
|
1900
1934
|
memoryCursor.reset();
|
|
@@ -1950,7 +1984,7 @@ function getCutActionsFromTextRanges(selections, docDataModel, segmentId) {
|
|
|
1950
1984
|
t: TextXActionType.RETAIN,
|
|
1951
1985
|
len,
|
|
1952
1986
|
segmentId
|
|
1953
|
-
}) : textX.push(...getRetainAndDeleteAndExcludeLineBreak(selection, originBody, segmentId, memoryCursor.cursor)), memoryCursor.reset(), memoryCursor.moveCursor(endOffset);
|
|
1987
|
+
}) : textX.push(...getRetainAndDeleteAndExcludeLineBreak(selection, originBody, segmentId, memoryCursor.cursor, !1)), memoryCursor.reset(), memoryCursor.moveCursor(endOffset);
|
|
1954
1988
|
}
|
|
1955
1989
|
const path = getRichTextEditPath(docDataModel, segmentId);
|
|
1956
1990
|
rawActions.push(jsonX.editOp(textX.serialize(), path));
|
|
@@ -2127,7 +2161,6 @@ const DeleteCustomBlockCommand = {
|
|
|
2127
2161
|
type: CommandType.COMMAND,
|
|
2128
2162
|
// eslint-disable-next-line max-lines-per-function
|
|
2129
2163
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
2130
|
-
var _a11, _b;
|
|
2131
2164
|
const textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), commandService = accessor.get(ICommandService), { direction, range } = params, activeRange = textSelectionManagerService.getActiveTextRangeWithStyle(), ranges = textSelectionManagerService.getCurrentTextRanges();
|
|
2132
2165
|
if (activeRange == null || ranges == null)
|
|
2133
2166
|
return !1;
|
|
@@ -2137,7 +2170,7 @@ const DeleteCustomBlockCommand = {
|
|
|
2137
2170
|
const actualRange = getDeleteSelection(activeRange, originBody), unitId = docDataModel.getUnitId(), { startOffset, collapsed } = actualRange;
|
|
2138
2171
|
if (!collapsed)
|
|
2139
2172
|
return !1;
|
|
2140
|
-
const startIndex = direction === DeleteDirection.LEFT ? startOffset : startOffset + 1, endIndex =
|
|
2173
|
+
const startIndex = direction === DeleteDirection.LEFT ? startOffset : startOffset + 1, endIndex = originBody.paragraphs.find((p) => p.startIndex >= startIndex).startIndex, body = getParagraphBody(accessor, unitId, originBody, startIndex, endIndex), cursor = direction === DeleteDirection.LEFT ? startOffset - 1 : startOffset, textRanges = [
|
|
2141
2174
|
{
|
|
2142
2175
|
startOffset: cursor,
|
|
2143
2176
|
endOffset: cursor,
|
|
@@ -2334,7 +2367,7 @@ const DeleteLeftCommand = {
|
|
|
2334
2367
|
}, DeleteRightCommand = {
|
|
2335
2368
|
id: "doc.command.delete-right",
|
|
2336
2369
|
type: CommandType.COMMAND,
|
|
2337
|
-
// eslint-disable-next-line max-lines-per-function
|
|
2370
|
+
// eslint-disable-next-line max-lines-per-function, complexity
|
|
2338
2371
|
handler: /* @__PURE__ */ __name(async (accessor) => {
|
|
2339
2372
|
var _a11, _b;
|
|
2340
2373
|
const textSelectionManagerService = accessor.get(TextSelectionManagerService), docDataModel = accessor.get(IUniverInstanceService).getCurrentUniverDocInstance();
|
|
@@ -2494,12 +2527,12 @@ const IMEInputCommand = {
|
|
|
2494
2527
|
const previousActiveRange = imeInputManagerService.getActiveRange();
|
|
2495
2528
|
if (!previousActiveRange)
|
|
2496
2529
|
return !1;
|
|
2497
|
-
const {
|
|
2530
|
+
const { style, segmentId } = previousActiveRange, body = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
2498
2531
|
if (body == null)
|
|
2499
2532
|
return !1;
|
|
2500
2533
|
const insertRange = getInsertSelection(previousActiveRange, body);
|
|
2501
2534
|
Object.assign(previousActiveRange, insertRange);
|
|
2502
|
-
const len = newText.length, textRanges = [
|
|
2535
|
+
const { startOffset } = previousActiveRange, len = newText.length, textRanges = [
|
|
2503
2536
|
{
|
|
2504
2537
|
startOffset: startOffset + len,
|
|
2505
2538
|
endOffset: startOffset + len,
|
|
@@ -3448,17 +3481,17 @@ let DocAutoFormatService = (_a6 = class extends Disposable {
|
|
|
3448
3481
|
}
|
|
3449
3482
|
onAutoFormat(id, params) {
|
|
3450
3483
|
var _a11, _b, _c, _d, _e, _f;
|
|
3451
|
-
const
|
|
3484
|
+
const autoFormats = (_a11 = this._matches.get(id)) != null ? _a11 : [], unit = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC), selection = this._textSelectionManagerService.getActiveTextRangeWithStyle();
|
|
3452
3485
|
if (unit && selection) {
|
|
3453
3486
|
const doc = unit.getSelfOrHeaderFooterModel(selection.segmentId), context = {
|
|
3454
3487
|
unit: doc,
|
|
3455
3488
|
selection,
|
|
3456
3489
|
isBody: !selection.segmentId,
|
|
3457
3490
|
paragraphs: getParagraphsInRange(selection, (_c = (_b = doc.getBody()) == null ? void 0 : _b.paragraphs) != null ? _c : []),
|
|
3458
|
-
customRanges:
|
|
3491
|
+
customRanges: getCustomRangesInterestsWithRange(selection, (_e = (_d = doc.getBody()) == null ? void 0 : _d.customRanges) != null ? _e : []),
|
|
3459
3492
|
commandId: id,
|
|
3460
3493
|
commandParams: params
|
|
3461
|
-
}, matched =
|
|
3494
|
+
}, matched = autoFormats.find((i) => i.match(context));
|
|
3462
3495
|
return (_f = matched == null ? void 0 : matched.getMutations(context)) != null ? _f : [];
|
|
3463
3496
|
}
|
|
3464
3497
|
return [];
|
|
@@ -3519,21 +3552,12 @@ let NormalInputController = (_a7 = class extends Disposable {
|
|
|
3519
3552
|
const unitId = documentModel.getUnitId(), { event, content = "", activeRange } = config, e = event, skeleton = (_a11 = this._renderManagerService.getRenderById(documentModel.getUnitId())) == null ? void 0 : _a11.with(DocSkeletonManagerService).getSkeleton();
|
|
3520
3553
|
if (e.data == null || skeleton == null || !skeleton || !activeRange)
|
|
3521
3554
|
return;
|
|
3522
|
-
const {
|
|
3523
|
-
{
|
|
3524
|
-
startOffset: startOffset + len,
|
|
3525
|
-
endOffset: startOffset + len,
|
|
3526
|
-
segmentId,
|
|
3527
|
-
segmentPage,
|
|
3528
|
-
style
|
|
3529
|
-
}
|
|
3530
|
-
];
|
|
3555
|
+
const { segmentId } = activeRange;
|
|
3531
3556
|
await this._commandService.executeCommand(InsertCommand.id, {
|
|
3532
3557
|
unitId,
|
|
3533
3558
|
body: {
|
|
3534
3559
|
dataStream: content
|
|
3535
3560
|
},
|
|
3536
|
-
textRanges,
|
|
3537
3561
|
range: activeRange,
|
|
3538
3562
|
segmentId
|
|
3539
3563
|
}), content === " " && await this._commandService.executeCommand(AfterSpaceCommand.id);
|
|
@@ -4029,11 +4053,25 @@ const DocsRenameMutation = {
|
|
|
4029
4053
|
}, DocTableTabCommand = {
|
|
4030
4054
|
id: "doc.table.tab-in-table",
|
|
4031
4055
|
type: CommandType.COMMAND,
|
|
4032
|
-
handler: /* @__PURE__ */ __name(async () =>
|
|
4033
|
-
},
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4056
|
+
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
4057
|
+
const { shift } = params, textSelectionManager = accessor.get(TextSelectionManagerService), activeTextRange = textSelectionManager.getActiveTextRangeWithStyle(), commandService = accessor.get(ICommandService), docDataModel = accessor.get(IUniverInstanceService).getCurrentUniverDocInstance();
|
|
4058
|
+
if (!docDataModel)
|
|
4059
|
+
return !1;
|
|
4060
|
+
const unitId = docDataModel.getUnitId(), docSkeletonManagerService = getCommandSkeleton(accessor, unitId), skeleton = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getSkeleton(), viewModel = skeleton == null ? void 0 : skeleton.getViewModel().getSelfOrHeaderFooterViewModel(activeTextRange == null ? void 0 : activeTextRange.segmentId);
|
|
4061
|
+
if (viewModel == null || activeTextRange == null)
|
|
4062
|
+
return !1;
|
|
4063
|
+
let offsets = null;
|
|
4064
|
+
if (shift ? offsets = getCellOffsets(viewModel, activeTextRange, CellPosition.PREV) : offsets = getCellOffsets(viewModel, activeTextRange, CellPosition.NEXT), offsets) {
|
|
4065
|
+
const { startOffset, endOffset } = offsets, textRanges = [{
|
|
4066
|
+
startOffset,
|
|
4067
|
+
endOffset
|
|
4068
|
+
}];
|
|
4069
|
+
return textSelectionManager.replaceTextRanges(textRanges), !0;
|
|
4070
|
+
}
|
|
4071
|
+
return shift === !1 ? await commandService.executeCommand(DocTableInsertRowCommand.id, {
|
|
4072
|
+
position: INSERT_ROW_POSITION.BELLOW
|
|
4073
|
+
}) : !0;
|
|
4074
|
+
}, "handler")
|
|
4037
4075
|
};
|
|
4038
4076
|
var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
4039
4077
|
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
@@ -4097,7 +4135,6 @@ let UniverDocsPlugin = (_a9 = class extends Plugin {
|
|
|
4097
4135
|
DocTableDeleteColumnsCommand,
|
|
4098
4136
|
DocTableDeleteTableCommand,
|
|
4099
4137
|
DocTableTabCommand,
|
|
4100
|
-
DocTableShiftTabCommand,
|
|
4101
4138
|
DocsRenameMutation,
|
|
4102
4139
|
TabCommand,
|
|
4103
4140
|
AfterSpaceCommand,
|
|
@@ -4136,7 +4173,11 @@ let UniverDocsPlugin = (_a9 = class extends Plugin {
|
|
|
4136
4173
|
UniverDocsPlugin = __decorateClass$1([
|
|
4137
4174
|
__decorateParam$1(1, Inject(Injector))
|
|
4138
4175
|
], UniverDocsPlugin);
|
|
4139
|
-
const
|
|
4176
|
+
const getPlainTextFormBody = /* @__PURE__ */ __name((body) => {
|
|
4177
|
+
let str = body.dataStream;
|
|
4178
|
+
return body.dataStream.endsWith(`\r
|
|
4179
|
+
`) && (str = body.dataStream.slice(0, -2)), str.replaceAll(DataStreamTreeTokenType.CUSTOM_RANGE_START, "").replaceAll(DataStreamTreeTokenType.CUSTOM_RANGE_END, "");
|
|
4180
|
+
}, "getPlainTextFormBody"), getPlainTextFormDocument = /* @__PURE__ */ __name((data) => data.body ? getPlainTextFormBody(data.body) : "", "getPlainTextFormDocument");
|
|
4140
4181
|
function addCustomRangeTextX(param, body) {
|
|
4141
4182
|
const { range, rangeId, rangeType, segmentId } = param, actualRange = getSelectionForAddCustomRange(range, body);
|
|
4142
4183
|
if (!actualRange)
|
|
@@ -4192,13 +4233,13 @@ function addCustomRangeFactory(param, body) {
|
|
|
4192
4233
|
__name(addCustomRangeFactory, "addCustomRangeFactory");
|
|
4193
4234
|
function addCustomRangeBySelectionFactory(accessor, param) {
|
|
4194
4235
|
var _a11;
|
|
4195
|
-
const {
|
|
4236
|
+
const { rangeId, rangeType, wholeEntity } = param, textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), selection = textSelectionManagerService.getActiveTextRangeWithStyle(), segmentId = selection == null ? void 0 : selection.segmentId;
|
|
4196
4237
|
if (!selection)
|
|
4197
4238
|
return !1;
|
|
4198
4239
|
const documentDataModel = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
|
|
4199
4240
|
if (!documentDataModel)
|
|
4200
4241
|
return !1;
|
|
4201
|
-
const body = documentDataModel.getBody(), unitId = documentDataModel.getUnitId();
|
|
4242
|
+
const body = documentDataModel.getSelfOrHeaderFooterModel(selection.segmentId).getBody(), unitId = documentDataModel.getUnitId();
|
|
4202
4243
|
if (!body)
|
|
4203
4244
|
return !1;
|
|
4204
4245
|
const { startOffset, endOffset } = normalizeSelection(selection), customRanges = (_a11 = body.customRanges) != null ? _a11 : [], relativeCustomRanges = [];
|
|
@@ -4265,8 +4306,8 @@ function addCustomRangeBySelectionFactory(accessor, param) {
|
|
|
4265
4306
|
actions: [],
|
|
4266
4307
|
textRanges: void 0
|
|
4267
4308
|
}
|
|
4268
|
-
};
|
|
4269
|
-
return doMutation.params.actions = jsonX.editOp(textX.serialize()), doMutation;
|
|
4309
|
+
}, path = getRichTextEditPath(documentDataModel, segmentId);
|
|
4310
|
+
return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), doMutation;
|
|
4270
4311
|
}
|
|
4271
4312
|
__name(addCustomRangeBySelectionFactory, "addCustomRangeBySelectionFactory");
|
|
4272
4313
|
function deleteCustomRangeTextX(accessor, params) {
|
|
@@ -4274,7 +4315,7 @@ function deleteCustomRangeTextX(accessor, params) {
|
|
|
4274
4315
|
const { unitId, rangeId, segmentId } = params, documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId);
|
|
4275
4316
|
if (!documentDataModel)
|
|
4276
4317
|
return !1;
|
|
4277
|
-
const range = (_b = (_a11 = documentDataModel.getBody()) == null ? void 0 : _a11.customRanges) == null ? void 0 : _b.find((r) => r.rangeId === rangeId);
|
|
4318
|
+
const range = (_b = (_a11 = documentDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a11.customRanges) == null ? void 0 : _b.find((r) => r.rangeId === rangeId);
|
|
4278
4319
|
if (!range)
|
|
4279
4320
|
return !1;
|
|
4280
4321
|
const { startIndex, endIndex } = range, textX = new TextX(), len = endIndex - startIndex + 1;
|
|
@@ -4300,15 +4341,22 @@ function deleteCustomRangeTextX(accessor, params) {
|
|
|
4300
4341
|
}
|
|
4301
4342
|
__name(deleteCustomRangeTextX, "deleteCustomRangeTextX");
|
|
4302
4343
|
function deleteCustomRangeFactory(accessor, params) {
|
|
4344
|
+
const { unitId, segmentId } = params, documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId);
|
|
4345
|
+
if (!documentDataModel)
|
|
4346
|
+
return !1;
|
|
4303
4347
|
const doMutation = {
|
|
4304
4348
|
id: RichTextEditingMutation.id,
|
|
4305
4349
|
params: {
|
|
4306
4350
|
unitId: params.unitId,
|
|
4307
4351
|
actions: [],
|
|
4308
|
-
textRanges: void 0
|
|
4352
|
+
textRanges: void 0,
|
|
4353
|
+
segmentId
|
|
4309
4354
|
}
|
|
4310
4355
|
}, jsonX = JSONX.getInstance(), textX = deleteCustomRangeTextX(accessor, params);
|
|
4311
|
-
|
|
4356
|
+
if (!textX)
|
|
4357
|
+
return !1;
|
|
4358
|
+
const path = getRichTextEditPath(documentDataModel, segmentId);
|
|
4359
|
+
return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), doMutation;
|
|
4312
4360
|
}
|
|
4313
4361
|
__name(deleteCustomRangeFactory, "deleteCustomRangeFactory");
|
|
4314
4362
|
function addCustomDecorationFactory(param) {
|
|
@@ -4415,17 +4463,20 @@ let DocInterceptorService = (_a10 = class extends Disposable {
|
|
|
4415
4463
|
constructor(_context, _docSkeletonManagerService) {
|
|
4416
4464
|
super();
|
|
4417
4465
|
__publicField(this, "_interceptorsByName", /* @__PURE__ */ new Map());
|
|
4418
|
-
this._context = _context, this._docSkeletonManagerService = _docSkeletonManagerService
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
this.interceptDocumentViewModel(viewModel);
|
|
4424
|
-
}
|
|
4425
|
-
})), this.disposeWithMe(this.intercept(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE, {
|
|
4466
|
+
this._context = _context, this._docSkeletonManagerService = _docSkeletonManagerService;
|
|
4467
|
+
const viewModel = this._docSkeletonManagerService.getViewModel(), unitId = viewModel.getDataModel().getUnitId();
|
|
4468
|
+
if (unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY || unitId === DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)
|
|
4469
|
+
return;
|
|
4470
|
+
this.disposeWithMe(this.interceptDocumentViewModel(viewModel)), this.disposeWithMe(this.intercept(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE, {
|
|
4426
4471
|
priority: -1,
|
|
4427
4472
|
handler: /* @__PURE__ */ __name((data, pos, next) => next(data), "handler")
|
|
4428
4473
|
}));
|
|
4474
|
+
let disposableCollection = new DisposableCollection();
|
|
4475
|
+
viewModel.segmentViewModels$.subscribe((segmentViewModels) => {
|
|
4476
|
+
disposableCollection.dispose(), disposableCollection = new DisposableCollection(), segmentViewModels.forEach((segmentViewModel) => {
|
|
4477
|
+
disposableCollection.add(this.interceptDocumentViewModel(segmentViewModel));
|
|
4478
|
+
});
|
|
4479
|
+
}), this.disposeWithMe(disposableCollection);
|
|
4429
4480
|
}
|
|
4430
4481
|
intercept(name, interceptor) {
|
|
4431
4482
|
const key = name;
|
|
@@ -4515,7 +4566,6 @@ export {
|
|
|
4515
4566
|
DocTableInsertRowAboveCommand,
|
|
4516
4567
|
DocTableInsertRowBellowCommand,
|
|
4517
4568
|
DocTableInsertRowCommand,
|
|
4518
|
-
DocTableShiftTabCommand,
|
|
4519
4569
|
DocTableTabCommand,
|
|
4520
4570
|
EditorInsertTextCommandId,
|
|
4521
4571
|
EnterCommand,
|
|
@@ -4564,6 +4614,7 @@ export {
|
|
|
4564
4614
|
generateParagraphs,
|
|
4565
4615
|
getCommandSkeleton,
|
|
4566
4616
|
getCursorWhenDelete,
|
|
4617
|
+
getCustomRangesInterestsWithRange,
|
|
4567
4618
|
getDeleteSelection,
|
|
4568
4619
|
getDocObject,
|
|
4569
4620
|
getDocObjectById,
|
|
@@ -4572,11 +4623,13 @@ export {
|
|
|
4572
4623
|
getInsertSelection,
|
|
4573
4624
|
getParagraphsInRange$1 as getParagraphsInRange,
|
|
4574
4625
|
getParagraphsInRanges,
|
|
4626
|
+
getPlainTextFormBody,
|
|
4575
4627
|
getPlainTextFormDocument,
|
|
4576
4628
|
getRetainAndDeleteFromReplace,
|
|
4577
4629
|
getRichTextEditPath,
|
|
4578
4630
|
getSelectionText,
|
|
4579
4631
|
getTableColumn,
|
|
4632
|
+
hasParagraphInTable,
|
|
4580
4633
|
isSegmentIntersects,
|
|
4581
4634
|
makeSelection,
|
|
4582
4635
|
neoGetDocObject,
|