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.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
fix(sheets-data-validation): data validation event trigger before data applied (#3498)
zhangwc4601a05beab
diff --git a/packages/data-validation/src/models/data-validation-model.ts b/packages/data-validation/src/models/data-validation-model.tsindex b044da6fb2..1502bf1688 100644--- a/packages/data-validation/src/models/data-validation-model.ts+++ b/packages/data-validation/src/models/data-validation-model.ts@@ -145,24 +145,28 @@ export class DataValidationModel extends Disposable {if (oldRule) {return;}- this._ruleChange$.next({++ return {rule,type: 'add',unitId,subUnitId,source,- });+ } as const;}addRule(unitId: string, subUnitId: string, rule: IDataValidationRule | IDataValidationRule[], source: DataValidationChangeSource, index?: number) {try {const subUnitMap = this._ensureMap(unitId, subUnitId);const rules = Array.isArray(rule) ? rule : [rule];- rules.forEach((item) => {- this._addRuleSideEffect(unitId, subUnitId, item, source);- });+ const effects = rules.map((item) => this._addRuleSideEffect(unitId, subUnitId, item, source));this._addSubUnitRule(subUnitMap, rule, index);+ effects.forEach((effect) => {+ if (effect) {+ this._ruleChange$.next(effect);+ }+ });} catch (error) {this._logService.error(error);}diff --git a/packages/docs-thread-comment-ui/src/controllers/doc-thread-comment-selection.controller.ts b/packages/docs-thread-comment-ui/src/controllers/doc-thread-comment-selection.controller.tsindex cc30ecbfac..7688d7ba38 100644--- a/packages/docs-thread-comment-ui/src/controllers/doc-thread-comment-selection.controller.ts+++ b/packages/docs-thread-comment-ui/src/controllers/doc-thread-comment-selection.controller.ts@@ -97,7 +97,7 @@ export class DocThreadCommentSelectionController extends Disposable {const doc = this._univerInstanceService.getUnit<DocumentDataModel>(activeComment.unitId);if (doc) {const backScrollController = this._renderManagerService.getRenderById(activeComment.unitId)?.with(DocBackScrollRenderController);- const customRange = doc.getCustomRanges()?.find((range) => range.rangeId === activeComment.commentId);+ const customRange = doc.getBody()?.customDecorations?.find((range) => range.id === activeComment.commentId);if (customRange && backScrollController) {backScrollController.scrollToRange({startOffset: customRange.startIndex,diff --git a/packages/sheets-data-validation/src/models/sheet-data-validation-model.ts b/packages/sheets-data-validation/src/models/sheet-data-validation-model.tsindex 9cbca56803..1a1eedfa98 100644--- a/packages/sheets-data-validation/src/models/sheet-data-validation-model.ts+++ b/packages/sheets-data-validation/src/models/sheet-data-validation-model.ts@@ -98,12 +98,13 @@ export class SheetDataValidationModel extends Disposable {unitMap = new Map();this._ruleMatrixMap.set(unitId, unitMap);}- const worksheet = workbook.getSheetBySheetId(subUnitId);- if (!worksheet) {- throw new Error(`worksheet not found, unitId: ${unitId}, subUnitId: ${subUnitId}`);- }+let matrix = unitMap.get(subUnitId);if (!matrix) {+ const worksheet = workbook.getSheetBySheetId(subUnitId);+ if (!worksheet) {+ throw new Error(`worksheet not found, unitId: ${unitId}, subUnitId: ${subUnitId}`);+ }matrix = new RuleMatrix(new Map(), worksheet);unitMap.set(subUnitId, matrix);}