@vaadin/overlay 23.3.0-alpha5 → 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/overlay",
3
- "version": "23.3.0-alpha5",
3
+ "version": "24.0.0-alpha2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -9,7 +9,7 @@
9
9
  "repository": {
10
10
  "type": "git",
11
11
  "url": "https://github.com/vaadin/web-components.git",
12
- "directory": "packages/overlay"
12
+ "directory": "packages/vaadin-overlay"
13
13
  },
14
14
  "author": "Vaadin Ltd",
15
15
  "homepage": "https://vaadin.com/components",
@@ -35,20 +35,20 @@
35
35
  ],
36
36
  "dependencies": {
37
37
  "@polymer/polymer": "^3.0.0",
38
- "@vaadin/component-base": "23.3.0-alpha5",
39
- "@vaadin/vaadin-lumo-styles": "23.3.0-alpha5",
40
- "@vaadin/vaadin-material-styles": "23.3.0-alpha5",
41
- "@vaadin/vaadin-themable-mixin": "23.3.0-alpha5"
38
+ "@vaadin/component-base": "24.0.0-alpha2",
39
+ "@vaadin/vaadin-lumo-styles": "24.0.0-alpha2",
40
+ "@vaadin/vaadin-material-styles": "24.0.0-alpha2",
41
+ "@vaadin/vaadin-themable-mixin": "24.0.0-alpha2"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@esm-bundle/chai": "^4.3.4",
45
- "@polymer/iron-overlay-behavior": "^3.0.0",
46
- "@vaadin/button": "23.3.0-alpha5",
47
- "@vaadin/radio-group": "23.3.0-alpha5",
45
+ "@vaadin/button": "24.0.0-alpha2",
46
+ "@vaadin/polymer-legacy-adapter": "24.0.0-alpha2",
47
+ "@vaadin/radio-group": "24.0.0-alpha2",
48
48
  "@vaadin/testing-helpers": "^0.3.2",
49
- "@vaadin/text-field": "23.3.0-alpha5",
49
+ "@vaadin/text-field": "24.0.0-alpha2",
50
50
  "lit": "^2.0.0",
51
51
  "sinon": "^13.0.2"
52
52
  },
53
- "gitHead": "0b6fdcf444683e97e3efb433d603e1274d5bcd66"
53
+ "gitHead": "0c16c01a6807e629a84f5a982793afecc1a7ced0"
54
54
  }
@@ -55,13 +55,10 @@ export type OverlayEventMap = HTMLElementEventMap & OverlayCustomEventMap;
55
55
 
56
56
  /**
57
57
  * `<vaadin-overlay>` is a Web Component for creating overlays. The content of the overlay
58
- * can be populated in two ways: imperatively by using renderer callback function and
59
- * declaratively by using Polymer's Templates.
58
+ * can be populated imperatively by using `renderer` callback function.
60
59
  *
61
60
  * ### Rendering
62
61
  *
63
- * By default, the overlay uses the content provided by using the renderer callback function.
64
- *
65
62
  * The renderer function provides `root`, `owner`, `model` arguments when applicable.
66
63
  * Generate DOM content by using `model` object properties if needed, append it to the `root`
67
64
  * element and control the state of the host element by accessing `owner`. Before generating new
@@ -82,39 +79,9 @@ export type OverlayEventMap = HTMLElementEventMap & OverlayCustomEventMap;
82
79
  * in the next renderer call and will be provided with the `root` argument.
83
80
  * On first call it will be empty.
84
81
  *
85
- * **NOTE:** when the renderer property is defined, the `<template>` content is not used.
86
- *
87
- * ### Templating
88
- *
89
- * Alternatively, the content can be provided with Polymer Template.
90
- * Overlay finds the first child template and uses that in case renderer callback function
91
- * is not provided. You can also set a custom template using the `template` property.
92
- *
93
- * After the content from the template is stamped, the `content` property
94
- * points to the content container.
95
- *
96
- * The overlay provides `forwardHostProp` when calling
97
- * `Polymer.Templatize.templatize` for the template, so that the bindings
98
- * from the parent scope propagate to the content.
99
- *
100
- * ```html
101
- * <vaadin-overlay>
102
- * <template>Overlay content</template>
103
- * </vaadin-overlay>
104
- * ```
105
- *
106
82
  * ### Styling
107
83
  *
108
- * To style the overlay content, use styles in the parent scope:
109
- *
110
- * - If the overlay is used in a component, then the component styles
111
- * apply the overlay content.
112
- * - If the overlay is used in the global DOM scope, then global styles
113
- * apply to the overlay content.
114
- *
115
- * See examples for styling the overlay content in the live demos.
116
- *
117
- * The following Shadow DOM parts are available for styling the overlay component itself:
84
+ * The following Shadow DOM parts are available for styling:
118
85
  *
119
86
  * Part name | Description
120
87
  * -----------|---------------------------------------------------------|
@@ -165,16 +132,6 @@ declare class Overlay extends ThemableMixin(DirMixin(ControllerMixin(HTMLElement
165
132
  */
166
133
  renderer: OverlayRenderer | null | undefined;
167
134
 
168
- /**
169
- * The template of the overlay content.
170
- */
171
- template: HTMLTemplateElement | null | undefined;
172
-
173
- /**
174
- * References the content container after the template is stamped.
175
- */
176
- content: HTMLElement | undefined;
177
-
178
135
  /**
179
136
  * When true the overlay has backdrop on top of content when opened.
180
137
  */
@@ -3,26 +3,21 @@
3
3
  * Copyright (c) 2017 - 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 { FlattenedNodesObserver } from '@polymer/polymer/lib/utils/flattened-nodes-observer.js';
7
6
  import { afterNextRender } from '@polymer/polymer/lib/utils/render-status.js';
8
- import { templatize } from '@polymer/polymer/lib/utils/templatize.js';
9
7
  import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
10
8
  import { isIOS } from '@vaadin/component-base/src/browser-utils.js';
11
9
  import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
12
10
  import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
13
11
  import { FocusTrapController } from '@vaadin/component-base/src/focus-trap-controller.js';
12
+ import { processTemplates } from '@vaadin/component-base/src/templates.js';
14
13
  import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
15
14
 
16
15
  /**
17
- *
18
16
  * `<vaadin-overlay>` is a Web Component for creating overlays. The content of the overlay
19
- * can be populated in two ways: imperatively by using renderer callback function and
20
- * declaratively by using Polymer's Templates.
17
+ * can be populated imperatively by using `renderer` callback function.
21
18
  *
22
19
  * ### Rendering
23
20
  *
24
- * By default, the overlay uses the content provided by using the renderer callback function.
25
- *
26
21
  * The renderer function provides `root`, `owner`, `model` arguments when applicable.
27
22
  * Generate DOM content by using `model` object properties if needed, append it to the `root`
28
23
  * element and control the state of the host element by accessing `owner`. Before generating new
@@ -43,33 +38,9 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
43
38
  * in the next renderer call and will be provided with the `root` argument.
44
39
  * On first call it will be empty.
45
40
  *
46
- * **NOTE:** when the renderer property is defined, the `<template>` content is not used.
47
- *
48
- * ### Templating
49
- *
50
- * Alternatively, the content can be provided with Polymer Template.
51
- * Overlay finds the first child template and uses that in case renderer callback function
52
- * is not provided. You can also set a custom template using the `template` property.
53
- *
54
- * After the content from the template is stamped, the `content` property
55
- * points to the content container.
56
- *
57
- * The overlay provides `forwardHostProp` when calling
58
- * `Polymer.Templatize.templatize` for the template, so that the bindings
59
- * from the parent scope propagate to the content.
60
- *
61
41
  * ### Styling
62
42
  *
63
- * To style the overlay content, use styles in the parent scope:
64
- *
65
- * - If the overlay is used in a component, then the component styles
66
- * apply the overlay content.
67
- * - If the overlay is used in the global DOM scope, then global styles
68
- * apply to the overlay content.
69
- *
70
- * See examples for styling the overlay content in the live demos.
71
- *
72
- * The following Shadow DOM parts are available for styling the overlay component itself:
43
+ * The following Shadow DOM parts are available for styling:
73
44
  *
74
45
  * Part name | Description
75
46
  * -----------|---------------------------------------------------------|
@@ -214,24 +185,6 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
214
185
  */
215
186
  renderer: Function,
216
187
 
217
- /**
218
- * The template of the overlay content.
219
- * @type {HTMLTemplateElement | null | undefined}
220
- */
221
- template: {
222
- type: Object,
223
- notify: true,
224
- },
225
-
226
- /**
227
- * References the content container after the template is stamped.
228
- * @type {!HTMLElement | undefined}
229
- */
230
- content: {
231
- type: Object,
232
- notify: true,
233
- },
234
-
235
188
  /**
236
189
  * When true the overlay has backdrop on top of content when opened.
237
190
  * @type {boolean}
@@ -308,26 +261,12 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
308
261
  type: Boolean,
309
262
  },
310
263
 
311
- /** @private */
312
- _instance: {
313
- type: Object,
314
- },
315
-
316
- /** @private */
317
- _originalContentPart: Object,
318
-
319
- /** @private */
320
- _contentNodes: Array,
321
-
322
264
  /** @private */
323
265
  _oldOwner: Element,
324
266
 
325
267
  /** @private */
326
268
  _oldModel: Object,
327
269
 
328
- /** @private */
329
- _oldTemplate: Object,
330
-
331
270
  /** @private */
332
271
  _oldRenderer: Object,
333
272
 
@@ -337,7 +276,7 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
337
276
  }
338
277
 
339
278
  static get observers() {
340
- return ['_templateOrRendererChanged(template, renderer, owner, model, opened)'];
279
+ return ['_rendererOrDataChanged(renderer, owner, model, opened)'];
341
280
  }
342
281
 
343
282
  constructor() {
@@ -347,13 +286,6 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
347
286
  this._boundOutsideClickListener = this._outsideClickListener.bind(this);
348
287
  this._boundKeydownListener = this._keydownListener.bind(this);
349
288
 
350
- this._observer = new FlattenedNodesObserver(this, (info) => {
351
- this._setTemplateFromNodes(info.addedNodes);
352
- });
353
-
354
- // Listener for preventing closing of the paper-dialog and all components extending `iron-overlay-behavior`.
355
- this._boundIronOverlayCanceledListener = this._ironOverlayCanceled.bind(this);
356
-
357
289
  /* c8 ignore next 3 */
358
290
  if (isIOS) {
359
291
  this._boundIosResizeListener = () => this._detectIosNavbar();
@@ -366,8 +298,6 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
366
298
  ready() {
367
299
  super.ready();
368
300
 
369
- this._observer.flush();
370
-
371
301
  // Need to add dummy click listeners to this and the backdrop or else
372
302
  // the document click event listener (_outsideClickListener) may never
373
303
  // get invoked on iOS Safari (reproducible in <vaadin-dialog>
@@ -376,6 +306,8 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
376
306
  this.$.backdrop.addEventListener('click', () => {});
377
307
 
378
308
  this.addController(this.__focusTrapController);
309
+
310
+ processTemplates(this);
379
311
  }
380
312
 
381
313
  /** @private */
@@ -399,14 +331,6 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
399
331
  }
400
332
  }
401
333
 
402
- /**
403
- * @param {!Array<!Element>} nodes
404
- * @protected
405
- */
406
- _setTemplateFromNodes(nodes) {
407
- this.template = nodes.find((node) => node.localName && node.localName === 'template') || this.template;
408
- }
409
-
410
334
  /**
411
335
  * @param {Event=} sourceEvent
412
336
  * @event vaadin-overlay-close
@@ -453,15 +377,10 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
453
377
  */
454
378
  requestContentUpdate() {
455
379
  if (this.renderer) {
456
- this.renderer.call(this.owner, this.content, this.owner, this.model);
380
+ this.renderer.call(this.owner, this, this.owner, this.model);
457
381
  }
458
382
  }
459
383
 
460
- /** @private */
461
- _ironOverlayCanceled(event) {
462
- event.preventDefault();
463
- }
464
-
465
384
  /** @private */
466
385
  _mouseDownListener(event) {
467
386
  this._mouseDownInside = event.composedPath().indexOf(this.$.overlay) >= 0;
@@ -534,11 +453,6 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
534
453
  }
535
454
  }
536
455
 
537
- /** @protected */
538
- _ensureTemplatized() {
539
- this._setTemplateFromNodes(Array.from(this.children));
540
- }
541
-
542
456
  /**
543
457
  * @event vaadin-overlay-open
544
458
  * fired after the `vaadin-overlay` is opened.
@@ -546,10 +460,6 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
546
460
  * @private
547
461
  */
548
462
  _openedChanged(opened, wasOpened) {
549
- if (!this._instance) {
550
- this._ensureTemplatized();
551
- }
552
-
553
463
  if (opened) {
554
464
  // Store focused node.
555
465
  this.__restoreFocusNode = this._getActiveElement();
@@ -661,13 +571,11 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
661
571
 
662
572
  /** @protected */
663
573
  _finishOpening() {
664
- document.addEventListener('iron-overlay-canceled', this._boundIronOverlayCanceledListener);
665
574
  this.removeAttribute('opening');
666
575
  }
667
576
 
668
577
  /** @protected */
669
578
  _finishClosing() {
670
- document.removeEventListener('iron-overlay-canceled', this._boundIronOverlayCanceledListener);
671
579
  this._detachOverlay();
672
580
  this.$.overlay.style.removeProperty('pointer-events');
673
581
  this.removeAttribute('closing');
@@ -815,108 +723,12 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
815
723
  }
816
724
  }
817
725
 
818
- /** @protected */
819
- _removeOldContent() {
820
- if (!this.content || !this._contentNodes) {
821
- return;
822
- }
823
-
824
- this._observer.disconnect();
825
-
826
- this._contentNodes.forEach((node) => {
827
- if (node.parentNode === this.content) {
828
- this.content.removeChild(node);
829
- }
830
- });
831
-
832
- if (this._originalContentPart) {
833
- // Restore the original <div part="content">
834
- this.$.content.parentNode.replaceChild(this._originalContentPart, this.$.content);
835
- this.$.content = this._originalContentPart;
836
- this._originalContentPart = undefined;
837
- }
838
-
839
- this._observer.connect();
840
-
841
- this._contentNodes = undefined;
842
- this.content = undefined;
843
- }
844
-
845
- /**
846
- * @param {!HTMLTemplateElement} template
847
- * @protected
848
- */
849
- _stampOverlayTemplate(template) {
850
- this._removeOldContent();
851
-
852
- if (!template._Templatizer) {
853
- template._Templatizer = templatize(template, this, {
854
- forwardHostProp(prop, value) {
855
- if (this._instance) {
856
- this._instance.forwardHostProp(prop, value);
857
- }
858
- },
859
- });
860
- }
861
-
862
- this._instance = new template._Templatizer({});
863
- this._contentNodes = Array.from(this._instance.root.childNodes);
864
-
865
- const templateRoot = template._templateRoot || (template._templateRoot = template.getRootNode());
866
-
867
- if (templateRoot !== document) {
868
- if (!this.$.content.shadowRoot) {
869
- this.$.content.attachShadow({ mode: 'open' });
870
- }
871
-
872
- let scopeCssText = Array.from(templateRoot.querySelectorAll('style')).reduce(
873
- (result, style) => result + style.textContent,
874
- '',
875
- );
876
-
877
- // The overlay root’s :host styles should not apply inside the overlay
878
- scopeCssText = scopeCssText.replace(/:host/g, ':host-nomatch');
879
-
880
- if (scopeCssText) {
881
- // Append a style to the content shadowRoot
882
- const style = document.createElement('style');
883
- style.textContent = scopeCssText;
884
- this.$.content.shadowRoot.appendChild(style);
885
- this._contentNodes.unshift(style);
886
- }
887
-
888
- this.$.content.shadowRoot.appendChild(this._instance.root);
889
- this.content = this.$.content.shadowRoot;
890
- } else {
891
- this.appendChild(this._instance.root);
892
- this.content = this;
893
- }
894
- }
895
-
896
- /** @private */
897
- _removeNewRendererOrTemplate(template, oldTemplate, renderer, oldRenderer) {
898
- if (template !== oldTemplate) {
899
- this.template = undefined;
900
- } else if (renderer !== oldRenderer) {
901
- this.renderer = undefined;
902
- }
903
- }
904
-
905
726
  /** @private */
906
- // eslint-disable-next-line max-params
907
- _templateOrRendererChanged(template, renderer, owner, model, opened) {
908
- if (template && renderer) {
909
- this._removeNewRendererOrTemplate(template, this._oldTemplate, renderer, this._oldRenderer);
910
- throw new Error('You should only use either a renderer or a template for overlay content');
911
- }
912
-
727
+ _rendererOrDataChanged(renderer, owner, model, opened) {
913
728
  const ownerOrModelChanged = this._oldOwner !== owner || this._oldModel !== model;
914
729
  this._oldModel = model;
915
730
  this._oldOwner = owner;
916
731
 
917
- const templateChanged = this._oldTemplate !== template;
918
- this._oldTemplate = template;
919
-
920
732
  const rendererChanged = this._oldRenderer !== renderer;
921
733
  this._oldRenderer = renderer;
922
734
 
@@ -924,20 +736,15 @@ class Overlay extends ThemableMixin(DirMixin(ControllerMixin(PolymerElement))) {
924
736
  this._oldOpened = opened;
925
737
 
926
738
  if (rendererChanged) {
927
- this.content = this;
928
- this.content.innerHTML = '';
739
+ this.innerHTML = '';
929
740
  // Whenever a Lit-based renderer is used, it assigns a Lit part to the node it was rendered into.
930
741
  // When clearing the rendered content, this part needs to be manually disposed of.
931
742
  // Otherwise, using a Lit-based renderer on the same node will throw an exception or render nothing afterward.
932
- delete this.content._$litPart$;
743
+ delete this._$litPart$;
933
744
  }
934
745
 
935
- if (template && templateChanged) {
936
- this._stampOverlayTemplate(template);
937
- } else if (renderer && (rendererChanged || openedChanged || ownerOrModelChanged)) {
938
- if (opened) {
939
- this.requestContentUpdate();
940
- }
746
+ if (opened && renderer && (rendererChanged || openedChanged || ownerOrModelChanged)) {
747
+ this.requestContentUpdate();
941
748
  }
942
749
  }
943
750