@univerjs/thread-comment 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 +45 -2
- package/lib/cjs/facade.js +97 -0
- package/lib/cjs/index.js +523 -111
- package/lib/es/facade.js +68 -0
- package/lib/es/index.js +513 -107
- package/lib/facade.js +68 -0
- package/lib/index.js +513 -107
- package/lib/types/{controllers/tc-resource.controller.d.ts → common/tc-resource.d.ts} +4 -11
- package/lib/types/facade/f-enum.d.ts +36 -0
- package/lib/types/facade/f-univer.d.ts +179 -0
- package/lib/types/facade/index.d.ts +18 -0
- package/lib/types/index.d.ts +6 -2
- package/lib/types/models/thread-comment.model.d.ts +28 -2
- package/lib/types/services/tc-datasource.service.d.ts +10 -18
- package/lib/types/services/thread-comment-api.service.d.ts +121 -0
- package/lib/types/types/comment-anchor.d.ts +57 -0
- package/lib/types/types/interfaces/i-thread-comment.d.ts +8 -0
- package/lib/umd/facade.js +1 -0
- package/lib/umd/index.js +2 -1
- package/package.json +14 -4
|
@@ -13,16 +13,9 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
+
import type { IResourceHook, UniverInstanceType } from '@univerjs/core';
|
|
17
|
+
import type { ThreadCommentModel } from '../models/thread-comment.model';
|
|
18
|
+
import type { IThreadCommentDataSourceService } from '../services/tc-datasource.service';
|
|
16
19
|
import type { IThreadComment } from '../types/interfaces/i-thread-comment';
|
|
17
|
-
import { Disposable, IResourceManagerService } from '@univerjs/core';
|
|
18
|
-
import { ThreadCommentModel } from '../models/thread-comment.model';
|
|
19
|
-
import { IThreadCommentDataSourceService } from '../services/tc-datasource.service';
|
|
20
20
|
export type UnitThreadCommentJSON = Record<string, IThreadComment[]>;
|
|
21
|
-
export declare
|
|
22
|
-
export declare class ThreadCommentResourceController extends Disposable {
|
|
23
|
-
private readonly _resourceManagerService;
|
|
24
|
-
private readonly _threadCommentModel;
|
|
25
|
-
private readonly _threadCommentDataSourceService;
|
|
26
|
-
constructor(_resourceManagerService: IResourceManagerService, _threadCommentModel: ThreadCommentModel, _threadCommentDataSourceService: IThreadCommentDataSourceService);
|
|
27
|
-
private _initSnapshot;
|
|
28
|
-
}
|
|
21
|
+
export declare function createThreadCommentResourceHook(threadCommentModel: ThreadCommentModel, threadCommentDataSourceService: IThreadCommentDataSourceService, pluginName: IResourceHook['pluginName'], businesses: UniverInstanceType[]): IResourceHook<UnitThreadCommentJSON>;
|
|
@@ -0,0 +1,36 @@
|
|
|
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 { FEnum } from '@univerjs/core/facade';
|
|
17
|
+
import { ThreadCommentAnchorKind } from '@univerjs/thread-comment';
|
|
18
|
+
export interface IFThreadCommentEnumMixin {
|
|
19
|
+
/**
|
|
20
|
+
* Stable product anchor kinds used when creating or filtering comments.
|
|
21
|
+
* @example
|
|
22
|
+
* ```ts
|
|
23
|
+
* const kind = univerAPI.Enum.ThreadCommentAnchorKind.BOARD_ELEMENT;
|
|
24
|
+
* const comments = univerAPI.getComments({ anchorKinds: [kind] });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
ThreadCommentAnchorKind: typeof ThreadCommentAnchorKind;
|
|
28
|
+
}
|
|
29
|
+
export declare class FThreadCommentEnumMixin extends FEnum implements IFThreadCommentEnumMixin {
|
|
30
|
+
/** @inheritdoc */
|
|
31
|
+
get ThreadCommentAnchorKind(): typeof ThreadCommentAnchorKind;
|
|
32
|
+
}
|
|
33
|
+
declare module '@univerjs/core/facade' {
|
|
34
|
+
interface FEnum extends IFThreadCommentEnumMixin {
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
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 { Injector } from '@univerjs/core';
|
|
17
|
+
import { FUniver } from '@univerjs/core/facade';
|
|
18
|
+
import * as ThreadComment from '@univerjs/thread-comment';
|
|
19
|
+
export interface IFUniverThreadCommentMixin {
|
|
20
|
+
/**
|
|
21
|
+
* Creates a root comment on a serialized product anchor.
|
|
22
|
+
* @param options Comment content, owner IDs, stable anchor, and optional caller-controlled IDs.
|
|
23
|
+
* @returns `true` when the command succeeds; otherwise, `false`.
|
|
24
|
+
* @throws {TypeError} If the content is empty or the anchor is invalid.
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const presentation = univerAPI.getActivePresentation();
|
|
28
|
+
* if (!presentation) throw new Error('No active presentation');
|
|
29
|
+
* const slide = presentation.getSlideByIndex(0);
|
|
30
|
+
* const element = slide?.getElements()[0];
|
|
31
|
+
* if (!slide || !element) throw new Error('No commentable slide element');
|
|
32
|
+
*
|
|
33
|
+
* await univerAPI.createCommentAsync({
|
|
34
|
+
* unitId: presentation.getId(),
|
|
35
|
+
* subUnitId: slide.getId(),
|
|
36
|
+
* anchor: {
|
|
37
|
+
* kind: univerAPI.Enum.ThreadCommentAnchorKind.SLIDE_ELEMENT,
|
|
38
|
+
* pageId: slide.getId(),
|
|
39
|
+
* elementId: element.getId(),
|
|
40
|
+
* },
|
|
41
|
+
* content: 'Verify this value.',
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
createCommentAsync(options: ThreadComment.ICreateThreadCommentOptions): Promise<boolean>;
|
|
46
|
+
/**
|
|
47
|
+
* Adds a reply to an existing root thread.
|
|
48
|
+
* @param options Reply content and the owning unit, subunit, and thread IDs.
|
|
49
|
+
* @returns `true` when the reply is created. Returns `false` when the root thread is not loaded or the command fails.
|
|
50
|
+
* @throws {TypeError} If the content is empty.
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* const [thread] = univerAPI.getComments({ resolved: false });
|
|
54
|
+
* if (thread) {
|
|
55
|
+
* await univerAPI.replyCommentAsync({
|
|
56
|
+
* unitId: thread.unitId,
|
|
57
|
+
* subUnitId: thread.subUnitId,
|
|
58
|
+
* threadId: thread.threadId,
|
|
59
|
+
* content: 'Verified.',
|
|
60
|
+
* });
|
|
61
|
+
* }
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
replyCommentAsync(options: ThreadComment.IReplyThreadCommentOptions): Promise<boolean>;
|
|
65
|
+
/**
|
|
66
|
+
* Updates the content or attachments of an existing root comment or reply.
|
|
67
|
+
* @param options Updated content and the owning unit, subunit, and comment IDs.
|
|
68
|
+
* @returns `true` when the update command succeeds; otherwise, `false`.
|
|
69
|
+
* @throws {TypeError} If the content is empty.
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* const [comment] = univerAPI.getComments({ resolved: false });
|
|
73
|
+
* if (comment) {
|
|
74
|
+
* await univerAPI.updateCommentAsync({
|
|
75
|
+
* unitId: comment.unitId,
|
|
76
|
+
* subUnitId: comment.subUnitId,
|
|
77
|
+
* commentId: comment.root.id,
|
|
78
|
+
* content: 'Updated review result.',
|
|
79
|
+
* });
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
updateCommentAsync(options: ThreadComment.IUpdateThreadCommentOptions): Promise<boolean>;
|
|
84
|
+
/**
|
|
85
|
+
* Deletes one comment, or the complete root and reply tree when `deleteThread` is `true`.
|
|
86
|
+
* @param options Owning IDs, target comment ID, and the optional whole-thread flag.
|
|
87
|
+
* @returns `true` when the delete command succeeds; otherwise, `false`.
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* const [comment] = univerAPI.getComments({ resolved: false });
|
|
91
|
+
* if (comment) {
|
|
92
|
+
* await univerAPI.deleteCommentAsync({
|
|
93
|
+
* unitId: comment.unitId,
|
|
94
|
+
* subUnitId: comment.subUnitId,
|
|
95
|
+
* commentId: comment.root.id,
|
|
96
|
+
* deleteThread: true,
|
|
97
|
+
* });
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
deleteCommentAsync(options: ThreadComment.IDeleteThreadCommentOptions): Promise<boolean>;
|
|
102
|
+
/**
|
|
103
|
+
* Resolves a thread. Pass `resolved: false` to reopen it.
|
|
104
|
+
* @param options Owning IDs, a comment ID in the thread, and the desired resolution state.
|
|
105
|
+
* @returns `true` when the resolve command succeeds; otherwise, `false`.
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* const [comment] = univerAPI.getComments({ resolved: false });
|
|
109
|
+
* if (comment) {
|
|
110
|
+
* await univerAPI.resolveCommentAsync({
|
|
111
|
+
* unitId: comment.unitId,
|
|
112
|
+
* subUnitId: comment.subUnitId,
|
|
113
|
+
* commentId: comment.root.id,
|
|
114
|
+
* });
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
resolveCommentAsync(options: ThreadComment.IResolveThreadCommentOptions): Promise<boolean>;
|
|
119
|
+
/**
|
|
120
|
+
* Queries locally loaded threads by unit, subunit, anchor kind, author, or resolution state.
|
|
121
|
+
* @param query Optional filters. Omit the argument to return every locally loaded thread.
|
|
122
|
+
* @returns Matching root threads, their replies, anchor kinds, parsed anchors, and related user IDs.
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* const presentation = univerAPI.getActivePresentation();
|
|
126
|
+
* const openAgentReviews = univerAPI.getComments({
|
|
127
|
+
* unitIds: presentation ? [presentation.getId()] : [],
|
|
128
|
+
* authorIds: ['agent-reviewer'],
|
|
129
|
+
* anchorKinds: [univerAPI.Enum.ThreadCommentAnchorKind.SLIDE_ELEMENT],
|
|
130
|
+
* resolved: false,
|
|
131
|
+
* });
|
|
132
|
+
* const sheetCellReviews = univerAPI.getComments({
|
|
133
|
+
* anchorKinds: [univerAPI.Enum.ThreadCommentAnchorKind.SHEET_CELL],
|
|
134
|
+
* });
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
getComments(query?: ThreadComment.IThreadCommentQuery): ThreadComment.IFacadeThreadCommentInfo[];
|
|
138
|
+
/**
|
|
139
|
+
* Synchronizes locally known threads from the configured datasource, then applies the same filters as `getComments`.
|
|
140
|
+
* This method does not discover thread IDs that have never been loaded into the model.
|
|
141
|
+
* @param query Optional filters. Omit the argument to synchronize and return every known thread.
|
|
142
|
+
* @returns A promise resolving to the synchronized matching threads.
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* const presentation = univerAPI.getActivePresentation();
|
|
146
|
+
* const comments = await univerAPI.listCommentsAsync({
|
|
147
|
+
* unitIds: presentation ? [presentation.getId()] : [],
|
|
148
|
+
* anchorKinds: [univerAPI.Enum.ThreadCommentAnchorKind.SLIDE_ELEMENT],
|
|
149
|
+
* resolved: false,
|
|
150
|
+
* });
|
|
151
|
+
* comments.forEach(({ root, children, anchorKind, anchor }) => {
|
|
152
|
+
* console.log(root.id, children.length, anchorKind, anchor);
|
|
153
|
+
* });
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
listCommentsAsync(query?: ThreadComment.IThreadCommentQuery): Promise<ThreadComment.IFacadeThreadCommentInfo[]>;
|
|
157
|
+
}
|
|
158
|
+
export declare class FUniverThreadCommentMixin extends FUniver implements IFUniverThreadCommentMixin {
|
|
159
|
+
private _threadCommentService;
|
|
160
|
+
_initialize(injector: Injector): void;
|
|
161
|
+
/** @inheritdoc */
|
|
162
|
+
createCommentAsync(options: ThreadComment.ICreateThreadCommentOptions): Promise<boolean>;
|
|
163
|
+
/** @inheritdoc */
|
|
164
|
+
replyCommentAsync(options: ThreadComment.IReplyThreadCommentOptions): Promise<boolean>;
|
|
165
|
+
/** @inheritdoc */
|
|
166
|
+
updateCommentAsync(options: ThreadComment.IUpdateThreadCommentOptions): Promise<boolean>;
|
|
167
|
+
/** @inheritdoc */
|
|
168
|
+
deleteCommentAsync(options: ThreadComment.IDeleteThreadCommentOptions): Promise<boolean>;
|
|
169
|
+
/** @inheritdoc */
|
|
170
|
+
resolveCommentAsync(options: ThreadComment.IResolveThreadCommentOptions): Promise<boolean>;
|
|
171
|
+
/** @inheritdoc */
|
|
172
|
+
getComments(query?: ThreadComment.IThreadCommentQuery): ThreadComment.IFacadeThreadCommentInfo[];
|
|
173
|
+
/** @inheritdoc */
|
|
174
|
+
listCommentsAsync(query?: ThreadComment.IThreadCommentQuery): Promise<ThreadComment.IFacadeThreadCommentInfo[]>;
|
|
175
|
+
}
|
|
176
|
+
declare module '@univerjs/core/facade' {
|
|
177
|
+
interface FUniver extends IFUniverThreadCommentMixin {
|
|
178
|
+
}
|
|
179
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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 { FThreadCommentEnumMixin, type IFThreadCommentEnumMixin } from './f-enum';
|
|
17
|
+
export type { IFUniverThreadCommentMixin } from './f-univer';
|
|
18
|
+
export { FUniverThreadCommentMixin } from './f-univer';
|
package/lib/types/index.d.ts
CHANGED
|
@@ -17,13 +17,17 @@ export { AddCommentCommand, DeleteCommentCommand, DeleteCommentTreeCommand, Reso
|
|
|
17
17
|
export type { IAddCommentCommandParams, IDeleteCommentCommandParams, IDeleteCommentTreeCommandParams, IResolveCommentCommandParams, IUpdateCommentCommandParams, } from './commands/commands/comment.command';
|
|
18
18
|
export { AddCommentMutation, DeleteCommentMutation, ResolveCommentMutation, UpdateCommentMutation, UpdateCommentRefMutation, } from './commands/mutations/comment.mutation';
|
|
19
19
|
export type { IAddCommentMutationParams, IDeleteCommentMutationParams, IResolveCommentMutationParams, IUpdateCommentMutationParams, IUpdateCommentPayload, IUpdateCommentRefMutationParams, } from './commands/mutations/comment.mutation';
|
|
20
|
+
export { createThreadCommentResourceHook, } from './common/tc-resource';
|
|
20
21
|
export { getDT } from './common/utils';
|
|
21
22
|
export type { IUniverThreadCommentConfig } from './config/config';
|
|
22
|
-
export { SHEET_UNIVER_THREAD_COMMENT_PLUGIN, ThreadCommentResourceController, } from './controllers/tc-resource.controller';
|
|
23
23
|
export { ThreadCommentModel } from './models/thread-comment.model';
|
|
24
|
-
export type { CommentUpdate, IThreadInfo } from './models/thread-comment.model';
|
|
24
|
+
export type { CommentUpdate, IThreadCommentQuery, IThreadInfo } from './models/thread-comment.model';
|
|
25
25
|
export { UniverThreadCommentPlugin } from './plugin';
|
|
26
26
|
export { IThreadCommentDataSourceService, ThreadCommentDataSourceService } from './services/tc-datasource.service';
|
|
27
27
|
export type { IThreadCommentDataSource, ThreadCommentJSON } from './services/tc-datasource.service';
|
|
28
|
+
export { isThreadCommentDocumentBody, normalizeThreadCommentContent, ThreadCommentFacadeService } from './services/thread-comment-api.service';
|
|
29
|
+
export type { ICreateThreadCommentOptions, IDeleteThreadCommentOptions, IFacadeThreadCommentInfo, IReplyThreadCommentOptions, IResolveThreadCommentOptions, IUpdateThreadCommentOptions, ThreadCommentContent, } from './services/thread-comment-api.service';
|
|
30
|
+
export { deserializeThreadCommentAnchor, isThreadCommentAnchor, serializeThreadCommentAnchor, ThreadCommentAnchorKind, } from './types/comment-anchor';
|
|
31
|
+
export type { IThreadCommentAnchor, IThreadCommentBaseRecordAnchor, IThreadCommentElementAnchor, IThreadCommentPositionAnchor, } from './types/comment-anchor';
|
|
28
32
|
export { TC_PLUGIN_NAME } from './types/const';
|
|
29
33
|
export type { IBaseComment, IThreadComment, IThreadCommentMention } from './types/interfaces/i-thread-comment';
|
|
@@ -16,8 +16,21 @@
|
|
|
16
16
|
import type { Nullable } from '@univerjs/core';
|
|
17
17
|
import type { IUpdateCommentPayload, IUpdateCommentRefPayload } from '../commands/mutations/comment.mutation';
|
|
18
18
|
import type { IThreadComment } from '../types/interfaces/i-thread-comment';
|
|
19
|
-
import { Disposable, LifecycleService } from '@univerjs/core';
|
|
19
|
+
import { Disposable, IUniverInstanceService, LifecycleService } from '@univerjs/core';
|
|
20
20
|
import { IThreadCommentDataSourceService } from '../services/tc-datasource.service';
|
|
21
|
+
import { ThreadCommentAnchorKind } from '../types/comment-anchor';
|
|
22
|
+
export interface IThreadCommentQuery {
|
|
23
|
+
/** Match comments in any of these Univer units. */
|
|
24
|
+
unitIds?: string[];
|
|
25
|
+
/** Match comments in any of these sheets, pages, tables, or product subunits. */
|
|
26
|
+
subUnitIds?: string[];
|
|
27
|
+
/** Match product targets such as ranges, drawings, slide elements, or base records. */
|
|
28
|
+
anchorKinds?: ThreadCommentAnchorKind[];
|
|
29
|
+
/** Match threads containing a root comment or reply written by any of these user IDs. */
|
|
30
|
+
authorIds?: string[];
|
|
31
|
+
/** Match resolved or unresolved root threads. */
|
|
32
|
+
resolved?: boolean;
|
|
33
|
+
}
|
|
21
34
|
export type CommentUpdate = {
|
|
22
35
|
unitId: string;
|
|
23
36
|
subUnitId: string;
|
|
@@ -51,25 +64,36 @@ export type CommentUpdate = {
|
|
|
51
64
|
payload: IThreadComment;
|
|
52
65
|
});
|
|
53
66
|
export interface IThreadInfo {
|
|
67
|
+
/** Univer unit that owns the thread. */
|
|
54
68
|
unitId: string;
|
|
69
|
+
/** Sheet, page, table, or product subunit that owns the thread. */
|
|
55
70
|
subUnitId: string;
|
|
71
|
+
/** Stable root thread ID. */
|
|
56
72
|
threadId: string;
|
|
73
|
+
/** Root comment. */
|
|
57
74
|
root: IThreadComment;
|
|
75
|
+
/** Replies ordered by the comment model. */
|
|
58
76
|
children: IThreadComment[];
|
|
77
|
+
/** Unique user IDs participating in the root and reply tree. */
|
|
59
78
|
relativeUsers: Set<string>;
|
|
60
79
|
}
|
|
61
80
|
export declare class ThreadCommentModel extends Disposable {
|
|
62
81
|
private readonly _dataSourceService;
|
|
63
82
|
private readonly _lifecycleService;
|
|
83
|
+
private readonly _univerInstanceService;
|
|
64
84
|
private _commentsMap;
|
|
65
85
|
private _threadMap;
|
|
86
|
+
private _syncVersions;
|
|
87
|
+
private _nextSyncVersion;
|
|
66
88
|
private _commentUpdate$;
|
|
67
89
|
commentUpdate$: import("rxjs").Observable<CommentUpdate>;
|
|
68
90
|
private _tasks;
|
|
69
|
-
constructor(_dataSourceService: IThreadCommentDataSourceService, _lifecycleService: LifecycleService);
|
|
91
|
+
constructor(_dataSourceService: IThreadCommentDataSourceService, _lifecycleService: LifecycleService, _univerInstanceService: IUniverInstanceService);
|
|
70
92
|
private _ensureCommentMap;
|
|
71
93
|
ensureMap(unitId: string, subUnitId: string): Map<string, IThreadComment>;
|
|
72
94
|
private _ensureThreadMap;
|
|
95
|
+
private _syncKey;
|
|
96
|
+
private _invalidateSync;
|
|
73
97
|
private _replaceComment;
|
|
74
98
|
syncThreadComments(unitId: string, subUnitId: string, threadIds: string[]): Promise<void>;
|
|
75
99
|
addComment(unitId: string, subUnitId: string, origin: IThreadComment, shouldSync?: boolean): boolean;
|
|
@@ -89,4 +113,6 @@ export declare class ThreadCommentModel extends Disposable {
|
|
|
89
113
|
unitId: string;
|
|
90
114
|
threads: IThreadInfo[];
|
|
91
115
|
}[];
|
|
116
|
+
getAnchorKind(unitId: string, ref: string): ThreadCommentAnchorKind | null;
|
|
117
|
+
query(query?: IThreadCommentQuery): IThreadInfo[];
|
|
92
118
|
}
|
|
@@ -36,6 +36,11 @@ export interface IThreadCommentDataSource {
|
|
|
36
36
|
* handler for delete-comment, throw error means fail and stop the process.
|
|
37
37
|
*/
|
|
38
38
|
deleteComment: (unitId: string, subUnitId: string, threadId: string, commentId: string) => Promise<Success>;
|
|
39
|
+
/**
|
|
40
|
+
* Delete a complete thread. Legacy data sources can omit this method and
|
|
41
|
+
* fall back to deleting the root comment through `deleteComment`.
|
|
42
|
+
*/
|
|
43
|
+
deleteThread?: (unitId: string, subUnitId: string, threadId: string) => Promise<Success>;
|
|
39
44
|
/**
|
|
40
45
|
* handler for batch-fetch-comment, throw error means fail and stop the process.
|
|
41
46
|
*/
|
|
@@ -64,6 +69,7 @@ export interface IThreadCommentDataSourceService {
|
|
|
64
69
|
* handler for delete-comment, throw error means fail and stop the process.
|
|
65
70
|
*/
|
|
66
71
|
deleteComment: (unitId: string, subUnitId: string, threadId: string, commentId: string) => Promise<Success>;
|
|
72
|
+
deleteThread?: (unitId: string, subUnitId: string, threadId: string) => Promise<Success>;
|
|
67
73
|
saveToSnapshot: (unitComments: Record<string, IThreadComment[]>, unitId: string) => Record<string, ThreadCommentJSON[]>;
|
|
68
74
|
getThreadComment: (unitId: string, subUnitId: string, threadId: string) => Promise<Nullable<IBaseComment>>;
|
|
69
75
|
listThreadComments: (unitId: string, subUnitId: string, threadId: string[]) => Promise<IBaseComment[] | false>;
|
|
@@ -73,33 +79,19 @@ export interface IThreadCommentDataSourceService {
|
|
|
73
79
|
*/
|
|
74
80
|
export declare class ThreadCommentDataSourceService extends Disposable implements IThreadCommentDataSourceService {
|
|
75
81
|
private _dataSource;
|
|
82
|
+
private readonly _pendingAdds;
|
|
76
83
|
syncUpdateMutationToColla: boolean;
|
|
77
84
|
set dataSource(dataSource: Nullable<IThreadCommentDataSource>);
|
|
78
85
|
get dataSource(): Nullable<IThreadCommentDataSource>;
|
|
79
86
|
constructor();
|
|
80
87
|
getThreadComment(unitId: string, subUnitId: string, threadId: string): Promise<Nullable<IBaseComment>>;
|
|
81
|
-
addComment(comment: IThreadComment): Promise<
|
|
82
|
-
threadId: string;
|
|
83
|
-
ref: string;
|
|
84
|
-
id: string;
|
|
85
|
-
dT: string;
|
|
86
|
-
updateT?: string;
|
|
87
|
-
personId: string;
|
|
88
|
-
text: import("@univerjs/core").IDocumentBody;
|
|
89
|
-
attachments?: string[];
|
|
90
|
-
updated?: boolean;
|
|
91
|
-
mentions?: string[];
|
|
92
|
-
parentId?: string;
|
|
93
|
-
resolved?: boolean;
|
|
94
|
-
unitId: string;
|
|
95
|
-
subUnitId: string;
|
|
96
|
-
children?: IBaseComment[];
|
|
97
|
-
}>;
|
|
88
|
+
addComment(comment: IThreadComment): Promise<IThreadComment>;
|
|
98
89
|
updateComment(comment: IThreadComment): Promise<boolean>;
|
|
99
90
|
resolveComment(comment: IThreadComment): Promise<boolean>;
|
|
100
91
|
deleteComment(unitId: string, subUnitId: string, threadId: string, commentId: string): Promise<boolean>;
|
|
92
|
+
deleteThread(unitId: string, subUnitId: string, threadId: string): Promise<boolean>;
|
|
101
93
|
listThreadComments(unitId: string, subUnitId: string, threadIds: string[]): Promise<false | IBaseComment[]>;
|
|
102
|
-
saveToSnapshot(unitComments: Record<string, IThreadComment[]>,
|
|
94
|
+
saveToSnapshot(unitComments: Record<string, IThreadComment[]>, _unitId: string): Record<string, ThreadCommentJSON[]>;
|
|
103
95
|
}
|
|
104
96
|
export declare const IThreadCommentDataSourceService: import("@wendellhu/redi").IdentifierDecorator<IThreadCommentDataSourceService>;
|
|
105
97
|
export {};
|
|
@@ -0,0 +1,121 @@
|
|
|
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 { IDocumentBody } from '@univerjs/core';
|
|
17
|
+
import type { IThreadCommentQuery, IThreadInfo } from '../models/thread-comment.model';
|
|
18
|
+
import type { IThreadCommentAnchor, ThreadCommentAnchorKind } from '../types/comment-anchor';
|
|
19
|
+
import { ICommandService, UserManagerService } from '@univerjs/core';
|
|
20
|
+
import { ThreadCommentModel } from '../models/thread-comment.model';
|
|
21
|
+
export interface ICreateThreadCommentOptions {
|
|
22
|
+
/** Univer unit that owns the comment. */
|
|
23
|
+
unitId: string;
|
|
24
|
+
/** Sheet, page, table, or product subunit that owns the comment. */
|
|
25
|
+
subUnitId: string;
|
|
26
|
+
/** Stable, serializable product anchor. */
|
|
27
|
+
anchor: IThreadCommentAnchor;
|
|
28
|
+
/** Plain text or a Univer document body for rich comment content. */
|
|
29
|
+
content: ThreadCommentContent;
|
|
30
|
+
/** Attachment resource IDs. */
|
|
31
|
+
attachments?: string[];
|
|
32
|
+
/** Caller-supplied stable comment ID, useful for idempotent agent workflows. */
|
|
33
|
+
id?: string;
|
|
34
|
+
/** Caller-supplied thread ID. Defaults to the root comment ID. */
|
|
35
|
+
threadId?: string;
|
|
36
|
+
/** Author user ID. Defaults to the current user managed by `UserManagerService`. */
|
|
37
|
+
personId?: string;
|
|
38
|
+
/** Creation time. Defaults to the current time. */
|
|
39
|
+
dateTime?: Date;
|
|
40
|
+
}
|
|
41
|
+
export interface IReplyThreadCommentOptions {
|
|
42
|
+
/** Univer unit that owns the thread. */
|
|
43
|
+
unitId: string;
|
|
44
|
+
/** Sheet, page, table, or product subunit that owns the thread. */
|
|
45
|
+
subUnitId: string;
|
|
46
|
+
/** Stable ID of the root thread being replied to. */
|
|
47
|
+
threadId: string;
|
|
48
|
+
/** Plain text or a Univer document body for rich reply content. */
|
|
49
|
+
content: ThreadCommentContent;
|
|
50
|
+
/** Attachment resource IDs. */
|
|
51
|
+
attachments?: string[];
|
|
52
|
+
/** Caller-supplied stable reply ID, useful for idempotent agent workflows. */
|
|
53
|
+
id?: string;
|
|
54
|
+
/** Author user ID. Defaults to the current user managed by `UserManagerService`. */
|
|
55
|
+
personId?: string;
|
|
56
|
+
/** Creation time. Defaults to the current time. */
|
|
57
|
+
dateTime?: Date;
|
|
58
|
+
}
|
|
59
|
+
export interface IUpdateThreadCommentOptions {
|
|
60
|
+
/** Univer unit that owns the comment. */
|
|
61
|
+
unitId: string;
|
|
62
|
+
/** Sheet, page, table, or product subunit that owns the comment. */
|
|
63
|
+
subUnitId: string;
|
|
64
|
+
/** Stable ID of the root comment or reply to update. */
|
|
65
|
+
commentId: string;
|
|
66
|
+
/** Replacement plain text or Univer document body. */
|
|
67
|
+
content: ThreadCommentContent;
|
|
68
|
+
/** Replacement attachment resource IDs. Omit to preserve the current attachments. */
|
|
69
|
+
attachments?: string[];
|
|
70
|
+
/** Update time. Defaults to the current time. */
|
|
71
|
+
dateTime?: Date;
|
|
72
|
+
}
|
|
73
|
+
export interface IDeleteThreadCommentOptions {
|
|
74
|
+
/** Univer unit that owns the comment. */
|
|
75
|
+
unitId: string;
|
|
76
|
+
/** Sheet, page, table, or product subunit that owns the comment. */
|
|
77
|
+
subUnitId: string;
|
|
78
|
+
/** Stable ID of the root comment or reply to delete. */
|
|
79
|
+
commentId: string;
|
|
80
|
+
/** Deletes the complete root and reply tree when true. */
|
|
81
|
+
deleteThread?: boolean;
|
|
82
|
+
}
|
|
83
|
+
export interface IResolveThreadCommentOptions {
|
|
84
|
+
/** Univer unit that owns the thread. */
|
|
85
|
+
unitId: string;
|
|
86
|
+
/** Sheet, page, table, or product subunit that owns the thread. */
|
|
87
|
+
subUnitId: string;
|
|
88
|
+
/** Stable ID of the root comment or a reply in the target thread. */
|
|
89
|
+
commentId: string;
|
|
90
|
+
/** Defaults to `true`. Pass `false` to reopen the thread. */
|
|
91
|
+
resolved?: boolean;
|
|
92
|
+
}
|
|
93
|
+
/** Plain text or a Univer document body used as comment content. */
|
|
94
|
+
export type ThreadCommentContent = string | IDocumentBody;
|
|
95
|
+
export declare function isThreadCommentDocumentBody(value: unknown): value is IDocumentBody;
|
|
96
|
+
export declare function normalizeThreadCommentContent(content: ThreadCommentContent): IDocumentBody;
|
|
97
|
+
export interface IFacadeThreadCommentInfo extends Omit<IThreadInfo, 'relativeUsers'> {
|
|
98
|
+
/**
|
|
99
|
+
* Product anchor category. Facade query results always populate this field, including for legacy
|
|
100
|
+
* Sheet cell and Document range comments. It remains optional for source compatibility with
|
|
101
|
+
* existing `IFacadeThreadCommentInfo` implementations.
|
|
102
|
+
*/
|
|
103
|
+
anchorKind?: ThreadCommentAnchorKind | null;
|
|
104
|
+
/** Parsed stable product anchor, or `null` for a legacy comment reference. */
|
|
105
|
+
anchor: IThreadCommentAnchor | null;
|
|
106
|
+
/** Unique IDs of authors participating in the root and reply tree. */
|
|
107
|
+
relativeUserIds: string[];
|
|
108
|
+
}
|
|
109
|
+
export declare class ThreadCommentFacadeService {
|
|
110
|
+
private readonly _commandService;
|
|
111
|
+
private readonly _model;
|
|
112
|
+
private readonly _userManagerService;
|
|
113
|
+
constructor(_commandService: ICommandService, _model: ThreadCommentModel, _userManagerService: UserManagerService);
|
|
114
|
+
createCommentAsync(options: ICreateThreadCommentOptions): Promise<boolean>;
|
|
115
|
+
replyCommentAsync(options: IReplyThreadCommentOptions): Promise<boolean>;
|
|
116
|
+
updateCommentAsync(options: IUpdateThreadCommentOptions): Promise<boolean>;
|
|
117
|
+
deleteCommentAsync(options: IDeleteThreadCommentOptions): Promise<boolean>;
|
|
118
|
+
resolveCommentAsync(options: IResolveThreadCommentOptions): Promise<boolean>;
|
|
119
|
+
getComments(query?: IThreadCommentQuery): IFacadeThreadCommentInfo[];
|
|
120
|
+
listCommentsAsync(query?: IThreadCommentQuery): Promise<IFacadeThreadCommentInfo[]>;
|
|
121
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
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 enum ThreadCommentAnchorKind {
|
|
17
|
+
/** A cell comment managed by the Sheets range Facade. */
|
|
18
|
+
SHEET_CELL = "sheet-cell",
|
|
19
|
+
/** A Sheet image, chart, Shape, or other drawing element. */
|
|
20
|
+
SHEET_DRAWING = "sheet-drawing",
|
|
21
|
+
/** A fixed text range comment managed by the Docs text range Facade. */
|
|
22
|
+
DOC_TEXT_RANGE = "doc-text-range",
|
|
23
|
+
/** A Document image, chart, Shape, or other drawing element. */
|
|
24
|
+
DOC_DRAWING = "doc-drawing",
|
|
25
|
+
/** A Slide page element identified by a stable element ID. */
|
|
26
|
+
SLIDE_ELEMENT = "slide-element",
|
|
27
|
+
/** A free position normalized to the Slide page size. */
|
|
28
|
+
SLIDE_POSITION = "slide-position",
|
|
29
|
+
/** A Board element identified by a stable element ID. */
|
|
30
|
+
BOARD_ELEMENT = "board-element",
|
|
31
|
+
/** A free position in Board world coordinates. */
|
|
32
|
+
BOARD_POSITION = "board-position",
|
|
33
|
+
/** A Base record identified by stable table and record IDs. */
|
|
34
|
+
BASE_RECORD = "base-record"
|
|
35
|
+
}
|
|
36
|
+
export interface IThreadCommentElementAnchor {
|
|
37
|
+
kind: ThreadCommentAnchorKind.SHEET_DRAWING | ThreadCommentAnchorKind.DOC_DRAWING | ThreadCommentAnchorKind.SLIDE_ELEMENT | ThreadCommentAnchorKind.BOARD_ELEMENT;
|
|
38
|
+
elementId: string;
|
|
39
|
+
/** Slide or Board page ID when the host product has pages. */
|
|
40
|
+
pageId?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface IThreadCommentPositionAnchor {
|
|
43
|
+
kind: ThreadCommentAnchorKind.SLIDE_POSITION | ThreadCommentAnchorKind.BOARD_POSITION;
|
|
44
|
+
x: number;
|
|
45
|
+
y: number;
|
|
46
|
+
/** Slide or Board page ID when the host product has pages. */
|
|
47
|
+
pageId?: string;
|
|
48
|
+
}
|
|
49
|
+
export interface IThreadCommentBaseRecordAnchor {
|
|
50
|
+
kind: ThreadCommentAnchorKind.BASE_RECORD;
|
|
51
|
+
tableId: string;
|
|
52
|
+
recordId: string;
|
|
53
|
+
}
|
|
54
|
+
export type IThreadCommentAnchor = IThreadCommentElementAnchor | IThreadCommentPositionAnchor | IThreadCommentBaseRecordAnchor;
|
|
55
|
+
export declare function isThreadCommentAnchor(value: unknown): value is IThreadCommentAnchor;
|
|
56
|
+
export declare function serializeThreadCommentAnchor(anchor: IThreadCommentAnchor): string;
|
|
57
|
+
export declare function deserializeThreadCommentAnchor(ref: string): IThreadCommentAnchor | null;
|
|
@@ -37,4 +37,12 @@ export interface IBaseComment {
|
|
|
37
37
|
}
|
|
38
38
|
export interface IThreadComment extends IBaseComment {
|
|
39
39
|
ref: string;
|
|
40
|
+
/** Inclusive start offset for a document text-range comment. */
|
|
41
|
+
startOffset?: number;
|
|
42
|
+
/** Exclusive end offset for a document text-range comment. */
|
|
43
|
+
endOffset?: number;
|
|
44
|
+
/** Document segment that owns the text range. Empty string means the document body. */
|
|
45
|
+
segmentId?: string;
|
|
46
|
+
/** Whether the document text range is collapsed. */
|
|
47
|
+
collapsed?: boolean;
|
|
40
48
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core/facade"),require("@univerjs/thread-comment")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core/facade`,`@univerjs/thread-comment`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverThreadCommentFacade={},e.UniverCoreFacade,e.UniverThreadComment))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=Object.create,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.getPrototypeOf,c=Object.prototype.hasOwnProperty,l=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var s=o(t),l=0,u=s.length,d;l<u;l++)d=s[l],!c.call(e,d)&&d!==n&&i(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=a(t,d))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:r(s(e)),l(t||!e||!e.__esModule?i(n,`default`,{value:e,enumerable:!0}):n,e)))(n);var u=class extends t.FEnum{get ThreadCommentAnchorKind(){return n.ThreadCommentAnchorKind}};t.FEnum.extend(u);var d=class extends t.FUniver{_initialize(e){let t;Object.defineProperty(this,"_threadCommentService",{get:()=>t??=e.get(n.ThreadCommentFacadeService)})}createCommentAsync(e){return this._threadCommentService.createCommentAsync(e)}replyCommentAsync(e){return this._threadCommentService.replyCommentAsync(e)}updateCommentAsync(e){return this._threadCommentService.updateCommentAsync(e)}deleteCommentAsync(e){return this._threadCommentService.deleteCommentAsync(e)}resolveCommentAsync(e){return this._threadCommentService.resolveCommentAsync(e)}getComments(e={}){return this._threadCommentService.getComments(e)}async listCommentsAsync(e={}){return this._threadCommentService.listCommentsAsync(e)}};t.FUniver.extend(d),e.FThreadCommentEnumMixin=u,e.FUniverThreadCommentMixin=d});
|