@vaadin/component-base
Advanced tools
Comparing version 22.0.2 to 22.0.3
{ | ||
"name": "@vaadin/component-base", | ||
"version": "22.0.2", | ||
"version": "22.0.3", | ||
"publishConfig": { | ||
@@ -44,3 +44,3 @@ "access": "public" | ||
}, | ||
"gitHead": "df21370c4a655a38eac11f79686021ab3b0887ad" | ||
"gitHead": "935ad1ea65a79b0f9ecb10d767689479b36c4e07" | ||
} |
/** | ||
* @license | ||
* Copyright (c) 2021 Vaadin Ltd. | ||
* Copyright (c) 2021 - 2022 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
@@ -5,0 +5,0 @@ */ |
/** | ||
* @license | ||
* Copyright (c) 2021 Vaadin Ltd. | ||
* Copyright (c) 2021 - 2022 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
@@ -5,0 +5,0 @@ */ |
/** | ||
* @license | ||
* Copyright (c) 2021 Vaadin Ltd. | ||
* Copyright (c) 2021 - 2022 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
@@ -5,0 +5,0 @@ */ |
/** | ||
* @license | ||
* Copyright (c) 2021 Vaadin Ltd. | ||
* Copyright (c) 2021 - 2022 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
@@ -5,0 +5,0 @@ */ |
/** | ||
* @license | ||
* Copyright (c) 2021 Vaadin Ltd. | ||
* Copyright (c) 2021 - 2022 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
@@ -5,0 +5,0 @@ */ |
/** | ||
* @license | ||
* Copyright (c) 2021 Vaadin Ltd. | ||
* Copyright (c) 2021 - 2022 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
@@ -5,0 +5,0 @@ */ |
/** | ||
* @license | ||
* Copyright (c) 2021 Vaadin Ltd. | ||
* Copyright (c) 2021 - 2022 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
@@ -5,0 +5,0 @@ */ |
/** | ||
* @license | ||
* Copyright (c) 2021 Vaadin Ltd. | ||
* Copyright (c) 2021 - 2022 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
@@ -5,0 +5,0 @@ */ |
/** | ||
* @license | ||
* Copyright (c) 2021 Vaadin Ltd. | ||
* Copyright (c) 2021 - 2022 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
@@ -5,0 +5,0 @@ */ |
/** | ||
* @license | ||
* Copyright (c) 2021 Vaadin Ltd. | ||
* Copyright (c) 2021 - 2022 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
@@ -5,0 +5,0 @@ */ |
/** | ||
* @license | ||
* Copyright (c) 2021 Vaadin Ltd. | ||
* Copyright (c) 2021 - 2022 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
@@ -5,0 +5,0 @@ */ |
/** | ||
* @license | ||
* Copyright (c) 2021 Vaadin Ltd. | ||
* Copyright (c) 2021 - 2022 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
@@ -5,0 +5,0 @@ */ |
/** | ||
* @license | ||
* Copyright (c) 2021 Vaadin Ltd. | ||
* Copyright (c) 2021 - 2022 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
@@ -35,3 +35,3 @@ */ | ||
static get version() { | ||
return '22.0.2'; | ||
return '22.0.3'; | ||
} | ||
@@ -38,0 +38,0 @@ |
/** | ||
* @license | ||
* Copyright (c) 2021 Vaadin Ltd. | ||
* Copyright (c) 2021 - 2022 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
@@ -5,0 +5,0 @@ */ |
/** | ||
* @license | ||
* Copyright (c) 2021 Vaadin Ltd. | ||
* Copyright (c) 2021 - 2022 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
@@ -5,0 +5,0 @@ */ |
/** | ||
* @license | ||
* Copyright (c) 2021 Vaadin Ltd. | ||
* Copyright (c) 2021 - 2022 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
@@ -5,0 +5,0 @@ */ |
/** | ||
* @license | ||
* Copyright (c) 2021 Vaadin Ltd. | ||
* Copyright (c) 2021 - 2022 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
@@ -5,0 +5,0 @@ */ |
/** | ||
* @license | ||
* Copyright (c) 2021 Vaadin Ltd. | ||
* Copyright (c) 2021 - 2022 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
@@ -8,3 +8,3 @@ */ | ||
export class SlotController implements ReactiveController { | ||
export class SlotController extends EventTarget implements ReactiveController { | ||
constructor( | ||
@@ -38,2 +38,8 @@ host: HTMLElement, | ||
protected defaultId: string; | ||
protected attachDefaultNode(): Node | undefined; | ||
protected initNode(node: Node): void; | ||
/** | ||
@@ -40,0 +46,0 @@ * Override to initialize the newly added custom node. |
/** | ||
* @license | ||
* Copyright (c) 2021 Vaadin Ltd. | ||
* Copyright (c) 2021 - 2022 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
@@ -11,4 +11,6 @@ */ | ||
*/ | ||
export class SlotController { | ||
export class SlotController extends EventTarget { | ||
constructor(host, slotName, slotFactory, slotInitializer) { | ||
super(); | ||
this.host = host; | ||
@@ -18,34 +20,34 @@ this.slotName = slotName; | ||
this.slotInitializer = slotInitializer; | ||
this.defaultId = SlotController.generateId(slotName, host); | ||
} | ||
/** | ||
* Ensure that every instance has unique ID. | ||
* | ||
* @param {string} slotName | ||
* @param {HTMLElement} host | ||
* @return {string} | ||
* @protected | ||
*/ | ||
static generateId(slotName, host) { | ||
const prefix = slotName || 'default'; | ||
// Maintain the unique ID counter for a given prefix. | ||
this[`${prefix}Id`] = 1 + this[`${prefix}Id`] || 0; | ||
return `${prefix}-${host.localName}-${this[`${prefix}Id`]}`; | ||
} | ||
hostConnected() { | ||
if (!this.initialized) { | ||
const { host, slotName, slotFactory, slotInitializer } = this; | ||
let node = this.getSlotChild(); | ||
const slotted = this.getSlotChild(); | ||
if (!slotted) { | ||
// Slot factory is optional, some slots don't have default content. | ||
if (slotFactory) { | ||
const slotContent = slotFactory(host); | ||
if (slotContent instanceof Element) { | ||
if (slotName !== '') { | ||
slotContent.setAttribute('slot', slotName); | ||
} | ||
host.appendChild(slotContent); | ||
this.node = slotContent; | ||
// Store reference to not pass default node to `initCustomNode`. | ||
this.defaultNode = slotContent; | ||
} | ||
} | ||
if (!node) { | ||
node = this.attachDefaultNode(); | ||
} else { | ||
this.node = slotted; | ||
this.node = node; | ||
this.initCustomNode(node); | ||
} | ||
// Don't try to bind `this` to initializer (normally it's arrow function). | ||
// Instead, pass the host as a first argument to access component's state. | ||
if (slotInitializer) { | ||
slotInitializer(host, this.node); | ||
} | ||
this.initNode(node); | ||
@@ -60,2 +62,32 @@ // TODO: Consider making this behavior opt-in to improve performance. | ||
/** | ||
* Create and attach default node using the slot factory. | ||
* @return {Node | undefined} | ||
* @protected | ||
*/ | ||
attachDefaultNode() { | ||
const { host, slotName, slotFactory } = this; | ||
// Check if the node was created previously and if so, reuse it. | ||
let node = this.defaultNode; | ||
// Slot factory is optional, some slots don't have default content. | ||
if (!node && slotFactory) { | ||
node = slotFactory(host); | ||
if (node instanceof Element) { | ||
if (slotName !== '') { | ||
node.setAttribute('slot', slotName); | ||
} | ||
this.node = node; | ||
this.defaultNode = node; | ||
} | ||
} | ||
if (node) { | ||
host.appendChild(node); | ||
} | ||
return node; | ||
} | ||
/** | ||
* Return a reference to the node managed by the controller. | ||
@@ -76,2 +108,15 @@ * @return {Node} | ||
/** | ||
* @param {Node} node | ||
* @protected | ||
*/ | ||
initNode(node) { | ||
const { slotInitializer } = this; | ||
// Don't try to bind `this` to initializer (normally it's arrow function). | ||
// Instead, pass the host as a first argument to access component's state. | ||
if (slotInitializer) { | ||
slotInitializer(this.host, node); | ||
} | ||
} | ||
/** | ||
* Override to initialize the newly added custom node. | ||
@@ -122,2 +167,4 @@ * | ||
this.initCustomNode(newNode); | ||
this.initNode(newNode); | ||
} | ||
@@ -124,0 +171,0 @@ } |
/** | ||
* @license | ||
* Copyright (c) 2021 Vaadin Ltd. | ||
* Copyright (c) 2021 - 2022 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
@@ -5,0 +5,0 @@ */ |
/** | ||
* @license | ||
* Copyright (c) 2021 Vaadin Ltd. | ||
* Copyright (c) 2021 - 2022 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
@@ -5,0 +5,0 @@ */ |
/** | ||
* @license | ||
* Copyright (c) 2021 Vaadin Ltd. | ||
* Copyright (c) 2021 - 2022 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
@@ -5,0 +5,0 @@ */ |
/** | ||
* @license | ||
* Copyright (c) 2021 Vaadin Ltd. | ||
* Copyright (c) 2021 - 2022 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
@@ -5,0 +5,0 @@ */ |
/** | ||
* @license | ||
* Copyright (c) 2021 Vaadin Ltd. | ||
* Copyright (c) 2021 - 2022 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
@@ -5,0 +5,0 @@ */ |
/** | ||
* @license | ||
* Copyright (c) 2021 Vaadin Ltd. | ||
* Copyright (c) 2021 - 2022 Vaadin Ltd. | ||
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ | ||
@@ -5,0 +5,0 @@ */ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
114330
3004