@univerjs/docs 1.0.4 → 1.2.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/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { AlignTypeH, BooleanNumber, BuildTextUtils, ColumnSeparatorType, CommandType, CustomCommandExecutionError, CustomRangeType, DEFAULT_STYLES, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DataStreamTreeTokenType, DeleteDirection, DependentOn, Disposable, DisposableCollection, DocumentDataModel, DocumentFlavor, DocxBreakType, DrawingTypeEnum, ErrorService, ICommandService, IConfigService, ILogService, IPermissionService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, JSON1, JSONX, LocaleService, MODERN_DOCUMENT_DEFAULT_MARGIN, MODERN_DOCUMENT_WIDTH, MemoryCursor, ModernDocumentWidthMode, ObjectPermissionRuleModel, ObjectPermissionService, ObjectRelativeFromH, ObjectRelativeFromV, Optional, PAGE_SIZE, PageOrientType, PaperType, PermissionStatus, Plugin, PositionedObjectLayoutType, RESTORE_INSERTED_PARAGRAPH_IDS, RedoCommandId, RxDisposable, SectionType, TRADITIONAL_DOCUMENT_DEFAULT_MARGIN, TextX, TextXActionType, Tools, UndoCommandId, UniverInstanceType, UpdateDocsAttributeType, composeInterceptors, containsInteriorInsertionOffset, createIdentifier, createInterceptorKey, createParagraphId, createSectionId, generateRandomId, getBlockRangeInterval, getColumnGroupRangeInterval, getParagraphContentStartOffset, getParagraphContentStartOffsets, getRichTextEditPath, getSdtBindingKey, getSdtBindingValue, getSectionHeaderFooterReferenceKey, getTableRangeInterval, isInternalEditorID, merge, remove, requestImmediateMacroTask, resolveSectionHeaderFooterReference, toDisposable, validateDocBodyStructure, validateDocumentStructure } from "@univerjs/core";
1
+ import { AlignTypeH, BooleanNumber, BuildTextUtils, ColumnSeparatorType, CommandType, CustomCommandExecutionError, CustomRangeType, DEFAULT_STYLES, DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DataStreamTreeTokenType, DeleteDirection, DependentOn, Disposable, DisposableCollection, DocumentDataModel, DocumentFlavor, DocxBreakType, DrawingTypeEnum, ErrorService, ICommandService, IConfigService, ILogService, IPermissionService, IResourceManagerService, IUndoRedoService, IUniverInstanceService, Inject, Injector, JSON1, JSONX, LocaleService, MODERN_DOCUMENT_DEFAULT_MARGIN, MODERN_DOCUMENT_WIDTH, MemoryCursor, ModernDocumentWidthMode, ObjectPermissionRuleModel, ObjectPermissionService, ObjectRelativeFromH, ObjectRelativeFromV, Optional, PAGE_SIZE, PageOrientType, PaperType, PermissionStatus, Plugin, PositionedObjectLayoutType, RESTORE_INSERTED_PARAGRAPH_IDS, RedoCommandId, RxDisposable, SHEET_TEXT_LINE_GAP, SectionType, TRADITIONAL_DOCUMENT_DEFAULT_MARGIN, TextX, TextXActionType, Tools, UndoCommandId, UniverInstanceType, UpdateDocsAttributeType, composeInterceptors, containsInteriorInsertionOffset, createIdentifier, createInterceptorKey, createParagraphId, createSectionId, generateRandomId, getBlockRangeInterval, getColumnGroupRangeInterval, getParagraphContentStartOffset, getParagraphContentStartOffsets, getRichTextEditPath, getSdtBindingKey, getSdtBindingValue, getSectionHeaderFooterReferenceKey, getTableRangeInterval, isInternalEditorID, merge, remove, requestImmediateMacroTask, resolveSectionHeaderFooterReference, toDisposable, validateDocBodyStructure, validateDocumentStructure } from "@univerjs/core";
2
2
  import { DocumentLayoutSession, DocumentSkeleton, DocumentViewModel, FontCache, IRenderManagerService, NORMAL_TEXT_SELECTION_PLUGIN_STYLE, getDocsCustomBlockRenderViewport, getDocumentLayoutPresentation, getFontStyleString, setDocsCustomBlockRenderViewportProvider } from "@univerjs/engine-render";
3
3
  import { BehaviorSubject, Observable, Subject, shareReplay, takeUntil } from "rxjs";
4
4
  import { UnitAction, UnitObject } from "@univerjs/protocol";
@@ -14,7 +14,7 @@ const SetTextSelectionsOperation = {
14
14
  };
15
15
 
16
16
  //#endregion
17
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
17
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/typeof.js
18
18
  function _typeof(o) {
19
19
  "@babel/helpers - typeof";
20
20
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -25,7 +25,7 @@ function _typeof(o) {
25
25
  }
26
26
 
27
27
  //#endregion
28
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
28
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPrimitive.js
29
29
  function toPrimitive(t, r) {
30
30
  if ("object" != _typeof(t) || !t) return t;
31
31
  var e = t[Symbol.toPrimitive];
@@ -38,14 +38,14 @@ function toPrimitive(t, r) {
38
38
  }
39
39
 
40
40
  //#endregion
41
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
41
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/toPropertyKey.js
42
42
  function toPropertyKey(t) {
43
43
  var i = toPrimitive(t, "string");
44
44
  return "symbol" == _typeof(i) ? i : i + "";
45
45
  }
46
46
 
47
47
  //#endregion
48
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
48
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/defineProperty.js
49
49
  function _defineProperty(e, r, t) {
50
50
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
51
51
  value: t,
@@ -56,7 +56,7 @@ function _defineProperty(e, r, t) {
56
56
  }
57
57
 
58
58
  //#endregion
59
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
59
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorateParam.js
60
60
  function __decorateParam(paramIndex, decorator) {
61
61
  return function(target, key) {
62
62
  decorator(target, key, paramIndex);
@@ -64,7 +64,7 @@ function __decorateParam(paramIndex, decorator) {
64
64
  }
65
65
 
66
66
  //#endregion
67
- //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
67
+ //#region \0@oxc-project+runtime@0.153.0/helpers/esm/decorate.js
68
68
  function __decorate(decorators, target, key, desc) {
69
69
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
70
70
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -159,7 +159,10 @@ let DocSelectionManagerService = class DocSelectionManagerService extends RxDisp
159
159
  subUnitId,
160
160
  docRanges,
161
161
  isEditing,
162
- options
162
+ options: {
163
+ ...options,
164
+ preserveInputStyle: false
165
+ }
163
166
  });
164
167
  }
165
168
  /**
@@ -179,7 +182,13 @@ let DocSelectionManagerService = class DocSelectionManagerService extends RxDisp
179
182
  ...textSelectionInfo,
180
183
  ...search
181
184
  };
182
- this._replaceByParam(params);
185
+ this._replaceByParam({
186
+ ...params,
187
+ options: {
188
+ ...params.options,
189
+ preserveInputStyle: true
190
+ }
191
+ });
183
192
  this._textSelection$.next(params);
184
193
  const { unitId, subUnitId, segmentId, style, textRanges, rectRanges, isEditing } = params;
185
194
  const ranges = [...textRanges, ...rectRanges].filter((range) => range.startOffset != null && range.endOffset != null).sort((a, b) => {
@@ -220,10 +229,11 @@ let DocSelectionManagerService = class DocSelectionManagerService extends RxDisp
220
229
  subUnitId,
221
230
  docRanges,
222
231
  isEditing,
223
- options: (options === null || options === void 0 ? void 0 : options.forceFocus) ? {
232
+ options: {
224
233
  ...options,
225
- forceFocus: false
226
- } : options
234
+ forceFocus: false,
235
+ preserveInputStyle: (options === null || options === void 0 ? void 0 : options.preserveInputStyle) ?? true
236
+ }
227
237
  });
228
238
  }
229
239
  _replaceByParam(insertParam) {
@@ -635,9 +645,11 @@ let DocLayoutExecutorService = _DocLayoutExecutorService = class DocLayoutExecut
635
645
  });
636
646
  }
637
647
  _enqueueCommittedMutation(params) {
648
+ var _params$actions;
638
649
  const executor = this._executor;
639
650
  const dataModel = this._getEligibleModel(params.unitId);
640
651
  if (executor == null || dataModel == null) return;
652
+ if (JSONX.isNoop(params.actions) || ((_params$actions = params.actions) === null || _params$actions === void 0 ? void 0 : _params$actions.length) === 0) return;
641
653
  const session = this._sessions.get(params.unitId);
642
654
  if (session == null) {
643
655
  this._replaceSession(dataModel).catch((error) => {
@@ -645,7 +657,6 @@ let DocLayoutExecutorService = _DocLayoutExecutorService = class DocLayoutExecut
645
657
  });
646
658
  return;
647
659
  }
648
- if (JSONX.isNoop(params.actions)) return;
649
660
  const sourceMutationRevision = dataModel.getMutationRevision();
650
661
  if (sourceMutationRevision !== session.sourceMutationRevision + 1) {
651
662
  session.needsResnapshot = true;
@@ -899,12 +910,13 @@ DocLayoutExecutorService = _DocLayoutExecutorService = __decorate([
899
910
  //#endregion
900
911
  //#region src/services/doc-skeleton-manager.service.ts
901
912
  let DocSkeletonManagerService = class DocSkeletonManagerService extends RxDisposable {
902
- constructor(_context, _localeService, _univerInstanceService, _docLayoutExecutorService) {
913
+ constructor(_context, _localeService, _univerInstanceService, _docLayoutExecutorService, _configService) {
903
914
  super();
904
915
  this._context = _context;
905
916
  this._localeService = _localeService;
906
917
  this._univerInstanceService = _univerInstanceService;
907
918
  this._docLayoutExecutorService = _docLayoutExecutorService;
919
+ this._configService = _configService;
908
920
  _defineProperty(this, "_skeleton", void 0);
909
921
  _defineProperty(this, "_docViewModel", void 0);
910
922
  _defineProperty(this, "_currentSkeleton$", new BehaviorSubject(null));
@@ -964,7 +976,8 @@ let DocSkeletonManagerService = class DocSkeletonManagerService extends RxDispos
964
976
  this._currentViewModel$.next(this._docViewModel);
965
977
  }
966
978
  _buildSkeleton(documentViewModel) {
967
- return DocumentSkeleton.create(documentViewModel, this._localeService);
979
+ const isSheetEditor = this._context.unitId === DOCS_NORMAL_EDITOR_UNIT_ID_KEY || this._context.unitId === DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY;
980
+ return DocumentSkeleton.create(documentViewModel, this._localeService, { lineGap: isSheetEditor ? this._configService.getConfig(SHEET_TEXT_LINE_GAP) : void 0 });
968
981
  }
969
982
  _buildDocViewModel(documentDataModel) {
970
983
  return new DocumentViewModel(documentDataModel);
@@ -973,7 +986,8 @@ let DocSkeletonManagerService = class DocSkeletonManagerService extends RxDispos
973
986
  DocSkeletonManagerService = __decorate([
974
987
  __decorateParam(1, Inject(LocaleService)),
975
988
  __decorateParam(2, IUniverInstanceService),
976
- __decorateParam(3, Inject(DocLayoutExecutorService))
989
+ __decorateParam(3, Inject(DocLayoutExecutorService)),
990
+ __decorateParam(4, IConfigService)
977
991
  ], DocSkeletonManagerService);
978
992
 
979
993
  //#endregion
@@ -1372,13 +1386,15 @@ function scheduleDocumentSelectionUpdate(selectionManager, params, isSync) {
1372
1386
  textRanges: logicalTextRanges,
1373
1387
  rectRanges: [],
1374
1388
  isEditing,
1375
- options: params.options
1389
+ options: {
1390
+ ...params.options,
1391
+ preserveInputStyle: false
1392
+ }
1376
1393
  }, selectionTarget);
1377
1394
  const updatedSelection = selectionManager.getSelectionInfo(selectionTarget);
1378
1395
  queueMicrotask(() => {
1379
1396
  if (selectionManager.getSelectionInfo(selectionTarget) !== updatedSelection) return;
1380
- if (updatedSelection == null) selectionManager.replaceDocRanges(logicalTextRanges, selectionTarget, isEditing, params.options);
1381
- else selectionManager.refreshSelection(selectionTarget, isEditing);
1397
+ selectionManager.replaceDocRanges(logicalTextRanges, selectionTarget, isEditing, params.options);
1382
1398
  });
1383
1399
  }
1384
1400
  /**
@@ -2110,384 +2126,717 @@ function getTopLevelSectionBreaks(body) {
2110
2126
  }
2111
2127
 
2112
2128
  //#endregion
2113
- //#region src/commands/commands/set-section-header-footer-link.command.ts
2114
- const SetSectionHeaderFooterLinkCommand = {
2115
- id: "doc.command.set-section-header-footer-link",
2116
- type: CommandType.COMMAND,
2117
- handler: (accessor, params) => {
2118
- var _snapshot$body$sectio;
2119
- if (!params) return false;
2120
- const instanceService = accessor.get(IUniverInstanceService);
2121
- const commandService = accessor.get(ICommandService);
2122
- const documentDataModel = instanceService.getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
2123
- const snapshot = documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getSnapshot();
2124
- if (!documentDataModel || !(snapshot === null || snapshot === void 0 ? void 0 : snapshot.body) || snapshot.documentStyle.documentFlavor !== DocumentFlavor.TRADITIONAL) return false;
2125
- const sections = getTopLevelSectionBreaks(snapshot.body);
2126
- const sectionIndex = sections.findIndex((section) => section.sectionId === params.sectionId);
2127
- if (sectionIndex <= 0) return false;
2128
- 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;
2129
- if (storageIndex < 0) return false;
2130
- const context = {
2131
- snapshot,
2132
- sections,
2133
- sectionIndex,
2134
- storageIndex,
2135
- key: getSectionHeaderFooterReferenceKey(params.kind, params.variant)
2136
- };
2137
- const rawActions = params.linkedToPrevious ? buildLinkActions(context, params.kind) : buildUnlinkActions(context, params.kind, params.segmentId);
2138
- if (!rawActions) return false;
2139
- const mutation = {
2140
- id: RichTextEditingMutation.id,
2141
- params: {
2142
- unitId: params.unitId,
2143
- actions: rawActions.reduce((actions, action) => JSONX.compose(actions, action), null),
2144
- textRanges: null,
2145
- noNeedSetTextRange: true,
2146
- debounce: true,
2147
- isEditing: false,
2148
- trigger: SetSectionHeaderFooterLinkCommand.id
2149
- }
2150
- };
2151
- return Boolean(commandService.syncExecuteCommand(mutation.id, mutation.params));
2129
+ //#region src/services/permission/document-permission-resolver.ts
2130
+ const HEADER_FOOTER_REFERENCE_KEYS = [
2131
+ "defaultHeaderId",
2132
+ "defaultFooterId",
2133
+ "firstPageHeaderId",
2134
+ "firstPageFooterId",
2135
+ "evenPageHeaderId",
2136
+ "evenPageFooterId"
2137
+ ];
2138
+ const documentPermissionResolverIndexCache = /* @__PURE__ */ new WeakMap();
2139
+ function getDocumentPermissionResolverIndex(documentDataModel) {
2140
+ var _getMutationRevision, _snapshot$body;
2141
+ const mutationRevision = ((_getMutationRevision = documentDataModel.getMutationRevision) === null || _getMutationRevision === void 0 ? void 0 : _getMutationRevision.call(documentDataModel)) ?? NaN;
2142
+ const cached = documentPermissionResolverIndexCache.get(documentDataModel);
2143
+ if ((cached === null || cached === void 0 ? void 0 : cached.mutationRevision) === mutationRevision) return cached;
2144
+ const snapshot = documentDataModel.getSnapshot();
2145
+ const topLevelSections = snapshot.body ? getTopLevelSectionBreaks(snapshot.body) : [];
2146
+ const drawingSegmentIds = /* @__PURE__ */ new Map();
2147
+ const addDrawingSegments = (body, segmentId) => {
2148
+ for (const block of (body === null || body === void 0 ? void 0 : body.customBlocks) ?? []) if (!drawingSegmentIds.has(block.blockId)) drawingSegmentIds.set(block.blockId, segmentId);
2149
+ };
2150
+ addDrawingSegments(snapshot.body, "");
2151
+ Object.entries(snapshot.headers ?? {}).forEach(([segmentId, header]) => addDrawingSegments(header.body, segmentId));
2152
+ Object.entries(snapshot.footers ?? {}).forEach(([segmentId, footer]) => addDrawingSegments(footer.body, segmentId));
2153
+ Object.entries(snapshot.notes ?? {}).forEach(([segmentId, footnote]) => addDrawingSegments(footnote.body, segmentId));
2154
+ const footnoteReferenceRanges = /* @__PURE__ */ new Map();
2155
+ for (const reference of ((_snapshot$body = snapshot.body) === null || _snapshot$body === void 0 ? void 0 : _snapshot$body.customRanges) ?? []) {
2156
+ var _reference$properties;
2157
+ if ((reference.rangeType === CustomRangeType.FOOTNOTE || reference.rangeType === CustomRangeType.ENDNOTE) && typeof ((_reference$properties = reference.properties) === null || _reference$properties === void 0 ? void 0 : _reference$properties.noteId) === "string") footnoteReferenceRanges.set(reference.properties.noteId, {
2158
+ startOffset: reference.startIndex,
2159
+ endOffset: reference.endIndex + 1
2160
+ });
2152
2161
  }
2153
- };
2154
- function buildLinkActions(context, kind) {
2155
- const { snapshot, sections, sectionIndex, storageIndex, key } = context;
2156
- const section = sections[sectionIndex];
2157
- const explicitSegmentId = section[key];
2158
- if (typeof explicitSegmentId !== "string" || !explicitSegmentId) return null;
2159
- const jsonX = JSONX.getInstance();
2160
- const actions = [jsonX.removeOp([
2161
- "body",
2162
- "sectionBreaks",
2163
- storageIndex,
2164
- key
2165
- ], explicitSegmentId)];
2166
- const referenceKeys = kind === "header" ? [
2167
- "defaultHeaderId",
2168
- "firstPageHeaderId",
2169
- "evenPageHeaderId"
2170
- ] : [
2171
- "defaultFooterId",
2172
- "firstPageFooterId",
2173
- "evenPageFooterId"
2174
- ];
2175
- const referencedByDocument = referenceKeys.some((referenceKey) => snapshot.documentStyle[referenceKey] === explicitSegmentId);
2176
- const referencedBySection = sections.some((item) => referenceKeys.some((referenceKey) => !(item.sectionId === section.sectionId && referenceKey === key) && item[referenceKey] === explicitSegmentId));
2177
- const resources = kind === "header" ? snapshot.headers : snapshot.footers;
2178
- if (!referencedByDocument && !referencedBySection && (resources === null || resources === void 0 ? void 0 : resources[explicitSegmentId])) actions.push(jsonX.removeOp([kind === "header" ? "headers" : "footers", explicitSegmentId], resources[explicitSegmentId]));
2179
- return actions;
2162
+ const index = {
2163
+ drawingSegmentIds,
2164
+ footnoteReferenceRanges,
2165
+ mutationRevision,
2166
+ segments: /* @__PURE__ */ new Map(),
2167
+ topLevelSections
2168
+ };
2169
+ documentPermissionResolverIndexCache.set(documentDataModel, index);
2170
+ return index;
2180
2171
  }
2181
- function buildUnlinkActions(context, kind, requestedSegmentId) {
2182
- const { snapshot, sections, sectionIndex, storageIndex, key } = context;
2183
- const explicitSegmentId = sections[sectionIndex][key];
2184
- if (typeof explicitSegmentId === "string" && explicitSegmentId) return null;
2185
- const sourceSegmentId = resolveSectionHeaderFooterReference(snapshot.documentStyle, sections, sectionIndex - 1, key).segmentId;
2186
- const segmentId = requestedSegmentId ?? generateRandomId(6);
2187
- const resources = kind === "header" ? snapshot.headers : snapshot.footers;
2188
- if (resources === null || resources === void 0 ? void 0 : resources[segmentId]) return null;
2189
- const source = sourceSegmentId ? resources === null || resources === void 0 ? void 0 : resources[sourceSegmentId] : void 0;
2190
- const idKey = kind === "header" ? "headerId" : "footerId";
2191
- const resource = source ? {
2192
- ...Tools.deepClone(source),
2193
- [idKey]: segmentId
2194
- } : {
2195
- [idKey]: segmentId,
2196
- body: getEmptyHeaderFooterBody()
2172
+ function getDocumentPermissionSegmentIndex(documentDataModel, segmentId, resolverIndex = getDocumentPermissionResolverIndex(documentDataModel)) {
2173
+ var _documentDataModel$ge, _snapshot$notes;
2174
+ const cached = resolverIndex.segments.get(segmentId);
2175
+ if (cached) return cached;
2176
+ const body = ((_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.getBody()) ?? null;
2177
+ const snapshot = documentDataModel.getSnapshot();
2178
+ const note = (_snapshot$notes = snapshot.notes) === null || _snapshot$notes === void 0 ? void 0 : _snapshot$notes[segmentId];
2179
+ const drawings = (note ? note.drawings : snapshot.drawings) ?? {};
2180
+ const entities = body == null ? [] : [
2181
+ ...(body.tables ?? []).map((item) => ({
2182
+ type: "table",
2183
+ id: item.tableId,
2184
+ startOffset: item.startIndex,
2185
+ endOffset: item.endIndex
2186
+ })),
2187
+ ...(body.customBlocks ?? []).map((item) => ({
2188
+ type: drawings[item.blockId] ? "drawing" : "custom-block",
2189
+ id: item.blockId,
2190
+ startOffset: item.startIndex,
2191
+ endOffset: item.startIndex + 1
2192
+ })),
2193
+ ...(body.blockRanges ?? []).map((item) => ({
2194
+ type: "block-range",
2195
+ id: item.blockId,
2196
+ startOffset: item.startIndex,
2197
+ endOffset: item.endIndex + 1
2198
+ })),
2199
+ ...(body.customRanges ?? []).map((item) => ({
2200
+ type: "custom-range",
2201
+ id: item.rangeId,
2202
+ startOffset: item.startIndex,
2203
+ endOffset: item.endIndex + 1
2204
+ })),
2205
+ ...(body.columnGroups ?? []).map((item) => ({
2206
+ type: "column-group",
2207
+ id: item.columnGroupId,
2208
+ startOffset: item.startIndex,
2209
+ endOffset: item.endIndex + 1
2210
+ }))
2211
+ ];
2212
+ const entityRanges = new Map(entities.map((entity) => [`${entity.type}:${entity.id}`, {
2213
+ startOffset: entity.startOffset,
2214
+ endOffset: entity.endOffset
2215
+ }]));
2216
+ for (const block of (body === null || body === void 0 ? void 0 : body.customBlocks) ?? []) {
2217
+ const range = {
2218
+ startOffset: block.startIndex,
2219
+ endOffset: block.startIndex + 1
2220
+ };
2221
+ entityRanges.set(`custom-block:${block.blockId}`, range);
2222
+ entityRanges.set(`drawing:${block.blockId}`, range);
2223
+ }
2224
+ const segmentIndex = {
2225
+ body,
2226
+ entities,
2227
+ entityRanges,
2228
+ paragraphContentStartOffsets: body == null ? /* @__PURE__ */ new Map() : getParagraphContentStartOffsets(body),
2229
+ paragraphsById: new Map(((body === null || body === void 0 ? void 0 : body.paragraphs) ?? []).filter((paragraph) => paragraph.paragraphId != null).map((paragraph) => [paragraph.paragraphId, paragraph]))
2197
2230
  };
2198
- const jsonX = JSONX.getInstance();
2199
- return [jsonX.insertOp([kind === "header" ? "headers" : "footers", segmentId], resource), jsonX.insertOp([
2200
- "body",
2201
- "sectionBreaks",
2202
- storageIndex,
2203
- key
2204
- ], segmentId)];
2231
+ resolverIndex.segments.set(segmentId, segmentIndex);
2232
+ return segmentIndex;
2205
2233
  }
2206
-
2207
- //#endregion
2208
- //#region src/commands/commands/update-document-paragraph-style.command.ts
2209
- function isValidParams(params) {
2210
- 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);
2234
+ function getDocumentDrawingSegmentId(documentDataModel, drawingId) {
2235
+ return getDocumentPermissionResolverIndex(documentDataModel).drawingSegmentIds.get(drawingId) ?? "";
2211
2236
  }
2212
- function getCurrentParagraph(body, params) {
2213
- const matches = (body.paragraphs ?? []).filter((paragraph) => paragraph.paragraphId === params.paragraphId);
2214
- if (matches.length !== 1) return null;
2215
- const paragraph = matches[0];
2216
- return getParagraphContentStartOffset(body, paragraph) === params.startOffset && paragraph.startIndex === params.endOffset && body.dataStream[params.endOffset] === "\r" ? paragraph : null;
2237
+ function getDocumentEditTargetObjectIds(documentDataModel, segmentId, range) {
2238
+ const resolverIndex = getDocumentPermissionResolverIndex(documentDataModel);
2239
+ const segmentIndex = getDocumentPermissionSegmentIndex(documentDataModel, segmentId, resolverIndex);
2240
+ const { body } = segmentIndex;
2241
+ if (!body) return [];
2242
+ return [
2243
+ ...getSectionPermissionObjectIds(documentDataModel, segmentId, range, resolverIndex),
2244
+ ...getParagraphPermissionObjectIds(body, segmentId, range, segmentIndex),
2245
+ ...getEntityPermissionObjectIds(segmentId, range, segmentIndex)
2246
+ ];
2217
2247
  }
2218
- function createParagraphStyleTextX(body, paragraph, params) {
2219
- const textX = new TextX();
2220
- const initializesTextRuns = Boolean(params.style.textStyle && params.startOffset < params.endOffset && body.textRuns == null);
2221
- if (params.startOffset > 0) textX.push({
2222
- t: TextXActionType.RETAIN,
2223
- len: params.startOffset
2224
- });
2225
- if (params.style.textStyle && params.startOffset < params.endOffset && !initializesTextRuns) textX.push({
2226
- t: TextXActionType.RETAIN,
2227
- len: params.endOffset - params.startOffset,
2228
- coverType: UpdateDocsAttributeType.COVER,
2229
- body: {
2230
- dataStream: "",
2231
- textRuns: [{
2232
- st: 0,
2233
- ed: params.endOffset - params.startOffset,
2234
- ts: Tools.deepClone(params.style.textStyle)
2235
- }]
2236
- }
2237
- });
2238
- else if (params.startOffset < params.endOffset) textX.push({
2239
- t: TextXActionType.RETAIN,
2240
- len: params.endOffset - params.startOffset
2241
- });
2242
- const paragraphBody = {
2243
- dataStream: "",
2244
- paragraphs: [{
2245
- ...Tools.deepClone(paragraph),
2246
- startIndex: 0,
2247
- paragraphStyle: {
2248
- ...Tools.deepClone(paragraph.paragraphStyle ?? {}),
2249
- ...Tools.deepClone(params.style)
2250
- }
2251
- }]
2252
- };
2253
- Object.defineProperty(paragraphBody, RESTORE_INSERTED_PARAGRAPH_IDS, {
2254
- value: true,
2255
- enumerable: true
2248
+ function getDocumentEditTargetObjectIdsFromActions(documentDataModel, segmentId, actions) {
2249
+ const result = /* @__PURE__ */ new Set();
2250
+ if (actions == null) return [];
2251
+ const cursor = JSON1.type.readCursor(actions);
2252
+ cursor.traverse(null, () => {
2253
+ const path = cursor.getPath();
2254
+ const edit = cursor.getComponent();
2255
+ const scopedSegment = [
2256
+ "headers",
2257
+ "footers",
2258
+ "notes"
2259
+ ].includes(String(path[0])) && typeof path[1] === "string" ? path[1] : segmentId;
2260
+ if (path[0] === "notes" && typeof path[1] === "string") getSectionPermissionObjectIds(documentDataModel, path[1], {
2261
+ startOffset: 0,
2262
+ endOffset: 0
2263
+ }).forEach((objectId) => result.add(objectId));
2264
+ if (path[0] === "noteSettings") getDocumentPermissionResolverIndex(documentDataModel).topLevelSections.forEach((section) => {
2265
+ result.add(getDocumentSectionPermissionObjectId("", section.sectionId));
2266
+ });
2267
+ if (path[0] === "body" && path[1] === "sectionBreaks" && typeof path[2] === "number" && (path[3] === "noteProperties" || path[3] === "suppressEndnotes")) {
2268
+ var _documentDataModel$ge2;
2269
+ const sectionId = (_documentDataModel$ge2 = documentDataModel.getBody()) === null || _documentDataModel$ge2 === void 0 || (_documentDataModel$ge2 = _documentDataModel$ge2.sectionBreaks) === null || _documentDataModel$ge2 === void 0 || (_documentDataModel$ge2 = _documentDataModel$ge2[path[2]]) === null || _documentDataModel$ge2 === void 0 ? void 0 : _documentDataModel$ge2.sectionId;
2270
+ if (sectionId) result.add(getDocumentSectionPermissionObjectId("", sectionId));
2271
+ }
2272
+ if (path[path.length - 1] !== "body" || (edit === null || edit === void 0 ? void 0 : edit.et) !== TextX.id || !Array.isArray(edit.e) || !edit.e.every(isTextXAction)) return;
2273
+ const textActions = edit.e;
2274
+ let offset = 0;
2275
+ const addRange = (startOffset, endOffset) => {
2276
+ getDocumentEditTargetObjectIds(documentDataModel, scopedSegment, {
2277
+ startOffset,
2278
+ endOffset
2279
+ }).forEach((objectId) => result.add(objectId));
2280
+ };
2281
+ textActions.forEach((action) => {
2282
+ if (action.t === TextXActionType.INSERT) {
2283
+ addRange(offset, offset);
2284
+ return;
2285
+ }
2286
+ if (action.t === TextXActionType.DELETE) {
2287
+ addRange(offset, offset + action.len);
2288
+ offset += action.len;
2289
+ return;
2290
+ }
2291
+ if (action.body !== void 0 || action.oldBody !== void 0 || action.coverType !== void 0) addRange(offset, offset + action.len);
2292
+ offset += action.len;
2293
+ });
2256
2294
  });
2257
- textX.push({
2258
- t: TextXActionType.RETAIN,
2259
- len: 1,
2260
- coverType: UpdateDocsAttributeType.REPLACE,
2261
- body: paragraphBody
2295
+ getDrawingIdsFromActions(actions).forEach((drawingId) => {
2296
+ var _documentDataModel$ge3, _body$customBlocks;
2297
+ result.add(getDocumentEntityPermissionObjectId(segmentId, "drawing", drawingId));
2298
+ const body = (_documentDataModel$ge3 = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge3 === void 0 ? void 0 : _documentDataModel$ge3.getBody();
2299
+ const block = body === null || body === void 0 || (_body$customBlocks = body.customBlocks) === null || _body$customBlocks === void 0 ? void 0 : _body$customBlocks.find((item) => item.blockId === drawingId);
2300
+ if (block) getSectionPermissionObjectIds(documentDataModel, segmentId, {
2301
+ startOffset: block.startIndex,
2302
+ endOffset: block.startIndex + 1
2303
+ }).forEach((objectId) => result.add(objectId));
2262
2304
  });
2263
- return {
2264
- textX,
2265
- initializesTextRuns
2266
- };
2305
+ return [...result];
2267
2306
  }
2268
- const UpdateDocumentParagraphStyleCommand = {
2269
- id: "doc.command.update-paragraph-style",
2270
- type: CommandType.COMMAND,
2271
- handler: (accessor, params) => {
2272
- var _documentDataModel$ge;
2273
- if (!isValidParams(params)) return false;
2274
- const instanceService = accessor.get(IUniverInstanceService);
2275
- const commandService = accessor.get(ICommandService);
2276
- const documentDataModel = instanceService.getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
2277
- const segmentId = params.segmentId ?? "";
2278
- const body = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.getBody();
2279
- if (!documentDataModel || !body) return false;
2280
- const paragraph = getCurrentParagraph(body, params);
2281
- if (!paragraph) return false;
2282
- const { textX, initializesTextRuns } = createParagraphStyleTextX(body, paragraph, params);
2283
- const jsonX = JSONX.getInstance();
2284
- const path = getRichTextEditPath(documentDataModel, segmentId);
2285
- let actions = jsonX.editOp(textX.serialize(), path);
2286
- if (initializesTextRuns) {
2287
- const initializeTextRunsActions = jsonX.replaceOp([...path, "textRuns"], void 0, [{
2288
- st: params.startOffset,
2289
- ed: params.endOffset,
2290
- ts: Tools.deepClone(params.style.textStyle)
2291
- }]);
2292
- actions = JSONX.compose(initializeTextRunsActions, actions);
2307
+ function getDrawingIdsFromActions(actions) {
2308
+ const result = /* @__PURE__ */ new Set();
2309
+ const visit = (value) => {
2310
+ if (Array.isArray(value)) {
2311
+ value.forEach((item, index) => {
2312
+ if (item === "drawings" && typeof value[index + 1] === "string") result.add(value[index + 1]);
2313
+ visit(item);
2314
+ });
2315
+ return;
2293
2316
  }
2294
- return Boolean(commandService.syncExecuteCommand(RichTextEditingMutation.id, {
2295
- unitId: params.unitId,
2296
- segmentId,
2297
- actions,
2298
- textRanges: null,
2299
- noNeedSetTextRange: true,
2300
- isEditing: false,
2301
- trigger: UpdateDocumentParagraphStyleCommand.id
2302
- }));
2303
- }
2304
- };
2305
-
2306
- //#endregion
2307
- //#region src/utils/section-columns.ts
2308
- function resolveSectionValue(sectionValue, documentValue, fallback) {
2309
- return sectionValue ?? documentValue ?? fallback;
2310
- }
2311
- function getEffectivePageSize(documentStyle, section) {
2312
- var _section$pageSize, _documentStyle$pageSi, _section$pageSize2, _documentStyle$pageSi2;
2313
- const fallback = PAGE_SIZE[PaperType.A4];
2314
- return {
2315
- 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),
2316
- 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)
2317
+ if (!isRecord$2(value)) return;
2318
+ Object.values(value).forEach(visit);
2317
2319
  };
2320
+ visit(actions);
2321
+ return [...result];
2318
2322
  }
2319
- function getEffectiveMargins(documentStyle, section) {
2320
- return {
2321
- top: resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginTop, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginTop, TRADITIONAL_DOCUMENT_DEFAULT_MARGIN),
2322
- bottom: resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginBottom, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginBottom, TRADITIONAL_DOCUMENT_DEFAULT_MARGIN),
2323
- left: resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginLeft, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginLeft, TRADITIONAL_DOCUMENT_DEFAULT_MARGIN),
2324
- right: resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginRight, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginRight, TRADITIONAL_DOCUMENT_DEFAULT_MARGIN)
2325
- };
2323
+ function isTextXAction(value) {
2324
+ if (!isRecord$2(value) || typeof value.len !== "number") return false;
2325
+ if (value.t === TextXActionType.INSERT) return isRecord$2(value.body);
2326
+ return value.t === TextXActionType.RETAIN || value.t === TextXActionType.DELETE;
2326
2327
  }
2327
- function assertPositivePageSetup(pageSize, contentSize) {
2328
- if (![
2329
- pageSize.width,
2330
- pageSize.height,
2331
- contentSize.width,
2332
- contentSize.height
2333
- ].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.");
2328
+ function isRecord$2(value) {
2329
+ return typeof value === "object" && value !== null && !Array.isArray(value);
2334
2330
  }
2335
- /** Resolves nominal traditional page geometry without requiring a renderer. */
2336
- function getEffectiveSectionPageSetup(documentStyle, section) {
2337
- const pageSize = getEffectivePageSize(documentStyle, section);
2338
- const margins = getEffectiveMargins(documentStyle, section);
2339
- const contentSize = {
2340
- width: getSectionContentWidth(documentStyle, section),
2341
- height: pageSize.height - margins.top - margins.bottom
2342
- };
2343
- assertPositivePageSetup(pageSize, contentSize);
2344
- const pageNumberStart = (section === null || section === void 0 ? void 0 : section.pageNumberStart) ?? (documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.pageNumberStart);
2345
- return {
2346
- pageSize,
2347
- pageOrient: resolveSectionValue(section === null || section === void 0 ? void 0 : section.pageOrient, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.pageOrient, PageOrientType.PORTRAIT),
2348
- margins,
2349
- contentSize,
2350
- ...pageNumberStart == null ? {} : { pageNumberStart }
2351
- };
2331
+ function getDocumentEntityParentPermissionObjectIds(documentDataModel, segmentId, entityType, entityId) {
2332
+ const resolverIndex = getDocumentPermissionResolverIndex(documentDataModel);
2333
+ const range = getDocumentPermissionSegmentIndex(documentDataModel, segmentId, resolverIndex).entityRanges.get(`${entityType}:${entityId}`) ?? null;
2334
+ return range ? getSectionPermissionObjectIds(documentDataModel, segmentId, range, resolverIndex) : [];
2352
2335
  }
2353
- /** Returns the usable horizontal layout width for a traditional section. */
2354
- function getSectionContentWidth(documentStyle, section) {
2355
- var _section$pageSize3, _documentStyle$pageSi3;
2356
- 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, PAGE_SIZE[PaperType.A4].width);
2357
- return Math.max(0, pageWidth - resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginLeft, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginLeft, TRADITIONAL_DOCUMENT_DEFAULT_MARGIN) - resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginRight, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginRight, TRADITIONAL_DOCUMENT_DEFAULT_MARGIN));
2336
+ function getDocumentParagraphParentPermissionObjectIds(documentDataModel, segmentId, paragraphId) {
2337
+ const resolverIndex = getDocumentPermissionResolverIndex(documentDataModel);
2338
+ const segmentIndex = getDocumentPermissionSegmentIndex(documentDataModel, segmentId, resolverIndex);
2339
+ const { body } = segmentIndex;
2340
+ const paragraph = segmentIndex.paragraphsById.get(paragraphId);
2341
+ if (!body || !paragraph) return [];
2342
+ return getSectionPermissionObjectIds(documentDataModel, segmentId, {
2343
+ startOffset: segmentIndex.paragraphContentStartOffsets.get(paragraph.startIndex) ?? getParagraphContentStartOffset(body, paragraph),
2344
+ endOffset: paragraph.startIndex + 1
2345
+ }, resolverIndex);
2358
2346
  }
2359
- /** Creates explicit OOXML section columns from a count, gap, and optional widths. */
2360
- function createSectionColumnProperties(documentStyle, section, columnCount, gap, widths) {
2361
- if (columnCount <= 1) return [];
2362
- const safeGap = Math.max(0, gap);
2363
- const contentWidth = getSectionContentWidth(documentStyle, section);
2364
- const availableWidth = Math.max(0, contentWidth - safeGap * (columnCount - 1));
2365
- if (widths) {
2366
- if (widths.some((width) => !Number.isFinite(width) || width < 0)) throw new RangeError("Section column widths must be finite and non-negative.");
2367
- if (widths.reduce((sum, width) => sum + width, 0) > availableWidth) throw new RangeError("Section columns exceed the available page content width.");
2347
+ function getDocumentSectionPermissionObjectIdsByIds(sectionIds) {
2348
+ return Array.from(sectionIds, (sectionId) => getDocumentSectionPermissionObjectId("", sectionId));
2349
+ }
2350
+ function getDocumentSectionIdsAtOffset(body, offset) {
2351
+ return getSectionsIntersectingRange(getTopLevelSectionBreaks(body), {
2352
+ startOffset: offset,
2353
+ endOffset: offset
2354
+ }).map((section) => section.sectionId);
2355
+ }
2356
+ function getSectionPermissionObjectIds(documentDataModel, segmentId, range, resolverIndex = getDocumentPermissionResolverIndex(documentDataModel)) {
2357
+ if (segmentId) {
2358
+ const referenceRange = resolverIndex.footnoteReferenceRanges.get(segmentId);
2359
+ if (referenceRange) return getDocumentEditTargetObjectIds(documentDataModel, "", referenceRange);
2360
+ return getHeaderFooterOwnerSectionIds(documentDataModel, segmentId, resolverIndex.topLevelSections).map((sectionId) => getDocumentSectionPermissionObjectId("", sectionId));
2368
2361
  }
2369
- return (widths ?? Array.from({ length: columnCount }, () => availableWidth / columnCount)).map((width, index) => ({
2370
- width: Math.max(0, width),
2371
- paddingEnd: index === columnCount - 1 ? 0 : safeGap
2372
- }));
2362
+ return getSectionsIntersectingRange(resolverIndex.topLevelSections, range).map((section) => getDocumentSectionPermissionObjectId("", section.sectionId));
2363
+ }
2364
+ function getParagraphPermissionObjectIds(body, segmentId, range, segmentIndex) {
2365
+ const startOffset = Math.min(range.startOffset, range.endOffset);
2366
+ const endOffset = Math.max(range.startOffset, range.endOffset);
2367
+ return (body.paragraphs ?? []).filter((paragraph) => intersectsRange(segmentIndex.paragraphContentStartOffsets.get(paragraph.startIndex) ?? getParagraphContentStartOffset(body, paragraph), paragraph.startIndex + 1, startOffset, endOffset)).flatMap((paragraph) => paragraph.paragraphId ? [getDocumentParagraphPermissionObjectId(segmentId, paragraph.paragraphId)] : []);
2368
+ }
2369
+ function getEntityPermissionObjectIds(segmentId, range, segmentIndex) {
2370
+ const startOffset = Math.min(range.startOffset, range.endOffset);
2371
+ const endOffset = Math.max(range.startOffset, range.endOffset);
2372
+ return segmentIndex.entities.filter((item) => intersectsRange(item.startOffset, item.endOffset, startOffset, endOffset)).map((item) => getDocumentEntityPermissionObjectId(segmentId, item.type, item.id));
2373
+ }
2374
+ function getSectionsIntersectingRange(sections, range) {
2375
+ const startOffset = Math.min(range.startOffset, range.endOffset);
2376
+ const endOffset = Math.max(range.startOffset, range.endOffset);
2377
+ return sections.filter((section, index) => intersectsRange(index === 0 ? 0 : sections[index - 1].startIndex + 1, section.startIndex + 1, startOffset, endOffset));
2378
+ }
2379
+ function intersectsRange(targetStart, targetEnd, rangeStart, rangeEnd) {
2380
+ if (rangeStart === rangeEnd) return rangeStart >= targetStart && rangeStart < targetEnd;
2381
+ return rangeStart < targetEnd && rangeEnd > targetStart;
2382
+ }
2383
+ function getHeaderFooterOwnerSectionIds(documentDataModel, segmentId, sections = getDocumentPermissionResolverIndex(documentDataModel).topLevelSections) {
2384
+ const snapshot = documentDataModel.getSnapshot();
2385
+ const result = /* @__PURE__ */ new Set();
2386
+ sections.forEach((section, sectionIndex) => {
2387
+ if (HEADER_FOOTER_REFERENCE_KEYS.some((key) => resolveSectionHeaderFooterReference(snapshot.documentStyle, sections, sectionIndex, key).segmentId === segmentId)) result.add(section.sectionId);
2388
+ });
2389
+ return [...result];
2373
2390
  }
2374
2391
 
2375
2392
  //#endregion
2376
- //#region src/commands/commands/update-document-section.command.ts
2377
- const UpdateDocumentSectionCommand = {
2378
- id: "doc.command.update-section",
2393
+ //#region src/commands/commands/set-heading-collapsed.command.ts
2394
+ const SetHeadingCollapsedCommand = {
2395
+ id: "doc.command.set-heading-collapsed",
2379
2396
  type: CommandType.COMMAND,
2380
2397
  handler: (accessor, params) => {
2381
- if (!(params === null || params === void 0 ? void 0 : params.updates.length) || params.updates.some(({ sectionId, config }) => !sectionId || Object.keys(config).length === 0)) return false;
2382
- const instanceService = accessor.get(IUniverInstanceService);
2383
- const commandService = accessor.get(ICommandService);
2384
- const documentDataModel = instanceService.getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
2385
- if (!documentDataModel || documentDataModel.getDocumentStyle().documentFlavor !== DocumentFlavor.TRADITIONAL) return false;
2386
- const body = documentDataModel.getBody();
2387
- if (!body) return false;
2388
- const updates = new Map(params.updates.map(({ sectionId, config }) => [sectionId, config]));
2389
- if (updates.size !== params.updates.length) return false;
2390
- const selectedIds = new Set(updates.keys());
2391
- const sections = getTopLevelSectionBreaks(body).filter((section) => selectedIds.has(section.sectionId)).sort((left, right) => left.startIndex - right.startIndex);
2392
- if (sections.length !== selectedIds.size) return false;
2393
- const documentStyle = documentDataModel.getDocumentStyle();
2394
- if (sections.some((section) => !isValidSectionConfig({
2395
- ...section,
2396
- ...updates.get(section.sectionId)
2397
- }, documentStyle))) return false;
2398
- const cursor = new MemoryCursor();
2399
- const textX = new TextX();
2400
- for (const section of sections) {
2401
- textX.push({
2398
+ var _body$paragraphs;
2399
+ if (!params || typeof params.collapsed !== "boolean") return false;
2400
+ const doc = accessor.get(IUniverInstanceService).getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
2401
+ if (!doc || doc.getDisabled() || doc.getSnapshot().documentStyle.documentFlavor !== DocumentFlavor.MODERN) return false;
2402
+ const body = doc.getBody();
2403
+ const matches = (body === null || body === void 0 || (_body$paragraphs = body.paragraphs) === null || _body$paragraphs === void 0 ? void 0 : _body$paragraphs.filter((paragraph) => paragraph.paragraphId === params.paragraphId)) ?? [];
2404
+ const paragraph = matches[0];
2405
+ if (!body || matches.length !== 1 || paragraph.headingCollapsed === true === params.collapsed) return false;
2406
+ const viewModel = new DocumentViewModel(doc);
2407
+ try {
2408
+ var _selectionService$get;
2409
+ const section = viewModel.getHeadingSections().find((section) => section.paragraphId === params.paragraphId);
2410
+ if (!section || params.collapsed && section.startOffset >= section.endOffset || viewModel.getCollapsedHeadingAtOffset(paragraph.startIndex)) return false;
2411
+ const targets = getDocumentEditTargetObjectIds(doc, "", {
2412
+ startOffset: getParagraphContentStartOffset(body, paragraph),
2413
+ endOffset: paragraph.startIndex + 1
2414
+ });
2415
+ if (!canEditDocumentTargets(accessor.get(IPermissionService), params.unitId, targets)) return false;
2416
+ const textX = new TextX();
2417
+ if (paragraph.startIndex > 0) textX.push({
2402
2418
  t: TextXActionType.RETAIN,
2403
- len: section.startIndex - cursor.cursor
2419
+ len: paragraph.startIndex
2404
2420
  });
2405
2421
  textX.push({
2406
2422
  t: TextXActionType.RETAIN,
2407
2423
  len: 1,
2408
- coverType: UpdateDocsAttributeType.REPLACE,
2424
+ coverType: UpdateDocsAttributeType.COVER,
2409
2425
  body: {
2410
2426
  dataStream: "",
2411
- sectionBreaks: [{
2412
- ...Tools.deepClone(section),
2413
- ...Tools.deepClone(updates.get(section.sectionId)),
2414
- sectionId: section.sectionId,
2415
- startIndex: 0
2427
+ paragraphs: [{
2428
+ paragraphId: paragraph.paragraphId,
2429
+ startIndex: 0,
2430
+ headingCollapsed: params.collapsed
2416
2431
  }]
2417
2432
  }
2418
2433
  });
2419
- cursor.moveCursorTo(section.startIndex + 1);
2434
+ const actions = JSONX.getInstance().editOp(textX.serialize(), getRichTextEditPath(doc));
2435
+ const selectionService = accessor.get(DocSelectionManagerService);
2436
+ const selectionTarget = {
2437
+ unitId: params.unitId,
2438
+ subUnitId: params.unitId
2439
+ };
2440
+ const ranges = selectionService.getDocRanges(selectionTarget) ?? [];
2441
+ const hidesSelection = params.collapsed && !((_selectionService$get = selectionService.getSelectionInfo(selectionTarget)) === null || _selectionService$get === void 0 ? void 0 : _selectionService$get.segmentId) && ranges.some((range) => !range.segmentId && range.startOffset != null && range.endOffset != null && range.endOffset >= section.startOffset && range.startOffset < section.endOffset);
2442
+ return Boolean(accessor.get(ICommandService).syncExecuteCommand(RichTextEditingMutation.id, {
2443
+ unitId: params.unitId,
2444
+ actions,
2445
+ textRanges: hidesSelection ? [{
2446
+ startOffset: paragraph.startIndex,
2447
+ endOffset: paragraph.startIndex,
2448
+ collapsed: true
2449
+ }] : null,
2450
+ prevTextRanges: ranges,
2451
+ noNeedSetTextRange: !hidesSelection,
2452
+ isEditing: false,
2453
+ trigger: SetHeadingCollapsedCommand.id
2454
+ }));
2455
+ } finally {
2456
+ viewModel.dispose();
2420
2457
  }
2421
- const jsonX = JSONX.getInstance();
2458
+ }
2459
+ };
2460
+
2461
+ //#endregion
2462
+ //#region src/commands/commands/set-section-header-footer-link.command.ts
2463
+ const SetSectionHeaderFooterLinkCommand = {
2464
+ id: "doc.command.set-section-header-footer-link",
2465
+ type: CommandType.COMMAND,
2466
+ handler: (accessor, params) => {
2467
+ var _snapshot$body$sectio;
2468
+ if (!params) return false;
2469
+ const instanceService = accessor.get(IUniverInstanceService);
2470
+ const commandService = accessor.get(ICommandService);
2471
+ const documentDataModel = instanceService.getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
2472
+ const snapshot = documentDataModel === null || documentDataModel === void 0 ? void 0 : documentDataModel.getSnapshot();
2473
+ if (!documentDataModel || !(snapshot === null || snapshot === void 0 ? void 0 : snapshot.body) || snapshot.documentStyle.documentFlavor !== DocumentFlavor.TRADITIONAL) return false;
2474
+ const sections = getTopLevelSectionBreaks(snapshot.body);
2475
+ const sectionIndex = sections.findIndex((section) => section.sectionId === params.sectionId);
2476
+ if (sectionIndex <= 0) return false;
2477
+ 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;
2478
+ if (storageIndex < 0) return false;
2479
+ const context = {
2480
+ snapshot,
2481
+ sections,
2482
+ sectionIndex,
2483
+ storageIndex,
2484
+ key: getSectionHeaderFooterReferenceKey(params.kind, params.variant)
2485
+ };
2486
+ const rawActions = params.linkedToPrevious ? buildLinkActions(context, params.kind) : buildUnlinkActions(context, params.kind, params.segmentId);
2487
+ if (!rawActions) return false;
2422
2488
  const mutation = {
2423
2489
  id: RichTextEditingMutation.id,
2424
2490
  params: {
2425
2491
  unitId: params.unitId,
2426
- actions: jsonX.editOp(textX.serialize(), getRichTextEditPath(documentDataModel)),
2492
+ actions: rawActions.reduce((actions, action) => JSONX.compose(actions, action), null),
2427
2493
  textRanges: null,
2428
2494
  noNeedSetTextRange: true,
2429
2495
  debounce: true,
2430
2496
  isEditing: false,
2431
- trigger: UpdateDocumentSectionCommand.id
2497
+ trigger: SetSectionHeaderFooterLinkCommand.id
2432
2498
  }
2433
2499
  };
2434
2500
  return Boolean(commandService.syncExecuteCommand(mutation.id, mutation.params));
2435
2501
  }
2436
2502
  };
2437
- const InsertDocumentSectionBreakCommand = {
2438
- id: "doc.command.insert-section-break",
2503
+ function buildLinkActions(context, kind) {
2504
+ const { snapshot, sections, sectionIndex, storageIndex, key } = context;
2505
+ const section = sections[sectionIndex];
2506
+ const explicitSegmentId = section[key];
2507
+ if (typeof explicitSegmentId !== "string" || !explicitSegmentId) return null;
2508
+ const jsonX = JSONX.getInstance();
2509
+ const actions = [jsonX.removeOp([
2510
+ "body",
2511
+ "sectionBreaks",
2512
+ storageIndex,
2513
+ key
2514
+ ], explicitSegmentId)];
2515
+ const referenceKeys = kind === "header" ? [
2516
+ "defaultHeaderId",
2517
+ "firstPageHeaderId",
2518
+ "evenPageHeaderId"
2519
+ ] : [
2520
+ "defaultFooterId",
2521
+ "firstPageFooterId",
2522
+ "evenPageFooterId"
2523
+ ];
2524
+ const referencedByDocument = referenceKeys.some((referenceKey) => snapshot.documentStyle[referenceKey] === explicitSegmentId);
2525
+ const referencedBySection = sections.some((item) => referenceKeys.some((referenceKey) => !(item.sectionId === section.sectionId && referenceKey === key) && item[referenceKey] === explicitSegmentId));
2526
+ const resources = kind === "header" ? snapshot.headers : snapshot.footers;
2527
+ if (!referencedByDocument && !referencedBySection && (resources === null || resources === void 0 ? void 0 : resources[explicitSegmentId])) actions.push(jsonX.removeOp([kind === "header" ? "headers" : "footers", explicitSegmentId], resources[explicitSegmentId]));
2528
+ return actions;
2529
+ }
2530
+ function buildUnlinkActions(context, kind, requestedSegmentId) {
2531
+ const { snapshot, sections, sectionIndex, storageIndex, key } = context;
2532
+ const explicitSegmentId = sections[sectionIndex][key];
2533
+ if (typeof explicitSegmentId === "string" && explicitSegmentId) return null;
2534
+ const sourceSegmentId = resolveSectionHeaderFooterReference(snapshot.documentStyle, sections, sectionIndex - 1, key).segmentId;
2535
+ const segmentId = requestedSegmentId ?? generateRandomId(6);
2536
+ const resources = kind === "header" ? snapshot.headers : snapshot.footers;
2537
+ if (resources === null || resources === void 0 ? void 0 : resources[segmentId]) return null;
2538
+ const source = sourceSegmentId ? resources === null || resources === void 0 ? void 0 : resources[sourceSegmentId] : void 0;
2539
+ const idKey = kind === "header" ? "headerId" : "footerId";
2540
+ const resource = source ? {
2541
+ ...Tools.deepClone(source),
2542
+ [idKey]: segmentId
2543
+ } : {
2544
+ [idKey]: segmentId,
2545
+ body: getEmptyHeaderFooterBody()
2546
+ };
2547
+ const jsonX = JSONX.getInstance();
2548
+ return [jsonX.insertOp([kind === "header" ? "headers" : "footers", segmentId], resource), jsonX.insertOp([
2549
+ "body",
2550
+ "sectionBreaks",
2551
+ storageIndex,
2552
+ key
2553
+ ], segmentId)];
2554
+ }
2555
+
2556
+ //#endregion
2557
+ //#region src/commands/commands/update-document-paragraph-style.command.ts
2558
+ function isValidParams(params) {
2559
+ 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);
2560
+ }
2561
+ function getCurrentParagraph(body, params) {
2562
+ const matches = (body.paragraphs ?? []).filter((paragraph) => paragraph.paragraphId === params.paragraphId);
2563
+ if (matches.length !== 1) return null;
2564
+ const paragraph = matches[0];
2565
+ return getParagraphContentStartOffset(body, paragraph) === params.startOffset && paragraph.startIndex === params.endOffset && body.dataStream[params.endOffset] === "\r" ? paragraph : null;
2566
+ }
2567
+ function createParagraphStyleTextX(body, paragraph, params) {
2568
+ const textX = new TextX();
2569
+ const initializesTextRuns = Boolean(params.style.textStyle && params.startOffset < params.endOffset && body.textRuns == null);
2570
+ if (params.startOffset > 0) textX.push({
2571
+ t: TextXActionType.RETAIN,
2572
+ len: params.startOffset
2573
+ });
2574
+ if (params.style.textStyle && params.startOffset < params.endOffset && !initializesTextRuns) textX.push({
2575
+ t: TextXActionType.RETAIN,
2576
+ len: params.endOffset - params.startOffset,
2577
+ coverType: UpdateDocsAttributeType.COVER,
2578
+ body: {
2579
+ dataStream: "",
2580
+ textRuns: [{
2581
+ st: 0,
2582
+ ed: params.endOffset - params.startOffset,
2583
+ ts: Tools.deepClone(params.style.textStyle)
2584
+ }]
2585
+ }
2586
+ });
2587
+ else if (params.startOffset < params.endOffset) textX.push({
2588
+ t: TextXActionType.RETAIN,
2589
+ len: params.endOffset - params.startOffset
2590
+ });
2591
+ const paragraphBody = {
2592
+ dataStream: "",
2593
+ paragraphs: [{
2594
+ ...Tools.deepClone(paragraph),
2595
+ startIndex: 0,
2596
+ paragraphStyle: {
2597
+ ...Tools.deepClone(paragraph.paragraphStyle ?? {}),
2598
+ ...Tools.deepClone(params.style)
2599
+ }
2600
+ }]
2601
+ };
2602
+ Object.defineProperty(paragraphBody, RESTORE_INSERTED_PARAGRAPH_IDS, {
2603
+ value: true,
2604
+ enumerable: true
2605
+ });
2606
+ textX.push({
2607
+ t: TextXActionType.RETAIN,
2608
+ len: 1,
2609
+ coverType: UpdateDocsAttributeType.REPLACE,
2610
+ body: paragraphBody
2611
+ });
2612
+ return {
2613
+ textX,
2614
+ initializesTextRuns
2615
+ };
2616
+ }
2617
+ const UpdateDocumentParagraphStyleCommand = {
2618
+ id: "doc.command.update-paragraph-style",
2439
2619
  type: CommandType.COMMAND,
2440
2620
  handler: (accessor, params) => {
2441
- var _body$sectionBreaks;
2442
- if (!params) return false;
2443
- const context = getTraditionalDocumentContext(accessor, params.unitId);
2444
- if (!context || !params.sectionId || !Number.isInteger(params.offset) || params.nextSectionType != null && !isValidEnumValue(SectionType, params.nextSectionType)) return false;
2445
- const { body, documentDataModel, commandService } = context;
2446
- const insertedSection = {
2447
- ...Tools.deepClone(params.config ?? {}),
2448
- sectionId: params.sectionId,
2449
- startIndex: params.offset
2450
- };
2451
- 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;
2452
- const nextSection = params.nextSectionType == null ? void 0 : getTopLevelSectionBreaks(body).find((section) => section.startIndex >= params.offset);
2453
- if (params.nextSectionType != null && !nextSection) return false;
2454
- const textX = new TextX();
2455
- textX.retain(params.offset);
2456
- textX.insert(1, {
2457
- dataStream: DataStreamTreeTokenType.SECTION_BREAK,
2458
- sectionBreaks: [{
2459
- ...insertedSection,
2460
- startIndex: 0
2461
- }]
2462
- });
2463
- if (nextSection && params.nextSectionType != null) {
2464
- textX.retain(nextSection.startIndex - params.offset);
2465
- textX.push({
2466
- t: TextXActionType.RETAIN,
2467
- len: 1,
2468
- coverType: UpdateDocsAttributeType.REPLACE,
2469
- body: {
2470
- dataStream: "",
2471
- sectionBreaks: [{
2472
- ...Tools.deepClone(nextSection),
2473
- sectionType: params.nextSectionType,
2474
- startIndex: 0
2475
- }]
2476
- }
2477
- });
2621
+ var _documentDataModel$ge;
2622
+ if (!isValidParams(params)) return false;
2623
+ const instanceService = accessor.get(IUniverInstanceService);
2624
+ const commandService = accessor.get(ICommandService);
2625
+ const documentDataModel = instanceService.getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
2626
+ const segmentId = params.segmentId ?? "";
2627
+ const body = documentDataModel === null || documentDataModel === void 0 || (_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.getBody();
2628
+ if (!documentDataModel || !body) return false;
2629
+ const paragraph = getCurrentParagraph(body, params);
2630
+ if (!paragraph) return false;
2631
+ const { textX, initializesTextRuns } = createParagraphStyleTextX(body, paragraph, params);
2632
+ const jsonX = JSONX.getInstance();
2633
+ const path = getRichTextEditPath(documentDataModel, segmentId);
2634
+ let actions = jsonX.editOp(textX.serialize(), path);
2635
+ if (initializesTextRuns) {
2636
+ const initializeTextRunsActions = jsonX.replaceOp([...path, "textRuns"], void 0, [{
2637
+ st: params.startOffset,
2638
+ ed: params.endOffset,
2639
+ ts: Tools.deepClone(params.style.textStyle)
2640
+ }]);
2641
+ actions = JSONX.compose(initializeTextRunsActions, actions);
2478
2642
  }
2479
- return executeSectionTextX(commandService, documentDataModel, textX, InsertDocumentSectionBreakCommand.id);
2643
+ return Boolean(commandService.syncExecuteCommand(RichTextEditingMutation.id, {
2644
+ unitId: params.unitId,
2645
+ segmentId,
2646
+ actions,
2647
+ textRanges: null,
2648
+ noNeedSetTextRange: true,
2649
+ isEditing: false,
2650
+ trigger: UpdateDocumentParagraphStyleCommand.id
2651
+ }));
2480
2652
  }
2481
2653
  };
2482
- const InsertDocumentColumnBreakCommand = {
2483
- id: "doc.command.insert-column-break",
2484
- type: CommandType.COMMAND,
2485
- handler: (accessor, params) => {
2486
- if (!params) return false;
2487
- const context = getTraditionalDocumentContext(accessor, params.unitId);
2488
- if (!context || !isValidTopLevelInsertionOffset(context.body, params.offset)) return false;
2489
- const textX = new TextX();
2490
- textX.retain(params.offset);
2654
+
2655
+ //#endregion
2656
+ //#region src/utils/section-columns.ts
2657
+ function resolveSectionValue(sectionValue, documentValue, fallback) {
2658
+ return sectionValue ?? documentValue ?? fallback;
2659
+ }
2660
+ function getEffectivePageSize(documentStyle, section) {
2661
+ var _section$pageSize, _documentStyle$pageSi, _section$pageSize2, _documentStyle$pageSi2;
2662
+ const fallback = PAGE_SIZE[PaperType.A4];
2663
+ return {
2664
+ 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),
2665
+ 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)
2666
+ };
2667
+ }
2668
+ function getEffectiveMargins(documentStyle, section) {
2669
+ return {
2670
+ top: resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginTop, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginTop, TRADITIONAL_DOCUMENT_DEFAULT_MARGIN),
2671
+ bottom: resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginBottom, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginBottom, TRADITIONAL_DOCUMENT_DEFAULT_MARGIN),
2672
+ left: resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginLeft, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginLeft, TRADITIONAL_DOCUMENT_DEFAULT_MARGIN),
2673
+ right: resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginRight, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginRight, TRADITIONAL_DOCUMENT_DEFAULT_MARGIN)
2674
+ };
2675
+ }
2676
+ function assertPositivePageSetup(pageSize, contentSize) {
2677
+ if (![
2678
+ pageSize.width,
2679
+ pageSize.height,
2680
+ contentSize.width,
2681
+ contentSize.height
2682
+ ].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.");
2683
+ }
2684
+ /** Resolves nominal traditional page geometry without requiring a renderer. */
2685
+ function getEffectiveSectionPageSetup(documentStyle, section) {
2686
+ const pageSize = getEffectivePageSize(documentStyle, section);
2687
+ const margins = getEffectiveMargins(documentStyle, section);
2688
+ const contentSize = {
2689
+ width: getSectionContentWidth(documentStyle, section),
2690
+ height: pageSize.height - margins.top - margins.bottom
2691
+ };
2692
+ assertPositivePageSetup(pageSize, contentSize);
2693
+ const pageNumberStart = (section === null || section === void 0 ? void 0 : section.pageNumberStart) ?? (documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.pageNumberStart);
2694
+ return {
2695
+ pageSize,
2696
+ pageOrient: resolveSectionValue(section === null || section === void 0 ? void 0 : section.pageOrient, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.pageOrient, PageOrientType.PORTRAIT),
2697
+ margins,
2698
+ contentSize,
2699
+ ...pageNumberStart == null ? {} : { pageNumberStart }
2700
+ };
2701
+ }
2702
+ /** Returns the usable horizontal layout width for a traditional section. */
2703
+ function getSectionContentWidth(documentStyle, section) {
2704
+ var _section$pageSize3, _documentStyle$pageSi3;
2705
+ 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, PAGE_SIZE[PaperType.A4].width);
2706
+ return Math.max(0, pageWidth - resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginLeft, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginLeft, TRADITIONAL_DOCUMENT_DEFAULT_MARGIN) - resolveSectionValue(section === null || section === void 0 ? void 0 : section.marginRight, documentStyle === null || documentStyle === void 0 ? void 0 : documentStyle.marginRight, TRADITIONAL_DOCUMENT_DEFAULT_MARGIN));
2707
+ }
2708
+ /** Creates explicit OOXML section columns from a count, gap, and optional widths. */
2709
+ function createSectionColumnProperties(documentStyle, section, columnCount, gap, widths) {
2710
+ if (columnCount <= 1) return [];
2711
+ const safeGap = Math.max(0, gap);
2712
+ const contentWidth = getSectionContentWidth(documentStyle, section);
2713
+ const availableWidth = Math.max(0, contentWidth - safeGap * (columnCount - 1));
2714
+ if (widths) {
2715
+ if (widths.some((width) => !Number.isFinite(width) || width < 0)) throw new RangeError("Section column widths must be finite and non-negative.");
2716
+ if (widths.reduce((sum, width) => sum + width, 0) > availableWidth) throw new RangeError("Section columns exceed the available page content width.");
2717
+ }
2718
+ return (widths ?? Array.from({ length: columnCount }, () => availableWidth / columnCount)).map((width, index) => ({
2719
+ width: Math.max(0, width),
2720
+ paddingEnd: index === columnCount - 1 ? 0 : safeGap
2721
+ }));
2722
+ }
2723
+
2724
+ //#endregion
2725
+ //#region src/commands/commands/update-document-section.command.ts
2726
+ const UpdateDocumentSectionCommand = {
2727
+ id: "doc.command.update-section",
2728
+ type: CommandType.COMMAND,
2729
+ handler: (accessor, params) => {
2730
+ if (!(params === null || params === void 0 ? void 0 : params.updates.length) || params.updates.some(({ sectionId, config }) => !sectionId || Object.keys(config).length === 0)) return false;
2731
+ const instanceService = accessor.get(IUniverInstanceService);
2732
+ const commandService = accessor.get(ICommandService);
2733
+ const documentDataModel = instanceService.getUnit(params.unitId, UniverInstanceType.UNIVER_DOC);
2734
+ if (!documentDataModel || documentDataModel.getDocumentStyle().documentFlavor !== DocumentFlavor.TRADITIONAL) return false;
2735
+ const body = documentDataModel.getBody();
2736
+ if (!body) return false;
2737
+ const updates = new Map(params.updates.map(({ sectionId, config }) => [sectionId, config]));
2738
+ if (updates.size !== params.updates.length) return false;
2739
+ const selectedIds = new Set(updates.keys());
2740
+ const sections = getTopLevelSectionBreaks(body).filter((section) => selectedIds.has(section.sectionId)).sort((left, right) => left.startIndex - right.startIndex);
2741
+ if (sections.length !== selectedIds.size) return false;
2742
+ const documentStyle = documentDataModel.getDocumentStyle();
2743
+ if (sections.some((section) => !isValidSectionConfig({
2744
+ ...section,
2745
+ ...updates.get(section.sectionId)
2746
+ }, documentStyle))) return false;
2747
+ const cursor = new MemoryCursor();
2748
+ const textX = new TextX();
2749
+ for (const section of sections) {
2750
+ textX.push({
2751
+ t: TextXActionType.RETAIN,
2752
+ len: section.startIndex - cursor.cursor
2753
+ });
2754
+ textX.push({
2755
+ t: TextXActionType.RETAIN,
2756
+ len: 1,
2757
+ coverType: UpdateDocsAttributeType.REPLACE,
2758
+ body: {
2759
+ dataStream: "",
2760
+ sectionBreaks: [{
2761
+ ...Tools.deepClone(section),
2762
+ ...Tools.deepClone(updates.get(section.sectionId)),
2763
+ sectionId: section.sectionId,
2764
+ startIndex: 0
2765
+ }]
2766
+ }
2767
+ });
2768
+ cursor.moveCursorTo(section.startIndex + 1);
2769
+ }
2770
+ const jsonX = JSONX.getInstance();
2771
+ const mutation = {
2772
+ id: RichTextEditingMutation.id,
2773
+ params: {
2774
+ unitId: params.unitId,
2775
+ actions: jsonX.editOp(textX.serialize(), getRichTextEditPath(documentDataModel)),
2776
+ textRanges: null,
2777
+ noNeedSetTextRange: true,
2778
+ debounce: true,
2779
+ isEditing: false,
2780
+ trigger: UpdateDocumentSectionCommand.id
2781
+ }
2782
+ };
2783
+ return Boolean(commandService.syncExecuteCommand(mutation.id, mutation.params));
2784
+ }
2785
+ };
2786
+ const InsertDocumentSectionBreakCommand = {
2787
+ id: "doc.command.insert-section-break",
2788
+ type: CommandType.COMMAND,
2789
+ handler: (accessor, params) => {
2790
+ var _body$sectionBreaks;
2791
+ if (!params) return false;
2792
+ const context = getTraditionalDocumentContext(accessor, params.unitId);
2793
+ if (!context || !params.sectionId || !Number.isInteger(params.offset) || params.nextSectionType != null && !isValidEnumValue(SectionType, params.nextSectionType)) return false;
2794
+ const { body, documentDataModel, commandService } = context;
2795
+ const insertedSection = {
2796
+ ...Tools.deepClone(params.config ?? {}),
2797
+ sectionId: params.sectionId,
2798
+ startIndex: params.offset
2799
+ };
2800
+ 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;
2801
+ const nextSection = params.nextSectionType == null ? void 0 : getTopLevelSectionBreaks(body).find((section) => section.startIndex >= params.offset);
2802
+ if (params.nextSectionType != null && !nextSection) return false;
2803
+ const textX = new TextX();
2804
+ textX.retain(params.offset);
2805
+ textX.insert(1, {
2806
+ dataStream: DataStreamTreeTokenType.SECTION_BREAK,
2807
+ sectionBreaks: [{
2808
+ ...insertedSection,
2809
+ startIndex: 0
2810
+ }]
2811
+ });
2812
+ if (nextSection && params.nextSectionType != null) {
2813
+ textX.retain(nextSection.startIndex - params.offset);
2814
+ textX.push({
2815
+ t: TextXActionType.RETAIN,
2816
+ len: 1,
2817
+ coverType: UpdateDocsAttributeType.REPLACE,
2818
+ body: {
2819
+ dataStream: "",
2820
+ sectionBreaks: [{
2821
+ ...Tools.deepClone(nextSection),
2822
+ sectionType: params.nextSectionType,
2823
+ startIndex: 0
2824
+ }]
2825
+ }
2826
+ });
2827
+ }
2828
+ return executeSectionTextX(commandService, documentDataModel, textX, InsertDocumentSectionBreakCommand.id);
2829
+ }
2830
+ };
2831
+ const InsertDocumentColumnBreakCommand = {
2832
+ id: "doc.command.insert-column-break",
2833
+ type: CommandType.COMMAND,
2834
+ handler: (accessor, params) => {
2835
+ if (!params) return false;
2836
+ const context = getTraditionalDocumentContext(accessor, params.unitId);
2837
+ if (!context || !isValidTopLevelInsertionOffset(context.body, params.offset)) return false;
2838
+ const textX = new TextX();
2839
+ textX.retain(params.offset);
2491
2840
  textX.insert(1, {
2492
2841
  dataStream: DataStreamTreeTokenType.COLUMN_BREAK,
2493
2842
  customRanges: [{
@@ -2786,7 +3135,7 @@ function composeActions(actions) {
2786
3135
  //#endregion
2787
3136
  //#region package.json
2788
3137
  var name = "@univerjs/docs";
2789
- var version = "1.0.4";
3138
+ var version = "1.2.0";
2790
3139
 
2791
3140
  //#endregion
2792
3141
  //#region src/config/config.ts
@@ -2864,270 +3213,6 @@ DocCustomRangeController = __decorate([
2864
3213
  __decorateParam(2, IUniverInstanceService)
2865
3214
  ], DocCustomRangeController);
2866
3215
 
2867
- //#endregion
2868
- //#region src/services/permission/document-permission-resolver.ts
2869
- const HEADER_FOOTER_REFERENCE_KEYS = [
2870
- "defaultHeaderId",
2871
- "defaultFooterId",
2872
- "firstPageHeaderId",
2873
- "firstPageFooterId",
2874
- "evenPageHeaderId",
2875
- "evenPageFooterId"
2876
- ];
2877
- const documentPermissionResolverIndexCache = /* @__PURE__ */ new WeakMap();
2878
- function getDocumentPermissionResolverIndex(documentDataModel) {
2879
- var _getMutationRevision, _snapshot$body;
2880
- const mutationRevision = ((_getMutationRevision = documentDataModel.getMutationRevision) === null || _getMutationRevision === void 0 ? void 0 : _getMutationRevision.call(documentDataModel)) ?? NaN;
2881
- const cached = documentPermissionResolverIndexCache.get(documentDataModel);
2882
- if ((cached === null || cached === void 0 ? void 0 : cached.mutationRevision) === mutationRevision) return cached;
2883
- const snapshot = documentDataModel.getSnapshot();
2884
- const topLevelSections = snapshot.body ? getTopLevelSectionBreaks(snapshot.body) : [];
2885
- const drawingSegmentIds = /* @__PURE__ */ new Map();
2886
- const addDrawingSegments = (body, segmentId) => {
2887
- for (const block of (body === null || body === void 0 ? void 0 : body.customBlocks) ?? []) if (!drawingSegmentIds.has(block.blockId)) drawingSegmentIds.set(block.blockId, segmentId);
2888
- };
2889
- addDrawingSegments(snapshot.body, "");
2890
- Object.entries(snapshot.headers ?? {}).forEach(([segmentId, header]) => addDrawingSegments(header.body, segmentId));
2891
- Object.entries(snapshot.footers ?? {}).forEach(([segmentId, footer]) => addDrawingSegments(footer.body, segmentId));
2892
- Object.entries(snapshot.notes ?? {}).forEach(([segmentId, footnote]) => addDrawingSegments(footnote.body, segmentId));
2893
- const footnoteReferenceRanges = /* @__PURE__ */ new Map();
2894
- for (const reference of ((_snapshot$body = snapshot.body) === null || _snapshot$body === void 0 ? void 0 : _snapshot$body.customRanges) ?? []) {
2895
- var _reference$properties;
2896
- if ((reference.rangeType === CustomRangeType.FOOTNOTE || reference.rangeType === CustomRangeType.ENDNOTE) && typeof ((_reference$properties = reference.properties) === null || _reference$properties === void 0 ? void 0 : _reference$properties.noteId) === "string") footnoteReferenceRanges.set(reference.properties.noteId, {
2897
- startOffset: reference.startIndex,
2898
- endOffset: reference.endIndex + 1
2899
- });
2900
- }
2901
- const index = {
2902
- drawingSegmentIds,
2903
- footnoteReferenceRanges,
2904
- mutationRevision,
2905
- segments: /* @__PURE__ */ new Map(),
2906
- topLevelSections
2907
- };
2908
- documentPermissionResolverIndexCache.set(documentDataModel, index);
2909
- return index;
2910
- }
2911
- function getDocumentPermissionSegmentIndex(documentDataModel, segmentId, resolverIndex = getDocumentPermissionResolverIndex(documentDataModel)) {
2912
- var _documentDataModel$ge, _snapshot$notes;
2913
- const cached = resolverIndex.segments.get(segmentId);
2914
- if (cached) return cached;
2915
- const body = ((_documentDataModel$ge = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge === void 0 ? void 0 : _documentDataModel$ge.getBody()) ?? null;
2916
- const snapshot = documentDataModel.getSnapshot();
2917
- const note = (_snapshot$notes = snapshot.notes) === null || _snapshot$notes === void 0 ? void 0 : _snapshot$notes[segmentId];
2918
- const drawings = (note ? note.drawings : snapshot.drawings) ?? {};
2919
- const entities = body == null ? [] : [
2920
- ...(body.tables ?? []).map((item) => ({
2921
- type: "table",
2922
- id: item.tableId,
2923
- startOffset: item.startIndex,
2924
- endOffset: item.endIndex
2925
- })),
2926
- ...(body.customBlocks ?? []).map((item) => ({
2927
- type: drawings[item.blockId] ? "drawing" : "custom-block",
2928
- id: item.blockId,
2929
- startOffset: item.startIndex,
2930
- endOffset: item.startIndex + 1
2931
- })),
2932
- ...(body.blockRanges ?? []).map((item) => ({
2933
- type: "block-range",
2934
- id: item.blockId,
2935
- startOffset: item.startIndex,
2936
- endOffset: item.endIndex + 1
2937
- })),
2938
- ...(body.customRanges ?? []).map((item) => ({
2939
- type: "custom-range",
2940
- id: item.rangeId,
2941
- startOffset: item.startIndex,
2942
- endOffset: item.endIndex + 1
2943
- })),
2944
- ...(body.columnGroups ?? []).map((item) => ({
2945
- type: "column-group",
2946
- id: item.columnGroupId,
2947
- startOffset: item.startIndex,
2948
- endOffset: item.endIndex + 1
2949
- }))
2950
- ];
2951
- const entityRanges = new Map(entities.map((entity) => [`${entity.type}:${entity.id}`, {
2952
- startOffset: entity.startOffset,
2953
- endOffset: entity.endOffset
2954
- }]));
2955
- for (const block of (body === null || body === void 0 ? void 0 : body.customBlocks) ?? []) {
2956
- const range = {
2957
- startOffset: block.startIndex,
2958
- endOffset: block.startIndex + 1
2959
- };
2960
- entityRanges.set(`custom-block:${block.blockId}`, range);
2961
- entityRanges.set(`drawing:${block.blockId}`, range);
2962
- }
2963
- const segmentIndex = {
2964
- body,
2965
- entities,
2966
- entityRanges,
2967
- paragraphContentStartOffsets: body == null ? /* @__PURE__ */ new Map() : getParagraphContentStartOffsets(body),
2968
- paragraphsById: new Map(((body === null || body === void 0 ? void 0 : body.paragraphs) ?? []).filter((paragraph) => paragraph.paragraphId != null).map((paragraph) => [paragraph.paragraphId, paragraph]))
2969
- };
2970
- resolverIndex.segments.set(segmentId, segmentIndex);
2971
- return segmentIndex;
2972
- }
2973
- function getDocumentDrawingSegmentId(documentDataModel, drawingId) {
2974
- return getDocumentPermissionResolverIndex(documentDataModel).drawingSegmentIds.get(drawingId) ?? "";
2975
- }
2976
- function getDocumentEditTargetObjectIds(documentDataModel, segmentId, range) {
2977
- const resolverIndex = getDocumentPermissionResolverIndex(documentDataModel);
2978
- const segmentIndex = getDocumentPermissionSegmentIndex(documentDataModel, segmentId, resolverIndex);
2979
- const { body } = segmentIndex;
2980
- if (!body) return [];
2981
- return [
2982
- ...getSectionPermissionObjectIds(documentDataModel, segmentId, range, resolverIndex),
2983
- ...getParagraphPermissionObjectIds(body, segmentId, range, segmentIndex),
2984
- ...getEntityPermissionObjectIds(segmentId, range, segmentIndex)
2985
- ];
2986
- }
2987
- function getDocumentEditTargetObjectIdsFromActions(documentDataModel, segmentId, actions) {
2988
- const result = /* @__PURE__ */ new Set();
2989
- if (actions == null) return [];
2990
- const cursor = JSON1.type.readCursor(actions);
2991
- cursor.traverse(null, () => {
2992
- const path = cursor.getPath();
2993
- const edit = cursor.getComponent();
2994
- const scopedSegment = [
2995
- "headers",
2996
- "footers",
2997
- "notes"
2998
- ].includes(String(path[0])) && typeof path[1] === "string" ? path[1] : segmentId;
2999
- if (path[0] === "notes" && typeof path[1] === "string") getSectionPermissionObjectIds(documentDataModel, path[1], {
3000
- startOffset: 0,
3001
- endOffset: 0
3002
- }).forEach((objectId) => result.add(objectId));
3003
- if (path[0] === "noteSettings") getDocumentPermissionResolverIndex(documentDataModel).topLevelSections.forEach((section) => {
3004
- result.add(getDocumentSectionPermissionObjectId("", section.sectionId));
3005
- });
3006
- if (path[0] === "body" && path[1] === "sectionBreaks" && typeof path[2] === "number" && (path[3] === "noteProperties" || path[3] === "suppressEndnotes")) {
3007
- var _documentDataModel$ge2;
3008
- const sectionId = (_documentDataModel$ge2 = documentDataModel.getBody()) === null || _documentDataModel$ge2 === void 0 || (_documentDataModel$ge2 = _documentDataModel$ge2.sectionBreaks) === null || _documentDataModel$ge2 === void 0 || (_documentDataModel$ge2 = _documentDataModel$ge2[path[2]]) === null || _documentDataModel$ge2 === void 0 ? void 0 : _documentDataModel$ge2.sectionId;
3009
- if (sectionId) result.add(getDocumentSectionPermissionObjectId("", sectionId));
3010
- }
3011
- if (path[path.length - 1] !== "body" || (edit === null || edit === void 0 ? void 0 : edit.et) !== TextX.id || !Array.isArray(edit.e) || !edit.e.every(isTextXAction)) return;
3012
- const textActions = edit.e;
3013
- let offset = 0;
3014
- const addRange = (startOffset, endOffset) => {
3015
- getDocumentEditTargetObjectIds(documentDataModel, scopedSegment, {
3016
- startOffset,
3017
- endOffset
3018
- }).forEach((objectId) => result.add(objectId));
3019
- };
3020
- textActions.forEach((action) => {
3021
- if (action.t === TextXActionType.INSERT) {
3022
- addRange(offset, offset);
3023
- return;
3024
- }
3025
- if (action.t === TextXActionType.DELETE) {
3026
- addRange(offset, offset + action.len);
3027
- offset += action.len;
3028
- return;
3029
- }
3030
- if (action.body !== void 0 || action.oldBody !== void 0 || action.coverType !== void 0) addRange(offset, offset + action.len);
3031
- offset += action.len;
3032
- });
3033
- });
3034
- getDrawingIdsFromActions(actions).forEach((drawingId) => {
3035
- var _documentDataModel$ge3, _body$customBlocks;
3036
- result.add(getDocumentEntityPermissionObjectId(segmentId, "drawing", drawingId));
3037
- const body = (_documentDataModel$ge3 = documentDataModel.getSelfOrHeaderFooterModel(segmentId)) === null || _documentDataModel$ge3 === void 0 ? void 0 : _documentDataModel$ge3.getBody();
3038
- const block = body === null || body === void 0 || (_body$customBlocks = body.customBlocks) === null || _body$customBlocks === void 0 ? void 0 : _body$customBlocks.find((item) => item.blockId === drawingId);
3039
- if (block) getSectionPermissionObjectIds(documentDataModel, segmentId, {
3040
- startOffset: block.startIndex,
3041
- endOffset: block.startIndex + 1
3042
- }).forEach((objectId) => result.add(objectId));
3043
- });
3044
- return [...result];
3045
- }
3046
- function getDrawingIdsFromActions(actions) {
3047
- const result = /* @__PURE__ */ new Set();
3048
- const visit = (value) => {
3049
- if (Array.isArray(value)) {
3050
- value.forEach((item, index) => {
3051
- if (item === "drawings" && typeof value[index + 1] === "string") result.add(value[index + 1]);
3052
- visit(item);
3053
- });
3054
- return;
3055
- }
3056
- if (!isRecord$2(value)) return;
3057
- Object.values(value).forEach(visit);
3058
- };
3059
- visit(actions);
3060
- return [...result];
3061
- }
3062
- function isTextXAction(value) {
3063
- if (!isRecord$2(value) || typeof value.len !== "number") return false;
3064
- if (value.t === TextXActionType.INSERT) return isRecord$2(value.body);
3065
- return value.t === TextXActionType.RETAIN || value.t === TextXActionType.DELETE;
3066
- }
3067
- function isRecord$2(value) {
3068
- return typeof value === "object" && value !== null && !Array.isArray(value);
3069
- }
3070
- function getDocumentEntityParentPermissionObjectIds(documentDataModel, segmentId, entityType, entityId) {
3071
- const resolverIndex = getDocumentPermissionResolverIndex(documentDataModel);
3072
- const range = getDocumentPermissionSegmentIndex(documentDataModel, segmentId, resolverIndex).entityRanges.get(`${entityType}:${entityId}`) ?? null;
3073
- return range ? getSectionPermissionObjectIds(documentDataModel, segmentId, range, resolverIndex) : [];
3074
- }
3075
- function getDocumentParagraphParentPermissionObjectIds(documentDataModel, segmentId, paragraphId) {
3076
- const resolverIndex = getDocumentPermissionResolverIndex(documentDataModel);
3077
- const segmentIndex = getDocumentPermissionSegmentIndex(documentDataModel, segmentId, resolverIndex);
3078
- const { body } = segmentIndex;
3079
- const paragraph = segmentIndex.paragraphsById.get(paragraphId);
3080
- if (!body || !paragraph) return [];
3081
- return getSectionPermissionObjectIds(documentDataModel, segmentId, {
3082
- startOffset: segmentIndex.paragraphContentStartOffsets.get(paragraph.startIndex) ?? getParagraphContentStartOffset(body, paragraph),
3083
- endOffset: paragraph.startIndex + 1
3084
- }, resolverIndex);
3085
- }
3086
- function getDocumentSectionPermissionObjectIdsByIds(sectionIds) {
3087
- return Array.from(sectionIds, (sectionId) => getDocumentSectionPermissionObjectId("", sectionId));
3088
- }
3089
- function getDocumentSectionIdsAtOffset(body, offset) {
3090
- return getSectionsIntersectingRange(getTopLevelSectionBreaks(body), {
3091
- startOffset: offset,
3092
- endOffset: offset
3093
- }).map((section) => section.sectionId);
3094
- }
3095
- function getSectionPermissionObjectIds(documentDataModel, segmentId, range, resolverIndex = getDocumentPermissionResolverIndex(documentDataModel)) {
3096
- if (segmentId) {
3097
- const referenceRange = resolverIndex.footnoteReferenceRanges.get(segmentId);
3098
- if (referenceRange) return getDocumentEditTargetObjectIds(documentDataModel, "", referenceRange);
3099
- return getHeaderFooterOwnerSectionIds(documentDataModel, segmentId, resolverIndex.topLevelSections).map((sectionId) => getDocumentSectionPermissionObjectId("", sectionId));
3100
- }
3101
- return getSectionsIntersectingRange(resolverIndex.topLevelSections, range).map((section) => getDocumentSectionPermissionObjectId("", section.sectionId));
3102
- }
3103
- function getParagraphPermissionObjectIds(body, segmentId, range, segmentIndex) {
3104
- const startOffset = Math.min(range.startOffset, range.endOffset);
3105
- const endOffset = Math.max(range.startOffset, range.endOffset);
3106
- return (body.paragraphs ?? []).filter((paragraph) => intersectsRange(segmentIndex.paragraphContentStartOffsets.get(paragraph.startIndex) ?? getParagraphContentStartOffset(body, paragraph), paragraph.startIndex + 1, startOffset, endOffset)).flatMap((paragraph) => paragraph.paragraphId ? [getDocumentParagraphPermissionObjectId(segmentId, paragraph.paragraphId)] : []);
3107
- }
3108
- function getEntityPermissionObjectIds(segmentId, range, segmentIndex) {
3109
- const startOffset = Math.min(range.startOffset, range.endOffset);
3110
- const endOffset = Math.max(range.startOffset, range.endOffset);
3111
- return segmentIndex.entities.filter((item) => intersectsRange(item.startOffset, item.endOffset, startOffset, endOffset)).map((item) => getDocumentEntityPermissionObjectId(segmentId, item.type, item.id));
3112
- }
3113
- function getSectionsIntersectingRange(sections, range) {
3114
- const startOffset = Math.min(range.startOffset, range.endOffset);
3115
- const endOffset = Math.max(range.startOffset, range.endOffset);
3116
- return sections.filter((section, index) => intersectsRange(index === 0 ? 0 : sections[index - 1].startIndex + 1, section.startIndex + 1, startOffset, endOffset));
3117
- }
3118
- function intersectsRange(targetStart, targetEnd, rangeStart, rangeEnd) {
3119
- if (rangeStart === rangeEnd) return rangeStart >= targetStart && rangeStart < targetEnd;
3120
- return rangeStart < targetEnd && rangeEnd > targetStart;
3121
- }
3122
- function getHeaderFooterOwnerSectionIds(documentDataModel, segmentId, sections = getDocumentPermissionResolverIndex(documentDataModel).topLevelSections) {
3123
- const snapshot = documentDataModel.getSnapshot();
3124
- const result = /* @__PURE__ */ new Set();
3125
- sections.forEach((section, sectionIndex) => {
3126
- if (HEADER_FOOTER_REFERENCE_KEYS.some((key) => resolveSectionHeaderFooterReference(snapshot.documentStyle, sections, sectionIndex, key).segmentId === segmentId)) result.add(section.sectionId);
3127
- });
3128
- return [...result];
3129
- }
3130
-
3131
3216
  //#endregion
3132
3217
  //#region src/controllers/doc-permission.controller.ts
3133
3218
  const NON_EDIT_DOCUMENT_COMMAND_IDS = /* @__PURE__ */ new Set([
@@ -3704,6 +3789,7 @@ let UniverDocsPlugin = class UniverDocsPlugin extends Plugin {
3704
3789
  SetDocumentPermissionsCommand,
3705
3790
  SetDocumentDefaultParagraphStyleCommand,
3706
3791
  SetDocumentNameCommand,
3792
+ SetHeadingCollapsedCommand,
3707
3793
  SetSectionHeaderFooterLinkCommand,
3708
3794
  UpdateDocumentParagraphStyleCommand,
3709
3795
  UpdateDocumentSectionCommand,
@@ -4793,4 +4879,4 @@ function normalizeTextRange(textRange) {
4793
4879
  }
4794
4880
 
4795
4881
  //#endregion
4796
- export { CreateHeaderFooterCommand, DOCUMENT_UNIT_PERMISSION_ACTIONS, DOC_INTERCEPTOR_POINT, DOC_SELECTION_OPTION_PRESERVE_CARET, DeleteDocumentSectionBreakCommand, DeleteTextCommand, DocBlockMoveValidatorService, DocContentInsertService, DocHistoryAction, DocInterceptorService, DocLayoutExecutorService, DocLayoutExecutorState, DocLayoutExecutorType, DocLayoutSessionStatus, DocSelectionManagerService, DocSkeletonManagerService, DocStateChangeManagerService, DocStateEmitService, DocTextResolverService, DocsLayoutWorkerCapabilityError, DocsLayoutWorkerClientService, EMBED_DOCS_CUSTOM_BLOCK_DEFAULT_COMPONENT_KEY, HeaderFooterType, IDocStateChangeInterceptorService, InsertDocumentColumnBreakCommand, InsertDocumentSectionBreakCommand, InsertTextCommand, RichTextEditingMutation, SetDocumentDefaultParagraphStyleCommand, SetDocumentNameCommand, SetDocumentPermissionCommand, SetDocumentPermissionRuleMutation, SetDocumentPermissionRulesMutation, SetDocumentPermissionsCommand, SetSectionHeaderFooterLinkCommand, SetTextSelectionsOperation, UniverDocsLayoutWorkerPlugin, UniverDocsPlugin, UpdateDocumentParagraphStyleCommand, UpdateDocumentSectionCommand, UpdateTextCommand, addCustomRangeBySelectionFactory, addCustomRangeFactory, buildDocTransform, canEditDocumentTargets, consumeContentInsertRange, createDocsCustomBlockDrawing, createDocsCustomBlockInsertMutation, createDocsCustomBlockRemoveMutation, createDocumentPermissionPoint, createEmbedDocsCustomBlockData, createInsertCustomBlockActions, createRemoveCustomBlockActions, createSectionColumnProperties, deleteCustomRangeFactory, docDrawingPositionToTransform, generateParagraphs, getContentInsertRange, getDocumentDrawingSegmentId, getDocumentEditTargetObjectIds, getDocumentEntityParentPermissionObjectIds, getDocumentEntityPermissionObjectId, getDocumentParagraphParentPermissionObjectIds, getDocumentParagraphPermissionObjectId, getDocumentPermissionValue, getDocumentSectionPermissionObjectId, getEffectiveSectionPageSetup, getSectionContentWidth, getTopLevelSectionBreaks, isEmbedDocsCustomBlockData, isHeaderFooterSelection, isSheetLikeDocsCustomBlockChildType, normalizeTextRange, replaceSelectionFactory, resolveDocsCustomBlockSize, setDocumentPermissionValue, shouldUseInlineTextSelectionForDocsCustomBlockDrawing, startDocsLayoutWorker, transformDocumentTextRanges, transformToDocDrawingPosition };
4882
+ export { CreateHeaderFooterCommand, DOCUMENT_UNIT_PERMISSION_ACTIONS, DOC_INTERCEPTOR_POINT, DOC_SELECTION_OPTION_PRESERVE_CARET, DeleteDocumentSectionBreakCommand, DeleteTextCommand, DocBlockMoveValidatorService, DocContentInsertService, DocHistoryAction, DocInterceptorService, DocLayoutExecutorService, DocLayoutExecutorState, DocLayoutExecutorType, DocLayoutSessionStatus, DocSelectionManagerService, DocSkeletonManagerService, DocStateChangeManagerService, DocStateEmitService, DocTextResolverService, DocsLayoutWorkerCapabilityError, DocsLayoutWorkerClientService, EMBED_DOCS_CUSTOM_BLOCK_DEFAULT_COMPONENT_KEY, HeaderFooterType, IDocStateChangeInterceptorService, InsertDocumentColumnBreakCommand, InsertDocumentSectionBreakCommand, InsertTextCommand, RichTextEditingMutation, SetDocumentDefaultParagraphStyleCommand, SetDocumentNameCommand, SetDocumentPermissionCommand, SetDocumentPermissionRuleMutation, SetDocumentPermissionRulesMutation, SetDocumentPermissionsCommand, SetHeadingCollapsedCommand, SetSectionHeaderFooterLinkCommand, SetTextSelectionsOperation, UniverDocsLayoutWorkerPlugin, UniverDocsPlugin, UpdateDocumentParagraphStyleCommand, UpdateDocumentSectionCommand, UpdateTextCommand, addCustomRangeBySelectionFactory, addCustomRangeFactory, buildDocTransform, canEditDocumentTargets, consumeContentInsertRange, createDocsCustomBlockDrawing, createDocsCustomBlockInsertMutation, createDocsCustomBlockRemoveMutation, createDocumentPermissionPoint, createEmbedDocsCustomBlockData, createInsertCustomBlockActions, createRemoveCustomBlockActions, createSectionColumnProperties, deleteCustomRangeFactory, docDrawingPositionToTransform, generateParagraphs, getContentInsertRange, getDocumentDrawingSegmentId, getDocumentEditTargetObjectIds, getDocumentEntityParentPermissionObjectIds, getDocumentEntityPermissionObjectId, getDocumentParagraphParentPermissionObjectIds, getDocumentParagraphPermissionObjectId, getDocumentPermissionValue, getDocumentSectionPermissionObjectId, getEffectiveSectionPageSetup, getSectionContentWidth, getTopLevelSectionBreaks, isEmbedDocsCustomBlockData, isHeaderFooterSelection, isSheetLikeDocsCustomBlockChildType, normalizeTextRange, replaceSelectionFactory, resolveDocsCustomBlockSize, setDocumentPermissionValue, shouldUseInlineTextSelectionForDocsCustomBlockDrawing, startDocsLayoutWorker, transformDocumentTextRanges, transformToDocDrawingPosition };