@oslokommune/punkt-react 16.20.0 → 16.21.1

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.
@@ -1,38 +1,75 @@
1
1
  import '@testing-library/jest-dom'
2
2
 
3
- import { render } from '@testing-library/react'
3
+ import { act, render } from '@testing-library/react'
4
4
  import { axe, toHaveNoViolations } from 'jest-axe'
5
+ import { vi } from 'vitest'
5
6
 
6
7
  import { PktLoader } from './Loader'
7
8
  expect.extend(toHaveNoViolations)
8
9
 
9
10
  describe('PktLoader', () => {
10
11
  describe('basic rendering', () => {
11
- it('renders correctly without any props', async () => {
12
+ it('renders correctly without any props', () => {
12
13
  const { container } = render(<PktLoader id="loader1" />)
13
- await window.customElements.whenDefined('pkt-loader')
14
14
 
15
- const element = container.querySelector('pkt-loader')
16
- expect(element).toBeInTheDocument()
15
+ const root = container.querySelector('.pkt-loader')
16
+ expect(root).toBeInTheDocument()
17
+ expect(root).toHaveAttribute('id', 'loader1')
18
+ expect(root).toHaveAttribute('role', 'status')
19
+ expect(root).toHaveAttribute('aria-busy', 'true')
17
20
  })
18
21
 
19
- it('renders with size and variant', async () => {
20
- const { container } = render(<PktLoader id="loader1" size="small" variant="rainbow" message="Loading.." />)
21
- await window.customElements.whenDefined('pkt-loader')
22
+ it('renders with size and variant', () => {
23
+ const { container } = render(
24
+ <PktLoader id="loader1" size="small" variant="rainbow" message="Loading.." />,
25
+ )
22
26
 
23
- const loaderBox = container.querySelector('pkt-loader')
24
- const loaderSize = loaderBox?.querySelector('.pkt-loader--small')
25
-
26
- expect(loaderSize).toBeInTheDocument()
27
- expect(loaderBox).toHaveTextContent('Loading..')
27
+ const root = container.querySelector('.pkt-loader')
28
+ expect(root).toHaveClass('pkt-loader--small')
29
+ expect(root?.querySelector('.pkt-loader__spinner')).toBeInTheDocument()
30
+ expect(root).toHaveTextContent('Loading..')
28
31
  })
29
32
 
30
- it('renders inline', async () => {
33
+ it('renders inline', () => {
31
34
  const { container } = render(<PktLoader size="medium" message="Loading.." inline />)
32
- await window.customElements.whenDefined('pkt-loader')
33
- const elementInline = container.querySelector('.pkt-loader--inline')
35
+ expect(container.querySelector('.pkt-loader--inline')).toBeInTheDocument()
36
+ })
37
+
38
+ it('hides children while loading and shows them when not loading', () => {
39
+ const { container, rerender } = render(
40
+ <PktLoader isLoading>
41
+ <span data-testid="child">Innhold</span>
42
+ </PktLoader>,
43
+ )
44
+
45
+ const slot = container.querySelector('.pkt-contents')
46
+ expect(slot).toHaveClass('pkt-hide')
47
+ expect(slot?.querySelector('[data-testid="child"]')).toBeInTheDocument()
48
+
49
+ rerender(
50
+ <PktLoader isLoading={false}>
51
+ <span data-testid="child">Innhold</span>
52
+ </PktLoader>,
53
+ )
54
+ expect(container.querySelector('.pkt-contents')).not.toHaveClass('pkt-hide')
55
+ expect(container.querySelector('.pkt-loader__spinner')).not.toBeInTheDocument()
56
+ })
57
+ })
58
+
59
+ describe('delay', () => {
60
+ it('defers the spinner until after the delay has elapsed', () => {
61
+ vi.useFakeTimers()
62
+ try {
63
+ const { container } = render(<PktLoader delay={500} />)
64
+ expect(container.querySelector('.pkt-loader__spinner')).not.toBeInTheDocument()
34
65
 
35
- expect(elementInline).toBeInTheDocument()
66
+ act(() => {
67
+ vi.advanceTimersByTime(500)
68
+ })
69
+ expect(container.querySelector('.pkt-loader__spinner')).toBeInTheDocument()
70
+ } finally {
71
+ vi.useRealTimers()
72
+ }
36
73
  })
37
74
  })
38
75
 
@@ -1,33 +1,123 @@
1
1
  'use client'
2
2
 
3
- import { createComponent } from '@lit/react'
4
- import { type IPktLoader as IPktElLoader, PktLoader as PktElLoader } from '@oslokommune/punkt-elements'
5
- // eslint-disable-next-line no-restricted-syntax -- React is required for createComponent
6
- import React, { FC, ForwardedRef, forwardRef, type ReactElement } from 'react'
3
+ import classNames from 'classnames'
4
+ import { forwardRef, HTMLAttributes, ReactNode, useEffect, useState } from 'react'
7
5
 
8
- import type { PktElConstructor, PktElType } from '@/interfaces/IPktElements'
6
+ import { PktIcon } from '../icon/Icon'
9
7
 
10
- type ExtendedLoader = IPktElLoader & PktElType
8
+ declare global {
9
+ interface Window {
10
+ pktAnimationPath?: string
11
+ }
12
+ }
11
13
 
12
- // eslint-disable-next-line @typescript-eslint/no-empty-object-type
13
- export interface IPktLoader extends ExtendedLoader {}
14
+ if (typeof window !== 'undefined') {
15
+ window.pktAnimationPath =
16
+ window.pktAnimationPath || 'https://punkt-cdn.oslo.kommune.no/latest/animations/'
17
+ }
14
18
 
15
- const LitComponent: FC<IPktLoader> = createComponent({
16
- tagName: 'pkt-loader',
17
- elementClass: PktElLoader as PktElConstructor<HTMLElement>,
18
- react: React,
19
- displayName: 'PktLoader',
20
- events: {},
21
- })
19
+ export type TPktLoaderVariant = 'blue' | 'rainbow' | 'shapes'
20
+ export type TPktLoaderSize = 'small' | 'medium' | 'large'
21
+
22
+ export interface IPktLoader extends HTMLAttributes<HTMLDivElement> {
23
+ /**
24
+ * Tid i millisekunder før loader vises. Nyttig når lastetiden kan være
25
+ * så kort at loader ikke trengs.
26
+ */
27
+ delay?: number
28
+ /**
29
+ * Vises loader inline eller som blokk.
30
+ */
31
+ inline?: boolean
32
+ /**
33
+ * Styrer om loader eller barnenoder vises. Når `false` vises barnenoder.
34
+ */
35
+ isLoading?: boolean
36
+ /**
37
+ * Meldingstekst som vises sammen med loader.
38
+ */
39
+ message?: string | null
40
+ /**
41
+ * Størrelse på loader. Standard er "medium".
42
+ */
43
+ size?: TPktLoaderSize
44
+ /**
45
+ * Loader-variant. Standard er "shapes" (Oslo-bølger). Andre er "blue" og "rainbow" (spinner-varianter).
46
+ */
47
+ variant?: TPktLoaderVariant
48
+ /**
49
+ * Overstyrer stien til loader-animasjoner.
50
+ */
51
+ loadingAnimationPath?: string
52
+ children?: ReactNode
53
+ }
22
54
 
23
- export const PktLoader: FC<IPktLoader> = forwardRef(
24
- ({ children, ...props }: IPktLoader, ref: ForwardedRef<HTMLElement>): ReactElement => {
25
- return (
26
- <LitComponent {...props} ref={ref}>
27
- <div className="pkt-contents">{children}</div>
28
- </LitComponent>
29
- )
55
+ const variantIcon = (variant: TPktLoaderVariant): string => {
56
+ switch (variant) {
57
+ case 'blue':
58
+ return 'spinner-blue'
59
+ case 'rainbow':
60
+ return 'spinner'
61
+ default:
62
+ return 'loader'
63
+ }
64
+ }
65
+
66
+ export const PktLoader = forwardRef<HTMLDivElement, IPktLoader>(function PktLoader(
67
+ {
68
+ delay = 0,
69
+ inline = false,
70
+ isLoading = true,
71
+ message = null,
72
+ size = 'medium',
73
+ variant = 'shapes',
74
+ loadingAnimationPath = typeof window !== 'undefined' ? window.pktAnimationPath : undefined,
75
+ className,
76
+ children,
77
+ ...rest
30
78
  },
31
- )
79
+ ref,
80
+ ) {
81
+ const [shouldDisplayLoader, setShouldDisplayLoader] = useState(delay === 0)
82
+
83
+ useEffect(() => {
84
+ if (delay > 0) {
85
+ setShouldDisplayLoader(false)
86
+ const handle = setTimeout(() => setShouldDisplayLoader(true), delay)
87
+ return () => clearTimeout(handle)
88
+ }
89
+ setShouldDisplayLoader(true)
90
+ }, [delay])
91
+
92
+ const classes = classNames(
93
+ 'pkt-loader',
94
+ inline ? 'pkt-loader--inline' : 'pkt-loader--box',
95
+ `pkt-loader--${size}`,
96
+ className,
97
+ )
98
+
99
+ return (
100
+ <div
101
+ {...rest}
102
+ ref={ref}
103
+ role="status"
104
+ aria-live="polite"
105
+ aria-busy={isLoading ? 'true' : 'false'}
106
+ className={classes}
107
+ >
108
+ {isLoading && shouldDisplayLoader && (
109
+ <div className="pkt-loader__spinner">
110
+ <PktIcon
111
+ name={variantIcon(variant)}
112
+ path={loadingAnimationPath}
113
+ className={`pkt-loader__svg pkt-loader__${variant}`}
114
+ />
115
+ {message && <p>{message}</p>}
116
+ </div>
117
+ )}
118
+ <div className={classNames('pkt-contents', isLoading && 'pkt-hide')}>{children}</div>
119
+ </div>
120
+ )
121
+ })
32
122
 
33
123
  PktLoader.displayName = 'PktLoader'
@@ -1,315 +0,0 @@
1
-
2
- if (typeof HTMLElement === 'undefined') { globalThis.HTMLElement = function() {} };
3
- if (typeof document === 'undefined') {
4
- globalThis.document = {
5
- createTreeWalker: function() {
6
- return {
7
- currentNode: null,
8
- nextNode: function() { return null; },
9
- previousNode: function() { return null; },
10
- parentNode: function() { return null; },
11
- firstChild: function() { return null; },
12
- lastChild: function() { return null; },
13
- previousSibling: function() { return null; },
14
- nextSibling: function() { return null; }
15
- };
16
- },
17
- getElementsByTagName: function() { return []; },
18
- querySelectorAll: function() { return []; },
19
- querySelector: function() {
20
- return {
21
- querySelectorAll: function() { return []; },
22
- getElementsByTagName: function() { return []; }
23
- };
24
- },
25
- }
26
- };
27
- if (typeof customElements === 'undefined') { globalThis.customElements = { define: function() {} }; }
28
- if (typeof window === 'undefined') { globalThis.window = globalThis; }
29
- if (typeof SVGElement === 'undefined') { globalThis.SVGElement = function() {} };
30
- if (typeof Element === 'undefined') {
31
- globalThis.Element = function() {};
32
- globalThis.Element.prototype.querySelectorAll = function() {
33
- return [];
34
- };
35
- }
36
- //#region ../elements/dist/dialog-polyfill.esm-0dVT8G1o.js
37
- var e = window.CustomEvent;
38
- (!e || typeof e == "object") && (e = function(e, t) {
39
- t ||= {};
40
- var n = document.createEvent("CustomEvent");
41
- return n.initCustomEvent(e, !!t.bubbles, !!t.cancelable, t.detail || null), n;
42
- }, e.prototype = window.Event.prototype);
43
- function t(e, t) {
44
- var n = "on" + t.type.toLowerCase();
45
- return typeof e[n] == "function" && e[n](t), e.dispatchEvent(t);
46
- }
47
- function n(e) {
48
- for (; e && e !== document.body;) {
49
- var t = window.getComputedStyle(e), n = function(e, n) {
50
- return !(t[e] === void 0 || t[e] === n);
51
- };
52
- if (t.opacity < 1 || n("zIndex", "auto") || n("transform", "none") || n("mixBlendMode", "normal") || n("filter", "none") || n("perspective", "none") || t.isolation === "isolate" || t.position === "fixed" || t.webkitOverflowScrolling === "touch") return !0;
53
- e = e.parentElement;
54
- }
55
- return !1;
56
- }
57
- function r(e) {
58
- for (; e;) {
59
- if (e.localName === "dialog") return e;
60
- e = e.parentElement ? e.parentElement : e.parentNode ? e.parentNode.host : null;
61
- }
62
- return null;
63
- }
64
- function i(e) {
65
- for (; e && e.shadowRoot && e.shadowRoot.activeElement;) e = e.shadowRoot.activeElement;
66
- e && e.blur && e !== document.body && e.blur();
67
- }
68
- function a(e, t) {
69
- for (var n = 0; n < e.length; ++n) if (e[n] === t) return !0;
70
- return !1;
71
- }
72
- function o(e) {
73
- return !e || !e.hasAttribute("method") ? !1 : e.getAttribute("method").toLowerCase() === "dialog";
74
- }
75
- function s(e) {
76
- var t = [
77
- "button",
78
- "input",
79
- "keygen",
80
- "select",
81
- "textarea"
82
- ].map(function(e) {
83
- return e + ":not([disabled])";
84
- });
85
- t.push("[tabindex]:not([disabled]):not([tabindex=\"\"])");
86
- var n = e.querySelector(t.join(", "));
87
- if (!n && "attachShadow" in Element.prototype) for (var r = e.querySelectorAll("*"), i = 0; i < r.length && !(r[i].tagName && r[i].shadowRoot && (n = s(r[i].shadowRoot), n)); i++);
88
- return n;
89
- }
90
- function c(e) {
91
- return e.isConnected || document.body.contains(e);
92
- }
93
- function l(e) {
94
- if (e.submitter) return e.submitter;
95
- var t = e.target;
96
- if (!(t instanceof HTMLFormElement)) return null;
97
- var n = f.formSubmitter;
98
- if (!n) {
99
- var r = e.target;
100
- n = ("getRootNode" in r && r.getRootNode() || document).activeElement;
101
- }
102
- return !n || n.form !== t ? null : n;
103
- }
104
- function u(e) {
105
- if (!e.defaultPrevented) {
106
- var t = e.target, n = f.imagemapUseValue, i = l(e);
107
- n === null && i && (n = i.value);
108
- var a = r(t);
109
- a && (i && i.getAttribute("formmethod") || t.getAttribute("method")) === "dialog" && (e.preventDefault(), n == null ? a.close() : a.close(n));
110
- }
111
- }
112
- function d(e) {
113
- if (this.dialog_ = e, this.replacedStyleTop_ = !1, this.openAsModal_ = !1, e.hasAttribute("role") || e.setAttribute("role", "dialog"), e.show = this.show.bind(this), e.showModal = this.showModal.bind(this), e.close = this.close.bind(this), e.addEventListener("submit", u, !1), "returnValue" in e || (e.returnValue = ""), "MutationObserver" in window) new MutationObserver(this.maybeHideModal.bind(this)).observe(e, {
114
- attributes: !0,
115
- attributeFilter: ["open"]
116
- });
117
- else {
118
- var t = !1, n = function() {
119
- t ? this.downgradeModal() : this.maybeHideModal(), t = !1;
120
- }.bind(this), r, i = function(i) {
121
- if (i.target === e) {
122
- var a = "DOMNodeRemoved";
123
- t |= i.type.substr(0, a.length) === a, window.clearTimeout(r), r = window.setTimeout(n, 0);
124
- }
125
- };
126
- [
127
- "DOMAttrModified",
128
- "DOMNodeRemoved",
129
- "DOMNodeRemovedFromDocument"
130
- ].forEach(function(t) {
131
- e.addEventListener(t, i);
132
- });
133
- }
134
- Object.defineProperty(e, "open", {
135
- set: this.setOpen.bind(this),
136
- get: e.hasAttribute.bind(e, "open")
137
- }), this.backdrop_ = document.createElement("div"), this.backdrop_.className = "backdrop", this.backdrop_.addEventListener("mouseup", this.backdropMouseEvent_.bind(this)), this.backdrop_.addEventListener("mousedown", this.backdropMouseEvent_.bind(this)), this.backdrop_.addEventListener("click", this.backdropMouseEvent_.bind(this));
138
- }
139
- d.prototype = {
140
- get dialog() {
141
- return this.dialog_;
142
- },
143
- maybeHideModal: function() {
144
- this.dialog_.hasAttribute("open") && c(this.dialog_) || this.downgradeModal();
145
- },
146
- downgradeModal: function() {
147
- this.openAsModal_ && (this.openAsModal_ = !1, this.dialog_.style.zIndex = "", this.replacedStyleTop_ &&= (this.dialog_.style.top = "", !1), this.backdrop_.parentNode && this.backdrop_.parentNode.removeChild(this.backdrop_), f.dm.removeDialog(this));
148
- },
149
- setOpen: function(e) {
150
- e ? this.dialog_.hasAttribute("open") || this.dialog_.setAttribute("open", "") : (this.dialog_.removeAttribute("open"), this.maybeHideModal());
151
- },
152
- backdropMouseEvent_: function(e) {
153
- if (this.dialog_.hasAttribute("tabindex")) this.dialog_.focus();
154
- else {
155
- var t = document.createElement("div");
156
- this.dialog_.insertBefore(t, this.dialog_.firstChild), t.tabIndex = -1, t.focus(), this.dialog_.removeChild(t);
157
- }
158
- var n = document.createEvent("MouseEvents");
159
- n.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), this.dialog_.dispatchEvent(n), e.stopPropagation();
160
- },
161
- focus_: function() {
162
- var e = this.dialog_.querySelector("[autofocus]:not([disabled])");
163
- !e && this.dialog_.tabIndex >= 0 && (e = this.dialog_), e ||= s(this.dialog_), i(document.activeElement), e && e.focus();
164
- },
165
- updateZIndex: function(e, t) {
166
- if (e < t) throw Error("dialogZ should never be < backdropZ");
167
- this.dialog_.style.zIndex = e, this.backdrop_.style.zIndex = t;
168
- },
169
- show: function() {
170
- this.dialog_.open || (this.setOpen(!0), this.focus_());
171
- },
172
- showModal: function() {
173
- if (this.dialog_.hasAttribute("open")) throw Error("Failed to execute 'showModal' on dialog: The element is already open, and therefore cannot be opened modally.");
174
- if (!c(this.dialog_)) throw Error("Failed to execute 'showModal' on dialog: The element is not in a Document.");
175
- if (!f.dm.pushDialog(this)) throw Error("Failed to execute 'showModal' on dialog: There are too many open modal dialogs.");
176
- n(this.dialog_.parentElement) && 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"), this.setOpen(!0), this.openAsModal_ = !0, f.needsCentering(this.dialog_) ? (f.reposition(this.dialog_), this.replacedStyleTop_ = !0) : this.replacedStyleTop_ = !1, this.dialog_.parentNode.insertBefore(this.backdrop_, this.dialog_.nextSibling), this.focus_();
177
- },
178
- close: function(n) {
179
- if (!this.dialog_.hasAttribute("open")) throw Error("Failed to execute 'close' on dialog: The element does not have an 'open' attribute, and therefore cannot be closed.");
180
- this.setOpen(!1), n !== void 0 && (this.dialog_.returnValue = n);
181
- var r = new e("close", {
182
- bubbles: !1,
183
- cancelable: !1
184
- });
185
- t(this.dialog_, r);
186
- }
187
- };
188
- var f = {};
189
- if (f.reposition = function(e) {
190
- var t = document.body.scrollTop || document.documentElement.scrollTop, n = t + (window.innerHeight - e.offsetHeight) / 2;
191
- e.style.top = Math.max(t, n) + "px";
192
- }, f.isInlinePositionSetByStylesheet = function(e) {
193
- for (var t = 0; t < document.styleSheets.length; ++t) {
194
- var n = document.styleSheets[t], r = null;
195
- try {
196
- r = n.cssRules;
197
- } catch {}
198
- if (r) for (var i = 0; i < r.length; ++i) {
199
- var o = r[i], s = null;
200
- try {
201
- s = document.querySelectorAll(o.selectorText);
202
- } catch {}
203
- if (!(!s || !a(s, e))) {
204
- var c = o.style.getPropertyValue("top"), l = o.style.getPropertyValue("bottom");
205
- if (c && c !== "auto" || l && l !== "auto") return !0;
206
- }
207
- }
208
- }
209
- return !1;
210
- }, f.needsCentering = function(e) {
211
- return window.getComputedStyle(e).position !== "absolute" || e.style.top !== "auto" && e.style.top !== "" || e.style.bottom !== "auto" && e.style.bottom !== "" ? !1 : !f.isInlinePositionSetByStylesheet(e);
212
- }, f.forceRegisterDialog = function(e) {
213
- if ((window.HTMLDialogElement || e.showModal) && console.warn("This browser already supports <dialog>, the polyfill may not work correctly", e), e.localName !== "dialog") throw Error("Failed to register dialog: The element is not a dialog.");
214
- new d(e);
215
- }, f.registerDialog = function(e) {
216
- e.showModal || f.forceRegisterDialog(e);
217
- }, f.DialogManager = function() {
218
- this.pendingDialogStack = [];
219
- var e = this.checkDOM_.bind(this);
220
- this.overlay = document.createElement("div"), this.overlay.className = "_dialog_overlay", this.overlay.addEventListener("click", function(t) {
221
- this.forwardTab_ = void 0, t.stopPropagation(), e([]);
222
- }.bind(this)), this.handleKey_ = this.handleKey_.bind(this), this.handleFocus_ = this.handleFocus_.bind(this), this.zIndexLow_ = 1e5, this.zIndexHigh_ = 100150, this.forwardTab_ = void 0, "MutationObserver" in window && (this.mo_ = new MutationObserver(function(t) {
223
- var n = [];
224
- t.forEach(function(e) {
225
- for (var t = 0, r; r = e.removedNodes[t]; ++t) {
226
- if (r instanceof Element) r.localName === "dialog" && n.push(r);
227
- else continue;
228
- n = n.concat(r.querySelectorAll("dialog"));
229
- }
230
- }), n.length && e(n);
231
- }));
232
- }, f.DialogManager.prototype.blockDocument = function() {
233
- document.documentElement.addEventListener("focus", this.handleFocus_, !0), document.addEventListener("keydown", this.handleKey_), this.mo_ && this.mo_.observe(document, {
234
- childList: !0,
235
- subtree: !0
236
- });
237
- }, f.DialogManager.prototype.unblockDocument = function() {
238
- document.documentElement.removeEventListener("focus", this.handleFocus_, !0), document.removeEventListener("keydown", this.handleKey_), this.mo_ && this.mo_.disconnect();
239
- }, f.DialogManager.prototype.updateStacking = function() {
240
- for (var e = this.zIndexHigh_, t = 0, n; n = this.pendingDialogStack[t]; ++t) n.updateZIndex(--e, --e), t === 0 && (this.overlay.style.zIndex = --e);
241
- var r = this.pendingDialogStack[0];
242
- r ? (r.dialog.parentNode || document.body).appendChild(this.overlay) : this.overlay.parentNode && this.overlay.parentNode.removeChild(this.overlay);
243
- }, f.DialogManager.prototype.containedByTopDialog_ = function(e) {
244
- for (; e = r(e);) {
245
- for (var t = 0, n; n = this.pendingDialogStack[t]; ++t) if (n.dialog === e) return t === 0;
246
- e = e.parentElement;
247
- }
248
- return !1;
249
- }, f.DialogManager.prototype.handleFocus_ = function(e) {
250
- var t = e.composedPath ? e.composedPath()[0] : e.target;
251
- if (!this.containedByTopDialog_(t) && document.activeElement !== document.documentElement && (e.preventDefault(), e.stopPropagation(), i(t), this.forwardTab_ !== void 0)) {
252
- var n = this.pendingDialogStack[0];
253
- return n.dialog.compareDocumentPosition(t) & Node.DOCUMENT_POSITION_PRECEDING && (this.forwardTab_ ? n.focus_() : t !== document.documentElement && document.documentElement.focus()), !1;
254
- }
255
- }, f.DialogManager.prototype.handleKey_ = function(n) {
256
- if (this.forwardTab_ = void 0, n.keyCode === 27) {
257
- n.preventDefault(), n.stopPropagation();
258
- var r = new e("cancel", {
259
- bubbles: !1,
260
- cancelable: !0
261
- }), i = this.pendingDialogStack[0];
262
- i && t(i.dialog, r) && i.dialog.close();
263
- } else n.keyCode === 9 && (this.forwardTab_ = !n.shiftKey);
264
- }, f.DialogManager.prototype.checkDOM_ = function(e) {
265
- this.pendingDialogStack.slice().forEach(function(t) {
266
- e.indexOf(t.dialog) === -1 ? t.maybeHideModal() : t.downgradeModal();
267
- });
268
- }, f.DialogManager.prototype.pushDialog = function(e) {
269
- var t = (this.zIndexHigh_ - this.zIndexLow_) / 2 - 1;
270
- return this.pendingDialogStack.length >= t ? !1 : (this.pendingDialogStack.unshift(e) === 1 && this.blockDocument(), this.updateStacking(), !0);
271
- }, f.DialogManager.prototype.removeDialog = function(e) {
272
- var t = this.pendingDialogStack.indexOf(e);
273
- t !== -1 && (this.pendingDialogStack.splice(t, 1), this.pendingDialogStack.length === 0 && this.unblockDocument(), this.updateStacking());
274
- }, f.dm = new f.DialogManager(), f.formSubmitter = null, f.imagemapUseValue = null, window.HTMLDialogElement === void 0) {
275
- var p = document.createElement("form");
276
- if (p.setAttribute("method", "dialog"), p.method !== "dialog") {
277
- var m = Object.getOwnPropertyDescriptor(HTMLFormElement.prototype, "method");
278
- if (m) {
279
- var h = m.get;
280
- m.get = function() {
281
- return o(this) ? "dialog" : h.call(this);
282
- };
283
- var g = m.set;
284
- m.set = function(e) {
285
- return typeof e == "string" && e.toLowerCase() === "dialog" ? this.setAttribute("method", e) : g.call(this, e);
286
- }, Object.defineProperty(HTMLFormElement.prototype, "method", m);
287
- }
288
- }
289
- document.addEventListener("click", function(e) {
290
- if (f.formSubmitter = null, f.imagemapUseValue = null, !e.defaultPrevented) {
291
- var t = e.target;
292
- if ("composedPath" in e && (t = e.composedPath().shift() || t), !(!t || !o(t.form))) {
293
- if (!(t.type === "submit" && ["button", "input"].indexOf(t.localName) > -1)) {
294
- if (!(t.localName === "input" && t.type === "image")) return;
295
- f.imagemapUseValue = e.offsetX + "," + e.offsetY;
296
- }
297
- r(t) && (f.formSubmitter = t);
298
- }
299
- }
300
- }, !1), document.addEventListener("submit", function(e) {
301
- var t = e.target;
302
- if (!r(t)) {
303
- var n = l(e);
304
- (n && n.getAttribute("formmethod") || t.getAttribute("method")) === "dialog" && e.preventDefault();
305
- }
306
- });
307
- var _ = HTMLFormElement.prototype.submit, v = function() {
308
- if (!o(this)) return _.call(this);
309
- var e = r(this);
310
- e && e.close();
311
- };
312
- HTMLFormElement.prototype.submit = v;
313
- }
314
- //#endregion
315
- export { f as default };