@univerjs/docs 1.0.0-insiders.20260809-70eefdd → 1.0.0-rc.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 +331 -60
- package/lib/cjs/index.js +2472 -102
- package/lib/es/facade.js +326 -62
- package/lib/es/index.js +2419 -85
- package/lib/facade.js +326 -62
- package/lib/index.js +2419 -85
- 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 +20 -1
- package/lib/types/commands/mutations/doc-structure-mutation-validation.d.ts +17 -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 +15 -2
- package/lib/types/facade/f-document-text-range.d.ts +3 -1
- package/lib/types/facade/f-document.d.ts +34 -2
- package/lib/types/facade/f-univer.d.ts +4 -3
- 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 +24 -0
- package/lib/types/layout-worker/document-font-metrics.d.ts +18 -0
- package/lib/types/layout-worker/index.d.ts +70 -0
- package/lib/types/layout-worker/performance-tracker.d.ts +27 -0
- package/lib/types/layout-worker/protocol.d.ts +35 -0
- package/lib/types/layout-worker/worker.d.ts +49 -0
- package/lib/types/services/doc-interceptor/interceptor-const.d.ts +2 -1
- package/lib/types/services/doc-layout-executor.service.d.ts +218 -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 +1 -0
- package/lib/types/services/doc-state-emit.service.d.ts +4 -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.140.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.140.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
|
/**
|
|
@@ -233,7 +449,7 @@ var FDocumentTextRange = class extends _univerjs_core_facade.FBaseInitialable {
|
|
|
233
449
|
* ```
|
|
234
450
|
*/
|
|
235
451
|
setText(text) {
|
|
236
|
-
return replaceBodyRange(this.getRange(), buildPlainTextInsertBody(text), this._document.getDocumentDataModel(), this.
|
|
452
|
+
return replaceBodyRange(this.getRange(), buildPlainTextInsertBody(text), this._document.getDocumentDataModel(), this._commandService);
|
|
237
453
|
}
|
|
238
454
|
_validateRange() {
|
|
239
455
|
const bodyLength = this._document.getBody(this._segmentId).dataStream.length;
|
|
@@ -260,37 +476,22 @@ var FDocumentTextRange = class extends _univerjs_core_facade.FBaseInitialable {
|
|
|
260
476
|
return segments;
|
|
261
477
|
}
|
|
262
478
|
};
|
|
479
|
+
FDocumentTextRange = __decorate([__decorateParam(5, _univerjs_core.ICommandService)], FDocumentTextRange);
|
|
263
480
|
function isDeepEqual(left, right) {
|
|
264
481
|
return JSON.stringify(left) === JSON.stringify(right);
|
|
265
482
|
}
|
|
266
483
|
|
|
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
484
|
//#endregion
|
|
285
485
|
//#region src/facade/f-document-paragraph.ts
|
|
286
486
|
let FDocumentParagraph = class FDocumentParagraph extends _univerjs_core_facade.FBaseInitialable {
|
|
287
|
-
constructor(_document, _paragraphId, _segmentId = "", _injector, _commandService) {
|
|
487
|
+
constructor(_document, _paragraphId, _segmentId = "", _injector, _commandService, _permissionService) {
|
|
288
488
|
super(_injector);
|
|
289
489
|
this._document = _document;
|
|
290
490
|
this._paragraphId = _paragraphId;
|
|
291
491
|
this._segmentId = _segmentId;
|
|
292
492
|
this._injector = _injector;
|
|
293
493
|
this._commandService = _commandService;
|
|
494
|
+
this._permissionService = _permissionService;
|
|
294
495
|
}
|
|
295
496
|
/**
|
|
296
497
|
* Get the persisted paragraph id.
|
|
@@ -321,6 +522,19 @@ let FDocumentParagraph = class FDocumentParagraph extends _univerjs_core_facade.
|
|
|
321
522
|
return this._segmentId;
|
|
322
523
|
}
|
|
323
524
|
/**
|
|
525
|
+
* Returns this Paragraph's permission facade.
|
|
526
|
+
* @returns {FDocumentObjectPermission} Permission facade combining Document, Section, and Paragraph Edit points.
|
|
527
|
+
* @example
|
|
528
|
+
* ```ts
|
|
529
|
+
* const paragraph = univerAPI.getActiveDocument()?.getParagraphs()[0];
|
|
530
|
+
* if (!paragraph) throw new Error('Paragraph not found.');
|
|
531
|
+
* await paragraph.getPermission().setReadOnly();
|
|
532
|
+
* ```
|
|
533
|
+
*/
|
|
534
|
+
getPermission() {
|
|
535
|
+
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));
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
324
538
|
* Get this paragraph's metadata.
|
|
325
539
|
* @returns {IFDocumentParagraphInfo} The paragraph info.
|
|
326
540
|
* @example
|
|
@@ -478,7 +692,7 @@ let FDocumentParagraph = class FDocumentParagraph extends _univerjs_core_facade.
|
|
|
478
692
|
startOffset,
|
|
479
693
|
endOffset,
|
|
480
694
|
segmentId: this._segmentId
|
|
481
|
-
}, buildPlainTextInsertBody(text), this._document.getDocumentDataModel(), this.
|
|
695
|
+
}, buildPlainTextInsertBody(text), this._document.getDocumentDataModel(), this._commandService);
|
|
482
696
|
}
|
|
483
697
|
/**
|
|
484
698
|
* Append plain text before this paragraph's trailing paragraph break.
|
|
@@ -647,7 +861,7 @@ let FDocumentParagraph = class FDocumentParagraph extends _univerjs_core_facade.
|
|
|
647
861
|
body[_univerjs_core.RESTORE_INSERTED_PARAGRAPH_IDS] = true;
|
|
648
862
|
}
|
|
649
863
|
};
|
|
650
|
-
FDocumentParagraph = __decorate([__decorateParam(4, _univerjs_core.ICommandService)], FDocumentParagraph);
|
|
864
|
+
FDocumentParagraph = __decorate([__decorateParam(4, _univerjs_core.ICommandService), __decorateParam(5, _univerjs_core.IPermissionService)], FDocumentParagraph);
|
|
651
865
|
function isParagraphFacade(value) {
|
|
652
866
|
if (typeof value !== "object" || value === null) return false;
|
|
653
867
|
return typeof value.getId === "function" && typeof value.getSegmentId === "function" && typeof value.getInfo === "function" && typeof value.getRange === "function";
|
|
@@ -675,10 +889,11 @@ var DocsSectionUnsupportedDocumentFlavorError = class extends Error {
|
|
|
675
889
|
}
|
|
676
890
|
};
|
|
677
891
|
let FDocumentSection = class FDocumentSection {
|
|
678
|
-
constructor(_document, _sectionId, _commandService) {
|
|
892
|
+
constructor(_document, _sectionId, _commandService, _permissionService) {
|
|
679
893
|
this._document = _document;
|
|
680
894
|
this._sectionId = _sectionId;
|
|
681
895
|
this._commandService = _commandService;
|
|
896
|
+
this._permissionService = _permissionService;
|
|
682
897
|
}
|
|
683
898
|
/**
|
|
684
899
|
* Returns the persisted section id.
|
|
@@ -692,6 +907,19 @@ let FDocumentSection = class FDocumentSection {
|
|
|
692
907
|
return this._sectionId;
|
|
693
908
|
}
|
|
694
909
|
/**
|
|
910
|
+
* Returns this Section's permission facade.
|
|
911
|
+
* @returns {FDocumentObjectPermission} Permission facade combining Document and Section Edit points.
|
|
912
|
+
* @example
|
|
913
|
+
* ```ts
|
|
914
|
+
* const section = univerAPI.getActiveDocument()?.getSection(0);
|
|
915
|
+
* if (!section) throw new Error('Section not found.');
|
|
916
|
+
* await section.getPermission().setReadOnly();
|
|
917
|
+
* ```
|
|
918
|
+
*/
|
|
919
|
+
getPermission() {
|
|
920
|
+
return new FDocumentObjectPermission(this._document.getId(), (0, _univerjs_docs.getDocumentSectionPermissionObjectId)("", this._sectionId), this._commandService, this._permissionService);
|
|
921
|
+
}
|
|
922
|
+
/**
|
|
695
923
|
* Returns the current zero-based section index.
|
|
696
924
|
* @example
|
|
697
925
|
* ```ts
|
|
@@ -1190,7 +1418,7 @@ let FDocumentSection = class FDocumentSection {
|
|
|
1190
1418
|
};
|
|
1191
1419
|
}
|
|
1192
1420
|
};
|
|
1193
|
-
FDocumentSection = __decorate([__decorateParam(2, _univerjs_core.ICommandService)], FDocumentSection);
|
|
1421
|
+
FDocumentSection = __decorate([__decorateParam(2, _univerjs_core.ICommandService), __decorateParam(3, _univerjs_core.IPermissionService)], FDocumentSection);
|
|
1194
1422
|
|
|
1195
1423
|
//#endregion
|
|
1196
1424
|
//#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
|
|
@@ -1237,13 +1465,14 @@ function _defineProperty(e, r, t) {
|
|
|
1237
1465
|
//#endregion
|
|
1238
1466
|
//#region src/facade/f-document.ts
|
|
1239
1467
|
let FDocument = class FDocument extends _univerjs_core_facade.FBaseInitialable {
|
|
1240
|
-
constructor(_documentDataModel, _injector, _univerInstanceService, _resourceLoaderService, _commandService) {
|
|
1468
|
+
constructor(_documentDataModel, _injector, _univerInstanceService, _resourceLoaderService, _commandService, _permissionService) {
|
|
1241
1469
|
super(_injector);
|
|
1242
1470
|
this._documentDataModel = _documentDataModel;
|
|
1243
1471
|
this._injector = _injector;
|
|
1244
1472
|
this._univerInstanceService = _univerInstanceService;
|
|
1245
1473
|
this._resourceLoaderService = _resourceLoaderService;
|
|
1246
1474
|
this._commandService = _commandService;
|
|
1475
|
+
this._permissionService = _permissionService;
|
|
1247
1476
|
_defineProperty(this, "id", void 0);
|
|
1248
1477
|
this.id = this._documentDataModel.getUnitId();
|
|
1249
1478
|
}
|
|
@@ -1324,6 +1553,40 @@ let FDocument = class FDocument extends _univerjs_core_facade.FBaseInitialable {
|
|
|
1324
1553
|
return this.id;
|
|
1325
1554
|
}
|
|
1326
1555
|
/**
|
|
1556
|
+
* Returns the Document unit permission facade.
|
|
1557
|
+
* @returns {FDocumentPermission} Permission facade for Edit, Copy, Print, Export, and Comment.
|
|
1558
|
+
* @example
|
|
1559
|
+
* ```ts
|
|
1560
|
+
* const document = univerAPI.getActiveDocument();
|
|
1561
|
+
* if (!document) throw new Error('No active Document.');
|
|
1562
|
+
* await document.getPermission().setReadOnly();
|
|
1563
|
+
* ```
|
|
1564
|
+
*/
|
|
1565
|
+
getPermission() {
|
|
1566
|
+
return new FDocumentPermission(this.id, this._commandService, this._permissionService);
|
|
1567
|
+
}
|
|
1568
|
+
/**
|
|
1569
|
+
* Returns the permission facade for an entity with a stable id, such as a Table, Drawing, or Custom Block.
|
|
1570
|
+
*
|
|
1571
|
+
* Parent Section and Paragraph permission ceilings are resolved from the current Document model.
|
|
1572
|
+
* @param {string} segmentId Segment id, or an empty string for the main body.
|
|
1573
|
+
* @param {string} entityType Stable entity type used by the owning Doc feature.
|
|
1574
|
+
* @param {string} entityId Stable entity id.
|
|
1575
|
+
* @returns {FDocumentObjectPermission} Effective permission facade for the entity.
|
|
1576
|
+
* @example Make one drawing read-only
|
|
1577
|
+
* ```ts
|
|
1578
|
+
* const document = univerAPI.getActiveDocument();
|
|
1579
|
+
* if (!document) throw new Error('No active Document.');
|
|
1580
|
+
* const snapshot = document.getDocumentDataModel().getSnapshot();
|
|
1581
|
+
* const drawingId = snapshot.drawingsOrder?.[0];
|
|
1582
|
+
* if (!drawingId) throw new Error('Drawing not found.');
|
|
1583
|
+
* await document.getEntityPermission('', 'drawing', drawingId).setReadOnly();
|
|
1584
|
+
* ```
|
|
1585
|
+
*/
|
|
1586
|
+
getEntityPermission(segmentId, entityType, entityId) {
|
|
1587
|
+
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));
|
|
1588
|
+
}
|
|
1589
|
+
/**
|
|
1327
1590
|
* Get the document name.
|
|
1328
1591
|
* @returns {string} The document name.
|
|
1329
1592
|
* @example
|
|
@@ -1510,7 +1773,7 @@ let FDocument = class FDocument extends _univerjs_core_facade.FBaseInitialable {
|
|
|
1510
1773
|
startOffset: index,
|
|
1511
1774
|
endOffset: index,
|
|
1512
1775
|
segmentId
|
|
1513
|
-
}, buildPlainTextInsertBody(text), this._documentDataModel, this.
|
|
1776
|
+
}, buildPlainTextInsertBody(text), this._documentDataModel, this._commandService);
|
|
1514
1777
|
}
|
|
1515
1778
|
/**
|
|
1516
1779
|
* Returns document-level header/footer switches and margins. Margin values use 96-DPI layout pixels.
|
|
@@ -1731,7 +1994,7 @@ let FDocument = class FDocument extends _univerjs_core_facade.FBaseInitialable {
|
|
|
1731
1994
|
}, {
|
|
1732
1995
|
dataStream: _univerjs_core.DataStreamTreeTokenType.PARAGRAPH,
|
|
1733
1996
|
paragraphs
|
|
1734
|
-
}, this._documentDataModel, this.
|
|
1997
|
+
}, this._documentDataModel, this._commandService) ? this.getParagraph(paragraphId, segmentId) : null;
|
|
1735
1998
|
}
|
|
1736
1999
|
/**
|
|
1737
2000
|
* Get all paragraphs in the document body or header/footer body by the segment id.
|
|
@@ -1844,7 +2107,7 @@ let FDocument = class FDocument extends _univerjs_core_facade.FBaseInitialable {
|
|
|
1844
2107
|
startOffset: offset,
|
|
1845
2108
|
endOffset: offset,
|
|
1846
2109
|
segmentId
|
|
1847
|
-
}, buildPlainTextInsertBody(`${text}\r`), this._documentDataModel, this.
|
|
2110
|
+
}, buildPlainTextInsertBody(`${text}\r`), this._documentDataModel, this._commandService)) throw new Error("Failed to insert paragraph.");
|
|
1848
2111
|
const { paragraphs = [] } = this.getBody(segmentId);
|
|
1849
2112
|
const paragraph = paragraphs[index];
|
|
1850
2113
|
if (!paragraph) throw new Error("Failed to insert paragraph.");
|
|
@@ -1886,7 +2149,7 @@ let FDocument = class FDocument extends _univerjs_core_facade.FBaseInitialable {
|
|
|
1886
2149
|
deleteRange(range) {
|
|
1887
2150
|
const normalizedRange = this._normalizeDeleteRange(range);
|
|
1888
2151
|
if (normalizedRange.startOffset >= normalizedRange.endOffset) return false;
|
|
1889
|
-
return replaceBodyRange(normalizedRange, { dataStream: "" }, this._documentDataModel, this.
|
|
2152
|
+
return replaceBodyRange(normalizedRange, { dataStream: "" }, this._documentDataModel, this._commandService);
|
|
1890
2153
|
}
|
|
1891
2154
|
_createFDocumentParagraph(paragraphId, segmentId = "") {
|
|
1892
2155
|
return this._injector.createInstance(FDocumentParagraph, this, paragraphId, segmentId, this._injector);
|
|
@@ -1952,14 +2215,15 @@ FDocument = __decorate([
|
|
|
1952
2215
|
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
|
|
1953
2216
|
__decorateParam(2, _univerjs_core.IUniverInstanceService),
|
|
1954
2217
|
__decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_core.IResourceLoaderService)),
|
|
1955
|
-
__decorateParam(4, _univerjs_core.ICommandService)
|
|
2218
|
+
__decorateParam(4, _univerjs_core.ICommandService),
|
|
2219
|
+
__decorateParam(5, _univerjs_core.IPermissionService)
|
|
1956
2220
|
], FDocument);
|
|
1957
2221
|
|
|
1958
2222
|
//#endregion
|
|
1959
2223
|
//#region src/facade/f-univer.ts
|
|
1960
2224
|
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);
|
|
2225
|
+
createDocument(data, options) {
|
|
2226
|
+
const document = this._injector.get(_univerjs_core.IUniverInstanceService).createUnit(_univerjs_core.UniverInstanceType.UNIVER_DOC, data, options);
|
|
1963
2227
|
return this._injector.createInstance(FDocument, document);
|
|
1964
2228
|
}
|
|
1965
2229
|
getActiveDocument() {
|
|
@@ -2014,18 +2278,25 @@ Object.defineProperty(exports, 'FDocument', {
|
|
|
2014
2278
|
return FDocument;
|
|
2015
2279
|
}
|
|
2016
2280
|
});
|
|
2281
|
+
exports.FDocumentObjectPermission = FDocumentObjectPermission;
|
|
2017
2282
|
Object.defineProperty(exports, 'FDocumentParagraph', {
|
|
2018
2283
|
enumerable: true,
|
|
2019
2284
|
get: function () {
|
|
2020
2285
|
return FDocumentParagraph;
|
|
2021
2286
|
}
|
|
2022
2287
|
});
|
|
2288
|
+
exports.FDocumentPermission = FDocumentPermission;
|
|
2023
2289
|
Object.defineProperty(exports, 'FDocumentSection', {
|
|
2024
2290
|
enumerable: true,
|
|
2025
2291
|
get: function () {
|
|
2026
2292
|
return FDocumentSection;
|
|
2027
2293
|
}
|
|
2028
2294
|
});
|
|
2029
|
-
exports
|
|
2295
|
+
Object.defineProperty(exports, 'FDocumentTextRange', {
|
|
2296
|
+
enumerable: true,
|
|
2297
|
+
get: function () {
|
|
2298
|
+
return FDocumentTextRange;
|
|
2299
|
+
}
|
|
2300
|
+
});
|
|
2030
2301
|
exports.isParagraphFacade = isParagraphFacade;
|
|
2031
2302
|
exports.stripBlockTokens = stripBlockTokens;
|