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(sheets-ui): optimize ref-range for hyper-link and thread-comment (#2405)

zhangw88f2f6d0c1b0
diff --git a/examples/src/data/sheets/demo/default-workbook-data-demo.ts b/examples/src/data/sheets/demo/default-workbook-data-demo.ts
index 2ccb9f0dd4..33dfd5226f 100644
--- a/examples/src/data/sheets/demo/default-workbook-data-demo.ts
+++ b/examples/src/data/sheets/demo/default-workbook-data-demo.ts
@@ -175,13 +175,35 @@ const dataValidation = [
},
];
-const hyperLink = [{
- row: 20,
- column: 12,
- id: '123',
- display: 'linkTest哈哈哈哈',
- payload: '#gid=sheet-0011&range=1:1',
-}] as ICellHyperLink[];
+const dv2 = [
+ {
+ uid: 'xxx-2',
+ type: DataValidationType.CHECKBOX,
+ ranges: [{
+ startRow: 1,
+ endRow: 2,
+ startColumn: 1,
+ endColumn: 2,
+ }],
+ },
+];
+
+const hyperLink = [
+ {
+ row: 20,
+ column: 8,
+ id: '321',
+ display: 'linkTest',
+ payload: '#gid=sheet-0011&range=1:1',
+ },
+ {
+ row: 20,
+ column: 12,
+ id: '123',
+ display: 'linkTest哈哈哈哈',
+ payload: '#gid=sheet-0011&range=1:1',
+ },
+] as ICellHyperLink[];
export const DEFAULT_WORKBOOK_DATA_DEMO: IWorkbookData = {
id: 'workbook-01',
@@ -189,6 +211,7 @@ export const DEFAULT_WORKBOOK_DATA_DEMO: IWorkbookData = {
name: 'UniverSheet Demo',
sheetOrder: [
'sheet-0011',
+ 'dv-test',
'sheet-0001',
'sheet-0002',
'sheet-0003',
@@ -14082,6 +14105,10 @@ export const DEFAULT_WORKBOOK_DATA_DEMO: IWorkbookData = {
v: 345,
t: 2,
},
+ 8: {
+ v: 'linkTest',
+ t: 1,
+ },
12: {
v: 'linkTest哈哈哈哈',
t: 1,
@@ -14202,6 +14229,45 @@ export const DEFAULT_WORKBOOK_DATA_DEMO: IWorkbookData = {
],
rightToLeft: 0,
},
+ 'dv-test': {
+ name: 'dv-test',
+ id: 'dv-test',
+ tabColor: '',
+ hidden: 0,
+ rowCount: 1000,
+ columnCount: 20,
+ zoomRatio: 1,
+ cellData: {
+ 5: {
+ 1: {
+ v: '1',
+ t: 2,
+ },
+ 2: {
+ v: '12',
+ t: 2,
+ },
+ },
+ 6: {
+ 1: {
+ v: '2',
+ t: 2,
+ },
+ },
+ 7: {
+ 1: {
+ v: '3',
+ t: 2,
+ },
+ },
+ 8: {
+ 1: {
+ v: '4',
+ t: 2,
+ },
+ },
+ },
+ },
'sheet-0010': {
name: 'sheet-0010',
id: 'sheet-0010',
@@ -23564,6 +23630,7 @@ export const DEFAULT_WORKBOOK_DATA_DEMO: IWorkbookData = {
name: DATA_VALIDATION_PLUGIN_NAME,
data: JSON.stringify({
'sheet-0011': dataValidation,
+ 'dv-test': dv2,
}),
},
{
@@ -23581,7 +23648,86 @@ export const DEFAULT_WORKBOOK_DATA_DEMO: IWorkbookData = {
},
{
name: 'SHEET_THREAD_COMMENT_PLUGIN',
- data: '{"sheet-0011":[{"text":{"textRuns":[],"paragraphs":[{"startIndex":3,"paragraphStyle":{}}],"sectionBreaks":[{"startIndex":4}],"dataStream":"123\\n\\r","customRanges":[]},"dT":"2024/05/17 21:16","id":"jwV0QtHwUbhG3o--iy1qa","ref":"H9","personId":"mockId","unitId":"workbook-01","subUnitId":"sheet-0011"}]}',
+ data: JSON.stringify({
+ 'sheet-0011': [{ text: { textRuns: [], paragraphs: [{ startIndex: 3, paragraphStyle: {} }], sectionBreaks: [{ startIndex: 4 }], dataStream: '123\\n\\r', customRanges: [] }, dT: '2024/05/17 21:16', id: 'jwV0QtHwUbhG3o--iy1qa', ref: 'H9', personId: 'mockId', unitId: 'workbook-01', subUnitId: 'sheet-0011' }],
+ 'dv-test': [
+ {
+ text: {
+ textRuns: [],
+ paragraphs: [{ startIndex: 3, paragraphStyle: {} }],
+ sectionBreaks: [{ startIndex: 4 }],
+ dataStream: '1\\n\\r',
+ customRanges: [],
+ },
+ dT: '2024/05/17 21:16',
+ id: '12',
+ ref: 'C6',
+ personId: 'mockId',
+ unitId: 'workbook-01',
+ subUnitId: 'sheet-0011',
+ },
+ {
+ text: {
+ textRuns: [],
+ paragraphs: [{ startIndex: 3, paragraphStyle: {} }],
+ sectionBreaks: [{ startIndex: 4 }],
+ dataStream: '1\\n\\r',
+ customRanges: [],
+ },
+ dT: '2024/05/17 21:16',
+ id: '1',
+ ref: 'B6',
+ personId: 'mockId',
+ unitId: 'workbook-01',
+ subUnitId: 'sheet-0011',
+ },
+ {
+ text: {
+ textRuns: [],
+ paragraphs: [{ startIndex: 3, paragraphStyle: {} }],
+ sectionBreaks: [{ startIndex: 4 }],
+ dataStream: '2\\n\\r',
+ customRanges: [],
+ },
+ dT: '2024/05/17 21:16',
+ id: '2',
+ ref: 'B7',
+ personId: 'mockId',
+ unitId: 'workbook-01',
+ subUnitId: 'sheet-0011',
+ },
+ {
+ text: {
+ textRuns: [],
+ paragraphs: [{ startIndex: 3, paragraphStyle: {} }],
+ sectionBreaks: [{ startIndex: 4 }],
+ dataStream: '3\\n\\r',
+ customRanges: [],
+ },
+ dT: '2024/05/17 21:16',
+ id: '3',
+ ref: 'B8',
+ personId: 'mockId',
+ unitId: 'workbook-01',
+ subUnitId: 'sheet-0011',
+ },
+ {
+ text: {
+ textRuns: [],
+ paragraphs: [{ startIndex: 3, paragraphStyle: {} }],
+ sectionBreaks: [{ startIndex: 4 }],
+ dataStream: '4\\n\\r',
+ customRanges: [],
+ },
+ dT: '2024/05/17 21:16',
+ id: '4',
+ ref: 'B9',
+ personId: 'mockId',
+ unitId: 'workbook-01',
+ subUnitId: 'sheet-0011',
+ },
+ ],
+ }),
},
{
name: 'SHEET_DRAWING_PLUGIN',
diff --git a/packages/core/src/shared/common.ts b/packages/core/src/shared/common.ts
index 53312cfd62..fd140dad85 100644
--- a/packages/core/src/shared/common.ts
+++ b/packages/core/src/shared/common.ts
@@ -550,6 +550,18 @@ export function isValidRange(range: IRange): boolean {
return false;
}
+ if (
+ rangeType !== RANGE_TYPE.ROW &&
+ rangeType !== RANGE_TYPE.COLUMN && (
+ Number.isNaN(startColumn) ||
+ Number.isNaN(startRow) ||
+ Number.isNaN(endColumn) ||
+ Number.isNaN(endRow)
+ )
+ ) {
+ return false;
+ }
+
return true;
}
diff --git a/packages/core/src/sheets/range.ts b/packages/core/src/sheets/range.ts
index 889423f045..5e6b66dac7 100644
--- a/packages/core/src/sheets/range.ts
+++ b/packages/core/src/sheets/range.ts
@@ -19,16 +19,17 @@ import { ObjectMatrix, Tools } from '../shared';
import { DEFAULT_STYLES } from '../types/const';
import type { HorizontalAlign, VerticalAlign, WrapStrategy } from '../types/enum';
import { BooleanNumber, FontItalic, FontWeight } from '../types/enum';
-import type {
- IBorderData,
- ICellData,
- IDocumentBody,
- IDocumentData,
- IRange,
- IStyleBase,
- IStyleData,
- ITextDecoration,
- ITextRotation,
+import {
+ type IBorderData,
+ type ICellData,
+ type IDocumentBody,
+ type IDocumentData,
+ type IRange,
+ type IStyleBase,
+ type IStyleData,
+ type ITextDecoration,
+ type ITextRotation,
+ RANGE_TYPE,
} from '../types/interfaces';
import type { Styles } from './styles';
import type { Worksheet } from './worksheet';
@@ -122,6 +123,37 @@ export class Range {
}
}
+ static transformRange = (range: IRange, worksheet: Worksheet): IRange => {
+ if (range.rangeType === RANGE_TYPE.ALL) {
+ return {
+ startColumn: 0,
+ startRow: 0,
+ endColumn: worksheet.getMaxColumns() - 1,
+ endRow: worksheet.getMaxRows() - 1,
+ };
+ }
+
+ if (range.rangeType === RANGE_TYPE.COLUMN) {
+ return {
+ startRow: 0,
+ endRow: worksheet.getMaxRows() - 1,
+ startColumn: range.startColumn,
+ endColumn: range.endColumn,
+ };
+ }
+
+ if (range.rangeType === RANGE_TYPE.ROW) {
+ return {
+ startColumn: 0,
+ endColumn: worksheet.getMaxColumns() - 1,
+ startRow: range.startRow,
+ endRow: range.endRow,
+ };
+ }
+
+ return range;
+ };
+
/**
* get current range data
*
diff --git a/packages/core/src/types/interfaces/i-cell-custom-render.ts b/packages/core/src/types/interfaces/i-cell-custom-render.ts
index 7ff17e7cad..62f0a9830e 100644
--- a/packages/core/src/types/interfaces/i-cell-custom-render.ts
+++ b/packages/core/src/types/interfaces/i-cell-custom-render.ts
@@ -17,6 +17,8 @@
/* eslint-disable ts/no-explicit-any */
import type { Nullable } from '../../shared';
+import type { Worksheet } from '../../sheets/worksheet';
+import type { Workbook } from '../../sheets/workbook';
import type { ISelectionCellWithCoord } from './i-selection-data';
import type { IStyleData } from './i-style-data';
import type { ICellDataForSheetInterceptor } from './i-cell-data';
@@ -29,6 +31,8 @@ export interface ICellRenderContext {
subUnitId: string;
row: number;
col: number;
+ worksheet: Worksheet;
+ workbook?: Workbook;
}
/**
diff --git a/packages/data-validation/src/commands/commands/data-validation.command.ts b/packages/data-validation/src/commands/commands/data-validation.command.ts
index 170df816fc..b4747d5ac4 100644
--- a/packages/data-validation/src/commands/commands/data-validation.command.ts
+++ b/packages/data-validation/src/commands/commands/data-validation.command.ts
@@ -231,13 +231,12 @@ export const UpdateDataValidationSettingCommand: ICommand<IUpdateDataValidationS
if (!validator) {
return false;
}
-
- if (!validator.validatorFormula(setting).success) {
+ const rule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
+ if (!rule) {
return false;
}
- const rule = dataValidationModel.getRuleById(unitId, subUnitId, ruleId);
- if (!rule) {
+ if (!validator.validatorFormula({ ...rule, ...setting }, unitId, subUnitId).success) {
return false;
}
diff --git a/packages/data-validation/src/validators/base-data-validator.ts b/packages/data-validation/src/validators/base-data-validator.ts
index a4aea2ae54..01c3e3fae1 100644
--- a/packages/data-validation/src/validators/base-data-validator.ts
+++ b/packages/data-validation/src/validators/base-data-validator.ts
@@ -125,7 +125,7 @@ export abstract class BaseDataValidator<DataType = CellValue> {
abstract parseFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): Promise<IFormulaResult>;
- abstract validatorFormula(rule: IDataValidationRuleBase): IFormulaValidResult;
+ abstract validatorFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): IFormulaValidResult;
async isValidType(cellInfo: IValidatorCellInfo, formula: IFormulaResult, rule: IDataValidationRule): Promise<boolean> {
return true;
diff --git a/packages/engine-render/src/components/sheets/extensions/custom.ts b/packages/engine-render/src/components/sheets/extensions/custom.ts
index d239da7634..5c8a29d6a4 100644
--- a/packages/engine-render/src/components/sheets/extensions/custom.ts
+++ b/packages/engine-render/src/components/sheets/extensions/custom.ts
@@ -85,6 +85,7 @@ export class Custom extends SheetExtension {
subUnitId,
row,
col,
+ worksheet,
};
// current cell is hidden
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 fb72a6d72c..a6fb377a45 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
@@ -30,6 +30,7 @@ export interface IUpdateSheetDataValidationRangeCommandParams {
ranges: IRange[];
}
+// eslint-disable-next-line max-lines-per-function
export function getDataValidationDiffMutations(unitId: string, subUnitId: string, diffs: RangeMutation[]) {
const redoMutations: IMutationInfo[] = [];
diff --git a/packages/sheets-data-validation/src/controllers/dv-render.controller.ts b/packages/sheets-data-validation/src/controllers/dv-render.controller.ts
index c02a86526c..4886c47256 100644
--- a/packages/sheets-data-validation/src/controllers/dv-render.controller.ts
+++ b/packages/sheets-data-validation/src/controllers/dv-render.controller.ts
@@ -211,7 +211,7 @@ export class SheetsDataValidationRenderController extends RxDisposable {
priority: 200,
// eslint-disable-next-line max-lines-per-function
handler: (cell, pos, next) => {
- const { row, col, unitId, subUnitId } = pos;
+ const { row, col, unitId, subUnitId, workbook, worksheet } = pos;
const manager = this._dataValidationModel.ensureManager(unitId, subUnitId) as SheetDataValidationManager;
if (!manager) {
return next(cell);
@@ -235,7 +235,7 @@ export class SheetsDataValidationRenderController extends RxDisposable {
if (!rule) {
return next(cell);
}
- const cellRaw = pos.worksheet.getCellRaw(pos.row, pos.col);
+ const cellRaw = worksheet.getCellRaw(pos.row, pos.col);
const validStatus = this._dataValidationModel.validator(getCellValueOrigin(cellRaw), rule, pos);
const validator = this._dataValidatorRegistryService.getValidatorItem(rule.type);
const cellValue = getCellValueOrigin(cell);
@@ -331,6 +331,8 @@ export class SheetsDataValidationRenderController extends RxDisposable {
subUnitId,
row,
col,
+ workbook,
+ worksheet,
};
return validator?.canvasRender?.calcCellAutoHeight?.(info);
},
diff --git a/packages/sheets-data-validation/src/locale/en-US.ts b/packages/sheets-data-validation/src/locale/en-US.ts
index 7d858085c7..8115717f28 100644
--- a/packages/sheets-data-validation/src/locale/en-US.ts
+++ b/packages/sheets-data-validation/src/locale/en-US.ts
@@ -29,6 +29,7 @@ const locale: typeof zhCN = {
listInvalid: 'The list source must be a delimited list or a reference to a single row or column',
checkboxEqual: 'Enter different values for ticked and unticked cell contents.',
formulaError: 'The reference range contains invisible data, please readjust the range',
+ listIntersects: 'The selected range cannot intersect with the scope of the rules',
},
panel: {
title: 'Data validation management',
diff --git a/packages/sheets-data-validation/src/locale/ru-RU.ts b/packages/sheets-data-validation/src/locale/ru-RU.ts
index c9e4fe4cd8..a0fe9f8ac3 100644
--- a/packages/sheets-data-validation/src/locale/ru-RU.ts
+++ b/packages/sheets-data-validation/src/locale/ru-RU.ts
@@ -29,6 +29,7 @@ const locale: typeof zhCN = {
listInvalid: 'Источник списка должен быть разделенным списком или ссылкой на одну строку или столбец',
checkboxEqual: 'Для выбранных и не выбранных ячеек введите разные значения',
formulaError: 'Диапазон ссылок содержит невидимые данные, пожалуйста, пересмотрите диапазон',
+ listIntersects: 'Выбранный диапазон не может пересекаться с диапазоном правила.',
},
panel: {
title: 'Управление проверкой данных',
diff --git a/packages/sheets-data-validation/src/locale/zh-CN.ts b/packages/sheets-data-validation/src/locale/zh-CN.ts
index d36678c958..9fab9fee0a 100644
--- a/packages/sheets-data-validation/src/locale/zh-CN.ts
+++ b/packages/sheets-data-validation/src/locale/zh-CN.ts
@@ -27,6 +27,7 @@ const locale = {
listInvalid: '列表源必须是分隔列表或对单行或列的引用。',
checkboxEqual: '为勾选和未勾选的单元格内容输入不同的值。',
formulaError: '引用范围内包含不可见的数据,请重新调整范围',
+ listIntersects: '所选范围不能和规则范围相交',
},
panel: {
title: '管理数据验证',
diff --git a/packages/sheets-data-validation/src/models/rule-matrix.ts b/packages/sheets-data-validation/src/models/rule-matrix.ts
index dfb82b5158..7766df6e4a 100644
--- a/packages/sheets-data-validation/src/models/rule-matrix.ts
+++ b/packages/sheets-data-validation/src/models/rule-matrix.ts
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-import { type IRange, type ISheetDataValidationRule, ObjectMatrix, Range, Rectangle } from '@univerjs/core';
-import { queryObjectMatrix } from '@univerjs/core';
+import type { IRange, ISheetDataValidationRule, Worksheet } from '@univerjs/core';
+import { ObjectMatrix, queryObjectMatrix, Range, Rectangle } from '@univerjs/core';
export type RangeMutation = {
type: 'update';
@@ -34,22 +34,28 @@ export type RangeMutation = {
export class RuleMatrix {
readonly value: ObjectMatrix<string>;
- constructor(value: ObjectMatrix<string>) {
+ constructor(
+ value: ObjectMatrix<string>,
+ private _worksheet: Worksheet
+ ) {
this.value = value;
}
addRule(rule: ISheetDataValidationRule) {
const ruleId = rule.uid;
rule.ranges.forEach((range) => {
- Range.foreach(range, (row, col) => {
- this.value.setValue(row, col, ruleId);
- });
+ Range.foreach(
+ Range.transformRange(range, this._worksheet),
+ (row, col) => {
+ this.value.setValue(row, col, ruleId);
+ }
+ );
});
}
removeRange(ranges: IRange[]) {
ranges.forEach((range) => {
- Range.foreach(range, (row, col) => {
+ Range.foreach(Range.transformRange(range, this._worksheet), (row, col) => {
this.value.realDeleteValue(row, col);
});
});
@@ -57,14 +63,17 @@ export class RuleMatrix {
removeRule(rule: ISheetDataValidationRule) {
rule.ranges.forEach((range) => {
- Range.foreach(range, (row, col) => {
+ Range.foreach(Range.transformRange(range, this._worksheet), (row, col) => {
this.value.setValue(row, col, '');
});
});
}
- updateRange(ruleId: string, oldRanges: IRange[], newRanges: IRange[]) {
+ updateRange(ruleId: string, _oldRanges: IRange[], _newRanges: IRange[]) {
const tempRuleId = `${ruleId}$`;
+ const oldRanges = _oldRanges.map((range) => Range.transformRange(range, this._worksheet));
+ const newRanges = _newRanges.map((range) => Range.transformRange(range, this._worksheet));
+
oldRanges.forEach((range) => {
Range.foreach(range, (row, col) => {
if (this.value.getValue(row, col) === ruleId) {
@@ -159,7 +168,7 @@ export class RuleMatrix {
}
clone() {
- return new RuleMatrix(new ObjectMatrix(this.value.clone()));
+ return new RuleMatrix(new ObjectMatrix(this.value.clone()), this._worksheet);
}
getValue(row: number, col: number) {
diff --git a/packages/sheets-data-validation/src/models/sheet-data-validation-manager.ts b/packages/sheets-data-validation/src/models/sheet-data-validation-manager.ts
index 6b51e3d6d3..d50e24bd9b 100644
--- a/packages/sheets-data-validation/src/models/sheet-data-validation-manager.ts
+++ b/packages/sheets-data-validation/src/models/sheet-data-validation-manager.ts
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-import type { CellValue, ISheetDataValidationRule, Nullable } from '@univerjs/core';
+import type { CellValue, ISheetDataValidationRule, Nullable, Workbook } from '@univerjs/core';
import { DataValidationManager, DataValidatorRegistryService, UpdateRuleType } from '@univerjs/data-validation';
-import { DataValidationStatus, DataValidationType, ObjectMatrix, Range } from '@univerjs/core';
+import { DataValidationStatus, DataValidationType, IUniverInstanceService, ObjectMatrix, Range, UniverInstanceType } from '@univerjs/core';
import type { IUpdateRulePayload } from '@univerjs/data-validation';
import type { ISheetLocationBase } from '@univerjs/sheets';
import type { Injector } from '@wendellhu/redi';
@@ -53,7 +53,8 @@ export class SheetDataValidationManager extends DataValidationManager<ISheetData
this._dataValidationCustomFormulaService = this._injector.get(DataValidationCustomFormulaService);
this._dataValidationRefRangeController = this._injector.get(DataValidationRefRangeController);
this._cache = this._dataValidationCacheService.ensureCache(unitId, subUnitId);
-
+ const univerInstanceService = this._injector.get(IUniverInstanceService);
+ const worksheet = univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET)!.getSheetBySheetId(subUnitId)!;
const matrix = new ObjectMatrix<string>();
rules?.forEach((rule) => {
const ruleId = rule.uid;
@@ -67,7 +68,7 @@ export class SheetDataValidationManager extends DataValidationManager<ISheetData
rules?.forEach((rule) => {
this._dataValidationRefRangeController.register(unitId, subUnitId, rule);
});
- this._ruleMatrix = new RuleMatrix(matrix);
+ this._ruleMatrix = new RuleMatrix(matrix, worksheet);
}
private _addRuleSideEffect(rule: ISheetDataValidationRule) {
diff --git a/packages/sheets-data-validation/src/validators/checkbox-validator.ts b/packages/sheets-data-validation/src/validators/checkbox-validator.ts
index 795fc59c14..f05adc825f 100644
--- a/packages/sheets-data-validation/src/validators/checkbox-validator.ts
+++ b/packages/sheets-data-validation/src/validators/checkbox-validator.ts
@@ -45,7 +45,7 @@ export class CheckboxValidator extends BaseDataValidator {
return !valueStr || (valueStr === (`${formula1}`) || valueStr === `${formula2}`);
}
- override validatorFormula(rule: IDataValidationRuleBase): IFormulaValidResult {
+ override validatorFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): IFormulaValidResult {
const { formula1, formula2 } = rule;
const formula1Success = !Tools.isBlank(formula1);
const formula2Success = !Tools.isBlank(formula2);
diff --git a/packages/sheets-data-validation/src/validators/custom-validator.ts b/packages/sheets-data-validation/src/validators/custom-validator.ts
index 2b9ef7e843..714f3fdba6 100644
--- a/packages/sheets-data-validation/src/validators/custom-validator.ts
+++ b/packages/sheets-data-validation/src/validators/custom-validator.ts
@@ -31,7 +31,7 @@ export class CustomFormulaValidator extends BaseDataValidator {
private _customFormulaService = this.injector.get(DataValidationCustomFormulaService);
- override validatorFormula(rule: IDataValidationRuleBase): IFormulaValidResult {
+ override validatorFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): IFormulaValidResult {
const success = isFormulaString(rule.formula1);
return {
success,
diff --git a/packages/sheets-data-validation/src/validators/date-validator.ts b/packages/sheets-data-validation/src/validators/date-validator.ts
index 528d9ee2d5..6a04d27a65 100644
--- a/packages/sheets-data-validation/src/validators/date-validator.ts
+++ b/packages/sheets-data-validation/src/validators/date-validator.ts
@@ -96,7 +96,7 @@ export class DateValidator extends BaseDataValidator<Dayjs> {
return !Tools.isBlank(formula) && (isFormulaString(formula) || !Number.isNaN(+formula!) || (Boolean(formula) && dayjs(formula).isValid()));
}
- override validatorFormula(rule: IDataValidationRuleBase): IFormulaValidResult {
+ override validatorFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): IFormulaValidResult {
const operator = rule.operator;
if (!operator) {
return {
@@ -217,7 +217,7 @@ export class DateValidator extends BaseDataValidator<Dayjs> {
return cellValue.isBefore(formula1) || cellValue.isSame(formula1);
}
- validatorFormulaValue(rule: IDataValidationRuleBase): string | undefined {
+ validatorFormulaValue(rule: IDataValidationRule): string | undefined {
if (!Tools.isDefine(rule.operator)) {
return undefined;
}
diff --git a/packages/sheets-data-validation/src/validators/decimal-validator.ts b/packages/sheets-data-validation/src/validators/decimal-validator.ts
index 9bbfb69bea..c0bf79499a 100644
--- a/packages/sheets-data-validation/src/validators/decimal-validator.ts
+++ b/packages/sheets-data-validation/src/validators/decimal-validator.ts
@@ -15,7 +15,7 @@
*/
import { DataValidationOperator, DataValidationType, isFormulaString, Tools } from '@univerjs/core';
-import type { CellValue, IDataValidationRule, IDataValidationRuleBase, Nullable } from '@univerjs/core';
+import type { CellValue, IDataValidationRule, Nullable } from '@univerjs/core';
import type { IFormulaResult, IFormulaValidResult, IValidatorCellInfo } from '@univerjs/data-validation';
import { BaseDataValidator } from '@univerjs/data-validation';
import { BASE_FORMULA_INPUT_NAME } from '../views/formula-input';
@@ -95,7 +95,7 @@ export class DecimalValidator extends BaseDataValidator<number> {
return info;
}
- override validatorFormula(rule: IDataValidationRuleBase): IFormulaValidResult {
+ override validatorFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): IFormulaValidResult {
const operator = rule.operator;
if (!operator) {
return {
diff --git a/packages/sheets-data-validation/src/validators/list-validator.ts b/packages/sheets-data-validation/src/validators/list-validator.ts
index 69f593875b..ddb9a0b7ed 100644
--- a/packages/sheets-data-validation/src/validators/list-validator.ts
+++ b/packages/sheets-data-validation/src/validators/list-validator.ts
@@ -14,11 +14,11 @@
* limitations under the License.
*/
-import { DataValidationRenderMode, DataValidationType, isFormulaString, IUniverInstanceService, Tools, UniverInstanceType } from '@univerjs/core';
-import type { CellValue, DataValidationOperator, ICellData, IDataValidationRule, IDataValidationRuleBase, ISheetDataValidationRule, Nullable, Workbook } from '@univerjs/core';
+import { DataValidationRenderMode, DataValidationType, isFormulaString, IUniverInstanceService, Rectangle, Tools, UniverInstanceType } from '@univerjs/core';
+import type { CellValue, DataValidationOperator, ICellData, IDataValidationRule, IRange, ISheetDataValidationRule, Nullable, Workbook } from '@univerjs/core';
import type { IBaseDataValidationWidget, IFormulaResult, IFormulaValidResult, IValidatorCellInfo } from '@univerjs/data-validation';
import { BaseDataValidator } from '@univerjs/data-validation';
-import { isReferenceString, LexerTreeBuilder, sequenceNodeType } from '@univerjs/engine-formula';
+import { deserializeRangeWithSheet, isReferenceString, LexerTreeBuilder, sequenceNodeType } from '@univerjs/engine-formula';
import { LIST_FORMULA_INPUT_NAME } from '../views/formula-input';
import { LIST_DROPDOWN_KEY } from '../views';
import { DropdownWidget } from '../widgets/dropdown-widget';
@@ -70,9 +70,24 @@ export function isValidListFormula(formula: string, lexer: LexerTreeBuilder) {
return (nodes) && nodes.some((node) => typeof node === 'object' && node.nodeType === sequenceNodeType.FUNCTION && supportedFormula.indexOf(node.token.toLowerCase()) > -1);
}
+function isRuleIntersects(rule: IDataValidationRule, sheetName: string) {
+ const { formula1 = '', ranges } = rule;
+ const isRefString = isReferenceString(formula1.slice(1));
+
+ if (isRefString) {
+ const refRange = deserializeRangeWithSheet(formula1.slice(1));
+ if ((!refRange.sheetName || refRange.sheetName === sheetName) && ranges.some((range: IRange) => Rectangle.intersects(range, refRange.range))) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
export class ListValidator extends BaseDataValidator {
protected formulaService = this.injector.get(DataValidationFormulaService);
private _lexer = this.injector.get(LexerTreeBuilder);
+ private _univerInstanceService = this.injector.get(IUniverInstanceService);
id: string = DataValidationType.LIST;
title: string = 'dataValidation.list.title';
@@ -90,15 +105,19 @@ export class ListValidator extends BaseDataValidator {
return rule.renderMode !== DataValidationRenderMode.TEXT;
}
- override validatorFormula(rule: IDataValidationRuleBase): IFormulaValidResult {
+ override validatorFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): IFormulaValidResult {
const success = !Tools.isBlank(rule.formula1);
const valid = isValidListFormula(rule.formula1 ?? '', this._lexer);
+ const sheetName = this._univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET)?.getSheetBySheetId(subUnitId)?.getName();
+ const isIntersects = isRuleIntersects(rule, sheetName ?? '');
return {
- success: Boolean(success && valid),
+ success: Boolean(success && valid && !isIntersects),
formula1: success
- ? valid ?
- undefined :
+ ? valid
+ ? !isIntersects ?
+ undefined :
+ this.localeService.t('dataValidation.validFail.listIntersects') :
this.localeService.t('dataValidation.validFail.listInvalid')
: this.localeService.t('dataValidation.validFail.list'),
};
diff --git a/packages/sheets-data-validation/src/validators/text-length-validator.ts b/packages/sheets-data-validation/src/validators/text-length-validator.ts
index 238a912a9b..1b45f1d48d 100644
--- a/packages/sheets-data-validation/src/validators/text-length-validator.ts
+++ b/packages/sheets-data-validation/src/validators/text-length-validator.ts
@@ -49,7 +49,7 @@ export class TextLengthValidator extends BaseDataValidator<number> {
return !Tools.isBlank(formula) && (isFormulaString(formula) || (!Number.isNaN(+formula) && Number.isInteger(+formula)));
}
- override validatorFormula(rule: IDataValidationRuleBase): IFormulaValidResult {
+ override validatorFormula(rule: IDataValidationRule, unitId: string, subUnitId: string): IFormulaValidResult {
const operator = rule.operator;
if (!operator) {
return {
diff --git a/packages/sheets-data-validation/src/validators/whole-validator.ts b/packages/sheets-data-validation/src/validators/whole-validator.ts
index a085baa748..48c2cc554f 100644
--- a/packages/sheets-data-validation/src/validators/whole-validator.ts
+++ b/packages/sheets-data-validation/src/validators/whole-validator.ts
@@ -82,7 +82,7 @@ export class WholeValidator extends BaseDataValidator<number> {
return info;
}
- override validatorFormula(rule: IDataValidationRuleBase): IFormulaValidResult {
+ override validatorFormula(rule: IDataValidationRuleBase, unitId: string, subUnitId: string): IFormulaValidResult {
const operator = rule.operator;
if (!operator) {
return {
diff --git a/packages/sheets-data-validation/src/views/detail/index.tsx b/packages/sheets-data-validation/src/views/detail/index.tsx
index d0a1a40357..188e3a40ac 100644
--- a/packages/sheets-data-validation/src/views/detail/index.tsx
+++ b/packages/sheets-data-validation/src/views/detail/index.tsx
@@ -83,7 +83,7 @@ export function DataValidationDetail() {
const isTwoFormula = localRule.operator ? TWO_FORMULA_OPERATOR_COUNT.includes(localRule.operator) : false;
const handleOk = () => {
- if (validator.validatorFormula(localRule).success) {
+ if (validator.validatorFormula(localRule, unitId, subUnitId).success) {
dataValidationPanelService.setActiveRule(null);
} else {
setShowError(true);
@@ -96,7 +96,6 @@ export function DataValidationDetail() {
}
setLocalRanges(unitRanges);
const ranges = unitRanges.filter((i) => (!i.unitId || i.unitId === unitId) && (!i.sheetId || i.sheetId === subUnitId)).map((i) => i.range);
-
setLocalRule({
...localRule,
ranges,
@@ -186,7 +185,7 @@ export function DataValidationDetail() {
};
const FormulaInput = componentManager.get(validator.formulaInput);
- const rangeStr = localRanges.map((i) => serializeRange(i.range)).join(',');
+ const rangeStr = useMemo(() => localRanges.map((i) => serializeRange(i.range)).join(','), []);
const options: IDataValidationRuleOptions = getRuleOptions(localRule);
@@ -276,7 +275,7 @@ export function DataValidationDetail() {
});
}}
showError={showError}
- validResult={validator.validatorFormula(localRule)}
+ validResult={validator.validatorFormula(localRule, unitId, subUnitId)}
unitId={unitId}
subUnitId={subUnitId}
ruleId={ruleId}
diff --git a/packages/sheets-data-validation/src/views/formula-input/list-formula-input.tsx b/packages/sheets-data-validation/src/views/formula-input/list-formula-input.tsx
index c2f85e26c8..7c3e490567 100644
--- a/packages/sheets-data-validation/src/views/formula-input/list-formula-input.tsx
+++ b/packages/sheets-data-validation/src/views/formula-input/list-formula-input.tsx
@@ -80,7 +80,12 @@ const ColorSelect = (props: IColorSelectProps) => {
className={styles.dataValidationFormulaColorSelect}
value={value}
onChange={onChange}
- labelRender={(item) => <div className={styles.dataValidationFormulaColorItem} style={{ background: item.value }} />}
+ labelRender={(item) => (
+ <div
+ className={styles.dataValidationFormulaColorItem}
+ style={{ background: item.value, marginTop: 5 }}
+ />
+ )}
dropdownRender={() => {
return (
<div className={styles.dataValidationFormulaColorSelectPanel}>
diff --git a/packages/sheets-data-validation/src/widgets/checkbox-widget.ts b/packages/sheets-data-validation/src/widgets/checkbox-widget.ts
index c406e3a3ee..9d33608a42 100644
--- a/packages/sheets-data-validation/src/widgets/checkbox-widget.ts
+++ b/packages/sheets-data-validation/src/widgets/checkbox-widget.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import type { IMouseEvent, IPointerEvent, UniverRenderingContext2D } from '@univerjs/engine-render';
+import type { IMouseEvent, IPointerEvent, UniverRenderingContext, UniverRenderingContext2D } from '@univerjs/engine-render';
import { Checkbox, fixLineWidthByScale, Transform } from '@univerjs/engine-render';
import { HorizontalAlign, ICommandService, isFormulaString, ThemeService, VerticalAlign } from '@univerjs/core';
import type { ICellRenderContext, IDataValidationRule, IStyleData, Nullable } from '@univerjs/core';
@@ -141,7 +141,7 @@ export class CheckboxRender implements IBaseDataValidationWidget {
const checked = String(value) === String(formula1);
const defaultColor = colors.hyacinth500;
- Checkbox.drawWith(ctx, {
+ Checkbox.drawWith(ctx as UniverRenderingContext, {
checked,
width: size,
height: size,
diff --git a/packages/sheets-data-validation/src/widgets/dropdown-multiple-widget.ts b/packages/sheets-data-validation/src/widgets/dropdown-multiple-widget.ts
index 452b9f13ee..bab5ff3dc7 100644
--- a/packages/sheets-data-validation/src/widgets/dropdown-multiple-widget.ts
+++ b/packages/sheets-data-validation/src/widgets/dropdown-multiple-widget.ts
@@ -17,7 +17,7 @@
import { HorizontalAlign, ICommandService, VerticalAlign } from '@univerjs/core';
import type { ICellRenderContext } from '@univerjs/core';
import { getFontStyleString } from '@univerjs/engine-render';
-import type { IMouseEvent, IPointerEvent, Spreadsheet, SpreadsheetSkeleton, UniverRenderingContext2D } from '@univerjs/engine-render';
+import type { IMouseEvent, IPointerEvent, Spreadsheet, SpreadsheetSkeleton, UniverRenderingContext, UniverRenderingContext2D } from '@univerjs/engine-render';
import type { IBaseDataValidationWidget } from '@univerjs/data-validation';
import type { ListMultipleValidator } from '../validators/list-multiple-validator';
import { getCellValueOrigin } from '../utils/get-cell-data-origin';
@@ -147,7 +147,7 @@ export class DropdownMultipleWidget implements IBaseDataValidationWidget {
items.forEach((item) => {
ctx.save();
ctx.translateWithPrecision(item.left, 0);
- Dropdown.drawWith(ctx, {
+ Dropdown.drawWith(ctx as UniverRenderingContext, {
...fontStyle,
info: item,
color,
diff --git a/packages/sheets-data-validation/src/widgets/dropdown-widget.ts b/packages/sheets-data-validation/src/widgets/dropdown-widget.ts
index 4b50f56e22..5fe3d680b9 100644
--- a/packages/sheets-data-validation/src/widgets/dropdown-widget.ts
+++ b/packages/sheets-data-validation/src/widgets/dropdown-widget.ts
@@ -111,6 +111,40 @@ function createDocuments(text: string, localeService: LocaleService, style?: Nul
};
}
+function calcPadding(cellWidth: number, cellHeight: number, fontWidth: number, fontHeight: number, vt: VerticalAlign, ht: HorizontalAlign) {
+ let paddingTop = 0;
+ switch (vt) {
+ case VerticalAlign.BOTTOM:
+ paddingTop = (cellHeight - (MARGIN_V * 2) - fontHeight) + MARGIN_V;
+ break;
+ case VerticalAlign.MIDDLE:
+ paddingTop = ((cellHeight - (MARGIN_V * 2) - fontHeight) / 2) + MARGIN_V;
+ break;
+
+ default:
+ paddingTop = MARGIN_V;
+ break;
+ }
+
+ let paddingLeft = 0;
+ switch (ht) {
+ case HorizontalAlign.CENTER:
+ paddingLeft = (cellWidth - fontWidth) / 2;
+ break;
+ case HorizontalAlign.RIGHT:
+ paddingLeft = (cellWidth - fontWidth);
+ break;
+
+ default:
+ break;
+ }
+
+ return {
+ paddingLeft,
+ paddingTop,
+ };
+}
+
export interface IDropdownInfo {
top: number;
left: number;
@@ -175,7 +209,7 @@ export class DropdownWidget implements IBaseDataValidationWidget {
ctx.restore();
}
- // eslint-disable-next-line max-lines-per-function, complexity
+ // eslint-disable-next-line max-lines-per-function
drawWith(ctx: UniverRenderingContext2D, info: ICellRenderContext, skeleton: SpreadsheetSkeleton): void {
const { primaryWithCoord, row, col, style, data, subUnitId } = info;
const _cellBounding = primaryWithCoord.isMergedMainCell ? primaryWithCoord.mergeInfo : primaryWithCoord;
@@ -210,9 +244,8 @@ export class DropdownWidget implements IBaseDataValidationWidget {
const valueStr = `${value ?? ''}`;
const activeItem = list.find((i) => i.label === valueStr);
let { tb, vt, ht } = style || {};
-
tb = tb ?? WrapStrategy.WRAP;
- vt = vt ?? VerticalAlign.TOP;
+ vt = vt ?? VerticalAlign.BOTTOM;
ht = ht ?? HorizontalAlign.LEFT;
if (rule.renderMode === DataValidationRenderMode.ARROW) {
this._drawDownIcon(ctx, cellBounding, cellWidth, cellHeight, vt);
@@ -236,33 +269,7 @@ export class DropdownWidget implements IBaseDataValidationWidget {
const textLayout = getDocsSkeletonPageSize(documentSkeleton)!;
const { height: fontHeight, width: fontWidth } = textLayout;
-
- let paddingTop = 0;
- switch (vt) {
- case VerticalAlign.BOTTOM:
- paddingTop = (cellHeight - MARGIN_V - fontHeight);
- break;
- case VerticalAlign.MIDDLE:
- paddingTop = (cellHeight - MARGIN_V - fontHeight) / 2;
- break;
-
- default:
- paddingTop = MARGIN_V;
- break;
- }
-
- let paddingLeft = 0;
- switch (ht) {
- case HorizontalAlign.CENTER:
- paddingLeft = (realWidth - fontWidth) / 2;
- break;
- case HorizontalAlign.RIGHT:
- paddingLeft = (realWidth - fontWidth);
- break;
-
- default:
- break;
- }
+ const { paddingTop, paddingLeft } = calcPadding(realWidth, cellHeight, fontWidth, fontHeight, vt, ht);
ctx.translate(0, paddingTop);
ctx.save();
@@ -296,36 +303,10 @@ export class DropdownWidget implements IBaseDataValidationWidget {
) {
docModel.updateDocumentDataPageSize(Math.max(realWidth, 1));
}
-
documentSkeleton.calculate();
const textLayout = getDocsSkeletonPageSize(documentSkeleton)!;
-
const { height: fontHeight, width: fontWidth } = textLayout;
- let paddingTop = 0;
- switch (vt) {
- case VerticalAlign.BOTTOM:
- paddingTop = (cellHeight - MARGIN_V - fontHeight);
- break;
- case VerticalAlign.MIDDLE:
- paddingTop = (cellHeight - MARGIN_V - fontHeight) / 2;
- break;
-
- default:
- paddingTop = MARGIN_V;
- break;
- }
- let paddingLeft = 0;
- switch (ht) {
- case HorizontalAlign.CENTER:
- paddingLeft = (realWidth - fontWidth) / 2;
- break;
- case HorizontalAlign.RIGHT:
- paddingLeft = (realWidth - fontWidth);
- break;
-
- default:
- break;
- }
+ const { paddingTop, paddingLeft } = calcPadding(realWidth, cellHeight, fontWidth, fontHeight, vt, ht);
ctx.translate(MARGIN_H, paddingTop);
const rectWidth = Math.max(cellWidth - MARGIN_H * 2, 1);
@@ -393,7 +374,7 @@ export class DropdownWidget implements IBaseDataValidationWidget {
if (rule.renderMode === DataValidationRenderMode.ARROW) {
const realWidth = cellWidth - ICON_PLACE;
- const { documentSkeleton, docModel } = createDocSkeleton(valueStr, this._localeService, style);
+ const { documentSkeleton, docModel } = createDocuments(valueStr, this._localeService, style);
if (
tb === WrapStrategy.WRAP
) {
diff --git a/packages/sheets-hyper-link-ui/src/commands/operations/sidebar.operations.ts b/packages/sheets-hyper-link-ui/src/commands/operations/sidebar.operations.ts
index 1a86109096..1056edd362 100644
--- a/packages/sheets-hyper-link-ui/src/commands/operations/sidebar.operations.ts
+++ b/packages/sheets-hyper-link-ui/src/commands/operations/sidebar.operations.ts
@@ -82,8 +82,8 @@ export const InsertHyperLinkOperation: ICommand = {
if (!selection?.primary) {
return false;
}
- const row = selection.primary.actualRow;
- const column = selection.primary.actualColumn;
+ const row = selection.primary.startRow;
+ const column = selection.primary.startColumn;
return commandService.executeCommand(OpenHyperLinkSidebarOperation.id, {
unitId: target.unitId,
subUnitId: target.subUnitId,
diff --git a/packages/sheets-hyper-link-ui/src/common/util.ts b/packages/sheets-hyper-link-ui/src/common/util.ts
index 8f6af8b184..4b38c56611 100644
--- a/packages/sheets-hyper-link-ui/src/common/util.ts
+++ b/packages/sheets-hyper-link-ui/src/common/util.ts
@@ -14,10 +14,17 @@
* limitations under the License.
*/
+import type { ICellData, Nullable } from '@univerjs/core';
+import { DEFAULT_EMPTY_DOCUMENT_VALUE } from '@univerjs/core';
+
const expression = /[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gi;
const regex = new RegExp(expression);
export function isLegalLink(link: string) {
+ if (!Number.isNaN(+link)) {
+ return false;
+ }
+
if (link.startsWith('http://localhost:3002') || link.startsWith('localhost:3002')) {
return true;
}
@@ -34,10 +41,44 @@ export function isEmail(url: string) {
return pattern.test(url);
}
-export function serializeUrl(url: string) {
- if (isLegalLink(url)) {
- return hasProtocol(url) ? url : isEmail(url) ? `mailto://${url}` : `http://${url}`;
+export function serializeUrl(urlStr: string) {
+ if (isLegalLink(urlStr)) {
+ const transformedUrl = hasProtocol(urlStr) ? urlStr : isEmail(urlStr) ? `mailto://${urlStr}` : `http://${urlStr}`;
+
+ const url = new URL(transformedUrl);
+ if (
+ url.hostname === location.hostname &&
+ url.port === location.port &&
+ url.protocol === location.protocol &&
+ url.pathname === location.pathname &&
+ url.hash &&
+ !url.search
+ ) {
+ return url.hash;
+ }
+ }
+
+ return urlStr;
+}
+
+export function getCellValueOrigin(cell: Nullable<ICellData>) {
+ if (cell === null) {
+ return '';
+ }
+
+ if (cell?.p) {
+ const body = cell?.p.body;
+
+ if (body == null) {
+ return '';
+ }
+
+ const data = body.dataStream;
+ const lastString = data.substring(data.length - 2, data.length);
+ const newDataStream = lastString === DEFAULT_EMPTY_DOCUMENT_VALUE ? data.substring(0, data.length - 2) : data;
+
+ return newDataStream;
}
- return url;
+ return cell?.v;
}
diff --git a/packages/sheets-hyper-link-ui/src/controllers/auto-fill.controller.ts b/packages/sheets-hyper-link-ui/src/controllers/auto-fill.controller.ts
index b3b69ff585..71ee08284f 100644
--- a/packages/sheets-hyper-link-ui/src/controllers/auto-fill.controller.ts
+++ b/packages/sheets-hyper-link-ui/src/controllers/auto-fill.controller.ts
@@ -102,7 +102,7 @@ export class SheetsHyperLinkAutoFillController extends Disposable {
},
});
}
- if (APPLY_TYPE.COPY === applyType) {
+ if (APPLY_TYPE.COPY === applyType || APPLY_TYPE.SERIES === applyType) {
redos.push({
id: AddHyperLinkMutation.id,
params: {
@@ -138,7 +138,6 @@ export class SheetsHyperLinkAutoFillController extends Disposable {
}
});
});
-
return {
undos,
redos,
diff --git a/packages/sheets-hyper-link-ui/src/controllers/copy-paste.controller.ts b/packages/sheets-hyper-link-ui/src/controllers/copy-paste.controller.ts
index d238417348..6ba24cb1e0 100644
--- a/packages/sheets-hyper-link-ui/src/controllers/copy-paste.controller.ts
+++ b/packages/sheets-hyper-link-ui/src/controllers/copy-paste.controller.ts
@@ -43,7 +43,6 @@ export class SheetsHyperLinkCopyPasteController extends Disposable {
this._initCopyPaste();
}
- // eslint-disable-next-line max-lines-per-function
private _initCopyPaste() {
this._sheetClipboardService.addClipboardHook({
id: SHEET_HYPER_LINK_UI_PLUGIN,
@@ -56,20 +55,7 @@ export class SheetsHyperLinkCopyPasteController extends Disposable {
},
onPastePlainText: (pasteTo: ISheetDiscreteRangeLocation, clipText: string) => {
if (isLegalLink(clipText)) {
- let text = serializeUrl(clipText);
- const url = new URL(text);
- const name = clipText;
- if (
- url.hostname === location.hostname &&
- url.port === location.port &&
- url.protocol === location.protocol &&
- url.pathname === location.pathname &&
- url.hash
- ) {
- text = url.hash;
- // const urlInfo = this._resolverService.parseHyperLink(text);
- // name = urlInfo.name || clipText;
- }
+ const text = serializeUrl(clipText);
const { range, unitId, subUnitId } = pasteTo;
const { ranges: [pasteToRange], mapFunc } = virtualizeDiscreteRanges([range]);
@@ -98,7 +84,6 @@ export class SheetsHyperLinkCopyPasteController extends Disposable {
id: newId,
row,
column,
- display: name,
payload: text,
},
},
diff --git a/packages/sheets-hyper-link-ui/src/controllers/menu.ts b/packages/sheets-hyper-link-ui/src/controllers/menu.ts
index 3385f09eb0..01e33df1c5 100644
--- a/packages/sheets-hyper-link-ui/src/controllers/menu.ts
+++ b/packages/sheets-hyper-link-ui/src/controllers/menu.ts
@@ -49,7 +49,7 @@ export const insertLinkMenuToolbarFactory = (accessor: IAccessor) => {
};
export const InsertLinkShortcut: IShortcutItem = {
- id: InsertHyperLinkOperation.id,
+ id: InsertHyperLinkToolbarOperation.id,
binding: KeyCode.K | MetaKeys.CTRL_COMMAND,
preconditions: whenSheetEditorFocused,
};
diff --git a/packages/sheets-hyper-link-ui/src/controllers/popup.controller.ts b/packages/sheets-hyper-link-ui/src/controllers/popup.controller.ts
index 4885c13ab4..7458a53f6f 100644
--- a/packages/sheets-hyper-link-ui/src/controllers/popup.controller.ts
+++ b/packages/sheets-hyper-link-ui/src/controllers/popup.controller.ts
@@ -14,17 +14,19 @@
* limitations under the License.
*/
-import { Disposable, LifecycleStages, OnLifecycle } from '@univerjs/core';
-import { HoverManagerService } from '@univerjs/sheets-ui';
+import { Disposable, LifecycleStages, OnLifecycle, Rectangle } from '@univerjs/core';
+import { HoverManagerService, SheetSkeletonManagerService } from '@univerjs/sheets-ui';
import { Inject } from '@wendellhu/redi';
import { debounceTime } from 'rxjs';
+import { IRenderManagerService } from '@univerjs/engine-render';
import { SheetsHyperLinkPopupService } from '../services/popup.service';
@OnLifecycle(LifecycleStages.Rendered, SheetsHyperLinkPopupController)
export class SheetsHyperLinkPopupController extends Disposable {
constructor(
@Inject(HoverManagerService) private readonly _hoverManagerService: HoverManagerService,
- @Inject(SheetsHyperLinkPopupService) private readonly _sheetsHyperLinkPopupService: SheetsHyperLinkPopupService
+ @Inject(SheetsHyperLinkPopupService) private readonly _sheetsHyperLinkPopupService: SheetsHyperLinkPopupService,
+ @Inject(IRenderManagerService) private readonly _renderManagerService: IRenderManagerService
) {
super();
@@ -39,7 +41,30 @@ export class SheetsHyperLinkPopupController extends Disposable {
return;
}
- this._sheetsHyperLinkPopupService.showPopup(currentCell.location);
+ const skeleton = this._renderManagerService.getRenderById(currentCell.location.unitId)
+ ?.with(SheetSkeletonManagerService)
+ .getUnitSkeleton(currentCell.location.unitId, currentCell.location.subUnitId)
+ ?.skeleton;
+
+ const currentCol = currentCell.location.col;
+ const currentRow = currentCell.location.row;
+ let targetRow = currentRow;
+ let targetCol = currentCol;
+
+ if (skeleton) {
+ skeleton.overflowCache.forValue((row, col, value) => {
+ if (Rectangle.contains(value, { startColumn: currentCol, endColumn: currentCol, startRow: currentRow, endRow: currentRow })) {
+ targetRow = row;
+ targetCol = col;
+ }
+ });
+ }
+
+ this._sheetsHyperLinkPopupService.showPopup({
+ ...currentCell.location,
+ row: targetRow,
+ col: targetCol,
+ });
})
);
}
diff --git a/packages/sheets-hyper-link-ui/src/controllers/ref-range.controller.ts b/packages/sheets-hyper-link-ui/src/controllers/ref-range.controller.ts
deleted file mode 100644
index e4cbb48240..0000000000
--- a/packages/sheets-hyper-link-ui/src/controllers/ref-range.controller.ts
+++ /dev/null
@@ -1,237 +0,0 @@
-/**
- * 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 { IRange } from '@univerjs/core';
-import { Disposable, isValidRange, IUniverInstanceService, LifecycleStages, OnLifecycle, toDisposable } from '@univerjs/core';
-import type { EffectRefRangeParams } from '@univerjs/sheets';
-import { handleDefaultRangeChangeWithEffectRefCommands, RefRangeService } from '@univerjs/sheets';
-import type { IAddHyperLinkMutationParams, ICellHyperLink, IRemoveHyperLinkMutationParams, IUpdateHyperLinkMutationParams, IUpdateHyperLinkRefMutationParams } from '@univerjs/sheets-hyper-link';
-import { AddHyperLinkMutation, HyperLinkModel, RemoveHyperLinkMutation, UpdateHyperLinkMutation, UpdateHyperLinkRefMutation } from '@univerjs/sheets-hyper-link';
-import type { IDisposable } from '@wendellhu/redi';
-import { Inject } from '@wendellhu/redi';
-import { deserializeRangeWithSheet, serializeRange } from '@univerjs/engine-formula';
-import { SheetsHyperLinkResolverService } from '../services/resolver.service';
-import { ERROR_RANGE } from '../types/const';
-
-@OnLifecycle(LifecycleStages.Starting, SheetsHyperLinkRefRangeController)
-export class SheetsHyperLinkRefRangeController extends Disposable {
- private _disposableMap = new Map<string, IDisposable>();
- private _rangeDisableMap = new Map<string, IDisposable>();
-
- constructor(
- @Inject(RefRangeService) private readonly _refRangeService: RefRangeService,
- @Inject(HyperLinkModel) private readonly _hyperLinkModel: HyperLinkModel,
- @Inject(SheetsHyperLinkResolverService) private readonly _resolverService: SheetsHyperLinkResolverService,
- @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService
- ) {
- super();
- this._initData();
- this._initRefRange();
- }
-
- private _register(unitId: string, subUnitId: string, link: ICellHyperLink) {
- const id = link.id;
- const oldRange: IRange = {
- startColumn: link.column,
- endColumn: link.column,
- startRow: link.row,
- endRow: link.row,
- };
-
- const handleRangeChange = (commandInfo: EffectRefRangeParams) => {
- const resultRange = handleDefaultRangeChangeWithEffectRefCommands(oldRange, commandInfo);
- if (resultRange && resultRange.startColumn === oldRange.startColumn && resultRange.startRow === oldRange.startRow) {
- return {
- undos: [],
- redos: [],
- };
- }
-
- if (!resultRange) {
- return {
- redos: [{
- id: RemoveHyperLinkMutation.id,
- params: {
- unitId,
- subUnitId,
- id: link.id,
- } as IRemoveHyperLinkMutationParams,
- }],
- undos: [{
- id: AddHyperLinkMutation.id,
- params: {
- unitId,
- subUnitId,
- link,
- } as IAddHyperLinkMutationParams,
- }],
- };
- }
- return {
- redos: [{
- id: UpdateHyperLinkRefMutation.id,
- params: {
- unitId,
- subUnitId,
- id: link.id,
- row: resultRange.startRow,
- column: resultRange.startColumn,
- } as IUpdateHyperLinkRefMutationParams,
- }],
- undos: [{
- id: UpdateHyperLinkRefMutation.id,
- params: {
- unitId,
- subUnitId,
- id: link.id,
- row: oldRange.startRow,
- column: oldRange.startColumn,
- } as IUpdateHyperLinkRefMutationParams,
- }],
- };
- };
-
- this._disposableMap.set(
- id,
- this._refRangeService.registerRefRange(oldRange, handleRangeChange, unitId, subUnitId)
- );
- }
-
- private _unregister(id: string) {
- const disposable = this._disposableMap.get(id);
- disposable?.dispose();
- this._disposableMap.delete(id);
- }
-
- private _registerRange(unitId: string, id: string, payload: string) {
- const linkInfo = this._resolverService.parseHyperLink(payload);
- if (linkInfo.searchObj && linkInfo.searchObj.range && linkInfo.searchObj.gid) {
- const subUnitId = linkInfo.searchObj.gid;
- const range = deserializeRangeWithSheet(linkInfo.searchObj.range).range;
-
- if (isValidRange(range) && linkInfo.searchObj.range !== ERROR_RANGE) {
- const handleRangeChange = (commandInfo: EffectRefRangeParams) => {
- const resultRange = handleDefaultRangeChangeWithEffectRefCommands(range, commandInfo);
- if (resultRange && serializeRange(resultRange) === serializeRange(range)) {
- return {
- redos: [],
- undos: [],
- };
- }
-
- return {
- redos: [{
- id: UpdateHyperLinkMutation.id,
- params: {
- unitId,
- subUnitId,
- id,
- payload: {
- payload: `#gid=${subUnitId}&range=${resultRange ? serializeRange(resultRange) : 'err'}`,
- },
- } as IUpdateHyperLinkMutationParams,
- }],
- undos: [{
- id: UpdateHyperLinkMutation.id,
- params: {
- unitId,
- subUnitId,
- id,
- payload: {
- payload,
- },
- } as IUpdateHyperLinkMutationParams,
- }],
- };
- };
- this._rangeDisableMap.set(id, this._refRangeService.registerRefRange(range, handleRangeChange, unitId, subUnitId));
- }
- }
- }
-
- private _unregisterRange(id: string) {
- const disposable = this._rangeDisableMap.get(id);
- disposable?.dispose();
- this._rangeDisableMap.delete(id);
- }
-
- private _initData() {
- const data = this._hyperLinkModel.getAll();
-
- data.forEach((unitData) => {
- unitData.forEach((subUnitData) => {
- const { unitId, subUnitId, links } = subUnitData;
-
- links.forEach((link) => {
- this._register(unitId, subUnitId, link);
- });
- });
- });
- }
-
- private _initRefRange() {
- this.disposeWithMe(
- this._hyperLinkModel.linkUpdate$.subscribe((option) => {
- switch (option.type) {
- case 'add': {
- this._register(option.unitId, option.subUnitId, option.payload);
- this._registerRange(option.unitId, option.payload.id, option.payload.payload);
- break;
- }
- case 'remove': {
- this._unregister(option.payload.id);
- this._unregisterRange(option.payload.id);
- break;
- }
- case 'updateRef': {
- const { unitId, subUnitId, id } = option;
- const link = this._hyperLinkModel.getHyperLink(unitId, subUnitId, id);
- if (!link) {
- return;
- }
-
- this._unregister(id);
- this._register(unitId, subUnitId, link);
- break;
- }
- case 'unload': {
- const { unitLinks } = option;
- unitLinks.forEach((subUnitData) => {
- const { links } = subUnitData;
- links.forEach((link) => {
- this._unregister(link.id);
- this._unregisterRange(link.id);
- });
- });
- break;
- }
- case 'update': {
- this._unregisterRange(option.id);
- this._registerRange(option.unitId, option.id, option.payload.payload);
- break;
- }
- }
- })
- );
-
- this.disposeWithMe(toDisposable(() => {
- this._disposableMap.forEach((item) => {
- item.dispose();
- });
- this._disposableMap.clear();
- }));
- }
-}
diff --git a/packages/sheets-hyper-link-ui/src/controllers/set-range.controller.ts b/packages/sheets-hyper-link-ui/src/controllers/set-range.controller.ts
index ca4ff51257..5fab1a0c9e 100644
--- a/packages/sheets-hyper-link-ui/src/controllers/set-range.controller.ts
+++ b/packages/sheets-hyper-link-ui/src/controllers/set-range.controller.ts
@@ -19,8 +19,8 @@ import { CellValueType, Disposable, IUniverInstanceService, LifecycleStages, Obj
import { Inject, Injector } from '@wendellhu/redi';
import type { ISetRangeValuesMutationParams } from '@univerjs/sheets';
import { ClearSelectionAllCommand, ClearSelectionContentCommand, getSheetCommandTarget, SelectionManagerService, SetRangeValuesCommand, SetRangeValuesMutation, SetRangeValuesUndoMutationFactory, SheetInterceptorService } from '@univerjs/sheets';
-import type { IAddHyperLinkCommandParams, IUpdateHyperLinkCommandParams, IUpdateHyperLinkMutationParams } from '@univerjs/sheets-hyper-link';
-import { AddHyperLinkCommand, AddHyperLinkMutation, HyperLinkModel, RemoveHyperLinkMutation, UpdateHyperLinkCommand, UpdateHyperLinkMutation } from '@univerjs/sheets-hyper-link';
+import type { IAddHyperLinkCommandParams, IUpdateHyperLinkCommandParams } from '@univerjs/sheets-hyper-link';
+import { AddHyperLinkCommand, AddHyperLinkMutation, HyperLinkModel, RemoveHyperLinkMutation, UpdateHyperLinkCommand } from '@univerjs/sheets-hyper-link';
import { isLegalLink, serializeUrl } from '../common/util';
@OnLifecycle(LifecycleStages.Starting, SheetHyperLinkSetRangeController)
@@ -130,11 +130,9 @@ export class SheetHyperLinkSetRangeController extends Disposable {
}));
}
- // eslint-disable-next-line max-lines-per-function
private _initSetRangeValuesCommandInterceptor() {
this.disposeWithMe(this._sheetInterceptorService.interceptCommand({
- // eslint-disable-next-line max-lines-per-function
getMutations: (command) => {
if (command.id === SetRangeValuesCommand.id) {
const params = command.params as ISetRangeValuesMutationParams;
@@ -143,11 +141,10 @@ export class SheetHyperLinkSetRangeController extends Disposable {
const redos: IMutationInfo[] = [];
const undos: IMutationInfo[] = [];
if (params.cellValue) {
- // eslint-disable-next-line max-lines-per-function
new ObjectMatrix(params.cellValue).forValue((row, col, cell) => {
- const cellValue = (cell?.v ?? cell?.p?.body?.dataStream.slice(0, -2) ?? '').toString();
+ const cellValueRaw = cell?.v ?? cell?.p?.body?.dataStream.slice(0, -2);
+ const cellValue = (cellValueRaw ?? '').toString();
const link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, col);
-
if (!link) {
if (isLegalLink(cellValue)) {
const id = Tools.generateRandomId();
@@ -177,11 +174,7 @@ export class SheetHyperLinkSetRangeController extends Disposable {
return;
}
- if (link.display === cellValue) {
- return;
- }
-
- if (!cellValue) {
+ if (cellValueRaw === '') {
redos.push({
id: RemoveHyperLinkMutation.id,
params: {
@@ -199,33 +192,6 @@ export class SheetHyperLinkSetRangeController extends Disposable {
},
});
}
-
- const redoParams: IUpdateHyperLinkMutationParams = {
- unitId,
- subUnitId,
- id: link.id,
- payload: {
- payload: link.payload,
- display: cellValue,
- },
- };
- const undoParams: IUpdateHyperLinkMutationParams = {
- unitId,
- subUnitId,
- id: link.id,
- payload: {
- payload: link.payload,
- display: link.display,
- },
- };
- redos.push({
- id: UpdateHyperLinkMutation.id,
- params: redoParams,
- });
- undos.push({
- id: UpdateHyperLinkMutation.id,
- params: undoParams,
- });
});
}
diff --git a/packages/sheets-hyper-link-ui/src/index.ts b/packages/sheets-hyper-link-ui/src/index.ts
index e219c96fbc..e8f1a75b4a 100644
--- a/packages/sheets-hyper-link-ui/src/index.ts
+++ b/packages/sheets-hyper-link-ui/src/index.ts
@@ -15,7 +15,6 @@
*/
export { SheetsHyperLinkRemoveSheetController } from './controllers/remove-sheet.controller';
-export { SheetsHyperLinkRefRangeController } from './controllers/ref-range.controller';
export { SheetsHyperLinkRenderManagerController, SheetsHyperLinkRenderController } from './controllers/render-controllers/render.controller';
export { SheetsHyperLinkPopupService } from './services/popup.service';
export { SheetsHyperLinkResolverService } from './services/resolver.service';
diff --git a/packages/sheets-hyper-link-ui/src/plugin.ts b/packages/sheets-hyper-link-ui/src/plugin.ts
index 086b181955..d68b4ea909 100644
--- a/packages/sheets-hyper-link-ui/src/plugin.ts
+++ b/packages/sheets-hyper-link-ui/src/plugin.ts
@@ -20,7 +20,6 @@ import { DependentOn, Plugin, UniverInstanceType } from '@univerjs/core';
import { UniverSheetsHyperLinkPlugin } from '@univerjs/sheets-hyper-link';
import { IRenderManagerService } from '@univerjs/engine-render';
import { SheetsHyperLinkRemoveSheetController } from './controllers/remove-sheet.controller';
-import { SheetsHyperLinkRefRangeController } from './controllers/ref-range.controller';
import { SheetsHyperLinkRenderController, SheetsHyperLinkRenderManagerController } from './controllers/render-controllers/render.controller';
import { SheetsHyperLinkPopupService } from './services/popup.service';
import { SheetsHyperLinkResolverService } from './services/resolver.service';
@@ -53,7 +52,6 @@ export class UniverSheetsHyperLinkUIPlugin extends Plugin {
[SheetsHyperLinkPopupService],
[SheetsHyperLinkRemoveSheetController],
- [SheetsHyperLinkRefRangeController],
[SheetsHyperLinkRenderManagerController],
[SheetHyperLinkSetRangeController],
[SheetsHyperLinkPopupController],
diff --git a/packages/sheets-hyper-link-ui/src/services/popup.service.ts b/packages/sheets-hyper-link-ui/src/services/popup.service.ts
index f7a9f1f2e8..e7c28e19f1 100644
--- a/packages/sheets-hyper-link-ui/src/services/popup.service.ts
+++ b/packages/sheets-hyper-link-ui/src/services/popup.service.ts
@@ -20,6 +20,7 @@ import { SheetCanvasPopManagerService } from '@univerjs/sheets-ui';
import type { IDisposable } from '@wendellhu/redi';
import { Inject } from '@wendellhu/redi';
import { BehaviorSubject, Subject } from 'rxjs';
+import { Disposable } from '@univerjs/core';
import { CellLinkPopup } from '../views/CellLinkPopup';
interface IHyperLinkPopup {
@@ -27,6 +28,8 @@ interface IHyperLinkPopup {
subUnitId: string;
id: string;
disposable?: IDisposable;
+ row: number;
+ col: number;
}
interface IHyperLinkEditing {
@@ -36,7 +39,11 @@ interface IHyperLinkEditing {
column: number;
}
-export class SheetsHyperLinkPopupService {
+const isEqualLink = (a: ISheetLocationBase, b: ISheetLocationBase) => {
+ return a.unitId === b.unitId && a.subUnitId === b.subUnitId && a.row === b.row && a.col === b.col;
+};
+
+export class SheetsHyperLinkPopupService extends Disposable {
private _currentPopup: IHyperLinkPopup | null = null;
private _currentPopup$ = new Subject<IHyperLinkPopup | null>();
currentPopup$ = this._currentPopup$.asObservable();
@@ -55,11 +62,26 @@ export class SheetsHyperLinkPopupService {
constructor(
@Inject(HyperLinkModel) private readonly _hyperLinkModel: HyperLinkModel,
@Inject(SheetCanvasPopManagerService) private readonly _sheetCanvasPopManagerService: SheetCanvasPopManagerService
- ) {}
+ ) {
+ super();
+
+ this.disposeWithMe(() => {
+ this.hideCurrentPopup();
+ this.endEditing();
+
+ this._currentEditing$.complete();
+ this._currentPopup$.complete();
+ });
+ }
showPopup(location: ISheetLocationBase) {
+ if (this._currentPopup && isEqualLink(location, this._currentPopup)) {
+ return;
+ }
+
this.hideCurrentPopup();
const { unitId, subUnitId, row, col } = location;
+
const link = this._hyperLinkModel.getHyperLinkByLocation(unitId, subUnitId, row, col);
if (!link) {
return;
@@ -76,6 +98,8 @@ export class SheetsHyperLinkPopupService {
subUnitId,
id: link.id,
disposable,
+ row,
+ col,
};
this._currentPopup$.next(this._currentPopup);
}
diff --git a/packages/sheets-hyper-link-ui/src/services/resolver.service.ts b/packages/sheets-hyper-link-ui/src/services/resolver.service.ts
index 46fc927bf3..6cfddc320e 100644
--- a/packages/sheets-hyper-link-ui/src/services/resolver.service.ts
+++ b/packages/sheets-hyper-link-ui/src/services/resolver.service.ts
@@ -14,16 +14,16 @@
* limitations under the License.
*/
-import type { IRange, Workbook } from '@univerjs/core';
-import { ICommandService, isValidRange, IUniverInstanceService, LocaleService, Rectangle, UniverInstanceType } from '@univerjs/core';
+import type { IRange, Workbook, Worksheet } from '@univerjs/core';
+import { ICommandService, isValidRange, IUniverInstanceService, LocaleService, RANGE_TYPE, Rectangle, UniverInstanceType } from '@univerjs/core';
import { MessageType } from '@univerjs/design';
import { deserializeRangeWithSheet, IDefinedNamesService, serializeRangeWithSheet } from '@univerjs/engine-formula';
import type { ISetSelectionsOperationParams } from '@univerjs/sheets';
import { NORMAL_SELECTION_PLUGIN_NAME, SetSelectionsOperation, SetWorksheetActiveOperation } from '@univerjs/sheets';
-import { ScrollToCellCommand } from '@univerjs/sheets-ui';
+import { ERROR_RANGE } from '@univerjs/sheets-hyper-link';
+import { ScrollToRangeOperation } from '@univerjs/sheets-ui';
import { IMessageService } from '@univerjs/ui';
import { Inject } from '@wendellhu/redi';
-import { ERROR_RANGE } from '../types/const';
interface ISheetUrlParams {
gid?: string;
@@ -31,7 +31,22 @@ interface ISheetUrlParams {
rangeid?: string;
}
-function getContainRange(range: IRange, mergedCells: IRange[]) {
+function getContainRange(range: IRange, worksheet: Worksheet) {
+ const mergedCells = worksheet.getMergeData();
+ const maxCol = worksheet.getMaxColumns() - 1;
+ const maxRow = worksheet.getMaxRows() - 1;
+ if (maxCol < range.endColumn) {
+ range.endColumn = maxCol;
+ }
+
+ if (maxRow < range.endRow) {
+ range.endRow = maxRow;
+ }
+
+ if (range.rangeType === RANGE_TYPE.COLUMN || RANGE_TYPE.ROW) {
+ return range;
+ }
+
const relativeCells: IRange[] = [];
mergedCells.forEach((cell) => {
if (Rectangle.intersects(range, cell)) {
@@ -169,7 +184,7 @@ export class SheetsHyperLinkResolverService {
async navigateToRange(unitId: string, subUnitId: string, range: IRange) {
const worksheet = await this.navigateToSheetById(unitId, subUnitId);
if (worksheet) {
- const realRange = getContainRange(range, worksheet.getMergeData());
+ const realRange = getContainRange(range, worksheet);
await this._commandService.executeCommand(
SetSelectionsOperation.id,
{
@@ -177,12 +192,11 @@ export class SheetsHyperLinkResolverService {
subUnitId,
pluginName: NORMAL_SELECTION_PLUGIN_NAME,
selections: [{
-
range: realRange,
}],
} as ISetSelectionsOperationParams
);
- await this._commandService.executeCommand(ScrollToCellCommand.id, {
+ await this._commandService.executeCommand(ScrollToRangeOperation.id, {
range: realRange,
});
}
diff --git a/packages/sheets-hyper-link-ui/src/types/const.ts b/packages/sheets-hyper-link-ui/src/types/const.ts
index 8a2f6419c3..08dabe0648 100644
--- a/packages/sheets-hyper-link-ui/src/types/const.ts
+++ b/packages/sheets-hyper-link-ui/src/types/const.ts
@@ -15,5 +15,3 @@
*/
export const SHEET_HYPER_LINK_UI_PLUGIN = 'SHEET_HYPER_LINK_UI_PLUGIN';
-
-export const ERROR_RANGE = 'err';
diff --git a/packages/sheets-hyper-link-ui/src/views/CellLinkEdit/index.tsx b/packages/sheets-hyper-link-ui/src/views/CellLinkEdit/index.tsx
index 14fa63ffc5..b224bc6092 100644
--- a/packages/sheets-hyper-link-ui/src/views/CellLinkEdit/index.tsx
+++ b/packages/sheets-hyper-link-ui/src/views/CellLinkEdit/index.tsx
@@ -17,17 +17,17 @@
import React, { useEffect, useMemo, useRef, useState } from 'react';
import { Button, FormLayout, Input, Select } from '@univerjs/design';
import { useDependency } from '@wendellhu/redi/react-bindings';
-import type { ICellData, Nullable, Workbook } from '@univerjs/core';
-import { createInternalEditorID, DEFAULT_EMPTY_DOCUMENT_VALUE, ICommandService, isValidRange, IUniverInstanceService, LocaleService, Tools, UniverInstanceType } from '@univerjs/core';
-import { RangeSelector, useObservable } from '@univerjs/ui';
+import type { IUnitRangeWithName, Workbook } from '@univerjs/core';
+import { createInternalEditorID, ICommandService, isValidRange, IUniverInstanceService, LocaleService, Tools, UniverInstanceType } from '@univerjs/core';
+import { RangeSelector, useEvent, useObservable } from '@univerjs/ui';
import { deserializeRangeWithSheet, IDefinedNamesService, serializeRange, serializeRangeToRefString, serializeRangeWithSheet } from '@univerjs/engine-formula';
-import { AddHyperLinkCommand, HyperLinkModel, UpdateHyperLinkCommand } from '@univerjs/sheets-hyper-link';
+import { AddHyperLinkCommand, ERROR_RANGE, HyperLinkModel, UpdateHyperLinkCommand } from '@univerjs/sheets-hyper-link';
import { SetWorksheetActiveOperation } from '@univerjs/sheets';
-import { ScrollToCellCommand } from '@univerjs/sheets-ui';
+import { ScrollToRangeOperation } from '@univerjs/sheets-ui';
import { SheetsHyperLinkPopupService } from '../../services/popup.service';
import { SheetsHyperLinkResolverService } from '../../services/resolver.service';
import { CloseHyperLinkSidebarOperation } from '../../commands/operations/sidebar.operations';
-import { hasProtocol, isLegalLink } from '../../common/util';
+import { getCellValueOrigin, isLegalLink, serializeUrl } from '../../common/util';
import styles from './index.module.less';
enum LinkType {
@@ -37,28 +37,6 @@ enum LinkType {
definedName = 'rangeid',
}
-function getCellValueOrigin(cell: Nullable<ICellData>) {
- if (cell === null) {
- return '';
- }
-
- if (cell?.p) {
- const body = cell?.p.body;
-
- if (body == null) {
- return '';
- }
-
- const data = body.dataStream;
- const lastString = data.substring(data.length - 2, data.length);
- const newDataStream = lastString === DEFAULT_EMPTY_DOCUMENT_VALUE ? data.substring(0, data.length - 2) : data;
-
- return newDataStream;
- }
-
- return cell?.v;
-}
-
export const CellLinkEdit = () => {
const [id, setId] = useState('');
const [display, setDisplay] = useState('');
@@ -78,7 +56,7 @@ export const CellLinkEdit = () => {
useEffect(() => {
if (editing?.row !== undefined && editing.column !== undefined) {
- const link = hyperLinkModel.getHyperLinkByLocation(editing.unitId, editing.subUnitId, editing.row, editing.column);
+ const link = hyperLinkModel.getHyperLinkByLocationSync(editing.unitId, editing.subUnitId, editing.row, editing.column);
if (link) {
const linkInfo = resolverService.parseHyperLink(link.payload);
setId(link.id);
@@ -86,12 +64,16 @@ export const CellLinkEdit = () => {
if (linkInfo.type === 'outer') {
setType(LinkType.link);
setPayload(linkInfo.url);
+ if (linkInfo.url === link.display) {
+ setByPayload.current = true;
+ }
return;
} else {
const params = linkInfo.searchObj;
if (params.rangeid) {
setType(LinkType.definedName);
setPayload(params.rangeid);
+
return;
}
@@ -104,7 +86,16 @@ export const CellLinkEdit = () => {
?? ''
: '';
setType(LinkType.range);
- setPayload(serializeRangeWithSheet(sheetName, deserializeRangeWithSheet(params.range).range));
+ if (params.range === ERROR_RANGE) {
+ setPayload('');
+ } else {
+ const payload = (serializeRangeWithSheet(sheetName, deserializeRangeWithSheet(params.range).range));
+ setPayload(payload);
+ if (payload === link.display) {
+ setByPayload.current = true;
+ }
+ }
+
return;
}
@@ -166,7 +157,7 @@ export const CellLinkEdit = () => {
const formatUrl = (type: LinkType, payload: string) => {
if (type === LinkType.link) {
- return hasProtocol(payload) ? payload : `http://${payload}`;
+ return serializeUrl(payload);
}
if (type === LinkType.range) {
@@ -180,6 +171,23 @@ export const CellLinkEdit = () => {
return `#${type}=${payload}`;
};
+ const handleRangeChange = useEvent((newValue: IUnitRangeWithName[]) => {
+ const range = newValue[0];
+ if (!range || !isValidRange(range.range)) {
+ return;
+ }
+ if (!range.sheetName) {
+ range.sheetName = workbook.getActiveSheet().getName();
+ }
+ const newPayload = serializeRangeToRefString(range);
+ setPayload(newPayload);
+
+ if (newPayload && (setByPayload.current || !display)) {
+ setDisplay(newPayload);
+ setByPayload.current = true;
+ }
+ });
+
const handleSubmit = async () => {
if (editing) {
if (id) {
@@ -212,12 +220,13 @@ export const CellLinkEdit = () => {
subUnitId: editing.subUnitId,
});
- await commandService.executeCommand(ScrollToCellCommand.id, {
+ const GAP = 5;
+ await commandService.executeCommand(ScrollToRangeOperation.id, {
range: {
- startRow: editing.row,
- endRow: editing.row,
- startColumn: editing.column,
- endColumn: editing.column,
+ startRow: Math.max(editing.row - GAP, 0),
+ endRow: editing.row + GAP,
+ startColumn: Math.max(editing.column - GAP, 0),
+ endColumn: editing.column + GAP,
},
});
}
@@ -258,7 +267,7 @@ export const CellLinkEdit = () => {
value={payload}
onChange={(newLink) => {
setPayload(newLink);
- if (newLink && (setByPayload.current || !display)) {
+ if (newLink && (setByPayload.current || !display || display === payload)) {
setDisplay(newLink);
setByPayload.current = true;
}
@@ -274,23 +283,7 @@ export const CellLinkEdit = () => {
id={createInternalEditorID('hyper-link-edit')}
isSingleChoice
value={payloadInitial}
- onChange={(newValue) => {
- const range = newValue[0];
- if (!range || !isValidRange(range.range)) {
- return;
- }
- if (!range.sheetName) {
- range.sheetName = workbook.getActiveSheet().getName();
- }
- const newPayload = serializeRangeToRefString(range);
- setPayload(newPayload);
-
- if (newPayload && (setByPayload.current || !display)) {
- setDisplay(newPayload);
- setByPayload.current = true;
- }
- }}
-
+ onChange={handleRangeChange}
/>
</FormLayout>
)}
@@ -302,7 +295,8 @@ export const CellLinkEdit = () => {
onChange={(newPayload) => {
setPayload(newPayload);
const label = sheetsOption.find((i) => i.value === newPayload)?.label;
- if (label && (setByPayload.current || !display)) {
+ const oldLabel = sheetsOption.find((i) => i.value === payload)?.label;
+ if (label && (setByPayload.current || !display || display === oldLabel)) {
setDisplay(label);
setByPayload.current = true;
}
@@ -318,7 +312,8 @@ export const CellLinkEdit = () => {
onChange={(newValue) => {
setPayload(newValue);
const label = definedNames.find((i) => i.value === newValue)?.label;
- if (label && (setByPayload.current || !display)) {
+ const oldLabel = definedNames.find((i) => i.value === payload)?.label;
+ if (label && (setByPayload.current || !display || display === oldLabel)) {
setDisplay(label);
setByPayload.current = true;
}
diff --git a/packages/sheets-hyper-link/package.json b/packages/sheets-hyper-link/package.json
index 3dffc92d25..f5d1446d82 100644
--- a/packages/sheets-hyper-link/package.json
+++ b/packages/sheets-hyper-link/package.json
@@ -58,12 +58,17 @@
},
"peerDependencies": {
"@univerjs/core": "workspace:*",
+ "@univerjs/engine-formula": "workspace:*",
"@univerjs/sheets": "workspace:*",
"@wendellhu/redi": "0.15.2",
"rxjs": ">=7.0.0"
+ },
+ "dependencies": {
+
},
"devDependencies": {
"@univerjs/core": "workspace:*",
+ "@univerjs/engine-formula": "workspace:*",
"@univerjs/protocol": "^0.1.36",
"@univerjs/shared": "workspace:*",
"@univerjs/sheets": "workspace:*",
diff --git a/packages/sheets-hyper-link/src/commands/mutations/update-hyper-link.mutation.ts b/packages/sheets-hyper-link/src/commands/mutations/update-hyper-link.mutation.ts
index 6725d241a8..0da2ba1ecf 100644
--- a/packages/sheets-hyper-link/src/commands/mutations/update-hyper-link.mutation.ts
+++ b/packages/sheets-hyper-link/src/commands/mutations/update-hyper-link.mutation.ts
@@ -46,6 +46,7 @@ export interface IUpdateHyperLinkRefMutationParams {
id: string;
row: number;
column: number;
+ silent?: boolean;
}
export const UpdateHyperLinkRefMutation: ICommand<IUpdateHyperLinkRefMutationParams> = {
@@ -57,7 +58,7 @@ export const UpdateHyperLinkRefMutation: ICommand<IUpdateHyperLinkRefMutationPar
}
const model = accessor.get(HyperLinkModel);
- const { unitId, subUnitId, id, row, column } = params;
- return model.updateHyperLinkRef(unitId, subUnitId, id, { row, column });
+ const { unitId, subUnitId, id, row, column, silent } = params;
+ return model.updateHyperLinkRef(unitId, subUnitId, id, { row, column }, silent);
},
};
diff --git a/packages/sheets-hyper-link/src/controllers/ref-range.controller.ts b/packages/sheets-hyper-link/src/controllers/ref-range.controller.ts
new file mode 100644
index 0000000000..57c9d7577e
--- /dev/null
+++ b/packages/sheets-hyper-link/src/controllers/ref-range.controller.ts
@@ -0,0 +1,303 @@
+/**
+ * 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 { IRange, Nullable } from '@univerjs/core';
+import { Disposable, ICommandService, isValidRange, LifecycleStages, OnLifecycle, sequenceExecuteAsync, toDisposable } from '@univerjs/core';
+import type { EffectRefRangeParams } from '@univerjs/sheets';
+import { handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests, RefRangeService, SelectionManagerService } from '@univerjs/sheets';
+import type { IAddHyperLinkMutationParams, ICellHyperLink, IRemoveHyperLinkMutationParams, IUpdateHyperLinkMutationParams, IUpdateHyperLinkRefMutationParams } from '@univerjs/sheets-hyper-link';
+import { AddHyperLinkMutation, HyperLinkModel, RemoveHyperLinkMutation, UpdateHyperLinkMutation, UpdateHyperLinkRefMutation } from '@univerjs/sheets-hyper-link';
+import type { IDisposable } from '@wendellhu/redi';
+import { Inject } from '@wendellhu/redi';
+import { deserializeRangeWithSheet, serializeRange } from '@univerjs/engine-formula';
+import { ERROR_RANGE } from '../types/const';
+
+@OnLifecycle(LifecycleStages.Starting, SheetsHyperLinkRefRangeController)
+export class SheetsHyperLinkRefRangeController extends Disposable {
+ private _disposableMap = new Map<string, IDisposable>();
+ private _watchDisposableMap = new Map<string, IDisposable>();
+ private _rangeDisableMap = new Map<string, IDisposable>();
+ private _rangeWatcherMap = new Map<string, IDisposable>();
+
+ constructor(
+ @Inject(RefRangeService) private readonly _refRangeService: RefRangeService,
+ @Inject(HyperLinkModel) private readonly _hyperLinkModel: HyperLinkModel,
+ @Inject(SelectionManagerService) private readonly _selectionManagerService: SelectionManagerService,
+ @ICommandService private readonly _commandService: ICommandService
+ ) {
+ super();
+ this._initData();
+ this._initRefRange();
+ }
+
+ private _handlePositionChange = (unitId: string, subUnitId: string, link: ICellHyperLink, resultRange: Nullable<IRange>, silent: boolean) => {
+ const oldRange: IRange = {
+ startColumn: link.column,
+ endColumn: link.column,
+ startRow: link.row,
+ endRow: link.row,
+ };
+
+ if (!resultRange) {
+ return {
+ redos: [{
+ id: RemoveHyperLinkMutation.id,
+ params: {
+ unitId,
+ subUnitId,
+ id: link.id,
+ } as IRemoveHyperLinkMutationParams,
+ }],
+ undos: [{
+ id: AddHyperLinkMutation.id,
+ params: {
+ unitId,
+ subUnitId,
+ link,
+ } as IAddHyperLinkMutationParams,
+ }],
+ };
+ }
+ return {
+ redos: [{
+ id: UpdateHyperLinkRefMutation.id,
+ params: {
+ unitId,
+ subUnitId,
+ id: link.id,
+ row: resultRange.startRow,
+ column: resultRange.startColumn,
+ silent,
+ } as IUpdateHyperLinkRefMutationParams,
+ }],
+ undos: [{
+ id: UpdateHyperLinkRefMutation.id,
+ params: {
+ unitId,
+ subUnitId,
+ id: link.id,
+ row: oldRange.startRow,
+ column: oldRange.startColumn,
+ silent,
+ } as IUpdateHyperLinkRefMutationParams,
+ }],
+ };
+ };
+
+ private _registerPosition(unitId: string, subUnitId: string, link: ICellHyperLink) {
+ const id = link.id;
+ const oldRange: IRange = {
+ startColumn: link.column,
+ endColumn: link.column,
+ startRow: link.row,
+ endRow: link.row,
+ };
+
+ const handleRefRangeChange = (commandInfo: EffectRefRangeParams) => {
+ const resultRange = handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(oldRange, commandInfo, { selectionManagerService: this._selectionManagerService });
+ if (resultRange && resultRange.startColumn === oldRange.startColumn && resultRange.startRow === oldRange.startRow) {
+ return {
+ undos: [],
+ redos: [],
+ };
+ }
+
+ const res = this._handlePositionChange(unitId, subUnitId, link, resultRange, false);
+ return res;
+ };
+ this._disposableMap.set(id, this._refRangeService.registerRefRange(oldRange, handleRefRangeChange, unitId, subUnitId));
+ }
+
+ private _watchPosition(unitId: string, subUnitId: string, link: ICellHyperLink) {
+ const id = link.id;
+ const oldRange: IRange = {
+ startColumn: link.column,
+ endColumn: link.column,
+ startRow: link.row,
+ endRow: link.row,
+ };
+ this._watchDisposableMap.set(id,
+ this._refRangeService.watchRange(unitId, subUnitId, oldRange, (before, after) => {
+ const { redos } = this._handlePositionChange(unitId, subUnitId, link, after, true);
+ sequenceExecuteAsync(redos, this._commandService, { onlyLocal: true });
+ }, true)
+ );
+ }
+
+ private _unregisterPosition(id: string) {
+ const disposable = this._disposableMap.get(id);
+ disposable?.dispose();
+ this._disposableMap.delete(id);
+ }
+
+ private _unwatchPosition(id: string) {
+ const disposable = this._watchDisposableMap.get(id);
+ disposable?.dispose();
+ this._watchDisposableMap.delete(id);
+ }
+
+ private _registerRange(unitId: string, id: string, payload: string, silent = false) {
+ if (payload.startsWith('#')) {
+ const search = new URLSearchParams(payload.slice(1));
+ // range, gid, rangeid
+ const searchObj = {
+ gid: search.get('gid') ?? '',
+ range: search.get('range') ?? '',
+ rangeid: search.get('rangeid') ?? '',
+ };
+
+ if (searchObj.range && searchObj.gid) {
+ const subUnitId = searchObj.gid;
+ const range = deserializeRangeWithSheet(searchObj.range).range;
+
+ if (isValidRange(range) && searchObj.range !== ERROR_RANGE) {
+ const handleRangeChange = (commandInfo: EffectRefRangeParams) => {
+ const resultRange = handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(range, commandInfo, { selectionManagerService: this._selectionManagerService });
+ if (resultRange && serializeRange(resultRange) === serializeRange(range)) {
+ return {
+ redos: [],
+ undos: [],
+ };
+ }
+
+ return {
+ redos: [{
+ id: UpdateHyperLinkMutation.id,
+ params: {
+ unitId,
+ subUnitId,
+ id,
+ payload: {
+ payload: `#gid=${subUnitId}&range=${resultRange ? serializeRange(resultRange) : 'err'}`,
+ },
+ } as IUpdateHyperLinkMutationParams,
+ }],
+ undos: [{
+ id: UpdateHyperLinkMutation.id,
+ params: {
+ unitId,
+ subUnitId,
+ id,
+ payload: {
+ payload,
+ },
+ } as IUpdateHyperLinkMutationParams,
+ }],
+ };
+ };
+ this._rangeDisableMap.set(id, this._refRangeService.registerRefRange(range, handleRangeChange, unitId, subUnitId));
+ if (!silent) {
+ this._rangeWatcherMap.set(id, this._refRangeService.watchRange(unitId, subUnitId, range, (before, after) => {
+ this._hyperLinkModel.updateHyperLink(unitId, subUnitId, id, {
+ payload: `#gid=${subUnitId}&range=${after ? serializeRange(after) : 'err'}`,
+ }, true);
+ }, true));
+ }
+ }
+ }
+ }
+ }
+
+ private _unregisterRange(id: string) {
+ const disposable = this._rangeDisableMap.get(id);
+ disposable?.dispose();
+ this._rangeDisableMap.delete(id);
+ }
+
+ private _unwatchRange(id: string) {
+ const disposable = this._rangeWatcherMap.get(id);
+ disposable?.dispose();
+ this._rangeWatcherMap.delete(id);
+ }
+
+ private _initData() {
+ const data = this._hyperLinkModel.getAll();
+
+ data.forEach((unitData) => {
+ unitData.forEach((subUnitData) => {
+ const { unitId, subUnitId, links } = subUnitData;
+
+ links.forEach((link) => {
+ this._registerPosition(unitId, subUnitId, link);
+ this._watchPosition(unitId, subUnitId, link);
+ this._registerRange(unitId, link.id, link.payload);
+ });
+ });
+ });
+ }
+
+ private _initRefRange() {
+ this.disposeWithMe(
+ this._hyperLinkModel.linkUpdate$.subscribe((option) => {
+ switch (option.type) {
+ case 'add': {
+ this._registerPosition(option.unitId, option.subUnitId, option.payload);
+ this._watchPosition(option.unitId, option.subUnitId, option.payload);
+ this._registerRange(option.unitId, option.payload.id, option.payload.payload);
+ break;
+ }
+ case 'remove': {
+ this._unregisterPosition(option.payload.id);
+ this._unwatchPosition(option.payload.id);
+ this._unregisterRange(option.payload.id);
+ break;
+ }
+ case 'updateRef': {
+ const { unitId, subUnitId, id, silent } = option;
+ const link = this._hyperLinkModel.getHyperLink(unitId, subUnitId, id);
+ if (!link) {
+ return;
+ }
+
+ this._unregisterPosition(id);
+ this._registerPosition(unitId, subUnitId, link);
+ if (!silent) {
+ this._unwatchPosition(id);
+ this._watchPosition(unitId, subUnitId, link);
+ }
+ break;
+ }
+ case 'unload': {
+ const { unitLinks } = option;
+ unitLinks.forEach((subUnitData) => {
+ const { links } = subUnitData;
+ links.forEach((link) => {
+ this._unregisterPosition(link.id);
+ this._unregisterRange(link.id);
+ });
+ });
+ break;
+ }
+ case 'update': {
+ if (!option.silent) {
+ this._unwatchRange(option.id);
+ }
+ this._unregisterRange(option.id);
+ this._registerRange(option.unitId, option.id, option.payload.payload, option.silent);
+ break;
+ }
+ }
+ })
+ );
+
+ this.disposeWithMe(toDisposable(() => {
+ this._disposableMap.forEach((item) => {
+ item.dispose();
+ });
+ this._disposableMap.clear();
+ }));
+ }
+}
diff --git a/packages/sheets-hyper-link/src/controllers/sheet-hyper-link-resource.controller.ts b/packages/sheets-hyper-link/src/controllers/sheet-hyper-link-resource.controller.ts
index 75996b3e73..b37c447154 100644
--- a/packages/sheets-hyper-link/src/controllers/sheet-hyper-link-resource.controller.ts
+++ b/packages/sheets-hyper-link/src/controllers/sheet-hyper-link-resource.controller.ts
@@ -39,7 +39,7 @@ export class SheetsHyperLinkResourceController extends Disposable {
const resultMap: UnitHyperLinkJSON = {};
if (map) {
map.forEach((info) => {
- resultMap[info.subUnitId] = info.links;
+ resultMap[info.subUnitId] = info.links.map(({ display, ...link }) => link);
});
return JSON.stringify(resultMap);
diff --git a/packages/sheets-hyper-link/src/index.ts b/packages/sheets-hyper-link/src/index.ts
index efc5fe03d3..13e511b6c2 100644
--- a/packages/sheets-hyper-link/src/index.ts
+++ b/packages/sheets-hyper-link/src/index.ts
@@ -27,4 +27,7 @@ export { HyperLinkModel } from './models/hyper-link.model';
export { SheetsHyperLinkController } from './controllers/sheet-hyper-link.controller';
export { HyperLinkType } from './types/enums/hyper-link-type';
export { UniverSheetsHyperLinkPlugin } from './plugin';
+export { SheetsHyperLinkRefRangeController } from './controllers/ref-range.controller';
export type { ICellHyperLink, ICellLinkContent } from './types/interfaces/i-hyper-link';
+
+export { ERROR_RANGE } from './types/const';
diff --git a/packages/sheets-hyper-link/src/models/hyper-link.model.ts b/packages/sheets-hyper-link/src/models/hyper-link.model.ts
index 1206276804..67409ecee3 100644
--- a/packages/sheets-hyper-link/src/models/hyper-link.model.ts
+++ b/packages/sheets-hyper-link/src/models/hyper-link.model.ts
@@ -15,7 +15,8 @@
*/
import { Subject } from 'rxjs';
-import { Disposable, ObjectMatrix } from '@univerjs/core';
+import type { Workbook } from '@univerjs/core';
+import { Disposable, IUniverInstanceService, ObjectMatrix, UniverInstanceType } from '@univerjs/core';
import type { ICellHyperLink, ICellLinkContent } from '../types/interfaces/i-hyper-link';
type LinkUpdate = {
@@ -23,23 +24,27 @@ type LinkUpdate = {
payload: ICellHyperLink;
unitId: string;
subUnitId: string;
+ silent?: boolean;
} | {
type: 'remove';
payload: ICellHyperLink;
unitId: string;
subUnitId: string;
+ silent?: boolean;
} | {
type: 'update';
unitId: string;
subUnitId: string;
payload: ICellLinkContent;
id: string;
+ silent?: boolean;
} | {
type: 'updateRef';
unitId: string;
subUnitId: string;
id: string;
payload: { row: number; column: number };
+ silent?: boolean;
} | {
type: 'unload';
unitId: string;
@@ -48,6 +53,7 @@ type LinkUpdate = {
subUnitId: string;
links: ICellHyperLink[];
}[];
+ silent?: boolean;
};
export class HyperLinkModel extends Disposable {
@@ -57,7 +63,9 @@ export class HyperLinkModel extends Disposable {
private _linkMap: Map<string, Map<string, ObjectMatrix<ICellHyperLink>>> = new Map();
private _linkPositionMap: Map<string, Map<string, Map<string, { row: number; column: number; link: ICellHyperLink }>>> = new Map();
- constructor() {
+ constructor(
+ @IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService
+ ) {
super();
this.disposeWithMe({
dispose: () => {
@@ -121,22 +129,22 @@ export class HyperLinkModel extends Disposable {
return false;
}
Object.assign(link, payload);
- if (!silent) {
- this._linkUpdate$.next({
- unitId,
- subUnitId,
- payload: {
- display: link.display,
- payload: link.payload,
- },
- id,
- type: 'update',
- });
- }
+
+ this._linkUpdate$.next({
+ unitId,
+ subUnitId,
+ payload: {
+ display: link.display,
+ payload: link.payload,
+ },
+ id,
+ type: 'update',
+ silent,
+ });
return true;
}
- updateHyperLinkRef(unitId: string, subUnitId: string, id: string, payload: { row: number; column: number }) {
+ updateHyperLinkRef(unitId: string, subUnitId: string, id: string, payload: { row: number; column: number }, silent = false) {
const { matrix, positionMap } = this._ensureMap(unitId, subUnitId);
// const current = matrix.getValue();
const position = positionMap.get(id);
@@ -159,6 +167,7 @@ export class HyperLinkModel extends Disposable {
payload,
id,
type: 'updateRef',
+ silent,
});
return true;
}
@@ -195,10 +204,25 @@ export class HyperLinkModel extends Disposable {
getHyperLinkByLocation(unitId: string, subUnitId: string, row: number, column: number): ICellHyperLink | undefined {
const { matrix } = this._ensureMap(unitId, subUnitId);
-
return matrix.getValue(row, column);
}
+ getHyperLinkByLocationSync(unitId: string, subUnitId: string, row: number, column: number) {
+ const { matrix } = this._ensureMap(unitId, subUnitId);
+ const workbook = this._univerInstanceService.getUnit<Workbook>(unitId, UniverInstanceType.UNIVER_SHEET);
+ const cell = workbook?.getSheetBySheetId(subUnitId)?.getCellRaw(row, column);
+ const cellValueStr = (cell?.v ?? cell?.p?.body?.dataStream.slice(0, -2) ?? '').toString();
+ const link = matrix.getValue(row, column);
+
+ if (!link) {
+ return undefined;
+ }
+ return {
+ ...link,
+ display: cellValueStr,
+ };
+ }
+
getSubUnit(unitId: string, subUnitId: string) {
const { matrix } = this._ensureMap(unitId, subUnitId);
diff --git a/packages/sheets-hyper-link/src/plugin.ts b/packages/sheets-hyper-link/src/plugin.ts
index aed422e77b..34eab1e9cd 100644
--- a/packages/sheets-hyper-link/src/plugin.ts
+++ b/packages/sheets-hyper-link/src/plugin.ts
@@ -21,6 +21,7 @@ import { SheetsHyperLinkController } from './controllers/sheet-hyper-link.contro
import { HyperLinkModel } from './models/hyper-link.model';
import { SHEET_HYPER_LINK_PLUGIN } from './types/const';
import { SheetsHyperLinkResourceController } from './controllers/sheet-hyper-link-resource.controller';
+import { SheetsHyperLinkRefRangeController } from './controllers/ref-range.controller';
export class UniverSheetsHyperLinkPlugin extends Plugin {
static override pluginName = SHEET_HYPER_LINK_PLUGIN;
@@ -37,6 +38,7 @@ export class UniverSheetsHyperLinkPlugin extends Plugin {
([
[SheetsHyperLinkResourceController],
[SheetsHyperLinkController],
+ [SheetsHyperLinkRefRangeController],
[HyperLinkModel],
] as Dependency[]).forEach((dep) => {
_injector.add(dep);
diff --git a/packages/sheets-hyper-link/src/types/const.ts b/packages/sheets-hyper-link/src/types/const.ts
index b99fdfaa82..b9dcef556a 100644
--- a/packages/sheets-hyper-link/src/types/const.ts
+++ b/packages/sheets-hyper-link/src/types/const.ts
@@ -15,3 +15,4 @@
*/
export const SHEET_HYPER_LINK_PLUGIN = 'SHEET_HYPER_LINK_PLUGIN';
+export const ERROR_RANGE = 'err';
diff --git a/packages/sheets-hyper-link/src/types/interfaces/i-hyper-link.ts b/packages/sheets-hyper-link/src/types/interfaces/i-hyper-link.ts
index e6f12e2748..1b836c2ac6 100644
--- a/packages/sheets-hyper-link/src/types/interfaces/i-hyper-link.ts
+++ b/packages/sheets-hyper-link/src/types/interfaces/i-hyper-link.ts
@@ -23,7 +23,10 @@ export interface ICellLinkContent {
* file: file://a.xlsx
*/
payload: string;
- display: string;
+ /**
+ * only for notify, if you wan't to read the display of text, use cell-value of cell-matrix instead
+ */
+ display?: string;
}
export interface ICellHyperLink extends ICellLinkContent {
diff --git a/packages/sheets-thread-comment-base/README-zh.md b/packages/sheets-thread-comment-base/README-zh.md
new file mode 100644
index 0000000000..8a30086605
--- /dev/null
+++ b/packages/sheets-thread-comment-base/README-zh.md
@@ -0,0 +1,22 @@
+# @univerjs/sheets-thread-comment-base
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/sheets-thread-comment-base)](https://npmjs.org/packages/@univerjs/sheets-thread-comment-base)
+[![license](https://img.shields.io/npm/l/@univerjs/sheets-thread-comment-base)](https://img.shields.io/npm/l/@univerjs/sheets-thread-comment-base)
+
+## 简介
+
+> `@univerjs/sheets-thread-comment-base` 表格 评论/批注 核心包,如需使用请查看 [@univerjs/sheets-thread-comment](../sheets-thread-comment/README-zh.md)
+
+
+## 使用指南
+
+### 安装
+
+```shell
+# 使用 npm
+npm install @univerjs/sheets-thread-comment-base
+
+# 使用 pnpm
+pnpm add @univerjs/sheets-thread-comment-base
+```
+
diff --git a/packages/sheets-thread-comment-base/README.md b/packages/sheets-thread-comment-base/README.md
new file mode 100644
index 0000000000..d88a2e15c0
--- /dev/null
+++ b/packages/sheets-thread-comment-base/README.md
@@ -0,0 +1,22 @@
+# @univerjs/sheets-thread-comment-base
+
+[![npm version](https://img.shields.io/npm/v/@univerjs/sheets-thread-comment-base)](https://npmjs.org/packages/@univerjs/sheets-thread-comment-base)
+[![license](https://img.shields.io/npm/l/@univerjs/sheets-thread-comment-base)](https://img.shields.io/npm/l/@univerjs/sheets-thread-comment-base)
+
+## 简介
+
+> `@univerjs/sheets-thread-comment-base` core package for sheet comment. For using, please refer to [@univerjs/sheets-thread-comment](../sheets-thread-comment/README.md)
+
+
+## 使用指南
+
+### 安装
+
+```shell
+# 使用 npm
+npm install @univerjs/sheets-thread-comment-base
+
+# 使用 pnpm
+pnpm add @univerjs/sheets-thread-comment-base
+```
+
diff --git a/packages/sheets-thread-comment-base/package.json b/packages/sheets-thread-comment-base/package.json
new file mode 100644
index 0000000000..94c7ebd976
--- /dev/null
+++ b/packages/sheets-thread-comment-base/package.json
@@ -0,0 +1,88 @@
+{
+ "name": "@univerjs/sheets-thread-comment-base",
+ "version": "0.1.13",
+ "private": false,
+ "description": "Univer sheets thread comment base plugin",
+ "author": "DreamNum <[email protected]>",
+ "license": "Apache-2.0",
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/univer"
+ },
+ "homepage": "https://univer.ai",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/dream-num/univer"
+ },
+ "bugs": {
+ "url": "https://github.com/dream-num/univer/issues"
+ },
+ "keywords": [],
+ "exports": {
+ ".": "./src/index.ts",
+ "./*": "./src/*",
+ "./locale/*": "./src/locale/*.ts"
+ },
+ "main": "./lib/cjs/index.js",
+ "module": "./lib/es/index.js",
+ "types": "./lib/types/index.d.ts",
+ "publishConfig": {
+ "access": "public",
+ "main": "./lib/cjs/index.js",
+ "module": "./lib/es/index.js",
+ "exports": {
+ ".": {
+ "import": "./lib/es/index.js",
+ "require": "./lib/cjs/index.js",
+ "types": "./lib/types/index.d.ts"
+ },
+ "./*": {
+ "import": "./lib/es/*",
+ "require": "./lib/cjs/*",
+ "types": "./lib/types/index.d.ts"
+ },
+ "./locale/*": "./lib/locale/*.json",
+ "./lib/*": "./lib/*"
+ }
+ },
+ "directories": {
+ "lib": "lib"
+ },
+ "files": [
+ "lib"
+ ],
+ "scripts": {
+ "test": "vitest run",
+ "test:watch": "vitest",
+ "coverage": "vitest run --coverage",
+ "lint:types": "tsc --noEmit",
+ "build": "tsc && vite build"
+ },
+ "peerDependencies": {
+ "@univerjs/core": "workspace:*",
+ "@univerjs/engine-formula": "workspace:*",
+ "@univerjs/engine-render": "workspace:*",
+ "@univerjs/sheets": "workspace:*",
+ "@univerjs/thread-comment": "workspace:*",
+ "@univerjs/ui": "workspace:*",
+ "@wendellhu/redi": "0.15.2",
+ "react": "^16.9.0 || ^17.0.0 || ^18.0.0",
+ "rxjs": ">=7.0.0"
+ },
+ "dependencies": {
+ "@univerjs/thread-comment": "workspace:*"
+ },
+ "devDependencies": {
+ "@univerjs/core": "workspace:*",
+ "@univerjs/design": "workspace:*",
+ "@univerjs/engine-formula": "workspace:*",
+ "@univerjs/shared": "workspace:*",
+ "@univerjs/ui": "workspace:*",
+ "@wendellhu/redi": "0.15.2",
+ "react": "18.2.0",
+ "rxjs": "^7.8.1",
+ "typescript": "^5.4.5",
+ "vite": "^5.2.12",
+ "vitest": "^1.6.0"
+ }
+}
diff --git a/packages/sheets-thread-comment-base/src/controllers/sheets-thread-comment-ref-range.controller.ts b/packages/sheets-thread-comment-base/src/controllers/sheets-thread-comment-ref-range.controller.ts
new file mode 100644
index 0000000000..ac0ea0ff43
--- /dev/null
+++ b/packages/sheets-thread-comment-base/src/controllers/sheets-thread-comment-ref-range.controller.ts
@@ -0,0 +1,235 @@
+/**
+ * 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 { IRange, Nullable } from '@univerjs/core';
+import { Disposable, ICommandService, LifecycleStages, OnLifecycle, sequenceExecuteAsync, toDisposable } from '@univerjs/core';
+import type { IDisposable } from '@wendellhu/redi';
+import { Inject } from '@wendellhu/redi';
+import type { EffectRefRangeParams } from '@univerjs/sheets';
+import { handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests, RefRangeService, SelectionManagerService } from '@univerjs/sheets';
+import type { IAddCommentMutationParams, IUpdateCommentRefMutationParams } from '@univerjs/thread-comment';
+import { AddCommentMutation, DeleteCommentMutation, ThreadCommentModel, UpdateCommentRefMutation } from '@univerjs/thread-comment';
+import { serializeRange, singleReferenceToGrid } from '@univerjs/engine-formula';
+import type { ISheetThreadComment } from '../types/interfaces/i-sheet-thread-comment';
+import { SheetsThreadCommentModel } from '../models/sheets-thread-comment.model';
+
+@OnLifecycle(LifecycleStages.Starting, SheetsThreadCommentRefRangeController)
+export class SheetsThreadCommentRefRangeController extends Disposable {
+ private _disposableMap = new Map<string, IDisposable>();
+ private _watcherMap = new Map<string, IDisposable>();
+
+ constructor(
+ @Inject(RefRangeService) private readonly _refRangeService: RefRangeService,
+ @Inject(SheetsThreadCommentModel) private readonly _sheetsThreadCommentModel: SheetsThreadCommentModel,
+ @Inject(ThreadCommentModel) private readonly _threadCommentModel: ThreadCommentModel,
+ @Inject(SelectionManagerService) private readonly _selectionManagerService: SelectionManagerService,
+ @ICommandService private readonly _commandService: ICommandService
+ ) {
+ super();
+ this._initData();
+ this._initRefRange();
+ }
+
+ private _getIdWithUnitId(unitId: string, subUnitId: string, id: string) {
+ return `${unitId}-${subUnitId}-${id}`;
+ }
+
+ private _handleRangeChange = (unitId: string, subUnitId: string, comment: ISheetThreadComment, resultRange: Nullable<IRange>, silent?: boolean) => {
+ const commentId = comment.id;
+ const oldRange: IRange = {
+ startColumn: comment.column,
+ endColumn: comment.column,
+ startRow: comment.row,
+ endRow: comment.row,
+ };
+
+ if (!resultRange) {
+ return {
+ redos: [{
+ id: DeleteCommentMutation.id,
+ params: {
+ unitId,
+ subUnitId,
+ commentId,
+ },
+ }],
+ undos: [{
+ id: AddCommentMutation.id,
+ params: {
+ unitId,
+ subUnitId,
+ comment,
+ } as IAddCommentMutationParams,
+ }],
+ };
+ }
+ return {
+ redos: [{
+ id: UpdateCommentRefMutation.id,
+ params: {
+ unitId,
+ subUnitId,
+ payload: {
+ ref: serializeRange(resultRange),
+ commentId,
+ },
+ silent,
+ } as IUpdateCommentRefMutationParams,
+ }],
+ undos: [{
+ id: UpdateCommentRefMutation.id,
+ params: {
+ unitId,
+ subUnitId,
+ payload: {
+ ref: serializeRange(oldRange),
+ commentId,
+ },
+ silent,
+ } as IUpdateCommentRefMutationParams,
+ }],
+ };
+ };
+
+ private _register(unitId: string, subUnitId: string, comment: ISheetThreadComment) {
+ const commentId = comment.id;
+ const oldRange: IRange = {
+ startColumn: comment.column,
+ endColumn: comment.column,
+ startRow: comment.row,
+ endRow: comment.row,
+ };
+
+ this._disposableMap.set(
+ this._getIdWithUnitId(unitId, subUnitId, commentId),
+ this._refRangeService.registerRefRange(oldRange, (commandInfo: EffectRefRangeParams) => {
+ const resultRange = handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests(oldRange, commandInfo, { selectionManagerService: this._selectionManagerService });
+ if (resultRange && resultRange.startColumn === oldRange.startColumn && resultRange.startRow === oldRange.startRow) {
+ return {
+ undos: [],
+ redos: [],
+ };
+ }
+ const res = this._handleRangeChange(unitId, subUnitId, comment, resultRange, false);
+ return res;
+ }, unitId, subUnitId)
+ );
+ }
+
+ private _watch(unitId: string, subUnitId: string, comment: ISheetThreadComment) {
+ const commentId = comment.id;
+ const oldRange: IRange = {
+ startColumn: comment.column,
+ endColumn: comment.column,
+ startRow: comment.row,
+ endRow: comment.row,
+ };
+ this._watcherMap.set(
+ this._getIdWithUnitId(unitId, subUnitId, commentId),
+ this._refRangeService.watchRange(unitId, subUnitId, oldRange, (before, after) => {
+ const { redos } = this._handleRangeChange(unitId, subUnitId, comment, after, true);
+ sequenceExecuteAsync(redos, this._commandService, { onlyLocal: true });
+ }, true)
+ );
+ }
+
+ private _unwatch(unitId: string, subUnitId: string, commentId: string) {
+ const id = this._getIdWithUnitId(unitId, subUnitId, commentId);
+ this._watcherMap.get(id)?.dispose();
+ this._watcherMap.delete(id);
+ }
+
+ private _unregister(unitId: string, subUnitId: string, commentId: string) {
+ const id = this._getIdWithUnitId(unitId, subUnitId, commentId);
+ this._disposableMap.get(id)?.dispose();
+ this._disposableMap.delete(id);
+ }
+
+ private _initData() {
+ const data = this._threadCommentModel.getAll();
+
+ for (const unitId in data) {
+ const unitMap = data[unitId];
+ for (const subUnitId in unitMap) {
+ const subUnitMap = unitMap[subUnitId];
+ for (const id in subUnitMap) {
+ const comment = subUnitMap[id];
+ const ref = comment.ref;
+ const pos = singleReferenceToGrid(ref);
+ const sheetComment = {
+ ...comment,
+ ...pos,
+ };
+ this._register(unitId, subUnitId, sheetComment);
+ this._watch(unitId, subUnitId, sheetComment);
+ }
+ }
+ }
+ }
+
+ private _initRefRange() {
+ this.disposeWithMe(
+ this._sheetsThreadCommentModel.commentUpdate$.subscribe((option) => {
+ const { unitId, subUnitId } = option;
+ switch (option.type) {
+ case 'add': {
+ const comment = {
+ ...option.payload,
+ row: option.row,
+ column: option.column,
+ };
+
+ this._register(option.unitId, option.subUnitId, comment);
+ this._watch(option.unitId, option.subUnitId, comment);
+ break;
+ }
+ case 'delete': {
+ this._unregister(unitId, subUnitId, option.payload.commentId);
+ this._unwatch(unitId, subUnitId, option.payload.commentId);
+ break;
+ }
+ case 'updateRef': {
+ const comment = this._sheetsThreadCommentModel.getComment(unitId, subUnitId, option.payload.commentId);
+ if (!comment) {
+ return;
+ }
+
+ this._unregister(unitId, subUnitId, option.payload.commentId);
+ const sheetComment = {
+ ...comment,
+ row: option.row,
+ column: option.column,
+ };
+ if (!option.silent) {
+ this._unwatch(unitId, subUnitId, option.payload.commentId);
+ this._watch(unitId, subUnitId, sheetComment);
+ }
+
+ this._register(option.unitId, option.subUnitId, sheetComment);
+ break;
+ }
+ }
+ })
+ );
+
+ this.disposeWithMe(toDisposable(() => {
+ this._disposableMap.forEach((item) => {
+ item.dispose();
+ });
+ this._disposableMap.clear();
+ }));
+ }
+}
diff --git a/packages/sheets-thread-comment-base/src/index.ts b/packages/sheets-thread-comment-base/src/index.ts
new file mode 100644
index 0000000000..ecf3dc6066
--- /dev/null
+++ b/packages/sheets-thread-comment-base/src/index.ts
@@ -0,0 +1,20 @@
+/**
+ * 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.
+ */
+
+export { SheetsThreadCommentRefRangeController } from './controllers/sheets-thread-comment-ref-range.controller';
+export { SheetsThreadCommentModel } from './models/sheets-thread-comment.model';
+export type { ISheetThreadComment } from './types/interfaces/i-sheet-thread-comment';
+export { UniverSheetsThreadCommentBasePlugin } from './plugin';
diff --git a/packages/sheets-thread-comment/src/models/sheets-thread-comment.model.ts b/packages/sheets-thread-comment-base/src/models/sheets-thread-comment.model.ts
similarity index 97%
rename from packages/sheets-thread-comment/src/models/sheets-thread-comment.model.ts
rename to packages/sheets-thread-comment-base/src/models/sheets-thread-comment.model.ts
index bb1a584675..df32e58467 100644
--- a/packages/sheets-thread-comment/src/models/sheets-thread-comment.model.ts
+++ b/packages/sheets-thread-comment-base/src/models/sheets-thread-comment.model.ts
@@ -147,7 +147,10 @@ export class SheetsThreadCommentModel extends Disposable {
if (isRoot) {
const { row, column } = location;
if (row >= 0 && column >= 0) {
- matrix.realDeleteValue(row, column);
+ const current = matrix.getValue(row, column);
+ if (current === comment.id) {
+ matrix.realDeleteValue(row, column);
+ }
}
}
this._commentUpdate$.next({
@@ -186,7 +189,6 @@ export class SheetsThreadCommentModel extends Disposable {
matrix.setValue(location.row, location.column, commentId);
locationMap.set(commentId, { row: location.row, column: location.column });
}
-
this._commentUpdate$.next({
...update,
...location,
diff --git a/packages/sheets-thread-comment-base/src/plugin.ts b/packages/sheets-thread-comment-base/src/plugin.ts
new file mode 100644
index 0000000000..75ec29c297
--- /dev/null
+++ b/packages/sheets-thread-comment-base/src/plugin.ts
@@ -0,0 +1,46 @@
+/**
+ * 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 { Dependency } from '@wendellhu/redi';
+import { Inject, Injector } from '@wendellhu/redi';
+import { DependentOn, ICommandService, Plugin, UniverInstanceType } from '@univerjs/core';
+import { UniverThreadCommentPlugin } from '@univerjs/thread-comment';
+import { SheetsThreadCommentRefRangeController } from './controllers/sheets-thread-comment-ref-range.controller';
+import { SheetsThreadCommentModel } from './models/sheets-thread-comment.model';
+import { SHEETS_THREAD_COMMENT_BASE } from './types/const';
+
+@DependentOn(UniverThreadCommentPlugin)
+export class UniverSheetsThreadCommentBasePlugin extends Plugin {
+ static override pluginName = SHEETS_THREAD_COMMENT_BASE;
+ static override type = UniverInstanceType.UNIVER_SHEET;
+
+ constructor(
+ config: unknown,
+ @Inject(Injector) protected override _injector: Injector,
+ @Inject(ICommandService) protected _commandService: ICommandService
+ ) {
+ super();
+ }
+
+ override onStarting(injector: Injector): void {
+ ([
+ [SheetsThreadCommentModel],
+ [SheetsThreadCommentRefRangeController],
+ ] as Dependency[]).forEach((dep) => {
+ injector.add(dep);
+ });
+ }
+}
diff --git a/packages/sheets-thread-comment-base/src/types/const.ts b/packages/sheets-thread-comment-base/src/types/const.ts
new file mode 100644
index 0000000000..6bdf451718
--- /dev/null
+++ b/packages/sheets-thread-comment-base/src/types/const.ts
@@ -0,0 +1,17 @@
+/**
+ * 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.
+ */
+
+export const SHEETS_THREAD_COMMENT_BASE = 'SHEETS_THREAD_COMMENT_BASE_PLUGIN';
diff --git a/packages/sheets-thread-comment-base/src/types/interfaces/i-sheet-thread-comment.ts b/packages/sheets-thread-comment-base/src/types/interfaces/i-sheet-thread-comment.ts
new file mode 100644
index 0000000000..4ae71f95fe
--- /dev/null
+++ b/packages/sheets-thread-comment-base/src/types/interfaces/i-sheet-thread-comment.ts
@@ -0,0 +1,22 @@
+/**
+ * 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 { IThreadComment } from '@univerjs/thread-comment';
+
+export interface ISheetThreadComment extends IThreadComment {
+ row: number;
+ column: number;
+}
diff --git a/packages/sheets-thread-comment-base/src/vite-env.d.ts b/packages/sheets-thread-comment-base/src/vite-env.d.ts
new file mode 100644
index 0000000000..11f02fe2a0
--- /dev/null
+++ b/packages/sheets-thread-comment-base/src/vite-env.d.ts
@@ -0,0 +1 @@
+/// <reference types="vite/client" />
diff --git a/packages/sheets-thread-comment-base/tsconfig.json b/packages/sheets-thread-comment-base/tsconfig.json
new file mode 100644
index 0000000000..d676ad2a20
--- /dev/null
+++ b/packages/sheets-thread-comment-base/tsconfig.json
@@ -0,0 +1,9 @@
+{
+ "extends": "@univerjs/shared/tsconfigs/base",
+ "compilerOptions": {
+ "rootDir": "src",
+ "outDir": "lib/types"
+ },
+ "references": [{ "path": "./tsconfig.node.json" }],
+ "include": ["src"]
+}
diff --git a/packages/sheets-thread-comment-base/tsconfig.node.json b/packages/sheets-thread-comment-base/tsconfig.node.json
new file mode 100644
index 0000000000..e53dac8868
--- /dev/null
+++ b/packages/sheets-thread-comment-base/tsconfig.node.json
@@ -0,0 +1,4 @@
+{
+ "extends": "@univerjs/shared/tsconfigs/node",
+ "include": ["vite.config.ts"]
+}
diff --git a/packages/sheets-thread-comment-base/vite.config.ts b/packages/sheets-thread-comment-base/vite.config.ts
new file mode 100644
index 0000000000..925b530b4d
--- /dev/null
+++ b/packages/sheets-thread-comment-base/vite.config.ts
@@ -0,0 +1,12 @@
+import createViteConfig from '@univerjs/shared/vite';
+import pkg from './package.json';
+
+export default ({ mode }) => createViteConfig({}, {
+ mode,
+ pkg,
+ features: {
+ react: false,
+ css: true,
+ dom: true,
+ },
+});
diff --git a/packages/sheets-thread-comment/package.json b/packages/sheets-thread-comment/package.json
index faa5a12a2e..12cac89a5d 100644
--- a/packages/sheets-thread-comment/package.json
+++ b/packages/sheets-thread-comment/package.json
@@ -73,6 +73,7 @@
},
"dependencies": {
"@univerjs/icons": "^0.1.56",
+ "@univerjs/sheets-thread-comment-base": "workspace:*",
"@univerjs/thread-comment": "workspace:*",
"@univerjs/thread-comment-ui": "workspace:*"
},
diff --git a/packages/sheets-thread-comment/src/commands/operations/comment.operation.ts b/packages/sheets-thread-comment/src/commands/operations/comment.operation.ts
index 7e0a1c39da..a538336a7b 100644
--- a/packages/sheets-thread-comment/src/commands/operations/comment.operation.ts
+++ b/packages/sheets-thread-comment/src/commands/operations/comment.operation.ts
@@ -19,8 +19,8 @@ import { CommandType, IUniverInstanceService } from '@univerjs/core';
import type { ISheetLocation } from '@univerjs/sheets';
import { getSheetCommandTarget, SelectionManagerService } from '@univerjs/sheets';
import { ThreadCommentPanelService } from '@univerjs/thread-comment-ui';
+import { SheetsThreadCommentModel } from '@univerjs/sheets-thread-comment-base';
import { SheetsThreadCommentPopupService } from '../../services/sheets-thread-comment-popup.service';
-import { SheetsThreadCommentModel } from '../../models/sheets-thread-comment.model';
export const ShowAddSheetCommentModalOperation: ICommand = {
type: CommandType.OPERATION,
@@ -50,12 +50,12 @@ export const ShowAddSheetCommentModalOperation: ICommand = {
worksheet,
unitId,
subUnitId: sheetId,
- row: activeCell.actualRow,
+ row: activeCell.startRow,
col: activeCell.startColumn,
};
sheetsThreadCommentPopupService.showPopup(location);
- const rootId = model.getByLocation(unitId, sheetId, activeCell.actualRow, activeCell.startColumn);
+ const rootId = model.getByLocation(unitId, sheetId, activeCell.startRow, activeCell.startColumn);
if (rootId) {
threadCommentPanelService.setActiveComment({
unitId,
diff --git a/packages/sheets-thread-comment/src/controllers/render-controllers/render.controller.ts b/packages/sheets-thread-comment/src/controllers/render-controllers/render.controller.ts
index 99ef0c1c8d..89111a8f02 100644
--- a/packages/sheets-thread-comment/src/controllers/render-controllers/render.controller.ts
+++ b/packages/sheets-thread-comment/src/controllers/render-controllers/render.controller.ts
@@ -21,7 +21,7 @@ import { Inject } from '@wendellhu/redi';
import { SheetSkeletonManagerService } from '@univerjs/sheets-ui';
import type { Spreadsheet } from '@univerjs/engine-render';
import { IRenderManagerService } from '@univerjs/engine-render';
-import { SheetsThreadCommentModel } from '../../models/sheets-thread-comment.model';
+import { SheetsThreadCommentModel } from '@univerjs/sheets-thread-comment-base';
@OnLifecycle(LifecycleStages.Ready, SheetsThreadCommentRenderController)
export class SheetsThreadCommentRenderController extends Disposable {
diff --git a/packages/sheets-thread-comment/src/controllers/sheets-thread-comment-copy-paste.controller.ts b/packages/sheets-thread-comment/src/controllers/sheets-thread-comment-copy-paste.controller.ts
index 0d484a14af..1c65e5cc24 100644
--- a/packages/sheets-thread-comment/src/controllers/sheets-thread-comment-copy-paste.controller.ts
+++ b/packages/sheets-thread-comment/src/controllers/sheets-thread-comment-copy-paste.controller.ts
@@ -20,8 +20,8 @@ import { COPY_TYPE, ISheetClipboardService } from '@univerjs/sheets-ui';
import { Inject } from '@wendellhu/redi';
import { AddCommentMutation, DeleteCommentMutation, type IThreadComment } from '@univerjs/thread-comment';
import { serializeRange, singleReferenceToGrid } from '@univerjs/engine-formula';
+import { SheetsThreadCommentModel } from '@univerjs/sheets-thread-comment-base';
import { SHEETS_THREAD_COMMENT } from '../types/const';
-import { SheetsThreadCommentModel } from '../models/sheets-thread-comment.model';
const transformRef = (ref: string, source: { row: number; column: number }, target: { row: number; column: number }) => {
const refObj = singleReferenceToGrid(ref);
diff --git a/packages/sheets-thread-comment/src/controllers/sheets-thread-comment-hover.controller.ts b/packages/sheets-thread-comment/src/controllers/sheets-thread-comment-hover.controller.ts
index dff71a43ee..381c9fdf51 100644
--- a/packages/sheets-thread-comment/src/controllers/sheets-thread-comment-hover.controller.ts
+++ b/packages/sheets-thread-comment/src/controllers/sheets-thread-comment-hover.controller.ts
@@ -18,8 +18,8 @@ import { Disposable, LifecycleStages, OnLifecycle } from '@univerjs/core';
import { HoverManagerService } from '@univerjs/sheets-ui';
import { Inject } from '@wendellhu/redi';
import { debounceTime } from 'rxjs';
+import { SheetsThreadCommentModel } from '@univerjs/sheets-thread-comment-base';
import { SheetsThreadCommentPopupService } from '../services/sheets-thread-comment-popup.service';
-import { SheetsThreadCommentModel } from '../models/sheets-thread-comment.model';
@OnLifecycle(LifecycleStages.Rendered, SheetsThreadCommentHoverController)
export class SheetsThreadCommentHoverController extends Disposable {
diff --git a/packages/sheets-thread-comment/src/controllers/sheets-thread-comment-ref-range.controller.ts b/packages/sheets-thread-comment/src/controllers/sheets-thread-comment-ref-range.controller.ts
deleted file mode 100644
index 60ad5a99f6..0000000000
--- a/packages/sheets-thread-comment/src/controllers/sheets-thread-comment-ref-range.controller.ts
+++ /dev/null
@@ -1,182 +0,0 @@
-/**
- * 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 { IRange } from '@univerjs/core';
-import { Disposable, LifecycleStages, OnLifecycle, toDisposable } from '@univerjs/core';
-import type { IDisposable } from '@wendellhu/redi';
-import { Inject } from '@wendellhu/redi';
-import type { EffectRefRangeParams } from '@univerjs/sheets';
-import { handleDefaultRangeChangeWithEffectRefCommands, RefRangeService } from '@univerjs/sheets';
-import type { IAddCommentMutationParams, IUpdateCommentRefMutationParams } from '@univerjs/thread-comment';
-import { AddCommentMutation, DeleteCommentMutation, ThreadCommentModel, UpdateCommentRefMutation } from '@univerjs/thread-comment';
-import { serializeRange, singleReferenceToGrid } from '@univerjs/engine-formula';
-import type { ISheetThreadComment } from '../types/interfaces/i-sheet-thread-comment';
-import { SheetsThreadCommentModel } from '../models/sheets-thread-comment.model';
-
-@OnLifecycle(LifecycleStages.Starting, SheetsThreadCommentRefRangeController)
-export class SheetsThreadCommentRefRangeController extends Disposable {
- private _disposableMap = new Map<string, IDisposable>();
-
- constructor(
- @Inject(RefRangeService) private readonly _refRangeService: RefRangeService,
- @Inject(SheetsThreadCommentModel) private readonly _sheetsThreadCommentModel: SheetsThreadCommentModel,
- @Inject(ThreadCommentModel) private readonly _threadCommentModel: ThreadCommentModel
- ) {
- super();
- this._initData();
- this._initRefRange();
- }
-
- private _getIdWithUnitId(unitId: string, subUnitId: string, id: string) {
- return `${unitId}-${subUnitId}-${id}`;
- }
-
- private _register(unitId: string, subUnitId: string, comment: ISheetThreadComment) {
- const commentId = comment.id;
- const oldRange: IRange = {
- startColumn: comment.column,
- endColumn: comment.column,
- startRow: comment.row,
- endRow: comment.row,
- };
-
- const handleRangeChange = (commandInfo: EffectRefRangeParams) => {
- const resultRange = handleDefaultRangeChangeWithEffectRefCommands(oldRange, commandInfo);
- if (resultRange && resultRange.startColumn === oldRange.startColumn && resultRange.startRow === oldRange.startRow) {
- return {
- undos: [],
- redos: [],
- };
- }
-
- if (!resultRange) {
- return {
- redos: [{
- id: DeleteCommentMutation.id,
- params: {
- unitId,
- subUnitId,
- commentId,
- },
- }],
- undos: [{
- id: AddCommentMutation.id,
- params: {
- unitId,
- subUnitId,
- comment,
- } as IAddCommentMutationParams,
- }],
- };
- }
- return {
- redos: [{
- id: UpdateCommentRefMutation.id,
- params: {
- unitId,
- subUnitId,
- payload: {
- ref: serializeRange(resultRange),
- commentId,
- },
- } as IUpdateCommentRefMutationParams,
- }],
- undos: [{
- id: UpdateCommentRefMutation.id,
- params: {
- unitId,
- subUnitId,
- payload: {
- ref: serializeRange(oldRange),
- commentId,
- },
- } as IUpdateCommentRefMutationParams,
- }],
- };
- };
-
- this._disposableMap.set(
- this._getIdWithUnitId(unitId, subUnitId, commentId),
- this._refRangeService.registerRefRange(oldRange, handleRangeChange, unitId, subUnitId)
- );
- }
-
- private _initData() {
- const data = this._threadCommentModel.getAll();
-
- for (const unitId in data) {
- const unitMap = data[unitId];
- for (const subUnitId in unitMap) {
- const subUnitMap = unitMap[subUnitId];
- for (const id in subUnitMap) {
- const comment = subUnitMap[id];
- const ref = comment.ref;
- const pos = singleReferenceToGrid(ref);
- this._register(unitId, subUnitId, {
- ...comment,
- ...pos,
- });
- }
- }
- }
- }
-
- private _initRefRange() {
- this.disposeWithMe(
- this._sheetsThreadCommentModel.commentUpdate$.subscribe((option) => {
- const { unitId, subUnitId } = option;
- switch (option.type) {
- case 'add': {
- const comment = option.payload;
- this._register(option.unitId, option.subUnitId, {
- ...comment,
- row: option.row,
- column: option.column,
- });
- break;
- }
- case 'delete': {
- const disposable = this._disposableMap.get(this._getIdWithUnitId(unitId, subUnitId, option.payload.commentId));
- disposable?.dispose();
- break;
- }
- case 'updateRef': {
- const comment = this._sheetsThreadCommentModel.getComment(unitId, subUnitId, option.payload.commentId);
- if (!comment) {
- return;
- }
-
- const disposable = this._disposableMap.get(this._getIdWithUnitId(unitId, subUnitId, comment.id));
- disposable?.dispose();
- this._register(option.unitId, option.subUnitId, {
- ...comment,
- row: option.row,
- column: option.column,
- });
- break;
- }
- }
- })
- );
-
- this.disposeWithMe(toDisposable(() => {
- this._disposableMap.forEach((item) => {
- item.dispose();
- });
- this._disposableMap.clear();
- }));
- }
-}
diff --git a/packages/sheets-thread-comment/src/controllers/sheets-thread-comment.controller.ts b/packages/sheets-thread-comment/src/controllers/sheets-thread-comment.controller.ts
index 3a38d9b91c..b57813c658 100644
--- a/packages/sheets-thread-comment/src/controllers/sheets-thread-comment.controller.ts
+++ b/packages/sheets-thread-comment/src/controllers/sheets-thread-comment.controller.ts
@@ -24,14 +24,14 @@ import { SetActiveCommentOperation, THREAD_COMMENT_PANEL, ThreadCommentPanelServ
import type { ISetSelectionsOperationParams } from '@univerjs/sheets';
import { SelectionMoveType, SetSelectionsOperation, SetWorksheetActiveOperation } from '@univerjs/sheets';
import { singleReferenceToGrid } from '@univerjs/engine-formula';
-import { ScrollToCellCommand } from '@univerjs/sheets-ui';
import type { IDeleteCommentMutationParams } from '@univerjs/thread-comment';
import { DeleteCommentMutation } from '@univerjs/thread-comment';
+import { ScrollToRangeOperation } from '@univerjs/sheets-ui';
+import { SheetsThreadCommentModel } from '@univerjs/sheets-thread-comment-base';
import { SheetsThreadCommentCell } from '../views/sheets-thread-comment-cell';
import { COMMENT_SINGLE_ICON, SHEETS_THREAD_COMMENT_MODAL } from '../types/const';
import { SheetsThreadCommentPanel } from '../views/sheets-thread-comment-panel';
import { SheetsThreadCommentPopupService } from '../services/sheets-thread-comment-popup.service';
-import { SheetsThreadCommentModel } from '../models/sheets-thread-comment.model';
import { AddCommentShortcut, threadCommentMenuFactory, threadPanelMenuFactory } from './menu';
export interface IUniverSheetsThreadCommentConfig {
@@ -157,12 +157,13 @@ export class SheetsThreadCommentController extends Disposable {
}
const location = singleReferenceToGrid(comment.ref);
- await this._commandService.executeCommand(ScrollToCellCommand.id, {
+ const GAP = 5;
+ await this._commandService.executeCommand(ScrollToRangeOperation.id, {
range: {
- startColumn: location.column,
- endColumn: location.column,
- startRow: location.row,
- endRow: location.row,
+ startRow: Math.max(location.row - GAP, 0),
+ endRow: location.row + GAP,
+ startColumn: Math.max(location.column - GAP, 0),
+ endColumn: location.column + GAP,
},
});
this._sheetsThreadCommentPopupService.showPopup({
diff --git a/packages/sheets-thread-comment/src/index.ts b/packages/sheets-thread-comment/src/index.ts
index 2e1874ef15..77530547ba 100644
--- a/packages/sheets-thread-comment/src/index.ts
+++ b/packages/sheets-thread-comment/src/index.ts
@@ -19,8 +19,6 @@ export { Inject, Injector } from '@wendellhu/redi';
export { ICommandService, Plugin, UniverInstanceType } from '@univerjs/core';
export { UniverThreadCommentUIPlugin } from '@univerjs/thread-comment-ui';
export { SheetsThreadCommentController } from './controllers/sheets-thread-comment.controller';
-export { SheetsThreadCommentRefRangeController } from './controllers/sheets-thread-comment-ref-range.controller';
-export { SheetsThreadCommentModel } from './models/sheets-thread-comment.model';
export { SheetsThreadCommentPopupService } from './services/sheets-thread-comment-popup.service';
export { UniverSheetsThreadCommentPlugin } from './plugin';
export { SHEETS_THREAD_COMMENT } from './types/const';
@@ -29,3 +27,4 @@ export { SheetsThreadCommentHoverController } from './controllers/sheets-thread-
export { ThreadCommentRemoveSheetsController } from './controllers/sheets-thread-comment-remove.controller';
export { IThreadCommentMentionDataService } from '@univerjs/thread-comment-ui';
export { IThreadCommentDataSourceService } from '@univerjs/thread-comment';
+export { SheetsThreadCommentModel } from '@univerjs/sheets-thread-comment-base';
diff --git a/packages/sheets-thread-comment/src/plugin.ts b/packages/sheets-thread-comment/src/plugin.ts
index e088e366c3..2e9c022037 100644
--- a/packages/sheets-thread-comment/src/plugin.ts
+++ b/packages/sheets-thread-comment/src/plugin.ts
@@ -18,10 +18,9 @@ import type { Dependency } from '@wendellhu/redi';
import { Inject, Injector } from '@wendellhu/redi';
import { DependentOn, ICommandService, Plugin, Tools, UniverInstanceType } from '@univerjs/core';
import { UniverThreadCommentUIPlugin } from '@univerjs/thread-comment-ui';
+import { UniverSheetsThreadCommentBasePlugin } from '@univerjs/sheets-thread-comment-base';
import type { IUniverSheetsThreadCommentConfig } from './controllers/sheets-thread-comment.controller';
import { DefaultSheetsThreadCommentConfig, SheetsThreadCommentController } from './controllers/sheets-thread-comment.controller';
-import { SheetsThreadCommentRefRangeController } from './controllers/sheets-thread-comment-ref-range.controller';
-import { SheetsThreadCommentModel } from './models/sheets-thread-comment.model';
import { SheetsThreadCommentPopupService } from './services/sheets-thread-comment-popup.service';
import { ShowAddSheetCommentModalOperation } from './commands/operations/comment.operation';
import { SheetsThreadCommentRenderController } from './controllers/render-controllers/render.controller';
@@ -30,7 +29,7 @@ import { SheetsThreadCommentCopyPasteController } from './controllers/sheets-thr
import { SheetsThreadCommentHoverController } from './controllers/sheets-thread-comment-hover.controller';
import { ThreadCommentRemoveSheetsController } from './controllers/sheets-thread-comment-remove.controller';
-@DependentOn(UniverThreadCommentUIPlugin)
+@DependentOn(UniverThreadCommentUIPlugin, UniverSheetsThreadCommentBasePlugin)
export class UniverSheetsThreadCommentPlugin extends Plugin {
static override pluginName = SHEETS_THREAD_COMMENT;
static override type = UniverInstanceType.UNIVER_SHEET;
@@ -49,14 +48,12 @@ export class UniverSheetsThreadCommentPlugin extends Plugin {
override onStarting(injector: Injector): void {
([
- [SheetsThreadCommentModel],
[
SheetsThreadCommentController,
{
useFactory: () => this._injector.createInstance(SheetsThreadCommentController, this._pluginConfig),
},
],
- [SheetsThreadCommentRefRangeController],
[SheetsThreadCommentRenderController],
[SheetsThreadCommentCopyPasteController],
[SheetsThreadCommentHoverController],
diff --git a/packages/sheets-thread-comment/src/views/sheets-thread-comment-cell/index.tsx b/packages/sheets-thread-comment/src/views/sheets-thread-comment-cell/index.tsx
index 6e8ee9a5bd..79133a49e0 100644
--- a/packages/sheets-thread-comment/src/views/sheets-thread-comment-cell/index.tsx
+++ b/packages/sheets-thread-comment/src/views/sheets-thread-comment-cell/index.tsx
@@ -20,7 +20,7 @@ import { ThreadCommentTree } from '@univerjs/thread-comment-ui';
import type { Workbook } from '@univerjs/core';
import { IUniverInstanceService, Tools, UniverInstanceType } from '@univerjs/core';
import { useObservable } from '@univerjs/ui';
-import { SheetsThreadCommentModel } from '../../models/sheets-thread-comment.model';
+import { SheetsThreadCommentModel } from '@univerjs/sheets-thread-comment-base';
import { SheetsThreadCommentPopupService } from '../../services/sheets-thread-comment-popup.service';
export const SheetsThreadCommentCell = () => {
diff --git a/packages/sheets-ui/src/commands/commands/set-format-painter.command.ts b/packages/sheets-ui/src/commands/commands/set-format-painter.command.ts
index d855db12c0..76352bf3f5 100644
--- a/packages/sheets-ui/src/commands/commands/set-format-painter.command.ts
+++ b/packages/sheets-ui/src/commands/commands/set-format-painter.command.ts
@@ -100,6 +100,7 @@ export interface IApplyFormatPainterCommandParams {
export const ApplyFormatPainterCommand: ICommand = {
type: CommandType.COMMAND,
id: 'sheet.command.apply-format-painter',
+ // eslint-disable-next-line max-lines-per-function
handler: async (accessor: IAccessor, params: IApplyFormatPainterCommandParams) => {
const commandService = accessor.get(ICommandService);
const undoRedoService = accessor.get(IUndoRedoService);
diff --git a/packages/sheets-ui/src/commands/operations/scroll-to-range.operation.ts b/packages/sheets-ui/src/commands/operations/scroll-to-range.operation.ts
new file mode 100644
index 0000000000..161d0d0c23
--- /dev/null
+++ b/packages/sheets-ui/src/commands/operations/scroll-to-range.operation.ts
@@ -0,0 +1,34 @@
+/**
+ * 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 { CommandType, type ICommand, IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
+import { IRenderManagerService } from '@univerjs/engine-render';
+import type { IScrollToCellCommandParams } from '../commands/set-scroll.command';
+import { SheetsScrollRenderController } from '../../controllers/render-controllers/scroll.render-controller';
+
+export const ScrollToRangeOperation: ICommand<IScrollToCellCommandParams> = {
+ id: 'sheet.operation.scroll-to-range',
+ type: CommandType.OPERATION,
+ handler: (accessor, params) => {
+ const instanceService = accessor.get(IUniverInstanceService);
+ const renderManagerService = accessor.get(IRenderManagerService);
+ const scrollController = renderManagerService
+ .getRenderById(instanceService.getCurrentUnitForType(UniverInstanceType.UNIVER_SHEET)!.getUnitId())!
+ .with(SheetsScrollRenderController);
+
+ return scrollController.scrollToRange(params!.range);
+ },
+};
diff --git a/packages/sheets-ui/src/controllers/cell-custom-render.controller.ts b/packages/sheets-ui/src/controllers/cell-custom-render.controller.ts
index 9b8607bafc..5abda1fbd8 100644
--- a/packages/sheets-ui/src/controllers/cell-custom-render.controller.ts
+++ b/packages/sheets-ui/src/controllers/cell-custom-render.controller.ts
@@ -116,6 +116,8 @@ export class CellCustomRenderController extends Disposable implements IRenderMod
subUnitId,
row,
col,
+ workbook,
+ worksheet,
};
const position = {
diff --git a/packages/sheets-ui/src/controllers/render-controllers/scroll.render-controller.ts b/packages/sheets-ui/src/controllers/render-controllers/scroll.render-controller.ts
index 019dc51e60..5e68705df3 100644
--- a/packages/sheets-ui/src/controllers/render-controllers/scroll.render-controller.ts
+++ b/packages/sheets-ui/src/controllers/render-controllers/scroll.render-controller.ts
@@ -89,7 +89,7 @@ export class SheetsScrollRenderController extends Disposable implements IRenderM
this._scrollToSelection();
} else if (command.id === ScrollToCellOperation.id) {
const param = command.params as IRange;
- this._scrollToSelectionByDirection(param);
+ this.scrollToRange(param);
} else if (command.id === ExpandSelectionCommand.id) {
const param = command.params as IExpandSelectionCommandParams;
this._scrollToSelectionForExpand(param);
diff --git a/packages/sheets-ui/src/controllers/sheet-ui.controller.ts b/packages/sheets-ui/src/controllers/sheet-ui.controller.ts
index 4a5c02d5a9..eb695d75be 100644
--- a/packages/sheets-ui/src/controllers/sheet-ui.controller.ts
+++ b/packages/sheets-ui/src/controllers/sheet-ui.controller.ts
@@ -105,6 +105,7 @@ import { SheetPermissionOpenPanelOperation } from '../commands/operations/sheet-
import { SheetPermissionOpenDialogOperation } from '../commands/operations/sheet-permission-open-dialog.operation';
import { AddRangeProtectionFromContextMenuCommand, AddRangeProtectionFromSheetBarCommand, AddRangeProtectionFromToolbarCommand, DeleteRangeProtectionFromContextMenuCommand, SetProtectionCommand, SetRangeProtectionFromContextMenuCommand, ViewSheetPermissionFromContextMenuCommand, ViewSheetPermissionFromSheetBarCommand } from '../commands/commands/range-protection.command';
import { AddWorksheetProtectionCommand, ChangeSheetProtectionFromSheetBarCommand, DeleteWorksheetProtectionCommand, DeleteWorksheetProtectionFormSheetBarCommand, SetWorksheetProtectionCommand } from '../commands/commands/worksheet-protection.command';
+import { ScrollToRangeOperation } from '../commands/operations/scroll-to-range.operation';
import {
ClearSelectionAllMenuItemFactory,
ClearSelectionContentMenuItemFactory,
@@ -271,6 +272,7 @@ export class SheetUIController extends Disposable {
this.disposeWithMe(componentManager.register(DEFINED_NAME_CONTAINER, DefinedNameContainer));
}
+ // eslint-disable-next-line max-lines-per-function
private _initCommands(): void {
[
AddWorksheetMergeAllCommand,
@@ -317,6 +319,7 @@ export class SheetUIController extends Disposable {
SetSelectionFrozenCommand,
SetRowFrozenCommand,
SetColumnFrozenCommand,
+ ScrollToRangeOperation,
CancelFrozenCommand,
SetUnderlineCommand,
SetZoomRatioCommand,
diff --git a/packages/sheets-ui/src/index.ts b/packages/sheets-ui/src/index.ts
index 4d6eab6607..aaadbb2ef0 100644
--- a/packages/sheets-ui/src/index.ts
+++ b/packages/sheets-ui/src/index.ts
@@ -105,4 +105,5 @@ export { FormulaEditorController } from './controllers/editor/formula-editor.con
export { StatusBarController } from './controllers/status-bar.controller';
export { SheetPermissionInterceptorBaseController } from './controllers/permission/sheet-permission-interceptor-base.controller';
export type { IRangeProtectionRenderCellData } from './views/permission/extensions/range-protection.render';
+export { ScrollToRangeOperation } from './commands/operations/scroll-to-range.operation';
export { SheetPrintInterceptorService } from './services/print-interceptor.service';
diff --git a/packages/sheets/src/commands/commands/insert-row-col.command.ts b/packages/sheets/src/commands/commands/insert-row-col.command.ts
index 1d0bd24f00..478b036c2f 100644
--- a/packages/sheets/src/commands/commands/insert-row-col.command.ts
+++ b/packages/sheets/src/commands/commands/insert-row-col.command.ts
@@ -23,6 +23,7 @@ import {
IUndoRedoService,
IUniverInstanceService,
Range,
+ RANGE_TYPE,
sequenceExecute,
UniverInstanceType,
} from '@univerjs/core';
@@ -241,6 +242,7 @@ export const InsertRowAfterCommand: ICommand = {
endRow: range.endRow + count,
startColumn: 0,
endColumn: worksheet.getColumnCount() - 1,
+ rangeType: RANGE_TYPE.ROW,
},
};
@@ -377,6 +379,7 @@ export const InsertColBeforeCommand: ICommand = {
endColumn: range.startColumn + count - 1,
startRow: 0,
endRow: worksheet.getLastRowWithContent(),
+ rangeType: RANGE_TYPE.COLUMN,
},
cellValue,
};
diff --git a/packages/sheets/src/index.ts b/packages/sheets/src/index.ts
index 97027720cd..f36bb39f5b 100644
--- a/packages/sheets/src/index.ts
+++ b/packages/sheets/src/index.ts
@@ -291,6 +291,7 @@ export {
runRefRangeMutations,
handleCommonDefaultRangeChangeWithEffectRefCommands,
handleDefaultRangeChangeWithEffectRefCommands,
+ handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests,
} from './services/ref-range/util';
export { INTERCEPTOR_POINT } from './services/sheet-interceptor/interceptor-const';
export { SheetInterceptorService } from './services/sheet-interceptor/sheet-interceptor.service';
diff --git a/packages/sheets/src/services/ref-range/ref-range.service.ts b/packages/sheets/src/services/ref-range/ref-range.service.ts
index b27eee8440..4d81ffef5e 100644
--- a/packages/sheets/src/services/ref-range/ref-range.service.ts
+++ b/packages/sheets/src/services/ref-range/ref-range.service.ts
@@ -24,6 +24,7 @@ import {
IUniverInstanceService,
LifecycleStages,
OnLifecycle,
+ RANGE_TYPE,
Rectangle,
toDisposable,
UniverInstanceType,
@@ -36,7 +37,7 @@ import { SheetInterceptorService } from '../sheet-interceptor/sheet-interceptor.
import type { ISheetCommandSharedParams } from '../../commands/utils/interface';
import type { EffectRefRangeParams } from './type';
import { EffectRefRangId } from './type';
-import { adjustRangeOnMutation } from './util';
+import { adjustRangeOnMutation, getEffectedRangesOnMutation } from './util';
type RefRangCallback = (params: EffectRefRangeParams) => {
redos: IMutationInfo[];
@@ -50,6 +51,8 @@ export type WatchRangeCallback = (before: IRange, after: Nullable<IRange>) => vo
const MERGE_REDO = createInterceptorKey<IMutationInfo[], null>('MERGE_REDO');
const MERGE_UNDO = createInterceptorKey<IMutationInfo[], null>('MERGE_UNDO');
+const MAX_ROW_COL = Math.floor(Number.MAX_SAFE_INTEGER / 10);
+
class WatchRange extends Disposable {
constructor(
private readonly _unitId: string,
@@ -69,6 +72,13 @@ class WatchRange extends Disposable {
if (!this._range) {
return;
}
+ if (this._skipIntersects) {
+ const effectRanges = getEffectedRangesOnMutation(mutation);
+ if (effectRanges?.some((effectRange) => Rectangle.intersects(effectRange, this._range!))) {
+ return false;
+ }
+ }
+
const afterRange: Nullable<IRange> = adjustRangeOnMutation(this._range, mutation);
if (afterRange && Rectangle.equals(afterRange, this._range)) {
return false;
@@ -189,6 +199,7 @@ export class RefRangeService extends Disposable {
endRow: worksheet.getRowCount() - 1,
startColumn: 0,
endColumn: worksheet.getColumnCount() - 1,
+ rangeType: RANGE_TYPE.ROW,
};
return this._checkRange([range], unitId, subUnitId);
}
@@ -200,6 +211,7 @@ export class RefRangeService extends Disposable {
endRow: worksheet.getRowCount() - 1,
startColumn: colStart,
endColumn: worksheet.getColumnCount() - 1,
+ rangeType: RANGE_TYPE.COLUMN,
};
return this._checkRange([range], unitId, subUnitId);
}
@@ -212,6 +224,7 @@ export class RefRangeService extends Disposable {
endRow: worksheet.getRowCount() - 1,
startColumn: 0,
endColumn: worksheet.getColumnCount() - 1,
+ rangeType: RANGE_TYPE.ROW,
};
return this._checkRange([range], unitId, subUnitId);
}
@@ -223,6 +236,7 @@ export class RefRangeService extends Disposable {
endRow: worksheet.getRowCount() - 1,
startColumn: colStart,
endColumn: worksheet.getColumnCount() - 1,
+ rangeType: RANGE_TYPE.COLUMN,
};
return this._checkRange([range], unitId, subUnitId);
}
@@ -234,7 +248,7 @@ export class RefRangeService extends Disposable {
startRow: range.startRow,
startColumn: range.startColumn,
endColumn: range.endColumn,
- endRow: worksheet.getRowCount() - 1,
+ endRow: MAX_ROW_COL,
};
return this._checkRange([effectRange], unitId, subUnitId);
}
@@ -245,7 +259,7 @@ export class RefRangeService extends Disposable {
const effectRange = {
startRow: range.startRow,
startColumn: range.startColumn,
- endColumn: worksheet.getColumnCount() - 1,
+ endColumn: MAX_ROW_COL,
endRow: range.endRow,
};
return this._checkRange([effectRange], unitId, subUnitId);
@@ -318,9 +332,12 @@ export class RefRangeService extends Disposable {
endRow: +range.endRow,
startColumn: +range.startColumn,
endColumn: +range.endColumn,
+ rangeType: range.rangeType && +range.rangeType,
};
// Todo@Gggpound : How to reduce this calculation
- if (effectRanges.some((item) => Rectangle.intersects(item, realRange))) {
+ if (
+ effectRanges.some((item) => Rectangle.intersects(item, realRange))
+ ) {
cbList &&
cbList.forEach((callback) => {
callbackSet.add(callback);
diff --git a/packages/sheets/src/services/ref-range/util.ts b/packages/sheets/src/services/ref-range/util.ts
index f89bfe8984..39dbc9094d 100644
--- a/packages/sheets/src/services/ref-range/util.ts
+++ b/packages/sheets/src/services/ref-range/util.ts
@@ -108,6 +108,7 @@ interface ILine {
/**
* see docs/tldr/ref-range/move-rows-cols.tldr
*/
+// eslint-disable-next-line max-lines-per-function, complexity
export const handleBaseMoveRowsCols = (
fromRange: ILine,
toRange: ILine,
@@ -909,6 +910,15 @@ export const handleDefaultRangeChangeWithEffectRefCommands = (range: IRange, com
return resultRange;
};
+export const handleDefaultRangeChangeWithEffectRefCommandsSkipNoInterests = (range: IRange, commandInfo: ICommandInfo, deps: { selectionManagerService: SelectionManagerService }) => {
+ const effectRanges = getEffectedRangesOnCommand(commandInfo as EffectRefRangeParams, deps);
+ if (effectRanges.some((effectRange) => Rectangle.intersects(effectRange, range))) {
+ return handleDefaultRangeChangeWithEffectRefCommands(range, commandInfo);
+ }
+
+ return range;
+};
+
type MutationsAffectRange =
ISheetCommandSharedParams
| IRemoveSheetMutationParams
@@ -1003,6 +1013,7 @@ export function adjustRangeOnMutation(range: Readonly<IRange>, mutation: IMutati
{ start: (params as IMoveColumnsMutationParams).targetRange.startColumn, end: (params as IMoveColumnsMutationParams).targetRange.endColumn },
{ start: range.startColumn, end: range.endColumn }
);
+ baseRangeOperator.type = OperatorType.HorizontalMove;
break;
case RemoveColMutation.id:
baseRangeOperator = handleBaseRemoveRange((params as IRemoveColMutationParams).range, range);
@@ -1045,22 +1056,31 @@ export function adjustRangeOnMutation(range: Readonly<IRange>, mutation: IMutati
}
}
-const MAX_BOUND = Math.floor(Number.MAX_SAFE_INTEGER / 10);
-
// eslint-disable-next-line max-lines-per-function
export function getEffectedRangesOnCommand(command: EffectRefRangeParams, deps: { selectionManagerService: SelectionManagerService }) {
const { selectionManagerService } = deps;
switch (command.id) {
case EffectRefRangId.MoveColsCommandId: {
const params = command.params!;
- const startColumn = Math.min(params.fromRange.startColumn, params.toRange.startColumn);
- return [{ ...params.fromRange, startColumn, endColumn: MAX_BOUND }];
+ return [
+ params.fromRange,
+ {
+ ...params.toRange,
+ startColumn: params.toRange.startColumn - 0.5,
+ endColumn: params.toRange.endColumn - 0.5,
+ },
+ ];
}
case EffectRefRangId.MoveRowsCommandId: {
const params = command.params!;
- const startRow = Math.min(params.fromRange.startRow, params.toRange.startRow);
-
- return [{ ...params.fromRange, startRow, endRow: MAX_BOUND }];
+ return [
+ params.fromRange,
+ {
+ ...params.toRange,
+ startRow: params.toRange.startRow - 0.5,
+ endRow: params.toRange.startRow - 0.5,
+ },
+ ];
}
case EffectRefRangId.MoveRangeCommandId: {
const params = command;
@@ -1068,47 +1088,34 @@ export function getEffectedRangesOnCommand(command: EffectRefRangeParams, deps:
}
case EffectRefRangId.InsertRowCommandId: {
const params = command;
- const rowStart = params.params!.range.startRow;
- const range: IRange = {
- startRow: rowStart,
- endRow: MAX_BOUND,
- startColumn: 0,
- endColumn: MAX_BOUND,
- };
- return [range];
+ const range: IRange = params.params!.range;
+ return [
+ {
+ ...range,
+ startRow: range.startRow - 0.5,
+ endRow: range.endRow - 0.5,
+ },
+ ];
}
case EffectRefRangId.InsertColCommandId: {
const params = command;
- const colStart = params.params!.range.startColumn;
- const range: IRange = {
- startRow: 0,
- endRow: MAX_BOUND,
- startColumn: colStart,
- endColumn: MAX_BOUND,
- };
- return [range];
+ const range: IRange = params.params!.range;
+ return [
+ {
+ ...range,
+ startColumn: range.startColumn - 0.5,
+ endColumn: range.endColumn - 0.5,
+ },
+ ];
}
case EffectRefRangId.RemoveRowCommandId: {
const params = command;
-
- const rowStart = params.params!.range.startRow;
- const range: IRange = {
- startRow: rowStart,
- endRow: MAX_BOUND,
- startColumn: 0,
- endColumn: MAX_BOUND,
- };
+ const range: IRange = params.params!.range;
return [range];
}
case EffectRefRangId.RemoveColCommandId: {
const params = command;
- const colStart = params.params!.range.startColumn;
- const range: IRange = {
- startRow: 0,
- endRow: MAX_BOUND,
- startColumn: colStart,
- endColumn: MAX_BOUND,
- };
+ const range: IRange = params.params!.range;
return [range];
}
case EffectRefRangId.DeleteRangeMoveUpCommandId:
@@ -1118,13 +1125,7 @@ export function getEffectedRangesOnCommand(command: EffectRefRangeParams, deps:
if (!range) {
return [];
}
- const effectRange = {
- startRow: range.startRow,
- startColumn: range.startColumn,
- endColumn: range.endColumn,
- endRow: MAX_BOUND,
- };
- return [effectRange];
+ return [range];
}
case EffectRefRangId.DeleteRangeMoveLeftCommandId:
case EffectRefRangId.InsertRangeMoveRightCommandId: {
@@ -1133,13 +1134,7 @@ export function getEffectedRangesOnCommand(command: EffectRefRangeParams, deps:
if (!range) {
return [];
}
- const effectRange = {
- startRow: range.startRow,
- startColumn: range.startColumn,
- endColumn: MAX_BOUND,
- endRow: range.endRow,
- };
- return [effectRange];
+ return [range];
}
}
}
@@ -1148,13 +1143,25 @@ export function getEffectedRangesOnMutation(mutation: IMutationInfo<MutationsAff
switch (mutation.id) {
case MoveColsMutation.id: {
const params = mutation.params as IMoveColumnsMutationParams;
- const startColumn = Math.min(params.sourceRange.startColumn, params.targetRange.startColumn);
- return [{ ...params.sourceRange, startColumn, endColumn: MAX_BOUND }];
+ return [
+ params.sourceRange,
+ {
+ ...params.targetRange,
+ startColumn: params.targetRange.startColumn - 0.5,
+ endColumn: params.targetRange.endColumn - 0.5,
+ },
+ ];
}
case MoveRowsMutation.id: {
const params = mutation.params as IMoveRowsMutationParams;
- const startRow = Math.min(params.sourceRange.startRow, params.targetRange.startRow);
- return [{ ...params.sourceRange, startRow, endRow: MAX_BOUND }];
+ return [
+ params.sourceRange,
+ {
+ ...params.targetRange,
+ startRow: params.targetRange.startRow - 0.5,
+ endRow: params.targetRange.startRow - 0.5,
+ },
+ ];
}
case MoveRangeMutation.id: {
@@ -1163,46 +1170,34 @@ export function getEffectedRangesOnMutation(mutation: IMutationInfo<MutationsAff
}
case InsertColMutation.id: {
const params = mutation.params as IInsertColMutationParams;
- const colStart = params.range.startColumn;
- const range: IRange = {
- startRow: 0,
- endRow: MAX_BOUND,
- startColumn: colStart,
- endColumn: MAX_BOUND,
- };
- return [range];
+ const range: IRange = params.range;
+ return [
+ {
+ ...range,
+ startColumn: range.startColumn - 0.5,
+ endColumn: range.endColumn - 0.5,
+ },
+ ];
}
case InsertRowMutation.id: {
const params = mutation.params as IInsertRowMutationParams;
- const rowStart = params.range.startRow;
- const range: IRange = {
- startRow: rowStart,
- endRow: MAX_BOUND,
- startColumn: 0,
- endColumn: MAX_BOUND,
- };
- return [range];
+ const range: IRange = params.range;
+ return [
+ {
+ ...range,
+ startRow: range.startRow - 0.5,
+ endRow: range.endRow - 0.5,
+ },
+ ];
}
case RemoveColMutation.id: {
const params = mutation.params as IRemoveColMutationParams;
- const colStart = params.range.startColumn;
- const range: IRange = {
- startRow: 0,
- endRow: MAX_BOUND,
- startColumn: colStart,
- endColumn: MAX_BOUND,
- };
+ const range: IRange = params.range;
return [range];
}
case RemoveRowMutation.id: {
const params = mutation.params as IRemoveRowsMutationParams;
- const rowStart = params.range.startRow;
- const range: IRange = {
- startRow: rowStart,
- endRow: MAX_BOUND,
- startColumn: 0,
- endColumn: MAX_BOUND,
- };
+ const range: IRange = params.range;
return [range];
}
default:
diff --git a/packages/thread-comment/src/commands/mutations/comment.mutation.ts b/packages/thread-comment/src/commands/mutations/comment.mutation.ts
index 1421ca8f47..db092c511a 100644
--- a/packages/thread-comment/src/commands/mutations/comment.mutation.ts
+++ b/packages/thread-comment/src/commands/mutations/comment.mutation.ts
@@ -50,6 +50,7 @@ export interface IUpdateCommentMutationParams {
unitId: string;
subUnitId: string;
payload: IUpdateCommentPayload;
+ silent?: boolean;
}
export const UpdateCommentMutation: ICommand<IUpdateCommentMutationParams> = {
@@ -60,8 +61,8 @@ export const UpdateCommentMutation: ICommand<IUpdateCommentMutationParams> = {
return false;
}
const threadCommentModel = accessor.get(ThreadCommentModel);
- const { unitId, subUnitId, payload } = params;
- return threadCommentModel.updateComment(unitId, subUnitId, payload);
+ const { unitId, subUnitId, payload, silent } = params;
+ return threadCommentModel.updateComment(unitId, subUnitId, payload, silent);
},
};
@@ -74,6 +75,7 @@ export interface IUpdateCommentRefMutationParams {
unitId: string;
subUnitId: string;
payload: IUpdateCommentRefPayload;
+ silent?: boolean;
}
export const UpdateCommentRefMutation: ICommand<IUpdateCommentRefMutationParams> = {
@@ -84,8 +86,8 @@ export const UpdateCommentRefMutation: ICommand<IUpdateCommentRefMutationParams>
return false;
}
const threadCommentModel = accessor.get(ThreadCommentModel);
- const { unitId, subUnitId, payload } = params;
- return threadCommentModel.updateCommentRef(unitId, subUnitId, payload);
+ const { unitId, subUnitId, payload, silent } = params;
+ return threadCommentModel.updateCommentRef(unitId, subUnitId, payload, silent);
},
};
diff --git a/packages/thread-comment/src/models/thread-comment.model.ts b/packages/thread-comment/src/models/thread-comment.model.ts
index 14cd2252c7..116015fb71 100644
--- a/packages/thread-comment/src/models/thread-comment.model.ts
+++ b/packages/thread-comment/src/models/thread-comment.model.ts
@@ -22,16 +22,14 @@ import type { IUpdateCommentPayload, IUpdateCommentRefPayload } from '../command
export type CommentUpdate = {
unitId: string;
subUnitId: string;
+ silent?: boolean;
+} & ({
type: 'add';
payload: IThreadComment;
} | {
- unitId: string;
- subUnitId: string;
type: 'update';
payload: IUpdateCommentPayload;
} | {
- unitId: string;
- subUnitId: string;
type: 'delete';
payload: {
commentId: string;
@@ -39,19 +37,15 @@ export type CommentUpdate = {
comment: IThreadComment;
};
} | {
- unitId: string;
- subUnitId: string;
type: 'updateRef';
payload: IUpdateCommentRefPayload;
} | {
- unitId: string;
- subUnitId: string;
type: 'resolve';
payload: {
commentId: string;
resolved: boolean;
};
-};
+});
export class ThreadCommentModel {
private _commentsMap: Record<string, Record<string, Record<string, IThreadComment>>> = {};
@@ -166,7 +160,7 @@ export class ThreadCommentModel {
return true;
}
- updateComment(unitId: string, subUnitId: string, payload: IUpdateCommentPayload) {
+ updateComment(unitId: string, subUnitId: string, payload: IUpdateCommentPayload, silent?: boolean) {
const { commentMap } = this.ensureMap(unitId, subUnitId);
const oldComment = commentMap[payload.commentId];
if (!oldComment) {
@@ -182,13 +176,14 @@ export class ThreadCommentModel {
subUnitId,
type: 'update',
payload,
+ silent,
});
this._refreshCommentsMap$();
this._refreshCommentsTreeMap$();
return true;
}
- updateCommentRef(unitId: string, subUnitId: string, payload: IUpdateCommentRefPayload) {
+ updateCommentRef(unitId: string, subUnitId: string, payload: IUpdateCommentRefPayload, silent?: boolean) {
const { commentMap } = this.ensureMap(unitId, subUnitId);
const oldComment = commentMap[payload.commentId];
if (!oldComment) {
@@ -202,6 +197,7 @@ export class ThreadCommentModel {
subUnitId,
type: 'updateRef',
payload,
+ silent,
});
this._refreshCommentsMap$();
this._refreshCommentsTreeMap$();
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index c3cb7c3312..d62d99c783 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1632,6 +1632,9 @@ importers:
'@univerjs/core':
specifier: workspace:*
version: link:../core
+ '@univerjs/engine-formula':
+ specifier: workspace:*
+ version: link:../engine-formula
'@univerjs/protocol':
specifier: ^0.1.36
version: 0.1.36(@grpc/[email protected])([email protected])
@@ -1784,6 +1787,9 @@ importers:
'@univerjs/sheets':
specifier: workspace:*
version: link:../sheets
+ '@univerjs/sheets-thread-comment-base':
+ specifier: workspace:*
+ version: link:../sheets-thread-comment-base
'@univerjs/sheets-ui':
specifier: workspace:*
version: link:../sheets-ui
@@ -1831,6 +1837,52 @@ importers:
specifier: ^1.6.0
+ packages/sheets-thread-comment-base:
+ dependencies:
+ '@univerjs/engine-render':
+ specifier: workspace:*
+ version: link:../engine-render
+ '@univerjs/sheets':
+ specifier: workspace:*
+ version: link:../sheets
+ '@univerjs/thread-comment':
+ specifier: workspace:*
+ version: link:../thread-comment
+ devDependencies:
+ '@univerjs/core':
+ specifier: workspace:*
+ version: link:../core
+ '@univerjs/design':
+ specifier: workspace:*
+ version: link:../design
+ '@univerjs/engine-formula':
+ specifier: workspace:*
+ version: link:../engine-formula
+ '@univerjs/shared':
+ specifier: workspace:*
+ version: link:../../common/shared
+ '@univerjs/ui':
+ specifier: workspace:*
+ version: link:../ui
+ '@wendellhu/redi':
+ specifier: 0.15.2
+ version: 0.15.2
+ react:
+ specifier: 18.2.0
+ version: 18.2.0
+ rxjs:
+ specifier: ^7.8.1
+ version: 7.8.1
+ typescript:
+ specifier: ^5.4.5
+ version: 5.4.5
+ vite:
+ specifier: ^5.2.12
+ vitest:
+ specifier: ^1.6.0
+
packages/sheets-ui:
dependencies:
'@univerjs/docs-ui':