Socket
Socket
Sign inDemoInstall

@vaadin/field-base

Package Overview
Dependencies
Maintainers
14
Versions
373
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vaadin/field-base - npm Package Compare versions

Comparing version 23.1.1 to 23.2.0-alpha1

6

package.json
{
"name": "@vaadin/field-base",
"version": "23.1.1",
"version": "23.2.0-alpha1",
"publishConfig": {

@@ -35,3 +35,3 @@ "access": "public"

"@polymer/polymer": "^3.0.0",
"@vaadin/component-base": "^23.1.1",
"@vaadin/component-base": "23.2.0-alpha1",
"lit": "^2.0.0"

@@ -44,3 +44,3 @@ },

},
"gitHead": "390458d6519433a2dd502cef90da48e84573a275"
"gitHead": "f226a2976c270d3d53c824f6e0a740a5d3382d91"
}

@@ -92,6 +92,2 @@ /**

this.addController(this._fieldAriaController);
this.addController(this._helperController);
this.addController(this._errorController);
this._labelController.addEventListener('label-changed', (event) => {

@@ -108,2 +104,11 @@ const { hasLabel, node } = event.detail;

/** @protected */
ready() {
super.ready();
this.addController(this._fieldAriaController);
this.addController(this._helperController);
this.addController(this._errorController);
}
/** @private */

@@ -110,0 +115,0 @@ __helperChanged(hasHelper, helperNode) {

@@ -40,2 +40,15 @@ /**

/**
* A pattern matched against individual characters the user inputs.
*
* When set, the field will prevent:
* - `keydown` events if the entered key doesn't match `/^allowedCharPattern$/`
* - `paste` events if the pasted text doesn't match `/^allowedCharPattern*$/`
* - `drop` events if the dropped text doesn't match `/^allowedCharPattern*$/`
*
* For example, to allow entering only numbers and minus signs, use:
* `allowedCharPattern = "[\\d-]"`
*/
allowedCharPattern: string;
/**
* If true, the input text gets fully selected when the field is focused using click or touch / tap.

@@ -42,0 +55,0 @@ */

@@ -6,2 +6,4 @@ /**

*/
import { timeOut } from '@vaadin/component-base/src/async.js';
import { Debouncer } from '@vaadin/component-base/src/debounce.js';
import { KeyboardMixin } from '@vaadin/component-base/src/keyboard-mixin.js';

@@ -28,2 +30,18 @@ import { DelegateFocusMixin } from './delegate-focus-mixin.js';

/**
* A pattern matched against individual characters the user inputs.
*
* When set, the field will prevent:
* - `keydown` events if the entered key doesn't match `/^allowedCharPattern$/`
* - `paste` events if the pasted text doesn't match `/^allowedCharPattern*$/`
* - `drop` events if the dropped text doesn't match `/^allowedCharPattern*$/`
*
* For example, to allow entering only numbers and minus signs, use:
* `allowedCharPattern = "[\\d-]"`
*/
allowedCharPattern: {
type: String,
observer: '_allowedCharPatternChanged',
},
/**
* If true, the input text gets fully selected when the field is focused using click or touch / tap.

@@ -85,2 +103,10 @@ */

constructor() {
super();
this._boundOnPaste = this._onPaste.bind(this);
this._boundOnDrop = this._onDrop.bind(this);
this._boundOnBeforeInput = this._onBeforeInput.bind(this);
}
/**

@@ -179,2 +205,111 @@ * Any element extending this mixin is required to implement this getter.

/**
* Override a method from `InputMixin`.
* @param {!HTMLElement} input
* @protected
* @override
*/
_addInputListeners(input) {
super._addInputListeners(input);
input.addEventListener('paste', this._boundOnPaste);
input.addEventListener('drop', this._boundOnDrop);
input.addEventListener('beforeinput', this._boundOnBeforeInput);
}
/**
* Override a method from `InputMixin`.
* @param {!HTMLElement} input
* @protected
* @override
*/
_removeInputListeners(input) {
super._removeInputListeners(input);
input.removeEventListener('paste', this._boundOnPaste);
input.removeEventListener('drop', this._boundOnDrop);
input.removeEventListener('beforeinput', this._boundOnBeforeInput);
}
/**
* Override an event listener from `KeyboardMixin`.
* @param {!KeyboardEvent} event
* @protected
* @override
*/
_onKeyDown(event) {
super._onKeyDown(event);
if (this.allowedCharPattern && !this.__shouldAcceptKey(event)) {
event.preventDefault();
this._markInputPrevented();
}
}
/** @protected */
_markInputPrevented() {
// Add input-prevented attribute for 200ms
this.setAttribute('input-prevented', '');
this._preventInputDebouncer = Debouncer.debounce(this._preventInputDebouncer, timeOut.after(200), () => {
this.removeAttribute('input-prevented');
});
}
/** @private */
__shouldAcceptKey(event) {
return (
event.metaKey ||
event.ctrlKey ||
!event.key || // Allow typing anything if event.key is not supported
event.key.length !== 1 || // Allow "Backspace", "ArrowLeft" etc.
this.__allowedCharRegExp.test(event.key)
);
}
/** @private */
_onPaste(e) {
if (this.allowedCharPattern) {
const pastedText = e.clipboardData.getData('text');
if (!this.__allowedTextRegExp.test(pastedText)) {
e.preventDefault();
this._markInputPrevented();
}
}
}
/** @private */
_onDrop(e) {
if (this.allowedCharPattern) {
const draggedText = e.dataTransfer.getData('text');
if (!this.__allowedTextRegExp.test(draggedText)) {
e.preventDefault();
this._markInputPrevented();
}
}
}
/** @private */
_onBeforeInput(e) {
// The `beforeinput` event covers all the cases for `allowedCharPattern`: keyboard, pasting and dropping,
// but it is still experimental technology so we can't rely on it. It's used here just as an additional check,
// because it seems to be the only way to detect and prevent specific keys on mobile devices.
// See https://github.com/vaadin/vaadin-text-field/issues/429
if (this.allowedCharPattern && e.data && !this.__allowedTextRegExp.test(e.data)) {
e.preventDefault();
this._markInputPrevented();
}
}
/** @private */
_allowedCharPatternChanged(charPattern) {
if (charPattern) {
try {
this.__allowedCharRegExp = new RegExp(`^${charPattern}$`);
this.__allowedTextRegExp = new RegExp(`^${charPattern}*$`);
} catch (e) {
console.error(e);
}
}
}
/**
* Fired when the user commits a value change.

@@ -181,0 +316,0 @@ *

@@ -26,5 +26,3 @@ /**

// Ensure every instance has unique ID
const uniqueId = (InputController._uniqueInputId = 1 + InputController._uniqueInputId || 0);
host._inputId = `${host.localName}-${uniqueId}`;
node.id = host._inputId;
node.id = this.defaultId;

@@ -31,0 +29,0 @@ if (typeof callback === 'function') {

@@ -50,18 +50,2 @@ /**

},
/**
* A pattern matched against individual characters the user inputs.
* When set, the field will prevent:
* - `keyDown` events if the entered key doesn't match `/^_enabledCharPattern$/`
* - `paste` events if the pasted text doesn't match `/^_enabledCharPattern*$/`
* - `drop` events if the dropped text doesn't match `/^_enabledCharPattern*$/`
*
* For example, to enable entering only numbers and minus signs,
* `_enabledCharPattern = "[\\d-]"`
* @protected
*/
_enabledCharPattern: {
type: String,
observer: '_enabledCharPatternChanged',
},
};

@@ -74,10 +58,2 @@ }

constructor() {
super();
this._boundOnPaste = this._onPaste.bind(this);
this._boundOnDrop = this._onDrop.bind(this);
this._boundOnBeforeInput = this._onBeforeInput.bind(this);
}
/**

@@ -154,95 +130,2 @@ * @param {HTMLElement} input

}
/**
* Override a method from `InputMixin`.
* @param {!HTMLElement} input
* @protected
* @override
*/
_addInputListeners(input) {
super._addInputListeners(input);
input.addEventListener('paste', this._boundOnPaste);
input.addEventListener('drop', this._boundOnDrop);
input.addEventListener('beforeinput', this._boundOnBeforeInput);
}
/**
* Override a method from `InputMixin`.
* @param {!HTMLElement} input
* @protected
* @override
*/
_removeInputListeners(input) {
super._removeInputListeners(input);
input.removeEventListener('paste', this._boundOnPaste);
input.removeEventListener('drop', this._boundOnDrop);
input.removeEventListener('beforeinput', this._boundOnBeforeInput);
}
/**
* Override an event listener from `InputControlMixin`
* to avoid adding a separate listener.
* @param {!KeyboardEvent} event
* @protected
* @override
*/
_onKeyDown(event) {
if (this._enabledCharPattern && !this.__shouldAcceptKey(event)) {
event.preventDefault();
}
super._onKeyDown(event);
}
/** @private */
__shouldAcceptKey(event) {
return (
event.metaKey ||
event.ctrlKey ||
!event.key || // Allow typing anything if event.key is not supported
event.key.length !== 1 || // Allow "Backspace", "ArrowLeft" etc.
this.__enabledCharRegExp.test(event.key)
);
}
/** @private */
_onPaste(e) {
if (this._enabledCharPattern) {
const pastedText = (e.clipboardData || window.clipboardData).getData('text');
if (!this.__enabledTextRegExp.test(pastedText)) {
e.preventDefault();
}
}
}
/** @private */
_onDrop(e) {
if (this._enabledCharPattern) {
const draggedText = e.dataTransfer.getData('text');
if (!this.__enabledTextRegExp.test(draggedText)) {
e.preventDefault();
}
}
}
/** @private */
_onBeforeInput(e) {
// The `beforeinput` event covers all the cases for `_enabledCharPattern`: keyboard, pasting and dropping,
// but it is still experimental technology so we can't rely on it. It's used here just as an additional check,
// because it seems to be the only way to detect and prevent specific keys on mobile devices.
// See https://github.com/vaadin/vaadin-text-field/issues/429
if (this._enabledCharPattern && e.data && !this.__enabledTextRegExp.test(e.data)) {
e.preventDefault();
}
}
/** @private */
_enabledCharPatternChanged(charPattern) {
if (charPattern) {
this.__enabledCharRegExp = new RegExp(`^${charPattern}$`);
this.__enabledTextRegExp = new RegExp(`^${charPattern}*$`);
}
}
};

@@ -46,2 +46,8 @@ /**

this._labelController = new LabelController(this);
}
/** @protected */
ready() {
super.ready();
this.addController(this._labelController);

@@ -48,0 +54,0 @@ }

@@ -37,4 +37,5 @@ /**

* @attr {boolean} prevent-invalid-input
* @deprecated Please use `allowedCharPattern` instead.
*/
preventInvalidInput: boolean | null | undefined;
}

@@ -32,5 +32,7 @@ /**

* @attr {boolean} prevent-invalid-input
* @deprecated Please use `allowedCharPattern` instead.
*/
preventInvalidInput: {
type: Boolean,
observer: '_preventInvalidInputChanged',
},

@@ -72,2 +74,11 @@ };

}
/** @private */
_preventInvalidInputChanged(preventInvalidInput) {
if (preventInvalidInput) {
console.warn(
`WARNING: Since Vaadin 23.2, "preventInvalidInput" is deprecated. Please use "allowedCharPattern" instead.`,
);
}
}
};

@@ -44,3 +44,7 @@ /**

// to handle e.g. mutating text content while disconnected.
this.__checkAndCopyNodesToSlotTarget();
// Note, `hostConnected()` is called twice if the controller
// is initialized in `ready()` when using `ControllerMixin`.
if (!this.__copying) {
this.__checkAndCopyNodesToSlotTarget();
}
}

@@ -47,0 +51,0 @@

@@ -28,6 +28,3 @@ /**

// Ensure every instance has unique ID
const uniqueId = (TextAreaController._uniqueTextAreaId = 1 + TextAreaController._uniqueTextAreaId || 0);
host._textareaId = `${host.localName}-${uniqueId}`;
node.id = host._textareaId;
node.id = this.defaultId;

@@ -34,0 +31,0 @@ if (typeof callback === 'function') {

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