Skip to content

Commit

Permalink
Merge branch 'dev' into fix/font-cell
Browse files Browse the repository at this point in the history
  • Loading branch information
lumixraku authored Oct 15, 2024
2 parents c5105b7 + 555e9d5 commit f6bc97a
Show file tree
Hide file tree
Showing 90 changed files with 3,140 additions and 1,060 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export { isBlackColor, isWhiteColor } from './shared/color/color-kit';
export { cellToRange } from './shared/common';
export { getIntersectRange } from './shared/range';
export { nameCharacterCheck } from './shared/name';
export { fromCallback, takeAfter } from './shared/rxjs';
export { bufferDebounceTime, fromCallback, takeAfter } from './shared/rxjs';
export { awaitTime } from './shared/timer';
export { Range } from './sheets/range';
export {
Expand Down
15 changes: 14 additions & 1 deletion packages/core/src/shared/rxjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
* limitations under the License.
*/

import { Observable } from 'rxjs';
import type { OperatorFunction } from 'rxjs';
import type { IDisposable } from '../common/di';
import { debounceTime, map, Observable, tap } from 'rxjs';

type CallbackFn<T extends readonly unknown[]> = (cb: (...args: T) => void) => IDisposable;

Expand Down Expand Up @@ -57,3 +58,15 @@ export function takeAfter<T>(callback: (value: T) => boolean) {
};
}

export function bufferDebounceTime<T>(time: number = 0): OperatorFunction<T, T[]> {
return (source: Observable<T>) => {
let bufferedValues: T[] = [];

return source.pipe(
tap((value) => bufferedValues.push(value)),
debounceTime(time),
map(() => bufferedValues),
tap(() => bufferedValues = [])
);
};
}
2 changes: 1 addition & 1 deletion packages/data-validation/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export {
} from './common/util';
export { DataValidationResourceController } from './controllers/dv-resource.controller';

export { type DataValidationChangeSource, DataValidationModel, type IRuleChange, type IValidStatusChange } from './models/data-validation-model';
export { type DataValidationChangeSource, DataValidationModel, type IRuleChange } from './models/data-validation-model';

export { UniverDataValidationPlugin } from './plugin';
export { DataValidatorRegistryScope, DataValidatorRegistryService } from './services/data-validator-registry.service';
Expand Down
11 changes: 2 additions & 9 deletions packages/data-validation/src/models/data-validation-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* limitations under the License.
*/

import type { IDataValidationRule } from '@univerjs/core';
import type { IUpdateRulePayload } from '../types/interfaces/i-update-rule-payload';
import { Disposable, ILogService, Tools } from '@univerjs/core';
import { debounceTime, Subject } from 'rxjs';
import type { DataValidationStatus, IDataValidationRule } from '@univerjs/core';
import { getRuleOptions, getRuleSetting } from '../common/util';
import { UpdateRuleType } from '../types/enum/update-rule-type';
import type { IUpdateRulePayload } from '../types/interfaces/i-update-rule-payload';

type DataValidationChangeType = 'update' | 'add' | 'remove';
export type DataValidationChangeSource = 'command' | 'patched';
Expand All @@ -34,13 +34,6 @@ export interface IRuleChange {
oldRule?: IDataValidationRule;
}

export interface IValidStatusChange {
unitId: string;
subUnitId: string;
ruleId: string;
status: DataValidationStatus;
}

interface ISubUnitDataValidation {
map: Map<string, IDataValidationRule>; list: IDataValidationRule[];
}
Expand Down
10 changes: 8 additions & 2 deletions packages/design/src/components/popup/RectPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,15 @@ function RectPopup(props: IRectPopupProps) {
}, [anchorRect, anchorRect.bottom, anchorRect.left, anchorRect.right, anchorRect.top, clickOtherFn, excludeOutside]);

useEffect(() => {
window.addEventListener('contextmenu', contextMenuFn);
const handleContextMenu = (e: MouseEvent) => {
if (e.ctrlKey && e.button === 0) {
return;
}
contextMenuFn();
};
window.addEventListener('contextmenu', handleContextMenu);
return () => {
window.removeEventListener('contextmenu', contextMenuFn);
window.removeEventListener('contextmenu', handleContextMenu);
};
}, [contextMenuFn]);

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

import type { IAccessor, ICommand } from '@univerjs/core';
import { CommandType, ICommandService, LocaleService } from '@univerjs/core';
import { IConfirmService } from '@univerjs/ui';
import type { IAccessor, ICommand } from '@univerjs/core';
import { COMPONENT_DOC_CREATE_TABLE_CONFIRM } from '../../views/table/create/component-name';
import { CreateDocTableCommand } from '../commands/table/doc-table-create.command';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ const dialogOnlyInputStyle: React.CSSProperties = {
pointerEvents: 'none',
};

/**
* @deprecated
*/
export function RangeSelector(props: IRangeSelectorProps) {
const { dialogOnly, onChange, id, value = '', width = 220, placeholder = '', size = 'middle', onActive, onValid, isSingleChoice = false, openForSheetUnitId, openForSheetSubUnitId, isReadonly = false, className, textEditorClassName, onSelectorVisibleChange: _onSelectorVisibleChange } = props;
const onSelectorVisibleChange = useEvent(_onSelectorVisibleChange);
Expand Down
2 changes: 1 addition & 1 deletion packages/docs-ui/src/controllers/menu.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import { ContextMenuGroup, ContextMenuPosition, RibbonStartGroup } from '@univerjs/ui';
import type { MenuSchemaType } from '@univerjs/ui';
import { ContextMenuGroup, ContextMenuPosition, RibbonStartGroup } from '@univerjs/ui';
import { DocCopyCommand, DocCutCommand, DocPasteCommand } from '../commands/commands/clipboard.command';
import { DeleteLeftCommand } from '../commands/commands/delete.command';
import { OpenHeaderFooterPanelCommand } from '../commands/commands/doc-header-footer.command';
Expand Down
8 changes: 5 additions & 3 deletions packages/docs-ui/src/controllers/menu/context-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* limitations under the License.
*/

import type { IAccessor } from '@univerjs/core';
import type { IRectRangeWithStyle } from '@univerjs/engine-render';
import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';
import { IUniverInstanceService, UniverInstanceType } from '@univerjs/core';
import { DocSelectionManagerService } from '@univerjs/docs';
import { getMenuHiddenObservable, MenuItemType } from '@univerjs/ui';
import { combineLatest, Observable } from 'rxjs';
import type { IAccessor } from '@univerjs/core';
import type { IRectRangeWithStyle } from '@univerjs/engine-render';
import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';
import { DocCopyCommand, DocCutCommand, DocPasteCommand } from '../../commands/commands/clipboard.command';
import { DeleteLeftCommand } from '../../commands/commands/delete.command';
import { DocTableDeleteColumnsCommand, DocTableDeleteRowsCommand, DocTableDeleteTableCommand } from '../../commands/commands/table/doc-table-delete.command';
Expand Down Expand Up @@ -85,6 +85,8 @@ const getDisableWhenSelectionNotInTableObservable = (accessor: IAccessor) => {
subscriber.next(true);
});

subscriber.next(true);

return () => observable.unsubscribe();
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class DocBackScrollRenderController extends RxDisposable implements IRend
const { startOffset } = range;
const anchorNodePosition = skeleton.findNodePositionByCharIndex(startOffset);

this.scrollToNode(anchorNodePosition);
anchorNodePosition && this.scrollToNode(anchorNodePosition);
}

scrollToNode(startNodePosition: Nullable<INodePosition>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export class EditorService extends Disposable implements IEditorService, IDispos
this._contextService.setContextValue(FOCUSING_UNIVER_EDITOR_STANDALONE_SINGLE_MODE, editor.isSingle());

if (!this._spreadsheetFocusState) {
this.singleSelection(editor.isSingleChoice());
this.singleSelection(!!editor.isSingleChoice());
}

this._focusStyle$.next(editorUnitId);
Expand Down
10 changes: 9 additions & 1 deletion packages/docs-ui/src/services/editor/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import type { DocumentDataModel, ICommandService, IDocumentData, IDocumentStyle,
import type { DocSelectionManagerService } from '@univerjs/docs';
import type { IDocSelectionInnerParam, IRender, ISuccinctDocRangeParam, ITextRangeWithStyle } from '@univerjs/engine-render';
import { DEFAULT_STYLES, Disposable, UniverInstanceType } from '@univerjs/core';
import { KeyCode } from '@univerjs/ui';
import { merge, type Observable, Subject } from 'rxjs';
import { filter } from 'rxjs/operators';
import { ReplaceSnapshotCommand } from '../../commands/commands/replace-content.command';
import { DocSelectionRenderService, type IEditorInputConfig } from '../selection/doc-selection-render.service';

Expand Down Expand Up @@ -222,7 +224,13 @@ export class Editor extends Disposable implements IEditor {
this.disposeWithMe(
merge(
docSelectionRenderService.onInput$,
docSelectionRenderService.onKeydown$,
docSelectionRenderService.onKeydown$.pipe(filter((e) => {
const event = e.event as KeyboardEvent;
if (event.ctrlKey || event.metaKey) {
return [KeyCode.X, KeyCode.V].includes(event.keyCode);
}
return [KeyCode.BACKSPACE].includes(event.keyCode);
})),
docSelectionRenderService.onCompositionupdate$,
docSelectionRenderService.onCompositionend$,
docSelectionRenderService.onPaste$
Expand Down
8 changes: 4 additions & 4 deletions packages/docs/src/services/doc-selection-manager.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
* limitations under the License.
*/

import { ICommandService, IUniverInstanceService, RxDisposable, UniverInstanceType } from '@univerjs/core';
import { NORMAL_TEXT_SELECTION_PLUGIN_STYLE } from '@univerjs/engine-render';
import { BehaviorSubject, Subject, takeUntil } from 'rxjs';
import type { DocumentDataModel, Nullable } from '@univerjs/core';
import type {
IDocSelectionInnerParam,
IRectRangeWithStyle,
ISuccinctDocRangeParam,
ITextRangeWithStyle,
} from '@univerjs/engine-render';
import { ICommandService, IUniverInstanceService, RxDisposable, UniverInstanceType } from '@univerjs/core';
import { NORMAL_TEXT_SELECTION_PLUGIN_STYLE } from '@univerjs/engine-render';
import { BehaviorSubject, takeUntil } from 'rxjs';
import { SetTextSelectionsOperation } from '../commands/operations/text-selection.operation';

interface IDocSelectionManagerSearchParam {
Expand Down Expand Up @@ -51,7 +51,7 @@ export class DocSelectionManagerService extends RxDisposable {

private readonly _textSelectionInfo: ITextSelectionInfo = new Map();

private readonly _textSelection$ = new BehaviorSubject<Nullable<ITextSelectionManagerInsertParam>>(null);
private readonly _textSelection$ = new Subject<ITextSelectionManagerInsertParam>();
readonly textSelection$ = this._textSelection$.asObservable();

private readonly _refreshSelection$ = new BehaviorSubject<Nullable<IRefreshSelectionParam>>(null);
Expand Down
3 changes: 2 additions & 1 deletion packages/engine-formula/src/basics/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import { isRealNum, numfmt } from '@univerjs/core';
import type { BaseValueObject } from '../engine/value-object/base-value-object';
import { isRealNum, numfmt } from '@univerjs/core';
import { ErrorValueObject } from '../engine/value-object/base-value-object';
import { ErrorType } from './error-type';

Expand Down Expand Up @@ -515,6 +515,7 @@ export function isLeapYear1900(year: number): boolean {
const daysInMonthL = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
const daysInMonthR = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

// month is 0 based
export function getDaysInMonth(year: number, month: number): number {
return isLeapYear(year) ? daysInMonthL[month] : daysInMonthR[month];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

import { describe, expect, it } from 'vitest';

import { FUNCTION_NAMES_DATE } from '../../function-names';
import { Datedif } from '../index';
import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
import { ErrorType } from '../../../../basics/error-type';
import { ArrayValueObject, transformToValueObject } from '../../../../engine/value-object/array-value-object';
import { ErrorValueObject } from '../../../../engine/value-object/base-value-object';
import { ErrorType } from '../../../../basics/error-type';
import { BooleanValueObject, NumberValueObject, StringValueObject } from '../../../../engine/value-object/primitive-object';
import { FUNCTION_NAMES_DATE } from '../../function-names';
import { Datedif } from '../index';

describe('Test datedif function', () => {
const testFunction = new Datedif(FUNCTION_NAMES_DATE.DATEDIF);
Expand Down Expand Up @@ -70,14 +70,32 @@ describe('Test datedif function', () => {
const unit = StringValueObject.create('YY');
const result = testFunction.calculate(startDate, endDate, unit);
expect(result.getValue()).toStrictEqual(ErrorType.NUM);

const unit2 = ErrorValueObject.create(ErrorType.NAME);
const result2 = testFunction.calculate(startDate, endDate, unit2);
expect(result2.getValue()).toStrictEqual(ErrorType.NAME);

const unit3 = BooleanValueObject.create(true);
const result3 = testFunction.calculate(startDate, endDate, unit3);
expect(result3.getValue()).toStrictEqual(ErrorType.NUM);

const unit4 = NumberValueObject.create(11);
const result4 = testFunction.calculate(startDate, endDate, unit4);
expect(result4.getValue()).toStrictEqual(ErrorType.NUM);
});

it('value is error', () => {
const startDate = NumberValueObject.create(1);
const startDate = StringValueObject.create('2011/1/29');
const endDate = ErrorValueObject.create(ErrorType.NAME);
const unit = StringValueObject.create('YY');
const unit = StringValueObject.create('d');
const result = testFunction.calculate(startDate, endDate, unit);
expect(result.getValue()).toStrictEqual(ErrorType.NAME);

const startDate2 = ErrorValueObject.create(ErrorType.NAME);
const endDate2 = StringValueObject.create('2021/3/31');
const unit2 = StringValueObject.create('d');
const result2 = testFunction.calculate(startDate2, endDate2, unit2);
expect(result2.getValue()).toStrictEqual(ErrorType.NAME);
});

it('value is boolean', () => {
Expand All @@ -90,10 +108,16 @@ describe('Test datedif function', () => {

it('value is normal string', () => {
const startDate = StringValueObject.create('test');
const endDate = StringValueObject.create('2021-12-31');
const endDate = StringValueObject.create('2021-3-31');
const unit = StringValueObject.create('d');
const result = testFunction.calculate(startDate, endDate, unit);
expect(result.getValue()).toStrictEqual(ErrorType.VALUE);

const startDate2 = StringValueObject.create('2011-1-29');
const endDate2 = StringValueObject.create('test');
const unit2 = StringValueObject.create('d');
const result2 = testFunction.calculate(startDate2, endDate2, unit2);
expect(result2.getValue()).toStrictEqual(ErrorType.VALUE);
});

it('value is array', () => {
Expand Down Expand Up @@ -138,7 +162,85 @@ describe('Test datedif function', () => {
});

const result = testFunction.calculate(startDate, endDate, unit);
expect(result.getValue()).toStrictEqual(6);
expect(result.getValue()).toStrictEqual(5);
});

it('M more test', () => {
const startDate = StringValueObject.create('2011/1/1');
const endDate = StringValueObject.create('2013/9/1');
const unit = StringValueObject.create('M');
const result = testFunction.calculate(startDate, endDate, unit);
expect(result.getValue()).toStrictEqual(32);

const startDate2 = StringValueObject.create('2014/3/1');
const endDate2 = StringValueObject.create('2016/2/1');
const result2 = testFunction.calculate(startDate2, endDate2, unit);
expect(result2.getValue()).toStrictEqual(23);

const startDate3 = StringValueObject.create('2009/1/2');
const endDate3 = StringValueObject.create('2012/1/1');
const result3 = testFunction.calculate(startDate3, endDate3, unit);
expect(result3.getValue()).toStrictEqual(35);
});

it('MD more test', () => {
const startDate = StringValueObject.create('2010-7-29');
const endDate = StringValueObject.create('2012-1-28');
const unit = StringValueObject.create('MD');
const result = testFunction.calculate(startDate, endDate, unit);
expect(result.getValue()).toStrictEqual(30);

const endDate2 = StringValueObject.create('2012-2-28');
const result2 = testFunction.calculate(startDate, endDate2, unit);
expect(result2.getValue()).toStrictEqual(30);

const endDate3 = StringValueObject.create('2012-3-28');
const result3 = testFunction.calculate(startDate, endDate3, unit);
expect(result3.getValue()).toStrictEqual(28);

const endDate4 = StringValueObject.create('2012-4-28');
const result4 = testFunction.calculate(startDate, endDate4, unit);
expect(result4.getValue()).toStrictEqual(30);

const endDate5 = StringValueObject.create('2012-5-28');
const result5 = testFunction.calculate(startDate, endDate5, unit);
expect(result5.getValue()).toStrictEqual(29);
});

it('YM more test', () => {
const startDate = StringValueObject.create('2011/1/1');
const endDate = StringValueObject.create('2013/9/1');
const unit = StringValueObject.create('YM');
const result = testFunction.calculate(startDate, endDate, unit);
expect(result.getValue()).toStrictEqual(8);

const startDate2 = StringValueObject.create('2014/3/1');
const endDate2 = StringValueObject.create('2016/2/1');
const result2 = testFunction.calculate(startDate2, endDate2, unit);
expect(result2.getValue()).toStrictEqual(11);

const startDate3 = StringValueObject.create('2009/1/2');
const endDate3 = StringValueObject.create('2012/1/1');
const result3 = testFunction.calculate(startDate3, endDate3, unit);
expect(result3.getValue()).toStrictEqual(11);
});

it('YD more test', () => {
const startDate = StringValueObject.create('2011/1/1');
const endDate = StringValueObject.create('2013/9/1');
const unit = StringValueObject.create('YD');
const result = testFunction.calculate(startDate, endDate, unit);
expect(result.getValue()).toStrictEqual(243);

const startDate2 = StringValueObject.create('2014/3/1');
const endDate2 = StringValueObject.create('2016/2/1');
const result2 = testFunction.calculate(startDate2, endDate2, unit);
expect(result2.getValue()).toStrictEqual(337);

const startDate3 = StringValueObject.create('2009/1/2');
const endDate3 = StringValueObject.create('2012/1/1');
const result3 = testFunction.calculate(startDate3, endDate3, unit);
expect(result3.getValue()).toStrictEqual(364);
});
});
});
Loading

0 comments on commit f6bc97a

Please sign in to comment.