@univerjs/docs 1.0.0-alpha.8 → 1.0.0-beta.1
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/facade.js +80 -62
- package/lib/cjs/index.js +146 -112
- package/lib/es/facade.js +81 -63
- package/lib/es/index.js +146 -113
- package/lib/facade.js +81 -63
- package/lib/index.js +146 -113
- package/lib/types/commands/commands/set-document-name.command.d.ts +21 -0
- package/lib/types/commands/mutations/docs-rename.mutation.d.ts +2 -2
- package/lib/types/facade/f-document.d.ts +40 -0
- package/lib/types/facade/index.d.ts +1 -1
- package/lib/types/index.d.ts +2 -0
- package/lib/types/services/doc-skeleton-manager.service.d.ts +1 -0
- package/lib/types/services/doc-state-emit.service.d.ts +4 -0
- package/lib/umd/facade.js +2 -2
- package/lib/umd/index.js +2 -2
- package/package.json +4 -4
package/lib/es/index.js
CHANGED
|
@@ -123,9 +123,8 @@ let DocSelectionManagerService = class DocSelectionManagerService extends RxDisp
|
|
|
123
123
|
return (_this$_getTextRanges2 = this._getTextRanges(params)) === null || _this$_getTextRanges2 === void 0 ? void 0 : _this$_getTextRanges2.rectRanges;
|
|
124
124
|
}
|
|
125
125
|
getDocRanges(params = this._currentSelection) {
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
const rectRanges = (_this$getRectRanges = this.getRectRanges(params)) !== null && _this$getRectRanges !== void 0 ? _this$getRectRanges : [];
|
|
126
|
+
const textRanges = this.getTextRanges(params) ?? [];
|
|
127
|
+
const rectRanges = this.getRectRanges(params) ?? [];
|
|
129
128
|
return [...textRanges, ...rectRanges].filter((range) => range.startOffset != null && range.endOffset != null).sort((a, b) => {
|
|
130
129
|
if (a.startOffset > b.startOffset) return 1;
|
|
131
130
|
else if (a.startOffset < b.startOffset) return -1;
|
|
@@ -258,6 +257,13 @@ let DocSkeletonManagerService = class DocSkeletonManagerService extends RxDispos
|
|
|
258
257
|
getViewModel() {
|
|
259
258
|
return this._docViewModel;
|
|
260
259
|
}
|
|
260
|
+
recalculate() {
|
|
261
|
+
const skeleton = this._skeleton;
|
|
262
|
+
skeleton.calculate();
|
|
263
|
+
this._currentSkeletonBefore$.next(skeleton);
|
|
264
|
+
this._currentSkeleton$.next(skeleton);
|
|
265
|
+
return skeleton;
|
|
266
|
+
}
|
|
261
267
|
_init() {
|
|
262
268
|
const documentDataModel = this._context.unit;
|
|
263
269
|
this._update(documentDataModel);
|
|
@@ -270,10 +276,7 @@ let DocSkeletonManagerService = class DocSkeletonManagerService extends RxDispos
|
|
|
270
276
|
this._context.unit = documentDataModel;
|
|
271
277
|
} else if (!this._docViewModel) this._docViewModel = this._buildDocViewModel(documentDataModel);
|
|
272
278
|
if (!this._skeleton) this._skeleton = this._buildSkeleton(this._docViewModel);
|
|
273
|
-
|
|
274
|
-
skeleton.calculate();
|
|
275
|
-
this._currentSkeletonBefore$.next(skeleton);
|
|
276
|
-
this._currentSkeleton$.next(skeleton);
|
|
279
|
+
this.recalculate();
|
|
277
280
|
this._currentViewModel$.next(this._docViewModel);
|
|
278
281
|
}
|
|
279
282
|
_buildSkeleton(documentViewModel) {
|
|
@@ -334,7 +337,7 @@ const RichTextEditingMutation = {
|
|
|
334
337
|
id: RichTextEditingMutationId,
|
|
335
338
|
type: CommandType.MUTATION,
|
|
336
339
|
handler: (accessor, params, options) => {
|
|
337
|
-
var _renderManagerService
|
|
340
|
+
var _renderManagerService;
|
|
338
341
|
const { unitId, segmentId = "", actions, textRanges, prevTextRanges, trigger, noHistory, isCompositionEnd, noNeedSetTextRange, debounce, isEditing = true, isSync: paramsIsSync, syncer } = params;
|
|
339
342
|
const isSync = paramsIsSync || (options === null || options === void 0 ? void 0 : options.fromCollab) || (options === null || options === void 0 ? void 0 : options.fromChangeset);
|
|
340
343
|
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
@@ -344,7 +347,8 @@ const RichTextEditingMutation = {
|
|
|
344
347
|
const documentViewModel = (_renderManagerService = renderManagerService.getRenderUnitById(unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(DocSkeletonManagerService).getViewModel();
|
|
345
348
|
if (documentDataModel == null) throw new Error(`DocumentDataModel not found for unitId: ${unitId}`);
|
|
346
349
|
const docSelectionManagerService = accessor.get(DocSelectionManagerService);
|
|
347
|
-
const docRanges =
|
|
350
|
+
const docRanges = docSelectionManagerService.getDocRanges() ?? [];
|
|
351
|
+
const selectionInfo = docSelectionManagerService.getSelectionInfo();
|
|
348
352
|
const disabled = !!documentDataModel.getSnapshot().disabled;
|
|
349
353
|
if (JSONX.isNoop(actions) || actions && actions.length === 0 || disabled) return {
|
|
350
354
|
unitId,
|
|
@@ -375,11 +379,15 @@ const RichTextEditingMutation = {
|
|
|
375
379
|
debounce,
|
|
376
380
|
redoState: {
|
|
377
381
|
actions,
|
|
378
|
-
textRanges
|
|
382
|
+
textRanges,
|
|
383
|
+
options: params.options,
|
|
384
|
+
isEditing
|
|
379
385
|
},
|
|
380
386
|
undoState: {
|
|
381
387
|
actions: undoActions,
|
|
382
|
-
textRanges: prevTextRanges
|
|
388
|
+
textRanges: prevTextRanges ?? docRanges,
|
|
389
|
+
options: selectionInfo === null || selectionInfo === void 0 ? void 0 : selectionInfo.options,
|
|
390
|
+
isEditing: selectionInfo === null || selectionInfo === void 0 ? void 0 : selectionInfo.isEditing
|
|
383
391
|
},
|
|
384
392
|
isCompositionEnd,
|
|
385
393
|
isSync,
|
|
@@ -403,7 +411,7 @@ const InsertTextCommand = {
|
|
|
403
411
|
id: "doc.command.insert-text",
|
|
404
412
|
type: CommandType.COMMAND,
|
|
405
413
|
handler: (accessor, params) => {
|
|
406
|
-
var
|
|
414
|
+
var _docDataModel$getSelf;
|
|
407
415
|
const commandService = accessor.get(ICommandService);
|
|
408
416
|
const { range, segmentId, body, unitId, cursorOffset } = params;
|
|
409
417
|
const docSelectionManagerService = accessor.get(DocSelectionManagerService);
|
|
@@ -411,11 +419,11 @@ const InsertTextCommand = {
|
|
|
411
419
|
if (docDataModel == null) return false;
|
|
412
420
|
const activeRange = docSelectionManagerService.getActiveTextRange();
|
|
413
421
|
const rangeSegmentId = "segmentId" in range ? range.segmentId : void 0;
|
|
414
|
-
const targetSegmentId =
|
|
422
|
+
const targetSegmentId = segmentId ?? rangeSegmentId ?? (activeRange === null || activeRange === void 0 ? void 0 : activeRange.segmentId) ?? "";
|
|
415
423
|
const originBody = (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(targetSegmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
|
|
416
424
|
if (originBody == null) return false;
|
|
417
425
|
const { startOffset, collapsed } = range;
|
|
418
|
-
const cursorMove = cursorOffset
|
|
426
|
+
const cursorMove = cursorOffset ?? body.dataStream.length;
|
|
419
427
|
const textRanges = [{
|
|
420
428
|
startOffset: startOffset + cursorMove,
|
|
421
429
|
endOffset: startOffset + cursorMove,
|
|
@@ -584,7 +592,7 @@ function getEmptyHeaderFooterBody() {
|
|
|
584
592
|
function createHeaderFooterAction(segmentId, createType, headerFooterConfig, actions, createMode = "single", configPath = ["documentStyle"]) {
|
|
585
593
|
const jsonX = JSONX.getInstance();
|
|
586
594
|
const ID_LEN = 6;
|
|
587
|
-
const firstSegmentId = segmentId
|
|
595
|
+
const firstSegmentId = segmentId ?? generateRandomId(ID_LEN);
|
|
588
596
|
const isHeader = createType === 2 || createType === 0 || createType === 4;
|
|
589
597
|
const insertAction = jsonX.insertOp([isHeader ? "headers" : "footers", firstSegmentId], {
|
|
590
598
|
[isHeader ? "headerId" : "footerId"]: firstSegmentId,
|
|
@@ -643,7 +651,7 @@ const CreateHeaderFooterCommand = {
|
|
|
643
651
|
id: "doc.command.create-header-footer",
|
|
644
652
|
type: CommandType.COMMAND,
|
|
645
653
|
handler: (accessor, params) => {
|
|
646
|
-
var _body$sectionBreaks
|
|
654
|
+
var _body$sectionBreaks, _body$sectionBreaks2;
|
|
647
655
|
const commandService = accessor.get(ICommandService);
|
|
648
656
|
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
649
657
|
const { unitId, segmentId, createType, headerFooterProps, createMode = "single", sectionId } = params;
|
|
@@ -653,10 +661,10 @@ const CreateHeaderFooterCommand = {
|
|
|
653
661
|
if (documentStyle.documentFlavor === DocumentFlavor.MODERN) return false;
|
|
654
662
|
const rawActions = [];
|
|
655
663
|
const jsonX = JSONX.getInstance();
|
|
656
|
-
const sectionIndex = sectionId == null ? -1 : (
|
|
664
|
+
const sectionIndex = sectionId == null ? -1 : (body === null || body === void 0 || (_body$sectionBreaks = body.sectionBreaks) === null || _body$sectionBreaks === void 0 ? void 0 : _body$sectionBreaks.findIndex((section) => section.sectionId === sectionId)) ?? -1;
|
|
657
665
|
const sectionBreak = sectionIndex < 0 ? void 0 : body === null || body === void 0 || (_body$sectionBreaks2 = body.sectionBreaks) === null || _body$sectionBreaks2 === void 0 ? void 0 : _body$sectionBreaks2[sectionIndex];
|
|
658
666
|
if (sectionId != null && !sectionBreak) return false;
|
|
659
|
-
const headerFooterConfig = sectionBreak
|
|
667
|
+
const headerFooterConfig = sectionBreak ?? documentStyle;
|
|
660
668
|
const configPath = sectionId == null ? ["documentStyle"] : [
|
|
661
669
|
"body",
|
|
662
670
|
"sectionBreaks",
|
|
@@ -734,12 +742,58 @@ const SetDocumentDefaultParagraphStyleCommand = {
|
|
|
734
742
|
}
|
|
735
743
|
};
|
|
736
744
|
|
|
745
|
+
//#endregion
|
|
746
|
+
//#region src/commands/mutations/docs-rename.mutation.ts
|
|
747
|
+
const DocsRenameMutation = {
|
|
748
|
+
id: "doc.mutation.rename-doc",
|
|
749
|
+
type: CommandType.MUTATION,
|
|
750
|
+
handler: (accessor, params) => {
|
|
751
|
+
const doc = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
|
|
752
|
+
if (!doc) return false;
|
|
753
|
+
doc.setName(params.name);
|
|
754
|
+
return true;
|
|
755
|
+
}
|
|
756
|
+
};
|
|
757
|
+
|
|
758
|
+
//#endregion
|
|
759
|
+
//#region src/commands/commands/set-document-name.command.ts
|
|
760
|
+
const SetDocumentNameCommand = {
|
|
761
|
+
id: "doc.command.set-name",
|
|
762
|
+
type: CommandType.COMMAND,
|
|
763
|
+
handler: (accessor, params) => {
|
|
764
|
+
if (!params) return false;
|
|
765
|
+
const document = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
|
|
766
|
+
if (!document) return false;
|
|
767
|
+
const commandService = accessor.get(ICommandService);
|
|
768
|
+
const redoParams = {
|
|
769
|
+
unitId: params.unitId,
|
|
770
|
+
name: params.name
|
|
771
|
+
};
|
|
772
|
+
const undoParams = {
|
|
773
|
+
unitId: params.unitId,
|
|
774
|
+
name: document.getTitle() || ""
|
|
775
|
+
};
|
|
776
|
+
if (!commandService.syncExecuteCommand(DocsRenameMutation.id, redoParams)) return false;
|
|
777
|
+
accessor.get(IUndoRedoService).pushUndoRedo({
|
|
778
|
+
unitID: params.unitId,
|
|
779
|
+
redoMutations: [{
|
|
780
|
+
id: DocsRenameMutation.id,
|
|
781
|
+
params: redoParams
|
|
782
|
+
}],
|
|
783
|
+
undoMutations: [{
|
|
784
|
+
id: DocsRenameMutation.id,
|
|
785
|
+
params: undoParams
|
|
786
|
+
}]
|
|
787
|
+
});
|
|
788
|
+
return true;
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
|
|
737
792
|
//#endregion
|
|
738
793
|
//#region src/utils/sections.ts
|
|
739
794
|
/** Returns document-level section breaks, excluding table-cell and modern-column sentinels. */
|
|
740
795
|
function getTopLevelSectionBreaks(body) {
|
|
741
|
-
|
|
742
|
-
const sectionBreakByIndex = new Map(((_body$sectionBreaks = body.sectionBreaks) !== null && _body$sectionBreaks !== void 0 ? _body$sectionBreaks : []).map((sectionBreak) => [sectionBreak.startIndex, sectionBreak]));
|
|
796
|
+
const sectionBreakByIndex = new Map((body.sectionBreaks ?? []).map((sectionBreak) => [sectionBreak.startIndex, sectionBreak]));
|
|
743
797
|
const result = [];
|
|
744
798
|
let tableCellDepth = 0;
|
|
745
799
|
let columnDepth = 0;
|
|
@@ -763,7 +817,7 @@ const SetSectionHeaderFooterLinkCommand = {
|
|
|
763
817
|
id: "doc.command.set-section-header-footer-link",
|
|
764
818
|
type: CommandType.COMMAND,
|
|
765
819
|
handler: (accessor, params) => {
|
|
766
|
-
var _snapshot$body$sectio
|
|
820
|
+
var _snapshot$body$sectio;
|
|
767
821
|
if (!params) return false;
|
|
768
822
|
const instanceService = accessor.get(IUniverInstanceService);
|
|
769
823
|
const commandService = accessor.get(ICommandService);
|
|
@@ -773,7 +827,7 @@ const SetSectionHeaderFooterLinkCommand = {
|
|
|
773
827
|
const sections = getTopLevelSectionBreaks(snapshot.body);
|
|
774
828
|
const sectionIndex = sections.findIndex((section) => section.sectionId === params.sectionId);
|
|
775
829
|
if (sectionIndex <= 0) return false;
|
|
776
|
-
const storageIndex = (_snapshot$body$sectio =
|
|
830
|
+
const storageIndex = ((_snapshot$body$sectio = snapshot.body.sectionBreaks) === null || _snapshot$body$sectio === void 0 ? void 0 : _snapshot$body$sectio.findIndex((item) => item.sectionId === params.sectionId)) ?? -1;
|
|
777
831
|
if (storageIndex < 0) return false;
|
|
778
832
|
const context = {
|
|
779
833
|
snapshot,
|
|
@@ -831,7 +885,7 @@ function buildUnlinkActions(context, kind, requestedSegmentId) {
|
|
|
831
885
|
const explicitSegmentId = sections[sectionIndex][key];
|
|
832
886
|
if (typeof explicitSegmentId === "string" && explicitSegmentId) return null;
|
|
833
887
|
const sourceSegmentId = resolveSectionHeaderFooterReference(snapshot.documentStyle, sections, sectionIndex - 1, key).segmentId;
|
|
834
|
-
const segmentId = requestedSegmentId
|
|
888
|
+
const segmentId = requestedSegmentId ?? generateRandomId(6);
|
|
835
889
|
const resources = kind === "header" ? snapshot.headers : snapshot.footers;
|
|
836
890
|
if (resources === null || resources === void 0 ? void 0 : resources[segmentId]) return null;
|
|
837
891
|
const source = sourceSegmentId ? resources === null || resources === void 0 ? void 0 : resources[sourceSegmentId] : void 0;
|
|
@@ -858,14 +912,12 @@ function isValidParams(params) {
|
|
|
858
912
|
return Boolean((params === null || params === void 0 ? void 0 : params.unitId) && params.paragraphId && Number.isInteger(params.startOffset) && Number.isInteger(params.endOffset) && params.startOffset >= 0 && params.endOffset >= params.startOffset && params.style && Object.keys(params.style).length > 0);
|
|
859
913
|
}
|
|
860
914
|
function getCurrentParagraph(body, params) {
|
|
861
|
-
|
|
862
|
-
const matches = ((_body$paragraphs = body.paragraphs) !== null && _body$paragraphs !== void 0 ? _body$paragraphs : []).filter((paragraph) => paragraph.paragraphId === params.paragraphId);
|
|
915
|
+
const matches = (body.paragraphs ?? []).filter((paragraph) => paragraph.paragraphId === params.paragraphId);
|
|
863
916
|
if (matches.length !== 1) return null;
|
|
864
917
|
const paragraph = matches[0];
|
|
865
918
|
return getParagraphContentStartOffset(body, paragraph) === params.startOffset && paragraph.startIndex === params.endOffset && body.dataStream[params.endOffset] === "\r" ? paragraph : null;
|
|
866
919
|
}
|
|
867
920
|
function createParagraphStyleTextX(body, paragraph, params) {
|
|
868
|
-
var _paragraph$paragraphS;
|
|
869
921
|
const textX = new TextX();
|
|
870
922
|
const initializesTextRuns = Boolean(params.style.textStyle && params.startOffset < params.endOffset && body.textRuns == null);
|
|
871
923
|
if (params.startOffset > 0) textX.push({
|
|
@@ -895,7 +947,7 @@ function createParagraphStyleTextX(body, paragraph, params) {
|
|
|
895
947
|
...Tools.deepClone(paragraph),
|
|
896
948
|
startIndex: 0,
|
|
897
949
|
paragraphStyle: {
|
|
898
|
-
...Tools.deepClone(
|
|
950
|
+
...Tools.deepClone(paragraph.paragraphStyle ?? {}),
|
|
899
951
|
...Tools.deepClone(params.style)
|
|
900
952
|
}
|
|
901
953
|
}]
|
|
@@ -919,12 +971,12 @@ const UpdateDocumentParagraphStyleCommand = {
|
|
|
919
971
|
id: "doc.command.update-paragraph-style",
|
|
920
972
|
type: CommandType.COMMAND,
|
|
921
973
|
handler: (accessor, params) => {
|
|
922
|
-
var
|
|
974
|
+
var _documentDataModel$ge;
|
|
923
975
|
if (!isValidParams(params)) return false;
|
|
924
976
|
const instanceService = accessor.get(IUniverInstanceService);
|
|
925
977
|
const commandService = accessor.get(ICommandService);
|
|
926
978
|
const documentDataModel = instanceService.getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
|
|
927
|
-
const segmentId =
|
|
979
|
+
const segmentId = params.segmentId ?? "";
|
|
928
980
|
const body = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.getBody();
|
|
929
981
|
if (!documentDataModel || !body) return false;
|
|
930
982
|
const paragraph = getCurrentParagraph(body, params);
|
|
@@ -956,8 +1008,7 @@ const UpdateDocumentParagraphStyleCommand = {
|
|
|
956
1008
|
//#endregion
|
|
957
1009
|
//#region src/utils/section-columns.ts
|
|
958
1010
|
function resolveSectionValue(sectionValue, documentValue, fallback) {
|
|
959
|
-
|
|
960
|
-
return (_ref = sectionValue !== null && sectionValue !== void 0 ? sectionValue : documentValue) !== null && _ref !== void 0 ? _ref : fallback;
|
|
1011
|
+
return sectionValue ?? documentValue ?? fallback;
|
|
961
1012
|
}
|
|
962
1013
|
function getEffectivePageSize(documentStyle, section) {
|
|
963
1014
|
var _section$pageSize, _documentStyle$pageSi, _section$pageSize2, _documentStyle$pageSi2;
|
|
@@ -985,7 +1036,6 @@ function assertPositivePageSetup(pageSize, contentSize) {
|
|
|
985
1036
|
}
|
|
986
1037
|
/** Resolves nominal traditional page geometry without requiring a renderer. */
|
|
987
1038
|
function getEffectiveSectionPageSetup(documentStyle, section) {
|
|
988
|
-
var _section$pageNumberSt;
|
|
989
1039
|
const pageSize = getEffectivePageSize(documentStyle, section);
|
|
990
1040
|
const margins = getEffectiveMargins(documentStyle, section);
|
|
991
1041
|
const contentSize = {
|
|
@@ -993,7 +1043,7 @@ function getEffectiveSectionPageSetup(documentStyle, section) {
|
|
|
993
1043
|
height: pageSize.height - margins.top - margins.bottom
|
|
994
1044
|
};
|
|
995
1045
|
assertPositivePageSetup(pageSize, contentSize);
|
|
996
|
-
const pageNumberStart = (
|
|
1046
|
+
const pageNumberStart = (section === null || section === void 0 ? void 0 : section.pageNumberStart) ?? (documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.pageNumberStart);
|
|
997
1047
|
return {
|
|
998
1048
|
pageSize,
|
|
999
1049
|
pageOrient: resolveSectionValue(section === null || section === void 0 ? void 0 : section.pageOrient, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.pageOrient, PageOrientType.PORTRAIT),
|
|
@@ -1018,7 +1068,7 @@ function createSectionColumnProperties(documentStyle, section, columnCount, gap,
|
|
|
1018
1068
|
if (widths.some((width) => !Number.isFinite(width) || width < 0)) throw new RangeError("Section column widths must be finite and non-negative.");
|
|
1019
1069
|
if (widths.reduce((sum, width) => sum + width, 0) > availableWidth) throw new RangeError("Section columns exceed the available page content width.");
|
|
1020
1070
|
}
|
|
1021
|
-
return (widths
|
|
1071
|
+
return (widths ?? Array.from({ length: columnCount }, () => availableWidth / columnCount)).map((width, index) => ({
|
|
1022
1072
|
width: Math.max(0, width),
|
|
1023
1073
|
paddingEnd: index === columnCount - 1 ? 0 : safeGap
|
|
1024
1074
|
}));
|
|
@@ -1090,13 +1140,13 @@ const InsertDocumentSectionBreakCommand = {
|
|
|
1090
1140
|
id: "doc.command.insert-section-break",
|
|
1091
1141
|
type: CommandType.COMMAND,
|
|
1092
1142
|
handler: (accessor, params) => {
|
|
1093
|
-
var
|
|
1143
|
+
var _body$sectionBreaks;
|
|
1094
1144
|
if (!params) return false;
|
|
1095
1145
|
const context = getTraditionalDocumentContext(accessor, params.unitId);
|
|
1096
1146
|
if (!context || !params.sectionId || !Number.isInteger(params.offset) || params.nextSectionType != null && !isValidEnumValue(SectionType, params.nextSectionType)) return false;
|
|
1097
1147
|
const { body, documentDataModel, commandService } = context;
|
|
1098
1148
|
const insertedSection = {
|
|
1099
|
-
...Tools.deepClone(
|
|
1149
|
+
...Tools.deepClone(params.config ?? {}),
|
|
1100
1150
|
sectionId: params.sectionId,
|
|
1101
1151
|
startIndex: params.offset
|
|
1102
1152
|
};
|
|
@@ -1148,7 +1198,7 @@ const InsertDocumentColumnBreakCommand = {
|
|
|
1148
1198
|
rangeId: `docx-break-${generateRandomId()}`,
|
|
1149
1199
|
rangeType: CustomRangeType.CUSTOM,
|
|
1150
1200
|
wholeEntity: true,
|
|
1151
|
-
properties: {
|
|
1201
|
+
properties: { breakType: DocxBreakType.COLUMN }
|
|
1152
1202
|
}]
|
|
1153
1203
|
});
|
|
1154
1204
|
return executeSectionTextX(context.commandService, context.documentDataModel, textX, InsertDocumentColumnBreakCommand.id);
|
|
@@ -1164,7 +1214,7 @@ const DeleteDocumentSectionBreakCommand = {
|
|
|
1164
1214
|
const sections = getTopLevelSectionBreaks(context.body);
|
|
1165
1215
|
if (sections.length <= 1) return false;
|
|
1166
1216
|
const section = sections.find((item) => item.sectionId === params.sectionId);
|
|
1167
|
-
if (!section || section === sections.
|
|
1217
|
+
if (!section || section === sections[sections.length - 1]) return false;
|
|
1168
1218
|
const textX = new TextX();
|
|
1169
1219
|
textX.retain(section.startIndex);
|
|
1170
1220
|
textX.delete(1);
|
|
@@ -1187,7 +1237,6 @@ function isValidTopLevelInsertionOffset(body, offset) {
|
|
|
1187
1237
|
return Number.isInteger(offset) && offset >= 0 && offset <= body.dataStream.length && !((_body$tables = body.tables) === null || _body$tables === void 0 ? void 0 : _body$tables.some((range) => containsInteriorInsertionOffset(getTableRangeInterval(range), offset))) && !((_body$columnGroups = body.columnGroups) === null || _body$columnGroups === void 0 ? void 0 : _body$columnGroups.some((range) => containsInteriorInsertionOffset(getColumnGroupRangeInterval(range), offset))) && !((_body$blockRanges = body.blockRanges) === null || _body$blockRanges === void 0 ? void 0 : _body$blockRanges.some((range) => containsInteriorInsertionOffset(getBlockRangeInterval(range), offset)));
|
|
1188
1238
|
}
|
|
1189
1239
|
function isValidSectionConfig(section, documentStyle) {
|
|
1190
|
-
var _section$pageSize, _ref, _section$marginTop, _ref2, _section$marginBottom, _ref3, _section$marginLeft, _ref4, _section$marginRight, _section$columnProper;
|
|
1191
1240
|
if (section.sectionType != null && !isValidEnumValue(SectionType, section.sectionType)) return false;
|
|
1192
1241
|
if (section.pageOrient != null && !isValidEnumValue(PageOrientType, section.pageOrient)) return false;
|
|
1193
1242
|
if (section.columnSeparatorType != null && !isValidEnumValue(ColumnSeparatorType, section.columnSeparatorType)) return false;
|
|
@@ -1199,13 +1248,13 @@ function isValidSectionConfig(section, documentStyle) {
|
|
|
1199
1248
|
section.marginLeft,
|
|
1200
1249
|
section.marginRight
|
|
1201
1250
|
].some((margin) => margin != null && (!Number.isFinite(margin) || margin < 0))) return false;
|
|
1202
|
-
const pageSize =
|
|
1203
|
-
const marginTop =
|
|
1204
|
-
const marginBottom =
|
|
1205
|
-
const marginLeft =
|
|
1206
|
-
const marginRight =
|
|
1251
|
+
const pageSize = section.pageSize ?? documentStyle.pageSize;
|
|
1252
|
+
const marginTop = section.marginTop ?? documentStyle.marginTop ?? 0;
|
|
1253
|
+
const marginBottom = section.marginBottom ?? documentStyle.marginBottom ?? 0;
|
|
1254
|
+
const marginLeft = section.marginLeft ?? documentStyle.marginLeft ?? 0;
|
|
1255
|
+
const marginRight = section.marginRight ?? documentStyle.marginRight ?? 0;
|
|
1207
1256
|
if ((pageSize === null || pageSize === void 0 ? void 0 : pageSize.width) != null && marginLeft + marginRight >= pageSize.width || (pageSize === null || pageSize === void 0 ? void 0 : pageSize.height) != null && marginTop + marginBottom >= pageSize.height) return false;
|
|
1208
|
-
const columns =
|
|
1257
|
+
const columns = section.columnProperties ?? [];
|
|
1209
1258
|
if (columns.some(({ width, paddingEnd }) => !Number.isFinite(width) || !Number.isFinite(paddingEnd) || width < 0 || paddingEnd < 0)) return false;
|
|
1210
1259
|
return columns.reduce((sum, { width, paddingEnd }) => sum + width + paddingEnd, 0) <= getSectionContentWidth(documentStyle, section);
|
|
1211
1260
|
}
|
|
@@ -1281,7 +1330,6 @@ function createRemoveCustomBlockActions(params) {
|
|
|
1281
1330
|
return composeActions([toBodyEditActions(textX, params.segmentId), createDrawingRemoveActions(params)]);
|
|
1282
1331
|
}
|
|
1283
1332
|
function createDocsCustomBlockDrawing(params) {
|
|
1284
|
-
var _params$componentKey;
|
|
1285
1333
|
const size = resolveDocsCustomBlockSize(params.childType);
|
|
1286
1334
|
const isInline = params.interactionMode === "inline";
|
|
1287
1335
|
return {
|
|
@@ -1289,7 +1337,7 @@ function createDocsCustomBlockDrawing(params) {
|
|
|
1289
1337
|
subUnitId: params.unitId,
|
|
1290
1338
|
drawingId: params.blockId,
|
|
1291
1339
|
drawingType: DrawingTypeEnum.DRAWING_DOM,
|
|
1292
|
-
componentKey:
|
|
1340
|
+
componentKey: params.componentKey ?? "UniverEmbedDocsCustomBlock",
|
|
1293
1341
|
data: createEmbedDocsCustomBlockData(params),
|
|
1294
1342
|
title: params.blockId,
|
|
1295
1343
|
description: "Univer embedded unit custom block",
|
|
@@ -1327,15 +1375,14 @@ function isSheetLikeDocsCustomBlockChildType(childType) {
|
|
|
1327
1375
|
return childType === UniverInstanceType.UNIVER_SHEET || childType === UniverInstanceType.UNIVER_BASE;
|
|
1328
1376
|
}
|
|
1329
1377
|
function createEmbedDocsCustomBlockData(params) {
|
|
1330
|
-
var _params$embedId, _params$interactionMo;
|
|
1331
1378
|
return {
|
|
1332
1379
|
version: 1,
|
|
1333
|
-
embedId:
|
|
1380
|
+
embedId: params.embedId ?? params.blockId,
|
|
1334
1381
|
hostUnitId: params.unitId,
|
|
1335
1382
|
hostAnchorId: params.blockId,
|
|
1336
1383
|
childUnitId: params.childUnitId,
|
|
1337
1384
|
childType: params.childType,
|
|
1338
|
-
interactionMode:
|
|
1385
|
+
interactionMode: params.interactionMode ?? "block"
|
|
1339
1386
|
};
|
|
1340
1387
|
}
|
|
1341
1388
|
function isEmbedDocsCustomBlockData(data) {
|
|
@@ -1362,53 +1409,36 @@ function createRichTextMutation(unitId, segmentId, actions) {
|
|
|
1362
1409
|
};
|
|
1363
1410
|
}
|
|
1364
1411
|
function toBodyEditActions(textX, segmentId) {
|
|
1365
|
-
|
|
1412
|
+
return JSONX.getInstance().editOp(textX.serialize(), segmentId ? [
|
|
1366
1413
|
"headers",
|
|
1367
1414
|
segmentId,
|
|
1368
1415
|
"body"
|
|
1369
|
-
] : ["body"]);
|
|
1370
|
-
return action !== null && action !== void 0 ? action : [];
|
|
1416
|
+
] : ["body"]) ?? [];
|
|
1371
1417
|
}
|
|
1372
1418
|
function createDrawingInsertActions(params) {
|
|
1373
|
-
var _jsonX$insertOp, _jsonX$insertOp2, _params$drawingOrderI;
|
|
1374
1419
|
if (params.segmentId) return [];
|
|
1375
1420
|
const jsonX = JSONX.getInstance();
|
|
1376
1421
|
const drawing = createDocsCustomBlockDrawing(params);
|
|
1377
|
-
return composeActions([
|
|
1422
|
+
return composeActions([jsonX.insertOp(["drawings", params.blockId], drawing) ?? [], jsonX.insertOp(["drawingsOrder", params.drawingOrderIndex ?? 0], params.blockId) ?? []]);
|
|
1378
1423
|
}
|
|
1379
1424
|
function createDrawingRemoveActions(params) {
|
|
1380
|
-
var _jsonX$removeOp, _jsonX$removeOp2, _params$drawingOrderI2;
|
|
1381
1425
|
if (params.segmentId) return [];
|
|
1382
1426
|
const jsonX = JSONX.getInstance();
|
|
1383
1427
|
const drawing = createDocsCustomBlockDrawing(params);
|
|
1384
|
-
return composeActions([
|
|
1428
|
+
return composeActions([jsonX.removeOp(["drawings", params.blockId], drawing) ?? [], jsonX.removeOp(["drawingsOrder", params.drawingOrderIndex ?? 0], params.blockId) ?? []]);
|
|
1385
1429
|
}
|
|
1386
1430
|
function composeActions(actions) {
|
|
1387
1431
|
return actions.reduce((composed, action) => {
|
|
1388
|
-
var _JSONX$compose;
|
|
1389
1432
|
if (!action || JSONX.isNoop(action) || action.length === 0) return composed;
|
|
1390
1433
|
if (!composed || JSONX.isNoop(composed) || composed.length === 0) return action;
|
|
1391
|
-
return
|
|
1434
|
+
return JSONX.compose(composed, action) ?? [];
|
|
1392
1435
|
}, []);
|
|
1393
1436
|
}
|
|
1394
1437
|
|
|
1395
1438
|
//#endregion
|
|
1396
1439
|
//#region package.json
|
|
1397
1440
|
var name = "@univerjs/docs";
|
|
1398
|
-
var version = "1.0.0-
|
|
1399
|
-
|
|
1400
|
-
//#endregion
|
|
1401
|
-
//#region src/commands/mutations/docs-rename.mutation.ts
|
|
1402
|
-
const DocsRenameMutation = {
|
|
1403
|
-
id: "doc.mutation.rename-doc",
|
|
1404
|
-
type: CommandType.MUTATION,
|
|
1405
|
-
handler: (accessor, params) => {
|
|
1406
|
-
const doc = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
|
|
1407
|
-
if (!doc) return false;
|
|
1408
|
-
doc.setName(params.name);
|
|
1409
|
-
return true;
|
|
1410
|
-
}
|
|
1411
|
-
};
|
|
1441
|
+
var version = "1.0.0-beta.1";
|
|
1412
1442
|
|
|
1413
1443
|
//#endregion
|
|
1414
1444
|
//#region src/config/config.ts
|
|
@@ -1570,10 +1600,9 @@ let DocStateChangeManagerService = class DocStateChangeManagerService extends Rx
|
|
|
1570
1600
|
this._listenDocStateChange();
|
|
1571
1601
|
}
|
|
1572
1602
|
getStateCache(unitId) {
|
|
1573
|
-
var _this$_historyStateCa, _this$_changeStateCac;
|
|
1574
1603
|
return {
|
|
1575
|
-
history:
|
|
1576
|
-
collaboration:
|
|
1604
|
+
history: this._historyStateCache.get(unitId) ?? [],
|
|
1605
|
+
collaboration: this._changeStateCache.get(unitId) ?? []
|
|
1577
1606
|
};
|
|
1578
1607
|
}
|
|
1579
1608
|
setStateCache(unitId, cache) {
|
|
@@ -1597,9 +1626,9 @@ let DocStateChangeManagerService = class DocStateChangeManagerService extends Rx
|
|
|
1597
1626
|
}
|
|
1598
1627
|
_listenDocStateChange() {
|
|
1599
1628
|
this._docStateEmitService.docStateChangeParams$.pipe(takeUntil(this.dispose$)).subscribe((changeStateInfo) => {
|
|
1600
|
-
var _this$_docStateChange
|
|
1629
|
+
var _this$_docStateChange;
|
|
1601
1630
|
if (changeStateInfo == null) return;
|
|
1602
|
-
const interceptedChangeStateInfo = (_this$_docStateChange =
|
|
1631
|
+
const interceptedChangeStateInfo = ((_this$_docStateChange = this._docStateChangeInterceptorService) === null || _this$_docStateChange === void 0 ? void 0 : _this$_docStateChange.transformChangeStateInfo(changeStateInfo)) ?? changeStateInfo;
|
|
1603
1632
|
if (interceptedChangeStateInfo == null) return;
|
|
1604
1633
|
if (interceptedChangeStateInfo.isSync) return;
|
|
1605
1634
|
const { isCompositionEnd: _isCompositionEnd, isSync: _isSync, syncer: _syncer, ...changeState } = interceptedChangeStateInfo;
|
|
@@ -1612,6 +1641,8 @@ let DocStateChangeManagerService = class DocStateChangeManagerService extends Rx
|
|
|
1612
1641
|
if (type === "history" && (trigger === RedoCommandId || trigger === UndoCommandId)) return;
|
|
1613
1642
|
const stateCache = type === "history" ? this._historyStateCache : this._changeStateCache;
|
|
1614
1643
|
const cb = type === "history" ? this._pushHistory.bind(this) : this._emitChangeState.bind(this);
|
|
1644
|
+
const pendingStates = stateCache.get(unitId);
|
|
1645
|
+
if ((pendingStates === null || pendingStates === void 0 ? void 0 : pendingStates.length) && pendingStates[pendingStates.length - 1].segmentId !== changeState.segmentId) cb(unitId);
|
|
1615
1646
|
if (stateCache.has(unitId)) {
|
|
1616
1647
|
const cacheStates = stateCache.get(unitId);
|
|
1617
1648
|
cacheStates === null || cacheStates === void 0 || cacheStates.push(changeState);
|
|
@@ -1640,12 +1671,18 @@ let DocStateChangeManagerService = class DocStateChangeManagerService extends Rx
|
|
|
1640
1671
|
const redoParams = {
|
|
1641
1672
|
unitId,
|
|
1642
1673
|
actions: cacheStates.reduce((acc, cur) => JSONX.compose(acc, cur.redoState.actions), null),
|
|
1643
|
-
textRanges: lastState.redoState.textRanges
|
|
1674
|
+
textRanges: lastState.redoState.textRanges,
|
|
1675
|
+
segmentId: lastState.segmentId,
|
|
1676
|
+
options: lastState.redoState.options,
|
|
1677
|
+
isEditing: lastState.redoState.isEditing
|
|
1644
1678
|
};
|
|
1645
1679
|
const undoParams = {
|
|
1646
1680
|
unitId,
|
|
1647
1681
|
actions: cacheStates.reverse().reduce((acc, cur) => JSONX.compose(acc, cur.undoState.actions), null),
|
|
1648
|
-
textRanges: firstState.undoState.textRanges
|
|
1682
|
+
textRanges: firstState.undoState.textRanges,
|
|
1683
|
+
segmentId: firstState.segmentId,
|
|
1684
|
+
options: firstState.undoState.options,
|
|
1685
|
+
isEditing: firstState.undoState.isEditing
|
|
1649
1686
|
};
|
|
1650
1687
|
undoRedoService.pushUndoRedo({
|
|
1651
1688
|
unitID: unitId,
|
|
@@ -1674,12 +1711,18 @@ let DocStateChangeManagerService = class DocStateChangeManagerService extends Rx
|
|
|
1674
1711
|
redoState: {
|
|
1675
1712
|
unitId,
|
|
1676
1713
|
actions: cacheStates.reduce((acc, cur) => JSONX.compose(acc, cur.redoState.actions), null),
|
|
1677
|
-
textRanges: lastState.redoState.textRanges
|
|
1714
|
+
textRanges: lastState.redoState.textRanges,
|
|
1715
|
+
segmentId: lastState.segmentId,
|
|
1716
|
+
options: lastState.redoState.options,
|
|
1717
|
+
isEditing: lastState.redoState.isEditing
|
|
1678
1718
|
},
|
|
1679
1719
|
undoState: {
|
|
1680
1720
|
unitId,
|
|
1681
1721
|
actions: cacheStates.reverse().reduce((acc, cur) => JSONX.compose(acc, cur.undoState.actions), null),
|
|
1682
|
-
textRanges: firstState.undoState.textRanges
|
|
1722
|
+
textRanges: firstState.undoState.textRanges,
|
|
1723
|
+
segmentId: firstState.segmentId,
|
|
1724
|
+
options: firstState.undoState.options,
|
|
1725
|
+
isEditing: firstState.undoState.isEditing
|
|
1683
1726
|
},
|
|
1684
1727
|
segmentId,
|
|
1685
1728
|
noHistory,
|
|
@@ -1735,14 +1778,11 @@ var DocTextResolverService = class extends Disposable {
|
|
|
1735
1778
|
replaceable: true
|
|
1736
1779
|
});
|
|
1737
1780
|
text += replacement.text;
|
|
1738
|
-
for (let index = 0; index < replacement.text.length; index += 1) {
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
replaceable: (_replacement$replacea = replacement.replaceable) !== null && _replacement$replacea !== void 0 ? _replacement$replacea : false
|
|
1744
|
-
});
|
|
1745
|
-
}
|
|
1781
|
+
for (let index = 0; index < replacement.text.length; index += 1) characters.push({
|
|
1782
|
+
startOffset: replacement.startOffset,
|
|
1783
|
+
endOffset: replacement.endOffset,
|
|
1784
|
+
replaceable: replacement.replaceable ?? false
|
|
1785
|
+
});
|
|
1746
1786
|
sourceOffset = replacement.endOffset;
|
|
1747
1787
|
}
|
|
1748
1788
|
text += body.dataStream.slice(sourceOffset);
|
|
@@ -1795,6 +1835,7 @@ let UniverDocsPlugin = class UniverDocsPlugin extends Plugin {
|
|
|
1795
1835
|
UpdateTextCommand,
|
|
1796
1836
|
CreateHeaderFooterCommand,
|
|
1797
1837
|
SetDocumentDefaultParagraphStyleCommand,
|
|
1838
|
+
SetDocumentNameCommand,
|
|
1798
1839
|
SetSectionHeaderFooterLinkCommand,
|
|
1799
1840
|
UpdateDocumentParagraphStyleCommand,
|
|
1800
1841
|
UpdateDocumentSectionCommand,
|
|
@@ -1871,10 +1912,7 @@ let DocInterceptorService = class DocInterceptorService extends Disposable {
|
|
|
1871
1912
|
if (!this._interceptorsByName.has(key)) this._interceptorsByName.set(key, []);
|
|
1872
1913
|
const interceptors = this._interceptorsByName.get(key);
|
|
1873
1914
|
interceptors.push(interceptor);
|
|
1874
|
-
this._interceptorsByName.set(key, interceptors.sort((a, b) =>
|
|
1875
|
-
var _b$priority, _a$priority;
|
|
1876
|
-
return ((_b$priority = b.priority) !== null && _b$priority !== void 0 ? _b$priority : 0) - ((_a$priority = a.priority) !== null && _a$priority !== void 0 ? _a$priority : 0);
|
|
1877
|
-
}));
|
|
1915
|
+
this._interceptorsByName.set(key, interceptors.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0)));
|
|
1878
1916
|
return this.disposeWithMe(toDisposable(() => remove(this._interceptorsByName.get(key), interceptor)));
|
|
1879
1917
|
}
|
|
1880
1918
|
fetchThroughInterceptors(name) {
|
|
@@ -1885,19 +1923,17 @@ let DocInterceptorService = class DocInterceptorService extends Disposable {
|
|
|
1885
1923
|
const disposableCollection = new DisposableCollection();
|
|
1886
1924
|
disposableCollection.add(viewModel.registerCustomRangeInterceptor({
|
|
1887
1925
|
getCustomRange: (index) => {
|
|
1888
|
-
var _viewModel$getDataMod;
|
|
1889
1926
|
return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE)(viewModel.getCustomRangeRaw(index), {
|
|
1890
1927
|
index,
|
|
1891
1928
|
unitId: viewModel.getDataModel().getUnitId(),
|
|
1892
|
-
customRanges:
|
|
1929
|
+
customRanges: viewModel.getDataModel().getCustomRanges() ?? []
|
|
1893
1930
|
});
|
|
1894
1931
|
},
|
|
1895
1932
|
getCustomDecoration: (index) => {
|
|
1896
|
-
var _viewModel$getDataMod2;
|
|
1897
1933
|
return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION)(viewModel.getCustomDecorationRaw(index), {
|
|
1898
1934
|
index,
|
|
1899
1935
|
unitId: viewModel.getDataModel().getUnitId(),
|
|
1900
|
-
customDecorations:
|
|
1936
|
+
customDecorations: viewModel.getDataModel().getCustomDecorations() ?? []
|
|
1901
1937
|
});
|
|
1902
1938
|
}
|
|
1903
1939
|
}));
|
|
@@ -1935,7 +1971,7 @@ function addCustomRangeBySelectionFactory(accessor, param) {
|
|
|
1935
1971
|
const { rangeId, rangeType, wholeEntity, properties, unitId, selections: propSelection } = param;
|
|
1936
1972
|
const docSelectionManagerService = accessor.get(DocSelectionManagerService);
|
|
1937
1973
|
const univerInstanceService = accessor.get(IUniverInstanceService);
|
|
1938
|
-
const selections = propSelection
|
|
1974
|
+
const selections = propSelection ?? docSelectionManagerService.getTextRanges({
|
|
1939
1975
|
unitId,
|
|
1940
1976
|
subUnitId: unitId
|
|
1941
1977
|
});
|
|
@@ -2018,8 +2054,7 @@ function generateParagraphs(dataStream, prevParagraph, borderBottom, existingPar
|
|
|
2018
2054
|
if (prevParagraph.paragraphStyle.headingId) paragraph.paragraphStyle.headingId = generateRandomId(6);
|
|
2019
2055
|
}
|
|
2020
2056
|
if (borderBottom) {
|
|
2021
|
-
|
|
2022
|
-
(_paragraph$paragraphS = paragraph.paragraphStyle) !== null && _paragraph$paragraphS !== void 0 || (paragraph.paragraphStyle = {});
|
|
2057
|
+
paragraph.paragraphStyle ??= {};
|
|
2023
2058
|
paragraph.paragraphStyle.borderBottom = Tools.deepClone(borderBottom);
|
|
2024
2059
|
paragraph.paragraphStyle.spaceBelow = { v: 10 };
|
|
2025
2060
|
}
|
|
@@ -2030,7 +2065,7 @@ function generateParagraphs(dataStream, prevParagraph, borderBottom, existingPar
|
|
|
2030
2065
|
//#endregion
|
|
2031
2066
|
//#region src/utils/replace-selection-factory.ts
|
|
2032
2067
|
function replaceSelectionFactory(accessor, params) {
|
|
2033
|
-
var _params$selection, _docDataModel$getSelf
|
|
2068
|
+
var _params$selection, _docDataModel$getSelf;
|
|
2034
2069
|
const { unitId, body: insertBody, doc } = params;
|
|
2035
2070
|
let docDataModel = doc;
|
|
2036
2071
|
if (!docDataModel) docDataModel = accessor.get(IUniverInstanceService).getUnit(unitId);
|
|
@@ -2039,9 +2074,9 @@ function replaceSelectionFactory(accessor, params) {
|
|
|
2039
2074
|
const body = (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
|
|
2040
2075
|
if (!body) return false;
|
|
2041
2076
|
const docSelectionManagerService = accessor.get(DocSelectionManagerService);
|
|
2042
|
-
const selection =
|
|
2077
|
+
const selection = params.selection ?? docSelectionManagerService.getActiveTextRange();
|
|
2043
2078
|
if (!selection || !body) return false;
|
|
2044
|
-
const textRanges =
|
|
2079
|
+
const textRanges = params.textRanges ?? [{
|
|
2045
2080
|
startOffset: selection.startOffset + insertBody.dataStream.length,
|
|
2046
2081
|
endOffset: selection.startOffset + insertBody.dataStream.length,
|
|
2047
2082
|
collapsed: true,
|
|
@@ -2072,7 +2107,6 @@ function replaceSelectionFactory(accessor, params) {
|
|
|
2072
2107
|
//#endregion
|
|
2073
2108
|
//#region src/utils/transform-position.ts
|
|
2074
2109
|
function buildDocTransform(width, height, position) {
|
|
2075
|
-
var _position$left, _position$top;
|
|
2076
2110
|
return {
|
|
2077
2111
|
size: {
|
|
2078
2112
|
width,
|
|
@@ -2080,11 +2114,11 @@ function buildDocTransform(width, height, position) {
|
|
|
2080
2114
|
},
|
|
2081
2115
|
positionH: {
|
|
2082
2116
|
relativeFrom: ObjectRelativeFromH.PAGE,
|
|
2083
|
-
posOffset: (
|
|
2117
|
+
posOffset: (position === null || position === void 0 ? void 0 : position.left) ?? 0
|
|
2084
2118
|
},
|
|
2085
2119
|
positionV: {
|
|
2086
2120
|
relativeFrom: ObjectRelativeFromV.PARAGRAPH,
|
|
2087
|
-
posOffset: (
|
|
2121
|
+
posOffset: (position === null || position === void 0 ? void 0 : position.top) ?? 0
|
|
2088
2122
|
},
|
|
2089
2123
|
angle: 0
|
|
2090
2124
|
};
|
|
@@ -2130,7 +2164,7 @@ function consumeContentInsertRange(accessor, unitId) {
|
|
|
2130
2164
|
}
|
|
2131
2165
|
function getContentInsertRange(accessor, unitId) {
|
|
2132
2166
|
var _accessor$get$getCurr;
|
|
2133
|
-
const _unitId = unitId
|
|
2167
|
+
const _unitId = unitId ?? ((_accessor$get$getCurr = accessor.get(IUniverInstanceService).getCurrentUnitOfType(UniverInstanceType.UNIVER_DOC)) === null || _accessor$get$getCurr === void 0 ? void 0 : _accessor$get$getCurr.getUnitId());
|
|
2134
2168
|
if (!_unitId) return null;
|
|
2135
2169
|
const insertRange = consumeContentInsertRange(accessor, _unitId);
|
|
2136
2170
|
if (!insertRange) return null;
|
|
@@ -2143,15 +2177,14 @@ function isHeaderFooterSelection(range) {
|
|
|
2143
2177
|
return Boolean(range === null || range === void 0 ? void 0 : range.segmentId);
|
|
2144
2178
|
}
|
|
2145
2179
|
function normalizeTextRange(textRange) {
|
|
2146
|
-
|
|
2147
|
-
const endOffset = (_textRange$endOffset = textRange.endOffset) !== null && _textRange$endOffset !== void 0 ? _textRange$endOffset : textRange.startOffset;
|
|
2180
|
+
const endOffset = textRange.endOffset ?? textRange.startOffset;
|
|
2148
2181
|
return {
|
|
2149
2182
|
...textRange,
|
|
2150
2183
|
endOffset,
|
|
2151
|
-
collapsed:
|
|
2152
|
-
segmentId:
|
|
2184
|
+
collapsed: textRange.collapsed ?? textRange.startOffset === endOffset,
|
|
2185
|
+
segmentId: textRange.segmentId ?? ""
|
|
2153
2186
|
};
|
|
2154
2187
|
}
|
|
2155
2188
|
|
|
2156
2189
|
//#endregion
|
|
2157
|
-
export { CreateHeaderFooterCommand, DOC_INTERCEPTOR_POINT, DOC_SELECTION_OPTION_PRESERVE_CARET, DeleteDocumentSectionBreakCommand, DeleteTextCommand, DocBlockMoveValidatorService, DocContentInsertService, DocInterceptorService, DocSelectionManagerService, DocSkeletonManagerService, DocStateChangeManagerService, DocStateEmitService, DocTextResolverService, EMBED_DOCS_CUSTOM_BLOCK_DEFAULT_COMPONENT_KEY, HeaderFooterType, IDocStateChangeInterceptorService, InsertDocumentColumnBreakCommand, InsertDocumentSectionBreakCommand, InsertTextCommand, RichTextEditingMutation, SetDocumentDefaultParagraphStyleCommand, SetSectionHeaderFooterLinkCommand, SetTextSelectionsOperation, UniverDocsPlugin, UpdateDocumentParagraphStyleCommand, UpdateDocumentSectionCommand, UpdateTextCommand, addCustomRangeBySelectionFactory, addCustomRangeFactory, buildDocTransform, consumeContentInsertRange, createDocsCustomBlockDrawing, createDocsCustomBlockInsertMutation, createDocsCustomBlockRemoveMutation, createEmbedDocsCustomBlockData, createInsertCustomBlockActions, createRemoveCustomBlockActions, createSectionColumnProperties, deleteCustomRangeFactory, docDrawingPositionToTransform, generateParagraphs, getContentInsertRange, getEffectiveSectionPageSetup, getSectionContentWidth, getTopLevelSectionBreaks, isEmbedDocsCustomBlockData, isHeaderFooterSelection, isSheetLikeDocsCustomBlockChildType, normalizeTextRange, replaceSelectionFactory, resolveDocsCustomBlockSize, shouldUseInlineTextSelectionForDocsCustomBlockDrawing, transformToDocDrawingPosition };
|
|
2190
|
+
export { CreateHeaderFooterCommand, DOC_INTERCEPTOR_POINT, DOC_SELECTION_OPTION_PRESERVE_CARET, DeleteDocumentSectionBreakCommand, DeleteTextCommand, DocBlockMoveValidatorService, DocContentInsertService, DocInterceptorService, DocSelectionManagerService, DocSkeletonManagerService, DocStateChangeManagerService, DocStateEmitService, DocTextResolverService, EMBED_DOCS_CUSTOM_BLOCK_DEFAULT_COMPONENT_KEY, HeaderFooterType, IDocStateChangeInterceptorService, InsertDocumentColumnBreakCommand, InsertDocumentSectionBreakCommand, InsertTextCommand, RichTextEditingMutation, SetDocumentDefaultParagraphStyleCommand, SetDocumentNameCommand, SetSectionHeaderFooterLinkCommand, SetTextSelectionsOperation, UniverDocsPlugin, UpdateDocumentParagraphStyleCommand, UpdateDocumentSectionCommand, UpdateTextCommand, addCustomRangeBySelectionFactory, addCustomRangeFactory, buildDocTransform, consumeContentInsertRange, createDocsCustomBlockDrawing, createDocsCustomBlockInsertMutation, createDocsCustomBlockRemoveMutation, createEmbedDocsCustomBlockData, createInsertCustomBlockActions, createRemoveCustomBlockActions, createSectionColumnProperties, deleteCustomRangeFactory, docDrawingPositionToTransform, generateParagraphs, getContentInsertRange, getEffectiveSectionPageSetup, getSectionContentWidth, getTopLevelSectionBreaks, isEmbedDocsCustomBlockData, isHeaderFooterSelection, isSheetLikeDocsCustomBlockChildType, normalizeTextRange, replaceSelectionFactory, resolveDocsCustomBlockSize, shouldUseInlineTextSelectionForDocsCustomBlockDrawing, transformToDocDrawingPosition };
|