@vaadin/message-list 24.0.0-alpha1 → 24.0.0-alpha2

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/message-list",
3
- "version": "24.0.0-alpha1",
3
+ "version": "24.0.0-alpha2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -38,11 +38,12 @@
38
38
  ],
39
39
  "dependencies": {
40
40
  "@polymer/polymer": "^3.0.0",
41
- "@vaadin/avatar": "24.0.0-alpha1",
42
- "@vaadin/component-base": "24.0.0-alpha1",
43
- "@vaadin/vaadin-lumo-styles": "24.0.0-alpha1",
44
- "@vaadin/vaadin-material-styles": "24.0.0-alpha1",
45
- "@vaadin/vaadin-themable-mixin": "24.0.0-alpha1"
41
+ "@vaadin/avatar": "24.0.0-alpha2",
42
+ "@vaadin/component-base": "24.0.0-alpha2",
43
+ "@vaadin/vaadin-lumo-styles": "24.0.0-alpha2",
44
+ "@vaadin/vaadin-material-styles": "24.0.0-alpha2",
45
+ "@vaadin/vaadin-themable-mixin": "24.0.0-alpha2",
46
+ "lit": "^2.0.0"
46
47
  },
47
48
  "devDependencies": {
48
49
  "@esm-bundle/chai": "^4.3.4",
@@ -53,5 +54,5 @@
53
54
  "web-types.json",
54
55
  "web-types.lit.json"
55
56
  ],
56
- "gitHead": "427527c27c4b27822d61fd41d38d7b170134770b"
57
+ "gitHead": "0c16c01a6807e629a84f5a982793afecc1a7ced0"
57
58
  }
@@ -3,7 +3,9 @@
3
3
  * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
6
+ import { html as legacyHtml, PolymerElement } from '@polymer/polymer/polymer-element.js';
7
+ import { html, render } from 'lit';
8
+ import { ifDefined } from 'lit/directives/if-defined.js';
7
9
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
8
10
  import { KeyboardDirectionMixin } from '@vaadin/component-base/src/keyboard-direction-mixin.js';
9
11
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
@@ -78,7 +80,7 @@ class MessageList extends KeyboardDirectionMixin(ElementMixin(ThemableMixin(Poly
78
80
  }
79
81
 
80
82
  static get template() {
81
- return html`
83
+ return legacyHtml`
82
84
  <style>
83
85
  :host {
84
86
  display: block;
@@ -130,20 +132,7 @@ class MessageList extends KeyboardDirectionMixin(ElementMixin(ThemableMixin(Poly
130
132
  const focusedIndex = this._getIndexOfFocusableElement();
131
133
  const closeToBottom = this.scrollHeight < this.clientHeight + this.scrollTop + 50;
132
134
 
133
- const removed = oldItems.filter((item) => !items.includes(item));
134
- const added = [...items];
135
-
136
- this._messages.forEach((message) => {
137
- const item = message._item;
138
- if (removed.includes(item)) {
139
- message.remove();
140
- } else if (added.includes(item)) {
141
- added.splice(added.indexOf(item), 1);
142
- }
143
- });
144
-
145
- this.__addMessages(added, items);
146
-
135
+ this._renderMessages(items);
147
136
  this._setTabIndexesByIndex(focusedIndex);
148
137
 
149
138
  requestAnimationFrame(() => {
@@ -155,42 +144,29 @@ class MessageList extends KeyboardDirectionMixin(ElementMixin(ThemableMixin(Poly
155
144
  }
156
145
 
157
146
  /** @private */
158
- __addMessages(itemsToAdd, allItems) {
159
- itemsToAdd.forEach((item) => {
160
- const message = this.__createMessage(item);
161
- const nextItem = allItems[allItems.indexOf(item) + 1];
162
- const nextMessage = this._messages.find((msg) => msg._item === nextItem);
163
- if (nextMessage) {
164
- this.insertBefore(message, nextMessage);
165
- } else {
166
- this.appendChild(message);
167
- }
168
- });
169
- }
170
-
171
- /** @private */
172
- __createMessage(item) {
173
- const message = document.createElement('vaadin-message');
174
- message.setAttribute('role', 'listitem');
175
-
176
- message.textContent = item.text;
177
- message.time = item.time;
178
- message.userName = item.userName;
179
- message.userAbbr = item.userAbbr;
180
- message.userImg = item.userImg;
181
- message.userColorIndex = item.userColorIndex;
182
-
183
- message._item = item;
184
-
185
- if (item.theme) {
186
- message.setAttribute('theme', item.theme);
187
- }
188
-
189
- message.addEventListener('focusin', (e) => {
190
- this._onMessageFocusIn(e);
191
- });
192
-
193
- return message;
147
+ _renderMessages(items) {
148
+ render(
149
+ html`
150
+ ${items.map(
151
+ (item) =>
152
+ html`
153
+ <vaadin-message
154
+ role="listitem"
155
+ .time="${item.time}"
156
+ .userAbbr="${item.userAbbr}"
157
+ .userName="${item.userName}"
158
+ .userImg="${item.userImg}"
159
+ .userColorIndex="${item.userColorIndex}"
160
+ theme="${ifDefined(item.theme)}"
161
+ @focusin="${this._onMessageFocusIn}"
162
+ >${item.text}</vaadin-message
163
+ >
164
+ `,
165
+ )}
166
+ `,
167
+ this,
168
+ { host: this },
169
+ );
194
170
  }
195
171
 
196
172
  /** @private */
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/message-list",
4
- "version": "24.0.0-alpha1",
4
+ "version": "24.0.0-alpha2",
5
5
  "description-markup": "markdown",
6
6
  "contributions": {
7
7
  "html": {
@@ -140,7 +140,7 @@
140
140
  },
141
141
  {
142
142
  "name": "vaadin-message-list",
143
- "description": "`<vaadin-message-list>` is a Web Component for showing an ordered list of messages. The messages are rendered as <vaadin-message>\n\n### Example\n\nTo create a new message list, add the component to the page:\n\n```html\n<vaadin-message-list></vaadin-message-list>\n```\n\nProvide the messages to the message list with the [`items`](https://cdn.vaadin.com/vaadin-web-components/24.0.0-alpha1/#/elements/vaadin-message-list#property-items) property.\n\n```js\ndocument.querySelector('vaadin-message-list').items = [\n { text: 'Hello list', time: 'yesterday', userName: 'Matt Mambo', userAbbr: 'MM', userColorIndex: 1 },\n { text: 'Another message', time: 'right now', userName: 'Linsey Listy', userAbbr: 'LL', userColorIndex: 2, userImg: '/static/img/avatar.jpg' }\n];\n```\n\n### Styling\n\nThe following shadow DOM parts are available for styling:\n\nPart name | Description\n----------|----------------\n`list` | The container wrapping messages.\n\nSee the [`<vaadin-message>`](https://cdn.vaadin.com/vaadin-web-components/24.0.0-alpha1/#/elements/vaadin-message) documentation for the available\nstate attributes and stylable shadow parts of message elements.\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.",
143
+ "description": "`<vaadin-message-list>` is a Web Component for showing an ordered list of messages. The messages are rendered as <vaadin-message>\n\n### Example\n\nTo create a new message list, add the component to the page:\n\n```html\n<vaadin-message-list></vaadin-message-list>\n```\n\nProvide the messages to the message list with the [`items`](https://cdn.vaadin.com/vaadin-web-components/24.0.0-alpha2/#/elements/vaadin-message-list#property-items) property.\n\n```js\ndocument.querySelector('vaadin-message-list').items = [\n { text: 'Hello list', time: 'yesterday', userName: 'Matt Mambo', userAbbr: 'MM', userColorIndex: 1 },\n { text: 'Another message', time: 'right now', userName: 'Linsey Listy', userAbbr: 'LL', userColorIndex: 2, userImg: '/static/img/avatar.jpg' }\n];\n```\n\n### Styling\n\nThe following shadow DOM parts are available for styling:\n\nPart name | Description\n----------|----------------\n`list` | The container wrapping messages.\n\nSee the [`<vaadin-message>`](https://cdn.vaadin.com/vaadin-web-components/24.0.0-alpha2/#/elements/vaadin-message) documentation for the available\nstate attributes and stylable shadow parts of message elements.\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.",
144
144
  "attributes": [
145
145
  {
146
146
  "name": "theme",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/message-list",
4
- "version": "24.0.0-alpha1",
4
+ "version": "24.0.0-alpha2",
5
5
  "description-markup": "markdown",
6
6
  "framework": "lit",
7
7
  "framework-config": {
@@ -58,7 +58,7 @@
58
58
  },
59
59
  {
60
60
  "name": "vaadin-message-list",
61
- "description": "`<vaadin-message-list>` is a Web Component for showing an ordered list of messages. The messages are rendered as <vaadin-message>\n\n### Example\n\nTo create a new message list, add the component to the page:\n\n```html\n<vaadin-message-list></vaadin-message-list>\n```\n\nProvide the messages to the message list with the [`items`](https://cdn.vaadin.com/vaadin-web-components/24.0.0-alpha1/#/elements/vaadin-message-list#property-items) property.\n\n```js\ndocument.querySelector('vaadin-message-list').items = [\n { text: 'Hello list', time: 'yesterday', userName: 'Matt Mambo', userAbbr: 'MM', userColorIndex: 1 },\n { text: 'Another message', time: 'right now', userName: 'Linsey Listy', userAbbr: 'LL', userColorIndex: 2, userImg: '/static/img/avatar.jpg' }\n];\n```\n\n### Styling\n\nThe following shadow DOM parts are available for styling:\n\nPart name | Description\n----------|----------------\n`list` | The container wrapping messages.\n\nSee the [`<vaadin-message>`](https://cdn.vaadin.com/vaadin-web-components/24.0.0-alpha1/#/elements/vaadin-message) documentation for the available\nstate attributes and stylable shadow parts of message elements.\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.",
61
+ "description": "`<vaadin-message-list>` is a Web Component for showing an ordered list of messages. The messages are rendered as <vaadin-message>\n\n### Example\n\nTo create a new message list, add the component to the page:\n\n```html\n<vaadin-message-list></vaadin-message-list>\n```\n\nProvide the messages to the message list with the [`items`](https://cdn.vaadin.com/vaadin-web-components/24.0.0-alpha2/#/elements/vaadin-message-list#property-items) property.\n\n```js\ndocument.querySelector('vaadin-message-list').items = [\n { text: 'Hello list', time: 'yesterday', userName: 'Matt Mambo', userAbbr: 'MM', userColorIndex: 1 },\n { text: 'Another message', time: 'right now', userName: 'Linsey Listy', userAbbr: 'LL', userColorIndex: 2, userImg: '/static/img/avatar.jpg' }\n];\n```\n\n### Styling\n\nThe following shadow DOM parts are available for styling:\n\nPart name | Description\n----------|----------------\n`list` | The container wrapping messages.\n\nSee the [`<vaadin-message>`](https://cdn.vaadin.com/vaadin-web-components/24.0.0-alpha2/#/elements/vaadin-message) documentation for the available\nstate attributes and stylable shadow parts of message elements.\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/custom-theme/styling-components) documentation.",
62
62
  "extension": true,
63
63
  "attributes": [
64
64
  {