@vaadin/virtual-list 23.1.0-beta1 → 23.1.0-beta4

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/lit.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './src/lit/renderer-directives.js';
package/lit.js ADDED
@@ -0,0 +1 @@
1
+ export * from './src/lit/renderer-directives.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/virtual-list",
3
- "version": "23.1.0-beta1",
3
+ "version": "23.1.0-beta4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -20,6 +20,8 @@
20
20
  "module": "vaadin-virtual-list.js",
21
21
  "type": "module",
22
22
  "files": [
23
+ "lit.d.ts",
24
+ "lit.js",
23
25
  "src",
24
26
  "theme",
25
27
  "vaadin-*.d.ts",
@@ -34,17 +36,18 @@
34
36
  ],
35
37
  "dependencies": {
36
38
  "@polymer/polymer": "^3.0.0",
37
- "@vaadin/component-base": "23.1.0-beta1",
38
- "@vaadin/vaadin-lumo-styles": "23.1.0-beta1",
39
- "@vaadin/vaadin-material-styles": "23.1.0-beta1",
40
- "@vaadin/vaadin-themable-mixin": "23.1.0-beta1"
39
+ "@vaadin/component-base": "23.1.0-beta4",
40
+ "@vaadin/lit-renderer": "23.1.0-beta4",
41
+ "@vaadin/vaadin-lumo-styles": "23.1.0-beta4",
42
+ "@vaadin/vaadin-material-styles": "23.1.0-beta4",
43
+ "@vaadin/vaadin-themable-mixin": "23.1.0-beta4"
41
44
  },
42
45
  "devDependencies": {
43
46
  "@esm-bundle/chai": "^4.3.4",
44
- "@vaadin/polymer-legacy-adapter": "23.1.0-beta1",
47
+ "@vaadin/polymer-legacy-adapter": "23.1.0-beta4",
45
48
  "@vaadin/testing-helpers": "^0.3.2",
46
49
  "lit": "^2.0.0",
47
50
  "sinon": "^13.0.2"
48
51
  },
49
- "gitHead": "8be43cf83102a6b9ccf309687446e590ce0164e8"
52
+ "gitHead": "06e283473964ecb3085aacf3eddb5333d052a045"
50
53
  }
@@ -0,0 +1,66 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2017 - 2022 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { TemplateResult } from 'lit';
7
+ import { DirectiveResult } from 'lit/directive.js';
8
+ import { LitRendererDirective } from '@vaadin/lit-renderer';
9
+ import { VirtualList, VirtualListItemModel } from '../vaadin-virtual-list.js';
10
+
11
+ export type VirtualListLitRenderer<TItem> = (
12
+ item: TItem,
13
+ model: VirtualListItemModel<TItem>,
14
+ virtualList: VirtualList<TItem>,
15
+ ) => TemplateResult;
16
+
17
+ export class VirtualListRendererDirective<TItem> extends LitRendererDirective<
18
+ VirtualList,
19
+ VirtualListLitRenderer<TItem>
20
+ > {
21
+ /**
22
+ * Adds the renderer callback to the virtual list.
23
+ */
24
+ addRenderer(): void;
25
+
26
+ /**
27
+ * Runs the renderer callback on the virtual list.
28
+ */
29
+ runRenderer(): void;
30
+
31
+ /**
32
+ * Removes the renderer callback from the virtual list.
33
+ */
34
+ removeRenderer(): void;
35
+ }
36
+
37
+ /**
38
+ * A Lit directive for rendering the content of the `<vaadin-virtual-list>` item elements.
39
+ *
40
+ * The directive accepts a renderer callback returning a Lit template and assigns it to the virtual
41
+ * list via the `renderer` property. The renderer is called once to populate the content when
42
+ * assigned and whenever a single dependency or an array of dependencies changes.
43
+ * It is not guaranteed that the renderer will be called immediately (synchronously) in both cases.
44
+ *
45
+ * Dependencies can be a single value or an array of values.
46
+ * Values are checked against previous values with strict equality (`===`),
47
+ * so the check won't detect nested property changes inside objects or arrays.
48
+ * When dependencies are provided as an array, each item is checked against the previous value
49
+ * at the same index with strict equality. Nested arrays are also checked only by strict
50
+ * equality.
51
+ *
52
+ * Example of usage:
53
+ * ```js
54
+ * `<vaadin-virtual-list
55
+ * ${virtualListRenderer((item, model, virtualList) => html`...`)}
56
+ * ></vaadin-virtual-list>`
57
+ * ```
58
+ *
59
+ * @param renderer the renderer callback that returns a Lit template.
60
+ * @param dependencies a single dependency or an array of dependencies
61
+ * which trigger a re-render when changed.
62
+ */
63
+ export declare function virtualListRenderer<TItem>(
64
+ renderer: VirtualListLitRenderer<TItem>,
65
+ dependencies?: unknown,
66
+ ): DirectiveResult<typeof VirtualListRendererDirective>;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2017 - 2022 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { directive } from 'lit/directive.js';
7
+ import { LitRendererDirective } from '@vaadin/lit-renderer';
8
+
9
+ export class VirtualListRendererDirective extends LitRendererDirective {
10
+ /**
11
+ * Adds the renderer callback to the virtual list.
12
+ */
13
+ addRenderer() {
14
+ this.element.renderer = (root, virtualList, model) => {
15
+ this.renderRenderer(root, model.item, model, virtualList);
16
+ };
17
+ }
18
+
19
+ /**
20
+ * Runs the renderer callback on the virtual list.
21
+ */
22
+ runRenderer() {
23
+ this.element.requestContentUpdate();
24
+ }
25
+
26
+ /**
27
+ * Removes the renderer callback from the virtual list.
28
+ */
29
+ removeRenderer() {
30
+ this.element.renderer = null;
31
+ }
32
+ }
33
+
34
+ /**
35
+ * A Lit directive for rendering the content of the `<vaadin-virtual-list>` item elements.
36
+ *
37
+ * The directive accepts a renderer callback returning a Lit template and assigns it to the virtual
38
+ * list via the `renderer` property. The renderer is called once to populate the content when
39
+ * assigned and whenever a single dependency or an array of dependencies changes.
40
+ * It is not guaranteed that the renderer will be called immediately (synchronously) in both cases.
41
+ *
42
+ * Dependencies can be a single value or an array of values.
43
+ * Values are checked against previous values with strict equality (`===`),
44
+ * so the check won't detect nested property changes inside objects or arrays.
45
+ * When dependencies are provided as an array, each item is checked against the previous value
46
+ * at the same index with strict equality. Nested arrays are also checked only by strict
47
+ * equality.
48
+ *
49
+ * Example of usage:
50
+ * ```js
51
+ * `<vaadin-virtual-list
52
+ * ${virtualListRenderer((item, model, virtualList) => html`...`)}
53
+ * ></vaadin-virtual-list>`
54
+ * ```
55
+ *
56
+ * @param renderer the renderer callback that returns a Lit template.
57
+ * @param dependencies a single dependency or an array of dependencies
58
+ * which trigger a re-render when changed.
59
+ */
60
+ export const virtualListRenderer = directive(VirtualListRendererDirective);