abledom 0.0.4 → 0.1.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.
package/dist/index.js CHANGED
@@ -100,9 +100,6 @@ var ui_default = "#abledom-report {\n bottom: 20px;\n display: flex;\n flex-d
100
100
 
101
101
  // src/ui/domBuilder.ts
102
102
  var DOMBuilder = class {
103
- // static fromString(parent: HTMLElement | DocumentFragment, html: string): void {
104
- // // const builder = new DOMBuilder(parent);
105
- // }
106
103
  constructor(parent) {
107
104
  __publicField(this, "_doc");
108
105
  __publicField(this, "_stack");
@@ -145,8 +142,8 @@ var DOMBuilder = class {
145
142
  (_a = this._stack[0]) == null ? void 0 : _a.appendChild(document.createTextNode(text));
146
143
  return this;
147
144
  }
148
- builder(buildDOM) {
149
- buildDOM(this._stack[0]);
145
+ element(callback) {
146
+ callback(this._stack[0]);
150
147
  return this;
151
148
  }
152
149
  };
@@ -361,7 +358,7 @@ var _NotificationUI = class _NotificationUI {
361
358
  );
362
359
  };
363
360
  }
364
- ).builder(log_default).closeTag().openTag(
361
+ ).element(log_default).closeTag().openTag(
365
362
  "button",
366
363
  {
367
364
  class: "button",
@@ -385,12 +382,20 @@ var _NotificationUI = class _NotificationUI {
385
382
  revealButton.style.display = "none";
386
383
  }
387
384
  }
388
- ).builder(reveal_default).closeTag().text(notification.message).openTag("a", {
389
- class: "button close",
390
- href: "/",
391
- title: "Open help",
392
- target: "_blank"
393
- }).builder(help_default).closeTag().openTag(
385
+ ).element(reveal_default).closeTag().text(notification.message).openTag(
386
+ "a",
387
+ {
388
+ class: "button close",
389
+ href: notification.help || "/",
390
+ title: "Open help",
391
+ target: "_blank"
392
+ },
393
+ (help) => {
394
+ if (!notification.help) {
395
+ help.style.display = "none";
396
+ }
397
+ }
398
+ ).element(help_default).closeTag().openTag(
394
399
  "button",
395
400
  {
396
401
  class: "button close",
@@ -403,7 +408,7 @@ var _NotificationUI = class _NotificationUI {
403
408
  (_a = _NotificationUI._highlight) == null ? void 0 : _a.hide();
404
409
  };
405
410
  }
406
- ).builder(close_default).closeTag().closeTag().closeTag();
411
+ ).element(close_default).closeTag().closeTag().closeTag();
407
412
  }
408
413
  toggle(show, initial = false) {
409
414
  var _a;
@@ -439,7 +444,6 @@ var NotificationsUI = class {
439
444
  __publicField(this, "_alignBottomRightButton");
440
445
  __publicField(this, "_isMuted", false);
441
446
  __publicField(this, "_notifications", /* @__PURE__ */ new Set());
442
- var _a;
443
447
  const container = this._container = win.document.createElement("div");
444
448
  container.__abledomui = true;
445
449
  container.id = "abledom-report";
@@ -452,83 +456,111 @@ var NotificationsUI = class {
452
456
  container.appendChild(notificationsContainer);
453
457
  const menuElement = this._menuElement = win.document.createElement("div");
454
458
  menuElement.className = "abledom-menu-container";
455
- new DOMBuilder(menuElement).openTag("div", { class: "abledom-menu" }).openTag("span", {
456
- class: "notifications-count",
457
- title: "Number of notifications"
458
- }).closeTag().openTag("button", {
459
- class: "button",
460
- title: "Show all notifications"
461
- }).builder(showall_default).closeTag().openTag("button", {
462
- class: "button",
463
- title: "Hide all notifications"
464
- }).builder(hideall_default).closeTag().openTag("button", {
465
- class: "button",
466
- title: "Mute newly appearing notifications"
467
- }).builder(muteall_default).closeTag().openTag("button", {
468
- class: "button align-button align-button-first pressed",
469
- title: "Attach notifications to bottom left"
470
- }).builder(alignbottomleft_default).closeTag().openTag("button", {
471
- class: "button align-button",
472
- title: "Attach notifications to top left"
473
- }).builder(aligntopleft_default).closeTag().openTag("button", {
474
- class: "button align-button",
475
- title: "Attach notifications to top right"
476
- }).builder(aligntopright_default).closeTag().openTag("button", {
477
- class: "button align-button align-button-last",
478
- title: "Attach notifications to bottom right"
479
- }).builder(alignbottomright_default).closeTag().closeTag();
480
- const [
481
- notificationCountElement,
482
- showAllButton,
483
- hideAllButton,
484
- muteButton,
485
- alignBottomLeftButton,
486
- alignTopLeftButton,
487
- alignTopRightButton,
488
- alignBottomRightButton
489
- ] = ((_a = menuElement.firstElementChild) == null ? void 0 : _a.childNodes) || [];
490
- if (notificationCountElement instanceof HTMLSpanElement && showAllButton instanceof HTMLButtonElement && hideAllButton instanceof HTMLButtonElement && muteButton instanceof HTMLButtonElement && alignBottomLeftButton instanceof HTMLButtonElement && alignTopLeftButton instanceof HTMLButtonElement && alignTopRightButton instanceof HTMLButtonElement && alignBottomRightButton instanceof HTMLButtonElement) {
491
- container.appendChild(menuElement);
492
- this._notificationCountElement = notificationCountElement;
493
- this._showAllButton = showAllButton;
494
- this._hideAllButton = hideAllButton;
495
- this._alignBottomLeftButton = alignBottomLeftButton;
496
- this._alignTopLeftButton = alignTopLeftButton;
497
- this._alignTopRightButton = alignTopRightButton;
498
- this._alignBottomRightButton = alignBottomRightButton;
499
- showAllButton.onclick = () => {
500
- this.showAll();
501
- };
502
- hideAllButton.onclick = () => {
503
- this.hideAll();
504
- };
505
- muteButton.onclick = () => {
506
- const isMuted = this._isMuted = muteButton.classList.toggle(pressedClass);
507
- if (isMuted) {
508
- muteButton.setAttribute(
509
- "title",
510
- "Unmute newly appearing notifications"
511
- );
512
- } else {
513
- muteButton.setAttribute(
514
- "title",
515
- "Mute newly appearing notifications"
516
- );
517
- }
518
- };
519
- alignBottomLeftButton.onclick = () => {
520
- this.setUIAlignment("bottom-left" /* BottomLeft */);
521
- };
522
- alignBottomRightButton.onclick = () => {
523
- this.setUIAlignment("bottom-right" /* BottomRight */);
524
- };
525
- alignTopLeftButton.onclick = () => {
526
- this.setUIAlignment("top-left" /* TopLeft */);
527
- };
528
- alignTopRightButton.onclick = () => {
529
- this.setUIAlignment("top-right" /* TopRight */);
530
- };
531
- }
459
+ container.appendChild(menuElement);
460
+ new DOMBuilder(menuElement).openTag("div", { class: "abledom-menu" }).openTag(
461
+ "span",
462
+ {
463
+ class: "notifications-count",
464
+ title: "Number of notifications"
465
+ },
466
+ (notificationCountElement) => {
467
+ this._notificationCountElement = notificationCountElement;
468
+ }
469
+ ).closeTag().openTag(
470
+ "button",
471
+ {
472
+ class: "button",
473
+ title: "Show all notifications"
474
+ },
475
+ (showAllButton) => {
476
+ this._showAllButton = showAllButton;
477
+ showAllButton.onclick = () => {
478
+ this.showAll();
479
+ };
480
+ }
481
+ ).element(showall_default).closeTag().openTag(
482
+ "button",
483
+ {
484
+ class: "button",
485
+ title: "Hide all notifications"
486
+ },
487
+ (hideAllButton) => {
488
+ this._hideAllButton = hideAllButton;
489
+ hideAllButton.onclick = () => {
490
+ this.hideAll();
491
+ };
492
+ }
493
+ ).element(hideall_default).closeTag().openTag(
494
+ "button",
495
+ {
496
+ class: "button",
497
+ title: "Mute newly appearing notifications"
498
+ },
499
+ (muteButton) => {
500
+ muteButton.onclick = () => {
501
+ const isMuted = this._isMuted = muteButton.classList.toggle(pressedClass);
502
+ if (isMuted) {
503
+ muteButton.setAttribute(
504
+ "title",
505
+ "Unmute newly appearing notifications"
506
+ );
507
+ } else {
508
+ muteButton.setAttribute(
509
+ "title",
510
+ "Mute newly appearing notifications"
511
+ );
512
+ }
513
+ };
514
+ }
515
+ ).element(muteall_default).closeTag().openTag(
516
+ "button",
517
+ {
518
+ class: "button align-button align-button-first pressed",
519
+ title: "Attach notifications to bottom left"
520
+ },
521
+ (alignBottomLeftButton) => {
522
+ this._alignBottomLeftButton = alignBottomLeftButton;
523
+ alignBottomLeftButton.onclick = () => {
524
+ this.setUIAlignment("bottom-left" /* BottomLeft */);
525
+ };
526
+ }
527
+ ).element(alignbottomleft_default).closeTag().openTag(
528
+ "button",
529
+ {
530
+ class: "button align-button",
531
+ title: "Attach notifications to top left"
532
+ },
533
+ (alignTopLeftButton) => {
534
+ this._alignTopLeftButton = alignTopLeftButton;
535
+ alignTopLeftButton.onclick = () => {
536
+ this.setUIAlignment("top-left" /* TopLeft */);
537
+ };
538
+ }
539
+ ).element(aligntopleft_default).closeTag().openTag(
540
+ "button",
541
+ {
542
+ class: "button align-button",
543
+ title: "Attach notifications to top right"
544
+ },
545
+ (alignTopRightButton) => {
546
+ this._alignTopRightButton = alignTopRightButton;
547
+ alignTopRightButton.onclick = () => {
548
+ this.setUIAlignment("top-right" /* TopRight */);
549
+ };
550
+ }
551
+ ).element(aligntopright_default).closeTag().openTag(
552
+ "button",
553
+ {
554
+ class: "button align-button align-button-last",
555
+ title: "Attach notifications to bottom right"
556
+ },
557
+ (alignBottomRightButton) => {
558
+ this._alignBottomRightButton = alignBottomRightButton;
559
+ alignBottomRightButton.onclick = () => {
560
+ this.setUIAlignment("bottom-right" /* BottomRight */);
561
+ };
562
+ }
563
+ ).element(alignbottomright_default).closeTag().closeTag();
532
564
  win.document.body.appendChild(container);
533
565
  }
534
566
  setUIAlignment(alignment) {
@@ -1384,7 +1416,8 @@ var FocusableElementLabelRule = class extends ValidationRule {
1384
1416
  notification: isElementVisible(element) ? {
1385
1417
  id: "focusable-element-label",
1386
1418
  message: "Focusable element must have a non-empty text label.",
1387
- element
1419
+ element,
1420
+ help: "https://www.w3.org/WAI/tutorials/forms/labels/"
1388
1421
  } : void 0,
1389
1422
  dependsOnIds: new Set(labelledByValues)
1390
1423
  };