Skip to content

Commit

Permalink
Merge branch 'dev' into feat/slide-dep
Browse files Browse the repository at this point in the history
  • Loading branch information
lumixraku authored Aug 14, 2024
2 parents ad69371 + 92dedd6 commit 12cab3d
Show file tree
Hide file tree
Showing 52 changed files with 387 additions and 370 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function updateTextRuns(
return removeTextRuns;
}

// eslint-disable-next-line max-lines-per-function
// eslint-disable-next-line max-lines-per-function, complexity
export function coverTextRuns(
updateDataTextRuns: ITextRun[],
removeTextRuns: ITextRun[],
Expand Down Expand Up @@ -202,7 +202,7 @@ export function coverTextRuns(
const updateLastTextRun = updateDataTextRuns[updateLength - 1];
const removeLastTextRun = removeTextRuns[removeLength - 1];

if (tempTopTextRun.ed !== Math.max(updateLastTextRun.ed, removeLastTextRun.ed)) {
if (tempTopTextRun && (tempTopTextRun.ed !== Math.max(updateLastTextRun.ed, removeLastTextRun.ed))) {
if (updateLastTextRun.ed > removeLastTextRun.ed) {
newUpdateTextRuns.push(updateLastTextRun);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import type { CellValue, IDataValidationRule, IDataValidationRuleBase, Nullable } from '@univerjs/core';
import type { CellValue, IDataValidationRule, IDataValidationRuleBase, Nullable, Workbook, Worksheet } from '@univerjs/core';
import { DataValidationOperator, Inject, Injector, LocaleService, Tools } from '@univerjs/core';
import { OperatorErrorTitleMap, OperatorTitleMap } from '../types/const/operator-text-map';
import type { IBaseDataValidationWidget } from './base-widget';
Expand All @@ -39,6 +39,8 @@ export interface IValidatorCellInfo<DataType = Nullable<CellValue>> {
column: number;
unitId: string;
subUnitId: string;
worksheet: Worksheet;
workbook: Workbook;
}

export interface IFormulaResult<T = any> {
Expand Down Expand Up @@ -107,7 +109,7 @@ export abstract class BaseDataValidator<DataType = CellValue> {
}

getRuleFinalError(rule: IDataValidationRule) {
if (rule.showInputMessage && rule.error) {
if (rule.showErrorMessage && rule.error) {
return rule.error;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { CommandType, CustomRangeType, generateRandomId, type ICommand, ICommandService, sequenceExecuteAsync } from '@univerjs/core';
import { CommandType, CustomRangeType, generateRandomId, type ICommand, ICommandService, sequenceExecute } from '@univerjs/core';
import { addCustomRangeBySelectionFactory } from '@univerjs/docs';
import { AddDocHyperLinkMutation } from '@univerjs/docs-hyper-link';

Expand Down Expand Up @@ -47,7 +47,7 @@ export const AddDocHyperLinkCommand: ICommand<IAddDocHyperLinkCommandParams> = {
params: { unitId, link: { payload, id } },
};

return (await sequenceExecuteAsync([hyperLinkMutation, doMutation], commandService)).result;
return (await sequenceExecute([hyperLinkMutation, doMutation], commandService)).result;
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ export class DocHyperLinkClipboardController extends Disposable {
customRanges?.find(
(range) =>
range.rangeType === CustomRangeType.HYPERLINK &&
range.startIndex <= activeRange.startOffset &&
range.endIndex >= activeRange.endOffset - 1
range.startIndex < activeRange.startOffset &&
range.endIndex > activeRange.endOffset - 1
)
: null;
// insert into current link inside
Expand Down
6 changes: 3 additions & 3 deletions packages/docs-ui/src/services/doc-popup-manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ export function transformPosition2Offset(x: number, y: number, scene: Scene) {
};
}

export interface IDocCanvasPopup extends Pick<IPopup,
'direction' | 'excludeOutside' | 'closeOnSelfTarget' | 'componentKey' | 'offset' | 'onClickOutside'
> {
export interface IDocCanvasPopup extends Pick<IPopup, 'direction' | 'excludeOutside' | 'closeOnSelfTarget' | 'componentKey' | 'offset' | 'onClickOutside' | 'hideOnInvisible'> {
mask?: boolean;
extraProps?: Record<string, any>;
}
Expand Down Expand Up @@ -223,6 +221,7 @@ export class DocCanvasPopManagerService extends Disposable {
subUnitId: 'default',
anchorRect: position,
anchorRect$: position$,
canvasElement: currentRender.engine.getCanvasElement(),
});

return {
Expand Down Expand Up @@ -259,6 +258,7 @@ export class DocCanvasPopManagerService extends Disposable {
excludeRects: bounds,
excludeRects$: bounds$,
direction: direction === 'top' ? 'top' : 'bottom',
canvasElement: currentRender.engine.getCanvasElement(),
});

return {
Expand Down
11 changes: 7 additions & 4 deletions packages/docs/src/basics/replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export function getRetainAndDeleteAndExcludeLineBreak(
selection: ITextRange,
body: IDocumentBody,
segmentId: string = '',
memoryCursor: number = 0
memoryCursor: number = 0,
preserveLineBreak: boolean = true
): Array<IRetainAction | IDeleteAction> {
const { startOffset, endOffset } = getDeleteSelection(selection, body);
const dos: Array<IRetainAction | IDeleteAction> = [];
Expand Down Expand Up @@ -73,9 +74,11 @@ export function getRetainAndDeleteAndExcludeLineBreak(
});
}

if (paragraphInRange && paragraphInRange.startIndex - memoryCursor > textStart) {
const paragraphIndex = paragraphInRange.startIndex - memoryCursor;
retainPoints.add(paragraphIndex);
if (preserveLineBreak) {
if (paragraphInRange && paragraphInRange.startIndex - memoryCursor > textStart) {
const paragraphIndex = paragraphInRange.startIndex - memoryCursor;
retainPoints.add(paragraphIndex);
}
}

const sortedRetains = [...retainPoints].sort((pre, aft) => pre - aft);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function getCutActionsFromTextRanges(
segmentId,
});
} else {
textX.push(...getRetainAndDeleteAndExcludeLineBreak(selection, originBody, segmentId, memoryCursor.cursor));
textX.push(...getRetainAndDeleteAndExcludeLineBreak(selection, originBody, segmentId, memoryCursor.cursor, false));
}

memoryCursor.reset();
Expand Down Expand Up @@ -393,7 +393,6 @@ export const CutContentCommand: ICommand<IInnerCutCommandParams> = {
const commandService = accessor.get(ICommandService);
const textSelectionManagerService = accessor.get(TextSelectionManagerService);
const univerInstanceService = accessor.get(IUniverInstanceService);

const selections = params.selections ?? textSelectionManagerService.getCurrentTextRanges();
const rectRanges = textSelectionManagerService.getCurrentRectRanges();

Expand Down Expand Up @@ -434,7 +433,6 @@ export const CutContentCommand: ICommand<IInnerCutCommandParams> = {
if (Array.isArray(selections) && selections?.length !== 0) {
doMutation.params.actions = getCutActionsFromTextRanges(selections, docDataModel, segmentId);
}

if (Array.isArray(rectRanges) && rectRanges?.length !== 0) {
const actions = getCutActionsFromRectRanges(rectRanges, docDataModel, viewModel, segmentId);
if (doMutation.params.actions?.length === 0 || doMutation.params.actions == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export const ReplaceSelectionCommand: ICommand<IReplaceSelectionCommandParams> =
const textX = new TextX();
const jsonX = JSONX.getInstance();
// delete
textX.push(...getRetainAndDeleteAndExcludeLineBreak(selection, body));
textX.push(...getRetainAndDeleteAndExcludeLineBreak(selection, body, '', 0, false));
// insert
textX.push({
t: TextXActionType.INSERT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class DataValidationRejectInputController extends Disposable {
{
handler: async (cellPromise, context, next) => {
const cell = await cellPromise;
const { worksheet, row, col, unitId, subUnitId } = context;
const { worksheet, row, col, unitId, subUnitId, workbook } = context;
const manager = this._dataValidationModel.ensureManager(unitId, subUnitId) as SheetDataValidationManager;
const ruleId = manager.getRuleIdByLocation(row, col);
const rule = ruleId ? manager.getRuleById(ruleId) : undefined;
Expand All @@ -62,6 +62,8 @@ export class DataValidationRejectInputController extends Disposable {
column: col,
unitId,
subUnitId,
worksheet,
workbook,
}, rule
);

Expand Down
32 changes: 1 addition & 31 deletions packages/sheets-data-validation/src/controllers/dv.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
*/

import type { Workbook } from '@univerjs/core';
import { DisposableCollection, Inject, Injector, IUniverInstanceService, LifecycleStages, OnLifecycle, RxDisposable, toDisposable, UniverInstanceType } from '@univerjs/core';
import { Inject, Injector, IUniverInstanceService, LifecycleStages, OnLifecycle, RxDisposable, UniverInstanceType } from '@univerjs/core';
import { DataValidationModel, DataValidatorRegistryService } from '@univerjs/data-validation';
import { DataValidationSingle } from '@univerjs/icons';
import { ComponentManager } from '@univerjs/ui';
import { ClearSelectionAllCommand, SheetInterceptorService, SheetsSelectionsService } from '@univerjs/sheets';
import { SheetDataValidationService } from '../services/dv.service';
import { CustomFormulaValidator } from '../validators/custom-validator';
import { CheckboxValidator, DateValidator, DecimalValidator, ListValidator, TextLengthValidator } from '../validators';
import { WholeValidator } from '../validators/whole-validator';
Expand All @@ -39,7 +38,6 @@ import { DataValidationIcon } from './dv.menu';
export class DataValidationController extends RxDisposable {
constructor(
@IUniverInstanceService private readonly _univerInstanceService: IUniverInstanceService,
@Inject(SheetDataValidationService) private readonly _sheetDataValidationService: SheetDataValidationService,
@Inject(DataValidatorRegistryService) private readonly _dataValidatorRegistryService: DataValidatorRegistryService,
@Inject(Injector) private readonly _injector: Injector,
@Inject(ComponentManager) private readonly _componentManger: ComponentManager,
Expand All @@ -53,7 +51,6 @@ export class DataValidationController extends RxDisposable {

private _init() {
this._registerValidators();
this._initInstanceChange();
this._initCommandInterceptor();
this._initComponents();
}
Expand Down Expand Up @@ -81,33 +78,6 @@ export class DataValidationController extends RxDisposable {
});
}

private _initInstanceChange() {
const disposableCollection = new DisposableCollection();
this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$<Workbook>(UniverInstanceType.UNIVER_SHEET).subscribe((workbook) => {
disposableCollection.dispose();
if (!workbook) {
return;
}
const worksheet = workbook.getActiveSheet();
if (!worksheet) {
return;
}

this._sheetDataValidationService.switchCurrent(workbook.getUnitId(), worksheet.getSheetId());
disposableCollection.add(toDisposable(
workbook.activeSheet$.subscribe((worksheet) => {
if (worksheet) {
const unitId = workbook.getUnitId();
const subUnitId = worksheet.getSheetId();
this._sheetDataValidationService.switchCurrent(unitId, subUnitId);
}
})
));
}));

this.disposeWithMe(disposableCollection);
}

private _initCommandInterceptor() {
this._sheetInterceptorService.interceptCommand({
getMutations: (commandInfo) => {
Expand Down
9 changes: 0 additions & 9 deletions packages/sheets-data-validation/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,10 @@

export { UniverSheetsDataValidationPlugin } from './plugin';
export { UniverSheetsDataValidationMobilePlugin } from './mobile-plugin';
export { SheetsDataValidationRenderController } from './controllers/dv-render.controller';
export { DataValidationController } from './controllers/dv.controller';
export { SheetDataValidationService } from './services/dv.service';
export { DataValidationAlertController } from './controllers/dv-alert.controller';
export { DataValidationCacheService } from './services/dv-cache.service';
export { DataValidationFormulaService } from './services/dv-formula.service';
export { DataValidationCustomFormulaService } from './services/dv-custom-formula.service';
export { DataValidationRefRangeController } from './controllers/dv-ref-range.controller';
export { DATA_VALIDATION_PLUGIN_NAME } from './common/const';
export { DataValidationAutoFillController } from './controllers/dv-auto-fill.controller';
export { DataValidationCopyPasteController } from './controllers/dv-copy-paste.controller';
export { DataValidationRejectInputController } from './controllers/dv-reject-input.controller';
export { DataValidationFormulaController } from './controllers/dv-formula.controller';
export { SheetsDataValidationValidatorService } from './services/dv-validator-service';

// #region - all commands
Expand Down
17 changes: 9 additions & 8 deletions packages/sheets-data-validation/src/locale/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ const locale: typeof zhCN = {
notBetween: 'is not between {FORMULA1}',
},
errorMsg: {
between: 'Value must be between {FORMULA1} and {FORMULA2}',
greaterThan: 'Value must be after {FORMULA1}',
greaterThanOrEqual: 'Value must be on or after {FORMULA1}',
lessThan: 'Value must be before {FORMULA1}',
lessThanOrEqual: 'Value must be on or before {FORMULA1}',
equal: 'Value must be {FORMULA1}',
notEqual: 'Value must be not {FORMULA1}',
notBetween: 'Value must be not between {FORMULA1}',
between: 'Value must be a legal date and between {FORMULA1} and {FORMULA2}',
greaterThan: 'Value must be a legal date and after {FORMULA1}',
greaterThanOrEqual: 'Value must be a legal date and on or after {FORMULA1}',
lessThan: 'Value must be a legal date and before {FORMULA1}',
lessThanOrEqual: 'Value must be a legal date and on or before {FORMULA1}',
equal: 'Value must be a legal date and {FORMULA1}',
notEqual: 'Value must be a legal date and not {FORMULA1}',
notBetween: 'Value must be a legal date and not between {FORMULA1}',
},
},
list: {
Expand All @@ -128,6 +128,7 @@ const locale: typeof zhCN = {
customOptions: 'Custom',
refOptions: 'From a range',
formulaError: 'The list source must be a delimited list of data, or a reference to a single row or column.',
edit: 'Edit',
},
listMultiple: {
title: 'Dropdown-Multiple',
Expand Down
1 change: 1 addition & 0 deletions packages/sheets-data-validation/src/locale/ru-RU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ const locale: typeof zhCN = {
customOptions: 'Пользовательские',
refOptions: 'Из диапазона',
formulaError: 'Источник списка должен быть разделенным списком данных или ссылкой на одну строку или столбец.',
edit: 'Редактировать',
},
listMultiple: {
title: 'Выпадающий список - Множественный',
Expand Down
1 change: 1 addition & 0 deletions packages/sheets-data-validation/src/locale/vi-VN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ const locale: typeof zhCN = {
customOptions: 'Tùy chỉnh',
refOptions: 'Tham chiếu dữ liệu',
formulaError: 'Nguồn danh sách phải là danh sách dữ liệu đã được phân chia rõ ràng, hoặc là tham chiếu đến một hàng hoặc cột đơn.',
edit: 'Biên tập',
},
listMultiple: {
title: 'Danh sách thả xuống - Chọn nhiều',
Expand Down
17 changes: 9 additions & 8 deletions packages/sheets-data-validation/src/locale/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ const locale = {
notBetween: '在 {FORMULA1} 和 {FORMULA2} 范围之外',
},
errorMsg: {
between: '日期必须介于 {FORMULA1} 和 {FORMULA2} 之间',
greaterThan: '日期必须晚于 {FORMULA1}',
greaterThanOrEqual: '日期必须晚于或等于 {FORMULA1}',
lessThan: '日期必须早于 {FORMULA1}',
lessThanOrEqual: '早于或等于 {FORMULA1}',
equal: '日期必须等于 {FORMULA1}',
notEqual: '日期必须不等于 {FORMULA1}',
notBetween: '日期必须在 {FORMULA1} 和 {FORMULA2} 范围之外',
between: '必须为有效日期且介于 {FORMULA1} 和 {FORMULA2} 之间',
greaterThan: '必须为有效日期且晚于 {FORMULA1}',
greaterThanOrEqual: '必须为有效日期且晚于或等于 {FORMULA1}',
lessThan: '必须为有效日期且早于 {FORMULA1}',
lessThanOrEqual: '必须为有效日期且早于或等于 {FORMULA1}',
equal: '必须为有效日期且等于 {FORMULA1}',
notEqual: '必须为有效日期且不等于 {FORMULA1}',
notBetween: '必须为有效日期且在 {FORMULA1} 和 {FORMULA2} 范围之外',
},
},
list: {
Expand All @@ -128,6 +128,7 @@ const locale = {
customOptions: '自定义',
refOptions: '引用数据',
formulaError: '列表源必须是划定分界后的数据列表,或是对单一行或一列的引用。',
edit: '编辑',
},
listMultiple: {
title: '下拉菜单-多选',
Expand Down
1 change: 1 addition & 0 deletions packages/sheets-data-validation/src/locale/zh-TW.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ const locale: typeof zhCN = {
customOptions: '自訂',
refOptions: '引用資料',
formulaError: '列表來源必須是劃定分界後的資料列表,或是對單一行或一列的引用。 ',
edit: '編輯',
},
listMultiple: {
title: '下拉式選單-多選',
Expand Down
2 changes: 0 additions & 2 deletions packages/sheets-data-validation/src/mobile-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { UniverSheetsUIPlugin } from '@univerjs/sheets-ui';
import type { IUniverSheetsDataValidation } from './controllers/dv-render.controller';
import { DefaultSheetsDataValidation, SheetsDataValidationMobileRenderController } from './controllers/dv-render.controller';
import { DataValidationController } from './controllers/dv.controller';
import { SheetDataValidationService } from './services/dv.service';
import { DataValidationAlertController } from './controllers/dv-alert.controller';
import { AddSheetDataValidationAndOpenCommand, AddSheetDataValidationCommand, UpdateSheetDataValidationRangeCommand } from './commands/commands/data-validation.command';
import { DataValidationCacheService } from './services/dv-cache.service';
Expand Down Expand Up @@ -58,7 +57,6 @@ export class UniverSheetsDataValidationMobilePlugin extends Plugin {
override onStarting() {
([
[DataValidationPanelService],
[SheetDataValidationService],
[DataValidationCacheService],
[DataValidationFormulaService],
[DataValidationCustomFormulaService],
Expand Down
Loading

0 comments on commit 12cab3d

Please sign in to comment.