Socket
Socket
Sign inDemoInstall

@vaadin/component-base

Package Overview
Dependencies
Maintainers
19
Versions
369
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vaadin/component-base - npm Package Compare versions

Comparing version 22.0.0-alpha6 to 22.0.0-alpha7

custom_typings/vaadin-usage-statistics.d.ts

1

index.d.ts
export { ActiveMixin } from './src/active-mixin.js';
export { DisabledMixin } from './src/disabled-mixin.js';
export { ElementMixin } from './src/element-mixin.js';
export { FocusMixin } from './src/focus-mixin.js';

@@ -4,0 +5,0 @@ export { KeyboardMixin } from './src/keyboard-mixin.js';

export { ActiveMixin } from './src/active-mixin.js';
export { DisabledMixin } from './src/disabled-mixin.js';
export { ElementMixin } from './src/element-mixin.js';
export { FocusMixin } from './src/focus-mixin.js';

@@ -4,0 +5,0 @@ export { KeyboardMixin } from './src/keyboard-mixin.js';

44

package.json
{
"name": "@vaadin/component-base",
"version": "22.0.0-alpha6",
"version": "22.0.0-alpha7",
"publishConfig": {
"access": "public"
},
"description": "Vaadin component base mixins",
"main": "index.js",
"module": "index.js",
"repository": "vaadin/web-components",
"keywords": [
"Vaadin",
"web-components",
"web-component"
],
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/vaadin/web-components.git",
"directory": "packages/component-base"
},
"author": "Vaadin Ltd",
"license": "Apache-2.0",
"homepage": "https://vaadin.com/components",
"bugs": {
"url": "https://github.com/vaadin/web-components"
},
"homepage": "https://vaadin.com/components",
"main": "index.js",
"module": "index.js",
"files": [
"custom_typings",
"index.d.ts",
"index.js",
"index.d.ts",
"src"
],
"keywords": [
"Vaadin",
"web-components",
"web-component"
],
"dependencies": {
"@polymer/polymer": "^3.0.0"
"@polymer/polymer": "^3.0.0",
"@vaadin/vaadin-development-mode-detector": "^2.0.0",
"@vaadin/vaadin-usage-statistics": "^2.1.0",
"lit": "^2.0.0"
},

@@ -30,8 +41,5 @@ "devDependencies": {

"@vaadin/testing-helpers": "^0.3.0",
"sinon": "^9.2.1"
"sinon": "^9.2.4"
},
"publishConfig": {
"access": "public"
},
"gitHead": "4b136b1c7da8942960e7255f40c27859125b3a45"
"gitHead": "8e89419c6b44a1d225d5859e180d7b35e47ddb52"
}

@@ -8,1 +8,3 @@ # @vaadin/component-base

Apache License 2.0
Vaadin collects development time usage statistics to improve this product. For details and to opt-out, see https://github.com/vaadin/vaadin-usage-statistics.

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

*/
import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
import { GestureEventListeners } from '@polymer/polymer/lib/mixins/gesture-event-listeners.js';

@@ -12,3 +11,14 @@ import { DisabledMixin } from './disabled-mixin.js';

const ActiveMixinImplementation = (superclass) =>
/**
* A mixin to toggle the `active` attribute.
*
* The attribute is set whenever the user activates the element by a pointer
* or presses an activation key on the element from the keyboard.
*
* The attribute is removed as soon as the element is deactivated
* by the pointer or by releasing the activation key.
*
* @polymerMixin
*/
export const ActiveMixin = (superclass) =>
class ActiveMixinClass extends DisabledMixin(GestureEventListeners(KeyboardMixin(superclass))) {

@@ -32,6 +42,6 @@ /**

this._addEventListenerToNode(this, 'down', () => {
if (this.disabled) return;
this._setActive(true);
this._addEventListenerToNode(this, 'down', (event) => {
if (this._shouldSetActive(event)) {
this._setActive(true);
}
});

@@ -42,6 +52,2 @@

});
this.addEventListener('blur', () => {
this._setActive(false);
});
}

@@ -61,2 +67,10 @@

/**
* @param {KeyboardEvent | MouseEvent} _event
* @protected
*/
_shouldSetActive(_event) {
return !this.disabled;
}
/**
* Sets the `active` attribute on the element if an activation key is pressed.

@@ -71,3 +85,3 @@ *

if (!this.disabled && this._activeKeys.includes(event.key)) {
if (this._shouldSetActive(event) && this._activeKeys.includes(event.key)) {
this._setActive(true);

@@ -102,12 +116,1 @@ }

};
/**
* A mixin to toggle the `active` attribute.
*
* The attribute is set whenever the user activates the element by a pointer
* or presses an activation key on the element from the keyboard.
*
* The attribute is removed as soon as the element is deactivated
* by the pointer or by releasing the activation key.
*/
export const ActiveMixin = dedupingMixin(ActiveMixinImplementation);

@@ -8,54 +8,56 @@ /**

const DisabledMixinImplementation = (superclass) =>
class DisabledMixinClass extends superclass {
static get properties() {
return {
/**
* If true, the user cannot interact with this element.
*/
disabled: {
type: Boolean,
value: false,
observer: '_disabledChanged',
reflectToAttribute: true
}
};
}
/**
* A mixin to provide disabled property for field components.
*
* @polymerMixin
*/
export const DisabledMixin = dedupingMixin(
(superclass) =>
class DisabledMixinClass extends superclass {
static get properties() {
return {
/**
* If true, the user cannot interact with this element.
*/
disabled: {
type: Boolean,
value: false,
observer: '_disabledChanged',
reflectToAttribute: true
}
};
}
/**
* @param {boolean} disabled
* @protected
*/
_disabledChanged(disabled) {
this._setAriaDisabled(disabled);
}
/**
* @param {boolean} disabled
* @protected
*/
_disabledChanged(disabled) {
this._setAriaDisabled(disabled);
}
/**
* @param {boolean} disabled
* @protected
*/
_setAriaDisabled(disabled) {
if (disabled) {
this.setAttribute('aria-disabled', 'true');
} else {
this.removeAttribute('aria-disabled');
/**
* @param {boolean} disabled
* @protected
*/
_setAriaDisabled(disabled) {
if (disabled) {
this.setAttribute('aria-disabled', 'true');
} else {
this.removeAttribute('aria-disabled');
}
}
}
/**
* Overrides the default element `click` method in order to prevent
* firing the `click` event when the element is disabled.
*
* @override
*/
click() {
if (!this.disabled) {
super.click();
/**
* Overrides the default element `click` method in order to prevent
* firing the `click` event when the element is disabled.
* @protected
* @override
*/
click() {
if (!this.disabled) {
super.click();
}
}
}
};
/**
* A mixin to provide disabled property for field components.
*/
export const DisabledMixin = dedupingMixin(DisabledMixinImplementation);
);

@@ -30,76 +30,78 @@ /**

const FocusMixinImplementation = (superclass) =>
class FocusMixinClass extends superclass {
/** @protected */
ready() {
this.addEventListener('focusin', (e) => {
if (this._shouldSetFocus(e)) {
this._setFocused(true);
}
});
/**
* A mixin to handle `focused` and `focus-ring` attributes based on focus.
*
* @polymerMixin
*/
export const FocusMixin = dedupingMixin(
(superclass) =>
class FocusMixinClass extends superclass {
/** @protected */
ready() {
this.addEventListener('focusin', (e) => {
if (this._shouldSetFocus(e)) {
this._setFocused(true);
}
});
this.addEventListener('focusout', (e) => {
if (this._shouldRemoveFocus(e)) {
this._setFocused(false);
}
});
this.addEventListener('focusout', (e) => {
if (this._shouldRemoveFocus(e)) {
this._setFocused(false);
}
});
// In super.ready() other 'focusin' and 'focusout' listeners might be
// added, so we call it after our own ones to ensure they execute first.
// Issue to watch out: when incorrect, <vaadin-combo-box> refocuses the
// input field on iOS after “Done” is pressed.
super.ready();
}
// In super.ready() other 'focusin' and 'focusout' listeners might be
// added, so we call it after our own ones to ensure they execute first.
// Issue to watch out: when incorrect, <vaadin-combo-box> refocuses the
// input field on iOS after “Done” is pressed.
super.ready();
}
/** @protected */
disconnectedCallback() {
super.disconnectedCallback();
/** @protected */
disconnectedCallback() {
super.disconnectedCallback();
// in non-Chrome browsers, blur does not fire on the element when it is disconnected.
// reproducible in `<vaadin-date-picker>` when closing on `Cancel` or `Today` click.
if (this.hasAttribute('focused')) {
this._setFocused(false);
// in non-Chrome browsers, blur does not fire on the element when it is disconnected.
// reproducible in `<vaadin-date-picker>` when closing on `Cancel` or `Today` click.
if (this.hasAttribute('focused')) {
this._setFocused(false);
}
}
}
/**
* Override to change how focused and focus-ring attributes are set.
*
* @param {boolean} focused
* @protected
*/
_setFocused(focused) {
this.toggleAttribute('focused', focused);
/**
* Override to change how focused and focus-ring attributes are set.
*
* @param {boolean} focused
* @protected
*/
_setFocused(focused) {
this.toggleAttribute('focused', focused);
// focus-ring is true when the element was focused from the keyboard.
// Focus Ring [A11ycasts]: https://youtu.be/ilj2P5-5CjI
this.toggleAttribute('focus-ring', focused && keyboardActive);
}
// focus-ring is true when the element was focused from the keyboard.
// Focus Ring [A11ycasts]: https://youtu.be/ilj2P5-5CjI
this.toggleAttribute('focus-ring', focused && keyboardActive);
}
/**
* Override to define if the field receives focus based on the event.
*
* @param {FocusEvent} event
* @return {boolean}
* @protected
*/
_shouldSetFocus(_event) {
return true;
}
/**
* Override to define if the field receives focus based on the event.
*
* @param {FocusEvent} event
* @return {boolean}
* @protected
*/
_shouldSetFocus(_event) {
return true;
}
/**
* Override to define if the field loses focus based on the event.
*
* @param {FocusEvent} event
* @return {boolean}
* @protected
*/
_shouldRemoveFocus(_event) {
return true;
/**
* Override to define if the field loses focus based on the event.
*
* @param {FocusEvent} event
* @return {boolean}
* @protected
*/
_shouldRemoveFocus(_event) {
return true;
}
}
};
/**
* A mixin to handle `focused` and `focus-ring` attributes based on focus.
*/
export const FocusMixin = dedupingMixin(FocusMixinImplementation);
);

@@ -8,45 +8,47 @@ /**

const KeyboardMixinImplementation = (superclass) =>
class KeyboardMixinClass extends superclass {
/** @protected */
ready() {
super.ready();
/**
* A mixin that manages keyboard handling.
* The mixin subscribes to the keyboard events while an actual implementation
* for the event handlers is left to the client (a component or another mixin).
*
* @polymerMixin
*/
export const KeyboardMixin = dedupingMixin(
(superclass) =>
class KeyboardMixinClass extends superclass {
/** @protected */
ready() {
super.ready();
this.addEventListener('keydown', (event) => {
this._onKeyDown(event);
});
this.addEventListener('keydown', (event) => {
this._onKeyDown(event);
});
this.addEventListener('keyup', (event) => {
this._onKeyUp(event);
});
}
this.addEventListener('keyup', (event) => {
this._onKeyUp(event);
});
}
/**
* A handler for the `keydown` event. By default, it does nothing.
* Override the method to implement your own behavior.
*
* @param {KeyboardEvent} _event
* @protected
*/
_onKeyDown(_event) {
// To be implemented.
}
/**
* A handler for the `keydown` event. By default, it does nothing.
* Override the method to implement your own behavior.
*
* @param {KeyboardEvent} _event
* @protected
*/
_onKeyDown(_event) {
// To be implemented.
}
/**
* A handler for the `keyup` event. By default, it does nothing.
* Override the method to implement your own behavior.
*
* @param {KeyboardEvent} _event
* @protected
*/
_onKeyUp(_event) {
// To be implemented.
/**
* A handler for the `keyup` event. By default, it does nothing.
* Override the method to implement your own behavior.
*
* @param {KeyboardEvent} _event
* @protected
*/
_onKeyUp(_event) {
// To be implemented.
}
}
};
/**
* A mixin that manages keyboard handling.
* The mixin subscribes to the keyboard events while an actual implementation
* for the event handlers is left to the client (a component or another mixin).
*/
export const KeyboardMixin = dedupingMixin(KeyboardMixinImplementation);
);

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

const SlotMixinImplementation = (superclass) =>
class SlotMixinClass extends superclass {
/**
* List of named slots to initialize.
*/
get slots() {
return {};
}
/**
* A mixin to provide content for named slots defined by component.
*
* @polymerMixin
*/
export const SlotMixin = dedupingMixin(
(superclass) =>
class SlotMixinClass extends superclass {
/**
* List of named slots to initialize.
* @protected
*/
get slots() {
return {};
}
/** @protected */
ready() {
super.ready();
this._connectSlotMixin();
}
/** @protected */
ready() {
super.ready();
this._connectSlotMixin();
}
/** @private */
_connectSlotMixin() {
Object.keys(this.slots).forEach((slotName) => {
// Ignore labels of nested components, if any
const hasContent = this._getDirectSlotChild(slotName) !== undefined;
/** @private */
_connectSlotMixin() {
Object.keys(this.slots).forEach((slotName) => {
// Ignore labels of nested components, if any
const hasContent = this._getDirectSlotChild(slotName) !== undefined;
if (!hasContent) {
const slotFactory = this.slots[slotName];
const slotContent = slotFactory();
if (slotContent instanceof Element) {
slotContent.setAttribute('slot', slotName);
this.appendChild(slotContent);
if (!hasContent) {
const slotFactory = this.slots[slotName];
const slotContent = slotFactory();
if (slotContent instanceof Element) {
slotContent.setAttribute('slot', slotName);
this.appendChild(slotContent);
}
}
}
});
}
});
}
/** @protected */
_getDirectSlotChild(slotName) {
return Array.from(this.children).find((el) => el.slot === slotName);
/** @protected */
_getDirectSlotChild(slotName) {
return Array.from(this.children).find((el) => el.slot === slotName);
}
}
};
/**
* A mixin to provide content for named slots defined by component.
*/
export const SlotMixin = dedupingMixin(SlotMixinImplementation);
);

@@ -6,6 +6,16 @@ /**

*/
import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
import { DisabledMixin } from './disabled-mixin.js';
const TabindexMixinImplementation = (superclass) =>
/**
* A mixin to provide the `tabindex` attribute.
*
* By default, the attribute is set to 0 that makes the element focusable.
*
* The attribute is set to -1 whenever the user disables the element
* and restored with the last known value once the element is enabled.
*
* @polymerMixin
* @mixes DisabledMixin
*/
export const TabindexMixin = (superclass) =>
class TabindexMixinClass extends DisabledMixin(superclass) {

@@ -16,2 +26,3 @@ static get properties() {

* Indicates whether the element can be focused and where it participates in sequential keyboard navigation.
* @protected
*/

@@ -71,11 +82,1 @@ tabindex: {

};
/**
* A mixin to provide the `tabindex` attribute.
*
* By default, the attribute is set to 0 that makes the element focusable.
*
* The attribute is set to -1 whenever the user disables the element
* and restored with the last known value once the element is enabled.
*/
export const TabindexMixin = dedupingMixin(TabindexMixinImplementation);
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