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