@univerjs/thread-comment-ui 0.20.1 → 0.21.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/lib/cjs/index.js +844 -4
- package/lib/cjs/locale/ca-ES.js +37 -1
- package/lib/cjs/locale/en-US.js +52 -1
- package/lib/cjs/locale/es-ES.js +37 -1
- package/lib/cjs/locale/fa-IR.js +37 -1
- package/lib/cjs/locale/fr-FR.js +37 -1
- package/lib/cjs/locale/ja-JP.js +37 -1
- package/lib/cjs/locale/ko-KR.js +37 -1
- package/lib/cjs/locale/ru-RU.js +37 -1
- package/lib/cjs/locale/sk-SK.js +37 -1
- package/lib/cjs/locale/vi-VN.js +37 -1
- package/lib/cjs/locale/zh-CN.js +37 -1
- package/lib/cjs/locale/zh-TW.js +37 -1
- package/lib/es/index.js +828 -4
- package/lib/es/locale/ca-ES.js +36 -1
- package/lib/es/locale/en-US.js +51 -1
- package/lib/es/locale/es-ES.js +36 -1
- package/lib/es/locale/fa-IR.js +36 -1
- package/lib/es/locale/fr-FR.js +36 -1
- package/lib/es/locale/ja-JP.js +36 -1
- package/lib/es/locale/ko-KR.js +36 -1
- package/lib/es/locale/ru-RU.js +36 -1
- package/lib/es/locale/sk-SK.js +36 -1
- package/lib/es/locale/vi-VN.js +36 -1
- package/lib/es/locale/zh-CN.js +36 -1
- package/lib/es/locale/zh-TW.js +36 -1
- package/lib/index.js +828 -4
- package/lib/locale/ca-ES.js +36 -1
- package/lib/locale/en-US.js +51 -1
- package/lib/locale/es-ES.js +36 -1
- package/lib/locale/fa-IR.js +36 -1
- package/lib/locale/fr-FR.js +36 -1
- package/lib/locale/ja-JP.js +36 -1
- package/lib/locale/ko-KR.js +36 -1
- package/lib/locale/ru-RU.js +36 -1
- package/lib/locale/sk-SK.js +36 -1
- package/lib/locale/vi-VN.js +36 -1
- package/lib/locale/zh-CN.js +36 -1
- package/lib/locale/zh-TW.js +36 -1
- package/lib/umd/index.js +1 -1
- package/package.json +9 -9
package/lib/es/index.js
CHANGED
|
@@ -1,4 +1,828 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { BuildTextUtils, CommandType, CustomRangeType, DOCS_COMMENT_EDITOR_UNIT_ID_KEY, DOCS_NORMAL_EDITOR_UNIT_ID_KEY, DependentOn, Disposable, ICommandService, IConfigService, IUniverInstanceService, Inject, Injector, LocaleService, Plugin, Tools, UniverInstanceType, UserManagerService, generateRandomId, getBodySlice, merge, mergeOverrideWithDependencies } from "@univerjs/core";
|
|
2
|
+
import { ISidebarService, KeyCode, UI_PLUGIN_CONFIG_KEY, useConfigValue, useDependency, useObservable } from "@univerjs/ui";
|
|
3
|
+
import { BehaviorSubject, debounceTime, filter } from "rxjs";
|
|
4
|
+
import { AddCommentCommand, DeleteCommentCommand, DeleteCommentTreeCommand, ResolveCommentCommand, ThreadCommentModel, UniverThreadCommentPlugin, UpdateCommentCommand, getDT } from "@univerjs/thread-comment";
|
|
5
|
+
import { Button, Dropdown, Select, Tooltip, borderClassName, clsx, scrollbarClassName } from "@univerjs/design";
|
|
6
|
+
import { DeleteIcon, IncreaseIcon, MoreHorizontalIcon, ReplyToCommentIcon, ResolvedIcon, SolveIcon } from "@univerjs/icons";
|
|
7
|
+
import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
|
|
8
|
+
import { BreakLineCommand, IEditorService, RichTextEditor } from "@univerjs/docs-ui";
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
|
|
11
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
|
|
12
|
+
function _typeof(o) {
|
|
13
|
+
"@babel/helpers - typeof";
|
|
14
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
15
|
+
return typeof o;
|
|
16
|
+
} : function(o) {
|
|
17
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
18
|
+
}, _typeof(o);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
|
|
23
|
+
function toPrimitive(t, r) {
|
|
24
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
25
|
+
var e = t[Symbol.toPrimitive];
|
|
26
|
+
if (void 0 !== e) {
|
|
27
|
+
var i = e.call(t, r || "default");
|
|
28
|
+
if ("object" != _typeof(i)) return i;
|
|
29
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
30
|
+
}
|
|
31
|
+
return ("string" === r ? String : Number)(t);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
|
|
36
|
+
function toPropertyKey(t) {
|
|
37
|
+
var i = toPrimitive(t, "string");
|
|
38
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
|
|
43
|
+
function _defineProperty(e, r, t) {
|
|
44
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
45
|
+
value: t,
|
|
46
|
+
enumerable: !0,
|
|
47
|
+
configurable: !0,
|
|
48
|
+
writable: !0
|
|
49
|
+
}) : e[r] = t, e;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
|
|
54
|
+
function __decorateParam(paramIndex, decorator) {
|
|
55
|
+
return function(target, key) {
|
|
56
|
+
decorator(target, key, paramIndex);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
|
|
62
|
+
function __decorate(decorators, target, key, desc) {
|
|
63
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
64
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
65
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
66
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/services/thread-comment-panel.service.ts
|
|
71
|
+
let ThreadCommentPanelService = class ThreadCommentPanelService extends Disposable {
|
|
72
|
+
constructor(_sidebarService, _univerInstanceService) {
|
|
73
|
+
super();
|
|
74
|
+
this._sidebarService = _sidebarService;
|
|
75
|
+
this._univerInstanceService = _univerInstanceService;
|
|
76
|
+
_defineProperty(this, "_panelVisible", false);
|
|
77
|
+
_defineProperty(this, "_panelVisible$", new BehaviorSubject(false));
|
|
78
|
+
_defineProperty(this, "_activeCommentId", void 0);
|
|
79
|
+
_defineProperty(this, "_activeCommentId$", new BehaviorSubject(void 0));
|
|
80
|
+
_defineProperty(this, "panelVisible$", this._panelVisible$.asObservable());
|
|
81
|
+
_defineProperty(this, "activeCommentId$", this._activeCommentId$.asObservable());
|
|
82
|
+
this._init();
|
|
83
|
+
this.disposeWithMe(() => {
|
|
84
|
+
this._activeCommentId$.complete();
|
|
85
|
+
this._panelVisible$.complete();
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
_init() {
|
|
89
|
+
this.disposeWithMe(this._sidebarService.sidebarOptions$.subscribe((opt) => {
|
|
90
|
+
if (!opt.visible) this.setPanelVisible(false);
|
|
91
|
+
}));
|
|
92
|
+
this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(UniverInstanceType.UNIVER_SHEET).pipe(filter((sheet) => !sheet)).subscribe(() => {
|
|
93
|
+
this._sidebarService.close();
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
get panelVisible() {
|
|
97
|
+
return this._panelVisible;
|
|
98
|
+
}
|
|
99
|
+
get activeCommentId() {
|
|
100
|
+
return this._activeCommentId;
|
|
101
|
+
}
|
|
102
|
+
setPanelVisible(visible) {
|
|
103
|
+
this._panelVisible = visible;
|
|
104
|
+
this._panelVisible$.next(visible);
|
|
105
|
+
}
|
|
106
|
+
setActiveComment(commentInfo) {
|
|
107
|
+
this._activeCommentId = commentInfo;
|
|
108
|
+
this._activeCommentId$.next(commentInfo);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
ThreadCommentPanelService = __decorate([__decorateParam(0, Inject(ISidebarService)), __decorateParam(1, IUniverInstanceService)], ThreadCommentPanelService);
|
|
112
|
+
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/commands/operations/comment.operations.ts
|
|
115
|
+
const SetActiveCommentOperation = {
|
|
116
|
+
id: "thread-comment-ui.operation.set-active-comment",
|
|
117
|
+
type: CommandType.OPERATION,
|
|
118
|
+
handler(accessor, params) {
|
|
119
|
+
accessor.get(ThreadCommentPanelService).setActiveComment(params);
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region package.json
|
|
126
|
+
var name = "@univerjs/thread-comment-ui";
|
|
127
|
+
var version = "0.21.0";
|
|
128
|
+
|
|
129
|
+
//#endregion
|
|
130
|
+
//#region src/config/config.ts
|
|
131
|
+
const THREAD_COMMENT_UI_PLUGIN_CONFIG_KEY = "thread-comment-ui.config";
|
|
132
|
+
const configSymbol = Symbol(THREAD_COMMENT_UI_PLUGIN_CONFIG_KEY);
|
|
133
|
+
const defaultPluginConfig = {};
|
|
134
|
+
|
|
135
|
+
//#endregion
|
|
136
|
+
//#region src/types/const.ts
|
|
137
|
+
/**
|
|
138
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
139
|
+
*
|
|
140
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
141
|
+
* you may not use this file except in compliance with the License.
|
|
142
|
+
* You may obtain a copy of the License at
|
|
143
|
+
*
|
|
144
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
145
|
+
*
|
|
146
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
147
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
148
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
149
|
+
* See the License for the specific language governing permissions and
|
|
150
|
+
* limitations under the License.
|
|
151
|
+
*/
|
|
152
|
+
const PLUGIN_NAME = "UNIVER_THREAD_COMMENT_UI_PLUGIN";
|
|
153
|
+
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/plugin.ts
|
|
156
|
+
let UniverThreadCommentUIPlugin = class UniverThreadCommentUIPlugin extends Plugin {
|
|
157
|
+
constructor(_config = defaultPluginConfig, _injector, _commandService, _configService) {
|
|
158
|
+
super();
|
|
159
|
+
this._config = _config;
|
|
160
|
+
this._injector = _injector;
|
|
161
|
+
this._commandService = _commandService;
|
|
162
|
+
this._configService = _configService;
|
|
163
|
+
const { menu, ...rest } = merge({}, defaultPluginConfig, this._config);
|
|
164
|
+
if (menu) this._configService.setConfig("menu", menu, { merge: true });
|
|
165
|
+
this._configService.setConfig(THREAD_COMMENT_UI_PLUGIN_CONFIG_KEY, rest);
|
|
166
|
+
}
|
|
167
|
+
onStarting() {
|
|
168
|
+
var _this$_config;
|
|
169
|
+
mergeOverrideWithDependencies([[ThreadCommentPanelService]], (_this$_config = this._config) === null || _this$_config === void 0 ? void 0 : _this$_config.overrides).forEach((dep) => {
|
|
170
|
+
this._injector.add(dep);
|
|
171
|
+
});
|
|
172
|
+
[SetActiveCommentOperation].forEach((command) => {
|
|
173
|
+
this._commandService.registerCommand(command);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
_defineProperty(UniverThreadCommentUIPlugin, "pluginName", PLUGIN_NAME);
|
|
178
|
+
_defineProperty(UniverThreadCommentUIPlugin, "packageName", name);
|
|
179
|
+
_defineProperty(UniverThreadCommentUIPlugin, "version", version);
|
|
180
|
+
_defineProperty(UniverThreadCommentUIPlugin, "type", UniverInstanceType.UNIVER_UNKNOWN);
|
|
181
|
+
UniverThreadCommentUIPlugin = __decorate([
|
|
182
|
+
DependentOn(UniverThreadCommentPlugin),
|
|
183
|
+
__decorateParam(1, Inject(Injector)),
|
|
184
|
+
__decorateParam(2, ICommandService),
|
|
185
|
+
__decorateParam(3, IConfigService)
|
|
186
|
+
], UniverThreadCommentUIPlugin);
|
|
187
|
+
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/views/thread-comment-editor/index.tsx
|
|
190
|
+
function getSnapshot(body) {
|
|
191
|
+
return {
|
|
192
|
+
id: "d",
|
|
193
|
+
body,
|
|
194
|
+
documentStyle: {}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
const ThreadCommentEditor = forwardRef((props, ref) => {
|
|
198
|
+
var _editor$current5;
|
|
199
|
+
const { comment, onSave, id, onCancel, autoFocus, unitId, type, editorId } = props;
|
|
200
|
+
const commandService = useDependency(ICommandService);
|
|
201
|
+
const localeService = useDependency(LocaleService);
|
|
202
|
+
const [editing, setEditing] = useState(false);
|
|
203
|
+
const editorService = useDependency(IEditorService);
|
|
204
|
+
const editor = useRef(null);
|
|
205
|
+
const rootEditorId = type === UniverInstanceType.UNIVER_DOC ? DOCS_NORMAL_EDITOR_UNIT_ID_KEY : unitId;
|
|
206
|
+
const [canSubmit, setCanSubmit] = useState(() => {
|
|
207
|
+
var _editor$current$getDo, _editor$current;
|
|
208
|
+
return BuildTextUtils.transform.getPlainText((_editor$current$getDo = (_editor$current = editor.current) === null || _editor$current === void 0 || (_editor$current = _editor$current.getDocumentData().body) === null || _editor$current === void 0 ? void 0 : _editor$current.dataStream) !== null && _editor$current$getDo !== void 0 ? _editor$current$getDo : "");
|
|
209
|
+
});
|
|
210
|
+
useEffect(() => {
|
|
211
|
+
var _editor$current$getDo2, _editor$current2, _editor$current3;
|
|
212
|
+
setCanSubmit(BuildTextUtils.transform.getPlainText((_editor$current$getDo2 = (_editor$current2 = editor.current) === null || _editor$current2 === void 0 || (_editor$current2 = _editor$current2.getDocumentData().body) === null || _editor$current2 === void 0 ? void 0 : _editor$current2.dataStream) !== null && _editor$current$getDo2 !== void 0 ? _editor$current$getDo2 : ""));
|
|
213
|
+
const sub = (_editor$current3 = editor.current) === null || _editor$current3 === void 0 ? void 0 : _editor$current3.selectionChange$.subscribe(() => {
|
|
214
|
+
var _editor$current$getDo3, _editor$current4;
|
|
215
|
+
setCanSubmit(BuildTextUtils.transform.getPlainText((_editor$current$getDo3 = (_editor$current4 = editor.current) === null || _editor$current4 === void 0 || (_editor$current4 = _editor$current4.getDocumentData().body) === null || _editor$current4 === void 0 ? void 0 : _editor$current4.dataStream) !== null && _editor$current$getDo3 !== void 0 ? _editor$current$getDo3 : ""));
|
|
216
|
+
});
|
|
217
|
+
return () => sub === null || sub === void 0 ? void 0 : sub.unsubscribe();
|
|
218
|
+
}, [(_editor$current5 = editor.current) === null || _editor$current5 === void 0 ? void 0 : _editor$current5.selectionChange$]);
|
|
219
|
+
const keyboardEventConfig = useMemo(() => ({
|
|
220
|
+
keyCodes: [{ keyCode: KeyCode.ENTER }],
|
|
221
|
+
handler: (keyCode) => {
|
|
222
|
+
if (keyCode === KeyCode.ENTER) commandService.executeCommand(BreakLineCommand.id);
|
|
223
|
+
}
|
|
224
|
+
}), [commandService]);
|
|
225
|
+
useImperativeHandle(ref, () => ({ reply(text) {
|
|
226
|
+
var _getEditorId, _editor$current6;
|
|
227
|
+
if (!editor.current) return;
|
|
228
|
+
editorService.focus((_getEditorId = editor.current.getEditorId()) !== null && _getEditorId !== void 0 ? _getEditorId : "");
|
|
229
|
+
const documentData = getSnapshot(text);
|
|
230
|
+
(_editor$current6 = editor.current) === null || _editor$current6 === void 0 || _editor$current6.setDocumentData(documentData, [{
|
|
231
|
+
startOffset: documentData.body.dataStream.length - 2,
|
|
232
|
+
endOffset: documentData.body.dataStream.length - 2,
|
|
233
|
+
collapsed: true
|
|
234
|
+
}]);
|
|
235
|
+
} }));
|
|
236
|
+
const handleSave = () => {
|
|
237
|
+
if (editor.current) {
|
|
238
|
+
const newText = Tools.deepClone(editor.current.getDocumentData().body);
|
|
239
|
+
setEditing(false);
|
|
240
|
+
onSave === null || onSave === void 0 || onSave({
|
|
241
|
+
...comment,
|
|
242
|
+
text: newText
|
|
243
|
+
});
|
|
244
|
+
editor.current.replaceText("");
|
|
245
|
+
setTimeout(() => {
|
|
246
|
+
var _editor$current7, _editor$current8;
|
|
247
|
+
(_editor$current7 = editor.current) === null || _editor$current7 === void 0 || _editor$current7.setSelectionRanges([]);
|
|
248
|
+
(_editor$current8 = editor.current) === null || _editor$current8 === void 0 || _editor$current8.blur();
|
|
249
|
+
}, 10);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
253
|
+
onClick: (e) => e.preventDefault(),
|
|
254
|
+
children: [/* @__PURE__ */ jsx(RichTextEditor, {
|
|
255
|
+
className: "univer-w-full",
|
|
256
|
+
editorRef: editor,
|
|
257
|
+
editorId,
|
|
258
|
+
autoFocus,
|
|
259
|
+
keyboardEventConfig,
|
|
260
|
+
placeholder: localeService.t("threadCommentUI.editor.placeholder"),
|
|
261
|
+
initialValue: (comment === null || comment === void 0 ? void 0 : comment.text) && getSnapshot(comment.text),
|
|
262
|
+
onFocusChange: (isFocus) => isFocus && setEditing(isFocus),
|
|
263
|
+
isSingle: false,
|
|
264
|
+
maxHeight: 64,
|
|
265
|
+
onClickOutside: () => {
|
|
266
|
+
setTimeout(() => {
|
|
267
|
+
editorService.focus(rootEditorId);
|
|
268
|
+
}, 30);
|
|
269
|
+
}
|
|
270
|
+
}), editing ? /* @__PURE__ */ jsxs("div", {
|
|
271
|
+
className: "univer-mt-3 univer-flex univer-flex-row univer-justify-end univer-gap-2",
|
|
272
|
+
children: [/* @__PURE__ */ jsx(Button, {
|
|
273
|
+
onClick: () => {
|
|
274
|
+
var _editor$current9;
|
|
275
|
+
onCancel === null || onCancel === void 0 || onCancel();
|
|
276
|
+
setEditing(false);
|
|
277
|
+
(_editor$current9 = editor.current) === null || _editor$current9 === void 0 || _editor$current9.replaceText("", true);
|
|
278
|
+
commandService.executeCommand(SetActiveCommentOperation.id);
|
|
279
|
+
},
|
|
280
|
+
children: localeService.t("threadCommentUI.editor.cancel")
|
|
281
|
+
}), /* @__PURE__ */ jsx(Button, {
|
|
282
|
+
variant: "primary",
|
|
283
|
+
disabled: !canSubmit,
|
|
284
|
+
onClick: handleSave,
|
|
285
|
+
children: localeService.t(id ? "threadCommentUI.editor.save" : "threadCommentUI.editor.reply")
|
|
286
|
+
})]
|
|
287
|
+
}) : null]
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
//#endregion
|
|
292
|
+
//#region src/views/thread-comment-editor/util.ts
|
|
293
|
+
const transformDocument2TextNodesInParagraph = (doc) => {
|
|
294
|
+
const { dataStream, customRanges } = doc;
|
|
295
|
+
const end = dataStream.endsWith("\r\n") ? dataStream.length - 2 : dataStream.length;
|
|
296
|
+
const textNodes = [];
|
|
297
|
+
let lastIndex = 0;
|
|
298
|
+
customRanges === null || customRanges === void 0 || customRanges.forEach((range) => {
|
|
299
|
+
if (lastIndex < range.startIndex) textNodes.push({
|
|
300
|
+
type: "text",
|
|
301
|
+
content: dataStream.slice(lastIndex, range.startIndex)
|
|
302
|
+
});
|
|
303
|
+
textNodes.push({
|
|
304
|
+
type: "mention",
|
|
305
|
+
content: {
|
|
306
|
+
label: dataStream.slice(range.startIndex, range.endIndex + 1),
|
|
307
|
+
id: range.rangeId
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
lastIndex = range.endIndex + 1;
|
|
311
|
+
});
|
|
312
|
+
textNodes.push({
|
|
313
|
+
type: "text",
|
|
314
|
+
content: dataStream.slice(lastIndex, end)
|
|
315
|
+
});
|
|
316
|
+
return textNodes;
|
|
317
|
+
};
|
|
318
|
+
const transformDocument2TextNodes = (doc) => {
|
|
319
|
+
if (!doc) return [];
|
|
320
|
+
const { paragraphs = [] } = doc;
|
|
321
|
+
return paragraphs.map((paragraph, index) => {
|
|
322
|
+
return transformDocument2TextNodesInParagraph(getBodySlice(doc, index === 0 ? 0 : paragraphs[index - 1].startIndex + 1, paragraph.startIndex));
|
|
323
|
+
});
|
|
324
|
+
};
|
|
325
|
+
const transformTextNodes2Document = (nodes) => {
|
|
326
|
+
let str = "";
|
|
327
|
+
const customRanges = [];
|
|
328
|
+
nodes.forEach((node) => {
|
|
329
|
+
switch (node.type) {
|
|
330
|
+
case "text":
|
|
331
|
+
str += node.content;
|
|
332
|
+
break;
|
|
333
|
+
case "mention": {
|
|
334
|
+
const start = str.length;
|
|
335
|
+
str += node.content.label;
|
|
336
|
+
const end = str.length - 1;
|
|
337
|
+
customRanges.push({
|
|
338
|
+
rangeId: node.content.id,
|
|
339
|
+
rangeType: CustomRangeType.MENTION,
|
|
340
|
+
startIndex: start,
|
|
341
|
+
endIndex: end,
|
|
342
|
+
properties: {},
|
|
343
|
+
wholeEntity: true
|
|
344
|
+
});
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
default: break;
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
str += "\r\n";
|
|
351
|
+
return {
|
|
352
|
+
textRuns: [],
|
|
353
|
+
paragraphs: [{
|
|
354
|
+
startIndex: str.length - 2,
|
|
355
|
+
paragraphStyle: {}
|
|
356
|
+
}],
|
|
357
|
+
sectionBreaks: [{ startIndex: str.length - 1 }],
|
|
358
|
+
dataStream: str,
|
|
359
|
+
customRanges
|
|
360
|
+
};
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
//#endregion
|
|
364
|
+
//#region src/views/thread-comment-tree/index.tsx
|
|
365
|
+
let ThreadCommentTreeLocation = /* @__PURE__ */ function(ThreadCommentTreeLocation) {
|
|
366
|
+
ThreadCommentTreeLocation["CELL"] = "CELL";
|
|
367
|
+
ThreadCommentTreeLocation["PANEL"] = "PANEL";
|
|
368
|
+
return ThreadCommentTreeLocation;
|
|
369
|
+
}({});
|
|
370
|
+
const MOCK_ID = "__mock__";
|
|
371
|
+
const ThreadCommentItem = (props) => {
|
|
372
|
+
const { item, unitId, subUnitId, editing, onEditingChange, onReply, resolved, isRoot, onClose, onDeleteComment, type, threadCommentEditorId } = props;
|
|
373
|
+
const commandService = useDependency(ICommandService);
|
|
374
|
+
const localeService = useDependency(LocaleService);
|
|
375
|
+
const userManagerService = useDependency(UserManagerService);
|
|
376
|
+
const user = userManagerService.getUser(item.personId);
|
|
377
|
+
const currentUser = useObservable(userManagerService.currentUser$);
|
|
378
|
+
const isCommentBySelf = (currentUser === null || currentUser === void 0 ? void 0 : currentUser.userID) === item.personId;
|
|
379
|
+
const isMock = item.id === MOCK_ID;
|
|
380
|
+
const [showReply, setShowReply] = useState(false);
|
|
381
|
+
const uiConfig = useConfigValue(UI_PLUGIN_CONFIG_KEY);
|
|
382
|
+
const avatarFallback = uiConfig === null || uiConfig === void 0 ? void 0 : uiConfig.avatarFallback;
|
|
383
|
+
const handleDeleteItem = () => {
|
|
384
|
+
if ((onDeleteComment === null || onDeleteComment === void 0 ? void 0 : onDeleteComment(item)) === false) return;
|
|
385
|
+
commandService.executeCommand(isRoot ? DeleteCommentTreeCommand.id : DeleteCommentCommand.id, {
|
|
386
|
+
unitId,
|
|
387
|
+
subUnitId,
|
|
388
|
+
commentId: item.id
|
|
389
|
+
});
|
|
390
|
+
if (isRoot) onClose === null || onClose === void 0 || onClose();
|
|
391
|
+
};
|
|
392
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
393
|
+
className: "univer-relative univer-mb-3 univer-pl-[30px]",
|
|
394
|
+
onMouseLeave: () => setShowReply(false),
|
|
395
|
+
onMouseEnter: () => setShowReply(true),
|
|
396
|
+
children: [
|
|
397
|
+
/* @__PURE__ */ jsx("div", {
|
|
398
|
+
className: "univer-absolute univer-left-0 univer-top-0 univer-size-6 univer-rounded-full univer-bg-cover univer-bg-center univer-bg-no-repeat",
|
|
399
|
+
style: { backgroundImage: `url(${(user === null || user === void 0 ? void 0 : user.avatar) || avatarFallback})` }
|
|
400
|
+
}),
|
|
401
|
+
user ? /* @__PURE__ */ jsxs("div", {
|
|
402
|
+
className: "univer-mb-1 univer-flex univer-h-6 univer-items-center univer-justify-between",
|
|
403
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
404
|
+
className: "univer-text-sm univer-font-medium univer-leading-5",
|
|
405
|
+
children: (user === null || user === void 0 ? void 0 : user.name) || " "
|
|
406
|
+
}), /* @__PURE__ */ jsxs("div", { children: [isMock || resolved ? null : showReply && user ? /* @__PURE__ */ jsx("div", {
|
|
407
|
+
className: "univer-ml-1 univer-inline-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-sm univer-text-base hover:univer-bg-gray-50",
|
|
408
|
+
onClick: () => onReply(user),
|
|
409
|
+
children: /* @__PURE__ */ jsx(ReplyToCommentIcon, {})
|
|
410
|
+
}) : null, isCommentBySelf && !isMock && !resolved ? /* @__PURE__ */ jsx(Dropdown, {
|
|
411
|
+
overlay: /* @__PURE__ */ jsx("div", {
|
|
412
|
+
className: "univer-rounded-lg",
|
|
413
|
+
children: /* @__PURE__ */ jsxs("ul", {
|
|
414
|
+
className: "univer-m-0 univer-box-border univer-grid univer-list-none univer-p-1.5 univer-text-sm [&_a]:univer-block [&_a]:univer-cursor-pointer [&_a]:univer-rounded [&_a]:univer-px-2 [&_a]:univer-py-1.5 [&_a]:univer-transition-colors",
|
|
415
|
+
children: [/* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("a", {
|
|
416
|
+
className: "hover:univer-bg-gray-200",
|
|
417
|
+
onClick: () => onEditingChange === null || onEditingChange === void 0 ? void 0 : onEditingChange(true),
|
|
418
|
+
children: localeService.t("threadCommentUI.item.edit")
|
|
419
|
+
}) }), /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx("a", {
|
|
420
|
+
className: "hover:univer-bg-gray-200",
|
|
421
|
+
onClick: handleDeleteItem,
|
|
422
|
+
children: localeService.t("threadCommentUI.item.delete")
|
|
423
|
+
}) })]
|
|
424
|
+
})
|
|
425
|
+
}),
|
|
426
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
427
|
+
className: "univer-ml-1 univer-inline-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-sm univer-text-base hover:univer-bg-gray-50",
|
|
428
|
+
children: /* @__PURE__ */ jsx(MoreHorizontalIcon, {})
|
|
429
|
+
})
|
|
430
|
+
}) : null] })]
|
|
431
|
+
}) : null,
|
|
432
|
+
/* @__PURE__ */ jsx("time", {
|
|
433
|
+
className: "univer-mb-1 univer-text-xs/normal univer-text-gray-600 dark:!univer-text-gray-200",
|
|
434
|
+
children: item.dT
|
|
435
|
+
}),
|
|
436
|
+
editing ? /* @__PURE__ */ jsx(ThreadCommentEditor, {
|
|
437
|
+
type,
|
|
438
|
+
id: item.id,
|
|
439
|
+
comment: item,
|
|
440
|
+
onCancel: () => onEditingChange === null || onEditingChange === void 0 ? void 0 : onEditingChange(false),
|
|
441
|
+
autoFocus: true,
|
|
442
|
+
unitId,
|
|
443
|
+
subUnitId,
|
|
444
|
+
editorId: threadCommentEditorId,
|
|
445
|
+
onSave: ({ text, attachments }) => {
|
|
446
|
+
onEditingChange === null || onEditingChange === void 0 || onEditingChange(false);
|
|
447
|
+
commandService.executeCommand(UpdateCommentCommand.id, {
|
|
448
|
+
unitId,
|
|
449
|
+
subUnitId,
|
|
450
|
+
payload: {
|
|
451
|
+
commentId: item.id,
|
|
452
|
+
text,
|
|
453
|
+
attachments
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
}) : /* @__PURE__ */ jsx("div", {
|
|
458
|
+
className: "univer-text-sm univer-text-gray-900 dark:!univer-text-white",
|
|
459
|
+
children: transformDocument2TextNodes(item.text).map((paragraph, i) => /* @__PURE__ */ jsx("div", {
|
|
460
|
+
className: "univer-break-words",
|
|
461
|
+
children: paragraph.map((item, i) => {
|
|
462
|
+
switch (item.type) {
|
|
463
|
+
case "mention": return /* @__PURE__ */ jsxs("a", {
|
|
464
|
+
className: "univer-text-primary-600",
|
|
465
|
+
children: [item.content.label, " "]
|
|
466
|
+
}, i);
|
|
467
|
+
default: return item.content;
|
|
468
|
+
}
|
|
469
|
+
})
|
|
470
|
+
}, i))
|
|
471
|
+
})
|
|
472
|
+
]
|
|
473
|
+
});
|
|
474
|
+
};
|
|
475
|
+
const ThreadCommentTree = (props) => {
|
|
476
|
+
var _currentUser$userID, _comments$children, _comments$root$subUni;
|
|
477
|
+
const { id, unitId, subUnitId, refStr, showEdit = true, onClick, showHighlight, onClose, getSubUnitName, location, autoFocus, onMouseEnter, onMouseLeave, onAddComment, onDeleteComment, onResolve, type, style, full } = props;
|
|
478
|
+
const threadCommentModel = useDependency(ThreadCommentModel);
|
|
479
|
+
const [isHover, setIsHover] = useState(false);
|
|
480
|
+
const [editingId, setEditingId] = useState("");
|
|
481
|
+
useObservable(useMemo(() => threadCommentModel.commentUpdate$.pipe(debounceTime(16)), [threadCommentModel]));
|
|
482
|
+
const comments = id ? threadCommentModel.getCommentWithChildren(unitId, subUnitId, id) : null;
|
|
483
|
+
const commandService = useDependency(ICommandService);
|
|
484
|
+
const userManagerService = useDependency(UserManagerService);
|
|
485
|
+
const resolved = comments === null || comments === void 0 ? void 0 : comments.root.resolved;
|
|
486
|
+
const currentUser = useObservable(userManagerService.currentUser$);
|
|
487
|
+
const editorRef = useRef(null);
|
|
488
|
+
const renderComments = [...comments ? [comments.root] : [{
|
|
489
|
+
id: MOCK_ID,
|
|
490
|
+
text: { dataStream: "\n\r" },
|
|
491
|
+
personId: (_currentUser$userID = currentUser === null || currentUser === void 0 ? void 0 : currentUser.userID) !== null && _currentUser$userID !== void 0 ? _currentUser$userID : "",
|
|
492
|
+
ref: refStr !== null && refStr !== void 0 ? refStr : "",
|
|
493
|
+
dT: "",
|
|
494
|
+
unitId,
|
|
495
|
+
subUnitId,
|
|
496
|
+
threadId: ""
|
|
497
|
+
}], ...(_comments$children = comments === null || comments === void 0 ? void 0 : comments.children) !== null && _comments$children !== void 0 ? _comments$children : []];
|
|
498
|
+
const scroller = useRef(null);
|
|
499
|
+
const handleResolve = (e) => {
|
|
500
|
+
e.stopPropagation();
|
|
501
|
+
if (!resolved) commandService.executeCommand(SetActiveCommentOperation.id);
|
|
502
|
+
else commandService.executeCommand(SetActiveCommentOperation.id, {
|
|
503
|
+
unitId,
|
|
504
|
+
subUnitId,
|
|
505
|
+
commentId: id
|
|
506
|
+
});
|
|
507
|
+
commandService.executeCommand(ResolveCommentCommand.id, {
|
|
508
|
+
unitId,
|
|
509
|
+
subUnitId,
|
|
510
|
+
commentId: id,
|
|
511
|
+
resolved: !resolved
|
|
512
|
+
});
|
|
513
|
+
onResolve === null || onResolve === void 0 || onResolve(!resolved);
|
|
514
|
+
};
|
|
515
|
+
const handleDeleteRoot = (e) => {
|
|
516
|
+
e.stopPropagation();
|
|
517
|
+
commandService.executeCommand(SetActiveCommentOperation.id);
|
|
518
|
+
if ((comments === null || comments === void 0 ? void 0 : comments.root) && (onDeleteComment === null || onDeleteComment === void 0 ? void 0 : onDeleteComment(comments.root)) === false) return;
|
|
519
|
+
commandService.executeCommand(DeleteCommentTreeCommand.id, {
|
|
520
|
+
unitId,
|
|
521
|
+
subUnitId,
|
|
522
|
+
commentId: id
|
|
523
|
+
});
|
|
524
|
+
onClose === null || onClose === void 0 || onClose();
|
|
525
|
+
};
|
|
526
|
+
useEffect(() => {
|
|
527
|
+
return onMouseLeave === null || onMouseLeave === void 0 ? void 0 : onMouseLeave();
|
|
528
|
+
}, []);
|
|
529
|
+
const subUnitName = getSubUnitName((_comments$root$subUni = comments === null || comments === void 0 ? void 0 : comments.root.subUnitId) !== null && _comments$root$subUni !== void 0 ? _comments$root$subUni : subUnitId);
|
|
530
|
+
const editorVisible = showEdit && !editingId && !resolved;
|
|
531
|
+
const title = `${refStr || (comments === null || comments === void 0 ? void 0 : comments.root.ref) || ""}${subUnitName ? " · " : ""}${subUnitName}`;
|
|
532
|
+
const threadCommentEditorId = `${DOCS_COMMENT_EDITOR_UNIT_ID_KEY}_${location}`;
|
|
533
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
534
|
+
id: `${location}-${unitId}-${subUnitId}-${id}`,
|
|
535
|
+
className: clsx("univer-relative univer-box-border univer-rounded-md univer-bg-white univer-p-4 dark:!univer-bg-gray-900 dark:!univer-text-white", borderClassName, {
|
|
536
|
+
"univer-w-[278px]": !full,
|
|
537
|
+
"univer-w-full": full,
|
|
538
|
+
"univer-shadow": !resolved && (showHighlight || isHover || location === ThreadCommentTreeLocation.CELL)
|
|
539
|
+
}),
|
|
540
|
+
style,
|
|
541
|
+
onClick,
|
|
542
|
+
onMouseEnter: () => {
|
|
543
|
+
onMouseEnter === null || onMouseEnter === void 0 || onMouseEnter();
|
|
544
|
+
setIsHover(true);
|
|
545
|
+
},
|
|
546
|
+
onMouseLeave: () => {
|
|
547
|
+
onMouseLeave === null || onMouseLeave === void 0 || onMouseLeave();
|
|
548
|
+
setIsHover(false);
|
|
549
|
+
},
|
|
550
|
+
children: [
|
|
551
|
+
!resolved && showHighlight && /* @__PURE__ */ jsx("div", { className: "univer-absolute univer-left-0 univer-right-0 univer-top-0 univer-h-1.5 univer-rounded-t-md univer-bg-yellow-400" }),
|
|
552
|
+
/* @__PURE__ */ jsxs("div", {
|
|
553
|
+
className: "univer-mb-4 univer-flex univer-flex-row univer-items-center univer-justify-between univer-text-sm univer-leading-5",
|
|
554
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
555
|
+
className: "univer-flex univer-flex-1 univer-flex-row univer-items-center univer-overflow-hidden",
|
|
556
|
+
children: [/* @__PURE__ */ jsx("div", { className: "univer-mr-2 univer-h-3.5 univer-w-[3px] univer-flex-shrink-0 univer-flex-grow-0 univer-rounded-sm univer-bg-yellow-500" }), /* @__PURE__ */ jsx(Tooltip, {
|
|
557
|
+
showIfEllipsis: true,
|
|
558
|
+
title,
|
|
559
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
560
|
+
className: "univer-flex-1 univer-truncate",
|
|
561
|
+
children: title
|
|
562
|
+
})
|
|
563
|
+
})]
|
|
564
|
+
}), !!comments && /* @__PURE__ */ jsxs("div", {
|
|
565
|
+
className: "univer-flex univer-flex-shrink-0 univer-flex-grow-0 univer-flex-row",
|
|
566
|
+
children: [/* @__PURE__ */ jsx("div", {
|
|
567
|
+
className: clsx("univer-ml-1 univer-inline-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-[3px] univer-text-base hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-800", { "univer-text-green-500": resolved }),
|
|
568
|
+
onClick: handleResolve,
|
|
569
|
+
children: resolved ? /* @__PURE__ */ jsx(ResolvedIcon, {}) : /* @__PURE__ */ jsx(SolveIcon, {})
|
|
570
|
+
}), (currentUser === null || currentUser === void 0 ? void 0 : currentUser.userID) === comments.root.personId ? /* @__PURE__ */ jsx("div", {
|
|
571
|
+
className: "univer-ml-1 univer-inline-flex univer-size-6 univer-cursor-pointer univer-items-center univer-justify-center univer-rounded-[3px] univer-text-base hover:univer-bg-gray-50 dark:hover:!univer-bg-gray-800",
|
|
572
|
+
onClick: handleDeleteRoot,
|
|
573
|
+
children: /* @__PURE__ */ jsx(DeleteIcon, {})
|
|
574
|
+
}) : null]
|
|
575
|
+
})]
|
|
576
|
+
}),
|
|
577
|
+
/* @__PURE__ */ jsx("div", {
|
|
578
|
+
ref: scroller,
|
|
579
|
+
className: clsx("univer-max-h-80 univer-overflow-y-auto univer-overflow-x-hidden", scrollbarClassName),
|
|
580
|
+
children: renderComments.map((item) => /* @__PURE__ */ jsx(ThreadCommentItem, {
|
|
581
|
+
unitId,
|
|
582
|
+
subUnitId,
|
|
583
|
+
item,
|
|
584
|
+
isRoot: item.id === (comments === null || comments === void 0 ? void 0 : comments.root.id),
|
|
585
|
+
editing: editingId === item.id,
|
|
586
|
+
resolved: comments === null || comments === void 0 ? void 0 : comments.root.resolved,
|
|
587
|
+
type,
|
|
588
|
+
threadCommentEditorId,
|
|
589
|
+
onClose,
|
|
590
|
+
onEditingChange: (editing) => {
|
|
591
|
+
if (editing) setEditingId(item.id);
|
|
592
|
+
else setEditingId("");
|
|
593
|
+
},
|
|
594
|
+
onReply: (user) => {
|
|
595
|
+
if (!user) return;
|
|
596
|
+
requestAnimationFrame(() => {
|
|
597
|
+
var _editorRef$current;
|
|
598
|
+
(_editorRef$current = editorRef.current) === null || _editorRef$current === void 0 || _editorRef$current.reply(transformTextNodes2Document([{
|
|
599
|
+
type: "mention",
|
|
600
|
+
content: {
|
|
601
|
+
id: user.userID,
|
|
602
|
+
label: `@${user.name}`
|
|
603
|
+
}
|
|
604
|
+
}, {
|
|
605
|
+
type: "text",
|
|
606
|
+
content: " "
|
|
607
|
+
}]));
|
|
608
|
+
});
|
|
609
|
+
},
|
|
610
|
+
onAddComment,
|
|
611
|
+
onDeleteComment
|
|
612
|
+
}, item.id))
|
|
613
|
+
}),
|
|
614
|
+
editorVisible && /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(ThreadCommentEditor, {
|
|
615
|
+
ref: editorRef,
|
|
616
|
+
type,
|
|
617
|
+
unitId,
|
|
618
|
+
subUnitId,
|
|
619
|
+
editorId: threadCommentEditorId,
|
|
620
|
+
onSave: async ({ text, attachments }) => {
|
|
621
|
+
var _currentUser$userID2, _comments$root$thread;
|
|
622
|
+
const comment = {
|
|
623
|
+
text,
|
|
624
|
+
attachments,
|
|
625
|
+
dT: getDT(),
|
|
626
|
+
id: generateRandomId(),
|
|
627
|
+
ref: refStr,
|
|
628
|
+
personId: (_currentUser$userID2 = currentUser === null || currentUser === void 0 ? void 0 : currentUser.userID) !== null && _currentUser$userID2 !== void 0 ? _currentUser$userID2 : "",
|
|
629
|
+
parentId: comments === null || comments === void 0 ? void 0 : comments.root.id,
|
|
630
|
+
unitId,
|
|
631
|
+
subUnitId,
|
|
632
|
+
threadId: (_comments$root$thread = comments === null || comments === void 0 ? void 0 : comments.root.threadId) !== null && _comments$root$thread !== void 0 ? _comments$root$thread : ""
|
|
633
|
+
};
|
|
634
|
+
if ((onAddComment === null || onAddComment === void 0 ? void 0 : onAddComment(comment)) === false) return;
|
|
635
|
+
await commandService.executeCommand(AddCommentCommand.id, {
|
|
636
|
+
unitId,
|
|
637
|
+
subUnitId,
|
|
638
|
+
comment
|
|
639
|
+
});
|
|
640
|
+
if (scroller.current) scroller.current.scrollTop = scroller.current.scrollHeight;
|
|
641
|
+
},
|
|
642
|
+
autoFocus: autoFocus || !comments,
|
|
643
|
+
onCancel: () => {
|
|
644
|
+
if (!comments) onClose === null || onClose === void 0 || onClose();
|
|
645
|
+
}
|
|
646
|
+
}, `${autoFocus}`) })
|
|
647
|
+
]
|
|
648
|
+
});
|
|
649
|
+
};
|
|
650
|
+
|
|
651
|
+
//#endregion
|
|
652
|
+
//#region src/views/thread-comment-panel/index.tsx
|
|
653
|
+
const ThreadCommentPanel = (props) => {
|
|
654
|
+
const { unitId, subUnitId$, type, onAdd, getSubUnitName, onResolve, sortComments, onItemLeave, onItemEnter, disableAdd, tempComment, onAddComment, onDeleteComment, showComments } = props;
|
|
655
|
+
const [unit, setUnit] = useState("all");
|
|
656
|
+
const [status, setStatus] = useState("all");
|
|
657
|
+
const localeService = useDependency(LocaleService);
|
|
658
|
+
const userService = useDependency(UserManagerService);
|
|
659
|
+
const threadCommentModel = useDependency(ThreadCommentModel);
|
|
660
|
+
const [unitComments, setUnitComments] = useState(() => threadCommentModel.getUnit(unitId));
|
|
661
|
+
const activeCommentId = useObservable(useDependency(ThreadCommentPanelService).activeCommentId$);
|
|
662
|
+
const update = useObservable(threadCommentModel.commentUpdate$);
|
|
663
|
+
const commandService = useDependency(ICommandService);
|
|
664
|
+
const subUnitId = useObservable(subUnitId$);
|
|
665
|
+
const shouldScroll = useRef(true);
|
|
666
|
+
const location = ThreadCommentTreeLocation.PANEL;
|
|
667
|
+
const currentUser = useObservable(userService.currentUser$);
|
|
668
|
+
const comments = useMemo(() => {
|
|
669
|
+
var _unitComments$filter;
|
|
670
|
+
const allComments = unit === "all" ? unitComments : (_unitComments$filter = unitComments.filter((i) => i.subUnitId === subUnitId)) !== null && _unitComments$filter !== void 0 ? _unitComments$filter : [];
|
|
671
|
+
const sort = sortComments !== null && sortComments !== void 0 ? sortComments : ((a) => a);
|
|
672
|
+
const res = allComments.map((i) => {
|
|
673
|
+
var _i$children;
|
|
674
|
+
return {
|
|
675
|
+
...i.root,
|
|
676
|
+
children: (_i$children = i.children) !== null && _i$children !== void 0 ? _i$children : [],
|
|
677
|
+
users: i.relativeUsers
|
|
678
|
+
};
|
|
679
|
+
});
|
|
680
|
+
if (showComments) {
|
|
681
|
+
const map = /* @__PURE__ */ new Map();
|
|
682
|
+
res.forEach((comment) => {
|
|
683
|
+
map.set(comment.id, comment);
|
|
684
|
+
});
|
|
685
|
+
return [...showComments, ""].map((id) => map.get(id)).filter(Boolean);
|
|
686
|
+
} else return sort(res);
|
|
687
|
+
}, [
|
|
688
|
+
showComments,
|
|
689
|
+
unit,
|
|
690
|
+
unitComments,
|
|
691
|
+
sortComments,
|
|
692
|
+
subUnitId
|
|
693
|
+
]);
|
|
694
|
+
const commentsSorted = useMemo(() => [...comments.filter((comment) => !comment.resolved), ...comments.filter((comment) => comment.resolved)], [comments]);
|
|
695
|
+
const statuedComments = useMemo(() => {
|
|
696
|
+
if (status === "resolved") return commentsSorted.filter((comment) => comment.resolved);
|
|
697
|
+
if (status === "unsolved") return commentsSorted.filter((comment) => !comment.resolved);
|
|
698
|
+
if (status === "concern_me") {
|
|
699
|
+
if (!(currentUser === null || currentUser === void 0 ? void 0 : currentUser.userID)) return commentsSorted;
|
|
700
|
+
return commentsSorted.filter((comment) => comment === null || comment === void 0 ? void 0 : comment.users.has(currentUser.userID));
|
|
701
|
+
}
|
|
702
|
+
return commentsSorted;
|
|
703
|
+
}, [
|
|
704
|
+
commentsSorted,
|
|
705
|
+
currentUser === null || currentUser === void 0 ? void 0 : currentUser.userID,
|
|
706
|
+
status
|
|
707
|
+
]);
|
|
708
|
+
const renderComments = tempComment ? [tempComment, ...statuedComments] : statuedComments;
|
|
709
|
+
const unSolvedComments = renderComments.filter((comment) => !comment.resolved);
|
|
710
|
+
const solvedComments = renderComments.filter((comment) => comment.resolved);
|
|
711
|
+
const isFiltering = status !== "all" || unit !== "all";
|
|
712
|
+
const onReset = () => {
|
|
713
|
+
setStatus("all");
|
|
714
|
+
setUnit("all");
|
|
715
|
+
};
|
|
716
|
+
useEffect(() => {
|
|
717
|
+
if (unitId) setUnitComments(threadCommentModel.getUnit(unitId));
|
|
718
|
+
}, [
|
|
719
|
+
unitId,
|
|
720
|
+
threadCommentModel,
|
|
721
|
+
update
|
|
722
|
+
]);
|
|
723
|
+
useEffect(() => {
|
|
724
|
+
var _document$getElementB;
|
|
725
|
+
if (!activeCommentId) return;
|
|
726
|
+
if (!shouldScroll.current) {
|
|
727
|
+
shouldScroll.current = true;
|
|
728
|
+
return;
|
|
729
|
+
}
|
|
730
|
+
const { unitId, subUnitId, commentId } = activeCommentId;
|
|
731
|
+
const id = `${location}-${unitId}-${subUnitId}-${commentId}`;
|
|
732
|
+
(_document$getElementB = document.getElementById(id)) === null || _document$getElementB === void 0 || _document$getElementB.scrollIntoView({ block: "center" });
|
|
733
|
+
}, [activeCommentId]);
|
|
734
|
+
const renderComment = (comment) => /* @__PURE__ */ jsx(ThreadCommentTree, {
|
|
735
|
+
location,
|
|
736
|
+
getSubUnitName,
|
|
737
|
+
id: comment.id,
|
|
738
|
+
unitId: comment.unitId,
|
|
739
|
+
subUnitId: comment.subUnitId,
|
|
740
|
+
refStr: comment.ref,
|
|
741
|
+
type,
|
|
742
|
+
showEdit: (activeCommentId === null || activeCommentId === void 0 ? void 0 : activeCommentId.commentId) === comment.id,
|
|
743
|
+
showHighlight: (activeCommentId === null || activeCommentId === void 0 ? void 0 : activeCommentId.commentId) === comment.id,
|
|
744
|
+
onClick: () => {
|
|
745
|
+
shouldScroll.current = false;
|
|
746
|
+
if (!comment.resolved) commandService.executeCommand(SetActiveCommentOperation.id, {
|
|
747
|
+
unitId: comment.unitId,
|
|
748
|
+
subUnitId: comment.subUnitId,
|
|
749
|
+
commentId: comment.id,
|
|
750
|
+
temp: false
|
|
751
|
+
});
|
|
752
|
+
else commandService.executeCommand(SetActiveCommentOperation.id);
|
|
753
|
+
},
|
|
754
|
+
onMouseEnter: () => onItemEnter === null || onItemEnter === void 0 ? void 0 : onItemEnter(comment),
|
|
755
|
+
onMouseLeave: () => onItemLeave === null || onItemLeave === void 0 ? void 0 : onItemLeave(comment),
|
|
756
|
+
onAddComment,
|
|
757
|
+
onDeleteComment,
|
|
758
|
+
onResolve: (resolved) => onResolve === null || onResolve === void 0 ? void 0 : onResolve(comment.id, resolved)
|
|
759
|
+
}, comment.id);
|
|
760
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
761
|
+
className: "univer-flex univer-min-h-full univer-flex-col univer-pb-3",
|
|
762
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
763
|
+
className: "univer-mt-3 univer-flex univer-flex-row univer-justify-between",
|
|
764
|
+
children: [type === UniverInstanceType.UNIVER_SHEET ? /* @__PURE__ */ jsx(Select, {
|
|
765
|
+
borderless: true,
|
|
766
|
+
value: unit,
|
|
767
|
+
options: [{
|
|
768
|
+
value: "current",
|
|
769
|
+
label: localeService.t("threadCommentUI.filter.sheet.current")
|
|
770
|
+
}, {
|
|
771
|
+
value: "all",
|
|
772
|
+
label: localeService.t("threadCommentUI.filter.sheet.all")
|
|
773
|
+
}],
|
|
774
|
+
onChange: setUnit
|
|
775
|
+
}) : null, /* @__PURE__ */ jsx(Select, {
|
|
776
|
+
borderless: true,
|
|
777
|
+
value: status,
|
|
778
|
+
options: [
|
|
779
|
+
{
|
|
780
|
+
value: "all",
|
|
781
|
+
label: localeService.t("threadCommentUI.filter.status.all")
|
|
782
|
+
},
|
|
783
|
+
{
|
|
784
|
+
value: "resolved",
|
|
785
|
+
label: localeService.t("threadCommentUI.filter.status.resolved")
|
|
786
|
+
},
|
|
787
|
+
{
|
|
788
|
+
value: "unsolved",
|
|
789
|
+
label: localeService.t("threadCommentUI.filter.status.unsolved")
|
|
790
|
+
},
|
|
791
|
+
{
|
|
792
|
+
value: "concern_me",
|
|
793
|
+
label: localeService.t("threadCommentUI.filter.status.concernMe")
|
|
794
|
+
}
|
|
795
|
+
],
|
|
796
|
+
onChange: setStatus
|
|
797
|
+
})]
|
|
798
|
+
}), renderComments.length === 0 ? /* @__PURE__ */ jsxs("div", {
|
|
799
|
+
className: "univer-flex univer-flex-1 univer-flex-col univer-items-center univer-justify-center univer-text-sm univer-text-gray-600 dark:!univer-text-gray-200",
|
|
800
|
+
children: [localeService.t("threadCommentUI.panel.empty"), isFiltering ? /* @__PURE__ */ jsx("div", {
|
|
801
|
+
className: "univer-mt-2 univer-flex univer-flex-row",
|
|
802
|
+
children: /* @__PURE__ */ jsx(Button, {
|
|
803
|
+
onClick: onReset,
|
|
804
|
+
children: localeService.t("threadCommentUI.panel.reset")
|
|
805
|
+
})
|
|
806
|
+
}) : !disableAdd ? /* @__PURE__ */ jsx("div", {
|
|
807
|
+
className: "univer-mt-2 univer-flex univer-flex-row",
|
|
808
|
+
children: /* @__PURE__ */ jsxs(Button, {
|
|
809
|
+
onClick: onAdd,
|
|
810
|
+
children: [/* @__PURE__ */ jsx(IncreaseIcon, { className: "univer-mr-1.5" }), localeService.t("threadCommentUI.panel.addComment")]
|
|
811
|
+
})
|
|
812
|
+
}) : null]
|
|
813
|
+
}) : /* @__PURE__ */ jsxs("div", {
|
|
814
|
+
className: "univer-mt-3 univer-flex univer-flex-col univer-gap-3",
|
|
815
|
+
children: [
|
|
816
|
+
unSolvedComments.map(renderComment),
|
|
817
|
+
solvedComments.length > 0 && /* @__PURE__ */ jsx("div", {
|
|
818
|
+
className: "univer-text-xs",
|
|
819
|
+
children: localeService.t("threadCommentUI.panel.solved")
|
|
820
|
+
}),
|
|
821
|
+
solvedComments.map(renderComment)
|
|
822
|
+
]
|
|
823
|
+
})]
|
|
824
|
+
});
|
|
825
|
+
};
|
|
826
|
+
|
|
827
|
+
//#endregion
|
|
828
|
+
export { SetActiveCommentOperation, ThreadCommentPanel, ThreadCommentPanelService, ThreadCommentTree, ThreadCommentTreeLocation, UniverThreadCommentUIPlugin };
|