@vaadin/dialog 23.1.0-alpha4 → 23.1.0-beta3
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 +1 -0
- package/lit.js +1 -0
- package/package.json +12 -9
- package/src/lit/renderer-directives.d.ts +139 -0
- package/src/lit/renderer-directives.js +147 -0
- package/src/vaadin-dialog.js +5 -12
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/dialog",
|
|
3
|
-
"version": "23.1.0-
|
|
3
|
+
"version": "23.1.0-beta3",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
"files": [
|
|
23
23
|
"src",
|
|
24
24
|
"theme",
|
|
25
|
+
"lit.js",
|
|
26
|
+
"lit.d.ts",
|
|
25
27
|
"vaadin-*.d.ts",
|
|
26
28
|
"vaadin-*.js"
|
|
27
29
|
],
|
|
@@ -35,18 +37,19 @@
|
|
|
35
37
|
"dependencies": {
|
|
36
38
|
"@open-wc/dedupe-mixin": "^1.3.0",
|
|
37
39
|
"@polymer/polymer": "^3.0.0",
|
|
38
|
-
"@vaadin/component-base": "23.1.0-
|
|
39
|
-
"@vaadin/
|
|
40
|
-
"@vaadin/vaadin-
|
|
41
|
-
"@vaadin/vaadin-
|
|
42
|
-
"@vaadin/vaadin-
|
|
40
|
+
"@vaadin/component-base": "23.1.0-beta3",
|
|
41
|
+
"@vaadin/lit-renderer": "23.1.0-beta3",
|
|
42
|
+
"@vaadin/vaadin-lumo-styles": "23.1.0-beta3",
|
|
43
|
+
"@vaadin/vaadin-material-styles": "23.1.0-beta3",
|
|
44
|
+
"@vaadin/vaadin-overlay": "23.1.0-beta3",
|
|
45
|
+
"@vaadin/vaadin-themable-mixin": "23.1.0-beta3"
|
|
43
46
|
},
|
|
44
47
|
"devDependencies": {
|
|
45
48
|
"@esm-bundle/chai": "^4.3.4",
|
|
46
|
-
"@vaadin/polymer-legacy-adapter": "23.1.0-
|
|
49
|
+
"@vaadin/polymer-legacy-adapter": "23.1.0-beta3",
|
|
47
50
|
"@vaadin/testing-helpers": "^0.3.2",
|
|
48
|
-
"@vaadin/text-area": "23.1.0-
|
|
51
|
+
"@vaadin/text-area": "23.1.0-beta3",
|
|
49
52
|
"sinon": "^13.0.2"
|
|
50
53
|
},
|
|
51
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "c787ceb8a312f88631c6d429ff320d5f89b1b838"
|
|
52
55
|
}
|
|
@@ -0,0 +1,139 @@
|
|
|
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
|
+
/* eslint-disable max-classes-per-file */
|
|
7
|
+
import { TemplateResult } from 'lit';
|
|
8
|
+
import { DirectiveResult } from 'lit/directive.js';
|
|
9
|
+
import { LitRendererDirective } from '@vaadin/lit-renderer';
|
|
10
|
+
import { Dialog } from '../vaadin-dialog.js';
|
|
11
|
+
|
|
12
|
+
export type DialogLitRenderer = (dialog: Dialog) => TemplateResult;
|
|
13
|
+
|
|
14
|
+
declare abstract class AbstractDialogRendererDirective extends LitRendererDirective<Dialog, DialogLitRenderer> {
|
|
15
|
+
/**
|
|
16
|
+
* A property to that the renderer callback will be assigned.
|
|
17
|
+
*/
|
|
18
|
+
abstract rendererProperty: 'renderer' | 'headerRenderer' | 'footerRenderer';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Adds the renderer callback to the dialog.
|
|
22
|
+
*/
|
|
23
|
+
addRenderer(): void;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Runs the renderer callback on the dialog.
|
|
27
|
+
*/
|
|
28
|
+
runRenderer(): void;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Removes the renderer callback from the dialog.
|
|
32
|
+
*/
|
|
33
|
+
removeRenderer(): void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class DialogRendererDirective extends AbstractDialogRendererDirective {
|
|
37
|
+
rendererProperty: 'renderer';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export class DialogHeaderRendererDirective extends AbstractDialogRendererDirective {
|
|
41
|
+
rendererProperty: 'headerRenderer';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class DialogFooterRendererDirective extends AbstractDialogRendererDirective {
|
|
45
|
+
rendererProperty: 'footerRenderer';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A Lit directive for populating the content of the dialog.
|
|
50
|
+
*
|
|
51
|
+
* The directive accepts a renderer callback returning a Lit template and assigns it to the dialog
|
|
52
|
+
* via the `renderer` property. The renderer is called to populate the content once when assigned
|
|
53
|
+
* and whenever a single dependency or an array of dependencies changes.
|
|
54
|
+
* It is not guaranteed that the renderer will be called immediately (synchronously) in both cases.
|
|
55
|
+
*
|
|
56
|
+
* Dependencies can be a single value or an array of values.
|
|
57
|
+
* Values are checked against previous values with strict equality (`===`),
|
|
58
|
+
* so the check won't detect nested property changes inside objects or arrays.
|
|
59
|
+
* When dependencies are provided as an array, each item is checked against the previous value
|
|
60
|
+
* at the same index with strict equality. Nested arrays are also checked only by strict
|
|
61
|
+
* equality.
|
|
62
|
+
*
|
|
63
|
+
* Example of usage:
|
|
64
|
+
* ```js
|
|
65
|
+
* `<vaadin-dialog
|
|
66
|
+
* ${dialogRenderer((dialog) => html`...`)}
|
|
67
|
+
* ></vaadin-dialog>`
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @param renderer the renderer callback that returns a Lit template.
|
|
71
|
+
* @param dependencies a single dependency or an array of dependencies
|
|
72
|
+
* which trigger a re-render when changed.
|
|
73
|
+
*/
|
|
74
|
+
export declare function dialogRenderer(
|
|
75
|
+
renderer: DialogLitRenderer,
|
|
76
|
+
dependencies?: unknown,
|
|
77
|
+
): DirectiveResult<typeof DialogRendererDirective>;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* A Lit directive for populating the content of the dialog header.
|
|
81
|
+
*
|
|
82
|
+
* The directive accepts a renderer callback returning a Lit template and assigns it to the dialog
|
|
83
|
+
* via the `headerRenderer` property. The renderer is called to populate the content once
|
|
84
|
+
* when assigned and whenever a single dependency or an array of dependencies changes.
|
|
85
|
+
* It is not guaranteed that the renderer will be called immediately (synchronously) in both cases.
|
|
86
|
+
*
|
|
87
|
+
* Dependencies can be a single value or an array of values.
|
|
88
|
+
* Values are checked against previous values with strict equality (`===`),
|
|
89
|
+
* so the check won't detect nested property changes inside objects or arrays.
|
|
90
|
+
* When dependencies are provided as an array, each item is checked against the previous value
|
|
91
|
+
* at the same index with strict equality. Nested arrays are also checked only by strict
|
|
92
|
+
* equality.
|
|
93
|
+
*
|
|
94
|
+
* Example of usage:
|
|
95
|
+
* ```js
|
|
96
|
+
* `<vaadin-dialog
|
|
97
|
+
* ${dialogHeaderRenderer((dialog) => html`...`)}
|
|
98
|
+
* ></vaadin-dialog>`
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* @param renderer the renderer callback.
|
|
102
|
+
* @param dependencies a single dependency or an array of dependencies
|
|
103
|
+
* which trigger a re-render when changed.
|
|
104
|
+
*/
|
|
105
|
+
export declare function dialogHeaderRenderer(
|
|
106
|
+
renderer: DialogLitRenderer,
|
|
107
|
+
dependencies?: unknown,
|
|
108
|
+
): DirectiveResult<typeof DialogHeaderRendererDirective>;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* A Lit directive for populating the content of the dialog footer.
|
|
112
|
+
*
|
|
113
|
+
* The directive accepts a renderer callback returning a Lit template and assigns it to the dialog
|
|
114
|
+
* via the `footerRenderer` property. The renderer is called to populate the content once when assigned
|
|
115
|
+
* and whenever a single dependency or an array of dependencies changes.
|
|
116
|
+
* It is not guaranteed that the renderer will be called immediately (synchronously) in both cases.
|
|
117
|
+
*
|
|
118
|
+
* Dependencies can be a single value or an array of values.
|
|
119
|
+
* Values are checked against previous values with strict equality (`===`),
|
|
120
|
+
* so the check won't detect nested property changes inside objects or arrays.
|
|
121
|
+
* When dependencies are provided as an array, each item is checked against the previous value
|
|
122
|
+
* at the same index with strict equality. Nested arrays are also checked only by strict
|
|
123
|
+
* equality.
|
|
124
|
+
*
|
|
125
|
+
* Example of usage:
|
|
126
|
+
* ```js
|
|
127
|
+
* `<vaadin-dialog
|
|
128
|
+
* ${dialogFooterRenderer((dialog) => html`...`)}
|
|
129
|
+
* ></vaadin-dialog>`
|
|
130
|
+
* ```
|
|
131
|
+
*
|
|
132
|
+
* @param renderer the renderer callback.
|
|
133
|
+
* @param dependencies a single dependency or an array of dependencies
|
|
134
|
+
* which trigger a re-render when changed.
|
|
135
|
+
*/
|
|
136
|
+
export declare function dialogFooterRenderer(
|
|
137
|
+
renderer: DialogLitRenderer,
|
|
138
|
+
dependencies?: unknown,
|
|
139
|
+
): DirectiveResult<typeof DialogFooterRendererDirective>;
|
|
@@ -0,0 +1,147 @@
|
|
|
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
|
+
/* eslint-disable max-classes-per-file */
|
|
7
|
+
import { directive } from 'lit/directive.js';
|
|
8
|
+
import { microTask } from '@vaadin/component-base/src/async.js';
|
|
9
|
+
import { Debouncer } from '@vaadin/component-base/src/debounce.js';
|
|
10
|
+
import { LitRendererDirective } from '@vaadin/lit-renderer';
|
|
11
|
+
|
|
12
|
+
const CONTENT_UPDATE_DEBOUNCER = Symbol('contentUpdateDebouncer');
|
|
13
|
+
|
|
14
|
+
class AbstractDialogRendererDirective extends LitRendererDirective {
|
|
15
|
+
/**
|
|
16
|
+
* A property to that the renderer callback will be assigned.
|
|
17
|
+
*
|
|
18
|
+
* @abstract
|
|
19
|
+
*/
|
|
20
|
+
rendererProperty;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Adds the renderer callback to the dialog.
|
|
24
|
+
*/
|
|
25
|
+
addRenderer() {
|
|
26
|
+
this.element[this.rendererProperty] = (root, dialog) => {
|
|
27
|
+
this.renderRenderer(root, dialog);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Runs the renderer callback on the dialog.
|
|
33
|
+
*/
|
|
34
|
+
runRenderer() {
|
|
35
|
+
this.element[CONTENT_UPDATE_DEBOUNCER] = Debouncer.debounce(
|
|
36
|
+
this.element[CONTENT_UPDATE_DEBOUNCER],
|
|
37
|
+
microTask,
|
|
38
|
+
() => {
|
|
39
|
+
this.element.requestContentUpdate();
|
|
40
|
+
},
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Removes the renderer callback from the dialog.
|
|
46
|
+
*/
|
|
47
|
+
removeRenderer() {
|
|
48
|
+
this.element[this.rendererProperty] = null;
|
|
49
|
+
delete this.element[CONTENT_UPDATE_DEBOUNCER];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export class DialogRendererDirective extends AbstractDialogRendererDirective {
|
|
54
|
+
rendererProperty = 'renderer';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export class DialogHeaderRendererDirective extends AbstractDialogRendererDirective {
|
|
58
|
+
rendererProperty = 'headerRenderer';
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export class DialogFooterRendererDirective extends AbstractDialogRendererDirective {
|
|
62
|
+
rendererProperty = 'footerRenderer';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* A Lit directive for populating the content of the dialog.
|
|
67
|
+
*
|
|
68
|
+
* The directive accepts a renderer callback returning a Lit template and assigns it to the dialog
|
|
69
|
+
* via the `renderer` property. The renderer is called to populate the content once when assigned
|
|
70
|
+
* and whenever a single dependency or an array of dependencies changes.
|
|
71
|
+
* It is not guaranteed that the renderer will be called immediately (synchronously) in both cases.
|
|
72
|
+
*
|
|
73
|
+
* Dependencies can be a single value or an array of values.
|
|
74
|
+
* Values are checked against previous values with strict equality (`===`),
|
|
75
|
+
* so the check won't detect nested property changes inside objects or arrays.
|
|
76
|
+
* When dependencies are provided as an array, each item is checked against the previous value
|
|
77
|
+
* at the same index with strict equality. Nested arrays are also checked only by strict
|
|
78
|
+
* equality.
|
|
79
|
+
*
|
|
80
|
+
* Example of usage:
|
|
81
|
+
* ```js
|
|
82
|
+
* `<vaadin-dialog
|
|
83
|
+
* ${dialogRenderer((dialog) => html`...`)}
|
|
84
|
+
* ></vaadin-dialog>`
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* @param renderer the renderer callback that returns a Lit template.
|
|
88
|
+
* @param dependencies a single dependency or an array of dependencies
|
|
89
|
+
* which trigger a re-render when changed.
|
|
90
|
+
*/
|
|
91
|
+
export const dialogRenderer = directive(DialogRendererDirective);
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* A Lit directive for populating the content of the dialog header.
|
|
95
|
+
*
|
|
96
|
+
* The directive accepts a renderer callback returning a Lit template and assigns it to the dialog
|
|
97
|
+
* via the `headerRenderer` property. The renderer is called to populate the content once when assigned
|
|
98
|
+
* and whenever a single dependency or an array of dependencies changes.
|
|
99
|
+
* It is not guaranteed that the renderer will be called immediately (synchronously) in both cases.
|
|
100
|
+
*
|
|
101
|
+
* Dependencies can be a single value or an array of values.
|
|
102
|
+
* Values are checked against previous values with strict equality (`===`),
|
|
103
|
+
* so the check won't detect nested property changes inside objects or arrays.
|
|
104
|
+
* When dependencies are provided as an array, each item is checked against the previous value
|
|
105
|
+
* at the same index with strict equality. Nested arrays are also checked only by strict
|
|
106
|
+
* equality.
|
|
107
|
+
*
|
|
108
|
+
* Example of usage:
|
|
109
|
+
* ```js
|
|
110
|
+
* `<vaadin-dialog
|
|
111
|
+
* ${dialogHeaderRenderer((dialog) => html`...`)}
|
|
112
|
+
* ></vaadin-dialog>`
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* @param renderer the renderer callback.
|
|
116
|
+
* @param dependencies a single dependency or an array of dependencies
|
|
117
|
+
* which trigger a re-render when changed.
|
|
118
|
+
*/
|
|
119
|
+
export const dialogHeaderRenderer = directive(DialogHeaderRendererDirective);
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* A Lit directive for populating the content of the dialog footer.
|
|
123
|
+
*
|
|
124
|
+
* The directive accepts a renderer callback returning a Lit template and assigns it to the dialog
|
|
125
|
+
* via the `footerRenderer` property. The renderer is called to populate the content once when assigned
|
|
126
|
+
* and whenever a single dependency or an array of dependencies changes.
|
|
127
|
+
* It is not guaranteed that the renderer will be called immediately (synchronously) in both cases.
|
|
128
|
+
*
|
|
129
|
+
* Dependencies can be a single value or an array of values.
|
|
130
|
+
* Values are checked against previous values with strict equality (`===`),
|
|
131
|
+
* so the check won't detect nested property changes inside objects or arrays.
|
|
132
|
+
* When dependencies are provided as an array, each item is checked against the previous value
|
|
133
|
+
* at the same index with strict equality. Nested arrays are also checked only by strict
|
|
134
|
+
* equality.
|
|
135
|
+
*
|
|
136
|
+
* Example of usage:
|
|
137
|
+
* ```js
|
|
138
|
+
* `<vaadin-dialog
|
|
139
|
+
* ${dialogFooterRenderer((dialog) => html`...`)}
|
|
140
|
+
* ></vaadin-dialog>`
|
|
141
|
+
* ```
|
|
142
|
+
*
|
|
143
|
+
* @param renderer the renderer callback.
|
|
144
|
+
* @param dependencies a single dependency or an array of dependencies
|
|
145
|
+
* which trigger a re-render when changed.
|
|
146
|
+
*/
|
|
147
|
+
export const dialogFooterRenderer = directive(DialogFooterRendererDirective);
|
package/src/vaadin-dialog.js
CHANGED
|
@@ -99,7 +99,7 @@ export class DialogOverlay extends OverlayElement {
|
|
|
99
99
|
memoizedTemplate = super.template.cloneNode(true);
|
|
100
100
|
const contentPart = memoizedTemplate.content.querySelector('[part="content"]');
|
|
101
101
|
const overlayPart = memoizedTemplate.content.querySelector('[part="overlay"]');
|
|
102
|
-
const resizerContainer = document.createElement('
|
|
102
|
+
const resizerContainer = document.createElement('section');
|
|
103
103
|
resizerContainer.id = 'resizerContainer';
|
|
104
104
|
resizerContainer.classList.add('resizer-container');
|
|
105
105
|
resizerContainer.appendChild(contentPart);
|
|
@@ -161,9 +161,6 @@ export class DialogOverlay extends OverlayElement {
|
|
|
161
161
|
ready() {
|
|
162
162
|
super.ready();
|
|
163
163
|
|
|
164
|
-
const uniqueId = (DialogOverlay._uniqueId = 1 + DialogOverlay._uniqueId || 0);
|
|
165
|
-
this._titleId = `${this.constructor.is}-title-${uniqueId}`;
|
|
166
|
-
|
|
167
164
|
// Update overflow attribute on resize
|
|
168
165
|
this.__resizeObserver = new ResizeObserver(() => {
|
|
169
166
|
this.__updateOverflow();
|
|
@@ -264,18 +261,14 @@ export class DialogOverlay extends OverlayElement {
|
|
|
264
261
|
if (this.headerTitle) {
|
|
265
262
|
if (!this.headerTitleElement) {
|
|
266
263
|
this.headerTitleElement = document.createElement('span');
|
|
267
|
-
this.headerTitleElement.id = this._titleId;
|
|
268
264
|
this.headerTitleElement.setAttribute('slot', 'title');
|
|
269
265
|
this.headerTitleElement.classList.add('draggable');
|
|
270
|
-
|
|
271
|
-
this.setAttribute('aria-labelledby', this._titleId);
|
|
272
266
|
}
|
|
273
267
|
this.appendChild(this.headerTitleElement);
|
|
274
268
|
this.headerTitleElement.textContent = this.headerTitle;
|
|
275
269
|
} else if (this.headerTitleElement) {
|
|
276
270
|
this.headerTitleElement.remove();
|
|
277
271
|
this.headerTitleElement = null;
|
|
278
|
-
this.removeAttribute('aria-labelledby');
|
|
279
272
|
}
|
|
280
273
|
}
|
|
281
274
|
|
|
@@ -594,7 +587,7 @@ class Dialog extends ThemePropertyMixin(ElementMixin(DialogDraggableMixin(Dialog
|
|
|
594
587
|
static get observers() {
|
|
595
588
|
return [
|
|
596
589
|
'_openedChanged(opened)',
|
|
597
|
-
'_ariaLabelChanged(ariaLabel)',
|
|
590
|
+
'_ariaLabelChanged(ariaLabel, headerTitle)',
|
|
598
591
|
'_rendererChanged(renderer, headerRenderer, footerRenderer)',
|
|
599
592
|
];
|
|
600
593
|
}
|
|
@@ -648,9 +641,9 @@ class Dialog extends ThemePropertyMixin(ElementMixin(DialogDraggableMixin(Dialog
|
|
|
648
641
|
}
|
|
649
642
|
|
|
650
643
|
/** @private */
|
|
651
|
-
_ariaLabelChanged(ariaLabel) {
|
|
652
|
-
if (ariaLabel) {
|
|
653
|
-
this.$.overlay.setAttribute('aria-label', ariaLabel);
|
|
644
|
+
_ariaLabelChanged(ariaLabel, headerTitle) {
|
|
645
|
+
if (ariaLabel || headerTitle) {
|
|
646
|
+
this.$.overlay.setAttribute('aria-label', ariaLabel || headerTitle);
|
|
654
647
|
} else {
|
|
655
648
|
this.$.overlay.removeAttribute('aria-label');
|
|
656
649
|
}
|