inclusive-elements 0.2.1 → 0.2.2

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,25 +1,36 @@
1
- var T = Object.defineProperty;
2
- var C = (a, o, t) => o in a ? T(a, o, { enumerable: !0, configurable: !0, writable: !0, value: t }) : a[o] = t;
3
- var s = (a, o, t) => (C(a, typeof o != "symbol" ? o + "" : o, t), t);
4
- import { move as E, hello as l, goodbye as u, cancel as k } from "hello-goodbye";
5
- import { isFocusable as D, focusable as g } from "tabbable";
1
+ var C = Object.defineProperty;
2
+ var T = (o, r, t) => r in o ? C(o, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[r] = t;
3
+ var s = (o, r, t) => (T(o, typeof r != "symbol" ? r + "" : r, t), t);
4
+ import { move as k, hello as h, goodbye as l, cancel as E } from "hello-goodbye";
5
+ import { isFocusable as D, focusable as A } from "tabbable";
6
6
  import { createFocusTrap as H } from "focus-trap";
7
- import { autoUpdate as M, computePosition as A, shift as L, flip as x, size as O } from "@floating-ui/dom";
7
+ import { autoUpdate as K, computePosition as L, shift as g, flip as x, size as M } from "@floating-ui/dom";
8
8
  const v = class extends HTMLElement {
9
9
  constructor() {
10
- super(...arguments);
10
+ super();
11
11
  s(this, "timeouts", /* @__PURE__ */ new Map());
12
12
  s(this, "index", 0);
13
+ new MutationObserver((e) => {
14
+ e.forEach((i) => {
15
+ i.addedNodes.forEach((n) => {
16
+ n instanceof HTMLElement && this.show(n);
17
+ });
18
+ });
19
+ }).observe(this, { childList: !0 });
13
20
  }
14
21
  connectedCallback() {
15
22
  this.hasAttribute("role") || this.setAttribute("role", "status"), this.hasAttribute("aria-live") || this.setAttribute("aria-live", "polite"), this.hasAttribute("aria-relevant") || this.setAttribute("aria-relevant", "additions");
23
+ for (const t of this.children)
24
+ this.show(t, { animate: !1 });
16
25
  }
17
26
  show(t, e = {}) {
18
- const i = e.key || String(this.index++);
19
- this.dismiss(i), t.dataset.key = i, E(this.children, () => {
20
- this.append(t), l(t);
27
+ const i = e.key || t.dataset.key || String(this.index++);
28
+ t.dataset.key = i, this.contains(t) ? h(t) : e.animate === !1 ? this.append(t) : k(this.children, () => {
29
+ this.append(t), h(t);
21
30
  });
22
- const n = typeof e.duration < "u" ? Number(e.duration) : v.duration;
31
+ const n = Number(
32
+ e.duration !== void 0 ? e.duration : t.dataset.duration || v.duration
33
+ );
23
34
  return n > 0 && (this.startTimeout(t, n), t.addEventListener("mouseenter", this.clearTimeout.bind(this, t)), t.addEventListener("focusin", this.clearTimeout.bind(this, t)), t.addEventListener(
24
35
  "mouseleave",
25
36
  this.startTimeout.bind(this, t, n)
@@ -37,8 +48,8 @@ const v = class extends HTMLElement {
37
48
  });
38
49
  return;
39
50
  }
40
- E(this.children, () => {
41
- u(t, {
51
+ k(this.children, () => {
52
+ l(t, {
42
53
  finish: () => this.removeChild(t)
43
54
  });
44
55
  }), this.clearTimeout(t);
@@ -118,9 +129,9 @@ const w = class extends HTMLElement {
118
129
  i < 0 && (i = e.length - 1), i >= e.length && (i = 0), (n = e[i]) == null || n.focus();
119
130
  }
120
131
  };
121
- let m = w;
122
- s(m, "searchDelay", 800);
123
- const d = class extends HTMLElement {
132
+ let b = w;
133
+ s(b, "searchDelay", 800);
134
+ const c = class extends HTMLElement {
124
135
  constructor() {
125
136
  super();
126
137
  s(this, "focusTrap");
@@ -133,7 +144,7 @@ const d = class extends HTMLElement {
133
144
  const e = this.attachShadow({ mode: "open" });
134
145
  e.appendChild(t.content.cloneNode(!0)), this.backdrop.addEventListener("click", () => {
135
146
  var i;
136
- this.hasAttribute("static") ? (i = d.attention) == null || i.call(d, e.children[1]) : this.close();
147
+ this.hasAttribute("static") ? (i = c.attention) == null || i.call(c, e.children[1]) : this.close();
137
148
  }), this.focusTrap = H(this, {
138
149
  escapeDeactivates: !1,
139
150
  allowOutsideClick: !0
@@ -143,8 +154,8 @@ const d = class extends HTMLElement {
143
154
  return ["open"];
144
155
  }
145
156
  connectedCallback() {
146
- var t, e, i, n, r, y;
147
- this.connected = !0, (t = this.content) != null && t.hasAttribute("role") || (e = this.content) == null || e.setAttribute("role", "dialog"), (i = this.content) != null && i.hasAttribute("aria-modal") || (n = this.content) == null || n.setAttribute("aria-modal", "true"), (r = this.content) != null && r.hasAttribute("tabindex") || (y = this.content) == null || y.setAttribute("tabindex", "-1"), this.addEventListener("keydown", (p) => {
157
+ var t, e, i, n, a, y;
158
+ this.connected = !0, (t = this.content) != null && t.hasAttribute("role") || (e = this.content) == null || e.setAttribute("role", "dialog"), (i = this.content) != null && i.hasAttribute("aria-modal") || (n = this.content) == null || n.setAttribute("aria-modal", "true"), (a = this.content) != null && a.hasAttribute("tabindex") || (y = this.content) == null || y.setAttribute("tabindex", "-1"), this.addEventListener("keydown", (p) => {
148
159
  p.key === "Escape" && this.open && (p.preventDefault(), p.stopPropagation(), this.close());
149
160
  }), this.open && this.wasOpened();
150
161
  }
@@ -168,11 +179,11 @@ const d = class extends HTMLElement {
168
179
  }
169
180
  wasOpened() {
170
181
  var t, e;
171
- this.hidden = !1, l(this), (t = this.focusTrap) == null || t.activate(), (e = this.querySelector("[autofocus]")) == null || e.focus(), this.dispatchEvent(new Event("open"));
182
+ this.hidden = !1, h(this), (t = this.focusTrap) == null || t.activate(), (e = this.querySelector("[autofocus]")) == null || e.focus(), this.dispatchEvent(new Event("open"));
172
183
  }
173
184
  wasClosed() {
174
185
  var t;
175
- (t = this.focusTrap) == null || t.deactivate(), u(this, {
186
+ (t = this.focusTrap) == null || t.deactivate(), l(this, {
176
187
  finish: () => this.hidden = !0
177
188
  }), this.dispatchEvent(new Event("close"));
178
189
  }
@@ -184,8 +195,8 @@ const d = class extends HTMLElement {
184
195
  return this.firstElementChild;
185
196
  }
186
197
  };
187
- let b = d;
188
- s(b, "attention", (t) => t.animate(
198
+ let m = c;
199
+ s(m, "attention", (t) => t.animate(
189
200
  [
190
201
  { transform: "scale(1)" },
191
202
  { transform: "scale(1.1)" },
@@ -193,10 +204,29 @@ s(b, "attention", (t) => t.animate(
193
204
  ],
194
205
  300
195
206
  ));
196
- class F extends HTMLElement {
207
+ function O(o) {
208
+ return o.altKey || o.ctrlKey || o.metaKey || o.shiftKey || o.button !== void 0 && o.button !== 0;
209
+ }
210
+ class $ extends HTMLElement {
197
211
  constructor() {
198
212
  super();
199
213
  s(this, "cleanup");
214
+ s(this, "onButtonClick", (t) => {
215
+ !O(t) && !this.disabled && (this.open = !this.open, t.preventDefault());
216
+ });
217
+ s(this, "onButtonKeyDown", (t) => {
218
+ var e;
219
+ t.key === "ArrowDown" && !this.disabled && (t.preventDefault(), this.open = !0, (e = A(this.content)[0]) == null || e.focus());
220
+ });
221
+ s(this, "onKeyDown", (t) => {
222
+ t.key === "Escape" && this.open && (t.preventDefault(), t.stopPropagation(), this.open = !1, this.button.focus());
223
+ });
224
+ s(this, "onFocusOut", (t) => {
225
+ (!(t.relatedTarget instanceof Node) || !this.contains(t.relatedTarget)) && (this.open = !1);
226
+ });
227
+ s(this, "onContentClick", (t) => {
228
+ t.target instanceof Element && t.target.closest("[role=menuitem], [role=menuitemradio]") && (this.open = !1, this.button.focus());
229
+ });
200
230
  const t = document.createElement("template");
201
231
  t.innerHTML = `
202
232
  <div part="backdrop" hidden style="position: fixed; top: 0; left: 0; right: 0; bottom: 0"></div>
@@ -209,21 +239,10 @@ class F extends HTMLElement {
209
239
  connectedCallback() {
210
240
  this.backdrop.hidden = !0, this.content.hidden = !0, this.open = !1, this.button.setAttribute("aria-expanded", "false"), setTimeout(() => {
211
241
  this.content.getAttribute("role") === "menu" && this.button.setAttribute("aria-haspopup", "true");
212
- }), this.button.addEventListener("click", () => {
213
- this.open = !this.open;
214
- }), this.button.addEventListener("keydown", (t) => {
215
- var e;
216
- t.key === "ArrowDown" && (t.preventDefault(), this.open = !0, (e = g(this.content)[0]) == null || e.focus());
217
- }), this.addEventListener("keydown", (t) => {
218
- t.key === "Escape" && this.open && (t.preventDefault(), t.stopPropagation(), this.open = !1, this.button.focus());
219
- }), this.addEventListener("focusout", (t) => {
220
- (!(t.relatedTarget instanceof Node) || !this.contains(t.relatedTarget)) && (this.open = !1);
221
- }), this.content.addEventListener("click", (t) => {
222
- t.target instanceof Element && t.target.closest("[role=menuitem], [role=menuitemradio]") && (this.open = !1, this.button.focus());
223
- });
242
+ }), this.button.addEventListener("click", this.onButtonClick), this.button.addEventListener("keydown", this.onButtonKeyDown), this.addEventListener("keydown", this.onKeyDown), this.addEventListener("focusout", this.onFocusOut), this.content.addEventListener("click", this.onContentClick);
224
243
  }
225
244
  disconnectedCallback() {
226
- k(this.backdrop), k(this.content);
245
+ E(this.backdrop), E(this.content), this.button.removeAttribute("aria-expanded"), this.button.removeAttribute("aria-haspopup"), this.button.removeEventListener("click", this.onButtonClick), this.button.removeEventListener("keydown", this.onButtonKeyDown), this.removeEventListener("keydown", this.onKeyDown), this.removeEventListener("focusout", this.onFocusOut), this.content.removeEventListener("click", this.onContentClick);
227
246
  }
228
247
  get open() {
229
248
  return this.hasAttribute("open");
@@ -231,22 +250,25 @@ class F extends HTMLElement {
231
250
  set open(t) {
232
251
  t ? this.setAttribute("open", "") : this.removeAttribute("open");
233
252
  }
253
+ get disabled() {
254
+ return this.hasAttribute("disabled");
255
+ }
234
256
  attributeChangedCallback(t, e, i) {
235
257
  t === "open" && (i !== null ? this.wasOpened() : this.wasClosed());
236
258
  }
237
259
  wasOpened() {
238
260
  if (!this.content.hidden)
239
261
  return;
240
- this.content.hidden = !1, this.backdrop.hidden = !1, l(this.content), l(this.backdrop), this.button.setAttribute("aria-expanded", "true"), this.content.style.position = "absolute", this.cleanup = M(
262
+ this.content.hidden = !1, this.backdrop.hidden = !1, h(this.content), h(this.backdrop), this.button.setAttribute("aria-expanded", "true"), this.content.style.position = "absolute", this.cleanup = K(
241
263
  this.button,
242
264
  this.content,
243
265
  () => {
244
- A(this.button, this.content, {
266
+ L(this.button, this.content, {
245
267
  placement: this.getAttribute("placement") || "bottom",
246
268
  middleware: [
247
- L(),
269
+ g(),
248
270
  x(),
249
- O({
271
+ M({
250
272
  apply: ({ availableWidth: e, availableHeight: i }) => {
251
273
  Object.assign(this.content.style, {
252
274
  maxWidth: "",
@@ -271,9 +293,9 @@ class F extends HTMLElement {
271
293
  }
272
294
  wasClosed() {
273
295
  var t;
274
- this.content.hidden || (this.button.setAttribute("aria-expanded", "false"), (t = this.cleanup) == null || t.call(this), u(this.backdrop, {
296
+ this.content.hidden || (this.button.setAttribute("aria-expanded", "false"), (t = this.cleanup) == null || t.call(this), l(this.backdrop, {
275
297
  finish: () => this.backdrop.hidden = !0
276
- }), u(this.content, {
298
+ }), l(this.content, {
277
299
  finish: () => this.content.hidden = !0
278
300
  }), this.dispatchEvent(new Event("close")));
279
301
  }
@@ -288,7 +310,7 @@ class F extends HTMLElement {
288
310
  return this.children[1];
289
311
  }
290
312
  }
291
- class $ extends HTMLElement {
313
+ class P extends HTMLElement {
292
314
  constructor() {
293
315
  super(...arguments);
294
316
  s(this, "onInitialFocus", () => {
@@ -300,8 +322,8 @@ class $ extends HTMLElement {
300
322
  const e = this.controls, i = this.controls.length, n = e.indexOf(t.target);
301
323
  if (n === -1)
302
324
  return;
303
- let r = 0;
304
- t.key === "ArrowLeft" && (r = n - 1), t.key === "ArrowRight" && (r = n + 1), t.key === "End" && (r = i - 1), r < 0 && (r = i - 1), r > i - 1 && (r = 0), this.focusControlAtIndex(r), t.preventDefault();
325
+ let a = 0;
326
+ t.key === "ArrowLeft" && (a = n - 1), t.key === "ArrowRight" && (a = n + 1), t.key === "End" && (a = i - 1), a < 0 && (a = i - 1), a > i - 1 && (a = 0), this.focusControlAtIndex(a), t.preventDefault();
305
327
  });
306
328
  }
307
329
  connectedCallback() {
@@ -316,10 +338,10 @@ class $ extends HTMLElement {
316
338
  });
317
339
  }
318
340
  get controls() {
319
- return g(this);
341
+ return A(this);
320
342
  }
321
343
  }
322
- const c = class extends HTMLElement {
344
+ const u = class extends HTMLElement {
323
345
  constructor() {
324
346
  super(...arguments);
325
347
  s(this, "parent");
@@ -356,9 +378,9 @@ const c = class extends HTMLElement {
356
378
  if (this.disabled)
357
379
  return;
358
380
  const t = this.createTooltip();
359
- clearTimeout(this.timeout), this.showing || (t.hidden = !1, l(t), this.showing = !0), t.innerHTML !== this.innerHTML && (t.innerHTML = this.innerHTML), t.style.position = "absolute", A(this.parent, t, {
360
- placement: this.getAttribute("placement") || c.placement,
361
- middleware: [L(), x()]
381
+ clearTimeout(this.timeout), this.showing || (t.hidden = !1, h(t), this.showing = !0), t.innerHTML !== this.innerHTML && (t.innerHTML = this.innerHTML), t.style.position = "absolute", L(this.parent, t, {
382
+ placement: this.getAttribute("placement") || u.placement,
383
+ middleware: [g(), x()]
362
384
  }).then(({ x: e, y: i, placement: n }) => {
363
385
  Object.assign(t.style, {
364
386
  left: `${e}px`,
@@ -367,7 +389,7 @@ const c = class extends HTMLElement {
367
389
  });
368
390
  }
369
391
  hide() {
370
- clearTimeout(this.timeout), this.showing && (this.showing = !1, u(this.tooltip, {
392
+ clearTimeout(this.timeout), this.showing && (this.showing = !1, l(this.tooltip, {
371
393
  finish: () => {
372
394
  this.tooltip && (this.tooltip.hidden = !0);
373
395
  }
@@ -378,23 +400,23 @@ const c = class extends HTMLElement {
378
400
  const e = parseInt(this.getAttribute("delay") || "");
379
401
  this.timeout = window.setTimeout(
380
402
  t.bind(this),
381
- isNaN(e) ? c.delay : e
403
+ isNaN(e) ? u.delay : e
382
404
  );
383
405
  }
384
406
  createTooltip() {
385
- return this.tooltip || (this.tooltip = document.createElement("div"), this.tooltip.className = this.getAttribute("tooltip-class") || c.tooltipClass, this.tooltip.hidden = !0, this.tooltip.addEventListener("mouseenter", this.show.bind(this)), this.tooltip.addEventListener(
407
+ return this.tooltip || (this.tooltip = document.createElement("div"), this.tooltip.className = this.getAttribute("tooltip-class") || u.tooltipClass, this.tooltip.hidden = !0, this.tooltip.addEventListener("mouseenter", this.show.bind(this)), this.tooltip.addEventListener(
386
408
  "mouseleave",
387
409
  this.afterDelay.bind(this, this.hide)
388
410
  ), document.body.appendChild(this.tooltip)), this.tooltip;
389
411
  }
390
412
  };
391
- let h = c;
392
- s(h, "delay", 100), s(h, "placement", "top"), s(h, "tooltipClass", "tooltip");
413
+ let d = u;
414
+ s(d, "delay", 100), s(d, "placement", "top"), s(d, "tooltipClass", "tooltip");
393
415
  export {
394
416
  f as AlertsElement,
395
- m as MenuElement,
396
- b as ModalElement,
397
- F as PopupElement,
398
- $ as ToolbarElement,
399
- h as TooltipElement
417
+ b as MenuElement,
418
+ m as ModalElement,
419
+ $ as PopupElement,
420
+ P as ToolbarElement,
421
+ d as TooltipElement
400
422
  };
@@ -1,11 +1,13 @@
1
1
  export declare type AlertOptions = {
2
2
  key?: string;
3
3
  duration?: number;
4
+ animate?: boolean;
4
5
  };
5
6
  export default class AlertsElement extends HTMLElement {
6
7
  static duration: number;
7
8
  private timeouts;
8
9
  private index;
10
+ constructor();
9
11
  connectedCallback(): void;
10
12
  show(el: HTMLElement, options?: AlertOptions): string;
11
13
  dismiss(el: HTMLElement): void;
@@ -4,8 +4,14 @@ export default class PopupElement extends HTMLElement {
4
4
  constructor();
5
5
  connectedCallback(): void;
6
6
  disconnectedCallback(): void;
7
+ private onButtonClick;
8
+ private onButtonKeyDown;
9
+ private onKeyDown;
10
+ private onFocusOut;
11
+ private onContentClick;
7
12
  get open(): boolean;
8
13
  set open(val: boolean);
14
+ get disabled(): boolean;
9
15
  attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
10
16
  private wasOpened;
11
17
  private wasClosed;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Determine whether the user is trying to open a link in a new tab.
3
+ */
4
+ export declare function shouldOpenInNewTab(e: MouseEvent): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inclusive-elements",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Accessible, lightweight, unstyled implementations of common UI controls.",
5
5
  "module": "dist/inclusive-elements.js",
6
6
  "type": "module",