Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/devextreme/js/__internal/core/localization/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ const numberLocalizationBase = {
return value.replace(regExp, (char) => String.fromCharCode(char.charCodeAt(0) + (toFirstDigit.charCodeAt(0) - fromFirstDigit.charCodeAt(0)))) as TValue;
},

getNegativeEtalonRegExp(format: FormatConfig | string): RegExp {
getNegativeEtalonRegExp(format: LocalizationFormat): RegExp {
const separators: FormatterConfig = this._getSeparators();
const digitalRegExp = new RegExp(`[0-9${escapeRegExp(separators.decimalSeparator + separators.thousandsSeparator)}]+`, 'g');
const specialCharacters = ['\\', '(', ')', '[', ']', '*', '+', '$', '^', '?', '|', '{', '}'];
Expand All @@ -301,7 +301,7 @@ const numberLocalizationBase = {
return new RegExp(negativeEtalon, 'g');
},

getSign(text: string, format?: FormatConfig | string): 1 | -1 {
getSign(text: string, format?: LocalizationFormat): 1 | -1 {
if (!format) {
if (text.replace(/[^0-9-]/g, '').startsWith('-')) {
return -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ class ChatTextArea extends TextArea<Properties> {
return maxHeight;
}

_keyPressHandler(e: { originalEvent: InputEvent & KeyboardEvent }): void {
_keyPressHandler(e: DxEvent): void {
super._keyPressHandler(e);

this._updateButtonsState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { isCommandKeyPressed } from '@ts/events/utils/index';
import Draggable from '@ts/m_draggable';
import type { EditorProperties, ValueChangedEvent } from '@ts/ui/editor/editor';
import Editor from '@ts/ui/editor/editor';
import NumberBox from '@ts/ui/number_box/m_number_box';
import { WIDGET_CLASS as NUMBERBOX_CLASS } from '@ts/ui/number_box/m_number_box.base';
import NumberBox from '@ts/ui/number_box/number_box';
import { WIDGET_CLASS as NUMBERBOX_CLASS } from '@ts/ui/number_box/number_box.base';
import TextBox from '@ts/ui/text_box/text_box';

const COLOR_VIEW_CLASS = 'dx-colorview';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class DateBoxMask<
this._caret(this._getActivePartProp('caret'));
}

_keyPressHandler(e: { originalEvent: InputEvent & KeyboardEvent }): void {
_keyPressHandler(e: DxEvent<InputEvent>): void {
const { originalEvent: event } = e;

const isBackwardDeletion = event?.inputType === 'deleteContentBackward';
Expand Down
4 changes: 2 additions & 2 deletions packages/devextreme/js/__internal/ui/date_box/time_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import Box from '@ts/ui/box';
import dateUtils from '@ts/ui/date_box/date_utils';
import type { EditorProperties } from '@ts/ui/editor/editor';
import Editor from '@ts/ui/editor/editor';
import NumberBox from '@ts/ui/number_box/m_number_box';
import type { NumberBoxMaskProperties } from '@ts/ui/number_box/m_number_box.mask';
import NumberBox from '@ts/ui/number_box/number_box';
import type { NumberBoxMaskProperties } from '@ts/ui/number_box/number_box.mask';
import SelectBox from '@ts/ui/select_box';

const TIMEVIEW_CLASS = 'dx-timeview';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ interface EditorWithDropDown {
export default class DropDownButton<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
TComponent extends Editor<any> & EditorWithDropDown = DropDownEditor,
> extends TextEditorButton<TComponent> {
declare instance: Button | null;

> extends TextEditorButton<TComponent, Button> {
currentTemplate: DropDownEditorProperties['dropDownButtonTemplate'] | null;

constructor(name: string, editor: TComponent, options: ButtonProperties) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { describe, expect, it } from '@jest/globals';

import {
asPattern, getNthOccurrence, getRealSeparatorIndex, splitByIndex,
} from '../utils';

describe('getNthOccurrence', () => {
it('returns the position of the requested occurrence', () => {
expect(getNthOccurrence('1.234.567', '.', 1)).toBe(1);
expect(getNthOccurrence('1.234.567', '.', 2)).toBe(5);
});

it('returns -1 when the character is absent', () => {
expect(getNthOccurrence('1234', '.', 1)).toBe(-1);
expect(getNthOccurrence('', '.', 1)).toBe(-1);
});

it('returns -1 when there are fewer occurrences than requested', () => {
expect(getNthOccurrence('abc.d', '.', 2)).toBe(-1);
expect(getNthOccurrence('abc.d', '.', 3)).toBe(-1);
expect(getNthOccurrence('a.b.c', '.', 4)).toBe(-1);
expect(getNthOccurrence('a.b.c', '.', 5)).toBe(-1);
});

it('returns -1 when no occurrence is requested', () => {
expect(getNthOccurrence('1.2', '.', 0)).toBe(-1);
});

it('counts adjacent occurrences separately', () => {
expect(getNthOccurrence('...', '.', 1)).toBe(0);
expect(getNthOccurrence('...', '.', 3)).toBe(2);
expect(getNthOccurrence('...', '.', 4)).toBe(-1);
});
});

describe('getRealSeparatorIndex', () => {
it('reports the first separator of a plain pattern', () => {
expect(getRealSeparatorIndex('#0.00')).toEqual({ occurrence: 1, index: 2 });
expect(getRealSeparatorIndex('#,##0.##')).toEqual({ occurrence: 1, index: 5 });
});

it('skips separators inside escaped stubs', () => {
expect(getRealSeparatorIndex("'.'#0.00")).toEqual({ occurrence: 2, index: 5 });
expect(getRealSeparatorIndex("'..' #0.00")).toEqual({ occurrence: 3, index: 7 });
});

it('reports a missing separator for patterns without a float part', () => {
expect(getRealSeparatorIndex('#,##0')).toEqual({ occurrence: 1, index: -1 });
});

it('treats a format that is not a pattern as having no separator', () => {
expect(getRealSeparatorIndex({ type: 'fixedPoint', precision: 2 }))
.toEqual({ occurrence: 1, index: -1 });
expect(getRealSeparatorIndex(undefined)).toEqual({ occurrence: 1, index: -1 });
});

it('locates the separator of a stubbed pattern in the formatted text', () => {
const { occurrence } = getRealSeparatorIndex("'...' #0.0");

expect(getNthOccurrence('... 12.5', '.', occurrence)).toBe(6);
expect(getNthOccurrence('.. 12', '.', occurrence)).toBe(-1);
});
});

describe('splitByIndex', () => {
it('splits the text around the given index', () => {
expect(splitByIndex('12.34', 2)).toEqual(['12', '34']);
});

it('keeps the text whole when there is no split point', () => {
expect(splitByIndex('1234', -1)).toEqual(['1234']);
});
});

describe('asPattern', () => {
it('passes a pattern string through', () => {
expect(asPattern('#0.00')).toBe('#0.00');
});

it('reports an empty pattern for formats that are not strings', () => {
expect(asPattern(undefined)).toBe('');
expect(asPattern({ type: 'currency' })).toBe('');
expect(asPattern((value: number): string => String(value))).toBe('');
});
});

This file was deleted.

Loading
Loading