@univerjs/docs 1.0.0-alpha.7 → 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
@@ -13,7 +13,7 @@ const SetTextSelectionsOperation = {
13
13
  };
14
14
 
15
15
  //#endregion
16
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
16
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
17
17
  function _typeof(o) {
18
18
  "@babel/helpers - typeof";
19
19
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -24,7 +24,7 @@ function _typeof(o) {
24
24
  }
25
25
 
26
26
  //#endregion
27
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
27
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPrimitive.js
28
28
  function toPrimitive(t, r) {
29
29
  if ("object" != _typeof(t) || !t) return t;
30
30
  var e = t[Symbol.toPrimitive];
@@ -37,14 +37,14 @@ function toPrimitive(t, r) {
37
37
  }
38
38
 
39
39
  //#endregion
40
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
40
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPropertyKey.js
41
41
  function toPropertyKey(t) {
42
42
  var i = toPrimitive(t, "string");
43
43
  return "symbol" == _typeof(i) ? i : i + "";
44
44
  }
45
45
 
46
46
  //#endregion
47
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
47
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/defineProperty.js
48
48
  function _defineProperty(e, r, t) {
49
49
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
50
50
  value: t,
@@ -55,7 +55,7 @@ function _defineProperty(e, r, t) {
55
55
  }
56
56
 
57
57
  //#endregion
58
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorateParam.js
58
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorateParam.js
59
59
  function __decorateParam(paramIndex, decorator) {
60
60
  return function(target, key) {
61
61
  decorator(target, key, paramIndex);
@@ -63,7 +63,7 @@ function __decorateParam(paramIndex, decorator) {
63
63
  }
64
64
 
65
65
  //#endregion
66
- //#region \0@oxc-project+runtime@0.137.0/helpers/esm/decorate.js
66
+ //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorate.js
67
67
  function __decorate(decorators, target, key, desc) {
68
68
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
69
69
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -73,6 +73,11 @@ function __decorate(decorators, target, key, desc) {
73
73
 
74
74
  //#endregion
75
75
  //#region src/services/doc-selection-manager.service.ts
76
+ /**
77
+ * Keeps a programmatically restored collapsed caret from being promoted back
78
+ * into a neighboring whole-entity selection by feature-specific UI.
79
+ */
80
+ const DOC_SELECTION_OPTION_PRESERVE_CARET = "preserveCaret";
76
81
  let DocSelectionManagerService = class DocSelectionManagerService extends _univerjs_core.RxDisposable {
77
82
  constructor(_commandService, _univerInstanceService) {
78
83
  super();
@@ -119,9 +124,8 @@ let DocSelectionManagerService = class DocSelectionManagerService extends _unive
119
124
  return (_this$_getTextRanges2 = this._getTextRanges(params)) === null || _this$_getTextRanges2 === void 0 ? void 0 : _this$_getTextRanges2.rectRanges;
120
125
  }
121
126
  getDocRanges(params = this._currentSelection) {
122
- var _this$getTextRanges, _this$getRectRanges;
123
- const textRanges = (_this$getTextRanges = this.getTextRanges(params)) !== null && _this$getTextRanges !== void 0 ? _this$getTextRanges : [];
124
- 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) ?? [];
125
129
  return [...textRanges, ...rectRanges].filter((range) => range.startOffset != null && range.endOffset != null).sort((a, b) => {
126
130
  if (a.startOffset > b.startOffset) return 1;
127
131
  else if (a.startOffset < b.startOffset) return -1;
@@ -134,16 +138,6 @@ let DocSelectionManagerService = class DocSelectionManagerService extends _unive
134
138
  const { textRanges } = selectionInfo;
135
139
  return textRanges.find((textRange) => textRange.isActive);
136
140
  }
137
- /**
138
- *
139
- * @deprecated
140
- */
141
- getActiveRectRange() {
142
- const selectionInfo = this._getTextRanges(this._currentSelection);
143
- if (selectionInfo == null) return;
144
- const { rectRanges } = selectionInfo;
145
- return rectRanges.find((rectRange) => rectRange.isActive);
146
- }
147
141
  __TEST_ONLY_add(textRanges, isEditing = true) {
148
142
  if (this._currentSelection == null) return;
149
143
  this._addByParam({
@@ -156,12 +150,6 @@ let DocSelectionManagerService = class DocSelectionManagerService extends _unive
156
150
  style: _univerjs_engine_render.NORMAL_TEXT_SELECTION_PLUGIN_STYLE
157
151
  });
158
152
  }
159
- /**
160
- * @deprecated pls use replaceDocRanges.
161
- */
162
- replaceTextRanges(docRanges, isEditing = true, options) {
163
- return this.replaceDocRanges(docRanges, this._currentSelection, isEditing, options);
164
- }
165
153
  replaceDocRanges(docRanges, params = this._currentSelection, isEditing = true, options) {
166
154
  if (params == null) return;
167
155
  const { unitId, subUnitId } = params;
@@ -212,14 +200,15 @@ let DocSelectionManagerService = class DocSelectionManagerService extends _unive
212
200
  _refresh(param) {
213
201
  const allTextSelectionInfo = this._getTextRanges(param);
214
202
  if (allTextSelectionInfo == null) return;
215
- const { textRanges, rectRanges } = allTextSelectionInfo;
203
+ const { textRanges, rectRanges, options } = allTextSelectionInfo;
216
204
  const docRanges = [...textRanges, ...rectRanges];
217
205
  const { unitId, subUnitId } = param;
218
206
  this._refreshSelection$.next({
219
207
  unitId,
220
208
  subUnitId,
221
209
  docRanges,
222
- isEditing: false
210
+ isEditing: false,
211
+ options
223
212
  });
224
213
  }
225
214
  _replaceByParam(insertParam) {
@@ -269,6 +258,13 @@ let DocSkeletonManagerService = class DocSkeletonManagerService extends _univerj
269
258
  getViewModel() {
270
259
  return this._docViewModel;
271
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
+ }
272
268
  _init() {
273
269
  const documentDataModel = this._context.unit;
274
270
  this._update(documentDataModel);
@@ -281,10 +277,7 @@ let DocSkeletonManagerService = class DocSkeletonManagerService extends _univerj
281
277
  this._context.unit = documentDataModel;
282
278
  } else if (!this._docViewModel) this._docViewModel = this._buildDocViewModel(documentDataModel);
283
279
  if (!this._skeleton) this._skeleton = this._buildSkeleton(this._docViewModel);
284
- const skeleton = this._skeleton;
285
- skeleton.calculate();
286
- this._currentSkeletonBefore$.next(skeleton);
287
- this._currentSkeleton$.next(skeleton);
280
+ this.recalculate();
288
281
  this._currentViewModel$.next(this._docViewModel);
289
282
  }
290
283
  _buildSkeleton(documentViewModel) {
@@ -345,7 +338,7 @@ const RichTextEditingMutation = {
345
338
  id: RichTextEditingMutationId,
346
339
  type: _univerjs_core.CommandType.MUTATION,
347
340
  handler: (accessor, params, options) => {
348
- var _renderManagerService, _docSelectionManagerS;
341
+ var _renderManagerService;
349
342
  const { unitId, segmentId = "", actions, textRanges, prevTextRanges, trigger, noHistory, isCompositionEnd, noNeedSetTextRange, debounce, isEditing = true, isSync: paramsIsSync, syncer } = params;
350
343
  const isSync = paramsIsSync || (options === null || options === void 0 ? void 0 : options.fromCollab) || (options === null || options === void 0 ? void 0 : options.fromChangeset);
351
344
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
@@ -355,7 +348,7 @@ const RichTextEditingMutation = {
355
348
  const documentViewModel = (_renderManagerService = renderManagerService.getRenderUnitById(unitId)) === null || _renderManagerService === void 0 ? void 0 : _renderManagerService.with(DocSkeletonManagerService).getViewModel();
356
349
  if (documentDataModel == null) throw new Error(`DocumentDataModel not found for unitId: ${unitId}`);
357
350
  const docSelectionManagerService = accessor.get(DocSelectionManagerService);
358
- const docRanges = (_docSelectionManagerS = docSelectionManagerService.getDocRanges()) !== null && _docSelectionManagerS !== void 0 ? _docSelectionManagerS : [];
351
+ const docRanges = docSelectionManagerService.getDocRanges() ?? [];
359
352
  const disabled = !!documentDataModel.getSnapshot().disabled;
360
353
  if (_univerjs_core.JSONX.isNoop(actions) || actions && actions.length === 0 || disabled) return {
361
354
  unitId,
@@ -390,7 +383,7 @@ const RichTextEditingMutation = {
390
383
  },
391
384
  undoState: {
392
385
  actions: undoActions,
393
- textRanges: prevTextRanges !== null && prevTextRanges !== void 0 ? prevTextRanges : docRanges
386
+ textRanges: prevTextRanges ?? docRanges
394
387
  },
395
388
  isCompositionEnd,
396
389
  isSync,
@@ -414,7 +407,7 @@ const InsertTextCommand = {
414
407
  id: "doc.command.insert-text",
415
408
  type: _univerjs_core.CommandType.COMMAND,
416
409
  handler: (accessor, params) => {
417
- var _ref, _ref2, _docDataModel$getSelf;
410
+ var _docDataModel$getSelf;
418
411
  const commandService = accessor.get(_univerjs_core.ICommandService);
419
412
  const { range, segmentId, body, unitId, cursorOffset } = params;
420
413
  const docSelectionManagerService = accessor.get(DocSelectionManagerService);
@@ -422,11 +415,11 @@ const InsertTextCommand = {
422
415
  if (docDataModel == null) return false;
423
416
  const activeRange = docSelectionManagerService.getActiveTextRange();
424
417
  const rangeSegmentId = "segmentId" in range ? range.segmentId : void 0;
425
- 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) ?? "";
426
419
  const originBody = (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(targetSegmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
427
420
  if (originBody == null) return false;
428
421
  const { startOffset, collapsed } = range;
429
- const cursorMove = cursorOffset !== null && cursorOffset !== void 0 ? cursorOffset : body.dataStream.length;
422
+ const cursorMove = cursorOffset ?? body.dataStream.length;
430
423
  const textRanges = [{
431
424
  startOffset: startOffset + cursorMove,
432
425
  endOffset: startOffset + cursorMove,
@@ -595,7 +588,7 @@ function getEmptyHeaderFooterBody() {
595
588
  function createHeaderFooterAction(segmentId, createType, headerFooterConfig, actions, createMode = "single", configPath = ["documentStyle"]) {
596
589
  const jsonX = _univerjs_core.JSONX.getInstance();
597
590
  const ID_LEN = 6;
598
- const firstSegmentId = segmentId !== null && segmentId !== void 0 ? segmentId : (0, _univerjs_core.generateRandomId)(ID_LEN);
591
+ const firstSegmentId = segmentId ?? (0, _univerjs_core.generateRandomId)(ID_LEN);
599
592
  const isHeader = createType === 2 || createType === 0 || createType === 4;
600
593
  const insertAction = jsonX.insertOp([isHeader ? "headers" : "footers", firstSegmentId], {
601
594
  [isHeader ? "headerId" : "footerId"]: firstSegmentId,
@@ -654,7 +647,7 @@ const CreateHeaderFooterCommand = {
654
647
  id: "doc.command.create-header-footer",
655
648
  type: _univerjs_core.CommandType.COMMAND,
656
649
  handler: (accessor, params) => {
657
- var _body$sectionBreaks$f, _body$sectionBreaks, _body$sectionBreaks2;
650
+ var _body$sectionBreaks, _body$sectionBreaks2;
658
651
  const commandService = accessor.get(_univerjs_core.ICommandService);
659
652
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
660
653
  const { unitId, segmentId, createType, headerFooterProps, createMode = "single", sectionId } = params;
@@ -664,10 +657,10 @@ const CreateHeaderFooterCommand = {
664
657
  if (documentStyle.documentFlavor === _univerjs_core.DocumentFlavor.MODERN) return false;
665
658
  const rawActions = [];
666
659
  const jsonX = _univerjs_core.JSONX.getInstance();
667
- 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;
668
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];
669
662
  if (sectionId != null && !sectionBreak) return false;
670
- const headerFooterConfig = sectionBreak !== null && sectionBreak !== void 0 ? sectionBreak : documentStyle;
663
+ const headerFooterConfig = sectionBreak ?? documentStyle;
671
664
  const configPath = sectionId == null ? ["documentStyle"] : [
672
665
  "body",
673
666
  "sectionBreaks",
@@ -749,8 +742,7 @@ const SetDocumentDefaultParagraphStyleCommand = {
749
742
  //#region src/utils/sections.ts
750
743
  /** Returns document-level section breaks, excluding table-cell and modern-column sentinels. */
751
744
  function getTopLevelSectionBreaks(body) {
752
- var _body$sectionBreaks;
753
- 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]));
754
746
  const result = [];
755
747
  let tableCellDepth = 0;
756
748
  let columnDepth = 0;
@@ -774,7 +766,7 @@ const SetSectionHeaderFooterLinkCommand = {
774
766
  id: "doc.command.set-section-header-footer-link",
775
767
  type: _univerjs_core.CommandType.COMMAND,
776
768
  handler: (accessor, params) => {
777
- var _snapshot$body$sectio, _snapshot$body$sectio2;
769
+ var _snapshot$body$sectio;
778
770
  if (!params) return false;
779
771
  const instanceService = accessor.get(_univerjs_core.IUniverInstanceService);
780
772
  const commandService = accessor.get(_univerjs_core.ICommandService);
@@ -784,7 +776,7 @@ const SetSectionHeaderFooterLinkCommand = {
784
776
  const sections = getTopLevelSectionBreaks(snapshot.body);
785
777
  const sectionIndex = sections.findIndex((section) => section.sectionId === params.sectionId);
786
778
  if (sectionIndex <= 0) return false;
787
- 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;
788
780
  if (storageIndex < 0) return false;
789
781
  const context = {
790
782
  snapshot,
@@ -842,7 +834,7 @@ function buildUnlinkActions(context, kind, requestedSegmentId) {
842
834
  const explicitSegmentId = sections[sectionIndex][key];
843
835
  if (typeof explicitSegmentId === "string" && explicitSegmentId) return null;
844
836
  const sourceSegmentId = (0, _univerjs_core.resolveSectionHeaderFooterReference)(snapshot.documentStyle, sections, sectionIndex - 1, key).segmentId;
845
- const segmentId = requestedSegmentId !== null && requestedSegmentId !== void 0 ? requestedSegmentId : (0, _univerjs_core.generateRandomId)(6);
837
+ const segmentId = requestedSegmentId ?? (0, _univerjs_core.generateRandomId)(6);
846
838
  const resources = kind === "header" ? snapshot.headers : snapshot.footers;
847
839
  if (resources === null || resources === void 0 ? void 0 : resources[segmentId]) return null;
848
840
  const source = sourceSegmentId ? resources === null || resources === void 0 ? void 0 : resources[sourceSegmentId] : void 0;
@@ -863,6 +855,174 @@ function buildUnlinkActions(context, kind, requestedSegmentId) {
863
855
  ], segmentId)];
864
856
  }
865
857
 
858
+ //#endregion
859
+ //#region src/commands/commands/update-document-paragraph-style.command.ts
860
+ function isValidParams(params) {
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);
862
+ }
863
+ function getCurrentParagraph(body, params) {
864
+ const matches = (body.paragraphs ?? []).filter((paragraph) => paragraph.paragraphId === params.paragraphId);
865
+ if (matches.length !== 1) return null;
866
+ const paragraph = matches[0];
867
+ return (0, _univerjs_core.getParagraphContentStartOffset)(body, paragraph) === params.startOffset && paragraph.startIndex === params.endOffset && body.dataStream[params.endOffset] === "\r" ? paragraph : null;
868
+ }
869
+ function createParagraphStyleTextX(body, paragraph, params) {
870
+ const textX = new _univerjs_core.TextX();
871
+ const initializesTextRuns = Boolean(params.style.textStyle && params.startOffset < params.endOffset && body.textRuns == null);
872
+ if (params.startOffset > 0) textX.push({
873
+ t: _univerjs_core.TextXActionType.RETAIN,
874
+ len: params.startOffset
875
+ });
876
+ if (params.style.textStyle && params.startOffset < params.endOffset && !initializesTextRuns) textX.push({
877
+ t: _univerjs_core.TextXActionType.RETAIN,
878
+ len: params.endOffset - params.startOffset,
879
+ coverType: _univerjs_core.UpdateDocsAttributeType.COVER,
880
+ body: {
881
+ dataStream: "",
882
+ textRuns: [{
883
+ st: 0,
884
+ ed: params.endOffset - params.startOffset,
885
+ ts: _univerjs_core.Tools.deepClone(params.style.textStyle)
886
+ }]
887
+ }
888
+ });
889
+ else if (params.startOffset < params.endOffset) textX.push({
890
+ t: _univerjs_core.TextXActionType.RETAIN,
891
+ len: params.endOffset - params.startOffset
892
+ });
893
+ const paragraphBody = {
894
+ dataStream: "",
895
+ paragraphs: [{
896
+ ..._univerjs_core.Tools.deepClone(paragraph),
897
+ startIndex: 0,
898
+ paragraphStyle: {
899
+ ..._univerjs_core.Tools.deepClone(paragraph.paragraphStyle ?? {}),
900
+ ..._univerjs_core.Tools.deepClone(params.style)
901
+ }
902
+ }]
903
+ };
904
+ Object.defineProperty(paragraphBody, _univerjs_core.RESTORE_INSERTED_PARAGRAPH_IDS, {
905
+ value: true,
906
+ enumerable: true
907
+ });
908
+ textX.push({
909
+ t: _univerjs_core.TextXActionType.RETAIN,
910
+ len: 1,
911
+ coverType: _univerjs_core.UpdateDocsAttributeType.REPLACE,
912
+ body: paragraphBody
913
+ });
914
+ return {
915
+ textX,
916
+ initializesTextRuns
917
+ };
918
+ }
919
+ const UpdateDocumentParagraphStyleCommand = {
920
+ id: "doc.command.update-paragraph-style",
921
+ type: _univerjs_core.CommandType.COMMAND,
922
+ handler: (accessor, params) => {
923
+ var _documentDataModel$ge;
924
+ if (!isValidParams(params)) return false;
925
+ const instanceService = accessor.get(_univerjs_core.IUniverInstanceService);
926
+ const commandService = accessor.get(_univerjs_core.ICommandService);
927
+ const documentDataModel = instanceService.getUnit(params.unitId, _univerjs_core.UniverInstanceType.UNIVER_DOC);
928
+ const segmentId = params.segmentId ?? "";
929
+ const body = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.getBody();
930
+ if (!documentDataModel || !body) return false;
931
+ const paragraph = getCurrentParagraph(body, params);
932
+ if (!paragraph) return false;
933
+ const { textX, initializesTextRuns } = createParagraphStyleTextX(body, paragraph, params);
934
+ const jsonX = _univerjs_core.JSONX.getInstance();
935
+ const path = (0, _univerjs_core.getRichTextEditPath)(documentDataModel, segmentId);
936
+ let actions = jsonX.editOp(textX.serialize(), path);
937
+ if (initializesTextRuns) {
938
+ const initializeTextRunsActions = jsonX.replaceOp([...path, "textRuns"], void 0, [{
939
+ st: params.startOffset,
940
+ ed: params.endOffset,
941
+ ts: _univerjs_core.Tools.deepClone(params.style.textStyle)
942
+ }]);
943
+ actions = _univerjs_core.JSONX.compose(initializeTextRunsActions, actions);
944
+ }
945
+ return Boolean(commandService.syncExecuteCommand(RichTextEditingMutation.id, {
946
+ unitId: params.unitId,
947
+ segmentId,
948
+ actions,
949
+ textRanges: null,
950
+ noNeedSetTextRange: true,
951
+ isEditing: false,
952
+ trigger: UpdateDocumentParagraphStyleCommand.id
953
+ }));
954
+ }
955
+ };
956
+
957
+ //#endregion
958
+ //#region src/utils/section-columns.ts
959
+ function resolveSectionValue(sectionValue, documentValue, fallback) {
960
+ return sectionValue ?? documentValue ?? fallback;
961
+ }
962
+ function getEffectivePageSize(documentStyle, section) {
963
+ var _section$pageSize, _documentStyle$pageSi, _section$pageSize2, _documentStyle$pageSi2;
964
+ const fallback = _univerjs_core.PAGE_SIZE[_univerjs_core.PaperType.A4];
965
+ return {
966
+ width: resolveSectionValue(section === null || section === void 0 || (_section$pageSize = section.pageSize) === null || _section$pageSize === void 0 ? void 0 : _section$pageSize.width, documentStyle === null || documentStyle === void 0 || (_documentStyle$pageSi = documentStyle.pageSize) === null || _documentStyle$pageSi === void 0 ? void 0 : _documentStyle$pageSi.width, fallback.width),
967
+ height: resolveSectionValue(section === null || section === void 0 || (_section$pageSize2 = section.pageSize) === null || _section$pageSize2 === void 0 ? void 0 : _section$pageSize2.height, documentStyle === null || documentStyle === void 0 || (_documentStyle$pageSi2 = documentStyle.pageSize) === null || _documentStyle$pageSi2 === void 0 ? void 0 : _documentStyle$pageSi2.height, fallback.height)
968
+ };
969
+ }
970
+ function getEffectiveMargins(documentStyle, section) {
971
+ return {
972
+ top: resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginTop, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginTop, _univerjs_core.TRADITIONAL_DOCUMENT_DEFAULT_MARGIN),
973
+ bottom: resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginBottom, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginBottom, _univerjs_core.TRADITIONAL_DOCUMENT_DEFAULT_MARGIN),
974
+ left: resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginLeft, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginLeft, _univerjs_core.TRADITIONAL_DOCUMENT_DEFAULT_MARGIN),
975
+ right: resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginRight, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginRight, _univerjs_core.TRADITIONAL_DOCUMENT_DEFAULT_MARGIN)
976
+ };
977
+ }
978
+ function assertPositivePageSetup(pageSize, contentSize) {
979
+ if (![
980
+ pageSize.width,
981
+ pageSize.height,
982
+ contentSize.width,
983
+ contentSize.height
984
+ ].every((value) => Number.isFinite(value) && value > 0)) throw new RangeError("Effective section page setup must leave a positive content area and use finite positive page dimensions.");
985
+ }
986
+ /** Resolves nominal traditional page geometry without requiring a renderer. */
987
+ function getEffectiveSectionPageSetup(documentStyle, section) {
988
+ const pageSize = getEffectivePageSize(documentStyle, section);
989
+ const margins = getEffectiveMargins(documentStyle, section);
990
+ const contentSize = {
991
+ width: getSectionContentWidth(documentStyle, section),
992
+ height: pageSize.height - margins.top - margins.bottom
993
+ };
994
+ assertPositivePageSetup(pageSize, contentSize);
995
+ const pageNumberStart = (section === null || section === void 0 ? void 0 : section.pageNumberStart) ?? (documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.pageNumberStart);
996
+ return {
997
+ pageSize,
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),
999
+ margins,
1000
+ contentSize,
1001
+ ...pageNumberStart == null ? {} : { pageNumberStart }
1002
+ };
1003
+ }
1004
+ /** Returns the usable horizontal layout width for a traditional section. */
1005
+ function getSectionContentWidth(documentStyle, section) {
1006
+ var _section$pageSize3, _documentStyle$pageSi3;
1007
+ const pageWidth = resolveSectionValue(section === null || section === void 0 || (_section$pageSize3 = section.pageSize) === null || _section$pageSize3 === void 0 ? void 0 : _section$pageSize3.width, documentStyle === null || documentStyle === void 0 || (_documentStyle$pageSi3 = documentStyle.pageSize) === null || _documentStyle$pageSi3 === void 0 ? void 0 : _documentStyle$pageSi3.width, _univerjs_core.PAGE_SIZE[_univerjs_core.PaperType.A4].width);
1008
+ return Math.max(0, pageWidth - resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginLeft, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginLeft, _univerjs_core.TRADITIONAL_DOCUMENT_DEFAULT_MARGIN) - resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginRight, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginRight, _univerjs_core.TRADITIONAL_DOCUMENT_DEFAULT_MARGIN));
1009
+ }
1010
+ /** Creates explicit OOXML section columns from a count, gap, and optional widths. */
1011
+ function createSectionColumnProperties(documentStyle, section, columnCount, gap, widths) {
1012
+ if (columnCount <= 1) return [];
1013
+ const safeGap = Math.max(0, gap);
1014
+ const contentWidth = getSectionContentWidth(documentStyle, section);
1015
+ const availableWidth = Math.max(0, contentWidth - safeGap * (columnCount - 1));
1016
+ if (widths) {
1017
+ if (widths.some((width) => !Number.isFinite(width) || width < 0)) throw new RangeError("Section column widths must be finite and non-negative.");
1018
+ if (widths.reduce((sum, width) => sum + width, 0) > availableWidth) throw new RangeError("Section columns exceed the available page content width.");
1019
+ }
1020
+ return (widths ?? Array.from({ length: columnCount }, () => availableWidth / columnCount)).map((width, index) => ({
1021
+ width: Math.max(0, width),
1022
+ paddingEnd: index === columnCount - 1 ? 0 : safeGap
1023
+ }));
1024
+ }
1025
+
866
1026
  //#endregion
867
1027
  //#region src/commands/commands/update-document-section.command.ts
868
1028
  const UpdateDocumentSectionCommand = {
@@ -881,6 +1041,11 @@ const UpdateDocumentSectionCommand = {
881
1041
  const selectedIds = new Set(updates.keys());
882
1042
  const sections = getTopLevelSectionBreaks(body).filter((section) => selectedIds.has(section.sectionId)).sort((left, right) => left.startIndex - right.startIndex);
883
1043
  if (sections.length !== selectedIds.size) return false;
1044
+ const documentStyle = documentDataModel.getDocumentStyle();
1045
+ if (sections.some((section) => !isValidSectionConfig({
1046
+ ...section,
1047
+ ...updates.get(section.sectionId)
1048
+ }, documentStyle))) return false;
884
1049
  const cursor = new _univerjs_core.MemoryCursor();
885
1050
  const textX = new _univerjs_core.TextX();
886
1051
  for (const section of sections) {
@@ -924,25 +1089,70 @@ const InsertDocumentSectionBreakCommand = {
924
1089
  id: "doc.command.insert-section-break",
925
1090
  type: _univerjs_core.CommandType.COMMAND,
926
1091
  handler: (accessor, params) => {
927
- var _body$sectionBreaks, _body$tables, _body$columnGroups, _body$blockRanges, _params$config;
1092
+ var _body$sectionBreaks;
928
1093
  if (!params) return false;
929
1094
  const context = getTraditionalDocumentContext(accessor, params.unitId);
930
- if (!context || !params.sectionId || !Number.isInteger(params.offset)) return false;
1095
+ if (!context || !params.sectionId || !Number.isInteger(params.offset) || params.nextSectionType != null && !isValidEnumValue(_univerjs_core.SectionType, params.nextSectionType)) return false;
931
1096
  const { body, documentDataModel, commandService } = context;
932
- if (params.offset < 0 || params.offset > body.dataStream.length || ((_body$sectionBreaks = body.sectionBreaks) === null || _body$sectionBreaks === void 0 ? void 0 : _body$sectionBreaks.some((section) => section.sectionId === params.sectionId)) || ((_body$tables = body.tables) === null || _body$tables === void 0 ? void 0 : _body$tables.some((range) => (0, _univerjs_core.containsInteriorInsertionOffset)((0, _univerjs_core.getTableRangeInterval)(range), params.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), params.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), params.offset)))) return false;
1097
+ const insertedSection = {
1098
+ ..._univerjs_core.Tools.deepClone(params.config ?? {}),
1099
+ sectionId: params.sectionId,
1100
+ startIndex: params.offset
1101
+ };
1102
+ if (!isValidTopLevelInsertionOffset(body, params.offset) || ((_body$sectionBreaks = body.sectionBreaks) === null || _body$sectionBreaks === void 0 ? void 0 : _body$sectionBreaks.some((section) => section.sectionId === params.sectionId)) || !isValidSectionConfig(insertedSection, documentDataModel.getDocumentStyle())) return false;
1103
+ const nextSection = params.nextSectionType == null ? void 0 : getTopLevelSectionBreaks(body).find((section) => section.startIndex >= params.offset);
1104
+ if (params.nextSectionType != null && !nextSection) return false;
933
1105
  const textX = new _univerjs_core.TextX();
934
1106
  textX.retain(params.offset);
935
1107
  textX.insert(1, {
936
1108
  dataStream: _univerjs_core.DataStreamTreeTokenType.SECTION_BREAK,
937
1109
  sectionBreaks: [{
938
- ..._univerjs_core.Tools.deepClone((_params$config = params.config) !== null && _params$config !== void 0 ? _params$config : {}),
939
- sectionId: params.sectionId,
1110
+ ...insertedSection,
940
1111
  startIndex: 0
941
1112
  }]
942
1113
  });
1114
+ if (nextSection && params.nextSectionType != null) {
1115
+ textX.retain(nextSection.startIndex - params.offset);
1116
+ textX.push({
1117
+ t: _univerjs_core.TextXActionType.RETAIN,
1118
+ len: 1,
1119
+ coverType: _univerjs_core.UpdateDocsAttributeType.REPLACE,
1120
+ body: {
1121
+ dataStream: "",
1122
+ sectionBreaks: [{
1123
+ ..._univerjs_core.Tools.deepClone(nextSection),
1124
+ sectionType: params.nextSectionType,
1125
+ startIndex: 0
1126
+ }]
1127
+ }
1128
+ });
1129
+ }
943
1130
  return executeSectionTextX(commandService, documentDataModel, textX, InsertDocumentSectionBreakCommand.id);
944
1131
  }
945
1132
  };
1133
+ const InsertDocumentColumnBreakCommand = {
1134
+ id: "doc.command.insert-column-break",
1135
+ type: _univerjs_core.CommandType.COMMAND,
1136
+ handler: (accessor, params) => {
1137
+ if (!params) return false;
1138
+ const context = getTraditionalDocumentContext(accessor, params.unitId);
1139
+ if (!context || !isValidTopLevelInsertionOffset(context.body, params.offset)) return false;
1140
+ const textX = new _univerjs_core.TextX();
1141
+ textX.retain(params.offset);
1142
+ textX.insert(1, {
1143
+ dataStream: _univerjs_core.DataStreamTreeTokenType.COLUMN_BREAK,
1144
+ customRanges: [{
1145
+ startIndex: 0,
1146
+ endIndex: 0,
1147
+ rangeId: `docx-break-${(0, _univerjs_core.generateRandomId)()}`,
1148
+ rangeType: _univerjs_core.CustomRangeType.CUSTOM,
1149
+ wholeEntity: true,
1150
+ properties: { docxBreakType: _univerjs_core.DocxBreakType.COLUMN }
1151
+ }]
1152
+ });
1153
+ return executeSectionTextX(context.commandService, context.documentDataModel, textX, InsertDocumentColumnBreakCommand.id);
1154
+ }
1155
+ };
946
1156
  const DeleteDocumentSectionBreakCommand = {
947
1157
  id: "doc.command.delete-section-break",
948
1158
  type: _univerjs_core.CommandType.COMMAND,
@@ -953,7 +1163,7 @@ const DeleteDocumentSectionBreakCommand = {
953
1163
  const sections = getTopLevelSectionBreaks(context.body);
954
1164
  if (sections.length <= 1) return false;
955
1165
  const section = sections.find((item) => item.sectionId === params.sectionId);
956
- if (!section) return false;
1166
+ if (!section || section === sections[sections.length - 1]) return false;
957
1167
  const textX = new _univerjs_core.TextX();
958
1168
  textX.retain(section.startIndex);
959
1169
  textX.delete(1);
@@ -971,6 +1181,38 @@ function getTraditionalDocumentContext(accessor, unitId) {
971
1181
  commandService: accessor.get(_univerjs_core.ICommandService)
972
1182
  };
973
1183
  }
1184
+ function isValidTopLevelInsertionOffset(body, offset) {
1185
+ var _body$tables, _body$columnGroups, _body$blockRanges;
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)));
1187
+ }
1188
+ function isValidSectionConfig(section, documentStyle) {
1189
+ if (section.sectionType != null && !isValidEnumValue(_univerjs_core.SectionType, section.sectionType)) return false;
1190
+ if (section.pageOrient != null && !isValidEnumValue(_univerjs_core.PageOrientType, section.pageOrient)) return false;
1191
+ if (section.columnSeparatorType != null && !isValidEnumValue(_univerjs_core.ColumnSeparatorType, section.columnSeparatorType)) return false;
1192
+ if (section.pageNumberStart != null && (!Number.isInteger(section.pageNumberStart) || section.pageNumberStart < 1)) return false;
1193
+ if (section.pageSize && (!isPositiveFinite(section.pageSize.width) || !isPositiveFinite(section.pageSize.height))) return false;
1194
+ if ([
1195
+ section.marginTop,
1196
+ section.marginBottom,
1197
+ section.marginLeft,
1198
+ section.marginRight
1199
+ ].some((margin) => margin != null && (!Number.isFinite(margin) || margin < 0))) return false;
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;
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;
1206
+ const columns = section.columnProperties ?? [];
1207
+ if (columns.some(({ width, paddingEnd }) => !Number.isFinite(width) || !Number.isFinite(paddingEnd) || width < 0 || paddingEnd < 0)) return false;
1208
+ return columns.reduce((sum, { width, paddingEnd }) => sum + width + paddingEnd, 0) <= getSectionContentWidth(documentStyle, section);
1209
+ }
1210
+ function isPositiveFinite(value) {
1211
+ return value != null && Number.isFinite(value) && value > 0;
1212
+ }
1213
+ function isValidEnumValue(enumObject, value) {
1214
+ return Object.values(enumObject).includes(value);
1215
+ }
974
1216
  function executeSectionTextX(commandService, documentDataModel, textX, trigger) {
975
1217
  const actions = _univerjs_core.JSONX.getInstance().editOp(textX.serialize(), (0, _univerjs_core.getRichTextEditPath)(documentDataModel));
976
1218
  return Boolean(commandService.syncExecuteCommand(RichTextEditingMutation.id, {
@@ -1037,7 +1279,6 @@ function createRemoveCustomBlockActions(params) {
1037
1279
  return composeActions([toBodyEditActions(textX, params.segmentId), createDrawingRemoveActions(params)]);
1038
1280
  }
1039
1281
  function createDocsCustomBlockDrawing(params) {
1040
- var _params$componentKey;
1041
1282
  const size = resolveDocsCustomBlockSize(params.childType);
1042
1283
  const isInline = params.interactionMode === "inline";
1043
1284
  return {
@@ -1045,7 +1286,7 @@ function createDocsCustomBlockDrawing(params) {
1045
1286
  subUnitId: params.unitId,
1046
1287
  drawingId: params.blockId,
1047
1288
  drawingType: _univerjs_core.DrawingTypeEnum.DRAWING_DOM,
1048
- componentKey: (_params$componentKey = params.componentKey) !== null && _params$componentKey !== void 0 ? _params$componentKey : EMBED_DOCS_CUSTOM_BLOCK_DEFAULT_COMPONENT_KEY,
1289
+ componentKey: params.componentKey ?? "UniverEmbedDocsCustomBlock",
1049
1290
  data: createEmbedDocsCustomBlockData(params),
1050
1291
  title: params.blockId,
1051
1292
  description: "Univer embedded unit custom block",
@@ -1083,15 +1324,14 @@ function isSheetLikeDocsCustomBlockChildType(childType) {
1083
1324
  return childType === _univerjs_core.UniverInstanceType.UNIVER_SHEET || childType === _univerjs_core.UniverInstanceType.UNIVER_BASE;
1084
1325
  }
1085
1326
  function createEmbedDocsCustomBlockData(params) {
1086
- var _params$embedId, _params$interactionMo;
1087
1327
  return {
1088
1328
  version: 1,
1089
- embedId: (_params$embedId = params.embedId) !== null && _params$embedId !== void 0 ? _params$embedId : params.blockId,
1329
+ embedId: params.embedId ?? params.blockId,
1090
1330
  hostUnitId: params.unitId,
1091
1331
  hostAnchorId: params.blockId,
1092
1332
  childUnitId: params.childUnitId,
1093
1333
  childType: params.childType,
1094
- interactionMode: (_params$interactionMo = params.interactionMode) !== null && _params$interactionMo !== void 0 ? _params$interactionMo : "block"
1334
+ interactionMode: params.interactionMode ?? "block"
1095
1335
  };
1096
1336
  }
1097
1337
  function isEmbedDocsCustomBlockData(data) {
@@ -1118,40 +1358,36 @@ function createRichTextMutation(unitId, segmentId, actions) {
1118
1358
  };
1119
1359
  }
1120
1360
  function toBodyEditActions(textX, segmentId) {
1121
- const action = _univerjs_core.JSONX.getInstance().editOp(textX.serialize(), segmentId ? [
1361
+ return _univerjs_core.JSONX.getInstance().editOp(textX.serialize(), segmentId ? [
1122
1362
  "headers",
1123
1363
  segmentId,
1124
1364
  "body"
1125
- ] : ["body"]);
1126
- return action !== null && action !== void 0 ? action : [];
1365
+ ] : ["body"]) ?? [];
1127
1366
  }
1128
1367
  function createDrawingInsertActions(params) {
1129
- var _jsonX$insertOp, _jsonX$insertOp2, _params$drawingOrderI;
1130
1368
  if (params.segmentId) return [];
1131
1369
  const jsonX = _univerjs_core.JSONX.getInstance();
1132
1370
  const drawing = createDocsCustomBlockDrawing(params);
1133
- 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) ?? []]);
1134
1372
  }
1135
1373
  function createDrawingRemoveActions(params) {
1136
- var _jsonX$removeOp, _jsonX$removeOp2, _params$drawingOrderI2;
1137
1374
  if (params.segmentId) return [];
1138
1375
  const jsonX = _univerjs_core.JSONX.getInstance();
1139
1376
  const drawing = createDocsCustomBlockDrawing(params);
1140
- 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) ?? []]);
1141
1378
  }
1142
1379
  function composeActions(actions) {
1143
1380
  return actions.reduce((composed, action) => {
1144
- var _JSONX$compose;
1145
1381
  if (!action || _univerjs_core.JSONX.isNoop(action) || action.length === 0) return composed;
1146
1382
  if (!composed || _univerjs_core.JSONX.isNoop(composed) || composed.length === 0) return action;
1147
- return (_JSONX$compose = _univerjs_core.JSONX.compose(composed, action)) !== null && _JSONX$compose !== void 0 ? _JSONX$compose : [];
1383
+ return _univerjs_core.JSONX.compose(composed, action) ?? [];
1148
1384
  }, []);
1149
1385
  }
1150
1386
 
1151
1387
  //#endregion
1152
1388
  //#region package.json
1153
1389
  var name = "@univerjs/docs";
1154
- var version = "1.0.0-alpha.7";
1390
+ var version = "1.0.0-beta.0";
1155
1391
 
1156
1392
  //#endregion
1157
1393
  //#region src/commands/mutations/docs-rename.mutation.ts
@@ -1229,7 +1465,7 @@ let DocCustomRangeController = class DocCustomRangeController extends _univerjs_
1229
1465
  const doc = this._univerInstanceService.getUnit(unitId);
1230
1466
  if (!doc) return;
1231
1467
  const transformedRanges = ranges.map((range) => this._transformCustomRange(doc, range));
1232
- if (transformedRanges.some((range, i) => ranges[i] !== range)) this._textSelectionManagerService.replaceTextRanges(transformedRanges, isEditing);
1468
+ if (transformedRanges.some((range, i) => ranges[i] !== range)) this._textSelectionManagerService.replaceDocRanges(transformedRanges, void 0, isEditing);
1233
1469
  }
1234
1470
  }));
1235
1471
  }
@@ -1326,10 +1562,9 @@ let DocStateChangeManagerService = class DocStateChangeManagerService extends _u
1326
1562
  this._listenDocStateChange();
1327
1563
  }
1328
1564
  getStateCache(unitId) {
1329
- var _this$_historyStateCa, _this$_changeStateCac;
1330
1565
  return {
1331
- history: (_this$_historyStateCa = this._historyStateCache.get(unitId)) !== null && _this$_historyStateCa !== void 0 ? _this$_historyStateCa : [],
1332
- 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) ?? []
1333
1568
  };
1334
1569
  }
1335
1570
  setStateCache(unitId, cache) {
@@ -1353,9 +1588,9 @@ let DocStateChangeManagerService = class DocStateChangeManagerService extends _u
1353
1588
  }
1354
1589
  _listenDocStateChange() {
1355
1590
  this._docStateEmitService.docStateChangeParams$.pipe((0, rxjs.takeUntil)(this.dispose$)).subscribe((changeStateInfo) => {
1356
- var _this$_docStateChange, _this$_docStateChange2;
1591
+ var _this$_docStateChange;
1357
1592
  if (changeStateInfo == null) return;
1358
- 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;
1359
1594
  if (interceptedChangeStateInfo == null) return;
1360
1595
  if (interceptedChangeStateInfo.isSync) return;
1361
1596
  const { isCompositionEnd: _isCompositionEnd, isSync: _isSync, syncer: _syncer, ...changeState } = interceptedChangeStateInfo;
@@ -1453,6 +1688,79 @@ DocStateChangeManagerService = __decorate([
1453
1688
  __decorateParam(4, (0, _univerjs_core.Optional)(IDocStateChangeInterceptorService))
1454
1689
  ], DocStateChangeManagerService);
1455
1690
 
1691
+ //#endregion
1692
+ //#region src/services/doc-text-resolver.service.ts
1693
+ /**
1694
+ * Builds a consumer-facing text projection while retaining a mapping back to
1695
+ * the native document offsets.
1696
+ *
1697
+ * Consumers such as find/replace can search the projected text and then use
1698
+ * `characters` to focus the native object that supplied a matching character.
1699
+ * Resolvers must return half-open, non-overlapping replacements.
1700
+ */
1701
+ var DocTextResolverService = class extends _univerjs_core.Disposable {
1702
+ constructor(..._args) {
1703
+ super(..._args);
1704
+ _defineProperty(this, "_resolvers", /* @__PURE__ */ new Set());
1705
+ _defineProperty(this, "_textChanged$", new rxjs.Subject());
1706
+ _defineProperty(this, "textChanged$", this._textChanged$.asObservable());
1707
+ }
1708
+ register(resolver) {
1709
+ this._resolvers.add(resolver);
1710
+ return (0, _univerjs_core.toDisposable)(() => this._resolvers.delete(resolver));
1711
+ }
1712
+ notifyTextChanged(unitId) {
1713
+ this._textChanged$.next(unitId);
1714
+ }
1715
+ resolve(unitId, body) {
1716
+ const replacements = this._collectReplacements(unitId, body);
1717
+ const characters = [];
1718
+ let text = "";
1719
+ let sourceOffset = 0;
1720
+ for (const replacement of replacements) {
1721
+ const sourceText = body.dataStream.slice(sourceOffset, replacement.startOffset);
1722
+ text += sourceText;
1723
+ for (let index = sourceOffset; index < replacement.startOffset; index += 1) characters.push({
1724
+ startOffset: index,
1725
+ endOffset: index + 1,
1726
+ replaceable: true
1727
+ });
1728
+ text += replacement.text;
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
+ });
1734
+ sourceOffset = replacement.endOffset;
1735
+ }
1736
+ text += body.dataStream.slice(sourceOffset);
1737
+ for (let index = sourceOffset; index < body.dataStream.length; index += 1) characters.push({
1738
+ startOffset: index,
1739
+ endOffset: index + 1,
1740
+ replaceable: true
1741
+ });
1742
+ return {
1743
+ characters,
1744
+ text
1745
+ };
1746
+ }
1747
+ _collectReplacements(unitId, body) {
1748
+ const candidates = [...this._resolvers].flatMap((resolver) => resolver.resolve(unitId, body)).filter((replacement) => Number.isInteger(replacement.startOffset) && Number.isInteger(replacement.endOffset) && replacement.startOffset >= 0 && replacement.endOffset > replacement.startOffset && replacement.endOffset <= body.dataStream.length).sort((left, right) => left.startOffset - right.startOffset || right.endOffset - left.endOffset);
1749
+ const replacements = [];
1750
+ let previousEnd = -1;
1751
+ for (const candidate of candidates) {
1752
+ if (candidate.startOffset < previousEnd) continue;
1753
+ replacements.push(candidate);
1754
+ previousEnd = candidate.endOffset;
1755
+ }
1756
+ return replacements;
1757
+ }
1758
+ dispose() {
1759
+ this._textChanged$.complete();
1760
+ super.dispose();
1761
+ }
1762
+ };
1763
+
1456
1764
  //#endregion
1457
1765
  //#region src/plugin.ts
1458
1766
  let UniverDocsPlugin = class UniverDocsPlugin extends _univerjs_core.Plugin {
@@ -1476,8 +1784,10 @@ let UniverDocsPlugin = class UniverDocsPlugin extends _univerjs_core.Plugin {
1476
1784
  CreateHeaderFooterCommand,
1477
1785
  SetDocumentDefaultParagraphStyleCommand,
1478
1786
  SetSectionHeaderFooterLinkCommand,
1787
+ UpdateDocumentParagraphStyleCommand,
1479
1788
  UpdateDocumentSectionCommand,
1480
1789
  InsertDocumentSectionBreakCommand,
1790
+ InsertDocumentColumnBreakCommand,
1481
1791
  DeleteDocumentSectionBreakCommand,
1482
1792
  RichTextEditingMutation,
1483
1793
  DocsRenameMutation,
@@ -1493,6 +1803,7 @@ let UniverDocsPlugin = class UniverDocsPlugin extends _univerjs_core.Plugin {
1493
1803
  [DocStateChangeManagerService],
1494
1804
  [DocBlockMoveValidatorService],
1495
1805
  [DocContentInsertService],
1806
+ [DocTextResolverService],
1496
1807
  [DocCustomRangeController]
1497
1808
  ].forEach((d) => this._injector.add(d));
1498
1809
  }
@@ -1548,10 +1859,7 @@ let DocInterceptorService = class DocInterceptorService extends _univerjs_core.D
1548
1859
  if (!this._interceptorsByName.has(key)) this._interceptorsByName.set(key, []);
1549
1860
  const interceptors = this._interceptorsByName.get(key);
1550
1861
  interceptors.push(interceptor);
1551
- this._interceptorsByName.set(key, interceptors.sort((a, b) => {
1552
- var _b$priority, _a$priority;
1553
- 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);
1554
- }));
1862
+ this._interceptorsByName.set(key, interceptors.sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0)));
1555
1863
  return this.disposeWithMe((0, _univerjs_core.toDisposable)(() => (0, _univerjs_core.remove)(this._interceptorsByName.get(key), interceptor)));
1556
1864
  }
1557
1865
  fetchThroughInterceptors(name) {
@@ -1562,19 +1870,17 @@ let DocInterceptorService = class DocInterceptorService extends _univerjs_core.D
1562
1870
  const disposableCollection = new _univerjs_core.DisposableCollection();
1563
1871
  disposableCollection.add(viewModel.registerCustomRangeInterceptor({
1564
1872
  getCustomRange: (index) => {
1565
- var _viewModel$getDataMod;
1566
1873
  return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_RANGE)(viewModel.getCustomRangeRaw(index), {
1567
1874
  index,
1568
1875
  unitId: viewModel.getDataModel().getUnitId(),
1569
- customRanges: (_viewModel$getDataMod = viewModel.getDataModel().getCustomRanges()) !== null && _viewModel$getDataMod !== void 0 ? _viewModel$getDataMod : []
1876
+ customRanges: viewModel.getDataModel().getCustomRanges() ?? []
1570
1877
  });
1571
1878
  },
1572
1879
  getCustomDecoration: (index) => {
1573
- var _viewModel$getDataMod2;
1574
1880
  return this.fetchThroughInterceptors(DOC_INTERCEPTOR_POINT.CUSTOM_DECORATION)(viewModel.getCustomDecorationRaw(index), {
1575
1881
  index,
1576
1882
  unitId: viewModel.getDataModel().getUnitId(),
1577
- customDecorations: (_viewModel$getDataMod2 = viewModel.getDataModel().getCustomDecorations()) !== null && _viewModel$getDataMod2 !== void 0 ? _viewModel$getDataMod2 : []
1883
+ customDecorations: viewModel.getDataModel().getCustomDecorations() ?? []
1578
1884
  });
1579
1885
  }
1580
1886
  }));
@@ -1612,7 +1918,7 @@ function addCustomRangeBySelectionFactory(accessor, param) {
1612
1918
  const { rangeId, rangeType, wholeEntity, properties, unitId, selections: propSelection } = param;
1613
1919
  const docSelectionManagerService = accessor.get(DocSelectionManagerService);
1614
1920
  const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
1615
- const selections = propSelection !== null && propSelection !== void 0 ? propSelection : docSelectionManagerService.getTextRanges({
1921
+ const selections = propSelection ?? docSelectionManagerService.getTextRanges({
1616
1922
  unitId,
1617
1923
  subUnitId: unitId
1618
1924
  });
@@ -1695,8 +2001,7 @@ function generateParagraphs(dataStream, prevParagraph, borderBottom, existingPar
1695
2001
  if (prevParagraph.paragraphStyle.headingId) paragraph.paragraphStyle.headingId = (0, _univerjs_core.generateRandomId)(6);
1696
2002
  }
1697
2003
  if (borderBottom) {
1698
- var _paragraph$paragraphS;
1699
- (_paragraph$paragraphS = paragraph.paragraphStyle) !== null && _paragraph$paragraphS !== void 0 || (paragraph.paragraphStyle = {});
2004
+ paragraph.paragraphStyle ??= {};
1700
2005
  paragraph.paragraphStyle.borderBottom = _univerjs_core.Tools.deepClone(borderBottom);
1701
2006
  paragraph.paragraphStyle.spaceBelow = { v: 10 };
1702
2007
  }
@@ -1707,7 +2012,7 @@ function generateParagraphs(dataStream, prevParagraph, borderBottom, existingPar
1707
2012
  //#endregion
1708
2013
  //#region src/utils/replace-selection-factory.ts
1709
2014
  function replaceSelectionFactory(accessor, params) {
1710
- var _params$selection, _docDataModel$getSelf, _params$selection2, _params$textRanges;
2015
+ var _params$selection, _docDataModel$getSelf;
1711
2016
  const { unitId, body: insertBody, doc } = params;
1712
2017
  let docDataModel = doc;
1713
2018
  if (!docDataModel) docDataModel = accessor.get(_univerjs_core.IUniverInstanceService).getUnit(unitId);
@@ -1716,9 +2021,9 @@ function replaceSelectionFactory(accessor, params) {
1716
2021
  const body = (_docDataModel$getSelf = docDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _docDataModel$getSelf === void 0 ? void 0 : _docDataModel$getSelf.getBody();
1717
2022
  if (!body) return false;
1718
2023
  const docSelectionManagerService = accessor.get(DocSelectionManagerService);
1719
- const selection = (_params$selection2 = params.selection) !== null && _params$selection2 !== void 0 ? _params$selection2 : docSelectionManagerService.getActiveTextRange();
2024
+ const selection = params.selection ?? docSelectionManagerService.getActiveTextRange();
1720
2025
  if (!selection || !body) return false;
1721
- const textRanges = (_params$textRanges = params.textRanges) !== null && _params$textRanges !== void 0 ? _params$textRanges : [{
2026
+ const textRanges = params.textRanges ?? [{
1722
2027
  startOffset: selection.startOffset + insertBody.dataStream.length,
1723
2028
  endOffset: selection.startOffset + insertBody.dataStream.length,
1724
2029
  collapsed: true,
@@ -1746,26 +2051,9 @@ function replaceSelectionFactory(accessor, params) {
1746
2051
  return doMutation;
1747
2052
  }
1748
2053
 
1749
- //#endregion
1750
- //#region src/utils/section-columns.ts
1751
- /** Creates explicit OOXML section columns from a count, gap, and optional widths. */
1752
- function createSectionColumnProperties(documentStyle, section, columnCount, gap, widths) {
1753
- var _ref, _section$pageSize$wid, _section$pageSize, _documentStyle$pageSi, _ref2, _section$marginLeft, _ref3, _section$marginRight;
1754
- if (columnCount <= 1) return [];
1755
- const safeGap = Math.max(0, gap);
1756
- const pageWidth = (_ref = (_section$pageSize$wid = section === null || section === void 0 || (_section$pageSize = section.pageSize) === null || _section$pageSize === void 0 ? void 0 : _section$pageSize.width) !== null && _section$pageSize$wid !== void 0 ? _section$pageSize$wid : documentStyle === null || documentStyle === void 0 || (_documentStyle$pageSi = documentStyle.pageSize) === null || _documentStyle$pageSi === void 0 ? void 0 : _documentStyle$pageSi.width) !== null && _ref !== void 0 ? _ref : _univerjs_core.PAGE_SIZE[_univerjs_core.PaperType.A4].width;
1757
- const contentWidth = Math.max(0, pageWidth - ((_ref2 = (_section$marginLeft = section === null || section === void 0 ? void 0 : section.marginLeft) !== null && _section$marginLeft !== void 0 ? _section$marginLeft : documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginLeft) !== null && _ref2 !== void 0 ? _ref2 : 72) - ((_ref3 = (_section$marginRight = section === null || section === void 0 ? void 0 : section.marginRight) !== null && _section$marginRight !== void 0 ? _section$marginRight : documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginRight) !== null && _ref3 !== void 0 ? _ref3 : 72));
1758
- const availableWidth = Math.max(0, contentWidth - safeGap * (columnCount - 1));
1759
- return (widths !== null && widths !== void 0 ? widths : Array.from({ length: columnCount }, () => availableWidth / columnCount)).map((width, index) => ({
1760
- width: Math.max(0, width),
1761
- paddingEnd: index === columnCount - 1 ? 0 : safeGap
1762
- }));
1763
- }
1764
-
1765
2054
  //#endregion
1766
2055
  //#region src/utils/transform-position.ts
1767
2056
  function buildDocTransform(width, height, position) {
1768
- var _position$left, _position$top;
1769
2057
  return {
1770
2058
  size: {
1771
2059
  width,
@@ -1773,11 +2061,11 @@ function buildDocTransform(width, height, position) {
1773
2061
  },
1774
2062
  positionH: {
1775
2063
  relativeFrom: _univerjs_core.ObjectRelativeFromH.PAGE,
1776
- 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
1777
2065
  },
1778
2066
  positionV: {
1779
2067
  relativeFrom: _univerjs_core.ObjectRelativeFromV.PARAGRAPH,
1780
- 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
1781
2069
  },
1782
2070
  angle: 0
1783
2071
  };
@@ -1823,7 +2111,7 @@ function consumeContentInsertRange(accessor, unitId) {
1823
2111
  }
1824
2112
  function getContentInsertRange(accessor, unitId) {
1825
2113
  var _accessor$get$getCurr;
1826
- 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());
1827
2115
  if (!_unitId) return null;
1828
2116
  const insertRange = consumeContentInsertRange(accessor, _unitId);
1829
2117
  if (!insertRange) return null;
@@ -1836,19 +2124,19 @@ function isHeaderFooterSelection(range) {
1836
2124
  return Boolean(range === null || range === void 0 ? void 0 : range.segmentId);
1837
2125
  }
1838
2126
  function normalizeTextRange(textRange) {
1839
- var _textRange$endOffset, _textRange$collapsed, _textRange$segmentId;
1840
- const endOffset = (_textRange$endOffset = textRange.endOffset) !== null && _textRange$endOffset !== void 0 ? _textRange$endOffset : textRange.startOffset;
2127
+ const endOffset = textRange.endOffset ?? textRange.startOffset;
1841
2128
  return {
1842
2129
  ...textRange,
1843
2130
  endOffset,
1844
- collapsed: (_textRange$collapsed = textRange.collapsed) !== null && _textRange$collapsed !== void 0 ? _textRange$collapsed : textRange.startOffset === endOffset,
1845
- segmentId: (_textRange$segmentId = textRange.segmentId) !== null && _textRange$segmentId !== void 0 ? _textRange$segmentId : ""
2131
+ collapsed: textRange.collapsed ?? textRange.startOffset === endOffset,
2132
+ segmentId: textRange.segmentId ?? ""
1846
2133
  };
1847
2134
  }
1848
2135
 
1849
2136
  //#endregion
1850
2137
  exports.CreateHeaderFooterCommand = CreateHeaderFooterCommand;
1851
2138
  exports.DOC_INTERCEPTOR_POINT = DOC_INTERCEPTOR_POINT;
2139
+ exports.DOC_SELECTION_OPTION_PRESERVE_CARET = DOC_SELECTION_OPTION_PRESERVE_CARET;
1852
2140
  exports.DeleteDocumentSectionBreakCommand = DeleteDocumentSectionBreakCommand;
1853
2141
  exports.DeleteTextCommand = DeleteTextCommand;
1854
2142
  exports.DocBlockMoveValidatorService = DocBlockMoveValidatorService;
@@ -1878,9 +2166,11 @@ Object.defineProperty(exports, 'DocStateChangeManagerService', {
1878
2166
  }
1879
2167
  });
1880
2168
  exports.DocStateEmitService = DocStateEmitService;
2169
+ exports.DocTextResolverService = DocTextResolverService;
1881
2170
  exports.EMBED_DOCS_CUSTOM_BLOCK_DEFAULT_COMPONENT_KEY = EMBED_DOCS_CUSTOM_BLOCK_DEFAULT_COMPONENT_KEY;
1882
2171
  exports.HeaderFooterType = HeaderFooterType;
1883
2172
  exports.IDocStateChangeInterceptorService = IDocStateChangeInterceptorService;
2173
+ exports.InsertDocumentColumnBreakCommand = InsertDocumentColumnBreakCommand;
1884
2174
  exports.InsertDocumentSectionBreakCommand = InsertDocumentSectionBreakCommand;
1885
2175
  exports.InsertTextCommand = InsertTextCommand;
1886
2176
  exports.RichTextEditingMutation = RichTextEditingMutation;
@@ -1893,6 +2183,7 @@ Object.defineProperty(exports, 'UniverDocsPlugin', {
1893
2183
  return UniverDocsPlugin;
1894
2184
  }
1895
2185
  });
2186
+ exports.UpdateDocumentParagraphStyleCommand = UpdateDocumentParagraphStyleCommand;
1896
2187
  exports.UpdateDocumentSectionCommand = UpdateDocumentSectionCommand;
1897
2188
  exports.UpdateTextCommand = UpdateTextCommand;
1898
2189
  exports.addCustomRangeBySelectionFactory = addCustomRangeBySelectionFactory;
@@ -1910,6 +2201,8 @@ exports.deleteCustomRangeFactory = deleteCustomRangeFactory;
1910
2201
  exports.docDrawingPositionToTransform = docDrawingPositionToTransform;
1911
2202
  exports.generateParagraphs = generateParagraphs;
1912
2203
  exports.getContentInsertRange = getContentInsertRange;
2204
+ exports.getEffectiveSectionPageSetup = getEffectiveSectionPageSetup;
2205
+ exports.getSectionContentWidth = getSectionContentWidth;
1913
2206
  exports.getTopLevelSectionBreaks = getTopLevelSectionBreaks;
1914
2207
  exports.isEmbedDocsCustomBlockData = isEmbedDocsCustomBlockData;
1915
2208
  exports.isHeaderFooterSelection = isHeaderFooterSelection;