@vaadin/component-base 25.4.0-alpha5 → 25.4.0-alpha7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/component-base",
3
- "version": "25.4.0-alpha5",
3
+ "version": "25.4.0-alpha7",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -39,11 +39,11 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "@polymer/polymer": "^3.0.0",
42
- "@vaadin/chai-plugins": "25.4.0-alpha5",
43
- "@vaadin/test-runner-commands": "25.4.0-alpha5",
42
+ "@vaadin/chai-plugins": "25.4.0-alpha7",
43
+ "@vaadin/test-runner-commands": "25.4.0-alpha7",
44
44
  "@vaadin/testing-helpers": "^2.0.0",
45
45
  "sinon": "^22.0.0"
46
46
  },
47
47
  "customElements": "custom-elements.json",
48
- "gitHead": "65e9c9e49c0a723b08ee91b9aae8b901e91a3597"
48
+ "gitHead": "368fb0f0df09ec6f51766d9c44047c8d7620d6bd"
49
49
  }
package/src/define.js CHANGED
@@ -13,7 +13,7 @@ function dashToCamelCase(dash) {
13
13
 
14
14
  const experimentalMap = {};
15
15
 
16
- export function defineCustomElement(CustomElement, version = '25.4.0-alpha5') {
16
+ export function defineCustomElement(CustomElement, version = '25.4.0-alpha7') {
17
17
  Object.defineProperty(CustomElement, 'version', {
18
18
  get() {
19
19
  return version;
@@ -20,3 +20,9 @@ export interface PartNameInfo {
20
20
  * if the property value is truthy, and removed if the value is falsy.
21
21
  */
22
22
  export declare function partMap(partNameInfo: PartNameInfo): DirectiveResult;
23
+
24
+ /**
25
+ * Parses a whitespace separated list of part names
26
+ * into an object accepted by the `partMap` directive.
27
+ */
28
+ export declare function parsePartNames(partName: string | null | undefined): Record<string, boolean>;
@@ -84,3 +84,19 @@ class PartMapDirective extends Directive {
84
84
  * if the property value is truthy, and removed if the value is falsy.
85
85
  */
86
86
  export const partMap = directive(PartMapDirective);
87
+
88
+ /**
89
+ * Parses a whitespace separated list of part names
90
+ * into an object accepted by the `partMap` directive.
91
+ *
92
+ * @param {string | null | undefined} partName
93
+ * @return {Record<string, boolean>}
94
+ */
95
+ export function parsePartNames(partName) {
96
+ return Object.fromEntries(
97
+ (partName || '')
98
+ .split(/\s+/u)
99
+ .filter((name) => name !== '')
100
+ .map((name) => [name, true]),
101
+ );
102
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 - 2026 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import type { DirectiveResult } from 'lit/directive.js';
7
+
8
+ /**
9
+ * A directive that renders the content of a `<slot>` into the light DOM of
10
+ * the host element. The content must have the `slot` attribute of that slot.
11
+ *
12
+ * Use it as an element expression of the `<slot>` in the template returned by
13
+ * `render()`, e.g. `<slot name="form" ${slotContent(this._renderForm())}></slot>`.
14
+ *
15
+ * On the first render, the directive appends a comment marker to the host and
16
+ * renders the content before it. Children that the host already has stay before
17
+ * the content, and children added later go after the marker, so rendering again
18
+ * does not move or remove them.
19
+ *
20
+ * Always render the directive: pass `nothing` as content instead of removing it,
21
+ * which would leave the content in the light DOM. On the first render, the content
22
+ * is connected before the shadow DOM of the host.
23
+ */
24
+ export declare function slotContent(content: unknown): DirectiveResult;
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2026 - 2026 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { noChange, render } from 'lit';
7
+ import { Directive, directive, PartType } from 'lit/directive.js';
8
+
9
+ class SlotContentDirective extends Directive {
10
+ // Comment node in the light DOM of the host that the content is rendered before.
11
+ #marker = null;
12
+
13
+ constructor(partInfo) {
14
+ super(partInfo);
15
+ if (partInfo.type !== PartType.ELEMENT) {
16
+ throw new Error('`slotContent()` can only be used as an element expression of a `<slot>`.');
17
+ }
18
+ }
19
+
20
+ render(_content) {
21
+ return noChange;
22
+ }
23
+
24
+ update(part, [content]) {
25
+ if (part.element.localName !== 'slot') {
26
+ throw new Error('`slotContent()` can only be used as an element expression of a `<slot>`.');
27
+ }
28
+
29
+ const host = part.options?.host;
30
+ if (!host) {
31
+ throw new Error('`slotContent()` requires the template to be rendered with the `host` option.');
32
+ }
33
+
34
+ // Create a new marker when it was removed, e.g. when the host light DOM was cleared
35
+ if (this.#marker?.parentNode !== host) {
36
+ this.#marker = document.createComment('');
37
+ host.appendChild(this.#marker);
38
+ }
39
+
40
+ render(content, host, { host, renderBefore: this.#marker });
41
+
42
+ return noChange;
43
+ }
44
+ }
45
+
46
+ /**
47
+ * A directive that renders the content of a `<slot>` into the light DOM of
48
+ * the host element. The content must have the `slot` attribute of that slot.
49
+ *
50
+ * Use it as an element expression of the `<slot>` in the template returned by
51
+ * `render()`, e.g. `<slot name="form" ${slotContent(this._renderForm())}></slot>`.
52
+ *
53
+ * On the first render, the directive appends a comment marker to the host and
54
+ * renders the content before it. Children that the host already has stay before
55
+ * the content, and children added later go after the marker, so rendering again
56
+ * does not move or remove them.
57
+ *
58
+ * Always render the directive: pass `nothing` as content instead of removing it,
59
+ * which would leave the content in the light DOM. On the first render, the content
60
+ * is connected before the shadow DOM of the host.
61
+ */
62
+ export const slotContent = directive(SlotContentDirective);
@@ -49,6 +49,9 @@ const ResizeMixinImplementation = (superclass) =>
49
49
 
50
50
  if (!parent.resizables) {
51
51
  parent.resizables = new Set();
52
+ }
53
+
54
+ if (parent.resizables.size === 0) {
52
55
  observer.observe(parent);
53
56
  }
54
57