๐ - Delete calibration on initialization + create `maskitoInitialCalibrationPlugin`
nsbarsukov opened this issue ยท 3 comments
Which package(s) are relevant/related to the feature request?
@maskito/core
Description
Delete this line
maskito/projects/core/src/lib/mask.ts
Line 39 in a6777ec
+ add maskitoInitialCalibrationPlugin
(inside @maskito/core
or @maskito/kit
???):
export function maskitoInitialCalibrationPlugin(
customOptions?: MaskitoOptions,
): MaskitoPlugin {
return (element, options) => {
element.value = maskitoTransform(element.value, customOptions || options);
};
}
Why?
The current implementation is not so flexible as required.
Sometimes the such initial calibration is not required for developer, and develop wants calibration to work only on user's interactions.
The new way allows to select: use maskitoInitialCalibrationPlugin
or not.
For these cases
Developer can use the optional argument of maskitoInitialCalibrationPlugin
.
@tuiPure
private calculateMask(
precision: number,
decimalMode: TuiDecimal,
decimalSeparator: string,
thousandSeparator: string,
min: number,
max: number,
prefix: string,
postfix: string,
): MaskitoOptions {
const generatorParams = {
decimalSeparator,
thousandSeparator,
min,
max,
prefix,
postfix,
precision: decimalMode === 'never' ? 0 : precision,
decimalZeroPadding: decimalMode === 'always',
};
const {plugins, ...options} = maskitoNumberOptionsGenerator(generatorParams);
const initialCalibrationPlugin = maskitoInitialCalibrationPlugin(
maskitoNumberOptionsGenerator({
...generatorParams,
min: Number.MIN_SAFE_INTEGER,
max: Number.MAX_SAFE_INTEGER
})
);
return {
...options,
plugins: [
...plugins,
initialCalibrationPlugin,
maskitoCaretGuard(value => [
prefix.length,
value.length - postfix.length,
]),
],
};
}
Drop initialElementState.value &&
from this line (after solving this issue):
Possibly after solving this issue we can also drop these lines ๐ค
maskito/projects/kit/src/lib/processors/postfix-postprocessor.ts
Lines 12 to 15 in 77a81d1
UPDATE: nope, it will break maskitoRemoveOnBlurPlugin
(it dispatches input event and triggers mask check again) and other similar cases