@univerjs/sheets-thread-comment 0.4.1 → 0.4.2-nightly.202410301606
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/README.md +4 -73
- package/lib/es/facade.js +226 -0
- package/lib/es/index.js +172 -780
- package/lib/sheets-thread-comment.model-17mh6Jez.mjs +169 -0
- package/lib/types/controllers/config.schema.d.ts +17 -6
- package/lib/types/controllers/sheets-thread-comment-ref-range.controller.d.ts +22 -0
- package/lib/types/facade/f-range.d.ts +26 -0
- package/lib/types/facade/f-thread-comment.d.ts +56 -0
- package/lib/types/facade/f-workbook.d.ts +35 -0
- package/lib/types/facade/f-worksheet.d.ts +13 -0
- package/lib/types/facade/index.d.ts +1 -0
- package/lib/types/index.d.ts +3 -9
- package/lib/types/models/sheets-thread-comment.model.d.ts +30 -0
- package/lib/types/plugin.d.ts +2 -7
- package/lib/types/types/const.d.ts +1 -3
- package/lib/umd/facade.js +1 -0
- package/lib/umd/index.js +1 -1
- package/package.json +15 -29
- package/LICENSE +0 -176
- package/lib/cjs/index.js +0 -1
- package/lib/locale/en-US.json +0 -8
- package/lib/locale/fa-IR.json +0 -8
- package/lib/locale/ru-RU.json +0 -8
- package/lib/locale/vi-VN.json +0 -8
- package/lib/locale/zh-CN.json +0 -8
- package/lib/locale/zh-TW.json +0 -8
- package/lib/types/commands/operations/comment.operation.d.ts +0 -2
- package/lib/types/controllers/menu.d.ts +0 -12
- package/lib/types/controllers/menu.schema.d.ts +0 -2
- package/lib/types/controllers/render-controllers/render.controller.d.ts +0 -13
- package/lib/types/controllers/sheets-thread-comment-copy-paste.controller.d.ts +0 -12
- package/lib/types/controllers/sheets-thread-comment-hover.controller.d.ts +0 -12
- package/lib/types/controllers/sheets-thread-comment-popup.controller.d.ts +0 -26
- package/lib/types/controllers/sheets-thread-comment-remove.controller.d.ts +0 -11
- package/lib/types/controllers/sheets-thread-comment.controller.d.ts +0 -11
- package/lib/types/locale/en-US.d.ts +0 -24
- package/lib/types/locale/fa-IR.d.ts +0 -24
- package/lib/types/locale/ru-RU.d.ts +0 -24
- package/lib/types/locale/vi-VN.d.ts +0 -24
- package/lib/types/locale/zh-CN.d.ts +0 -24
- package/lib/types/locale/zh-TW.d.ts +0 -24
- package/lib/types/services/sheets-thread-comment-popup.service.d.ts +0 -23
- package/lib/types/views/sheets-thread-comment-cell/index.d.ts +0 -2
- package/lib/types/views/sheets-thread-comment-panel/index.d.ts +0 -2
package/README.md
CHANGED
|
@@ -4,93 +4,24 @@
|
|
|
4
4
|
|
|
5
5
|
| Package Name | UMD Namespace | Version | License | Downloads | Contains CSS | Contains i18n locales |
|
|
6
6
|
| --- | --- | --- | --- | --- | :---: | :---: |
|
|
7
|
-
| `@univerjs/sheets-thread-comment` | `
|
|
7
|
+
| `@univerjs/sheets-thread-comment` | `UniverSheetsThreadCommentBase` | [![][npm-version-shield]][npm-version-link] | ![][npm-license-shield] | ![][npm-downloads-shield] | ❌ | ❌ |
|
|
8
8
|
|
|
9
9
|
## Introduction
|
|
10
10
|
|
|
11
|
-
`@univerjs/sheets-thread-comment`
|
|
11
|
+
`@univerjs/sheets-thread-comment` core package for sheet comment. For using, please refer to [@univerjs/sheets-thread-comment](../sheets-thread-comment/README.md)
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
15
|
### Installation
|
|
16
16
|
|
|
17
17
|
```shell
|
|
18
|
-
#
|
|
18
|
+
# Using npm
|
|
19
19
|
npm install @univerjs/sheets-thread-comment
|
|
20
20
|
|
|
21
|
-
#
|
|
21
|
+
# Using pnpm
|
|
22
22
|
pnpm add @univerjs/sheets-thread-comment
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
### Register the plugin
|
|
26
|
-
|
|
27
|
-
```typescript
|
|
28
|
-
import { UniverSheetsThreadCommentPlugin, IThreadCommentMentionDataService} from '@univerjs/sheets-thread-comment';
|
|
29
|
-
|
|
30
|
-
const mockUser = {
|
|
31
|
-
userID: 'mockId',
|
|
32
|
-
name: 'MockUser',
|
|
33
|
-
avatar: 'icon-url',
|
|
34
|
-
anonymous: false,
|
|
35
|
-
canBindAnonymous: false,
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
class CustomMentionDataService implements IThreadCommentMentionDataService {
|
|
39
|
-
trigger: string = '@';
|
|
40
|
-
|
|
41
|
-
// Get the common interface implementation of the mentioned user
|
|
42
|
-
async getMentions(search: string) {
|
|
43
|
-
return [
|
|
44
|
-
{
|
|
45
|
-
id: mockUser.userID,
|
|
46
|
-
label: mockUser.name,
|
|
47
|
-
type: 'user',
|
|
48
|
-
icon: mockUser.avatar,
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
id: '2',
|
|
52
|
-
label: 'User2',
|
|
53
|
-
type: 'user',
|
|
54
|
-
icon: mockUser.avatar,
|
|
55
|
-
},
|
|
56
|
-
];
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
univer.registerPlugin(UniverSheetsThreadCommentPlugin, {
|
|
61
|
-
overrides: [[IThreadCommentMentionDataService, { useClass: CustomMentionDataService }]],
|
|
62
|
-
});
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### API
|
|
66
|
-
```typescript
|
|
67
|
-
import {
|
|
68
|
-
AddCommentCommand,
|
|
69
|
-
DeleteCommentCommand,
|
|
70
|
-
UpdateCommentCommand,
|
|
71
|
-
ResolveCommentCommand,
|
|
72
|
-
DeleteCommentTreeCommand,
|
|
73
|
-
} from '@univerjs/sheets-thread-comment';
|
|
74
|
-
import type {
|
|
75
|
-
IAddCommentCommandParams,
|
|
76
|
-
IDeleteCommentCommandParams,
|
|
77
|
-
IResolveCommentCommandParams,
|
|
78
|
-
IUpdateCommentCommandParams,
|
|
79
|
-
IDeleteCommentTreeCommandParams,
|
|
80
|
-
} from '@univerjs/sheets-thread-comment';
|
|
81
|
-
|
|
82
|
-
// Add comment by command
|
|
83
|
-
const commandService = univer.__getInjector().get(ICommandService);
|
|
84
|
-
|
|
85
|
-
commandService.executeCommand(AddCommentCommand.id, {
|
|
86
|
-
unitId: 'unitId',
|
|
87
|
-
subUnitId: 'subUnitId',
|
|
88
|
-
comment: {
|
|
89
|
-
// comment content
|
|
90
|
-
},
|
|
91
|
-
} as IAddCommentCommandParams);
|
|
92
|
-
```
|
|
93
|
-
|
|
94
25
|
<!-- Links -->
|
|
95
26
|
[npm-version-shield]: https://img.shields.io/npm/v/@univerjs/sheets-thread-comment?style=flat-square
|
|
96
27
|
[npm-version-link]: https://npmjs.com/package/@univerjs/sheets-thread-comment
|
package/lib/es/facade.js
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
|
|
3
|
+
import { Inject, Injector, UniverInstanceType, ICommandService, IUniverInstanceService, UserManagerService, Tools, toDisposable } from "@univerjs/core";
|
|
4
|
+
import { FRange, FWorkbook, FWorksheet } from "@univerjs/sheets/facade";
|
|
5
|
+
import { DeleteCommentTreeCommand, DeleteCommentCommand, getDT, UpdateCommentCommand, ResolveCommentCommand, AddCommentCommand, ThreadCommentModel } from "@univerjs/thread-comment";
|
|
6
|
+
import { S as SheetsThreadCommentModel } from "../sheets-thread-comment.model-17mh6Jez.mjs";
|
|
7
|
+
import { deserializeRangeWithSheet } from "@univerjs/engine-formula";
|
|
8
|
+
import { filter } from "rxjs";
|
|
9
|
+
var __defProp2 = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = /* @__PURE__ */ __name((decorators, target, key, kind) => {
|
|
10
|
+
for (var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target, i = decorators.length - 1, decorator; i >= 0; i--)
|
|
11
|
+
(decorator = decorators[i]) && (result = (kind ? decorator(target, key, result) : decorator(result)) || result);
|
|
12
|
+
return kind && result && __defProp2(target, key, result), result;
|
|
13
|
+
}, "__decorateClass"), __decorateParam = /* @__PURE__ */ __name((index, decorator) => (target, key) => decorator(target, key, index), "__decorateParam"), _a;
|
|
14
|
+
let FThreadComment = (_a = class {
|
|
15
|
+
constructor(_thread, _parent, _injector, _commandService, _univerInstanceService, _threadCommentModel) {
|
|
16
|
+
this._thread = _thread, this._parent = _parent, this._injector = _injector, this._commandService = _commandService, this._univerInstanceService = _univerInstanceService, this._threadCommentModel = _threadCommentModel;
|
|
17
|
+
}
|
|
18
|
+
_getRef() {
|
|
19
|
+
var _a2;
|
|
20
|
+
const ref = ((_a2 = this._parent) == null ? void 0 : _a2.ref) || this._thread.ref;
|
|
21
|
+
return deserializeRangeWithSheet(ref).range;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Whether the comment is a root comment
|
|
25
|
+
* @returns Whether the comment is a root comment
|
|
26
|
+
*/
|
|
27
|
+
getIsRoot() {
|
|
28
|
+
return !this._parent;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Get the comment data
|
|
32
|
+
* @returns The comment data
|
|
33
|
+
*/
|
|
34
|
+
getCommentData() {
|
|
35
|
+
const { children, ...comment } = this._thread;
|
|
36
|
+
return comment;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get the replies of the comment
|
|
40
|
+
* @returns the replies of the comment
|
|
41
|
+
*/
|
|
42
|
+
getReplies() {
|
|
43
|
+
var _a2;
|
|
44
|
+
const range = this._getRef(), comments = this._threadCommentModel.getCommentWithChildren(this._thread.unitId, this._thread.subUnitId, range.startRow, range.startColumn);
|
|
45
|
+
return (_a2 = comments == null ? void 0 : comments.children) == null ? void 0 : _a2.map((child) => this._injector.createInstance(FThreadComment, child));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get the range of the comment
|
|
49
|
+
* @returns The range of the comment
|
|
50
|
+
*/
|
|
51
|
+
getRange() {
|
|
52
|
+
const workbook = this._univerInstanceService.getUnit(this._thread.unitId, UniverInstanceType.UNIVER_SHEET);
|
|
53
|
+
if (!workbook)
|
|
54
|
+
return null;
|
|
55
|
+
const worksheet = workbook.getSheetBySheetId(this._thread.subUnitId);
|
|
56
|
+
if (!worksheet)
|
|
57
|
+
return null;
|
|
58
|
+
const range = this._getRef();
|
|
59
|
+
return this._injector.createInstance(FRange, workbook, worksheet, range);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Get the content of the comment
|
|
63
|
+
* @returns The content of the comment
|
|
64
|
+
*/
|
|
65
|
+
getContent() {
|
|
66
|
+
return this._thread.text;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Delete the comment and it's replies
|
|
70
|
+
* @returns success or not
|
|
71
|
+
*/
|
|
72
|
+
delete() {
|
|
73
|
+
return this._commandService.executeCommand(
|
|
74
|
+
this.getIsRoot() ? DeleteCommentTreeCommand.id : DeleteCommentCommand.id,
|
|
75
|
+
{
|
|
76
|
+
commentId: this._thread.id,
|
|
77
|
+
unitId: this._thread.unitId,
|
|
78
|
+
subUnitId: this._thread.subUnitId
|
|
79
|
+
}
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Update the comment content
|
|
84
|
+
* @param content The new content of the comment
|
|
85
|
+
* @returns success or not
|
|
86
|
+
*/
|
|
87
|
+
async update(content) {
|
|
88
|
+
const dt = getDT();
|
|
89
|
+
return await this._commandService.executeCommand(
|
|
90
|
+
UpdateCommentCommand.id,
|
|
91
|
+
{
|
|
92
|
+
unitId: this._thread.unitId,
|
|
93
|
+
subUnitId: this._thread.subUnitId,
|
|
94
|
+
payload: {
|
|
95
|
+
commentId: this._thread.id,
|
|
96
|
+
text: content,
|
|
97
|
+
updated: !0,
|
|
98
|
+
updateT: dt
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Resolve the comment
|
|
105
|
+
* @param resolved Whether the comment is resolved
|
|
106
|
+
* @returns success or not
|
|
107
|
+
*/
|
|
108
|
+
resolve(resolved) {
|
|
109
|
+
return this._commandService.executeCommand(
|
|
110
|
+
ResolveCommentCommand.id,
|
|
111
|
+
{
|
|
112
|
+
unitId: this._thread.unitId,
|
|
113
|
+
subUnitId: this._thread.subUnitId,
|
|
114
|
+
commentId: this._thread.id,
|
|
115
|
+
resolved: resolved != null ? resolved : !this._thread.resolved
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
}, __name(_a, "FThreadComment"), _a);
|
|
120
|
+
FThreadComment = __decorateClass([
|
|
121
|
+
__decorateParam(2, Inject(Injector)),
|
|
122
|
+
__decorateParam(3, ICommandService),
|
|
123
|
+
__decorateParam(4, IUniverInstanceService),
|
|
124
|
+
__decorateParam(5, Inject(SheetsThreadCommentModel))
|
|
125
|
+
], FThreadComment);
|
|
126
|
+
const _FRangeCommentMixin = class _FRangeCommentMixin extends FRange {
|
|
127
|
+
getComment() {
|
|
128
|
+
const sheetsTheadCommentModel = this._injector.get(SheetsThreadCommentModel), unitId = this._workbook.getUnitId(), sheetId = this._worksheet.getSheetId(), commentId = sheetsTheadCommentModel.getByLocation(unitId, sheetId, this._range.startRow, this._range.startColumn);
|
|
129
|
+
if (!commentId)
|
|
130
|
+
return null;
|
|
131
|
+
const comment = sheetsTheadCommentModel.getComment(unitId, sheetId, commentId);
|
|
132
|
+
return comment ? this._injector.createInstance(FThreadComment, comment) : null;
|
|
133
|
+
}
|
|
134
|
+
addComment(content) {
|
|
135
|
+
var _a2;
|
|
136
|
+
const injector = this._injector, currentComment = (_a2 = this.getComment()) == null ? void 0 : _a2.getCommentData(), commentService = injector.get(ICommandService), userService = injector.get(UserManagerService), unitId = this._workbook.getUnitId(), sheetId = this._worksheet.getSheetId(), refStr = `${Tools.chatAtABC(this._range.startColumn)}${this._range.startRow + 1}`, currentUser = userService.getCurrentUser();
|
|
137
|
+
return commentService.executeCommand(AddCommentCommand.id, {
|
|
138
|
+
unitId,
|
|
139
|
+
subUnitId: sheetId,
|
|
140
|
+
comment: {
|
|
141
|
+
text: content,
|
|
142
|
+
attachments: [],
|
|
143
|
+
dT: getDT(),
|
|
144
|
+
id: Tools.generateRandomId(),
|
|
145
|
+
ref: refStr,
|
|
146
|
+
personId: currentUser.userID,
|
|
147
|
+
parentId: currentComment == null ? void 0 : currentComment.id,
|
|
148
|
+
unitId,
|
|
149
|
+
subUnitId: sheetId,
|
|
150
|
+
threadId: currentComment == null ? void 0 : currentComment.threadId
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
clearComment() {
|
|
155
|
+
var _a2;
|
|
156
|
+
const injector = this._injector, currentComment = (_a2 = this.getComment()) == null ? void 0 : _a2.getCommentData(), commentService = injector.get(ICommandService), unitId = this._workbook.getUnitId(), sheetId = this._worksheet.getSheetId();
|
|
157
|
+
return currentComment ? commentService.executeCommand(DeleteCommentTreeCommand.id, {
|
|
158
|
+
unitId,
|
|
159
|
+
subUnitId: sheetId,
|
|
160
|
+
threadId: currentComment.threadId,
|
|
161
|
+
commentId: currentComment.id
|
|
162
|
+
}) : Promise.resolve(!0);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
__name(_FRangeCommentMixin, "FRangeCommentMixin");
|
|
166
|
+
let FRangeCommentMixin = _FRangeCommentMixin;
|
|
167
|
+
FRange.extend(FRangeCommentMixin);
|
|
168
|
+
const _FWorkbookThreadCommentMixin = class _FWorkbookThreadCommentMixin extends FWorkbook {
|
|
169
|
+
_initialize() {
|
|
170
|
+
Object.defineProperty(this, "_threadCommentModel", {
|
|
171
|
+
get() {
|
|
172
|
+
return this._injector.get(ThreadCommentModel);
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
onThreadCommentChange(callback) {
|
|
177
|
+
return toDisposable(this._threadCommentModel.commentUpdate$.pipe(filter((change) => change.unitId === this._workbook.getUnitId())).subscribe(callback));
|
|
178
|
+
}
|
|
179
|
+
onBeforeAddThreadComment(callback) {
|
|
180
|
+
return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
|
|
181
|
+
const params = commandInfo.params;
|
|
182
|
+
if (commandInfo.id === AddCommentCommand.id) {
|
|
183
|
+
if (params.unitId !== this._workbook.getUnitId())
|
|
184
|
+
return;
|
|
185
|
+
if (callback(params, options) === !1)
|
|
186
|
+
throw new Error("Command is stopped by the hook onBeforeAddThreadComment");
|
|
187
|
+
}
|
|
188
|
+
}));
|
|
189
|
+
}
|
|
190
|
+
onBeforeUpdateThreadComment(callback) {
|
|
191
|
+
return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
|
|
192
|
+
const params = commandInfo.params;
|
|
193
|
+
if (commandInfo.id === UpdateCommentCommand.id) {
|
|
194
|
+
if (params.unitId !== this._workbook.getUnitId())
|
|
195
|
+
return;
|
|
196
|
+
if (callback(params, options) === !1)
|
|
197
|
+
throw new Error("Command is stopped by the hook onBeforeUpdateThreadComment");
|
|
198
|
+
}
|
|
199
|
+
}));
|
|
200
|
+
}
|
|
201
|
+
onBeforeDeleteThreadComment(callback) {
|
|
202
|
+
return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
|
|
203
|
+
const params = commandInfo.params;
|
|
204
|
+
if (commandInfo.id === DeleteCommentCommand.id || commandInfo.id === DeleteCommentTreeCommand.id) {
|
|
205
|
+
if (params.unitId !== this._workbook.getUnitId())
|
|
206
|
+
return;
|
|
207
|
+
if (callback(params, options) === !1)
|
|
208
|
+
throw new Error("Command is stopped by the hook onBeforeDeleteThreadComment");
|
|
209
|
+
}
|
|
210
|
+
}));
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
__name(_FWorkbookThreadCommentMixin, "FWorkbookThreadCommentMixin");
|
|
214
|
+
let FWorkbookThreadCommentMixin = _FWorkbookThreadCommentMixin;
|
|
215
|
+
FWorkbook.extend(FWorkbookThreadCommentMixin);
|
|
216
|
+
const _FWorksheetCommentMixin = class _FWorksheetCommentMixin extends FWorksheet {
|
|
217
|
+
getComments() {
|
|
218
|
+
return this._injector.get(SheetsThreadCommentModel).getSubUnitAll(this._workbook.getUnitId(), this._worksheet.getSheetId()).map((comment) => this._injector.createInstance(FThreadComment, comment));
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
__name(_FWorksheetCommentMixin, "FWorksheetCommentMixin");
|
|
222
|
+
let FWorksheetCommentMixin = _FWorksheetCommentMixin;
|
|
223
|
+
FWorksheet.extend(FWorksheetCommentMixin);
|
|
224
|
+
export {
|
|
225
|
+
FThreadComment
|
|
226
|
+
};
|