@zanichelli/albe-web-components 21.0.0-RC1 → 21.0.0-RC3

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.
Files changed (132) hide show
  1. package/dist/cjs/dialog-polyfill.esm-D8Polhcd.js +863 -0
  2. package/dist/cjs/dialog-polyfill.esm-D8Polhcd.js.map +1 -0
  3. package/dist/cjs/hammer-CJF2Ixtg.js +2665 -0
  4. package/dist/cjs/hammer-CJF2Ixtg.js.map +1 -0
  5. package/dist/cjs/index-CZz7uP-M.js +6 -6
  6. package/dist/cjs/z-dragdrop-area_2.cjs.entry.js +8 -862
  7. package/dist/cjs/z-dragdrop-area_2.cjs.entry.js.map +1 -1
  8. package/dist/cjs/z-toast-notification.cjs.entry.js +7 -2657
  9. package/dist/cjs/z-toast-notification.cjs.entry.js.map +1 -1
  10. package/dist/collection/components/z-modal/index.js +8 -6
  11. package/dist/collection/components/z-modal/index.js.map +1 -1
  12. package/dist/collection/components/z-toast-notification/index.js +7 -5
  13. package/dist/collection/components/z-toast-notification/index.js.map +1 -1
  14. package/dist/components/p-BRkq64wS.js +2 -0
  15. package/dist/components/p-BRkq64wS.js.map +1 -0
  16. package/dist/components/p-Bt1M0wUw.js +7 -0
  17. package/dist/components/p-Bt1M0wUw.js.map +1 -0
  18. package/dist/components/p-BvCsF6Eq.js +2 -0
  19. package/dist/components/p-BvCsF6Eq.js.map +1 -0
  20. package/dist/components/z-file-upload.js +1 -1
  21. package/dist/components/z-modal.js +1 -1
  22. package/dist/components/z-toast-notification.js +2 -7
  23. package/dist/components/z-toast-notification.js.map +1 -1
  24. package/dist/esm/dialog-polyfill.esm-BRkq64wS.js +861 -0
  25. package/dist/esm/dialog-polyfill.esm-BRkq64wS.js.map +1 -0
  26. package/dist/esm/hammer-C3JqVNyx.js +2663 -0
  27. package/dist/esm/hammer-C3JqVNyx.js.map +1 -0
  28. package/dist/esm/index-BcDWN4F1.js +6 -6
  29. package/dist/esm/z-dragdrop-area_2.entry.js +8 -862
  30. package/dist/esm/z-dragdrop-area_2.entry.js.map +1 -1
  31. package/dist/esm/z-toast-notification.entry.js +7 -2657
  32. package/dist/esm/z-toast-notification.entry.js.map +1 -1
  33. package/dist/types/components/z-modal/index.d.ts +1 -1
  34. package/dist/web-components-library/p-67051e01.entry.js +3 -0
  35. package/dist/web-components-library/p-67051e01.entry.js.map +1 -0
  36. package/dist/web-components-library/p-BRkq64wS.js +2 -0
  37. package/dist/web-components-library/p-BRkq64wS.js.map +1 -0
  38. package/dist/web-components-library/p-Bt1M0wUw.js +7 -0
  39. package/dist/web-components-library/p-Bt1M0wUw.js.map +1 -0
  40. package/dist/web-components-library/p-c3f69ac9.entry.js +2 -0
  41. package/dist/web-components-library/p-c3f69ac9.entry.js.map +1 -0
  42. package/dist/web-components-library/web-components-library.esm.js +1 -1
  43. package/package.json +3 -3
  44. package/react/components.js +64 -132
  45. package/react/index.d.ts +1 -1
  46. package/react/index.js +1 -17
  47. package/react/package.json +3 -0
  48. package/react/z-accordion.js +7 -13
  49. package/react/z-anchor-navigation.js +7 -13
  50. package/react/z-app-header.js +7 -13
  51. package/react/z-aria-alert.js +7 -13
  52. package/react/z-avatar.js +7 -13
  53. package/react/z-book-card-app.js +7 -13
  54. package/react/z-book-card.js +7 -13
  55. package/react/z-book-cover.js +7 -13
  56. package/react/z-breadcrumb.js +7 -13
  57. package/react/z-button-sort.js +7 -13
  58. package/react/z-button.js +7 -13
  59. package/react/z-card.js +7 -13
  60. package/react/z-carousel.js +7 -13
  61. package/react/z-chip.js +7 -13
  62. package/react/z-color-picker.js +7 -13
  63. package/react/z-combobox.js +7 -13
  64. package/react/z-cover-hero.js +7 -13
  65. package/react/z-date-picker.js +7 -13
  66. package/react/z-divider.js +7 -13
  67. package/react/z-dragdrop-area.js +7 -13
  68. package/react/z-file-upload.js +7 -13
  69. package/react/z-file.js +7 -13
  70. package/react/z-ghost-loading.js +7 -13
  71. package/react/z-icon.js +7 -13
  72. package/react/z-info-box.js +7 -13
  73. package/react/z-info-reveal.js +7 -13
  74. package/react/z-input-message.js +7 -13
  75. package/react/z-input-range.js +7 -13
  76. package/react/z-input.js +7 -13
  77. package/react/z-list-element.js +7 -13
  78. package/react/z-list-group.js +7 -13
  79. package/react/z-list.js +7 -13
  80. package/react/z-logo.js +7 -13
  81. package/react/z-menu-section.js +7 -13
  82. package/react/z-menu.js +7 -13
  83. package/react/z-modal.js +7 -13
  84. package/react/z-navigation-tabs.js +7 -13
  85. package/react/z-notification.js +7 -13
  86. package/react/z-offcanvas.js +7 -13
  87. package/react/z-pagination.js +7 -13
  88. package/react/z-popover.js +7 -13
  89. package/react/z-range-picker.js +7 -13
  90. package/react/z-result-card.js +7 -13
  91. package/react/z-searchbar.js +7 -13
  92. package/react/z-select.js +7 -13
  93. package/react/z-skip-to-content.js +7 -13
  94. package/react/z-stepper-item.js +7 -13
  95. package/react/z-stepper.js +7 -13
  96. package/react/z-table.js +7 -13
  97. package/react/z-tag.js +7 -13
  98. package/react/z-tbody.js +7 -13
  99. package/react/z-td.js +7 -13
  100. package/react/z-tfoot.js +7 -13
  101. package/react/z-th.js +7 -13
  102. package/react/z-thead.js +7 -13
  103. package/react/z-toast-notification-list.js +7 -13
  104. package/react/z-toast-notification.js +7 -13
  105. package/react/z-toggle-switch.js +7 -13
  106. package/react/z-tool.js +7 -13
  107. package/react/z-toolbar.js +7 -13
  108. package/react/z-tooltip.js +7 -13
  109. package/react/z-tr.js +7 -13
  110. package/react/z-tree-list.js +7 -13
  111. package/react/z-visually-hidden.js +7 -13
  112. package/www/build/{p-de6e8c2b.js → p-3ddbf8a7.js} +1 -1
  113. package/www/build/p-67051e01.entry.js +3 -0
  114. package/www/build/p-67051e01.entry.js.map +1 -0
  115. package/www/build/p-BRkq64wS.js +2 -0
  116. package/www/build/p-BRkq64wS.js.map +1 -0
  117. package/www/build/p-Bt1M0wUw.js +7 -0
  118. package/www/build/p-Bt1M0wUw.js.map +1 -0
  119. package/www/build/p-c3f69ac9.entry.js +2 -0
  120. package/www/build/p-c3f69ac9.entry.js.map +1 -0
  121. package/www/build/web-components-library.esm.js +1 -1
  122. package/www/index.html +1 -1
  123. package/dist/components/p-BbZelagf.js +0 -2
  124. package/dist/components/p-BbZelagf.js.map +0 -1
  125. package/dist/web-components-library/p-baa35a6e.entry.js +0 -2
  126. package/dist/web-components-library/p-baa35a6e.entry.js.map +0 -1
  127. package/dist/web-components-library/p-ea96790b.entry.js +0 -8
  128. package/dist/web-components-library/p-ea96790b.entry.js.map +0 -1
  129. package/www/build/p-baa35a6e.entry.js +0 -2
  130. package/www/build/p-baa35a6e.entry.js.map +0 -1
  131. package/www/build/p-ea96790b.entry.js +0 -8
  132. package/www/build/p-ea96790b.entry.js.map +0 -1
@@ -0,0 +1,863 @@
1
+ 'use strict';
2
+
3
+ // nb. This is for IE10 and lower _only_.
4
+ var supportCustomEvent = window.CustomEvent;
5
+ if (!supportCustomEvent || typeof supportCustomEvent === 'object') {
6
+ supportCustomEvent = function CustomEvent(event, x) {
7
+ x = x || {};
8
+ var ev = document.createEvent('CustomEvent');
9
+ ev.initCustomEvent(event, !!x.bubbles, !!x.cancelable, x.detail || null);
10
+ return ev;
11
+ };
12
+ supportCustomEvent.prototype = window.Event.prototype;
13
+ }
14
+
15
+ /**
16
+ * Dispatches the passed event to both an "on<type>" handler as well as via the
17
+ * normal dispatch operation. Does not bubble.
18
+ *
19
+ * @param {!EventTarget} target
20
+ * @param {!Event} event
21
+ * @return {boolean}
22
+ */
23
+ function safeDispatchEvent(target, event) {
24
+ var check = 'on' + event.type.toLowerCase();
25
+ if (typeof target[check] === 'function') {
26
+ target[check](event);
27
+ }
28
+ return target.dispatchEvent(event);
29
+ }
30
+
31
+ /**
32
+ * @param {Element} el to check for stacking context
33
+ * @return {boolean} whether this el or its parents creates a stacking context
34
+ */
35
+ function createsStackingContext(el) {
36
+ while (el && el !== document.body) {
37
+ var s = window.getComputedStyle(el);
38
+ var invalid = function(k, ok) {
39
+ return !(s[k] === undefined || s[k] === ok);
40
+ };
41
+
42
+ if (s.opacity < 1 ||
43
+ invalid('zIndex', 'auto') ||
44
+ invalid('transform', 'none') ||
45
+ invalid('mixBlendMode', 'normal') ||
46
+ invalid('filter', 'none') ||
47
+ invalid('perspective', 'none') ||
48
+ s['isolation'] === 'isolate' ||
49
+ s.position === 'fixed' ||
50
+ s.webkitOverflowScrolling === 'touch') {
51
+ return true;
52
+ }
53
+ el = el.parentElement;
54
+ }
55
+ return false;
56
+ }
57
+
58
+ /**
59
+ * Finds the nearest <dialog> from the passed element.
60
+ *
61
+ * @param {Element} el to search from
62
+ * @return {HTMLDialogElement} dialog found
63
+ */
64
+ function findNearestDialog(el) {
65
+ while (el) {
66
+ if (el.localName === 'dialog') {
67
+ return /** @type {HTMLDialogElement} */ (el);
68
+ }
69
+ if (el.parentElement) {
70
+ el = el.parentElement;
71
+ } else if (el.parentNode) {
72
+ el = el.parentNode.host;
73
+ } else {
74
+ el = null;
75
+ }
76
+ }
77
+ return null;
78
+ }
79
+
80
+ /**
81
+ * Blur the specified element, as long as it's not the HTML body element.
82
+ * This works around an IE9/10 bug - blurring the body causes Windows to
83
+ * blur the whole application.
84
+ *
85
+ * @param {Element} el to blur
86
+ */
87
+ function safeBlur(el) {
88
+ // Find the actual focused element when the active element is inside a shadow root
89
+ while (el && el.shadowRoot && el.shadowRoot.activeElement) {
90
+ el = el.shadowRoot.activeElement;
91
+ }
92
+
93
+ if (el && el.blur && el !== document.body) {
94
+ el.blur();
95
+ }
96
+ }
97
+
98
+ /**
99
+ * @param {!NodeList} nodeList to search
100
+ * @param {Node} node to find
101
+ * @return {boolean} whether node is inside nodeList
102
+ */
103
+ function inNodeList(nodeList, node) {
104
+ for (var i = 0; i < nodeList.length; ++i) {
105
+ if (nodeList[i] === node) {
106
+ return true;
107
+ }
108
+ }
109
+ return false;
110
+ }
111
+
112
+ /**
113
+ * @param {HTMLFormElement} el to check
114
+ * @return {boolean} whether this form has method="dialog"
115
+ */
116
+ function isFormMethodDialog(el) {
117
+ if (!el || !el.hasAttribute('method')) {
118
+ return false;
119
+ }
120
+ return el.getAttribute('method').toLowerCase() === 'dialog';
121
+ }
122
+
123
+ /**
124
+ * @param {!DocumentFragment|!Element} hostElement
125
+ * @return {?Element}
126
+ */
127
+ function findFocusableElementWithin(hostElement) {
128
+ // Note that this is 'any focusable area'. This list is probably not exhaustive, but the
129
+ // alternative involves stepping through and trying to focus everything.
130
+ var opts = ['button', 'input', 'keygen', 'select', 'textarea'];
131
+ var query = opts.map(function(el) {
132
+ return el + ':not([disabled])';
133
+ });
134
+ // TODO(samthor): tabindex values that are not numeric are not focusable.
135
+ query.push('[tabindex]:not([disabled]):not([tabindex=""])'); // tabindex != "", not disabled
136
+ var target = hostElement.querySelector(query.join(', '));
137
+
138
+ if (!target && 'attachShadow' in Element.prototype) {
139
+ // If we haven't found a focusable target, see if the host element contains an element
140
+ // which has a shadowRoot.
141
+ // Recursively search for the first focusable item in shadow roots.
142
+ var elems = hostElement.querySelectorAll('*');
143
+ for (var i = 0; i < elems.length; i++) {
144
+ if (elems[i].tagName && elems[i].shadowRoot) {
145
+ target = findFocusableElementWithin(elems[i].shadowRoot);
146
+ if (target) {
147
+ break;
148
+ }
149
+ }
150
+ }
151
+ }
152
+ return target;
153
+ }
154
+
155
+ /**
156
+ * Determines if an element is attached to the DOM.
157
+ * @param {Element} element to check
158
+ * @return {boolean} whether the element is in DOM
159
+ */
160
+ function isConnected(element) {
161
+ return element.isConnected || document.body.contains(element);
162
+ }
163
+
164
+ /**
165
+ * @param {!Event} event
166
+ * @return {?Element}
167
+ */
168
+ function findFormSubmitter(event) {
169
+ if (event.submitter) {
170
+ return event.submitter;
171
+ }
172
+
173
+ var form = event.target;
174
+ if (!(form instanceof HTMLFormElement)) {
175
+ return null;
176
+ }
177
+
178
+ var submitter = dialogPolyfill.formSubmitter;
179
+ if (!submitter) {
180
+ var target = event.target;
181
+ var root = ('getRootNode' in target && target.getRootNode() || document);
182
+ submitter = root.activeElement;
183
+ }
184
+
185
+ if (!submitter || submitter.form !== form) {
186
+ return null;
187
+ }
188
+ return submitter;
189
+ }
190
+
191
+ /**
192
+ * @param {!Event} event
193
+ */
194
+ function maybeHandleSubmit(event) {
195
+ if (event.defaultPrevented) {
196
+ return;
197
+ }
198
+ var form = /** @type {!HTMLFormElement} */ (event.target);
199
+
200
+ // We'd have a value if we clicked on an imagemap.
201
+ var value = dialogPolyfill.imagemapUseValue;
202
+ var submitter = findFormSubmitter(event);
203
+ if (value === null && submitter) {
204
+ value = submitter.value;
205
+ }
206
+
207
+ // There should always be a dialog as this handler is added specifically on them, but check just
208
+ // in case.
209
+ var dialog = findNearestDialog(form);
210
+ if (!dialog) {
211
+ return;
212
+ }
213
+
214
+ // Prefer formmethod on the button.
215
+ var formmethod = submitter && submitter.getAttribute('formmethod') || form.getAttribute('method');
216
+ if (formmethod !== 'dialog') {
217
+ return;
218
+ }
219
+ event.preventDefault();
220
+
221
+ if (value != null) {
222
+ // nb. we explicitly check against null/undefined
223
+ dialog.close(value);
224
+ } else {
225
+ dialog.close();
226
+ }
227
+ }
228
+
229
+ /**
230
+ * @param {!HTMLDialogElement} dialog to upgrade
231
+ * @constructor
232
+ */
233
+ function dialogPolyfillInfo(dialog) {
234
+ this.dialog_ = dialog;
235
+ this.replacedStyleTop_ = false;
236
+ this.openAsModal_ = false;
237
+
238
+ // Set a11y role. Browsers that support dialog implicitly know this already.
239
+ if (!dialog.hasAttribute('role')) {
240
+ dialog.setAttribute('role', 'dialog');
241
+ }
242
+
243
+ dialog.show = this.show.bind(this);
244
+ dialog.showModal = this.showModal.bind(this);
245
+ dialog.close = this.close.bind(this);
246
+
247
+ dialog.addEventListener('submit', maybeHandleSubmit, false);
248
+
249
+ if (!('returnValue' in dialog)) {
250
+ dialog.returnValue = '';
251
+ }
252
+
253
+ if ('MutationObserver' in window) {
254
+ var mo = new MutationObserver(this.maybeHideModal.bind(this));
255
+ mo.observe(dialog, {attributes: true, attributeFilter: ['open']});
256
+ } else {
257
+ // IE10 and below support. Note that DOMNodeRemoved etc fire _before_ removal. They also
258
+ // seem to fire even if the element was removed as part of a parent removal. Use the removed
259
+ // events to force downgrade (useful if removed/immediately added).
260
+ var removed = false;
261
+ var cb = function() {
262
+ removed ? this.downgradeModal() : this.maybeHideModal();
263
+ removed = false;
264
+ }.bind(this);
265
+ var timeout;
266
+ var delayModel = function(ev) {
267
+ if (ev.target !== dialog) { return; } // not for a child element
268
+ var cand = 'DOMNodeRemoved';
269
+ removed |= (ev.type.substr(0, cand.length) === cand);
270
+ window.clearTimeout(timeout);
271
+ timeout = window.setTimeout(cb, 0);
272
+ };
273
+ ['DOMAttrModified', 'DOMNodeRemoved', 'DOMNodeRemovedFromDocument'].forEach(function(name) {
274
+ dialog.addEventListener(name, delayModel);
275
+ });
276
+ }
277
+ // Note that the DOM is observed inside DialogManager while any dialog
278
+ // is being displayed as a modal, to catch modal removal from the DOM.
279
+
280
+ Object.defineProperty(dialog, 'open', {
281
+ set: this.setOpen.bind(this),
282
+ get: dialog.hasAttribute.bind(dialog, 'open')
283
+ });
284
+
285
+ this.backdrop_ = document.createElement('div');
286
+ this.backdrop_.className = 'backdrop';
287
+ this.backdrop_.addEventListener('mouseup' , this.backdropMouseEvent_.bind(this));
288
+ this.backdrop_.addEventListener('mousedown', this.backdropMouseEvent_.bind(this));
289
+ this.backdrop_.addEventListener('click' , this.backdropMouseEvent_.bind(this));
290
+ }
291
+
292
+ dialogPolyfillInfo.prototype = /** @type {HTMLDialogElement.prototype} */ ({
293
+
294
+ get dialog() {
295
+ return this.dialog_;
296
+ },
297
+
298
+ /**
299
+ * Maybe remove this dialog from the modal top layer. This is called when
300
+ * a modal dialog may no longer be tenable, e.g., when the dialog is no
301
+ * longer open or is no longer part of the DOM.
302
+ */
303
+ maybeHideModal: function() {
304
+ if (this.dialog_.hasAttribute('open') && isConnected(this.dialog_)) { return; }
305
+ this.downgradeModal();
306
+ },
307
+
308
+ /**
309
+ * Remove this dialog from the modal top layer, leaving it as a non-modal.
310
+ */
311
+ downgradeModal: function() {
312
+ if (!this.openAsModal_) { return; }
313
+ this.openAsModal_ = false;
314
+ this.dialog_.style.zIndex = '';
315
+
316
+ // This won't match the native <dialog> exactly because if the user set top on a centered
317
+ // polyfill dialog, that top gets thrown away when the dialog is closed. Not sure it's
318
+ // possible to polyfill this perfectly.
319
+ if (this.replacedStyleTop_) {
320
+ this.dialog_.style.top = '';
321
+ this.replacedStyleTop_ = false;
322
+ }
323
+
324
+ // Clear the backdrop and remove from the manager.
325
+ this.backdrop_.parentNode && this.backdrop_.parentNode.removeChild(this.backdrop_);
326
+ dialogPolyfill.dm.removeDialog(this);
327
+ },
328
+
329
+ /**
330
+ * @param {boolean} value whether to open or close this dialog
331
+ */
332
+ setOpen: function(value) {
333
+ if (value) {
334
+ this.dialog_.hasAttribute('open') || this.dialog_.setAttribute('open', '');
335
+ } else {
336
+ this.dialog_.removeAttribute('open');
337
+ this.maybeHideModal(); // nb. redundant with MutationObserver
338
+ }
339
+ },
340
+
341
+ /**
342
+ * Handles mouse events ('mouseup', 'mousedown', 'click') on the fake .backdrop element, redirecting them as if
343
+ * they were on the dialog itself.
344
+ *
345
+ * @param {!Event} e to redirect
346
+ */
347
+ backdropMouseEvent_: function(e) {
348
+ if (!this.dialog_.hasAttribute('tabindex')) {
349
+ // Clicking on the backdrop should move the implicit cursor, even if dialog cannot be
350
+ // focused. Create a fake thing to focus on. If the backdrop was _before_ the dialog, this
351
+ // would not be needed - clicks would move the implicit cursor there.
352
+ var fake = document.createElement('div');
353
+ this.dialog_.insertBefore(fake, this.dialog_.firstChild);
354
+ fake.tabIndex = -1;
355
+ fake.focus();
356
+ this.dialog_.removeChild(fake);
357
+ } else {
358
+ this.dialog_.focus();
359
+ }
360
+
361
+ var redirectedEvent = document.createEvent('MouseEvents');
362
+ redirectedEvent.initMouseEvent(e.type, e.bubbles, e.cancelable, window,
363
+ e.detail, e.screenX, e.screenY, e.clientX, e.clientY, e.ctrlKey,
364
+ e.altKey, e.shiftKey, e.metaKey, e.button, e.relatedTarget);
365
+ this.dialog_.dispatchEvent(redirectedEvent);
366
+ e.stopPropagation();
367
+ },
368
+
369
+ /**
370
+ * Focuses on the first focusable element within the dialog. This will always blur the current
371
+ * focus, even if nothing within the dialog is found.
372
+ */
373
+ focus_: function() {
374
+ // Find element with `autofocus` attribute, or fall back to the first form/tabindex control.
375
+ var target = this.dialog_.querySelector('[autofocus]:not([disabled])');
376
+ if (!target && this.dialog_.tabIndex >= 0) {
377
+ target = this.dialog_;
378
+ }
379
+ if (!target) {
380
+ target = findFocusableElementWithin(this.dialog_);
381
+ }
382
+ safeBlur(document.activeElement);
383
+ target && target.focus();
384
+ },
385
+
386
+ /**
387
+ * Sets the zIndex for the backdrop and dialog.
388
+ *
389
+ * @param {number} dialogZ
390
+ * @param {number} backdropZ
391
+ */
392
+ updateZIndex: function(dialogZ, backdropZ) {
393
+ if (dialogZ < backdropZ) {
394
+ throw new Error('dialogZ should never be < backdropZ');
395
+ }
396
+ this.dialog_.style.zIndex = dialogZ;
397
+ this.backdrop_.style.zIndex = backdropZ;
398
+ },
399
+
400
+ /**
401
+ * Shows the dialog. If the dialog is already open, this does nothing.
402
+ */
403
+ show: function() {
404
+ if (!this.dialog_.open) {
405
+ this.setOpen(true);
406
+ this.focus_();
407
+ }
408
+ },
409
+
410
+ /**
411
+ * Show this dialog modally.
412
+ */
413
+ showModal: function() {
414
+ if (this.dialog_.hasAttribute('open')) {
415
+ throw new Error('Failed to execute \'showModal\' on dialog: The element is already open, and therefore cannot be opened modally.');
416
+ }
417
+ if (!isConnected(this.dialog_)) {
418
+ throw new Error('Failed to execute \'showModal\' on dialog: The element is not in a Document.');
419
+ }
420
+ if (!dialogPolyfill.dm.pushDialog(this)) {
421
+ throw new Error('Failed to execute \'showModal\' on dialog: There are too many open modal dialogs.');
422
+ }
423
+
424
+ if (createsStackingContext(this.dialog_.parentElement)) {
425
+ console.warn('A dialog is being shown inside a stacking context. ' +
426
+ 'This may cause it to be unusable. For more information, see this link: ' +
427
+ 'https://github.com/GoogleChrome/dialog-polyfill/#stacking-context');
428
+ }
429
+
430
+ this.setOpen(true);
431
+ this.openAsModal_ = true;
432
+
433
+ // Optionally center vertically, relative to the current viewport.
434
+ if (dialogPolyfill.needsCentering(this.dialog_)) {
435
+ dialogPolyfill.reposition(this.dialog_);
436
+ this.replacedStyleTop_ = true;
437
+ } else {
438
+ this.replacedStyleTop_ = false;
439
+ }
440
+
441
+ // Insert backdrop.
442
+ this.dialog_.parentNode.insertBefore(this.backdrop_, this.dialog_.nextSibling);
443
+
444
+ // Focus on whatever inside the dialog.
445
+ this.focus_();
446
+ },
447
+
448
+ /**
449
+ * Closes this HTMLDialogElement. This is optional vs clearing the open
450
+ * attribute, however this fires a 'close' event.
451
+ *
452
+ * @param {string=} opt_returnValue to use as the returnValue
453
+ */
454
+ close: function(opt_returnValue) {
455
+ if (!this.dialog_.hasAttribute('open')) {
456
+ throw new Error('Failed to execute \'close\' on dialog: The element does not have an \'open\' attribute, and therefore cannot be closed.');
457
+ }
458
+ this.setOpen(false);
459
+
460
+ // Leave returnValue untouched in case it was set directly on the element
461
+ if (opt_returnValue !== undefined) {
462
+ this.dialog_.returnValue = opt_returnValue;
463
+ }
464
+
465
+ // Triggering "close" event for any attached listeners on the <dialog>.
466
+ var closeEvent = new supportCustomEvent('close', {
467
+ bubbles: false,
468
+ cancelable: false
469
+ });
470
+ safeDispatchEvent(this.dialog_, closeEvent);
471
+ }
472
+
473
+ });
474
+
475
+ var dialogPolyfill = {};
476
+
477
+ dialogPolyfill.reposition = function(element) {
478
+ var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
479
+ var topValue = scrollTop + (window.innerHeight - element.offsetHeight) / 2;
480
+ element.style.top = Math.max(scrollTop, topValue) + 'px';
481
+ };
482
+
483
+ dialogPolyfill.isInlinePositionSetByStylesheet = function(element) {
484
+ for (var i = 0; i < document.styleSheets.length; ++i) {
485
+ var styleSheet = document.styleSheets[i];
486
+ var cssRules = null;
487
+ // Some browsers throw on cssRules.
488
+ try {
489
+ cssRules = styleSheet.cssRules;
490
+ } catch (e) {}
491
+ if (!cssRules) { continue; }
492
+ for (var j = 0; j < cssRules.length; ++j) {
493
+ var rule = cssRules[j];
494
+ var selectedNodes = null;
495
+ // Ignore errors on invalid selector texts.
496
+ try {
497
+ selectedNodes = document.querySelectorAll(rule.selectorText);
498
+ } catch(e) {}
499
+ if (!selectedNodes || !inNodeList(selectedNodes, element)) {
500
+ continue;
501
+ }
502
+ var cssTop = rule.style.getPropertyValue('top');
503
+ var cssBottom = rule.style.getPropertyValue('bottom');
504
+ if ((cssTop && cssTop !== 'auto') || (cssBottom && cssBottom !== 'auto')) {
505
+ return true;
506
+ }
507
+ }
508
+ }
509
+ return false;
510
+ };
511
+
512
+ dialogPolyfill.needsCentering = function(dialog) {
513
+ var computedStyle = window.getComputedStyle(dialog);
514
+ if (computedStyle.position !== 'absolute') {
515
+ return false;
516
+ }
517
+
518
+ // We must determine whether the top/bottom specified value is non-auto. In
519
+ // WebKit/Blink, checking computedStyle.top == 'auto' is sufficient, but
520
+ // Firefox returns the used value. So we do this crazy thing instead: check
521
+ // the inline style and then go through CSS rules.
522
+ if ((dialog.style.top !== 'auto' && dialog.style.top !== '') ||
523
+ (dialog.style.bottom !== 'auto' && dialog.style.bottom !== '')) {
524
+ return false;
525
+ }
526
+ return !dialogPolyfill.isInlinePositionSetByStylesheet(dialog);
527
+ };
528
+
529
+ /**
530
+ * @param {!Element} element to force upgrade
531
+ */
532
+ dialogPolyfill.forceRegisterDialog = function(element) {
533
+ if (window.HTMLDialogElement || element.showModal) {
534
+ console.warn('This browser already supports <dialog>, the polyfill ' +
535
+ 'may not work correctly', element);
536
+ }
537
+ if (element.localName !== 'dialog') {
538
+ throw new Error('Failed to register dialog: The element is not a dialog.');
539
+ }
540
+ new dialogPolyfillInfo(/** @type {!HTMLDialogElement} */ (element));
541
+ };
542
+
543
+ /**
544
+ * @param {!Element} element to upgrade, if necessary
545
+ */
546
+ dialogPolyfill.registerDialog = function(element) {
547
+ if (!element.showModal) {
548
+ dialogPolyfill.forceRegisterDialog(element);
549
+ }
550
+ };
551
+
552
+ /**
553
+ * @constructor
554
+ */
555
+ dialogPolyfill.DialogManager = function() {
556
+ /** @type {!Array<!dialogPolyfillInfo>} */
557
+ this.pendingDialogStack = [];
558
+
559
+ var checkDOM = this.checkDOM_.bind(this);
560
+
561
+ // The overlay is used to simulate how a modal dialog blocks the document.
562
+ // The blocking dialog is positioned on top of the overlay, and the rest of
563
+ // the dialogs on the pending dialog stack are positioned below it. In the
564
+ // actual implementation, the modal dialog stacking is controlled by the
565
+ // top layer, where z-index has no effect.
566
+ this.overlay = document.createElement('div');
567
+ this.overlay.className = '_dialog_overlay';
568
+ this.overlay.addEventListener('click', function(e) {
569
+ this.forwardTab_ = undefined;
570
+ e.stopPropagation();
571
+ checkDOM([]); // sanity-check DOM
572
+ }.bind(this));
573
+
574
+ this.handleKey_ = this.handleKey_.bind(this);
575
+ this.handleFocus_ = this.handleFocus_.bind(this);
576
+
577
+ this.zIndexLow_ = 100000;
578
+ this.zIndexHigh_ = 100000 + 150;
579
+
580
+ this.forwardTab_ = undefined;
581
+
582
+ if ('MutationObserver' in window) {
583
+ this.mo_ = new MutationObserver(function(records) {
584
+ var removed = [];
585
+ records.forEach(function(rec) {
586
+ for (var i = 0, c; c = rec.removedNodes[i]; ++i) {
587
+ if (!(c instanceof Element)) {
588
+ continue;
589
+ } else if (c.localName === 'dialog') {
590
+ removed.push(c);
591
+ }
592
+ removed = removed.concat(c.querySelectorAll('dialog'));
593
+ }
594
+ });
595
+ removed.length && checkDOM(removed);
596
+ });
597
+ }
598
+ };
599
+
600
+ /**
601
+ * Called on the first modal dialog being shown. Adds the overlay and related
602
+ * handlers.
603
+ */
604
+ dialogPolyfill.DialogManager.prototype.blockDocument = function() {
605
+ document.documentElement.addEventListener('focus', this.handleFocus_, true);
606
+ document.addEventListener('keydown', this.handleKey_);
607
+ this.mo_ && this.mo_.observe(document, {childList: true, subtree: true});
608
+ };
609
+
610
+ /**
611
+ * Called on the first modal dialog being removed, i.e., when no more modal
612
+ * dialogs are visible.
613
+ */
614
+ dialogPolyfill.DialogManager.prototype.unblockDocument = function() {
615
+ document.documentElement.removeEventListener('focus', this.handleFocus_, true);
616
+ document.removeEventListener('keydown', this.handleKey_);
617
+ this.mo_ && this.mo_.disconnect();
618
+ };
619
+
620
+ /**
621
+ * Updates the stacking of all known dialogs.
622
+ */
623
+ dialogPolyfill.DialogManager.prototype.updateStacking = function() {
624
+ var zIndex = this.zIndexHigh_;
625
+
626
+ for (var i = 0, dpi; dpi = this.pendingDialogStack[i]; ++i) {
627
+ dpi.updateZIndex(--zIndex, --zIndex);
628
+ if (i === 0) {
629
+ this.overlay.style.zIndex = --zIndex;
630
+ }
631
+ }
632
+
633
+ // Make the overlay a sibling of the dialog itself.
634
+ var last = this.pendingDialogStack[0];
635
+ if (last) {
636
+ var p = last.dialog.parentNode || document.body;
637
+ p.appendChild(this.overlay);
638
+ } else if (this.overlay.parentNode) {
639
+ this.overlay.parentNode.removeChild(this.overlay);
640
+ }
641
+ };
642
+
643
+ /**
644
+ * @param {Element} candidate to check if contained or is the top-most modal dialog
645
+ * @return {boolean} whether candidate is contained in top dialog
646
+ */
647
+ dialogPolyfill.DialogManager.prototype.containedByTopDialog_ = function(candidate) {
648
+ while (candidate = findNearestDialog(candidate)) {
649
+ for (var i = 0, dpi; dpi = this.pendingDialogStack[i]; ++i) {
650
+ if (dpi.dialog === candidate) {
651
+ return i === 0; // only valid if top-most
652
+ }
653
+ }
654
+ candidate = candidate.parentElement;
655
+ }
656
+ return false;
657
+ };
658
+
659
+ dialogPolyfill.DialogManager.prototype.handleFocus_ = function(event) {
660
+ var target = event.composedPath ? event.composedPath()[0] : event.target;
661
+
662
+ if (this.containedByTopDialog_(target)) { return; }
663
+
664
+ if (document.activeElement === document.documentElement) { return; }
665
+
666
+ event.preventDefault();
667
+ event.stopPropagation();
668
+ safeBlur(/** @type {Element} */ (target));
669
+
670
+ if (this.forwardTab_ === undefined) { return; } // move focus only from a tab key
671
+
672
+ var dpi = this.pendingDialogStack[0];
673
+ var dialog = dpi.dialog;
674
+ var position = dialog.compareDocumentPosition(target);
675
+ if (position & Node.DOCUMENT_POSITION_PRECEDING) {
676
+ if (this.forwardTab_) {
677
+ // forward
678
+ dpi.focus_();
679
+ } else if (target !== document.documentElement) {
680
+ // backwards if we're not already focused on <html>
681
+ document.documentElement.focus();
682
+ }
683
+ }
684
+
685
+ return false;
686
+ };
687
+
688
+ dialogPolyfill.DialogManager.prototype.handleKey_ = function(event) {
689
+ this.forwardTab_ = undefined;
690
+ if (event.keyCode === 27) {
691
+ event.preventDefault();
692
+ event.stopPropagation();
693
+ var cancelEvent = new supportCustomEvent('cancel', {
694
+ bubbles: false,
695
+ cancelable: true
696
+ });
697
+ var dpi = this.pendingDialogStack[0];
698
+ if (dpi && safeDispatchEvent(dpi.dialog, cancelEvent)) {
699
+ dpi.dialog.close();
700
+ }
701
+ } else if (event.keyCode === 9) {
702
+ this.forwardTab_ = !event.shiftKey;
703
+ }
704
+ };
705
+
706
+ /**
707
+ * Finds and downgrades any known modal dialogs that are no longer displayed. Dialogs that are
708
+ * removed and immediately readded don't stay modal, they become normal.
709
+ *
710
+ * @param {!Array<!HTMLDialogElement>} removed that have definitely been removed
711
+ */
712
+ dialogPolyfill.DialogManager.prototype.checkDOM_ = function(removed) {
713
+ // This operates on a clone because it may cause it to change. Each change also calls
714
+ // updateStacking, which only actually needs to happen once. But who removes many modal dialogs
715
+ // at a time?!
716
+ var clone = this.pendingDialogStack.slice();
717
+ clone.forEach(function(dpi) {
718
+ if (removed.indexOf(dpi.dialog) !== -1) {
719
+ dpi.downgradeModal();
720
+ } else {
721
+ dpi.maybeHideModal();
722
+ }
723
+ });
724
+ };
725
+
726
+ /**
727
+ * @param {!dialogPolyfillInfo} dpi
728
+ * @return {boolean} whether the dialog was allowed
729
+ */
730
+ dialogPolyfill.DialogManager.prototype.pushDialog = function(dpi) {
731
+ var allowed = (this.zIndexHigh_ - this.zIndexLow_) / 2 - 1;
732
+ if (this.pendingDialogStack.length >= allowed) {
733
+ return false;
734
+ }
735
+ if (this.pendingDialogStack.unshift(dpi) === 1) {
736
+ this.blockDocument();
737
+ }
738
+ this.updateStacking();
739
+ return true;
740
+ };
741
+
742
+ /**
743
+ * @param {!dialogPolyfillInfo} dpi
744
+ */
745
+ dialogPolyfill.DialogManager.prototype.removeDialog = function(dpi) {
746
+ var index = this.pendingDialogStack.indexOf(dpi);
747
+ if (index === -1) { return; }
748
+
749
+ this.pendingDialogStack.splice(index, 1);
750
+ if (this.pendingDialogStack.length === 0) {
751
+ this.unblockDocument();
752
+ }
753
+ this.updateStacking();
754
+ };
755
+
756
+ dialogPolyfill.dm = new dialogPolyfill.DialogManager();
757
+ dialogPolyfill.formSubmitter = null;
758
+ dialogPolyfill.imagemapUseValue = null;
759
+
760
+ /**
761
+ * Installs global handlers, such as click listers and native method overrides. These are needed
762
+ * even if a no dialog is registered, as they deal with <form method="dialog">.
763
+ */
764
+ if (window.HTMLDialogElement === undefined) {
765
+
766
+ /**
767
+ * If HTMLFormElement translates method="DIALOG" into 'get', then replace the descriptor with
768
+ * one that returns the correct value.
769
+ */
770
+ var testForm = document.createElement('form');
771
+ testForm.setAttribute('method', 'dialog');
772
+ if (testForm.method !== 'dialog') {
773
+ var methodDescriptor = Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, 'method');
774
+ if (methodDescriptor) {
775
+ // nb. Some older iOS and older PhantomJS fail to return the descriptor. Don't do anything
776
+ // and don't bother to update the element.
777
+ var realGet = methodDescriptor.get;
778
+ methodDescriptor.get = function() {
779
+ if (isFormMethodDialog(this)) {
780
+ return 'dialog';
781
+ }
782
+ return realGet.call(this);
783
+ };
784
+ var realSet = methodDescriptor.set;
785
+ /** @this {HTMLElement} */
786
+ methodDescriptor.set = function(v) {
787
+ if (typeof v === 'string' && v.toLowerCase() === 'dialog') {
788
+ return this.setAttribute('method', v);
789
+ }
790
+ return realSet.call(this, v);
791
+ };
792
+ Object.defineProperty(HTMLFormElement.prototype, 'method', methodDescriptor);
793
+ }
794
+ }
795
+
796
+ /**
797
+ * Global 'click' handler, to capture the <input type="submit"> or <button> element which has
798
+ * submitted a <form method="dialog">. Needed as Safari and others don't report this inside
799
+ * document.activeElement.
800
+ */
801
+ document.addEventListener('click', function(ev) {
802
+ dialogPolyfill.formSubmitter = null;
803
+ dialogPolyfill.imagemapUseValue = null;
804
+ if (ev.defaultPrevented) { return; } // e.g. a submit which prevents default submission
805
+
806
+ var target = /** @type {Element} */ (ev.target);
807
+ if ('composedPath' in ev) {
808
+ var path = ev.composedPath();
809
+ target = path.shift() || target;
810
+ }
811
+ if (!target || !isFormMethodDialog(target.form)) { return; }
812
+
813
+ var valid = (target.type === 'submit' && ['button', 'input'].indexOf(target.localName) > -1);
814
+ if (!valid) {
815
+ if (!(target.localName === 'input' && target.type === 'image')) { return; }
816
+ // this is a <input type="image">, which can submit forms
817
+ dialogPolyfill.imagemapUseValue = ev.offsetX + ',' + ev.offsetY;
818
+ }
819
+
820
+ var dialog = findNearestDialog(target);
821
+ if (!dialog) { return; }
822
+
823
+ dialogPolyfill.formSubmitter = target;
824
+
825
+ }, false);
826
+
827
+ /**
828
+ * Global 'submit' handler. This handles submits of `method="dialog"` which are invalid, i.e.,
829
+ * outside a dialog. They get prevented.
830
+ */
831
+ document.addEventListener('submit', function(ev) {
832
+ var form = ev.target;
833
+ var dialog = findNearestDialog(form);
834
+ if (dialog) {
835
+ return; // ignore, handle there
836
+ }
837
+
838
+ var submitter = findFormSubmitter(ev);
839
+ var formmethod = submitter && submitter.getAttribute('formmethod') || form.getAttribute('method');
840
+ if (formmethod === 'dialog') {
841
+ ev.preventDefault();
842
+ }
843
+ });
844
+
845
+ /**
846
+ * Replace the native HTMLFormElement.submit() method, as it won't fire the
847
+ * submit event and give us a chance to respond.
848
+ */
849
+ var nativeFormSubmit = HTMLFormElement.prototype.submit;
850
+ var replacementFormSubmit = function () {
851
+ if (!isFormMethodDialog(this)) {
852
+ return nativeFormSubmit.call(this);
853
+ }
854
+ var dialog = findNearestDialog(this);
855
+ dialog && dialog.close();
856
+ };
857
+ HTMLFormElement.prototype.submit = replacementFormSubmit;
858
+ }
859
+
860
+ exports.default = dialogPolyfill;
861
+ //# sourceMappingURL=dialog-polyfill.esm-D8Polhcd.js.map
862
+
863
+ //# sourceMappingURL=dialog-polyfill.esm-D8Polhcd.js.map