@univerjs/docs 0.2.8 → 0.2.10
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 +3 -2
- package/lib/es/index.js +238 -173
- package/lib/types/basics/custom-range-factory.d.ts +0 -1
- package/lib/types/basics/custom-range.d.ts +1 -1
- package/lib/types/basics/paragraph.d.ts +2 -0
- package/lib/types/basics/plain-text.d.ts +5 -1
- package/lib/types/basics/replace.d.ts +2 -2
- package/lib/types/basics/selection.d.ts +1 -1
- package/lib/types/basics/table.d.ts +0 -2
- package/lib/types/commands/commands/clipboard.inner.command.d.ts +4 -2
- package/lib/types/commands/commands/core-editing.command.d.ts +0 -1
- package/lib/types/commands/commands/list.command.d.ts +1 -0
- package/lib/types/commands/commands/table/doc-table-tab.command.d.ts +1 -3
- package/lib/types/commands/commands/table/table.d.ts +10 -0
- package/lib/types/index.d.ts +6 -3
- package/lib/types/services/doc-auto-format.service.d.ts +4 -4
- package/lib/types/services/doc-interceptor/doc-interceptor.service.d.ts +2 -2
- package/lib/umd/index.js +3 -2
- 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, isInternalEditorID, Tools, PresetListType, MemoryCursor, TextX, PRESET_LIST_TYPE, GridType, TextXActionType,
|
|
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;
|
|
@@ -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
|
};
|
|
@@ -1130,38 +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, originBody, body: insertBody } = params,
|
|
1111
|
+
var _a11, _b, _c, _d;
|
|
1112
|
+
const { unitId, originBody, body: insertBody } = params, docDataModel = accessor.get(IUniverInstanceService).getUnit(unitId);
|
|
1113
|
+
if (!docDataModel)
|
|
1114
|
+
return !1;
|
|
1115
|
+
const segmentId = (_a11 = params.selection) == null ? void 0 : _a11.segmentId;
|
|
1135
1116
|
let body;
|
|
1136
|
-
if (params.originBody)
|
|
1137
|
-
|
|
1138
|
-
else {
|
|
1139
|
-
const docDataModel = univerInstanceService.getUnit(unitId);
|
|
1140
|
-
body = docDataModel == null ? void 0 : docDataModel.getBody();
|
|
1141
|
-
}
|
|
1142
|
-
if (!body) return !1;
|
|
1143
|
-
const textSelectionManagerService = accessor.get(TextSelectionManagerService), selection = (_a11 = params.selection) != null ? _a11 : textSelectionManagerService.getActiveTextRangeWithStyle();
|
|
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();
|
|
1144
1119
|
if (!selection || !body)
|
|
1145
1120
|
return !1;
|
|
1146
|
-
const textRanges = (
|
|
1121
|
+
const textRanges = (_d = params.textRanges) != null ? _d : [{
|
|
1147
1122
|
startOffset: selection.startOffset + insertBody.dataStream.length,
|
|
1148
1123
|
endOffset: selection.startOffset + insertBody.dataStream.length,
|
|
1149
|
-
collapsed: !0
|
|
1124
|
+
collapsed: !0,
|
|
1125
|
+
segmentId
|
|
1150
1126
|
}], doMutation = {
|
|
1151
1127
|
id: RichTextEditingMutation.id,
|
|
1152
1128
|
params: {
|
|
1153
1129
|
unitId,
|
|
1154
1130
|
actions: [],
|
|
1155
1131
|
textRanges,
|
|
1156
|
-
debounce: !0
|
|
1132
|
+
debounce: !0,
|
|
1133
|
+
segmentId
|
|
1157
1134
|
}
|
|
1158
1135
|
}, textX = new TextX(), jsonX = JSONX.getInstance();
|
|
1159
|
-
|
|
1136
|
+
textX.push(...getRetainAndDeleteAndExcludeLineBreak(selection, body, segmentId)), textX.push({
|
|
1160
1137
|
t: TextXActionType.INSERT,
|
|
1161
1138
|
body: insertBody,
|
|
1162
1139
|
len: insertBody.dataStream.length,
|
|
1163
|
-
line: 0
|
|
1164
|
-
|
|
1140
|
+
line: 0,
|
|
1141
|
+
segmentId
|
|
1142
|
+
});
|
|
1143
|
+
const path = getRichTextEditPath(docDataModel, segmentId);
|
|
1144
|
+
return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), doMutation;
|
|
1165
1145
|
}
|
|
1166
1146
|
__name(replaceSelectionFactory, "replaceSelectionFactory");
|
|
1167
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 || {});
|
|
@@ -1263,10 +1243,9 @@ __name(getRetainAndDeleteFromReplace, "getRetainAndDeleteFromReplace");
|
|
|
1263
1243
|
const EditorInsertTextCommandId = "doc.command.insert-text", InsertCommand = {
|
|
1264
1244
|
id: EditorInsertTextCommandId,
|
|
1265
1245
|
type: CommandType.COMMAND,
|
|
1266
|
-
// eslint-disable-next-line max-lines-per-function
|
|
1267
1246
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1268
1247
|
var _a11;
|
|
1269
|
-
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);
|
|
1270
1249
|
if (docDataModel == null)
|
|
1271
1250
|
return !1;
|
|
1272
1251
|
const activeRange = textSelectionManagerService.getActiveTextRangeWithStyle(), originBody = docDataModel.getSelfOrHeaderFooterModel((_a11 = activeRange == null ? void 0 : activeRange.segmentId) != null ? _a11 : "").getBody();
|
|
@@ -1284,7 +1263,7 @@ const EditorInsertTextCommandId = "doc.command.insert-text", InsertCommand = {
|
|
|
1284
1263
|
params: {
|
|
1285
1264
|
unitId,
|
|
1286
1265
|
actions: [],
|
|
1287
|
-
textRanges
|
|
1266
|
+
textRanges,
|
|
1288
1267
|
debounce: !0
|
|
1289
1268
|
}
|
|
1290
1269
|
}, textX = new TextX(), jsonX = JSONX.getInstance();
|
|
@@ -1296,11 +1275,11 @@ const EditorInsertTextCommandId = "doc.command.insert-text", InsertCommand = {
|
|
|
1296
1275
|
});
|
|
1297
1276
|
else {
|
|
1298
1277
|
const { dos, retain } = getRetainAndDeleteFromReplace(actualRange, segmentId, 0, originBody);
|
|
1299
|
-
textX.push(...dos),
|
|
1278
|
+
textX.push(...dos), doMutation.params.textRanges = [{
|
|
1300
1279
|
startOffset: startOffset + cursorMove + retain,
|
|
1301
1280
|
endOffset: startOffset + cursorMove + retain,
|
|
1302
1281
|
collapsed
|
|
1303
|
-
}]
|
|
1282
|
+
}];
|
|
1304
1283
|
}
|
|
1305
1284
|
textX.push({
|
|
1306
1285
|
t: TextXActionType.INSERT,
|
|
@@ -1876,6 +1855,67 @@ function getDeleteRowContentActionParams(rangeInfo, viewModel) {
|
|
|
1876
1855
|
};
|
|
1877
1856
|
}
|
|
1878
1857
|
__name(getDeleteRowContentActionParams, "getDeleteRowContentActionParams");
|
|
1858
|
+
var CellPosition = /* @__PURE__ */ ((CellPosition2) => (CellPosition2[CellPosition2.NEXT = 0] = "NEXT", CellPosition2[CellPosition2.PREV = 1] = "PREV", CellPosition2))(CellPosition || {});
|
|
1859
|
+
function getCellOffsets(viewModel, range, position) {
|
|
1860
|
+
const { startOffset } = range;
|
|
1861
|
+
let targetTable = null;
|
|
1862
|
+
for (const section of viewModel.children) {
|
|
1863
|
+
for (const paragraph of section.children) {
|
|
1864
|
+
const table = paragraph.children[0];
|
|
1865
|
+
if (table && startOffset > table.startIndex && startOffset < table.endIndex) {
|
|
1866
|
+
targetTable = table;
|
|
1867
|
+
break;
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
if (targetTable)
|
|
1871
|
+
break;
|
|
1872
|
+
}
|
|
1873
|
+
if (targetTable == null)
|
|
1874
|
+
return null;
|
|
1875
|
+
let cellIndex = -1, rowIndex = -1, targetRow = null;
|
|
1876
|
+
for (const row of targetTable.children) {
|
|
1877
|
+
for (const cell of row.children)
|
|
1878
|
+
if (startOffset > cell.startIndex && startOffset < cell.endIndex) {
|
|
1879
|
+
cellIndex = row.children.indexOf(cell), rowIndex = targetTable.children.indexOf(row), targetRow = row;
|
|
1880
|
+
break;
|
|
1881
|
+
}
|
|
1882
|
+
if (cellIndex > -1)
|
|
1883
|
+
break;
|
|
1884
|
+
}
|
|
1885
|
+
if (cellIndex === -1 || rowIndex === -1 || targetRow == null)
|
|
1886
|
+
return null;
|
|
1887
|
+
let newCell = null;
|
|
1888
|
+
if (position === 0) {
|
|
1889
|
+
if (newCell = targetRow.children[cellIndex + 1], !newCell) {
|
|
1890
|
+
const nextRow = targetTable.children[rowIndex + 1];
|
|
1891
|
+
nextRow && (newCell = nextRow.children[0]);
|
|
1892
|
+
}
|
|
1893
|
+
} else if (newCell = targetRow.children[cellIndex - 1], !newCell) {
|
|
1894
|
+
const prevRow = targetTable.children[rowIndex - 1];
|
|
1895
|
+
prevRow && (newCell = prevRow.children[prevRow.children.length - 1]);
|
|
1896
|
+
}
|
|
1897
|
+
if (newCell) {
|
|
1898
|
+
const { startIndex, endIndex } = newCell;
|
|
1899
|
+
return {
|
|
1900
|
+
startOffset: startIndex + 1,
|
|
1901
|
+
endOffset: endIndex - 2
|
|
1902
|
+
};
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
__name(getCellOffsets, "getCellOffsets");
|
|
1906
|
+
function getCustomBlockIdsInSelections(body, selections) {
|
|
1907
|
+
const customBlockIds = [], { customBlocks = [] } = body;
|
|
1908
|
+
for (const selection of selections) {
|
|
1909
|
+
const { startOffset, endOffset } = selection;
|
|
1910
|
+
if (!(startOffset == null || endOffset == null))
|
|
1911
|
+
for (const customBlock of customBlocks) {
|
|
1912
|
+
const { startIndex } = customBlock;
|
|
1913
|
+
startIndex >= startOffset && startIndex < endOffset && customBlockIds.push(customBlock.blockId);
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
return customBlockIds;
|
|
1917
|
+
}
|
|
1918
|
+
__name(getCustomBlockIdsInSelections, "getCustomBlockIdsInSelections");
|
|
1879
1919
|
function hasRangeInTable(ranges) {
|
|
1880
1920
|
return ranges.some((range) => {
|
|
1881
1921
|
const { anchorNodePosition } = range;
|
|
@@ -1886,10 +1926,10 @@ __name(hasRangeInTable, "hasRangeInTable");
|
|
|
1886
1926
|
const InnerPasteCommand = {
|
|
1887
1927
|
id: "doc.command.inner-paste",
|
|
1888
1928
|
type: CommandType.COMMAND,
|
|
1889
|
-
// eslint-disable-next-line max-lines-per-function
|
|
1929
|
+
// eslint-disable-next-line max-lines-per-function, complexity
|
|
1890
1930
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
1891
|
-
var _a11;
|
|
1892
|
-
const { segmentId, textRanges, doc } = params, commandService = accessor.get(ICommandService), textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), selections = textSelectionManagerService.getCurrentTextRanges(), { body, tableSource } = doc;
|
|
1931
|
+
var _a11, _b, _c, _d;
|
|
1932
|
+
const { segmentId, textRanges, doc } = params, commandService = accessor.get(ICommandService), textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), selections = textSelectionManagerService.getCurrentTextRanges(), { body, tableSource, drawings } = doc;
|
|
1893
1933
|
if (!Array.isArray(selections) || selections.length === 0 || body == null)
|
|
1894
1934
|
return !1;
|
|
1895
1935
|
const docDataModel = univerInstanceService.getCurrentUniverDocInstance(), originBody = docDataModel == null ? void 0 : docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
@@ -1900,11 +1940,12 @@ const InnerPasteCommand = {
|
|
|
1900
1940
|
params: {
|
|
1901
1941
|
unitId,
|
|
1902
1942
|
actions: [],
|
|
1903
|
-
textRanges
|
|
1943
|
+
textRanges,
|
|
1944
|
+
segmentId
|
|
1904
1945
|
}
|
|
1905
1946
|
}, memoryCursor = new MemoryCursor();
|
|
1906
1947
|
memoryCursor.reset();
|
|
1907
|
-
const textX = new TextX(), jsonX = JSONX.getInstance(), rawActions = [], hasTable = !!((_a11 = body.tables) != null && _a11.length);
|
|
1948
|
+
const textX = new TextX(), jsonX = JSONX.getInstance(), rawActions = [], hasTable = !!((_a11 = body.tables) != null && _a11.length), hasCustomBlock = !!((_b = body.customBlocks) != null && _b.length);
|
|
1908
1949
|
if (hasTable && segmentId || hasTable && hasRangeInTable(selections))
|
|
1909
1950
|
return !1;
|
|
1910
1951
|
for (const selection of selections) {
|
|
@@ -1918,6 +1959,17 @@ const InnerPasteCommand = {
|
|
|
1918
1959
|
const action = jsonX.insertOp(["tableSource", tableId], table);
|
|
1919
1960
|
rawActions.push(action);
|
|
1920
1961
|
}
|
|
1962
|
+
if (hasCustomBlock && drawings) {
|
|
1963
|
+
const drawingLen = (_d = (_c = docDataModel.getSnapshot().drawingsOrder) == null ? void 0 : _c.length) != null ? _d : 0;
|
|
1964
|
+
for (const block of cloneBody.customBlocks) {
|
|
1965
|
+
const { blockId } = block, drawingId = Tools.generateRandomId(6);
|
|
1966
|
+
block.blockId = drawingId;
|
|
1967
|
+
const drawing = Tools.deepClone(drawings[blockId]);
|
|
1968
|
+
drawing.drawingId = drawingId;
|
|
1969
|
+
const action = jsonX.insertOp(["drawings", drawingId], drawing), orderAction = jsonX.insertOp(["drawingsOrder", drawingLen], drawingId);
|
|
1970
|
+
rawActions.push(action), rawActions.push(orderAction);
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1921
1973
|
if (collapsed)
|
|
1922
1974
|
textX.push({
|
|
1923
1975
|
t: TextXActionType.RETAIN,
|
|
@@ -2042,11 +2094,23 @@ function getCutActionsFromRectRanges(ranges, docDataModel, viewModel, segmentId)
|
|
|
2042
2094
|
return rawActions.push(jsonX.editOp(textX.serialize(), path)), rawActions.reduce((acc, cur) => JSONX.compose(acc, cur), null);
|
|
2043
2095
|
}
|
|
2044
2096
|
__name(getCutActionsFromRectRanges, "getCutActionsFromRectRanges");
|
|
2097
|
+
function getCutActionsFromDocRanges(textRanges, rectRanges, docDataModel, viewModel, segmentId) {
|
|
2098
|
+
let rawActions = [];
|
|
2099
|
+
if (Array.isArray(textRanges) && (textRanges == null ? void 0 : textRanges.length) !== 0 && (rawActions = getCutActionsFromTextRanges(textRanges, docDataModel, segmentId)), Array.isArray(rectRanges) && (rectRanges == null ? void 0 : rectRanges.length) !== 0) {
|
|
2100
|
+
const actions = getCutActionsFromRectRanges(rectRanges, docDataModel, viewModel, segmentId);
|
|
2101
|
+
rawActions == null || rawActions.length === 0 ? rawActions = actions : rawActions = JSONX.compose(
|
|
2102
|
+
rawActions,
|
|
2103
|
+
JSONX.transform(actions, rawActions, "right")
|
|
2104
|
+
);
|
|
2105
|
+
}
|
|
2106
|
+
return rawActions;
|
|
2107
|
+
}
|
|
2108
|
+
__name(getCutActionsFromDocRanges, "getCutActionsFromDocRanges");
|
|
2045
2109
|
const INNER_CUT_COMMAND_ID = "doc.command.inner-cut", CutContentCommand = {
|
|
2046
2110
|
id: INNER_CUT_COMMAND_ID,
|
|
2047
2111
|
type: CommandType.COMMAND,
|
|
2048
2112
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
2049
|
-
var _a11, _b
|
|
2113
|
+
var _a11, _b;
|
|
2050
2114
|
const { segmentId, textRanges } = params, commandService = accessor.get(ICommandService), textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), selections = (_a11 = params.selections) != null ? _a11 : textSelectionManagerService.getCurrentTextRanges(), rectRanges = textSelectionManagerService.getCurrentRectRanges();
|
|
2051
2115
|
if ((!Array.isArray(selections) || selections.length === 0) && (!Array.isArray(rectRanges) || rectRanges.length === 0))
|
|
2052
2116
|
return !1;
|
|
@@ -2067,30 +2131,9 @@ const INNER_CUT_COMMAND_ID = "doc.command.inner-cut", CutContentCommand = {
|
|
|
2067
2131
|
textRanges
|
|
2068
2132
|
}
|
|
2069
2133
|
};
|
|
2070
|
-
|
|
2071
|
-
const actions = getCutActionsFromRectRanges(rectRanges, docDataModel, viewModel, segmentId);
|
|
2072
|
-
((_c = doMutation.params.actions) == null ? void 0 : _c.length) === 0 || doMutation.params.actions == null ? doMutation.params.actions = actions : doMutation.params.actions = JSONX.compose(
|
|
2073
|
-
doMutation.params.actions,
|
|
2074
|
-
JSONX.transform(actions, doMutation.params.actions, "right")
|
|
2075
|
-
);
|
|
2076
|
-
}
|
|
2077
|
-
return !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
2134
|
+
return doMutation.params.actions = getCutActionsFromDocRanges(selections, rectRanges, docDataModel, viewModel, segmentId), !!commandService.syncExecuteCommand(doMutation.id, doMutation.params);
|
|
2078
2135
|
}, "handler")
|
|
2079
|
-
}
|
|
2080
|
-
function getCustomBlockIdsInSelections(body, selections) {
|
|
2081
|
-
const customBlockIds = [], { customBlocks = [] } = body;
|
|
2082
|
-
for (const selection of selections) {
|
|
2083
|
-
const { startOffset, endOffset } = selection;
|
|
2084
|
-
if (!(startOffset == null || endOffset == null))
|
|
2085
|
-
for (const customBlock of customBlocks) {
|
|
2086
|
-
const { startIndex } = customBlock;
|
|
2087
|
-
startIndex >= startOffset && startIndex < endOffset && customBlockIds.push(customBlock.blockId);
|
|
2088
|
-
}
|
|
2089
|
-
}
|
|
2090
|
-
return customBlockIds;
|
|
2091
|
-
}
|
|
2092
|
-
__name(getCustomBlockIdsInSelections, "getCustomBlockIdsInSelections");
|
|
2093
|
-
const DeleteCustomBlockCommand = {
|
|
2136
|
+
}, DeleteCustomBlockCommand = {
|
|
2094
2137
|
id: "doc.command.delete-custom-block",
|
|
2095
2138
|
type: CommandType.COMMAND,
|
|
2096
2139
|
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
@@ -2499,12 +2542,12 @@ const IMEInputCommand = {
|
|
|
2499
2542
|
const previousActiveRange = imeInputManagerService.getActiveRange();
|
|
2500
2543
|
if (!previousActiveRange)
|
|
2501
2544
|
return !1;
|
|
2502
|
-
const {
|
|
2545
|
+
const { style, segmentId } = previousActiveRange, body = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody();
|
|
2503
2546
|
if (body == null)
|
|
2504
2547
|
return !1;
|
|
2505
2548
|
const insertRange = getInsertSelection(previousActiveRange, body);
|
|
2506
2549
|
Object.assign(previousActiveRange, insertRange);
|
|
2507
|
-
const len = newText.length, textRanges = [
|
|
2550
|
+
const { startOffset } = previousActiveRange, len = newText.length, textRanges = [
|
|
2508
2551
|
{
|
|
2509
2552
|
startOffset: startOffset + len,
|
|
2510
2553
|
endOffset: startOffset + len,
|
|
@@ -3453,17 +3496,17 @@ let DocAutoFormatService = (_a6 = class extends Disposable {
|
|
|
3453
3496
|
}
|
|
3454
3497
|
onAutoFormat(id, params) {
|
|
3455
3498
|
var _a11, _b, _c, _d, _e, _f;
|
|
3456
|
-
const
|
|
3499
|
+
const autoFormats = (_a11 = this._matches.get(id)) != null ? _a11 : [], unit = this._univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC), selection = this._textSelectionManagerService.getActiveTextRangeWithStyle();
|
|
3457
3500
|
if (unit && selection) {
|
|
3458
3501
|
const doc = unit.getSelfOrHeaderFooterModel(selection.segmentId), context = {
|
|
3459
3502
|
unit: doc,
|
|
3460
3503
|
selection,
|
|
3461
3504
|
isBody: !selection.segmentId,
|
|
3462
3505
|
paragraphs: getParagraphsInRange(selection, (_c = (_b = doc.getBody()) == null ? void 0 : _b.paragraphs) != null ? _c : []),
|
|
3463
|
-
customRanges:
|
|
3506
|
+
customRanges: getCustomRangesInterestsWithRange(selection, (_e = (_d = doc.getBody()) == null ? void 0 : _d.customRanges) != null ? _e : []),
|
|
3464
3507
|
commandId: id,
|
|
3465
3508
|
commandParams: params
|
|
3466
|
-
}, matched =
|
|
3509
|
+
}, matched = autoFormats.find((i) => i.match(context));
|
|
3467
3510
|
return (_f = matched == null ? void 0 : matched.getMutations(context)) != null ? _f : [];
|
|
3468
3511
|
}
|
|
3469
3512
|
return [];
|
|
@@ -3524,21 +3567,12 @@ let NormalInputController = (_a7 = class extends Disposable {
|
|
|
3524
3567
|
const unitId = documentModel.getUnitId(), { event, content = "", activeRange } = config, e = event, skeleton = (_a11 = this._renderManagerService.getRenderById(documentModel.getUnitId())) == null ? void 0 : _a11.with(DocSkeletonManagerService).getSkeleton();
|
|
3525
3568
|
if (e.data == null || skeleton == null || !skeleton || !activeRange)
|
|
3526
3569
|
return;
|
|
3527
|
-
const {
|
|
3528
|
-
{
|
|
3529
|
-
startOffset: startOffset + len,
|
|
3530
|
-
endOffset: startOffset + len,
|
|
3531
|
-
segmentId,
|
|
3532
|
-
segmentPage,
|
|
3533
|
-
style
|
|
3534
|
-
}
|
|
3535
|
-
];
|
|
3570
|
+
const { segmentId } = activeRange;
|
|
3536
3571
|
await this._commandService.executeCommand(InsertCommand.id, {
|
|
3537
3572
|
unitId,
|
|
3538
3573
|
body: {
|
|
3539
3574
|
dataStream: content
|
|
3540
3575
|
},
|
|
3541
|
-
textRanges,
|
|
3542
3576
|
range: activeRange,
|
|
3543
3577
|
segmentId
|
|
3544
3578
|
}), content === " " && await this._commandService.executeCommand(AfterSpaceCommand.id);
|
|
@@ -4034,11 +4068,25 @@ const DocsRenameMutation = {
|
|
|
4034
4068
|
}, DocTableTabCommand = {
|
|
4035
4069
|
id: "doc.table.tab-in-table",
|
|
4036
4070
|
type: CommandType.COMMAND,
|
|
4037
|
-
handler: /* @__PURE__ */ __name(async () =>
|
|
4038
|
-
},
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4071
|
+
handler: /* @__PURE__ */ __name(async (accessor, params) => {
|
|
4072
|
+
const { shift } = params, textSelectionManager = accessor.get(TextSelectionManagerService), activeTextRange = textSelectionManager.getActiveTextRangeWithStyle(), commandService = accessor.get(ICommandService), docDataModel = accessor.get(IUniverInstanceService).getCurrentUniverDocInstance();
|
|
4073
|
+
if (!docDataModel)
|
|
4074
|
+
return !1;
|
|
4075
|
+
const unitId = docDataModel.getUnitId(), docSkeletonManagerService = getCommandSkeleton(accessor, unitId), skeleton = docSkeletonManagerService == null ? void 0 : docSkeletonManagerService.getSkeleton(), viewModel = skeleton == null ? void 0 : skeleton.getViewModel().getSelfOrHeaderFooterViewModel(activeTextRange == null ? void 0 : activeTextRange.segmentId);
|
|
4076
|
+
if (viewModel == null || activeTextRange == null)
|
|
4077
|
+
return !1;
|
|
4078
|
+
let offsets = null;
|
|
4079
|
+
if (shift ? offsets = getCellOffsets(viewModel, activeTextRange, CellPosition.PREV) : offsets = getCellOffsets(viewModel, activeTextRange, CellPosition.NEXT), offsets) {
|
|
4080
|
+
const { startOffset, endOffset } = offsets, textRanges = [{
|
|
4081
|
+
startOffset,
|
|
4082
|
+
endOffset
|
|
4083
|
+
}];
|
|
4084
|
+
return textSelectionManager.replaceTextRanges(textRanges), !0;
|
|
4085
|
+
}
|
|
4086
|
+
return shift === !1 ? await commandService.executeCommand(DocTableInsertRowCommand.id, {
|
|
4087
|
+
position: INSERT_ROW_POSITION.BELLOW
|
|
4088
|
+
}) : !0;
|
|
4089
|
+
}, "handler")
|
|
4042
4090
|
};
|
|
4043
4091
|
var __defProp$1 = Object.defineProperty, __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor, __decorateClass$1 = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
4044
4092
|
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
@@ -4102,7 +4150,6 @@ let UniverDocsPlugin = (_a9 = class extends Plugin {
|
|
|
4102
4150
|
DocTableDeleteColumnsCommand,
|
|
4103
4151
|
DocTableDeleteTableCommand,
|
|
4104
4152
|
DocTableTabCommand,
|
|
4105
|
-
DocTableShiftTabCommand,
|
|
4106
4153
|
DocsRenameMutation,
|
|
4107
4154
|
TabCommand,
|
|
4108
4155
|
AfterSpaceCommand,
|
|
@@ -4141,7 +4188,11 @@ let UniverDocsPlugin = (_a9 = class extends Plugin {
|
|
|
4141
4188
|
UniverDocsPlugin = __decorateClass$1([
|
|
4142
4189
|
__decorateParam$1(1, Inject(Injector))
|
|
4143
4190
|
], UniverDocsPlugin);
|
|
4144
|
-
const
|
|
4191
|
+
const getPlainTextFormBody = /* @__PURE__ */ __name((body) => {
|
|
4192
|
+
let str = body.dataStream;
|
|
4193
|
+
return body.dataStream.endsWith(`\r
|
|
4194
|
+
`) && (str = body.dataStream.slice(0, -2)), str.replaceAll(DataStreamTreeTokenType.CUSTOM_RANGE_START, "").replaceAll(DataStreamTreeTokenType.CUSTOM_RANGE_END, "");
|
|
4195
|
+
}, "getPlainTextFormBody"), getPlainTextFormDocument = /* @__PURE__ */ __name((data) => data.body ? getPlainTextFormBody(data.body) : "", "getPlainTextFormDocument");
|
|
4145
4196
|
function addCustomRangeTextX(param, body) {
|
|
4146
4197
|
const { range, rangeId, rangeType, segmentId } = param, actualRange = getSelectionForAddCustomRange(range, body);
|
|
4147
4198
|
if (!actualRange)
|
|
@@ -4197,13 +4248,13 @@ function addCustomRangeFactory(param, body) {
|
|
|
4197
4248
|
__name(addCustomRangeFactory, "addCustomRangeFactory");
|
|
4198
4249
|
function addCustomRangeBySelectionFactory(accessor, param) {
|
|
4199
4250
|
var _a11;
|
|
4200
|
-
const {
|
|
4251
|
+
const { rangeId, rangeType, wholeEntity } = param, textSelectionManagerService = accessor.get(TextSelectionManagerService), univerInstanceService = accessor.get(IUniverInstanceService), selection = textSelectionManagerService.getActiveTextRangeWithStyle(), segmentId = selection == null ? void 0 : selection.segmentId;
|
|
4201
4252
|
if (!selection)
|
|
4202
4253
|
return !1;
|
|
4203
4254
|
const documentDataModel = univerInstanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_DOC);
|
|
4204
4255
|
if (!documentDataModel)
|
|
4205
4256
|
return !1;
|
|
4206
|
-
const body = documentDataModel.getBody(), unitId = documentDataModel.getUnitId();
|
|
4257
|
+
const body = documentDataModel.getSelfOrHeaderFooterModel(selection.segmentId).getBody(), unitId = documentDataModel.getUnitId();
|
|
4207
4258
|
if (!body)
|
|
4208
4259
|
return !1;
|
|
4209
4260
|
const { startOffset, endOffset } = normalizeSelection(selection), customRanges = (_a11 = body.customRanges) != null ? _a11 : [], relativeCustomRanges = [];
|
|
@@ -4270,8 +4321,8 @@ function addCustomRangeBySelectionFactory(accessor, param) {
|
|
|
4270
4321
|
actions: [],
|
|
4271
4322
|
textRanges: void 0
|
|
4272
4323
|
}
|
|
4273
|
-
};
|
|
4274
|
-
return doMutation.params.actions = jsonX.editOp(textX.serialize()), doMutation;
|
|
4324
|
+
}, path = getRichTextEditPath(documentDataModel, segmentId);
|
|
4325
|
+
return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), doMutation;
|
|
4275
4326
|
}
|
|
4276
4327
|
__name(addCustomRangeBySelectionFactory, "addCustomRangeBySelectionFactory");
|
|
4277
4328
|
function deleteCustomRangeTextX(accessor, params) {
|
|
@@ -4279,7 +4330,7 @@ function deleteCustomRangeTextX(accessor, params) {
|
|
|
4279
4330
|
const { unitId, rangeId, segmentId } = params, documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId);
|
|
4280
4331
|
if (!documentDataModel)
|
|
4281
4332
|
return !1;
|
|
4282
|
-
const range = (_b = (_a11 = documentDataModel.getBody()) == null ? void 0 : _a11.customRanges) == null ? void 0 : _b.find((r) => r.rangeId === rangeId);
|
|
4333
|
+
const range = (_b = (_a11 = documentDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()) == null ? void 0 : _a11.customRanges) == null ? void 0 : _b.find((r) => r.rangeId === rangeId);
|
|
4283
4334
|
if (!range)
|
|
4284
4335
|
return !1;
|
|
4285
4336
|
const { startIndex, endIndex } = range, textX = new TextX(), len = endIndex - startIndex + 1;
|
|
@@ -4305,15 +4356,22 @@ function deleteCustomRangeTextX(accessor, params) {
|
|
|
4305
4356
|
}
|
|
4306
4357
|
__name(deleteCustomRangeTextX, "deleteCustomRangeTextX");
|
|
4307
4358
|
function deleteCustomRangeFactory(accessor, params) {
|
|
4359
|
+
const { unitId, segmentId } = params, documentDataModel = accessor.get(IUniverInstanceService).getUnit(unitId);
|
|
4360
|
+
if (!documentDataModel)
|
|
4361
|
+
return !1;
|
|
4308
4362
|
const doMutation = {
|
|
4309
4363
|
id: RichTextEditingMutation.id,
|
|
4310
4364
|
params: {
|
|
4311
4365
|
unitId: params.unitId,
|
|
4312
4366
|
actions: [],
|
|
4313
|
-
textRanges: void 0
|
|
4367
|
+
textRanges: void 0,
|
|
4368
|
+
segmentId
|
|
4314
4369
|
}
|
|
4315
4370
|
}, jsonX = JSONX.getInstance(), textX = deleteCustomRangeTextX(accessor, params);
|
|
4316
|
-
|
|
4371
|
+
if (!textX)
|
|
4372
|
+
return !1;
|
|
4373
|
+
const path = getRichTextEditPath(documentDataModel, segmentId);
|
|
4374
|
+
return doMutation.params.actions = jsonX.editOp(textX.serialize(), path), doMutation;
|
|
4317
4375
|
}
|
|
4318
4376
|
__name(deleteCustomRangeFactory, "deleteCustomRangeFactory");
|
|
4319
4377
|
function addCustomDecorationFactory(param) {
|
|
@@ -4420,17 +4478,20 @@ let DocInterceptorService = (_a10 = class extends Disposable {
|
|
|
4420
4478
|
constructor(_context, _docSkeletonManagerService) {
|
|
4421
4479
|
super();
|
|
4422
4480
|
__publicField(this, "_interceptorsByName", /* @__PURE__ */ new Map());
|
|
4423
|
-
this._context = _context, this._docSkeletonManagerService = _docSkeletonManagerService
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
this.interceptDocumentViewModel(viewModel);
|
|
4429
|
-
}
|
|
4430
|
-
})), this.disposeWithMe(this.intercept(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE, {
|
|
4481
|
+
this._context = _context, this._docSkeletonManagerService = _docSkeletonManagerService;
|
|
4482
|
+
const viewModel = this._docSkeletonManagerService.getViewModel(), unitId = viewModel.getDataModel().getUnitId();
|
|
4483
|
+
if (unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY || unitId === DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)
|
|
4484
|
+
return;
|
|
4485
|
+
this.disposeWithMe(this.interceptDocumentViewModel(viewModel)), this.disposeWithMe(this.intercept(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE, {
|
|
4431
4486
|
priority: -1,
|
|
4432
4487
|
handler: /* @__PURE__ */ __name((data, pos, next) => next(data), "handler")
|
|
4433
4488
|
}));
|
|
4489
|
+
let disposableCollection = new DisposableCollection();
|
|
4490
|
+
viewModel.segmentViewModels$.subscribe((segmentViewModels) => {
|
|
4491
|
+
disposableCollection.dispose(), disposableCollection = new DisposableCollection(), segmentViewModels.forEach((segmentViewModel) => {
|
|
4492
|
+
disposableCollection.add(this.interceptDocumentViewModel(segmentViewModel));
|
|
4493
|
+
});
|
|
4494
|
+
}), this.disposeWithMe(disposableCollection);
|
|
4434
4495
|
}
|
|
4435
4496
|
intercept(name, interceptor) {
|
|
4436
4497
|
const key = name;
|
|
@@ -4520,7 +4581,6 @@ export {
|
|
|
4520
4581
|
DocTableInsertRowAboveCommand,
|
|
4521
4582
|
DocTableInsertRowBellowCommand,
|
|
4522
4583
|
DocTableInsertRowCommand,
|
|
4523
|
-
DocTableShiftTabCommand,
|
|
4524
4584
|
DocTableTabCommand,
|
|
4525
4585
|
EditorInsertTextCommandId,
|
|
4526
4586
|
EnterCommand,
|
|
@@ -4569,6 +4629,9 @@ export {
|
|
|
4569
4629
|
generateParagraphs,
|
|
4570
4630
|
getCommandSkeleton,
|
|
4571
4631
|
getCursorWhenDelete,
|
|
4632
|
+
getCustomBlockIdsInSelections,
|
|
4633
|
+
getCustomRangesInterestsWithRange,
|
|
4634
|
+
getCutActionsFromDocRanges,
|
|
4572
4635
|
getDeleteSelection,
|
|
4573
4636
|
getDocObject,
|
|
4574
4637
|
getDocObjectById,
|
|
@@ -4577,11 +4640,13 @@ export {
|
|
|
4577
4640
|
getInsertSelection,
|
|
4578
4641
|
getParagraphsInRange$1 as getParagraphsInRange,
|
|
4579
4642
|
getParagraphsInRanges,
|
|
4643
|
+
getPlainTextFormBody,
|
|
4580
4644
|
getPlainTextFormDocument,
|
|
4581
4645
|
getRetainAndDeleteFromReplace,
|
|
4582
4646
|
getRichTextEditPath,
|
|
4583
4647
|
getSelectionText,
|
|
4584
4648
|
getTableColumn,
|
|
4649
|
+
hasParagraphInTable,
|
|
4585
4650
|
isSegmentIntersects,
|
|
4586
4651
|
makeSelection,
|
|
4587
4652
|
neoGetDocObject,
|