Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

fix(sheets-thread-comment): fix some ui issues & update readme.md (#2294)

zhangwb230655dfca8
diff --git a/packages/sheets-thread-comment/README-zh.md b/packages/sheets-thread-comment/README-zh.md
index f57dd2229b..9606191a46 100644
--- a/packages/sheets-thread-comment/README-zh.md
+++ b/packages/sheets-thread-comment/README-zh.md
@@ -5,7 +5,8 @@
## 简介
-> TODO: Introduction
+`@univerjs/sheets-thread-comment` 提供了 Univer Sheets 的评论/批注功能。
+
## 使用指南
@@ -18,3 +19,39 @@ npm install @univerjs/sheets-thread-comment
# 使用 pnpm
pnpm add @univerjs/sheets-thread-comment
```
+
+### 使用
+```js
+import { UniverSheetsThreadCommentPlugin } from '@univerjs/sheets-thread-comment';
+
+const mockUser = {
+ userID: 'mockId',
+ name: 'MockUser',
+ avatar: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAInSURBVHgBtZU9TxtBEIbfWRzFSIdkikhBSqRQkJqkCKTCFkqVInSUSaT0wC8w/gXxD4gU2nRJkXQWhAZowDUUWKIwEgWWbEEB3mVmx3dn4DA2nB/ppNuPeWd29mMIPXDr+RxwtgRHeW6+guNPRxogqnL7Dwz9psJ27S4NShaeZTH3kwXy6I81dlRKcmRui88swdq9AcSFL7Buz1Vmlns64MiLsCjzwnIYHLH57tbfFbs7KRaXyEU8FVZofqccOfA5l7Q8LPIkGrwnb2RPNEXWFVMUF3L+kDCk0btDDAMzOm5YfAHDwp4tG74wnzAsiOYMnJ3GoDybA7IT98/jm5+JNnfiIzAS6LlqHQBN/i6b2t/cV1Hh6BfwYlHnHP4AXi5q/8kmMMpOs8+BixZw/Fd6xUEHEbnkgclvQP2fGp7uShRKnQ3G32rkjV1th8JhIGG7tR/JyjGteSOZELwGMmNqIIigRCLRh2OZIE6BjItdd7pCW6Uhm1zzkUtungSxwEUzNpQ+GQumtH1ej1MqgmNT6vwmhCq5yuwq56EYTbgeQUz3yvrpV1b4ok3nYJ+eYhgYmjRUqErx2EDq0Fr8FhG++iqVGqxlUJI/70Ar0UgJaWHj6hYVHJrfKssAHot1JfqwE9WVWzXZVd5z2Ws/4PnmtEjkXeKJDvxUecLbWOXH/DP6QQ4J72NS0adedp1aseBfXP8odlZFfPvBF7SN/8hky1TYuPOAXAEipMx15u5ToAAAAABJRU5ErkJggg==',
+ anonymous: false,
+ canBindAnonymous: false,
+};
+
+univer.registerPlugin(UniverSheetsThreadCommentPlugin, {
+ mentions: [{
+ trigger: '@',
+ // 获取提及用户的通用接口实现
+ getMentions: async () => {
+ return [
+ {
+ id: mockUser.userID,
+ label: mockUser.name,
+ type: 'user',
+ icon: mockUser.avatar,
+ },
+ {
+ id: '2',
+ label: 'User2',
+ type: 'user',
+ icon: mockUser.avatar,
+ },
+ ];
+ },
+ }],
+});
+```
diff --git a/packages/sheets-thread-comment/README.md b/packages/sheets-thread-comment/README.md
index c081d14672..423aab038b 100644
--- a/packages/sheets-thread-comment/README.md
+++ b/packages/sheets-thread-comment/README.md
@@ -1,20 +1,57 @@
# @univerjs/sheets-thread-comment
-[![npm version](https://img.shields.io/npm/v/@univerjs/sheets-thread-comment)](https://npmjs.org/packages/@univerjs/sheets-thread-comment)
-[![license](https://img.shields.io/npm/l/@univerjs/sheets-thread-comment)](https://img.shields.io/npm/l/@univerjs/sheets-thread-comment)
+[![npm version](https://img.shields.io/npm/v/@univerjs/sheets-thread-comment)](https://npmjs.org/packages/@univerjs/sheets-thread-comment )
+[![license](https://img.shields.io/npm/l/@univerjs/sheets-thread-comment)](https://img.shields.io/npm/l/@univerjs/sheets- thread-comment)
## Introduction
-> TODO: Introduction
+`@univerjs/sheets-thread-comment` provides the comment/annotation function of Univer Sheets.
+
## Usage
-### Installation
+### Install
```shell
-# Using npm
+# Use npm
npm install @univerjs/sheets-thread-comment
-# Using pnpm
+# Use pnpm
pnpm add @univerjs/sheets-thread-comment
```
+
+### use
+```js
+import { UniverSheetsThreadCommentPlugin } from '@univerjs/sheets-thread-comment';
+
+const mockUser = {
+ userID: 'mockId',
+ name: 'MockUser',
+ avatar: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAInSURBVHgBtZU9TxtBEIbfWRzFSIdkikhBSqRQk JqkCKTCFkqVInSUSaT0wC8w/gXxD4gU2nRJkXQWhAZowDUUWKIwEgWWbEEB3mVmx3dn4DA2nB/ppNuPeWd29mMIPXDr+RxwtgRHeW6+guNPRxogqnL7Dwz9psJ27S4NShaeZTH3kwXy6I81 dlRKcmRui88swdq9AcSFL7Buz1Vmlns64MiLsCjzwnIYHLH57tbfFbs7KRaXyEU8FVZofqccOfA5 l7Q8LPIkGrwnb2RPNEXWFVMUF3L+kDCk0btDDAMzOm5YfAHDwp4tG74wnzAsiOYMnJ3GoDybA7IT 98/jm5+JNnfiIzAS6LlqHQBN/i6b2t/cV1Hh6BfwYlHnHP4AXi5q/8kmMMpOs8+BixZw/Fd6xUE HEbnkgclvQP2fGp7uShRKnQ3G32rkjV1th8JhIGG7tR/JyjGteSOZELwGMmNqIIigRCLRh2OZIE 6BjItdd7pCW6Uhm1zzkUtungSxwEUzNpQ+GQumtH1ej1MqgmNT6vwmhCq5yuwq56EYTbgeQUz 3yvrpV1b4ok3nYJ+eYhgYmjRUqErx2EDq0Fr8FhG++iqVGqxlUJI/70Ar0UgJaWHj6hYVHJrf KssAHot1JfqwE9WVWzXZVd5z2Ws/4PnmtEjkXeKJDvxUecLbWOXH/ DP6QQ4J72NS0adedp1aseBfXP8odlZFfPvBF7SN/8hky1TYuPOAXAEipMx15u5ToAAAAABJRU5ErkJggg==',
+ anonymous: false,
+ canBindAnonymous: false,
+};
+
+univer.registerPlugin(UniverSheetsThreadCommentPlugin, {
+ mentions: [{
+ trigger: '@',
+ // Get the common interface implementation of the mentioned user
+ getMentions: async () => {
+ return [
+ {
+ id: mockUser.userID,
+ label: mockUser.name,
+ type: 'user',
+ icon: mockUser.avatar,
+ },
+ {
+ id: '2',
+ label: 'User2',
+ type: 'user',
+ icon: mockUser.avatar,
+ },
+ ];
+ },
+ }],
+});
+```
diff --git a/packages/sheets-thread-comment/package.json b/packages/sheets-thread-comment/package.json
index b2cb61c4e2..17f45ba332 100644
--- a/packages/sheets-thread-comment/package.json
+++ b/packages/sheets-thread-comment/package.json
@@ -2,7 +2,7 @@
"name": "@univerjs/sheets-thread-comment",
"version": "0.1.11",
"private": false,
- "description": "",
+ "description": "Univer thread comment plugin",
"author": "DreamNum <[email protected]>",
"license": "Apache-2.0",
"funding": {
diff --git a/packages/sheets-thread-comment/src/views/sheets-thread-comment-panel/index.tsx b/packages/sheets-thread-comment/src/views/sheets-thread-comment-panel/index.tsx
index c2f2278199..6bb0b5bcfd 100644
--- a/packages/sheets-thread-comment/src/views/sheets-thread-comment-panel/index.tsx
+++ b/packages/sheets-thread-comment/src/views/sheets-thread-comment-panel/index.tsx
@@ -16,17 +16,20 @@
import type { Workbook } from '@univerjs/core';
import { ICommandService, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
-import { ThreadCommentPanel } from '@univerjs/thread-comment-ui';
-import { useDependency } from '@wendellhu/redi/react-bindings';
-import React, { useCallback, useMemo } from 'react';
+import { ThreadCommentPanel, ThreadCommentPanelService } from '@univerjs/thread-comment-ui';
+import { useDependency, useObservable } from '@wendellhu/redi/react-bindings';
+import React, { useCallback, useEffect, useMemo, useRef } from 'react';
import { map } from 'rxjs';
-import type { IThreadComment } from '@univerjs/thread-comment';
+import { type IThreadComment, ThreadCommentModel } from '@univerjs/thread-comment';
import { singleReferenceToGrid } from '@univerjs/engine-formula';
+import { IMarkSelectionService } from '@univerjs/sheets-ui';
import { ShowAddSheetCommentModalOperation } from '../../commands/operations/comment.operation';
import { SheetsThreadCommentPopupService } from '../../services/sheets-thread-comment-popup.service';
export const SheetsThreadCommentPanel = () => {
+ const markSelectionService = useDependency(IMarkSelectionService);
const univerInstanceService = useDependency(IUniverInstanceService);
+ const threadCommentModel = useDependency(ThreadCommentModel);
const sheetsThreadCommentPopupService = useDependency(SheetsThreadCommentPopupService);
const workbook = univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET);
if (!workbook) {
@@ -35,7 +38,10 @@ export const SheetsThreadCommentPanel = () => {
const unitId = workbook.getUnitId();
const commandService = useDependency(ICommandService);
const subUnitId$ = useMemo(() => workbook.activeSheet$.pipe(map((i) => i?.getSheetId())), [workbook.activeSheet$]);
-
+ const subUnitId = useObservable(subUnitId$, workbook.getActiveSheet().getSheetId());
+ const activeShapeId = useRef<string | null>();
+ const panelService = useDependency(ThreadCommentPanelService);
+ const activeCommentId = useObservable(panelService.activeCommentId$);
const sortComments = useCallback((comments: IThreadComment[]) => {
const worksheets = workbook.getSheets();
const sheetIndex: Record<string, number> = {};
@@ -59,6 +65,30 @@ export const SheetsThreadCommentPanel = () => {
});
}, [workbook]);
+ const showShape = useCallback((comment: IThreadComment) => {
+ if (comment.unitId === unitId && comment.subUnitId === subUnitId && !comment.resolved) {
+ const { row, column } = singleReferenceToGrid(comment.ref);
+ if (!Number.isNaN(row) && !Number.isNaN(column)) {
+ return markSelectionService.addShape({
+ range: {
+ startColumn: column,
+ endColumn: column,
+ startRow: row,
+ endRow: row,
+ },
+ style: {
+ hasAutoFill: false,
+ fill: 'rgb(255, 189, 55, 0.35)',
+ strokeWidth: 1,
+ stroke: '#FFBD37',
+ widgets: {},
+ },
+ primary: null,
+ });
+ }
+ }
+ }, [markSelectionService, subUnitId, unitId]);
+
const getSubUnitName = (id: string) => {
return workbook.getSheetBySheetId(id)?.getName() ?? '';
};
@@ -71,6 +101,47 @@ export const SheetsThreadCommentPanel = () => {
sheetsThreadCommentPopupService.hidePopup();
};
+ const handleHover = (comment: IThreadComment) => {
+ if (
+ activeCommentId &&
+ activeCommentId.unitId === comment.unitId &&
+ activeCommentId.subUnitId === comment.subUnitId &&
+ activeCommentId.commentId === comment.id
+ ) {
+ return;
+ }
+
+ if (activeShapeId.current) {
+ markSelectionService.removeShape(activeShapeId.current);
+ activeShapeId.current = null;
+ }
+
+ activeShapeId.current = showShape(comment);
+ };
+
+ const handleLeave = () => {
+ if (activeShapeId.current) {
+ markSelectionService.removeShape(activeShapeId.current);
+ activeShapeId.current = null;
+ }
+ };
+
+ useEffect(() => {
+ if (!activeCommentId) {
+ return;
+ }
+ const comment = threadCommentModel.getComment(activeCommentId.unitId, activeCommentId.subUnitId, activeCommentId.commentId);
+ if (!comment) {
+ return;
+ }
+ const id = showShape(comment);
+ return () => {
+ if (id) {
+ markSelectionService.removeShape(id);
+ }
+ };
+ }, [showShape, activeCommentId, threadCommentModel, markSelectionService]);
+
return (
<ThreadCommentPanel
unitId={unitId}
@@ -80,6 +151,8 @@ export const SheetsThreadCommentPanel = () => {
getSubUnitName={getSubUnitName}
onResolve={handleResolve}
sortComments={sortComments}
+ onItemEnter={handleHover}
+ onItemLeave={handleLeave}
/>
);
};
diff --git a/packages/sheets/src/commands/mutations/set-worksheet-row-height.mutation.ts b/packages/sheets/src/commands/mutations/set-worksheet-row-height.mutation.ts
index e74ba5eb20..7cdfff4565 100644
--- a/packages/sheets/src/commands/mutations/set-worksheet-row-height.mutation.ts
+++ b/packages/sheets/src/commands/mutations/set-worksheet-row-height.mutation.ts
@@ -110,8 +110,16 @@ export const SetWorksheetRowAutoHeightMutationFactory = (
const workbook = univerInstanceService.getUniverSheetInstance(unitId);
const worksheet = workbook?.getSheetBySheetId(subUnitId);
+ if (!worksheet) {
+ return {
+ unitId,
+ subUnitId,
+ rowsAutoHeightInfo: [],
+ };
+ }
+
const results: IRowAutoHeightInfo[] = [];
- const manager = worksheet!.getRowManager();
+ const manager = worksheet.getRowManager();
for (const rowInfo of rowsAutoHeightInfo) {
const { row } = rowInfo;
diff --git a/packages/thread-comment-ui/README-zh.md b/packages/thread-comment-ui/README-zh.md
index 9eff440b70..5bcd5c3233 100644
--- a/packages/thread-comment-ui/README-zh.md
+++ b/packages/thread-comment-ui/README-zh.md
@@ -7,7 +7,7 @@
## 简介
-> TODO: Introduction
+> `@univerjs/thread-comment-ui` 评论/批注 通用UI包,如需使用请查看 [@univerjs/sheets-thread-comment](../sheets-thread-comment/README-zh.md)
## 使用指南
diff --git a/packages/thread-comment-ui/README.md b/packages/thread-comment-ui/README.md
index 988b5019c2..f7bd59f5ce 100644
--- a/packages/thread-comment-ui/README.md
+++ b/packages/thread-comment-ui/README.md
@@ -7,7 +7,7 @@
## Introduction
-> TODO: Introduction
+> `@univerjs/thread-comment` common UI package for comment. For using, please refer to [@univerjs/sheets-thread-comment](../sheets-thread-comment/README.md)
## Usage
diff --git a/packages/thread-comment-ui/package.json b/packages/thread-comment-ui/package.json
index 7f5f3e2090..84971e7100 100644
--- a/packages/thread-comment-ui/package.json
+++ b/packages/thread-comment-ui/package.json
@@ -2,7 +2,7 @@
"name": "@univerjs/thread-comment-ui",
"version": "0.1.11",
"private": false,
- "description": "",
+ "description": "Univer common thread comment UI plugin",
"author": "DreamNum <[email protected]>",
"license": "Apache-2.0",
"funding": {
diff --git a/packages/thread-comment-ui/src/locale/en-US.ts b/packages/thread-comment-ui/src/locale/en-US.ts
index 9016a2affc..ebf1ccb28f 100644
--- a/packages/thread-comment-ui/src/locale/en-US.ts
+++ b/packages/thread-comment-ui/src/locale/en-US.ts
@@ -14,7 +14,9 @@
* limitations under the License.
*/
-export default {
+import type zhCN from './zh-CN';
+
+const enUS: typeof zhCN = {
threadCommentUI: {
panel: {
title: 'Comment Management',
@@ -47,3 +49,5 @@ export default {
},
},
};
+
+export default enUS;
diff --git a/packages/thread-comment-ui/src/views/thread-comment-panel/index.tsx b/packages/thread-comment-ui/src/views/thread-comment-panel/index.tsx
index 7692397ae5..9282849aec 100644
--- a/packages/thread-comment-ui/src/views/thread-comment-panel/index.tsx
+++ b/packages/thread-comment-ui/src/views/thread-comment-panel/index.tsx
@@ -36,10 +36,12 @@ export interface IThreadCommentPanelProps {
getSubUnitName: (subUnitId: string) => string;
onResolve?: (id: string) => void;
sortComments?: (comments: IThreadComment[]) => IThreadComment[];
+ onItemLeave?: (comment: IThreadComment) => void;
+ onItemEnter?: (comment: IThreadComment) => void;
}
export const ThreadCommentPanel = (props: IThreadCommentPanelProps) => {
- const { unitId, subUnitId$, type, onAdd, getSubUnitName, onResolve, sortComments } = props;
+ const { unitId, subUnitId$, type, onAdd, getSubUnitName, onResolve, sortComments, onItemLeave, onItemEnter } = props;
const [unit, setUnit] = useState('all');
const [status, setStatus] = useState('all');
const localeService = useDependency(LocaleService);
@@ -176,6 +178,8 @@ export const ThreadCommentPanel = (props: IThreadCommentPanelProps) => {
});
}}
onClose={() => onResolve?.(comment.id)}
+ onMouseEnter={() => onItemEnter?.(comment)}
+ onMouseLeave={() => onItemLeave?.(comment)}
/>
))}
{statuedComments.length
diff --git a/packages/thread-comment-ui/src/views/thread-comment-tree/index.module.less b/packages/thread-comment-ui/src/views/thread-comment-tree/index.module.less
index 12b73881a0..53bc5a571d 100644
--- a/packages/thread-comment-ui/src/views/thread-comment-tree/index.module.less
+++ b/packages/thread-comment-ui/src/views/thread-comment-tree/index.module.less
@@ -6,6 +6,9 @@
border-radius: 8px;
box-sizing: border-box;
position: relative;
+}
+
+.thread-comment-active {
box-shadow: var(--box-shadow-base);
}
@@ -43,6 +46,7 @@
justify-content: center;
align-items: center;
cursor: pointer;
+ font-size: 16px;
}
.thread-comment-icon:hover {
@@ -55,6 +59,22 @@
align-items: center;
justify-content: space-between;
margin-bottom: 16px;
+ font-size: 14px;
+ line-height: 20px;
+}
+
+.thread-comment-title-position {
+ display: flex;
+ flex-direction: row;
+ align-items: center;
+}
+
+.thread-comment-title-highlight {
+ width: 3px;
+ height: 14px;
+ border-radius: 1.5px;
+ background-color: rgba(var(--gold-400));
+ margin-right: 8px;
}
.thread-comment-username {
diff --git a/packages/thread-comment-ui/src/views/thread-comment-tree/index.tsx b/packages/thread-comment-ui/src/views/thread-comment-tree/index.tsx
index 2ebfae67a9..47813d1d97 100644
--- a/packages/thread-comment-ui/src/views/thread-comment-tree/index.tsx
+++ b/packages/thread-comment-ui/src/views/thread-comment-tree/index.tsx
@@ -24,6 +24,7 @@ import { useObservable } from '@univerjs/ui';
import dayjs from 'dayjs';
import { Dropdown, Menu, MenuItem } from '@univerjs/design';
import type { IUser } from '@univerjs/protocol';
+import cs from 'clsx';
import type { IThreadCommentEditorInstance } from '../thread-comment-editor';
import { ThreadCommentEditor } from '../thread-comment-editor';
import { transformDocument2TextNodes, transformTextNodes2Document } from '../thread-comment-editor/util';
@@ -42,6 +43,8 @@ export interface IThreadCommentTreeProps {
getSubUnitName: (subUnitId: string) => string;
prefix?: string;
autoFocus?: boolean;
+ onMouseEnter?: () => void;
+ onMouseLeave?: () => void;
}
export interface IThreadCommentItemProps {
@@ -180,9 +183,11 @@ export const ThreadCommentTree = (props: IThreadCommentTreeProps) => {
getSubUnitName,
prefix,
autoFocus,
+ onMouseEnter,
+ onMouseLeave,
} = props;
const threadCommentModel = useDependency(ThreadCommentModel);
-
+ const [isHover, setIsHover] = useState(false);
const [editingId, setEditingId] = useState('');
useObservable(threadCommentModel.commentMap$);
const comments = id ? threadCommentModel.getCommentWithChildren(unitId, subUnitId, id) : null;
@@ -231,8 +236,22 @@ export const ThreadCommentTree = (props: IThreadCommentTreeProps) => {
};
return (
- <div className={styles.threadComment} onClick={onClick} id={`${prefix}-${unitId}-${subUnitId}-${id}`}>
- {showHighlight ? <div className={styles.threadCommentHighlight} /> : null}
+ <div
+ className={cs(styles.threadComment, {
+ [styles.threadCommentActive]: !resolved && (showHighlight || isHover || prefix === 'cell'),
+ })}
+ onClick={onClick}
+ id={`${prefix}-${unitId}-${subUnitId}-${id}`}
+ onMouseEnter={() => {
+ onMouseEnter?.();
+ setIsHover(true);
+ }}
+ onMouseLeave={() => {
+ onMouseLeave?.();
+ setIsHover(false);
+ }}
+ >
+ {!resolved && showHighlight ? <div className={styles.threadCommentHighlight} /> : null}
<div className={styles.threadCommentTitle}>
<div className={styles.threadCommentTitlePosition}>
<div className={styles.threadCommentTitleHighlight} />
diff --git a/packages/thread-comment/README-zh.md b/packages/thread-comment/README-zh.md
index b3cbabd64b..b24e68266d 100644
--- a/packages/thread-comment/README-zh.md
+++ b/packages/thread-comment/README-zh.md
@@ -5,7 +5,7 @@
## 简介
-> TODO: Introduction
+> `@univerjs/thread-comment` 评论/批注 核心包,如需使用请查看 [@univerjs/sheets-thread-comment](../sheets-thread-comment/README-zh.md)
## 使用指南
diff --git a/packages/thread-comment/README.md b/packages/thread-comment/README.md
index c7f3c4c1ad..028fb5b0ae 100644
--- a/packages/thread-comment/README.md
+++ b/packages/thread-comment/README.md
@@ -5,7 +5,7 @@
## Introduction
-> TODO: Introduction
+> `@univerjs/thread-comment` core package for comment. For using, please refer to [@univerjs/sheets-thread-comment](../sheets-thread-comment/README.md)
## Usage
diff --git a/packages/thread-comment/package.json b/packages/thread-comment/package.json
index 7d060b760a..b761c36e88 100644
--- a/packages/thread-comment/package.json
+++ b/packages/thread-comment/package.json
@@ -2,7 +2,7 @@
"name": "@univerjs/thread-comment",
"version": "0.1.11",
"private": false,
- "description": "",
+ "description": "Univer thread comment core plugin",
"author": "DreamNum <[email protected]>",
"license": "Apache-2.0",
"funding": {