@univerjs/docs 1.0.0-alpha.8 → 1.0.0-beta.0

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,7 @@ 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() ?? [];
349
352
  const disabled = !!documentDataModel.getSnapshot().disabled;
350
353
  if (_univerjs_core.JSONX.isNoop(actions) || actions && actions.length === 0 || disabled) return {
351
354
  unitId,
@@ -380,7 +383,7 @@ const RichTextEditingMutation = {
380
383
  },
381
384
  undoState: {
382
385
  actions: undoActions,
383
- textRanges: prevTextRanges !== null && prevTextRanges !== void 0 ? prevTextRanges : docRanges
386
+ textRanges: prevTextRanges ?? docRanges
384
387
  },
385
388
  isCompositionEnd,
386
389
  isSync,
@@ -404,7 +407,7 @@ const InsertTextCommand = {
404
407
  id: "doc.command.insert-text",
405
408
  type: _univerjs_core.CommandType.COMMAND,
406
409
  handler: (accessor, params) => {
407
- var _ref, _ref2, _docDataModel$getSelf;
410
+ var _docDataModel$getSelf;
408
411
  const commandService = accessor.get(_univerjs_core.ICommandService);
409
412
  const { range, segmentId, body, unitId, cursorOffset } = params;
410
413
  const docSelectionManagerService = accessor.get(DocSelectionManagerService);
@@ -412,11 +415,11 @@ const InsertTextCommand = {
412
415
  if (docDataModel == null) return false;
413
416
  const activeRange = docSelectionManagerService.getActiveTextRange();
414
417
  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 : "";
418
+ const targetSegmentId = segmentId ?? rangeSegmentId ?? (activeRange === null || activeRange === void 0 ? void 0 : activeRange.segmentId) ?? "";
416
419
  const originBody = (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(targetSegmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
417
420
  if (originBody == null) return false;
418
421
  const { startOffset, collapsed } = range;
419
- const cursorMove = cursorOffset !== null && cursorOffset !== void 0 ? cursorOffset : body.dataStream.length;
422
+ const cursorMove = cursorOffset ?? body.dataStream.length;
420
423
  const textRanges = [{
421
424
  startOffset: startOffset + cursorMove,
422
425
  endOffset: startOffset + cursorMove,
@@ -585,7 +588,7 @@ function getEmptyHeaderFooterBody() {
585
588
  function createHeaderFooterAction(segmentId, createType, headerFooterConfig, actions, createMode = "single", configPath = ["documentStyle"]) {
586
589
  const jsonX = _univerjs_core.JSONX.getInstance();
587
590
  const ID_LEN = 6;
588
- const firstSegmentId = segmentId !== null && segmentId !== void 0 ? segmentId : (0, _univerjs_core.generateRandomId)(ID_LEN);
591
+ const firstSegmentId = segmentId ?? (0, _univerjs_core.generateRandomId)(ID_LEN);
589
592
  const isHeader = createType === 2 || createType === 0 || createType === 4;
590
593
  const insertAction = jsonX.insertOp([isHeader ? "headers" : "footers", firstSegmentId], {
591
594
  [isHeader ? "headerId" : "footerId"]: firstSegmentId,
@@ -644,7 +647,7 @@ const CreateHeaderFooterCommand = {
644
647
  id: "doc.command.create-header-footer",
645
648
  type: _univerjs_core.CommandType.COMMAND,
646
649
  handler: (accessor, params) => {
647
- var _body$sectionBreaks$f, _body$sectionBreaks, _body$sectionBreaks2;
650
+ var _body$sectionBreaks, _body$sectionBreaks2;
648
651
  const commandService = accessor.get(_univerjs_core.ICommandService);
649
652
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
650
653
  const { unitId, segmentId, createType, headerFooterProps, createMode = "single", sectionId } = params;
@@ -654,10 +657,10 @@ const CreateHeaderFooterCommand = {
654
657
  if (documentStyle.documentFlavor === _univerjs_core.DocumentFlavor.MODERN) return false;
655
658
  const rawActions = [];
656
659
  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;
660
+ 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
661
  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
662
  if (sectionId != null && !sectionBreak) return false;
660
- const headerFooterConfig = sectionBreak !== null && sectionBreak !== void 0 ? sectionBreak : documentStyle;
663
+ const headerFooterConfig = sectionBreak ?? documentStyle;
661
664
  const configPath = sectionId == null ? ["documentStyle"] : [
662
665
  "body",
663
666
  "sectionBreaks",
@@ -739,8 +742,7 @@ const SetDocumentDefaultParagraphStyleCommand = {
739
742
  //#region src/utils/sections.ts
740
743
  /** Returns document-level section breaks, excluding table-cell and modern-column sentinels. */
741
744
  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]));
745
+ const sectionBreakByIndex = new Map((body.sectionBreaks ?? []).map((sectionBreak) => [sectionBreak.startIndex, sectionBreak]));
744
746
  const result = [];
745
747
  let tableCellDepth = 0;
746
748
  let columnDepth = 0;
@@ -764,7 +766,7 @@ const SetSectionHeaderFooterLinkCommand = {
764
766
  id: "doc.command.set-section-header-footer-link",
765
767
  type: _univerjs_core.CommandType.COMMAND,
766
768
  handler: (accessor, params) => {
767
- var _snapshot$body$sectio, _snapshot$body$sectio2;
769
+ var _snapshot$body$sectio;
768
770
  if (!params) return false;
769
771
  const instanceService = accessor.get(_univerjs_core.IUniverInstanceService);
770
772
  const commandService = accessor.get(_univerjs_core.ICommandService);
@@ -774,7 +776,7 @@ const SetSectionHeaderFooterLinkCommand = {
774
776
  const sections = getTopLevelSectionBreaks(snapshot.body);
775
777
  const sectionIndex = sections.findIndex((section) => section.sectionId === params.sectionId);
776
778
  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;
779
+ 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
780
  if (storageIndex < 0) return false;
779
781
  const context = {
780
782
  snapshot,
@@ -832,7 +834,7 @@ function buildUnlinkActions(context, kind, requestedSegmentId) {
832
834
  const explicitSegmentId = sections[sectionIndex][key];
833
835
  if (typeof explicitSegmentId === "string" && explicitSegmentId) return null;
834
836
  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);
837
+ const segmentId = requestedSegmentId ?? (0, _univerjs_core.generateRandomId)(6);
836
838
  const resources = kind === "header" ? snapshot.headers : snapshot.footers;
837
839
  if (resources === null || resources === void 0 ? void 0 : resources[segmentId]) return null;
838
840
  const source = sourceSegmentId ? resources === null || resources === void 0 ? void 0 : resources[sourceSegmentId] : void 0;
@@ -859,14 +861,12 @@ function isValidParams(params) {
859
861
  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
862
  }
861
863
  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);
864
+ const matches = (body.paragraphs ?? []).filter((paragraph) => paragraph.paragraphId === params.paragraphId);
864
865
  if (matches.length !== 1) return null;
865
866
  const paragraph = matches[0];
866
867
  return (0, _univerjs_core.getParagraphContentStartOffset)(body, paragraph) === params.startOffset && paragraph.startIndex === params.endOffset && body.dataStream[params.endOffset] === "\r" ? paragraph : null;
867
868
  }
868
869
  function createParagraphStyleTextX(body, paragraph, params) {
869
- var _paragraph$paragraphS;
870
870
  const textX = new _univerjs_core.TextX();
871
871
  const initializesTextRuns = Boolean(params.style.textStyle && params.startOffset < params.endOffset && body.textRuns == null);
872
872
  if (params.startOffset > 0) textX.push({
@@ -896,7 +896,7 @@ function createParagraphStyleTextX(body, paragraph, params) {
896
896
  ..._univerjs_core.Tools.deepClone(paragraph),
897
897
  startIndex: 0,
898
898
  paragraphStyle: {
899
- ..._univerjs_core.Tools.deepClone((_paragraph$paragraphS = paragraph.paragraphStyle) !== null && _paragraph$paragraphS !== void 0 ? _paragraph$paragraphS : {}),
899
+ ..._univerjs_core.Tools.deepClone(paragraph.paragraphStyle ?? {}),
900
900
  ..._univerjs_core.Tools.deepClone(params.style)
901
901
  }
902
902
  }]
@@ -920,12 +920,12 @@ const UpdateDocumentParagraphStyleCommand = {
920
920
  id: "doc.command.update-paragraph-style",
921
921
  type: _univerjs_core.CommandType.COMMAND,
922
922
  handler: (accessor, params) => {
923
- var _params$segmentId, _documentDataModel$ge;
923
+ var _documentDataModel$ge;
924
924
  if (!isValidParams(params)) return false;
925
925
  const instanceService = accessor.get(_univerjs_core.IUniverInstanceService);
926
926
  const commandService = accessor.get(_univerjs_core.ICommandService);
927
927
  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 : "";
928
+ const segmentId = params.segmentId ?? "";
929
929
  const body = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.getBody();
930
930
  if (!documentDataModel || !body) return false;
931
931
  const paragraph = getCurrentParagraph(body, params);
@@ -957,8 +957,7 @@ const UpdateDocumentParagraphStyleCommand = {
957
957
  //#endregion
958
958
  //#region src/utils/section-columns.ts
959
959
  function resolveSectionValue(sectionValue, documentValue, fallback) {
960
- var _ref;
961
- return (_ref = sectionValue !== null && sectionValue !== void 0 ? sectionValue : documentValue) !== null && _ref !== void 0 ? _ref : fallback;
960
+ return sectionValue ?? documentValue ?? fallback;
962
961
  }
963
962
  function getEffectivePageSize(documentStyle, section) {
964
963
  var _section$pageSize, _documentStyle$pageSi, _section$pageSize2, _documentStyle$pageSi2;
@@ -986,7 +985,6 @@ function assertPositivePageSetup(pageSize, contentSize) {
986
985
  }
987
986
  /** Resolves nominal traditional page geometry without requiring a renderer. */
988
987
  function getEffectiveSectionPageSetup(documentStyle, section) {
989
- var _section$pageNumberSt;
990
988
  const pageSize = getEffectivePageSize(documentStyle, section);
991
989
  const margins = getEffectiveMargins(documentStyle, section);
992
990
  const contentSize = {
@@ -994,7 +992,7 @@ function getEffectiveSectionPageSetup(documentStyle, section) {
994
992
  height: pageSize.height - margins.top - margins.bottom
995
993
  };
996
994
  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;
995
+ const pageNumberStart = (section === null || section === void 0 ? void 0 : section.pageNumberStart) ?? (documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.pageNumberStart);
998
996
  return {
999
997
  pageSize,
1000
998
  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 +1017,7 @@ function createSectionColumnProperties(documentStyle, section, columnCount, gap,
1019
1017
  if (widths.some((width) => !Number.isFinite(width) || width < 0)) throw new RangeError("Section column widths must be finite and non-negative.");
1020
1018
  if (widths.reduce((sum, width) => sum + width, 0) > availableWidth) throw new RangeError("Section columns exceed the available page content width.");
1021
1019
  }
1022
- return (widths !== null && widths !== void 0 ? widths : Array.from({ length: columnCount }, () => availableWidth / columnCount)).map((width, index) => ({
1020
+ return (widths ?? Array.from({ length: columnCount }, () => availableWidth / columnCount)).map((width, index) => ({
1023
1021
  width: Math.max(0, width),
1024
1022
  paddingEnd: index === columnCount - 1 ? 0 : safeGap
1025
1023
  }));
@@ -1091,13 +1089,13 @@ const InsertDocumentSectionBreakCommand = {
1091
1089
  id: "doc.command.insert-section-break",
1092
1090
  type: _univerjs_core.CommandType.COMMAND,
1093
1091
  handler: (accessor, params) => {
1094
- var _params$config, _body$sectionBreaks;
1092
+ var _body$sectionBreaks;
1095
1093
  if (!params) return false;
1096
1094
  const context = getTraditionalDocumentContext(accessor, params.unitId);
1097
1095
  if (!context || !params.sectionId || !Number.isInteger(params.offset) || params.nextSectionType != null && !isValidEnumValue(_univerjs_core.SectionType, params.nextSectionType)) return false;
1098
1096
  const { body, documentDataModel, commandService } = context;
1099
1097
  const insertedSection = {
1100
- ..._univerjs_core.Tools.deepClone((_params$config = params.config) !== null && _params$config !== void 0 ? _params$config : {}),
1098
+ ..._univerjs_core.Tools.deepClone(params.config ?? {}),
1101
1099
  sectionId: params.sectionId,
1102
1100
  startIndex: params.offset
1103
1101
  };
@@ -1165,7 +1163,7 @@ const DeleteDocumentSectionBreakCommand = {
1165
1163
  const sections = getTopLevelSectionBreaks(context.body);
1166
1164
  if (sections.length <= 1) return false;
1167
1165
  const section = sections.find((item) => item.sectionId === params.sectionId);
1168
- if (!section || section === sections.at(-1)) return false;
1166
+ if (!section || section === sections[sections.length - 1]) return false;
1169
1167
  const textX = new _univerjs_core.TextX();
1170
1168
  textX.retain(section.startIndex);
1171
1169
  textX.delete(1);
@@ -1188,7 +1186,6 @@ function isValidTopLevelInsertionOffset(body, offset) {
1188
1186
  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
1187
  }
1190
1188
  function isValidSectionConfig(section, documentStyle) {
1191
- var _section$pageSize, _ref, _section$marginTop, _ref2, _section$marginBottom, _ref3, _section$marginLeft, _ref4, _section$marginRight, _section$columnProper;
1192
1189
  if (section.sectionType != null && !isValidEnumValue(_univerjs_core.SectionType, section.sectionType)) return false;
1193
1190
  if (section.pageOrient != null && !isValidEnumValue(_univerjs_core.PageOrientType, section.pageOrient)) return false;
1194
1191
  if (section.columnSeparatorType != null && !isValidEnumValue(_univerjs_core.ColumnSeparatorType, section.columnSeparatorType)) return false;
@@ -1200,13 +1197,13 @@ function isValidSectionConfig(section, documentStyle) {
1200
1197
  section.marginLeft,
1201
1198
  section.marginRight
1202
1199
  ].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;
1200
+ const pageSize = section.pageSize ?? documentStyle.pageSize;
1201
+ const marginTop = section.marginTop ?? documentStyle.marginTop ?? 0;
1202
+ const marginBottom = section.marginBottom ?? documentStyle.marginBottom ?? 0;
1203
+ const marginLeft = section.marginLeft ?? documentStyle.marginLeft ?? 0;
1204
+ const marginRight = section.marginRight ?? documentStyle.marginRight ?? 0;
1208
1205
  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 : [];
1206
+ const columns = section.columnProperties ?? [];
1210
1207
  if (columns.some(({ width, paddingEnd }) => !Number.isFinite(width) || !Number.isFinite(paddingEnd) || width < 0 || paddingEnd < 0)) return false;
1211
1208
  return columns.reduce((sum, { width, paddingEnd }) => sum + width + paddingEnd, 0) <= getSectionContentWidth(documentStyle, section);
1212
1209
  }
@@ -1282,7 +1279,6 @@ function createRemoveCustomBlockActions(params) {
1282
1279
  return composeActions([toBodyEditActions(textX, params.segmentId), createDrawingRemoveActions(params)]);
1283
1280
  }
1284
1281
  function createDocsCustomBlockDrawing(params) {
1285
- var _params$componentKey;
1286
1282
  const size = resolveDocsCustomBlockSize(params.childType);
1287
1283
  const isInline = params.interactionMode === "inline";
1288
1284
  return {
@@ -1290,7 +1286,7 @@ function createDocsCustomBlockDrawing(params) {
1290
1286
  subUnitId: params.unitId,
1291
1287
  drawingId: params.blockId,
1292
1288
  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,
1289
+ componentKey: params.componentKey ?? "UniverEmbedDocsCustomBlock",
1294
1290
  data: createEmbedDocsCustomBlockData(params),
1295
1291
  title: params.blockId,
1296
1292
  description: "Univer embedded unit custom block",
@@ -1328,15 +1324,14 @@ function isSheetLikeDocsCustomBlockChildType(childType) {
1328
1324
  return childType === _univerjs_core.UniverInstanceType.UNIVER_SHEET || childType === _univerjs_core.UniverInstanceType.UNIVER_BASE;
1329
1325
  }
1330
1326
  function createEmbedDocsCustomBlockData(params) {
1331
- var _params$embedId, _params$interactionMo;
1332
1327
  return {
1333
1328
  version: 1,
1334
- embedId: (_params$embedId = params.embedId) !== null && _params$embedId !== void 0 ? _params$embedId : params.blockId,
1329
+ embedId: params.embedId ?? params.blockId,
1335
1330
  hostUnitId: params.unitId,
1336
1331
  hostAnchorId: params.blockId,
1337
1332
  childUnitId: params.childUnitId,
1338
1333
  childType: params.childType,
1339
- interactionMode: (_params$interactionMo = params.interactionMode) !== null && _params$interactionMo !== void 0 ? _params$interactionMo : "block"
1334
+ interactionMode: params.interactionMode ?? "block"
1340
1335
  };
1341
1336
  }
1342
1337
  function isEmbedDocsCustomBlockData(data) {
@@ -1363,40 +1358,36 @@ function createRichTextMutation(unitId, segmentId, actions) {
1363
1358
  };
1364
1359
  }
1365
1360
  function toBodyEditActions(textX, segmentId) {
1366
- const action = _univerjs_core.JSONX.getInstance().editOp(textX.serialize(), segmentId ? [
1361
+ return _univerjs_core.JSONX.getInstance().editOp(textX.serialize(), segmentId ? [
1367
1362
  "headers",
1368
1363
  segmentId,
1369
1364
  "body"
1370
- ] : ["body"]);
1371
- return action !== null && action !== void 0 ? action : [];
1365
+ ] : ["body"]) ?? [];
1372
1366
  }
1373
1367
  function createDrawingInsertActions(params) {
1374
- var _jsonX$insertOp, _jsonX$insertOp2, _params$drawingOrderI;
1375
1368
  if (params.segmentId) return [];
1376
1369
  const jsonX = _univerjs_core.JSONX.getInstance();
1377
1370
  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 : []]);
1371
+ return composeActions([jsonX.insertOp(["drawings", params.blockId], drawing) ?? [], jsonX.insertOp(["drawingsOrder", params.drawingOrderIndex ?? 0], params.blockId) ?? []]);
1379
1372
  }
1380
1373
  function createDrawingRemoveActions(params) {
1381
- var _jsonX$removeOp, _jsonX$removeOp2, _params$drawingOrderI2;
1382
1374
  if (params.segmentId) return [];
1383
1375
  const jsonX = _univerjs_core.JSONX.getInstance();
1384
1376
  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 : []]);
1377
+ return composeActions([jsonX.removeOp(["drawings", params.blockId], drawing) ?? [], jsonX.removeOp(["drawingsOrder", params.drawingOrderIndex ?? 0], params.blockId) ?? []]);
1386
1378
  }
1387
1379
  function composeActions(actions) {
1388
1380
  return actions.reduce((composed, action) => {
1389
- var _JSONX$compose;
1390
1381
  if (!action || _univerjs_core.JSONX.isNoop(action) || action.length === 0) return composed;
1391
1382
  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 : [];
1383
+ return _univerjs_core.JSONX.compose(composed, action) ?? [];
1393
1384
  }, []);
1394
1385
  }
1395
1386
 
1396
1387
  //#endregion
1397
1388
  //#region package.json
1398
1389
  var name = "@univerjs/docs";
1399
- var version = "1.0.0-alpha.8";
1390
+ var version = "1.0.0-beta.0";
1400
1391
 
1401
1392
  //#endregion
1402
1393
  //#region src/commands/mutations/docs-rename.mutation.ts
@@ -1571,10 +1562,9 @@ let DocStateChangeManagerService = class DocStateChangeManagerService extends _u
1571
1562
  this._listenDocStateChange();
1572
1563
  }
1573
1564
  getStateCache(unitId) {
1574
- var _this$_historyStateCa, _this$_changeStateCac;
1575
1565
  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 : []
1566
+ history: this._historyStateCache.get(unitId) ?? [],
1567
+ collaboration: this._changeStateCache.get(unitId) ?? []
1578
1568
  };
1579
1569
  }
1580
1570
  setStateCache(unitId, cache) {
@@ -1598,9 +1588,9 @@ let DocStateChangeManagerService = class DocStateChangeManagerService extends _u
1598
1588
  }
1599
1589
  _listenDocStateChange() {
1600
1590
  this._docStateEmitService.docStateChangeParams$.pipe((0, rxjs.takeUntil)(this.dispose$)).subscribe((changeStateInfo) => {
1601
- var _this$_docStateChange, _this$_docStateChange2;
1591
+ var _this$_docStateChange;
1602
1592
  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;
1593
+ const interceptedChangeStateInfo = ((_this$_docStateChange = this._docStateChangeInterceptorService) === null || _this$_docStateChange === void 0 ? void 0 : _this$_docStateChange.transformChangeStateInfo(changeStateInfo)) ?? changeStateInfo;
1604
1594
  if (interceptedChangeStateInfo == null) return;
1605
1595
  if (interceptedChangeStateInfo.isSync) return;
1606
1596
  const { isCompositionEnd: _isCompositionEnd, isSync: _isSync, syncer: _syncer, ...changeState } = interceptedChangeStateInfo;
@@ -1736,14 +1726,11 @@ var DocTextResolverService = class extends _univerjs_core.Disposable {
1736
1726
  replaceable: true
1737
1727
  });
1738
1728
  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
- }
1729
+ for (let index = 0; index < replacement.text.length; index += 1) characters.push({
1730
+ startOffset: replacement.startOffset,
1731
+ endOffset: replacement.endOffset,
1732
+ replaceable: replacement.replaceable ?? false
1733
+ });
1747
1734
  sourceOffset = replacement.endOffset;
1748
1735
  }
1749
1736
  text += body.dataStream.slice(sourceOffset);
@@ -1872,10 +1859,7 @@ let DocInterceptorService = class DocInterceptorService extends _univerjs_core.D
1872
1859
  if (!this._interceptorsByName.has(key)) this._interceptorsByName.set(key, []);
1873
1860
  const interceptors = this._interceptorsByName.get(key);
1874
1861
  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
- }));
1862
+ this._interceptorsByName.set(key, interceptors.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0)));
1879
1863
  return this.disposeWithMe((0, _univerjs_core.toDisposable)(() => (0, _univerjs_core.remove)(this._interceptorsByName.get(key), interceptor)));
1880
1864
  }
1881
1865
  fetchThroughInterceptors(name) {
@@ -1886,19 +1870,17 @@ let DocInterceptorService = class DocInterceptorService extends _univerjs_core.D
1886
1870
  const disposableCollection = new _univerjs_core.DisposableCollection();
1887
1871
  disposableCollection.add(viewModel.registerCustomRangeInterceptor({
1888
1872
  getCustomRange: (index) => {
1889
- var _viewModel$getDataMod;
1890
1873
  return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE)(viewModel.getCustomRangeRaw(index), {
1891
1874
  index,
1892
1875
  unitId: viewModel.getDataModel().getUnitId(),
1893
- customRanges: (_viewModel$getDataMod = viewModel.getDataModel().getCustomRanges()) !== null && _viewModel$getDataMod !== void 0 ? _viewModel$getDataMod : []
1876
+ customRanges: viewModel.getDataModel().getCustomRanges() ?? []
1894
1877
  });
1895
1878
  },
1896
1879
  getCustomDecoration: (index) => {
1897
- var _viewModel$getDataMod2;
1898
1880
  return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION)(viewModel.getCustomDecorationRaw(index), {
1899
1881
  index,
1900
1882
  unitId: viewModel.getDataModel().getUnitId(),
1901
- customDecorations: (_viewModel$getDataMod2 = viewModel.getDataModel().getCustomDecorations()) !== null && _viewModel$getDataMod2 !== void 0 ? _viewModel$getDataMod2 : []
1883
+ customDecorations: viewModel.getDataModel().getCustomDecorations() ?? []
1902
1884
  });
1903
1885
  }
1904
1886
  }));
@@ -1936,7 +1918,7 @@ function addCustomRangeBySelectionFactory(accessor, param) {
1936
1918
  const { rangeId, rangeType, wholeEntity, properties, unitId, selections: propSelection } = param;
1937
1919
  const docSelectionManagerService = accessor.get(DocSelectionManagerService);
1938
1920
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
1939
- const selections = propSelection !== null && propSelection !== void 0 ? propSelection : docSelectionManagerService.getTextRanges({
1921
+ const selections = propSelection ?? docSelectionManagerService.getTextRanges({
1940
1922
  unitId,
1941
1923
  subUnitId: unitId
1942
1924
  });
@@ -2019,8 +2001,7 @@ function generateParagraphs(dataStream, prevParagraph, borderBottom, existingPar
2019
2001
  if (prevParagraph.paragraphStyle.headingId) paragraph.paragraphStyle.headingId = (0, _univerjs_core.generateRandomId)(6);
2020
2002
  }
2021
2003
  if (borderBottom) {
2022
- var _paragraph$paragraphS;
2023
- (_paragraph$paragraphS = paragraph.paragraphStyle) !== null && _paragraph$paragraphS !== void 0 || (paragraph.paragraphStyle = {});
2004
+ paragraph.paragraphStyle ??= {};
2024
2005
  paragraph.paragraphStyle.borderBottom = _univerjs_core.Tools.deepClone(borderBottom);
2025
2006
  paragraph.paragraphStyle.spaceBelow = { v: 10 };
2026
2007
  }
@@ -2031,7 +2012,7 @@ function generateParagraphs(dataStream, prevParagraph, borderBottom, existingPar
2031
2012
  //#endregion
2032
2013
  //#region src/utils/replace-selection-factory.ts
2033
2014
  function replaceSelectionFactory(accessor, params) {
2034
- var _params$selection, _docDataModel$getSelf, _params$selection2, _params$textRanges;
2015
+ var _params$selection, _docDataModel$getSelf;
2035
2016
  const { unitId, body: insertBody, doc } = params;
2036
2017
  let docDataModel = doc;
2037
2018
  if (!docDataModel) docDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId);
@@ -2040,9 +2021,9 @@ function replaceSelectionFactory(accessor, params) {
2040
2021
  const body = (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
2041
2022
  if (!body) return false;
2042
2023
  const docSelectionManagerService = accessor.get(DocSelectionManagerService);
2043
- const selection = (_params$selection2 = params.selection) !== null && _params$selection2 !== void 0 ? _params$selection2 : docSelectionManagerService.getActiveTextRange();
2024
+ const selection = params.selection ?? docSelectionManagerService.getActiveTextRange();
2044
2025
  if (!selection || !body) return false;
2045
- const textRanges = (_params$textRanges = params.textRanges) !== null && _params$textRanges !== void 0 ? _params$textRanges : [{
2026
+ const textRanges = params.textRanges ?? [{
2046
2027
  startOffset: selection.startOffset + insertBody.dataStream.length,
2047
2028
  endOffset: selection.startOffset + insertBody.dataStream.length,
2048
2029
  collapsed: true,
@@ -2073,7 +2054,6 @@ function replaceSelectionFactory(accessor, params) {
2073
2054
  //#endregion
2074
2055
  //#region src/utils/transform-position.ts
2075
2056
  function buildDocTransform(width, height, position) {
2076
- var _position$left, _position$top;
2077
2057
  return {
2078
2058
  size: {
2079
2059
  width,
@@ -2081,11 +2061,11 @@ function buildDocTransform(width, height, position) {
2081
2061
  },
2082
2062
  positionH: {
2083
2063
  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
2064
+ posOffset: (position === null || position === void 0 ? void 0 : position.left) ?? 0
2085
2065
  },
2086
2066
  positionV: {
2087
2067
  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
2068
+ posOffset: (position === null || position === void 0 ? void 0 : position.top) ?? 0
2089
2069
  },
2090
2070
  angle: 0
2091
2071
  };
@@ -2131,7 +2111,7 @@ function consumeContentInsertRange(accessor, unitId) {
2131
2111
  }
2132
2112
  function getContentInsertRange(accessor, unitId) {
2133
2113
  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();
2114
+ 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
2115
  if (!_unitId) return null;
2136
2116
  const insertRange = consumeContentInsertRange(accessor, _unitId);
2137
2117
  if (!insertRange) return null;
@@ -2144,13 +2124,12 @@ function isHeaderFooterSelection(range) {
2144
2124
  return Boolean(range === null || range === void 0 ? void 0 : range.segmentId);
2145
2125
  }
2146
2126
  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;
2127
+ const endOffset = textRange.endOffset ?? textRange.startOffset;
2149
2128
  return {
2150
2129
  ...textRange,
2151
2130
  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 : ""
2131
+ collapsed: textRange.collapsed ?? textRange.startOffset === endOffset,
2132
+ segmentId: textRange.segmentId ?? ""
2154
2133
  };
2155
2134
  }
2156
2135