@startinblox/core 0.18.1 → 0.19.0-beta.10

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