@startinblox/core 0.19.0-beta.2 → 0.19.0-beta.21

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