Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@maskito/core

Package Overview
Dependencies
Maintainers
4
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@maskito/core - npm Package Compare versions

Comparing version 0.7.2 to 0.8.0

2

package.json
{
"name": "@maskito/core",
"version": "0.7.2",
"version": "0.8.0",
"description": "The main zero-dependency and framework-agnostic Maskito's package to create an input mask",

@@ -5,0 +5,0 @@ "keywords": [

@@ -1,2 +0,2 @@

import type { ElementState, SelectionRange, TypedInputEvent } from '../types';
import type { ElementState, TypedInputEvent } from '../types';
export declare abstract class MaskHistory {

@@ -6,4 +6,3 @@ private now;

private future;
protected abstract updateValue(value: string, eventInit: Pick<TypedInputEvent, 'data' | 'inputType'>): void;
protected abstract updateSelectionRange(selection: SelectionRange): void;
protected abstract updateElementState(state: ElementState, eventInit: Pick<TypedInputEvent, 'data' | 'inputType'>): void;
protected undo(): void;

@@ -10,0 +9,0 @@ protected redo(): void;

@@ -39,6 +39,5 @@ export class MaskHistory {

this.now = state;
this.updateValue(state.value, { inputType, data: null });
this.updateSelectionRange(state.selection);
this.updateElementState(state, { inputType, data: null });
}
}
//# sourceMappingURL=mask-history.js.map
import { MaskHistory } from './classes';
import { MaskitoOptions, SelectionRange, TypedInputEvent } from './types';
import { ElementState, MaskitoOptions, TypedInputEvent } from './types';
export declare class Maskito extends MaskHistory {

@@ -12,10 +12,12 @@ private readonly element;

destroy(): void;
protected updateSelectionRange([from, to]: SelectionRange): void;
protected updateValue(newValue: string, eventInit?: Pick<TypedInputEvent, 'data' | 'inputType'>): void;
protected updateElementState({ value, selection }: ElementState, eventInit?: Pick<TypedInputEvent, 'data' | 'inputType'>): void;
private handleKeydown;
private conformValueToMask;
private ensureValueFitsMask;
private handleDelete;
private handleInsert;
private handleEnter;
private updateSelectionRange;
private updateValue;
private dispatchInputEvent;
}
//# sourceMappingURL=mask.d.ts.map

@@ -11,3 +11,3 @@ import { MaskHistory, MaskModel } from './classes';

this.options = Object.assign(Object.assign({}, MASKITO_DEFAULT_OPTIONS), this.maskitoOptions);
this.conformValueToMask();
this.ensureValueFitsMask();
this.updateHistory(this.elementState);

@@ -89,3 +89,3 @@ this.eventListener.listen('keydown', event => {

this.eventListener.listen('input', () => {
this.conformValueToMask();
this.ensureValueFitsMask();
this.updateHistory(this.elementState);

@@ -107,20 +107,11 @@ });

}
updateSelectionRange([from, to]) {
var _a, _b;
if (this.element.selectionStart !== from || this.element.selectionEnd !== to) {
(_b = (_a = this.element).setSelectionRange) === null || _b === void 0 ? void 0 : _b.call(_a, from, to);
}
}
updateValue(newValue, eventInit = {
updateElementState({ value, selection }, eventInit = {
inputType: 'insertText',
data: null,
}) {
if (this.element.value !== newValue) {
const globalObject = typeof window !== 'undefined' ? window : globalThis;
this.element.value = newValue;
// TODO: replace `globalObject` with `globalThis` after bumping Firefox to 65+
// @see https://caniuse.com/?search=globalThis
if (globalObject === null || globalObject === void 0 ? void 0 : globalObject.InputEvent) {
this.element.dispatchEvent(new InputEvent('input', Object.assign(Object.assign({}, eventInit), { bubbles: true, cancelable: true })));
}
const initialValue = this.elementState.value;
this.updateValue(value);
this.updateSelectionRange(selection);
if (initialValue !== value) {
this.dispatchInputEvent(eventInit);
}

@@ -147,6 +138,4 @@ }

}
conformValueToMask() {
const { value, selection } = maskitoTransform(this.elementState, this.options);
this.updateValue(value);
this.updateSelectionRange(selection);
ensureValueFitsMask() {
this.updateElementState(maskitoTransform(this.elementState, this.options));
}

@@ -181,7 +170,6 @@ handleDelete({ event, selection, isForward, force = false, }) {

: 'deleteContentBackward';
this.updateValue(newElementState.value, {
this.updateElementState(newElementState, {
inputType: 'inputType' in event ? event.inputType : inputTypeFallback,
data: null,
});
this.updateSelectionRange(newElementState.selection);
this.updateHistory(newElementState);

@@ -204,11 +192,10 @@ }

const newPossibleValue = elementState.value.slice(0, from) + data + elementState.value.slice(to);
const { value, selection } = this.options.postprocessor(maskModel, initialElementState);
if (newPossibleValue !== value) {
const newElementState = this.options.postprocessor(maskModel, initialElementState);
if (newPossibleValue !== newElementState.value) {
event.preventDefault();
this.updateValue(value, {
this.updateElementState(newElementState, {
data,
inputType: 'inputType' in event ? event.inputType : 'insertText',
});
this.updateSelectionRange(selection);
this.updateHistory({ value, selection });
this.updateHistory(newElementState);
}

@@ -221,3 +208,25 @@ }

}
updateSelectionRange([from, to]) {
var _a, _b;
if (this.element.selectionStart !== from || this.element.selectionEnd !== to) {
(_b = (_a = this.element).setSelectionRange) === null || _b === void 0 ? void 0 : _b.call(_a, from, to);
}
}
updateValue(newValue) {
if (this.element.value !== newValue) {
this.element.value = newValue;
}
}
dispatchInputEvent(eventInit = {
inputType: 'insertText',
data: null,
}) {
const globalObject = typeof window !== 'undefined' ? window : globalThis;
// TODO: replace `globalObject` with `globalThis` after bumping Firefox to 65+
// @see https://caniuse.com/?search=globalThis
if (globalObject === null || globalObject === void 0 ? void 0 : globalObject.InputEvent) {
this.element.dispatchEvent(new InputEvent('input', Object.assign(Object.assign({}, eventInit), { bubbles: true, cancelable: false })));
}
}
}
//# sourceMappingURL=mask.js.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc