@vaadin/app-layout 25.2.0-alpha7 → 25.2.0-alpha8

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/app-layout",
3
- "version": "25.2.0-alpha7",
3
+ "version": "25.2.0-alpha8",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -35,18 +35,18 @@
35
35
  ],
36
36
  "dependencies": {
37
37
  "@open-wc/dedupe-mixin": "^1.3.0",
38
- "@vaadin/a11y-base": "25.2.0-alpha7",
39
- "@vaadin/button": "25.2.0-alpha7",
40
- "@vaadin/component-base": "25.2.0-alpha7",
41
- "@vaadin/vaadin-themable-mixin": "25.2.0-alpha7",
38
+ "@vaadin/a11y-base": "25.2.0-alpha8",
39
+ "@vaadin/button": "25.2.0-alpha8",
40
+ "@vaadin/component-base": "25.2.0-alpha8",
41
+ "@vaadin/vaadin-themable-mixin": "25.2.0-alpha8",
42
42
  "lit": "^3.0.0"
43
43
  },
44
44
  "devDependencies": {
45
- "@vaadin/aura": "25.2.0-alpha7",
46
- "@vaadin/chai-plugins": "25.2.0-alpha7",
47
- "@vaadin/test-runner-commands": "25.2.0-alpha7",
45
+ "@vaadin/aura": "25.2.0-alpha8",
46
+ "@vaadin/chai-plugins": "25.2.0-alpha8",
47
+ "@vaadin/test-runner-commands": "25.2.0-alpha8",
48
48
  "@vaadin/testing-helpers": "^2.0.0",
49
- "@vaadin/vaadin-lumo-styles": "25.2.0-alpha7",
49
+ "@vaadin/vaadin-lumo-styles": "25.2.0-alpha8",
50
50
  "sinon": "^21.0.2"
51
51
  },
52
52
  "customElements": "custom-elements.json",
@@ -54,5 +54,5 @@
54
54
  "web-types.json",
55
55
  "web-types.lit.json"
56
56
  ],
57
- "gitHead": "3f0862906d60205d107836d8eca84c6fde4a9129"
57
+ "gitHead": "2b82e20cdfc605b1187e9a24ae42869e1500ab68"
58
58
  }
@@ -18,18 +18,9 @@ export const appLayoutStyles = css`
18
18
  --vaadin-app-layout-navbar-offset-top: var(--_vaadin-app-layout-navbar-offset-size);
19
19
  --vaadin-app-layout-navbar-offset-bottom: var(--_vaadin-app-layout-navbar-offset-size-bottom);
20
20
  --vaadin-app-layout-drawer-offset-left: 0px;
21
- padding-top: max(var(--vaadin-app-layout-navbar-offset-top), var(--safe-area-inset-top));
22
- padding-bottom: max(var(--vaadin-app-layout-navbar-offset-bottom), var(--safe-area-inset-bottom));
23
- }
24
-
25
- :host(:dir(ltr)) {
26
- padding-left: max(var(--vaadin-app-layout-drawer-offset-left), var(--safe-area-inset-left));
27
- padding-right: var(--safe-area-inset-right);
28
- }
29
-
30
- :host(:dir(rtl)) {
31
- padding-left: var(--safe-area-inset-left);
32
- padding-right: max(var(--vaadin-app-layout-drawer-offset-left), var(--safe-area-inset-right));
21
+ padding-top: var(--vaadin-app-layout-navbar-offset-top);
22
+ padding-bottom: var(--vaadin-app-layout-navbar-offset-bottom);
23
+ padding-inline-start: var(--vaadin-app-layout-drawer-offset-left);
33
24
  }
34
25
 
35
26
  :host([hidden]),
@@ -58,6 +49,14 @@ export const appLayoutStyles = css`
58
49
  [part~='content'] {
59
50
  height: 100%;
60
51
  transition: inherit;
52
+ box-sizing: border-box;
53
+ padding-top: max(0px, var(--safe-area-inset-top) - var(--vaadin-app-layout-navbar-offset-top));
54
+ padding-bottom: max(0px, var(--safe-area-inset-bottom) - var(--vaadin-app-layout-navbar-offset-bottom));
55
+ padding-inline: var(--safe-area-inset-inline-start) var(--safe-area-inset-inline-end);
56
+ }
57
+
58
+ :host([drawer-opened]:not([overlay])) [part~='content'] {
59
+ padding-inline-start: 0;
61
60
  }
62
61
 
63
62
  @media (pointer: coarse) and (max-width: 800px) and (min-height: 500px) {
@@ -122,6 +121,7 @@ export const appLayoutStyles = css`
122
121
  width: var(--_vaadin-app-layout-drawer-width);
123
122
  box-sizing: border-box;
124
123
  padding-block: var(--safe-area-inset-top) var(--safe-area-inset-bottom);
124
+ padding-inline-start: var(--safe-area-inset-inline-start);
125
125
  outline: none;
126
126
  /* The drawer should be inaccessible by the tabbing navigation when it is closed. */
127
127
  visibility: hidden;
@@ -130,15 +130,8 @@ export const appLayoutStyles = css`
130
130
  background: var(--vaadin-app-layout-drawer-background, transparent);
131
131
  }
132
132
 
133
- [part='drawer']:dir(ltr) {
134
- padding-left: var(--safe-area-inset-left);
135
- }
136
-
137
- [part='drawer']:dir(rtl) {
138
- padding-right: var(--safe-area-inset-right);
139
- }
140
-
141
- :host([has-navbar]:not([overlay])) [part='drawer'] {
133
+ :host([has-navbar]:not([overlay])) [part='drawer'],
134
+ :host([has-navbar]) [part='content'] {
142
135
  --safe-area-inset-top: 0px;
143
136
  }
144
137
 
@@ -120,7 +120,6 @@ export const AppLayoutMixin = (superclass) =>
120
120
  constructor() {
121
121
  super();
122
122
  // TODO(jouni): might want to debounce
123
- this.__boundResizeListener = this._resize.bind(this);
124
123
  this.__drawerToggleClickListener = this._drawerToggleClick.bind(this);
125
124
  this.__onDrawerKeyDown = this.__onDrawerKeyDown.bind(this);
126
125
  this.__closeOverlayDrawerListener = this.__closeOverlayDrawer.bind(this);
@@ -138,34 +137,13 @@ export const AppLayoutMixin = (superclass) =>
138
137
  connectedCallback() {
139
138
  super.connectedCallback();
140
139
 
141
- this._blockAnimationUntilAfterNextRender();
140
+ this.__resizeObserver = new ResizeObserver((entries) => this.__onResize(entries));
141
+ this.__resizeObserver.observe(this);
142
+ this.__resizeObserver.observe(this.$.drawer);
143
+ this.__resizeObserver.observe(this.$.navbarTop);
144
+ this.__resizeObserver.observe(this.$.navbarBottom);
142
145
 
143
- window.addEventListener('resize', this.__boundResizeListener);
144
146
  this.addEventListener('drawer-toggle-click', this.__drawerToggleClickListener);
145
-
146
- requestAnimationFrame(() => {
147
- this._updateOffsetSize();
148
- });
149
-
150
- this._updateTouchOptimizedMode();
151
- this._updateDrawerSize();
152
- this._updateOverlayMode();
153
-
154
- this._navbarSizeObserver = new ResizeObserver(() => {
155
- requestAnimationFrame(() => {
156
- // Prevent updating offset size multiple times
157
- // during the drawer open / close transition.
158
- if (this.__isDrawerAnimating) {
159
- this.__updateOffsetSizePending = true;
160
- } else {
161
- this._updateOffsetSize();
162
- }
163
- });
164
- });
165
- this._navbarSizeObserver.observe(this.$.navbarTop);
166
- this._navbarSizeObserver.observe(this.$.navbarBottom);
167
- this._navbarSizeObserver.observe(this.$.drawer);
168
-
169
147
  window.addEventListener('close-overlay-drawer', this.__closeOverlayDrawerListener);
170
148
  window.addEventListener('keydown', this.__onDrawerKeyDown);
171
149
  }
@@ -181,25 +159,15 @@ export const AppLayoutMixin = (superclass) =>
181
159
  });
182
160
 
183
161
  this.$.drawer.addEventListener('transitionend', () => {
184
- // Update offset size after drawer animation.
185
- if (this.__updateOffsetSizePending) {
186
- this.__updateOffsetSizePending = false;
187
- this._updateOffsetSize();
188
- }
189
-
190
- // Delay resetting the flag until animation frame
191
- // to avoid updating offset size again on resize.
192
- requestAnimationFrame(() => {
193
- this.__isDrawerAnimating = false;
194
- });
162
+ this.__isDrawerAnimating = false;
163
+ this.__scheduleResize(this.$.drawer);
195
164
  });
196
165
  }
197
166
 
198
167
  /** @protected */
199
168
  disconnectedCallback() {
200
169
  super.disconnectedCallback();
201
-
202
- window.removeEventListener('resize', this.__boundResizeListener);
170
+ this.__resizeObserver.disconnect();
203
171
  this.removeEventListener('drawer-toggle-click', this.__drawerToggleClickListener);
204
172
  window.removeEventListener('close-overlay-drawer', this.__drawerToggleClickListener);
205
173
  window.removeEventListener('keydown', this.__onDrawerKeyDown);
@@ -207,16 +175,54 @@ export const AppLayoutMixin = (superclass) =>
207
175
 
208
176
  /** @private */
209
177
  __onNavbarSlotChange() {
210
- this._updateTouchOptimizedMode();
178
+ this.__scheduleResize(this.$.navbarTop);
179
+ this.__scheduleResize(this.$.navbarBottom);
211
180
  this.toggleAttribute('has-navbar', !!this.querySelector('[slot="navbar"]'));
212
181
  }
213
182
 
214
183
  /** @private */
215
184
  __onDrawerSlotChange() {
216
- this._updateDrawerSize();
185
+ this.__scheduleResize(this.$.drawer);
186
+ this.__updateDrawerSize();
217
187
  this.toggleAttribute('has-drawer', !!this.querySelector('[slot="drawer"]'));
218
188
  }
219
189
 
190
+ /** @private */
191
+ __onResize(entries) {
192
+ cancelAnimationFrame(this.__resizeRaf);
193
+
194
+ const isHostResized = entries.some(({ target }) => target === this);
195
+ const isNavbarResized = entries.some(({ target }) => [this.$.navbarTop, this.$.navbarBottom].includes(target));
196
+
197
+ const overlayMode = this._getCustomPropertyValue('--vaadin-app-layout-drawer-overlay') === 'true';
198
+ const touchOptimized = this._getCustomPropertyValue('--vaadin-app-layout-touch-optimized') === 'true';
199
+
200
+ const drawerRect = this.$.drawer.getBoundingClientRect();
201
+ const navbarTopRect = this.$.navbarTop.getBoundingClientRect();
202
+ const navbarBottomRect = this.$.navbarBottom.getBoundingClientRect();
203
+
204
+ const isDrawerAnimating = this.__isDrawerAnimating;
205
+
206
+ this.__resizeRaf = requestAnimationFrame(() => {
207
+ if (isHostResized) {
208
+ this._blockAnimationUntilAfterNextRender();
209
+ this.__setOverlayMode(overlayMode);
210
+ }
211
+
212
+ if (isHostResized || isNavbarResized) {
213
+ this.__setTouchOptimized(touchOptimized);
214
+ }
215
+
216
+ if (!isDrawerAnimating) {
217
+ this.__setOffsetSize({
218
+ drawerRect,
219
+ navbarTopRect,
220
+ navbarBottomRect,
221
+ });
222
+ }
223
+ });
224
+ }
225
+
220
226
  /**
221
227
  * A callback for the `primarySection` property observer.
222
228
  *
@@ -306,48 +312,27 @@ export const AppLayoutMixin = (superclass) =>
306
312
  }
307
313
  }
308
314
 
309
- /** @protected */
310
- _updateDrawerSize() {
315
+ /** @private */
316
+ __updateDrawerSize() {
311
317
  const childCount = this.querySelectorAll('[slot=drawer]').length;
312
- const drawer = this.$.drawer;
313
-
314
318
  if (childCount === 0) {
315
- drawer.setAttribute('hidden', '');
319
+ this.$.drawer.setAttribute('hidden', '');
316
320
  this.style.setProperty('--_vaadin-app-layout-drawer-width', 0);
317
321
  } else {
318
- drawer.removeAttribute('hidden');
322
+ this.$.drawer.removeAttribute('hidden');
319
323
  this.style.removeProperty('--_vaadin-app-layout-drawer-width');
320
324
  }
321
- this._updateOffsetSize();
322
325
  }
323
326
 
324
327
  /** @private */
325
- _resize() {
326
- this._blockAnimationUntilAfterNextRender();
327
- this._updateTouchOptimizedMode();
328
- this._updateOverlayMode();
329
- }
330
-
331
- /** @protected */
332
- _updateOffsetSize() {
333
- const navbar = this.$.navbarTop;
334
- const navbarRect = navbar.getBoundingClientRect();
335
-
336
- const navbarBottom = this.$.navbarBottom;
337
- const navbarBottomRect = navbarBottom.getBoundingClientRect();
338
-
339
- const drawer = this.$.drawer;
340
- const drawerRect = drawer.getBoundingClientRect();
341
-
342
- this.style.setProperty('--_vaadin-app-layout-navbar-offset-size', `${navbarRect.height}px`);
343
- this.style.setProperty('--_vaadin-app-layout-navbar-offset-size-bottom', `${navbarBottomRect.height}px`);
328
+ __setOffsetSize({ drawerRect, navbarTopRect, navbarBottomRect }) {
344
329
  this.style.setProperty('--_vaadin-app-layout-drawer-offset-size', `${drawerRect.width}px`);
330
+ this.style.setProperty('--_vaadin-app-layout-navbar-offset-size', `${navbarTopRect.height}px`);
331
+ this.style.setProperty('--_vaadin-app-layout-navbar-offset-size-bottom', `${navbarBottomRect.height}px`);
345
332
  }
346
333
 
347
- /** @protected */
348
- _updateOverlayMode() {
349
- const overlay = this._getCustomPropertyValue('--vaadin-app-layout-drawer-overlay') === 'true';
350
-
334
+ /** @private */
335
+ __setOverlayMode(overlay) {
351
336
  if (!this.overlay && overlay) {
352
337
  // Changed from not overlay to overlay
353
338
  this._drawerStateSaved = this.drawerOpened;
@@ -487,12 +472,9 @@ export const AppLayoutMixin = (superclass) =>
487
472
  return (customPropertyValue || '').trim().toLowerCase();
488
473
  }
489
474
 
490
- /** @protected */
491
- _updateTouchOptimizedMode() {
492
- const touchOptimized = this._getCustomPropertyValue('--vaadin-app-layout-touch-optimized') === 'true';
493
-
475
+ /** @private */
476
+ __setTouchOptimized(touchOptimized) {
494
477
  const navbarItems = this.querySelectorAll('[slot*="navbar"]');
495
-
496
478
  if (navbarItems.length > 0) {
497
479
  Array.from(navbarItems).forEach((navbar) => {
498
480
  if (navbar.getAttribute('slot').indexOf('touch-optimized') > -1) {
@@ -518,8 +500,6 @@ export const AppLayoutMixin = (superclass) =>
518
500
  } else {
519
501
  this.$.navbarBottom.removeAttribute('hidden');
520
502
  }
521
-
522
- this._updateOffsetSize();
523
503
  }
524
504
 
525
505
  /** @protected */
@@ -533,6 +513,18 @@ export const AppLayoutMixin = (superclass) =>
533
513
  });
534
514
  }
535
515
 
516
+ /**
517
+ * Forces the ResizeObserver to re-report the size of the given element,
518
+ * scheduling a new {@link __onResize} callback even if the size hasn't changed.
519
+ *
520
+ * @param {Element} element
521
+ * @private
522
+ */
523
+ __scheduleResize(element) {
524
+ this.__resizeObserver.unobserve(element);
525
+ this.__resizeObserver.observe(element);
526
+ }
527
+
536
528
  /**
537
529
  * App Layout listens to `close-overlay-drawer` on the window level.
538
530
  * A custom event can be dispatched and the App Layout will close the drawer in overlay.
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/app-layout",
4
- "version": "25.2.0-alpha7",
4
+ "version": "25.2.0-alpha8",
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/app-layout",
4
- "version": "25.2.0-alpha7",
4
+ "version": "25.2.0-alpha8",
5
5
  "description-markup": "markdown",
6
6
  "framework": "lit",
7
7
  "framework-config": {