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