@vaadin/vaadin-dialog 22.0.0-alpha6 → 22.0.0-beta1

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,10 +1,29 @@
1
1
  {
2
2
  "name": "@vaadin/vaadin-dialog",
3
- "version": "22.0.0-alpha6",
3
+ "version": "22.0.0-beta1",
4
+ "publishConfig": {
5
+ "access": "public"
6
+ },
4
7
  "description": "vaadin-dialog",
8
+ "license": "Apache-2.0",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/vaadin/web-components.git",
12
+ "directory": "packages/vaadin-dialog"
13
+ },
14
+ "author": "Vaadin Ltd",
15
+ "homepage": "https://vaadin.com/components",
16
+ "bugs": {
17
+ "url": "https://github.com/vaadin/vaadin-dialog/issues"
18
+ },
5
19
  "main": "vaadin-dialog.js",
6
20
  "module": "vaadin-dialog.js",
7
- "repository": "vaadin/vaadin-dialog",
21
+ "files": [
22
+ "src",
23
+ "theme",
24
+ "vaadin-*.d.ts",
25
+ "vaadin-*.js"
26
+ ],
8
27
  "keywords": [
9
28
  "Vaadin",
10
29
  "vaadin-dialog",
@@ -12,36 +31,8 @@
12
31
  "web-component",
13
32
  "polymer"
14
33
  ],
15
- "author": "Vaadin Ltd",
16
- "license": "Apache-2.0",
17
- "bugs": {
18
- "url": "https://github.com/vaadin/vaadin-dialog/issues"
19
- },
20
- "homepage": "https://vaadin.com/components",
21
- "files": [
22
- "vaadin-*.d.ts",
23
- "vaadin-*.js",
24
- "src",
25
- "theme"
26
- ],
27
34
  "dependencies": {
28
- "@polymer/iron-resizable-behavior": "^3.0.0",
29
- "@polymer/polymer": "^3.0.0",
30
- "@vaadin/vaadin-element-mixin": "^22.0.0-alpha6",
31
- "@vaadin/vaadin-lumo-styles": "^22.0.0-alpha6",
32
- "@vaadin/vaadin-material-styles": "^22.0.0-alpha6",
33
- "@vaadin/vaadin-overlay": "^22.0.0-alpha6",
34
- "@vaadin/vaadin-themable-mixin": "^22.0.0-alpha6"
35
- },
36
- "devDependencies": {
37
- "@esm-bundle/chai": "^4.3.4",
38
- "@vaadin/testing-helpers": "^0.3.0",
39
- "@vaadin/text-area": "^22.0.0-alpha6",
40
- "@vaadin/vaadin-template-renderer": "^22.0.0-alpha6",
41
- "sinon": "^9.2.1"
42
- },
43
- "publishConfig": {
44
- "access": "public"
35
+ "@vaadin/dialog": "22.0.0-beta1"
45
36
  },
46
- "gitHead": "4b136b1c7da8942960e7255f40c27859125b3a45"
37
+ "gitHead": "4cf8a9d0504994200c610e44b3676114fef49c1e"
47
38
  }
@@ -1,130 +1,18 @@
1
- import { ElementMixin } from '@vaadin/vaadin-element-mixin/vaadin-element-mixin.js';
2
-
3
- import { ThemePropertyMixin } from '@vaadin/vaadin-themable-mixin/vaadin-theme-property-mixin.js';
4
-
5
- import { DialogDraggableMixin } from './vaadin-dialog-draggable-mixin.js';
6
-
7
- import { DialogResizableMixin } from './vaadin-dialog-resizable-mixin.js';
8
-
9
- import { DialogEventMap, DialogRenderer } from './interfaces';
10
-
11
1
  /**
12
- * `<vaadin-dialog>` is a Web Component for creating customized modal dialogs.
13
- *
14
- * ### Rendering
15
- *
16
- * The content of the dialog can be populated by using the renderer callback function.
17
- *
18
- * The renderer function provides `root`, `dialog` arguments.
19
- * Generate DOM content, append it to the `root` element and control the state
20
- * of the host element by accessing `dialog`. Before generating new content,
21
- * users are able to check if there is already content in `root` for reusing it.
22
- *
23
- * ```html
24
- * <vaadin-dialog id="dialog"></vaadin-dialog>
25
- * ```
26
- * ```js
27
- * const dialog = document.querySelector('#dialog');
28
- * dialog.renderer = function(root, dialog) {
29
- * root.textContent = "Sample dialog";
30
- * };
31
- * ```
32
- *
33
- * Renderer is called on the opening of the dialog.
34
- * DOM generated during the renderer call can be reused
35
- * in the next renderer call and will be provided with the `root` argument.
36
- * On first call it will be empty.
37
- *
38
- * ### Styling
39
- *
40
- * `<vaadin-dialog>` uses `<vaadin-dialog-overlay>` internal
41
- * themable component as the actual visible dialog overlay.
42
- *
43
- * See [`<vaadin-overlay>`](#/elements/vaadin-overlay) documentation.
44
- * for `<vaadin-dialog-overlay>` parts.
45
- *
46
- * Note: the `theme` attribute value set on `<vaadin-dialog>` is
47
- * propagated to the internal `<vaadin-dialog-overlay>` component.
48
- *
49
- * See [Styling Components](https://vaadin.com/docs/latest/ds/customization/styling-components) documentation.
50
- *
51
- * @fires {CustomEvent} resize - Fired when the dialog resize is finished.
52
- * @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
2
+ * @license
3
+ * Copyright (c) 2021 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
53
5
  */
54
- declare class DialogElement extends ThemePropertyMixin(
55
- ElementMixin(DialogDraggableMixin(DialogResizableMixin(HTMLElement)))
56
- ) {
57
- /**
58
- * True if the overlay is currently displayed.
59
- */
60
- opened: boolean;
61
-
62
- /**
63
- * Set to true to disable closing dialog on outside click
64
- * @attr {boolean} no-close-on-outside-click
65
- */
66
- noCloseOnOutsideClick: boolean;
67
-
68
- /**
69
- * Set to true to disable closing dialog on Escape press
70
- * @attr {boolean} no-close-on-esc
71
- */
72
- noCloseOnEsc: boolean;
73
-
74
- /**
75
- * Set the `aria-label` attribute for assistive technologies like
76
- * screen readers. An `undefined` value for this property (the
77
- * default) means that the `aria-label` attribute is not present at
78
- * all.
79
- */
80
- ariaLabel: string | null | undefined;
81
-
82
- /**
83
- * Custom function for rendering the content of the dialog.
84
- * Receives two arguments:
85
- *
86
- * - `root` The root container DOM element. Append your content to it.
87
- * - `dialog` The reference to the `<vaadin-dialog>` element.
88
- */
89
- renderer: DialogRenderer | null | undefined;
6
+ import { Dialog } from '@vaadin/dialog/src/vaadin-dialog.js';
90
7
 
91
- /**
92
- * Set to true to remove backdrop and allow click events on background elements.
93
- */
94
- modeless: boolean;
95
-
96
- /**
97
- * Requests an update for the content of the dialog.
98
- * While performing the update, it invokes the renderer passed in the `renderer` property.
99
- *
100
- * It is not guaranteed that the update happens immediately (synchronously) after it is requested.
101
- */
102
- requestContentUpdate(): void;
103
-
104
- /**
105
- * Manually invoke existing renderer.
106
- *
107
- * @deprecated Since Vaadin 21, `render()` is deprecated. Please use `requestContentUpdate()` instead.
108
- */
109
- render(): void;
110
-
111
- addEventListener<K extends keyof DialogEventMap>(
112
- type: K,
113
- listener: (this: DialogElement, ev: DialogEventMap[K]) => void,
114
- options?: boolean | AddEventListenerOptions
115
- ): void;
116
-
117
- removeEventListener<K extends keyof DialogEventMap>(
118
- type: K,
119
- listener: (this: DialogElement, ev: DialogEventMap[K]) => void,
120
- options?: boolean | EventListenerOptions
121
- ): void;
122
- }
8
+ /**
9
+ * @deprecated Import `Dialog` from `@vaadin/dialog` instead.
10
+ */
11
+ export type DialogElement = Dialog;
123
12
 
124
- declare global {
125
- interface HTMLElementTagNameMap {
126
- 'vaadin-dialog': DialogElement;
127
- }
128
- }
13
+ /**
14
+ * @deprecated Import `Dialog` from `@vaadin/dialog` instead.
15
+ */
16
+ export const DialogElement: typeof Dialog;
129
17
 
130
- export { DialogElement };
18
+ export * from '@vaadin/dialog/src/vaadin-dialog.js';
@@ -3,362 +3,11 @@
3
3
  * Copyright (c) 2021 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { PolymerElement, html } from '@polymer/polymer/polymer-element.js';
7
- import { IronResizableBehavior } from '@polymer/iron-resizable-behavior/iron-resizable-behavior.js';
8
- import { mixinBehaviors } from '@polymer/polymer/lib/legacy/class.js';
9
- import { OverlayElement } from '@vaadin/vaadin-overlay/src/vaadin-overlay.js';
10
- import { ElementMixin } from '@vaadin/vaadin-element-mixin/vaadin-element-mixin.js';
11
- import { processTemplates } from '@vaadin/vaadin-element-mixin/templates.js';
12
- import { ThemePropertyMixin } from '@vaadin/vaadin-themable-mixin/vaadin-theme-property-mixin.js';
13
- import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
14
- import { DialogDraggableMixin } from './vaadin-dialog-draggable-mixin.js';
15
- import { DialogResizableMixin } from './vaadin-dialog-resizable-mixin.js';
16
-
17
- registerStyles(
18
- 'vaadin-dialog-overlay',
19
- css`
20
- /*
21
- NOTE(platosha): Make some min-width to prevent collapsing of the content
22
- taking the parent width, e. g., <vaadin-grid> and such.
23
- */
24
- [part='content'] {
25
- min-width: 12em; /* matches the default <vaadin-text-field> width */
26
- }
27
-
28
- :host([has-bounds-set]) [part='overlay'] {
29
- max-width: none;
30
- }
31
- `,
32
- { moduleId: 'vaadin-dialog-overlay-styles' }
33
- );
34
-
35
- let memoizedTemplate;
36
-
37
- /**
38
- * An element used internally by `<vaadin-dialog>`. Not intended to be used separately.
39
- *
40
- * @extends OverlayElement
41
- * @private
42
- */
43
- class DialogOverlayElement extends mixinBehaviors(IronResizableBehavior, OverlayElement) {
44
- static get is() {
45
- return 'vaadin-dialog-overlay';
46
- }
47
-
48
- static get template() {
49
- if (!memoizedTemplate) {
50
- memoizedTemplate = super.template.cloneNode(true);
51
- const contentPart = memoizedTemplate.content.querySelector('[part="content"]');
52
- const overlayPart = memoizedTemplate.content.querySelector('[part="overlay"]');
53
- const resizerContainer = document.createElement('div');
54
- resizerContainer.id = 'resizerContainer';
55
- resizerContainer.classList.add('resizer-container');
56
- resizerContainer.appendChild(contentPart);
57
- overlayPart.appendChild(resizerContainer);
58
- }
59
- return memoizedTemplate;
60
- }
61
-
62
- static get properties() {
63
- return {
64
- modeless: Boolean,
65
-
66
- withBackdrop: Boolean
67
- };
68
- }
69
-
70
- /**
71
- * Updates the coordinates of the overlay.
72
- * @param {!DialogOverlayBoundsParam} bounds
73
- */
74
- setBounds(bounds) {
75
- const overlay = this.$.overlay;
76
- const parsedBounds = Object.assign({}, bounds);
77
-
78
- if (overlay.style.position !== 'absolute') {
79
- overlay.style.position = 'absolute';
80
- this.setAttribute('has-bounds-set', '');
81
- this.__forceSafariReflow();
82
- }
83
-
84
- for (const arg in parsedBounds) {
85
- if (typeof parsedBounds[arg] === 'number') {
86
- parsedBounds[arg] = `${parsedBounds[arg]}px`;
87
- }
88
- }
89
-
90
- Object.assign(overlay.style, parsedBounds);
91
- }
92
-
93
- /**
94
- * Retrieves the coordinates of the overlay.
95
- * @return {!DialogOverlayBounds}
96
- */
97
- getBounds() {
98
- const overlayBounds = this.$.overlay.getBoundingClientRect();
99
- const containerBounds = this.getBoundingClientRect();
100
- const top = overlayBounds.top - containerBounds.top;
101
- const left = overlayBounds.left - containerBounds.left;
102
- const width = overlayBounds.width;
103
- const height = overlayBounds.height;
104
- return { top, left, width, height };
105
- }
106
-
107
- /**
108
- * Safari 13 renders overflowing elements incorrectly.
109
- * This forces it to recalculate height.
110
- * @private
111
- */
112
- __forceSafariReflow() {
113
- const scrollPosition = this.$.resizerContainer.scrollTop;
114
- const overlay = this.$.overlay;
115
- overlay.style.display = 'block';
116
-
117
- requestAnimationFrame(() => {
118
- overlay.style.display = '';
119
- this.$.resizerContainer.scrollTop = scrollPosition;
120
- });
121
- }
122
- }
123
-
124
- customElements.define(DialogOverlayElement.is, DialogOverlayElement);
6
+ import { Dialog } from '@vaadin/dialog/src/vaadin-dialog.js';
125
7
 
126
8
  /**
127
- * `<vaadin-dialog>` is a Web Component for creating customized modal dialogs.
128
- *
129
- * ### Rendering
130
- *
131
- * The content of the dialog can be populated by using the renderer callback function.
132
- *
133
- * The renderer function provides `root`, `dialog` arguments.
134
- * Generate DOM content, append it to the `root` element and control the state
135
- * of the host element by accessing `dialog`. Before generating new content,
136
- * users are able to check if there is already content in `root` for reusing it.
137
- *
138
- * ```html
139
- * <vaadin-dialog id="dialog"></vaadin-dialog>
140
- * ```
141
- * ```js
142
- * const dialog = document.querySelector('#dialog');
143
- * dialog.renderer = function(root, dialog) {
144
- * root.textContent = "Sample dialog";
145
- * };
146
- * ```
147
- *
148
- * Renderer is called on the opening of the dialog.
149
- * DOM generated during the renderer call can be reused
150
- * in the next renderer call and will be provided with the `root` argument.
151
- * On first call it will be empty.
152
- *
153
- * ### Styling
154
- *
155
- * `<vaadin-dialog>` uses `<vaadin-dialog-overlay>` internal
156
- * themable component as the actual visible dialog overlay.
157
- *
158
- * See [`<vaadin-overlay>`](#/elements/vaadin-overlay) documentation.
159
- * for `<vaadin-dialog-overlay>` parts.
160
- *
161
- * Note: the `theme` attribute value set on `<vaadin-dialog>` is
162
- * propagated to the internal `<vaadin-dialog-overlay>` component.
163
- *
164
- * See [Styling Components](https://vaadin.com/docs/latest/ds/customization/styling-components) documentation.
165
- *
166
- * @fires {CustomEvent} resize - Fired when the dialog resize is finished.
167
- * @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
168
- *
169
- * @extends HTMLElement
170
- * @mixes ThemePropertyMixin
171
- * @mixes ElementMixin
172
- * @mixes DialogDraggableMixin
173
- * @mixes DialogResizableMixin
9
+ * @deprecated Import `Dialog` from `@vaadin/dialog` instead.
174
10
  */
175
- class DialogElement extends ThemePropertyMixin(
176
- ElementMixin(DialogDraggableMixin(DialogResizableMixin(PolymerElement)))
177
- ) {
178
- static get template() {
179
- return html`
180
- <style>
181
- :host {
182
- display: none;
183
- }
184
- </style>
185
-
186
- <vaadin-dialog-overlay
187
- id="overlay"
188
- on-opened-changed="_onOverlayOpened"
189
- on-mousedown="_bringOverlayToFront"
190
- on-touchstart="_bringOverlayToFront"
191
- theme$="[[theme]]"
192
- modeless="[[modeless]]"
193
- with-backdrop="[[!modeless]]"
194
- resizable$="[[resizable]]"
195
- focus-trap
196
- ></vaadin-dialog-overlay>
197
- `;
198
- }
199
-
200
- static get is() {
201
- return 'vaadin-dialog';
202
- }
203
-
204
- static get properties() {
205
- return {
206
- /**
207
- * True if the overlay is currently displayed.
208
- * @type {boolean}
209
- */
210
- opened: {
211
- type: Boolean,
212
- value: false,
213
- notify: true
214
- },
215
-
216
- /**
217
- * Set to true to disable closing dialog on outside click
218
- * @attr {boolean} no-close-on-outside-click
219
- * @type {boolean}
220
- */
221
- noCloseOnOutsideClick: {
222
- type: Boolean,
223
- value: false
224
- },
225
-
226
- /**
227
- * Set to true to disable closing dialog on Escape press
228
- * @attr {boolean} no-close-on-esc
229
- * @type {boolean}
230
- */
231
- noCloseOnEsc: {
232
- type: Boolean,
233
- value: false
234
- },
235
-
236
- /**
237
- * Set the `aria-label` attribute for assistive technologies like
238
- * screen readers. An `undefined` value for this property (the
239
- * default) means that the `aria-label` attribute is not present at
240
- * all.
241
- */
242
- ariaLabel: {
243
- type: String
244
- },
245
-
246
- /**
247
- * Custom function for rendering the content of the dialog.
248
- * Receives two arguments:
249
- *
250
- * - `root` The root container DOM element. Append your content to it.
251
- * - `dialog` The reference to the `<vaadin-dialog>` element.
252
- * @type {DialogRenderer | undefined}
253
- */
254
- renderer: Function,
255
-
256
- /**
257
- * Set to true to remove backdrop and allow click events on background elements.
258
- * @type {boolean}
259
- */
260
- modeless: {
261
- type: Boolean,
262
- value: false
263
- }
264
- };
265
- }
266
-
267
- static get observers() {
268
- return ['_openedChanged(opened)', '_ariaLabelChanged(ariaLabel)', '_rendererChanged(renderer)'];
269
- }
270
-
271
- /** @protected */
272
- ready() {
273
- super.ready();
274
- this.$.overlay.setAttribute('role', 'dialog');
275
- this.$.overlay.addEventListener('vaadin-overlay-outside-click', this._handleOutsideClick.bind(this));
276
- this.$.overlay.addEventListener('vaadin-overlay-escape-press', this._handleEscPress.bind(this));
277
-
278
- processTemplates(this);
279
- }
280
-
281
- /**
282
- * Requests an update for the content of the dialog.
283
- * While performing the update, it invokes the renderer passed in the `renderer` property.
284
- *
285
- * It is not guaranteed that the update happens immediately (synchronously) after it is requested.
286
- */
287
- requestContentUpdate() {
288
- this.$.overlay.requestContentUpdate();
289
- }
290
-
291
- /**
292
- * Manually invoke existing renderer.
293
- *
294
- * @deprecated Since Vaadin 21, `render()` is deprecated. Please use `requestContentUpdate()` instead.
295
- */
296
- render() {
297
- console.warn('WARNING: Since Vaadin 21, render() is deprecated. Please use requestContentUpdate() instead.');
298
-
299
- this.requestContentUpdate();
300
- }
301
-
302
- /** @private */
303
- _rendererChanged(renderer) {
304
- this.$.overlay.setProperties({ owner: this, renderer });
305
- }
306
-
307
- /** @protected */
308
- disconnectedCallback() {
309
- super.disconnectedCallback();
310
- this.opened = false;
311
- }
312
-
313
- /** @private */
314
- _openedChanged(opened) {
315
- this.$.overlay.opened = opened;
316
- }
317
-
318
- /** @private */
319
- _ariaLabelChanged(ariaLabel) {
320
- if (ariaLabel !== undefined && ariaLabel !== null) {
321
- this.$.overlay.setAttribute('aria-label', ariaLabel);
322
- } else {
323
- this.$.overlay.removeAttribute('aria-label');
324
- }
325
- }
326
-
327
- /** @private */
328
- _onOverlayOpened(e) {
329
- if (e.detail.value === false) {
330
- this.opened = false;
331
- }
332
- }
333
-
334
- /**
335
- * Close the dialog if `noCloseOnOutsideClick` isn't set to true
336
- * @private
337
- */
338
- _handleOutsideClick(e) {
339
- if (this.noCloseOnOutsideClick) {
340
- e.preventDefault();
341
- }
342
- }
343
-
344
- /**
345
- * Close the dialog if `noCloseOnEsc` isn't set to true
346
- * @private
347
- */
348
- _handleEscPress(e) {
349
- if (this.noCloseOnEsc) {
350
- e.preventDefault();
351
- }
352
- }
353
-
354
- /** @private */
355
- _bringOverlayToFront() {
356
- if (this.modeless) {
357
- this.$.overlay.bringToFront();
358
- }
359
- }
360
- }
361
-
362
- customElements.define(DialogElement.is, DialogElement);
11
+ export const DialogElement = Dialog;
363
12
 
364
- export { DialogElement };
13
+ export * from '@vaadin/dialog/src/vaadin-dialog.js';
@@ -1,2 +1 @@
1
- import './vaadin-dialog-styles.js';
2
- import '../../src/vaadin-dialog.js';
1
+ import '@vaadin/dialog/theme/lumo/vaadin-dialog.js';
@@ -1,2 +1 @@
1
- import './vaadin-dialog-styles.js';
2
- import '../../src/vaadin-dialog.js';
1
+ import '@vaadin/dialog/theme/material/vaadin-dialog.js';
@@ -1,2 +1 @@
1
1
  export * from './src/vaadin-dialog.js';
2
- export * from './src/interfaces';
@@ -1,46 +0,0 @@
1
- import { DialogElement } from './vaadin-dialog.js';
2
-
3
- export type DialogRenderer = (root: HTMLElement, dialog?: DialogElement) => void;
4
-
5
- export type DialogResizableDirection = 'n' | 'e' | 's' | 'w' | 'nw' | 'ne' | 'se' | 'sw';
6
-
7
- export type DialogResizeDimensions = {
8
- width: string;
9
- height: string;
10
- contentWidth: string;
11
- contentHeight: string;
12
- };
13
-
14
- export type DialogOverlayBounds = {
15
- top: number;
16
- left: number;
17
- width: number;
18
- height: number;
19
- };
20
-
21
- export type DialogOverlayBoundsParam =
22
- | DialogOverlayBounds
23
- | {
24
- top?: string | number;
25
- left?: string | number;
26
- width?: string | number;
27
- height?: string | number;
28
- };
29
-
30
- /**
31
- * Fired when the `opened` property changes.
32
- */
33
- export type DialogOpenedChangedEvent = CustomEvent<{ value: boolean }>;
34
-
35
- /**
36
- * Fired when the dialog resize is finished.
37
- */
38
- export type DialogResizeEvent = CustomEvent<DialogResizeDimensions>;
39
-
40
- export interface DialogElementEventMap {
41
- 'opened-changed': DialogOpenedChangedEvent;
42
-
43
- resize: DialogResizeEvent;
44
- }
45
-
46
- export type DialogEventMap = HTMLElementEventMap & DialogElementEventMap;
@@ -1,23 +0,0 @@
1
- declare function DialogDraggableMixin<T extends new (...args: any[]) => {}>(
2
- base: T
3
- ): T & DialogDraggableMixinConstructor;
4
-
5
- interface DialogDraggableMixinConstructor {
6
- new (...args: any[]): DialogDraggableMixin;
7
- }
8
-
9
- interface DialogDraggableMixin {
10
- /**
11
- * Set to true to enable repositioning the dialog by clicking and dragging.
12
- *
13
- * By default, only the overlay area can be used to drag the element. But,
14
- * a child element can be marked as a draggable area by adding a
15
- * "`draggable`" class to it, this will by default make all of its children draggable also.
16
- * If you want a child element to be draggable
17
- * but still have its children non-draggable (by default), mark it with
18
- * "`draggable-leaf-only`" class name.
19
- */
20
- draggable: boolean;
21
- }
22
-
23
- export { DialogDraggableMixin, DialogDraggableMixinConstructor };
@@ -1,118 +0,0 @@
1
- import { getMouseOrFirstTouchEvent, eventInWindow } from './vaadin-dialog-utils.js';
2
-
3
- const TOUCH_DEVICE = (() => {
4
- try {
5
- document.createEvent('TouchEvent');
6
- return true;
7
- } catch (e) {
8
- return false;
9
- }
10
- })();
11
-
12
- /**
13
- * @polymerMixin
14
- */
15
- export const DialogDraggableMixin = (superClass) =>
16
- class VaadinDialogDraggableMixin extends superClass {
17
- static get properties() {
18
- return {
19
- /**
20
- * Set to true to enable repositioning the dialog by clicking and dragging.
21
- *
22
- * By default, only the overlay area can be used to drag the element. But,
23
- * a child element can be marked as a draggable area by adding a
24
- * "`draggable`" class to it, this will by default make all of its children draggable also.
25
- * If you want a child element to be draggable
26
- * but still have its children non-draggable (by default), mark it with
27
- * "`draggable-leaf-only`" class name.
28
- *
29
- * @type {boolean}
30
- */
31
- draggable: {
32
- type: Boolean,
33
- value: false,
34
- reflectToAttribute: true
35
- },
36
-
37
- /** @private */
38
- _touchDevice: {
39
- type: Boolean,
40
- value: TOUCH_DEVICE
41
- },
42
-
43
- /* TODO: Expose as a public property (check naming) */
44
- __dragHandleClassName: {
45
- type: String
46
- }
47
- };
48
- }
49
-
50
- /** @protected */
51
- ready() {
52
- super.ready();
53
- this._originalBounds = {};
54
- this._originalMouseCoords = {};
55
- this._startDrag = this._startDrag.bind(this);
56
- this._drag = this._drag.bind(this);
57
- this._stopDrag = this._stopDrag.bind(this);
58
- this.$.overlay.$.overlay.addEventListener('mousedown', this._startDrag);
59
- this.$.overlay.$.overlay.addEventListener('touchstart', this._startDrag);
60
- }
61
-
62
- /** @private */
63
- _startDrag(e) {
64
- // Don't initiate when there's more than 1 touch (pinch zoom)
65
- if (e.type === 'touchstart' && e.touches.length > 1) {
66
- return;
67
- }
68
-
69
- if (this.draggable && (e.button === 0 || e.touches)) {
70
- const resizerContainer = this.$.overlay.$.resizerContainer;
71
- const isResizerContainer = e.target === resizerContainer;
72
- const isResizerContainerScrollbar =
73
- e.offsetX > resizerContainer.clientWidth || e.offsetY > resizerContainer.clientHeight;
74
- const isContentPart = e.target === this.$.overlay.$.content;
75
-
76
- const isDraggable = e.composedPath().some((node, index) => {
77
- if (node.classList) {
78
- const isDraggableNode = node.classList.contains(this.__dragHandleClassName || 'draggable');
79
- const isDraggableLeafOnly = node.classList.contains('draggable-leaf-only');
80
- const isLeafNode = index === 0;
81
- return (isDraggableLeafOnly && isLeafNode) || (isDraggableNode && (!isDraggableLeafOnly || isLeafNode));
82
- }
83
- });
84
-
85
- if ((isResizerContainer && !isResizerContainerScrollbar) || isContentPart || isDraggable) {
86
- !isDraggable && e.preventDefault();
87
- this._originalBounds = this.$.overlay.getBounds();
88
- const event = getMouseOrFirstTouchEvent(e);
89
- this._originalMouseCoords = { top: event.pageY, left: event.pageX };
90
- window.addEventListener('mouseup', this._stopDrag);
91
- window.addEventListener('touchend', this._stopDrag);
92
- window.addEventListener('mousemove', this._drag);
93
- window.addEventListener('touchmove', this._drag);
94
- if (this.$.overlay.$.overlay.style.position !== 'absolute') {
95
- this.$.overlay.setBounds(this._originalBounds);
96
- }
97
- }
98
- }
99
- }
100
-
101
- /** @private */
102
- _drag(e) {
103
- const event = getMouseOrFirstTouchEvent(e);
104
- if (eventInWindow(event)) {
105
- const top = this._originalBounds.top + (event.pageY - this._originalMouseCoords.top);
106
- const left = this._originalBounds.left + (event.pageX - this._originalMouseCoords.left);
107
- this.$.overlay.setBounds({ top, left });
108
- }
109
- }
110
-
111
- /** @private */
112
- _stopDrag() {
113
- window.removeEventListener('mouseup', this._stopDrag);
114
- window.removeEventListener('touchend', this._stopDrag);
115
- window.removeEventListener('mousemove', this._drag);
116
- window.removeEventListener('touchmove', this._drag);
117
- }
118
- };
@@ -1,26 +0,0 @@
1
- import { DialogResizableDirection, DialogResizeDimensions } from './interfaces';
2
-
3
- declare function DialogResizableMixin<T extends new (...args: any[]) => {}>(
4
- base: T
5
- ): T & DialogResizableMixinConstructor;
6
-
7
- interface DialogResizableMixinConstructor {
8
- new (...args: any[]): DialogResizableMixin;
9
- }
10
-
11
- interface DialogResizableMixin {
12
- /**
13
- * Set to true to enable resizing the dialog by dragging the corners and edges.
14
- */
15
- resizable: boolean;
16
-
17
- _startResize(e: MouseEvent | TouchEvent, direction: DialogResizableDirection): void;
18
-
19
- _resize(e: MouseEvent | TouchEvent, resizer: DialogResizableDirection): void;
20
-
21
- _stopResize(direction: DialogResizableDirection): void;
22
-
23
- _getResizeDimensions(): DialogResizeDimensions;
24
- }
25
-
26
- export { DialogResizableMixin, DialogResizableMixinConstructor };
@@ -1,250 +0,0 @@
1
- import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
2
- import { getMouseOrFirstTouchEvent, eventInWindow } from './vaadin-dialog-utils.js';
3
-
4
- registerStyles(
5
- 'vaadin-dialog-overlay',
6
- css`
7
- [part='overlay'] {
8
- position: relative;
9
- overflow: visible;
10
- max-height: 100%;
11
- display: flex;
12
- }
13
-
14
- [part='content'] {
15
- box-sizing: border-box;
16
- height: 100%;
17
- }
18
-
19
- .resizer-container {
20
- overflow: auto;
21
- flex-grow: 1;
22
- }
23
-
24
- [part='overlay'][style] .resizer-container {
25
- min-height: 100%;
26
- width: 100%;
27
- }
28
-
29
- :host(:not([resizable])) .resizer {
30
- display: none;
31
- }
32
-
33
- .resizer {
34
- position: absolute;
35
- height: 16px;
36
- width: 16px;
37
- }
38
-
39
- .resizer.edge {
40
- height: 8px;
41
- width: 8px;
42
- top: -4px;
43
- right: -4px;
44
- bottom: -4px;
45
- left: -4px;
46
- }
47
-
48
- .resizer.edge.n {
49
- width: auto;
50
- bottom: auto;
51
- cursor: ns-resize;
52
- }
53
-
54
- .resizer.ne {
55
- top: -4px;
56
- right: -4px;
57
- cursor: nesw-resize;
58
- }
59
-
60
- .resizer.edge.e {
61
- height: auto;
62
- left: auto;
63
- cursor: ew-resize;
64
- }
65
-
66
- .resizer.se {
67
- bottom: -4px;
68
- right: -4px;
69
- cursor: nwse-resize;
70
- }
71
-
72
- .resizer.edge.s {
73
- width: auto;
74
- top: auto;
75
- cursor: ns-resize;
76
- }
77
-
78
- .resizer.sw {
79
- bottom: -4px;
80
- left: -4px;
81
- cursor: nesw-resize;
82
- }
83
-
84
- .resizer.edge.w {
85
- height: auto;
86
- right: auto;
87
- cursor: ew-resize;
88
- }
89
-
90
- .resizer.nw {
91
- top: -4px;
92
- left: -4px;
93
- cursor: nwse-resize;
94
- }
95
- `,
96
- { moduleId: 'vaadin-dialog-resizable-overlay-styles' }
97
- );
98
-
99
- /**
100
- * @polymerMixin
101
- */
102
- export const DialogResizableMixin = (superClass) =>
103
- class VaadinDialogResizableMixin extends superClass {
104
- static get properties() {
105
- return {
106
- /**
107
- * Set to true to enable resizing the dialog by dragging the corners and edges.
108
- * @type {boolean}
109
- */
110
- resizable: {
111
- type: Boolean,
112
- value: false,
113
- reflectToAttribute: true
114
- }
115
- };
116
- }
117
-
118
- /** @protected */
119
- ready() {
120
- super.ready();
121
- this._originalBounds = {};
122
- this._originalMouseCoords = {};
123
- this._resizeListeners = { start: {}, resize: {}, stop: {} };
124
- this._addResizeListeners();
125
- }
126
-
127
- /** @private */
128
- _addResizeListeners() {
129
- // Note: edge controls added before corners
130
- ['n', 'e', 's', 'w', 'nw', 'ne', 'se', 'sw'].forEach((direction) => {
131
- const resizer = document.createElement('div');
132
- this._resizeListeners.start[direction] = (e) => this._startResize(e, direction);
133
- this._resizeListeners.resize[direction] = (e) => this._resize(e, direction);
134
- this._resizeListeners.stop[direction] = () => this._stopResize(direction);
135
- if (direction.length === 1) {
136
- resizer.classList.add('edge');
137
- }
138
- resizer.classList.add('resizer');
139
- resizer.classList.add(direction);
140
- resizer.addEventListener('mousedown', this._resizeListeners.start[direction]);
141
- resizer.addEventListener('touchstart', this._resizeListeners.start[direction]);
142
- this.$.overlay.$.resizerContainer.appendChild(resizer);
143
- });
144
- }
145
-
146
- /**
147
- * @param {!MouseEvent | !TouchEvent} e
148
- * @param {!DialogResizableDirection} direction
149
- * @protected
150
- */
151
- _startResize(e, direction) {
152
- // Don't initiate when there's more than 1 touch (pinch zoom)
153
- if (e.type === 'touchstart' && e.touches.length > 1) {
154
- return;
155
- }
156
-
157
- if (e.button === 0 || e.touches) {
158
- e.preventDefault();
159
-
160
- this._originalBounds = this.$.overlay.getBounds();
161
- const event = getMouseOrFirstTouchEvent(e);
162
- this._originalMouseCoords = { top: event.pageY, left: event.pageX };
163
- window.addEventListener('mousemove', this._resizeListeners.resize[direction]);
164
- window.addEventListener('touchmove', this._resizeListeners.resize[direction]);
165
- window.addEventListener('mouseup', this._resizeListeners.stop[direction]);
166
- window.addEventListener('touchend', this._resizeListeners.stop[direction]);
167
- if (this.$.overlay.$.overlay.style.position !== 'absolute') {
168
- this.$.overlay.setBounds(this._originalBounds);
169
- }
170
- }
171
- }
172
-
173
- /**
174
- * @param {!MouseEvent | !TouchEvent} e
175
- * @param {!DialogResizableDirection} resizer
176
- * @protected
177
- */
178
- _resize(e, resizer) {
179
- const event = getMouseOrFirstTouchEvent(e);
180
- if (eventInWindow(event)) {
181
- const minimumSize = 40;
182
- resizer.split('').forEach((direction) => {
183
- switch (direction) {
184
- case 'n': {
185
- const height = this._originalBounds.height - (event.pageY - this._originalMouseCoords.top);
186
- const top = this._originalBounds.top + (event.pageY - this._originalMouseCoords.top);
187
- if (height > minimumSize) {
188
- this.$.overlay.setBounds({ top, height });
189
- }
190
- break;
191
- }
192
- case 'e': {
193
- const width = this._originalBounds.width + (event.pageX - this._originalMouseCoords.left);
194
- if (width > minimumSize) {
195
- this.$.overlay.setBounds({ width });
196
- }
197
- break;
198
- }
199
- case 's': {
200
- const height = this._originalBounds.height + (event.pageY - this._originalMouseCoords.top);
201
- if (height > minimumSize) {
202
- this.$.overlay.setBounds({ height });
203
- }
204
- break;
205
- }
206
- case 'w': {
207
- const width = this._originalBounds.width - (event.pageX - this._originalMouseCoords.left);
208
- const left = this._originalBounds.left + (event.pageX - this._originalMouseCoords.left);
209
- if (width > minimumSize) {
210
- this.$.overlay.setBounds({ left, width });
211
- }
212
- break;
213
- }
214
- }
215
- });
216
-
217
- this.$.overlay.notifyResize();
218
- }
219
- }
220
-
221
- /**
222
- * @param {!DialogResizableDirection} direction
223
- * @protected
224
- */
225
- _stopResize(direction) {
226
- window.removeEventListener('mousemove', this._resizeListeners.resize[direction]);
227
- window.removeEventListener('touchmove', this._resizeListeners.resize[direction]);
228
- window.removeEventListener('mouseup', this._resizeListeners.stop[direction]);
229
- window.removeEventListener('touchend', this._resizeListeners.stop[direction]);
230
- this.dispatchEvent(new CustomEvent('resize', { detail: this._getResizeDimensions() }));
231
- }
232
-
233
- /**
234
- * @return {!DialogResizeDimensions}
235
- * @protected
236
- */
237
- _getResizeDimensions() {
238
- const scrollPosition = this.$.overlay.$.resizerContainer.scrollTop;
239
- const { width, height } = getComputedStyle(this.$.overlay.$.overlay);
240
- const content = this.$.overlay.$.content;
241
- content.setAttribute(
242
- 'style',
243
- 'position: absolute; top: 0; right: 0; bottom: 0; left: 0; box-sizing: content-box; height: auto;'
244
- );
245
- const { width: contentWidth, height: contentHeight } = getComputedStyle(content);
246
- content.removeAttribute('style');
247
- this.$.overlay.$.resizerContainer.scrollTop = scrollPosition;
248
- return { width, height, contentWidth, contentHeight };
249
- }
250
- };
@@ -1,14 +0,0 @@
1
- /**
2
- * Checks if the argument is a touch event and if so, returns a first touch.
3
- * Otherwise, if the mouse event was passed, returns it as is.
4
- */
5
- declare function getMouseOrFirstTouchEvent(e: MouseEvent | TouchEvent): MouseEvent | Touch;
6
-
7
- export { getMouseOrFirstTouchEvent };
8
-
9
- /**
10
- * Checks whether a mouse or touch event is in window.
11
- */
12
- declare function eventInWindow(e: MouseEvent | TouchEvent): boolean;
13
-
14
- export { eventInWindow };
@@ -1,20 +0,0 @@
1
- /**
2
- * Checks if the argument is a touch event and if so, returns a first touch.
3
- * Otherwise, if the mouse event was passed, returns it as is.
4
- * @param {!MouseEvent | !TouchEvent} e
5
- * @return {!MouseEvent | !Touch}
6
- * @protected
7
- */
8
- export function getMouseOrFirstTouchEvent(e) {
9
- return e.touches ? e.touches[0] : e;
10
- }
11
-
12
- /**
13
- * Checks whether a mouse or touch event is in window.
14
- * @param {!MouseEvent | !TouchEvent} e
15
- * @return {boolean}
16
- * @protected
17
- */
18
- export function eventInWindow(e) {
19
- return e.clientX >= 0 && e.clientX <= window.innerWidth && e.clientY >= 0 && e.clientY <= window.innerHeight;
20
- }
@@ -1,69 +0,0 @@
1
- import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
2
- import '@vaadin/vaadin-lumo-styles/spacing.js';
3
- import { overlay } from '@vaadin/vaadin-lumo-styles/mixins/overlay.js';
4
-
5
- const dialogOverlay = css`
6
- /* Optical centering */
7
- :host::before,
8
- :host::after {
9
- content: '';
10
- flex-basis: 0;
11
- flex-grow: 1;
12
- }
13
-
14
- :host::after {
15
- flex-grow: 1.1;
16
- }
17
-
18
- [part='overlay'] {
19
- border-radius: var(--lumo-border-radius-l);
20
- box-shadow: 0 0 0 1px var(--lumo-shade-5pct), var(--lumo-box-shadow-xl);
21
- background-image: none;
22
- outline: none;
23
- -webkit-tap-highlight-color: transparent;
24
- }
25
-
26
- [part='content'] {
27
- padding: var(--lumo-space-l);
28
- }
29
-
30
- /* No padding */
31
- :host([theme~='no-padding']) [part='content'] {
32
- padding: 0;
33
- }
34
-
35
- /* Animations */
36
-
37
- :host([opening]),
38
- :host([closing]) {
39
- animation: 0.25s lumo-overlay-dummy-animation;
40
- }
41
-
42
- :host([opening]) [part='overlay'] {
43
- animation: 0.12s 0.05s vaadin-dialog-enter cubic-bezier(0.215, 0.61, 0.355, 1) both;
44
- }
45
-
46
- @keyframes vaadin-dialog-enter {
47
- 0% {
48
- opacity: 0;
49
- transform: scale(0.95);
50
- }
51
- }
52
-
53
- :host([closing]) [part='overlay'] {
54
- animation: 0.1s 0.03s vaadin-dialog-exit cubic-bezier(0.55, 0.055, 0.675, 0.19) both;
55
- }
56
-
57
- :host([closing]) [part='backdrop'] {
58
- animation-delay: 0.05s;
59
- }
60
-
61
- @keyframes vaadin-dialog-exit {
62
- 100% {
63
- opacity: 0;
64
- transform: scale(1.02);
65
- }
66
- }
67
- `;
68
-
69
- registerStyles('vaadin-dialog-overlay', [overlay, dialogOverlay], { moduleId: 'lumo-dialog' });
@@ -1,26 +0,0 @@
1
- import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
2
- import { overlay } from '@vaadin/vaadin-material-styles/mixins/overlay.js';
3
- import '@vaadin/vaadin-material-styles/shadow.js';
4
-
5
- const dialogOverlay = css`
6
- [part='overlay'] {
7
- box-shadow: var(--material-shadow-elevation-24dp);
8
- outline: none;
9
- max-width: 560px;
10
- min-width: 280px;
11
- -webkit-tap-highlight-color: transparent;
12
- }
13
-
14
- [part='content'] {
15
- padding: 24px;
16
- }
17
-
18
- /* No padding */
19
- :host([theme~='no-padding']) [part='content'] {
20
- padding: 0;
21
- }
22
- `;
23
-
24
- registerStyles('vaadin-dialog-overlay', [overlay, dialogOverlay], {
25
- moduleId: 'material-dialog'
26
- });