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.

chore(collaboration): set selection

Dushusir64a226dca47e
diff --git a/examples/univer-preact-ts/src/main.tsx b/examples/univer-preact-ts/src/main.tsx
index 2aec98d83d..c37fed48f3 100644
--- a/examples/univer-preact-ts/src/main.tsx
+++ b/examples/univer-preact-ts/src/main.tsx
@@ -60,8 +60,8 @@ const defaultWorkbookData = Tools.deepClone(DEFAULT_WORKBOOK_DATA_DEMO7);
// },
// };
-const ipAddress = 'localhost:8500';
-// const ipAddress = '47.100.177.253:8500'
+// const ipAddress = 'localhost:8500';
+const ipAddress = '47.100.177.253:8500'
const config = { type: 'sheet', template: 'DEMO1' };
insertButton();
diff --git a/packages/base-sheets/src/Controller/EditTooltipsController.ts b/packages/base-sheets/src/Controller/EditTooltipsController.ts
index b196b214cc..29d4d8de4c 100644
--- a/packages/base-sheets/src/Controller/EditTooltipsController.ts
+++ b/packages/base-sheets/src/Controller/EditTooltipsController.ts
@@ -12,6 +12,7 @@ export class EditTooltipsController {
constructor(plugin: SheetPlugin) {
this._plugin = plugin;
+ this._editTooltipsPage = new Map();
}
removeEditTooltipsByKey(key: string): EditTooltips | null {
@@ -84,7 +85,7 @@ export class EditTooltipsController {
const scene = this._plugin.getMainScene();
if (scene) {
if (this._layer == null) {
- this._layer = new Layer(scene, []);
+ this._layer = new Layer(scene, [], 3);
scene.addLayer(this._layer);
}
this._layer.clear();
diff --git a/packages/common-plugin-collaboration/src/Controller/CollaborationController.ts b/packages/common-plugin-collaboration/src/Controller/CollaborationController.ts
index fb7bb435c3..fad42b4695 100644
--- a/packages/common-plugin-collaboration/src/Controller/CollaborationController.ts
+++ b/packages/common-plugin-collaboration/src/Controller/CollaborationController.ts
@@ -1,4 +1,4 @@
-import { SheetPlugin, SetSelectionValueAction } from '@univerjs/base-sheets';
+import { SheetPlugin, SetSelectionValueAction, ISetSelectionValueActionData } from '@univerjs/base-sheets';
import {
ActionOperation,
ACTION_NAMES,
@@ -14,6 +14,8 @@ import {
SheetActionBase,
SheetContext,
IActionData,
+ IGridRange,
+ Tools,
} from '@univerjs/core';
import { CollaborationPlugin } from '../CollaborationPlugin';
@@ -27,6 +29,8 @@ export class CollaborationController {
previousMessage: string;
+ userNum: number = 1;
+
private _plugin: CollaborationPlugin;
private _sheetPlugin: SheetPlugin;
@@ -153,31 +157,42 @@ export class CollaborationController {
}
highlightCell(config: MessageConfigType) {
- console.info('收到高亮消息===')
- // const { actionData } = config;
- // const { sheetId, cellValue } = actionData as ISetRangeDataActionData;
-
- // const context = this._sheetPlugin.getContext();
- // const _commandManager = context.getCommandManager();
- // const worksheet = this._sheetPlugin.getWorkbook().getSheetBySheetId(sheetId);
-
- // if (!worksheet) return;
-
- // console.log('收到协同更新==范围:', '数据:', cellValue);
-
- // let setValue: ISetRangeDataActionData = {
- // sheetId: worksheet.getSheetId(),
- // actionName: ACTION_NAMES.SET_RANGE_DATA_ACTION,
- // cellValue,
- // };
- // setValue = ActionOperation.make<ISetRangeDataActionData>(setValue).removeCollaboration().getAction();
- // const command = new Command(
- // {
- // WorkBookUnit: context.getWorkBook(),
- // },
- // setValue
- // );
- // _commandManager.invoke(command);
+ const { actionData } = config;
+ const { sheetId, selections } = actionData as ISetSelectionValueActionData;
+
+ const context = this._sheetPlugin.getContext();
+ const _commandManager = context.getCommandManager();
+ const worksheet = this._sheetPlugin.getWorkbook().getSheetBySheetId(sheetId);
+
+ if (!worksheet || !selections[0].cell) return;
+
+ const { row: startRow, column: startColumn } = selections[0].cell;
+ const range: IGridRange = {
+ sheetId,
+ rangeData: {
+ startRow,
+ startColumn,
+ endRow: startRow,
+ endColumn: startColumn,
+ },
+ };
+
+ // getEditTooltipsController
+ console.info('range===', range);
+ const key = Tools.generateRandomId();
+ const editTooltipsController = this._plugin
+ .getContext()
+ .getUniver()
+ .getCurrentUniverSheetInstance()
+ .getWorkBook()
+ .getContext()
+ .getPluginManager()
+ .getPluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)
+ ?.getEditTooltipsController();
+
+ editTooltipsController?.createIfEditTooltips(key, sheetId, { text: `User${this.userNum++}` });
+ editTooltipsController?.setRowColumn(key, sheetId, startRow, startColumn);
+ editTooltipsController?.refreshEditTooltips();
}
refresh(config: IKeyValue) {
@@ -268,23 +283,23 @@ export class CollaborationController {
timer = null;
}
- timer = setTimeout(() => {
- // const currentEditRangeValue = this._sheetPlugin.getCellEditorController().getCurrentEditRangeData();
- const data: MessageConfigType = {
- univerId: currentUnitId,
- actionData: action.getDoActionData(),
- };
-
- let stringData = JSON.stringify(data);
- const message = {
- type: 'data',
- data: stringData,
- };
-
- const stringMessage = JSON.stringify(message);
- this.previousMessage = stringData;
- this.socket.send(stringMessage);
- }, 100);
+ // timer = setTimeout(() => {
+ // const currentEditRangeValue = this._sheetPlugin.getCellEditorController().getCurrentEditRangeData();
+ const data: MessageConfigType = {
+ univerId: currentUnitId,
+ actionData: action.getDoActionData(),
+ };
+
+ let stringData = JSON.stringify(data);
+ const message = {
+ type: 'data',
+ data: stringData,
+ };
+
+ const stringMessage = JSON.stringify(message);
+ this.previousMessage = stringData;
+ this.socket.send(stringMessage);
+ // }, 100);
} catch (error) {
console.info(error);
}
diff --git a/packages/core/src/Basics/Univer.ts b/packages/core/src/Basics/Univer.ts
index 9b90ffb74f..666cbbff8c 100644
--- a/packages/core/src/Basics/Univer.ts
+++ b/packages/core/src/Basics/Univer.ts
@@ -1,10 +1,10 @@
-import { IUniverData } from './../Interfaces/IUniverData';
import { UniverSheet } from './UniverSheet';
import { UniverDoc } from './UniverDoc';
import { UniverSlide } from './UniverSlide';
import { Nullable } from '../Shared';
import { Context } from './Context';
import { Plugin } from '../Plugin';
+import { IUniverData } from '../Interfaces';
export class Univer {
private _univerSheets: UniverSheet[];
diff --git a/packages/core/src/Command/ActionBase.ts b/packages/core/src/Command/ActionBase.ts
index b598a21492..a61c331b35 100644
--- a/packages/core/src/Command/ActionBase.ts
+++ b/packages/core/src/Command/ActionBase.ts
@@ -16,27 +16,30 @@ export enum ActionOperationType {
/**
* send obs
*/
- OBSERVER_ACTION = 1,
+ OBSERVER_ACTION = 0x00000001,
/**
* send server
*/
- SERVER_ACTION = 2,
+ SERVER_ACTION = 0x00000002,
/**
* push to UNDO/REDO stack
*/
- UNDO_ACTION = 3,
+ UNDO_ACTION = 0x00000004,
/**
* action extension
*/
- EXTENSION_ACTION = 4,
+ EXTENSION_ACTION = 0x00000008,
/**
* default obs
*/
- DEFAULT_ACTION = 1 | 2 | 3 | 4,
+ DEFAULT_ACTION = ActionOperationType.OBSERVER_ACTION |
+ ActionOperationType.SERVER_ACTION |
+ ActionOperationType.UNDO_ACTION |
+ ActionOperationType.EXTENSION_ACTION,
}
/**