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.

feat(facade): add facade api for sheets-thread-comment & float-dom & optmize data-validation facade api (#3200)

zhangw5aa3342980b8
diff --git a/packages/data-validation/src/index.ts b/packages/data-validation/src/index.ts
index 93889158e3..729c1e793e 100644
--- a/packages/data-validation/src/index.ts
+++ b/packages/data-validation/src/index.ts
@@ -16,7 +16,7 @@
export { UniverDataValidationPlugin } from './plugin';
export { DataValidatorRegistryService, DataValidatorRegistryScope } from './services/data-validator-registry.service';
-export { DataValidationModel, type DataValidationChangeSource } from './models/data-validation-model';
+export { DataValidationModel, type DataValidationChangeSource, type IRuleChange, type IValidStatusChange } from './models/data-validation-model';
export {
createDefaultNewRule,
@@ -63,3 +63,4 @@ export {
} from './commands/mutations/data-validation.mutation';
// #endregion
+
diff --git a/packages/facade/package.json b/packages/facade/package.json
index fed6ffa44e..dac12bd20c 100644
--- a/packages/facade/package.json
+++ b/packages/facade/package.json
@@ -68,11 +68,15 @@
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-crosshair-highlight": "workspace:*",
"@univerjs/sheets-data-validation": "workspace:*",
+ "@univerjs/sheets-drawing-ui": "workspace:*",
"@univerjs/sheets-filter": "workspace:*",
"@univerjs/sheets-filter-ui": "workspace:*",
"@univerjs/sheets-formula": "workspace:*",
"@univerjs/sheets-numfmt": "workspace:*",
+ "@univerjs/sheets-thread-comment": "workspace:*",
"@univerjs/sheets-ui": "workspace:*",
+ "@univerjs/thread-comment": "workspace:*",
+ "@univerjs/thread-comment-ui": "workspace:*",
"rxjs": ">=7.0.0"
},
"devDependencies": {
@@ -88,11 +92,15 @@
"@univerjs/sheets-conditional-formatting": "workspace:*",
"@univerjs/sheets-crosshair-highlight": "workspace:*",
"@univerjs/sheets-data-validation": "workspace:*",
+ "@univerjs/sheets-drawing-ui": "workspace:*",
"@univerjs/sheets-filter": "workspace:*",
"@univerjs/sheets-filter-ui": "workspace:*",
"@univerjs/sheets-formula": "workspace:*",
"@univerjs/sheets-numfmt": "workspace:*",
+ "@univerjs/sheets-thread-comment": "workspace:*",
"@univerjs/sheets-ui": "workspace:*",
+ "@univerjs/thread-comment": "workspace:*",
+ "@univerjs/thread-comment-ui": "workspace:*",
"@univerjs/ui": "workspace:*",
"jest-canvas-mock": "^2.5.2",
"jsdom": "^24.1.1",
diff --git a/packages/facade/src/apis/__tests__/create-test-bed.ts b/packages/facade/src/apis/__tests__/create-test-bed.ts
index aafc990014..dd08bc0032 100644
--- a/packages/facade/src/apis/__tests__/create-test-bed.ts
+++ b/packages/facade/src/apis/__tests__/create-test-bed.ts
@@ -59,6 +59,8 @@ import { ConditionalFormattingFormulaService, ConditionalFormattingRuleModel, Co
import { UniverDataValidationPlugin } from '@univerjs/data-validation';
import { DataValidationCacheService, DataValidationCustomFormulaService, DataValidationFormulaService, DataValidationModel, SheetDataValidationManager, SheetsDataValidationValidatorService } from '@univerjs/sheets-data-validation';
import { UniverSheetsFilterPlugin } from '@univerjs/sheets-filter';
+import { SheetsThreadCommentModel } from '@univerjs/sheets-thread-comment';
+import { IThreadCommentDataSourceService, ThreadCommentDataSourceService, ThreadCommentModel } from '@univerjs/thread-comment';
import { FUniver } from '../facade';
function getTestWorkbookDataDemo(): IWorkbookData {
@@ -184,6 +186,10 @@ export function createFacadeTestBed(workbookData?: IWorkbookData, dependencies?:
[SheetsDataValidationValidatorService],
// sheets filter
+ // comment
+ [SheetsThreadCommentModel],
+ [ThreadCommentModel],
+ [IThreadCommentDataSourceService, { useClass: ThreadCommentDataSourceService }],
] as Dependency[]).forEach((d) => {
injector.add(d);
});
diff --git a/packages/facade/src/apis/__tests__/facade.spec.ts b/packages/facade/src/apis/__tests__/facade.spec.ts
index 90d2d2d616..b5156caabf 100644
--- a/packages/facade/src/apis/__tests__/facade.spec.ts
+++ b/packages/facade/src/apis/__tests__/facade.spec.ts
@@ -31,6 +31,7 @@ import { IRenderManagerService } from '@univerjs/engine-render';
import { SHEET_VIEW_KEY } from '@univerjs/sheets-ui';
import { RegisterFunctionMutation, SetFormulaCalculationStartMutation } from '@univerjs/engine-formula';
import { IDescriptionService } from '@univerjs/sheets-formula';
+import { AddCommentCommand, AddCommentMutation, DeleteCommentCommand, DeleteCommentMutation, DeleteCommentTreeCommand, ResolveCommentMutation, UpdateCommentCommand, UpdateCommentMutation, UpdateCommentRefMutation } from '@univerjs/thread-comment';
import type { FUniver } from '../facade';
import { createFacadeTestBed } from './create-test-bed';
import { COLUMN_UNIQUE_KEY, ColumnHeaderCustomExtension, MAIN_UNIQUE_KEY, MainCustomExtension, ROW_UNIQUE_KEY, RowHeaderCustomExtension } from './utils/sheet-extension-util';
@@ -65,6 +66,17 @@ describe('Test FUniver', () => {
commandService.registerCommand(RegisterFunctionMutation);
commandService.registerCommand(SetStyleCommand);
commandService.registerCommand(SetFormulaCalculationStartMutation);
+ [
+ DeleteCommentCommand,
+ DeleteCommentTreeCommand,
+ UpdateCommentCommand,
+ AddCommentCommand,
+ AddCommentMutation,
+ DeleteCommentMutation,
+ ResolveCommentMutation,
+ UpdateCommentMutation,
+ UpdateCommentRefMutation,
+ ].forEach((command) => commandService.registerCommand(command));
getValueByPosition = (
startRow: number,
@@ -336,4 +348,40 @@ describe('Test FUniver', () => {
vi.advanceTimersByTime(16); // mock time pass by
expect(spy).toHaveBeenCalled();
});
+
+ it('Add Comment', async () => {
+ const worksheet = univerAPI.getActiveWorkbook()?.getActiveSheet();
+ if (!worksheet) {
+ return;
+ }
+
+ const range = worksheet.getRange(1, 1, 1, 1);
+ await range.addComment({
+ dataStream: 'test\r\n',
+ });
+
+ const comment = range.getComment()!;
+ expect(comment).toBeTruthy();
+ expect(comment.getContent().dataStream).toBe('test\r\n');
+ expect(worksheet.getComments().length).toBe(1);
+
+ await range.addComment({
+ dataStream: 'reply\r\n',
+ });
+ const newComment = range.getComment()!;
+ expect(newComment).toBeTruthy();
+ expect(newComment.getContent().dataStream).toBe('test\r\n');
+ expect(newComment.getReplies()?.length).toBe(1);
+
+ await newComment.update({
+ dataStream: 'test updated\r\n',
+ });
+ // expect(worksheet.getComments()).toBe([]);
+ expect(newComment.getContent().dataStream).toBe('test updated\r\n');
+ expect(range.getComment()?.getContent().dataStream).toBe('test updated\r\n');
+
+ await newComment.delete();
+ expect(worksheet.getComments().length).toBe(0);
+ expect(range.getComment()).toBeNull();
+ });
});
diff --git a/packages/facade/src/apis/sheets/f-data-validation.ts b/packages/facade/src/apis/sheets/f-data-validation.ts
index 47ecf1613d..e95baa8496 100644
--- a/packages/facade/src/apis/sheets/f-data-validation.ts
+++ b/packages/facade/src/apis/sheets/f-data-validation.ts
@@ -14,15 +14,23 @@
* limitations under the License.
*/
-import type { DataValidationType, IDataValidationRule } from '@univerjs/core';
-import { DataValidationErrorStyle } from '@univerjs/core';
+import type { DataValidationOperator, DataValidationType, IDataValidationRule, IDataValidationRuleOptions, IRange } from '@univerjs/core';
+import { DataValidationErrorStyle, ICommandService } from '@univerjs/core';
+import { DataValidationModel, getRuleOptions } from '@univerjs/data-validation';
+import type { IRemoveSheetDataValidationCommandParams, IUpdateSheetDataValidationOptionsCommandParams, IUpdateSheetDataValidationRangeCommandParams, IUpdateSheetDataValidationSettingCommandParams } from '@univerjs/sheets-data-validation';
+import { RemoveSheetDataValidationCommand, UpdateSheetDataValidationOptionsCommand, UpdateSheetDataValidationRangeCommand, UpdateSheetDataValidationSettingCommand } from '@univerjs/sheets-data-validation';
import { FDataValidationBuilder } from './f-data-validation-builder';
+import type { FWorksheet } from './f-worksheet';
+import { FRange } from './f-range';
export class FDataValidation {
rule: IDataValidationRule;
- constructor(rule: IDataValidationRule) {
+ private _worksheet: FWorksheet | undefined;
+
+ constructor(rule: IDataValidationRule, worksheet?: FWorksheet) {
this.rule = rule;
+ this._worksheet = worksheet;
}
/**
@@ -70,4 +78,166 @@ export class FDataValidation {
copy(): FDataValidationBuilder {
return new FDataValidationBuilder(this.rule);
}
+
+ /**
+ * Gets whether the data validation rule is applied to the worksheet.
+ *
+ * @returns true if the rule is applied, false otherwise.
+ */
+ getApplied(): boolean {
+ if (!this._worksheet) {
+ return false;
+ }
+
+ const dataValidationModel = this._worksheet.getInject().get(DataValidationModel);
+ const currentRule = dataValidationModel.getRuleById(this._worksheet.getWorkbook().getUnitId(), this._worksheet.getSheetId(), this.rule.uid);
+
+ if (currentRule && currentRule.ranges.length) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Gets the ranges to which the data validation rule is applied.
+ *
+ * @returns An array of IRange objects representing the ranges to which the data validation rule is applied.
+ */
+ getRanges(): FRange[] {
+ if (!this.getAllowInvalid()) {
+ return [];
+ }
+
+ const workbook = this._worksheet?.getWorkbook();
+ const sheetId = this.getSheetId();
+ if (!sheetId) {
+ return [];
+ }
+ const worksheet = workbook?.getSheetBySheetId(sheetId);
+ if (!workbook || !worksheet) {
+ return [];
+ }
+
+ return this.rule.ranges.map((range: IRange) => this._worksheet?.getInject().createInstance(FRange, workbook, worksheet, range));
+ }
+
+ /**
+ * Gets the title of the error message dialog box.
+ *
+ * @returns The title of the error message dialog box.
+ */
+ getUnitId(): string | undefined {
+ return this._worksheet?.getWorkbook().getUnitId();
+ }
+
+ /**
+ * Gets the sheetId of the worksheet.
+ *
+ * @returns The sheetId of the worksheet.
+ */
+ getSheetId(): string | undefined {
+ return this._worksheet?.getSheetId();
+ }
+
+ /**
+ * Set Criteria for the data validation rule.
+ * @param type The type of data validation criteria.
+ * @param values An array containing the operator, formula1, and formula2 values.
+ * @returns true if the criteria is set successfully, false otherwise.
+ */
+ setCriteria(type: DataValidationType, values: [DataValidationOperator, string, string]): boolean {
+ if (this.getApplied()) {
+ const commandService = this._worksheet!.getInject().get(ICommandService);
+ const res = commandService.syncExecuteCommand(UpdateSheetDataValidationSettingCommand.id, {
+ unitId: this.getUnitId(),
+ subUnitId: this.getSheetId(),
+ ruleId: this.rule.uid,
+ setting: {
+ operator: values[0],
+ formula1: values[1],
+ formula2: values[2],
+ type: this.rule.type,
+ },
+ } as IUpdateSheetDataValidationSettingCommandParams);
+
+ if (!res) {
+ return false;
+ }
+ }
+
+ this.rule.operator = values[0];
+ this.rule.formula1 = values[1];
+ this.rule.formula2 = values[2];
+ this.rule.type = type;
+
+ return true;
+ }
+
+ /**
+ * Set the options for the data validation rule.
+ * @param options An object containing the options to set. `IDataValidationRuleOptions`
+ * @returns true if the options are set successfully, false otherwise.
+ */
+ setOptions(options: Partial<IDataValidationRuleOptions>): boolean {
+ if (this.getApplied()) {
+ const commandService = this._worksheet!.getInject().get(ICommandService);
+ const res = commandService.syncExecuteCommand(UpdateSheetDataValidationOptionsCommand.id, {
+ unitId: this.getUnitId(),
+ subUnitId: this.getSheetId(),
+ ruleId: this.rule.uid,
+ options: {
+ ...getRuleOptions(this.rule),
+ ...options,
+ },
+ } as IUpdateSheetDataValidationOptionsCommandParams);
+
+ if (!res) {
+ return false;
+ }
+ }
+
+ Object.assign(this.rule, options);
+ return true;
+ }
+
+ /**
+ * Set the ranges to the data validation rule.
+ * @param ranges new ranges array.
+ * @returns true if the ranges are set successfully, false otherwise.
+ */
+ setRanges(ranges: FRange[]): boolean {
+ if (this.getApplied()) {
+ const commandService = this._worksheet!.getInject().get(ICommandService);
+ const res = commandService.syncExecuteCommand(UpdateSheetDataValidationRangeCommand.id, {
+ unitId: this.getUnitId(),
+ subUnitId: this.getSheetId(),
+ ruleId: this.rule.uid,
+ ranges: ranges.map((range) => range.getRange()),
+ } as IUpdateSheetDataValidationRangeCommandParams);
+
+ if (!res) {
+ return false;
+ }
+ }
+
+ this.rule.ranges = ranges;
+ return true;
+ }
+
+ /**
+ * Delete the data validation rule from the worksheet.
+ * @returns true if the rule is deleted successfully, false otherwise.
+ */
+ delete(): boolean {
+ if (!this.getApplied()) {
+ return false;
+ }
+
+ const commandService = this._worksheet!.getInject().get(ICommandService);
+ return commandService.syncExecuteCommand(RemoveSheetDataValidationCommand.id, {
+ unitId: this.getUnitId(),
+ subUnitId: this.getSheetId(),
+ ruleId: this.rule.uid,
+ } as IRemoveSheetDataValidationCommandParams);
+ }
}
diff --git a/packages/facade/src/apis/sheets/f-range.ts b/packages/facade/src/apis/sheets/f-range.ts
index d5c79067fd..a1804acd2e 100644
--- a/packages/facade/src/apis/sheets/f-range.ts
+++ b/packages/facade/src/apis/sheets/f-range.ts
@@ -19,6 +19,8 @@ import type {
DataValidationStatus,
ICellData,
IColorStyle,
+ IDisposable,
+ IDocumentBody,
IObjectMatrixPrimitiveType,
IRange,
ISelectionCellWithMergeInfo,
@@ -28,7 +30,7 @@ import type {
Workbook,
Worksheet,
} from '@univerjs/core';
-import { BooleanNumber, ICommandService, Inject, Injector, WrapStrategy } from '@univerjs/core';
+import { BooleanNumber, ICommandService, Inject, Injector, Tools, UserManagerService, WrapStrategy } from '@univerjs/core';
import type {
ISetHorizontalTextAlignCommandParams,
ISetStyleCommandParams,
@@ -45,9 +47,9 @@ import {
} from '@univerjs/sheets';
import type { ISetNumfmtCommandParams } from '@univerjs/sheets-numfmt';
import { SetNumfmtCommand } from '@univerjs/sheets-numfmt';
-
import { FormulaDataModel } from '@univerjs/engine-formula';
-import { ISheetClipboardService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
+import type { ICanvasPopup } from '@univerjs/sheets-ui';
+import { ISheetClipboardService, SheetCanvasPopManagerService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
import { IRenderManagerService } from '@univerjs/engine-render';
import type { IAddSheetDataValidationCommandParams, IClearRangeDataValidationCommandParams } from '@univerjs/sheets-data-validation';
import { AddSheetDataValidationCommand, ClearRangeDataValidationCommand, SheetsDataValidationValidatorService } from '@univerjs/sheets-data-validation';
@@ -55,11 +57,15 @@ import type { FilterModel } from '@univerjs/sheets-filter';
import { SheetsFilterService } from '@univerjs/sheets-filter';
import type { ISetSheetFilterRangeCommandParams } from '@univerjs/sheets-filter-ui';
import { SetSheetFilterRangeCommand } from '@univerjs/sheets-filter-ui';
-import type { FHorizontalAlignment, FVerticalAlignment } from './utils';
+import { ComponentManager } from '@univerjs/ui';
+import { AddCommentCommand, DeleteCommentTreeCommand, SheetsThreadCommentModel } from '@univerjs/sheets-thread-comment';
+import { getDT } from '@univerjs/thread-comment-ui';
+import type { FHorizontalAlignment, FVerticalAlignment, IFComponentKey } from './utils';
import {
covertCellValue,
covertCellValues,
isCellMerged,
+ transformComponentKey,
transformCoreHorizontalAlignment,
transformCoreVerticalAlignment,
transformFacadeHorizontalAlignment,
@@ -67,11 +73,16 @@ import {
} from './utils';
import { FDataValidation } from './f-data-validation';
import { FFilter } from './f-filter';
+import { FThreadComment } from './f-thread-comment';
export type FontLine = 'none' | 'underline' | 'line-through';
export type FontStyle = 'normal' | 'italic';
export type FontWeight = 'normal' | 'bold';
+export interface IFCanvasPopup extends Omit<ICanvasPopup, 'componentKey'>, IFComponentKey {
+
+}
+
export class FRange {
constructor(
private readonly _workbook: Workbook,
@@ -714,4 +725,108 @@ export class FRange {
}
// #endregion
+
+ /**
+ * Attach a popup to the start cell of current range.
+ * If current worksheet is not active, the popup will not be shown.
+ * Be careful to manager the detach disposable object, if not dispose correctly, it might memory leaks.
+ * @param popup The popup to attach
+ * @returns The disposable object to detach the popup, if the popup is not attached, return `null`.
+ */
+ attachPopup(popup: IFCanvasPopup): Nullable<IDisposable> {
+ const { key, disposableCollection } = transformComponentKey(popup, this._injector.get(ComponentManager));
+ const sheetsPopupService = this._injector.get(SheetCanvasPopManagerService);
+ const disposePopup = sheetsPopupService.attachPopupToCell(
+ this._range.startRow,
+ this._range.startColumn,
+ { ...popup, componentKey: key },
+ this.getUnitId(),
+ this._worksheet.getSheetId()
+ );
+ if (disposePopup) {
+ disposableCollection.add(disposePopup);
+ return disposableCollection;
+ }
+
+ disposableCollection.dispose();
+ return null;
+ }
+
+ /**
+ * Get the comment of the start cell in the current range.
+ * @returns The comment of the start cell in the current range. If the cell does not have a comment, return `null`.
+ */
+ getComment(): Nullable<FThreadComment> {
+ const injector = this._injector;
+ const sheetsTheadCommentModel = injector.get(SheetsThreadCommentModel);
+ const unitId = this._workbook.getUnitId();
+ const sheetId = this._worksheet.getSheetId();
+ const commentId = sheetsTheadCommentModel.getByLocation(unitId, sheetId, this._range.startRow, this._range.startColumn);
+ if (!commentId) {
+ return null;
+ }
+
+ const comment = sheetsTheadCommentModel.getComment(unitId, sheetId, commentId);
+ if (comment) {
+ return this._injector.createInstance(FThreadComment, comment);
+ }
+
+ return null;
+ }
+
+ /**
+ * Add a comment to the start cell in the current range.
+ * @param content The content of the comment.
+ * @returns Whether the comment is added successfully.
+ */
+ addComment(content: IDocumentBody): Promise<boolean> {
+ const injector = this._injector;
+ const currentComment = this.getComment()?.getCommentData();
+ const commentService = injector.get(ICommandService);
+ const userService = injector.get(UserManagerService);
+ const unitId = this._workbook.getUnitId();
+ const sheetId = this._worksheet.getSheetId();
+ const refStr = `${Tools.chatAtABC(this._range.startColumn)}${this._range.startRow + 1}`;
+ const currentUser = userService.getCurrentUser();
+
+ return commentService.executeCommand(AddCommentCommand.id, {
+ unitId,
+ subUnitId: sheetId,
+ comment: {
+ text: content,
+ attachments: [],
+ dT: getDT(),
+ id: Tools.generateRandomId(),
+ ref: refStr!,
+ personId: currentUser.userID,
+ parentId: currentComment?.id,
+ unitId,
+ subUnitId: sheetId,
+ threadId: currentComment?.threadId,
+ },
+ });
+ }
+
+ /**
+ * Clear the comment of the start cell in the current range.
+ * @returns Whether the comment is cleared successfully.
+ */
+ clearComment(): Promise<boolean> {
+ const injector = this._injector;
+ const currentComment = this.getComment()?.getCommentData();
+ const commentService = injector.get(ICommandService);
+ const unitId = this._workbook.getUnitId();
+ const sheetId = this._worksheet.getSheetId();
+
+ if (currentComment) {
+ return commentService.executeCommand(DeleteCommentTreeCommand.id, {
+ unitId,
+ subUnitId: sheetId,
+ threadId: currentComment.threadId,
+ commentId: currentComment.id,
+ });
+ }
+
+ return Promise.resolve(true);
+ }
}
diff --git a/packages/facade/src/apis/sheets/f-sheet-hooks.ts b/packages/facade/src/apis/sheets/f-sheet-hooks.ts
index 5b462f97ef..0d8f127fce 100644
--- a/packages/facade/src/apis/sheets/f-sheet-hooks.ts
+++ b/packages/facade/src/apis/sheets/f-sheet-hooks.ts
@@ -15,7 +15,7 @@
*/
import type { IDisposable, Nullable } from '@univerjs/core';
-import { Inject, toDisposable } from '@univerjs/core';
+import { ICommandService, Inject, Injector, toDisposable } from '@univerjs/core';
import type { IDragCellPosition, IHoverCellPosition } from '@univerjs/sheets-ui';
import { DragManagerService, HoverManagerService } from '@univerjs/sheets-ui';
@@ -23,7 +23,9 @@ import { DragManagerService, HoverManagerService } from '@univerjs/sheets-ui';
export class FSheetHooks {
constructor(
@Inject(HoverManagerService) private readonly _hoverManagerService: HoverManagerService,
- @Inject(DragManagerService) private readonly _dragManagerService: DragManagerService
+ @Inject(DragManagerService) private readonly _dragManagerService: DragManagerService,
+ @Inject(ICommandService) private readonly _commandService: ICommandService,
+ @Inject(Injector) private readonly _injector: Injector
) {
// empty
}
diff --git a/packages/facade/src/apis/sheets/f-thread-comment.ts b/packages/facade/src/apis/sheets/f-thread-comment.ts
new file mode 100644
index 0000000000..5eb687044c
--- /dev/null
+++ b/packages/facade/src/apis/sheets/f-thread-comment.ts
@@ -0,0 +1,152 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { IDocumentBody, IRange, Workbook } from '@univerjs/core';
+import { ICommandService, Inject, Injector, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
+import type { IBaseComment, IDeleteCommentCommandParams, IResolveCommentCommandParams, IThreadComment, IUpdateCommentCommandParams } from '@univerjs/thread-comment';
+import { DeleteCommentCommand, DeleteCommentTreeCommand, ResolveCommentCommand, UpdateCommentCommand } from '@univerjs/thread-comment';
+import { getDT } from '@univerjs/thread-comment-ui';
+import { deserializeRangeWithSheet } from '@univerjs/engine-formula';
+import { SheetsThreadCommentModel } from '@univerjs/sheets-thread-comment';
+import { FRange } from './f-range';
+
+export class FThreadComment {
+ constructor(
+ private readonly _thread: IThreadComment | IBaseComment,
+ private readonly _parent: IThreadComment | undefined,
+ @Inject(Injector) private readonly _injector: Injector,
+ @ICommandService private readonly _commandService: ICommandService,
+ @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
+ @Inject(SheetsThreadCommentModel) private readonly _threadCommentModel: SheetsThreadCommentModel
+ ) {
+ }
+
+ private _getRef(): IRange {
+ const ref = this._parent?.ref || (this._thread as IThreadComment).ref;
+ const range = deserializeRangeWithSheet(ref);
+
+ return range.range;
+ }
+
+ /**
+ * Whether the comment is a root comment
+ * @returns Whether the comment is a root comment
+ */
+ getIsRoot(): boolean {
+ return !this._parent;
+ }
+
+ /**
+ * Get the comment data
+ * @returns The comment data
+ */
+ getCommentData(): IBaseComment {
+ const { children, ...comment } = this._thread;
+ return comment;
+ }
+
+ /**
+ * Get the replies of the comment
+ * @returns the replies of the comment
+ */
+ getReplies(): FThreadComment[] | undefined {
+ const range = this._getRef();
+ const comments = this._threadCommentModel.getCommentWithChildren(this._thread.unitId, this._thread.subUnitId, range.startRow, range.startColumn);
+
+ return comments?.children?.map((child) => this._injector.createInstance(FThreadComment, child));
+ }
+
+ /**
+ * Get the range of the comment
+ * @returns The range of the comment
+ */
+ getRange(): FRange | null {
+ const workbook = this._univerInstanceService.getUnit<Workbook>(this._thread.unitId, UniverInstanceType.UNIVER_SHEET);
+ if (!workbook) {
+ return null;
+ }
+ const worksheet = workbook.getSheetBySheetId(this._thread.subUnitId);
+ if (!worksheet) {
+ return null;
+ }
+ const range = this._getRef();
+ return this._injector.createInstance(FRange, workbook, worksheet, range);
+ }
+
+ /**
+ * Get the content of the comment
+ * @returns The content of the comment
+ */
+ getContent(): IDocumentBody {
+ return this._thread.text;
+ }
+
+ /**
+ * Delete the comment and it's replies
+ * @returns success or not
+ */
+ delete(): Promise<boolean> {
+ return this._commandService.executeCommand(
+ this.getIsRoot() ? DeleteCommentTreeCommand.id : DeleteCommentCommand.id,
+ {
+ commentId: this._thread.id,
+ unitId: this._thread.unitId,
+ subUnitId: this._thread.subUnitId,
+ } as IDeleteCommentCommandParams
+ );
+ }
+
+ /**
+ * Update the comment content
+ * @param content The new content of the comment
+ * @returns success or not
+ */
+ async update(content: IDocumentBody): Promise<boolean> {
+ const dt = getDT();
+ const res = await this._commandService.executeCommand(
+ UpdateCommentCommand.id,
+ {
+ unitId: this._thread.unitId,
+ subUnitId: this._thread.subUnitId,
+ payload: {
+ commentId: this._thread.id,
+ text: content,
+ updated: true,
+ updateT: dt,
+ },
+ } as IUpdateCommentCommandParams
+ );
+
+ return res;
+ }
+
+ /**
+ * Resolve the comment
+ * @param resolved Whether the comment is resolved
+ * @returns success or not
+ */
+ resolve(resolved?: boolean): Promise<boolean> {
+ return this._commandService.executeCommand(
+ ResolveCommentCommand.id,
+ {
+ unitId: this._thread.unitId,
+ subUnitId: this._thread.subUnitId,
+ commentId: this._thread.id,
+ resolved: resolved ?? !this._thread.resolved,
+ } as IResolveCommentCommandParams
+ );
+ }
+}
diff --git a/packages/facade/src/apis/sheets/f-workbook.ts b/packages/facade/src/apis/sheets/f-workbook.ts
index acf771afb4..e47eea35bd 100644
--- a/packages/facade/src/apis/sheets/f-workbook.ts
+++ b/packages/facade/src/apis/sheets/f-workbook.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import type { CommandListener, ICommandInfo, IDisposable, IRange, IWorkbookData, Nullable, ObjectMatrix, Workbook } from '@univerjs/core';
+import type { CommandListener, ICommandInfo, IDisposable, IExecutionOptions, IRange, ISheetDataValidationRule, IWorkbookData, Nullable, ObjectMatrix, Workbook } from '@univerjs/core';
import {
ICommandService,
ILogService,
@@ -33,11 +33,21 @@ import type {
ISheetCommandSharedParams,
} from '@univerjs/sheets';
import { InsertSheetCommand, RemoveSheetCommand, SetWorksheetActiveOperation, SheetsSelectionsService, WorkbookEditablePermission } from '@univerjs/sheets';
-
-import type { IDataValidationResCache } from '@univerjs/sheets-data-validation';
-import { SheetsDataValidationValidatorService } from '@univerjs/sheets-data-validation';
+import type { ICanvasFloatDom } from '@univerjs/sheets-drawing-ui';
+import type { IAddSheetDataValidationCommandParams, IDataValidationResCache, IRemoveSheetAllDataValidationCommandParams, IRemoveSheetDataValidationCommandParams, IUpdateSheetDataValidationOptionsCommandParams, IUpdateSheetDataValidationRangeCommandParams, IUpdateSheetDataValidationSettingCommandParams } from '@univerjs/sheets-data-validation';
+import { AddSheetDataValidationCommand, DataValidationModel, RemoveSheetAllDataValidationCommand, RemoveSheetDataValidationCommand, SheetsDataValidationValidatorService, UpdateSheetDataValidationOptionsCommand, UpdateSheetDataValidationRangeCommand, UpdateSheetDataValidationSettingCommand } from '@univerjs/sheets-data-validation';
+import type { IRuleChange, IValidStatusChange } from '@univerjs/data-validation';
+import type { IUpdateCommandParams } from '@univerjs/docs';
+import type { CommentUpdate, IAddCommentCommandParams, IDeleteCommentCommandParams } from '@univerjs/thread-comment';
+import { AddCommentCommand, DeleteCommentCommand, DeleteCommentTreeCommand, ThreadCommentModel, UpdateCommentCommand } from '@univerjs/thread-comment';
+import { filter } from 'rxjs';
+import type { IFComponentKey } from './utils';
import { FWorksheet } from './f-worksheet';
+export interface IFICanvasFloatDom extends Omit<ICanvasFloatDom, 'componentKey' | 'unitId' | 'subUnitId'>, IFComponentKey {
+
+}
+
export class FWorkbook {
readonly id: string;
@@ -55,6 +65,14 @@ export class FWorkbook {
this.id = this._workbook.getUnitId();
}
+ private get _dataValidationModel(): DataValidationModel {
+ return this._injector.get(DataValidationModel);
+ }
+
+ private get _threadCommentModel(): ThreadCommentModel {
+ return this._injector.get(ThreadCommentModel);
+ }
+
getId(): string {
return this.id;
}
@@ -297,4 +315,211 @@ export class FWorkbook {
this._workbook.getUnitId()
);
}
+
+ // region DataValidationHooks
+ /**
+ * The onDataValidationChange event is fired when the data validation rule of this sheet is changed.
+ * @param callback Callback function that will be called when the event is fired
+ * @returns A disposable object that can be used to unsubscribe from the event
+ */
+ onDataValidationChange(callback: (ruleChange: IRuleChange<ISheetDataValidationRule>) => void): IDisposable {
+ return toDisposable(this._dataValidationModel.ruleChange$.pipe(filter((change) => change.unitId === this._workbook.getUnitId())).subscribe(callback));
+ }
+
+ /**
+ * The onDataValidationStatusChange event is fired when the data validation status of this sheet is changed.
+ * @param callback Callback function that will be called when the event is fired
+ * @returns A disposable object that can be used to unsubscribe from the event
+ */
+ onDataValidationStatusChange(callback: (statusChange: IValidStatusChange) => void): IDisposable {
+ return toDisposable(this._dataValidationModel.validStatusChange$.pipe(filter((change) => change.unitId === this._workbook.getUnitId())).subscribe(callback));
+ }
+
+ /**
+ * The onBeforeAddDataValidation event is fired before the data validation rule is added.
+ * @param callback Callback function that will be called when the event is fired
+ * @returns A disposable object that can be used to unsubscribe from the event
+ */
+ onBeforeAddDataValidation(callback: (params: IAddSheetDataValidationCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable {
+ return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
+ const params = commandInfo.params as IAddSheetDataValidationCommandParams;
+ if (commandInfo.id === AddSheetDataValidationCommand.id) {
+ if (params.unitId !== this._workbook.getUnitId()) {
+ return;
+ }
+ if (callback(params, options) === false) {
+ throw new Error('Command is stopped by the hook onBeforeAddDataValidation');
+ }
+ }
+ }));
+ }
+
+ /**
+ * The onBeforeUpdateDataValidationCriteria event is fired before the data validation rule is updated.
+ * @param callback Callback function that will be called when the event is fired
+ * @returns A disposable object that can be used to unsubscribe from the event
+ */
+ onBeforeUpdateDataValidationCriteria(callback: (params: IUpdateSheetDataValidationSettingCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable {
+ return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
+ const params = commandInfo.params as IUpdateSheetDataValidationSettingCommandParams;
+ if (commandInfo.id === UpdateSheetDataValidationSettingCommand.id) {
+ if (params.unitId !== this._workbook.getUnitId()) {
+ return;
+ }
+
+ if (callback(params, options) === false) {
+ throw new Error('Command is stopped by the hook onBeforeUpdateDataValidationCriteria');
+ }
+ }
+ }));
+ }
+
+ /**
+ * The onBeforeUpdateDataValidationRange event is fired before the data validation rule is updated.
+ * @param callback Callback function that will be called when the event is fired
+ * @returns A disposable object that can be used to unsubscribe from the event
+ */
+ onBeforeUpdateDataValidationRange(callback: (params: IUpdateSheetDataValidationRangeCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable {
+ return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
+ const params = commandInfo.params as IUpdateSheetDataValidationRangeCommandParams;
+ if (commandInfo.id === UpdateSheetDataValidationRangeCommand.id) {
+ if (params.unitId !== this._workbook.getUnitId()) {
+ return;
+ }
+
+ if (callback(params, options) === false) {
+ throw new Error('Command is stopped by the hook onBeforeUpdateDataValidationRange');
+ }
+ }
+ }));
+ }
+
+ /**
+ * The onBeforeUpdateDataValidationOptions event is fired before the data validation rule is updated.
+ * @param callback Callback function that will be called when the event is fired
+ * @returns A disposable object that can be used to unsubscribe from the event
+ */
+ onBeforeUpdateDataValidationOptions(callback: (params: IUpdateSheetDataValidationOptionsCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable {
+ return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
+ const params = commandInfo.params as IUpdateSheetDataValidationOptionsCommandParams;
+ if (commandInfo.id === UpdateSheetDataValidationOptionsCommand.id) {
+ if (params.unitId !== this._workbook.getUnitId()) {
+ return;
+ }
+
+ if (callback(params, options) === false) {
+ throw new Error('Command is stopped by the hook onBeforeUpdateDataValidationOptions');
+ }
+ }
+ }));
+ }
+
+ /**
+ * The onBeforeDeleteDataValidation event is fired before the data validation rule is deleted.
+ * @param callback Callback function that will be called when the event is fired
+ * @returns A disposable object that can be used to unsubscribe from the event
+ */
+ onBeforeDeleteDataValidation(callback: (params: IRemoveSheetDataValidationCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable {
+ return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
+ const params = commandInfo.params as IRemoveSheetDataValidationCommandParams;
+ if (commandInfo.id === RemoveSheetDataValidationCommand.id) {
+ if (params.unitId !== this._workbook.getUnitId()) {
+ return;
+ }
+ if (callback(params, options) === false) {
+ throw new Error('Command is stopped by the hook onBeforeDeleteDataValidation');
+ }
+ }
+ }));
+ }
+
+ /**
+ * The onBeforeDeleteAllDataValidation event is fired before delete all data validation rules.
+ * @param callback Callback function that will be called when the event is fired
+ * @returns A disposable object that can be used to unsubscribe from the event
+ */
+ onBeforeDeleteAllDataValidation(callback: (params: IRemoveSheetAllDataValidationCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable {
+ return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
+ const params = commandInfo.params as IRemoveSheetAllDataValidationCommandParams;
+ if (commandInfo.id === RemoveSheetAllDataValidationCommand.id) {
+ if (params.unitId !== this._workbook.getUnitId()) {
+ return;
+ }
+ if (callback(params, options) === false) {
+ throw new Error('Command is stopped by the hook onBeforeDeleteAllDataValidation');
+ }
+ }
+ }));
+ }
+
+ // endregion
+
+ // region ThreadCommentHooks
+ /**
+ * The onThreadCommentChange event is fired when the thread comment of this sheet is changed.
+ * @param callback Callback function that will be called when the event is fired
+ * @returns A disposable object that can be used to unsubscribe from the event
+ */
+ onThreadCommentChange(callback: (commentUpdate: CommentUpdate) => void | false): IDisposable {
+ return toDisposable(this._threadCommentModel.commentUpdate$.pipe(filter((change) => change.unitId === this._workbook.getUnitId())).subscribe(callback));
+ }
+
+ /**
+ * The onThreadCommentChange event is fired when the thread comment of this sheet is changed.
+ * @param callback Callback function that will be called when the event is fired
+ * @returns A disposable object that can be used to unsubscribe from the event
+ */
+ onBeforeAddThreadComment(callback: (params: IAddCommentCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable {
+ return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
+ const params = commandInfo.params as IAddCommentCommandParams;
+ if (commandInfo.id === AddCommentCommand.id) {
+ if (params.unitId !== this._workbook.getUnitId()) {
+ return;
+ }
+ if (callback(params, options) === false) {
+ throw new Error('Command is stopped by the hook onBeforeAddThreadComment');
+ }
+ }
+ }));
+ }
+
+ /**
+ * The onBeforeUpdateThreadComment event is fired before the thread comment is updated.
+ * @param callback Callback function that will be called when the event is fired
+ * @returns A disposable object that can be used to unsubscribe from the event
+ */
+ onBeforeUpdateThreadComment(callback: (params: IUpdateCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable {
+ return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
+ const params = commandInfo.params as IUpdateCommandParams;
+ if (commandInfo.id === UpdateCommentCommand.id) {
+ if (params.unitId !== this._workbook.getUnitId()) {
+ return;
+ }
+ if (callback(params, options) === false) {
+ throw new Error('Command is stopped by the hook onBeforeUpdateThreadComment');
+ }
+ }
+ }));
+ }
+
+ /**
+ * The onBeforeDeleteThreadComment event is fired before the thread comment is deleted.
+ * @param callback Callback function that will be called when the event is fired
+ * @returns A disposable object that can be used to unsubscribe from the event
+ */
+ onBeforeDeleteThreadComment(callback: (params: IDeleteCommentCommandParams, options: IExecutionOptions | undefined) => void | false): IDisposable {
+ return toDisposable(this._commandService.beforeCommandExecuted((commandInfo, options) => {
+ const params = commandInfo.params as IDeleteCommentCommandParams;
+ if (commandInfo.id === DeleteCommentCommand.id || commandInfo.id === DeleteCommentTreeCommand.id) {
+ if (params.unitId !== this._workbook.getUnitId()) {
+ return;
+ }
+ if (callback(params, options) === false) {
+ throw new Error('Command is stopped by the hook onBeforeDeleteThreadComment');
+ }
+ }
+ }));
+ }
+
+ // endregion
}
diff --git a/packages/facade/src/apis/sheets/f-worksheet.ts b/packages/facade/src/apis/sheets/f-worksheet.ts
index 283be0a558..4f3c5eae19 100644
--- a/packages/facade/src/apis/sheets/f-worksheet.ts
+++ b/packages/facade/src/apis/sheets/f-worksheet.ts
@@ -22,11 +22,16 @@ import type { IDataValidationResCache } from '@univerjs/sheets-data-validation';
import { DataValidationModel, SheetsDataValidationValidatorService } from '@univerjs/sheets-data-validation';
import type { FilterModel } from '@univerjs/sheets-filter';
import { SheetsFilterService } from '@univerjs/sheets-filter';
+import { SheetsThreadCommentModel } from '@univerjs/sheets-thread-comment';
+import { ComponentManager } from '@univerjs/ui';
+import { SheetCanvasFloatDomManagerService } from '@univerjs/sheets-drawing-ui';
import { FRange } from './f-range';
import { FSelection } from './f-selection';
import { FDataValidation } from './f-data-validation';
import { FFilter } from './f-filter';
-import { covertToColRange, covertToRowRange } from './utils';
+import { FThreadComment } from './f-thread-comment';
+import type { IFICanvasFloatDom } from './f-workbook';
+import { covertToColRange, covertToRowRange, transformComponentKey } from './utils';
export class FWorksheet {
constructor(
@@ -39,6 +44,22 @@ export class FWorksheet {
// empty
}
+ /**
+ * Returns the injector
+ * @returns The injector
+ */
+ getInject(): Injector {
+ return this._injector;
+ }
+
+ /**
+ * Returns the workbook
+ * @returns The workbook
+ */
+ getWorkbook(): Workbook {
+ return this._workbook;
+ }
+
/**
* Returns the worksheet id
* @returns The id of the worksheet
@@ -130,6 +151,48 @@ export class FWorksheet {
// #endregion
+ // #region Comment
+ /**
+ * Get all comments in the current sheet
+ * @returns all comments in the current sheet
+ */
+ getComments(): FThreadComment[] {
+ const sheetsTheadCommentModel = this._injector.get(SheetsThreadCommentModel);
+ const comments = sheetsTheadCommentModel.getSubUnitAll(this._workbook.getUnitId(), this._worksheet.getSheetId());
+ return comments.map((comment) => this._injector.createInstance(FThreadComment, comment));
+ }
+ // #endregion
+
+ /**
+ * add a float dom to position
+ * @param layer float dom config
+ * @param id float dom id, if not given will be auto generated
+ * @returns float dom id and dispose function
+ */
+ addFloatDomToPosition(layer: IFICanvasFloatDom, id?: string): Nullable<{
+ id: string;
+ dispose: () => void;
+ }> {
+ const unitId = this._workbook.getUnitId();
+ const subUnitId = this._worksheet.getSheetId();
+ const { key, disposableCollection } = transformComponentKey(layer, this._injector.get(ComponentManager));
+ const floatDomService = this._injector.get(SheetCanvasFloatDomManagerService);
+ const res = floatDomService.addFloatDomToPosition({ ...layer, componentKey: key, unitId, subUnitId }, id);
+
+ if (res) {
+ disposableCollection.add(res.dispose);
+ return {
+ id: res.id,
+ dispose: (): void => {
+ disposableCollection.dispose();
+ res.dispose();
+ },
+ };
+ }
+
+ disposableCollection.dispose();
+ return null;
+ }
// #region Row
/**
diff --git a/packages/facade/src/apis/sheets/utils.ts b/packages/facade/src/apis/sheets/utils.ts
index 46ff30b3fd..754dbbe80d 100644
--- a/packages/facade/src/apis/sheets/utils.ts
+++ b/packages/facade/src/apis/sheets/utils.ts
@@ -16,6 +16,8 @@
import type { CellValue, ICellData, IObjectMatrixPrimitiveType, IRange, IRangeWithCoord, Nullable, Worksheet } from '@univerjs/core';
import {
+ DisposableCollection,
+ generateRandomId,
HorizontalAlign,
isCellV,
isFormulaString,
@@ -25,6 +27,7 @@ import {
Tools,
VerticalAlign,
} from '@univerjs/core';
+import type { ComponentManager, ComponentType } from '@univerjs/ui';
export type FHorizontalAlignment = 'left' | 'center' | 'normal';
export type FVerticalAlignment = 'top' | 'middle' | 'bottom';
@@ -152,6 +155,36 @@ export function isSingleCell(mergeInfo: IRangeWithCoord, range: IRange): boolean
&& mergeInfo.endRow === range.endRow;
}
+export interface IFComponentKey {
+ /**
+ * The key of the component to be rendered in the popup.
+ * if key is a string, it will be query from the component registry.
+ * if key is a React or Vue3 component, it will be rendered directly.
+ */
+ componentKey: string | ComponentType;
+ /**
+ * If componentKey is a Vue3 component, this must be set to true
+ */
+ isVue3?: boolean;
+}
+
+export function transformComponentKey(component: IFComponentKey, componentManager: ComponentManager): { key: string; disposableCollection: DisposableCollection } {
+ const { componentKey, isVue3 } = component;
+ let key: string;
+ const disposableCollection = new DisposableCollection();
+ if (typeof componentKey === 'string') {
+ key = componentKey;
+ } else {
+ key = componentManager.getKey(componentKey) ?? `External_${generateRandomId(6)}`;
+ disposableCollection.add(componentManager.register(key, componentKey, { framework: isVue3 ? 'vue3' : 'react' }));
+ }
+
+ return {
+ key,
+ disposableCollection,
+ };
+}
+
export function covertToRowRange(range: IRange, worksheet: Worksheet): IRange {
return {
startRow: range.startRow,
diff --git a/packages/facade/src/index.ts b/packages/facade/src/index.ts
index 942caf2f94..f7d930be87 100644
--- a/packages/facade/src/index.ts
+++ b/packages/facade/src/index.ts
@@ -22,8 +22,6 @@ export { FHooks } from './apis/f-hooks';
// #region - Univer Sheet
-export { FDataValidation } from './apis/sheets/f-data-validation';
-export { FDataValidationBuilder } from './apis/sheets/f-data-validation-builder';
export { FFilter } from './apis/sheets/f-filter';
export { FFormula } from './apis/sheets/f-formula';
export { FPermission } from './apis/sheets/f-permission';
@@ -32,5 +30,8 @@ export { FSelection } from './apis/sheets/f-selection';
export { FSheetHooks } from './apis/sheets/f-sheet-hooks';
export { FWorkbook } from './apis/sheets/f-workbook';
export { FWorksheet } from './apis/sheets/f-worksheet';
+export { FDataValidation } from './apis/sheets/f-data-validation';
+export { FDataValidationBuilder } from './apis/sheets/f-data-validation-builder';
+export { FThreadComment } from './apis/sheets/f-thread-comment';
// #endregion
diff --git a/packages/sheets-data-validation/src/commands/commands/data-validation.command.ts b/packages/sheets-data-validation/src/commands/commands/data-validation.command.ts
index 8a92271dc1..f6da4b7fdc 100644
--- a/packages/sheets-data-validation/src/commands/commands/data-validation.command.ts
+++ b/packages/sheets-data-validation/src/commands/commands/data-validation.command.ts
@@ -514,7 +514,28 @@ export const ClearRangeDataValidationCommand: ICommand<IClearRangeDataValidation
if (!params) {
return false;
}
+ const { unitId, subUnitId, ranges } = params;
const commandService = accessor.get(ICommandService);
- return true;
+ const univerInstanceService = accessor.get(IUniverInstanceService);
+ const target = getSheetCommandTarget(univerInstanceService, { unitId, subUnitId });
+ const dataValidationModel = accessor.get(DataValidationModel);
+
+ if (!target) return false;
+ const undoRedoService = accessor.get(IUndoRedoService);
+ const manager = dataValidationModel.ensureManager(unitId, subUnitId) as SheetDataValidationManager;
+
+ const matrix = manager.getRuleObjectMatrix().clone();
+ matrix.removeRange(ranges);
+
+ const diffs = matrix.diff(manager.getDataValidations());
+ const { redoMutations, undoMutations } = getDataValidationDiffMutations(unitId, subUnitId, diffs, accessor);
+
+ undoRedoService.pushUndoRedo({
+ unitID: unitId,
+ redoMutations,
+ undoMutations,
+ });
+
+ return sequenceExecute(redoMutations, commandService).result;
},
};
diff --git a/packages/sheets-data-validation/src/index.ts b/packages/sheets-data-validation/src/index.ts
index 12f44d08e7..60e0f2aa1b 100644
--- a/packages/sheets-data-validation/src/index.ts
+++ b/packages/sheets-data-validation/src/index.ts
@@ -22,7 +22,11 @@ export { DataValidationFormulaService } from './services/dv-formula.service';
export { DataValidationCustomFormulaService } from './services/dv-custom-formula.service';
export { DATA_VALIDATION_PLUGIN_NAME } from './common/const';
export { SheetsDataValidationValidatorService } from './services/dv-validator-service';
-export { DataValidationModel } from '@univerjs/data-validation';
+export {
+ DataValidationModel,
+ RemoveAllDataValidationCommand as RemoveSheetAllDataValidationCommand,
+ type IRemoveAllDataValidationCommandParams as IRemoveSheetAllDataValidationCommandParams,
+} from '@univerjs/data-validation';
export { SheetDataValidationManager } from './models/sheet-data-validation-manager';
// #region - all commands
diff --git a/packages/sheets-drawing-ui/src/services/canvas-float-dom-manager.service.ts b/packages/sheets-drawing-ui/src/services/canvas-float-dom-manager.service.ts
index 6f973c191d..7564872c43 100644
--- a/packages/sheets-drawing-ui/src/services/canvas-float-dom-manager.service.ts
+++ b/packages/sheets-drawing-ui/src/services/canvas-float-dom-manager.service.ts
@@ -32,10 +32,22 @@ import { InsertSheetDrawingCommand } from '../commands/commands/insert-sheet-dra
import type { IInsertDrawingCommandParams } from '../commands/commands/interfaces';
export interface ICanvasFloatDom {
+ /**
+ * whether allow transform float-dom
+ */
allowTransform: boolean;
+ /**
+ * initial position of float-dom
+ */
initPosition: IPosition;
componentKey: string;
+ /**
+ * unitId of workbook, if not set, will use current workbook
+ */
unitId?: string;
+ /**
+ * subUnitId of worksheet, if not set, will use current worksheet
+ */
subUnitId?: string;
/**
* @deprecated Please use `data`. for saving to disk, everything add to float-dom must be serializable.
diff --git a/packages/sheets-thread-comment-base/src/models/sheets-thread-comment.model.ts b/packages/sheets-thread-comment-base/src/models/sheets-thread-comment.model.ts
index 8f25ee39ec..ce698bc887 100644
--- a/packages/sheets-thread-comment-base/src/models/sheets-thread-comment.model.ts
+++ b/packages/sheets-thread-comment-base/src/models/sheets-thread-comment.model.ts
@@ -268,4 +268,8 @@ export class SheetsThreadCommentModel extends Disposable {
return false;
}
+
+ getSubUnitAll(unitId: string, subUnitId: string) {
+ return Object.values(this._threadCommentModel.getAll()[unitId]?.[subUnitId] ?? {});
+ }
}
diff --git a/packages/sheets-ui/src/services/canvas-pop-manager.service.ts b/packages/sheets-ui/src/services/canvas-pop-manager.service.ts
index fafeeea310..5936bbd331 100644
--- a/packages/sheets-ui/src/services/canvas-pop-manager.service.ts
+++ b/packages/sheets-ui/src/services/canvas-pop-manager.service.ts
@@ -156,9 +156,8 @@ export class SheetCanvasPopManagerService extends Disposable {
* @param viewport target viewport
* @returns disposable
*/
- attachPopupToCell(row: number, col: number, popup: ICanvasPopup, viewport?: Viewport, showOnSelectionMoving = false): Nullable<IDisposable> {
+ attachPopupToCell(row: number, col: number, popup: ICanvasPopup, _unitId?: string, _subUnitId?: string, viewport?: Viewport, showOnSelectionMoving = false): Nullable<IDisposable> {
const workbook = this._univerInstanceService.getCurrentUnitForType<Workbook>(UniverInstanceType.UNIVER_SHEET)!;
-
const worksheet = workbook.getActiveSheet();
if (!worksheet) {
return null;
@@ -166,6 +165,9 @@ export class SheetCanvasPopManagerService extends Disposable {
const unitId = workbook.getUnitId();
const subUnitId = worksheet.getSheetId();
+ if (unitId !== _unitId || subUnitId !== _subUnitId) {
+ return null;
+ }
const currentRender = this._renderManagerService.getRenderById(unitId);
const skeleton = currentRender?.with(SheetSkeletonManagerService).getOrCreateSkeleton({
sheetId: subUnitId,
diff --git a/packages/ui/src/common/component-manager.ts b/packages/ui/src/common/component-manager.ts
index ab535cb72d..9641148329 100644
--- a/packages/ui/src/common/component-manager.ts
+++ b/packages/ui/src/common/component-manager.ts
@@ -145,6 +145,7 @@ export type ComponentList = Map<string, IVue3Component | IReactComponent>;
export class ComponentManager {
private _components: ComponentList = new Map();
+ private _componentsReverse = new Map<ComponentType, string>();
// eslint-disable-next-line max-lines-per-function
constructor() {
@@ -268,8 +269,16 @@ export class ComponentManager {
framework,
component,
});
+ this._componentsReverse.set(component, name);
- return toDisposable(() => this._components.delete(name));
+ return toDisposable(() => {
+ this._components.delete(name);
+ this._componentsReverse.delete(component);
+ });
+ }
+
+ getKey(component: ComponentType) {
+ return this._componentsReverse.get(component);
}
get(name: string) {
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 70dd8a23cd..5c3941ae83 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1539,6 +1539,9 @@ importers:
'@univerjs/sheets-data-validation':
specifier: workspace:*
version: link:../sheets-data-validation
+ '@univerjs/sheets-drawing-ui':
+ specifier: workspace:*
+ version: link:../sheets-drawing-ui
'@univerjs/sheets-filter':
specifier: workspace:*
version: link:../sheets-filter
@@ -1551,9 +1554,18 @@ importers:
'@univerjs/sheets-numfmt':
specifier: workspace:*
version: link:../sheets-numfmt
+ '@univerjs/sheets-thread-comment':
+ specifier: workspace:*
+ version: link:../sheets-thread-comment
'@univerjs/sheets-ui':
specifier: workspace:*
version: link:../sheets-ui
+ '@univerjs/thread-comment':
+ specifier: workspace:*
+ version: link:../thread-comment
+ '@univerjs/thread-comment-ui':
+ specifier: workspace:*
+ version: link:../thread-comment-ui
'@univerjs/ui':
specifier: workspace:*
version: link:../ui