inclusive-elements 0.2.2 → 0.3.0

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,11 +1,32 @@
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
- import { createFocusTrap as H } from "focus-trap";
7
- import { autoUpdate as K, computePosition as L, shift as g, flip as x, size as M } from "@floating-ui/dom";
8
- const v = class extends HTMLElement {
1
+ var T = Object.defineProperty;
2
+ var D = (o, r, t) => r in o ? T(o, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[r] = t;
3
+ var s = (o, r, t) => (D(o, typeof r != "symbol" ? r + "" : r, t), t);
4
+ import { move as k, hello as h, goodbye as d, cancel as v } from "hello-goodbye";
5
+ import { isFocusable as H, focusable as A } from "tabbable";
6
+ import { createFocusTrap as O } from "focus-trap";
7
+ import { autoUpdate as M, computePosition as g, shift as L, flip as x, size as K } from "@floating-ui/dom";
8
+ class I extends HTMLElement {
9
+ constructor() {
10
+ super(...arguments);
11
+ s(this, "onOpen", (t) => {
12
+ this.querySelectorAll(
13
+ ":scope > ui-disclosure"
14
+ ).forEach((e) => {
15
+ e.open = e === t.target, this.required && e.toggleAttribute("disabled", e === t.target);
16
+ });
17
+ });
18
+ }
19
+ connectedCallback() {
20
+ this.addEventListener("open", this.onOpen, { capture: !0 });
21
+ }
22
+ disconnectedCallback() {
23
+ this.removeEventListener("open", this.onOpen, { capture: !0 });
24
+ }
25
+ get required() {
26
+ return this.hasAttribute("required");
27
+ }
28
+ }
29
+ const w = class extends HTMLElement {
9
30
  constructor() {
10
31
  super();
11
32
  s(this, "timeouts", /* @__PURE__ */ new Map());
@@ -29,7 +50,7 @@ const v = class extends HTMLElement {
29
50
  this.append(t), h(t);
30
51
  });
31
52
  const n = Number(
32
- e.duration !== void 0 ? e.duration : t.dataset.duration || v.duration
53
+ e.duration !== void 0 ? e.duration : t.dataset.duration || w.duration
33
54
  );
34
55
  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(
35
56
  "mouseleave",
@@ -49,7 +70,7 @@ const v = class extends HTMLElement {
49
70
  return;
50
71
  }
51
72
  k(this.children, () => {
52
- l(t, {
73
+ d(t, {
53
74
  finish: () => this.removeChild(t)
54
75
  });
55
76
  }), this.clearTimeout(t);
@@ -83,9 +104,55 @@ const v = class extends HTMLElement {
83
104
  this.timeouts.has(t) && clearTimeout(this.timeouts.get(t));
84
105
  }
85
106
  };
86
- let f = v;
87
- s(f, "duration", 1e4);
88
- const w = class extends HTMLElement {
107
+ let b = w;
108
+ s(b, "duration", 1e4);
109
+ function C(o) {
110
+ return o.altKey || o.ctrlKey || o.metaKey || o.shiftKey || o.button !== void 0 && o.button !== 0;
111
+ }
112
+ class $ extends HTMLElement {
113
+ constructor() {
114
+ super(...arguments);
115
+ s(this, "onButtonClick", (t) => {
116
+ !C(t) && !this.disabled && (this.open = !this.open, t.preventDefault());
117
+ });
118
+ }
119
+ static get observedAttributes() {
120
+ return ["open"];
121
+ }
122
+ connectedCallback() {
123
+ this.content.hidden = !this.open, this.button.setAttribute("aria-expanded", String(this.open)), this.button.addEventListener("click", this.onButtonClick);
124
+ }
125
+ disconnectedCallback() {
126
+ v(this.content), this.button.removeAttribute("aria-expanded"), this.button.removeEventListener("click", this.onButtonClick);
127
+ }
128
+ get open() {
129
+ return this.hasAttribute("open");
130
+ }
131
+ set open(t) {
132
+ t ? this.setAttribute("open", "") : this.removeAttribute("open");
133
+ }
134
+ get disabled() {
135
+ return this.hasAttribute("disabled");
136
+ }
137
+ attributeChangedCallback(t, e, i) {
138
+ t === "open" && (i !== null ? this.wasOpened() : this.wasClosed());
139
+ }
140
+ wasOpened() {
141
+ this.content.hidden && (this.content.hidden = !1, h(this.content), this.button.setAttribute("aria-expanded", "true"), this.dispatchEvent(new Event("open")));
142
+ }
143
+ wasClosed() {
144
+ this.content.hidden || (this.button.setAttribute("aria-expanded", "false"), d(this.content, {
145
+ finish: () => this.content.hidden = !0
146
+ }), this.dispatchEvent(new Event("close")));
147
+ }
148
+ get button() {
149
+ return this.querySelector("button, [role=button]");
150
+ }
151
+ get content() {
152
+ return this.children[1];
153
+ }
154
+ }
155
+ const y = class extends HTMLElement {
89
156
  constructor() {
90
157
  super(...arguments);
91
158
  s(this, "search", "");
@@ -102,7 +169,7 @@ const w = class extends HTMLElement {
102
169
  }
103
170
  t.key.length > 1 || t.ctrlKey || t.metaKey || t.altKey || (this.search += t.key.toLowerCase(), t.preventDefault(), clearTimeout(this.searchTimeout), this.searchTimeout = window.setTimeout(() => {
104
171
  this.search = "";
105
- }, w.searchDelay), this.items.some((e) => {
172
+ }, y.searchDelay), this.items.some((e) => {
106
173
  var i;
107
174
  return ((i = e.textContent) == null ? void 0 : i.trim().toLowerCase().indexOf(this.search)) === 0 ? (e.focus(), !0) : !1;
108
175
  }));
@@ -120,7 +187,7 @@ const w = class extends HTMLElement {
120
187
  get items() {
121
188
  return Array.from(
122
189
  this.querySelectorAll("[role^=menuitem]")
123
- ).filter((t) => D(t));
190
+ ).filter((t) => H(t));
124
191
  }
125
192
  navigate(t) {
126
193
  var n;
@@ -129,9 +196,9 @@ const w = class extends HTMLElement {
129
196
  i < 0 && (i = e.length - 1), i >= e.length && (i = 0), (n = e[i]) == null || n.focus();
130
197
  }
131
198
  };
132
- let b = w;
133
- s(b, "searchDelay", 800);
134
- const c = class extends HTMLElement {
199
+ let f = y;
200
+ s(f, "searchDelay", 800);
201
+ const u = class extends HTMLElement {
135
202
  constructor() {
136
203
  super();
137
204
  s(this, "focusTrap");
@@ -144,18 +211,19 @@ const c = class extends HTMLElement {
144
211
  const e = this.attachShadow({ mode: "open" });
145
212
  e.appendChild(t.content.cloneNode(!0)), this.backdrop.addEventListener("click", () => {
146
213
  var i;
147
- this.hasAttribute("static") ? (i = c.attention) == null || i.call(c, e.children[1]) : this.close();
148
- }), this.focusTrap = H(this, {
214
+ this.hasAttribute("static") ? (i = u.attention) == null || i.call(u, e.children[1]) : this.close();
215
+ }), this.focusTrap = O(this, {
149
216
  escapeDeactivates: !1,
150
- allowOutsideClick: !0
217
+ allowOutsideClick: !0,
218
+ preventScroll: !0
151
219
  });
152
220
  }
153
221
  static get observedAttributes() {
154
222
  return ["open"];
155
223
  }
156
224
  connectedCallback() {
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) => {
225
+ var t, e, i, n, a, E;
226
+ 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") || (E = this.content) == null || E.setAttribute("tabindex", "-1"), this.addEventListener("keydown", (p) => {
159
227
  p.key === "Escape" && this.open && (p.preventDefault(), p.stopPropagation(), this.close());
160
228
  }), this.open && this.wasOpened();
161
229
  }
@@ -183,7 +251,7 @@ const c = class extends HTMLElement {
183
251
  }
184
252
  wasClosed() {
185
253
  var t;
186
- (t = this.focusTrap) == null || t.deactivate(), l(this, {
254
+ (t = this.focusTrap) == null || t.deactivate(), d(this, {
187
255
  finish: () => this.hidden = !0
188
256
  }), this.dispatchEvent(new Event("close"));
189
257
  }
@@ -195,7 +263,7 @@ const c = class extends HTMLElement {
195
263
  return this.firstElementChild;
196
264
  }
197
265
  };
198
- let m = c;
266
+ let m = u;
199
267
  s(m, "attention", (t) => t.animate(
200
268
  [
201
269
  { transform: "scale(1)" },
@@ -204,15 +272,12 @@ s(m, "attention", (t) => t.animate(
204
272
  ],
205
273
  300
206
274
  ));
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 {
275
+ class P extends HTMLElement {
211
276
  constructor() {
212
277
  super();
213
278
  s(this, "cleanup");
214
279
  s(this, "onButtonClick", (t) => {
215
- !O(t) && !this.disabled && (this.open = !this.open, t.preventDefault());
280
+ !C(t) && !this.disabled && (this.open = !this.open, t.preventDefault());
216
281
  });
217
282
  s(this, "onButtonKeyDown", (t) => {
218
283
  var e;
@@ -242,7 +307,7 @@ class $ extends HTMLElement {
242
307
  }), 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);
243
308
  }
244
309
  disconnectedCallback() {
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);
310
+ v(this.backdrop), v(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);
246
311
  }
247
312
  get open() {
248
313
  return this.hasAttribute("open");
@@ -259,16 +324,16 @@ class $ extends HTMLElement {
259
324
  wasOpened() {
260
325
  if (!this.content.hidden)
261
326
  return;
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(
327
+ 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 = M(
263
328
  this.button,
264
329
  this.content,
265
330
  () => {
266
- L(this.button, this.content, {
331
+ g(this.button, this.content, {
267
332
  placement: this.getAttribute("placement") || "bottom",
268
333
  middleware: [
269
- g(),
334
+ L(),
270
335
  x(),
271
- M({
336
+ K({
272
337
  apply: ({ availableWidth: e, availableHeight: i }) => {
273
338
  Object.assign(this.content.style, {
274
339
  maxWidth: "",
@@ -293,9 +358,9 @@ class $ extends HTMLElement {
293
358
  }
294
359
  wasClosed() {
295
360
  var t;
296
- this.content.hidden || (this.button.setAttribute("aria-expanded", "false"), (t = this.cleanup) == null || t.call(this), l(this.backdrop, {
361
+ this.content.hidden || (this.button.setAttribute("aria-expanded", "false"), (t = this.cleanup) == null || t.call(this), d(this.backdrop, {
297
362
  finish: () => this.backdrop.hidden = !0
298
- }), l(this.content, {
363
+ }), d(this.content, {
299
364
  finish: () => this.content.hidden = !0
300
365
  }), this.dispatchEvent(new Event("close")));
301
366
  }
@@ -304,13 +369,13 @@ class $ extends HTMLElement {
304
369
  return (t = this.shadowRoot) == null ? void 0 : t.firstElementChild;
305
370
  }
306
371
  get button() {
307
- return this.children[0];
372
+ return this.querySelector("button, [role=button]");
308
373
  }
309
374
  get content() {
310
375
  return this.children[1];
311
376
  }
312
377
  }
313
- class P extends HTMLElement {
378
+ class j extends HTMLElement {
314
379
  constructor() {
315
380
  super(...arguments);
316
381
  s(this, "onInitialFocus", () => {
@@ -341,7 +406,7 @@ class P extends HTMLElement {
341
406
  return A(this);
342
407
  }
343
408
  }
344
- const u = class extends HTMLElement {
409
+ const l = class extends HTMLElement {
345
410
  constructor() {
346
411
  super(...arguments);
347
412
  s(this, "parent");
@@ -378,9 +443,9 @@ const u = class extends HTMLElement {
378
443
  if (this.disabled)
379
444
  return;
380
445
  const t = this.createTooltip();
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()]
446
+ 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", g(this.parent, t, {
447
+ placement: this.getAttribute("placement") || l.placement,
448
+ middleware: [L(), x()]
384
449
  }).then(({ x: e, y: i, placement: n }) => {
385
450
  Object.assign(t.style, {
386
451
  left: `${e}px`,
@@ -389,7 +454,7 @@ const u = class extends HTMLElement {
389
454
  });
390
455
  }
391
456
  hide() {
392
- clearTimeout(this.timeout), this.showing && (this.showing = !1, l(this.tooltip, {
457
+ clearTimeout(this.timeout), this.showing && (this.showing = !1, d(this.tooltip, {
393
458
  finish: () => {
394
459
  this.tooltip && (this.tooltip.hidden = !0);
395
460
  }
@@ -400,23 +465,25 @@ const u = class extends HTMLElement {
400
465
  const e = parseInt(this.getAttribute("delay") || "");
401
466
  this.timeout = window.setTimeout(
402
467
  t.bind(this),
403
- isNaN(e) ? u.delay : e
468
+ isNaN(e) ? l.delay : e
404
469
  );
405
470
  }
406
471
  createTooltip() {
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(
472
+ return this.tooltip || (this.tooltip = document.createElement("div"), this.tooltip.className = this.getAttribute("tooltip-class") || l.tooltipClass, this.tooltip.hidden = !0, this.tooltip.addEventListener("mouseenter", this.show.bind(this)), this.tooltip.addEventListener(
408
473
  "mouseleave",
409
474
  this.afterDelay.bind(this, this.hide)
410
475
  ), document.body.appendChild(this.tooltip)), this.tooltip;
411
476
  }
412
477
  };
413
- let d = u;
414
- s(d, "delay", 100), s(d, "placement", "top"), s(d, "tooltipClass", "tooltip");
478
+ let c = l;
479
+ s(c, "delay", 100), s(c, "placement", "top"), s(c, "tooltipClass", "tooltip");
415
480
  export {
416
- f as AlertsElement,
417
- b as MenuElement,
481
+ I as AccordionElement,
482
+ b as AlertsElement,
483
+ $ as DisclosureElement,
484
+ f as MenuElement,
418
485
  m as ModalElement,
419
- $ as PopupElement,
420
- P as ToolbarElement,
421
- d as TooltipElement
486
+ P as PopupElement,
487
+ j as ToolbarElement,
488
+ c as TooltipElement
422
489
  };
@@ -0,0 +1,6 @@
1
+ export default class AccordionElement extends HTMLElement {
2
+ connectedCallback(): void;
3
+ disconnectedCallback(): void;
4
+ private onOpen;
5
+ get required(): boolean;
6
+ }
@@ -1,4 +1,4 @@
1
- export declare type AlertOptions = {
1
+ export type AlertOptions = {
2
2
  key?: string;
3
3
  duration?: number;
4
4
  animate?: boolean;
@@ -0,0 +1,14 @@
1
+ export default class DisclosureElement extends HTMLElement {
2
+ static get observedAttributes(): string[];
3
+ connectedCallback(): void;
4
+ disconnectedCallback(): void;
5
+ private onButtonClick;
6
+ get open(): boolean;
7
+ set open(val: boolean);
8
+ get disabled(): boolean;
9
+ attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
10
+ private wasOpened;
11
+ private wasClosed;
12
+ private get button();
13
+ private get content();
14
+ }
@@ -1,4 +1,6 @@
1
+ export { default as AccordionElement } from './accordion/accordion';
1
2
  export { default as AlertsElement } from './alerts/alerts';
3
+ export { default as DisclosureElement } from './disclosure/disclosure';
2
4
  export { default as MenuElement } from './menu/menu';
3
5
  export { default as ModalElement } from './modal/modal';
4
6
  export { default as PopupElement } from './popup/popup';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inclusive-elements",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "Accessible, lightweight, unstyled implementations of common UI controls.",
5
5
  "module": "dist/inclusive-elements.js",
6
6
  "type": "module",
@@ -15,30 +15,35 @@
15
15
  "dev": "vite",
16
16
  "build": "tsc --noEmit && vite build && tsc --emitDeclarationOnly",
17
17
  "preview": "vite preview",
18
- "release": "release-it --npm.tag=latest"
18
+ "release": "release-it"
19
19
  },
20
20
  "dependencies": {
21
- "@floating-ui/dom": "^1.0.0",
22
- "focus-trap": "^6.7.2",
23
- "hello-goodbye": "^0.1.0-beta.5",
24
- "tabbable": "^5.2.1"
21
+ "@floating-ui/dom": "^1.2.4",
22
+ "focus-trap": "^6.9.4",
23
+ "hello-goodbye": "^0.1.1",
24
+ "tabbable": "^5.3.3"
25
25
  },
26
26
  "devDependencies": {
27
- "@release-it/keep-a-changelog": "^2.3.0",
28
- "prettier": "^2.6.2",
29
- "release-it": "^14.12.4",
30
- "typescript": "^4.5.5",
31
- "vite": "^3.0.4"
27
+ "@release-it/conventional-changelog": "^5.1.1",
28
+ "prettier": "^2.8.4",
29
+ "release-it": "^15.9.0",
30
+ "typescript": "^5.0.2",
31
+ "vite": "^4.2.0"
32
32
  },
33
33
  "release-it": {
34
+ "git": {
35
+ "commitMessage": "release: v${version}",
36
+ "tagName": "v${version}"
37
+ },
34
38
  "github": {
35
- "release": true
39
+ "release": true,
40
+ "releaseName": "v${version}"
36
41
  },
37
42
  "plugins": {
38
- "@release-it/keep-a-changelog": {
39
- "filename": "CHANGELOG.md",
40
- "addUnreleased": true,
41
- "addVersionUrl": true
43
+ "@release-it/conventional-changelog": {
44
+ "preset": "conventionalcommits",
45
+ "infile": "CHANGELOG.md",
46
+ "header": "# Changelog"
42
47
  }
43
48
  },
44
49
  "hooks": {