@vaadin/message-input 24.6.0-beta1 → 24.6.0

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-input",
3
- "version": "24.6.0-beta1",
3
+ "version": "24.6.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -35,16 +35,18 @@
35
35
  "polymer"
36
36
  ],
37
37
  "dependencies": {
38
+ "@open-wc/dedupe-mixin": "^1.3.0",
38
39
  "@polymer/polymer": "^3.0.0",
39
- "@vaadin/button": "24.6.0-beta1",
40
- "@vaadin/component-base": "24.6.0-beta1",
41
- "@vaadin/text-area": "24.6.0-beta1",
42
- "@vaadin/vaadin-lumo-styles": "24.6.0-beta1",
43
- "@vaadin/vaadin-material-styles": "24.6.0-beta1",
44
- "@vaadin/vaadin-themable-mixin": "24.6.0-beta1"
40
+ "@vaadin/button": "~24.6.0",
41
+ "@vaadin/component-base": "~24.6.0",
42
+ "@vaadin/text-area": "~24.6.0",
43
+ "@vaadin/vaadin-lumo-styles": "~24.6.0",
44
+ "@vaadin/vaadin-material-styles": "~24.6.0",
45
+ "@vaadin/vaadin-themable-mixin": "~24.6.0",
46
+ "lit": "^3.0.0"
45
47
  },
46
48
  "devDependencies": {
47
- "@vaadin/chai-plugins": "24.6.0-beta1",
49
+ "@vaadin/chai-plugins": "~24.6.0",
48
50
  "@vaadin/testing-helpers": "^1.0.0",
49
51
  "sinon": "^18.0.0"
50
52
  },
@@ -52,5 +54,5 @@
52
54
  "web-types.json",
53
55
  "web-types.lit.json"
54
56
  ],
55
- "gitHead": "ab28efb0dcf2cd1ef72100e2e8f32232fa49aacc"
57
+ "gitHead": "c0b38aa981494d04fac64da35aa3890ad72551ea"
56
58
  }
@@ -0,0 +1 @@
1
+ export * from './vaadin-message-input.js';
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2021 - 2024 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import '@vaadin/button/src/vaadin-lit-button.js';
7
+ import '@vaadin/text-area/src/vaadin-lit-text-area.js';
8
+ import { css, html, LitElement } from 'lit';
9
+ import { defineCustomElement } from '@vaadin/component-base/src/define.js';
10
+ import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
11
+ import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
12
+ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
13
+ import { MessageInputMixin } from './vaadin-message-input-mixin.js';
14
+
15
+ /**
16
+ * LitElement based version of `<vaadin-message-input>` web component.
17
+ *
18
+ * ## Disclaimer
19
+ *
20
+ * This component is an experiment and not yet a part of Vaadin platform.
21
+ * There is no ETA regarding specific Vaadin version where it'll land.
22
+ * Feel free to try this code in your apps as per Apache 2.0 license.
23
+ */
24
+ class MessageInput extends MessageInputMixin(ElementMixin(ThemableMixin(PolylitMixin(LitElement)))) {
25
+ static get is() {
26
+ return 'vaadin-message-input';
27
+ }
28
+
29
+ static get styles() {
30
+ return css`
31
+ :host {
32
+ align-items: flex-start;
33
+ box-sizing: border-box;
34
+ display: flex;
35
+ max-height: 50vh;
36
+ overflow: hidden;
37
+ flex-shrink: 0;
38
+ }
39
+
40
+ :host([hidden]) {
41
+ display: none !important;
42
+ }
43
+
44
+ ::slotted([slot='button']) {
45
+ flex-shrink: 0;
46
+ }
47
+
48
+ ::slotted([slot='textarea']) {
49
+ align-self: stretch;
50
+ flex-grow: 1;
51
+ }
52
+ `;
53
+ }
54
+
55
+ /** @protected */
56
+ render() {
57
+ return html`
58
+ <slot name="textarea"></slot>
59
+
60
+ <slot name="button"></slot>
61
+
62
+ <slot name="tooltip"></slot>
63
+ `;
64
+ }
65
+ }
66
+
67
+ defineCustomElement(MessageInput);
68
+
69
+ export { MessageInput };
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2021 - 2024 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import type { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type { ControllerMixinClass } from '@vaadin/component-base/src/controller-mixin.js';
8
+
9
+ export interface MessageInputI18n {
10
+ send: string;
11
+ message: string;
12
+ }
13
+
14
+ export declare function MessageInputMixin<T extends Constructor<HTMLElement>>(
15
+ base: T,
16
+ ): Constructor<ControllerMixinClass> & Constructor<MessageInputMixinClass> & T;
17
+
18
+ export declare class MessageInputMixinClass {
19
+ /**
20
+ * Current content of the text input field
21
+ */
22
+ value: string | null | undefined;
23
+
24
+ /**
25
+ * The object used to localize this component.
26
+ * For changing the default localization, change the entire
27
+ * `i18n` object.
28
+ *
29
+ * The object has the following JSON structure and default values:
30
+ *
31
+ * ```
32
+ * {
33
+ * // Used as the button label
34
+ * send: 'Send',
35
+ *
36
+ * // Used as the input field's placeholder and aria-label
37
+ * message: 'Message'
38
+ * }
39
+ * ```
40
+ */
41
+ i18n: MessageInputI18n;
42
+
43
+ /**
44
+ * Set to true to disable this element.
45
+ */
46
+ disabled: boolean;
47
+ }
@@ -0,0 +1,188 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2021 - 2024 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
7
+ import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
8
+ import { TooltipController } from '@vaadin/component-base/src/tooltip-controller.js';
9
+
10
+ /**
11
+ * @polymerMixin
12
+ * @mixes ControllerMixin
13
+ */
14
+ export const MessageInputMixin = (superClass) =>
15
+ class MessageInputMixinClass extends ControllerMixin(superClass) {
16
+ static get properties() {
17
+ return {
18
+ /**
19
+ * Current content of the text input field
20
+ */
21
+ value: {
22
+ type: String,
23
+ value: '',
24
+ sync: true,
25
+ },
26
+
27
+ /**
28
+ * The object used to localize this component.
29
+ * For changing the default localization, change the entire
30
+ * `i18n` object.
31
+ *
32
+ * The object has the following JSON structure and default values:
33
+ *
34
+ * ```
35
+ * {
36
+ * // Used as the button label
37
+ * send: 'Send',
38
+ *
39
+ * // Used as the input field's placeholder and aria-label
40
+ * message: 'Message'
41
+ * }
42
+ * ```
43
+ *
44
+ * @type {!MessageInputI18n}
45
+ * @default {English}
46
+ */
47
+ i18n: {
48
+ type: Object,
49
+ sync: true,
50
+ value: () => ({
51
+ send: 'Send',
52
+ message: 'Message',
53
+ }),
54
+ },
55
+
56
+ /**
57
+ * Set to true to disable this element.
58
+ * @type {boolean}
59
+ */
60
+ disabled: {
61
+ type: Boolean,
62
+ value: false,
63
+ reflectToAttribute: true,
64
+ sync: true,
65
+ },
66
+
67
+ /** @private */
68
+ _button: {
69
+ type: Object,
70
+ sync: true,
71
+ },
72
+
73
+ /** @private */
74
+ _textArea: {
75
+ type: Object,
76
+ sync: true,
77
+ },
78
+ };
79
+ }
80
+
81
+ static get observers() {
82
+ return [
83
+ '__buttonPropsChanged(_button, disabled, i18n)',
84
+ '__textAreaPropsChanged(_textArea, disabled, i18n, value)',
85
+ ];
86
+ }
87
+
88
+ /** @protected */
89
+ ready() {
90
+ super.ready();
91
+
92
+ this._buttonController = new SlotController(this, 'button', 'vaadin-button', {
93
+ initializer: (btn) => {
94
+ btn.setAttribute('theme', 'primary contained');
95
+
96
+ btn.addEventListener('click', () => {
97
+ this.__submit();
98
+ });
99
+
100
+ this._button = btn;
101
+ },
102
+ });
103
+ this.addController(this._buttonController);
104
+
105
+ this._textAreaController = new SlotController(this, 'textarea', 'vaadin-text-area', {
106
+ initializer: (textarea) => {
107
+ textarea.addEventListener('value-changed', (event) => {
108
+ this.value = event.detail.value;
109
+ });
110
+
111
+ textarea.addEventListener('keydown', (event) => {
112
+ if (event.key === 'Enter' && !event.shiftKey) {
113
+ event.preventDefault();
114
+ event.stopImmediatePropagation();
115
+ this.__submit();
116
+ }
117
+ });
118
+
119
+ // With Lit version, input element renders asynchronously and it will
120
+ // override the `rows` attribute set to `1` in the `minRows` observer.
121
+ // Workaround: perform update twice to run the observer synchronously.
122
+ // TODO: needs https://github.com/vaadin/web-components/pull/8168
123
+ if (textarea.performUpdate) {
124
+ textarea.performUpdate();
125
+ textarea.performUpdate();
126
+ }
127
+
128
+ const input = textarea.inputElement;
129
+
130
+ // Set initial height to one row
131
+ input.setAttribute('rows', 1);
132
+ input.style.minHeight = '0';
133
+
134
+ this._textArea = textarea;
135
+ },
136
+ });
137
+ this.addController(this._textAreaController);
138
+
139
+ this._tooltipController = new TooltipController(this);
140
+ this.addController(this._tooltipController);
141
+ }
142
+
143
+ focus() {
144
+ if (this._textArea) {
145
+ this._textArea.focus();
146
+ }
147
+ }
148
+
149
+ /** @private */
150
+ __buttonPropsChanged(button, disabled, i18n) {
151
+ if (button) {
152
+ button.disabled = disabled;
153
+ button.textContent = i18n.send;
154
+ }
155
+ }
156
+
157
+ /** @private */
158
+ __textAreaPropsChanged(textArea, disabled, i18n, value) {
159
+ if (textArea) {
160
+ textArea.disabled = disabled;
161
+ textArea.value = value;
162
+
163
+ const message = i18n.message;
164
+ textArea.placeholder = message;
165
+ textArea.accessibleName = message;
166
+ }
167
+ }
168
+
169
+ /**
170
+ * Submits the current value as an custom event named 'submit'.
171
+ * It also clears the text input and refocuses it for sending another message.
172
+ * In UI, can be triggered by pressing the submit button or pressing enter key when field is focused.
173
+ * It does not submit anything if text is empty.
174
+ */
175
+ __submit() {
176
+ if (this.value !== '') {
177
+ this.dispatchEvent(new CustomEvent('submit', { detail: { value: this.value } }));
178
+ this.value = '';
179
+ }
180
+ this._textArea.focus();
181
+ }
182
+
183
+ /**
184
+ * Fired when a new message is submitted with `<vaadin-message-input>`, either
185
+ * by clicking the "send" button, or pressing the Enter key.
186
+ * @event submit
187
+ */
188
+ };
@@ -3,14 +3,11 @@
3
3
  * Copyright (c) 2021 - 2024 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
7
6
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
8
7
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
8
+ import { MessageInputMixin } from './vaadin-message-input-mixin.js';
9
9
 
10
- export interface MessageInputI18n {
11
- send: string;
12
- message: string;
13
- }
10
+ export { MessageInputI18n } from './vaadin-message-input-mixin.js';
14
11
 
15
12
  /**
16
13
  * Fired when a new message is submitted with `<vaadin-message-input>`, either
@@ -36,36 +33,7 @@ export type MessageInputEventMap = HTMLElementEventMap & MessageInputCustomEvent
36
33
  * <vaadin-message-input></vaadin-message-input>
37
34
  * ```
38
35
  */
39
- declare class MessageInput extends ThemableMixin(ElementMixin(ControllerMixin(HTMLElement))) {
40
- /**
41
- * Current content of the text input field
42
- */
43
- value: string | null | undefined;
44
-
45
- /**
46
- * The object used to localize this component.
47
- * For changing the default localization, change the entire
48
- * `i18n` object.
49
- *
50
- * The object has the following JSON structure and default values:
51
- *
52
- * ```
53
- * {
54
- * // Used as the button label
55
- * send: 'Send',
56
- *
57
- * // Used as the input field's placeholder and aria-label
58
- * message: 'Message'
59
- * }
60
- * ```
61
- */
62
- i18n: MessageInputI18n;
63
-
64
- /**
65
- * Set to true to disable this element.
66
- */
67
- disabled: boolean;
68
-
36
+ declare class MessageInput extends MessageInputMixin(ThemableMixin(ElementMixin(HTMLElement))) {
69
37
  addEventListener<K extends keyof MessageInputEventMap>(
70
38
  type: K,
71
39
  listener: (this: MessageInput, ev: MessageInputEventMap[K]) => void,
@@ -6,12 +6,10 @@
6
6
  import '@vaadin/button/src/vaadin-button.js';
7
7
  import '@vaadin/text-area/src/vaadin-text-area.js';
8
8
  import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
9
- import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
10
9
  import { defineCustomElement } from '@vaadin/component-base/src/define.js';
11
10
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
12
- import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
13
- import { TooltipController } from '@vaadin/component-base/src/tooltip-controller.js';
14
11
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
12
+ import { MessageInputMixin } from './vaadin-message-input-mixin.js';
15
13
 
16
14
  /**
17
15
  * `<vaadin-message-input>` is a Web Component for sending messages.
@@ -27,71 +25,11 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
27
25
  *
28
26
  * @customElement
29
27
  * @extends HTMLElement
30
- * @mixes ControllerMixin
28
+ * @mixes MessageInputMixin
31
29
  * @mixes ThemableMixin
32
30
  * @mixes ElementMixin
33
31
  */
34
- class MessageInput extends ElementMixin(ThemableMixin(ControllerMixin(PolymerElement))) {
35
- static get properties() {
36
- return {
37
- /**
38
- * Current content of the text input field
39
- */
40
- value: {
41
- type: String,
42
- value: '',
43
- },
44
-
45
- /**
46
- * The object used to localize this component.
47
- * For changing the default localization, change the entire
48
- * `i18n` object.
49
- *
50
- * The object has the following JSON structure and default values:
51
- *
52
- * ```
53
- * {
54
- * // Used as the button label
55
- * send: 'Send',
56
- *
57
- * // Used as the input field's placeholder and aria-label
58
- * message: 'Message'
59
- * }
60
- * ```
61
- *
62
- * @type {!MessageInputI18n}
63
- * @default {English}
64
- */
65
- i18n: {
66
- type: Object,
67
- value: () => ({
68
- send: 'Send',
69
- message: 'Message',
70
- }),
71
- },
72
-
73
- /**
74
- * Set to true to disable this element.
75
- * @type {boolean}
76
- */
77
- disabled: {
78
- type: Boolean,
79
- value: false,
80
- reflectToAttribute: true,
81
- },
82
-
83
- /** @private */
84
- _button: {
85
- type: Object,
86
- },
87
-
88
- /** @private */
89
- _textArea: {
90
- type: Object,
91
- },
92
- };
93
- }
94
-
32
+ class MessageInput extends MessageInputMixin(ElementMixin(ThemableMixin(PolymerElement))) {
95
33
  static get template() {
96
34
  return html`
97
35
  <style>
@@ -128,111 +66,6 @@ class MessageInput extends ElementMixin(ThemableMixin(ControllerMixin(PolymerEle
128
66
  static get is() {
129
67
  return 'vaadin-message-input';
130
68
  }
131
-
132
- static get observers() {
133
- return [
134
- '__buttonPropsChanged(_button, disabled, i18n)',
135
- '__textAreaPropsChanged(_textArea, disabled, i18n, value)',
136
- ];
137
- }
138
-
139
- /** @protected */
140
- ready() {
141
- super.ready();
142
-
143
- this._buttonController = new SlotController(this, 'button', 'vaadin-button', {
144
- initializer: (btn) => {
145
- btn.setAttribute('theme', 'primary contained');
146
-
147
- btn.addEventListener('click', () => {
148
- this.__submit();
149
- });
150
-
151
- this._button = btn;
152
- },
153
- });
154
- this.addController(this._buttonController);
155
-
156
- this._textAreaController = new SlotController(this, 'textarea', 'vaadin-text-area', {
157
- initializer: (textarea) => {
158
- textarea.addEventListener('value-changed', (event) => {
159
- this.value = event.detail.value;
160
- });
161
-
162
- textarea.addEventListener('keydown', (event) => {
163
- if (event.key === 'Enter' && !event.shiftKey) {
164
- event.preventDefault();
165
- event.stopImmediatePropagation();
166
- this.__submit();
167
- }
168
- });
169
-
170
- const input = textarea.inputElement;
171
- input.removeAttribute('aria-labelledby');
172
-
173
- // Set initial height to one row
174
- input.setAttribute('rows', 1);
175
- input.style.minHeight = '0';
176
-
177
- this._textArea = textarea;
178
- },
179
- });
180
- this.addController(this._textAreaController);
181
-
182
- this._tooltipController = new TooltipController(this);
183
- this.addController(this._tooltipController);
184
- }
185
-
186
- focus() {
187
- if (this._textArea) {
188
- this._textArea.focus();
189
- }
190
- }
191
-
192
- /** @private */
193
- __buttonPropsChanged(button, disabled, i18n) {
194
- if (button) {
195
- button.disabled = disabled;
196
- button.textContent = i18n.send;
197
- }
198
- }
199
-
200
- /** @private */
201
- __textAreaPropsChanged(textArea, disabled, i18n, value) {
202
- if (textArea) {
203
- textArea.disabled = disabled;
204
- textArea.value = value;
205
-
206
- const message = i18n.message;
207
- textArea.placeholder = message;
208
-
209
- if (message) {
210
- textArea.inputElement.setAttribute('aria-label', message);
211
- } else {
212
- textArea.inputElement.removeAttribute('aria-label');
213
- }
214
- }
215
- }
216
-
217
- /**
218
- * Submits the current value as an custom event named 'submit'.
219
- * It also clears the text input and refocuses it for sending another message.
220
- * In UI, can be triggered by pressing the submit button or pressing enter key when field is focused.
221
- * It does not submit anything if text is empty.
222
- */
223
- __submit() {
224
- if (this.value !== '') {
225
- this.dispatchEvent(new CustomEvent('submit', { detail: { value: this.value } }));
226
- this.value = '';
227
- }
228
- this._textArea.focus();
229
- }
230
-
231
- /**
232
- * Fired when a new message is submitted with `<vaadin-message-input>`, either
233
- * by clicking the "send" button, or pressing the Enter key.
234
- * @event submit
235
- */
236
69
  }
237
70
 
238
71
  defineCustomElement(MessageInput);
@@ -0,0 +1,4 @@
1
+ import '@vaadin/button/theme/lumo/vaadin-lit-button.js';
2
+ import '@vaadin/text-area/theme/lumo/vaadin-lit-text-area.js';
3
+ import './vaadin-message-input-styles.js';
4
+ import '../../src/vaadin-lit-message-input.js';
@@ -0,0 +1,4 @@
1
+ import '@vaadin/button/theme/lumo/vaadin-lit-button.js';
2
+ import '@vaadin/text-area/theme/lumo/vaadin-lit-text-area.js';
3
+ import './vaadin-message-input-styles.js';
4
+ import '../../src/vaadin-lit-message-input.js';
@@ -0,0 +1,4 @@
1
+ import '@vaadin/button/theme/material/vaadin-lit-button.js';
2
+ import '@vaadin/text-area/theme/material/vaadin-lit-text-area.js';
3
+ import './vaadin-message-input-styles.js';
4
+ import '../../src/vaadin-lit-message-input.js';
@@ -0,0 +1,4 @@
1
+ import '@vaadin/button/theme/material/vaadin-lit-button.js';
2
+ import '@vaadin/text-area/theme/material/vaadin-lit-text-area.js';
3
+ import './vaadin-message-input-styles.js';
4
+ import '../../src/vaadin-lit-message-input.js';
@@ -0,0 +1 @@
1
+ export * from './src/vaadin-message-input.js';
@@ -0,0 +1,2 @@
1
+ import './theme/lumo/vaadin-lit-message-input.js';
2
+ export * from './src/vaadin-lit-message-input.js';
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-input",
4
- "version": "24.6.0-beta1",
4
+ "version": "24.6.0",
5
5
  "description-markup": "markdown",
6
6
  "contributions": {
7
7
  "html": {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/message-input",
4
- "version": "24.6.0-beta1",
4
+ "version": "24.6.0",
5
5
  "description-markup": "markdown",
6
6
  "framework": "lit",
7
7
  "framework-config": {