@univerjs/docs 1.0.0-insiders.20260813-7c9aa50 → 1.0.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.
Files changed (55) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +0 -1
  3. package/lib/cjs/facade.js +395 -78
  4. package/lib/cjs/index.js +2734 -100
  5. package/lib/es/facade.js +390 -80
  6. package/lib/es/index.js +2703 -105
  7. package/lib/facade.js +390 -80
  8. package/lib/index.js +2703 -105
  9. package/lib/types/commands/commands/core-editing.command.d.ts +5 -1
  10. package/lib/types/commands/commands/set-document-permission.command.d.ts +27 -0
  11. package/lib/types/commands/commands/set-document-permissions.command.d.ts +17 -0
  12. package/lib/types/commands/mutations/core-editing.mutation-id.d.ts +16 -0
  13. package/lib/types/commands/mutations/core-editing.mutation.d.ts +22 -1
  14. package/lib/types/commands/mutations/doc-structure-mutation-validation.d.ts +18 -0
  15. package/lib/types/commands/mutations/set-document-permission-rule.mutation.d.ts +17 -0
  16. package/lib/types/commands/mutations/set-document-permission-rules.mutation.d.ts +17 -0
  17. package/lib/types/controllers/doc-permission.controller.d.ts +26 -0
  18. package/lib/types/facade/f-document-paragraph.d.ts +15 -2
  19. package/lib/types/facade/f-document-permission.d.ts +177 -0
  20. package/lib/types/facade/f-document-section.d.ts +43 -2
  21. package/lib/types/facade/f-document-text-range.d.ts +7 -1
  22. package/lib/types/facade/f-document.d.ts +63 -15
  23. package/lib/types/facade/f-univer.d.ts +5 -4
  24. package/lib/types/facade/index.d.ts +1 -0
  25. package/lib/types/facade/utils.d.ts +2 -1
  26. package/lib/types/index.d.ts +13 -1
  27. package/lib/types/layout-worker/config/config.d.ts +32 -0
  28. package/lib/types/layout-worker/document-font-metrics.d.ts +18 -0
  29. package/lib/types/layout-worker/font-loader.d.ts +26 -0
  30. package/lib/types/layout-worker/index.d.ts +73 -0
  31. package/lib/types/layout-worker/performance-tracker.d.ts +27 -0
  32. package/lib/types/layout-worker/protocol.d.ts +37 -0
  33. package/lib/types/layout-worker/worker.d.ts +51 -0
  34. package/lib/types/plugin.d.ts +1 -0
  35. package/lib/types/services/doc-interceptor/interceptor-const.d.ts +2 -1
  36. package/lib/types/services/doc-layout-executor.service.d.ts +224 -0
  37. package/lib/types/services/doc-selection-manager.service.d.ts +7 -1
  38. package/lib/types/services/doc-skeleton-manager.service.d.ts +6 -1
  39. package/lib/types/services/doc-state-change-manager.service.d.ts +3 -0
  40. package/lib/types/services/doc-state-emit.service.d.ts +1 -0
  41. package/lib/types/services/document-layout-snapshot.d.ts +22 -0
  42. package/lib/types/services/permission/document-permission-resolver.d.ts +27 -0
  43. package/lib/types/services/permission/document-permission-rule.model.d.ts +19 -0
  44. package/lib/types/services/permission/document-permission.d.ts +35 -0
  45. package/lib/types/services/permission/permission-point/document/comment.d.ts +27 -0
  46. package/lib/types/services/permission/permission-point/document/copy.d.ts +27 -0
  47. package/lib/types/services/permission/permission-point/document/editable.d.ts +27 -0
  48. package/lib/types/services/permission/permission-point/document/export.d.ts +27 -0
  49. package/lib/types/services/permission/permission-point/document/print.d.ts +27 -0
  50. package/lib/types/services/permission/permission-point/entity/edit.d.ts +28 -0
  51. package/lib/types/services/permission/permission-point/paragraph/edit.d.ts +28 -0
  52. package/lib/types/services/permission/permission-point/section/edit.d.ts +28 -0
  53. package/lib/umd/facade.js +3 -3
  54. package/lib/umd/index.js +2 -2
  55. package/package.json +7 -5
package/lib/es/facade.js CHANGED
@@ -1,7 +1,219 @@
1
- import { BooleanNumber, ColumnSeparatorType, DashStyleType, DataStreamTreeTokenType, DocumentFlavor, ICommandService, IResourceLoaderService, IUniverInstanceService, Inject, Injector, JSONX, PageOrientType, PresetListType, RESTORE_INSERTED_PARAGRAPH_IDS, RedoCommand, SectionType, TextX, TextXActionType, Tools, UndoCommand, UniverInstanceType, UpdateDocsAttributeType, createParagraphId, createSectionId, generateRandomId, getParagraphContentStartOffset, getRichTextEditPath, getSectionHeaderFooterReferenceKey, regexp, resolveSectionHeaderFooterReference } from "@univerjs/core";
1
+ import { BooleanNumber, ColumnSeparatorType, DashStyleType, DataStreamTreeTokenType, DocumentFlavor, ICommandService, IPermissionService, IResourceLoaderService, IUniverInstanceService, Inject, Injector, JSONX, PageOrientType, PresetListType, RESTORE_INSERTED_PARAGRAPH_IDS, RedoCommand, SectionType, TextX, TextXActionType, Tools, UndoCommand, UniverInstanceType, UpdateDocsAttributeType, createParagraphId, createSectionId, generateRandomId, getParagraphContentStartOffset, getRichTextEditPath, getSectionHeaderFooterReferenceKey, regexp, resolveSectionHeaderFooterReference } from "@univerjs/core";
2
2
  import { FBaseInitialable, FEnum, FUniver } from "@univerjs/core/facade";
3
- import { CreateHeaderFooterCommand, DeleteDocumentSectionBreakCommand, HeaderFooterType, InsertDocumentColumnBreakCommand, InsertDocumentSectionBreakCommand, RichTextEditingMutation, SetDocumentNameCommand, SetSectionHeaderFooterLinkCommand, UpdateDocumentParagraphStyleCommand, UpdateDocumentSectionCommand, createSectionColumnProperties, generateParagraphs, getEffectiveSectionPageSetup, getSectionContentWidth, getTopLevelSectionBreaks } from "@univerjs/docs";
3
+ import { CreateHeaderFooterCommand, DeleteDocumentSectionBreakCommand, HeaderFooterType, InsertDocumentColumnBreakCommand, InsertDocumentSectionBreakCommand, InsertTextCommand, RichTextEditingMutation, SetDocumentNameCommand, SetDocumentPermissionCommand, SetDocumentPermissionsCommand, SetSectionHeaderFooterLinkCommand, UpdateDocumentParagraphStyleCommand, UpdateDocumentSectionCommand, canEditDocumentTargets, createSectionColumnProperties, generateParagraphs, getDocumentEntityParentPermissionObjectIds, getDocumentEntityPermissionObjectId, getDocumentParagraphParentPermissionObjectIds, getDocumentParagraphPermissionObjectId, getDocumentPermissionValue, getDocumentSectionPermissionObjectId, getEffectiveSectionPageSetup, getSectionContentWidth, getTopLevelSectionBreaks } from "@univerjs/docs";
4
+ import { UnitAction } from "@univerjs/protocol";
4
5
 
6
+ //#region src/facade/f-document-permission.ts
7
+ /**
8
+ * Command-backed permissions for one Document unit.
9
+ * @hideconstructor
10
+ */
11
+ var FDocumentPermission = class {
12
+ constructor(_unitId, _commandService, _permissionService) {
13
+ this._unitId = _unitId;
14
+ this._commandService = _commandService;
15
+ this._permissionService = _permissionService;
16
+ }
17
+ /**
18
+ * Creates or updates child-object edit policies in this unit; policy: null removes protection and restores inheritance.
19
+ *
20
+ * Requires Authz support and objectPermissionTypes configured for every target type. File and parent restrictions
21
+ * still apply. Use the exported permission object ID helpers, not raw object IDs or server permission IDs.
22
+ * The batch must be nonempty, contain distinct objects, and belong to this unit; file-wide policies are excluded.
23
+ * Other targets use getDocumentSectionPermissionObjectId and getDocumentEntityPermissionObjectId.
24
+ *
25
+ * edit: 'all' allows Unit editors, 'owner' restricts editing to the object owner, and 'members' selects existing
26
+ * Unit collaborators. Pass their collaborator records from the member service; this does not invite new users.
27
+ * Use strategies: [] for the default Edit strategy; child-object strategies support only UnitAction.Edit.
28
+ *
29
+ * Authz writes execute per object and can partially succeed. Inspect failed before retrying only those objects.
30
+ * refreshError means writes finished but permission readback failed; do not retry succeeded objects for that error.
31
+ * Successful binding changes share one undo entry; existing remote policy edits are not undoable.
32
+ * @param {IObjectPermissionChange[]} changes Permission object IDs and policies to apply.
33
+ * @returns {Promise<IObjectPermissionBatchResult>} Successful object IDs, per-object failures, and optional readback error.
34
+ * @throws {Error} Invalid batches or unsupported object types are rejected before Authz writes.
35
+ * @example Set owner/member editing and remove protection in one batch
36
+ * ```ts
37
+ * import type { ICollaborator } from '@univerjs/protocol';
38
+ * import { getDocumentParagraphPermissionObjectId } from '@univerjs/docs';
39
+ *
40
+ * // selectedMembers comes from the existing Unit collaborator picker/service.
41
+ * async function applyPermissions(selectedMembers: ICollaborator[]) {
42
+ * if (!selectedMembers.length) throw new Error('Select at least one Unit collaborator.');
43
+ * const document = univerAPI.getActiveDocument();
44
+ * if (!document) throw new Error('No active document.');
45
+ * const objects = document.getParagraphs().slice(0, 3);
46
+ * const objectIds = objects.map((paragraph) =>
47
+ * getDocumentParagraphPermissionObjectId(paragraph.getSegmentId(), paragraph.getId()));
48
+ * if (objectIds.length < 3) throw new Error('This example requires three paragraphs.');
49
+ * const result = await document.getPermission().setObjectPermissions([
50
+ * { objectId: objectIds[0], policy: { edit: 'owner', collaborators: [], strategies: [] } },
51
+ * { objectId: objectIds[1], policy: { edit: 'members', collaborators: selectedMembers, strategies: [] } },
52
+ * { objectId: objectIds[2], policy: null },
53
+ * ]);
54
+ * // A policy creates protection if absent, or updates the existing policy when already configured.
55
+ * for (const failure of result.failed) {
56
+ * console.error(failure.objectId, failure.error);
57
+ * }
58
+ * if (result.refreshError) {
59
+ * console.error(result.refreshError);
60
+ * }
61
+ * return result;
62
+ * }
63
+ * ```
64
+ */
65
+ async setObjectPermissions(changes) {
66
+ return this._commandService.executeCommand(SetDocumentPermissionsCommand.id, {
67
+ unitId: this._unitId,
68
+ changes
69
+ });
70
+ }
71
+ /**
72
+ * Sets one Document unit permission through the command system.
73
+ *
74
+ * Supported actions are Edit, Copy, Print, Export, and Comment. Await the returned promise
75
+ * before reading the new value or performing an action that depends on it.
76
+ *
77
+ * @param {DocumentUnitPermissionAction} action Unit permission action to update.
78
+ * @param {boolean} value Whether the action is allowed.
79
+ * @returns {Promise<void>} Resolves after the permission command finishes.
80
+ * @example Disable copying while keeping the Document editable
81
+ * ```ts
82
+ * import { UnitAction } from '@univerjs/protocol';
83
+ *
84
+ * const document = univerAPI.getActiveDocument();
85
+ * if (!document) throw new Error('No active Document.');
86
+ * await document.getPermission().setPoint(UnitAction.Copy, false);
87
+ * ```
88
+ */
89
+ async setPoint(action, value) {
90
+ await this._commandService.executeCommand(SetDocumentPermissionCommand.id, {
91
+ unitId: this._unitId,
92
+ objectId: this._unitId,
93
+ action,
94
+ value
95
+ });
96
+ }
97
+ /**
98
+ * Returns the current value of one Document unit permission.
99
+ * @param {DocumentUnitPermissionAction} action Unit permission action to query.
100
+ * @returns {boolean} Whether the action is currently allowed.
101
+ * @example
102
+ * ```ts
103
+ * import { UnitAction } from '@univerjs/protocol';
104
+ *
105
+ * const document = univerAPI.getActiveDocument();
106
+ * const canPrint = document?.getPermission().getPoint(UnitAction.Print) ?? false;
107
+ * console.log(canPrint);
108
+ * ```
109
+ */
110
+ getPoint(action) {
111
+ return getDocumentPermissionValue(this._permissionService, this._unitId, this._unitId, action);
112
+ }
113
+ /**
114
+ * Enables or disables editing for the whole Document.
115
+ * @param {boolean} [editable] Whether editing is allowed. Defaults to true.
116
+ * @returns {Promise<void>} Resolves after the permission command finishes.
117
+ */
118
+ async setEditable(editable = true) {
119
+ await this._commandService.executeCommand(SetDocumentPermissionCommand.id, {
120
+ unitId: this._unitId,
121
+ objectId: this._unitId,
122
+ action: UnitAction.Edit,
123
+ value: editable
124
+ });
125
+ }
126
+ /**
127
+ * Makes the whole Document read-only.
128
+ * @returns {Promise<void>} Resolves after the permission command finishes.
129
+ * @example
130
+ * ```ts
131
+ * const document = univerAPI.getActiveDocument();
132
+ * if (!document) throw new Error('No active Document.');
133
+ * await document.getPermission().setReadOnly();
134
+ * ```
135
+ */
136
+ async setReadOnly() {
137
+ await this._commandService.executeCommand(SetDocumentPermissionCommand.id, {
138
+ unitId: this._unitId,
139
+ objectId: this._unitId,
140
+ action: UnitAction.Edit,
141
+ value: false
142
+ });
143
+ }
144
+ /**
145
+ * Returns whether the whole Document is currently editable.
146
+ * @returns {boolean} Whether Document editing is allowed.
147
+ */
148
+ canEdit() {
149
+ return getDocumentPermissionValue(this._permissionService, this._unitId, this._unitId, UnitAction.Edit);
150
+ }
151
+ };
152
+ /**
153
+ * Command-backed Edit permission for one stable Document object.
154
+ * @hideconstructor
155
+ */
156
+ var FDocumentObjectPermission = class {
157
+ constructor(_unitId, _objectId, _commandService, _permissionService, _getParentObjectIds = () => []) {
158
+ this._unitId = _unitId;
159
+ this._objectId = _objectId;
160
+ this._commandService = _commandService;
161
+ this._permissionService = _permissionService;
162
+ this._getParentObjectIds = _getParentObjectIds;
163
+ }
164
+ /**
165
+ * Enables or disables editing for this stable Document object.
166
+ *
167
+ * This changes only the object's Edit point. `canEdit()` also applies the Document unit and
168
+ * parent Section or Paragraph ceilings.
169
+ *
170
+ * @param {boolean} [editable] Whether object editing is allowed. Defaults to true.
171
+ * @returns {Promise<void>} Resolves after the permission command finishes.
172
+ * @example Restore editing for a paragraph
173
+ * ```ts
174
+ * const document = univerAPI.getActiveDocument();
175
+ * const paragraph = document?.getParagraphs()[0];
176
+ * if (!paragraph) throw new Error('Paragraph not found.');
177
+ * await paragraph.getPermission().setEditable();
178
+ * ```
179
+ */
180
+ async setEditable(editable = true) {
181
+ await this._commandService.executeCommand(SetDocumentPermissionCommand.id, {
182
+ unitId: this._unitId,
183
+ objectId: this._objectId,
184
+ action: UnitAction.Edit,
185
+ value: editable
186
+ });
187
+ }
188
+ /**
189
+ * Makes this stable Document object read-only.
190
+ * @returns {Promise<void>} Resolves after the permission command finishes.
191
+ * @example
192
+ * ```ts
193
+ * const document = univerAPI.getActiveDocument();
194
+ * const section = document?.getSection(0);
195
+ * if (!section) throw new Error('Section not found.');
196
+ * await section.getPermission().setReadOnly();
197
+ * ```
198
+ */
199
+ async setReadOnly() {
200
+ await this._commandService.executeCommand(SetDocumentPermissionCommand.id, {
201
+ unitId: this._unitId,
202
+ objectId: this._objectId,
203
+ action: UnitAction.Edit,
204
+ value: false
205
+ });
206
+ }
207
+ /**
208
+ * Returns the effective Edit result after applying the Document, parent, and object permissions.
209
+ * @returns {boolean} Whether the object is currently editable.
210
+ */
211
+ canEdit() {
212
+ return canEditDocumentTargets(this._permissionService, this._unitId, [...this._getParentObjectIds(), this._objectId]);
213
+ }
214
+ };
215
+
216
+ //#endregion
5
217
  //#region src/facade/utils.ts
6
218
  function cloneParagraphStyle(paragraphStyle) {
7
219
  return paragraphStyle == null ? paragraphStyle : JSON.parse(JSON.stringify(paragraphStyle));
@@ -32,31 +244,24 @@ function buildPlainTextInsertBody(dataStream, options = {}) {
32
244
  if (paragraphs.length > 0) body.paragraphs = paragraphs;
33
245
  return body;
34
246
  }
35
- function replaceBodyRange(range, insertBody, docDataModel, injector) {
247
+ function replaceBodyRange(range, insertBody, docDataModel, commandService) {
36
248
  const { startOffset, endOffset, segmentId } = range;
37
- const textX = new TextX();
38
- if (startOffset > 0) textX.push({
39
- t: TextXActionType.RETAIN,
40
- len: startOffset
41
- });
42
- if (endOffset > startOffset) textX.push({
43
- t: TextXActionType.DELETE,
44
- len: endOffset - startOffset
45
- });
46
- if (insertBody.dataStream.length > 0) textX.push({
47
- t: TextXActionType.INSERT,
48
- body: insertBody,
49
- len: insertBody.dataStream.length
50
- });
51
- const actions = JSONX.getInstance().editOp(textX.serialize(), getRichTextEditPath(docDataModel, segmentId));
52
- const result = injector.get(ICommandService).syncExecuteCommand(RichTextEditingMutation.id, {
249
+ const result = commandService.syncExecuteCommand(InsertTextCommand.id, {
53
250
  unitId: docDataModel.getUnitId(),
251
+ body: insertBody,
252
+ range: {
253
+ startOffset,
254
+ endOffset,
255
+ collapsed: startOffset === endOffset,
256
+ segmentId
257
+ },
54
258
  segmentId,
55
- actions,
259
+ debounce: false,
56
260
  textRanges: [],
261
+ noNeedSetTextRange: true,
57
262
  isEditing: false
58
263
  });
59
- return Boolean((result === null || result === void 0 ? void 0 : result.actions) && result.actions.length > 0);
264
+ return Boolean(result);
60
265
  }
61
266
  function retainBodyRange(range, updateBody, coverType, docDataModel, injector) {
62
267
  var _updateBody$textRuns, _docDataModel$getSelf;
@@ -97,23 +302,34 @@ function stripBlockTokens(text) {
97
302
  return Array.from(text).map((char) => char === DataStreamTreeTokenType.PARAGRAPH ? "\n" : char).filter((char) => char !== DataStreamTreeTokenType.BLOCK_START && char !== DataStreamTreeTokenType.BLOCK_END && char !== DataStreamTreeTokenType.SECTION_BREAK).join("").replace(/\n$/, "");
98
303
  }
99
304
 
305
+ //#endregion
306
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorateParam.js
307
+ function __decorateParam(paramIndex, decorator) {
308
+ return function(target, key) {
309
+ decorator(target, key, paramIndex);
310
+ };
311
+ }
312
+
313
+ //#endregion
314
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/decorate.js
315
+ function __decorate(decorators, target, key, desc) {
316
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
317
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
318
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
319
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
320
+ }
321
+
100
322
  //#endregion
101
323
  //#region src/facade/f-document-text-range.ts
102
- /**
103
- * Facade wrapper for reading and styling a fixed document text range.
104
- *
105
- * Offsets are fixed when the wrapper is created. Create a new range after edits
106
- * that insert or remove content before it.
107
- * @hideconstructor
108
- */
109
- var FDocumentTextRange = class extends FBaseInitialable {
110
- constructor(_document, _startOffset, _endOffset, _segmentId, _injector) {
324
+ let FDocumentTextRange = class FDocumentTextRange extends FBaseInitialable {
325
+ constructor(_document, _startOffset, _endOffset, _segmentId, _injector, _commandService) {
111
326
  super(_injector);
112
327
  this._document = _document;
113
328
  this._startOffset = _startOffset;
114
329
  this._endOffset = _endOffset;
115
330
  this._segmentId = _segmentId;
116
331
  this._injector = _injector;
332
+ this._commandService = _commandService;
117
333
  this._validateRange();
118
334
  }
119
335
  /**
@@ -204,6 +420,8 @@ var FDocumentTextRange = class extends FBaseInitialable {
204
420
  * Existing text-run splitting, merging, and normalization are handled by
205
421
  * the document mutation pipeline.
206
422
  * `style.fs` is a font size in points (pt), not CSS pixels.
423
+ * @param {ITextStyle} style Text-style properties to merge into the range.
424
+ * @returns {boolean} Whether the style update succeeded; `false` for an empty range.
207
425
  * @example
208
426
  * ```ts
209
427
  * const fDocument = univerAPI.getActiveDocument();
@@ -224,6 +442,8 @@ var FDocumentTextRange = class extends FBaseInitialable {
224
442
  }
225
443
  /**
226
444
  * Replaces the range with plain text while preserving document mutation semantics.
445
+ * @param {string} text Replacement plain text. An empty string deletes the range.
446
+ * @returns {boolean} Whether the replacement succeeded.
227
447
  * @example
228
448
  * ```ts
229
449
  * const fDocument = univerAPI.getActiveDocument();
@@ -232,7 +452,7 @@ var FDocumentTextRange = class extends FBaseInitialable {
232
452
  * ```
233
453
  */
234
454
  setText(text) {
235
- return replaceBodyRange(this.getRange(), buildPlainTextInsertBody(text), this._document.getDocumentDataModel(), this._injector);
455
+ return replaceBodyRange(this.getRange(), buildPlainTextInsertBody(text), this._document.getDocumentDataModel(), this._commandService);
236
456
  }
237
457
  _validateRange() {
238
458
  const bodyLength = this._document.getBody(this._segmentId).dataStream.length;
@@ -259,37 +479,22 @@ var FDocumentTextRange = class extends FBaseInitialable {
259
479
  return segments;
260
480
  }
261
481
  };
482
+ FDocumentTextRange = __decorate([__decorateParam(5, ICommandService)], FDocumentTextRange);
262
483
  function isDeepEqual(left, right) {
263
484
  return JSON.stringify(left) === JSON.stringify(right);
264
485
  }
265
486
 
266
- //#endregion
267
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorateParam.js
268
- function __decorateParam(paramIndex, decorator) {
269
- return function(target, key) {
270
- decorator(target, key, paramIndex);
271
- };
272
- }
273
-
274
- //#endregion
275
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/decorate.js
276
- function __decorate(decorators, target, key, desc) {
277
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
278
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
279
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
280
- return c > 3 && r && Object.defineProperty(target, key, r), r;
281
- }
282
-
283
487
  //#endregion
284
488
  //#region src/facade/f-document-paragraph.ts
285
489
  let FDocumentParagraph = class FDocumentParagraph extends FBaseInitialable {
286
- constructor(_document, _paragraphId, _segmentId = "", _injector, _commandService) {
490
+ constructor(_document, _paragraphId, _segmentId = "", _injector, _commandService, _permissionService) {
287
491
  super(_injector);
288
492
  this._document = _document;
289
493
  this._paragraphId = _paragraphId;
290
494
  this._segmentId = _segmentId;
291
495
  this._injector = _injector;
292
496
  this._commandService = _commandService;
497
+ this._permissionService = _permissionService;
293
498
  }
294
499
  /**
295
500
  * Get the persisted paragraph id.
@@ -320,6 +525,19 @@ let FDocumentParagraph = class FDocumentParagraph extends FBaseInitialable {
320
525
  return this._segmentId;
321
526
  }
322
527
  /**
528
+ * Returns this Paragraph's permission facade.
529
+ * @returns {FDocumentObjectPermission} Permission facade combining Document, Section, and Paragraph Edit points.
530
+ * @example
531
+ * ```ts
532
+ * const paragraph = univerAPI.getActiveDocument()?.getParagraphs()[0];
533
+ * if (!paragraph) throw new Error('Paragraph not found.');
534
+ * await paragraph.getPermission().setReadOnly();
535
+ * ```
536
+ */
537
+ getPermission() {
538
+ return new FDocumentObjectPermission(this._document.getId(), getDocumentParagraphPermissionObjectId(this._segmentId, this._paragraphId), this._commandService, this._permissionService, () => getDocumentParagraphParentPermissionObjectIds(this._document.getDocumentDataModel(), this._segmentId, this._paragraphId));
539
+ }
540
+ /**
323
541
  * Get this paragraph's metadata.
324
542
  * @returns {IFDocumentParagraphInfo} The paragraph info.
325
543
  * @example
@@ -477,7 +695,7 @@ let FDocumentParagraph = class FDocumentParagraph extends FBaseInitialable {
477
695
  startOffset,
478
696
  endOffset,
479
697
  segmentId: this._segmentId
480
- }, buildPlainTextInsertBody(text), this._document.getDocumentDataModel(), this._injector);
698
+ }, buildPlainTextInsertBody(text), this._document.getDocumentDataModel(), this._commandService);
481
699
  }
482
700
  /**
483
701
  * Append plain text before this paragraph's trailing paragraph break.
@@ -646,7 +864,7 @@ let FDocumentParagraph = class FDocumentParagraph extends FBaseInitialable {
646
864
  body[RESTORE_INSERTED_PARAGRAPH_IDS] = true;
647
865
  }
648
866
  };
649
- FDocumentParagraph = __decorate([__decorateParam(4, ICommandService)], FDocumentParagraph);
867
+ FDocumentParagraph = __decorate([__decorateParam(4, ICommandService), __decorateParam(5, IPermissionService)], FDocumentParagraph);
650
868
  function isParagraphFacade(value) {
651
869
  if (typeof value !== "object" || value === null) return false;
652
870
  return typeof value.getId === "function" && typeof value.getSegmentId === "function" && typeof value.getInfo === "function" && typeof value.getRange === "function";
@@ -674,10 +892,11 @@ var DocsSectionUnsupportedDocumentFlavorError = class extends Error {
674
892
  }
675
893
  };
676
894
  let FDocumentSection = class FDocumentSection {
677
- constructor(_document, _sectionId, _commandService) {
895
+ constructor(_document, _sectionId, _commandService, _permissionService) {
678
896
  this._document = _document;
679
897
  this._sectionId = _sectionId;
680
898
  this._commandService = _commandService;
899
+ this._permissionService = _permissionService;
681
900
  }
682
901
  /**
683
902
  * Returns the persisted section id.
@@ -691,6 +910,19 @@ let FDocumentSection = class FDocumentSection {
691
910
  return this._sectionId;
692
911
  }
693
912
  /**
913
+ * Returns this Section's permission facade.
914
+ * @returns {FDocumentObjectPermission} Permission facade combining Document and Section Edit points.
915
+ * @example
916
+ * ```ts
917
+ * const section = univerAPI.getActiveDocument()?.getSection(0);
918
+ * if (!section) throw new Error('Section not found.');
919
+ * await section.getPermission().setReadOnly();
920
+ * ```
921
+ */
922
+ getPermission() {
923
+ return new FDocumentObjectPermission(this._document.getId(), getDocumentSectionPermissionObjectId("", this._sectionId), this._commandService, this._permissionService);
924
+ }
925
+ /**
694
926
  * Returns the current zero-based section index.
695
927
  * @example
696
928
  * ```ts
@@ -771,6 +1003,10 @@ let FDocumentSection = class FDocumentSection {
771
1003
  * Sets equal or explicitly sized columns for this traditional section.
772
1004
  * Use `columnCount = 1` to restore normal single-column layout.
773
1005
  * `gap` and `widths` are in 96-DPI layout pixels.
1006
+ * @param {number} columnCount Positive integer column count.
1007
+ * @param {IFDocumentSectionColumnOptions} [options] Column widths, gap (default 18 pixels), and separator (default none).
1008
+ * @returns {boolean} Whether the section update succeeded.
1009
+ * @throws {RangeError} If column dimensions or the separator are invalid, or columns exceed the available width.
774
1010
  * @example
775
1011
  * ```ts
776
1012
  * const fDocument = univerAPI.getActiveDocument();
@@ -796,6 +1032,10 @@ let FDocumentSection = class FDocumentSection {
796
1032
  }
797
1033
  /**
798
1034
  * Sets explicit OOXML-compatible column width and trailing-space values in 96-DPI layout pixels.
1035
+ * @param {ISectionColumnProperties[]} columns Explicit widths and trailing spaces; an empty array restores a single column.
1036
+ * @param {ColumnSeparatorType} [separator] Column separator style. Defaults to `ColumnSeparatorType.NONE`.
1037
+ * @returns {boolean} Whether the section update succeeded.
1038
+ * @throws {RangeError} If column dimensions or the separator are invalid, or columns exceed the available width.
799
1039
  * @example
800
1040
  * ```ts
801
1041
  * const fDocument = univerAPI.getActiveDocument();
@@ -962,6 +1202,8 @@ let FDocumentSection = class FDocumentSection {
962
1202
  }
963
1203
  /**
964
1204
  * Ensures a header segment linked specifically to this section.
1205
+ * @param {SectionHeaderFooterVariant} [variant] The `'default'`, `'first'`, or `'even'` variant. Defaults to `'default'`.
1206
+ * @returns {string} The existing or newly created section-specific segment ID.
965
1207
  * @example
966
1208
  * ```ts
967
1209
  * const fDocument = univerAPI.getActiveDocument();
@@ -978,6 +1220,8 @@ let FDocumentSection = class FDocumentSection {
978
1220
  }
979
1221
  /**
980
1222
  * Ensures a footer segment linked specifically to this section.
1223
+ * @param {SectionHeaderFooterVariant} [variant] The `'default'`, `'first'`, or `'even'` variant. Defaults to `'default'`.
1224
+ * @returns {string} The existing or newly created section-specific segment ID.
981
1225
  * @example
982
1226
  * ```ts
983
1227
  * const fDocument = univerAPI.getActiveDocument();
@@ -994,6 +1238,8 @@ let FDocumentSection = class FDocumentSection {
994
1238
  }
995
1239
  /**
996
1240
  * Returns the effective header id after resolving links to previous sections.
1241
+ * @param {SectionHeaderFooterVariant} [variant] The `'default'`, `'first'`, or `'even'` variant. Defaults to `'default'`.
1242
+ * @returns {string | null} The effective segment ID, or `null` if no segment is available.
997
1243
  * @example
998
1244
  * ```ts
999
1245
  * const fDocument = univerAPI.getActiveDocument();
@@ -1005,6 +1251,8 @@ let FDocumentSection = class FDocumentSection {
1005
1251
  }
1006
1252
  /**
1007
1253
  * Returns the effective footer id after resolving links to previous sections.
1254
+ * @param {SectionHeaderFooterVariant} [variant] The `'default'`, `'first'`, or `'even'` variant. Defaults to `'default'`.
1255
+ * @returns {string | null} The effective segment ID, or `null` if no segment is available.
1008
1256
  * @example
1009
1257
  * ```ts
1010
1258
  * const fDocument = univerAPI.getActiveDocument();
@@ -1016,6 +1264,8 @@ let FDocumentSection = class FDocumentSection {
1016
1264
  }
1017
1265
  /**
1018
1266
  * Whether this header variant inherits the previous section's reference.
1267
+ * @param {SectionHeaderFooterVariant} [variant] The `'default'`, `'first'`, or `'even'` variant. Defaults to `'default'`.
1268
+ * @returns {boolean} Whether this variant inherits from the previous section.
1019
1269
  * @example
1020
1270
  * ```ts
1021
1271
  * const fDocument = univerAPI.getActiveDocument();
@@ -1027,6 +1277,8 @@ let FDocumentSection = class FDocumentSection {
1027
1277
  }
1028
1278
  /**
1029
1279
  * Whether this footer variant inherits the previous section's reference.
1280
+ * @param {SectionHeaderFooterVariant} [variant] The `'default'`, `'first'`, or `'even'` variant. Defaults to `'default'`.
1281
+ * @returns {boolean} Whether this variant inherits from the previous section.
1030
1282
  * @example
1031
1283
  * ```ts
1032
1284
  * const fDocument = univerAPI.getActiveDocument();
@@ -1038,6 +1290,9 @@ let FDocumentSection = class FDocumentSection {
1038
1290
  }
1039
1291
  /**
1040
1292
  * Links or unlinks this header variant. Unlinking clones the inherited header.
1293
+ * @param {boolean} linkedToPrevious Whether to inherit the previous section's header/footer.
1294
+ * @param {SectionHeaderFooterVariant} [variant] The `'default'`, `'first'`, or `'even'` variant. Defaults to `'default'`.
1295
+ * @returns {boolean} Whether the link update succeeded.
1041
1296
  * @example
1042
1297
  * ```ts
1043
1298
  * const fDocument = univerAPI.getActiveDocument();
@@ -1051,6 +1306,9 @@ let FDocumentSection = class FDocumentSection {
1051
1306
  }
1052
1307
  /**
1053
1308
  * Links or unlinks this footer variant. Unlinking clones the inherited footer.
1309
+ * @param {boolean} linkedToPrevious Whether to inherit the previous section's header/footer.
1310
+ * @param {SectionHeaderFooterVariant} [variant] The `'default'`, `'first'`, or `'even'` variant. Defaults to `'default'`.
1311
+ * @returns {boolean} Whether the link update succeeded.
1054
1312
  * @example
1055
1313
  * ```ts
1056
1314
  * const fDocument = univerAPI.getActiveDocument();
@@ -1065,6 +1323,8 @@ let FDocumentSection = class FDocumentSection {
1065
1323
  /**
1066
1324
  * Updates header/footer switches and margins on this section break.
1067
1325
  * `marginHeader` and `marginFooter` are in 96-DPI layout pixels.
1326
+ * @param {IHeaderFooterProps} options Header/footer switches and margins to update. Omitted properties are preserved.
1327
+ * @returns {boolean} Whether the update command succeeded.
1068
1328
  * @example
1069
1329
  * ```ts
1070
1330
  * const fDocument = univerAPI.getActiveDocument();
@@ -1144,7 +1404,8 @@ let FDocumentSection = class FDocumentSection {
1144
1404
  }
1145
1405
  _getHeaderFooterReference(kind, variant) {
1146
1406
  const { index } = this._resolve();
1147
- return resolveSectionHeaderFooterReference(this._document.getDocumentDataModel().getSnapshot().documentStyle, getTopLevelSectionBreaks(this._document.getBody()), index, getSectionHeaderFooterReferenceKey(kind, variant));
1407
+ const snapshot = this._document.getDocumentDataModel().getSnapshot();
1408
+ return resolveSectionHeaderFooterReference(snapshot.documentStyle, getTopLevelSectionBreaks(this._document.getBody()), index, getSectionHeaderFooterReferenceKey(kind, variant));
1148
1409
  }
1149
1410
  _describeHeaderFooterReference(kind, variant) {
1150
1411
  const reference = this._getHeaderFooterReference(kind, variant);
@@ -1189,10 +1450,10 @@ let FDocumentSection = class FDocumentSection {
1189
1450
  };
1190
1451
  }
1191
1452
  };
1192
- FDocumentSection = __decorate([__decorateParam(2, ICommandService)], FDocumentSection);
1453
+ FDocumentSection = __decorate([__decorateParam(2, ICommandService), __decorateParam(3, IPermissionService)], FDocumentSection);
1193
1454
 
1194
1455
  //#endregion
1195
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
1456
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/typeof.js
1196
1457
  function _typeof(o) {
1197
1458
  "@babel/helpers - typeof";
1198
1459
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -1203,7 +1464,7 @@ function _typeof(o) {
1203
1464
  }
1204
1465
 
1205
1466
  //#endregion
1206
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPrimitive.js
1467
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPrimitive.js
1207
1468
  function toPrimitive(t, r) {
1208
1469
  if ("object" != _typeof(t) || !t) return t;
1209
1470
  var e = t[Symbol.toPrimitive];
@@ -1216,14 +1477,14 @@ function toPrimitive(t, r) {
1216
1477
  }
1217
1478
 
1218
1479
  //#endregion
1219
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/toPropertyKey.js
1480
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/toPropertyKey.js
1220
1481
  function toPropertyKey(t) {
1221
1482
  var i = toPrimitive(t, "string");
1222
1483
  return "symbol" == _typeof(i) ? i : i + "";
1223
1484
  }
1224
1485
 
1225
1486
  //#endregion
1226
- //#region \0@oxc-project+runtime@0.140.0/helpers/esm/defineProperty.js
1487
+ //#region \0@oxc-project+runtime@0.149.0/helpers/esm/defineProperty.js
1227
1488
  function _defineProperty(e, r, t) {
1228
1489
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
1229
1490
  value: t,
@@ -1236,19 +1497,20 @@ function _defineProperty(e, r, t) {
1236
1497
  //#endregion
1237
1498
  //#region src/facade/f-document.ts
1238
1499
  let FDocument = class FDocument extends FBaseInitialable {
1239
- constructor(_documentDataModel, _injector, _univerInstanceService, _resourceLoaderService, _commandService) {
1500
+ constructor(_documentDataModel, _injector, _univerInstanceService, _resourceLoaderService, _commandService, _permissionService) {
1240
1501
  super(_injector);
1241
1502
  this._documentDataModel = _documentDataModel;
1242
1503
  this._injector = _injector;
1243
1504
  this._univerInstanceService = _univerInstanceService;
1244
1505
  this._resourceLoaderService = _resourceLoaderService;
1245
1506
  this._commandService = _commandService;
1507
+ this._permissionService = _permissionService;
1246
1508
  _defineProperty(this, "id", void 0);
1247
1509
  this.id = this._documentDataModel.getUnitId();
1248
1510
  }
1249
1511
  /**
1250
1512
  * Get the document data model of the document.
1251
- * @param {string} segmentId The segment id used to get the header/footer data model. Defaults to an empty string for the document data model of the document.
1513
+ * @param {string} [segmentId] The segment id used to get the header/footer data model. Defaults to an empty string for the document data model of the document.
1252
1514
  * @returns {DocumentDataModel} The document data model.
1253
1515
  * @example
1254
1516
  * ```typescript
@@ -1290,7 +1552,7 @@ let FDocument = class FDocument extends FBaseInitialable {
1290
1552
  * Get the document body or header/footer body by the segment id.
1291
1553
  * The main body has an empty segment id.
1292
1554
  * The header and footer body have their respective segment ids.
1293
- * @param {string} segmentId The segment id of the body. Defaults to an empty string for the main body.
1555
+ * @param {string} [segmentId] The segment id of the body. Defaults to an empty string for the main body.
1294
1556
  * @returns {IDocumentBody} The document body.
1295
1557
  * @example
1296
1558
  * ```typescript
@@ -1307,6 +1569,7 @@ let FDocument = class FDocument extends FBaseInitialable {
1307
1569
  if (!body) throw new Error(segmentId === "" ? "Body is not found in the document." : `Body is not found in the segment: ${segmentId}`);
1308
1570
  return body;
1309
1571
  }
1572
+ /** Releases this facade's resources. Use `univerAPI.disposeUnit()` to unload the owning unit. */
1310
1573
  dispose() {
1311
1574
  super.dispose();
1312
1575
  }
@@ -1323,6 +1586,40 @@ let FDocument = class FDocument extends FBaseInitialable {
1323
1586
  return this.id;
1324
1587
  }
1325
1588
  /**
1589
+ * Returns the Document unit permission facade.
1590
+ * @returns {FDocumentPermission} Permission facade for Edit, Copy, Print, Export, and Comment.
1591
+ * @example
1592
+ * ```ts
1593
+ * const document = univerAPI.getActiveDocument();
1594
+ * if (!document) throw new Error('No active Document.');
1595
+ * await document.getPermission().setReadOnly();
1596
+ * ```
1597
+ */
1598
+ getPermission() {
1599
+ return new FDocumentPermission(this.id, this._commandService, this._permissionService);
1600
+ }
1601
+ /**
1602
+ * Returns the permission facade for an entity with a stable id, such as a Table, Drawing, or Custom Block.
1603
+ *
1604
+ * Parent Section and Paragraph permission ceilings are resolved from the current Document model.
1605
+ * @param {string} segmentId Segment id, or an empty string for the main body.
1606
+ * @param {string} entityType Stable entity type used by the owning Doc feature.
1607
+ * @param {string} entityId Stable entity id.
1608
+ * @returns {FDocumentObjectPermission} Effective permission facade for the entity.
1609
+ * @example Make one drawing read-only
1610
+ * ```ts
1611
+ * const document = univerAPI.getActiveDocument();
1612
+ * if (!document) throw new Error('No active Document.');
1613
+ * const snapshot = document.getDocumentDataModel().getSnapshot();
1614
+ * const drawingId = snapshot.drawingsOrder?.[0];
1615
+ * if (!drawingId) throw new Error('Drawing not found.');
1616
+ * await document.getEntityPermission('', 'drawing', drawingId).setReadOnly();
1617
+ * ```
1618
+ */
1619
+ getEntityPermission(segmentId, entityType, entityId) {
1620
+ return new FDocumentObjectPermission(this.id, getDocumentEntityPermissionObjectId(segmentId, entityType, entityId), this._commandService, this._permissionService, () => getDocumentEntityParentPermissionObjectIds(this._documentDataModel, segmentId, entityType, entityId));
1621
+ }
1622
+ /**
1326
1623
  * Get the document name.
1327
1624
  * @returns {string} The document name.
1328
1625
  * @example
@@ -1463,7 +1760,7 @@ let FDocument = class FDocument extends FBaseInitialable {
1463
1760
  }
1464
1761
  /**
1465
1762
  * Ensure the page header segment exists and return its segment id.
1466
- * @param {number} pageIndex The zero-based page index. Defaults to the first page.
1763
+ * @param {number} [pageIndex] The zero-based page index. Defaults to the first page.
1467
1764
  * @returns {string} The header segment id.
1468
1765
  * @example
1469
1766
  * ```ts
@@ -1477,7 +1774,7 @@ let FDocument = class FDocument extends FBaseInitialable {
1477
1774
  }
1478
1775
  /**
1479
1776
  * Ensure the page footer segment exists and return its segment id.
1480
- * @param {number} pageIndex The zero-based page index. Defaults to the first page.
1777
+ * @param {number} [pageIndex] The zero-based page index. Defaults to the first page.
1481
1778
  * @returns {string} The footer segment id.
1482
1779
  * @example
1483
1780
  * ```ts
@@ -1493,7 +1790,7 @@ let FDocument = class FDocument extends FBaseInitialable {
1493
1790
  * Insert plain text at a document body offset.
1494
1791
  * @param {number} index The zero-based insertion offset.
1495
1792
  * @param {string} text The plain text to insert.
1496
- * @param {string} segmentId The segment id of the body. Defaults to an empty string for the main body.
1793
+ * @param {string} [segmentId] The segment id of the body. Defaults to an empty string for the main body.
1497
1794
  * @returns {boolean} `true` if the edit was applied.
1498
1795
  * @example
1499
1796
  * ```ts
@@ -1509,7 +1806,7 @@ let FDocument = class FDocument extends FBaseInitialable {
1509
1806
  startOffset: index,
1510
1807
  endOffset: index,
1511
1808
  segmentId
1512
- }, buildPlainTextInsertBody(text), this._documentDataModel, this._injector);
1809
+ }, buildPlainTextInsertBody(text), this._documentDataModel, this._commandService);
1513
1810
  }
1514
1811
  /**
1515
1812
  * Returns document-level header/footer switches and margins. Margin values use 96-DPI layout pixels.
@@ -1534,6 +1831,8 @@ let FDocument = class FDocument extends FBaseInitialable {
1534
1831
  * Traditional and Unspecified documents keep the legacy header/footer
1535
1832
  * behavior. Modern documents reject this API. `marginHeader` and
1536
1833
  * `marginFooter` use 96-DPI layout pixels.
1834
+ * @param {IHeaderFooterProps} options Header/footer switches and margins to update. Omitted properties are preserved.
1835
+ * @returns {boolean} Whether the update command succeeded.
1537
1836
  * @example
1538
1837
  * ```ts
1539
1838
  * const fDocument = univerAPI.getActiveDocument();
@@ -1557,7 +1856,7 @@ let FDocument = class FDocument extends FBaseInitialable {
1557
1856
  * The end offset is exclusive, and offsets are scoped to the selected body segment.
1558
1857
  * @param {number} startOffset The inclusive start offset.
1559
1858
  * @param {number} endOffset The exclusive end offset.
1560
- * @param {string} segmentId The header/footer segment id, or an empty string for the main body.
1859
+ * @param {string} [segmentId] The header/footer segment id, or an empty string for the main body.
1561
1860
  * @returns {FDocumentTextRange} A fixed text-range facade.
1562
1861
  * @example
1563
1862
  * ```ts
@@ -1585,6 +1884,8 @@ let FDocument = class FDocument extends FBaseInitialable {
1585
1884
  }
1586
1885
  /**
1587
1886
  * Returns a traditional section by zero-based index, or `null` in modern documents.
1887
+ * @param {number} index Zero-based section index.
1888
+ * @returns {FDocumentSection | null} The matching section, or `null` if none exists or the document is not Traditional.
1588
1889
  * @example
1589
1890
  * ```ts
1590
1891
  * const fDocument = univerAPI.getActiveDocument();
@@ -1597,6 +1898,8 @@ let FDocument = class FDocument extends FBaseInitialable {
1597
1898
  }
1598
1899
  /**
1599
1900
  * Returns the traditional section containing a data-stream offset, or `null` in modern documents.
1901
+ * @param {number} offset Zero-based data-stream offset in the main document body.
1902
+ * @returns {FDocumentSection | null} The matching section, or `null` if none exists or the document is not Traditional.
1600
1903
  * @example
1601
1904
  * ```ts
1602
1905
  * const fDocument = univerAPI.getActiveDocument();
@@ -1681,6 +1984,8 @@ let FDocument = class FDocument extends FBaseInitialable {
1681
1984
  * In a single-column section, the traditional renderer advances to the next physical page.
1682
1985
  * Modern documents must use ColumnGroup. Unspecified documents must resolve
1683
1986
  * their flavor first. Both throw `DocsSectionUnsupportedDocumentFlavorError`.
1987
+ * @param {number} offset Zero-based data-stream offset at which to insert the column break.
1988
+ * @returns {boolean} Whether the insertion succeeded.
1684
1989
  * @example
1685
1990
  * ```ts
1686
1991
  * const fDocument = univerAPI.getActiveDocument();
@@ -1704,6 +2009,10 @@ let FDocument = class FDocument extends FBaseInitialable {
1704
2009
  * Inserts a horizontal rule using the existing paragraph `borderBottom` mechanism.
1705
2010
  * The returned paragraph can be inspected or removed with normal paragraph APIs.
1706
2011
  * Border width and padding are in points (pt).
2012
+ * @param {number} offset Zero-based insertion offset in the selected body segment.
2013
+ * @param {IParagraphBorder} [border] Bottom border appearance. Defaults to a solid gray 1 pt line with 5 pt padding.
2014
+ * @param {string} [segmentId] Header/footer segment ID, or an empty string for the main body (default).
2015
+ * @returns {FDocumentParagraph | null} The inserted paragraph, or `null` if insertion fails.
1707
2016
  * @example
1708
2017
  * ```ts
1709
2018
  * const fDocument = univerAPI.getActiveDocument();
@@ -1730,11 +2039,11 @@ let FDocument = class FDocument extends FBaseInitialable {
1730
2039
  }, {
1731
2040
  dataStream: DataStreamTreeTokenType.PARAGRAPH,
1732
2041
  paragraphs
1733
- }, this._documentDataModel, this._injector) ? this.getParagraph(paragraphId, segmentId) : null;
2042
+ }, this._documentDataModel, this._commandService) ? this.getParagraph(paragraphId, segmentId) : null;
1734
2043
  }
1735
2044
  /**
1736
2045
  * Get all paragraphs in the document body or header/footer body by the segment id.
1737
- * @param {string} segmentId The segment id of the body. Defaults to an empty string for the main body.
2046
+ * @param {string} [segmentId] The segment id of the body. Defaults to an empty string for the main body.
1738
2047
  * @returns {FDocumentParagraph[]} An array of paragraph facade instances.
1739
2048
  * @example
1740
2049
  * ```ts
@@ -1754,7 +2063,7 @@ let FDocument = class FDocument extends FBaseInitialable {
1754
2063
  /**
1755
2064
  * Get a paragraph by its paragraph id and segment id.
1756
2065
  * @param {string} paragraphId The paragraph id.
1757
- * @param {string} segmentId The segment id of the body. Defaults to an empty string for the main body.
2066
+ * @param {string} [segmentId] The segment id of the body. Defaults to an empty string for the main body.
1758
2067
  * @returns {FDocumentParagraph | null} The paragraph facade instance, or `null` if the paragraph is not found.
1759
2068
  * @example
1760
2069
  * ```ts
@@ -1775,7 +2084,7 @@ let FDocument = class FDocument extends FBaseInitialable {
1775
2084
  /**
1776
2085
  * Find a paragraph by its text content and segment id.
1777
2086
  * @param {string} text The text content to search for.
1778
- * @param {string} segmentId The segment id of the body. Defaults to an empty string for the main body.
2087
+ * @param {string} [segmentId] The segment id of the body. Defaults to an empty string for the main body.
1779
2088
  * @returns {FDocumentParagraph | null} The paragraph facade instance, or `null` if the paragraph is not found.
1780
2089
  * @example
1781
2090
  * ```ts
@@ -1823,8 +2132,8 @@ let FDocument = class FDocument extends FBaseInitialable {
1823
2132
  /**
1824
2133
  * Insert a plain-text paragraph before the paragraph at the given paragraph index.
1825
2134
  * @param {number} index The zero-based paragraph insertion index.
1826
- * @param {string} text The paragraph text. Defaults to an empty paragraph.
1827
- * @param {string} segmentId The segment id of the body. Defaults to an empty string for the main body.
2135
+ * @param {string} [text] The paragraph text. Defaults to an empty paragraph.
2136
+ * @param {string} [segmentId] The segment id of the body. Defaults to an empty string for the main body.
1828
2137
  * @returns {FDocumentParagraph} The inserted paragraph facade instance.
1829
2138
  * @example
1830
2139
  * ```ts
@@ -1843,7 +2152,7 @@ let FDocument = class FDocument extends FBaseInitialable {
1843
2152
  startOffset: offset,
1844
2153
  endOffset: offset,
1845
2154
  segmentId
1846
- }, buildPlainTextInsertBody(`${text}\r`), this._documentDataModel, this._injector)) throw new Error("Failed to insert paragraph.");
2155
+ }, buildPlainTextInsertBody(`${text}\r`), this._documentDataModel, this._commandService)) throw new Error("Failed to insert paragraph.");
1847
2156
  const { paragraphs = [] } = this.getBody(segmentId);
1848
2157
  const paragraph = paragraphs[index];
1849
2158
  if (!paragraph) throw new Error("Failed to insert paragraph.");
@@ -1851,8 +2160,8 @@ let FDocument = class FDocument extends FBaseInitialable {
1851
2160
  }
1852
2161
  /**
1853
2162
  * Append a plain-text paragraph at the end of the body.
1854
- * @param {string} text The paragraph text. Defaults to an empty paragraph.
1855
- * @param {string} segmentId The segment id of the body. Defaults to an empty string for the main body.
2163
+ * @param {string} [text] The paragraph text. Defaults to an empty paragraph.
2164
+ * @param {string} [segmentId] The segment id of the body. Defaults to an empty string for the main body.
1856
2165
  * @returns {FDocumentParagraph} The appended paragraph wrapper.
1857
2166
  * @example
1858
2167
  * ```ts
@@ -1885,7 +2194,7 @@ let FDocument = class FDocument extends FBaseInitialable {
1885
2194
  deleteRange(range) {
1886
2195
  const normalizedRange = this._normalizeDeleteRange(range);
1887
2196
  if (normalizedRange.startOffset >= normalizedRange.endOffset) return false;
1888
- return replaceBodyRange(normalizedRange, { dataStream: "" }, this._documentDataModel, this._injector);
2197
+ return replaceBodyRange(normalizedRange, { dataStream: "" }, this._documentDataModel, this._commandService);
1889
2198
  }
1890
2199
  _createFDocumentParagraph(paragraphId, segmentId = "") {
1891
2200
  return this._injector.createInstance(FDocumentParagraph, this, paragraphId, segmentId, this._injector);
@@ -1951,14 +2260,15 @@ FDocument = __decorate([
1951
2260
  __decorateParam(1, Inject(Injector)),
1952
2261
  __decorateParam(2, IUniverInstanceService),
1953
2262
  __decorateParam(3, Inject(IResourceLoaderService)),
1954
- __decorateParam(4, ICommandService)
2263
+ __decorateParam(4, ICommandService),
2264
+ __decorateParam(5, IPermissionService)
1955
2265
  ], FDocument);
1956
2266
 
1957
2267
  //#endregion
1958
2268
  //#region src/facade/f-univer.ts
1959
2269
  var FUniverDocsMixin = class extends FUniver {
1960
- createDocument(data) {
1961
- const document = this._injector.get(IUniverInstanceService).createUnit(UniverInstanceType.UNIVER_DOC, data);
2270
+ createDocument(data, options) {
2271
+ const document = this._injector.get(IUniverInstanceService).createUnit(UniverInstanceType.UNIVER_DOC, data, options);
1962
2272
  return this._injector.createInstance(FDocument, document);
1963
2273
  }
1964
2274
  getActiveDocument() {
@@ -2005,4 +2315,4 @@ var FDocsEnumMixin = class extends FEnum {
2005
2315
  FEnum.extend(FDocsEnumMixin);
2006
2316
 
2007
2317
  //#endregion
2008
- export { DocsSectionUnsupportedDocumentFlavorError, FDocsEnumMixin, FDocument, FDocumentParagraph, FDocumentSection, FDocumentTextRange, isParagraphFacade, stripBlockTokens };
2318
+ export { DocsSectionUnsupportedDocumentFlavorError, FDocsEnumMixin, FDocument, FDocumentObjectPermission, FDocumentParagraph, FDocumentPermission, FDocumentSection, FDocumentTextRange, isParagraphFacade, stripBlockTokens };