@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
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import type { ICommand, IDocumentBody, IDocumentData, ITextRange, UpdateDocsAttributeType } from '@univerjs/core';
|
|
16
|
+
import type { ICommand, IDocumentBody, IDocumentData, ITextRange, Nullable, UpdateDocsAttributeType } from '@univerjs/core';
|
|
17
17
|
import type { ITextRangeWithStyle } from '@univerjs/engine-render';
|
|
18
18
|
import { DeleteDirection } from '@univerjs/core';
|
|
19
19
|
export interface IInsertTextCommandParams {
|
|
@@ -22,6 +22,10 @@ export interface IInsertTextCommandParams {
|
|
|
22
22
|
range: ITextRange;
|
|
23
23
|
segmentId?: string;
|
|
24
24
|
cursorOffset?: number;
|
|
25
|
+
debounce?: boolean;
|
|
26
|
+
textRanges?: Nullable<ITextRangeWithStyle[]>;
|
|
27
|
+
noNeedSetTextRange?: boolean;
|
|
28
|
+
isEditing?: boolean;
|
|
25
29
|
}
|
|
26
30
|
/**
|
|
27
31
|
* The command to insert text. The changed range could be non-collapsed, mainly use in line break and normal input.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { ICommand, IObjectPermissionPolicy } from '@univerjs/core';
|
|
17
|
+
import type { DocumentUnitPermissionAction } from '../../services/permission/document-permission';
|
|
18
|
+
export interface ISetDocumentPermissionCommandParams {
|
|
19
|
+
unitId: string;
|
|
20
|
+
objectId: string;
|
|
21
|
+
action: DocumentUnitPermissionAction;
|
|
22
|
+
value: boolean;
|
|
23
|
+
policy?: IObjectPermissionPolicy;
|
|
24
|
+
/** Remove the child permission rule and restore inherited rights; never deletes content. */
|
|
25
|
+
remove?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare const SetDocumentPermissionCommand: ICommand<ISetDocumentPermissionCommandParams>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { ICommand, IObjectPermissionBatchResult, ISetObjectPermissionsCommandParams } from '@univerjs/core';
|
|
17
|
+
export declare const SetDocumentPermissionsCommand: ICommand<ISetObjectPermissionsCommandParams, IObjectPermissionBatchResult>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export declare const RICH_TEXT_EDITING_MUTATION_ID = "doc.mutation.rich-text-editing";
|
|
@@ -13,10 +13,23 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import type { IMutation, IMutationCommonParams, JSONXActions, Nullable } from '@univerjs/core';
|
|
16
|
+
import type { IMutation, IMutationCommonParams, JSONXActions, Nullable, TPriority } from '@univerjs/core';
|
|
17
17
|
import type { ITextRangeWithStyle } from '@univerjs/engine-render';
|
|
18
|
+
export declare enum DocHistoryAction {
|
|
19
|
+
DeleteChart = "delete-chart",
|
|
20
|
+
DeleteDivider = "delete-divider",
|
|
21
|
+
DeleteImage = "delete-image",
|
|
22
|
+
DeleteShape = "delete-shape",
|
|
23
|
+
EditTableCell = "edit-table-cell",
|
|
24
|
+
FormatParagraph = "format-paragraph",
|
|
25
|
+
InsertCustomRange = "insert-custom-range",
|
|
26
|
+
UpdateImage = "update-image",
|
|
27
|
+
UpdatePageLayout = "update-page-layout"
|
|
28
|
+
}
|
|
18
29
|
export interface IRichTextEditingMutationParams extends IMutationCommonParams {
|
|
19
30
|
unitId: string;
|
|
31
|
+
historyAction?: string;
|
|
32
|
+
historyActions?: string[];
|
|
20
33
|
actions: JSONXActions;
|
|
21
34
|
textRanges: Nullable<ITextRangeWithStyle[]>;
|
|
22
35
|
segmentId?: string;
|
|
@@ -32,6 +45,12 @@ export interface IRichTextEditingMutationParams extends IMutationCommonParams {
|
|
|
32
45
|
isEditing?: boolean;
|
|
33
46
|
syncer?: string;
|
|
34
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Transforms document selections through the same JSONX actions applied by a rich-text mutation.
|
|
50
|
+
* Collaboration and rendering use this shared offset rule so the Main interaction window follows
|
|
51
|
+
* the transformed local caret before an authoritative background layout is published.
|
|
52
|
+
*/
|
|
53
|
+
export declare function transformDocumentTextRanges(actions: JSONXActions, textRanges: ITextRangeWithStyle[], priority?: TPriority): ITextRangeWithStyle[];
|
|
35
54
|
/**
|
|
36
55
|
* The core mutator to change rich text actions. The execution result would be undo mutation params. Could be directly
|
|
37
56
|
* send to undo redo service (will be used by the triggering command).
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { DocumentDataModel, JSONXActions } from '@univerjs/core';
|
|
17
|
+
export declare function validateDocStructureMutation(documentDataModel: DocumentDataModel, segmentId: string, actions: JSONXActions, undoActions: JSONXActions): boolean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { IMutation, ISetObjectPermissionRuleMutationParams } from '@univerjs/core';
|
|
17
|
+
export declare const SetDocumentPermissionRuleMutation: IMutation<ISetObjectPermissionRuleMutationParams>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { IMutation, ISetObjectPermissionRulesMutationParams } from '@univerjs/core';
|
|
17
|
+
export declare const SetDocumentPermissionRulesMutation: IMutation<ISetObjectPermissionRulesMutationParams>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import { Disposable, ICommandService, Injector, IPermissionService, IUniverInstanceService } from '@univerjs/core';
|
|
17
|
+
export declare class DocPermissionController extends Disposable {
|
|
18
|
+
private readonly _injector;
|
|
19
|
+
private readonly _commandService;
|
|
20
|
+
private readonly _permissionService;
|
|
21
|
+
private readonly _univerInstanceService;
|
|
22
|
+
constructor(_injector: Injector, _commandService: ICommandService, _permissionService: IPermissionService, _univerInstanceService: IUniverInstanceService);
|
|
23
|
+
private _registerUnitPermissionPoints;
|
|
24
|
+
private _check;
|
|
25
|
+
private _resolveTargetObjectIds;
|
|
26
|
+
}
|
|
@@ -16,8 +16,9 @@
|
|
|
16
16
|
import type { Injector, IParagraph, IParagraphStyle } from '@univerjs/core';
|
|
17
17
|
import type { FDocument } from './f-document';
|
|
18
18
|
import type { IFDocumentTextRange } from './utils';
|
|
19
|
-
import { ICommandService } from '@univerjs/core';
|
|
19
|
+
import { ICommandService, IPermissionService } from '@univerjs/core';
|
|
20
20
|
import { FBaseInitialable } from '@univerjs/core/facade';
|
|
21
|
+
import { FDocumentObjectPermission } from './f-document-permission';
|
|
21
22
|
import { FDocumentTextRange } from './f-document-text-range';
|
|
22
23
|
/**
|
|
23
24
|
* Resolved paragraph metadata in the the document body.
|
|
@@ -62,7 +63,8 @@ export declare class FDocumentParagraph extends FBaseInitialable {
|
|
|
62
63
|
protected readonly _segmentId: string;
|
|
63
64
|
protected readonly _injector: Injector;
|
|
64
65
|
private readonly _commandService;
|
|
65
|
-
|
|
66
|
+
private readonly _permissionService;
|
|
67
|
+
constructor(_document: FDocument, _paragraphId: string, _segmentId: string | undefined, _injector: Injector, _commandService: ICommandService, _permissionService: IPermissionService);
|
|
66
68
|
/**
|
|
67
69
|
* Get the persisted paragraph id.
|
|
68
70
|
* @returns {string} The paragraph id.
|
|
@@ -87,6 +89,17 @@ export declare class FDocumentParagraph extends FBaseInitialable {
|
|
|
87
89
|
* ```
|
|
88
90
|
*/
|
|
89
91
|
getSegmentId(): string;
|
|
92
|
+
/**
|
|
93
|
+
* Returns this Paragraph's permission facade.
|
|
94
|
+
* @returns {FDocumentObjectPermission} Permission facade combining Document, Section, and Paragraph Edit points.
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* const paragraph = univerAPI.getActiveDocument()?.getParagraphs()[0];
|
|
98
|
+
* if (!paragraph) throw new Error('Paragraph not found.');
|
|
99
|
+
* await paragraph.getPermission().setReadOnly();
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
getPermission(): FDocumentObjectPermission;
|
|
90
103
|
/**
|
|
91
104
|
* Get this paragraph's metadata.
|
|
92
105
|
* @returns {IFDocumentParagraphInfo} The paragraph info.
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type { ICommandService, IObjectPermissionBatchResult, IObjectPermissionChange, IPermissionService } from '@univerjs/core';
|
|
17
|
+
import type { DocumentUnitPermissionAction } from '@univerjs/docs';
|
|
18
|
+
/**
|
|
19
|
+
* Command-backed permissions for one Document unit.
|
|
20
|
+
* @hideconstructor
|
|
21
|
+
*/
|
|
22
|
+
export declare class FDocumentPermission {
|
|
23
|
+
private readonly _unitId;
|
|
24
|
+
private readonly _commandService;
|
|
25
|
+
private readonly _permissionService;
|
|
26
|
+
constructor(_unitId: string, _commandService: ICommandService, _permissionService: IPermissionService);
|
|
27
|
+
/**
|
|
28
|
+
* Creates or updates child-object edit policies in this unit; policy: null removes protection and restores inheritance.
|
|
29
|
+
*
|
|
30
|
+
* Requires Authz support and objectPermissionTypes configured for every target type. File and parent restrictions
|
|
31
|
+
* still apply. Use the exported permission object ID helpers, not raw object IDs or server permission IDs.
|
|
32
|
+
* The batch must be nonempty, contain distinct objects, and belong to this unit; file-wide policies are excluded.
|
|
33
|
+
* Other targets use getDocumentSectionPermissionObjectId and getDocumentEntityPermissionObjectId.
|
|
34
|
+
*
|
|
35
|
+
* edit: 'all' allows Unit editors, 'owner' restricts editing to the object owner, and 'members' selects existing
|
|
36
|
+
* Unit collaborators. Pass their collaborator records from the member service; this does not invite new users.
|
|
37
|
+
* Use strategies: [] for the default Edit strategy; child-object strategies support only UnitAction.Edit.
|
|
38
|
+
*
|
|
39
|
+
* Authz writes execute per object and can partially succeed. Inspect failed before retrying only those objects.
|
|
40
|
+
* refreshError means writes finished but permission readback failed; do not retry succeeded objects for that error.
|
|
41
|
+
* Successful binding changes share one undo entry; existing remote policy edits are not undoable.
|
|
42
|
+
* @param {IObjectPermissionChange[]} changes Permission object IDs and policies to apply.
|
|
43
|
+
* @returns {Promise<IObjectPermissionBatchResult>} Successful object IDs, per-object failures, and optional readback error.
|
|
44
|
+
* @throws {Error} Invalid batches or unsupported object types are rejected before Authz writes.
|
|
45
|
+
* @example Set owner/member editing and remove protection in one batch
|
|
46
|
+
* ```ts
|
|
47
|
+
* import type { ICollaborator } from '@univerjs/protocol';
|
|
48
|
+
* import { getDocumentParagraphPermissionObjectId } from '@univerjs/docs';
|
|
49
|
+
*
|
|
50
|
+
* // selectedMembers comes from the existing Unit collaborator picker/service.
|
|
51
|
+
* async function applyPermissions(selectedMembers: ICollaborator[]) {
|
|
52
|
+
* if (!selectedMembers.length) throw new Error('Select at least one Unit collaborator.');
|
|
53
|
+
* const document = univerAPI.getActiveDocument();
|
|
54
|
+
* if (!document) throw new Error('No active document.');
|
|
55
|
+
* const objects = document.getParagraphs().slice(0, 3);
|
|
56
|
+
* const objectIds = objects.map((paragraph) =>
|
|
57
|
+
* getDocumentParagraphPermissionObjectId(paragraph.getSegmentId(), paragraph.getId()));
|
|
58
|
+
* if (objectIds.length < 3) throw new Error('This example requires three paragraphs.');
|
|
59
|
+
* const result = await document.getPermission().setObjectPermissions([
|
|
60
|
+
* { objectId: objectIds[0], policy: { edit: 'owner', collaborators: [], strategies: [] } },
|
|
61
|
+
* { objectId: objectIds[1], policy: { edit: 'members', collaborators: selectedMembers, strategies: [] } },
|
|
62
|
+
* { objectId: objectIds[2], policy: null },
|
|
63
|
+
* ]);
|
|
64
|
+
* // A policy creates protection if absent, or updates the existing policy when already configured.
|
|
65
|
+
* for (const failure of result.failed) {
|
|
66
|
+
* console.error(failure.objectId, failure.error);
|
|
67
|
+
* }
|
|
68
|
+
* if (result.refreshError) {
|
|
69
|
+
* console.error(result.refreshError);
|
|
70
|
+
* }
|
|
71
|
+
* return result;
|
|
72
|
+
* }
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
setObjectPermissions(changes: IObjectPermissionChange[]): Promise<IObjectPermissionBatchResult>;
|
|
76
|
+
/**
|
|
77
|
+
* Sets one Document unit permission through the command system.
|
|
78
|
+
*
|
|
79
|
+
* Supported actions are Edit, Copy, Print, Export, and Comment. Await the returned promise
|
|
80
|
+
* before reading the new value or performing an action that depends on it.
|
|
81
|
+
*
|
|
82
|
+
* @param {DocumentUnitPermissionAction} action Unit permission action to update.
|
|
83
|
+
* @param {boolean} value Whether the action is allowed.
|
|
84
|
+
* @returns {Promise<void>} Resolves after the permission command finishes.
|
|
85
|
+
* @example Disable copying while keeping the Document editable
|
|
86
|
+
* ```ts
|
|
87
|
+
* import { UnitAction } from '@univerjs/protocol';
|
|
88
|
+
*
|
|
89
|
+
* const document = univerAPI.getActiveDocument();
|
|
90
|
+
* if (!document) throw new Error('No active Document.');
|
|
91
|
+
* await document.getPermission().setPoint(UnitAction.Copy, false);
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
setPoint(action: DocumentUnitPermissionAction, value: boolean): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Returns the current value of one Document unit permission.
|
|
97
|
+
* @param {DocumentUnitPermissionAction} action Unit permission action to query.
|
|
98
|
+
* @returns {boolean} Whether the action is currently allowed.
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* import { UnitAction } from '@univerjs/protocol';
|
|
102
|
+
*
|
|
103
|
+
* const document = univerAPI.getActiveDocument();
|
|
104
|
+
* const canPrint = document?.getPermission().getPoint(UnitAction.Print) ?? false;
|
|
105
|
+
* console.log(canPrint);
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
getPoint(action: DocumentUnitPermissionAction): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Enables or disables editing for the whole Document.
|
|
111
|
+
* @param {boolean} [editable] Whether editing is allowed. Defaults to true.
|
|
112
|
+
* @returns {Promise<void>} Resolves after the permission command finishes.
|
|
113
|
+
*/
|
|
114
|
+
setEditable(editable?: boolean): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Makes the whole Document read-only.
|
|
117
|
+
* @returns {Promise<void>} Resolves after the permission command finishes.
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* const document = univerAPI.getActiveDocument();
|
|
121
|
+
* if (!document) throw new Error('No active Document.');
|
|
122
|
+
* await document.getPermission().setReadOnly();
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
setReadOnly(): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* Returns whether the whole Document is currently editable.
|
|
128
|
+
* @returns {boolean} Whether Document editing is allowed.
|
|
129
|
+
*/
|
|
130
|
+
canEdit(): boolean;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Command-backed Edit permission for one stable Document object.
|
|
134
|
+
* @hideconstructor
|
|
135
|
+
*/
|
|
136
|
+
export declare class FDocumentObjectPermission {
|
|
137
|
+
private readonly _unitId;
|
|
138
|
+
private readonly _objectId;
|
|
139
|
+
private readonly _commandService;
|
|
140
|
+
private readonly _permissionService;
|
|
141
|
+
private readonly _getParentObjectIds;
|
|
142
|
+
constructor(_unitId: string, _objectId: string, _commandService: ICommandService, _permissionService: IPermissionService, _getParentObjectIds?: () => string[]);
|
|
143
|
+
/**
|
|
144
|
+
* Enables or disables editing for this stable Document object.
|
|
145
|
+
*
|
|
146
|
+
* This changes only the object's Edit point. `canEdit()` also applies the Document unit and
|
|
147
|
+
* parent Section or Paragraph ceilings.
|
|
148
|
+
*
|
|
149
|
+
* @param {boolean} [editable] Whether object editing is allowed. Defaults to true.
|
|
150
|
+
* @returns {Promise<void>} Resolves after the permission command finishes.
|
|
151
|
+
* @example Restore editing for a paragraph
|
|
152
|
+
* ```ts
|
|
153
|
+
* const document = univerAPI.getActiveDocument();
|
|
154
|
+
* const paragraph = document?.getParagraphs()[0];
|
|
155
|
+
* if (!paragraph) throw new Error('Paragraph not found.');
|
|
156
|
+
* await paragraph.getPermission().setEditable();
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
setEditable(editable?: boolean): Promise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* Makes this stable Document object read-only.
|
|
162
|
+
* @returns {Promise<void>} Resolves after the permission command finishes.
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* const document = univerAPI.getActiveDocument();
|
|
166
|
+
* const section = document?.getSection(0);
|
|
167
|
+
* if (!section) throw new Error('Section not found.');
|
|
168
|
+
* await section.getPermission().setReadOnly();
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
setReadOnly(): Promise<void>;
|
|
172
|
+
/**
|
|
173
|
+
* Returns the effective Edit result after applying the Document, parent, and object permissions.
|
|
174
|
+
* @returns {boolean} Whether the object is currently editable.
|
|
175
|
+
*/
|
|
176
|
+
canEdit(): boolean;
|
|
177
|
+
}
|
|
@@ -17,7 +17,8 @@ import type { ISectionBreak, ISectionColumnProperties, SectionHeaderFooterKind,
|
|
|
17
17
|
import type { IEffectiveSectionPageSetup, IHeaderFooterProps } from '@univerjs/docs';
|
|
18
18
|
import type { FDocument } from './f-document';
|
|
19
19
|
import type { IFDocumentTextRange } from './utils';
|
|
20
|
-
import { ColumnSeparatorType, ICommandService, SectionType } from '@univerjs/core';
|
|
20
|
+
import { ColumnSeparatorType, ICommandService, IPermissionService, SectionType } from '@univerjs/core';
|
|
21
|
+
import { FDocumentObjectPermission } from './f-document-permission';
|
|
21
22
|
export interface IFDocumentSectionColumnOptions {
|
|
22
23
|
/** Gap after each column except the last, in 96-DPI layout pixels. */
|
|
23
24
|
gap?: number;
|
|
@@ -61,7 +62,8 @@ export declare class FDocumentSection {
|
|
|
61
62
|
private readonly _document;
|
|
62
63
|
private readonly _sectionId;
|
|
63
64
|
private readonly _commandService;
|
|
64
|
-
|
|
65
|
+
private readonly _permissionService;
|
|
66
|
+
constructor(_document: FDocument, _sectionId: string, _commandService: ICommandService, _permissionService: IPermissionService);
|
|
65
67
|
/**
|
|
66
68
|
* Returns the persisted section id.
|
|
67
69
|
* @example
|
|
@@ -71,6 +73,17 @@ export declare class FDocumentSection {
|
|
|
71
73
|
* ```
|
|
72
74
|
*/
|
|
73
75
|
getId(): string;
|
|
76
|
+
/**
|
|
77
|
+
* Returns this Section's permission facade.
|
|
78
|
+
* @returns {FDocumentObjectPermission} Permission facade combining Document and Section Edit points.
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* const section = univerAPI.getActiveDocument()?.getSection(0);
|
|
82
|
+
* if (!section) throw new Error('Section not found.');
|
|
83
|
+
* await section.getPermission().setReadOnly();
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
getPermission(): FDocumentObjectPermission;
|
|
74
87
|
/**
|
|
75
88
|
* Returns the current zero-based section index.
|
|
76
89
|
* @example
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
import type { Injector, ITextStyle } from '@univerjs/core';
|
|
17
17
|
import type { FDocument } from './f-document';
|
|
18
18
|
import type { IFDocumentTextRange } from './utils';
|
|
19
|
+
import { ICommandService } from '@univerjs/core';
|
|
19
20
|
import { FBaseInitialable } from '@univerjs/core/facade';
|
|
20
21
|
/** A clipped text-style run in document offsets. */
|
|
21
22
|
export interface IFDocumentTextStyleRun {
|
|
@@ -48,7 +49,8 @@ export declare class FDocumentTextRange extends FBaseInitialable {
|
|
|
48
49
|
protected readonly _endOffset: number;
|
|
49
50
|
protected readonly _segmentId: string;
|
|
50
51
|
protected readonly _injector: Injector;
|
|
51
|
-
|
|
52
|
+
private readonly _commandService;
|
|
53
|
+
constructor(_document: FDocument, _startOffset: number, _endOffset: number, _segmentId: string, _injector: Injector, _commandService: ICommandService);
|
|
52
54
|
/**
|
|
53
55
|
* Returns the serializable document range.
|
|
54
56
|
* @example
|
|
@@ -16,9 +16,10 @@
|
|
|
16
16
|
import type { DocumentDataModel, IDocumentBody, IDocumentData, IParagraphBorder, ISectionBreak, SectionType } from '@univerjs/core';
|
|
17
17
|
import type { IHeaderFooterProps } from '@univerjs/docs';
|
|
18
18
|
import type { IFDocumentTextRange } from './utils';
|
|
19
|
-
import { DocumentFlavor, ICommandService, Injector, IResourceLoaderService, IUniverInstanceService } from '@univerjs/core';
|
|
19
|
+
import { DocumentFlavor, ICommandService, Injector, IPermissionService, IResourceLoaderService, IUniverInstanceService } from '@univerjs/core';
|
|
20
20
|
import { FBaseInitialable } from '@univerjs/core/facade';
|
|
21
21
|
import { FDocumentParagraph } from './f-document-paragraph';
|
|
22
|
+
import { FDocumentObjectPermission, FDocumentPermission } from './f-document-permission';
|
|
22
23
|
import { FDocumentSection } from './f-document-section';
|
|
23
24
|
import { FDocumentTextRange } from './f-document-text-range';
|
|
24
25
|
export interface IFDocumentParagraphQuery {
|
|
@@ -64,8 +65,9 @@ export declare class FDocument extends FBaseInitialable {
|
|
|
64
65
|
protected readonly _univerInstanceService: IUniverInstanceService;
|
|
65
66
|
protected readonly _resourceLoaderService: IResourceLoaderService;
|
|
66
67
|
private readonly _commandService;
|
|
68
|
+
private readonly _permissionService;
|
|
67
69
|
readonly id: string;
|
|
68
|
-
constructor(_documentDataModel: DocumentDataModel, _injector: Injector, _univerInstanceService: IUniverInstanceService, _resourceLoaderService: IResourceLoaderService, _commandService: ICommandService);
|
|
70
|
+
constructor(_documentDataModel: DocumentDataModel, _injector: Injector, _univerInstanceService: IUniverInstanceService, _resourceLoaderService: IResourceLoaderService, _commandService: ICommandService, _permissionService: IPermissionService);
|
|
69
71
|
/**
|
|
70
72
|
* Get the document data model of the document.
|
|
71
73
|
* @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.
|
|
@@ -122,6 +124,36 @@ export declare class FDocument extends FBaseInitialable {
|
|
|
122
124
|
* ```
|
|
123
125
|
*/
|
|
124
126
|
getId(): string;
|
|
127
|
+
/**
|
|
128
|
+
* Returns the Document unit permission facade.
|
|
129
|
+
* @returns {FDocumentPermission} Permission facade for Edit, Copy, Print, Export, and Comment.
|
|
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
|
+
getPermission(): FDocumentPermission;
|
|
138
|
+
/**
|
|
139
|
+
* Returns the permission facade for an entity with a stable id, such as a Table, Drawing, or Custom Block.
|
|
140
|
+
*
|
|
141
|
+
* Parent Section and Paragraph permission ceilings are resolved from the current Document model.
|
|
142
|
+
* @param {string} segmentId Segment id, or an empty string for the main body.
|
|
143
|
+
* @param {string} entityType Stable entity type used by the owning Doc feature.
|
|
144
|
+
* @param {string} entityId Stable entity id.
|
|
145
|
+
* @returns {FDocumentObjectPermission} Effective permission facade for the entity.
|
|
146
|
+
* @example Make one drawing read-only
|
|
147
|
+
* ```ts
|
|
148
|
+
* const document = univerAPI.getActiveDocument();
|
|
149
|
+
* if (!document) throw new Error('No active Document.');
|
|
150
|
+
* const snapshot = document.getDocumentDataModel().getSnapshot();
|
|
151
|
+
* const drawingId = snapshot.drawingsOrder?.[0];
|
|
152
|
+
* if (!drawingId) throw new Error('Drawing not found.');
|
|
153
|
+
* await document.getEntityPermission('', 'drawing', drawingId).setReadOnly();
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
getEntityPermission(segmentId: string, entityType: string, entityId: string): FDocumentObjectPermission;
|
|
125
157
|
/**
|
|
126
158
|
* Get the document name.
|
|
127
159
|
* @returns {string} The document name.
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import type { IDocumentData } from '@univerjs/core';
|
|
16
|
+
import type { ICreateUnitOptions, IDocumentData } from '@univerjs/core';
|
|
17
17
|
import { FUniver } from '@univerjs/core/facade';
|
|
18
18
|
import { FDocument } from './f-document';
|
|
19
19
|
/**
|
|
@@ -23,6 +23,7 @@ export interface IFUniverDocsMixin {
|
|
|
23
23
|
/**
|
|
24
24
|
* Create a new document and get the API handler of that document.
|
|
25
25
|
* @param {Partial<IDocumentData>} data The snapshot of the document.
|
|
26
|
+
* @param {ICreateUnitOptions} options The options of creating the document.
|
|
26
27
|
* @returns {FDocument} The document API instance.
|
|
27
28
|
* @example
|
|
28
29
|
* ```typescript
|
|
@@ -30,7 +31,7 @@ export interface IFUniverDocsMixin {
|
|
|
30
31
|
* console.log(fDocument);
|
|
31
32
|
* ```
|
|
32
33
|
*/
|
|
33
|
-
createDocument(data: Partial<IDocumentData
|
|
34
|
+
createDocument(data: Partial<IDocumentData>, options?: ICreateUnitOptions): FDocument;
|
|
34
35
|
/**
|
|
35
36
|
* Get the currently focused Univer document.
|
|
36
37
|
* @returns {FDocument | null} The currently focused Univer document API instance, or null if there is no focused Univer document.
|
|
@@ -54,7 +55,7 @@ export interface IFUniverDocsMixin {
|
|
|
54
55
|
getDocument(id: string): FDocument | null;
|
|
55
56
|
}
|
|
56
57
|
export declare class FUniverDocsMixin extends FUniver implements IFUniverDocsMixin {
|
|
57
|
-
createDocument(data: Partial<IDocumentData
|
|
58
|
+
createDocument(data: Partial<IDocumentData>, options?: ICreateUnitOptions): FDocument;
|
|
58
59
|
getActiveDocument(): FDocument | null;
|
|
59
60
|
getDocument(id: string): FDocument | null;
|
|
60
61
|
}
|
|
@@ -18,6 +18,7 @@ import './f-enum';
|
|
|
18
18
|
export { FDocument, type IDocumentCustomBlockLayout, type IDocumentCustomBlockLayoutItem, } from './f-document';
|
|
19
19
|
export { FDocumentParagraph, isParagraphFacade } from './f-document-paragraph';
|
|
20
20
|
export type { IFDocumentFindTextOptions, IFDocumentParagraphInfo } from './f-document-paragraph';
|
|
21
|
+
export { FDocumentObjectPermission, FDocumentPermission } from './f-document-permission';
|
|
21
22
|
export { DocsSectionUnsupportedDocumentFlavorError, FDocumentSection } from './f-document-section';
|
|
22
23
|
export type { FDocumentSectionPageSetup, IFDocumentSectionColumnOptions, IFDocumentSectionDescription } from './f-document-section';
|
|
23
24
|
export { FDocumentTextRange } from './f-document-text-range';
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
import type { DocumentDataModel, IDocumentBody, Injector, IParagraphStyle, UpdateDocsAttributeType } from '@univerjs/core';
|
|
17
|
+
import { ICommandService } from '@univerjs/core';
|
|
17
18
|
export interface IBuildPlainTextInsertBodyOptions {
|
|
18
19
|
paragraphStyle?: IParagraphStyle;
|
|
19
20
|
removeLeadingParagraphBreak?: boolean;
|
|
@@ -33,6 +34,6 @@ export declare function getRemovedLeadingParagraphBreakLength(dataStream: string
|
|
|
33
34
|
export declare function getNormalizedPlainTextCursorOffset(dataStream: string, cursorOffset: number, removeLeadingParagraphBreak?: boolean): number;
|
|
34
35
|
export declare function getParagraphStyleAtOffset(body: IDocumentBody, offset: number): IParagraphStyle | undefined;
|
|
35
36
|
export declare function buildPlainTextInsertBody(dataStream: string, options?: IBuildPlainTextInsertBodyOptions): IDocumentBody;
|
|
36
|
-
export declare function replaceBodyRange(range: IFDocumentTextRange, insertBody: IDocumentBody, docDataModel: DocumentDataModel,
|
|
37
|
+
export declare function replaceBodyRange(range: IFDocumentTextRange, insertBody: IDocumentBody, docDataModel: DocumentDataModel, commandService: ICommandService): boolean;
|
|
37
38
|
export declare function retainBodyRange(range: IFDocumentTextRange, updateBody: IDocumentBody, coverType: UpdateDocsAttributeType, docDataModel: DocumentDataModel, injector: Injector): boolean;
|
|
38
39
|
export declare function stripBlockTokens(text: string): string;
|