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