@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/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,
|
|
247
|
+
function replaceBodyRange(range, insertBody, docDataModel, commandService) {
|
|
36
248
|
const { startOffset, endOffset, segmentId } = range;
|
|
37
|
-
const
|
|
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
|
-
|
|
259
|
+
debounce: false,
|
|
56
260
|
textRanges: [],
|
|
261
|
+
noNeedSetTextRange: true,
|
|
57
262
|
isEditing: false
|
|
58
263
|
});
|
|
59
|
-
return Boolean(
|
|
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.140.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.140.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
|
-
|
|
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
|
/**
|
|
@@ -232,7 +448,7 @@ var FDocumentTextRange = class extends FBaseInitialable {
|
|
|
232
448
|
* ```
|
|
233
449
|
*/
|
|
234
450
|
setText(text) {
|
|
235
|
-
return replaceBodyRange(this.getRange(), buildPlainTextInsertBody(text), this._document.getDocumentDataModel(), this.
|
|
451
|
+
return replaceBodyRange(this.getRange(), buildPlainTextInsertBody(text), this._document.getDocumentDataModel(), this._commandService);
|
|
236
452
|
}
|
|
237
453
|
_validateRange() {
|
|
238
454
|
const bodyLength = this._document.getBody(this._segmentId).dataStream.length;
|
|
@@ -259,37 +475,22 @@ var FDocumentTextRange = class extends FBaseInitialable {
|
|
|
259
475
|
return segments;
|
|
260
476
|
}
|
|
261
477
|
};
|
|
478
|
+
FDocumentTextRange = __decorate([__decorateParam(5, ICommandService)], FDocumentTextRange);
|
|
262
479
|
function isDeepEqual(left, right) {
|
|
263
480
|
return JSON.stringify(left) === JSON.stringify(right);
|
|
264
481
|
}
|
|
265
482
|
|
|
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
483
|
//#endregion
|
|
284
484
|
//#region src/facade/f-document-paragraph.ts
|
|
285
485
|
let FDocumentParagraph = class FDocumentParagraph extends FBaseInitialable {
|
|
286
|
-
constructor(_document, _paragraphId, _segmentId = "", _injector, _commandService) {
|
|
486
|
+
constructor(_document, _paragraphId, _segmentId = "", _injector, _commandService, _permissionService) {
|
|
287
487
|
super(_injector);
|
|
288
488
|
this._document = _document;
|
|
289
489
|
this._paragraphId = _paragraphId;
|
|
290
490
|
this._segmentId = _segmentId;
|
|
291
491
|
this._injector = _injector;
|
|
292
492
|
this._commandService = _commandService;
|
|
493
|
+
this._permissionService = _permissionService;
|
|
293
494
|
}
|
|
294
495
|
/**
|
|
295
496
|
* Get the persisted paragraph id.
|
|
@@ -320,6 +521,19 @@ let FDocumentParagraph = class FDocumentParagraph extends FBaseInitialable {
|
|
|
320
521
|
return this._segmentId;
|
|
321
522
|
}
|
|
322
523
|
/**
|
|
524
|
+
* Returns this Paragraph's permission facade.
|
|
525
|
+
* @returns {FDocumentObjectPermission} Permission facade combining Document, Section, and Paragraph Edit points.
|
|
526
|
+
* @example
|
|
527
|
+
* ```ts
|
|
528
|
+
* const paragraph = univerAPI.getActiveDocument()?.getParagraphs()[0];
|
|
529
|
+
* if (!paragraph) throw new Error('Paragraph not found.');
|
|
530
|
+
* await paragraph.getPermission().setReadOnly();
|
|
531
|
+
* ```
|
|
532
|
+
*/
|
|
533
|
+
getPermission() {
|
|
534
|
+
return new FDocumentObjectPermission(this._document.getId(), getDocumentParagraphPermissionObjectId(this._segmentId, this._paragraphId), this._commandService, this._permissionService, () => getDocumentParagraphParentPermissionObjectIds(this._document.getDocumentDataModel(), this._segmentId, this._paragraphId));
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
323
537
|
* Get this paragraph's metadata.
|
|
324
538
|
* @returns {IFDocumentParagraphInfo} The paragraph info.
|
|
325
539
|
* @example
|
|
@@ -477,7 +691,7 @@ let FDocumentParagraph = class FDocumentParagraph extends FBaseInitialable {
|
|
|
477
691
|
startOffset,
|
|
478
692
|
endOffset,
|
|
479
693
|
segmentId: this._segmentId
|
|
480
|
-
}, buildPlainTextInsertBody(text), this._document.getDocumentDataModel(), this.
|
|
694
|
+
}, buildPlainTextInsertBody(text), this._document.getDocumentDataModel(), this._commandService);
|
|
481
695
|
}
|
|
482
696
|
/**
|
|
483
697
|
* Append plain text before this paragraph's trailing paragraph break.
|
|
@@ -646,7 +860,7 @@ let FDocumentParagraph = class FDocumentParagraph extends FBaseInitialable {
|
|
|
646
860
|
body[RESTORE_INSERTED_PARAGRAPH_IDS] = true;
|
|
647
861
|
}
|
|
648
862
|
};
|
|
649
|
-
FDocumentParagraph = __decorate([__decorateParam(4, ICommandService)], FDocumentParagraph);
|
|
863
|
+
FDocumentParagraph = __decorate([__decorateParam(4, ICommandService), __decorateParam(5, IPermissionService)], FDocumentParagraph);
|
|
650
864
|
function isParagraphFacade(value) {
|
|
651
865
|
if (typeof value !== "object" || value === null) return false;
|
|
652
866
|
return typeof value.getId === "function" && typeof value.getSegmentId === "function" && typeof value.getInfo === "function" && typeof value.getRange === "function";
|
|
@@ -674,10 +888,11 @@ var DocsSectionUnsupportedDocumentFlavorError = class extends Error {
|
|
|
674
888
|
}
|
|
675
889
|
};
|
|
676
890
|
let FDocumentSection = class FDocumentSection {
|
|
677
|
-
constructor(_document, _sectionId, _commandService) {
|
|
891
|
+
constructor(_document, _sectionId, _commandService, _permissionService) {
|
|
678
892
|
this._document = _document;
|
|
679
893
|
this._sectionId = _sectionId;
|
|
680
894
|
this._commandService = _commandService;
|
|
895
|
+
this._permissionService = _permissionService;
|
|
681
896
|
}
|
|
682
897
|
/**
|
|
683
898
|
* Returns the persisted section id.
|
|
@@ -691,6 +906,19 @@ let FDocumentSection = class FDocumentSection {
|
|
|
691
906
|
return this._sectionId;
|
|
692
907
|
}
|
|
693
908
|
/**
|
|
909
|
+
* Returns this Section's permission facade.
|
|
910
|
+
* @returns {FDocumentObjectPermission} Permission facade combining Document and Section Edit points.
|
|
911
|
+
* @example
|
|
912
|
+
* ```ts
|
|
913
|
+
* const section = univerAPI.getActiveDocument()?.getSection(0);
|
|
914
|
+
* if (!section) throw new Error('Section not found.');
|
|
915
|
+
* await section.getPermission().setReadOnly();
|
|
916
|
+
* ```
|
|
917
|
+
*/
|
|
918
|
+
getPermission() {
|
|
919
|
+
return new FDocumentObjectPermission(this._document.getId(), getDocumentSectionPermissionObjectId("", this._sectionId), this._commandService, this._permissionService);
|
|
920
|
+
}
|
|
921
|
+
/**
|
|
694
922
|
* Returns the current zero-based section index.
|
|
695
923
|
* @example
|
|
696
924
|
* ```ts
|
|
@@ -1189,7 +1417,7 @@ let FDocumentSection = class FDocumentSection {
|
|
|
1189
1417
|
};
|
|
1190
1418
|
}
|
|
1191
1419
|
};
|
|
1192
|
-
FDocumentSection = __decorate([__decorateParam(2, ICommandService)], FDocumentSection);
|
|
1420
|
+
FDocumentSection = __decorate([__decorateParam(2, ICommandService), __decorateParam(3, IPermissionService)], FDocumentSection);
|
|
1193
1421
|
|
|
1194
1422
|
//#endregion
|
|
1195
1423
|
//#region \0@oxc-project+runtime@0.140.0/helpers/esm/typeof.js
|
|
@@ -1236,13 +1464,14 @@ function _defineProperty(e, r, t) {
|
|
|
1236
1464
|
//#endregion
|
|
1237
1465
|
//#region src/facade/f-document.ts
|
|
1238
1466
|
let FDocument = class FDocument extends FBaseInitialable {
|
|
1239
|
-
constructor(_documentDataModel, _injector, _univerInstanceService, _resourceLoaderService, _commandService) {
|
|
1467
|
+
constructor(_documentDataModel, _injector, _univerInstanceService, _resourceLoaderService, _commandService, _permissionService) {
|
|
1240
1468
|
super(_injector);
|
|
1241
1469
|
this._documentDataModel = _documentDataModel;
|
|
1242
1470
|
this._injector = _injector;
|
|
1243
1471
|
this._univerInstanceService = _univerInstanceService;
|
|
1244
1472
|
this._resourceLoaderService = _resourceLoaderService;
|
|
1245
1473
|
this._commandService = _commandService;
|
|
1474
|
+
this._permissionService = _permissionService;
|
|
1246
1475
|
_defineProperty(this, "id", void 0);
|
|
1247
1476
|
this.id = this._documentDataModel.getUnitId();
|
|
1248
1477
|
}
|
|
@@ -1323,6 +1552,40 @@ let FDocument = class FDocument extends FBaseInitialable {
|
|
|
1323
1552
|
return this.id;
|
|
1324
1553
|
}
|
|
1325
1554
|
/**
|
|
1555
|
+
* Returns the Document unit permission facade.
|
|
1556
|
+
* @returns {FDocumentPermission} Permission facade for Edit, Copy, Print, Export, and Comment.
|
|
1557
|
+
* @example
|
|
1558
|
+
* ```ts
|
|
1559
|
+
* const document = univerAPI.getActiveDocument();
|
|
1560
|
+
* if (!document) throw new Error('No active Document.');
|
|
1561
|
+
* await document.getPermission().setReadOnly();
|
|
1562
|
+
* ```
|
|
1563
|
+
*/
|
|
1564
|
+
getPermission() {
|
|
1565
|
+
return new FDocumentPermission(this.id, this._commandService, this._permissionService);
|
|
1566
|
+
}
|
|
1567
|
+
/**
|
|
1568
|
+
* Returns the permission facade for an entity with a stable id, such as a Table, Drawing, or Custom Block.
|
|
1569
|
+
*
|
|
1570
|
+
* Parent Section and Paragraph permission ceilings are resolved from the current Document model.
|
|
1571
|
+
* @param {string} segmentId Segment id, or an empty string for the main body.
|
|
1572
|
+
* @param {string} entityType Stable entity type used by the owning Doc feature.
|
|
1573
|
+
* @param {string} entityId Stable entity id.
|
|
1574
|
+
* @returns {FDocumentObjectPermission} Effective permission facade for the entity.
|
|
1575
|
+
* @example Make one drawing read-only
|
|
1576
|
+
* ```ts
|
|
1577
|
+
* const document = univerAPI.getActiveDocument();
|
|
1578
|
+
* if (!document) throw new Error('No active Document.');
|
|
1579
|
+
* const snapshot = document.getDocumentDataModel().getSnapshot();
|
|
1580
|
+
* const drawingId = snapshot.drawingsOrder?.[0];
|
|
1581
|
+
* if (!drawingId) throw new Error('Drawing not found.');
|
|
1582
|
+
* await document.getEntityPermission('', 'drawing', drawingId).setReadOnly();
|
|
1583
|
+
* ```
|
|
1584
|
+
*/
|
|
1585
|
+
getEntityPermission(segmentId, entityType, entityId) {
|
|
1586
|
+
return new FDocumentObjectPermission(this.id, getDocumentEntityPermissionObjectId(segmentId, entityType, entityId), this._commandService, this._permissionService, () => getDocumentEntityParentPermissionObjectIds(this._documentDataModel, segmentId, entityType, entityId));
|
|
1587
|
+
}
|
|
1588
|
+
/**
|
|
1326
1589
|
* Get the document name.
|
|
1327
1590
|
* @returns {string} The document name.
|
|
1328
1591
|
* @example
|
|
@@ -1509,7 +1772,7 @@ let FDocument = class FDocument extends FBaseInitialable {
|
|
|
1509
1772
|
startOffset: index,
|
|
1510
1773
|
endOffset: index,
|
|
1511
1774
|
segmentId
|
|
1512
|
-
}, buildPlainTextInsertBody(text), this._documentDataModel, this.
|
|
1775
|
+
}, buildPlainTextInsertBody(text), this._documentDataModel, this._commandService);
|
|
1513
1776
|
}
|
|
1514
1777
|
/**
|
|
1515
1778
|
* Returns document-level header/footer switches and margins. Margin values use 96-DPI layout pixels.
|
|
@@ -1730,7 +1993,7 @@ let FDocument = class FDocument extends FBaseInitialable {
|
|
|
1730
1993
|
}, {
|
|
1731
1994
|
dataStream: DataStreamTreeTokenType.PARAGRAPH,
|
|
1732
1995
|
paragraphs
|
|
1733
|
-
}, this._documentDataModel, this.
|
|
1996
|
+
}, this._documentDataModel, this._commandService) ? this.getParagraph(paragraphId, segmentId) : null;
|
|
1734
1997
|
}
|
|
1735
1998
|
/**
|
|
1736
1999
|
* Get all paragraphs in the document body or header/footer body by the segment id.
|
|
@@ -1843,7 +2106,7 @@ let FDocument = class FDocument extends FBaseInitialable {
|
|
|
1843
2106
|
startOffset: offset,
|
|
1844
2107
|
endOffset: offset,
|
|
1845
2108
|
segmentId
|
|
1846
|
-
}, buildPlainTextInsertBody(`${text}\r`), this._documentDataModel, this.
|
|
2109
|
+
}, buildPlainTextInsertBody(`${text}\r`), this._documentDataModel, this._commandService)) throw new Error("Failed to insert paragraph.");
|
|
1847
2110
|
const { paragraphs = [] } = this.getBody(segmentId);
|
|
1848
2111
|
const paragraph = paragraphs[index];
|
|
1849
2112
|
if (!paragraph) throw new Error("Failed to insert paragraph.");
|
|
@@ -1885,7 +2148,7 @@ let FDocument = class FDocument extends FBaseInitialable {
|
|
|
1885
2148
|
deleteRange(range) {
|
|
1886
2149
|
const normalizedRange = this._normalizeDeleteRange(range);
|
|
1887
2150
|
if (normalizedRange.startOffset >= normalizedRange.endOffset) return false;
|
|
1888
|
-
return replaceBodyRange(normalizedRange, { dataStream: "" }, this._documentDataModel, this.
|
|
2151
|
+
return replaceBodyRange(normalizedRange, { dataStream: "" }, this._documentDataModel, this._commandService);
|
|
1889
2152
|
}
|
|
1890
2153
|
_createFDocumentParagraph(paragraphId, segmentId = "") {
|
|
1891
2154
|
return this._injector.createInstance(FDocumentParagraph, this, paragraphId, segmentId, this._injector);
|
|
@@ -1951,14 +2214,15 @@ FDocument = __decorate([
|
|
|
1951
2214
|
__decorateParam(1, Inject(Injector)),
|
|
1952
2215
|
__decorateParam(2, IUniverInstanceService),
|
|
1953
2216
|
__decorateParam(3, Inject(IResourceLoaderService)),
|
|
1954
|
-
__decorateParam(4, ICommandService)
|
|
2217
|
+
__decorateParam(4, ICommandService),
|
|
2218
|
+
__decorateParam(5, IPermissionService)
|
|
1955
2219
|
], FDocument);
|
|
1956
2220
|
|
|
1957
2221
|
//#endregion
|
|
1958
2222
|
//#region src/facade/f-univer.ts
|
|
1959
2223
|
var FUniverDocsMixin = class extends FUniver {
|
|
1960
|
-
createDocument(data) {
|
|
1961
|
-
const document = this._injector.get(IUniverInstanceService).createUnit(UniverInstanceType.UNIVER_DOC, data);
|
|
2224
|
+
createDocument(data, options) {
|
|
2225
|
+
const document = this._injector.get(IUniverInstanceService).createUnit(UniverInstanceType.UNIVER_DOC, data, options);
|
|
1962
2226
|
return this._injector.createInstance(FDocument, document);
|
|
1963
2227
|
}
|
|
1964
2228
|
getActiveDocument() {
|
|
@@ -2005,4 +2269,4 @@ var FDocsEnumMixin = class extends FEnum {
|
|
|
2005
2269
|
FEnum.extend(FDocsEnumMixin);
|
|
2006
2270
|
|
|
2007
2271
|
//#endregion
|
|
2008
|
-
export { DocsSectionUnsupportedDocumentFlavorError, FDocsEnumMixin, FDocument, FDocumentParagraph, FDocumentSection, FDocumentTextRange, isParagraphFacade, stripBlockTokens };
|
|
2272
|
+
export { DocsSectionUnsupportedDocumentFlavorError, FDocsEnumMixin, FDocument, FDocumentObjectPermission, FDocumentParagraph, FDocumentPermission, FDocumentSection, FDocumentTextRange, isParagraphFacade, stripBlockTokens };
|